Commit 93023347 authored by David Fuhrmann's avatar David Fuhrmann

macosx: Factorize code for adding dropped file as subtitle

Adds dedicated method for trying to set the given file as subtitle.
Deduplicate code from three places.

Also removes superfluous add to recent media list.
parent de1327e2
......@@ -637,26 +637,7 @@ static int BossCallback(vlc_object_t *p_this, const char *psz_var,
if (items.count == 0)
return NO;
// Try to add file as a subtitle
input_thread_t *p_input = pl_CurrentInput(getIntf());
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);
return YES;
}
}
}
if (p_input)
vlc_object_release(p_input);
[[[VLCMain sharedInstance] playlist] addPlaylistItems:items];
[[[VLCMain sharedInstance] playlist] addPlaylistItems:items tryAsSubtitle:YES];
return YES;
}
......
......@@ -441,35 +441,19 @@ static VLCMain *sharedInstance = nil;
}
}
char *psz_uri = vlc_path2uri([[o_names firstObject] UTF8String], NULL);
// try to add file as subtitle
if ([o_names count] == 1 && psz_uri) {
input_thread_t * p_input = pl_CurrentInput(getIntf());
if (p_input) {
int i_result = input_AddSubtitleOSD(p_input, [[o_names firstObject] UTF8String], true, true);
vlc_object_release(p_input);
if (i_result == VLC_SUCCESS) {
free(psz_uri);
return;
}
}
}
free(psz_uri);
NSArray *o_sorted_names = [o_names sortedArrayUsingSelector: @selector(caseInsensitiveCompare:)];
NSMutableArray *o_result = [NSMutableArray arrayWithCapacity: [o_sorted_names count]];
for (NSUInteger i = 0; i < [o_sorted_names count]; i++) {
psz_uri = vlc_path2uri([[o_sorted_names objectAtIndex:i] UTF8String], "file");
char *psz_uri = vlc_path2uri([[o_sorted_names objectAtIndex:i] UTF8String], "file");
if (!psz_uri)
continue;
NSDictionary *o_dic = [NSDictionary dictionaryWithObject:toNSStr(psz_uri) forKey:@"ITEM_URL"];
free(psz_uri);
[o_result addObject: o_dic];
free(psz_uri);
}
[[[VLCMain sharedInstance] playlist] addPlaylistItems:o_result];
[[[VLCMain sharedInstance] playlist] addPlaylistItems:o_result tryAsSubtitle:YES];
}
/* When user click in the Dock icon our double click in the finder */
......
......@@ -83,9 +83,19 @@
/**
* Simplified version to add new items at the end of the current playlist
* @param o_array array of items. Each item is a Dictionary with meta info.
*/
- (void)addPlaylistItems:(NSArray*)o_array;
/**
* Add new items to playlist, with the possibility to check if an item can be added
* to the currently playing media as subtitle.
*
* @param array array of items. Each item is a Dictionary with meta info.
* @param isSubtitle if YES, method tries to add the item as a subtitle
*/
- (void)addPlaylistItems:(NSArray*)array tryAsSubtitle:(BOOL)isSubtitle;
/**
* Adds new items to the playlist, at specified parent node and index.
* @param o_array array of items. Each item is a Dictionary with meta info.
......
......@@ -665,6 +665,28 @@
[self addPlaylistItems:array withParentItemId:i_plItemId atPos:-1 startPlayback:b_autoplay];
}
- (void)addPlaylistItems:(NSArray*)array tryAsSubtitle:(BOOL)isSubtitle
{
input_thread_t *p_input = pl_CurrentInput(getIntf());
if (isSubtitle && array.count == 1 && p_input) {
char *path = vlc_uri2path([[[array firstObject] objectForKey:@"ITEM_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);
return;
}
}
}
if (p_input)
vlc_object_release(p_input);
[self addPlaylistItems:array];
}
- (void)addPlaylistItems:(NSArray*)array withParentItemId:(int)i_plItemId atPos:(int)i_position startPlayback:(BOOL)b_start
{
playlist_t * p_playlist = pl_Get(getIntf());
......
......@@ -42,26 +42,11 @@
if ([o_command isEqualToString:@"GetURL"] || [o_command isEqualToString:@"OpenURL"]) {
if (o_urlString) {
NSURL * o_url = [NSURL fileURLWithPath: o_urlString];
if (o_url != nil)
[[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL: o_url];
input_thread_t * p_input = pl_CurrentInput(getIntf());
BOOL b_returned = NO;
if (p_input) {
b_returned = input_AddSubtitle(p_input, [o_urlString UTF8String], true);
vlc_object_release(p_input);
if (!b_returned)
return nil;
}
NSDictionary *o_dic;
NSArray *o_array;
o_dic = [NSDictionary dictionaryWithObject:o_urlString forKey:@"ITEM_URL"];
o_array = [NSArray arrayWithObject: o_dic];
NSDictionary *o_dic = [NSDictionary dictionaryWithObject:o_urlString forKey:@"ITEM_URL"];
NSArray* item = [NSArray arrayWithObject:o_dic];
[[[VLCMain sharedInstance] playlist] addPlaylistItems:o_array];
[[[VLCMain sharedInstance] playlist] addPlaylistItems:item tryAsSubtitle:YES];
}
}
return nil;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment