FreeRDP
Loading...
Searching...
No Matches
AdvancedBookmarkEditorController.m
1/*
2 Controller to edit advanced bookmark settings
3
4 Copyright 2013 Thincast Technologies GmbH, Author: Martin Fleisz
5
6 This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
7 If a copy of the MPL was not distributed with this file, You can obtain one at
8 http://mozilla.org/MPL/2.0/.
9 */
10
11#import "AdvancedBookmarkEditorController.h"
12#import "Bookmark.h"
13#import "Utils.h"
14#import "EditorSelectionController.h"
15#import "ScreenSelectionController.h"
16#import "PerformanceEditorController.h"
17#import "BookmarkGatewaySettingsController.h"
18
20
21@end
22
23#define SECTION_ADVANCED_SETTINGS 0
24#define SECTION_COUNT 1
25
27
28- (id)initWithBookmark:(ComputerBookmark *)bookmark
29{
30 if ((self = [super initWithStyle:UITableViewStyleInsetGrouped]))
31 {
32 // set additional settings state according to bookmark data
33 _bookmark = [bookmark retain];
34 _params = [bookmark params];
35 }
36 return self;
37}
38
39- (void)viewDidLoad
40{
41 [super viewDidLoad];
42 [self setTitle:NSLocalizedString(@"Advanced Settings", @"Advanced Settings title")];
43}
44
45- (void)viewWillAppear:(BOOL)animated
46{
47 [super viewWillAppear:animated];
48
49 // we need to reload the table view data here to have up-to-date data for the
50 // advanced settings accessory items (like for resolution/color mode settings)
51 [[self tableView] reloadData];
52}
53
54- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
55{
56 return YES;
57}
58
59#pragma mark -
60#pragma mark Table view data source
61
62- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
63{
64 // Return the number of sections.
65 return SECTION_COUNT;
66}
67
68- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
69{
70 // Return the number of rows in the section.
71 switch (section)
72 {
73 case SECTION_ADVANCED_SETTINGS: // advanced settings
74 return 9;
75 default:
76 break;
77 }
78
79 return 0;
80}
81
82// set section headers
83- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
84{
85 switch (section)
86 {
87 case SECTION_ADVANCED_SETTINGS:
88 return NSLocalizedString(@"Advanced", @"'Advanced': advanced settings header");
89 }
90 return @"unknown";
91}
92
93// Customize the appearance of table view cells.
94- (UITableViewCell *)tableView:(UITableView *)tableView
95 cellForRowAtIndexPath:(NSIndexPath *)indexPath
96{
97
98 // determine the required cell type
99 NSString *cellType = nil;
100 switch ([indexPath section])
101 {
102 case SECTION_ADVANCED_SETTINGS: // advanced settings
103 {
104 switch ([indexPath row])
105 {
106 case 0: // Enable/Disable TSG Settings
107 cellType = TableCellIdentifierYesNo;
108 break;
109 case 1: // TS Gateway Settings
110 cellType = TableCellIdentifierSubEditor;
111 break;
112 case 2: // 3G Settings
113 cellType = TableCellIdentifierYesNo;
114 break;
115 case 3: // 3G screen/color depth
116 cellType = TableCellIdentifierSelection;
117 break;
118 case 4: // 3G performance settings
119 cellType = TableCellIdentifierSubEditor;
120 break;
121 case 5: // security mode
122 cellType = TableCellIdentifierSelection;
123 break;
124 case 6: // remote program
125 case 7: // work dir
126 cellType = TableCellIdentifierText;
127 break;
128 case 8: // console mode
129 cellType = TableCellIdentifierYesNo;
130 break;
131 default:
132 break;
133 }
134 break;
135 }
136 }
137 NSAssert(cellType != nil, @"Couldn't determine cell type");
138
139 // get the table view cell
140 UITableViewCell *cell = [self tableViewCellFromIdentifier:cellType];
141 NSAssert(cell, @"Invalid cell");
142
143 // set cell values
144 switch ([indexPath section])
145 {
146 // advanced settings
147 case SECTION_ADVANCED_SETTINGS:
148 [self initAdvancedSettings:indexPath cell:cell];
149 break;
150
151 default:
152 break;
153 }
154
155 return cell;
156}
157
158// updates advanced settings in the UI
159- (void)initAdvancedSettings:(NSIndexPath *)indexPath cell:(UITableViewCell *)cell
160{
161 BOOL enable_3G_settings = [_params boolForKey:@"enable_3g_settings"];
162 switch (indexPath.row)
163 {
164 case 0:
165 {
167 [flagCell
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];
175 break;
176 }
177 case 1:
178 {
179 BOOL enable_tsg_settings = [_params boolForKey:@"enable_tsg_settings"];
181 [editCell
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];
187 break;
188 }
189 case 2:
190 {
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];
199 break;
200 }
201 case 3:
202 {
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];
215 break;
216 }
217 case 4:
218 {
220 [editCell
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];
226 break;
227 }
228 case 5:
229 {
231 [selCell setTitle:NSLocalizedString(
232 @"Security", @"'Security': Bookmark protocol security settings")];
233 [selCell setValue:ProtocolSecurityDescription([_params intForKey:@"security"])];
234 break;
235 }
236 case 6:
237 {
239 [[textCell label]
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")];
246 break;
247 }
248 case 7:
249 {
251 [[textCell label]
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")];
259 break;
260 }
261 case 8:
262 {
264 [flagCell
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];
272 break;
273 }
274 default:
275 NSLog(@"Invalid row index in settings table!");
276 break;
277 }
278}
279
280#pragma mark -
281#pragma mark Table view delegate
282
283- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
284{
285 UIViewController *viewCtrl = nil;
286
287 // determine view
288 switch ([indexPath row])
289 {
290 case 1:
291 if ([_params boolForKey:@"enable_tsg_settings"])
292 viewCtrl = [[[BookmarkGatewaySettingsController alloc] initWithBookmark:_bookmark]
293 autorelease];
294 break;
295 case 3:
296 if ([_params boolForKey:@"enable_3g_settings"])
297 viewCtrl = [[[ScreenSelectionController alloc]
298 initWithConnectionParams:_params
299 keyPath:@"settings_3g"] autorelease];
300 break;
301 case 4:
302 if ([_params boolForKey:@"enable_3g_settings"])
303 viewCtrl = [[[PerformanceEditorController alloc]
304 initWithConnectionParams:_params
305 keyPath:@"settings_3g"] autorelease];
306 break;
307 case 5:
308 viewCtrl = [[[EditorSelectionController alloc]
309 initWithConnectionParams:_params
310 entries:[NSArray arrayWithObject:@"security"]
311 selections:[NSArray arrayWithObject:SelectionForSecuritySetting()]]
312 autorelease];
313 break;
314 default:
315 break;
316 }
317
318 // display view
319 if (viewCtrl)
320 [[self navigationController] pushViewController:viewCtrl animated:YES];
321}
322
323#pragma mark -
324#pragma mark Text Field delegate
325
326- (BOOL)textFieldShouldReturn:(UITextField *)textField
327{
328 [textField resignFirstResponder];
329 return NO;
330}
331
332- (BOOL)textFieldShouldEndEditing:(UITextField *)textField
333{
334 switch (textField.tag)
335 {
336 // update remote program/work dir settings
337 case GET_TAG(SECTION_ADVANCED_SETTINGS, 6):
338 {
339 [_params setValue:[textField text] forKey:@"remote_program"];
340 break;
341 }
342
343 case GET_TAG(SECTION_ADVANCED_SETTINGS, 7):
344 {
345 [_params setValue:[textField text] forKey:@"working_dir"];
346 break;
347 }
348
349 default:
350 break;
351 }
352 return YES;
353}
354
355#pragma mark - Action handlers
356
357- (void)toggleSettingValue:(id)sender
358{
359 UISwitch *valueSwitch = (UISwitch *)sender;
360 switch (valueSwitch.tag)
361 {
362 case GET_TAG(SECTION_ADVANCED_SETTINGS, 0):
363 {
364 [_params setBool:[valueSwitch isOn] forKey:@"enable_tsg_settings"];
365 // TS gateway settings row
366 NSArray *indexPaths =
367 [NSArray arrayWithObjects:[NSIndexPath indexPathForRow:1
368 inSection:SECTION_ADVANCED_SETTINGS],
369 nil];
370 [[self tableView] reloadRowsAtIndexPaths:indexPaths
371 withRowAnimation:UITableViewRowAnimationNone];
372 break;
373 }
374
375 case GET_TAG(SECTION_ADVANCED_SETTINGS, 2):
376 {
377 [_params setBool:[valueSwitch isOn] forKey:@"enable_3g_settings"];
378 // 3G screen and 3G performance rows
379 NSArray *indexPaths =
380 [NSArray arrayWithObjects:[NSIndexPath indexPathForRow:3
381 inSection:SECTION_ADVANCED_SETTINGS],
382 [NSIndexPath indexPathForRow:4
383 inSection:SECTION_ADVANCED_SETTINGS],
384 nil];
385 [[self tableView] reloadRowsAtIndexPaths:indexPaths
386 withRowAnimation:UITableViewRowAnimationNone];
387 break;
388 }
389
390 case GET_TAG(SECTION_ADVANCED_SETTINGS, 8):
391 [_params setBool:[valueSwitch isOn] forKey:@"console"];
392 break;
393
394 default:
395 break;
396 }
397}
398
399@end