]> git.sesse.net Git - vlc/blob - modules/gui/macosx/playlist.m
Much cleaner fix for the "vlc would crash on item deletion" bug.
[vlc] / modules / gui / macosx / playlist.m
1 /*****************************************************************************
2  * playlist.m: MacOS X interface module
3  *****************************************************************************
4 * Copyright (C) 2002-2005 VideoLAN
5  * $Id$
6  *
7  * Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
8  *          Derk-Jan Hartman <hartman at videolan dot org>
9  *          Benjamin Pracht <bigben at videolab dot org>
10  *
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.
15  *
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.
20  *
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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
24  *****************************************************************************/
25
26 /* TODO
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
34  */
35
36
37 /*****************************************************************************
38  * Preamble
39  *****************************************************************************/
40 #include <stdlib.h>                                      /* malloc(), free() */
41 #include <sys/param.h>                                    /* for MAXPATHLEN */
42 #include <string.h>
43 #include <math.h>
44 #include <sys/mount.h>
45 #include <vlc_keys.h>
46
47 #include "intf.h"
48 #include "playlist.h"
49 #include "controls.h"
50 #include "osd.h"
51 #include "misc.h"
52
53 /*****************************************************************************
54  * VLCPlaylistView implementation 
55  *****************************************************************************/
56 @implementation VLCPlaylistView
57
58 - (NSMenu *)menuForEvent:(NSEvent *)o_event
59 {
60     return( [[self delegate] menuForEvent: o_event] );
61 }
62
63 - (void)keyDown:(NSEvent *)o_event
64 {
65     unichar key = 0;
66
67     if( [[o_event characters] length] )
68     {
69         key = [[o_event characters] characterAtIndex: 0];
70     }
71
72     switch( key )
73     {
74         case NSDeleteCharacter:
75         case NSDeleteFunctionKey:
76         case NSDeleteCharFunctionKey:
77         case NSBackspaceCharacter:
78             [[self delegate] deleteItem:self];
79             break;
80
81         case NSEnterCharacter:
82         case NSCarriageReturnCharacter:
83             [(VLCPlaylist *)[[VLCMain sharedInstance] getPlaylist]
84                                                             playItem:self];
85             break;
86
87         default:
88             [super keyDown: o_event];
89             break;
90     }
91 }
92
93 @end
94
95 /*****************************************************************************
96  * VLCPlaylist implementation 
97  *****************************************************************************/
98 @implementation VLCPlaylist
99
100 - (id)init
101 {
102     self = [super init];
103     if ( self != nil )
104     {
105         o_outline_dict = [[NSMutableDictionary alloc] init];
106         //i_moveRow = -1;
107     }
108     return self;
109 }
110
111 - (void)awakeFromNib
112 {
113     playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
114                                           FIND_ANYWHERE );
115     vlc_list_t *p_list = vlc_list_find( p_playlist, VLC_OBJECT_MODULE,
116                                         FIND_ANYWHERE );
117
118     int i_index;
119     i_current_view = VIEW_CATEGORY;
120     playlist_ViewUpdate( p_playlist, i_current_view );
121
122     [o_outline_view setTarget: self];
123     [o_outline_view setDelegate: self];
124     [o_outline_view setDataSource: self];
125
126     [o_outline_view setDoubleAction: @selector(playItem:)];
127
128     [o_outline_view registerForDraggedTypes:
129         [NSArray arrayWithObjects: NSFilenamesPboardType, nil]];
130     [o_outline_view setIntercellSpacing: NSMakeSize (0.0, 1.0)];
131
132 /* We need to check whether _defaultTableHeaderSortImage exists, since it 
133 belongs to an Apple hidden private API, and then can "disapear" at any time*/
134
135     if( [[NSOutlineView class] respondsToSelector:@selector(_defaultTableHeaderSortImage)] )
136     {
137         o_ascendingSortingImage = [[NSOutlineView class] _defaultTableHeaderSortImage];
138     }
139     else
140     {
141         o_ascendingSortingImage = nil;
142     }
143
144     if( [[NSOutlineView class] respondsToSelector:@selector(_defaultTableHeaderReverseSortImage)] )
145     {
146         o_descendingSortingImage = [[NSOutlineView class] _defaultTableHeaderReverseSortImage];
147     }
148     else
149     {
150         o_descendingSortingImage = nil;
151     }
152
153     o_tc_sortColumn = nil;
154
155     for( i_index = 0; i_index < p_list->i_count; i_index++ )
156     {
157         NSMenuItem * o_lmi;
158         module_t * p_parser = (module_t *)p_list->p_values[i_index].p_object ;
159
160         if( !strcmp( p_parser->psz_capability, "services_discovery" ) )
161         {
162             /* create the menu entries used in the playlist menu */
163             o_lmi = [[o_mi_services submenu] addItemWithTitle:
164                      [NSString stringWithUTF8String:
165                      p_parser->psz_longname ? p_parser->psz_longname :
166                      ( p_parser->psz_shortname ? p_parser->psz_shortname:
167                      p_parser->psz_object_name)]
168                                              action: @selector(servicesChange:)
169                                              keyEquivalent: @""];
170             [o_lmi setTarget: self];
171             [o_lmi setRepresentedObject:
172                    [NSString stringWithCString: p_parser->psz_object_name]];
173             if( playlist_IsServicesDiscoveryLoaded( p_playlist,
174                     p_parser->psz_object_name ) )
175                 [o_lmi setState: NSOnState];
176                 
177             /* create the menu entries for the main menu */
178             o_lmi = [[o_mm_mi_services submenu] addItemWithTitle:
179                      [NSString stringWithUTF8String:
180                      p_parser->psz_longname ? p_parser->psz_longname :
181                      ( p_parser->psz_shortname ? p_parser->psz_shortname:
182                      p_parser->psz_object_name)]
183                                              action: @selector(servicesChange:)
184                                              keyEquivalent: @""];
185             [o_lmi setTarget: self];
186             [o_lmi setRepresentedObject:
187                    [NSString stringWithCString: p_parser->psz_object_name]];
188             if( playlist_IsServicesDiscoveryLoaded( p_playlist,
189                     p_parser->psz_object_name ) )
190                 [o_lmi setState: NSOnState];
191         }
192     }
193     vlc_list_release( p_list );
194     vlc_object_release( p_playlist );
195
196     /* Change the simple textfield into a searchField if we can... */
197 #if 0
198     if( MACOS_VERSION >= 10.3 )
199     {
200         NSView *o_parentview = [o_status_field superview];
201         NSSearchField *o_better_search_field = [[NSSearchField alloc]initWithFrame:[o_search_field frame]];
202         [o_better_search_field setRecentsAutosaveName:@"VLC media player search"];
203         [o_better_search_field setDelegate:self];
204         [[NSNotificationCenter defaultCenter] addObserver: self
205             selector: @selector(searchfieldChanged:)
206             name: NSControlTextDidChangeNotification
207             object: o_better_search_field];
208
209         [o_better_search_field setTarget:self];
210         [o_better_search_field setAction:@selector(searchItem:)];
211
212         [o_better_search_field setAutoresizingMask:NSViewMinXMargin];
213         [o_parentview addSubview:o_better_search_field];
214         [o_search_field setHidden:YES];
215     }
216 #endif
217     [self initStrings];
218     //[self playlistUpdated];
219 }
220
221 - (void)searchfieldChanged:(NSNotification *)o_notification
222 {
223     [o_search_field setStringValue:[[o_notification object] stringValue]];
224 }
225
226 - (void)initStrings
227 {
228     [o_mi_save_playlist setTitle: _NS("Save Playlist...")];
229     [o_mi_play setTitle: _NS("Play")];
230     [o_mi_delete setTitle: _NS("Delete")];
231     [o_mi_selectall setTitle: _NS("Select All")];
232     [o_mi_info setTitle: _NS("Properties")];
233     [o_mi_sort_name setTitle: _NS("Sort Node by Name")];
234     [o_mi_sort_author setTitle: _NS("Sort Node by Author")];
235     [o_mi_services setTitle: _NS("Services discovery")];
236     [[o_tc_name headerCell] setStringValue:_NS("Name")];
237     [[o_tc_author headerCell] setStringValue:_NS("Author")];
238     [[o_tc_duration headerCell] setStringValue:_NS("Duration")];
239     [o_status_field setStringValue: [NSString stringWithFormat:
240                         _NS("no items in playlist")]];
241
242     [o_random_ckb setTitle: _NS("Random")];
243 #if 0
244     [o_search_button setTitle: _NS("Search")];
245 #endif
246     [o_search_field setToolTip: _NS("Search in Playlist")];
247     [[o_loop_popup itemAtIndex:0] setTitle: _NS("Standard Play")];
248     [[o_loop_popup itemAtIndex:1] setTitle: _NS("Repeat One")];
249     [[o_loop_popup itemAtIndex:2] setTitle: _NS("Repeat All")];
250 }
251
252 - (NSOutlineView *)outlineView
253 {
254     return o_outline_view;
255 }
256
257 - (void)playlistUpdated
258 {
259     unsigned int i;
260
261     /* Clear indications of any existing column sorting*/
262     for( i = 0 ; i < [[o_outline_view tableColumns] count] ; i++ )
263     {
264         [o_outline_view setIndicatorImage:nil inTableColumn:
265                             [[o_outline_view tableColumns] objectAtIndex:i]];
266     }
267
268     [o_outline_view setHighlightedTableColumn:nil];
269     o_tc_sortColumn = nil;
270     // TODO Find a way to keep the dict size to a minimum
271     //[o_outline_dict removeAllObjects];
272     [o_outline_view reloadData];
273 }
274
275 - (void)playModeUpdated
276 {
277     playlist_t *p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
278                                           FIND_ANYWHERE );
279     vlc_value_t val, val2;
280
281     if( p_playlist == NULL )
282     {
283         return;
284     }
285
286     var_Get( p_playlist, "loop", &val2 );
287     var_Get( p_playlist, "repeat", &val );
288     if( val.b_bool == VLC_TRUE )
289     {
290         [o_loop_popup selectItemAtIndex: 1];
291    }
292     else if( val2.b_bool == VLC_TRUE )
293     {
294         [o_loop_popup selectItemAtIndex: 2];
295     }
296     else
297     {
298         [o_loop_popup selectItemAtIndex: 0];
299     }
300
301     var_Get( p_playlist, "random", &val );
302     [o_random_ckb setState: val.b_bool];
303
304     vlc_object_release( p_playlist );
305 }
306
307 - (void)updateRowSelection
308 {
309     int i,i_row;
310     unsigned int j;
311
312     playlist_t *p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
313                                           FIND_ANYWHERE );
314     playlist_item_t *p_item, *p_temp_item;
315     NSMutableArray *o_array = [NSMutableArray array];
316
317     if( p_playlist == NULL )
318         return;
319
320     p_item = p_playlist->status.p_item;
321     if( p_item == NULL ) return;
322
323     p_temp_item = p_item;
324     while( p_temp_item->i_parents > 0 )
325     {
326         [o_array insertObject: [NSValue valueWithPointer: p_temp_item] atIndex: 0];
327         for (i = 0 ; i < p_temp_item->i_parents ; i++)
328         {
329             if( p_temp_item->pp_parents[i]->i_view == i_current_view )
330             {
331                 p_temp_item = p_temp_item->pp_parents[i]->p_parent;
332                 break;
333             }
334         }
335     }
336
337     for (j = 0 ; j < [o_array count] - 1 ; j++)
338     {
339         id o_item;
340         if( ( o_item = [o_outline_dict objectForKey:
341                             [NSString stringWithFormat: @"%p",
342                             [[o_array objectAtIndex:j] pointerValue]]] ) != nil )
343             [o_outline_view expandItem: o_item];
344
345     }
346
347     i_row = [o_outline_view rowForItem:[o_outline_dict
348             objectForKey:[NSString stringWithFormat: @"%p", p_item]]];
349
350     [o_outline_view selectRow: i_row byExtendingSelection: NO];
351     [o_outline_view scrollRowToVisible: i_row];
352
353     vlc_object_release(p_playlist);
354 }
355
356 - (BOOL)isValueItem: (id)o_item inNode: (id)o_node
357 {
358     int i;
359     int i_total = [[o_outline_view dataSource] outlineView:o_outline_view
360                                         numberOfChildrenOfItem: o_node];
361     for( i = 0 ; i < i_total ; i++ )
362     {
363         id o_temp_item = [[o_outline_view dataSource] outlineView:
364                                     o_outline_view child:i ofItem: o_node];
365         if( [[o_outline_view dataSource] outlineView:o_outline_view
366                                     numberOfChildrenOfItem: o_temp_item] > 0 )
367         {
368             if( [self isValueItem: o_item inNode: o_temp_item] == YES )
369             return YES;
370         }
371         else if( [o_temp_item isEqual: o_item] )
372         {
373             return YES;
374         }
375     }
376     return NO;
377 }
378
379 - (IBAction)savePlaylist:(id)sender
380 {
381     intf_thread_t * p_intf = VLCIntf;
382     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
383                                                        FIND_ANYWHERE );
384
385     NSSavePanel *o_save_panel = [NSSavePanel savePanel];
386     NSString * o_name = [NSString stringWithFormat: @"%@.m3u", _NS("Untitled")];
387     [o_save_panel setTitle: _NS("Save Playlist")];
388     [o_save_panel setPrompt: _NS("Save")];
389
390     if( [o_save_panel runModalForDirectory: nil
391             file: o_name] == NSOKButton )
392     {
393         playlist_Export( p_playlist, [[o_save_panel filename] fileSystemRepresentation], "export-m3u" );
394     }
395 }
396
397
398 /* When called retrieves the selected outlineview row and plays that node or item */
399 - (IBAction)playItem:(id)sender
400 {
401     intf_thread_t * p_intf = VLCIntf;
402     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
403                                                        FIND_ANYWHERE );
404
405     if( p_playlist != NULL )
406     {
407         playlist_item_t *p_item;
408         playlist_item_t *p_node = NULL;
409         int i;
410
411         p_item = [[o_outline_view itemAtRow:[o_outline_view selectedRow]] pointerValue];
412
413         if( p_item )
414         {
415             if( p_item->i_children == -1 )
416             {
417                 for( i = 0 ; i < p_item->i_parents ; i++ )
418                 {
419                     if( p_item->pp_parents[i]->i_view == i_current_view )
420                     {
421                         p_node = p_item->pp_parents[i]->p_parent;
422                     }
423                 }
424             }
425             else
426             {
427                 p_node = p_item;
428                 if( p_node->i_children > 0 && p_node->pp_children[0]->i_children == -1 )
429                 {
430                     p_item = p_node->pp_children[0];
431                 }
432                 else
433                 {
434                     p_item = NULL;
435                 }
436             }
437             playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, i_current_view, p_node, p_item );
438         }
439         vlc_object_release( p_playlist );
440     }
441 }
442
443 - (IBAction)servicesChange:(id)sender
444 {
445     NSMenuItem *o_mi = (NSMenuItem *)sender;
446     NSString *o_string = [o_mi representedObject];
447     playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
448                                           FIND_ANYWHERE );
449     if( !playlist_IsServicesDiscoveryLoaded( p_playlist, [o_string cString] ) )
450         playlist_ServicesDiscoveryAdd( p_playlist, [o_string cString] );
451     else
452         playlist_ServicesDiscoveryRemove( p_playlist, [o_string cString] );
453
454     [o_mi setState: playlist_IsServicesDiscoveryLoaded( p_playlist,
455                                           [o_string cString] ) ? YES : NO];
456
457     i_current_view = VIEW_CATEGORY;
458     playlist_ViewUpdate( p_playlist, i_current_view );
459     vlc_object_release( p_playlist );
460     [self playlistUpdated];
461     return;
462 }
463
464 - (IBAction)selectAll:(id)sender
465 {
466     [o_outline_view selectAll: nil];
467 }
468
469 - (IBAction)deleteItem:(id)sender
470 {
471     int i, i_count, i_row;
472     NSMutableArray *o_to_delete;
473     NSNumber *o_number;
474
475     playlist_t * p_playlist;
476     intf_thread_t * p_intf = VLCIntf;
477
478     p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
479                                           FIND_ANYWHERE );
480
481     if ( p_playlist == NULL )
482     {
483         return;
484     }
485     o_to_delete = [NSMutableArray arrayWithArray:[[o_outline_view selectedRowEnumerator] allObjects]];
486     i_count = [o_to_delete count];
487
488     for( i = 0; i < i_count; i++ )
489     {
490         o_number = [o_to_delete lastObject];
491         i_row = [o_number intValue];
492         id o_item = [o_outline_view itemAtRow: i_row];
493         playlist_item_t *p_item = [o_item pointerValue];
494         [o_to_delete removeObject: o_number];
495         [o_outline_view deselectRow: i_row];
496
497         if( [[o_outline_view dataSource] outlineView:o_outline_view
498                                         numberOfChildrenOfItem: o_item]  > 0 )
499         //is a node and not an item
500         {
501             id o_playing_item = [o_outline_dict objectForKey:
502                 [NSString stringWithFormat: @"%p", p_playlist->status.p_item]];
503             if( p_playlist->status.i_status != PLAYLIST_STOPPED &&
504                 [self isValueItem: o_playing_item inNode: o_item] == YES )
505             {
506                 // if current item is in selected node and is playing then stop playlist
507                 playlist_Stop( p_playlist );
508             }
509             vlc_mutex_lock( &p_playlist->object_lock );
510             playlist_NodeDelete( p_playlist, p_item, VLC_TRUE, VLC_FALSE );
511             vlc_mutex_unlock( &p_playlist->object_lock );
512         }
513         else
514         {
515             if( p_playlist->status.i_status != PLAYLIST_STOPPED &&
516                 p_playlist->status.p_item == [[o_outline_view itemAtRow: i_row] pointerValue] )
517             {
518                 playlist_Stop( p_playlist );
519             }
520             vlc_mutex_lock( &p_playlist->object_lock );
521             playlist_Delete( p_playlist, p_item->input.i_id );
522             vlc_mutex_unlock( &p_playlist->object_lock );
523         }
524     }
525     [self playlistUpdated];
526     vlc_object_release( p_playlist );
527 }
528
529 - (IBAction)sortNodeByName:(id)sender
530 {
531     [self sortNode: SORT_TITLE];
532 }
533
534 - (IBAction)sortNodeByAuthor:(id)sender
535 {
536     [self sortNode: SORT_AUTHOR];
537 }
538
539 - (void)sortNode:(int)i_mode
540 {
541     playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
542                                           FIND_ANYWHERE );
543     playlist_item_t * p_item;
544
545     if (p_playlist == NULL)
546     {
547         return;
548     }
549
550     if( [o_outline_view selectedRow] > -1 )
551     {
552         p_item = [[o_outline_view itemAtRow: [o_outline_view selectedRow]]
553                                                                 pointerValue];
554     }
555     else
556     /*If no item is selected, sort the whole playlist*/
557     {
558         playlist_view_t * p_view = playlist_ViewFind( p_playlist, i_current_view );
559         p_item = p_view->p_root;
560     }
561
562     if( p_item->i_children > -1 ) // the item is a node
563     {
564         vlc_mutex_lock( &p_playlist->object_lock );
565         playlist_RecursiveNodeSort( p_playlist, p_item, i_mode, ORDER_NORMAL );
566         vlc_mutex_unlock( &p_playlist->object_lock );
567     }
568     else
569     {
570         int i;
571
572         for( i = 0 ; i < p_item->i_parents ; i++ )
573         {
574             if( p_item->pp_parents[i]->i_view == i_current_view )
575             {
576                 vlc_mutex_lock( &p_playlist->object_lock );
577                 playlist_RecursiveNodeSort( p_playlist,
578                         p_item->pp_parents[i]->p_parent, i_mode, ORDER_NORMAL );
579                 vlc_mutex_unlock( &p_playlist->object_lock );
580                 break;
581             }
582         }
583     }
584     vlc_object_release( p_playlist );
585     [self playlistUpdated];
586 }
587
588 - (playlist_item_t *)createItem:(NSDictionary *)o_one_item
589 {
590     intf_thread_t * p_intf = VLCIntf;
591     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
592                                                        FIND_ANYWHERE );
593
594     if( p_playlist == NULL )
595     {
596         return NULL;
597     }
598     playlist_item_t *p_item;
599     int i;
600     BOOL b_rem = FALSE, b_dir = FALSE;
601     NSString *o_uri, *o_name;
602     NSArray *o_options;
603     NSURL *o_true_file;
604
605     /* Get the item */
606     o_uri = (NSString *)[o_one_item objectForKey: @"ITEM_URL"];
607     o_name = (NSString *)[o_one_item objectForKey: @"ITEM_NAME"];
608     o_options = (NSArray *)[o_one_item objectForKey: @"ITEM_OPTIONS"];
609
610     /* Find the name for a disc entry ( i know, can you believe the trouble?) */
611     if( ( !o_name || [o_name isEqualToString:@""] ) && [o_uri rangeOfString: @"/dev/"].location != NSNotFound )
612     {
613         int i_count, i_index;
614         struct statfs *mounts = NULL;
615
616         i_count = getmntinfo (&mounts, MNT_NOWAIT);
617         /* getmntinfo returns a pointer to static data. Do not free. */
618         for( i_index = 0 ; i_index < i_count; i_index++ )
619         {
620             NSMutableString *o_temp, *o_temp2;
621             o_temp = [NSMutableString stringWithString: o_uri];
622             o_temp2 = [NSMutableString stringWithCString: mounts[i_index].f_mntfromname];
623             [o_temp replaceOccurrencesOfString: @"/dev/rdisk" withString: @"/dev/disk" options:NULL range:NSMakeRange(0, [o_temp length]) ];
624             [o_temp2 replaceOccurrencesOfString: @"s0" withString: @"" options:NULL range:NSMakeRange(0, [o_temp2 length]) ];
625             [o_temp2 replaceOccurrencesOfString: @"s1" withString: @"" options:NULL range:NSMakeRange(0, [o_temp2 length]) ];
626
627             if( strstr( [o_temp fileSystemRepresentation], [o_temp2 fileSystemRepresentation] ) != NULL )
628             {
629                 o_name = [[NSFileManager defaultManager] displayNameAtPath: [NSString stringWithCString:mounts[i_index].f_mntonname]];
630             }
631         }
632     }
633     /* If no name, then make a guess */
634     if( !o_name) o_name = [[NSFileManager defaultManager] displayNameAtPath: o_uri];
635
636     if( [[NSFileManager defaultManager] fileExistsAtPath:o_uri isDirectory:&b_dir] && b_dir &&
637         [[NSWorkspace sharedWorkspace] getFileSystemInfoForPath: o_uri isRemovable: &b_rem
638                 isWritable:NULL isUnmountable:NULL description:NULL type:NULL] && b_rem   )
639     {
640         /* All of this is to make sure CD's play when you D&D them on VLC */
641         /* Converts mountpoint to a /dev file */
642         struct statfs *buf;
643         char *psz_dev;
644         NSMutableString *o_temp;
645
646         buf = (struct statfs *) malloc (sizeof(struct statfs));
647         statfs( [o_uri fileSystemRepresentation], buf );
648         psz_dev = strdup(buf->f_mntfromname);
649         o_temp = [NSMutableString stringWithCString: psz_dev ];
650         [o_temp replaceOccurrencesOfString: @"/dev/disk" withString: @"/dev/rdisk" options:NULL range:NSMakeRange(0, [o_temp length]) ];
651         [o_temp replaceOccurrencesOfString: @"s0" withString: @"" options:NULL range:NSMakeRange(0, [o_temp length]) ];
652         [o_temp replaceOccurrencesOfString: @"s1" withString: @"" options:NULL range:NSMakeRange(0, [o_temp length]) ];
653         o_uri = o_temp;
654     }
655
656     p_item = playlist_ItemNew( p_intf, [o_uri fileSystemRepresentation], [o_name UTF8String] );
657     if( !p_item )
658        return NULL;
659
660     if( o_options )
661     {
662         for( i = 0; i < (int)[o_options count]; i++ )
663         {
664             playlist_ItemAddOption( p_item, strdup( [[o_options objectAtIndex:i] UTF8String] ) );
665         }
666     }
667
668     /* Recent documents menu */
669     o_true_file = [NSURL fileURLWithPath: o_uri];
670     if( o_true_file != nil )
671     {
672         [[NSDocumentController sharedDocumentController]
673             noteNewRecentDocumentURL: o_true_file];
674     }
675
676     vlc_object_release( p_playlist );
677     return p_item;
678 }
679
680 - (void)appendArray:(NSArray*)o_array atPos:(int)i_position enqueue:(BOOL)b_enqueue
681 {
682     int i_item;
683     playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
684                                             FIND_ANYWHERE );
685     if( p_playlist == NULL )
686     {
687         return;
688     }
689
690     for( i_item = 0; i_item < (int)[o_array count]; i_item++ )
691     {
692         playlist_item_t *p_item;
693         NSDictionary *o_one_item;
694
695         /* Get the item */
696         o_one_item = [o_array objectAtIndex: i_item];
697         p_item = [self createItem: o_one_item];
698         if( !p_item )
699         {
700             continue;
701         }
702
703         /* Add the item */
704         playlist_AddItem( p_playlist, p_item, PLAYLIST_APPEND, i_position == -1 ? PLAYLIST_END : i_position + i_item );
705
706         if( i_item == 0 && !b_enqueue )
707         {
708             playlist_Control( p_playlist, PLAYLIST_ITEMPLAY, p_item );
709         }
710     }
711     vlc_object_release( p_playlist );
712 }
713
714 - (void)appendNodeArray:(NSArray*)o_array inNode:(playlist_item_t *)p_node atPos:(int)i_position inView:(int)i_view enqueue:(BOOL)b_enqueue
715 {
716     int i_item;
717     playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
718                                             FIND_ANYWHERE );
719     if( p_playlist == NULL )
720     {
721         return;
722     }
723
724     for( i_item = 0; i_item < (int)[o_array count]; i_item++ )
725     {
726         playlist_item_t *p_item;
727         NSDictionary *o_one_item;
728
729         /* Get the item */
730         o_one_item = [o_array objectAtIndex: i_item];
731         p_item = [self createItem: o_one_item];
732         if( !p_item )
733         {
734             continue;
735         }
736
737         /* Add the item */
738         playlist_NodeAddItem( p_playlist, p_item, i_view, p_node, PLAYLIST_APPEND, i_position + i_item );
739
740         if( i_item == 0 && !b_enqueue )
741         {
742             playlist_Control( p_playlist, PLAYLIST_ITEMPLAY, p_item );
743         }
744     }
745     vlc_object_release( p_playlist );
746
747 }
748
749 - (IBAction)handlePopUp:(id)sender
750
751 {
752     intf_thread_t * p_intf = VLCIntf;
753     vlc_value_t val1,val2;
754     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
755                                             FIND_ANYWHERE );
756     if( p_playlist == NULL )
757     {
758         return;
759     }
760
761     switch( [o_loop_popup indexOfSelectedItem] )
762     {
763         case 1:
764
765              val1.b_bool = 0;
766              var_Set( p_playlist, "loop", val1 );
767              val1.b_bool = 1;
768              var_Set( p_playlist, "repeat", val1 );
769              vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat One" ) );
770         break;
771
772         case 2:
773              val1.b_bool = 0;
774              var_Set( p_playlist, "repeat", val1 );
775              val1.b_bool = 1;
776              var_Set( p_playlist, "loop", val1 );
777              vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat All" ) );
778         break;
779
780         default:
781              var_Get( p_playlist, "repeat", &val1 );
782              var_Get( p_playlist, "loop", &val2 );
783              if( val1.b_bool || val2.b_bool )
784              {
785                   val1.b_bool = 0;
786                   var_Set( p_playlist, "repeat", val1 );
787                   var_Set( p_playlist, "loop", val1 );
788                   vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat Off" ) );
789              }
790          break;
791      }
792      vlc_object_release( p_playlist );
793      [self playlistUpdated];
794 }
795
796 - (NSMutableArray *)subSearchItem:(playlist_item_t *)p_item
797 {
798     playlist_t *p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
799                                                        FIND_ANYWHERE );
800     playlist_item_t *p_selected_item;
801     int i_current, i_selected_row;
802
803     if( !p_playlist )
804         return NULL;
805
806     i_selected_row = [o_outline_view selectedRow];
807     if (i_selected_row < 0)
808         i_selected_row = 0;
809
810     p_selected_item = (playlist_item_t *)[[o_outline_view itemAtRow:
811                                             i_selected_row] pointerValue];
812
813     for( i_current = 0; i_current < p_item->i_children ; i_current++ )
814     {
815         char *psz_temp;
816         NSString *o_current_name, *o_current_author;
817
818         vlc_mutex_lock( &p_playlist->object_lock );
819         o_current_name = [NSString stringWithUTF8String:
820             p_item->pp_children[i_current]->input.psz_name];
821         psz_temp = vlc_input_item_GetInfo( &p_item->input ,
822                    _("Meta-information"),_("Artist") );
823         o_current_author = [NSString stringWithUTF8String: psz_temp];
824         free( psz_temp);
825         vlc_mutex_unlock( &p_playlist->object_lock );
826
827         if( p_selected_item == p_item->pp_children[i_current] &&
828                     b_selected_item_met == NO )
829         {
830             b_selected_item_met = YES;
831         }
832         else if( p_selected_item == p_item->pp_children[i_current] &&
833                     b_selected_item_met == YES )
834         {
835             vlc_object_release( p_playlist );
836             return NULL;
837         }
838         else if( b_selected_item_met == YES &&
839                     ( [o_current_name rangeOfString:[o_search_field
840                         stringValue] options:NSCaseInsensitiveSearch ].length ||
841                       [o_current_author rangeOfString:[o_search_field
842                         stringValue] options:NSCaseInsensitiveSearch ].length ) )
843         {
844             vlc_object_release( p_playlist );
845             /*Adds the parent items in the result array as well, so that we can
846             expand the tree*/
847             return [NSMutableArray arrayWithObject: [NSValue
848                             valueWithPointer: p_item->pp_children[i_current]]];
849         }
850         if( p_item->pp_children[i_current]->i_children > 0 )
851         {
852             id o_result = [self subSearchItem:
853                                             p_item->pp_children[i_current]];
854             if( o_result != NULL )
855             {
856                 vlc_object_release( p_playlist );
857                 [o_result insertObject: [NSValue valueWithPointer:
858                                 p_item->pp_children[i_current]] atIndex:0];
859                 return o_result;
860             }
861         }
862     }
863     vlc_object_release( p_playlist );
864     return NULL;
865 }
866
867 - (IBAction)searchItem:(id)sender
868 {
869     playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
870                                                        FIND_ANYWHERE );
871     playlist_view_t * p_view;
872     id o_result;
873
874     unsigned int i;
875     int i_row = -1;
876
877     b_selected_item_met = NO;
878
879     if( p_playlist == NULL )
880         return;
881     p_view = playlist_ViewFind( p_playlist, i_current_view );
882
883     if( p_view )
884     {
885         /*First, only search after the selected item:*
886          *(b_selected_item_met = NO)                 */
887         o_result = [self subSearchItem:p_view->p_root];
888         if( o_result == NULL )
889         {
890             /* If the first search failed, search again from the beginning */
891             o_result = [self subSearchItem:p_view->p_root];
892         }
893         if( o_result != NULL )
894         {
895             int i_start;
896             if( [[o_result objectAtIndex: 0] pointerValue] ==
897                                                     p_playlist->p_general )
898             i_start = 1;
899             else
900             i_start = 0;
901
902             for( i = i_start ; i < [o_result count] - 1 ; i++ )
903             {
904                 [o_outline_view expandItem: [o_outline_dict objectForKey:
905                             [NSString stringWithFormat: @"%p",
906                             [[o_result objectAtIndex: i] pointerValue]]]];
907             }
908             i_row = [o_outline_view rowForItem: [o_outline_dict objectForKey:
909                             [NSString stringWithFormat: @"%p",
910                             [[o_result objectAtIndex: [o_result count] - 1 ]
911                             pointerValue]]]];
912         }
913         if( i_row > -1 )
914         {
915             [o_outline_view selectRow:i_row byExtendingSelection: NO];
916             [o_outline_view scrollRowToVisible: i_row];
917         }
918     }
919     vlc_object_release( p_playlist );
920 }
921
922 - (NSMenu *)menuForEvent:(NSEvent *)o_event
923 {
924     NSPoint pt;
925     vlc_bool_t b_rows;
926     vlc_bool_t b_item_sel;
927
928     pt = [o_outline_view convertPoint: [o_event locationInWindow]
929                                                  fromView: nil];
930     b_item_sel = ( [o_outline_view rowAtPoint: pt] != -1 &&
931                    [o_outline_view selectedRow] != -1 );
932     b_rows = [o_outline_view numberOfRows] != 0;
933
934     [o_mi_play setEnabled: b_item_sel];
935     [o_mi_delete setEnabled: b_item_sel];
936     [o_mi_selectall setEnabled: b_rows];
937     [o_mi_info setEnabled: b_item_sel];
938
939     return( o_ctx_menu );
940 }
941
942 - (playlist_item_t *)selectedPlaylistItem
943 {
944     return [[o_outline_view itemAtRow: [o_outline_view selectedRow]]
945                                                                 pointerValue];
946 }
947
948 - (void)outlineView: (NSTableView*)o_tv
949                   didClickTableColumn:(NSTableColumn *)o_tc
950 {
951     int i_mode = 0, i_type;
952     intf_thread_t *p_intf = VLCIntf;
953     playlist_view_t *p_view;
954
955     playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
956                                        FIND_ANYWHERE );
957     if( p_playlist == NULL )
958     {
959         return;
960     }
961
962     /* Check whether the selected table column header corresponds to a
963        sortable table column*/
964     if( !( o_tc == o_tc_name || o_tc == o_tc_author ) )
965     {
966         vlc_object_release( p_playlist );
967         return;
968     }
969
970     p_view = playlist_ViewFind( p_playlist, i_current_view );
971
972     if( o_tc_sortColumn == o_tc )
973     {
974         b_isSortDescending = !b_isSortDescending;
975     }
976     else
977     {
978         b_isSortDescending = VLC_FALSE;
979     }
980
981     if( o_tc == o_tc_name )
982     {
983         i_mode = SORT_TITLE;
984     }
985     else if( o_tc == o_tc_author )
986     {
987         i_mode = SORT_AUTHOR;
988     }
989
990     if( b_isSortDescending )
991     {
992         i_type = ORDER_REVERSE;
993     }
994     else
995     {
996         i_type = ORDER_NORMAL;
997     }
998
999     vlc_mutex_lock( &p_playlist->object_lock );
1000     playlist_RecursiveNodeSort( p_playlist, p_view->p_root, i_mode, i_type );
1001     vlc_mutex_unlock( &p_playlist->object_lock );
1002
1003     vlc_object_release( p_playlist );
1004     [self playlistUpdated];
1005
1006     o_tc_sortColumn = o_tc;
1007     [o_outline_view setHighlightedTableColumn:o_tc];
1008
1009     if( b_isSortDescending )
1010     {
1011         [o_outline_view setIndicatorImage:o_descendingSortingImage
1012                                                         inTableColumn:o_tc];
1013     }
1014     else
1015     {
1016         [o_outline_view setIndicatorImage:o_ascendingSortingImage
1017                                                         inTableColumn:o_tc];
1018     }
1019 }
1020
1021
1022 - (void)outlineView:(NSOutlineView *)outlineView
1023                                 willDisplayCell:(id)cell
1024                                 forTableColumn:(NSTableColumn *)tableColumn
1025                                 item:(id)item
1026 {
1027     playlist_t *p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
1028                                           FIND_ANYWHERE );
1029
1030     id o_playing_item;
1031
1032     if( !p_playlist ) return;
1033
1034     o_playing_item = [o_outline_dict objectForKey:
1035                 [NSString stringWithFormat:@"%p",  p_playlist->status.p_item]];
1036
1037     if( [self isValueItem: o_playing_item inNode: item] ||
1038                                                 [o_playing_item isEqual: item] )
1039     {
1040         [cell setFont: [NSFont boldSystemFontOfSize: 0]];
1041     }
1042     else
1043     {
1044         [cell setFont: [NSFont systemFontOfSize: 0]];
1045     }
1046     vlc_object_release( p_playlist );
1047 }
1048
1049 @end
1050
1051 @implementation VLCPlaylist (NSOutlineViewDataSource)
1052
1053 /* return the number of children for Obj-C pointer item */ /* DONE */
1054 - (int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
1055 {
1056     int i_return = 0;
1057     playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
1058                                                        FIND_ANYWHERE );
1059     if( p_playlist == NULL || outlineView != o_outline_view )
1060         return 0;
1061
1062     if( item == nil )
1063     {
1064         /* root object */
1065         playlist_view_t *p_view;
1066         p_view = playlist_ViewFind( p_playlist, i_current_view );
1067         if( p_view && p_view->p_root )
1068         {
1069             i_return = p_view->p_root->i_children;
1070             if( i_current_view == VIEW_CATEGORY )
1071             {
1072                 i_return--; /* remove the GENERAL item from the list */
1073                 i_return += p_playlist->p_general->i_children; /* add the items of the general node */
1074             }
1075         }
1076     }
1077     else
1078     {
1079         playlist_item_t *p_item = (playlist_item_t *)[item pointerValue];
1080         if( p_item )
1081             i_return = p_item->i_children;
1082     }
1083     vlc_object_release( p_playlist );
1084     
1085     if( i_return <= 0 )
1086         i_return = 0;
1087     
1088     return i_return;
1089 }
1090
1091 /* return the child at index for the Obj-C pointer item */ /* DONE */
1092 - (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item
1093 {
1094     playlist_item_t *p_return = NULL;
1095     playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
1096                                                        FIND_ANYWHERE );
1097     NSValue *o_value;
1098
1099     if( p_playlist == NULL )
1100         return nil;
1101
1102     if( item == nil )
1103     {
1104         /* root object */
1105         playlist_view_t *p_view;
1106         p_view = playlist_ViewFind( p_playlist, i_current_view );
1107         if( p_view && p_view->p_root ) p_return = p_view->p_root->pp_children[index];
1108         
1109         if( i_current_view == VIEW_CATEGORY )
1110         {
1111             if( p_playlist->p_general->i_children && index >= 0 && index < p_playlist->p_general->i_children )
1112             {
1113                 p_return = p_playlist->p_general->pp_children[index];
1114             }
1115             else if( p_view && p_view->p_root && index >= 0 && index - p_playlist->p_general->i_children < p_view->p_root->i_children )
1116             {
1117                 p_return = p_view->p_root->pp_children[index - p_playlist->p_general->i_children + 1];
1118                 
1119             }
1120         }
1121     }
1122     else
1123     {
1124         playlist_item_t *p_item = (playlist_item_t *)[item pointerValue];
1125         if( p_item && index < p_item->i_children && index >= 0 )
1126             p_return = p_item->pp_children[index];
1127     }
1128     
1129     if( p_playlist->i_size >= 2 )
1130     {
1131         [o_status_field setStringValue: [NSString stringWithFormat:
1132                     _NS("%i items in playlist"), p_playlist->i_size]];
1133     }
1134     else
1135     {
1136         if( p_playlist->i_size == 0 )
1137         {
1138             [o_status_field setStringValue: [NSString stringWithFormat:
1139                     _NS("no items in playlist"), p_playlist->i_size]];
1140         }
1141         else
1142         {
1143             [o_status_field setStringValue: [NSString stringWithFormat:
1144                     _NS("1 item in playlist"), p_playlist->i_size]];
1145         }
1146     }
1147
1148     vlc_object_release( p_playlist );
1149
1150     o_value = [[NSValue valueWithPointer: p_return] retain];
1151
1152     [o_outline_dict setObject:o_value forKey:[NSString stringWithFormat:@"%p", p_return]];
1153     return o_value;
1154 }
1155
1156 /* is the item expandable */
1157 - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item
1158 {
1159     int i_return = 0;
1160     playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
1161                                                        FIND_ANYWHERE );
1162     if( p_playlist == NULL )
1163         return NO;
1164
1165     if( item == nil )
1166     {
1167         /* root object */
1168         playlist_view_t *p_view;
1169         p_view = playlist_ViewFind( p_playlist, i_current_view );
1170         if( p_view && p_view->p_root ) i_return = p_view->p_root->i_children;
1171         
1172         if( i_current_view == VIEW_CATEGORY )
1173         {
1174             i_return--;
1175             i_return += p_playlist->p_general->i_children;
1176         }
1177     }
1178     else
1179     {
1180         playlist_item_t *p_item = (playlist_item_t *)[item pointerValue];
1181         if( p_item )
1182             i_return = p_item->i_children;
1183     }
1184     vlc_object_release( p_playlist );
1185
1186     if( i_return <= 0 )
1187         return NO;
1188     else
1189         return YES;
1190 }
1191
1192 /* retrieve the string values for the cells */
1193 - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)o_tc byItem:(id)item
1194 {
1195     id o_value = nil;
1196     intf_thread_t *p_intf = VLCIntf;
1197     playlist_t *p_playlist;
1198     playlist_item_t *p_item;
1199     
1200     if( item == nil || ![item isKindOfClass: [NSValue class]] ) return( @"error" );
1201     
1202     p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1203                                                FIND_ANYWHERE );
1204     if( p_playlist == NULL )
1205     {
1206         return( @"error" );
1207     }
1208
1209     p_item = (playlist_item_t *)[item pointerValue];
1210
1211     if( p_item == NULL )
1212     {
1213         vlc_object_release( p_playlist );
1214         return( @"error");
1215     }
1216
1217     if( [[o_tc identifier] isEqualToString:@"1"] )
1218     {
1219         o_value = [NSString stringWithUTF8String:
1220             p_item->input.psz_name];
1221         if( o_value == NULL )
1222             o_value = [NSString stringWithCString:
1223                 p_item->input.psz_name];
1224     }
1225     else if( [[o_tc identifier] isEqualToString:@"2"] )
1226     {
1227         char *psz_temp;
1228         psz_temp = vlc_input_item_GetInfo( &p_item->input ,_("Meta-information"),_("Artist") );
1229
1230         if( psz_temp == NULL )
1231             o_value = @"";
1232         else
1233         {
1234             o_value = [NSString stringWithUTF8String: psz_temp];
1235             if( o_value == NULL )
1236             {
1237                 o_value = [NSString stringWithCString: psz_temp];
1238             }
1239             free( psz_temp );
1240         }
1241     }
1242     else if( [[o_tc identifier] isEqualToString:@"3"] )
1243     {
1244         char psz_duration[MSTRTIME_MAX_SIZE];
1245         mtime_t dur = p_item->input.i_duration;
1246         if( dur != -1 )
1247         {
1248             secstotimestr( psz_duration, dur/1000000 );
1249             o_value = [NSString stringWithUTF8String: psz_duration];
1250         }
1251         else
1252         {
1253             o_value = @"-:--:--";
1254         }
1255     }
1256     vlc_object_release( p_playlist );
1257
1258     return( o_value );
1259 }
1260
1261 /* Required for drag & drop and reordering */
1262 - (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pboard
1263 {
1264 /*    unsigned int i;
1265
1266     for( i = 0 ; i < [items count] ; i++ )
1267     {
1268         if( [outlineView levelForItem: [items objectAtIndex: i]] == 0 )
1269         {
1270             return NO;
1271         }
1272     }*/
1273     return NO;
1274 }
1275
1276 - (NSDragOperation)outlineView:(NSOutlineView *)outlineView validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(int)index
1277 {
1278     NSPasteboard *o_pasteboard = [info draggingPasteboard];
1279
1280     if( [[o_pasteboard types] containsObject: NSFilenamesPboardType] )
1281     {
1282         return NSDragOperationGeneric;
1283     }
1284     return NSDragOperationNone;
1285 }
1286
1287 - (BOOL)outlineView:(NSOutlineView *)outlineView acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(int)index
1288 {
1289     playlist_t * p_playlist =  vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
1290                                                        FIND_ANYWHERE );
1291     NSPasteboard *o_pasteboard = [info draggingPasteboard];
1292
1293     if( !p_playlist ) return NO;
1294
1295     if( [[o_pasteboard types] containsObject: NSFilenamesPboardType] )
1296     {
1297         int i;
1298         playlist_item_t *p_node = [item pointerValue];
1299
1300         NSArray *o_array = [NSArray array];
1301         NSArray *o_values = [[o_pasteboard propertyListForType:
1302                                         NSFilenamesPboardType]
1303                                 sortedArrayUsingSelector:
1304                                         @selector(caseInsensitiveCompare:)];
1305
1306         for( i = 0; i < (int)[o_values count]; i++)
1307         {
1308             NSDictionary *o_dic;
1309             o_dic = [NSDictionary dictionaryWithObject:[o_values
1310                         objectAtIndex:i] forKey:@"ITEM_URL"];
1311             o_array = [o_array arrayByAddingObject: o_dic];
1312         }
1313
1314         if ( item == nil )
1315         {
1316             [self appendArray: o_array atPos: index enqueue: YES];
1317         }
1318         else if( p_node->i_children == -1 )
1319         {
1320             int i_counter;
1321             playlist_item_t *p_real_node = NULL;
1322
1323             for( i_counter = 0 ; i_counter < p_node->i_parents ; i_counter++ )
1324             {
1325                 if( p_node->pp_parents[i_counter]->i_view == i_current_view )
1326                 {
1327                     p_real_node = p_node->pp_parents[i_counter]->p_parent;
1328                     break;
1329                 }
1330                 if( i_counter == p_node->i_parents )
1331                 {
1332                     return NO;
1333                 }
1334             }
1335             [self appendNodeArray: o_array inNode: p_real_node
1336                 atPos: index inView: i_current_view enqueue: YES];
1337         }
1338         else
1339         {
1340             [self appendNodeArray: o_array inNode: p_node
1341                 atPos: index inView: i_current_view enqueue: YES];
1342         }
1343         vlc_object_release( p_playlist );
1344         return YES;
1345     }
1346     vlc_object_release( p_playlist );
1347     return NO;
1348 }
1349
1350 /* Delegate method of NSWindow */
1351 /*- (void)windowWillClose:(NSNotification *)aNotification
1352 {
1353     [o_btn_playlist setState: NSOffState];
1354 }
1355 */
1356 @end
1357
1358