vlc | branch: master | Felix Paul Kühne <fe...@feepk.net> | Wed Aug 14 11:42:20 
2019 +0200| [3417d4eb604b9c174640b8354c89327029910671] | committer: Felix Paul 
Kühne

macosx: merge both audio library data sources

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=3417d4eb604b9c174640b8354c89327029910671
---

 .../package/macosx/VLC.xcodeproj/project.pbxproj   |   6 -
 modules/gui/macosx/Makefile.am                     |   2 -
 .../gui/macosx/library/VLCLibraryAudioDataSource.h |   1 +
 .../gui/macosx/library/VLCLibraryAudioDataSource.m | 174 +++++++++++++++------
 .../library/VLCLibraryTiledAudioViewController.h   |  40 -----
 .../library/VLCLibraryTiledAudioViewController.m   | 174 ---------------------
 modules/gui/macosx/library/VLCLibraryWindow.m      |  12 +-
 po/POTFILES.in                                     |   2 -
 8 files changed, 134 insertions(+), 277 deletions(-)

diff --git a/extras/package/macosx/VLC.xcodeproj/project.pbxproj 
b/extras/package/macosx/VLC.xcodeproj/project.pbxproj
index 99ade54dc1..3e28d52b18 100644
--- a/extras/package/macosx/VLC.xcodeproj/project.pbxproj
+++ b/extras/package/macosx/VLC.xcodeproj/project.pbxproj
@@ -162,7 +162,6 @@
                7DE2F0442282C84A0040DD0A /* VLCLibraryAudioDataSource.m in 
Sources */ = {isa = PBXBuildFile; fileRef = 7DE2F0432282C84A0040DD0A /* 
VLCLibraryAudioDataSource.m */; };
                7DE2F0472282D5D10040DD0A /* VLCLibraryTableCellView.m in 
Sources */ = {isa = PBXBuildFile; fileRef = 7DE2F0462282D5D10040DD0A /* 
VLCLibraryTableCellView.m */; };
                7DE7232E22A51F8D00D72616 /* VLCPositionFormatter.m in Sources 
*/ = {isa = PBXBuildFile; fileRef = 7DE7232D22A51F8D00D72616 /* 
VLCPositionFormatter.m */; };
-               7DE7E72F228C795B00D6EA38 /* 
VLCLibraryTiledAudioViewController.m in Sources */ = {isa = PBXBuildFile; 
fileRef = 7DE7E72E228C795B00D6EA38 /* VLCLibraryTiledAudioViewController.m */; 
};
                7DE82E7922843781002D341A /* VLCLibraryAlbumTableCellView.m in 
Sources */ = {isa = PBXBuildFile; fileRef = 7DE82E7822843781002D341A /* 
VLCLibraryAlbumTableCellView.m */; };
                7DE9C7DD220728420089108F /* VLCPlayerController.m in Sources */ 
= {isa = PBXBuildFile; fileRef = 7DE9C7DC220728420089108F /* 
VLCPlayerController.m */; };
                7DFBDCA82269E77500B700A5 /* VLCLibraryController.m in Sources 
*/ = {isa = PBXBuildFile; fileRef = 7DFBDCA72269E77500B700A5 /* 
VLCLibraryController.m */; };
@@ -565,8 +564,6 @@
                7DE2F0482282D7980040DD0A /* VLCLibraryTableCellView.xib */ = 
{isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = 
VLCLibraryTableCellView.xib; sourceTree = "<group>"; };
                7DE7232C22A51F8C00D72616 /* VLCPositionFormatter.h */ = {isa = 
PBXFileReference; lastKnownFileType = sourcecode.c.h; path = 
VLCPositionFormatter.h; sourceTree = "<group>"; };
                7DE7232D22A51F8D00D72616 /* VLCPositionFormatter.m */ = {isa = 
PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = 
VLCPositionFormatter.m; sourceTree = "<group>"; };
-               7DE7E72D228C795B00D6EA38 /* 
VLCLibraryTiledAudioViewController.h */ = {isa = PBXFileReference; 
lastKnownFileType = sourcecode.c.h; path = 
VLCLibraryTiledAudioViewController.h; sourceTree = "<group>"; };
-               7DE7E72E228C795B00D6EA38 /* 
VLCLibraryTiledAudioViewController.m */ = {isa = PBXFileReference; 
lastKnownFileType = sourcecode.c.objc; path = 
VLCLibraryTiledAudioViewController.m; sourceTree = "<group>"; };
                7DE82E7722843781002D341A /* VLCLibraryAlbumTableCellView.h */ = 
{isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = 
VLCLibraryAlbumTableCellView.h; sourceTree = "<group>"; };
                7DE82E7822843781002D341A /* VLCLibraryAlbumTableCellView.m */ = 
{isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = 
VLCLibraryAlbumTableCellView.m; sourceTree = "<group>"; };
                7DE82E7A228437AA002D341A /* VLCLibraryAlbumTableCellView.xib */ 
