Files
FreeRDP/client/iOS/Controllers/BookmarkGatewaySettingsController.m

243 lines
5.9 KiB
Mathematica
Raw Permalink Normal View History

2013-05-07 12:05:21 +02:00
//
// BookmarkGatewaySettingsController.m
// FreeRDP
//
2013-12-04 11:37:57 +01:00
// Created by a Thincast Developer on 4/30/13.
2013-05-07 12:05:21 +02:00
//
//
#import "BookmarkGatewaySettingsController.h"
2013-05-08 14:50:29 +02:00
#import "Bookmark.h"
#import "Utils.h"
#import "EditorSelectionController.h"
#define SECTION_TSGATEWAY_SETTINGS 0
#define SECTION_COUNT 1
2013-05-07 12:05:21 +02:00
@interface BookmarkGatewaySettingsController ()
@end
@implementation BookmarkGatewaySettingsController
2019-11-06 15:24:51 +01:00
- (id)initWithBookmark:(ComputerBookmark *)bookmark
2013-05-07 12:05:21 +02:00
{
2019-11-06 15:24:51 +01:00
if ((self = [super initWithStyle:UITableViewStyleGrouped]))
2013-05-08 14:50:29 +02:00
{
// set additional settings state according to bookmark data
_bookmark = [bookmark retain];
2019-11-06 15:24:51 +01:00
_params = [bookmark params];
}
return self;
2013-05-07 12:05:21 +02:00
}
- (void)viewDidLoad
{
2019-11-06 15:24:51 +01:00
[super viewDidLoad];
[self setTitle:NSLocalizedString(@"TS Gateway Settings", @"TS Gateway Settings title")];
2013-05-08 14:50:29 +02:00
}
2013-05-07 12:05:21 +02:00
2013-05-08 14:50:29 +02:00
- (void)viewWillAppear:(BOOL)animated
{
2019-11-06 15:24:51 +01:00
[super viewWillAppear:animated];
// we need to reload the table view data here to have up-to-date data for the
// advanced settings accessory items (like for resolution/color mode settings)
[[self tableView] reloadData];
2013-05-07 12:05:21 +02:00
}
2013-05-08 14:50:29 +02:00
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
2013-05-07 12:05:21 +02:00
{
2019-11-06 15:24:51 +01:00
return YES;
2013-05-08 14:50:29 +02:00
}
- (void)dealloc
{
2019-11-06 15:24:51 +01:00
[super dealloc];
[_bookmark release];
2013-05-07 12:05:21 +02:00
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
2019-11-06 15:24:51 +01:00
// Return the number of sections.
return SECTION_COUNT;
2013-05-07 12:05:21 +02:00
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
2019-11-06 15:24:51 +01:00
// Return the number of rows in the section.
2013-05-08 14:50:29 +02:00
switch (section)
{
case SECTION_TSGATEWAY_SETTINGS: // ts gateway settings
return 5;
default:
break;
}
2019-11-06 15:24:51 +01:00
return 0;
2013-05-07 12:05:21 +02:00
}
2013-05-08 14:50:29 +02:00
// set section headers
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
2019-11-06 15:24:51 +01:00
switch (section)
2013-05-08 14:50:29 +02:00
{
case SECTION_TSGATEWAY_SETTINGS:
return NSLocalizedString(@"TS Gateway", @"'TS Gateway': ts gateway settings header");
}
return @"unknown";
}
2019-11-06 15:24:51 +01:00
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
2013-05-07 12:05:21 +02:00
{
2013-05-08 14:50:29 +02:00
// determine the required cell type
2019-11-06 15:24:51 +01:00
NSString *cellType = nil;
switch ([indexPath section])
2013-05-08 14:50:29 +02:00
{
2019-11-06 15:24:51 +01:00
case SECTION_TSGATEWAY_SETTINGS: // advanced settings
{
switch ([indexPath row])
{
case 0: // hostname
case 1: // port
case 2: // username
case 4: // domain
cellType = TableCellIdentifierText;
break;
case 3: // password
cellType = TableCellIdentifierSecretText;
break;
default:
break;
}
break;
}
2013-05-08 14:50:29 +02:00
}
NSAssert(cellType != nil, @"Couldn't determine cell type");
2019-11-06 15:24:51 +01:00
2013-05-08 14:50:29 +02:00
// get the table view cell
UITableViewCell *cell = [self tableViewCellFromIdentifier:cellType];
NSAssert(cell, @"Invalid cell");
2019-11-06 15:24:51 +01:00
2013-05-08 14:50:29 +02:00
// set cell values
2019-11-06 15:24:51 +01:00
switch ([indexPath section])
2013-05-08 14:50:29 +02:00
{
2019-11-06 15:24:51 +01:00
// advanced settings
2013-05-08 14:50:29 +02:00
case SECTION_TSGATEWAY_SETTINGS:
[self initGatewaySettings:indexPath cell:cell];
break;
2019-11-06 15:24:51 +01:00
2013-05-08 14:50:29 +02:00
default:
break;
}
2019-11-06 15:24:51 +01:00
return cell;
2013-05-07 12:05:21 +02:00
}
2013-05-08 14:50:29 +02:00
// updates server settings in the UI
2019-11-06 15:24:51 +01:00
- (void)initGatewaySettings:(NSIndexPath *)indexPath cell:(UITableViewCell *)cell
2013-05-07 12:05:21 +02:00
{
2019-11-06 15:24:51 +01:00
EditTextTableViewCell *textCell = (EditTextTableViewCell *)cell;
2013-05-08 14:50:29 +02:00
[[textCell textfield] setTag:GET_TAG_FROM_PATH(indexPath)];
2019-11-06 15:24:51 +01:00
switch ([indexPath row])
2013-05-08 14:50:29 +02:00
{
case 0:
2019-11-06 15:24:51 +01:00
{
2013-05-08 14:50:29 +02:00
[[textCell label] setText:NSLocalizedString(@"Host", @"'Host': Bookmark hostname")];
[[textCell textfield] setText:[_params StringForKey:@"tsg_hostname"]];
2019-11-06 15:24:51 +01:00
[[textCell textfield]
setPlaceholder:NSLocalizedString(@"not set", @"not set placeholder")];
2013-05-08 14:50:29 +02:00
break;
2019-11-06 15:24:51 +01:00
}
2013-05-08 14:50:29 +02:00
case 1:
2019-11-06 15:24:51 +01:00
{
int port = [_params intForKey:@"tsg_port"];
if (port == 0)
port = 443;
2013-05-08 14:50:29 +02:00
[[textCell label] setText:NSLocalizedString(@"Port", @"'Port': Bookmark port")];
[[textCell textfield] setText:[NSString stringWithFormat:@"%d", port]];
2019-11-06 15:24:51 +01:00
[[textCell textfield] setKeyboardType:UIKeyboardTypeNumberPad];
break;
}
2013-05-08 14:50:29 +02:00
case 2:
2019-11-06 15:24:51 +01:00
{
[[textCell textfield] setTag:GET_TAG_FROM_PATH(indexPath)];
[[textCell label]
setText:NSLocalizedString(@"Username", @"'Username': Bookmark username")];
2013-05-08 14:50:29 +02:00
[[textCell textfield] setText:[_params StringForKey:@"tsg_username"]];
2019-11-06 15:24:51 +01:00
[[textCell textfield]
setPlaceholder:NSLocalizedString(@"not set", @"not set placeholder")];
2013-05-08 14:50:29 +02:00
break;
2019-11-06 15:24:51 +01:00
}
2013-05-08 14:50:29 +02:00
case 3:
2019-11-06 15:24:51 +01:00
{
[[textCell textfield] setTag:GET_TAG_FROM_PATH(indexPath)];
[[textCell label]
setText:NSLocalizedString(@"Password", @"'Password': Bookmark password")];
2013-05-08 14:50:29 +02:00
[[textCell textfield] setText:[_params StringForKey:@"tsg_password"]];
2019-11-06 15:24:51 +01:00
[[textCell textfield]
setPlaceholder:NSLocalizedString(@"not set", @"not set placeholder")];
2013-05-08 14:50:29 +02:00
break;
2019-11-06 15:24:51 +01:00
}
2013-05-08 14:50:29 +02:00
case 4:
2019-11-06 15:24:51 +01:00
{
[[textCell textfield] setTag:GET_TAG_FROM_PATH(indexPath)];
2013-05-08 14:50:29 +02:00
[[textCell label] setText:NSLocalizedString(@"Domain", @"'Domain': Bookmark domain")];
[[textCell textfield] setText:[_params StringForKey:@"tsg_domain"]];
2019-11-06 15:24:51 +01:00
[[textCell textfield]
setPlaceholder:NSLocalizedString(@"not set", @"not set placeholder")];
2013-05-08 14:50:29 +02:00
break;
2019-11-06 15:24:51 +01:00
}
2013-05-08 14:50:29 +02:00
default:
NSLog(@"Invalid row index in settings table!");
break;
}
2013-05-07 12:05:21 +02:00
2019-11-06 15:24:51 +01:00
[self adjustEditTextTableViewCell:textCell];
}
2013-05-07 12:05:21 +02:00
2013-05-08 14:50:29 +02:00
#pragma mark -
#pragma mark Text Field delegate
2013-05-07 12:05:21 +02:00
2019-11-06 15:24:51 +01:00
- (BOOL)textFieldShouldReturn:(UITextField *)textField
2013-05-07 12:05:21 +02:00
{
2013-05-08 14:50:29 +02:00
[textField resignFirstResponder];
return NO;
2013-05-07 12:05:21 +02:00
}
2013-05-08 14:50:29 +02:00
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField
2013-05-07 12:05:21 +02:00
{
2019-11-06 15:24:51 +01:00
switch (textField.tag)
2013-05-08 14:50:29 +02:00
{
2019-11-06 15:24:51 +01:00
// update server settings
2013-05-08 14:50:29 +02:00
case GET_TAG(SECTION_TSGATEWAY_SETTINGS, 0):
[_params setValue:[textField text] forKey:@"tsg_hostname"];
break;
2019-11-06 15:24:51 +01:00
2013-05-08 14:50:29 +02:00
case GET_TAG(SECTION_TSGATEWAY_SETTINGS, 1):
[_params setInt:[[textField text] intValue] forKey:@"tsg_port"];
break;
2019-11-06 15:24:51 +01:00
2013-05-08 14:50:29 +02:00
case GET_TAG(SECTION_TSGATEWAY_SETTINGS, 2):
[_params setValue:[textField text] forKey:@"tsg_username"];
break;
2019-11-06 15:24:51 +01:00
2013-05-08 14:50:29 +02:00
case GET_TAG(SECTION_TSGATEWAY_SETTINGS, 3):
[_params setValue:[textField text] forKey:@"tsg_password"];
break;
2019-11-06 15:24:51 +01:00
2013-05-08 14:50:29 +02:00
case GET_TAG(SECTION_TSGATEWAY_SETTINGS, 4):
[_params setValue:[textField text] forKey:@"tsg_domain"];
2019-11-06 15:24:51 +01:00
break;
2013-05-08 14:50:29 +02:00
default:
break;
}
return YES;
2013-05-07 12:05:21 +02:00
}
@end