Fixed the state for the playlists menu item to show the currently playing playlist.
authorKent Sutherland <ksuther@ithinksw.com>
Mon, 12 Sep 2005 23:53:47 +0000 (23:53 +0000)
committerKent Sutherland <ksuther@ithinksw.com>
Mon, 12 Sep 2005 23:53:47 +0000 (23:53 +0000)
Added a new hotkey to toggle if a song should appear in shuffle.
Slightly modified the table view in the hot keys tab of the preferences.
I still have to make a status window for shufflability state.
Changed multiple instances of iTunesRemote using int32Value to typeCodeValue, which will hopefully reduce breakage in the future.

English.lproj/Preferences.nib/info.nib
English.lproj/Preferences.nib/keyedobjects.nib
ITMTRemote.h
ITMTRemote.m
MainController.m
MenuController.m
PreferencesController.m
iTunesRemote.m

index d935081..e50d6ba 100755 (executable)
@@ -12,7 +12,7 @@
                <string>386 450 380 122 0 0 1152 746 </string>
        </dict>
        <key>IBFramework Version</key>
-       <string>364.0</string>
+       <string>439.0</string>
        <key>IBLockedObjects</key>
        <array>
                <integer>281</integer>
@@ -22,6 +22,6 @@
                <integer>6</integer>
        </array>
        <key>IBSystem Version</key>
-       <string>7H63</string>
+       <string>8C46</string>
 </dict>
 </plist>
index 82b46aa..338c636 100755 (executable)
Binary files a/English.lproj/Preferences.nib/keyedobjects.nib and b/English.lproj/Preferences.nib/keyedobjects.nib differ
index 9cd019b..6f10b7b 100755 (executable)
@@ -324,6 +324,16 @@ er's process managment.
  */
 - (BOOL)setCurrentSongRating:(float)rating;
 
+/*!
+ * @method currentSongShuffable
+ */
+- (BOOL)currentSongShufflable;
+
+/*!
+ * @method setCurrentSongShuffable:
+ */
+- (BOOL)setCurrentSongShufflable:(BOOL)shufflable;
+
 /*!
  * @method equalizerEnabled
  */
index 3b4a828..75ed74f 100755 (executable)
     return NO;
 }
 
+- (BOOL)currentSongShufflable
+{
+       return NO;
+}
+
+- (BOOL)setCurrentSongShufflable:(BOOL)shufflable
+{
+       return NO;
+}
+
 - (BOOL)equalizerEnabled
 {
     return NO;
index 5819acd..7b008dd 100755 (executable)
@@ -768,7 +768,7 @@ static MainController *sharedController;
 {
     ITDebugLog(@"Show preferences.");
     [[PreferencesController sharedPrefs] showPrefsWindow:self];
-    [[StatusWindow sharedWindow] setLocked:NO];
+    [(StatusWindow *)[StatusWindow sharedWindow] setLocked:NO];
     [[StatusWindow sharedWindow] vanish:self];
     [[StatusWindow sharedWindow] setIgnoresMouseEvents:YES];
 }
@@ -975,6 +975,16 @@ static MainController *sharedController;
         [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]];
     }
     
+       if ([df objectForKey:@"ToggleShufflability"] != nil) {
+        ITDebugLog(@"Setting up toggle song shufflability hot key.");
+        hotKey = [[ITHotKey alloc] init];
+        [hotKey setName:@"ToggleShufflability"];
+        [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"ToggleShufflability"]]];
+        [hotKey setTarget:self];
+        [hotKey setAction:@selector(toggleSongShufflable)];
+        [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]];
+    }
+       
     if ([df objectForKey:@"PopupMenu"] != nil) {
         ITDebugLog(@"Setting up popup menu hot key.");
         hotKey = [[ITHotKey alloc] init];
@@ -1318,9 +1328,22 @@ static MainController *sharedController;
     NS_ENDHANDLER
 }
 
