X-Git-Url: http://git.ithinksw.org/MenuTunes.git/blobdiff_plain/6e637324a7d146b5675fec00c819259d7ac9c244..da05d51282a00722e05f2c777db5cc3d0623d348:/MainController.m diff --git a/MainController.m b/MainController.m index aaddc7f..341eb8d 100755 --- a/MainController.m +++ b/MainController.m @@ -42,6 +42,7 @@ static MainController *sharedController; statusWindowController = [StatusWindowController sharedController]; menuController = [[MenuController alloc] init]; df = [[NSUserDefaults standardUserDefaults] retain]; + [[PreferencesController sharedPrefs] setController:self]; timerUpdating = NO; blinged = NO; } @@ -472,7 +473,6 @@ static MainController *sharedController; - (void)showPreferences { ITDebugLog(@"Show preferences."); - [[PreferencesController sharedPrefs] setController:self]; [[PreferencesController sharedPrefs] showPrefsWindow:self]; } @@ -945,15 +945,22 @@ static MainController *sharedController; - (BOOL)connectToServer { + int result; ITDebugLog(@"Attempting to connect to shared remote."); + result = [networkController connectToHost:[df stringForKey:@"sharedPlayerHost"]]; //Connect - if ([networkController connectToHost:[df stringForKey:@"sharedPlayerHost"]]) { + if (result == 1) { currentRemote = [[[networkController networkObject] remote] retain]; [self timerUpdate]; //[refreshTimer invalidate]; ITDebugLog(@"Connection successful."); return YES; + } else if (result == 0) { + ITDebugLog(@"Connection failed."); + currentRemote = [remoteArray objectAtIndex:0]; + return NO; } else { + //Do something about the password being invalid ITDebugLog(@"Connection failed."); currentRemote = [remoteArray objectAtIndex:0]; return NO; @@ -977,7 +984,9 @@ static MainController *sharedController; if ([networkController checkForServerAtHost:[df stringForKey:@"sharedPlayerHost"]]) { ITDebugLog(@"Remote server found."); [timer invalidate]; - [[StatusWindowController sharedController] showReconnectQueryWindow]; + if (![networkController isConnectedToServer]) { + [[StatusWindowController sharedController] showReconnectQueryWindow]; + } } else { ITDebugLog(@"Remote server not found."); } @@ -986,9 +995,10 @@ static MainController *sharedController; - (void)networkError:(NSException *)exception { ITDebugLog(@"Remote exception thrown: %@: %@", [exception name], [exception reason]); - if ([[exception name] isEqualToString:NSPortTimeoutException]) { + NSLog(@"%@", [exception reason]); + if ([[exception name] isEqualToString:NSPortTimeoutException] && [networkController isConnectedToServer]) { 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); - if ([networkController isConnectedToServer] && [self disconnectFromServer]) { + if ([self disconnectFromServer]) { [NSTimer scheduledTimerWithTimeInterval:45 target:self selector:@selector(checkForRemoteServer:) userInfo:nil repeats:YES]; } else { ITDebugLog(@"CRITICAL ERROR, DISCONNECTING!");