[vlc-commits] macosx/open: replace dictionary with magic keys by a proper structure to define input metadata

Felix Paul Kühne git at videolan.org
Fri Feb 1 16:41:59 CET 2019


vlc | branch: master | Felix Paul Kühne <felix at feepk.net> | Fri Feb  1 16:35:48 2019 +0100| [881cc835821c58497d730269d9b361e9a64eedb3] | committer: Felix Paul Kühne

macosx/open: replace dictionary with magic keys by a proper structure to define input metadata

Note that this switches the remaining entry points to the new playlist

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=881cc835821c58497d730269d9b361e9a64eedb3
---

 .../package/macosx/VLC.xcodeproj/project.pbxproj   |  6 +++
 modules/gui/macosx/Makefile.am                     |  1 +
 modules/gui/macosx/VLCMain.m                       |  8 ++--
 modules/gui/macosx/VLCOpenInputMetadata.h          | 45 ++++++++++++++++++++++
 modules/gui/macosx/VLCOpenInputMetadata.m          | 27 +++++++++++++
 modules/gui/macosx/VLCOpenWindowController.m       | 31 ++++++---------
 modules/gui/macosx/VLCPlaylistController.m         | 13 ++++---
 modules/gui/macosx/applescript.m                   | 10 ++---
 8 files changed, 107 insertions(+), 34 deletions(-)

diff --git a/extras/package/macosx/VLC.xcodeproj/project.pbxproj b/extras/package/macosx/VLC.xcodeproj/project.pbxproj
index d913151f34..a8b5713f7d 100644
--- a/extras/package/macosx/VLC.xcodeproj/project.pbxproj
+++ b/extras/package/macosx/VLC.xcodeproj/project.pbxproj
@@ -152,6 +152,7 @@
 		7DB7F20720CC07E600C2CAED /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7DB7F20620CC07E600C2CAED /* SystemConfiguration.framework */; };
 		7DB7F20920CC07FD00C2CAED /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7DB7F20820CC07FD00C2CAED /* WebKit.framework */; };
 		7DB7F20B20CC082800C2CAED /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7DB7F20A20CC082800C2CAED /* QuartzCore.framework */; };
+		7DC21A7422049A6600F98A02 /* VLCOpenInputMetadata.m in Sources */ = {isa = PBXBuildFile; fileRef = 7DC21A7322049A6600F98A02 /* VLCOpenInputMetadata.m */; };
 		7DD2F5C52081B73B007EE187 /* VLCRemoteControlService.m in Sources */ = {isa = PBXBuildFile; fileRef = 7DD2F5C42081B73B007EE187 /* VLCRemoteControlService.m */; };
 /* End PBXBuildFile section */
 
@@ -509,6 +510,8 @@
 		7DB7F20820CC07FD00C2CAED /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = System/Library/Frameworks/WebKit.framework; sourceTree = SDKROOT; };
 		7DB7F20A20CC082800C2CAED /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
 		7DBB06631CC2314D004C74D2 /* caopengllayer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = caopengllayer.m; path = ../../../modules/video_output/caopengllayer.m; sourceTree = "<group>"; };
+		7DC21A7222049A6600F98A02 /* VLCOpenInputMetadata.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VLCOpenInputMetadata.h; sourceTree = "<group>"; };
+		7DC21A7322049A6600F98A02 /* VLCOpenInputMetadata.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = VLCOpenInputMetadata.m; sourceTree = "<group>"; };
 		7DD2F5C32081B73B007EE187 /* VLCRemoteControlService.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VLCRemoteControlService.h; sourceTree = "<group>"; };
 		7DD2F5C42081B73B007EE187 /* VLCRemoteControlService.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = VLCRemoteControlService.m; sourceTree = "<group>"; };
 		7DF0435E1972E26A0022B534 /* VLCAddonListItem.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VLCAddonListItem.h; sourceTree = "<group>"; };
@@ -1318,6 +1321,8 @@
 			children = (
 				8ED6C28103E2EB1C0059A3A7 /* VLCOpenWindowController.h */,
 				8ED6C28203E2EB1C0059A3A7 /* VLCOpenWindowController.m */,
+				7DC21A7222049A6600F98A02 /* VLCOpenInputMetadata.h */,
+				7DC21A7322049A6600F98A02 /* VLCOpenInputMetadata.m */,
 			);
 			name = "Open media";
 			sourceTree = "<group>";
