1 /*****************************************************************************
2 * playlist.m: MacOS X interface module
3 *****************************************************************************
4 * Copyright (C) 2002-2008 the VideoLAN team
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>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
27 * add 'icons' for different types of nodes? (http://www.cocoadev.com/index.pl?IconAndTextInTableCell)
28 * reimplement enable/disable item
29 * create a new 'tool' button (see the gear button in the Finder window) for 'actions'
30 (adding service discovery, other views, new node/playlist, save node/playlist) stuff like that
34 /*****************************************************************************
36 *****************************************************************************/
37 #include <stdlib.h> /* malloc(), free() */
38 #include <sys/param.h> /* for MAXPATHLEN */
41 #include <sys/mount.h>
47 #import "playlistinfo.h"
52 #import <vlc_interface.h>
54 /*****************************************************************************
55 * VLCPlaylistView implementation
56 *****************************************************************************/
57 @implementation VLCPlaylistView
59 - (NSMenu *)menuForEvent:(NSEvent *)o_event
61 return( [[self delegate] menuForEvent: o_event] );
64 - (void)keyDown:(NSEvent *)o_event
68 if( [[o_event characters] length] )
70 key = [[o_event characters] characterAtIndex: 0];
75 case NSDeleteCharacter:
76 case NSDeleteFunctionKey:
77 case NSDeleteCharFunctionKey:
78 case NSBackspaceCharacter:
79 [[self delegate] deleteItem:self];
82 case NSEnterCharacter:
83 case NSCarriageReturnCharacter:
84 [(VLCPlaylist *)[[VLCMain sharedInstance] getPlaylist] playItem:self];
88 [super keyDown: o_event];
95 /*****************************************************************************
96 * VLCPlaylistCommon implementation
98 * This class the superclass of the VLCPlaylist and VLCPlaylistWizard.
99 * It contains the common methods and elements of these 2 entities.
100 *****************************************************************************/
101 @implementation VLCPlaylistCommon
108 o_outline_dict = [[NSMutableDictionary alloc] init];
114 playlist_t * p_playlist = pl_Hold( VLCIntf );
115 [o_outline_view setTarget: self];
116 [o_outline_view setDelegate: self];
117 [o_outline_view setDataSource: self];
118 [o_outline_view setAllowsEmptySelection: NO];
120 vlc_object_release( p_playlist );
126 [[o_tc_name headerCell] setStringValue:_NS("Name")];
127 [[o_tc_author headerCell] setStringValue:_NS("Author")];
128 [[o_tc_duration headerCell] setStringValue:_NS("Duration")];
131 - (NSOutlineView *)outlineView
133 return o_outline_view;
136 - (playlist_item_t *)selectedPlaylistItem
138 return [[o_outline_view itemAtRow: [o_outline_view selectedRow]]
144 @implementation VLCPlaylistCommon (NSOutlineViewDataSource)
146 /* return the number of children for Obj-C pointer item */ /* DONE */
147 - (int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
150 playlist_item_t *p_item = NULL;
151 playlist_t * p_playlist = pl_Hold( VLCIntf );
152 assert( outlineView == o_outline_view );
155 p_item = p_playlist->p_root_category;
157 p_item = (playlist_item_t *)[item pointerValue];
160 i_return = p_item->i_children;
162 pl_Release( VLCIntf );
164 return i_return > 0 ? i_return : 0;
167 /* return the child at index for the Obj-C pointer item */ /* DONE */
168 - (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item
170 playlist_item_t *p_return = NULL, *p_item = NULL;
172 playlist_t * p_playlist = pl_Hold( VLCIntf );
178 p_item = p_playlist->p_root_category;
182 p_item = (playlist_item_t *)[item pointerValue];
184 if( p_item && index < p_item->i_children && index >= 0 )
185 p_return = p_item->pp_children[index];
188 vlc_object_release( p_playlist );
190 o_value = [o_outline_dict objectForKey:[NSString stringWithFormat: @"%p", p_return]];
194 /* Why is there a warning if that happens all the time and seems
195 * to be normal? Add an assert and fix it.
196 * msg_Warn( VLCIntf, "playlist item misses pointer value, adding one" ); */
197 o_value = [[NSValue valueWithPointer: p_return] retain];
202 /* is the item expandable */
203 - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item
206 playlist_t *p_playlist = pl_Hold( VLCIntf );
211 if( p_playlist->p_root_category )
213 i_return = p_playlist->p_root_category->i_children;
218 playlist_item_t *p_item = (playlist_item_t *)[item pointerValue];
220 i_return = p_item->i_children;
222 pl_Release( VLCIntf );
224 return (i_return >= 0);
227 /* retrieve the string values for the cells */
228 - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)o_tc byItem:(id)item
231 playlist_item_t *p_item;
233 /* For error handling */
234 static BOOL attempted_reload = NO;
236 if( item == nil || ![item isKindOfClass: [NSValue class]] )
238 /* Attempt to fix the error by asking for a data redisplay
239 * This might cause infinite loop, so add a small check */
240 if( !attempted_reload )
242 attempted_reload = YES;
243 [outlineView reloadData];
248 p_item = (playlist_item_t *)[item pointerValue];
249 if( !p_item || !p_item->p_input )
251 /* Attempt to fix the error by asking for a data redisplay
252 * This might cause infinite loop, so add a small check */
253 if( !attempted_reload )
255 attempted_reload = YES;
256 [outlineView reloadData];
261 attempted_reload = NO;
263 if( [[o_tc identifier] isEqualToString:@"name"] )
265 /* sanity check to prevent the NSString class from crashing */
266 char *psz_title = input_item_GetTitle( p_item->p_input );
267 if( !EMPTY_STR( psz_title ) )
269 o_value = [NSString stringWithUTF8String: psz_title];
273 char *psz_name = input_item_GetName( p_item->p_input );
275 o_value = [NSString stringWithUTF8String: psz_name];
280 else if( [[o_tc identifier] isEqualToString:@"artist"] )
282 char *psz_artist = input_item_GetArtist( p_item->p_input );
284 o_value = [NSString stringWithUTF8String: psz_artist];
287 else if( [[o_tc identifier] isEqualToString:@"duration"] )
289 char psz_duration[MSTRTIME_MAX_SIZE];
290 mtime_t dur = input_item_GetDuration( p_item->p_input );
293 secstotimestr( psz_duration, dur/1000000 );
294 o_value = [NSString stringWithUTF8String: psz_duration];
299 else if( [[o_tc identifier] isEqualToString:@"status"] )
301 if( input_item_HasErrorWhenReading( p_item->p_input ) )
303 o_value = [NSImage imageWithWarningIcon];
311 /*****************************************************************************
312 * VLCPlaylistWizard implementation
313 *****************************************************************************/
314 @implementation VLCPlaylistWizard
316 - (IBAction)reloadOutlineView
318 /* Only reload the outlineview if the wizard window is open since this can
319 be quite long on big playlists */
320 if( [[o_outline_view window] isVisible] )
322 [o_outline_view reloadData];
328 /*****************************************************************************
329 * extension to NSOutlineView's interface to fix compilation warnings
330 * and let us access these 2 functions properly
331 * this uses a private Apple-API, but works fine on all current OSX releases
332 * keep checking for compatiblity with future releases though
333 *****************************************************************************/
335 @interface NSOutlineView (UndocumentedSortImages)
336 + (NSImage *)_defaultTableHeaderSortImage;
337 + (NSImage *)_defaultTableHeaderReverseSortImage;
341 /*****************************************************************************
342 * VLCPlaylist implementation
343 *****************************************************************************/
344 @implementation VLCPlaylist
351 o_nodes_array = [[NSMutableArray alloc] init];
352 o_items_array = [[NSMutableArray alloc] init];
359 [o_nodes_array release];
360 [o_items_array release];
366 playlist_t * p_playlist = pl_Hold( VLCIntf );
370 [super awakeFromNib];
372 [o_outline_view setDoubleAction: @selector(playItem:)];
374 [o_outline_view registerForDraggedTypes:
375 [NSArray arrayWithObjects: NSFilenamesPboardType,
376 @"VLCPlaylistItemPboardType", nil]];
377 [o_outline_view setIntercellSpacing: NSMakeSize (0.0, 1.0)];
379 /* This uses private Apple API which works fine until 10.5.
380 * We need to keep checking in the future!
381 * These methods are being added artificially to NSOutlineView's interface above */
382 o_ascendingSortingImage = [[NSOutlineView class] _defaultTableHeaderSortImage];
383 o_descendingSortingImage = [[NSOutlineView class] _defaultTableHeaderReverseSortImage];
385 o_tc_sortColumn = nil;
388 char ** ppsz_services = services_discovery_GetServicesNames( p_playlist, &ppsz_name );
391 vlc_object_release( p_playlist );
395 for( i = 0; ppsz_services[i]; i++ )
400 char * name = ppsz_name[i] ? ppsz_name[i] : ppsz_services[i];
401 /* Check whether to enable these menuitems */
402 b_enabled = playlist_IsServicesDiscoveryLoaded( p_playlist, ppsz_services[i] );
404 /* Create the menu entries used in the playlist menu */
405 o_lmi = [[o_mi_services submenu] addItemWithTitle:
406 [NSString stringWithUTF8String: name]
407 action: @selector(servicesChange:)
409 [o_lmi setTarget: self];
410 [o_lmi setRepresentedObject: [NSString stringWithUTF8String: ppsz_services[i]]];
411 if( b_enabled ) [o_lmi setState: NSOnState];
413 /* Create the menu entries for the main menu */
414 o_lmi = [[o_mm_mi_services submenu] addItemWithTitle:
415 [NSString stringWithUTF8String: name]
416 action: @selector(servicesChange:)
418 [o_lmi setTarget: self];
419 [o_lmi setRepresentedObject: [NSString stringWithUTF8String: ppsz_services[i]]];
420 if( b_enabled ) [o_lmi setState: NSOnState];
422 free( ppsz_services[i] );
423 free( ppsz_name[i] );
425 free( ppsz_services );
428 vlc_object_release( p_playlist );
431 - (void)searchfieldChanged:(NSNotification *)o_notification
433 [o_search_field setStringValue:[[o_notification object] stringValue]];
440 [o_mi_save_playlist setTitle: _NS("Save Playlist...")];
441 [o_mi_play setTitle: _NS("Play")];
442 [o_mi_delete setTitle: _NS("Delete")];
443 [o_mi_recursive_expand setTitle: _NS("Expand Node")];
444 [o_mi_selectall setTitle: _NS("Select All")];
445 [o_mi_info setTitle: _NS("Information...")];
446 [o_mi_preparse setTitle: _NS("Fetch Meta Data")];
447 [o_mi_revealInFinder setTitle: _NS("Reveal in Finder")];
448 [o_mm_mi_revealInFinder setTitle: _NS("Reveal in Finder")];
449 [[o_mm_mi_revealInFinder menu] setAutoenablesItems: NO];
450 [o_mi_sort_name setTitle: _NS("Sort Node by Name")];
451 [o_mi_sort_author setTitle: _NS("Sort Node by Author")];
452 [o_mi_services setTitle: _NS("Services discovery")];
453 [o_mm_mi_services setTitle: _NS("Services discovery")];
454 [o_status_field setStringValue: _NS("No items in the playlist")];
456 [o_search_field setToolTip: _NS("Search in Playlist")];
457 [o_mi_addNode setTitle: _NS("Add Folder to Playlist")];
459 [o_save_accessory_text setStringValue: _NS("File Format:")];
460 [[o_save_accessory_popup itemAtIndex:0] setTitle: _NS("Extended M3U")];
461 [[o_save_accessory_popup itemAtIndex:1] setTitle: _NS("XML Shareable Playlist Format (XSPF)")];
464 - (void)playlistUpdated
466 /* Clear indications of any existing column sorting */
467 for( unsigned int i = 0 ; i < [[o_outline_view tableColumns] count] ; i++ )
469 [o_outline_view setIndicatorImage:nil inTableColumn:
470 [[o_outline_view tableColumns] objectAtIndex:i]];
473 [o_outline_view setHighlightedTableColumn:nil];
474 o_tc_sortColumn = nil;
475 // TODO Find a way to keep the dict size to a minimum
476 //[o_outline_dict removeAllObjects];
477 [o_outline_view reloadData];
478 [[[[VLCMain sharedInstance] getWizard] getPlaylistWizard] reloadOutlineView];
479 [[[[VLCMain sharedInstance] getBookmarks] getDataTable] reloadData];
481 playlist_t *p_playlist = pl_Hold( VLCIntf );
483 if( playlist_CurrentSize( p_playlist ) >= 2 )
485 [o_status_field setStringValue: [NSString stringWithFormat:
487 playlist_CurrentSize( p_playlist )]];
491 if( playlist_IsEmpty( p_playlist ) )
492 [o_status_field setStringValue: _NS("No items in the playlist")];
494 [o_status_field setStringValue: _NS("1 item")];
496 vlc_object_release( p_playlist );
498 [self outlineViewSelectionDidChange: nil];
501 - (void)playModeUpdated
503 playlist_t *p_playlist = pl_Hold( VLCIntf );
505 bool loop = var_GetBool( p_playlist, "loop" );
506 bool repeat = var_GetBool( p_playlist, "repeat" );
508 [[[VLCMain sharedInstance] getControls] repeatOne];
510 [[[VLCMain sharedInstance] getControls] repeatAll];
512 [[[VLCMain sharedInstance] getControls] repeatOff];
514 [[[VLCMain sharedInstance] getControls] shuffle];
516 vlc_object_release( p_playlist );
519 - (void)outlineViewSelectionDidChange:(NSNotification *)notification
522 playlist_item_t * p_item = [[o_outline_view itemAtRow:[o_outline_view selectedRow]] pointerValue];
526 /* update our info-panel to reflect the new item */
527 [[[VLCMain sharedInstance] getInfo] updatePanelWithItem:p_item->p_input];
529 /* update the state of our Reveal-in-Finder menu items */
530 NSMutableString *o_mrl;
531 char *psz_uri = input_item_GetURI( p_item->p_input );
534 o_mrl = [NSMutableString stringWithUTF8String: psz_uri];
536 /* perform some checks whether it is a file and if it is local at all... */
537 NSRange prefix_range = [o_mrl rangeOfString: @"file:"];
538 if( prefix_range.location != NSNotFound )
539 [o_mrl deleteCharactersInRange: prefix_range];
541 if( [o_mrl characterAtIndex:0] == '/' )
543 [o_mi_revealInFinder setEnabled: YES];
544 [o_mm_mi_revealInFinder setEnabled: YES];
548 [o_mi_revealInFinder setEnabled: NO];
549 [o_mm_mi_revealInFinder setEnabled: NO];
553 - (BOOL)isSelectionEmpty
555 return [o_outline_view selectedRow] == -1;
558 - (void)updateRowSelection
564 playlist_t *p_playlist = pl_Hold( VLCIntf );
565 playlist_item_t *p_item, *p_temp_item;
566 NSMutableArray *o_array = [NSMutableArray array];
568 p_item = playlist_CurrentPlayingItem( p_playlist );
571 pl_Release( VLCIntf );
575 p_temp_item = p_item;
576 while( p_temp_item->p_parent )
578 [o_array insertObject: [NSValue valueWithPointer: p_temp_item] atIndex: 0];
579 p_temp_item = p_temp_item->p_parent;
582 for( j = 0; j < [o_array count] - 1; j++ )
585 if( ( o_item = [o_outline_dict objectForKey:
586 [NSString stringWithFormat: @"%p",
587 [[o_array objectAtIndex:j] pointerValue]]] ) != nil )
589 [o_outline_view expandItem: o_item];
594 pl_Release( VLCIntf );
597 /* Check if p_item is a child of p_node recursively. We need to check the item
598 existence first since OSX sometimes tries to redraw items that have been
599 deleted. We don't do it when not required since this verification takes
600 quite a long time on big playlists (yes, pretty hacky). */
602 - (BOOL)isItem: (playlist_item_t *)p_item
603 inNode: (playlist_item_t *)p_node
604 checkItemExistence:(BOOL)b_check
605 locked:(BOOL)b_locked
608 playlist_t * p_playlist = pl_Hold( VLCIntf );
609 playlist_item_t *p_temp_item = p_item;
611 if( p_node == p_item )
613 vlc_object_release(p_playlist);
617 if( p_node->i_children < 1)
619 vlc_object_release(p_playlist);
626 if(!b_locked) PL_LOCK;
630 /* Since outlineView: willDisplayCell:... may call this function with
631 p_items that don't exist anymore, first check if the item is still
632 in the playlist. Any cleaner solution welcomed. */
633 for( i = 0; i < p_playlist->all_items.i_size; i++ )
635 if( ARRAY_VAL( p_playlist->all_items, i) == p_item ) break;
636 else if ( i == p_playlist->all_items.i_size - 1 )
638 if(!b_locked) PL_UNLOCK;
639 vlc_object_release( p_playlist );
647 p_temp_item = p_temp_item->p_parent;
648 if( p_temp_item == p_node )
650 if(!b_locked) PL_UNLOCK;
651 vlc_object_release( p_playlist );
655 if(!b_locked) PL_UNLOCK;
658 vlc_object_release( p_playlist );
662 - (BOOL)isItem: (playlist_item_t *)p_item
663 inNode: (playlist_item_t *)p_node
664 checkItemExistence:(BOOL)b_check
666 [self isItem:p_item inNode:p_node checkItemExistence:b_check locked:NO];
669 /* This method is usefull for instance to remove the selected children of an
670 already selected node */
671 - (void)removeItemsFrom:(id)o_items ifChildrenOf:(id)o_nodes
674 for( i = 0 ; i < [o_items count] ; i++ )
676 for ( j = 0 ; j < [o_nodes count] ; j++ )
678 if( o_items == o_nodes)
680 if( j == i ) continue;
682 if( [self isItem: [[o_items objectAtIndex:i] pointerValue]
683 inNode: [[o_nodes objectAtIndex:j] pointerValue]
684 checkItemExistence: NO locked:NO] )
686 [o_items removeObjectAtIndex:i];
687 /* We need to execute the next iteration with the same index
688 since the current item has been deleted */
696 - (IBAction)savePlaylist:(id)sender
698 playlist_t * p_playlist = pl_Hold( VLCIntf );
700 NSSavePanel *o_save_panel = [NSSavePanel savePanel];
701 NSString * o_name = [NSString stringWithFormat: @"%@", _NS("Untitled")];
703 //[o_save_panel setAllowedFileTypes: [NSArray arrayWithObjects: @"m3u", @"xpf", nil] ];
704 [o_save_panel setTitle: _NS("Save Playlist")];
705 [o_save_panel setPrompt: _NS("Save")];
706 [o_save_panel setAccessoryView: o_save_accessory_view];
708 if( [o_save_panel runModalForDirectory: nil
709 file: o_name] == NSOKButton )
711 NSString *o_filename = [o_save_panel filename];
713 if( [o_save_accessory_popup indexOfSelectedItem] == 1 )
715 NSString * o_real_filename;
717 range.location = [o_filename length] - [@".xspf" length];
718 range.length = [@".xspf" length];
720 if( [o_filename compare:@".xspf" options: NSCaseInsensitiveSearch
721 range: range] != NSOrderedSame )
723 o_real_filename = [NSString stringWithFormat: @"%@.xspf", o_filename];
727 o_real_filename = o_filename;
729 playlist_Export( p_playlist,
730 [o_real_filename fileSystemRepresentation],
731 p_playlist->p_local_category, "export-xspf" );
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" );
754 vlc_object_release( p_playlist );
757 /* When called retrieves the selected outlineview row and plays that node or item */
758 - (IBAction)playItem:(id)sender
760 intf_thread_t * p_intf = VLCIntf;
761 playlist_t * p_playlist = pl_Hold( p_intf );
763 playlist_item_t *p_item;
764 playlist_item_t *p_node = NULL;
766 p_item = [[o_outline_view itemAtRow:[o_outline_view selectedRow]] pointerValue];
770 if( p_item->i_children == -1 )
772 p_node = p_item->p_parent;
778 if( p_node->i_children > 0 && p_node->pp_children[0]->i_children == -1 )
780 p_item = p_node->pp_children[0];
787 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, pl_Unlocked, p_node, p_item );
789 vlc_object_release( p_playlist );
792 - (IBAction)revealItemInFinder:(id)sender
794 playlist_item_t * p_item = [[o_outline_view itemAtRow:[o_outline_view selectedRow]] pointerValue];
795 NSMutableString * o_mrl = nil;
797 if(! p_item || !p_item->p_input )
800 char *psz_uri = input_item_GetURI( p_item->p_input );
802 o_mrl = [NSMutableString stringWithUTF8String: psz_uri];
804 /* perform some checks whether it is a file and if it is local at all... */
805 NSRange prefix_range = [o_mrl rangeOfString: @"file:"];
806 if( prefix_range.location != NSNotFound )
807 [o_mrl deleteCharactersInRange: prefix_range];
809 if( [o_mrl characterAtIndex:0] == '/' )
810 [[NSWorkspace sharedWorkspace] selectFile: o_mrl inFileViewerRootedAtPath: o_mrl];
813 /* When called retrieves the selected outlineview row and plays that node or item */
814 - (IBAction)preparseItem:(id)sender
817 NSMutableArray *o_to_preparse;
818 intf_thread_t * p_intf = VLCIntf;
819 playlist_t * p_playlist = pl_Hold( p_intf );
821 o_to_preparse = [NSMutableArray arrayWithArray:[[o_outline_view selectedRowEnumerator] allObjects]];
822 i_count = [o_to_preparse count];
826 playlist_item_t *p_item = NULL;
828 for( i = 0; i < i_count; i++ )
830 o_number = [o_to_preparse lastObject];
831 i_row = [o_number intValue];
832 p_item = [[o_outline_view itemAtRow:i_row] pointerValue];
833 [o_to_preparse removeObject: o_number];
834 [o_outline_view deselectRow: i_row];
838 if( p_item->i_children == -1 )
840 playlist_PreparseEnqueue( p_playlist, p_item->p_input );
844 msg_Dbg( p_intf, "preparsing nodes not implemented" );
848 vlc_object_release( p_playlist );
849 [self playlistUpdated];
852 - (IBAction)servicesChange:(id)sender
854 NSMenuItem *o_mi = (NSMenuItem *)sender;
855 NSString *o_string = [o_mi representedObject];
856 playlist_t * p_playlist = pl_Hold( VLCIntf );
857 if( !playlist_IsServicesDiscoveryLoaded( p_playlist, [o_string UTF8String] ) )
858 playlist_ServicesDiscoveryAdd( p_playlist, [o_string UTF8String] );
860 playlist_ServicesDiscoveryRemove( p_playlist, [o_string UTF8String] );
862 [o_mi setState: playlist_IsServicesDiscoveryLoaded( p_playlist,
863 [o_string UTF8String] ) ? YES : NO];
865 vlc_object_release( p_playlist );
866 [self playlistUpdated];
870 - (IBAction)selectAll:(id)sender
872 [o_outline_view selectAll: nil];
875 - (IBAction)deleteItem:(id)sender
878 NSMutableArray *o_to_delete;
881 playlist_t * p_playlist;
882 intf_thread_t * p_intf = VLCIntf;
884 o_to_delete = [NSMutableArray arrayWithArray:[[o_outline_view selectedRowEnumerator] allObjects]];
885 i_count = [o_to_delete count];
887 p_playlist = pl_Hold( p_intf );
890 for( int i = 0; i < i_count; i++ )
892 o_number = [o_to_delete lastObject];
893 i_row = [o_number intValue];
894 id o_item = [o_outline_view itemAtRow: i_row];
895 playlist_item_t *p_item = [o_item pointerValue];
897 msg_Dbg( p_intf, "deleting item %i (of %i) with id \"%i\", pointerValue \"%p\" and %i children", i+1, i_count,
898 p_item->p_input->i_id, [o_item pointerValue], p_item->i_children +1 );
900 [o_to_delete removeObject: o_number];
901 [o_outline_view deselectRow: i_row];
903 if( p_item->i_children != -1 )
904 //is a node and not an item
906 if( playlist_Status( p_playlist ) != PLAYLIST_STOPPED &&
907 [self isItem: playlist_CurrentPlayingItem( p_playlist ) inNode:
908 ((playlist_item_t *)[o_item pointerValue])
909 checkItemExistence: NO locked:YES] == YES )
910 // if current item is in selected node and is playing then stop playlist
911 playlist_Control(p_playlist, PLAYLIST_STOP, pl_Locked );
913 playlist_NodeDelete( p_playlist, p_item, true, false );
916 playlist_DeleteFromInput( p_playlist, p_item->p_input->i_id, pl_Locked );
920 [self playlistUpdated];
921 vlc_object_release( p_playlist );
924 - (IBAction)sortNodeByName:(id)sender
926 [self sortNode: SORT_TITLE];
929 - (IBAction)sortNodeByAuthor:(id)sender
931 [self sortNode: SORT_ARTIST];
934 - (void)sortNode:(int)i_mode
936 playlist_t * p_playlist = pl_Hold( VLCIntf );
937 playlist_item_t * p_item;
939 if( [o_outline_view selectedRow] > -1 )
941 p_item = [[o_outline_view itemAtRow: [o_outline_view selectedRow]] pointerValue];
944 /*If no item is selected, sort the whole playlist*/
946 p_item = p_playlist->p_root_category;
949 if( p_item->i_children > -1 ) // the item is a node
952 playlist_RecursiveNodeSort( p_playlist, p_item, i_mode, ORDER_NORMAL );
958 playlist_RecursiveNodeSort( p_playlist,
959 p_item->p_parent, i_mode, ORDER_NORMAL );
962 vlc_object_release( p_playlist );
963 [self playlistUpdated];
966 - (input_item_t *)createItem:(NSDictionary *)o_one_item
968 intf_thread_t * p_intf = VLCIntf;
969 playlist_t * p_playlist = pl_Hold( p_intf );
971 input_item_t *p_input;
973 BOOL b_rem = FALSE, b_dir = FALSE;
974 NSString *o_uri, *o_name;
979 o_uri = (NSString *)[o_one_item objectForKey: @"ITEM_URL"];
980 o_name = (NSString *)[o_one_item objectForKey: @"ITEM_NAME"];
981 o_options = (NSArray *)[o_one_item objectForKey: @"ITEM_OPTIONS"];
983 /* Find the name for a disc entry (i know, can you believe the trouble?) */
984 if( ( !o_name || [o_name isEqualToString:@""] ) && [o_uri rangeOfString: @"/dev/"].location != NSNotFound )
986 int i_count, i_index;
987 struct statfs *mounts = NULL;
989 i_count = getmntinfo (&mounts, MNT_NOWAIT);
990 /* getmntinfo returns a pointer to static data. Do not free. */
991 for( i_index = 0 ; i_index < i_count; i_index++ )
993 NSMutableString *o_temp, *o_temp2;
994 o_temp = [NSMutableString stringWithString: o_uri];
995 o_temp2 = [NSMutableString stringWithUTF8String: mounts[i_index].f_mntfromname];
996 [o_temp replaceOccurrencesOfString: @"/dev/rdisk" withString: @"/dev/disk" options:NSLiteralSearch range:NSMakeRange(0, [o_temp length]) ];
997 [o_temp2 replaceOccurrencesOfString: @"s0" withString: @"" options:NSLiteralSearch range:NSMakeRange(0, [o_temp2 length]) ];
998 [o_temp2 replaceOccurrencesOfString: @"s1" withString: @"" options:NSLiteralSearch range:NSMakeRange(0, [o_temp2 length]) ];
1000 if( strstr( [o_temp fileSystemRepresentation], [o_temp2 fileSystemRepresentation] ) != NULL )
1002 o_name = [[NSFileManager defaultManager] displayNameAtPath: [NSString stringWithUTF8String:mounts[i_index].f_mntonname]];
1006 /* If no name, then make a guess */
1007 if( !o_name) o_name = [[NSFileManager defaultManager] displayNameAtPath: o_uri];
1009 if( [[NSFileManager defaultManager] fileExistsAtPath:o_uri isDirectory:&b_dir] && b_dir &&
1010 [[NSWorkspace sharedWorkspace] getFileSystemInfoForPath: o_uri isRemovable: &b_rem
1011 isWritable:NULL isUnmountable:NULL description:NULL type:NULL] && b_rem )
1013 /* All of this is to make sure CD's play when you D&D them on VLC */
1014 /* Converts mountpoint to a /dev file */
1017 NSMutableString *o_temp;
1019 buf = (struct statfs *) malloc (sizeof(struct statfs));
1020 statfs( [o_uri fileSystemRepresentation], buf );
1021 psz_dev = strdup(buf->f_mntfromname);
1022 o_temp = [NSMutableString stringWithUTF8String: psz_dev ];
1023 [o_temp replaceOccurrencesOfString: @"/dev/disk" withString: @"/dev/rdisk" options:NSLiteralSearch range:NSMakeRange(0, [o_temp length]) ];
1024 [o_temp replaceOccurrencesOfString: @"s0" withString: @"" options:NSLiteralSearch range:NSMakeRange(0, [o_temp length]) ];
1025 [o_temp replaceOccurrencesOfString: @"s1" withString: @"" options:NSLiteralSearch range:NSMakeRange(0, [o_temp length]) ];
1029 p_input = input_item_New( p_playlist, [o_uri fileSystemRepresentation], [o_name UTF8String] );
1035 for( i = 0; i < (int)[o_options count]; i++ )
1037 input_item_AddOption( p_input, strdup( [[o_options objectAtIndex:i] UTF8String] ) );
1041 /* Recent documents menu */
1042 o_true_file = [NSURL fileURLWithPath: o_uri];
1043 if( o_true_file != nil && (BOOL)config_GetInt( p_playlist, "macosx-recentitems" ) == YES )
1045 [[NSDocumentController sharedDocumentController]
1046 noteNewRecentDocumentURL: o_true_file];
1049 vlc_object_release( p_playlist );
1053 - (void)appendArray:(NSArray*)o_array atPos:(int)i_position enqueue:(BOOL)b_enqueue
1056 playlist_t * p_playlist = pl_Hold( VLCIntf );
1059 for( i_item = 0; i_item < (int)[o_array count]; i_item++ )
1061 input_item_t *p_input;
1062 NSDictionary *o_one_item;
1065 o_one_item = [o_array objectAtIndex: i_item];
1066 p_input = [self createItem: o_one_item];
1073 /* FIXME: playlist_AddInput() can fail */
1075 playlist_AddInput( p_playlist, p_input, PLAYLIST_INSERT,
1076 i_position == -1 ? PLAYLIST_END : i_position + i_item, true,
1079 if( i_item == 0 && !b_enqueue )
1081 playlist_item_t *p_item = NULL;
1082 playlist_item_t *p_node = NULL;
1083 p_item = playlist_ItemGetByInput( p_playlist, p_input, pl_Locked );
1086 if( p_item->i_children == -1 )
1087 p_node = p_item->p_parent;
1091 if( p_node->i_children > 0 && p_node->pp_children[0]->i_children == -1 )
1092 p_item = p_node->pp_children[0];
1096 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, pl_Locked, p_node, p_item );
1099 vlc_gc_decref( p_input );
1103 [self playlistUpdated];
1104 vlc_object_release( p_playlist );
1107 - (void)appendNodeArray:(NSArray*)o_array inNode:(playlist_item_t *)p_node atPos:(int)i_position enqueue:(BOOL)b_enqueue
1110 playlist_t * p_playlist = pl_Hold( VLCIntf );
1112 for( i_item = 0; i_item < (int)[o_array count]; i_item++ )
1114 input_item_t *p_input;
1115 NSDictionary *o_one_item;
1118 o_one_item = [o_array objectAtIndex: i_item];
1119 p_input = [self createItem: o_one_item];
1121 if( !p_input ) continue;
1124 /* FIXME: playlist_BothAddInput() can fail */
1126 playlist_BothAddInput( p_playlist, p_input, p_node,
1129 PLAYLIST_END : i_position + i_item,
1130 NULL, NULL, pl_Locked );
1133 if( i_item == 0 && !b_enqueue )
1135 playlist_item_t *p_item;
1136 p_item = playlist_ItemGetByInput( p_playlist, p_input, pl_Locked );
1137 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, pl_Locked, p_node, p_item );
1140 vlc_gc_decref( p_input );
1142 [self playlistUpdated];
1143 vlc_object_release( p_playlist );
1146 - (NSMutableArray *)subSearchItem:(playlist_item_t *)p_item
1148 playlist_t *p_playlist = pl_Hold( VLCIntf );
1149 playlist_item_t *p_selected_item;
1150 int i_current, i_selected_row;
1152 i_selected_row = [o_outline_view selectedRow];
1153 if (i_selected_row < 0)
1156 p_selected_item = (playlist_item_t *)[[o_outline_view itemAtRow:
1157 i_selected_row] pointerValue];
1159 for( i_current = 0; i_current < p_item->i_children ; i_current++ )
1162 NSString *o_current_name, *o_current_author;
1165 o_current_name = [NSString stringWithUTF8String:
1166 p_item->pp_children[i_current]->p_input->psz_name];
1167 psz_temp = input_item_GetInfo( p_item->p_input ,
1168 _("Meta-information"),_("Artist") );
1169 o_current_author = [NSString stringWithUTF8String: psz_temp];
1173 if( p_selected_item == p_item->pp_children[i_current] &&
1174 b_selected_item_met == NO )
1176 b_selected_item_met = YES;
1178 else if( p_selected_item == p_item->pp_children[i_current] &&
1179 b_selected_item_met == YES )
1181 vlc_object_release( p_playlist );
1184 else if( b_selected_item_met == YES &&
1185 ( [o_current_name rangeOfString:[o_search_field
1186 stringValue] options:NSCaseInsensitiveSearch].length ||
1187 [o_current_author rangeOfString:[o_search_field
1188 stringValue] options:NSCaseInsensitiveSearch].length ) )
1190 vlc_object_release( p_playlist );
1191 /*Adds the parent items in the result array as well, so that we can
1193 return [NSMutableArray arrayWithObject: [NSValue
1194 valueWithPointer: p_item->pp_children[i_current]]];
1196 if( p_item->pp_children[i_current]->i_children > 0 )
1198 id o_result = [self subSearchItem:
1199 p_item->pp_children[i_current]];
1200 if( o_result != NULL )
1202 vlc_object_release( p_playlist );
1203 [o_result insertObject: [NSValue valueWithPointer:
1204 p_item->pp_children[i_current]] atIndex:0];
1209 vlc_object_release( p_playlist );
1213 - (IBAction)searchItem:(id)sender
1215 playlist_t * p_playlist = pl_Hold( VLCIntf );
1221 b_selected_item_met = NO;
1223 /*First, only search after the selected item:*
1224 *(b_selected_item_met = NO) */
1225 o_result = [self subSearchItem:p_playlist->p_root_category];
1226 if( o_result == NULL )
1228 /* If the first search failed, search again from the beginning */
1229 o_result = [self subSearchItem:p_playlist->p_root_category];
1231 if( o_result != NULL )
1234 if( [[o_result objectAtIndex: 0] pointerValue] ==
1235 p_playlist->p_local_category )
1240 for( i = i_start ; i < [o_result count] - 1 ; i++ )
1242 [o_outline_view expandItem: [o_outline_dict objectForKey:
1243 [NSString stringWithFormat: @"%p",
1244 [[o_result objectAtIndex: i] pointerValue]]]];
1246 i_row = [o_outline_view rowForItem: [o_outline_dict objectForKey:
1247 [NSString stringWithFormat: @"%p",
1248 [[o_result objectAtIndex: [o_result count] - 1 ]
1253 [o_outline_view selectRow:i_row byExtendingSelection: NO];
1254 [o_outline_view scrollRowToVisible: i_row];
1256 vlc_object_release( p_playlist );
1259 - (IBAction)recursiveExpandNode:(id)sender
1261 id o_item = [o_outline_view itemAtRow: [o_outline_view selectedRow]];
1262 playlist_item_t *p_item = (playlist_item_t *)[o_item pointerValue];
1264 if( ![[o_outline_view dataSource] outlineView: o_outline_view
1265 isItemExpandable: o_item] )
1267 o_item = [o_outline_dict objectForKey: [NSString
1268 stringWithFormat: @"%p", p_item->p_parent]];
1271 /* We need to collapse the node first, since OSX refuses to recursively
1272 expand an already expanded node, even if children nodes are collapsed. */
1273 [o_outline_view collapseItem: o_item collapseChildren: YES];
1274 [o_outline_view expandItem: o_item expandChildren: YES];
1277 - (NSMenu *)menuForEvent:(NSEvent *)o_event
1283 pt = [o_outline_view convertPoint: [o_event locationInWindow]
1285 int row = [o_outline_view rowAtPoint:pt];
1287 [o_outline_view selectRowIndexes:[NSIndexSet indexSetWithIndex:row] byExtendingSelection:NO];
1289 b_item_sel = ( row != -1 && [o_outline_view selectedRow] != -1 );
1290 b_rows = [o_outline_view numberOfRows] != 0;
1292 [o_mi_play setEnabled: b_item_sel];
1293 [o_mi_delete setEnabled: b_item_sel];
1294 [o_mi_selectall setEnabled: b_rows];
1295 [o_mi_info setEnabled: b_item_sel];
1296 [o_mi_preparse setEnabled: b_item_sel];
1297 [o_mi_recursive_expand setEnabled: b_item_sel];
1298 [o_mi_sort_name setEnabled: b_item_sel];
1299 [o_mi_sort_author setEnabled: b_item_sel];
1301 return( o_ctx_menu );
1304 - (void)outlineView: (NSTableView*)o_tv
1305 didClickTableColumn:(NSTableColumn *)o_tc
1307 int i_mode = 0, i_type;
1308 intf_thread_t *p_intf = VLCIntf;
1310 playlist_t *p_playlist = pl_Hold( p_intf );
1312 /* Check whether the selected table column header corresponds to a
1313 sortable table column*/
1314 if( !( o_tc == o_tc_name || o_tc == o_tc_author ) )
1316 vlc_object_release( p_playlist );
1320 if( o_tc_sortColumn == o_tc )
1322 b_isSortDescending = !b_isSortDescending;
1326 b_isSortDescending = false;
1329 if( o_tc == o_tc_name )
1331 i_mode = SORT_TITLE;
1333 else if( o_tc == o_tc_author )
1335 i_mode = SORT_ARTIST;
1338 if( b_isSortDescending )
1340 i_type = ORDER_REVERSE;
1344 i_type = ORDER_NORMAL;
1348 playlist_RecursiveNodeSort( p_playlist, p_playlist->p_root_category, i_mode, i_type );
1351 vlc_object_release( p_playlist );
1352 [self playlistUpdated];
1354 o_tc_sortColumn = o_tc;
1355 [o_outline_view setHighlightedTableColumn:o_tc];
1357 if( b_isSortDescending )
1359 [o_outline_view setIndicatorImage:o_descendingSortingImage
1360 inTableColumn:o_tc];
1364 [o_outline_view setIndicatorImage:o_ascendingSortingImage
1365 inTableColumn:o_tc];
1370 - (void)outlineView:(NSOutlineView *)outlineView
1371 willDisplayCell:(id)cell
1372 forTableColumn:(NSTableColumn *)tableColumn
1375 playlist_t *p_playlist = pl_Hold( VLCIntf );
1379 o_playing_item = [o_outline_dict objectForKey:
1380 [NSString stringWithFormat:@"%p", playlist_CurrentPlayingItem( p_playlist )]];
1382 if( [self isItem: [o_playing_item pointerValue] inNode:
1383 [item pointerValue] checkItemExistence: YES]
1384 || [o_playing_item isEqual: item] )
1386 [cell setFont: [[NSFontManager sharedFontManager] convertFont:[cell font] toHaveTrait:NSBoldFontMask]];
1390 [cell setFont: [[NSFontManager sharedFontManager] convertFont:[cell font] toNotHaveTrait:NSBoldFontMask]];
1392 vlc_object_release( p_playlist );
1395 - (IBAction)addNode:(id)sender
1397 /* we have to create a new thread here because otherwise we would block the
1398 * interface since the interaction-stuff and this code would run in the same
1400 [NSThread detachNewThreadSelector: @selector(addNodeThreadedly)
1401 toTarget: self withObject:nil];
1402 [self playlistUpdated];
1405 - (void)addNodeThreadedly
1407 NSAutoreleasePool * ourPool = [[NSAutoreleasePool alloc] init];
1409 /* simply adds a new node to the end of the playlist */
1410 playlist_t * p_playlist = pl_Hold( VLCIntf );
1411 vlc_thread_set_priority( p_playlist, VLC_THREAD_PRIORITY_LOW );
1414 char *psz_name = NULL;
1415 ret_v = intf_UserStringInput( p_playlist, _("New Node"),
1416 _("Please enter a name for the new node."), &psz_name );
1419 if( ret_v != DIALOG_CANCELLED && psz_name )
1421 playlist_NodeCreate( p_playlist, psz_name,
1422 p_playlist->p_local_category, 0, NULL );
1424 else if(! config_GetInt( p_playlist, "interact" ) )
1426 /* in case that the interaction is disabled, just give it a bogus name */
1427 playlist_NodeCreate( p_playlist, _("Empty Folder"),
1428 p_playlist->p_local_category, 0, NULL );
1433 pl_Release( VLCIntf );
1439 @implementation VLCPlaylist (NSOutlineViewDataSource)
1441 - (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item
1443 id o_value = [super outlineView: outlineView child: index ofItem: item];
1444 playlist_t *p_playlist = pl_Hold( VLCIntf );
1446 if( playlist_CurrentSize( p_playlist ) >= 2 )
1448 [o_status_field setStringValue: [NSString stringWithFormat:
1450 playlist_CurrentSize( p_playlist )]];
1454 if( playlist_IsEmpty( p_playlist ) )
1456 [o_status_field setStringValue: _NS("No items in the playlist")];
1460 [o_status_field setStringValue: _NS("1 item")];
1463 vlc_object_release( p_playlist );
1465 [o_outline_dict setObject:o_value forKey:[NSString stringWithFormat:@"%p",
1466 [o_value pointerValue]]];
1471 /* Required for drag & drop and reordering */
1472 - (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pboard
1475 playlist_t *p_playlist = pl_Hold( VLCIntf );
1477 /* First remove the items that were moved during the last drag & drop
1479 [o_items_array removeAllObjects];
1480 [o_nodes_array removeAllObjects];
1482 for( i = 0 ; i < [items count] ; i++ )
1484 id o_item = [items objectAtIndex: i];
1486 /* Refuse to move items that are not in the General Node
1487 (Service Discovery) */
1488 if( ![self isItem: [o_item pointerValue] inNode:
1489 p_playlist->p_local_category checkItemExistence: NO] &&
1490 var_CreateGetBool( p_playlist, "media-library" ) &&
1491 ![self isItem: [o_item pointerValue] inNode:
1492 p_playlist->p_ml_category checkItemExistence: NO] ||
1493 [o_item pointerValue] == p_playlist->p_local_category ||
1494 [o_item pointerValue] == p_playlist->p_ml_category )
1496 vlc_object_release(p_playlist);
1499 /* Fill the items and nodes to move in 2 different arrays */
1500 if( ((playlist_item_t *)[o_item pointerValue])->i_children > 0 )
1501 [o_nodes_array addObject: o_item];
1503 [o_items_array addObject: o_item];
1506 /* Now we need to check if there are selected items that are in already
1507 selected nodes. In that case, we only want to move the nodes */
1508 [self removeItemsFrom: o_nodes_array ifChildrenOf: o_nodes_array];
1509 [self removeItemsFrom: o_items_array ifChildrenOf: o_nodes_array];
1511 /* We add the "VLCPlaylistItemPboardType" type to be able to recognize
1512 a Drop operation coming from the playlist. */
1514 [pboard declareTypes: [NSArray arrayWithObjects:
1515 @"VLCPlaylistItemPboardType", nil] owner: self];
1516 [pboard setData:[NSData data] forType:@"VLCPlaylistItemPboardType"];
1518 vlc_object_release(p_playlist);
1522 - (NSDragOperation)outlineView:(NSOutlineView *)outlineView validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(int)index
1524 playlist_t *p_playlist = pl_Hold( VLCIntf );
1525 NSPasteboard *o_pasteboard = [info draggingPasteboard];
1527 if( !p_playlist ) return NSDragOperationNone;
1529 /* Dropping ON items is not allowed if item is not a node */
1532 if( index == NSOutlineViewDropOnItemIndex &&
1533 ((playlist_item_t *)[item pointerValue])->i_children == -1 )
1535 vlc_object_release( p_playlist );
1536 return NSDragOperationNone;
1540 /* Don't allow on drop on playlist root element's child */
1541 if( !item && index != NSOutlineViewDropOnItemIndex)
1543 vlc_object_release( p_playlist );
1544 return NSDragOperationNone;
1547 /* We refuse to drop an item in anything else than a child of the General
1548 Node. We still accept items that would be root nodes of the outlineview
1549 however, to allow drop in an empty playlist. */
1550 if( !( ([self isItem: [item pointerValue] inNode: p_playlist->p_local_category checkItemExistence: NO] ||
1551 ( var_CreateGetBool( p_playlist, "media-library" ) && [self isItem: [item pointerValue] inNode: p_playlist->p_ml_category checkItemExistence: NO] ) ) || item == nil ) )
1553 vlc_object_release( p_playlist );
1554 return NSDragOperationNone;
1557 /* Drop from the Playlist */
1558 if( [[o_pasteboard types] containsObject: @"VLCPlaylistItemPboardType"] )
1561 for( i = 0 ; i < [o_nodes_array 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 vlc_object_release( p_playlist );
1569 return NSDragOperationNone;
1572 vlc_object_release( p_playlist );
1573 return NSDragOperationMove;
1576 /* Drop from the Finder */
1577 else if( [[o_pasteboard types] containsObject: NSFilenamesPboardType] )
1579 vlc_object_release( p_playlist );
1580 return NSDragOperationGeneric;
1582 vlc_object_release( p_playlist );
1583 return NSDragOperationNone;
1586 - (BOOL)outlineView:(NSOutlineView *)outlineView acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(int)index
1588 playlist_t * p_playlist = pl_Hold( VLCIntf );
1589 NSPasteboard *o_pasteboard = [info draggingPasteboard];
1591 /* Drag & Drop inside the playlist */
1592 if( [[o_pasteboard types] containsObject: @"VLCPlaylistItemPboardType"] )
1594 int i_row, i_removed_from_node = 0;
1596 playlist_item_t *p_new_parent, *p_item = NULL;
1597 NSArray *o_all_items = [o_nodes_array arrayByAddingObjectsFromArray:
1599 /* If the item is to be dropped as root item of the outline, make it a
1600 child of the General node.
1601 Else, choose the proposed parent as parent. */
1602 if( item == nil ) p_new_parent = p_playlist->p_local_category;
1603 else p_new_parent = [item pointerValue];
1605 /* Make sure the proposed parent is a node.
1606 (This should never be true) */
1607 if( p_new_parent->i_children < 0 )
1609 vlc_object_release( p_playlist );
1613 for( i = 0; i < [o_all_items count]; i++ )
1615 playlist_item_t *p_old_parent = NULL;
1616 int i_old_index = 0;
1618 p_item = [[o_all_items objectAtIndex:i] pointerValue];
1619 p_old_parent = p_item->p_parent;
1622 /* We may need the old index later */
1623 if( p_new_parent == p_old_parent )
1626 for( 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 &&
1650 i_old_index < index + (int)i) )
1652 i_removed_from_node++;
1654 i_new_index = index + i - i_removed_from_node;
1656 // Reattach the item to the new position
1657 playlist_NodeInsert( p_playlist, p_item, p_new_parent, i_new_index );
1661 [self playlistUpdated];
1662 i_row = [o_outline_view rowForItem:[o_outline_dict
1663 objectForKey:[NSString stringWithFormat: @"%p",
1664 [[o_all_items objectAtIndex: 0] pointerValue]]]];
1668 i_row = [o_outline_view rowForItem:[o_outline_dict
1669 objectForKey:[NSString stringWithFormat: @"%p", p_new_parent]]];
1672 [o_outline_view deselectAll: self];
1673 [o_outline_view selectRow: i_row byExtendingSelection: NO];
1674 [o_outline_view scrollRowToVisible: i_row];
1676 vlc_object_release( p_playlist );
1680 else if( [[o_pasteboard types] containsObject: NSFilenamesPboardType] )
1683 playlist_item_t *p_node = [item pointerValue];
1685 NSArray *o_array = [NSArray array];
1686 NSArray *o_values = [[o_pasteboard propertyListForType:
1687 NSFilenamesPboardType]
1688 sortedArrayUsingSelector:
1689 @selector(caseInsensitiveCompare:)];
1691 for( i = 0; i < (int)[o_values count]; i++)
1693 NSDictionary *o_dic;
1694 o_dic = [NSDictionary dictionaryWithObject:[o_values
1695 objectAtIndex:i] forKey:@"ITEM_URL"];
1696 o_array = [o_array arrayByAddingObject: o_dic];
1701 [self appendArray:o_array atPos:index enqueue: YES];
1705 assert( p_node->i_children != -1 );
1706 [self appendNodeArray:o_array inNode: p_node
1707 atPos:index enqueue:YES];
1709 vlc_object_release( p_playlist );
1712 vlc_object_release( p_playlist );