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 - (ITMTRemote *)loadRemote
194 NSString *folderPath = [[NSBundle mainBundle] builtInPlugInsPath];
195 ITDebugLog(@"Gathering remotes.");
197 NSArray *bundlePathList = [NSBundle pathsForResourcesOfType:@"remote" inDirectory:folderPath];
198 NSEnumerator *enumerator = [bundlePathList objectEnumerator];
199 NSString *bundlePath;
201 while ( (bundlePath = [enumerator nextObject]) ) {
202 NSBundle* remoteBundle = [NSBundle bundleWithPath:bundlePath];
205 Class remoteClass = [remoteBundle principalClass];
207 if ([remoteClass conformsToProtocol:@protocol(ITMTRemote)] &&
208 [(NSObject *)remoteClass isKindOfClass:[NSObject class]]) {
209 id remote = [remoteClass remote];
210 ITDebugLog(@"Adding remote at path %@", bundlePath);
211 [remoteArray addObject:remote];
216 // if ( [remoteArray count] > 0 ) { // UNCOMMENT WHEN WE HAVE > 1 PLUGIN
217 // if ( [remoteArray count] > 1 ) {
218 // [remoteArray sortUsingSelector:@selector(sortAlpha:)];
220 // [self loadModuleAccessUI]; //Comment out this line to disable remote visibility
223 // NSLog(@"%@", [remoteArray objectAtIndex:0]); //DEBUG
224 return [remoteArray objectAtIndex:0];
227 /*************************************************************************/
229 #pragma mark INSTANCE METHODS
230 /*************************************************************************/
232 /*- (void)startTimerInNewThread
234 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
235 NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
236 refreshTimer = [[NSTimer scheduledTimerWithTimeInterval:0.5
238 selector:@selector(timerUpdate)
240 repeats:YES] retain];
242 ITDebugLog(@"Timer started.");
246 - (void)setBlingTime:(NSDate*)date
248 NSMutableDictionary *globalPrefs;
250 globalPrefs = [[df persistentDomainForName:@".GlobalPreferences"] mutableCopy];
252 [globalPrefs setObject:date forKey:@"ITMTTrialStart"];
253 [globalPrefs setObject:[NSNumber numberWithInt:MT_CURRENT_VERSION] forKey:@"ITMTTrialVers"];
255 [globalPrefs removeObjectForKey:@"ITMTTrialStart"];
256 [globalPrefs removeObjectForKey:@"ITMTTrialVers"];
258 [df setPersistentDomain:globalPrefs forName:@".GlobalPreferences"];
260 [globalPrefs release];
263 - (NSDate*)getBlingTime
266 return [[df persistentDomainForName:@".GlobalPreferences"] objectForKey:@"ITMTTrialStart"];
271 NSDate *now = [NSDate date];
272 if (![self blingBling]) {
273 if ( (! [self getBlingTime] ) || ([now timeIntervalSinceDate:[self getBlingTime]] < 0) ) {
274 [self setBlingTime:now];
275 } else if ([[[df persistentDomainForName:@".GlobalPreferences"] objectForKey:@"ITMTTrialVers"] intValue] < MT_CURRENT_VERSION) {
276 if ([now timeIntervalSinceDate:[self getBlingTime]] >= 345600) {
277 [self setBlingTime:[now addTimeInterval:-259200]];
279 NSMutableDictionary *globalPrefs;
281 globalPrefs = [[df persistentDomainForName:@".GlobalPreferences"] mutableCopy];
282 [globalPrefs setObject:[NSNumber numberWithInt:MT_CURRENT_VERSION] forKey:@"ITMTTrialVers"];
283 [df setPersistentDomain:globalPrefs forName:@".GlobalPreferences"];
285 [globalPrefs release];
289 if ( ([now timeIntervalSinceDate:[self getBlingTime]] >= 604800) && (blinged != YES) ) {
291 [statusItem setEnabled:NO];
292 [[ITHotKeyCenter sharedCenter] setEnabled:NO];
293 if ([refreshTimer isValid]) {
294 [refreshTimer invalidate];
295 [refreshTimer release];
298 [statusWindowController showRegistrationQueryWindow];
302 [statusItem setEnabled:YES];
303 [[ITHotKeyCenter sharedCenter] setEnabled:YES];
304 if (![refreshTimer isValid]) {
305 [refreshTimer release];
306 refreshTimer = [[NSTimer scheduledTimerWithTimeInterval:([networkController isConnectedToServer] ? 10.0 : 0.5)
308 selector:@selector(timerUpdate)
310 repeats:YES] retain];
314 [self setBlingTime:nil];
325 if ( ! ([bling checkDone] == 2475) ) {
332 - (BOOL)songIsPlaying
334 NSString *identifier = nil;
336 identifier = [[self currentRemote] playerStateUniqueIdentifier];
338 [self networkError:localException];
340 return ( ! ([identifier isEqualToString:@"0-0"]) );
343 - (BOOL)radioIsPlaying
345 ITMTRemotePlayerPlaylistClass class = nil;
347 class = [[self currentRemote] currentPlaylistClass];
349 [self networkError:localException];
351 return (class == ITMTRemotePlayerRadioPlaylist );
356 NSString *identifier = nil;
358 identifier = [[self currentRemote] playerStateUniqueIdentifier];
360 [self networkError:localException];
362 return ( ! [identifier isEqualToString:_latestSongIdentifier] );
365 - (NSString *)latestSongIdentifier
367 return _latestSongIdentifier;
370 - (void)setLatestSongIdentifier:(NSString *)newIdentifier
372 ITDebugLog(@"Setting latest song identifier:");
373 ITDebugLog(@" - Identifier: %@", newIdentifier);
374 [_latestSongIdentifier autorelease];
375 _latestSongIdentifier = [newIdentifier retain];
380 NSString *identifier = [[self currentRemote] playerStateUniqueIdentifier];
381 if (refreshTimer && identifier == nil) {
382 if ([statusItem isEnabled]) {
383 [statusItem setToolTip:@"iTunes not responding."];
385 [statusItem setEnabled:NO];
387 } else if (![statusItem isEnabled]) {
388 [statusItem setEnabled:YES];
389 [statusItem setToolTip:_toolTip];
393 if ( [self songChanged] && (timerUpdating != YES) && (playerRunningState == ITMTRemotePlayerRunning) ) {
394 ITDebugLog(@"The song changed. '%@'", _latestSongIdentifier);
395 if ([df boolForKey:@"runScripts"]) {
396 NSArray *scripts = [[NSFileManager defaultManager] directoryContentsAtPath:[NSHomeDirectory() stringByAppendingPathComponent:@"Library/Application Support/MenuTunes/Scripts"]];
397 NSEnumerator *scriptsEnum = [scripts objectEnumerator];
398 NSString *nextScript;
399 ITDebugLog(@"Running AppleScripts for song change.");
400 while ( (nextScript = [scriptsEnum nextObject]) ) {
402 NSAppleScript *currentScript = [[NSAppleScript alloc] initWithContentsOfURL:[NSURL fileURLWithPath:[[NSHomeDirectory() stringByAppendingPathComponent:@"Library/Application Support/MenuTunes/Scripts"] stringByAppendingPathComponent:nextScript]] error:&error];
403 ITDebugLog(@"Running script: %@", nextScript);
404 if (!currentScript || ![currentScript executeAndReturnError:nil]) {
405 ITDebugLog(@"Error running script %@.", nextScript);
407 [currentScript release];
412 [statusItem setEnabled:NO];
415 latestPlaylistClass = [[self currentRemote] currentPlaylistClass];
417 if ([menuController rebuildSubmenus]) {
418 if ( [df boolForKey:@"showSongInfoOnChange"] ) {
419 [self performSelector:@selector(showCurrentTrackInfo) withObject:nil afterDelay:0.0];
421 [self setLatestSongIdentifier:identifier];
422 //Create the tooltip for the status item
423 if ( [df boolForKey:@"showToolTip"] ) {
424 NSString *artist = [[self currentRemote] currentSongArtist];
425 NSString *title = [[self currentRemote] currentSongTitle];
426 ITDebugLog(@"Creating status item tooltip.");
428 _toolTip = [NSString stringWithFormat:@"%@ - %@", artist, title];
432 _toolTip = NSLocalizedString(@"noSongPlaying", @"No song is playing.");
434 [statusItem setToolTip:_toolTip];
436 [statusItem setToolTip:nil];
440 [self networkError:localException];
443 [statusItem setEnabled:YES];
446 if ([networkController isConnectedToServer]) {
447 [statusItem setMenu:([[self currentRemote] playerRunningState] == ITMTRemotePlayerRunning) ? [menuController menu] : [menuController menuForNoPlayer]];
453 ITDebugLog(@"Menu clicked.");
455 if (([[self currentRemote] playerStateUniqueIdentifier] == nil) && playerRunningState == ITMTRemotePlayerRunning) {
457 if ([statusItem isEnabled]) {
458 [statusItem setToolTip:NSLocalizedString(@"iTunesNotResponding", @"iTunes is not responding.")];
460 [statusItem setEnabled:NO];
462 NSMenu *menu = [[NSMenu alloc] init];
463 [menu addItemWithTitle:NSLocalizedString(@"iTunesNotResponding", @"iTunes is not responding.") action:nil keyEquivalent:@""];
464 [statusItem setMenu:[menu autorelease]];
467 } else if (![statusItem isEnabled]) {
468 [statusItem setEnabled:YES];
469 [statusItem setToolTip:_toolTip];
473 if ([networkController isConnectedToServer]) {
474 //Used the cached version
479 if ([[self currentRemote] playerRunningState] == ITMTRemotePlayerRunning) {
480 [statusItem setMenu:[menuController menu]];
482 [statusItem setMenu:[menuController menuForNoPlayer]];
485 [self networkError:localException];
489 - (void)trackChanged:(NSNotification *)note
491 //If we're running the timer, shut it off since we don't need it!
492 if (refreshTimer && [refreshTimer isValid]) {
493 ITDebugLog(@"Invalidating refresh timer.");
494 [refreshTimer invalidate];
495 [refreshTimer release];
499 if (![self songChanged]) {
502 NSString *identifier = [[self currentRemote] playerStateUniqueIdentifier];
503 if ( [df boolForKey:@"showSongInfoOnChange"] ) {
504 [self performSelector:@selector(showCurrentTrackInfo) withObject:nil afterDelay:0.0];
506 [_lastTrackInfo release];
507 _lastTrackInfo = [[note userInfo] retain];
509 [self setLatestSongIdentifier:identifier];
510 ITDebugLog(@"The song changed. '%@'", _latestSongIdentifier);
511 if ([df boolForKey:@"runScripts"]) {
512 NSArray *scripts = [[NSFileManager defaultManager] directoryContentsAtPath:[NSHomeDirectory() stringByAppendingPathComponent:@"Library/Application Support/MenuTunes/Scripts"]];
513 NSEnumerator *scriptsEnum = [scripts objectEnumerator];
514 NSString *nextScript;
515 ITDebugLog(@"Running AppleScripts for song change.");
516 while ( (nextScript = [scriptsEnum nextObject]) ) {
518 NSAppleScript *currentScript = [[NSAppleScript alloc] initWithContentsOfURL:[NSURL fileURLWithPath:[[NSHomeDirectory() stringByAppendingPathComponent:@"Library/Application Support/MenuTunes/Scripts"] stringByAppendingPathComponent:nextScript]] error:&error];
519 ITDebugLog(@"Running script: %@", nextScript);
520 if (!currentScript || ![currentScript executeAndReturnError:nil]) {
521 ITDebugLog(@"Error running script %@.", nextScript);
523 [currentScript release];
527 [statusItem setEnabled:NO];
530 latestPlaylistClass = [[self currentRemote] currentPlaylistClass];
532 if ([menuController rebuildSubmenus]) {
533 /*if ( [df boolForKey:@"showSongInfoOnChange"] ) {
534 [self performSelector:@selector(showCurrentTrackInfo) withObject:nil afterDelay:0.0];
536 [self setLatestSongIdentifier:identifier];
537 //Create the tooltip for the status item
538 if ( [df boolForKey:@"showToolTip"] ) {
539 ITDebugLog(@"Creating status item tooltip.");
540 NSString *artist = [_lastTrackInfo objectForKey:@"Artist"], *title = [_lastTrackInfo objectForKey:@"Name"];
542 _toolTip = [NSString stringWithFormat:@"%@ - %@", artist, title];
546 _toolTip = NSLocalizedString(@"noSongPlaying", @"No song is playing.");;
548 [statusItem setToolTip:_toolTip];
550 [statusItem setToolTip:nil];
554 [self networkError:localException];
557 [statusItem setEnabled:YES];
559 if ([networkController isConnectedToServer]) {
560 [statusItem setMenu:([[self currentRemote] playerRunningState] == ITMTRemotePlayerRunning) ? [menuController menu] : [menuController menuForNoPlayer]];
573 ITMTRemotePlayerPlayingState state = [[self currentRemote] playerPlayingState];
574 ITDebugLog(@"Play/Pause toggled");
575 if (state == ITMTRemotePlayerPlaying) {
576 [[self currentRemote] pause];
577 } else if ((state == ITMTRemotePlayerForwarding) || (state == ITMTRemotePlayerRewinding)) {
578 [[self currentRemote] pause];
579 [[self currentRemote] play];
581 [[self currentRemote] play];
584 [self networkError:localException];
594 ITDebugLog(@"Going to next song.");
596 [[self currentRemote] goToNextSong];
598 [self networkError:localException];
607 ITDebugLog(@"Going to previous song.");
609 [[self currentRemote] goToPreviousSong];
611 [self networkError:localException];
620 ITDebugLog(@"Fast forwarding.");
622 [[self currentRemote] forward];
624 [self networkError:localException];
633 ITDebugLog(@"Rewinding.");
635 [[self currentRemote] rewind];
637 [self networkError:localException];
644 - (void)selectPlaylistAtIndex:(int)index
646 ITDebugLog(@"Selecting playlist %i", index);
648 [[self currentRemote] switchToPlaylistAtIndex:(index % 1000) ofSourceAtIndex:(index / 1000)];
649 //[[self currentRemote] switchToPlaylistAtIndex:index];
651 [self networkError:localException];
658 - (void)selectSongAtIndex:(int)index
660 ITDebugLog(@"Selecting song %i", index);
662 [[self currentRemote] switchToSongAtIndex:index];
664 [self networkError:localException];
671 - (void)selectSongRating:(int)rating
673 ITDebugLog(@"Selecting song rating %i", rating);
675 [[self currentRemote] setCurrentSongRating:(float)rating / 100.0];
677 [self networkError:localException];
684 - (void)selectEQPresetAtIndex:(int)index
686 ITDebugLog(@"Selecting EQ preset %i", index);
689 [[self currentRemote] setEqualizerEnabled:![[self currentRemote] equalizerEnabled]];
691 [[self currentRemote] switchToEQAtIndex:index];
694 [self networkError:localException];
701 - (void)makePlaylistWithTerm:(NSString *)term ofType:(int)type
703 ITDebugLog(@"Making playlist with term %@, type %i", term, type);
705 [[self currentRemote] makePlaylistWithTerm:term ofType:type];
707 [self networkError:localException];
709 ITDebugLog(@"Done making playlist");
714 ITDebugLog(@"Beginning show player.");
715 //if ( ( playerRunningState == ITMTRemotePlayerRunning) ) {
716 ITDebugLog(@"Showing player interface.");
718 [[self currentRemote] showPrimaryInterface];
720 [self networkError:localException];
723 ITDebugLog(@"Launching player.");
726 if ( (path = [df stringForKey:@"CustomPlayerPath"]) ) {
728 pathITDebugLog(@"Showing player interface."); = [[self currentRemote] playerFullName];
730 if (![[NSWorkspace sharedWorkspace] launchApplication:path]) {
731 ITDebugLog(@"Error Launching Player");
734 [self networkError:localException];
737 ITDebugLog(@"Finished show player.");
740 - (void)showPreferences
742 ITDebugLog(@"Show preferences.");
743 [[PreferencesController sharedPrefs] showPrefsWindow:self];
746 - (void)showPreferencesAndClose
748 ITDebugLog(@"Show preferences.");
749 [[PreferencesController sharedPrefs] showPrefsWindow:self];
750 [[StatusWindow sharedWindow] setLocked:NO];
751 [[StatusWindow sharedWindow] vanish:self];
752 [[StatusWindow sharedWindow] setIgnoresMouseEvents:YES];
755 - (void)showTestWindow
757 [self showCurrentTrackInfo];
760 - (void)quitMenuTunes
762 ITDebugLog(@"Quitting MenuTunes.");
763 [NSApp terminate:self];
769 - (MenuController *)menuController
771 return menuController;
774 - (void)closePreferences
776 ITDebugLog(@"Preferences closed.");
777 if ( ( playerRunningState == ITMTRemotePlayerRunning) ) {
782 - (ITMTRemote *)currentRemote
784 if ([networkController isConnectedToServer] && ![[networkController networkObject] isValid]) {
785 [self networkError:nil];
788 return currentRemote;
799 NSEnumerator *hotKeyEnumerator = [[[ITHotKeyCenter sharedCenter] allHotKeys] objectEnumerator];
800 ITHotKey *nextHotKey;
801 ITDebugLog(@"Clearing hot keys.");
802 while ( (nextHotKey = [hotKeyEnumerator nextObject]) ) {
803 [[ITHotKeyCenter sharedCenter] unregisterHotKey:nextHotKey];
805 ITDebugLog(@"Done clearing hot keys.");
811 ITDebugLog(@"Setting up hot keys.");
813 if (playerRunningState == ITMTRemotePlayerNotRunning && ![[NetworkController sharedController] isConnectedToServer]) {
817 if ([df objectForKey:@"PlayPause"] != nil) {
818 ITDebugLog(@"Setting up play pause hot key.");
819 hotKey = [[ITHotKey alloc] init];
820 [hotKey setName:@"PlayPause"];
821 [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"PlayPause"]]];
822 [hotKey setTarget:self];
823 [hotKey setAction:@selector(playPause)];
824 [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]];
827 if ([df objectForKey:@"NextTrack"] != nil) {
828 ITDebugLog(@"Setting up next track hot key.");
829 hotKey = [[ITHotKey alloc] init];
830 [hotKey setName:@"NextTrack"];
831 [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"NextTrack"]]];
832 [hotKey setTarget:self];
833 [hotKey setAction:@selector(nextSong)];
834 [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]];
837 if ([df objectForKey:@"PrevTrack"] != nil) {
838 ITDebugLog(@"Setting up previous track hot key.");
839 hotKey = [[ITHotKey alloc] init];
840 [hotKey setName:@"PrevTrack"];
841 [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"PrevTrack"]]];
842 [hotKey setTarget:self];
843 [hotKey setAction:@selector(prevSong)];
844 [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]];
847 if ([df objectForKey:@"FastForward"] != nil) {
848 ITDebugLog(@"Setting up fast forward hot key.");
849 hotKey = [[ITHotKey alloc] init];
850 [hotKey setName:@"FastForward"];
851 [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"FastForward"]]];
852 [hotKey setTarget:self];
853 [hotKey setAction:@selector(fastForward)];
854 [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]];
857 if ([df objectForKey:@"Rewind"] != nil) {
858 ITDebugLog(@"Setting up rewind hot key.");
859 hotKey = [[ITHotKey alloc] init];
860 [hotKey setName:@"Rewind"];
861 [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"Rewind"]]];
862 [hotKey setTarget:self];
863 [hotKey setAction:@selector(rewind)];
864 [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]];
867 if ([df objectForKey:@"ShowPlayer"] != nil) {
868 ITDebugLog(@"Setting up show player hot key.");
869 hotKey = [[ITHotKey alloc] init];
870 [hotKey setName:@"ShowPlayer"];
871 [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"ShowPlayer"]]];
872 [hotKey setTarget:self];
873 [hotKey setAction:@selector(showPlayer)];
874 [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]];
877 if ([df objectForKey:@"TrackInfo"] != nil) {
878 ITDebugLog(@"Setting up track info hot key.");
879 hotKey = [[ITHotKey alloc] init];
880 [hotKey setName:@"TrackInfo"];
881 [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"TrackInfo"]]];
882 [hotKey setTarget:self];
883 [hotKey setAction:@selector(showCurrentTrackInfo)];
884 [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]];
887 if ([df objectForKey:@"UpcomingSongs"] != nil) {
888 ITDebugLog(@"Setting up upcoming songs hot key.");
889 hotKey = [[ITHotKey alloc] init];
890 [hotKey setName:@"UpcomingSongs"];
891 [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"UpcomingSongs"]]];
892 [hotKey setTarget:self];
893 [hotKey setAction:@selector(showUpcomingSongs)];
894 [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]];
897 if ([df objectForKey:@"ToggleLoop"] != nil) {
898 ITDebugLog(@"Setting up toggle loop hot key.");
899 hotKey = [[ITHotKey alloc] init];
900 [hotKey setName:@"ToggleLoop"];
901 [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"ToggleLoop"]]];
902 [hotKey setTarget:self];
903 [hotKey setAction:@selector(toggleLoop)];
904 [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]];
907 if ([df objectForKey:@"ToggleShuffle"] != nil) {
908 ITDebugLog(@"Setting up toggle shuffle hot key.");
909 hotKey = [[ITHotKey alloc] init];
910 [hotKey setName:@"ToggleShuffle"];
911 [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"ToggleShuffle"]]];
912 [hotKey setTarget:self];
913 [hotKey setAction:@selector(toggleShuffle)];
914 [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]];
917 if ([df objectForKey:@"IncrementVolume"] != nil) {
918 ITDebugLog(@"Setting up increment volume hot key.");
919 hotKey = [[ITHotKey alloc] init];
920 [hotKey setName:@"IncrementVolume"];
921 [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"IncrementVolume"]]];
922 [hotKey setTarget:self];
923 [hotKey setAction:@selector(incrementVolume)];
924 [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]];
927 if ([df objectForKey:@"DecrementVolume"] != nil) {
928 ITDebugLog(@"Setting up decrement volume hot key.");
929 hotKey = [[ITHotKey alloc] init];
930 [hotKey setName:@"DecrementVolume"];
931 [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"DecrementVolume"]]];
932 [hotKey setTarget:self];
933 [hotKey setAction:@selector(decrementVolume)];
934 [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]];
937 if ([df objectForKey:@"IncrementRating"] != nil) {
938 ITDebugLog(@"Setting up increment rating hot key.");
939 hotKey = [[ITHotKey alloc] init];
940 [hotKey setName:@"IncrementRating"];
941 [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"IncrementRating"]]];
942 [hotKey setTarget:self];
943 [hotKey setAction:@selector(incrementRating)];
944 [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]];
947 if ([df objectForKey:@"DecrementRating"] != nil) {
948 ITDebugLog(@"Setting up decrement rating hot key.");
949 hotKey = [[ITHotKey alloc] init];
950 [hotKey setName:@"DecrementRating"];
951 [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"DecrementRating"]]];
952 [hotKey setTarget:self];
953 [hotKey setAction:@selector(decrementRating)];
954 [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]];
957 if ([df objectForKey:@"PopupMenu"] != nil) {
958 ITDebugLog(@"Setting up popup menu hot key.");
959 hotKey = [[ITHotKey alloc] init];
960 [hotKey setName:@"PopupMenu"];
961 [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"PopupMenu"]]];
962 [hotKey setTarget:self];
963 [hotKey setAction:@selector(popupMenu)];
964 [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]];
968 for (i = 0; i <= 5; i++) {
969 NSString *curName = [NSString stringWithFormat:@"SetRating%i", i];
970 if ([df objectForKey:curName] != nil) {
971 ITDebugLog(@"Setting up set rating %i hot key.", i);
972 hotKey = [[ITHotKey alloc] init];
973 [hotKey setName:curName];
974 [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:curName]]];
975 [hotKey setTarget:self];
976 [hotKey setAction:@selector(setRating:)];
977 [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]];
980 ITDebugLog(@"Finished setting up hot keys.");
983 - (void)showCurrentTrackInfo
985 ITMTRemotePlayerSource source = 0;
986 NSString *title = nil;
987 NSString *album = nil;
988 NSString *artist = nil;
989 NSString *composer = nil;
990 NSString *time = nil;
991 NSString *track = nil;
996 ITDebugLog(@"Showing track info status window.");
999 source = [[self currentRemote] currentSource];
1000 title = [[self currentRemote] currentSongTitle];
1002 [self networkError:localException];
1006 if ( [df boolForKey:@"showAlbumArtwork"] ) {
1007 NSSize oldSize, newSize;
1009 art = [[self currentRemote] currentSongAlbumArt];
1010 oldSize = [art size];
1011 if (oldSize.width > oldSize.height) newSize = NSMakeSize(110,oldSize.height * (110.0f / oldSize.width));
1012 else newSize = NSMakeSize(oldSize.width * (110.0f / oldSize.height),110);
1013 art = [[[[NSImage alloc] initWithData:[art TIFFRepresentation]] autorelease] imageScaledSmoothlyToSize:newSize];
1015 [self networkError:localException];
1019 if ( [df boolForKey:@"showAlbum"] ) {
1021 album = [[self currentRemote] currentSongAlbum];
1023 [self networkError:localException];
1027 if ( [df boolForKey:@"showArtist"] ) {
1029 artist = [[self currentRemote] currentSongArtist];
1031 [self networkError:localException];
1035 if ( [df boolForKey:@"showComposer"] ) {
1037 composer = [[self currentRemote] currentSongComposer];
1039 [self networkError:localException];
1043 if ( [df boolForKey:@"showTime"] ) {
1045 time = [NSString stringWithFormat:@"%@: %@ / %@",
1046 NSLocalizedString(@"time", @"Time"),
1047 [[self currentRemote] currentSongElapsed],
1048 [[self currentRemote] currentSongLength]];
1050 [self networkError:localException];
1054 if ( [df boolForKey:@"showTrackNumber"] ) {
1059 trackNo = [[self currentRemote] currentSongTrack];
1060 trackCount = [[self currentRemote] currentAlbumTrackCount];
1062 [self networkError:localException];
1065 if ( (trackNo > 0) || (trackCount > 0) ) {
1066 track = [NSString stringWithFormat:@"%@: %i %@ %i",
1067 @"Track", trackNo, @"of", trackCount];
1071 if ( [df boolForKey:@"showTrackRating"] ) {
1072 float currentRating = 0;
1075 currentRating = [[self currentRemote] currentSongRating];
1077 [self networkError:localException];
1080 if (currentRating >= 0.0) {
1081 rating = ( currentRating * 5 );
1085 if ( [df boolForKey:@"showPlayCount"] && ![self radioIsPlaying] && [[self currentRemote] currentSource] == ITMTRemoteLibrarySource ) {
1087 playCount = [[self currentRemote] currentSongPlayCount];
1089 [self networkError:localException];
1093 title = NSLocalizedString(@"noSongPlaying", @"No song is playing.");
1095 ITDebugLog(@"Showing current track info status window.");
1096 [statusWindowController showSongInfoWindowWithSource:source
1108 - (void)showUpcomingSongs
1112 numSongs = [[self currentRemote] numberOfSongsInPlaylistAtIndex:[[self currentRemote] currentPlaylistIndex]];
1114 [self networkError:localException];
1117 ITDebugLog(@"Showing upcoming songs status window.");
1120 int numSongsInAdvance = [df integerForKey:@"SongsInAdvance"];
1121 NSMutableArray *songList = [NSMutableArray arrayWithCapacity:numSongsInAdvance];
1122 int curTrack = [[self currentRemote] currentSongIndex];
1125 for (i = curTrack + 1; i <= curTrack + numSongsInAdvance; i++) {
1126 if (i <= numSongs) {
1127 [songList addObject:[[self currentRemote] songTitleAtIndex:i]];
1131 if ([songList count] == 0) {
1132 [songList addObject:NSLocalizedString(@"noUpcomingSongs", @"No upcoming songs.")];
1135 [statusWindowController showUpcomingSongsWindowWithTitles:songList];
1137 [statusWindowController showUpcomingSongsWindowWithTitles:[NSArray arrayWithObject:NSLocalizedString(@"noUpcomingSongs", @"No upcoming songs.")]];
1140 [self networkError:localException];
1149 NSMenu *menu = [statusItem menu];
1150 [(NSCarbonMenuImpl *)[menu _menuImpl] popUpMenu:menu atLocation:[NSEvent mouseLocation] width:1 forView:nil withSelectedItem:-30 withFont:[NSFont menuFontOfSize:32]];
1155 - (void)incrementVolume
1158 float volume = [[self currentRemote] volume];
1159 float dispVol = volume;
1160 ITDebugLog(@"Incrementing volume.");
1169 ITDebugLog(@"Setting volume to %f", volume);
1170 [[self currentRemote] setVolume:volume];
1172 // Show volume status window
1173 [statusWindowController showVolumeWindowWithLevel:dispVol];
1175 [self networkError:localException];
1179 - (void)decrementVolume
1182 float volume = [[self currentRemote] volume];
1183 float dispVol = volume;
1184 ITDebugLog(@"Decrementing volume.");
1193 ITDebugLog(@"Setting volume to %f", volume);
1194 [[self currentRemote] setVolume:volume];
1196 //Show volume status window
1197 [statusWindowController showVolumeWindowWithLevel:dispVol];
1199 [self networkError:localException];
1203 - (void)incrementRating
1206 float rating = [[self currentRemote] currentSongRating];
1207 ITDebugLog(@"Incrementing rating.");
1209 if ([[self currentRemote] currentPlaylistIndex] == 0) {
1210 ITDebugLog(@"No song playing, rating change aborted.");
1218 ITDebugLog(@"Setting rating to %f", rating);
1219 [[self currentRemote] setCurrentSongRating:rating];
1221 //Show rating status window
1222 [statusWindowController showRatingWindowWithRating:rating];
1224 [self networkError:localException];
1228 - (void)decrementRating
1231 float rating = [[self currentRemote] currentSongRating];
1232 ITDebugLog(@"Decrementing rating.");
1234 if ([[self currentRemote] currentPlaylistIndex] == 0) {
1235 ITDebugLog(@"No song playing, rating change aborted.");
1243 ITDebugLog(@"Setting rating to %f", rating);
1244 [[self currentRemote] setCurrentSongRating:rating];
1246 //Show rating status window
1247 [statusWindowController showRatingWindowWithRating:rating];
1249 [self networkError:localException];
1253 - (void)setRating:(ITHotKey *)sender
1255 int stars = [[sender name] characterAtIndex:9] - 48;
1256 [self selectSongRating:stars * 20];
1257 [statusWindowController showRatingWindowWithRating:(float)stars / 5.0];
1263 ITMTRemotePlayerRepeatMode repeatMode = [[self currentRemote] repeatMode];
1264 ITDebugLog(@"Toggling repeat mode.");
1265 switch (repeatMode) {
1266 case ITMTRemotePlayerRepeatOff:
1267 repeatMode = ITMTRemotePlayerRepeatAll;
1269 case ITMTRemotePlayerRepeatAll:
1270 repeatMode = ITMTRemotePlayerRepeatOne;
1272 case ITMTRemotePlayerRepeatOne:
1273 repeatMode = ITMTRemotePlayerRepeatOff;
1276 ITDebugLog(@"Setting repeat mode to %i", repeatMode);
1277 [[self currentRemote] setRepeatMode:repeatMode];
1279 //Show loop status window
1280 [statusWindowController showRepeatWindowWithMode:repeatMode];
1282 [self networkError:localException];
1286 - (void)toggleShuffle
1289 BOOL newShuffleEnabled = ( ! [[self currentRemote] shuffleEnabled] );
1290 ITDebugLog(@"Toggling shuffle mode.");
1291 [[self currentRemote] setShuffleEnabled:newShuffleEnabled];
1292 //Show shuffle status window
1293 ITDebugLog(@"Setting shuffle mode to %i", newShuffleEnabled);
1294 [statusWindowController showShuffleWindow:newShuffleEnabled];
1296 [self networkError:localException];
1300 - (void)registerNowOK
1302 [[StatusWindow sharedWindow] setLocked:NO];
1303 [[StatusWindow sharedWindow] vanish:self];
1304 [[StatusWindow sharedWindow] setIgnoresMouseEvents:YES];
1309 - (void)registerNowCancel
1311 [[StatusWindow sharedWindow] setLocked:NO];
1312 [[StatusWindow sharedWindow] vanish:self];
1313 [[StatusWindow sharedWindow] setIgnoresMouseEvents:YES];
1315 [NSApp terminate:self];
1318 /*************************************************************************/
1320 #pragma mark NETWORK HANDLERS
1321 /*************************************************************************/
1323 - (void)setServerStatus:(BOOL)newStatus
1327 [networkController setServerStatus:YES];
1330 [networkController setServerStatus:NO];
1334 - (int)connectToServer
1337 ITDebugLog(@"Attempting to connect to shared remote.");
1338 result = [networkController connectToHost:[df stringForKey:@"sharedPlayerHost"]];
1341 [[PreferencesController sharedPrefs] resetRemotePlayerTextFields];
1342 currentRemote = [[[networkController networkObject] remote] retain];
1344 [self setupHotKeys];
1345 //playerRunningState = ITMTRemotePlayerRunning;
1346 playerRunningState = [[self currentRemote] playerRunningState];
1348 [refreshTimer invalidate];
1350 refreshTimer = [[NSTimer scheduledTimerWithTimeInterval:([networkController isConnectedToServer] ? 10.0 : 0.5)
1352 selector:@selector(timerUpdate)
1354 repeats:YES] retain];
1356 ITDebugLog(@"Connection successful.");
1358 } else if (result == 0) {
1359 ITDebugLog(@"Connection failed.");
1360 currentRemote = [remoteArray objectAtIndex:0];
1363 //Do something about the password being invalid
1364 ITDebugLog(@"Connection failed.");
1365 currentRemote = [remoteArray objectAtIndex:0];
1370 - (BOOL)disconnectFromServer
1372 ITDebugLog(@"Disconnecting from shared remote.");
1374 [currentRemote release];
1375 currentRemote = [remoteArray objectAtIndex:0];
1376 [networkController disconnect];
1378 if ([[self currentRemote] playerRunningState] == ITMTRemotePlayerRunning) {
1379 [self applicationLaunched:nil];
1381 [self applicationTerminated:nil];
1389 - (void)checkForRemoteServer
1391 [self checkForRemoteServerAndConnectImmediately:NO];
1394 - (void)checkForRemoteServerAndConnectImmediately:(BOOL)connectImmediately
1396 ITDebugLog(@"Checking for remote server.");
1397 if (!_checkingForServer) {
1398 if (!_serverCheckLock) {
1399 _serverCheckLock = [[NSLock alloc] init];
1401 [_serverCheckLock lock];
1402 _checkingForServer = YES;
1403 [_serverCheckLock unlock];
1404 [NSThread detachNewThreadSelector:@selector(runRemoteServerCheck:) toTarget:self withObject:[NSNumber numberWithBool:connectImmediately]];
1408 - (void)runRemoteServerCheck:(id)sender
1410 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
1411 ITDebugLog(@"Remote server check running.");
1412 if ([networkController checkForServerAtHost:[df stringForKey:@"sharedPlayerHost"]]) {
1413 ITDebugLog(@"Remote server found.");
1414 if ([sender boolValue]) {
1415 [self performSelectorOnMainThread:@selector(connectToServer) withObject:nil waitUntilDone:NO];
1417 [self performSelectorOnMainThread:@selector(remoteServerFound:) withObject:nil waitUntilDone:NO];
1420 ITDebugLog(@"Remote server not found.");
1421 [self performSelectorOnMainThread:@selector(remoteServerNotFound:) withObject:nil waitUntilDone:NO];
1423 [_serverCheckLock lock];
1424 _checkingForServer = NO;
1425 [_serverCheckLock unlock];
1429 - (void)remoteServerFound:(id)sender
1431 if (![networkController isServerOn] && ![networkController isConnectedToServer]) {
1432 [[StatusWindowController sharedController] showReconnectQueryWindow];
1436 - (void)remoteServerNotFound:(id)sender
1438 if (![[NetworkController sharedController] isConnectedToServer]) {
1439 [NSTimer scheduledTimerWithTimeInterval:90.0 target:self selector:@selector(checkForRemoteServer) userInfo:nil repeats:NO];
1443 - (void)networkError:(NSException *)exception
1445 ITDebugLog(@"Remote exception thrown: %@: %@", [exception name], [exception reason]);
1446 if ( ((exception == nil) || [[exception name] isEqualToString:NSPortTimeoutException]) && [networkController isConnectedToServer]) {
1447 //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);
1448 [[StatusWindowController sharedController] showNetworkErrorQueryWindow];
1449 if ([self disconnectFromServer]) {
1450 [[PreferencesController sharedPrefs] resetRemotePlayerTextFields];
1451 [NSTimer scheduledTimerWithTimeInterval:90.0 target:self selector:@selector(checkForRemoteServer) userInfo:nil repeats:NO];
1453 ITDebugLog(@"CRITICAL ERROR, DISCONNECTING!");
1460 /*if ([self connectToServer] == 0) {
1461 [NSTimer scheduledTimerWithTimeInterval:90.0 target:self selector:@selector(checkForRemoteServer) userInfo:nil repeats:NO];
1463 [self checkForRemoteServerAndConnectImmediately:YES];
1464 [[StatusWindow sharedWindow] setLocked:NO];
1465 [[StatusWindow sharedWindow] vanish:self];
1466 [[StatusWindow sharedWindow] setIgnoresMouseEvents:YES];
1469 - (void)cancelReconnect
1471 [[StatusWindow sharedWindow] setLocked:NO];
1472 [[StatusWindow sharedWindow] vanish:self];
1473 [[StatusWindow sharedWindow] setIgnoresMouseEvents:YES];
1476 /*************************************************************************/
1478 #pragma mark WORKSPACE NOTIFICATION HANDLERS
1479 /*************************************************************************/
1481 - (void)applicationLaunched:(NSNotification *)note
1484 if (!note || ([[[note userInfo] objectForKey:@"NSApplicationName"] isEqualToString:[[self currentRemote] playerFullName]] && ![[NetworkController sharedController] isConnectedToServer])) {
1485 ITDebugLog(@"Remote application launched.");
1486 playerRunningState = ITMTRemotePlayerRunning;
1487 [[self currentRemote] begin];
1488 [self setLatestSongIdentifier:@""];
1490 refreshTimer = [[NSTimer scheduledTimerWithTimeInterval:([networkController isConnectedToServer] ? 10.0 : 0.5)
1492 selector:@selector(timerUpdate)
1494 repeats:YES] retain];
1495 //[NSThread detachNewThreadSelector:@selector(startTimerInNewThread) toTarget:self withObject:nil];
1496 if (![df boolForKey:@"UsePollingOnly"]) {
1497 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(trackChanged:) name:@"ITMTTrackChanged" object:nil];
1499 [self setupHotKeys];
1502 [self networkError:localException];
1506 - (void)applicationTerminated:(NSNotification *)note
1509 if (!note || [[[note userInfo] objectForKey:@"NSApplicationName"] isEqualToString:[[self currentRemote] playerFullName]] && ![[NetworkController sharedController] isConnectedToServer]) {
1510 ITDebugLog(@"Remote application terminated.");
1511 playerRunningState = ITMTRemotePlayerNotRunning;
1512 [[self currentRemote] halt];
1513 [refreshTimer invalidate];
1514 [refreshTimer release];
1516 [[NSNotificationCenter defaultCenter] removeObserver:self name:@"ITMTTrackChanged" object:nil];
1517 [statusItem setEnabled:YES];
1518 [statusItem setToolTip:@"iTunes not running."];
1519 [self clearHotKeys];
1522 if ([df objectForKey:@"ShowPlayer"] != nil) {
1524 ITDebugLog(@"Setting up show player hot key.");
1525 hotKey = [[ITHotKey alloc] init];
1526 [hotKey setName:@"ShowPlayer"];
1527 [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"ShowPlayer"]]];
1528 [hotKey setTarget:self];
1529 [hotKey setAction:@selector(showPlayer)];
1530 [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]];
1534 [self networkError:localException];
1539 /*************************************************************************/
1541 #pragma mark NSApplication DELEGATE METHODS
1542 /*************************************************************************/
1544 - (void)applicationWillTerminate:(NSNotification *)note
1546 [[[NSWorkspace sharedWorkspace] notificationCenter] removeObserver:self];
1547 [networkController stopRemoteServerSearch];
1548 [self clearHotKeys];
1549 [[NSStatusBar systemStatusBar] removeStatusItem:statusItem];
1552 - (void)applicationDidBecomeActive:(NSNotification *)note
1554 if (_open && !blinged && ![NSApp mainWindow] && ([[StatusWindow sharedWindow] exitMode] == ITTransientStatusWindowExitAfterDelay)) {
1555 [[MainController sharedController] showPreferences];
1559 /*************************************************************************/
1561 #pragma mark DEALLOCATION METHOD
1562 /*************************************************************************/
1566 [self applicationTerminated:nil];
1568 [statusItem release];
1569 [statusWindowController release];
1570 [menuController release];
1571 [networkController release];
1572 [_serverCheckLock release];