From 28a72418f8254017a166b9307da970e5dc63c7e2 Mon Sep 17 00:00:00 2001 From: Kent Sutherland Date: Wed, 6 Oct 2004 22:48:05 +0000 Subject: [PATCH] Lots of code to keep MT from being bad when iTunes locks. Fixed leak in NSFont. --- MTShizzleWindow.m | 2 +- MainController.m | 63 ++++++++++++++++----------------- MenuController.h | 4 +-- MenuController.m | 53 ++++++++++++++++++++++----- MenuTunes.xcode/project.pbxproj | 1 + StatusWindow.m | 8 ++--- iTunesRemote.m | 5 ++- 7 files changed, 87 insertions(+), 49 deletions(-) diff --git a/MTShizzleWindow.m b/MTShizzleWindow.m index a0903a5..674d338 100755 --- a/MTShizzleWindow.m +++ b/MTShizzleWindow.m @@ -109,7 +109,7 @@ static MTShizzleWindow *_privateSharedWindow = nil; [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)]; diff --git a/MainController.m b/MainController.m index 4eb7891..0c19559 100755 --- a/MainController.m +++ b/MainController.m @@ -364,14 +364,14 @@ static MainController *sharedController; 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]; - [self setupHotKeys]; + [[ITHotKeyCenter sharedCenter] setEnabled:YES]; return; } @@ -395,41 +395,40 @@ static MainController *sharedController; timerUpdating = YES; [statusItem setEnabled:NO]; - + 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 - timerUpdating = NO; [statusItem setEnabled:YES]; } - + 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."]; - [self clearHotKeys]; + [[ITHotKeyCenter sharedCenter] setEnabled:NO]; } [statusItem setEnabled:NO]; return; } else if (![statusItem isEnabled]) { [statusItem setEnabled:YES]; [statusItem setToolTip:_toolTip]; - [self setupHotKeys]; + [[ITHotKeyCenter sharedCenter] setEnabled:YES]; return; } @@ -1234,7 +1233,7 @@ static MainController *sharedController; [self setupHotKeys]; //playerRunningState = ITMTRemotePlayerRunning; playerRunningState = [[self currentRemote] playerRunningState]; - + [refreshTimer invalidate]; refreshTimer = [[NSTimer scheduledTimerWithTimeInterval:([networkController isConnectedToServer] ? 10.0 : 0.5) target:self diff --git a/MenuController.h b/MenuController.h index fda5e5e..91a462a 100755 --- a/MenuController.h +++ b/MenuController.h @@ -45,12 +45,12 @@ typedef enum { NSMenu *_ratingMenu, *_upcomingSongsMenu, *_eqMenu, *_playlistsMenu, *_artistsMenu, *_albumsMenu; //Submenus int _currentPlaylist, _currentTrack; - BOOL _playingRadio; + BOOL _playingRadio, _continue; } - (NSMenu *)menu; - (NSMenu *)menuForNoPlayer; -- (void)rebuildSubmenus; +- (BOOL)rebuildSubmenus; // - (NSArray *)menuLayout; // - (void)setMenuLayout:(NSArray *)newLayoutArray; diff --git a/MenuController.m b/MenuController.m index 424957f..b5d2c21 100755 --- a/MenuController.m +++ b/MenuController.m @@ -491,7 +491,7 @@ return [menu autorelease]; } -- (void)rebuildSubmenus +- (BOOL)rebuildSubmenus { NSArray *menu = [[NSUserDefaults standardUserDefaults] arrayForKey:@"menu"]; ITDebugLog(@"Rebuilding all of the submenus."); @@ -503,38 +503,48 @@ [[MainController sharedController] networkError:localException]; NS_ENDHANDLER ITDebugLog(@"Releasing old submenus."); + _continue = YES; ITDebugLog(@" - Rating menu"); [_ratingMenu release]; + _ratingMenu = nil; ITDebugLog(@" - Upcoming songs menu"); [_upcomingSongsMenu release]; + _upcomingSongsMenu = nil; ITDebugLog(@" - Playlists menu"); [_playlistsMenu release]; + _playlistsMenu = nil; 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 \"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]; } - 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."); + return _continue; } - (NSMenu *)ratingMenu @@ -576,6 +586,11 @@ [[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) { @@ -604,7 +619,12 @@ } } 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 @@ -661,6 +681,13 @@ 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]; @@ -713,6 +740,7 @@ } } 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]; @@ -720,12 +748,19 @@ } 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"); - return playlistsMenu; + NS_VALUERETURN(playlistsMenu, NSMenu *); + NS_HANDLER + [playlistsMenu release]; + _continue = NO; + NS_VALUERETURN(nil, NSMenu *); + NS_ENDHANDLER } - (NSMenu *)eqMenu diff --git a/MenuTunes.xcode/project.pbxproj b/MenuTunes.xcode/project.pbxproj index 24c8b60..5a46077 100755 --- a/MenuTunes.xcode/project.pbxproj +++ b/MenuTunes.xcode/project.pbxproj @@ -1519,6 +1519,7 @@ buildRules = ( ); buildSettings = { + COPY_PHASE_STRIP = YES; FRAMEWORK_SEARCH_PATHS = "../ITFoundation/build ../ITKit/build"; GCC_ENABLE_TRIGRAPHS = NO; GCC_GENERATE_DEBUGGING_SYMBOLS = NO; diff --git a/StatusWindow.m b/StatusWindow.m index c116c09..9c8888a 100755 --- a/StatusWindow.m +++ b/StatusWindow.m @@ -218,7 +218,7 @@ 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 @@ -285,7 +285,7 @@ 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 @@ -375,9 +375,9 @@ 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]; - buttonFont = [NSFont fontWithName:@"Lucida Grande Bold" size:(14 / divisor)]; + buttonFont = [NSFont fontWithName:@"LucidaGrande-Bold" size:(14 / divisor)]; buttonAttr = [NSDictionary dictionaryWithObjectsAndKeys: buttonFont , NSFontAttributeName, textColor , NSForegroundColorAttributeName, diff --git a/iTunesRemote.m b/iTunesRemote.m index 34d49bd..6b08453 100755 --- a/iTunesRemote.m +++ b/iTunesRemote.m @@ -168,6 +168,7 @@ ITDebugLog(@"Getting playlists."); if (numSources == 0) { + [allSources release]; ITDebugLog(@"No sources."); return nil; } @@ -271,8 +272,10 @@ makePlaylistWithTerm:ofType: method. */ int temp1; + NSAppleEventDescriptor *result; 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; } -- 2.20.1