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_SIMPLE;
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 /* create the menu entries used in the playlist menu */
157 o_lmi = [[o_mi_services submenu] addItemWithTitle:
158 [NSString stringWithCString:
159 p_parser->psz_longname ? p_parser->psz_longname :
160 ( p_parser->psz_shortname ? p_parser->psz_shortname:
161 p_parser->psz_object_name)]
162 action: @selector(servicesChange:)
164 [o_lmi setTarget: self];
165 [o_lmi setRepresentedObject:
166 [NSString stringWithCString: p_parser->psz_object_name]];
167 if( playlist_IsServicesDiscoveryLoaded( p_playlist,
168 p_parser->psz_object_name ) )
169 [o_lmi setState: NSOnState];
171 /* create the menu entries for the main menu */
172 o_lmi = [[o_mm_mi_services submenu] addItemWithTitle:
173 [NSString stringWithCString:
174 p_parser->psz_longname ? p_parser->psz_longname :
175 ( p_parser->psz_shortname ? p_parser->psz_shortname:
176 p_parser->psz_object_name)]
177 action: @selector(servicesChange:)
179 [o_lmi setTarget: self];
180 [o_lmi setRepresentedObject:
181 [NSString stringWithCString: p_parser->psz_object_name]];
182 if( playlist_IsServicesDiscoveryLoaded( p_playlist,
183 p_parser->psz_object_name ) )
184 [o_lmi setState: NSOnState];
187 vlc_list_release( p_list );
188 vlc_object_release( p_playlist );
191 //[self playlistUpdated];
196 [o_mi_save_playlist setTitle: _NS("Save Playlist...")];
197 [o_mi_play setTitle: _NS("Play")];
198 [o_mi_delete setTitle: _NS("Delete")];
199 [o_mi_selectall setTitle: _NS("Select All")];
200 [o_mi_info setTitle: _NS("Properties")];
201 [o_mi_sort_name setTitle: _NS("Sort Node by Name")];
202 [o_mi_sort_author setTitle: _NS("Sort Node by Author")];
203 [o_mi_services setTitle: _NS("Services discovery")];
204 [[o_tc_name headerCell] setStringValue:_NS("Name")];
205 [[o_tc_author headerCell] setStringValue:_NS("Author")];
206 [[o_tc_duration headerCell] setStringValue:_NS("Duration")];
207 [o_status_field setStringValue: [NSString stringWithFormat:
208 _NS("no items in playlist")]];
210 [o_random_ckb setTitle: _NS("Random")];
212 [o_search_button setTitle: _NS("Search")];
214 [[o_loop_popup itemAtIndex:0] setTitle: _NS("Standard Play")];
215 [[o_loop_popup itemAtIndex:1] setTitle: _NS("Repeat One")];
216 [[o_loop_popup itemAtIndex:2] setTitle: _NS("Repeat All")];
219 - (NSOutlineView *)outlineView
221 return o_outline_view;
224 - (void)playlistUpdated
228 /* Clear indications of any existing column sorting*/
229 for( i = 0 ; i < [[o_outline_view tableColumns] count] ; i++ )
231 [o_outline_view setIndicatorImage:nil inTableColumn:
232 [[o_outline_view tableColumns] objectAtIndex:i]];
235 [o_outline_view setHighlightedTableColumn:nil];
236 o_tc_sortColumn = nil;
237 // TODO Find a way to keep the dict size to a minimum
238 //[o_outline_dict removeAllObjects];
239 [o_outline_view reloadData];
242 - (void)updateRowSelection
247 playlist_t *p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
249 playlist_item_t *p_item, *p_temp_item;
250 NSMutableArray *o_array = [NSMutableArray array];
252 if( p_playlist == NULL )
255 p_item = p_playlist->status.p_item;
256 p_temp_item = p_item;
258 while( p_temp_item->i_parents > 0 )
260 [o_array insertObject: [NSValue valueWithPointer: p_temp_item] atIndex: 0];
261 for (i = 0 ; i < p_temp_item->i_parents ; i++)
263 if( p_temp_item->pp_parents[i]->i_view == i_current_view )
265 p_temp_item = p_temp_item->pp_parents[i]->p_parent;
271 for (j = 0 ; j < [o_array count] - 1 ; j++)
273 [o_outline_view expandItem: [o_outline_dict objectForKey:
274 [NSString stringWithFormat: @"%p",
275 [[o_array objectAtIndex:j] pointerValue]]]];
279 i_row = [o_outline_view rowForItem:[o_outline_dict
280 objectForKey:[NSString stringWithFormat: @"%p", p_item]]];
282 [o_outline_view selectRow: i_row byExtendingSelection: NO];
283 [o_outline_view scrollRowToVisible: i_row];
285 vlc_object_release(p_playlist);
289 - (BOOL)isItem: (playlist_item_t *)p_item inNode: (playlist_item_t *)p_node
291 playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
293 playlist_item_t *p_temp_item = p_item;
295 if( p_playlist == NULL )
300 while( p_temp_item->i_parents > 0 )
303 for( i = 0; i < p_temp_item->i_parents ; i++ )
305 if( p_temp_item->pp_parents[i]->i_view == i_current_view )
307 if( p_temp_item->pp_parents[i]->p_parent == p_node )
309 vlc_object_release( p_playlist );
314 p_temp_item = p_temp_item->pp_parents[i]->p_parent;
321 vlc_object_release( p_playlist );
326 /* When called retrieves the selected outlineview row and plays that node or item */
327 - (IBAction)playItem:(id)sender
329 intf_thread_t * p_intf = VLCIntf;
330 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
333 if( p_playlist != NULL )
335 playlist_item_t *p_item;
336 playlist_item_t *p_node = NULL;
339 p_item = [[o_outline_view itemAtRow:[o_outline_view selectedRow]] pointerValue];
343 if( p_item->i_children == -1 )
345 for( i = 0 ; i < p_item->i_parents ; i++ )
347 if( p_item->pp_parents[i]->i_view == i_current_view )
349 p_node = p_item->pp_parents[i]->p_parent;
356 if( p_node->i_children > 0 && p_node->pp_children[0]->i_children == -1 )
358 p_item = p_node->pp_children[0];
365 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, i_current_view, p_node, p_item );
367 vlc_object_release( p_playlist );
371 - (IBAction)servicesChange:(id)sender
373 NSMenuItem *o_mi = (NSMenuItem *)sender;
374 NSString *o_string = [o_mi representedObject];
375 playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
377 if( !playlist_IsServicesDiscoveryLoaded( p_playlist, [o_string cString] ) )
378 playlist_ServicesDiscoveryAdd( p_playlist, [o_string cString] );
380 playlist_ServicesDiscoveryRemove( p_playlist, [o_string cString] );
382 [o_mi setState: playlist_IsServicesDiscoveryLoaded( p_playlist,
383 [o_string cString] ) ? YES : NO];
385 i_current_view = VIEW_CATEGORY;
386 playlist_ViewUpdate( p_playlist, i_current_view );
387 [self playlistUpdated];
391 - (IBAction)selectAll:(id)sender
393 [o_outline_view selectAll: nil];
396 - (IBAction)deleteItem:(id)sender
398 int i, i_count, i_row;
399 NSMutableArray *o_to_delete;
402 playlist_t * p_playlist;
403 intf_thread_t * p_intf = VLCIntf;
405 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
408 if ( p_playlist == NULL )
412 o_to_delete = [NSMutableArray arrayWithArray:[[o_outline_view selectedRowEnumerator] allObjects]];
413 i_count = [o_to_delete count];
415 for( i = 0; i < i_count; i++ )
417 playlist_item_t * p_item;
418 o_number = [o_to_delete lastObject];
419 i_row = [o_number intValue];
421 [o_to_delete removeObject: o_number];
422 [o_outline_view deselectRow: i_row];
424 p_item = (playlist_item_t *)[[o_outline_view itemAtRow: i_row] pointerValue];
426 if( p_item->i_children > -1 ) //is a node and not an item
428 if( p_playlist->status.i_status != PLAYLIST_STOPPED &&
429 [self isItem: p_playlist->status.p_item inNode: p_item] == YES )
431 // if current item is in selected node and is playing then stop playlist
432 playlist_Stop( p_playlist );
434 playlist_NodeDelete( p_playlist, p_item, VLC_TRUE, VLC_FALSE );
438 if( p_playlist->status.i_status != PLAYLIST_STOPPED &&
439 p_playlist->status.p_item == [[o_outline_view itemAtRow: i_row] pointerValue] )
441 playlist_Stop( p_playlist );
443 playlist_LockDelete( p_playlist, p_item->input.i_id );
446 [self playlistUpdated];
447 vlc_object_release( p_playlist );
450 - (IBAction)sortNodeByName:(id)sender
452 [self sortNode: SORT_TITLE];
455 - (IBAction)sortNodeByAuthor:(id)sender
457 [self sortNode: SORT_AUTHOR];
460 - (void)sortNode:(int)i_mode
462 playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
464 playlist_item_t * p_item;
466 if (p_playlist == NULL)
471 if( [o_outline_view selectedRow] > -1 )
473 p_item = [[o_outline_view itemAtRow: [o_outline_view selectedRow]]
477 /*If no item is selected, sort the whole playlist*/
479 playlist_view_t * p_view = playlist_ViewFind( p_playlist, i_current_view );
480 p_item = p_view->p_root;
483 if( p_item->i_children > -1 ) // the item is a node
485 vlc_mutex_lock( &p_playlist->object_lock );
486 playlist_RecursiveNodeSort( p_playlist, p_item, i_mode, ORDER_NORMAL );
487 vlc_mutex_unlock( &p_playlist->object_lock );
493 for( i = 0 ; i < p_item->i_parents ; i++ )
495 if( p_item->pp_parents[i]->i_view == i_current_view )
497 vlc_mutex_lock( &p_playlist->object_lock );
498 playlist_RecursiveNodeSort( p_playlist,
499 p_item->pp_parents[i]->p_parent, i_mode, ORDER_NORMAL );
500 vlc_mutex_unlock( &p_playlist->object_lock );
505 vlc_object_release( p_playlist );
506 [self playlistUpdated];
509 - (void)appendArray:(NSArray*)o_array atPos:(int)i_position enqueue:(BOOL)b_enqueue
512 intf_thread_t * p_intf = VLCIntf;
513 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
516 if( p_playlist == NULL )
521 for( i_item = 0; i_item < (int)[o_array count]; i_item++ )
524 NSDictionary *o_one_item;
525 int j, i_total_options = 0, i_new_id = -1;
526 int i_mode = PLAYLIST_INSERT;
527 BOOL b_rem = FALSE, b_dir = FALSE;
528 NSString *o_uri, *o_name;
531 char **ppsz_options = NULL;
534 o_one_item = [o_array objectAtIndex: i_item];
535 o_uri = (NSString *)[o_one_item objectForKey: @"ITEM_URL"];
536 o_name = (NSString *)[o_one_item objectForKey: @"ITEM_NAME"];
537 o_options = (NSArray *)[o_one_item objectForKey: @"ITEM_OPTIONS"];
539 /* Find the name for a disc entry ( i know, can you believe the trouble?) */
540 if( ( !o_name || [o_name isEqualToString:@""] ) && [o_uri rangeOfString: @"/dev/"].location != NSNotFound )
542 int i_count, i_index;
543 struct statfs *mounts = NULL;
545 i_count = getmntinfo (&mounts, MNT_NOWAIT);
546 /* getmntinfo returns a pointer to static data. Do not free. */
547 for( i_index = 0 ; i_index < i_count; i_index++ )
549 NSMutableString *o_temp, *o_temp2;
550 o_temp = [NSMutableString stringWithString: o_uri];
551 o_temp2 = [NSMutableString stringWithCString: mounts[i_index].f_mntfromname];
552 [o_temp replaceOccurrencesOfString: @"/dev/rdisk" withString: @"/dev/disk" options:NULL range:NSMakeRange(0, [o_temp length]) ];
553 [o_temp2 replaceOccurrencesOfString: @"s0" withString: @"" options:NULL range:NSMakeRange(0, [o_temp2 length]) ];
554 [o_temp2 replaceOccurrencesOfString: @"s1" withString: @"" options:NULL range:NSMakeRange(0, [o_temp2 length]) ];
556 if( strstr( [o_temp fileSystemRepresentation], [o_temp2 fileSystemRepresentation] ) != NULL )
558 o_name = [[NSFileManager defaultManager] displayNameAtPath: [NSString stringWithCString:mounts[i_index].f_mntonname]];
562 /* If no name, then make a guess */
563 if( !o_name) o_name = [[NSFileManager defaultManager] displayNameAtPath: o_uri];
565 if( [[NSFileManager defaultManager] fileExistsAtPath:o_uri isDirectory:&b_dir] && b_dir &&
566 [[NSWorkspace sharedWorkspace] getFileSystemInfoForPath: o_uri isRemovable: &b_rem
567 isWritable:NULL isUnmountable:NULL description:NULL type:NULL] && b_rem )
569 /* All of this is to make sure CD's play when you D&D them on VLC */
570 /* Converts mountpoint to a /dev file */
573 NSMutableString *o_temp;
575 buf = (struct statfs *) malloc (sizeof(struct statfs));
576 statfs( [o_uri fileSystemRepresentation], buf );
577 psz_dev = strdup(buf->f_mntfromname);
578 o_temp = [NSMutableString stringWithCString: psz_dev ];
579 [o_temp replaceOccurrencesOfString: @"/dev/disk" withString: @"/dev/rdisk" options:NULL range:NSMakeRange(0, [o_temp length]) ];
580 [o_temp replaceOccurrencesOfString: @"s0" withString: @"" options:NULL range:NSMakeRange(0, [o_temp length]) ];
581 [o_temp replaceOccurrencesOfString: @"s1" withString: @"" options:NULL range:NSMakeRange(0, [o_temp length]) ];
585 if( o_options && [o_options count] > 0 )
587 /* Count the input options */
588 i_total_options = [o_options count];
590 /* Allocate ppsz_options */
591 for( j = 0; j < i_total_options; j++ )
594 ppsz_options = (char **)malloc( sizeof(char *) * i_total_options );
596 ppsz_options[j] = strdup([[o_options objectAtIndex:j] UTF8String]);
601 i_new_id = playlist_AddExt( p_playlist, [o_uri fileSystemRepresentation],
602 [o_name UTF8String], i_mode,
603 i_position == -1 ? PLAYLIST_END : i_position + i_item,
604 0, (ppsz_options != NULL ) ? (const char **)ppsz_options : 0, i_total_options );
606 /* Recent documents menu */
607 o_true_file = [NSURL fileURLWithPath: o_uri];
608 if( o_true_file != nil )
610 [[NSDocumentController sharedDocumentController]
611 noteNewRecentDocumentURL: o_true_file];
614 if( i_item == 0 && !b_enqueue )
616 playlist_Goto( p_playlist, playlist_GetPositionById( p_playlist, i_new_id ) );
617 playlist_Play( p_playlist );
621 vlc_object_release( p_playlist );
624 - (IBAction)handlePopUp:(id)sender
627 intf_thread_t * p_intf = VLCIntf;
628 vlc_value_t val1,val2;
629 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
631 if( p_playlist == NULL )
636 switch( [o_loop_popup indexOfSelectedItem] )
641 var_Set( p_playlist, "loop", val1 );
643 var_Set( p_playlist, "repeat", val1 );
644 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat One" ) );
649 var_Set( p_playlist, "repeat", val1 );
651 var_Set( p_playlist, "loop", val1 );
652 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat All" ) );
656 var_Get( p_playlist, "repeat", &val1 );
657 var_Get( p_playlist, "loop", &val2 );
658 if( val1.b_bool || val2.b_bool )
661 var_Set( p_playlist, "repeat", val1 );
662 var_Set( p_playlist, "loop", val1 );
663 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat Off" ) );
667 vlc_object_release( p_playlist );
668 [self playlistUpdated];
671 - (NSMutableArray *)subSearchItem:(playlist_item_t *)p_item
673 playlist_t *p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
675 playlist_item_t *p_selected_item;
676 int i_current, i_selected_row;
681 i_selected_row = [o_outline_view selectedRow];
682 if (i_selected_row < 0)
685 p_selected_item = (playlist_item_t *)[[o_outline_view itemAtRow:
686 i_selected_row] pointerValue];
688 for( i_current = 0; i_current < p_item->i_children ; i_current++ )
691 NSString *o_current_name, *o_current_author;
693 vlc_mutex_lock( &p_playlist->object_lock );
694 o_current_name = [NSString stringWithUTF8String:
695 p_item->pp_children[i_current]->input.psz_name];
696 psz_temp = vlc_input_item_GetInfo( &p_item->input ,
697 _("Meta-information"),_("Artist") );
698 o_current_author = [NSString stringWithUTF8String: psz_temp];
700 vlc_mutex_unlock( &p_playlist->object_lock );
702 if( p_selected_item == p_item->pp_children[i_current] &&
703 b_selected_item_met == NO )
705 b_selected_item_met = YES;
707 else if( p_selected_item == p_item->pp_children[i_current] &&
708 b_selected_item_met == YES )
710 vlc_object_release( p_playlist );
713 else if( b_selected_item_met == YES &&
714 ( [o_current_name rangeOfString:[o_search_field
715 stringValue] options:NSCaseInsensitiveSearch ].length ||
716 [o_current_author rangeOfString:[o_search_field
717 stringValue] options:NSCaseInsensitiveSearch ].length ) )
719 vlc_object_release( p_playlist );
720 /*Adds the parent items in the result array as well, so that we can
722 return [NSMutableArray arrayWithObject: [NSValue
723 valueWithPointer: p_item->pp_children[i_current]]];
725 if( p_item->pp_children[i_current]->i_children > 0 )
727 id o_result = [self subSearchItem:
728 p_item->pp_children[i_current]];
729 if( o_result != NULL )
731 vlc_object_release( p_playlist );
732 [o_result insertObject: [NSValue valueWithPointer:
733 p_item->pp_children[i_current]] atIndex:0];
738 vlc_object_release( p_playlist );
742 - (IBAction)searchItem:(id)sender
744 playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
746 playlist_view_t * p_view;
752 b_selected_item_met = NO;
754 if( p_playlist == NULL )
757 p_view = playlist_ViewFind( p_playlist, i_current_view );
761 /*First, only search after the selected item:*
762 *(b_selected_item_met = NO) */
763 o_result = [self subSearchItem:p_view->p_root];
764 if( o_result == NULL )
766 /* If the first search failed, search again from the beginning */
767 o_result = [self subSearchItem:p_view->p_root];
769 if( o_result != NULL )
771 for( i = 0 ; i < [o_result count] - 1 ; i++ )
773 [o_outline_view expandItem: [o_outline_dict objectForKey:
774 [NSString stringWithFormat: @"%p",
775 [[o_result objectAtIndex: i] pointerValue]]]];
777 i_row = [o_outline_view rowForItem: [o_outline_dict objectForKey:
778 [NSString stringWithFormat: @"%p",
779 [[o_result objectAtIndex: [o_result count] - 1 ]
784 [o_outline_view selectRow:i_row byExtendingSelection: NO];
785 [o_outline_view scrollRowToVisible: i_row];
788 vlc_object_release( p_playlist );
791 - (NSMenu *)menuForEvent:(NSEvent *)o_event
795 vlc_bool_t b_item_sel;
797 pt = [o_outline_view convertPoint: [o_event locationInWindow]
799 b_item_sel = ( [o_outline_view rowAtPoint: pt] != -1 &&
800 [o_outline_view selectedRow] != -1 );
801 b_rows = [o_outline_view numberOfRows] != 0;
803 [o_mi_play setEnabled: b_item_sel];
804 [o_mi_delete setEnabled: b_item_sel];
805 [o_mi_selectall setEnabled: b_rows];
806 [o_mi_info setEnabled: b_item_sel];
808 return( o_ctx_menu );
811 - (playlist_item_t *)selectedPlaylistItem
813 return [[o_outline_view itemAtRow: [o_outline_view selectedRow]]
817 - (void)outlineView: (NSTableView*)o_tv
818 didClickTableColumn:(NSTableColumn *)o_tc
820 int i_mode = 0, i_type;
821 intf_thread_t *p_intf = VLCIntf;
822 playlist_view_t *p_view;
824 playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
826 if( p_playlist == NULL )
831 /* Check whether the selected table column header corresponds to a
832 sortable table column*/
833 if( !( o_tc == o_tc_name || o_tc == o_tc_author ) )
835 vlc_object_release( p_playlist );
839 p_view = playlist_ViewFind( p_playlist, i_current_view );
841 if( o_tc_sortColumn == o_tc )
843 b_isSortDescending = !b_isSortDescending;
847 b_isSortDescending = VLC_FALSE;
850 if( o_tc == o_tc_name )
854 else if( o_tc == o_tc_author )
856 i_mode = SORT_AUTHOR;
859 if( b_isSortDescending )
861 i_type = ORDER_REVERSE;
865 i_type = ORDER_NORMAL;
868 vlc_mutex_lock( &p_playlist->object_lock );
869 playlist_RecursiveNodeSort( p_playlist, p_view->p_root, i_mode, i_type );
870 vlc_mutex_unlock( &p_playlist->object_lock );
872 vlc_object_release( p_playlist );
873 [self playlistUpdated];
875 o_tc_sortColumn = o_tc;
876 [o_outline_view setHighlightedTableColumn:o_tc];
878 if( b_isSortDescending )
880 [o_outline_view setIndicatorImage:o_descendingSortingImage
885 [o_outline_view setIndicatorImage:o_ascendingSortingImage
892 @implementation VLCPlaylist (NSOutlineViewDataSource)
894 /* return the number of children for Obj-C pointer item */ /* DONE */
895 - (int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
898 playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
900 if( p_playlist == NULL || outlineView != o_outline_view )
906 playlist_view_t *p_view;
907 p_view = playlist_ViewFind( p_playlist, i_current_view );
908 if( p_view && p_view->p_root )
909 i_return = p_view->p_root->i_children;
913 playlist_item_t *p_item = (playlist_item_t *)[item pointerValue];
915 i_return = p_item->i_children;
917 vlc_object_release( p_playlist );
925 /* return the child at index for the Obj-C pointer item */ /* DONE */
926 - (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item
928 playlist_item_t *p_return = NULL;
929 playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
933 if( p_playlist == NULL )
939 playlist_view_t *p_view;
940 p_view = playlist_ViewFind( p_playlist, i_current_view );
941 if( p_view && index < p_view->p_root->i_children && index >= 0 )
942 p_return = p_view->p_root->pp_children[index];
946 playlist_item_t *p_item = (playlist_item_t *)[item pointerValue];
947 if( p_item && index < p_item->i_children && index >= 0 )
948 p_return = p_item->pp_children[index];
951 if( p_playlist->i_size >= 2 )
953 [o_status_field setStringValue: [NSString stringWithFormat:
954 _NS("%i items in playlist"), p_playlist->i_size]];
958 if( p_playlist->i_size == 0 )
960 [o_status_field setStringValue: [NSString stringWithFormat:
961 _NS("no items in playlist"), p_playlist->i_size]];
965 [o_status_field setStringValue: [NSString stringWithFormat:
966 _NS("1 item in playlist"), p_playlist->i_size]];
970 vlc_object_release( p_playlist );
973 o_value = [[NSValue valueWithPointer: p_return] retain];
975 if( [o_outline_dict objectForKey: [NSString stringWithFormat:@"%p", p_return]] == nil )
977 [o_outline_dict setObject:o_value forKey:[NSString stringWithFormat:@"%p", p_return]];
982 /* is the item expandable */
983 - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item
986 playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
988 if( p_playlist == NULL )
994 playlist_view_t *p_view;
995 p_view = playlist_ViewFind( p_playlist, i_current_view );
996 if( p_view && p_view->p_root )
997 i_return = p_view->p_root->i_children;
1001 playlist_item_t *p_item = (playlist_item_t *)[item pointerValue];
1003 i_return = p_item->i_children;
1005 vlc_object_release( p_playlist );
1013 /* retrieve the string values for the cells */
1014 - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)o_tc byItem:(id)item
1017 intf_thread_t *p_intf = VLCIntf;
1018 playlist_t *p_playlist;
1019 playlist_item_t *p_item;
1021 if( item == nil || ![item isKindOfClass: [NSValue class]] ) return( @"error" );
1023 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1025 if( p_playlist == NULL )
1030 p_item = (playlist_item_t *)[item pointerValue];
1032 if( p_item == NULL )
1034 vlc_object_release( p_playlist );
1038 if( [[o_tc identifier] isEqualToString:@"1"] )
1040 o_value = [NSString stringWithUTF8String:
1041 p_item->input.psz_name];
1042 if( o_value == NULL )
1043 o_value = [NSString stringWithCString:
1044 p_item->input.psz_name];
1046 else if( [[o_tc identifier] isEqualToString:@"2"] )
1049 psz_temp = vlc_input_item_GetInfo( &p_item->input ,_("Meta-information"),_("Artist") );
1051 if( psz_temp == NULL )
1055 o_value = [NSString stringWithUTF8String: psz_temp];
1056 if( o_value == NULL )
1058 o_value = [NSString stringWithCString: psz_temp];
1063 else if( [[o_tc identifier] isEqualToString:@"3"] )
1065 char psz_duration[MSTRTIME_MAX_SIZE];
1066 mtime_t dur = p_item->input.i_duration;
1069 secstotimestr( psz_duration, dur/1000000 );
1070 o_value = [NSString stringWithUTF8String: psz_duration];
1074 o_value = @"-:--:--";
1077 vlc_object_release( p_playlist );
1082 /* Required for drag & drop and reordering */
1083 - (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pboard
1088 - (NSDragOperation)outlineView:(NSOutlineView *)outlineView validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(int)index
1090 return NSDragOperationNone;
1093 /* Delegate method of NSWindow */
1094 /*- (void)windowWillClose:(NSNotification *)aNotification
1096 [o_btn_playlist setState: NSOffState];