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])
127 cellIdentifier = TableCellIdentifierYesNo;
132 case SECTION_CERTIFICATE_HANDLING_SETTINGS:
134 switch ([indexPath row])
137 cellIdentifier = TableCellIdentifierYesNo;
140 cellIdentifier = TableCellIdentifierSubEditor;
146 NSAssert(cellIdentifier != nil,
@"Couldn't determine cell type");
149 UITableViewCell *cell = [
self tableViewCellFromIdentifier:cellIdentifier];
150 NSAssert(cell,
@"Invalid cell");
153 switch ([indexPath section])
155 case SECTION_UI_SETTINGS:
156 [
self initUISettings:indexPath cell:cell];
159 case SECTION_CERTIFICATE_HANDLING_SETTINGS:
160 [
self initCertificateHandlingSettings:indexPath cell:cell];
170#pragma mark - Initialization helpers
173- (void)initUISettings:(NSIndexPath *)indexPath cell:(UITableViewCell *)cell
175 switch ([indexPath row])
180 [[flagCell label] setText:NSLocalizedString(@"Hide Status Bar",
181 "Show/Hide Phone Status Bar setting")];
182 [[flagCell toggle] setTag:GET_TAG_FROM_PATH(indexPath)];
184 setOn:[[NSUserDefaults standardUserDefaults] boolForKey:@"ui.hide_status_bar"]];
185 [[flagCell toggle] addTarget:self
186 action:@selector(toggleSettingValue:)
187 forControlEvents:UIControlEventValueChanged];
194 setText:NSLocalizedString(@"Hide Tool Bar", "Show/Hide Tool Bar setting")];
195 [[flagCell toggle] setTag:GET_TAG_FROM_PATH(indexPath)];
197 setOn:[[NSUserDefaults standardUserDefaults] boolForKey:@"ui.hide_tool_bar"]];
198 [[flagCell toggle] addTarget:self
199 action:@selector(toggleSettingValue:)
200 forControlEvents:UIControlEventValueChanged];
207 setText:NSLocalizedString(@"Swap Mouse Buttons", "Swap Mouse Button UI setting")];
208 [[flagCell toggle] setTag:GET_TAG_FROM_PATH(indexPath)];
210 setOn:[[NSUserDefaults standardUserDefaults] boolForKey:@"ui.swap_mouse_buttons"]];
211 [[flagCell toggle] addTarget:self
212 action:@selector(toggleSettingValue:)
213 forControlEvents:UIControlEventValueChanged];
220 setText:NSLocalizedString(@"Invert Scrolling", "Invert Scrolling UI setting")];
221 [[flagCell toggle] setTag:GET_TAG_FROM_PATH(indexPath)];
223 setOn:[[NSUserDefaults standardUserDefaults] boolForKey:@"ui.invert_scrolling"]];
224 [[flagCell toggle] addTarget:self
225 action:@selector(toggleSettingValue:)
226 forControlEvents:UIControlEventValueChanged];
230 NSLog(
@"Invalid row index in settings table!");
236- (void)initCertificateHandlingSettings:(NSIndexPath *)indexPath cell:(UITableViewCell *)cell
238 switch ([indexPath row])
243 [[flagCell label] setText:NSLocalizedString(@"Accept all Certificates",
244 "Accept All Certificates setting")];
245 [[flagCell toggle] setTag:GET_TAG_FROM_PATH(indexPath)];
246 [[flagCell toggle] setOn:[[NSUserDefaults standardUserDefaults]
247 boolForKey:@"security.accept_certificates"]];
248 [[flagCell toggle] addTarget:self
249 action:@selector(toggleSettingValue:)
250 forControlEvents:UIControlEventValueChanged];
256 [[subCell label] setText:NSLocalizedString(@"Erase Certificate Cache",
257 @"Erase certificate cache button")];
261 NSLog(
@"Invalid row index in settings table!");
267#pragma mark Table view delegate
269- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
273 [tableView deselectRowAtIndexPath:indexPath animated:YES];
276 [[
self view] endEditing:NO];
279 if ([indexPath section] == SECTION_CERTIFICATE_HANDLING_SETTINGS && [indexPath row] == 1)
283 if ([[NSFileManager defaultManager]
284 removeItemAtPath:[[NSSearchPathForDirectoriesInDomains(
285 NSDocumentDirectory, NSUserDomainMask, YES) lastObject]
286 stringByAppendingPathComponent:
@"/.freerdp"]
288 [[self view] makeToast:NSLocalizedString(
@"Certificate Cache cleared!",
289 @"Clear Certificate cache success message")
290 duration:ToastDurationNormal
293 [[
self view] makeToast:NSLocalizedString(@"Error clearing the Certificate Cache!",
294 @"Clear Certificate cache failed message")
295 duration:ToastDurationNormal
301#pragma mark Action Handlers
303- (void)toggleSettingValue:(
id)sender
305 UISwitch *valueSwitch = (UISwitch *)sender;
306 switch ([valueSwitch tag])
308 case GET_TAG(SECTION_UI_SETTINGS, 0):
309 [[NSUserDefaults standardUserDefaults] setBool:[valueSwitch isOn]
310 forKey:
@"ui.hide_status_bar"];
313 case GET_TAG(SECTION_UI_SETTINGS, 1):
314 [[NSUserDefaults standardUserDefaults] setBool:[valueSwitch isOn]
315 forKey:
@"ui.hide_tool_bar"];
318 case GET_TAG(SECTION_UI_SETTINGS, 2):
319 [[NSUserDefaults standardUserDefaults] setBool:[valueSwitch isOn]
320 forKey:
@"ui.swap_mouse_buttons"];
321 SetSwapMouseButtonsFlag([valueSwitch isOn]);
324 case GET_TAG(SECTION_UI_SETTINGS, 3):
325 [[NSUserDefaults standardUserDefaults] setBool:[valueSwitch isOn]
326 forKey:
@"ui.invert_scrolling"];
327 SetInvertScrollingFlag([valueSwitch isOn]);
330 case GET_TAG(SECTION_CERTIFICATE_HANDLING_SETTINGS, 0):
331 [[NSUserDefaults standardUserDefaults] setBool:[valueSwitch isOn]
332 forKey:
@"security.accept_certificates"];