[vlc-commits] [Git][videolan/vlc][master] 7 commits: macosx: Expose generateChildNodesForDirectoryNode in VLCMediaSource

Felix Paul Kühne (@fkuehne) gitlab at videolan.org
Thu Feb 13 06:55:59 UTC 2025



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


Commits:
33b72706 by Claudio Cambra at 2025-02-13T05:49:14+00:00
macosx: Expose generateChildNodesForDirectoryNode in VLCMediaSource

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

- - - - -
ab382911 by Claudio Cambra at 2025-02-13T05:49:14+00:00
macosx: When generating child nodes for a directory node, clear existing nodes

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

- - - - -
9a818d88 by Claudio Cambra at 2025-02-13T05:49:14+00:00
macosx: Observe current media source file path in media source data source, update when files change

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

- - - - -
0fe7af6a by Claudio Cambra at 2025-02-13T05:49:14+00:00
macosx: Extract configuration of dispatch source for location observation

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

- - - - -
80a6dc7d by Claudio Cambra at 2025-02-13T05:49:14+00:00
macosx: Refresh a node's children when setting it on the media source data source

Prevent going back in the navigation stack showing out-of-date folder
contents

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

- - - - -
e9069eec by Claudio Cambra at 2025-02-13T05:49:14+00:00
macosx: Store weak reference to parent base media source data source in media source data source

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

- - - - -
29890589 by Claudio Cambra at 2025-02-13T05:49:14+00:00
macosx: If the currently viewed folder is moved or deleted, go back to media source home view

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

- - - - -


5 changed files:

- modules/gui/macosx/library/media-source/VLCMediaSource.h
- modules/gui/macosx/library/media-source/VLCMediaSource.m
- modules/gui/macosx/library/media-source/VLCMediaSourceBaseDataSource.m
- modules/gui/macosx/library/media-source/VLCMediaSourceDataSource.h
- modules/gui/macosx/library/media-source/VLCMediaSourceDataSource.m


Changes:

=====================================
modules/gui/macosx/library/media-source/VLCMediaSource.h
=====================================
@@ -47,6 +47,8 @@ extern NSString *VLCMediaSourcePreparsingEnded;
 
 - (void)preparseInputNodeWithinTree:(VLCInputNode *)inputNode;
 - (void)clearChildNodesForNode:(input_item_node_t*)inputNode;
+- (void)generateChildNodesForDirectoryNode:(input_item_node_t*)directoryNode
+                                   withUrl:(NSURL*)directoryUrl;
 
 @property (nonatomic, readonly) NSString *mediaSourceDescription;
 @property (nonatomic, readonly) VLCInputNode *rootNode;


=====================================
modules/gui/macosx/library/media-source/VLCMediaSource.m
=====================================
@@ -417,6 +417,13 @@ static const char *const myFoldersDescription = "My Folders";
         return;
     }
 
