aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPConnectionController.m
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2009-08-07 22:38:47 +0000
committerrowanbeentje <rowan@beent.je>2009-08-07 22:38:47 +0000
commitdfbd00fda00bc0cbb9cc7bf3866d98165244c0d3 (patch)
tree1255df377be26a394cdc682feb2a3893ec11c13b /Source/SPConnectionController.m
parent31631781e5c9440ff3d9f75c8455b65662695e4e (diff)
downloadsequelpro-dfbd00fda00bc0cbb9cc7bf3866d98165244c0d3.tar.gz
sequelpro-dfbd00fda00bc0cbb9cc7bf3866d98165244c0d3.tar.bz2
sequelpro-dfbd00fda00bc0cbb9cc7bf3866d98165244c0d3.zip
- Fix "Add to favorites" behaviour when the user has no favourites (This addresses Issue #354)
- Improve favorites saving including names with anonymous users
Diffstat (limited to 'Source/SPConnectionController.m')
-rw-r--r--Source/SPConnectionController.m37
1 files changed, 18 insertions, 19 deletions
diff --git a/Source/SPConnectionController.m b/Source/SPConnectionController.m
index baef9691..6670c732 100644
--- a/Source/SPConnectionController.m
+++ b/Source/SPConnectionController.m
@@ -657,8 +657,8 @@
{
NSString *thePassword, *theSSHPassword;
NSNumber *favoriteid = [NSNumber numberWithInt:[[NSString stringWithFormat:@"%f", [[NSDate date] timeIntervalSince1970]] hash]];
- NSString *favoriteName = [[self name] length]?[self name]:[NSString stringWithFormat:@"%@@%@", [self user], [self host]];
- if (![[self name] length] && ![[self database] isEqualToString:@""])
+ NSString *favoriteName = [[self name] length]?[self name]:[NSString stringWithFormat:@"%@@%@", ([self user] && [[self user] length])?[self user]:@"anonymous", [self host]];
+ if (![[self name] length] && [self database] && ![[self database] isEqualToString:@""])
favoriteName = [NSString stringWithFormat:@"%@ %@", [self database], favoriteName];
// Ensure that host is not empty if this is a TCP/IP or SSH connection
@@ -676,21 +676,20 @@
// Ensure that a socket connection is not inadvertently used
if (![self checkHost]) return;
- // Construct the favorite details
- NSDictionary *newFavorite = [NSDictionary dictionaryWithObjectsAndKeys:
- [NSNumber numberWithInt:[self type]], @"type",
- favoriteName, @"name",
- [self host], @"host",
- [self socket], @"socket",
- [self user], @"user",
- [self port], @"port",
- [self database], @"database",
- [self sshHost], @"sshHost",
- [self sshUser], @"sshUser",
- [self sshPort], @"sshPort",
- favoriteid, @"id",
- nil];
-
+ // Construct the favorite details - cannot use only dictionaryWithObjectsAndKeys for possible nil values.
+ NSMutableDictionary *newFavorite = [NSMutableDictionary dictionaryWithObjectsAndKeys:
+ [NSNumber numberWithInt:[self type]], @"type",
+ favoriteName, @"name",
+ [self host], @"host",
+ favoriteid, @"id",
+ nil];
+ if ([self socket]) [newFavorite setObject:[self socket] forKey:@"socket"];
+ if ([self user]) [newFavorite setObject:[self user] forKey:@"user"];
+ if ([self port]) [newFavorite setObject:[self port] forKey:@"port"];
+ if ([self database]) [newFavorite setObject:[self database] forKey:@"database"];
+ if ([self sshHost]) [newFavorite setObject:[self sshHost] forKey:@"sshHost"];
+ if ([self sshUser]) [newFavorite setObject:[self sshUser] forKey:@"sshUser"];
+ if ([self sshPort]) [newFavorite setObject:[self sshPort] forKey:@"sshPort"];
// Add the new favorite to the user defaults array
NSMutableArray *currentFavorites;
@@ -708,7 +707,7 @@
if (mySQLConnection && connectionKeychainItemName) {
thePassword = [keychain getPasswordForName:connectionKeychainItemName account:connectionKeychainItemAccount];
}
- if (![thePassword isEqualToString:@""]) {
+ if (thePassword && ![thePassword isEqualToString:@""]) {
[keychain addPassword:thePassword
forName:[keychain nameForFavoriteName:favoriteName id:[NSString stringWithFormat:@"%i", [favoriteid intValue]]]
account:[keychain accountForUser:[self user] host:[self host] database:[self database]]];
@@ -719,7 +718,7 @@
if (mySQLConnection && connectionSSHKeychainItemName) {
theSSHPassword = [keychain getPasswordForName:connectionSSHKeychainItemName account:connectionSSHKeychainItemAccount];
}
- if (![theSSHPassword isEqualToString:@""]) {
+ if (theSSHPassword && ![theSSHPassword isEqualToString:@""]) {
[keychain addPassword:theSSHPassword
forName:[keychain nameForSSHForFavoriteName:favoriteName id:[NSString stringWithFormat:@"%i", [favoriteid intValue]]]
account:[keychain accountForSSHUser:[self sshUser] sshHost:[self sshHost]]];