diff options
author | Mikkel Krautz <mikkel@krautz.dk> | 2010-09-01 03:22:54 +0400 |
---|---|---|
committer | Mikkel Krautz <mikkel@krautz.dk> | 2010-09-01 03:22:54 +0400 |
commit | f35855acf1217e6f7d13f4c35e0fbb68c2cb55b0 (patch) | |
tree | 7d3fa53e2003f95f550971ab62712f98d8d646d4 | |
parent | 645e229ddc434845e2c7cf26a47745903b30db59 (diff) |
Store username and password in FavouriteServer class. Database support for serializing updated FavouriteServer class to SQLite. Remove identity references from UI.
-rw-r--r-- | Source/Classes/AppDelegate.m | 2 | ||||
-rw-r--r-- | Source/Classes/Database.m | 19 | ||||
-rw-r--r-- | Source/Classes/FavouriteServer.h | 12 | ||||
-rw-r--r-- | Source/Classes/FavouriteServer.m | 17 | ||||
-rw-r--r-- | Source/Classes/FavouriteServerEditViewController.m | 5 | ||||
-rw-r--r-- | Source/Classes/FavouriteServerListController.m | 9 | ||||
-rw-r--r-- | Source/Classes/ServerRootViewController.h | 10 | ||||
-rw-r--r-- | Source/Classes/ServerRootViewController.m | 12 | ||||
-rw-r--r-- | Source/Classes/WelcomeScreenPhone.m | 14 |
9 files changed, 67 insertions, 33 deletions
diff --git a/Source/Classes/AppDelegate.m b/Source/Classes/AppDelegate.m index 5a2d605..a359089 100644 --- a/Source/Classes/AppDelegate.m +++ b/Source/Classes/AppDelegate.m @@ -45,7 +45,6 @@ @synthesize window; @synthesize navigationController; - - (void) applicationDidFinishLaunching:(UIApplication *)application { _launchDate = [[NSDate alloc] init]; @@ -54,7 +53,6 @@ [self reloadPreferences]; [Database initializeDatabase]; - [Database showStoredIdentities]; // If we're running on anything below OS 3.2, UIDevice does not // respond to the userInterfaceIdiom method. We must assume we're diff --git a/Source/Classes/Database.m b/Source/Classes/Database.m index 32ef22f..c7dcb3f 100644 --- a/Source/Classes/Database.m +++ b/Source/Classes/Database.m @@ -90,6 +90,10 @@ static FMDatabase *db = nil; [db executeUpdate:@"ALTER TABLE `servers` ADD `identity` " @"INTEGER DEFAULT NULL REFERENCES identities(id) ON DELETE SET DEFAULT"]; + // fixme(mkrautz): This is a temporary solution for 0.1. + [db executeUpdate:@"ALTER TABLE `servers` ADD `username` TEXT"]; + [db executeUpdate:@"ALTER TABLE `servers` ADD `password` TEXT"]; + [db executeUpdate:@"VACUUM"]; if ([db hadError]) { @@ -144,11 +148,13 @@ static FMDatabase *db = nil; // If the favourite already has a primary key, update the currently stored entity if ([favServ hasPrimaryKey]) { NSLog(@"update!"); - [db executeUpdate:@"UPDATE `servers` SET `name`=?, `hostname`=?, `port`=?, `identity`=? WHERE `id`=?", + [db executeUpdate:@"UPDATE `servers` SET `name`=?, `hostname`=?, `port`=?, `identity`=?, `username`=?, `password`=? WHERE `id`=?", [favServ displayName], [favServ hostName], [NSString stringWithFormat:@"%u", [favServ port]], nil, + [favServ userName], + [favServ password], [NSNumber numberWithInt:[favServ primaryKey]]]; // If it isn't already stored, store it and update the object's pkey. } else { @@ -159,11 +165,13 @@ static FMDatabase *db = nil; BOOL newTransaction = ![db inTransaction]; if (newTransaction) [db beginTransaction]; - [db executeUpdate:@"INSERT INTO `servers` (`name`, `hostname`, `port`, `identity`) VALUES (?, ?, ?, ?)", + [db executeUpdate:@"INSERT INTO `servers` (`name`, `hostname`, `port`, `identity`, `username`, `password`) VALUES (?, ?, ?, ?, ?, ?)", [favServ displayName], [favServ hostName], [NSString stringWithFormat:@"%u", [favServ port]], - nil]; + nil, + [favServ userName], + [favServ password]]; FMResultSet *res = [db executeQuery:@"SELECT last_insert_rowid()"]; [res next]; [favServ setPrimaryKey:[res intForColumnIndex:0]]; @@ -196,7 +204,8 @@ static FMDatabase *db = nil; + (NSMutableArray *) fetchAllFavourites { NSMutableArray *favs = [[NSMutableArray alloc] init]; - FMResultSet *res = [db executeQuery:@"SELECT `id`, `name`, `hostname`, `port`, `identity` FROM `servers`"]; + FMResultSet *res = [db executeQuery:@"SELECT `id`, `name`, `hostname`, `port`, `identity`, `username`, `password` FROM `servers`"]; + NSLog(@"resultSet = %p", res); while ([res next]) { FavouriteServer *fs = [[FavouriteServer alloc] init]; @@ -204,6 +213,8 @@ static FMDatabase *db = nil; [fs setDisplayName:[res stringForColumnIndex:1]]; [fs setHostName:[res stringForColumnIndex:2]]; [fs setPort:[res intForColumnIndex:3]]; + [fs setUserName:[res stringForColumnIndex:5]]; + [fs setPassword:[res stringForColumnIndex:6]]; [favs addObject:fs]; } diff --git a/Source/Classes/FavouriteServer.h b/Source/Classes/FavouriteServer.h index 533fe32..2d6a0eb 100644 --- a/Source/Classes/FavouriteServer.h +++ b/Source/Classes/FavouriteServer.h @@ -29,14 +29,15 @@ */ @interface FavouriteServer : NSObject <NSCopying> { - NSInteger _pkey; - NSString *_displayName; - NSString *_hostName; + NSInteger _pkey; + NSString *_displayName; + NSString *_hostName; NSUInteger _port; - NSString *_userName; + NSString *_userName; + NSString *_password; } -- (id) initWithDisplayName:(NSString *)displayName hostName:(NSString *)hostName port:(NSUInteger)port userName:(NSString *)userName; +- (id) initWithDisplayName:(NSString *)displayName hostName:(NSString *)hostName port:(NSUInteger)port userName:(NSString *)userName password:(NSString *)passWord; - (id) init; - (void) dealloc; @@ -45,6 +46,7 @@ @property (copy) NSString *hostName; @property (assign) NSUInteger port; @property (copy) NSString *userName; +@property (copy) NSString *password; - (BOOL) hasPrimaryKey; diff --git a/Source/Classes/FavouriteServer.m b/Source/Classes/FavouriteServer.m index c6c6bdf..4da5567 100644 --- a/Source/Classes/FavouriteServer.m +++ b/Source/Classes/FavouriteServer.m @@ -32,13 +32,14 @@ @implementation FavouriteServer -@synthesize primaryKey = _pkey; +@synthesize primaryKey = _pkey; @synthesize displayName = _displayName; -@synthesize hostName = _hostName; -@synthesize port = _port; -@synthesize userName = _userName; +@synthesize hostName = _hostName; +@synthesize port = _port; +@synthesize userName = _userName; +@synthesize password = _password; -- (id) initWithDisplayName:(NSString *)displayName hostName:(NSString *)hostName port:(NSUInteger)port userName:(NSString *)userName { +- (id) initWithDisplayName:(NSString *)displayName hostName:(NSString *)hostName port:(NSUInteger)port userName:(NSString *)userName password:(NSString *)passWord { self = [super init]; if (self == nil) return nil; @@ -48,23 +49,25 @@ _hostName = [hostName copy]; _port = port; _userName = [userName copy]; + _password = [passWord copy]; return self; } - (id) init { - return [self initWithDisplayName:nil hostName:nil port:0 userName:nil]; + return [self initWithDisplayName:nil hostName:nil port:0 userName:nil password:nil]; } - (void) dealloc { [_displayName release]; [_hostName release]; [_userName release]; + [_password release]; [super dealloc]; } - (id) copyWithZone:(NSZone *)zone { - FavouriteServer *favServ = [[FavouriteServer alloc] initWithDisplayName:_displayName hostName:_hostName port:_port userName:_userName]; + FavouriteServer *favServ = [[FavouriteServer alloc] initWithDisplayName:_displayName hostName:_hostName port:_port userName:_userName password:_password]; if ([self hasPrimaryKey]) [favServ setPrimaryKey:[self primaryKey]]; return favServ; diff --git a/Source/Classes/FavouriteServerEditViewController.m b/Source/Classes/FavouriteServerEditViewController.m index 9cb910d..4aa813b 100644 --- a/Source/Classes/FavouriteServerEditViewController.m +++ b/Source/Classes/FavouriteServerEditViewController.m @@ -179,7 +179,7 @@ static NSString *FavouriteServerPlaceholderPassword = @"Optional"; [cell setPlaceholder:FavouriteServerPlaceholderPassword]; [cell setSecureTextEntry:YES]; [cell setValueChangedAction:@selector(passwordChanged:)]; - // fixme(mkrautz): Grab value from keychain? + [cell setTextValue:[_favourite password]]; } } @@ -210,7 +210,8 @@ static NSString *FavouriteServerPlaceholderPassword = @"Optional"; } - (void) passwordChanged:(id)sender { - // We should store passwords in keychain. + TableViewTextFieldCell *cell = (TableViewTextFieldCell *)sender; + [_favourite setPassword:[cell textValue]]; } #pragma mark - diff --git a/Source/Classes/FavouriteServerListController.m b/Source/Classes/FavouriteServerListController.m index 220c663..cc7e186 100644 --- a/Source/Classes/FavouriteServerListController.m +++ b/Source/Classes/FavouriteServerListController.m @@ -85,7 +85,12 @@ FavouriteServer *favServ = [_favouriteServers objectAtIndex:[indexPath row]]; cell.textLabel.text = [favServ displayName]; - cell.detailTextLabel.text = [NSString stringWithFormat:@"%@ on %@:%u", [favServ userName], [favServ hostName], [favServ port]]; + + NSString *hostName = [favServ hostName]; + NSString *userName = [favServ userName]; + cell.detailTextLabel.text = [NSString stringWithFormat:@"%@ on %@:%u", + userName ? userName : @"MumbleUser", + hostName ? hostName : @"(no server)", [favServ port]]; return cell; } @@ -130,7 +135,7 @@ // Connect if (index == 0) { UINavigationController *navCtrl = [[UINavigationController alloc] init]; - ServerRootViewController *serverRoot = [[ServerRootViewController alloc] initWithHostname:[favServ hostName] port:[favServ port]]; + ServerRootViewController *serverRoot = [[ServerRootViewController alloc] initWithHostname:[favServ hostName] port:[favServ port] username:[favServ userName] password:[favServ password]]; [navCtrl pushViewController:serverRoot animated:NO]; [[self navigationController] presentModalViewController:navCtrl animated:YES]; [serverRoot release]; diff --git a/Source/Classes/ServerRootViewController.h b/Source/Classes/ServerRootViewController.h index 1fed8e4..ce9c012 100644 --- a/Source/Classes/ServerRootViewController.h +++ b/Source/Classes/ServerRootViewController.h @@ -36,13 +36,15 @@ #import <UIKit/UIKit.h> @interface ServerRootViewController : UITableViewController { - MKConnection *_connection; - MKServerModel *_model; + MKConnection *_connection; + MKServerModel *_model; NSMutableArray *_channelUsers; - MKChannel *_currentChannel; + MKChannel *_currentChannel; + NSString *_username; + NSString *_password; } -- (id) initWithHostname:(NSString *)host port:(NSUInteger)port; +- (id) initWithHostname:(NSString *)host port:(NSUInteger)port username:(NSString *)username password:(NSString *)password; - (void) dealloc; @end diff --git a/Source/Classes/ServerRootViewController.m b/Source/Classes/ServerRootViewController.m index 0c1db08..53bf469 100644 --- a/Source/Classes/ServerRootViewController.m +++ b/Source/Classes/ServerRootViewController.m @@ -38,11 +38,14 @@ @implementation ServerRootViewController -- (id) initWithHostname:(NSString *)host port:(NSUInteger)port { +- (id) initWithHostname:(NSString *)host port:(NSUInteger)port username:(NSString *)username password:(NSString *)password { self = [super init]; if (! self) return nil; + _username = [username copy]; + _password = [password copy]; + _connection = [[MKConnection alloc] init]; [_connection setDelegate:self]; @@ -59,6 +62,11 @@ } - (void) dealloc { + [_username release]; + [_password release]; + [_model release]; + [_connection release]; + [super dealloc]; } @@ -150,7 +158,7 @@ // An SSL connection has been opened to the server. We should authenticate ourselves. // - (void) connectionOpened:(MKConnection *)conn { - [conn authenticateWithUsername:@"MumbleiPhoneUser" password:nil]; + [conn authenticateWithUsername:_username password:_password]; } #pragma mark MKServerModel Delegate diff --git a/Source/Classes/WelcomeScreenPhone.m b/Source/Classes/WelcomeScreenPhone.m index 419f766..7adf499 100644 --- a/Source/Classes/WelcomeScreenPhone.m +++ b/Source/Classes/WelcomeScreenPhone.m @@ -86,7 +86,7 @@ if (section == 0) return 3; if (section == 1) - return 4; + return 3; return 0; } @@ -125,11 +125,13 @@ } else if (indexPath.section == 1) { if (indexPath.row == 0) { cell.textLabel.text = @"Preferences"; +#if 0 } else if (indexPath.row == 1) { cell.textLabel.text = @"Identities"; - } else if (indexPath.row == 2) { +#endif + } else if (indexPath.row == 1) { cell.textLabel.text = @"Diagnostics"; - } else if (indexPath.row == 3) { + } else if (indexPath.row == 2) { cell.textLabel.text = @"About"; } } @@ -163,17 +165,19 @@ PreferencesViewController *preferences = [[PreferencesViewController alloc] init]; [[self navigationController] pushViewController:preferences animated:YES]; [preferences release]; +#if 0 } else if (indexPath.row == 1) { // Identities IdentityViewController *ident = [[IdentityViewController alloc] init]; //CertificateViewController *ident = [[CertificateViewController alloc] init]; //IdentitiesTabBarController *ident = [[IdentitiesTabBarController alloc] init]; [[self navigationController] pushViewController:ident animated:YES]; [ident release]; - } else if (indexPath.row == 2) { // Diagnostics +#endif + } else if (indexPath.row == 1) { // Diagnostics DiagnosticsViewController *diag = [[DiagnosticsViewController alloc] init]; [[self navigationController] pushViewController:diag animated:YES]; [diag release]; - } else if (indexPath.row == 3) { // About + } else if (indexPath.row == 2) { // About [self presentAboutDialog]; } } |