1 /*****************************************************************************
2 * playlist.m: MacOS X interface module
3 *****************************************************************************
4 * Copyright (C) 2002-2012 VLC authors and VideoLAN
7 * Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
8 * Derk-Jan Hartman <hartman at videola/n dot org>
9 * Benjamin Pracht <bigben at videolab dot org>
10 * Felix Paul Kühne <fkuehne at videolan dot org>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25 *****************************************************************************/
28 * add 'icons' for different types of nodes? (http://www.cocoadev.com/index.pl?IconAndTextInTableCell)
29 * reimplement enable/disable item
33 /*****************************************************************************
35 *****************************************************************************/
36 #include <stdlib.h> /* malloc(), free() */
37 #include <sys/param.h> /* for MAXPATHLEN */
40 #include <sys/mount.h>
45 #import "playlistinfo.h"
54 #import <vlc_interface.h>
58 /*****************************************************************************
59 * VLCPlaylistView implementation
60 *****************************************************************************/
61 @implementation VLCPlaylistView
63 - (NSMenu *)menuForEvent:(NSEvent *)o_event
65 return( [(VLCPlaylist *)[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 [(VLCPlaylist *)[self delegate] deleteItem:self];
86 case NSEnterCharacter:
87 case NSCarriageReturnCharacter:
88 [(VLCPlaylist *)[[VLCMain sharedInstance] playlist] playItem:nil];
92 [super keyDown: o_event];
97 - (BOOL)validateMenuItem:(NSMenuItem *)item
99 if (([self numberOfSelectedRows] >= 1 && [item action] == @selector(delete:)) || [item action] == @selector(selectAll:))
105 - (BOOL) acceptsFirstResponder
110 - (BOOL) becomeFirstResponder
112 [self setNeedsDisplay:YES];
116 - (BOOL) resignFirstResponder
118 [self setNeedsDisplay:YES];
122 - (IBAction)delete:(id)sender
124 [[[VLCMain sharedInstance] playlist] deleteItem: sender];
129 /*****************************************************************************
130 * VLCPlaylistCommon implementation
132 * This class the superclass of the VLCPlaylist and VLCPlaylistWizard.
133 * It contains the common methods and elements of these 2 entities.
134 *****************************************************************************/
135 @implementation VLCPlaylistCommon
138 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
139 NSMutableArray * o_columnArray = [[NSMutableArray alloc] init];
140 [o_columnArray addObject: [NSArray arrayWithObjects: TITLE_COLUMN, [NSNumber numberWithFloat: 190.], nil]];
141 [o_columnArray addObject: [NSArray arrayWithObjects: ARTIST_COLUMN, [NSNumber numberWithFloat: 95.], nil]];
142 [o_columnArray addObject: [NSArray arrayWithObjects: DURATION_COLUMN, [NSNumber numberWithFloat: 95.], nil]];
143 NSDictionary *appDefaults = [NSDictionary dictionaryWithObject:[NSArray arrayWithArray:o_columnArray] forKey:@"PlaylistColumnSelection"];
145 [defaults registerDefaults:appDefaults];
146 [o_columnArray release];
151 playlist_t * p_playlist = pl_Get( VLCIntf );
152 p_current_root_item = p_playlist->p_local_category;
157 o_outline_dict = [[NSMutableDictionary alloc] init];
164 playlist_t * p_playlist = pl_Get( VLCIntf );
165 [o_outline_view setTarget: self];
166 [o_outline_view setDelegate: self];
167 [o_outline_view setDataSource: self];
168 [o_outline_view setAllowsEmptySelection: NO];
169 [o_outline_view expandItem: [o_outline_view itemAtRow:0]];
171 [o_outline_view_other setTarget: self];
172 [o_outline_view_other setDelegate: self];
173 [o_outline_view_other setDataSource: self];
174 [o_outline_view_other setAllowsEmptySelection: NO];
176 [[o_tc_name_other headerCell] setStringValue:_NS("Name")];
177 [[o_tc_author_other headerCell] setStringValue:_NS("Author")];
178 [[o_tc_duration_other headerCell] setStringValue:_NS("Duration")];
180 NSArray * o_columnArray = [[NSUserDefaults standardUserDefaults] arrayForKey:@"PlaylistColumnSelection"];
181 NSUInteger count = [o_columnArray count];
183 id o_menu = [[VLCMain sharedInstance] mainMenu];
185 for (NSUInteger i = 0; i < count; i++)
187 o_column = [[o_columnArray objectAtIndex:i] objectAtIndex:0];
188 if ([o_column isEqualToString:@"status"])
191 [self setColumn: o_column state: NSOnState];
192 [o_menu setPlaylistColumnTableState: NSOnState forColumn: o_column];
193 [[o_outline_view tableColumnWithIdentifier: o_column] setWidth: [[[o_columnArray objectAtIndex:i] objectAtIndex:1] floatValue]];
196 [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(applicationWillTerminate:) name: NSApplicationWillTerminateNotification object: nil];
199 - (void)applicationWillTerminate:(NSNotification *)notification
201 /* let's make sure we save the correct widths and positions, since this likely changed since the last time the user played with the column selection */
202 [self saveTableColumns];
205 - (void)setPlaylistRoot: (playlist_item_t *)root_item
207 p_current_root_item = root_item;
208 [o_outline_view reloadData];
209 [o_outline_view_other reloadData];
212 - (playlist_item_t *)currentPlaylistRoot
214 return p_current_root_item;
217 - (NSOutlineView *)outlineView
219 return o_outline_view;
222 - (playlist_item_t *)selectedPlaylistItem
224 return [[o_outline_view itemAtRow: [o_outline_view selectedRow]]
228 - (void)setColumn: (NSString *)o_column state: (NSInteger)i_state
230 NSTableColumn * o_work_tc;
232 if (i_state == NSOnState)
234 o_work_tc = [[NSTableColumn alloc] initWithIdentifier: o_column];
235 [o_work_tc setEditable: NO];
236 [[o_work_tc dataCell] setFont: [NSFont controlContentFontOfSize:11.]];
238 /* we cannot use a makro here, because gettext isn't clever enough for that */
239 if ([o_column isEqualToString: TRACKNUM_COLUMN])
241 [o_work_tc setMaxWidth: 20.];
242 [[o_work_tc headerCell] setStringValue: @"#"];
244 else if ([o_column isEqualToString: TITLE_COLUMN])
246 [[o_work_tc headerCell] setStringValue: _NS("Name")];
247 [o_work_tc setResizingMask: NSTableColumnAutoresizingMask | NSTableColumnUserResizingMask];
249 else if ([o_column isEqualToString: ARTIST_COLUMN])
250 [[o_work_tc headerCell] setStringValue: _NS("Author")];
251 else if ([o_column isEqualToString: DURATION_COLUMN])
252 [[o_work_tc headerCell] setStringValue: _NS("Duration")];
253 else if ([o_column isEqualToString: GENRE_COLUMN])
254 [[o_work_tc headerCell] setStringValue: _NS("Genre")];
255 else if ([o_column isEqualToString: ALBUM_COLUMN])
256 [[o_work_tc headerCell] setStringValue: _NS("Album")];
257 else if ([o_column isEqualToString: DESCRIPTION_COLUMN])
258 [[o_work_tc headerCell] setStringValue: _NS("Description")];
259 else if ([o_column isEqualToString: DATE_COLUMN])
260 [[o_work_tc headerCell] setStringValue: _NS("Date")];
261 else if ([o_column isEqualToString: LANGUAGE_COLUMN])
262 [[o_work_tc headerCell] setStringValue: _NS("Language")];
264 [o_outline_view addTableColumn: o_work_tc];
266 [o_outline_view reloadData];
267 [o_outline_view setNeedsDisplay: YES];
270 [o_outline_view removeTableColumn: [o_outline_view tableColumnWithIdentifier: o_column]];
272 [self saveTableColumns];
275 - (void)saveTableColumns
277 NSMutableArray * o_arrayToSave = [[NSMutableArray alloc] init];
278 NSArray * o_columns = [o_outline_view tableColumns];
279 NSUInteger count = [o_columns count];
280 NSTableColumn * o_currentColumn;
281 for (NSUInteger i = 0; i < count; i++)
283 o_currentColumn = [o_columns objectAtIndex: i];
284 [o_arrayToSave addObject: [NSArray arrayWithObjects: [o_currentColumn identifier], [NSNumber numberWithFloat: [o_currentColumn width]], nil]];
286 [[NSUserDefaults standardUserDefaults] setObject: o_arrayToSave forKey:@"PlaylistColumnSelection"];
287 [o_arrayToSave release];
292 @implementation VLCPlaylistCommon (NSOutlineViewDataSource)
293 /* return the number of children for Obj-C pointer item */ /* DONE */
294 - (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
297 playlist_item_t *p_item = NULL;
298 playlist_t * p_playlist = pl_Get( VLCIntf );
299 //assert( outlineView == o_outline_view );
304 p_item = p_current_root_item;
307 p_item = (playlist_item_t *)[item pointerValue];
310 i_return = p_item->i_children;
313 return i_return > 0 ? i_return : 0;
316 /* return the child at index for the Obj-C pointer item */ /* DONE */
317 - (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item
319 playlist_item_t *p_return = NULL, *p_item = NULL;
321 playlist_t * p_playlist = pl_Get( VLCIntf );
327 p_item = p_current_root_item;
331 p_item = (playlist_item_t *)[item pointerValue];
333 if( p_item && index < p_item->i_children && index >= 0 )
334 p_return = p_item->pp_children[index];
337 o_value = [o_outline_dict objectForKey:[NSString stringWithFormat: @"%p", p_return]];
341 /* FIXME: Why is there a warning if that happens all the time and seems
342 * to be normal? Add an assert and fix it.
343 * msg_Warn( VLCIntf, "playlist item misses pointer value, adding one" ); */
344 o_value = [[NSValue valueWithPointer: p_return] retain];
349 /* is the item expandable */
350 - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item
353 playlist_t *p_playlist = pl_Get( VLCIntf );
359 if( p_current_root_item )
361 i_return = p_current_root_item->i_children;
366 playlist_item_t *p_item = (playlist_item_t *)[item pointerValue];
368 i_return = p_item->i_children;
372 return (i_return >= 0);
375 /* retrieve the string values for the cells */
376 - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)o_tc byItem:(id)item
380 playlist_item_t *p_item;
382 /* For error handling */
383 static BOOL attempted_reload = NO;
385 if( item == nil || ![item isKindOfClass: [NSValue class]] )
387 /* Attempt to fix the error by asking for a data redisplay
388 * This might cause infinite loop, so add a small check */
389 if( !attempted_reload )
391 attempted_reload = YES;
392 [outlineView reloadData];
397 p_item = (playlist_item_t *)[item pointerValue];
398 if( !p_item || !p_item->p_input )
400 /* Attempt to fix the error by asking for a data redisplay
401 * This might cause infinite loop, so add a small check */
402 if( !attempted_reload )
404 attempted_reload = YES;
405 [outlineView reloadData];
410 attempted_reload = NO;
411 NSString * o_identifier = [o_tc identifier];
413 if( [o_identifier isEqualToString:TRACKNUM_COLUMN] )
415 psz_value = input_item_GetTrackNumber( p_item->p_input ); \
417 o_value = [NSString stringWithUTF8String: psz_value]; \
421 else if( [o_identifier isEqualToString:TITLE_COLUMN] )
423 /* sanity check to prevent the NSString class from crashing */
424 char *psz_title = input_item_GetTitleFbName( p_item->p_input );
427 o_value = [NSString stringWithUTF8String: psz_title];
431 else if( [o_identifier isEqualToString:ARTIST_COLUMN] )
433 psz_value = input_item_GetArtist( p_item->p_input ); \
435 o_value = [NSString stringWithUTF8String: psz_value]; \
439 else if( [o_identifier isEqualToString:@"duration"] )
441 char psz_duration[MSTRTIME_MAX_SIZE];
442 mtime_t dur = input_item_GetDuration( p_item->p_input );
445 secstotimestr( psz_duration, dur/1000000 );
446 o_value = [NSString stringWithUTF8String: psz_duration];
451 else if( [o_identifier isEqualToString:GENRE_COLUMN] )
453 psz_value = input_item_GetGenre( p_item->p_input ); \
455 o_value = [NSString stringWithUTF8String: psz_value]; \
459 else if( [o_identifier isEqualToString:ALBUM_COLUMN] )
461 psz_value = input_item_GetAlbum( p_item->p_input ); \
463 o_value = [NSString stringWithUTF8String: psz_value]; \
467 else if( [o_identifier isEqualToString:DESCRIPTION_COLUMN] )
469 psz_value = input_item_GetDescription( p_item->p_input ); \
471 o_value = [NSString stringWithUTF8String: psz_value]; \
475 else if( [o_identifier isEqualToString:DATE_COLUMN] )
477 psz_value = input_item_GetDate( p_item->p_input ); \
479 o_value = [NSString stringWithUTF8String: psz_value]; \
483 else if( [o_identifier isEqualToString:LANGUAGE_COLUMN] )
485 psz_value = input_item_GetLanguage( p_item->p_input ); \
487 o_value = [NSString stringWithUTF8String: psz_value]; \
491 else if( [o_identifier isEqualToString:@"status"] )
493 if( input_item_HasErrorWhenReading( p_item->p_input ) )
495 o_value = [[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode(kAlertCautionIcon)];
496 [o_value setSize: NSMakeSize(16,16)];
505 /*****************************************************************************
506 * VLCPlaylistWizard implementation
507 *****************************************************************************/
508 @implementation VLCPlaylistWizard
510 - (IBAction)reloadOutlineView
512 /* Only reload the outlineview if the wizard window is open since this can
513 be quite long on big playlists */
514 if( [[o_outline_view window] isVisible] )
516 [o_outline_view reloadData];
522 /*****************************************************************************
523 * extension to NSOutlineView's interface to fix compilation warnings
524 * and let us access these 2 functions properly
525 * this uses a private Apple-API, but works fine on all current OSX releases
526 * keep checking for compatiblity with future releases though
527 *****************************************************************************/
529 @interface NSOutlineView (UndocumentedSortImages)
530 + (NSImage *)_defaultTableHeaderSortImage;
531 + (NSImage *)_defaultTableHeaderReverseSortImage;
535 /*****************************************************************************
536 * VLCPlaylist implementation
537 *****************************************************************************/
538 @implementation VLCPlaylist
545 o_nodes_array = [[NSMutableArray alloc] init];
546 o_items_array = [[NSMutableArray alloc] init];
553 [o_nodes_array release];
554 [o_items_array release];
560 playlist_t * p_playlist = pl_Get( VLCIntf );
564 [super awakeFromNib];
566 [o_outline_view setDoubleAction: @selector(playItem:)];
567 [o_outline_view_other setDoubleAction: @selector(playItem:)];
569 [o_outline_view registerForDraggedTypes:
570 [NSArray arrayWithObjects: NSFilenamesPboardType,
571 @"VLCPlaylistItemPboardType", nil]];
572 [o_outline_view setIntercellSpacing: NSMakeSize (0.0, 1.0)];
574 [o_outline_view_other registerForDraggedTypes:
575 [NSArray arrayWithObjects: NSFilenamesPboardType,
576 @"VLCPlaylistItemPboardType", nil]];
577 [o_outline_view_other setIntercellSpacing: NSMakeSize (0.0, 1.0)];
579 /* This uses private Apple API which works fine until 10.5.
580 * We need to keep checking in the future!
581 * These methods are being added artificially to NSOutlineView's interface above */
582 o_ascendingSortingImage = [[NSOutlineView class] _defaultTableHeaderSortImage];
583 o_descendingSortingImage = [[NSOutlineView class] _defaultTableHeaderReverseSortImage];
585 o_tc_sortColumn = nil;
588 - (void)searchfieldChanged:(NSNotification *)o_notification
590 [o_search_field setStringValue:[[o_notification object] stringValue]];
595 [o_mi_save_playlist setTitle: _NS("Save Playlist...")];
596 [o_mi_play setTitle: _NS("Play")];
597 [o_mi_delete setTitle: _NS("Delete")];
598 [o_mi_recursive_expand setTitle: _NS("Expand Node")];
599 [o_mi_selectall setTitle: _NS("Select All")];
600 [o_mi_info setTitle: _NS("Media Information...")];
601 [o_mi_dl_cover_art setTitle: _NS("Download Cover Art")];
602 [o_mi_preparse setTitle: _NS("Fetch Meta Data")];
603 [o_mi_revealInFinder setTitle: _NS("Reveal in Finder")];
604 [o_mm_mi_revealInFinder setTitle: _NS("Reveal in Finder")];
605 [[o_mm_mi_revealInFinder menu] setAutoenablesItems: NO];
606 [o_mi_sort_name setTitle: _NS("Sort Node by Name")];
607 [o_mi_sort_author setTitle: _NS("Sort Node by Author")];
609 [o_search_field setToolTip: _NS("Search in Playlist")];
610 [o_search_field_other setToolTip: _NS("Search in Playlist")];
612 [o_save_accessory_text setStringValue: _NS("File Format:")];
613 [[o_save_accessory_popup itemAtIndex:0] setTitle: _NS("Extended M3U")];
614 [[o_save_accessory_popup itemAtIndex:1] setTitle: _NS("XML Shareable Playlist Format (XSPF)")];
615 [[o_save_accessory_popup itemAtIndex:2] setTitle: _NS("HTML Playlist")];
618 - (void)playlistUpdated
620 /* Clear indications of any existing column sorting */
621 NSUInteger count = [[o_outline_view tableColumns] count];
622 for( NSUInteger i = 0 ; i < count ; i++ )
624 [o_outline_view setIndicatorImage:nil inTableColumn:
625 [[o_outline_view tableColumns] objectAtIndex:i]];
628 [o_outline_view setHighlightedTableColumn:nil];
629 o_tc_sortColumn = nil;
630 // TODO Find a way to keep the dict size to a minimum
631 //[o_outline_dict removeAllObjects];
632 [o_outline_view reloadData];
633 [[[[VLCMain sharedInstance] wizard] playlistWizard] reloadOutlineView];
634 [[[[VLCMain sharedInstance] bookmarks] dataTable] reloadData];
636 [self outlineViewSelectionDidChange: nil];
637 [[VLCMain sharedInstance] updateMainWindow];
640 - (void)outlineViewSelectionDidChange:(NSNotification *)notification
643 playlist_item_t * p_item = [[o_outline_view itemAtRow:[o_outline_view selectedRow]] pointerValue];
647 /* update the state of our Reveal-in-Finder menu items */
648 NSMutableString *o_mrl;
649 char *psz_uri = input_item_GetURI( p_item->p_input );
651 [o_mi_revealInFinder setEnabled: NO];
652 [o_mm_mi_revealInFinder setEnabled: NO];
655 o_mrl = [NSMutableString stringWithUTF8String: psz_uri];
657 /* perform some checks whether it is a file and if it is local at all... */
658 NSRange prefix_range = [o_mrl rangeOfString: @"file:"];
659 if( prefix_range.location != NSNotFound )
660 [o_mrl deleteCharactersInRange: prefix_range];
662 if( [o_mrl characterAtIndex:0] == '/' )
664 [o_mi_revealInFinder setEnabled: YES];
665 [o_mm_mi_revealInFinder setEnabled: YES];
670 /* update our info-panel to reflect the new item */
671 [[[VLCMain sharedInstance] info] updatePanelWithItem:p_item->p_input];
675 - (BOOL)isSelectionEmpty
677 return [o_outline_view selectedRow] == -1;
680 - (void)updateRowSelection
683 playlist_t *p_playlist = pl_Get( VLCIntf );
684 playlist_item_t *p_item, *p_temp_item;
685 NSMutableArray *o_array = [NSMutableArray array];
688 p_item = playlist_CurrentPlayingItem( p_playlist );
695 p_temp_item = p_item;
696 while( p_temp_item->p_parent )
698 [o_array insertObject: [NSValue valueWithPointer: p_temp_item] atIndex: 0];
699 p_temp_item = p_temp_item->p_parent;
703 NSUInteger count = [o_array count];
704 for( NSUInteger j = 0; j < count - 1; j++ )
707 if( ( o_item = [o_outline_dict objectForKey:
708 [NSString stringWithFormat: @"%p",
709 [[o_array objectAtIndex:j] pointerValue]]] ) != nil )
711 [o_outline_view expandItem: o_item];
715 id o_item = [o_outline_dict objectForKey:[NSString stringWithFormat: @"%p", p_item]];
716 NSInteger i_index = [o_outline_view rowForItem:o_item];
717 [o_outline_view selectRowIndexes:[NSIndexSet indexSetWithIndex:i_index] byExtendingSelection:NO];
718 [o_outline_view setNeedsDisplay:YES];
721 /* Check if p_item is a child of p_node recursively. We need to check the item
722 existence first since OSX sometimes tries to redraw items that have been
723 deleted. We don't do it when not required since this verification takes
724 quite a long time on big playlists (yes, pretty hacky). */
726 - (BOOL)isItem: (playlist_item_t *)p_item
727 inNode: (playlist_item_t *)p_node
728 checkItemExistence:(BOOL)b_check
729 locked:(BOOL)b_locked
732 playlist_t * p_playlist = pl_Get( VLCIntf );
733 playlist_item_t *p_temp_item = p_item;
735 if( p_node == p_item )
738 if( p_node->i_children < 1)
744 if(!b_locked) PL_LOCK;
748 /* Since outlineView: willDisplayCell:... may call this function with
749 p_items that don't exist anymore, first check if the item is still
750 in the playlist. Any cleaner solution welcomed. */
751 for( i = 0; i < p_playlist->all_items.i_size; i++ )
753 if( ARRAY_VAL( p_playlist->all_items, i) == p_item ) break;
754 else if ( i == p_playlist->all_items.i_size - 1 )
756 if(!b_locked) PL_UNLOCK;
764 p_temp_item = p_temp_item->p_parent;
765 if( p_temp_item == p_node )
767 if(!b_locked) PL_UNLOCK;
771 if(!b_locked) PL_UNLOCK;
776 - (BOOL)isItem: (playlist_item_t *)p_item
777 inNode: (playlist_item_t *)p_node
778 checkItemExistence:(BOOL)b_check
780 return [self isItem:p_item inNode:p_node checkItemExistence:b_check locked:NO];
783 /* This method is useful for instance to remove the selected children of an
784 already selected node */
785 - (void)removeItemsFrom:(id)o_items ifChildrenOf:(id)o_nodes
787 NSUInteger itemCount = [o_items count];
788 NSUInteger nodeCount = [o_nodes count];
789 for( NSUInteger i = 0 ; i < itemCount ; i++ )
791 for ( NSUInteger j = 0 ; j < nodeCount ; j++ )
793 if( o_items == o_nodes)
795 if( j == i ) continue;
797 if( [self isItem: [[o_items objectAtIndex:i] pointerValue]
798 inNode: [[o_nodes objectAtIndex:j] pointerValue]
799 checkItemExistence: NO locked:NO] )
801 [o_items removeObjectAtIndex:i];
802 /* We need to execute the next iteration with the same index
803 since the current item has been deleted */
811 - (IBAction)savePlaylist:(id)sender
813 playlist_t * p_playlist = pl_Get( VLCIntf );
815 NSSavePanel *o_save_panel = [NSSavePanel savePanel];
816 NSString * o_name = [NSString stringWithFormat: @"%@", _NS("Untitled")];
818 [o_save_panel setTitle: _NS("Save Playlist")];
819 [o_save_panel setPrompt: _NS("Save")];
820 [o_save_panel setAccessoryView: o_save_accessory_view];
822 if( [o_save_panel runModalForDirectory: nil
823 file: o_name] == NSOKButton )
825 NSString *o_filename = [[o_save_panel URL] path];
827 if( [o_save_accessory_popup indexOfSelectedItem] == 0 )
829 NSString * o_real_filename;
831 range.location = [o_filename length] - [@".m3u" length];
832 range.length = [@".m3u" length];
834 if( [o_filename compare:@".m3u" options: NSCaseInsensitiveSearch
835 range: range] != NSOrderedSame )
837 o_real_filename = [NSString stringWithFormat: @"%@.m3u", o_filename];
841 o_real_filename = o_filename;
843 playlist_Export( p_playlist,
844 [o_real_filename fileSystemRepresentation],
845 p_playlist->p_local_category, "export-m3u" );
847 else if( [o_save_accessory_popup indexOfSelectedItem] == 1 )
849 NSString * o_real_filename;
851 range.location = [o_filename length] - [@".xspf" length];
852 range.length = [@".xspf" length];
854 if( [o_filename compare:@".xspf" options: NSCaseInsensitiveSearch
855 range: range] != NSOrderedSame )
857 o_real_filename = [NSString stringWithFormat: @"%@.xspf", o_filename];
861 o_real_filename = o_filename;
863 playlist_Export( p_playlist,
864 [o_real_filename fileSystemRepresentation],
865 p_playlist->p_local_category, "export-xspf" );
869 NSString * o_real_filename;
871 range.location = [o_filename length] - [@".html" length];
872 range.length = [@".html" length];
874 if( [o_filename compare:@".html" options: NSCaseInsensitiveSearch
875 range: range] != NSOrderedSame )
877 o_real_filename = [NSString stringWithFormat: @"%@.html", o_filename];
881 o_real_filename = o_filename;
883 playlist_Export( p_playlist,
884 [o_real_filename fileSystemRepresentation],
885 p_playlist->p_local_category, "export-html" );
890 /* When called retrieves the selected outlineview row and plays that node or item */
891 - (IBAction)playItem:(id)sender
893 intf_thread_t * p_intf = VLCIntf;
894 playlist_t * p_playlist = pl_Get( p_intf );
896 playlist_item_t *p_item;
897 playlist_item_t *p_node = NULL;
899 // ignore clicks on column header when handling double action
900 if( sender != nil && [o_outline_view clickedRow] == -1 )
903 p_item = [[o_outline_view itemAtRow:[o_outline_view selectedRow]] pointerValue];
908 if( p_item->i_children == -1 )
910 p_node = p_item->p_parent;
915 if( p_node->i_children > 0 && p_node->pp_children[0]->i_children == -1 )
917 p_item = p_node->pp_children[0];
924 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, pl_Locked, p_node, p_item );
929 - (IBAction)revealItemInFinder:(id)sender
931 playlist_item_t * p_item = [[o_outline_view itemAtRow:[o_outline_view selectedRow]] pointerValue];
932 NSMutableString * o_mrl = nil;
934 if(! p_item || !p_item->p_input )
937 char *psz_uri = decode_URI( input_item_GetURI( p_item->p_input ) );
939 o_mrl = [NSMutableString stringWithUTF8String: psz_uri];
941 /* perform some checks whether it is a file and if it is local at all... */
942 NSRange prefix_range = [o_mrl rangeOfString: @"file:"];
943 if( prefix_range.location != NSNotFound )
944 [o_mrl deleteCharactersInRange: prefix_range];
946 if( [o_mrl characterAtIndex:0] == '/' )
947 [[NSWorkspace sharedWorkspace] selectFile: o_mrl inFileViewerRootedAtPath: o_mrl];
950 /* When called retrieves the selected outlineview row and plays that node or item */
951 - (IBAction)preparseItem:(id)sender
954 NSIndexSet *o_selected_indexes;
955 intf_thread_t * p_intf = VLCIntf;
956 playlist_t * p_playlist = pl_Get( p_intf );
957 playlist_item_t *p_item = NULL;
959 o_selected_indexes = [o_outline_view selectedRowIndexes];
960 i_count = [o_selected_indexes count];
962 NSUInteger indexes[i_count];
963 [o_selected_indexes getIndexes:indexes maxCount:i_count inIndexRange:nil];
964 for (int i = 0; i < i_count; i++)
966 p_item = [[o_outline_view itemAtRow:indexes[i]] pointerValue];
967 [o_outline_view deselectRow: indexes[i]];
971 if( p_item->i_children == -1 )
972 playlist_PreparseEnqueue( p_playlist, p_item->p_input );
974 msg_Dbg( p_intf, "preparsing nodes not implemented" );
977 [self playlistUpdated];
980 - (IBAction)downloadCoverArt:(id)sender
983 NSIndexSet *o_selected_indexes;
984 intf_thread_t * p_intf = VLCIntf;
985 playlist_t * p_playlist = pl_Get( p_intf );
986 playlist_item_t *p_item = NULL;
988 o_selected_indexes = [o_outline_view selectedRowIndexes];
989 i_count = [o_selected_indexes count];
991 NSUInteger indexes[i_count];
992 [o_selected_indexes getIndexes:indexes maxCount:i_count inIndexRange:nil];
993 for (int i = 0; i < i_count; i++)
995 p_item = [[o_outline_view itemAtRow: indexes[i]] pointerValue];
996 [o_outline_view deselectRow: indexes[i]];
998 if( p_item && p_item->i_children == -1 )
999 playlist_AskForArtEnqueue( p_playlist, p_item->p_input );
1001 [self playlistUpdated];
1004 - (IBAction)selectAll:(id)sender
1006 [o_outline_view selectAll: nil];
1009 - (IBAction)deleteItem:(id)sender
1012 NSIndexSet *o_selected_indexes;
1013 playlist_t * p_playlist;
1014 intf_thread_t * p_intf = VLCIntf;
1016 o_selected_indexes = [o_outline_view selectedRowIndexes];
1017 i_count = [o_selected_indexes count];
1019 p_playlist = pl_Get( p_intf );
1021 NSUInteger indexes[i_count];
1022 if (i_count == [o_outline_view numberOfRows])
1025 msg_Dbg( p_intf, "user selected entire list, deleting current playlist root instead of individual items" );
1028 playlist_NodeDelete( p_playlist, [self currentPlaylistRoot], true, false );
1030 [self playlistUpdated];
1033 [o_selected_indexes getIndexes:indexes maxCount:i_count inIndexRange:nil];
1034 for (int i = 0; i < i_count; i++)
1036 id o_item = [o_outline_view itemAtRow: indexes[i]];
1037 [o_outline_view deselectRow: indexes[i]];
1040 playlist_item_t *p_item = [o_item pointerValue];
1042 msg_Dbg( p_intf, "deleting item %i (of %i) with id \"%i\", pointerValue \"%p\" and %i children", i+1, i_count,
1043 p_item->p_input->i_id, [o_item pointerValue], p_item->i_children +1 );
1046 if( p_item->i_children != -1 )
1047 //is a node and not an item
1049 if( playlist_Status( p_playlist ) != PLAYLIST_STOPPED &&
1050 [self isItem: playlist_CurrentPlayingItem( p_playlist ) inNode: ((playlist_item_t *)[o_item pointerValue])
1051 checkItemExistence: NO locked:YES] == YES )
1052 // if current item is in selected node and is playing then stop playlist
1053 playlist_Control(p_playlist, PLAYLIST_STOP, pl_Locked );
1055 playlist_NodeDelete( p_playlist, p_item, true, false );
1058 playlist_DeleteFromInput( p_playlist, p_item->p_input, pl_Locked );
1061 [o_outline_dict removeObjectForKey:[NSString stringWithFormat:@"%p", [o_item pointerValue]]];
1065 [self playlistUpdated];
1068 - (IBAction)sortNodeByName:(id)sender
1070 [self sortNode: SORT_TITLE];
1073 - (IBAction)sortNodeByAuthor:(id)sender
1075 [self sortNode: SORT_ARTIST];
1078 - (void)sortNode:(int)i_mode
1080 playlist_t * p_playlist = pl_Get( VLCIntf );
1081 playlist_item_t * p_item;
1083 if( [o_outline_view selectedRow] > -1 )
1085 p_item = [[o_outline_view itemAtRow: [o_outline_view selectedRow]] pointerValue];
1088 /*If no item is selected, sort the whole playlist*/
1090 p_item = [self currentPlaylistRoot];
1094 if( p_item->i_children > -1 ) // the item is a node
1096 playlist_RecursiveNodeSort( p_playlist, p_item, i_mode, ORDER_NORMAL );
1100 playlist_RecursiveNodeSort( p_playlist,
1101 p_item->p_parent, i_mode, ORDER_NORMAL );
1104 [self playlistUpdated];
1107 - (input_item_t *)createItem:(NSDictionary *)o_one_item
1109 intf_thread_t * p_intf = VLCIntf;
1110 playlist_t * p_playlist = pl_Get( p_intf );
1112 input_item_t *p_input;
1113 BOOL b_rem = FALSE, b_dir = FALSE, b_writable = FALSE;
1114 NSString *o_uri, *o_name, *o_path;
1120 o_uri = (NSString *)[o_one_item objectForKey: @"ITEM_URL"];
1121 o_nsurl = [NSURL URLWithString: o_uri];
1122 o_path = [o_nsurl path];
1123 o_name = (NSString *)[o_one_item objectForKey: @"ITEM_NAME"];
1124 o_options = (NSArray *)[o_one_item objectForKey: @"ITEM_OPTIONS"];
1126 if( [[NSFileManager defaultManager] fileExistsAtPath:o_path isDirectory:&b_dir] && b_dir &&
1127 [[NSWorkspace sharedWorkspace] getFileSystemInfoForPath:o_path isRemovable: &b_rem
1128 isWritable:&b_writable isUnmountable:NULL description:NULL type:NULL] && b_rem && !b_writable && [o_nsurl isFileURL] )
1131 id o_vlc_open = [[VLCMain sharedInstance] open];
1133 char *diskType = [o_vlc_open getVolumeTypeFromMountPath: o_path];
1134 msg_Dbg( p_intf, "detected optical media of type '%s' in the file input", diskType );
1136 if (diskType == kVLCMediaDVD)
1138 o_uri = [NSString stringWithFormat: @"dvdnav://%@", [o_vlc_open getBSDNodeFromMountPath: o_path]];
1140 else if (diskType == kVLCMediaVideoTSFolder)
1142 o_uri = [NSString stringWithFormat: @"dvdnav://%@", o_path];
1144 else if (diskType == kVLCMediaAudioCD)
1146 o_uri = [NSString stringWithFormat: @"cdda://%@", [o_vlc_open getBSDNodeFromMountPath: o_path]];
1148 else if (diskType == kVLCMediaVCD)
1150 o_uri = [NSString stringWithFormat: @"vcd://%@#0:0", [o_vlc_open getBSDNodeFromMountPath: o_path]];
1152 else if (diskType == kVLCMediaSVCD)
1154 o_uri = [NSString stringWithFormat: @"vcd://%@@0:0", [o_vlc_open getBSDNodeFromMountPath: o_path]];
1156 else if (diskType == kVLCMediaBD || diskType == kVLCMediaBDMVFolder)
1158 o_uri = [NSString stringWithFormat: @"bluray://%@", o_path];
1162 msg_Warn( VLCIntf, "unknown disk type, treating %s as regular input", [o_path UTF8String] );
1165 p_input = input_item_New( [o_uri UTF8String], [[[NSFileManager defaultManager] displayNameAtPath: o_path] UTF8String] );
1168 p_input = input_item_New( [o_uri fileSystemRepresentation], o_name ? [o_name UTF8String] : NULL );
1175 NSUInteger count = [o_options count];
1176 for( NSUInteger i = 0; i < count; i++ )
1178 input_item_AddOption( p_input, [[o_options objectAtIndex:i] UTF8String],
1179 VLC_INPUT_OPTION_TRUSTED );
1183 /* Recent documents menu */
1184 if( o_nsurl != nil && (BOOL)config_GetInt( p_playlist, "macosx-recentitems" ) == YES )
1186 [[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL: o_nsurl];
1191 - (void)appendArray:(NSArray*)o_array atPos:(int)i_position enqueue:(BOOL)b_enqueue
1193 playlist_t * p_playlist = pl_Get( VLCIntf );
1194 NSUInteger count = [o_array count];
1195 BOOL b_usingPlaylist;
1196 if ([self currentPlaylistRoot] == p_playlist->p_ml_category)
1197 b_usingPlaylist = NO;
1199 b_usingPlaylist = YES;
1202 for( NSUInteger i_item = 0; i_item < count; i_item++ )
1204 input_item_t *p_input;
1205 NSDictionary *o_one_item;
1208 o_one_item = [o_array objectAtIndex: i_item];
1209 p_input = [self createItem: o_one_item];
1216 /* FIXME: playlist_AddInput() can fail */
1218 playlist_AddInput( p_playlist, p_input, PLAYLIST_INSERT, i_position == -1 ? PLAYLIST_END : i_position + i_item, b_usingPlaylist,
1221 if( i_item == 0 && !b_enqueue )
1223 playlist_item_t *p_item = playlist_ItemGetByInput( p_playlist, p_input );
1224 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, pl_Locked, p_item->p_parent, p_item );
1227 vlc_gc_decref( p_input );
1230 [self playlistUpdated];
1233 - (void)appendNodeArray:(NSArray*)o_array inNode:(playlist_item_t *)p_node atPos:(int)i_position enqueue:(BOOL)b_enqueue
1235 playlist_t * p_playlist = pl_Get( VLCIntf );
1236 NSUInteger count = [o_array count];
1238 for( NSUInteger i_item = 0; i_item < count; i_item++ )
1240 input_item_t *p_input;
1241 NSDictionary *o_one_item;
1244 o_one_item = [o_array objectAtIndex: i_item];
1245 p_input = [self createItem: o_one_item];
1247 if( !p_input ) continue;
1251 playlist_NodeAddInput( p_playlist, p_input, p_node,
1254 PLAYLIST_END : i_position + i_item,
1258 if( i_item == 0 && !b_enqueue )
1260 playlist_item_t *p_item;
1261 p_item = playlist_ItemGetByInput( p_playlist, p_input );
1262 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, pl_Locked, p_node, p_item );
1265 vlc_gc_decref( p_input );
1267 [self playlistUpdated];
1270 - (NSMutableArray *)subSearchItem:(playlist_item_t *)p_item
1272 playlist_t *p_playlist = pl_Get( VLCIntf );
1273 playlist_item_t *p_selected_item;
1276 i_selected_row = [o_outline_view selectedRow];
1277 if (i_selected_row < 0)
1280 p_selected_item = (playlist_item_t *)[[o_outline_view itemAtRow: i_selected_row] pointerValue];
1282 for( NSUInteger i_current = 0; i_current < p_item->i_children ; i_current++ )
1285 NSString *o_current_name, *o_current_author;
1288 o_current_name = [NSString stringWithUTF8String:
1289 p_item->pp_children[i_current]->p_input->psz_name];
1290 psz_temp = input_item_GetInfo( p_item->p_input ,
1291 _("Meta-information"),_("Artist") );
1292 o_current_author = [NSString stringWithUTF8String: psz_temp];
1296 if( p_selected_item == p_item->pp_children[i_current] &&
1297 b_selected_item_met == NO )
1299 b_selected_item_met = YES;
1301 else if( p_selected_item == p_item->pp_children[i_current] &&
1302 b_selected_item_met == YES )
1306 else if( b_selected_item_met == YES &&
1307 ( [o_current_name rangeOfString:[o_search_field
1308 stringValue] options:NSCaseInsensitiveSearch].length ||
1309 [o_current_author rangeOfString:[o_search_field
1310 stringValue] options:NSCaseInsensitiveSearch].length ) )
1312 /*Adds the parent items in the result array as well, so that we can
1314 return [NSMutableArray arrayWithObject: [NSValue
1315 valueWithPointer: p_item->pp_children[i_current]]];
1317 if( p_item->pp_children[i_current]->i_children > 0 )
1319 id o_result = [self subSearchItem:
1320 p_item->pp_children[i_current]];
1321 if( o_result != NULL )
1323 [o_result insertObject: [NSValue valueWithPointer:
1324 p_item->pp_children[i_current]] atIndex:0];
1332 - (IBAction)searchItem:(id)sender
1334 playlist_t * p_playlist = pl_Get( VLCIntf );
1339 b_selected_item_met = NO;
1341 /*First, only search after the selected item:*
1342 *(b_selected_item_met = NO) */
1343 o_result = [self subSearchItem:[self currentPlaylistRoot]];
1344 if( o_result == NULL )
1346 /* If the first search failed, search again from the beginning */
1347 o_result = [self subSearchItem:[self currentPlaylistRoot]];
1349 if( o_result != NULL )
1352 if( [[o_result objectAtIndex: 0] pointerValue] == p_playlist->p_local_category )
1356 NSUInteger count = [o_result count];
1358 for( NSUInteger i = i_start ; i < count - 1 ; i++ )
1360 [o_outline_view expandItem: [o_outline_dict objectForKey:
1361 [NSString stringWithFormat: @"%p",
1362 [[o_result objectAtIndex: i] pointerValue]]]];
1364 i_row = [o_outline_view rowForItem: [o_outline_dict objectForKey:
1365 [NSString stringWithFormat: @"%p",
1366 [[o_result objectAtIndex: count - 1 ]
1371 [o_outline_view selectRowIndexes:[NSIndexSet indexSetWithIndex:i_row] byExtendingSelection:NO];
1372 [o_outline_view scrollRowToVisible: i_row];
1376 - (IBAction)recursiveExpandNode:(id)sender
1378 id o_item = [o_outline_view itemAtRow: [o_outline_view selectedRow]];
1379 playlist_item_t *p_item = (playlist_item_t *)[o_item pointerValue];
1381 if( ![[o_outline_view dataSource] outlineView: o_outline_view isItemExpandable: o_item] )
1383 o_item = [o_outline_dict objectForKey: [NSString stringWithFormat: @"%p", p_item->p_parent]];
1386 /* We need to collapse the node first, since OSX refuses to recursively
1387 expand an already expanded node, even if children nodes are collapsed. */
1388 [o_outline_view collapseItem: o_item collapseChildren: YES];
1389 [o_outline_view expandItem: o_item expandChildren: YES];
1392 - (NSMenu *)menuForEvent:(NSEvent *)o_event
1398 pt = [o_outline_view convertPoint: [o_event locationInWindow] fromView: nil];
1399 int row = [o_outline_view rowAtPoint:pt];
1400 if( row != -1 && [o_outline_view selectedRow] == -1)
1401 [o_outline_view selectRowIndexes:[NSIndexSet indexSetWithIndex:row] byExtendingSelection:NO];
1403 b_item_sel = ( row != -1 && [o_outline_view selectedRow] != -1 );
1404 b_rows = [o_outline_view numberOfRows] != 0;
1406 [o_mi_play setEnabled: b_item_sel];
1407 [o_mi_delete setEnabled: b_item_sel];
1408 [o_mi_selectall setEnabled: b_rows];
1409 [o_mi_info setEnabled: b_item_sel];
1410 [o_mi_preparse setEnabled: b_item_sel];
1411 [o_mi_recursive_expand setEnabled: b_item_sel];
1412 [o_mi_sort_name setEnabled: b_item_sel];
1413 [o_mi_sort_author setEnabled: b_item_sel];
1415 return( o_ctx_menu );
1418 - (void)outlineView: (NSOutlineView *)o_tv didClickTableColumn:(NSTableColumn *)o_tc
1420 int i_mode, i_type = 0;
1421 intf_thread_t *p_intf = VLCIntf;
1422 NSString * o_identifier = [o_tc identifier];
1424 playlist_t *p_playlist = pl_Get( p_intf );
1426 if( [o_identifier isEqualToString:TRACKNUM_COLUMN] )
1427 i_mode = SORT_TRACK_NUMBER;
1428 else if( [o_identifier isEqualToString:TITLE_COLUMN] )
1429 i_mode = SORT_TITLE;
1430 else if( [o_identifier isEqualToString:ARTIST_COLUMN] )
1431 i_mode = SORT_ARTIST;
1432 else if( [o_identifier isEqualToString:GENRE_COLUMN] )
1433 i_mode = SORT_GENRE;
1434 else if( [o_identifier isEqualToString:DURATION_COLUMN] )
1435 i_mode = SORT_DURATION;
1436 else if( [o_identifier isEqualToString:ALBUM_COLUMN] )
1437 i_mode = SORT_ALBUM;
1438 else if( [o_identifier isEqualToString:DESCRIPTION_COLUMN] )
1439 i_mode = SORT_DESCRIPTION;
1443 if( o_tc_sortColumn == o_tc )
1444 b_isSortDescending = !b_isSortDescending;
1446 b_isSortDescending = false;
1448 if( b_isSortDescending )
1449 i_type = ORDER_REVERSE;
1451 i_type = ORDER_NORMAL;
1454 playlist_RecursiveNodeSort( p_playlist, [self currentPlaylistRoot], i_mode, i_type );
1457 [self playlistUpdated];
1459 o_tc_sortColumn = o_tc;
1460 [o_outline_view setHighlightedTableColumn:o_tc];
1462 if( b_isSortDescending )
1463 [o_outline_view setIndicatorImage:o_descendingSortingImage inTableColumn:o_tc];
1465 [o_outline_view setIndicatorImage:o_ascendingSortingImage inTableColumn:o_tc];
1469 - (void)outlineView:(NSOutlineView *)outlineView
1470 willDisplayCell:(id)cell
1471 forTableColumn:(NSTableColumn *)tableColumn
1474 /* this method can be called when VLC is already dead, hence the extra checks */
1475 intf_thread_t * p_intf = VLCIntf;
1478 playlist_t *p_playlist = pl_Get( p_intf );
1485 o_playing_item = [o_outline_dict objectForKey: [NSString stringWithFormat:@"%p", playlist_CurrentPlayingItem( p_playlist )]];
1488 if( [self isItem: [o_playing_item pointerValue] inNode:
1489 [item pointerValue] checkItemExistence: YES]
1490 || [o_playing_item isEqual: item] )
1492 [cell setFont: [[NSFontManager sharedFontManager] convertFont:[cell font] toHaveTrait:NSBoldFontMask]];
1496 [cell setFont: [[NSFontManager sharedFontManager] convertFont:[cell font] toNotHaveTrait:NSBoldFontMask]];
1502 playlist_t *p_playlist = pl_Get( VLCIntf );
1507 o_playing_item = [o_outline_dict objectForKey: [NSString stringWithFormat:@"%p", playlist_CurrentPlayingItem( p_playlist )]];
1510 return o_playing_item;
1513 - (NSArray *)draggedItems
1515 return [[o_nodes_array arrayByAddingObjectsFromArray: o_items_array] retain];
1519 @implementation VLCPlaylist (NSOutlineViewDataSource)
1521 - (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item
1523 id o_value = [super outlineView: outlineView child: index ofItem: item];
1525 [o_outline_dict setObject:o_value forKey:[NSString stringWithFormat:@"%p", [o_value pointerValue]]];
1529 /* Required for drag & drop and reordering */
1530 - (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pboard
1532 playlist_t *p_playlist = pl_Get( VLCIntf );
1534 /* First remove the items that were moved during the last drag & drop
1536 [o_items_array removeAllObjects];
1537 [o_nodes_array removeAllObjects];
1539 NSUInteger itemCount = [items count];
1541 for( NSUInteger i = 0 ; i < itemCount ; i++ )
1543 id o_item = [items objectAtIndex: i];
1545 /* Fill the items and nodes to move in 2 different arrays */
1546 if( ((playlist_item_t *)[o_item pointerValue])->i_children > 0 )
1547 [o_nodes_array addObject: o_item];
1549 [o_items_array addObject: o_item];
1552 /* Now we need to check if there are selected items that are in already
1553 selected nodes. In that case, we only want to move the nodes */
1554 [self removeItemsFrom: o_nodes_array ifChildrenOf: o_nodes_array];
1555 [self removeItemsFrom: o_items_array ifChildrenOf: o_nodes_array];
1557 /* We add the "VLCPlaylistItemPboardType" type to be able to recognize
1558 a Drop operation coming from the playlist. */
1560 [pboard declareTypes: [NSArray arrayWithObjects:
1561 @"VLCPlaylistItemPboardType", nil] owner: self];
1562 [pboard setData:[NSData data] forType:@"VLCPlaylistItemPboardType"];
1567 - (NSDragOperation)outlineView:(NSOutlineView *)outlineView validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(NSInteger)index
1569 playlist_t *p_playlist = pl_Get( VLCIntf );
1570 NSPasteboard *o_pasteboard = [info draggingPasteboard];
1572 if( !p_playlist ) return NSDragOperationNone;
1574 /* Dropping ON items is not allowed if item is not a node */
1577 if( index == NSOutlineViewDropOnItemIndex &&
1578 ((playlist_item_t *)[item pointerValue])->i_children == -1 )
1580 return NSDragOperationNone;
1584 /* We refuse to drop an item in anything else than a child of the General
1585 Node. We still accept items that would be root nodes of the outlineview
1586 however, to allow drop in an empty playlist. */
1587 if( !( ([self isItem: [item pointerValue] inNode: p_playlist->p_local_category checkItemExistence: NO] ||
1588 ( var_CreateGetBool( p_playlist, "media-library" ) && [self isItem: [item pointerValue] inNode: p_playlist->p_ml_category checkItemExistence: NO] ) ) || item == nil ) )
1590 return NSDragOperationNone;
1593 /* Drop from the Playlist */
1594 if( [[o_pasteboard types] containsObject: @"VLCPlaylistItemPboardType"] )
1596 NSUInteger count = [o_nodes_array count];
1597 for( NSUInteger i = 0 ; i < count ; i++ )
1599 /* We refuse to Drop in a child of an item we are moving */
1600 if( [self isItem: [item pointerValue] inNode:
1601 [[o_nodes_array objectAtIndex: i] pointerValue]
1602 checkItemExistence: NO] )
1604 return NSDragOperationNone;
1607 return NSDragOperationMove;
1610 /* Drop from the Finder */
1611 else if( [[o_pasteboard types] containsObject: NSFilenamesPboardType] )
1613 return NSDragOperationGeneric;
1615 return NSDragOperationNone;
1618 - (BOOL)outlineView:(NSOutlineView *)outlineView acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(NSInteger)index
1620 playlist_t * p_playlist = pl_Get( VLCIntf );
1621 NSPasteboard *o_pasteboard = [info draggingPasteboard];
1623 /* Drag & Drop inside the playlist */
1624 if( [[o_pasteboard types] containsObject: @"VLCPlaylistItemPboardType"] )
1626 int i_row, i_removed_from_node = 0;
1627 playlist_item_t *p_new_parent, *p_item = NULL;
1628 NSArray *o_all_items = [o_nodes_array arrayByAddingObjectsFromArray: o_items_array];
1629 /* If the item is to be dropped as root item of the outline, make it a
1630 child of the respective general node, if is either the pl or the ml
1631 Else, choose the proposed parent as parent. */
1634 if ([self currentPlaylistRoot] == p_playlist->p_local_category || [self currentPlaylistRoot] == p_playlist->p_ml_category)
1635 p_new_parent = [self currentPlaylistRoot];
1640 p_new_parent = [item pointerValue];
1642 /* Make sure the proposed parent is a node.
1643 (This should never be true) */
1644 if( p_new_parent->i_children < 0 )
1649 NSUInteger count = [o_all_items count];
1650 for( NSUInteger i = 0; i < count; i++ )
1652 playlist_item_t *p_old_parent = NULL;
1653 int i_old_index = 0;
1655 p_item = [[o_all_items objectAtIndex:i] pointerValue];
1656 p_old_parent = p_item->p_parent;
1659 /* We may need the old index later */
1660 if( p_new_parent == p_old_parent )
1662 for( NSInteger j = 0; j < p_old_parent->i_children; j++ )
1664 if( p_old_parent->pp_children[j] == p_item )
1673 // Actually detach the item from the old position
1674 if( playlist_NodeRemoveItem( p_playlist, p_item, p_old_parent ) ==
1678 /* Calculate the new index */
1681 /* If we move the item in the same node, we need to take into
1682 account that one item will be deleted */
1685 if ((p_new_parent == p_old_parent && i_old_index < index + (int)i) )
1687 i_removed_from_node++;
1689 i_new_index = index + i - i_removed_from_node;
1691 // Reattach the item to the new position
1692 playlist_NodeInsert( p_playlist, p_item, p_new_parent, i_new_index );
1696 [self playlistUpdated];
1697 i_row = [o_outline_view rowForItem:[o_outline_dict objectForKey:[NSString stringWithFormat: @"%p", [[o_all_items objectAtIndex: 0] pointerValue]]]];
1701 i_row = [o_outline_view rowForItem:[o_outline_dict objectForKey:[NSString stringWithFormat: @"%p", p_new_parent]]];
1704 [o_outline_view deselectAll: self];
1705 [o_outline_view selectRowIndexes:[NSIndexSet indexSetWithIndex:i_row] byExtendingSelection:NO];
1706 [o_outline_view scrollRowToVisible: i_row];
1711 else if( [[o_pasteboard types] containsObject: NSFilenamesPboardType] )
1713 if ([self currentPlaylistRoot] != p_playlist->p_local_category && [self currentPlaylistRoot] != p_playlist->p_ml_category)
1716 playlist_item_t *p_node = [item pointerValue];
1718 NSArray *o_values = [[o_pasteboard propertyListForType: NSFilenamesPboardType]
1719 sortedArrayUsingSelector: @selector(caseInsensitiveCompare:)];
1720 NSUInteger count = [o_values count];
1721 NSMutableArray *o_array = [NSMutableArray arrayWithCapacity:count];
1722 input_thread_t * p_input = pl_CurrentInput( VLCIntf );
1723 BOOL b_returned = NO;
1725 if (count == 1 && p_input)
1727 b_returned = input_AddSubtitle( p_input, make_URI([[o_values objectAtIndex:0] UTF8String], NULL), true );
1728 vlc_object_release( p_input );
1733 vlc_object_release( p_input );
1735 for( NSUInteger i = 0; i < count; i++)
1737 NSDictionary *o_dic;
1738 char *psz_uri = make_URI([[o_values objectAtIndex:i] UTF8String], NULL);
1742 o_dic = [NSDictionary dictionaryWithObject:[NSString stringWithCString:psz_uri encoding:NSUTF8StringEncoding] forKey:@"ITEM_URL"];
1746 [o_array addObject: o_dic];
1751 [self appendArray:o_array atPos:index enqueue: YES];
1755 assert( p_node->i_children != -1 );
1756 [self appendNodeArray:o_array inNode: p_node atPos:index enqueue:YES];