[vlc-commits] macosx: Factor code for drop handling of external files
David Fuhrmann
git at videolan.org
Fri Jan 1 22:40:33 CET 2016
vlc | branch: master | David Fuhrmann <dfuhrmann at videolan.org> | Fri Jan 1 22:31:21 2016 +0100| [e66d8e654f78c41a529632e7fa79846b2dcb4839] | committer: David Fuhrmann
macosx: Factor code for drop handling of external files
Adds helper method createItemsFromExternalPasteboard: returning
an array of file items from the pasteboard.
performDragOperation: in VLCCoreInteraction is the now only place
where we try to add the dropped file as a subtitle.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=e66d8e654f78c41a529632e7fa79846b2dcb4839
---
modules/gui/macosx/CoreInteraction.h | 1 +
modules/gui/macosx/CoreInteraction.m | 58 ++++++++++++++--------------------
modules/gui/macosx/MainWindow.m | 35 +++++++-------------
modules/gui/macosx/PLModel.m | 44 +++++++-------------------
modules/gui/macosx/VLCPlaylist.h | 8 +++++
modules/gui/macosx/VLCPlaylist.m | 24 ++++++++++++++
6 files changed, 79 insertions(+), 91 deletions(-)
diff --git a/modules/gui/macosx/CoreInteraction.h b/modules/gui/macosx/CoreInteraction.h
index 6ace054..043e4fb 100644
--- a/modules/gui/macosx/CoreInteraction.h
+++ b/modules/gui/macosx/CoreInteraction.h
@@ -71,6 +71,7 @@
- (void)stopListeningWithAppleRemote;
- (void)addSubtitlesToCurrentInput:(NSArray *)paths;
+
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender;
- (void)toggleFullscreen;
diff --git a/modules/gui/macosx/CoreInteraction.m b/modules/gui/macosx/CoreInteraction.m
index 400636b..312fa24 100644
--- a/modules/gui/macosx/CoreInteraction.m
+++ b/modules/gui/macosx/CoreInteraction.m
@@ -628,48 +628,36 @@ static int BossCallback(vlc_object_t *p_this, const char *psz_var,
}
}
-#pragma mark - drag and drop support for VLCVoutView, VLCDragDropView and VLCThreePartDropView
-- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
-{
- NSPasteboard *o_paste = [sender draggingPasteboard];
- NSArray *o_types = [NSArray arrayWithObject:NSFilenamesPboardType];
- NSString *o_desired_type = [o_paste availableTypeFromArray:o_types];
- NSData *o_carried_data = [o_paste dataForType:o_desired_type];
+#pragma mark - Drop support for files into the video, controls bar or drop box
- if (o_carried_data) {
- if ([o_desired_type isEqualToString:NSFilenamesPboardType]) {
- NSArray *o_array = [NSArray array];
- NSArray *o_values = [[o_paste propertyListForType: NSFilenamesPboardType] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
- NSUInteger count = [o_values count];
+- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender;
+{
+ NSArray *items = [[[VLCMain sharedInstance] playlist] createItemsFromExternalPasteboard:[sender draggingPasteboard]];
- input_thread_t * p_input = pl_CurrentInput(VLCIntf);
+ if (items.count == 0)
+ return NO;
- if (count == 1 && p_input) {
- int i_result = input_AddSubtitleOSD(p_input, [[o_values firstObject] UTF8String], true, true);
- vlc_object_release(p_input);
- if (i_result == VLC_SUCCESS)
- return YES;
- }
- else if (p_input)
+ // Try to add file as a subtitle
+ input_thread_t *p_input = pl_CurrentInput(VLCIntf);
+ if (items.count == 1 && p_input) {
+ NSString *url = [[items firstObject] valueForKey:@"ITEM_URL"];
+ char *path = vlc_uri2path([url UTF8String]);
+
+ if (path) {
+ int i_result = input_AddSubtitleOSD(p_input, path, true, true);
+ free(path);
+ if (i_result == VLC_SUCCESS) {
vlc_object_release(p_input);
-
- for (NSUInteger i = 0; i < count; i++) {
- NSDictionary *o_dic;
- char *psz_uri = vlc_path2uri([[o_values objectAtIndex:i] UTF8String], NULL);
- if (!psz_uri)
- continue;
-
- o_dic = [NSDictionary dictionaryWithObject:toNSStr(psz_uri) forKey:@"ITEM_URL"];
- free(psz_uri);
-
- o_array = [o_array arrayByAddingObject: o_dic];
+ return YES;
}
-
- [[[VLCMain sharedInstance] playlist] addPlaylistItems:o_array];
- return YES;
}
}
- return NO;
+
+ if (p_input)
+ vlc_object_release(p_input);
+
+ [[[VLCMain sharedInstance] playlist] addPlaylistItems:items];
+ return YES;
}
#pragma mark - video output stuff
diff --git a/modules/gui/macosx/MainWindow.m b/modules/gui/macosx/MainWindow.m
index 4ea2687..6d8c294 100644
--- a/modules/gui/macosx/MainWindow.m
+++ b/modules/gui/macosx/MainWindow.m
@@ -1197,28 +1197,7 @@ static const float f_min_window_height = 307.;
else
p_node = p_playlist->p_media_library;
- if ([[o_pasteboard types] containsObject: NSFilenamesPboardType]) {
- NSArray *o_values = [[o_pasteboard propertyListForType: NSFilenamesPboardType] sortedArrayUsingSelector: @selector(caseInsensitiveCompare:)];
- NSUInteger count = [o_values count];
- NSMutableArray *o_array = [NSMutableArray arrayWithCapacity:count];
-
- for(NSUInteger i = 0; i < count; i++) {
- NSDictionary *o_dic;
- char *psz_uri = vlc_path2uri([[o_values objectAtIndex:i] UTF8String], NULL);
- if (!psz_uri)
- continue;
-
- o_dic = [NSDictionary dictionaryWithObject:toNSStr(psz_uri) forKey:@"ITEM_URL"];
-
- free(psz_uri);
-
- [o_array addObject: o_dic];
- }
-
- [[[VLCMain sharedInstance] playlist] addPlaylistItems:o_array withParentItemId:p_node->i_id atPos:-1 startPlayback:NO];
- return YES;
- }
- else if ([[o_pasteboard types] containsObject: @"VLCPlaylistItemPboardType"]) {
+ if ([[o_pasteboard types] containsObject: @"VLCPlaylistItemPboardType"]) {
NSArray * array = [[[VLCMain sharedInstance] playlist] draggedItems];
NSUInteger count = [array count];
@@ -1233,7 +1212,17 @@ static const float f_min_window_height = 307.;
return YES;
}
- return NO;
+
+ // check if dropped item is a file
+ NSArray *items = [[[VLCMain sharedInstance] playlist] createItemsFromExternalPasteboard:o_pasteboard];
+ if (items.count == 0)
+ return NO;
+
+ [[[VLCMain sharedInstance] playlist] addPlaylistItems:items
+ withParentItemId:p_node->i_id
+ atPos:-1
+ startPlayback:NO];
+ return YES;
}
- (id)sourceList:(PXSourceList *)aSourceList persistentObjectForItem:(id)item
diff --git a/modules/gui/macosx/PLModel.m b/modules/gui/macosx/PLModel.m
index 57ea245..fddfd8a 100644
--- a/modules/gui/macosx/PLModel.m
+++ b/modules/gui/macosx/PLModel.m
@@ -733,42 +733,20 @@ static int VolumeUpdated(vlc_object_t *p_this, const char *psz_var,
return YES;
}
- else if ([[o_pasteboard types] containsObject: NSFilenamesPboardType]) {
+ // try file drop
- NSArray *o_values = [[o_pasteboard propertyListForType: NSFilenamesPboardType]
- sortedArrayUsingSelector: @selector(caseInsensitiveCompare:)];
- NSUInteger count = [o_values count];
- NSMutableArray *o_array = [NSMutableArray arrayWithCapacity:count];
- input_thread_t *p_input = playlist_CurrentInput(p_playlist);
-
- if (count == 1 && p_input) {
- int i_result = input_AddSubtitleOSD(p_input, vlc_path2uri([[o_values firstObject] UTF8String], NULL), true, true);
- vlc_object_release(p_input);
- if (i_result == VLC_SUCCESS)
- return YES;
- }
- else if (p_input)
- vlc_object_release(p_input);
+ // drop on a node itself will append entries at the end
+ static_assert(NSOutlineViewDropOnItemIndex == -1, "Expect NSOutlineViewDropOnItemIndex to be -1");
- for (NSUInteger i = 0; i < count; i++) {
- NSDictionary *o_dic;
- char *psz_uri = vlc_path2uri([[o_values objectAtIndex:i] UTF8String], NULL);
- if (!psz_uri)
- continue;
-
- o_dic = [NSDictionary dictionaryWithObject:toNSStr(psz_uri) forKey:@"ITEM_URL"];
- free(psz_uri);
-
- [o_array addObject: o_dic];
- }
+ NSArray *items = [[[VLCMain sharedInstance] playlist] createItemsFromExternalPasteboard:o_pasteboard];
+ if (items.count == 0)
+ return NO;
- // drop on a node itself will append entries at the end
- static_assert(NSOutlineViewDropOnItemIndex == -1, "Expect NSOutlineViewDropOnItemIndex to be -1");
-
- [_playlist addPlaylistItems:o_array withParentItemId:[targetItem plItemId] atPos:index startPlayback:NO];
- return YES;
- }
- return NO;
+ [[[VLCMain sharedInstance] playlist] addPlaylistItems:items
+ withParentItemId:[targetItem plItemId]
+ atPos:index
+ startPlayback:NO];
+ return YES;
}
@end
diff --git a/modules/gui/macosx/VLCPlaylist.h b/modules/gui/macosx/VLCPlaylist.h
index 937abb9..ebf259b 100644
--- a/modules/gui/macosx/VLCPlaylist.h
+++ b/modules/gui/macosx/VLCPlaylist.h
@@ -74,6 +74,14 @@
- (NSArray *)draggedItems;
/**
+ * Prepares an array of playlist items for all suitable pasteboard types.
+ *
+ * This function checks external pasteboard objects (like files). If suitable,
+ * an array of all objects is prepared.
+ */
+- (NSArray *)createItemsFromExternalPasteboard:(NSPasteboard *)pasteboard;
+
+/**
* Simplified version to add new items at the end of the current playlist
*/
- (void)addPlaylistItems:(NSArray*)o_array;
diff --git a/modules/gui/macosx/VLCPlaylist.m b/modules/gui/macosx/VLCPlaylist.m
index 3ab0add..7aab812 100644
--- a/modules/gui/macosx/VLCPlaylist.m
+++ b/modules/gui/macosx/VLCPlaylist.m
@@ -497,6 +497,30 @@
return p_input;
}
+- (NSArray *)createItemsFromExternalPasteboard:(NSPasteboard *)pasteboard
+{
+ NSArray *o_array = [NSArray array];
+ if (![[pasteboard types] containsObject: NSFilenamesPboardType])
+ return o_array;
+
+ NSArray *o_values = [[pasteboard propertyListForType: NSFilenamesPboardType] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
+ NSUInteger count = [o_values count];
+
+ for (NSUInteger i = 0; i < count; i++) {
+ NSDictionary *o_dic;
+ char *psz_uri = vlc_path2uri([[o_values objectAtIndex:i] UTF8String], NULL);
+ if (!psz_uri)
+ continue;
+
+ o_dic = [NSDictionary dictionaryWithObject:toNSStr(psz_uri) forKey:@"ITEM_URL"];
+ free(psz_uri);
+
+ o_array = [o_array arrayByAddingObject: o_dic];
+ }
+
+ return o_array;
+}
+
- (void)addPlaylistItems:(NSArray*)array
{
More information about the vlc-commits
mailing list