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 setTitle: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];
193 [flagCell setTitle:NSLocalizedString(@"Hide Tool Bar", "Show/Hide Tool Bar setting")];
194 [[flagCell toggle] setTag:GET_TAG_FROM_PATH(indexPath)];
196 setOn:[[NSUserDefaults standardUserDefaults] boolForKey:@"ui.hide_tool_bar"]];
197 [[flagCell toggle] addTarget:self
198 action:@selector(toggleSettingValue:)
199 forControlEvents:UIControlEventValueChanged];
206 setTitle:NSLocalizedString(@"Swap Mouse Buttons", "Swap Mouse Button UI setting")];
207 [[flagCell toggle] setTag:GET_TAG_FROM_PATH(indexPath)];
209 setOn:[[NSUserDefaults standardUserDefaults] boolForKey:@"ui.swap_mouse_buttons"]];
210 [[flagCell toggle] addTarget:self
211 action:@selector(toggleSettingValue:)
212 forControlEvents:UIControlEventValueChanged];
219 setTitle:NSLocalizedString(@"Invert Scrolling", "Invert Scrolling UI setting")];
220 [[flagCell toggle] setTag:GET_TAG_FROM_PATH(indexPath)];
222 setOn:[[NSUserDefaults standardUserDefaults] boolForKey:@"ui.invert_scrolling"]];
223 [[flagCell toggle] addTarget:self
224 action:@selector(toggleSettingValue:)
225 forControlEvents:UIControlEventValueChanged];
229 NSLog(
@"Invalid row index in settings table!");
235- (void)initCertificateHandlingSettings:(NSIndexPath *)indexPath cell:(UITableViewCell *)cell
237 switch ([indexPath row])
242 [flagCell setTitle:NSLocalizedString(@"Accept all Certificates",
243 "Accept All Certificates setting")];
244 [[flagCell toggle] setTag:GET_TAG_FROM_PATH(indexPath)];
245 [[flagCell toggle] setOn:[[NSUserDefaults standardUserDefaults]
246 boolForKey:@"security.accept_certificates"]];
247 [[flagCell toggle] addTarget:self
248 action:@selector(toggleSettingValue:)
249 forControlEvents:UIControlEventValueChanged];
255 [subCell setTitle:NSLocalizedString(@"Erase Certificate Cache",
256 @"Erase certificate cache button")];
260 NSLog(
@"Invalid row index in settings table!");
266#pragma mark Table view delegate
268- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
272 [tableView deselectRowAtIndexPath:indexPath animated:YES];
275 [[
self view] endEditing:NO];
278 if ([indexPath section] == SECTION_CERTIFICATE_HANDLING_SETTINGS && [indexPath row] == 1)
282 if ([[NSFileManager defaultManager]
283 removeItemAtPath:[[NSSearchPathForDirectoriesInDomains(
284 NSDocumentDirectory, NSUserDomainMask, YES) lastObject]
285 stringByAppendingPathComponent:
@"/.freerdp"]
287 [[self view] makeToast:NSLocalizedString(
@"Certificate Cache cleared!",
288 @"Clear Certificate cache success message")
289 duration:ToastDurationNormal
292 [[
self view] makeToast:NSLocalizedString(@"Error clearing the Certificate Cache!",
293 @"Clear Certificate cache failed message")
294 duration:ToastDurationNormal
300#pragma mark Action Handlers
302- (void)toggleSettingValue:(
id)sender
304 UISwitch *valueSwitch = (UISwitch *)sender;
305 switch ([valueSwitch tag])
307 case GET_TAG(SECTION_UI_SETTINGS, 0):
308 [[NSUserDefaults standardUserDefaults] setBool:[valueSwitch isOn]
309 forKey:
@"ui.hide_status_bar"];
312 case GET_TAG(SECTION_UI_SETTINGS, 1):
313 [[NSUserDefaults standardUserDefaults] setBool:[valueSwitch isOn]
314 forKey:
@"ui.hide_tool_bar"];
317 case GET_TAG(SECTION_UI_SETTINGS, 2):
318 [[NSUserDefaults standardUserDefaults] setBool:[valueSwitch isOn]
319 forKey:
@"ui.swap_mouse_buttons"];
320 SetSwapMouseButtonsFlag([valueSwitch isOn]);
323 case GET_TAG(SECTION_UI_SETTINGS, 3):
324 [[NSUserDefaults standardUserDefaults] setBool:[valueSwitch isOn]
325 forKey:
@"ui.invert_scrolling"];
326 SetInvertScrollingFlag([valueSwitch isOn]);
329 case GET_TAG(SECTION_CERTIFICATE_HANDLING_SETTINGS, 0):
330 [[NSUserDefaults standardUserDefaults] setBool:[valueSwitch isOn]
331 forKey:
@"security.accept_certificates"];