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