Bah, I thought Kent modified the MenuTunes class to accommodate the
[MenuTunes.git] / iTunesRemote.m
index 7bb71c5..a5a1f82 100755 (executable)
@@ -7,17 +7,17 @@
     return [[[iTunesRemote alloc] init] autorelease];
 }
 
-- (NSString *)title
+- (NSString *)remoteTitle
 {
-    return @"iTunes";
+    return @"iTunes Remote";
 }
 
-- (NSString *)information;
+- (NSString *)remoteInformation
 {
-    return @"Default MenuTunes plugin to control iTunes. Written by iThink Software.";
+    return @"Default MenuTunes plugin to control iTunes, by iThink Software.";
 }
 
-- (NSImage *)icon
+- (NSImage *)remoteIcon
 {
     return nil;
 }
 - (BOOL)begin
 {
     iTunesPSN = [self iTunesPSN];
-
-    //Register for application termination in NSWorkspace
+    
     [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(applicationLaunched:) name:NSWorkspaceDidLaunchApplicationNotification object:nil];
     [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(applicationTerminated:) name:NSWorkspaceDidTerminateApplicationNotification object:nil];
-
+    
     return YES;
 }
 
     return YES;
 }
 
-- (ITMTRemotePlayerRunningStatus)playerRunningStatus
+- (NSString *)playerFullName
+{
+    return @"iTunes";
+}
+
+- (NSString *)playerSimpleName
+{
+    return @"iTunes";
+}
+
+- (NSDictionary *)capabilities
+{
+    return nil;
+}
+
+- (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"]) {
+        if ([[[apps objectAtIndex:i] objectForKey:@"NSApplicationName"] isEqualToString:@"iTunes"]) {
             return ITMTRemotePlayerRunning;
         }
     }
     return ITMTRemotePlayerNotRunning;
 }
 
-- (ITMTRemotePlayerState)playerState
+- (ITMTRemotePlayerPlayingState)playerPlayingState
 {
     long result = [[ITAppleEventCenter sharedCenter] sendAEWithSendStringForNumber:@"'----':obj { form:'prop', want:type('prop'), seld:type('pPlS'), from:'null'() }" eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN];
     
     long i = 0;
     const signed long numPlaylists = [[ITAppleEventCenter sharedCenter] sendAEWithSendStringForNumber:@"kocl:type('cPly'), '----':(), &subj:()" eventClass:@"core" eventID:@"cnte" appPSN:iTunesPSN];
     NSMutableArray *playlists = [[NSMutableArray alloc] initWithCapacity:numPlaylists];
-
-
-          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:iTunesPSN];
-                 //NSLog(@"sent event cur %d max %d",i,numPlaylists);
-                 [playlists addObject:theObj];
-          }
-          return [playlists autorelease];
+    
+    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:iTunesPSN];
+        [playlists addObject:theObj];
+    }
+    return [playlists autorelease];
 }
 
 - (int)numberOfSongsInPlaylistAtIndex:(int)index
 
 - (NSString *)classOfPlaylistAtIndex:(int)index
 {
-    int realResult = [[ITAppleEventCenter sharedCenter]
-                sendTwoTierAEWithRequestedKeyForNumber:@"pcls" fromObjectByKey:@"pPla" eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN];
-
-    if (realResult == 'cRTP') return @"radio tuner playlist";
-    else return @"playlist";
+    int realResult = [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKeyForNumber:@"pcls" fromObjectByKey:@"pPla" eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN];
+    
+    if (realResult == 'cRTP') {
+        return @"radio tuner playlist";
+    } else {
+        return @"playlist";
+    }
 }
 
 - (int)currentPlaylistIndex
 {
     int result;
-    result = [[ITAppleEventCenter sharedCenter]
-                sendTwoTierAEWithRequestedKeyForNumber:@"pidx" fromObjectByKey:@"pPla" eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN];
+    result = [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKeyForNumber:@"pidx" fromObjectByKey:@"pPla" eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN];
     return result;
 }
 
     return NO;
 }
 
