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