|
Packit |
1fb8d4 |
/*
|
|
Packit |
1fb8d4 |
Controller to specify application wide settings
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
Copyright 2013 Thincast Technologies GmbH, Author: Martin Fleisz
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
|
|
Packit |
1fb8d4 |
If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
Packit |
1fb8d4 |
*/
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
#import "AppSettingsController.h"
|
|
Packit |
1fb8d4 |
#import "Utils.h"
|
|
Packit |
1fb8d4 |
#import "Toast+UIView.h"
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
@implementation AppSettingsController
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
// keep this up-to-date for correct section display/hidding
|
|
Packit |
1fb8d4 |
#define SECTION_UI_SETTINGS 0
|
|
Packit |
1fb8d4 |
#define SECTION_CERTIFICATE_HANDLING_SETTINGS 1
|
|
Packit |
1fb8d4 |
#define SECTION_NUM_SECTIONS 2
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
#pragma mark -
|
|
Packit |
1fb8d4 |
#pragma mark Initialization
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
- (id)initWithStyle:(UITableViewStyle)style
|
|
Packit |
1fb8d4 |
{
|
|
Packit |
1fb8d4 |
if ((self = [super initWithStyle:style]))
|
|
Packit |
1fb8d4 |
{
|
|
Packit |
1fb8d4 |
UIImage* tabBarIcon = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"tabbar_icon_settings" ofType:@"png"]];
|
|
Packit |
1fb8d4 |
[self setTabBarItem:[[[UITabBarItem alloc] initWithTitle:NSLocalizedString(@"Settings", @"Tabbar item settings") image:tabBarIcon tag:0] autorelease]];
|
|
Packit |
1fb8d4 |
}
|
|
Packit |
1fb8d4 |
return self;
|
|
Packit |
1fb8d4 |
}
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
#pragma mark -
|
|
Packit |
1fb8d4 |
#pragma mark View lifecycle
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
- (void)viewDidLoad {
|
|
Packit |
1fb8d4 |
[super viewDidLoad];
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
// set title
|
|
Packit |
1fb8d4 |
[self setTitle:NSLocalizedString(@"Settings", @"App Settings title")];
|
|
Packit |
1fb8d4 |
}
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
- (void)viewWillDisappear:(BOOL)animated {
|
|
Packit |
1fb8d4 |
[super viewWillDisappear:animated];
|
|
Packit |
1fb8d4 |
}
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
// Override to allow orientations other than the default portrait orientation.
|
|
Packit |
1fb8d4 |
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
|
|
Packit |
1fb8d4 |
return YES;
|
|
Packit |
1fb8d4 |
}
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
- (void)dealloc {
|
|
Packit |
1fb8d4 |
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
|
Packit |
1fb8d4 |
[super dealloc];
|
|
Packit |
1fb8d4 |
}
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
#pragma mark -
|
|
Packit |
1fb8d4 |
#pragma mark Table view data source
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
|
|
Packit |
1fb8d4 |
// Return the number of sections.
|
|
Packit |
1fb8d4 |
return SECTION_NUM_SECTIONS;
|
|
Packit |
1fb8d4 |
}
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
|
Packit |
1fb8d4 |
// Return the number of rows in the section.
|
|
Packit |
1fb8d4 |
switch (section)
|
|
Packit |
1fb8d4 |
{
|
|
Packit |
1fb8d4 |
case SECTION_UI_SETTINGS: // UI settings
|
|
Packit |
1fb8d4 |
return 5;
|
|
Packit |
1fb8d4 |
case SECTION_CERTIFICATE_HANDLING_SETTINGS: // certificate handling settings
|
|
Packit |
1fb8d4 |
return 2;
|
|
Packit |
1fb8d4 |
default:
|
|
Packit |
1fb8d4 |
break;
|
|
Packit |
1fb8d4 |
}
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
return 0;
|
|
Packit |
1fb8d4 |
}
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
// set section headers
|
|
Packit |
1fb8d4 |
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
|
|
Packit |
1fb8d4 |
{
|
|
Packit |
1fb8d4 |
switch(section)
|
|
Packit |
1fb8d4 |
{
|
|
Packit |
1fb8d4 |
case SECTION_UI_SETTINGS:
|
|
Packit |
1fb8d4 |
return NSLocalizedString(@"User Interface", @"UI settings section title");
|
|
Packit |
1fb8d4 |
case SECTION_CERTIFICATE_HANDLING_SETTINGS:
|
|
Packit |
1fb8d4 |
return NSLocalizedString(@"Server Certificate Handling", @"Server Certificate Handling section title");
|
|
Packit |
1fb8d4 |
default:
|
|
Packit |
1fb8d4 |
return nil;
|
|
Packit |
1fb8d4 |
}
|
|
Packit |
1fb8d4 |
return @"unknown";
|
|
Packit |
1fb8d4 |
}
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
// Customize the appearance of table view cells.
|
|
Packit |
1fb8d4 |
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
// determine the required cell type
|
|
Packit |
1fb8d4 |
NSString* cellIdentifier = nil;
|
|
Packit |
1fb8d4 |
switch([indexPath section])
|
|
Packit |
1fb8d4 |
{
|
|
Packit |
1fb8d4 |
case SECTION_UI_SETTINGS:
|
|
Packit |
1fb8d4 |
{
|
|
Packit |
1fb8d4 |
switch([indexPath row])
|
|
Packit |
1fb8d4 |
{
|
|
Packit |
1fb8d4 |
case 0:
|
|
Packit |
1fb8d4 |
case 1:
|
|
Packit |
1fb8d4 |
case 2:
|
|
Packit |
1fb8d4 |
case 3:
|
|
Packit |
1fb8d4 |
case 4:
|
|
Packit |
1fb8d4 |
cellIdentifier = TableCellIdentifierYesNo;
|
|
Packit |
1fb8d4 |
break;
|
|
Packit |
1fb8d4 |
}
|
|
Packit |
1fb8d4 |
break;
|
|
Packit |
1fb8d4 |
}
|
|
Packit |
1fb8d4 |
case SECTION_CERTIFICATE_HANDLING_SETTINGS:
|
|
Packit |
1fb8d4 |
{
|
|
Packit |
1fb8d4 |
switch([indexPath row])
|
|
Packit |
1fb8d4 |
{
|
|
Packit |
1fb8d4 |
case 0:
|
|
Packit |
1fb8d4 |
cellIdentifier = TableCellIdentifierYesNo;
|
|
Packit |
1fb8d4 |
break;
|
|
Packit |
1fb8d4 |
case 1:
|
|
Packit |
1fb8d4 |
cellIdentifier = TableCellIdentifierSubEditor;
|
|
Packit |
1fb8d4 |
break;
|
|
Packit |
1fb8d4 |
}
|
|
Packit |
1fb8d4 |
break;
|
|
Packit |
1fb8d4 |
}
|
|
Packit |
1fb8d4 |
}
|
|
Packit |
1fb8d4 |
NSAssert(cellIdentifier != nil, @"Couldn't determine cell type");
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
// get the table view cell
|
|
Packit |
1fb8d4 |
UITableViewCell *cell = [self tableViewCellFromIdentifier:cellIdentifier];
|
|
Packit |
1fb8d4 |
NSAssert(cell, @"Invalid cell");
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
// set cell values
|
|
Packit |
1fb8d4 |
switch([indexPath section])
|
|
Packit |
1fb8d4 |
{
|
|
Packit |
1fb8d4 |
case SECTION_UI_SETTINGS:
|
|
Packit |
1fb8d4 |
[self initUISettings:indexPath cell:cell];
|
|
Packit |
1fb8d4 |
break;
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
case SECTION_CERTIFICATE_HANDLING_SETTINGS:
|
|
Packit |
1fb8d4 |
[self initCertificateHandlingSettings:indexPath cell:cell];
|
|
Packit |
1fb8d4 |
break;
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
default:
|
|
Packit |
1fb8d4 |
break;
|
|
Packit |
1fb8d4 |
}
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
return cell;
|
|
Packit |
1fb8d4 |
}
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
#pragma mark - Initialization helpers
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
// updates UI settings in the UI
|
|
Packit |
1fb8d4 |
- (void)initUISettings:(NSIndexPath*)indexPath cell:(UITableViewCell*)cell
|
|
Packit |
1fb8d4 |
{
|
|
Packit |
1fb8d4 |
switch([indexPath row])
|
|
Packit |
1fb8d4 |
{
|
|
Packit |
1fb8d4 |
case 0:
|
|
Packit |
1fb8d4 |
{
|
|
Packit |
1fb8d4 |
EditFlagTableViewCell* flagCell = (EditFlagTableViewCell*)cell;
|
|
Packit |
1fb8d4 |
[[flagCell label] setText:NSLocalizedString(@"Hide Status Bar", "Show/Hide Phone Status Bar setting")];
|
|
Packit |
1fb8d4 |
[[flagCell toggle] setTag:GET_TAG_FROM_PATH(indexPath)];
|
|
Packit |
1fb8d4 |
[[flagCell toggle] setOn:[[NSUserDefaults standardUserDefaults] boolForKey:@"ui.hide_status_bar"]];
|
|
Packit |
1fb8d4 |
[[flagCell toggle] addTarget:self action:@selector(toggleSettingValue:) forControlEvents:UIControlEventValueChanged];
|
|
Packit |
1fb8d4 |
break;
|
|
Packit |
1fb8d4 |
}
|
|
Packit |
1fb8d4 |
case 1:
|
|
Packit |
1fb8d4 |
{
|
|
Packit |
1fb8d4 |
EditFlagTableViewCell* flagCell = (EditFlagTableViewCell*)cell;
|
|
Packit |
1fb8d4 |
[[flagCell label] setText:NSLocalizedString(@"Hide Tool Bar", "Show/Hide Tool Bar setting")];
|
|
Packit |
1fb8d4 |
[[flagCell toggle] setTag:GET_TAG_FROM_PATH(indexPath)];
|
|
Packit |
1fb8d4 |
[[flagCell toggle] setOn:[[NSUserDefaults standardUserDefaults] boolForKey:@"ui.hide_tool_bar"]];
|
|
Packit |
1fb8d4 |
[[flagCell toggle] addTarget:self action:@selector(toggleSettingValue:) forControlEvents:UIControlEventValueChanged];
|
|
Packit |
1fb8d4 |
break;
|
|
Packit |
1fb8d4 |
}
|
|
Packit |
1fb8d4 |
case 2:
|
|
Packit |
1fb8d4 |
{
|
|
Packit |
1fb8d4 |
EditFlagTableViewCell* flagCell = (EditFlagTableViewCell*)cell;
|
|
Packit |
1fb8d4 |
[[flagCell label] setText:NSLocalizedString(@"Swap Mouse Buttons", "Swap Mouse Button UI setting")];
|
|
Packit |
1fb8d4 |
[[flagCell toggle] setTag:GET_TAG_FROM_PATH(indexPath)];
|
|
Packit |
1fb8d4 |
[[flagCell toggle] setOn:[[NSUserDefaults standardUserDefaults] boolForKey:@"ui.swap_mouse_buttons"]];
|
|
Packit |
1fb8d4 |
[[flagCell toggle] addTarget:self action:@selector(toggleSettingValue:) forControlEvents:UIControlEventValueChanged];
|
|
Packit |
1fb8d4 |
break;
|
|
Packit |
1fb8d4 |
}
|
|
Packit |
1fb8d4 |
case 3:
|
|
Packit |
1fb8d4 |
{
|
|
Packit |
1fb8d4 |
EditFlagTableViewCell* flagCell = (EditFlagTableViewCell*)cell;
|
|
Packit |
1fb8d4 |
[[flagCell label] setText:NSLocalizedString(@"Invert Scrolling", "Invert Scrolling UI setting")];
|
|
Packit |
1fb8d4 |
[[flagCell toggle] setTag:GET_TAG_FROM_PATH(indexPath)];
|
|
Packit |
1fb8d4 |
[[flagCell toggle] setOn:[[NSUserDefaults standardUserDefaults] boolForKey:@"ui.invert_scrolling"]];
|
|
Packit |
1fb8d4 |
[[flagCell toggle] addTarget:self action:@selector(toggleSettingValue:) forControlEvents:UIControlEventValueChanged];
|
|
Packit |
1fb8d4 |
break;
|
|
Packit |
1fb8d4 |
}
|
|
Packit |
1fb8d4 |
case 4:
|
|
Packit |
1fb8d4 |
{
|
|
Packit |
1fb8d4 |
EditFlagTableViewCell* flagCell = (EditFlagTableViewCell*)cell;
|
|
Packit |
1fb8d4 |
[[flagCell label] setText:NSLocalizedString(@"Touch Pointer Auto Scroll", "Touch Pointer Auto Scroll UI setting")];
|
|
Packit |
1fb8d4 |
[[flagCell toggle] setTag:GET_TAG_FROM_PATH(indexPath)];
|
|
Packit |
1fb8d4 |
[[flagCell toggle] setOn:[[NSUserDefaults standardUserDefaults] boolForKey:@"ui.auto_scroll_touchpointer"]];
|
|
Packit |
1fb8d4 |
[[flagCell toggle] addTarget:self action:@selector(toggleSettingValue:) forControlEvents:UIControlEventValueChanged];
|
|
Packit |
1fb8d4 |
break;
|
|
Packit |
1fb8d4 |
}
|
|
Packit |
1fb8d4 |
default:
|
|
Packit |
1fb8d4 |
NSLog(@"Invalid row index in settings table!");
|
|
Packit |
1fb8d4 |
break;
|
|
Packit |
1fb8d4 |
}
|
|
Packit |
1fb8d4 |
}
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
// updates certificate handling settings in the UI
|
|
Packit |
1fb8d4 |
- (void)initCertificateHandlingSettings:(NSIndexPath*)indexPath cell:(UITableViewCell*)cell
|
|
Packit |
1fb8d4 |
{
|
|
Packit |
1fb8d4 |
switch([indexPath row])
|
|
Packit |
1fb8d4 |
{
|
|
Packit |
1fb8d4 |
case 0:
|
|
Packit |
1fb8d4 |
{
|
|
Packit |
1fb8d4 |
EditFlagTableViewCell* flagCell = (EditFlagTableViewCell*)cell;
|
|
Packit |
1fb8d4 |
[[flagCell label] setText:NSLocalizedString(@"Accept all Certificates", "Accept All Certificates setting")];
|
|
Packit |
1fb8d4 |
[[flagCell toggle] setTag:GET_TAG_FROM_PATH(indexPath)];
|
|
Packit |
1fb8d4 |
[[flagCell toggle] setOn:[[NSUserDefaults standardUserDefaults] boolForKey:@"security.accept_certificates"]];
|
|
Packit |
1fb8d4 |
[[flagCell toggle] addTarget:self action:@selector(toggleSettingValue:) forControlEvents:UIControlEventValueChanged];
|
|
Packit |
1fb8d4 |
break;
|
|
Packit |
1fb8d4 |
}
|
|
Packit |
1fb8d4 |
case 1:
|
|
Packit |
1fb8d4 |
{
|
|
Packit |
1fb8d4 |
EditSubEditTableViewCell* subCell = (EditSubEditTableViewCell*)cell;
|
|
Packit |
1fb8d4 |
[[subCell label] setText:NSLocalizedString(@"Erase Certificate Cache", @"Erase certificate cache button")];
|
|
Packit |
1fb8d4 |
break;
|
|
Packit |
1fb8d4 |
}
|
|
Packit |
1fb8d4 |
default:
|
|
Packit |
1fb8d4 |
NSLog(@"Invalid row index in settings table!");
|
|
Packit |
1fb8d4 |
break;
|
|
Packit |
1fb8d4 |
}
|
|
Packit |
1fb8d4 |
}
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
#pragma mark -
|
|
Packit |
1fb8d4 |
#pragma mark Table view delegate
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
// deselect any row to fake a button-pressed like effect
|
|
Packit |
1fb8d4 |
[tableView deselectRowAtIndexPath:indexPath animated:YES];
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
// ensure everything is stored in our settings before we proceed
|
|
Packit |
1fb8d4 |
[[self view] endEditing:NO];
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
// clear certificate cache
|
|
Packit |
1fb8d4 |
if([indexPath section] == SECTION_CERTIFICATE_HANDLING_SETTINGS && [indexPath row] == 1)
|
|
Packit |
1fb8d4 |
{
|
|
Packit |
1fb8d4 |
// delete certificates cache
|
|
Packit |
1fb8d4 |
NSError* err;
|
|
Packit |
1fb8d4 |
if ([[NSFileManager defaultManager] removeItemAtPath:[[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:@"/.freerdp"] error:&err])
|
|
Packit |
1fb8d4 |
[[self view] makeToast:NSLocalizedString(@"Certificate Cache cleared!", @"Clear Certificate cache success message") duration:ToastDurationNormal position:@"center"];
|
|
Packit |
1fb8d4 |
else
|
|
Packit |
1fb8d4 |
[[self view] makeToast:NSLocalizedString(@"Error clearing the Certificate Cache!", @"Clear Certificate cache failed message") duration:ToastDurationNormal position:@"center"];
|
|
Packit |
1fb8d4 |
}
|
|
Packit |
1fb8d4 |
}
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
#pragma mark -
|
|
Packit |
1fb8d4 |
#pragma mark Action Handlers
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
- (void)toggleSettingValue:(id)sender
|
|
Packit |
1fb8d4 |
{
|
|
Packit |
1fb8d4 |
UISwitch* valueSwitch = (UISwitch*)sender;
|
|
Packit |
1fb8d4 |
switch([valueSwitch tag])
|
|
Packit |
1fb8d4 |
{
|
|
Packit |
1fb8d4 |
case GET_TAG(SECTION_UI_SETTINGS, 0):
|
|
Packit |
1fb8d4 |
[[NSUserDefaults standardUserDefaults] setBool:[valueSwitch isOn] forKey:@"ui.hide_status_bar"];
|
|
Packit |
1fb8d4 |
break;
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
case GET_TAG(SECTION_UI_SETTINGS, 1):
|
|
Packit |
1fb8d4 |
[[NSUserDefaults standardUserDefaults] setBool:[valueSwitch isOn] forKey:@"ui.hide_tool_bar"];
|
|
Packit |
1fb8d4 |
break;
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
case GET_TAG(SECTION_UI_SETTINGS, 2):
|
|
Packit |
1fb8d4 |
[[NSUserDefaults standardUserDefaults] setBool:[valueSwitch isOn] forKey:@"ui.swap_mouse_buttons"];
|
|
Packit |
1fb8d4 |
SetSwapMouseButtonsFlag([valueSwitch isOn]);
|
|
Packit |
1fb8d4 |
break;
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
case GET_TAG(SECTION_UI_SETTINGS, 3):
|
|
Packit |
1fb8d4 |
[[NSUserDefaults standardUserDefaults] setBool:[valueSwitch isOn] forKey:@"ui.invert_scrolling"];
|
|
Packit |
1fb8d4 |
SetInvertScrollingFlag([valueSwitch isOn]);
|
|
Packit |
1fb8d4 |
break;
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
case GET_TAG(SECTION_UI_SETTINGS, 4):
|
|
Packit |
1fb8d4 |
[[NSUserDefaults standardUserDefaults] setBool:[valueSwitch isOn] forKey:@"ui.auto_scroll_touchpointer"];
|
|
Packit |
1fb8d4 |
SetInvertScrollingFlag([valueSwitch isOn]);
|
|
Packit |
1fb8d4 |
break;
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
case GET_TAG(SECTION_CERTIFICATE_HANDLING_SETTINGS, 0):
|
|
Packit |
1fb8d4 |
[[NSUserDefaults standardUserDefaults] setBool:[valueSwitch isOn] forKey:@"security.accept_certificates"];
|
|
Packit |
1fb8d4 |
break;
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
default:
|
|
Packit |
1fb8d4 |
break;
|
|
Packit |
1fb8d4 |
}
|
|
Packit |
1fb8d4 |
}
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
@end
|
|
Packit |
1fb8d4 |
|