From: Kent Sutherland Date: Wed, 26 May 2004 00:15:15 +0000 (+0000) Subject: More networking improvements. X-Git-Tag: v1.3~3 X-Git-Url: http://git.ithinksw.org/MenuTunes.git/commitdiff_plain/0204d8a09b6f8fba377e6f856d78a50a36fa3010 More networking improvements. --- diff --git a/MainController.h b/MainController.h index 6db9977..40887f9 100755 --- a/MainController.h +++ b/MainController.h @@ -77,7 +77,7 @@ - (void)setServerStatus:(BOOL)newStatus; - (int)connectToServer; - (BOOL)disconnectFromServer; -- (void)checkForRemoteServer; +- (void)checkForRemoteServerAndConnectImmediately:(BOOL)connectImmediately; - (void)networkError:(NSException *)exception; // diff --git a/MainController.m b/MainController.m index b2b8195..ecf39ba 100755 --- a/MainController.m +++ b/MainController.m @@ -89,7 +89,7 @@ static MainController *sharedController; if ([df boolForKey:@"enableSharing"]) { [self setServerStatus:YES]; } else if ([df boolForKey:@"useSharedPlayer"]) { - [self checkForRemoteServer]; + [self checkForRemoteServerAndConnectImmediately:YES]; } //Setup for notification of the remote player launching or quitting @@ -1131,9 +1131,14 @@ static MainController *sharedController; } - (void)checkForRemoteServer +{ + [self checkForRemoteServerAndConnectImmediately:NO]; +} + +- (void)checkForRemoteServerAndConnectImmediately:(BOOL)connectImmediately { ITDebugLog(@"Checking for remote server."); - [NSThread detachNewThreadSelector:@selector(runRemoteServerCheck:) toTarget:self withObject:nil]; + [NSThread detachNewThreadSelector:@selector(runRemoteServerCheck:) toTarget:self withObject:[NSNumber numberWithBool:connectImmediately]]; } - (void)runRemoteServerCheck:(id)sender @@ -1142,7 +1147,11 @@ static MainController *sharedController; ITDebugLog(@"Remote server check running."); if ([networkController checkForServerAtHost:[df stringForKey:@"sharedPlayerHost"]]) { ITDebugLog(@"Remote server found."); - [self performSelectorOnMainThread:@selector(remoteServerFound:) withObject:nil waitUntilDone:NO]; + if ([sender boolValue]) { + [self performSelectorOnMainThread:@selector(connectToServer) withObject:nil waitUntilDone:NO]; + } else { + [self performSelectorOnMainThread:@selector(remoteServerFound:) withObject:nil waitUntilDone:NO]; + } } else { ITDebugLog(@"Remote server not found."); [self performSelectorOnMainThread:@selector(remoteServerNotFound:) withObject:nil waitUntilDone:NO]; @@ -1159,7 +1168,9 @@ static MainController *sharedController; - (void)remoteServerNotFound:(id)sender { - [NSTimer scheduledTimerWithTimeInterval:90.0 target:self selector:@selector(checkForRemoteServer) userInfo:nil repeats:NO]; + if (![[NetworkController sharedController] isConnectedToServer]) { + [NSTimer scheduledTimerWithTimeInterval:90.0 target:self selector:@selector(checkForRemoteServer) userInfo:nil repeats:NO]; + } } - (void)networkError:(NSException *)exception @@ -1179,9 +1190,10 @@ static MainController *sharedController; - (void)reconnect { - if ([self connectToServer] == 0) { + /*if ([self connectToServer] == 0) { [NSTimer scheduledTimerWithTimeInterval:90.0 target:self selector:@selector(checkForRemoteServer) userInfo:nil repeats:NO]; - } + }*/ + [self checkForRemoteServerAndConnectImmediately:YES]; [[StatusWindow sharedWindow] setLocked:NO]; [[StatusWindow sharedWindow] vanish:self]; [[StatusWindow sharedWindow] setIgnoresMouseEvents:YES]; diff --git a/MenuController.m b/MenuController.m index 6ae64a3..a8e79e4 100755 --- a/MenuController.m +++ b/MenuController.m @@ -47,7 +47,7 @@ NSEnumerator *itemEnum; ITHotKey *hotKey; NSArray *hotKeys = [[ITHotKeyCenter sharedCenter] allHotKeys]; - int currentSongRating; + int currentSongRating = 0; //Get the information NS_DURING @@ -226,7 +226,7 @@ ITDebugLog(@"Check to see if a Track is playing..."); //Handle playing radio too if (_currentPlaylist) { - NSString *title; + NSString *title = nil; NS_DURING title = [[[MainController sharedController] currentRemote] currentSongTitle]; NS_HANDLER @@ -244,7 +244,7 @@ if (!_playingRadio) { if ([defaults boolForKey:@"showAlbum"]) { - NSString *curAlbum; + NSString *curAlbum = nil; NS_DURING curAlbum = [[[MainController sharedController] currentRemote] currentSongAlbum]; NS_HANDLER @@ -258,7 +258,7 @@ } if ([defaults boolForKey:@"showArtist"]) { - NSString *curArtist; + NSString *curArtist = nil; NS_DURING curArtist = [[[MainController sharedController] currentRemote] currentSongArtist]; NS_HANDLER @@ -272,7 +272,7 @@ } if ([defaults boolForKey:@"showComposer"]) { - NSString *curComposer; + NSString *curComposer = nil; NS_DURING curComposer = [[[MainController sharedController] currentRemote] currentSongComposer]; NS_HANDLER @@ -286,7 +286,7 @@ } if ([defaults boolForKey:@"showTrackNumber"]) { - int track; + int track = 0; NS_DURING track = [[[MainController sharedController] currentRemote] currentSongTrack]; NS_HANDLER @@ -431,7 +431,7 @@ - (NSMenu *)menuForNoPlayer { NSMenu *menu = [[NSMenu alloc] initWithTitle:@""]; - id tempItem; + id tempItem = nil; ITDebugLog(@"Creating menu for when player isn't running."); NS_DURING ITDebugLog(@"Add \"Open %@\" menu item.", [[[MainController sharedController] currentRemote] playerSimpleName]); @@ -518,7 +518,7 @@ - (NSMenu *)upcomingSongsMenu { NSMenu *upcomingSongsMenu = [[NSMenu alloc] initWithTitle:@""]; - int numSongs, numSongsInAdvance = [[NSUserDefaults standardUserDefaults] integerForKey:@"SongsInAdvance"]; + int numSongs = 0, numSongsInAdvance = [[NSUserDefaults standardUserDefaults] integerForKey:@"SongsInAdvance"]; NS_DURING numSongs = [[[MainController sharedController] currentRemote] numberOfSongsInPlaylistAtIndex:_currentPlaylist]; @@ -532,7 +532,7 @@ int i; for (i = _currentTrack + 1; i <= _currentTrack + numSongsInAdvance; i++) { if (i <= numSongs) { - NSString *curSong; + NSString *curSong = nil; NS_DURING curSong = [[[MainController sharedController] currentRemote] songTitleAtIndex:i]; NS_HANDLER @@ -601,7 +601,7 @@ - (NSMenu *)playlistsMenu { NSMenu *playlistsMenu = [[NSMenu alloc] initWithTitle:@""]; - NSArray *playlists; + NSArray *playlists = nil; id tempItem; ITMTRemotePlayerSource source = [[[MainController sharedController] currentRemote] currentSource]; int i, j; @@ -678,7 +678,7 @@ - (NSMenu *)eqMenu { NSMenu *eqMenu = [[NSMenu alloc] initWithTitle:@""]; - NSArray *eqPresets; + NSArray *eqPresets = nil; id tempItem; int i; diff --git a/NetworkController.m b/NetworkController.m index 41bf4ac..4204cbb 100755 --- a/NetworkController.m +++ b/NetworkController.m @@ -154,7 +154,7 @@ static NetworkController *sharedController; if (!clientProxy) { ITDebugLog(@"Null proxy! Couldn't connect!"); [self disconnect]; - return NO; + return 0; } if ([clientProxy requiresPassword]) { @@ -202,8 +202,8 @@ static NetworkController *sharedController; { NSData *fullPass = [[NSUserDefaults standardUserDefaults] dataForKey:@"connectPassword"]; unsigned char buffer; - NSConnection *testConnection; - NSSocketPort *testPort; + NSConnection *testConnection = nil; + NSSocketPort *testPort = nil; NetworkObject *tempProxy; BOOL valid; ITDebugLog(@"Checking for shared remote at %@.", host); @@ -309,7 +309,7 @@ static NetworkController *sharedController; ITDebugLog(@"Resolved service named %@.", [sender name]); [[NSNotificationCenter defaultCenter] postNotificationName:@"ITMTFoundNetService" object:nil]; if ([[NSUserDefaults standardUserDefaults] boolForKey:@"useSharedPlayer"] && !connectedToServer) { - [[MainController sharedController] checkForRemoteServer]; + [[MainController sharedController] checkForRemoteServerAndConnectImmediately:NO]; } [sender stop]; } diff --git a/StatusWindowController.m b/StatusWindowController.m index 0cb9b72..6ad04a1 100755 --- a/StatusWindowController.m +++ b/StatusWindowController.m @@ -267,7 +267,7 @@ static StatusWindowController *sharedController; - (void)showReconnectQueryWindow { NSString *message = @"The selected shared player is available again.\nWould you like to reconnect to it?"; - + [_window setLocked:NO]; [_window setImage:[NSImage imageNamed:@"Setup"]]; [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]]; [_window buildDialogWindowWithMessage:message