1 /*****************************************************************************
2 * playlist.m: MacOS X interface module
3 *****************************************************************************
4 * Copyright (C) 2002-2004 VideoLAN
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>
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.
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.
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 *****************************************************************************/
27 * add 'icons' for different types of nodes? (http://www.cocoadev.com/index.pl?IconAndTextInTableCell)
28 * create a new 'playlist toggle' that hides the playlist and in effect give you the old controller
29 * create a new search field build with pictures from the 'regular' search field, so it can be emulated on 10.2
30 * create toggle buttons for the shuffle, repeat one, repeat all functions.
31 * implement drag and drop and item reordering.
32 * reimplement enable/disable item
33 * create a new 'tool' button (see the gear button in the Finder window) for 'actions'
34 (adding service discovery, other views, new node/playlist, save node/playlist) stuff like that
38 /*****************************************************************************
40 *****************************************************************************/
41 #include <stdlib.h> /* malloc(), free() */
42 #include <sys/param.h> /* for MAXPATHLEN */
45 #include <sys/mount.h>
54 #define REF_HEIGHT 500
57 /*****************************************************************************
58 * VLCPlaylistView implementation
59 *****************************************************************************/
60 @implementation VLCPlaylistView
62 - (NSMenu *)menuForEvent:(NSEvent *)o_event
64 return( [[self delegate] menuForEvent: o_event] );
67 - (void)keyDown:(NSEvent *)o_event
71 if( [[o_event characters] length] )
73 key = [[o_event characters] characterAtIndex: 0];
78 case NSDeleteCharacter:
79 case NSDeleteFunctionKey:
80 case NSDeleteCharFunctionKey:
81 case NSBackspaceCharacter:
82 [[self delegate] deleteItem:self];
86 [super keyDown: o_event];
93 /*****************************************************************************
94 * VLCPlaylist implementation
95 *****************************************************************************/
96 @implementation VLCPlaylist
103 o_outline_dict = [[NSMutableDictionary alloc] init];
111 playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
113 i_current_view = VIEW_CATEGORY;
114 playlist_ViewUpdate( p_playlist, i_current_view );
115 vlc_object_release( p_playlist );
117 [o_outline_view setTarget: self];
118 [o_outline_view setDelegate: self];
119 [o_outline_view setDataSource: self];
121 [o_outline_view setDoubleAction: @selector(playItem:)];
123 [o_outline_view registerForDraggedTypes:
124 [NSArray arrayWithObjects: NSFilenamesPboardType, nil]];
125 [o_outline_view setIntercellSpacing: NSMakeSize (0.0, 1.0)];
127 /* We need to check whether _defaultTableHeaderSortImage exists, since it
128 belongs to an Apple hidden private API, and then can "disapear" at any time*/
130 if( [[NSOutlineView class] respondsToSelector:@selector(_defaultTableHeaderSortImage)] )
132 o_ascendingSortingImage = [[NSOutlineView class] _defaultTableHeaderSortImage];
136 o_ascendingSortingImage = nil;
139 if( [[NSOutlineView class] respondsToSelector:@selector(_defaultTableHeaderReverseSortImage)] )
141 o_descendingSortingImage = [[NSOutlineView class] _defaultTableHeaderReverseSortImage];
145 o_descendingSortingImage = nil;
148 o_tc_sortColumn = nil;
151 //[self playlistUpdated];
156 [o_mi_save_playlist setTitle: _NS("Save Playlist...")];
157 [o_mi_play setTitle: _NS("Play")];
158 [o_mi_delete setTitle: _NS("Delete")];
159 [o_mi_selectall setTitle: _NS("Select All")];
160 [o_mi_info setTitle: _NS("Properties")];
161 [o_mi_sort_name setTitle: _NS("Sort Node by Name")];
162 [o_mi_sort_author setTitle: _NS("Sort Node by Author")];
163 [[o_tc_name headerCell] setStringValue:_NS("Name")];
164 [[o_tc_author headerCell] setStringValue:_NS("Author")];
165 [[o_tc_duration headerCell] setStringValue:_NS("Duration")];
166 [o_status_field setStringValue: [NSString stringWithFormat:
167 _NS("no items in playlist")]];
169 [o_random_ckb setTitle: _NS("Random")];
171 [o_search_button setTitle: _NS("Search")];
173 [o_btn_playlist setToolTip: _NS("Playlist")];
174 [[o_loop_popup itemAtIndex:0] setTitle: _NS("Standard Play")];
175 [[o_loop_popup itemAtIndex:1] setTitle: _NS("Repeat One")];
176 [[o_loop_popup itemAtIndex:2] setTitle: _NS("Repeat All")];
179 - (NSOutlineView *)playlistView
181 return o_outline_view;
184 - (IBAction)toggleWindow:(id)sender
187 /*First, check if the playlist is visible*/
188 if ( [o_controller frame].size.height == [o_controller minSize].height )
190 /*Check if the stored heigth of the controller is usable (!= minSize)*/
191 if ([o_controller getSizeWithPlaylist].height !=
192 [o_controller minSize].height)
194 o_rect.size.height = [o_controller getSizeWithPlaylist].height;
198 /*If the stored height is not usable, use a reference one*/
199 o_rect.size.height = REF_HEIGHT;
202 /*Check if the controller width is the minimum one*/
203 if ( [o_controller frame].size.width == [o_controller minSize].width)
205 /*If the controller width is minimum, check if the stored height
206 of the playlist makes it visible*/
207 if ([o_controller getSizeWithPlaylist].height !=
208 [o_controller minSize].height)
210 o_rect.size.width = [o_controller getSizeWithPlaylist].width;
214 /*If not, use a reference width*/
215 o_rect.size.width = REF_WIDTH;
220 o_rect.size.width = [o_controller frame].size.width;
222 o_rect.origin.x = [o_controller frame].origin.x;
223 o_rect.origin.y = [o_controller frame].origin.y - o_rect.size.height +
224 [o_controller minSize].height;
226 [o_btn_playlist setState: YES];
230 o_rect.size = [o_controller minSize];
231 o_rect.origin.x = [o_controller frame].origin.x;
232 /*Calculate the position of the lower right corner after resize*/
233 o_rect.origin.y = [o_controller frame].origin.y +
234 [o_controller frame].size.height - [o_controller minSize].height;
236 [o_btn_playlist setState: NO];
239 [o_controller setFrame: o_rect display:YES animate: YES];
242 - (void)playlistUpdated
246 /* Clear indications of any existing column sorting*/
247 for( i = 0 ; i < [[o_outline_view tableColumns] count] ; i++ )
249 [o_outline_view setIndicatorImage:nil inTableColumn:
250 [[o_outline_view tableColumns] objectAtIndex:i]];
253 [o_outline_view setHighlightedTableColumn:nil];
254 o_tc_sortColumn = nil;
255 // TODO Find a way to keep the dict size to a minimum
256 //[o_outline_dict removeAllObjects];
257 [o_outline_view reloadData];
261 - (void)updateTogglePlaylistState
263 if( [o_controller getSizeWithPlaylist].height ==
264 [o_controller minSize].height )
266 [o_btn_playlist setState: NO];
270 [o_btn_playlist setState: YES];
274 - (void)updateRowSelection
279 playlist_t *p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
281 playlist_item_t *p_item, *p_temp_item;
282 NSMutableArray *o_array = [NSMutableArray array];
284 if( p_playlist == NULL )
287 p_item = p_playlist->status.p_item;
288 p_temp_item = p_item;
290 while( p_temp_item->i_parents > 0 )
292 [o_array insertObject: [NSValue valueWithPointer: p_temp_item] atIndex: 0];
293 for (i = 0 ; i < p_temp_item->i_parents ; i++)
295 if( p_temp_item->pp_parents[i]->i_view == i_current_view )
297 p_temp_item = p_temp_item->pp_parents[i]->p_parent;
303 for (j = 0 ; j < [o_array count] - 1 ; j++)
305 [o_outline_view expandItem: [o_outline_dict objectForKey:
306 [NSString stringWithFormat: @"%p",
307 [[o_array objectAtIndex:j] pointerValue]]]];
311 i_row = [o_outline_view rowForItem:[o_outline_dict
312 objectForKey:[NSString stringWithFormat: @"%p", p_item]]];
314 [o_outline_view selectRow: i_row byExtendingSelection: NO];
315 [o_outline_view scrollRowToVisible: i_row];
317 vlc_object_release(p_playlist);
321 - (BOOL)isItem: (playlist_item_t *)p_item inNode: (playlist_item_t *)p_node
323 playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
325 playlist_item_t *p_temp_item = p_item;
327 if( p_playlist == NULL )
332 while( p_temp_item->i_parents > 0 )
335 for( i = 0; i < p_temp_item->i_parents ; i++ )
337 if( p_temp_item->pp_parents[i]->i_view == i_current_view )
339 if( p_temp_item->pp_parents[i]->p_parent == p_node )
341 vlc_object_release( p_playlist );
346 p_temp_item = p_temp_item->pp_parents[i]->p_parent;
353 vlc_object_release( p_playlist );
358 /* When called retrieves the selected outlineview row and plays that node or item */
359 - (IBAction)playItem:(id)sender
361 intf_thread_t * p_intf = VLCIntf;
362 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
365 if( p_playlist != NULL )
367 playlist_item_t *p_item;
368 playlist_item_t *p_node = NULL;
371 p_item = [[o_outline_view itemAtRow:[o_outline_view selectedRow]] pointerValue];
375 if( p_item->i_children == -1 )
377 for( i = 0 ; i < p_item->i_parents ; i++ )
379 if( p_item->pp_parents[i]->i_view == i_current_view )
381 p_node = p_item->pp_parents[i]->p_parent;
388 if( p_node->i_children > 0 && p_node->pp_children[0]->i_children == -1 )
390 p_item = p_node->pp_children[0];
398 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, i_current_view, p_node, p_item );
400 vlc_object_release( p_playlist );
404 - (IBAction)selectAll:(id)sender
406 [o_outline_view selectAll: nil];
409 - (IBAction)deleteItem:(id)sender
411 int i, i_count, i_row;
412 NSMutableArray *o_to_delete;
415 playlist_t * p_playlist;
416 intf_thread_t * p_intf = VLCIntf;
418 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
421 if ( p_playlist == NULL )
425 o_to_delete = [NSMutableArray arrayWithArray:[[o_outline_view selectedRowEnumerator] allObjects]];
426 i_count = [o_to_delete count];
428 for( i = 0; i < i_count; i++ )
430 playlist_item_t * p_item;
431 o_number = [o_to_delete lastObject];
432 i_row = [o_number intValue];
434 [o_to_delete removeObject: o_number];
435 [o_outline_view deselectRow: i_row];
437 p_item = (playlist_item_t *)[[o_outline_view itemAtRow: i_row] pointerValue];
439 if( p_item->i_children > -1 ) //is a node and not an item
441 if( p_playlist->status.i_status != PLAYLIST_STOPPED &&
442 [self isItem: p_playlist->status.p_item inNode: p_item] == YES )
444 // if current item is in selected node and is playing then stop playlist
445 playlist_Stop( p_playlist );
447 playlist_NodeDelete( p_playlist, p_item, VLC_TRUE);
451 if( p_playlist->status.i_status != PLAYLIST_STOPPED &&
452 p_playlist->status.p_item == [[o_outline_view itemAtRow: i_row] pointerValue] )
454 playlist_Stop( p_playlist );
456 playlist_LockDelete( p_playlist, p_item->input.i_id );
459 [self playlistUpdated];
460 vlc_object_release( p_playlist );
463 - (IBAction)sortNodeByName:(id)sender
465 [self sortNode: SORT_TITLE];
468 - (IBAction)sortNodeByAuthor:(id)sender
470 [self sortNode: SORT_AUTHOR];
473 - (void)sortNode:(int)i_mode
475 playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
477 playlist_item_t * p_item;
479 if (p_playlist == NULL)
484 if( [o_outline_view selectedRow] > -1 )
486 p_item = [[o_outline_view itemAtRow: [o_outline_view selectedRow]]
490 /*If no item is selected, sort the whole playlist*/
492 playlist_view_t * p_view = playlist_ViewFind( p_playlist, i_current_view );
493 p_item = p_view->p_root;
496 if( p_item->i_children > -1 ) // the item is a node
498 vlc_mutex_lock( &p_playlist->object_lock );
499 playlist_RecursiveNodeSort( p_playlist, p_item, i_mode, ORDER_NORMAL );
500 vlc_mutex_unlock( &p_playlist->object_lock );
506 for( i = 0 ; i < p_item->i_parents ; i++ )
508 if( p_item->pp_parents[i]->i_view == i_current_view )
510 vlc_mutex_lock( &p_playlist->object_lock );
511 playlist_RecursiveNodeSort( p_playlist,
512 p_item->pp_parents[i]->p_parent, i_mode, ORDER_NORMAL );
513 vlc_mutex_unlock( &p_playlist->object_lock );
518 vlc_object_release( p_playlist );
519 [self playlistUpdated];
522 - (void)appendArray:(NSArray*)o_array atPos:(int)i_position enqueue:(BOOL)b_enqueue
525 intf_thread_t * p_intf = VLCIntf;
526 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
529 if( p_playlist == NULL )
534 for( i_item = 0; i_item < (int)[o_array count]; i_item++ )
537 NSDictionary *o_one_item;
538 int j, i_total_options = 0, i_new_id = -1;
539 int i_mode = PLAYLIST_INSERT;
540 BOOL b_rem = FALSE, b_dir = FALSE;
541 NSString *o_uri, *o_name;
544 char **ppsz_options = NULL;
547 o_one_item = [o_array objectAtIndex: i_item];
548 o_uri = (NSString *)[o_one_item objectForKey: @"ITEM_URL"];
549 o_name = (NSString *)[o_one_item objectForKey: @"ITEM_NAME"];
550 o_options = (NSArray *)[o_one_item objectForKey: @"ITEM_OPTIONS"];
552 /* If no name, then make a guess */
553 if( !o_name) o_name = [[NSFileManager defaultManager] displayNameAtPath: o_uri];
555 if( [[NSFileManager defaultManager] fileExistsAtPath:o_uri isDirectory:&b_dir] && b_dir &&
556 [[NSWorkspace sharedWorkspace] getFileSystemInfoForPath: o_uri isRemovable: &b_rem
557 isWritable:NULL isUnmountable:NULL description:NULL type:NULL] && b_rem )
559 /* All of this is to make sure CD's play when you D&D them on VLC */
560 /* Converts mountpoint to a /dev file */
563 buf = (struct statfs *) malloc (sizeof(struct statfs));
564 statfs( [o_uri fileSystemRepresentation], buf );
565 psz_dev = strdup(buf->f_mntfromname);
566 o_uri = [NSString stringWithCString: psz_dev ];
569 if( o_options && [o_options count] > 0 )
571 /* Count the input options */
572 i_total_options = [o_options count];
574 /* Allocate ppsz_options */
575 for( j = 0; j < i_total_options; j++ )
578 ppsz_options = (char **)malloc( sizeof(char *) * i_total_options );
580 ppsz_options[j] = strdup([[o_options objectAtIndex:j] UTF8String]);
585 i_new_id = playlist_AddExt( p_playlist, [o_uri fileSystemRepresentation],
586 [o_name UTF8String], i_mode,
587 i_position == -1 ? PLAYLIST_END : i_position + i_item,
588 0, (ppsz_options != NULL ) ? (const char **)ppsz_options : 0, i_total_options );
590 /* Recent documents menu */
591 o_true_file = [NSURL fileURLWithPath: o_uri];
592 if( o_true_file != nil )
594 [[NSDocumentController sharedDocumentController]
595 noteNewRecentDocumentURL: o_true_file];
598 if( i_item == 0 && !b_enqueue )
600 playlist_Goto( p_playlist, playlist_GetPositionById( p_playlist, i_new_id ) );
601 playlist_Play( p_playlist );
605 vlc_object_release( p_playlist );
608 - (IBAction)handlePopUp:(id)sender
611 intf_thread_t * p_intf = VLCIntf;
612 vlc_value_t val1,val2;
613 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
615 if( p_playlist == NULL )
620 switch( [o_loop_popup indexOfSelectedItem] )
625 var_Set( p_playlist, "loop", val1 );
627 var_Set( p_playlist, "repeat", val1 );
628 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat One" ) );
633 var_Set( p_playlist, "repeat", val1 );
635 var_Set( p_playlist, "loop", val1 );
636 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat All" ) );
640 var_Get( p_playlist, "repeat", &val1 );
641 var_Get( p_playlist, "loop", &val2 );
642 if( val1.b_bool || val2.b_bool )
645 var_Set( p_playlist, "repeat", val1 );
646 var_Set( p_playlist, "loop", val1 );
647 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat Off" ) );
651 vlc_object_release( p_playlist );
652 [self playlistUpdated];
655 - (NSMutableArray *)subSearchItem:(playlist_item_t *)p_item
657 playlist_t *p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
659 playlist_item_t *p_selected_item;
660 int i_current, i_selected_row;
665 i_selected_row = [o_outline_view selectedRow];
666 if (i_selected_row < 0)
669 p_selected_item = (playlist_item_t *)[[o_outline_view itemAtRow:
670 i_selected_row] pointerValue];
672 for( i_current = 0; i_current < p_item->i_children ; i_current++ )
675 NSString *o_current_name, *o_current_author;
677 vlc_mutex_lock( &p_playlist->object_lock );
678 o_current_name = [NSString stringWithUTF8String:
679 p_item->pp_children[i_current]->input.psz_name];
680 psz_temp = vlc_input_item_GetInfo( &p_item->input ,
681 _("Meta-information"),_("Author") );
682 o_current_author = [NSString stringWithUTF8String: psz_temp];
684 vlc_mutex_unlock( &p_playlist->object_lock );
686 if( p_selected_item == p_item->pp_children[i_current] &&
687 b_selected_item_met == NO )
689 b_selected_item_met = YES;
691 else if( p_selected_item == p_item->pp_children[i_current] &&
692 b_selected_item_met == YES )
694 vlc_object_release( p_playlist );
697 else if( b_selected_item_met == YES &&
698 ( [o_current_name rangeOfString:[o_search_field
699 stringValue] options:NSCaseInsensitiveSearch ].length ||
700 [o_current_author rangeOfString:[o_search_field
701 stringValue] options:NSCaseInsensitiveSearch ].length ) )
703 vlc_object_release( p_playlist );
704 /*Adds the parent items in the result array as well, so that we can
706 return [NSMutableArray arrayWithObject: [NSValue
707 valueWithPointer: p_item->pp_children[i_current]]];
709 if( p_item->pp_children[i_current]->i_children > 0 )
711 id o_result = [self subSearchItem:
712 p_item->pp_children[i_current]];
713 if( o_result != NULL )
715 vlc_object_release( p_playlist );
716 [o_result insertObject: [NSValue valueWithPointer:
717 p_item->pp_children[i_current]] atIndex:0];
722 vlc_object_release( p_playlist );
726 - (IBAction)searchItem:(id)sender
728 playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
730 playlist_view_t * p_view;
736 b_selected_item_met = NO;
738 if( p_playlist == NULL )
741 p_view = playlist_ViewFind( p_playlist, i_current_view );
745 /*First, only search after the selected item:*
746 *(b_selected_item_met = NO) */
747 o_result = [self subSearchItem:p_view->p_root];
748 if( o_result == NULL )
750 /* If the first search failed, search again from the beginning */
751 o_result = [self subSearchItem:p_view->p_root];
753 if( o_result != NULL )
755 for( i = 0 ; i < [o_result count] - 1 ; i++ )
757 [o_outline_view expandItem: [o_outline_dict objectForKey:
758 [NSString stringWithFormat: @"%p",
759 [[o_result objectAtIndex: i] pointerValue]]]];
761 i_row = [o_outline_view rowForItem: [o_outline_dict objectForKey:
762 [NSString stringWithFormat: @"%p",
763 [[o_result objectAtIndex: [o_result count] - 1 ]
768 [o_outline_view selectRow:i_row byExtendingSelection: NO];
769 [o_outline_view scrollRowToVisible: i_row];
772 vlc_object_release( p_playlist );
775 - (NSMenu *)menuForEvent:(NSEvent *)o_event
779 vlc_bool_t b_item_sel;
781 pt = [o_outline_view convertPoint: [o_event locationInWindow]
783 b_item_sel = ( [o_outline_view rowAtPoint: pt] != -1 &&
784 [o_outline_view selectedRow] != -1 );
785 b_rows = [o_outline_view numberOfRows] != 0;
787 [o_mi_play setEnabled: b_item_sel];
788 [o_mi_delete setEnabled: b_item_sel];
789 [o_mi_selectall setEnabled: b_rows];
790 [o_mi_info setEnabled: b_item_sel];
792 return( o_ctx_menu );
795 - (playlist_item_t *)selectedPlaylistItem
797 return [[o_outline_view itemAtRow: [o_outline_view selectedRow]]
801 - (void)outlineView: (NSTableView*)o_tv
802 didClickTableColumn:(NSTableColumn *)o_tc
804 int i_mode = 0, i_type;
805 intf_thread_t *p_intf = VLCIntf;
806 playlist_view_t *p_view;
808 playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
810 if( p_playlist == NULL )
815 /* Check whether the selected table column header corresponds to a
816 sortable table column*/
817 if( !( o_tc == o_tc_name || o_tc == o_tc_author ) )
819 vlc_object_release( p_playlist );
823 p_view = playlist_ViewFind( p_playlist, i_current_view );
825 if( o_tc_sortColumn == o_tc )
827 b_isSortDescending = !b_isSortDescending;
831 b_isSortDescending = VLC_FALSE;
834 if( o_tc == o_tc_name )
838 else if( o_tc == o_tc_author )
840 i_mode = SORT_AUTHOR;
843 if( b_isSortDescending )
845 i_type = ORDER_REVERSE;
849 i_type = ORDER_NORMAL;
852 vlc_mutex_lock( &p_playlist->object_lock );
853 playlist_RecursiveNodeSort( p_playlist, p_view->p_root, i_mode, i_type );
854 vlc_mutex_unlock( &p_playlist->object_lock );
856 vlc_object_release( p_playlist );
857 [self playlistUpdated];
859 o_tc_sortColumn = o_tc;
860 [o_outline_view setHighlightedTableColumn:o_tc];
862 if( b_isSortDescending )
864 [o_outline_view setIndicatorImage:o_descendingSortingImage
869 [o_outline_view setIndicatorImage:o_ascendingSortingImage
876 @implementation VLCPlaylist (NSOutlineViewDataSource)
878 /* return the number of children for Obj-C pointer item */ /* DONE */
879 - (int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
882 playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
884 if( p_playlist == NULL || outlineView != o_outline_view )
890 playlist_view_t *p_view;
891 p_view = playlist_ViewFind( p_playlist, i_current_view );
892 if( p_view && p_view->p_root )
893 i_return = p_view->p_root->i_children;
897 playlist_item_t *p_item = (playlist_item_t *)[item pointerValue];
899 i_return = p_item->i_children;
901 vlc_object_release( p_playlist );
909 /* return the child at index for the Obj-C pointer item */ /* DONE */
910 - (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item
912 playlist_item_t *p_return = NULL;
913 playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
917 if( p_playlist == NULL )
923 playlist_view_t *p_view;
924 p_view = playlist_ViewFind( p_playlist, i_current_view );
925 if( p_view && index < p_view->p_root->i_children && index >= 0 )
926 p_return = p_view->p_root->pp_children[index];
930 playlist_item_t *p_item = (playlist_item_t *)[item pointerValue];
931 if( p_item && index < p_item->i_children && index >= 0 )
932 p_return = p_item->pp_children[index];
935 if( p_playlist->i_size >= 2 )
937 [o_status_field setStringValue: [NSString stringWithFormat:
938 _NS("%i items in playlist"), p_playlist->i_size]];
942 if( p_playlist->i_size == 0 )
944 [o_status_field setStringValue: [NSString stringWithFormat:
945 _NS("no items in playlist"), p_playlist->i_size]];
949 [o_status_field setStringValue: [NSString stringWithFormat:
950 _NS("1 item in playlist"), p_playlist->i_size]];
954 vlc_object_release( p_playlist );
957 o_value = [[NSValue valueWithPointer: p_return] retain];
959 if( [o_outline_dict objectForKey: [NSString stringWithFormat:@"%p", p_return]] == nil )
961 [o_outline_dict setObject:o_value forKey:[NSString stringWithFormat:@"%p", p_return]];
966 /* is the item expandable */
967 - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item
970 playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
972 if( p_playlist == NULL )
978 playlist_view_t *p_view;
979 p_view = playlist_ViewFind( p_playlist, i_current_view );
980 if( p_view && p_view->p_root )
981 i_return = p_view->p_root->i_children;
985 playlist_item_t *p_item = (playlist_item_t *)[item pointerValue];
987 i_return = p_item->i_children;
989 vlc_object_release( p_playlist );
997 /* retrieve the string values for the cells */
998 - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)o_tc byItem:(id)item
1001 intf_thread_t *p_intf = VLCIntf;
1002 playlist_t *p_playlist;
1003 playlist_item_t *p_item;
1005 if( item == nil || ![item isKindOfClass: [NSValue class]] ) return( @"error" );
1007 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1009 if( p_playlist == NULL )
1014 p_item = (playlist_item_t *)[item pointerValue];
1016 if( p_item == NULL )
1018 vlc_object_release( p_playlist );
1022 if( [[o_tc identifier] isEqualToString:@"1"] )
1024 o_value = [NSString stringWithUTF8String:
1025 p_item->input.psz_name];
1026 if( o_value == NULL )
1027 o_value = [NSString stringWithCString:
1028 p_item->input.psz_name];
1030 else if( [[o_tc identifier] isEqualToString:@"2"] )
1033 psz_temp = vlc_input_item_GetInfo( &p_item->input ,_("Meta-information"),_("Artist") );
1035 if( psz_temp == NULL )
1039 o_value = [NSString stringWithUTF8String: psz_temp];
1040 if( o_value == NULL )
1042 o_value = [NSString stringWithCString: psz_temp];
1047 else if( [[o_tc identifier] isEqualToString:@"3"] )
1049 char psz_duration[MSTRTIME_MAX_SIZE];
1050 mtime_t dur = p_item->input.i_duration;
1053 secstotimestr( psz_duration, dur/1000000 );
1054 o_value = [NSString stringWithUTF8String: psz_duration];
1058 o_value = @"-:--:--";
1061 vlc_object_release( p_playlist );
1066 /* Required for drag & drop and reordering */
1067 - (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pboard
1072 - (NSDragOperation)outlineView:(NSOutlineView *)outlineView validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(int)index
1074 return NSDragOperationNone;
1077 /* Delegate method of NSWindow */
1078 /*- (void)windowWillClose:(NSNotification *)aNotification
1080 [o_btn_playlist setState: NSOffState];