Finally fixed all the memory leaks, I hope. Fixed iTunesRemote to not
authorKent Sutherland <ksuther@ithinksw.com>
Mon, 11 Oct 2004 03:08:03 +0000 (03:08 +0000)
committerKent Sutherland <ksuther@ithinksw.com>
Mon, 11 Oct 2004 03:08:03 +0000 (03:08 +0000)
leak in some methods, and fixed MenuController to not call things that
could possibly leak.

MenuController.m
iTunesRemote.m

index b5d2c21..4ceb31f 100755 (executable)
     NSArray *menu = [[NSUserDefaults standardUserDefaults] arrayForKey:@"menu"];
     ITDebugLog(@"Rebuilding all of the submenus.");
     NS_DURING
-        _currentPlaylist = [[[MainController sharedController] currentRemote] currentPlaylistIndex];
-        _currentTrack = [[[MainController sharedController] currentRemote] currentSongIndex];
+               _currentTrack = [[[MainController sharedController] currentRemote] currentSongIndex];
+               if (_currentTrack > -1) {
+                       _currentPlaylist = [[[MainController sharedController] currentRemote] currentPlaylistIndex];
+               }
         _playingRadio = ([[[MainController sharedController] currentRemote] currentPlaylistClass] == ITMTRemotePlayerRadioPlaylist);
     NS_HANDLER
         [[MainController sharedController] networkError:localException];
 
 - (NSMenu *)upcomingSongsMenu
 {
-    NSMenu *upcomingSongsMenu = [[NSMenu alloc] initWithTitle:@""];
+    NSMenu *upcomingSongsMenu;
     int numSongs = 0, numSongsInAdvance = [[NSUserDefaults standardUserDefaults] integerForKey:@"SongsInAdvance"];
+       if (_currentTrack == -1) {
+               return nil;
+       }
     NS_DURING
         numSongs = [[[MainController sharedController] currentRemote] numberOfSongsInPlaylistAtIndex:_currentPlaylist];
     NS_HANDLER
     NS_ENDHANDLER
     
        if (numSongs == -1) {
-               [upcomingSongsMenu release];
                return nil;
        }
+       upcomingSongsMenu = [[NSMenu alloc] initWithTitle:@""];
        NS_DURING
     ITDebugLog(@"Building \"Upcoming Songs\" menu.");
     if (_currentPlaylist && !_playingRadio) {
index 6b08453..0689704 100755 (executable)
     NSString *temp1;
     ITDebugLog(@"Getting current unique identifier.");
        NSAppleEventDescriptor *descriptor = ITSendAEWithString(@"'----':obj { form:'prop', want:type('prop'), seld:type('pcls'), from:obj { form:'prop', want:type('prop'), seld:type('pTrk'), from:'null'() } }", 'core', 'getd', &savedPSN);
-       if (descriptor == nil) {
-               return nil;
+       if ((descriptor == nil) || ([descriptor int32Value] == 'prop')) {
+               return @"0-0";
        }
     SInt32 cls = [descriptor int32Value];
     if ( ([self currentPlaylistClass] == ITMTRemotePlayerRadioPlaylist) || (cls == 'cURT') ) {
 {
     int temp1;
     ITDebugLog(@"Getting current song index.");
-    temp1 = [ITSendAEWithString(@"'----':obj { form:'prop', want:type('prop'), seld:type('pidx'), from:obj { form:'prop', want:type('prop'), seld:type('pTrk'), from:'null'() } }", 'core', 'getd', &savedPSN) int32Value];
+       temp1 = (([ITSendAEWithString(@"'----':obj { form:'prop', want:type('prop'), seld:type('pcls'), from:obj { form:'prop', want:type('prop'), seld:type('pTrk'), from:'null'() } }", 'core', 'getd', &savedPSN) int32Value] != 'prop') ? [ITSendAEWithString(@"'----':obj { form:'prop', want:type('prop'), seld:type('pidx'), from:obj { form:'prop', want:type('prop'), seld:type('pTrk'), from:'null'() } }", 'core', 'getd', &savedPSN) int32Value] : -1);
     ITDebugLog(@"Getting current song index done.");
     return temp1;
 }