-- (float)volume
-{
-    long vol = [[ITAppleEventCenter sharedCenter] sendAEWithRequestedKeyForNumber:@"pVol" eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN];
-    return vol / 100;
-}
-
-- (BOOL)setVolume:(float)volume
-{
-    [[ITAppleEventCenter sharedCenter] sendAEWithSendString:[NSString stringWithFormat:@"data:long(%lu), ----:obj { form:'prop', want:type('prop'), seld:type('pVol'), from:'null'() }",(long)volume*100] eventClass:@"core" eventID:@"setd" appPSN:iTunesPSN];
-    return NO;
-}
-
-- (NSArray *)eqPresets;
+- (NSArray *)eqPresets
 {
     int i;
     long numPresets = [[ITAppleEventCenter sharedCenter] sendAEWithSendStringForNumber:@"kocl:type('cEQP'), '----':(), &subj:()" eventClass:@"core" eventID:@"cnte" appPSN:iTunesPSN];
     NSMutableArray *presets = [[NSMutableArray alloc] initWithCapacity:numPresets];
-
-          for (i = 1; i <= numPresets; i++) {
-                 NSString *theObj = [[ITAppleEventCenter sharedCenter] sendAEWithSendString:[NSString stringWithFormat:@"'----':obj { form:'prop', want:type('prop'), seld:type('pnam'), from:obj { form:'indx', want:type('cEQP'), seld:long(%lu), from:'null'() } }",i] eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN];
-                 if (theObj) [presets addObject:theObj];
-          }
-          return [presets autorelease];
+    
+    for (i = 1; i <= numPresets; i++) {
+        NSString *theObj = [[ITAppleEventCenter sharedCenter] sendAEWithSendString:[NSString stringWithFormat:@"'----':obj { form:'prop', want:type('prop'), seld:type('pnam'), from:obj { form:'indx', want:type('cEQP'), seld:long(%lu), from:'null'() } }",i] eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN];
+        if (theObj) {
+            [presets addObject:theObj];
+        }
+    }
+    return [presets autorelease];
 }
 
 - (int)currentEQPresetIndex
 {
     int result;
     result = [[ITAppleEventCenter sharedCenter]
-                sendTwoTierAEWithRequestedKeyForNumber:@"pidx"fromObjectByKey:@"pEQP" eventClass:@"core" eventID:@"getd"appPSN:iTunesPSN];
+                sendTwoTierAEWithRequestedKeyForNumber:@"pidx" fromObjectByKey:@"pEQP" eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN];
     return result;
 }
 
+- (float)volume
+{
+    long vol = [[ITAppleEventCenter sharedCenter] sendAEWithRequestedKeyForNumber:@"pVol" eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN];
+    return vol / 100;
+}
+
+- (BOOL)setVolume:(float)volume
+{
+    [[ITAppleEventCenter sharedCenter] sendAEWithSendString:[NSString stringWithFormat:@"data:long(%lu), ----:obj { form:'prop', want:type('prop'), seld:type('pVol'), from:'null'() }",(long)volume*100] eventClass:@"core" eventID:@"setd" appPSN:iTunesPSN];
+    return NO;
+}
+
 - (BOOL)play
 {
     [[ITAppleEventCenter sharedCenter] sendAEWithEventClass:@"hook" eventID:@"Play" appPSN:iTunesPSN];
     return YES;
 }
 
-- (BOOL)fastForward
+- (BOOL)forward
 {
     [[ITAppleEventCenter sharedCenter] sendAEWithEventClass:@"hook" eventID:@"Fast" appPSN:iTunesPSN];
     return YES;
     return YES;
 }
 
-
 - (BOOL)switchToPlaylistAtIndex:(int)index
 {
     [[ITAppleEventCenter sharedCenter] sendAEWithSendString:[NSString stringWithFormat:@"'----':obj { form:'indx', want:type('cPly'), seld:long(%lu), from:() }",index] eventClass:@"hook" eventID:@"Play" appPSN:iTunesPSN];