[vlc-commits] [Git][videolan/vlc][master] 11 commits: macosx: Add class method to acquire VLCMediaLibraryGroup via library ID

Felix Paul Kühne (@fkuehne) gitlab at videolan.org
Sun Aug 18 06:13:15 UTC 2024



Felix Paul Kühne pushed to branch master at VideoLAN / VLC


Commits:
80c5ae09 by Claudio Cambra at 2024-08-17T17:53:35+00:00
macosx: Add class method to acquire VLCMediaLibraryGroup via library ID

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
c9735f22 by Claudio Cambra at 2024-08-17T17:53:35+00:00
macosx: Add group update notification name

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
04640abe by Claudio Cambra at 2024-08-17T17:53:35+00:00
macosx: Add group cache modification queue

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
5a3491fc by Claudio Cambra at 2024-08-17T17:53:35+00:00
macosx: Handle group update events granularly

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
a35c5564 by Claudio Cambra at 2024-08-17T17:53:35+00:00
macosx: Handle group deletion events granularly

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
66241e45 by Claudio Cambra at 2024-08-17T17:53:35+00:00
macosx: Use correct modification queue for playlist events

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
0e069f33 by Claudio Cambra at 2024-08-17T17:53:35+00:00
macosx: Respond to new group related notifications in sidebar view controller

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
4fe0cdea by Claudio Cambra at 2024-08-17T17:53:35+00:00
macosx: Handle new group update and deletions in data source

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
839e4b3b by Claudio Cambra at 2024-08-17T17:53:35+00:00
macosx: Granularly update group views when receiving update notification in data source

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
982961a8 by Claudio Cambra at 2024-08-17T17:53:35+00:00
macosx: Ensure we properly update the detail table view, maintain the selection post-update, and do so without unnecessary reloads

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
e9811999 by Claudio Cambra at 2024-08-17T17:53:35+00:00
macosx: Granularly handle deletions in groups data source

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -


6 changed files:

- modules/gui/macosx/library/VLCLibraryDataTypes.h
- modules/gui/macosx/library/VLCLibraryDataTypes.m
- modules/gui/macosx/library/VLCLibraryModel.h
- modules/gui/macosx/library/VLCLibraryModel.m
- modules/gui/macosx/library/VLCLibraryWindowNavigationSidebarViewController.m
- modules/gui/macosx/library/groups-library/VLCLibraryGroupsDataSource.m


Changes:

