#endif
#include <stdlib.h> /* malloc(), free() */
-#include <sys/param.h> /* for MAXPATHLEN */
#include <string.h>
#include <vlc_common.h>
#include <vlc_keys.h>
#import "CompatibilityFixes.h"
#import "intf.h"
-#import "StringUtility.h"
#import "MainMenu.h"
#import "VideoView.h"
#import "prefs.h"
#import "simple_prefs.h"
#import "CoreInteraction.h"
#import "TrackSynchronization.h"
-#import "VLCVoutWindowController.h"
#import "ExtensionsManager.h"
-#import "CrashReporter.h"
+#import "BWQuincyManager.h"
+#import "ControlsBar.h"
#import "VideoEffects.h"
#import "AudioEffects.h"
#import <Sparkle/Sparkle.h> /* we're the update delegate */
#import "iTunes.h"
+#import "Spotify.h"
/*****************************************************************************
* Local prototypes.
vlc_value_t, vlc_value_t, void *);
static int PLItemChanged(vlc_object_t *, const char *,
vlc_value_t, vlc_value_t, void *);
-static int PlaylistUpdated(vlc_object_t *, const char *,
- vlc_value_t, vlc_value_t, void *);
+static int PLItemUpdated(vlc_object_t *, const char *,
+ vlc_value_t, vlc_value_t, void *);
+
static int PlaybackModeUpdated(vlc_object_t *, const char *,
vlc_value_t, vlc_value_t, void *);
static int VolumeUpdated(vlc_object_t *, const char *,
[VLCApplication sharedApplication];
intf_thread_t *p_intf = (intf_thread_t*) p_this;
-
- p_intf->p_sys = malloc(sizeof(intf_sys_t));
- if (p_intf->p_sys == NULL)
- return VLC_ENOMEM;
-
- memset(p_intf->p_sys, 0, sizeof(*p_intf->p_sys));
-
Run(p_intf);
[o_pool release];
return VLC_SUCCESS;
}
-/*****************************************************************************
- * CloseIntf: destroy interface
- *****************************************************************************/
-void CloseIntf (vlc_object_t *p_this)
-{
- intf_thread_t *p_intf = (intf_thread_t*) p_this;
-
- free(p_intf->p_sys);
-}
-
static NSLock * o_vout_provider_lock = nil;
static int WindowControl(vout_window_t *, int i_query, va_list);
int WindowOpen(vout_window_t *p_wnd, const vout_window_cfg_t *cfg)
{
+ if (cfg->type != VOUT_WINDOW_TYPE_INVALID
+ && cfg->type != VOUT_WINDOW_TYPE_NSOBJECT)
+ return VLC_EGENERIC;
+
NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
intf_thread_t *p_intf = VLCIntf;
if (!p_intf) {
VLCVoutView *videoView = nil;
[inv getReturnValue:&videoView];
- if (!videoView) {
- msg_Err(p_wnd, "got no video view from the interface");
- [o_vout_provider_lock unlock];
- [o_pool release];
- return VLC_EGENERIC;
- }
+ // this method is not supposed to fail
+ assert(videoView != nil);
msg_Dbg(VLCIntf, "returning videoview with proposed position x=%i, y=%i, width=%i, height=%i", cfg->x, cfg->y, cfg->width, cfg->height);
p_wnd->handle.nsobject = videoView;
[o_vout_provider_lock unlock];
- [[VLCMain sharedInstance] setActiveVideoPlayback: YES];
+ p_wnd->type = VOUT_WINDOW_TYPE_NSOBJECT;
p_wnd->control = WindowControl;
[o_pool release];
{
unsigned i_state = va_arg(args, unsigned);
+ if (i_state & VOUT_WINDOW_STATE_BELOW)
+ {
+ msg_Dbg(p_wnd, "Ignore change to VOUT_WINDOW_STATE_BELOW");
+ goto out;
+ }
+
NSInteger i_cooca_level = NSNormalWindowLevel;
if (i_state & VOUT_WINDOW_STATE_ABOVE)
i_cooca_level = NSStatusWindowLevel;
}
case VOUT_WINDOW_SET_SIZE:
{
-
unsigned int i_width = va_arg(args, unsigned int);
unsigned int i_height = va_arg(args, unsigned int);
}
case VOUT_WINDOW_SET_FULLSCREEN:
{
- NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
+ if (var_InheritBool(VLCIntf, "video-wallpaper")) {
+ msg_Dbg(p_wnd, "Ignore fullscreen event as video-wallpaper is on");
+ goto out;
+ }
+
int i_full = va_arg(args, int);
+ BOOL b_animation = YES;
- SEL sel = @selector(setFullscreen:forWindow:);
+ SEL sel = @selector(setFullscreen:forWindow:withAnimation:);
NSInvocation *inv = [NSInvocation invocationWithMethodSignature:[o_vout_controller methodSignatureForSelector:sel]];
[inv setTarget:o_vout_controller];
[inv setSelector:sel];
[inv setArgument:&i_full atIndex:2]; // starting at 2!
[inv setArgument:&p_wnd atIndex:3];
+ [inv setArgument:&b_animation atIndex:4];
[inv performSelectorOnMainThread:@selector(invoke) withObject:nil
waitUntilDone:NO];
}
}
+out:
[o_vout_provider_lock unlock];
[o_pool release];
return VLC_SUCCESS;
[o_pool release];
}
+/* Used to abort the app.exec() on OSX after libvlc_Quit is called */
+#include "../../../lib/libvlc_internal.h" /* libvlc_SetExitHandler */
+
+static void QuitVLC( void *obj )
+{
+ [[VLCApplication sharedApplication] performSelectorOnMainThread:@selector(terminate:) withObject:nil waitUntilDone:NO];
+}
+
/*****************************************************************************
* Run: main loop
*****************************************************************************/
static NSLock * o_appLock = nil; // controls access to f_appExit
-static NSLock * o_plItemChangedLock = nil;
static void Run(intf_thread_t *p_intf)
{
[VLCApplication sharedApplication];
o_appLock = [[NSLock alloc] init];
- o_plItemChangedLock = [[NSLock alloc] init];
o_vout_provider_lock = [[NSLock alloc] init];
+ libvlc_SetExitHandler(p_intf->p_libvlc, QuitVLC, p_intf);
+
[[VLCMain sharedInstance] setIntf: p_intf];
[NSBundle loadNibNamed: @"MainMenu" owner: NSApp];
[NSApp run];
+ msg_Dbg(p_intf, "Run loop has been stopped");
[[VLCMain sharedInstance] applicationWillTerminate:nil];
- [o_plItemChangedLock release];
[o_appLock release];
[o_vout_provider_lock release];
o_vout_provider_lock = nil;
case INPUT_EVENT_ITEM_INFO:
[[VLCMain sharedInstance] performSelectorOnMainThread:@selector(updateMainMenu) withObject: nil waitUntilDone:NO];
[[VLCMain sharedInstance] performSelectorOnMainThread:@selector(updateName) withObject: nil waitUntilDone:NO];
- [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(updateInfoandMetaPanel) withObject: nil waitUntilDone:NO];
+ [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(updateMetaAndInfo) withObject: nil waitUntilDone:NO];
break;
case INPUT_EVENT_BOOKMARK:
break;
case INPUT_EVENT_ITEM_NAME:
[[VLCMain sharedInstance] performSelectorOnMainThread:@selector(updateName) withObject: nil waitUntilDone:NO];
- [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(playlistUpdated) withObject: nil waitUntilDone:NO];
break;
case INPUT_EVENT_AUDIO_DELAY:
[[VLCMain sharedInstance] performSelectorOnMainThread:@selector(updatePlaybackPosition) withObject:nil waitUntilDone:NO];
break;
- case INPUT_EVENT_ABORT:
- [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(updateName) withObject: nil waitUntilDone:NO];
- [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(updatePlaybackPosition) withObject:nil waitUntilDone:NO];
- break;
-
default:
break;
}
{
NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
- /* Due to constraints within NSAttributedString's main loop runtime handling
- * and other issues, we need to wait for -PlaylistItemChanged to finish and
- * then -informInputChanged on this non-main thread. */
- [o_plItemChangedLock lock];
- [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(PlaylistItemChanged) withObject:nil waitUntilDone:YES]; // MUST BE ON MAIN THREAD
- [[VLCMain sharedInstance] informInputChanged]; // DO NOT MOVE TO MAIN THREAD
- [o_plItemChangedLock unlock];
+ [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(PlaylistItemChanged) withObject:nil waitUntilDone:NO];
[o_pool release];
return VLC_SUCCESS;
}
-static int PlaylistUpdated(vlc_object_t *p_this, const char *psz_var,
+/**
+ * Callback for item-change variable. Is triggered after update of duration or metadata.
+ */
+static int PLItemUpdated(vlc_object_t *p_this, const char *psz_var,
vlc_value_t oldval, vlc_value_t new_val, void *param)
{
NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
- /* Avoid event queue flooding with playlistUpdated selectors, leading to UI freezes.
- * Therefore, only enqueue if no selector already enqueued.
- */
- VLCMain *o_main = [VLCMain sharedInstance];
- @synchronized(o_main) {
- if(![o_main playlistUpdatedSelectorInQueue]) {
- [o_main setPlaylistUpdatedSelectorInQueue:YES];
- [o_main performSelectorOnMainThread:@selector(playlistUpdated) withObject:nil waitUntilDone:NO];
- }
- }
+ [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(plItemUpdated) withObject:nil waitUntilDone:NO];
+
+ [o_pool release];
+ return VLC_SUCCESS;
+}
+
+static int PLItemAppended(vlc_object_t *p_this, const char *psz_var,
+ vlc_value_t oldval, vlc_value_t new_val, void *param)
+{
+ NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
+
+ playlist_add_t *p_add = new_val.p_address;
+ NSArray *o_val = [NSArray arrayWithObjects:[NSNumber numberWithInt:p_add->i_node], [NSNumber numberWithInt:p_add->i_item], nil];
+ [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(plItemAppended:) withObject:o_val waitUntilDone:NO];
+
+ [o_pool release];
+ return VLC_SUCCESS;
+}
+
+static int PLItemRemoved(vlc_object_t *p_this, const char *psz_var,
+ vlc_value_t oldval, vlc_value_t new_val, void *param)
+{
+ NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
+
+ NSNumber *o_val = [NSNumber numberWithInt:new_val.i_int];
+ [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(plItemRemoved:) withObject:o_val waitUntilDone:NO];
[o_pool release];
return VLC_SUCCESS;
vlc_value_t old_val, vlc_value_t new_val, void *param)
{
intf_thread_t * p_intf = VLCIntf;
- if (p_intf && p_intf->p_sys) {
+ if (p_intf) {
playlist_t * p_playlist = pl_Get(p_intf);
BOOL b_fullscreen = var_GetBool(p_playlist, "fullscreen");
- if (strcmp(psz_variable, "intf-toggle-fscontrol") || b_fullscreen)
+ if (b_fullscreen)
[[VLCMain sharedInstance] performSelectorOnMainThread:@selector(showFullscreenController) withObject:nil waitUntilDone:NO];
- else
+ else if (!strcmp(psz_variable, "intf-show"))
[[VLCMain sharedInstance] performSelectorOnMainThread:@selector(showMainWindow) withObject:nil waitUntilDone:NO];
}
+
return VLC_SUCCESS;
}
static int DialogCallback(vlc_object_t *p_this, const char *type, vlc_value_t previous, vlc_value_t value, void *data)
{
NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
- VLCMain *interface = (VLCMain *)data;
if ([[NSString stringWithUTF8String:type] isEqualToString: @"dialog-progress-bar"]) {
/* the progress panel needs to update itself and therefore wants special treatment within this context */
}
NSValue *o_value = [NSValue valueWithPointer:value.p_address];
- [[VLCCoreDialogProvider sharedInstance] performEventWithObject: o_value ofType: type];
+ [[[VLCMain sharedInstance] coreDialogProvider] performEventWithObject: o_value ofType: type];
[o_pool release];
return VLC_SUCCESS;
{
NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
- NSString *o_txt;
- if (text != NULL)
- o_txt = [NSString stringWithUTF8String:text];
- else
- o_txt = @"";
-
- [[[VLCMain sharedInstance] coreDialogProvider] updateProgressPanelWithText: o_txt andNumber: (double)(value * 1000.)];
+ NSString *o_txt = toNSStr(text);
+ dispatch_async(dispatch_get_main_queue(), ^{
+ [[[VLCMain sharedInstance] coreDialogProvider] updateProgressPanelWithText: o_txt andNumber: (double)(value * 1000.)];
+ });
[o_pool release];
}
bool checkProgressPanel (void *priv)
{
- NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
return [[[VLCMain sharedInstance] coreDialogProvider] progressCancelled];
- [o_pool release];
}
#pragma mark -
#pragma mark -
#pragma mark Private
-@interface VLCMain () <VLCCrashReporterDelegate>
+@interface VLCMain () <BWQuincyManagerDelegate>
- (void)removeOldPreferences;
@end
@interface VLCMain (Internal)
-- (void)handlePortMessage:(NSPortMessage *)o_msg;
- (void)resetMediaKeyJump;
- (void)coreChangedMediaKeySupportSetting: (NSNotification *)o_notification;
@end
@synthesize voutController=o_vout_controller;
@synthesize nativeFullscreenMode=b_nativeFullscreenMode;
-@synthesize playlistUpdatedSelectorInQueue=b_playlist_updated_selector_in_queue;
#pragma mark -
#pragma mark Initialization
_o_sharedMainInstance = [super init];
p_intf = NULL;
- p_current_input = p_input_changed = NULL;
+ p_current_input = NULL;
o_open = [[VLCOpen alloc] init];
o_coredialogs = [[VLCCoreDialogProvider alloc] init];
- o_info = [[VLCInfo alloc] init];
o_mainmenu = [[VLCMainMenu alloc] init];
o_coreinteraction = [[VLCCoreInteraction alloc] init];
o_eyetv = [[VLCEyeTVController alloc] init];
- o_mainwindow = [[VLCMainWindow alloc] init];
/* announce our launch to a potential eyetv plugin */
[[NSDistributedNotificationCenter defaultCenter] postNotificationName: @"VLCOSXGUIInit"
o_vout_controller = [[VLCVoutWindowController alloc] init];
+ informInputChangedQueue = dispatch_queue_create("org.videolan.vlc.inputChangedQueue", DISPATCH_QUEUE_SERIAL);
+
return _o_sharedMainInstance;
}
- (void)awakeFromNib
{
playlist_t *p_playlist;
- vlc_value_t val;
if (!p_intf) return;
var_Create(p_intf, "intf-change", VLC_VAR_BOOL);
p_playlist = pl_Get(p_intf);
- val.b_bool = false;
-
var_AddCallback(p_intf->p_libvlc, "intf-toggle-fscontrol", ShowController, self);
var_AddCallback(p_intf->p_libvlc, "intf-show", ShowController, self);
var_AddCallback(p_intf->p_libvlc, "intf-boss", BossCallback, self);
- // var_AddCallback(p_playlist, "item-change", PLItemChanged, self);
- var_AddCallback(p_playlist, "activity", PLItemChanged, self);
- var_AddCallback(p_playlist, "leaf-to-parent", PlaylistUpdated, self);
- var_AddCallback(p_playlist, "playlist-item-append", PlaylistUpdated, self);
- var_AddCallback(p_playlist, "playlist-item-deleted", PlaylistUpdated, self);
+ var_AddCallback(p_playlist, "item-change", PLItemUpdated, self);
+ var_AddCallback(p_playlist, "input-current", PLItemChanged, self);
+ var_AddCallback(p_playlist, "playlist-item-append", PLItemAppended, self);
+ var_AddCallback(p_playlist, "playlist-item-deleted", PLItemRemoved, self);
var_AddCallback(p_playlist, "random", PlaybackModeUpdated, self);
var_AddCallback(p_playlist, "repeat", PlaybackModeUpdated, self);
var_AddCallback(p_playlist, "loop", PlaybackModeUpdated, self);
var_SetBool(p_playlist, "fullscreen", YES);
}
- /* load our Core and Shared Dialogs nibs */
- nib_coredialogs_loaded = [NSBundle loadNibNamed:@"CoreDialogs" owner: NSApp];
+ /* load our Shared Dialogs nib */
[NSBundle loadNibNamed:@"SharedDialogs" owner: NSApp];
/* subscribe to various interactive dialogues */
PL_LOCK;
items_at_launch = p_playlist->p_local_category->i_children;
PL_UNLOCK;
+
+ [NSBundle loadNibNamed:@"MainWindow" owner: self];
+ [o_mainwindow makeKeyAndOrderFront:nil];
+
+ [[SUUpdater sharedUpdater] setDelegate:self];
}
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
if (!p_intf)
return;
+ NSString *appVersion = [[[NSBundle mainBundle] infoDictionary] valueForKey: @"CFBundleVersion"];
+ NSRange endRande = [appVersion rangeOfString:@"-"];
+ if (endRande.location != NSNotFound)
+ appVersion = [appVersion substringToIndex:endRande.location];
+
+ BWQuincyManager *quincyManager = [BWQuincyManager sharedQuincyManager];
+ [quincyManager setApplicationVersion:appVersion];
+ [quincyManager setSubmissionURL:@"http://crash.videolan.org/crash_v200.php"];
+ [quincyManager setDelegate:self];
+ [quincyManager setCompanyName:@"VideoLAN"];
+
[self updateCurrentlyUsedHotkeys];
/* init media key support */
[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(computerWillSleep:)
name:NSWorkspaceWillSleepNotification object:nil];
- [self performSelector:@selector(lookForCrashLog) withObject:nil afterDelay:1.5];
-
- /* we will need this, so let's load it here so the interface appears to be more responsive */
- nib_open_loaded = [NSBundle loadNibNamed:@"Open" owner: NSApp];
-
/* update the main window */
[o_mainwindow updateWindow];
[o_mainwindow updateTimeSlider];
[o_mainwindow updateVolumeSlider];
+ // respect playlist-autostart
+ // note that PLAYLIST_PLAY will not stop any playback if already started
playlist_t * p_playlist = pl_Get(VLCIntf);
PL_LOCK;
- BOOL kidsAround = p_playlist->p_local_category->i_children;
- PL_UNLOCK;
+ BOOL kidsAround = p_playlist->p_local_category->i_children != 0;
if (kidsAround && var_GetBool(p_playlist, "playlist-autostart"))
- [[self playlist] playItem:nil];
+ playlist_Control(p_playlist, PLAYLIST_PLAY, true);
+ PL_UNLOCK;
}
+/* don't allow a double termination call. If the user has
+ * already invoked the quit then simply return this time. */
+static bool f_appExit = false;
+
#pragma mark -
#pragma mark Termination
+- (BOOL)isTerminating
+{
+ return f_appExit;
+}
+
- (void)applicationWillTerminate:(NSNotification *)notification
{
- /* don't allow a double termination call. If the user has
- * already invoked the quit then simply return this time. */
- static bool f_appExit = false;
bool isTerminating;
[o_appLock lock];
[[NSNotificationCenter defaultCenter] postNotificationName: NSApplicationWillTerminateNotification object: nil];
playlist_t * p_playlist = pl_Get(p_intf);
- int returnedValue = 0;
-
- /* always exit fullscreen on quit, otherwise we get ugly artifacts on the next launch */
- if (b_nativeFullscreenMode && [o_mainwindow fullscreen]) {
- [o_mainwindow toggleFullScreen: self];
- [NSApp setPresentationOptions:(NSApplicationPresentationDefault)];
- }
/* save current video and audio profiles */
[[VLCVideoEffects sharedInstance] saveCurrentProfile];
var_DelCallback(p_intf, "dialog-login", DialogCallback, self);
var_DelCallback(p_intf, "dialog-question", DialogCallback, self);
var_DelCallback(p_intf, "dialog-progress-bar", DialogCallback, self);
- //var_DelCallback(p_playlist, "item-change", PLItemChanged, self);
- var_DelCallback(p_playlist, "activity", PLItemChanged, self);
- var_DelCallback(p_playlist, "leaf-to-parent", PlaylistUpdated, self);
- var_DelCallback(p_playlist, "playlist-item-append", PlaylistUpdated, self);
- var_DelCallback(p_playlist, "playlist-item-deleted", PlaylistUpdated, self);
+ var_DelCallback(p_playlist, "item-change", PLItemUpdated, self);
+ var_DelCallback(p_playlist, "input-current", PLItemChanged, self);
+ var_DelCallback(p_playlist, "playlist-item-append", PLItemAppended, self);
+ var_DelCallback(p_playlist, "playlist-item-deleted", PLItemRemoved, self);
var_DelCallback(p_playlist, "random", PlaybackModeUpdated, self);
var_DelCallback(p_playlist, "repeat", PlaybackModeUpdated, self);
var_DelCallback(p_playlist, "loop", PlaybackModeUpdated, self);
var_DelCallback(p_intf->p_libvlc, "intf-boss", BossCallback, self);
if (p_current_input) {
+ /* continue playback where you left off */
+ [[self playlist] storePlaybackPositionForItem:p_current_input];
+
var_DelCallback(p_current_input, "intf-event", InputEvent, [VLCMain sharedInstance]);
vlc_object_release(p_current_input);
p_current_input = NULL;
[o_vout_provider_lock lock];
// release before o_info!
+ // closes all open vouts
[o_vout_controller release];
o_vout_controller = nil;
[o_vout_provider_lock unlock];
if (o_wizard)
[o_wizard release];
+ if (!o_bookmarks)
+ [o_bookmarks release];
+
[o_coredialogs release];
[o_eyetv release];
+ [o_remote release];
/* unsubscribe from libvlc's debug messages */
vlc_LogSet(p_intf->p_libvlc, NULL, NULL);
[[NSUserDefaults standardUserDefaults] synchronize];
[o_mainmenu release];
+ [o_coreinteraction release];
- libvlc_Quit(p_intf->p_libvlc);
-
- [o_mainwindow release];
o_mainwindow = NULL;
[self setIntf:nil];
[[VLCCoreInteraction sharedInstance] stop];
}
+/* don't be enthusiastic about an update if we currently play a video */
+- (BOOL)updaterMayCheckForUpdates:(SUUpdater *)bundle
+{
+ if ([self activeVideoPlayback])
+ return NO;
+
+ return YES;
+}
+
#pragma mark -
#pragma mark Media Key support
- (void)application:(NSApplication *)o_app openFiles:(NSArray *)o_names
{
- char *psz_uri = vlc_path2uri([[o_names objectAtIndex:0] UTF8String], "file");
-
+ // Only add items here which are getting dropped to to the application icon
+ // or are given at startup. If a file is passed via command line, libvlccore
+ // will add the item, but cocoa also calls this function. In this case, the
+ // invocation is ignored here.
if (launched == NO) {
if (items_at_launch) {
int items = [o_names count];
}
}
+ char *psz_uri = vlc_path2uri([[o_names objectAtIndex:0] UTF8String], NULL);
+
// try to add file as subtitle
if ([o_names count] == 1 && psz_uri) {
input_thread_t * p_input = pl_CurrentInput(VLCIntf);
if (p_input) {
- BOOL b_returned = NO;
- b_returned = input_AddSubtitle(p_input, psz_uri, true);
+ int i_result = input_AddSubtitleOSD(p_input, [[o_names objectAtIndex:0] UTF8String], true, true);
vlc_object_release(p_input);
- if (!b_returned) {
+ if (i_result == VLC_SUCCESS) {
free(psz_uri);
return;
}
NSArray *o_sorted_names = [o_names sortedArrayUsingSelector: @selector(caseInsensitiveCompare:)];
NSMutableArray *o_result = [NSMutableArray arrayWithCapacity: [o_sorted_names count]];
- for (int i = 0; i < [o_sorted_names count]; i++) {
+ for (NSUInteger i = 0; i < [o_sorted_names count]; i++) {
psz_uri = vlc_path2uri([[o_sorted_names objectAtIndex:i] UTF8String], "file");
if (!psz_uri)
continue;
[o_result addObject: o_dic];
}
- [o_playlist appendArray: o_result atPos: -1 enqueue: !config_GetInt(VLCIntf, "macosx-autoplay")];
-
- return;
+ [[[VLCMain sharedInstance] playlist] addPlaylistItems:o_result];
}
/* When user click in the Dock icon our double click in the finder */
val.i_int |= CocoaKeyToVLC(key);
BOOL b_found_key = NO;
- for (int i = 0; i < [o_usedHotkeys count]; i++) {
+ for (NSUInteger i = 0; i < [o_usedHotkeys count]; i++) {
NSString *str = [o_usedHotkeys objectAtIndex:i];
unsigned int i_keyModifiers = [[VLCStringUtility sharedInstance] VLCModifiersToCocoa: str];
#pragma mark -
#pragma mark Interface updaters
+- (void)plItemAppended:(NSArray *)o_val
+{
+ int i_node = [[o_val objectAtIndex:0] intValue];
+ int i_item = [[o_val objectAtIndex:1] intValue];
+
+ [[[self playlist] model] addItem:i_item withParentNode:i_node];
+
+ // update badge in sidebar
+ [o_mainwindow updateWindow];
+
+ [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCMediaKeySupportSettingChanged"
+ object: nil
+ userInfo: nil];
+}
+
+- (void)plItemRemoved:(NSNumber *)o_val
+{
+ int i_item = [o_val intValue];
+
+ [[[self playlist] model] removeItem:i_item];
+ [[self playlist] deletionCompleted];
+
+ // update badge in sidebar
+ [o_mainwindow updateWindow];
+
+ [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCMediaKeySupportSettingChanged"
+ object: nil
+ userInfo: nil];
+}
+
+// This must be called on main thread
- (void)PlaylistItemChanged
{
+ input_thread_t *p_input_changed = NULL;
+
if (p_current_input && (p_current_input->b_dead || !vlc_object_alive(p_current_input))) {
var_DelCallback(p_current_input, "intf-event", InputEvent, [VLCMain sharedInstance]);
- p_input_changed = p_current_input;
+ vlc_object_release(p_current_input);
p_current_input = NULL;
[o_mainmenu setRateControlsEnabled: NO];
+
+ [[NSNotificationCenter defaultCenter] postNotificationName:VLCInputChangedNotification
+ object:nil];
}
else if (!p_current_input) {
// object is hold here and released then it is dead
var_AddCallback(p_current_input, "intf-event", InputEvent, [VLCMain sharedInstance]);
[self playbackStatusUpdated];
[o_mainmenu setRateControlsEnabled: YES];
- if ([self activeVideoPlayback] && [[o_mainwindow videoView] isHidden])
- [o_mainwindow performSelectorOnMainThread:@selector(togglePlaylist:) withObject: nil waitUntilDone:NO];
+
+ if ([self activeVideoPlayback] && [[o_mainwindow videoView] isHidden]) {
+ [o_mainwindow changePlaylistState: psPlaylistItemChangedEvent];
+ }
+
p_input_changed = vlc_object_hold(p_current_input);
+
+ [[self playlist] currentlyPlayingItemChanged];
+
+ [[self playlist] continuePlaybackWhereYouLeftOff:p_current_input];
+
+ [[NSNotificationCenter defaultCenter] postNotificationName:VLCInputChangedNotification
+ object:nil];
}
}
- [o_playlist updateRowSelection];
+ [self updateMetaAndInfo];
+
[o_mainwindow updateWindow];
[self updateDelays];
[self updateMainMenu];
+
+ /*
+ * Due to constraints within NSAttributedString's main loop runtime handling
+ * and other issues, we need to inform the extension manager on a separate thread.
+ * The serial queue ensures that changed inputs are propagated in the same order as they arrive.
+ */
+ dispatch_async(informInputChangedQueue, ^{
+ [[ExtensionsManager getInstance:p_intf] inputChanged:p_input_changed];
+ if (p_input_changed)
+ vlc_object_release(p_input_changed);
+ });
}
-- (void)informInputChanged
+- (void)plItemUpdated
{
- if (p_input_changed) {
- [[ExtensionsManager getInstance:p_intf] inputChanged:p_input_changed];
- vlc_object_release(p_input_changed);
- p_input_changed = NULL;
- }
+ [o_mainwindow updateName];
+
+ if (o_info != NULL)
+ [o_info updateMetadata];
}
- (void)updateMainMenu
[o_mainwindow updateVolumeSlider];
}
-- (void)playlistUpdated
-{
- @synchronized(self) {
- b_playlist_updated_selector_in_queue = NO;
- }
-
- [self playbackStatusUpdated];
- [o_playlist playlistUpdated];
- [o_mainwindow updateWindow];
- [o_mainwindow updateName];
-
- [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCMediaKeySupportSettingChanged"
- object: nil
- userInfo: nil];
-}
-
- (void)updateRecordState: (BOOL)b_value
{
[o_mainmenu updateRecordState:b_value];
}
-- (void)updateInfoandMetaPanel
+- (void)updateMetaAndInfo
{
- [o_playlist outlineViewSelectionDidChange:nil];
+ if (!p_current_input) {
+ [[self info] updatePanelWithItem:nil];
+ return;
+ }
+
+ input_item_t *p_input_item = input_GetItem(p_current_input);
+
+ [[[self playlist] model] updateItem:p_input_item];
+ [[self info] updatePanelWithItem:p_input_item];
}
- (void)resumeItunesPlayback:(id)sender
{
- if (b_has_itunes_paused && var_InheritInteger(p_intf, "macosx-control-itunes") > 1) {
- iTunesApplication *iTunesApp = [SBApplication applicationWithBundleIdentifier:@"com.apple.iTunes"];
- if (iTunesApp && [iTunesApp isRunning]) {
- if ([iTunesApp playerState] == iTunesEPlSPaused) {
- msg_Dbg(p_intf, "Unpause iTunes...");
- [iTunesApp playpause];
+ if (var_InheritInteger(p_intf, "macosx-control-itunes") > 1) {
+ if (b_has_itunes_paused) {
+ iTunesApplication *iTunesApp = (iTunesApplication *) [SBApplication applicationWithBundleIdentifier:@"com.apple.iTunes"];
+ if (iTunesApp && [iTunesApp isRunning]) {
+ if ([iTunesApp playerState] == iTunesEPlSPaused) {
+ msg_Dbg(p_intf, "unpausing iTunes");
+ [iTunesApp playpause];
+ }
}
}
+ if (b_has_spotify_paused) {
+ SpotifyApplication *spotifyApp = (SpotifyApplication *) [SBApplication applicationWithBundleIdentifier:@"com.spotify.client"];
+ if (spotifyApp) {
+ if ([spotifyApp respondsToSelector:@selector(isRunning)] && [spotifyApp respondsToSelector:@selector(playerState)]) {
+ if ([spotifyApp isRunning] && [spotifyApp playerState] == kSpotifyPlayerStatePaused) {
+ msg_Dbg(p_intf, "unpausing Spotify");
+ [spotifyApp play];
+ }
+ }
+ }
+ }
}
b_has_itunes_paused = NO;
+ b_has_spotify_paused = NO;
o_itunes_play_timer = nil;
}
}
if (state == PLAYING_S) {
- // pause iTunes
- if (i_control_itunes > 0 && !b_has_itunes_paused) {
- iTunesApplication *iTunesApp = [SBApplication applicationWithBundleIdentifier:@"com.apple.iTunes"];
- if (iTunesApp && [iTunesApp isRunning]) {
- if ([iTunesApp playerState] == iTunesEPlSPlaying) {
- msg_Dbg(p_intf, "Pause iTunes...");
- [iTunesApp pause];
- b_has_itunes_paused = YES;
+ if (i_control_itunes > 0) {
+ // pause iTunes
+ if (!b_has_itunes_paused) {
+ iTunesApplication *iTunesApp = (iTunesApplication *) [SBApplication applicationWithBundleIdentifier:@"com.apple.iTunes"];
+ if (iTunesApp && [iTunesApp isRunning]) {
+ if ([iTunesApp playerState] == iTunesEPlSPlaying) {
+ msg_Dbg(p_intf, "pausing iTunes");
+ [iTunesApp pause];
+ b_has_itunes_paused = YES;
+ }
}
}
- }
+ // pause Spotify
+ if (!b_has_spotify_paused) {
+ SpotifyApplication *spotifyApp = (SpotifyApplication *) [SBApplication applicationWithBundleIdentifier:@"com.spotify.client"];
+
+ if (spotifyApp) {
+ if ([spotifyApp respondsToSelector:@selector(isRunning)] && [spotifyApp respondsToSelector:@selector(playerState)]) {
+ if ([spotifyApp isRunning] && [spotifyApp playerState] == kSpotifyPlayerStatePlaying) {
+ msg_Dbg(p_intf, "pausing Spotify");
+ [spotifyApp pause];
+ b_has_spotify_paused = YES;
+ }
+ }
+ }
+ }
+ }
/* Declare user activity.
This wakes the display if it is off, and postpones display sleep according to the users system preferences
IOReturn success;
/* work-around a bug in 10.7.4 and 10.7.5, so check for 10.7.x < 10.7.4, 10.8 and 10.6 */
- if ((NSAppKitVersionNumber >= 1115.2 && NSAppKitVersionNumber < 1138.45) || OSX_MOUNTAIN_LION || OSX_MAVERICKS || OSX_SNOW_LEOPARD) {
+ if ((NSAppKitVersionNumber >= 1115.2 && NSAppKitVersionNumber < 1138.45) || OSX_MOUNTAIN_LION || OSX_MAVERICKS || OSX_YOSEMITE || OSX_SNOW_LEOPARD) {
CFStringRef reasonForActivity = CFStringCreateWithCString(kCFAllocatorDefault, _("VLC media playback"), kCFStringEncodingUTF8);
if ([self activeVideoPlayback])
success = IOPMAssertionCreateWithName(kIOPMAssertionTypeNoDisplaySleep, kIOPMAssertionLevelOn, reasonForActivity, &systemSleepAssertionID);
}
if (state == END_S || state == -1) {
+ /* continue playback where you left off */
+ if (p_current_input)
+ [[self playlist] storePlaybackPositionForItem:p_current_input];
+
if (i_control_itunes > 0) {
if (o_itunes_play_timer) {
[o_itunes_play_timer invalidate];
- (void)playbackModeUpdated
{
- vlc_value_t looping,repeating;
playlist_t * p_playlist = pl_Get(VLCIntf);
bool loop = var_GetBool(p_playlist, "loop");
- (void)setActiveVideoPlayback:(BOOL)b_value
{
+ assert([NSThread isMainThread]);
+
b_active_videoplayback = b_value;
if (o_mainwindow) {
- [o_mainwindow performSelectorOnMainThread:@selector(setVideoplayEnabled) withObject:nil waitUntilDone:YES];
- [o_mainwindow performSelectorOnMainThread:@selector(togglePlaylist:) withObject:nil waitUntilDone:NO];
+ [o_mainwindow setVideoplayEnabled];
}
// update sleep blockers
- [self performSelectorOnMainThread:@selector(playbackStatusUpdated) withObject:nil waitUntilDone:NO];
+ [self playbackStatusUpdated];
}
#pragma mark -
- (id)controls
{
- if (o_controls)
- return o_controls;
-
- return nil;
+ return o_controls;
}
- (id)bookmarks
- (id)open
{
- if (!o_open)
- return nil;
-
if (!nib_open_loaded)
nib_open_loaded = [NSBundle loadNibNamed:@"Open" owner: NSApp];
- (id)playlist
{
- if (o_playlist)
- return o_playlist;
-
- return nil;
+ return o_playlist;
}
- (id)info
{
+ if (!o_info)
+ o_info = [[VLCInfo alloc] init];
+
if (! nib_info_loaded)
nib_info_loaded = [NSBundle loadNibNamed:@"MediaInfo" owner: NSApp];
- if (o_info)
- return o_info;
-
- return nil;
+ return o_info;
}
- (id)wizard
nib_wizard_loaded = [NSBundle loadNibNamed:@"Wizard" owner: NSApp];
[o_wizard initStrings];
}
+
return o_wizard;
}
- (id)coreDialogProvider
{
- if (o_coredialogs)
- return o_coredialogs;
+ if (!nib_coredialogs_loaded) {
+ nib_coredialogs_loaded = [NSBundle loadNibNamed:@"CoreDialogs" owner: NSApp];
+ }
- return nil;
+ return o_coredialogs;
}
- (id)eyeTVController
{
- if (o_eyetv)
- return o_eyetv;
-
- return nil;
+ return o_eyetv;
}
- (id)appleRemoteController
}
#pragma mark -
-#pragma mark Crash Log handling
+#pragma mark Remove old prefs
-- (void)lookForCrashLog
+
+static NSString * kVLCPreferencesVersion = @"VLCPreferencesVersion";
+static const int kCurrentPreferencesVersion = 3;
+
++ (void)initialize
{
- VLCCrashReporter *reporter = [[VLCCrashReporter alloc] init];
- reporter.delegate = self;
- [reporter showDialogAndSendLogIfDesired];
+ NSDictionary *appDefaults = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:kCurrentPreferencesVersion]
+ forKey:kVLCPreferencesVersion];
+
+ [[NSUserDefaults standardUserDefaults] registerDefaults:appDefaults];
}
-- (void)reporterFinishedAction:(VLCCrashReporter *)reporter
+- (void)resetAndReinitializeUserDefaults
{
- [reporter release];
-}
+ // note that [NSUserDefaults resetStandardUserDefaults] will NOT correctly reset to the defaults
-#pragma mark -
-#pragma mark Remove old prefs
+ NSString *appDomain = [[NSBundle mainBundle] bundleIdentifier];
+ [[NSUserDefaults standardUserDefaults] removePersistentDomainForName:appDomain];
+
+ // set correct version to avoid question about outdated config
+ [[NSUserDefaults standardUserDefaults] setInteger:kCurrentPreferencesVersion forKey:kVLCPreferencesVersion];
+ [[NSUserDefaults standardUserDefaults] synchronize];
+}
- (void)removeOldPreferences
{
- static NSString * kVLCPreferencesVersion = @"VLCPreferencesVersion";
- static const int kCurrentPreferencesVersion = 3;
NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
int version = [defaults integerForKey:kVLCPreferencesVersion];
+
+ /*
+ * Store version explicitely in file, for ease of debugging.
+ * Otherwise, the value will be just defined at app startup,
+ * as initialized above.
+ */
+ [defaults setInteger:version forKey:kVLCPreferencesVersion];
if (version >= kCurrentPreferencesVersion)
return;
} else if (version == 2) {
/* version 2 (used by VLC 2.0.x and early versions of 2.1) can lead to exceptions within 2.1 or later
* so we reset the OS X specific prefs here - in practice, no user will notice */
- [NSUserDefaults resetStandardUserDefaults];
+ [self resetAndReinitializeUserDefaults];
- [defaults setInteger:kCurrentPreferencesVersion forKey:kVLCPreferencesVersion];
- [defaults synchronize];
} else {
NSArray *libraries = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,
NSUserDomainMask, YES);
if (!libraries || [libraries count] == 0) return;
NSString * preferences = [[libraries objectAtIndex:0] stringByAppendingPathComponent:@"Preferences"];
- /* File not found, don't attempt anything */
- if (![[NSFileManager defaultManager] fileExistsAtPath:[preferences stringByAppendingPathComponent:@"org.videolan.vlc"]] &&
- ![[NSFileManager defaultManager] fileExistsAtPath:[preferences stringByAppendingPathComponent:@"org.videolan.vlc.plist"]]) {
- [defaults setInteger:kCurrentPreferencesVersion forKey:kVLCPreferencesVersion];
- return;
- }
-
int res = NSRunInformationalAlertPanel(_NS("Remove old preferences?"),
_NS("We just found an older version of VLC's preferences files."),
_NS("Move To Trash and Relaunch VLC"), _NS("Ignore"), nil, nil);
return;
}
- NSArray * ourPreferences = [NSArray arrayWithObjects:@"org.videolan.vlc.plist", @"VLC", @"org.videolan.vlc", nil];
-
- /* Move the file to trash so that user can find them later */
- [[NSWorkspace sharedWorkspace] performFileOperation:NSWorkspaceRecycleOperation source:preferences destination:nil files:ourPreferences tag:0];
+ // Do NOT add the current plist file here as this would conflict with caching.
+ // Instead, just reset below.
+ NSArray * ourPreferences = [NSArray arrayWithObjects:@"org.videolan.vlc", @"VLC", nil];
- /* really reset the defaults from now on */
- [NSUserDefaults resetStandardUserDefaults];
+ /* Move the file to trash one by one. Using above array the method would stop after first file
+ not found. */
+ for (NSString *file in ourPreferences) {
+ [[NSWorkspace sharedWorkspace] performFileOperation:NSWorkspaceRecycleOperation source:preferences destination:@"" files:[NSArray arrayWithObject:file] tag:nil];
+ }
- [defaults setInteger:kCurrentPreferencesVersion forKey:kVLCPreferencesVersion];
- [defaults synchronize];
+ [self resetAndReinitializeUserDefaults];
}
/* Relaunch now */
/* For some reason we need to fork(), not just execl(), which reports a ENOTSUP then. */
if (fork() != 0) {
exit(0);
- return;
}
execl(path, path, NULL);
}
@implementation VLCMain (Internal)
-- (void)handlePortMessage:(NSPortMessage *)o_msg
-{
- id ** val;
- NSData * o_data;
- NSValue * o_value;
- NSInvocation * o_inv;
- NSConditionLock * o_lock;
-
- o_data = [[o_msg components] lastObject];
- o_inv = *((NSInvocation **)[o_data bytes]);
- [o_inv getArgument: &o_value atIndex: 2];
- val = (id **)[o_value pointerValue];
- [o_inv setArgument: val[1] atIndex: 2];
- o_lock = *(val[0]);
-
- [o_lock lock];
- [o_inv invoke];
- [o_lock unlockWithCondition: 1];
-}
-
- (void)resetMediaKeyJump
{
b_mediakeyJustJumped = NO;
- (void)coreChangedMediaKeySupportSetting: (NSNotification *)o_notification
{
b_mediaKeySupport = var_InheritBool(VLCIntf, "macosx-mediakeys");
- if (b_mediaKeySupport) {
- if (!o_mediaKeyController)
- o_mediaKeyController = [[SPMediaKeyTap alloc] initWithDelegate:self];
+ if (b_mediaKeySupport && !o_mediaKeyController)
+ o_mediaKeyController = [[SPMediaKeyTap alloc] initWithDelegate:self];
- if ([[[VLCMain sharedInstance] playlist] currentPlaylistRoot]->i_children > 0 ||
- p_current_input)
+ if (b_mediaKeySupport && ([[[[VLCMain sharedInstance] playlist] model] hasChildren] ||
+ p_current_input)) {
+ if (!b_mediaKeyTrapEnabled) {
+ b_mediaKeyTrapEnabled = YES;
+ msg_Dbg(p_intf, "Enable media key support");
[o_mediaKeyController startWatchingMediaKeys];
- else
+ }
+ } else {
+ if (b_mediaKeyTrapEnabled) {
+ b_mediaKeyTrapEnabled = NO;
+ msg_Dbg(p_intf, "Disable media key support");
[o_mediaKeyController stopWatchingMediaKeys];
+ }
}
- else if (!b_mediaKeySupport && o_mediaKeyController)
- [o_mediaKeyController stopWatchingMediaKeys];
}
@end