+ } else if ( [sender tag] == 1100) {
+ [df setBool:SENDER_STATE forKey:@"showAlbumArtwork"];
+ } else if ( [sender tag] == 1110) {
+ [df setBool:SENDER_STATE forKey:@"runScripts"];
+ if (SENDER_STATE) {
+ [runScriptsCheckbox setState:NSOnState];
+ [showScriptsButton setEnabled:YES];
+ } else {
+ [showScriptsButton setEnabled:NO];
+ }
+ } else if ( [sender tag] == 1120) {
+ mkdir([[NSHomeDirectory() stringByAppendingPathComponent:@"Library/Application Support/MenuTunes/Scripts"] cString], 0744);
+ [[NSWorkspace sharedWorkspace] openFile:[NSHomeDirectory() stringByAppendingPathComponent:@"Library/Application Support/MenuTunes/Scripts"]];
+ } else if ( [sender tag] == 6010) {
+ //Toggle the other Audioscrobbler options
+ [df setBool:SENDER_STATE forKey:@"audioscrobblerEnabled"];
+ [audioscrobblerUseCacheCheckbox setEnabled:SENDER_STATE];
+ [audioscrobblerUserTextField setEnabled:SENDER_STATE];
+ [audioscrobblerPasswordTextField setEnabled:SENDER_STATE];
+ } else if ( [sender tag ] == 6015) {
+ //Here we create a new keychain item if needed and deletes the keychain item if the field is cleared.
+ NSString *currentAccount = [df stringForKey:@"audioscrobblerUser"], *newAccount = [sender stringValue];
+ if ([newAccount length] == 0) {
+ [self deleteKeychainItemForUser:currentAccount];
+ } else if (![currentAccount isEqualToString:newAccount] && [[audioscrobblerPasswordTextField stringValue] length] > 0) {
+ [df setObject:newAccount forKey:@"audioscrobblerUser"];
+ if ([self keychainItemExistsForUser:currentAccount]) {
+ //Delete the current keychain item if there is one
+ [self deleteKeychainItemForUser:currentAccount];
+ }
+ [self createKeychainItemForUser:newAccount andPassword:[audioscrobblerPasswordTextField stringValue]];
+ }
+ } else if ( [sender tag ] == 6030) {
+ //Here we set the password for an existing keychain item or we create a new keychain item.
+ if ([[audioscrobblerUserTextField stringValue] length] > 0) {
+ NSString *account = [df stringForKey:@"audioscrobblerUser"];
+ if ([self keychainItemExistsForUser:account]) {
+ //Update the current keychain item
+ [self setKeychainItemPassword:[sender stringValue] forUser:account];
+ } else if ([[sender stringValue] length] > 0 && [[audioscrobblerUserTextField stringValue] length]) {
+ //Create a new keychain item
+ [self createKeychainItemForUser:account andPassword:[sender stringValue]];
+ }
+ }
+ } else if ( [sender tag] == 6045) {
+ [df setBool:SENDER_STATE forKey:@"audioscrobblerCacheSubmissions"];
+ }
+ [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];
+ [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"];
+ [[NetworkController sharedController] resetServerName];
+ } else if ( [sender tag] == 5030 ) {
+ //Set the server password
+ const char *instring = [[sender stringValue] UTF8String];
+ const char *password = "p4s5w0rdMT1.2";
+ char *result;
+ NSData *hashedPass, *passwordStringHash;
+ if ([[sender stringValue] length] == 0) {
+ [df setObject:[NSData data] forKey:@"sharedPlayerPassword"];
+ return;
+ }
+ result = (char *)SHA1((unsigned char *)instring, strlen(instring), NULL);
+ hashedPass = [NSData dataWithBytes:result length:strlen(result)];
+ result = (char *)SHA1((unsigned char *)password, strlen(password), NULL);
+ passwordStringHash = [NSData dataWithBytes:result length:strlen(result)];
+ if (![hashedPass isEqualToData:passwordStringHash]) {
+ [df setObject:hashedPass forKey:@"sharedPlayerPassword"];
+ [sender setStringValue:@"p4s5w0rdMT1.2"];
+ }
+ } else if ( [sender tag] == 5040 ) {
+ BOOL state = SENDER_STATE;
+ [df setBool:state forKey:@"useSharedPlayer"];
+ //Disable/enable the use of sharing options
+ [shareMenuTunesCheckbox setEnabled:!state];
+ [passwordTextField setEnabled:NO];
+ [nameTextField setEnabled:NO];
+ [selectSharedPlayerButton setEnabled:state];
+
+ if (state && ([controller connectToServer] == 1)) {
+ [selectedPlayerTextField setStringValue:[[[NetworkController sharedController] networkObject] serverName]];
+ [locationTextField setStringValue:[[NetworkController sharedController] remoteHost]];
+ } else {
+ [selectedPlayerTextField setStringValue:@"No shared player selected."];
+ [locationTextField setStringValue:@"-"];
+ if ([[NetworkController sharedController] isConnectedToServer]) {
+ [controller disconnectFromServer];
+ }
+
+ }
+ } else if ( [sender tag] == 5050 ) {
+ //If no player is selected in the table view, turn off OK button.
+ if ([sender clickedRow] == -1 ) {
+ [sharingPanelOKButton setEnabled:NO];
+ } else {
+ [sharingPanelOKButton setEnabled:YES];
+ }
+ } else if ( [sender tag] == 5051 ) {
+ [df setObject:[sender stringValue] forKey:@"sharedPlayerHost"];
+ } else if ( [sender tag] == 5060 ) {
+ //Set OK button state
+ if (([selectPlayerBox contentView] == zeroConfView && [sharingTableView selectedRow] == -1) ||
+ ([selectPlayerBox contentView] == manualView && [[hostTextField stringValue] length] == 0)) {
+ [sharingPanelOKButton setEnabled:NO];
+ } else {
+ [sharingPanelOKButton setEnabled:YES];
+ }
+ //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;
+ if ([sharingTableView selectedRow] == -1) {
+ [sharingPanelOKButton setEnabled:NO];
+ }
+ [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;
+ if ([[hostTextField stringValue] length] == 0) {
+ [sharingPanelOKButton setEnabled:NO];
+ } else {
+ [sharingPanelOKButton setEnabled:YES];
+ }
+ [selectPlayerBox setContentView:manualView];
+ [selectPlayerSheet setFrame:frame display:YES animate:YES];
+ [hostTextField selectText:nil];
+ }
+ } else if ( [sender tag] == 5150 ) {
+ const char *instring = [[sender stringValue] UTF8String];
+ char *result;
+ result = (char *)SHA1((unsigned char *)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] == 1) {
+ [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);
+ }
+ } 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];
+ char *result;
+ result = (char *)SHA1((unsigned char *)instring, strlen(instring), NULL);
+ [df setObject:[NSData dataWithBytes:result length:strlen(result)] forKey:@"connectPassword"];
+ [passwordPanel orderOut:nil];
+ [NSApp stopModalWithCode:1];