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>
53 #import <vlc_services_discovery.h>
55 /*****************************************************************************
56 * VLCPlaylistView implementation
57 *****************************************************************************/
58 @implementation VLCPlaylistView
60 - (NSMenu *)menuForEvent:(NSEvent *)o_event
62 return( [[self delegate] menuForEvent: o_event] );
65 - (void)keyDown:(NSEvent *)o_event
69 if( [[o_event characters] length] )
71 key = [[o_event characters] characterAtIndex: 0];
76 case NSDeleteCharacter:
77 case NSDeleteFunctionKey:
78 case NSDeleteCharFunctionKey:
79 case NSBackspaceCharacter:
80 [[self delegate] deleteItem:self];
83 case NSEnterCharacter:
84 case NSCarriageReturnCharacter:
85 [(VLCPlaylist *)[[VLCMain sharedInstance] getPlaylist] playItem:self];
89 [super keyDown: o_event];
96 /*****************************************************************************
97 * VLCPlaylistCommon implementation
99 * This class the superclass of the VLCPlaylist and VLCPlaylistWizard.
100 * It contains the common methods and elements of these 2 entities.
101 *****************************************************************************/
102 @implementation VLCPlaylistCommon
109 o_outline_dict = [[NSMutableDictionary alloc] init];
115 playlist_t * p_playlist = pl_Hold( VLCIntf );
116 [o_outline_view setTarget: self];
117 [o_outline_view setDelegate: self];
118 [o_outline_view setDataSource: self];
119 [o_outline_view setAllowsEmptySelection: NO];
120 [o_outline_view expandItem: [o_outline_view itemAtRow:0]];
122 vlc_object_release( p_playlist );
128 [[o_tc_name headerCell] setStringValue:_NS("Name")];
129 [[o_tc_author headerCell] setStringValue:_NS("Author")];
130 [[o_tc_duration headerCell] setStringValue:_NS("Duration")];
133 - (NSOutlineView *)outlineView
135 return o_outline_view;
138 - (playlist_item_t *)selectedPlaylistItem
140 return [[o_outline_view itemAtRow: [o_outline_view selectedRow]]
146 @implementation VLCPlaylistCommon (NSOutlineViewDataSource)
148 /* return the number of children for Obj-C pointer item */ /* DONE */
149 - (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
152 playlist_item_t *p_item = NULL;
153 playlist_t * p_playlist = pl_Hold( VLCIntf );
154 assert( outlineView == o_outline_view );
157 p_item = p_playlist->p_root_category;
159 p_item = (playlist_item_t *)[item pointerValue];
162 i_return = p_item->i_children;
164 pl_Release( VLCIntf );
166 return i_return > 0 ? i_return : 0;
169 /* return the child at index for the Obj-C pointer item */ /* DONE */
170 - (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item
172 playlist_item_t *p_return = NULL, *p_item = NULL;
174 playlist_t * p_playlist = pl_Hold( VLCIntf );
180 p_item = p_playlist->p_root_category;
184 p_item = (playlist_item_t *)[item pointerValue];
186 if( p_item && index < p_item->i_children && index >= 0 )
187 p_return = p_item->pp_children[index];
190 vlc_object_release( p_playlist );
192 o_value = [o_outline_dict objectForKey:[NSString stringWithFormat: @"%p", p_return]];
196 /* Why is there a warning if that happens all the time and seems
197 * to be normal? Add an assert and fix it.
198 * msg_Warn( VLCIntf, "playlist item misses pointer value, adding one" ); */
199 o_value = [[NSValue valueWithPointer: p_return] retain];
204 /* is the item expandable */
205 - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item
208 playlist_t *p_playlist = pl_Hold( VLCIntf );
213 if( p_playlist->p_root_category )
215 i_return = p_playlist->p_root_category->i_children;
220 playlist_item_t *p_item = (playlist_item_t *)[item pointerValue];
222 i_return = p_item->i_children;
224 pl_Release( VLCIntf );
226 return (i_return >= 0);
229 /* retrieve the string values for the cells */
230 - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)o_tc byItem:(id)item
233 playlist_item_t *p_item;
235 /* For error handling */
236 static BOOL attempted_reload = NO;
238 if( item == nil || ![item isKindOfClass: [NSValue class]] )
240 /* Attempt to fix the error by asking for a data redisplay
241 * This might cause infinite loop, so add a small check */
242 if( !attempted_reload )
244 attempted_reload = YES;
245 [outlineView reloadData];
250 p_item = (playlist_item_t *)[item pointerValue];
251 if( !p_item || !p_item->p_input )
253 /* Attempt to fix the error by asking for a data redisplay
254 * This might cause infinite loop, so add a small check */
255 if( !attempted_reload )
257 attempted_reload = YES;
258 [outlineView reloadData];
263 attempted_reload = NO;
265 if( [[o_tc identifier] isEqualToString:@"name"] )
267 /* sanity check to prevent the NSString class from crashing */
268 char *psz_title = input_item_GetTitle( p_item->p_input );
269 if( !EMPTY_STR( psz_title ) )
271 o_value = [NSString stringWithUTF8String: psz_title];
275 char *psz_name = input_item_GetName( p_item->p_input );
277 o_value = [NSString stringWithUTF8String: psz_name];
282 else if( [[o_tc identifier] isEqualToString:@"artist"] )
284 char *psz_artist = input_item_GetArtist( p_item->p_input );
286 o_value = [NSString stringWithUTF8String: psz_artist];
289 else if( [[o_tc identifier] isEqualToString:@"duration"] )
291 char psz_duration[MSTRTIME_MAX_SIZE];
292 mtime_t dur = input_item_GetDuration( p_item->p_input );
295 secstotimestr( psz_duration, dur/1000000 );
296 o_value = [NSString stringWithUTF8String: psz_duration];
301 else if( [[o_tc identifier] isEqualToString:@"status"] )
303 if( input_item_HasErrorWhenReading( p_item->p_input ) )
305 o_value = [NSImage imageWithWarningIcon];
313 /*****************************************************************************
314 * VLCPlaylistWizard implementation
315 *****************************************************************************/
316 @implementation VLCPlaylistWizard
318 - (IBAction)reloadOutlineView
320 /* Only reload the outlineview if the wizard window is open since this can
321 be quite long on big playlists */
322 if( [[o_outline_view window] isVisible] )
324 [o_outline_view reloadData];
330 /*****************************************************************************
331 * extension to NSOutlineView's interface to fix compilation warnings
332 * and let us access these 2 functions properly
333 * this uses a private Apple-API, but works fine on all current OSX releases
334 * keep checking for compatiblity with future releases though
335 *****************************************************************************/
337 @interface NSOutlineView (UndocumentedSortImages)
338 + (NSImage *)_defaultTableHeaderSortImage;
339 + (NSImage *)_defaultTableHeaderReverseSortImage;
343 /*****************************************************************************
344 * VLCPlaylist implementation
345 *****************************************************************************/
346 @implementation VLCPlaylist
353 o_nodes_array = [[NSMutableArray alloc] init];
354 o_items_array = [[NSMutableArray alloc] init];
361 [o_nodes_array release];
362 [o_items_array release];
368 playlist_t * p_playlist = pl_Hold( VLCIntf );
372 [super awakeFromNib];
374 [o_outline_view setDoubleAction: @selector(playItem:)];
376 [o_outline_view registerForDraggedTypes:
377 [NSArray arrayWithObjects: NSFilenamesPboardType,
378 @"VLCPlaylistItemPboardType", nil]];
379 [o_outline_view setIntercellSpacing: NSMakeSize (0.0, 1.0)];
381 /* This uses private Apple API which works fine until 10.5.
382 * We need to keep checking in the future!
383 * These methods are being added artificially to NSOutlineView's interface above */
384 o_ascendingSortingImage = [[NSOutlineView class] _defaultTableHeaderSortImage];
385 o_descendingSortingImage = [[NSOutlineView class] _defaultTableHeaderReverseSortImage];
387 o_tc_sortColumn = nil;
390 char ** ppsz_services = vlc_sd_GetNames( &ppsz_name );
393 vlc_object_release( p_playlist );
397 for( i = 0; ppsz_services[i]; i++ )
402 char * name = ppsz_name[i] ? ppsz_name[i] : ppsz_services[i];
403 /* Check whether to enable these menuitems */
404 b_enabled = playlist_IsServicesDiscoveryLoaded( p_playlist, ppsz_services[i] );
406 /* Create the menu entries used in the playlist menu */
407 o_lmi = [[o_mi_services submenu] addItemWithTitle:
408 [NSString stringWithUTF8String: name]
409 action: @selector(servicesChange:)
411 [o_lmi setTarget: self];
412 [o_lmi setRepresentedObject: [NSString stringWithUTF8String: ppsz_services[i]]];
413 if( b_enabled ) [o_lmi setState: NSOnState];
415 /* Create the menu entries for the main menu */
416 o_lmi = [[o_mm_mi_services submenu] addItemWithTitle:
417 [NSString stringWithUTF8String: name]
418 action: @selector(servicesChange:)
420 [o_lmi setTarget: self];
421 [o_lmi setRepresentedObject: [NSString stringWithUTF8String: ppsz_services[i]]];
422 if( b_enabled ) [o_lmi setState: NSOnState];
424 free( ppsz_services[i] );
425 free( ppsz_name[i] );
427 free( ppsz_services );
430 vlc_object_release( p_playlist );
433 - (void)searchfieldChanged:(NSNotification *)o_notification
435 [o_search_field setStringValue:[[o_notification object] stringValue]];
442 [o_mi_save_playlist setTitle: _NS("Save Playlist...")];
443 [o_mi_play setTitle: _NS("Play")];
444 [o_mi_delete setTitle: _NS("Delete")];
445 [o_mi_recursive_expand setTitle: _NS("Expand Node")];
446 [o_mi_selectall setTitle: _NS("Select All")];
447 [o_mi_info setTitle: _NS("Media Information...")];
448 [o_mi_dl_cover_art setTitle: _NS("Download Cover Art")];
449 [o_mi_preparse setTitle: _NS("Fetch Meta Data")];
450 [o_mi_revealInFinder setTitle: _NS("Reveal in Finder")];
451 [o_mm_mi_revealInFinder setTitle: _NS("Reveal in Finder")];
452 [[o_mm_mi_revealInFinder menu] setAutoenablesItems: NO];
453 [o_mi_sort_name setTitle: _NS("Sort Node by Name")];
454 [o_mi_sort_author setTitle: _NS("Sort Node by Author")];
455 [o_mi_services setTitle: _NS("Services discovery")];
456 [o_mm_mi_services setTitle: _NS("Services discovery")];
457 [o_status_field setStringValue: _NS("No items in the playlist")];
459 [o_search_field setToolTip: _NS("Search in Playlist")];
460 [o_mi_addNode setTitle: _NS("Add Folder to Playlist")];
462 [o_save_accessory_text setStringValue: _NS("File Format:")];
463 [[o_save_accessory_popup itemAtIndex:0] setTitle: _NS("Extended M3U")];
464 [[o_save_accessory_popup itemAtIndex:1] setTitle: _NS("XML Shareable Playlist Format (XSPF)")];
467 - (void)playlistUpdated
469 /* Clear indications of any existing column sorting */
470 for( unsigned int i = 0 ; i < [[o_outline_view tableColumns] count] ; i++ )
472 [o_outline_view setIndicatorImage:nil inTableColumn:
473 [[o_outline_view tableColumns] objectAtIndex:i]];
476 [o_outline_view setHighlightedTableColumn:nil];
477 o_tc_sortColumn = nil;
478 // TODO Find a way to keep the dict size to a minimum
479 //[o_outline_dict removeAllObjects];
480 [o_outline_view reloadData];
481 [[[[VLCMain sharedInstance] getWizard] getPlaylistWizard] reloadOutlineView];
482 [[[[VLCMain sharedInstance] getBookmarks] getDataTable] reloadData];
484 playlist_t *p_playlist = pl_Hold( VLCIntf );
487 if( playlist_CurrentSize( p_playlist ) >= 2 )
489 [o_status_field setStringValue: [NSString stringWithFormat:
491 playlist_CurrentSize( p_playlist )]];
495 if( playlist_IsEmpty( p_playlist ) )
496 [o_status_field setStringValue: _NS("No items in the playlist")];
498 [o_status_field setStringValue: _NS("1 item")];
501 vlc_object_release( p_playlist );
503 [self outlineViewSelectionDidChange: nil];
506 - (void)playModeUpdated
508 playlist_t *p_playlist = pl_Hold( VLCIntf );
510 bool loop = var_GetBool( p_playlist, "loop" );
511 bool repeat = var_GetBool( p_playlist, "repeat" );
513 [[[VLCMain sharedInstance] getControls] repeatOne];
515 [[[VLCMain sharedInstance] getControls] repeatAll];
517 [[[VLCMain sharedInstance] getControls] repeatOff];
519 [[[VLCMain sharedInstance] getControls] shuffle];
521 vlc_object_release( p_playlist );
524 - (void)outlineViewSelectionDidChange:(NSNotification *)notification
527 playlist_item_t * p_item = [[o_outline_view itemAtRow:[o_outline_view selectedRow]] pointerValue];
531 /* update the state of our Reveal-in-Finder menu items */
532 NSMutableString *o_mrl;
533 char *psz_uri = input_item_GetURI( p_item->p_input );
536 o_mrl = [NSMutableString stringWithUTF8String: psz_uri];
538 /* perform some checks whether it is a file and if it is local at all... */
539 NSRange prefix_range = [o_mrl rangeOfString: @"file:"];
540 if( prefix_range.location != NSNotFound )
541 [o_mrl deleteCharactersInRange: prefix_range];
543 if( [o_mrl characterAtIndex:0] == '/' )
545 [o_mi_revealInFinder setEnabled: YES];
546 [o_mm_mi_revealInFinder setEnabled: YES];
550 [o_mi_revealInFinder setEnabled: NO];
551 [o_mm_mi_revealInFinder setEnabled: NO];
553 if( [[VLCMain sharedInstance] isPlaylistCollapsed] == NO )
555 /* update our info-panel to reflect the new item, if we aren't collapsed */
556 [[[VLCMain sharedInstance] getInfo] updatePanelWithItem:p_item->p_input];
561 - (BOOL)isSelectionEmpty
563 return [o_outline_view selectedRow] == -1;
566 - (void)updateRowSelection
572 playlist_t *p_playlist = pl_Hold( VLCIntf );
573 playlist_item_t *p_item, *p_temp_item;
574 NSMutableArray *o_array = [NSMutableArray array];
576 p_item = playlist_CurrentPlayingItem( p_playlist );
579 pl_Release( VLCIntf );
583 p_temp_item = p_item;
584 while( p_temp_item->p_parent )
586 [o_array insertObject: [NSValue valueWithPointer: p_temp_item] atIndex: 0];
587 p_temp_item = p_temp_item->p_parent;
590 for( j = 0; j < [o_array count] - 1; j++ )
593 if( ( o_item = [o_outline_dict objectForKey:
594 [NSString stringWithFormat: @"%p",
595 [[o_array objectAtIndex:j] pointerValue]]] ) != nil )
597 [o_outline_view expandItem: o_item];
602 pl_Release( VLCIntf );
605 /* Check if p_item is a child of p_node recursively. We need to check the item
606 existence first since OSX sometimes tries to redraw items that have been
607 deleted. We don't do it when not required since this verification takes
608 quite a long time on big playlists (yes, pretty hacky). */
610 - (BOOL)isItem: (playlist_item_t *)p_item
611 inNode: (playlist_item_t *)p_node
612 checkItemExistence:(BOOL)b_check
613 locked:(BOOL)b_locked
616 playlist_t * p_playlist = pl_Hold( VLCIntf );
617 playlist_item_t *p_temp_item = p_item;
619 if( p_node == p_item )
621 vlc_object_release(p_playlist);
625 if( p_node->i_children < 1)
627 vlc_object_release(p_playlist);
634 if(!b_locked) PL_LOCK;
638 /* Since outlineView: willDisplayCell:... may call this function with
639 p_items that don't exist anymore, first check if the item is still
640 in the playlist. Any cleaner solution welcomed. */
641 for( i = 0; i < p_playlist->all_items.i_size; i++ )
643 if( ARRAY_VAL( p_playlist->all_items, i) == p_item ) break;
644 else if ( i == p_playlist->all_items.i_size - 1 )
646 if(!b_locked) PL_UNLOCK;
647 vlc_object_release( p_playlist );
655 p_temp_item = p_temp_item->p_parent;
656 if( p_temp_item == p_node )
658 if(!b_locked) PL_UNLOCK;
659 vlc_object_release( p_playlist );
663 if(!b_locked) PL_UNLOCK;
666 vlc_object_release( p_playlist );
670 - (BOOL)isItem: (playlist_item_t *)p_item
671 inNode: (playlist_item_t *)p_node
672 checkItemExistence:(BOOL)b_check
674 [self isItem:p_item inNode:p_node checkItemExistence:b_check locked:NO];
677 /* This method is usefull for instance to remove the selected children of an
678 already selected node */
679 - (void)removeItemsFrom:(id)o_items ifChildrenOf:(id)o_nodes
682 for( i = 0 ; i < [o_items count] ; i++ )
684 for ( j = 0 ; j < [o_nodes count] ; j++ )
686 if( o_items == o_nodes)
688 if( j == i ) continue;
690 if( [self isItem: [[o_items objectAtIndex:i] pointerValue]
691 inNode: [[o_nodes objectAtIndex:j] pointerValue]
692 checkItemExistence: NO locked:NO] )
694 [o_items removeObjectAtIndex:i];
695 /* We need to execute the next iteration with the same index
696 since the current item has been deleted */
704 - (IBAction)savePlaylist:(id)sender
706 playlist_t * p_playlist = pl_Hold( VLCIntf );
708 NSSavePanel *o_save_panel = [NSSavePanel savePanel];
709 NSString * o_name = [NSString stringWithFormat: @"%@", _NS("Untitled")];
711 //[o_save_panel setAllowedFileTypes: [NSArray arrayWithObjects: @"m3u", @"xpf", nil] ];
712 [o_save_panel setTitle: _NS("Save Playlist")];
713 [o_save_panel setPrompt: _NS("Save")];
714 [o_save_panel setAccessoryView: o_save_accessory_view];
716 if( [o_save_panel runModalForDirectory: nil
717 file: o_name] == NSOKButton )
719 NSString *o_filename = [o_save_panel filename];
721 if( [o_save_accessory_popup indexOfSelectedItem] == 1 )
723 NSString * o_real_filename;
725 range.location = [o_filename length] - [@".xspf" length];
726 range.length = [@".xspf" length];
728 if( [o_filename compare:@".xspf" options: NSCaseInsensitiveSearch
729 range: range] != NSOrderedSame )
731 o_real_filename = [NSString stringWithFormat: @"%@.xspf", o_filename];
735 o_real_filename = o_filename;
737 playlist_Export( p_playlist,
738 [o_real_filename fileSystemRepresentation],
739 p_playlist->p_local_category, "export-xspf" );
743 NSString * o_real_filename;
745 range.location = [o_filename length] - [@".m3u" length];
746 range.length = [@".m3u" length];
748 if( [o_filename compare:@".m3u" options: NSCaseInsensitiveSearch
749 range: range] != NSOrderedSame )
751 o_real_filename = [NSString stringWithFormat: @"%@.m3u", o_filename];
755 o_real_filename = o_filename;
757 playlist_Export( p_playlist,
758 [o_real_filename fileSystemRepresentation],
759 p_playlist->p_local_category, "export-m3u" );
762 vlc_object_release( p_playlist );
765 /* When called retrieves the selected outlineview row and plays that node or item */
766 - (IBAction)playItem:(id)sender
768 intf_thread_t * p_intf = VLCIntf;
769 playlist_t * p_playlist = pl_Hold( p_intf );
771 playlist_item_t *p_item;
772 playlist_item_t *p_node = NULL;
774 p_item = [[o_outline_view itemAtRow:[o_outline_view selectedRow]] pointerValue];
778 if( p_item->i_children == -1 )
780 p_node = p_item->p_parent;
786 if( p_node->i_children > 0 && p_node->pp_children[0]->i_children == -1 )
788 p_item = p_node->pp_children[0];
795 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, pl_Unlocked, p_node, p_item );
797 vlc_object_release( p_playlist );
800 - (IBAction)revealItemInFinder:(id)sender
802 playlist_item_t * p_item = [[o_outline_view itemAtRow:[o_outline_view selectedRow]] pointerValue];
803 NSMutableString * o_mrl = nil;
805 if(! p_item || !p_item->p_input )
808 char *psz_uri = input_item_GetURI( p_item->p_input );
810 o_mrl = [NSMutableString stringWithUTF8String: psz_uri];
812 /* perform some checks whether it is a file and if it is local at all... */
813 NSRange prefix_range = [o_mrl rangeOfString: @"file:"];
814 if( prefix_range.location != NSNotFound )
815 [o_mrl deleteCharactersInRange: prefix_range];
817 if( [o_mrl characterAtIndex:0] == '/' )
818 [[NSWorkspace sharedWorkspace] selectFile: o_mrl inFileViewerRootedAtPath: o_mrl];
821 /* When called retrieves the selected outlineview row and plays that node or item */
822 - (IBAction)preparseItem:(id)sender
825 NSMutableArray *o_to_preparse;
826 intf_thread_t * p_intf = VLCIntf;
827 playlist_t * p_playlist = pl_Hold( p_intf );
829 o_to_preparse = [NSMutableArray arrayWithArray:[[o_outline_view selectedRowEnumerator] allObjects]];
830 i_count = [o_to_preparse count];
834 playlist_item_t *p_item = NULL;
836 for( i = 0; i < i_count; i++ )
838 o_number = [o_to_preparse lastObject];
839 i_row = [o_number intValue];
840 p_item = [[o_outline_view itemAtRow:i_row] pointerValue];
841 [o_to_preparse removeObject: o_number];
842 [o_outline_view deselectRow: i_row];
846 if( p_item->i_children == -1 )
848 playlist_PreparseEnqueue( p_playlist, p_item->p_input, pl_Unlocked );
852 msg_Dbg( p_intf, "preparsing nodes not implemented" );
856 vlc_object_release( p_playlist );
857 [self playlistUpdated];
860 - (IBAction)downloadCoverArt:(id)sender
863 NSMutableArray *o_to_preparse;
864 intf_thread_t * p_intf = VLCIntf;
865 playlist_t * p_playlist = pl_Hold( p_intf );
867 o_to_preparse = [NSMutableArray arrayWithArray:[[o_outline_view selectedRowEnumerator] allObjects]];
868 i_count = [o_to_preparse count];
872 playlist_item_t *p_item = NULL;
874 for( i = 0; i < i_count; i++ )
876 o_number = [o_to_preparse lastObject];
877 i_row = [o_number intValue];
878 p_item = [[o_outline_view itemAtRow:i_row] pointerValue];
879 [o_to_preparse removeObject: o_number];
880 [o_outline_view deselectRow: i_row];
882 if( p_item && p_item->i_children == -1 )
884 playlist_AskForArtEnqueue( p_playlist, p_item->p_input, pl_Unlocked );
887 vlc_object_release( p_playlist );
888 [self playlistUpdated];
891 - (IBAction)servicesChange:(id)sender
893 NSMenuItem *o_mi = (NSMenuItem *)sender;
894 NSString *o_string = [o_mi representedObject];
895 playlist_t * p_playlist = pl_Hold( VLCIntf );
896 if( !playlist_IsServicesDiscoveryLoaded( p_playlist, [o_string UTF8String] ) )
897 playlist_ServicesDiscoveryAdd( p_playlist, [o_string UTF8String] );
899 playlist_ServicesDiscoveryRemove( p_playlist, [o_string UTF8String] );
901 [o_mi setState: playlist_IsServicesDiscoveryLoaded( p_playlist,
902 [o_string UTF8String] ) ? YES : NO];
904 vlc_object_release( p_playlist );
905 [self playlistUpdated];
909 - (IBAction)selectAll:(id)sender
911 [o_outline_view selectAll: nil];
914 - (IBAction)deleteItem:(id)sender
917 NSMutableArray *o_to_delete;
920 playlist_t * p_playlist;
921 intf_thread_t * p_intf = VLCIntf;
923 o_to_delete = [NSMutableArray arrayWithArray:[[o_outline_view selectedRowEnumerator] allObjects]];
924 i_count = [o_to_delete count];
926 p_playlist = pl_Hold( p_intf );
929 for( int i = 0; i < i_count; i++ )
931 o_number = [o_to_delete lastObject];
932 i_row = [o_number intValue];
933 id o_item = [o_outline_view itemAtRow: i_row];
934 playlist_item_t *p_item = [o_item pointerValue];
936 msg_Dbg( p_intf, "deleting item %i (of %i) with id \"%i\", pointerValue \"%p\" and %i children", i+1, i_count,
937 p_item->p_input->i_id, [o_item pointerValue], p_item->i_children +1 );
939 [o_to_delete removeObject: o_number];
940 [o_outline_view deselectRow: i_row];
942 if( p_item->i_children != -1 )
943 //is a node and not an item
945 if( playlist_Status( p_playlist ) != PLAYLIST_STOPPED &&
946 [self isItem: playlist_CurrentPlayingItem( p_playlist ) inNode:
947 ((playlist_item_t *)[o_item pointerValue])
948 checkItemExistence: NO locked:YES] == YES )
949 // if current item is in selected node and is playing then stop playlist
950 playlist_Control(p_playlist, PLAYLIST_STOP, pl_Locked );
952 playlist_NodeDelete( p_playlist, p_item, true, false );
955 playlist_DeleteFromInput( p_playlist, p_item->p_input->i_id, pl_Locked );
959 [self playlistUpdated];
960 vlc_object_release( p_playlist );
963 - (IBAction)sortNodeByName:(id)sender
965 [self sortNode: SORT_TITLE];
968 - (IBAction)sortNodeByAuthor:(id)sender
970 [self sortNode: SORT_ARTIST];
973 - (void)sortNode:(int)i_mode
975 playlist_t * p_playlist = pl_Hold( VLCIntf );
976 playlist_item_t * p_item;
978 if( [o_outline_view selectedRow] > -1 )
980 p_item = [[o_outline_view itemAtRow: [o_outline_view selectedRow]] pointerValue];
983 /*If no item is selected, sort the whole playlist*/
985 p_item = p_playlist->p_root_category;
988 if( p_item->i_children > -1 ) // the item is a node
991 playlist_RecursiveNodeSort( p_playlist, p_item, i_mode, ORDER_NORMAL );
997 playlist_RecursiveNodeSort( p_playlist,
998 p_item->p_parent, i_mode, ORDER_NORMAL );
1001 vlc_object_release( p_playlist );
1002 [self playlistUpdated];
1005 - (input_item_t *)createItem:(NSDictionary *)o_one_item
1007 intf_thread_t * p_intf = VLCIntf;
1008 playlist_t * p_playlist = pl_Hold( p_intf );
1010 input_item_t *p_input;
1012 BOOL b_rem = FALSE, b_dir = FALSE;
1013 NSString *o_uri, *o_name;
1018 o_uri = (NSString *)[o_one_item objectForKey: @"ITEM_URL"];
1019 o_name = (NSString *)[o_one_item objectForKey: @"ITEM_NAME"];
1020 o_options = (NSArray *)[o_one_item objectForKey: @"ITEM_OPTIONS"];
1022 /* Find the name for a disc entry (i know, can you believe the trouble?) */
1023 if( ( !o_name || [o_name isEqualToString:@""] ) && [o_uri rangeOfString: @"/dev/"].location != NSNotFound )
1025 int i_count, i_index;
1026 struct statfs *mounts = NULL;
1028 i_count = getmntinfo (&mounts, MNT_NOWAIT);
1029 /* getmntinfo returns a pointer to static data. Do not free. */
1030 for( i_index = 0 ; i_index < i_count; i_index++ )
1032 NSMutableString *o_temp, *o_temp2;
1033 o_temp = [NSMutableString stringWithString: o_uri];
1034 o_temp2 = [NSMutableString stringWithUTF8String: mounts[i_index].f_mntfromname];
1035 [o_temp replaceOccurrencesOfString: @"/dev/rdisk" withString: @"/dev/disk" options:NSLiteralSearch range:NSMakeRange(0, [o_temp length]) ];
1036 [o_temp2 replaceOccurrencesOfString: @"s0" withString: @"" options:NSLiteralSearch range:NSMakeRange(0, [o_temp2 length]) ];
1037 [o_temp2 replaceOccurrencesOfString: @"s1" withString: @"" options:NSLiteralSearch range:NSMakeRange(0, [o_temp2 length]) ];
1039 if( strstr( [o_temp fileSystemRepresentation], [o_temp2 fileSystemRepresentation] ) != NULL )
1041 o_name = [[NSFileManager defaultManager] displayNameAtPath: [NSString stringWithUTF8String:mounts[i_index].f_mntonname]];
1045 /* If no name, then make a guess */
1046 if( !o_name) o_name = [[NSFileManager defaultManager] displayNameAtPath: o_uri];
1048 if( [[NSFileManager defaultManager] fileExistsAtPath:o_uri isDirectory:&b_dir] && b_dir &&
1049 [[NSWorkspace sharedWorkspace] getFileSystemInfoForPath: o_uri isRemovable: &b_rem
1050 isWritable:NULL isUnmountable:NULL description:NULL type:NULL] && b_rem )
1052 /* All of this is to make sure CD's play when you D&D them on VLC */
1053 /* Converts mountpoint to a /dev file */
1056 NSMutableString *o_temp;
1058 buf = (struct statfs *) malloc (sizeof(struct statfs));
1059 statfs( [o_uri fileSystemRepresentation], buf );
1060 psz_dev = strdup(buf->f_mntfromname);
1061 o_temp = [NSMutableString stringWithUTF8String: psz_dev ];
1062 [o_temp replaceOccurrencesOfString: @"/dev/disk" withString: @"/dev/rdisk" options:NSLiteralSearch range:NSMakeRange(0, [o_temp length]) ];
1063 [o_temp replaceOccurrencesOfString: @"s0" withString: @"" options:NSLiteralSearch range:NSMakeRange(0, [o_temp length]) ];
1064 [o_temp replaceOccurrencesOfString: @"s1" withString: @"" options:NSLiteralSearch range:NSMakeRange(0, [o_temp length]) ];
1068 p_input = input_item_New( p_playlist, [o_uri fileSystemRepresentation], [o_name UTF8String] );
1074 for( i = 0; i < (int)[o_options count]; i++ )
1076 input_item_AddOption( p_input, strdup( [[o_options objectAtIndex:i] UTF8String] ),
1077 VLC_INPUT_OPTION_TRUSTED );
1081 /* Recent documents menu */
1082 o_true_file = [NSURL fileURLWithPath: o_uri];
1083 if( o_true_file != nil && (BOOL)config_GetInt( p_playlist, "macosx-recentitems" ) == YES )
1085 [[NSDocumentController sharedDocumentController]
1086 noteNewRecentDocumentURL: o_true_file];
1089 vlc_object_release( p_playlist );
1093 - (void)appendArray:(NSArray*)o_array atPos:(int)i_position enqueue:(BOOL)b_enqueue
1096 playlist_t * p_playlist = pl_Hold( VLCIntf );
1099 for( i_item = 0; i_item < (int)[o_array count]; i_item++ )
1101 input_item_t *p_input;
1102 NSDictionary *o_one_item;
1105 o_one_item = [o_array objectAtIndex: i_item];
1106 p_input = [self createItem: o_one_item];
1113 /* FIXME: playlist_AddInput() can fail */
1115 playlist_AddInput( p_playlist, p_input, PLAYLIST_INSERT,
1116 i_position == -1 ? PLAYLIST_END : i_position + i_item, true,
1119 if( i_item == 0 && !b_enqueue )
1121 playlist_item_t *p_item = NULL;
1122 playlist_item_t *p_node = NULL;
1123 p_item = playlist_ItemGetByInput( p_playlist, p_input );
1126 if( p_item->i_children == -1 )
1127 p_node = p_item->p_parent;
1131 if( p_node->i_children > 0 && p_node->pp_children[0]->i_children == -1 )
1132 p_item = p_node->pp_children[0];
1136 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, pl_Locked, p_node, p_item );
1139 vlc_gc_decref( p_input );
1143 [self playlistUpdated];
1144 vlc_object_release( p_playlist );
1147 - (void)appendNodeArray:(NSArray*)o_array inNode:(playlist_item_t *)p_node atPos:(int)i_position enqueue:(BOOL)b_enqueue
1150 playlist_t * p_playlist = pl_Hold( VLCIntf );
1152 for( i_item = 0; i_item < (int)[o_array count]; i_item++ )
1154 input_item_t *p_input;
1155 NSDictionary *o_one_item;
1158 o_one_item = [o_array objectAtIndex: i_item];
1159 p_input = [self createItem: o_one_item];
1161 if( !p_input ) continue;
1164 /* FIXME: playlist_BothAddInput() can fail */
1166 playlist_BothAddInput( p_playlist, p_input, p_node,
1169 PLAYLIST_END : i_position + i_item,
1170 NULL, NULL, pl_Locked );
1173 if( i_item == 0 && !b_enqueue )
1175 playlist_item_t *p_item;
1176 p_item = playlist_ItemGetByInput( p_playlist, p_input );
1177 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, pl_Locked, p_node, p_item );
1180 vlc_gc_decref( p_input );
1182 [self playlistUpdated];
1183 vlc_object_release( p_playlist );
1186 - (NSMutableArray *)subSearchItem:(playlist_item_t *)p_item
1188 playlist_t *p_playlist = pl_Hold( VLCIntf );
1189 playlist_item_t *p_selected_item;
1190 int i_current, i_selected_row;
1192 i_selected_row = [o_outline_view selectedRow];
1193 if (i_selected_row < 0)
1196 p_selected_item = (playlist_item_t *)[[o_outline_view itemAtRow:
1197 i_selected_row] pointerValue];
1199 for( i_current = 0; i_current < p_item->i_children ; i_current++ )
1202 NSString *o_current_name, *o_current_author;
1205 o_current_name = [NSString stringWithUTF8String:
1206 p_item->pp_children[i_current]->p_input->psz_name];
1207 psz_temp = input_item_GetInfo( p_item->p_input ,
1208 _("Meta-information"),_("Artist") );
1209 o_current_author = [NSString stringWithUTF8String: psz_temp];
1213 if( p_selected_item == p_item->pp_children[i_current] &&
1214 b_selected_item_met == NO )
1216 b_selected_item_met = YES;
1218 else if( p_selected_item == p_item->pp_children[i_current] &&
1219 b_selected_item_met == YES )
1221 vlc_object_release( p_playlist );
1224 else if( b_selected_item_met == YES &&
1225 ( [o_current_name rangeOfString:[o_search_field
1226 stringValue] options:NSCaseInsensitiveSearch].length ||
1227 [o_current_author rangeOfString:[o_search_field
1228 stringValue] options:NSCaseInsensitiveSearch].length ) )
1230 vlc_object_release( p_playlist );
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 vlc_object_release( p_playlist );
1243 [o_result insertObject: [NSValue valueWithPointer:
1244 p_item->pp_children[i_current]] atIndex:0];
1249 vlc_object_release( p_playlist );
1253 - (IBAction)searchItem:(id)sender
1255 playlist_t * p_playlist = pl_Hold( VLCIntf );
1261 b_selected_item_met = NO;
1263 /*First, only search after the selected item:*
1264 *(b_selected_item_met = NO) */
1265 o_result = [self subSearchItem:p_playlist->p_root_category];
1266 if( o_result == NULL )
1268 /* If the first search failed, search again from the beginning */
1269 o_result = [self subSearchItem:p_playlist->p_root_category];
1271 if( o_result != NULL )
1274 if( [[o_result objectAtIndex: 0] pointerValue] ==
1275 p_playlist->p_local_category )
1280 for( i = i_start ; i < [o_result count] - 1 ; i++ )
1282 [o_outline_view expandItem: [o_outline_dict objectForKey:
1283 [NSString stringWithFormat: @"%p",
1284 [[o_result objectAtIndex: i] pointerValue]]]];
1286 i_row = [o_outline_view rowForItem: [o_outline_dict objectForKey:
1287 [NSString stringWithFormat: @"%p",
1288 [[o_result objectAtIndex: [o_result count] - 1 ]
1293 [o_outline_view selectRow:i_row byExtendingSelection: NO];
1294 [o_outline_view scrollRowToVisible: i_row];
1296 vlc_object_release( p_playlist );
1299 - (IBAction)recursiveExpandNode:(id)sender
1301 id o_item = [o_outline_view itemAtRow: [o_outline_view selectedRow]];
1302 playlist_item_t *p_item = (playlist_item_t *)[o_item pointerValue];
1304 if( ![[o_outline_view dataSource] outlineView: o_outline_view
1305 isItemExpandable: o_item] )
1307 o_item = [o_outline_dict objectForKey: [NSString
1308 stringWithFormat: @"%p", p_item->p_parent]];
1311 /* We need to collapse the node first, since OSX refuses to recursively
1312 expand an already expanded node, even if children nodes are collapsed. */
1313 [o_outline_view collapseItem: o_item collapseChildren: YES];
1314 [o_outline_view expandItem: o_item expandChildren: YES];
1317 - (NSMenu *)menuForEvent:(NSEvent *)o_event
1323 pt = [o_outline_view convertPoint: [o_event locationInWindow]
1325 int row = [o_outline_view rowAtPoint:pt];
1327 [o_outline_view selectRowIndexes:[NSIndexSet indexSetWithIndex:row] byExtendingSelection:NO];
1329 b_item_sel = ( row != -1 && [o_outline_view selectedRow] != -1 );
1330 b_rows = [o_outline_view numberOfRows] != 0;
1332 [o_mi_play setEnabled: b_item_sel];
1333 [o_mi_delete setEnabled: b_item_sel];
1334 [o_mi_selectall setEnabled: b_rows];
1335 [o_mi_info setEnabled: b_item_sel];
1336 [o_mi_preparse setEnabled: b_item_sel];
1337 [o_mi_recursive_expand setEnabled: b_item_sel];
1338 [o_mi_sort_name setEnabled: b_item_sel];
1339 [o_mi_sort_author setEnabled: b_item_sel];
1341 return( o_ctx_menu );
1344 - (void)outlineView: (NSOutlineView *)o_tv
1345 didClickTableColumn:(NSTableColumn *)o_tc
1347 int i_mode, i_type = 0;
1348 intf_thread_t *p_intf = VLCIntf;
1350 playlist_t *p_playlist = pl_Hold( p_intf );
1352 /* Check whether the selected table column header corresponds to a
1353 sortable table column*/
1354 if( !( o_tc == o_tc_name || o_tc == o_tc_author ) )
1356 vlc_object_release( p_playlist );
1360 if( o_tc_sortColumn == o_tc )
1362 b_isSortDescending = !b_isSortDescending;
1366 b_isSortDescending = false;
1369 if( o_tc == o_tc_name )
1371 i_mode = SORT_TITLE;
1373 else if( o_tc == o_tc_author )
1375 i_mode = SORT_ARTIST;
1378 if( b_isSortDescending )
1380 i_type = ORDER_REVERSE;
1384 i_type = ORDER_NORMAL;
1388 playlist_RecursiveNodeSort( p_playlist, p_playlist->p_root_category, i_mode, i_type );
1391 vlc_object_release( p_playlist );
1392 [self playlistUpdated];
1394 o_tc_sortColumn = o_tc;
1395 [o_outline_view setHighlightedTableColumn:o_tc];
1397 if( b_isSortDescending )
1399 [o_outline_view setIndicatorImage:o_descendingSortingImage
1400 inTableColumn:o_tc];
1404 [o_outline_view setIndicatorImage:o_ascendingSortingImage
1405 inTableColumn:o_tc];
1410 - (void)outlineView:(NSOutlineView *)outlineView
1411 willDisplayCell:(id)cell
1412 forTableColumn:(NSTableColumn *)tableColumn
1415 playlist_t *p_playlist = pl_Hold( VLCIntf );
1419 o_playing_item = [o_outline_dict objectForKey:
1420 [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]];
1432 vlc_object_release( p_playlist );
1435 - (IBAction)addNode:(id)sender
1437 /* we have to create a new thread here because otherwise we would block the
1438 * interface since the interaction-stuff and this code would run in the same
1440 [NSThread detachNewThreadSelector: @selector(addNodeThreadedly)
1441 toTarget: self withObject:nil];
1442 [self playlistUpdated];
1445 - (void)addNodeThreadedly
1447 NSAutoreleasePool * ourPool = [[NSAutoreleasePool alloc] init];
1449 /* simply adds a new node to the end of the playlist */
1450 playlist_t * p_playlist = pl_Hold( VLCIntf );
1451 vlc_thread_set_priority( p_playlist, VLC_THREAD_PRIORITY_LOW );
1454 char *psz_name = NULL;
1455 ret_v = intf_UserStringInput( p_playlist, _("New Node"),
1456 _("Please enter a name for the new node."), &psz_name );
1459 if( ret_v != DIALOG_CANCELLED && psz_name )
1461 playlist_NodeCreate( p_playlist, psz_name,
1462 p_playlist->p_local_category, 0, NULL );
1464 else if(! config_GetInt( p_playlist, "interact" ) )
1466 /* in case that the interaction is disabled, just give it a bogus name */
1467 playlist_NodeCreate( p_playlist, _("Empty Folder"),
1468 p_playlist->p_local_category, 0, NULL );
1473 pl_Release( VLCIntf );
1479 @implementation VLCPlaylist (NSOutlineViewDataSource)
1481 - (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item
1483 id o_value = [super outlineView: outlineView child: index ofItem: item];
1484 playlist_t *p_playlist = pl_Hold( VLCIntf );
1487 if( playlist_CurrentSize( p_playlist ) >= 2 )
1489 [o_status_field setStringValue: [NSString stringWithFormat:
1491 playlist_CurrentSize( p_playlist )]];
1495 if( playlist_IsEmpty( p_playlist ) )
1497 [o_status_field setStringValue: _NS("No items in the playlist")];
1501 [o_status_field setStringValue: _NS("1 item")];
1506 vlc_object_release( p_playlist );
1508 [o_outline_dict setObject:o_value forKey:[NSString stringWithFormat:@"%p",
1509 [o_value pointerValue]]];
1514 /* Required for drag & drop and reordering */
1515 - (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pboard
1518 playlist_t *p_playlist = pl_Hold( VLCIntf );
1520 /* First remove the items that were moved during the last drag & drop
1522 [o_items_array removeAllObjects];
1523 [o_nodes_array removeAllObjects];
1525 for( i = 0 ; i < [items count] ; i++ )
1527 id o_item = [items objectAtIndex: i];
1529 /* Refuse to move items that are not in the General Node
1530 (Service Discovery) */
1531 if( ![self isItem: [o_item pointerValue] inNode:
1532 p_playlist->p_local_category checkItemExistence: NO] &&
1533 var_CreateGetBool( p_playlist, "media-library" ) &&
1534 ![self isItem: [o_item pointerValue] inNode:
1535 p_playlist->p_ml_category checkItemExistence: NO] ||
1536 [o_item pointerValue] == p_playlist->p_local_category ||
1537 [o_item pointerValue] == p_playlist->p_ml_category )
1539 vlc_object_release(p_playlist);
1542 /* Fill the items and nodes to move in 2 different arrays */
1543 if( ((playlist_item_t *)[o_item pointerValue])->i_children > 0 )
1544 [o_nodes_array addObject: o_item];
1546 [o_items_array addObject: o_item];
1549 /* Now we need to check if there are selected items that are in already
1550 selected nodes. In that case, we only want to move the nodes */
1551 [self removeItemsFrom: o_nodes_array ifChildrenOf: o_nodes_array];
1552 [self removeItemsFrom: o_items_array ifChildrenOf: o_nodes_array];
1554 /* We add the "VLCPlaylistItemPboardType" type to be able to recognize
1555 a Drop operation coming from the playlist. */
1557 [pboard declareTypes: [NSArray arrayWithObjects:
1558 @"VLCPlaylistItemPboardType", nil] owner: self];
1559 [pboard setData:[NSData data] forType:@"VLCPlaylistItemPboardType"];
1561 vlc_object_release(p_playlist);
1565 - (NSDragOperation)outlineView:(NSOutlineView *)outlineView validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(NSInteger)index
1567 playlist_t *p_playlist = pl_Hold( VLCIntf );
1568 NSPasteboard *o_pasteboard = [info draggingPasteboard];
1570 if( !p_playlist ) return NSDragOperationNone;
1572 /* Dropping ON items is not allowed if item is not a node */
1575 if( index == NSOutlineViewDropOnItemIndex &&
1576 ((playlist_item_t *)[item pointerValue])->i_children == -1 )
1578 vlc_object_release( p_playlist );
1579 return NSDragOperationNone;
1583 /* Don't allow on drop on playlist root element's child */
1584 if( !item && index != NSOutlineViewDropOnItemIndex)
1586 vlc_object_release( p_playlist );
1587 return NSDragOperationNone;
1590 /* We refuse to drop an item in anything else than a child of the General
1591 Node. We still accept items that would be root nodes of the outlineview
1592 however, to allow drop in an empty playlist. */
1593 if( !( ([self isItem: [item pointerValue] inNode: p_playlist->p_local_category checkItemExistence: NO] ||
1594 ( var_CreateGetBool( p_playlist, "media-library" ) && [self isItem: [item pointerValue] inNode: p_playlist->p_ml_category checkItemExistence: NO] ) ) || item == nil ) )
1596 vlc_object_release( p_playlist );
1597 return NSDragOperationNone;
1600 /* Drop from the Playlist */
1601 if( [[o_pasteboard types] containsObject: @"VLCPlaylistItemPboardType"] )
1604 for( i = 0 ; i < [o_nodes_array count] ; i++ )
1606 /* We refuse to Drop in a child of an item we are moving */
1607 if( [self isItem: [item pointerValue] inNode:
1608 [[o_nodes_array objectAtIndex: i] pointerValue]
1609 checkItemExistence: NO] )
1611 vlc_object_release( p_playlist );
1612 return NSDragOperationNone;
1615 vlc_object_release( p_playlist );
1616 return NSDragOperationMove;
1619 /* Drop from the Finder */
1620 else if( [[o_pasteboard types] containsObject: NSFilenamesPboardType] )
1622 vlc_object_release( p_playlist );
1623 return NSDragOperationGeneric;
1625 vlc_object_release( p_playlist );
1626 return NSDragOperationNone;
1629 - (BOOL)outlineView:(NSOutlineView *)outlineView acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(NSInteger)index
1631 playlist_t * p_playlist = pl_Hold( VLCIntf );
1632 NSPasteboard *o_pasteboard = [info draggingPasteboard];
1634 /* Drag & Drop inside the playlist */
1635 if( [[o_pasteboard types] containsObject: @"VLCPlaylistItemPboardType"] )
1637 int i_row, i_removed_from_node = 0;
1639 playlist_item_t *p_new_parent, *p_item = NULL;
1640 NSArray *o_all_items = [o_nodes_array arrayByAddingObjectsFromArray:
1642 /* If the item is to be dropped as root item of the outline, make it a
1643 child of the General node.
1644 Else, choose the proposed parent as parent. */
1645 if( item == nil ) p_new_parent = p_playlist->p_local_category;
1646 else p_new_parent = [item pointerValue];
1648 /* Make sure the proposed parent is a node.
1649 (This should never be true) */
1650 if( p_new_parent->i_children < 0 )
1652 vlc_object_release( p_playlist );
1656 for( i = 0; i < [o_all_items count]; i++ )
1658 playlist_item_t *p_old_parent = NULL;
1659 int i_old_index = 0;
1661 p_item = [[o_all_items objectAtIndex:i] pointerValue];
1662 p_old_parent = p_item->p_parent;
1665 /* We may need the old index later */
1666 if( p_new_parent == p_old_parent )
1669 for( j = 0; j < p_old_parent->i_children; j++ )
1671 if( p_old_parent->pp_children[j] == p_item )
1680 // Actually detach the item from the old position
1681 if( playlist_NodeRemoveItem( p_playlist, p_item, p_old_parent ) ==
1685 /* Calculate the new index */
1688 /* If we move the item in the same node, we need to take into
1689 account that one item will be deleted */
1692 if ((p_new_parent == p_old_parent &&
1693 i_old_index < index + (int)i) )
1695 i_removed_from_node++;
1697 i_new_index = index + i - i_removed_from_node;
1699 // Reattach the item to the new position
1700 playlist_NodeInsert( p_playlist, p_item, p_new_parent, i_new_index );
1704 [self playlistUpdated];
1705 i_row = [o_outline_view rowForItem:[o_outline_dict
1706 objectForKey:[NSString stringWithFormat: @"%p",
1707 [[o_all_items objectAtIndex: 0] pointerValue]]]];
1711 i_row = [o_outline_view rowForItem:[o_outline_dict
1712 objectForKey:[NSString stringWithFormat: @"%p", p_new_parent]]];
1715 [o_outline_view deselectAll: self];
1716 [o_outline_view selectRow: i_row byExtendingSelection: NO];
1717 [o_outline_view scrollRowToVisible: i_row];
1719 vlc_object_release( p_playlist );
1723 else if( [[o_pasteboard types] containsObject: NSFilenamesPboardType] )
1726 playlist_item_t *p_node = [item pointerValue];
1728 NSArray *o_array = [NSArray array];
1729 NSArray *o_values = [[o_pasteboard propertyListForType:
1730 NSFilenamesPboardType]
1731 sortedArrayUsingSelector:
1732 @selector(caseInsensitiveCompare:)];
1734 for( i = 0; i < (int)[o_values count]; i++)
1736 NSDictionary *o_dic;
1737 o_dic = [NSDictionary dictionaryWithObject:[o_values
1738 objectAtIndex:i] forKey:@"ITEM_URL"];
1739 o_array = [o_array arrayByAddingObject: o_dic];
1744 [self appendArray:o_array atPos:index enqueue: YES];
1748 assert( p_node->i_children != -1 );
1749 [self appendNodeArray:o_array inNode: p_node
1750 atPos:index enqueue:YES];
1752 vlc_object_release( p_playlist );
1755 vlc_object_release( p_playlist );