+    // Clear pre-existing child nodes
+    while (directoryNode->i_children > 0) {
+        input_item_node_t * const child = directoryNode->pp_children[0];
+        input_item_node_RemoveNode(directoryNode, child);
+        input_item_node_Delete(child);
+    }
+
     NSError *error;
     NSArray<NSURL *> *subDirectories = [[NSFileManager defaultManager] contentsOfDirectoryAtURL:directoryUrl
                                                                      includingPropertiesForKeys:@[NSURLIsDirectoryKey]


=====================================
modules/gui/macosx/library/media-source/VLCMediaSourceBaseDataSource.m
=====================================
@@ -420,6 +420,7 @@ referenceSizeForHeaderInSection:(NSInteger)section
     newChildDataSource.pathControl = self.pathControl;
     newChildDataSource.tableView = self.tableView;
     newChildDataSource.navigationStack = self.navigationStack;
+    newChildDataSource.parentBaseDataSource = self;
 
     [self setChildDataSource:newChildDataSource];
     [self.navigationStack appendCurrentLibraryState];


=====================================
modules/gui/macosx/library/media-source/VLCMediaSourceDataSource.h
=====================================
@@ -29,6 +29,7 @@ NS_ASSUME_NONNULL_BEGIN
 @class VLCInputNodePathControl;
 @class VLCLibraryMediaSourceViewNavigationStack;
 @class VLCMediaSource;
+ at class VLCMediaSourceBaseDataSource;
 
 extern NSString * const VLCMediaSourceDataSourceNodeChanged;
 
@@ -44,6 +45,7 @@ extern NSString * const VLCMediaSourceDataSourceNodeChanged;
 @property (readwrite, weak) NSTableView *tableView;
 @property (readwrite, weak) VLCInputNodePathControl *pathControl;
 @property (readwrite, weak) VLCLibraryMediaSourceViewNavigationStack *navigationStack;
+ at property (readwrite, weak) VLCMediaSourceBaseDataSource *parentBaseDataSource;
 
 - (void)setupViews;
 - (VLCInputItem *)mediaSourceInputItemAtRow:(NSInteger)tableViewRow;


=====================================
modules/gui/macosx/library/media-source/VLCMediaSourceDataSource.m
=====================================
@@ -22,7 +22,13 @@
 
 #import "VLCMediaSourceDataSource.h"
 
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+
 #import "VLCLibraryMediaSourceViewNavigationStack.h"
+#import "VLCMediaSourceBaseDataSource.h"
 #import "VLCMediaSourceCollectionViewItem.h"
 #import "VLCMediaSource.h"
 
@@ -47,15 +53,65 @@ NSString * const VLCMediaSourceDataSourceNodeChanged = @"VLCMediaSourceDataSourc
 {
     VLCInputItem *_childRootInput;
 }
+
+ at property (readwrite) dispatch_source_t observedPathDispatchSource;
+
 @end
 
 @implementation VLCMediaSourceDataSource
 
+- (dispatch_source_t)observeLocalUrl:(NSURL *)url
+                      forVnodeEvents:(dispatch_source_vnode_flags_t)eventsFlags
+                    withEventHandler:(dispatch_block_t)eventHandlerBlock
+{
+    const uintptr_t descriptor = open(url.path.UTF8String, O_EVTONLY);
+    if (descriptor == -1) {
+        return nil;
+    }
+    struct stat fileStat;
+    const int statResult = fstat(descriptor, &fileStat);
+
+    const dispatch_queue_t globalQueue =
+        dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
+    const dispatch_source_t fileDispatchSource =
+        dispatch_source_create(DISPATCH_SOURCE_TYPE_VNODE, descriptor, eventsFlags, globalQueue);
+    dispatch_source_set_event_handler(fileDispatchSource, eventHandlerBlock);
+    dispatch_source_set_cancel_handler(fileDispatchSource, ^{
+        close(descriptor);
+    });
+    dispatch_resume(fileDispatchSource);
+    return fileDispatchSource;
+}
+
 - (void)setNodeToDisplay:(nonnull VLCInputNode*)nodeToDisplay
 {
     NSAssert(nodeToDisplay, @"Nil node to display, will not set");
     _nodeToDisplay = nodeToDisplay;
+
+    input_item_node_t * const inputNode = nodeToDisplay.vlcInputItemNode;
+    NSURL * const nodeUrl = [NSURL URLWithString:nodeToDisplay.inputItem.MRL];
+    [self.displayedMediaSource generateChildNodesForDirectoryNode:inputNode withUrl:nodeUrl];
+
     [self reloadData];
+
+    const __weak typeof(self) weakSelf = self;
+
+    self.observedPathDispatchSource = [self observeLocalUrl:nodeUrl
+                                             forVnodeEvents:DISPATCH_VNODE_WRITE | DISPATCH_VNODE_DELETE | DISPATCH_VNODE_RENAME
+                                           withEventHandler:^{
+        const uintptr_t eventFlags = dispatch_source_get_data(weakSelf.observedPathDispatchSource);
+        if (eventFlags & DISPATCH_VNODE_DELETE || eventFlags & DISPATCH_VNODE_RENAME) {
+            dispatch_async(dispatch_get_main_queue(), ^{
+                [weakSelf.parentBaseDataSource homeButtonAction:weakSelf];
+            });
+        } else {
+            dispatch_async(dispatch_get_main_queue(), ^{
+                [weakSelf.displayedMediaSource generateChildNodesForDirectoryNode:inputNode
+                                                                          withUrl:nodeUrl];
+                [weakSelf reloadData];
+            });
+        }
+    }];
 }
 
 - (void)setupViews



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/b4c8a4cafa8982ab8e596e393afb010b23de8ed8...2989058985e4ec855d7afcf3688233a732e5f810

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