9 #import "BookmarkGatewaySettingsController.h"
12 #import "EditorSelectionController.h"
14 #define SECTION_TSGATEWAY_SETTINGS 0
15 #define SECTION_COUNT 1
25 if ((
self = [super initWithStyle:UITableViewStyleGrouped]))
28 _bookmark = [bookmark retain];
29 _params = [bookmark params];
37 [
self setTitle:NSLocalizedString(@"TS Gateway Settings", @"TS Gateway Settings title")];
40 - (void)viewWillAppear:(BOOL)animated
42 [
super viewWillAppear:animated];
46 [[
self tableView] reloadData];
49 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
60 #pragma mark - Table view data source
62 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
68 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
73 case SECTION_TSGATEWAY_SETTINGS:
83 - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
87 case SECTION_TSGATEWAY_SETTINGS:
88 return NSLocalizedString(
@"TS Gateway",
@"'TS Gateway': ts gateway settings header");
93 - (UITableViewCell *)tableView:(UITableView *)tableView
94 cellForRowAtIndexPath:(NSIndexPath *)indexPath
97 NSString *cellType = nil;
98 switch ([indexPath section])
100 case SECTION_TSGATEWAY_SETTINGS:
102 switch ([indexPath row])
108 cellType = TableCellIdentifierText;
111 cellType = TableCellIdentifierSecretText;
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_TSGATEWAY_SETTINGS:
130 [
self initGatewaySettings:indexPath cell:cell];
141 - (void)initGatewaySettings:(NSIndexPath *)indexPath cell:(UITableViewCell *)cell
144 [[textCell textfield] setTag:GET_TAG_FROM_PATH(indexPath)];
145 switch ([indexPath row])
149 [[textCell label] setText:NSLocalizedString(@"Host", @"'Host': Bookmark hostname")];
150 [[textCell textfield] setText:[_params StringForKey:@"tsg_hostname"]];
151 [[textCell textfield]
152 setPlaceholder:NSLocalizedString(@"not set", @"not set placeholder")];
157 int port = [_params intForKey:@"tsg_port"];
160 [[textCell label] setText:NSLocalizedString(@"Port", @"'Port': Bookmark port")];
161 [[textCell textfield] setText:[NSString stringWithFormat:@"%d", port]];
162 [[textCell textfield] setKeyboardType:UIKeyboardTypeNumberPad];
167 [[textCell textfield] setTag:GET_TAG_FROM_PATH(indexPath)];
169 setText:NSLocalizedString(@"Username", @"'Username': Bookmark username")];
170 [[textCell textfield] setText:[_params StringForKey:@"tsg_username"]];
171 [[textCell textfield]
172 setPlaceholder:NSLocalizedString(@"not set", @"not set placeholder")];
177 [[textCell textfield] setTag:GET_TAG_FROM_PATH(indexPath)];
179 setText:NSLocalizedString(@"Password", @"'Password': Bookmark password")];
180 [[textCell textfield] setText:[_params StringForKey:@"tsg_password"]];
181 [[textCell textfield]
182 setPlaceholder:NSLocalizedString(@"not set", @"not set placeholder")];
187 [[textCell textfield] setTag:GET_TAG_FROM_PATH(indexPath)];
188 [[textCell label] setText:NSLocalizedString(@"Domain", @"'Domain': Bookmark domain")];
189 [[textCell textfield] setText:[_params StringForKey:@"tsg_domain"]];
190 [[textCell textfield]
191 setPlaceholder:NSLocalizedString(@"not set", @"not set placeholder")];
195 NSLog(
@"Invalid row index in settings table!");
199 [
self adjustEditTextTableViewCell:textCell];
203 #pragma mark Text Field delegate
205 - (BOOL)textFieldShouldReturn:(UITextField *)textField
207 [textField resignFirstResponder];
211 - (BOOL)textFieldShouldEndEditing:(UITextField *)textField
213 switch (textField.tag)
216 case GET_TAG(SECTION_TSGATEWAY_SETTINGS, 0):
217 [_params setValue:[textField text] forKey:
@"tsg_hostname"];
220 case GET_TAG(SECTION_TSGATEWAY_SETTINGS, 1):
221 [_params setInt:[[textField text] intValue] forKey:
@"tsg_port"];
224 case GET_TAG(SECTION_TSGATEWAY_SETTINGS, 2):
225 [_params setValue:[textField text] forKey:
@"tsg_username"];
228 case GET_TAG(SECTION_TSGATEWAY_SETTINGS, 3):
229 [_params setValue:[textField text] forKey:
@"tsg_password"];
232 case GET_TAG(SECTION_TSGATEWAY_SETTINGS, 4):
233 [_params setValue:[textField text] forKey:
@"tsg_domain"];