#import "PreferencesController.h"
#import "MainController.h"
+#import "NetworkController.h"
+#import "NetworkObject.h"
#import "StatusWindow.h"
#import "StatusWindowController.h"
#import "CustomMenuTableView.h"
+#import <netinet/in.h>
+#import <arpa/inet.h>
+#import <openssl/sha.h>
+
#import <ITKit/ITHotKeyCenter.h>
#import <ITKit/ITKeyCombo.h>
#import <ITKit/ITKeyComboPanel.h>
[hotKeysTableView setDoubleAction:@selector(hotKeysTableViewDoubleClicked:)];
//Change the launch player checkbox to the proper name
- [launchPlayerAtLaunchCheckbox setTitle:[NSString stringWithFormat:@"Launch %@ when MenuTunes launches", [[controller currentRemote] playerSimpleName]]]; //This isn't localized...
+ NS_DURING
+ [launchPlayerAtLaunchCheckbox setTitle:[NSString stringWithFormat:@"Launch %@ when MenuTunes launches", [[controller currentRemote] playerSimpleName]]]; //This isn't localized...
+ NS_HANDLER
+ [controller networkError:localException];
+ NS_ENDHANDLER
}
[window center];
[df synchronize];
}
+- (IBAction)changeSharingSetting:(id)sender
+{
+ ITDebugLog(@"Changing sharing setting of tag %i.", [sender tag]);
+ if ( [sender tag] == 5010 ) {
+ BOOL state = SENDER_STATE;
+ [df setBool:state forKey:@"enableSharing"];
+ //Disable/enable the use of shared player options
+ [useSharedMenuTunesCheckbox setEnabled:!state];
+ [usePasswordCheckbox setEnabled:state];
+ [passwordTextField setEnabled:state];
+ [nameTextField setEnabled:state];
+ [selectSharedPlayerButton setEnabled:NO];
+ [controller setServerStatus:state]; //Set server status
+ } else if ( [sender tag] == 5015 ) {
+ [df setObject:[sender stringValue] forKey:@"sharedPlayerName"];
+ } else if ( [sender tag] == 5020 ) {
+ [df setBool:SENDER_STATE forKey:@"enableSharingPassword"];
+ } else if ( [sender tag] == 5030 ) {
+ //Set the server password
+ const char *instring = [[sender stringValue] UTF8String];
+ const char *password = "password";
+ unsigned char *result;
+ NSData *hashedPass, *passwordStringHash;
+ 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;
+ [df setBool:state forKey:@"useSharedPlayer"];
+ //Disable/enable the use of sharing options
+ [shareMenuTunesCheckbox setEnabled:!state];
+ [usePasswordCheckbox setEnabled:NO];
+ [passwordTextField setEnabled:NO];
+ [nameTextField setEnabled:NO];
+ [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
+ } else if ( [sender tag] == 5051 ) {
+ [df setObject:[sender stringValue] forKey:@"sharedPlayerHost"];
+ } else if ( [sender tag] == 5060 ) {
+ //Show selection sheet
+ [NSApp beginSheet:selectPlayerSheet modalForWindow:window modalDelegate:self didEndSelector:NULL contextInfo:nil];
+ } else if ( [sender tag] == 5100 ) {
+ //Change view
+ if ( ([sender indexOfItem:[sender selectedItem]] == 0) && ([selectPlayerBox contentView] != zeroConfView) ) {
+ NSRect frame = [selectPlayerSheet frame];
+ frame.origin.y -= 58;
+ frame.size.height = 273;
+ [selectPlayerBox setContentView:zeroConfView];
+ [selectPlayerSheet setFrame:frame display:YES animate:YES];
+ } else if ( ([sender indexOfItem:[sender selectedItem]] == 1) && ([selectPlayerBox contentView] != manualView) ){
+ NSRect frame = [selectPlayerSheet frame];
+ frame.origin.y += 58;
+ frame.size.height = 215;
+ //[window makeFirstResponder:hostTextField];
+ [selectPlayerBox setContentView:manualView];
+ [selectPlayerSheet setFrame:frame display:YES animate:YES];
+ [hostTextField selectText:nil];
+ }
+ } else if ( [sender tag] == 5150 ) {
+ const char *instring = [[sender stringValue] UTF8String];
+ 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];
+ [selectPlayerSheet orderOut:nil];
+ if ([selectPlayerBox contentView] == manualView) {
+ [hostTextField setStringValue:[df stringForKey:@"sharedPlayerHost"]];
+ } else {
+ }
+ } else if ( [sender tag] == 5120 ) {
+ //OK, try to connect
+ [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]] addresses] objectAtIndex:0] bytes]).sin_addr)] forKey:@"sharedPlayerHost"];
+ }
+ }
+
+ if ([controller connectToServer]) {
+ [useSharedMenuTunesCheckbox setState:NSOnState];
+ [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);
+ }
+ }
+ [df synchronize];
+}
+
- (IBAction)changeStatusWindowSetting:(id)sender
{
StatusWindow *sw = [StatusWindow sharedWindow];
} else if ( effectTag == 2103 ) {
[sw setEntryEffect:[[[ITSlideHorizontallyWindowEffect alloc] initWithWindow:sw] autorelease]];
} else if ( effectTag == 2104 ) {
- NSLog(@"dflhgldf");
[sw setEntryEffect:[[[ITPivotWindowEffect alloc] initWithWindow:sw] autorelease]];
}
NSMutableDictionary *loginwindow;
NSMutableArray *loginarray;
NSEnumerator *loginEnum, *keyArrayEnum;
+ NSString *serverName;
id anItem;
ITDebugLog(@"Setting up preferences UI.");
[vanishSpeedSlider setFloatValue:-([df floatForKey:@"statusWindowVanishSpeed"])];
[vanishDelaySlider setFloatValue:[df floatForKey:@"statusWindowVanishDelay"]];
[showOnChangeCheckbox setState:([df boolForKey:@"showSongInfoOnChange"] ? NSOnState : NSOffState)];
+
+ // Setup the sharing controls
+ if ([df boolForKey:@"enableSharing"]) {
+ [shareMenuTunesCheckbox setState:NSOnState];
+ [useSharedMenuTunesCheckbox setEnabled:NO];
+ [selectSharedPlayerButton setEnabled:NO];
+ [passwordTextField setEnabled:YES];
+ [usePasswordCheckbox setEnabled:YES];
+ [nameTextField setEnabled:YES];
+ } else if ([df boolForKey:@"useSharedPlayer"]) {
+ [useSharedMenuTunesCheckbox setState:NSOnState];
+ [shareMenuTunesCheckbox setEnabled:NO];
+ [selectSharedPlayerButton setEnabled:YES];
+ }
+
+ [[NSNotificationCenter defaultCenter] addObserver:sharingTableView selector:@selector(reloadData) name:@"ITMTFoundNetService" object:nil];
+
+ serverName = [df stringForKey:@"sharedPlayerName"];
+ if (!serverName || [serverName length] == 0) {
+ serverName = @"MenuTunes Shared Player";
+ }
+ [nameTextField setStringValue:serverName];
+
+ [selectPlayerBox setContentView:zeroConfView];
+ [usePasswordCheckbox setState:([df boolForKey:@"enableSharingPassword"] ? NSOnState : NSOffState)];
+ if ([df dataForKey:@"sharedPlayerPassword"]) {
+ [passwordTextField setStringValue:@"password"];
+ }
+ if ([df stringForKey:@"sharedPlayerHost"]) {
+ [hostTextField setStringValue:[df stringForKey:@"sharedPlayerHost"]];
+ }
+
+ if ([[NetworkController sharedController] isConnectedToServer]) {
+ [selectedPlayerTextField setStringValue:[[[NetworkController sharedController] networkObject] serverName]];
+ [locationTextField setStringValue:[[NetworkController sharedController] remoteHost]];
+ } else {
+ [selectedPlayerTextField setStringValue:@"No shared player selected."];
+ [locationTextField setStringValue:@"-"];
+ }
}
- (IBAction)changeMenus:(id)sender
return [myItems count];
} else if (aTableView == allTableView) {
return [availableItems count];
- } else {
+ } else if (aTableView == hotKeysTableView) {
return [hotKeysArray count];
+ } else {
+ return [[[NetworkController sharedController] remoteServices] count];
}
}
NSString *object = [myItems objectAtIndex:rowIndex];
if ([[aTableColumn identifier] isEqualToString:@"name"]) {
if ([object isEqualToString:@"showPlayer"]) {
- return [NSString stringWithFormat:@"%@ %@", NSLocalizedString(@"show", @"Show"), [[controller currentRemote] playerSimpleName]];
+ NSString *string;
+ NS_DURING
+ string = [NSString stringWithFormat:@"%@ %@", NSLocalizedString(@"show", @"Show"), [[controller currentRemote] playerSimpleName]];
+ NS_HANDLER
+ [controller networkError:localException];
+ NS_ENDHANDLER
+ return string;
}
return NSLocalizedString(object, @"ERROR");
} else {
NSString *object = [availableItems objectAtIndex:rowIndex];
if ([[aTableColumn identifier] isEqualToString:@"name"]) {
if ([object isEqualToString:@"showPlayer"]) {
- return [NSString stringWithFormat:@"%@ %@", NSLocalizedString(@"show", @"Show"), [[controller currentRemote] playerSimpleName]];
+ NSString *string;
+ NS_DURING
+ string = [NSString stringWithFormat:@"%@ %@", NSLocalizedString(@"show", @"Show"), [[controller currentRemote] playerSimpleName]];
+ NS_HANDLER
+ [controller networkError:localException];
+ NS_ENDHANDLER
+ return string;
}
return NSLocalizedString(object, @"ERROR");
} else {
return nil;
}
}
- } else {
+ } else if (aTableView == hotKeysTableView) {
if ([[aTableColumn identifier] isEqualToString:@"name"]) {
return [hotKeyNamesArray objectAtIndex:rowIndex];
} else {
return [[hotKeysDictionary objectForKey:[hotKeysArray objectAtIndex:rowIndex]] description];
}
+ } else {
+ return [[[[NetworkController sharedController] remoteServices] objectAtIndex:rowIndex] name];
}
}