+/*************************************************************************/
+#pragma mark -
+#pragma mark NETWORK HANDLERS
+/*************************************************************************/
+
+- (void)setServerStatus:(BOOL)newStatus
+{
+ if (newStatus) {
+ //Turn on
+ [networkController setServerStatus:YES];
+ } else {
+ //Tear down
+ [networkController setServerStatus:NO];
+ }
+}
+
+- (BOOL)connectToServer
+{
+ ITDebugLog(@"Attempting to connect to shared remote.");
+ //Connect
+ if ([networkController connectToHost:[df stringForKey:@"sharedPlayerHost"]]) {
+ currentRemote = [[networkController networkObject] remote];
+ [refreshTimer invalidate];
+ ITDebugLog(@"Connection successful.");
+ return YES;
+ } else {
+ ITDebugLog(@"Connection failed.");
+ currentRemote = [remoteArray objectAtIndex:0];
+ return NO;
+ }
+}
+
+- (BOOL)disconnectFromServer
+{
+ ITDebugLog(@"Disconnecting from shared remote.");
+ //Disconnect
+ currentRemote = [remoteArray objectAtIndex:0];
+ [networkController disconnect];
+ [self timerUpdate];
+ return YES;
+}
+
+- (void)checkForRemoteServer:(NSTimer *)timer
+{
+ ITDebugLog(@"Checking for remote server.");
+ if ([networkController checkForServerAtHost:[df stringForKey:@"sharedPlayerHost"]]) {
+ ITDebugLog(@"Remote server found.");
+ [timer invalidate];
+ [[StatusWindowController sharedController] showReconnectQueryWindow];
+ } else {
+ ITDebugLog(@"Remote server not found.");
+ }
+}
+
+- (void)networkError:(NSException *)exception
+{
+ ITDebugLog(@"Remote exception thrown: %@: %@", [exception name], [exception reason]);
+ NSLog(@"Remote exception thrown: %@: %@", [exception name], [exception reason]);
+ 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 ([[exception name] isEqualToString:NSPortTimeoutException]) {
+ [NSTimer scheduledTimerWithTimeInterval:45 target:self selector:@selector(checkForRemoteServer:) userInfo:nil repeats:YES];
+ }
+ } else {
+ ITDebugLog(@"CRITICAL ERROR, DISCONNECTING!");
+ }
+}
+
+- (void)reconnect
+{
+ if (![self connectToServer]) {
+ [NSTimer scheduledTimerWithTimeInterval:45 target:self selector:@selector(checkForRemoteServer:) userInfo:nil repeats:YES];
+ }
+ [[StatusWindow sharedWindow] setLocked:NO];
+ [[StatusWindow sharedWindow] vanish:self];
+ [[StatusWindow sharedWindow] setIgnoresMouseEvents:YES];
+}
+
+- (void)cancelReconnect
+{
+ [[StatusWindow sharedWindow] setLocked:NO];
+ [[StatusWindow sharedWindow] vanish:self];
+ [[StatusWindow sharedWindow] setIgnoresMouseEvents:YES];
+}