11 #import "AppSettingsController.h"
13 #import "Toast+UIView.h"
18 #define SECTION_UI_SETTINGS 0
19 #define SECTION_CERTIFICATE_HANDLING_SETTINGS 1
20 #define SECTION_NUM_SECTIONS 2
23 #pragma mark Initialization
25 - (id)initWithStyle:(UITableViewStyle)style
27 if ((
self = [super initWithStyle:style]))
29 UIImage *tabBarIcon = [UIImage
30 imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"tabbar_icon_settings"
33 setTabBarItem:[[[UITabBarItem alloc]
34 initWithTitle:NSLocalizedString(@"Settings", @"Tabbar item settings")
42 #pragma mark View lifecycle
49 [
self setTitle:NSLocalizedString(@"Settings", @"App Settings title")];
52 - (void)viewWillDisappear:(BOOL)animated
54 [
super viewWillDisappear:animated];
58 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
65 [[NSNotificationCenter defaultCenter] removeObserver:self];
70 #pragma mark Table view data source
72 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
75 return SECTION_NUM_SECTIONS;
78 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
83 case SECTION_UI_SETTINGS:
85 case SECTION_CERTIFICATE_HANDLING_SETTINGS:
95 - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
99 case SECTION_UI_SETTINGS:
100 return NSLocalizedString(
@"User Interface",
@"UI settings section title");
101 case SECTION_CERTIFICATE_HANDLING_SETTINGS:
102 return NSLocalizedString(
@"Server Certificate Handling",
103 @"Server Certificate Handling section title");
111 - (UITableViewCell *)tableView:(UITableView *)tableView
112 cellForRowAtIndexPath:(NSIndexPath *)indexPath
116 NSString *cellIdentifier = nil;
117 switch ([indexPath section])
119 case SECTION_UI_SETTINGS:
121 switch ([indexPath row])
128 cellIdentifier = TableCellIdentifierYesNo;
133 case SECTION_CERTIFICATE_HANDLING_SETTINGS:
135 switch ([indexPath row])
138 cellIdentifier = TableCellIdentifierYesNo;
141 cellIdentifier = TableCellIdentifierSubEditor;
147 NSAssert(cellIdentifier != nil,
@"Couldn't determine cell type");
150 UITableViewCell *cell = [
self tableViewCellFromIdentifier:cellIdentifier];
151 NSAssert(cell,
@"Invalid cell");
154 switch ([indexPath section])
156 case SECTION_UI_SETTINGS:
157 [
self initUISettings:indexPath cell:cell];
160 case SECTION_CERTIFICATE_HANDLING_SETTINGS:
161 [
self initCertificateHandlingSettings:indexPath cell:cell];
171 #pragma mark - Initialization helpers
174 - (void)initUISettings:(NSIndexPath *)indexPath cell:(UITableViewCell *)cell
176 switch ([indexPath row])
181 [[flagCell label] setText:NSLocalizedString(@"Hide Status Bar",
182 "Show/Hide Phone Status Bar setting")];
183 [[flagCell toggle] setTag:GET_TAG_FROM_PATH(indexPath)];
185 setOn:[[NSUserDefaults standardUserDefaults] boolForKey:@"ui.hide_status_bar"]];
186 [[flagCell toggle] addTarget:self
187 action:@selector(toggleSettingValue:)
188 forControlEvents:UIControlEventValueChanged];
195 setText:NSLocalizedString(@"Hide Tool Bar", "Show/Hide Tool Bar setting")];
196 [[flagCell toggle] setTag:GET_TAG_FROM_PATH(indexPath)];
198 setOn:[[NSUserDefaults standardUserDefaults] boolForKey:@"ui.hide_tool_bar"]];
199 [[flagCell toggle] addTarget:self
200 action:@selector(toggleSettingValue:)
201 forControlEvents:UIControlEventValueChanged];
208 setText:NSLocalizedString(@"Swap Mouse Buttons", "Swap Mouse Button UI setting")];
209 [[flagCell toggle] setTag:GET_TAG_FROM_PATH(indexPath)];
211 setOn:[[NSUserDefaults standardUserDefaults] boolForKey:@"ui.swap_mouse_buttons"]];
212 [[flagCell toggle] addTarget:self
213 action:@selector(toggleSettingValue:)
214 forControlEvents:UIControlEventValueChanged];
221 setText:NSLocalizedString(@"Invert Scrolling", "Invert Scrolling UI setting")];
222 [[flagCell toggle] setTag:GET_TAG_FROM_PATH(indexPath)];
224 setOn:[[NSUserDefaults standardUserDefaults] boolForKey:@"ui.invert_scrolling"]];
225 [[flagCell toggle] addTarget:self
226 action:@selector(toggleSettingValue:)
227 forControlEvents:UIControlEventValueChanged];
233 [[flagCell label] setText:NSLocalizedString(@"Touch Pointer Auto Scroll",
234 "Touch Pointer Auto Scroll UI setting")];
235 [[flagCell toggle] setTag:GET_TAG_FROM_PATH(indexPath)];
236 [[flagCell toggle] setOn:[[NSUserDefaults standardUserDefaults]
237 boolForKey:@"ui.auto_scroll_touchpointer"]];
238 [[flagCell toggle] addTarget:self
239 action:@selector(toggleSettingValue:)
240 forControlEvents:UIControlEventValueChanged];
244 NSLog(
@"Invalid row index in settings table!");
250 - (void)initCertificateHandlingSettings:(NSIndexPath *)indexPath cell:(UITableViewCell *)cell
252 switch ([indexPath row])
257 [[flagCell label] setText:NSLocalizedString(@"Accept all Certificates",
258 "Accept All Certificates setting")];
259 [[flagCell toggle] setTag:GET_TAG_FROM_PATH(indexPath)];
260 [[flagCell toggle] setOn:[[NSUserDefaults standardUserDefaults]
261 boolForKey:@"security.accept_certificates"]];
262 [[flagCell toggle] addTarget:self
263 action:@selector(toggleSettingValue:)
264 forControlEvents:UIControlEventValueChanged];
270 [[subCell label] setText:NSLocalizedString(@"Erase Certificate Cache",
271 @"Erase certificate cache button")];
275 NSLog(
@"Invalid row index in settings table!");
281 #pragma mark Table view delegate
283 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
287 [tableView deselectRowAtIndexPath:indexPath animated:YES];
290 [[
self view] endEditing:NO];
293 if ([indexPath section] == SECTION_CERTIFICATE_HANDLING_SETTINGS && [indexPath row] == 1)
297 if ([[NSFileManager defaultManager]
298 removeItemAtPath:[[NSSearchPathForDirectoriesInDomains(
299 NSDocumentDirectory, NSUserDomainMask, YES) lastObject]
300 stringByAppendingPathComponent:
@"/.freerdp"]
302 [[
self view] makeToast:NSLocalizedString(@"Certificate Cache cleared!",
303 @"Clear Certificate cache success message")
304 duration:ToastDurationNormal
307 [[
self view] makeToast:NSLocalizedString(@"Error clearing the Certificate Cache!",
308 @"Clear Certificate cache failed message")
309 duration:ToastDurationNormal
315 #pragma mark Action Handlers
317 - (void)toggleSettingValue:(
id)sender
319 UISwitch *valueSwitch = (UISwitch *)sender;
320 switch ([valueSwitch tag])
322 case GET_TAG(SECTION_UI_SETTINGS, 0):
323 [[NSUserDefaults standardUserDefaults] setBool:[valueSwitch isOn]
324 forKey:
@"ui.hide_status_bar"];
327 case GET_TAG(SECTION_UI_SETTINGS, 1):
328 [[NSUserDefaults standardUserDefaults] setBool:[valueSwitch isOn]
329 forKey:
@"ui.hide_tool_bar"];
332 case GET_TAG(SECTION_UI_SETTINGS, 2):
333 [[NSUserDefaults standardUserDefaults] setBool:[valueSwitch isOn]
334 forKey:
@"ui.swap_mouse_buttons"];
335 SetSwapMouseButtonsFlag([valueSwitch isOn]);
338 case GET_TAG(SECTION_UI_SETTINGS, 3):
339 [[NSUserDefaults standardUserDefaults] setBool:[valueSwitch isOn]
340 forKey:
@"ui.invert_scrolling"];
341 SetInvertScrollingFlag([valueSwitch isOn]);
344 case GET_TAG(SECTION_UI_SETTINGS, 4):
345 [[NSUserDefaults standardUserDefaults] setBool:[valueSwitch isOn]
346 forKey:
@"ui.auto_scroll_touchpointer"];
347 SetInvertScrollingFlag([valueSwitch isOn]);
350 case GET_TAG(SECTION_CERTIFICATE_HANDLING_SETTINGS, 0):
351 [[NSUserDefaults standardUserDefaults] setBool:[valueSwitch isOn]
352 forKey:
@"security.accept_certificates"];