[vlc-commits] macosx/audio library: add double click on collection for playback and refactor
Felix Paul Kühne
git at videolan.org
Mon Sep 2 11:57:44 CEST 2019
vlc | branch: master | Felix Paul Kühne <felix at feepk.net> | Fri Aug 30 16:57:09 2019 +0200| [c62561d1556599fa2a65660546a02e966258c469] | committer: Felix Paul Kühne
macosx/audio library: add double click on collection for playback and refactor
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=c62561d1556599fa2a65660546a02e966258c469
---
.../gui/macosx/library/VLCLibraryAudioDataSource.m | 56 +++++++++++++++++++---
modules/gui/macosx/library/VLCLibraryController.h | 1 +
modules/gui/macosx/library/VLCLibraryController.m | 21 ++++++++
3 files changed, 72 insertions(+), 6 deletions(-)
diff --git a/modules/gui/macosx/library/VLCLibraryAudioDataSource.m b/modules/gui/macosx/library/VLCLibraryAudioDataSource.m
index 8071e77826..6512f27685 100644
--- a/modules/gui/macosx/library/VLCLibraryAudioDataSource.m
+++ b/modules/gui/macosx/library/VLCLibraryAudioDataSource.m
@@ -71,6 +71,8 @@ static NSString *VLCAudioLibraryCellIdentifier = @"VLCAudioLibraryCellIdentifier
_groupSelectionTableView.target = self;
_groupSelectionTableView.doubleAction = @selector(groubSelectionDoubleClickAction:);
+ _collectionSelectionTableView.target = self;
+ _collectionSelectionTableView.doubleAction = @selector(collectionSelectionDoubleClickAction:);
[self reloadAppearance];
}
@@ -297,13 +299,55 @@ static NSString *VLCAudioLibraryCellIdentifier = @"VLCAudioLibraryCellIdentifier
VLCLibraryController *libraryController = [[VLCMain sharedInstance] libraryController];
NSArray *tracks = [listOfAlbums[clickedRow] tracksAsMediaItems];
- NSUInteger trackCount = tracks.count;
- BOOL playImmediately = YES;
- for (NSUInteger x = 0; x < trackCount; x++) {
- [libraryController appendItemToPlaylist:tracks[x] playImmediately:playImmediately];
- if (playImmediately) {
- playImmediately = NO;
+ [libraryController appendItemsToPlaylist:tracks playFirstItemImmediately:YES];
+}
+
+- (void)collectionSelectionDoubleClickAction:(id)sender
+{
+ NSArray *listOfAlbums;
+
+ switch (_currentParentType) {
+ case VLC_ML_PARENT_ARTIST:
+ {
+ VLCMediaLibraryArtist *artist = _displayedCollection[self.collectionSelectionTableView.selectedRow];
+ listOfAlbums = [_libraryModel listAlbumsOfParentType:VLC_ML_PARENT_ARTIST forID:artist.artistID];
+ break;
+ }
+ case VLC_ML_PARENT_ALBUM:
+ {
+ VLCMediaLibraryAlbum *album = _displayedCollection[self.collectionSelectionTableView.selectedRow];
+ listOfAlbums = @[album];
+ break;
+ }
+ case VLC_ML_PARENT_UNKNOWN:
+ {
+ // FIXME: we have nothing to show here
+ listOfAlbums = nil;
+ break;
}
+ case VLC_ML_PARENT_GENRE:
+ {
+ VLCMediaLibraryGenre *genre = _displayedCollection[self.collectionSelectionTableView.selectedRow];
+ listOfAlbums = [_libraryModel listAlbumsOfParentType:VLC_ML_PARENT_GENRE forID:genre.genreID];
+ break;
+ }
+ default:
+ NSAssert(1, @"reached the unreachable");
+ break;
+ }
+
+ if (!listOfAlbums) {
+ return;
+ }
+ NSUInteger albumCount = listOfAlbums.count;
+ if (albumCount == 0) {
+ return;
+ }
+
+ VLCLibraryController *libraryController = [[VLCMain sharedInstance] libraryController];
+ for (NSUInteger x = 0; x < albumCount; x++) {
+ NSArray *tracks = [listOfAlbums[x] tracksAsMediaItems];
+ [libraryController appendItemsToPlaylist:tracks playFirstItemImmediately:YES];
}
}
diff --git a/modules/gui/macosx/library/VLCLibraryController.h b/modules/gui/macosx/library/VLCLibraryController.h
index 271112cad1..95a19981f1 100644
--- a/modules/gui/macosx/library/VLCLibraryController.h
+++ b/modules/gui/macosx/library/VLCLibraryController.h
@@ -34,6 +34,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (readonly, nullable) VLCLibraryModel *libraryModel;
- (int)appendItemToPlaylist:(VLCMediaLibraryMediaItem *)mediaItem playImmediately:(BOOL)playImmediately;
+- (int)appendItemsToPlaylist:(NSArray <VLCMediaLibraryMediaItem *> *)mediaItemArray playFirstItemImmediately:(BOOL)playFirstItemImmediately;
- (void)showItemInFinder:(VLCMediaLibraryMediaItem *)mediaItem;
- (int)attemptToGenerateThumbnailForMediaItem:(VLCMediaLibraryMediaItem *)mediaItem;
diff --git a/modules/gui/macosx/library/VLCLibraryController.m b/modules/gui/macosx/library/VLCLibraryController.m
index 556e1c4de6..da62097af3 100644
--- a/modules/gui/macosx/library/VLCLibraryController.m
+++ b/modules/gui/macosx/library/VLCLibraryController.m
@@ -130,6 +130,27 @@ float kVLCDefaultThumbnailPosition = .15;
return ret;
}
+- (int)appendItemsToPlaylist:(NSArray <VLCMediaLibraryMediaItem *> *)mediaItemArray playFirstItemImmediately:(BOOL)playFirstItemImmediately
+{
+ if (!_p_libraryInstance) {
+ return VLC_ENOOBJ;
+ }
+
+ NSUInteger itemCount = [mediaItemArray count];
+ int ret = VLC_SUCCESS;
+ for (NSUInteger x = 0; x < itemCount; x++) {
+ if (unlikely(x == 0 && playFirstItemImmediately)) {
+ ret = [self appendItemToPlaylist:mediaItemArray[x] playImmediately:YES];
+ } else {
+ ret = [self appendItemToPlaylist:mediaItemArray[x] playImmediately:NO];
+ }
+ if (unlikely(ret != VLC_SUCCESS)) {
+ break;
+ }
+ }
+ return ret;
+}
+
- (void)showItemInFinder:(VLCMediaLibraryMediaItem *)mediaItem;
{
if (mediaItem == nil) {
More information about the vlc-commits
mailing list