]> git.sesse.net Git - vlc/blob - modules/gui/macosx/playlist.m
* Fixes playlist search
[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
357 - (BOOL)isItem: (playlist_item_t *)p_item inNode: (playlist_item_t *)p_node
358 {
359     playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
360                                           FIND_ANYWHERE );
361     playlist_item_t *p_temp_item = p_item;
362
363     if( p_playlist == NULL )
364     {
365         return NO;
366     }
367
368     if ( p_temp_item )
369     {
370         int i;
371         vlc_mutex_lock( &p_playlist->object_lock );
372
373         /* Since outlineView: willDisplayCell:... may call this function with
374            p_items that don't exist anymore, first check if the item is still
375            in the playlist. Any cleaner solution welcomed. */
376
377         for ( i = 0 ; i < p_playlist->i_all_size ; i++ )
378         {
379             if( p_playlist->pp_all_items[i] == p_item ) break;
380             else if ( i == p_playlist->i_all_size - 1 )
381             {
382                 vlc_object_release( p_playlist );
383                 vlc_mutex_unlock( &p_playlist->object_lock );
384                 return NO;
385             }
386         }
387
388         while( p_temp_item->i_parents > 0 )
389         {
390             for( i = 0; i < p_temp_item->i_parents ; i++ )
391             {
392                 if( p_temp_item->pp_parents[i]->i_view == i_current_view )
393                 {
394                     if( p_temp_item->pp_parents[i]->p_parent == p_node )
395                     {
396                         vlc_mutex_unlock( &p_playlist->object_lock );
397                         vlc_object_release( p_playlist );
398                         return YES;
399                     }
400                     else
401                     {
402                         p_temp_item = p_temp_item->pp_parents[i]->p_parent;
403                         break;
404                     }
405                 }
406             }
407             vlc_mutex_unlock( &p_playlist->object_lock );
408         }
409     }
410
411     vlc_object_release( p_playlist );
412     return NO;
413 }
414
415 - (IBAction)savePlaylist:(id)sender
416 {
417     intf_thread_t * p_intf = VLCIntf;
418     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
419                                                        FIND_ANYWHERE );
420
421     NSSavePanel *o_save_panel = [NSSavePanel savePanel];
422     NSString * o_name = [NSString stringWithFormat: @"%@.m3u", _NS("Untitled")];
423     [o_save_panel setTitle: _NS("Save Playlist")];
424     [o_save_panel setPrompt: _NS("Save")];
425
426     if( [o_save_panel runModalForDirectory: nil
427             file: o_name] == NSOKButton )
428     {
429         playlist_Export( p_playlist, [[o_save_panel filename] fileSystemRepresentation], "export-m3u" );
430     }
431 }
432
433
434 /* When called retrieves the selected outlineview row and plays that node or item */
435 - (IBAction)playItem:(id)sender
436 {
437     intf_thread_t * p_intf = VLCIntf;
438     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
439                                                        FIND_ANYWHERE );
440
441     if( p_playlist != NULL )
442     {
443         playlist_item_t *p_item;
444         playlist_item_t *p_node = NULL;
445         int i;
446
447         p_item = [[o_outline_view itemAtRow:[o_outline_view selectedRow]] pointerValue];
448
449         if( p_item )
450         {
451             if( p_item->i_children == -1 )
452             {
453                 for( i = 0 ; i < p_item->i_parents ; i++ )
454                 {
455                     if( p_item->pp_parents[i]->i_view == i_current_view )
456                     {
457                         p_node = p_item->pp_parents[i]->p_parent;
458                     }
459                 }
460             }
461             else
462             {
463                 p_node = p_item;
464                 if( p_node->i_children > 0 && p_node->pp_children[0]->i_children == -1 )
465                 {
466                     p_item = p_node->pp_children[0];
467                 }
468                 else
469                 {
470                     p_item = NULL;
471                 }
472             }
473             playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, i_current_view, p_node, p_item );
474         }
475         vlc_object_release( p_playlist );
476     }
477 }
478
479 - (IBAction)servicesChange:(id)sender
480 {
481     NSMenuItem *o_mi = (NSMenuItem *)sender;
482     NSString *o_string = [o_mi representedObject];
483     playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
484                                           FIND_ANYWHERE );
485     if( !playlist_IsServicesDiscoveryLoaded( p_playlist, [o_string cString] ) )
486         playlist_ServicesDiscoveryAdd( p_playlist, [o_string cString] );
487     else
488         playlist_ServicesDiscoveryRemove( p_playlist, [o_string cString] );
489
490     [o_mi setState: playlist_IsServicesDiscoveryLoaded( p_playlist,
491                                           [o_string cString] ) ? YES : NO];
492
493     i_current_view = VIEW_CATEGORY;
494     playlist_ViewUpdate( p_playlist, i_current_view );
495     vlc_object_release( p_playlist );
496     [self playlistUpdated];
497     return;
498 }
499
500 - (IBAction)selectAll:(id)sender
501 {
502     [o_outline_view selectAll: nil];
503 }
504
505 - (IBAction)deleteItem:(id)sender
506 {
507     int i, i_count, i_row;
508     NSMutableArray *o_to_delete;
509     NSNumber *o_number;
510
511     playlist_t * p_playlist;
512     intf_thread_t * p_intf = VLCIntf;
513
514     p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
515                                           FIND_ANYWHERE );
516
517     if ( p_playlist == NULL )
518     {
519         return;
520     }
521     o_to_delete = [NSMutableArray arrayWithArray:[[o_outline_view selectedRowEnumerator] allObjects]];
522     i_count = [o_to_delete count];
523
524     for( i = 0; i < i_count; i++ )
525     {
526         playlist_item_t * p_item;
527         o_number = [o_to_delete lastObject];
528         i_row = [o_number intValue];
529         [o_to_delete removeObject: o_number];
530         [o_outline_view deselectRow: i_row];
531
532         p_item = (playlist_item_t *)[[o_outline_view itemAtRow: i_row] pointerValue];
533
534         if( p_item->i_children > -1 ) //is a node and not an item
535         {
536             if( p_playlist->status.i_status != PLAYLIST_STOPPED &&
537                 [self isItem: p_playlist->status.p_item inNode: p_item] == YES )
538             {
539                 // if current item is in selected node and is playing then stop playlist
540                 playlist_Stop( p_playlist );
541             }
542             vlc_mutex_lock( &p_playlist->object_lock );
543             playlist_NodeDelete( p_playlist, p_item, VLC_TRUE, VLC_FALSE );
544             vlc_mutex_unlock( &p_playlist->object_lock );
545         }
546         else
547         {
548             if( p_playlist->status.i_status != PLAYLIST_STOPPED &&
549                 p_playlist->status.p_item == [[o_outline_view itemAtRow: i_row] pointerValue] )
550             {
551                 playlist_Stop( p_playlist );
552             }
553             vlc_mutex_lock( &p_playlist->object_lock );
554             playlist_Delete( p_playlist, p_item->input.i_id );
555             vlc_mutex_unlock( &p_playlist->object_lock );
556         }
557     }
558     [self playlistUpdated];
559     vlc_object_release( p_playlist );
560 }
561
562 - (IBAction)sortNodeByName:(id)sender
563 {
564     [self sortNode: SORT_TITLE];
565 }
566
567 - (IBAction)sortNodeByAuthor:(id)sender
568 {
569     [self sortNode: SORT_AUTHOR];
570 }
571
572 - (void)sortNode:(int)i_mode
573 {
574     playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
575                                           FIND_ANYWHERE );
576     playlist_item_t * p_item;
577
578     if (p_playlist == NULL)
579     {
580         return;
581     }
582
583     if( [o_outline_view selectedRow] > -1 )
584     {
585         p_item = [[o_outline_view itemAtRow: [o_outline_view selectedRow]]
586                                                                 pointerValue];
587     }
588     else
589     /*If no item is selected, sort the whole playlist*/
590     {
591         playlist_view_t * p_view = playlist_ViewFind( p_playlist, i_current_view );
592         p_item = p_view->p_root;
593     }
594
595     if( p_item->i_children > -1 ) // the item is a node
596     {
597         vlc_mutex_lock( &p_playlist->object_lock );
598         playlist_RecursiveNodeSort( p_playlist, p_item, i_mode, ORDER_NORMAL );
599         vlc_mutex_unlock( &p_playlist->object_lock );
600     }
601     else
602     {
603         int i;
604
605         for( i = 0 ; i < p_item->i_parents ; i++ )
606         {
607             if( p_item->pp_parents[i]->i_view == i_current_view )
608             {
609                 vlc_mutex_lock( &p_playlist->object_lock );
610                 playlist_RecursiveNodeSort( p_playlist,
611                         p_item->pp_parents[i]->p_parent, i_mode, ORDER_NORMAL );
612                 vlc_mutex_unlock( &p_playlist->object_lock );
613                 break;
614             }
615         }
616     }
617     vlc_object_release( p_playlist );
618     [self playlistUpdated];
619 }
620
621 - (playlist_item_t *)createItem:(NSDictionary *)o_one_item
622 {
623     intf_thread_t * p_intf = VLCIntf;
624     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
625                                                        FIND_ANYWHERE );
626
627     if( p_playlist == NULL )
628     {
629         return NULL;
630     }
631     playlist_item_t *p_item;
632     int i;
633     BOOL b_rem = FALSE, b_dir = FALSE;
634     NSString *o_uri, *o_name;
635     NSArray *o_options;
636     NSURL *o_true_file;
637
638     /* Get the item */
639     o_uri = (NSString *)[o_one_item objectForKey: @"ITEM_URL"];
640     o_name = (NSString *)[o_one_item objectForKey: @"ITEM_NAME"];
641     o_options = (NSArray *)[o_one_item objectForKey: @"ITEM_OPTIONS"];
642
643     /* Find the name for a disc entry ( i know, can you believe the trouble?) */
644     if( ( !o_name || [o_name isEqualToString:@""] ) && [o_uri rangeOfString: @"/dev/"].location != NSNotFound )
645     {
646         int i_count, i_index;
647         struct statfs *mounts = NULL;
648
649         i_count = getmntinfo (&mounts, MNT_NOWAIT);
650         /* getmntinfo returns a pointer to static data. Do not free. */
651         for( i_index = 0 ; i_index < i_count; i_index++ )
652         {
653             NSMutableString *o_temp, *o_temp2;
654             o_temp = [NSMutableString stringWithString: o_uri];
655             o_temp2 = [NSMutableString stringWithCString: mounts[i_index].f_mntfromname];
656             [o_temp replaceOccurrencesOfString: @"/dev/rdisk" withString: @"/dev/disk" options:NULL range:NSMakeRange(0, [o_temp length]) ];
657             [o_temp2 replaceOccurrencesOfString: @"s0" withString: @"" options:NULL range:NSMakeRange(0, [o_temp2 length]) ];
658             [o_temp2 replaceOccurrencesOfString: @"s1" withString: @"" options:NULL range:NSMakeRange(0, [o_temp2 length]) ];
659
660             if( strstr( [o_temp fileSystemRepresentation], [o_temp2 fileSystemRepresentation] ) != NULL )
661             {
662                 o_name = [[NSFileManager defaultManager] displayNameAtPath: [NSString stringWithCString:mounts[i_index].f_mntonname]];
663             }
664         }
665     }
666     /* If no name, then make a guess */
667     if( !o_name) o_name = [[NSFileManager defaultManager] displayNameAtPath: o_uri];
668
669     if( [[NSFileManager defaultManager] fileExistsAtPath:o_uri isDirectory:&b_dir] && b_dir &&
670         [[NSWorkspace sharedWorkspace] getFileSystemInfoForPath: o_uri isRemovable: &b_rem
671                 isWritable:NULL isUnmountable:NULL description:NULL type:NULL] && b_rem   )
672     {
673         /* All of this is to make sure CD's play when you D&D them on VLC */
674         /* Converts mountpoint to a /dev file */
675         struct statfs *buf;
676         char *psz_dev;
677         NSMutableString *o_temp;
678
679         buf = (struct statfs *) malloc (sizeof(struct statfs));
680         statfs( [o_uri fileSystemRepresentation], buf );
681         psz_dev = strdup(buf->f_mntfromname);
682         o_temp = [NSMutableString stringWithCString: psz_dev ];
683         [o_temp replaceOccurrencesOfString: @"/dev/disk" withString: @"/dev/rdisk" options:NULL range:NSMakeRange(0, [o_temp length]) ];
684         [o_temp replaceOccurrencesOfString: @"s0" withString: @"" options:NULL range:NSMakeRange(0, [o_temp length]) ];
685         [o_temp replaceOccurrencesOfString: @"s1" withString: @"" options:NULL range:NSMakeRange(0, [o_temp length]) ];
686         o_uri = o_temp;
687     }
688
689     p_item = playlist_ItemNew( p_intf, [o_uri fileSystemRepresentation], [o_name UTF8String] );
690     if( !p_item )
691        return NULL;
692
693     if( o_options )
694     {
695         for( i = 0; i < (int)[o_options count]; i++ )
696         {
697             playlist_ItemAddOption( p_item, strdup( [[o_options objectAtIndex:i] UTF8String] ) );
698         }
699     }
700
701     /* Recent documents menu */
702     o_true_file = [NSURL fileURLWithPath: o_uri];
703     if( o_true_file != nil )
704     {
705         [[NSDocumentController sharedDocumentController]
706             noteNewRecentDocumentURL: o_true_file];
707     }
708
709     vlc_object_release( p_playlist );
710     return p_item;
711 }
712
713 - (void)appendArray:(NSArray*)o_array atPos:(int)i_position enqueue:(BOOL)b_enqueue
714 {
715     int i_item;
716     playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
717                                             FIND_ANYWHERE );
718     if( p_playlist == NULL )
719     {
720         return;
721     }
722
723     for( i_item = 0; i_item < (int)[o_array count]; i_item++ )
724     {
725         playlist_item_t *p_item;
726         NSDictionary *o_one_item;
727
728         /* Get the item */
729         o_one_item = [o_array objectAtIndex: i_item];
730         p_item = [self createItem: o_one_item];
731         if( !p_item )
732         {
733             continue;
734         }
735
736         /* Add the item */
737         playlist_AddItem( p_playlist, p_item, PLAYLIST_APPEND, i_position == -1 ? PLAYLIST_END : i_position + i_item );
738
739         if( i_item == 0 && !b_enqueue )
740         {
741             playlist_Control( p_playlist, PLAYLIST_ITEMPLAY, p_item );
742         }
743     }
744     vlc_object_release( p_playlist );
745 }
746
747 - (void)appendNodeArray:(NSArray*)o_array inNode:(playlist_item_t *)p_node atPos:(int)i_position inView:(int)i_view enqueue:(BOOL)b_enqueue
748 {
749     int i_item;
750     playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
751                                             FIND_ANYWHERE );
752     if( p_playlist == NULL )
753     {
754         return;
755     }
756
757     for( i_item = 0; i_item < (int)[o_array count]; i_item++ )
758     {
759         playlist_item_t *p_item;
760         NSDictionary *o_one_item;
761
762         /* Get the item */
763         o_one_item = [o_array objectAtIndex: i_item];
764         p_item = [self createItem: o_one_item];
765         if( !p_item )
766         {
767             continue;
768         }
769
770         /* Add the item */
771         playlist_NodeAddItem( p_playlist, p_item, i_view, p_node, PLAYLIST_APPEND, i_position + i_item );
772
773         if( i_item == 0 && !b_enqueue )
774         {
775             playlist_Control( p_playlist, PLAYLIST_ITEMPLAY, p_item );
776         }
777     }
778     vlc_object_release( p_playlist );
779
780 }
781
782 - (IBAction)handlePopUp:(id)sender
783
784 {
785     intf_thread_t * p_intf = VLCIntf;
786     vlc_value_t val1,val2;
787     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
788                                             FIND_ANYWHERE );
789     if( p_playlist == NULL )
790     {
791         return;
792     }
793
794     switch( [o_loop_popup indexOfSelectedItem] )
795     {
796         case 1:
797
798              val1.b_bool = 0;
799              var_Set( p_playlist, "loop", val1 );
800              val1.b_bool = 1;
801              var_Set( p_playlist, "repeat", val1 );
802              vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat One" ) );
803         break;
804
805         case 2:
806              val1.b_bool = 0;
807              var_Set( p_playlist, "repeat", val1 );
808              val1.b_bool = 1;
809              var_Set( p_playlist, "loop", val1 );
810              vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat All" ) );
811         break;
812
813         default:
814              var_Get( p_playlist, "repeat", &val1 );
815              var_Get( p_playlist, "loop", &val2 );
816              if( val1.b_bool || val2.b_bool )
817              {
818                   val1.b_bool = 0;
819                   var_Set( p_playlist, "repeat", val1 );
820                   var_Set( p_playlist, "loop", val1 );
821                   vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat Off" ) );
822              }
823          break;
824      }
825      vlc_object_release( p_playlist );
826      [self playlistUpdated];
827 }
828
829 - (NSMutableArray *)subSearchItem:(playlist_item_t *)p_item
830 {
831     playlist_t *p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
832                                                        FIND_ANYWHERE );
833     playlist_item_t *p_selected_item;
834     int i_current, i_selected_row;
835
836     if( !p_playlist )
837         return NULL;
838
839     i_selected_row = [o_outline_view selectedRow];
840     if (i_selected_row < 0)
841         i_selected_row = 0;
842
843     p_selected_item = (playlist_item_t *)[[o_outline_view itemAtRow:
844                                             i_selected_row] pointerValue];
845
846     for( i_current = 0; i_current < p_item->i_children ; i_current++ )
847     {
848         char *psz_temp;
849         NSString *o_current_name, *o_current_author;
850
851         vlc_mutex_lock( &p_playlist->object_lock );
852         o_current_name = [NSString stringWithUTF8String:
853             p_item->pp_children[i_current]->input.psz_name];
854         psz_temp = vlc_input_item_GetInfo( &p_item->input ,
855                    _("Meta-information"),_("Artist") );
856         o_current_author = [NSString stringWithUTF8String: psz_temp];
857         free( psz_temp);
858         vlc_mutex_unlock( &p_playlist->object_lock );
859
860         if( p_selected_item == p_item->pp_children[i_current] &&
861                     b_selected_item_met == NO )
862         {
863             b_selected_item_met = YES;
864         }
865         else if( p_selected_item == p_item->pp_children[i_current] &&
866                     b_selected_item_met == YES )
867         {
868             vlc_object_release( p_playlist );
869             return NULL;
870         }
871         else if( b_selected_item_met == YES &&
872                     ( [o_current_name rangeOfString:[o_search_field
873                         stringValue] options:NSCaseInsensitiveSearch ].length ||
874                       [o_current_author rangeOfString:[o_search_field
875                         stringValue] options:NSCaseInsensitiveSearch ].length ) )
876         {
877             vlc_object_release( p_playlist );
878             /*Adds the parent items in the result array as well, so that we can
879             expand the tree*/
880             return [NSMutableArray arrayWithObject: [NSValue
881                             valueWithPointer: p_item->pp_children[i_current]]];
882         }
883         if( p_item->pp_children[i_current]->i_children > 0 )
884         {
885             id o_result = [self subSearchItem:
886                                             p_item->pp_children[i_current]];
887             if( o_result != NULL )
888             {
889                 vlc_object_release( p_playlist );
890                 [o_result insertObject: [NSValue valueWithPointer:
891                                 p_item->pp_children[i_current]] atIndex:0];
892                 return o_result;
893             }
894         }
895     }
896     vlc_object_release( p_playlist );
897     return NULL;
898 }
899
900 - (IBAction)searchItem:(id)sender
901 {
902     playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
903                                                        FIND_ANYWHERE );
904     playlist_view_t * p_view;
905     id o_result;
906
907     unsigned int i;
908     int i_row = -1;
909
910     b_selected_item_met = NO;
911
912     if( p_playlist == NULL )
913         return;
914     p_view = playlist_ViewFind( p_playlist, i_current_view );
915
916     if( p_view )
917     {
918         /*First, only search after the selected item:*
919          *(b_selected_item_met = NO)                 */
920         o_result = [self subSearchItem:p_view->p_root];
921         if( o_result == NULL )
922         {
923             /* If the first search failed, search again from the beginning */
924             o_result = [self subSearchItem:p_view->p_root];
925         }
926         if( o_result != NULL )
927         {
928             int i_start;
929             if( [[o_result objectAtIndex: 0] pointerValue] ==
930                                                     p_playlist->p_general )
931             i_start = 1;
932             else
933             i_start = 0;
934
935             for( i = i_start ; i < [o_result count] - 1 ; i++ )
936             {
937                 [o_outline_view expandItem: [o_outline_dict objectForKey:
938                             [NSString stringWithFormat: @"%p",
939                             [[o_result objectAtIndex: i] pointerValue]]]];
940             }
941             i_row = [o_outline_view rowForItem: [o_outline_dict objectForKey:
942                             [NSString stringWithFormat: @"%p",
943                             [[o_result objectAtIndex: [o_result count] - 1 ]
944                             pointerValue]]]];
945         }
946         if( i_row > -1 )
947         {
948             [o_outline_view selectRow:i_row byExtendingSelection: NO];
949             [o_outline_view scrollRowToVisible: i_row];
950         }
951     }
952     vlc_object_release( p_playlist );
953 }
954
955 - (NSMenu *)menuForEvent:(NSEvent *)o_event
956 {
957     NSPoint pt;
958     vlc_bool_t b_rows;
959     vlc_bool_t b_item_sel;
960
961     pt = [o_outline_view convertPoint: [o_event locationInWindow]
962                                                  fromView: nil];
963     b_item_sel = ( [o_outline_view rowAtPoint: pt] != -1 &&
964                    [o_outline_view selectedRow] != -1 );
965     b_rows = [o_outline_view numberOfRows] != 0;
966
967     [o_mi_play setEnabled: b_item_sel];
968     [o_mi_delete setEnabled: b_item_sel];
969     [o_mi_selectall setEnabled: b_rows];
970     [o_mi_info setEnabled: b_item_sel];
971
972     return( o_ctx_menu );
973 }
974
975 - (playlist_item_t *)selectedPlaylistItem
976 {
977     return [[o_outline_view itemAtRow: [o_outline_view selectedRow]]
978                                                                 pointerValue];
979 }
980
981 - (void)outlineView: (NSTableView*)o_tv
982                   didClickTableColumn:(NSTableColumn *)o_tc
983 {
984     int i_mode = 0, i_type;
985     intf_thread_t *p_intf = VLCIntf;
986     playlist_view_t *p_view;
987
988     playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
989                                        FIND_ANYWHERE );
990     if( p_playlist == NULL )
991     {
992         return;
993     }
994
995     /* Check whether the selected table column header corresponds to a
996        sortable table column*/
997     if( !( o_tc == o_tc_name || o_tc == o_tc_author ) )
998     {
999         vlc_object_release( p_playlist );
1000         return;
1001     }
1002
1003     p_view = playlist_ViewFind( p_playlist, i_current_view );
1004
1005     if( o_tc_sortColumn == o_tc )
1006     {
1007         b_isSortDescending = !b_isSortDescending;
1008     }
1009     else
1010     {
1011         b_isSortDescending = VLC_FALSE;
1012     }
1013
1014     if( o_tc == o_tc_name )
1015     {
1016         i_mode = SORT_TITLE;
1017     }
1018     else if( o_tc == o_tc_author )
1019     {
1020         i_mode = SORT_AUTHOR;
1021     }
1022
1023     if( b_isSortDescending )
1024     {
1025         i_type = ORDER_REVERSE;
1026     }
1027     else
1028     {
1029         i_type = ORDER_NORMAL;
1030     }
1031
1032     vlc_mutex_lock( &p_playlist->object_lock );
1033     playlist_RecursiveNodeSort( p_playlist, p_view->p_root, i_mode, i_type );
1034     vlc_mutex_unlock( &p_playlist->object_lock );
1035
1036     vlc_object_release( p_playlist );
1037     [self playlistUpdated];
1038
1039     o_tc_sortColumn = o_tc;
1040     [o_outline_view setHighlightedTableColumn:o_tc];
1041
1042     if( b_isSortDescending )
1043     {
1044         [o_outline_view setIndicatorImage:o_descendingSortingImage
1045                                                         inTableColumn:o_tc];
1046     }
1047     else
1048     {
1049         [o_outline_view setIndicatorImage:o_ascendingSortingImage
1050                                                         inTableColumn:o_tc];
1051     }
1052 }
1053
1054
1055 - (void)outlineView:(NSOutlineView *)outlineView
1056                                 willDisplayCell:(id)cell
1057                                 forTableColumn:(NSTableColumn *)tableColumn
1058                                 item:(id)item
1059 {
1060     playlist_t *p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
1061                                           FIND_ANYWHERE );
1062     playlist_item_t *p_item;
1063
1064     if( !p_playlist ) return;
1065
1066     p_item = (playlist_item_t *)[item pointerValue];
1067     if( ( p_item == p_playlist->status.p_item ) ||
1068             ( p_item->i_children != 0 &&
1069             [self isItem: p_playlist->status.p_item inNode: p_item] ) )
1070     {
1071         [cell setFont: [NSFont boldSystemFontOfSize: 0]];
1072     }
1073     else
1074     {
1075         [cell setFont: [NSFont systemFontOfSize: 0]];
1076     }
1077     vlc_object_release( p_playlist );
1078 }
1079
1080 @end
1081
1082 @implementation VLCPlaylist (NSOutlineViewDataSource)
1083
1084 /* return the number of children for Obj-C pointer item */ /* DONE */
1085 - (int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
1086 {
1087     int i_return = 0;
1088     playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
1089                                                        FIND_ANYWHERE );
1090     if( p_playlist == NULL || outlineView != o_outline_view )
1091         return 0;
1092
1093     if( item == nil )
1094     {
1095         /* root object */
1096         playlist_view_t *p_view;
1097         p_view = playlist_ViewFind( p_playlist, i_current_view );
1098         if( p_view && p_view->p_root )
1099         {
1100             i_return = p_view->p_root->i_children;
1101             if( i_current_view == VIEW_CATEGORY )
1102             {
1103                 i_return--; /* remove the GENERAL item from the list */
1104                 i_return += p_playlist->p_general->i_children; /* add the items of the general node */
1105             }
1106         }
1107     }
1108     else
1109     {
1110         playlist_item_t *p_item = (playlist_item_t *)[item pointerValue];
1111         if( p_item )
1112             i_return = p_item->i_children;
1113     }
1114     vlc_object_release( p_playlist );
1115     
1116     if( i_return <= 0 )
1117         i_return = 0;
1118     
1119     return i_return;
1120 }
1121
1122 /* return the child at index for the Obj-C pointer item */ /* DONE */
1123 - (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item
1124 {
1125     playlist_item_t *p_return = NULL;
1126     playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
1127                                                        FIND_ANYWHERE );
1128     NSValue *o_value;
1129
1130     if( p_playlist == NULL )
1131         return nil;
1132
1133     if( item == nil )
1134     {
1135         /* root object */
1136         playlist_view_t *p_view;
1137         p_view = playlist_ViewFind( p_playlist, i_current_view );
1138         if( p_view && p_view->p_root ) p_return = p_view->p_root->pp_children[index];
1139         
1140         if( i_current_view == VIEW_CATEGORY )
1141         {
1142             if( p_playlist->p_general->i_children && index >= 0 && index < p_playlist->p_general->i_children )
1143             {
1144                 p_return = p_playlist->p_general->pp_children[index];
1145             }
1146             else if( p_view && p_view->p_root && index >= 0 && index - p_playlist->p_general->i_children < p_view->p_root->i_children )
1147             {
1148                 p_return = p_view->p_root->pp_children[index - p_playlist->p_general->i_children + 1];
1149                 
1150             }
1151         }
1152     }
1153     else
1154     {
1155         playlist_item_t *p_item = (playlist_item_t *)[item pointerValue];
1156         if( p_item && index < p_item->i_children && index >= 0 )
1157             p_return = p_item->pp_children[index];
1158     }
1159     
1160     if( p_playlist->i_size >= 2 )
1161     {
1162         [o_status_field setStringValue: [NSString stringWithFormat:
1163                     _NS("%i items in playlist"), p_playlist->i_size]];
1164     }
1165     else
1166     {
1167         if( p_playlist->i_size == 0 )
1168         {
1169             [o_status_field setStringValue: [NSString stringWithFormat:
1170                     _NS("no items in playlist"), p_playlist->i_size]];
1171         }
1172         else
1173         {
1174             [o_status_field setStringValue: [NSString stringWithFormat:
1175                     _NS("1 item in playlist"), p_playlist->i_size]];
1176         }
1177     }
1178
1179     vlc_object_release( p_playlist );
1180
1181     o_value = [[NSValue valueWithPointer: p_return] retain];
1182
1183     [o_outline_dict setObject:o_value forKey:[NSString stringWithFormat:@"%p", p_return]];
1184     return o_value;
1185 }
1186
1187 /* is the item expandable */
1188 - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item
1189 {
1190     int i_return = 0;
1191     playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
1192                                                        FIND_ANYWHERE );
1193     if( p_playlist == NULL )
1194         return NO;
1195
1196     if( item == nil )
1197     {
1198         /* root object */
1199         playlist_view_t *p_view;
1200         p_view = playlist_ViewFind( p_playlist, i_current_view );
1201         if( p_view && p_view->p_root ) i_return = p_view->p_root->i_children;
1202         
1203         if( i_current_view == VIEW_CATEGORY )
1204         {
1205             i_return--;
1206             i_return += p_playlist->p_general->i_children;
1207         }
1208     }
1209     else
1210     {
1211         playlist_item_t *p_item = (playlist_item_t *)[item pointerValue];
1212         if( p_item )
1213             i_return = p_item->i_children;
1214     }
1215     vlc_object_release( p_playlist );
1216
1217     if( i_return <= 0 )
1218         return NO;
1219     else
1220         return YES;
1221 }
1222
1223 /* retrieve the string values for the cells */
1224 - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)o_tc byItem:(id)item
1225 {
1226     id o_value = nil;
1227     intf_thread_t *p_intf = VLCIntf;
1228     playlist_t *p_playlist;
1229     playlist_item_t *p_item;
1230     
1231     if( item == nil || ![item isKindOfClass: [NSValue class]] ) return( @"error" );
1232     
1233     p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1234                                                FIND_ANYWHERE );
1235     if( p_playlist == NULL )
1236     {
1237         return( @"error" );
1238     }
1239
1240     p_item = (playlist_item_t *)[item pointerValue];
1241
1242     if( p_item == NULL )
1243     {
1244         vlc_object_release( p_playlist );
1245         return( @"error");
1246     }
1247
1248     if( [[o_tc identifier] isEqualToString:@"1"] )
1249     {
1250         o_value = [NSString stringWithUTF8String:
1251             p_item->input.psz_name];
1252         if( o_value == NULL )
1253             o_value = [NSString stringWithCString:
1254                 p_item->input.psz_name];
1255     }
1256     else if( [[o_tc identifier] isEqualToString:@"2"] )
1257     {
1258         char *psz_temp;
1259         psz_temp = vlc_input_item_GetInfo( &p_item->input ,_("Meta-information"),_("Artist") );
1260
1261         if( psz_temp == NULL )
1262             o_value = @"";
1263         else
1264         {
1265             o_value = [NSString stringWithUTF8String: psz_temp];
1266             if( o_value == NULL )
1267             {
1268                 o_value = [NSString stringWithCString: psz_temp];
1269             }
1270             free( psz_temp );
1271         }
1272     }
1273     else if( [[o_tc identifier] isEqualToString:@"3"] )
1274     {
1275         char psz_duration[MSTRTIME_MAX_SIZE];
1276         mtime_t dur = p_item->input.i_duration;
1277         if( dur != -1 )
1278         {
1279             secstotimestr( psz_duration, dur/1000000 );
1280             o_value = [NSString stringWithUTF8String: psz_duration];
1281         }
1282         else
1283         {
1284             o_value = @"-:--:--";
1285         }
1286     }
1287     vlc_object_release( p_playlist );
1288
1289     return( o_value );
1290 }
1291
1292 /* Required for drag & drop and reordering */
1293 - (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pboard
1294 {
1295 /*    unsigned int i;
1296
1297     for( i = 0 ; i < [items count] ; i++ )
1298     {
1299         if( [outlineView levelForItem: [items objectAtIndex: i]] == 0 )
1300         {
1301             return NO;
1302         }
1303     }*/
1304     return NO;
1305 }
1306
1307 - (NSDragOperation)outlineView:(NSOutlineView *)outlineView validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(int)index
1308 {
1309     NSPasteboard *o_pasteboard = [info draggingPasteboard];
1310
1311     if( [[o_pasteboard types] containsObject: NSFilenamesPboardType] )
1312     {
1313         return NSDragOperationGeneric;
1314     }
1315     return NSDragOperationNone;
1316 }
1317
1318 - (BOOL)outlineView:(NSOutlineView *)outlineView acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(int)index
1319 {
1320     playlist_t * p_playlist =  vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
1321                                                        FIND_ANYWHERE );
1322     NSPasteboard *o_pasteboard = [info draggingPasteboard];
1323
1324     if( !p_playlist ) return NO;
1325
1326     if( [[o_pasteboard types] containsObject: NSFilenamesPboardType] )
1327     {
1328         int i;
1329         playlist_item_t *p_node = [item pointerValue];
1330
1331         NSArray *o_array = [NSArray array];
1332         NSArray *o_values = [[o_pasteboard propertyListForType:
1333                                         NSFilenamesPboardType]
1334                                 sortedArrayUsingSelector:
1335                                         @selector(caseInsensitiveCompare:)];
1336
1337         for( i = 0; i < (int)[o_values count]; i++)
1338         {
1339             NSDictionary *o_dic;
1340             o_dic = [NSDictionary dictionaryWithObject:[o_values
1341                         objectAtIndex:i] forKey:@"ITEM_URL"];
1342             o_array = [o_array arrayByAddingObject: o_dic];
1343         }
1344
1345         if ( item == nil )
1346         {
1347             [self appendArray: o_array atPos: index enqueue: YES];
1348         }
1349         else if( p_node->i_children == -1 )
1350         {
1351             int i_counter;
1352             playlist_item_t *p_real_node = NULL;
1353
1354             for( i_counter = 0 ; i_counter < p_node->i_parents ; i_counter++ )
1355             {
1356                 if( p_node->pp_parents[i_counter]->i_view == i_current_view )
1357                 {
1358                     p_real_node = p_node->pp_parents[i_counter]->p_parent;
1359                     break;
1360                 }
1361                 if( i_counter == p_node->i_parents )
1362                 {
1363                     return NO;
1364                 }
1365             }
1366             [self appendNodeArray: o_array inNode: p_real_node
1367                 atPos: index inView: i_current_view enqueue: YES];
1368         }
1369         else
1370         {
1371             [self appendNodeArray: o_array inNode: p_node
1372                 atPos: index inView: i_current_view enqueue: YES];
1373         }
1374         vlc_object_release( p_playlist );
1375         return YES;
1376     }
1377     vlc_object_release( p_playlist );
1378     return NO;
1379 }
1380
1381 /* Delegate method of NSWindow */
1382 /*- (void)windowWillClose:(NSNotification *)aNotification
1383 {
1384     [o_btn_playlist setState: NSOffState];
1385 }
1386 */
1387 @end
1388
1389