Commit b95be948 authored by Marvin Scholz's avatar Marvin Scholz

macosx: Refactor and update drag handling in ConvertAndSave Window

Fixes a crash when dragging a playlist item onto the drag and drop area
of the Convert an Save window, as it tried to access the no longer
present playlist item pointerValue.
Instead, the playlist item id has to be used to get the playlist item.

Additionally refactor the way too complex and hard to follow
draggedItems iteration code.
parent 82547ae9
......@@ -608,44 +608,49 @@
NSString *desired_type = [paste availableTypeFromArray: types];
NSData *carried_data = [paste dataForType: desired_type];
if (carried_data) {
if ([desired_type isEqualToString:NSFilenamesPboardType]) {
NSArray *values = [[paste propertyListForType: NSFilenamesPboardType] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
if ([values count] > 0) {
[self setMRL: toNSStr(vlc_path2uri([[values firstObject] UTF8String], NULL))];
[self updateOKButton];
[self updateDropView];
return YES;
}
} else if ([desired_type isEqualToString:@"VLCPlaylistItemPboardType"]) {
NSArray * array = [[[VLCMain sharedInstance] playlist] draggedItems];
NSUInteger count = [array count];
if (count > 0) {
playlist_t * p_playlist = pl_Get(getIntf());
playlist_item_t * p_item = NULL;
PL_LOCK;
/* let's look for the first proper input item */
for (NSUInteger x = 0; x < count; x++) {
p_item = [[array objectAtIndex:x] pointerValue];
if (p_item) {
if (p_item->p_input) {
if (p_item->p_input->psz_uri != nil) {
[self setMRL: toNSStr(p_item->p_input->psz_uri)];
[self updateDropView];
[self updateOKButton];
PL_UNLOCK;
return YES;
}
}
}
}
PL_UNLOCK;
if (carried_data == nil)
return NO;
if ([desired_type isEqualToString:NSFilenamesPboardType]) {
NSArray *values = [[paste propertyListForType: NSFilenamesPboardType] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
if ([values count] > 0) {
[self setMRL: toNSStr(vlc_path2uri([[values firstObject] UTF8String], NULL))];
[self updateOKButton];
[self updateDropView];
return YES;
}
} else if ([desired_type isEqualToString:@"VLCPlaylistItemPboardType"]) {
NSArray *draggedItems = [[[VLCMain sharedInstance] playlist] draggedItems];
// Return early to prevent unnecessary playlist access/locking
if ([draggedItems count] <= 0) {
return NO;
}
playlist_t *p_playlist = pl_Get(getIntf());
playlist_item_t *p_item = NULL;
PL_LOCK;
for (VLCPLItem *draggedItem in draggedItems) {
p_item = playlist_ItemGetById(p_playlist, [draggedItem plItemId]);
// Check if the item is usable
if (!p_item || !p_item->p_input || !p_item->p_input->psz_uri) {
// Item not usable, reset it.
p_item = NULL;
continue;
}
// First usable item found
[self setMRL: toNSStr(p_item->p_input->psz_uri)];
[self updateDropView];
[self updateOKButton];
break;
}
PL_UNLOCK;
return (p_item != NULL) ? YES : NO;
}
return NO;
}
......
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