/*****************************************************************************
* playlist.m: MacOS X interface module
*****************************************************************************
-* Copyright (C) 2002-2012 VLC authors and VideoLAN
+* Copyright (C) 2002-2014 VLC authors and VideoLAN
* $Id$
*
* Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
#include <math.h>
#include <sys/mount.h>
+#import "CompatibilityFixes.h"
+
#import "intf.h"
#import "wizard.h"
#import "bookmarks.h"
#import "misc.h"
#import "open.h"
#import "MainMenu.h"
+#import "CoreInteraction.h"
#include <vlc_keys.h>
-#import <vlc_osd.h>
#import <vlc_interface.h>
-
#include <vlc_url.h>
/*****************************************************************************
return NO;
}
-- (BOOL) acceptsFirstResponder
+- (BOOL)acceptsFirstResponder
{
return YES;
}
-- (BOOL) becomeFirstResponder
+- (BOOL)becomeFirstResponder
{
[self setNeedsDisplay:YES];
return YES;
}
-- (BOOL) resignFirstResponder
+- (BOOL)resignFirstResponder
{
[self setNeedsDisplay:YES];
return YES;
* This class the superclass of the VLCPlaylist and VLCPlaylistWizard.
* It contains the common methods and elements of these 2 entities.
*****************************************************************************/
+@interface VLCPlaylistCommon ()
+{
+ playlist_item_t * p_current_root_item;
+}
+@end
+
@implementation VLCPlaylistCommon
- (id)init
[o_outline_view setAllowsEmptySelection: NO];
[o_outline_view expandItem: [o_outline_view itemAtRow:0]];
- [o_outline_view_other setTarget: self];
- [o_outline_view_other setDelegate: self];
- [o_outline_view_other setDataSource: self];
- [o_outline_view_other setAllowsEmptySelection: NO];
-
- [[o_tc_name_other headerCell] setStringValue:_NS("Name")];
- [[o_tc_author_other headerCell] setStringValue:_NS("Author")];
- [[o_tc_duration_other headerCell] setStringValue:_NS("Duration")];
+ [self reloadStyles];
}
- (void)setPlaylistRoot: (playlist_item_t *)root_item
{
p_current_root_item = root_item;
[o_outline_view reloadData];
- [o_outline_view_other reloadData];
}
- (playlist_item_t *)currentPlaylistRoot
pointerValue];
}
+- (void)reloadStyles
+{
+ NSFont *fontToUse;
+ CGFloat rowHeight;
+ if (config_GetInt(VLCIntf, "macosx-large-text")) {
+ fontToUse = [NSFont systemFontOfSize:13.];
+ rowHeight = 21.;
+ } else {
+ fontToUse = [NSFont systemFontOfSize:11.];
+ rowHeight = 16.;
+ }
+
+ NSArray *columns = [o_outline_view tableColumns];
+ NSUInteger count = columns.count;
+ for (NSUInteger x = 0; x < count; x++)
+ [[[columns objectAtIndex:x] dataCell] setFont:fontToUse];
+ [o_outline_view setRowHeight:rowHeight];
+}
+
+- (void)dealloc {
+ [o_outline_dict release];
+ [super dealloc];
+}
+
@end
@implementation VLCPlaylistCommon (NSOutlineViewDataSource)
if ([o_identifier isEqualToString:TRACKNUM_COLUMN]) {
psz_value = input_item_GetTrackNumber(p_item->p_input);
if (psz_value) {
- o_value = [NSString stringWithUTF8String: psz_value];
+ o_value = [NSString stringWithUTF8String:psz_value];
free(psz_value);
}
} else if ([o_identifier isEqualToString:TITLE_COLUMN]) {
/* sanity check to prevent the NSString class from crashing */
char *psz_title = input_item_GetTitleFbName(p_item->p_input);
if (psz_title) {
- o_value = [NSString stringWithUTF8String: psz_title];
+ o_value = [NSString stringWithUTF8String:psz_title];
free(psz_title);
}
} else if ([o_identifier isEqualToString:ARTIST_COLUMN]) {
psz_value = input_item_GetArtist(p_item->p_input);
if (psz_value) {
- o_value = [NSString stringWithUTF8String: psz_value];
+ o_value = [NSString stringWithUTF8String:psz_value];
free(psz_value);
}
} else if ([o_identifier isEqualToString:@"duration"]) {
mtime_t dur = input_item_GetDuration(p_item->p_input);
if (dur != -1) {
secstotimestr(psz_duration, dur/1000000);
- o_value = [NSString stringWithUTF8String: psz_duration];
+ o_value = [NSString stringWithUTF8String:psz_duration];
}
else
o_value = @"--:--";
} else if ([o_identifier isEqualToString:GENRE_COLUMN]) {
psz_value = input_item_GetGenre(p_item->p_input);
if (psz_value) {
- o_value = [NSString stringWithUTF8String: psz_value];
+ o_value = [NSString stringWithUTF8String:psz_value];
free(psz_value);
}
} else if ([o_identifier isEqualToString:ALBUM_COLUMN]) {
psz_value = input_item_GetAlbum(p_item->p_input);
if (psz_value) {
- o_value = [NSString stringWithUTF8String: psz_value];
+ o_value = [NSString stringWithUTF8String:psz_value];
free(psz_value);
}
} else if ([o_identifier isEqualToString:DESCRIPTION_COLUMN]) {
psz_value = input_item_GetDescription(p_item->p_input);
if (psz_value) {
- o_value = [NSString stringWithUTF8String: psz_value];
+ o_value = [NSString stringWithUTF8String:psz_value];
free(psz_value);
}
} else if ([o_identifier isEqualToString:DATE_COLUMN]) {
psz_value = input_item_GetDate(p_item->p_input);
if (psz_value) {
- o_value = [NSString stringWithUTF8String: psz_value];
+ o_value = [NSString stringWithUTF8String:psz_value];
free(psz_value);
}
} else if ([o_identifier isEqualToString:LANGUAGE_COLUMN]) {
psz_value = input_item_GetLanguage(p_item->p_input);
if (psz_value) {
- o_value = [NSString stringWithUTF8String: psz_value];
+ o_value = [NSString stringWithUTF8String:psz_value];
free(psz_value);
}
}
else if ([o_identifier isEqualToString:URI_COLUMN]) {
psz_value = decode_URI(input_item_GetURI(p_item->p_input));
if (psz_value) {
- o_value = [NSString stringWithUTF8String: psz_value];
+ o_value = [NSString stringWithUTF8String:psz_value];
+ free(psz_value);
+ }
+ }
+ else if ([o_identifier isEqualToString:FILESIZE_COLUMN]) {
+ psz_value = input_item_GetURI(p_item->p_input);
+ o_value = @"";
+ if (psz_value) {
+ NSURL *url = [NSURL URLWithString:[NSString stringWithUTF8String:psz_value]];
+ if ([url isFileURL]) {
+ NSFileManager *fileManager = [NSFileManager defaultManager];
+ if ([fileManager fileExistsAtPath:[url path]]) {
+ NSError *error;
+ NSDictionary *attributes = [fileManager attributesOfItemAtPath:[url path] error:&error];
+ o_value = [VLCByteCountFormatter stringFromByteCount:[attributes fileSize] countStyle:NSByteCountFormatterCountStyleDecimal];
+ }
+ }
free(psz_value);
}
}
/*****************************************************************************
* VLCPlaylist implementation
*****************************************************************************/
+@interface VLCPlaylist ()
+{
+ NSImage *o_descendingSortingImage;
+ NSImage *o_ascendingSortingImage;
+
+ NSMutableArray *o_nodes_array;
+ NSMutableArray *o_items_array;
+
+ BOOL b_selected_item_met;
+ BOOL b_isSortDescending;
+ id o_tc_sortColumn;
+ NSUInteger retainedRowSelection;
+
+ BOOL b_playlistmenu_nib_loaded;
+ BOOL b_view_setup;
+}
+
+- (void)saveTableColumns;
+@end
+
@implementation VLCPlaylist
-+ (void)initialize{
++ (void)initialize
+{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
- NSMutableArray * o_columnArray = [[NSMutableArray alloc] init];
- [o_columnArray addObject: [NSArray arrayWithObjects: TITLE_COLUMN, [NSNumber numberWithFloat: 190.], nil]];
- [o_columnArray addObject: [NSArray arrayWithObjects: ARTIST_COLUMN, [NSNumber numberWithFloat: 95.], nil]];
- [o_columnArray addObject: [NSArray arrayWithObjects: DURATION_COLUMN, [NSNumber numberWithFloat: 95.], nil]];
- NSDictionary *appDefaults = [NSDictionary dictionaryWithObject:[NSArray arrayWithArray:o_columnArray] forKey:@"PlaylistColumnSelection"];
+ NSMutableArray *o_columnArray = [[NSMutableArray alloc] init];
+ [o_columnArray addObject: [NSArray arrayWithObjects:TITLE_COLUMN, [NSNumber numberWithFloat:190.], nil]];
+ [o_columnArray addObject: [NSArray arrayWithObjects:ARTIST_COLUMN, [NSNumber numberWithFloat:95.], nil]];
+ [o_columnArray addObject: [NSArray arrayWithObjects:DURATION_COLUMN, [NSNumber numberWithFloat:95.], nil]];
+
+ NSDictionary *appDefaults = [NSDictionary dictionaryWithObjectsAndKeys:
+ [NSArray arrayWithArray:o_columnArray], @"PlaylistColumnSelection",
+ [NSArray array], @"recentlyPlayedMediaList",
+ [NSDictionary dictionary], @"recentlyPlayedMedia", nil];
[defaults registerDefaults:appDefaults];
[o_columnArray release];
- (void)awakeFromNib
{
+ if (b_view_setup)
+ return;
+
playlist_t * p_playlist = pl_Get(VLCIntf);
[super awakeFromNib];
+ [self initStrings];
[o_outline_view setDoubleAction: @selector(playItem:)];
- [o_outline_view_other setDoubleAction: @selector(playItem:)];
- [o_outline_view registerForDraggedTypes:
- [NSArray arrayWithObjects: NSFilenamesPboardType,
- @"VLCPlaylistItemPboardType", nil]];
+ [o_outline_view registerForDraggedTypes: [NSArray arrayWithObjects:NSFilenamesPboardType, @"VLCPlaylistItemPboardType", nil]];
[o_outline_view setIntercellSpacing: NSMakeSize (0.0, 1.0)];
- [o_outline_view_other registerForDraggedTypes:
- [NSArray arrayWithObjects: NSFilenamesPboardType,
- @"VLCPlaylistItemPboardType", nil]];
- [o_outline_view_other setIntercellSpacing: NSMakeSize (0.0, 1.0)];
-
/* This uses a private API, but works fine on all current OSX releases.
* Radar ID 11739459 request a public API for this. However, it is probably
* easier and faster to recreate similar looking bitmaps ourselves. */
if ([o_column isEqualToString:@"status"])
continue;
- [o_menu setPlaylistColumnTableState: NSOnState forColumn: o_column];
+ if(![o_menu setPlaylistColumnTableState: NSOnState forColumn: o_column])
+ continue;
+
[[o_outline_view tableColumnWithIdentifier: o_column] setWidth: [[[o_columnArray objectAtIndex:i] objectAtIndex:1] floatValue]];
}
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(applicationWillTerminate:) name: NSApplicationWillTerminateNotification object: nil];
+
+ b_view_setup = YES;
}
- (void)applicationWillTerminate:(NSNotification *)notification
- (void)initStrings
{
- [o_mi_save_playlist setTitle: _NS("Save Playlist...")];
[o_mi_play setTitle: _NS("Play")];
[o_mi_delete setTitle: _NS("Delete")];
[o_mi_recursive_expand setTitle: _NS("Expand Node")];
[o_mi_sort_author setTitle: _NS("Sort Node by Author")];
[o_search_field setToolTip: _NS("Search in Playlist")];
- [o_search_field_other setToolTip: _NS("Search in Playlist")];
-
- [o_save_accessory_text setStringValue: _NS("File Format:")];
- [[o_save_accessory_popup itemAtIndex:0] setTitle: _NS("Extended M3U")];
- [[o_save_accessory_popup itemAtIndex:1] setTitle: _NS("XML Shareable Playlist Format (XSPF)")];
- [[o_save_accessory_popup itemAtIndex:2] setTitle: _NS("HTML Playlist")];
}
- (void)playlistUpdated
//[o_outline_dict removeAllObjects];
[o_outline_view reloadData];
[[[[VLCMain sharedInstance] wizard] playlistWizard] reloadOutlineView];
- [[[[VLCMain sharedInstance] bookmarks] dataTable] reloadData];
+
+ [o_outline_view selectRowIndexes:[NSIndexSet indexSetWithIndex:retainedRowSelection] byExtendingSelection:NO];
[self outlineViewSelectionDidChange: nil];
[[VLCMain sharedInstance] updateMainWindow];
NSSavePanel *o_save_panel = [NSSavePanel savePanel];
NSString * o_name = [NSString stringWithFormat: @"%@", _NS("Untitled")];
+ [NSBundle loadNibNamed:@"PlaylistAccessoryView" owner:self];
+
+ [o_save_accessory_text setStringValue: _NS("File Format:")];
+ [[o_save_accessory_popup itemAtIndex:0] setTitle: _NS("Extended M3U")];
+ [[o_save_accessory_popup itemAtIndex:1] setTitle: _NS("XML Shareable Playlist Format (XSPF)")];
+ [[o_save_accessory_popup itemAtIndex:2] setTitle: _NS("HTML playlist")];
+
[o_save_panel setTitle: _NS("Save Playlist")];
[o_save_panel setPrompt: _NS("Save")];
[o_save_panel setAccessoryView: o_save_accessory_view];
else
p_item = NULL;
}
+
playlist_Control(p_playlist, PLAYLIST_VIEWPLAY, pl_Locked, p_node, p_item);
}
PL_UNLOCK;
if (! p_item || !p_item->p_input)
continue;
- o_mrl = [[NSMutableString alloc] initWithFormat: @"%s", decode_URI(input_item_GetURI(p_item->p_input))];
+ char * psz_url = decode_URI(input_item_GetURI(p_item->p_input));
+ o_mrl = [[NSMutableString alloc] initWithString: [NSString stringWithUTF8String:psz_url ? psz_url : ""]];
+ if (psz_url != NULL)
+ free( psz_url );
/* perform some checks whether it is a file and if it is local at all... */
if ([o_mrl length] > 0) {
if (p_item) {
if (p_item->i_children == -1)
- playlist_PreparseEnqueue(p_playlist, p_item->p_input);
+ libvlc_MetaRequest(p_intf->p_libvlc, p_item->p_input, META_REQUEST_OPTION_NONE);
else
msg_Dbg(p_intf, "preparsing nodes not implemented");
}
p_item = [[o_outline_view itemAtRow: indexes[i]] pointerValue];
if (p_item && p_item->i_children == -1)
- playlist_AskForArtEnqueue(p_playlist, p_item->p_input);
+ libvlc_ArtRequest(p_intf->p_libvlc, p_item->p_input, META_REQUEST_OPTION_NONE);
}
[self playlistUpdated];
}
[o_outline_view selectAll: nil];
}
+- (IBAction)showInfoPanel:(id)sender
+{
+ [[[VLCMain sharedInstance] info] initPanel];
+}
+
- (IBAction)deleteItem:(id)sender
{
int i_count;
NSIndexSet *o_selected_indexes;
- playlist_t * p_playlist;
intf_thread_t * p_intf = VLCIntf;
+ playlist_t * p_playlist = pl_Get(p_intf);
+
+ // check if deletion is allowed
+ if ([self currentPlaylistRoot] != p_playlist->p_local_category && [self currentPlaylistRoot] != p_playlist->p_ml_category)
+ return;
o_selected_indexes = [o_outline_view selectedRowIndexes];
i_count = [o_selected_indexes count];
+ retainedRowSelection = [o_selected_indexes firstIndex];
+ if (retainedRowSelection == NSNotFound)
+ retainedRowSelection = 0;
- p_playlist = pl_Get(p_intf);
NSUInteger indexes[i_count];
if (i_count == [o_outline_view numberOfRows]) {
-#ifndef NDEBUG
- msg_Dbg(p_intf, "user selected entire list, deleting current playlist root instead of individual items");
-#endif
PL_LOCK;
playlist_NodeDelete(p_playlist, [self currentPlaylistRoot], true, false);
PL_UNLOCK;
PL_UNLOCK;
continue;
}
-#ifndef NDEBUG
- msg_Dbg(p_intf, "deleting item %i (of %i) with id \"%i\", pointerValue \"%p\" and %i children", i+1, i_count,
- p_item->p_input->i_id, [o_item pointerValue], p_item->i_children +1);
-#endif
if (p_item->i_children != -1) {
//is a node and not an item
if ([[NSFileManager defaultManager] fileExistsAtPath:o_path isDirectory:&b_dir] && b_dir &&
[[NSWorkspace sharedWorkspace] getFileSystemInfoForPath:o_path isRemovable: &b_rem
isWritable:&b_writable isUnmountable:NULL description:NULL type:NULL] && b_rem && !b_writable && [o_nsurl isFileURL]) {
- id o_vlc_open = [[VLCMain sharedInstance] open];
- NSString *diskType = [o_vlc_open getVolumeTypeFromMountPath: o_path];
+ NSString *diskType = [VLCOpen getVolumeTypeFromMountPath: o_path];
msg_Dbg(p_intf, "detected optical media of type %s in the file input", [diskType UTF8String]);
if ([diskType isEqualToString: kVLCMediaDVD])
- o_uri = [NSString stringWithFormat: @"dvdnav://%@", [o_vlc_open getBSDNodeFromMountPath: o_path]];
+ o_uri = [NSString stringWithFormat: @"dvdnav://%@", [VLCOpen getBSDNodeFromMountPath: o_path]];
else if ([diskType isEqualToString: kVLCMediaVideoTSFolder])
o_uri = [NSString stringWithFormat: @"dvdnav://%@", o_path];
else if ([diskType isEqualToString: kVLCMediaAudioCD])
- o_uri = [NSString stringWithFormat: @"cdda://%@", [o_vlc_open getBSDNodeFromMountPath: o_path]];
+ o_uri = [NSString stringWithFormat: @"cdda://%@", [VLCOpen getBSDNodeFromMountPath: o_path]];
else if ([diskType isEqualToString: kVLCMediaVCD])
- o_uri = [NSString stringWithFormat: @"vcd://%@#0:0", [o_vlc_open getBSDNodeFromMountPath: o_path]];
+ o_uri = [NSString stringWithFormat: @"vcd://%@#0:0", [VLCOpen getBSDNodeFromMountPath: o_path]];
else if ([diskType isEqualToString: kVLCMediaSVCD])
- o_uri = [NSString stringWithFormat: @"vcd://%@@0:0", [o_vlc_open getBSDNodeFromMountPath: o_path]];
+ o_uri = [NSString stringWithFormat: @"vcd://%@@0:0", [VLCOpen getBSDNodeFromMountPath: o_path]];
else if ([diskType isEqualToString: kVLCMediaBD] || [diskType isEqualToString: kVLCMediaBDMVFolder])
o_uri = [NSString stringWithFormat: @"bluray://%@", o_path];
else
NSDictionary *o_one_item;
/* Get the item */
- o_one_item = [o_array objectAtIndex: i_item];
+ o_one_item = [o_array objectAtIndex:i_item];
p_input = [self createItem: o_one_item];
if (!p_input)
continue;
NSDictionary *o_one_item;
/* Get the item */
- o_one_item = [o_array objectAtIndex: i_item];
+ PL_LOCK;
+ o_one_item = [o_array objectAtIndex:i_item];
p_input = [self createItem: o_one_item];
if (!p_input)
continue;
/* Add the item */
- PL_LOCK;
playlist_NodeAddInput(p_playlist, p_input, p_node,
PLAYLIST_INSERT,
i_position == -1 ?
NSString *o_current_name, *o_current_author;
PL_LOCK;
- o_current_name = [NSString stringWithUTF8String:
- p_item->pp_children[i_current]->p_input->psz_name];
- psz_temp = input_item_GetInfo(p_item->p_input ,
- _("Meta-information"),_("Artist"));
- o_current_author = [NSString stringWithUTF8String: psz_temp];
+ o_current_name = [NSString stringWithUTF8String:p_item->pp_children[i_current]->p_input->psz_name];
+ psz_temp = input_item_GetInfo(p_item->p_input, _("Meta-information"),_("Artist"));
+ o_current_author = [NSString stringWithUTF8String:psz_temp];
free(psz_temp);
PL_UNLOCK;
if (o_result != NULL) {
int i_start;
- if ([[o_result objectAtIndex: 0] pointerValue] == p_playlist->p_local_category)
+ if ([[o_result objectAtIndex:0] pointerValue] == p_playlist->p_local_category)
i_start = 1;
else
i_start = 0;
for (NSUInteger i = i_start ; i < count - 1 ; i++) {
[o_outline_view expandItem: [o_outline_dict objectForKey:
[NSString stringWithFormat: @"%p",
- [[o_result objectAtIndex: i] pointerValue]]]];
+ [[o_result objectAtIndex:i] pointerValue]]]];
}
i_row = [o_outline_view rowForItem: [o_outline_dict objectForKey:
[NSString stringWithFormat: @"%p",
- [[o_result objectAtIndex: count - 1 ]
+ [[o_result objectAtIndex:count - 1 ]
pointerValue]]]];
}
if (i_row > -1) {
- (NSMenu *)menuForEvent:(NSEvent *)o_event
{
+ if (!b_playlistmenu_nib_loaded)
+ b_playlistmenu_nib_loaded = [NSBundle loadNibNamed:@"PlaylistMenu" owner:self];
+
NSPoint pt;
bool b_rows;
bool b_item_sel;
b_item_sel = (row != -1 && [o_outline_view selectedRow] != -1);
b_rows = [o_outline_view numberOfRows] != 0;
+ playlist_t *p_playlist = pl_Get(VLCIntf);
+ bool b_del_allowed = [self currentPlaylistRoot] == p_playlist->p_local_category || [self currentPlaylistRoot] == p_playlist->p_ml_category;
+
[o_mi_play setEnabled: b_item_sel];
- [o_mi_delete setEnabled: b_item_sel];
+ [o_mi_delete setEnabled: b_item_sel && b_del_allowed];
[o_mi_selectall setEnabled: b_rows];
[o_mi_info setEnabled: b_item_sel];
[o_mi_preparse setEnabled: b_item_sel];
[o_mi_sort_name setEnabled: b_item_sel];
[o_mi_sort_author setEnabled: b_item_sel];
- return(o_ctx_menu);
+ return o_ctx_menu;
}
- (void)outlineView: (NSOutlineView *)o_tv didClickTableColumn:(NSTableColumn *)o_tc
o_playing_item = [o_outline_dict objectForKey: [NSString stringWithFormat:@"%p", playlist_CurrentPlayingItem(p_playlist)]];
PL_UNLOCK;
+ NSFont *fontToUse;
+ if (config_GetInt(VLCIntf, "macosx-large-text"))
+ fontToUse = [NSFont systemFontOfSize:13.];
+ else
+ fontToUse = [NSFont systemFontOfSize:11.];
+
if ([self isItem: [o_playing_item pointerValue] inNode: [item pointerValue] checkItemExistence:YES locked:NO]
|| [o_playing_item isEqual: item])
- [cell setFont: [[NSFontManager sharedFontManager] convertFont:[cell font] toHaveTrait:NSBoldFontMask]];
+ [cell setFont: [[NSFontManager sharedFontManager] convertFont:fontToUse toHaveTrait:NSBoldFontMask]];
else
- [cell setFont: [[NSFontManager sharedFontManager] convertFont:[cell font] toNotHaveTrait:NSBoldFontMask]];
+ [cell setFont: [[NSFontManager sharedFontManager] convertFont:fontToUse toNotHaveTrait:NSBoldFontMask]];
}
- (id)playingItem
NSTableColumn * o_work_tc;
if (i_state == NSOnState) {
+ NSString *o_title = [o_dict objectForKey:o_column];
+ if (!o_title)
+ return;
+
o_work_tc = [[NSTableColumn alloc] initWithIdentifier: o_column];
[o_work_tc setEditable: NO];
[[o_work_tc dataCell] setFont: [NSFont controlContentFontOfSize:11.]];
}
else
[o_outline_view removeTableColumn: [o_outline_view tableColumnWithIdentifier: o_column]];
+
+ [o_outline_view setOutlineTableColumn: [o_outline_view tableColumnWithIdentifier:TITLE_COLUMN]];
}
- (void)saveTableColumns
NSUInteger count = [o_columns count];
NSTableColumn * o_currentColumn;
for (NSUInteger i = 0; i < count; i++) {
- o_currentColumn = [o_columns objectAtIndex: i];
- [o_arrayToSave addObject: [NSArray arrayWithObjects: [o_currentColumn identifier], [NSNumber numberWithFloat: [o_currentColumn width]], nil]];
+ o_currentColumn = [o_columns objectAtIndex:i];
+ [o_arrayToSave addObject:[NSArray arrayWithObjects:[o_currentColumn identifier], [NSNumber numberWithFloat:[o_currentColumn width]], nil]];
}
[[NSUserDefaults standardUserDefaults] setObject: o_arrayToSave forKey:@"PlaylistColumnSelection"];
[[NSUserDefaults standardUserDefaults] synchronize];
[o_arrayToSave release];
}
+- (BOOL)isValidResumeItem:(input_item_t *)p_item
+{
+ char *psz_url = input_item_GetURI(p_item);
+ NSString *o_url_string = toNSStr(psz_url);
+ free(psz_url);
+
+ if ([o_url_string isEqualToString:@""])
+ return NO;
+
+ NSURL *o_url = [NSURL URLWithString:o_url_string];
+
+ if (![o_url isFileURL])
+ return NO;
+
+ BOOL isDir = false;
+ if (![[NSFileManager defaultManager] fileExistsAtPath:[o_url path] isDirectory:&isDir])
+ return NO;
+
+ if (isDir)
+ return NO;
+
+ return YES;
+}
+
+- (void)updateAlertWindow:(NSTimer *)timer
+{
+ NSAlert *alert = [timer userInfo];
+
+ --currentResumeTimeout;
+ if (currentResumeTimeout <= 0) {
+ [[alert window] close];
+ [NSApp abortModal];
+ }
+
+ NSString *buttonLabel = _NS("Restart playback");
+ buttonLabel = [buttonLabel stringByAppendingFormat:@" (%d)", currentResumeTimeout];
+
+ [[[alert buttons] objectAtIndex:2] setTitle:buttonLabel];
+}
+
+- (void)continuePlaybackWhereYouLeftOff:(input_thread_t *)p_input_thread
+{
+ NSDictionary *recentlyPlayedFiles = [[NSUserDefaults standardUserDefaults] objectForKey:@"recentlyPlayedMedia"];
+ if (!recentlyPlayedFiles)
+ return;
+
+ input_item_t *p_item = input_GetItem(p_input_thread);
+ if (!p_item)
+ return;
+
+ /* allow the user to over-write the start/stop/run-time */
+ if (var_GetFloat(p_input_thread, "run-time") > 0 ||
+ var_GetFloat(p_input_thread, "start-time") > 0 ||
+ var_GetFloat(p_input_thread, "stop-time") > 0) {
+ return;
+ }
+
+ /* check for file existance before resuming */
+ if (![self isValidResumeItem:p_item])
+ return;
+
+ char *psz_url = decode_URI(input_item_GetURI(p_item));
+ if (!psz_url)
+ return;
+ NSString *url = toNSStr(psz_url);
+ free(psz_url);
+
+ NSNumber *lastPosition = [recentlyPlayedFiles objectForKey:url];
+ if (!lastPosition || lastPosition.intValue <= 0)
+ return;
+
+ int settingValue = config_GetInt(VLCIntf, "macosx-continue-playback");
+ if (settingValue == 2) // never resume
+ return;
+
+ NSInteger returnValue = NSAlertErrorReturn;
+ if (settingValue == 0) { // ask
+ 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]];
+
+ currentResumeTimeout = 6;
+ NSTimer *timer = [NSTimer timerWithTimeInterval:1
+ target:self
+ selector:@selector(updateAlertWindow:)
+ userInfo:theAlert
+ repeats:YES];
+
+ [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSModalPanelRunLoopMode];
+
+ [[VLCCoreInteraction sharedInstance] pause];
+ returnValue = [theAlert runModal];
+ [timer invalidate];
+ [[VLCCoreInteraction sharedInstance] playOrPause];
+
+ // restart button was pressed or timeout happened
+ if (returnValue == NSAlertAlternateReturn ||
+ returnValue == NSRunAbortedResponse)
+ return;
+ }
+
+ mtime_t lastPos = (mtime_t)lastPosition.intValue * 1000000;
+ msg_Dbg(VLCIntf, "continuing playback at %lld", lastPos);
+ var_SetTime(p_input_thread, "time", lastPos);
+
+ if (returnValue == NSAlertOtherReturn)
+ config_PutInt(VLCIntf, "macosx-continue-playback", 1);
+}
+
+- (void)storePlaybackPositionForItem:(input_thread_t *)p_input_thread
+{
+ if (!var_InheritBool(VLCIntf, "macosx-recentitems"))
+ return;
+
+ input_item_t *p_item = input_GetItem(p_input_thread);
+ if (!p_item)
+ return;
+
+ if (![self isValidResumeItem:p_item])
+ return;
+
+ char *psz_url = decode_URI(input_item_GetURI(p_item));
+ if (!psz_url)
+ return;
+ NSString *url = toNSStr(psz_url);
+ free(psz_url);
+
+ NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
+ NSMutableDictionary *mutDict = [[NSMutableDictionary alloc] initWithDictionary:[defaults objectForKey:@"recentlyPlayedMedia"]];
+
+ float relativePos = var_GetFloat(p_input_thread, "position");
+ mtime_t pos = var_GetTime(p_input_thread, "time") / 1000000;
+ mtime_t dur = input_item_GetDuration(p_item) / 1000000;
+
+ NSMutableArray *mediaList = [[defaults objectForKey:@"recentlyPlayedMediaList"] mutableCopy];
+
+ if (relativePos > .05 && relativePos < .95 && dur > 180) {
+ [mutDict setObject:[NSNumber numberWithInt:pos] forKey:url];
+
+ [mediaList removeObject:url];
+ [mediaList addObject:url];
+ NSUInteger mediaListCount = mediaList.count;
+ if (mediaListCount > 30) {
+ for (NSUInteger x = 0; x < mediaListCount - 30; x++) {
+ [mutDict removeObjectForKey:[mediaList objectAtIndex:0]];
+ [mediaList removeObjectAtIndex:0];
+ }
+ }
+ } else {
+ [mutDict removeObjectForKey:url];
+ [mediaList removeObject:url];
+ }
+ [defaults setObject:mutDict forKey:@"recentlyPlayedMedia"];
+ [defaults setObject:mediaList forKey:@"recentlyPlayedMediaList"];
+ [defaults synchronize];
+
+ [mutDict release];
+ [mediaList release];
+}
+
@end
@implementation VLCPlaylist (NSOutlineViewDataSource)
NSUInteger itemCount = [items count];
for (NSUInteger i = 0 ; i < itemCount ; i++) {
- id o_item = [items objectAtIndex: i];
+ id o_item = [items objectAtIndex:i];
/* Fill the items and nodes to move in 2 different arrays */
if (((playlist_item_t *)[o_item pointerValue])->i_children > 0)
/* We add the "VLCPlaylistItemPboardType" type to be able to recognize
a Drop operation coming from the playlist. */
- [pboard declareTypes: [NSArray arrayWithObjects:
- @"VLCPlaylistItemPboardType", nil] owner: self];
+ [pboard declareTypes: [NSArray arrayWithObject:@"VLCPlaylistItemPboardType"] owner: self];
[pboard setData:[NSData data] forType:@"VLCPlaylistItemPboardType"];
return YES;
NSUInteger count = [o_nodes_array count];
for (NSUInteger i = 0 ; i < count ; i++) {
/* We refuse to Drop in a child of an item we are moving */
- if ([self isItem: [item pointerValue] inNode: [[o_nodes_array objectAtIndex: i] pointerValue] checkItemExistence: NO locked:NO]) {
+ if ([self isItem: [item pointerValue] inNode: [[o_nodes_array objectAtIndex:i] pointerValue] checkItemExistence: NO locked:NO]) {
return NSDragOperationNone;
}
}
/* Drag & Drop inside the playlist */
if ([[o_pasteboard types] containsObject: @"VLCPlaylistItemPboardType"]) {
+ if (index == -1) // this is no valid target, sanitize to top of table
+ index = 0;
+
int i_row = 0;
playlist_item_t *p_new_parent, *p_item = NULL;
NSArray *o_all_items = [o_nodes_array arrayByAddingObjectsFromArray: o_items_array];
free(pp_items);
[self playlistUpdated];
- i_row = [o_outline_view rowForItem:[o_outline_dict objectForKey:[NSString stringWithFormat: @"%p", [[o_all_items objectAtIndex: 0] pointerValue]]]];
+ i_row = [o_outline_view rowForItem:[o_outline_dict objectForKey:[NSString stringWithFormat: @"%p", [[o_all_items objectAtIndex:0] pointerValue]]]];
if (i_row == -1)
i_row = [o_outline_view rowForItem:[o_outline_dict objectForKey:[NSString stringWithFormat: @"%p", p_new_parent]]];
NSUInteger count = [o_values count];
NSMutableArray *o_array = [NSMutableArray arrayWithCapacity:count];
input_thread_t * p_input = pl_CurrentInput(VLCIntf);
- BOOL b_returned = NO;
if (count == 1 && p_input) {
- b_returned = input_AddSubtitle(p_input, vlc_path2uri([[o_values objectAtIndex:0] UTF8String], NULL), true);
+ int i_result = input_AddSubtitleOSD(p_input, vlc_path2uri([[o_values objectAtIndex:0] UTF8String], NULL), true, true);
vlc_object_release(p_input);
- if (!b_returned)
+ if (i_result == VLC_SUCCESS)
return YES;
}
else if (p_input)