More changes, bug fixes.
[MenuTunes.git] / OldMainController.m
index 0d22d9a..ff98908 100755 (executable)
@@ -20,7 +20,7 @@
 
 /*************************************************************************/
 #pragma mark -
-#pragma mark INITIALIZATION METHODS
+#pragma mark INITIALIZATION/DEALLOCATION METHODS
 /*************************************************************************/
 
 - (id)init
     return self;
 }
 
+- (void)dealloc
+{
+    if (refreshTimer) {
+        [refreshTimer invalidate];
+        [refreshTimer release];
+        refreshTimer = nil;
+    }
+    [currentRemote halt];
+    [statusItem release];
+    [menu release];
+    [super dealloc];
+}
+
 - (void)applicationDidFinishLaunching:(NSNotification *)note
 {
     currentRemote = [self loadRemote];
     [currentRemote begin];
     
     //Setup for notification of the remote player launching or quitting
-    [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(applicationTerminated:) name:NSWorkspaceDidTerminateApplicationNotification object:nil];
-    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationLaunched:) name:NSWorkspaceDidLaunchApplicationNotification object:nil];
+    [[[NSWorkspace sharedWorkspace] notificationCenter]
+            addObserver:self
+            selector:@selector(applicationTerminated:)
+            name:NSWorkspaceDidTerminateApplicationNotification
+            object:nil];
+    
+    [[[NSWorkspace sharedWorkspace] notificationCenter]
+            addObserver:self
+            selector:@selector(applicationLaunched:)
+            name:NSWorkspaceDidLaunchApplicationNotification
+            object:nil];
     
     [self registerDefaults];
     
-    menu = [[NSMenu alloc] initWithTitle:@""];
+    statusItem = [[ITStatusItem alloc]
+            initWithStatusBar:[NSStatusBar systemStatusBar]
+            withLength:NSSquareStatusItemLength];
     
+    menu = [[NSMenu alloc] initWithTitle:@""];
     if ( ( [currentRemote playerRunningState] == ITMTRemotePlayerRunning ) ) {
         [self applicationLaunched:nil];
     } else {
         [self applicationTerminated:nil];
     }
     
-    statusItem = [[ITStatusItem alloc] initWithStatusBar:[NSStatusBar systemStatusBar] 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:@[NSString stringWithFormat:@"This Nontransferable Beta (Built on %s) of iThink Software's MenuTunes is Registered to: Beta Tester (betatester@somedomain.com).",__DATE__]];
 }
 
+- (void)applicationWillTerminate:(NSNotification *)note
+{
+    [self clearHotKeys];
+    [[NSStatusBar systemStatusBar] removeStatusItem:statusItem];
+}
+
 - (ITMTRemote *)loadRemote
 {
     NSString *folderPath = [[NSBundle mainBundle] builtInPlugInsPath];
         [notRunningMenu addItem:[NSMenuItem separatorItem]];
         [[notRunningMenu addItemWithTitle:@"Preferences" action:@selector(showPreferences:) keyEquivalent:@""] setTarget:self];
         [[notRunningMenu addItemWithTitle:@"Quit" action:@selector(quitMenuTunes:) keyEquivalent:@""] setTarget:self];
-        [statusItem setMenu:[menu autorelease]];
+        [statusItem setMenu:[notRunningMenu autorelease]];
         
         [refreshTimer invalidate];
         [refreshTimer release];
     }
 }
 
-- (void)startTimerInNewThread
-{
-    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-    NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
-    refreshTimer = [[NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(timerUpdate) userInfo:nil repeats:YES] retain];
-    [runLoop run];
-    [pool release];
-}
-
 /*************************************************************************/
 #pragma mark -
 #pragma mark INSTANCE METHODS
         
         for (i = 0; i < [loginarray count]; i++) {
             NSDictionary *tempDict = [loginarray objectAtIndex:i];
-            if ([[[tempDict objectForKey:@"Path"] lastPathComponent] isEqualToString:[[[NSBundle mainBundle] bundlePath] lastPathComponent]]) {
+            if ([[[tempDict objectForKey:@"Path"] lastPathComponent] isEqualToString:
+                [[[NSBundle mainBundle] bundlePath] lastPathComponent]]) {
                 found = YES;
             }
         }
     }
 }
 
