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 = vlc_input_item_GetInfo(&p_item->input ,
674 _("Meta-information"),_("Author") );
675 o_current_author = [NSString stringWithUTF8String: psz_temp];
677 vlc_mutex_unlock( &p_playlist->object_lock );
679 if (p_selected_item == p_item->pp_children[i_current] &&
680 b_selected_item_met == NO)
682 b_selected_item_met = YES;
684 else if (p_selected_item == p_item->pp_children[i_current] &&
685 b_selected_item_met == YES)
687 vlc_object_release(p_playlist);
690 else if (b_selected_item_met == YES &&
691 ([o_current_name rangeOfString:[o_search_field
692 stringValue] options:NSCaseInsensitiveSearch ].length ||
693 [o_current_author rangeOfString:[o_search_field
694 stringValue] options:NSCaseInsensitiveSearch ].length))
696 vlc_object_release(p_playlist);
697 /*Adds the parent items in the result array as well, so that we can
699 return [NSMutableArray arrayWithObject: [NSValue
700 valueWithPointer: p_item->pp_children[i_current]]];
702 if (p_item->pp_children[i_current]->i_children > 0)
704 id o_result = [self subSearchItem:
705 p_item->pp_children[i_current]];
706 if (o_result != NULL)
708 vlc_object_release(p_playlist);
709 [o_result insertObject: [NSValue valueWithPointer:
710 p_item->pp_children[i_current]] atIndex:0];
715 vlc_object_release(p_playlist);
719 - (IBAction)searchItem:(id)sender
721 playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
723 playlist_view_t * p_view;
729 b_selected_item_met = NO;
731 if( p_playlist == NULL )
734 p_view = playlist_ViewFind( p_playlist, VIEW_SIMPLE );
738 /*First, only search after the selected item:*
739 *(b_selected_item_met = NO) */
740 o_result = [self subSearchItem:p_view->p_root];
741 if (o_result == NULL)
743 /* If the first search failed, search again from the beginning */
744 o_result = [self subSearchItem:p_view->p_root];
746 if (o_result != NULL)
748 for (i = 0 ; i < [o_result count] - 1 ; i++)
750 [o_outline_view expandItem: [o_outline_dict objectForKey:
751 [NSString stringWithFormat: @"%p",
752 [[o_result objectAtIndex: i] pointerValue]]]];
754 i_row = [o_outline_view rowForItem: [o_outline_dict objectForKey:
755 [NSString stringWithFormat: @"%p",
756 [[o_result objectAtIndex: [o_result count] - 1 ]
761 [o_outline_view selectRow:i_row byExtendingSelection: NO];
762 [o_outline_view scrollRowToVisible: i_row];
765 vlc_object_release(p_playlist);
769 - (NSMenu *)menuForEvent:(NSEvent *)o_event
773 vlc_bool_t b_item_sel;
775 pt = [o_outline_view convertPoint: [o_event locationInWindow]
777 b_item_sel = ( [o_outline_view rowAtPoint: pt] != -1 &&
778 [o_outline_view selectedRow] != -1 );
779 b_rows = [o_outline_view numberOfRows] != 0;
781 [o_mi_play setEnabled: b_item_sel];
782 [o_mi_delete setEnabled: b_item_sel];
783 [o_mi_selectall setEnabled: b_rows];
784 [o_mi_info setEnabled: b_item_sel];
786 return( o_ctx_menu );
789 - (playlist_item_t *)selectedPlaylistItem
791 return [[o_outline_view itemAtRow: [o_outline_view selectedRow]]
795 - (void) outlineView:(NSTableView*)o_tv
796 didClickTableColumn:(NSTableColumn *)o_tc
798 intf_thread_t * p_intf = VLCIntf;
799 playlist_t *p_playlist =
800 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
802 playlist_view_t * p_view = playlist_ViewFind( p_playlist, VIEW_SIMPLE );
803 int i_mode = 0, i_type;
805 if( p_playlist == NULL )
810 /* Check whether the selected table column header corresponds to a
811 sortable table column*/
812 if ( !(o_tc == o_tc_name || o_tc == o_tc_author))
817 if( o_tc_sortColumn == o_tc )
819 b_isSortDescending = !b_isSortDescending;
823 b_isSortDescending = VLC_FALSE;
826 if (o_tc == o_tc_name)
830 else if (o_tc == o_tc_author)
832 i_mode = SORT_AUTHOR;
835 if (b_isSortDescending)
837 i_type = ORDER_REVERSE;
841 i_type = ORDER_NORMAL;
844 vlc_mutex_lock(&p_playlist->object_lock );
845 playlist_RecursiveNodeSort(p_playlist, p_view->p_root, i_mode, i_type);
846 vlc_mutex_unlock(&p_playlist->object_lock );
848 vlc_object_release( p_playlist );
849 [self playlistUpdated];
851 o_tc_sortColumn = o_tc;
852 [o_outline_view setHighlightedTableColumn:o_tc];
854 if (b_isSortDescending)
856 [o_outline_view setIndicatorImage:o_descendingSortingImage
861 [o_outline_view setIndicatorImage:o_ascendingSortingImage
868 @implementation VLCPlaylist (NSOutlineViewDataSource)
870 /* return the number of children for Obj-C pointer item */ /* DONE */
871 - (int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
874 playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
876 if( p_playlist == NULL )
882 playlist_view_t *p_view;
883 p_view = playlist_ViewFind( p_playlist, VIEW_SIMPLE );
884 if( p_view && p_view->p_root )
885 i_return = p_view->p_root->i_children;
889 playlist_item_t *p_item = (playlist_item_t *)[item pointerValue];
891 i_return = p_item->i_children;
893 vlc_object_release( p_playlist );
894 if( i_return == -1 ) i_return = 0;
895 msg_Dbg( p_playlist, "I have %d children", i_return );
899 /* return the child at index for the Obj-C pointer item */ /* DONE */
900 - (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item
902 playlist_item_t *p_return = NULL;
903 playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
907 if( p_playlist == NULL )
913 playlist_view_t *p_view;
914 p_view = playlist_ViewFind( p_playlist, VIEW_SIMPLE );
915 if( p_view && index < p_view->p_root->i_children )
916 p_return = p_view->p_root->pp_children[index];
920 playlist_item_t *p_item = (playlist_item_t *)[item pointerValue];
921 if( p_item && index < p_item->i_children )
923 p_return = p_item->pp_children[index];
927 if( p_playlist->i_size >= 2 )
929 [o_status_field setStringValue: [NSString stringWithFormat:
930 _NS("%i items in playlist"), p_playlist->i_size]];
932 if( p_playlist->i_size == 0 )
934 [o_status_field setStringValue: [NSString stringWithFormat:
935 _NS("no items in playlist"), p_playlist->i_size]];
937 [o_status_field setStringValue: [NSString stringWithFormat:
938 _NS("1 item in playlist"), p_playlist->i_size]];
942 vlc_object_release( p_playlist );
943 msg_Dbg( p_playlist, "childitem with index %d", index );
945 o_value = [NSValue valueWithPointer: p_return];
947 [o_outline_dict setObject:o_value forKey:[NSString stringWithFormat:@"%p", p_return]];
951 /* is the item expandable */
952 - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item
955 playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
957 if( p_playlist == NULL )
963 playlist_view_t *p_view;
964 p_view = playlist_ViewFind( p_playlist, VIEW_SIMPLE );
965 if( p_view && p_view->p_root )
966 i_return = p_view->p_root->i_children;
970 playlist_item_t *p_item = (playlist_item_t *)[item pointerValue];
972 i_return = p_item->i_children;
974 vlc_object_release( p_playlist );
976 if( i_return == -1 || i_return == 0 )
982 /* retrieve the string values for the cells */
983 - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)o_tc byItem:(id)item
986 intf_thread_t * p_intf = VLCIntf;
987 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
989 playlist_item_t *p_item = (playlist_item_t *)[item pointerValue];
991 if( p_playlist == NULL || p_item == NULL )
996 if( [[o_tc identifier] isEqualToString:@"1"] )
998 o_value = [NSString stringWithUTF8String:
999 p_item->input.psz_name];
1000 if( o_value == NULL )
1001 o_value = [NSString stringWithCString:
1002 p_item->input.psz_name];
1004 else if( [[o_tc identifier] isEqualToString:@"2"] )
1007 psz_temp = vlc_input_item_GetInfo( &p_item->input ,_("Meta-information"),_("Artist") );
1009 if( psz_temp == NULL )
1013 o_value = [NSString stringWithUTF8String: psz_temp];
1014 if( o_value == NULL )
1016 o_value = [NSString stringWithCString: psz_temp];
1021 else if( [[o_tc identifier] isEqualToString:@"3"] )
1023 char psz_duration[MSTRTIME_MAX_SIZE];
1024 mtime_t dur = p_item->input.i_duration;
1027 secstotimestr( psz_duration, dur/1000000 );
1028 o_value = [NSString stringWithUTF8String: psz_duration];
1032 o_value = @"-:--:--";
1036 vlc_object_release( p_playlist );
1041 /* Required for drag & drop and reordering */
1042 - (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pboard
1047 - (NSDragOperation)outlineView:(NSOutlineView *)outlineView validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(int)index
1049 return NSDragOperationNone;
1052 /* Delegate method of NSWindow */
1053 /*- (void)windowWillClose:(NSNotification *)aNotification
1055 [o_btn_playlist setState: NSOffState];