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 vlc_list_t *p_list = vlc_list_find( p_playlist, VLC_OBJECT_MODULE,
117 i_current_view = VIEW_CATEGORY;
118 playlist_ViewUpdate( p_playlist, i_current_view );
120 [o_outline_view setTarget: self];
121 [o_outline_view setDelegate: self];
122 [o_outline_view setDataSource: self];
124 [o_outline_view setDoubleAction: @selector(playItem:)];
126 [o_outline_view registerForDraggedTypes:
127 [NSArray arrayWithObjects: NSFilenamesPboardType, nil]];
128 [o_outline_view setIntercellSpacing: NSMakeSize (0.0, 1.0)];
130 /* We need to check whether _defaultTableHeaderSortImage exists, since it
131 belongs to an Apple hidden private API, and then can "disapear" at any time*/
133 if( [[NSOutlineView class] respondsToSelector:@selector(_defaultTableHeaderSortImage)] )
135 o_ascendingSortingImage = [[NSOutlineView class] _defaultTableHeaderSortImage];
139 o_ascendingSortingImage = nil;
142 if( [[NSOutlineView class] respondsToSelector:@selector(_defaultTableHeaderReverseSortImage)] )
144 o_descendingSortingImage = [[NSOutlineView class] _defaultTableHeaderReverseSortImage];
148 o_descendingSortingImage = nil;
151 o_tc_sortColumn = nil;
153 for( i_index = 0; i_index < p_list->i_count; i_index++ )
156 module_t * p_parser = (module_t *)p_list->p_values[i_index].p_object ;
158 if( !strcmp( p_parser->psz_capability, "services_discovery" ) )
160 o_lmi = [[o_mi_services submenu] addItemWithTitle:
161 [NSString stringWithCString:
162 p_parser->psz_longname ? p_parser->psz_longname :
163 ( p_parser->psz_shortname ? p_parser->psz_shortname:
164 p_parser->psz_object_name)]
165 action: @selector(servicesChange:)
167 [o_lmi setTarget: self];
168 [o_lmi setRepresentedObject:
169 [NSString stringWithCString: p_parser->psz_object_name]];
170 if( playlist_IsServicesDiscoveryLoaded( p_playlist,
171 p_parser->psz_object_name ) )
172 [o_lmi setState: NSOnState];
175 vlc_list_release( p_list );
176 vlc_object_release( p_playlist );
179 //[self playlistUpdated];
184 [o_mi_save_playlist setTitle: _NS("Save Playlist...")];
185 [o_mi_play setTitle: _NS("Play")];
186 [o_mi_delete setTitle: _NS("Delete")];
187 [o_mi_selectall setTitle: _NS("Select All")];
188 [o_mi_info setTitle: _NS("Properties")];
189 [o_mi_sort_name setTitle: _NS("Sort Node by Name")];
190 [o_mi_sort_author setTitle: _NS("Sort Node by Author")];
191 [o_mi_services setTitle: _NS("Services discovery")];
192 [[o_tc_name headerCell] setStringValue:_NS("Name")];
193 [[o_tc_author headerCell] setStringValue:_NS("Author")];
194 [[o_tc_duration headerCell] setStringValue:_NS("Duration")];
195 [o_status_field setStringValue: [NSString stringWithFormat:
196 _NS("no items in playlist")]];
198 [o_random_ckb setTitle: _NS("Random")];
200 [o_search_button setTitle: _NS("Search")];
202 [o_btn_playlist setToolTip: _NS("Playlist")];
203 [[o_loop_popup itemAtIndex:0] setTitle: _NS("Standard Play")];
204 [[o_loop_popup itemAtIndex:1] setTitle: _NS("Repeat One")];
205 [[o_loop_popup itemAtIndex:2] setTitle: _NS("Repeat All")];
208 - (NSOutlineView *)playlistView
210 return o_outline_view;
213 - (IBAction)toggleWindow:(id)sender
216 /*First, check if the playlist is visible*/
217 if ( [o_controller frame].size.height == [o_controller minSize].height )
219 /*Check if the stored heigth of the controller is usable (!= minSize)*/
220 if ([o_controller getSizeWithPlaylist].height !=
221 [o_controller minSize].height)
223 o_rect.size.height = [o_controller getSizeWithPlaylist].height;
227 /*If the stored height is not usable, use a reference one*/
228 o_rect.size.height = REF_HEIGHT;
231 /*Check if the controller width is the minimum one*/
232 if ( [o_controller frame].size.width == [o_controller minSize].width)
234 /*If the controller width is minimum, check if the stored height
235 of the playlist makes it visible*/
236 if ([o_controller getSizeWithPlaylist].height !=
237 [o_controller minSize].height)
239 o_rect.size.width = [o_controller getSizeWithPlaylist].width;
243 /*If not, use a reference width*/
244 o_rect.size.width = REF_WIDTH;
249 o_rect.size.width = [o_controller frame].size.width;
251 o_rect.origin.x = [o_controller frame].origin.x;
252 o_rect.origin.y = [o_controller frame].origin.y - o_rect.size.height +
253 [o_controller minSize].height;
255 [o_btn_playlist setState: YES];
259 o_rect.size = [o_controller minSize];
260 o_rect.origin.x = [o_controller frame].origin.x;
261 /*Calculate the position of the lower right corner after resize*/
262 o_rect.origin.y = [o_controller frame].origin.y +
263 [o_controller frame].size.height - [o_controller minSize].height;
265 [o_btn_playlist setState: NO];
268 [o_controller setFrame: o_rect display:YES animate: YES];
271 - (void)playlistUpdated
275 /* Clear indications of any existing column sorting*/
276 for( i = 0 ; i < [[o_outline_view tableColumns] count] ; i++ )
278 [o_outline_view setIndicatorImage:nil inTableColumn:
279 [[o_outline_view tableColumns] objectAtIndex:i]];
282 [o_outline_view setHighlightedTableColumn:nil];
283 o_tc_sortColumn = nil;
284 // TODO Find a way to keep the dict size to a minimum
285 //[o_outline_dict removeAllObjects];
286 [o_outline_view reloadData];
290 - (void)updateTogglePlaylistState
292 if( [o_controller getSizeWithPlaylist].height ==
293 [o_controller minSize].height )
295 [o_btn_playlist setState: NO];
299 [o_btn_playlist setState: YES];
303 - (void)updateRowSelection
308 playlist_t *p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
310 playlist_item_t *p_item, *p_temp_item;
311 NSMutableArray *o_array = [NSMutableArray array];
313 if( p_playlist == NULL )
316 p_item = p_playlist->status.p_item;
317 p_temp_item = p_item;
319 while( p_temp_item->i_parents > 0 )
321 [o_array insertObject: [NSValue valueWithPointer: p_temp_item] atIndex: 0];
322 for (i = 0 ; i < p_temp_item->i_parents ; i++)
324 if( p_temp_item->pp_parents[i]->i_view == i_current_view )
326 p_temp_item = p_temp_item->pp_parents[i]->p_parent;
332 for (j = 0 ; j < [o_array count] - 1 ; j++)
334 [o_outline_view expandItem: [o_outline_dict objectForKey:
335 [NSString stringWithFormat: @"%p",
336 [[o_array objectAtIndex:j] pointerValue]]]];
340 i_row = [o_outline_view rowForItem:[o_outline_dict
341 objectForKey:[NSString stringWithFormat: @"%p", p_item]]];
343 [o_outline_view selectRow: i_row byExtendingSelection: NO];
344 [o_outline_view scrollRowToVisible: i_row];
346 vlc_object_release(p_playlist);
350 - (BOOL)isItem: (playlist_item_t *)p_item inNode: (playlist_item_t *)p_node
352 playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
354 playlist_item_t *p_temp_item = p_item;
356 if( p_playlist == NULL )
361 while( p_temp_item->i_parents > 0 )
364 for( i = 0; i < p_temp_item->i_parents ; i++ )
366 if( p_temp_item->pp_parents[i]->i_view == i_current_view )
368 if( p_temp_item->pp_parents[i]->p_parent == p_node )
370 vlc_object_release( p_playlist );
375 p_temp_item = p_temp_item->pp_parents[i]->p_parent;
382 vlc_object_release( p_playlist );
387 /* When called retrieves the selected outlineview row and plays that node or item */
388 - (IBAction)playItem:(id)sender
390 intf_thread_t * p_intf = VLCIntf;
391 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
394 if( p_playlist != NULL )
396 playlist_item_t *p_item;
397 playlist_item_t *p_node = NULL;
400 p_item = [[o_outline_view itemAtRow:[o_outline_view selectedRow]] pointerValue];
404 if( p_item->i_children == -1 )
406 for( i = 0 ; i < p_item->i_parents ; i++ )
408 if( p_item->pp_parents[i]->i_view == i_current_view )
410 p_node = p_item->pp_parents[i]->p_parent;
417 if( p_node->i_children > 0 && p_node->pp_children[0]->i_children == -1 )
419 p_item = p_node->pp_children[0];
427 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, i_current_view, p_node, p_item );
429 vlc_object_release( p_playlist );
433 - (IBAction)servicesChange:(id)sender
435 NSMenuItem *o_mi = (NSMenuItem *)sender;
436 NSString *o_string = [o_mi representedObject];
437 playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
439 if( !playlist_IsServicesDiscoveryLoaded( p_playlist, [o_string cString] ) )
440 playlist_ServicesDiscoveryAdd( p_playlist, [o_string cString] );
442 playlist_ServicesDiscoveryRemove( p_playlist, [o_string cString] );
444 [o_mi setState: playlist_IsServicesDiscoveryLoaded( p_playlist,
445 [o_string cString] ) ? YES : NO];
446 [self playlistUpdated];
450 - (IBAction)selectAll:(id)sender
452 [o_outline_view selectAll: nil];
455 - (IBAction)deleteItem:(id)sender
457 int i, i_count, i_row;
458 NSMutableArray *o_to_delete;
461 playlist_t * p_playlist;
462 intf_thread_t * p_intf = VLCIntf;
464 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
467 if ( p_playlist == NULL )
471 o_to_delete = [NSMutableArray arrayWithArray:[[o_outline_view selectedRowEnumerator] allObjects]];
472 i_count = [o_to_delete count];
474 for( i = 0; i < i_count; i++ )
476 playlist_item_t * p_item;
477 o_number = [o_to_delete lastObject];
478 i_row = [o_number intValue];
480 [o_to_delete removeObject: o_number];
481 [o_outline_view deselectRow: i_row];
483 p_item = (playlist_item_t *)[[o_outline_view itemAtRow: i_row] pointerValue];
485 if( p_item->i_children > -1 ) //is a node and not an item
487 if( p_playlist->status.i_status != PLAYLIST_STOPPED &&
488 [self isItem: p_playlist->status.p_item inNode: p_item] == YES )
490 // if current item is in selected node and is playing then stop playlist
491 playlist_Stop( p_playlist );
493 playlist_NodeDelete( p_playlist, p_item, VLC_TRUE, VLC_FALSE );
497 if( p_playlist->status.i_status != PLAYLIST_STOPPED &&
498 p_playlist->status.p_item == [[o_outline_view itemAtRow: i_row] pointerValue] )
500 playlist_Stop( p_playlist );
502 playlist_LockDelete( p_playlist, p_item->input.i_id );
505 [self playlistUpdated];
506 vlc_object_release( p_playlist );
509 - (IBAction)sortNodeByName:(id)sender
511 [self sortNode: SORT_TITLE];
514 - (IBAction)sortNodeByAuthor:(id)sender
516 [self sortNode: SORT_AUTHOR];
519 - (void)sortNode:(int)i_mode
521 playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
523 playlist_item_t * p_item;
525 if (p_playlist == NULL)
530 if( [o_outline_view selectedRow] > -1 )
532 p_item = [[o_outline_view itemAtRow: [o_outline_view selectedRow]]
536 /*If no item is selected, sort the whole playlist*/
538 playlist_view_t * p_view = playlist_ViewFind( p_playlist, i_current_view );
539 p_item = p_view->p_root;
542 if( p_item->i_children > -1 ) // the item is a node
544 vlc_mutex_lock( &p_playlist->object_lock );
545 playlist_RecursiveNodeSort( p_playlist, p_item, i_mode, ORDER_NORMAL );
546 vlc_mutex_unlock( &p_playlist->object_lock );
552 for( i = 0 ; i < p_item->i_parents ; i++ )
554 if( p_item->pp_parents[i]->i_view == i_current_view )
556 vlc_mutex_lock( &p_playlist->object_lock );
557 playlist_RecursiveNodeSort( p_playlist,
558 p_item->pp_parents[i]->p_parent, i_mode, ORDER_NORMAL );
559 vlc_mutex_unlock( &p_playlist->object_lock );
564 vlc_object_release( p_playlist );
565 [self playlistUpdated];
568 - (void)appendArray:(NSArray*)o_array atPos:(int)i_position enqueue:(BOOL)b_enqueue
571 intf_thread_t * p_intf = VLCIntf;
572 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
575 if( p_playlist == NULL )
580 for( i_item = 0; i_item < (int)[o_array count]; i_item++ )
583 NSDictionary *o_one_item;
584 int j, i_total_options = 0, i_new_id = -1;
585 int i_mode = PLAYLIST_INSERT;
586 BOOL b_rem = FALSE, b_dir = FALSE;
587 NSString *o_uri, *o_name;
590 char **ppsz_options = NULL;
593 o_one_item = [o_array objectAtIndex: i_item];
594 o_uri = (NSString *)[o_one_item objectForKey: @"ITEM_URL"];
595 o_name = (NSString *)[o_one_item objectForKey: @"ITEM_NAME"];
596 o_options = (NSArray *)[o_one_item objectForKey: @"ITEM_OPTIONS"];
598 /* If no name, then make a guess */
599 if( !o_name) o_name = [[NSFileManager defaultManager] displayNameAtPath: o_uri];
601 if( [[NSFileManager defaultManager] fileExistsAtPath:o_uri isDirectory:&b_dir] && b_dir &&
602 [[NSWorkspace sharedWorkspace] getFileSystemInfoForPath: o_uri isRemovable: &b_rem
603 isWritable:NULL isUnmountable:NULL description:NULL type:NULL] && b_rem )
605 /* All of this is to make sure CD's play when you D&D them on VLC */
606 /* Converts mountpoint to a /dev file */
609 buf = (struct statfs *) malloc (sizeof(struct statfs));
610 statfs( [o_uri fileSystemRepresentation], buf );
611 psz_dev = strdup(buf->f_mntfromname);
612 o_uri = [NSString stringWithCString: psz_dev ];
615 if( o_options && [o_options count] > 0 )
617 /* Count the input options */
618 i_total_options = [o_options count];
620 /* Allocate ppsz_options */
621 for( j = 0; j < i_total_options; j++ )
624 ppsz_options = (char **)malloc( sizeof(char *) * i_total_options );
626 ppsz_options[j] = strdup([[o_options objectAtIndex:j] UTF8String]);
631 i_new_id = playlist_AddExt( p_playlist, [o_uri fileSystemRepresentation],
632 [o_name UTF8String], i_mode,
633 i_position == -1 ? PLAYLIST_END : i_position + i_item,
634 0, (ppsz_options != NULL ) ? (const char **)ppsz_options : 0, i_total_options );
636 /* Recent documents menu */
637 o_true_file = [NSURL fileURLWithPath: o_uri];
638 if( o_true_file != nil )
640 [[NSDocumentController sharedDocumentController]
641 noteNewRecentDocumentURL: o_true_file];
644 if( i_item == 0 && !b_enqueue )
646 playlist_Goto( p_playlist, playlist_GetPositionById( p_playlist, i_new_id ) );
647 playlist_Play( p_playlist );
651 vlc_object_release( p_playlist );
654 - (IBAction)handlePopUp:(id)sender
657 intf_thread_t * p_intf = VLCIntf;
658 vlc_value_t val1,val2;
659 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
661 if( p_playlist == NULL )
666 switch( [o_loop_popup indexOfSelectedItem] )
671 var_Set( p_playlist, "loop", val1 );
673 var_Set( p_playlist, "repeat", val1 );
674 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat One" ) );
679 var_Set( p_playlist, "repeat", val1 );
681 var_Set( p_playlist, "loop", val1 );
682 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat All" ) );
686 var_Get( p_playlist, "repeat", &val1 );
687 var_Get( p_playlist, "loop", &val2 );
688 if( val1.b_bool || val2.b_bool )
691 var_Set( p_playlist, "repeat", val1 );
692 var_Set( p_playlist, "loop", val1 );
693 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat Off" ) );
697 vlc_object_release( p_playlist );
698 [self playlistUpdated];
701 - (NSMutableArray *)subSearchItem:(playlist_item_t *)p_item
703 playlist_t *p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
705 playlist_item_t *p_selected_item;
706 int i_current, i_selected_row;
711 i_selected_row = [o_outline_view selectedRow];
712 if (i_selected_row < 0)
715 p_selected_item = (playlist_item_t *)[[o_outline_view itemAtRow:
716 i_selected_row] pointerValue];
718 for( i_current = 0; i_current < p_item->i_children ; i_current++ )
721 NSString *o_current_name, *o_current_author;
723 vlc_mutex_lock( &p_playlist->object_lock );
724 o_current_name = [NSString stringWithUTF8String:
725 p_item->pp_children[i_current]->input.psz_name];
726 psz_temp = vlc_input_item_GetInfo( &p_item->input ,
727 _("Meta-information"),_("Artist") );
728 o_current_author = [NSString stringWithUTF8String: psz_temp];
730 vlc_mutex_unlock( &p_playlist->object_lock );
732 if( p_selected_item == p_item->pp_children[i_current] &&
733 b_selected_item_met == NO )
735 b_selected_item_met = YES;
737 else if( p_selected_item == p_item->pp_children[i_current] &&
738 b_selected_item_met == YES )
740 vlc_object_release( p_playlist );
743 else if( b_selected_item_met == YES &&
744 ( [o_current_name rangeOfString:[o_search_field
745 stringValue] options:NSCaseInsensitiveSearch ].length ||
746 [o_current_author rangeOfString:[o_search_field
747 stringValue] options:NSCaseInsensitiveSearch ].length ) )
749 vlc_object_release( p_playlist );
750 /*Adds the parent items in the result array as well, so that we can
752 return [NSMutableArray arrayWithObject: [NSValue
753 valueWithPointer: p_item->pp_children[i_current]]];
755 if( p_item->pp_children[i_current]->i_children > 0 )
757 id o_result = [self subSearchItem:
758 p_item->pp_children[i_current]];
759 if( o_result != NULL )
761 vlc_object_release( p_playlist );
762 [o_result insertObject: [NSValue valueWithPointer:
763 p_item->pp_children[i_current]] atIndex:0];
768 vlc_object_release( p_playlist );
772 - (IBAction)searchItem:(id)sender
774 playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
776 playlist_view_t * p_view;
782 b_selected_item_met = NO;
784 if( p_playlist == NULL )
787 p_view = playlist_ViewFind( p_playlist, i_current_view );
791 /*First, only search after the selected item:*
792 *(b_selected_item_met = NO) */
793 o_result = [self subSearchItem:p_view->p_root];
794 if( o_result == NULL )
796 /* If the first search failed, search again from the beginning */
797 o_result = [self subSearchItem:p_view->p_root];
799 if( o_result != NULL )
801 for( i = 0 ; i < [o_result count] - 1 ; i++ )
803 [o_outline_view expandItem: [o_outline_dict objectForKey:
804 [NSString stringWithFormat: @"%p",
805 [[o_result objectAtIndex: i] pointerValue]]]];
807 i_row = [o_outline_view rowForItem: [o_outline_dict objectForKey:
808 [NSString stringWithFormat: @"%p",
809 [[o_result objectAtIndex: [o_result count] - 1 ]
814 [o_outline_view selectRow:i_row byExtendingSelection: NO];
815 [o_outline_view scrollRowToVisible: i_row];
818 vlc_object_release( p_playlist );
821 - (NSMenu *)menuForEvent:(NSEvent *)o_event
825 vlc_bool_t b_item_sel;
827 pt = [o_outline_view convertPoint: [o_event locationInWindow]
829 b_item_sel = ( [o_outline_view rowAtPoint: pt] != -1 &&
830 [o_outline_view selectedRow] != -1 );
831 b_rows = [o_outline_view numberOfRows] != 0;
833 [o_mi_play setEnabled: b_item_sel];
834 [o_mi_delete setEnabled: b_item_sel];
835 [o_mi_selectall setEnabled: b_rows];
836 [o_mi_info setEnabled: b_item_sel];
838 return( o_ctx_menu );
841 - (playlist_item_t *)selectedPlaylistItem
843 return [[o_outline_view itemAtRow: [o_outline_view selectedRow]]
847 - (void)outlineView: (NSTableView*)o_tv
848 didClickTableColumn:(NSTableColumn *)o_tc
850 int i_mode = 0, i_type;
851 intf_thread_t *p_intf = VLCIntf;
852 playlist_view_t *p_view;
854 playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
856 if( p_playlist == NULL )
861 /* Check whether the selected table column header corresponds to a
862 sortable table column*/
863 if( !( o_tc == o_tc_name || o_tc == o_tc_author ) )
865 vlc_object_release( p_playlist );
869 p_view = playlist_ViewFind( p_playlist, i_current_view );
871 if( o_tc_sortColumn == o_tc )
873 b_isSortDescending = !b_isSortDescending;
877 b_isSortDescending = VLC_FALSE;
880 if( o_tc == o_tc_name )
884 else if( o_tc == o_tc_author )
886 i_mode = SORT_AUTHOR;
889 if( b_isSortDescending )
891 i_type = ORDER_REVERSE;
895 i_type = ORDER_NORMAL;
898 vlc_mutex_lock( &p_playlist->object_lock );
899 playlist_RecursiveNodeSort( p_playlist, p_view->p_root, i_mode, i_type );
900 vlc_mutex_unlock( &p_playlist->object_lock );
902 vlc_object_release( p_playlist );
903 [self playlistUpdated];
905 o_tc_sortColumn = o_tc;
906 [o_outline_view setHighlightedTableColumn:o_tc];
908 if( b_isSortDescending )
910 [o_outline_view setIndicatorImage:o_descendingSortingImage
915 [o_outline_view setIndicatorImage:o_ascendingSortingImage
922 @implementation VLCPlaylist (NSOutlineViewDataSource)
924 /* return the number of children for Obj-C pointer item */ /* DONE */
925 - (int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
928 playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
930 if( p_playlist == NULL || outlineView != o_outline_view )
936 playlist_view_t *p_view;
937 p_view = playlist_ViewFind( p_playlist, i_current_view );
938 if( p_view && p_view->p_root )
939 i_return = p_view->p_root->i_children;
943 playlist_item_t *p_item = (playlist_item_t *)[item pointerValue];
945 i_return = p_item->i_children;
947 vlc_object_release( p_playlist );
955 /* return the child at index for the Obj-C pointer item */ /* DONE */
956 - (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item
958 playlist_item_t *p_return = NULL;
959 playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
963 if( p_playlist == NULL )
969 playlist_view_t *p_view;
970 p_view = playlist_ViewFind( p_playlist, i_current_view );
971 if( p_view && index < p_view->p_root->i_children && index >= 0 )
972 p_return = p_view->p_root->pp_children[index];
976 playlist_item_t *p_item = (playlist_item_t *)[item pointerValue];
977 if( p_item && index < p_item->i_children && index >= 0 )
978 p_return = p_item->pp_children[index];
981 if( p_playlist->i_size >= 2 )
983 [o_status_field setStringValue: [NSString stringWithFormat:
984 _NS("%i items in playlist"), p_playlist->i_size]];
988 if( p_playlist->i_size == 0 )
990 [o_status_field setStringValue: [NSString stringWithFormat:
991 _NS("no items in playlist"), p_playlist->i_size]];
995 [o_status_field setStringValue: [NSString stringWithFormat:
996 _NS("1 item in playlist"), p_playlist->i_size]];
1000 vlc_object_release( p_playlist );
1003 o_value = [[NSValue valueWithPointer: p_return] retain];
1005 if( [o_outline_dict objectForKey: [NSString stringWithFormat:@"%p", p_return]] == nil )
1007 [o_outline_dict setObject:o_value forKey:[NSString stringWithFormat:@"%p", p_return]];
1012 /* is the item expandable */
1013 - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item
1016 playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
1018 if( p_playlist == NULL )
1024 playlist_view_t *p_view;
1025 p_view = playlist_ViewFind( p_playlist, i_current_view );
1026 if( p_view && p_view->p_root )
1027 i_return = p_view->p_root->i_children;
1031 playlist_item_t *p_item = (playlist_item_t *)[item pointerValue];
1033 i_return = p_item->i_children;
1035 vlc_object_release( p_playlist );
1043 /* retrieve the string values for the cells */
1044 - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)o_tc byItem:(id)item
1047 intf_thread_t *p_intf = VLCIntf;
1048 playlist_t *p_playlist;
1049 playlist_item_t *p_item;
1051 if( item == nil || ![item isKindOfClass: [NSValue class]] ) return( @"error" );
1053 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1055 if( p_playlist == NULL )
1060 p_item = (playlist_item_t *)[item pointerValue];
1062 if( p_item == NULL )
1064 vlc_object_release( p_playlist );
1068 if( [[o_tc identifier] isEqualToString:@"1"] )
1070 o_value = [NSString stringWithUTF8String:
1071 p_item->input.psz_name];
1072 if( o_value == NULL )
1073 o_value = [NSString stringWithCString:
1074 p_item->input.psz_name];
1076 else if( [[o_tc identifier] isEqualToString:@"2"] )
1079 psz_temp = vlc_input_item_GetInfo( &p_item->input ,_("Meta-information"),_("Artist") );
1081 if( psz_temp == NULL )
1085 o_value = [NSString stringWithUTF8String: psz_temp];
1086 if( o_value == NULL )
1088 o_value = [NSString stringWithCString: psz_temp];
1093 else if( [[o_tc identifier] isEqualToString:@"3"] )
1095 char psz_duration[MSTRTIME_MAX_SIZE];
1096 mtime_t dur = p_item->input.i_duration;
1099 secstotimestr( psz_duration, dur/1000000 );
1100 o_value = [NSString stringWithUTF8String: psz_duration];
1104 o_value = @"-:--:--";
1107 vlc_object_release( p_playlist );
1112 /* Required for drag & drop and reordering */
1113 - (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pboard
1118 - (NSDragOperation)outlineView:(NSOutlineView *)outlineView validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(int)index
1120 return NSDragOperationNone;
1123 /* Delegate method of NSWindow */
1124 /*- (void)windowWillClose:(NSNotification *)aNotification
1126 [o_btn_playlist setState: NSOffState];