[vlc-commits] [Git][videolan/vlc][master] macosx: Fix the preferences' media library folders table

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Fri Aug 26 00:22:50 UTC 2022



Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC


Commits:
bec320b8 by Claudio Cambra at 2022-08-26T00:05:22+00:00
macosx: Fix the preferences' media library folders table

Signed-off-by: Claudio Cambra <claudio.cambra at gmail.com>

- - - - -


3 changed files:

- modules/gui/macosx/library/VLCLibraryModel.h
- modules/gui/macosx/library/VLCLibraryModel.m
- modules/gui/macosx/preferences/VLCSimplePrefsController.m


Changes:

=====================================
modules/gui/macosx/library/VLCLibraryModel.h
=====================================
@@ -38,6 +38,7 @@ extern NSString *VLCLibraryModelAlbumListUpdated;
 extern NSString *VLCLibraryModelGenreListUpdated;
 extern NSString *VLCLibraryModelVideoMediaListUpdated;
 extern NSString *VLCLibraryModelRecentMediaListUpdated;
+extern NSString *VLCLibraryModelListOfMonitoredFoldersUpdated;
 extern NSString *VLCLibraryModelMediaItemUpdated;
 
 @interface VLCLibraryModel : NSObject


=====================================
modules/gui/macosx/library/VLCLibraryModel.m
=====================================
@@ -32,6 +32,7 @@ NSString *VLCLibraryModelAlbumListUpdated = @"VLCLibraryModelAlbumListUpdated";
 NSString *VLCLibraryModelGenreListUpdated = @"VLCLibraryModelGenreListUpdated";
 NSString *VLCLibraryModelVideoMediaListUpdated = @"VLCLibraryModelVideoMediaListUpdated";
 NSString *VLCLibraryModelRecentMediaListUpdated = @"VLCLibraryModelRecentMediaListUpdated";
+NSString *VLCLibraryModelListOfMonitoredFoldersUpdated = @"VLCLibraryModelListOfMonitoredFoldersUpdated";
 NSString *VLCLibraryModelMediaItemUpdated = @"VLCLibraryModelMediaItemUpdated";
 
 @interface VLCLibraryModel ()
@@ -45,6 +46,7 @@ NSString *VLCLibraryModelMediaItemUpdated = @"VLCLibraryModelMediaItemUpdated";
     NSArray *_cachedGenres;
     NSArray *_cachedVideoMedia;
     NSArray *_cachedRecentMedia;
+    NSArray *_cachedListOfMonitoredFolders;
     NSNotificationCenter *_defaultNotificationCenter;
 
     enum vlc_ml_sorting_criteria_t _sortCriteria;
@@ -61,6 +63,7 @@ NSString *VLCLibraryModelMediaItemUpdated = @"VLCLibraryModelMediaItemUpdated";
 - (void)updateCachedListOfArtists;
 - (void)updateCachedListOfAlbums;
 - (void)updateCachedListOfGenres;
+- (void)updateCachedListOfMonitoredFolders;
 - (void)mediaItemWasUpdated:(VLCMediaLibraryMediaItem *)mediaItem;
 
 @end
@@ -121,6 +124,15 @@ static void libraryCallback(void *p_data, const vlc_ml_event_t *p_event)
             });
             break;
         }
+        case VLC_ML_EVENT_FOLDER_ADDED:
+        case VLC_ML_EVENT_FOLDER_UPDATED:
+        case VLC_ML_EVENT_FOLDER_DELETED:
+        {
+            dispatch_async(dispatch_get_main_queue(), ^{
+                VLCLibraryModel *libraryModel = (__bridge VLCLibraryModel *)p_data;
+                [libraryModel updateCachedListOfMonitoredFolders];
+            });
+        }
         default:
             break;
     }
@@ -419,24 +431,41 @@ static void libraryCallback(void *p_data, const vlc_ml_event_t *p_event)
     return _cachedRecentMedia;
 }
 
