]> git.sesse.net Git - vlc/blob - modules/gui/macosx/playlist.m
Implements sorting of the current node from context menu
[vlc] / modules / gui / macosx / playlist.m
1 /*****************************************************************************
2  * playlist.m: MacOS X interface module
3  *****************************************************************************
4  * Copyright (C) 2002-2004 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  * connect delegates, actions and outlets in IB
28  * implement delete by backspace
29  * implement playlist item rightclick menu
30  * implement sorting
31  * add 'icons' for different types of nodes? (http://www.cocoadev.com/index.pl?IconAndTextInTableCell)
32  * create a new 'playlist toggle' that hides the playlist and in effect give you the old controller
33  * create a new search field build with pictures from the 'regular' search field, so it can be emulated on 10.2
34  * create toggle buttons for the shuffle, repeat one, repeat all functions.
35  * implement drag and drop and item reordering.
36  * reimplement enable/disable item
37  * create a new 'tool' button (see the gear button in the Finder window) for 'actions'
38    (adding service discovery, other views, new node/playlist, save node/playlist) stuff like that
39  */
40
41
42
43 /*****************************************************************************
44  * Preamble
45  *****************************************************************************/
46 #include <stdlib.h>                                      /* malloc(), free() */
47 #include <sys/param.h>                                    /* for MAXPATHLEN */
48 #include <string.h>
49 #include <math.h>
50 #include <sys/mount.h>
51 #include <vlc_keys.h>
52
53 #include "intf.h"
54 #include "playlist.h"
55 #include "controls.h"
56 #include "osd.h"
57
58 /*****************************************************************************
59  * VLCPlaylistView implementation 
60  *****************************************************************************/
61 @implementation VLCPlaylistView
62
63 - (NSMenu *)menuForEvent:(NSEvent *)o_event
64 {
65     return( [[self delegate] menuForEvent: o_event] );
66 }
67
68 - (void)keyDown:(NSEvent *)o_event
69 {
70     unichar key = 0;
71
72     if( [[o_event characters] length] )
73     {
74         key = [[o_event characters] characterAtIndex: 0];
75     }
76
77     switch( key )
78     {
79         case NSDeleteCharacter:
80         case NSDeleteFunctionKey:
81         case NSDeleteCharFunctionKey:
82         case NSBackspaceCharacter:
83             [[self delegate] deleteItem:self];
84             break;
85
86         default:
87             [super keyDown: o_event];
88             break;
89     }
90 }
91
92 @end
93
94 /*****************************************************************************
95  * VLCPlaylist implementation 
96  *****************************************************************************/
97 @implementation VLCPlaylist
98
99 - (id)init
100 {
101     self = [super init];
102     if ( self !=nil )
103     {
104         //i_moveRow = -1;
105     }
106     return self;
107 }
108
109 - (void)awakeFromNib
110 {
111     [o_outline_view setTarget: self];
112     [o_outline_view setDelegate: self];
113     [o_outline_view setDataSource: self];
114
115     [o_outline_view setDoubleAction: @selector(playItem:)];
116
117     [o_outline_view registerForDraggedTypes: 
118         [NSArray arrayWithObjects: NSFilenamesPboardType, nil]];
119     [o_outline_view setIntercellSpacing: NSMakeSize (0.0, 1.0)];
120
121 /* We need to check whether _defaultTableHeaderSortImage exists, since it 
122 belongs to an Apple hidden private API, and then can "disapear" at any time*/
123
124     if( [[NSOutlineView class] respondsToSelector:@selector(_defaultTableHeaderSortImage)] )
125     {
126         o_ascendingSortingImage = [[NSOutlineView class] _defaultTableHeaderSortImage];
127     }
128     else
129     {
130         o_ascendingSortingImage = nil;
131     }
132
133     if( [[NSOutlineView class] respondsToSelector:@selector(_defaultTableHeaderReverseSortImage)] )
134     {
135         o_descendingSortingImage = [[NSOutlineView class] _defaultTableHeaderReverseSortImage];
136     }
137     else
138     {
139         o_descendingSortingImage = nil;
140     }
141
142     o_outline_dict = [[NSMutableDictionary alloc] init];
143
144     [self initStrings];
145     //[self playlistUpdated];
146 }
147
148 - (void)initStrings
149 {
150     [o_mi_save_playlist setTitle: _NS("Save Playlist...")];
151     [o_mi_play setTitle: _NS("Play")];
152     [o_mi_delete setTitle: _NS("Delete")];
153     [o_mi_selectall setTitle: _NS("Select All")];
154     [o_mi_info setTitle: _NS("Properties")];
155     [o_mi_sort_name setTitle: _NS("Sort Node by Name")];
156     [o_mi_sort_author setTitle: _NS("Sort Node by Author")];
157     [[o_tc_name headerCell] setStringValue:_NS("Name")];
158     [[o_tc_author headerCell] setStringValue:_NS("Author")];
159     [[o_tc_duration headerCell] setStringValue:_NS("Duration")];
160     [o_status_field setStringValue: [NSString stringWithFormat:
161                         _NS("0 items in playlist")]];
162
163     [o_random_ckb setTitle: _NS("Random")];
164 #if 0
165     [o_search_button setTitle: _NS("Search")];
166 #endif
167     [o_btn_playlist setToolTip: _NS("Playlist")];
168     [[o_loop_popup itemAtIndex:0] setTitle: _NS("Standard Play")];
169     [[o_loop_popup itemAtIndex:1] setTitle: _NS("Repeat One")];
170     [[o_loop_popup itemAtIndex:2] setTitle: _NS("Repeat All")];
171 }
172
173 - (void)playlistUpdated
174 {
175     [o_outline_dict removeAllObjects];
176     [o_outline_view reloadData];
177 }
178
179 - (bool)isItem:(playlist_item_t *)p_item inNode:(playlist_item_t *)p_node
180 {
181     playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
182                                           FIND_ANYWHERE );
183     playlist_item_t * p_temp_item = p_item;
184
185     if ( p_playlist == NULL )
186     {
187         return NO;
188     }
189
190     while ( p_temp_item->i_parents > 0 )
191     {
192         int i;
193         for (i = 0; i < p_temp_item->i_parents ; i++)
194         {
195             if (p_temp_item->pp_parents[i]->i_view == VIEW_SIMPLE)
196             {
197                 if (p_temp_item->pp_parents[i]->p_parent == p_node)
198                 {
199                     vlc_object_release(p_playlist);
200                     return YES;
201                 }
202                 else
203                 {
204                     p_temp_item = p_temp_item->pp_parents[i]->p_parent;
205                     break;
206                 }
207             }
208         }
209     }
210
211     vlc_object_release(p_playlist);
212     return NO;
213 }
214
215
216 - (IBAction)playItem:(id)sender
217 {
218     intf_thread_t * p_intf = VLCIntf;
219     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
220                                                        FIND_ANYWHERE );
221
222     if( p_playlist != NULL )
223     {
224         playlist_item_t *p_item;
225         playlist_item_t *p_node = NULL;
226         int i;
227
228         p_item = [[o_outline_view itemAtRow:[o_outline_view selectedRow]] pointerValue];
229
230         if( p_item )
231         {
232             if (p_item->i_children == -1)
233             {
234                 for (i = 0 ; i < p_item->i_parents ; i++)
235                 {
236                     if (p_item->pp_parents[i]->i_view == VIEW_SIMPLE)
237                     {
238                         p_node = p_item->pp_parents[i]->p_parent;
239                     }
240                 }
241             }
242             else
243             {
244                 p_node = p_item;
245                 if (p_node->pp_children[0]->i_children == -1 &&
246                     p_node->i_children > 0)
247                 {
248                     p_item = p_node->pp_children[0];
249                 }
250                 else
251                 {
252                     p_item = NULL;
253                 }
254             }
255
256 //        p_view = playlist_ViewFind( p_playlist, VIEW_SIMPLE );
257
258
259             playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, VIEW_SIMPLE, p_node, p_item );
260 //            playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, VIEW_SIMPLE, p_view ? p_view->p_root : NULL, p_item );
261         }
262         vlc_object_release( p_playlist );
263     }
264 }
265
266 - (IBAction)selectAll:(id)sender
267 {
268     [o_outline_view selectAll: nil];
269 }
270
271 - (IBAction)deleteItem:(id)sender
272 {
273     int i, c, i_row;
274     NSMutableArray *o_to_delete;
275     NSNumber *o_number;
276
277     playlist_t * p_playlist;
278     intf_thread_t * p_intf = VLCIntf;
279
280     p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
281                                           FIND_ANYWHERE );
282
283     if ( p_playlist == NULL )
284     {
285         return;
286     }
287     o_to_delete = [NSMutableArray arrayWithArray:[[o_outline_view selectedRowEnumerator] allObjects]];
288     c = [o_to_delete count];
289
290     for( i = 0; i < c; i++ ) {
291         playlist_item_t * p_item;
292         o_number = [o_to_delete lastObject];
293         i_row = [o_number intValue];
294
295         [o_to_delete removeObject: o_number];
296         [o_outline_view deselectRow: i_row];
297         p_item = (playlist_item_t *)[[o_outline_view itemAtRow: i_row]pointerValue];
298         if (p_item->i_children > -1)
299         {
300             if (p_playlist->status.i_status)
301             {
302                 if ([self isItem:p_playlist->status.p_item inNode: p_item]
303                                     == YES && p_playlist->status.i_status)
304                 {
305                     playlist_Stop( p_playlist );
306                 }
307             }
308             playlist_NodeDelete( p_playlist, p_item, VLC_TRUE);
309         }
310         else
311         {
312             if( p_playlist->status.p_item == [[o_outline_view itemAtRow: i_row]
313                         pointerValue] && p_playlist->status.i_status )
314             {
315                 playlist_Stop( p_playlist );
316             }
317             playlist_Delete( p_playlist, p_item->input.i_id );
318         }
319         [self playlistUpdated];
320     }
321 }
322
323 - (IBAction)sortNodeByName:(id)sender
324 {
325     [self sortNode: SORT_TITLE];
326 }
327
328 - (IBAction)sortNodeByAuthor:(id)sender
329 {
330     [self sortNode: SORT_AUTHOR];
331 }
332
333 - (void)sortNode:(int)i_mode
334 {
335     playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
336                                           FIND_ANYWHERE );
337     playlist_item_t * p_item;
338
339     if (p_playlist == NULL)
340     {
341         return;
342     }
343
344     if ([o_outline_view selectedRow] > -1)
345     {
346         p_item = [[o_outline_view itemAtRow: [o_outline_view selectedRow]]
347                                                                 pointerValue];
348     }
349     else
350     /*If no item is selected, sort the whole playlist*/
351     {
352         playlist_view_t * p_view = playlist_ViewFind( p_playlist, VIEW_SIMPLE );
353         p_item = p_view->p_root;
354     }
355
356     if (p_item->i_children > -1)
357     {
358         vlc_mutex_lock(&p_playlist->object_lock );
359         playlist_RecursiveNodeSort( p_playlist, p_item, i_mode, ORDER_NORMAL );
360         vlc_mutex_unlock(&p_playlist->object_lock );
361     }
362     else
363     {
364         int i;
365
366         for (i = 0 ; i < p_item->i_parents ; i++)
367         {
368             if (p_item->pp_parents[i]->i_view == VIEW_SIMPLE)
369             {
370                 vlc_mutex_lock(&p_playlist->object_lock );
371                 playlist_RecursiveNodeSort( p_playlist,
372                         p_item->pp_parents[i]->p_parent, i_mode, ORDER_NORMAL );
373                 vlc_mutex_unlock(&p_playlist->object_lock );
374                 break;
375             }
376         }
377     }
378     vlc_object_release(p_playlist);
379     [self playlistUpdated];
380 }
381
382 - (void)appendArray:(NSArray*)o_array atPos:(int)i_position enqueue:(BOOL)b_enqueue
383 {
384     int i_item;
385     intf_thread_t * p_intf = VLCIntf;
386     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
387                                                        FIND_ANYWHERE );
388
389     if( p_playlist == NULL )
390     {
391         return;
392     }
393
394     for ( i_item = 0; i_item < (int)[o_array count]; i_item++ )
395     {
396         /* One item */
397         NSDictionary *o_one_item;
398         int j, i_total_options = 0, i_new_id = -1;
399         int i_mode = PLAYLIST_INSERT;
400         BOOL b_rem = FALSE, b_dir = FALSE;
401         NSString *o_uri, *o_name;
402         NSArray *o_options;
403         NSURL *o_true_file;
404         char **ppsz_options = NULL;
405
406         /* Get the item */
407         o_one_item = [o_array objectAtIndex: i_item];
408         o_uri = (NSString *)[o_one_item objectForKey: @"ITEM_URL"];
409         o_name = (NSString *)[o_one_item objectForKey: @"ITEM_NAME"];
410         o_options = (NSArray *)[o_one_item objectForKey: @"ITEM_OPTIONS"];
411
412         /* If no name, then make a guess */
413         if( !o_name) o_name = [[NSFileManager defaultManager] displayNameAtPath: o_uri];
414
415         if( [[NSFileManager defaultManager] fileExistsAtPath:o_uri isDirectory:&b_dir] && b_dir &&
416             [[NSWorkspace sharedWorkspace] getFileSystemInfoForPath: o_uri isRemovable: &b_rem
417                     isWritable:NULL isUnmountable:NULL description:NULL type:NULL] && b_rem   )
418         {
419             /* All of this is to make sure CD's play when you D&D them on VLC */
420             /* Converts mountpoint to a /dev file */
421             struct statfs *buf;
422             char *psz_dev;
423             buf = (struct statfs *) malloc (sizeof(struct statfs));
424             statfs( [o_uri fileSystemRepresentation], buf );
425             psz_dev = strdup(buf->f_mntfromname);
426             o_uri = [NSString stringWithCString: psz_dev ];
427         }
428
429         if( o_options && [o_options count] > 0 )
430         {
431             /* Count the input options */
432             i_total_options = [o_options count];
433
434             /* Allocate ppsz_options */
435             for( j = 0; j < i_total_options; j++ )
436             {
437                 if( !ppsz_options )
438                     ppsz_options = (char **)malloc( sizeof(char *) * i_total_options );
439
440                 ppsz_options[j] = strdup([[o_options objectAtIndex:j] UTF8String]);
441             }
442         }
443
444         /* Add the item */
445         i_new_id = playlist_AddExt( p_playlist, [o_uri fileSystemRepresentation],
446                       [o_name UTF8String], i_mode,
447                       i_position == -1 ? PLAYLIST_END : i_position + i_item,
448                       0, (ppsz_options != NULL ) ? (const char **)ppsz_options : 0, i_total_options );
449
450         /* clean up
451         for( j = 0; j < i_total_options; j++ )
452             free( ppsz_options[j] );
453         if( ppsz_options ) free( ppsz_options ); */
454
455         /* Recent documents menu */
456         o_true_file = [NSURL fileURLWithPath: o_uri];
457         if( o_true_file != nil )
458         {
459             [[NSDocumentController sharedDocumentController]
460                 noteNewRecentDocumentURL: o_true_file];
461         }
462
463         if( i_item == 0 && !b_enqueue )
464         {
465             playlist_Goto( p_playlist, playlist_GetPositionById( p_playlist, i_new_id ) );
466             playlist_Play( p_playlist );
467         }
468     }
469
470     vlc_object_release( p_playlist );
471 }
472
473 - (IBAction)handlePopUp:(id)sender
474
475 {
476              intf_thread_t * p_intf = VLCIntf;
477              vlc_value_t val1,val2;
478              playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
479                                                         FIND_ANYWHERE );
480              if( p_playlist == NULL )
481              {
482                  return;
483              }
484
485     switch ([o_loop_popup indexOfSelectedItem])
486     {
487         case 1:
488
489              val1.b_bool = 0;
490              var_Set( p_playlist, "loop", val1 );
491              val1.b_bool = 1;
492              var_Set( p_playlist, "repeat", val1 );
493              vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat One" ) );
494         break;
495
496         case 2:
497              val1.b_bool = 0;
498              var_Set( p_playlist, "repeat", val1 );
499              val1.b_bool = 1;
500              var_Set( p_playlist, "loop", val1 );
501              vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat All" ) );
502         break;
503
504         default:
505              var_Get( p_playlist, "repeat", &val1 );
506              var_Get( p_playlist, "loop", &val2 );
507              if (val1.b_bool || val2.b_bool)
508              {
509                   val1.b_bool = 0;
510                   var_Set( p_playlist, "repeat", val1 );
511                   var_Set( p_playlist, "loop", val1 );
512                   vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat Off" ) );
513              }
514          break;
515      }
516      vlc_object_release( p_playlist );
517      [self playlistUpdated];
518 }
519
520 - (NSMutableArray *)subSearchItem:(playlist_item_t *)p_item
521 {
522     playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
523                                                        FIND_ANYWHERE );
524     playlist_item_t * p_selected_item;
525     int i_current, i_selected_row;
526
527     if (!p_playlist)
528         return NULL;
529
530     i_selected_row = [o_outline_view selectedRow];
531     if (i_selected_row < 0)
532         i_selected_row = 0;
533
534     p_selected_item = (playlist_item_t *)[[o_outline_view itemAtRow:
535                                             i_selected_row] pointerValue];
536
537     for (i_current = 0; i_current < p_item->i_children ; i_current++)
538     {
539         char * psz_temp;
540         NSString * o_current_name, * o_current_author;
541
542         vlc_mutex_lock( &p_playlist->object_lock );
543         o_current_name = [NSString stringWithUTF8String:
544             p_item->pp_children[i_current]->input.psz_name];
545         psz_temp = playlist_ItemGetInfo(p_item ,_("Meta-information"),_("Author") );
546         o_current_author = [NSString stringWithUTF8String: psz_temp];
547         free( psz_temp);
548         vlc_mutex_unlock( &p_playlist->object_lock );
549
550         if (p_selected_item == p_item->pp_children[i_current] &&
551                     b_selected_item_met == NO)
552         {
553             b_selected_item_met = YES;
554         }
555         else if (p_selected_item == p_item->pp_children[i_current] &&
556                     b_selected_item_met == YES)
557         {
558             vlc_object_release(p_playlist);
559             return NULL;
560         }
561         else if (b_selected_item_met == YES &&
562                     ([o_current_name rangeOfString:[o_search_field
563                         stringValue] options:NSCaseInsensitiveSearch ].length ||
564                     [o_current_author rangeOfString:[o_search_field
565                         stringValue] options:NSCaseInsensitiveSearch ].length))
566         {
567             vlc_object_release(p_playlist);
568             /*Adds the parent items in the result array as well, so that we can
569             expand the tree*/
570             return [NSMutableArray arrayWithObject: [NSValue
571                             valueWithPointer: p_item->pp_children[i_current]]];
572         }
573         if (p_item->pp_children[i_current]->i_children > 0)
574         {
575             id o_result = [self subSearchItem:
576                                             p_item->pp_children[i_current]];
577             if (o_result != NULL)
578             {
579                 vlc_object_release(p_playlist);
580                 [o_result insertObject: [NSValue valueWithPointer:
581                                 p_item->pp_children[i_current]] atIndex:0];
582                 return o_result;
583             }
584         }
585     }
586     vlc_object_release(p_playlist);
587     return NULL;
588 }
589
590 - (IBAction)searchItem:(id)sender
591 {
592     playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
593                                                        FIND_ANYWHERE );
594     playlist_view_t * p_view;
595     id o_result;
596
597     unsigned int i;
598     int i_row = -1;
599
600     b_selected_item_met = NO;
601
602     if( p_playlist == NULL )
603         return;
604
605     p_view = playlist_ViewFind( p_playlist, VIEW_SIMPLE );
606
607     if (p_view)
608     {
609         /*First, only search after the selected item:*
610          *(b_selected_item_met = NO)                 */
611         o_result = [self subSearchItem:p_view->p_root];
612         if (o_result == NULL)
613         {
614             /* If the first search failed, search again from the beginning */
615             o_result = [self subSearchItem:p_view->p_root];
616         }
617         if (o_result != NULL)
618         {
619             for (i = 0 ; i < [o_result count] - 1 ; i++)
620             {
621                 [o_outline_view expandItem: [o_outline_dict objectForKey:
622                             [NSString stringWithFormat: @"%p",
623                             [[o_result objectAtIndex: i] pointerValue]]]];
624             }
625             i_row = [o_outline_view rowForItem: [o_outline_dict objectForKey:
626                             [NSString stringWithFormat: @"%p",
627                             [[o_result objectAtIndex: [o_result count] - 1 ]
628                             pointerValue]]]];
629         }
630         if (i_row > -1)
631         {
632             [o_outline_view selectRow:i_row byExtendingSelection: NO];
633             [o_outline_view scrollRowToVisible: i_row];
634         }
635     }
636     vlc_object_release(p_playlist);
637
638 }
639
640 - (NSMenu *)menuForEvent:(NSEvent *)o_event
641 {
642     NSPoint pt;
643     vlc_bool_t b_rows;
644     vlc_bool_t b_item_sel;
645
646     pt = [o_outline_view convertPoint: [o_event locationInWindow]
647                                                  fromView: nil];
648     b_item_sel = ( [o_outline_view rowAtPoint: pt] != -1 &&
649                    [o_outline_view selectedRow] != -1 );
650     b_rows = [o_outline_view numberOfRows] != 0;
651
652     [o_mi_play setEnabled: b_item_sel];
653     [o_mi_delete setEnabled: b_item_sel];
654     [o_mi_selectall setEnabled: b_rows];
655     [o_mi_info setEnabled: b_item_sel];
656
657     return( o_ctx_menu );
658 }
659
660 - (playlist_item_t *)selectedPlaylistItem
661 {
662     return [[o_outline_view itemAtRow: [o_outline_view selectedRow]]
663                                                                 pointerValue];
664 }
665
666 @end
667
668 @implementation VLCPlaylist (NSOutlineViewDataSource)
669
670 /* return the number of children for Obj-C pointer item */ /* DONE */
671 - (int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
672 {
673     int i_return = 0;
674     playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
675                                                        FIND_ANYWHERE );
676     if( p_playlist == NULL )
677         return 0;
678
679     if( item == nil )
680     {
681         /* root object */
682         playlist_view_t *p_view;
683         p_view = playlist_ViewFind( p_playlist, VIEW_SIMPLE );
684         if( p_view && p_view->p_root )
685             i_return = p_view->p_root->i_children;
686     }
687     else
688     {
689         playlist_item_t *p_item = (playlist_item_t *)[item pointerValue];
690         if( p_item )
691             i_return = p_item->i_children;
692     }
693     vlc_object_release( p_playlist );
694     if( i_return == -1 ) i_return = 0;
695     msg_Dbg( p_playlist, "I have %d children", i_return );
696     return i_return;
697 }
698
699 /* return the child at index for the Obj-C pointer item */ /* DONE */
700 - (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item
701 {
702     playlist_item_t *p_return = NULL;
703     playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
704                                                        FIND_ANYWHERE );
705     NSValue * o_value;
706
707     if( p_playlist == NULL )
708         return nil;
709
710     if( item == nil )
711     {
712         /* root object */
713         playlist_view_t *p_view;
714         p_view = playlist_ViewFind( p_playlist, VIEW_SIMPLE );
715         if( p_view && index < p_view->p_root->i_children )
716             p_return = p_view->p_root->pp_children[index];
717     }
718     else
719     {
720         playlist_item_t *p_item = (playlist_item_t *)[item pointerValue];
721         if( p_item && index < p_item->i_children )
722         {
723             p_return = p_item->pp_children[index];
724         }
725     }
726
727     [o_status_field setStringValue: [NSString stringWithFormat:
728                         _NS("%i items in playlist"), p_playlist->i_size]];
729
730     vlc_object_release( p_playlist );
731     msg_Dbg( p_playlist, "childitem with index %d", index );
732
733     o_value = [NSValue valueWithPointer: p_return];
734
735     [o_outline_dict setObject:o_value forKey:[NSString stringWithFormat:@"%p",                                                                      p_return]];
736     return o_value;
737 }
738
739 /* is the item expandable */
740 - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item
741 {
742     int i_return = 0;
743     playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
744                                                        FIND_ANYWHERE );
745     if( p_playlist == NULL )
746         return NO;
747
748     if( item == nil )
749     {
750         /* root object */
751         playlist_view_t *p_view;
752         p_view = playlist_ViewFind( p_playlist, VIEW_SIMPLE );
753         if( p_view && p_view->p_root )
754             i_return = p_view->p_root->i_children;
755     }
756     else
757     {
758         playlist_item_t *p_item = (playlist_item_t *)[item pointerValue];
759         if( p_item )
760             i_return = p_item->i_children;
761     }
762     vlc_object_release( p_playlist );
763
764     if( i_return == -1 || i_return == 0 )
765         return NO;
766     else
767         return YES;
768 }
769
770 /* retrieve the string values for the cells */
771 - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)o_tc byItem:(id)item
772 {
773     id o_value = nil;
774     intf_thread_t * p_intf = VLCIntf;
775     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
776                                                FIND_ANYWHERE );
777     playlist_item_t *p_item = (playlist_item_t *)[item pointerValue];
778
779     if( p_playlist == NULL || p_item == NULL )
780     {
781         return( @"error" );
782     }
783
784     if( [[o_tc identifier] isEqualToString:@"1"] )
785     {
786         o_value = [NSString stringWithUTF8String:
787             p_item->input.psz_name];
788         if( o_value == NULL )
789             o_value = [NSString stringWithCString:
790                 p_item->input.psz_name];
791     }
792     else if( [[o_tc identifier] isEqualToString:@"2"] )
793     {
794         char *psz_temp;
795         psz_temp = playlist_ItemGetInfo( p_item ,_("Meta-information"),_("Artist") );
796
797         if( psz_temp == NULL )
798             o_value = @"";
799         else
800         {
801             o_value = [NSString stringWithUTF8String: psz_temp];
802             if( o_value == NULL )
803             {
804                 o_value = [NSString stringWithCString: psz_temp];
805             }
806             free( psz_temp );
807         }
808     }
809     else if( [[o_tc identifier] isEqualToString:@"3"] )
810     {
811         char psz_duration[MSTRTIME_MAX_SIZE];
812         mtime_t dur = p_item->input.i_duration;
813         if( dur != -1 )
814         {
815             secstotimestr( psz_duration, dur/1000000 );
816             o_value = [NSString stringWithUTF8String: psz_duration];
817         }
818         else
819         {
820             o_value = @"-:--:--";
821         }
822     }
823
824     vlc_object_release( p_playlist );
825
826     return( o_value );
827 }
828
829 /* Required for drag & drop and reordering */
830 - (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pboard
831 {
832     return NO;
833 }
834
835 - (NSDragOperation)outlineView:(NSOutlineView *)outlineView validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(int)index
836 {
837     return NSDragOperationNone;
838 }
839
840 /* Delegate method of NSWindow */
841 - (void)windowWillClose:(NSNotification *)aNotification
842 {
843     [o_btn_playlist setState: NSOffState];
844 }
845
846 @end
847
848