@@ -1692,6 +1697,7 @@
 				1CCC88FF2078A3D500E5626F /* PlaylistMenu.xib in Sources */,
 				1CCC89002078A3D500E5626F /* PopupPanel.xib in Sources */,
 				1CCC89012078A3D500E5626F /* Preferences.xib in Sources */,
+				7DC21A7422049A6600F98A02 /* VLCOpenInputMetadata.m in Sources */,
 				1CCC89022078A3D500E5626F /* ResumeDialog.xib in Sources */,
 				1CCC89032078A3D500E5626F /* SimplePreferences.xib in Sources */,
 				1CCC89042078A3D500E5626F /* StreamOutput.xib in Sources */,
diff --git a/modules/gui/macosx/Makefile.am b/modules/gui/macosx/Makefile.am
index 095cd311fb..9201351876 100644
--- a/modules/gui/macosx/Makefile.am
+++ b/modules/gui/macosx/Makefile.am
@@ -55,6 +55,7 @@ libmacosx_plugin_la_SOURCES = \
 	gui/macosx/NSSound+VLCAdditions.h gui/macosx/NSSound+VLCAdditions.m \
 	gui/macosx/NSScreen+VLCAdditions.h gui/macosx/NSScreen+VLCAdditions.m \
 	gui/macosx/VLCOpenWindowController.h gui/macosx/VLCOpenWindowController.m \
+	gui/macosx/VLCOpenInputMetadata.h gui/macosx/VLCOpenInputMetadata.m \
 	gui/macosx/VLCOutput.h gui/macosx/VLCOutput.m \
 	gui/macosx/VLCPlaylistView.h gui/macosx/VLCPlaylistView.m \
 	gui/macosx/VLCPlaylist.h gui/macosx/VLCPlaylist.m \
diff --git a/modules/gui/macosx/VLCMain.m b/modules/gui/macosx/VLCMain.m
index b0c57fad0b..87d24588a3 100644
--- a/modules/gui/macosx/VLCMain.m
+++ b/modules/gui/macosx/VLCMain.m
@@ -62,6 +62,7 @@
 #import "VLCConvertAndSaveWindowController.h"
 #import "VLCLibraryWindow.h"
 #import "VLCPlaylistController.h"
+#import "VLCOpenInputMetadata.h"
 
 #import "VLCVideoEffectsWindowController.h"
 #import "VLCAudioEffectsWindowController.h"
@@ -415,12 +416,13 @@ static VLCMain *sharedInstance = nil;
         if (!psz_uri)
             continue;
 
-        NSDictionary *o_dic = [NSDictionary dictionaryWithObject:toNSStr(psz_uri) forKey:@"ITEM_URL"];
-        [o_result addObject: o_dic];
+        VLCOpenInputMetadata *o_inputMetadata = [[VLCOpenInputMetadata alloc] init];
+        o_inputMetadata.MRLString = toNSStr(psz_uri);
+        [o_result addObject: o_inputMetadata];
         free(psz_uri);
     }
 
-    [[[VLCMain sharedInstance] playlist] addPlaylistItems:o_result tryAsSubtitle:YES];
+    [_playlistController addPlaylistItems:o_result];
 }
 
 /* When user click in the Dock icon our double click in the finder */
