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
39 /*****************************************************************************
41 *****************************************************************************/
42 #include <stdlib.h> /* malloc(), free() */
43 #include <sys/param.h> /* for MAXPATHLEN */
46 #include <sys/mount.h>
55 #define REF_HEIGHT 500
58 /*****************************************************************************
59 * VLCPlaylistView implementation
60 *****************************************************************************/
61 @implementation VLCPlaylistView
63 - (NSMenu *)menuForEvent:(NSEvent *)o_event
65 return( [[self delegate] menuForEvent: o_event] );
68 - (void)keyDown:(NSEvent *)o_event
72 if( [[o_event characters] length] )
74 key = [[o_event characters] characterAtIndex: 0];
79 case NSDeleteCharacter:
80 case NSDeleteFunctionKey:
81 case NSDeleteCharFunctionKey:
82 case NSBackspaceCharacter:
83 [[self delegate] deleteItem:self];
87 [super keyDown: o_event];
94 /*****************************************************************************
95 * VLCPlaylist implementation
96 *****************************************************************************/
97 @implementation VLCPlaylist
111 [o_outline_view setTarget: self];
112 [o_outline_view setDelegate: self];
113 [o_outline_view setDataSource: self];
115 [o_outline_view setDoubleAction: @selector(playItem:)];
117 [o_outline_view registerForDraggedTypes:
118 [NSArray arrayWithObjects: NSFilenamesPboardType, nil]];
119 [o_outline_view setIntercellSpacing: NSMakeSize (0.0, 1.0)];
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*/
124 if( [[NSOutlineView class] respondsToSelector:@selector(_defaultTableHeaderSortImage)] )
126 o_ascendingSortingImage = [[NSOutlineView class] _defaultTableHeaderSortImage];
130 o_ascendingSortingImage = nil;
133 if( [[NSOutlineView class] respondsToSelector:@selector(_defaultTableHeaderReverseSortImage)] )
135 o_descendingSortingImage = [[NSOutlineView class] _defaultTableHeaderReverseSortImage];
139 o_descendingSortingImage = nil;
142 o_outline_dict = [[NSMutableDictionary alloc] init];
143 o_tc_sortColumn = nil;
146 //[self playlistUpdated];
151 [o_mi_save_playlist setTitle: _NS("Save Playlist...")];
152 [o_mi_play setTitle: _NS("Play")];
153 [o_mi_delete setTitle: _NS("Delete")];
154 [o_mi_selectall setTitle: _NS("Select All")];
155 [o_mi_info setTitle: _NS("Properties")];
156 [o_mi_sort_name setTitle: _NS("Sort Node by Name")];
157 [o_mi_sort_author setTitle: _NS("Sort Node by Author")];
158 [[o_tc_name headerCell] setStringValue:_NS("Name")];
159 [[o_tc_author headerCell] setStringValue:_NS("Author")];
160 [[o_tc_duration headerCell] setStringValue:_NS("Duration")];
161 [o_status_field setStringValue: [NSString stringWithFormat:
162 _NS("no items in playlist")]];
164 [o_random_ckb setTitle: _NS("Random")];
166 [o_search_button setTitle: _NS("Search")];
168 [o_btn_playlist setToolTip: _NS("Playlist")];
169 [[o_loop_popup itemAtIndex:0] setTitle: _NS("Standard Play")];
170 [[o_loop_popup itemAtIndex:1] setTitle: _NS("Repeat One")];
171 [[o_loop_popup itemAtIndex:2] setTitle: _NS("Repeat All")];
174 - (IBAction)toggleWindow:(id)sender
177 /*First, check if the playlist is visible*/
178 if ( [o_controller frame].size.height == [o_controller minSize].height )
180 /*Check if the stored heigth of the controller is usable (!= minSize)*/
181 if ([o_controller getSizeWithPlaylist].height !=
182 [o_controller minSize].height)
184 o_rect.size.height = [o_controller getSizeWithPlaylist].height;
188 /*If the stored height is not usable, use a reference one*/
189 o_rect.size.height = REF_HEIGHT;
192 /*Check if the controller width is the minimum one*/
193 if ( [o_controller frame].size.width == [o_controller minSize].width)
195 /*If the controller width is minimum, check if the stored height
196 of the playlist makes it visible*/
197 if ([o_controller getSizeWithPlaylist].height !=
198 [o_controller minSize].height)
200 o_rect.size.width = [o_controller getSizeWithPlaylist].width;
204 /*If not, use a reference width*/
205 o_rect.size.width = REF_WIDTH;
210 o_rect.size.width = [o_controller frame].size.width;
212 o_rect.origin.x = [o_controller frame].origin.x;
213 o_rect.origin.y = [o_controller frame].origin.y - o_rect.size.height +
214 [o_controller minSize].height;
216 [o_btn_playlist setState: YES];
220 o_rect.size = [o_controller minSize];
221 o_rect.origin.x = [o_controller frame].origin.x;
222 /*Calculate the position of the lower right corner after resize*/
223 o_rect.origin.y = [o_controller frame].origin.y +
224 [o_controller frame].size.height - [o_controller minSize].height;
226 [o_btn_playlist setState: NO];
229 [o_controller setFrame: o_rect display:YES animate: YES];
232 - (void)playlistUpdated
236 /* Clear indications of any existing column sorting*/
237 for( i = 0 ; i < [[o_outline_view tableColumns] count] ; i++ )
239 [o_outline_view setIndicatorImage:nil inTableColumn:
240 [[o_outline_view tableColumns] objectAtIndex:i]];
243 [o_outline_view setHighlightedTableColumn:nil];
244 o_tc_sortColumn = nil;
245 [o_outline_dict removeAllObjects];
246 [o_outline_view reloadData];
249 - (void)updateTogglePlaylistState
251 if ([o_controller getSizeWithPlaylist].height ==
252 [o_controller minSize].height)
254 [o_btn_playlist setState: NO];
258 [o_btn_playlist setState: YES];
262 - (void)updateRowSelection
264 playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
266 playlist_item_t * p_item, * p_temp_item;
267 NSMutableArray * o_array = [NSMutableArray array];
271 if (p_playlist == NULL)
274 p_item = p_playlist->status.p_item;
275 p_temp_item = p_item;
277 while (p_temp_item->i_parents > 0)
279 [o_array insertObject: [NSValue valueWithPointer: p_temp_item] atIndex: 0];
280 for (i = 0 ; i < p_temp_item->i_parents ; i++)
282 if (p_temp_item->pp_parents[i]->i_view == VIEW_SIMPLE)
284 p_temp_item = p_temp_item->pp_parents[i]->p_parent;
290 for (j = 0 ; j < [o_array count] - 1 ; j++)
292 [o_outline_view expandItem: [o_outline_dict objectForKey:
293 [NSString stringWithFormat: @"%p",
294 [[o_array objectAtIndex:j] pointerValue]]]];
298 i_row = [o_outline_view rowForItem:[o_outline_dict
299 objectForKey:[NSString stringWithFormat: @"%p", p_item]]];
301 [o_outline_view selectRow: i_row byExtendingSelection: NO];
302 [o_outline_view scrollRowToVisible: i_row];
304 vlc_object_release(p_playlist);
307 - (bool)isItem:(playlist_item_t *)p_item inNode:(playlist_item_t *)p_node
309 playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
311 playlist_item_t * p_temp_item = p_item;
313 if ( p_playlist == NULL )
318 while ( p_temp_item->i_parents > 0 )
321 for (i = 0; i < p_temp_item->i_parents ; i++)
323 if (p_temp_item->pp_parents[i]->i_view == VIEW_SIMPLE)
325 if (p_temp_item->pp_parents[i]->p_parent == p_node)
327 vlc_object_release(p_playlist);
332 p_temp_item = p_temp_item->pp_parents[i]->p_parent;
339 vlc_object_release(p_playlist);
344 - (IBAction)playItem:(id)sender
346 intf_thread_t * p_intf = VLCIntf;
347 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
350 if( p_playlist != NULL )
352 playlist_item_t *p_item;
353 playlist_item_t *p_node = NULL;
356 p_item = [[o_outline_view itemAtRow:[o_outline_view selectedRow]] pointerValue];
360 if (p_item->i_children == -1)
362 for (i = 0 ; i < p_item->i_parents ; i++)
364 if (p_item->pp_parents[i]->i_view == VIEW_SIMPLE)
366 p_node = p_item->pp_parents[i]->p_parent;
373 if (p_node->pp_children[0]->i_children == -1 &&
374 p_node->i_children > 0)
376 p_item = p_node->pp_children[0];
384 // p_view = playlist_ViewFind( p_playlist, VIEW_SIMPLE );
387 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, VIEW_SIMPLE, p_node, p_item );
388 // playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, VIEW_SIMPLE, p_view ? p_view->p_root : NULL, p_item );
390 vlc_object_release( p_playlist );
394 - (IBAction)selectAll:(id)sender
396 [o_outline_view selectAll: nil];
399 - (IBAction)deleteItem:(id)sender
402 NSMutableArray *o_to_delete;
405 playlist_t * p_playlist;
406 intf_thread_t * p_intf = VLCIntf;
408 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
411 if ( p_playlist == NULL )
415 o_to_delete = [NSMutableArray arrayWithArray:[[o_outline_view selectedRowEnumerator] allObjects]];
416 c = [o_to_delete count];
418 for( i = 0; i < c; i++ ) {
419 playlist_item_t * p_item;
420 o_number = [o_to_delete lastObject];
421 i_row = [o_number intValue];
423 [o_to_delete removeObject: o_number];
424 [o_outline_view deselectRow: i_row];
425 p_item = (playlist_item_t *)[[o_outline_view itemAtRow: i_row]pointerValue];
426 if (p_item->i_children > -1)
428 if (p_playlist->status.i_status)
430 if ([self isItem:p_playlist->status.p_item inNode: p_item]
431 == YES && p_playlist->status.i_status)
433 playlist_Stop( p_playlist );
436 playlist_NodeDelete( p_playlist, p_item, VLC_TRUE);
440 if( p_playlist->status.p_item == [[o_outline_view itemAtRow: i_row]
441 pointerValue] && p_playlist->status.i_status )
443 playlist_Stop( p_playlist );
445 playlist_LockDelete( p_playlist, p_item->input.i_id );
447 [self playlistUpdated];
451 - (IBAction)sortNodeByName:(id)sender
453 [self sortNode: SORT_TITLE];
456 - (IBAction)sortNodeByAuthor:(id)sender
458 [self sortNode: SORT_AUTHOR];
461 - (void)sortNode:(int)i_mode
463 playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
465 playlist_item_t * p_item;
467 if (p_playlist == NULL)
472 if ([o_outline_view selectedRow] > -1)
474 p_item = [[o_outline_view itemAtRow: [o_outline_view selectedRow]]
478 /*If no item is selected, sort the whole playlist*/
480 playlist_view_t * p_view = playlist_ViewFind( p_playlist, VIEW_SIMPLE );
481 p_item = p_view->p_root;
484 if (p_item->i_children > -1)
486 vlc_mutex_lock(&p_playlist->object_lock );
487 playlist_RecursiveNodeSort( p_playlist, p_item, i_mode, ORDER_NORMAL );
488 vlc_mutex_unlock(&p_playlist->object_lock );
494 for (i = 0 ; i < p_item->i_parents ; i++)
496 if (p_item->pp_parents[i]->i_view == VIEW_SIMPLE)
498 vlc_mutex_lock(&p_playlist->object_lock );
499 playlist_RecursiveNodeSort( p_playlist,
500 p_item->pp_parents[i]->p_parent, i_mode, ORDER_NORMAL );
501 vlc_mutex_unlock(&p_playlist->object_lock );
506 vlc_object_release(p_playlist);
507 [self playlistUpdated];
510 - (void)appendArray:(NSArray*)o_array atPos:(int)i_position enqueue:(BOOL)b_enqueue
513 intf_thread_t * p_intf = VLCIntf;
514 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
517 if( p_playlist == NULL )
522 for ( i_item = 0; i_item < (int)[o_array count]; i_item++ )
525 NSDictionary *o_one_item;
526 int j, i_total_options = 0, i_new_id = -1;
527 int i_mode = PLAYLIST_INSERT;
528 BOOL b_rem = FALSE, b_dir = FALSE;
529 NSString *o_uri, *o_name;
532 char **ppsz_options = NULL;
535 o_one_item = [o_array objectAtIndex: i_item];
536 o_uri = (NSString *)[o_one_item objectForKey: @"ITEM_URL"];
537 o_name = (NSString *)[o_one_item objectForKey: @"ITEM_NAME"];
538 o_options = (NSArray *)[o_one_item objectForKey: @"ITEM_OPTIONS"];
540 /* If no name, then make a guess */
541 if( !o_name) o_name = [[NSFileManager defaultManager] displayNameAtPath: o_uri];
543 if( [[NSFileManager defaultManager] fileExistsAtPath:o_uri isDirectory:&b_dir] && b_dir &&
544 [[NSWorkspace sharedWorkspace] getFileSystemInfoForPath: o_uri isRemovable: &b_rem
545 isWritable:NULL isUnmountable:NULL description:NULL type:NULL] && b_rem )
547 /* All of this is to make sure CD's play when you D&D them on VLC */
548 /* Converts mountpoint to a /dev file */
551 buf = (struct statfs *) malloc (sizeof(struct statfs));
552 statfs( [o_uri fileSystemRepresentation], buf );
553 psz_dev = strdup(buf->f_mntfromname);
554 o_uri = [NSString stringWithCString: psz_dev ];
557 if( o_options && [o_options count] > 0 )
559 /* Count the input options */
560 i_total_options = [o_options count];
562 /* Allocate ppsz_options */
563 for( j = 0; j < i_total_options; j++ )
566 ppsz_options = (char **)malloc( sizeof(char *) * i_total_options );
568 ppsz_options[j] = strdup([[o_options objectAtIndex:j] UTF8String]);
573 i_new_id = playlist_AddExt( p_playlist, [o_uri fileSystemRepresentation],
574 [o_name UTF8String], i_mode,
575 i_position == -1 ? PLAYLIST_END : i_position + i_item,
576 0, (ppsz_options != NULL ) ? (const char **)ppsz_options : 0, i_total_options );
579 for( j = 0; j < i_total_options; j++ )
580 free( ppsz_options[j] );
581 if( ppsz_options ) free( ppsz_options ); */
583 /* Recent documents menu */
584 o_true_file = [NSURL fileURLWithPath: o_uri];
585 if( o_true_file != nil )
587 [[NSDocumentController sharedDocumentController]
588 noteNewRecentDocumentURL: o_true_file];
591 if( i_item == 0 && !b_enqueue )
593 playlist_Goto( p_playlist, playlist_GetPositionById( p_playlist, i_new_id ) );
594 playlist_Play( p_playlist );
598 vlc_object_release( p_playlist );
601 - (IBAction)handlePopUp:(id)sender
604 intf_thread_t * p_intf = VLCIntf;
605 vlc_value_t val1,val2;
606 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
608 if( p_playlist == NULL )
613 switch ([o_loop_popup indexOfSelectedItem])
618 var_Set( p_playlist, "loop", val1 );
620 var_Set( p_playlist, "repeat", val1 );
621 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat One" ) );
626 var_Set( p_playlist, "repeat", val1 );
628 var_Set( p_playlist, "loop", val1 );
629 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat All" ) );
633 var_Get( p_playlist, "repeat", &val1 );
634 var_Get( p_playlist, "loop", &val2 );
635 if (val1.b_bool || val2.b_bool)
638 var_Set( p_playlist, "repeat", val1 );
639 var_Set( p_playlist, "loop", val1 );
640 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat Off" ) );
644 vlc_object_release( p_playlist );
645 [self playlistUpdated];
648 - (NSMutableArray *)subSearchItem:(playlist_item_t *)p_item
650 playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
652 playlist_item_t * p_selected_item;
653 int i_current, i_selected_row;
658 i_selected_row = [o_outline_view selectedRow];
659 if (i_selected_row < 0)
662 p_selected_item = (playlist_item_t *)[[o_outline_view itemAtRow:
663 i_selected_row] pointerValue];
665 for (i_current = 0; i_current < p_item->i_children ; i_current++)
668 NSString * o_current_name, * o_current_author;
670 vlc_mutex_lock( &p_playlist->object_lock );
671 o_current_name = [NSString stringWithUTF8String:
672 p_item->pp_children[i_current]->input.psz_name];
673 psz_temp = playlist_ItemGetInfo(p_item ,_("Meta-information"),_("Author") );
674 o_current_author = [NSString stringWithUTF8String: psz_temp];
676 vlc_mutex_unlock( &p_playlist->object_lock );
678 if (p_selected_item == p_item->pp_children[i_current] &&
679 b_selected_item_met == NO)
681 b_selected_item_met = YES;
683 else if (p_selected_item == p_item->pp_children[i_current] &&
684 b_selected_item_met == YES)
686 vlc_object_release(p_playlist);
689 else if (b_selected_item_met == YES &&
690 ([o_current_name rangeOfString:[o_search_field
691 stringValue] options:NSCaseInsensitiveSearch ].length ||
692 [o_current_author rangeOfString:[o_search_field
693 stringValue] options:NSCaseInsensitiveSearch ].length))
695 vlc_object_release(p_playlist);
696 /*Adds the parent items in the result array as well, so that we can
698 return [NSMutableArray arrayWithObject: [NSValue
699 valueWithPointer: p_item->pp_children[i_current]]];
701 if (p_item->pp_children[i_current]->i_children > 0)
703 id o_result = [self subSearchItem:
704 p_item->pp_children[i_current]];
705 if (o_result != NULL)
707 vlc_object_release(p_playlist);
708 [o_result insertObject: [NSValue valueWithPointer:
709 p_item->pp_children[i_current]] atIndex:0];
714 vlc_object_release(p_playlist);
718 - (IBAction)searchItem:(id)sender
720 playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
722 playlist_view_t * p_view;
728 b_selected_item_met = NO;
730 if( p_playlist == NULL )
733 p_view = playlist_ViewFind( p_playlist, VIEW_SIMPLE );
737 /*First, only search after the selected item:*
738 *(b_selected_item_met = NO) */
739 o_result = [self subSearchItem:p_view->p_root];
740 if (o_result == NULL)
742 /* If the first search failed, search again from the beginning */
743 o_result = [self subSearchItem:p_view->p_root];
745 if (o_result != NULL)
747 for (i = 0 ; i < [o_result count] - 1 ; i++)
749 [o_outline_view expandItem: [o_outline_dict objectForKey:
750 [NSString stringWithFormat: @"%p",
751 [[o_result objectAtIndex: i] pointerValue]]]];
753 i_row = [o_outline_view rowForItem: [o_outline_dict objectForKey:
754 [NSString stringWithFormat: @"%p",
755 [[o_result objectAtIndex: [o_result count] - 1 ]
760 [o_outline_view selectRow:i_row byExtendingSelection: NO];
761 [o_outline_view scrollRowToVisible: i_row];
764 vlc_object_release(p_playlist);
768 - (NSMenu *)menuForEvent:(NSEvent *)o_event
772 vlc_bool_t b_item_sel;
774 pt = [o_outline_view convertPoint: [o_event locationInWindow]
776 b_item_sel = ( [o_outline_view rowAtPoint: pt] != -1 &&
777 [o_outline_view selectedRow] != -1 );
778 b_rows = [o_outline_view numberOfRows] != 0;
780 [o_mi_play setEnabled: b_item_sel];
781 [o_mi_delete setEnabled: b_item_sel];
782 [o_mi_selectall setEnabled: b_rows];
783 [o_mi_info setEnabled: b_item_sel];
785 return( o_ctx_menu );
788 - (playlist_item_t *)selectedPlaylistItem
790 return [[o_outline_view itemAtRow: [o_outline_view selectedRow]]
794 - (void) outlineView:(NSTableView*)o_tv
795 didClickTableColumn:(NSTableColumn *)o_tc
797 intf_thread_t * p_intf = VLCIntf;
798 playlist_t *p_playlist =
799 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
801 playlist_view_t * p_view = playlist_ViewFind( p_playlist, VIEW_SIMPLE );
802 int i_mode = 0, i_type;
804 if( p_playlist == NULL )
809 /* Check whether the selected table column header corresponds to a
810 sortable table column*/
811 if ( !(o_tc == o_tc_name || o_tc == o_tc_author))
816 if( o_tc_sortColumn == o_tc )
818 b_isSortDescending = !b_isSortDescending;
822 b_isSortDescending = VLC_FALSE;
825 if (o_tc == o_tc_name)
829 else if (o_tc == o_tc_author)
831 i_mode = SORT_AUTHOR;
834 if (b_isSortDescending)
836 i_type = ORDER_REVERSE;
840 i_type = ORDER_NORMAL;
843 vlc_mutex_lock(&p_playlist->object_lock );
844 playlist_RecursiveNodeSort(p_playlist, p_view->p_root, i_mode, i_type);
845 vlc_mutex_unlock(&p_playlist->object_lock );
847 vlc_object_release( p_playlist );
848 [self playlistUpdated];
850 o_tc_sortColumn = o_tc;
851 [o_outline_view setHighlightedTableColumn:o_tc];
853 if (b_isSortDescending)
855 [o_outline_view setIndicatorImage:o_descendingSortingImage
860 [o_outline_view setIndicatorImage:o_ascendingSortingImage
867 @implementation VLCPlaylist (NSOutlineViewDataSource)
869 /* return the number of children for Obj-C pointer item */ /* DONE */
870 - (int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
873 playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
875 if( p_playlist == NULL )
881 playlist_view_t *p_view;
882 p_view = playlist_ViewFind( p_playlist, VIEW_SIMPLE );
883 if( p_view && p_view->p_root )
884 i_return = p_view->p_root->i_children;
888 playlist_item_t *p_item = (playlist_item_t *)[item pointerValue];
890 i_return = p_item->i_children;
892 vlc_object_release( p_playlist );
893 if( i_return == -1 ) i_return = 0;
894 msg_Dbg( p_playlist, "I have %d children", i_return );
898 /* return the child at index for the Obj-C pointer item */ /* DONE */
899 - (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item
901 playlist_item_t *p_return = NULL;
902 playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
906 if( p_playlist == NULL )
912 playlist_view_t *p_view;
913 p_view = playlist_ViewFind( p_playlist, VIEW_SIMPLE );
914 if( p_view && index < p_view->p_root->i_children )
915 p_return = p_view->p_root->pp_children[index];
919 playlist_item_t *p_item = (playlist_item_t *)[item pointerValue];
920 if( p_item && index < p_item->i_children )
922 p_return = p_item->pp_children[index];
926 if( p_playlist->i_size >= 2 )
928 [o_status_field setStringValue: [NSString stringWithFormat:
929 _NS("%i items in playlist"), p_playlist->i_size]];
931 if( p_playlist->i_size == 0 )
933 [o_status_field setStringValue: [NSString stringWithFormat:
934 _NS("no items in playlist"), p_playlist->i_size]];
936 [o_status_field setStringValue: [NSString stringWithFormat:
937 _NS("1 item in playlist"), p_playlist->i_size]];
941 vlc_object_release( p_playlist );
942 msg_Dbg( p_playlist, "childitem with index %d", index );
944 o_value = [NSValue valueWithPointer: p_return];
946 [o_outline_dict setObject:o_value forKey:[NSString stringWithFormat:@"%p", p_return]];
950 /* is the item expandable */
951 - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item
954 playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
956 if( p_playlist == NULL )
962 playlist_view_t *p_view;
963 p_view = playlist_ViewFind( p_playlist, VIEW_SIMPLE );
964 if( p_view && p_view->p_root )
965 i_return = p_view->p_root->i_children;
969 playlist_item_t *p_item = (playlist_item_t *)[item pointerValue];
971 i_return = p_item->i_children;
973 vlc_object_release( p_playlist );
975 if( i_return == -1 || i_return == 0 )
981 /* retrieve the string values for the cells */
982 - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)o_tc byItem:(id)item
985 intf_thread_t * p_intf = VLCIntf;
986 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
988 playlist_item_t *p_item = (playlist_item_t *)[item pointerValue];
990 if( p_playlist == NULL || p_item == NULL )
995 if( [[o_tc identifier] isEqualToString:@"1"] )
997 o_value = [NSString stringWithUTF8String:
998 p_item->input.psz_name];
999 if( o_value == NULL )
1000 o_value = [NSString stringWithCString:
1001 p_item->input.psz_name];
1003 else if( [[o_tc identifier] isEqualToString:@"2"] )
1006 psz_temp = playlist_ItemGetInfo( p_item ,_("Meta-information"),_("Artist") );
1008 if( psz_temp == NULL )
1012 o_value = [NSString stringWithUTF8String: psz_temp];
1013 if( o_value == NULL )
1015 o_value = [NSString stringWithCString: psz_temp];
1020 else if( [[o_tc identifier] isEqualToString:@"3"] )
1022 char psz_duration[MSTRTIME_MAX_SIZE];
1023 mtime_t dur = p_item->input.i_duration;
1026 secstotimestr( psz_duration, dur/1000000 );
1027 o_value = [NSString stringWithUTF8String: psz_duration];
1031 o_value = @"-:--:--";
1035 vlc_object_release( p_playlist );
1040 /* Required for drag & drop and reordering */
1041 - (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pboard
1046 - (NSDragOperation)outlineView:(NSOutlineView *)outlineView validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(int)index
1048 return NSDragOperationNone;
1051 /* Delegate method of NSWindow */
1052 /*- (void)windowWillClose:(NSNotification *)aNotification
1054 [o_btn_playlist setState: NSOffState];