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];
102 /*****************************************************************************
103 * VLCPlaylistCommon implementation
105 * This class the superclass of the VLCPlaylist and VLCPlaylistWizard.
106 * It contains the common methods and elements of these 2 entities.
107 *****************************************************************************/
108 @implementation VLCPlaylistCommon
112 playlist_t * p_playlist = pl_Get( VLCIntf );
113 p_current_root_item = p_playlist->p_local_category;
118 o_outline_dict = [[NSMutableDictionary alloc] init];
125 playlist_t * p_playlist = pl_Get( VLCIntf );
126 [o_outline_view setTarget: self];
127 [o_outline_view setDelegate: self];
128 [o_outline_view setDataSource: self];
129 [o_outline_view setAllowsEmptySelection: NO];
130 [o_outline_view expandItem: [o_outline_view itemAtRow:0]];
132 [o_outline_view_other setTarget: self];
133 [o_outline_view_other setDelegate: self];
134 [o_outline_view_other setDataSource: self];
135 [o_outline_view_other setAllowsEmptySelection: NO];
142 [[o_tc_name headerCell] setStringValue:_NS("Name")];
143 [[o_tc_author headerCell] setStringValue:_NS("Author")];
144 [[o_tc_duration headerCell] setStringValue:_NS("Duration")];
146 [[o_tc_name_other headerCell] setStringValue:_NS("Name")];
147 [[o_tc_author_other headerCell] setStringValue:_NS("Author")];
148 [[o_tc_duration_other headerCell] setStringValue:_NS("Duration")];
151 - (void)setPlaylistRoot: (playlist_item_t *)root_item
153 p_current_root_item = root_item;
154 [o_outline_view reloadData];
155 [o_outline_view_other reloadData];
158 - (playlist_item_t *)currentPlaylistRoot
160 return p_current_root_item;
163 - (void)swapPlaylists:(id)newList
165 if(newList != o_outline_view)
167 id o_outline_view_temp = o_outline_view;
168 id o_tc_author_temp = o_tc_author;
169 id o_tc_duration_temp = o_tc_duration;
170 id o_tc_name_temp = o_tc_name;
171 o_outline_view = o_outline_view_other;
172 o_tc_author = o_tc_author_other;
173 o_tc_duration = o_tc_duration_other;
174 o_tc_name = o_tc_name_other;
175 o_outline_view_other = o_outline_view_temp;
176 o_tc_author_other = o_tc_author_temp;
177 o_tc_duration_other = o_tc_duration_temp;
178 o_tc_name_other = o_tc_name_temp;
182 - (NSOutlineView *)outlineView
184 return o_outline_view;
187 - (playlist_item_t *)selectedPlaylistItem
189 return [[o_outline_view itemAtRow: [o_outline_view selectedRow]]
195 @implementation VLCPlaylistCommon (NSOutlineViewDataSource)
196 /* return the number of children for Obj-C pointer item */ /* DONE */
197 - (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
200 playlist_item_t *p_item = NULL;
201 playlist_t * p_playlist = pl_Get( VLCIntf );
202 //assert( outlineView == o_outline_view );
207 p_item = p_current_root_item;
210 p_item = (playlist_item_t *)[item pointerValue];
213 i_return = p_item->i_children;
216 return i_return > 0 ? i_return : 0;
219 /* return the child at index for the Obj-C pointer item */ /* DONE */
220 - (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item
222 playlist_item_t *p_return = NULL, *p_item = NULL;
224 playlist_t * p_playlist = pl_Get( VLCIntf );
230 p_item = p_current_root_item;
234 p_item = (playlist_item_t *)[item pointerValue];
236 if( p_item && index < p_item->i_children && index >= 0 )
237 p_return = p_item->pp_children[index];
240 o_value = [o_outline_dict objectForKey:[NSString stringWithFormat: @"%p", p_return]];
244 /* FIXME: Why is there a warning if that happens all the time and seems
245 * to be normal? Add an assert and fix it.
246 * msg_Warn( VLCIntf, "playlist item misses pointer value, adding one" ); */
247 o_value = [[NSValue valueWithPointer: p_return] retain];
252 /* is the item expandable */
253 - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item
256 playlist_t *p_playlist = pl_Get( VLCIntf );
262 if( p_current_root_item )
264 i_return = p_current_root_item->i_children;
269 playlist_item_t *p_item = (playlist_item_t *)[item pointerValue];
271 i_return = p_item->i_children;
275 return (i_return >= 0);
278 /* retrieve the string values for the cells */
279 - (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;
314 if( [[o_tc identifier] isEqualToString:@"name"] )
316 /* sanity check to prevent the NSString class from crashing */
317 char *psz_title = input_item_GetTitleFbName( p_item->p_input );
320 o_value = [NSString stringWithUTF8String: psz_title];
324 else if( [[o_tc identifier] isEqualToString:@"artist"] )
326 char *psz_artist = input_item_GetArtist( p_item->p_input );
328 o_value = [NSString stringWithUTF8String: psz_artist];
331 else if( [[o_tc identifier] isEqualToString:@"duration"] )
333 char psz_duration[MSTRTIME_MAX_SIZE];
334 mtime_t dur = input_item_GetDuration( p_item->p_input );
337 secstotimestr( psz_duration, dur/1000000 );
338 o_value = [NSString stringWithUTF8String: psz_duration];
343 else if( [[o_tc identifier] isEqualToString:@"status"] )
345 if( input_item_HasErrorWhenReading( p_item->p_input ) )
347 o_value = [[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode(kAlertCautionIcon)];
348 [o_value setSize: NSMakeSize(16,16)];
356 /*****************************************************************************
357 * VLCPlaylistWizard implementation
358 *****************************************************************************/
359 @implementation VLCPlaylistWizard
361 - (IBAction)reloadOutlineView
363 /* Only reload the outlineview if the wizard window is open since this can
364 be quite long on big playlists */
365 if( [[o_outline_view window] isVisible] )
367 [o_outline_view reloadData];
373 /*****************************************************************************
374 * extension to NSOutlineView's interface to fix compilation warnings
375 * and let us access these 2 functions properly
376 * this uses a private Apple-API, but works fine on all current OSX releases
377 * keep checking for compatiblity with future releases though
378 *****************************************************************************/
380 @interface NSOutlineView (UndocumentedSortImages)
381 + (NSImage *)_defaultTableHeaderSortImage;
382 + (NSImage *)_defaultTableHeaderReverseSortImage;
386 /*****************************************************************************
387 * VLCPlaylist implementation
388 *****************************************************************************/
389 @implementation VLCPlaylist
396 o_nodes_array = [[NSMutableArray alloc] init];
397 o_items_array = [[NSMutableArray alloc] init];
404 [o_nodes_array release];
405 [o_items_array release];
411 playlist_t * p_playlist = pl_Get( VLCIntf );
415 [super awakeFromNib];
417 [o_outline_view setDoubleAction: @selector(playItem:)];
418 [o_outline_view_other setDoubleAction: @selector(playItem:)];
420 [o_outline_view registerForDraggedTypes:
421 [NSArray arrayWithObjects: NSFilenamesPboardType,
422 @"VLCPlaylistItemPboardType", nil]];
423 [o_outline_view setIntercellSpacing: NSMakeSize (0.0, 1.0)];
425 [o_outline_view_other registerForDraggedTypes:
426 [NSArray arrayWithObjects: NSFilenamesPboardType,
427 @"VLCPlaylistItemPboardType", nil]];
428 [o_outline_view_other setIntercellSpacing: NSMakeSize (0.0, 1.0)];
430 /* This uses private Apple API which works fine until 10.5.
431 * We need to keep checking in the future!
432 * These methods are being added artificially to NSOutlineView's interface above */
433 o_ascendingSortingImage = [[NSOutlineView class] _defaultTableHeaderSortImage];
434 o_descendingSortingImage = [[NSOutlineView class] _defaultTableHeaderReverseSortImage];
436 o_tc_sortColumn = nil;
439 char ** ppsz_services = vlc_sd_GetNames( VLCIntf, &ppsz_name, NULL );
443 for( i = 0; ppsz_services[i]; i++ )
448 char * name = ppsz_name[i] ? ppsz_name[i] : ppsz_services[i];
449 /* Check whether to enable these menuitems */
450 b_enabled = playlist_IsServicesDiscoveryLoaded( p_playlist, ppsz_services[i] );
452 /* Create the menu entries used in the playlist menu */
453 o_lmi = [[o_mi_services submenu] addItemWithTitle:
454 [NSString stringWithUTF8String: name]
455 action: @selector(servicesChange:)
457 [o_lmi setTarget: self];
458 [o_lmi setRepresentedObject: [NSString stringWithUTF8String: ppsz_services[i]]];
459 if( b_enabled ) [o_lmi setState: NSOnState];
461 /* Create the menu entries for the main menu */
462 o_lmi = [[o_mm_mi_services submenu] addItemWithTitle:
463 [NSString stringWithUTF8String: name]
464 action: @selector(servicesChange:)
466 [o_lmi setTarget: self];
467 [o_lmi setRepresentedObject: [NSString stringWithUTF8String: ppsz_services[i]]];
468 if( b_enabled ) [o_lmi setState: NSOnState];
470 free( ppsz_services[i] );
471 free( ppsz_name[i] );
473 free( ppsz_services );
478 - (void)searchfieldChanged:(NSNotification *)o_notification
480 [o_search_field setStringValue:[[o_notification object] stringValue]];
487 [o_mi_save_playlist setTitle: _NS("Save Playlist...")];
488 [o_mi_play setTitle: _NS("Play")];
489 [o_mi_delete setTitle: _NS("Delete")];
490 [o_mi_recursive_expand setTitle: _NS("Expand Node")];
491 [o_mi_selectall setTitle: _NS("Select All")];
492 [o_mi_info setTitle: _NS("Media Information...")];
493 [o_mi_dl_cover_art setTitle: _NS("Download Cover Art")];
494 [o_mi_preparse setTitle: _NS("Fetch Meta Data")];
495 [o_mi_revealInFinder setTitle: _NS("Reveal in Finder")];
496 [o_mm_mi_revealInFinder setTitle: _NS("Reveal in Finder")];
497 [[o_mm_mi_revealInFinder menu] setAutoenablesItems: NO];
498 [o_mi_sort_name setTitle: _NS("Sort Node by Name")];
499 [o_mi_sort_author setTitle: _NS("Sort Node by Author")];
500 [o_mi_services setTitle: _NS("Services discovery")];
501 [o_mm_mi_services setTitle: _NS("Services discovery")];
503 [o_search_field setToolTip: _NS("Search in Playlist")];
504 [o_search_field_other setToolTip: _NS("Search in Playlist")];
506 [o_save_accessory_text setStringValue: _NS("File Format:")];
507 [[o_save_accessory_popup itemAtIndex:0] setTitle: _NS("Extended M3U")];
508 [[o_save_accessory_popup itemAtIndex:1] setTitle: _NS("XML Shareable Playlist Format (XSPF)")];
509 [[o_save_accessory_popup itemAtIndex:2] setTitle: _NS("HTML Playlist")];
512 - (void)swapPlaylists:(id)newList
514 if(newList != o_outline_view)
516 id o_search_field_temp = o_search_field;
517 o_search_field = o_search_field_other;
518 o_search_field_other = o_search_field_temp;
519 [super swapPlaylists:newList];
520 [self playlistUpdated];
524 - (void)playlistUpdated
526 /* Clear indications of any existing column sorting */
527 NSUInteger count = [[o_outline_view tableColumns] count];
528 for( NSUInteger i = 0 ; i < count ; i++ )
530 [o_outline_view setIndicatorImage:nil inTableColumn:
531 [[o_outline_view tableColumns] objectAtIndex:i]];
534 [o_outline_view setHighlightedTableColumn:nil];
535 o_tc_sortColumn = nil;
536 // TODO Find a way to keep the dict size to a minimum
537 //[o_outline_dict removeAllObjects];
538 [o_outline_view reloadData];
539 [[[[VLCMain sharedInstance] wizard] playlistWizard] reloadOutlineView];
540 [[[[VLCMain sharedInstance] bookmarks] dataTable] reloadData];
542 [self outlineViewSelectionDidChange: nil];
543 [[VLCMain sharedInstance] updateMainWindow];
546 - (void)outlineViewSelectionDidChange:(NSNotification *)notification
549 playlist_item_t * p_item = [[o_outline_view itemAtRow:[o_outline_view selectedRow]] pointerValue];
553 /* update the state of our Reveal-in-Finder menu items */
554 NSMutableString *o_mrl;
555 char *psz_uri = input_item_GetURI( p_item->p_input );
557 [o_mi_revealInFinder setEnabled: NO];
558 [o_mm_mi_revealInFinder setEnabled: NO];
561 o_mrl = [NSMutableString stringWithUTF8String: psz_uri];
563 /* perform some checks whether it is a file and if it is local at all... */
564 NSRange prefix_range = [o_mrl rangeOfString: @"file:"];
565 if( prefix_range.location != NSNotFound )
566 [o_mrl deleteCharactersInRange: prefix_range];
568 if( [o_mrl characterAtIndex:0] == '/' )
570 [o_mi_revealInFinder setEnabled: YES];
571 [o_mm_mi_revealInFinder setEnabled: YES];
576 /* update our info-panel to reflect the new item */
577 [[[VLCMain sharedInstance] info] updatePanelWithItem:p_item->p_input];
581 - (BOOL)isSelectionEmpty
583 return [o_outline_view selectedRow] == -1;
586 - (void)updateRowSelection
589 playlist_t *p_playlist = pl_Get( VLCIntf );
590 playlist_item_t *p_item, *p_temp_item;
591 NSMutableArray *o_array = [NSMutableArray array];
594 p_item = playlist_CurrentPlayingItem( p_playlist );
601 p_temp_item = p_item;
602 while( p_temp_item->p_parent )
604 [o_array insertObject: [NSValue valueWithPointer: p_temp_item] atIndex: 0];
605 p_temp_item = p_temp_item->p_parent;
609 NSUInteger count = [o_array count];
610 for( NSUInteger j = 0; j < count - 1; j++ )
613 if( ( o_item = [o_outline_dict objectForKey:
614 [NSString stringWithFormat: @"%p",
615 [[o_array objectAtIndex:j] pointerValue]]] ) != nil )
617 [o_outline_view expandItem: o_item];
621 id o_item = [o_outline_dict objectForKey:[NSString stringWithFormat: @"%p", p_item]];
622 NSInteger i_index = [o_outline_view rowForItem:o_item];
623 [o_outline_view selectRowIndexes:[NSIndexSet indexSetWithIndex:i_index] byExtendingSelection:NO];
624 [o_outline_view setNeedsDisplay:YES];
627 /* Check if p_item is a child of p_node recursively. We need to check the item
628 existence first since OSX sometimes tries to redraw items that have been
629 deleted. We don't do it when not required since this verification takes
630 quite a long time on big playlists (yes, pretty hacky). */
632 - (BOOL)isItem: (playlist_item_t *)p_item
633 inNode: (playlist_item_t *)p_node
634 checkItemExistence:(BOOL)b_check
635 locked:(BOOL)b_locked
638 playlist_t * p_playlist = pl_Get( VLCIntf );
639 playlist_item_t *p_temp_item = p_item;
641 if( p_node == p_item )
644 if( p_node->i_children < 1)
650 if(!b_locked) PL_LOCK;
654 /* Since outlineView: willDisplayCell:... may call this function with
655 p_items that don't exist anymore, first check if the item is still
656 in the playlist. Any cleaner solution welcomed. */
657 for( i = 0; i < p_playlist->all_items.i_size; i++ )
659 if( ARRAY_VAL( p_playlist->all_items, i) == p_item ) break;
660 else if ( i == p_playlist->all_items.i_size - 1 )
662 if(!b_locked) PL_UNLOCK;
670 p_temp_item = p_temp_item->p_parent;
671 if( p_temp_item == p_node )
673 if(!b_locked) PL_UNLOCK;
677 if(!b_locked) PL_UNLOCK;
682 - (BOOL)isItem: (playlist_item_t *)p_item
683 inNode: (playlist_item_t *)p_node
684 checkItemExistence:(BOOL)b_check
686 return [self isItem:p_item inNode:p_node checkItemExistence:b_check locked:NO];
689 /* This method is useful for instance to remove the selected children of an
690 already selected node */
691 - (void)removeItemsFrom:(id)o_items ifChildrenOf:(id)o_nodes
693 NSUInteger itemCount = [o_items count];
694 NSUInteger nodeCount = [o_nodes count];
695 for( NSUInteger i = 0 ; i < itemCount ; i++ )
697 for ( NSUInteger j = 0 ; j < nodeCount ; j++ )
699 if( o_items == o_nodes)
701 if( j == i ) continue;
703 if( [self isItem: [[o_items objectAtIndex:i] pointerValue]
704 inNode: [[o_nodes objectAtIndex:j] pointerValue]
705 checkItemExistence: NO locked:NO] )
707 [o_items removeObjectAtIndex:i];
708 /* We need to execute the next iteration with the same index
709 since the current item has been deleted */
717 - (IBAction)savePlaylist:(id)sender
719 playlist_t * p_playlist = pl_Get( VLCIntf );
721 NSSavePanel *o_save_panel = [NSSavePanel savePanel];
722 NSString * o_name = [NSString stringWithFormat: @"%@", _NS("Untitled")];
724 [o_save_panel setTitle: _NS("Save Playlist")];
725 [o_save_panel setPrompt: _NS("Save")];
726 [o_save_panel setAccessoryView: o_save_accessory_view];
728 if( [o_save_panel runModalForDirectory: nil
729 file: o_name] == NSOKButton )
731 NSString *o_filename = [[o_save_panel URL] path];
733 if( [o_save_accessory_popup indexOfSelectedItem] == 0 )
735 NSString * o_real_filename;
737 range.location = [o_filename length] - [@".m3u" length];
738 range.length = [@".m3u" length];
740 if( [o_filename compare:@".m3u" options: NSCaseInsensitiveSearch
741 range: range] != NSOrderedSame )
743 o_real_filename = [NSString stringWithFormat: @"%@.m3u", o_filename];
747 o_real_filename = o_filename;
749 playlist_Export( p_playlist,
750 [o_real_filename fileSystemRepresentation],
751 p_playlist->p_local_category, "export-m3u" );
753 else if( [o_save_accessory_popup indexOfSelectedItem] == 1 )
755 NSString * o_real_filename;
757 range.location = [o_filename length] - [@".xspf" length];
758 range.length = [@".xspf" length];
760 if( [o_filename compare:@".xspf" options: NSCaseInsensitiveSearch
761 range: range] != NSOrderedSame )
763 o_real_filename = [NSString stringWithFormat: @"%@.xspf", o_filename];
767 o_real_filename = o_filename;
769 playlist_Export( p_playlist,
770 [o_real_filename fileSystemRepresentation],
771 p_playlist->p_local_category, "export-xspf" );
775 NSString * o_real_filename;
777 range.location = [o_filename length] - [@".html" length];
778 range.length = [@".html" length];
780 if( [o_filename compare:@".html" options: NSCaseInsensitiveSearch
781 range: range] != NSOrderedSame )
783 o_real_filename = [NSString stringWithFormat: @"%@.html", o_filename];
787 o_real_filename = o_filename;
789 playlist_Export( p_playlist,
790 [o_real_filename fileSystemRepresentation],
791 p_playlist->p_local_category, "export-html" );
796 /* When called retrieves the selected outlineview row and plays that node or item */
797 - (IBAction)playItem:(id)sender
799 intf_thread_t * p_intf = VLCIntf;
800 playlist_t * p_playlist = pl_Get( p_intf );
802 playlist_item_t *p_item;
803 playlist_item_t *p_node = NULL;
805 p_item = [[o_outline_view itemAtRow:[o_outline_view selectedRow]] pointerValue];
810 if( p_item->i_children == -1 )
812 p_node = p_item->p_parent;
817 if( p_node->i_children > 0 && p_node->pp_children[0]->i_children == -1 )
819 p_item = p_node->pp_children[0];
826 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, pl_Locked, p_node, p_item );
831 - (IBAction)revealItemInFinder:(id)sender
833 playlist_item_t * p_item = [[o_outline_view itemAtRow:[o_outline_view selectedRow]] pointerValue];
834 NSMutableString * o_mrl = nil;
836 if(! p_item || !p_item->p_input )
839 char *psz_uri = decode_URI( input_item_GetURI( p_item->p_input ) );
841 o_mrl = [NSMutableString stringWithUTF8String: psz_uri];
843 /* perform some checks whether it is a file and if it is local at all... */
844 NSRange prefix_range = [o_mrl rangeOfString: @"file:"];
845 if( prefix_range.location != NSNotFound )
846 [o_mrl deleteCharactersInRange: prefix_range];
848 if( [o_mrl characterAtIndex:0] == '/' )
849 [[NSWorkspace sharedWorkspace] selectFile: o_mrl inFileViewerRootedAtPath: o_mrl];
852 /* When called retrieves the selected outlineview row and plays that node or item */
853 - (IBAction)preparseItem:(id)sender
856 NSIndexSet *o_selected_indexes;
857 intf_thread_t * p_intf = VLCIntf;
858 playlist_t * p_playlist = pl_Get( p_intf );
859 playlist_item_t *p_item = NULL;
861 o_selected_indexes = [o_outline_view selectedRowIndexes];
862 i_count = [o_selected_indexes count];
864 NSUInteger indexes[i_count];
865 [o_selected_indexes getIndexes:indexes maxCount:i_count inIndexRange:nil];
866 for (int i = 0; i < i_count; i++)
868 p_item = [[o_outline_view itemAtRow:indexes[i]] pointerValue];
869 [o_outline_view deselectRow: indexes[i]];
873 if( p_item->i_children == -1 )
874 playlist_PreparseEnqueue( p_playlist, p_item->p_input );
876 msg_Dbg( p_intf, "preparsing nodes not implemented" );
879 [self playlistUpdated];
882 - (IBAction)downloadCoverArt:(id)sender
885 NSIndexSet *o_selected_indexes;
886 intf_thread_t * p_intf = VLCIntf;
887 playlist_t * p_playlist = pl_Get( p_intf );
888 playlist_item_t *p_item = NULL;
890 o_selected_indexes = [o_outline_view selectedRowIndexes];
891 i_count = [o_selected_indexes count];
893 NSUInteger indexes[i_count];
894 [o_selected_indexes getIndexes:indexes maxCount:i_count inIndexRange:nil];
895 for (int i = 0; i < i_count; i++)
897 p_item = [[o_outline_view itemAtRow: indexes[i]] pointerValue];
898 [o_outline_view deselectRow: indexes[i]];
900 if( p_item && p_item->i_children == -1 )
901 playlist_AskForArtEnqueue( p_playlist, p_item->p_input );
903 [self playlistUpdated];
906 - (IBAction)servicesChange:(id)sender
908 NSMenuItem *o_mi = (NSMenuItem *)sender;
909 NSString *o_string = [o_mi representedObject];
910 playlist_t * p_playlist = pl_Get( VLCIntf );
911 if( !playlist_IsServicesDiscoveryLoaded( p_playlist, [o_string UTF8String] ) )
912 playlist_ServicesDiscoveryAdd( p_playlist, [o_string UTF8String] );
914 playlist_ServicesDiscoveryRemove( p_playlist, [o_string UTF8String] );
916 [o_mi setState: playlist_IsServicesDiscoveryLoaded( p_playlist,
917 [o_string UTF8String] ) ? YES : NO];
919 [self playlistUpdated];
923 - (IBAction)selectAll:(id)sender
925 [o_outline_view selectAll: nil];
928 - (IBAction)deleteItem:(id)sender
931 NSIndexSet *o_selected_indexes;
932 playlist_t * p_playlist;
933 intf_thread_t * p_intf = VLCIntf;
935 o_selected_indexes = [o_outline_view selectedRowIndexes];
936 i_count = [o_selected_indexes count];
938 p_playlist = pl_Get( p_intf );
940 NSUInteger indexes[i_count];
941 if (i_count == [o_outline_view numberOfRows])
944 msg_Dbg( p_intf, "user selected entire list, deleting current playlist root instead of individual items" );
947 playlist_NodeDelete( p_playlist, [self currentPlaylistRoot], true, false );
949 [self playlistUpdated];
952 [o_selected_indexes getIndexes:indexes maxCount:i_count inIndexRange:nil];
953 for (int i = 0; i < i_count; i++)
955 id o_item = [o_outline_view itemAtRow: indexes[i]];
956 [o_outline_view deselectRow: indexes[i]];
959 playlist_item_t *p_item = [o_item pointerValue];
961 msg_Dbg( p_intf, "deleting item %i (of %i) with id \"%i\", pointerValue \"%p\" and %i children", i+1, i_count,
962 p_item->p_input->i_id, [o_item pointerValue], p_item->i_children +1 );
965 if( p_item->i_children != -1 )
966 //is a node and not an item
968 if( playlist_Status( p_playlist ) != PLAYLIST_STOPPED &&
969 [self isItem: playlist_CurrentPlayingItem( p_playlist ) inNode: ((playlist_item_t *)[o_item pointerValue])
970 checkItemExistence: NO locked:YES] == YES )
971 // if current item is in selected node and is playing then stop playlist
972 playlist_Control(p_playlist, PLAYLIST_STOP, pl_Locked );
974 playlist_NodeDelete( p_playlist, p_item, true, false );
977 playlist_DeleteFromInput( p_playlist, p_item->p_input, pl_Locked );
980 [o_outline_dict removeObjectForKey:[NSString stringWithFormat:@"%p", [o_item pointerValue]]];
984 [self playlistUpdated];
987 - (IBAction)sortNodeByName:(id)sender
989 [self sortNode: SORT_TITLE];
992 - (IBAction)sortNodeByAuthor:(id)sender
994 [self sortNode: SORT_ARTIST];
997 - (void)sortNode:(int)i_mode
999 playlist_t * p_playlist = pl_Get( VLCIntf );
1000 playlist_item_t * p_item;
1002 if( [o_outline_view selectedRow] > -1 )
1004 p_item = [[o_outline_view itemAtRow: [o_outline_view selectedRow]] pointerValue];
1007 /*If no item is selected, sort the whole playlist*/
1009 p_item = [self currentPlaylistRoot];
1013 if( p_item->i_children > -1 ) // the item is a node
1015 playlist_RecursiveNodeSort( p_playlist, p_item, i_mode, ORDER_NORMAL );
1019 playlist_RecursiveNodeSort( p_playlist,
1020 p_item->p_parent, i_mode, ORDER_NORMAL );
1023 [self playlistUpdated];
1026 - (input_item_t *)createItem:(NSDictionary *)o_one_item
1028 intf_thread_t * p_intf = VLCIntf;
1029 playlist_t * p_playlist = pl_Get( p_intf );
1031 input_item_t *p_input;
1032 BOOL b_rem = FALSE, b_dir = FALSE, b_writable = FALSE;
1033 NSString *o_uri, *o_name, *o_path;
1039 o_uri = (NSString *)[o_one_item objectForKey: @"ITEM_URL"];
1040 o_nsurl = [NSURL URLWithString: o_uri];
1041 o_path = [o_nsurl path];
1042 o_name = (NSString *)[o_one_item objectForKey: @"ITEM_NAME"];
1043 o_options = (NSArray *)[o_one_item objectForKey: @"ITEM_OPTIONS"];
1045 if( [[NSFileManager defaultManager] fileExistsAtPath:o_path isDirectory:&b_dir] && b_dir &&
1046 [[NSWorkspace sharedWorkspace] getFileSystemInfoForPath:o_path isRemovable: &b_rem
1047 isWritable:&b_writable isUnmountable:NULL description:NULL type:NULL] && b_rem && !b_writable && [o_nsurl isFileURL] )
1050 id o_vlc_open = [[VLCMain sharedInstance] open];
1052 char *diskType = [o_vlc_open getVolumeTypeFromMountPath: o_path];
1053 msg_Dbg( p_intf, "detected optical media of type '%s' in the file input", diskType );
1055 if (diskType == kVLCMediaDVD)
1057 o_uri = [NSString stringWithFormat: @"dvdnav://%@", [o_vlc_open getBSDNodeFromMountPath: o_path]];
1059 else if (diskType == kVLCMediaVideoTSFolder)
1061 o_uri = [NSString stringWithFormat: @"dvdnav://%@", o_path];
1063 else if (diskType == kVLCMediaAudioCD)
1065 o_uri = [NSString stringWithFormat: @"cdda://%@", [o_vlc_open getBSDNodeFromMountPath: o_path]];
1067 else if (diskType == kVLCMediaVCD)
1069 o_uri = [NSString stringWithFormat: @"vcd://%@#0:0", [o_vlc_open getBSDNodeFromMountPath: o_path]];
1071 else if (diskType == kVLCMediaSVCD)
1073 o_uri = [NSString stringWithFormat: @"vcd://%@@0:0", [o_vlc_open getBSDNodeFromMountPath: o_path]];
1075 else if (diskType == kVLCMediaBD || diskType == kVLCMediaBDMVFolder)
1077 o_uri = [NSString stringWithFormat: @"bluray://%@", o_path];
1081 msg_Warn( VLCIntf, "unknown disk type, treating %s as regular input", [o_path UTF8String] );
1084 p_input = input_item_New( [o_uri UTF8String], [[[NSFileManager defaultManager] displayNameAtPath: o_path] UTF8String] );
1087 p_input = input_item_New( [o_uri fileSystemRepresentation], o_name ? [o_name UTF8String] : NULL );
1094 NSUInteger count = [o_options count];
1095 for( NSUInteger i = 0; i < count; i++ )
1097 input_item_AddOption( p_input, [[o_options objectAtIndex:i] UTF8String],
1098 VLC_INPUT_OPTION_TRUSTED );
1102 /* Recent documents menu */
1103 if( o_nsurl != nil && (BOOL)config_GetInt( p_playlist, "macosx-recentitems" ) == YES )
1105 [[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL: o_nsurl];
1110 - (void)appendArray:(NSArray*)o_array atPos:(int)i_position enqueue:(BOOL)b_enqueue
1112 playlist_t * p_playlist = pl_Get( VLCIntf );
1113 NSUInteger count = [o_array count];
1114 BOOL b_usingPlaylist;
1115 if ([self currentPlaylistRoot] == p_playlist->p_ml_category)
1116 b_usingPlaylist = NO;
1118 b_usingPlaylist = YES;
1121 for( NSUInteger i_item = 0; i_item < count; i_item++ )
1123 input_item_t *p_input;
1124 NSDictionary *o_one_item;
1127 o_one_item = [o_array objectAtIndex: i_item];
1128 p_input = [self createItem: o_one_item];
1135 /* FIXME: playlist_AddInput() can fail */
1137 playlist_AddInput( p_playlist, p_input, PLAYLIST_INSERT, i_position == -1 ? PLAYLIST_END : i_position + i_item, b_usingPlaylist,
1140 if( i_item == 0 && !b_enqueue )
1142 playlist_item_t *p_item = playlist_ItemGetByInput( p_playlist, p_input );
1143 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, pl_Locked, p_item->p_parent, p_item );
1146 vlc_gc_decref( p_input );
1149 [self playlistUpdated];
1152 - (void)appendNodeArray:(NSArray*)o_array inNode:(playlist_item_t *)p_node atPos:(int)i_position enqueue:(BOOL)b_enqueue
1154 playlist_t * p_playlist = pl_Get( VLCIntf );
1155 NSUInteger count = [o_array count];
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];
1166 if( !p_input ) continue;
1170 playlist_NodeAddInput( p_playlist, p_input, p_node,
1173 PLAYLIST_END : i_position + i_item,
1177 if( i_item == 0 && !b_enqueue )
1179 playlist_item_t *p_item;
1180 p_item = playlist_ItemGetByInput( p_playlist, p_input );
1181 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, pl_Locked, p_node, p_item );
1184 vlc_gc_decref( p_input );
1186 [self playlistUpdated];
1189 - (NSMutableArray *)subSearchItem:(playlist_item_t *)p_item
1191 playlist_t *p_playlist = pl_Get( VLCIntf );
1192 playlist_item_t *p_selected_item;
1195 i_selected_row = [o_outline_view selectedRow];
1196 if (i_selected_row < 0)
1199 p_selected_item = (playlist_item_t *)[[o_outline_view itemAtRow: i_selected_row] pointerValue];
1201 for( NSUInteger i_current = 0; i_current < p_item->i_children ; i_current++ )
1204 NSString *o_current_name, *o_current_author;
1207 o_current_name = [NSString stringWithUTF8String:
1208 p_item->pp_children[i_current]->p_input->psz_name];
1209 psz_temp = input_item_GetInfo( p_item->p_input ,
1210 _("Meta-information"),_("Artist") );
1211 o_current_author = [NSString stringWithUTF8String: psz_temp];
1215 if( p_selected_item == p_item->pp_children[i_current] &&
1216 b_selected_item_met == NO )
1218 b_selected_item_met = YES;
1220 else if( p_selected_item == p_item->pp_children[i_current] &&
1221 b_selected_item_met == YES )
1225 else if( b_selected_item_met == YES &&
1226 ( [o_current_name rangeOfString:[o_search_field
1227 stringValue] options:NSCaseInsensitiveSearch].length ||
1228 [o_current_author rangeOfString:[o_search_field
1229 stringValue] options:NSCaseInsensitiveSearch].length ) )
1231 /*Adds the parent items in the result array as well, so that we can
1233 return [NSMutableArray arrayWithObject: [NSValue
1234 valueWithPointer: p_item->pp_children[i_current]]];
1236 if( p_item->pp_children[i_current]->i_children > 0 )
1238 id o_result = [self subSearchItem:
1239 p_item->pp_children[i_current]];
1240 if( o_result != NULL )
1242 [o_result insertObject: [NSValue valueWithPointer:
1243 p_item->pp_children[i_current]] atIndex:0];
1251 - (IBAction)searchItem:(id)sender
1253 playlist_t * p_playlist = pl_Get( VLCIntf );
1258 b_selected_item_met = NO;
1260 /*First, only search after the selected item:*
1261 *(b_selected_item_met = NO) */
1262 o_result = [self subSearchItem:[self currentPlaylistRoot]];
1263 if( o_result == NULL )
1265 /* If the first search failed, search again from the beginning */
1266 o_result = [self subSearchItem:[self currentPlaylistRoot]];
1268 if( o_result != NULL )
1271 if( [[o_result objectAtIndex: 0] pointerValue] == p_playlist->p_local_category )
1275 NSUInteger count = [o_result count];
1277 for( NSUInteger i = i_start ; i < count - 1 ; i++ )
1279 [o_outline_view expandItem: [o_outline_dict objectForKey:
1280 [NSString stringWithFormat: @"%p",
1281 [[o_result objectAtIndex: i] pointerValue]]]];
1283 i_row = [o_outline_view rowForItem: [o_outline_dict objectForKey:
1284 [NSString stringWithFormat: @"%p",
1285 [[o_result objectAtIndex: count - 1 ]
1290 [o_outline_view selectRowIndexes:[NSIndexSet indexSetWithIndex:i_row] byExtendingSelection:NO];
1291 [o_outline_view scrollRowToVisible: i_row];
1295 - (IBAction)recursiveExpandNode:(id)sender
1297 id o_item = [o_outline_view itemAtRow: [o_outline_view selectedRow]];
1298 playlist_item_t *p_item = (playlist_item_t *)[o_item pointerValue];
1300 if( ![[o_outline_view dataSource] outlineView: o_outline_view
1301 isItemExpandable: o_item] )
1303 o_item = [o_outline_dict objectForKey: [NSString stringWithFormat: @"%p", p_item->p_parent]];
1306 /* We need to collapse the node first, since OSX refuses to recursively
1307 expand an already expanded node, even if children nodes are collapsed. */
1308 [o_outline_view collapseItem: o_item collapseChildren: YES];
1309 [o_outline_view expandItem: o_item expandChildren: YES];
1312 - (NSMenu *)menuForEvent:(NSEvent *)o_event
1318 pt = [o_outline_view convertPoint: [o_event locationInWindow]
1320 int row = [o_outline_view rowAtPoint:pt];
1322 [o_outline_view selectRowIndexes:[NSIndexSet indexSetWithIndex:row] byExtendingSelection:NO];
1324 b_item_sel = ( row != -1 && [o_outline_view selectedRow] != -1 );
1325 b_rows = [o_outline_view numberOfRows] != 0;
1327 [o_mi_play setEnabled: b_item_sel];
1328 [o_mi_delete setEnabled: b_item_sel];
1329 [o_mi_selectall setEnabled: b_rows];
1330 [o_mi_info setEnabled: b_item_sel];
1331 [o_mi_preparse setEnabled: b_item_sel];
1332 [o_mi_recursive_expand setEnabled: b_item_sel];
1333 [o_mi_sort_name setEnabled: b_item_sel];
1334 [o_mi_sort_author setEnabled: b_item_sel];
1336 return( o_ctx_menu );
1339 - (void)outlineView: (NSOutlineView *)o_tv
1340 didClickTableColumn:(NSTableColumn *)o_tc
1342 int i_mode, i_type = 0;
1343 intf_thread_t *p_intf = VLCIntf;
1345 playlist_t *p_playlist = pl_Get( p_intf );
1347 /* Check whether the selected table column header corresponds to a
1348 sortable table column*/
1349 if( !( o_tc == o_tc_name || o_tc == o_tc_author ) )
1354 if( o_tc_sortColumn == o_tc )
1356 b_isSortDescending = !b_isSortDescending;
1360 b_isSortDescending = false;
1363 if( o_tc == o_tc_name )
1365 i_mode = SORT_TITLE;
1367 else if( o_tc == o_tc_author )
1369 i_mode = SORT_ARTIST;
1372 if( b_isSortDescending )
1374 i_type = ORDER_REVERSE;
1378 i_type = ORDER_NORMAL;
1382 playlist_RecursiveNodeSort( p_playlist, [self currentPlaylistRoot], i_mode, i_type );
1385 [self playlistUpdated];
1387 o_tc_sortColumn = o_tc;
1388 [o_outline_view setHighlightedTableColumn:o_tc];
1390 if( b_isSortDescending )
1392 [o_outline_view setIndicatorImage:o_descendingSortingImage
1393 inTableColumn:o_tc];
1397 [o_outline_view setIndicatorImage:o_ascendingSortingImage
1398 inTableColumn:o_tc];
1403 - (void)outlineView:(NSOutlineView *)outlineView
1404 willDisplayCell:(id)cell
1405 forTableColumn:(NSTableColumn *)tableColumn
1408 /* this method can be called when VLC is already dead, hence the extra checks */
1409 intf_thread_t * p_intf = VLCIntf;
1412 playlist_t *p_playlist = pl_Get( p_intf );
1419 o_playing_item = [o_outline_dict objectForKey: [NSString stringWithFormat:@"%p", playlist_CurrentPlayingItem( p_playlist )]];
1422 if( [self isItem: [o_playing_item pointerValue] inNode:
1423 [item pointerValue] checkItemExistence: YES]
1424 || [o_playing_item isEqual: item] )
1426 [cell setFont: [[NSFontManager sharedFontManager] convertFont:[cell font] toHaveTrait:NSBoldFontMask]];
1430 [cell setFont: [[NSFontManager sharedFontManager] convertFont:[cell font] toNotHaveTrait:NSBoldFontMask]];
1436 playlist_t *p_playlist = pl_Get( VLCIntf );
1441 o_playing_item = [o_outline_dict objectForKey: [NSString stringWithFormat:@"%p", playlist_CurrentPlayingItem( p_playlist )]];
1444 return o_playing_item;
1448 @implementation VLCPlaylist (NSOutlineViewDataSource)
1450 - (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item
1452 id o_value = [super outlineView: outlineView child: index ofItem: item];
1454 [o_outline_dict setObject:o_value forKey:[NSString stringWithFormat:@"%p", [o_value pointerValue]]];
1458 /* Required for drag & drop and reordering */
1459 - (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pboard
1461 playlist_t *p_playlist = pl_Get( VLCIntf );
1463 /* First remove the items that were moved during the last drag & drop
1465 [o_items_array removeAllObjects];
1466 [o_nodes_array removeAllObjects];
1468 NSUInteger itemCount = [items count];
1470 for( NSUInteger i = 0 ; i < itemCount ; i++ )
1472 id o_item = [items objectAtIndex: i];
1474 /* Refuse to move items that are not in the General Node
1475 (Service Discovery) */
1476 if( (![self isItem: [o_item pointerValue] inNode: p_playlist->p_local_category checkItemExistence: NO] &&
1477 var_CreateGetBool( p_playlist, "media-library" ) && ![self isItem: [o_item pointerValue] inNode: p_playlist->p_ml_category checkItemExistence: NO]) ||
1478 [o_item pointerValue] == p_playlist->p_local_category ||
1479 [o_item pointerValue] == p_playlist->p_ml_category )
1483 /* Fill the items and nodes to move in 2 different arrays */
1484 if( ((playlist_item_t *)[o_item pointerValue])->i_children > 0 )
1485 [o_nodes_array addObject: o_item];
1487 [o_items_array addObject: o_item];
1490 /* Now we need to check if there are selected items that are in already
1491 selected nodes. In that case, we only want to move the nodes */
1492 [self removeItemsFrom: o_nodes_array ifChildrenOf: o_nodes_array];
1493 [self removeItemsFrom: o_items_array ifChildrenOf: o_nodes_array];
1495 /* We add the "VLCPlaylistItemPboardType" type to be able to recognize
1496 a Drop operation coming from the playlist. */
1498 [pboard declareTypes: [NSArray arrayWithObjects:
1499 @"VLCPlaylistItemPboardType", nil] owner: self];
1500 [pboard setData:[NSData data] forType:@"VLCPlaylistItemPboardType"];
1505 - (NSDragOperation)outlineView:(NSOutlineView *)outlineView validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(NSInteger)index
1507 playlist_t *p_playlist = pl_Get( VLCIntf );
1508 NSPasteboard *o_pasteboard = [info draggingPasteboard];
1510 if( !p_playlist ) return NSDragOperationNone;
1512 /* Dropping ON items is not allowed if item is not a node */
1515 if( index == NSOutlineViewDropOnItemIndex &&
1516 ((playlist_item_t *)[item pointerValue])->i_children == -1 )
1518 return NSDragOperationNone;
1522 /* We refuse to drop an item in anything else than a child of the General
1523 Node. We still accept items that would be root nodes of the outlineview
1524 however, to allow drop in an empty playlist. */
1525 if( !( ([self isItem: [item pointerValue] inNode: p_playlist->p_local_category checkItemExistence: NO] ||
1526 ( var_CreateGetBool( p_playlist, "media-library" ) && [self isItem: [item pointerValue] inNode: p_playlist->p_ml_category checkItemExistence: NO] ) ) || item == nil ) )
1528 return NSDragOperationNone;
1531 /* Drop from the Playlist */
1532 if( [[o_pasteboard types] containsObject: @"VLCPlaylistItemPboardType"] )
1534 NSUInteger count = [o_nodes_array count];
1535 for( NSUInteger i = 0 ; i < count ; i++ )
1537 /* We refuse to Drop in a child of an item we are moving */
1538 if( [self isItem: [item pointerValue] inNode:
1539 [[o_nodes_array objectAtIndex: i] pointerValue]
1540 checkItemExistence: NO] )
1542 return NSDragOperationNone;
1545 return NSDragOperationMove;
1548 /* Drop from the Finder */
1549 else if( [[o_pasteboard types] containsObject: NSFilenamesPboardType] )
1551 return NSDragOperationGeneric;
1553 return NSDragOperationNone;
1556 - (BOOL)outlineView:(NSOutlineView *)outlineView acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(NSInteger)index
1558 playlist_t * p_playlist = pl_Get( VLCIntf );
1559 NSPasteboard *o_pasteboard = [info draggingPasteboard];
1561 /* Drag & Drop inside the playlist */
1562 if( [[o_pasteboard types] containsObject: @"VLCPlaylistItemPboardType"] )
1564 int i_row, i_removed_from_node = 0;
1565 playlist_item_t *p_new_parent, *p_item = NULL;
1566 NSArray *o_all_items = [o_nodes_array arrayByAddingObjectsFromArray:
1568 /* If the item is to be dropped as root item of the outline, make it a
1569 child of the respective general node, if is either the pl or the ml
1570 Else, choose the proposed parent as parent. */
1573 if ([self currentPlaylistRoot] == p_playlist->p_local_category || [self currentPlaylistRoot] == p_playlist->p_ml_category)
1574 p_new_parent = [self currentPlaylistRoot];
1579 p_new_parent = [item pointerValue];
1581 /* Make sure the proposed parent is a node.
1582 (This should never be true) */
1583 if( p_new_parent->i_children < 0 )
1588 NSUInteger count = [o_all_items count];
1589 for( NSUInteger i = 0; i < count; i++ )
1591 playlist_item_t *p_old_parent = NULL;
1592 int i_old_index = 0;
1594 p_item = [[o_all_items objectAtIndex:i] pointerValue];
1595 p_old_parent = p_item->p_parent;
1598 /* We may need the old index later */
1599 if( p_new_parent == p_old_parent )
1601 for( NSInteger j = 0; j < p_old_parent->i_children; j++ )
1603 if( p_old_parent->pp_children[j] == p_item )
1612 // Actually detach the item from the old position
1613 if( playlist_NodeRemoveItem( p_playlist, p_item, p_old_parent ) ==
1617 /* Calculate the new index */
1620 /* If we move the item in the same node, we need to take into
1621 account that one item will be deleted */
1624 if ((p_new_parent == p_old_parent && i_old_index < index + (int)i) )
1626 i_removed_from_node++;
1628 i_new_index = index + i - i_removed_from_node;
1630 // Reattach the item to the new position
1631 playlist_NodeInsert( p_playlist, p_item, p_new_parent, i_new_index );
1635 [self playlistUpdated];
1636 i_row = [o_outline_view rowForItem:[o_outline_dict objectForKey:[NSString stringWithFormat: @"%p", [[o_all_items objectAtIndex: 0] pointerValue]]]];
1640 i_row = [o_outline_view rowForItem:[o_outline_dict objectForKey:[NSString stringWithFormat: @"%p", p_new_parent]]];
1643 [o_outline_view deselectAll: self];
1644 [o_outline_view selectRowIndexes:[NSIndexSet indexSetWithIndex:i_row] byExtendingSelection:NO];
1645 [o_outline_view scrollRowToVisible: i_row];
1650 else if( [[o_pasteboard types] containsObject: NSFilenamesPboardType] )
1652 if ([self currentPlaylistRoot] != p_playlist->p_local_category && [self currentPlaylistRoot] != p_playlist->p_ml_category)
1655 playlist_item_t *p_node = [item pointerValue];
1657 NSArray *o_values = [[o_pasteboard propertyListForType: NSFilenamesPboardType]
1658 sortedArrayUsingSelector: @selector(caseInsensitiveCompare:)];
1659 NSUInteger count = [o_values count];
1660 NSMutableArray *o_array = [NSMutableArray arrayWithCapacity:count];
1661 input_thread_t * p_input = pl_CurrentInput( VLCIntf );
1662 BOOL b_returned = NO;
1664 if (count == 1 && p_input)
1666 b_returned = input_AddSubtitle( p_input, make_URI([[o_values objectAtIndex:0] UTF8String], NULL), true );
1667 vlc_object_release( p_input );
1672 vlc_object_release( p_input );
1674 for( NSUInteger i = 0; i < count; i++)
1676 NSDictionary *o_dic;
1677 char *psz_uri = make_URI([[o_values objectAtIndex:i] UTF8String], NULL);
1681 o_dic = [NSDictionary dictionaryWithObject:[NSString stringWithCString:psz_uri encoding:NSUTF8StringEncoding] forKey:@"ITEM_URL"];
1685 [o_array addObject: o_dic];
1690 [self appendArray:o_array atPos:index enqueue: YES];
1694 assert( p_node->i_children != -1 );
1695 [self appendNodeArray:o_array inNode: p_node atPos:index enqueue:YES];