More work done to networking. Bugfixes out the wazoo, but there's still
[MenuTunes.git] / PreferencesController.m
index 970ba88..f6c6d7b 100755 (executable)
@@ -1,6 +1,7 @@
 #import "PreferencesController.h"
 #import "MainController.h"
 #import "NetworkController.h"
+#import "NetworkObject.h"
 #import "StatusWindow.h"
 #import "StatusWindowController.h"
 #import "CustomMenuTableView.h"
@@ -198,14 +199,15 @@ static PreferencesController *prefs = nil;
         //Set the server password
         const char *instring = [[sender stringValue] UTF8String];
         const char *password = "password";
-        unsigned char result;
+        unsigned char *result;
         NSData *hashedPass, *passwordStringHash;
-        SHA1(instring, strlen(instring), &result);
-        hashedPass = [NSData dataWithBytes:&result length:strlen(&result)];
-        SHA1(password, strlen(password), &result);
-        passwordStringHash = [NSData dataWithBytes:&result length:strlen(&result)];
+        result = SHA1(instring, strlen(instring), NULL);
+        hashedPass = [NSData dataWithBytes:result length:strlen(result)];
+        result = SHA1(password, strlen(password), NULL);
+        passwordStringHash = [NSData dataWithBytes:result length:strlen(result)];
         if (![hashedPass isEqualToData:passwordStringHash]) {
             [df setObject:hashedPass forKey:@"sharedPlayerPassword"];
+            [sender setStringValue:@"password"];
         }
     } else if ( [sender tag] == 5040 ) {
         BOOL state = SENDER_STATE;
@@ -218,9 +220,14 @@ static PreferencesController *prefs = nil;
         [selectSharedPlayerButton setEnabled:state];
         
         if (state) {
+            [selectedPlayerTextField setStringValue:[[[NetworkController sharedController] networkObject] serverName]];
+            [locationTextField setStringValue:[[NetworkController sharedController] remoteHost]];
             [controller connectToServer];
         } else {
+            [selectedPlayerTextField setStringValue:@"No shared player selected."];
+            [locationTextField setStringValue:@"-"];
             [controller disconnectFromServer];
+            
         }
     } else if ( [sender tag] == 5050 ) {
         //Do nothing on table view click
@@ -248,9 +255,9 @@ static PreferencesController *prefs = nil;
         }
     } else if ( [sender tag] == 5150 ) {
         const char *instring = [[sender stringValue] UTF8String];
-        unsigned char result;
-        SHA1(instring, strlen(instring), &result);
-        [df setObject:[NSData dataWithBytes:&result length:strlen(&result)] forKey:@"connectPassword"];
+        unsigned char *result;
+        result = SHA1(instring, strlen(instring), NULL);
+        [df setObject:[NSData dataWithBytes:result length:strlen(result)] forKey:@"connectPassword"];
     } else if ( [sender tag] == 5110 ) {
         //Cancel
         [NSApp endSheet:selectPlayerSheet];
@@ -264,17 +271,19 @@ static PreferencesController *prefs = nil;
         [NSApp endSheet:selectPlayerSheet];
         [selectPlayerSheet orderOut:nil];
         
+        [self changeSharingSetting:clientPasswordTextField];
+        
         if ([selectPlayerBox contentView] == manualView) {
             [df setObject:[hostTextField stringValue] forKey:@"sharedPlayerHost"];
         } else {
             if ([sharingTableView selectedRow] > -1) {
-                [df setObject:[NSString stringWithCString:inet_ntoa((*(struct sockaddr_in*)[[[[NetworkController sharedController] remoteServices] objectAtIndex:[sharingTableView selectedRow]] bytes]).sin_addr)] forKey:@"sharedPlayerHost"];
+                [df setObject:[NSString stringWithCString:inet_ntoa((*(struct sockaddr_in*)[[[[[[NetworkController sharedController] remoteServices] objectAtIndex:[sharingTableView selectedRow]] addresses] objectAtIndex:0] bytes]).sin_addr)] forKey:@"sharedPlayerHost"];
             }
         }
         
         if ([controller connectToServer]) {
             [useSharedMenuTunesCheckbox setState:NSOnState];
-            [selectedPlayerTextField setStringValue:[[[MainController sharedController] currentRemote] sharedRemoteName]];
+            [selectedPlayerTextField setStringValue:[[[NetworkController sharedController] networkObject] serverName]];
             [locationTextField setStringValue:[[NetworkController sharedController] remoteHost]];
         } 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);
@@ -307,7 +316,6 @@ static PreferencesController *prefs = nil;
         } else if ( effectTag == 2103 ) {
             [sw setEntryEffect:[[[ITSlideHorizontallyWindowEffect alloc] initWithWindow:sw] autorelease]];
         } else if ( effectTag == 2104 ) {
-            NSLog(@"dflhgldf");
             [sw setEntryEffect:[[[ITPivotWindowEffect alloc] initWithWindow:sw] autorelease]];
         }
 
@@ -669,7 +677,7 @@ static PreferencesController *prefs = nil;
     }
     
     if ([[NetworkController sharedController] isConnectedToServer]) {
-        [selectedPlayerTextField setStringValue:[[[MainController sharedController] currentRemote] sharedRemoteName]];
+        [selectedPlayerTextField setStringValue:[[[NetworkController sharedController] networkObject] serverName]];
         [locationTextField setStringValue:[[NetworkController sharedController] remoteHost]];
     } else {
         [selectedPlayerTextField setStringValue:@"No shared player selected."];
@@ -794,11 +802,7 @@ static PreferencesController *prefs = nil;
             return [[hotKeysDictionary objectForKey:[hotKeysArray objectAtIndex:rowIndex]] description];
         }
     } else {
-        if ([[aTableColumn identifier] isEqualToString:@"name"]) {
-            return [[[[NetworkController sharedController] remoteServices] objectAtIndex:rowIndex] name];
-        } else {
-            return @"X";
-        }
+        return [[[[NetworkController sharedController] remoteServices] objectAtIndex:rowIndex] name];
     }
 }