1 #import "MainController.h"
2 #import "PreferencesController.h"
3 #import "HotKeyCenter.h"
4 #import "StatusWindow.h"
6 @interface MainController(Private)
7 - (ITMTRemote *)loadRemote;
8 - (void)rebuildUpcomingSongsMenu;
9 - (void)rebuildPlaylistMenu;
10 - (void)rebuildEQPresetsMenu;
11 - (void)updateRatingMenu;
14 - (void)setKeyEquivalentForCode:(short)code andModifiers:(long)modifiers
15 onItem:(NSMenuItem *)item;
19 @implementation MainController
21 /*************************************************************************/
23 #pragma mark INITIALIZATION/DEALLOCATION METHODS
24 /*************************************************************************/
28 if ( ( self = [super init] ) ) {
29 remoteArray = [[NSMutableArray alloc] initWithCapacity:1];
30 statusWindow = [StatusWindow sharedWindow];
38 [refreshTimer invalidate];
39 [refreshTimer release];
48 - (void)applicationDidFinishLaunching:(NSNotification *)note
50 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
51 currentRemote = [self loadRemote];
53 //Setup for notification of the remote player launching or quitting
54 [[[NSWorkspace sharedWorkspace] notificationCenter]
56 selector:@selector(applicationTerminated:)
57 name:NSWorkspaceDidTerminateApplicationNotification
60 [[[NSWorkspace sharedWorkspace] notificationCenter]
62 selector:@selector(applicationLaunched:)
63 name:NSWorkspaceDidLaunchApplicationNotification
66 if ( ! [defaults objectForKey:@"menu"] ) { // If this is nil, defaults have never been registered.
67 [[PreferencesController sharedPrefs] registerDefaults];
70 statusItem = [[ITStatusItem alloc]
71 initWithStatusBar:[NSStatusBar systemStatusBar]
72 withLength:NSSquareStatusItemLength];
74 menu = [[NSMenu alloc] initWithTitle:@""];
75 if ( ( [currentRemote playerRunningState] == ITMTRemotePlayerRunning ) ) {
76 [self applicationLaunched:nil];
78 [self applicationTerminated:nil];
81 [statusItem setImage:[NSImage imageNamed:@"menu"]];
82 [statusItem setAlternateImage:[NSImage imageNamed:@"selected_image"]];
83 // Below line of code is for creating builds for Beta Testers
84 // [statusItem setToolTip:@[NSString stringWithFormat:@"This Nontransferable Beta (Built on %s) of iThink Software's MenuTunes is Registered to: Beta Tester (betatester@somedomain.com).",__DATE__]];
87 - (void)applicationWillTerminate:(NSNotification *)note
90 [[NSStatusBar systemStatusBar] removeStatusItem:statusItem];
93 - (ITMTRemote *)loadRemote
95 NSString *folderPath = [[NSBundle mainBundle] builtInPlugInsPath];
98 NSArray *bundlePathList = [NSBundle pathsForResourcesOfType:@"remote" inDirectory:folderPath];
99 NSEnumerator *enumerator = [bundlePathList objectEnumerator];
100 NSString *bundlePath;
102 while ( (bundlePath = [enumerator nextObject]) ) {
103 NSBundle* remoteBundle = [NSBundle bundleWithPath:bundlePath];
106 Class remoteClass = [remoteBundle principalClass];
108 if ([remoteClass conformsToProtocol:@protocol(ITMTRemote)] &&
109 [remoteClass isKindOfClass:[NSObject class]]) {
111 id remote = [remoteClass remote];
112 [remoteArray addObject:remote];
117 // if ( [remoteArray count] > 0 ) { // UNCOMMENT WHEN WE HAVE > 1 PLUGIN
118 // if ( [remoteArray count] > 1 ) {
119 // [remoteArray sortUsingSelector:@selector(sortAlpha:)];
121 // [self loadModuleAccessUI]; //Comment out this line to disable remote visibility
124 // NSLog(@"%@", [remoteArray objectAtIndex:0]); //DEBUG
125 return [remoteArray objectAtIndex:0];
131 - (void)applicationLaunched:(NSNotification *)note
133 if (!note || [[[note userInfo] objectForKey:@"NSApplicationName"] isEqualToString:[currentRemote playerFullName]]) {
134 [currentRemote begin];
136 [NSThread detachNewThreadSelector:@selector(startTimerInNewThread) toTarget:self withObject:nil];
138 isAppRunning = ITMTRemotePlayerRunning;
142 - (void)applicationTerminated:(NSNotification *)note
144 if (!note || [[[note userInfo] objectForKey:@"NSApplicationName"] isEqualToString:[currentRemote playerFullName]]) {
145 NSMenu *notRunningMenu = [[NSMenu alloc] initWithTitle:@""];
146 [notRunningMenu addItemWithTitle:[NSString stringWithFormat:@"Open %@", [currentRemote playerSimpleName]] action:@selector(showPlayer:) keyEquivalent:@""];
147 [notRunningMenu addItem:[NSMenuItem separatorItem]];
148 [notRunningMenu addItemWithTitle:@"Preferences..." action:@selector(showPreferences:) keyEquivalent:@""];
149 [notRunningMenu addItemWithTitle:@"Quit" action:@selector(quitMenuTunes:) keyEquivalent:@""];
150 [statusItem setMenu:[notRunningMenu autorelease]];
152 [currentRemote halt];
153 [refreshTimer invalidate];
154 [refreshTimer release];
157 isAppRunning = ITMTRemotePlayerNotRunning;
161 /*************************************************************************/
163 #pragma mark INSTANCE METHODS
164 /*************************************************************************/
166 - (void)startTimerInNewThread
168 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
169 NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
170 refreshTimer = [[NSTimer scheduledTimerWithTimeInterval:0.5
172 selector:@selector(timerUpdate)
174 repeats:YES] retain];
179 //Recreate the status item menu
182 NSUserDefaults *defaults;
186 unichar fullstar = 0x2605;
187 unichar emptystar = 0x2606;
188 NSString *fullStarChar;
189 NSString *emptyStarChar;
191 if ([currentRemote playerRunningState] == ITMTRemotePlayerNotRunning) {
195 defaults = [NSUserDefaults standardUserDefaults];
196 myMenu = [defaults arrayForKey:@"menu"];
197 playlist = [currentRemote currentPlaylistIndex];
198 fullStarChar = [NSString stringWithCharacters:&fullstar length:1];
199 emptyStarChar = [NSString stringWithCharacters:&emptystar length:1];
202 lastPlaylistIndex = -1;
205 menu = [[NSMenu alloc] initWithTitle:@""];
207 //Release the old submenus
209 upcomingSongsItem = nil;
210 [upcomingSongsMenu release];
211 upcomingSongsMenu = nil;
213 [playlistMenu release];
219 [ratingItem setSubmenu:nil];
220 [ratingItem release];
224 //Build the rating menu
225 [ratingMenu release];
226 ratingMenu = [[NSMenu alloc] initWithTitle:@""];
227 [[ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", emptyStarChar, emptyStarChar, emptyStarChar, emptyStarChar, emptyStarChar] action:@selector(selectSongRating:) keyEquivalent:@""] setTag:0];
228 [[ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", fullStarChar, emptyStarChar, emptyStarChar, emptyStarChar, emptyStarChar] action:@selector(selectSongRating:) keyEquivalent:@""] setTag:20];
229 [[ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", fullStarChar, fullStarChar, emptyStarChar, emptyStarChar, emptyStarChar] action:@selector(selectSongRating:) keyEquivalent:@""] setTag:40];
230 [[ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", fullStarChar, fullStarChar, fullStarChar, emptyStarChar, emptyStarChar] action:@selector(selectSongRating:) keyEquivalent:@""] setTag:60];
231 [[ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", fullStarChar, fullStarChar, fullStarChar, fullStarChar, emptyStarChar] action:@selector(selectSongRating:) keyEquivalent:@""] setTag:80];
232 [[ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", fullStarChar, fullStarChar, fullStarChar, fullStarChar, fullStarChar] action:@selector(selectSongRating:) keyEquivalent:@""] setTag:100];
234 //Build the custom menu
235 for (i = 0; i < [myMenu count]; i++) {
236 NSString *item = [myMenu objectAtIndex:i];
237 if ([item isEqualToString:@"Play/Pause"]) {
238 KeyCombo *tempCombo = [[NSUserDefaults standardUserDefaults] keyComboForKey:@"PlayPause"];
239 playPauseItem = [menu addItemWithTitle:@"Play"
240 action:@selector(playPause:)
244 [self setKeyEquivalentForCode:[tempCombo keyCode]
245 andModifiers:[tempCombo modifiers] onItem:playPauseItem];
248 } else if ([item isEqualToString:@"Next Track"]) {
249 KeyCombo *tempCombo = [[NSUserDefaults standardUserDefaults] keyComboForKey:@"NextTrack"];
250 NSMenuItem *nextTrack = [menu addItemWithTitle:@"Next Track"
251 action:@selector(nextSong:)
255 [self setKeyEquivalentForCode:[tempCombo keyCode]
256 andModifiers:[tempCombo modifiers] onItem:nextTrack];
259 } else if ([item isEqualToString:@"Previous Track"]) {
260 KeyCombo *tempCombo = [[NSUserDefaults standardUserDefaults] keyComboForKey:@"PrevTrack"];
261 NSMenuItem *prevTrack = [menu addItemWithTitle:@"Previous Track"
262 action:@selector(prevSong:)
266 [self setKeyEquivalentForCode:[tempCombo keyCode]
267 andModifiers:[tempCombo modifiers] onItem:prevTrack];
270 } else if ([item isEqualToString:@"Fast Forward"]) {
271 [menu addItemWithTitle:@"Fast Forward"
272 action:@selector(fastForward:)
274 } else if ([item isEqualToString:@"Rewind"]) {
275 [menu addItemWithTitle:@"Rewind"
276 action:@selector(rewind:)
278 } else if ([item isEqualToString:@"Show Player"]) {
279 [menu addItemWithTitle:[NSString stringWithFormat:@"Show %@", [currentRemote playerSimpleName]]
280 action:@selector(showPlayer:)
282 } else if ([item isEqualToString:@"Upcoming Songs"]) {
283 upcomingSongsItem = [menu addItemWithTitle:@"Upcoming Songs"
286 upcomingSongsMenu = [[NSMenu alloc] initWithTitle:@""];
287 [upcomingSongsItem setSubmenu:upcomingSongsMenu];
288 [upcomingSongsItem setEnabled:NO];
289 } else if ([item isEqualToString:@"Playlists"]) {
290 playlistItem = [menu addItemWithTitle:@"Playlists"
293 } else if ([item isEqualToString:@"EQ Presets"]) {
294 eqItem = [menu addItemWithTitle:@"EQ Presets"
297 } else if ([item isEqualToString:@"PreferencesÉ"]) {
298 [menu addItemWithTitle:@"PreferencesÉ"
299 action:@selector(showPreferences:)
301 } else if ([item isEqualToString:@"Quit"]) {
302 [menu addItemWithTitle:@"Quit"
303 action:@selector(quitMenuTunes:)
305 } else if ([item isEqualToString:@"Current Track Info"]) {
306 trackInfoIndex = [menu numberOfItems];
307 [menu addItemWithTitle:@"No Song"
310 } else if ([item isEqualToString:@"Song Rating"]) {
311 ratingItem = [[menu addItemWithTitle:@"Song Rating"
313 keyEquivalent:@""] retain];
314 [ratingItem setSubmenu:ratingMenu];
315 } else if ([item isEqualToString:@"<separator>"]) {
316 [menu addItem:[NSMenuItem separatorItem]];
321 [self rebuildPlaylistMenu];
325 [self rebuildEQPresetsMenu];
328 isPlayingRadio = ([currentRemote currentPlaylistClass] == ITMTRemotePlayerRadioPlaylist);
330 if (upcomingSongsItem) {
331 [self rebuildUpcomingSongsMenu];
335 if (isPlayingRadio || !playlist) {
336 [ratingItem setEnabled:NO];
338 int currentSongRating = ([currentRemote currentSongRating] * 5);
339 lastSongRating = currentSongRating;
340 [[ratingMenu itemAtIndex:lastSongRating] setState:NSOnState];
341 [ratingItem setEnabled:YES];
345 //Set the new unique song identifier
346 lastSongIdentifier = [[currentRemote currentSongUniqueIdentifier] retain];
348 //If we're in a playlist or radio mode
349 if ( ![lastSongIdentifier isEqualToString:@"0-0"] && (trackInfoIndex > -1) ) {
352 if ( (i = [menu indexOfItemWithTitle:@"No Song"]) ) {
354 [menu removeItemAtIndex:i];
355 [menu insertItemWithTitle:@"Now Playing" action:NULL keyEquivalent:@"" atIndex:i];
359 title = [currentRemote currentSongTitle];
361 if (!isPlayingRadio) {
362 if ([defaults boolForKey:@"showTime"]) {
363 NSString *length = [currentRemote currentSongLength];
364 char character = [length characterAtIndex:0];
365 if ( (character > '0') && (character < '9') ) {
366 [menu insertItemWithTitle:[NSString stringWithFormat:@" %@", [currentRemote currentSongLength]] action:nil keyEquivalent:@"" atIndex:trackInfoIndex + 1];
370 if ([defaults boolForKey:@"showTrackRating"]) {
371 if (title) { //Check to see if there's a song playing
372 [menu insertItemWithTitle:[NSString stringWithFormat:@" %@", [[ratingMenu itemAtIndex:[currentRemote currentSongRating] * 5] title]] action:nil keyEquivalent:@"" atIndex:trackInfoIndex + 1];
376 if ([defaults boolForKey:@"showArtist"]) {
377 NSString *artist = [currentRemote currentSongArtist];
378 if ([artist length] > 0) {
379 [menu insertItemWithTitle:[NSString stringWithFormat:@" %@", artist] action:nil keyEquivalent:@"" atIndex:trackInfoIndex + 1];
383 if ([defaults boolForKey:@"showTrackNumber"]) {
384 int track = [currentRemote currentSongTrack];
385 int total = [currentRemote currentAlbumTrackCount];
387 [menu insertItemWithTitle:[NSString stringWithFormat:@" Track %i of %i", track, total] action:nil keyEquivalent:@"" atIndex:trackInfoIndex + 1];
391 if ([defaults boolForKey:@"showAlbum"]) {
392 NSString *album = [currentRemote currentSongAlbum];
393 if ([album length] > 0) {
394 [menu insertItemWithTitle:[NSString stringWithFormat:@" %@", album] action:nil keyEquivalent:@"" atIndex:trackInfoIndex + 1];
399 if ([title length] > 0) {
400 [menu insertItemWithTitle:[NSString stringWithFormat:@" %@", title] action:nil keyEquivalent:@"" atIndex:trackInfoIndex + 1];
404 [statusItem setMenu:menu];
410 //Rebuild the upcoming songs submenu. Can be improved a lot.
411 - (void)rebuildUpcomingSongsMenu
413 int curIndex = [currentRemote currentPlaylistIndex];
414 int numSongs = [currentRemote numberOfSongsInPlaylistAtIndex:curIndex];
415 int numSongsInAdvance = [[NSUserDefaults standardUserDefaults] integerForKey:@"SongsInAdvance"];
417 if (!isPlayingRadio) {
419 int curTrack = [currentRemote currentSongIndex];
422 [upcomingSongsMenu release];
423 upcomingSongsMenu = [[NSMenu alloc] initWithTitle:@""];
424 [upcomingSongsItem setSubmenu:upcomingSongsMenu];
425 [upcomingSongsItem setEnabled:YES];
427 for (i = curTrack + 1; i <= curTrack + numSongsInAdvance; i++) {
429 NSString *curSong = [currentRemote songTitleAtIndex:i];
430 NSMenuItem *songItem;
431 songItem = [[NSMenuItem alloc] initWithTitle:curSong action:@selector(selectSong:) keyEquivalent:@""];
432 [songItem setRepresentedObject:[NSNumber numberWithInt:i]];
433 [upcomingSongsMenu addItem:songItem];
441 [upcomingSongsItem setSubmenu:nil];
442 [upcomingSongsItem setEnabled:NO];
446 - (void)rebuildPlaylistMenu
448 NSArray *playlists = [currentRemote playlists];
449 int i, currentPlaylist = [currentRemote currentPlaylistIndex];
451 [playlistMenu release];
452 playlistMenu = [[NSMenu alloc] initWithTitle:@""];
454 for (i = 0; i < [playlists count]; i++) {
455 NSString *playlistName = [playlists objectAtIndex:i];
456 NSMenuItem *tempItem;
457 tempItem = [[NSMenuItem alloc] initWithTitle:playlistName action:@selector(selectPlaylist:) keyEquivalent:@""];
458 [tempItem setTag:i + 1];
459 [playlistMenu addItem:tempItem];
462 [playlistItem setSubmenu:playlistMenu];
463 [playlistItem setEnabled:YES];
465 if (!isPlayingRadio && currentPlaylist) {
466 [[playlistMenu itemAtIndex:currentPlaylist - 1] setState:NSOnState];
470 //Build a menu with the list of all available EQ presets
471 - (void)rebuildEQPresetsMenu
473 NSArray *eqPresets = [currentRemote eqPresets];
476 [eqMenu autorelease];
477 eqMenu = [[NSMenu alloc] initWithTitle:@""];
479 for (i = 0; i < [eqPresets count]; i++) {
481 NSMenuItem *tempItem;
482 if ( ( name = [eqPresets objectAtIndex:i] ) ) {
483 tempItem = [[NSMenuItem alloc] initWithTitle:name action:@selector(selectEQPreset:) keyEquivalent:@""];
485 [eqMenu addItem:tempItem];
486 [tempItem autorelease];
490 [eqItem setSubmenu:eqMenu];
491 [eqItem setEnabled:YES];
492 [[eqMenu itemAtIndex:([currentRemote currentEQPresetIndex] - 1)] setState:NSOnState];
495 - (void)updateRatingMenu
497 int currentSongRating = ([currentRemote currentSongRating] * 5);
498 if ([currentRemote currentPlaylistIndex] && (currentSongRating != lastSongRating)) {
499 if ([currentRemote currentPlaylistClass] == ITMTRemotePlayerRadioPlaylist) {
502 [[ratingMenu itemAtIndex:lastSongRating] setState:NSOffState];
503 lastSongRating = currentSongRating;
504 [[ratingMenu itemAtIndex:lastSongRating] setState:NSOnState];
510 NSString *currentIdentifier = [currentRemote currentSongUniqueIdentifier];
511 if (![lastSongIdentifier isEqualToString:currentIdentifier] ||
512 (!isPlayingRadio && ([currentRemote currentPlaylistClass] == ITMTRemotePlayerRadioPlaylist))) {
515 // If we want to show the new track floater, do it here!
516 //[self showCurrentTrackInfo];
522 [self updateRatingMenu];
524 //Update Play/Pause menu item
528 // If we want to show the song played/paused, show it here!
531 if ([currentRemote playerPlayingState] == ITMTRemotePlayerPlaying) {
532 [playPauseItem setTitle:@"Pause"];
534 [playPauseItem setTitle:@"Play"];
545 - (void)selectSong:(id)sender
547 [currentRemote switchToSongAtIndex:[[sender representedObject] intValue]];
550 - (void)selectPlaylist:(id)sender
552 int playlist = [sender tag];
553 [currentRemote switchToPlaylistAtIndex:playlist];
556 - (void)selectEQPreset:(id)sender
558 int curSet = [currentRemote currentEQPresetIndex];
559 int item = [sender tag];
561 [currentRemote switchToEQAtIndex:item];
562 [[eqMenu itemAtIndex:curSet - 1] setState:NSOffState];
563 [[eqMenu itemAtIndex:item] setState:NSOnState];
566 - (void)selectSongRating:(id)sender
568 int newRating = [sender tag];
569 [[ratingMenu itemAtIndex:lastSongRating] setState:NSOffState];
570 [sender setState:NSOnState];
571 [currentRemote setCurrentSongRating:(float)newRating / 100.0];
572 lastSongRating = newRating / 20;
575 - (void)playPause:(id)sender
577 ITMTRemotePlayerPlayingState state = [currentRemote playerPlayingState];
579 if (state == ITMTRemotePlayerPlaying) {
580 [currentRemote pause];
581 [playPauseItem setTitle:@"Play"];
582 } else if ((state == ITMTRemotePlayerForwarding) || (state == ITMTRemotePlayerRewinding)) {
583 [currentRemote pause];
584 [currentRemote play];
586 [currentRemote play];
587 [playPauseItem setTitle:@"Pause"];
591 - (void)nextSong:(id)sender
593 [currentRemote goToNextSong];
596 - (void)prevSong:(id)sender
598 [currentRemote goToPreviousSong];
601 - (void)fastForward:(id)sender
603 [currentRemote forward];
604 [playPauseItem setTitle:@"Play"];
607 - (void)rewind:(id)sender
609 [currentRemote rewind];
610 [playPauseItem setTitle:@"Play"];
615 - (void)quitMenuTunes:(id)sender
617 [NSApp terminate:self];
620 - (void)showPlayer:(id)sender
622 if ( ( isAppRunning == ITMTRemotePlayerRunning) ) {
623 [currentRemote showPrimaryInterface];
625 if (![[NSWorkspace sharedWorkspace] launchApplication:[currentRemote playerFullName]]) {
626 NSLog(@"Error Launching Player");
631 - (void)showPreferences:(id)sender
633 [[PreferencesController sharedPrefs] setController:self];
634 [[PreferencesController sharedPrefs] showPrefsWindow:self];
637 - (void)closePreferences
639 if ( ( isAppRunning == ITMTRemotePlayerRunning) ) {
644 - (ITMTRemote *)currentRemote
646 return currentRemote;
657 [[HotKeyCenter sharedCenter] removeHotKey:@"PlayPause"];
658 [[HotKeyCenter sharedCenter] removeHotKey:@"NextTrack"];
659 [[HotKeyCenter sharedCenter] removeHotKey:@"PrevTrack"];
660 [[HotKeyCenter sharedCenter] removeHotKey:@"TrackInfo"];
661 [[HotKeyCenter sharedCenter] removeHotKey:@"UpcomingSongs"];
662 [[HotKeyCenter sharedCenter] removeHotKey:@"ToggleLoop"];
663 [[HotKeyCenter sharedCenter] removeHotKey:@"ToggleShuffle"];
664 [[HotKeyCenter sharedCenter] removeHotKey:@"IncrementVolume"];
665 [[HotKeyCenter sharedCenter] removeHotKey:@"DecrementVolume"];
666 [[HotKeyCenter sharedCenter] removeHotKey:@"IncrementRating"];
667 [[HotKeyCenter sharedCenter] removeHotKey:@"DecrementRating"];
672 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
674 if ([defaults objectForKey:@"PlayPause"] != nil) {
675 [[HotKeyCenter sharedCenter] addHotKey:@"PlayPause"
676 combo:[defaults keyComboForKey:@"PlayPause"]
677 target:self action:@selector(playPause:)];
680 if ([defaults objectForKey:@"NextTrack"] != nil) {
681 [[HotKeyCenter sharedCenter] addHotKey:@"NextTrack"
682 combo:[defaults keyComboForKey:@"NextTrack"]
683 target:self action:@selector(nextSong:)];
686 if ([defaults objectForKey:@"PrevTrack"] != nil) {
687 [[HotKeyCenter sharedCenter] addHotKey:@"PrevTrack"
688 combo:[defaults keyComboForKey:@"PrevTrack"]
689 target:self action:@selector(prevSong:)];
692 if ([defaults objectForKey:@"TrackInfo"] != nil) {
693 [[HotKeyCenter sharedCenter] addHotKey:@"TrackInfo"
694 combo:[defaults keyComboForKey:@"TrackInfo"]
695 target:self action:@selector(showCurrentTrackInfo)];
698 if ([defaults objectForKey:@"UpcomingSongs"] != nil) {
699 [[HotKeyCenter sharedCenter] addHotKey:@"UpcomingSongs"
700 combo:[defaults keyComboForKey:@"UpcomingSongs"]
701 target:self action:@selector(showUpcomingSongs)];
704 if ([defaults objectForKey:@"ToggleLoop"] != nil) {
705 [[HotKeyCenter sharedCenter] addHotKey:@"ToggleLoop"
706 combo:[defaults keyComboForKey:@"ToggleLoop"]
707 target:self action:@selector(showToggleLoopStatusWindow)];
710 if ([defaults objectForKey:@"ToggleShuffle"] != nil) {
711 [[HotKeyCenter sharedCenter] addHotKey:@"ToggleShuffle"
712 combo:[defaults keyComboForKey:@"ToggleShuffle"]
713 target:self action:@selector(showToggleShuffleStatusWindow)];
716 if ([defaults objectForKey:@"IncrementVolume"] != nil) {
717 [[HotKeyCenter sharedCenter] addHotKey:@"IncrementVolume"
718 combo:[defaults keyComboForKey:@"IncrementVolume"]
719 target:self action:@selector(showVolumeIncrementStatusWindow)];
722 if ([defaults objectForKey:@"DecrementVolume"] != nil) {
723 [[HotKeyCenter sharedCenter] addHotKey:@"DecrementVolume"
724 combo:[defaults keyComboForKey:@"DecrementVolume"]
725 target:self action:@selector(showVolumeDecrementStatusWindow)];
728 if ([defaults objectForKey:@"IncrementRating"] != nil) {
729 [[HotKeyCenter sharedCenter] addHotKey:@"IncrementRating"
730 combo:[defaults keyComboForKey:@"IncrementRating"]
731 target:self action:@selector(showRatingIncrementStatusWindow)];
734 if ([defaults objectForKey:@"DecrementRating"] != nil) {
735 [[HotKeyCenter sharedCenter] addHotKey:@"DecrementRating"
736 combo:[defaults keyComboForKey:@"DecrementRating"]
737 target:self action:@selector(showRatingDecrementStatusWindow)];
743 // Status Window Methods
747 - (void)showCurrentTrackInfo
749 NSString *trackName = [currentRemote currentSongTitle];
750 if (!statusWindow && [trackName length]) {
751 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
752 NSString *stringToShow = @"";
754 if ([defaults boolForKey:@"showName"]) {
755 if ([defaults boolForKey:@"showArtist"]) {
756 NSString *trackArtist = [currentRemote currentSongArtist];
757 trackName = [NSString stringWithFormat:@"%@ - %@", trackArtist, trackName];
759 stringToShow = [stringToShow stringByAppendingString:trackName];
760 stringToShow = [stringToShow stringByAppendingString:@"\n"];
763 if ([defaults boolForKey:@"showAlbum"]) {
764 NSString *trackAlbum = [currentRemote currentSongAlbum];
765 if ([trackAlbum length]) {
766 stringToShow = [stringToShow stringByAppendingString:trackAlbum];
767 stringToShow = [stringToShow stringByAppendingString:@"\n"];
771 if ([defaults boolForKey:@"showTime"]) {
772 NSString *trackTime = [currentRemote currentSongLength];
773 if ([trackTime length]) {
774 stringToShow = [NSString stringWithFormat:@"%@Total Time: %@\n", stringToShow, trackTime];
779 int trackTimeLeft = [[currentRemote currentSongRemaining] intValue];
780 int minutes = trackTimeLeft / 60, seconds = trackTimeLeft % 60;
782 stringToShow = [stringToShow stringByAppendingString:
783 [NSString stringWithFormat:@"Time Remaining: %i:0%i", minutes, seconds]];
785 stringToShow = [stringToShow stringByAppendingString:
786 [NSString stringWithFormat:@"Time Remaining: %i:%i", minutes, seconds]];
791 //SHOW THE STATUS WINDOW HERE WITH STRING stringToShow
794 /*[statusWindow setText:stringToShow];
795 [NSTimer scheduledTimerWithTimeInterval:3.0
797 selector:@selector(fadeAndCloseStatusWindow)
803 - (void)showUpcomingSongs
805 int curPlaylist = [currentRemote currentPlaylistIndex];
807 int numSongs = [currentRemote numberOfSongsInPlaylistAtIndex:curPlaylist];
810 int numSongsInAdvance = [[NSUserDefaults standardUserDefaults] integerForKey:@"SongsInAdvance"];
811 int curTrack = [currentRemote currentSongIndex];
813 NSString *songs = @"";
815 for (i = curTrack + 1; i <= curTrack + numSongsInAdvance; i++) {
817 NSString *curSong = [currentRemote songTitleAtIndex:i];
818 songs = [songs stringByAppendingString:curSong];
819 songs = [songs stringByAppendingString:@"\n"];
824 //SHOW STATUS WINDOW HERE WITH STRING songs
827 /*[statusWindow setText:songs];
828 [NSTimer scheduledTimerWithTimeInterval:3.0
830 selector:@selector(fadeAndCloseStatusWindow)
837 - (void)showVolumeIncrementStatusWindow
841 - (void)showVolumeDecrementStatusWindow
845 - (void)showRatingIncrementStatusWindow
849 - (void)showRatingDecrementStatusWindow
853 - (void)showToggleLoopStatusWindow
857 - (void)showToggleShuffleStatusWindow
861 - (void)fadeAndCloseStatusWindow
863 [statusWindow orderOut:self];
866 - (void)setKeyEquivalentForCode:(short)code andModifiers:(long)modifiers
867 onItem:(NSMenuItem *)item
869 unichar charcode = 'a';
871 long cocoaModifiers = 0;
872 static long carbonToCocoa[6][2] =
874 { cmdKey, NSCommandKeyMask },
875 { optionKey, NSAlternateKeyMask },
876 { controlKey, NSControlKeyMask },
877 { shiftKey, NSShiftKeyMask },
880 for (i = 0; i < 6; i++) {
881 if (modifiers & carbonToCocoa[i][0]) {
882 cocoaModifiers += carbonToCocoa[i][1];
885 [item setKeyEquivalentModifierMask:cocoaModifiers];
887 //Missing key combos for some keys. Must find them later.
901 // Haven't tested this, though it should work.
904 [[NSString stringWithString:@"Space"] getCharacters:&buffer];
906 /*MenuRef menuRef = _NSGetCarbonMenu([item menu]);
907 NSLog(@"%@", menuRef);
908 SetMenuItemCommandKey(menuRef, 0, NO, 49);
909 SetMenuItemModifiers(menuRef, 0, kMenuNoCommandModifier);
910 SetMenuItemKeyGlyph(menuRef, 0, kMenuBlankGlyph);
917 charcode = NSDeleteFunctionKey;
933 charcode = NSF5FunctionKey;
937 charcode = NSF6FunctionKey;
941 charcode = NSF7FunctionKey;
945 charcode = NSF3FunctionKey;
949 charcode = NSF8FunctionKey;
953 charcode = NSF9FunctionKey;
957 charcode = NSF11FunctionKey;
961 charcode = NSF3FunctionKey;
965 charcode = NSF14FunctionKey;
969 charcode = NSF10FunctionKey;
973 charcode = NSF12FunctionKey;
977 charcode = NSF13FunctionKey;
981 charcode = NSInsertFunctionKey;
985 charcode = NSHomeFunctionKey;
989 charcode = NSPageUpFunctionKey;
993 charcode = NSDeleteFunctionKey;
997 charcode = NSF4FunctionKey;
1001 charcode = NSEndFunctionKey;
1005 charcode = NSF2FunctionKey;
1009 charcode = NSPageDownFunctionKey;
1013 charcode = NSF1FunctionKey;
1017 charcode = NSLeftArrowFunctionKey;
1021 charcode = NSRightArrowFunctionKey;
1025 charcode = NSDownArrowFunctionKey;
1029 charcode = NSUpArrowFunctionKey;
1033 if (charcode == 'a') {
1034 unsigned long state;
1039 kchr = (Ptr) GetScriptVariable(smCurrentScript, smKCHRCache);
1040 keyTrans = KeyTranslate(kchr, code, &state);
1041 charCode = keyTrans;
1042 [item setKeyEquivalent:[NSString stringWithCString:&charCode length:1]];
1043 } else if (charcode != 'b') {
1044 [item setKeyEquivalent:[NSString stringWithCharacters:&charcode length:1]];