X-Git-Url: http://git.ithinksw.org/MenuTunes.git/blobdiff_plain/68dce30ee215d5614aff29c67733f9d71cfd033a..d6c5534acee4d543ee2c08b279b416ea69de42d8:/MainController.m diff --git a/MainController.m b/MainController.m index 8079f3b..8abe8de 100755 --- a/MainController.m +++ b/MainController.m @@ -89,10 +89,7 @@ static MainController *sharedController; if ([df boolForKey:@"enableSharing"]) { [self setServerStatus:YES]; } else if ([df boolForKey:@"useSharedPlayer"]) { - [self checkForRemoteServer:nil]; - /*if ([self connectToServer] == 0) { - [NSTimer scheduledTimerWithTimeInterval:45 target:self selector:@selector(checkForRemoteServer:) userInfo:nil repeats:YES]; - }*/ + [self checkForRemoteServer]; } //Setup for notification of the remote player launching or quitting @@ -165,7 +162,7 @@ static MainController *sharedController; Class remoteClass = [remoteBundle principalClass]; if ([remoteClass conformsToProtocol:@protocol(ITMTRemote)] && - [remoteClass isKindOfClass:[NSObject class]]) { + [(NSObject *)remoteClass isKindOfClass:[NSObject class]]) { id remote = [remoteClass remote]; ITDebugLog(@"Adding remote at path %@", bundlePath); [remoteArray addObject:remote]; @@ -780,7 +777,19 @@ static MainController *sharedController; NS_ENDHANDLER if ( title ) { - + if ( [df boolForKey:@"showAlbumArtwork"] ) { + NSSize oldSize, newSize; + NS_DURING + art = [[self currentRemote] currentSongAlbumArt]; + oldSize = [art size]; + if (oldSize.width > oldSize.height) newSize = NSMakeSize(110,oldSize.height * (110.0f / oldSize.width)); + else newSize = NSMakeSize(oldSize.width * (110.0f / oldSize.height),110); + art = [[[[NSImage alloc] initWithData:[art TIFFRepresentation]] autorelease] imageScaledSmoothlyToSize:newSize]; + NS_HANDLER + [self networkError:localException]; + NS_ENDHANDLER + } + if ( [df boolForKey:@"showAlbum"] ) { NS_DURING album = [[self currentRemote] currentSongAlbum]; @@ -846,20 +855,6 @@ static MainController *sharedController; rating = ( currentRating * 5 ); } } - - if ( [df boolForKey:@"showAlbumArtwork"] ) { - NSSize oldSize, newSize; - NS_DURING - art = [[self currentRemote] currentSongAlbumArt]; - oldSize = [art size]; - if (oldSize.width > oldSize.height) newSize = NSMakeSize(110,oldSize.height * (110.0f / oldSize.width)); - else newSize = NSMakeSize(oldSize.width * (110.0f / oldSize.height),110); - art = [[[[NSImage alloc] initWithData:[art TIFFRepresentation]] autorelease] imageScaledSmoothlyToSize:newSize]; - NS_HANDLER - [self networkError:localException]; - NS_ENDHANDLER - } - } else { title = NSLocalizedString(@"noSongPlaying", @"No song is playing."); } @@ -1135,24 +1130,10 @@ static MainController *sharedController; return YES; } -- (void)checkForRemoteServer:(NSTimer *)timer +- (void)checkForRemoteServer { ITDebugLog(@"Checking for remote server."); - - //New code [NSThread detachNewThreadSelector:@selector(runRemoteServerCheck:) toTarget:self withObject:nil]; - //[timer invalidate]; - // - - /*if ([networkController checkForServerAtHost:[df stringForKey:@"sharedPlayerHost"]]) { - ITDebugLog(@"Remote server found."); - [timer invalidate]; - if (![networkController isServerOn] && ![networkController isConnectedToServer]) { - [[StatusWindowController sharedController] showReconnectQueryWindow]; - } - } else { - ITDebugLog(@"Remote server not found."); - }*/ } - (void)runRemoteServerCheck:(id)sender @@ -1178,17 +1159,18 @@ static MainController *sharedController; - (void)remoteServerNotFound:(id)sender { - [NSTimer scheduledTimerWithTimeInterval:45 target:self selector:@selector(checkForRemoteServer:) userInfo:nil repeats:NO]; + [NSTimer scheduledTimerWithTimeInterval:90.0 target:self selector:@selector(checkForRemoteServer) userInfo:nil repeats:NO]; } - (void)networkError:(NSException *)exception { ITDebugLog(@"Remote exception thrown: %@: %@", [exception name], [exception reason]); if ( ((exception == nil) || [[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); + //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); + [[StatusWindowController sharedController] showNetworkErrorQueryWindow]; if ([self disconnectFromServer]) { [[PreferencesController sharedPrefs] resetRemotePlayerTextFields]; - [NSTimer scheduledTimerWithTimeInterval:45 target:self selector:@selector(checkForRemoteServer:) userInfo:nil repeats:YES]; + [NSTimer scheduledTimerWithTimeInterval:90.0 target:self selector:@selector(checkForRemoteServer) userInfo:nil repeats:YES]; } else { ITDebugLog(@"CRITICAL ERROR, DISCONNECTING!"); } @@ -1198,7 +1180,7 @@ static MainController *sharedController; - (void)reconnect { if ([self connectToServer] == 0) { - [NSTimer scheduledTimerWithTimeInterval:45 target:self selector:@selector(checkForRemoteServer:) userInfo:nil repeats:YES]; + [NSTimer scheduledTimerWithTimeInterval:90.0 target:self selector:@selector(checkForRemoteServer) userInfo:nil repeats:YES]; } [[StatusWindow sharedWindow] setLocked:NO]; [[StatusWindow sharedWindow] vanish:self];