11#import "AppSettingsController.h"
13#import "Toast+UIView.h"
14#include <freerdp/settings.h>
19#define SECTION_UI_SETTINGS 0
20#define SECTION_CERTIFICATE_HANDLING_SETTINGS 1
21#define SECTION_NUM_SECTIONS 2
24#pragma mark Initialization
26- (id)initWithStyle:(UITableViewStyle)style
28 if ((
self = [super initWithStyle:style]))
30 UIImage *tabBarIcon = [UIImage
31 imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"tabbar_icon_settings"
34 setTabBarItem:[[[UITabBarItem alloc]
35 initWithTitle:NSLocalizedString(@"Settings", @"Tabbar item settings")
43#pragma mark View lifecycle
50 [
self setTitle:NSLocalizedString(@"Settings", @"App Settings title")];
53- (void)viewWillDisappear:(BOOL)animated
55 [
super viewWillDisappear:animated];
59- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
66 [[NSNotificationCenter defaultCenter] removeObserver:self];
71#pragma mark Table view data source
73- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
76 return SECTION_NUM_SECTIONS;
79- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
84 case SECTION_UI_SETTINGS:
86 return IsPad() ? 2 : 3;
87 case SECTION_CERTIFICATE_HANDLING_SETTINGS:
97- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
101 case SECTION_UI_SETTINGS:
102 return NSLocalizedString(
@"User Interface",
@"UI settings section title");
103 case SECTION_CERTIFICATE_HANDLING_SETTINGS:
104 return NSLocalizedString(
@"Server Certificate Handling",
105 @"Server Certificate Handling section title");
113- (UITableViewCell *)tableView:(UITableView *)tableView
114 cellForRowAtIndexPath:(NSIndexPath *)indexPath
118 NSString *cellIdentifier = nil;
119 switch ([indexPath section])
121 case SECTION_UI_SETTINGS:
123 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])
182 setTitle:NSLocalizedString(@"Swap Mouse Buttons", "Swap Mouse Button UI setting")];
183 [[flagCell toggle] setTag:GET_TAG_FROM_PATH(indexPath)];
185 setOn:[[NSUserDefaults standardUserDefaults] boolForKey:@"ui.swap_mouse_buttons"]];
186 [[flagCell toggle] addTarget:self
187 action:@selector(toggleSettingValue:)
188 forControlEvents:UIControlEventValueChanged];
195 setTitle:NSLocalizedString(@"Invert Scrolling", "Invert Scrolling UI setting")];
196 [[flagCell toggle] setTag:GET_TAG_FROM_PATH(indexPath)];
198 setOn:[[NSUserDefaults standardUserDefaults] boolForKey:@"ui.invert_scrolling"]];
199 [[flagCell toggle] addTarget:self
200 action:@selector(toggleSettingValue:)
201 forControlEvents:UIControlEventValueChanged];
208 setTitle:NSLocalizedString(@"Avoid Screen Edges", "Avoid Screen Edges UI setting")];
209 [[flagCell toggle] setTag:GET_TAG_FROM_PATH(indexPath)];
211 setOn:[[NSUserDefaults standardUserDefaults] boolForKey:@"ui.avoid_screen_edges"]];
212 [[flagCell toggle] addTarget:self
213 action:@selector(toggleSettingValue:)
214 forControlEvents:UIControlEventValueChanged];
218 NSLog(
@"Invalid row index in settings table!");
224- (void)initCertificateHandlingSettings:(NSIndexPath *)indexPath cell:(UITableViewCell *)cell
226 switch ([indexPath row])
231 [flagCell setTitle:NSLocalizedString(@"Accept all Certificates",
232 "Accept All Certificates setting")];
233 [[flagCell toggle] setTag:GET_TAG_FROM_PATH(indexPath)];
234 [[flagCell toggle] setOn:[[NSUserDefaults standardUserDefaults]
235 boolForKey:@"security.accept_certificates"]];
236 [[flagCell toggle] addTarget:self
237 action:@selector(toggleSettingValue:)
238 forControlEvents:UIControlEventValueChanged];
244 [subCell setTitle:NSLocalizedString(@"Erase Certificate Cache",
245 @"Erase certificate cache button")];
249 NSLog(
@"Invalid row index in settings table!");
255#pragma mark Table view delegate
257- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
261 [tableView deselectRowAtIndexPath:indexPath animated:YES];
264 [[
self view] endEditing:NO];
267 if ([indexPath section] == SECTION_CERTIFICATE_HANDLING_SETTINGS && [indexPath row] == 1)
274 NSString *configPath = [NSString stringWithUTF8String:config];
275 NSFileManager *fileManager = [NSFileManager defaultManager];
276 NSString *path = [configPath stringByAppendingPathComponent:@"server"];
277 if ([fileManager fileExistsAtPath:path] && ![fileManager removeItemAtPath:path
289 [[
self view] makeToast:NSLocalizedString(@"Certificate Cache cleared!",
290 @"Clear Certificate cache success message")
291 duration:ToastDurationNormal
294 [[
self view] makeToast:NSLocalizedString(@"Error clearing the Certificate Cache!",
295 @"Clear Certificate cache failed message")
296 duration:ToastDurationNormal
302#pragma mark Action Handlers
304- (void)toggleSettingValue:(
id)sender
306 UISwitch *valueSwitch = (UISwitch *)sender;
307 switch ([valueSwitch tag])
309 case GET_TAG(SECTION_UI_SETTINGS, 0):
310 [[NSUserDefaults standardUserDefaults] setBool:[valueSwitch isOn]
311 forKey:
@"ui.swap_mouse_buttons"];
312 SetSwapMouseButtonsFlag([valueSwitch isOn]);
315 case GET_TAG(SECTION_UI_SETTINGS, 1):
316 [[NSUserDefaults standardUserDefaults] setBool:[valueSwitch isOn]
317 forKey:
@"ui.invert_scrolling"];
318 SetInvertScrollingFlag([valueSwitch isOn]);
321 case GET_TAG(SECTION_UI_SETTINGS, 2):
322 [[NSUserDefaults standardUserDefaults] setBool:[valueSwitch isOn]
323 forKey:
@"ui.avoid_screen_edges"];
326 case GET_TAG(SECTION_CERTIFICATE_HANDLING_SETTINGS, 0):
327 [[NSUserDefaults standardUserDefaults] setBool:[valueSwitch isOn]
328 forKey:
@"security.accept_certificates"];
WINPR_ATTR_NODISCARD FREERDP_API char * freerdp_settings_get_config_path(void)
return the configuration directory for the library