X-Git-Url: http://git.ithinksw.org/MenuTunes.git/blobdiff_plain/6e879de483fcc0349bb3720d1eb8ae74dc6d3803..a822d608c6739b4c2cd2c39187a78ca461d4d6d4:/PreferencesController.m?ds=sidebyside diff --git a/PreferencesController.m b/PreferencesController.m index 187398f..82b7f82 100755 --- a/PreferencesController.m +++ b/PreferencesController.m @@ -1,27 +1,22 @@ #import "PreferencesController.h" -#import "MenuTunes.h" +#import "MainController.h" #import "HotKeyCenter.h" @implementation PreferencesController -- (id)initWithMenuTunes:(MenuTunes *)tunes; +- (id)initWithMenuTunes:(MainController *)tunes; { if ( (self = [super init]) ) { int i; NSImageCell *imgCell = [[[NSImageCell alloc] init] autorelease]; NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; - NSString *temp; mt = [tunes retain]; + [mt registerDefaults]; //Load the nib [NSBundle loadNibNamed:@"Preferences" owner:self]; - //Show our window - [window setLevel:NSStatusWindowLevel]; - [window center]; - [window makeKeyAndOrderFront:nil]; - //Set the table view cells up [imgCell setImageScaling:NSScaleNone]; [[menuTableView tableColumnWithIdentifier:@"submenu"] setDataCell:imgCell]; @@ -32,15 +27,10 @@ [allTableView registerForDraggedTypes:[NSArray arrayWithObjects:@"MenuTableViewPboardType", @"AllTableViewPboardType", nil]]; //Set the list of items you can have. - availableItems = [[NSMutableArray alloc] initWithObjects:@"Current Track Info", @"Upcoming Songs", @"Playlists", @"EQ Presets", @"Play/Pause", @"Next Track", @"Previous Track", @"Fast Forward", @"Rewind", @"", nil]; + availableItems = [[NSMutableArray alloc] initWithObjects:@"Current Track Info", @"Upcoming Songs", @"Playlists", @"EQ Presets", @"Song Rating", @"Play/Pause", @"Next Track", @"Previous Track", @"Fast Forward", @"Rewind", @"", nil]; //Get our preferred menu myItems = [[[NSUserDefaults standardUserDefaults] arrayForKey:@"menu"] mutableCopy]; - if (myItems == nil) - { - myItems = [[NSMutableArray alloc] initWithObjects:@"Play/Pause", @"Next Track", @"Previous Track", @"Fast Forward", @"Rewind", @"", @"Upcoming Songs", @"Playlists", @"EQ Presets", @"", @"PreferencesÉ", @"Quit", @"", @"Current Track Info", nil]; - [[NSUserDefaults standardUserDefaults] setObject:myItems forKey:@"menu"]; - } //Delete items in the availableItems array that are already part of the menu for (i = 0; i < [myItems count]; i++) { @@ -52,14 +42,10 @@ } //Items that show should a submenu image - submenuItems = [[NSArray alloc] initWithObjects:@"Upcoming Songs", @"Playlists", @"EQ Presets", nil]; + submenuItems = [[NSArray alloc] initWithObjects:@"Upcoming Songs", @"Playlists", @"EQ Presets", @"Song Rating", nil]; //Fill in the number of songs in advance to show field - if ([defaults integerForKey:@"SongsInAdvance"]) { - [songsInAdvance setIntValue:[defaults integerForKey:@"SongsInAdvance"]]; - } else { - [songsInAdvance setIntValue:5]; - } + [songsInAdvance setIntValue:[defaults integerForKey:@"SongsInAdvance"]]; //Fill in hot key buttons if ([defaults objectForKey:@"PlayPause"]){ @@ -98,24 +84,8 @@ } //Check current track info buttons - - //Album and name get special treatment because they are defaults - if ( (temp = [defaults stringForKey:@"showAlbum"]) ) { - if ((temp == nil) || [temp isEqualToString:@"1"]) { - [albumCheckbox setState:NSOnState]; - } else { - [albumCheckbox setState:NSOffState]; - } - } - - if ( (temp = [defaults stringForKey:@"showName"]) ) { - if ((temp == nil) || [temp isEqualToString:@"1"]) { - [nameCheckbox setState:NSOnState]; - } else { - [nameCheckbox setState:NSOffState]; - } - } - + [albumCheckbox setState:[defaults boolForKey:@"showAlbum"] ? NSOnState : NSOffState]; + [nameCheckbox setState:[defaults boolForKey:@"showName"] ? NSOnState : NSOffState]; [artistCheckbox setState:[defaults boolForKey:@"showArtist"] ? NSOnState : NSOffState]; [trackTimeCheckbox setState:[defaults boolForKey:@"showTime"] ? NSOnState : NSOffState]; @@ -131,15 +101,17 @@ for (i = 0; i < [loginarray count]; i++) { NSDictionary *tempDict = [loginarray objectAtIndex:i]; - - //Here we are seeing if our program is already in loginwindow.plist. - //See the problem below for this problem here. We will do the same thing. - - if ([[[tempDict objectForKey:@"Path"] lastPathComponent] isEqualToString:@"VocabularyBuilder.app"]) { + if ([[[tempDict objectForKey:@"Path"] lastPathComponent] isEqualToString:[[[NSBundle mainBundle] bundlePath] lastPathComponent]]) { [launchAtLoginCheckbox setState:NSOnState]; } } } + + //Show our window + [window setLevel:NSStatusWindowLevel]; + [window center]; + [window makeKeyAndOrderFront:nil]; + [window setDelegate:self]; } return self; } @@ -163,7 +135,6 @@ - (IBAction)apply:(id)sender { - ProcessSerialNumber psn; NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; [defaults setObject:myItems forKey:@"menu"]; @@ -184,6 +155,7 @@ if ([launchAtLoginCheckbox state] == NSOnState) { NSMutableDictionary *loginwindow; NSMutableArray *loginarray; + ComponentInstance temp = OpenDefaultComponent(kOSAComponentType, kAppleScriptSubtype);; int i; BOOL skip = NO; @@ -193,20 +165,23 @@ for (i = 0; i < [loginarray count]; i++) { NSDictionary *tempDict = [loginarray objectAtIndex:i]; - - //Here we are seeing if our program is already in loginwindow.plist. - //See the problem below for this problem here. We will do the same thing. - - if ([[[tempDict objectForKey:@"Path"] lastPathComponent] isEqualToString:@"VocabularyBuilder.app"]) { + if ([[[tempDict objectForKey:@"Path"] lastPathComponent] isEqualToString:[[[NSBundle mainBundle] bundlePath] lastPathComponent]]) { skip = YES; } } if (!skip) { - [loginarray addObject:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:NO], @"Hide", [[NSBundle mainBundle] bundlePath], @"Path", nil]]; + AEDesc scriptDesc, resultDesc; + NSString *script = [NSString stringWithFormat:@"tell application \"System Events\"\nmake new login item at end of login items with properties {path:\"%@\", kind:\"APPLICATION\"}\nend tell", [[NSBundle mainBundle] bundlePath]]; - [defaults setPersistentDomain:loginwindow forName:@"loginwindow"]; - [defaults synchronize]; + AECreateDesc(typeChar, [script cString], [script cStringLength], + &scriptDesc); + + OSADoScript(temp, &scriptDesc, kOSANullScript, typeChar, kOSAModeCanInteract, &resultDesc); + + AEDisposeDesc(&scriptDesc); + AEDisposeDesc(&resultDesc); + CloseComponent(temp); } } else { NSMutableDictionary *loginwindow; @@ -219,8 +194,7 @@ for (i = 0; i < [loginarray count]; i++) { NSDictionary *tempDict = [loginarray objectAtIndex:i]; - - if ([[[tempDict objectForKey:@"Path"] lastPathComponent] isEqualToString:@"VocabularyBuilder.app"]) { + if ([[[tempDict objectForKey:@"Path"] lastPathComponent] isEqualToString:[[[NSBundle mainBundle] bundlePath] lastPathComponent]]) { [loginarray removeObjectAtIndex:i]; [defaults setPersistentDomain:loginwindow forName:@"loginwindow"]; [defaults synchronize]; @@ -236,10 +210,17 @@ [defaults setInteger:5 forKey:@"SongsInAdvance"]; } - psn = [mt iTunesPSN]; - if (!((psn.highLongOfPSN == kNoProcess) && (psn.lowLongOfPSN == 0))) { - [mt rebuildMenu]; - } + /*{ + NSArray *apps = [[NSWorkspace sharedWorkspace] launchedApplications]; + int i; + + for (i = 0; i < [apps count]; i++) { + if ([[[apps objectAtIndex:i] objectForKey:@"NSApplicationName"] + isEqualToString:@"iTunes"]) { + [mt rebuildMenu]; + } + } + }*/ [mt clearHotKeys]; } @@ -263,15 +244,7 @@ - (IBAction)okHotKey:(id)sender { - NSString *string; - if (([combo modifiers] <= 0) && ([combo keyCode] >= 0)) { - [window setLevel:NSNormalWindowLevel]; - NSRunAlertPanel(@"Bad Key Combo", @"Please enter a valid key combo. A valid combo must have a modifier key in it. (Command, option, shift, control).", @"OK", nil, nil, nil); - [window setLevel:NSStatusWindowLevel]; - return; - } - - string = [combo userDisplayRep]; + NSString *string = [combo userDisplayRep]; if (string == nil) { string = @"None"; @@ -419,15 +392,12 @@ [keyComboField setStringValue:string]; } -// -// -// Text Field Delegate // // -- (void)controlTextDidChange:(NSNotification *)note +- (void)windowWillClose:(NSNotification *)note { - NSLog(@"%@", [note userInfo]); + [mt closePreferences]; } //