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];
52 [currentRemote begin];
54 //Setup for notification of the remote player launching or quitting
55 [[[NSWorkspace sharedWorkspace] notificationCenter]
57 selector:@selector(applicationTerminated:)
58 name:NSWorkspaceDidTerminateApplicationNotification
61 [[[NSWorkspace sharedWorkspace] notificationCenter]
63 selector:@selector(applicationLaunched:)
64 name:NSWorkspaceDidLaunchApplicationNotification
67 if ( ! [defaults objectForKey:@"menu"] ) { // If this is nil, defaults have never been registered.
68 [[PreferencesController sharedPrefs] registerDefaults];
71 statusItem = [[ITStatusItem alloc]
72 initWithStatusBar:[NSStatusBar systemStatusBar]
73 withLength:NSSquareStatusItemLength];
75 menu = [[NSMenu alloc] initWithTitle:@""];
76 if ( ( [currentRemote playerRunningState] == ITMTRemotePlayerRunning ) ) {
77 [self applicationLaunched:nil];
79 [self applicationTerminated:nil];
82 [statusItem setImage:[NSImage imageNamed:@"menu"]];
83 [statusItem setAlternateImage:[NSImage imageNamed:@"selected_image"]];
84 // Below line of code is for creating builds for Beta Testers
85 // [statusItem setToolTip:@[NSString stringWithFormat:@"This Nontransferable Beta (Built on %s) of iThink Software's MenuTunes is Registered to: Beta Tester (betatester@somedomain.com).",__DATE__]];
88 - (void)applicationWillTerminate:(NSNotification *)note
91 [[NSStatusBar systemStatusBar] removeStatusItem:statusItem];
94 - (ITMTRemote *)loadRemote
96 NSString *folderPath = [[NSBundle mainBundle] builtInPlugInsPath];
99 NSArray *bundlePathList = [NSBundle pathsForResourcesOfType:@"remote" inDirectory:folderPath];
100 NSEnumerator *enumerator = [bundlePathList objectEnumerator];
101 NSString *bundlePath;
103 while ( (bundlePath = [enumerator nextObject]) ) {
104 NSBundle* remoteBundle = [NSBundle bundleWithPath:bundlePath];
107 Class remoteClass = [remoteBundle principalClass];
109 if ([remoteClass conformsToProtocol:@protocol(ITMTRemote)] &&
110 [remoteClass isKindOfClass:[NSObject class]]) {
112 id remote = [remoteClass remote];
113 [remoteArray addObject:remote];
118 // if ( [remoteArray count] > 0 ) { // UNCOMMENT WHEN WE HAVE > 1 PLUGIN
119 // if ( [remoteArray count] > 1 ) {
120 // [remoteArray sortUsingSelector:@selector(sortAlpha:)];
122 // [self loadModuleAccessUI]; //Comment out this line to disable remote visibility
125 // NSLog(@"%@", [remoteArray objectAtIndex:0]); //DEBUG
126 return [remoteArray objectAtIndex:0];
132 - (void)applicationLaunched:(NSNotification *)note
134 if (!note || [[[note userInfo] objectForKey:@"NSApplicationName"] isEqualToString:[currentRemote playerFullName]]) {
135 unichar fullstar = 0x2605;
136 unichar emptystar = 0x2606;
137 NSString *fullStarChar = [NSString stringWithCharacters:&fullstar length:1];
138 NSString *emptyStarChar = [NSString stringWithCharacters:&emptystar length:1];
139 //Build the song rating menu
140 ratingMenu = [[NSMenu alloc] initWithTitle:@""];
141 [[ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", emptyStarChar, emptyStarChar, emptyStarChar, emptyStarChar, emptyStarChar] action:@selector(selectSongRating:) keyEquivalent:@""] setTag:0];
142 [[ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", fullStarChar, emptyStarChar, emptyStarChar, emptyStarChar, emptyStarChar] action:@selector(selectSongRating:) keyEquivalent:@""] setTag:20];
143 [[ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", fullStarChar, fullStarChar, emptyStarChar, emptyStarChar, emptyStarChar] action:@selector(selectSongRating:) keyEquivalent:@""] setTag:40];
144 [[ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", fullStarChar, fullStarChar, fullStarChar, emptyStarChar, emptyStarChar] action:@selector(selectSongRating:) keyEquivalent:@""] setTag:60];
145 [[ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", fullStarChar, fullStarChar, fullStarChar, fullStarChar, emptyStarChar] action:@selector(selectSongRating:) keyEquivalent:@""] setTag:80];
146 [[ratingMenu addItemWithTitle:[NSString stringWithFormat:@"%@%@%@%@%@", fullStarChar, fullStarChar, fullStarChar, fullStarChar, fullStarChar] action:@selector(selectSongRating:) keyEquivalent:@""] setTag:100];
147 [NSThread detachNewThreadSelector:@selector(startTimerInNewThread) toTarget:self withObject:nil];
150 isAppRunning = ITMTRemotePlayerRunning;
154 - (void)applicationTerminated:(NSNotification *)note
156 if (!note || [[[note userInfo] objectForKey:@"NSApplicationName"] isEqualToString:[currentRemote playerFullName]]) {
157 NSMenu *notRunningMenu = [[NSMenu alloc] initWithTitle:@""];
158 [notRunningMenu addItemWithTitle:[NSString stringWithFormat:@"Open %@", [currentRemote playerSimpleName]] action:@selector(showPlayer:) keyEquivalent:@""];
159 [notRunningMenu addItem:[NSMenuItem separatorItem]];
160 [notRunningMenu addItemWithTitle:@"Preferences" action:@selector(showPreferences:) keyEquivalent:@""];
161 [notRunningMenu addItemWithTitle:@"Quit" action:@selector(quitMenuTunes:) keyEquivalent:@""];
163 [refreshTimer invalidate];
164 [refreshTimer release];
167 isAppRunning = ITMTRemotePlayerNotRunning;
169 [ratingMenu release];
171 [statusItem setMenu:[notRunningMenu autorelease]];
175 /*************************************************************************/
177 #pragma mark INSTANCE METHODS
178 /*************************************************************************/
180 - (void)startTimerInNewThread
182 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
183 NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
184 refreshTimer = [[NSTimer scheduledTimerWithTimeInterval:0.5
186 selector:@selector(timerUpdate)
188 repeats:YES] retain];
193 //Recreate the status item menu
196 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
197 NSArray *myMenu = [defaults arrayForKey:@"menu"];
198 int playlist = [currentRemote currentPlaylistIndex];
201 if ([currentRemote playerRunningState] == ITMTRemotePlayerNotRunning) {
206 lastPlaylistIndex = -1;
209 menu = [[NSMenu alloc] initWithTitle:@""];
213 upcomingSongsItem = nil;
214 [upcomingSongsMenu release];
215 upcomingSongsMenu = nil;
218 [ratingItem setSubmenu:nil];
222 [playlistMenu release];
229 //Build the custom menu
230 for (i = 0; i < [myMenu count]; i++) {
231 NSString *item = [myMenu objectAtIndex:i];
232 if ([item isEqualToString:@"Play/Pause"]) {
233 KeyCombo *tempCombo = [[NSUserDefaults standardUserDefaults] keyComboForKey:@"PlayPause"];
234 playPauseItem = [menu addItemWithTitle:@"Play"
235 action:@selector(playPause:)
239 [self setKeyEquivalentForCode:[tempCombo keyCode]
240 andModifiers:[tempCombo modifiers] onItem:playPauseItem];
243 } else if ([item isEqualToString:@"Next Track"]) {
244 KeyCombo *tempCombo = [[NSUserDefaults standardUserDefaults] keyComboForKey:@"NextTrack"];
245 NSMenuItem *nextTrack = [menu addItemWithTitle:@"Next Track"
246 action:@selector(nextSong:)
250 [self setKeyEquivalentForCode:[tempCombo keyCode]
251 andModifiers:[tempCombo modifiers] onItem:nextTrack];
254 } else if ([item isEqualToString:@"Previous Track"]) {
255 KeyCombo *tempCombo = [[NSUserDefaults standardUserDefaults] keyComboForKey:@"PrevTrack"];
256 NSMenuItem *prevTrack = [menu addItemWithTitle:@"Previous Track"
257 action:@selector(prevSong:)
261 [self setKeyEquivalentForCode:[tempCombo keyCode]
262 andModifiers:[tempCombo modifiers] onItem:prevTrack];
265 } else if ([item isEqualToString:@"Fast Forward"]) {
266 [menu addItemWithTitle:@"Fast Forward"
267 action:@selector(fastForward:)
269 } else if ([item isEqualToString:@"Rewind"]) {
270 [menu addItemWithTitle:@"Rewind"
271 action:@selector(rewind:)
273 } else if ([item isEqualToString:@"Show Player"]) {
274 [menu addItemWithTitle:[NSString stringWithFormat:@"Show %@", [currentRemote playerSimpleName]]
275 action:@selector(showPlayer:)
277 } else if ([item isEqualToString:@"Upcoming Songs"]) {
278 upcomingSongsItem = [menu addItemWithTitle:@"Upcoming Songs"
281 upcomingSongsMenu = [[NSMenu alloc] initWithTitle:@""];
282 [upcomingSongsItem setSubmenu:upcomingSongsMenu];
283 [upcomingSongsItem setEnabled:NO];
284 } else if ([item isEqualToString:@"Playlists"]) {
285 playlistItem = [menu addItemWithTitle:@"Playlists"
288 } else if ([item isEqualToString:@"EQ Presets"]) {
289 eqItem = [menu addItemWithTitle:@"EQ Presets"
292 } else if ([item isEqualToString:@"PreferencesÉ"]) {
293 [menu addItemWithTitle:@"PreferencesÉ"
294 action:@selector(showPreferences:)
296 } else if ([item isEqualToString:@"Quit"]) {
297 [menu addItemWithTitle:@"Quit"
298 action:@selector(quitMenuTunes:)
300 } else if ([item isEqualToString:@"Current Track Info"]) {
301 trackInfoIndex = [menu numberOfItems];
302 [menu addItemWithTitle:@"No Song"
305 } else if ([item isEqualToString:@"Song Rating"]) {
306 ratingItem = [menu addItemWithTitle:@"Song Rating"
309 [ratingItem setSubmenu:ratingMenu];
310 } else if ([item isEqualToString:@"<separator>"]) {
311 [menu addItem:[NSMenuItem separatorItem]];
316 [self rebuildPlaylistMenu];
320 [self rebuildEQPresetsMenu];
323 isPlayingRadio = ([currentRemote classOfPlaylistAtIndex:playlist] == ITMTRemotePlayerRadioPlaylist);
325 if (upcomingSongsItem) {
326 [self rebuildUpcomingSongsMenu];
330 if (isPlayingRadio || !playlist) {
331 [ratingItem setEnabled:NO];
333 int currentSongRating = ([currentRemote currentSongRating] * 5);
334 [[ratingMenu itemAtIndex:lastSongRating] setState:NSOffState];
335 lastSongRating = currentSongRating;
336 [[ratingMenu itemAtIndex:lastSongRating] setState:NSOnState];
337 [ratingItem setEnabled:YES];
341 //Set the new unique song identifier
342 lastSongIdentifier = [[currentRemote currentSongUniqueIdentifier] retain];
344 //If we're in a playlist or radio mode
345 if ( ![lastSongIdentifier isEqualToString:@"0-0"] && (trackInfoIndex > -1) ) {
348 if ( (i = [menu indexOfItemWithTitle:@"No Song"]) ) {
350 [menu removeItemAtIndex:i];
351 [menu insertItemWithTitle:@"Now Playing" action:NULL keyEquivalent:@"" atIndex:i];
355 title = [currentRemote currentSongTitle];
357 if (!isPlayingRadio) {
358 if ([defaults boolForKey:@"showTime"]) {
359 NSString *length = [currentRemote currentSongLength];
360 char character = [length characterAtIndex:0];
361 if ( (character > '0') && (character < '9') ) {
362 [menu insertItemWithTitle:[NSString stringWithFormat:@" %@", [currentRemote currentSongLength]] action:nil keyEquivalent:@"" atIndex:trackInfoIndex + 1];
366 if ([defaults boolForKey:@"showTrackRating"]) {
367 if (title) { //Check to see if there's a song playing
368 [menu insertItemWithTitle:[NSString stringWithFormat:@" %@", [[ratingMenu itemAtIndex:[currentRemote currentSongRating] * 5] title]] action:nil keyEquivalent:@"" atIndex:trackInfoIndex + 1];
372 if ([defaults boolForKey:@"showArtist"]) {
373 NSString *artist = [currentRemote currentSongArtist];
374 if ([artist length] > 0) {
375 [menu insertItemWithTitle:[NSString stringWithFormat:@" %@", artist] action:nil keyEquivalent:@"" atIndex:trackInfoIndex + 1];
379 if ([defaults boolForKey:@"showTrackNumber"]) {
380 int track = [currentRemote currentSongTrack];
381 int total = [currentRemote currentAlbumTrackCount];
383 [menu insertItemWithTitle:[NSString stringWithFormat:@" Track %i of %i", track, total] action:nil keyEquivalent:@"" atIndex:trackInfoIndex + 1];
387 if ([defaults boolForKey:@"showAlbum"]) {
388 NSString *album = [currentRemote currentSongAlbum];
389 if ([album length] > 0) {
390 [menu insertItemWithTitle:[NSString stringWithFormat:@" %@", album] action:nil keyEquivalent:@"" atIndex:trackInfoIndex + 1];
395 if ([title length] > 0) {
396 [menu insertItemWithTitle:[NSString stringWithFormat:@" %@", title] action:nil keyEquivalent:@"" atIndex:trackInfoIndex + 1];
400 [statusItem setMenu:menu];
406 //Rebuild the upcoming songs submenu. Can be improved a lot.
407 - (void)rebuildUpcomingSongsMenu
409 int curIndex = [currentRemote currentPlaylistIndex];
410 int numSongs = [currentRemote numberOfSongsInPlaylistAtIndex:curIndex];
411 int numSongsInAdvance = [[NSUserDefaults standardUserDefaults] integerForKey:@"SongsInAdvance"];
413 if (!isPlayingRadio) {
415 int curTrack = [currentRemote currentSongIndex];
418 [upcomingSongsMenu release];
419 upcomingSongsMenu = [[NSMenu alloc] initWithTitle:@""];
420 [upcomingSongsItem setSubmenu:upcomingSongsMenu];
421 [upcomingSongsItem setEnabled:YES];
423 for (i = curTrack + 1; i <= curTrack + numSongsInAdvance; i++) {
425 NSString *curSong = [currentRemote songTitleAtIndex:i];
426 NSMenuItem *songItem;
427 songItem = [[NSMenuItem alloc] initWithTitle:curSong action:@selector(selectSong:) keyEquivalent:@""];
428 [songItem setRepresentedObject:[NSNumber numberWithInt:i]];
429 [upcomingSongsMenu addItem:songItem];
437 [upcomingSongsItem setSubmenu:nil];
438 [upcomingSongsItem setEnabled:NO];
442 - (void)rebuildPlaylistMenu
444 NSArray *playlists = [currentRemote playlists];
445 int i, currentPlaylist = [currentRemote currentPlaylistIndex];
447 [playlistMenu release];
448 playlistMenu = [[NSMenu alloc] initWithTitle:@""];
450 for (i = 0; i < [playlists count]; i++) {
451 NSString *playlistName = [playlists objectAtIndex:i];
452 NSMenuItem *tempItem;
453 tempItem = [[NSMenuItem alloc] initWithTitle:playlistName action:@selector(selectPlaylist:) keyEquivalent:@""];
454 [tempItem setTag:i + 1];
455 [playlistMenu addItem:tempItem];
458 [playlistItem setSubmenu:playlistMenu];
459 [playlistItem setEnabled:YES];
461 if (!isPlayingRadio && currentPlaylist) {
462 [[playlistMenu itemAtIndex:currentPlaylist - 1] setState:NSOnState];
466 //Build a menu with the list of all available EQ presets
467 - (void)rebuildEQPresetsMenu
469 NSArray *eqPresets = [currentRemote eqPresets];
472 [eqMenu autorelease];
473 eqMenu = [[NSMenu alloc] initWithTitle:@""];
475 for (i = 0; i < [eqPresets count]; i++) {
477 NSMenuItem *tempItem;
478 if ( ( name = [eqPresets objectAtIndex:i] ) ) {
479 tempItem = [[NSMenuItem alloc] initWithTitle:name action:@selector(selectEQPreset:) keyEquivalent:@""];
481 [eqMenu addItem:tempItem];
482 [tempItem autorelease];
486 [eqItem setSubmenu:eqMenu];
487 [eqItem setEnabled:YES];
488 [[eqMenu itemAtIndex:([currentRemote currentEQPresetIndex] - 1)] setState:NSOnState];
491 - (void)updateRatingMenu
493 int currentSongRating = ([currentRemote currentSongRating] * 5);
494 if ([currentRemote currentPlaylistIndex] && (currentSongRating != lastSongRating)) {
495 if ([currentRemote classOfPlaylistAtIndex:[currentRemote currentPlaylistIndex]] == ITMTRemotePlayerRadioPlaylist) {
498 [[ratingMenu itemAtIndex:lastSongRating] setState:NSOffState];
499 lastSongRating = currentSongRating;
500 [[ratingMenu itemAtIndex:lastSongRating] setState:NSOnState];
506 NSString *currentIdentifier = [currentRemote currentSongUniqueIdentifier];
507 if (![lastSongIdentifier isEqualToString:currentIdentifier] ||
508 (!isPlayingRadio && ([currentRemote classOfPlaylistAtIndex:[currentRemote currentPlaylistIndex]] == ITMTRemotePlayerRadioPlaylist))) {
511 // If we want to show the new track floater, do it here!
517 [self updateRatingMenu];
519 //Update Play/Pause menu item
523 // If we want to show the song played/paused, show it here!
526 if ([currentRemote playerPlayingState] == ITMTRemotePlayerPlaying) {
527 [playPauseItem setTitle:@"Pause"];
529 [playPauseItem setTitle:@"Play"];
540 - (void)selectSong:(id)sender
542 [currentRemote switchToSongAtIndex:[[sender representedObject] intValue]];
545 - (void)selectPlaylist:(id)sender
547 int playlist = [sender tag];
548 [currentRemote switchToPlaylistAtIndex:playlist];
551 - (void)selectEQPreset:(id)sender
553 int curSet = [currentRemote currentEQPresetIndex];
554 int item = [sender tag];
556 [currentRemote switchToEQAtIndex:item];
557 [[eqMenu itemAtIndex:curSet - 1] setState:NSOffState];
558 [[eqMenu itemAtIndex:item] setState:NSOnState];
561 - (void)selectSongRating:(id)sender
563 int newRating = [sender tag];
564 [[ratingMenu itemAtIndex:lastSongRating] setState:NSOffState];
565 [sender setState:NSOnState];
566 [currentRemote setCurrentSongRating:(float)newRating / 100.0];
567 lastSongRating = newRating / 20;
570 - (void)playPause:(id)sender
572 ITMTRemotePlayerPlayingState state = [currentRemote playerPlayingState];
574 if (state == ITMTRemotePlayerPlaying) {
575 [currentRemote pause];
576 [playPauseItem setTitle:@"Play"];
577 } else if ((state == ITMTRemotePlayerForwarding) || (state == ITMTRemotePlayerRewinding)) {
578 [currentRemote pause];
579 [currentRemote play];
581 [currentRemote play];
582 [playPauseItem setTitle:@"Pause"];
586 - (void)nextSong:(id)sender
588 [currentRemote goToNextSong];
591 - (void)prevSong:(id)sender
593 [currentRemote goToPreviousSong];
596 - (void)fastForward:(id)sender
598 [currentRemote forward];
599 [playPauseItem setTitle:@"Play"];
602 - (void)rewind:(id)sender
604 [currentRemote rewind];
605 [playPauseItem setTitle:@"Play"];
610 - (void)quitMenuTunes:(id)sender
612 [NSApp terminate:self];
615 - (void)showPlayer:(id)sender
617 if ( ( isAppRunning == ITMTRemotePlayerRunning) ) {
618 [currentRemote showPrimaryInterface];
620 if (![[NSWorkspace sharedWorkspace] launchApplication:[currentRemote playerFullName]]) {
621 NSLog(@"Error Launching Player");
626 - (void)showPreferences:(id)sender
628 [[PreferencesController sharedPrefs] setController:self];
629 [[PreferencesController sharedPrefs] showPrefsWindow:self];
632 - (void)closePreferences
634 if ( ( isAppRunning == ITMTRemotePlayerRunning) ) {
639 - (ITMTRemote *)currentRemote
641 return currentRemote;
652 [[HotKeyCenter sharedCenter] removeHotKey:@"PlayPause"];
653 [[HotKeyCenter sharedCenter] removeHotKey:@"NextTrack"];
654 [[HotKeyCenter sharedCenter] removeHotKey:@"PrevTrack"];
655 [[HotKeyCenter sharedCenter] removeHotKey:@"TrackInfo"];
656 [[HotKeyCenter sharedCenter] removeHotKey:@"UpcomingSongs"];
657 [[HotKeyCenter sharedCenter] removeHotKey:@"ToggleLoop"];
658 [[HotKeyCenter sharedCenter] removeHotKey:@"ToggleShuffle"];
659 [[HotKeyCenter sharedCenter] removeHotKey:@"IncrementVolume"];
660 [[HotKeyCenter sharedCenter] removeHotKey:@"DecrementVolume"];
661 [[HotKeyCenter sharedCenter] removeHotKey:@"IncrementRating"];
662 [[HotKeyCenter sharedCenter] removeHotKey:@"DecrementRating"];
667 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
669 if ([defaults objectForKey:@"PlayPause"] != nil) {
670 [[HotKeyCenter sharedCenter] addHotKey:@"PlayPause"
671 combo:[defaults keyComboForKey:@"PlayPause"]
672 target:self action:@selector(playPause:)];
675 if ([defaults objectForKey:@"NextTrack"] != nil) {
676 [[HotKeyCenter sharedCenter] addHotKey:@"NextTrack"
677 combo:[defaults keyComboForKey:@"NextTrack"]
678 target:self action:@selector(nextSong:)];
681 if ([defaults objectForKey:@"PrevTrack"] != nil) {
682 [[HotKeyCenter sharedCenter] addHotKey:@"PrevTrack"
683 combo:[defaults keyComboForKey:@"PrevTrack"]
684 target:self action:@selector(prevSong:)];
687 if ([defaults objectForKey:@"TrackInfo"] != nil) {
688 [[HotKeyCenter sharedCenter] addHotKey:@"TrackInfo"
689 combo:[defaults keyComboForKey:@"TrackInfo"]
690 target:self action:@selector(showCurrentTrackInfo)];
693 if ([defaults objectForKey:@"UpcomingSongs"] != nil) {
694 [[HotKeyCenter sharedCenter] addHotKey:@"UpcomingSongs"
695 combo:[defaults keyComboForKey:@"UpcomingSongs"]
696 target:self action:@selector(showUpcomingSongs)];
699 if ([defaults objectForKey:@"ToggleLoop"] != nil) {
700 [[HotKeyCenter sharedCenter] addHotKey:@"ToggleLoop"
701 combo:[defaults keyComboForKey:@"ToggleLoop"]
702 target:self action:NULL/*Set this to something*/];
705 if ([defaults objectForKey:@"ToggleShuffle"] != nil) {
706 [[HotKeyCenter sharedCenter] addHotKey:@"ToggleShuffle"
707 combo:[defaults keyComboForKey:@"ToggleShuffle"]
708 target:self action:NULL/*Set this to something*/];
711 if ([defaults objectForKey:@"IncrementVolume"] != nil) {
712 [[HotKeyCenter sharedCenter] addHotKey:@"IncrementVolume"
713 combo:[defaults keyComboForKey:@"IncrementVolume"]
714 target:self action:NULL/*Set this to something*/];
717 if ([defaults objectForKey:@"DecrementVolume"] != nil) {
718 [[HotKeyCenter sharedCenter] addHotKey:@"DecrementVolume"
719 combo:[defaults keyComboForKey:@"DecrementVolume"]
720 target:self action:NULL/*Set this to something*/];
723 if ([defaults objectForKey:@"IncrementRating"] != nil) {
724 [[HotKeyCenter sharedCenter] addHotKey:@"IncrementRating"
725 combo:[defaults keyComboForKey:@"IncrementRating"]
726 target:self action:NULL/*Set this to something*/];
729 if ([defaults objectForKey:@"DecrementRating"] != nil) {
730 [[HotKeyCenter sharedCenter] addHotKey:@"DecrementRating"
731 combo:[defaults keyComboForKey:@"DecrementRating"]
732 target:self action:NULL/*Set this to something*/];
738 // Show Current Track Info And Show Upcoming Songs Floaters
742 - (void)showCurrentTrackInfo
744 NSString *trackName = [currentRemote currentSongTitle];
745 if (!statusWindow && [trackName length]) {
746 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
747 NSString *stringToShow = @"";
749 if ([defaults boolForKey:@"showName"]) {
750 if ([defaults boolForKey:@"showArtist"]) {
751 NSString *trackArtist = [currentRemote currentSongArtist];
752 trackName = [NSString stringWithFormat:@"%@ - %@", trackArtist, trackName];
754 stringToShow = [stringToShow stringByAppendingString:trackName];
755 stringToShow = [stringToShow stringByAppendingString:@"\n"];
758 if ([defaults boolForKey:@"showAlbum"]) {
759 NSString *trackAlbum = [currentRemote currentSongAlbum];
760 if ([trackAlbum length]) {
761 stringToShow = [stringToShow stringByAppendingString:trackAlbum];
762 stringToShow = [stringToShow stringByAppendingString:@"\n"];
766 if ([defaults boolForKey:@"showTime"]) {
767 NSString *trackTime = [currentRemote currentSongLength];
768 if ([trackTime length]) {
769 stringToShow = [NSString stringWithFormat:@"%@Total Time: %@\n", stringToShow, trackTime];
774 int trackTimeLeft = [[currentRemote currentSongRemaining] intValue];
775 int minutes = trackTimeLeft / 60, seconds = trackTimeLeft % 60;
777 stringToShow = [stringToShow stringByAppendingString:
778 [NSString stringWithFormat:@"Time Remaining: %i:0%i", minutes, seconds]];
780 stringToShow = [stringToShow stringByAppendingString:
781 [NSString stringWithFormat:@"Time Remaining: %i:%i", minutes, seconds]];
786 //SHOW THE STATUS WINDOW HERE WITH STRING stringToShow
789 /*[statusWindow setText:stringToShow];
790 [NSTimer scheduledTimerWithTimeInterval:3.0
792 selector:@selector(fadeAndCloseStatusWindow)
798 - (void)showUpcomingSongs
800 int curPlaylist = [currentRemote currentPlaylistIndex];
802 int numSongs = [currentRemote numberOfSongsInPlaylistAtIndex:curPlaylist];
805 int numSongsInAdvance = [[NSUserDefaults standardUserDefaults] integerForKey:@"SongsInAdvance"];
806 int curTrack = [currentRemote currentSongIndex];
808 NSString *songs = @"";
810 for (i = curTrack + 1; i <= curTrack + numSongsInAdvance; i++) {
812 NSString *curSong = [currentRemote songTitleAtIndex:i];
813 songs = [songs stringByAppendingString:curSong];
814 songs = [songs stringByAppendingString:@"\n"];
819 //SHOW STATUS WINDOW HERE WITH STRING songs
822 /*[statusWindow setText:songs];
823 [NSTimer scheduledTimerWithTimeInterval:3.0
825 selector:@selector(fadeAndCloseStatusWindow)
832 - (void)fadeAndCloseStatusWindow
834 [statusWindow orderOut:self];
837 - (void)setKeyEquivalentForCode:(short)code andModifiers:(long)modifiers
838 onItem:(NSMenuItem *)item
840 unichar charcode = 'a';
842 long cocoaModifiers = 0;
843 static long carbonToCocoa[6][2] =
845 { cmdKey, NSCommandKeyMask },
846 { optionKey, NSAlternateKeyMask },
847 { controlKey, NSControlKeyMask },
848 { shiftKey, NSShiftKeyMask },
851 for (i = 0; i < 6; i++) {
852 if (modifiers & carbonToCocoa[i][0]) {
853 cocoaModifiers += carbonToCocoa[i][1];
856 [item setKeyEquivalentModifierMask:cocoaModifiers];
858 //Missing key combos for some keys. Must find them later.
872 // Haven't tested this, though it should work.
874 [[NSString stringWithString:@"Space"] getCharacters:&buffer];
876 /*MenuRef menuRef = _NSGetCarbonMenu([item menu]);
877 NSLog(@"%@", menuRef);
878 SetMenuItemCommandKey(menuRef, 0, NO, 49);
879 SetMenuItemModifiers(menuRef, 0, kMenuNoCommandModifier);
880 SetMenuItemKeyGlyph(menuRef, 0, kMenuBlankGlyph);
887 charcode = NSDeleteFunctionKey;
903 charcode = NSF5FunctionKey;
907 charcode = NSF6FunctionKey;
911 charcode = NSF7FunctionKey;
915 charcode = NSF3FunctionKey;
919 charcode = NSF8FunctionKey;
923 charcode = NSF9FunctionKey;
927 charcode = NSF11FunctionKey;
931 charcode = NSF3FunctionKey;
935 charcode = NSF14FunctionKey;
939 charcode = NSF10FunctionKey;
943 charcode = NSF12FunctionKey;
947 charcode = NSF13FunctionKey;
951 charcode = NSInsertFunctionKey;
955 charcode = NSHomeFunctionKey;
959 charcode = NSPageUpFunctionKey;
963 charcode = NSDeleteFunctionKey;
967 charcode = NSF4FunctionKey;
971 charcode = NSEndFunctionKey;
975 charcode = NSF2FunctionKey;
979 charcode = NSPageDownFunctionKey;
983 charcode = NSF1FunctionKey;
987 charcode = NSLeftArrowFunctionKey;
991 charcode = NSRightArrowFunctionKey;
995 charcode = NSDownArrowFunctionKey;
999 charcode = NSUpArrowFunctionKey;
1003 if (charcode == 'a') {
1004 unsigned long state;
1009 kchr = (Ptr) GetScriptVariable(smCurrentScript, smKCHRCache);
1010 keyTrans = KeyTranslate(kchr, code, &state);
1011 charCode = keyTrans;
1012 [item setKeyEquivalent:[NSString stringWithCString:&charCode length:1]];
1013 } else if (charcode != 'b') {
1014 [item setKeyEquivalent:[NSString stringWithCharacters:&charcode length:1]];