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"
52 #import <vlc_services_discovery.h>
54 #import <vlc_interface.h>
59 /*****************************************************************************
60 * VLCPlaylistView implementation
61 *****************************************************************************/
62 @implementation VLCPlaylistView
64 - (NSMenu *)menuForEvent:(NSEvent *)o_event
66 return( [[self delegate] menuForEvent: o_event] );
69 - (void)keyDown:(NSEvent *)o_event
73 if( [[o_event characters] length] )
75 key = [[o_event characters] characterAtIndex: 0];
80 case NSDeleteCharacter:
81 case NSDeleteFunctionKey:
82 case NSDeleteCharFunctionKey:
83 case NSBackspaceCharacter:
84 [[self delegate] deleteItem:self];
87 case NSEnterCharacter:
88 case NSCarriageReturnCharacter:
89 [(VLCPlaylist *)[[VLCMain sharedInstance] playlist] playItem:self];
93 [super keyDown: o_event];
100 /*****************************************************************************
101 * VLCPlaylistCommon implementation
103 * This class the superclass of the VLCPlaylist and VLCPlaylistWizard.
104 * It contains the common methods and elements of these 2 entities.
105 *****************************************************************************/
106 @implementation VLCPlaylistCommon
113 o_outline_dict = [[NSMutableDictionary alloc] init];
119 playlist_t * p_playlist = pl_Get( VLCIntf );
120 [o_outline_view setTarget: self];
121 [o_outline_view setDelegate: self];
122 [o_outline_view setDataSource: self];
123 [o_outline_view setAllowsEmptySelection: NO];
124 [o_outline_view expandItem: [o_outline_view itemAtRow:0]];
126 [o_outline_view_other setTarget: self];
127 [o_outline_view_other setDelegate: self];
128 [o_outline_view_other setDataSource: self];
129 [o_outline_view_other setAllowsEmptySelection: NO];
136 [[o_tc_name headerCell] setStringValue:_NS("Name")];
137 [[o_tc_author headerCell] setStringValue:_NS("Author")];
138 [[o_tc_duration headerCell] setStringValue:_NS("Duration")];
140 [[o_tc_name_other headerCell] setStringValue:_NS("Name")];
141 [[o_tc_author_other headerCell] setStringValue:_NS("Author")];
142 [[o_tc_duration_other headerCell] setStringValue:_NS("Duration")];
145 - (void)swapPlaylists:(id)newList
147 if(newList != o_outline_view)
149 id o_outline_view_temp = o_outline_view;
150 id o_tc_author_temp = o_tc_author;
151 id o_tc_duration_temp = o_tc_duration;
152 id o_tc_name_temp = o_tc_name;
153 o_outline_view = o_outline_view_other;
154 o_tc_author = o_tc_author_other;
155 o_tc_duration = o_tc_duration_other;
156 o_tc_name = o_tc_name_other;
157 o_outline_view_other = o_outline_view_temp;
158 o_tc_author_other = o_tc_author_temp;
159 o_tc_duration_other = o_tc_duration_temp;
160 o_tc_name_other = o_tc_name_temp;
164 - (NSOutlineView *)outlineView
166 return o_outline_view;
169 - (playlist_item_t *)selectedPlaylistItem
171 return [[o_outline_view itemAtRow: [o_outline_view selectedRow]]
177 @implementation VLCPlaylistCommon (NSOutlineViewDataSource)
179 /* return the number of children for Obj-C pointer item */ /* DONE */
180 - (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
183 playlist_item_t *p_item = NULL;
184 playlist_t * p_playlist = pl_Get( VLCIntf );
185 //assert( outlineView == o_outline_view );
188 p_item = p_playlist->p_root_category;
190 p_item = (playlist_item_t *)[item pointerValue];
193 i_return = p_item->i_children;
195 return i_return > 0 ? i_return : 0;
198 /* return the child at index for the Obj-C pointer item */ /* DONE */
199 - (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item
201 playlist_item_t *p_return = NULL, *p_item = NULL;
203 playlist_t * p_playlist = pl_Get( VLCIntf );
209 p_item = p_playlist->p_root_category;
213 p_item = (playlist_item_t *)[item pointerValue];
215 if( p_item && index < p_item->i_children && index >= 0 )
216 p_return = p_item->pp_children[index];
219 o_value = [o_outline_dict objectForKey:[NSString stringWithFormat: @"%p", p_return]];
223 /* FIXME: Why is there a warning if that happens all the time and seems
224 * to be normal? Add an assert and fix it.
225 * msg_Warn( VLCIntf, "playlist item misses pointer value, adding one" ); */
226 o_value = [[NSValue valueWithPointer: p_return] retain];
231 /* is the item expandable */
232 - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item
235 playlist_t *p_playlist = pl_Get( VLCIntf );
241 if( p_playlist->p_root_category )
243 i_return = p_playlist->p_root_category->i_children;
248 playlist_item_t *p_item = (playlist_item_t *)[item pointerValue];
250 i_return = p_item->i_children;
254 return (i_return >= 0);
257 /* retrieve the string values for the cells */
258 - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)o_tc byItem:(id)item
261 playlist_item_t *p_item;
263 /* For error handling */
264 static BOOL attempted_reload = NO;
266 if( item == nil || ![item isKindOfClass: [NSValue class]] )
268 /* Attempt to fix the error by asking for a data redisplay
269 * This might cause infinite loop, so add a small check */
270 if( !attempted_reload )
272 attempted_reload = YES;
273 [outlineView reloadData];
278 p_item = (playlist_item_t *)[item pointerValue];
279 if( !p_item || !p_item->p_input )
281 /* Attempt to fix the error by asking for a data redisplay
282 * This might cause infinite loop, so add a small check */
283 if( !attempted_reload )
285 attempted_reload = YES;
286 [outlineView reloadData];
291 attempted_reload = NO;
293 if( [[o_tc identifier] isEqualToString:@"name"] )
295 /* sanity check to prevent the NSString class from crashing */
296 char *psz_title = input_item_GetTitleFbName( p_item->p_input );
299 o_value = [NSString stringWithUTF8String: psz_title];
303 else if( [[o_tc identifier] isEqualToString:@"artist"] )
305 char *psz_artist = input_item_GetArtist( p_item->p_input );
307 o_value = [NSString stringWithUTF8String: psz_artist];
310 else if( [[o_tc identifier] isEqualToString:@"duration"] )
312 char psz_duration[MSTRTIME_MAX_SIZE];
313 mtime_t dur = input_item_GetDuration( p_item->p_input );
316 secstotimestr( psz_duration, dur/1000000 );
317 o_value = [NSString stringWithUTF8String: psz_duration];
322 else if( [[o_tc identifier] isEqualToString:@"status"] )
324 if( input_item_HasErrorWhenReading( p_item->p_input ) )
326 o_value = [[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode(kAlertCautionIcon)];
327 [o_value setSize: NSMakeSize(16,16)];
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")];
481 [o_search_field setToolTip: _NS("Search in Playlist")];
482 [o_search_field_other setToolTip: _NS("Search in Playlist")];
484 [o_save_accessory_text setStringValue: _NS("File Format:")];
485 [[o_save_accessory_popup itemAtIndex:0] setTitle: _NS("Extended M3U")];
486 [[o_save_accessory_popup itemAtIndex:1] setTitle: _NS("XML Shareable Playlist Format (XSPF)")];
487 [[o_save_accessory_popup itemAtIndex:2] setTitle: _NS("HTML Playlist")];
490 - (void)swapPlaylists:(id)newList
492 if(newList != o_outline_view)
494 id o_search_field_temp = o_search_field;
495 o_search_field = o_search_field_other;
496 o_search_field_other = o_search_field_temp;
497 [super swapPlaylists:newList];
498 [self playlistUpdated];
502 - (void)playlistUpdated
504 /* Clear indications of any existing column sorting */
505 NSUInteger count = [[o_outline_view tableColumns] count];
506 for( NSUInteger i = 0 ; i < count ; i++ )
508 [o_outline_view setIndicatorImage:nil inTableColumn:
509 [[o_outline_view tableColumns] objectAtIndex:i]];
512 [o_outline_view setHighlightedTableColumn:nil];
513 o_tc_sortColumn = nil;
514 // TODO Find a way to keep the dict size to a minimum
515 //[o_outline_dict removeAllObjects];
516 [o_outline_view reloadData];
517 [[[[VLCMain sharedInstance] wizard] playlistWizard] reloadOutlineView];
518 [[[[VLCMain sharedInstance] bookmarks] dataTable] reloadData];
520 [self outlineViewSelectionDidChange: nil];
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 );
534 [o_mi_revealInFinder setEnabled: NO];
535 [o_mm_mi_revealInFinder setEnabled: NO];
538 o_mrl = [NSMutableString stringWithUTF8String: psz_uri];
540 /* perform some checks whether it is a file and if it is local at all... */
541 NSRange prefix_range = [o_mrl rangeOfString: @"file:"];
542 if( prefix_range.location != NSNotFound )
543 [o_mrl deleteCharactersInRange: prefix_range];
545 if( [o_mrl characterAtIndex:0] == '/' )
547 [o_mi_revealInFinder setEnabled: YES];
548 [o_mm_mi_revealInFinder setEnabled: YES];
553 /* update our info-panel to reflect the new item */
554 [[[VLCMain sharedInstance] info] updatePanelWithItem:p_item->p_input];
558 - (BOOL)isSelectionEmpty
560 return [o_outline_view selectedRow] == -1;
563 - (void)updateRowSelection
566 playlist_t *p_playlist = pl_Get( VLCIntf );
567 playlist_item_t *p_item, *p_temp_item;
568 NSMutableArray *o_array = [NSMutableArray array];
571 p_item = playlist_CurrentPlayingItem( p_playlist );
578 p_temp_item = p_item;
579 while( p_temp_item->p_parent )
581 [o_array insertObject: [NSValue valueWithPointer: p_temp_item] atIndex: 0];
582 p_temp_item = p_temp_item->p_parent;
586 NSUInteger count = [o_array count];
587 for( NSUInteger j = 0; j < count - 1; j++ )
590 if( ( o_item = [o_outline_dict objectForKey:
591 [NSString stringWithFormat: @"%p",
592 [[o_array objectAtIndex:j] pointerValue]]] ) != nil )
594 [o_outline_view expandItem: o_item];
599 /* Check if p_item is a child of p_node recursively. We need to check the item
600 existence first since OSX sometimes tries to redraw items that have been
601 deleted. We don't do it when not required since this verification takes
602 quite a long time on big playlists (yes, pretty hacky). */
604 - (BOOL)isItem: (playlist_item_t *)p_item
605 inNode: (playlist_item_t *)p_node
606 checkItemExistence:(BOOL)b_check
607 locked:(BOOL)b_locked
610 playlist_t * p_playlist = pl_Get( VLCIntf );
611 playlist_item_t *p_temp_item = p_item;
613 if( p_node == p_item )
616 if( p_node->i_children < 1)
622 if(!b_locked) PL_LOCK;
626 /* Since outlineView: willDisplayCell:... may call this function with
627 p_items that don't exist anymore, first check if the item is still
628 in the playlist. Any cleaner solution welcomed. */
629 for( i = 0; i < p_playlist->all_items.i_size; i++ )
631 if( ARRAY_VAL( p_playlist->all_items, i) == p_item ) break;
632 else if ( i == p_playlist->all_items.i_size - 1 )
634 if(!b_locked) PL_UNLOCK;
642 p_temp_item = p_temp_item->p_parent;
643 if( p_temp_item == p_node )
645 if(!b_locked) PL_UNLOCK;
649 if(!b_locked) PL_UNLOCK;
654 - (BOOL)isItem: (playlist_item_t *)p_item
655 inNode: (playlist_item_t *)p_node
656 checkItemExistence:(BOOL)b_check
658 return [self isItem:p_item inNode:p_node checkItemExistence:b_check locked:NO];
661 /* This method is useful for instance to remove the selected children of an
662 already selected node */
663 - (void)removeItemsFrom:(id)o_items ifChildrenOf:(id)o_nodes
665 NSUInteger itemCount = [o_items count];
666 NSUInteger nodeCount = [o_nodes count];
667 for( NSUInteger i = 0 ; i < itemCount ; i++ )
669 for ( NSUInteger j = 0 ; j < nodeCount ; j++ )
671 if( o_items == o_nodes)
673 if( j == i ) continue;
675 if( [self isItem: [[o_items objectAtIndex:i] pointerValue]
676 inNode: [[o_nodes objectAtIndex:j] pointerValue]
677 checkItemExistence: NO locked:NO] )
679 [o_items removeObjectAtIndex:i];
680 /* We need to execute the next iteration with the same index
681 since the current item has been deleted */
689 - (IBAction)savePlaylist:(id)sender
691 playlist_t * p_playlist = pl_Get( VLCIntf );
693 NSSavePanel *o_save_panel = [NSSavePanel savePanel];
694 NSString * o_name = [NSString stringWithFormat: @"%@", _NS("Untitled")];
696 [o_save_panel setTitle: _NS("Save Playlist")];
697 [o_save_panel setPrompt: _NS("Save")];
698 [o_save_panel setAccessoryView: o_save_accessory_view];
700 if( [o_save_panel runModalForDirectory: nil
701 file: o_name] == NSOKButton )
703 NSString *o_filename = [[o_save_panel URL] path];
705 if( [o_save_accessory_popup indexOfSelectedItem] == 0 )
707 NSString * o_real_filename;
709 range.location = [o_filename length] - [@".m3u" length];
710 range.length = [@".m3u" length];
712 if( [o_filename compare:@".m3u" options: NSCaseInsensitiveSearch
713 range: range] != NSOrderedSame )
715 o_real_filename = [NSString stringWithFormat: @"%@.m3u", o_filename];
719 o_real_filename = o_filename;
721 playlist_Export( p_playlist,
722 [o_real_filename fileSystemRepresentation],
723 p_playlist->p_local_category, "export-m3u" );
725 else if( [o_save_accessory_popup indexOfSelectedItem] == 1 )
727 NSString * o_real_filename;
729 range.location = [o_filename length] - [@".xspf" length];
730 range.length = [@".xspf" length];
732 if( [o_filename compare:@".xspf" options: NSCaseInsensitiveSearch
733 range: range] != NSOrderedSame )
735 o_real_filename = [NSString stringWithFormat: @"%@.xspf", o_filename];
739 o_real_filename = o_filename;
741 playlist_Export( p_playlist,
742 [o_real_filename fileSystemRepresentation],
743 p_playlist->p_local_category, "export-xspf" );
747 NSString * o_real_filename;
749 range.location = [o_filename length] - [@".html" length];
750 range.length = [@".html" length];
752 if( [o_filename compare:@".html" options: NSCaseInsensitiveSearch
753 range: range] != NSOrderedSame )
755 o_real_filename = [NSString stringWithFormat: @"%@.html", o_filename];
759 o_real_filename = o_filename;
761 playlist_Export( p_playlist,
762 [o_real_filename fileSystemRepresentation],
763 p_playlist->p_local_category, "export-html" );
768 /* When called retrieves the selected outlineview row and plays that node or item */
769 - (IBAction)playItem:(id)sender
771 intf_thread_t * p_intf = VLCIntf;
772 playlist_t * p_playlist = pl_Get( p_intf );
774 playlist_item_t *p_item;
775 playlist_item_t *p_node = NULL;
777 p_item = [[o_outline_view itemAtRow:[o_outline_view selectedRow]] pointerValue];
782 if( p_item->i_children == -1 )
784 p_node = p_item->p_parent;
789 if( p_node->i_children > 0 && p_node->pp_children[0]->i_children == -1 )
791 p_item = p_node->pp_children[0];
798 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, pl_Locked, p_node, p_item );
803 - (IBAction)revealItemInFinder:(id)sender
805 playlist_item_t * p_item = [[o_outline_view itemAtRow:[o_outline_view selectedRow]] pointerValue];
806 NSMutableString * o_mrl = nil;
808 if(! p_item || !p_item->p_input )
811 char *psz_uri = decode_URI( input_item_GetURI( p_item->p_input ) );
813 o_mrl = [NSMutableString stringWithUTF8String: psz_uri];
815 /* perform some checks whether it is a file and if it is local at all... */
816 NSRange prefix_range = [o_mrl rangeOfString: @"file:"];
817 if( prefix_range.location != NSNotFound )
818 [o_mrl deleteCharactersInRange: prefix_range];
820 if( [o_mrl characterAtIndex:0] == '/' )
821 [[NSWorkspace sharedWorkspace] selectFile: o_mrl inFileViewerRootedAtPath: o_mrl];
824 /* When called retrieves the selected outlineview row and plays that node or item */
825 - (IBAction)preparseItem:(id)sender
828 NSIndexSet *o_selected_indexes;
829 intf_thread_t * p_intf = VLCIntf;
830 playlist_t * p_playlist = pl_Get( p_intf );
831 playlist_item_t *p_item = NULL;
833 o_selected_indexes = [o_outline_view selectedRowIndexes];
834 i_count = [o_selected_indexes count];
836 NSUInteger indexes[i_count];
837 [o_selected_indexes getIndexes:indexes maxCount:i_count inIndexRange:nil];
838 for (int i = 0; i < i_count; i++)
840 p_item = [[o_outline_view itemAtRow:indexes[i]] pointerValue];
841 [o_outline_view deselectRow: indexes[i]];
845 if( p_item->i_children == -1 )
846 playlist_PreparseEnqueue( p_playlist, p_item->p_input );
848 msg_Dbg( p_intf, "preparsing nodes not implemented" );
851 [self playlistUpdated];
854 - (IBAction)downloadCoverArt:(id)sender
857 NSIndexSet *o_selected_indexes;
858 intf_thread_t * p_intf = VLCIntf;
859 playlist_t * p_playlist = pl_Get( p_intf );
860 playlist_item_t *p_item = NULL;
862 o_selected_indexes = [o_outline_view selectedRowIndexes];
863 i_count = [o_selected_indexes count];
865 NSUInteger indexes[i_count];
866 [o_selected_indexes getIndexes:indexes maxCount:i_count inIndexRange:nil];
867 for (int i = 0; i < i_count; i++)
869 p_item = [[o_outline_view itemAtRow: indexes[i]] pointerValue];
870 [o_outline_view deselectRow: indexes[i]];
872 if( p_item && p_item->i_children == -1 )
873 playlist_AskForArtEnqueue( p_playlist, p_item->p_input );
875 [self playlistUpdated];
878 - (IBAction)servicesChange:(id)sender
880 NSMenuItem *o_mi = (NSMenuItem *)sender;
881 NSString *o_string = [o_mi representedObject];
882 playlist_t * p_playlist = pl_Get( VLCIntf );
883 if( !playlist_IsServicesDiscoveryLoaded( p_playlist, [o_string UTF8String] ) )
884 playlist_ServicesDiscoveryAdd( p_playlist, [o_string UTF8String] );
886 playlist_ServicesDiscoveryRemove( p_playlist, [o_string UTF8String] );
888 [o_mi setState: playlist_IsServicesDiscoveryLoaded( p_playlist,
889 [o_string UTF8String] ) ? YES : NO];
891 [self playlistUpdated];
895 - (IBAction)selectAll:(id)sender
897 [o_outline_view selectAll: nil];
900 - (IBAction)deleteItem:(id)sender
903 NSIndexSet *o_selected_indexes;
904 playlist_t * p_playlist;
905 intf_thread_t * p_intf = VLCIntf;
907 o_selected_indexes = [o_outline_view selectedRowIndexes];
908 i_count = [o_selected_indexes count];
910 p_playlist = pl_Get( p_intf );
912 NSUInteger indexes[i_count];
913 [o_selected_indexes getIndexes:indexes maxCount:i_count inIndexRange:nil];
914 for (int i = 0; i < i_count; i++)
916 id o_item = [o_outline_view itemAtRow: indexes[i]];
917 [o_outline_view deselectRow: indexes[i]];
920 playlist_item_t *p_item = [o_item pointerValue];
922 msg_Dbg( p_intf, "deleting item %i (of %i) with id \"%i\", pointerValue \"%p\" and %i children", i+1, i_count,
923 p_item->p_input->i_id, [o_item pointerValue], p_item->i_children +1 );
926 if( p_item->i_children != -1 )
927 //is a node and not an item
929 if( playlist_Status( p_playlist ) != PLAYLIST_STOPPED &&
930 [self isItem: playlist_CurrentPlayingItem( p_playlist ) inNode: ((playlist_item_t *)[o_item pointerValue])
931 checkItemExistence: NO locked:YES] == YES )
932 // if current item is in selected node and is playing then stop playlist
933 playlist_Control(p_playlist, PLAYLIST_STOP, pl_Locked );
935 playlist_NodeDelete( p_playlist, p_item, true, false );
938 playlist_DeleteFromInput( p_playlist, p_item->p_input, pl_Locked );
941 [o_outline_dict removeObjectForKey:[NSString stringWithFormat:@"%p", [o_item pointerValue]]];
945 [self playlistUpdated];
948 - (IBAction)sortNodeByName:(id)sender
950 [self sortNode: SORT_TITLE];
953 - (IBAction)sortNodeByAuthor:(id)sender
955 [self sortNode: SORT_ARTIST];
958 - (void)sortNode:(int)i_mode
960 playlist_t * p_playlist = pl_Get( VLCIntf );
961 playlist_item_t * p_item;
963 if( [o_outline_view selectedRow] > -1 )
965 p_item = [[o_outline_view itemAtRow: [o_outline_view selectedRow]] pointerValue];
968 /*If no item is selected, sort the whole playlist*/
970 p_item = p_playlist->p_root_category;
974 if( p_item->i_children > -1 ) // the item is a node
976 playlist_RecursiveNodeSort( p_playlist, p_item, i_mode, ORDER_NORMAL );
980 playlist_RecursiveNodeSort( p_playlist,
981 p_item->p_parent, i_mode, ORDER_NORMAL );
984 [self playlistUpdated];
987 - (input_item_t *)createItem:(NSDictionary *)o_one_item
989 intf_thread_t * p_intf = VLCIntf;
990 playlist_t * p_playlist = pl_Get( p_intf );
992 input_item_t *p_input;
993 BOOL b_rem = FALSE, b_dir = FALSE;
994 NSString *o_uri, *o_name;
999 o_uri = (NSString *)[o_one_item objectForKey: @"ITEM_URL"];
1000 o_name = (NSString *)[o_one_item objectForKey: @"ITEM_NAME"];
1001 o_options = (NSArray *)[o_one_item objectForKey: @"ITEM_OPTIONS"];
1003 /* Find the name for a disc entry (i know, can you believe the trouble?) */
1004 if( ( !o_name || [o_name isEqualToString:@""] ) && [o_uri rangeOfString: @"/dev/"].location != NSNotFound )
1007 struct statfs *mounts = NULL;
1009 i_count = getmntinfo (&mounts, MNT_NOWAIT);
1010 /* getmntinfo returns a pointer to static data. Do not free. */
1011 for( int i_index = 0 ; i_index < i_count; i_index++ )
1013 NSMutableString *o_temp, *o_temp2;
1014 o_temp = [NSMutableString stringWithString: o_uri];
1015 o_temp2 = [NSMutableString stringWithUTF8String: mounts[i_index].f_mntfromname];
1016 [o_temp replaceOccurrencesOfString: @"/dev/rdisk" withString: @"/dev/disk" options:NSLiteralSearch range:NSMakeRange(0, [o_temp length]) ];
1017 [o_temp2 replaceOccurrencesOfString: @"s0" withString: @"" options:NSLiteralSearch range:NSMakeRange(0, [o_temp2 length]) ];
1018 [o_temp2 replaceOccurrencesOfString: @"s1" withString: @"" options:NSLiteralSearch range:NSMakeRange(0, [o_temp2 length]) ];
1020 if( strstr( [o_temp fileSystemRepresentation], [o_temp2 fileSystemRepresentation] ) != NULL )
1022 o_name = [[NSFileManager defaultManager] displayNameAtPath: [NSString stringWithUTF8String:mounts[i_index].f_mntonname]];
1027 if( [[NSFileManager defaultManager] fileExistsAtPath:o_uri isDirectory:&b_dir] && b_dir &&
1028 [[NSWorkspace sharedWorkspace] getFileSystemInfoForPath: o_uri isRemovable: &b_rem
1029 isWritable:NULL isUnmountable:NULL description:NULL type:NULL] && b_rem )
1031 /* All of this is to make sure CD's play when you D&D them on VLC */
1032 /* Converts mountpoint to a /dev file */
1035 NSMutableString *o_temp;
1037 buf = (struct statfs *) malloc (sizeof(struct statfs));
1038 statfs( [o_uri fileSystemRepresentation], buf );
1039 psz_dev = strdup(buf->f_mntfromname);
1040 o_temp = [NSMutableString stringWithUTF8String: psz_dev ];
1041 [o_temp replaceOccurrencesOfString: @"/dev/disk" withString: @"/dev/rdisk" options:NSLiteralSearch range:NSMakeRange(0, [o_temp length]) ];
1042 [o_temp replaceOccurrencesOfString: @"s0" withString: @"" options:NSLiteralSearch range:NSMakeRange(0, [o_temp length]) ];
1043 [o_temp replaceOccurrencesOfString: @"s1" withString: @"" options:NSLiteralSearch range:NSMakeRange(0, [o_temp length]) ];
1047 p_input = input_item_New( [o_uri fileSystemRepresentation], o_name ? [o_name UTF8String] : NULL );
1053 NSUInteger count = [o_options count];
1054 for( NSUInteger i = 0; i < count; i++ )
1056 input_item_AddOption( p_input, [[o_options objectAtIndex:i] UTF8String],
1057 VLC_INPUT_OPTION_TRUSTED );
1061 /* Recent documents menu */
1062 o_true_file = [NSURL URLWithString: o_uri];
1063 if( o_true_file != nil && (BOOL)config_GetInt( p_playlist, "macosx-recentitems" ) == YES )
1065 [[NSDocumentController sharedDocumentController]
1066 noteNewRecentDocumentURL: o_true_file];
1071 - (void)appendArray:(NSArray*)o_array atPos:(int)i_position enqueue:(BOOL)b_enqueue
1073 playlist_t * p_playlist = pl_Get( VLCIntf );
1074 NSUInteger count = [o_array count];
1077 for( NSUInteger i_item = 0; i_item < count; i_item++ )
1079 input_item_t *p_input;
1080 NSDictionary *o_one_item;
1083 o_one_item = [o_array objectAtIndex: i_item];
1084 p_input = [self createItem: o_one_item];
1091 /* FIXME: playlist_AddInput() can fail */
1093 playlist_AddInput( p_playlist, p_input, PLAYLIST_INSERT, i_position == -1 ? PLAYLIST_END : i_position + i_item, true,
1096 /* if( i_item == 0 && !b_enqueue )
1098 playlist_item_t *p_item = NULL;
1099 playlist_item_t *p_node = NULL;
1100 p_item = playlist_ItemGetByInput( p_playlist, p_input );
1103 if( p_item->i_children == -1 )
1104 p_node = p_item->p_parent;
1108 if( p_node->i_children > 0 && p_node->pp_children[0]->i_children == -1 )
1109 p_item = p_node->pp_children[0];
1113 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, pl_Locked, p_node, p_item );
1116 vlc_gc_decref( p_input );
1119 [o_outline_view selectRowIndexes:[NSIndexSet indexSetWithIndex:i_position] byExtendingSelection:YES];
1120 [self playItem:nil];
1122 [self playlistUpdated];
1125 - (void)appendNodeArray:(NSArray*)o_array inNode:(playlist_item_t *)p_node atPos:(int)i_position enqueue:(BOOL)b_enqueue
1127 playlist_t * p_playlist = pl_Get( VLCIntf );
1128 NSUInteger count = [o_array count];
1130 for( NSUInteger i_item = 0; i_item < count; i_item++ )
1132 input_item_t *p_input;
1133 NSDictionary *o_one_item;
1136 o_one_item = [o_array objectAtIndex: i_item];
1137 p_input = [self createItem: o_one_item];
1139 if( !p_input ) continue;
1143 playlist_NodeAddInput( p_playlist, p_input, p_node,
1146 PLAYLIST_END : i_position + i_item,
1150 if( i_item == 0 && !b_enqueue )
1152 playlist_item_t *p_item;
1153 p_item = playlist_ItemGetByInput( p_playlist, p_input );
1154 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, pl_Locked, p_node, p_item );
1157 vlc_gc_decref( p_input );
1159 [self playlistUpdated];
1162 - (NSMutableArray *)subSearchItem:(playlist_item_t *)p_item
1164 playlist_t *p_playlist = pl_Get( VLCIntf );
1165 playlist_item_t *p_selected_item;
1168 i_selected_row = [o_outline_view selectedRow];
1169 if (i_selected_row < 0)
1172 p_selected_item = (playlist_item_t *)[[o_outline_view itemAtRow: i_selected_row] pointerValue];
1174 for( NSUInteger i_current = 0; i_current < p_item->i_children ; i_current++ )
1177 NSString *o_current_name, *o_current_author;
1180 o_current_name = [NSString stringWithUTF8String:
1181 p_item->pp_children[i_current]->p_input->psz_name];
1182 psz_temp = input_item_GetInfo( p_item->p_input ,
1183 _("Meta-information"),_("Artist") );
1184 o_current_author = [NSString stringWithUTF8String: psz_temp];
1188 if( p_selected_item == p_item->pp_children[i_current] &&
1189 b_selected_item_met == NO )
1191 b_selected_item_met = YES;
1193 else if( p_selected_item == p_item->pp_children[i_current] &&
1194 b_selected_item_met == YES )
1198 else if( b_selected_item_met == YES &&
1199 ( [o_current_name rangeOfString:[o_search_field
1200 stringValue] options:NSCaseInsensitiveSearch].length ||
1201 [o_current_author rangeOfString:[o_search_field
1202 stringValue] options:NSCaseInsensitiveSearch].length ) )
1204 /*Adds the parent items in the result array as well, so that we can
1206 return [NSMutableArray arrayWithObject: [NSValue
1207 valueWithPointer: p_item->pp_children[i_current]]];
1209 if( p_item->pp_children[i_current]->i_children > 0 )
1211 id o_result = [self subSearchItem:
1212 p_item->pp_children[i_current]];
1213 if( o_result != NULL )
1215 [o_result insertObject: [NSValue valueWithPointer:
1216 p_item->pp_children[i_current]] atIndex:0];
1224 - (IBAction)searchItem:(id)sender
1226 playlist_t * p_playlist = pl_Get( VLCIntf );
1231 b_selected_item_met = NO;
1233 /*First, only search after the selected item:*
1234 *(b_selected_item_met = NO) */
1235 o_result = [self subSearchItem:p_playlist->p_root_category];
1236 if( o_result == NULL )
1238 /* If the first search failed, search again from the beginning */
1239 o_result = [self subSearchItem:p_playlist->p_root_category];
1241 if( o_result != NULL )
1244 if( [[o_result objectAtIndex: 0] pointerValue] == p_playlist->p_local_category )
1248 NSUInteger count = [o_result count];
1250 for( NSUInteger i = i_start ; i < count - 1 ; i++ )
1252 [o_outline_view expandItem: [o_outline_dict objectForKey:
1253 [NSString stringWithFormat: @"%p",
1254 [[o_result objectAtIndex: i] pointerValue]]]];
1256 i_row = [o_outline_view rowForItem: [o_outline_dict objectForKey:
1257 [NSString stringWithFormat: @"%p",
1258 [[o_result objectAtIndex: count - 1 ]
1263 [o_outline_view selectRowIndexes:[NSIndexSet indexSetWithIndex:i_row] byExtendingSelection:NO];
1264 [o_outline_view scrollRowToVisible: i_row];
1268 - (IBAction)recursiveExpandNode:(id)sender
1270 id o_item = [o_outline_view itemAtRow: [o_outline_view selectedRow]];
1271 playlist_item_t *p_item = (playlist_item_t *)[o_item pointerValue];
1273 if( ![[o_outline_view dataSource] outlineView: o_outline_view
1274 isItemExpandable: o_item] )
1276 o_item = [o_outline_dict objectForKey: [NSString stringWithFormat: @"%p", p_item->p_parent]];
1279 /* We need to collapse the node first, since OSX refuses to recursively
1280 expand an already expanded node, even if children nodes are collapsed. */
1281 [o_outline_view collapseItem: o_item collapseChildren: YES];
1282 [o_outline_view expandItem: o_item expandChildren: YES];
1285 - (NSMenu *)menuForEvent:(NSEvent *)o_event
1291 pt = [o_outline_view convertPoint: [o_event locationInWindow]
1293 int row = [o_outline_view rowAtPoint:pt];
1295 [o_outline_view selectRowIndexes:[NSIndexSet indexSetWithIndex:row] byExtendingSelection:NO];
1297 b_item_sel = ( row != -1 && [o_outline_view selectedRow] != -1 );
1298 b_rows = [o_outline_view numberOfRows] != 0;
1300 [o_mi_play setEnabled: b_item_sel];
1301 [o_mi_delete setEnabled: b_item_sel];
1302 [o_mi_selectall setEnabled: b_rows];
1303 [o_mi_info setEnabled: b_item_sel];
1304 [o_mi_preparse setEnabled: b_item_sel];
1305 [o_mi_recursive_expand setEnabled: b_item_sel];
1306 [o_mi_sort_name setEnabled: b_item_sel];
1307 [o_mi_sort_author setEnabled: b_item_sel];
1309 return( o_ctx_menu );
1312 - (void)outlineView: (NSOutlineView *)o_tv
1313 didClickTableColumn:(NSTableColumn *)o_tc
1315 int i_mode, i_type = 0;
1316 intf_thread_t *p_intf = VLCIntf;
1318 playlist_t *p_playlist = pl_Get( p_intf );
1320 /* Check whether the selected table column header corresponds to a
1321 sortable table column*/
1322 if( !( o_tc == o_tc_name || o_tc == o_tc_author ) )
1327 if( o_tc_sortColumn == o_tc )
1329 b_isSortDescending = !b_isSortDescending;
1333 b_isSortDescending = false;
1336 if( o_tc == o_tc_name )
1338 i_mode = SORT_TITLE;
1340 else if( o_tc == o_tc_author )
1342 i_mode = SORT_ARTIST;
1345 if( b_isSortDescending )
1347 i_type = ORDER_REVERSE;
1351 i_type = ORDER_NORMAL;
1355 playlist_RecursiveNodeSort( p_playlist, p_playlist->p_root_category, i_mode, i_type );
1358 [self playlistUpdated];
1360 o_tc_sortColumn = o_tc;
1361 [o_outline_view setHighlightedTableColumn:o_tc];
1363 if( b_isSortDescending )
1365 [o_outline_view setIndicatorImage:o_descendingSortingImage
1366 inTableColumn:o_tc];
1370 [o_outline_view setIndicatorImage:o_ascendingSortingImage
1371 inTableColumn:o_tc];
1376 - (void)outlineView:(NSOutlineView *)outlineView
1377 willDisplayCell:(id)cell
1378 forTableColumn:(NSTableColumn *)tableColumn
1381 playlist_t *p_playlist = pl_Get( VLCIntf );
1386 o_playing_item = [o_outline_dict objectForKey: [NSString stringWithFormat:@"%p", playlist_CurrentPlayingItem( p_playlist )]];
1389 if( [self isItem: [o_playing_item pointerValue] inNode:
1390 [item pointerValue] checkItemExistence: YES]
1391 || [o_playing_item isEqual: item] )
1393 [cell setFont: [[NSFontManager sharedFontManager] convertFont:[cell font] toHaveTrait:NSBoldFontMask]];
1397 [cell setFont: [[NSFontManager sharedFontManager] convertFont:[cell font] toNotHaveTrait:NSBoldFontMask]];
1403 playlist_t *p_playlist = pl_Get( VLCIntf );
1408 o_playing_item = [o_outline_dict objectForKey: [NSString stringWithFormat:@"%p", playlist_CurrentPlayingItem( p_playlist )]];
1411 return o_playing_item;
1415 @implementation VLCPlaylist (NSOutlineViewDataSource)
1417 - (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item
1419 id o_value = [super outlineView: outlineView child: index ofItem: item];
1421 [o_outline_dict setObject:o_value forKey:[NSString stringWithFormat:@"%p", [o_value pointerValue]]];
1425 /* Required for drag & drop and reordering */
1426 - (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pboard
1428 playlist_t *p_playlist = pl_Get( VLCIntf );
1430 /* First remove the items that were moved during the last drag & drop
1432 [o_items_array removeAllObjects];
1433 [o_nodes_array removeAllObjects];
1435 NSUInteger itemCount = [items count];
1437 for( NSUInteger i = 0 ; i < itemCount ; i++ )
1439 id o_item = [items objectAtIndex: i];
1441 /* Refuse to move items that are not in the General Node
1442 (Service Discovery) */
1443 if( (![self isItem: [o_item pointerValue] inNode: p_playlist->p_local_category checkItemExistence: NO] &&
1444 var_CreateGetBool( p_playlist, "media-library" ) && ![self isItem: [o_item pointerValue] inNode: p_playlist->p_ml_category checkItemExistence: NO]) ||
1445 [o_item pointerValue] == p_playlist->p_local_category ||
1446 [o_item pointerValue] == p_playlist->p_ml_category )
1450 /* Fill the items and nodes to move in 2 different arrays */
1451 if( ((playlist_item_t *)[o_item pointerValue])->i_children > 0 )
1452 [o_nodes_array addObject: o_item];
1454 [o_items_array addObject: o_item];
1457 /* Now we need to check if there are selected items that are in already
1458 selected nodes. In that case, we only want to move the nodes */
1459 [self removeItemsFrom: o_nodes_array ifChildrenOf: o_nodes_array];
1460 [self removeItemsFrom: o_items_array ifChildrenOf: o_nodes_array];
1462 /* We add the "VLCPlaylistItemPboardType" type to be able to recognize
1463 a Drop operation coming from the playlist. */
1465 [pboard declareTypes: [NSArray arrayWithObjects:
1466 @"VLCPlaylistItemPboardType", nil] owner: self];
1467 [pboard setData:[NSData data] forType:@"VLCPlaylistItemPboardType"];
1472 - (NSDragOperation)outlineView:(NSOutlineView *)outlineView validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(NSInteger)index
1474 playlist_t *p_playlist = pl_Get( VLCIntf );
1475 NSPasteboard *o_pasteboard = [info draggingPasteboard];
1477 if( !p_playlist ) return NSDragOperationNone;
1479 /* Dropping ON items is not allowed if item is not a node */
1482 if( index == NSOutlineViewDropOnItemIndex &&
1483 ((playlist_item_t *)[item pointerValue])->i_children == -1 )
1485 return NSDragOperationNone;
1489 /* Don't allow on drop on playlist root element's child */
1490 if( !item && index != NSOutlineViewDropOnItemIndex)
1492 return NSDragOperationNone;
1495 /* We refuse to drop an item in anything else than a child of the General
1496 Node. We still accept items that would be root nodes of the outlineview
1497 however, to allow drop in an empty playlist. */
1498 if( !( ([self isItem: [item pointerValue] inNode: p_playlist->p_local_category checkItemExistence: NO] ||
1499 ( var_CreateGetBool( p_playlist, "media-library" ) && [self isItem: [item pointerValue] inNode: p_playlist->p_ml_category checkItemExistence: NO] ) ) || item == nil ) )
1501 return NSDragOperationNone;
1504 /* Drop from the Playlist */
1505 if( [[o_pasteboard types] containsObject: @"VLCPlaylistItemPboardType"] )
1507 NSUInteger count = [o_nodes_array count];
1508 for( NSUInteger i = 0 ; i < count ; i++ )
1510 /* We refuse to Drop in a child of an item we are moving */
1511 if( [self isItem: [item pointerValue] inNode:
1512 [[o_nodes_array objectAtIndex: i] pointerValue]
1513 checkItemExistence: NO] )
1515 return NSDragOperationNone;
1518 return NSDragOperationMove;
1521 /* Drop from the Finder */
1522 else if( [[o_pasteboard types] containsObject: NSFilenamesPboardType] )
1524 return NSDragOperationGeneric;
1526 return NSDragOperationNone;
1529 - (BOOL)outlineView:(NSOutlineView *)outlineView acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(NSInteger)index
1531 playlist_t * p_playlist = pl_Get( VLCIntf );
1532 NSPasteboard *o_pasteboard = [info draggingPasteboard];
1534 /* Drag & Drop inside the playlist */
1535 if( [[o_pasteboard types] containsObject: @"VLCPlaylistItemPboardType"] )
1537 int i_row, i_removed_from_node = 0;
1538 playlist_item_t *p_new_parent, *p_item = NULL;
1539 NSArray *o_all_items = [o_nodes_array arrayByAddingObjectsFromArray:
1541 /* If the item is to be dropped as root item of the outline, make it a
1542 child of the General node.
1543 Else, choose the proposed parent as parent. */
1544 if( item == nil ) p_new_parent = p_playlist->p_local_category;
1545 else p_new_parent = [item pointerValue];
1547 /* Make sure the proposed parent is a node.
1548 (This should never be true) */
1549 if( p_new_parent->i_children < 0 )
1554 NSUInteger count = [o_all_items count];
1555 for( NSUInteger i = 0; i < count; i++ )
1557 playlist_item_t *p_old_parent = NULL;
1558 int i_old_index = 0;
1560 p_item = [[o_all_items objectAtIndex:i] pointerValue];
1561 p_old_parent = p_item->p_parent;
1564 /* We may need the old index later */
1565 if( p_new_parent == p_old_parent )
1567 for( NSInteger j = 0; j < p_old_parent->i_children; j++ )
1569 if( p_old_parent->pp_children[j] == p_item )
1578 // Actually detach the item from the old position
1579 if( playlist_NodeRemoveItem( p_playlist, p_item, p_old_parent ) ==
1583 /* Calculate the new index */
1586 /* If we move the item in the same node, we need to take into
1587 account that one item will be deleted */
1590 if ((p_new_parent == p_old_parent && i_old_index < index + (int)i) )
1592 i_removed_from_node++;
1594 i_new_index = index + i - i_removed_from_node;
1596 // Reattach the item to the new position
1597 playlist_NodeInsert( p_playlist, p_item, p_new_parent, i_new_index );
1601 [self playlistUpdated];
1602 i_row = [o_outline_view rowForItem:[o_outline_dict objectForKey:[NSString stringWithFormat: @"%p", [[o_all_items objectAtIndex: 0] pointerValue]]]];
1606 i_row = [o_outline_view rowForItem:[o_outline_dict objectForKey:[NSString stringWithFormat: @"%p", p_new_parent]]];
1609 [o_outline_view deselectAll: self];
1610 [o_outline_view selectRowIndexes:[NSIndexSet indexSetWithIndex:i_row] byExtendingSelection:NO];
1611 [o_outline_view scrollRowToVisible: i_row];
1616 else if( [[o_pasteboard types] containsObject: NSFilenamesPboardType] )
1618 playlist_item_t *p_node = [item pointerValue];
1620 NSArray *o_values = [[o_pasteboard propertyListForType: NSFilenamesPboardType]
1621 sortedArrayUsingSelector: @selector(caseInsensitiveCompare:)];
1622 NSUInteger count = [o_values count];
1623 NSMutableArray *o_array = [NSMutableArray arrayWithCapacity:count];
1625 for( NSUInteger i = 0; i < count; i++)
1627 NSDictionary *o_dic;
1628 char *psz_uri = make_URI([[o_values objectAtIndex:i] UTF8String], NULL);
1632 o_dic = [NSDictionary dictionaryWithObject:[NSString stringWithCString:psz_uri encoding:NSUTF8StringEncoding] forKey:@"ITEM_URL"];
1636 [o_array addObject: o_dic];
1641 [self appendArray:o_array atPos:index enqueue: YES];
1645 assert( p_node->i_children != -1 );
1646 [self appendNodeArray:o_array inNode: p_node atPos:index enqueue:YES];