More bugfixes in networking. Added password panels. Fixed bug with 0:60 time.
authorKent Sutherland <ksuther@ithinksw.com>
Fri, 31 Oct 2003 05:06:07 +0000 (05:06 +0000)
committerKent Sutherland <ksuther@ithinksw.com>
Fri, 31 Oct 2003 05:06:07 +0000 (05:06 +0000)
English.lproj/Preferences.nib/classes.nib
English.lproj/Preferences.nib/info.nib
English.lproj/Preferences.nib/keyedobjects.nib
MainController.m
NetworkController.m
NetworkObject.h
NetworkObject.m
PreferencesController.h
PreferencesController.m
iTunesRemote.m
libValidate.a

index cebb794..a407ae6 100755 (executable)
                 menuTableView = CustomMenuTableView; 
                 nameCheckbox = NSButton; 
                 nameTextField = NSTextField; 
+                passwordPanel = NSPanel; 
+                passwordPanelMessage = NSTextField; 
+                passwordPanelOKButton = NSButton; 
+                passwordPanelTextField = NSTextField; 
                 passwordTextField = NSTextField; 
                 ratingCheckbox = NSButton; 
                 selectPlayerBox = NSBox; 
index 1c8a9f3..1bf11ab 100755 (executable)
@@ -21,7 +21,6 @@
        <array>
                <integer>6</integer>
                <integer>699</integer>
-               <integer>624</integer>
        </array>
        <key>IBSystem Version</key>
        <string>7B85</string>
index e180aca..04a312d 100755 (executable)
Binary files a/English.lproj/Preferences.nib/keyedobjects.nib and b/English.lproj/Preferences.nib/keyedobjects.nib differ
index a9e67e9..341eb8d 100755 (executable)
@@ -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
     }
 }
 
index 65962ba..1e7a230 100755 (executable)
@@ -14,6 +14,7 @@
 #import "NetworkController.h"
 #import "MainController.h"
 #import "NetworkObject.h"
+#import "PreferencesController.h"
 #import <ITFoundation/ITDebug.h>
 #import <ITFoundation/ITFoundation.h>
 
@@ -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;
 }
 
index 75d534c..2222414 100755 (executable)
@@ -21,7 +21,7 @@
 
 @interface NetworkObject : NSObject
 {
-
+    BOOL _authenticated;
 }
 - (ITMTRemote *)remote;
 - (NSString *)serverName;
index da316e1..32bbbc8 100755 (executable)
 
 @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
 - (BOOL)sendPassword:(NSData *)password
 {
     if ([password isEqualToData:[[NSUserDefaults standardUserDefaults] dataForKey:@"sharedPlayerPassword"]]) {
+        _authenticated = YES;
         return YES;
     } else {
+        _authenticated = NO;
         return NO;
     }
 }
index 9ac7365..c2cc388 100755 (executable)
     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;
index f6c6d7b..4141086 100755 (executable)
@@ -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];
 }
index 3e25046..3253f45 100755 (executable)
 - (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 {
index 61c6a97..bba70d4 100755 (executable)
Binary files a/libValidate.a and b/libValidate.a differ