statusWindowController = [StatusWindowController sharedController];
menuController = [[MenuController alloc] init];
df = [[NSUserDefaults standardUserDefaults] retain];
+ [[PreferencesController sharedPrefs] setController:self];
timerUpdating = NO;
blinged = NO;
}
if ([df boolForKey:@"enableSharing"]) {
[self setServerStatus:YES];
} else if ([df boolForKey:@"useSharedPlayer"]) {
- if (![self connectToServer]) {
+ if ([self connectToServer] == 0) {
[NSTimer scheduledTimerWithTimeInterval:45 target:self selector:@selector(checkForRemoteServer:) userInfo:nil repeats:YES];
}
}
- (BOOL)songIsPlaying
{
- NSString *identifier;
+ NSString *identifier = nil;
NS_DURING
identifier = [[self currentRemote] playerStateUniqueIdentifier];
NS_HANDLER
- (BOOL)radioIsPlaying
{
- ITMTRemotePlayerPlaylistClass class;
+ ITMTRemotePlayerPlaylistClass class = nil;
NS_DURING
class = [[self currentRemote] currentPlaylistClass];
NS_HANDLER
- (BOOL)songChanged
{
- NSString *identifier;
+ NSString *identifier = nil;
NS_DURING
identifier = [[self currentRemote] playerStateUniqueIdentifier];
NS_HANDLER
- (void)showPreferences
{
ITDebugLog(@"Show preferences.");
- [[PreferencesController sharedPrefs] setController:self];
[[PreferencesController sharedPrefs] showPrefsWindow:self];
}
+- (void)showTestWindow
+{
+ [self showCurrentTrackInfo];
+}
+
- (void)quitMenuTunes
{
ITDebugLog(@"Quitting MenuTunes.");
- (void)showCurrentTrackInfo
{
- ITMTRemotePlayerSource source;
- NSString *title;
+ ITMTRemotePlayerSource source = 0;
+ NSString *title = nil;
NSString *album = nil;
NSString *artist = nil;
NSString *time = nil;
}
if ( [df boolForKey:@"showTrackNumber"] ) {
- int trackNo;
- int trackCount;
+ int trackNo = 0;
+ int trackCount = 0;
NS_DURING
trackNo = [[self currentRemote] currentSongTrack];
}
if ( [df boolForKey:@"showTrackRating"] ) {
- float currentRating;
+ float currentRating = 0;
NS_DURING
currentRating = [[self currentRemote] currentSongRating];
- (void)showUpcomingSongs
{
- int numSongs;
-
+ int numSongs = 0;
NS_DURING
numSongs = [[self currentRemote] numberOfSongsInPlaylistAtIndex:[[self currentRemote] currentPlaylistIndex]];
NS_HANDLER
ITDebugLog(@"Showing upcoming songs status window.");
NS_DURING
if (numSongs > 0) {
- NSMutableArray *songList = [NSMutableArray arrayWithCapacity:5];
int numSongsInAdvance = [df integerForKey:@"SongsInAdvance"];
+ NSMutableArray *songList = [NSMutableArray arrayWithCapacity:numSongsInAdvance];
int curTrack = [[self currentRemote] currentSongIndex];
int i;
}
}
+ if ([songList count] == 0) {
+ [songList addObject:NSLocalizedString(@"noUpcomingSongs", @"No upcoming songs.")];
+ }
+
[statusWindowController showUpcomingSongsWindowWithTitles:songList];
} else {
[statusWindowController showUpcomingSongsWindowWithTitles:[NSArray arrayWithObject:NSLocalizedString(@"noUpcomingSongs", @"No upcoming songs.")]];
}
}
-- (BOOL)connectToServer
+- (int)connectToServer
{
int result;
ITDebugLog(@"Attempting to connect to shared remote.");
result = [networkController connectToHost:[df stringForKey:@"sharedPlayerHost"]];
//Connect
if (result == 1) {
+ [[PreferencesController sharedPrefs] resetRemotePlayerTextFields];
currentRemote = [[[networkController networkObject] remote] retain];
[self timerUpdate];
- //[refreshTimer invalidate];
ITDebugLog(@"Connection successful.");
- return YES;
+ return 1;
} else if (result == 0) {
ITDebugLog(@"Connection failed.");
currentRemote = [remoteArray objectAtIndex:0];
- return NO;
- } else if (result == -1) {
+ return 0;
+ } else {
+ //Do something about the password being invalid
ITDebugLog(@"Connection failed.");
currentRemote = [remoteArray objectAtIndex:0];
- return NO;
- //Do something about the password being invalid
+ return -1;
}
}
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 ([self disconnectFromServer]) {
+ [[PreferencesController sharedPrefs] resetRemotePlayerTextFields];
[NSTimer scheduledTimerWithTimeInterval:45 target:self selector:@selector(checkForRemoteServer:) userInfo:nil repeats:YES];
} else {
ITDebugLog(@"CRITICAL ERROR, DISCONNECTING!");
- (void)reconnect
{
- if (![self connectToServer]) {
+ if ([self connectToServer] == 0) {
[NSTimer scheduledTimerWithTimeInterval:45 target:self selector:@selector(checkForRemoteServer:) userInfo:nil repeats:YES];
}
[[StatusWindow sharedWindow] setLocked:NO];
- (void)applicationWillTerminate:(NSNotification *)note
{
- [self clearHotKeys];
[networkController stopRemoteServerSearch];
+ [self clearHotKeys];
[[NSStatusBar systemStatusBar] removeStatusItem:statusItem];
}
[super dealloc];
}
-
@end
\ No newline at end of file