1 #import "MainController.h"
2 #import "MenuController.h"
3 #import "PreferencesController.h"
4 #import "NetworkController.h"
5 #import "NetworkObject.h"
6 #import <ITKit/ITHotKeyCenter.h>
7 #import <ITKit/ITHotKey.h>
8 #import <ITKit/ITKeyCombo.h>
9 #import <ITKit/ITCategory-NSMenu.h>
10 #import "StatusWindow.h"
11 #import "StatusWindowController.h"
12 #import "StatusItemHack.h"
14 @interface NSMenu (MenuImpl)
18 @interface NSCarbonMenuImpl:NSObject
24 + (void)setupForNoMenuBar;
28 - (void)itemChanged:fp8;
29 - (void)itemAdded:fp8;
30 - (void)itemRemoved:fp8;
31 - (void)performActionWithHighlightingForItemAtIndex:(int)fp8;
32 - (void)performMenuAction:(SEL)fp8 withTarget:fp12;
33 - (void)setupCarbonMenuBar;
34 - (void)setAsMainCarbonMenuBar;
35 - (void)clearAsMainCarbonMenuBar;
36 - (void)popUpMenu:fp8 atLocation:(NSPoint)fp12 width:(float)fp20 forView:fp24 withSelectedItem:(int)fp28 withFont:fp32;
37 - (void)_popUpContextMenu:fp8 withEvent:fp12 forView:fp16 withFont:fp20;
38 - (void)_popUpContextMenu:fp8 withEvent:fp12 forView:fp16;
42 @implementation NSImage (SmoothAdditions)
44 - (NSImage *)imageScaledSmoothlyToSize:(NSSize)scaledSize
47 NSImageRep *rep = [self bestRepresentationForDevice:nil];
49 newImage = [[NSImage alloc] initWithSize:scaledSize];
52 [[NSGraphicsContext currentContext] setImageInterpolation:NSImageInterpolationHigh];
53 [[NSGraphicsContext currentContext] setShouldAntialias:YES];
54 [rep drawInRect:NSMakeRect(3, 3, scaledSize.width - 6, scaledSize.height - 6)];
56 [newImage unlockFocus];
57 return [newImage autorelease];
62 @interface MainController(Private)
63 - (ITMTRemote *)loadRemote;
64 - (void)setLatestSongIdentifier:(NSString *)newIdentifier;
65 - (void)applicationLaunched:(NSNotification *)note;
66 - (void)applicationTerminated:(NSNotification *)note;
69 static MainController *sharedController;
71 @implementation MainController
73 + (MainController *)sharedController
75 return sharedController;
78 /*************************************************************************/
80 #pragma mark INITIALIZATION/DEALLOCATION METHODS
81 /*************************************************************************/
85 if ( ( self = [super init] ) ) {
86 sharedController = self;
88 remoteArray = [[NSMutableArray alloc] initWithCapacity:1];
89 [[PreferencesController sharedPrefs] setController:self];
90 statusWindowController = [StatusWindowController sharedController];
91 menuController = [[MenuController alloc] init];
92 df = [[NSUserDefaults standardUserDefaults] retain];
99 - (void)applicationDidFinishLaunching:(NSNotification *)note
101 //Turn on debug mode if needed
102 if ([df boolForKey:@"ITDebugMode"]) {
106 if (([df integerForKey:@"appVersion"] < 1200) && ([df integerForKey:@"SongsInAdvance"] > 0)) {
107 [df removePersistentDomainForName:@"com.ithinksw.menutunes"];
109 [[PreferencesController sharedPrefs] registerDefaults];
110 [[StatusWindowController sharedController] showPreferencesUpdateWindow];
113 currentRemote = [self loadRemote];
114 [[self currentRemote] begin];
116 //Turn on network stuff if needed
117 networkController = [[NetworkController alloc] init];
118 if ([df boolForKey:@"enableSharing"]) {
119 [self setServerStatus:YES];
120 } else if ([df boolForKey:@"useSharedPlayer"]) {
121 [self checkForRemoteServerAndConnectImmediately:YES];
124 //Setup for notification of the remote player launching or quitting
125 [[[NSWorkspace sharedWorkspace] notificationCenter]
127 selector:@selector(applicationTerminated:)
128 name:NSWorkspaceDidTerminateApplicationNotification
131 [[[NSWorkspace sharedWorkspace] notificationCenter]
133 selector:@selector(applicationLaunched:)
134 name:NSWorkspaceDidLaunchApplicationNotification
137 if (![df objectForKey:@"menu"]) { // If this is nil, defaults have never been registered.
138 [[PreferencesController sharedPrefs] registerDefaults];
141 if ([df boolForKey:@"ITMTNoStatusItem"]) {
144 [StatusItemHack install];
145 statusItem = [[ITStatusItem alloc]
146 initWithStatusBar:[NSStatusBar systemStatusBar]
147 withLength:NSSquareStatusItemLength];
150 /*bling = [[MTBlingController alloc] init];
152 registerTimer = [[NSTimer scheduledTimerWithTimeInterval:10.0
154 selector:@selector(blingTime)
156 repeats:YES] retain];*/
159 if ([[self currentRemote] playerRunningState] == ITMTRemotePlayerRunning) {
160 [self applicationLaunched:nil];
162 if ([df boolForKey:@"LaunchPlayerWithMT"])
165 [self applicationTerminated:nil];
168 [self networkError:localException];
171 [statusItem setImage:[NSImage imageNamed:@"MenuNormal"]];
172 [statusItem setAlternateImage:[NSImage imageNamed:@"MenuInverted"]];
174 [networkController startRemoteServerSearch];
176 [self performSelector:@selector(rawr) withObject:nil afterDelay:1.0];
178 bling = [[MTBlingController alloc] init];
180 registerTimer = [[NSTimer scheduledTimerWithTimeInterval:10.0
182 selector:@selector(blingTime)
184 repeats:YES] retain];
192 - (void)applicationDidBecomeActive:(NSNotification *)note
194 if (_open && !blinged && ![NSApp mainWindow] && ![[StatusWindow sharedWindow] isVisible]) {
195 [[MainController sharedController] showPreferences];
199 - (ITMTRemote *)loadRemote
201 NSString *folderPath = [[NSBundle mainBundle] builtInPlugInsPath];
202 ITDebugLog(@"Gathering remotes.");
204 NSArray *bundlePathList = [NSBundle pathsForResourcesOfType:@"remote" inDirectory:folderPath];
205 NSEnumerator *enumerator = [bundlePathList objectEnumerator];
206 NSString *bundlePath;
208 while ( (bundlePath = [enumerator nextObject]) ) {
209 NSBundle* remoteBundle = [NSBundle bundleWithPath:bundlePath];
212 Class remoteClass = [remoteBundle principalClass];
214 if ([remoteClass conformsToProtocol:@protocol(ITMTRemote)] &&
215 [(NSObject *)remoteClass isKindOfClass:[NSObject class]]) {
216 id remote = [remoteClass remote];
217 ITDebugLog(@"Adding remote at path %@", bundlePath);
218 [remoteArray addObject:remote];
223 // if ( [remoteArray count] > 0 ) { // UNCOMMENT WHEN WE HAVE > 1 PLUGIN
224 // if ( [remoteArray count] > 1 ) {
225 // [remoteArray sortUsingSelector:@selector(sortAlpha:)];
227 // [self loadModuleAccessUI]; //Comment out this line to disable remote visibility
230 // NSLog(@"%@", [remoteArray objectAtIndex:0]); //DEBUG
231 return [remoteArray objectAtIndex:0];
234 /*************************************************************************/
236 #pragma mark INSTANCE METHODS
237 /*************************************************************************/
239 /*- (void)startTimerInNewThread
241 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
242 NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
243 refreshTimer = [[NSTimer scheduledTimerWithTimeInterval:0.5
245 selector:@selector(timerUpdate)
247 repeats:YES] retain];
249 ITDebugLog(@"Timer started.");
253 - (void)setBlingTime:(NSDate*)date
255 NSMutableDictionary *globalPrefs;
257 globalPrefs = [[df persistentDomainForName:@".GlobalPreferences"] mutableCopy];
259 [globalPrefs setObject:date forKey:@"ITMTTrialStart"];
260 [globalPrefs setObject:[NSNumber numberWithInt:MT_CURRENT_VERSION] forKey:@"ITMTTrialVers"];
262 [globalPrefs removeObjectForKey:@"ITMTTrialStart"];
263 [globalPrefs removeObjectForKey:@"ITMTTrialVers"];
265 [df setPersistentDomain:globalPrefs forName:@".GlobalPreferences"];
267 [globalPrefs release];
270 - (NSDate*)getBlingTime
273 return [[df persistentDomainForName:@".GlobalPreferences"] objectForKey:@"ITMTTrialStart"];
278 NSDate *now = [NSDate date];
279 if (![self blingBling]) {
280 if ( (! [self getBlingTime] ) || ([now timeIntervalSinceDate:[self getBlingTime]] < 0) ) {
281 [self setBlingTime:now];
282 } else if ([[[df persistentDomainForName:@".GlobalPreferences"] objectForKey:@"ITMTTrialVers"] intValue] < MT_CURRENT_VERSION) {
283 if ([now timeIntervalSinceDate:[self getBlingTime]] >= 345600) {
284 [self setBlingTime:[now addTimeInterval:-259200]];
286 NSMutableDictionary *globalPrefs;
288 globalPrefs = [[df persistentDomainForName:@".GlobalPreferences"] mutableCopy];
289 [globalPrefs setObject:[NSNumber numberWithInt:MT_CURRENT_VERSION] forKey:@"ITMTTrialVers"];
290 [df setPersistentDomain:globalPrefs forName:@".GlobalPreferences"];
292 [globalPrefs release];
296 if ( ([now timeIntervalSinceDate:[self getBlingTime]] >= 604800) && (blinged != YES) ) {
298 [statusItem setEnabled:NO];
299 [[ITHotKeyCenter sharedCenter] setEnabled:NO];
300 if ([refreshTimer isValid]) {
301 [refreshTimer invalidate];
302 [refreshTimer release];
305 [statusWindowController showRegistrationQueryWindow];
309 [statusItem setEnabled:YES];
310 [[ITHotKeyCenter sharedCenter] setEnabled:YES];
311 if (![refreshTimer isValid]) {
312 [refreshTimer release];
313 refreshTimer = [[NSTimer scheduledTimerWithTimeInterval:([networkController isConnectedToServer] ? 10.0 : 0.5)
315 selector:@selector(timerUpdate)
317 repeats:YES] retain];
321 [self setBlingTime:nil];
332 if ( ! ([bling checkDone] == 2475) ) {
339 - (BOOL)songIsPlaying
341 NSString *identifier = nil;
343 identifier = [[self currentRemote] playerStateUniqueIdentifier];
345 [self networkError:localException];
347 return ( ! ([identifier isEqualToString:@"0-0"]) );
350 - (BOOL)radioIsPlaying
352 ITMTRemotePlayerPlaylistClass class = nil;
354 class = [[self currentRemote] currentPlaylistClass];
356 [self networkError:localException];
358 return (class == ITMTRemotePlayerRadioPlaylist );
363 NSString *identifier = nil;
365 identifier = [[self currentRemote] playerStateUniqueIdentifier];
367 [self networkError:localException];
369 return ( ! [identifier isEqualToString:_latestSongIdentifier] );
372 - (NSString *)latestSongIdentifier
374 return _latestSongIdentifier;
377 - (void)setLatestSongIdentifier:(NSString *)newIdentifier
379 ITDebugLog(@"Setting latest song identifier:");
380 ITDebugLog(@" - Identifier: %@", newIdentifier);
381 [_latestSongIdentifier autorelease];
382 _latestSongIdentifier = [newIdentifier retain];
387 NSString *identifier = [[self currentRemote] playerStateUniqueIdentifier];
388 if (refreshTimer && identifier == nil) {
389 if ([statusItem isEnabled]) {
390 [statusItem setToolTip:@"iTunes not responding."];
391 [[ITHotKeyCenter sharedCenter] setEnabled:NO];
393 [statusItem setEnabled:NO];
395 } else if (![statusItem isEnabled]) {
396 [statusItem setEnabled:YES];
397 [statusItem setToolTip:_toolTip];
398 [[ITHotKeyCenter sharedCenter] setEnabled:YES];
402 if ( [self songChanged] && (timerUpdating != YES) && (playerRunningState == ITMTRemotePlayerRunning) ) {
403 ITDebugLog(@"The song changed. '%@'", _latestSongIdentifier);
404 if ([df boolForKey:@"runScripts"]) {
405 NSArray *scripts = [[NSFileManager defaultManager] directoryContentsAtPath:[NSHomeDirectory() stringByAppendingPathComponent:@"Library/Application Support/MenuTunes/Scripts"]];
406 NSEnumerator *scriptsEnum = [scripts objectEnumerator];
407 NSString *nextScript;
408 ITDebugLog(@"Running AppleScripts for song change.");
409 while ( (nextScript = [scriptsEnum nextObject]) ) {
411 NSAppleScript *currentScript = [[NSAppleScript alloc] initWithContentsOfURL:[NSURL fileURLWithPath:[[NSHomeDirectory() stringByAppendingPathComponent:@"Library/Application Support/MenuTunes/Scripts"] stringByAppendingPathComponent:nextScript]] error:&error];
412 ITDebugLog(@"Running script: %@", nextScript);
413 if (!currentScript || ![currentScript executeAndReturnError:nil]) {
414 ITDebugLog(@"Error running script %@.", nextScript);
416 [currentScript release];
421 [statusItem setEnabled:NO];
424 latestPlaylistClass = [[self currentRemote] currentPlaylistClass];
426 if ([menuController rebuildSubmenus]) {
427 if ( [df boolForKey:@"showSongInfoOnChange"] ) {
428 [self performSelector:@selector(showCurrentTrackInfo) withObject:nil afterDelay:0.0];
430 [self setLatestSongIdentifier:identifier];
431 //Create the tooltip for the status item
432 if ( [df boolForKey:@"showToolTip"] ) {
433 NSString *artist = [[self currentRemote] currentSongArtist];
434 NSString *title = [[self currentRemote] currentSongTitle];
435 ITDebugLog(@"Creating status item tooltip.");
437 _toolTip = [NSString stringWithFormat:@"%@ - %@", artist, title];
441 _toolTip = NSLocalizedString(@"noSongPlaying", @"No song is playing.");
443 [statusItem setToolTip:_toolTip];
445 [statusItem setToolTip:nil];
449 [self networkError:localException];
452 [statusItem setEnabled:YES];
455 if ([networkController isConnectedToServer]) {
456 [statusItem setMenu:([[self currentRemote] playerRunningState] == ITMTRemotePlayerRunning) ? [menuController menu] : [menuController menuForNoPlayer]];
462 ITDebugLog(@"Menu clicked.");
464 if (([[self currentRemote] playerStateUniqueIdentifier] == nil) && playerRunningState == ITMTRemotePlayerRunning) {
466 if ([statusItem isEnabled]) {
467 [statusItem setToolTip:NSLocalizedString(@"iTunesNotResponding", @"iTunes is not responding.")];
468 [[ITHotKeyCenter sharedCenter] setEnabled:NO];
470 [statusItem setEnabled:NO];
472 NSMenu *menu = [[NSMenu alloc] init];
473 [menu addItemWithTitle:NSLocalizedString(@"iTunesNotResponding", @"iTunes is not responding.") action:nil keyEquivalent:@""];
474 [statusItem setMenu:[menu autorelease]];
477 } else if (![statusItem isEnabled]) {
478 [statusItem setEnabled:YES];
479 [statusItem setToolTip:_toolTip];
480 [[ITHotKeyCenter sharedCenter] setEnabled:YES];
484 if ([networkController isConnectedToServer]) {
485 //Used the cached version
490 if ([[self currentRemote] playerRunningState] == ITMTRemotePlayerRunning) {
491 [statusItem setMenu:[menuController menu]];
493 [statusItem setMenu:[menuController menuForNoPlayer]];
496 [self networkError:localException];
500 - (void)trackChanged:(NSNotification *)note
502 //If we're running the timer, shut it off since we don't need it!
503 if (refreshTimer && [refreshTimer isValid]) {
504 ITDebugLog(@"Invalidating refresh timer.");
505 [refreshTimer invalidate];
506 [refreshTimer release];
510 if (![self songChanged]) {
513 NSString *identifier = [[self currentRemote] playerStateUniqueIdentifier];
514 if ( [df boolForKey:@"showSongInfoOnChange"] ) {
515 [self performSelector:@selector(showCurrentTrackInfo) withObject:nil afterDelay:0.0];
517 [_lastTrackInfo release];
518 _lastTrackInfo = [[note userInfo] retain];
520 [self setLatestSongIdentifier:identifier];
521 ITDebugLog(@"The song changed. '%@'", _latestSongIdentifier);
522 if ([df boolForKey:@"runScripts"]) {
523 NSArray *scripts = [[NSFileManager defaultManager] directoryContentsAtPath:[NSHomeDirectory() stringByAppendingPathComponent:@"Library/Application Support/MenuTunes/Scripts"]];
524 NSEnumerator *scriptsEnum = [scripts objectEnumerator];
525 NSString *nextScript;
526 ITDebugLog(@"Running AppleScripts for song change.");
527 while ( (nextScript = [scriptsEnum nextObject]) ) {
529 NSAppleScript *currentScript = [[NSAppleScript alloc] initWithContentsOfURL:[NSURL fileURLWithPath:[[NSHomeDirectory() stringByAppendingPathComponent:@"Library/Application Support/MenuTunes/Scripts"] stringByAppendingPathComponent:nextScript]] error:&error];
530 ITDebugLog(@"Running script: %@", nextScript);
531 if (!currentScript || ![currentScript executeAndReturnError:nil]) {
532 ITDebugLog(@"Error running script %@.", nextScript);
534 [currentScript release];
538 [statusItem setEnabled:NO];
541 latestPlaylistClass = [[self currentRemote] currentPlaylistClass];
543 if ([menuController rebuildSubmenus]) {
544 /*if ( [df boolForKey:@"showSongInfoOnChange"] ) {
545 [self performSelector:@selector(showCurrentTrackInfo) withObject:nil afterDelay:0.0];
547 [self setLatestSongIdentifier:identifier];
548 //Create the tooltip for the status item
549 if ( [df boolForKey:@"showToolTip"] ) {
550 ITDebugLog(@"Creating status item tooltip.");
551 NSString *artist = [_lastTrackInfo objectForKey:@"Artist"], *title = [_lastTrackInfo objectForKey:@"Name"];
553 _toolTip = [NSString stringWithFormat:@"%@ - %@", artist, title];
557 _toolTip = NSLocalizedString(@"noSongPlaying", @"No song is playing.");;
559 [statusItem setToolTip:_toolTip];
561 [statusItem setToolTip:nil];
565 [self networkError:localException];
568 [statusItem setEnabled:YES];
570 if ([networkController isConnectedToServer]) {
571 [statusItem setMenu:([[self currentRemote] playerRunningState] == ITMTRemotePlayerRunning) ? [menuController menu] : [menuController menuForNoPlayer]];
584 ITMTRemotePlayerPlayingState state = [[self currentRemote] playerPlayingState];
585 ITDebugLog(@"Play/Pause toggled");
586 if (state == ITMTRemotePlayerPlaying) {
587 [[self currentRemote] pause];
588 } else if ((state == ITMTRemotePlayerForwarding) || (state == ITMTRemotePlayerRewinding)) {
589 [[self currentRemote] pause];
590 [[self currentRemote] play];
592 [[self currentRemote] play];
595 [self networkError:localException];
605 ITDebugLog(@"Going to next song.");
607 [[self currentRemote] goToNextSong];
609 [self networkError:localException];
618 ITDebugLog(@"Going to previous song.");
620 [[self currentRemote] goToPreviousSong];
622 [self networkError:localException];
631 ITDebugLog(@"Fast forwarding.");
633 [[self currentRemote] forward];
635 [self networkError:localException];
644 ITDebugLog(@"Rewinding.");
646 [[self currentRemote] rewind];
648 [self networkError:localException];
655 - (void)selectPlaylistAtIndex:(int)index
657 ITDebugLog(@"Selecting playlist %i", index);
659 [[self currentRemote] switchToPlaylistAtIndex:(index % 1000) ofSourceAtIndex:(index / 1000)];
660 //[[self currentRemote] switchToPlaylistAtIndex:index];
662 [self networkError:localException];
669 - (void)selectSongAtIndex:(int)index
671 ITDebugLog(@"Selecting song %i", index);
673 [[self currentRemote] switchToSongAtIndex:index];
675 [self networkError:localException];
682 - (void)selectSongRating:(int)rating
684 ITDebugLog(@"Selecting song rating %i", rating);
686 [[self currentRemote] setCurrentSongRating:(float)rating / 100.0];
688 [self networkError:localException];
695 - (void)selectEQPresetAtIndex:(int)index
697 ITDebugLog(@"Selecting EQ preset %i", index);
700 [[self currentRemote] setEqualizerEnabled:![[self currentRemote] equalizerEnabled]];
702 [[self currentRemote] switchToEQAtIndex:index];
705 [self networkError:localException];
712 - (void)makePlaylistWithTerm:(NSString *)term ofType:(int)type
714 ITDebugLog(@"Making playlist with term %@, type %i", term, type);
716 [[self currentRemote] makePlaylistWithTerm:term ofType:type];
718 [self networkError:localException];
720 ITDebugLog(@"Done making playlist");
725 ITDebugLog(@"Beginning show player.");
726 //if ( ( playerRunningState == ITMTRemotePlayerRunning) ) {
727 ITDebugLog(@"Showing player interface.");
729 [[self currentRemote] showPrimaryInterface];
731 [self networkError:localException];
734 ITDebugLog(@"Launching player.");
737 if ( (path = [df stringForKey:@"CustomPlayerPath"]) ) {
739 pathITDebugLog(@"Showing player interface."); = [[self currentRemote] playerFullName];
741 if (![[NSWorkspace sharedWorkspace] launchApplication:path]) {
742 ITDebugLog(@"Error Launching Player");
745 [self networkError:localException];
748 ITDebugLog(@"Finished show player.");
751 - (void)showPreferences
753 ITDebugLog(@"Show preferences.");
754 [[PreferencesController sharedPrefs] showPrefsWindow:self];
757 - (void)showPreferencesAndClose
759 ITDebugLog(@"Show preferences.");
760 [[PreferencesController sharedPrefs] showPrefsWindow:self];
761 [[StatusWindow sharedWindow] setLocked:NO];
762 [[StatusWindow sharedWindow] vanish:self];
763 [[StatusWindow sharedWindow] setIgnoresMouseEvents:YES];
766 - (void)showTestWindow
768 [self showCurrentTrackInfo];
771 - (void)quitMenuTunes
773 ITDebugLog(@"Quitting MenuTunes.");
774 [NSApp terminate:self];
780 - (MenuController *)menuController
782 return menuController;
785 - (void)closePreferences
787 ITDebugLog(@"Preferences closed.");
788 if ( ( playerRunningState == ITMTRemotePlayerRunning) ) {
793 - (ITMTRemote *)currentRemote
795 if ([networkController isConnectedToServer] && ![[networkController networkObject] isValid]) {
796 [self networkError:nil];
799 return currentRemote;
810 NSEnumerator *hotKeyEnumerator = [[[ITHotKeyCenter sharedCenter] allHotKeys] objectEnumerator];
811 ITHotKey *nextHotKey;
812 ITDebugLog(@"Clearing hot keys.");
813 while ( (nextHotKey = [hotKeyEnumerator nextObject]) ) {
814 [[ITHotKeyCenter sharedCenter] unregisterHotKey:nextHotKey];
816 ITDebugLog(@"Done clearing hot keys.");
822 ITDebugLog(@"Setting up hot keys.");
824 if (playerRunningState == ITMTRemotePlayerNotRunning && ![[NetworkController sharedController] isConnectedToServer]) {
828 if ([df objectForKey:@"PlayPause"] != nil) {
829 ITDebugLog(@"Setting up play pause hot key.");
830 hotKey = [[ITHotKey alloc] init];
831 [hotKey setName:@"PlayPause"];
832 [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"PlayPause"]]];
833 [hotKey setTarget:self];
834 [hotKey setAction:@selector(playPause)];
835 [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]];
838 if ([df objectForKey:@"NextTrack"] != nil) {
839 ITDebugLog(@"Setting up next track hot key.");
840 hotKey = [[ITHotKey alloc] init];
841 [hotKey setName:@"NextTrack"];
842 [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"NextTrack"]]];
843 [hotKey setTarget:self];
844 [hotKey setAction:@selector(nextSong)];
845 [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]];
848 if ([df objectForKey:@"PrevTrack"] != nil) {
849 ITDebugLog(@"Setting up previous track hot key.");
850 hotKey = [[ITHotKey alloc] init];
851 [hotKey setName:@"PrevTrack"];
852 [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"PrevTrack"]]];
853 [hotKey setTarget:self];
854 [hotKey setAction:@selector(prevSong)];
855 [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]];
858 if ([df objectForKey:@"FastForward"] != nil) {
859 ITDebugLog(@"Setting up fast forward hot key.");
860 hotKey = [[ITHotKey alloc] init];
861 [hotKey setName:@"FastForward"];
862 [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"FastForward"]]];
863 [hotKey setTarget:self];
864 [hotKey setAction:@selector(fastForward)];
865 [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]];
868 if ([df objectForKey:@"Rewind"] != nil) {
869 ITDebugLog(@"Setting up rewind hot key.");
870 hotKey = [[ITHotKey alloc] init];
871 [hotKey setName:@"Rewind"];
872 [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"Rewind"]]];
873 [hotKey setTarget:self];
874 [hotKey setAction:@selector(rewind)];
875 [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]];
878 if ([df objectForKey:@"ShowPlayer"] != nil) {
879 ITDebugLog(@"Setting up show player hot key.");
880 hotKey = [[ITHotKey alloc] init];
881 [hotKey setName:@"ShowPlayer"];
882 [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"ShowPlayer"]]];
883 [hotKey setTarget:self];
884 [hotKey setAction:@selector(showPlayer)];
885 [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]];
888 if ([df objectForKey:@"TrackInfo"] != nil) {
889 ITDebugLog(@"Setting up track info hot key.");
890 hotKey = [[ITHotKey alloc] init];
891 [hotKey setName:@"TrackInfo"];
892 [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"TrackInfo"]]];
893 [hotKey setTarget:self];
894 [hotKey setAction:@selector(showCurrentTrackInfo)];
895 [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]];
898 if ([df objectForKey:@"UpcomingSongs"] != nil) {
899 ITDebugLog(@"Setting up upcoming songs hot key.");
900 hotKey = [[ITHotKey alloc] init];
901 [hotKey setName:@"UpcomingSongs"];
902 [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"UpcomingSongs"]]];
903 [hotKey setTarget:self];
904 [hotKey setAction:@selector(showUpcomingSongs)];
905 [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]];
908 if ([df objectForKey:@"ToggleLoop"] != nil) {
909 ITDebugLog(@"Setting up toggle loop hot key.");
910 hotKey = [[ITHotKey alloc] init];
911 [hotKey setName:@"ToggleLoop"];
912 [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"ToggleLoop"]]];
913 [hotKey setTarget:self];
914 [hotKey setAction:@selector(toggleLoop)];
915 [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]];
918 if ([df objectForKey:@"ToggleShuffle"] != nil) {
919 ITDebugLog(@"Setting up toggle shuffle hot key.");
920 hotKey = [[ITHotKey alloc] init];
921 [hotKey setName:@"ToggleShuffle"];
922 [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"ToggleShuffle"]]];
923 [hotKey setTarget:self];
924 [hotKey setAction:@selector(toggleShuffle)];
925 [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]];
928 if ([df objectForKey:@"IncrementVolume"] != nil) {
929 ITDebugLog(@"Setting up increment volume hot key.");
930 hotKey = [[ITHotKey alloc] init];
931 [hotKey setName:@"IncrementVolume"];
932 [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"IncrementVolume"]]];
933 [hotKey setTarget:self];
934 [hotKey setAction:@selector(incrementVolume)];
935 [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]];
938 if ([df objectForKey:@"DecrementVolume"] != nil) {
939 ITDebugLog(@"Setting up decrement volume hot key.");
940 hotKey = [[ITHotKey alloc] init];
941 [hotKey setName:@"DecrementVolume"];
942 [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"DecrementVolume"]]];
943 [hotKey setTarget:self];
944 [hotKey setAction:@selector(decrementVolume)];
945 [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]];
948 if ([df objectForKey:@"IncrementRating"] != nil) {
949 ITDebugLog(@"Setting up increment rating hot key.");
950 hotKey = [[ITHotKey alloc] init];
951 [hotKey setName:@"IncrementRating"];
952 [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"IncrementRating"]]];
953 [hotKey setTarget:self];
954 [hotKey setAction:@selector(incrementRating)];
955 [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]];
958 if ([df objectForKey:@"DecrementRating"] != nil) {
959 ITDebugLog(@"Setting up decrement rating hot key.");
960 hotKey = [[ITHotKey alloc] init];
961 [hotKey setName:@"DecrementRating"];
962 [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"DecrementRating"]]];
963 [hotKey setTarget:self];
964 [hotKey setAction:@selector(decrementRating)];
965 [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]];
968 if ([df objectForKey:@"PopupMenu"] != nil) {
969 ITDebugLog(@"Setting up popup menu hot key.");
970 hotKey = [[ITHotKey alloc] init];
971 [hotKey setName:@"PopupMenu"];
972 [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"PopupMenu"]]];
973 [hotKey setTarget:self];
974 [hotKey setAction:@selector(popupMenu)];
975 [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]];
979 for (i = 0; i <= 5; i++) {
980 NSString *curName = [NSString stringWithFormat:@"SetRating%i", i];
981 if ([df objectForKey:curName] != nil) {
982 ITDebugLog(@"Setting up set rating %i hot key.", i);
983 hotKey = [[ITHotKey alloc] init];
984 [hotKey setName:curName];
985 [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:curName]]];
986 [hotKey setTarget:self];
987 [hotKey setAction:@selector(setRating:)];
988 [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]];
991 ITDebugLog(@"Finished setting up hot keys.");
994 - (void)showCurrentTrackInfo
996 ITMTRemotePlayerSource source = 0;
997 NSString *title = nil;
998 NSString *album = nil;
999 NSString *artist = nil;
1000 NSString *composer = nil;
1001 NSString *time = nil;
1002 NSString *track = nil;
1007 ITDebugLog(@"Showing track info status window.");
1010 source = [[self currentRemote] currentSource];
1011 title = [[self currentRemote] currentSongTitle];
1013 [self networkError:localException];
1017 if ( [df boolForKey:@"showAlbumArtwork"] ) {
1018 NSSize oldSize, newSize;
1020 art = [[self currentRemote] currentSongAlbumArt];
1021 oldSize = [art size];
1022 if (oldSize.width > oldSize.height) newSize = NSMakeSize(110,oldSize.height * (110.0f / oldSize.width));
1023 else newSize = NSMakeSize(oldSize.width * (110.0f / oldSize.height),110);
1024 art = [[[[NSImage alloc] initWithData:[art TIFFRepresentation]] autorelease] imageScaledSmoothlyToSize:newSize];
1026 [self networkError:localException];
1030 if ( [df boolForKey:@"showAlbum"] ) {
1032 album = [[self currentRemote] currentSongAlbum];
1034 [self networkError:localException];
1038 if ( [df boolForKey:@"showArtist"] ) {
1040 artist = [[self currentRemote] currentSongArtist];
1042 [self networkError:localException];
1046 if ( [df boolForKey:@"showComposer"] ) {
1048 composer = [[self currentRemote] currentSongComposer];
1050 [self networkError:localException];
1054 if ( [df boolForKey:@"showTime"] ) {
1056 time = [NSString stringWithFormat:@"%@: %@ / %@",
1057 NSLocalizedString(@"time", @"Time"),
1058 [[self currentRemote] currentSongElapsed],
1059 [[self currentRemote] currentSongLength]];
1061 [self networkError:localException];
1065 if ( [df boolForKey:@"showTrackNumber"] ) {
1070 trackNo = [[self currentRemote] currentSongTrack];
1071 trackCount = [[self currentRemote] currentAlbumTrackCount];
1073 [self networkError:localException];
1076 if ( (trackNo > 0) || (trackCount > 0) ) {
1077 track = [NSString stringWithFormat:@"%@: %i %@ %i",
1078 @"Track", trackNo, @"of", trackCount];
1082 if ( [df boolForKey:@"showTrackRating"] ) {
1083 float currentRating = 0;
1086 currentRating = [[self currentRemote] currentSongRating];
1088 [self networkError:localException];
1091 if (currentRating >= 0.0) {
1092 rating = ( currentRating * 5 );
1096 if ( [df boolForKey:@"showPlayCount"] && ![self radioIsPlaying] && [[self currentRemote] currentSource] == ITMTRemoteLibrarySource ) {
1098 playCount = [[self currentRemote] currentSongPlayCount];
1100 [self networkError:localException];
1104 title = NSLocalizedString(@"noSongPlaying", @"No song is playing.");
1106 ITDebugLog(@"Showing current track info status window.");
1107 [statusWindowController showSongInfoWindowWithSource:source
1119 - (void)showUpcomingSongs
1123 numSongs = [[self currentRemote] numberOfSongsInPlaylistAtIndex:[[self currentRemote] currentPlaylistIndex]];
1125 [self networkError:localException];
1128 ITDebugLog(@"Showing upcoming songs status window.");
1131 int numSongsInAdvance = [df integerForKey:@"SongsInAdvance"];
1132 NSMutableArray *songList = [NSMutableArray arrayWithCapacity:numSongsInAdvance];
1133 int curTrack = [[self currentRemote] currentSongIndex];
1136 for (i = curTrack + 1; i <= curTrack + numSongsInAdvance; i++) {
1137 if (i <= numSongs) {
1138 [songList addObject:[[self currentRemote] songTitleAtIndex:i]];
1142 if ([songList count] == 0) {
1143 [songList addObject:NSLocalizedString(@"noUpcomingSongs", @"No upcoming songs.")];
1146 [statusWindowController showUpcomingSongsWindowWithTitles:songList];
1148 [statusWindowController showUpcomingSongsWindowWithTitles:[NSArray arrayWithObject:NSLocalizedString(@"noUpcomingSongs", @"No upcoming songs.")]];
1151 [self networkError:localException];
1160 NSMenu *menu = [statusItem menu];
1161 [(NSCarbonMenuImpl *)[menu _menuImpl] popUpMenu:menu atLocation:[NSEvent mouseLocation] width:1 forView:nil withSelectedItem:-30 withFont:[NSFont menuFontOfSize:32]];
1166 - (void)incrementVolume
1169 float volume = [[self currentRemote] volume];
1170 float dispVol = volume;
1171 ITDebugLog(@"Incrementing volume.");
1180 ITDebugLog(@"Setting volume to %f", volume);
1181 [[self currentRemote] setVolume:volume];
1183 // Show volume status window
1184 [statusWindowController showVolumeWindowWithLevel:dispVol];
1186 [self networkError:localException];
1190 - (void)decrementVolume
1193 float volume = [[self currentRemote] volume];
1194 float dispVol = volume;
1195 ITDebugLog(@"Decrementing volume.");
1204 ITDebugLog(@"Setting volume to %f", volume);
1205 [[self currentRemote] setVolume:volume];
1207 //Show volume status window
1208 [statusWindowController showVolumeWindowWithLevel:dispVol];
1210 [self networkError:localException];
1214 - (void)incrementRating
1217 float rating = [[self currentRemote] currentSongRating];
1218 ITDebugLog(@"Incrementing rating.");
1220 if ([[self currentRemote] currentPlaylistIndex] == 0) {
1221 ITDebugLog(@"No song playing, rating change aborted.");
1229 ITDebugLog(@"Setting rating to %f", rating);
1230 [[self currentRemote] setCurrentSongRating:rating];
1232 //Show rating status window
1233 [statusWindowController showRatingWindowWithRating:rating];
1235 [self networkError:localException];
1239 - (void)decrementRating
1242 float rating = [[self currentRemote] currentSongRating];
1243 ITDebugLog(@"Decrementing rating.");
1245 if ([[self currentRemote] currentPlaylistIndex] == 0) {
1246 ITDebugLog(@"No song playing, rating change aborted.");
1254 ITDebugLog(@"Setting rating to %f", rating);
1255 [[self currentRemote] setCurrentSongRating:rating];
1257 //Show rating status window
1258 [statusWindowController showRatingWindowWithRating:rating];
1260 [self networkError:localException];
1264 - (void)setRating:(ITHotKey *)sender
1266 int stars = [[sender name] characterAtIndex:9] - 48;
1267 [self selectSongRating:stars * 20];
1268 [statusWindowController showRatingWindowWithRating:(float)stars / 5.0];
1274 ITMTRemotePlayerRepeatMode repeatMode = [[self currentRemote] repeatMode];
1275 ITDebugLog(@"Toggling repeat mode.");
1276 switch (repeatMode) {
1277 case ITMTRemotePlayerRepeatOff:
1278 repeatMode = ITMTRemotePlayerRepeatAll;
1280 case ITMTRemotePlayerRepeatAll:
1281 repeatMode = ITMTRemotePlayerRepeatOne;
1283 case ITMTRemotePlayerRepeatOne:
1284 repeatMode = ITMTRemotePlayerRepeatOff;
1287 ITDebugLog(@"Setting repeat mode to %i", repeatMode);
1288 [[self currentRemote] setRepeatMode:repeatMode];
1290 //Show loop status window
1291 [statusWindowController showRepeatWindowWithMode:repeatMode];
1293 [self networkError:localException];
1297 - (void)toggleShuffle
1300 BOOL newShuffleEnabled = ( ! [[self currentRemote] shuffleEnabled] );
1301 ITDebugLog(@"Toggling shuffle mode.");
1302 [[self currentRemote] setShuffleEnabled:newShuffleEnabled];
1303 //Show shuffle status window
1304 ITDebugLog(@"Setting shuffle mode to %i", newShuffleEnabled);
1305 [statusWindowController showShuffleWindow:newShuffleEnabled];
1307 [self networkError:localException];
1311 - (void)registerNowOK
1313 [[StatusWindow sharedWindow] setLocked:NO];
1314 [[StatusWindow sharedWindow] vanish:self];
1315 [[StatusWindow sharedWindow] setIgnoresMouseEvents:YES];
1320 - (void)registerNowCancel
1322 [[StatusWindow sharedWindow] setLocked:NO];
1323 [[StatusWindow sharedWindow] vanish:self];
1324 [[StatusWindow sharedWindow] setIgnoresMouseEvents:YES];
1326 [NSApp terminate:self];
1329 /*************************************************************************/
1331 #pragma mark NETWORK HANDLERS
1332 /*************************************************************************/
1334 - (void)setServerStatus:(BOOL)newStatus
1338 [networkController setServerStatus:YES];
1341 [networkController setServerStatus:NO];
1345 - (int)connectToServer
1348 ITDebugLog(@"Attempting to connect to shared remote.");
1349 result = [networkController connectToHost:[df stringForKey:@"sharedPlayerHost"]];
1352 [[PreferencesController sharedPrefs] resetRemotePlayerTextFields];
1353 currentRemote = [[[networkController networkObject] remote] retain];
1355 [self setupHotKeys];
1356 //playerRunningState = ITMTRemotePlayerRunning;
1357 playerRunningState = [[self currentRemote] playerRunningState];
1359 [refreshTimer invalidate];
1361 refreshTimer = [[NSTimer scheduledTimerWithTimeInterval:([networkController isConnectedToServer] ? 10.0 : 0.5)
1363 selector:@selector(timerUpdate)
1365 repeats:YES] retain];
1367 ITDebugLog(@"Connection successful.");
1369 } else if (result == 0) {
1370 ITDebugLog(@"Connection failed.");
1371 currentRemote = [remoteArray objectAtIndex:0];
1374 //Do something about the password being invalid
1375 ITDebugLog(@"Connection failed.");
1376 currentRemote = [remoteArray objectAtIndex:0];
1381 - (BOOL)disconnectFromServer
1383 ITDebugLog(@"Disconnecting from shared remote.");
1385 [currentRemote release];
1386 currentRemote = [remoteArray objectAtIndex:0];
1387 [networkController disconnect];
1389 if ([[self currentRemote] playerRunningState] == ITMTRemotePlayerRunning) {
1390 [self applicationLaunched:nil];
1392 [self applicationTerminated:nil];
1400 - (void)checkForRemoteServer
1402 [self checkForRemoteServerAndConnectImmediately:NO];
1405 - (void)checkForRemoteServerAndConnectImmediately:(BOOL)connectImmediately
1407 ITDebugLog(@"Checking for remote server.");
1408 if (!_checkingForServer) {
1409 if (!_serverCheckLock) {
1410 _serverCheckLock = [[NSLock alloc] init];
1412 [_serverCheckLock lock];
1413 _checkingForServer = YES;
1414 [_serverCheckLock unlock];
1415 [NSThread detachNewThreadSelector:@selector(runRemoteServerCheck:) toTarget:self withObject:[NSNumber numberWithBool:connectImmediately]];
1419 - (void)runRemoteServerCheck:(id)sender
1421 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
1422 ITDebugLog(@"Remote server check running.");
1423 if ([networkController checkForServerAtHost:[df stringForKey:@"sharedPlayerHost"]]) {
1424 ITDebugLog(@"Remote server found.");
1425 if ([sender boolValue]) {
1426 [self performSelectorOnMainThread:@selector(connectToServer) withObject:nil waitUntilDone:NO];
1428 [self performSelectorOnMainThread:@selector(remoteServerFound:) withObject:nil waitUntilDone:NO];
1431 ITDebugLog(@"Remote server not found.");
1432 [self performSelectorOnMainThread:@selector(remoteServerNotFound:) withObject:nil waitUntilDone:NO];
1434 [_serverCheckLock lock];
1435 _checkingForServer = NO;
1436 [_serverCheckLock unlock];
1440 - (void)remoteServerFound:(id)sender
1442 if (![networkController isServerOn] && ![networkController isConnectedToServer]) {
1443 [[StatusWindowController sharedController] showReconnectQueryWindow];
1447 - (void)remoteServerNotFound:(id)sender
1449 if (![[NetworkController sharedController] isConnectedToServer]) {
1450 [NSTimer scheduledTimerWithTimeInterval:90.0 target:self selector:@selector(checkForRemoteServer) userInfo:nil repeats:NO];
1454 - (void)networkError:(NSException *)exception
1456 ITDebugLog(@"Remote exception thrown: %@: %@", [exception name], [exception reason]);
1457 if ( ((exception == nil) || [[exception name] isEqualToString:NSPortTimeoutException]) && [networkController isConnectedToServer]) {
1458 //NSRunCriticalAlertPanel(@"Remote MenuTunes Disconnected", @"The MenuTunes server you were connected to stopped responding or quit. MenuTunes will revert back to the local player.", @"OK", nil, nil);
1459 [[StatusWindowController sharedController] showNetworkErrorQueryWindow];
1460 if ([self disconnectFromServer]) {
1461 [[PreferencesController sharedPrefs] resetRemotePlayerTextFields];
1462 [NSTimer scheduledTimerWithTimeInterval:90.0 target:self selector:@selector(checkForRemoteServer) userInfo:nil repeats:NO];
1464 ITDebugLog(@"CRITICAL ERROR, DISCONNECTING!");
1471 /*if ([self connectToServer] == 0) {
1472 [NSTimer scheduledTimerWithTimeInterval:90.0 target:self selector:@selector(checkForRemoteServer) userInfo:nil repeats:NO];
1474 [self checkForRemoteServerAndConnectImmediately:YES];
1475 [[StatusWindow sharedWindow] setLocked:NO];
1476 [[StatusWindow sharedWindow] vanish:self];
1477 [[StatusWindow sharedWindow] setIgnoresMouseEvents:YES];
1480 - (void)cancelReconnect
1482 [[StatusWindow sharedWindow] setLocked:NO];
1483 [[StatusWindow sharedWindow] vanish:self];
1484 [[StatusWindow sharedWindow] setIgnoresMouseEvents:YES];
1487 /*************************************************************************/
1489 #pragma mark WORKSPACE NOTIFICATION HANDLERS
1490 /*************************************************************************/
1492 - (void)applicationLaunched:(NSNotification *)note
1495 if (!note || ([[[note userInfo] objectForKey:@"NSApplicationName"] isEqualToString:[[self currentRemote] playerFullName]] && ![[NetworkController sharedController] isConnectedToServer])) {
1496 ITDebugLog(@"Remote application launched.");
1497 playerRunningState = ITMTRemotePlayerRunning;
1498 [[self currentRemote] begin];
1499 [self setLatestSongIdentifier:@""];
1501 refreshTimer = [[NSTimer scheduledTimerWithTimeInterval:([networkController isConnectedToServer] ? 10.0 : 0.5)
1503 selector:@selector(timerUpdate)
1505 repeats:YES] retain];
1506 //[NSThread detachNewThreadSelector:@selector(startTimerInNewThread) toTarget:self withObject:nil];
1507 if (![df boolForKey:@"UsePollingOnly"]) {
1508 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(trackChanged:) name:@"ITMTTrackChanged" object:nil];
1510 [self setupHotKeys];
1513 [self networkError:localException];
1517 - (void)applicationTerminated:(NSNotification *)note
1520 if (!note || [[[note userInfo] objectForKey:@"NSApplicationName"] isEqualToString:[[self currentRemote] playerFullName]] && ![[NetworkController sharedController] isConnectedToServer]) {
1521 ITDebugLog(@"Remote application terminated.");
1522 playerRunningState = ITMTRemotePlayerNotRunning;
1523 [[self currentRemote] halt];
1524 [refreshTimer invalidate];
1525 [refreshTimer release];
1527 [[NSNotificationCenter defaultCenter] removeObserver:self];
1528 [statusItem setEnabled:YES];
1529 [statusItem setToolTip:@"iTunes not running."];
1530 [self clearHotKeys];
1533 if ([df objectForKey:@"ShowPlayer"] != nil) {
1535 ITDebugLog(@"Setting up show player hot key.");
1536 hotKey = [[ITHotKey alloc] init];
1537 [hotKey setName:@"ShowPlayer"];
1538 [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"ShowPlayer"]]];
1539 [hotKey setTarget:self];
1540 [hotKey setAction:@selector(showPlayer)];
1541 [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]];
1545 [self networkError:localException];
1550 /*************************************************************************/
1552 #pragma mark NSApplication DELEGATE METHODS
1553 /*************************************************************************/
1555 - (void)applicationWillTerminate:(NSNotification *)note
1557 [[[NSWorkspace sharedWorkspace] notificationCenter] removeObserver:self];
1558 [networkController stopRemoteServerSearch];
1559 [self clearHotKeys];
1560 [[NSStatusBar systemStatusBar] removeStatusItem:statusItem];
1564 /*************************************************************************/
1566 #pragma mark DEALLOCATION METHOD
1567 /*************************************************************************/
1571 [self applicationTerminated:nil];
1573 [statusItem release];
1574 [statusWindowController release];
1575 [menuController release];
1576 [networkController release];
1577 [_serverCheckLock release];