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 case SECTION_CERTIFICATE_HANDLING_SETTINGS:
96- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
100 case SECTION_UI_SETTINGS:
101 return NSLocalizedString(
@"User Interface",
@"UI settings section title");
102 case SECTION_CERTIFICATE_HANDLING_SETTINGS:
103 return NSLocalizedString(
@"Server Certificate Handling",
104 @"Server Certificate Handling section title");
112- (UITableViewCell *)tableView:(UITableView *)tableView
113 cellForRowAtIndexPath:(NSIndexPath *)indexPath
117 NSString *cellIdentifier = nil;
118 switch ([indexPath section])
120 case SECTION_UI_SETTINGS:
122 switch ([indexPath row])
126 cellIdentifier = TableCellIdentifierYesNo;
131 case SECTION_CERTIFICATE_HANDLING_SETTINGS:
133 switch ([indexPath row])
136 cellIdentifier = TableCellIdentifierYesNo;
139 cellIdentifier = TableCellIdentifierSubEditor;
145 NSAssert(cellIdentifier != nil,
@"Couldn't determine cell type");
148 UITableViewCell *cell = [
self tableViewCellFromIdentifier:cellIdentifier];
149 NSAssert(cell,
@"Invalid cell");
152 switch ([indexPath section])
154 case SECTION_UI_SETTINGS:
155 [
self initUISettings:indexPath cell:cell];
158 case SECTION_CERTIFICATE_HANDLING_SETTINGS:
159 [
self initCertificateHandlingSettings:indexPath cell:cell];
169#pragma mark - Initialization helpers
172- (void)initUISettings:(NSIndexPath *)indexPath cell:(UITableViewCell *)cell
174 switch ([indexPath row])
180 setTitle:NSLocalizedString(@"Swap Mouse Buttons", "Swap Mouse Button UI setting")];
181 [[flagCell toggle] setTag:GET_TAG_FROM_PATH(indexPath)];
183 setOn:[[NSUserDefaults standardUserDefaults] boolForKey:@"ui.swap_mouse_buttons"]];
184 [[flagCell toggle] addTarget:self
185 action:@selector(toggleSettingValue:)
186 forControlEvents:UIControlEventValueChanged];
193 setTitle:NSLocalizedString(@"Invert Scrolling", "Invert Scrolling UI setting")];
194 [[flagCell toggle] setTag:GET_TAG_FROM_PATH(indexPath)];
196 setOn:[[NSUserDefaults standardUserDefaults] boolForKey:@"ui.invert_scrolling"]];
197 [[flagCell toggle] addTarget:self
198 action:@selector(toggleSettingValue:)
199 forControlEvents:UIControlEventValueChanged];
203 NSLog(
@"Invalid row index in settings table!");
209- (void)initCertificateHandlingSettings:(NSIndexPath *)indexPath cell:(UITableViewCell *)cell
211 switch ([indexPath row])
216 [flagCell setTitle:NSLocalizedString(@"Accept all Certificates",
217 "Accept All Certificates setting")];
218 [[flagCell toggle] setTag:GET_TAG_FROM_PATH(indexPath)];
219 [[flagCell toggle] setOn:[[NSUserDefaults standardUserDefaults]
220 boolForKey:@"security.accept_certificates"]];
221 [[flagCell toggle] addTarget:self
222 action:@selector(toggleSettingValue:)
223 forControlEvents:UIControlEventValueChanged];
229 [subCell setTitle:NSLocalizedString(@"Erase Certificate Cache",
230 @"Erase certificate cache button")];
234 NSLog(
@"Invalid row index in settings table!");
240#pragma mark Table view delegate
242- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
246 [tableView deselectRowAtIndexPath:indexPath animated:YES];
249 [[
self view] endEditing:NO];
252 if ([indexPath section] == SECTION_CERTIFICATE_HANDLING_SETTINGS && [indexPath row] == 1)
259 NSString *configPath = [NSString stringWithUTF8String:config];
260 NSFileManager *fileManager = [NSFileManager defaultManager];
261 NSString *path = [configPath stringByAppendingPathComponent:@"server"];
262 if ([fileManager fileExistsAtPath:path] && ![fileManager removeItemAtPath:path
274 [[
self view] makeToast:NSLocalizedString(@"Certificate Cache cleared!",
275 @"Clear Certificate cache success message")
276 duration:ToastDurationNormal
279 [[
self view] makeToast:NSLocalizedString(@"Error clearing the Certificate Cache!",
280 @"Clear Certificate cache failed message")
281 duration:ToastDurationNormal
287#pragma mark Action Handlers
289- (void)toggleSettingValue:(
id)sender
291 UISwitch *valueSwitch = (UISwitch *)sender;
292 switch ([valueSwitch tag])
294 case GET_TAG(SECTION_UI_SETTINGS, 0):
295 [[NSUserDefaults standardUserDefaults] setBool:[valueSwitch isOn]
296 forKey:
@"ui.swap_mouse_buttons"];
297 SetSwapMouseButtonsFlag([valueSwitch isOn]);
300 case GET_TAG(SECTION_UI_SETTINGS, 1):
301 [[NSUserDefaults standardUserDefaults] setBool:[valueSwitch isOn]
302 forKey:
@"ui.invert_scrolling"];
303 SetInvertScrollingFlag([valueSwitch isOn]);
306 case GET_TAG(SECTION_CERTIFICATE_HANDLING_SETTINGS, 0):
307 [[NSUserDefaults standardUserDefaults] setBool:[valueSwitch isOn]
308 forKey:
@"security.accept_certificates"];
WINPR_ATTR_NODISCARD FREERDP_API char * freerdp_settings_get_config_path(void)
return the configuration directory for the library