1 #import "MainController.h"
2 #import "PreferencesController.h"
3 #import "HotKeyCenter.h"
4 #import "StatusWindowController.h"
6 @interface MainController(Private)
7 - (ITMTRemote *)loadRemote;
10 - (void)setKeyEquivalentForCode:(short)code andModifiers:(long)modifiers
11 onItem:(NSMenuItem *)item;
14 @implementation MainController
16 /*************************************************************************/
18 #pragma mark INITIALIZATION/DEALLOCATION METHODS
19 /*************************************************************************/
23 if ( ( self = [super init] ) ) {
24 remoteArray = [[NSMutableArray alloc] initWithCapacity:1];
25 statusWindowController = [[StatusWindowController alloc] init];
26 df = [[NSUserDefaults standardUserDefaults] retain];
27 [self setLatestSongIdentifier:@"0-0"];
32 - (void)applicationDidFinishLaunching:(NSNotification *)note
34 currentRemote = [self loadRemote];
35 [currentRemote begin];
37 //Setup for notification of the remote player launching or quitting
38 [[[NSWorkspace sharedWorkspace] notificationCenter]
40 selector:@selector(applicationTerminated:)
41 name:NSWorkspaceDidTerminateApplicationNotification
44 [[[NSWorkspace sharedWorkspace] notificationCenter]
46 selector:@selector(applicationLaunched:)
47 name:NSWorkspaceDidLaunchApplicationNotification
50 if ( ! [df objectForKey:@"menu"] ) { // If this is nil, defaults have never been registered.
51 [[PreferencesController sharedPrefs] registerDefaults];
54 statusItem = [[ITStatusItem alloc]
55 initWithStatusBar:[NSStatusBar systemStatusBar]
56 withLength:NSSquareStatusItemLength];
58 [statusItem setImage:[NSImage imageNamed:@"menu"]];
59 [statusItem setAlternateImage:[NSImage imageNamed:@"selected_image"]];
62 - (ITMTRemote *)loadRemote
64 NSString *folderPath = [[NSBundle mainBundle] builtInPlugInsPath];
67 NSArray *bundlePathList = [NSBundle pathsForResourcesOfType:@"remote" inDirectory:folderPath];
68 NSEnumerator *enumerator = [bundlePathList objectEnumerator];
71 while ( (bundlePath = [enumerator nextObject]) ) {
72 NSBundle* remoteBundle = [NSBundle bundleWithPath:bundlePath];
75 Class remoteClass = [remoteBundle principalClass];
77 if ([remoteClass conformsToProtocol:@protocol(ITMTRemote)] &&
78 [remoteClass isKindOfClass:[NSObject class]]) {
80 id remote = [remoteClass remote];
81 [remoteArray addObject:remote];
86 // if ( [remoteArray count] > 0 ) { // UNCOMMENT WHEN WE HAVE > 1 PLUGIN
87 // if ( [remoteArray count] > 1 ) {
88 // [remoteArray sortUsingSelector:@selector(sortAlpha:)];
90 // [self loadModuleAccessUI]; //Comment out this line to disable remote visibility
93 // NSLog(@"%@", [remoteArray objectAtIndex:0]); //DEBUG
94 return [remoteArray objectAtIndex:0];
97 /*************************************************************************/
99 #pragma mark INSTANCE METHODS
100 /*************************************************************************/
102 - (void)startTimerInNewThread
104 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
105 NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
106 refreshTimer = [[NSTimer scheduledTimerWithTimeInterval:0.5
108 selector:@selector(timerUpdate)
110 repeats:YES] retain];
116 /*************************************************************************/
118 #pragma mark MENU BUILDING METHODS
119 /*************************************************************************/
123 NSMenu *theMenu = [[[NSMenu alloc] initWithTitle:@""] autorelease];
125 [theMenu addItem:[self playlistMenuItem]];
126 [theMenu addItem:[self upcomingSongsMenuItem]];
127 [theMenu addItem:[self ratingMenuItem]];
132 - (NSMenu *)menuForNoPlayer
137 - (NSMenuItem *)playlistMenuItem
139 NSMenuItem *item = [[[NSMenuItem alloc] initWithTitle:@"Playlists"
141 keyEquivalent:@""] autorelease];
142 NSMenu *submenu = [[[NSMenu alloc] initWithTitle:@""] autorelease];
144 int currentPlaylist = [currentRemote currentPlaylistIndex];
145 NSArray *playlists = [currentRemote playlists];
146 NSEnumerator *playlistEnum = [playlists objectEnumerator];
150 [item setSubmenu:submenu];
151 [submenu setAutoenablesItems:NO];
153 while ( (aPlaylist = [playlistEnum nextObject]) ) {
154 NSMenuItem *playlistItem = [[[NSMenuItem alloc] initWithTitle:aPlaylist
155 action:@selector(selectPlaylist:)
156 keyEquivalent:@""] autorelease];
157 [playlistItem setTag:playlistTag];
158 [playlistItem setTarget:self];
160 [submenu addItem:playlistItem];
163 if ( (! [self radioIsPlaying]) && currentPlaylist) {
164 [[submenu itemAtIndex:(currentPlaylist - 1)] setState:NSOnState];
170 - (NSMenuItem *)upcomingSongsMenuItem
172 NSMenuItem *item = [[[NSMenuItem alloc] initWithTitle:@"Upcoming Songs"
174 keyEquivalent:@""] autorelease];
175 NSMenu *submenu = [[[NSMenu alloc] initWithTitle:@""] autorelease];
177 int curIndex = [currentRemote currentPlaylistIndex];
178 int numSongs = [currentRemote numberOfSongsInPlaylistAtIndex:curIndex];
179 int numSongsInAdvance = [df integerForKey:@"SongsInAdvance"];
181 [item setSubmenu:submenu];
183 if ( [self radioIsPlaying] ) {
184 [submenu addItemWithTitle:@"No Upcoming Songs..." action:nil keyEquivalent:@""];
185 [submenu addItemWithTitle:@"Playing Radio Stream" action:nil keyEquivalent:@""];
187 if ( ! (numSongs > 0) ) {
188 [submenu addItemWithTitle:@"No Songs in Playlist" action:nil keyEquivalent:@""];
190 int curTrack = [currentRemote currentSongIndex];
193 for (i = curTrack + 1; ( (i <= curTrack + numSongsInAdvance) && (i <= numSongs) ); i++) {
195 NSString *curSong = [currentRemote songTitleAtIndex:i];
196 NSMenuItem *songItem = [[[NSMenuItem alloc] initWithTitle:curSong
197 action:@selector(selectSong:)
198 keyEquivalent:@""] autorelease];
199 [songItem setRepresentedObject:[NSNumber numberWithInt:i]];
200 [submenu addItem:songItem];
208 - (NSMenuItem *)ratingMenuItem
210 NSMenuItem *item = [[[NSMenuItem alloc] initWithTitle:@"Rating"
212 keyEquivalent:@""] autorelease];
213 NSMenu *submenu = [[[NSMenu alloc] initWithTitle:@""] autorelease];
215 [item setSubmenu:submenu];
217 [submenu addItemWithTitle:[NSString stringWithUTF8String:"☆☆☆☆☆"] action:nil keyEquivalent:@""];
218 [submenu addItemWithTitle:[NSString stringWithUTF8String:"★☆☆☆☆"] action:nil keyEquivalent:@""];
219 [submenu addItemWithTitle:[NSString stringWithUTF8String:"★★☆☆☆"] action:nil keyEquivalent:@""];
220 [submenu addItemWithTitle:[NSString stringWithUTF8String:"★★★☆☆"] action:nil keyEquivalent:@""];
221 [submenu addItemWithTitle:[NSString stringWithUTF8String:"★★★★☆"] action:nil keyEquivalent:@""];
222 [submenu addItemWithTitle:[NSString stringWithUTF8String:"★★★★★"] action:nil keyEquivalent:@""];
224 if ( ! ( [self radioIsPlaying] || [self songIsPlaying] ) ) {
226 NSEnumerator *itemEnum;
229 SEL itemSelector = @selector(selectSongRating:);
231 itemEnum = [[submenu itemArray] objectEnumerator];
232 while ( (anItem = [itemEnum nextObject]) ) {
233 [anItem setAction:itemSelector];
234 [anItem setTag:itemTag];
242 - (NSMenuItem *)eqMenuItem
244 NSMenuItem *item = [[[NSMenuItem alloc] initWithTitle:@"Equalizer"
246 keyEquivalent:@""] autorelease];
247 NSMenu *submenu = [[[NSMenu alloc] initWithTitle:@""] autorelease];
249 NSArray *eqPresets = [currentRemote eqPresets];
250 NSEnumerator *eqEnum = [eqPresets objectEnumerator];
254 [item setSubmenu:submenu];
256 while ( ( anEq = [eqEnum nextObject]) ) {
257 NSMenuItem *eqItem = [[[NSMenuItem alloc] initWithTitle:anEq
258 action:@selector(selectEQPreset:)
259 keyEquivalent:@""] autorelease];
260 [eqItem setTag:eqTag];
262 [submenu addItem:eqItem];
265 [[submenu itemAtIndex:([currentRemote currentEQPresetIndex] - 1)] setState:NSOnState];
268 - (BOOL)songIsPlaying
270 return ( ! ([[currentRemote currentSongUniqueIdentifier] isEqualToString:@"0-0"]) );
273 - (BOOL)radioIsPlaying
275 return ( [currentRemote currentPlaylistClass] == ITMTRemotePlayerRadioPlaylist );
280 return ( ! [[currentRemote currentSongUniqueIdentifier] isEqualToString:_latestSongIdentifier] );
283 - (NSString *)latestSongIdentifier
285 return _latestSongIdentifier;
288 - (void)setLatestSongIdentifier:(NSString *)newIdentifier
290 [_latestSongIdentifier autorelease];
291 _latestSongIdentifier = [newIdentifier copy];
295 //Recreate the status item menu
298 NSArray *myMenu = [df arrayForKey:@"menu"];
299 int playlist = [currentRemote currentPlaylistIndex];
302 if ([currentRemote playerRunningState] == ITMTRemotePlayerNotRunning) {
307 lastPlaylistIndex = -1;
310 menu = [[NSMenu alloc] initWithTitle:@""];
314 upcomingSongsItem = nil;
315 [upcomingSongsMenu release];
316 upcomingSongsMenu = nil;
319 [ratingItem setSubmenu:nil];
323 [playlistMenu release];
330 //Build the custom menu
331 for (i = 0; i < [myMenu count]; i++) {
332 NSString *item = [myMenu objectAtIndex:i];
333 if ([item isEqualToString:@"Play/Pause"]) {
334 KeyCombo *tempCombo = [df keyComboForKey:@"PlayPause"];
335 playPauseItem = [menu addItemWithTitle:@"Play"
336 action:@selector(playPause:)
340 [self setKeyEquivalentForCode:[tempCombo keyCode]
341 andModifiers:[tempCombo modifiers] onItem:playPauseItem];
344 } else if ([item isEqualToString:@"Next Track"]) {
345 KeyCombo *tempCombo = [df keyComboForKey:@"NextTrack"];
346 NSMenuItem *nextTrack = [menu addItemWithTitle:@"Next Track"
347 action:@selector(nextSong:)
351 [self setKeyEquivalentForCode:[tempCombo keyCode]
352 andModifiers:[tempCombo modifiers] onItem:nextTrack];
355 } else if ([item isEqualToString:@"Previous Track"]) {
356 KeyCombo *tempCombo = [df keyComboForKey:@"PrevTrack"];
357 NSMenuItem *prevTrack = [menu addItemWithTitle:@"Previous Track"
358 action:@selector(prevSong:)
362 [self setKeyEquivalentForCode:[tempCombo keyCode]
363 andModifiers:[tempCombo modifiers] onItem:prevTrack];
366 } else if ([item isEqualToString:@"Fast Forward"]) {
367 [menu addItemWithTitle:@"Fast Forward"
368 action:@selector(fastForward:)
370 } else if ([item isEqualToString:@"Rewind"]) {
371 [menu addItemWithTitle:@"Rewind"
372 action:@selector(rewind:)
374 } else if ([item isEqualToString:@"Show Player"]) {
375 [menu addItemWithTitle:[NSString stringWithFormat:@"Show %@", [currentRemote playerSimpleName]]
376 action:@selector(showPlayer:)
378 } else if ([item isEqualToString:@"Upcoming Songs"]) {
379 upcomingSongsItem = [menu addItemWithTitle:@"Upcoming Songs"
382 upcomingSongsMenu = [[NSMenu alloc] initWithTitle:@""];
383 [upcomingSongsItem setSubmenu:upcomingSongsMenu];
384 [upcomingSongsItem setEnabled:NO];
385 } else if ([item isEqualToString:@"Playlists"]) {
386 playlistItem = [menu addItemWithTitle:@"Playlists"
389 } else if ([item isEqualToString:@"EQ Presets"]) {
390 eqItem = [menu addItemWithTitle:@"EQ Presets"
393 } else if ([item isEqualToString:@"Preferences…"]) {
394 [menu addItemWithTitle:@"Preferences…"
395 action:@selector(showPreferences:)
397 } else if ([item isEqualToString:@"Quit"]) {
398 [menu addItemWithTitle:@"Quit"
399 action:@selector(quitMenuTunes:)
401 } else if ([item isEqualToString:@"Current Track Info"]) {
402 trackInfoIndex = [menu numberOfItems];
403 [menu addItemWithTitle:@"No Song"
406 } else if ([item isEqualToString:@"Song Rating"]) {
407 ratingItem = [menu addItemWithTitle:@"Song Rating"
410 [ratingItem setSubmenu:ratingMenu];
411 } else if ([item isEqualToString:@"<separator>"]) {
412 [menu addItem:[NSMenuItem separatorItem]];
417 [self rebuildPlaylistMenu];
421 [self rebuildEQPresetsMenu];
424 isPlayingRadio = ([currentRemote classOfPlaylistAtIndex:playlist] == ITMTRemotePlayerRadioPlaylist);
426 if (upcomingSongsItem) {
427 [self rebuildUpcomingSongsMenu];
431 if (isPlayingRadio || !playlist) {
432 [ratingItem setEnabled:NO];
434 int currentSongRating = ([currentRemote currentSongRating] * 5);
435 [[ratingMenu itemAtIndex:lastSongRating] setState:NSOffState];
436 lastSongRating = currentSongRating;
437 [[ratingMenu itemAtIndex:lastSongRating] setState:NSOnState];
438 [ratingItem setEnabled:YES];
442 //Set the new unique song identifier
443 lastSongIdentifier = [[currentRemote currentSongUniqueIdentifier] retain];
445 //If we're in a playlist or radio mode
446 if ( ![lastSongIdentifier isEqualToString:@"0-0"] && (trackInfoIndex > -1) ) {
449 if ( (i = [menu indexOfItemWithTitle:@"No Song"]) ) {
451 [menu removeItemAtIndex:i];
452 [menu insertItemWithTitle:@"Now Playing" action:NULL keyEquivalent:@"" atIndex:i];
456 title = [currentRemote currentSongTitle];
458 if (!isPlayingRadio) {
459 if ([df boolForKey:@"showTime"]) {
460 NSString *length = [currentRemote currentSongLength];
461 char character = [length characterAtIndex:0];
462 if ( (character > '0') && (character < '9') ) {
463 [menu insertItemWithTitle:[NSString stringWithFormat:@" %@", [currentRemote currentSongLength]] action:nil keyEquivalent:@"" atIndex:trackInfoIndex + 1];
467 if ([df boolForKey:@"showRating"]) {
468 if (title) { //Check to see if there's a song playing
469 [menu insertItemWithTitle:[NSString stringWithFormat:@" %@", [[ratingMenu itemAtIndex:[currentRemote currentSongRating] * 5] title]] action:nil keyEquivalent:@"" atIndex:trackInfoIndex + 1];
473 if ([df boolForKey:@"showArtist"]) {
474 NSString *artist = [currentRemote currentSongArtist];
475 if ([artist length] > 0) {
476 [menu insertItemWithTitle:[NSString stringWithFormat:@" %@", artist] action:nil keyEquivalent:@"" atIndex:trackInfoIndex + 1];
480 if ([df boolForKey:@"showNumber"]) {
481 int track = [currentRemote currentSongTrack];
482 int total = [currentRemote currentAlbumTrackCount];
484 [menu insertItemWithTitle:[NSString stringWithFormat:@" Track %i of %i", track, total] action:nil keyEquivalent:@"" atIndex:trackInfoIndex + 1];
488 if ([df boolForKey:@"showAlbum"]) {
489 NSString *album = [currentRemote currentSongAlbum];
490 if ([album length] > 0) {
491 [menu insertItemWithTitle:[NSString stringWithFormat:@" %@", album] action:nil keyEquivalent:@"" atIndex:trackInfoIndex + 1];
496 if ([title length] > 0) {
497 [menu insertItemWithTitle:[NSString stringWithFormat:@" %@", title] action:nil keyEquivalent:@"" atIndex:trackInfoIndex + 1];
501 [statusItem setMenu:menu];
508 //Build a menu with the list of all available EQ presets
509 - (void)rebuildEQPresetsMenu
511 NSArray *eqPresets = [currentRemote eqPresets];
514 [eqMenu autorelease];
515 eqMenu = [[NSMenu alloc] initWithTitle:@""];
517 for (i = 0; i < [eqPresets count]; i++) {
519 NSMenuItem *tempItem;
520 if ( ( name = [eqPresets objectAtIndex:i] ) ) {
521 tempItem = [[NSMenuItem alloc] initWithTitle:name action:@selector(selectEQPreset:) keyEquivalent:@""];
523 [eqMenu addItem:tempItem];
524 [tempItem autorelease];
528 [eqItem setSubmenu:eqMenu];
529 [eqItem setEnabled:YES];
530 [[eqMenu itemAtIndex:([currentRemote currentEQPresetIndex] - 1)] setState:NSOnState];
537 if ( ( [self songChanged] ) ||
538 ( ([self radioIsPlaying]) && (latestPlaylistClass != ITMTRemotePlayerRadioPlaylist) ) ||
539 ( (! [self radioIsPlaying]) && (latestPlaylistClass == ITMTRemotePlayerRadioPlaylist) ) ) {
540 [statusItem setMenu:[self menu]];
541 [self setLatestSongIdentifier:[currentRemote currentSongUniqueIdentifier]];
542 latestPlaylistClass = [currentRemote currentPlaylistClass];
544 if ( [df boolForKey:@"showSongInfoOnChange"] ) {
545 [self showCurrentTrackInfo];
549 //Update Play/Pause menu item
551 if ([currentRemote playerPlayingState] == ITMTRemotePlayerPlaying) {
552 [playPauseItem setTitle:@"Pause"];
554 [playPauseItem setTitle:@"Play"];
567 - (void)selectSong:(id)sender
569 [currentRemote switchToSongAtIndex:[[sender representedObject] intValue]];
572 - (void)selectPlaylist:(id)sender
574 int playlist = [sender tag];
575 [currentRemote switchToPlaylistAtIndex:playlist];
578 - (void)selectEQPreset:(id)sender
580 int curSet = [currentRemote currentEQPresetIndex];
581 int item = [sender tag];
583 [currentRemote switchToEQAtIndex:item];
584 [[eqMenu itemAtIndex:curSet - 1] setState:NSOffState];
585 [[eqMenu itemAtIndex:item] setState:NSOnState];
589 - (void)selectSongRating:(id)sender
591 int newRating = [sender tag];
592 // [[ratingMenu itemAtIndex:lastSongRating] setState:NSOffState];
593 [sender setState:NSOnState];
594 [currentRemote setCurrentSongRating:(float)newRating / 100.0];
595 lastSongRating = newRating / 20;
599 - (void)playPause:(id)sender
601 ITMTRemotePlayerPlayingState state = [currentRemote playerPlayingState];
603 if (state == ITMTRemotePlayerPlaying) {
604 [currentRemote pause];
605 [playPauseItem setTitle:@"Play"];
606 } else if ((state == ITMTRemotePlayerForwarding) || (state == ITMTRemotePlayerRewinding)) {
607 [currentRemote pause];
608 [currentRemote play];
610 [currentRemote play];
611 [playPauseItem setTitle:@"Pause"];
615 - (void)nextSong:(id)sender
617 [currentRemote goToNextSong];
620 - (void)prevSong:(id)sender
622 [currentRemote goToPreviousSong];
625 - (void)fastForward:(id)sender
627 [currentRemote forward];
628 [playPauseItem setTitle:@"Play"];
631 - (void)rewind:(id)sender
633 [currentRemote rewind];
634 [playPauseItem setTitle:@"Play"];
640 - (void)quitMenuTunes:(id)sender
642 [NSApp terminate:self];
645 - (void)showPlayer:(id)sender
647 if ( ( playerRunningState == ITMTRemotePlayerRunning) ) {
648 [currentRemote showPrimaryInterface];
650 if (![[NSWorkspace sharedWorkspace] launchApplication:[currentRemote playerFullName]]) {
651 NSLog(@"Error Launching Player");
656 - (void)showPreferences:(id)sender
658 [[PreferencesController sharedPrefs] setController:self];
659 [[PreferencesController sharedPrefs] showPrefsWindow:self];
662 - (void)closePreferences
664 if ( ( playerRunningState == ITMTRemotePlayerRunning) ) {
669 - (ITMTRemote *)currentRemote
671 return currentRemote;
682 [[HotKeyCenter sharedCenter] removeHotKey:@"PlayPause"];
683 [[HotKeyCenter sharedCenter] removeHotKey:@"NextTrack"];
684 [[HotKeyCenter sharedCenter] removeHotKey:@"PrevTrack"];
685 [[HotKeyCenter sharedCenter] removeHotKey:@"TrackInfo"];
686 [[HotKeyCenter sharedCenter] removeHotKey:@"UpcomingSongs"];
687 [[HotKeyCenter sharedCenter] removeHotKey:@"ToggleLoop"];
688 [[HotKeyCenter sharedCenter] removeHotKey:@"ToggleShuffle"];
689 [[HotKeyCenter sharedCenter] removeHotKey:@"IncrementVolume"];
690 [[HotKeyCenter sharedCenter] removeHotKey:@"DecrementVolume"];
691 [[HotKeyCenter sharedCenter] removeHotKey:@"IncrementRating"];
692 [[HotKeyCenter sharedCenter] removeHotKey:@"DecrementRating"];
697 if ([df objectForKey:@"PlayPause"] != nil) {
698 [[HotKeyCenter sharedCenter] addHotKey:@"PlayPause"
699 combo:[df keyComboForKey:@"PlayPause"]
700 target:self action:@selector(playPause:)];
703 if ([df objectForKey:@"NextTrack"] != nil) {
704 [[HotKeyCenter sharedCenter] addHotKey:@"NextTrack"
705 combo:[df keyComboForKey:@"NextTrack"]
706 target:self action:@selector(nextSong:)];
709 if ([df objectForKey:@"PrevTrack"] != nil) {
710 [[HotKeyCenter sharedCenter] addHotKey:@"PrevTrack"
711 combo:[df keyComboForKey:@"PrevTrack"]
712 target:self action:@selector(prevSong:)];
715 if ([df objectForKey:@"TrackInfo"] != nil) {
716 [[HotKeyCenter sharedCenter] addHotKey:@"TrackInfo"
717 combo:[df keyComboForKey:@"TrackInfo"]
718 target:self action:@selector(showCurrentTrackInfo)];
721 if ([df objectForKey:@"UpcomingSongs"] != nil) {
722 [[HotKeyCenter sharedCenter] addHotKey:@"UpcomingSongs"
723 combo:[df keyComboForKey:@"UpcomingSongs"]
724 target:self action:@selector(showUpcomingSongs)];
727 if ([df objectForKey:@"ToggleLoop"] != nil) {
728 [[HotKeyCenter sharedCenter] addHotKey:@"ToggleLoop"
729 combo:[df keyComboForKey:@"ToggleLoop"]
730 target:self action:NULL/*Set this to something*/];
733 if ([df objectForKey:@"ToggleShuffle"] != nil) {
734 [[HotKeyCenter sharedCenter] addHotKey:@"ToggleShuffle"
735 combo:[df keyComboForKey:@"ToggleShuffle"]
736 target:self action:NULL/*Set this to something*/];
739 if ([df objectForKey:@"IncrementVolume"] != nil) {
740 [[HotKeyCenter sharedCenter] addHotKey:@"IncrementVolume"
741 combo:[df keyComboForKey:@"IncrementVolume"]
742 target:self action:NULL/*Set this to something*/];
745 if ([df objectForKey:@"DecrementVolume"] != nil) {
746 [[HotKeyCenter sharedCenter] addHotKey:@"DecrementVolume"
747 combo:[df keyComboForKey:@"DecrementVolume"]
748 target:self action:NULL/*Set this to something*/];
751 if ([df objectForKey:@"IncrementRating"] != nil) {
752 [[HotKeyCenter sharedCenter] addHotKey:@"IncrementRating"
753 combo:[df keyComboForKey:@"IncrementRating"]
754 target:self action:NULL/*Set this to something*/];
757 if ([df objectForKey:@"DecrementRating"] != nil) {
758 [[HotKeyCenter sharedCenter] addHotKey:@"DecrementRating"
759 combo:[df keyComboForKey:@"DecrementRating"]
760 target:self action:NULL/*Set this to something*/];
764 - (void)showCurrentTrackInfo
766 NSString *title = [currentRemote currentSongTitle];
769 NSString *album = nil;
770 NSString *artist = nil;
771 NSString *time = nil;
776 if ( [df boolForKey:@"showAlbum"] ) {
777 album = [currentRemote currentSongAlbum];
780 if ( [df boolForKey:@"showArtist"] ) {
781 artist = [currentRemote currentSongArtist];
784 if ( [df boolForKey:@"showTime"] ) {
785 time = [currentRemote currentSongLength];
788 if ( [df boolForKey:@"showNumber"] ) {
789 trackNumber = [currentRemote currentSongTrack];
790 trackTotal = [currentRemote currentAlbumTrackCount];
793 if ( [df boolForKey:@"showRating"] ) {
794 rating = ( [currentRemote currentSongRating] * 5 );
797 [statusWindowController showSongWindowWithTitle:title
801 trackNumber:trackNumber
802 trackTotal:trackTotal
805 title = @"No song is playing.";
806 [statusWindowController showSongWindowWithTitle:title
816 - (void)showUpcomingSongs
818 int curPlaylist = [currentRemote currentPlaylistIndex];
819 int numSongs = [currentRemote numberOfSongsInPlaylistAtIndex:curPlaylist];
822 NSMutableArray *songList = [NSMutableArray arrayWithCapacity:5];
823 int numSongsInAdvance = [df integerForKey:@"SongsInAdvance"];
824 int curTrack = [currentRemote currentSongIndex];
827 for (i = curTrack + 1; i <= curTrack + numSongsInAdvance; i++) {
829 [songList addObject:[currentRemote songTitleAtIndex:i]];
833 [statusWindowController showUpcomingSongsWithTitles:songList];
836 [statusWindowController showUpcomingSongsWithTitles:[NSArray arrayWithObject:@"No upcoming songs."]];
840 - (void)setKeyEquivalentForCode:(short)code andModifiers:(long)modifiers
841 onItem:(NSMenuItem *)item
843 unichar charcode = 'a';
845 long cocoaModifiers = 0;
846 static long carbonToCocoa[6][2] =
848 { cmdKey, NSCommandKeyMask },
849 { optionKey, NSAlternateKeyMask },
850 { controlKey, NSControlKeyMask },
851 { shiftKey, NSShiftKeyMask },
854 for (i = 0; i < 6; i++) {
855 if (modifiers & carbonToCocoa[i][0]) {
856 cocoaModifiers += carbonToCocoa[i][1];
859 [item setKeyEquivalentModifierMask:cocoaModifiers];
861 //Missing key combos for some keys. Must find them later.
875 // Haven't tested this, though it should work.
877 [[NSString stringWithString:@"Space"] getCharacters:&buffer];
879 /*MenuRef menuRef = _NSGetCarbonMenu([item menu]);
880 NSLog(@"%@", menuRef);
881 SetMenuItemCommandKey(menuRef, 0, NO, 49);
882 SetMenuItemModifiers(menuRef, 0, kMenuNoCommandModifier);
883 SetMenuItemKeyGlyph(menuRef, 0, kMenuBlankGlyph);
890 charcode = NSDeleteFunctionKey;
906 charcode = NSF5FunctionKey;
910 charcode = NSF6FunctionKey;
914 charcode = NSF7FunctionKey;
918 charcode = NSF3FunctionKey;
922 charcode = NSF8FunctionKey;
926 charcode = NSF9FunctionKey;
930 charcode = NSF11FunctionKey;
934 charcode = NSF3FunctionKey;
938 charcode = NSF14FunctionKey;
942 charcode = NSF10FunctionKey;
946 charcode = NSF12FunctionKey;
950 charcode = NSF13FunctionKey;
954 charcode = NSInsertFunctionKey;
958 charcode = NSHomeFunctionKey;
962 charcode = NSPageUpFunctionKey;
966 charcode = NSDeleteFunctionKey;
970 charcode = NSF4FunctionKey;
974 charcode = NSEndFunctionKey;
978 charcode = NSF2FunctionKey;
982 charcode = NSPageDownFunctionKey;
986 charcode = NSF1FunctionKey;
990 charcode = NSLeftArrowFunctionKey;
994 charcode = NSRightArrowFunctionKey;
998 charcode = NSDownArrowFunctionKey;
1002 charcode = NSUpArrowFunctionKey;
1006 if (charcode == 'a') {
1007 unsigned long state;
1012 kchr = (Ptr) GetScriptVariable(smCurrentScript, smKCHRCache);
1013 keyTrans = KeyTranslate(kchr, code, &state);
1014 charCode = keyTrans;
1015 [item setKeyEquivalent:[NSString stringWithCString:&charCode length:1]];
1016 } else if (charcode != 'b') {
1017 [item setKeyEquivalent:[NSString stringWithCharacters:&charcode length:1]];
1021 /*************************************************************************/
1023 #pragma mark WORKSPACE NOTIFICATION HANDLERS
1024 /*************************************************************************/
1026 - (void)applicationLaunched:(NSNotification *)note
1028 if (!note || [[[note userInfo] objectForKey:@"NSApplicationName"] isEqualToString:[currentRemote playerFullName]]) {
1029 [NSThread detachNewThreadSelector:@selector(startTimerInNewThread) toTarget:self withObject:nil];
1030 [self setupHotKeys];
1031 playerRunningState = ITMTRemotePlayerRunning;
1035 - (void)applicationTerminated:(NSNotification *)note
1037 if (!note || [[[note userInfo] objectForKey:@"NSApplicationName"] isEqualToString:[currentRemote playerFullName]]) {
1039 NSMenu *notRunningMenu = [[NSMenu alloc] initWithTitle:@""];
1040 [notRunningMenu addItemWithTitle:[NSString stringWithFormat:@"Open %@", [currentRemote playerSimpleName]] action:@selector(showPlayer:) keyEquivalent:@""];
1041 [notRunningMenu addItem:[NSMenuItem separatorItem]];
1042 [notRunningMenu addItemWithTitle:@"Preferences" action:@selector(showPreferences:) keyEquivalent:@""];
1043 [notRunningMenu addItemWithTitle:@"Quit" action:@selector(quitMenuTunes:) keyEquivalent:@""];
1045 [refreshTimer invalidate];
1046 [refreshTimer release];
1048 [self clearHotKeys];
1049 playerRunningState = ITMTRemotePlayerNotRunning;
1051 [statusItem setMenu:[self menuForNoPlayer]];
1056 /*************************************************************************/
1058 #pragma mark NSApplication DELEGATE METHODS
1059 /*************************************************************************/
1061 - (void)applicationWillTerminate:(NSNotification *)note
1063 [self clearHotKeys];
1064 [[NSStatusBar systemStatusBar] removeStatusItem:statusItem];
1068 /*************************************************************************/
1070 #pragma mark DEALLOCATION METHOD
1071 /*************************************************************************/
1076 [refreshTimer invalidate];
1077 [refreshTimer release];
1081 [currentRemote halt];
1082 [statusItem release];
1083 [statusWindowController release];