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];
119 [o_outline_view expandItem: [o_outline_view itemAtRow:0]];
121 vlc_object_release( p_playlist );
127 [[o_tc_name headerCell] setStringValue:_NS("Name")];
128 [[o_tc_author headerCell] setStringValue:_NS("Author")];
129 [[o_tc_duration headerCell] setStringValue:_NS("Duration")];
132 - (NSOutlineView *)outlineView
134 return o_outline_view;
137 - (playlist_item_t *)selectedPlaylistItem
139 return [[o_outline_view itemAtRow: [o_outline_view selectedRow]]
145 @implementation VLCPlaylistCommon (NSOutlineViewDataSource)
147 /* return the number of children for Obj-C pointer item */ /* DONE */
148 - (int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
151 playlist_item_t *p_item = NULL;
152 playlist_t * p_playlist = pl_Hold( VLCIntf );
153 assert( outlineView == o_outline_view );
156 p_item = p_playlist->p_root_category;
158 p_item = (playlist_item_t *)[item pointerValue];
161 i_return = p_item->i_children;
163 pl_Release( VLCIntf );
165 return i_return > 0 ? i_return : 0;
168 /* return the child at index for the Obj-C pointer item */ /* DONE */
169 - (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item
171 playlist_item_t *p_return = NULL, *p_item = NULL;
173 playlist_t * p_playlist = pl_Hold( VLCIntf );
179 p_item = p_playlist->p_root_category;
183 p_item = (playlist_item_t *)[item pointerValue];
185 if( p_item && index < p_item->i_children && index >= 0 )
186 p_return = p_item->pp_children[index];
189 vlc_object_release( p_playlist );
191 o_value = [o_outline_dict objectForKey:[NSString stringWithFormat: @"%p", p_return]];
195 /* Why is there a warning if that happens all the time and seems
196 * to be normal? Add an assert and fix it.
197 * msg_Warn( VLCIntf, "playlist item misses pointer value, adding one" ); */
198 o_value = [[NSValue valueWithPointer: p_return] retain];
203 /* is the item expandable */
204 - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item
207 playlist_t *p_playlist = pl_Hold( VLCIntf );
212 if( p_playlist->p_root_category )
214 i_return = p_playlist->p_root_category->i_children;
219 playlist_item_t *p_item = (playlist_item_t *)[item pointerValue];
221 i_return = p_item->i_children;
223 pl_Release( VLCIntf );
225 return (i_return >= 0);
228 /* retrieve the string values for the cells */
229 - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)o_tc byItem:(id)item
232 playlist_item_t *p_item;
234 /* For error handling */
235 static BOOL attempted_reload = NO;
237 if( item == nil || ![item isKindOfClass: [NSValue class]] )
239 /* Attempt to fix the error by asking for a data redisplay
240 * This might cause infinite loop, so add a small check */
241 if( !attempted_reload )
243 attempted_reload = YES;
244 [outlineView reloadData];
249 p_item = (playlist_item_t *)[item pointerValue];
250 if( !p_item || !p_item->p_input )
252 /* Attempt to fix the error by asking for a data redisplay
253 * This might cause infinite loop, so add a small check */
254 if( !attempted_reload )
256 attempted_reload = YES;
257 [outlineView reloadData];
262 attempted_reload = NO;
264 if( [[o_tc identifier] isEqualToString:@"name"] )
266 /* sanity check to prevent the NSString class from crashing */
267 char *psz_title = input_item_GetTitle( p_item->p_input );
268 if( !EMPTY_STR( psz_title ) )
270 o_value = [NSString stringWithUTF8String: psz_title];
274 char *psz_name = input_item_GetName( p_item->p_input );
276 o_value = [NSString stringWithUTF8String: psz_name];
281 else if( [[o_tc identifier] isEqualToString:@"artist"] )
283 char *psz_artist = input_item_GetArtist( p_item->p_input );
285 o_value = [NSString stringWithUTF8String: psz_artist];
288 else if( [[o_tc identifier] isEqualToString:@"duration"] )
290 char psz_duration[MSTRTIME_MAX_SIZE];
291 mtime_t dur = input_item_GetDuration( p_item->p_input );
294 secstotimestr( psz_duration, dur/1000000 );
295 o_value = [NSString stringWithUTF8String: psz_duration];
300 else if( [[o_tc identifier] isEqualToString:@"status"] )
302 if( input_item_HasErrorWhenReading( p_item->p_input ) )
304 o_value = [NSImage imageWithWarningIcon];
312 /*****************************************************************************
313 * VLCPlaylistWizard implementation
314 *****************************************************************************/
315 @implementation VLCPlaylistWizard
317 - (IBAction)reloadOutlineView
319 /* Only reload the outlineview if the wizard window is open since this can
320 be quite long on big playlists */
321 if( [[o_outline_view window] isVisible] )
323 [o_outline_view reloadData];
329 /*****************************************************************************
330 * extension to NSOutlineView's interface to fix compilation warnings
331 * and let us access these 2 functions properly
332 * this uses a private Apple-API, but works fine on all current OSX releases
333 * keep checking for compatiblity with future releases though
334 *****************************************************************************/
336 @interface NSOutlineView (UndocumentedSortImages)
337 + (NSImage *)_defaultTableHeaderSortImage;
338 + (NSImage *)_defaultTableHeaderReverseSortImage;
342 /*****************************************************************************
343 * VLCPlaylist implementation
344 *****************************************************************************/
345 @implementation VLCPlaylist
352 o_nodes_array = [[NSMutableArray alloc] init];
353 o_items_array = [[NSMutableArray alloc] init];
360 [o_nodes_array release];
361 [o_items_array release];
367 playlist_t * p_playlist = pl_Hold( VLCIntf );
371 [super awakeFromNib];
373 [o_outline_view setDoubleAction: @selector(playItem:)];
375 [o_outline_view registerForDraggedTypes:
376 [NSArray arrayWithObjects: NSFilenamesPboardType,
377 @"VLCPlaylistItemPboardType", nil]];
378 [o_outline_view setIntercellSpacing: NSMakeSize (0.0, 1.0)];
380 /* This uses private Apple API which works fine until 10.5.
381 * We need to keep checking in the future!
382 * These methods are being added artificially to NSOutlineView's interface above */
383 o_ascendingSortingImage = [[NSOutlineView class] _defaultTableHeaderSortImage];
384 o_descendingSortingImage = [[NSOutlineView class] _defaultTableHeaderReverseSortImage];
386 o_tc_sortColumn = nil;
389 char ** ppsz_services = services_discovery_GetServicesNames( p_playlist, &ppsz_name );
392 vlc_object_release( p_playlist );
396 for( i = 0; ppsz_services[i]; i++ )
401 char * name = ppsz_name[i] ? ppsz_name[i] : ppsz_services[i];
402 /* Check whether to enable these menuitems */
403 b_enabled = playlist_IsServicesDiscoveryLoaded( p_playlist, ppsz_services[i] );
405 /* Create the menu entries used in the playlist menu */
406 o_lmi = [[o_mi_services submenu] addItemWithTitle:
407 [NSString stringWithUTF8String: name]
408 action: @selector(servicesChange:)
410 [o_lmi setTarget: self];
411 [o_lmi setRepresentedObject: [NSString stringWithUTF8String: ppsz_services[i]]];
412 if( b_enabled ) [o_lmi setState: NSOnState];
414 /* Create the menu entries for the main menu */
415 o_lmi = [[o_mm_mi_services submenu] addItemWithTitle:
416 [NSString stringWithUTF8String: name]
417 action: @selector(servicesChange:)
419 [o_lmi setTarget: self];
420 [o_lmi setRepresentedObject: [NSString stringWithUTF8String: ppsz_services[i]]];
421 if( b_enabled ) [o_lmi setState: NSOnState];
423 free( ppsz_services[i] );
424 free( ppsz_name[i] );
426 free( ppsz_services );
429 vlc_object_release( p_playlist );
432 - (void)searchfieldChanged:(NSNotification *)o_notification
434 [o_search_field setStringValue:[[o_notification object] stringValue]];
441 [o_mi_save_playlist setTitle: _NS("Save Playlist...")];
442 [o_mi_play setTitle: _NS("Play")];
443 [o_mi_delete setTitle: _NS("Delete")];
444 [o_mi_recursive_expand setTitle: _NS("Expand Node")];
445 [o_mi_selectall setTitle: _NS("Select All")];
446 [o_mi_info setTitle: _NS("Media Information...")];
447 [o_mi_dl_cover_art setTitle: _NS("Download Cover Art")];
448 [o_mi_preparse setTitle: _NS("Fetch Meta Data")];
449 [o_mi_revealInFinder setTitle: _NS("Reveal in Finder")];
450 [o_mm_mi_revealInFinder setTitle: _NS("Reveal in Finder")];
451 [[o_mm_mi_revealInFinder menu] setAutoenablesItems: NO];
452 [o_mi_sort_name setTitle: _NS("Sort Node by Name")];
453 [o_mi_sort_author setTitle: _NS("Sort Node by Author")];
454 [o_mi_services setTitle: _NS("Services discovery")];
455 [o_mm_mi_services setTitle: _NS("Services discovery")];
456 [o_status_field setStringValue: _NS("No items in the playlist")];
458 [o_search_field setToolTip: _NS("Search in Playlist")];
459 [o_mi_addNode setTitle: _NS("Add Folder to Playlist")];
461 [o_save_accessory_text setStringValue: _NS("File Format:")];
462 [[o_save_accessory_popup itemAtIndex:0] setTitle: _NS("Extended M3U")];
463 [[o_save_accessory_popup itemAtIndex:1] setTitle: _NS("XML Shareable Playlist Format (XSPF)")];
466 - (void)playlistUpdated
468 /* Clear indications of any existing column sorting */
469 for( unsigned int i = 0 ; i < [[o_outline_view tableColumns] count] ; i++ )
471 [o_outline_view setIndicatorImage:nil inTableColumn:
472 [[o_outline_view tableColumns] objectAtIndex:i]];
475 [o_outline_view setHighlightedTableColumn:nil];
476 o_tc_sortColumn = nil;
477 // TODO Find a way to keep the dict size to a minimum
478 //[o_outline_dict removeAllObjects];
479 [o_outline_view reloadData];
480 [[[[VLCMain sharedInstance] getWizard] getPlaylistWizard] reloadOutlineView];
481 [[[[VLCMain sharedInstance] getBookmarks] getDataTable] reloadData];
483 playlist_t *p_playlist = pl_Hold( VLCIntf );
486 if( playlist_CurrentSize( p_playlist ) >= 2 )
488 [o_status_field setStringValue: [NSString stringWithFormat:
490 playlist_CurrentSize( p_playlist )]];
494 if( playlist_IsEmpty( p_playlist ) )
495 [o_status_field setStringValue: _NS("No items in the playlist")];
497 [o_status_field setStringValue: _NS("1 item")];
500 vlc_object_release( p_playlist );
502 [self outlineViewSelectionDidChange: nil];
505 - (void)playModeUpdated
507 playlist_t *p_playlist = pl_Hold( VLCIntf );
509 bool loop = var_GetBool( p_playlist, "loop" );
510 bool repeat = var_GetBool( p_playlist, "repeat" );
512 [[[VLCMain sharedInstance] getControls] repeatOne];
514 [[[VLCMain sharedInstance] getControls] repeatAll];
516 [[[VLCMain sharedInstance] getControls] repeatOff];
518 [[[VLCMain sharedInstance] getControls] shuffle];
520 vlc_object_release( p_playlist );
523 - (void)outlineViewSelectionDidChange:(NSNotification *)notification
526 playlist_item_t * p_item = [[o_outline_view itemAtRow:[o_outline_view selectedRow]] pointerValue];
530 /* update the state of our Reveal-in-Finder menu items */
531 NSMutableString *o_mrl;
532 char *psz_uri = input_item_GetURI( p_item->p_input );
535 o_mrl = [NSMutableString stringWithUTF8String: psz_uri];
537 /* perform some checks whether it is a file and if it is local at all... */
538 NSRange prefix_range = [o_mrl rangeOfString: @"file:"];
539 if( prefix_range.location != NSNotFound )
540 [o_mrl deleteCharactersInRange: prefix_range];
542 if( [o_mrl characterAtIndex:0] == '/' )
544 [o_mi_revealInFinder setEnabled: YES];
545 [o_mm_mi_revealInFinder setEnabled: YES];
549 [o_mi_revealInFinder setEnabled: NO];
550 [o_mm_mi_revealInFinder setEnabled: NO];
554 - (BOOL)isSelectionEmpty
556 return [o_outline_view selectedRow] == -1;
559 - (void)updateRowSelection
565 playlist_t *p_playlist = pl_Hold( VLCIntf );
566 playlist_item_t *p_item, *p_temp_item;
567 NSMutableArray *o_array = [NSMutableArray array];
569 p_item = playlist_CurrentPlayingItem( p_playlist );
572 pl_Release( VLCIntf );
576 p_temp_item = p_item;
577 while( p_temp_item->p_parent )
579 [o_array insertObject: [NSValue valueWithPointer: p_temp_item] atIndex: 0];
580 p_temp_item = p_temp_item->p_parent;
583 for( j = 0; j < [o_array count] - 1; j++ )
586 if( ( o_item = [o_outline_dict objectForKey:
587 [NSString stringWithFormat: @"%p",
588 [[o_array objectAtIndex:j] pointerValue]]] ) != nil )
590 [o_outline_view expandItem: o_item];
595 pl_Release( VLCIntf );
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_Hold( 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_Hold( 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_Hold( 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_Hold( 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, pl_Unlocked );
845 msg_Dbg( p_intf, "preparsing nodes not implemented" );
849 vlc_object_release( p_playlist );
850 [self playlistUpdated];
853 - (IBAction)downloadCoverArt:(id)sender
856 NSMutableArray *o_to_preparse;
857 intf_thread_t * p_intf = VLCIntf;
858 playlist_t * p_playlist = pl_Hold( p_intf );
860 o_to_preparse = [NSMutableArray arrayWithArray:[[o_outline_view selectedRowEnumerator] allObjects]];
861 i_count = [o_to_preparse count];
865 playlist_item_t *p_item = NULL;
867 for( i = 0; i < i_count; i++ )
869 o_number = [o_to_preparse lastObject];
870 i_row = [o_number intValue];
871 p_item = [[o_outline_view itemAtRow:i_row] pointerValue];
872 [o_to_preparse removeObject: o_number];
873 [o_outline_view deselectRow: i_row];
875 if( p_item && p_item->i_children == -1 )
877 playlist_AskForArtEnqueue( p_playlist, p_item->p_input, pl_Unlocked );
880 vlc_object_release( p_playlist );
881 [self playlistUpdated];
884 - (IBAction)servicesChange:(id)sender
886 NSMenuItem *o_mi = (NSMenuItem *)sender;
887 NSString *o_string = [o_mi representedObject];
888 playlist_t * p_playlist = pl_Hold( VLCIntf );
889 if( !playlist_IsServicesDiscoveryLoaded( p_playlist, [o_string UTF8String] ) )
890 playlist_ServicesDiscoveryAdd( p_playlist, [o_string UTF8String] );
892 playlist_ServicesDiscoveryRemove( p_playlist, [o_string UTF8String] );
894 [o_mi setState: playlist_IsServicesDiscoveryLoaded( p_playlist,
895 [o_string UTF8String] ) ? YES : NO];
897 vlc_object_release( p_playlist );
898 [self playlistUpdated];
902 - (IBAction)selectAll:(id)sender
904 [o_outline_view selectAll: nil];
907 - (IBAction)deleteItem:(id)sender
910 NSMutableArray *o_to_delete;
913 playlist_t * p_playlist;
914 intf_thread_t * p_intf = VLCIntf;
916 o_to_delete = [NSMutableArray arrayWithArray:[[o_outline_view selectedRowEnumerator] allObjects]];
917 i_count = [o_to_delete count];
919 p_playlist = pl_Hold( p_intf );
922 for( int i = 0; i < i_count; i++ )
924 o_number = [o_to_delete lastObject];
925 i_row = [o_number intValue];
926 id o_item = [o_outline_view itemAtRow: i_row];
927 playlist_item_t *p_item = [o_item pointerValue];
929 msg_Dbg( p_intf, "deleting item %i (of %i) with id \"%i\", pointerValue \"%p\" and %i children", i+1, i_count,
930 p_item->p_input->i_id, [o_item pointerValue], p_item->i_children +1 );
932 [o_to_delete removeObject: o_number];
933 [o_outline_view deselectRow: i_row];
935 if( p_item->i_children != -1 )
936 //is a node and not an item
938 if( playlist_Status( p_playlist ) != PLAYLIST_STOPPED &&
939 [self isItem: playlist_CurrentPlayingItem( p_playlist ) inNode:
940 ((playlist_item_t *)[o_item pointerValue])
941 checkItemExistence: NO locked:YES] == YES )
942 // if current item is in selected node and is playing then stop playlist
943 playlist_Control(p_playlist, PLAYLIST_STOP, pl_Locked );
945 playlist_NodeDelete( p_playlist, p_item, true, false );
948 playlist_DeleteFromInput( p_playlist, p_item->p_input->i_id, pl_Locked );
952 [self playlistUpdated];
953 vlc_object_release( p_playlist );
956 - (IBAction)sortNodeByName:(id)sender
958 [self sortNode: SORT_TITLE];
961 - (IBAction)sortNodeByAuthor:(id)sender
963 [self sortNode: SORT_ARTIST];
966 - (void)sortNode:(int)i_mode
968 playlist_t * p_playlist = pl_Hold( VLCIntf );
969 playlist_item_t * p_item;
971 if( [o_outline_view selectedRow] > -1 )
973 p_item = [[o_outline_view itemAtRow: [o_outline_view selectedRow]] pointerValue];
976 /*If no item is selected, sort the whole playlist*/
978 p_item = p_playlist->p_root_category;
981 if( p_item->i_children > -1 ) // the item is a node
984 playlist_RecursiveNodeSort( p_playlist, p_item, i_mode, ORDER_NORMAL );
990 playlist_RecursiveNodeSort( p_playlist,
991 p_item->p_parent, i_mode, ORDER_NORMAL );
994 vlc_object_release( p_playlist );
995 [self playlistUpdated];
998 - (input_item_t *)createItem:(NSDictionary *)o_one_item
1000 intf_thread_t * p_intf = VLCIntf;
1001 playlist_t * p_playlist = pl_Hold( p_intf );
1003 input_item_t *p_input;
1005 BOOL b_rem = FALSE, b_dir = FALSE;
1006 NSString *o_uri, *o_name;
1011 o_uri = (NSString *)[o_one_item objectForKey: @"ITEM_URL"];
1012 o_name = (NSString *)[o_one_item objectForKey: @"ITEM_NAME"];
1013 o_options = (NSArray *)[o_one_item objectForKey: @"ITEM_OPTIONS"];
1015 /* Find the name for a disc entry (i know, can you believe the trouble?) */
1016 if( ( !o_name || [o_name isEqualToString:@""] ) && [o_uri rangeOfString: @"/dev/"].location != NSNotFound )
1018 int i_count, i_index;
1019 struct statfs *mounts = NULL;
1021 i_count = getmntinfo (&mounts, MNT_NOWAIT);
1022 /* getmntinfo returns a pointer to static data. Do not free. */
1023 for( i_index = 0 ; i_index < i_count; i_index++ )
1025 NSMutableString *o_temp, *o_temp2;
1026 o_temp = [NSMutableString stringWithString: o_uri];
1027 o_temp2 = [NSMutableString stringWithUTF8String: mounts[i_index].f_mntfromname];
1028 [o_temp replaceOccurrencesOfString: @"/dev/rdisk" withString: @"/dev/disk" options:NSLiteralSearch range:NSMakeRange(0, [o_temp length]) ];
1029 [o_temp2 replaceOccurrencesOfString: @"s0" withString: @"" options:NSLiteralSearch range:NSMakeRange(0, [o_temp2 length]) ];
1030 [o_temp2 replaceOccurrencesOfString: @"s1" withString: @"" options:NSLiteralSearch range:NSMakeRange(0, [o_temp2 length]) ];
1032 if( strstr( [o_temp fileSystemRepresentation], [o_temp2 fileSystemRepresentation] ) != NULL )
1034 o_name = [[NSFileManager defaultManager] displayNameAtPath: [NSString stringWithUTF8String:mounts[i_index].f_mntonname]];
1038 /* If no name, then make a guess */
1039 if( !o_name) o_name = [[NSFileManager defaultManager] displayNameAtPath: o_uri];
1041 if( [[NSFileManager defaultManager] fileExistsAtPath:o_uri isDirectory:&b_dir] && b_dir &&
1042 [[NSWorkspace sharedWorkspace] getFileSystemInfoForPath: o_uri isRemovable: &b_rem
1043 isWritable:NULL isUnmountable:NULL description:NULL type:NULL] && b_rem )
1045 /* All of this is to make sure CD's play when you D&D them on VLC */
1046 /* Converts mountpoint to a /dev file */
1049 NSMutableString *o_temp;
1051 buf = (struct statfs *) malloc (sizeof(struct statfs));
1052 statfs( [o_uri fileSystemRepresentation], buf );
1053 psz_dev = strdup(buf->f_mntfromname);
1054 o_temp = [NSMutableString stringWithUTF8String: psz_dev ];
1055 [o_temp replaceOccurrencesOfString: @"/dev/disk" withString: @"/dev/rdisk" options:NSLiteralSearch range:NSMakeRange(0, [o_temp length]) ];
1056 [o_temp replaceOccurrencesOfString: @"s0" withString: @"" options:NSLiteralSearch range:NSMakeRange(0, [o_temp length]) ];
1057 [o_temp replaceOccurrencesOfString: @"s1" withString: @"" options:NSLiteralSearch range:NSMakeRange(0, [o_temp length]) ];
1061 p_input = input_item_New( p_playlist, [o_uri fileSystemRepresentation], [o_name UTF8String] );
1067 for( i = 0; i < (int)[o_options count]; i++ )
1069 input_item_AddOption( p_input, strdup( [[o_options objectAtIndex:i] UTF8String] ) );
1073 /* Recent documents menu */
1074 o_true_file = [NSURL fileURLWithPath: o_uri];
1075 if( o_true_file != nil && (BOOL)config_GetInt( p_playlist, "macosx-recentitems" ) == YES )
1077 [[NSDocumentController sharedDocumentController]
1078 noteNewRecentDocumentURL: o_true_file];
1081 vlc_object_release( p_playlist );
1085 - (void)appendArray:(NSArray*)o_array atPos:(int)i_position enqueue:(BOOL)b_enqueue
1088 playlist_t * p_playlist = pl_Hold( VLCIntf );
1091 for( i_item = 0; i_item < (int)[o_array count]; i_item++ )
1093 input_item_t *p_input;
1094 NSDictionary *o_one_item;
1097 o_one_item = [o_array objectAtIndex: i_item];
1098 p_input = [self createItem: o_one_item];
1105 /* FIXME: playlist_AddInput() can fail */
1107 playlist_AddInput( p_playlist, p_input, PLAYLIST_INSERT,
1108 i_position == -1 ? PLAYLIST_END : i_position + i_item, true,
1111 if( i_item == 0 && !b_enqueue )
1113 playlist_item_t *p_item = NULL;
1114 playlist_item_t *p_node = NULL;
1115 p_item = playlist_ItemGetByInput( p_playlist, p_input, pl_Locked );
1118 if( p_item->i_children == -1 )
1119 p_node = p_item->p_parent;
1123 if( p_node->i_children > 0 && p_node->pp_children[0]->i_children == -1 )
1124 p_item = p_node->pp_children[0];
1128 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, pl_Locked, p_node, p_item );
1131 vlc_gc_decref( p_input );
1135 [self playlistUpdated];
1136 vlc_object_release( p_playlist );
1139 - (void)appendNodeArray:(NSArray*)o_array inNode:(playlist_item_t *)p_node atPos:(int)i_position enqueue:(BOOL)b_enqueue
1142 playlist_t * p_playlist = pl_Hold( VLCIntf );
1144 for( i_item = 0; i_item < (int)[o_array count]; i_item++ )
1146 input_item_t *p_input;
1147 NSDictionary *o_one_item;
1150 o_one_item = [o_array objectAtIndex: i_item];
1151 p_input = [self createItem: o_one_item];
1153 if( !p_input ) continue;
1156 /* FIXME: playlist_BothAddInput() can fail */
1158 playlist_BothAddInput( p_playlist, p_input, p_node,
1161 PLAYLIST_END : i_position + i_item,
1162 NULL, NULL, pl_Locked );
1165 if( i_item == 0 && !b_enqueue )
1167 playlist_item_t *p_item;
1168 p_item = playlist_ItemGetByInput( p_playlist, p_input, pl_Locked );
1169 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, pl_Locked, p_node, p_item );
1172 vlc_gc_decref( p_input );
1174 [self playlistUpdated];
1175 vlc_object_release( p_playlist );
1178 - (NSMutableArray *)subSearchItem:(playlist_item_t *)p_item
1180 playlist_t *p_playlist = pl_Hold( VLCIntf );
1181 playlist_item_t *p_selected_item;
1182 int i_current, i_selected_row;
1184 i_selected_row = [o_outline_view selectedRow];
1185 if (i_selected_row < 0)
1188 p_selected_item = (playlist_item_t *)[[o_outline_view itemAtRow:
1189 i_selected_row] pointerValue];
1191 for( i_current = 0; i_current < p_item->i_children ; i_current++ )
1194 NSString *o_current_name, *o_current_author;
1197 o_current_name = [NSString stringWithUTF8String:
1198 p_item->pp_children[i_current]->p_input->psz_name];
1199 psz_temp = input_item_GetInfo( p_item->p_input ,
1200 _("Meta-information"),_("Artist") );
1201 o_current_author = [NSString stringWithUTF8String: psz_temp];
1205 if( p_selected_item == p_item->pp_children[i_current] &&
1206 b_selected_item_met == NO )
1208 b_selected_item_met = YES;
1210 else if( p_selected_item == p_item->pp_children[i_current] &&
1211 b_selected_item_met == YES )
1213 vlc_object_release( p_playlist );
1216 else if( b_selected_item_met == YES &&
1217 ( [o_current_name rangeOfString:[o_search_field
1218 stringValue] options:NSCaseInsensitiveSearch].length ||
1219 [o_current_author rangeOfString:[o_search_field
1220 stringValue] options:NSCaseInsensitiveSearch].length ) )
1222 vlc_object_release( p_playlist );
1223 /*Adds the parent items in the result array as well, so that we can
1225 return [NSMutableArray arrayWithObject: [NSValue
1226 valueWithPointer: p_item->pp_children[i_current]]];
1228 if( p_item->pp_children[i_current]->i_children > 0 )
1230 id o_result = [self subSearchItem:
1231 p_item->pp_children[i_current]];
1232 if( o_result != NULL )
1234 vlc_object_release( p_playlist );
1235 [o_result insertObject: [NSValue valueWithPointer:
1236 p_item->pp_children[i_current]] atIndex:0];
1241 vlc_object_release( p_playlist );
1245 - (IBAction)searchItem:(id)sender
1247 playlist_t * p_playlist = pl_Hold( VLCIntf );
1253 b_selected_item_met = NO;
1255 /*First, only search after the selected item:*
1256 *(b_selected_item_met = NO) */
1257 o_result = [self subSearchItem:p_playlist->p_root_category];
1258 if( o_result == NULL )
1260 /* If the first search failed, search again from the beginning */
1261 o_result = [self subSearchItem:p_playlist->p_root_category];
1263 if( o_result != NULL )
1266 if( [[o_result objectAtIndex: 0] pointerValue] ==
1267 p_playlist->p_local_category )
1272 for( i = i_start ; i < [o_result count] - 1 ; i++ )
1274 [o_outline_view expandItem: [o_outline_dict objectForKey:
1275 [NSString stringWithFormat: @"%p",
1276 [[o_result objectAtIndex: i] pointerValue]]]];
1278 i_row = [o_outline_view rowForItem: [o_outline_dict objectForKey:
1279 [NSString stringWithFormat: @"%p",
1280 [[o_result objectAtIndex: [o_result count] - 1 ]
1285 [o_outline_view selectRow:i_row byExtendingSelection: NO];
1286 [o_outline_view scrollRowToVisible: i_row];
1288 vlc_object_release( p_playlist );
1291 - (IBAction)recursiveExpandNode:(id)sender
1293 id o_item = [o_outline_view itemAtRow: [o_outline_view selectedRow]];
1294 playlist_item_t *p_item = (playlist_item_t *)[o_item pointerValue];
1296 if( ![[o_outline_view dataSource] outlineView: o_outline_view
1297 isItemExpandable: o_item] )
1299 o_item = [o_outline_dict objectForKey: [NSString
1300 stringWithFormat: @"%p", p_item->p_parent]];
1303 /* We need to collapse the node first, since OSX refuses to recursively
1304 expand an already expanded node, even if children nodes are collapsed. */
1305 [o_outline_view collapseItem: o_item collapseChildren: YES];
1306 [o_outline_view expandItem: o_item expandChildren: YES];
1309 - (NSMenu *)menuForEvent:(NSEvent *)o_event
1315 pt = [o_outline_view convertPoint: [o_event locationInWindow]
1317 int row = [o_outline_view rowAtPoint:pt];
1319 [o_outline_view selectRowIndexes:[NSIndexSet indexSetWithIndex:row] byExtendingSelection:NO];
1321 b_item_sel = ( row != -1 && [o_outline_view selectedRow] != -1 );
1322 b_rows = [o_outline_view numberOfRows] != 0;
1324 [o_mi_play setEnabled: b_item_sel];
1325 [o_mi_delete setEnabled: b_item_sel];
1326 [o_mi_selectall setEnabled: b_rows];
1327 [o_mi_info setEnabled: b_item_sel];
1328 [o_mi_preparse setEnabled: b_item_sel];
1329 [o_mi_recursive_expand setEnabled: b_item_sel];
1330 [o_mi_sort_name setEnabled: b_item_sel];
1331 [o_mi_sort_author setEnabled: b_item_sel];
1333 return( o_ctx_menu );
1336 - (void)outlineView: (NSOutlineView *)o_tv
1337 didClickTableColumn:(NSTableColumn *)o_tc
1339 int i_mode, i_type = 0;
1340 intf_thread_t *p_intf = VLCIntf;
1342 playlist_t *p_playlist = pl_Hold( p_intf );
1344 /* Check whether the selected table column header corresponds to a
1345 sortable table column*/
1346 if( !( o_tc == o_tc_name || o_tc == o_tc_author ) )
1348 vlc_object_release( p_playlist );
1352 if( o_tc_sortColumn == o_tc )
1354 b_isSortDescending = !b_isSortDescending;
1358 b_isSortDescending = false;
1361 if( o_tc == o_tc_name )
1363 i_mode = SORT_TITLE;
1365 else if( o_tc == o_tc_author )
1367 i_mode = SORT_ARTIST;
1370 if( b_isSortDescending )
1372 i_type = ORDER_REVERSE;
1376 i_type = ORDER_NORMAL;
1380 playlist_RecursiveNodeSort( p_playlist, p_playlist->p_root_category, i_mode, i_type );
1383 vlc_object_release( p_playlist );
1384 [self playlistUpdated];
1386 o_tc_sortColumn = o_tc;
1387 [o_outline_view setHighlightedTableColumn:o_tc];
1389 if( b_isSortDescending )
1391 [o_outline_view setIndicatorImage:o_descendingSortingImage
1392 inTableColumn:o_tc];
1396 [o_outline_view setIndicatorImage:o_ascendingSortingImage
1397 inTableColumn:o_tc];
1402 - (void)outlineView:(NSOutlineView *)outlineView
1403 willDisplayCell:(id)cell
1404 forTableColumn:(NSTableColumn *)tableColumn
1407 playlist_t *p_playlist = pl_Hold( VLCIntf );
1411 o_playing_item = [o_outline_dict objectForKey:
1412 [NSString stringWithFormat:@"%p", playlist_CurrentPlayingItem( p_playlist )]];
1414 if( [self isItem: [o_playing_item pointerValue] inNode:
1415 [item pointerValue] checkItemExistence: YES]
1416 || [o_playing_item isEqual: item] )
1418 [cell setFont: [[NSFontManager sharedFontManager] convertFont:[cell font] toHaveTrait:NSBoldFontMask]];
1422 [cell setFont: [[NSFontManager sharedFontManager] convertFont:[cell font] toNotHaveTrait:NSBoldFontMask]];
1424 vlc_object_release( p_playlist );
1427 - (IBAction)addNode:(id)sender
1429 /* we have to create a new thread here because otherwise we would block the
1430 * interface since the interaction-stuff and this code would run in the same
1432 [NSThread detachNewThreadSelector: @selector(addNodeThreadedly)
1433 toTarget: self withObject:nil];
1434 [self playlistUpdated];
1437 - (void)addNodeThreadedly
1439 NSAutoreleasePool * ourPool = [[NSAutoreleasePool alloc] init];
1441 /* simply adds a new node to the end of the playlist */
1442 playlist_t * p_playlist = pl_Hold( VLCIntf );
1443 vlc_thread_set_priority( p_playlist, VLC_THREAD_PRIORITY_LOW );
1446 char *psz_name = NULL;
1447 ret_v = intf_UserStringInput( p_playlist, _("New Node"),
1448 _("Please enter a name for the new node."), &psz_name );
1451 if( ret_v != DIALOG_CANCELLED && psz_name )
1453 playlist_NodeCreate( p_playlist, psz_name,
1454 p_playlist->p_local_category, 0, NULL );
1456 else if(! config_GetInt( p_playlist, "interact" ) )
1458 /* in case that the interaction is disabled, just give it a bogus name */
1459 playlist_NodeCreate( p_playlist, _("Empty Folder"),
1460 p_playlist->p_local_category, 0, NULL );
1465 pl_Release( VLCIntf );
1471 @implementation VLCPlaylist (NSOutlineViewDataSource)
1473 - (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item
1475 id o_value = [super outlineView: outlineView child: index ofItem: item];
1476 playlist_t *p_playlist = pl_Hold( VLCIntf );
1479 if( playlist_CurrentSize( p_playlist ) >= 2 )
1481 [o_status_field setStringValue: [NSString stringWithFormat:
1483 playlist_CurrentSize( p_playlist )]];
1487 if( playlist_IsEmpty( p_playlist ) )
1489 [o_status_field setStringValue: _NS("No items in the playlist")];
1493 [o_status_field setStringValue: _NS("1 item")];
1498 vlc_object_release( p_playlist );
1500 [o_outline_dict setObject:o_value forKey:[NSString stringWithFormat:@"%p",
1501 [o_value pointerValue]]];
1506 /* Required for drag & drop and reordering */
1507 - (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pboard
1510 playlist_t *p_playlist = pl_Hold( VLCIntf );
1512 /* First remove the items that were moved during the last drag & drop
1514 [o_items_array removeAllObjects];
1515 [o_nodes_array removeAllObjects];
1517 for( i = 0 ; i < [items count] ; i++ )
1519 id o_item = [items objectAtIndex: i];
1521 /* Refuse to move items that are not in the General Node
1522 (Service Discovery) */
1523 if( ![self isItem: [o_item pointerValue] inNode:
1524 p_playlist->p_local_category checkItemExistence: NO] &&
1525 var_CreateGetBool( p_playlist, "media-library" ) &&
1526 ![self isItem: [o_item pointerValue] inNode:
1527 p_playlist->p_ml_category checkItemExistence: NO] ||
1528 [o_item pointerValue] == p_playlist->p_local_category ||
1529 [o_item pointerValue] == p_playlist->p_ml_category )
1531 vlc_object_release(p_playlist);
1534 /* Fill the items and nodes to move in 2 different arrays */
1535 if( ((playlist_item_t *)[o_item pointerValue])->i_children > 0 )
1536 [o_nodes_array addObject: o_item];
1538 [o_items_array addObject: o_item];
1541 /* Now we need to check if there are selected items that are in already
1542 selected nodes. In that case, we only want to move the nodes */
1543 [self removeItemsFrom: o_nodes_array ifChildrenOf: o_nodes_array];
1544 [self removeItemsFrom: o_items_array ifChildrenOf: o_nodes_array];
1546 /* We add the "VLCPlaylistItemPboardType" type to be able to recognize
1547 a Drop operation coming from the playlist. */
1549 [pboard declareTypes: [NSArray arrayWithObjects:
1550 @"VLCPlaylistItemPboardType", nil] owner: self];
1551 [pboard setData:[NSData data] forType:@"VLCPlaylistItemPboardType"];
1553 vlc_object_release(p_playlist);
1557 - (NSDragOperation)outlineView:(NSOutlineView *)outlineView validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(int)index
1559 playlist_t *p_playlist = pl_Hold( VLCIntf );
1560 NSPasteboard *o_pasteboard = [info draggingPasteboard];
1562 if( !p_playlist ) return NSDragOperationNone;
1564 /* Dropping ON items is not allowed if item is not a node */
1567 if( index == NSOutlineViewDropOnItemIndex &&
1568 ((playlist_item_t *)[item pointerValue])->i_children == -1 )
1570 vlc_object_release( p_playlist );
1571 return NSDragOperationNone;
1575 /* Don't allow on drop on playlist root element's child */
1576 if( !item && index != NSOutlineViewDropOnItemIndex)
1578 vlc_object_release( p_playlist );
1579 return NSDragOperationNone;
1582 /* We refuse to drop an item in anything else than a child of the General
1583 Node. We still accept items that would be root nodes of the outlineview
1584 however, to allow drop in an empty playlist. */
1585 if( !( ([self isItem: [item pointerValue] inNode: p_playlist->p_local_category checkItemExistence: NO] ||
1586 ( var_CreateGetBool( p_playlist, "media-library" ) && [self isItem: [item pointerValue] inNode: p_playlist->p_ml_category checkItemExistence: NO] ) ) || item == nil ) )
1588 vlc_object_release( p_playlist );
1589 return NSDragOperationNone;
1592 /* Drop from the Playlist */
1593 if( [[o_pasteboard types] containsObject: @"VLCPlaylistItemPboardType"] )
1596 for( i = 0 ; i < [o_nodes_array count] ; i++ )
1598 /* We refuse to Drop in a child of an item we are moving */
1599 if( [self isItem: [item pointerValue] inNode:
1600 [[o_nodes_array objectAtIndex: i] pointerValue]
1601 checkItemExistence: NO] )
1603 vlc_object_release( p_playlist );
1604 return NSDragOperationNone;
1607 vlc_object_release( p_playlist );
1608 return NSDragOperationMove;
1611 /* Drop from the Finder */
1612 else if( [[o_pasteboard types] containsObject: NSFilenamesPboardType] )
1614 vlc_object_release( p_playlist );
1615 return NSDragOperationGeneric;
1617 vlc_object_release( p_playlist );
1618 return NSDragOperationNone;
1621 - (BOOL)outlineView:(NSOutlineView *)outlineView acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(int)index
1623 playlist_t * p_playlist = pl_Hold( VLCIntf );
1624 NSPasteboard *o_pasteboard = [info draggingPasteboard];
1626 /* Drag & Drop inside the playlist */
1627 if( [[o_pasteboard types] containsObject: @"VLCPlaylistItemPboardType"] )
1629 int i_row, i_removed_from_node = 0;
1631 playlist_item_t *p_new_parent, *p_item = NULL;
1632 NSArray *o_all_items = [o_nodes_array arrayByAddingObjectsFromArray:
1634 /* If the item is to be dropped as root item of the outline, make it a
1635 child of the General node.
1636 Else, choose the proposed parent as parent. */
1637 if( item == nil ) p_new_parent = p_playlist->p_local_category;
1638 else p_new_parent = [item pointerValue];
1640 /* Make sure the proposed parent is a node.
1641 (This should never be true) */
1642 if( p_new_parent->i_children < 0 )
1644 vlc_object_release( p_playlist );
1648 for( i = 0; i < [o_all_items count]; i++ )
1650 playlist_item_t *p_old_parent = NULL;
1651 int i_old_index = 0;
1653 p_item = [[o_all_items objectAtIndex:i] pointerValue];
1654 p_old_parent = p_item->p_parent;
1657 /* We may need the old index later */
1658 if( p_new_parent == p_old_parent )
1661 for( j = 0; j < p_old_parent->i_children; j++ )
1663 if( p_old_parent->pp_children[j] == p_item )
1672 // Actually detach the item from the old position
1673 if( playlist_NodeRemoveItem( p_playlist, p_item, p_old_parent ) ==
1677 /* Calculate the new index */
1680 /* If we move the item in the same node, we need to take into
1681 account that one item will be deleted */
1684 if ((p_new_parent == p_old_parent &&
1685 i_old_index < index + (int)i) )
1687 i_removed_from_node++;
1689 i_new_index = index + i - i_removed_from_node;
1691 // Reattach the item to the new position
1692 playlist_NodeInsert( p_playlist, p_item, p_new_parent, i_new_index );
1696 [self playlistUpdated];
1697 i_row = [o_outline_view rowForItem:[o_outline_dict
1698 objectForKey:[NSString stringWithFormat: @"%p",
1699 [[o_all_items objectAtIndex: 0] pointerValue]]]];
1703 i_row = [o_outline_view rowForItem:[o_outline_dict
1704 objectForKey:[NSString stringWithFormat: @"%p", p_new_parent]]];
1707 [o_outline_view deselectAll: self];
1708 [o_outline_view selectRow: i_row byExtendingSelection: NO];
1709 [o_outline_view scrollRowToVisible: i_row];
1711 vlc_object_release( p_playlist );
1715 else if( [[o_pasteboard types] containsObject: NSFilenamesPboardType] )
1718 playlist_item_t *p_node = [item pointerValue];
1720 NSArray *o_array = [NSArray array];
1721 NSArray *o_values = [[o_pasteboard propertyListForType:
1722 NSFilenamesPboardType]
1723 sortedArrayUsingSelector:
1724 @selector(caseInsensitiveCompare:)];
1726 for( i = 0; i < (int)[o_values count]; i++)
1728 NSDictionary *o_dic;
1729 o_dic = [NSDictionary dictionaryWithObject:[o_values
1730 objectAtIndex:i] forKey:@"ITEM_URL"];
1731 o_array = [o_array arrayByAddingObject: o_dic];
1736 [self appendArray:o_array atPos:index enqueue: YES];
1740 assert( p_node->i_children != -1 );
1741 [self appendNodeArray:o_array inNode: p_node
1742 atPos:index enqueue:YES];
1744 vlc_object_release( p_playlist );
1747 vlc_object_release( p_playlist );