FreeRDP
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Modules Pages
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:UITableViewStyleGrouped]))
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 label]
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];
175 break;
176 }
177 case 1:
178 {
179 BOOL enable_tsg_settings = [_params boolForKey:@"enable_tsg_settings"];
181 [[editCell label]
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];
187 break;
188 }
189 case 2:
190 {
192 [[flagCell label]
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];
200 break;
201 }
202 case 3:
203 {
205 [[selCell label]
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"];
213 [[selCell selection]
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];
219 break;
220 }
221 case 4:
222 {
224 [[editCell label]
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];
230 break;
231 }
232 case 5:
233 {
235 [[selCell label]
236 setText:NSLocalizedString(@"Security",
237 @"'Security': Bookmark protocol security settings")];
238 [[selCell selection]
239 setText:ProtocolSecurityDescription([_params intForKey:@"security"])];
240 break;
241 }
242 case 6:
243 {
245 [[textCell label]
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];
253 break;
254 }
255 case 7:
256 {
258 [[textCell label]
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];
267 break;
268 }
269 case 8:
270 {
272 [[flagCell label]
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];
280 break;
281 }
282 default:
283 NSLog(@"Invalid row index in settings table!");
284 break;
285 }
286}
287
288#pragma mark -
289#pragma mark Table view delegate
290
291- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
292{
293 UIViewController *viewCtrl = nil;
294
295 // determine view
296 switch ([indexPath row])
297 {
298 case 1:
299 if ([_params boolForKey:@"enable_tsg_settings"])
300 viewCtrl = [[[BookmarkGatewaySettingsController alloc] initWithBookmark:_bookmark]
301 autorelease];
302 break;
303 case 3:
304 if ([_params boolForKey:@"enable_3g_settings"])
305 viewCtrl = [[[ScreenSelectionController alloc]
306 initWithConnectionParams:_params
307 keyPath:@"settings_3g"] autorelease];
308 break;
309 case 4:
310 if ([_params boolForKey:@"enable_3g_settings"])
311 viewCtrl = [[[PerformanceEditorController alloc]
312 initWithConnectionParams:_params
313 keyPath:@"settings_3g"] autorelease];
314 break;
315 case 5:
316 viewCtrl = [[[EditorSelectionController alloc]
317 initWithConnectionParams:_params
318 entries:[NSArray arrayWithObject:@"security"]
319 selections:[NSArray arrayWithObject:SelectionForSecuritySetting()]]
320 autorelease];
321 break;
322 default:
323 break;
324 }
325
326 // display view
327 if (viewCtrl)
328 [[self navigationController] pushViewController:viewCtrl animated:YES];
329}
330
331#pragma mark -
332#pragma mark Text Field delegate
333
334- (BOOL)textFieldShouldReturn:(UITextField *)textField
335{
336 [textField resignFirstResponder];
337 return NO;
338}
339
340- (BOOL)textFieldShouldEndEditing:(UITextField *)textField
341{
342 switch (textField.tag)
343 {
344 // update remote program/work dir settings
345 case GET_TAG(SECTION_ADVANCED_SETTINGS, 6):
346 {
347 [_params setValue:[textField text] forKey:@"remote_program"];
348 break;
349 }
350
351 case GET_TAG(SECTION_ADVANCED_SETTINGS, 7):
352 {
353 [_params setValue:[textField text] forKey:@"working_dir"];
354 break;
355 }
356
357 default:
358 break;
359 }
360 return YES;
361}
362
363#pragma mark - Action handlers
364
365- (void)toggleSettingValue:(id)sender
366{
367 UISwitch *valueSwitch = (UISwitch *)sender;
368 switch (valueSwitch.tag)
369 {
370 case GET_TAG(SECTION_ADVANCED_SETTINGS, 0):
371 {
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],
378 nil];
379 [[self tableView] reloadRowsAtIndexPaths:indexPaths
380 withRowAnimation:UITableViewRowAnimationNone];
381 break;
382 }
383
384 case GET_TAG(SECTION_ADVANCED_SETTINGS, 2):
385 {
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],
392 nil];
393 [[self tableView] reloadRowsAtIndexPaths:indexPaths
394 withRowAnimation:UITableViewRowAnimationNone];
395 break;
396 }
397
398 case GET_TAG(SECTION_ADVANCED_SETTINGS, 8):
399 [_params setBool:[valueSwitch isOn] forKey:@"console"];
400 break;
401
402 default:
403 break;
404 }
405}
406
407@end