[vlc-commits] [Git][videolan/vlc][master] 6 commits: macosx: Respond to albums reset notification in audio group data source
Felix Paul Kühne (@fkuehne)
gitlab at videolan.org
Mon Apr 21 17:23:21 UTC 2025
Felix Paul Kühne pushed to branch master at VideoLAN / VLC
Commits:
1d9ebee3 by Claudio Cambra at 2025-04-21T16:58:49+00:00
macosx: Respond to albums reset notification in audio group data source
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
0b05625f by Claudio Cambra at 2025-04-21T16:58:49+00:00
macosx: Add method to perform a given action on all registered table views and collection views in audio groups data source
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
97bbe99a by Claudio Cambra at 2025-04-21T16:58:49+00:00
macosx: Respond to album deletion notification in audio groups data source
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
332df615 by Claudio Cambra at 2025-04-21T16:58:49+00:00
macosx: Respond to album update notification in audio groups data source
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
5364ea2a by Claudio Cambra at 2025-04-21T16:58:49+00:00
macosx: Move album update handling to separate method
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
25b50ae6 by Claudio Cambra at 2025-04-21T16:58:49+00:00
macosx: Handle library item update and delete in audio group data source
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
1 changed file:
- modules/gui/macosx/library/audio-library/VLCLibraryAudioGroupDataSource.m
Changes:
=====================================
modules/gui/macosx/library/audio-library/VLCLibraryAudioGroupDataSource.m
=====================================
@@ -93,11 +93,6 @@
}
}
-- (void)libraryModelAudioMediaItemsReset:(NSNotification *)notification
-{
- [self updateRepresentedListOfAlbums];
-}
-
- (void)connect
{
NSNotificationCenter * const notificationCenter = NSNotificationCenter.defaultCenter;
@@ -106,7 +101,27 @@
selector:@selector(libraryModelAudioMediaItemsReset:)
name:VLCLibraryModelAudioMediaListReset
object:nil];
- // TODO: Handle item deletion, update
+ [notificationCenter addObserver:self
+ selector:@selector(libraryModelAudioMediaItemUpdated:)
+ name:VLCLibraryModelAudioMediaItemUpdated
+ object:nil];
+ [notificationCenter addObserver:self
+ selector:@selector(libraryModelAudioMediaItemDeleted:)
+ name:VLCLibraryModelAudioMediaItemDeleted
+ object:nil];
+
+ [notificationCenter addObserver:self
+ selector:@selector(libraryModelAlbumsReset:)
+ name:VLCLibraryModelAlbumListReset
+ object:nil];
+ [notificationCenter addObserver:self
+ selector:@selector(libraryModelAlbumUpdated:)
+ name:VLCLibraryModelAlbumUpdated
+ object:nil];
+ [notificationCenter addObserver:self
+ selector:@selector(libraryModelAlbumDeleted:)
+ name:VLCLibraryModelAlbumDeleted
+ object:nil];
[self reloadData];
}
@@ -116,6 +131,106 @@
[NSNotificationCenter.defaultCenter removeObserver:self];
}
+- (NSInteger)rowContainingMediaItem:(id<VLCMediaLibraryItemProtocol>)libraryItem
+{
+ return [self.representedAudioGroup.albums indexOfObjectPassingTest:^BOOL(VLCMediaLibraryAlbum *album, NSUInteger idx, BOOL *stop) {
+ return [album.mediaItems indexOfObjectPassingTest:^BOOL(VLCMediaLibraryMediaItem *item, NSUInteger idx, BOOL *stop) {
+ return item.libraryID == libraryItem.libraryID;
+ }] != NSNotFound;
+ }];
+}
+
+- (void)handleAlbumUpdateInRow:(NSInteger)row
+{
+ NSParameterAssert(row >= 0 && row < self.representedListOfAlbums.count);
+ NSIndexSet * const indexSet = [NSIndexSet indexSetWithIndex:row];
+ NSIndexSet * const columnIndexSet = [NSIndexSet indexSetWithIndex:0];
+ NSSet * const indexPaths = [NSSet setWithObject:[NSIndexPath indexPathForItem:row inSection:0]];
+
+ [self performActionOnTableViews:^(NSTableView * const tableView){
+ [tableView reloadDataForRowIndexes:indexSet columnIndexes:columnIndexSet];
+ } onCollectionViews:^(NSCollectionView * const collectionView){
+ [collectionView reloadItemsAtIndexPaths:indexPaths];
+ }];
+}
+
+- (void)handleLibraryItemChange:(id<VLCMediaLibraryItemProtocol>)item
+{
+ NSParameterAssert(item != nil);
+ const NSInteger row = [self rowContainingMediaItem:item];
+ if (row == NSNotFound) {
+ NSLog(@"VLCLibraryAudioGroupDataSource: Unable to find row for library item, can't change");
+ return;
+ }
+ [self handleAlbumUpdateInRow:row];
+}
+
+- (void)performActionOnTableViews:(void (^)(NSTableView *))tableViewAction
+ onCollectionViews:(void (^)(NSCollectionView *))collectionViewAction
+{
+ NSParameterAssert(tableViewAction != nil && collectionViewAction != nil);
+
+ NSArray<NSTableView *> * const tableViews = self.tableViews;
+ for (NSTableView * const tableView in tableViews) {
+ tableViewAction(tableView);
+ }
+
+ NSArray<NSCollectionView *> * const collectionViews = self.collectionViews;
+ for (NSCollectionView * const collectionView in collectionViews) {
+ collectionViewAction(collectionView);
+ }
+}
+
+- (void)libraryModelAudioMediaItemsReset:(NSNotification *)notification
+{
+ [self updateRepresentedListOfAlbums];
+}
+
+
+- (void)libraryModelAudioMediaItemUpdated:(NSNotification *)notification
+{
+ [self handleLibraryItemChange:notification.object];
+}
+
+- (void)libraryModelAudioMediaItemDeleted:(NSNotification *)notification
+{
+ [self handleLibraryItemChange:notification.object];
+}
+
+- (void)libraryModelAlbumsReset:(NSNotification *)notification
+{
+ [self updateRepresentedListOfAlbums];
+}
+
+- (void)libraryModelAlbumUpdated:(NSNotification *)notification
+{
+ const NSInteger row = [self rowForLibraryItem:notification.object];
+ if (row == NSNotFound) {
+ NSLog(@"VLCLibraryAudioGroupDataSource: Unable to find row for library item, can't update");
+ return;
+ }
+
+ [self handleAlbumUpdateInRow:row];
+}
+
+- (void)libraryModelAlbumDeleted:(NSNotification *)notification
+{
+ const NSInteger row = [self rowForLibraryItem:notification.object];
+ if (row == NSNotFound) {
+ NSLog(@"VLCLibraryAudioGroupDataSource: Unable to find row for library item, can't delete");
+ return;
+ }
+
+ NSIndexSet * const indexSet = [NSIndexSet indexSetWithIndex:row];
+ NSSet * const indexPaths = [NSSet setWithObject:[NSIndexPath indexPathForItem:row inSection:0]];
+
+ [self performActionOnTableViews:^(NSTableView * const tableView){
+ [tableView removeRowsAtIndexes:indexSet withAnimation:NSTableViewAnimationSlideUp];
+ } onCollectionViews:^(NSCollectionView * const collectionView){
+ [collectionView deleteItemsAtIndexPaths:indexPaths];
+ }];
+}
+
- (void)reloadTableViews
{
NSArray<NSTableView *> * const tableViews = self.tableViews;
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/83347d675b8f95df36eccb14ffed468f81fc385b...25b50ae6a0f080f3107f9072b0a6c1eee5cd99e8
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/83347d675b8f95df36eccb14ffed468f81fc385b...25b50ae6a0f080f3107f9072b0a6c1eee5cd99e8
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list