11#import "AdvancedBookmarkEditorController.h"
14#import "EditorSelectionController.h"
15#import "ScreenSelectionController.h"
16#import "PerformanceEditorController.h"
17#import "BookmarkGatewaySettingsController.h"
23#define SECTION_ADVANCED_SETTINGS 0
24#define SECTION_COUNT 1
30 if ((
self = [super initWithStyle:UITableViewStyleInsetGrouped]))
33 _bookmark = [bookmark retain];
34 _params = [bookmark params];
42 [
self setTitle:NSLocalizedString(@"Advanced Settings", @"Advanced Settings title")];
45- (void)viewWillAppear:(BOOL)animated
47 [
super viewWillAppear:animated];
51 [[
self tableView] reloadData];
54- (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_ADVANCED_SETTINGS:
83- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
87 case SECTION_ADVANCED_SETTINGS:
88 return NSLocalizedString(
@"Advanced",
@"'Advanced': advanced settings header");
94- (UITableViewCell *)tableView:(UITableView *)tableView
95 cellForRowAtIndexPath:(NSIndexPath *)indexPath
99 NSString *cellType = nil;
100 switch ([indexPath section])
102 case SECTION_ADVANCED_SETTINGS:
104 switch ([indexPath row])
107 cellType = TableCellIdentifierYesNo;
110 cellType = TableCellIdentifierSubEditor;
113 cellType = TableCellIdentifierYesNo;
116 cellType = TableCellIdentifierSelection;
119 cellType = TableCellIdentifierSubEditor;
122 cellType = TableCellIdentifierSelection;
126 cellType = TableCellIdentifierText;
129 cellType = TableCellIdentifierYesNo;
137 NSAssert(cellType != nil,
@"Couldn't determine cell type");
140 UITableViewCell *cell = [
self tableViewCellFromIdentifier:cellType];
141 NSAssert(cell,
@"Invalid cell");
144 switch ([indexPath section])
147 case SECTION_ADVANCED_SETTINGS:
148 [
self initAdvancedSettings:indexPath cell:cell];
159- (void)initAdvancedSettings:(NSIndexPath *)indexPath cell:(UITableViewCell *)cell
161 BOOL enable_3G_settings = [_params boolForKey:@"enable_3g_settings"];
162 switch (indexPath.row)
168 setTitle:NSLocalizedString(@"Enable TS Gateway",
169 @"'Enable TS Gateway': Bookmark enable TSG settings")];
170 [[flagCell toggle] setTag:GET_TAG_FROM_PATH(indexPath)];
171 [[flagCell toggle] setOn:[_params boolForKey:@"enable_tsg_settings"]];
172 [[flagCell toggle] addTarget:self
173 action:@selector(toggleSettingValue:)
174 forControlEvents:UIControlEventValueChanged];
179 BOOL enable_tsg_settings = [_params boolForKey:@"enable_tsg_settings"];
182 setTitle:NSLocalizedString(@"TS Gateway Settings",
183 @"'TS Gateway Settings': Bookmark TS Gateway Settings")];
184 [editCell setEnabled:enable_tsg_settings];
185 [editCell setSelectionStyle:enable_tsg_settings ? UITableViewCellSelectionStyleBlue
186 : UITableViewCellSelectionStyleNone];
192 [flagCell setTitle:NSLocalizedString(@"3G Settings",
193 @"'3G Settings': Bookmark enable 3G settings")];
194 [[flagCell toggle] setTag:GET_TAG_FROM_PATH(indexPath)];
195 [[flagCell toggle] setOn:[_params boolForKey:@"enable_3g_settings"]];
196 [[flagCell toggle] addTarget:self
197 action:@selector(toggleSettingValue:)
198 forControlEvents:UIControlEventValueChanged];
204 [selCell setTitle:NSLocalizedString(@"3G Screen",
205 @"'3G Screen': Bookmark 3G Screen settings")];
206 NSString *resolution = ScreenResolutionDescription(
207 [_params intForKeyPath:
@"settings_3g.screen_resolution_type"],
208 [_params intForKeyPath:
@"settings_3g.width"],
209 [_params intForKeyPath:
@"settings_3g.height"]);
210 int colorBits = [_params intForKeyPath:@"settings_3g.colors"];
211 [selCell setValue:[NSString stringWithFormat:@"%@@%d", resolution, colorBits]];
212 [selCell setEnabled:enable_3G_settings];
213 [selCell setSelectionStyle:enable_3G_settings ? UITableViewCellSelectionStyleBlue
214 : UITableViewCellSelectionStyleNone];
221 setTitle:NSLocalizedString(@"3G Performance",
222 @"'3G Performance': Bookmark 3G Performance Settings")];
223 [editCell setEnabled:enable_3G_settings];
224 [editCell setSelectionStyle:enable_3G_settings ? UITableViewCellSelectionStyleBlue
225 : UITableViewCellSelectionStyleNone];
231 [selCell setTitle:NSLocalizedString(
232 @"Security", @"'Security': Bookmark protocol security settings")];
233 [selCell setValue:ProtocolSecurityDescription([_params intForKey:@"security"])];
240 setText:NSLocalizedString(@"Remote Program",
241 @"'Remote Program': Bookmark remote program settings")];
242 [[textCell textfield] setText:[_params StringForKey:@"remote_program"]];
243 [[textCell textfield] setTag:GET_TAG_FROM_PATH(indexPath)];
244 [[textCell textfield]
245 setPlaceholder:NSLocalizedString(@"not set", @"not set placeholder")];
252 setText:NSLocalizedString(
253 @"Working Directory",
254 @"'Working Directory': Bookmark working directory settings")];
255 [[textCell textfield] setText:[_params StringForKey:@"working_dir"]];
256 [[textCell textfield] setTag:GET_TAG_FROM_PATH(indexPath)];
257 [[textCell textfield]
258 setPlaceholder:NSLocalizedString(@"not set", @"not set placeholder")];
265 setTitle:NSLocalizedString(@"Console Mode",
266 @"'Console Mode': Bookmark console mode settings")];
267 [[flagCell toggle] setTag:GET_TAG_FROM_PATH(indexPath)];
268 [[flagCell toggle] setOn:[_params boolForKey:@"console"]];
269 [[flagCell toggle] addTarget:self
270 action:@selector(toggleSettingValue:)
271 forControlEvents:UIControlEventValueChanged];
275 NSLog(
@"Invalid row index in settings table!");
281#pragma mark Table view delegate
283- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
285 UIViewController *viewCtrl = nil;
288 switch ([indexPath row])
291 if ([_params boolForKey:
@"enable_tsg_settings"])
296 if ([_params boolForKey:
@"enable_3g_settings"])
298 initWithConnectionParams:_params
299 keyPath:
@"settings_3g"] autorelease];
302 if ([_params boolForKey:
@"enable_3g_settings"])
304 initWithConnectionParams:_params
305 keyPath:
@"settings_3g"] autorelease];
309 initWithConnectionParams:_params
310 entries:[NSArray arrayWithObject:@"security"]
311 selections:[NSArray arrayWithObject:SelectionForSecuritySetting()]]
320 [[
self navigationController] pushViewController:viewCtrl animated:YES];
324#pragma mark Text Field delegate
326- (BOOL)textFieldShouldReturn:(UITextField *)textField
328 [textField resignFirstResponder];
332- (BOOL)textFieldShouldEndEditing:(UITextField *)textField
334 switch (textField.tag)
337 case GET_TAG(SECTION_ADVANCED_SETTINGS, 6):
339 [_params setValue:[textField text] forKey:@"remote_program"];
343 case GET_TAG(SECTION_ADVANCED_SETTINGS, 7):
345 [_params setValue:[textField text] forKey:@"working_dir"];
355#pragma mark - Action handlers
357- (void)toggleSettingValue:(
id)sender
359 UISwitch *valueSwitch = (UISwitch *)sender;
360 switch (valueSwitch.tag)
362 case GET_TAG(SECTION_ADVANCED_SETTINGS, 0):
364 [_params setBool:[valueSwitch isOn] forKey:@"enable_tsg_settings"];
366 NSArray *indexPaths =
367 [NSArray arrayWithObjects:[NSIndexPath indexPathForRow:1
368 inSection:SECTION_ADVANCED_SETTINGS],
370 [[
self tableView] reloadRowsAtIndexPaths:indexPaths
371 withRowAnimation:UITableViewRowAnimationNone];
375 case GET_TAG(SECTION_ADVANCED_SETTINGS, 2):
377 [_params setBool:[valueSwitch isOn] forKey:@"enable_3g_settings"];
379 NSArray *indexPaths =
380 [NSArray arrayWithObjects:[NSIndexPath indexPathForRow:3
381 inSection:SECTION_ADVANCED_SETTINGS],
382 [NSIndexPath indexPathForRow:4
383 inSection:SECTION_ADVANCED_SETTINGS],
385 [[
self tableView] reloadRowsAtIndexPaths:indexPaths
386 withRowAnimation:UITableViewRowAnimationNone];
390 case GET_TAG(SECTION_ADVANCED_SETTINGS, 8):
391 [_params setBool:[valueSwitch isOn] forKey:
@"console"];