= {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path 
= VLCLibraryAlbumTableCellView.xib; sourceTree = "<group>"; };
@@ -1026,8 +1023,6 @@
                                7DBB7638227F3FBC002649E1 /* 
VLCLibraryCollectionViewSupplementaryElementView.m */,
                                7D713D302201AE350042BEB7 /* VLCLibraryWindow.h 
*/,
                                7D713D312201AE350042BEB7 /* VLCLibraryWindow.m 
*/,
-                               7DE7E72D228C795B00D6EA38 /* 
VLCLibraryTiledAudioViewController.h */,
-                               7DE7E72E228C795B00D6EA38 /* 
VLCLibraryTiledAudioViewController.m */,
                                7DFBDCA62269E77400B700A5 /* 
VLCLibraryController.h */,
                                7DFBDCA72269E77500B700A5 /* 
VLCLibraryController.m */,
                                7DFBDCA92269E77F00B700A5 /* VLCLibraryModel.h 
*/,
@@ -1767,7 +1762,6 @@
                                1C3113D31E508C6900D4DD76 /* 
VLCResumeDialogController.m in Sources */,
                                7D2FFA40227B8A5B0085D649 /* 
VLCLinearProgressIndicator.m in Sources */,
                                7DFBDCB1226A518400B700A5 /* 
VLCLibraryMenuController.m in Sources */,
-                               7DE7E72F228C795B00D6EA38 /* 
VLCLibraryTiledAudioViewController.m in Sources */,
                                1C3113D51E508C6900D4DD76 /* 
VLCTextfieldPanelController.m in Sources */,
                                7DFBDCAE2269ED0C00B700A5 /* 
VLCLibraryVideoDataSource.m in Sources */,
                                1C3113D71E508C6900D4DD76 /* 
VLCPopupPanelController.m in Sources */,
diff --git a/modules/gui/macosx/Makefile.am b/modules/gui/macosx/Makefile.am
index 216eed4923..ef6db51d54 100644
--- a/modules/gui/macosx/Makefile.am
+++ b/modules/gui/macosx/Makefile.am
@@ -72,8 +72,6 @@ libmacosx_plugin_la_SOURCES = \
        gui/macosx/library/VLCLibrarySortingMenuController.m \
        gui/macosx/library/VLCLibraryTableCellView.h \
        gui/macosx/library/VLCLibraryTableCellView.m \
-       gui/macosx/library/VLCLibraryTiledAudioViewController.h \
-       gui/macosx/library/VLCLibraryTiledAudioViewController.m \
        gui/macosx/library/VLCLibraryVideoDataSource.h \
        gui/macosx/library/VLCLibraryVideoDataSource.m \
        gui/macosx/library/VLCLibraryWindow.h \
diff --git a/modules/gui/macosx/library/VLCLibraryAudioDataSource.h 
b/modules/gui/macosx/library/VLCLibraryAudioDataSource.h
index e90a0c8714..75071f2e4b 100644
--- a/modules/gui/macosx/library/VLCLibraryAudioDataSource.h
+++ b/modules/gui/macosx/library/VLCLibraryAudioDataSource.h
@@ -35,6 +35,7 @@ NS_ASSUME_NONNULL_BEGIN
 @property (readwrite, assign) NSSegmentedControl *segmentedControl;
 @property (readwrite, assign) NSTableView *collectionSelectionTableView;
 @property (readwrite, assign) NSTableView *groupSelectionTableView;
+@property (readwrite, assign) NSCollectionView *collectionView;
 
 - (void)setupAppearance;
 - (void)reloadAppearance;
