1 /*****************************************************************************
2 * playlist.m: MacOS X interface module
3 *****************************************************************************
4 * Copyright (C) 2002-2005 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 search field build with pictures from the 'regular' search field, so it can be emulated on 10.2
29 * create toggle buttons for the shuffle, repeat one, repeat all functions.
30 * implement drag and drop and item reordering.
31 * reimplement enable/disable item
32 * create a new 'tool' button (see the gear button in the Finder window) for 'actions'
33 (adding service discovery, other views, new node/playlist, save node/playlist) stuff like that
37 /*****************************************************************************
39 *****************************************************************************/
40 #include <stdlib.h> /* malloc(), free() */
41 #include <sys/param.h> /* for MAXPATHLEN */
44 #include <sys/mount.h>
53 /*****************************************************************************
54 * VLCPlaylistView implementation
55 *****************************************************************************/
56 @implementation VLCPlaylistView
58 - (NSMenu *)menuForEvent:(NSEvent *)o_event
60 return( [[self delegate] menuForEvent: o_event] );
63 - (void)keyDown:(NSEvent *)o_event
67 if( [[o_event characters] length] )
69 key = [[o_event characters] characterAtIndex: 0];
74 case NSDeleteCharacter:
75 case NSDeleteFunctionKey:
76 case NSDeleteCharFunctionKey:
77 case NSBackspaceCharacter:
78 [[self delegate] deleteItem:self];
82 [super keyDown: o_event];
89 /*****************************************************************************
90 * VLCPlaylist implementation
91 *****************************************************************************/
92 @implementation VLCPlaylist
99 o_outline_dict = [[NSMutableDictionary alloc] init];
107 playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
109 vlc_list_t *p_list = vlc_list_find( p_playlist, VLC_OBJECT_MODULE,
113 i_current_view = VIEW_CATEGORY;
114 playlist_ViewUpdate( p_playlist, i_current_view );
116 [o_outline_view setTarget: self];
117 [o_outline_view setDelegate: self];
118 [o_outline_view setDataSource: self];
120 [o_outline_view setDoubleAction: @selector(playItem:)];
122 [o_outline_view registerForDraggedTypes:
123 [NSArray arrayWithObjects: NSFilenamesPboardType, nil]];
124 [o_outline_view setIntercellSpacing: NSMakeSize (0.0, 1.0)];
126 /* We need to check whether _defaultTableHeaderSortImage exists, since it
127 belongs to an Apple hidden private API, and then can "disapear" at any time*/
129 if( [[NSOutlineView class] respondsToSelector:@selector(_defaultTableHeaderSortImage)] )
131 o_ascendingSortingImage = [[NSOutlineView class] _defaultTableHeaderSortImage];
135 o_ascendingSortingImage = nil;
138 if( [[NSOutlineView class] respondsToSelector:@selector(_defaultTableHeaderReverseSortImage)] )
140 o_descendingSortingImage = [[NSOutlineView class] _defaultTableHeaderReverseSortImage];
144 o_descendingSortingImage = nil;
147 o_tc_sortColumn = nil;
149 for( i_index = 0; i_index < p_list->i_count; i_index++ )
152 module_t * p_parser = (module_t *)p_list->p_values[i_index].p_object ;
154 if( !strcmp( p_parser->psz_capability, "services_discovery" ) )
156 o_lmi = [[o_mi_services submenu] addItemWithTitle:
157 [NSString stringWithCString:
158 p_parser->psz_longname ? p_parser->psz_longname :
159 ( p_parser->psz_shortname ? p_parser->psz_shortname:
160 p_parser->psz_object_name)]
161 action: @selector(servicesChange:)
163 [o_lmi setTarget: self];
164 [o_lmi setRepresentedObject:
165 [NSString stringWithCString: p_parser->psz_object_name]];
166 if( playlist_IsServicesDiscoveryLoaded( p_playlist,
167 p_parser->psz_object_name ) )
168 [o_lmi setState: NSOnState];
171 vlc_list_release( p_list );
172 vlc_object_release( p_playlist );
175 //[self playlistUpdated];
180 [o_mi_save_playlist setTitle: _NS("Save Playlist...")];
181 [o_mi_play setTitle: _NS("Play")];
182 [o_mi_delete setTitle: _NS("Delete")];
183 [o_mi_selectall setTitle: _NS("Select All")];
184 [o_mi_info setTitle: _NS("Properties")];
185 [o_mi_sort_name setTitle: _NS("Sort Node by Name")];
186 [o_mi_sort_author setTitle: _NS("Sort Node by Author")];
187 [o_mi_services setTitle: _NS("Services discovery")];
188 [[o_tc_name headerCell] setStringValue:_NS("Name")];
189 [[o_tc_author headerCell] setStringValue:_NS("Author")];
190 [[o_tc_duration headerCell] setStringValue:_NS("Duration")];
191 [o_status_field setStringValue: [NSString stringWithFormat:
192 _NS("no items in playlist")]];
194 [o_random_ckb setTitle: _NS("Random")];
196 [o_search_button setTitle: _NS("Search")];
198 [[o_loop_popup itemAtIndex:0] setTitle: _NS("Standard Play")];
199 [[o_loop_popup itemAtIndex:1] setTitle: _NS("Repeat One")];
200 [[o_loop_popup itemAtIndex:2] setTitle: _NS("Repeat All")];
203 - (NSOutlineView *)outlineView
205 return o_outline_view;
208 - (void)playlistUpdated
212 /* Clear indications of any existing column sorting*/
213 for( i = 0 ; i < [[o_outline_view tableColumns] count] ; i++ )
215 [o_outline_view setIndicatorImage:nil inTableColumn:
216 [[o_outline_view tableColumns] objectAtIndex:i]];
219 [o_outline_view setHighlightedTableColumn:nil];
220 o_tc_sortColumn = nil;
221 // TODO Find a way to keep the dict size to a minimum
222 //[o_outline_dict removeAllObjects];
223 [o_outline_view reloadData];
226 - (void)updateRowSelection
231 playlist_t *p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
233 playlist_item_t *p_item, *p_temp_item;
234 NSMutableArray *o_array = [NSMutableArray array];
236 if( p_playlist == NULL )
239 p_item = p_playlist->status.p_item;
240 p_temp_item = p_item;
242 while( p_temp_item->i_parents > 0 )
244 [o_array insertObject: [NSValue valueWithPointer: p_temp_item] atIndex: 0];
245 for (i = 0 ; i < p_temp_item->i_parents ; i++)
247 if( p_temp_item->pp_parents[i]->i_view == i_current_view )
249 p_temp_item = p_temp_item->pp_parents[i]->p_parent;
255 for (j = 0 ; j < [o_array count] - 1 ; j++)
257 [o_outline_view expandItem: [o_outline_dict objectForKey:
258 [NSString stringWithFormat: @"%p",
259 [[o_array objectAtIndex:j] pointerValue]]]];
263 i_row = [o_outline_view rowForItem:[o_outline_dict
264 objectForKey:[NSString stringWithFormat: @"%p", p_item]]];
266 [o_outline_view selectRow: i_row byExtendingSelection: NO];
267 [o_outline_view scrollRowToVisible: i_row];
269 vlc_object_release(p_playlist);
273 - (BOOL)isItem: (playlist_item_t *)p_item inNode: (playlist_item_t *)p_node
275 playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
277 playlist_item_t *p_temp_item = p_item;
279 if( p_playlist == NULL )
284 while( p_temp_item->i_parents > 0 )
287 for( i = 0; i < p_temp_item->i_parents ; i++ )
289 if( p_temp_item->pp_parents[i]->i_view == i_current_view )
291 if( p_temp_item->pp_parents[i]->p_parent == p_node )
293 vlc_object_release( p_playlist );
298 p_temp_item = p_temp_item->pp_parents[i]->p_parent;
305 vlc_object_release( p_playlist );
310 /* When called retrieves the selected outlineview row and plays that node or item */
311 - (IBAction)playItem:(id)sender
313 intf_thread_t * p_intf = VLCIntf;
314 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
317 if( p_playlist != NULL )
319 playlist_item_t *p_item;
320 playlist_item_t *p_node = NULL;
323 p_item = [[o_outline_view itemAtRow:[o_outline_view selectedRow]] pointerValue];
327 if( p_item->i_children == -1 )
329 for( i = 0 ; i < p_item->i_parents ; i++ )
331 if( p_item->pp_parents[i]->i_view == i_current_view )
333 p_node = p_item->pp_parents[i]->p_parent;
340 if( p_node->i_children > 0 && p_node->pp_children[0]->i_children == -1 )
342 p_item = p_node->pp_children[0];
350 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, i_current_view, p_node, p_item );
352 vlc_object_release( p_playlist );
356 - (IBAction)servicesChange:(id)sender
358 NSMenuItem *o_mi = (NSMenuItem *)sender;
359 NSString *o_string = [o_mi representedObject];
360 playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
362 if( !playlist_IsServicesDiscoveryLoaded( p_playlist, [o_string cString] ) )
363 playlist_ServicesDiscoveryAdd( p_playlist, [o_string cString] );
365 playlist_ServicesDiscoveryRemove( p_playlist, [o_string cString] );
367 [o_mi setState: playlist_IsServicesDiscoveryLoaded( p_playlist,
368 [o_string cString] ) ? YES : NO];
369 [self playlistUpdated];
373 - (IBAction)selectAll:(id)sender
375 [o_outline_view selectAll: nil];
378 - (IBAction)deleteItem:(id)sender
380 int i, i_count, i_row;
381 NSMutableArray *o_to_delete;
384 playlist_t * p_playlist;
385 intf_thread_t * p_intf = VLCIntf;
387 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
390 if ( p_playlist == NULL )
394 o_to_delete = [NSMutableArray arrayWithArray:[[o_outline_view selectedRowEnumerator] allObjects]];
395 i_count = [o_to_delete count];
397 for( i = 0; i < i_count; i++ )
399 playlist_item_t * p_item;
400 o_number = [o_to_delete lastObject];
401 i_row = [o_number intValue];
403 [o_to_delete removeObject: o_number];
404 [o_outline_view deselectRow: i_row];
406 p_item = (playlist_item_t *)[[o_outline_view itemAtRow: i_row] pointerValue];
408 if( p_item->i_children > -1 ) //is a node and not an item
410 if( p_playlist->status.i_status != PLAYLIST_STOPPED &&
411 [self isItem: p_playlist->status.p_item inNode: p_item] == YES )
413 // if current item is in selected node and is playing then stop playlist
414 playlist_Stop( p_playlist );
416 playlist_NodeDelete( p_playlist, p_item, VLC_TRUE, VLC_FALSE );
420 if( p_playlist->status.i_status != PLAYLIST_STOPPED &&
421 p_playlist->status.p_item == [[o_outline_view itemAtRow: i_row] pointerValue] )
423 playlist_Stop( p_playlist );
425 playlist_LockDelete( p_playlist, p_item->input.i_id );
428 [self playlistUpdated];
429 vlc_object_release( p_playlist );
432 - (IBAction)sortNodeByName:(id)sender
434 [self sortNode: SORT_TITLE];
437 - (IBAction)sortNodeByAuthor:(id)sender
439 [self sortNode: SORT_AUTHOR];
442 - (void)sortNode:(int)i_mode
444 playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
446 playlist_item_t * p_item;
448 if (p_playlist == NULL)
453 if( [o_outline_view selectedRow] > -1 )
455 p_item = [[o_outline_view itemAtRow: [o_outline_view selectedRow]]
459 /*If no item is selected, sort the whole playlist*/
461 playlist_view_t * p_view = playlist_ViewFind( p_playlist, i_current_view );
462 p_item = p_view->p_root;
465 if( p_item->i_children > -1 ) // the item is a node
467 vlc_mutex_lock( &p_playlist->object_lock );
468 playlist_RecursiveNodeSort( p_playlist, p_item, i_mode, ORDER_NORMAL );
469 vlc_mutex_unlock( &p_playlist->object_lock );
475 for( i = 0 ; i < p_item->i_parents ; i++ )
477 if( p_item->pp_parents[i]->i_view == i_current_view )
479 vlc_mutex_lock( &p_playlist->object_lock );
480 playlist_RecursiveNodeSort( p_playlist,
481 p_item->pp_parents[i]->p_parent, i_mode, ORDER_NORMAL );
482 vlc_mutex_unlock( &p_playlist->object_lock );
487 vlc_object_release( p_playlist );
488 [self playlistUpdated];
491 - (void)appendArray:(NSArray*)o_array atPos:(int)i_position enqueue:(BOOL)b_enqueue
494 intf_thread_t * p_intf = VLCIntf;
495 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
498 if( p_playlist == NULL )
503 for( i_item = 0; i_item < (int)[o_array count]; i_item++ )
506 NSDictionary *o_one_item;
507 int j, i_total_options = 0, i_new_id = -1;
508 int i_mode = PLAYLIST_INSERT;
509 BOOL b_rem = FALSE, b_dir = FALSE;
510 NSString *o_uri, *o_name;
513 char **ppsz_options = NULL;
516 o_one_item = [o_array objectAtIndex: i_item];
517 o_uri = (NSString *)[o_one_item objectForKey: @"ITEM_URL"];
518 o_name = (NSString *)[o_one_item objectForKey: @"ITEM_NAME"];
519 o_options = (NSArray *)[o_one_item objectForKey: @"ITEM_OPTIONS"];
521 /* Find the name for a disc entry ( i know, can you believe the trouble?) */
522 if( ( !o_name || [o_name isEqualToString:@""] ) && [o_uri rangeOfString: @"/dev/"].location != NSNotFound )
524 int i_count, i_index;
525 struct statfs *mounts = NULL;
527 i_count = getmntinfo (&mounts, MNT_NOWAIT);
528 /* getmntinfo returns a pointer to static data. Do not free. */
529 for( i_index = 0 ; i_index < i_count; i_index++ )
531 NSMutableString *o_temp, *o_temp2;
532 o_temp = [NSMutableString stringWithString: o_uri];
533 o_temp2 = [NSMutableString stringWithCString: mounts[i_index].f_mntfromname];
534 [o_temp replaceOccurrencesOfString: @"/dev/rdisk" withString: @"/dev/disk" options:NULL range:NSMakeRange(0, [o_temp length]) ];
535 [o_temp2 replaceOccurrencesOfString: @"s0" withString: @"" options:NULL range:NSMakeRange(0, [o_temp2 length]) ];
536 [o_temp2 replaceOccurrencesOfString: @"s1" withString: @"" options:NULL range:NSMakeRange(0, [o_temp2 length]) ];
538 if( strstr( [o_temp fileSystemRepresentation], [o_temp2 fileSystemRepresentation] ) != NULL )
540 o_name = [[NSFileManager defaultManager] displayNameAtPath: [NSString stringWithCString:mounts[i_index].f_mntonname]];
544 /* If no name, then make a guess */
545 if( !o_name) o_name = [[NSFileManager defaultManager] displayNameAtPath: o_uri];
547 if( [[NSFileManager defaultManager] fileExistsAtPath:o_uri isDirectory:&b_dir] && b_dir &&
548 [[NSWorkspace sharedWorkspace] getFileSystemInfoForPath: o_uri isRemovable: &b_rem
549 isWritable:NULL isUnmountable:NULL description:NULL type:NULL] && b_rem )
551 /* All of this is to make sure CD's play when you D&D them on VLC */
552 /* Converts mountpoint to a /dev file */
555 NSMutableString *o_temp;
557 buf = (struct statfs *) malloc (sizeof(struct statfs));
558 statfs( [o_uri fileSystemRepresentation], buf );
559 psz_dev = strdup(buf->f_mntfromname);
560 o_temp = [NSMutableString stringWithCString: psz_dev ];
561 [o_temp replaceOccurrencesOfString: @"/dev/disk" withString: @"/dev/rdisk" options:NULL range:NSMakeRange(0, [o_temp length]) ];
562 [o_temp replaceOccurrencesOfString: @"s0" withString: @"" options:NULL range:NSMakeRange(0, [o_temp length]) ];
563 [o_temp replaceOccurrencesOfString: @"s1" withString: @"" options:NULL range:NSMakeRange(0, [o_temp length]) ];
567 if( o_options && [o_options count] > 0 )
569 /* Count the input options */
570 i_total_options = [o_options count];
572 /* Allocate ppsz_options */
573 for( j = 0; j < i_total_options; j++ )
576 ppsz_options = (char **)malloc( sizeof(char *) * i_total_options );
578 ppsz_options[j] = strdup([[o_options objectAtIndex:j] UTF8String]);
583 i_new_id = playlist_AddExt( p_playlist, [o_uri fileSystemRepresentation],
584 [o_name UTF8String], i_mode,
585 i_position == -1 ? PLAYLIST_END : i_position + i_item,
586 0, (ppsz_options != NULL ) ? (const char **)ppsz_options : 0, i_total_options );
588 /* Recent documents menu */
589 o_true_file = [NSURL fileURLWithPath: o_uri];
590 if( o_true_file != nil )
592 [[NSDocumentController sharedDocumentController]
593 noteNewRecentDocumentURL: o_true_file];
596 if( i_item == 0 && !b_enqueue )
598 playlist_Goto( p_playlist, playlist_GetPositionById( p_playlist, i_new_id ) );
599 playlist_Play( p_playlist );
603 vlc_object_release( p_playlist );
606 - (IBAction)handlePopUp:(id)sender
609 intf_thread_t * p_intf = VLCIntf;
610 vlc_value_t val1,val2;
611 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
613 if( p_playlist == NULL )
618 switch( [o_loop_popup indexOfSelectedItem] )
623 var_Set( p_playlist, "loop", val1 );
625 var_Set( p_playlist, "repeat", val1 );
626 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat One" ) );
631 var_Set( p_playlist, "repeat", val1 );
633 var_Set( p_playlist, "loop", val1 );
634 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat All" ) );
638 var_Get( p_playlist, "repeat", &val1 );
639 var_Get( p_playlist, "loop", &val2 );
640 if( val1.b_bool || val2.b_bool )
643 var_Set( p_playlist, "repeat", val1 );
644 var_Set( p_playlist, "loop", val1 );
645 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat Off" ) );
649 vlc_object_release( p_playlist );
650 [self playlistUpdated];
653 - (NSMutableArray *)subSearchItem:(playlist_item_t *)p_item
655 playlist_t *p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
657 playlist_item_t *p_selected_item;
658 int i_current, i_selected_row;
663 i_selected_row = [o_outline_view selectedRow];
664 if (i_selected_row < 0)
667 p_selected_item = (playlist_item_t *)[[o_outline_view itemAtRow:
668 i_selected_row] pointerValue];
670 for( i_current = 0; i_current < p_item->i_children ; i_current++ )
673 NSString *o_current_name, *o_current_author;
675 vlc_mutex_lock( &p_playlist->object_lock );
676 o_current_name = [NSString stringWithUTF8String:
677 p_item->pp_children[i_current]->input.psz_name];
678 psz_temp = vlc_input_item_GetInfo( &p_item->input ,
679 _("Meta-information"),_("Artist") );
680 o_current_author = [NSString stringWithUTF8String: psz_temp];
682 vlc_mutex_unlock( &p_playlist->object_lock );
684 if( p_selected_item == p_item->pp_children[i_current] &&
685 b_selected_item_met == NO )
687 b_selected_item_met = YES;
689 else if( p_selected_item == p_item->pp_children[i_current] &&
690 b_selected_item_met == YES )
692 vlc_object_release( p_playlist );
695 else if( b_selected_item_met == YES &&
696 ( [o_current_name rangeOfString:[o_search_field
697 stringValue] options:NSCaseInsensitiveSearch ].length ||
698 [o_current_author rangeOfString:[o_search_field
699 stringValue] options:NSCaseInsensitiveSearch ].length ) )
701 vlc_object_release( p_playlist );
702 /*Adds the parent items in the result array as well, so that we can
704 return [NSMutableArray arrayWithObject: [NSValue
705 valueWithPointer: p_item->pp_children[i_current]]];
707 if( p_item->pp_children[i_current]->i_children > 0 )
709 id o_result = [self subSearchItem:
710 p_item->pp_children[i_current]];
711 if( o_result != NULL )
713 vlc_object_release( p_playlist );
714 [o_result insertObject: [NSValue valueWithPointer:
715 p_item->pp_children[i_current]] atIndex:0];
720 vlc_object_release( p_playlist );
724 - (IBAction)searchItem:(id)sender
726 playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
728 playlist_view_t * p_view;
734 b_selected_item_met = NO;
736 if( p_playlist == NULL )
739 p_view = playlist_ViewFind( p_playlist, i_current_view );
743 /*First, only search after the selected item:*
744 *(b_selected_item_met = NO) */
745 o_result = [self subSearchItem:p_view->p_root];
746 if( o_result == NULL )
748 /* If the first search failed, search again from the beginning */
749 o_result = [self subSearchItem:p_view->p_root];
751 if( o_result != NULL )
753 for( i = 0 ; i < [o_result count] - 1 ; i++ )
755 [o_outline_view expandItem: [o_outline_dict objectForKey:
756 [NSString stringWithFormat: @"%p",
757 [[o_result objectAtIndex: i] pointerValue]]]];
759 i_row = [o_outline_view rowForItem: [o_outline_dict objectForKey:
760 [NSString stringWithFormat: @"%p",
761 [[o_result objectAtIndex: [o_result count] - 1 ]
766 [o_outline_view selectRow:i_row byExtendingSelection: NO];
767 [o_outline_view scrollRowToVisible: i_row];
770 vlc_object_release( p_playlist );
773 - (NSMenu *)menuForEvent:(NSEvent *)o_event
777 vlc_bool_t b_item_sel;
779 pt = [o_outline_view convertPoint: [o_event locationInWindow]
781 b_item_sel = ( [o_outline_view rowAtPoint: pt] != -1 &&
782 [o_outline_view selectedRow] != -1 );
783 b_rows = [o_outline_view numberOfRows] != 0;
785 [o_mi_play setEnabled: b_item_sel];
786 [o_mi_delete setEnabled: b_item_sel];
787 [o_mi_selectall setEnabled: b_rows];
788 [o_mi_info setEnabled: b_item_sel];
790 return( o_ctx_menu );
793 - (playlist_item_t *)selectedPlaylistItem
795 return [[o_outline_view itemAtRow: [o_outline_view selectedRow]]
799 - (void)outlineView: (NSTableView*)o_tv
800 didClickTableColumn:(NSTableColumn *)o_tc
802 int i_mode = 0, i_type;
803 intf_thread_t *p_intf = VLCIntf;
804 playlist_view_t *p_view;
806 playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
808 if( p_playlist == NULL )
813 /* Check whether the selected table column header corresponds to a
814 sortable table column*/
815 if( !( o_tc == o_tc_name || o_tc == o_tc_author ) )
817 vlc_object_release( p_playlist );
821 p_view = playlist_ViewFind( p_playlist, i_current_view );
823 if( o_tc_sortColumn == o_tc )
825 b_isSortDescending = !b_isSortDescending;
829 b_isSortDescending = VLC_FALSE;
832 if( o_tc == o_tc_name )
836 else if( o_tc == o_tc_author )
838 i_mode = SORT_AUTHOR;
841 if( b_isSortDescending )
843 i_type = ORDER_REVERSE;
847 i_type = ORDER_NORMAL;
850 vlc_mutex_lock( &p_playlist->object_lock );
851 playlist_RecursiveNodeSort( p_playlist, p_view->p_root, i_mode, i_type );
852 vlc_mutex_unlock( &p_playlist->object_lock );
854 vlc_object_release( p_playlist );
855 [self playlistUpdated];
857 o_tc_sortColumn = o_tc;
858 [o_outline_view setHighlightedTableColumn:o_tc];
860 if( b_isSortDescending )
862 [o_outline_view setIndicatorImage:o_descendingSortingImage
867 [o_outline_view setIndicatorImage:o_ascendingSortingImage
874 @implementation VLCPlaylist (NSOutlineViewDataSource)
876 /* return the number of children for Obj-C pointer item */ /* DONE */
877 - (int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
880 playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
882 if( p_playlist == NULL || outlineView != o_outline_view )
888 playlist_view_t *p_view;
889 p_view = playlist_ViewFind( p_playlist, i_current_view );
890 if( p_view && p_view->p_root )
891 i_return = p_view->p_root->i_children;
895 playlist_item_t *p_item = (playlist_item_t *)[item pointerValue];
897 i_return = p_item->i_children;
899 vlc_object_release( p_playlist );
907 /* return the child at index for the Obj-C pointer item */ /* DONE */
908 - (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item
910 playlist_item_t *p_return = NULL;
911 playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
915 if( p_playlist == NULL )
921 playlist_view_t *p_view;
922 p_view = playlist_ViewFind( p_playlist, i_current_view );
923 if( p_view && index < p_view->p_root->i_children && index >= 0 )
924 p_return = p_view->p_root->pp_children[index];
928 playlist_item_t *p_item = (playlist_item_t *)[item pointerValue];
929 if( p_item && index < p_item->i_children && index >= 0 )
930 p_return = p_item->pp_children[index];
933 if( p_playlist->i_size >= 2 )
935 [o_status_field setStringValue: [NSString stringWithFormat:
936 _NS("%i items in playlist"), p_playlist->i_size]];
940 if( p_playlist->i_size == 0 )
942 [o_status_field setStringValue: [NSString stringWithFormat:
943 _NS("no items in playlist"), p_playlist->i_size]];
947 [o_status_field setStringValue: [NSString stringWithFormat:
948 _NS("1 item in playlist"), p_playlist->i_size]];
952 vlc_object_release( p_playlist );
955 o_value = [[NSValue valueWithPointer: p_return] retain];
957 if( [o_outline_dict objectForKey: [NSString stringWithFormat:@"%p", p_return]] == nil )
959 [o_outline_dict setObject:o_value forKey:[NSString stringWithFormat:@"%p", p_return]];
964 /* is the item expandable */
965 - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item
968 playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
970 if( p_playlist == NULL )
976 playlist_view_t *p_view;
977 p_view = playlist_ViewFind( p_playlist, i_current_view );
978 if( p_view && p_view->p_root )
979 i_return = p_view->p_root->i_children;
983 playlist_item_t *p_item = (playlist_item_t *)[item pointerValue];
985 i_return = p_item->i_children;
987 vlc_object_release( p_playlist );
995 /* retrieve the string values for the cells */
996 - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)o_tc byItem:(id)item
999 intf_thread_t *p_intf = VLCIntf;
1000 playlist_t *p_playlist;
1001 playlist_item_t *p_item;
1003 if( item == nil || ![item isKindOfClass: [NSValue class]] ) return( @"error" );
1005 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1007 if( p_playlist == NULL )
1012 p_item = (playlist_item_t *)[item pointerValue];
1014 if( p_item == NULL )
1016 vlc_object_release( p_playlist );
1020 if( [[o_tc identifier] isEqualToString:@"1"] )
1022 o_value = [NSString stringWithUTF8String:
1023 p_item->input.psz_name];
1024 if( o_value == NULL )
1025 o_value = [NSString stringWithCString:
1026 p_item->input.psz_name];
1028 else if( [[o_tc identifier] isEqualToString:@"2"] )
1031 psz_temp = vlc_input_item_GetInfo( &p_item->input ,_("Meta-information"),_("Artist") );
1033 if( psz_temp == NULL )
1037 o_value = [NSString stringWithUTF8String: psz_temp];
1038 if( o_value == NULL )
1040 o_value = [NSString stringWithCString: psz_temp];
1045 else if( [[o_tc identifier] isEqualToString:@"3"] )
1047 char psz_duration[MSTRTIME_MAX_SIZE];
1048 mtime_t dur = p_item->input.i_duration;
1051 secstotimestr( psz_duration, dur/1000000 );
1052 o_value = [NSString stringWithUTF8String: psz_duration];
1056 o_value = @"-:--:--";
1059 vlc_object_release( p_playlist );
1064 /* Required for drag & drop and reordering */
1065 - (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pboard
1070 - (NSDragOperation)outlineView:(NSOutlineView *)outlineView validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(int)index
1072 return NSDragOperationNone;
1075 /* Delegate method of NSWindow */
1076 /*- (void)windowWillClose:(NSNotification *)aNotification
1078 [o_btn_playlist setState: NSOffState];