diff --git a/modules/gui/macosx/VLCOpenInputMetadata.h b/modules/gui/macosx/VLCOpenInputMetadata.h
new file mode 100644
index 0000000000..071df0d45c
--- /dev/null
+++ b/modules/gui/macosx/VLCOpenInputMetadata.h
@@ -0,0 +1,45 @@
+/*****************************************************************************
+ * VLCOpenInputMetadata.h: macOS interface
+ *****************************************************************************
+ * Copyright (C) 2019 VLC authors and VideoLAN
+ *
+ * Authors: Felix Paul Kühne <fkuehne # videolan dot org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#import <Foundation/Foundation.h>
+
+ at interface VLCOpenInputMetadata : NSObject
+
+/**
+ * this is the MRL of the future input item and defines where to search for media
+ * it is the only required property, because if unset we don't know what to play
+ */
+ at property (readwrite, copy) NSString *MRLString;
+
+/**
+ * this is an optional property to define the item name
+ * if not set, the MRL or (if suitable) a file name will be displayed to the user
+ */
+ at property (readwrite, copy) NSString *itemName;
+
+/**
+ * this is an optional property to define custom playback options
+ * this typically relies on VLC's private API and shall be considered potentially unstable
+ */
+ at property (readwrite, copy) NSArray *playbackOptions;
+
+ at end
diff --git a/modules/gui/macosx/VLCOpenInputMetadata.m b/modules/gui/macosx/VLCOpenInputMetadata.m
new file mode 100644
index 0000000000..2e6883a645
--- /dev/null
+++ b/modules/gui/macosx/VLCOpenInputMetadata.m
@@ -0,0 +1,27 @@
+/*****************************************************************************
+ * VLCOpenInputMetadata.h: macOS interface
+ *****************************************************************************
+ * Copyright (C) 2019 VLC authors and VideoLAN
+ *
+ * Authors: Felix Paul Kühne <fkuehne # videolan dot org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#import "VLCOpenInputMetadata.h"
+
+ at implementation VLCOpenInputMetadata
+
+ at end
diff --git a/modules/gui/macosx/VLCOpenWindowController.m b/modules/gui/macosx/VLCOpenWindowController.m
index 3ad907e334..77d834c2c3 100644
--- a/modules/gui/macosx/VLCOpenWindowController.m
+++ b/modules/gui/macosx/VLCOpenWindowController.m
@@ -24,22 +24,14 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
-#import <stdlib.h>                                      /* malloc(), free() */
-#import <sys/param.h>                                    /* for MAXPATHLEN */
-
-#import "CompatibilityFixes.h"
-
-#import <paths.h>
-#import <IOKit/IOBSD.h>
 #import <Cocoa/Cocoa.h>
 #import <AVFoundation/AVFoundation.h>
-#import <CoreMedia/CoreMedia.h>
 
 #import "VLCMain.h"
-#import "VLCPlaylist.h"
 #import "VLCOpenWindowController.h"
 #import "VLCOutput.h"
-#import "misc.h"
+#import "VLCPlaylistController.h"
+#import "VLCOpenInputMetadata.h"
 
 #import <vlc_url.h>
 
@@ -95,7 +87,6 @@ struct display_info_t
 
 @implementation VLCOpenWindowController
 
-
 static NSString *kFileTabViewId     = @"file";
 static NSString *kDiscTabViewId     = @"disc";
 static NSString *kNetworkTabViewId  = @"network";
@@ -110,7 +101,6 @@ static NSString *kCaptureTabViewId  = @"capture";
     return self;
 }
 
-
 - (void)dealloc
 {
     NSUInteger displayInfoCount = [_displayInfos count];
@@ -425,7 +415,8 @@ static NSString *kCaptureTabViewId  = @"capture";
         return;
 
     NSMutableArray *options = [NSMutableArray array];
-    NSMutableDictionary *itemOptionsDictionary = [NSMutableDictionary dictionaryWithObject: [self MRL] forKey: @"ITEM_URL"];
+    VLCOpenInputMetadata *inputMetadata = [[VLCOpenInputMetadata alloc] init];
+    inputMetadata.MRLString = [self MRL];
 
     if ([_fileSubCheckbox state] == NSOnState) {
         module_config_t * p_item;
@@ -507,9 +498,9 @@ static NSString *kCaptureTabViewId  = @"capture";
     }
 
     /* apply the options to our item(s) */
-    [itemOptionsDictionary setObject: (NSArray *)[options copy] forKey: @"ITEM_OPTIONS"];
+    inputMetadata.playbackOptions = options;
 
-    [[[VLCMain sharedInstance] playlist] addPlaylistItems:[NSArray arrayWithObject:itemOptionsDictionary]];
+    [[[VLCMain sharedInstance] playlistController] addPlaylistItems:@[inputMetadata]];
 }
 
 #pragma mark -
@@ -587,13 +578,14 @@ static NSString *kCaptureTabViewId  = @"capture";
         [values sortUsingSelector:@selector(caseInsensitiveCompare:)];
 
         for (NSUInteger i = 0; i < count; i++) {
-            NSDictionary *dictionary;
+            VLCOpenInputMetadata *inputMetadata;
             char *psz_uri = vlc_path2uri([[values objectAtIndex:i] UTF8String], "file");
             if (!psz_uri)
                 continue;
-            dictionary = [NSDictionary dictionaryWithObject:toNSStr(psz_uri) forKey:@"ITEM_URL"];
+            inputMetadata = [[VLCOpenInputMetadata alloc] init];
+            inputMetadata.MRLString = toNSStr(psz_uri);
             free(psz_uri);
-            [array addObject: dictionary];
+            [array addObject:inputMetadata];
         }
 
         action(array);