diff --git a/modules/gui/macosx/library/VLCLibraryAudioDataSource.m 
b/modules/gui/macosx/library/VLCLibraryAudioDataSource.m
index bb0701e11c..9db88f9637 100644
--- a/modules/gui/macosx/library/VLCLibraryAudioDataSource.m
+++ b/modules/gui/macosx/library/VLCLibraryAudioDataSource.m
@@ -26,12 +26,20 @@
 #import "library/VLCLibraryDataTypes.h"
 #import "library/VLCLibraryTableCellView.h"
 #import "library/VLCLibraryAlbumTableCellView.h"
+#import "library/VLCLibraryCollectionViewItem.h"
 
 #import "extensions/NSString+Helpers.h"
 #import "views/VLCImageView.h"
 
 static NSString *VLCAudioLibraryCellIdentifier = 
@"VLCAudioLibraryCellIdentifier";
 
+@interface VLCLibraryAudioDataSource () <NSCollectionViewDelegate, 
NSCollectionViewDataSource>
+{
+    NSArray *_displayedCollection;
+    enum vlc_ml_parent_type _currentParentType;
+}
+@end
+
 @implementation VLCLibraryAudioDataSource
 
 - (instancetype)init
@@ -49,6 +57,15 @@ static NSString *VLCAudioLibraryCellIdentifier = 
@"VLCAudioLibraryCellIdentifier
         [self.segmentedControl setLabel:availableCollections[x] forSegment:x];
     }
 
+    _collectionView.dataSource = self;
+    _collectionView.delegate = self;
+    [_collectionView registerClass:[VLCLibraryCollectionViewItem class] 
forItemWithIdentifier:VLCLibraryCellIdentifier];
+    NSCollectionViewFlowLayout *flowLayout = 
_collectionView.collectionViewLayout;
+    flowLayout.itemSize = CGSizeMake(214., 260.);
+    flowLayout.sectionInset = NSEdgeInsetsMake(20., 20., 20., 20.);
+    flowLayout.minimumLineSpacing = 20.;
+    flowLayout.minimumInteritemSpacing = 20.;
+
     [self reloadAppearance];
 }
 
@@ -60,40 +77,45 @@ static NSString *VLCAudioLibraryCellIdentifier = 
@"VLCAudioLibraryCellIdentifier
 
     [self.collectionSelectionTableView reloadData];
     [self.groupSelectionTableView reloadData];
-}
 
-- (IBAction)segmentedControlAction:(id)sender
-{
-    [self.collectionSelectionTableView reloadData];
-    [self.groupSelectionTableView reloadData];
+    [self.collectionView reloadData];
 }
 
-- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView
+- (IBAction)segmentedControlAction:(id)sender
 {
-    NSInteger ret = 0;
-
     switch (_segmentedControl.selectedSegment) {
-        case 0: // artists
-            ret = _libraryModel.numberOfArtists;
+        case 0:
+            _displayedCollection = [self.libraryModel listOfArtists];
+            _currentParentType = VLC_ML_PARENT_ARTIST;
             break;
-
-        case 1: // albums
-            ret = _libraryModel.numberOfAlbums;
+        case 1:
+            _displayedCollection = [self.libraryModel listOfAlbums];
+            _currentParentType = VLC_ML_PARENT_ALBUM;
             break;
-
-        case 2: // songs
-            ret = _libraryModel.numberOfAudioMedia;
+        case 2:
+            _displayedCollection = [self.libraryModel listOfAudioMedia];
+            _currentParentType = VLC_ML_PARENT_UNKNOWN;
             break;
-
-        case 3: // genres
-            ret = _libraryModel.numberOfGenres;
+        case 3:
+            _displayedCollection = [self.libraryModel listOfGenres];
+            _currentParentType = VLC_ML_PARENT_GENRE;
             break;
 
         default:
+            NSAssert(1, @"reached the unreachable");
             break;
     }
+    [self.collectionView reloadData];
 
-    return ret;
+    [self.collectionSelectionTableView reloadData];
+    [self.groupSelectionTableView reloadData];
+}
+
+#pragma mark - table view data source and delegation
+
+- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView
+{
+    return _displayedCollection.count;
 }
 
 - (NSView *)tableView:(NSTableView *)tableView 
viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
@@ -118,11 +140,10 @@ static NSString *VLCAudioLibraryCellIdentifier = 
@"VLCAudioLibraryCellIdentifier
         cellView.identifier = VLCAudioLibraryCellIdentifier;
     }
 
-    switch (self.segmentedControl.selectedSegment) {
-        case 0: // artists
+    switch (_currentParentType) {
+        case VLC_ML_PARENT_ARTIST:
         {
-            NSArray *listOfArtists = [_libraryModel listOfArtists];
-            VLCMediaLibraryArtist *artist = listOfArtists[row];
+            VLCMediaLibraryArtist *artist = _displayedCollection[row];
 
             cellView.singlePrimaryTitleTextField.hidden = NO;
             cellView.singlePrimaryTitleTextField.stringValue = artist.name;
@@ -137,10 +158,9 @@ static NSString *VLCAudioLibraryCellIdentifier = 
@"VLCAudioLibraryCellIdentifier
             cellView.representedImageView.image = image;
             break;
         }
-        case 1: // albums
+        case VLC_ML_PARENT_ALBUM:
         {
-            NSArray *listOfAlbums = [_libraryModel listOfAlbums];
-            VLCMediaLibraryAlbum *album = listOfAlbums[row];
+            VLCMediaLibraryAlbum *album = _displayedCollection[row];
 
             cellView.primaryTitleTextField.hidden = NO;
             cellView.secondaryTitleTextField.hidden = NO;
@@ -157,10 +177,9 @@ static NSString *VLCAudioLibraryCellIdentifier = 
@"VLCAudioLibraryCellIdentifier
             cellView.representedImageView.image = image;
             break;
         }
-        case 2: // songs
+        case VLC_ML_PARENT_UNKNOWN:
         {
-            NSArray *listOfAudioMedia = [_libraryModel listOfAudioMedia];
-            VLCMediaLibraryMediaItem *mediaItem = listOfAudioMedia[row];
+            VLCMediaLibraryMediaItem *mediaItem = _displayedCollection[row];
 
             NSImage *image;
             if (mediaItem.smallArtworkGenerated) {
@@ -196,10 +215,9 @@ static NSString *VLCAudioLibraryCellIdentifier = 
@"VLCAudioLibraryCellIdentifier
             }
             break;
         }
-        case 3: // genres
+        case VLC_ML_PARENT_GENRE:
         {
-            NSArray *listOfGenres = [_libraryModel listOfGenres];
-            VLCMediaLibraryGenre *genre = listOfGenres[row];
+            VLCMediaLibraryGenre *genre = _displayedCollection[row];
 
             cellView.primaryTitleTextField.hidden = NO;
             cellView.secondaryTitleTextField.hidden = NO;
@@ -211,6 +229,7 @@ static NSString *VLCAudioLibraryCellIdentifier = 
@"VLCAudioLibraryCellIdentifier
             break;
         }
         default:
+            NSAssert(1, @"reached the unreachable");
             break;
     }
 
@@ -219,43 +238,110 @@ static NSString *VLCAudioLibraryCellIdentifier = 
@"VLCAudioLibraryCellIdentifier
 
 - (void)tableViewSelectionDidChange:(NSNotification *)notification
 {
-    switch (self.segmentedControl.selectedSegment) {
-        case 0: // artists
+    switch (_currentParentType) {
+        case VLC_ML_PARENT_ARTIST:
         {
-            NSArray *listOfArtists = [_libraryModel listOfArtists];
-            VLCMediaLibraryArtist *artist = 
listOfArtists[self.collectionSelectionTableView.selectedRow];
+            VLCMediaLibraryArtist *artist = 
_displayedCollection[self.collectionSelectionTableView.selectedRow];
             NSArray *albumsForArtist = [_libraryModel 
listAlbumsOfParentType:VLC_ML_PARENT_ARTIST forID:artist.artistID];
             _groupDataSource.representedListOfAlbums = albumsForArtist;
             break;
         }
-        case 1: // albums
+        case VLC_ML_PARENT_ALBUM:
         {
-            NSArray *listOfAlbums = [_libraryModel listOfAlbums];
-            VLCMediaLibraryAlbum *album = 
listOfAlbums[self.collectionSelectionTableView.selectedRow];
+            VLCMediaLibraryAlbum *album = 
_displayedCollection[self.collectionSelectionTableView.selectedRow];
             _groupDataSource.representedListOfAlbums = @[album];
             break;
         }
-        case 2: // songs
+        case VLC_ML_PARENT_UNKNOWN:
         {
             // FIXME: we have nothing to show here
             _groupDataSource.representedListOfAlbums = nil;
             break;
         }
-        case 3: // genres
+        case VLC_ML_PARENT_GENRE:
         {
-            NSArray *listOfGenres = [_libraryModel listOfGenres];
-            VLCMediaLibraryGenre *genre = 
listOfGenres[self.collectionSelectionTableView.selectedRow];
+            VLCMediaLibraryGenre *genre = 
_displayedCollection[self.collectionSelectionTableView.selectedRow];
             NSArray *albumsForGenre = [_libraryModel 
listAlbumsOfParentType:VLC_ML_PARENT_GENRE forID:genre.genreID];
             _groupDataSource.representedListOfAlbums = albumsForGenre;
             break;
         }
         default:
+            NSAssert(1, @"reached the unreachable");
             break;
     }
 
     [self.groupSelectionTableView reloadData];
 }
 
+#pragma mark - collection view data source and delegation
+
+- (NSInteger)collectionView:(NSCollectionView *)collectionView
+     numberOfItemsInSection:(NSInteger)section
+{
+    return _displayedCollection.count;
+}
+
+- (NSInteger)numberOfSectionsInCollectionView:(NSCollectionView 
*)collectionView
+{
+    return 1;
+}
+
+- (NSCollectionViewItem *)collectionView:(NSCollectionView *)collectionView
+     itemForRepresentedObjectAtIndexPath:(NSIndexPath *)indexPath
+{
+    VLCLibraryCollectionViewItem *viewItem = [collectionView 
makeItemWithIdentifier:VLCLibraryCellIdentifier forIndexPath:indexPath];
+    switch (_currentParentType) {
+        case VLC_ML_PARENT_ARTIST:
+        {
+            VLCMediaLibraryArtist *artist = 
_displayedCollection[indexPath.item];
+            viewItem.mediaTitleTextField.stringValue = artist.name;
+            viewItem.durationTextField.stringValue = [NSString 
stringWithFormat:_NS("%u albums, %u songs"), artist.numberOfAlbums, 
artist.numberOfTracks];
+            NSImage *image;
+            if (artist.artworkMRL.length > 0) {
+                image = [[NSImage alloc] initWithContentsOfURL:[NSURL 
URLWithString:artist.artworkMRL]];
+            }
+            if (!image) {
+                image = [NSImage imageNamed: @"noart.png"];
+            }
+            viewItem.mediaImageView.image = image;
+            break;
+        }
+        case VLC_ML_PARENT_ALBUM:
+        {
+            VLCMediaLibraryAlbum *album = _displayedCollection[indexPath.item];
+            viewItem.mediaTitleTextField.stringValue = album.title;
+            viewItem.durationTextField.stringValue = [NSString 
stringWithFormat:_NS("%u songs"), album.numberOfTracks];
+            NSImage *image;
+            if (album.artworkMRL.length > 0) {
+                image = [[NSImage alloc] initWithContentsOfURL:[NSURL 
URLWithString:album.artworkMRL]];
+            }
+            if (!image) {
+                image = [NSImage imageNamed: @"noart.png"];
+            }
+            viewItem.mediaImageView.image = image;
+            break;
+        }
+        case VLC_ML_PARENT_UNKNOWN:
+        {
+            VLCMediaLibraryMediaItem *mediaItem = 
_displayedCollection[indexPath.item];
+            viewItem.representedMediaItem = mediaItem;
+            break;
+        }
+        case VLC_ML_PARENT_GENRE:
+        {
+            VLCMediaLibraryGenre *genre = _displayedCollection[indexPath.item];
+            viewItem.mediaTitleTextField.stringValue = genre.name;
+            viewItem.durationTextField.stringValue = [NSString 
stringWithFormat:_NS("%u items"), genre.numberOfTracks];
+            viewItem.mediaImageView.image = [NSImage imageNamed: @"noart.png"];
+        }
+
+        default:
+            break;
+    }
+
+    return viewItem;
+}
+
 @end
 
 @implementation VLCLibraryGroupDataSource
diff --git a/modules/gui/macosx/library/VLCLibraryTiledAudioViewController.h 
b/modules/gui/macosx/library/VLCLibraryTiledAudioViewController.h
deleted file mode 100644
index 94a5b00957..0000000000
--- a/modules/gui/macosx/library/VLCLibraryTiledAudioViewController.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/*****************************************************************************
- * VLCLibraryTiledAudioViewController.h: MacOS X interface module
- *****************************************************************************
- * Copyright (C) 2019 VLC authors and VideoLAN
- *
- * Authors: Felix Paul Kühne <fkuehne # videolan -dot- org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, 
USA.
- *****************************************************************************/
-
-#import <Cocoa/Cocoa.h>
-
-NS_ASSUME_NONNULL_BEGIN
-
-@class VLCLibraryModel;
-
-@interface VLCLibraryTiledAudioViewController : NSObject
-
-@property (readwrite, assign) NSCollectionView *collectionView;
-@property (readwrite, assign) NSSegmentedControl *segmentedControl;
-@property (readwrite, assign) VLCLibraryModel *libraryModel;
-
-- (void)setupAppearance;
-- (void)reloadAppearance;
-
-@end
-
-NS_ASSUME_NONNULL_END
diff --git a/modules/gui/macosx/library/VLCLibraryTiledAudioViewController.m 
b/modules/gui/macosx/library/VLCLibraryTiledAudioViewController.m
deleted file mode 100644
index f0fe181c87..0000000000
--- a/modules/gui/macosx/library/VLCLibraryTiledAudioViewController.m
+++ /dev/null
@@ -1,174 +0,0 @@
-/*****************************************************************************
- * VLCLibraryTiledAudioViewController.m: MacOS X interface module
- *****************************************************************************
- * Copyright (C) 2019 VLC authors and VideoLAN
- *
- * Authors: Felix Paul Kühne <fkuehne # videolan -dot- org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, 
USA.
- *****************************************************************************/
-
-#import "VLCLibraryTiledAudioViewController.h"
-
-#import "library/VLCLibraryModel.h"
-#import "library/VLCLibraryCollectionViewItem.h"
-#import "library/VLCLibraryDataTypes.h"
-
-#import "extensions/NSString+Helpers.h"
-#import "views/VLCImageView.h"
-
-@interface VLCLibraryTiledAudioViewController () <NSCollectionViewDelegate, 
NSCollectionViewDataSource>
-{
-    NSArray *_displayedCollection;
-    enum vlc_ml_parent_type _currentParentType;
-}
-@end
-
-@implementation VLCLibraryTiledAudioViewController
-
-- (void)setupAppearance
-{
-    NSArray *availableCollections = [VLCLibraryModel 
availableAudioCollections];
-    NSUInteger availableCollectionsCount = availableCollections.count;
-    self.segmentedControl.segmentCount = availableCollectionsCount;
-    for (NSUInteger x = 0; x < availableCollectionsCount; x++) {
-        [self.segmentedControl setLabel:availableCollections[x] forSegment:x];
-    }
-
-    _collectionView.dataSource = self;
-    _collectionView.delegate = self;
-    [_collectionView registerClass:[VLCLibraryCollectionViewItem class] 
forItemWithIdentifier:VLCLibraryCellIdentifier];
-    NSCollectionViewFlowLayout *flowLayout = 
_collectionView.collectionViewLayout;
-    flowLayout.itemSize = CGSizeMake(214., 260.);
-    flowLayout.sectionInset = NSEdgeInsetsMake(20., 20., 20., 20.);
-    flowLayout.minimumLineSpacing = 20.;
-    flowLayout.minimumInteritemSpacing = 20.;
-
-    [self.segmentedControl setTarget:self];
-    [self.segmentedControl setAction:@selector(segmentedControlAction:)];
-    [self segmentedControlAction:nil];
-}
-
-- (void)reloadAppearance
-{
-    [self.segmentedControl setTarget:self];
-    [self.segmentedControl setAction:@selector(segmentedControlAction:)];
-    [self segmentedControlAction:nil];
-
-    [self.collectionView reloadData];
-}
-
-- (IBAction)segmentedControlAction:(id)sender
-{
-    // FIXME: this relies on knowledge internal to VLCLibraryModel
-    switch (_segmentedControl.selectedSegment) {
-        case 0:
-            _displayedCollection = [self.libraryModel listOfArtists];
-            _currentParentType = VLC_ML_PARENT_ARTIST;
-            break;
-        case 1:
-            _displayedCollection = [self.libraryModel listOfAlbums];
-            _currentParentType = VLC_ML_PARENT_ALBUM;
-            break;
-        case 2:
-            _displayedCollection = [self.libraryModel listOfAudioMedia];
-            _currentParentType = VLC_ML_PARENT_UNKNOWN;
-            break;
-        case 3:
-            _displayedCollection = [self.libraryModel listOfGenres];
-            _currentParentType = VLC_ML_PARENT_GENRE;
-            break;
-
-        default:
-            NSAssert(1, @"reached the unreachable");
-            break;
-    }
-    [self.collectionView reloadData];
-}
-
-- (NSInteger)collectionView:(NSCollectionView *)collectionView
-     numberOfItemsInSection:(NSInteger)section
-{
-    return _displayedCollection.count;
-}
-
-- (NSInteger)numberOfSectionsInCollectionView:(NSCollectionView 
*)collectionView
-{
-    return 1;
-}
-
-- (NSCollectionViewItem *)collectionView:(NSCollectionView *)collectionView
-     itemForRepresentedObjectAtIndexPath:(NSIndexPath *)indexPath
-{
-    VLCLibraryCollectionViewItem *viewItem = [collectionView 
makeItemWithIdentifier:VLCLibraryCellIdentifier forIndexPath:indexPath];
-    switch (_currentParentType) {
-        case VLC_ML_PARENT_ARTIST:
-        {
-            VLCMediaLibraryArtist *artist = 
_displayedCollection[indexPath.item];
-            viewItem.mediaTitleTextField.stringValue = artist.name;
-            viewItem.durationTextField.stringValue = [NSString 
stringWithFormat:_NS("%u albums, %u songs"), artist.numberOfAlbums, 
artist.numberOfTracks];
-            NSImage *image;
-            if (artist.artworkMRL.length > 0) {
-                image = [[NSImage alloc] initWithContentsOfURL:[NSURL 
URLWithString:artist.artworkMRL]];
-            }
-            if (!image) {
-                image = [NSImage imageNamed: @"noart.png"];
-            }
-            viewItem.mediaImageView.image = image;
-            break;
-        }
-        case VLC_ML_PARENT_ALBUM:
-        {
-            VLCMediaLibraryAlbum *album = _displayedCollection[indexPath.item];
-            viewItem.mediaTitleTextField.stringValue = album.title;
-            viewItem.durationTextField.stringValue = [NSString 
stringWithFormat:_NS("%u songs"), album.numberOfTracks];
-            NSImage *image;
-            if (album.artworkMRL.length > 0) {
-                image = [[NSImage alloc] initWithContentsOfURL:[NSURL 
URLWithString:album.artworkMRL]];
-            }
-            if (!image) {
-                image = [NSImage imageNamed: @"noart.png"];
-            }
-            viewItem.mediaImageView.image = image;
-            break;
-        }
-        case VLC_ML_PARENT_UNKNOWN:
-        {
-            VLCMediaLibraryMediaItem *mediaItem = 
_displayedCollection[indexPath.item];
-            viewItem.representedMediaItem = mediaItem;
-            break;
-        }
-        case VLC_ML_PARENT_GENRE:
-        {
-            VLCMediaLibraryGenre *genre = _displayedCollection[indexPath.item];
-            viewItem.mediaTitleTextField.stringValue = genre.name;
-            viewItem.durationTextField.stringValue = [NSString 
stringWithFormat:_NS("%u items"), genre.numberOfTracks];
-            viewItem.mediaImageView.image = [NSImage imageNamed: @"noart.png"];
-        }
-
-        default:
-            break;
-    }
-
-    return viewItem;
-}
-
-- (void)collectionView:(NSCollectionView *)collectionView 
didSelectItemsAtIndexPaths:(NSSet<NSIndexPath *> *)indexPaths
-{
-    NSLog(@"library selection changed: %@", indexPaths);
-}
-
-
-@end
diff --git a/modules/gui/macosx/library/VLCLibraryWindow.m 
b/modules/gui/macosx/library/VLCLibraryWindow.m
index 060695b768..b9990cb3bf 100644
--- a/modules/gui/macosx/library/VLCLibraryWindow.m
+++ b/modules/gui/macosx/library/VLCLibraryWindow.m
@@ -38,7 +38,6 @@
 #import "library/VLCLibraryCollectionViewItem.h"
 #import "library/VLCLibraryModel.h"
 #import "library/VLCLibraryCollectionViewSupplementaryElementView.h"
-#import "library/VLCLibraryTiledAudioViewController.h"
 #import "library/VLCLibrarySortingMenuController.h"
 
 #import "media-source/VLCMediaSourceBaseDataSource.h"
@@ -72,7 +71,6 @@ const CGFloat VLCLibraryWindowDefaultPlaylistWidth = 340.;
     VLCLibraryGroupDataSource *_libraryAudioGroupDataSource;
     VLCLibrarySortingMenuController *_librarySortingMenuController;
     VLCMediaSourceBaseDataSource *_mediaSourceDataSource;
-    VLCLibraryTiledAudioViewController *_gridAudioViewController;
     VLCPlaylistSortingMenuController *_playlistSortingMenuController;
 
     VLCPlaylistController *_playlistController;
@@ -224,6 +222,8 @@ static int ShowController(vlc_object_t *p_this, const char 
*psz_variable,
     _libraryAudioDataSource.collectionSelectionTableView = 
_audioCollectionSelectionTableView;
     _libraryAudioDataSource.groupSelectionTableView = 
_audioGroupSelectionTableView;
     _libraryAudioDataSource.segmentedControl = self.audioSegmentedControl;
+    _libraryAudioDataSource.collectionView = self.audioLibraryCollectionView;
+    [_libraryAudioDataSource setupAppearance];
     _audioCollectionSelectionTableView.dataSource = _libraryAudioDataSource;
     _audioCollectionSelectionTableView.delegate = _libraryAudioDataSource;
     _audioCollectionSelectionTableView.rowHeight = 
VLCLibraryWindowLargeRowHeight;
@@ -248,12 +248,6 @@ static int ShowController(vlc_object_t *p_this, const char 
*psz_variable,
     [self updateColorsBasedOnAppearance];
     self.openMediaButton.title = _NS("Open media...");
 
-    _gridAudioViewController = [[VLCLibraryTiledAudioViewController alloc] 
init];
-    _gridAudioViewController.collectionView = self.audioLibraryCollectionView;
-    _gridAudioViewController.segmentedControl = self.audioSegmentedControl;
-    _gridAudioViewController.libraryModel = 
mainInstance.libraryController.libraryModel;
-    [_gridAudioViewController setupAppearance];
-
     _mainSplitView.delegate = self;
     _lastPlaylistWidthBeforeCollaps = VLCLibraryWindowDefaultPlaylistWidth;
 
@@ -417,7 +411,7 @@ static int ShowController(vlc_object_t *p_this, const char 
*psz_variable,
     if (self.gridVsListSegmentedControl.selectedSegment == 0) {
         _audioLibrarySplitView.hidden = YES;
         _audioCollectionViewScrollView.hidden = NO;
-        [_gridAudioViewController reloadAppearance];
+        [_libraryAudioDataSource reloadAppearance];
     } else {
         _audioLibrarySplitView.hidden = NO;
         _audioLibrarySplitView.wantsLayer = YES;
diff --git a/po/POTFILES.in b/po/POTFILES.in
index adc2700530..6552e071a2 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -478,8 +478,6 @@ modules/gui/macosx/library/VLCLibrarySortingMenuController.h
 modules/gui/macosx/library/VLCLibrarySortingMenuController.m
 modules/gui/macosx/library/VLCLibraryTableCellView.h
 modules/gui/macosx/library/VLCLibraryTableCellView.m
-modules/gui/macosx/library/VLCLibraryTiledAudioViewController.h
-modules/gui/macosx/library/VLCLibraryTiledAudioViewController.m
 modules/gui/macosx/library/VLCLibraryVideoDataSource.h
 modules/gui/macosx/library/VLCLibraryVideoDataSource.m
 modules/gui/macosx/library/VLCLibraryWindow.h

_______________________________________________
vlc-commits mailing list
vlc-commits@videolan.org
https://mailman.videolan.org/listinfo/vlc-commits

Reply via email to