Lots of code to keep MT from being bad when iTunes locks. Fixed leak in
authorKent Sutherland <ksuther@ithinksw.com>
Wed, 6 Oct 2004 22:48:05 +0000 (22:48 +0000)
committerKent Sutherland <ksuther@ithinksw.com>
Wed, 6 Oct 2004 22:48:05 +0000 (22:48 +0000)
NSFont.

MTShizzleWindow.m
MainController.m
MenuController.h
MenuController.m
MenuTunes.xcode/project.pbxproj
StatusWindow.m
iTunesRemote.m

index a0903a5..674d338 100755 (executable)
@@ -109,7 +109,7 @@ static MTShizzleWindow *_privateSharedWindow = nil;
     [regBenefits setEditable:NO];
     [regBenefits setSelectable:NO];
     [regBenefits setDrawsBackground:NO];
     [regBenefits setEditable:NO];
     [regBenefits setSelectable:NO];
     [regBenefits setDrawsBackground:NO];
-    [regBenefits setFont:[NSFont fontWithName:@"Lucida Grande" size:11]];
+    [regBenefits setFont:[NSFont fontWithName:@"LucidaGrande" size:11]];
     [[box contentView] addSubview:regBenefits];
     
     enterInfo = [[NSTextField alloc] initWithFrame:NSMakeRect(20, 148, 345, 17)];
     [[box contentView] addSubview:regBenefits];
     
     enterInfo = [[NSTextField alloc] initWithFrame:NSMakeRect(20, 148, 345, 17)];
index 4eb7891..0c19559 100755 (executable)
@@ -364,14 +364,14 @@ static MainController *sharedController;
        if ([[self currentRemote] playerStateUniqueIdentifier] == nil) {
                if ([statusItem isEnabled]) {
                        [statusItem setToolTip:@"iTunes not responding."];
        if ([[self currentRemote] playerStateUniqueIdentifier] == nil) {
                if ([statusItem isEnabled]) {
                        [statusItem setToolTip:@"iTunes not responding."];
-                       [self clearHotKeys];
+                       [[ITHotKeyCenter sharedCenter] setEnabled:NO];
                }
                [statusItem setEnabled:NO];
                return;
        } else if (![statusItem isEnabled]) {
                [statusItem setEnabled:YES];
                [statusItem setToolTip:_toolTip];
                }
                [statusItem setEnabled:NO];
                return;
        } else if (![statusItem isEnabled]) {
                [statusItem setEnabled:YES];
                [statusItem setToolTip:_toolTip];
-               [self setupHotKeys];
+               [[ITHotKeyCenter sharedCenter] setEnabled:YES];
                return;
        }
        
                return;
        }
        
@@ -395,41 +395,40 @@ static MainController *sharedController;
         
         timerUpdating = YES;
         [statusItem setEnabled:NO];
         
         timerUpdating = YES;
         [statusItem setEnabled:NO];
-        
+               
         NS_DURING
             latestPlaylistClass = [[self currentRemote] currentPlaylistClass];
         NS_DURING
             latestPlaylistClass = [[self currentRemote] currentPlaylistClass];
-            [menuController rebuildSubmenus];
-    
-            if ( [df boolForKey:@"showSongInfoOnChange"] ) {
-                [self performSelector:@selector(showCurrentTrackInfo) withObject:nil afterDelay:0.0];
-            }
-            
-            [self setLatestSongIdentifier:[[self currentRemote] playerStateUniqueIdentifier]];
-            
-            //Create the tooltip for the status item
-            if ( [df boolForKey:@"showToolTip"] ) {
-                NSString *artist = [[self currentRemote] currentSongArtist];
-                NSString *title = [[self currentRemote] currentSongTitle];
-                ITDebugLog(@"Creating status item tooltip.");
-                if (artist) {
-                    _toolTip = [NSString stringWithFormat:@"%@ - %@", artist, title];
-                } else if (title) {
-                    _toolTip = title;
-                } else {
-                    _toolTip = @"No Song Playing";
-                }
-                [statusItem setToolTip:_toolTip];
-            } else {
-                [statusItem setToolTip:nil];
-            }
+                       
+                       if ([menuController rebuildSubmenus]) {
+                               if ( [df boolForKey:@"showSongInfoOnChange"] ) {
+                                       [self performSelector:@selector(showCurrentTrackInfo) withObject:nil afterDelay:0.0];
+                               }
+                               
+                               [self setLatestSongIdentifier:[[self currentRemote] playerStateUniqueIdentifier]];
+                               //Create the tooltip for the status item
+                               if ( [df boolForKey:@"showToolTip"] ) {
+                                       NSString *artist = [[self currentRemote] currentSongArtist];
+                                       NSString *title = [[self currentRemote] currentSongTitle];
+                                       ITDebugLog(@"Creating status item tooltip.");
+                                       if (artist) {
+                                               _toolTip = [NSString stringWithFormat:@"%@ - %@", artist, title];
+                                       } else if (title) {
+                                               _toolTip = title;
+                                       } else {
+                                               _toolTip = @"No Song Playing";
+                                       }
+                                       [statusItem setToolTip:_toolTip];
+                               } else {
+                                       [statusItem setToolTip:nil];
+                               }
+                       }
         NS_HANDLER
             [self networkError:localException];
         NS_ENDHANDLER
         NS_HANDLER
             [self networkError:localException];
         NS_ENDHANDLER
