+ return [NSDictionary dictionaryWithObjectsAndKeys:
+ [NSNumber numberWithBool: YES], @"Remote",
+ [NSNumber numberWithBool: YES], @"Basic Track Control",
+ [NSNumber numberWithBool: YES], @"Track Information",
+ [NSNumber numberWithBool: YES], @"Track Navigation",
+ [NSNumber numberWithBool: YES], @"Upcoming Songs",
+ [NSNumber numberWithBool: YES], @"Playlists",
+ [NSNumber numberWithBool: YES], @"Volume",
+ [NSNumber numberWithBool: YES], @"Shuffle",
+ [NSNumber numberWithBool: YES], @"Repeat Modes",
+ [NSNumber numberWithBool: YES], @"Equalizer",
+ [NSNumber numberWithBool: YES], @"Track Rating",
+ nil];
+}
+
+- (BOOL)showPrimaryInterface
+{
+ ITDebugLog(@"Showing player primary interface.");
+ // Still have to convert these to AEs:
+ // set minimized of browser window 1 to false
+ [[ITAppleEventCenter sharedCenter] sendAEWithSendString:@"data:long(0), '----':obj { form:'prop', want:type('prop'), seld:type('pMin'), from:obj { form:'indx', want:type('cBrW'), seld:1, from:'null'() } }" eventClass:@"core" eventID:@"setd" appPSN:savedPSN];
+ // set visible of browser window 1 to true
+ [[ITAppleEventCenter sharedCenter] sendAEWithSendString:@"data:long(1), '----':obj { form:'prop', want:type('prop'), seld:type('pvis'), from:obj { form:'indx', want:type('cBrW'), seld:1, from:'null'() } }" eventClass:@"core" eventID:@"setd" appPSN:savedPSN];
+ // Make this into AppleEvents... shouldn't be too hard, I'm just too tired to do it right now.
+ [[ITAppleEventCenter sharedCenter] sendAEWithSendString:@"data:long(1), '----':obj { form:'prop', want:type('prop'), seld:type('pisf'), from:'null'() }" eventClass:@"core" eventID:@"setd" appPSN:savedPSN];
+ ITDebugLog(@"Done showing player primary interface.");
+ return YES;
+}
+
+- (ITMTRemotePlayerRunningState)playerRunningState
+{
+ NSArray *apps = [[NSWorkspace sharedWorkspace] launchedApplications];
+ int i;
+ int count = [apps count];
+
+ for (i = 0; i < count; i++) {
+ if ([[[apps objectAtIndex:i] objectForKey:@"NSApplicationName"] isEqualToString:@"iTunes"]) {
+ ITDebugLog(@"Player running state: 1");
+ return ITMTRemotePlayerRunning;
+ }
+ }
+ ITDebugLog(@"Player running state: 0");
+ return ITMTRemotePlayerNotRunning;
+}
+
+- (ITMTRemotePlayerPlayingState)playerPlayingState
+{
+ long result;
+
+ ITDebugLog(@"Getting player playing state");
+
+ result = [[ITAppleEventCenter sharedCenter] sendAEWithSendStringForNumber:@"'----':obj { form:'prop', want:type('prop'), seld:type('pPlS'), from:'null'() }" eventClass:@"core" eventID:@"getd" appPSN:savedPSN];
+
+ switch (result)
+ {
+ case 'kPSP':
+ ITDebugLog(@"Getting player playing state done. Player state: Playing");
+ return ITMTRemotePlayerPlaying;
+ case 'kPSp':
+ ITDebugLog(@"Getting player playing state done. Player state: Paused");
+ return ITMTRemotePlayerPaused;
+ case 'kPSR':
+ ITDebugLog(@"Getting player playing state done. Player state: Rewinding");
+ return ITMTRemotePlayerRewinding;
+ case 'kPSF':
+ ITDebugLog(@"Getting player playing state done. Player state: Forwarding");
+ return ITMTRemotePlayerForwarding;
+ case 'kPSS':
+ default:
+ ITDebugLog(@"Getting player playing state done. Player state: Stopped");
+ return ITMTRemotePlayerStopped;
+ }
+ ITDebugLog(@"Getting player playing state done. Player state: Stopped");
+ return ITMTRemotePlayerStopped;
+}
+
+- (NSArray *)playlists
+{
+ long i = 0;
+ const signed long numPlaylists = [[ITAppleEventCenter sharedCenter] sendAEWithSendStringForNumber:@"kocl:type('cPly'), '----':()" eventClass:@"core" eventID:@"cnte" appPSN:savedPSN];
+ NSMutableArray *playlists = [[NSMutableArray alloc] initWithCapacity:numPlaylists];
+
+ ITDebugLog(@"Getting playlists.");
+
+ for (i = 1; i <= numPlaylists; i++) {
+ const long j = i;
+ NSString *sendStr = [NSString stringWithFormat:@"'----':obj { form:'prop', want:type('prop'), seld:type('pnam'), from:obj { form:'indx', want:type('cPly'), seld:long(%lu), from:'null'() } }",(unsigned long)j];
+ NSString *theObj = [[ITAppleEventCenter sharedCenter] sendAEWithSendString:sendStr eventClass:@"core" eventID:@"getd" appPSN:savedPSN];
+ ITDebugLog(@"Adding playlist: %@", theObj);
+ [playlists addObject:theObj];
+ }
+ ITDebugLog(@"Finished getting playlists.");
+ return [playlists autorelease];
+}
+
+- (int)numberOfSongsInPlaylistAtIndex:(int)index
+{
+ int temp1;
+ ITDebugLog(@"Getting number of songs in playlist at index %i", index);
+ temp1 = [[ITAppleEventCenter sharedCenter] sendAEWithSendStringForNumber:[NSString stringWithFormat:@"kocl:type('cTrk'), '----':obj { form:'indx', want:type('cPly'), seld:long(%lu), from:'null'() }",index] eventClass:@"core" eventID:@"cnte" appPSN:savedPSN];
+ ITDebugLog(@"Getting number of songs in playlist at index %i done", index);
+ return temp1;
+}
+
+- (ITMTRemotePlayerSource)currentSource
+{
+ unsigned long fourcc;
+
+ ITDebugLog(@"Getting current source.");
+
+ fourcc = (unsigned long)[[ITAppleEventCenter sharedCenter] sendAEWithSendStringForNumber :[NSString stringWithFormat:@"'----':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'() } } }"] eventClass:@"core" eventID:@"getd" appPSN:savedPSN];
+
+ switch (fourcc) {
+ case 'kTun':
+ ITDebugLog(@"Getting current source done. Source: Radio.");
+ return ITMTRemoteRadioSource;
+ break;
+ case 'kDev':
+ ITDebugLog(@"Getting current source done. Source: Generic Device.");
+ return ITMTRemoteGenericDeviceSource;
+ case 'kPod':
+ ITDebugLog(@"Getting current source done. Source: iPod.");
+ return ITMTRemoteiPodSource; //this is stupid
+ break;
+ case 'kMCD':
+ case 'kACD':
+ ITDebugLog(@"Getting current source done. Source: CD.");
+ return ITMTRemoteCDSource;
+ break;
+ case 'kUnk':
+ case 'kLib':
+ case 'kShd':
+ default:
+ ITDebugLog(@"Getting current source done. Source: Library.");
+ return ITMTRemoteLibrarySource;
+ break;
+ }
+}
+
+- (ITMTRemotePlayerPlaylistClass)currentPlaylistClass
+{
+ int realResult = [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKeyForNumber:@"pcls" fromObjectByKey:@"pPla" eventClass:@"core" eventID:@"getd" appPSN:savedPSN];
+
+ ITDebugLog(@"Getting current playlist class");
+ switch (realResult)
+ {
+ case 'cLiP':
+ ITDebugLog(@"Getting current playlist class done. Class: Library.");
+ return ITMTRemotePlayerLibraryPlaylist;
+ break;
+ case 'cRTP':
+ ITDebugLog(@"Getting current playlist class done. Class: Radio.");
+ return ITMTRemotePlayerRadioPlaylist;
+ break;
+ default:
+ ITDebugLog(@"Getting current playlist class done. Class: Standard playlist.");
+ return ITMTRemotePlayerPlaylist;
+ }