X-Git-Url: http://git.ithinksw.org/MenuTunes.git/blobdiff_plain/14a8ec19b5f01373410c11ef20c28367fe911e28..418a547d5daa457e97c3964224af5d703df5a19f:/MenuTunes.m diff --git a/MenuTunes.m b/MenuTunes.m index 7df098f..98748eb 100755 --- a/MenuTunes.m +++ b/MenuTunes.m @@ -3,6 +3,8 @@ Things to do: ¥ Make preferences window pretty ¥ Optimize ¥ Apple Events! Apple Events! Apple Events! +¥ Manual and webpage +¥ Finish up registration frontend */ #import "MenuTunes.h" @@ -11,7 +13,6 @@ Things to do: #import "StatusWindowController.h" @interface MenuTunes(Private) -- (void)registerDefaultsIfNeeded; - (void)updateMenu; - (void)rebuildUpcomingSongsMenu; - (void)rebuildPlaylistMenu; @@ -43,10 +44,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 { @@ -59,13 +60,13 @@ Things to do: } statusItem = [[ITStatusItem alloc] initWithStatusBar:[NSStatusBar systemStatusBar] - withLength:NSVariableStatusItemLength]; + withLength:NSSquareStatusItemLength]; [statusItem setImage:[NSImage imageNamed:@"menu"]]; [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 setToolTip:@[NSString stringWithFormat:@"This Nontransferable Beta (Built on %s) of iThink Software's MenuTunes is Registered to: Beta Tester (betatester@somedomain.com).",__DATE__]]; } @@ -78,6 +79,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 +100,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,31 +261,31 @@ 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]; } - if (didHaveAlbumName) { + if (didHaveAlbumName && [defaults boolForKey:@"showAlbum"]) { [menu removeItemAtIndex:index + 1]; } - if (didHaveArtistName) { + if (didHaveArtistName && [defaults boolForKey:@"showArtist"]) { [menu removeItemAtIndex:index + 1]; } if ([defaults boolForKey:@"showTime"]) { [menu removeItemAtIndex:index + 1]; } } + if (!isPlayingRadio) { if ([defaults boolForKey:@"showTime"]) { menuItem = [[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@" %@", [self runScriptAndReturnResult:@"return time of current track"]] @@ -274,11 +311,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 +326,6 @@ Things to do: [menu insertItem:menuItem atIndex:trackInfoIndex]; [menuItem release]; } - } else if ([menu indexOfItemWithTitle:@"No Song"] == -1) { [menu removeItemAtIndex:trackInfoIndex]; @@ -312,12 +351,12 @@ Things to do: } if ([defaults boolForKey:@"showArtist"]) { - didHaveAlbumName = (([curAlbumName length] > 0) ? YES : NO); - } + didHaveArtistName = (([curArtistName length] > 0) ? YES : NO); + } - if ([defaults boolForKey:@"showAlbum"]) { - didHaveArtistName = (([curArtistName length] > 0) ? YES : NO); - } + if ([defaults boolForKey:@"showAlbum"]) { + didHaveAlbumName = (([curAlbumName length] > 0) ? YES : NO); + } } } @@ -589,7 +628,7 @@ Things to do: if ([(NSString *)procName isEqualToString:@"iTunes"]) { return procNum; } - [(NSString *)procName release]; + CFRelease(procName); } } return procNum; @@ -716,7 +755,6 @@ isEqualToString:@"rewinding"]) { if (!statusController && [trackName length]) { NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSString *stringToShow = @""; - int lines = 1; if ([defaults boolForKey:@"showName"]) { if ([defaults boolForKey:@"showArtist"]) { @@ -725,10 +763,6 @@ isEqualToString:@"rewinding"]) { } stringToShow = [stringToShow stringByAppendingString:trackName]; stringToShow = [stringToShow stringByAppendingString:@"\n"]; - if ([trackName length] > 38) { - lines++; - } - lines++; } if ([defaults boolForKey:@"showAlbum"]) { @@ -736,7 +770,6 @@ isEqualToString:@"rewinding"]) { if ([trackAlbum length]) { stringToShow = [stringToShow stringByAppendingString:trackAlbum]; stringToShow = [stringToShow stringByAppendingString:@"\n"]; - lines++; } } @@ -744,7 +777,6 @@ isEqualToString:@"rewinding"]) { NSString *trackTime = [self runScriptAndReturnResult:@"return time of current track"]; if ([trackTime length]) { stringToShow = [NSString stringWithFormat:@"%@Total Time: %@\n", stringToShow, trackTime]; - lines++; } } @@ -761,12 +793,12 @@ isEqualToString:@"rewinding"]) { } statusController = [[StatusWindowController alloc] init]; - [statusController setTrackInfo:stringToShow lines:lines]; + [statusController setTrackInfo:stringToShow]; [NSTimer scheduledTimerWithTimeInterval:3.0 - target:self - selector:@selector(fadeAndCloseStatusWindow) - userInfo:nil - repeats:NO]; + target:self + selector:@selector(fadeAndCloseStatusWindow) + userInfo:nil + repeats:NO]; } } @@ -790,7 +822,7 @@ isEqualToString:@"rewinding"]) { songs = [songs stringByAppendingString:@"\n"]; } } - [statusController setUpcomingSongs:songs numSongs:numSongsInAdvance]; + [statusController setUpcomingSongs:songs]; [NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(fadeAndCloseStatusWindow)