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