From 13cf91d9f8bff4826b27829e441ad75efed02cdb Mon Sep 17 00:00:00 2001 From: Kent Sutherland Date: Tue, 16 Dec 2003 00:40:02 +0000 Subject: [PATCH] Reverted back to the lame single source style playlist menu because I suck at coding. --- ITMTRemote.h | 2 +- ITMTRemote.m | 4 ++-- MainController.m | 7 +++--- MenuController.m | 60 +++++++++++++++++++++++++++++++++++++---------- iTunesRemote.m | 12 +++++----- libValidate.a | Bin 8032 -> 8032 bytes 6 files changed, 60 insertions(+), 25 deletions(-) diff --git a/ITMTRemote.h b/ITMTRemote.h index 0d2c21a..b77fc22 100755 --- a/ITMTRemote.h +++ b/ITMTRemote.h @@ -382,7 +382,7 @@ er's process managment. /*! * @method switchToPlaylistAtIndex: */ -- (BOOL)switchToPlaylistAtIndex:(int)index ofSourceAtIndex:(int)index2; +//- (BOOL)switchToPlaylistAtIndex:(int)index ofSourceAtIndex:(int)index2; /*! * @method switchToSongAtIndex: diff --git a/ITMTRemote.m b/ITMTRemote.m index 55e599b..b88b086 100755 --- a/ITMTRemote.m +++ b/ITMTRemote.m @@ -264,10 +264,10 @@ return NO; } -- (BOOL)switchToPlaylistAtIndex:(int)index ofSourceAtIndex:(int)index2 +/*- (BOOL)switchToPlaylistAtIndex:(int)index ofSourceAtIndex:(int)index2 { return NO; -} +}*/ - (BOOL)switchToSongAtIndex:(int)index { diff --git a/MainController.m b/MainController.m index 2b3a7fb..9313f11 100755 --- a/MainController.m +++ b/MainController.m @@ -292,7 +292,7 @@ static MainController *sharedController; [statusItem setMenu:[menuController menu]]; } - if ( [self songChanged] && (timerUpdating != YES) ) { + if ( [self songChanged] && (timerUpdating != YES) && (playerRunningState == ITMTRemotePlayerRunning) ) { ITDebugLog(@"The song changed."); timerUpdating = YES; @@ -406,7 +406,8 @@ static MainController *sharedController; { ITDebugLog(@"Selecting playlist %i", index); NS_DURING - [[self currentRemote] switchToPlaylistAtIndex:(index % 1000) ofSourceAtIndex:(index / 1000)]; + //[[self currentRemote] switchToPlaylistAtIndex:(index % 1000) ofSourceAtIndex:(index / 1000)]; + [[self currentRemote] switchToPlaylistAtIndex:index]; NS_HANDLER [self networkError:localException]; NS_ENDHANDLER @@ -1072,12 +1073,12 @@ static MainController *sharedController; NS_DURING if (!note || [[[note userInfo] objectForKey:@"NSApplicationName"] isEqualToString:[[self currentRemote] playerFullName]]) { ITDebugLog(@"Remote application terminated."); + playerRunningState = ITMTRemotePlayerNotRunning; [[self currentRemote] halt]; [refreshTimer invalidate]; [refreshTimer release]; refreshTimer = nil; [self clearHotKeys]; - playerRunningState = ITMTRemotePlayerNotRunning; if ([df objectForKey:@"ShowPlayer"] != nil) { ITHotKey *hotKey; diff --git a/MenuController.m b/MenuController.m index 9c7f9b5..668f961 100755 --- a/MenuController.m +++ b/MenuController.m @@ -22,6 +22,7 @@ - (NSMenu *)eqMenu; - (void)setKeyEquivalentForCode:(short)code andModifiers:(long)modifiers onItem:(NSMenuItem *)item; +- (BOOL)iPodAtPathAutomaticallyUpdates:(NSString *)name; @end @implementation MenuController @@ -430,7 +431,6 @@ - (void)rebuildSubmenus { ITDebugLog(@"Rebuilding all of the submenus."); - NS_DURING _currentPlaylist = [[[MainController sharedController] currentRemote] currentPlaylistIndex]; _currentTrack = [[[MainController sharedController] currentRemote] currentSongIndex]; @@ -525,7 +525,7 @@ return upcomingSongsMenu; } -/*- (NSMenu *)playlistsMenu +- (NSMenu *)playlistsMenu { NSMenu *playlistsMenu = [[NSMenu alloc] initWithTitle:@""]; NSArray *playlists; @@ -563,10 +563,10 @@ } ITDebugLog(@"Done Building \"Playlists\" menu"); return playlistsMenu; -}*/ +} -- (NSMenu *)playlistsMenu +/*- (NSMenu *)playlistsMenu { NSMenu *playlistsMenu = [[NSMenu alloc] initWithTitle:@""]; NSArray *playlists; @@ -604,16 +604,18 @@ NSString *name = [curPlaylist objectAtIndex:0]; NSMenu *submenu = [[NSMenu alloc] init]; ITDebugLog(@"Adding source: %@", name); - for (j = 2; j < [curPlaylist count]; j++) { - ITDebugLog(@"Adding playlist: %@", [curPlaylist objectAtIndex:j]); - tempItem = [submenu addItemWithTitle:[curPlaylist objectAtIndex:j] action:@selector(performPlaylistMenuAction:) keyEquivalent:@""]; - [tempItem setTag:(i * 1000) + j]; - [tempItem setTarget:self]; - if ([[curPlaylist objectAtIndex:i] intValue] == ITMTRemoteiPodSource) { - [tempItem setEnabled:NO]; + + if ( ([[curPlaylist objectAtIndex:i] intValue] == ITMTRemoteiPodSource) && (![self iPodAtPathAutomaticallyUpdates:[curPlaylist objectAtIndex:j]]) ) { + ITDebugLog(@"Invalid iPod source."); + } else { + for (j = 2; j < [curPlaylist count]; j++) { + ITDebugLog(@"Adding playlist: %@", [curPlaylist objectAtIndex:j]); + tempItem = [submenu addItemWithTitle:[curPlaylist objectAtIndex:j] action:@selector(performPlaylistMenuAction:) keyEquivalent:@""]; + [tempItem setTag:(i * 1000) + j]; + [tempItem setTarget:self]; } + [[playlistsMenu addItemWithTitle:name action:NULL keyEquivalent:@""] setSubmenu:[submenu autorelease]]; } - [[playlistsMenu addItemWithTitle:name action:NULL keyEquivalent:@""] setSubmenu:[submenu autorelease]]; } if ( (source == ITMTRemoteSharedLibrarySource) || (source == ITMTRemoteiPodSource) || (source == ITMTRemoteGenericDeviceSource) || (source == ITMTRemoteCDSource) ){ @@ -625,7 +627,7 @@ } ITDebugLog(@"Done Building \"Playlists\" menu"); return playlistsMenu; -} +}*/ - (NSMenu *)eqMenu { @@ -978,4 +980,36 @@ ITDebugLog(@"Done setting key equivalent on menu item: %@", [item title]); } +- (BOOL)iPodAtPathAutomaticallyUpdates:(NSString *)name +{ + NSArray *volumes = [[NSWorkspace sharedWorkspace] mountedLocalVolumePaths]; + NSEnumerator *volEnum = [volumes objectEnumerator]; + NSString *nextVolume; + + while ( (nextVolume = [volEnum nextObject]) ) { + if ([nextVolume rangeOfString:name options:nil range:NSMakeRange(0, [name length] - 1)].location != NSNotFound) { + NSFileHandle *handle; + NSData *data; + NSString *path = [nextVolume stringByAppendingPathComponent:@"/iPod_Control/iTunes/iTunesPrefs"]; + if ( ![[NSFileManager defaultManager] fileExistsAtPath:path] ) { + ITDebugLog(@"Error, path isn't an iPod! %@", path); + return NO; + } + handle = [NSFileHandle fileHandleForReadingAtPath:name]; + [handle seekToFileOffset:10]; + data = [handle readDataOfLength:1]; + if ( (*((unsigned char*)[data bytes]) == 0x00) ) { + ITDebugLog(@"iPod is manually updated. %@", path); + return NO; + } else if ( ( *((unsigned char*)[data bytes]) == 0x01 ) ) { + ITDebugLog(@"iPod is automatically updated. %@", path); + return YES; + } else { + ITDebugLog(@"Error! Value: %h Desc: %@ Path: %@", *((unsigned char*)[data bytes]), [data description], path); + return NO; + } + } + } +} + @end \ No newline at end of file diff --git a/iTunesRemote.m b/iTunesRemote.m index c7d17a8..d41f3bd 100755 --- a/iTunesRemote.m +++ b/iTunesRemote.m @@ -123,7 +123,7 @@ return ITMTRemotePlayerStopped; } -/*- (NSArray *)playlists +- (NSArray *)playlists { long i = 0; const signed long numPlaylists = [[ITAppleEventCenter sharedCenter] sendAEWithSendStringForNumber:@"kocl:type('cPly'), '----':()" eventClass:@"core" eventID:@"cnte" appPSN:savedPSN]; @@ -136,10 +136,10 @@ [playlists addObject:theObj]; } return [playlists autorelease]; -}*/ +} //Full source awareness -- (NSArray *)playlists +/*- (NSArray *)playlists { unsigned long i,k; const signed long numSources = [[ITAppleEventCenter sharedCenter] sendAEWithSendStringForNumber:@"kocl:type('cSrc'), '----':()" eventClass:@"core" eventID:@"cnte" appPSN:savedPSN]; NSMutableArray *allSources = [[NSMutableArray alloc] init]; @@ -188,7 +188,7 @@ } ITDebugLog(@"Finished getting playlists."); return [NSArray arrayWithArray:[allSources autorelease]]; -} +}*/ - (int)numberOfSongsInPlaylistAtIndex:(int)index { @@ -626,14 +626,14 @@ return YES; } -- (BOOL)switchToPlaylistAtIndex:(int)index ofSourceAtIndex:(int)index2 +/*- (BOOL)switchToPlaylistAtIndex:(int)index ofSourceAtIndex:(int)index2 { ITDebugLog(@"Switching to playlist at index %i of source %i", index, index2); [[ITAppleEventCenter sharedCenter] sendAEWithSendString:[NSString stringWithFormat:@"'----':obj { form:'indx', want:type('cPly'), seld:long(%lu), from: obj { form:'indx', want:type('cSrc'), seld:long(%lu), from:'null'() } }", index - 1, index2 + 1] eventClass:@"hook" eventID:@"Play" appPSN:savedPSN]; //{ form:'indx', want:type('cPly'), seld:long(%lu), from:obj { form:'indx', want:type('cSrc'), seld:long('%lu'), from:'null'() } } -- obj { form:'indx', want:type('cSrc'), seld:long(1), from:'null'() } ITDebugLog(@"Done switching to playlist at index %i of source %i", index, index2); return YES; -} +}*/ - (BOOL)switchToSongAtIndex:(int)index { diff --git a/libValidate.a b/libValidate.a index 34e2f0d2fd7d7ca576e11e3f3033c5c1251a8bc9..4fb44859b76b67decdd2995a24396cf2849faa9d 100755 GIT binary patch delta 17 YcmaE0_rPv~44bL3siBeKMkPCW066&tPyhe` delta 17 YcmaE0_rPv~44bj3v7v$KMkPCW066ajPyhe` -- 2.20.1