-        
         timerUpdating = NO;
         [statusItem setEnabled:YES];
     }
         timerUpdating = NO;
         [statusItem setEnabled:YES];
     }
-    
+       
     if ([networkController isConnectedToServer]) {
         [statusItem setMenu:([[self currentRemote] playerRunningState] == ITMTRemotePlayerRunning) ? [menuController menu] : [menuController menuForNoPlayer]];
     }
     if ([networkController isConnectedToServer]) {
         [statusItem setMenu:([[self currentRemote] playerRunningState] == ITMTRemotePlayerRunning) ? [menuController menu] : [menuController menuForNoPlayer]];
     }
@@ -442,14 +441,14 @@ static MainController *sharedController;
        if ( ([[self currentRemote] playerStateUniqueIdentifier] == nil) && playerRunningState == ITMTRemotePlayerRunning ) {
                if ([statusItem isEnabled]) {
                        [statusItem setToolTip:@"iTunes not responding."];
        if ( ([[self currentRemote] playerStateUniqueIdentifier] == nil) && playerRunningState == ITMTRemotePlayerRunning ) {
                if ([statusItem isEnabled]) {
                        [statusItem setToolTip:@"iTunes not responding."];
-                       [self clearHotKeys];
+                       [[ITHotKeyCenter sharedCenter] setEnabled:NO];
                }
                [statusItem setEnabled:NO];
                return;
        } else if (![statusItem isEnabled]) {
                [statusItem setEnabled:YES];
                [statusItem setToolTip:_toolTip];
                }
                [statusItem setEnabled:NO];
                return;
        } else if (![statusItem isEnabled]) {
                [statusItem setEnabled:YES];
                [statusItem setToolTip:_toolTip];
-               [self setupHotKeys];
+               [[ITHotKeyCenter sharedCenter] setEnabled:YES];
                return;
        }
        
                return;
        }
        
@@ -1234,7 +1233,7 @@ static MainController *sharedController;
         [self setupHotKeys];
         //playerRunningState = ITMTRemotePlayerRunning;
         playerRunningState = [[self currentRemote] playerRunningState];
         [self setupHotKeys];
         //playerRunningState = ITMTRemotePlayerRunning;
         playerRunningState = [[self currentRemote] playerRunningState];
