Changing hotkeys in the prefs now writes to the prefs and rebuilds the menu.
[MenuTunes.git] / iTunesRemote.m
index f796d95..1ab3043 100755 (executable)
 - (BOOL)begin
 {
     iTunesPSN = [self iTunesPSN];
-    
-    [[[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 [[ITAppleEventCenter sharedCenter] sendAEWithSendString:[NSString stringWithFormat:@"'----':obj { form:'prop', want:type('prop'), seld:type('pnam'), from:obj { form:'indx', want:type('cTrk'), seld:long(%lu), from:obj { form:'prop', want:type('prop'), seld:type('pPla'), from:'null'() } } }",index] eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN];
 }
 
+- (int)currentAlbumTrackCount
+{
+    return [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKeyForNumber:@"pTrC" fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN];
+}
+
+- (int)currentSongTrack
+{
+    return [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKeyForNumber:@"pTrN" fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN];
+}
+
 - (NSString *)currentSongUniqueIdentifier
 {
     return [NSString stringWithFormat:@"%i-%i", [self currentPlaylistIndex], [[ITAppleEventCenter sharedCenter] sendTwoTierAEWithRequestedKeyForNumber:@"pDID" fromObjectByKey:@"pTrk" eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN]];
     return YES;
 }
 
-- (BOOL)equalizerEnabled
+/* - (BOOL)equalizerEnabled
 {
     int thingy = [[ITAppleEventCenter sharedCenter] sendAEWithSendStringForNumber:@"'----':obj { form:type('prop'), want:type('prop'), seld:type('pEQ '), from:() }" eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN];
     NSLog(@"Debug equalizerEnabled: %i", thingy);
-    return thingy;    
+    return thingy;
 }
 
 - (BOOL)setEqualizerEnabled:(BOOL)enabled
 {
     [[ITAppleEventCenter sharedCenter] sendAEWithSendString:[NSString stringWithFormat:@"data:long(%lu), '----':obj { form:'prop', want:type('prop'), seld:type('pEQ '), from:'null'() }",enabled] eventClass:@"core" eventID:@"setd" appPSN:iTunesPSN];
     return YES;
-}
+} */
 
 - (NSArray *)eqPresets
 {
 
 - (ITMTRemotePlayerRepeatMode)repeatMode
 {
-    FourCharCode m00f;
-    int result;
+    FourCharCode m00f = 0;
+    int result = 0;
     m00f = [[ITAppleEventCenter sharedCenter]
                 sendTwoTierAEWithRequestedKeyForNumber:@"pRpt" fromObjectByKey:@"pPla" eventClass:@"core" eventID:@"getd" appPSN:iTunesPSN];
 
 
 - (BOOL)setRepeatMode:(ITMTRemotePlayerRepeatMode)repeatMode
 {
-    FourCharCode m00f;
+    FourCharCode m00f = 0;
     switch (repeatMode)
           {
           case ITMTRemotePlayerRepeatOff:
     return number;
 }
 
-- (void)applicationLaunched:(NSNotification *)note
-{
-    NSDictionary *info = [note userInfo];
-
-    if ([[info objectForKey:@"NSApplicationName"] isEqualToString:@"iTunes"]) {
-        iTunesPSN.highLongOfPSN = [[info objectForKey:@"NSApplicationProcessSerialNumberHigh"] longValue];
-        iTunesPSN.lowLongOfPSN = [[info objectForKey:@"NSApplicationProcessSerialNumberLow"] longValue];
-
-        [[NSNotificationCenter defaultCenter] postNotificationName:@"ITMTRemoteAppDidLaunchNotification" object:nil];
-    }
-}
-
-- (void)applicationTerminated:(NSNotification *)note
-{
-    NSDictionary *info = [note userInfo];
-
-    if ([[info objectForKey:@"NSApplicationName"] isEqualToString:@"iTunes"]) {
-        iTunesPSN.highLongOfPSN = kNoProcess;
-        [[NSNotificationCenter defaultCenter] postNotificationName:@"ITMTRemoteAppDidTerminateNotification" object:nil];
-    }
-}
-
 @end