From: Kent Sutherland Date: Sat, 14 Dec 2002 23:00:40 +0000 (+0000) Subject: Changes in autologin and defaults. X-Git-Tag: v1.0~258 X-Git-Url: http://git.ithinksw.org/MenuTunes.git/commitdiff_plain/ea3dc416d45e5e72dc83a757a2031a2a763bbe51 Changes in autologin and defaults. --- diff --git a/English.lproj/Preferences.nib/objects.nib b/English.lproj/Preferences.nib/objects.nib index b6245a4..837bf6e 100755 Binary files a/English.lproj/Preferences.nib/objects.nib and b/English.lproj/Preferences.nib/objects.nib differ diff --git a/MenuTunes.h b/MenuTunes.h index da28d11..cde1eff 100755 --- a/MenuTunes.h +++ b/MenuTunes.h @@ -51,7 +51,7 @@ PreferencesController *prefsController; StatusWindowController *statusController; //Shows track info and upcoming songs. } - +- (void)registerDefaultsIfNeeded; - (void)rebuildMenu; - (void)clearHotKeys; - (ProcessSerialNumber)iTunesPSN; diff --git a/MenuTunes.m b/MenuTunes.m index c461779..0b25dc9 100755 --- a/MenuTunes.m +++ b/MenuTunes.m @@ -3,6 +3,7 @@ Things to do: ¥ Make preferences window pretty ¥ Optimize ¥ Apple Events! Apple Events! Apple Events! +¥ Manual and webpage */ #import "MenuTunes.h" @@ -11,7 +12,6 @@ Things to do: #import "StatusWindowController.h" @interface MenuTunes(Private) -- (void)registerDefaultsIfNeeded; - (void)updateMenu; - (void)rebuildUpcomingSongsMenu; - (void)rebuildPlaylistMenu; @@ -43,10 +43,10 @@ Things to do: { [self rebuildMenu]; refreshTimer = [NSTimer scheduledTimerWithTimeInterval:3.5 - target:self - selector:@selector(timerUpdate) - userInfo:nil - repeats:YES]; + target:self + selector:@selector(timerUpdate) + userInfo:nil + repeats:YES]; } else { @@ -78,6 +78,11 @@ Things to do: { NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; if (![defaults objectForKey:@"menu"]) { + bool found = NO; + NSMutableDictionary *loginwindow; + NSMutableArray *loginarray; + int i; + [defaults setObject: [NSArray arrayWithObjects: @"Play/Pause", @@ -94,6 +99,37 @@ Things to do: @"", @"Current Track Info", nil] forKey:@"menu"]; + + [defaults synchronize]; + loginwindow = [[defaults persistentDomainForName:@"loginwindow"] mutableCopy]; + loginarray = [loginwindow objectForKey:@"AutoLaunchedApplicationDictionary"]; + + for (i = 0; i < [loginarray count]; i++) { + NSDictionary *tempDict = [loginarray objectAtIndex:i]; + if ([[[tempDict objectForKey:@"Path"] lastPathComponent] isEqualToString:[[[NSBundle mainBundle] bundlePath] lastPathComponent]]) { + found = YES; + } + } + + if (!found) { + if (NSRunInformationalAlertPanel(@"Auto-launch MenuTunes", @"Would you like MenuTunes to automatically launch at login?", @"Yes", @"No", nil) == NSOKButton) { + 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]]; + + AECreateDesc(typeChar, [script cString], [script cStringLength], + &scriptDesc); + + OSADoScript(asComponent, &scriptDesc, kOSANullScript, typeChar, kOSAModeCanInteract, &resultDesc); + + AEDisposeDesc(&scriptDesc); + AEDisposeDesc(&resultDesc); + } + } + } + + if (![defaults integerForKey:@"SongsInAdvance"]) + { + [defaults setInteger:5 forKey:@"SongsInAdvance"]; } if (![defaults objectForKey:@"showName"]) { @@ -224,17 +260,16 @@ Things to do: NSString *curSongName, *curAlbumName = @"", *curArtistName = @""; curSongName = [self runScriptAndReturnResult:@"return name of current track"]; - if ([defaults boolForKey:@"showArtist"]) { + if ([defaults boolForKey:@"showAlbum"]) { curAlbumName = [self runScriptAndReturnResult:@"return album of current track"]; } - if ([defaults boolForKey:@"showAlbum"]) { + if ([defaults boolForKey:@"showArtist"]) { curArtistName = [self runScriptAndReturnResult:@"return artist of current track"]; } if ([curSongName length] > 0) { int index = [menu indexOfItemWithTitle:@"Now Playing"]; - if (index > -1) { if ([defaults boolForKey:@"showName"]) { [menu removeItemAtIndex:index + 1]; @@ -274,11 +309,14 @@ Things to do: [menuItem release]; } } - menuItem = [[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@" %@", curSongName] - action:nil - keyEquivalent:@""]; - [menu insertItem:menuItem atIndex:trackInfoIndex + 1]; - [menuItem release]; + + if ([defaults boolForKey:@"showName"]) { + menuItem = [[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@" %@", curSongName] + action:nil + keyEquivalent:@""]; + [menu insertItem:menuItem atIndex:trackInfoIndex + 1]; + [menuItem release]; + } if (index == -1) { menuItem = [[NSMenuItem alloc] initWithTitle:@"Now Playing" action:nil keyEquivalent:@""]; @@ -286,7 +324,6 @@ Things to do: [menu insertItem:menuItem atIndex:trackInfoIndex]; [menuItem release]; } - } else if ([menu indexOfItemWithTitle:@"No Song"] == -1) { [menu removeItemAtIndex:trackInfoIndex]; @@ -312,12 +349,12 @@ Things to do: } if ([defaults boolForKey:@"showArtist"]) { - didHaveAlbumName = (([curAlbumName length] > 0) ? YES : NO); - } + didHaveAlbumName = (([curArtistName length] > 0) ? YES : NO); + } - if ([defaults boolForKey:@"showAlbum"]) { - didHaveArtistName = (([curArtistName length] > 0) ? YES : NO); - } + if ([defaults boolForKey:@"showAlbum"]) { + didHaveArtistName = (([curAlbumName length] > 0) ? YES : NO); + } } } @@ -763,10 +800,10 @@ isEqualToString:@"rewinding"]) { statusController = [[StatusWindowController alloc] init]; [statusController setTrackInfo:stringToShow lines:lines]; [NSTimer scheduledTimerWithTimeInterval:3.0 - target:self - selector:@selector(fadeAndCloseStatusWindow) - userInfo:nil - repeats:NO]; + target:self + selector:@selector(fadeAndCloseStatusWindow) + userInfo:nil + repeats:NO]; } } diff --git a/PreferencesController.m b/PreferencesController.m index 5a83ffb..b4cba9e 100755 --- a/PreferencesController.m +++ b/PreferencesController.m @@ -10,9 +10,9 @@ int i; NSImageCell *imgCell = [[[NSImageCell alloc] init] autorelease]; NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; - NSString *temp; mt = [tunes retain]; + [mt registerDefaultsIfNeeded]; //Load the nib [NSBundle loadNibNamed:@"Preferences" owner:self]; @@ -36,11 +36,6 @@ //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++) { @@ -55,11 +50,7 @@ submenuItems = [[NSArray alloc] initWithObjects:@"Upcoming Songs", @"Playlists", @"EQ Presets", 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 +89,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,11 +106,7 @@ 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]; } } @@ -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];