Added ITFoundation launch at login, but it doesn'ty work. Other small fixes for netwo...
[MenuTunes.git] / MainController.m
index 906dca5..ad6f2e1 100755 (executable)
@@ -326,17 +326,14 @@ static MainController *sharedController;
 
 - (void)setLatestSongIdentifier:(NSString *)newIdentifier
 {
-    ITDebugLog(@"Setting latest song identifier to %@", newIdentifier);
+    ITDebugLog(@"Setting latest song identifier:");
+    ITDebugLog(@"   - Identifier: %@", newIdentifier);
     [_latestSongIdentifier autorelease];
-    _latestSongIdentifier = [newIdentifier copy];
+    _latestSongIdentifier = [newIdentifier retain];
 }
 
 - (void)timerUpdate
 {
-    if ([networkController isConnectedToServer]) {
-        [statusItem setMenu:[menuController menu]];
-    }
-    
     if ( [self songChanged] && (timerUpdating != YES) && (playerRunningState == ITMTRemotePlayerRunning) ) {
         ITDebugLog(@"The song changed.");
         
@@ -357,6 +354,7 @@ static MainController *sharedController;
         }
         
         timerUpdating = YES;
+        [statusItem setEnabled:NO];
         
         NS_DURING
             latestPlaylistClass = [[self currentRemote] currentPlaylistClass];
@@ -390,6 +388,11 @@ static MainController *sharedController;
         NS_ENDHANDLER
         
         timerUpdating = NO;
+        [statusItem setEnabled:YES];
+    }
+    
+    if ([networkController isConnectedToServer]) {
+        [statusItem setMenu:[menuController menu]];
     }
 }
 
@@ -766,6 +769,8 @@ static MainController *sharedController;
     NSImage                *art         = nil;
     int                     rating      = -1;
     
+    ITDebugLog(@"Showing track info status window.");
+    
     NS_DURING
         source      = [[self currentRemote] currentSource];
         title       = [[self currentRemote] currentSongTitle];
@@ -773,8 +778,6 @@ static MainController *sharedController;
         [self networkError:localException];
     NS_ENDHANDLER
     
-    ITDebugLog(@"Showing track info status window.");
-    
     if ( title ) {
 
         if ( [df boolForKey:@"showAlbum"] ) {
@@ -859,6 +862,7 @@ static MainController *sharedController;
     } else {
         title = NSLocalizedString(@"noSongPlaying", @"No song is playing.");
     }
+    ITDebugLog(@"Showing current track info status window.");
     [statusWindowController showSongInfoWindowWithSource:source
                                                    title:title
                                                    album:album
@@ -1087,6 +1091,11 @@ static MainController *sharedController;
     if (result == 1) {
         [[PreferencesController sharedPrefs] resetRemotePlayerTextFields];
         currentRemote = [[[networkController networkObject] remote] retain];
+        
+        [self setupHotKeys];
+        //playerRunningState = ITMTRemotePlayerRunning;
+        playerRunningState = [[self currentRemote] playerRunningState];
+        
         [refreshTimer invalidate];
         refreshTimer = [[NSTimer scheduledTimerWithTimeInterval:([networkController isConnectedToServer] ? 10.0 : 0.5)
                                 target:self
@@ -1115,6 +1124,12 @@ static MainController *sharedController;
     [currentRemote release];
     currentRemote = [remoteArray objectAtIndex:0];
     [networkController disconnect];
+    
+    if ([[self currentRemote] playerRunningState] == ITMTRemotePlayerRunning) {
+        [self applicationLaunched:nil];
+    } else {
+        [self applicationTerminated:nil];
+    }
     [self timerUpdate];
     return YES;
 }
@@ -1172,7 +1187,7 @@ static MainController *sharedController;
 - (void)applicationLaunched:(NSNotification *)note
 {
     NS_DURING
-        if (!note || [[[note userInfo] objectForKey:@"NSApplicationName"] isEqualToString:[[self currentRemote] playerFullName]]) {
+        if (!note || ([[[note userInfo] objectForKey:@"NSApplicationName"] isEqualToString:[[self currentRemote] playerFullName]] && ![[NetworkController sharedController] isConnectedToServer])) {
             ITDebugLog(@"Remote application launched.");
             playerRunningState = ITMTRemotePlayerRunning;
             [[self currentRemote] begin];