+- (void)startTimerInNewThread
+{
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+    NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
+    refreshTimer = [[NSTimer scheduledTimerWithTimeInterval:0.5
+                             target:self
+                             selector:@selector(timerUpdate)
+                             userInfo:nil
+                             repeats:YES] retain];
+    [runLoop run];
+    [pool release];
+}
+
 //Recreate the status item menu
 - (void)rebuildMenu
 {
             playPauseMenuItem = [menu addItemWithTitle:@"Play"
                                     action:@selector(playPause:)
                                     keyEquivalent:@""];
-            [playPauseMenuItem setTarget:self];
             
             if (tempCombo) {
                 [self setKeyEquivalentForCode:[tempCombo keyCode]
                                         action:@selector(nextSong:)
                                         keyEquivalent:@""];
             
-            [nextTrack setTarget:self];
             if (tempCombo) {
                 [self setKeyEquivalentForCode:[tempCombo keyCode]
                     andModifiers:[tempCombo modifiers] onItem:nextTrack];
                                         action:@selector(prevSong:)
                                         keyEquivalent:@""];
             
-            [prevTrack setTarget:self];
             if (tempCombo) {
                 [self setKeyEquivalentForCode:[tempCombo keyCode]
                     andModifiers:[tempCombo modifiers] onItem:prevTrack];
                 [tempCombo release];
             }
         } else if ([item isEqualToString:@"Fast Forward"]) {
-            [[menu addItemWithTitle:@"Fast Forward"
+            [menu addItemWithTitle:@"Fast Forward"
                     action:@selector(fastForward:)
-                    keyEquivalent:@""] setTarget:self];
+                    keyEquivalent:@""];
         } else if ([item isEqualToString:@"Rewind"]) {
-            [[menu addItemWithTitle:@"Rewind"
+            [menu addItemWithTitle:@"Rewind"
                     action:@selector(rewind:)
-                    keyEquivalent:@""] setTarget:self];
+                    keyEquivalent:@""];
         } else if ([item isEqualToString:@"Upcoming Songs"]) {
             upcomingSongsItem = [menu addItemWithTitle:@"Upcoming Songs"
                     action:nil
                     action:nil
                     keyEquivalent:@""];
         } else if ([item isEqualToString:@"PreferencesÉ"]) {
-            [[menu addItemWithTitle:@"PreferencesÉ"
+            [menu addItemWithTitle:@"PreferencesÉ"
                     action:@selector(showPreferences:)
-                    keyEquivalent:@""] setTarget:self];
+                    keyEquivalent:@""];
         } else if ([item isEqualToString:@"Quit"]) {
-            [[menu addItemWithTitle:@"Quit"
+            [menu addItemWithTitle:@"Quit"
                     action:@selector(quitMenuTunes:)
-                    keyEquivalent:@""] setTarget:self];
+                    keyEquivalent:@""];
         } else if ([item isEqualToString:@"Current Track Info"]) {
             trackInfoIndex = [menu numberOfItems];
             [menu addItemWithTitle:@"No Song"
             ratingMenu = [[NSMenu alloc] initWithTitle:@""];
             
             item = [ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", emptyStarChar, emptyStarChar, emptyStarChar, emptyStarChar, emptyStarChar] action:@selector(selectSongRating:) keyEquivalent:@""];
-            [item setTarget:self];
             [item setTag:0];
             
             item = [ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", fullStarChar, emptyStarChar, emptyStarChar, emptyStarChar, emptyStarChar] action:@selector(selectSongRating:) keyEquivalent:@""];
-            [item setTarget:self];
             [item setTag:20];
             
             item = [ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", fullStarChar, fullStarChar, emptyStarChar, emptyStarChar, emptyStarChar] action:@selector(selectSongRating:) keyEquivalent:@""];
-            [item setTarget:self];
             [item setTag:40];
             
             item = [ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", fullStarChar, fullStarChar, fullStarChar, emptyStarChar, emptyStarChar] action:@selector(selectSongRating:) keyEquivalent:@""];
-            [item setTarget:self];
             [item setTag:60];
             
             item = [ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", fullStarChar, fullStarChar, fullStarChar, fullStarChar, emptyStarChar] action:@selector(selectSongRating:) keyEquivalent:@""];
-            [item setTarget:self];
             [item setTag:80];
             
             item = [ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", fullStarChar, fullStarChar, fullStarChar, fullStarChar, fullStarChar] action:@selector(selectSongRating:) keyEquivalent:@""];
-            [item setTarget:self];
             [item setTag:100];
         } else if ([item isEqualToString:@"<separator>"]) {
             [menu addItem:[NSMenuItem separatorItem]];
         }
     }
     
-    [self timerUpdate]; //Updates dynamic info in the menu
+    [self updateMenu];
+    //[self timerUpdate]; //Updates dynamic info in the menu
     
     [self clearHotKeys];
     [self setupHotKeys];
 }
 
-//Updates the menu with current player state, song, and upcoming songs
-- (void)updateMenu
-{
-    NSMenuItem *menuItem;
-    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
-    
-    if ( ( isAppRunning == ITMTRemotePlayerNotRunning ) ) {
-        return;
-    }
-    
-    if (upcomingSongsItem) {
-        [self rebuildUpcomingSongsMenu];
-    }
-    
-    if (playlistItem) {
-        [self rebuildPlaylistMenu];
-    }
-    
-    if (eqItem) {
-        [self rebuildEQPresetsMenu];
-    }
-    if (trackInfoIndex > -1) {
-        NSString *curSongName, *curAlbumName = @"", *curArtistName = @"";
-        curSongName = [currentRemote currentSongTitle];
-        
-        if ([defaults boolForKey:@"showAlbum"]) {
-            curAlbumName = [currentRemote currentSongAlbum];
-        }
-        
-        if ([defaults boolForKey:@"showArtist"]) {
-            curArtistName = [currentRemote currentSongArtist];
-        }
-        
-        if ([curSongName length] > 0) {
-            int index = [menu indexOfItemWithTitle:@"Now Playing"];
-            if (index > -1) {
-                if ([defaults boolForKey:@"showName"]) {
-                    [menu removeItemAtIndex:index + 1];
-                }
-                if (didHaveAlbumName && [defaults boolForKey:@"showAlbum"]) {
-                    [menu removeItemAtIndex:index + 1];
-                }
-                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:@"  %@", [currentRemote currentSongLength]]
-                            action:nil
-                            keyEquivalent:@""];
-                    [menu insertItem:menuItem atIndex:trackInfoIndex + 1];
-                    [menuItem release];
-                }
-                
-                if ([curArtistName length] > 0) {
-                    menuItem = [[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@"  %@", curArtistName]
-                            action:nil
-                            keyEquivalent:@""];
-                    [menu insertItem:menuItem atIndex:trackInfoIndex + 1];
-                    [menuItem release];
-                }
-                
-                if ([curAlbumName length] > 0) {
-                    menuItem = [[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@"  %@", curAlbumName]
-                            action:nil
-                            keyEquivalent:@""];
-                    [menu insertItem:menuItem atIndex:trackInfoIndex + 1];
-                    [menuItem release];
-                }
-                
-                if (songRatingMenuItem) {
-                    int rating = (int)[currentRemote currentSongRating] * 10;
-                    int i;
-                    for (i = 0; i < 5; i++) {
-                        [[ratingMenu itemAtIndex:i] setState:NSOffState];
-                        [[ratingMenu itemAtIndex:i] setTarget:self];
-                    }
-                    [[ratingMenu itemAtIndex:rating / 2] setState:NSOnState];
-                }
-            }
-            
-            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:@""];
-                [menu removeItemAtIndex:[menu indexOfItemWithTitle:@"No Song"]];
-                [menu insertItem:menuItem atIndex:trackInfoIndex];
-                [menuItem release];
-                
-                [songRatingMenuItem setSubmenu:ratingMenu];
-                [songRatingMenuItem setEnabled:YES];
-            }
-        } else if ([menu indexOfItemWithTitle:@"No Song"] == -1) {
-            [menu removeItemAtIndex:trackInfoIndex];
-            
-            if ([defaults boolForKey:@"showName"] == YES) {
-                [menu removeItemAtIndex:trackInfoIndex];
-            }
-            
-            if ([defaults boolForKey:@"showTime"] == YES) {
-                [menu removeItemAtIndex:trackInfoIndex];
-            }
-            
-            if (didHaveArtistName && [defaults boolForKey:@"showArtist"]) {
-                [menu removeItemAtIndex:trackInfoIndex];
-            }
-            
-            if (didHaveAlbumName && [defaults boolForKey:@"showAlbum"]) {
-                [menu removeItemAtIndex:trackInfoIndex];
-            }
-            
-            menuItem = [[NSMenuItem alloc] initWithTitle:@"No Song" action:nil keyEquivalent:@""];
-            [menu insertItem:menuItem atIndex:trackInfoIndex];
-            [menuItem release];
-        }
-        
-        if ([defaults boolForKey:@"showArtist"]) {
-            didHaveArtistName = (([curArtistName length] > 0) ? YES : NO);
-        }
-            
-        if ([defaults boolForKey:@"showAlbum"]) {
-            didHaveAlbumName = (([curAlbumName length] > 0) ? YES : NO);
-        }
-    }
-    [menu update];
-}
-
 //Rebuild the upcoming songs submenu. Can be improved a lot.
 - (void)rebuildUpcomingSongsMenu
 {
                 if (i <= numSongs) {
                     NSString *curSong = [currentRemote songTitleAtIndex:i];
                     NSMenuItem *songItem;
-                    songItem = [[NSMenuItem alloc] initWithTitle:curSong action:@selector(playTrack:) keyEquivalent:@""];
-                    [songItem setTarget:self];
+                    songItem = [[NSMenuItem alloc] initWithTitle:curSong action:@selector(selectSong:) keyEquivalent:@""];
                     [songItem setRepresentedObject:[NSNumber numberWithInt:i]];
                     [upcomingSongsMenu addItem:songItem];
                     [songItem release];
         NSString *playlistName = [playlists objectAtIndex:i];
         NSMenuItem *tempItem;
         tempItem = [[NSMenuItem alloc] initWithTitle:playlistName action:@selector(selectPlaylist:) keyEquivalent:@""];
-        [tempItem setTarget:self];
         [tempItem setRepresentedObject:[NSNumber numberWithInt:i + 1]];
         [playlistMenu addItem:tempItem];
         [tempItem release];
     [eqMenu release];
     eqMenu = [[NSMenu alloc] initWithTitle:@""];
     
-    enabledItem = [eqMenu addItemWithTitle:@"Disabled"
-                          action:@selector(toggleEqualizer)
+    enabledItem = [eqMenu addItemWithTitle:@"Enabled"
+                          action:@selector(selectEQPreset:)
                           keyEquivalent:@""];
+    [enabledItem setTag:-1];
     
-    if ([currentRemote equalizerEnabled] == NO) {
+    if ([currentRemote equalizerEnabled]) {
         [enabledItem setState:NSOnState];
     }
     
         NSMenuItem *tempItem;
        if (setName) {
         tempItem = [[NSMenuItem alloc] initWithTitle:setName action:@selector(selectEQPreset:) keyEquivalent:@""];
-        [tempItem setTarget:self];
-        [tempItem setRepresentedObject:[NSNumber numberWithInt:i]];
+        [tempItem setTag:i];
         [eqMenu addItem:tempItem];
         [tempItem release];
        }
     [[eqMenu itemAtIndex:[currentRemote currentEQPresetIndex] + 1] setState:NSOnState];
 }
 
-- (void)clearHotKeys
-{
-    [[HotKeyCenter sharedCenter] removeHotKey:@"PlayPause"];
-    [[HotKeyCenter sharedCenter] removeHotKey:@"NextTrack"];
-    [[HotKeyCenter sharedCenter] removeHotKey:@"PrevTrack"];
-    [[HotKeyCenter sharedCenter] removeHotKey:@"TrackInfo"];
-    [[HotKeyCenter sharedCenter] removeHotKey:@"UpcomingSongs"];
-}
-
-- (void)setupHotKeys
-{
-    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
-    
-    if ([defaults objectForKey:@"PlayPause"] != nil) {
-        [[HotKeyCenter sharedCenter] addHotKey:@"PlayPause"
-                combo:[defaults keyComboForKey:@"PlayPause"]
-                target:self action:@selector(playPause:)];
-    }
-    
-    if ([defaults objectForKey:@"NextTrack"] != nil) {
-        [[HotKeyCenter sharedCenter] addHotKey:@"NextTrack"
-                combo:[defaults keyComboForKey:@"NextTrack"]
-                target:self action:@selector(nextSong:)];
-    }
-    
-    if ([defaults objectForKey:@"PrevTrack"] != nil) {
-        [[HotKeyCenter sharedCenter] addHotKey:@"PrevTrack"
-                combo:[defaults keyComboForKey:@"PrevTrack"]
-                target:self action:@selector(prevSong:)];
-    }
-    
-    if ([defaults objectForKey:@"TrackInfo"] != nil) {
-        [[HotKeyCenter sharedCenter] addHotKey:@"TrackInfo"
-                combo:[defaults keyComboForKey:@"TrackInfo"]
-                target:self action:@selector(showCurrentTrackInfo)];
-    }
-    
-    if ([defaults objectForKey:@"UpcomingSongs"] != nil) {
-        [[HotKeyCenter sharedCenter] addHotKey:@"UpcomingSongs"
-               combo:[defaults keyComboForKey:@"UpcomingSongs"]
-               target:self action:@selector(showUpcomingSongs)];
-    }
-}
-
 //Called when the timer fires.
 - (void)timerUpdate
 {
     int playlist = [currentRemote currentPlaylistIndex];
-    ITMTRemotePlayerPlayingState playerPlayingState = [currentRemote playerPlayingState];
+    ITMTRemotePlayerPlayingState playerState = [currentRemote playerPlayingState];
     
-    if ((playlist > 0) || playerPlayingState != ITMTRemotePlayerStopped) {
+    if ((playlist > 0) || playerState != ITMTRemotePlayerStopped) {
         int trackPlayingIndex = [currentRemote currentSongIndex];
         
         if (trackPlayingIndex != lastSongIndex) {
                 [menu insertItem:temp atIndex:trackInfoIndex + 1];
                 [temp release];
             }
-            
             [self updateMenu];
             lastSongIndex = trackPlayingIndex;
         } else {
         }
         //Update Play/Pause menu item
         if (playPauseMenuItem){
-            if (playerPlayingState == ITMTRemotePlayerPlaying) {
+            if (playerState == ITMTRemotePlayerPlaying) {
                 [playPauseMenuItem setTitle:@"Pause"];
             } else {
                 [playPauseMenuItem setTitle:@"Play"];
         NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
         //Remote the now playing item and add no song item
         [menu removeItemAtIndex:trackInfoIndex];
-        
         if ([defaults boolForKey:@"showName"] == YES) {
             [menu removeItemAtIndex:trackInfoIndex];
         }
     }
 }
 
+//Updates the menu with current player state, song, and upcoming songs
+- (void)updateMenu
+{
+    NSMenuItem *menuItem;
+    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
+    
+    if ( ( isAppRunning == ITMTRemotePlayerNotRunning ) ) {
+        return;
+    }
+    
+    if (upcomingSongsItem) {
+        [self rebuildUpcomingSongsMenu];
+    }
+    
+    if (playlistItem) {
+        [self rebuildPlaylistMenu];
+    }
+    
+    if (eqItem) {
+        [self rebuildEQPresetsMenu];
+    }
+    if (trackInfoIndex > -1) {
+        NSString *curSongName, *curAlbumName = @"", *curArtistName = @"";
+        curSongName = [currentRemote currentSongTitle];
+        
+        if ([defaults boolForKey:@"showAlbum"]) {
+            curAlbumName = [currentRemote currentSongAlbum];
+        }
+        
+        if ([defaults boolForKey:@"showArtist"]) {
+            curArtistName = [currentRemote currentSongArtist];
+        }
+        
+        if ([curSongName length] > 0) {
+            int index = [menu indexOfItemWithTitle:@"Now Playing"];
+            if (index > -1) {
+                if ([defaults boolForKey:@"showName"]) {
+                    [menu removeItemAtIndex:index + 1];
+                }
+                if (didHaveAlbumName && [defaults boolForKey:@"showAlbum"]) {
+                    [menu removeItemAtIndex:index + 1];
+                }
+                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:@"  %@", [currentRemote currentSongLength]]
+                            action:nil
+                            keyEquivalent:@""];
+                    [menu insertItem:menuItem atIndex:trackInfoIndex + 1];
+                    [menuItem release];
+                }
+                
+                if ([curArtistName length] > 0) {
+                    menuItem = [[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@"  %@", curArtistName]
+                            action:nil
+                            keyEquivalent:@""];
+                    [menu insertItem:menuItem atIndex:trackInfoIndex + 1];
+                    [menuItem release];
+                }
+                
+                if ([curAlbumName length] > 0) {
+                    menuItem = [[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@"  %@", curAlbumName]
+                            action:nil
+                            keyEquivalent:@""];
+                    [menu insertItem:menuItem atIndex:trackInfoIndex + 1];
+                    [menuItem release];
+                }
+                
+                if (songRatingMenuItem) {
+                    int rating = (int)[currentRemote currentSongRating] * 10;
+                    int i;
+                    for (i = 0; i < 5; i++) {
+                        [[ratingMenu itemAtIndex:i] setState:NSOffState];
+                        [[ratingMenu itemAtIndex:i] setTarget:self];
+                    }
+                    [[ratingMenu itemAtIndex:rating / 2] setState:NSOnState];
+                }
+            }
+            
+            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:@""];
+                [menu removeItemAtIndex:[menu indexOfItemWithTitle:@"No Song"]];
+                [menu insertItem:menuItem atIndex:trackInfoIndex];
+                [menuItem release];
+                
+                [songRatingMenuItem setSubmenu:ratingMenu];
+                [songRatingMenuItem setEnabled:YES];
+            }
+        } else if ([menu indexOfItemWithTitle:@"No Song"] == -1) {
+            [menu removeItemAtIndex:trackInfoIndex];
+            
+            if ([defaults boolForKey:@"showName"] == YES) {
+                [menu removeItemAtIndex:trackInfoIndex];
+            }
+            
+            if ([defaults boolForKey:@"showTime"] == YES) {
+                [menu removeItemAtIndex:trackInfoIndex];
+            }
+            
+            if (didHaveArtistName && [defaults boolForKey:@"showArtist"]) {
+                [menu removeItemAtIndex:trackInfoIndex];
+            }
+            
+            if (didHaveAlbumName && [defaults boolForKey:@"showAlbum"]) {
+                [menu removeItemAtIndex:trackInfoIndex];
+            }
+            
+            menuItem = [[NSMenuItem alloc] initWithTitle:@"No Song" action:nil keyEquivalent:@""];
+            [menu insertItem:menuItem atIndex:trackInfoIndex];
+            [menuItem release];
+        }
+        
+        if ([defaults boolForKey:@"showArtist"]) {
+            didHaveArtistName = (([curArtistName length] > 0) ? YES : NO);
+        }
+            
+        if ([defaults boolForKey:@"showAlbum"]) {
+            didHaveAlbumName = (([curAlbumName length] > 0) ? YES : NO);
+        }
+    }
+    [menu update];
+}
+
 //
 //
-// Selectors - called from status item menu
+// Menu Selectors
 //
 //
 
-// Plugin dependent selectors
-
-- (void)playTrack:(id)sender
+- (void)selectSong:(id)sender
 {
     [currentRemote switchToSongAtIndex:[[sender representedObject] intValue]];
 }
 - (void)selectEQPreset:(id)sender
 {
     int curSet = [currentRemote currentEQPresetIndex];
-    int item = [[sender representedObject] intValue];
-    [currentRemote switchToEQAtIndex:item];
-    [[eqMenu itemAtIndex:curSet + 1] setState:NSOffState];
-    [[eqMenu itemAtIndex:item + 2] setState:NSOnState];
+    int item = [sender tag];
+    
+    if (item == -1) {
+        [currentRemote setEqualizerEnabled:![currentRemote equalizerEnabled]];
+    } else {
+        [currentRemote setEqualizerEnabled:YES];
+        [currentRemote switchToEQAtIndex:item];
+        [[eqMenu itemAtIndex:curSet + 1] setState:NSOffState];
+        [[eqMenu itemAtIndex:item + 2] setState:NSOnState];
+    }
+}
+
+- (void)selectSongRating:(id)sender
+{
+    [[ratingMenu itemAtIndex:([currentRemote currentSongRating] / 20)] setState:NSOffState];
+    [currentRemote setCurrentSongRating:(float)[sender tag] / 100.0];
+    [sender setState:NSOnState];
 }
 
 - (void)playPause:(id)sender
     [playPauseMenuItem setTitle:@"Play"];
 }
 
-- (void)toggleEqualizer
-{
-    [currentRemote setEqualizerEnabled:![currentRemote equalizerEnabled]];
-}
-
-- (void)selectSongRating:(id)sender
-{
-    [[ratingMenu itemAtIndex:([currentRemote currentSongRating] / 20)] setState:NSOffState];
-    [currentRemote setCurrentSongRating:(float)[sender tag] / 100.0];
-    [sender setState:NSOnState];
-}
-
-//
-//
-// Plugin independent selectors
 //
 //
 - (void)quitMenuTunes:(id)sender
     [NSApp terminate:self];
 }
 
