X-Git-Url: http://git.ithinksw.org/MenuTunes.git/blobdiff_plain/b747fc827fed9c1cb7f9076067ae5334d12ab576..f5837543befd727c75d9c6a99cd5d5bfec234d10:/MenuTunes.m diff --git a/MenuTunes.m b/MenuTunes.m index f4a66cd..4c68648 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 { @@ -57,16 +57,15 @@ Things to do: [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(iTunesLaunched:) name:NSWorkspaceDidLaunchApplicationNotification object:nil]; refreshTimer = nil; } + + statusItem = [[ITStatusItem alloc] initWithStatusBar:[NSStatusBar systemStatusBar] + withLength:NSSquareStatusItemLength]; - statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength]; - [[[statusItem _button] cell] setType:NSNullCellType]; [statusItem setImage:[NSImage imageNamed:@"menu"]]; - [[statusItem _button] setAlternateImage:[NSImage imageNamed:@"selected_image"]]; - [statusItem setHighlightMode:YES]; + [statusItem setAlternateImage:[NSImage imageNamed:@"selected_image"]]; [statusItem setMenu:menu]; // Below line of code is for creating builds for Beta Testers - // [statusItem setToolTip:@"This Nontransferable Beta (Built on __DATE__) of iThink Software's MenuTunes is Registered to: Beta Tester (betatester@somedomain.com)."]; - [statusItem retain]; + // [statusItem setToolTip:@"This Nontransferable Beta (Built on XXX) of iThink Software's MenuTunes is Registered to: Beta Tester (betatester@somedomain.com)."]; } @@ -79,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", @@ -95,25 +99,52 @@ 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 objectForKey:@"showName"]) + if (![defaults integerForKey:@"SongsInAdvance"]) { + [defaults setInteger:5 forKey:@"SongsInAdvance"]; + } + + if (![defaults objectForKey:@"showName"]) { [defaults setBool:YES forKey:@"showName"]; } - if (![defaults objectForKey:@"showArtist"]) - { + if (![defaults objectForKey:@"showArtist"]) { [defaults setBool:YES forKey:@"showArtist"]; } - if (![defaults objectForKey:@"showAlbum"]) - { + if (![defaults objectForKey:@"showAlbum"]) { [defaults setBool:NO forKey:@"showAlbum"]; } - if (![defaults objectForKey:@"showTime"]) - { + if (![defaults objectForKey:@"showTime"]) { [defaults setBool:NO forKey:@"showTime"]; } } @@ -215,9 +246,11 @@ Things to do: if (upcomingSongsItem) { [self rebuildUpcomingSongsMenu]; } + if (playlistItem) { [self rebuildPlaylistMenu]; } + if (eqItem) { [self rebuildEQPresetsMenu]; } @@ -227,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]; @@ -277,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:@""]; @@ -289,7 +324,6 @@ Things to do: [menu insertItem:menuItem atIndex:trackInfoIndex]; [menuItem release]; } - } else if ([menu indexOfItemWithTitle:@"No Song"] == -1) { [menu removeItemAtIndex:trackInfoIndex]; @@ -315,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); + } } } @@ -766,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]; } }