-        
+               
         [refreshTimer invalidate];
         refreshTimer = [[NSTimer scheduledTimerWithTimeInterval:([networkController isConnectedToServer] ? 10.0 : 0.5)
                                 target:self
         [refreshTimer invalidate];
         refreshTimer = [[NSTimer scheduledTimerWithTimeInterval:([networkController isConnectedToServer] ? 10.0 : 0.5)
                                 target:self
index fda5e5e..91a462a 100755 (executable)
@@ -45,12 +45,12 @@ typedef enum {
     NSMenu *_ratingMenu, *_upcomingSongsMenu, *_eqMenu, *_playlistsMenu, *_artistsMenu, *_albumsMenu; //Submenus
     
     int _currentPlaylist, _currentTrack;
     NSMenu *_ratingMenu, *_upcomingSongsMenu, *_eqMenu, *_playlistsMenu, *_artistsMenu, *_albumsMenu; //Submenus
     
     int _currentPlaylist, _currentTrack;
-    BOOL _playingRadio;
+    BOOL _playingRadio, _continue;
 }
 
 - (NSMenu *)menu;
 - (NSMenu *)menuForNoPlayer;
 }
 
 - (NSMenu *)menu;
 - (NSMenu *)menuForNoPlayer;
-- (void)rebuildSubmenus;
+- (BOOL)rebuildSubmenus;
 
 // - (NSArray *)menuLayout;
 // - (void)setMenuLayout:(NSArray *)newLayoutArray;
 
 // - (NSArray *)menuLayout;
 // - (void)setMenuLayout:(NSArray *)newLayoutArray;
index 424957f..b5d2c21 100755 (executable)
     return [menu autorelease];
 }
 
     return [menu autorelease];
 }
 
-- (void)rebuildSubmenus
+- (BOOL)rebuildSubmenus
 {
     NSArray *menu = [[NSUserDefaults standardUserDefaults] arrayForKey:@"menu"];
     ITDebugLog(@"Rebuilding all of the submenus.");
 {
     NSArray *menu = [[NSUserDefaults standardUserDefaults] arrayForKey:@"menu"];
     ITDebugLog(@"Rebuilding all of the submenus.");
         [[MainController sharedController] networkError:localException];
     NS_ENDHANDLER
     ITDebugLog(@"Releasing old submenus.");
         [[MainController sharedController] networkError:localException];
     NS_ENDHANDLER
     ITDebugLog(@"Releasing old submenus.");
+       _continue = YES;
     ITDebugLog(@" - Rating menu");
     [_ratingMenu release];
     ITDebugLog(@" - Rating menu");
     [_ratingMenu release];
+       _ratingMenu = nil;
     ITDebugLog(@" - Upcoming songs menu");
     [_upcomingSongsMenu release];
     ITDebugLog(@" - Upcoming songs menu");
     [_upcomingSongsMenu release];
+       _upcomingSongsMenu = nil;
     ITDebugLog(@" - Playlists menu");
     [_playlistsMenu release];
     ITDebugLog(@" - Playlists menu");
     [_playlistsMenu release];
+       _playlistsMenu = nil;
     ITDebugLog(@" - EQ menu");
     [_eqMenu release];
     ITDebugLog(@" - EQ menu");
     [_eqMenu release];
+       _eqMenu = nil;
     
     ITDebugLog(@"Beginning Rebuild of \"Song Rating\" submenu.");
     _ratingMenu = [self ratingMenu];
     ITDebugLog(@"Beginning Rebuild of \"Upcoming Songs\" submenu.");
     _upcomingSongsMenu = [self upcomingSongsMenu];
     
     ITDebugLog(@"Beginning Rebuild of \"Song Rating\" submenu.");
     _ratingMenu = [self ratingMenu];
     ITDebugLog(@"Beginning Rebuild of \"Upcoming Songs\" submenu.");
     _upcomingSongsMenu = [self upcomingSongsMenu];
-    ITDebugLog(@"Beginning Rebuild of \"Playlists\" submenu.");
-    _playlistsMenu = [self playlistsMenu];
-    ITDebugLog(@"Beginning Rebuild of \"EQ Presets\" submenu.");
-    _eqMenu = [self eqMenu];
+       if (_continue) {
+               ITDebugLog(@"Beginning Rebuild of \"Playlists\" submenu.");
+               _playlistsMenu = [self playlistsMenu];
+       }
+       if (_continue) {
+               ITDebugLog(@"Beginning Rebuild of \"EQ Presets\" submenu.");
+               _eqMenu = [self eqMenu];
+       }
     
     
-    if ([menu containsObject:@"artists"]) {
+    if (_continue && [menu containsObject:@"artists"]) {
         ITDebugLog(@"Releasing artists menu");
         [_artistsMenu release];
         ITDebugLog(@"Beginning Rebuild of \"Artists\" submenu.");
         _artistsMenu = [self artistsMenu];
     }
     
         ITDebugLog(@"Releasing artists menu");
         [_artistsMenu release];
         ITDebugLog(@"Beginning Rebuild of \"Artists\" submenu.");
         _artistsMenu = [self artistsMenu];
     }
     
-    if ([menu containsObject:@"albums"]) {
+    if (_continue && [menu containsObject:@"albums"]) {
         ITDebugLog(@"Releasing albums menu");
         [_albumsMenu release];
         ITDebugLog(@"Beginning Rebuild of \"Albums\" submenu.");
         _albumsMenu = [self albumsMenu];
     }
     ITDebugLog(@"Done rebuilding all of the submenus.");
         ITDebugLog(@"Releasing albums menu");
         [_albumsMenu release];
         ITDebugLog(@"Beginning Rebuild of \"Albums\" submenu.");
         _albumsMenu = [self albumsMenu];
     }
     ITDebugLog(@"Done rebuilding all of the submenus.");
+       return _continue;
 }
 
 - (NSMenu *)ratingMenu
 }
 
 - (NSMenu *)ratingMenu
         [[MainController sharedController] networkError:localException];
     NS_ENDHANDLER
     
         [[MainController sharedController] networkError:localException];
     NS_ENDHANDLER
     
+       if (numSongs == -1) {
+               [upcomingSongsMenu release];
+               return nil;
+       }
+       NS_DURING
     ITDebugLog(@"Building \"Upcoming Songs\" menu.");
     if (_currentPlaylist && !_playingRadio) {
         if (numSongs > 0) {
     ITDebugLog(@"Building \"Upcoming Songs\" menu.");
     if (_currentPlaylist && !_playingRadio) {
         if (numSongs > 0) {
         }
     }
     ITDebugLog(@"Done Building \"Upcoming Songs\" menu.");
         }
     }
     ITDebugLog(@"Done Building \"Upcoming Songs\" menu.");
-    return upcomingSongsMenu;
+       NS_VALUERETURN(upcomingSongsMenu, NSMenu *);
+       NS_HANDLER
+               [upcomingSongsMenu release];
+               _continue = NO;
+               NS_VALUERETURN(nil, NSMenu *);
+       NS_ENDHANDLER
 }
 
 /*- (NSMenu *)playlistsMenu
 }
 
 /*- (NSMenu *)playlistsMenu
     NS_HANDLER
         [[MainController sharedController] networkError:localException];
     NS_ENDHANDLER
     NS_HANDLER
         [[MainController sharedController] networkError:localException];
     NS_ENDHANDLER
+       
+       if (!playlists) {
+               [playlistsMenu release];
+               return nil;
+       }
+       
+       NS_DURING
     ITDebugLog(@"Building \"Playlists\" menu.");
     {
         NSArray *curPlaylist = [playlists objectAtIndex:0];
     ITDebugLog(@"Building \"Playlists\" menu.");
     {
         NSArray *curPlaylist = [playlists objectAtIndex:0];
         }
     }
     ITDebugLog(@"Checking the current source.");
         }
     }
     ITDebugLog(@"Checking the current source.");
+       NS_DURING
     if ( (source == ITMTRemoteSharedLibrarySource) || (source == ITMTRemoteiPodSource) || (source == ITMTRemoteGenericDeviceSource) || (source == ITMTRemoteCDSource) ) {
         tempItem = [playlistsMenu itemAtIndex:[playlistsMenu numberOfItems] + [indices indexOfObject:[NSNumber numberWithInt:[[[MainController sharedController] currentRemote] currentSourceIndex]]] - [indices count]];
         [tempItem setState:NSOnState];
     if ( (source == ITMTRemoteSharedLibrarySource) || (source == ITMTRemoteiPodSource) || (source == ITMTRemoteGenericDeviceSource) || (source == ITMTRemoteCDSource) ) {
         tempItem = [playlistsMenu itemAtIndex:[playlistsMenu numberOfItems] + [indices indexOfObject:[NSNumber numberWithInt:[[[MainController sharedController] currentRemote] currentSourceIndex]]] - [indices count]];
         [tempItem setState:NSOnState];
     } else if (source == ITMTRemoteLibrarySource && _currentPlaylist) {
         [[playlistsMenu itemAtIndex:_currentPlaylist - 1] setState:NSOnState];
     }
     } else if (source == ITMTRemoteLibrarySource && _currentPlaylist) {
         [[playlistsMenu itemAtIndex:_currentPlaylist - 1] setState:NSOnState];
     }
+       NS_HANDLER
+       NS_ENDHANDLER
     [indices release];
     tempItem = [playlistsMenu addItemWithTitle:NSLocalizedString(@"refresh", @"Refresh") action:@selector(rebuildSubmenus) keyEquivalent:@""];
     [tempItem setTarget:self];
     [tempItem setImage:[NSImage imageNamed:@"ChasingArrow"]];
     ITDebugLog(@"Done Building \"Playlists\" menu");
     [indices release];
     tempItem = [playlistsMenu addItemWithTitle:NSLocalizedString(@"refresh", @"Refresh") action:@selector(rebuildSubmenus) keyEquivalent:@""];
     [tempItem setTarget:self];
     [tempItem setImage:[NSImage imageNamed:@"ChasingArrow"]];
     ITDebugLog(@"Done Building \"Playlists\" menu");
-    return playlistsMenu;
+    NS_VALUERETURN(playlistsMenu, NSMenu *);
+       NS_HANDLER
+               [playlistsMenu release];
+               _continue = NO;
+               NS_VALUERETURN(nil, NSMenu *);
+       NS_ENDHANDLER
 }
 
 - (NSMenu *)eqMenu
 }
 
 - (NSMenu *)eqMenu
index 24c8b60..5a46077 100755 (executable)
                        buildRules = (
                        );
                        buildSettings = {
                        buildRules = (
                        );
                        buildSettings = {
+                               COPY_PHASE_STRIP = YES;
                                FRAMEWORK_SEARCH_PATHS = "../ITFoundation/build ../ITKit/build";
                                GCC_ENABLE_TRIGRAPHS = NO;
                                GCC_GENERATE_DEBUGGING_SYMBOLS = NO;
                                FRAMEWORK_SEARCH_PATHS = "../ITFoundation/build ../ITKit/build";
                                GCC_ENABLE_TRIGRAPHS = NO;
                                GCC_GENERATE_DEBUGGING_SYMBOLS = NO;
index c116c09..9c8888a 100755 (executable)
             divisor = MINI_DIVISOR;
         }
 
             divisor = MINI_DIVISOR;
         }
 
-        font = [NSFont fontWithName:@"Lucida Grande Bold" size:(baseFontSize / divisor)];
+        font = [NSFont fontWithName:@"LucidaGrande-Bold" size:(baseFontSize / divisor)];
         attr = [NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName];
         
 //      Iterate over each line to get text width and height
         attr = [NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName];
         
 //      Iterate over each line to get text width and height
             divisor = MINI_DIVISOR;
         }
         
             divisor = MINI_DIVISOR;
         }
         
-        font        = [NSFont fontWithName:@"Lucida Grande Bold" size:( size / divisor )];
+        font        = [NSFont fontWithName:@"LucidaGrande-Bold" size:( size / divisor )];
         attr        = [NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName];
         charSize    = [character sizeWithAttributes:attr];
         cellHeight  = ( charSize.height + 4.0 );  // Add 4.0 for shadow
         attr        = [NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName];
         charSize    = [character sizeWithAttributes:attr];
         cellHeight  = ( charSize.height + 4.0 );  // Add 4.0 for shadow
             divisor = MINI_DIVISOR;
         }
         
             divisor = MINI_DIVISOR;
         }
         
-        font = [NSFont fontWithName:@"Lucida Grande Bold" size:(baseFontSize / divisor)];
+        font = [NSFont fontWithName:@"LucidaGrande-Bold" size:(baseFontSize / divisor)];
         attr = [NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName];
         attr = [NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName];
-        buttonFont = [NSFont fontWithName:@"Lucida Grande Bold" size:(14 / divisor)];
+        buttonFont = [NSFont fontWithName:@"LucidaGrande-Bold" size:(14 / divisor)];
         buttonAttr = [NSDictionary dictionaryWithObjectsAndKeys:
             buttonFont , NSFontAttributeName,
             textColor  , NSForegroundColorAttributeName, 
         buttonAttr = [NSDictionary dictionaryWithObjectsAndKeys:
             buttonFont , NSFontAttributeName,
             textColor  , NSForegroundColorAttributeName, 
index 34d49bd..6b08453 100755 (executable)
     
     ITDebugLog(@"Getting playlists.");
     if (numSources == 0) {
     
     ITDebugLog(@"Getting playlists.");
     if (numSources == 0) {
+               [allSources release];
         ITDebugLog(@"No sources.");
         return nil;
     }
         ITDebugLog(@"No sources.");
         return nil;
     }
                makePlaylistWithTerm:ofType: method.
        */
     int temp1;
                makePlaylistWithTerm:ofType: method.
        */
     int temp1;
