Commit c6abf403 authored by David's avatar David
Browse files

macosx: simplify/unify addition of new playlist items

parent f24504e4
......@@ -568,7 +568,6 @@ static VLCCoreInteraction *_o_sharedInstance = nil;
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];
BOOL b_autoplay = config_GetInt(VLCIntf, "macosx-autoplay");
if (o_carried_data) {
if ([o_desired_type isEqualToString:NSFilenamesPboardType]) {
......@@ -598,11 +597,8 @@ static VLCCoreInteraction *_o_sharedInstance = nil;
o_array = [o_array arrayByAddingObject: o_dic];
}
if (b_autoplay)
[[[VLCMain sharedInstance] playlist] appendArray: o_array atPos: -1 enqueue:NO];
else
[[[VLCMain sharedInstance] playlist] appendArray: o_array atPos: -1 enqueue:YES];
[[[VLCMain sharedInstance] playlist] addPlaylistItems:o_array];
return YES;
}
}
......
......@@ -1196,9 +1196,9 @@ static VLCMainWindow *_o_sharedInstance = nil;
playlist_item_t *p_node;
if ([[item identifier] isEqualToString:@"playlist"])
p_node = p_playlist->p_local_category;
p_node = p_playlist->p_playing;
else
p_node = p_playlist->p_ml_category;
p_node = p_playlist->p_media_library;
if ([[o_pasteboard types] containsObject: NSFilenamesPboardType]) {
NSArray *o_values = [[o_pasteboard propertyListForType: NSFilenamesPboardType] sortedArrayUsingSelector: @selector(caseInsensitiveCompare:)];
......@@ -1218,7 +1218,7 @@ static VLCMainWindow *_o_sharedInstance = nil;
[o_array addObject: o_dic];
}
[[[VLCMain sharedInstance] playlist] appendNodeArray:o_array inNode: p_node atPos:-1 enqueue:YES];
[[[VLCMain sharedInstance] playlist] addPlaylistItems:o_array withParentItemId:p_node->i_id atPos:-1 startPlayback:NO];
return YES;
}
else if ([[o_pasteboard types] containsObject: @"VLCPlaylistItemPboardType"]) {
......
......@@ -21,9 +21,10 @@
#import "PLModel.h"
#import "misc.h"
#import "misc.h" /* VLCByteCountFormatter */
#import "playlist.h"
#import "StringUtility.h"
#include <vlc_playlist.h>
#include <vlc_input_item.h>
......@@ -447,14 +448,16 @@
{
NSPasteboard *o_pasteboard = [info draggingPasteboard];
// this is no valid target, sanitize to top of table
if (index == NSOutlineViewDropOnItemIndex)
index = 0;
if (targetItem == nil) {
targetItem = _rootItem;
}
/* Drag & Drop inside the playlist */
if ([[o_pasteboard types] containsObject:VLCPLItemPasteboadType]) {
if (index == -1) // this is no valid target, sanitize to top of table
index = 0;
if (targetItem == nil) {
targetItem = _rootItem;
}
NSMutableArray *o_filteredItems = [NSMutableArray arrayWithArray:_draggedItems];
const NSUInteger draggedItemsCount = [_draggedItems count];
......@@ -556,20 +559,13 @@
if (!psz_uri)
continue;
o_dic = [NSDictionary dictionaryWithObject:[NSString stringWithCString:psz_uri encoding:NSUTF8StringEncoding] forKey:@"ITEM_URL"];
o_dic = [NSDictionary dictionaryWithObject:toNSStr(psz_uri) forKey:@"ITEM_URL"];
free(psz_uri);
[o_array addObject: o_dic];
}
// if (item == nil)
[_playlist appendArray:o_array atPos:index enqueue: YES];
// TODO support for drop on sub nodes
// else {
// assert(p_node->i_children != -1);
// [_playlist appendNodeArray:o_array inNode: p_node atPos:index enqueue:YES];
// }
[_playlist addPlaylistItems:o_array withParentItemId:[targetItem plItemId] atPos:index startPlayback:NO];
return YES;
}
return NO;
......
......@@ -42,7 +42,6 @@
if ([o_command isEqualToString:@"GetURL"] || [o_command isEqualToString:@"OpenURL"]) {
if (o_urlString) {
BOOL b_autoplay = config_GetInt(VLCIntf, "macosx-autoplay");
NSURL * o_url = [NSURL fileURLWithPath: o_urlString];
if (o_url != nil)
[[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL: o_url];
......@@ -62,10 +61,7 @@
o_dic = [NSDictionary dictionaryWithObject:o_urlString forKey:@"ITEM_URL"];
o_array = [NSArray arrayWithObject: o_dic];
if (b_autoplay)
[[[VLCMain sharedInstance] playlist] appendArray: o_array atPos: -1 enqueue: NO];
else
[[[VLCMain sharedInstance] playlist] appendArray: o_array atPos: -1 enqueue: YES];
[[[VLCMain sharedInstance] playlist] addPlaylistItems:o_array];
}
}
return nil;
......
......@@ -1088,7 +1088,7 @@ static bool f_appExit = false;
[o_result addObject: o_dic];
}
[o_playlist appendArray: o_result atPos: -1 enqueue: !config_GetInt(VLCIntf, "macosx-autoplay")];
[[[VLCMain sharedInstance] playlist] addPlaylistItems:o_result];
}
/* When user click in the Dock icon our double click in the finder */
......
......@@ -419,8 +419,6 @@ static VLCOpen *_o_sharedMainInstance = nil;
int i_result;
b_autoplay = config_GetInt(VLCIntf, "macosx-autoplay");
[o_tabview selectTabViewItemAtIndex: i_type];
[o_file_sub_ckbox setState: NSOffState];
......@@ -516,10 +514,8 @@ static VLCOpen *_o_sharedMainInstance = nil;
/* apply the options to our item(s) */
[o_dic setObject: (NSArray *)[o_options copy] forKey: @"ITEM_OPTIONS"];
if (b_autoplay)
[[[VLCMain sharedInstance] playlist] appendArray: [NSArray arrayWithObject:o_dic] atPos: -1 enqueue:NO];
else
[[[VLCMain sharedInstance] playlist] appendArray: [NSArray arrayWithObject:o_dic] atPos: -1 enqueue:YES];
[[[VLCMain sharedInstance] playlist] addPlaylistItems:[NSArray arrayWithObject:o_dic]];
}
}
......@@ -657,7 +653,6 @@ static VLCOpen *_o_sharedMainInstance = nil;
- (void)openFile
{
NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
b_autoplay = config_GetInt(VLCIntf, "macosx-autoplay");
[o_open_panel setAllowsMultipleSelection: YES];
[o_open_panel setCanChooseDirectories: YES];
......@@ -685,10 +680,8 @@ static VLCOpen *_o_sharedMainInstance = nil;
[o_array addObject: o_dic];
}
if (b_autoplay)
[[[VLCMain sharedInstance] playlist] appendArray: o_array atPos: -1 enqueue:NO];
else
[[[VLCMain sharedInstance] playlist] appendArray: o_array atPos: -1 enqueue:YES];
[[[VLCMain sharedInstance] playlist] addPlaylistItems:o_array];
}
}
......
......@@ -127,8 +127,20 @@
- (id)playingItem;
- (NSArray *)draggedItems;
- (void)appendArray:(NSArray*)o_array atPos:(int)i_position enqueue:(BOOL)b_enqueue;
- (void)appendNodeArray:(NSArray*)o_array inNode:(playlist_item_t *)p_node atPos:(int)i_position enqueue:(BOOL)b_enqueue;
/**
* Simplified version to add new items at the end of the current playlist
*/
- (void)addPlaylistItems:(NSArray*)o_array;
/**
* 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.
* @param i_plItemId parent playlist node id, -1 for default playlist
* @param i_position index for new items, -1 for appending at end
* @param b_start starts playback of first item if true
*/
- (void)addPlaylistItems:(NSArray*)o_array withParentItemId:(int)i_plItemId atPos:(int)i_position startPlayback:(BOOL)b_start;
- (void)setColumn: (NSString *)o_column state: (NSInteger)i_state translationDict:(NSDictionary *)o_dict;
- (void)continuePlaybackWhereYouLeftOff:(input_thread_t *)p_input_thread;
......
......@@ -784,77 +784,60 @@
return p_input;
}
- (void)appendArray:(NSArray*)o_array atPos:(int)i_position enqueue:(BOOL)b_enqueue
- (void)addPlaylistItems:(NSArray*)o_array
{
playlist_t * p_playlist = pl_Get(VLCIntf);
NSUInteger count = [o_array count];
BOOL b_usingPlaylist = [[self model] currentRootType] == ROOT_TYPE_PLAYLIST;
PL_LOCK;
for (NSUInteger i_item = 0; i_item < count; i_item++) {
input_item_t *p_input;
NSDictionary *o_one_item;
int i_plItemId = -1;
/* Get the item */
o_one_item = [o_array objectAtIndex:i_item];
p_input = [self createItem: o_one_item];
if (!p_input)
continue;
// add items directly to media library if this is the current root
if ([[self model] currentRootType] == ROOT_TYPE_MEDIALIBRARY)
i_plItemId = [[[self model] rootItem] plItemId];
/* Add the item */
int returnValue = playlist_AddInput(p_playlist, p_input, PLAYLIST_INSERT, i_position == -1 ? PLAYLIST_END : i_position + i_item, b_usingPlaylist, pl_Locked);
if (returnValue != VLC_SUCCESS) {
vlc_gc_decref(p_input);
continue;
}
BOOL b_autoplay = var_InheritBool(VLCIntf, "macosx-autoplay");
if (i_item == 0 && !b_enqueue) {
playlist_item_t *p_item = playlist_ItemGetByInput(p_playlist, p_input);
playlist_Control(p_playlist, PLAYLIST_VIEWPLAY, pl_Locked, p_item->p_parent, p_item);
}
vlc_gc_decref(p_input);
}
PL_UNLOCK;
[self playlistUpdated];
[self addPlaylistItems:o_array withParentItemId:i_plItemId atPos:-1 startPlayback:b_autoplay];
}
- (void)appendNodeArray:(NSArray*)o_array inNode:(playlist_item_t *)p_node atPos:(int)i_position enqueue:(BOOL)b_enqueue
- (void)addPlaylistItems:(NSArray*)o_array withParentItemId:(int)i_plItemId atPos:(int)i_position startPlayback:(BOOL)b_start
{
playlist_t * p_playlist = pl_Get(VLCIntf);
NSUInteger count = [o_array count];
PL_LOCK;
for (NSUInteger i_item = 0; i_item < count; i_item++) {
input_item_t *p_input;
NSDictionary *o_one_item;
playlist_item_t *p_parent = NULL;
if (i_plItemId >= 0)
p_parent = playlist_ItemGetById(p_playlist, i_plItemId);
else
p_parent = p_playlist->p_playing;
/* Get the item */
PL_LOCK;
o_one_item = [o_array objectAtIndex:i_item];
p_input = [self createItem: o_one_item];
if (!p_parent) {
PL_UNLOCK;
return;
}
NSUInteger count = [o_array count];
int i_current_offset = 0;
for (NSUInteger i = 0; i < count; ++i) {
NSDictionary *o_current_item = [o_array objectAtIndex:i];
input_item_t *p_input = [self createItem: o_current_item];
if (!p_input)
continue;
/* Add the item */
playlist_NodeAddInput(p_playlist, p_input, p_node,
PLAYLIST_INSERT,
i_position == -1 ?
PLAYLIST_END : i_position + i_item,
pl_Locked);
int i_pos = (i_position == -1) ? PLAYLIST_END : i_position + i_current_offset++;
playlist_item_t *p_item = playlist_NodeAddInput(p_playlist, p_input, p_parent,
PLAYLIST_INSERT, i_pos, pl_Locked);
if (!p_item)
continue;
if (i_item == 0 && !b_enqueue) {
playlist_item_t *p_item;
p_item = playlist_ItemGetByInput(p_playlist, p_input);
playlist_Control(p_playlist, PLAYLIST_VIEWPLAY, pl_Locked, p_node, p_item);
if (i == 0 && b_start) {
playlist_Control(p_playlist, PLAYLIST_VIEWPLAY, pl_Locked, p_parent, p_item);
}
PL_UNLOCK;
vlc_gc_decref(p_input);
input_item_Release(p_input);
}
// [self playlistUpdated];
PL_UNLOCK;
}
- (IBAction)searchItem:(id)sender
{
[[self model] searchUpdate:[o_search_field stringValue]];
......
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