@@ -772,8 +764,7 @@ static NSString *kCaptureTabViewId  = @"capture";
         [self showOpticalMediaView: _discBDView withIcon: image];
         [self setMRL: [NSString stringWithFormat: @"bluray://%@", opticalDevicePath]];
     } else {
-        if (getIntf())
-            msg_Warn(getIntf(), "unknown disk type, no idea what to display");
+        msg_Warn(getIntf(), "unknown disk type, no idea what to display");
 
         [self showOpticalMediaView: _discNoDiscView withIcon: [NSImage imageNamed:@"NSApplicationIcon"]];
     }
diff --git a/modules/gui/macosx/VLCPlaylistController.m b/modules/gui/macosx/VLCPlaylistController.m
index 7035e8fb6e..6b816a6693 100644
--- a/modules/gui/macosx/VLCPlaylistController.m
+++ b/modules/gui/macosx/VLCPlaylistController.m
@@ -24,6 +24,7 @@
 #import "VLCPlaylistModel.h"
 #import "VLCPlaylistItem.h"
 #import "VLCPlaylistDataSource.h"
+#import "VLCOpenInputMetadata.h"
 #import "VLCMain.h"
 #import <vlc_interface.h>
 
@@ -301,9 +302,9 @@ static const struct vlc_playlist_callbacks playlist_callbacks = {
     NSUInteger numberOfItems = [itemArray count];
 
     for (NSUInteger i = 0; i < numberOfItems; i++) {
-        NSDictionary *itemMetadata = itemArray[i];
+        VLCOpenInputMetadata *itemMetadata = itemArray[i];
         input_item_t *p_input = [self createInputItemBasedOnMetadata:itemMetadata];
-        NSString *itemURLString = itemMetadata[@"ITEM_URL"];
+        NSString *itemURLString = itemMetadata.MRLString;
 
         if (!p_input) {
             if (itemURLString) {
@@ -437,7 +438,7 @@ static const struct vlc_playlist_callbacks playlist_callbacks = {
 
 #pragma mark - helper methods
 
-- (input_item_t *)createInputItemBasedOnMetadata:(NSDictionary *)itemToCreateDict
+- (input_item_t *)createInputItemBasedOnMetadata:(VLCOpenInputMetadata *)itemMetadata
 {
     intf_thread_t *p_intf = getIntf();
 
@@ -448,11 +449,11 @@ static const struct vlc_playlist_callbacks playlist_callbacks = {
     NSArray *optionsArray;
 
     /* Get the item */
-    uri = (NSString *)[itemToCreateDict objectForKey: @"ITEM_URL"];
+    uri = itemMetadata.MRLString;
     url = [NSURL URLWithString: uri];
     path = [url path];
-    name = (NSString *)[itemToCreateDict objectForKey: @"ITEM_NAME"];
-    optionsArray = (NSArray *)[itemToCreateDict objectForKey: @"ITEM_OPTIONS"];
+    name = itemMetadata.itemName;
+    optionsArray = itemMetadata.playbackOptions;
 
     if ([[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:&b_dir]
         && b_dir &&
diff --git a/modules/gui/macosx/applescript.m b/modules/gui/macosx/applescript.m
index ea8bd69eb3..683f93bf3a 100644
--- a/modules/gui/macosx/applescript.m
+++ b/modules/gui/macosx/applescript.m
@@ -27,7 +27,8 @@
 #import "VLCMain.h"
 #import "applescript.h"
 #import "VLCCoreInteraction.h"
-#import "VLCPlaylist.h"
+#import "VLCPlaylistController.h"
+#import "VLCOpenInputMetadata.h"
 #import <vlc_url.h>
 
 /*****************************************************************************
@@ -41,11 +42,10 @@
 
     if ([o_command isEqualToString:@"GetURL"] || [o_command isEqualToString:@"OpenURL"]) {
         if (o_urlString) {
+            VLCOpenInputMetadata *o_inputMetadata = [[VLCOpenInputMetadata alloc] init];
+            o_inputMetadata.MRLString = o_urlString;
 
-            NSDictionary *o_dic = [NSDictionary dictionaryWithObject:o_urlString forKey:@"ITEM_URL"];
-            NSArray* item = [NSArray arrayWithObject:o_dic];
-
-            [[[VLCMain sharedInstance] playlist] addPlaylistItems:item tryAsSubtitle:YES];
+            [[[VLCMain sharedInstance] playlistController] addPlaylistItems:@[o_inputMetadata]];
         }
     }
     return nil;



More information about the vlc-commits mailing list