1 /*****************************************************************************
2 * playlist.m: MacOS X interface module
3 *****************************************************************************
4 * Copyright (C) 2002-2014 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>
42 #import "CompatibilityFixes.h"
47 #import "playlistinfo.h"
53 #import "CoreInteraction.h"
56 #import <vlc_interface.h>
59 /*****************************************************************************
60 * VLCPlaylistView implementation
61 *****************************************************************************/
62 @implementation VLCPlaylistView
64 - (NSMenu *)menuForEvent:(NSEvent *)o_event
66 return([(VLCPlaylist *)[self delegate] menuForEvent: o_event]);
69 - (void)keyDown:(NSEvent *)o_event
73 if ([[o_event characters] length])
74 key = [[o_event characters] characterAtIndex: 0];
77 case NSDeleteCharacter:
78 case NSDeleteFunctionKey:
79 case NSDeleteCharFunctionKey:
80 case NSBackspaceCharacter:
81 [(VLCPlaylist *)[self delegate] deleteItem:self];
84 case NSEnterCharacter:
85 case NSCarriageReturnCharacter:
86 [(VLCPlaylist *)[[VLCMain sharedInstance] playlist] playItem:nil];
90 [super keyDown: o_event];
95 - (BOOL)validateMenuItem:(NSMenuItem *)item
97 if (([self numberOfSelectedRows] >= 1 && [item action] == @selector(delete:)) || [item action] == @selector(selectAll:))
103 - (BOOL)acceptsFirstResponder
108 - (BOOL)becomeFirstResponder
110 [self setNeedsDisplay:YES];
114 - (BOOL)resignFirstResponder
116 [self setNeedsDisplay:YES];
120 - (IBAction)delete:(id)sender
122 [[[VLCMain sharedInstance] playlist] deleteItem: sender];
127 /*****************************************************************************
128 * VLCPlaylistCommon implementation
130 * This class the superclass of the VLCPlaylist and VLCPlaylistWizard.
131 * It contains the common methods and elements of these 2 entities.
132 *****************************************************************************/
133 @interface VLCPlaylistCommon ()
135 playlist_item_t * p_current_root_item;
139 @implementation VLCPlaylistCommon
143 playlist_t * p_playlist = pl_Get(VLCIntf);
144 p_current_root_item = p_playlist->p_local_category;
148 o_outline_dict = [[NSMutableDictionary alloc] init];
155 playlist_t * p_playlist = pl_Get(VLCIntf);
156 [o_outline_view setTarget: self];
157 [o_outline_view setDelegate: self];
158 [o_outline_view setDataSource: self];
159 [o_outline_view setAllowsEmptySelection: NO];
160 [o_outline_view expandItem: [o_outline_view itemAtRow:0]];
162 [o_outline_view_other setTarget: self];
163 [o_outline_view_other setDelegate: self];
164 [o_outline_view_other setDataSource: self];
165 [o_outline_view_other setAllowsEmptySelection: NO];
167 [[o_tc_name_other headerCell] setStringValue:_NS("Name")];
168 [[o_tc_author_other headerCell] setStringValue:_NS("Author")];
169 [[o_tc_duration_other headerCell] setStringValue:_NS("Duration")];
174 - (void)setPlaylistRoot: (playlist_item_t *)root_item
176 p_current_root_item = root_item;
177 [o_outline_view reloadData];
178 [o_outline_view_other reloadData];
181 - (playlist_item_t *)currentPlaylistRoot
183 return p_current_root_item;
186 - (NSOutlineView *)outlineView
188 return o_outline_view;
191 - (playlist_item_t *)selectedPlaylistItem
193 return [[o_outline_view itemAtRow: [o_outline_view selectedRow]]
201 if (config_GetInt(VLCIntf, "macosx-large-text")) {
202 fontToUse = [NSFont systemFontOfSize:13.];
205 fontToUse = [NSFont systemFontOfSize:11.];
209 NSArray *columns = [o_outline_view tableColumns];
210 NSUInteger count = columns.count;
211 for (NSUInteger x = 0; x < count; x++)
212 [[columns[x] dataCell] setFont:fontToUse];
213 [o_outline_view setRowHeight:rowHeight];
215 columns = [o_outline_view_other tableColumns];
216 count = columns.count;
217 for (NSUInteger x = 0; x < count; x++)
218 [[columns[x] dataCell] setFont:fontToUse];
219 [o_outline_view_other setRowHeight:rowHeight];
223 [o_outline_dict release];
229 @implementation VLCPlaylistCommon (NSOutlineViewDataSource)
230 /* return the number of children for Obj-C pointer item */ /* DONE */
231 - (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
234 playlist_item_t *p_item = NULL;
235 playlist_t * p_playlist = pl_Get(VLCIntf);
236 //assert(outlineView == o_outline_view);
240 p_item = p_current_root_item;
242 p_item = (playlist_item_t *)[item pointerValue];
245 i_return = p_item->i_children;
248 return i_return > 0 ? i_return : 0;
251 /* return the child at index for the Obj-C pointer item */ /* DONE */
252 - (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item
254 playlist_item_t *p_return = NULL, *p_item = NULL;
256 playlist_t * p_playlist = pl_Get(VLCIntf);
260 p_item = p_current_root_item; /* root object */
262 p_item = (playlist_item_t *)[item pointerValue];
264 if (p_item && index < p_item->i_children && index >= 0)
265 p_return = p_item->pp_children[index];
268 o_value = [o_outline_dict objectForKey:[NSString stringWithFormat: @"%p", p_return]];
270 if (o_value == nil) {
271 /* FIXME: Why is there a warning if that happens all the time and seems
272 * to be normal? Add an assert and fix it.
273 * msg_Warn(VLCIntf, "playlist item misses pointer value, adding one"); */
274 o_value = [[NSValue valueWithPointer: p_return] retain];
279 /* is the item expandable */
280 - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item
283 playlist_t *p_playlist = pl_Get(VLCIntf);
288 if (p_current_root_item) {
289 i_return = p_current_root_item->i_children;
292 playlist_item_t *p_item = (playlist_item_t *)[item pointerValue];
294 i_return = p_item->i_children;
298 return (i_return >= 0);
301 /* retrieve the string values for the cells */
302 - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)o_tc byItem:(id)item
306 playlist_item_t *p_item;
308 /* For error handling */
309 static BOOL attempted_reload = NO;
311 if (item == nil || ![item isKindOfClass: [NSValue class]]) {
312 /* Attempt to fix the error by asking for a data redisplay
313 * This might cause infinite loop, so add a small check */
314 if (!attempted_reload) {
315 attempted_reload = YES;
316 [outlineView reloadData];
321 p_item = (playlist_item_t *)[item pointerValue];
322 if (!p_item || !p_item->p_input) {
323 /* Attempt to fix the error by asking for a data redisplay
324 * This might cause infinite loop, so add a small check */
325 if (!attempted_reload) {
326 attempted_reload = YES;
327 [outlineView reloadData];
332 attempted_reload = NO;
333 NSString * o_identifier = [o_tc identifier];
335 if ([o_identifier isEqualToString:TRACKNUM_COLUMN]) {
336 psz_value = input_item_GetTrackNumber(p_item->p_input);
338 o_value = [NSString stringWithUTF8String:psz_value];
341 } else if ([o_identifier isEqualToString:TITLE_COLUMN]) {
342 /* sanity check to prevent the NSString class from crashing */
343 char *psz_title = input_item_GetTitleFbName(p_item->p_input);
345 o_value = [NSString stringWithUTF8String:psz_title];
348 } else if ([o_identifier isEqualToString:ARTIST_COLUMN]) {
349 psz_value = input_item_GetArtist(p_item->p_input);
351 o_value = [NSString stringWithUTF8String:psz_value];
354 } else if ([o_identifier isEqualToString:@"duration"]) {
355 char psz_duration[MSTRTIME_MAX_SIZE];
356 mtime_t dur = input_item_GetDuration(p_item->p_input);
358 secstotimestr(psz_duration, dur/1000000);
359 o_value = [NSString stringWithUTF8String:psz_duration];
363 } else if ([o_identifier isEqualToString:GENRE_COLUMN]) {
364 psz_value = input_item_GetGenre(p_item->p_input);
366 o_value = [NSString stringWithUTF8String:psz_value];
369 } else if ([o_identifier isEqualToString:ALBUM_COLUMN]) {
370 psz_value = input_item_GetAlbum(p_item->p_input);
372 o_value = [NSString stringWithUTF8String:psz_value];
375 } else if ([o_identifier isEqualToString:DESCRIPTION_COLUMN]) {
376 psz_value = input_item_GetDescription(p_item->p_input);
378 o_value = [NSString stringWithUTF8String:psz_value];
381 } else if ([o_identifier isEqualToString:DATE_COLUMN]) {
382 psz_value = input_item_GetDate(p_item->p_input);
384 o_value = [NSString stringWithUTF8String:psz_value];
387 } else if ([o_identifier isEqualToString:LANGUAGE_COLUMN]) {
388 psz_value = input_item_GetLanguage(p_item->p_input);
390 o_value = [NSString stringWithUTF8String:psz_value];
394 else if ([o_identifier isEqualToString:URI_COLUMN]) {
395 psz_value = decode_URI(input_item_GetURI(p_item->p_input));
397 o_value = [NSString stringWithUTF8String:psz_value];
401 else if ([o_identifier isEqualToString:FILESIZE_COLUMN]) {
402 psz_value = input_item_GetURI(p_item->p_input);
405 NSURL *url = [NSURL URLWithString:[NSString stringWithUTF8String:psz_value]];
406 if ([url isFileURL]) {
407 NSFileManager *fileManager = [NSFileManager defaultManager];
408 if ([fileManager fileExistsAtPath:[url path]]) {
410 NSDictionary *attributes = [fileManager attributesOfItemAtPath:[url path] error:&error];
411 o_value = [VLCByteCountFormatter stringFromByteCount:[attributes fileSize] countStyle:NSByteCountFormatterCountStyleDecimal];
417 else if ([o_identifier isEqualToString:@"status"]) {
418 if (input_item_HasErrorWhenReading(p_item->p_input)) {
419 o_value = [[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode(kAlertCautionIcon)];
420 [o_value setSize: NSMakeSize(16,16)];
429 /*****************************************************************************
430 * VLCPlaylistWizard implementation
431 *****************************************************************************/
432 @implementation VLCPlaylistWizard
434 - (IBAction)reloadOutlineView
436 /* Only reload the outlineview if the wizard window is open since this can
437 be quite long on big playlists */
438 if ([[o_outline_view window] isVisible])
439 [o_outline_view reloadData];
444 /*****************************************************************************
445 * An extension to NSOutlineView's interface to fix compilation warnings
446 * and let us access these 2 functions properly.
447 * This uses a private API, but works fine on all current OSX releases.
448 * Radar ID 11739459 request a public API for this. However, it is probably
449 * easier and faster to recreate similar looking bitmaps ourselves.
450 *****************************************************************************/
452 @interface NSOutlineView (UndocumentedSortImages)
453 + (NSImage *)_defaultTableHeaderSortImage;
454 + (NSImage *)_defaultTableHeaderReverseSortImage;
458 /*****************************************************************************
459 * VLCPlaylist implementation
460 *****************************************************************************/
461 @interface VLCPlaylist ()
463 NSImage *o_descendingSortingImage;
464 NSImage *o_ascendingSortingImage;
466 NSMutableArray *o_nodes_array;
467 NSMutableArray *o_items_array;
469 BOOL b_selected_item_met;
470 BOOL b_isSortDescending;
472 NSUInteger retainedRowSelection;
474 BOOL b_playlistmenu_nib_loaded;
478 - (void)saveTableColumns;
481 @implementation VLCPlaylist
485 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
486 NSMutableArray *o_columnArray = [[NSMutableArray alloc] init];
487 [o_columnArray addObject: [NSArray arrayWithObjects:TITLE_COLUMN, [NSNumber numberWithFloat:190.], nil]];
488 [o_columnArray addObject: [NSArray arrayWithObjects:ARTIST_COLUMN, [NSNumber numberWithFloat:95.], nil]];
489 [o_columnArray addObject: [NSArray arrayWithObjects:DURATION_COLUMN, [NSNumber numberWithFloat:95.], nil]];
491 NSDictionary *appDefaults = [NSDictionary dictionaryWithObjectsAndKeys:
492 [NSArray arrayWithArray:o_columnArray], @"PlaylistColumnSelection",
493 [NSArray array], @"recentlyPlayedMediaList",
494 [NSDictionary dictionary], @"recentlyPlayedMedia", nil];
496 [defaults registerDefaults:appDefaults];
497 [o_columnArray release];
504 o_nodes_array = [[NSMutableArray alloc] init];
505 o_items_array = [[NSMutableArray alloc] init];
512 [o_nodes_array release];
513 [o_items_array release];
522 playlist_t * p_playlist = pl_Get(VLCIntf);
524 [super awakeFromNib];
527 [o_outline_view setDoubleAction: @selector(playItem:)];
528 [o_outline_view_other setDoubleAction: @selector(playItem:)];
530 [o_outline_view registerForDraggedTypes: [NSArray arrayWithObjects:NSFilenamesPboardType, @"VLCPlaylistItemPboardType", nil]];
531 [o_outline_view setIntercellSpacing: NSMakeSize (0.0, 1.0)];
533 [o_outline_view_other registerForDraggedTypes: [NSArray arrayWithObjects:NSFilenamesPboardType, @"VLCPlaylistItemPboardType", nil]];
534 [o_outline_view_other setIntercellSpacing: NSMakeSize (0.0, 1.0)];
536 /* This uses a private API, but works fine on all current OSX releases.
537 * Radar ID 11739459 request a public API for this. However, it is probably
538 * easier and faster to recreate similar looking bitmaps ourselves. */
539 o_ascendingSortingImage = [[NSOutlineView class] _defaultTableHeaderSortImage];
540 o_descendingSortingImage = [[NSOutlineView class] _defaultTableHeaderReverseSortImage];
542 o_tc_sortColumn = nil;
544 NSArray * o_columnArray = [[NSUserDefaults standardUserDefaults] arrayForKey:@"PlaylistColumnSelection"];
545 NSUInteger count = [o_columnArray count];
547 id o_menu = [[VLCMain sharedInstance] mainMenu];
550 NSMenu *o_context_menu = [o_menu setupPlaylistTableColumnsMenu];
551 [o_playlist_header setMenu: o_context_menu];
553 for (NSUInteger i = 0; i < count; i++) {
554 o_column = [[o_columnArray objectAtIndex:i] objectAtIndex:0];
555 if ([o_column isEqualToString:@"status"])
558 if(![o_menu setPlaylistColumnTableState: NSOnState forColumn: o_column])
561 [[o_outline_view tableColumnWithIdentifier: o_column] setWidth: [[[o_columnArray objectAtIndex:i] objectAtIndex:1] floatValue]];
564 [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(applicationWillTerminate:) name: NSApplicationWillTerminateNotification object: nil];
569 - (void)applicationWillTerminate:(NSNotification *)notification
571 /* 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 */
572 [self saveTableColumns];
575 - (void)searchfieldChanged:(NSNotification *)o_notification
577 [o_search_field setStringValue:[[o_notification object] stringValue]];
582 [o_mi_play setTitle: _NS("Play")];
583 [o_mi_delete setTitle: _NS("Delete")];
584 [o_mi_recursive_expand setTitle: _NS("Expand Node")];
585 [o_mi_selectall setTitle: _NS("Select All")];
586 [o_mi_info setTitle: _NS("Media Information...")];
587 [o_mi_dl_cover_art setTitle: _NS("Download Cover Art")];
588 [o_mi_preparse setTitle: _NS("Fetch Meta Data")];
589 [o_mi_revealInFinder setTitle: _NS("Reveal in Finder")];
590 [o_mm_mi_revealInFinder setTitle: _NS("Reveal in Finder")];
591 [[o_mm_mi_revealInFinder menu] setAutoenablesItems: NO];
592 [o_mi_sort_name setTitle: _NS("Sort Node by Name")];
593 [o_mi_sort_author setTitle: _NS("Sort Node by Author")];
595 [o_search_field setToolTip: _NS("Search in Playlist")];
598 - (void)playlistUpdated
600 /* Clear indications of any existing column sorting */
601 NSUInteger count = [[o_outline_view tableColumns] count];
602 for (NSUInteger i = 0 ; i < count ; i++)
603 [o_outline_view setIndicatorImage:nil inTableColumn: [[o_outline_view tableColumns] objectAtIndex:i]];
605 [o_outline_view setHighlightedTableColumn:nil];
606 o_tc_sortColumn = nil;
607 // TODO Find a way to keep the dict size to a minimum
608 //[o_outline_dict removeAllObjects];
609 [o_outline_view reloadData];
610 [[[[VLCMain sharedInstance] wizard] playlistWizard] reloadOutlineView];
611 [[[[VLCMain sharedInstance] bookmarks] dataTable] reloadData];
613 [o_outline_view selectRowIndexes:[NSIndexSet indexSetWithIndex:retainedRowSelection] byExtendingSelection:NO];
615 [self outlineViewSelectionDidChange: nil];
616 [[VLCMain sharedInstance] updateMainWindow];
619 - (void)outlineViewSelectionDidChange:(NSNotification *)notification
622 playlist_item_t * p_item = [[o_outline_view itemAtRow:[o_outline_view selectedRow]] pointerValue];
625 /* update the state of our Reveal-in-Finder menu items */
626 NSMutableString *o_mrl;
627 char *psz_uri = input_item_GetURI(p_item->p_input);
629 [o_mi_revealInFinder setEnabled: NO];
630 [o_mm_mi_revealInFinder setEnabled: NO];
632 o_mrl = [NSMutableString stringWithUTF8String: psz_uri];
634 /* perform some checks whether it is a file and if it is local at all... */
635 NSRange prefix_range = [o_mrl rangeOfString: @"file:"];
636 if (prefix_range.location != NSNotFound)
637 [o_mrl deleteCharactersInRange: prefix_range];
639 if ([o_mrl characterAtIndex:0] == '/') {
640 [o_mi_revealInFinder setEnabled: YES];
641 [o_mm_mi_revealInFinder setEnabled: YES];
646 /* update our info-panel to reflect the new item */
647 [[[VLCMain sharedInstance] info] updatePanelWithItem:p_item->p_input];
651 - (BOOL)isSelectionEmpty
653 return [o_outline_view selectedRow] == -1;
656 - (void)updateRowSelection
659 playlist_t *p_playlist = pl_Get(VLCIntf);
660 playlist_item_t *p_item, *p_temp_item;
661 NSMutableArray *o_array = [NSMutableArray array];
664 p_item = playlist_CurrentPlayingItem(p_playlist);
665 if (p_item == NULL) {
670 p_temp_item = p_item;
671 while(p_temp_item->p_parent) {
672 [o_array insertObject: [NSValue valueWithPointer: p_temp_item] atIndex: 0];
673 p_temp_item = p_temp_item->p_parent;
677 NSUInteger count = [o_array count];
678 for (NSUInteger j = 0; j < count - 1; j++) {
680 if ((o_item = [o_outline_dict objectForKey:
681 [NSString stringWithFormat: @"%p",
682 [[o_array objectAtIndex:j] pointerValue]]]) != nil) {
683 [o_outline_view expandItem: o_item];
687 id o_item = [o_outline_dict objectForKey:[NSString stringWithFormat: @"%p", p_item]];
688 NSInteger i_index = [o_outline_view rowForItem:o_item];
689 [o_outline_view selectRowIndexes:[NSIndexSet indexSetWithIndex:i_index] byExtendingSelection:NO];
690 [o_outline_view setNeedsDisplay:YES];
693 /* Check if p_item is a child of p_node recursively. We need to check the item
694 existence first since OSX sometimes tries to redraw items that have been
695 deleted. We don't do it when not required since this verification takes
696 quite a long time on big playlists (yes, pretty hacky). */
698 - (BOOL)isItem: (playlist_item_t *)p_item inNode: (playlist_item_t *)p_node checkItemExistence:(BOOL)b_check locked:(BOOL)b_locked
700 playlist_t * p_playlist = pl_Get(VLCIntf);
701 playlist_item_t *p_temp_item = p_item;
706 if (p_node == p_item)
709 if (p_node->i_children < 1)
714 if (!b_locked) PL_LOCK;
717 /* Since outlineView: willDisplayCell:... may call this function with
718 p_items that don't exist anymore, first check if the item is still
719 in the playlist. Any cleaner solution welcomed. */
720 for (i = 0; i < p_playlist->all_items.i_size; i++) {
721 if (ARRAY_VAL(p_playlist->all_items, i) == p_item)
723 else if (i == p_playlist->all_items.i_size - 1)
725 if (!b_locked) PL_UNLOCK;
732 p_temp_item = p_temp_item->p_parent;
733 if (p_temp_item == p_node) {
734 if (!b_locked) PL_UNLOCK;
738 if (!b_locked) PL_UNLOCK;
743 /* This method is useful for instance to remove the selected children of an
744 already selected node */
745 - (void)removeItemsFrom:(id)o_items ifChildrenOf:(id)o_nodes
747 NSUInteger itemCount = [o_items count];
748 NSUInteger nodeCount = [o_nodes count];
749 for (NSUInteger i = 0 ; i < itemCount ; i++) {
750 for (NSUInteger j = 0 ; j < nodeCount ; j++) {
751 if (o_items == o_nodes) {
752 if (j == i) continue;
754 if ([self isItem: [[o_items objectAtIndex:i] pointerValue]
755 inNode: [[o_nodes objectAtIndex:j] pointerValue]
756 checkItemExistence: NO locked:NO]) {
757 [o_items removeObjectAtIndex:i];
758 /* We need to execute the next iteration with the same index
759 since the current item has been deleted */
767 - (IBAction)savePlaylist:(id)sender
769 playlist_t * p_playlist = pl_Get(VLCIntf);
771 NSSavePanel *o_save_panel = [NSSavePanel savePanel];
772 NSString * o_name = [NSString stringWithFormat: @"%@", _NS("Untitled")];
774 [NSBundle loadNibNamed:@"PlaylistAccessoryView" owner:self];
776 [o_save_accessory_text setStringValue: _NS("File Format:")];
777 [[o_save_accessory_popup itemAtIndex:0] setTitle: _NS("Extended M3U")];
778 [[o_save_accessory_popup itemAtIndex:1] setTitle: _NS("XML Shareable Playlist Format (XSPF)")];
779 [[o_save_accessory_popup itemAtIndex:2] setTitle: _NS("HTML playlist")];
781 [o_save_panel setTitle: _NS("Save Playlist")];
782 [o_save_panel setPrompt: _NS("Save")];
783 [o_save_panel setAccessoryView: o_save_accessory_view];
784 [o_save_panel setNameFieldStringValue: o_name];
786 if ([o_save_panel runModal] == NSFileHandlingPanelOKButton) {
787 NSString *o_filename = [[o_save_panel URL] path];
789 if ([o_save_accessory_popup indexOfSelectedItem] == 0) {
790 NSString * o_real_filename;
792 range.location = [o_filename length] - [@".m3u" length];
793 range.length = [@".m3u" length];
795 if ([o_filename compare:@".m3u" options: NSCaseInsensitiveSearch range: range] != NSOrderedSame)
796 o_real_filename = [NSString stringWithFormat: @"%@.m3u", o_filename];
798 o_real_filename = o_filename;
800 playlist_Export(p_playlist,
801 [o_real_filename fileSystemRepresentation],
802 p_playlist->p_local_category, "export-m3u");
803 } else if ([o_save_accessory_popup indexOfSelectedItem] == 1) {
804 NSString * o_real_filename;
806 range.location = [o_filename length] - [@".xspf" length];
807 range.length = [@".xspf" length];
809 if ([o_filename compare:@".xspf" options: NSCaseInsensitiveSearch range: range] != NSOrderedSame)
810 o_real_filename = [NSString stringWithFormat: @"%@.xspf", o_filename];
812 o_real_filename = o_filename;
814 playlist_Export(p_playlist,
815 [o_real_filename fileSystemRepresentation],
816 p_playlist->p_local_category, "export-xspf");
818 NSString * o_real_filename;
820 range.location = [o_filename length] - [@".html" length];
821 range.length = [@".html" length];
823 if ([o_filename compare:@".html" options: NSCaseInsensitiveSearch range: range] != NSOrderedSame)
824 o_real_filename = [NSString stringWithFormat: @"%@.html", o_filename];
826 o_real_filename = o_filename;
828 playlist_Export(p_playlist,
829 [o_real_filename fileSystemRepresentation],
830 p_playlist->p_local_category, "export-html");
835 /* When called retrieves the selected outlineview row and plays that node or item */
836 - (IBAction)playItem:(id)sender
838 intf_thread_t * p_intf = VLCIntf;
839 playlist_t * p_playlist = pl_Get(p_intf);
841 playlist_item_t *p_item;
842 playlist_item_t *p_node = NULL;
844 // ignore clicks on column header when handling double action
845 if (sender != nil && [o_outline_view clickedRow] == -1 && sender != o_mi_play)
848 p_item = [[o_outline_view itemAtRow:[o_outline_view selectedRow]] pointerValue];
852 if (p_item->i_children == -1) {
853 p_node = p_item->p_parent;
856 if (p_node->i_children > 0 && p_node->pp_children[0]->i_children == -1)
857 p_item = p_node->pp_children[0];
862 playlist_Control(p_playlist, PLAYLIST_VIEWPLAY, pl_Locked, p_node, p_item);
867 - (IBAction)revealItemInFinder:(id)sender
869 NSIndexSet * selectedRows = [o_outline_view selectedRowIndexes];
870 NSUInteger count = [selectedRows count];
871 NSUInteger indexes[count];
872 [selectedRows getIndexes:indexes maxCount:count inIndexRange:nil];
874 NSMutableString * o_mrl;
875 playlist_item_t *p_item;
876 for (NSUInteger i = 0; i < count; i++) {
877 p_item = [[o_outline_view itemAtRow:indexes[i]] pointerValue];
879 if (! p_item || !p_item->p_input)
882 char * psz_url = decode_URI(input_item_GetURI(p_item->p_input));
883 o_mrl = [[NSMutableString alloc] initWithString: [NSString stringWithUTF8String:psz_url ? psz_url : ""]];
887 /* perform some checks whether it is a file and if it is local at all... */
888 if ([o_mrl length] > 0) {
889 NSRange prefix_range = [o_mrl rangeOfString: @"file:"];
890 if (prefix_range.location != NSNotFound)
891 [o_mrl deleteCharactersInRange: prefix_range];
893 if ([o_mrl characterAtIndex:0] == '/')
894 [[NSWorkspace sharedWorkspace] selectFile: o_mrl inFileViewerRootedAtPath: o_mrl];
901 /* When called retrieves the selected outlineview row and plays that node or item */
902 - (IBAction)preparseItem:(id)sender
905 NSIndexSet *o_selected_indexes;
906 intf_thread_t * p_intf = VLCIntf;
907 playlist_t * p_playlist = pl_Get(p_intf);
908 playlist_item_t *p_item = NULL;
910 o_selected_indexes = [o_outline_view selectedRowIndexes];
911 i_count = [o_selected_indexes count];
913 NSUInteger indexes[i_count];
914 [o_selected_indexes getIndexes:indexes maxCount:i_count inIndexRange:nil];
915 for (int i = 0; i < i_count; i++) {
916 p_item = [[o_outline_view itemAtRow:indexes[i]] pointerValue];
917 [o_outline_view deselectRow: indexes[i]];
920 if (p_item->i_children == -1)
921 libvlc_MetaRequest(p_intf->p_libvlc, p_item->p_input, META_REQUEST_OPTION_NONE);
923 msg_Dbg(p_intf, "preparsing nodes not implemented");
926 [self playlistUpdated];
929 - (IBAction)downloadCoverArt:(id)sender
932 NSIndexSet *o_selected_indexes;
933 intf_thread_t * p_intf = VLCIntf;
934 playlist_t * p_playlist = pl_Get(p_intf);
935 playlist_item_t *p_item = NULL;
937 o_selected_indexes = [o_outline_view selectedRowIndexes];
938 i_count = [o_selected_indexes count];
940 NSUInteger indexes[i_count];
941 [o_selected_indexes getIndexes:indexes maxCount:i_count inIndexRange:nil];
942 for (int i = 0; i < i_count; i++) {
943 p_item = [[o_outline_view itemAtRow: indexes[i]] pointerValue];
945 if (p_item && p_item->i_children == -1)
946 libvlc_ArtRequest(p_intf->p_libvlc, p_item->p_input, META_REQUEST_OPTION_NONE);
948 [self playlistUpdated];
951 - (IBAction)selectAll:(id)sender
953 [o_outline_view selectAll: nil];
956 - (IBAction)showInfoPanel:(id)sender
958 [[[VLCMain sharedInstance] info] initPanel];
961 - (IBAction)deleteItem:(id)sender
964 NSIndexSet *o_selected_indexes;
965 playlist_t * p_playlist;
966 intf_thread_t * p_intf = VLCIntf;
968 o_selected_indexes = [o_outline_view selectedRowIndexes];
969 i_count = [o_selected_indexes count];
970 retainedRowSelection = [o_selected_indexes firstIndex];
971 if (retainedRowSelection == NSNotFound)
972 retainedRowSelection = 0;
974 p_playlist = pl_Get(p_intf);
976 NSUInteger indexes[i_count];
977 if (i_count == [o_outline_view numberOfRows]) {
979 playlist_NodeDelete(p_playlist, [self currentPlaylistRoot], true, false);
981 [self playlistUpdated];
984 [o_selected_indexes getIndexes:indexes maxCount:i_count inIndexRange:nil];
985 for (int i = 0; i < i_count; i++) {
986 id o_item = [o_outline_view itemAtRow: indexes[i]];
987 [o_outline_view deselectRow: indexes[i]];
990 playlist_item_t *p_item = [o_item pointerValue];
991 if (!p_item || !p_item->p_input) {
996 if (p_item->i_children != -1) {
997 //is a node and not an item
998 if (playlist_Status(p_playlist) != PLAYLIST_STOPPED &&
999 [self isItem: playlist_CurrentPlayingItem(p_playlist) inNode: ((playlist_item_t *)[o_item pointerValue])
1000 checkItemExistence: NO locked:YES] == YES)
1001 // if current item is in selected node and is playing then stop playlist
1002 playlist_Control(p_playlist, PLAYLIST_STOP, pl_Locked);
1004 playlist_NodeDelete(p_playlist, p_item, true, false);
1006 playlist_DeleteFromInput(p_playlist, p_item->p_input, pl_Locked);
1009 [o_outline_dict removeObjectForKey:[NSString stringWithFormat:@"%p", [o_item pointerValue]]];
1013 [self playlistUpdated];
1016 - (IBAction)sortNodeByName:(id)sender
1018 [self sortNode: SORT_TITLE];
1021 - (IBAction)sortNodeByAuthor:(id)sender
1023 [self sortNode: SORT_ARTIST];
1026 - (void)sortNode:(int)i_mode
1028 playlist_t * p_playlist = pl_Get(VLCIntf);
1029 playlist_item_t * p_item;
1031 if ([o_outline_view selectedRow] > -1) {
1032 p_item = [[o_outline_view itemAtRow: [o_outline_view selectedRow]] pointerValue];
1036 p_item = [self currentPlaylistRoot]; // If no item is selected, sort the whole playlist
1039 if (p_item->i_children > -1) // the item is a node
1040 playlist_RecursiveNodeSort(p_playlist, p_item, i_mode, ORDER_NORMAL);
1042 playlist_RecursiveNodeSort(p_playlist, p_item->p_parent, i_mode, ORDER_NORMAL);
1045 [self playlistUpdated];
1048 - (input_item_t *)createItem:(NSDictionary *)o_one_item
1050 intf_thread_t * p_intf = VLCIntf;
1051 playlist_t * p_playlist = pl_Get(p_intf);
1053 input_item_t *p_input;
1054 BOOL b_rem = FALSE, b_dir = FALSE, b_writable = FALSE;
1055 NSString *o_uri, *o_name, *o_path;
1061 o_uri = (NSString *)[o_one_item objectForKey: @"ITEM_URL"];
1062 o_nsurl = [NSURL URLWithString: o_uri];
1063 o_path = [o_nsurl path];
1064 o_name = (NSString *)[o_one_item objectForKey: @"ITEM_NAME"];
1065 o_options = (NSArray *)[o_one_item objectForKey: @"ITEM_OPTIONS"];
1067 if ([[NSFileManager defaultManager] fileExistsAtPath:o_path isDirectory:&b_dir] && b_dir &&
1068 [[NSWorkspace sharedWorkspace] getFileSystemInfoForPath:o_path isRemovable: &b_rem
1069 isWritable:&b_writable isUnmountable:NULL description:NULL type:NULL] && b_rem && !b_writable && [o_nsurl isFileURL]) {
1070 id o_vlc_open = [[VLCMain sharedInstance] open];
1072 NSString *diskType = [o_vlc_open getVolumeTypeFromMountPath: o_path];
1073 msg_Dbg(p_intf, "detected optical media of type %s in the file input", [diskType UTF8String]);
1075 if ([diskType isEqualToString: kVLCMediaDVD])
1076 o_uri = [NSString stringWithFormat: @"dvdnav://%@", [o_vlc_open getBSDNodeFromMountPath: o_path]];
1077 else if ([diskType isEqualToString: kVLCMediaVideoTSFolder])
1078 o_uri = [NSString stringWithFormat: @"dvdnav://%@", o_path];
1079 else if ([diskType isEqualToString: kVLCMediaAudioCD])
1080 o_uri = [NSString stringWithFormat: @"cdda://%@", [o_vlc_open getBSDNodeFromMountPath: o_path]];
1081 else if ([diskType isEqualToString: kVLCMediaVCD])
1082 o_uri = [NSString stringWithFormat: @"vcd://%@#0:0", [o_vlc_open getBSDNodeFromMountPath: o_path]];
1083 else if ([diskType isEqualToString: kVLCMediaSVCD])
1084 o_uri = [NSString stringWithFormat: @"vcd://%@@0:0", [o_vlc_open getBSDNodeFromMountPath: o_path]];
1085 else if ([diskType isEqualToString: kVLCMediaBD] || [diskType isEqualToString: kVLCMediaBDMVFolder])
1086 o_uri = [NSString stringWithFormat: @"bluray://%@", o_path];
1088 msg_Warn(VLCIntf, "unknown disk type, treating %s as regular input", [o_path UTF8String]);
1090 p_input = input_item_New([o_uri UTF8String], [[[NSFileManager defaultManager] displayNameAtPath: o_path] UTF8String]);
1093 p_input = input_item_New([o_uri fileSystemRepresentation], o_name ? [o_name UTF8String] : NULL);
1099 NSUInteger count = [o_options count];
1100 for (NSUInteger i = 0; i < count; i++)
1101 input_item_AddOption(p_input, [[o_options objectAtIndex:i] UTF8String], VLC_INPUT_OPTION_TRUSTED);
1104 /* Recent documents menu */
1105 if (o_nsurl != nil && (BOOL)config_GetInt(p_playlist, "macosx-recentitems") == YES)
1106 [[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL: o_nsurl];
1111 - (void)appendArray:(NSArray*)o_array atPos:(int)i_position enqueue:(BOOL)b_enqueue
1113 playlist_t * p_playlist = pl_Get(VLCIntf);
1114 NSUInteger count = [o_array count];
1115 BOOL b_usingPlaylist;
1116 if ([self currentPlaylistRoot] == p_playlist->p_ml_category)
1117 b_usingPlaylist = NO;
1119 b_usingPlaylist = YES;
1122 for (NSUInteger i_item = 0; i_item < count; i_item++) {
1123 input_item_t *p_input;
1124 NSDictionary *o_one_item;
1127 o_one_item = [o_array objectAtIndex:i_item];
1128 p_input = [self createItem: o_one_item];
1133 int returnValue = playlist_AddInput(p_playlist, p_input, PLAYLIST_INSERT, i_position == -1 ? PLAYLIST_END : i_position + i_item, b_usingPlaylist, pl_Locked);
1134 if (returnValue != VLC_SUCCESS) {
1135 vlc_gc_decref(p_input);
1139 if (i_item == 0 && !b_enqueue) {
1140 playlist_item_t *p_item = playlist_ItemGetByInput(p_playlist, p_input);
1141 playlist_Control(p_playlist, PLAYLIST_VIEWPLAY, pl_Locked, p_item->p_parent, p_item);
1144 vlc_gc_decref(p_input);
1147 [self playlistUpdated];
1150 - (void)appendNodeArray:(NSArray*)o_array inNode:(playlist_item_t *)p_node atPos:(int)i_position enqueue:(BOOL)b_enqueue
1152 playlist_t * p_playlist = pl_Get(VLCIntf);
1153 NSUInteger count = [o_array count];
1155 for (NSUInteger i_item = 0; i_item < count; i_item++) {
1156 input_item_t *p_input;
1157 NSDictionary *o_one_item;
1161 o_one_item = [o_array objectAtIndex:i_item];
1162 p_input = [self createItem: o_one_item];
1168 playlist_NodeAddInput(p_playlist, p_input, p_node,
1171 PLAYLIST_END : i_position + i_item,
1175 if (i_item == 0 && !b_enqueue) {
1176 playlist_item_t *p_item;
1177 p_item = playlist_ItemGetByInput(p_playlist, p_input);
1178 playlist_Control(p_playlist, PLAYLIST_VIEWPLAY, pl_Locked, p_node, p_item);
1181 vlc_gc_decref(p_input);
1183 [self playlistUpdated];
1186 - (NSMutableArray *)subSearchItem:(playlist_item_t *)p_item
1188 playlist_t *p_playlist = pl_Get(VLCIntf);
1189 playlist_item_t *p_selected_item;
1192 i_selected_row = [o_outline_view selectedRow];
1193 if (i_selected_row < 0)
1196 p_selected_item = (playlist_item_t *)[[o_outline_view itemAtRow: i_selected_row] pointerValue];
1198 for (NSUInteger i_current = 0; i_current < p_item->i_children ; i_current++) {
1200 NSString *o_current_name, *o_current_author;
1203 o_current_name = [NSString stringWithUTF8String:p_item->pp_children[i_current]->p_input->psz_name];
1204 psz_temp = input_item_GetInfo(p_item->p_input, _("Meta-information"),_("Artist"));
1205 o_current_author = [NSString stringWithUTF8String:psz_temp];
1209 if (p_selected_item == p_item->pp_children[i_current] && b_selected_item_met == NO)
1210 b_selected_item_met = YES;
1211 else if (p_selected_item == p_item->pp_children[i_current] && b_selected_item_met == YES)
1213 else if (b_selected_item_met == YES &&
1214 ([o_current_name rangeOfString:[o_search_field
1215 stringValue] options:NSCaseInsensitiveSearch].length ||
1216 [o_current_author rangeOfString:[o_search_field
1217 stringValue] options:NSCaseInsensitiveSearch].length))
1218 /*Adds the parent items in the result array as well, so that we can
1220 return [NSMutableArray arrayWithObject: [NSValue valueWithPointer: p_item->pp_children[i_current]]];
1222 if (p_item->pp_children[i_current]->i_children > 0) {
1223 id o_result = [self subSearchItem:
1224 p_item->pp_children[i_current]];
1225 if (o_result != NULL) {
1226 [o_result insertObject: [NSValue valueWithPointer:
1227 p_item->pp_children[i_current]] atIndex:0];
1235 - (IBAction)searchItem:(id)sender
1237 playlist_t * p_playlist = pl_Get(VLCIntf);
1242 b_selected_item_met = NO;
1244 /* First, only search after the selected item:
1245 * (b_selected_item_met = NO) */
1246 o_result = [self subSearchItem:[self currentPlaylistRoot]];
1247 if (o_result == NULL)
1248 /* If the first search failed, search again from the beginning */
1249 o_result = [self subSearchItem:[self currentPlaylistRoot]];
1251 if (o_result != NULL) {
1253 if ([[o_result objectAtIndex:0] pointerValue] == p_playlist->p_local_category)
1257 NSUInteger count = [o_result count];
1259 for (NSUInteger i = i_start ; i < count - 1 ; i++) {
1260 [o_outline_view expandItem: [o_outline_dict objectForKey:
1261 [NSString stringWithFormat: @"%p",
1262 [[o_result objectAtIndex:i] pointerValue]]]];
1264 i_row = [o_outline_view rowForItem: [o_outline_dict objectForKey:
1265 [NSString stringWithFormat: @"%p",
1266 [[o_result objectAtIndex:count - 1 ]
1270 [o_outline_view selectRowIndexes:[NSIndexSet indexSetWithIndex:i_row] byExtendingSelection:NO];
1271 [o_outline_view scrollRowToVisible: i_row];
1275 - (IBAction)recursiveExpandNode:(id)sender
1277 NSIndexSet * selectedRows = [o_outline_view selectedRowIndexes];
1278 NSUInteger count = [selectedRows count];
1279 NSUInteger indexes[count];
1280 [selectedRows getIndexes:indexes maxCount:count inIndexRange:nil];
1283 playlist_item_t *p_item;
1284 for (NSUInteger i = 0; i < count; i++) {
1285 o_item = [o_outline_view itemAtRow: indexes[i]];
1286 p_item = (playlist_item_t *)[o_item pointerValue];
1288 if (![[o_outline_view dataSource] outlineView: o_outline_view isItemExpandable: o_item])
1289 o_item = [o_outline_dict objectForKey: [NSString stringWithFormat: @"%p", p_item->p_parent]];
1291 /* We need to collapse the node first, since OSX refuses to recursively
1292 expand an already expanded node, even if children nodes are collapsed. */
1293 [o_outline_view collapseItem: o_item collapseChildren: YES];
1294 [o_outline_view expandItem: o_item expandChildren: YES];
1296 selectedRows = [o_outline_view selectedRowIndexes];
1297 [selectedRows getIndexes:indexes maxCount:count inIndexRange:nil];
1301 - (NSMenu *)menuForEvent:(NSEvent *)o_event
1303 if (!b_playlistmenu_nib_loaded)
1304 b_playlistmenu_nib_loaded = [NSBundle loadNibNamed:@"PlaylistMenu" owner:self];
1310 pt = [o_outline_view convertPoint: [o_event locationInWindow] fromView: nil];
1311 int row = [o_outline_view rowAtPoint:pt];
1312 if (row != -1 && ![[o_outline_view selectedRowIndexes] containsIndex: row])
1313 [o_outline_view selectRowIndexes:[NSIndexSet indexSetWithIndex:row] byExtendingSelection:NO];
1315 b_item_sel = (row != -1 && [o_outline_view selectedRow] != -1);
1316 b_rows = [o_outline_view numberOfRows] != 0;
1318 [o_mi_play setEnabled: b_item_sel];
1319 [o_mi_delete setEnabled: b_item_sel];
1320 [o_mi_selectall setEnabled: b_rows];
1321 [o_mi_info setEnabled: b_item_sel];
1322 [o_mi_preparse setEnabled: b_item_sel];
1323 [o_mi_recursive_expand setEnabled: b_item_sel];
1324 [o_mi_sort_name setEnabled: b_item_sel];
1325 [o_mi_sort_author setEnabled: b_item_sel];
1330 - (void)outlineView: (NSOutlineView *)o_tv didClickTableColumn:(NSTableColumn *)o_tc
1332 int i_mode, i_type = 0;
1333 intf_thread_t *p_intf = VLCIntf;
1334 NSString * o_identifier = [o_tc identifier];
1336 playlist_t *p_playlist = pl_Get(p_intf);
1338 if ([o_identifier isEqualToString:TRACKNUM_COLUMN])
1339 i_mode = SORT_TRACK_NUMBER;
1340 else if ([o_identifier isEqualToString:TITLE_COLUMN])
1341 i_mode = SORT_TITLE;
1342 else if ([o_identifier isEqualToString:ARTIST_COLUMN])
1343 i_mode = SORT_ARTIST;
1344 else if ([o_identifier isEqualToString:GENRE_COLUMN])
1345 i_mode = SORT_GENRE;
1346 else if ([o_identifier isEqualToString:DURATION_COLUMN])
1347 i_mode = SORT_DURATION;
1348 else if ([o_identifier isEqualToString:ALBUM_COLUMN])
1349 i_mode = SORT_ALBUM;
1350 else if ([o_identifier isEqualToString:DESCRIPTION_COLUMN])
1351 i_mode = SORT_DESCRIPTION;
1352 else if ([o_identifier isEqualToString:URI_COLUMN])
1357 if (o_tc_sortColumn == o_tc)
1358 b_isSortDescending = !b_isSortDescending;
1360 b_isSortDescending = false;
1362 if (b_isSortDescending)
1363 i_type = ORDER_REVERSE;
1365 i_type = ORDER_NORMAL;
1368 playlist_RecursiveNodeSort(p_playlist, [self currentPlaylistRoot], i_mode, i_type);
1371 [self playlistUpdated];
1373 o_tc_sortColumn = o_tc;
1374 [o_outline_view setHighlightedTableColumn:o_tc];
1376 if (b_isSortDescending)
1377 [o_outline_view setIndicatorImage:o_descendingSortingImage inTableColumn:o_tc];
1379 [o_outline_view setIndicatorImage:o_ascendingSortingImage inTableColumn:o_tc];
1383 - (void)outlineView:(NSOutlineView *)outlineView
1384 willDisplayCell:(id)cell
1385 forTableColumn:(NSTableColumn *)tableColumn
1388 /* this method can be called when VLC is already dead, hence the extra checks */
1389 intf_thread_t * p_intf = VLCIntf;
1392 playlist_t *p_playlist = pl_Get(p_intf);
1399 o_playing_item = [o_outline_dict objectForKey: [NSString stringWithFormat:@"%p", playlist_CurrentPlayingItem(p_playlist)]];
1403 if (config_GetInt(VLCIntf, "macosx-large-text"))
1404 fontToUse = [NSFont systemFontOfSize:13.];
1406 fontToUse = [NSFont systemFontOfSize:11.];
1408 if ([self isItem: [o_playing_item pointerValue] inNode: [item pointerValue] checkItemExistence:YES locked:NO]
1409 || [o_playing_item isEqual: item])
1410 [cell setFont: [[NSFontManager sharedFontManager] convertFont:fontToUse toHaveTrait:NSBoldFontMask]];
1412 [cell setFont: [[NSFontManager sharedFontManager] convertFont:fontToUse toNotHaveTrait:NSBoldFontMask]];
1417 playlist_t *p_playlist = pl_Get(VLCIntf);
1422 o_playing_item = [o_outline_dict objectForKey: [NSString stringWithFormat:@"%p", playlist_CurrentPlayingItem(p_playlist)]];
1425 return o_playing_item;
1428 - (NSArray *)draggedItems
1430 return [[o_nodes_array arrayByAddingObjectsFromArray: o_items_array] retain];
1433 - (void)setColumn: (NSString *)o_column state: (NSInteger)i_state translationDict:(NSDictionary *)o_dict
1435 NSTableColumn * o_work_tc;
1437 if (i_state == NSOnState) {
1438 NSString *o_title = [o_dict objectForKey:o_column];
1442 o_work_tc = [[NSTableColumn alloc] initWithIdentifier: o_column];
1443 [o_work_tc setEditable: NO];
1444 [[o_work_tc dataCell] setFont: [NSFont controlContentFontOfSize:11.]];
1446 [[o_work_tc headerCell] setStringValue: [o_dict objectForKey:o_column]];
1448 if ([o_column isEqualToString: TRACKNUM_COLUMN]) {
1449 [o_work_tc setWidth: 20.];
1450 [o_work_tc setResizingMask: NSTableColumnNoResizing];
1451 [[o_work_tc headerCell] setStringValue: @"#"];
1454 [o_outline_view addTableColumn: o_work_tc];
1455 [o_work_tc release];
1456 [o_outline_view reloadData];
1457 [o_outline_view setNeedsDisplay: YES];
1460 [o_outline_view removeTableColumn: [o_outline_view tableColumnWithIdentifier: o_column]];
1462 [o_outline_view setOutlineTableColumn: [o_outline_view tableColumnWithIdentifier:TITLE_COLUMN]];
1465 - (void)saveTableColumns
1467 NSMutableArray * o_arrayToSave = [[NSMutableArray alloc] init];
1468 NSArray * o_columns = [[NSArray alloc] initWithArray:[o_outline_view tableColumns]];
1469 NSUInteger count = [o_columns count];
1470 NSTableColumn * o_currentColumn;
1471 for (NSUInteger i = 0; i < count; i++) {
1472 o_currentColumn = [o_columns objectAtIndex:i];
1473 [o_arrayToSave addObject:[NSArray arrayWithObjects:[o_currentColumn identifier], [NSNumber numberWithFloat:[o_currentColumn width]], nil]];
1475 [[NSUserDefaults standardUserDefaults] setObject: o_arrayToSave forKey:@"PlaylistColumnSelection"];
1476 [[NSUserDefaults standardUserDefaults] synchronize];
1477 [o_columns release];
1478 [o_arrayToSave release];
1481 - (void)continuePlaybackWhereYouLeftOff:(input_thread_t *)p_input_thread
1483 NSDictionary *recentlyPlayedFiles = [[NSUserDefaults standardUserDefaults] objectForKey:@"recentlyPlayedMedia"];
1484 if (recentlyPlayedFiles) {
1485 input_item_t *p_item = input_GetItem(p_input_thread);
1489 /* allow the user to over-write the start-time */
1490 if (p_item->i_options > 0) {
1491 for (int x = 0; x < p_item->i_options; x++) {
1492 if (strstr(p_item->ppsz_options[x],"start-time"))
1497 char *psz_url = decode_URI(input_item_GetURI(p_item));
1501 NSString *url = [NSString stringWithUTF8String:psz_url ? psz_url : ""];
1504 /* check for file existance before resuming */
1505 if (![[NSFileManager defaultManager] fileExistsAtPath:[[NSURL URLWithString:[NSString stringWithUTF8String:input_item_GetURI(p_item)]] path]])
1508 NSNumber *lastPosition = [recentlyPlayedFiles objectForKey:url];
1509 if (lastPosition && lastPosition.intValue > 0) {
1511 var_Get(p_input_thread, "position", &pos);
1512 float f_current_pos = 100. * pos.f_float;
1513 long long int dur = input_item_GetDuration(p_item) / 1000000;
1514 int current_pos_in_sec = (f_current_pos * dur) / 100;
1516 if (current_pos_in_sec >= lastPosition.intValue)
1519 int settingValue = config_GetInt(VLCIntf, "macosx-continue-playback");
1520 NSInteger returnValue = NSAlertErrorReturn;
1522 if (settingValue == 0) {
1523 NSAlert *theAlert = [NSAlert alertWithMessageText:_NS("Continue playback?") defaultButton:_NS("Continue") alternateButton:_NS("Restart playback") otherButton:_NS("Always continue") informativeTextWithFormat:_NS("Playback of \"%@\" will continue at %@"), [NSString stringWithUTF8String:input_item_GetTitleFbName(p_item)], [[VLCStringUtility sharedInstance] stringForTime:lastPosition.intValue]];
1525 [[VLCCoreInteraction sharedInstance] pause];
1526 returnValue = [theAlert runModal];
1527 [[VLCCoreInteraction sharedInstance] playOrPause];
1530 if (returnValue == NSAlertAlternateReturn || settingValue == 2)
1531 lastPosition = [NSNumber numberWithInt:0];
1533 pos.f_float = (float)lastPosition.intValue / (float)dur;
1534 msg_Dbg(VLCIntf, "continuing playback at %2.2f", pos.f_float);
1535 var_Set(p_input_thread, "position", pos);
1537 if (returnValue == NSAlertOtherReturn)
1538 config_PutInt(VLCIntf, "macosx-continue-playback", 1);
1543 - (void)storePlaybackPositionForItem:(input_thread_t *)p_input_thread
1545 input_item_t *p_item = input_GetItem(p_input_thread);
1549 char *psz_url = decode_URI(input_item_GetURI(p_item));
1550 NSString *url = [NSString stringWithUTF8String:psz_url ? psz_url : ""];
1556 if ([url rangeOfString:@"file://" options:NSCaseInsensitiveSearch].location != 0)
1559 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
1560 NSMutableDictionary *mutDict = [[NSMutableDictionary alloc] initWithDictionary:[defaults objectForKey:@"recentlyPlayedMedia"]];
1563 var_Get(p_input_thread, "position", &pos);
1564 float f_current_pos = 100. * pos.f_float;
1565 long long int dur = input_item_GetDuration(p_item) / 1000000;
1566 int current_pos_in_sec = (f_current_pos * dur) / 100;
1567 NSMutableArray *mediaList = [[defaults objectForKey:@"recentlyPlayedMediaList"] mutableCopy];
1569 if (pos.f_float > .05 && pos.f_float < .95 && dur > 180) {
1570 [mutDict setObject:[NSNumber numberWithInt:current_pos_in_sec] forKey:url];
1572 [mediaList removeObject:url];
1573 [mediaList addObject:url];
1574 NSUInteger mediaListCount = mediaList.count;
1575 if (mediaListCount > 30) {
1576 for (NSUInteger x = 0; x < mediaListCount - 30; x++) {
1577 [mutDict removeObjectForKey:[mediaList objectAtIndex:0]];
1578 [mediaList removeObjectAtIndex:0];
1582 [mutDict removeObjectForKey:url];
1583 [mediaList removeObject:url];
1585 [defaults setObject:mutDict forKey:@"recentlyPlayedMedia"];
1586 [defaults setObject:mediaList forKey:@"recentlyPlayedMediaList"];
1587 [defaults synchronize];
1590 [mediaList release];
1595 @implementation VLCPlaylist (NSOutlineViewDataSource)
1597 - (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item
1599 id o_value = [super outlineView: outlineView child: index ofItem: item];
1601 [o_outline_dict setObject:o_value forKey:[NSString stringWithFormat:@"%p", [o_value pointerValue]]];
1605 /* Required for drag & drop and reordering */
1606 - (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pboard
1608 playlist_t *p_playlist = pl_Get(VLCIntf);
1610 /* First remove the items that were moved during the last drag & drop
1612 [o_items_array removeAllObjects];
1613 [o_nodes_array removeAllObjects];
1615 NSUInteger itemCount = [items count];
1617 for (NSUInteger i = 0 ; i < itemCount ; i++) {
1618 id o_item = [items objectAtIndex:i];
1620 /* Fill the items and nodes to move in 2 different arrays */
1621 if (((playlist_item_t *)[o_item pointerValue])->i_children > 0)
1622 [o_nodes_array addObject: o_item];
1624 [o_items_array addObject: o_item];
1627 /* Now we need to check if there are selected items that are in already
1628 selected nodes. In that case, we only want to move the nodes */
1629 [self removeItemsFrom: o_nodes_array ifChildrenOf: o_nodes_array];
1630 [self removeItemsFrom: o_items_array ifChildrenOf: o_nodes_array];
1632 /* We add the "VLCPlaylistItemPboardType" type to be able to recognize
1633 a Drop operation coming from the playlist. */
1635 [pboard declareTypes: [NSArray arrayWithObject:@"VLCPlaylistItemPboardType"] owner: self];
1636 [pboard setData:[NSData data] forType:@"VLCPlaylistItemPboardType"];
1641 - (NSDragOperation)outlineView:(NSOutlineView *)outlineView validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(NSInteger)index
1643 playlist_t *p_playlist = pl_Get(VLCIntf);
1644 NSPasteboard *o_pasteboard = [info draggingPasteboard];
1646 if (!p_playlist) return NSDragOperationNone;
1648 /* Dropping ON items is not allowed if item is not a node */
1650 if (index == NSOutlineViewDropOnItemIndex &&
1651 ((playlist_item_t *)[item pointerValue])->i_children == -1) {
1652 return NSDragOperationNone;
1656 /* We refuse to drop an item in anything else than a child of the General
1657 Node. We still accept items that would be root nodes of the outlineview
1658 however, to allow drop in an empty playlist. */
1659 if (!(([self isItem: [item pointerValue] inNode: p_playlist->p_local_category checkItemExistence: NO locked: NO] ||
1660 (var_CreateGetBool(p_playlist, "media-library") && [self isItem: [item pointerValue] inNode: p_playlist->p_ml_category checkItemExistence: NO locked: NO])) || item == nil)) {
1661 return NSDragOperationNone;
1664 /* Drop from the Playlist */
1665 if ([[o_pasteboard types] containsObject: @"VLCPlaylistItemPboardType"]) {
1666 NSUInteger count = [o_nodes_array count];
1667 for (NSUInteger i = 0 ; i < count ; i++) {
1668 /* We refuse to Drop in a child of an item we are moving */
1669 if ([self isItem: [item pointerValue] inNode: [[o_nodes_array objectAtIndex:i] pointerValue] checkItemExistence: NO locked:NO]) {
1670 return NSDragOperationNone;
1673 return NSDragOperationMove;
1675 /* Drop from the Finder */
1676 else if ([[o_pasteboard types] containsObject: NSFilenamesPboardType]) {
1677 return NSDragOperationGeneric;
1679 return NSDragOperationNone;
1682 - (BOOL)outlineView:(NSOutlineView *)outlineView acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(NSInteger)index
1684 playlist_t * p_playlist = pl_Get(VLCIntf);
1685 NSPasteboard *o_pasteboard = [info draggingPasteboard];
1687 /* Drag & Drop inside the playlist */
1688 if ([[o_pasteboard types] containsObject: @"VLCPlaylistItemPboardType"]) {
1689 if (index == -1) // this is no valid target, sanitize to top of table
1693 playlist_item_t *p_new_parent, *p_item = NULL;
1694 NSArray *o_all_items = [o_nodes_array arrayByAddingObjectsFromArray: o_items_array];
1695 /* If the item is to be dropped as root item of the outline, make it a
1696 child of the respective general node, if is either the pl or the ml
1697 Else, choose the proposed parent as parent. */
1699 if ([self currentPlaylistRoot] == p_playlist->p_local_category || [self currentPlaylistRoot] == p_playlist->p_ml_category)
1700 p_new_parent = [self currentPlaylistRoot];
1705 p_new_parent = [item pointerValue];
1707 /* Make sure the proposed parent is a node.
1708 (This should never be true) */
1709 if (p_new_parent->i_children < 0)
1712 NSUInteger count = [o_all_items count];
1716 playlist_item_t **pp_items = (playlist_item_t **)calloc(count, sizeof(playlist_item_t*));
1722 for (NSUInteger i = 0; i < count; i++) {
1723 p_item = [[o_all_items objectAtIndex:i] pointerValue];
1725 pp_items[j++] = p_item;
1728 if (j == 0 || playlist_TreeMoveMany(p_playlist, j, pp_items, p_new_parent, index) != VLC_SUCCESS) {
1737 [self playlistUpdated];
1738 i_row = [o_outline_view rowForItem:[o_outline_dict objectForKey:[NSString stringWithFormat: @"%p", [[o_all_items objectAtIndex:0] pointerValue]]]];
1741 i_row = [o_outline_view rowForItem:[o_outline_dict objectForKey:[NSString stringWithFormat: @"%p", p_new_parent]]];
1743 [o_outline_view deselectAll: self];
1744 [o_outline_view selectRowIndexes:[NSIndexSet indexSetWithIndex:i_row] byExtendingSelection:NO];
1745 [o_outline_view scrollRowToVisible: i_row];
1750 else if ([[o_pasteboard types] containsObject: NSFilenamesPboardType]) {
1751 if ([self currentPlaylistRoot] != p_playlist->p_local_category && [self currentPlaylistRoot] != p_playlist->p_ml_category)
1754 playlist_item_t *p_node = [item pointerValue];
1756 NSArray *o_values = [[o_pasteboard propertyListForType: NSFilenamesPboardType]
1757 sortedArrayUsingSelector: @selector(caseInsensitiveCompare:)];
1758 NSUInteger count = [o_values count];
1759 NSMutableArray *o_array = [NSMutableArray arrayWithCapacity:count];
1760 input_thread_t * p_input = pl_CurrentInput(VLCIntf);
1762 if (count == 1 && p_input) {
1763 int i_result = input_AddSubtitleOSD(p_input, vlc_path2uri([[o_values objectAtIndex:0] UTF8String], NULL), true, true);
1764 vlc_object_release(p_input);
1765 if (i_result == VLC_SUCCESS)
1769 vlc_object_release(p_input);
1771 for (NSUInteger i = 0; i < count; i++) {
1772 NSDictionary *o_dic;
1773 char *psz_uri = vlc_path2uri([[o_values objectAtIndex:i] UTF8String], NULL);
1777 o_dic = [NSDictionary dictionaryWithObject:[NSString stringWithCString:psz_uri encoding:NSUTF8StringEncoding] forKey:@"ITEM_URL"];
1781 [o_array addObject: o_dic];
1785 [self appendArray:o_array atPos:index enqueue: YES];
1787 assert(p_node->i_children != -1);
1788 [self appendNodeArray:o_array inNode: p_node atPos:index enqueue:YES];