[vlc-commits] [Git][videolan/vlc][master] 9 commits: macosx: Remove redundant NULLin of _p_mediaSource->description

Felix Paul Kühne (@fkuehne) gitlab at videolan.org
Sun Oct 29 13:02:02 UTC 2023



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


Commits:
8d03b31a by Claudio Cambra at 2023-10-29T12:41:09+00:00
macosx: Remove redundant NULLin of _p_mediaSource->description

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

- - - - -
0a173b99 by Claudio Cambra at 2023-10-29T12:41:09+00:00
macosx: Add method to create a VLCMediaSource from a local URL

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

- - - - -
f77157a8 by Claudio Cambra at 2023-10-29T12:41:09+00:00
macosx: Remove erroneous semicolon from method implementation

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

- - - - -
0242d020 by Claudio Cambra at 2023-10-29T12:41:09+00:00
macosx: Add list of media sources for My Folders entry

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

- - - - -
5a06cf95 by Claudio Cambra at 2023-10-29T12:41:09+00:00
macosx: Replace per-folder media source My Folder with single My Folders media source

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

- - - - -
d64ad867 by Claudio Cambra at 2023-10-29T12:41:09+00:00
macosx: Add My Folders media source to list of local media sources

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

- - - - -
a592186a by Claudio Cambra at 2023-10-29T12:41:09+00:00
macosx: Provide clean names for my folders media source nodes

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

- - - - -
862073a6 by Claudio Cambra at 2023-10-29T12:41:09+00:00
macosx: Simplify looping over media sources in base data source

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

- - - - -
8403c838 by Claudio Cambra at 2023-10-29T12:41:09+00:00
macosx: Reorder, refactor instantiation of local media sources

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/VLCMediaSourceProvider.h
- modules/gui/macosx/library/media-source/VLCMediaSourceProvider.m


Changes:

=====================================
modules/gui/macosx/library/media-source/VLCMediaSource.h
=====================================
@@ -40,6 +40,7 @@ extern NSString *VLCMediaSourcePreparsingEnded;
 - (instancetype)initWithMediaSource:(vlc_media_source_t *)p_mediaSource
                   andLibVLCInstance:(libvlc_int_t *)p_libvlcInstance
                         forCategory:(enum services_discovery_category_e)category;
+- (instancetype)initMyFoldersMediaSourceWithLibVLCInstance:(libvlc_int_t *)p_libvlcInstance;
 
 - (void)preparseInputNodeWithinTree:(VLCInputNode *)inputNode;
 - (void)clearChildNodesForNode:(input_item_node_t*)inputNode;


=====================================
modules/gui/macosx/library/media-source/VLCMediaSource.m
=====================================
@@ -97,6 +97,7 @@ static const struct vlc_media_tree_callbacks treeCallbacks = {
 };
 
 static const char *const localDevicesDescription = "My Machine";
+static const char *const myFoldersDescription = "My Folders";
 
 #pragma mark - VLCMediaSource methods
 @implementation VLCMediaSource
@@ -146,6 +147,74 @@ static const char *const localDevicesDescription = "My Machine";
     return self;
 }
 
