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:UITableViewStyleGrouped]))
 
   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          setText: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          setText:NSLocalizedString(@"TS Gateway Settings",
 
  183                                    @"'TS Gateway Settings': Bookmark TS Gateway Settings")];
 
  184      [[editCell label] setEnabled:enable_tsg_settings];
 
  185      [editCell setSelectionStyle:enable_tsg_settings ? UITableViewCellSelectionStyleBlue
 
  186                                                      : UITableViewCellSelectionStyleNone];
 
  193          setText:NSLocalizedString(@"3G Settings",
 
  194                                    @"'3G Settings': Bookmark enable 3G settings")];
 
  195      [[flagCell toggle] setTag:GET_TAG_FROM_PATH(indexPath)];
 
  196      [[flagCell toggle] setOn:[_params boolForKey:@"enable_3g_settings"]];
 
  197      [[flagCell toggle] addTarget:self
 
  198                            action:@selector(toggleSettingValue:)
 
  199                  forControlEvents:UIControlEventValueChanged];
 
  206          setText:NSLocalizedString(@"3G Screen",
 
  207                                    @"'3G Screen': Bookmark 3G Screen settings")];
 
  208      NSString *resolution = ScreenResolutionDescription(
 
  209          [_params intForKeyPath:
@"settings_3g.screen_resolution_type"],
 
  210          [_params intForKeyPath:
@"settings_3g.width"],
 
  211          [_params intForKeyPath:
@"settings_3g.height"]);
 
  212      int colorBits = [_params intForKeyPath:@"settings_3g.colors"];
 
  214          setText:[NSString stringWithFormat:@"%@@%d", resolution, colorBits]];
 
  215      [[selCell label] setEnabled:enable_3G_settings];
 
  216      [[selCell selection] setEnabled:enable_3G_settings];
 
  217      [selCell setSelectionStyle:enable_3G_settings ? UITableViewCellSelectionStyleBlue
 
  218                                                    : UITableViewCellSelectionStyleNone];
 
  225          setText:NSLocalizedString(@"3G Performance",
 
  226                                    @"'3G Performance': Bookmark 3G Performance Settings")];
 
  227      [[editCell label] setEnabled:enable_3G_settings];
 
  228      [editCell setSelectionStyle:enable_3G_settings ? UITableViewCellSelectionStyleBlue
 
  229                                                     : UITableViewCellSelectionStyleNone];
 
  236          setText:NSLocalizedString(@"Security",
 
  237                                    @"'Security': Bookmark protocol security settings")];
 
  239          setText:ProtocolSecurityDescription([_params intForKey:@"security"])];
 
  246          setText:NSLocalizedString(@"Remote Program",
 
  247                                    @"'Remote Program': Bookmark remote program settings")];
 
  248      [[textCell textfield] setText:[_params StringForKey:@"remote_program"]];
 
  249      [[textCell textfield] setTag:GET_TAG_FROM_PATH(indexPath)];
 
  250      [[textCell textfield]
 
  251          setPlaceholder:NSLocalizedString(@"not set", @"not set placeholder")];
 
  252      [
self adjustEditTextTableViewCell:textCell];
 
  259          setText:NSLocalizedString(
 
  260                      @"Working Directory",
 
  261                      @"'Working Directory': Bookmark working directory settings")];
 
  262      [[textCell textfield] setText:[_params StringForKey:@"working_dir"]];
 
  263      [[textCell textfield] setTag:GET_TAG_FROM_PATH(indexPath)];
 
  264      [[textCell textfield]
 
  265          setPlaceholder:NSLocalizedString(@"not set", @"not set placeholder")];
 
  266      [
self adjustEditTextTableViewCell:textCell];
 
  273          setText:NSLocalizedString(@"Console Mode",
 
  274                                    @"'Console Mode': Bookmark console mode settings")];
 
  275      [[flagCell toggle] setTag:GET_TAG_FROM_PATH(indexPath)];
 
  276      [[flagCell toggle] setOn:[_params boolForKey:@"console"]];
 
  277      [[flagCell toggle] addTarget:self
 
  278                            action:@selector(toggleSettingValue:)
 
  279                  forControlEvents:UIControlEventValueChanged];
 
  283      NSLog(
@"Invalid row index in settings table!");
 
  289#pragma mark Table view delegate 
  291- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
 
  293  UIViewController *viewCtrl = nil;
 
  296  switch ([indexPath row])
 
  299      if ([_params boolForKey:
@"enable_tsg_settings"])
 
  304      if ([_params boolForKey:
@"enable_3g_settings"])
 
  306            initWithConnectionParams:_params
 
  307                             keyPath:
@"settings_3g"] autorelease];
 
  310      if ([_params boolForKey:
@"enable_3g_settings"])
 
  312            initWithConnectionParams:_params
 
  313                             keyPath:
@"settings_3g"] autorelease];
 
  317          initWithConnectionParams:_params
 
  318                           entries:[NSArray arrayWithObject:@"security"]
 
  319                        selections:[NSArray arrayWithObject:SelectionForSecuritySetting()]]
 
  328    [[
self navigationController] pushViewController:viewCtrl animated:YES];
 
  332#pragma mark Text Field delegate 
  334- (BOOL)textFieldShouldReturn:(UITextField *)textField
 
  336  [textField resignFirstResponder];
 
  340- (BOOL)textFieldShouldEndEditing:(UITextField *)textField
 
  342  switch (textField.tag)
 
  345    case GET_TAG(SECTION_ADVANCED_SETTINGS, 6):
 
  347      [_params setValue:[textField text] forKey:@"remote_program"];
 
  351    case GET_TAG(SECTION_ADVANCED_SETTINGS, 7):
 
  353      [_params setValue:[textField text] forKey:@"working_dir"];
 
  363#pragma mark - Action handlers 
  365- (void)toggleSettingValue:(
id)sender
 
  367  UISwitch *valueSwitch = (UISwitch *)sender;
 
  368  switch (valueSwitch.tag)
 
  370    case GET_TAG(SECTION_ADVANCED_SETTINGS, 0):
 
  372      [_params setBool:[valueSwitch isOn] forKey:@"enable_tsg_settings"];
 
  373      NSArray *indexPaths =
 
  374          [NSArray arrayWithObjects:[NSIndexPath indexPathForRow:1
 
  375                                                       inSection:SECTION_ADVANCED_SETTINGS],
 
  376                                    [NSIndexPath indexPathForRow:2
 
  377                                                       inSection:SECTION_ADVANCED_SETTINGS],
 
  379      [[
self tableView] reloadRowsAtIndexPaths:indexPaths
 
  380                              withRowAnimation:UITableViewRowAnimationNone];
 
  384    case GET_TAG(SECTION_ADVANCED_SETTINGS, 2):
 
  386      [_params setBool:[valueSwitch isOn] forKey:@"enable_3g_settings"];
 
  387      NSArray *indexPaths =
 
  388          [NSArray arrayWithObjects:[NSIndexPath indexPathForRow:3
 
  389                                                       inSection:SECTION_ADVANCED_SETTINGS],
 
  390                                    [NSIndexPath indexPathForRow:2
 
  391                                                       inSection:SECTION_ADVANCED_SETTINGS],
 
  393      [[
self tableView] reloadRowsAtIndexPaths:indexPaths
 
  394                              withRowAnimation:UITableViewRowAnimationNone];
 
  398    case GET_TAG(SECTION_ADVANCED_SETTINGS, 8):
 
  399      [_params setBool:[valueSwitch isOn] forKey:
@"console"];