Added another timeout check.
[MenuTunes.git] / MainController.m
index 2517c39..da07757 100755 (executable)
@@ -357,9 +357,22 @@ static MainController *sharedController;
 
 - (void)timerUpdate
 {
-    if ( [self songChanged] && (timerUpdating != YES) && (playerRunningState == ITMTRemotePlayerRunning) ) {
-        ITDebugLog(@"The song changed.");
-        
+       if ([[self currentRemote] playerStateUniqueIdentifier] == nil) {
+               if ([statusItem isEnabled]) {
+                       [statusItem setToolTip:@"iTunes not responding."];
+                       [self clearHotKeys];
+               }
+               [statusItem setEnabled:NO];
+               return;
+       } else if (![statusItem isEnabled]) {
+               [statusItem setEnabled:YES];
+               [statusItem setToolTip:_toolTip];
+               [self setupHotKeys];
+               return;
+       }
+       
+       if ( [self songChanged] && (timerUpdating != YES) && (playerRunningState == ITMTRemotePlayerRunning) ) {
+        ITDebugLog(@"The song changed. '%@'", _latestSongIdentifier);
         if ([df boolForKey:@"runScripts"]) {
             NSArray *scripts = [[NSFileManager defaultManager] directoryContentsAtPath:[NSHomeDirectory() stringByAppendingPathComponent:@"Library/Application Support/MenuTunes/Scripts"]];
             NSEnumerator *scriptsEnum = [scripts objectEnumerator];
@@ -393,16 +406,15 @@ static MainController *sharedController;
             if ( [df boolForKey:@"showToolTip"] ) {
                 NSString *artist = [[self currentRemote] currentSongArtist];
                 NSString *title = [[self currentRemote] currentSongTitle];
-                NSString *toolTip;
                 ITDebugLog(@"Creating status item tooltip.");
                 if (artist) {
-                    toolTip = [NSString stringWithFormat:@"%@ - %@", artist, title];
+                    _toolTip = [NSString stringWithFormat:@"%@ - %@", artist, title];
                 } else if (title) {
-                    toolTip = title;
+                    _toolTip = title;
                 } else {
-                    toolTip = @"No Song Playing";
+                    _toolTip = @"No Song Playing";
                 }
-                [statusItem setToolTip:toolTip];
+                [statusItem setToolTip:_toolTip];
             } else {
                 [statusItem setToolTip:nil];
             }
@@ -422,6 +434,21 @@ static MainController *sharedController;
 - (void)menuClicked
 {
     ITDebugLog(@"Menu clicked.");
+       
+       if ([[self currentRemote] playerStateUniqueIdentifier] == nil) {
+               if ([statusItem isEnabled]) {
+                       [statusItem setToolTip:@"iTunes not responding."];
+                       [self clearHotKeys];
+               }
+               [statusItem setEnabled:NO];
+               return;
+       } else if (![statusItem isEnabled]) {
+               [statusItem setEnabled:YES];
+               [statusItem setToolTip:_toolTip];
+               [self setupHotKeys];
+               return;
+       }
+       
     if ([networkController isConnectedToServer]) {
         //Used the cached version
         return;
@@ -557,6 +584,17 @@ static MainController *sharedController;
     [self timerUpdate];
 }
 
+- (void)makePlaylistWithTerm:(NSString *)term ofType:(int)type
+{
+    ITDebugLog(@"Making playlist with term %@, type %i", term, type);
+    NS_DURING
+        [[self currentRemote] makePlaylistWithTerm:term ofType:type];
+    NS_HANDLER
+        [self networkError:localException];
+    NS_ENDHANDLER
+    ITDebugLog(@"Done making playlist");
+}
+
 - (void)showPlayer
 {
     ITDebugLog(@"Beginning show player.");
@@ -891,7 +929,7 @@ static MainController *sharedController;
         if ( [df boolForKey:@"showTime"] ) {
             NS_DURING
                 time = [NSString stringWithFormat:@"%@: %@ / %@",
-                @"Time",
+                NSLocalizedString(@"time", @"Time"),
                 [[self currentRemote] currentSongElapsed],
                 [[self currentRemote] currentSongLength]];
             NS_HANDLER
@@ -930,7 +968,7 @@ static MainController *sharedController;
             }
         }
         
-        if ( [df boolForKey:@"showPlayCount"] ) {
+        if ( [df boolForKey:@"showPlayCount"] && ![self radioIsPlaying] && [[self currentRemote] currentSource] == ITMTRemoteLibrarySource ) {
             NS_DURING
                 playCount = [[self currentRemote] currentSongPlayCount];
             NS_HANDLER
@@ -991,8 +1029,13 @@ static MainController *sharedController;
 
 - (void)popupMenu
 {
-    NSMenu *menu = [menuController menu];
-    [(NSCarbonMenuImpl *)[menu _menuImpl] popUpMenu:menu atLocation:[NSEvent mouseLocation] width:1 forView:nil withSelectedItem:-30 withFont:[NSFont menuFontOfSize:32]];
+    if (!_popped) {
+        _popped = YES;
+        [self menuClicked];
+        NSMenu *menu = [statusItem menu];
+        [(NSCarbonMenuImpl *)[menu _menuImpl] popUpMenu:menu atLocation:[NSEvent mouseLocation] width:1 forView:nil withSelectedItem:-30 withFont:[NSFont menuFontOfSize:32]];
+        _popped = NO;
+    }
 }
 
 - (void)incrementVolume
@@ -1095,9 +1138,9 @@ static MainController *sharedController;
 
 - (void)setRating:(ITHotKey *)sender
 {
-    float rating = ([[sender name] characterAtIndex:9] - 48) / 5.0;
-    [self selectSongRating:rating];
-    [statusWindowController showRatingWindowWithRating:rating];
+    int stars = [[sender name] characterAtIndex:9] - 48;
+    [self selectSongRating:stars * 20];
+    [statusWindowController showRatingWindowWithRating:(float)stars / 5.0];
 }
 
 - (void)toggleLoop