+- (void)showPlayer:(id)sender
+{
+    if ( ( isAppRunning == ITMTRemotePlayerRunning) ) {
+        [currentRemote showPrimaryInterface];
+    } else {
+        if (![[NSWorkspace sharedWorkspace] launchApplication:[currentRemote playerFullName]]) {
+            NSLog(@"Error Launching Player");
+        }
+    }
+}
+
 - (void)showPreferences:(id)sender
 {
     if (!prefsController) {
     prefsController = nil;
 }
 
-- (void)showPlayer:(id)sender
+
+//
+//
+// Hot key setup
+//
+//
+
+- (void)clearHotKeys
 {
-    if ( ( isAppRunning == ITMTRemotePlayerRunning) ) {
-        [currentRemote showPrimaryInterface];
-    } else {
-        if (![[NSWorkspace sharedWorkspace] launchApplication:[currentRemote playerFullName]]) {
-            NSLog(@"Error Launching Player");
-        }
+    [[HotKeyCenter sharedCenter] removeHotKey:@"PlayPause"];
+    [[HotKeyCenter sharedCenter] removeHotKey:@"NextTrack"];
+    [[HotKeyCenter sharedCenter] removeHotKey:@"PrevTrack"];
+    [[HotKeyCenter sharedCenter] removeHotKey:@"TrackInfo"];
+    [[HotKeyCenter sharedCenter] removeHotKey:@"UpcomingSongs"];
+}
+
+- (void)setupHotKeys
+{
+    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
+    
+    if ([defaults objectForKey:@"PlayPause"] != nil) {
+        [[HotKeyCenter sharedCenter] addHotKey:@"PlayPause"
+                combo:[defaults keyComboForKey:@"PlayPause"]
+                target:self action:@selector(playPause:)];
+    }
+    
+    if ([defaults objectForKey:@"NextTrack"] != nil) {
+        [[HotKeyCenter sharedCenter] addHotKey:@"NextTrack"
+                combo:[defaults keyComboForKey:@"NextTrack"]
+                target:self action:@selector(nextSong:)];
+    }
+    
+    if ([defaults objectForKey:@"PrevTrack"] != nil) {
+        [[HotKeyCenter sharedCenter] addHotKey:@"PrevTrack"
+                combo:[defaults keyComboForKey:@"PrevTrack"]
+                target:self action:@selector(prevSong:)];
+    }
+    
+    if ([defaults objectForKey:@"TrackInfo"] != nil) {
+        [[HotKeyCenter sharedCenter] addHotKey:@"TrackInfo"
+                combo:[defaults keyComboForKey:@"TrackInfo"]
+                target:self action:@selector(showCurrentTrackInfo)];
+    }
+    
+    if ([defaults objectForKey:@"UpcomingSongs"] != nil) {
+        [[HotKeyCenter sharedCenter] addHotKey:@"UpcomingSongs"
+               combo:[defaults keyComboForKey:@"UpcomingSongs"]
+               target:self action:@selector(showUpcomingSongs)];
     }
 }
-        
 
 //
 //
     }
 }
 
-/*************************************************************************/
-#pragma mark -
-#pragma mark NSApplication DELEGATE METHODS
-/*************************************************************************/
-
-- (void)applicationWillTerminate:(NSNotification *)note
-{
-    [self clearHotKeys];
-    [[NSStatusBar systemStatusBar] removeStatusItem:statusItem];
-}
-
-
-/*************************************************************************/
-#pragma mark -
-#pragma mark DEALLOCATION METHODS
-/*************************************************************************/
-
-- (void)dealloc
-{
-    if (refreshTimer) {
-        [refreshTimer invalidate];
-        [refreshTimer release];
-        refreshTimer = nil;
-    }
-    [currentRemote halt];
-    [statusItem release];
-    [menu release];
-//  [view release];
-    [super dealloc];
-}
-
 @end