+- (void)toggleSongShufflable
+{
+       NS_DURING
+        BOOL flag = ![[self currentRemote] currentSongShufflable];
+        ITDebugLog(@"Toggling shufflability.");
+        [[self currentRemote] setCurrentSongShufflable:flag];
+        //Show song shufflability status window
+        //[statusWindowController showSongShuffabilityWindow:flag];
+    NS_HANDLER
+        [self networkError:localException];
+    NS_ENDHANDLER
+}
+
 - (void)registerNowOK
 {
-    [[StatusWindow sharedWindow] setLocked:NO];
+    [(StatusWindow *)[StatusWindow sharedWindow] setLocked:NO];
     [[StatusWindow sharedWindow] vanish:self];
     [[StatusWindow sharedWindow] setIgnoresMouseEvents:YES];
 
@@ -1329,7 +1352,7 @@ static MainController *sharedController;
 
 - (void)registerNowCancel
 {
-    [[StatusWindow sharedWindow] setLocked:NO];
+    [(StatusWindow *)[StatusWindow sharedWindow] setLocked:NO];
     [[StatusWindow sharedWindow] vanish:self];
     [[StatusWindow sharedWindow] setIgnoresMouseEvents:YES];
 
@@ -1484,14 +1507,14 @@ static MainController *sharedController;
         [NSTimer scheduledTimerWithTimeInterval:90.0 target:self selector:@selector(checkForRemoteServer) userInfo:nil repeats:NO];
     }*/
     [self checkForRemoteServerAndConnectImmediately:YES];
-    [[StatusWindow sharedWindow] setLocked:NO];
+    [(StatusWindow *)[StatusWindow sharedWindow] setLocked:NO];
     [[StatusWindow sharedWindow] vanish:self];
     [[StatusWindow sharedWindow] setIgnoresMouseEvents:YES];
 }
 
 - (void)cancelReconnect
 {
-    [[StatusWindow sharedWindow] setLocked:NO];
+    [(StatusWindow *)[StatusWindow sharedWindow] setLocked:NO];
     [[StatusWindow sharedWindow] vanish:self];
     [[StatusWindow sharedWindow] setIgnoresMouseEvents:YES];
 }
index 382e6f2..50ffb98 100755 (executable)
             if (source == ITMTRemoteRadioSource) {
                 [playlistsMenu addItem:[NSMenuItem separatorItem]];
                 [[playlistsMenu addItemWithTitle:NSLocalizedString(@"radio", @"Radio") action:@selector(performPlaylistMenuAction:) keyEquivalent:@""] setState:NSOnState];
-            }
-        } else {
-            [playlistsMenu addItem:[NSMenuItem separatorItem]];
+            } else if ([playlists count] > 2) {
+                               [playlistsMenu addItem:[NSMenuItem separatorItem]];
+                       }
         }
                
                //Add other sources as needed (shared music, iPods, CDs)
                        [tempItem setState:NSOnState];
                        [[[tempItem submenu] itemAtIndex:_currentPlaylist - 1] setState:NSOnState];
                } else if (source == ITMTRemoteLibrarySource && _currentPlaylist) {
-                       [[playlistsMenu itemAtIndex:_currentPlaylist - 1] setState:NSOnState];
+                       [[playlistsMenu itemAtIndex:_currentPlaylist - 2] setState:NSOnState];
                }
        }
        NS_HANDLER
index 247dca7..02ba0a0 100755 (executable)
@@ -98,6 +98,7 @@ static PreferencesController *prefs = nil;
                                                        @"DecrementRating",
                                                        @"ToggleShuffle",
                                                        @"ToggleLoop",
+                                                                                                          @"ToggleShufflability",
                                                        @"PopupMenu",
                                                        @"SetRating0",
                                                        @"SetRating1",
@@ -121,6 +122,7 @@ static PreferencesController *prefs = nil;
                                                        @"Decrement Rating",
                                                        @"Toggle Shuffle",
                                                        @"Toggle Loop",
+                                                                                                          @"Toggle Song Included In Shuffle",
                                                        @"Pop-up status menu",
                                                        [NSString stringWithUTF8String:"Set Rating: ☆☆☆☆☆"],
                                                        [NSString stringWithUTF8String:"Set Rating: ★☆☆☆☆"],
