#import <Cocoa/Cocoa.h>
+typedef enum {stopped = -1, paused, playing, rewinding, forwarding} PlayerState;
+
/*! @protocol ITMTRemote
* @abstract Declares what a MenuTunes Remote must be able to do.
* @discussion A MenuTunes Remote must be able to return and change state information.
*/
- (BOOL)halt;
+- (PlayerState)playerState;
+
- (NSArray *)playlists;
- (int)numberOfSongsInPlaylistAtIndex:(int)index;
- (NSString *)classOfPlaylistAtIndex:(int)index;
- (BOOL)pause;
- (BOOL)goToNextSong;
- (BOOL)goToPreviousSong;
+- (BOOL)fastForward;
+- (BOOL)rewind;
- (BOOL)switchToPlaylistAtIndex:(int)index;
- (BOOL)switchToSongAtIndex:(int)index;
- (void)playPause:(id)sender
{
NSString *state = [self runScriptAndReturnResult:@"return player state"];
+ NSLog(@"%i", [currentRemote playerState]);
if ([state isEqualToString:@"playing"]) {
[currentRemote play];
[playPauseMenuItem setTitle:@"Play"];
- (void)fastForward:(id)sender
{
- [self sendAEWithEventClass:'hook' andEventID:'Fast'];
+ [currentRemote fastForward];
}
- (void)rewind:(id)sender
{
- [self sendAEWithEventClass:'hook' andEventID:'Rwnd'];
+ [currentRemote rewind];
}
+//
+//
// Plugin independent selectors
-
+//
+//
- (void)quitMenuTunes:(id)sender
{
[NSApp terminate:self];
}
+//How is this going to work, now that we're pluginized?
- (void)openiTunes:(id)sender
{
[[NSWorkspace sharedWorkspace] launchApplication:@"iTunes"];
switch (code)
{
case 36:
+ charcode = '\r';
break;
case 48:
+ charcode = '\t';
break;
+ //Space -- ARGH!
case 49:
+ {
+ /*MenuRef menuRef = _NSGetCarbonMenu([item menu]);
+ NSLog(@"%@", menuRef);
+ SetMenuItemCommandKey(menuRef, 0, NO, 49);
+ SetMenuItemModifiers(menuRef, 0, kMenuNoCommandModifier);
+ SetMenuItemKeyGlyph(menuRef, 0, kMenuBlankGlyph);
+ charcode = 'b';*/
+ }
break;
case 51:
charcode = NSDeleteFunctionKey;
break;
-
+
case 53:
+ charcode = '\e';
break;
-
+
case 71:
+ charcode = '\e';
break;
case 76:
+ charcode = '\r';
break;
case 96:
break;
case 115:
+ charcode = NSHomeFunctionKey;
break;
case 116:
keyTrans = KeyTranslate(kchr, code, &state);
charCode = keyTrans;
[item setKeyEquivalent:[NSString stringWithCString:&charCode length:1]];
- } else {
+ } else if (charcode != 'b') {
[item setKeyEquivalent:[NSString stringWithCharacters:&charcode length:1]];
}
}
return YES;
}
+- (PlayerState)playerState
+{
+ NSString *result = [self runScriptAndReturnResult:@"get player state"];
+
+ if ([result isEqualToString:@"playing"]) {
+ return playing;
+ } else if ([result isEqualToString:@"paused"]) {
+ return paused;
+ } else if ([result isEqualToString:@"stopped"]) {
+ return stopped;
+ } else if ([result isEqualToString:@"rewinding"]) {
+ return rewinding;
+ } else if ([result isEqualToString:@"fast forwarding"]) {
+ return forwarding;
+ }
+
+ return stopped;
+}
+
- (NSArray *)playlists
{
int i;
return YES;
}
+- (BOOL)fastForward
+{
+ [[ITAppleEventCenter sharedCenter] sendAEWithEventClass:@"hook" eventID:@"Fast"
+ appPSN:[self iTunesPSN]];
+ return YES;
+}
+
+- (BOOL)rewind
+{
+ [[ITAppleEventCenter sharedCenter] sendAEWithEventClass:@"hook" eventID:@"Rwnd"
+ appPSN:[self iTunesPSN]];
+ return YES;
+}
+
+
- (BOOL)switchToPlaylistAtIndex:(int)index
{
[self runScriptAndReturnResult:[NSString stringWithFormat: