11#import "CredentialsEditorController.h"
19#define SECTION_CREDENTIALS 0
20#define SECTION_COUNT 1
26 if ((
self = [super initWithStyle:UITableViewStyleGrouped]))
29 _bookmark = [bookmark retain];
30 _params = [bookmark params];
38 [
self setTitle:NSLocalizedString(@"Credentials", @"Credentials title")];
43 [
super viewDidUnload];
47- (void)viewWillDisappear:(BOOL)animated
49 [
super viewWillDisappear:animated];
52 [[
self view] endEditing:NO];
55- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
67#pragma mark Table view data source
69- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
75- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
80 case SECTION_CREDENTIALS:
90- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
94 case SECTION_CREDENTIALS:
95 return NSLocalizedString(
@"Credentials",
@"'Credentials': credentials settings header");
101- (UITableViewCell *)tableView:(UITableView *)tableView
102 cellForRowAtIndexPath:(NSIndexPath *)indexPath
106 NSString *cellType = nil;
107 switch ([indexPath section])
109 case SECTION_CREDENTIALS:
110 if ([indexPath row] == 1)
111 cellType = TableCellIdentifierSecretText;
113 cellType = TableCellIdentifierText;
119 NSAssert(cellType != nil,
@"Couldn't determine cell type");
122 UITableViewCell *cell = [
self tableViewCellFromIdentifier:cellType];
123 NSAssert(cell,
@"Invalid cell");
126 switch ([indexPath section])
129 case SECTION_CREDENTIALS:
130 [
self initCredentialSettings:indexPath cell:cell];
141- (void)initCredentialSettings:(NSIndexPath *)indexPath cell:(UITableViewCell *)cell
143 switch (indexPath.row)
148 [[textCell textfield] setTag:GET_TAG_FROM_PATH(indexPath)];
150 setText:NSLocalizedString(@"Username", @"'Username': Bookmark username")];
151 [[textCell textfield] setText:[_params StringForKey:@"username"]];
152 [[textCell textfield]
153 setPlaceholder:NSLocalizedString(@"not set", @"not set placeholder")];
159 [[textCell textfield] setTag:GET_TAG_FROM_PATH(indexPath)];
161 setText:NSLocalizedString(@"Password", @"'Password': Bookmark password")];
162 [[textCell textfield] setText:[_params StringForKey:@"password"]];
163 [[textCell textfield]
164 setPlaceholder:NSLocalizedString(@"not set", @"not set placeholder")];
170 [[textCell textfield] setTag:GET_TAG_FROM_PATH(indexPath)];
171 [[textCell label] setText:NSLocalizedString(@"Domain", @"'Domain': Bookmark domain")];
172 [[textCell textfield] setText:[_params StringForKey:@"domain"]];
173 [[textCell textfield]
174 setPlaceholder:NSLocalizedString(@"not set", @"not set placeholder")];
178 NSLog(
@"Invalid row index in settings table!");
184#pragma mark Text Field delegate
186- (BOOL)textFieldShouldReturn:(UITextField *)textField
188 [textField resignFirstResponder];
192- (BOOL)textFieldShouldEndEditing:(UITextField *)textField
194 switch (textField.tag)
197 case GET_TAG(SECTION_CREDENTIALS, 0):
198 [_params setValue:[textField text] forKey:
@"username"];
201 case GET_TAG(SECTION_CREDENTIALS, 1):
202 [_params setValue:[textField text] forKey:
@"password"];
205 case GET_TAG(SECTION_CREDENTIALS, 2):
206 [_params setValue:[textField text] forKey:
@"domain"];