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_Yield( 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_Yield( 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_Yield( 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_Yield( 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_Yield( 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_Yield( 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_Yield( 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_Yield( VLCIntf );
565 playlist_item_t *p_item, *p_temp_item;
566 NSMutableArray *o_array = [NSMutableArray array];
568 p_item = p_playlist->status.p_item;
571 vlc_object_release(p_playlist);
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 vlc_object_release( p_playlist );
598 /* Check if p_item is a child of p_node recursively. We need to check the item
599 existence first since OSX sometimes tries to redraw items that have been
600 deleted. We don't do it when not required since this verification takes
601 quite a long time on big playlists (yes, pretty hacky). */
603 - (BOOL)isItem: (playlist_item_t *)p_item
604 inNode: (playlist_item_t *)p_node
605 checkItemExistence:(BOOL)b_check
606 locked:(BOOL)b_locked
609 playlist_t * p_playlist = pl_Yield( VLCIntf );
610 playlist_item_t *p_temp_item = p_item;
612 if( p_node == p_item )
614 vlc_object_release(p_playlist);
618 if( p_node->i_children < 1)
620 vlc_object_release(p_playlist);
627 if(!b_locked) PL_LOCK;
631 /* Since outlineView: willDisplayCell:... may call this function with
632 p_items that don't exist anymore, first check if the item is still
633 in the playlist. Any cleaner solution welcomed. */
634 for( i = 0; i < p_playlist->all_items.i_size; i++ )
636 if( ARRAY_VAL( p_playlist->all_items, i) == p_item ) break;
637 else if ( i == p_playlist->all_items.i_size - 1 )
639 if(!b_locked) PL_UNLOCK;
640 vlc_object_release( p_playlist );
648 p_temp_item = p_temp_item->p_parent;
649 if( p_temp_item == p_node )
651 if(!b_locked) PL_UNLOCK;
652 vlc_object_release( p_playlist );
656 if(!b_locked) PL_UNLOCK;
659 vlc_object_release( p_playlist );
663 - (BOOL)isItem: (playlist_item_t *)p_item
664 inNode: (playlist_item_t *)p_node
665 checkItemExistence:(BOOL)b_check
667 [self isItem:p_item inNode:p_node checkItemExistence:b_check locked:NO];
670 /* This method is usefull for instance to remove the selected children of an
671 already selected node */
672 - (void)removeItemsFrom:(id)o_items ifChildrenOf:(id)o_nodes
675 for( i = 0 ; i < [o_items count] ; i++ )
677 for ( j = 0 ; j < [o_nodes count] ; j++ )
679 if( o_items == o_nodes)
681 if( j == i ) continue;
683 if( [self isItem: [[o_items objectAtIndex:i] pointerValue]
684 inNode: [[o_nodes objectAtIndex:j] pointerValue]
685 checkItemExistence: NO locked:NO] )
687 [o_items removeObjectAtIndex:i];
688 /* We need to execute the next iteration with the same index
689 since the current item has been deleted */
697 - (IBAction)savePlaylist:(id)sender
699 playlist_t * p_playlist = pl_Yield( VLCIntf );
701 NSSavePanel *o_save_panel = [NSSavePanel savePanel];
702 NSString * o_name = [NSString stringWithFormat: @"%@", _NS("Untitled")];
704 //[o_save_panel setAllowedFileTypes: [NSArray arrayWithObjects: @"m3u", @"xpf", nil] ];
705 [o_save_panel setTitle: _NS("Save Playlist")];
706 [o_save_panel setPrompt: _NS("Save")];
707 [o_save_panel setAccessoryView: o_save_accessory_view];
709 if( [o_save_panel runModalForDirectory: nil
710 file: o_name] == NSOKButton )
712 NSString *o_filename = [o_save_panel filename];
714 if( [o_save_accessory_popup indexOfSelectedItem] == 1 )
716 NSString * o_real_filename;
718 range.location = [o_filename length] - [@".xspf" length];
719 range.length = [@".xspf" length];
721 if( [o_filename compare:@".xspf" options: NSCaseInsensitiveSearch
722 range: range] != NSOrderedSame )
724 o_real_filename = [NSString stringWithFormat: @"%@.xspf", o_filename];
728 o_real_filename = o_filename;
730 playlist_Export( p_playlist,
731 [o_real_filename fileSystemRepresentation],
732 p_playlist->p_local_category, "export-xspf" );
736 NSString * o_real_filename;
738 range.location = [o_filename length] - [@".m3u" length];
739 range.length = [@".m3u" length];
741 if( [o_filename compare:@".m3u" options: NSCaseInsensitiveSearch
742 range: range] != NSOrderedSame )
744 o_real_filename = [NSString stringWithFormat: @"%@.m3u", o_filename];
748 o_real_filename = o_filename;
750 playlist_Export( p_playlist,
751 [o_real_filename fileSystemRepresentation],
752 p_playlist->p_local_category, "export-m3u" );
755 vlc_object_release( p_playlist );
758 /* When called retrieves the selected outlineview row and plays that node or item */
759 - (IBAction)playItem:(id)sender
761 intf_thread_t * p_intf = VLCIntf;
762 playlist_t * p_playlist = pl_Yield( p_intf );
764 playlist_item_t *p_item;
765 playlist_item_t *p_node = NULL;
767 p_item = [[o_outline_view itemAtRow:[o_outline_view selectedRow]] pointerValue];
771 if( p_item->i_children == -1 )
773 p_node = p_item->p_parent;
779 if( p_node->i_children > 0 && p_node->pp_children[0]->i_children == -1 )
781 p_item = p_node->pp_children[0];
788 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, pl_Unlocked, p_node, p_item );
790 vlc_object_release( p_playlist );
793 - (IBAction)revealItemInFinder:(id)sender
795 playlist_item_t * p_item = [[o_outline_view itemAtRow:[o_outline_view selectedRow]] pointerValue];
796 NSMutableString * o_mrl = nil;
798 if(! p_item || !p_item->p_input )
801 char *psz_uri = input_item_GetURI( p_item->p_input );
803 o_mrl = [NSMutableString stringWithUTF8String: psz_uri];
805 /* perform some checks whether it is a file and if it is local at all... */
806 NSRange prefix_range = [o_mrl rangeOfString: @"file:"];
807 if( prefix_range.location != NSNotFound )
808 [o_mrl deleteCharactersInRange: prefix_range];
810 if( [o_mrl characterAtIndex:0] == '/' )
811 [[NSWorkspace sharedWorkspace] selectFile: o_mrl inFileViewerRootedAtPath: o_mrl];
814 /* When called retrieves the selected outlineview row and plays that node or item */
815 - (IBAction)preparseItem:(id)sender
818 NSMutableArray *o_to_preparse;
819 intf_thread_t * p_intf = VLCIntf;
820 playlist_t * p_playlist = pl_Yield( p_intf );
822 o_to_preparse = [NSMutableArray arrayWithArray:[[o_outline_view selectedRowEnumerator] allObjects]];
823 i_count = [o_to_preparse count];
827 playlist_item_t *p_item = NULL;
829 for( i = 0; i < i_count; i++ )
831 o_number = [o_to_preparse lastObject];
832 i_row = [o_number intValue];
833 p_item = [[o_outline_view itemAtRow:i_row] pointerValue];
834 [o_to_preparse removeObject: o_number];
835 [o_outline_view deselectRow: i_row];
839 if( p_item->i_children == -1 )
841 playlist_PreparseEnqueue( p_playlist, p_item->p_input );
845 msg_Dbg( p_intf, "preparsing nodes not implemented" );
849 vlc_object_release( p_playlist );
850 [self playlistUpdated];
853 - (IBAction)servicesChange:(id)sender
855 NSMenuItem *o_mi = (NSMenuItem *)sender;
856 NSString *o_string = [o_mi representedObject];
857 playlist_t * p_playlist = pl_Yield( VLCIntf );
858 if( !playlist_IsServicesDiscoveryLoaded( p_playlist, [o_string UTF8String] ) )
859 playlist_ServicesDiscoveryAdd( p_playlist, [o_string UTF8String] );
861 playlist_ServicesDiscoveryRemove( p_playlist, [o_string UTF8String] );
863 [o_mi setState: playlist_IsServicesDiscoveryLoaded( p_playlist,
864 [o_string UTF8String] ) ? YES : NO];
866 vlc_object_release( p_playlist );
867 [self playlistUpdated];
871 - (IBAction)selectAll:(id)sender
873 [o_outline_view selectAll: nil];
876 - (IBAction)deleteItem:(id)sender
879 NSMutableArray *o_to_delete;
882 playlist_t * p_playlist;
883 intf_thread_t * p_intf = VLCIntf;
885 o_to_delete = [NSMutableArray arrayWithArray:[[o_outline_view selectedRowEnumerator] allObjects]];
886 i_count = [o_to_delete count];
888 p_playlist = pl_Yield( p_intf );
891 for( int i = 0; i < i_count; i++ )
893 o_number = [o_to_delete lastObject];
894 i_row = [o_number intValue];
895 id o_item = [o_outline_view itemAtRow: i_row];
896 playlist_item_t *p_item = [o_item pointerValue];
898 msg_Dbg( p_intf, "deleting item %i (of %i) with id \"%i\", pointerValue \"%p\" and %i children", i+1, i_count,
899 p_item->p_input->i_id, [o_item pointerValue], p_item->i_children +1 );
901 [o_to_delete removeObject: o_number];
902 [o_outline_view deselectRow: i_row];
904 if( p_item->i_children != -1 )
905 //is a node and not an item
907 if( p_playlist->status.i_status != PLAYLIST_STOPPED &&
908 [self isItem: p_playlist->status.p_item inNode:
909 ((playlist_item_t *)[o_item pointerValue])
910 checkItemExistence: NO locked:YES] == YES )
911 // if current item is in selected node and is playing then stop playlist
912 playlist_Control(p_playlist, PLAYLIST_STOP, pl_Locked );
914 playlist_NodeDelete( p_playlist, p_item, true, false );
917 playlist_DeleteFromInput( p_playlist, p_item->p_input->i_id, pl_Locked );
921 [self playlistUpdated];
922 vlc_object_release( p_playlist );
925 - (IBAction)sortNodeByName:(id)sender
927 [self sortNode: SORT_TITLE];
930 - (IBAction)sortNodeByAuthor:(id)sender
932 [self sortNode: SORT_ARTIST];
935 - (void)sortNode:(int)i_mode
937 playlist_t * p_playlist = pl_Yield( VLCIntf );
938 playlist_item_t * p_item;
940 if( [o_outline_view selectedRow] > -1 )
942 p_item = [[o_outline_view itemAtRow: [o_outline_view selectedRow]] pointerValue];
945 /*If no item is selected, sort the whole playlist*/
947 p_item = p_playlist->p_root_category;
950 if( p_item->i_children > -1 ) // the item is a node
953 playlist_RecursiveNodeSort( p_playlist, p_item, i_mode, ORDER_NORMAL );
959 playlist_RecursiveNodeSort( p_playlist,
960 p_item->p_parent, i_mode, ORDER_NORMAL );
963 vlc_object_release( p_playlist );
964 [self playlistUpdated];
967 - (input_item_t *)createItem:(NSDictionary *)o_one_item
969 intf_thread_t * p_intf = VLCIntf;
970 playlist_t * p_playlist = pl_Yield( p_intf );
972 input_item_t *p_input;
974 BOOL b_rem = FALSE, b_dir = FALSE;
975 NSString *o_uri, *o_name;
980 o_uri = (NSString *)[o_one_item objectForKey: @"ITEM_URL"];
981 o_name = (NSString *)[o_one_item objectForKey: @"ITEM_NAME"];
982 o_options = (NSArray *)[o_one_item objectForKey: @"ITEM_OPTIONS"];
984 /* Find the name for a disc entry (i know, can you believe the trouble?) */
985 if( ( !o_name || [o_name isEqualToString:@""] ) && [o_uri rangeOfString: @"/dev/"].location != NSNotFound )
987 int i_count, i_index;
988 struct statfs *mounts = NULL;
990 i_count = getmntinfo (&mounts, MNT_NOWAIT);
991 /* getmntinfo returns a pointer to static data. Do not free. */
992 for( i_index = 0 ; i_index < i_count; i_index++ )
994 NSMutableString *o_temp, *o_temp2;
995 o_temp = [NSMutableString stringWithString: o_uri];
996 o_temp2 = [NSMutableString stringWithUTF8String: mounts[i_index].f_mntfromname];
997 [o_temp replaceOccurrencesOfString: @"/dev/rdisk" withString: @"/dev/disk" options:NSLiteralSearch range:NSMakeRange(0, [o_temp length]) ];
998 [o_temp2 replaceOccurrencesOfString: @"s0" withString: @"" options:NSLiteralSearch range:NSMakeRange(0, [o_temp2 length]) ];
999 [o_temp2 replaceOccurrencesOfString: @"s1" withString: @"" options:NSLiteralSearch range:NSMakeRange(0, [o_temp2 length]) ];
1001 if( strstr( [o_temp fileSystemRepresentation], [o_temp2 fileSystemRepresentation] ) != NULL )
1003 o_name = [[NSFileManager defaultManager] displayNameAtPath: [NSString stringWithUTF8String:mounts[i_index].f_mntonname]];
1007 /* If no name, then make a guess */
1008 if( !o_name) o_name = [[NSFileManager defaultManager] displayNameAtPath: o_uri];
1010 if( [[NSFileManager defaultManager] fileExistsAtPath:o_uri isDirectory:&b_dir] && b_dir &&
1011 [[NSWorkspace sharedWorkspace] getFileSystemInfoForPath: o_uri isRemovable: &b_rem
1012 isWritable:NULL isUnmountable:NULL description:NULL type:NULL] && b_rem )
1014 /* All of this is to make sure CD's play when you D&D them on VLC */
1015 /* Converts mountpoint to a /dev file */
1018 NSMutableString *o_temp;
1020 buf = (struct statfs *) malloc (sizeof(struct statfs));
1021 statfs( [o_uri fileSystemRepresentation], buf );
1022 psz_dev = strdup(buf->f_mntfromname);
1023 o_temp = [NSMutableString stringWithUTF8String: psz_dev ];
1024 [o_temp replaceOccurrencesOfString: @"/dev/disk" withString: @"/dev/rdisk" options:NSLiteralSearch range:NSMakeRange(0, [o_temp length]) ];
1025 [o_temp replaceOccurrencesOfString: @"s0" withString: @"" options:NSLiteralSearch range:NSMakeRange(0, [o_temp length]) ];
1026 [o_temp replaceOccurrencesOfString: @"s1" withString: @"" options:NSLiteralSearch range:NSMakeRange(0, [o_temp length]) ];
1030 p_input = input_item_New( p_playlist, [o_uri fileSystemRepresentation], [o_name UTF8String] );
1036 for( i = 0; i < (int)[o_options count]; i++ )
1038 input_item_AddOption( p_input, strdup( [[o_options objectAtIndex:i] UTF8String] ) );
1042 /* Recent documents menu */
1043 o_true_file = [NSURL fileURLWithPath: o_uri];
1044 if( o_true_file != nil && (BOOL)config_GetInt( p_playlist, "macosx-recentitems" ) == YES )
1046 [[NSDocumentController sharedDocumentController]
1047 noteNewRecentDocumentURL: o_true_file];
1050 vlc_object_release( p_playlist );
1054 - (void)appendArray:(NSArray*)o_array atPos:(int)i_position enqueue:(BOOL)b_enqueue
1057 playlist_t * p_playlist = pl_Yield( VLCIntf );
1060 for( i_item = 0; i_item < (int)[o_array count]; i_item++ )
1062 input_item_t *p_input;
1063 NSDictionary *o_one_item;
1066 o_one_item = [o_array objectAtIndex: i_item];
1067 p_input = [self createItem: o_one_item];
1074 /* FIXME: playlist_AddInput() can fail */
1076 playlist_AddInput( p_playlist, p_input, PLAYLIST_INSERT,
1077 i_position == -1 ? PLAYLIST_END : i_position + i_item, true,
1080 if( i_item == 0 && !b_enqueue )
1082 playlist_item_t *p_item = NULL;
1083 playlist_item_t *p_node = NULL;
1084 p_item = playlist_ItemGetByInput( p_playlist, p_input, pl_Locked );
1087 if( p_item->i_children == -1 )
1088 p_node = p_item->p_parent;
1092 if( p_node->i_children > 0 && p_node->pp_children[0]->i_children == -1 )
1093 p_item = p_node->pp_children[0];
1097 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, pl_Locked, p_node, p_item );
1100 vlc_gc_decref( p_input );
1104 [self playlistUpdated];
1105 vlc_object_release( p_playlist );
1108 - (void)appendNodeArray:(NSArray*)o_array inNode:(playlist_item_t *)p_node atPos:(int)i_position enqueue:(BOOL)b_enqueue
1111 playlist_t * p_playlist = pl_Yield( VLCIntf );
1113 for( i_item = 0; i_item < (int)[o_array count]; i_item++ )
1115 input_item_t *p_input;
1116 NSDictionary *o_one_item;
1119 o_one_item = [o_array objectAtIndex: i_item];
1120 p_input = [self createItem: o_one_item];
1122 if( !p_input ) continue;
1125 /* FIXME: playlist_BothAddInput() can fail */
1127 playlist_BothAddInput( p_playlist, p_input, p_node,
1130 PLAYLIST_END : i_position + i_item,
1131 NULL, NULL, pl_Locked );
1134 if( i_item == 0 && !b_enqueue )
1136 playlist_item_t *p_item;
1137 p_item = playlist_ItemGetByInput( p_playlist, p_input, pl_Locked );
1138 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, pl_Locked, p_node, p_item );
1141 vlc_gc_decref( p_input );
1143 [self playlistUpdated];
1144 vlc_object_release( p_playlist );
1147 - (NSMutableArray *)subSearchItem:(playlist_item_t *)p_item
1149 playlist_t *p_playlist = pl_Yield( VLCIntf );
1150 playlist_item_t *p_selected_item;
1151 int i_current, i_selected_row;
1153 i_selected_row = [o_outline_view selectedRow];
1154 if (i_selected_row < 0)
1157 p_selected_item = (playlist_item_t *)[[o_outline_view itemAtRow:
1158 i_selected_row] pointerValue];
1160 for( i_current = 0; i_current < p_item->i_children ; i_current++ )
1163 NSString *o_current_name, *o_current_author;
1166 o_current_name = [NSString stringWithUTF8String:
1167 p_item->pp_children[i_current]->p_input->psz_name];
1168 psz_temp = input_item_GetInfo( p_item->p_input ,
1169 _("Meta-information"),_("Artist") );
1170 o_current_author = [NSString stringWithUTF8String: psz_temp];
1174 if( p_selected_item == p_item->pp_children[i_current] &&
1175 b_selected_item_met == NO )
1177 b_selected_item_met = YES;
1179 else if( p_selected_item == p_item->pp_children[i_current] &&
1180 b_selected_item_met == YES )
1182 vlc_object_release( p_playlist );
1185 else if( b_selected_item_met == YES &&
1186 ( [o_current_name rangeOfString:[o_search_field
1187 stringValue] options:NSCaseInsensitiveSearch].length ||
1188 [o_current_author rangeOfString:[o_search_field
1189 stringValue] options:NSCaseInsensitiveSearch].length ) )
1191 vlc_object_release( p_playlist );
1192 /*Adds the parent items in the result array as well, so that we can
1194 return [NSMutableArray arrayWithObject: [NSValue
1195 valueWithPointer: p_item->pp_children[i_current]]];
1197 if( p_item->pp_children[i_current]->i_children > 0 )
1199 id o_result = [self subSearchItem:
1200 p_item->pp_children[i_current]];
1201 if( o_result != NULL )
1203 vlc_object_release( p_playlist );
1204 [o_result insertObject: [NSValue valueWithPointer:
1205 p_item->pp_children[i_current]] atIndex:0];
1210 vlc_object_release( p_playlist );
1214 - (IBAction)searchItem:(id)sender
1216 playlist_t * p_playlist = pl_Yield( VLCIntf );
1222 b_selected_item_met = NO;
1224 /*First, only search after the selected item:*
1225 *(b_selected_item_met = NO) */
1226 o_result = [self subSearchItem:p_playlist->p_root_category];
1227 if( o_result == NULL )
1229 /* If the first search failed, search again from the beginning */
1230 o_result = [self subSearchItem:p_playlist->p_root_category];
1232 if( o_result != NULL )
1235 if( [[o_result objectAtIndex: 0] pointerValue] ==
1236 p_playlist->p_local_category )
1241 for( i = i_start ; i < [o_result count] - 1 ; i++ )
1243 [o_outline_view expandItem: [o_outline_dict objectForKey:
1244 [NSString stringWithFormat: @"%p",
1245 [[o_result objectAtIndex: i] pointerValue]]]];
1247 i_row = [o_outline_view rowForItem: [o_outline_dict objectForKey:
1248 [NSString stringWithFormat: @"%p",
1249 [[o_result objectAtIndex: [o_result count] - 1 ]
1254 [o_outline_view selectRow:i_row byExtendingSelection: NO];
1255 [o_outline_view scrollRowToVisible: i_row];
1257 vlc_object_release( p_playlist );
1260 - (IBAction)recursiveExpandNode:(id)sender
1262 id o_item = [o_outline_view itemAtRow: [o_outline_view selectedRow]];
1263 playlist_item_t *p_item = (playlist_item_t *)[o_item pointerValue];
1265 if( ![[o_outline_view dataSource] outlineView: o_outline_view
1266 isItemExpandable: o_item] )
1268 o_item = [o_outline_dict objectForKey: [NSString
1269 stringWithFormat: @"%p", p_item->p_parent]];
1272 /* We need to collapse the node first, since OSX refuses to recursively
1273 expand an already expanded node, even if children nodes are collapsed. */
1274 [o_outline_view collapseItem: o_item collapseChildren: YES];
1275 [o_outline_view expandItem: o_item expandChildren: YES];
1278 - (NSMenu *)menuForEvent:(NSEvent *)o_event
1284 pt = [o_outline_view convertPoint: [o_event locationInWindow]
1286 int row = [o_outline_view rowAtPoint:pt];
1288 [o_outline_view selectRowIndexes:[NSIndexSet indexSetWithIndex:row] byExtendingSelection:NO];
1290 b_item_sel = ( row != -1 && [o_outline_view selectedRow] != -1 );
1291 b_rows = [o_outline_view numberOfRows] != 0;
1293 [o_mi_play setEnabled: b_item_sel];
1294 [o_mi_delete setEnabled: b_item_sel];
1295 [o_mi_selectall setEnabled: b_rows];
1296 [o_mi_info setEnabled: b_item_sel];
1297 [o_mi_preparse setEnabled: b_item_sel];
1298 [o_mi_recursive_expand setEnabled: b_item_sel];
1299 [o_mi_sort_name setEnabled: b_item_sel];
1300 [o_mi_sort_author setEnabled: b_item_sel];
1302 return( o_ctx_menu );
1305 - (void)outlineView: (NSTableView*)o_tv
1306 didClickTableColumn:(NSTableColumn *)o_tc
1308 int i_mode = 0, i_type;
1309 intf_thread_t *p_intf = VLCIntf;
1311 playlist_t *p_playlist = pl_Yield( p_intf );
1313 /* Check whether the selected table column header corresponds to a
1314 sortable table column*/
1315 if( !( o_tc == o_tc_name || o_tc == o_tc_author ) )
1317 vlc_object_release( p_playlist );
1321 if( o_tc_sortColumn == o_tc )
1323 b_isSortDescending = !b_isSortDescending;
1327 b_isSortDescending = false;
1330 if( o_tc == o_tc_name )
1332 i_mode = SORT_TITLE;
1334 else if( o_tc == o_tc_author )
1336 i_mode = SORT_ARTIST;
1339 if( b_isSortDescending )
1341 i_type = ORDER_REVERSE;
1345 i_type = ORDER_NORMAL;
1349 playlist_RecursiveNodeSort( p_playlist, p_playlist->p_root_category, i_mode, i_type );
1352 vlc_object_release( p_playlist );
1353 [self playlistUpdated];
1355 o_tc_sortColumn = o_tc;
1356 [o_outline_view setHighlightedTableColumn:o_tc];
1358 if( b_isSortDescending )
1360 [o_outline_view setIndicatorImage:o_descendingSortingImage
1361 inTableColumn:o_tc];
1365 [o_outline_view setIndicatorImage:o_ascendingSortingImage
1366 inTableColumn:o_tc];
1371 - (void)outlineView:(NSOutlineView *)outlineView
1372 willDisplayCell:(id)cell
1373 forTableColumn:(NSTableColumn *)tableColumn
1376 playlist_t *p_playlist = pl_Yield( VLCIntf );
1380 o_playing_item = [o_outline_dict objectForKey:
1381 [NSString stringWithFormat:@"%p", p_playlist->status.p_item]];
1383 if( [self isItem: [o_playing_item pointerValue] inNode:
1384 [item pointerValue] checkItemExistence: YES]
1385 || [o_playing_item isEqual: item] )
1387 [cell setFont: [[NSFontManager sharedFontManager] convertFont:[cell font] toHaveTrait:NSBoldFontMask]];
1391 [cell setFont: [[NSFontManager sharedFontManager] convertFont:[cell font] toNotHaveTrait:NSBoldFontMask]];
1393 vlc_object_release( p_playlist );
1396 - (IBAction)addNode:(id)sender
1398 /* we have to create a new thread here because otherwise we would block the
1399 * interface since the interaction-stuff and this code would run in the same
1401 [NSThread detachNewThreadSelector: @selector(addNodeThreadedly)
1402 toTarget: self withObject:nil];
1403 [self playlistUpdated];
1406 - (void)addNodeThreadedly
1408 NSAutoreleasePool * ourPool = [[NSAutoreleasePool alloc] init];
1410 /* simply adds a new node to the end of the playlist */
1411 playlist_t * p_playlist = pl_Yield( VLCIntf );
1412 vlc_thread_set_priority( p_playlist, VLC_THREAD_PRIORITY_LOW );
1415 char *psz_name = NULL;
1416 ret_v = intf_UserStringInput( p_playlist, _("New Node"),
1417 _("Please enter a name for the new node."), &psz_name );
1420 if( ret_v != DIALOG_CANCELLED && psz_name )
1422 playlist_NodeCreate( p_playlist, psz_name,
1423 p_playlist->p_local_category, 0, NULL );
1425 else if(! config_GetInt( p_playlist, "interact" ) )
1427 /* in case that the interaction is disabled, just give it a bogus name */
1428 playlist_NodeCreate( p_playlist, _("Empty Folder"),
1429 p_playlist->p_local_category, 0, NULL );
1434 pl_Release( VLCIntf );
1440 @implementation VLCPlaylist (NSOutlineViewDataSource)
1442 - (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item
1444 id o_value = [super outlineView: outlineView child: index ofItem: item];
1445 playlist_t *p_playlist = pl_Yield( VLCIntf );
1447 if( playlist_CurrentSize( p_playlist ) >= 2 )
1449 [o_status_field setStringValue: [NSString stringWithFormat:
1451 playlist_CurrentSize( p_playlist )]];
1455 if( playlist_IsEmpty( p_playlist ) )
1457 [o_status_field setStringValue: _NS("No items in the playlist")];
1461 [o_status_field setStringValue: _NS("1 item")];
1464 vlc_object_release( p_playlist );
1466 [o_outline_dict setObject:o_value forKey:[NSString stringWithFormat:@"%p",
1467 [o_value pointerValue]]];
1472 /* Required for drag & drop and reordering */
1473 - (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pboard
1476 playlist_t *p_playlist = pl_Yield( VLCIntf );
1478 /* First remove the items that were moved during the last drag & drop
1480 [o_items_array removeAllObjects];
1481 [o_nodes_array removeAllObjects];
1483 for( i = 0 ; i < [items count] ; i++ )
1485 id o_item = [items objectAtIndex: i];
1487 /* Refuse to move items that are not in the General Node
1488 (Service Discovery) */
1489 if( ![self isItem: [o_item pointerValue] inNode:
1490 p_playlist->p_local_category checkItemExistence: NO] &&
1491 var_CreateGetBool( p_playlist, "media-library" ) &&
1492 ![self isItem: [o_item pointerValue] inNode:
1493 p_playlist->p_ml_category checkItemExistence: NO] ||
1494 [o_item pointerValue] == p_playlist->p_local_category ||
1495 [o_item pointerValue] == p_playlist->p_ml_category )
1497 vlc_object_release(p_playlist);
1500 /* Fill the items and nodes to move in 2 different arrays */
1501 if( ((playlist_item_t *)[o_item pointerValue])->i_children > 0 )
1502 [o_nodes_array addObject: o_item];
1504 [o_items_array addObject: o_item];
1507 /* Now we need to check if there are selected items that are in already
1508 selected nodes. In that case, we only want to move the nodes */
1509 [self removeItemsFrom: o_nodes_array ifChildrenOf: o_nodes_array];
1510 [self removeItemsFrom: o_items_array ifChildrenOf: o_nodes_array];
1512 /* We add the "VLCPlaylistItemPboardType" type to be able to recognize
1513 a Drop operation coming from the playlist. */
1515 [pboard declareTypes: [NSArray arrayWithObjects:
1516 @"VLCPlaylistItemPboardType", nil] owner: self];
1517 [pboard setData:[NSData data] forType:@"VLCPlaylistItemPboardType"];
1519 vlc_object_release(p_playlist);
1523 - (NSDragOperation)outlineView:(NSOutlineView *)outlineView validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(int)index
1525 playlist_t *p_playlist = pl_Yield( VLCIntf );
1526 NSPasteboard *o_pasteboard = [info draggingPasteboard];
1528 if( !p_playlist ) return NSDragOperationNone;
1530 /* Dropping ON items is not allowed if item is not a node */
1533 if( index == NSOutlineViewDropOnItemIndex &&
1534 ((playlist_item_t *)[item pointerValue])->i_children == -1 )
1536 vlc_object_release( p_playlist );
1537 return NSDragOperationNone;
1541 /* Don't allow on drop on playlist root element's child */
1542 if( !item && index != NSOutlineViewDropOnItemIndex)
1544 vlc_object_release( p_playlist );
1545 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 vlc_object_release( p_playlist );
1555 return NSDragOperationNone;
1558 /* Drop from the Playlist */
1559 if( [[o_pasteboard types] containsObject: @"VLCPlaylistItemPboardType"] )
1562 for( i = 0 ; i < [o_nodes_array count] ; i++ )
1564 /* We refuse to Drop in a child of an item we are moving */
1565 if( [self isItem: [item pointerValue] inNode:
1566 [[o_nodes_array objectAtIndex: i] pointerValue]
1567 checkItemExistence: NO] )
1569 vlc_object_release( p_playlist );
1570 return NSDragOperationNone;
1573 vlc_object_release( p_playlist );
1574 return NSDragOperationMove;
1577 /* Drop from the Finder */
1578 else if( [[o_pasteboard types] containsObject: NSFilenamesPboardType] )
1580 vlc_object_release( p_playlist );
1581 return NSDragOperationGeneric;
1583 vlc_object_release( p_playlist );
1584 return NSDragOperationNone;
1587 - (BOOL)outlineView:(NSOutlineView *)outlineView acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(int)index
1589 playlist_t * p_playlist = pl_Yield( VLCIntf );
1590 NSPasteboard *o_pasteboard = [info draggingPasteboard];
1592 /* Drag & Drop inside the playlist */
1593 if( [[o_pasteboard types] containsObject: @"VLCPlaylistItemPboardType"] )
1595 int i_row, i_removed_from_node = 0;
1597 playlist_item_t *p_new_parent, *p_item = NULL;
1598 NSArray *o_all_items = [o_nodes_array arrayByAddingObjectsFromArray:
1600 /* If the item is to be dropped as root item of the outline, make it a
1601 child of the General node.
1602 Else, choose the proposed parent as parent. */
1603 if( item == nil ) p_new_parent = p_playlist->p_local_category;
1604 else 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 )
1610 vlc_object_release( p_playlist );
1614 for( i = 0; i < [o_all_items 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 )
1627 for( j = 0; j < p_old_parent->i_children; j++ )
1629 if( p_old_parent->pp_children[j] == p_item )
1638 // Actually detach the item from the old position
1639 if( playlist_NodeRemoveItem( p_playlist, p_item, p_old_parent ) ==
1643 /* Calculate the new index */
1646 /* If we move the item in the same node, we need to take into
1647 account that one item will be deleted */
1650 if ((p_new_parent == p_old_parent &&
1651 i_old_index < index + (int)i) )
1653 i_removed_from_node++;
1655 i_new_index = index + i - i_removed_from_node;
1657 // Reattach the item to the new position
1658 playlist_NodeInsert( p_playlist, p_item, p_new_parent, i_new_index );
1662 [self playlistUpdated];
1663 i_row = [o_outline_view rowForItem:[o_outline_dict
1664 objectForKey:[NSString stringWithFormat: @"%p",
1665 [[o_all_items objectAtIndex: 0] pointerValue]]]];
1669 i_row = [o_outline_view rowForItem:[o_outline_dict
1670 objectForKey:[NSString stringWithFormat: @"%p", p_new_parent]]];
1673 [o_outline_view deselectAll: self];
1674 [o_outline_view selectRow: i_row byExtendingSelection: NO];
1675 [o_outline_view scrollRowToVisible: i_row];
1677 vlc_object_release( p_playlist );
1681 else if( [[o_pasteboard types] containsObject: NSFilenamesPboardType] )
1684 playlist_item_t *p_node = [item pointerValue];
1686 NSArray *o_array = [NSArray array];
1687 NSArray *o_values = [[o_pasteboard propertyListForType:
1688 NSFilenamesPboardType]
1689 sortedArrayUsingSelector:
1690 @selector(caseInsensitiveCompare:)];
1692 for( i = 0; i < (int)[o_values count]; i++)
1694 NSDictionary *o_dic;
1695 o_dic = [NSDictionary dictionaryWithObject:[o_values
1696 objectAtIndex:i] forKey:@"ITEM_URL"];
1697 o_array = [o_array arrayByAddingObject: o_dic];
1702 [self appendArray:o_array atPos:index enqueue: YES];
1706 assert( p_node->i_children != -1 );
1707 [self appendNodeArray:o_array inNode: p_node
1708 atPos:index enqueue:YES];
1710 vlc_object_release( p_playlist );
1713 vlc_object_release( p_playlist );