Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC
Commits:
a9084b53 by Claudio Cambra at 2022-12-13T11:37:31+00:00
macosx: Extract view setup parts in VLCLibraryAudioDataSource into separate
methods
Signed-off-by: Claudio Cambra <develo...@claudiocambra.com>
- - - - -
0bd9b55c by Claudio Cambra at 2022-12-13T11:37:31+00:00
macosx: Define songs table column identifiers as static global NSStrings
Signed-off-by: Claudio Cambra <develo...@claudiocambra.com>
- - - - -
cd272a2a by Claudio Cambra at 2022-12-13T11:37:31+00:00
macosx: Add NSSortDescriptors to songs table view
Signed-off-by: Claudio Cambra <develo...@claudiocambra.com>
- - - - -
02e4203a by Claudio Cambra at 2022-12-13T11:37:31+00:00
macosx: Make song table view headers functional, change sort
Signed-off-by: Claudio Cambra <develo...@claudiocambra.com>
- - - - -
855ea3ea by Claudio Cambra at 2022-12-13T11:37:31+00:00
macosx: Correctly set initial sort on song table view init
Signed-off-by: Claudio Cambra <develo...@claudiocambra.com>
- - - - -
02343458 by Claudio Cambra at 2022-12-13T11:37:31+00:00
macosx: Ensure song table view headers are updated on library sort change
Signed-off-by: Claudio Cambra <develo...@claudiocambra.com>
- - - - -
1 changed file:
- modules/gui/macosx/library/audio-library/VLCLibraryAudioDataSource.m
Changes:
=====================================
modules/gui/macosx/library/audio-library/VLCLibraryAudioDataSource.m
=====================================
@@ -44,6 +44,23 @@
#import "views/VLCImageView.h"
#import "views/VLCSubScrollView.h"
+static NSString *VLCLibrarySongsTableViewSongPlayingColumnIdentifier =
@"VLCLibrarySongsTableViewSongPlayingColumnIdentifier";
+static NSString *VLCLibrarySongsTableViewTitleColumnIdentifier =
@"VLCLibrarySongsTableViewTitleColumnIdentifier";
+static NSString *VLCLibrarySongsTableViewDurationColumnIdentifier =
@"VLCLibrarySongsTableViewDurationColumnIdentifier";
+static NSString *VLCLibrarySongsTableViewArtistColumnIdentifier =
@"VLCLibrarySongsTableViewArtistColumnIdentifier";
+static NSString *VLCLibrarySongsTableViewAlbumColumnIdentifier =
@"VLCLibrarySongsTableViewAlbumColumnIdentifier";
+static NSString *VLCLibrarySongsTableViewGenreColumnIdentifier =
@"VLCLibrarySongsTableViewGenreColumnIdentifier";
+static NSString *VLCLibrarySongsTableViewPlayCountColumnIdentifier =
@"VLCLibrarySongsTableViewPlayCountColumnIdentifier";
+static NSString *VLCLibrarySongsTableViewYearColumnIdentifier =
@"VLCLibrarySongsTableViewYearColumnIdentifier";
+
+static NSString *VLCLibraryTitleSortDescriptorKey =
@"VLCLibraryTitleSortDescriptorKey";
+static NSString *VLCLibraryDurationSortDescriptorKey =
@"VLCLibraryDurationSortDescriptorKey";
+static NSString *VLCLibraryArtistSortDescriptorKey =
@"VLCLibraryArtistSortDescriptorKey";
+static NSString *VLCLibraryAlbumSortDescriptorKey =
@"VLCLibraryAlbumSortDescriptorKey";
+static NSString *VLCLibraryPlayCountSortDescriptorKey =
@"VLCLibraryPlayCountSortDescriptorKey";
+static NSString *VLCLibraryYearSortDescriptorKey =
@"VLCLibraryYearSortDescriptorKey";
+// TODO: Add sorting by genre
+
@interface VLCLibraryAudioDataSource ()
{
VLCLibraryCollectionViewFlowLayout *_collectionViewFlowLayout;
@@ -226,6 +243,14 @@
}
- (void)setup
+{
+ [self setupCollectionView];
+ [self setupTableViews];
+
+ _audioLibrarySegment = -1; // Force setAudioLibrarySegment to do something
always on first try
+}
+
+- (void)setupCollectionView
{
_collectionView.dataSource = self;
_collectionView.delegate = self;
@@ -234,12 +259,12 @@
NSNib *albumSupplementaryDetailView = [[NSNib alloc]
initWithNibNamed:@"VLCLibraryCollectionViewAlbumSupplementaryDetailView"
bundle:nil];
[_collectionView registerNib:albumSupplementaryDetailView
-
forSupplementaryViewOfKind:VLCLibraryCollectionViewAlbumSupplementaryDetailViewKind
+
forSupplementaryViewOfKind:VLCLibraryCollectionViewAlbumSupplementaryDetailViewKind
withIdentifier:VLCLibraryCollectionViewAlbumSupplementaryDetailViewIdentifier];
NSNib *audioGroupSupplementaryDetailView = [[NSNib alloc]
initWithNibNamed:@"VLCLibraryCollectionViewAudioGroupSupplementaryDetailView"
bundle:nil];
[_collectionView registerNib:audioGroupSupplementaryDetailView
-
forSupplementaryViewOfKind:VLCLibraryCollectionViewAudioGroupSupplementaryDetailViewKind
+
forSupplementaryViewOfKind:VLCLibraryCollectionViewAudioGroupSupplementaryDetailViewKind
withIdentifier:VLCLibraryCollectionViewAudioGroupSupplementaryDetailViewIdentifier];
NSNib *mediaItemSupplementaryDetailView = [[NSNib alloc]
initWithNibNamed:@"VLCLibraryCollectionViewMediaItemSupplementaryDetailView"
bundle:nil];
@@ -249,15 +274,99 @@
_collectionViewFlowLayout = [[VLCLibraryCollectionViewFlowLayout alloc]
init];
_collectionView.collectionViewLayout = _collectionViewFlowLayout;
+}
+- (void)setupTableViews
+{
_groupSelectionTableView.target = self;
_groupSelectionTableView.doubleAction =
@selector(groubSelectionDoubleClickAction:);
+
_collectionSelectionTableView.target = self;
_collectionSelectionTableView.doubleAction =
@selector(collectionSelectionDoubleClickAction:);
+
+ [self setupSongsTableView];
+}
+
+- (void)setupSongsTableView
+{
_songsTableView.target = self;
_songsTableView.doubleAction = @selector(songDoubleClickAction:);
- _audioLibrarySegment = -1; // Force setAudioLibrarySegment to do something
always on first try
+ [self setupPrototypeSortDescriptorsForTableView:_songsTableView];
+ [self setupExistingSortForTableView:_songsTableView];
+}
+
+- (void)setupPrototypeSortDescriptorsForTableView:(NSTableView *)tableView
+{
+ for(NSTableColumn *column in tableView.tableColumns) {
+ NSSortDescriptor * const columnSortDescriptor = [self
sortDescriptorPrototypeForSongsTableViewColumnIdentifier:column.identifier];
+
+ if(columnSortDescriptor) {
+ column.sortDescriptorPrototype = columnSortDescriptor;
+ }
+ }
+}
+
+- (NSSortDescriptor
*)sortDescriptorPrototypeForSongsTableViewColumnIdentifier:(NSString
*)columnIdentifier
+{
+ if ([columnIdentifier
isEqualToString:VLCLibrarySongsTableViewTitleColumnIdentifier]) {
+ return [[NSSortDescriptor alloc]
initWithKey:VLCLibraryTitleSortDescriptorKey ascending:true];
+
+ } else if ([columnIdentifier
isEqualToString:VLCLibrarySongsTableViewDurationColumnIdentifier]) {
+ return [[NSSortDescriptor alloc]
initWithKey:VLCLibraryDurationSortDescriptorKey ascending:true];
+
+ } else if ([columnIdentifier
isEqualToString:VLCLibrarySongsTableViewArtistColumnIdentifier]) {
+ return [[NSSortDescriptor alloc]
initWithKey:VLCLibraryArtistSortDescriptorKey ascending:true];
+
+ } else if ([columnIdentifier
isEqualToString:VLCLibrarySongsTableViewAlbumColumnIdentifier]) {
+ return [[NSSortDescriptor alloc]
initWithKey:VLCLibraryAlbumSortDescriptorKey ascending:true];
+
+ } else if ([columnIdentifier
isEqualToString:VLCLibrarySongsTableViewPlayCountColumnIdentifier]) {
+ return [[NSSortDescriptor alloc]
initWithKey:VLCLibraryPlayCountSortDescriptorKey ascending:true];
+
+ } else if ([columnIdentifier
isEqualToString:VLCLibrarySongsTableViewYearColumnIdentifier]) {
+ return [[NSSortDescriptor alloc]
initWithKey:VLCLibraryYearSortDescriptorKey ascending:true];
+
+ }
+
+ return nil;
+}
+
+- (void)setupExistingSortForTableView:(NSTableView *)tableView
+{
+ const VLCLibraryController * const libraryController =
VLCMain.sharedInstance.libraryController;
+ const vlc_ml_sorting_criteria_t existingSortCriteria =
libraryController.lastSortingCriteria;
+
+ NSString *sortDescriptorKey = [self
sortDescriptorKeyFromVlcMlSortingCriteria:existingSortCriteria];
+ const NSSortDescriptor * const sortDescriptor = [[NSSortDescriptor alloc]
initWithKey:sortDescriptorKey
+
ascending:!libraryController.descendingLibrarySorting];
+
+ tableView.sortDescriptors = @[sortDescriptor];
+}
+
+- (NSString
*)sortDescriptorKeyFromVlcMlSortingCriteria:(vlc_ml_sorting_criteria_t)existingSortCriteria
+{
+ if (existingSortCriteria == VLC_ML_SORTING_DEFAULT) {
+ return VLCLibraryTitleSortDescriptorKey;
+
+ } else if (existingSortCriteria == VLC_ML_SORTING_DURATION) {
+ return VLCLibraryDurationSortDescriptorKey;
+
+ } else if (existingSortCriteria == VLC_ML_SORTING_ARTIST) {
+ return VLCLibraryArtistSortDescriptorKey;
+
+ } else if (existingSortCriteria == VLC_ML_SORTING_ALBUM) {
+ return VLCLibraryAlbumSortDescriptorKey;
+
+ } else if (existingSortCriteria == VLC_ML_SORTING_PLAYCOUNT) {
+ return VLCLibraryPlayCountSortDescriptorKey;
+
+ } else if (existingSortCriteria == VLC_ML_SORTING_RELEASEDATE) {
+ return VLCLibraryYearSortDescriptorKey;
+
+ }
+
+ return VLCLibraryTitleSortDescriptorKey;
}
- (void)reloadData
@@ -274,6 +383,7 @@
[self.collectionSelectionTableView reloadData];
[self.groupSelectionTableView reloadData];
[self.songsTableView reloadData];
+ [self setupExistingSortForTableView:_songsTableView];
}
- (void)setAudioLibrarySegment:(VLCAudioLibrarySegment)audioLibrarySegment
@@ -332,30 +442,30 @@
NSString *cellText = @"";
NSString *cellIdentifier = @"";
- if ([columnIdentifier
isEqualToString:@"VLCLibrarySongsTableViewSongPlayingColumnIdentifier"]) {
+ if ([columnIdentifier
isEqualToString:VLCLibrarySongsTableViewSongPlayingColumnIdentifier]) {
VLCLibrarySongsTableViewSongPlayingTableCellView *cellView =
(VLCLibrarySongsTableViewSongPlayingTableCellView*)[tableView
makeViewWithIdentifier:@"VLCLibrarySongsTableViewSongPlayingTableCellViewIdentifier"
owner:self];
NSAssert(cellView, @"Unexpectedly received null cellview");
cellView.representedMediaItem = [self libraryItemAtRow:row];
return cellView;
- } else if ([columnIdentifier
isEqualToString:@"VLCLibrarySongsTableViewTitleColumnIdentifier"]) {
+ } else if ([columnIdentifier
isEqualToString:VLCLibrarySongsTableViewTitleColumnIdentifier]) {
cellIdentifier =
@"VLCLibrarySongsTableViewTitleTableCellViewIdentifier";
cellText = mediaItem.title;
- } else if ([columnIdentifier
isEqualToString:@"VLCLibrarySongsTableViewDurationColumnIdentifier"]) {
+ } else if ([columnIdentifier
isEqualToString:VLCLibrarySongsTableViewDurationColumnIdentifier]) {
cellIdentifier =
@"VLCLibrarySongsTableViewDurationTableCellViewIdentifier";
cellText = mediaItem.durationString;
- } else if ([columnIdentifier
isEqualToString:@"VLCLibrarySongsTableViewArtistColumnIdentifier"]) {
+ } else if ([columnIdentifier
isEqualToString:VLCLibrarySongsTableViewArtistColumnIdentifier]) {
cellIdentifier =
@"VLCLibrarySongsTableViewArtistTableCellViewIdentifier";
cellText = album.artistName.length == 0 ? @"" : album.artistName;
- } else if ([columnIdentifier
isEqualToString:@"VLCLibrarySongsTableViewAlbumColumnIdentifier"]) {
+ } else if ([columnIdentifier
isEqualToString:VLCLibrarySongsTableViewAlbumColumnIdentifier]) {
cellIdentifier =
@"VLCLibrarySongsTableViewAlbumTableCellViewIdentifier";
cellText = album.title.length == 0 ? @"" : album.title;
- } else if ([columnIdentifier
isEqualToString:@"VLCLibrarySongsTableViewGenreColumnIdentifier"]) {
+ } else if ([columnIdentifier
isEqualToString:VLCLibrarySongsTableViewGenreColumnIdentifier]) {
cellIdentifier =
@"VLCLibrarySongsTableViewGenreTableCellViewIdentifier";
cellText = genre.name.length == 0 ? @"" : genre.name;
- } else if ([columnIdentifier
isEqualToString:@"VLCLibrarySongsTableViewPlayCountColumnIdentifier"]) {
+ } else if ([columnIdentifier
isEqualToString:VLCLibrarySongsTableViewPlayCountColumnIdentifier]) {
cellIdentifier =
@"VLCLibrarySongsTableViewPlayCountTableCellViewIdentifier";
cellText = [@(mediaItem.playCount) stringValue];
- } else if ([columnIdentifier
isEqualToString:@"VLCLibrarySongsTableViewYearColumnIdentifier"]) {
+ } else if ([columnIdentifier
isEqualToString:VLCLibrarySongsTableViewYearColumnIdentifier]) {
cellIdentifier =
@"VLCLibrarySongsTableViewYearTableCellViewIdentifier";
cellText = [@(mediaItem.year) stringValue];
} else {
@@ -402,6 +512,40 @@
[self.groupSelectionTableView reloadData];
}
+- (void)tableView:(NSTableView *)tableView
sortDescriptorsDidChange:(NSArray<NSSortDescriptor *> *)oldDescriptors
+{
+ const NSSortDescriptor * const sortDescriptor =
tableView.sortDescriptors.firstObject;
+ const vlc_ml_sorting_criteria_t sortCriteria = [self
sortDescriptorKeyToVlcMlSortingCriteria:sortDescriptor.key];
+
+ [VLCMain.sharedInstance.libraryController sortByCriteria:sortCriteria
andDescending:!sortDescriptor.ascending];
+ [self reloadData];
+}
+
+- (vlc_ml_sorting_criteria_t)sortDescriptorKeyToVlcMlSortingCriteria:(NSString
*)sortDescriptorKey
+{
+ if ([sortDescriptorKey isEqualToString:VLCLibraryTitleSortDescriptorKey]) {
+ return VLC_ML_SORTING_DEFAULT;
+
+ } else if ([sortDescriptorKey
isEqualToString:VLCLibraryDurationSortDescriptorKey]) {
+ return VLC_ML_SORTING_DURATION;
+
+ } else if ([sortDescriptorKey
isEqualToString:VLCLibraryArtistSortDescriptorKey]) {
+ return VLC_ML_SORTING_ARTIST;
+
+ } else if ([sortDescriptorKey
isEqualToString:VLCLibraryAlbumSortDescriptorKey]) {
+ return VLC_ML_SORTING_ALBUM;
+
+ } else if ([sortDescriptorKey
isEqualToString:VLCLibraryPlayCountSortDescriptorKey]) {
+ return VLC_ML_SORTING_PLAYCOUNT;
+
+ } else if ([sortDescriptorKey
isEqualToString:VLCLibraryYearSortDescriptorKey]) {
+ return VLC_ML_SORTING_RELEASEDATE;
+
+ }
+
+ return VLC_ML_SORTING_DEFAULT;
+}
+
#pragma mark - table view double click actions
- (void)groubSelectionDoubleClickAction:(id)sender
View it on GitLab:
https://code.videolan.org/videolan/vlc/-/compare/2d9100ed9c1780d5b1eada4d64712265f36a5139...02343458eadb9eccb4ba8befd4e470930d9913f3
--
View it on GitLab:
https://code.videolan.org/videolan/vlc/-/compare/2d9100ed9c1780d5b1eada4d64712265f36a5139...02343458eadb9eccb4ba8befd4e470930d9913f3
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
_______________________________________________
vlc-commits mailing list
vlc-commits@videolan.org
https://mailman.videolan.org/listinfo/vlc-commits