- BOOL newShuffleEnabled = ( ! [currentRemote shuffleEnabled] );
- ITDebugLog(@"Toggling shuffle mode.");
- [currentRemote setShuffleEnabled:newShuffleEnabled];
- //Show shuffle status window
- ITDebugLog(@"Setting shuffle mode to %i", newShuffleEnabled);
- [statusWindowController showShuffleWindow:newShuffleEnabled];
+ NS_DURING
+ BOOL newShuffleEnabled = ( ! [[self currentRemote] shuffleEnabled] );
+ ITDebugLog(@"Toggling shuffle mode.");
+ [[self currentRemote] setShuffleEnabled:newShuffleEnabled];
+ //Show shuffle status window
+ ITDebugLog(@"Setting shuffle mode to %i", newShuffleEnabled);
+ [statusWindowController showShuffleWindow:newShuffleEnabled];
+ NS_HANDLER
+ [self networkError:localException];
+ NS_ENDHANDLER
+}
+
+- (void)registerNowOK
+{
+ [[StatusWindow sharedWindow] setLocked:NO];
+ [[StatusWindow sharedWindow] vanish:self];
+ [[StatusWindow sharedWindow] setIgnoresMouseEvents:YES];
+
+ [self blingNow];
+}
+
+- (void)registerNowCancel
+{
+ [[StatusWindow sharedWindow] setLocked:NO];
+ [[StatusWindow sharedWindow] vanish:self];
+ [[StatusWindow sharedWindow] setIgnoresMouseEvents:YES];
+
+ [NSApp terminate:self];
+}
+
+/*************************************************************************/
+#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
+{
+ //Connect
+ if ([networkController connectToHost:[df stringForKey:@"sharedPlayerHost"]]) {
+ currentRemote = [networkController sharedRemote];
+ [refreshTimer invalidate];
+ return YES;
+ } else {
+ currentRemote = [remoteArray objectAtIndex:0];
+ return NO;
+ }
+}
+
+- (BOOL)disconnectFromServer
+{
+ //Disconnect
+ currentRemote = [remoteArray objectAtIndex:0];
+ [networkController disconnect];
+ [self timerUpdate];
+ return YES;
+}
+
+- (void)networkError:(NSException *)exception
+{
+ ITDebugLog(@"Remote exception thrown: %@: %@", [exception name], [exception reason]);
+ NSRunAlertPanel(@"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]) {
+ } else {
+ ITDebugLog(@"CRITICAL ERROR DISCONNECTING!");
+ }