-- (NSArray<VLCMediaLibraryEntryPoint *> *)listOfMonitoredFolders
+- (void)updateCachedListOfMonitoredFolders
 {
-    vlc_ml_folder_list_t *pp_entrypoints = vlc_ml_list_entry_points(_p_mediaLibrary, NULL);
-    if (pp_entrypoints == NULL) {
-        msg_Err(getIntf(), "failed to retrieve list of monitored library folders");
-        return @[];
-    }
+    dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INTERACTIVE, 0), ^{
+        vlc_ml_folder_list_t *pp_entrypoints = vlc_ml_list_entry_points(self->_p_mediaLibrary, NULL);
+        if (pp_entrypoints == NULL) {
+            msg_Err(getIntf(), "failed to retrieve list of monitored library folders");
+            return;
+        }
 
-    NSMutableArray *mutableArray = [[NSMutableArray alloc] initWithCapacity:pp_entrypoints->i_nb_items];
-    for (size_t x = 0; x < pp_entrypoints->i_nb_items; x++) {
-        VLCMediaLibraryEntryPoint *entryPoint = [[VLCMediaLibraryEntryPoint alloc] initWithEntryPoint:&pp_entrypoints->p_items[x]];
-        if (entryPoint) {
-            [mutableArray addObject:entryPoint];
+        NSMutableArray *mutableArray = [[NSMutableArray alloc] initWithCapacity:pp_entrypoints->i_nb_items];
+        for (size_t x = 0; x < pp_entrypoints->i_nb_items; x++) {
+            VLCMediaLibraryEntryPoint *entryPoint = [[VLCMediaLibraryEntryPoint alloc] initWithEntryPoint:&pp_entrypoints->p_items[x]];
+            if (entryPoint) {
+                [mutableArray addObject:entryPoint];
+            }
         }
+
+        vlc_ml_folder_list_release(pp_entrypoints);
+
+        dispatch_async(dispatch_get_main_queue(), ^{
+            self->_cachedListOfMonitoredFolders = [mutableArray copy];
+            [self->_defaultNotificationCenter postNotificationName:VLCLibraryModelListOfMonitoredFoldersUpdated object:self];
+        });
+    });
+}
+
+- (NSArray<VLCMediaLibraryEntryPoint *> *)listOfMonitoredFolders
+{
+    if(!_cachedListOfMonitoredFolders) {
+        dispatch_async(dispatch_get_main_queue(), ^{
+            [self updateCachedListOfMonitoredFolders];
+        });
     }
 
-    vlc_ml_folder_list_release(pp_entrypoints);
-    return [mutableArray copy];
+    return _cachedListOfMonitoredFolders;
 }
 
 - (nullable NSArray <VLCMediaLibraryAlbum *>*)listAlbumsOfParentType:(enum vlc_ml_parent_type)parentType forID:(int64_t)ID;


=====================================
modules/gui/macosx/preferences/VLCSimplePrefsController.m
=====================================
@@ -134,8 +134,8 @@ static NSString* VLCHotkeysSettingToolbarIdentifier = @"Hotkeys Settings Item Id
 
 @interface VLCMediaLibraryFolderManagementController : NSObject <NSTableViewDelegate, NSTableViewDataSource>
 {
-    NSArray *_cachedFolderList;
     VLCLibraryController *_libraryController;
+    VLCLibraryModel *_libraryModel;
 }
 
 @property (readwrite, weak) NSTableView *libraryFolderTableView;
@@ -235,6 +235,7 @@ static NSString* VLCHotkeysSettingToolbarIdentifier = @"Hotkeys Settings Item Id
 
     _mediaLibraryFolderTableView.delegate = _mediaLibraryManagementController;
     _mediaLibraryFolderTableView.dataSource = _mediaLibraryManagementController;
+    _mediaLibraryManagementController.libraryFolderTableView = _mediaLibraryFolderTableView;
 
     _mediaLibraryManagementController.nameTableColumn = _mediaLibraryNameTableColumn;
     _mediaLibraryManagementController.presentTableColumn = _mediaLibraryPresentTableColumn;
