1 /*****************************************************************************
2 * playlist.m: MacOS X interface module
3 *****************************************************************************
4 * Copyright (C) 2002-2012 VLC authors and VideoLAN
7 * Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
8 * Derk-Jan Hartman <hartman at videola/n dot org>
9 * Benjamin Pracht <bigben at videolab dot org>
10 * Felix Paul Kühne <fkuehne at videolan dot org>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25 *****************************************************************************/
28 * add 'icons' for different types of nodes? (http://www.cocoadev.com/index.pl?IconAndTextInTableCell)
29 * reimplement enable/disable item
33 /*****************************************************************************
35 *****************************************************************************/
36 #include <stdlib.h> /* malloc(), free() */
37 #include <sys/param.h> /* for MAXPATHLEN */
40 #include <sys/mount.h>
45 #import "playlistinfo.h"
54 #import <vlc_interface.h>
58 /*****************************************************************************
59 * VLCPlaylistView implementation
60 *****************************************************************************/
61 @implementation VLCPlaylistView
63 - (NSMenu *)menuForEvent:(NSEvent *)o_event
65 return([(VLCPlaylist *)[self delegate] menuForEvent: o_event]);
68 - (void)keyDown:(NSEvent *)o_event
72 if ([[o_event characters] length])
73 key = [[o_event characters] characterAtIndex: 0];
76 case NSDeleteCharacter:
77 case NSDeleteFunctionKey:
78 case NSDeleteCharFunctionKey:
79 case NSBackspaceCharacter:
80 [(VLCPlaylist *)[self delegate] deleteItem:self];
83 case NSEnterCharacter:
84 case NSCarriageReturnCharacter:
85 [(VLCPlaylist *)[[VLCMain sharedInstance] playlist] playItem:nil];
89 [super keyDown: o_event];
94 - (BOOL)validateMenuItem:(NSMenuItem *)item
96 if (([self numberOfSelectedRows] >= 1 && [item action] == @selector(delete:)) || [item action] == @selector(selectAll:))
102 - (BOOL) acceptsFirstResponder
107 - (BOOL) becomeFirstResponder
109 [self setNeedsDisplay:YES];
113 - (BOOL) resignFirstResponder
115 [self setNeedsDisplay:YES];
119 - (IBAction)delete:(id)sender
121 [[[VLCMain sharedInstance] playlist] deleteItem: sender];
126 /*****************************************************************************
127 * VLCPlaylistCommon implementation
129 * This class the superclass of the VLCPlaylist and VLCPlaylistWizard.
130 * It contains the common methods and elements of these 2 entities.
131 *****************************************************************************/
132 @implementation VLCPlaylistCommon
136 playlist_t * p_playlist = pl_Get(VLCIntf);
137 p_current_root_item = p_playlist->p_local_category;
141 o_outline_dict = [[NSMutableDictionary alloc] init];
148 playlist_t * p_playlist = pl_Get(VLCIntf);
149 [o_outline_view setTarget: self];
150 [o_outline_view setDelegate: self];
151 [o_outline_view setDataSource: self];
152 [o_outline_view setAllowsEmptySelection: NO];
153 [o_outline_view expandItem: [o_outline_view itemAtRow:0]];
155 [o_outline_view_other setTarget: self];
156 [o_outline_view_other setDelegate: self];
157 [o_outline_view_other setDataSource: self];
158 [o_outline_view_other setAllowsEmptySelection: NO];
160 [[o_tc_name_other headerCell] setStringValue:_NS("Name")];
161 [[o_tc_author_other headerCell] setStringValue:_NS("Author")];
162 [[o_tc_duration_other headerCell] setStringValue:_NS("Duration")];
165 - (void)setPlaylistRoot: (playlist_item_t *)root_item
167 p_current_root_item = root_item;
168 [o_outline_view reloadData];
169 [o_outline_view_other reloadData];
172 - (playlist_item_t *)currentPlaylistRoot
174 return p_current_root_item;
177 - (NSOutlineView *)outlineView
179 return o_outline_view;
182 - (playlist_item_t *)selectedPlaylistItem
184 return [[o_outline_view itemAtRow: [o_outline_view selectedRow]]
190 @implementation VLCPlaylistCommon (NSOutlineViewDataSource)
191 /* return the number of children for Obj-C pointer item */ /* DONE */
192 - (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
195 playlist_item_t *p_item = NULL;
196 playlist_t * p_playlist = pl_Get(VLCIntf);
197 //assert(outlineView == o_outline_view);
201 p_item = p_current_root_item;
203 p_item = (playlist_item_t *)[item pointerValue];
206 i_return = p_item->i_children;
209 return i_return > 0 ? i_return : 0;
212 /* return the child at index for the Obj-C pointer item */ /* DONE */
213 - (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item
215 playlist_item_t *p_return = NULL, *p_item = NULL;
217 playlist_t * p_playlist = pl_Get(VLCIntf);
221 p_item = p_current_root_item; /* root object */
223 p_item = (playlist_item_t *)[item pointerValue];
225 if (p_item && index < p_item->i_children && index >= 0)
226 p_return = p_item->pp_children[index];
229 o_value = [o_outline_dict objectForKey:[NSString stringWithFormat: @"%p", p_return]];
231 if (o_value == nil) {
232 /* FIXME: Why is there a warning if that happens all the time and seems
233 * to be normal? Add an assert and fix it.
234 * msg_Warn(VLCIntf, "playlist item misses pointer value, adding one"); */
235 o_value = [[NSValue valueWithPointer: p_return] retain];
240 /* is the item expandable */
241 - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item
244 playlist_t *p_playlist = pl_Get(VLCIntf);
249 if (p_current_root_item) {
250 i_return = p_current_root_item->i_children;
253 playlist_item_t *p_item = (playlist_item_t *)[item pointerValue];
255 i_return = p_item->i_children;
259 return (i_return >= 0);
262 /* retrieve the string values for the cells */
263 - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)o_tc byItem:(id)item
267 playlist_item_t *p_item;
269 /* For error handling */
270 static BOOL attempted_reload = NO;
272 if (item == nil || ![item isKindOfClass: [NSValue class]]) {
273 /* Attempt to fix the error by asking for a data redisplay
274 * This might cause infinite loop, so add a small check */
275 if (!attempted_reload) {
276 attempted_reload = YES;
277 [outlineView reloadData];
282 p_item = (playlist_item_t *)[item pointerValue];
283 if (!p_item || !p_item->p_input) {
284 /* Attempt to fix the error by asking for a data redisplay
285 * This might cause infinite loop, so add a small check */
286 if (!attempted_reload) {
287 attempted_reload = YES;
288 [outlineView reloadData];
293 attempted_reload = NO;
294 NSString * o_identifier = [o_tc identifier];
296 if ([o_identifier isEqualToString:TRACKNUM_COLUMN]) {
297 psz_value = input_item_GetTrackNumber(p_item->p_input);
299 o_value = [NSString stringWithUTF8String: psz_value];
302 } else if ([o_identifier isEqualToString:TITLE_COLUMN]) {
303 /* sanity check to prevent the NSString class from crashing */
304 char *psz_title = input_item_GetTitleFbName(p_item->p_input);
306 o_value = [NSString stringWithUTF8String: psz_title];
309 } else if ([o_identifier isEqualToString:ARTIST_COLUMN]) {
310 psz_value = input_item_GetArtist(p_item->p_input);
312 o_value = [NSString stringWithUTF8String: psz_value];
315 } else if ([o_identifier isEqualToString:@"duration"]) {
316 char psz_duration[MSTRTIME_MAX_SIZE];
317 mtime_t dur = input_item_GetDuration(p_item->p_input);
319 secstotimestr(psz_duration, dur/1000000);
320 o_value = [NSString stringWithUTF8String: psz_duration];
324 } else if ([o_identifier isEqualToString:GENRE_COLUMN]) {
325 psz_value = input_item_GetGenre(p_item->p_input);
327 o_value = [NSString stringWithUTF8String: psz_value];
330 } else if ([o_identifier isEqualToString:ALBUM_COLUMN]) {
331 psz_value = input_item_GetAlbum(p_item->p_input);
333 o_value = [NSString stringWithUTF8String: psz_value];
336 } else if ([o_identifier isEqualToString:DESCRIPTION_COLUMN]) {
337 psz_value = input_item_GetDescription(p_item->p_input);
339 o_value = [NSString stringWithUTF8String: psz_value];
342 } else if ([o_identifier isEqualToString:DATE_COLUMN]) {
343 psz_value = input_item_GetDate(p_item->p_input);
345 o_value = [NSString stringWithUTF8String: psz_value];
348 } else if ([o_identifier isEqualToString:LANGUAGE_COLUMN]) {
349 psz_value = input_item_GetLanguage(p_item->p_input);
351 o_value = [NSString stringWithUTF8String: psz_value];
355 else if ([o_identifier isEqualToString:URI_COLUMN]) {
356 psz_value = decode_URI(input_item_GetURI(p_item->p_input));
358 o_value = [NSString stringWithUTF8String: psz_value];
362 else if ([o_identifier isEqualToString:@"status"]) {
363 if (input_item_HasErrorWhenReading(p_item->p_input)) {
364 o_value = [[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode(kAlertCautionIcon)];
365 [o_value setSize: NSMakeSize(16,16)];
374 /*****************************************************************************
375 * VLCPlaylistWizard implementation
376 *****************************************************************************/
377 @implementation VLCPlaylistWizard
379 - (IBAction)reloadOutlineView
381 /* Only reload the outlineview if the wizard window is open since this can
382 be quite long on big playlists */
383 if ([[o_outline_view window] isVisible])
384 [o_outline_view reloadData];
389 /*****************************************************************************
390 * An extension to NSOutlineView's interface to fix compilation warnings
391 * and let us access these 2 functions properly.
392 * This uses a private API, but works fine on all current OSX releases.
393 * Radar ID 11739459 request a public API for this. However, it is probably
394 * easier and faster to recreate similar looking bitmaps ourselves.
395 *****************************************************************************/
397 @interface NSOutlineView (UndocumentedSortImages)
398 + (NSImage *)_defaultTableHeaderSortImage;
399 + (NSImage *)_defaultTableHeaderReverseSortImage;
403 /*****************************************************************************
404 * VLCPlaylist implementation
405 *****************************************************************************/
406 @interface VLCPlaylist (Internal)
407 - (void)saveTableColumns;
410 @implementation VLCPlaylist
413 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
414 NSMutableArray * o_columnArray = [[NSMutableArray alloc] init];
415 [o_columnArray addObject: [NSArray arrayWithObjects: TITLE_COLUMN, [NSNumber numberWithFloat: 190.], nil]];
416 [o_columnArray addObject: [NSArray arrayWithObjects: ARTIST_COLUMN, [NSNumber numberWithFloat: 95.], nil]];
417 [o_columnArray addObject: [NSArray arrayWithObjects: DURATION_COLUMN, [NSNumber numberWithFloat: 95.], nil]];
418 NSDictionary *appDefaults = [NSDictionary dictionaryWithObject:[NSArray arrayWithArray:o_columnArray] forKey:@"PlaylistColumnSelection"];
420 [defaults registerDefaults:appDefaults];
421 [o_columnArray release];
428 o_nodes_array = [[NSMutableArray alloc] init];
429 o_items_array = [[NSMutableArray alloc] init];
436 [o_nodes_array release];
437 [o_items_array release];
443 playlist_t * p_playlist = pl_Get(VLCIntf);
445 [super awakeFromNib];
447 [o_outline_view setDoubleAction: @selector(playItem:)];
448 [o_outline_view_other setDoubleAction: @selector(playItem:)];
450 [o_outline_view registerForDraggedTypes:
451 [NSArray arrayWithObjects: NSFilenamesPboardType,
452 @"VLCPlaylistItemPboardType", nil]];
453 [o_outline_view setIntercellSpacing: NSMakeSize (0.0, 1.0)];
455 [o_outline_view_other registerForDraggedTypes:
456 [NSArray arrayWithObjects: NSFilenamesPboardType,
457 @"VLCPlaylistItemPboardType", nil]];
458 [o_outline_view_other setIntercellSpacing: NSMakeSize (0.0, 1.0)];
460 /* This uses a private API, but works fine on all current OSX releases.
461 * Radar ID 11739459 request a public API for this. However, it is probably
462 * easier and faster to recreate similar looking bitmaps ourselves. */
463 o_ascendingSortingImage = [[NSOutlineView class] _defaultTableHeaderSortImage];
464 o_descendingSortingImage = [[NSOutlineView class] _defaultTableHeaderReverseSortImage];
466 o_tc_sortColumn = nil;
468 NSArray * o_columnArray = [[NSUserDefaults standardUserDefaults] arrayForKey:@"PlaylistColumnSelection"];
469 NSUInteger count = [o_columnArray count];
471 id o_menu = [[VLCMain sharedInstance] mainMenu];
474 NSMenu *o_context_menu = [o_menu setupPlaylistTableColumnsMenu];
475 [o_playlist_header setMenu: o_context_menu];
477 for (NSUInteger i = 0; i < count; i++) {
478 o_column = [[o_columnArray objectAtIndex:i] objectAtIndex:0];
479 if ([o_column isEqualToString:@"status"])
482 [o_menu setPlaylistColumnTableState: NSOnState forColumn: o_column];
483 [[o_outline_view tableColumnWithIdentifier: o_column] setWidth: [[[o_columnArray objectAtIndex:i] objectAtIndex:1] floatValue]];
486 [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(applicationWillTerminate:) name: NSApplicationWillTerminateNotification object: nil];
489 - (void)applicationWillTerminate:(NSNotification *)notification
491 /* let's make sure we save the correct widths and positions, since this likely changed since the last time the user played with the column selection */
492 [self saveTableColumns];
495 - (void)searchfieldChanged:(NSNotification *)o_notification
497 [o_search_field setStringValue:[[o_notification object] stringValue]];
502 [o_mi_save_playlist setTitle: _NS("Save Playlist...")];
503 [o_mi_play setTitle: _NS("Play")];
504 [o_mi_delete setTitle: _NS("Delete")];
505 [o_mi_recursive_expand setTitle: _NS("Expand Node")];
506 [o_mi_selectall setTitle: _NS("Select All")];
507 [o_mi_info setTitle: _NS("Media Information...")];
508 [o_mi_dl_cover_art setTitle: _NS("Download Cover Art")];
509 [o_mi_preparse setTitle: _NS("Fetch Meta Data")];
510 [o_mi_revealInFinder setTitle: _NS("Reveal in Finder")];
511 [o_mm_mi_revealInFinder setTitle: _NS("Reveal in Finder")];
512 [[o_mm_mi_revealInFinder menu] setAutoenablesItems: NO];
513 [o_mi_sort_name setTitle: _NS("Sort Node by Name")];
514 [o_mi_sort_author setTitle: _NS("Sort Node by Author")];
516 [o_search_field setToolTip: _NS("Search in Playlist")];
517 [o_search_field_other setToolTip: _NS("Search in Playlist")];
519 [o_save_accessory_text setStringValue: _NS("File Format:")];
520 [[o_save_accessory_popup itemAtIndex:0] setTitle: _NS("Extended M3U")];
521 [[o_save_accessory_popup itemAtIndex:1] setTitle: _NS("XML Shareable Playlist Format (XSPF)")];
522 [[o_save_accessory_popup itemAtIndex:2] setTitle: _NS("HTML Playlist")];
525 - (void)playlistUpdated
527 /* Clear indications of any existing column sorting */
528 NSUInteger count = [[o_outline_view tableColumns] count];
529 for (NSUInteger i = 0 ; i < count ; i++)
530 [o_outline_view setIndicatorImage:nil inTableColumn: [[o_outline_view tableColumns] objectAtIndex:i]];
532 [o_outline_view setHighlightedTableColumn:nil];
533 o_tc_sortColumn = nil;
534 // TODO Find a way to keep the dict size to a minimum
535 //[o_outline_dict removeAllObjects];
536 [o_outline_view reloadData];
537 [[[[VLCMain sharedInstance] wizard] playlistWizard] reloadOutlineView];
538 [[[[VLCMain sharedInstance] bookmarks] dataTable] reloadData];
540 [self outlineViewSelectionDidChange: nil];
541 [[VLCMain sharedInstance] updateMainWindow];
544 - (void)outlineViewSelectionDidChange:(NSNotification *)notification
547 playlist_item_t * p_item = [[o_outline_view itemAtRow:[o_outline_view selectedRow]] pointerValue];
550 /* update the state of our Reveal-in-Finder menu items */
551 NSMutableString *o_mrl;
552 char *psz_uri = input_item_GetURI(p_item->p_input);
554 [o_mi_revealInFinder setEnabled: NO];
555 [o_mm_mi_revealInFinder setEnabled: NO];
557 o_mrl = [NSMutableString stringWithUTF8String: psz_uri];
559 /* perform some checks whether it is a file and if it is local at all... */
560 NSRange prefix_range = [o_mrl rangeOfString: @"file:"];
561 if (prefix_range.location != NSNotFound)
562 [o_mrl deleteCharactersInRange: prefix_range];
564 if ([o_mrl characterAtIndex:0] == '/') {
565 [o_mi_revealInFinder setEnabled: YES];
566 [o_mm_mi_revealInFinder setEnabled: YES];
571 /* update our info-panel to reflect the new item */
572 [[[VLCMain sharedInstance] info] updatePanelWithItem:p_item->p_input];
576 - (BOOL)isSelectionEmpty
578 return [o_outline_view selectedRow] == -1;
581 - (void)updateRowSelection
584 playlist_t *p_playlist = pl_Get(VLCIntf);
585 playlist_item_t *p_item, *p_temp_item;
586 NSMutableArray *o_array = [NSMutableArray array];
589 p_item = playlist_CurrentPlayingItem(p_playlist);
590 if (p_item == NULL) {
595 p_temp_item = p_item;
596 while(p_temp_item->p_parent) {
597 [o_array insertObject: [NSValue valueWithPointer: p_temp_item] atIndex: 0];
598 p_temp_item = p_temp_item->p_parent;
602 NSUInteger count = [o_array count];
603 for (NSUInteger j = 0; j < count - 1; j++) {
605 if ((o_item = [o_outline_dict objectForKey:
606 [NSString stringWithFormat: @"%p",
607 [[o_array objectAtIndex:j] pointerValue]]]) != nil) {
608 [o_outline_view expandItem: o_item];
612 id o_item = [o_outline_dict objectForKey:[NSString stringWithFormat: @"%p", p_item]];
613 NSInteger i_index = [o_outline_view rowForItem:o_item];
614 [o_outline_view selectRowIndexes:[NSIndexSet indexSetWithIndex:i_index] byExtendingSelection:NO];
615 [o_outline_view setNeedsDisplay:YES];
618 /* Check if p_item is a child of p_node recursively. We need to check the item
619 existence first since OSX sometimes tries to redraw items that have been
620 deleted. We don't do it when not required since this verification takes
621 quite a long time on big playlists (yes, pretty hacky). */
623 - (BOOL)isItem: (playlist_item_t *)p_item inNode: (playlist_item_t *)p_node checkItemExistence:(BOOL)b_check locked:(BOOL)b_locked
625 playlist_t * p_playlist = pl_Get(VLCIntf);
626 playlist_item_t *p_temp_item = p_item;
631 if (p_node == p_item)
634 if (p_node->i_children < 1)
639 if (!b_locked) PL_LOCK;
642 /* Since outlineView: willDisplayCell:... may call this function with
643 p_items that don't exist anymore, first check if the item is still
644 in the playlist. Any cleaner solution welcomed. */
645 for (i = 0; i < p_playlist->all_items.i_size; i++) {
646 if (ARRAY_VAL(p_playlist->all_items, i) == p_item)
648 else if (i == p_playlist->all_items.i_size - 1)
650 if (!b_locked) PL_UNLOCK;
657 p_temp_item = p_temp_item->p_parent;
658 if (p_temp_item == p_node) {
659 if (!b_locked) PL_UNLOCK;
663 if (!b_locked) PL_UNLOCK;
668 /* This method is useful for instance to remove the selected children of an
669 already selected node */
670 - (void)removeItemsFrom:(id)o_items ifChildrenOf:(id)o_nodes
672 NSUInteger itemCount = [o_items count];
673 NSUInteger nodeCount = [o_nodes count];
674 for (NSUInteger i = 0 ; i < itemCount ; i++) {
675 for (NSUInteger j = 0 ; j < nodeCount ; j++) {
676 if (o_items == o_nodes) {
677 if (j == i) continue;
679 if ([self isItem: [[o_items objectAtIndex:i] pointerValue]
680 inNode: [[o_nodes objectAtIndex:j] pointerValue]
681 checkItemExistence: NO locked:NO]) {
682 [o_items removeObjectAtIndex:i];
683 /* We need to execute the next iteration with the same index
684 since the current item has been deleted */
692 - (IBAction)savePlaylist:(id)sender
694 playlist_t * p_playlist = pl_Get(VLCIntf);
696 NSSavePanel *o_save_panel = [NSSavePanel savePanel];
697 NSString * o_name = [NSString stringWithFormat: @"%@", _NS("Untitled")];
699 [o_save_panel setTitle: _NS("Save Playlist")];
700 [o_save_panel setPrompt: _NS("Save")];
701 [o_save_panel setAccessoryView: o_save_accessory_view];
702 [o_save_panel setNameFieldStringValue: o_name];
704 if ([o_save_panel runModal] == NSFileHandlingPanelOKButton) {
705 NSString *o_filename = [[o_save_panel URL] path];
707 if ([o_save_accessory_popup indexOfSelectedItem] == 0) {
708 NSString * o_real_filename;
710 range.location = [o_filename length] - [@".m3u" length];
711 range.length = [@".m3u" length];
713 if ([o_filename compare:@".m3u" options: NSCaseInsensitiveSearch range: range] != NSOrderedSame)
714 o_real_filename = [NSString stringWithFormat: @"%@.m3u", o_filename];
716 o_real_filename = o_filename;
718 playlist_Export(p_playlist,
719 [o_real_filename fileSystemRepresentation],
720 p_playlist->p_local_category, "export-m3u");
721 } else if ([o_save_accessory_popup indexOfSelectedItem] == 1) {
722 NSString * o_real_filename;
724 range.location = [o_filename length] - [@".xspf" length];
725 range.length = [@".xspf" length];
727 if ([o_filename compare:@".xspf" options: NSCaseInsensitiveSearch range: range] != NSOrderedSame)
728 o_real_filename = [NSString stringWithFormat: @"%@.xspf", o_filename];
730 o_real_filename = o_filename;
732 playlist_Export(p_playlist,
733 [o_real_filename fileSystemRepresentation],
734 p_playlist->p_local_category, "export-xspf");
736 NSString * o_real_filename;
738 range.location = [o_filename length] - [@".html" length];
739 range.length = [@".html" length];
741 if ([o_filename compare:@".html" options: NSCaseInsensitiveSearch range: range] != NSOrderedSame)
742 o_real_filename = [NSString stringWithFormat: @"%@.html", o_filename];
744 o_real_filename = o_filename;
746 playlist_Export(p_playlist,
747 [o_real_filename fileSystemRepresentation],
748 p_playlist->p_local_category, "export-html");
753 /* When called retrieves the selected outlineview row and plays that node or item */
754 - (IBAction)playItem:(id)sender
756 intf_thread_t * p_intf = VLCIntf;
757 playlist_t * p_playlist = pl_Get(p_intf);
759 playlist_item_t *p_item;
760 playlist_item_t *p_node = NULL;
762 // ignore clicks on column header when handling double action
763 if (sender != nil && [o_outline_view clickedRow] == -1 && sender != o_mi_play)
766 p_item = [[o_outline_view itemAtRow:[o_outline_view selectedRow]] pointerValue];
770 if (p_item->i_children == -1) {
771 p_node = p_item->p_parent;
774 if (p_node->i_children > 0 && p_node->pp_children[0]->i_children == -1)
775 p_item = p_node->pp_children[0];
779 playlist_Control(p_playlist, PLAYLIST_VIEWPLAY, pl_Locked, p_node, p_item);
784 - (IBAction)revealItemInFinder:(id)sender
786 NSIndexSet * selectedRows = [o_outline_view selectedRowIndexes];
787 NSUInteger count = [selectedRows count];
788 NSUInteger indexes[count];
789 [selectedRows getIndexes:indexes maxCount:count inIndexRange:nil];
791 NSMutableString * o_mrl;
792 playlist_item_t *p_item;
793 for (NSUInteger i = 0; i < count; i++) {
794 p_item = [[o_outline_view itemAtRow:indexes[i]] pointerValue];
796 if (! p_item || !p_item->p_input)
799 char * psz_url = decode_URI(input_item_GetURI(p_item->p_input));
800 o_mrl = [[NSMutableString alloc] initWithString: [NSString stringWithUTF8String: psz_url ? psz_url : ""]];
804 /* perform some checks whether it is a file and if it is local at all... */
805 if ([o_mrl length] > 0) {
806 NSRange prefix_range = [o_mrl rangeOfString: @"file:"];
807 if (prefix_range.location != NSNotFound)
808 [o_mrl deleteCharactersInRange: prefix_range];
810 if ([o_mrl characterAtIndex:0] == '/')
811 [[NSWorkspace sharedWorkspace] selectFile: o_mrl inFileViewerRootedAtPath: o_mrl];
818 /* When called retrieves the selected outlineview row and plays that node or item */
819 - (IBAction)preparseItem:(id)sender
822 NSIndexSet *o_selected_indexes;
823 intf_thread_t * p_intf = VLCIntf;
824 playlist_t * p_playlist = pl_Get(p_intf);
825 playlist_item_t *p_item = NULL;
827 o_selected_indexes = [o_outline_view selectedRowIndexes];
828 i_count = [o_selected_indexes count];
830 NSUInteger indexes[i_count];
831 [o_selected_indexes getIndexes:indexes maxCount:i_count inIndexRange:nil];
832 for (int i = 0; i < i_count; i++) {
833 p_item = [[o_outline_view itemAtRow:indexes[i]] pointerValue];
834 [o_outline_view deselectRow: indexes[i]];
837 if (p_item->i_children == -1)
838 playlist_PreparseEnqueue(p_playlist, p_item->p_input);
840 msg_Dbg(p_intf, "preparsing nodes not implemented");
843 [self playlistUpdated];
846 - (IBAction)downloadCoverArt:(id)sender
849 NSIndexSet *o_selected_indexes;
850 intf_thread_t * p_intf = VLCIntf;
851 playlist_t * p_playlist = pl_Get(p_intf);
852 playlist_item_t *p_item = NULL;
854 o_selected_indexes = [o_outline_view selectedRowIndexes];
855 i_count = [o_selected_indexes count];
857 NSUInteger indexes[i_count];
858 [o_selected_indexes getIndexes:indexes maxCount:i_count inIndexRange:nil];
859 for (int i = 0; i < i_count; i++) {
860 p_item = [[o_outline_view itemAtRow: indexes[i]] pointerValue];
862 if (p_item && p_item->i_children == -1)
863 playlist_AskForArtEnqueue(p_playlist, p_item->p_input);
865 [self playlistUpdated];
868 - (IBAction)selectAll:(id)sender
870 [o_outline_view selectAll: nil];
873 - (IBAction)deleteItem:(id)sender
876 NSIndexSet *o_selected_indexes;
877 playlist_t * p_playlist;
878 intf_thread_t * p_intf = VLCIntf;
880 o_selected_indexes = [o_outline_view selectedRowIndexes];
881 i_count = [o_selected_indexes count];
883 p_playlist = pl_Get(p_intf);
885 NSUInteger indexes[i_count];
886 if (i_count == [o_outline_view numberOfRows]) {
888 msg_Dbg(p_intf, "user selected entire list, deleting current playlist root instead of individual items");
891 playlist_NodeDelete(p_playlist, [self currentPlaylistRoot], true, false);
893 [self playlistUpdated];
896 [o_selected_indexes getIndexes:indexes maxCount:i_count inIndexRange:nil];
897 for (int i = 0; i < i_count; i++) {
898 id o_item = [o_outline_view itemAtRow: indexes[i]];
899 [o_outline_view deselectRow: indexes[i]];
902 playlist_item_t *p_item = [o_item pointerValue];
903 if (!p_item || !p_item->p_input) {
908 msg_Dbg(p_intf, "deleting item %i (of %i) with id \"%i\", pointerValue \"%p\" and %i children", i+1, i_count,
909 p_item->p_input->i_id, [o_item pointerValue], p_item->i_children +1);
912 if (p_item->i_children != -1) {
913 //is a node and not an item
914 if (playlist_Status(p_playlist) != PLAYLIST_STOPPED &&
915 [self isItem: playlist_CurrentPlayingItem(p_playlist) inNode: ((playlist_item_t *)[o_item pointerValue])
916 checkItemExistence: NO locked:YES] == YES)
917 // if current item is in selected node and is playing then stop playlist
918 playlist_Control(p_playlist, PLAYLIST_STOP, pl_Locked);
920 playlist_NodeDelete(p_playlist, p_item, true, false);
922 playlist_DeleteFromInput(p_playlist, p_item->p_input, pl_Locked);
925 [o_outline_dict removeObjectForKey:[NSString stringWithFormat:@"%p", [o_item pointerValue]]];
929 [self playlistUpdated];
932 - (IBAction)sortNodeByName:(id)sender
934 [self sortNode: SORT_TITLE];
937 - (IBAction)sortNodeByAuthor:(id)sender
939 [self sortNode: SORT_ARTIST];
942 - (void)sortNode:(int)i_mode
944 playlist_t * p_playlist = pl_Get(VLCIntf);
945 playlist_item_t * p_item;
947 if ([o_outline_view selectedRow] > -1) {
948 p_item = [[o_outline_view itemAtRow: [o_outline_view selectedRow]] pointerValue];
952 p_item = [self currentPlaylistRoot]; // If no item is selected, sort the whole playlist
955 if (p_item->i_children > -1) // the item is a node
956 playlist_RecursiveNodeSort(p_playlist, p_item, i_mode, ORDER_NORMAL);
958 playlist_RecursiveNodeSort(p_playlist, p_item->p_parent, i_mode, ORDER_NORMAL);
961 [self playlistUpdated];
964 - (input_item_t *)createItem:(NSDictionary *)o_one_item
966 intf_thread_t * p_intf = VLCIntf;
967 playlist_t * p_playlist = pl_Get(p_intf);
969 input_item_t *p_input;
970 BOOL b_rem = FALSE, b_dir = FALSE, b_writable = FALSE;
971 NSString *o_uri, *o_name, *o_path;
977 o_uri = (NSString *)[o_one_item objectForKey: @"ITEM_URL"];
978 o_nsurl = [NSURL URLWithString: o_uri];
979 o_path = [o_nsurl path];
980 o_name = (NSString *)[o_one_item objectForKey: @"ITEM_NAME"];
981 o_options = (NSArray *)[o_one_item objectForKey: @"ITEM_OPTIONS"];
983 if ([[NSFileManager defaultManager] fileExistsAtPath:o_path isDirectory:&b_dir] && b_dir &&
984 [[NSWorkspace sharedWorkspace] getFileSystemInfoForPath:o_path isRemovable: &b_rem
985 isWritable:&b_writable isUnmountable:NULL description:NULL type:NULL] && b_rem && !b_writable && [o_nsurl isFileURL]) {
986 id o_vlc_open = [[VLCMain sharedInstance] open];
988 NSString *diskType = [o_vlc_open getVolumeTypeFromMountPath: o_path];
989 msg_Dbg(p_intf, "detected optical media of type %s in the file input", [diskType UTF8String]);
991 if ([diskType isEqualToString: kVLCMediaDVD])
992 o_uri = [NSString stringWithFormat: @"dvdnav://%@", [o_vlc_open getBSDNodeFromMountPath: o_path]];
993 else if ([diskType isEqualToString: kVLCMediaVideoTSFolder])
994 o_uri = [NSString stringWithFormat: @"dvdnav://%@", o_path];
995 else if ([diskType isEqualToString: kVLCMediaAudioCD])
996 o_uri = [NSString stringWithFormat: @"cdda://%@", [o_vlc_open getBSDNodeFromMountPath: o_path]];
997 else if ([diskType isEqualToString: kVLCMediaVCD])
998 o_uri = [NSString stringWithFormat: @"vcd://%@#0:0", [o_vlc_open getBSDNodeFromMountPath: o_path]];
999 else if ([diskType isEqualToString: kVLCMediaSVCD])
1000 o_uri = [NSString stringWithFormat: @"vcd://%@@0:0", [o_vlc_open getBSDNodeFromMountPath: o_path]];
1001 else if ([diskType isEqualToString: kVLCMediaBD] || [diskType isEqualToString: kVLCMediaBDMVFolder])
1002 o_uri = [NSString stringWithFormat: @"bluray://%@", o_path];
1004 msg_Warn(VLCIntf, "unknown disk type, treating %s as regular input", [o_path UTF8String]);
1006 p_input = input_item_New([o_uri UTF8String], [[[NSFileManager defaultManager] displayNameAtPath: o_path] UTF8String]);
1009 p_input = input_item_New([o_uri fileSystemRepresentation], o_name ? [o_name UTF8String] : NULL);
1015 NSUInteger count = [o_options count];
1016 for (NSUInteger i = 0; i < count; i++)
1017 input_item_AddOption(p_input, [[o_options objectAtIndex:i] UTF8String], VLC_INPUT_OPTION_TRUSTED);
1020 /* Recent documents menu */
1021 if (o_nsurl != nil && (BOOL)config_GetInt(p_playlist, "macosx-recentitems") == YES)
1022 [[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL: o_nsurl];
1027 - (void)appendArray:(NSArray*)o_array atPos:(int)i_position enqueue:(BOOL)b_enqueue
1029 playlist_t * p_playlist = pl_Get(VLCIntf);
1030 NSUInteger count = [o_array count];
1031 BOOL b_usingPlaylist;
1032 if ([self currentPlaylistRoot] == p_playlist->p_ml_category)
1033 b_usingPlaylist = NO;
1035 b_usingPlaylist = YES;
1038 for (NSUInteger i_item = 0; i_item < count; i_item++) {
1039 input_item_t *p_input;
1040 NSDictionary *o_one_item;
1043 o_one_item = [o_array objectAtIndex: i_item];
1044 p_input = [self createItem: o_one_item];
1049 int returnValue = playlist_AddInput(p_playlist, p_input, PLAYLIST_INSERT, i_position == -1 ? PLAYLIST_END : i_position + i_item, b_usingPlaylist, pl_Locked);
1050 if (returnValue != VLC_SUCCESS) {
1051 vlc_gc_decref(p_input);
1055 if (i_item == 0 && !b_enqueue) {
1056 playlist_item_t *p_item = playlist_ItemGetByInput(p_playlist, p_input);
1057 playlist_Control(p_playlist, PLAYLIST_VIEWPLAY, pl_Locked, p_item->p_parent, p_item);
1060 vlc_gc_decref(p_input);
1063 [self playlistUpdated];
1066 - (void)appendNodeArray:(NSArray*)o_array inNode:(playlist_item_t *)p_node atPos:(int)i_position enqueue:(BOOL)b_enqueue
1068 playlist_t * p_playlist = pl_Get(VLCIntf);
1069 NSUInteger count = [o_array count];
1071 for (NSUInteger i_item = 0; i_item < count; i_item++) {
1072 input_item_t *p_input;
1073 NSDictionary *o_one_item;
1076 o_one_item = [o_array objectAtIndex: i_item];
1077 p_input = [self createItem: o_one_item];
1084 playlist_NodeAddInput(p_playlist, p_input, p_node,
1087 PLAYLIST_END : i_position + i_item,
1091 if (i_item == 0 && !b_enqueue) {
1092 playlist_item_t *p_item;
1093 p_item = playlist_ItemGetByInput(p_playlist, p_input);
1094 playlist_Control(p_playlist, PLAYLIST_VIEWPLAY, pl_Locked, p_node, p_item);
1097 vlc_gc_decref(p_input);
1099 [self playlistUpdated];
1102 - (NSMutableArray *)subSearchItem:(playlist_item_t *)p_item
1104 playlist_t *p_playlist = pl_Get(VLCIntf);
1105 playlist_item_t *p_selected_item;
1108 i_selected_row = [o_outline_view selectedRow];
1109 if (i_selected_row < 0)
1112 p_selected_item = (playlist_item_t *)[[o_outline_view itemAtRow: i_selected_row] pointerValue];
1114 for (NSUInteger i_current = 0; i_current < p_item->i_children ; i_current++) {
1116 NSString *o_current_name, *o_current_author;
1119 o_current_name = [NSString stringWithUTF8String:
1120 p_item->pp_children[i_current]->p_input->psz_name];
1121 psz_temp = input_item_GetInfo(p_item->p_input ,
1122 _("Meta-information"),_("Artist"));
1123 o_current_author = [NSString stringWithUTF8String: psz_temp];
1127 if (p_selected_item == p_item->pp_children[i_current] && b_selected_item_met == NO)
1128 b_selected_item_met = YES;
1129 else if (p_selected_item == p_item->pp_children[i_current] && b_selected_item_met == YES)
1131 else if (b_selected_item_met == YES &&
1132 ([o_current_name rangeOfString:[o_search_field
1133 stringValue] options:NSCaseInsensitiveSearch].length ||
1134 [o_current_author rangeOfString:[o_search_field
1135 stringValue] options:NSCaseInsensitiveSearch].length))
1136 /*Adds the parent items in the result array as well, so that we can
1138 return [NSMutableArray arrayWithObject: [NSValue valueWithPointer: p_item->pp_children[i_current]]];
1140 if (p_item->pp_children[i_current]->i_children > 0) {
1141 id o_result = [self subSearchItem:
1142 p_item->pp_children[i_current]];
1143 if (o_result != NULL) {
1144 [o_result insertObject: [NSValue valueWithPointer:
1145 p_item->pp_children[i_current]] atIndex:0];
1153 - (IBAction)searchItem:(id)sender
1155 playlist_t * p_playlist = pl_Get(VLCIntf);
1160 b_selected_item_met = NO;
1162 /* First, only search after the selected item:
1163 * (b_selected_item_met = NO) */
1164 o_result = [self subSearchItem:[self currentPlaylistRoot]];
1165 if (o_result == NULL)
1166 /* If the first search failed, search again from the beginning */
1167 o_result = [self subSearchItem:[self currentPlaylistRoot]];
1169 if (o_result != NULL) {
1171 if ([[o_result objectAtIndex: 0] pointerValue] == p_playlist->p_local_category)
1175 NSUInteger count = [o_result count];
1177 for (NSUInteger i = i_start ; i < count - 1 ; i++) {
1178 [o_outline_view expandItem: [o_outline_dict objectForKey:
1179 [NSString stringWithFormat: @"%p",
1180 [[o_result objectAtIndex: i] pointerValue]]]];
1182 i_row = [o_outline_view rowForItem: [o_outline_dict objectForKey:
1183 [NSString stringWithFormat: @"%p",
1184 [[o_result objectAtIndex: count - 1 ]
1188 [o_outline_view selectRowIndexes:[NSIndexSet indexSetWithIndex:i_row] byExtendingSelection:NO];
1189 [o_outline_view scrollRowToVisible: i_row];
1193 - (IBAction)recursiveExpandNode:(id)sender
1195 NSIndexSet * selectedRows = [o_outline_view selectedRowIndexes];
1196 NSUInteger count = [selectedRows count];
1197 NSUInteger indexes[count];
1198 [selectedRows getIndexes:indexes maxCount:count inIndexRange:nil];
1201 playlist_item_t *p_item;
1202 for (NSUInteger i = 0; i < count; i++) {
1203 o_item = [o_outline_view itemAtRow: indexes[i]];
1204 p_item = (playlist_item_t *)[o_item pointerValue];
1206 if (![[o_outline_view dataSource] outlineView: o_outline_view isItemExpandable: o_item])
1207 o_item = [o_outline_dict objectForKey: [NSString stringWithFormat: @"%p", p_item->p_parent]];
1209 /* We need to collapse the node first, since OSX refuses to recursively
1210 expand an already expanded node, even if children nodes are collapsed. */
1211 [o_outline_view collapseItem: o_item collapseChildren: YES];
1212 [o_outline_view expandItem: o_item expandChildren: YES];
1214 selectedRows = [o_outline_view selectedRowIndexes];
1215 [selectedRows getIndexes:indexes maxCount:count inIndexRange:nil];
1219 - (NSMenu *)menuForEvent:(NSEvent *)o_event
1225 pt = [o_outline_view convertPoint: [o_event locationInWindow] fromView: nil];
1226 int row = [o_outline_view rowAtPoint:pt];
1227 if (row != -1 && ![[o_outline_view selectedRowIndexes] containsIndex: row])
1228 [o_outline_view selectRowIndexes:[NSIndexSet indexSetWithIndex:row] byExtendingSelection:NO];
1230 b_item_sel = (row != -1 && [o_outline_view selectedRow] != -1);
1231 b_rows = [o_outline_view numberOfRows] != 0;
1233 [o_mi_play setEnabled: b_item_sel];
1234 [o_mi_delete setEnabled: b_item_sel];
1235 [o_mi_selectall setEnabled: b_rows];
1236 [o_mi_info setEnabled: b_item_sel];
1237 [o_mi_preparse setEnabled: b_item_sel];
1238 [o_mi_recursive_expand setEnabled: b_item_sel];
1239 [o_mi_sort_name setEnabled: b_item_sel];
1240 [o_mi_sort_author setEnabled: b_item_sel];
1245 - (void)outlineView: (NSOutlineView *)o_tv didClickTableColumn:(NSTableColumn *)o_tc
1247 int i_mode, i_type = 0;
1248 intf_thread_t *p_intf = VLCIntf;
1249 NSString * o_identifier = [o_tc identifier];
1251 playlist_t *p_playlist = pl_Get(p_intf);
1253 if ([o_identifier isEqualToString:TRACKNUM_COLUMN])
1254 i_mode = SORT_TRACK_NUMBER;
1255 else if ([o_identifier isEqualToString:TITLE_COLUMN])
1256 i_mode = SORT_TITLE;
1257 else if ([o_identifier isEqualToString:ARTIST_COLUMN])
1258 i_mode = SORT_ARTIST;
1259 else if ([o_identifier isEqualToString:GENRE_COLUMN])
1260 i_mode = SORT_GENRE;
1261 else if ([o_identifier isEqualToString:DURATION_COLUMN])
1262 i_mode = SORT_DURATION;
1263 else if ([o_identifier isEqualToString:ALBUM_COLUMN])
1264 i_mode = SORT_ALBUM;
1265 else if ([o_identifier isEqualToString:DESCRIPTION_COLUMN])
1266 i_mode = SORT_DESCRIPTION;
1267 else if ([o_identifier isEqualToString:URI_COLUMN])
1272 if (o_tc_sortColumn == o_tc)
1273 b_isSortDescending = !b_isSortDescending;
1275 b_isSortDescending = false;
1277 if (b_isSortDescending)
1278 i_type = ORDER_REVERSE;
1280 i_type = ORDER_NORMAL;
1283 playlist_RecursiveNodeSort(p_playlist, [self currentPlaylistRoot], i_mode, i_type);
1286 [self playlistUpdated];
1288 o_tc_sortColumn = o_tc;
1289 [o_outline_view setHighlightedTableColumn:o_tc];
1291 if (b_isSortDescending)
1292 [o_outline_view setIndicatorImage:o_descendingSortingImage inTableColumn:o_tc];
1294 [o_outline_view setIndicatorImage:o_ascendingSortingImage inTableColumn:o_tc];
1298 - (void)outlineView:(NSOutlineView *)outlineView
1299 willDisplayCell:(id)cell
1300 forTableColumn:(NSTableColumn *)tableColumn
1303 /* this method can be called when VLC is already dead, hence the extra checks */
1304 intf_thread_t * p_intf = VLCIntf;
1307 playlist_t *p_playlist = pl_Get(p_intf);
1314 o_playing_item = [o_outline_dict objectForKey: [NSString stringWithFormat:@"%p", playlist_CurrentPlayingItem(p_playlist)]];
1317 if ([self isItem: [o_playing_item pointerValue] inNode: [item pointerValue] checkItemExistence:YES locked:NO]
1318 || [o_playing_item isEqual: item])
1319 [cell setFont: [[NSFontManager sharedFontManager] convertFont:[cell font] toHaveTrait:NSBoldFontMask]];
1321 [cell setFont: [[NSFontManager sharedFontManager] convertFont:[cell font] toNotHaveTrait:NSBoldFontMask]];
1326 playlist_t *p_playlist = pl_Get(VLCIntf);
1331 o_playing_item = [o_outline_dict objectForKey: [NSString stringWithFormat:@"%p", playlist_CurrentPlayingItem(p_playlist)]];
1334 return o_playing_item;
1337 - (NSArray *)draggedItems
1339 return [[o_nodes_array arrayByAddingObjectsFromArray: o_items_array] retain];
1342 - (void)setColumn: (NSString *)o_column state: (NSInteger)i_state translationDict:(NSDictionary *)o_dict
1344 NSTableColumn * o_work_tc;
1346 if (i_state == NSOnState) {
1347 o_work_tc = [[NSTableColumn alloc] initWithIdentifier: o_column];
1348 [o_work_tc setEditable: NO];
1349 [[o_work_tc dataCell] setFont: [NSFont controlContentFontOfSize:11.]];
1351 [[o_work_tc headerCell] setStringValue: [o_dict objectForKey:o_column]];
1353 if ([o_column isEqualToString: TRACKNUM_COLUMN]) {
1354 [o_work_tc setWidth: 20.];
1355 [o_work_tc setResizingMask: NSTableColumnNoResizing];
1356 [[o_work_tc headerCell] setStringValue: @"#"];
1359 [o_outline_view addTableColumn: o_work_tc];
1360 [o_work_tc release];
1361 [o_outline_view reloadData];
1362 [o_outline_view setNeedsDisplay: YES];
1365 [o_outline_view removeTableColumn: [o_outline_view tableColumnWithIdentifier: o_column]];
1368 - (void)saveTableColumns
1370 NSMutableArray * o_arrayToSave = [[NSMutableArray alloc] init];
1371 NSArray * o_columns = [[NSArray alloc] initWithArray:[o_outline_view tableColumns]];
1372 NSUInteger count = [o_columns count];
1373 NSTableColumn * o_currentColumn;
1374 for (NSUInteger i = 0; i < count; i++) {
1375 o_currentColumn = [o_columns objectAtIndex: i];
1376 [o_arrayToSave addObject: [NSArray arrayWithObjects: [o_currentColumn identifier], [NSNumber numberWithFloat: [o_currentColumn width]], nil]];
1378 [[NSUserDefaults standardUserDefaults] setObject: o_arrayToSave forKey:@"PlaylistColumnSelection"];
1379 [[NSUserDefaults standardUserDefaults] synchronize];
1380 [o_columns release];
1381 [o_arrayToSave release];
1386 @implementation VLCPlaylist (NSOutlineViewDataSource)
1388 - (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item
1390 id o_value = [super outlineView: outlineView child: index ofItem: item];
1392 [o_outline_dict setObject:o_value forKey:[NSString stringWithFormat:@"%p", [o_value pointerValue]]];
1396 /* Required for drag & drop and reordering */
1397 - (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pboard
1399 playlist_t *p_playlist = pl_Get(VLCIntf);
1401 /* First remove the items that were moved during the last drag & drop
1403 [o_items_array removeAllObjects];
1404 [o_nodes_array removeAllObjects];
1406 NSUInteger itemCount = [items count];
1408 for (NSUInteger i = 0 ; i < itemCount ; i++) {
1409 id o_item = [items objectAtIndex: i];
1411 /* Fill the items and nodes to move in 2 different arrays */
1412 if (((playlist_item_t *)[o_item pointerValue])->i_children > 0)
1413 [o_nodes_array addObject: o_item];
1415 [o_items_array addObject: o_item];
1418 /* Now we need to check if there are selected items that are in already
1419 selected nodes. In that case, we only want to move the nodes */
1420 [self removeItemsFrom: o_nodes_array ifChildrenOf: o_nodes_array];
1421 [self removeItemsFrom: o_items_array ifChildrenOf: o_nodes_array];
1423 /* We add the "VLCPlaylistItemPboardType" type to be able to recognize
1424 a Drop operation coming from the playlist. */
1426 [pboard declareTypes: [NSArray arrayWithObjects:
1427 @"VLCPlaylistItemPboardType", nil] owner: self];
1428 [pboard setData:[NSData data] forType:@"VLCPlaylistItemPboardType"];
1433 - (NSDragOperation)outlineView:(NSOutlineView *)outlineView validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(NSInteger)index
1435 playlist_t *p_playlist = pl_Get(VLCIntf);
1436 NSPasteboard *o_pasteboard = [info draggingPasteboard];
1438 if (!p_playlist) return NSDragOperationNone;
1440 /* Dropping ON items is not allowed if item is not a node */
1442 if (index == NSOutlineViewDropOnItemIndex &&
1443 ((playlist_item_t *)[item pointerValue])->i_children == -1) {
1444 return NSDragOperationNone;
1448 /* We refuse to drop an item in anything else than a child of the General
1449 Node. We still accept items that would be root nodes of the outlineview
1450 however, to allow drop in an empty playlist. */
1451 if (!(([self isItem: [item pointerValue] inNode: p_playlist->p_local_category checkItemExistence: NO locked: NO] ||
1452 (var_CreateGetBool(p_playlist, "media-library") && [self isItem: [item pointerValue] inNode: p_playlist->p_ml_category checkItemExistence: NO locked: NO])) || item == nil)) {
1453 return NSDragOperationNone;
1456 /* Drop from the Playlist */
1457 if ([[o_pasteboard types] containsObject: @"VLCPlaylistItemPboardType"]) {
1458 NSUInteger count = [o_nodes_array count];
1459 for (NSUInteger i = 0 ; i < count ; i++) {
1460 /* We refuse to Drop in a child of an item we are moving */
1461 if ([self isItem: [item pointerValue] inNode: [[o_nodes_array objectAtIndex: i] pointerValue] checkItemExistence: NO locked:NO]) {
1462 return NSDragOperationNone;
1465 return NSDragOperationMove;
1467 /* Drop from the Finder */
1468 else if ([[o_pasteboard types] containsObject: NSFilenamesPboardType]) {
1469 return NSDragOperationGeneric;
1471 return NSDragOperationNone;
1474 - (BOOL)outlineView:(NSOutlineView *)outlineView acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(NSInteger)index
1476 playlist_t * p_playlist = pl_Get(VLCIntf);
1477 NSPasteboard *o_pasteboard = [info draggingPasteboard];
1479 /* Drag & Drop inside the playlist */
1480 if ([[o_pasteboard types] containsObject: @"VLCPlaylistItemPboardType"]) {
1482 playlist_item_t *p_new_parent, *p_item = NULL;
1483 NSArray *o_all_items = [o_nodes_array arrayByAddingObjectsFromArray: o_items_array];
1484 /* If the item is to be dropped as root item of the outline, make it a
1485 child of the respective general node, if is either the pl or the ml
1486 Else, choose the proposed parent as parent. */
1488 if ([self currentPlaylistRoot] == p_playlist->p_local_category || [self currentPlaylistRoot] == p_playlist->p_ml_category)
1489 p_new_parent = [self currentPlaylistRoot];
1494 p_new_parent = [item pointerValue];
1496 /* Make sure the proposed parent is a node.
1497 (This should never be true) */
1498 if (p_new_parent->i_children < 0)
1501 NSUInteger count = [o_all_items count];
1505 playlist_item_t **pp_items = (playlist_item_t **)calloc(count, sizeof(playlist_item_t*));
1511 for (NSUInteger i = 0; i < count; i++) {
1512 p_item = [[o_all_items objectAtIndex:i] pointerValue];
1514 pp_items[j++] = p_item;
1517 if (j == 0 || playlist_TreeMoveMany(p_playlist, j, pp_items, p_new_parent, index) != VLC_SUCCESS) {
1526 [self playlistUpdated];
1527 i_row = [o_outline_view rowForItem:[o_outline_dict objectForKey:[NSString stringWithFormat: @"%p", [[o_all_items objectAtIndex: 0] pointerValue]]]];
1530 i_row = [o_outline_view rowForItem:[o_outline_dict objectForKey:[NSString stringWithFormat: @"%p", p_new_parent]]];
1532 [o_outline_view deselectAll: self];
1533 [o_outline_view selectRowIndexes:[NSIndexSet indexSetWithIndex:i_row] byExtendingSelection:NO];
1534 [o_outline_view scrollRowToVisible: i_row];
1539 else if ([[o_pasteboard types] containsObject: NSFilenamesPboardType]) {
1540 if ([self currentPlaylistRoot] != p_playlist->p_local_category && [self currentPlaylistRoot] != p_playlist->p_ml_category)
1543 playlist_item_t *p_node = [item pointerValue];
1545 NSArray *o_values = [[o_pasteboard propertyListForType: NSFilenamesPboardType]
1546 sortedArrayUsingSelector: @selector(caseInsensitiveCompare:)];
1547 NSUInteger count = [o_values count];
1548 NSMutableArray *o_array = [NSMutableArray arrayWithCapacity:count];
1549 input_thread_t * p_input = pl_CurrentInput(VLCIntf);
1550 BOOL b_returned = NO;
1552 if (count == 1 && p_input) {
1553 b_returned = input_AddSubtitle(p_input, vlc_path2uri([[o_values objectAtIndex:0] UTF8String], NULL), true);
1554 vlc_object_release(p_input);
1559 vlc_object_release(p_input);
1561 for (NSUInteger i = 0; i < count; i++) {
1562 NSDictionary *o_dic;
1563 char *psz_uri = vlc_path2uri([[o_values objectAtIndex:i] UTF8String], NULL);
1567 o_dic = [NSDictionary dictionaryWithObject:[NSString stringWithCString:psz_uri encoding:NSUTF8StringEncoding] forKey:@"ITEM_URL"];
1571 [o_array addObject: o_dic];
1575 [self appendArray:o_array atPos:index enqueue: YES];
1577 assert(p_node->i_children != -1);
1578 [self appendNodeArray:o_array inNode: p_node atPos:index enqueue:YES];