=====================================
modules/gui/macosx/library/VLCLibraryDataTypes.h
=====================================
@@ -233,8 +233,6 @@ typedef NS_ENUM(NSUInteger, VLCMediaLibraryParentGroupType) {
 
 @interface VLCMediaLibraryGroup : VLCAbstractMediaLibraryItem
 
-- (instancetype)initWithGroup:(struct vlc_ml_group_t *)p_group;
-
 @property (readonly) NSString *name;
 @property (readonly) NSUInteger numberOfTotalItems;
 @property (readonly) NSUInteger numberOfVideoItems;
@@ -250,6 +248,9 @@ typedef NS_ENUM(NSUInteger, VLCMediaLibraryParentGroupType) {
 @property (readonly) NSDate *creationDate;
 @property (readonly) NSDate *lastModificationDate;
 
++ (nullable instancetype)groupWithID:(int64_t)libraryID;
+- (instancetype)initWithGroup:(struct vlc_ml_group_t *)p_group;
+
 @end
 
 @interface VLCMediaLibraryPlaylist : VLCAbstractMediaLibraryItem<VLCMediaLibraryItemProtocol>


=====================================
modules/gui/macosx/library/VLCLibraryDataTypes.m
=====================================
@@ -779,6 +779,16 @@ static NSString *genreArrayDisplayString(NSArray<VLCMediaLibraryGenre *> * const
 @synthesize primaryActionableDetailLibraryItem = _primaryActionableDetailLibraryItem;
 @synthesize secondaryActionableDetailLibraryItem = _secondaryActionableDetailLibraryItem;
 
++ (nullable instancetype)groupWithID:(int64_t)libraryID
+{
+    vlc_medialibrary_t * const p_mediaLibrary = getMediaLibrary();
+    if (!p_mediaLibrary) {
+        return nil;
+    }
+    vlc_ml_group_t * const p_group = vlc_ml_get_group(p_mediaLibrary, libraryID);
+    return p_group ? [[VLCMediaLibraryGroup alloc] initWithGroup:p_group] : nil;
+}
+
 - (instancetype)initWithGroup:(struct vlc_ml_group_t *)p_group
 {
     NSParameterAssert(p_group != NULL);


=====================================
modules/gui/macosx/library/VLCLibraryModel.h
=====================================
@@ -48,6 +48,7 @@ extern NSString * const VLCLibraryModelRecentAudioMediaItemDeleted;
 extern NSString * const VLCLibraryModelAlbumDeleted;
 extern NSString * const VLCLibraryModelArtistDeleted;
 extern NSString * const VLCLibraryModelGenreDeleted;
+extern NSString * const VLCLibraryModelGroupDeleted;
 extern NSString * const VLCLibraryModelPlaylistDeleted;
 
 extern NSString * const VLCLibraryModelAudioMediaItemUpdated;
@@ -57,6 +58,7 @@ extern NSString * const VLCLibraryModelRecentAudioMediaItemUpdated;
 extern NSString * const VLCLibraryModelAlbumUpdated;
 extern NSString * const VLCLibraryModelArtistUpdated;
 extern NSString * const VLCLibraryModelGenreUpdated;
+extern NSString * const VLCLibraryModelGroupUpdated;
 extern NSString * const VLCLibraryModelPlaylistUpdated;
 
 @interface VLCLibraryModel : NSObject


=====================================
modules/gui/macosx/library/VLCLibraryModel.m
=====================================
@@ -48,6 +48,7 @@ NSString * const VLCLibraryModelRecentAudioMediaItemDeleted = @"VLCLibraryModelR
 NSString * const VLCLibraryModelAlbumDeleted = @"VLCLibraryModelAlbumDeleted";
 NSString * const VLCLibraryModelArtistDeleted = @"VLCLibraryModelArtistDeleted";
 NSString * const VLCLibraryModelGenreDeleted = @"VLCLibraryModelGenreDeleted";
+NSString * const VLCLibraryModelGroupDeleted = @"VLCLibraryModelGroupDeleted";
 NSString * const VLCLibraryModelPlaylistDeleted = @"VLCLibraryModelPlaylistDeleted";
 
 NSString * const VLCLibraryModelAudioMediaItemUpdated = @"VLCLibraryModelAudioMediaItemUpdated";
@@ -57,6 +58,7 @@ NSString * const VLCLibraryModelRecentAudioMediaItemUpdated = @"VLCLibraryModelR
 NSString * const VLCLibraryModelAlbumUpdated = @"VLCLibraryModelAlbumUpdated";
 NSString * const VLCLibraryModelArtistUpdated = @"VLCLibraryModelArtistUpdated";
 NSString * const VLCLibraryModelGenreUpdated = @"VLCLibraryModelGenreUpdated";
+NSString * const VLCLibraryModelGroupUpdated = @"VLCLibraryModelGroupUpdated";
 NSString * const VLCLibraryModelPlaylistUpdated = @"VLCLibraryModelPlaylistUpdated";
 
 @interface VLCLibraryModel ()
@@ -84,6 +86,7 @@ NSString * const VLCLibraryModelPlaylistUpdated = @"VLCLibraryModelPlaylistUpdat
     dispatch_queue_t _albumCacheModificationQueue;
     dispatch_queue_t _artistCacheModificationQueue;
     dispatch_queue_t _genreCacheModificationQueue;
+    dispatch_queue_t _groupCacheModificationQueue;
     dispatch_queue_t _playlistCacheModificationQueue;
 }
 
@@ -112,11 +115,13 @@ NSString * const VLCLibraryModelPlaylistUpdated = @"VLCLibraryModelPlaylistUpdat
 - (void)handleAlbumDeletionEvent:(const vlc_ml_event_t * const)p_event;
 - (void)handleArtistDeletionEvent:(const vlc_ml_event_t * const)p_event;
 - (void)handleGenreDeletionEvent:(const vlc_ml_event_t * const)p_event;
+- (void)handleGroupDeletionEvent:(const vlc_ml_event_t * const)p_event;
 - (void)handlePlaylistDeletionEvent:(const vlc_ml_event_t * const)p_event;
 - (void)handleMediaItemUpdateEvent:(const vlc_ml_event_t * const)p_event;
 - (void)handleAlbumUpdateEvent:(const vlc_ml_event_t * const)p_event;
 - (void)handleArtistUpdateEvent:(const vlc_ml_event_t * const)p_event;
 - (void)handleGenreUpdateEvent:(const vlc_ml_event_t * const)p_event;
+- (void)handleGroupUpdateEvent:(const vlc_ml_event_t * const)p_event;
 - (void)handlePlaylistUpdateEvent:(const vlc_ml_event_t * const)p_event;
 
 @end
@@ -181,9 +186,14 @@ static void libraryCallback(void *p_data, const vlc_ml_event_t *p_event)
             [libraryModel handleGenreDeletionEvent:p_event];
             break;
         case VLC_ML_EVENT_GROUP_ADDED:
+            [libraryModel resetCachedListOfGroups];
+            break;
         case VLC_ML_EVENT_GROUP_UPDATED:
+            [libraryModel handleGroupUpdateEvent:p_event];
+            break;
         case VLC_ML_EVENT_GROUP_DELETED:
-            [libraryModel resetCachedListOfGroups]; // TODO: Handle each event granularly
+            [libraryModel handleGroupDeletionEvent:p_event];
+            break;
         case VLC_ML_EVENT_PLAYLIST_ADDED:
             [libraryModel resetCachedListOfPlaylists];
             break;
@@ -235,6 +245,7 @@ static void libraryCallback(void *p_data, const vlc_ml_event_t *p_event)
         _albumCacheModificationQueue = dispatch_queue_create("albumCacheModificationQueue", 0);
         _artistCacheModificationQueue = dispatch_queue_create("artistCacheModificationQueue", 0);
         _genreCacheModificationQueue = dispatch_queue_create("genreCacheModificationQueue", 0);
+        _groupCacheModificationQueue = dispatch_queue_create("groupCacheModificationQueue", 0);
         _playlistCacheModificationQueue = dispatch_queue_create("playlistCacheModificationQueue", 0);
 
         _defaultNotificationCenter = NSNotificationCenter.defaultCenter;
@@ -1161,6 +1172,70 @@ static void libraryCallback(void *p_data, const vlc_ml_event_t *p_event)
                 withNotificationName:VLCLibraryModelGenreDeleted];
 }
 
+- (void)handleGroupDeletionEvent:(const vlc_ml_event_t *const)p_event
+{
+    NSParameterAssert(p_event != NULL);
+
+    const int64_t itemId = p_event->modification.i_entity_id;
+
+    dispatch_async(_groupCacheModificationQueue, ^{
+        NSMutableArray * const mutableGroups = self.cachedListOfGroups.mutableCopy;
+        const NSUInteger groupIdx =
+            [mutableGroups indexOfObjectPassingTest:^BOOL(VLCMediaLibraryGroup * const group,
+                                                          const NSUInteger idx,
+                                                          BOOL * const stop) {
+            return group.libraryID == itemId;
+        }];
+
+        if (groupIdx == NSNotFound) {
+            NSLog(@"Could not handle deletion of groupI with id %lld in model", itemId);
+            return;
+        }
+
+        dispatch_sync(dispatch_get_main_queue(), ^{
+            VLCMediaLibraryGroup * const group = mutableGroups[groupIdx];
+            [mutableGroups removeObjectAtIndex:groupIdx];
+            self.cachedListOfGroups = mutableGroups.copy;
+            [self->_defaultNotificationCenter postNotificationName:VLCLibraryModelGroupDeleted
+                                                            object:group];
+        });
+    });
+}
+
+- (void)handleGroupUpdateEvent:(const vlc_ml_event_t *const)p_event
+{
+    NSParameterAssert(p_event != NULL);
+
+    const int64_t itemId = p_event->modification.i_entity_id;
+    VLCMediaLibraryGroup * const group = [VLCMediaLibraryGroup groupWithID:itemId];
+    if (group == nil) {
+        NSLog(@"Could not find a library group with this ID. Can't handle update.");
+        return;
+    }
+
+    dispatch_async(_groupCacheModificationQueue, ^{
+        const NSUInteger groupIdx = 
+            [self.cachedListOfGroups indexOfObjectPassingTest:^BOOL(VLCMediaLibraryGroup * const group,
+                                                                    const NSUInteger idx,
+                                                                    BOOL * const stop) {
+            NSAssert(group != nil, @"Cache list should not contain nil groups");
+            return group.libraryID == itemId;
+        }];
+
+        if (groupIdx == NSNotFound) {
+            NSLog(@"Could not handle deletion of group with id %lld in model", itemId);
+            return;
+        }
+
+        dispatch_sync(dispatch_get_main_queue(), ^{
+            NSMutableArray * const mutableGroups = self.cachedListOfGroups.mutableCopy;
+            [mutableGroups replaceObjectAtIndex:groupIdx withObject:group];
+            self.cachedListOfGroups = mutableGroups.copy;
+            [self->_defaultNotificationCenter postNotificationName:VLCLibraryModelGroupUpdated object:group];
+        });
+    });
+}
+
 - (void)handlePlaylistUpdateEvent:(const vlc_ml_event_t * const)p_event
 {
     NSParameterAssert(p_event != NULL);
@@ -1172,7 +1247,7 @@ static void libraryCallback(void *p_data, const vlc_ml_event_t *p_event)
         return;
     }
 
-    dispatch_async(_mediaItemCacheModificationQueue, ^{
+    dispatch_async(_playlistCacheModificationQueue, ^{
         NSMutableArray * const mutablePlaylists = self.cachedPlaylists.mutableCopy;
         const NSUInteger playlistIdx = [mutablePlaylists indexOfObjectPassingTest:^BOOL(VLCMediaLibraryPlaylist * const playlist, const NSUInteger idx, BOOL * const stop) {
             NSAssert(playlist != nil, @"Cache list should not contain nil playlists");
@@ -1198,7 +1273,7 @@ static void libraryCallback(void *p_data, const vlc_ml_event_t *p_event)
 
     const int64_t itemId = p_event->modification.i_entity_id;
 
-    dispatch_async(_mediaItemCacheModificationQueue, ^{
+    dispatch_async(_playlistCacheModificationQueue, ^{
         NSMutableArray * const mutablePlaylists = self.cachedPlaylists.mutableCopy;
         const NSUInteger playlistIdx = [mutablePlaylists indexOfObjectPassingTest:^BOOL(VLCMediaLibraryPlaylist * const playlist, const NSUInteger idx, BOOL * const stop) {
             NSAssert(playlist != nil, @"Cache list should not contain nil playlists");


=====================================
modules/gui/macosx/library/VLCLibraryWindowNavigationSidebarViewController.m
=====================================
@@ -82,6 +82,14 @@ static NSString * const VLCLibrarySegmentCellIdentifier = @"VLCLibrarySegmentCel
                       selector:@selector(internalNodesChanged:)
                           name:VLCLibraryModelListOfGroupsReset
                         object:nil];
+    [defaultCenter addObserver:self
+                      selector:@selector(internalNodesChanged:)
+                          name:VLCLibraryModelGroupUpdated
+                        object:nil];
+    [defaultCenter addObserver:self
+                      selector:@selector(internalNodesChanged:)
+                          name:VLCLibraryModelGroupDeleted
+                        object:nil];
 }
 
 - (void)internalNodesChanged:(NSNotification *)notification


=====================================
modules/gui/macosx/library/groups-library/VLCLibraryGroupsDataSource.m
=====================================
@@ -43,6 +43,14 @@
                            selector:@selector(libraryModelGroupsListReset:)
                                name:VLCLibraryModelListOfGroupsReset
                              object:nil];
+    [notificationCenter addObserver:self
+                           selector:@selector(libraryModelGroupDeleted:)
+                               name:VLCLibraryModelGroupDeleted
+                             object:nil];
+    [notificationCenter addObserver:self
+                           selector:@selector(libraryModelGroupUpdated:)
+                               name:VLCLibraryModelGroupUpdated
+                             object:nil];
 
     [self reloadData];
 }
@@ -67,4 +75,47 @@
     return VLCMediaLibraryParentGroupTypeGroup;
 }
 
+- (void)libraryModelGroupUpdated:(NSNotification *)notification
+{
+    VLCMediaLibraryGroup * const group = notification.object;
+    NSIndexPath * const indexPath = [self indexPathForLibraryItem:group];
+
+    if (indexPath != nil) {
+        [self.collectionView reloadItemsAtIndexPaths:[NSSet setWithObject:indexPath]];
+    }
+
+    const NSInteger rowIndex = [self rowForLibraryItem:group];
+    if (rowIndex != NSNotFound) {
+        const NSInteger selectedMasterRow = self.masterTableView.selectedRow;
+        [self.masterTableView reloadDataForRowIndexes:[NSIndexSet indexSetWithIndex:rowIndex]
+                                        columnIndexes:[NSIndexSet indexSetWithIndex:0]];
+
+        // Check, if the selected row was for the group that has been reloaded, if the selection in
+        // the master table view has changed after reloading the target index. In this case, we want
+        // to reselect. If the selection has been maintained then we need to reload the detail table
+        // view.
+        if (rowIndex == selectedMasterRow && self.masterTableView.selectedRow != selectedMasterRow) {
+            [self.masterTableView selectRow:selectedMasterRow byExtendingSelection:NO];
+        } else {
+            [self.detailTableView reloadData];
+        }
+    }
+}
+
+- (void)libraryModelGroupDeleted:(NSNotification *)notification
+{
+    VLCMediaLibraryGroup * const group = notification.object;
+    NSIndexPath * const indexPath = [self indexPathForLibraryItem:group];
+
+    if (indexPath != nil) {
+        [self.collectionView deleteItemsAtIndexPaths:[NSSet setWithObject:indexPath]];
+    }
+
+    const NSInteger rowIndex = [self rowForLibraryItem:group];
+    if (rowIndex != NSNotFound) {
+        [self.masterTableView removeRowsAtIndexes:[NSIndexSet indexSetWithIndex:rowIndex]
+                                    withAnimation:NSTableViewAnimationEffectFade];
+    }
+}
+
 @end



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/dba07a4112145ed10b27a4a28706317b6d14eec1...e98119994cc91d39386c8c842a9e4cc1db2b3968

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/dba07a4112145ed10b27a4a28706317b6d14eec1...e98119994cc91d39386c8c842a9e4cc1db2b3968
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