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
30 * create a new 'tool' button (see the gear button in the Finder window) for 'actions'
31 (adding service discovery, other views, new node/playlist, save node/playlist) stuff like that
35 /*****************************************************************************
37 *****************************************************************************/
38 #include <stdlib.h> /* malloc(), free() */
39 #include <sys/param.h> /* for MAXPATHLEN */
42 #include <sys/mount.h>
47 #import "playlistinfo.h"
54 #import <vlc_services_discovery.h>
56 #import <vlc_interface.h>
61 /*****************************************************************************
62 * VLCPlaylistView implementation
63 *****************************************************************************/
64 @implementation VLCPlaylistView
66 - (NSMenu *)menuForEvent:(NSEvent *)o_event
68 return( [(VLCPlaylist *)[self delegate] menuForEvent: o_event] );
71 - (void)keyDown:(NSEvent *)o_event
75 if( [[o_event characters] length] )
77 key = [[o_event characters] characterAtIndex: 0];
82 case NSDeleteCharacter:
83 case NSDeleteFunctionKey:
84 case NSDeleteCharFunctionKey:
85 case NSBackspaceCharacter:
86 [(VLCPlaylist *)[self delegate] deleteItem:self];
89 case NSEnterCharacter:
90 case NSCarriageReturnCharacter:
91 [(VLCPlaylist *)[[VLCMain sharedInstance] playlist] playItem:self];
95 [super keyDown: o_event];
100 - (BOOL)validateMenuItem:(NSMenuItem *)item
102 if (([self numberOfSelectedRows] >= 1 && [item action] == @selector(delete:)) || [item action] == @selector(selectAll:))
108 - (BOOL) acceptsFirstResponder
113 - (BOOL) becomeFirstResponder
115 [self setNeedsDisplay:YES];
119 - (BOOL) resignFirstResponder
121 [self setNeedsDisplay:YES];
125 - (IBAction)delete:(id)sender
127 [[[VLCMain sharedInstance] playlist] deleteItem: sender];
132 /*****************************************************************************
133 * VLCPlaylistCommon implementation
135 * This class the superclass of the VLCPlaylist and VLCPlaylistWizard.
136 * It contains the common methods and elements of these 2 entities.
137 *****************************************************************************/
138 @implementation VLCPlaylistCommon
142 playlist_t * p_playlist = pl_Get( VLCIntf );
143 p_current_root_item = p_playlist->p_local_category;
148 o_outline_dict = [[NSMutableDictionary alloc] init];
155 playlist_t * p_playlist = pl_Get( VLCIntf );
156 [o_outline_view setTarget: self];
157 [o_outline_view setDelegate: self];
158 [o_outline_view setDataSource: self];
159 [o_outline_view setAllowsEmptySelection: NO];
160 [o_outline_view expandItem: [o_outline_view itemAtRow:0]];
162 [o_outline_view_other setTarget: self];
163 [o_outline_view_other setDelegate: self];
164 [o_outline_view_other setDataSource: self];
165 [o_outline_view_other setAllowsEmptySelection: NO];
172 [[o_tc_name headerCell] setStringValue:_NS("Name")];
173 [[o_tc_author headerCell] setStringValue:_NS("Author")];
174 [[o_tc_duration headerCell] setStringValue:_NS("Duration")];
176 [[o_tc_name_other headerCell] setStringValue:_NS("Name")];
177 [[o_tc_author_other headerCell] setStringValue:_NS("Author")];
178 [[o_tc_duration_other headerCell] setStringValue:_NS("Duration")];
181 - (void)setPlaylistRoot: (playlist_item_t *)root_item
183 p_current_root_item = root_item;
184 [o_outline_view reloadData];
185 [o_outline_view_other reloadData];
188 - (playlist_item_t *)currentPlaylistRoot
190 return p_current_root_item;
193 - (void)swapPlaylists:(id)newList
195 if(newList != o_outline_view)
197 id o_outline_view_temp = o_outline_view;
198 id o_tc_author_temp = o_tc_author;
199 id o_tc_duration_temp = o_tc_duration;
200 id o_tc_name_temp = o_tc_name;
201 o_outline_view = o_outline_view_other;
202 o_tc_author = o_tc_author_other;
203 o_tc_duration = o_tc_duration_other;
204 o_tc_name = o_tc_name_other;
205 o_outline_view_other = o_outline_view_temp;
206 o_tc_author_other = o_tc_author_temp;
207 o_tc_duration_other = o_tc_duration_temp;
208 o_tc_name_other = o_tc_name_temp;
212 - (NSOutlineView *)outlineView
214 return o_outline_view;
217 - (playlist_item_t *)selectedPlaylistItem
219 return [[o_outline_view itemAtRow: [o_outline_view selectedRow]]
225 @implementation VLCPlaylistCommon (NSOutlineViewDataSource)
226 /* return the number of children for Obj-C pointer item */ /* DONE */
227 - (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
230 playlist_item_t *p_item = NULL;
231 playlist_t * p_playlist = pl_Get( VLCIntf );
232 //assert( outlineView == o_outline_view );
237 p_item = p_current_root_item;
240 p_item = (playlist_item_t *)[item pointerValue];
243 i_return = p_item->i_children;
246 return i_return > 0 ? i_return : 0;
249 /* return the child at index for the Obj-C pointer item */ /* DONE */
250 - (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item
252 playlist_item_t *p_return = NULL, *p_item = NULL;
254 playlist_t * p_playlist = pl_Get( VLCIntf );
260 p_item = p_current_root_item;
264 p_item = (playlist_item_t *)[item pointerValue];
266 if( p_item && index < p_item->i_children && index >= 0 )
267 p_return = p_item->pp_children[index];
270 o_value = [o_outline_dict objectForKey:[NSString stringWithFormat: @"%p", p_return]];
274 /* FIXME: Why is there a warning if that happens all the time and seems
275 * to be normal? Add an assert and fix it.
276 * msg_Warn( VLCIntf, "playlist item misses pointer value, adding one" ); */
277 o_value = [[NSValue valueWithPointer: p_return] retain];
282 /* is the item expandable */
283 - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item
286 playlist_t *p_playlist = pl_Get( VLCIntf );
292 if( p_current_root_item )
294 i_return = p_current_root_item->i_children;
299 playlist_item_t *p_item = (playlist_item_t *)[item pointerValue];
301 i_return = p_item->i_children;
305 return (i_return >= 0);
308 /* retrieve the string values for the cells */
309 - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)o_tc byItem:(id)item
312 playlist_item_t *p_item;
314 /* For error handling */
315 static BOOL attempted_reload = NO;
317 if( item == nil || ![item isKindOfClass: [NSValue class]] )
319 /* Attempt to fix the error by asking for a data redisplay
320 * This might cause infinite loop, so add a small check */
321 if( !attempted_reload )
323 attempted_reload = YES;
324 [outlineView reloadData];
329 p_item = (playlist_item_t *)[item pointerValue];
330 if( !p_item || !p_item->p_input )
332 /* Attempt to fix the error by asking for a data redisplay
333 * This might cause infinite loop, so add a small check */
334 if( !attempted_reload )
336 attempted_reload = YES;
337 [outlineView reloadData];
342 attempted_reload = NO;
344 if( [[o_tc identifier] isEqualToString:@"name"] )
346 /* sanity check to prevent the NSString class from crashing */
347 char *psz_title = input_item_GetTitleFbName( p_item->p_input );
350 o_value = [NSString stringWithUTF8String: psz_title];
354 else if( [[o_tc identifier] isEqualToString:@"artist"] )
356 char *psz_artist = input_item_GetArtist( p_item->p_input );
358 o_value = [NSString stringWithUTF8String: psz_artist];
361 else if( [[o_tc identifier] isEqualToString:@"duration"] )
363 char psz_duration[MSTRTIME_MAX_SIZE];
364 mtime_t dur = input_item_GetDuration( p_item->p_input );
367 secstotimestr( psz_duration, dur/1000000 );
368 o_value = [NSString stringWithUTF8String: psz_duration];
373 else if( [[o_tc identifier] isEqualToString:@"status"] )
375 if( input_item_HasErrorWhenReading( p_item->p_input ) )
377 o_value = [[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode(kAlertCautionIcon)];
378 [o_value setSize: NSMakeSize(16,16)];
386 /*****************************************************************************
387 * VLCPlaylistWizard implementation
388 *****************************************************************************/
389 @implementation VLCPlaylistWizard
391 - (IBAction)reloadOutlineView
393 /* Only reload the outlineview if the wizard window is open since this can
394 be quite long on big playlists */
395 if( [[o_outline_view window] isVisible] )
397 [o_outline_view reloadData];
403 /*****************************************************************************
404 * extension to NSOutlineView's interface to fix compilation warnings
405 * and let us access these 2 functions properly
406 * this uses a private Apple-API, but works fine on all current OSX releases
407 * keep checking for compatiblity with future releases though
408 *****************************************************************************/
410 @interface NSOutlineView (UndocumentedSortImages)
411 + (NSImage *)_defaultTableHeaderSortImage;
412 + (NSImage *)_defaultTableHeaderReverseSortImage;
416 /*****************************************************************************
417 * VLCPlaylist implementation
418 *****************************************************************************/
419 @implementation VLCPlaylist
426 o_nodes_array = [[NSMutableArray alloc] init];
427 o_items_array = [[NSMutableArray alloc] init];
434 [o_nodes_array release];
435 [o_items_array release];
441 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 private Apple API which works fine until 10.5.
461 * We need to keep checking in the future!
462 * These methods are being added artificially to NSOutlineView's interface above */
463 o_ascendingSortingImage = [[NSOutlineView class] _defaultTableHeaderSortImage];
464 o_descendingSortingImage = [[NSOutlineView class] _defaultTableHeaderReverseSortImage];
466 o_tc_sortColumn = nil;
469 char ** ppsz_services = vlc_sd_GetNames( VLCIntf, &ppsz_name, NULL );
473 for( i = 0; ppsz_services[i]; i++ )
478 char * name = ppsz_name[i] ? ppsz_name[i] : ppsz_services[i];
479 /* Check whether to enable these menuitems */
480 b_enabled = playlist_IsServicesDiscoveryLoaded( p_playlist, ppsz_services[i] );
482 /* Create the menu entries used in the playlist menu */
483 o_lmi = [[o_mi_services submenu] addItemWithTitle:
484 [NSString stringWithUTF8String: name]
485 action: @selector(servicesChange:)
487 [o_lmi setTarget: self];
488 [o_lmi setRepresentedObject: [NSString stringWithUTF8String: ppsz_services[i]]];
489 if( b_enabled ) [o_lmi setState: NSOnState];
491 /* Create the menu entries for the main menu */
492 o_lmi = [[o_mm_mi_services submenu] addItemWithTitle:
493 [NSString stringWithUTF8String: name]
494 action: @selector(servicesChange:)
496 [o_lmi setTarget: self];
497 [o_lmi setRepresentedObject: [NSString stringWithUTF8String: ppsz_services[i]]];
498 if( b_enabled ) [o_lmi setState: NSOnState];
500 free( ppsz_services[i] );
501 free( ppsz_name[i] );
503 free( ppsz_services );
508 - (void)searchfieldChanged:(NSNotification *)o_notification
510 [o_search_field setStringValue:[[o_notification object] stringValue]];
517 [o_mi_save_playlist setTitle: _NS("Save Playlist...")];
518 [o_mi_play setTitle: _NS("Play")];
519 [o_mi_delete setTitle: _NS("Delete")];
520 [o_mi_recursive_expand setTitle: _NS("Expand Node")];
521 [o_mi_selectall setTitle: _NS("Select All")];
522 [o_mi_info setTitle: _NS("Media Information...")];
523 [o_mi_dl_cover_art setTitle: _NS("Download Cover Art")];
524 [o_mi_preparse setTitle: _NS("Fetch Meta Data")];
525 [o_mi_revealInFinder setTitle: _NS("Reveal in Finder")];
526 [o_mm_mi_revealInFinder setTitle: _NS("Reveal in Finder")];
527 [[o_mm_mi_revealInFinder menu] setAutoenablesItems: NO];
528 [o_mi_sort_name setTitle: _NS("Sort Node by Name")];
529 [o_mi_sort_author setTitle: _NS("Sort Node by Author")];
530 [o_mi_services setTitle: _NS("Services discovery")];
531 [o_mm_mi_services setTitle: _NS("Services discovery")];
533 [o_search_field setToolTip: _NS("Search in Playlist")];
534 [o_search_field_other setToolTip: _NS("Search in Playlist")];
536 [o_save_accessory_text setStringValue: _NS("File Format:")];
537 [[o_save_accessory_popup itemAtIndex:0] setTitle: _NS("Extended M3U")];
538 [[o_save_accessory_popup itemAtIndex:1] setTitle: _NS("XML Shareable Playlist Format (XSPF)")];
539 [[o_save_accessory_popup itemAtIndex:2] setTitle: _NS("HTML Playlist")];
542 - (void)swapPlaylists:(id)newList
544 if(newList != o_outline_view)
546 id o_search_field_temp = o_search_field;
547 o_search_field = o_search_field_other;
548 o_search_field_other = o_search_field_temp;
549 [super swapPlaylists:newList];
550 [self playlistUpdated];
554 - (void)playlistUpdated
556 /* Clear indications of any existing column sorting */
557 NSUInteger count = [[o_outline_view tableColumns] count];
558 for( NSUInteger i = 0 ; i < count ; i++ )
560 [o_outline_view setIndicatorImage:nil inTableColumn:
561 [[o_outline_view tableColumns] objectAtIndex:i]];
564 [o_outline_view setHighlightedTableColumn:nil];
565 o_tc_sortColumn = nil;
566 // TODO Find a way to keep the dict size to a minimum
567 //[o_outline_dict removeAllObjects];
568 [o_outline_view reloadData];
569 [[[[VLCMain sharedInstance] wizard] playlistWizard] reloadOutlineView];
570 [[[[VLCMain sharedInstance] bookmarks] dataTable] reloadData];
572 [self outlineViewSelectionDidChange: nil];
573 [[VLCMain sharedInstance] updateMainWindow];
576 - (void)outlineViewSelectionDidChange:(NSNotification *)notification
579 playlist_item_t * p_item = [[o_outline_view itemAtRow:[o_outline_view selectedRow]] pointerValue];
583 /* update the state of our Reveal-in-Finder menu items */
584 NSMutableString *o_mrl;
585 char *psz_uri = input_item_GetURI( p_item->p_input );
587 [o_mi_revealInFinder setEnabled: NO];
588 [o_mm_mi_revealInFinder setEnabled: NO];
591 o_mrl = [NSMutableString stringWithUTF8String: psz_uri];
593 /* perform some checks whether it is a file and if it is local at all... */
594 NSRange prefix_range = [o_mrl rangeOfString: @"file:"];
595 if( prefix_range.location != NSNotFound )
596 [o_mrl deleteCharactersInRange: prefix_range];
598 if( [o_mrl characterAtIndex:0] == '/' )
600 [o_mi_revealInFinder setEnabled: YES];
601 [o_mm_mi_revealInFinder setEnabled: YES];
606 /* update our info-panel to reflect the new item */
607 [[[VLCMain sharedInstance] info] updatePanelWithItem:p_item->p_input];
611 - (BOOL)isSelectionEmpty
613 return [o_outline_view selectedRow] == -1;
616 - (void)updateRowSelection
619 playlist_t *p_playlist = pl_Get( VLCIntf );
620 playlist_item_t *p_item, *p_temp_item;
621 NSMutableArray *o_array = [NSMutableArray array];
624 p_item = playlist_CurrentPlayingItem( p_playlist );
631 p_temp_item = p_item;
632 while( p_temp_item->p_parent )
634 [o_array insertObject: [NSValue valueWithPointer: p_temp_item] atIndex: 0];
635 p_temp_item = p_temp_item->p_parent;
639 NSUInteger count = [o_array count];
640 for( NSUInteger j = 0; j < count - 1; j++ )
643 if( ( o_item = [o_outline_dict objectForKey:
644 [NSString stringWithFormat: @"%p",
645 [[o_array objectAtIndex:j] pointerValue]]] ) != nil )
647 [o_outline_view expandItem: o_item];
651 id o_item = [o_outline_dict objectForKey:[NSString stringWithFormat: @"%p", p_item]];
652 NSInteger i_index = [o_outline_view rowForItem:o_item];
653 [o_outline_view selectRowIndexes:[NSIndexSet indexSetWithIndex:i_index] byExtendingSelection:NO];
654 [o_outline_view setNeedsDisplay:YES];
657 /* Check if p_item is a child of p_node recursively. We need to check the item
658 existence first since OSX sometimes tries to redraw items that have been
659 deleted. We don't do it when not required since this verification takes
660 quite a long time on big playlists (yes, pretty hacky). */
662 - (BOOL)isItem: (playlist_item_t *)p_item
663 inNode: (playlist_item_t *)p_node
664 checkItemExistence:(BOOL)b_check
665 locked:(BOOL)b_locked
668 playlist_t * p_playlist = pl_Get( VLCIntf );
669 playlist_item_t *p_temp_item = p_item;
671 if( p_node == p_item )
674 if( p_node->i_children < 1)
680 if(!b_locked) PL_LOCK;
684 /* Since outlineView: willDisplayCell:... may call this function with
685 p_items that don't exist anymore, first check if the item is still
686 in the playlist. Any cleaner solution welcomed. */
687 for( i = 0; i < p_playlist->all_items.i_size; i++ )
689 if( ARRAY_VAL( p_playlist->all_items, i) == p_item ) break;
690 else if ( i == p_playlist->all_items.i_size - 1 )
692 if(!b_locked) PL_UNLOCK;
700 p_temp_item = p_temp_item->p_parent;
701 if( p_temp_item == p_node )
703 if(!b_locked) PL_UNLOCK;
707 if(!b_locked) PL_UNLOCK;
712 - (BOOL)isItem: (playlist_item_t *)p_item
713 inNode: (playlist_item_t *)p_node
714 checkItemExistence:(BOOL)b_check
716 return [self isItem:p_item inNode:p_node checkItemExistence:b_check locked:NO];
719 /* This method is useful for instance to remove the selected children of an
720 already selected node */
721 - (void)removeItemsFrom:(id)o_items ifChildrenOf:(id)o_nodes
723 NSUInteger itemCount = [o_items count];
724 NSUInteger nodeCount = [o_nodes count];
725 for( NSUInteger i = 0 ; i < itemCount ; i++ )
727 for ( NSUInteger j = 0 ; j < nodeCount ; j++ )
729 if( o_items == o_nodes)
731 if( j == i ) continue;
733 if( [self isItem: [[o_items objectAtIndex:i] pointerValue]
734 inNode: [[o_nodes objectAtIndex:j] pointerValue]
735 checkItemExistence: NO locked:NO] )
737 [o_items removeObjectAtIndex:i];
738 /* We need to execute the next iteration with the same index
739 since the current item has been deleted */
747 - (IBAction)savePlaylist:(id)sender
749 playlist_t * p_playlist = pl_Get( VLCIntf );
751 NSSavePanel *o_save_panel = [NSSavePanel savePanel];
752 NSString * o_name = [NSString stringWithFormat: @"%@", _NS("Untitled")];
754 [o_save_panel setTitle: _NS("Save Playlist")];
755 [o_save_panel setPrompt: _NS("Save")];
756 [o_save_panel setAccessoryView: o_save_accessory_view];
758 if( [o_save_panel runModalForDirectory: nil
759 file: o_name] == NSOKButton )
761 NSString *o_filename = [[o_save_panel URL] path];
763 if( [o_save_accessory_popup indexOfSelectedItem] == 0 )
765 NSString * o_real_filename;
767 range.location = [o_filename length] - [@".m3u" length];
768 range.length = [@".m3u" length];
770 if( [o_filename compare:@".m3u" options: NSCaseInsensitiveSearch
771 range: range] != NSOrderedSame )
773 o_real_filename = [NSString stringWithFormat: @"%@.m3u", o_filename];
777 o_real_filename = o_filename;
779 playlist_Export( p_playlist,
780 [o_real_filename fileSystemRepresentation],
781 p_playlist->p_local_category, "export-m3u" );
783 else if( [o_save_accessory_popup indexOfSelectedItem] == 1 )
785 NSString * o_real_filename;
787 range.location = [o_filename length] - [@".xspf" length];
788 range.length = [@".xspf" length];
790 if( [o_filename compare:@".xspf" options: NSCaseInsensitiveSearch
791 range: range] != NSOrderedSame )
793 o_real_filename = [NSString stringWithFormat: @"%@.xspf", o_filename];
797 o_real_filename = o_filename;
799 playlist_Export( p_playlist,
800 [o_real_filename fileSystemRepresentation],
801 p_playlist->p_local_category, "export-xspf" );
805 NSString * o_real_filename;
807 range.location = [o_filename length] - [@".html" length];
808 range.length = [@".html" length];
810 if( [o_filename compare:@".html" options: NSCaseInsensitiveSearch
811 range: range] != NSOrderedSame )
813 o_real_filename = [NSString stringWithFormat: @"%@.html", o_filename];
817 o_real_filename = o_filename;
819 playlist_Export( p_playlist,
820 [o_real_filename fileSystemRepresentation],
821 p_playlist->p_local_category, "export-html" );
826 /* When called retrieves the selected outlineview row and plays that node or item */
827 - (IBAction)playItem:(id)sender
829 intf_thread_t * p_intf = VLCIntf;
830 playlist_t * p_playlist = pl_Get( p_intf );
832 playlist_item_t *p_item;
833 playlist_item_t *p_node = NULL;
835 p_item = [[o_outline_view itemAtRow:[o_outline_view selectedRow]] pointerValue];
840 if( p_item->i_children == -1 )
842 p_node = p_item->p_parent;
847 if( p_node->i_children > 0 && p_node->pp_children[0]->i_children == -1 )
849 p_item = p_node->pp_children[0];
856 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, pl_Locked, p_node, p_item );
861 - (IBAction)revealItemInFinder:(id)sender
863 playlist_item_t * p_item = [[o_outline_view itemAtRow:[o_outline_view selectedRow]] pointerValue];
864 NSMutableString * o_mrl = nil;
866 if(! p_item || !p_item->p_input )
869 char *psz_uri = decode_URI( input_item_GetURI( p_item->p_input ) );
871 o_mrl = [NSMutableString stringWithUTF8String: psz_uri];
873 /* perform some checks whether it is a file and if it is local at all... */
874 NSRange prefix_range = [o_mrl rangeOfString: @"file:"];
875 if( prefix_range.location != NSNotFound )
876 [o_mrl deleteCharactersInRange: prefix_range];
878 if( [o_mrl characterAtIndex:0] == '/' )
879 [[NSWorkspace sharedWorkspace] selectFile: o_mrl inFileViewerRootedAtPath: o_mrl];
882 /* When called retrieves the selected outlineview row and plays that node or item */
883 - (IBAction)preparseItem:(id)sender
886 NSIndexSet *o_selected_indexes;
887 intf_thread_t * p_intf = VLCIntf;
888 playlist_t * p_playlist = pl_Get( p_intf );
889 playlist_item_t *p_item = NULL;
891 o_selected_indexes = [o_outline_view selectedRowIndexes];
892 i_count = [o_selected_indexes count];
894 NSUInteger indexes[i_count];
895 [o_selected_indexes getIndexes:indexes maxCount:i_count inIndexRange:nil];
896 for (int i = 0; i < i_count; i++)
898 p_item = [[o_outline_view itemAtRow:indexes[i]] pointerValue];
899 [o_outline_view deselectRow: indexes[i]];
903 if( p_item->i_children == -1 )
904 playlist_PreparseEnqueue( p_playlist, p_item->p_input );
906 msg_Dbg( p_intf, "preparsing nodes not implemented" );
909 [self playlistUpdated];
912 - (IBAction)downloadCoverArt:(id)sender
915 NSIndexSet *o_selected_indexes;
916 intf_thread_t * p_intf = VLCIntf;
917 playlist_t * p_playlist = pl_Get( p_intf );
918 playlist_item_t *p_item = NULL;
920 o_selected_indexes = [o_outline_view selectedRowIndexes];
921 i_count = [o_selected_indexes count];
923 NSUInteger indexes[i_count];
924 [o_selected_indexes getIndexes:indexes maxCount:i_count inIndexRange:nil];
925 for (int i = 0; i < i_count; i++)
927 p_item = [[o_outline_view itemAtRow: indexes[i]] pointerValue];
928 [o_outline_view deselectRow: indexes[i]];
930 if( p_item && p_item->i_children == -1 )
931 playlist_AskForArtEnqueue( p_playlist, p_item->p_input );
933 [self playlistUpdated];
936 - (IBAction)servicesChange:(id)sender
938 NSMenuItem *o_mi = (NSMenuItem *)sender;
939 NSString *o_string = [o_mi representedObject];
940 playlist_t * p_playlist = pl_Get( VLCIntf );
941 if( !playlist_IsServicesDiscoveryLoaded( p_playlist, [o_string UTF8String] ) )
942 playlist_ServicesDiscoveryAdd( p_playlist, [o_string UTF8String] );
944 playlist_ServicesDiscoveryRemove( p_playlist, [o_string UTF8String] );
946 [o_mi setState: playlist_IsServicesDiscoveryLoaded( p_playlist,
947 [o_string UTF8String] ) ? YES : NO];
949 [self playlistUpdated];
953 - (IBAction)selectAll:(id)sender
955 [o_outline_view selectAll: nil];
958 - (IBAction)deleteItem:(id)sender
961 NSIndexSet *o_selected_indexes;
962 playlist_t * p_playlist;
963 intf_thread_t * p_intf = VLCIntf;
965 o_selected_indexes = [o_outline_view selectedRowIndexes];
966 i_count = [o_selected_indexes count];
968 p_playlist = pl_Get( p_intf );
970 NSUInteger indexes[i_count];
971 if (i_count == [o_outline_view numberOfRows])
974 msg_Dbg( p_intf, "user selected entire list, deleting current playlist root instead of individual items" );
977 playlist_NodeDelete( p_playlist, [self currentPlaylistRoot], true, false );
979 [self playlistUpdated];
982 [o_selected_indexes getIndexes:indexes maxCount:i_count inIndexRange:nil];
983 for (int i = 0; i < i_count; i++)
985 id o_item = [o_outline_view itemAtRow: indexes[i]];
986 [o_outline_view deselectRow: indexes[i]];
989 playlist_item_t *p_item = [o_item pointerValue];
991 msg_Dbg( p_intf, "deleting item %i (of %i) with id \"%i\", pointerValue \"%p\" and %i children", i+1, i_count,
992 p_item->p_input->i_id, [o_item pointerValue], p_item->i_children +1 );
995 if( p_item->i_children != -1 )
996 //is a node and not an item
998 if( playlist_Status( p_playlist ) != PLAYLIST_STOPPED &&
999 [self isItem: playlist_CurrentPlayingItem( p_playlist ) inNode: ((playlist_item_t *)[o_item pointerValue])
1000 checkItemExistence: NO locked:YES] == YES )
1001 // if current item is in selected node and is playing then stop playlist
1002 playlist_Control(p_playlist, PLAYLIST_STOP, pl_Locked );
1004 playlist_NodeDelete( p_playlist, p_item, true, false );
1007 playlist_DeleteFromInput( p_playlist, p_item->p_input, pl_Locked );
1010 [o_outline_dict removeObjectForKey:[NSString stringWithFormat:@"%p", [o_item pointerValue]]];
1014 [self playlistUpdated];
1017 - (IBAction)sortNodeByName:(id)sender
1019 [self sortNode: SORT_TITLE];
1022 - (IBAction)sortNodeByAuthor:(id)sender
1024 [self sortNode: SORT_ARTIST];
1027 - (void)sortNode:(int)i_mode
1029 playlist_t * p_playlist = pl_Get( VLCIntf );
1030 playlist_item_t * p_item;
1032 if( [o_outline_view selectedRow] > -1 )
1034 p_item = [[o_outline_view itemAtRow: [o_outline_view selectedRow]] pointerValue];
1037 /*If no item is selected, sort the whole playlist*/
1039 p_item = [self currentPlaylistRoot];
1043 if( p_item->i_children > -1 ) // the item is a node
1045 playlist_RecursiveNodeSort( p_playlist, p_item, i_mode, ORDER_NORMAL );
1049 playlist_RecursiveNodeSort( p_playlist,
1050 p_item->p_parent, i_mode, ORDER_NORMAL );
1053 [self playlistUpdated];
1056 - (input_item_t *)createItem:(NSDictionary *)o_one_item
1058 intf_thread_t * p_intf = VLCIntf;
1059 playlist_t * p_playlist = pl_Get( p_intf );
1061 input_item_t *p_input;
1062 BOOL b_rem = FALSE, b_dir = FALSE, b_writable = FALSE;
1063 NSString *o_uri, *o_name, *o_path;
1069 o_uri = (NSString *)[o_one_item objectForKey: @"ITEM_URL"];
1070 o_nsurl = [NSURL URLWithString: o_uri];
1071 o_path = [o_nsurl path];
1072 o_name = (NSString *)[o_one_item objectForKey: @"ITEM_NAME"];
1073 o_options = (NSArray *)[o_one_item objectForKey: @"ITEM_OPTIONS"];
1075 if( [[NSFileManager defaultManager] fileExistsAtPath:o_path isDirectory:&b_dir] && b_dir &&
1076 [[NSWorkspace sharedWorkspace] getFileSystemInfoForPath:o_path isRemovable: &b_rem
1077 isWritable:&b_writable isUnmountable:NULL description:NULL type:NULL] && b_rem && !b_writable && [o_nsurl isFileURL] )
1080 id o_vlc_open = [[VLCMain sharedInstance] open];
1082 char *diskType = [o_vlc_open getVolumeTypeFromMountPath: o_path];
1083 msg_Dbg( p_intf, "detected optical media of type '%s' in the file input", diskType );
1085 if (diskType == kVLCMediaDVD)
1087 o_uri = [NSString stringWithFormat: @"dvdnav://%@", [o_vlc_open getBSDNodeFromMountPath: o_path]];
1089 else if (diskType == kVLCMediaVideoTSFolder)
1091 o_uri = [NSString stringWithFormat: @"dvdnav://%@", o_path];
1093 else if (diskType == kVLCMediaAudioCD)
1095 o_uri = [NSString stringWithFormat: @"cdda://%@", [o_vlc_open getBSDNodeFromMountPath: o_path]];
1097 else if (diskType == kVLCMediaVCD)
1099 o_uri = [NSString stringWithFormat: @"vcd://%@#0:0", [o_vlc_open getBSDNodeFromMountPath: o_path]];
1101 else if (diskType == kVLCMediaSVCD)
1103 o_uri = [NSString stringWithFormat: @"vcd://%@@0:0", [o_vlc_open getBSDNodeFromMountPath: o_path]];
1105 else if (diskType == kVLCMediaBD || diskType == kVLCMediaBDMVFolder)
1107 o_uri = [NSString stringWithFormat: @"bluray://%@", o_path];
1111 msg_Warn( VLCIntf, "unknown disk type, treating %s as regular input", [o_path UTF8String] );
1114 p_input = input_item_New( [o_uri UTF8String], [[[NSFileManager defaultManager] displayNameAtPath: o_path] UTF8String] );
1117 p_input = input_item_New( [o_uri fileSystemRepresentation], o_name ? [o_name UTF8String] : NULL );
1124 NSUInteger count = [o_options count];
1125 for( NSUInteger i = 0; i < count; i++ )
1127 input_item_AddOption( p_input, [[o_options objectAtIndex:i] UTF8String],
1128 VLC_INPUT_OPTION_TRUSTED );
1132 /* Recent documents menu */
1133 if( o_nsurl != nil && (BOOL)config_GetInt( p_playlist, "macosx-recentitems" ) == YES )
1135 [[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL: o_nsurl];
1140 - (void)appendArray:(NSArray*)o_array atPos:(int)i_position enqueue:(BOOL)b_enqueue
1142 playlist_t * p_playlist = pl_Get( VLCIntf );
1143 NSUInteger count = [o_array count];
1144 BOOL b_usingPlaylist;
1145 if ([self currentPlaylistRoot] == p_playlist->p_ml_category)
1146 b_usingPlaylist = NO;
1148 b_usingPlaylist = YES;
1151 for( NSUInteger i_item = 0; i_item < count; i_item++ )
1153 input_item_t *p_input;
1154 NSDictionary *o_one_item;
1157 o_one_item = [o_array objectAtIndex: i_item];
1158 p_input = [self createItem: o_one_item];
1165 /* FIXME: playlist_AddInput() can fail */
1167 playlist_AddInput( p_playlist, p_input, PLAYLIST_INSERT, i_position == -1 ? PLAYLIST_END : i_position + i_item, b_usingPlaylist,
1170 if( i_item == 0 && !b_enqueue )
1172 playlist_item_t *p_item = playlist_ItemGetByInput( p_playlist, p_input );
1173 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, pl_Locked, p_item->p_parent, p_item );
1176 vlc_gc_decref( p_input );
1179 [self playlistUpdated];
1182 - (void)appendNodeArray:(NSArray*)o_array inNode:(playlist_item_t *)p_node atPos:(int)i_position enqueue:(BOOL)b_enqueue
1184 playlist_t * p_playlist = pl_Get( VLCIntf );
1185 NSUInteger count = [o_array count];
1187 for( NSUInteger i_item = 0; i_item < count; i_item++ )
1189 input_item_t *p_input;
1190 NSDictionary *o_one_item;
1193 o_one_item = [o_array objectAtIndex: i_item];
1194 p_input = [self createItem: o_one_item];
1196 if( !p_input ) continue;
1200 playlist_NodeAddInput( p_playlist, p_input, p_node,
1203 PLAYLIST_END : i_position + i_item,
1207 if( i_item == 0 && !b_enqueue )
1209 playlist_item_t *p_item;
1210 p_item = playlist_ItemGetByInput( p_playlist, p_input );
1211 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, pl_Locked, p_node, p_item );
1214 vlc_gc_decref( p_input );
1216 [self playlistUpdated];
1219 - (NSMutableArray *)subSearchItem:(playlist_item_t *)p_item
1221 playlist_t *p_playlist = pl_Get( VLCIntf );
1222 playlist_item_t *p_selected_item;
1225 i_selected_row = [o_outline_view selectedRow];
1226 if (i_selected_row < 0)
1229 p_selected_item = (playlist_item_t *)[[o_outline_view itemAtRow: i_selected_row] pointerValue];
1231 for( NSUInteger i_current = 0; i_current < p_item->i_children ; i_current++ )
1234 NSString *o_current_name, *o_current_author;
1237 o_current_name = [NSString stringWithUTF8String:
1238 p_item->pp_children[i_current]->p_input->psz_name];
1239 psz_temp = input_item_GetInfo( p_item->p_input ,
1240 _("Meta-information"),_("Artist") );
1241 o_current_author = [NSString stringWithUTF8String: psz_temp];
1245 if( p_selected_item == p_item->pp_children[i_current] &&
1246 b_selected_item_met == NO )
1248 b_selected_item_met = YES;
1250 else if( p_selected_item == p_item->pp_children[i_current] &&
1251 b_selected_item_met == YES )
1255 else if( b_selected_item_met == YES &&
1256 ( [o_current_name rangeOfString:[o_search_field
1257 stringValue] options:NSCaseInsensitiveSearch].length ||
1258 [o_current_author rangeOfString:[o_search_field
1259 stringValue] options:NSCaseInsensitiveSearch].length ) )
1261 /*Adds the parent items in the result array as well, so that we can
1263 return [NSMutableArray arrayWithObject: [NSValue
1264 valueWithPointer: p_item->pp_children[i_current]]];
1266 if( p_item->pp_children[i_current]->i_children > 0 )
1268 id o_result = [self subSearchItem:
1269 p_item->pp_children[i_current]];
1270 if( o_result != NULL )
1272 [o_result insertObject: [NSValue valueWithPointer:
1273 p_item->pp_children[i_current]] atIndex:0];
1281 - (IBAction)searchItem:(id)sender
1283 playlist_t * p_playlist = pl_Get( VLCIntf );
1288 b_selected_item_met = NO;
1290 /*First, only search after the selected item:*
1291 *(b_selected_item_met = NO) */
1292 o_result = [self subSearchItem:[self currentPlaylistRoot]];
1293 if( o_result == NULL )
1295 /* If the first search failed, search again from the beginning */
1296 o_result = [self subSearchItem:[self currentPlaylistRoot]];
1298 if( o_result != NULL )
1301 if( [[o_result objectAtIndex: 0] pointerValue] == p_playlist->p_local_category )
1305 NSUInteger count = [o_result count];
1307 for( NSUInteger i = i_start ; i < count - 1 ; i++ )
1309 [o_outline_view expandItem: [o_outline_dict objectForKey:
1310 [NSString stringWithFormat: @"%p",
1311 [[o_result objectAtIndex: i] pointerValue]]]];
1313 i_row = [o_outline_view rowForItem: [o_outline_dict objectForKey:
1314 [NSString stringWithFormat: @"%p",
1315 [[o_result objectAtIndex: count - 1 ]
1320 [o_outline_view selectRowIndexes:[NSIndexSet indexSetWithIndex:i_row] byExtendingSelection:NO];
1321 [o_outline_view scrollRowToVisible: i_row];
1325 - (IBAction)recursiveExpandNode:(id)sender
1327 id o_item = [o_outline_view itemAtRow: [o_outline_view selectedRow]];
1328 playlist_item_t *p_item = (playlist_item_t *)[o_item pointerValue];
1330 if( ![[o_outline_view dataSource] outlineView: o_outline_view
1331 isItemExpandable: o_item] )
1333 o_item = [o_outline_dict objectForKey: [NSString stringWithFormat: @"%p", p_item->p_parent]];
1336 /* We need to collapse the node first, since OSX refuses to recursively
1337 expand an already expanded node, even if children nodes are collapsed. */
1338 [o_outline_view collapseItem: o_item collapseChildren: YES];
1339 [o_outline_view expandItem: o_item expandChildren: YES];
1342 - (NSMenu *)menuForEvent:(NSEvent *)o_event
1348 pt = [o_outline_view convertPoint: [o_event locationInWindow]
1350 int row = [o_outline_view rowAtPoint:pt];
1352 [o_outline_view selectRowIndexes:[NSIndexSet indexSetWithIndex:row] byExtendingSelection:NO];
1354 b_item_sel = ( row != -1 && [o_outline_view selectedRow] != -1 );
1355 b_rows = [o_outline_view numberOfRows] != 0;
1357 [o_mi_play setEnabled: b_item_sel];
1358 [o_mi_delete setEnabled: b_item_sel];
1359 [o_mi_selectall setEnabled: b_rows];
1360 [o_mi_info setEnabled: b_item_sel];
1361 [o_mi_preparse setEnabled: b_item_sel];
1362 [o_mi_recursive_expand setEnabled: b_item_sel];
1363 [o_mi_sort_name setEnabled: b_item_sel];
1364 [o_mi_sort_author setEnabled: b_item_sel];
1366 return( o_ctx_menu );
1369 - (void)outlineView: (NSOutlineView *)o_tv
1370 didClickTableColumn:(NSTableColumn *)o_tc
1372 int i_mode, i_type = 0;
1373 intf_thread_t *p_intf = VLCIntf;
1375 playlist_t *p_playlist = pl_Get( p_intf );
1377 /* Check whether the selected table column header corresponds to a
1378 sortable table column*/
1379 if( !( o_tc == o_tc_name || o_tc == o_tc_author ) )
1384 if( o_tc_sortColumn == o_tc )
1386 b_isSortDescending = !b_isSortDescending;
1390 b_isSortDescending = false;
1393 if( o_tc == o_tc_name )
1395 i_mode = SORT_TITLE;
1397 else if( o_tc == o_tc_author )
1399 i_mode = SORT_ARTIST;
1402 if( b_isSortDescending )
1404 i_type = ORDER_REVERSE;
1408 i_type = ORDER_NORMAL;
1412 playlist_RecursiveNodeSort( p_playlist, [self currentPlaylistRoot], i_mode, i_type );
1415 [self playlistUpdated];
1417 o_tc_sortColumn = o_tc;
1418 [o_outline_view setHighlightedTableColumn:o_tc];
1420 if( b_isSortDescending )
1422 [o_outline_view setIndicatorImage:o_descendingSortingImage
1423 inTableColumn:o_tc];
1427 [o_outline_view setIndicatorImage:o_ascendingSortingImage
1428 inTableColumn:o_tc];
1433 - (void)outlineView:(NSOutlineView *)outlineView
1434 willDisplayCell:(id)cell
1435 forTableColumn:(NSTableColumn *)tableColumn
1438 /* this method can be called when VLC is already dead, hence the extra checks */
1439 intf_thread_t * p_intf = VLCIntf;
1442 playlist_t *p_playlist = pl_Get( p_intf );
1449 o_playing_item = [o_outline_dict objectForKey: [NSString stringWithFormat:@"%p", playlist_CurrentPlayingItem( p_playlist )]];
1452 if( [self isItem: [o_playing_item pointerValue] inNode:
1453 [item pointerValue] checkItemExistence: YES]
1454 || [o_playing_item isEqual: item] )
1456 [cell setFont: [[NSFontManager sharedFontManager] convertFont:[cell font] toHaveTrait:NSBoldFontMask]];
1460 [cell setFont: [[NSFontManager sharedFontManager] convertFont:[cell font] toNotHaveTrait:NSBoldFontMask]];
1466 playlist_t *p_playlist = pl_Get( VLCIntf );
1471 o_playing_item = [o_outline_dict objectForKey: [NSString stringWithFormat:@"%p", playlist_CurrentPlayingItem( p_playlist )]];
1474 return o_playing_item;
1477 - (NSArray *)draggedItems
1479 return [[o_nodes_array arrayByAddingObjectsFromArray: o_items_array] retain];
1483 @implementation VLCPlaylist (NSOutlineViewDataSource)
1485 - (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item
1487 id o_value = [super outlineView: outlineView child: index ofItem: item];
1489 [o_outline_dict setObject:o_value forKey:[NSString stringWithFormat:@"%p", [o_value pointerValue]]];
1493 /* Required for drag & drop and reordering */
1494 - (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pboard
1496 playlist_t *p_playlist = pl_Get( VLCIntf );
1498 /* First remove the items that were moved during the last drag & drop
1500 [o_items_array removeAllObjects];
1501 [o_nodes_array removeAllObjects];
1503 NSUInteger itemCount = [items count];
1505 for( NSUInteger i = 0 ; i < itemCount ; i++ )
1507 id o_item = [items objectAtIndex: i];
1509 /* Fill the items and nodes to move in 2 different arrays */
1510 if( ((playlist_item_t *)[o_item pointerValue])->i_children > 0 )
1511 [o_nodes_array addObject: o_item];
1513 [o_items_array addObject: o_item];
1516 /* Now we need to check if there are selected items that are in already
1517 selected nodes. In that case, we only want to move the nodes */
1518 [self removeItemsFrom: o_nodes_array ifChildrenOf: o_nodes_array];
1519 [self removeItemsFrom: o_items_array ifChildrenOf: o_nodes_array];
1521 /* We add the "VLCPlaylistItemPboardType" type to be able to recognize
1522 a Drop operation coming from the playlist. */
1524 [pboard declareTypes: [NSArray arrayWithObjects:
1525 @"VLCPlaylistItemPboardType", nil] owner: self];
1526 [pboard setData:[NSData data] forType:@"VLCPlaylistItemPboardType"];
1531 - (NSDragOperation)outlineView:(NSOutlineView *)outlineView validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(NSInteger)index
1533 playlist_t *p_playlist = pl_Get( VLCIntf );
1534 NSPasteboard *o_pasteboard = [info draggingPasteboard];
1536 if( !p_playlist ) return NSDragOperationNone;
1538 /* Dropping ON items is not allowed if item is not a node */
1541 if( index == NSOutlineViewDropOnItemIndex &&
1542 ((playlist_item_t *)[item pointerValue])->i_children == -1 )
1544 return NSDragOperationNone;
1548 /* We refuse to drop an item in anything else than a child of the General
1549 Node. We still accept items that would be root nodes of the outlineview
1550 however, to allow drop in an empty playlist. */
1551 if( !( ([self isItem: [item pointerValue] inNode: p_playlist->p_local_category checkItemExistence: NO] ||
1552 ( var_CreateGetBool( p_playlist, "media-library" ) && [self isItem: [item pointerValue] inNode: p_playlist->p_ml_category checkItemExistence: NO] ) ) || item == nil ) )
1554 return NSDragOperationNone;
1557 /* Drop from the Playlist */
1558 if( [[o_pasteboard types] containsObject: @"VLCPlaylistItemPboardType"] )
1560 NSUInteger count = [o_nodes_array count];
1561 for( NSUInteger i = 0 ; i < count ; i++ )
1563 /* We refuse to Drop in a child of an item we are moving */
1564 if( [self isItem: [item pointerValue] inNode:
1565 [[o_nodes_array objectAtIndex: i] pointerValue]
1566 checkItemExistence: NO] )
1568 return NSDragOperationNone;
1571 return NSDragOperationMove;
1574 /* Drop from the Finder */
1575 else if( [[o_pasteboard types] containsObject: NSFilenamesPboardType] )
1577 return NSDragOperationGeneric;
1579 return NSDragOperationNone;
1582 - (BOOL)outlineView:(NSOutlineView *)outlineView acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(NSInteger)index
1584 playlist_t * p_playlist = pl_Get( VLCIntf );
1585 NSPasteboard *o_pasteboard = [info draggingPasteboard];
1587 /* Drag & Drop inside the playlist */
1588 if( [[o_pasteboard types] containsObject: @"VLCPlaylistItemPboardType"] )
1590 int i_row, i_removed_from_node = 0;
1591 playlist_item_t *p_new_parent, *p_item = NULL;
1592 NSArray *o_all_items = [o_nodes_array arrayByAddingObjectsFromArray: o_items_array];
1593 /* If the item is to be dropped as root item of the outline, make it a
1594 child of the respective general node, if is either the pl or the ml
1595 Else, choose the proposed parent as parent. */
1598 if ([self currentPlaylistRoot] == p_playlist->p_local_category || [self currentPlaylistRoot] == p_playlist->p_ml_category)
1599 p_new_parent = [self currentPlaylistRoot];
1604 p_new_parent = [item pointerValue];
1606 /* Make sure the proposed parent is a node.
1607 (This should never be true) */
1608 if( p_new_parent->i_children < 0 )
1613 NSUInteger count = [o_all_items count];
1614 for( NSUInteger i = 0; i < count; i++ )
1616 playlist_item_t *p_old_parent = NULL;
1617 int i_old_index = 0;
1619 p_item = [[o_all_items objectAtIndex:i] pointerValue];
1620 p_old_parent = p_item->p_parent;
1623 /* We may need the old index later */
1624 if( p_new_parent == p_old_parent )
1626 for( NSInteger j = 0; j < p_old_parent->i_children; j++ )
1628 if( p_old_parent->pp_children[j] == p_item )
1637 // Actually detach the item from the old position
1638 if( playlist_NodeRemoveItem( p_playlist, p_item, p_old_parent ) ==
1642 /* Calculate the new index */
1645 /* If we move the item in the same node, we need to take into
1646 account that one item will be deleted */
1649 if ((p_new_parent == p_old_parent && i_old_index < index + (int)i) )
1651 i_removed_from_node++;
1653 i_new_index = index + i - i_removed_from_node;
1655 // Reattach the item to the new position
1656 playlist_NodeInsert( p_playlist, p_item, p_new_parent, i_new_index );
1660 [self playlistUpdated];
1661 i_row = [o_outline_view rowForItem:[o_outline_dict objectForKey:[NSString stringWithFormat: @"%p", [[o_all_items objectAtIndex: 0] pointerValue]]]];
1665 i_row = [o_outline_view rowForItem:[o_outline_dict objectForKey:[NSString stringWithFormat: @"%p", p_new_parent]]];
1668 [o_outline_view deselectAll: self];
1669 [o_outline_view selectRowIndexes:[NSIndexSet indexSetWithIndex:i_row] byExtendingSelection:NO];
1670 [o_outline_view scrollRowToVisible: i_row];
1675 else if( [[o_pasteboard types] containsObject: NSFilenamesPboardType] )
1677 if ([self currentPlaylistRoot] != p_playlist->p_local_category && [self currentPlaylistRoot] != p_playlist->p_ml_category)
1680 playlist_item_t *p_node = [item pointerValue];
1682 NSArray *o_values = [[o_pasteboard propertyListForType: NSFilenamesPboardType]
1683 sortedArrayUsingSelector: @selector(caseInsensitiveCompare:)];
1684 NSUInteger count = [o_values count];
1685 NSMutableArray *o_array = [NSMutableArray arrayWithCapacity:count];
1686 input_thread_t * p_input = pl_CurrentInput( VLCIntf );
1687 BOOL b_returned = NO;
1689 if (count == 1 && p_input)
1691 b_returned = input_AddSubtitle( p_input, make_URI([[o_values objectAtIndex:0] UTF8String], NULL), true );
1692 vlc_object_release( p_input );
1697 vlc_object_release( p_input );
1699 for( NSUInteger i = 0; i < count; i++)
1701 NSDictionary *o_dic;
1702 char *psz_uri = make_URI([[o_values objectAtIndex:i] UTF8String], NULL);
1706 o_dic = [NSDictionary dictionaryWithObject:[NSString stringWithCString:psz_uri encoding:NSUTF8StringEncoding] forKey:@"ITEM_URL"];
1710 [o_array addObject: o_dic];
1715 [self appendArray:o_array atPos:index enqueue: YES];
1719 assert( p_node->i_children != -1 );
1720 [self appendNodeArray:o_array inNode: p_node atPos:index enqueue:YES];