- ProcessSerialNumber psn;
- NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
- [defaults setObject:myItems forKey:@"menu"];
-
- //Set key combos
- [defaults setKeyCombo:playPauseCombo forKey:@"PlayPause"];
- [defaults setKeyCombo:nextTrackCombo forKey:@"NextTrack"];
- [defaults setKeyCombo:prevTrackCombo forKey:@"PrevTrack"];
- [defaults setKeyCombo:trackInfoCombo forKey:@"TrackInfo"];
- [defaults setKeyCombo:upcomingSongsCombo forKey:@"UpcomingSongs"];
-
- //Set info checkboxes
- [defaults setBool:[albumCheckbox state] forKey:@"showAlbum"];
- [defaults setBool:[nameCheckbox state] forKey:@"showName"];
- [defaults setBool:[artistCheckbox state] forKey:@"showArtist"];
- [defaults setBool:[trackTimeCheckbox state] forKey:@"showTime"];
-
- //Here we set whether we will launch at login by modifying loginwindow.plist
- if ([launchAtLoginCheckbox state] == NSOnState)
- {
- NSMutableDictionary *loginwindow;
- NSMutableArray *loginarray;
- int i;
- BOOL skip = NO;
+ [controller autorelease];
+ controller = [object retain];
+}
+
+
+/*************************************************************************/
+#pragma mark -
+#pragma mark INSTANCE METHODS
+/*************************************************************************/
+
+- (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
+ [window setDelegate:self];
+ [menuTableView reloadData];
+ [hotKeysTableView setDoubleAction:@selector(hotKeysTableViewDoubleClicked:)];
+
+ //Change the launch player checkbox to the proper name
+ 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];
+ [NSApp activateIgnoringOtherApps:YES];
+ [window performSelector:@selector(makeKeyAndOrderFront:) withObject:self afterDelay:0.0];
+}
+
+- (IBAction)changeGeneralSetting:(id)sender
+{
+ ITDebugLog(@"Changing general setting of tag %i.", [sender tag]);
+ if ( [sender tag] == 1010) {
+ [self setLaunchesAtLogin:SENDER_STATE];
+ } else if ( [sender tag] == 1020) {
+ [df setBool:SENDER_STATE forKey:@"LaunchPlayerWithMT"];
+ } else if ( [sender tag] == 1030) {
+ [df setInteger:[sender intValue] forKey:@"SongsInAdvance"];
+
+ } else if ( [sender tag] == 1040) {
+ // This will not be executed. Song info always shows the title of the song.
+ // [df setBool:SENDER_STATE forKey:@"showName"];
+ } else if ( [sender tag] == 1050) {
+ [df setBool:SENDER_STATE forKey:@"showArtist"];
+ } else if ( [sender tag] == 1060) {
+ [df setBool:SENDER_STATE forKey:@"showAlbum"];
+ } else if ( [sender tag] == 1070) {
+ [df setBool:SENDER_STATE forKey:@"showTime"];
+ } else if ( [sender tag] == 1080) {
+ [df setBool:SENDER_STATE forKey:@"showTrackNumber"];
+ } else if ( [sender tag] == 1090) {
+ [df setBool:SENDER_STATE forKey:@"showTrackRating"];
+ }
+ [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;
+ SHA1(instring, strlen(instring), &result);
+ hashedPass = [NSData dataWithBytes:&result length:strlen(&result)];
+ SHA1(password, strlen(password), &result);
+ passwordStringHash = [NSData dataWithBytes:&result length:strlen(&result)];
+ if (![hashedPass isEqualToData:passwordStringHash]) {
+ [df setObject:hashedPass forKey:@"sharedPlayerPassword"];
+ }
+ } 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];