- (void)setServerStatus:(BOOL)newStatus;
- (int)connectToServer;
- (BOOL)disconnectFromServer;
-- (void)checkForRemoteServer;
+- (void)checkForRemoteServerAndConnectImmediately:(BOOL)connectImmediately;
- (void)networkError:(NSException *)exception;
//
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
}
- (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
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];
- (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
- (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];
NSEnumerator *itemEnum;
ITHotKey *hotKey;
NSArray *hotKeys = [[ITHotKeyCenter sharedCenter] allHotKeys];
- int currentSongRating;
+ int currentSongRating = 0;
//Get the information
NS_DURING
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
if (!_playingRadio) {
if ([defaults boolForKey:@"showAlbum"]) {
- NSString *curAlbum;
+ NSString *curAlbum = nil;
NS_DURING
curAlbum = [[[MainController sharedController] currentRemote] currentSongAlbum];
NS_HANDLER
}
if ([defaults boolForKey:@"showArtist"]) {
- NSString *curArtist;
+ NSString *curArtist = nil;
NS_DURING
curArtist = [[[MainController sharedController] currentRemote] currentSongArtist];
NS_HANDLER
}
if ([defaults boolForKey:@"showComposer"]) {
- NSString *curComposer;
+ NSString *curComposer = nil;
NS_DURING
curComposer = [[[MainController sharedController] currentRemote] currentSongComposer];
NS_HANDLER
}
if ([defaults boolForKey:@"showTrackNumber"]) {
- int track;
+ int track = 0;
NS_DURING
track = [[[MainController sharedController] currentRemote] currentSongTrack];
NS_HANDLER
- (NSMenu *)menuForNoPlayer
{
NSMenu *menu = [[NSMenu alloc] initWithTitle:@""];
- id <NSMenuItem> tempItem;
+ id <NSMenuItem> tempItem = nil;
ITDebugLog(@"Creating menu for when player isn't running.");
NS_DURING
ITDebugLog(@"Add \"Open %@\" menu item.", [[[MainController sharedController] currentRemote] playerSimpleName]);
- (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];
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
- (NSMenu *)playlistsMenu
{
NSMenu *playlistsMenu = [[NSMenu alloc] initWithTitle:@""];
- NSArray *playlists;
+ NSArray *playlists = nil;
id <NSMenuItem> tempItem;
ITMTRemotePlayerSource source = [[[MainController sharedController] currentRemote] currentSource];
int i, j;
- (NSMenu *)eqMenu
{
NSMenu *eqMenu = [[NSMenu alloc] initWithTitle:@""];
- NSArray *eqPresets;
+ NSArray *eqPresets = nil;
id <NSMenuItem> tempItem;
int i;
if (!clientProxy) {
ITDebugLog(@"Null proxy! Couldn't connect!");
[self disconnect];
- return NO;
+ return 0;
}
if ([clientProxy requiresPassword]) {
{
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);
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];
}
- (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