index ef53fc5..3dc2504 100755 (executable)
        
        //Loop through each source
        for (i = 1; i <= numSources; i++) {
-        SInt32 fourcc = [ITSendAEWithString([NSString stringWithFormat:@"'----':obj { form:'prop', want:type('prop'), seld:type('pKnd'), from:obj { form:'indx', want:type('cSrc'), seld:long(%i), from:() } }", i], 'core', 'getd', &savedPSN) int32Value]; //Type of the current source
+        FourCharCode fourcc = [ITSendAEWithString([NSString stringWithFormat:@"'----':obj { form:'prop', want:type('prop'), seld:type('pKnd'), from:obj { form:'indx', want:type('cSrc'), seld:long(%i), from:() } }", i], 'core', 'getd', &savedPSN) typeCodeValue]; //Type of the current source
         NSString *sourceName = [ITSendAEWithString([NSString stringWithFormat:@"'----':obj { form:'prop', want:type('prop'), seld:type('pnam'), from:obj { form:'indx', want:type('cSrc'), seld:long(%i), from:() } }", i], 'core', 'getd', &savedPSN) stringValue]; //Name of the current source
         SInt32 index = [ITSendAEWithString([NSString stringWithFormat:@"'----':obj { form:'prop', want:type('prop'), seld:type('pidx'), from:obj { form:'indx', want:type('cSrc'), seld:long(%i), from:() } }", i], 'core', 'getd', &savedPSN) int32Value]; //Index of the current source
         ITMTRemotePlayerSource class; //The class of the current source
 
     ITDebugLog(@"Getting current source.");   
     
-    fourcc = ([self isPlaying]) ? [ITSendAEWithString(@"'----':obj { form:'prop', want:type('prop'), seld:type('pKnd'), from:obj { form:'prop', want:type('prop'), seld:type('ctnr'), from:obj { form:'prop', want:type('prop'), seld:type('pPla'), from:'null'() } } }", 'core', 'getd', &savedPSN) int32Value] : 'kLib';
+    fourcc = ([self isPlaying]) ? [ITSendAEWithString(@"'----':obj { form:'prop', want:type('prop'), seld:type('pKnd'), from:obj { form:'prop', want:type('prop'), seld:type('ctnr'), from:obj { form:'prop', want:type('prop'), seld:type('pPla'), from:'null'() } } }", 'core', 'getd', &savedPSN) typeCodeValue] : 'kLib';
     
     switch (fourcc) {
         case 'kTun':
 
 - (ITMTRemotePlayerPlaylistClass)currentPlaylistClass
 {
-    SInt32 realResult;
+    FourCharCode realResult;
     ITDebugLog(@"Getting current playlist class");
-    realResult = [ITSendAEWithString(@"'----':obj { form:'prop', want:type('prop'), seld:type('pcls'), from:obj { form:'prop', want:type('prop'), seld:type('pPla'), from:'null'() } }", 'core', 'getd', &savedPSN) int32Value];
+    realResult = [ITSendAEWithString(@"'----':obj { form:'prop', want:type('prop'), seld:type('pcls'), from:obj { form:'prop', want:type('prop'), seld:type('pPla'), from:'null'() } }", 'core', 'getd', &savedPSN) typeCodeValue];
     switch (realResult)
           {
           case 'cLiP':
     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 int32Value] == 'prop') {
+       if ([descriptor typeCodeValue] == 'prop') {
                return @"0-0";
        } else if (descriptor == nil) {
                return nil;
        }
-    SInt32 cls = [descriptor int32Value];
+    FourCharCode cls = [descriptor typeCodeValue];
     if ( ([self currentPlaylistClass] == ITMTRemotePlayerRadioPlaylist) || (cls == 'cURT') ) {
                NSString *bad = [NSString stringWithUTF8String:"浳湧"];
         temp1 = [ITSendAEWithKey('pStT', 'core', 'getd', &savedPSN) stringValue];
 {
     NSString *temp1;
     ITDebugLog(@"Getting current song title.");
-    SInt32 result = [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];
+    FourCharCode result = [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) typeCodeValue];
        
     //If we're listening to the radio.
     if (result == 'cURT') {
     return YES;
 }
 
+- (BOOL)currentSongShufflable
+{
+       BOOL temp1;
+       ITDebugLog(@"Getting current song shufflable status.");
+    temp1 = (![self isPlaying] || ([self currentPlaylistClass] == ITMTRemotePlayerRadioPlaylist)) ? NO : [ITSendAEWithString(@"'----':obj { form:'prop', want:type('prop'), seld:type('pSfa'), from:obj { form:'prop', want:type('prop'), seld:type('pTrk'), from:'null'() } }", 'core', 'getd', &savedPSN) booleanValue];
+    ITDebugLog(@"Getting current song shufflable status done.");
+    return temp1;
+}
+
+- (BOOL)setCurrentSongShufflable:(BOOL)shufflable
+{
+       ITDebugLog(@"Setting current song shufflable status to %i.", shufflable);
+    if ([self currentPlaylistClass] == ITMTRemotePlayerRadioPlaylist) {
+               ITDebugLog(@"Not a valid track to set status to, returning.");
+               return NO;
+       }
+       ITSendAEWithString([NSString stringWithFormat:@"data:long(%lu), '----':obj { form:'prop', want:type('prop'), seld:type('pSfa'), from:obj { form:'indx', want:type('cTrk'), seld:long(%lu), from:obj { form:'prop', want:type('prop'), seld:type('pPla'), from:'null'() } } }", !shufflable, [self currentSongIndex]], 'core', 'setd', &savedPSN);
+    ITDebugLog(@"Setting current song shufflable status to %i done.", shufflable);
+    return YES;
+}
+
 - (BOOL)equalizerEnabled
 {
     ITDebugLog(@"Getting equalizer enabled status.");
 
 - (BOOL)isPlaying
 {
-       return ([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');
+       return ([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) typeCodeValue] != 'prop');
 }
 
 - (void)notificationHandler:(NSNotification *)note