]> git.saurik.com Git - apple/security.git/blob - Keychain/DeviceTableViewController.m
Security-57031.1.35.tar.gz
[apple/security.git] / Keychain / DeviceTableViewController.m
1 //
2 // DeviceTableViewController.m
3 // Security
4 //
5 //
6
7
8 #import "DeviceTableViewController.h"
9 #import "DeviceItemCell.h"
10
11 static NSString *redCircle = @"🔴";
12 static NSString *blueCircle = @"🔵";
13
14 enum
15 {
16 KCA_ITEM_STATUS_ID = 300,
17 KCA_ITEM_NAME_ID = 301,
18 KCA_ITEM_ACCT_ID = 302,
19 };
20
21 @interface DeviceTableViewController ()
22
23 @end
24
25 @implementation DeviceTableViewController
26
27 - (id)initWithStyle:(UITableViewStyle)style
28 {
29 NSLog(@"DeviceTableViewController: initWithStyle");
30 if (self = [super initWithStyle:style])
31 {
32 // Custom initialization
33 // [self.tableView registerClass:(Class)[KeychainItemCell class] forCellReuseIdentifier:(NSString *)@"kciCell"];
34
35 _kcItemStatuses = [[NSArray alloc] initWithObjects:@"",redCircle, blueCircle,@"",@"",blueCircle,nil];
36 _kcItemNames = [[NSArray alloc] initWithObjects:@"Facebook",@"iCloud", @"WSJ",@"Twitter",@"NYTimes",@"Wells Fargo", nil];
37 // self.navigationItem.rightBarButtonItem = self.editButtonItem;
38 }
39 return self;
40 }
41
42 #if 0
43 - (void)viewDidLoad
44 {
45 NSLog(@"DeviceTableViewController: viewDidLoad");
46 [super viewDidLoad];
47
48 // Uncomment the following line to preserve selection between presentations.
49 // self.clearsSelectionOnViewWillAppear = NO;
50 _kcItemStatuses = [[NSArray alloc] initWithObjects:@"",redCircle, blueCircle,@"",@"",nil];
51 _kcItemNames = [[NSArray alloc] initWithObjects:@"Facebook",@"iCloud", @"WSJ",@"Twitter",@"NYTimes",nil];
52
53 // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
54 self.navigationItem.rightBarButtonItem = self.editButtonItem;
55 }
56 #endif
57
58 - (void)didReceiveMemoryWarning
59 {
60 [super didReceiveMemoryWarning];
61 // Dispose of any resources that can be recreated.
62 }
63
64 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
65 {
66 if ([[segue identifier] isEqualToString:@"ItemDetail"])
67 {
68 #if 0
69 KCAItemDetailViewController *detailViewController = [segue destinationViewController];
70 NSIndexPath *myIndexPath = [self.tableView indexPathForSelectedRow];
71 int row = [myIndexPath row];
72 //TODO - horribly inefficient !
73 NSArray *items = [self getItems];
74 detailViewController.itemDetailModel = [items objectAtIndex: row];
75 #endif
76 }
77 }
78
79 // MARK: - Table view data source
80
81 - (NSArray *)getItems
82 {
83 NSArray *allItems = NULL;//(NSArray *)[[MyKeychain sharedInstance] fetchDictionaryAll];
84 return allItems;
85 }
86
87 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
88 {
89 // Return the number of sections.
90 NSLog(@"numberOfSectionsInTableView");
91 return 1; //TODO
92 }
93
94 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
95 {
96 // Return the number of rows in the section.
97
98 // SOSCircleCountPeers(circle) + SOSCircleCountApplicants(circle)
99
100 static bool dumpedit = false;
101
102 if (!dumpedit)
103 {
104 NSMutableDictionary *allItems = NULL;//[[MyKeychain sharedInstance] fetchDictionaryAll];
105 NSLog(@"numberOfRowsInSection: items: %lu", (unsigned long)[allItems count]);
106
107 dumpedit = true;
108 }
109 //TODO
110 #if _USE_TEST_DATA
111 return _kcItemStatuses.count;
112 #else
113 NSInteger count = [[self getItems] count];
114 NSLog(@"numberOfRowsInSection: %ld", (long)count);
115 return count;
116 #endif
117
118 return 1;
119 }
120
121 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
122 {
123 #if 1
124 NSLog(@"cellForRowAtIndexPath %@", indexPath);
125
126 //- (id)dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(6_0); // newer dequeue method guarantees a cell is returned and resized properly, assuming identifier is registered
127
128 // KeychainItemCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
129
130 // UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:KCAItemCellIdentifier forIndexPath:(NSIndexPath *)indexPath];
131 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"deviceTableCell" forIndexPath:(NSIndexPath *)indexPath];
132 if (cell == nil)
133 {
134 NSLog(@"cellForRowAtIndexPath : cell was nil");
135 cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"deviceTableCell"];
136 }
137
138 // Configure the cell...
139
140 NSUInteger row = [indexPath row];
141
142 #if _USE_TEST_DATA
143 UILabel *statusLabel = (UILabel *)[cell viewWithTag:KCA_ITEM_STATUS_ID];
144 statusLabel.text = [_kcItemStatuses objectAtIndex: row];
145 UILabel *nameLabel = (UILabel *)[cell viewWithTag:KCA_ITEM_NAME_ID];
146 nameLabel.text = [_kcItemNames objectAtIndex: row];
147 #else
148 NSArray *items = [self getItems];
149 NSDictionary *theItem = [items objectAtIndex: row];
150 UILabel *statusLabel = (UILabel *)[cell viewWithTag:KCA_ITEM_STATUS_ID];
151 statusLabel.text = [_kcItemStatuses objectAtIndex: row];
152 UILabel *nameLabel = (UILabel *)[cell viewWithTag:KCA_ITEM_NAME_ID];
153 nameLabel.text = [theItem objectForKey: (__bridge id)(kSecAttrService)];
154 UILabel *accountLabel = (UILabel *)[cell viewWithTag:KCA_ITEM_ACCT_ID];
155 accountLabel.text = [theItem objectForKey: (__bridge id)(kSecAttrAccount)];
156 #endif
157
158 /*
159 WHY DOESNT THIS WORK !!!
160 cell.itemAccount.text =
161 cell.itemStatus.text =
162 cell.itemName.text = [_kcItemNames objectAtIndex: [indexPath row]];
163 */
164 return cell;
165 #else
166 static NSString *CellIdentifier = @"DeviceCell";
167 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
168 if (cell == nil) {
169 cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
170 }
171
172 // Configure the cell...
173 // cell.textLabel.text = @"1234";
174 cell.textLabel.text = self.objects[indexPath.row];
175 #endif
176 return cell;
177 }
178
179
180 @end