1 /*****************************************************************************
2 * playlist.m: MacOS X interface module
3 *****************************************************************************
4 * Copyright (C) 2002-2006 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 * create toggle buttons for the shuffle, repeat one, repeat all functions.
29 * reimplement enable/disable item
30 * create a new 'tool' button (see the gear button in the Finder window) for 'actions'
31 (adding service discovery, other views, new node/playlist, save node/playlist) stuff like that
35 /*****************************************************************************
37 *****************************************************************************/
38 #include <stdlib.h> /* malloc(), free() */
39 #include <sys/param.h> /* for MAXPATHLEN */
42 #include <sys/mount.h>
48 #import "playlistinfo.h"
53 #import <vlc_interaction.h>
55 /*****************************************************************************
56 * VLCPlaylistView implementation
57 *****************************************************************************/
58 @implementation VLCPlaylistView
60 - (NSMenu *)menuForEvent:(NSEvent *)o_event
62 return( [[self delegate] menuForEvent: o_event] );
65 - (void)keyDown:(NSEvent *)o_event
69 if( [[o_event characters] length] )
71 key = [[o_event characters] characterAtIndex: 0];
76 case NSDeleteCharacter:
77 case NSDeleteFunctionKey:
78 case NSDeleteCharFunctionKey:
79 case NSBackspaceCharacter:
80 [[self delegate] deleteItem:self];
83 case NSEnterCharacter:
84 case NSCarriageReturnCharacter:
85 [(VLCPlaylist *)[[VLCMain sharedInstance] getPlaylist]
90 [super keyDown: o_event];
98 /*****************************************************************************
99 * VLCPlaylistCommon implementation
101 * This class the superclass of the VLCPlaylist and VLCPlaylistWizard.
102 * It contains the common methods and elements of these 2 entities.
103 *****************************************************************************/
104 @implementation VLCPlaylistCommon
111 o_outline_dict = [[NSMutableDictionary alloc] init];
117 playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
119 [o_outline_view setTarget: self];
120 [o_outline_view setDelegate: self];
121 [o_outline_view setDataSource: self];
123 vlc_object_release( p_playlist );
129 [[o_tc_name headerCell] setStringValue:_NS("Name")];
130 [[o_tc_author headerCell] setStringValue:_NS("Author")];
131 [[o_tc_duration headerCell] setStringValue:_NS("Duration")];
134 - (NSOutlineView *)outlineView
136 return o_outline_view;
139 - (playlist_item_t *)selectedPlaylistItem
141 return [[o_outline_view itemAtRow: [o_outline_view selectedRow]]
147 @implementation VLCPlaylistCommon (NSOutlineViewDataSource)
149 /* return the number of children for Obj-C pointer item */ /* DONE */
150 - (int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
153 playlist_item_t *p_item = NULL;
154 playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
156 if( p_playlist == NULL )
158 if( outlineView != o_outline_view )
160 vlc_object_release( p_playlist );
167 p_item = p_playlist->p_root_category;
171 p_item = (playlist_item_t *)[item pointerValue];
174 i_return = p_item->i_children;
175 vlc_object_release( p_playlist );
179 NSLog( @"%d children for %s", i_return, p_item->p_input->psz_name );
183 /* return the child at index for the Obj-C pointer item */ /* DONE */
184 - (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item
186 playlist_item_t *p_return = NULL, *p_item = NULL;
188 playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
191 if( p_playlist == NULL )
197 p_item = p_playlist->p_root_category;
201 p_item = (playlist_item_t *)[item pointerValue];
203 if( p_item && index < p_item->i_children && index >= 0 )
204 p_return = p_item->pp_children[index];
206 vlc_object_release( p_playlist );
208 o_value = [o_outline_dict objectForKey:[NSString stringWithFormat: @"%p", p_return]];
209 NSLog( @"%s", p_return->p_input->psz_name);
212 o_value = [[NSValue valueWithPointer: p_return] retain];
213 NSLog( @"error missing value" );
218 /* is the item expandable */
219 - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item
222 playlist_t *p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
224 if( p_playlist == NULL )
230 if( p_playlist->p_root_category )
232 i_return = p_playlist->p_root_category->i_children;
237 playlist_item_t *p_item = (playlist_item_t *)[item pointerValue];
239 i_return = p_item->i_children;
241 vlc_object_release( p_playlist );
243 NSLog( @"expandable" );
250 /* retrieve the string values for the cells */
251 - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)o_tc byItem:(id)item
254 intf_thread_t *p_intf = VLCIntf;
255 playlist_t *p_playlist;
256 playlist_item_t *p_item;
258 if( item == nil || ![item isKindOfClass: [NSValue class]] ) return( @"error" );
260 /* Check to see if the playlist is present */
261 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
262 if( p_playlist == NULL ) return( @"error");
263 vlc_object_release( p_playlist);
265 p_item = (playlist_item_t *)[item pointerValue];
270 //NSLog( @"values for %p", p_item );
272 if( [[o_tc identifier] isEqualToString:@"1"] )
274 o_value = [NSString stringWithUTF8String:
275 p_item->p_input->psz_name];
276 if( o_value == NULL )
277 o_value = [NSString stringWithCString:
278 p_item->p_input->psz_name];
280 else if( [[o_tc identifier] isEqualToString:@"2"] && p_item->p_input->p_meta &&
281 p_item->p_input->p_meta->psz_artist && *p_item->p_input->p_meta->psz_artist )
283 o_value = [NSString stringWithUTF8String:
284 p_item->p_input->p_meta->psz_artist];
285 if( o_value == NULL )
286 o_value = [NSString stringWithCString:
287 p_item->p_input->p_meta->psz_artist];
289 else if( [[o_tc identifier] isEqualToString:@"3"] )
291 char psz_duration[MSTRTIME_MAX_SIZE];
292 mtime_t dur = p_item->p_input->i_duration;
295 secstotimestr( psz_duration, dur/1000000 );
296 o_value = [NSString stringWithUTF8String: psz_duration];
300 o_value = @"-:--:--";
309 /*****************************************************************************
310 * VLCPlaylistWizard implementation
311 *****************************************************************************/
312 @implementation VLCPlaylistWizard
314 - (IBAction)reloadOutlineView
316 /* Only reload the outlineview if the wizard window is open since this can
317 be quite long on big playlists */
318 if( [[o_outline_view window] isVisible] )
320 [o_outline_view reloadData];
326 /*****************************************************************************
327 * VLCPlaylist implementation
328 *****************************************************************************/
329 @implementation VLCPlaylist
336 o_nodes_array = [[NSMutableArray alloc] init];
337 o_items_array = [[NSMutableArray alloc] init];
344 playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
346 vlc_list_t *p_list = vlc_list_find( p_playlist, VLC_OBJECT_MODULE,
351 [super awakeFromNib];
353 [o_outline_view setDoubleAction: @selector(playItem:)];
355 [o_outline_view registerForDraggedTypes:
356 [NSArray arrayWithObjects: NSFilenamesPboardType,
357 @"VLCPlaylistItemPboardType", nil]];
358 [o_outline_view setIntercellSpacing: NSMakeSize (0.0, 1.0)];
360 /* We need to check whether _defaultTableHeaderSortImage exists, since it
361 belongs to an Apple hidden private API, and then can "disapear" at any time*/
363 if( [[NSOutlineView class] respondsToSelector:@selector(_defaultTableHeaderSortImage)] )
365 o_ascendingSortingImage = [[NSOutlineView class] _defaultTableHeaderSortImage];
369 o_ascendingSortingImage = nil;
372 if( [[NSOutlineView class] respondsToSelector:@selector(_defaultTableHeaderReverseSortImage)] )
374 o_descendingSortingImage = [[NSOutlineView class] _defaultTableHeaderReverseSortImage];
378 o_descendingSortingImage = nil;
381 o_tc_sortColumn = nil;
383 for( i_index = 0; i_index < p_list->i_count; i_index++ )
386 module_t * p_parser = (module_t *)p_list->p_values[i_index].p_object ;
388 if( !strcmp( p_parser->psz_capability, "services_discovery" ) )
390 /* create the menu entries used in the playlist menu */
391 o_lmi = [[o_mi_services submenu] addItemWithTitle:
392 [NSString stringWithUTF8String:
393 p_parser->psz_longname ? p_parser->psz_longname :
394 ( p_parser->psz_shortname ? p_parser->psz_shortname:
395 p_parser->psz_object_name)]
396 action: @selector(servicesChange:)
398 [o_lmi setTarget: self];
399 [o_lmi setRepresentedObject:
400 [NSString stringWithCString: p_parser->psz_object_name]];
401 if( playlist_IsServicesDiscoveryLoaded( p_playlist,
402 p_parser->psz_object_name ) )
403 [o_lmi setState: NSOnState];
405 /* create the menu entries for the main menu */
406 o_lmi = [[o_mm_mi_services submenu] addItemWithTitle:
407 [NSString stringWithUTF8String:
408 p_parser->psz_longname ? p_parser->psz_longname :
409 ( p_parser->psz_shortname ? p_parser->psz_shortname:
410 p_parser->psz_object_name)]
411 action: @selector(servicesChange:)
413 [o_lmi setTarget: self];
414 [o_lmi setRepresentedObject:
415 [NSString stringWithCString: p_parser->psz_object_name]];
416 if( playlist_IsServicesDiscoveryLoaded( p_playlist,
417 p_parser->psz_object_name ) )
418 [o_lmi setState: NSOnState];
421 vlc_list_release( p_list );
422 vlc_object_release( p_playlist );
424 //[self playlistUpdated];
427 - (void)searchfieldChanged:(NSNotification *)o_notification
429 [o_search_field setStringValue:[[o_notification object] stringValue]];
436 [o_mi_save_playlist setTitle: _NS("Save Playlist...")];
437 [o_mi_play setTitle: _NS("Play")];
438 [o_mi_delete setTitle: _NS("Delete")];
439 [o_mi_recursive_expand setTitle: _NS("Expand Node")];
440 [o_mi_selectall setTitle: _NS("Select All")];
441 [o_mi_info setTitle: _NS("Information")];
442 [o_mi_preparse setTitle: _NS("Get Stream Information")];
443 [o_mi_sort_name setTitle: _NS("Sort Node by Name")];
444 [o_mi_sort_author setTitle: _NS("Sort Node by Author")];
445 [o_mi_services setTitle: _NS("Services discovery")];
446 [o_status_field setStringValue: [NSString stringWithFormat:
447 _NS("No items in the playlist")]];
449 [o_random_ckb setTitle: _NS("Random")];
451 [o_search_button setTitle: _NS("Search")];
453 [o_search_field setToolTip: _NS("Search in Playlist")];
454 [[o_loop_popup itemAtIndex:0] setTitle: _NS("Standard Play")];
455 [[o_loop_popup itemAtIndex:1] setTitle: _NS("Repeat One")];
456 [[o_loop_popup itemAtIndex:2] setTitle: _NS("Repeat All")];
457 [o_mi_addNode setTitle: _NS("Add Folder to Playlist")];
459 [o_save_accessory_text setStringValue: _NS("File Format:")];
460 [[o_save_accessory_popup itemAtIndex:0] setTitle: _NS("Extended M3U")];
461 [[o_save_accessory_popup itemAtIndex:1] setTitle: _NS("XML Shareable Playlist Format (XSPF)")];
464 - (void)playlistUpdated
468 /* Clear indications of any existing column sorting */
469 for( 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 = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
488 if( p_playlist->i_size >= 2 )
490 [o_status_field setStringValue: [NSString stringWithFormat:
491 _NS("%i items in the playlist"), p_playlist->i_size]];
495 if( p_playlist->i_size == 0 )
497 [o_status_field setStringValue: _NS("No items in the playlist")];
501 [o_status_field setStringValue: _NS("1 item in the playlist")];
504 vlc_object_release( p_playlist );
507 - (void)playModeUpdated
509 playlist_t *p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
511 vlc_value_t val, val2;
513 if( p_playlist == NULL )
518 var_Get( p_playlist, "loop", &val2 );
519 var_Get( p_playlist, "repeat", &val );
520 if( val.b_bool == VLC_TRUE )
522 [o_loop_popup selectItemAtIndex: 1];
524 else if( val2.b_bool == VLC_TRUE )
526 [o_loop_popup selectItemAtIndex: 2];
530 [o_loop_popup selectItemAtIndex: 0];
533 var_Get( p_playlist, "random", &val );
534 [o_random_ckb setState: val.b_bool];
536 vlc_object_release( p_playlist );
539 - (void)updateRowSelection
544 playlist_t *p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
546 playlist_item_t *p_item, *p_temp_item;
547 NSMutableArray *o_array = [NSMutableArray array];
549 if( p_playlist == NULL )
552 p_item = p_playlist->status.p_item;
555 vlc_object_release(p_playlist);
559 p_temp_item = p_item;
560 while( p_temp_item->p_parent )
562 [o_array insertObject: [NSValue valueWithPointer: p_temp_item] atIndex: 0];
563 p_temp_item = p_temp_item->p_parent;
564 /*for (i = 0 ; i < p_temp_item->i_parents ; i++)
566 if( p_temp_item->pp_parents[i]->i_view == i_current_view )
568 p_temp_item = p_temp_item->pp_parents[i]->p_parent;
574 for( j = 0; j < [o_array count] - 1; j++ )
577 if( ( o_item = [o_outline_dict objectForKey:
578 [NSString stringWithFormat: @"%p",
579 [[o_array objectAtIndex:j] pointerValue]]] ) != nil )
581 msg_Err( p_playlist, "o_item: %p", o_item );
582 [o_outline_view expandItem: o_item];
587 i_row = [o_outline_view rowForItem:[o_outline_dict
588 objectForKey:[NSString stringWithFormat: @"%p", p_item]]];
590 [o_outline_view selectRow: i_row byExtendingSelection: NO];
591 [o_outline_view scrollRowToVisible: i_row];
593 vlc_object_release(p_playlist);
595 /* update our info-panel to reflect the new item */
596 [[[VLCMain sharedInstance] getInfo] updatePanel];
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). */
603 - (BOOL)isItem: (playlist_item_t *)p_item
604 inNode: (playlist_item_t *)p_node
605 checkItemExistence:(BOOL)b_check
608 playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
610 playlist_item_t *p_temp_item = p_item;
612 if( p_playlist == NULL )
617 if( p_node == p_item )
619 vlc_object_release(p_playlist);
623 if( p_node->i_children < 1)
625 vlc_object_release(p_playlist);
632 vlc_mutex_lock( &p_playlist->object_lock );
636 /* Since outlineView: willDisplayCell:... may call this function with
637 p_items that don't exist anymore, first check if the item is still
638 in the playlist. Any cleaner solution welcomed. */
639 for( i = 0; i < p_playlist->i_all_size; i++ )
641 if( p_playlist->pp_all_items[i] == p_item ) break;
642 else if ( i == p_playlist->i_all_size - 1 )
644 vlc_object_release( p_playlist );
645 vlc_mutex_unlock( &p_playlist->object_lock );
653 p_temp_item = p_temp_item->p_parent;
654 if( p_temp_item == p_node )
656 vlc_mutex_unlock( &p_playlist->object_lock );
657 vlc_object_release( p_playlist );
661 vlc_mutex_unlock( &p_playlist->object_lock );
664 vlc_object_release( p_playlist );
668 /* This method is usefull for instance to remove the selected children of an
669 already selected node */
670 - (void)removeItemsFrom:(id)o_items ifChildrenOf:(id)o_nodes
673 for( i = 0 ; i < [o_items count] ; i++ )
675 for ( j = 0 ; j < [o_nodes count] ; j++ )
677 if( o_items == o_nodes)
679 if( j == i ) continue;
681 if( [self isItem: [[o_items objectAtIndex:i] pointerValue]
682 inNode: [[o_nodes objectAtIndex:j] pointerValue]
683 checkItemExistence: NO] )
685 [o_items removeObjectAtIndex:i];
686 /* We need to execute the next iteration with the same index
687 since the current item has been deleted */
696 - (IBAction)savePlaylist:(id)sender
698 intf_thread_t * p_intf = VLCIntf;
699 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
702 NSSavePanel *o_save_panel = [NSSavePanel savePanel];
703 NSString * o_name = [NSString stringWithFormat: @"%@", _NS("Untitled")];
705 //[o_save_panel setAllowedFileTypes: [NSArray arrayWithObjects: @"m3u", @"xpf", nil] ];
706 [o_save_panel setTitle: _NS("Save Playlist")];
707 [o_save_panel setPrompt: _NS("Save")];
708 [o_save_panel setAccessoryView: o_save_accessory_view];
710 if( [o_save_panel runModalForDirectory: nil
711 file: o_name] == NSOKButton )
713 NSString *o_filename = [o_save_panel filename];
715 if( [o_save_accessory_popup indexOfSelectedItem] == 1 )
717 NSString * o_real_filename;
719 range.location = [o_filename length] - [@".xspf" length];
720 range.length = [@".xspf" length];
722 if( [o_filename compare:@".xspf" options: NSCaseInsensitiveSearch
723 range: range] != NSOrderedSame )
725 o_real_filename = [NSString stringWithFormat: @"%@.xspf", o_filename];
729 o_real_filename = o_filename;
731 playlist_Export( p_playlist,
732 [o_real_filename fileSystemRepresentation],
733 p_playlist->p_local_category, "export-xspf" );
737 NSString * o_real_filename;
739 range.location = [o_filename length] - [@".m3u" length];
740 range.length = [@".m3u" length];
742 if( [o_filename compare:@".m3u" options: NSCaseInsensitiveSearch
743 range: range] != NSOrderedSame )
745 o_real_filename = [NSString stringWithFormat: @"%@.m3u", o_filename];
749 o_real_filename = o_filename;
751 playlist_Export( p_playlist,
752 [o_real_filename fileSystemRepresentation],
753 p_playlist->p_local_category, "export-m3u" );
756 vlc_object_release( p_playlist );
759 /* When called retrieves the selected outlineview row and plays that node or item */
760 - (IBAction)playItem:(id)sender
762 intf_thread_t * p_intf = VLCIntf;
763 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
766 if( p_playlist != NULL )
768 playlist_item_t *p_item;
769 playlist_item_t *p_node = NULL;
771 p_item = [[o_outline_view itemAtRow:[o_outline_view selectedRow]] pointerValue];
775 if( p_item->i_children == -1 )
777 p_node = p_item->p_parent;
783 if( p_node->i_children > 0 && p_node->pp_children[0]->i_children == -1 )
785 p_item = p_node->pp_children[0];
792 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, 0, p_node, p_item );
794 vlc_object_release( p_playlist );
798 /* When called retrieves the selected outlineview row and plays that node or item */
799 - (IBAction)preparseItem:(id)sender
802 NSMutableArray *o_to_preparse;
803 intf_thread_t * p_intf = VLCIntf;
804 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
807 o_to_preparse = [NSMutableArray arrayWithArray:[[o_outline_view selectedRowEnumerator] allObjects]];
808 i_count = [o_to_preparse count];
810 if( p_playlist != NULL )
814 playlist_item_t *p_item = NULL;
816 for( i = 0; i < i_count; i++ )
818 o_number = [o_to_preparse lastObject];
819 i_row = [o_number intValue];
820 p_item = [[o_outline_view itemAtRow:i_row] pointerValue];
821 [o_to_preparse removeObject: o_number];
822 [o_outline_view deselectRow: i_row];
826 if( p_item->i_children == -1 )
828 playlist_PreparseEnqueue( p_playlist, p_item->p_input );
832 msg_Dbg( p_intf, "preparse of nodes not yet implemented" );
836 vlc_object_release( p_playlist );
838 [self playlistUpdated];
841 - (IBAction)servicesChange:(id)sender
843 NSMenuItem *o_mi = (NSMenuItem *)sender;
844 NSString *o_string = [o_mi representedObject];
845 playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
847 if( !playlist_IsServicesDiscoveryLoaded( p_playlist, [o_string cString] ) )
848 playlist_ServicesDiscoveryAdd( p_playlist, [o_string cString] );
850 playlist_ServicesDiscoveryRemove( p_playlist, [o_string cString] );
852 [o_mi setState: playlist_IsServicesDiscoveryLoaded( p_playlist,
853 [o_string cString] ) ? YES : NO];
855 vlc_object_release( p_playlist );
856 [self playlistUpdated];
860 - (IBAction)selectAll:(id)sender
862 [o_outline_view selectAll: nil];
865 - (IBAction)deleteItem:(id)sender
867 int i, i_count, i_row;
868 NSMutableArray *o_to_delete;
871 playlist_t * p_playlist;
872 intf_thread_t * p_intf = VLCIntf;
874 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
877 if ( p_playlist == NULL )
881 o_to_delete = [NSMutableArray arrayWithArray:[[o_outline_view selectedRowEnumerator] allObjects]];
882 i_count = [o_to_delete count];
884 for( i = 0; i < i_count; i++ )
886 o_number = [o_to_delete lastObject];
887 i_row = [o_number intValue];
888 id o_item = [o_outline_view itemAtRow: i_row];
889 playlist_item_t *p_item = [o_item pointerValue];
890 [o_to_delete removeObject: o_number];
891 [o_outline_view deselectRow: i_row];
893 if( [[o_outline_view dataSource] outlineView:o_outline_view
894 numberOfChildrenOfItem: o_item] > 0 )
895 //is a node and not an item
897 if( p_playlist->status.i_status != PLAYLIST_STOPPED &&
898 [self isItem: p_playlist->status.p_item inNode:
899 ((playlist_item_t *)[o_item pointerValue])
900 checkItemExistence: NO] == YES )
902 // if current item is in selected node and is playing then stop playlist
903 playlist_Stop( p_playlist );
905 vlc_mutex_lock( &p_playlist->object_lock );
906 playlist_NodeDelete( p_playlist, p_item, VLC_TRUE, VLC_FALSE );
907 vlc_mutex_unlock( &p_playlist->object_lock );
911 playlist_LockDelete( p_playlist, p_item->i_id );
914 [self playlistUpdated];
915 vlc_object_release( p_playlist );
918 - (IBAction)sortNodeByName:(id)sender
920 [self sortNode: SORT_TITLE];
923 - (IBAction)sortNodeByAuthor:(id)sender
925 [self sortNode: SORT_AUTHOR];
928 - (void)sortNode:(int)i_mode
930 playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
932 playlist_item_t * p_item;
934 if (p_playlist == NULL)
939 if( [o_outline_view selectedRow] > -1 )
941 p_item = [[o_outline_view itemAtRow: [o_outline_view selectedRow]]
945 /*If no item is selected, sort the whole playlist*/
947 p_item = p_playlist->p_root_category;
950 if( p_item->i_children > -1 ) // the item is a node
952 vlc_mutex_lock( &p_playlist->object_lock );
953 playlist_RecursiveNodeSort( p_playlist, p_item, i_mode, ORDER_NORMAL );
954 vlc_mutex_unlock( &p_playlist->object_lock );
958 vlc_mutex_lock( &p_playlist->object_lock );
959 playlist_RecursiveNodeSort( p_playlist,
960 p_item->p_parent, i_mode, ORDER_NORMAL );
961 vlc_mutex_unlock( &p_playlist->object_lock );
963 vlc_object_release( p_playlist );
964 [self playlistUpdated];
967 - (input_item_t *)createItem:(NSDictionary *)o_one_item
969 intf_thread_t * p_intf = VLCIntf;
970 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
973 if( p_playlist == NULL )
977 input_item_t *p_input;
979 BOOL b_rem = FALSE, b_dir = FALSE;
980 NSString *o_uri, *o_name;
985 o_uri = (NSString *)[o_one_item objectForKey: @"ITEM_URL"];
986 o_name = (NSString *)[o_one_item objectForKey: @"ITEM_NAME"];
987 o_options = (NSArray *)[o_one_item objectForKey: @"ITEM_OPTIONS"];
989 /* Find the name for a disc entry ( i know, can you believe the trouble?) */
990 if( ( !o_name || [o_name isEqualToString:@""] ) && [o_uri rangeOfString: @"/dev/"].location != NSNotFound )
992 int i_count, i_index;
993 struct statfs *mounts = NULL;
995 i_count = getmntinfo (&mounts, MNT_NOWAIT);
996 /* getmntinfo returns a pointer to static data. Do not free. */
997 for( i_index = 0 ; i_index < i_count; i_index++ )
999 NSMutableString *o_temp, *o_temp2;
1000 o_temp = [NSMutableString stringWithString: o_uri];
1001 o_temp2 = [NSMutableString stringWithCString: mounts[i_index].f_mntfromname];
1002 [o_temp replaceOccurrencesOfString: @"/dev/rdisk" withString: @"/dev/disk" options:nil range:NSMakeRange(0, [o_temp length]) ];
1003 [o_temp2 replaceOccurrencesOfString: @"s0" withString: @"" options:nil range:NSMakeRange(0, [o_temp2 length]) ];
1004 [o_temp2 replaceOccurrencesOfString: @"s1" withString: @"" options:nil range:NSMakeRange(0, [o_temp2 length]) ];
1006 if( strstr( [o_temp fileSystemRepresentation], [o_temp2 fileSystemRepresentation] ) != NULL )
1008 o_name = [[NSFileManager defaultManager] displayNameAtPath: [NSString stringWithCString:mounts[i_index].f_mntonname]];
1012 /* If no name, then make a guess */
1013 if( !o_name) o_name = [[NSFileManager defaultManager] displayNameAtPath: o_uri];
1015 if( [[NSFileManager defaultManager] fileExistsAtPath:o_uri isDirectory:&b_dir] && b_dir &&
1016 [[NSWorkspace sharedWorkspace] getFileSystemInfoForPath: o_uri isRemovable: &b_rem
1017 isWritable:NULL isUnmountable:NULL description:NULL type:NULL] && b_rem )
1019 /* All of this is to make sure CD's play when you D&D them on VLC */
1020 /* Converts mountpoint to a /dev file */
1023 NSMutableString *o_temp;
1025 buf = (struct statfs *) malloc (sizeof(struct statfs));
1026 statfs( [o_uri fileSystemRepresentation], buf );
1027 psz_dev = strdup(buf->f_mntfromname);
1028 o_temp = [NSMutableString stringWithCString: psz_dev ];
1029 [o_temp replaceOccurrencesOfString: @"/dev/disk" withString: @"/dev/rdisk" options:nil range:NSMakeRange(0, [o_temp length]) ];
1030 [o_temp replaceOccurrencesOfString: @"s0" withString: @"" options:nil range:NSMakeRange(0, [o_temp length]) ];
1031 [o_temp replaceOccurrencesOfString: @"s1" withString: @"" options:nil range:NSMakeRange(0, [o_temp length]) ];
1035 p_input = input_ItemNew( p_playlist, [o_uri fileSystemRepresentation], [o_name UTF8String] );
1041 for( i = 0; i < (int)[o_options count]; i++ )
1043 vlc_input_item_AddOption( p_input, strdup( [[o_options objectAtIndex:i] UTF8String] ) );
1047 /* Recent documents menu */
1048 o_true_file = [NSURL fileURLWithPath: o_uri];
1049 if( o_true_file != nil )
1051 [[NSDocumentController sharedDocumentController]
1052 noteNewRecentDocumentURL: o_true_file];
1055 vlc_object_release( p_playlist );
1059 - (void)appendArray:(NSArray*)o_array atPos:(int)i_position enqueue:(BOOL)b_enqueue
1062 playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
1064 if( p_playlist == NULL )
1069 for( i_item = 0; i_item < (int)[o_array count]; i_item++ )
1071 input_item_t *p_input;
1072 NSDictionary *o_one_item;
1075 o_one_item = [o_array objectAtIndex: i_item];
1076 p_input = [self createItem: o_one_item];
1083 playlist_PlaylistAddInput( p_playlist, p_input, PLAYLIST_INSERT,
1084 i_position == -1 ? PLAYLIST_END : i_position + i_item );
1086 if( i_item == 0 && !b_enqueue )
1088 playlist_item_t *p_item;
1089 p_item = playlist_ItemGetByInput( p_playlist, p_input );
1090 playlist_Control( p_playlist, PLAYLIST_ITEMPLAY, p_item );
1094 playlist_item_t *p_item;
1095 p_item = playlist_ItemGetByInput( p_playlist, p_input );
1096 playlist_Control( p_playlist, PLAYLIST_PREPARSE, p_item );
1099 [self playlistUpdated];
1100 vlc_object_release( p_playlist );
1103 - (void)appendNodeArray:(NSArray*)o_array inNode:(playlist_item_t *)p_node atPos:(int)i_position enqueue:(BOOL)b_enqueue
1106 playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
1108 if( p_playlist == NULL )
1113 for( i_item = 0; i_item < (int)[o_array count]; i_item++ )
1115 input_item_t *p_input;
1116 NSDictionary *o_one_item;
1119 o_one_item = [o_array objectAtIndex: i_item];
1120 p_input = [self createItem: o_one_item];
1127 playlist_NodeAddInput( p_playlist, p_input, p_node,
1130 PLAYLIST_END : i_position + i_item );
1133 if( i_item == 0 && !b_enqueue )
1135 playlist_item_t *p_item;
1136 p_item = playlist_ItemGetByInput( p_playlist, p_input );
1137 playlist_Control( p_playlist, PLAYLIST_ITEMPLAY, p_item );
1141 playlist_item_t *p_item;
1142 p_item = playlist_ItemGetByInput( p_playlist, p_input );
1143 playlist_Control( p_playlist, PLAYLIST_PREPARSE, p_item );
1146 [self playlistUpdated];
1147 vlc_object_release( p_playlist );
1150 - (IBAction)handlePopUp:(id)sender
1153 intf_thread_t * p_intf = VLCIntf;
1154 vlc_value_t val1,val2;
1155 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1157 if( p_playlist == NULL )
1162 switch( [o_loop_popup indexOfSelectedItem] )
1167 var_Set( p_playlist, "loop", val1 );
1169 var_Set( p_playlist, "repeat", val1 );
1170 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat One" ) );
1175 var_Set( p_playlist, "repeat", val1 );
1177 var_Set( p_playlist, "loop", val1 );
1178 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat All" ) );
1182 var_Get( p_playlist, "repeat", &val1 );
1183 var_Get( p_playlist, "loop", &val2 );
1184 if( val1.b_bool || val2.b_bool )
1187 var_Set( p_playlist, "repeat", val1 );
1188 var_Set( p_playlist, "loop", val1 );
1189 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat Off" ) );
1193 vlc_object_release( p_playlist );
1194 [self playlistUpdated];
1197 - (NSMutableArray *)subSearchItem:(playlist_item_t *)p_item
1199 playlist_t *p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
1201 playlist_item_t *p_selected_item;
1202 int i_current, i_selected_row;
1207 i_selected_row = [o_outline_view selectedRow];
1208 if (i_selected_row < 0)
1211 p_selected_item = (playlist_item_t *)[[o_outline_view itemAtRow:
1212 i_selected_row] pointerValue];
1214 for( i_current = 0; i_current < p_item->i_children ; i_current++ )
1217 NSString *o_current_name, *o_current_author;
1219 vlc_mutex_lock( &p_playlist->object_lock );
1220 o_current_name = [NSString stringWithUTF8String:
1221 p_item->pp_children[i_current]->p_input->psz_name];
1222 psz_temp = vlc_input_item_GetInfo( p_item->p_input ,
1223 _("Meta-information"),_("Artist") );
1224 o_current_author = [NSString stringWithUTF8String: psz_temp];
1226 vlc_mutex_unlock( &p_playlist->object_lock );
1228 if( p_selected_item == p_item->pp_children[i_current] &&
1229 b_selected_item_met == NO )
1231 b_selected_item_met = YES;
1233 else if( p_selected_item == p_item->pp_children[i_current] &&
1234 b_selected_item_met == YES )
1236 vlc_object_release( p_playlist );
1239 else if( b_selected_item_met == YES &&
1240 ( [o_current_name rangeOfString:[o_search_field
1241 stringValue] options:NSCaseInsensitiveSearch ].length ||
1242 [o_current_author rangeOfString:[o_search_field
1243 stringValue] options:NSCaseInsensitiveSearch ].length ) )
1245 vlc_object_release( p_playlist );
1246 /*Adds the parent items in the result array as well, so that we can
1248 return [NSMutableArray arrayWithObject: [NSValue
1249 valueWithPointer: p_item->pp_children[i_current]]];
1251 if( p_item->pp_children[i_current]->i_children > 0 )
1253 id o_result = [self subSearchItem:
1254 p_item->pp_children[i_current]];
1255 if( o_result != NULL )
1257 vlc_object_release( p_playlist );
1258 [o_result insertObject: [NSValue valueWithPointer:
1259 p_item->pp_children[i_current]] atIndex:0];
1264 vlc_object_release( p_playlist );
1268 - (IBAction)searchItem:(id)sender
1270 playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
1277 b_selected_item_met = NO;
1279 if( p_playlist == NULL )
1282 /*First, only search after the selected item:*
1283 *(b_selected_item_met = NO) */
1284 o_result = [self subSearchItem:p_playlist->p_root_category];
1285 if( o_result == NULL )
1287 /* If the first search failed, search again from the beginning */
1288 o_result = [self subSearchItem:p_playlist->p_root_category];
1290 if( o_result != NULL )
1293 if( [[o_result objectAtIndex: 0] pointerValue] ==
1294 p_playlist->p_local_category )
1299 for( i = i_start ; i < [o_result count] - 1 ; i++ )
1301 [o_outline_view expandItem: [o_outline_dict objectForKey:
1302 [NSString stringWithFormat: @"%p",
1303 [[o_result objectAtIndex: i] pointerValue]]]];
1305 i_row = [o_outline_view rowForItem: [o_outline_dict objectForKey:
1306 [NSString stringWithFormat: @"%p",
1307 [[o_result objectAtIndex: [o_result count] - 1 ]
1312 [o_outline_view selectRow:i_row byExtendingSelection: NO];
1313 [o_outline_view scrollRowToVisible: i_row];
1315 vlc_object_release( p_playlist );
1318 - (IBAction)recursiveExpandNode:(id)sender
1320 id o_item = [o_outline_view itemAtRow: [o_outline_view selectedRow]];
1321 playlist_item_t *p_item = (playlist_item_t *)[o_item pointerValue];
1323 if( ![[o_outline_view dataSource] outlineView: o_outline_view
1324 isItemExpandable: o_item] )
1326 o_item = [o_outline_dict objectForKey: [NSString
1327 stringWithFormat: @"%p", p_item->p_parent]];
1330 /* We need to collapse the node first, since OSX refuses to recursively
1331 expand an already expanded node, even if children nodes are collapsed. */
1332 [o_outline_view collapseItem: o_item collapseChildren: YES];
1333 [o_outline_view expandItem: o_item expandChildren: YES];
1336 - (NSMenu *)menuForEvent:(NSEvent *)o_event
1340 vlc_bool_t b_item_sel;
1342 pt = [o_outline_view convertPoint: [o_event locationInWindow]
1344 b_item_sel = ( [o_outline_view rowAtPoint: pt] != -1 &&
1345 [o_outline_view selectedRow] != -1 );
1346 b_rows = [o_outline_view numberOfRows] != 0;
1348 [o_mi_play setEnabled: b_item_sel];
1349 [o_mi_delete setEnabled: b_item_sel];
1350 [o_mi_selectall setEnabled: b_rows];
1351 [o_mi_info setEnabled: b_item_sel];
1352 [o_mi_preparse setEnabled: b_item_sel];
1353 [o_mi_recursive_expand setEnabled: b_item_sel];
1354 [o_mi_sort_name setEnabled: b_item_sel];
1355 [o_mi_sort_author setEnabled: b_item_sel];
1357 return( o_ctx_menu );
1360 - (void)outlineView: (NSTableView*)o_tv
1361 didClickTableColumn:(NSTableColumn *)o_tc
1363 int i_mode = 0, i_type;
1364 intf_thread_t *p_intf = VLCIntf;
1366 playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1368 if( p_playlist == NULL )
1373 /* Check whether the selected table column header corresponds to a
1374 sortable table column*/
1375 if( !( o_tc == o_tc_name || o_tc == o_tc_author ) )
1377 vlc_object_release( p_playlist );
1381 if( o_tc_sortColumn == o_tc )
1383 b_isSortDescending = !b_isSortDescending;
1387 b_isSortDescending = VLC_FALSE;
1390 if( o_tc == o_tc_name )
1392 i_mode = SORT_TITLE;
1394 else if( o_tc == o_tc_author )
1396 i_mode = SORT_AUTHOR;
1399 if( b_isSortDescending )
1401 i_type = ORDER_REVERSE;
1405 i_type = ORDER_NORMAL;
1408 vlc_mutex_lock( &p_playlist->object_lock );
1409 playlist_RecursiveNodeSort( p_playlist, p_playlist->p_root_category, i_mode, i_type );
1410 vlc_mutex_unlock( &p_playlist->object_lock );
1412 vlc_object_release( p_playlist );
1413 [self playlistUpdated];
1415 o_tc_sortColumn = o_tc;
1416 [o_outline_view setHighlightedTableColumn:o_tc];
1418 if( b_isSortDescending )
1420 [o_outline_view setIndicatorImage:o_descendingSortingImage
1421 inTableColumn:o_tc];
1425 [o_outline_view setIndicatorImage:o_ascendingSortingImage
1426 inTableColumn:o_tc];
1431 - (void)outlineView:(NSOutlineView *)outlineView
1432 willDisplayCell:(id)cell
1433 forTableColumn:(NSTableColumn *)tableColumn
1436 playlist_t *p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
1441 if( !p_playlist ) return;
1443 o_playing_item = [o_outline_dict objectForKey:
1444 [NSString stringWithFormat:@"%p", p_playlist->status.p_item]];
1446 if( [self isItem: [o_playing_item pointerValue] inNode:
1447 [item pointerValue] checkItemExistence: YES]
1448 || [o_playing_item isEqual: item] )
1450 [cell setFont: [NSFont boldSystemFontOfSize: 0]];
1454 [cell setFont: [NSFont systemFontOfSize: 0]];
1456 vlc_object_release( p_playlist );
1459 - (IBAction)addNode:(id)sender
1461 /* we have to create a new thread here because otherwise we would block the
1462 * interface since the interaction-stuff and this code would run in the same
1464 [NSThread detachNewThreadSelector: @selector(addNodeThreadedly)
1465 toTarget: self withObject:nil];
1466 [self playlistUpdated];
1469 - (void)addNodeThreadedly
1471 NSAutoreleasePool * ourPool = [[NSAutoreleasePool alloc] init];
1473 /* simply adds a new node to the end of the playlist */
1474 playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
1476 vlc_thread_set_priority( p_playlist, VLC_THREAD_PRIORITY_LOW );
1484 char *psz_name = NULL;
1485 playlist_item_t * p_item;
1486 ret_v = intf_UserStringInput( p_playlist, _("New Node"),
1487 _("Please enter a name for the new node."), &psz_name );
1488 if( psz_name != NULL && psz_name != "" )
1489 p_item = playlist_NodeCreate( p_playlist, psz_name,
1490 p_playlist->p_local_category );
1492 p_item = playlist_NodeCreate( p_playlist, _("Empty Folder"),
1493 p_playlist->p_local_category );
1496 msg_Warn( VLCIntf, "node creation failed" );
1498 vlc_object_release( p_playlist );
1504 @implementation VLCPlaylist (NSOutlineViewDataSource)
1506 - (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item
1508 id o_value = [super outlineView: outlineView child: index ofItem: item];
1509 playlist_t *p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
1512 if( !p_playlist ) return nil;
1514 if( p_playlist->i_size >= 2 )
1516 [o_status_field setStringValue: [NSString stringWithFormat:
1517 _NS("%i items in the playlist"), p_playlist->i_size]];
1521 if( p_playlist->i_size == 0 )
1523 [o_status_field setStringValue: _NS("No items in the playlist")];
1527 [o_status_field setStringValue: _NS("1 item in the playlist")];
1530 vlc_object_release( p_playlist );
1532 [o_outline_dict setObject:o_value forKey:[NSString stringWithFormat:@"%p",
1533 [o_value pointerValue]]];
1534 NSLog( @"add item %p", [o_value pointerValue] );
1539 /* Required for drag & drop and reordering */
1540 - (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pboard
1543 playlist_t *p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
1546 /* First remove the items that were moved during the last drag & drop
1548 [o_items_array removeAllObjects];
1549 [o_nodes_array removeAllObjects];
1551 if( !p_playlist ) return NO;
1553 for( i = 0 ; i < [items count] ; i++ )
1555 id o_item = [items objectAtIndex: i];
1557 /* Refuse to move items that are not in the General Node
1558 (Service Discovery) */
1559 if( ![self isItem: [o_item pointerValue] inNode:
1560 p_playlist->p_local_category checkItemExistence: NO])
1562 vlc_object_release(p_playlist);
1565 /* Fill the items and nodes to move in 2 different arrays */
1566 if( ((playlist_item_t *)[o_item pointerValue])->i_children > 0 )
1567 [o_nodes_array addObject: o_item];
1569 [o_items_array addObject: o_item];
1572 /* Now we need to check if there are selected items that are in already
1573 selected nodes. In that case, we only want to move the nodes */
1574 [self removeItemsFrom: o_nodes_array ifChildrenOf: o_nodes_array];
1575 [self removeItemsFrom: o_items_array ifChildrenOf: o_nodes_array];
1577 /* We add the "VLCPlaylistItemPboardType" type to be able to recognize
1578 a Drop operation coming from the playlist. */
1580 [pboard declareTypes: [NSArray arrayWithObjects:
1581 @"VLCPlaylistItemPboardType", nil] owner: self];
1582 [pboard setData:[NSData data] forType:@"VLCPlaylistItemPboardType"];
1584 vlc_object_release(p_playlist);
1588 - (NSDragOperation)outlineView:(NSOutlineView *)outlineView validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(int)index
1590 playlist_t *p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
1592 NSPasteboard *o_pasteboard = [info draggingPasteboard];
1594 if( !p_playlist ) return NSDragOperationNone;
1596 /* Dropping ON items is not allowed if item is not a node */
1599 if( index == NSOutlineViewDropOnItemIndex &&
1600 ((playlist_item_t *)[item pointerValue])->i_children == -1 )
1602 vlc_object_release( p_playlist );
1603 return NSDragOperationNone;
1607 /* We refuse to drop an item in anything else than a child of the General
1608 Node. We still accept items that would be root nodes of the outlineview
1609 however, to allow drop in an empty playlist. */
1610 if( !([self isItem: [item pointerValue] inNode: p_playlist->p_local_category
1611 checkItemExistence: NO] || item == nil) )
1613 vlc_object_release( p_playlist );
1614 return NSDragOperationNone;
1617 /* Drop from the Playlist */
1618 if( [[o_pasteboard types] containsObject: @"VLCPlaylistItemPboardType"] )
1621 for( i = 0 ; i < [o_nodes_array count] ; i++ )
1623 /* We refuse to Drop in a child of an item we are moving */
1624 if( [self isItem: [item pointerValue] inNode:
1625 [[o_nodes_array objectAtIndex: i] pointerValue]
1626 checkItemExistence: NO] )
1628 vlc_object_release( p_playlist );
1629 return NSDragOperationNone;
1632 vlc_object_release(p_playlist);
1633 return NSDragOperationMove;
1636 /* Drop from the Finder */
1637 else if( [[o_pasteboard types] containsObject: NSFilenamesPboardType] )
1639 vlc_object_release(p_playlist);
1640 return NSDragOperationGeneric;
1642 vlc_object_release(p_playlist);
1643 return NSDragOperationNone;
1646 - (BOOL)outlineView:(NSOutlineView *)outlineView acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(int)index
1648 playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
1650 NSPasteboard *o_pasteboard = [info draggingPasteboard];
1652 if( !p_playlist ) return NO;
1654 /* Drag & Drop inside the playlist */
1655 if( [[o_pasteboard types] containsObject: @"VLCPlaylistItemPboardType"] )
1657 int i_row, i_removed_from_node = 0;
1659 playlist_item_t *p_new_parent, *p_item = NULL;
1660 NSArray *o_all_items = [o_nodes_array arrayByAddingObjectsFromArray:
1662 /* If the item is to be dropped as root item of the outline, make it a
1663 child of the General node.
1664 Else, choose the proposed parent as parent. */
1665 if( item == nil ) p_new_parent = p_playlist->p_local_category;
1666 else p_new_parent = [item pointerValue];
1668 /* Make sure the proposed parent is a node.
1669 (This should never be true) */
1670 if( p_new_parent->i_children < 0 )
1672 vlc_object_release( p_playlist );
1676 for( i = 0; i < [o_all_items count]; i++ )
1678 playlist_item_t *p_old_parent = NULL;
1679 int i_old_index = 0;
1681 p_item = [[o_all_items objectAtIndex:i] pointerValue];
1682 p_old_parent = p_item->p_parent;
1685 /* We may need the old index later */
1686 if( p_new_parent == p_old_parent )
1689 for( j = 0; j < p_old_parent->i_children; j++ )
1691 if( p_old_parent->pp_children[j] == p_item )
1699 vlc_mutex_lock( &p_playlist->object_lock );
1700 // Acually detach the item from the old position
1701 if( playlist_NodeRemoveItem( p_playlist, p_item, p_old_parent ) ==
1705 /* Calculate the new index */
1708 /* If we move the item in the same node, we need to take into
1709 account that one item will be deleted */
1712 if ((p_new_parent == p_old_parent &&
1713 i_old_index < index + (int)i) )
1715 i_removed_from_node++;
1717 i_new_index = index + i - i_removed_from_node;
1719 // Reattach the item to the new position
1720 playlist_NodeInsert( p_playlist, p_item, p_new_parent, i_new_index );
1722 vlc_mutex_unlock( &p_playlist->object_lock );
1724 [self playlistUpdated];
1725 i_row = [o_outline_view rowForItem:[o_outline_dict
1726 objectForKey:[NSString stringWithFormat: @"%p",
1727 [[o_all_items objectAtIndex: 0] pointerValue]]]];
1731 i_row = [o_outline_view rowForItem:[o_outline_dict
1732 objectForKey:[NSString stringWithFormat: @"%p", p_new_parent]]];
1735 [o_outline_view deselectAll: self];
1736 [o_outline_view selectRow: i_row byExtendingSelection: NO];
1737 [o_outline_view scrollRowToVisible: i_row];
1739 vlc_object_release(p_playlist);
1743 else if( [[o_pasteboard types] containsObject: NSFilenamesPboardType] )
1746 playlist_item_t *p_node = [item pointerValue];
1748 NSArray *o_array = [NSArray array];
1749 NSArray *o_values = [[o_pasteboard propertyListForType:
1750 NSFilenamesPboardType]
1751 sortedArrayUsingSelector:
1752 @selector(caseInsensitiveCompare:)];
1754 for( i = 0; i < (int)[o_values count]; i++)
1756 NSDictionary *o_dic;
1757 o_dic = [NSDictionary dictionaryWithObject:[o_values
1758 objectAtIndex:i] forKey:@"ITEM_URL"];
1759 o_array = [o_array arrayByAddingObject: o_dic];
1764 [self appendArray: o_array atPos: index enqueue: YES];
1766 /* This should never occur */
1767 else if( p_node->i_children == -1 )
1769 vlc_object_release( p_playlist );
1774 [self appendNodeArray: o_array inNode: p_node
1775 atPos: index enqueue: YES];
1777 vlc_object_release( p_playlist );
1780 vlc_object_release( p_playlist );
1784 /* Delegate method of NSWindow */
1785 /*- (void)windowWillClose:(NSNotification *)aNotification
1787 [o_btn_playlist setState: NSOffState];