From f33e0138e4c1a2401e88be75ce10e9f301856e7c Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Tue, 14 Jan 2025 23:37:17 -0800 Subject: [PATCH] Playlist: Added play count column It should also be possible to sort by the column, ascending or descending. This also necessitated adding playlist row refreshing for play count updates. Signed-off-by: Christopher Snowhill --- Application/AppController.h | 1 + Base.lproj/MainMenu.xib | 169 +++++++++++++++++++++------------- Playlist/PlaylistController.m | 46 +++++++-- en.lproj/MainMenu.strings | 3 + es.lproj/MainMenu.strings | 3 + pl.lproj/MainMenu.strings | 3 + ru.lproj/MainMenu.strings | 3 + tr.lproj/MainMenu.strings | 3 + 8 files changed, 161 insertions(+), 70 deletions(-) diff --git a/Application/AppController.h b/Application/AppController.h index b455e028d..1b8ab6135 100644 --- a/Application/AppController.h +++ b/Application/AppController.h @@ -37,6 +37,7 @@ IBOutlet NSMenuItem *showArtistColumn; IBOutlet NSMenuItem *showAlbumColumn; IBOutlet NSMenuItem *showGenreColumn; + IBOutlet NSMenuItem *showPlayCountColumn; IBOutlet NSMenuItem *showLengthColumn; IBOutlet NSMenuItem *showTrackColumn; IBOutlet NSMenuItem *showYearColumn; diff --git a/Base.lproj/MainMenu.xib b/Base.lproj/MainMenu.xib index 3fd0e9689..4ccbbbd3e 100644 --- a/Base.lproj/MainMenu.xib +++ b/Base.lproj/MainMenu.xib @@ -17,31 +17,31 @@ - + - + - + - + - + - + - + @@ -54,11 +54,11 @@ - + - - + + @@ -95,14 +95,14 @@ - + - + @@ -127,7 +127,7 @@ - + @@ -141,11 +141,11 @@ - + - - + + @@ -171,7 +171,7 @@ - + @@ -185,11 +185,11 @@ - + - - + + @@ -231,7 +231,7 @@ - + @@ -259,7 +259,7 @@ - + @@ -273,10 +273,10 @@ - + - + @@ -320,7 +320,7 @@ - + @@ -347,7 +347,7 @@ - + @@ -361,11 +361,11 @@ - + - - + + @@ -391,7 +391,7 @@ - + @@ -404,11 +404,11 @@ - + - - + + @@ -435,7 +435,7 @@ - + @@ -448,11 +448,11 @@ - + - - + + @@ -475,7 +475,7 @@ - + @@ -489,11 +489,11 @@ - + - - + + @@ -516,7 +516,7 @@ - + @@ -529,11 +529,11 @@ - + - - + + @@ -556,6 +556,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -860,8 +904,8 @@ - - + + @@ -923,7 +967,7 @@ - + @@ -988,7 +1032,7 @@ - + @@ -1223,7 +1267,7 @@ - + @@ -1277,7 +1321,7 @@ - + @@ -2241,6 +2285,7 @@ Gw path status queued + playCount @@ -2592,7 +2637,7 @@ Gw - + @@ -2601,7 +2646,7 @@ Gw - + @@ -2651,7 +2696,7 @@ Gw - + diff --git a/Playlist/PlaylistController.m b/Playlist/PlaylistController.m index 47f988bd2..8e42b7b07 100644 --- a/Playlist/PlaylistController.m +++ b/Playlist/PlaylistController.m @@ -48,7 +48,7 @@ static void *playlistControllerContext = &playlistControllerContext; cellIdentifiers = @[@"index", @"status", @"title", @"albumartist", @"artist", @"album", @"length", @"year", @"genre", @"track", @"path", @"filename", @"codec", @"rating", @"samplerate", - @"bitspersample", @"bitrate", @"composer"]; + @"bitspersample", @"bitrate", @"composer", @"playcount"]; NSValueTransformer *repeatNoneTransformer = [[RepeatModeTransformer alloc] initWithMode:RepeatModeNoRepeat]; @@ -253,9 +253,9 @@ static void *playlistControllerContext = &playlistControllerContext; - (void)updatePlayCountForTrack:(PlaylistEntry *)pe { if(pe.countAdded) return; pe.countAdded = YES; - + __block PlayCount *pc = pe.playCountItem; - + if(pc) { [self.persistentContainer.viewContext performBlockAndWait:^{ pc.count += 1; @@ -272,8 +272,13 @@ static void *playlistControllerContext = &playlistControllerContext; pc.filename = pe.filenameFragment; }]; } - + [self commitPersistentStore]; + + NSIndexSet *refreshRow = [NSIndexSet indexSetWithIndex:pe.index]; + NSIndexSet *refreshColumns = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [[self.tableView tableColumns] count])]; + + [self.tableView reloadDataForRowIndexes:refreshRow columnIndexes:refreshColumns]; } - (void)firstSawTrack:(PlaylistEntry *)pe { @@ -290,6 +295,11 @@ static void *playlistControllerContext = &playlistControllerContext; pc.filename = pe.filenameFragment; }]; } + + NSIndexSet *refreshRow = [NSIndexSet indexSetWithIndex:pe.index]; + NSIndexSet *refreshColumns = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [[self.tableView tableColumns] count])]; + + [self.tableView reloadDataForRowIndexes:refreshRow columnIndexes:refreshColumns]; } - (void)ratingUpdatedWithEntry:(PlaylistEntry *)pe rating:(CGFloat)rating { @@ -313,6 +323,11 @@ static void *playlistControllerContext = &playlistControllerContext; }]; [self commitPersistentStore]; + + NSIndexSet *refreshRow = [NSIndexSet indexSetWithIndex:pe.index]; + NSIndexSet *refreshColumns = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [[self.tableView tableColumns] count])]; + + [self.tableView reloadDataForRowIndexes:refreshRow columnIndexes:refreshColumns]; } } @@ -527,6 +542,11 @@ static void *playlistControllerContext = &playlistControllerContext; case 17: if([pe composer]) cellText = pe.composer; break; + + case 18: + cellText = pe.playCount; + cellTextAlignment = NSTextAlignmentRight; + break; } } @@ -1922,10 +1942,19 @@ static inline void dispatch_sync_reentrant(dispatch_queue_t queue, dispatch_bloc - (IBAction)resetPlaycounts:(id)sender { NSArray *selectedobjects = [self selectedObjects]; if([selectedobjects count]) { + NSMutableIndexSet *refreshRows = [[NSMutableIndexSet alloc] init]; + for(PlaylistEntry *pe in selectedobjects) { [self resetPlayCountForTrack:pe]; + if(pe.index >= 0 && pe.index < NSNotFound) { + [refreshRows addIndex:pe.index]; + } } [self commitPersistentStore]; + + NSIndexSet *refreshColumns = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [[self.tableView tableColumns] count])]; + + [self.tableView reloadDataForRowIndexes:refreshRows columnIndexes:refreshColumns]; } } @@ -1937,17 +1966,18 @@ static inline void dispatch_sync_reentrant(dispatch_queue_t queue, dispatch_bloc } [self commitPersistentStore]; - NSMutableIndexSet *refreshSet = [[NSMutableIndexSet alloc] init]; + NSMutableIndexSet *refreshRows = [[NSMutableIndexSet alloc] init]; for(PlaylistEntry *pe in selectedobjects) { if(pe.index >= 0 && pe.index < NSNotFound) { - [refreshSet addIndex:pe.index]; + [refreshRows addIndex:pe.index]; } } // Refresh entire row to refresh tooltips - unsigned long columns = [[self.tableView tableColumns] count]; - [self.tableView reloadDataForRowIndexes:refreshSet columnIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, columns)]]; + NSIndexSet *refreshColumns = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [[self.tableView tableColumns] count])]; + + [self.tableView reloadDataForRowIndexes:refreshRows columnIndexes:refreshColumns]; } } diff --git a/en.lproj/MainMenu.strings b/en.lproj/MainMenu.strings index 8a86fae51..b27be9ea8 100644 --- a/en.lproj/MainMenu.strings +++ b/en.lproj/MainMenu.strings @@ -188,6 +188,9 @@ /* Class = "NSTableColumn"; headerCell.title = "Genre"; ObjectID = "849"; */ "849.headerCell.title" = "Genre"; +/* Class = "NSTableColumn"; headerCell.title = "Play Count"; ObjectID = "1g1-Th-emL"; */ +"1g1-Th-emL.headerCell.title" = "Play Count"; + /* Class = "NSTableColumn"; headerCell.title = "№"; ObjectID = "850"; */ "850.headerCell.title" = "№"; diff --git a/es.lproj/MainMenu.strings b/es.lproj/MainMenu.strings index 819325a0e..f867495ba 100644 --- a/es.lproj/MainMenu.strings +++ b/es.lproj/MainMenu.strings @@ -188,6 +188,9 @@ /* Class = "NSTableColumn"; headerCell.title = "Genre"; ObjectID = "849"; */ "849.headerCell.title" = "Género"; +/* Class = "NSTableColumn"; headerCell.title = "Play Count"; ObjectID = "1g1-Th-emL"; */ +"1g1-Th-emL.headerCell.title" = "Recuento de repr."; + /* Class = "NSTableColumn"; headerCell.title = "№"; ObjectID = "850"; */ "850.headerCell.title" = "№"; diff --git a/pl.lproj/MainMenu.strings b/pl.lproj/MainMenu.strings index 57fccea71..c429fda63 100644 --- a/pl.lproj/MainMenu.strings +++ b/pl.lproj/MainMenu.strings @@ -155,6 +155,9 @@ /* Class = "NSTableColumn"; headerCell.title = "Genre"; ObjectID = "849"; */ "849.headerCell.title" = "gatunek"; +/* Class = "NSTableColumn"; headerCell.title = "Play Count"; ObjectID = "1g1-Th-emL"; */ +"1g1-Th-emL.headerCell.title" = "ilość odtworzeń"; + /* Class = "NSTableColumn"; headerCell.title = "№"; ObjectID = "850"; */ "850.headerCell.title" = "№"; diff --git a/ru.lproj/MainMenu.strings b/ru.lproj/MainMenu.strings index b88263ba1..1f4b48012 100644 --- a/ru.lproj/MainMenu.strings +++ b/ru.lproj/MainMenu.strings @@ -173,6 +173,9 @@ /* Class = "NSTableColumn"; headerCell.title = "Genre"; ObjectID = "849"; */ "849.headerCell.title" = "Жанр"; +/* Class = "NSTableColumn"; headerCell.title = "Play Count"; ObjectID = "1g1-Th-emL"; */ +"1g1-Th-emL.headerCell.title" = "Проигрываний"; + /* Class = "NSTableColumn"; headerCell.title = "№"; ObjectID = "850"; */ "850.headerCell.title" = "№"; diff --git a/tr.lproj/MainMenu.strings b/tr.lproj/MainMenu.strings index 4b7221c44..96133e709 100644 --- a/tr.lproj/MainMenu.strings +++ b/tr.lproj/MainMenu.strings @@ -167,6 +167,9 @@ /* Class = "NSTableColumn"; headerCell.title = "Genre"; ObjectID = "849"; */ "849.headerCell.title" = "Tür"; +/* Class = "NSTableColumn"; headerCell.title = "Play Count"; ObjectID = "1g1-Th-emL"; */ +"1g1-Th-emL.headerCell.title" = "Oynatma Sayısı"; + /* Class = "NSTableColumn"; headerCell.title = "№"; ObjectID = "850"; */ "850.headerCell.title" = "№";