+       NSAppleEventDescriptor *result;
     ITDebugLog(@"Getting number of songs in playlist at index %i", index);
     ITDebugLog(@"Getting number of songs in playlist at index %i", index);
-    temp1 = (int)[ITSendAEWithString([NSString stringWithFormat:@"kocl:type('cTrk'), '----':obj { form:'indx', want:type('cPly'), seld:long(%lu), from:obj { form:'prop', want:type('prop'), seld:type('ctnr'), from:obj { form:'prop', want:type('prop'), seld:type('pPla'), from:'null'() } } }", index], 'core', 'cnte', &savedPSN) int32Value];
+       result = ITSendAEWithString([NSString stringWithFormat:@"kocl:type('cTrk'), '----':obj { form:'indx', want:type('cPly'), seld:long(%lu), from:obj { form:'prop', want:type('prop'), seld:type('ctnr'), from:obj { form:'prop', want:type('prop'), seld:type('pPla'), from:'null'() } } }", index], 'core', 'cnte', &savedPSN);
+       temp1 = (result == nil) ? -1 : (int)[result int32Value];
     ITDebugLog(@"Getting number of songs in playlist at index %i done", index);
     return temp1;
 }
     ITDebugLog(@"Getting number of songs in playlist at index %i done", index);
     return temp1;
 }