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] )
74 key = [[o_event characters] characterAtIndex: 0];
79 case NSDeleteCharacter:
80 case NSDeleteFunctionKey:
81 case NSDeleteCharFunctionKey:
82 case NSBackspaceCharacter:
83 [(VLCPlaylist *)[self delegate] deleteItem:self];
86 case NSEnterCharacter:
87 case NSCarriageReturnCharacter:
88 [(VLCPlaylist *)[[VLCMain sharedInstance] playlist] playItem:nil];
92 [super keyDown: o_event];
97 - (BOOL)validateMenuItem:(NSMenuItem *)item
99 if (([self numberOfSelectedRows] >= 1 && [item action] == @selector(delete:)) || [item action] == @selector(selectAll:))
105 - (BOOL) acceptsFirstResponder
110 - (BOOL) becomeFirstResponder
112 [self setNeedsDisplay:YES];
116 - (BOOL) resignFirstResponder
118 [self setNeedsDisplay:YES];
122 - (IBAction)delete:(id)sender
124 [[[VLCMain sharedInstance] playlist] deleteItem: sender];
129 /*****************************************************************************
130 * VLCPlaylistCommon implementation
132 * This class the superclass of the VLCPlaylist and VLCPlaylistWizard.
133 * It contains the common methods and elements of these 2 entities.
134 *****************************************************************************/
135 @implementation VLCPlaylistCommon
139 playlist_t * p_playlist = pl_Get( VLCIntf );
140 p_current_root_item = p_playlist->p_local_category;
145 o_outline_dict = [[NSMutableDictionary alloc] init];
152 playlist_t * p_playlist = pl_Get( VLCIntf );
153 [o_outline_view setTarget: self];
154 [o_outline_view setDelegate: self];
155 [o_outline_view setDataSource: self];
156 [o_outline_view setAllowsEmptySelection: NO];
157 [o_outline_view expandItem: [o_outline_view itemAtRow:0]];
159 [o_outline_view_other setTarget: self];
160 [o_outline_view_other setDelegate: self];
161 [o_outline_view_other setDataSource: self];
162 [o_outline_view_other setAllowsEmptySelection: NO];
164 [[o_tc_name_other headerCell] setStringValue:_NS("Name")];
165 [[o_tc_author_other headerCell] setStringValue:_NS("Author")];
166 [[o_tc_duration_other headerCell] setStringValue:_NS("Duration")];
169 - (void)setPlaylistRoot: (playlist_item_t *)root_item
171 p_current_root_item = root_item;
172 [o_outline_view reloadData];
173 [o_outline_view_other reloadData];
176 - (playlist_item_t *)currentPlaylistRoot
178 return p_current_root_item;
181 - (NSOutlineView *)outlineView
183 return o_outline_view;
186 - (playlist_item_t *)selectedPlaylistItem
188 return [[o_outline_view itemAtRow: [o_outline_view selectedRow]]
194 @implementation VLCPlaylistCommon (NSOutlineViewDataSource)
195 /* return the number of children for Obj-C pointer item */ /* DONE */
196 - (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
199 playlist_item_t *p_item = NULL;
200 playlist_t * p_playlist = pl_Get( VLCIntf );
201 //assert( outlineView == o_outline_view );
206 p_item = p_current_root_item;
209 p_item = (playlist_item_t *)[item pointerValue];
212 i_return = p_item->i_children;
215 return i_return > 0 ? i_return : 0;
218 /* return the child at index for the Obj-C pointer item */ /* DONE */
219 - (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item
221 playlist_item_t *p_return = NULL, *p_item = NULL;
223 playlist_t * p_playlist = pl_Get( VLCIntf );
229 p_item = p_current_root_item;
233 p_item = (playlist_item_t *)[item pointerValue];
235 if( p_item && index < p_item->i_children && index >= 0 )
236 p_return = p_item->pp_children[index];
239 o_value = [o_outline_dict objectForKey:[NSString stringWithFormat: @"%p", p_return]];
243 /* FIXME: Why is there a warning if that happens all the time and seems
244 * to be normal? Add an assert and fix it.
245 * msg_Warn( VLCIntf, "playlist item misses pointer value, adding one" ); */
246 o_value = [[NSValue valueWithPointer: p_return] retain];
251 /* is the item expandable */
252 - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item
255 playlist_t *p_playlist = pl_Get( VLCIntf );
261 if( p_current_root_item )
263 i_return = p_current_root_item->i_children;
268 playlist_item_t *p_item = (playlist_item_t *)[item pointerValue];
270 i_return = p_item->i_children;
274 return (i_return >= 0);
277 /* retrieve the string values for the cells */
278 - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)o_tc byItem:(id)item
282 playlist_item_t *p_item;
284 /* For error handling */
285 static BOOL attempted_reload = NO;
287 if( item == nil || ![item isKindOfClass: [NSValue class]] )
289 /* Attempt to fix the error by asking for a data redisplay
290 * This might cause infinite loop, so add a small check */
291 if( !attempted_reload )
293 attempted_reload = YES;
294 [outlineView reloadData];
299 p_item = (playlist_item_t *)[item pointerValue];
300 if( !p_item || !p_item->p_input )
302 /* Attempt to fix the error by asking for a data redisplay
303 * This might cause infinite loop, so add a small check */
304 if( !attempted_reload )
306 attempted_reload = YES;
307 [outlineView reloadData];
312 attempted_reload = NO;
313 NSString * o_identifier = [o_tc identifier];
315 if( [o_identifier isEqualToString:TRACKNUM_COLUMN] )
317 psz_value = input_item_GetTrackNumber( p_item->p_input ); \
319 o_value = [NSString stringWithUTF8String: psz_value]; \
323 else if( [o_identifier isEqualToString:TITLE_COLUMN] )
325 /* sanity check to prevent the NSString class from crashing */
326 char *psz_title = input_item_GetTitleFbName( p_item->p_input );
329 o_value = [NSString stringWithUTF8String: psz_title];
333 else if( [o_identifier isEqualToString:ARTIST_COLUMN] )
335 psz_value = input_item_GetArtist( p_item->p_input ); \
337 o_value = [NSString stringWithUTF8String: psz_value]; \
341 else if( [o_identifier isEqualToString:@"duration"] )
343 char psz_duration[MSTRTIME_MAX_SIZE];
344 mtime_t dur = input_item_GetDuration( p_item->p_input );
347 secstotimestr( psz_duration, dur/1000000 );
348 o_value = [NSString stringWithUTF8String: psz_duration];
353 else if( [o_identifier isEqualToString:GENRE_COLUMN] )
355 psz_value = input_item_GetGenre( p_item->p_input ); \
357 o_value = [NSString stringWithUTF8String: psz_value]; \
361 else if( [o_identifier isEqualToString:ALBUM_COLUMN] )
363 psz_value = input_item_GetAlbum( p_item->p_input ); \
365 o_value = [NSString stringWithUTF8String: psz_value]; \
369 else if( [o_identifier isEqualToString:DESCRIPTION_COLUMN] )
371 psz_value = input_item_GetDescription( p_item->p_input ); \
373 o_value = [NSString stringWithUTF8String: psz_value]; \
377 else if( [o_identifier isEqualToString:DATE_COLUMN] )
379 psz_value = input_item_GetDate( p_item->p_input ); \
381 o_value = [NSString stringWithUTF8String: psz_value]; \
385 else if( [o_identifier isEqualToString:LANGUAGE_COLUMN] )
387 psz_value = input_item_GetLanguage( p_item->p_input ); \
389 o_value = [NSString stringWithUTF8String: psz_value]; \
393 else if( [o_identifier isEqualToString:URI_COLUMN] )
395 psz_value = decode_URI(input_item_GetURI( p_item->p_input )); \
397 o_value = [NSString stringWithUTF8String: psz_value]; \
401 else if( [o_identifier isEqualToString:@"status"] )
403 if( input_item_HasErrorWhenReading( p_item->p_input ) )
405 o_value = [[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode(kAlertCautionIcon)];
406 [o_value setSize: NSMakeSize(16,16)];
415 /*****************************************************************************
416 * VLCPlaylistWizard implementation
417 *****************************************************************************/
418 @implementation VLCPlaylistWizard
420 - (IBAction)reloadOutlineView
422 /* Only reload the outlineview if the wizard window is open since this can
423 be quite long on big playlists */
424 if( [[o_outline_view window] isVisible] )
426 [o_outline_view reloadData];
432 /*****************************************************************************
433 * An extension to NSOutlineView's interface to fix compilation warnings
434 * and let us access these 2 functions properly.
435 * This uses a private API, but works fine on all current OSX releases.
436 * Radar ID 11739459 request a public API for this. However, it is probably
437 * easier and faster to recreate similar looking bitmaps ourselves.
438 *****************************************************************************/
440 @interface NSOutlineView (UndocumentedSortImages)
441 + (NSImage *)_defaultTableHeaderSortImage;
442 + (NSImage *)_defaultTableHeaderReverseSortImage;
446 /*****************************************************************************
447 * VLCPlaylist implementation
448 *****************************************************************************/
449 @implementation VLCPlaylist
452 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
453 NSMutableArray * o_columnArray = [[NSMutableArray alloc] init];
454 [o_columnArray addObject: [NSArray arrayWithObjects: TITLE_COLUMN, [NSNumber numberWithFloat: 190.], nil]];
455 [o_columnArray addObject: [NSArray arrayWithObjects: ARTIST_COLUMN, [NSNumber numberWithFloat: 95.], nil]];
456 [o_columnArray addObject: [NSArray arrayWithObjects: DURATION_COLUMN, [NSNumber numberWithFloat: 95.], nil]];
457 NSDictionary *appDefaults = [NSDictionary dictionaryWithObject:[NSArray arrayWithArray:o_columnArray] forKey:@"PlaylistColumnSelection"];
459 [defaults registerDefaults:appDefaults];
460 [o_columnArray release];
468 o_nodes_array = [[NSMutableArray alloc] init];
469 o_items_array = [[NSMutableArray alloc] init];
476 [o_nodes_array release];
477 [o_items_array release];
483 playlist_t * p_playlist = pl_Get( VLCIntf );
487 [super awakeFromNib];
489 [o_outline_view setDoubleAction: @selector(playItem:)];
490 [o_outline_view_other setDoubleAction: @selector(playItem:)];
492 [o_outline_view registerForDraggedTypes:
493 [NSArray arrayWithObjects: NSFilenamesPboardType,
494 @"VLCPlaylistItemPboardType", nil]];
495 [o_outline_view setIntercellSpacing: NSMakeSize (0.0, 1.0)];
497 [o_outline_view_other registerForDraggedTypes:
498 [NSArray arrayWithObjects: NSFilenamesPboardType,
499 @"VLCPlaylistItemPboardType", nil]];
500 [o_outline_view_other setIntercellSpacing: NSMakeSize (0.0, 1.0)];
502 /* This uses a private API, but works fine on all current OSX releases.
503 * Radar ID 11739459 request a public API for this. However, it is probably
504 * easier and faster to recreate similar looking bitmaps ourselves. */
505 o_ascendingSortingImage = [[NSOutlineView class] _defaultTableHeaderSortImage];
506 o_descendingSortingImage = [[NSOutlineView class] _defaultTableHeaderReverseSortImage];
508 o_tc_sortColumn = nil;
510 NSArray * o_columnArray = [[NSUserDefaults standardUserDefaults] arrayForKey:@"PlaylistColumnSelection"];
511 NSUInteger count = [o_columnArray count];
513 id o_menu = [[VLCMain sharedInstance] mainMenu];
516 NSMenu *o_context_menu = [o_menu setupPlaylistTableColumnsMenu];
517 [o_playlist_header setMenu: o_context_menu];
519 for (NSUInteger i = 0; i < count; i++)
521 o_column = [[o_columnArray objectAtIndex:i] objectAtIndex:0];
522 if ([o_column isEqualToString:@"status"])
525 [o_menu setPlaylistColumnTableState: NSOnState forColumn: o_column];
526 [[o_outline_view tableColumnWithIdentifier: o_column] setWidth: [[[o_columnArray objectAtIndex:i] objectAtIndex:1] floatValue]];
529 [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(applicationWillTerminate:) name: NSApplicationWillTerminateNotification object: nil];
532 - (void)applicationWillTerminate:(NSNotification *)notification
534 /* 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 */
535 [self saveTableColumns];
538 - (void)searchfieldChanged:(NSNotification *)o_notification
540 [o_search_field setStringValue:[[o_notification object] stringValue]];
545 [o_mi_save_playlist setTitle: _NS("Save Playlist...")];
546 [o_mi_play setTitle: _NS("Play")];
547 [o_mi_delete setTitle: _NS("Delete")];
548 [o_mi_recursive_expand setTitle: _NS("Expand Node")];
549 [o_mi_selectall setTitle: _NS("Select All")];
550 [o_mi_info setTitle: _NS("Media Information...")];
551 [o_mi_dl_cover_art setTitle: _NS("Download Cover Art")];
552 [o_mi_preparse setTitle: _NS("Fetch Meta Data")];
553 [o_mi_revealInFinder setTitle: _NS("Reveal in Finder")];
554 [o_mm_mi_revealInFinder setTitle: _NS("Reveal in Finder")];
555 [[o_mm_mi_revealInFinder menu] setAutoenablesItems: NO];
556 [o_mi_sort_name setTitle: _NS("Sort Node by Name")];
557 [o_mi_sort_author setTitle: _NS("Sort Node by Author")];
559 [o_search_field setToolTip: _NS("Search in Playlist")];
560 [o_search_field_other setToolTip: _NS("Search in Playlist")];
562 [o_save_accessory_text setStringValue: _NS("File Format:")];
563 [[o_save_accessory_popup itemAtIndex:0] setTitle: _NS("Extended M3U")];
564 [[o_save_accessory_popup itemAtIndex:1] setTitle: _NS("XML Shareable Playlist Format (XSPF)")];
565 [[o_save_accessory_popup itemAtIndex:2] setTitle: _NS("HTML Playlist")];
568 - (void)playlistUpdated
570 /* Clear indications of any existing column sorting */
571 NSUInteger count = [[o_outline_view tableColumns] count];
572 for( NSUInteger i = 0 ; i < count ; i++ )
574 [o_outline_view setIndicatorImage:nil inTableColumn: [[o_outline_view tableColumns] objectAtIndex:i]];
577 [o_outline_view setHighlightedTableColumn:nil];
578 o_tc_sortColumn = nil;
579 // TODO Find a way to keep the dict size to a minimum
580 //[o_outline_dict removeAllObjects];
581 [o_outline_view reloadData];
582 [[[[VLCMain sharedInstance] wizard] playlistWizard] reloadOutlineView];
583 [[[[VLCMain sharedInstance] bookmarks] dataTable] reloadData];
585 [self outlineViewSelectionDidChange: nil];
586 [[VLCMain sharedInstance] updateMainWindow];
589 - (void)outlineViewSelectionDidChange:(NSNotification *)notification
592 playlist_item_t * p_item = [[o_outline_view itemAtRow:[o_outline_view selectedRow]] pointerValue];
596 /* update the state of our Reveal-in-Finder menu items */
597 NSMutableString *o_mrl;
598 char *psz_uri = input_item_GetURI( p_item->p_input );
600 [o_mi_revealInFinder setEnabled: NO];
601 [o_mm_mi_revealInFinder setEnabled: NO];
604 o_mrl = [NSMutableString stringWithUTF8String: psz_uri];
606 /* perform some checks whether it is a file and if it is local at all... */
607 NSRange prefix_range = [o_mrl rangeOfString: @"file:"];
608 if( prefix_range.location != NSNotFound )
609 [o_mrl deleteCharactersInRange: prefix_range];
611 if( [o_mrl characterAtIndex:0] == '/' )
613 [o_mi_revealInFinder setEnabled: YES];
614 [o_mm_mi_revealInFinder setEnabled: YES];
619 /* update our info-panel to reflect the new item */
620 [[[VLCMain sharedInstance] info] updatePanelWithItem:p_item->p_input];
624 - (BOOL)isSelectionEmpty
626 return [o_outline_view selectedRow] == -1;
629 - (void)updateRowSelection
632 playlist_t *p_playlist = pl_Get( VLCIntf );
633 playlist_item_t *p_item, *p_temp_item;
634 NSMutableArray *o_array = [NSMutableArray array];
637 p_item = playlist_CurrentPlayingItem( p_playlist );
644 p_temp_item = p_item;
645 while( p_temp_item->p_parent )
647 [o_array insertObject: [NSValue valueWithPointer: p_temp_item] atIndex: 0];
648 p_temp_item = p_temp_item->p_parent;
652 NSUInteger count = [o_array count];
653 for( NSUInteger j = 0; j < count - 1; j++ )
656 if( ( o_item = [o_outline_dict objectForKey:
657 [NSString stringWithFormat: @"%p",
658 [[o_array objectAtIndex:j] pointerValue]]] ) != nil )
660 [o_outline_view expandItem: o_item];
664 id o_item = [o_outline_dict objectForKey:[NSString stringWithFormat: @"%p", p_item]];
665 NSInteger i_index = [o_outline_view rowForItem:o_item];
666 [o_outline_view selectRowIndexes:[NSIndexSet indexSetWithIndex:i_index] byExtendingSelection:NO];
667 [o_outline_view setNeedsDisplay:YES];
670 /* Check if p_item is a child of p_node recursively. We need to check the item
671 existence first since OSX sometimes tries to redraw items that have been
672 deleted. We don't do it when not required since this verification takes
673 quite a long time on big playlists (yes, pretty hacky). */
675 - (BOOL)isItem: (playlist_item_t *)p_item inNode: (playlist_item_t *)p_node checkItemExistence:(BOOL)b_check locked:(BOOL)b_locked
677 playlist_t * p_playlist = pl_Get( VLCIntf );
678 playlist_item_t *p_temp_item = p_item;
683 if( p_node == p_item )
686 if( p_node->i_children < 1)
692 if(!b_locked) PL_LOCK;
696 /* Since outlineView: willDisplayCell:... may call this function with
697 p_items that don't exist anymore, first check if the item is still
698 in the playlist. Any cleaner solution welcomed. */
699 for( i = 0; i < p_playlist->all_items.i_size; i++ )
701 if( ARRAY_VAL( p_playlist->all_items, i) == p_item )
703 else if ( i == p_playlist->all_items.i_size - 1 )
705 if(!b_locked) PL_UNLOCK;
713 p_temp_item = p_temp_item->p_parent;
714 if( p_temp_item == p_node )
716 if(!b_locked) PL_UNLOCK;
720 if(!b_locked) PL_UNLOCK;
725 /* This method is useful for instance to remove the selected children of an
726 already selected node */
727 - (void)removeItemsFrom:(id)o_items ifChildrenOf:(id)o_nodes
729 NSUInteger itemCount = [o_items count];
730 NSUInteger nodeCount = [o_nodes count];
731 for( NSUInteger i = 0 ; i < itemCount ; i++ )
733 for ( NSUInteger j = 0 ; j < nodeCount ; j++ )
735 if( o_items == o_nodes)
737 if( j == i ) continue;
739 if( [self isItem: [[o_items objectAtIndex:i] pointerValue]
740 inNode: [[o_nodes objectAtIndex:j] pointerValue]
741 checkItemExistence: NO locked:NO] )
743 [o_items removeObjectAtIndex:i];
744 /* We need to execute the next iteration with the same index
745 since the current item has been deleted */
753 - (IBAction)savePlaylist:(id)sender
755 playlist_t * p_playlist = pl_Get( VLCIntf );
757 NSSavePanel *o_save_panel = [NSSavePanel savePanel];
758 NSString * o_name = [NSString stringWithFormat: @"%@", _NS("Untitled")];
760 [o_save_panel setTitle: _NS("Save Playlist")];
761 [o_save_panel setPrompt: _NS("Save")];
762 [o_save_panel setAccessoryView: o_save_accessory_view];
763 [o_save_panel setNameFieldStringValue: o_name];
765 if( [o_save_panel runModal] == NSFileHandlingPanelOKButton )
767 NSString *o_filename = [[o_save_panel URL] path];
769 if( [o_save_accessory_popup indexOfSelectedItem] == 0 )
771 NSString * o_real_filename;
773 range.location = [o_filename length] - [@".m3u" length];
774 range.length = [@".m3u" length];
776 if( [o_filename compare:@".m3u" options: NSCaseInsensitiveSearch
777 range: range] != NSOrderedSame )
779 o_real_filename = [NSString stringWithFormat: @"%@.m3u", o_filename];
783 o_real_filename = o_filename;
785 playlist_Export( p_playlist,
786 [o_real_filename fileSystemRepresentation],
787 p_playlist->p_local_category, "export-m3u" );
789 else if( [o_save_accessory_popup indexOfSelectedItem] == 1 )
791 NSString * o_real_filename;
793 range.location = [o_filename length] - [@".xspf" length];
794 range.length = [@".xspf" length];
796 if( [o_filename compare:@".xspf" options: NSCaseInsensitiveSearch
797 range: range] != NSOrderedSame )
799 o_real_filename = [NSString stringWithFormat: @"%@.xspf", o_filename];
803 o_real_filename = o_filename;
805 playlist_Export( p_playlist,
806 [o_real_filename fileSystemRepresentation],
807 p_playlist->p_local_category, "export-xspf" );
811 NSString * o_real_filename;
813 range.location = [o_filename length] - [@".html" length];
814 range.length = [@".html" length];
816 if( [o_filename compare:@".html" options: NSCaseInsensitiveSearch
817 range: range] != NSOrderedSame )
819 o_real_filename = [NSString stringWithFormat: @"%@.html", o_filename];
823 o_real_filename = o_filename;
825 playlist_Export( p_playlist,
826 [o_real_filename fileSystemRepresentation],
827 p_playlist->p_local_category, "export-html" );
832 /* When called retrieves the selected outlineview row and plays that node or item */
833 - (IBAction)playItem:(id)sender
835 intf_thread_t * p_intf = VLCIntf;
836 playlist_t * p_playlist = pl_Get( p_intf );
838 playlist_item_t *p_item;
839 playlist_item_t *p_node = NULL;
841 // ignore clicks on column header when handling double action
842 if( sender != nil && [o_outline_view clickedRow] == -1 && sender != o_mi_play)
845 p_item = [[o_outline_view itemAtRow:[o_outline_view selectedRow]] pointerValue];
850 if( p_item->i_children == -1 )
852 p_node = p_item->p_parent;
857 if( p_node->i_children > 0 && p_node->pp_children[0]->i_children == -1 )
859 p_item = p_node->pp_children[0];
866 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, pl_Locked, p_node, p_item );
871 - (IBAction)revealItemInFinder:(id)sender
873 NSIndexSet * selectedRows = [o_outline_view selectedRowIndexes];
874 NSUInteger count = [selectedRows count];
875 NSUInteger indexes[count];
876 [selectedRows getIndexes:indexes maxCount:count inIndexRange:nil];
878 NSMutableString * o_mrl;
879 playlist_item_t *p_item;
880 for (NSUInteger i = 0; i < count; i++) {
881 p_item = [[o_outline_view itemAtRow:indexes[i]] pointerValue];
883 if(! p_item || !p_item->p_input )
886 o_mrl = [[NSMutableString alloc] initWithFormat: @"%s", decode_URI( input_item_GetURI( p_item->p_input ))];
888 /* perform some checks whether it is a file and if it is local at all... */
889 if ([o_mrl length] > 0)
891 NSRange prefix_range = [o_mrl rangeOfString: @"file:"];
892 if( prefix_range.location != NSNotFound )
893 [o_mrl deleteCharactersInRange: prefix_range];
895 if( [o_mrl characterAtIndex:0] == '/' )
896 [[NSWorkspace sharedWorkspace] selectFile: o_mrl inFileViewerRootedAtPath: o_mrl];
903 /* When called retrieves the selected outlineview row and plays that node or item */
904 - (IBAction)preparseItem:(id)sender
907 NSIndexSet *o_selected_indexes;
908 intf_thread_t * p_intf = VLCIntf;
909 playlist_t * p_playlist = pl_Get( p_intf );
910 playlist_item_t *p_item = NULL;
912 o_selected_indexes = [o_outline_view selectedRowIndexes];
913 i_count = [o_selected_indexes count];
915 NSUInteger indexes[i_count];
916 [o_selected_indexes getIndexes:indexes maxCount:i_count inIndexRange:nil];
917 for (int i = 0; i < i_count; i++)
919 p_item = [[o_outline_view itemAtRow:indexes[i]] pointerValue];
920 [o_outline_view deselectRow: indexes[i]];
924 if( p_item->i_children == -1 )
925 playlist_PreparseEnqueue( p_playlist, p_item->p_input );
927 msg_Dbg( p_intf, "preparsing nodes not implemented" );
930 [self playlistUpdated];
933 - (IBAction)downloadCoverArt:(id)sender
936 NSIndexSet *o_selected_indexes;
937 intf_thread_t * p_intf = VLCIntf;
938 playlist_t * p_playlist = pl_Get( p_intf );
939 playlist_item_t *p_item = NULL;
941 o_selected_indexes = [o_outline_view selectedRowIndexes];
942 i_count = [o_selected_indexes count];
944 NSUInteger indexes[i_count];
945 [o_selected_indexes getIndexes:indexes maxCount:i_count inIndexRange:nil];
946 for (int i = 0; i < i_count; i++)
948 p_item = [[o_outline_view itemAtRow: indexes[i]] pointerValue];
950 if( p_item && p_item->i_children == -1 )
951 playlist_AskForArtEnqueue( p_playlist, p_item->p_input );
953 [self playlistUpdated];
956 - (IBAction)selectAll:(id)sender
958 [o_outline_view selectAll: nil];
961 - (IBAction)deleteItem:(id)sender
964 NSIndexSet *o_selected_indexes;
965 playlist_t * p_playlist;
966 intf_thread_t * p_intf = VLCIntf;
968 o_selected_indexes = [o_outline_view selectedRowIndexes];
969 i_count = [o_selected_indexes count];
971 p_playlist = pl_Get( p_intf );
973 NSUInteger indexes[i_count];
974 if (i_count == [o_outline_view numberOfRows])
977 msg_Dbg( p_intf, "user selected entire list, deleting current playlist root instead of individual items" );
980 playlist_NodeDelete( p_playlist, [self currentPlaylistRoot], true, false );
982 [self playlistUpdated];
985 [o_selected_indexes getIndexes:indexes maxCount:i_count inIndexRange:nil];
986 for (int i = 0; i < i_count; i++)
988 id o_item = [o_outline_view itemAtRow: indexes[i]];
989 [o_outline_view deselectRow: indexes[i]];
992 playlist_item_t *p_item = [o_item pointerValue];
993 if (!p_item || !p_item->p_input) {
998 msg_Dbg( p_intf, "deleting item %i (of %i) with id \"%i\", pointerValue \"%p\" and %i children", i+1, i_count,
999 p_item->p_input->i_id, [o_item pointerValue], p_item->i_children +1 );
1002 if( p_item->i_children != -1 )
1003 //is a node and not an item
1005 if( playlist_Status( p_playlist ) != PLAYLIST_STOPPED &&
1006 [self isItem: playlist_CurrentPlayingItem( p_playlist ) inNode: ((playlist_item_t *)[o_item pointerValue])
1007 checkItemExistence: NO locked:YES] == YES )
1008 // if current item is in selected node and is playing then stop playlist
1009 playlist_Control(p_playlist, PLAYLIST_STOP, pl_Locked );
1011 playlist_NodeDelete( p_playlist, p_item, true, false );
1014 playlist_DeleteFromInput( p_playlist, p_item->p_input, pl_Locked );
1017 [o_outline_dict removeObjectForKey:[NSString stringWithFormat:@"%p", [o_item pointerValue]]];
1021 [self playlistUpdated];
1024 - (IBAction)sortNodeByName:(id)sender
1026 [self sortNode: SORT_TITLE];
1029 - (IBAction)sortNodeByAuthor:(id)sender
1031 [self sortNode: SORT_ARTIST];
1034 - (void)sortNode:(int)i_mode
1036 playlist_t * p_playlist = pl_Get( VLCIntf );
1037 playlist_item_t * p_item;
1039 if( [o_outline_view selectedRow] > -1 )
1041 p_item = [[o_outline_view itemAtRow: [o_outline_view selectedRow]] pointerValue];
1046 p_item = [self currentPlaylistRoot]; // If no item is selected, sort the whole playlist
1049 if( p_item->i_children > -1 ) // the item is a node
1051 playlist_RecursiveNodeSort( p_playlist, p_item, i_mode, ORDER_NORMAL );
1055 playlist_RecursiveNodeSort( p_playlist,
1056 p_item->p_parent, i_mode, ORDER_NORMAL );
1059 [self playlistUpdated];
1062 - (input_item_t *)createItem:(NSDictionary *)o_one_item
1064 intf_thread_t * p_intf = VLCIntf;
1065 playlist_t * p_playlist = pl_Get( p_intf );
1067 input_item_t *p_input;
1068 BOOL b_rem = FALSE, b_dir = FALSE, b_writable = FALSE;
1069 NSString *o_uri, *o_name, *o_path;
1075 o_uri = (NSString *)[o_one_item objectForKey: @"ITEM_URL"];
1076 o_nsurl = [NSURL URLWithString: o_uri];
1077 o_path = [o_nsurl path];
1078 o_name = (NSString *)[o_one_item objectForKey: @"ITEM_NAME"];
1079 o_options = (NSArray *)[o_one_item objectForKey: @"ITEM_OPTIONS"];
1081 if( [[NSFileManager defaultManager] fileExistsAtPath:o_path isDirectory:&b_dir] && b_dir &&
1082 [[NSWorkspace sharedWorkspace] getFileSystemInfoForPath:o_path isRemovable: &b_rem
1083 isWritable:&b_writable isUnmountable:NULL description:NULL type:NULL] && b_rem && !b_writable && [o_nsurl isFileURL] )
1086 id o_vlc_open = [[VLCMain sharedInstance] open];
1088 NSString *diskType = [o_vlc_open getVolumeTypeFromMountPath: o_path];
1089 msg_Dbg( p_intf, "detected optical media of type %s in the file input", [diskType UTF8String] );
1091 if ([diskType isEqualToString: kVLCMediaDVD])
1093 o_uri = [NSString stringWithFormat: @"dvdnav://%@", [o_vlc_open getBSDNodeFromMountPath: o_path]];
1095 else if ([diskType isEqualToString: kVLCMediaVideoTSFolder])
1097 o_uri = [NSString stringWithFormat: @"dvdnav://%@", o_path];
1099 else if ([diskType isEqualToString: kVLCMediaAudioCD])
1101 o_uri = [NSString stringWithFormat: @"cdda://%@", [o_vlc_open getBSDNodeFromMountPath: o_path]];
1103 else if ([diskType isEqualToString: kVLCMediaVCD])
1105 o_uri = [NSString stringWithFormat: @"vcd://%@#0:0", [o_vlc_open getBSDNodeFromMountPath: o_path]];
1107 else if ([diskType isEqualToString: kVLCMediaSVCD])
1109 o_uri = [NSString stringWithFormat: @"vcd://%@@0:0", [o_vlc_open getBSDNodeFromMountPath: o_path]];
1111 else if ([diskType isEqualToString: kVLCMediaBD] || [diskType isEqualToString: kVLCMediaBDMVFolder])
1113 o_uri = [NSString stringWithFormat: @"bluray://%@", o_path];
1117 msg_Warn( VLCIntf, "unknown disk type, treating %s as regular input", [o_path UTF8String] );
1120 p_input = input_item_New( [o_uri UTF8String], [[[NSFileManager defaultManager] displayNameAtPath: o_path] UTF8String] );
1123 p_input = input_item_New( [o_uri fileSystemRepresentation], o_name ? [o_name UTF8String] : NULL );
1130 NSUInteger count = [o_options count];
1131 for( NSUInteger i = 0; i < count; i++ )
1133 input_item_AddOption( p_input, [[o_options objectAtIndex:i] UTF8String],
1134 VLC_INPUT_OPTION_TRUSTED );
1138 /* Recent documents menu */
1139 if( o_nsurl != nil && (BOOL)config_GetInt( p_playlist, "macosx-recentitems" ) == YES )
1141 [[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL: o_nsurl];
1146 - (void)appendArray:(NSArray*)o_array atPos:(int)i_position enqueue:(BOOL)b_enqueue
1148 playlist_t * p_playlist = pl_Get( VLCIntf );
1149 NSUInteger count = [o_array count];
1150 BOOL b_usingPlaylist;
1151 if ([self currentPlaylistRoot] == p_playlist->p_ml_category)
1152 b_usingPlaylist = NO;
1154 b_usingPlaylist = YES;
1157 for( NSUInteger i_item = 0; i_item < count; i_item++ )
1159 input_item_t *p_input;
1160 NSDictionary *o_one_item;
1163 o_one_item = [o_array objectAtIndex: i_item];
1164 p_input = [self createItem: o_one_item];
1169 int returnValue = playlist_AddInput( p_playlist, p_input, PLAYLIST_INSERT, i_position == -1 ? PLAYLIST_END : i_position + i_item, b_usingPlaylist, pl_Locked );
1170 if (returnValue != VLC_SUCCESS) {
1171 vlc_gc_decref( p_input );
1175 if( i_item == 0 && !b_enqueue )
1177 playlist_item_t *p_item = playlist_ItemGetByInput( p_playlist, p_input );
1178 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, pl_Locked, p_item->p_parent, p_item );
1181 vlc_gc_decref( p_input );
1184 [self playlistUpdated];
1187 - (void)appendNodeArray:(NSArray*)o_array inNode:(playlist_item_t *)p_node atPos:(int)i_position enqueue:(BOOL)b_enqueue
1189 playlist_t * p_playlist = pl_Get( VLCIntf );
1190 NSUInteger count = [o_array count];
1192 for( NSUInteger i_item = 0; i_item < count; i_item++ )
1194 input_item_t *p_input;
1195 NSDictionary *o_one_item;
1198 o_one_item = [o_array objectAtIndex: i_item];
1199 p_input = [self createItem: o_one_item];
1201 if( !p_input ) continue;
1205 playlist_NodeAddInput( p_playlist, p_input, p_node,
1208 PLAYLIST_END : i_position + i_item,
1212 if( i_item == 0 && !b_enqueue )
1214 playlist_item_t *p_item;
1215 p_item = playlist_ItemGetByInput( p_playlist, p_input );
1216 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, pl_Locked, p_node, p_item );
1219 vlc_gc_decref( p_input );
1221 [self playlistUpdated];
1224 - (NSMutableArray *)subSearchItem:(playlist_item_t *)p_item
1226 playlist_t *p_playlist = pl_Get( VLCIntf );
1227 playlist_item_t *p_selected_item;
1230 i_selected_row = [o_outline_view selectedRow];
1231 if (i_selected_row < 0)
1234 p_selected_item = (playlist_item_t *)[[o_outline_view itemAtRow: i_selected_row] pointerValue];
1236 for( NSUInteger i_current = 0; i_current < p_item->i_children ; i_current++ )
1239 NSString *o_current_name, *o_current_author;
1242 o_current_name = [NSString stringWithUTF8String:
1243 p_item->pp_children[i_current]->p_input->psz_name];
1244 psz_temp = input_item_GetInfo( p_item->p_input ,
1245 _("Meta-information"),_("Artist") );
1246 o_current_author = [NSString stringWithUTF8String: psz_temp];
1250 if( p_selected_item == p_item->pp_children[i_current] &&
1251 b_selected_item_met == NO )
1253 b_selected_item_met = YES;
1255 else if( p_selected_item == p_item->pp_children[i_current] &&
1256 b_selected_item_met == YES )
1260 else if( b_selected_item_met == YES &&
1261 ( [o_current_name rangeOfString:[o_search_field
1262 stringValue] options:NSCaseInsensitiveSearch].length ||
1263 [o_current_author rangeOfString:[o_search_field
1264 stringValue] options:NSCaseInsensitiveSearch].length ) )
1266 /*Adds the parent items in the result array as well, so that we can
1268 return [NSMutableArray arrayWithObject: [NSValue
1269 valueWithPointer: p_item->pp_children[i_current]]];
1271 if( p_item->pp_children[i_current]->i_children > 0 )
1273 id o_result = [self subSearchItem:
1274 p_item->pp_children[i_current]];
1275 if( o_result != NULL )
1277 [o_result insertObject: [NSValue valueWithPointer:
1278 p_item->pp_children[i_current]] atIndex:0];
1286 - (IBAction)searchItem:(id)sender
1288 playlist_t * p_playlist = pl_Get( VLCIntf );
1293 b_selected_item_met = NO;
1295 /*First, only search after the selected item:*
1296 *(b_selected_item_met = NO) */
1297 o_result = [self subSearchItem:[self currentPlaylistRoot]];
1298 if( o_result == NULL )
1300 /* If the first search failed, search again from the beginning */
1301 o_result = [self subSearchItem:[self currentPlaylistRoot]];
1303 if( o_result != NULL )
1306 if( [[o_result objectAtIndex: 0] pointerValue] == p_playlist->p_local_category )
1310 NSUInteger count = [o_result count];
1312 for( NSUInteger i = i_start ; i < count - 1 ; i++ )
1314 [o_outline_view expandItem: [o_outline_dict objectForKey:
1315 [NSString stringWithFormat: @"%p",
1316 [[o_result objectAtIndex: i] pointerValue]]]];
1318 i_row = [o_outline_view rowForItem: [o_outline_dict objectForKey:
1319 [NSString stringWithFormat: @"%p",
1320 [[o_result objectAtIndex: count - 1 ]
1325 [o_outline_view selectRowIndexes:[NSIndexSet indexSetWithIndex:i_row] byExtendingSelection:NO];
1326 [o_outline_view scrollRowToVisible: i_row];
1330 - (IBAction)recursiveExpandNode:(id)sender
1332 NSIndexSet * selectedRows = [o_outline_view selectedRowIndexes];
1333 NSUInteger count = [selectedRows count];
1334 NSUInteger indexes[count];
1335 [selectedRows getIndexes:indexes maxCount:count inIndexRange:nil];
1338 playlist_item_t *p_item;
1339 for (NSUInteger i = 0; i < count; i++) {
1340 o_item = [o_outline_view itemAtRow: indexes[i]];
1341 p_item = (playlist_item_t *)[o_item pointerValue];
1343 if( ![[o_outline_view dataSource] outlineView: o_outline_view isItemExpandable: o_item] )
1344 o_item = [o_outline_dict objectForKey: [NSString stringWithFormat: @"%p", p_item->p_parent]];
1346 /* We need to collapse the node first, since OSX refuses to recursively
1347 expand an already expanded node, even if children nodes are collapsed. */
1348 [o_outline_view collapseItem: o_item collapseChildren: YES];
1349 [o_outline_view expandItem: o_item expandChildren: YES];
1351 selectedRows = [o_outline_view selectedRowIndexes];
1352 [selectedRows getIndexes:indexes maxCount:count inIndexRange:nil];
1356 - (NSMenu *)menuForEvent:(NSEvent *)o_event
1362 pt = [o_outline_view convertPoint: [o_event locationInWindow] fromView: nil];
1363 int row = [o_outline_view rowAtPoint:pt];
1364 if( row != -1 && ![[o_outline_view selectedRowIndexes] containsIndex: row] )
1365 [o_outline_view selectRowIndexes:[NSIndexSet indexSetWithIndex:row] byExtendingSelection:NO];
1367 b_item_sel = ( row != -1 && [o_outline_view selectedRow] != -1 );
1368 b_rows = [o_outline_view numberOfRows] != 0;
1370 [o_mi_play setEnabled: b_item_sel];
1371 [o_mi_delete setEnabled: b_item_sel];
1372 [o_mi_selectall setEnabled: b_rows];
1373 [o_mi_info setEnabled: b_item_sel];
1374 [o_mi_preparse setEnabled: b_item_sel];
1375 [o_mi_recursive_expand setEnabled: b_item_sel];
1376 [o_mi_sort_name setEnabled: b_item_sel];
1377 [o_mi_sort_author setEnabled: b_item_sel];
1379 return( o_ctx_menu );
1382 - (void)outlineView: (NSOutlineView *)o_tv didClickTableColumn:(NSTableColumn *)o_tc
1384 int i_mode, i_type = 0;
1385 intf_thread_t *p_intf = VLCIntf;
1386 NSString * o_identifier = [o_tc identifier];
1388 playlist_t *p_playlist = pl_Get( p_intf );
1390 if( [o_identifier isEqualToString:TRACKNUM_COLUMN] )
1391 i_mode = SORT_TRACK_NUMBER;
1392 else if( [o_identifier isEqualToString:TITLE_COLUMN] )
1393 i_mode = SORT_TITLE;
1394 else if( [o_identifier isEqualToString:ARTIST_COLUMN] )
1395 i_mode = SORT_ARTIST;
1396 else if( [o_identifier isEqualToString:GENRE_COLUMN] )
1397 i_mode = SORT_GENRE;
1398 else if( [o_identifier isEqualToString:DURATION_COLUMN] )
1399 i_mode = SORT_DURATION;
1400 else if( [o_identifier isEqualToString:ALBUM_COLUMN] )
1401 i_mode = SORT_ALBUM;
1402 else if( [o_identifier isEqualToString:DESCRIPTION_COLUMN] )
1403 i_mode = SORT_DESCRIPTION;
1404 else if( [o_identifier isEqualToString:URI_COLUMN] )
1409 if( o_tc_sortColumn == o_tc )
1410 b_isSortDescending = !b_isSortDescending;
1412 b_isSortDescending = false;
1414 if( b_isSortDescending )
1415 i_type = ORDER_REVERSE;
1417 i_type = ORDER_NORMAL;
1420 playlist_RecursiveNodeSort( p_playlist, [self currentPlaylistRoot], i_mode, i_type );
1423 [self playlistUpdated];
1425 o_tc_sortColumn = o_tc;
1426 [o_outline_view setHighlightedTableColumn:o_tc];
1428 if( b_isSortDescending )
1429 [o_outline_view setIndicatorImage:o_descendingSortingImage inTableColumn:o_tc];
1431 [o_outline_view setIndicatorImage:o_ascendingSortingImage inTableColumn:o_tc];
1435 - (void)outlineView:(NSOutlineView *)outlineView
1436 willDisplayCell:(id)cell
1437 forTableColumn:(NSTableColumn *)tableColumn
1440 /* this method can be called when VLC is already dead, hence the extra checks */
1441 intf_thread_t * p_intf = VLCIntf;
1444 playlist_t *p_playlist = pl_Get( p_intf );
1451 o_playing_item = [o_outline_dict objectForKey: [NSString stringWithFormat:@"%p", playlist_CurrentPlayingItem( p_playlist )]];
1454 if( [self isItem: [o_playing_item pointerValue] inNode: [item pointerValue] checkItemExistence:YES locked:NO]
1455 || [o_playing_item isEqual: item] )
1457 [cell setFont: [[NSFontManager sharedFontManager] convertFont:[cell font] toHaveTrait:NSBoldFontMask]];
1461 [cell setFont: [[NSFontManager sharedFontManager] convertFont:[cell font] toNotHaveTrait:NSBoldFontMask]];
1467 playlist_t *p_playlist = pl_Get( VLCIntf );
1472 o_playing_item = [o_outline_dict objectForKey: [NSString stringWithFormat:@"%p", playlist_CurrentPlayingItem( p_playlist )]];
1475 return o_playing_item;
1478 - (NSArray *)draggedItems
1480 return [[o_nodes_array arrayByAddingObjectsFromArray: o_items_array] retain];
1483 - (void)setColumn: (NSString *)o_column state: (NSInteger)i_state translationDict:(NSDictionary *)o_dict
1485 NSTableColumn * o_work_tc;
1487 if (i_state == NSOnState)
1489 o_work_tc = [[NSTableColumn alloc] initWithIdentifier: o_column];
1490 [o_work_tc setEditable: NO];
1491 [[o_work_tc dataCell] setFont: [NSFont controlContentFontOfSize:11.]];
1493 [[o_work_tc headerCell] setStringValue: [o_dict objectForKey:o_column]];
1495 if ([o_column isEqualToString: TRACKNUM_COLUMN])
1497 [o_work_tc setWidth: 20.];
1498 [o_work_tc setResizingMask: NSTableColumnNoResizing];
1499 [[o_work_tc headerCell] setStringValue: @"#"];
1502 [o_outline_view addTableColumn: o_work_tc];
1503 [o_work_tc release];
1504 [o_outline_view reloadData];
1505 [o_outline_view setNeedsDisplay: YES];
1508 [o_outline_view removeTableColumn: [o_outline_view tableColumnWithIdentifier: o_column]];
1511 - (void)saveTableColumns
1513 NSMutableArray * o_arrayToSave = [[NSMutableArray alloc] init];
1514 NSArray * o_columns = [[NSArray alloc] initWithArray:[o_outline_view tableColumns]];
1515 NSUInteger count = [o_columns count];
1516 NSTableColumn * o_currentColumn;
1517 for (NSUInteger i = 0; i < count; i++)
1519 o_currentColumn = [o_columns objectAtIndex: i];
1520 [o_arrayToSave addObject: [NSArray arrayWithObjects: [o_currentColumn identifier], [NSNumber numberWithFloat: [o_currentColumn width]], nil]];
1522 [[NSUserDefaults standardUserDefaults] setObject: o_arrayToSave forKey:@"PlaylistColumnSelection"];
1523 [[NSUserDefaults standardUserDefaults] synchronize];
1524 [o_columns release];
1525 [o_arrayToSave release];
1530 @implementation VLCPlaylist (NSOutlineViewDataSource)
1532 - (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item
1534 id o_value = [super outlineView: outlineView child: index ofItem: item];
1536 [o_outline_dict setObject:o_value forKey:[NSString stringWithFormat:@"%p", [o_value pointerValue]]];
1540 /* Required for drag & drop and reordering */
1541 - (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pboard
1543 playlist_t *p_playlist = pl_Get( VLCIntf );
1545 /* First remove the items that were moved during the last drag & drop
1547 [o_items_array removeAllObjects];
1548 [o_nodes_array removeAllObjects];
1550 NSUInteger itemCount = [items count];
1552 for( NSUInteger i = 0 ; i < itemCount ; i++ )
1554 id o_item = [items objectAtIndex: i];
1556 /* Fill the items and nodes to move in 2 different arrays */
1557 if( ((playlist_item_t *)[o_item pointerValue])->i_children > 0 )
1558 [o_nodes_array addObject: o_item];
1560 [o_items_array addObject: o_item];
1563 /* Now we need to check if there are selected items that are in already
1564 selected nodes. In that case, we only want to move the nodes */
1565 [self removeItemsFrom: o_nodes_array ifChildrenOf: o_nodes_array];
1566 [self removeItemsFrom: o_items_array ifChildrenOf: o_nodes_array];
1568 /* We add the "VLCPlaylistItemPboardType" type to be able to recognize
1569 a Drop operation coming from the playlist. */
1571 [pboard declareTypes: [NSArray arrayWithObjects:
1572 @"VLCPlaylistItemPboardType", nil] owner: self];
1573 [pboard setData:[NSData data] forType:@"VLCPlaylistItemPboardType"];
1578 - (NSDragOperation)outlineView:(NSOutlineView *)outlineView validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(NSInteger)index
1580 playlist_t *p_playlist = pl_Get( VLCIntf );
1581 NSPasteboard *o_pasteboard = [info draggingPasteboard];
1583 if( !p_playlist ) return NSDragOperationNone;
1585 /* Dropping ON items is not allowed if item is not a node */
1588 if( index == NSOutlineViewDropOnItemIndex &&
1589 ((playlist_item_t *)[item pointerValue])->i_children == -1 )
1591 return NSDragOperationNone;
1595 /* We refuse to drop an item in anything else than a child of the General
1596 Node. We still accept items that would be root nodes of the outlineview
1597 however, to allow drop in an empty playlist. */
1598 if( !( ([self isItem: [item pointerValue] inNode: p_playlist->p_local_category checkItemExistence: NO locked: NO] ||
1599 ( var_CreateGetBool( p_playlist, "media-library" ) && [self isItem: [item pointerValue] inNode: p_playlist->p_ml_category checkItemExistence: NO locked: NO] ) ) || item == nil ) )
1601 return NSDragOperationNone;
1604 /* Drop from the Playlist */
1605 if( [[o_pasteboard types] containsObject: @"VLCPlaylistItemPboardType"] )
1607 NSUInteger count = [o_nodes_array count];
1608 for( NSUInteger i = 0 ; i < count ; i++ )
1610 /* We refuse to Drop in a child of an item we are moving */
1611 if( [self isItem: [item pointerValue] inNode: [[o_nodes_array objectAtIndex: i] pointerValue] checkItemExistence: NO locked:NO] )
1613 return NSDragOperationNone;
1616 return NSDragOperationMove;
1619 /* Drop from the Finder */
1620 else if( [[o_pasteboard types] containsObject: NSFilenamesPboardType] )
1622 return NSDragOperationGeneric;
1624 return NSDragOperationNone;
1627 - (BOOL)outlineView:(NSOutlineView *)outlineView acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(NSInteger)index
1629 playlist_t * p_playlist = pl_Get( VLCIntf );
1630 NSPasteboard *o_pasteboard = [info draggingPasteboard];
1632 /* Drag & Drop inside the playlist */
1633 if( [[o_pasteboard types] containsObject: @"VLCPlaylistItemPboardType"] )
1636 playlist_item_t *p_new_parent, *p_item = NULL;
1637 NSArray *o_all_items = [o_nodes_array arrayByAddingObjectsFromArray: o_items_array];
1638 /* If the item is to be dropped as root item of the outline, make it a
1639 child of the respective general node, if is either the pl or the ml
1640 Else, choose the proposed parent as parent. */
1643 if ([self currentPlaylistRoot] == p_playlist->p_local_category || [self currentPlaylistRoot] == p_playlist->p_ml_category)
1644 p_new_parent = [self currentPlaylistRoot];
1649 p_new_parent = [item pointerValue];
1651 /* Make sure the proposed parent is a node.
1652 (This should never be true) */
1653 if( p_new_parent->i_children < 0 )
1658 NSUInteger count = [o_all_items count];
1662 playlist_item_t **pp_items = (playlist_item_t **)calloc( count, sizeof( playlist_item_t* ) );
1668 for( NSUInteger i = 0; i < count; i++ )
1670 p_item = [[o_all_items objectAtIndex:i] pointerValue];
1672 pp_items[j++] = p_item;
1675 if( j == 0 || playlist_TreeMoveMany( p_playlist, j, pp_items, p_new_parent, index ) != VLC_SUCCESS )
1685 [self playlistUpdated];
1686 i_row = [o_outline_view rowForItem:[o_outline_dict objectForKey:[NSString stringWithFormat: @"%p", [[o_all_items objectAtIndex: 0] pointerValue]]]];
1690 i_row = [o_outline_view rowForItem:[o_outline_dict objectForKey:[NSString stringWithFormat: @"%p", p_new_parent]]];
1693 [o_outline_view deselectAll: self];
1694 [o_outline_view selectRowIndexes:[NSIndexSet indexSetWithIndex:i_row] byExtendingSelection:NO];
1695 [o_outline_view scrollRowToVisible: i_row];
1700 else if( [[o_pasteboard types] containsObject: NSFilenamesPboardType] )
1702 if ([self currentPlaylistRoot] != p_playlist->p_local_category && [self currentPlaylistRoot] != p_playlist->p_ml_category)
1705 playlist_item_t *p_node = [item pointerValue];
1707 NSArray *o_values = [[o_pasteboard propertyListForType: NSFilenamesPboardType]
1708 sortedArrayUsingSelector: @selector(caseInsensitiveCompare:)];
1709 NSUInteger count = [o_values count];
1710 NSMutableArray *o_array = [NSMutableArray arrayWithCapacity:count];
1711 input_thread_t * p_input = pl_CurrentInput( VLCIntf );
1712 BOOL b_returned = NO;
1714 if (count == 1 && p_input)
1716 b_returned = input_AddSubtitle( p_input, vlc_path2uri([[o_values objectAtIndex:0] UTF8String], NULL), true );
1717 vlc_object_release( p_input );
1722 vlc_object_release( p_input );
1724 for( NSUInteger i = 0; i < count; i++)
1726 NSDictionary *o_dic;
1727 char *psz_uri = vlc_path2uri([[o_values objectAtIndex:i] UTF8String], NULL);
1731 o_dic = [NSDictionary dictionaryWithObject:[NSString stringWithCString:psz_uri encoding:NSUTF8StringEncoding] forKey:@"ITEM_URL"];
1735 [o_array addObject: o_dic];
1740 [self appendArray:o_array atPos:index enqueue: YES];
1744 assert( p_node->i_children != -1 );
1745 [self appendNodeArray:o_array inNode: p_node atPos:index enqueue:YES];