From: Kent Sutherland Date: Fri, 31 Oct 2003 05:06:07 +0000 (+0000) Subject: More bugfixes in networking. Added password panels. Fixed bug with 0:60 time. X-Git-Tag: v1.2~41 X-Git-Url: http://git.ithinksw.org/MenuTunes.git/commitdiff_plain/da05d51282a00722e05f2c777db5cc3d0623d348 More bugfixes in networking. Added password panels. Fixed bug with 0:60 time. --- diff --git a/English.lproj/Preferences.nib/classes.nib b/English.lproj/Preferences.nib/classes.nib index cebb794..a407ae6 100755 --- a/English.lproj/Preferences.nib/classes.nib +++ b/English.lproj/Preferences.nib/classes.nib @@ -30,6 +30,10 @@ menuTableView = CustomMenuTableView; nameCheckbox = NSButton; nameTextField = NSTextField; + passwordPanel = NSPanel; + passwordPanelMessage = NSTextField; + passwordPanelOKButton = NSButton; + passwordPanelTextField = NSTextField; passwordTextField = NSTextField; ratingCheckbox = NSButton; selectPlayerBox = NSBox; diff --git a/English.lproj/Preferences.nib/info.nib b/English.lproj/Preferences.nib/info.nib index 1c8a9f3..1bf11ab 100755 --- a/English.lproj/Preferences.nib/info.nib +++ b/English.lproj/Preferences.nib/info.nib @@ -21,7 +21,6 @@ 6 699 - 624 IBSystem Version 7B85 diff --git a/English.lproj/Preferences.nib/keyedobjects.nib b/English.lproj/Preferences.nib/keyedobjects.nib index e180aca..04a312d 100755 Binary files a/English.lproj/Preferences.nib/keyedobjects.nib and b/English.lproj/Preferences.nib/keyedobjects.nib differ diff --git a/MainController.m b/MainController.m index a9e67e9..341eb8d 100755 --- a/MainController.m +++ b/MainController.m @@ -42,6 +42,7 @@ static MainController *sharedController; statusWindowController = [StatusWindowController sharedController]; menuController = [[MenuController alloc] init]; df = [[NSUserDefaults standardUserDefaults] retain]; + [[PreferencesController sharedPrefs] setController:self]; timerUpdating = NO; blinged = NO; } @@ -472,7 +473,6 @@ static MainController *sharedController; - (void)showPreferences { ITDebugLog(@"Show preferences."); - [[PreferencesController sharedPrefs] setController:self]; [[PreferencesController sharedPrefs] showPrefsWindow:self]; } @@ -959,11 +959,11 @@ static MainController *sharedController; ITDebugLog(@"Connection failed."); currentRemote = [remoteArray objectAtIndex:0]; return NO; - } else if (result == -1) { + } else { + //Do something about the password being invalid ITDebugLog(@"Connection failed."); currentRemote = [remoteArray objectAtIndex:0]; return NO; - //Do something about the password being invalid } } diff --git a/NetworkController.m b/NetworkController.m index 65962ba..1e7a230 100755 --- a/NetworkController.m +++ b/NetworkController.m @@ -14,6 +14,7 @@ #import "NetworkController.h" #import "MainController.h" #import "NetworkObject.h" +#import "PreferencesController.h" #import #import @@ -146,17 +147,32 @@ static NetworkController *sharedController; } if ([clientProxy requiresPassword]) { + ITDebugLog(@"Server requires password."); + //Check to see if a password is set in defaults + if ([[NSUserDefaults standardUserDefaults] dataForKey:@"connectPassword"] == nil) { + ITDebugLog(@"Asking for password."); + if (![[PreferencesController sharedPrefs] showPasswordPanel]) { + ITDebugLog(@"Giving up connection attempt."); + [self disconnect]; + return -1; + } + } + + //Send the password ITDebugLog(@"Sending password."); - if (![clientProxy sendPassword:[[NSUserDefaults standardUserDefaults] dataForKey:@"connectPassword"]]) { + while (![clientProxy sendPassword:[[NSUserDefaults standardUserDefaults] dataForKey:@"connectPassword"]]) { ITDebugLog(@"Invalid password!"); - [self disconnect]; - return -1; + if (![[PreferencesController sharedPrefs] showInvalidPasswordPanel]) { + ITDebugLog(@"Giving up connection attempt."); + [self disconnect]; + return -1; + } } } ITDebugLog(@"Connected to host: %@", host); [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(disconnect) name:NSConnectionDidDieNotification object:clientConnection]; - connectedToServer = 1; + connectedToServer = YES; return 1; } diff --git a/NetworkObject.h b/NetworkObject.h index 75d534c..2222414 100755 --- a/NetworkObject.h +++ b/NetworkObject.h @@ -21,7 +21,7 @@ @interface NetworkObject : NSObject { - + BOOL _authenticated; } - (ITMTRemote *)remote; - (NSString *)serverName; diff --git a/NetworkObject.m b/NetworkObject.m index da316e1..32bbbc8 100755 --- a/NetworkObject.m +++ b/NetworkObject.m @@ -21,9 +21,24 @@ @implementation NetworkObject +- (id)init +{ + if ( (self = [super init]) ) { + if (![self requiresPassword]) { + _authenticated = YES; + } else { + _authenticated = NO; + } + } + return self; +} + - (ITMTRemote *)remote { - return [[MainController sharedController] currentRemote]; + if (_authenticated) + return [[MainController sharedController] currentRemote]; + else + return nil; } - (NSString *)serverName @@ -42,8 +57,10 @@ - (BOOL)sendPassword:(NSData *)password { if ([password isEqualToData:[[NSUserDefaults standardUserDefaults] dataForKey:@"sharedPlayerPassword"]]) { + _authenticated = YES; return YES; } else { + _authenticated = NO; return NO; } } diff --git a/PreferencesController.h b/PreferencesController.h index 9ac7365..c2cc388 100755 --- a/PreferencesController.h +++ b/PreferencesController.h @@ -33,6 +33,10 @@ IBOutlet CustomMenuTableView *menuTableView; IBOutlet NSButton *nameCheckbox; IBOutlet NSTextField *nameTextField; + IBOutlet NSPanel *passwordPanel; + IBOutlet NSTextField *passwordPanelMessage; + IBOutlet NSButton *passwordPanelOKButton; + IBOutlet NSTextField *passwordPanelTextField; IBOutlet NSTextField *passwordTextField; IBOutlet NSButton *ratingCheckbox; IBOutlet NSTextField *selectedPlayerTextField; @@ -68,6 +72,9 @@ - (id)controller; - (void)setController:(id)object; +- (BOOL)showPasswordPanel; +- (BOOL)showInvalidPasswordPanel; + - (IBAction)changeGeneralSetting:(id)sender; - (IBAction)changeSharingSetting:(id)sender; - (IBAction)changeStatusWindowSetting:(id)sender; diff --git a/PreferencesController.m b/PreferencesController.m index f6c6d7b..4141086 100755 --- a/PreferencesController.m +++ b/PreferencesController.m @@ -98,6 +98,8 @@ static PreferencesController *prefs = nil; nil]; hotKeysDictionary = [[NSMutableDictionary alloc] init]; controller = nil; + + [self setupWindow]; // Load in the nib, and perform any initial setup. } return self; } @@ -125,12 +127,37 @@ static PreferencesController *prefs = nil; #pragma mark INSTANCE METHODS /*************************************************************************/ +- (BOOL)showPasswordPanel +{ + [passwordPanel setLevel:NSStatusWindowLevel]; + [passwordPanelOKButton setTitle:@"OK"]; + [passwordPanelMessage setStringValue:[NSString stringWithFormat:@"Please enter a password for access to the MenuTunes player named %@ at %@.", [[[NetworkController sharedController] networkObject] serverName], [[NetworkController sharedController] remoteHost]]]; + [passwordPanel makeKeyAndOrderFront:nil]; + if ([NSApp runModalForWindow:passwordPanel]) { + return YES; + } else { + return NO; + } +} + +- (BOOL)showInvalidPasswordPanel +{ + [passwordPanel setLevel:NSStatusWindowLevel]; + [passwordPanelOKButton setTitle:@"Retry"]; + [passwordPanelMessage setStringValue:[NSString stringWithFormat:@"The password entered for access to the MenuTunes player named %@ at %@ is invalid. Please provide a new password.", [[[NetworkController sharedController] networkObject] serverName], [[NetworkController sharedController] remoteHost]]]; + [passwordPanel makeKeyAndOrderFront:nil]; + if ([NSApp runModalForWindow:passwordPanel]) { + return YES; + } else { + return NO; + } +} + - (IBAction)showPrefsWindow:(id)sender { ITDebugLog(@"Showing preferences window."); if (! window) { // If window does not exist yet, then the nib hasn't been loaded. ITDebugLog(@"Window doesn't exist, initial setup."); - [self setupWindow]; // Load in the nib, and perform any initial setup. [self setupCustomizationTables]; // Setup the DnD manu config tables. [self setupMenuItems]; // Setup the arrays of menu items [self setupUI]; // Sets up additional UI @@ -219,14 +246,15 @@ static PreferencesController *prefs = nil; [nameTextField setEnabled:NO]; [selectSharedPlayerButton setEnabled:state]; - if (state) { + if (state && [controller connectToServer]) { [selectedPlayerTextField setStringValue:[[[NetworkController sharedController] networkObject] serverName]]; [locationTextField setStringValue:[[NetworkController sharedController] remoteHost]]; - [controller connectToServer]; } else { [selectedPlayerTextField setStringValue:@"No shared player selected."]; [locationTextField setStringValue:@"-"]; - [controller disconnectFromServer]; + if ([[NetworkController sharedController] isConnectedToServer]) { + [controller disconnectFromServer]; + } } } else if ( [sender tag] == 5050 ) { @@ -288,6 +316,18 @@ static PreferencesController *prefs = nil; } else { NSRunAlertPanel(@"Connection error.", @"The MenuTunes server you attempted to connect to was not responding. MenuTunes will revert back to the local player.", @"OK", nil, nil); } + } else if ( [sender tag] == 6010 ) { + //Cancel password entry + [passwordPanel orderOut:nil]; + [NSApp stopModalWithCode:0]; + } else if ( [sender tag] == 6020 ) { + //OK password entry, retry connect + const char *instring = [[passwordPanelTextField stringValue] UTF8String]; + unsigned char *result; + result = SHA1(instring, strlen(instring), NULL); + [df setObject:[NSData dataWithBytes:result length:strlen(result)] forKey:@"connectPassword"]; + [passwordPanel orderOut:nil]; + [NSApp stopModalWithCode:1]; } [df synchronize]; } diff --git a/iTunesRemote.m b/iTunesRemote.m index 3e25046..3253f45 100755 --- a/iTunesRemote.m +++ b/iTunesRemote.m @@ -635,7 +635,7 @@ - (NSString*)formatTimeInSeconds:(long)seconds { long final = seconds; NSString *finalString; - if (final > 60) { + if (final >= 60) { if (final > 3600) { finalString = [NSString stringWithFormat:@"%i:%@:%@",(final / 3600),[self zeroSixty:(int)((final % 3600) / 60)],[self zeroSixty:(int)((final % 3600) % 60)]]; } else { diff --git a/libValidate.a b/libValidate.a index 61c6a97..bba70d4 100755 Binary files a/libValidate.a and b/libValidate.a differ