1 /*****************************************************************************
2 * playlist.m: MacOS X interface module
3 *****************************************************************************
4 * Copyright (C) 2002-2009 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>
46 #import "playlistinfo.h"
50 #import "sidebarview.h"
53 #import <vlc_services_discovery.h>
55 #import <vlc_interface.h>
60 /*****************************************************************************
61 * VLCPlaylistView implementation
62 *****************************************************************************/
63 @implementation VLCPlaylistView
65 - (NSMenu *)menuForEvent:(NSEvent *)o_event
67 return( [[self delegate] menuForEvent: o_event] );
70 - (void)keyDown:(NSEvent *)o_event
74 if( [[o_event characters] length] )
76 key = [[o_event characters] characterAtIndex: 0];
81 case NSDeleteCharacter:
82 case NSDeleteFunctionKey:
83 case NSDeleteCharFunctionKey:
84 case NSBackspaceCharacter:
85 [[self delegate] deleteItem:self];
88 case NSEnterCharacter:
89 case NSCarriageReturnCharacter:
90 [(VLCPlaylist *)[[VLCMain sharedInstance] playlist] playItem:self];
94 [super keyDown: o_event];
101 /*****************************************************************************
102 * VLCPlaylistCommon implementation
104 * This class the superclass of the VLCPlaylist and VLCPlaylistWizard.
105 * It contains the common methods and elements of these 2 entities.
106 *****************************************************************************/
107 @implementation VLCPlaylistCommon
114 o_outline_dict = [[NSMutableDictionary alloc] init];
120 playlist_t * p_playlist = pl_Get( VLCIntf );
121 [o_outline_view setTarget: self];
122 [o_outline_view setDelegate: self];
123 [o_outline_view setDataSource: self];
124 [o_outline_view setAllowsEmptySelection: NO];
125 [o_outline_view expandItem: [o_outline_view itemAtRow:0]];
127 [o_outline_view_other setTarget: self];
128 [o_outline_view_other setDelegate: self];
129 [o_outline_view_other setDataSource: self];
130 [o_outline_view_other setAllowsEmptySelection: NO];
137 [[o_tc_name headerCell] setStringValue:_NS("Name")];
138 [[o_tc_author headerCell] setStringValue:_NS("Author")];
139 [[o_tc_duration headerCell] setStringValue:_NS("Duration")];
141 [[o_tc_name_other headerCell] setStringValue:_NS("Name")];
142 [[o_tc_author_other headerCell] setStringValue:_NS("Author")];
143 [[o_tc_duration_other headerCell] setStringValue:_NS("Duration")];
146 - (void)swapPlaylists:(id)newList
148 if(newList != o_outline_view)
150 id o_outline_view_temp = o_outline_view;
151 id o_tc_author_temp = o_tc_author;
152 id o_tc_duration_temp = o_tc_duration;
153 id o_tc_name_temp = o_tc_name;
154 o_outline_view = o_outline_view_other;
155 o_tc_author = o_tc_author_other;
156 o_tc_duration = o_tc_duration_other;
157 o_tc_name = o_tc_name_other;
158 o_outline_view_other = o_outline_view_temp;
159 o_tc_author_other = o_tc_author_temp;
160 o_tc_duration_other = o_tc_duration_temp;
161 o_tc_name_other = o_tc_name_temp;
165 - (NSOutlineView *)outlineView
167 return o_outline_view;
170 - (playlist_item_t *)selectedPlaylistItem
172 return [[o_outline_view itemAtRow: [o_outline_view selectedRow]]
178 @implementation VLCPlaylistCommon (NSOutlineViewDataSource)
180 /* return the number of children for Obj-C pointer item */ /* DONE */
181 - (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
184 playlist_item_t *p_item = NULL;
185 playlist_t * p_playlist = pl_Get( VLCIntf );
186 //assert( outlineView == o_outline_view );
189 p_item = p_playlist->p_root_category;
191 p_item = (playlist_item_t *)[item pointerValue];
194 i_return = p_item->i_children;
196 return i_return > 0 ? i_return : 0;
199 /* return the child at index for the Obj-C pointer item */ /* DONE */
200 - (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item
202 playlist_item_t *p_return = NULL, *p_item = NULL;
204 playlist_t * p_playlist = pl_Get( VLCIntf );
210 p_item = p_playlist->p_root_category;
214 p_item = (playlist_item_t *)[item pointerValue];
216 if( p_item && index < p_item->i_children && index >= 0 )
217 p_return = p_item->pp_children[index];
220 o_value = [o_outline_dict objectForKey:[NSString stringWithFormat: @"%p", p_return]];
224 /* FIXME: Why is there a warning if that happens all the time and seems
225 * to be normal? Add an assert and fix it.
226 * msg_Warn( VLCIntf, "playlist item misses pointer value, adding one" ); */
227 o_value = [[NSValue valueWithPointer: p_return] retain];
232 /* is the item expandable */
233 - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item
236 playlist_t *p_playlist = pl_Get( VLCIntf );
242 if( p_playlist->p_root_category )
244 i_return = p_playlist->p_root_category->i_children;
249 playlist_item_t *p_item = (playlist_item_t *)[item pointerValue];
251 i_return = p_item->i_children;
255 return (i_return >= 0);
258 /* retrieve the string values for the cells */
259 - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)o_tc byItem:(id)item
262 playlist_item_t *p_item;
264 /* For error handling */
265 static BOOL attempted_reload = NO;
267 if( item == nil || ![item isKindOfClass: [NSValue class]] )
269 /* Attempt to fix the error by asking for a data redisplay
270 * This might cause infinite loop, so add a small check */
271 if( !attempted_reload )
273 attempted_reload = YES;
274 [outlineView reloadData];
279 p_item = (playlist_item_t *)[item pointerValue];
280 if( !p_item || !p_item->p_input )
282 /* Attempt to fix the error by asking for a data redisplay
283 * This might cause infinite loop, so add a small check */
284 if( !attempted_reload )
286 attempted_reload = YES;
287 [outlineView reloadData];
292 attempted_reload = NO;
294 if( [[o_tc identifier] isEqualToString:@"name"] )
296 /* sanity check to prevent the NSString class from crashing */
297 char *psz_title = input_item_GetTitleFbName( p_item->p_input );
300 o_value = [NSString stringWithUTF8String: psz_title];
304 else if( [[o_tc identifier] isEqualToString:@"artist"] )
306 char *psz_artist = input_item_GetArtist( p_item->p_input );
308 o_value = [NSString stringWithUTF8String: psz_artist];
311 else if( [[o_tc identifier] isEqualToString:@"duration"] )
313 char psz_duration[MSTRTIME_MAX_SIZE];
314 mtime_t dur = input_item_GetDuration( p_item->p_input );
317 secstotimestr( psz_duration, dur/1000000 );
318 o_value = [NSString stringWithUTF8String: psz_duration];
323 else if( [[o_tc identifier] isEqualToString:@"status"] )
325 if( input_item_HasErrorWhenReading( p_item->p_input ) )
327 o_value = [NSImage imageWithWarningIcon];
335 /*****************************************************************************
336 * VLCPlaylistWizard implementation
337 *****************************************************************************/
338 @implementation VLCPlaylistWizard
340 - (IBAction)reloadOutlineView
342 /* Only reload the outlineview if the wizard window is open since this can
343 be quite long on big playlists */
344 if( [[o_outline_view window] isVisible] )
346 [o_outline_view reloadData];
352 /*****************************************************************************
353 * extension to NSOutlineView's interface to fix compilation warnings
354 * and let us access these 2 functions properly
355 * this uses a private Apple-API, but works fine on all current OSX releases
356 * keep checking for compatiblity with future releases though
357 *****************************************************************************/
359 @interface NSOutlineView (UndocumentedSortImages)
360 + (NSImage *)_defaultTableHeaderSortImage;
361 + (NSImage *)_defaultTableHeaderReverseSortImage;
365 /*****************************************************************************
366 * VLCPlaylist implementation
367 *****************************************************************************/
368 @implementation VLCPlaylist
375 o_nodes_array = [[NSMutableArray alloc] init];
376 o_items_array = [[NSMutableArray alloc] init];
383 [o_nodes_array release];
384 [o_items_array release];
390 playlist_t * p_playlist = pl_Get( VLCIntf );
394 [super awakeFromNib];
396 [o_outline_view setDoubleAction: @selector(playItem:)];
397 [o_outline_view_other setDoubleAction: @selector(playItem:)];
399 [o_outline_view registerForDraggedTypes:
400 [NSArray arrayWithObjects: NSFilenamesPboardType,
401 @"VLCPlaylistItemPboardType", nil]];
402 [o_outline_view setIntercellSpacing: NSMakeSize (0.0, 1.0)];
404 [o_outline_view_other registerForDraggedTypes:
405 [NSArray arrayWithObjects: NSFilenamesPboardType,
406 @"VLCPlaylistItemPboardType", nil]];
407 [o_outline_view_other setIntercellSpacing: NSMakeSize (0.0, 1.0)];
409 /* This uses private Apple API which works fine until 10.5.
410 * We need to keep checking in the future!
411 * These methods are being added artificially to NSOutlineView's interface above */
412 o_ascendingSortingImage = [[NSOutlineView class] _defaultTableHeaderSortImage];
413 o_descendingSortingImage = [[NSOutlineView class] _defaultTableHeaderReverseSortImage];
415 o_tc_sortColumn = nil;
418 char ** ppsz_services = vlc_sd_GetNames( VLCIntf, &ppsz_name, NULL );
422 for( i = 0; ppsz_services[i]; i++ )
427 char * name = ppsz_name[i] ? ppsz_name[i] : ppsz_services[i];
428 /* Check whether to enable these menuitems */
429 b_enabled = playlist_IsServicesDiscoveryLoaded( p_playlist, ppsz_services[i] );
431 /* Create the menu entries used in the playlist menu */
432 o_lmi = [[o_mi_services submenu] addItemWithTitle:
433 [NSString stringWithUTF8String: name]
434 action: @selector(servicesChange:)
436 [o_lmi setTarget: self];
437 [o_lmi setRepresentedObject: [NSString stringWithUTF8String: ppsz_services[i]]];
438 if( b_enabled ) [o_lmi setState: NSOnState];
440 /* Create the menu entries for the main menu */
441 o_lmi = [[o_mm_mi_services submenu] addItemWithTitle:
442 [NSString stringWithUTF8String: name]
443 action: @selector(servicesChange:)
445 [o_lmi setTarget: self];
446 [o_lmi setRepresentedObject: [NSString stringWithUTF8String: ppsz_services[i]]];
447 if( b_enabled ) [o_lmi setState: NSOnState];
449 free( ppsz_services[i] );
450 free( ppsz_name[i] );
452 free( ppsz_services );
456 - (void)searchfieldChanged:(NSNotification *)o_notification
458 [o_search_field setStringValue:[[o_notification object] stringValue]];
465 [o_mi_save_playlist setTitle: _NS("Save Playlist...")];
466 [o_mi_play setTitle: _NS("Play")];
467 [o_mi_delete setTitle: _NS("Delete")];
468 [o_mi_recursive_expand setTitle: _NS("Expand Node")];
469 [o_mi_selectall setTitle: _NS("Select All")];
470 [o_mi_info setTitle: _NS("Media Information...")];
471 [o_mi_dl_cover_art setTitle: _NS("Download Cover Art")];
472 [o_mi_preparse setTitle: _NS("Fetch Meta Data")];
473 [o_mi_revealInFinder setTitle: _NS("Reveal in Finder")];
474 [o_mm_mi_revealInFinder setTitle: _NS("Reveal in Finder")];
475 [[o_mm_mi_revealInFinder menu] setAutoenablesItems: NO];
476 [o_mi_sort_name setTitle: _NS("Sort Node by Name")];
477 [o_mi_sort_author setTitle: _NS("Sort Node by Author")];
478 [o_mi_services setTitle: _NS("Services discovery")];
479 [o_mm_mi_services setTitle: _NS("Services discovery")];
480 [o_status_field setStringValue: _NS("No items in the playlist")];
481 [o_status_field_embed setStringValue: _NS("No items in the playlist")];
483 [o_search_field setToolTip: _NS("Search in Playlist")];
484 [o_search_field_other setToolTip: _NS("Search in Playlist")];
485 [o_mi_addNode setTitle: _NS("Add Folder to Playlist")];
487 [o_save_accessory_text setStringValue: _NS("File Format:")];
488 [[o_save_accessory_popup itemAtIndex:0] setTitle: _NS("Extended M3U")];
489 [[o_save_accessory_popup itemAtIndex:1] setTitle: _NS("XML Shareable Playlist Format (XSPF)")];
490 [[o_save_accessory_popup itemAtIndex:2] setTitle: _NS("HTML Playlist")];
493 - (void)swapPlaylists:(id)newList
495 if(newList != o_outline_view)
497 id o_search_field_temp = o_search_field;
498 o_search_field = o_search_field_other;
499 o_search_field_other = o_search_field_temp;
500 [super swapPlaylists:newList];
501 [self playlistUpdated];
505 - (void)playlistUpdated
507 /* Clear indications of any existing column sorting */
508 for( unsigned int i = 0 ; i < [[o_outline_view tableColumns] count] ; i++ )
510 [o_outline_view setIndicatorImage:nil inTableColumn:
511 [[o_outline_view tableColumns] objectAtIndex:i]];
514 [o_outline_view setHighlightedTableColumn:nil];
515 o_tc_sortColumn = nil;
516 // TODO Find a way to keep the dict size to a minimum
517 //[o_outline_dict removeAllObjects];
518 [o_outline_view reloadData];
519 [o_sidebar updateSidebar:[self playingItem]];
520 [[[[VLCMain sharedInstance] wizard] playlistWizard] reloadOutlineView];
521 [[[[VLCMain sharedInstance] bookmarks] dataTable] reloadData];
523 playlist_t *p_playlist = pl_Get( VLCIntf );
526 if( playlist_CurrentSize( p_playlist ) >= 2 )
528 [o_status_field setStringValue: [NSString stringWithFormat:
530 playlist_CurrentSize( p_playlist )]];
531 [o_status_field_embed setStringValue: [NSString stringWithFormat:
533 playlist_CurrentSize( p_playlist )]];
537 if( playlist_IsEmpty( p_playlist ) )
539 [o_status_field setStringValue: _NS("No items in the playlist")];
540 [o_status_field_embed setStringValue: _NS("No items in the playlist")];
544 [o_status_field setStringValue: _NS("1 item")];
545 [o_status_field_embed setStringValue: _NS("1 item")];
550 [self outlineViewSelectionDidChange: nil];
553 - (void)playModeUpdated
555 playlist_t *p_playlist = pl_Get( VLCIntf );
557 bool loop = var_GetBool( p_playlist, "loop" );
558 bool repeat = var_GetBool( p_playlist, "repeat" );
560 [[[VLCMain sharedInstance] controls] repeatOne];
562 [[[VLCMain sharedInstance] controls] repeatAll];
564 [[[VLCMain sharedInstance] controls] repeatOff];
566 [[[VLCMain sharedInstance] controls] shuffle];
569 - (void)outlineViewSelectionDidChange:(NSNotification *)notification
572 playlist_item_t * p_item = [[o_outline_view itemAtRow:[o_outline_view selectedRow]] pointerValue];
576 /* update the state of our Reveal-in-Finder menu items */
577 NSMutableString *o_mrl;
578 char *psz_uri = input_item_GetURI( p_item->p_input );
580 [o_mi_revealInFinder setEnabled: NO];
581 [o_mm_mi_revealInFinder setEnabled: NO];
584 o_mrl = [NSMutableString stringWithUTF8String: psz_uri];
586 /* perform some checks whether it is a file and if it is local at all... */
587 NSRange prefix_range = [o_mrl rangeOfString: @"file:"];
588 if( prefix_range.location != NSNotFound )
589 [o_mrl deleteCharactersInRange: prefix_range];
591 if( [o_mrl characterAtIndex:0] == '/' )
593 [o_mi_revealInFinder setEnabled: YES];
594 [o_mm_mi_revealInFinder setEnabled: YES];
599 if( [[VLCMain sharedInstance] isPlaylistCollapsed] == NO )
601 /* update our info-panel to reflect the new item, if we aren't collapsed */
602 [[[VLCMain sharedInstance] info] updatePanelWithItem:p_item->p_input];
607 - (BOOL)isSelectionEmpty
609 return [o_outline_view selectedRow] == -1;
612 - (void)updateRowSelection
618 playlist_t *p_playlist = pl_Get( VLCIntf );
619 playlist_item_t *p_item, *p_temp_item;
620 NSMutableArray *o_array = [NSMutableArray array];
623 p_item = playlist_CurrentPlayingItem( p_playlist );
630 p_temp_item = p_item;
631 while( p_temp_item->p_parent )
633 [o_array insertObject: [NSValue valueWithPointer: p_temp_item] atIndex: 0];
634 p_temp_item = p_temp_item->p_parent;
638 for( j = 0; j < [o_array count] - 1; j++ )
641 if( ( o_item = [o_outline_dict objectForKey:
642 [NSString stringWithFormat: @"%p",
643 [[o_array objectAtIndex:j] pointerValue]]] ) != nil )
645 [o_outline_view expandItem: o_item];
650 /* Check if p_item is a child of p_node recursively. We need to check the item
651 existence first since OSX sometimes tries to redraw items that have been
652 deleted. We don't do it when not required since this verification takes
653 quite a long time on big playlists (yes, pretty hacky). */
655 - (BOOL)isItem: (playlist_item_t *)p_item
656 inNode: (playlist_item_t *)p_node
657 checkItemExistence:(BOOL)b_check
658 locked:(BOOL)b_locked
661 playlist_t * p_playlist = pl_Get( VLCIntf );
662 playlist_item_t *p_temp_item = p_item;
664 if( p_node == p_item )
667 if( p_node->i_children < 1)
673 if(!b_locked) PL_LOCK;
677 /* Since outlineView: willDisplayCell:... may call this function with
678 p_items that don't exist anymore, first check if the item is still
679 in the playlist. Any cleaner solution welcomed. */
680 for( i = 0; i < p_playlist->all_items.i_size; i++ )
682 if( ARRAY_VAL( p_playlist->all_items, i) == p_item ) break;
683 else if ( i == p_playlist->all_items.i_size - 1 )
685 if(!b_locked) PL_UNLOCK;
693 p_temp_item = p_temp_item->p_parent;
694 if( p_temp_item == p_node )
696 if(!b_locked) PL_UNLOCK;
700 if(!b_locked) PL_UNLOCK;
705 - (BOOL)isItem: (playlist_item_t *)p_item
706 inNode: (playlist_item_t *)p_node
707 checkItemExistence:(BOOL)b_check
709 [self isItem:p_item inNode:p_node checkItemExistence:b_check locked:NO];
712 /* This method is useful for instance to remove the selected children of an
713 already selected node */
714 - (void)removeItemsFrom:(id)o_items ifChildrenOf:(id)o_nodes
717 for( i = 0 ; i < [o_items count] ; i++ )
719 for ( j = 0 ; j < [o_nodes count] ; j++ )
721 if( o_items == o_nodes)
723 if( j == i ) continue;
725 if( [self isItem: [[o_items objectAtIndex:i] pointerValue]
726 inNode: [[o_nodes objectAtIndex:j] pointerValue]
727 checkItemExistence: NO locked:NO] )
729 [o_items removeObjectAtIndex:i];
730 /* We need to execute the next iteration with the same index
731 since the current item has been deleted */
739 - (IBAction)savePlaylist:(id)sender
741 playlist_t * p_playlist = pl_Get( VLCIntf );
743 NSSavePanel *o_save_panel = [NSSavePanel savePanel];
744 NSString * o_name = [NSString stringWithFormat: @"%@", _NS("Untitled")];
746 [o_save_panel setTitle: _NS("Save Playlist")];
747 [o_save_panel setPrompt: _NS("Save")];
748 [o_save_panel setAccessoryView: o_save_accessory_view];
750 if( [o_save_panel runModalForDirectory: nil
751 file: o_name] == NSOKButton )
753 NSString *o_filename = [o_save_panel filename];
755 if( [o_save_accessory_popup indexOfSelectedItem] == 0 )
757 NSString * o_real_filename;
759 range.location = [o_filename length] - [@".m3u" length];
760 range.length = [@".m3u" length];
762 if( [o_filename compare:@".m3u" options: NSCaseInsensitiveSearch
763 range: range] != NSOrderedSame )
765 o_real_filename = [NSString stringWithFormat: @"%@.m3u", o_filename];
769 o_real_filename = o_filename;
771 playlist_Export( p_playlist,
772 [o_real_filename fileSystemRepresentation],
773 p_playlist->p_local_category, "export-m3u" );
775 else if( [o_save_accessory_popup indexOfSelectedItem] == 1 )
777 NSString * o_real_filename;
779 range.location = [o_filename length] - [@".xspf" length];
780 range.length = [@".xspf" length];
782 if( [o_filename compare:@".xspf" options: NSCaseInsensitiveSearch
783 range: range] != NSOrderedSame )
785 o_real_filename = [NSString stringWithFormat: @"%@.xspf", o_filename];
789 o_real_filename = o_filename;
791 playlist_Export( p_playlist,
792 [o_real_filename fileSystemRepresentation],
793 p_playlist->p_local_category, "export-xspf" );
797 NSString * o_real_filename;
799 range.location = [o_filename length] - [@".html" length];
800 range.length = [@".html" length];
802 if( [o_filename compare:@".html" options: NSCaseInsensitiveSearch
803 range: range] != NSOrderedSame )
805 o_real_filename = [NSString stringWithFormat: @"%@.html", o_filename];
809 o_real_filename = o_filename;
811 playlist_Export( p_playlist,
812 [o_real_filename fileSystemRepresentation],
813 p_playlist->p_local_category, "export-html" );
818 /* When called retrieves the selected outlineview row and plays that node or item */
819 - (IBAction)playItem:(id)sender
821 intf_thread_t * p_intf = VLCIntf;
822 playlist_t * p_playlist = pl_Get( p_intf );
824 playlist_item_t *p_item;
825 playlist_item_t *p_node = NULL;
827 p_item = [[o_outline_view itemAtRow:[o_outline_view selectedRow]] pointerValue];
832 if( p_item->i_children == -1 )
834 p_node = p_item->p_parent;
839 if( p_node->i_children > 0 && p_node->pp_children[0]->i_children == -1 )
841 p_item = p_node->pp_children[0];
848 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, pl_Locked, p_node, p_item );
853 - (void)playSidebarItem:(id)item
855 intf_thread_t * p_intf = VLCIntf;
856 playlist_t * p_playlist = pl_Get( p_intf );
858 playlist_item_t *p_item;
859 playlist_item_t *p_node = NULL;
861 p_item = [item pointerValue];
865 if( p_item->i_children == -1 )
867 p_node = p_item->p_parent;
873 if( p_node->i_children > 0 && p_node->pp_children[0]->i_children == -1 )
875 p_item = p_node->pp_children[0];
882 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, pl_Unlocked, p_node, p_item );
886 - (IBAction)revealItemInFinder:(id)sender
888 playlist_item_t * p_item = [[o_outline_view itemAtRow:[o_outline_view selectedRow]] pointerValue];
889 NSMutableString * o_mrl = nil;
891 if(! p_item || !p_item->p_input )
894 char *psz_uri = input_item_GetURI( p_item->p_input );
896 o_mrl = [NSMutableString stringWithUTF8String: psz_uri];
898 /* perform some checks whether it is a file and if it is local at all... */
899 NSRange prefix_range = [o_mrl rangeOfString: @"file:"];
900 if( prefix_range.location != NSNotFound )
901 [o_mrl deleteCharactersInRange: prefix_range];
903 if( [o_mrl characterAtIndex:0] == '/' )
904 [[NSWorkspace sharedWorkspace] selectFile: o_mrl inFileViewerRootedAtPath: o_mrl];
907 /* When called retrieves the selected outlineview row and plays that node or item */
908 - (IBAction)preparseItem:(id)sender
911 NSMutableArray *o_to_preparse;
912 intf_thread_t * p_intf = VLCIntf;
913 playlist_t * p_playlist = pl_Get( p_intf );
915 o_to_preparse = [NSMutableArray arrayWithArray:[[o_outline_view selectedRowEnumerator] allObjects]];
916 i_count = [o_to_preparse count];
920 playlist_item_t *p_item = NULL;
922 for( i = 0; i < i_count; i++ )
924 o_number = [o_to_preparse lastObject];
925 i_row = [o_number intValue];
926 p_item = [[o_outline_view itemAtRow:i_row] pointerValue];
927 [o_to_preparse removeObject: o_number];
928 [o_outline_view deselectRow: i_row];
932 if( p_item->i_children == -1 )
934 playlist_PreparseEnqueue( p_playlist, p_item->p_input );
938 msg_Dbg( p_intf, "preparsing nodes not implemented" );
942 [self playlistUpdated];
945 - (IBAction)downloadCoverArt:(id)sender
948 NSMutableArray *o_to_preparse;
949 intf_thread_t * p_intf = VLCIntf;
950 playlist_t * p_playlist = pl_Get( p_intf );
952 o_to_preparse = [NSMutableArray arrayWithArray:[[o_outline_view selectedRowEnumerator] allObjects]];
953 i_count = [o_to_preparse count];
957 playlist_item_t *p_item = NULL;
959 for( i = 0; i < i_count; i++ )
961 o_number = [o_to_preparse lastObject];
962 i_row = [o_number intValue];
963 p_item = [[o_outline_view itemAtRow:i_row] pointerValue];
964 [o_to_preparse removeObject: o_number];
965 [o_outline_view deselectRow: i_row];
967 if( p_item && p_item->i_children == -1 )
969 playlist_AskForArtEnqueue( p_playlist, p_item->p_input );
972 [self playlistUpdated];
975 - (IBAction)servicesChange:(id)sender
977 NSMenuItem *o_mi = (NSMenuItem *)sender;
978 NSString *o_string = [o_mi representedObject];
979 playlist_t * p_playlist = pl_Get( VLCIntf );
980 if( !playlist_IsServicesDiscoveryLoaded( p_playlist, [o_string UTF8String] ) )
981 playlist_ServicesDiscoveryAdd( p_playlist, [o_string UTF8String] );
983 playlist_ServicesDiscoveryRemove( p_playlist, [o_string UTF8String] );
985 [o_mi setState: playlist_IsServicesDiscoveryLoaded( p_playlist,
986 [o_string UTF8String] ) ? YES : NO];
988 [self playlistUpdated];
992 - (IBAction)selectAll:(id)sender
994 [o_outline_view selectAll: nil];
997 - (IBAction)deleteItem:(id)sender
1000 NSMutableArray *o_to_delete;
1003 playlist_t * p_playlist;
1004 intf_thread_t * p_intf = VLCIntf;
1006 o_to_delete = [NSMutableArray arrayWithArray:[[o_outline_view selectedRowEnumerator] allObjects]];
1007 i_count = [o_to_delete count];
1009 p_playlist = pl_Get( p_intf );
1011 for( int i = 0; i < i_count; i++ )
1013 o_number = [o_to_delete lastObject];
1014 i_row = [o_number intValue];
1015 id o_item = [o_outline_view itemAtRow: i_row];
1016 [o_outline_view deselectRow: i_row];
1019 playlist_item_t *p_item = [o_item pointerValue];
1021 msg_Dbg( p_intf, "deleting item %i (of %i) with id \"%i\", pointerValue \"%p\" and %i children", i+1, i_count,
1022 p_item->p_input->i_id, [o_item pointerValue], p_item->i_children +1 );
1024 [o_to_delete removeObject: o_number];
1026 if( p_item->i_children != -1 )
1027 //is a node and not an item
1029 if( playlist_Status( p_playlist ) != PLAYLIST_STOPPED &&
1030 [self isItem: playlist_CurrentPlayingItem( p_playlist ) inNode:
1031 ((playlist_item_t *)[o_item pointerValue])
1032 checkItemExistence: NO locked:YES] == YES )
1033 // if current item is in selected node and is playing then stop playlist
1034 playlist_Control(p_playlist, PLAYLIST_STOP, pl_Locked );
1036 playlist_NodeDelete( p_playlist, p_item, true, false );
1039 playlist_DeleteFromInput( p_playlist, p_item->p_input, pl_Locked );
1042 [o_outline_dict removeObjectForKey:[NSString stringWithFormat:@"%p",
1043 [o_item pointerValue]]];
1047 [self playlistUpdated];
1050 - (IBAction)sortNodeByName:(id)sender
1052 [self sortNode: SORT_TITLE];
1055 - (IBAction)sortNodeByAuthor:(id)sender
1057 [self sortNode: SORT_ARTIST];
1060 - (void)sortNode:(int)i_mode
1062 playlist_t * p_playlist = pl_Get( VLCIntf );
1063 playlist_item_t * p_item;
1065 if( [o_outline_view selectedRow] > -1 )
1067 p_item = [[o_outline_view itemAtRow: [o_outline_view selectedRow]] pointerValue];
1070 /*If no item is selected, sort the whole playlist*/
1072 p_item = p_playlist->p_root_category;
1076 if( p_item->i_children > -1 ) // the item is a node
1078 playlist_RecursiveNodeSort( p_playlist, p_item, i_mode, ORDER_NORMAL );
1082 playlist_RecursiveNodeSort( p_playlist,
1083 p_item->p_parent, i_mode, ORDER_NORMAL );
1086 [self playlistUpdated];
1089 - (input_item_t *)createItem:(NSDictionary *)o_one_item
1091 intf_thread_t * p_intf = VLCIntf;
1092 playlist_t * p_playlist = pl_Get( p_intf );
1094 input_item_t *p_input;
1096 BOOL b_rem = FALSE, b_dir = FALSE;
1097 NSString *o_uri, *o_name;
1102 o_uri = (NSString *)[o_one_item objectForKey: @"ITEM_URL"];
1103 o_name = (NSString *)[o_one_item objectForKey: @"ITEM_NAME"];
1104 o_options = (NSArray *)[o_one_item objectForKey: @"ITEM_OPTIONS"];
1106 /* Find the name for a disc entry (i know, can you believe the trouble?) */
1107 if( ( !o_name || [o_name isEqualToString:@""] ) && [o_uri rangeOfString: @"/dev/"].location != NSNotFound )
1109 int i_count, i_index;
1110 struct statfs *mounts = NULL;
1112 i_count = getmntinfo (&mounts, MNT_NOWAIT);
1113 /* getmntinfo returns a pointer to static data. Do not free. */
1114 for( i_index = 0 ; i_index < i_count; i_index++ )
1116 NSMutableString *o_temp, *o_temp2;
1117 o_temp = [NSMutableString stringWithString: o_uri];
1118 o_temp2 = [NSMutableString stringWithUTF8String: mounts[i_index].f_mntfromname];
1119 [o_temp replaceOccurrencesOfString: @"/dev/rdisk" withString: @"/dev/disk" options:NSLiteralSearch range:NSMakeRange(0, [o_temp length]) ];
1120 [o_temp2 replaceOccurrencesOfString: @"s0" withString: @"" options:NSLiteralSearch range:NSMakeRange(0, [o_temp2 length]) ];
1121 [o_temp2 replaceOccurrencesOfString: @"s1" withString: @"" options:NSLiteralSearch range:NSMakeRange(0, [o_temp2 length]) ];
1123 if( strstr( [o_temp fileSystemRepresentation], [o_temp2 fileSystemRepresentation] ) != NULL )
1125 o_name = [[NSFileManager defaultManager] displayNameAtPath: [NSString stringWithUTF8String:mounts[i_index].f_mntonname]];
1130 if( [[NSFileManager defaultManager] fileExistsAtPath:o_uri isDirectory:&b_dir] && b_dir &&
1131 [[NSWorkspace sharedWorkspace] getFileSystemInfoForPath: o_uri isRemovable: &b_rem
1132 isWritable:NULL isUnmountable:NULL description:NULL type:NULL] && b_rem )
1134 /* All of this is to make sure CD's play when you D&D them on VLC */
1135 /* Converts mountpoint to a /dev file */
1138 NSMutableString *o_temp;
1140 buf = (struct statfs *) malloc (sizeof(struct statfs));
1141 statfs( [o_uri fileSystemRepresentation], buf );
1142 psz_dev = strdup(buf->f_mntfromname);
1143 o_temp = [NSMutableString stringWithUTF8String: psz_dev ];
1144 [o_temp replaceOccurrencesOfString: @"/dev/disk" withString: @"/dev/rdisk" options:NSLiteralSearch range:NSMakeRange(0, [o_temp length]) ];
1145 [o_temp replaceOccurrencesOfString: @"s0" withString: @"" options:NSLiteralSearch range:NSMakeRange(0, [o_temp length]) ];
1146 [o_temp replaceOccurrencesOfString: @"s1" withString: @"" options:NSLiteralSearch range:NSMakeRange(0, [o_temp length]) ];
1150 p_input = input_item_New( p_playlist, [o_uri fileSystemRepresentation], o_name ? [o_name UTF8String] : NULL );
1156 for( i = 0; i < (int)[o_options count]; i++ )
1158 input_item_AddOption( p_input, [[o_options objectAtIndex:i] UTF8String],
1159 VLC_INPUT_OPTION_TRUSTED );
1163 /* Recent documents menu */
1164 o_true_file = [NSURL URLWithString: o_uri];
1165 if( o_true_file != nil && (BOOL)config_GetInt( p_playlist, "macosx-recentitems" ) == YES )
1167 [[NSDocumentController sharedDocumentController]
1168 noteNewRecentDocumentURL: o_true_file];
1173 - (void)appendArray:(NSArray*)o_array atPos:(int)i_position enqueue:(BOOL)b_enqueue
1176 playlist_t * p_playlist = pl_Get( VLCIntf );
1179 for( i_item = 0; i_item < (int)[o_array count]; i_item++ )
1181 input_item_t *p_input;
1182 NSDictionary *o_one_item;
1185 o_one_item = [o_array objectAtIndex: i_item];
1186 p_input = [self createItem: o_one_item];
1193 /* FIXME: playlist_AddInput() can fail */
1195 playlist_AddInput( p_playlist, p_input, PLAYLIST_INSERT,
1196 i_position == -1 ? PLAYLIST_END : i_position + i_item, true,
1199 if( i_item == 0 && !b_enqueue )
1201 playlist_item_t *p_item = NULL;
1202 playlist_item_t *p_node = NULL;
1203 p_item = playlist_ItemGetByInput( p_playlist, p_input );
1206 if( p_item->i_children == -1 )
1207 p_node = p_item->p_parent;
1211 if( p_node->i_children > 0 && p_node->pp_children[0]->i_children == -1 )
1212 p_item = p_node->pp_children[0];
1216 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, pl_Locked, p_node, p_item );
1219 vlc_gc_decref( p_input );
1223 [self playlistUpdated];
1226 - (void)appendNodeArray:(NSArray*)o_array inNode:(playlist_item_t *)p_node atPos:(int)i_position enqueue:(BOOL)b_enqueue
1229 playlist_t * p_playlist = pl_Get( VLCIntf );
1231 for( i_item = 0; i_item < (int)[o_array count]; i_item++ )
1233 input_item_t *p_input;
1234 NSDictionary *o_one_item;
1237 o_one_item = [o_array objectAtIndex: i_item];
1238 p_input = [self createItem: o_one_item];
1240 if( !p_input ) continue;
1244 playlist_NodeAddInput( p_playlist, p_input, p_node,
1247 PLAYLIST_END : i_position + i_item,
1251 if( i_item == 0 && !b_enqueue )
1253 playlist_item_t *p_item;
1254 p_item = playlist_ItemGetByInput( p_playlist, p_input );
1255 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, pl_Locked, p_node, p_item );
1258 vlc_gc_decref( p_input );
1260 [self playlistUpdated];
1263 - (NSMutableArray *)subSearchItem:(playlist_item_t *)p_item
1265 playlist_t *p_playlist = pl_Get( VLCIntf );
1266 playlist_item_t *p_selected_item;
1267 int i_current, i_selected_row;
1269 i_selected_row = [o_outline_view selectedRow];
1270 if (i_selected_row < 0)
1273 p_selected_item = (playlist_item_t *)[[o_outline_view itemAtRow:
1274 i_selected_row] pointerValue];
1276 for( i_current = 0; i_current < p_item->i_children ; i_current++ )
1279 NSString *o_current_name, *o_current_author;
1282 o_current_name = [NSString stringWithUTF8String:
1283 p_item->pp_children[i_current]->p_input->psz_name];
1284 psz_temp = input_item_GetInfo( p_item->p_input ,
1285 _("Meta-information"),_("Artist") );
1286 o_current_author = [NSString stringWithUTF8String: psz_temp];
1290 if( p_selected_item == p_item->pp_children[i_current] &&
1291 b_selected_item_met == NO )
1293 b_selected_item_met = YES;
1295 else if( p_selected_item == p_item->pp_children[i_current] &&
1296 b_selected_item_met == YES )
1300 else if( b_selected_item_met == YES &&
1301 ( [o_current_name rangeOfString:[o_search_field
1302 stringValue] options:NSCaseInsensitiveSearch].length ||
1303 [o_current_author rangeOfString:[o_search_field
1304 stringValue] options:NSCaseInsensitiveSearch].length ) )
1306 /*Adds the parent items in the result array as well, so that we can
1308 return [NSMutableArray arrayWithObject: [NSValue
1309 valueWithPointer: p_item->pp_children[i_current]]];
1311 if( p_item->pp_children[i_current]->i_children > 0 )
1313 id o_result = [self subSearchItem:
1314 p_item->pp_children[i_current]];
1315 if( o_result != NULL )
1317 [o_result insertObject: [NSValue valueWithPointer:
1318 p_item->pp_children[i_current]] atIndex:0];
1326 - (IBAction)searchItem:(id)sender
1328 playlist_t * p_playlist = pl_Get( VLCIntf );
1334 b_selected_item_met = NO;
1336 /*First, only search after the selected item:*
1337 *(b_selected_item_met = NO) */
1338 o_result = [self subSearchItem:p_playlist->p_root_category];
1339 if( o_result == NULL )
1341 /* If the first search failed, search again from the beginning */
1342 o_result = [self subSearchItem:p_playlist->p_root_category];
1344 if( o_result != NULL )
1347 if( [[o_result objectAtIndex: 0] pointerValue] ==
1348 p_playlist->p_local_category )
1353 for( i = i_start ; i < [o_result count] - 1 ; i++ )
1355 [o_outline_view expandItem: [o_outline_dict objectForKey:
1356 [NSString stringWithFormat: @"%p",
1357 [[o_result objectAtIndex: i] pointerValue]]]];
1359 i_row = [o_outline_view rowForItem: [o_outline_dict objectForKey:
1360 [NSString stringWithFormat: @"%p",
1361 [[o_result objectAtIndex: [o_result count] - 1 ]
1366 [o_outline_view selectRowIndexes:[NSIndexSet indexSetWithIndex:i_row] byExtendingSelection:NO];
1367 [o_outline_view scrollRowToVisible: i_row];
1371 - (IBAction)recursiveExpandNode:(id)sender
1373 id o_item = [o_outline_view itemAtRow: [o_outline_view selectedRow]];
1374 playlist_item_t *p_item = (playlist_item_t *)[o_item pointerValue];
1376 if( ![[o_outline_view dataSource] outlineView: o_outline_view
1377 isItemExpandable: o_item] )
1379 o_item = [o_outline_dict objectForKey: [NSString
1380 stringWithFormat: @"%p", p_item->p_parent]];
1383 /* We need to collapse the node first, since OSX refuses to recursively
1384 expand an already expanded node, even if children nodes are collapsed. */
1385 [o_outline_view collapseItem: o_item collapseChildren: YES];
1386 [o_outline_view expandItem: o_item expandChildren: YES];
1389 - (NSMenu *)menuForEvent:(NSEvent *)o_event
1395 pt = [o_outline_view convertPoint: [o_event locationInWindow]
1397 int row = [o_outline_view rowAtPoint:pt];
1399 [o_outline_view selectRowIndexes:[NSIndexSet indexSetWithIndex:row] byExtendingSelection:NO];
1401 b_item_sel = ( row != -1 && [o_outline_view selectedRow] != -1 );
1402 b_rows = [o_outline_view numberOfRows] != 0;
1404 [o_mi_play setEnabled: b_item_sel];
1405 [o_mi_delete setEnabled: b_item_sel];
1406 [o_mi_selectall setEnabled: b_rows];
1407 [o_mi_info setEnabled: b_item_sel];
1408 [o_mi_preparse setEnabled: b_item_sel];
1409 [o_mi_recursive_expand setEnabled: b_item_sel];
1410 [o_mi_sort_name setEnabled: b_item_sel];
1411 [o_mi_sort_author setEnabled: b_item_sel];
1413 return( o_ctx_menu );
1416 - (void)outlineView: (NSOutlineView *)o_tv
1417 didClickTableColumn:(NSTableColumn *)o_tc
1419 int i_mode, i_type = 0;
1420 intf_thread_t *p_intf = VLCIntf;
1422 playlist_t *p_playlist = pl_Get( p_intf );
1424 /* Check whether the selected table column header corresponds to a
1425 sortable table column*/
1426 if( !( o_tc == o_tc_name || o_tc == o_tc_author ) )
1431 if( o_tc_sortColumn == o_tc )
1433 b_isSortDescending = !b_isSortDescending;
1437 b_isSortDescending = false;
1440 if( o_tc == o_tc_name )
1442 i_mode = SORT_TITLE;
1444 else if( o_tc == o_tc_author )
1446 i_mode = SORT_ARTIST;
1449 if( b_isSortDescending )
1451 i_type = ORDER_REVERSE;
1455 i_type = ORDER_NORMAL;
1459 playlist_RecursiveNodeSort( p_playlist, p_playlist->p_root_category, i_mode, i_type );
1462 [self playlistUpdated];
1464 o_tc_sortColumn = o_tc;
1465 [o_outline_view setHighlightedTableColumn:o_tc];
1467 if( b_isSortDescending )
1469 [o_outline_view setIndicatorImage:o_descendingSortingImage
1470 inTableColumn:o_tc];
1474 [o_outline_view setIndicatorImage:o_ascendingSortingImage
1475 inTableColumn:o_tc];
1480 - (void)outlineView:(NSOutlineView *)outlineView
1481 willDisplayCell:(id)cell
1482 forTableColumn:(NSTableColumn *)tableColumn
1485 playlist_t *p_playlist = pl_Get( VLCIntf );
1490 o_playing_item = [o_outline_dict objectForKey:
1491 [NSString stringWithFormat:@"%p", playlist_CurrentPlayingItem( p_playlist )]];
1494 if( [self isItem: [o_playing_item pointerValue] inNode:
1495 [item pointerValue] checkItemExistence: YES]
1496 || [o_playing_item isEqual: item] )
1498 [cell setFont: [[NSFontManager sharedFontManager] convertFont:[cell font] toHaveTrait:NSBoldFontMask]];
1502 [cell setFont: [[NSFontManager sharedFontManager] convertFont:[cell font] toNotHaveTrait:NSBoldFontMask]];
1508 playlist_t *p_playlist = pl_Get( VLCIntf );
1513 o_playing_item = [o_outline_dict objectForKey:
1514 [NSString stringWithFormat:@"%p", playlist_CurrentPlayingItem( p_playlist )]];
1517 return o_playing_item;
1520 - (IBAction)addNode:(id)sender
1522 playlist_t * p_playlist = pl_Get( VLCIntf );
1523 vlc_thread_set_priority( p_playlist, VLC_THREAD_PRIORITY_LOW );
1526 playlist_NodeCreate( p_playlist, _("Empty Folder"),
1527 p_playlist->p_local_category, PLAYLIST_END, 0, NULL );
1530 [self playlistUpdated];
1534 @implementation VLCPlaylist (NSOutlineViewDataSource)
1536 - (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item
1538 id o_value = [super outlineView: outlineView child: index ofItem: item];
1539 playlist_t *p_playlist = pl_Get( VLCIntf );
1542 if( playlist_CurrentSize( p_playlist ) >= 2 )
1544 [o_status_field setStringValue: [NSString stringWithFormat:
1546 playlist_CurrentSize( p_playlist )]];
1547 [o_status_field_embed setStringValue: [NSString stringWithFormat:
1549 playlist_CurrentSize( p_playlist )]];
1553 if( playlist_IsEmpty( p_playlist ) )
1555 [o_status_field setStringValue: _NS("No items in the playlist")];
1556 [o_status_field_embed setStringValue: _NS("No items in the playlist")];
1560 [o_status_field setStringValue: _NS("1 item")];
1561 [o_status_field_embed setStringValue: _NS("1 item")];
1566 [o_outline_dict setObject:o_value forKey:[NSString stringWithFormat:@"%p",
1567 [o_value pointerValue]]];
1572 /* Required for drag & drop and reordering */
1573 - (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pboard
1576 playlist_t *p_playlist = pl_Get( VLCIntf );
1578 /* First remove the items that were moved during the last drag & drop
1580 [o_items_array removeAllObjects];
1581 [o_nodes_array removeAllObjects];
1583 for( i = 0 ; i < [items count] ; i++ )
1585 id o_item = [items objectAtIndex: i];
1587 /* Refuse to move items that are not in the General Node
1588 (Service Discovery) */
1589 if( ![self isItem: [o_item pointerValue] inNode:
1590 p_playlist->p_local_category checkItemExistence: NO] &&
1591 var_CreateGetBool( p_playlist, "media-library" ) &&
1592 ![self isItem: [o_item pointerValue] inNode:
1593 p_playlist->p_ml_category checkItemExistence: NO] ||
1594 [o_item pointerValue] == p_playlist->p_local_category ||
1595 [o_item pointerValue] == p_playlist->p_ml_category )
1599 /* Fill the items and nodes to move in 2 different arrays */
1600 if( ((playlist_item_t *)[o_item pointerValue])->i_children > 0 )
1601 [o_nodes_array addObject: o_item];
1603 [o_items_array addObject: o_item];
1606 /* Now we need to check if there are selected items that are in already
1607 selected nodes. In that case, we only want to move the nodes */
1608 [self removeItemsFrom: o_nodes_array ifChildrenOf: o_nodes_array];
1609 [self removeItemsFrom: o_items_array ifChildrenOf: o_nodes_array];
1611 /* We add the "VLCPlaylistItemPboardType" type to be able to recognize
1612 a Drop operation coming from the playlist. */
1614 [pboard declareTypes: [NSArray arrayWithObjects:
1615 @"VLCPlaylistItemPboardType", nil] owner: self];
1616 [pboard setData:[NSData data] forType:@"VLCPlaylistItemPboardType"];
1621 - (NSDragOperation)outlineView:(NSOutlineView *)outlineView validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(NSInteger)index
1623 playlist_t *p_playlist = pl_Get( VLCIntf );
1624 NSPasteboard *o_pasteboard = [info draggingPasteboard];
1626 if( !p_playlist ) return NSDragOperationNone;
1628 /* Dropping ON items is not allowed if item is not a node */
1631 if( index == NSOutlineViewDropOnItemIndex &&
1632 ((playlist_item_t *)[item pointerValue])->i_children == -1 )
1634 return NSDragOperationNone;
1638 /* Don't allow on drop on playlist root element's child */
1639 if( !item && index != NSOutlineViewDropOnItemIndex)
1641 return NSDragOperationNone;
1644 /* We refuse to drop an item in anything else than a child of the General
1645 Node. We still accept items that would be root nodes of the outlineview
1646 however, to allow drop in an empty playlist. */
1647 if( !( ([self isItem: [item pointerValue] inNode: p_playlist->p_local_category checkItemExistence: NO] ||
1648 ( var_CreateGetBool( p_playlist, "media-library" ) && [self isItem: [item pointerValue] inNode: p_playlist->p_ml_category checkItemExistence: NO] ) ) || item == nil ) )
1650 return NSDragOperationNone;
1653 /* Drop from the Playlist */
1654 if( [[o_pasteboard types] containsObject: @"VLCPlaylistItemPboardType"] )
1657 for( i = 0 ; i < [o_nodes_array count] ; i++ )
1659 /* We refuse to Drop in a child of an item we are moving */
1660 if( [self isItem: [item pointerValue] inNode:
1661 [[o_nodes_array objectAtIndex: i] pointerValue]
1662 checkItemExistence: NO] )
1664 return NSDragOperationNone;
1667 return NSDragOperationMove;
1670 /* Drop from the Finder */
1671 else if( [[o_pasteboard types] containsObject: NSFilenamesPboardType] )
1673 return NSDragOperationGeneric;
1675 return NSDragOperationNone;
1678 - (BOOL)outlineView:(NSOutlineView *)outlineView acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(NSInteger)index
1680 playlist_t * p_playlist = pl_Get( VLCIntf );
1681 NSPasteboard *o_pasteboard = [info draggingPasteboard];
1683 /* Drag & Drop inside the playlist */
1684 if( [[o_pasteboard types] containsObject: @"VLCPlaylistItemPboardType"] )
1686 int i_row, i_removed_from_node = 0;
1688 playlist_item_t *p_new_parent, *p_item = NULL;
1689 NSArray *o_all_items = [o_nodes_array arrayByAddingObjectsFromArray:
1691 /* If the item is to be dropped as root item of the outline, make it a
1692 child of the General node.
1693 Else, choose the proposed parent as parent. */
1694 if( item == nil ) p_new_parent = p_playlist->p_local_category;
1695 else p_new_parent = [item pointerValue];
1697 /* Make sure the proposed parent is a node.
1698 (This should never be true) */
1699 if( p_new_parent->i_children < 0 )
1704 for( i = 0; i < [o_all_items count]; i++ )
1706 playlist_item_t *p_old_parent = NULL;
1707 int i_old_index = 0;
1709 p_item = [[o_all_items objectAtIndex:i] pointerValue];
1710 p_old_parent = p_item->p_parent;
1713 /* We may need the old index later */
1714 if( p_new_parent == p_old_parent )
1717 for( j = 0; j < p_old_parent->i_children; j++ )
1719 if( p_old_parent->pp_children[j] == p_item )
1728 // Actually detach the item from the old position
1729 if( playlist_NodeRemoveItem( p_playlist, p_item, p_old_parent ) ==
1733 /* Calculate the new index */
1736 /* If we move the item in the same node, we need to take into
1737 account that one item will be deleted */
1740 if ((p_new_parent == p_old_parent &&
1741 i_old_index < index + (int)i) )
1743 i_removed_from_node++;
1745 i_new_index = index + i - i_removed_from_node;
1747 // Reattach the item to the new position
1748 playlist_NodeInsert( p_playlist, p_item, p_new_parent, i_new_index );
1752 [self playlistUpdated];
1753 i_row = [o_outline_view rowForItem:[o_outline_dict
1754 objectForKey:[NSString stringWithFormat: @"%p",
1755 [[o_all_items objectAtIndex: 0] pointerValue]]]];
1759 i_row = [o_outline_view rowForItem:[o_outline_dict
1760 objectForKey:[NSString stringWithFormat: @"%p", p_new_parent]]];
1763 [o_outline_view deselectAll: self];
1764 [o_outline_view selectRowIndexes:[NSIndexSet indexSetWithIndex:i_row] byExtendingSelection:NO];
1765 [o_outline_view scrollRowToVisible: i_row];
1770 else if( [[o_pasteboard types] containsObject: NSFilenamesPboardType] )
1773 playlist_item_t *p_node = [item pointerValue];
1775 NSArray *o_array = [NSArray array];
1776 NSArray *o_values = [[o_pasteboard propertyListForType:
1777 NSFilenamesPboardType]
1778 sortedArrayUsingSelector:
1779 @selector(caseInsensitiveCompare:)];
1781 for( i = 0; i < (int)[o_values count]; i++)
1783 NSDictionary *o_dic;
1784 char *psz_uri = make_URI([[o_values objectAtIndex:i] UTF8String], NULL);
1788 o_dic = [NSDictionary dictionaryWithObject:[NSString stringWithCString:psz_uri encoding:NSUTF8StringEncoding] forKey:@"ITEM_URL"];
1792 o_array = [o_array arrayByAddingObject: o_dic];
1797 [self appendArray:o_array atPos:index enqueue: YES];
1801 assert( p_node->i_children != -1 );
1802 [self appendNodeArray:o_array inNode: p_node
1803 atPos:index enqueue:YES];