+- (instancetype)initMyFoldersMediaSourceWithLibVLCInstance:(libvlc_int_t *)p_libvlcInstance
+{
+    self = [super init];
+    if (self) {
+        _p_libvlcInstance = p_libvlcInstance;
+
+         _p_mediaSource = malloc(sizeof(vlc_media_source_t));
+        if (!_p_mediaSource) {
+            return self;
+        }
+
+        _p_mediaSource->description = myFoldersDescription;
+        _p_mediaSource->tree = calloc(1, sizeof(vlc_media_tree_t));
+
+        if (_p_mediaSource->tree == NULL) {
+            free(_p_mediaSource);
+            _p_mediaSource = NULL;
+            return self;
+        }
+
+        _category = SD_CAT_MYCOMPUTER;
+
+        NSFileManager * const fileManager = NSFileManager.defaultManager;
+
+        void (^addIfNotEmpty)(NSArray<NSURL *> *directories) = ^(NSArray<NSURL *> *directories) {
+            if (directories == nil || directories.count == 0) {
+                return;
+            }
+
+            NSURL * const directory = directories.firstObject;
+            const char * const directoryPath = directory.absoluteString.UTF8String;
+            const char * const directoryDesc = directory.lastPathComponent.UTF8String;
+            input_item_t * const directoryItem = input_item_NewExt(directoryPath,
+                                                                   directoryDesc,
+                                                                   0,
+                                                                   ITEM_TYPE_DIRECTORY,
+                                                                   ITEM_LOCAL);
+            input_item_node_t * const directoryNode = input_item_node_Create(directoryItem);
+            input_item_node_AppendNode(&(_p_mediaSource->tree->root), directoryNode);
+            input_item_Release(directoryItem);
+        };
+
+        NSArray<NSURL *> * const documentUrls = [fileManager URLsForDirectory:NSDocumentDirectory
+                                                                    inDomains:NSUserDomainMask];
+        addIfNotEmpty(documentUrls);
+
+        NSArray<NSURL *> * const desktopUrls = [fileManager URLsForDirectory:NSDesktopDirectory
+                                                                   inDomains:NSUserDomainMask];
+        addIfNotEmpty(desktopUrls);
+
+        NSArray<NSURL *> * const downloadsUrls = [fileManager URLsForDirectory:NSDownloadsDirectory
+                                                                     inDomains:NSUserDomainMask];
+        addIfNotEmpty(downloadsUrls);
+
+        NSArray<NSURL *> * const moviesUrls = [fileManager URLsForDirectory:NSMoviesDirectory
+                                                                  inDomains:NSUserDomainMask];
+        addIfNotEmpty(moviesUrls);
+
+        NSArray<NSURL *> * const musicUrls = [fileManager URLsForDirectory:NSMusicDirectory
+                                                                 inDomains:NSUserDomainMask];
+        addIfNotEmpty(musicUrls);
+
+        NSArray<NSURL *> * const picturesUrls = [fileManager URLsForDirectory:NSPicturesDirectory
+                                                                    inDomains:NSUserDomainMask];
+    }
+    return self;
+}
+
 - (void)dealloc
 {
     if (_p_mediaSource != NULL) {
@@ -153,8 +222,9 @@ static const char *const localDevicesDescription = "My Machine";
             vlc_media_tree_RemoveListener(_p_mediaSource->tree,
                                           _p_treeListenerID);
         }
-        if (_p_mediaSource->description == localDevicesDescription) {
+        if (_p_mediaSource->description == localDevicesDescription || _p_mediaSource->description == myFoldersDescription) {
             _p_mediaSource->description = NULL;
+
             input_item_node_t **childrenNodes = _p_mediaSource->tree->root.pp_children;
             if (childrenNodes) {
                 for (int i = 0; i <_p_mediaSource->tree->root.i_children; ++i) {
@@ -163,9 +233,7 @@ static const char *const localDevicesDescription = "My Machine";
                     input_item_node_Delete(childNode);
                 }
             }
-            
-            _p_mediaSource->description = NULL;
-            
+
             free(_p_mediaSource->tree);
             free(_p_mediaSource);
             _p_mediaSource = NULL;
@@ -356,7 +424,7 @@ static const char *const localDevicesDescription = "My Machine";
 - (VLCInputNode *)rootNode
 {
     VLCInputNode *inputNode = nil;
-    if (_p_mediaSource->description == localDevicesDescription) {
+    if (_p_mediaSource->description == localDevicesDescription || _p_mediaSource->description == myFoldersDescription) {
         // Since it is a manually constructed tree, we skip the locking
         inputNode = [[VLCInputNode alloc] initWithInputNode:&_p_mediaSource->tree->root];
     } else {


=====================================
modules/gui/macosx/library/media-source/VLCMediaSourceBaseDataSource.m
=====================================
@@ -155,14 +155,11 @@
     }
     NSAssert(mediaSources != nil, @"Media sources array should not be nil");
 
-    const NSUInteger count = mediaSources.count;
-    if (count > 0) {
-        for (NSUInteger x = 0; x < count; x++) {
-            VLCMediaSource * const mediaSource = mediaSources[x];
-            VLCInputNode * const rootNode = [mediaSource rootNode];
-            [mediaSource preparseInputNodeWithinTree:rootNode];
-        }
+    for (VLCMediaSource * const mediaSource in mediaSources) {
+        VLCInputNode * const rootNode = [mediaSource rootNode];
+        [mediaSource preparseInputNodeWithinTree:rootNode];
     }
+
     _mediaSources = mediaSources;
     [self.collectionView reloadData];
 }
@@ -338,8 +335,7 @@ referenceSizeForHeaderInSection:(NSInteger)section
             const NSInteger mediaSourceCount = _mediaSources.count;
             currentDevices = [[NSMutableArray alloc] initWithCapacity:mediaSourceCount];
 
-            for (NSUInteger x = 0; x < mediaSourceCount; x++) {
-                VLCMediaSource * const mediaSource = _mediaSources[x];
+            for (VLCMediaSource * const mediaSource in _mediaSources) {
                 VLCInputNode * const rootNode = mediaSource.rootNode;
                 [currentDevices addObjectsFromArray:rootNode.children];
             }


=====================================
modules/gui/macosx/library/media-source/VLCMediaSourceProvider.h
=====================================
@@ -30,9 +30,9 @@ NS_ASSUME_NONNULL_BEGIN
 
 @interface VLCMediaSourceProvider : NSObject
 
- at property (class, readonly) NSArray <VLCMediaSource *> *listOfLocalMediaSources;
+ at property(class, readonly) NSArray<VLCMediaSource *> *listOfLocalMediaSources;
 
-+ (NSArray <VLCMediaSource *> *)listOfMediaSourcesForCategory:(enum services_discovery_category_e)category;
++ (NSArray<VLCMediaSource *> *)listOfMediaSourcesForCategory:(enum services_discovery_category_e)category;
 
 @end
 


=====================================
modules/gui/macosx/library/media-source/VLCMediaSourceProvider.m
=====================================
@@ -70,14 +70,18 @@ static inline void getMediaSourcesForCategory(NSMutableArray <VLCMediaSource *>
     return [mutableArray copy];
 }
 
-+ (NSArray<VLCMediaSource *> *)listOfLocalMediaSources;
++ (NSArray<VLCMediaSource *> *)listOfLocalMediaSources
 {
-    libvlc_int_t *p_libvlcInstance = vlc_object_instance(getIntf());
-    vlc_media_source_provider_t *p_sourceProvider = vlc_media_source_provider_Get(p_libvlcInstance);
+    libvlc_int_t * const p_libvlcInstance = vlc_object_instance(getIntf());
+    NSMutableArray<VLCMediaSource *> * const mutableArray = [[NSMutableArray alloc] initWithCapacity:32]; // A sane default
 
-    NSMutableArray<VLCMediaSource *> *mutableArray = [[NSMutableArray alloc] initWithCapacity:32]; // A sane default
-    [mutableArray addObject:[[VLCMediaSource alloc] initForLocalDevices:p_libvlcInstance]];
+    // "My Folders" and "My Machine" entries are a bit of a custom implementation so it gets treated differently
+    VLCMediaSource * const myFoldersMediaSource = [[VLCMediaSource alloc] initMyFoldersMediaSourceWithLibVLCInstance:p_libvlcInstance];
+    VLCMediaSource * const localDevicesMediaSource = [[VLCMediaSource alloc] initForLocalDevices:p_libvlcInstance];
+    [mutableArray addObject:myFoldersMediaSource];
+    [mutableArray addObject:localDevicesMediaSource];
 
+    vlc_media_source_provider_t * const p_sourceProvider = vlc_media_source_provider_Get(p_libvlcInstance);
     if (p_sourceProvider != NULL) {
         // Currently, SD_CAT_MYCOMPUTER and SD_CAT_DEVICES return empty list.
         // They are left for future implementation.
@@ -89,9 +93,4 @@ static inline void getMediaSourcesForCategory(NSMutableArray <VLCMediaSource *>
     return [mutableArray copy];
 }
 
-
 @end
-
-
-
-



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/647d53d9d9f5fc19e59a6b48400144344a2dbb9b...8403c838aab4a0f90c2f2fcd9072af84e0d6194b

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/647d53d9d9f5fc19e59a6b48400144344a2dbb9b...8403c838aab4a0f90c2f2fcd9072af84e0d6194b
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