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 = vlc_sd_GetNames( &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];
552 if( [[VLCMain sharedInstance] isPlaylistCollapsed] == NO )
554 /* update our info-panel to reflect the new item, if we aren't collapsed */
555 [[[VLCMain sharedInstance] getInfo] updatePanelWithItem:p_item->p_input];
560 - (BOOL)isSelectionEmpty
562 return [o_outline_view selectedRow] == -1;
565 - (void)updateRowSelection
571 playlist_t *p_playlist = pl_Hold( VLCIntf );
572 playlist_item_t *p_item, *p_temp_item;
573 NSMutableArray *o_array = [NSMutableArray array];
575 p_item = playlist_CurrentPlayingItem( p_playlist );
578 pl_Release( VLCIntf );
582 p_temp_item = p_item;
583 while( p_temp_item->p_parent )
585 [o_array insertObject: [NSValue valueWithPointer: p_temp_item] atIndex: 0];
586 p_temp_item = p_temp_item->p_parent;
589 for( j = 0; j < [o_array count] - 1; j++ )
592 if( ( o_item = [o_outline_dict objectForKey:
593 [NSString stringWithFormat: @"%p",
594 [[o_array objectAtIndex:j] pointerValue]]] ) != nil )
596 [o_outline_view expandItem: o_item];
601 pl_Release( VLCIntf );
604 /* Check if p_item is a child of p_node recursively. We need to check the item
605 existence first since OSX sometimes tries to redraw items that have been
606 deleted. We don't do it when not required since this verification takes
607 quite a long time on big playlists (yes, pretty hacky). */
609 - (BOOL)isItem: (playlist_item_t *)p_item
610 inNode: (playlist_item_t *)p_node
611 checkItemExistence:(BOOL)b_check
612 locked:(BOOL)b_locked
615 playlist_t * p_playlist = pl_Hold( VLCIntf );
616 playlist_item_t *p_temp_item = p_item;
618 if( p_node == p_item )
620 vlc_object_release(p_playlist);
624 if( p_node->i_children < 1)
626 vlc_object_release(p_playlist);
633 if(!b_locked) PL_LOCK;
637 /* Since outlineView: willDisplayCell:... may call this function with
638 p_items that don't exist anymore, first check if the item is still
639 in the playlist. Any cleaner solution welcomed. */
640 for( i = 0; i < p_playlist->all_items.i_size; i++ )
642 if( ARRAY_VAL( p_playlist->all_items, i) == p_item ) break;
643 else if ( i == p_playlist->all_items.i_size - 1 )
645 if(!b_locked) PL_UNLOCK;
646 vlc_object_release( p_playlist );
654 p_temp_item = p_temp_item->p_parent;
655 if( p_temp_item == p_node )
657 if(!b_locked) PL_UNLOCK;
658 vlc_object_release( p_playlist );
662 if(!b_locked) PL_UNLOCK;
665 vlc_object_release( p_playlist );
669 - (BOOL)isItem: (playlist_item_t *)p_item
670 inNode: (playlist_item_t *)p_node
671 checkItemExistence:(BOOL)b_check
673 [self isItem:p_item inNode:p_node checkItemExistence:b_check locked:NO];
676 /* This method is usefull for instance to remove the selected children of an
677 already selected node */
678 - (void)removeItemsFrom:(id)o_items ifChildrenOf:(id)o_nodes
681 for( i = 0 ; i < [o_items count] ; i++ )
683 for ( j = 0 ; j < [o_nodes count] ; j++ )
685 if( o_items == o_nodes)
687 if( j == i ) continue;
689 if( [self isItem: [[o_items objectAtIndex:i] pointerValue]
690 inNode: [[o_nodes objectAtIndex:j] pointerValue]
691 checkItemExistence: NO locked:NO] )
693 [o_items removeObjectAtIndex:i];
694 /* We need to execute the next iteration with the same index
695 since the current item has been deleted */
703 - (IBAction)savePlaylist:(id)sender
705 playlist_t * p_playlist = pl_Hold( VLCIntf );
707 NSSavePanel *o_save_panel = [NSSavePanel savePanel];
708 NSString * o_name = [NSString stringWithFormat: @"%@", _NS("Untitled")];
710 //[o_save_panel setAllowedFileTypes: [NSArray arrayWithObjects: @"m3u", @"xpf", nil] ];
711 [o_save_panel setTitle: _NS("Save Playlist")];
712 [o_save_panel setPrompt: _NS("Save")];
713 [o_save_panel setAccessoryView: o_save_accessory_view];
715 if( [o_save_panel runModalForDirectory: nil
716 file: o_name] == NSOKButton )
718 NSString *o_filename = [o_save_panel filename];
720 if( [o_save_accessory_popup indexOfSelectedItem] == 1 )
722 NSString * o_real_filename;
724 range.location = [o_filename length] - [@".xspf" length];
725 range.length = [@".xspf" length];
727 if( [o_filename compare:@".xspf" options: NSCaseInsensitiveSearch
728 range: range] != NSOrderedSame )
730 o_real_filename = [NSString stringWithFormat: @"%@.xspf", o_filename];
734 o_real_filename = o_filename;
736 playlist_Export( p_playlist,
737 [o_real_filename fileSystemRepresentation],
738 p_playlist->p_local_category, "export-xspf" );
742 NSString * o_real_filename;
744 range.location = [o_filename length] - [@".m3u" length];
745 range.length = [@".m3u" length];
747 if( [o_filename compare:@".m3u" options: NSCaseInsensitiveSearch
748 range: range] != NSOrderedSame )
750 o_real_filename = [NSString stringWithFormat: @"%@.m3u", o_filename];
754 o_real_filename = o_filename;
756 playlist_Export( p_playlist,
757 [o_real_filename fileSystemRepresentation],
758 p_playlist->p_local_category, "export-m3u" );
761 vlc_object_release( p_playlist );
764 /* When called retrieves the selected outlineview row and plays that node or item */
765 - (IBAction)playItem:(id)sender
767 intf_thread_t * p_intf = VLCIntf;
768 playlist_t * p_playlist = pl_Hold( p_intf );
770 playlist_item_t *p_item;
771 playlist_item_t *p_node = NULL;
773 p_item = [[o_outline_view itemAtRow:[o_outline_view selectedRow]] pointerValue];
777 if( p_item->i_children == -1 )
779 p_node = p_item->p_parent;
785 if( p_node->i_children > 0 && p_node->pp_children[0]->i_children == -1 )
787 p_item = p_node->pp_children[0];
794 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, pl_Unlocked, p_node, p_item );
796 vlc_object_release( p_playlist );
799 - (IBAction)revealItemInFinder:(id)sender
801 playlist_item_t * p_item = [[o_outline_view itemAtRow:[o_outline_view selectedRow]] pointerValue];
802 NSMutableString * o_mrl = nil;
804 if(! p_item || !p_item->p_input )
807 char *psz_uri = input_item_GetURI( p_item->p_input );
809 o_mrl = [NSMutableString stringWithUTF8String: psz_uri];
811 /* perform some checks whether it is a file and if it is local at all... */
812 NSRange prefix_range = [o_mrl rangeOfString: @"file:"];
813 if( prefix_range.location != NSNotFound )
814 [o_mrl deleteCharactersInRange: prefix_range];
816 if( [o_mrl characterAtIndex:0] == '/' )
817 [[NSWorkspace sharedWorkspace] selectFile: o_mrl inFileViewerRootedAtPath: o_mrl];
820 /* When called retrieves the selected outlineview row and plays that node or item */
821 - (IBAction)preparseItem:(id)sender
824 NSMutableArray *o_to_preparse;
825 intf_thread_t * p_intf = VLCIntf;
826 playlist_t * p_playlist = pl_Hold( p_intf );
828 o_to_preparse = [NSMutableArray arrayWithArray:[[o_outline_view selectedRowEnumerator] allObjects]];
829 i_count = [o_to_preparse count];
833 playlist_item_t *p_item = NULL;
835 for( i = 0; i < i_count; i++ )
837 o_number = [o_to_preparse lastObject];
838 i_row = [o_number intValue];
839 p_item = [[o_outline_view itemAtRow:i_row] pointerValue];
840 [o_to_preparse removeObject: o_number];
841 [o_outline_view deselectRow: i_row];
845 if( p_item->i_children == -1 )
847 playlist_PreparseEnqueue( p_playlist, p_item->p_input, pl_Unlocked );
851 msg_Dbg( p_intf, "preparsing nodes not implemented" );
855 vlc_object_release( p_playlist );
856 [self playlistUpdated];
859 - (IBAction)downloadCoverArt:(id)sender
862 NSMutableArray *o_to_preparse;
863 intf_thread_t * p_intf = VLCIntf;
864 playlist_t * p_playlist = pl_Hold( p_intf );
866 o_to_preparse = [NSMutableArray arrayWithArray:[[o_outline_view selectedRowEnumerator] allObjects]];
867 i_count = [o_to_preparse count];
871 playlist_item_t *p_item = NULL;
873 for( i = 0; i < i_count; i++ )
875 o_number = [o_to_preparse lastObject];
876 i_row = [o_number intValue];
877 p_item = [[o_outline_view itemAtRow:i_row] pointerValue];
878 [o_to_preparse removeObject: o_number];
879 [o_outline_view deselectRow: i_row];
881 if( p_item && p_item->i_children == -1 )
883 playlist_AskForArtEnqueue( p_playlist, p_item->p_input, pl_Unlocked );
886 vlc_object_release( p_playlist );
887 [self playlistUpdated];
890 - (IBAction)servicesChange:(id)sender
892 NSMenuItem *o_mi = (NSMenuItem *)sender;
893 NSString *o_string = [o_mi representedObject];
894 playlist_t * p_playlist = pl_Hold( VLCIntf );
895 if( !playlist_IsServicesDiscoveryLoaded( p_playlist, [o_string UTF8String] ) )
896 playlist_ServicesDiscoveryAdd( p_playlist, [o_string UTF8String] );
898 playlist_ServicesDiscoveryRemove( p_playlist, [o_string UTF8String] );
900 [o_mi setState: playlist_IsServicesDiscoveryLoaded( p_playlist,
901 [o_string UTF8String] ) ? YES : NO];
903 vlc_object_release( p_playlist );
904 [self playlistUpdated];
908 - (IBAction)selectAll:(id)sender
910 [o_outline_view selectAll: nil];
913 - (IBAction)deleteItem:(id)sender
916 NSMutableArray *o_to_delete;
919 playlist_t * p_playlist;
920 intf_thread_t * p_intf = VLCIntf;
922 o_to_delete = [NSMutableArray arrayWithArray:[[o_outline_view selectedRowEnumerator] allObjects]];
923 i_count = [o_to_delete count];
925 p_playlist = pl_Hold( p_intf );
928 for( int i = 0; i < i_count; i++ )
930 o_number = [o_to_delete lastObject];
931 i_row = [o_number intValue];
932 id o_item = [o_outline_view itemAtRow: i_row];
933 playlist_item_t *p_item = [o_item pointerValue];
935 msg_Dbg( p_intf, "deleting item %i (of %i) with id \"%i\", pointerValue \"%p\" and %i children", i+1, i_count,
936 p_item->p_input->i_id, [o_item pointerValue], p_item->i_children +1 );
938 [o_to_delete removeObject: o_number];
939 [o_outline_view deselectRow: i_row];
941 if( p_item->i_children != -1 )
942 //is a node and not an item
944 if( playlist_Status( p_playlist ) != PLAYLIST_STOPPED &&
945 [self isItem: playlist_CurrentPlayingItem( p_playlist ) inNode:
946 ((playlist_item_t *)[o_item pointerValue])
947 checkItemExistence: NO locked:YES] == YES )
948 // if current item is in selected node and is playing then stop playlist
949 playlist_Control(p_playlist, PLAYLIST_STOP, pl_Locked );
951 playlist_NodeDelete( p_playlist, p_item, true, false );
954 playlist_DeleteFromInput( p_playlist, p_item->p_input->i_id, pl_Locked );
958 [self playlistUpdated];
959 vlc_object_release( p_playlist );
962 - (IBAction)sortNodeByName:(id)sender
964 [self sortNode: SORT_TITLE];
967 - (IBAction)sortNodeByAuthor:(id)sender
969 [self sortNode: SORT_ARTIST];
972 - (void)sortNode:(int)i_mode
974 playlist_t * p_playlist = pl_Hold( VLCIntf );
975 playlist_item_t * p_item;
977 if( [o_outline_view selectedRow] > -1 )
979 p_item = [[o_outline_view itemAtRow: [o_outline_view selectedRow]] pointerValue];
982 /*If no item is selected, sort the whole playlist*/
984 p_item = p_playlist->p_root_category;
987 if( p_item->i_children > -1 ) // the item is a node
990 playlist_RecursiveNodeSort( p_playlist, p_item, i_mode, ORDER_NORMAL );
996 playlist_RecursiveNodeSort( p_playlist,
997 p_item->p_parent, i_mode, ORDER_NORMAL );
1000 vlc_object_release( p_playlist );
1001 [self playlistUpdated];
1004 - (input_item_t *)createItem:(NSDictionary *)o_one_item
1006 intf_thread_t * p_intf = VLCIntf;
1007 playlist_t * p_playlist = pl_Hold( p_intf );
1009 input_item_t *p_input;
1011 BOOL b_rem = FALSE, b_dir = FALSE;
1012 NSString *o_uri, *o_name;
1017 o_uri = (NSString *)[o_one_item objectForKey: @"ITEM_URL"];
1018 o_name = (NSString *)[o_one_item objectForKey: @"ITEM_NAME"];
1019 o_options = (NSArray *)[o_one_item objectForKey: @"ITEM_OPTIONS"];
1021 /* Find the name for a disc entry (i know, can you believe the trouble?) */
1022 if( ( !o_name || [o_name isEqualToString:@""] ) && [o_uri rangeOfString: @"/dev/"].location != NSNotFound )
1024 int i_count, i_index;
1025 struct statfs *mounts = NULL;
1027 i_count = getmntinfo (&mounts, MNT_NOWAIT);
1028 /* getmntinfo returns a pointer to static data. Do not free. */
1029 for( i_index = 0 ; i_index < i_count; i_index++ )
1031 NSMutableString *o_temp, *o_temp2;
1032 o_temp = [NSMutableString stringWithString: o_uri];
1033 o_temp2 = [NSMutableString stringWithUTF8String: mounts[i_index].f_mntfromname];
1034 [o_temp replaceOccurrencesOfString: @"/dev/rdisk" withString: @"/dev/disk" options:NSLiteralSearch range:NSMakeRange(0, [o_temp length]) ];
1035 [o_temp2 replaceOccurrencesOfString: @"s0" withString: @"" options:NSLiteralSearch range:NSMakeRange(0, [o_temp2 length]) ];
1036 [o_temp2 replaceOccurrencesOfString: @"s1" withString: @"" options:NSLiteralSearch range:NSMakeRange(0, [o_temp2 length]) ];
1038 if( strstr( [o_temp fileSystemRepresentation], [o_temp2 fileSystemRepresentation] ) != NULL )
1040 o_name = [[NSFileManager defaultManager] displayNameAtPath: [NSString stringWithUTF8String:mounts[i_index].f_mntonname]];
1044 /* If no name, then make a guess */
1045 if( !o_name) o_name = [[NSFileManager defaultManager] displayNameAtPath: o_uri];
1047 if( [[NSFileManager defaultManager] fileExistsAtPath:o_uri isDirectory:&b_dir] && b_dir &&
1048 [[NSWorkspace sharedWorkspace] getFileSystemInfoForPath: o_uri isRemovable: &b_rem
1049 isWritable:NULL isUnmountable:NULL description:NULL type:NULL] && b_rem )
1051 /* All of this is to make sure CD's play when you D&D them on VLC */
1052 /* Converts mountpoint to a /dev file */
1055 NSMutableString *o_temp;
1057 buf = (struct statfs *) malloc (sizeof(struct statfs));
1058 statfs( [o_uri fileSystemRepresentation], buf );
1059 psz_dev = strdup(buf->f_mntfromname);
1060 o_temp = [NSMutableString stringWithUTF8String: psz_dev ];
1061 [o_temp replaceOccurrencesOfString: @"/dev/disk" withString: @"/dev/rdisk" options:NSLiteralSearch range:NSMakeRange(0, [o_temp length]) ];
1062 [o_temp replaceOccurrencesOfString: @"s0" withString: @"" options:NSLiteralSearch range:NSMakeRange(0, [o_temp length]) ];
1063 [o_temp replaceOccurrencesOfString: @"s1" withString: @"" options:NSLiteralSearch range:NSMakeRange(0, [o_temp length]) ];
1067 p_input = input_item_New( p_playlist, [o_uri fileSystemRepresentation], [o_name UTF8String] );
1073 for( i = 0; i < (int)[o_options count]; i++ )
1075 input_item_AddOption( p_input, strdup( [[o_options objectAtIndex:i] UTF8String] ) );
1079 /* Recent documents menu */
1080 o_true_file = [NSURL fileURLWithPath: o_uri];
1081 if( o_true_file != nil && (BOOL)config_GetInt( p_playlist, "macosx-recentitems" ) == YES )
1083 [[NSDocumentController sharedDocumentController]
1084 noteNewRecentDocumentURL: o_true_file];
1087 vlc_object_release( p_playlist );
1091 - (void)appendArray:(NSArray*)o_array atPos:(int)i_position enqueue:(BOOL)b_enqueue
1094 playlist_t * p_playlist = pl_Hold( VLCIntf );
1097 for( i_item = 0; i_item < (int)[o_array count]; i_item++ )
1099 input_item_t *p_input;
1100 NSDictionary *o_one_item;
1103 o_one_item = [o_array objectAtIndex: i_item];
1104 p_input = [self createItem: o_one_item];
1111 /* FIXME: playlist_AddInput() can fail */
1113 playlist_AddInput( p_playlist, p_input, PLAYLIST_INSERT,
1114 i_position == -1 ? PLAYLIST_END : i_position + i_item, true,
1117 if( i_item == 0 && !b_enqueue )
1119 playlist_item_t *p_item = NULL;
1120 playlist_item_t *p_node = NULL;
1121 p_item = playlist_ItemGetByInput( p_playlist, p_input, pl_Locked );
1124 if( p_item->i_children == -1 )
1125 p_node = p_item->p_parent;
1129 if( p_node->i_children > 0 && p_node->pp_children[0]->i_children == -1 )
1130 p_item = p_node->pp_children[0];
1134 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, pl_Locked, p_node, p_item );
1137 vlc_gc_decref( p_input );
1141 [self playlistUpdated];
1142 vlc_object_release( p_playlist );
1145 - (void)appendNodeArray:(NSArray*)o_array inNode:(playlist_item_t *)p_node atPos:(int)i_position enqueue:(BOOL)b_enqueue
1148 playlist_t * p_playlist = pl_Hold( VLCIntf );
1150 for( i_item = 0; i_item < (int)[o_array count]; i_item++ )
1152 input_item_t *p_input;
1153 NSDictionary *o_one_item;
1156 o_one_item = [o_array objectAtIndex: i_item];
1157 p_input = [self createItem: o_one_item];
1159 if( !p_input ) continue;
1162 /* FIXME: playlist_BothAddInput() can fail */
1164 playlist_BothAddInput( p_playlist, p_input, p_node,
1167 PLAYLIST_END : i_position + i_item,
1168 NULL, NULL, pl_Locked );
1171 if( i_item == 0 && !b_enqueue )
1173 playlist_item_t *p_item;
1174 p_item = playlist_ItemGetByInput( p_playlist, p_input, pl_Locked );
1175 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, pl_Locked, p_node, p_item );
1178 vlc_gc_decref( p_input );
1180 [self playlistUpdated];
1181 vlc_object_release( p_playlist );
1184 - (NSMutableArray *)subSearchItem:(playlist_item_t *)p_item
1186 playlist_t *p_playlist = pl_Hold( VLCIntf );
1187 playlist_item_t *p_selected_item;
1188 int i_current, i_selected_row;
1190 i_selected_row = [o_outline_view selectedRow];
1191 if (i_selected_row < 0)
1194 p_selected_item = (playlist_item_t *)[[o_outline_view itemAtRow:
1195 i_selected_row] pointerValue];
1197 for( i_current = 0; i_current < p_item->i_children ; i_current++ )
1200 NSString *o_current_name, *o_current_author;
1203 o_current_name = [NSString stringWithUTF8String:
1204 p_item->pp_children[i_current]->p_input->psz_name];
1205 psz_temp = input_item_GetInfo( p_item->p_input ,
1206 _("Meta-information"),_("Artist") );
1207 o_current_author = [NSString stringWithUTF8String: psz_temp];
1211 if( p_selected_item == p_item->pp_children[i_current] &&
1212 b_selected_item_met == NO )
1214 b_selected_item_met = YES;
1216 else if( p_selected_item == p_item->pp_children[i_current] &&
1217 b_selected_item_met == YES )
1219 vlc_object_release( p_playlist );
1222 else if( b_selected_item_met == YES &&
1223 ( [o_current_name rangeOfString:[o_search_field
1224 stringValue] options:NSCaseInsensitiveSearch].length ||
1225 [o_current_author rangeOfString:[o_search_field
1226 stringValue] options:NSCaseInsensitiveSearch].length ) )
1228 vlc_object_release( p_playlist );
1229 /*Adds the parent items in the result array as well, so that we can
1231 return [NSMutableArray arrayWithObject: [NSValue
1232 valueWithPointer: p_item->pp_children[i_current]]];
1234 if( p_item->pp_children[i_current]->i_children > 0 )
1236 id o_result = [self subSearchItem:
1237 p_item->pp_children[i_current]];
1238 if( o_result != NULL )
1240 vlc_object_release( p_playlist );
1241 [o_result insertObject: [NSValue valueWithPointer:
1242 p_item->pp_children[i_current]] atIndex:0];
1247 vlc_object_release( p_playlist );
1251 - (IBAction)searchItem:(id)sender
1253 playlist_t * p_playlist = pl_Hold( VLCIntf );
1259 b_selected_item_met = NO;
1261 /*First, only search after the selected item:*
1262 *(b_selected_item_met = NO) */
1263 o_result = [self subSearchItem:p_playlist->p_root_category];
1264 if( o_result == NULL )
1266 /* If the first search failed, search again from the beginning */
1267 o_result = [self subSearchItem:p_playlist->p_root_category];
1269 if( o_result != NULL )
1272 if( [[o_result objectAtIndex: 0] pointerValue] ==
1273 p_playlist->p_local_category )
1278 for( i = i_start ; i < [o_result count] - 1 ; i++ )
1280 [o_outline_view expandItem: [o_outline_dict objectForKey:
1281 [NSString stringWithFormat: @"%p",
1282 [[o_result objectAtIndex: i] pointerValue]]]];
1284 i_row = [o_outline_view rowForItem: [o_outline_dict objectForKey:
1285 [NSString stringWithFormat: @"%p",
1286 [[o_result objectAtIndex: [o_result count] - 1 ]
1291 [o_outline_view selectRow:i_row byExtendingSelection: NO];
1292 [o_outline_view scrollRowToVisible: i_row];
1294 vlc_object_release( p_playlist );
1297 - (IBAction)recursiveExpandNode:(id)sender
1299 id o_item = [o_outline_view itemAtRow: [o_outline_view selectedRow]];
1300 playlist_item_t *p_item = (playlist_item_t *)[o_item pointerValue];
1302 if( ![[o_outline_view dataSource] outlineView: o_outline_view
1303 isItemExpandable: o_item] )
1305 o_item = [o_outline_dict objectForKey: [NSString
1306 stringWithFormat: @"%p", p_item->p_parent]];
1309 /* We need to collapse the node first, since OSX refuses to recursively
1310 expand an already expanded node, even if children nodes are collapsed. */
1311 [o_outline_view collapseItem: o_item collapseChildren: YES];
1312 [o_outline_view expandItem: o_item expandChildren: YES];
1315 - (NSMenu *)menuForEvent:(NSEvent *)o_event
1321 pt = [o_outline_view convertPoint: [o_event locationInWindow]
1323 int row = [o_outline_view rowAtPoint:pt];
1325 [o_outline_view selectRowIndexes:[NSIndexSet indexSetWithIndex:row] byExtendingSelection:NO];
1327 b_item_sel = ( row != -1 && [o_outline_view selectedRow] != -1 );
1328 b_rows = [o_outline_view numberOfRows] != 0;
1330 [o_mi_play setEnabled: b_item_sel];
1331 [o_mi_delete setEnabled: b_item_sel];
1332 [o_mi_selectall setEnabled: b_rows];
1333 [o_mi_info setEnabled: b_item_sel];
1334 [o_mi_preparse setEnabled: b_item_sel];
1335 [o_mi_recursive_expand setEnabled: b_item_sel];
1336 [o_mi_sort_name setEnabled: b_item_sel];
1337 [o_mi_sort_author setEnabled: b_item_sel];
1339 return( o_ctx_menu );
1342 - (void)outlineView: (NSOutlineView *)o_tv
1343 didClickTableColumn:(NSTableColumn *)o_tc
1345 int i_mode, i_type = 0;
1346 intf_thread_t *p_intf = VLCIntf;
1348 playlist_t *p_playlist = pl_Hold( p_intf );
1350 /* Check whether the selected table column header corresponds to a
1351 sortable table column*/
1352 if( !( o_tc == o_tc_name || o_tc == o_tc_author ) )
1354 vlc_object_release( p_playlist );
1358 if( o_tc_sortColumn == o_tc )
1360 b_isSortDescending = !b_isSortDescending;
1364 b_isSortDescending = false;
1367 if( o_tc == o_tc_name )
1369 i_mode = SORT_TITLE;
1371 else if( o_tc == o_tc_author )
1373 i_mode = SORT_ARTIST;
1376 if( b_isSortDescending )
1378 i_type = ORDER_REVERSE;
1382 i_type = ORDER_NORMAL;
1386 playlist_RecursiveNodeSort( p_playlist, p_playlist->p_root_category, i_mode, i_type );
1389 vlc_object_release( p_playlist );
1390 [self playlistUpdated];
1392 o_tc_sortColumn = o_tc;
1393 [o_outline_view setHighlightedTableColumn:o_tc];
1395 if( b_isSortDescending )
1397 [o_outline_view setIndicatorImage:o_descendingSortingImage
1398 inTableColumn:o_tc];
1402 [o_outline_view setIndicatorImage:o_ascendingSortingImage
1403 inTableColumn:o_tc];
1408 - (void)outlineView:(NSOutlineView *)outlineView
1409 willDisplayCell:(id)cell
1410 forTableColumn:(NSTableColumn *)tableColumn
1413 playlist_t *p_playlist = pl_Hold( VLCIntf );
1417 o_playing_item = [o_outline_dict objectForKey:
1418 [NSString stringWithFormat:@"%p", playlist_CurrentPlayingItem( p_playlist )]];
1420 if( [self isItem: [o_playing_item pointerValue] inNode:
1421 [item pointerValue] checkItemExistence: YES]
1422 || [o_playing_item isEqual: item] )
1424 [cell setFont: [[NSFontManager sharedFontManager] convertFont:[cell font] toHaveTrait:NSBoldFontMask]];
1428 [cell setFont: [[NSFontManager sharedFontManager] convertFont:[cell font] toNotHaveTrait:NSBoldFontMask]];
1430 vlc_object_release( p_playlist );
1433 - (IBAction)addNode:(id)sender
1435 /* we have to create a new thread here because otherwise we would block the
1436 * interface since the interaction-stuff and this code would run in the same
1438 [NSThread detachNewThreadSelector: @selector(addNodeThreadedly)
1439 toTarget: self withObject:nil];
1440 [self playlistUpdated];
1443 - (void)addNodeThreadedly
1445 NSAutoreleasePool * ourPool = [[NSAutoreleasePool alloc] init];
1447 /* simply adds a new node to the end of the playlist */
1448 playlist_t * p_playlist = pl_Hold( VLCIntf );
1449 vlc_thread_set_priority( p_playlist, VLC_THREAD_PRIORITY_LOW );
1452 char *psz_name = NULL;
1453 ret_v = intf_UserStringInput( p_playlist, _("New Node"),
1454 _("Please enter a name for the new node."), &psz_name );
1457 if( ret_v != DIALOG_CANCELLED && psz_name )
1459 playlist_NodeCreate( p_playlist, psz_name,
1460 p_playlist->p_local_category, 0, NULL );
1462 else if(! config_GetInt( p_playlist, "interact" ) )
1464 /* in case that the interaction is disabled, just give it a bogus name */
1465 playlist_NodeCreate( p_playlist, _("Empty Folder"),
1466 p_playlist->p_local_category, 0, NULL );
1471 pl_Release( VLCIntf );
1477 @implementation VLCPlaylist (NSOutlineViewDataSource)
1479 - (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item
1481 id o_value = [super outlineView: outlineView child: index ofItem: item];
1482 playlist_t *p_playlist = pl_Hold( VLCIntf );
1485 if( playlist_CurrentSize( p_playlist ) >= 2 )
1487 [o_status_field setStringValue: [NSString stringWithFormat:
1489 playlist_CurrentSize( p_playlist )]];
1493 if( playlist_IsEmpty( p_playlist ) )
1495 [o_status_field setStringValue: _NS("No items in the playlist")];
1499 [o_status_field setStringValue: _NS("1 item")];
1504 vlc_object_release( p_playlist );
1506 [o_outline_dict setObject:o_value forKey:[NSString stringWithFormat:@"%p",
1507 [o_value pointerValue]]];
1512 /* Required for drag & drop and reordering */
1513 - (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pboard
1516 playlist_t *p_playlist = pl_Hold( VLCIntf );
1518 /* First remove the items that were moved during the last drag & drop
1520 [o_items_array removeAllObjects];
1521 [o_nodes_array removeAllObjects];
1523 for( i = 0 ; i < [items count] ; i++ )
1525 id o_item = [items objectAtIndex: i];
1527 /* Refuse to move items that are not in the General Node
1528 (Service Discovery) */
1529 if( ![self isItem: [o_item pointerValue] inNode:
1530 p_playlist->p_local_category checkItemExistence: NO] &&
1531 var_CreateGetBool( p_playlist, "media-library" ) &&
1532 ![self isItem: [o_item pointerValue] inNode:
1533 p_playlist->p_ml_category checkItemExistence: NO] ||
1534 [o_item pointerValue] == p_playlist->p_local_category ||
1535 [o_item pointerValue] == p_playlist->p_ml_category )
1537 vlc_object_release(p_playlist);
1540 /* Fill the items and nodes to move in 2 different arrays */
1541 if( ((playlist_item_t *)[o_item pointerValue])->i_children > 0 )
1542 [o_nodes_array addObject: o_item];
1544 [o_items_array addObject: o_item];
1547 /* Now we need to check if there are selected items that are in already
1548 selected nodes. In that case, we only want to move the nodes */
1549 [self removeItemsFrom: o_nodes_array ifChildrenOf: o_nodes_array];
1550 [self removeItemsFrom: o_items_array ifChildrenOf: o_nodes_array];
1552 /* We add the "VLCPlaylistItemPboardType" type to be able to recognize
1553 a Drop operation coming from the playlist. */
1555 [pboard declareTypes: [NSArray arrayWithObjects:
1556 @"VLCPlaylistItemPboardType", nil] owner: self];
1557 [pboard setData:[NSData data] forType:@"VLCPlaylistItemPboardType"];
1559 vlc_object_release(p_playlist);
1563 - (NSDragOperation)outlineView:(NSOutlineView *)outlineView validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(int)index
1565 playlist_t *p_playlist = pl_Hold( VLCIntf );
1566 NSPasteboard *o_pasteboard = [info draggingPasteboard];
1568 if( !p_playlist ) return NSDragOperationNone;
1570 /* Dropping ON items is not allowed if item is not a node */
1573 if( index == NSOutlineViewDropOnItemIndex &&
1574 ((playlist_item_t *)[item pointerValue])->i_children == -1 )
1576 vlc_object_release( p_playlist );
1577 return NSDragOperationNone;
1581 /* Don't allow on drop on playlist root element's child */
1582 if( !item && index != NSOutlineViewDropOnItemIndex)
1584 vlc_object_release( p_playlist );
1585 return NSDragOperationNone;
1588 /* We refuse to drop an item in anything else than a child of the General
1589 Node. We still accept items that would be root nodes of the outlineview
1590 however, to allow drop in an empty playlist. */
1591 if( !( ([self isItem: [item pointerValue] inNode: p_playlist->p_local_category checkItemExistence: NO] ||
1592 ( var_CreateGetBool( p_playlist, "media-library" ) && [self isItem: [item pointerValue] inNode: p_playlist->p_ml_category checkItemExistence: NO] ) ) || item == nil ) )
1594 vlc_object_release( p_playlist );
1595 return NSDragOperationNone;
1598 /* Drop from the Playlist */
1599 if( [[o_pasteboard types] containsObject: @"VLCPlaylistItemPboardType"] )
1602 for( i = 0 ; i < [o_nodes_array count] ; i++ )
1604 /* We refuse to Drop in a child of an item we are moving */
1605 if( [self isItem: [item pointerValue] inNode:
1606 [[o_nodes_array objectAtIndex: i] pointerValue]
1607 checkItemExistence: NO] )
1609 vlc_object_release( p_playlist );
1610 return NSDragOperationNone;
1613 vlc_object_release( p_playlist );
1614 return NSDragOperationMove;
1617 /* Drop from the Finder */
1618 else if( [[o_pasteboard types] containsObject: NSFilenamesPboardType] )
1620 vlc_object_release( p_playlist );
1621 return NSDragOperationGeneric;
1623 vlc_object_release( p_playlist );
1624 return NSDragOperationNone;
1627 - (BOOL)outlineView:(NSOutlineView *)outlineView acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(int)index
1629 playlist_t * p_playlist = pl_Hold( VLCIntf );
1630 NSPasteboard *o_pasteboard = [info draggingPasteboard];
1632 /* Drag & Drop inside the playlist */
1633 if( [[o_pasteboard types] containsObject: @"VLCPlaylistItemPboardType"] )
1635 int i_row, i_removed_from_node = 0;
1637 playlist_item_t *p_new_parent, *p_item = NULL;
1638 NSArray *o_all_items = [o_nodes_array arrayByAddingObjectsFromArray:
1640 /* If the item is to be dropped as root item of the outline, make it a
1641 child of the General node.
1642 Else, choose the proposed parent as parent. */
1643 if( item == nil ) p_new_parent = p_playlist->p_local_category;
1644 else p_new_parent = [item pointerValue];
1646 /* Make sure the proposed parent is a node.
1647 (This should never be true) */
1648 if( p_new_parent->i_children < 0 )
1650 vlc_object_release( p_playlist );
1654 for( i = 0; i < [o_all_items count]; i++ )
1656 playlist_item_t *p_old_parent = NULL;
1657 int i_old_index = 0;
1659 p_item = [[o_all_items objectAtIndex:i] pointerValue];
1660 p_old_parent = p_item->p_parent;
1663 /* We may need the old index later */
1664 if( p_new_parent == p_old_parent )
1667 for( j = 0; j < p_old_parent->i_children; j++ )
1669 if( p_old_parent->pp_children[j] == p_item )
1678 // Actually detach the item from the old position
1679 if( playlist_NodeRemoveItem( p_playlist, p_item, p_old_parent ) ==
1683 /* Calculate the new index */
1686 /* If we move the item in the same node, we need to take into
1687 account that one item will be deleted */
1690 if ((p_new_parent == p_old_parent &&
1691 i_old_index < index + (int)i) )
1693 i_removed_from_node++;
1695 i_new_index = index + i - i_removed_from_node;
1697 // Reattach the item to the new position
1698 playlist_NodeInsert( p_playlist, p_item, p_new_parent, i_new_index );
1702 [self playlistUpdated];
1703 i_row = [o_outline_view rowForItem:[o_outline_dict
1704 objectForKey:[NSString stringWithFormat: @"%p",
1705 [[o_all_items objectAtIndex: 0] pointerValue]]]];
1709 i_row = [o_outline_view rowForItem:[o_outline_dict
1710 objectForKey:[NSString stringWithFormat: @"%p", p_new_parent]]];
1713 [o_outline_view deselectAll: self];
1714 [o_outline_view selectRow: i_row byExtendingSelection: NO];
1715 [o_outline_view scrollRowToVisible: i_row];
1717 vlc_object_release( p_playlist );
1721 else if( [[o_pasteboard types] containsObject: NSFilenamesPboardType] )
1724 playlist_item_t *p_node = [item pointerValue];
1726 NSArray *o_array = [NSArray array];
1727 NSArray *o_values = [[o_pasteboard propertyListForType:
1728 NSFilenamesPboardType]
1729 sortedArrayUsingSelector:
1730 @selector(caseInsensitiveCompare:)];
1732 for( i = 0; i < (int)[o_values count]; i++)
1734 NSDictionary *o_dic;
1735 o_dic = [NSDictionary dictionaryWithObject:[o_values
1736 objectAtIndex:i] forKey:@"ITEM_URL"];
1737 o_array = [o_array arrayByAddingObject: o_dic];
1742 [self appendArray:o_array atPos:index enqueue: YES];
1746 assert( p_node->i_children != -1 );
1747 [self appendNodeArray:o_array inNode: p_node
1748 atPos:index enqueue:YES];
1750 vlc_object_release( p_playlist );
1753 vlc_object_release( p_playlist );