1 /*****************************************************************************
2 * playlist.m: MacOS X interface module
3 *****************************************************************************
4 * Copyright (C) 2002-2005 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 a new search field build with pictures from the 'regular' search field, so it can be emulated on 10.2
29 * create toggle buttons for the shuffle, repeat one, repeat all functions.
30 * implement drag and drop and item reordering.
31 * reimplement enable/disable item
32 * create a new 'tool' button (see the gear button in the Finder window) for 'actions'
33 (adding service discovery, other views, new node/playlist, save node/playlist) stuff like that
37 /*****************************************************************************
39 *****************************************************************************/
40 #include <stdlib.h> /* malloc(), free() */
41 #include <sys/param.h> /* for MAXPATHLEN */
44 #include <sys/mount.h>
50 #import "playlistinfo.h"
56 /*****************************************************************************
57 * VLCPlaylistView implementation
58 *****************************************************************************/
59 @implementation VLCPlaylistView
61 - (NSMenu *)menuForEvent:(NSEvent *)o_event
63 return( [[self delegate] menuForEvent: o_event] );
66 - (void)keyDown:(NSEvent *)o_event
70 if( [[o_event characters] length] )
72 key = [[o_event characters] characterAtIndex: 0];
77 case NSDeleteCharacter:
78 case NSDeleteFunctionKey:
79 case NSDeleteCharFunctionKey:
80 case NSBackspaceCharacter:
81 [[self delegate] deleteItem:self];
84 case NSEnterCharacter:
85 case NSCarriageReturnCharacter:
86 [(VLCPlaylist *)[[VLCMain sharedInstance] getPlaylist]
91 [super keyDown: o_event];
99 /*****************************************************************************
100 * VLCPlaylistCommon implementation
102 * This class the superclass of the VLCPlaylist and VLCPlaylistWizard.
103 * It contains the common methods and elements of these 2 entities.
104 *****************************************************************************/
105 @implementation VLCPlaylistCommon
112 o_outline_dict = [[NSMutableDictionary alloc] init];
118 playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
120 i_current_view = VIEW_CATEGORY;
121 playlist_ViewUpdate( p_playlist, i_current_view );
123 [o_outline_view setTarget: self];
124 [o_outline_view setDelegate: self];
125 [o_outline_view setDataSource: self];
127 vlc_object_release( p_playlist );
133 [[o_tc_name headerCell] setStringValue:_NS("Name")];
134 [[o_tc_author headerCell] setStringValue:_NS("Author")];
135 [[o_tc_duration headerCell] setStringValue:_NS("Duration")];
138 - (NSOutlineView *)outlineView
140 return o_outline_view;
143 - (playlist_item_t *)selectedPlaylistItem
145 return [[o_outline_view itemAtRow: [o_outline_view selectedRow]]
151 @implementation VLCPlaylistCommon (NSOutlineViewDataSource)
153 /* return the number of children for Obj-C pointer item */ /* DONE */
154 - (int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
157 playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
159 if( p_playlist == NULL )
161 if( outlineView != o_outline_view )
163 vlc_object_release( p_playlist );
170 playlist_view_t *p_view;
171 p_view = playlist_ViewFind( p_playlist, i_current_view );
172 if( p_view && p_view->p_root )
174 i_return = p_view->p_root->i_children;
176 if( i_current_view == VIEW_CATEGORY )
178 i_return--; /* remove the GENERAL item from the list */
179 i_return += p_playlist->p_general->i_children; /* add the items of the general node */
185 playlist_item_t *p_item = (playlist_item_t *)[item pointerValue];
187 i_return = p_item->i_children;
189 vlc_object_release( p_playlist );
197 /* return the child at index for the Obj-C pointer item */ /* DONE */
198 - (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item
200 playlist_item_t *p_return = NULL;
201 playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
205 if( p_playlist == NULL )
211 playlist_view_t *p_view;
212 p_view = playlist_ViewFind( p_playlist, i_current_view );
213 if( p_view && p_view->p_root ) p_return = p_view->p_root->pp_children[index];
215 if( i_current_view == VIEW_CATEGORY )
217 if( p_playlist->p_general->i_children && index >= 0 && index < p_playlist->p_general->i_children )
219 p_return = p_playlist->p_general->pp_children[index];
221 else if( p_view && p_view->p_root && index >= 0 && index - p_playlist->p_general->i_children < p_view->p_root->i_children )
223 p_return = p_view->p_root->pp_children[index - p_playlist->p_general->i_children + 1];
229 playlist_item_t *p_item = (playlist_item_t *)[item pointerValue];
230 if( p_item && index < p_item->i_children && index >= 0 )
231 p_return = p_item->pp_children[index];
235 vlc_object_release( p_playlist );
237 o_value = [o_outline_dict objectForKey:[NSString stringWithFormat: @"%p", p_return]];
240 o_value = [[NSValue valueWithPointer: p_return] retain];
245 /* is the item expandable */
246 - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item
249 playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
251 if( p_playlist == NULL )
257 playlist_view_t *p_view;
258 p_view = playlist_ViewFind( p_playlist, i_current_view );
259 if( p_view && p_view->p_root ) i_return = p_view->p_root->i_children;
261 if( i_current_view == VIEW_CATEGORY )
264 i_return += p_playlist->p_general->i_children;
269 playlist_item_t *p_item = (playlist_item_t *)[item pointerValue];
271 i_return = p_item->i_children;
273 vlc_object_release( p_playlist );
281 /* retrieve the string values for the cells */
282 - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)o_tc byItem:(id)item
285 intf_thread_t *p_intf = VLCIntf;
286 playlist_t *p_playlist;
287 playlist_item_t *p_item;
289 if( item == nil || ![item isKindOfClass: [NSValue class]] ) return( @"error" );
291 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
293 if( p_playlist == NULL )
298 p_item = (playlist_item_t *)[item pointerValue];
302 vlc_object_release( p_playlist );
306 if( [[o_tc identifier] isEqualToString:@"1"] )
308 o_value = [NSString stringWithUTF8String:
309 p_item->input.psz_name];
310 if( o_value == NULL )
311 o_value = [NSString stringWithCString:
312 p_item->input.psz_name];
314 else if( [[o_tc identifier] isEqualToString:@"2"] )
317 psz_temp = vlc_input_item_GetInfo( &p_item->input ,_("Meta-information"),_("Artist") );
319 if( psz_temp == NULL )
323 o_value = [NSString stringWithUTF8String: psz_temp];
324 if( o_value == NULL )
326 o_value = [NSString stringWithCString: psz_temp];
331 else if( [[o_tc identifier] isEqualToString:@"3"] )
333 char psz_duration[MSTRTIME_MAX_SIZE];
334 mtime_t dur = p_item->input.i_duration;
337 secstotimestr( psz_duration, dur/1000000 );
338 o_value = [NSString stringWithUTF8String: psz_duration];
342 o_value = @"-:--:--";
345 vlc_object_release( p_playlist );
352 /*****************************************************************************
353 * VLCPlaylistWizard implementation
354 *****************************************************************************/
355 @implementation VLCPlaylistWizard
357 - (IBAction)reloadOutlineView
359 /* Only reload the outlineview if the wizard window is open since this can
360 be quite long on big playlists */
361 if( [[o_outline_view window] isVisible] )
363 [o_outline_view reloadData];
369 /*****************************************************************************
370 * VLCPlaylist implementation
371 *****************************************************************************/
372 @implementation VLCPlaylist
379 o_nodes_array = [[NSMutableArray alloc] init];
380 o_items_array = [[NSMutableArray alloc] init];
387 playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
389 vlc_list_t *p_list = vlc_list_find( p_playlist, VLC_OBJECT_MODULE,
394 [super awakeFromNib];
396 [o_outline_view setDoubleAction: @selector(playItem:)];
398 [o_outline_view registerForDraggedTypes:
399 [NSArray arrayWithObjects: NSFilenamesPboardType,
400 @"VLCPlaylistItemPboardType", nil]];
401 [o_outline_view setIntercellSpacing: NSMakeSize (0.0, 1.0)];
403 /* We need to check whether _defaultTableHeaderSortImage exists, since it
404 belongs to an Apple hidden private API, and then can "disapear" at any time*/
406 if( [[NSOutlineView class] respondsToSelector:@selector(_defaultTableHeaderSortImage)] )
408 o_ascendingSortingImage = [[NSOutlineView class] _defaultTableHeaderSortImage];
412 o_ascendingSortingImage = nil;
415 if( [[NSOutlineView class] respondsToSelector:@selector(_defaultTableHeaderReverseSortImage)] )
417 o_descendingSortingImage = [[NSOutlineView class] _defaultTableHeaderReverseSortImage];
421 o_descendingSortingImage = nil;
424 o_tc_sortColumn = nil;
426 for( i_index = 0; i_index < p_list->i_count; i_index++ )
429 module_t * p_parser = (module_t *)p_list->p_values[i_index].p_object ;
431 if( !strcmp( p_parser->psz_capability, "services_discovery" ) )
433 /* create the menu entries used in the playlist menu */
434 o_lmi = [[o_mi_services submenu] addItemWithTitle:
435 [NSString stringWithUTF8String:
436 p_parser->psz_longname ? p_parser->psz_longname :
437 ( p_parser->psz_shortname ? p_parser->psz_shortname:
438 p_parser->psz_object_name)]
439 action: @selector(servicesChange:)
441 [o_lmi setTarget: self];
442 [o_lmi setRepresentedObject:
443 [NSString stringWithCString: p_parser->psz_object_name]];
444 if( playlist_IsServicesDiscoveryLoaded( p_playlist,
445 p_parser->psz_object_name ) )
446 [o_lmi setState: NSOnState];
448 /* create the menu entries for the main menu */
449 o_lmi = [[o_mm_mi_services submenu] addItemWithTitle:
450 [NSString stringWithUTF8String:
451 p_parser->psz_longname ? p_parser->psz_longname :
452 ( p_parser->psz_shortname ? p_parser->psz_shortname:
453 p_parser->psz_object_name)]
454 action: @selector(servicesChange:)
456 [o_lmi setTarget: self];
457 [o_lmi setRepresentedObject:
458 [NSString stringWithCString: p_parser->psz_object_name]];
459 if( playlist_IsServicesDiscoveryLoaded( p_playlist,
460 p_parser->psz_object_name ) )
461 [o_lmi setState: NSOnState];
464 vlc_list_release( p_list );
465 vlc_object_release( p_playlist );
467 //[self playlistUpdated];
470 - (void)searchfieldChanged:(NSNotification *)o_notification
472 [o_search_field setStringValue:[[o_notification object] stringValue]];
479 [o_mi_save_playlist setTitle: _NS("Save Playlist...")];
480 [o_mi_play setTitle: _NS("Play")];
481 [o_mi_delete setTitle: _NS("Delete")];
482 [o_mi_recursive_expand setTitle: _NS("Expand Node")];
483 [o_mi_selectall setTitle: _NS("Select All")];
484 [o_mi_info setTitle: _NS("Information")];
485 [o_mi_preparse setTitle: _NS("Get Stream Information")];
486 [o_mi_sort_name setTitle: _NS("Sort Node by Name")];
487 [o_mi_sort_author setTitle: _NS("Sort Node by Author")];
488 [o_mi_services setTitle: _NS("Services discovery")];
489 [o_status_field setStringValue: [NSString stringWithFormat:
490 _NS("No items in the playlist")]];
492 [o_random_ckb setTitle: _NS("Random")];
494 [o_search_button setTitle: _NS("Search")];
496 [o_search_field setToolTip: _NS("Search in Playlist")];
497 [[o_loop_popup itemAtIndex:0] setTitle: _NS("Standard Play")];
498 [[o_loop_popup itemAtIndex:1] setTitle: _NS("Repeat One")];
499 [[o_loop_popup itemAtIndex:2] setTitle: _NS("Repeat All")];
500 [o_mi_addNode setTitle: _NS("Add Folder to Playlist")];
503 - (void)playlistUpdated
507 /* Clear indications of any existing column sorting */
508 for( 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 [[[[VLCMain sharedInstance] getWizard] getPlaylistWizard] reloadOutlineView];
520 [[[[VLCMain sharedInstance] getBookmarks] getDataTable] reloadData];
523 - (void)playModeUpdated
525 playlist_t *p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
527 vlc_value_t val, val2;
529 if( p_playlist == NULL )
534 var_Get( p_playlist, "loop", &val2 );
535 var_Get( p_playlist, "repeat", &val );
536 if( val.b_bool == VLC_TRUE )
538 [o_loop_popup selectItemAtIndex: 1];
540 else if( val2.b_bool == VLC_TRUE )
542 [o_loop_popup selectItemAtIndex: 2];
546 [o_loop_popup selectItemAtIndex: 0];
549 var_Get( p_playlist, "random", &val );
550 [o_random_ckb setState: val.b_bool];
552 vlc_object_release( p_playlist );
555 - (playlist_item_t *)parentOfItem:(playlist_item_t *)p_item
558 for( i = 0 ; i < p_item->i_parents; i++ )
560 if( p_item->pp_parents[i]->i_view == i_current_view )
562 return p_item->pp_parents[i]->p_parent;
568 - (void)updateRowSelection
573 playlist_t *p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
575 playlist_item_t *p_item, *p_temp_item;
576 NSMutableArray *o_array = [NSMutableArray array];
578 if( p_playlist == NULL )
581 p_item = p_playlist->status.p_item;
584 vlc_object_release(p_playlist);
588 p_temp_item = p_item;
589 while( p_temp_item->i_parents > 0 )
591 [o_array insertObject: [NSValue valueWithPointer: p_temp_item] atIndex: 0];
593 p_temp_item = [self parentOfItem: p_temp_item];
594 /*for (i = 0 ; i < p_temp_item->i_parents ; i++)
596 if( p_temp_item->pp_parents[i]->i_view == i_current_view )
598 p_temp_item = p_temp_item->pp_parents[i]->p_parent;
604 for (j = 0 ; j < [o_array count] - 1 ; j++)
607 if( ( o_item = [o_outline_dict objectForKey:
608 [NSString stringWithFormat: @"%p",
609 [[o_array objectAtIndex:j] pointerValue]]] ) != nil )
610 [o_outline_view expandItem: o_item];
614 i_row = [o_outline_view rowForItem:[o_outline_dict
615 objectForKey:[NSString stringWithFormat: @"%p", p_item]]];
617 [o_outline_view selectRow: i_row byExtendingSelection: NO];
618 [o_outline_view scrollRowToVisible: i_row];
620 vlc_object_release(p_playlist);
622 /* update our info-panel to reflect the new item */
623 [[[VLCMain sharedInstance] getInfo] updatePanel];
626 /* Check if p_item is a child of p_node recursively. We need to check the item
627 existence first since OSX sometimes tries to redraw items that have been
628 deleted. We don't do it when not required since this verification takes
629 quite a long time on big playlists (yes, pretty hacky). */
630 - (BOOL)isItem: (playlist_item_t *)p_item
631 inNode: (playlist_item_t *)p_node
632 checkItemExistence:(BOOL)b_check
635 playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
637 playlist_item_t *p_temp_item = p_item;
639 if( p_playlist == NULL )
644 if( p_node == p_item )
646 vlc_object_release(p_playlist);
650 if( p_node->i_children < 1)
652 vlc_object_release(p_playlist);
659 vlc_mutex_lock( &p_playlist->object_lock );
663 /* Since outlineView: willDisplayCell:... may call this function with
664 p_items that don't exist anymore, first check if the item is still
665 in the playlist. Any cleaner solution welcomed. */
666 for( i = 0; i < p_playlist->i_all_size; i++ )
668 if( p_playlist->pp_all_items[i] == p_item ) break;
669 else if ( i == p_playlist->i_all_size - 1 )
671 vlc_object_release( p_playlist );
672 vlc_mutex_unlock( &p_playlist->object_lock );
678 while( p_temp_item->i_parents > 0 )
680 p_temp_item = [self parentOfItem: p_temp_item];
681 if( p_temp_item == p_node )
683 vlc_mutex_unlock( &p_playlist->object_lock );
684 vlc_object_release( p_playlist );
688 /* for( i = 0; i < p_temp_item->i_parents ; i++ )
690 if( p_temp_item->pp_parents[i]->i_view == i_current_view )
692 if( p_temp_item->pp_parents[i]->p_parent == p_node )
694 vlc_mutex_unlock( &p_playlist->object_lock );
695 vlc_object_release( p_playlist );
700 p_temp_item = p_temp_item->pp_parents[i]->p_parent;
706 vlc_mutex_unlock( &p_playlist->object_lock );
709 vlc_object_release( p_playlist );
713 /* This method is usefull for instance to remove the selected children of an
714 already selected node */
715 - (void)removeItemsFrom:(id)o_items ifChildrenOf:(id)o_nodes
718 for( i = 0 ; i < [o_items count] ; i++ )
720 for ( j = 0 ; j < [o_nodes count] ; j++ )
722 if( o_items == o_nodes)
724 if( j == i ) continue;
726 if( [self isItem: [[o_items objectAtIndex:i] pointerValue]
727 inNode: [[o_nodes objectAtIndex:j] pointerValue]
728 checkItemExistence: NO] )
730 [o_items removeObjectAtIndex:i];
731 /* We need to execute the next iteration with the same index
732 since the current item has been deleted */
741 - (IBAction)savePlaylist:(id)sender
743 intf_thread_t * p_intf = VLCIntf;
744 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
747 NSSavePanel *o_save_panel = [NSSavePanel savePanel];
748 NSString * o_name = [NSString stringWithFormat: @"%@.m3u", _NS("Untitled")];
749 [o_save_panel setTitle: _NS("Save Playlist")];
750 [o_save_panel setPrompt: _NS("Save")];
752 if( [o_save_panel runModalForDirectory: nil
753 file: o_name] == NSOKButton )
755 playlist_Export( p_playlist, [[o_save_panel filename] fileSystemRepresentation], "export-m3u" );
757 vlc_object_release( p_playlist );
761 /* When called retrieves the selected outlineview row and plays that node or item */
762 - (IBAction)playItem:(id)sender
764 intf_thread_t * p_intf = VLCIntf;
765 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
768 if( p_playlist != NULL )
770 playlist_item_t *p_item;
771 playlist_item_t *p_node = NULL;
773 p_item = [[o_outline_view itemAtRow:[o_outline_view selectedRow]] pointerValue];
777 if( p_item->i_children == -1 )
779 p_node = [self parentOfItem: p_item];
781 /* for( i = 0 ; i < p_item->i_parents ; i++ )
783 if( p_item->pp_parents[i]->i_view == i_current_view )
785 p_node = p_item->pp_parents[i]->p_parent;
792 if( p_node->i_children > 0 && p_node->pp_children[0]->i_children == -1 )
794 p_item = p_node->pp_children[0];
801 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, i_current_view, p_node, p_item );
803 vlc_object_release( p_playlist );
807 /* When called retrieves the selected outlineview row and plays that node or item */
808 - (IBAction)preparseItem:(id)sender
811 NSMutableArray *o_to_preparse;
812 intf_thread_t * p_intf = VLCIntf;
813 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
816 o_to_preparse = [NSMutableArray arrayWithArray:[[o_outline_view selectedRowEnumerator] allObjects]];
817 i_count = [o_to_preparse count];
819 if( p_playlist != NULL )
823 playlist_item_t *p_item = NULL;
825 for( i = 0; i < i_count; i++ )
827 o_number = [o_to_preparse lastObject];
828 i_row = [o_number intValue];
829 p_item = [[o_outline_view itemAtRow:i_row] pointerValue];
830 [o_to_preparse removeObject: o_number];
831 [o_outline_view deselectRow: i_row];
835 if( p_item->i_children == -1 )
837 playlist_PreparseEnqueue( p_playlist, &p_item->input );
841 msg_Dbg( p_intf, "preparse of nodes not yet implemented" );
845 vlc_object_release( p_playlist );
847 [self playlistUpdated];
850 - (IBAction)servicesChange:(id)sender
852 NSMenuItem *o_mi = (NSMenuItem *)sender;
853 NSString *o_string = [o_mi representedObject];
854 playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
856 if( !playlist_IsServicesDiscoveryLoaded( p_playlist, [o_string cString] ) )
857 playlist_ServicesDiscoveryAdd( p_playlist, [o_string cString] );
859 playlist_ServicesDiscoveryRemove( p_playlist, [o_string cString] );
861 [o_mi setState: playlist_IsServicesDiscoveryLoaded( p_playlist,
862 [o_string cString] ) ? YES : NO];
864 i_current_view = VIEW_CATEGORY;
865 playlist_ViewUpdate( p_playlist, i_current_view );
866 vlc_object_release( p_playlist );
867 [self playlistUpdated];
871 - (IBAction)selectAll:(id)sender
873 [o_outline_view selectAll: nil];
876 - (IBAction)deleteItem:(id)sender
878 int i, i_count, i_row;
879 NSMutableArray *o_to_delete;
882 playlist_t * p_playlist;
883 intf_thread_t * p_intf = VLCIntf;
885 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
888 if ( p_playlist == NULL )
892 o_to_delete = [NSMutableArray arrayWithArray:[[o_outline_view selectedRowEnumerator] allObjects]];
893 i_count = [o_to_delete count];
895 for( i = 0; i < i_count; i++ )
897 o_number = [o_to_delete lastObject];
898 i_row = [o_number intValue];
899 id o_item = [o_outline_view itemAtRow: i_row];
900 playlist_item_t *p_item = [o_item pointerValue];
901 [o_to_delete removeObject: o_number];
902 [o_outline_view deselectRow: i_row];
904 if( [[o_outline_view dataSource] outlineView:o_outline_view
905 numberOfChildrenOfItem: o_item] > 0 )
906 //is a node and not an item
908 if( p_playlist->status.i_status != PLAYLIST_STOPPED &&
909 [self isItem: p_playlist->status.p_item inNode:
910 ((playlist_item_t *)[o_item pointerValue])
911 checkItemExistence: NO] == YES )
913 // if current item is in selected node and is playing then stop playlist
914 playlist_Stop( p_playlist );
916 vlc_mutex_lock( &p_playlist->object_lock );
917 playlist_NodeDelete( p_playlist, p_item, VLC_TRUE, VLC_FALSE );
918 vlc_mutex_unlock( &p_playlist->object_lock );
922 if( p_playlist->status.i_status != PLAYLIST_STOPPED &&
923 p_playlist->status.p_item == [[o_outline_view itemAtRow: i_row] pointerValue] )
925 playlist_Stop( p_playlist );
927 vlc_mutex_lock( &p_playlist->object_lock );
928 playlist_Delete( p_playlist, p_item->input.i_id );
929 vlc_mutex_unlock( &p_playlist->object_lock );
932 [self playlistUpdated];
933 vlc_object_release( p_playlist );
936 - (IBAction)sortNodeByName:(id)sender
938 [self sortNode: SORT_TITLE];
941 - (IBAction)sortNodeByAuthor:(id)sender
943 [self sortNode: SORT_AUTHOR];
946 - (void)sortNode:(int)i_mode
948 playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
950 playlist_item_t * p_item;
952 if (p_playlist == NULL)
957 if( [o_outline_view selectedRow] > -1 )
959 p_item = [[o_outline_view itemAtRow: [o_outline_view selectedRow]]
963 /*If no item is selected, sort the whole playlist*/
965 playlist_view_t * p_view = playlist_ViewFind( p_playlist, i_current_view );
966 p_item = p_view->p_root;
969 if( p_item->i_children > -1 ) // the item is a node
971 vlc_mutex_lock( &p_playlist->object_lock );
972 playlist_RecursiveNodeSort( p_playlist, p_item, i_mode, ORDER_NORMAL );
973 vlc_mutex_unlock( &p_playlist->object_lock );
979 for( i = 0 ; i < p_item->i_parents ; i++ )
981 if( p_item->pp_parents[i]->i_view == i_current_view )
983 vlc_mutex_lock( &p_playlist->object_lock );
984 playlist_RecursiveNodeSort( p_playlist,
985 p_item->pp_parents[i]->p_parent, i_mode, ORDER_NORMAL );
986 vlc_mutex_unlock( &p_playlist->object_lock );
991 vlc_object_release( p_playlist );
992 [self playlistUpdated];
995 - (playlist_item_t *)createItem:(NSDictionary *)o_one_item
997 intf_thread_t * p_intf = VLCIntf;
998 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1001 if( p_playlist == NULL )
1005 playlist_item_t *p_item;
1007 BOOL b_rem = FALSE, b_dir = FALSE;
1008 NSString *o_uri, *o_name;
1013 o_uri = (NSString *)[o_one_item objectForKey: @"ITEM_URL"];
1014 o_name = (NSString *)[o_one_item objectForKey: @"ITEM_NAME"];
1015 o_options = (NSArray *)[o_one_item objectForKey: @"ITEM_OPTIONS"];
1017 /* Find the name for a disc entry ( i know, can you believe the trouble?) */
1018 if( ( !o_name || [o_name isEqualToString:@""] ) && [o_uri rangeOfString: @"/dev/"].location != NSNotFound )
1020 int i_count, i_index;
1021 struct statfs *mounts = NULL;
1023 i_count = getmntinfo (&mounts, MNT_NOWAIT);
1024 /* getmntinfo returns a pointer to static data. Do not free. */
1025 for( i_index = 0 ; i_index < i_count; i_index++ )
1027 NSMutableString *o_temp, *o_temp2;
1028 o_temp = [NSMutableString stringWithString: o_uri];
1029 o_temp2 = [NSMutableString stringWithCString: mounts[i_index].f_mntfromname];
1030 [o_temp replaceOccurrencesOfString: @"/dev/rdisk" withString: @"/dev/disk" options:nil range:NSMakeRange(0, [o_temp length]) ];
1031 [o_temp2 replaceOccurrencesOfString: @"s0" withString: @"" options:nil range:NSMakeRange(0, [o_temp2 length]) ];
1032 [o_temp2 replaceOccurrencesOfString: @"s1" withString: @"" options:nil range:NSMakeRange(0, [o_temp2 length]) ];
1034 if( strstr( [o_temp fileSystemRepresentation], [o_temp2 fileSystemRepresentation] ) != NULL )
1036 o_name = [[NSFileManager defaultManager] displayNameAtPath: [NSString stringWithCString:mounts[i_index].f_mntonname]];
1040 /* If no name, then make a guess */
1041 if( !o_name) o_name = [[NSFileManager defaultManager] displayNameAtPath: o_uri];
1043 if( [[NSFileManager defaultManager] fileExistsAtPath:o_uri isDirectory:&b_dir] && b_dir &&
1044 [[NSWorkspace sharedWorkspace] getFileSystemInfoForPath: o_uri isRemovable: &b_rem
1045 isWritable:NULL isUnmountable:NULL description:NULL type:NULL] && b_rem )
1047 /* All of this is to make sure CD's play when you D&D them on VLC */
1048 /* Converts mountpoint to a /dev file */
1051 NSMutableString *o_temp;
1053 buf = (struct statfs *) malloc (sizeof(struct statfs));
1054 statfs( [o_uri fileSystemRepresentation], buf );
1055 psz_dev = strdup(buf->f_mntfromname);
1056 o_temp = [NSMutableString stringWithCString: psz_dev ];
1057 [o_temp replaceOccurrencesOfString: @"/dev/disk" withString: @"/dev/rdisk" options:nil range:NSMakeRange(0, [o_temp length]) ];
1058 [o_temp replaceOccurrencesOfString: @"s0" withString: @"" options:nil range:NSMakeRange(0, [o_temp length]) ];
1059 [o_temp replaceOccurrencesOfString: @"s1" withString: @"" options:nil range:NSMakeRange(0, [o_temp length]) ];
1063 p_item = playlist_ItemNew( p_intf, [o_uri fileSystemRepresentation], [o_name UTF8String] );
1069 for( i = 0; i < (int)[o_options count]; i++ )
1071 playlist_ItemAddOption( p_item, strdup( [[o_options objectAtIndex:i] UTF8String] ) );
1075 /* Recent documents menu */
1076 o_true_file = [NSURL fileURLWithPath: o_uri];
1077 if( o_true_file != nil )
1079 [[NSDocumentController sharedDocumentController]
1080 noteNewRecentDocumentURL: o_true_file];
1083 vlc_object_release( p_playlist );
1087 - (void)appendArray:(NSArray*)o_array atPos:(int)i_position enqueue:(BOOL)b_enqueue
1090 playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
1092 if( p_playlist == NULL )
1097 for( i_item = 0; i_item < (int)[o_array count]; i_item++ )
1099 playlist_item_t *p_item;
1100 NSDictionary *o_one_item;
1103 o_one_item = [o_array objectAtIndex: i_item];
1104 p_item = [self createItem: o_one_item];
1111 playlist_AddItem( p_playlist, p_item, PLAYLIST_INSERT, i_position == -1 ? PLAYLIST_END : i_position + i_item );
1113 if( i_item == 0 && !b_enqueue )
1115 playlist_Control( p_playlist, PLAYLIST_ITEMPLAY, p_item );
1118 vlc_object_release( p_playlist );
1121 - (void)appendNodeArray:(NSArray*)o_array inNode:(playlist_item_t *)p_node atPos:(int)i_position inView:(int)i_view enqueue:(BOOL)b_enqueue
1124 playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
1126 if( p_playlist == NULL )
1131 for( i_item = 0; i_item < (int)[o_array count]; i_item++ )
1133 playlist_item_t *p_item;
1134 NSDictionary *o_one_item;
1137 o_one_item = [o_array objectAtIndex: i_item];
1138 p_item = [self createItem: o_one_item];
1145 playlist_NodeAddItem( p_playlist, p_item, i_view, p_node, PLAYLIST_INSERT, i_position + i_item );
1147 if( i_item == 0 && !b_enqueue )
1149 playlist_Control( p_playlist, PLAYLIST_ITEMPLAY, p_item );
1152 vlc_object_release( p_playlist );
1156 - (IBAction)handlePopUp:(id)sender
1159 intf_thread_t * p_intf = VLCIntf;
1160 vlc_value_t val1,val2;
1161 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1163 if( p_playlist == NULL )
1168 switch( [o_loop_popup indexOfSelectedItem] )
1173 var_Set( p_playlist, "loop", val1 );
1175 var_Set( p_playlist, "repeat", val1 );
1176 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat One" ) );
1181 var_Set( p_playlist, "repeat", val1 );
1183 var_Set( p_playlist, "loop", val1 );
1184 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat All" ) );
1188 var_Get( p_playlist, "repeat", &val1 );
1189 var_Get( p_playlist, "loop", &val2 );
1190 if( val1.b_bool || val2.b_bool )
1193 var_Set( p_playlist, "repeat", val1 );
1194 var_Set( p_playlist, "loop", val1 );
1195 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat Off" ) );
1199 vlc_object_release( p_playlist );
1200 [self playlistUpdated];
1203 - (NSMutableArray *)subSearchItem:(playlist_item_t *)p_item
1205 playlist_t *p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
1207 playlist_item_t *p_selected_item;
1208 int i_current, i_selected_row;
1213 i_selected_row = [o_outline_view selectedRow];
1214 if (i_selected_row < 0)
1217 p_selected_item = (playlist_item_t *)[[o_outline_view itemAtRow:
1218 i_selected_row] pointerValue];
1220 for( i_current = 0; i_current < p_item->i_children ; i_current++ )
1223 NSString *o_current_name, *o_current_author;
1225 vlc_mutex_lock( &p_playlist->object_lock );
1226 o_current_name = [NSString stringWithUTF8String:
1227 p_item->pp_children[i_current]->input.psz_name];
1228 psz_temp = vlc_input_item_GetInfo( &p_item->input ,
1229 _("Meta-information"),_("Artist") );
1230 o_current_author = [NSString stringWithUTF8String: psz_temp];
1232 vlc_mutex_unlock( &p_playlist->object_lock );
1234 if( p_selected_item == p_item->pp_children[i_current] &&
1235 b_selected_item_met == NO )
1237 b_selected_item_met = YES;
1239 else if( p_selected_item == p_item->pp_children[i_current] &&
1240 b_selected_item_met == YES )
1242 vlc_object_release( p_playlist );
1245 else if( b_selected_item_met == YES &&
1246 ( [o_current_name rangeOfString:[o_search_field
1247 stringValue] options:NSCaseInsensitiveSearch ].length ||
1248 [o_current_author rangeOfString:[o_search_field
1249 stringValue] options:NSCaseInsensitiveSearch ].length ) )
1251 vlc_object_release( p_playlist );
1252 /*Adds the parent items in the result array as well, so that we can
1254 return [NSMutableArray arrayWithObject: [NSValue
1255 valueWithPointer: p_item->pp_children[i_current]]];
1257 if( p_item->pp_children[i_current]->i_children > 0 )
1259 id o_result = [self subSearchItem:
1260 p_item->pp_children[i_current]];
1261 if( o_result != NULL )
1263 vlc_object_release( p_playlist );
1264 [o_result insertObject: [NSValue valueWithPointer:
1265 p_item->pp_children[i_current]] atIndex:0];
1270 vlc_object_release( p_playlist );
1274 - (IBAction)searchItem:(id)sender
1276 playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
1278 playlist_view_t * p_view;
1284 b_selected_item_met = NO;
1286 if( p_playlist == NULL )
1288 p_view = playlist_ViewFind( p_playlist, i_current_view );
1292 /*First, only search after the selected item:*
1293 *(b_selected_item_met = NO) */
1294 o_result = [self subSearchItem:p_view->p_root];
1295 if( o_result == NULL )
1297 /* If the first search failed, search again from the beginning */
1298 o_result = [self subSearchItem:p_view->p_root];
1300 if( o_result != NULL )
1303 if( [[o_result objectAtIndex: 0] pointerValue] ==
1304 p_playlist->p_general )
1309 for( i = i_start ; i < [o_result count] - 1 ; i++ )
1311 [o_outline_view expandItem: [o_outline_dict objectForKey:
1312 [NSString stringWithFormat: @"%p",
1313 [[o_result objectAtIndex: i] pointerValue]]]];
1315 i_row = [o_outline_view rowForItem: [o_outline_dict objectForKey:
1316 [NSString stringWithFormat: @"%p",
1317 [[o_result objectAtIndex: [o_result count] - 1 ]
1322 [o_outline_view selectRow:i_row byExtendingSelection: NO];
1323 [o_outline_view scrollRowToVisible: i_row];
1326 vlc_object_release( p_playlist );
1329 - (IBAction)recursiveExpandNode:(id)sender
1332 id o_item = [o_outline_view itemAtRow: [o_outline_view selectedRow]];
1333 playlist_item_t *p_item = (playlist_item_t *)[o_item pointerValue];
1335 if( ![[o_outline_view dataSource] outlineView: o_outline_view
1336 isItemExpandable: o_item] )
1338 for( i = 0 ; i < p_item->i_parents ; i++ )
1340 if( p_item->pp_parents[i]->i_view == i_current_view )
1342 o_item = [o_outline_dict objectForKey: [NSString
1343 stringWithFormat: @"%p", p_item->pp_parents[i]->p_parent]];
1349 /* We need to collapse the node first, since OSX refuses to recursively
1350 expand an already expanded node, even if children nodes are collapsed. */
1351 [o_outline_view collapseItem: o_item collapseChildren: YES];
1352 [o_outline_view expandItem: o_item expandChildren: YES];
1355 - (NSMenu *)menuForEvent:(NSEvent *)o_event
1359 vlc_bool_t b_item_sel;
1361 pt = [o_outline_view convertPoint: [o_event locationInWindow]
1363 b_item_sel = ( [o_outline_view rowAtPoint: pt] != -1 &&
1364 [o_outline_view selectedRow] != -1 );
1365 b_rows = [o_outline_view numberOfRows] != 0;
1367 [o_mi_play setEnabled: b_item_sel];
1368 [o_mi_delete setEnabled: b_item_sel];
1369 [o_mi_selectall setEnabled: b_rows];
1370 [o_mi_info setEnabled: b_item_sel];
1371 [o_mi_preparse setEnabled: b_item_sel];
1372 [o_mi_recursive_expand setEnabled: b_item_sel];
1373 [o_mi_sort_name setEnabled: b_item_sel];
1374 [o_mi_sort_author setEnabled: b_item_sel];
1376 return( o_ctx_menu );
1379 - (void)outlineView: (NSTableView*)o_tv
1380 didClickTableColumn:(NSTableColumn *)o_tc
1382 int i_mode = 0, i_type;
1383 intf_thread_t *p_intf = VLCIntf;
1384 playlist_view_t *p_view;
1386 playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1388 if( p_playlist == NULL )
1393 /* Check whether the selected table column header corresponds to a
1394 sortable table column*/
1395 if( !( o_tc == o_tc_name || o_tc == o_tc_author ) )
1397 vlc_object_release( p_playlist );
1401 p_view = playlist_ViewFind( p_playlist, i_current_view );
1403 if( o_tc_sortColumn == o_tc )
1405 b_isSortDescending = !b_isSortDescending;
1409 b_isSortDescending = VLC_FALSE;
1412 if( o_tc == o_tc_name )
1414 i_mode = SORT_TITLE;
1416 else if( o_tc == o_tc_author )
1418 i_mode = SORT_AUTHOR;
1421 if( b_isSortDescending )
1423 i_type = ORDER_REVERSE;
1427 i_type = ORDER_NORMAL;
1430 vlc_mutex_lock( &p_playlist->object_lock );
1431 playlist_RecursiveNodeSort( p_playlist, p_view->p_root, i_mode, i_type );
1432 vlc_mutex_unlock( &p_playlist->object_lock );
1434 vlc_object_release( p_playlist );
1435 [self playlistUpdated];
1437 o_tc_sortColumn = o_tc;
1438 [o_outline_view setHighlightedTableColumn:o_tc];
1440 if( b_isSortDescending )
1442 [o_outline_view setIndicatorImage:o_descendingSortingImage
1443 inTableColumn:o_tc];
1447 [o_outline_view setIndicatorImage:o_ascendingSortingImage
1448 inTableColumn:o_tc];
1453 - (void)outlineView:(NSOutlineView *)outlineView
1454 willDisplayCell:(id)cell
1455 forTableColumn:(NSTableColumn *)tableColumn
1458 playlist_t *p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
1463 if( !p_playlist ) return;
1465 o_playing_item = [o_outline_dict objectForKey:
1466 [NSString stringWithFormat:@"%p", p_playlist->status.p_item]];
1468 if( [self isItem: [o_playing_item pointerValue] inNode:
1469 [item pointerValue] checkItemExistence: YES]
1470 || [o_playing_item isEqual: item] )
1472 [cell setFont: [NSFont boldSystemFontOfSize: 0]];
1476 [cell setFont: [NSFont systemFontOfSize: 0]];
1478 vlc_object_release( p_playlist );
1481 - (IBAction)addNode:(id)sender
1483 /* simply adds a new node to the end of the playlist */
1484 playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
1491 playlist_item_t * p_item = playlist_NodeCreate( p_playlist, VIEW_CATEGORY,
1492 _("Empty Folder"), p_playlist->p_general );
1495 msg_Warn( VLCIntf, "node creation failed" );
1497 playlist_ViewUpdate( p_playlist, VIEW_CATEGORY );
1499 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]]];
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_general 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_general
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_general;
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 = [self parentOfItem: p_item];
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 ) ==
1703 playlist_NodeRemoveParent( p_playlist, p_item, p_old_parent ) ==
1707 /* Calculate the new index */
1710 /* If we move the item in the same node, we need to take into
1711 account that one item will be deleted */
1714 if ((p_new_parent == p_old_parent &&
1715 i_old_index < index + (int)i) )
1717 i_removed_from_node++;
1719 i_new_index = index + i - i_removed_from_node;
1721 // Reattach the item to the new position
1722 playlist_NodeInsert( p_playlist, i_current_view, p_item,
1723 p_new_parent, i_new_index );
1725 vlc_mutex_unlock( &p_playlist->object_lock );
1727 [self playlistUpdated];
1728 i_row = [o_outline_view rowForItem:[o_outline_dict
1729 objectForKey:[NSString stringWithFormat: @"%p",
1730 [[o_all_items objectAtIndex: 0] pointerValue]]]];
1734 i_row = [o_outline_view rowForItem:[o_outline_dict
1735 objectForKey:[NSString stringWithFormat: @"%p", p_new_parent]]];
1738 [o_outline_view deselectAll: self];
1739 [o_outline_view selectRow: i_row byExtendingSelection: NO];
1740 [o_outline_view scrollRowToVisible: i_row];
1742 vlc_object_release(p_playlist);
1746 else if( [[o_pasteboard types] containsObject: NSFilenamesPboardType] )
1749 playlist_item_t *p_node = [item pointerValue];
1751 NSArray *o_array = [NSArray array];
1752 NSArray *o_values = [[o_pasteboard propertyListForType:
1753 NSFilenamesPboardType]
1754 sortedArrayUsingSelector:
1755 @selector(caseInsensitiveCompare:)];
1757 for( i = 0; i < (int)[o_values count]; i++)
1759 NSDictionary *o_dic;
1760 o_dic = [NSDictionary dictionaryWithObject:[o_values
1761 objectAtIndex:i] forKey:@"ITEM_URL"];
1762 o_array = [o_array arrayByAddingObject: o_dic];
1767 [self appendArray: o_array atPos: index enqueue: YES];
1769 /* This should never occur */
1770 else if( p_node->i_children == -1 )
1772 vlc_object_release( p_playlist );
1777 [self appendNodeArray: o_array inNode: p_node
1778 atPos: index inView: i_current_view enqueue: YES];
1780 vlc_object_release( p_playlist );
1783 vlc_object_release( p_playlist );
1787 /* Delegate method of NSWindow */
1788 /*- (void)windowWillClose:(NSNotification *)aNotification
1790 [o_btn_playlist setState: NSOffState];