Skip to content

Commit

Permalink
tracks on top lists
Browse files Browse the repository at this point in the history
  • Loading branch information
Longyi Qi committed Aug 11, 2011
1 parent 7cf74a1 commit 135c30d
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 24 deletions.
8 changes: 4 additions & 4 deletions repeatify.xcodeproj/project.pbxproj
Expand Up @@ -366,7 +366,7 @@
ARCHS = "$(ARCHS_STANDARD_64_BIT)";
CLANG_ENABLE_OBJC_ARC = NO;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 10;
CURRENT_PROJECT_VERSION = 15;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
Expand Down Expand Up @@ -395,7 +395,7 @@
ARCHS = "$(ARCHS_STANDARD_64_BIT)";
CLANG_ENABLE_OBJC_ARC = NO;
COPY_PHASE_STRIP = YES;
CURRENT_PROJECT_VERSION = 10;
CURRENT_PROJECT_VERSION = 15;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
Expand All @@ -413,7 +413,7 @@
29E8C9B413DDDFDC00CAFBE6 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CURRENT_PROJECT_VERSION = 10;
CURRENT_PROJECT_VERSION = 15;
FRAMEWORK_SEARCH_PATHS = (
"\"$(SOURCE_ROOT)/lib/CocoaLibSpotify\"",
"\"$(SRCROOT)/../../Library/Developer/Xcode/DerivedData/repeatify-bduzbsczeotvxffreawzutbpzyjs/Build/Products/Debug\"",
Expand All @@ -432,7 +432,7 @@
29E8C9B513DDDFDC00CAFBE6 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CURRENT_PROJECT_VERSION = 10;
CURRENT_PROJECT_VERSION = 15;
FRAMEWORK_SEARCH_PATHS = (
"\"$(SOURCE_ROOT)/lib/CocoaLibSpotify\"",
"\"$(SRCROOT)/../../Library/Developer/Xcode/DerivedData/repeatify-bduzbsczeotvxffreawzutbpzyjs/Build/Products/Debug\"",
Expand Down
2 changes: 1 addition & 1 deletion repeatify/repeatify-Info.plist
Expand Up @@ -21,7 +21,7 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>10</string>
<string>15</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.music</string>
<key>LSMinimumSystemVersion</key>
Expand Down
1 change: 1 addition & 0 deletions repeatify/repeatifyAppDelegate.h
Expand Up @@ -25,6 +25,7 @@ typedef enum _RPLoginStatus {
NSMenu *_statusMenu;

SPMediaKeyTap *_mediaKeyTap;
SPToplist *_topList;
RPPlaybackManager *_playbackManager;

RPLoginStatus _loginStatus;
Expand Down
71 changes: 52 additions & 19 deletions repeatify/repeatifyAppDelegate.m
Expand Up @@ -26,15 +26,20 @@ @interface repeatifyAppDelegate()

- (void)handlePlaylistFolder:(SPPlaylistFolder *)folder menuItem:(NSMenuItem *)menuItem;
- (void)handlePlaylist:(SPPlaylist *)list menuItem:(NSMenuItem *)menuItem;
- (void)handleTopList:(NSMenu *)menu;
- (void)handleNowPlayingView:(NSMenu *)menu;

- (void)addTracks:(NSArray *)tracks toMenuItem:(NSMenuItem *)menuItem;
- (void)addTrack:(SPTrack *)track toMenu:(NSMenu *)menu;

- (void)updateMenu;
- (void)clickTrackMenuItem:(id)sender;
- (void)updateAlbumCoverImage:(id)sender;

- (void)showLoginDialog;
- (void)didLoggedIn;
- (void)logoutUser;

- (void)showAboutPanel;
- (void)quitRepeatify;

Expand Down Expand Up @@ -64,7 +69,8 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification

[[SPSession sharedSession] setDelegate:self];

_playbackManager = [[RPPlaybackManager alloc] initWithPlaybackSession:[SPSession sharedSession]];
_playbackManager = [[RPPlaybackManager alloc] initWithPlaybackSession:[SPSession sharedSession]];
_topList = nil;
_mediaKeyTap = [[SPMediaKeyTap alloc] initWithDelegate:self];
if([SPMediaKeyTap usesGlobalMediaKeyTap]) {
[_mediaKeyTap startWatchingMediaKeys];
Expand Down Expand Up @@ -92,6 +98,10 @@ - (void)dealloc {
[_statusItem release];
[_playbackManager release];
[_mediaKeyTap release];
if (_topList != nil) {
[_topList release];
_topList = nil;
}

[super dealloc];
}
Expand Down Expand Up @@ -129,6 +139,9 @@ - (void)updateMenu {
}
if (_loginStatus == RPLoginStatusLoggedIn && container != nil) {
NSArray *playlists = container.playlists;
if ([playlists count] == 0) {
[_statusMenu addItemWithTitle:@"No Playlist Found" action:nil keyEquivalent:@""];
}
for (id playlist in playlists) {
NSMenuItem *innerMenuItem = [[NSMenuItem alloc] init];

Expand All @@ -142,6 +155,7 @@ - (void)updateMenu {
[_statusMenu addItem:innerMenuItem];
[innerMenuItem release];
}
[self handleTopList:_statusMenu];
}

if (_loginStatus != RPLoginStatusNoUser) {
Expand All @@ -158,6 +172,18 @@ - (void)updateMenu {
[_statusMenu addItemWithTitle:@"Quit" action:@selector(quitRepeatify) keyEquivalent:@""];
}

- (void)handleTopList:(NSMenu *)menu {
if (_topList.isLoaded) {
[menu addItem:[NSMenuItem separatorItem]];

NSMenuItem *innerMenuItem = [[NSMenuItem alloc] init];
[innerMenuItem setTitle:@"Top Tracks"];
[self addTracks:_topList.tracks toMenuItem:innerMenuItem];
[menu addItem:innerMenuItem];
[innerMenuItem release];
}
}

- (void)handlePlaylistFolder:(SPPlaylistFolder *)folder menuItem:(NSMenuItem *)menuItem {
[menuItem setTitle:folder.name];
NSMenu *innerMenu = [[NSMenu alloc] init];
Expand All @@ -182,33 +208,39 @@ - (void)handlePlaylistFolder:(SPPlaylistFolder *)folder menuItem:(NSMenuItem *)m

- (void)handlePlaylist:(SPPlaylist *)list menuItem:(NSMenuItem *)menuItem {
[menuItem setTitle:list.name];
NSMenu *innerMenu = [[NSMenu alloc] init];
[self addTracks:list.tracks toMenuItem:menuItem];

NSArray *tracks = list.tracks;
}

- (void)addTracks:(NSArray *)tracks toMenuItem:(NSMenuItem *)menuItem {
NSMenu *innerMenu = [[NSMenu alloc] init];
for (SPTrack *track in tracks) {
if (track != nil) {
NSMenuItem *innerMenuItem;
if (track.name == nil) {
innerMenuItem = [[NSMenuItem alloc] initWithTitle:@"Loading Track..." action:nil keyEquivalent:@""];
}
else {
if (track.availableForPlayback) {
innerMenuItem = [[NSMenuItem alloc] initWithTitle:track.name action:@selector(clickTrackMenuItem:) keyEquivalent:@""];
}
else {
innerMenuItem = [[NSMenuItem alloc] initWithTitle:track.name action:nil keyEquivalent:@""];
}
}
[innerMenuItem setRepresentedObject:track];
[innerMenu addItem:innerMenuItem];
[innerMenuItem release];
[self addTrack:track toMenu:innerMenu];
}
}

[menuItem setSubmenu:innerMenu];
[innerMenu release];
}

- (void)addTrack:(SPTrack *)track toMenu:(NSMenu *)menu {
NSMenuItem *innerMenuItem;
if (track.name == nil) {
innerMenuItem = [[NSMenuItem alloc] initWithTitle:@"Loading Track..." action:nil keyEquivalent:@""];
}
else {
if (track.availableForPlayback) {
innerMenuItem = [[NSMenuItem alloc] initWithTitle:track.name action:@selector(clickTrackMenuItem:) keyEquivalent:@""];
}
else {
innerMenuItem = [[NSMenuItem alloc] initWithTitle:track.name action:nil keyEquivalent:@""];
}
}
[innerMenuItem setRepresentedObject:track];
[menu addItem:innerMenuItem];
[innerMenuItem release];
}

#pragma mark -
#pragma mark Playback

Expand Down Expand Up @@ -350,6 +382,7 @@ - (void)logoutUser {

-(void)sessionDidLoginSuccessfully:(SPSession *)aSession {
NSLog(@"login successfully");
_topList = [[SPToplist alloc] initLocaleToplistWithLocale:[[SPSession sharedSession] locale] inSession:[SPSession sharedSession]];
_loginStatus = RPLoginStatusLoadingPlaylist;
[self.loginStatusField setStringValue:@"Loading Playlists..."];
[self performSelector:@selector(didLoggedIn) withObject:nil afterDelay:5.0];
Expand Down

0 comments on commit 135c30d

Please sign in to comment.