@@ -1537,10 +1538,29 @@ static inline void save_string_list(intf_thread_t * p_intf, id object, const cha
     self = [super init];
     if (self) {
         _libraryController = [[VLCMain sharedInstance] libraryController];
+        _libraryModel = _libraryController.libraryModel;
+
+        NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
+        [notificationCenter addObserver:self
+                               selector:@selector(listOfMonitoredFoldersUpdated:)
+                                   name:VLCLibraryModelListOfMonitoredFoldersUpdated
+                                 object:nil];
     }
     return self;
 }
 
+- (void)dealloc
+{
+    [[NSNotificationCenter defaultCenter] removeObserver:self];
+}
+
+- (void)listOfMonitoredFoldersUpdated:(NSNotification *)aNotification
+{
+    NSLog(@"WEEEE");
+    [self.libraryFolderTableView reloadData];
+    NSLog(@"%@", _libraryModel.listOfMonitoredFolders);
+}
+
 - (IBAction)addFolder:(id)sender
 {
     NSOpenPanel *openPanel = [NSOpenPanel openPanel];
@@ -1558,49 +1578,34 @@ static inline void save_string_list(intf_thread_t * p_intf, id object, const cha
             NSURL *url = URLs[i];
             [_libraryController addFolderWithFileURL:url];
         }
-
-        _cachedFolderList = nil;
-        [self.libraryFolderTableView reloadData];
     }
 }
 
 - (IBAction)banFolder:(id)sender
 {
-    VLCMediaLibraryEntryPoint *entryPoint = _cachedFolderList[self.libraryFolderTableView.selectedRow];
+    VLCMediaLibraryEntryPoint *entryPoint = _libraryModel.listOfMonitoredFolders[self.libraryFolderTableView.selectedRow];
     if (entryPoint.isBanned) {
         [_libraryController unbanFolderWithFileURL:[NSURL URLWithString:entryPoint.MRL]];
     } else {
         [_libraryController banFolderWithFileURL:[NSURL URLWithString:entryPoint.MRL]];
     }
-
-    _cachedFolderList = nil;
-    [self.libraryFolderTableView reloadData];
 }
 
 - (IBAction)removeFolder:(id)sender
 {
-    VLCMediaLibraryEntryPoint *entryPoint = _cachedFolderList[self.libraryFolderTableView.selectedRow];
+    VLCMediaLibraryEntryPoint *entryPoint = _libraryModel.listOfMonitoredFolders[self.libraryFolderTableView.selectedRow];
     [_libraryController removeFolderWithFileURL:[NSURL URLWithString:entryPoint.MRL]];
-
-    _cachedFolderList = nil;
-    [self.libraryFolderTableView reloadData];
 }
 
 - (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView
 {
-    VLCLibraryModel *libraryModel = [_libraryController libraryModel];
-    if (!libraryModel) {
-        return 0;
-    }
-    if (!_cachedFolderList) {
-        _cachedFolderList = [libraryModel listOfMonitoredFolders];
-    }
-    return _cachedFolderList.count;
+    NSLog(@"%@", _libraryModel.listOfMonitoredFolders);
+    return _libraryModel.listOfMonitoredFolders.count;
 }
 
 - (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
 {
-    VLCMediaLibraryEntryPoint *entryPoint = _cachedFolderList[row];
+    VLCMediaLibraryEntryPoint *entryPoint = _libraryModel.listOfMonitoredFolders[row];
     if (tableColumn == self.nameTableColumn) {
         return [entryPoint.decodedMRL lastPathComponent];
     } else if (tableColumn == self.presentTableColumn) {
@@ -1620,7 +1625,7 @@ static inline void save_string_list(intf_thread_t * p_intf, id object, const cha
         return;
     }
     self.banFolderButton.enabled = self.removeFolderButton.enabled = YES;
-    VLCMediaLibraryEntryPoint *entryPoint = _cachedFolderList[selectedRow];
+    VLCMediaLibraryEntryPoint *entryPoint = _libraryModel.listOfMonitoredFolders[selectedRow];
     [self.banFolderButton setTitle:entryPoint.isBanned ? _NS("Unban Folder") : _NS("Ban Folder")];
 }
 



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/bec320b81a7f1d06c688d67a2dd45f0599573bcb

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