1 /*****************************************************************************
2 * intf.m: MacOS X interface module
3 *****************************************************************************
4 * Copyright (C) 2002-2013 VLC authors and VideoLAN
7 * Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
8 * Derk-Jan Hartman <hartman at videolan.org>
9 * Felix Paul Kühne <fkuehne at videolan dot org>
10 * Pierre d'Herbemont <pdherbemont # videolan org>
11 * David Fuhrmann <david dot fuhrmann at googlemail dot com>
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
26 *****************************************************************************/
28 /*****************************************************************************
30 *****************************************************************************/
35 #include <stdlib.h> /* malloc(), free() */
36 #include <sys/param.h> /* for MAXPATHLEN */
38 #include <vlc_common.h>
40 #include <vlc_dialog.h>
42 #include <vlc_modules.h>
43 #include <vlc_plugin.h>
44 #include <vlc_vout_display.h>
45 #include <unistd.h> /* execl() */
47 #import "CompatibilityFixes.h"
49 #import "StringUtility.h"
54 #import "playlistinfo.h"
59 #import "coredialogs.h"
60 #import "AppleRemote.h"
62 #import "simple_prefs.h"
63 #import "CoreInteraction.h"
64 #import "TrackSynchronization.h"
65 #import "VLCVoutWindowController.h"
66 #import "ExtensionsManager.h"
68 #import "VideoEffects.h"
69 #import "AudioEffects.h"
71 #import <AddressBook/AddressBook.h> /* for crashlog send mechanism */
72 #import <Sparkle/Sparkle.h> /* we're the update delegate */
76 /*****************************************************************************
78 *****************************************************************************/
79 static void Run (intf_thread_t *p_intf);
81 static void updateProgressPanel (void *, const char *, float);
82 static bool checkProgressPanel (void *);
83 static void destroyProgressPanel (void *);
85 static void MsgCallback(void *data, int type, const vlc_log_t *item, const char *format, va_list ap);
87 static int InputEvent(vlc_object_t *, const char *,
88 vlc_value_t, vlc_value_t, void *);
89 static int PLItemChanged(vlc_object_t *, const char *,
90 vlc_value_t, vlc_value_t, void *);
91 static int PlaylistUpdated(vlc_object_t *, const char *,
92 vlc_value_t, vlc_value_t, void *);
93 static int PlaybackModeUpdated(vlc_object_t *, const char *,
94 vlc_value_t, vlc_value_t, void *);
95 static int VolumeUpdated(vlc_object_t *, const char *,
96 vlc_value_t, vlc_value_t, void *);
97 static int BossCallback(vlc_object_t *, const char *,
98 vlc_value_t, vlc_value_t, void *);
101 #pragma mark VLC Interface Object Callbacks
103 /*****************************************************************************
104 * OpenIntf: initialize interface
105 *****************************************************************************/
106 int OpenIntf (vlc_object_t *p_this)
108 NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
109 [VLCApplication sharedApplication];
111 intf_thread_t *p_intf = (intf_thread_t*) p_this;
113 p_intf->p_sys = malloc(sizeof(intf_sys_t));
114 if (p_intf->p_sys == NULL)
117 memset(p_intf->p_sys, 0, sizeof(*p_intf->p_sys));
125 /*****************************************************************************
126 * CloseIntf: destroy interface
127 *****************************************************************************/
128 void CloseIntf (vlc_object_t *p_this)
130 intf_thread_t *p_intf = (intf_thread_t*) p_this;
135 static NSLock * o_vout_provider_lock = nil;
137 static int WindowControl(vout_window_t *, int i_query, va_list);
139 int WindowOpen(vout_window_t *p_wnd, const vout_window_cfg_t *cfg)
141 NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
142 intf_thread_t *p_intf = VLCIntf;
144 msg_Err(p_wnd, "Mac OS X interface not found");
148 NSRect proposedVideoViewPosition = NSMakeRect(cfg->x, cfg->y, cfg->width, cfg->height);
150 [o_vout_provider_lock lock];
151 VLCVoutWindowController *o_vout_controller = [[VLCMain sharedInstance] voutController];
152 if (!o_vout_controller) {
153 [o_vout_provider_lock unlock];
158 SEL sel = @selector(setupVoutForWindow:withProposedVideoViewPosition:);
159 NSInvocation *inv = [NSInvocation invocationWithMethodSignature:[o_vout_controller methodSignatureForSelector:sel]];
160 [inv setTarget:o_vout_controller];
161 [inv setSelector:sel];
162 [inv setArgument:&p_wnd atIndex:2]; // starting at 2!
163 [inv setArgument:&proposedVideoViewPosition atIndex:3];
165 [inv performSelectorOnMainThread:@selector(invoke) withObject:nil
168 VLCVoutView *videoView = nil;
169 [inv getReturnValue:&videoView];
172 msg_Err(p_wnd, "got no video view from the interface");
173 [o_vout_provider_lock unlock];
178 msg_Dbg(VLCIntf, "returning videoview with proposed position x=%i, y=%i, width=%i, height=%i", cfg->x, cfg->y, cfg->width, cfg->height);
179 p_wnd->handle.nsobject = videoView;
181 // TODO: find a cleaner way for "start in fullscreen"
182 if (var_GetBool(pl_Get(VLCIntf), "fullscreen")) {
185 SEL sel = @selector(setFullscreen:forWindow:);
186 NSInvocation *inv = [NSInvocation invocationWithMethodSignature:[[[VLCMain sharedInstance] voutController] methodSignatureForSelector:sel]];
187 [inv setTarget:[[VLCMain sharedInstance] voutController]];
188 [inv setSelector:sel];
189 [inv setArgument:&i_full atIndex:2];
190 [inv setArgument:&p_wnd atIndex:3];
191 [inv performSelectorOnMainThread:@selector(invoke) withObject:nil
194 [o_vout_provider_lock unlock];
196 [[VLCMain sharedInstance] setActiveVideoPlayback: YES];
197 p_wnd->control = WindowControl;
203 static int WindowControl(vout_window_t *p_wnd, int i_query, va_list args)
205 NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
207 [o_vout_provider_lock lock];
208 VLCVoutWindowController *o_vout_controller = [[VLCMain sharedInstance] voutController];
209 if (!o_vout_controller) {
210 [o_vout_provider_lock unlock];
216 case VOUT_WINDOW_SET_STATE:
218 unsigned i_state = va_arg(args, unsigned);
220 NSInteger i_cooca_level = NSNormalWindowLevel;
221 if (i_state & VOUT_WINDOW_STATE_ABOVE)
222 i_cooca_level = NSStatusWindowLevel;
224 SEL sel = @selector(setWindowLevel:forWindow:);
225 NSInvocation *inv = [NSInvocation invocationWithMethodSignature:[o_vout_controller methodSignatureForSelector:sel]];
226 [inv setTarget:o_vout_controller];
227 [inv setSelector:sel];
228 [inv setArgument:&i_cooca_level atIndex:2]; // starting at 2!
229 [inv setArgument:&p_wnd atIndex:3];
230 [inv performSelectorOnMainThread:@selector(invoke) withObject:nil
235 case VOUT_WINDOW_SET_SIZE:
238 unsigned int i_width = va_arg(args, unsigned int);
239 unsigned int i_height = va_arg(args, unsigned int);
241 NSSize newSize = NSMakeSize(i_width, i_height);
242 SEL sel = @selector(setNativeVideoSize:forWindow:);
243 NSInvocation *inv = [NSInvocation invocationWithMethodSignature:[o_vout_controller methodSignatureForSelector:sel]];
244 [inv setTarget:o_vout_controller];
245 [inv setSelector:sel];
246 [inv setArgument:&newSize atIndex:2]; // starting at 2!
247 [inv setArgument:&p_wnd atIndex:3];
248 [inv performSelectorOnMainThread:@selector(invoke) withObject:nil
253 case VOUT_WINDOW_SET_FULLSCREEN:
255 NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
256 int i_full = va_arg(args, int);
258 SEL sel = @selector(setFullscreen:forWindow:);
259 NSInvocation *inv = [NSInvocation invocationWithMethodSignature:[o_vout_controller methodSignatureForSelector:sel]];
260 [inv setTarget:o_vout_controller];
261 [inv setSelector:sel];
262 [inv setArgument:&i_full atIndex:2]; // starting at 2!
263 [inv setArgument:&p_wnd atIndex:3];
264 [inv performSelectorOnMainThread:@selector(invoke) withObject:nil
271 msg_Warn(p_wnd, "unsupported control query");
272 [o_vout_provider_lock unlock];
278 [o_vout_provider_lock unlock];
283 void WindowClose(vout_window_t *p_wnd)
285 NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
287 [o_vout_provider_lock lock];
288 VLCVoutWindowController *o_vout_controller = [[VLCMain sharedInstance] voutController];
289 if (!o_vout_controller) {
290 [o_vout_provider_lock unlock];
295 [o_vout_controller performSelectorOnMainThread:@selector(removeVoutforDisplay:) withObject:[NSValue valueWithPointer:p_wnd] waitUntilDone:NO];
296 [o_vout_provider_lock unlock];
301 /*****************************************************************************
303 *****************************************************************************/
304 static NSLock * o_appLock = nil; // controls access to f_appExit
305 static NSLock * o_plItemChangedLock = nil;
307 static void Run(intf_thread_t *p_intf)
309 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
310 [VLCApplication sharedApplication];
312 o_appLock = [[NSLock alloc] init];
313 o_plItemChangedLock = [[NSLock alloc] init];
314 o_vout_provider_lock = [[NSLock alloc] init];
316 [[VLCMain sharedInstance] setIntf: p_intf];
318 [NSBundle loadNibNamed: @"MainMenu" owner: NSApp];
321 [[VLCMain sharedInstance] applicationWillTerminate:nil];
322 [o_plItemChangedLock release];
324 [o_vout_provider_lock release];
325 o_vout_provider_lock = nil;
332 #pragma mark Variables Callback
334 /*****************************************************************************
335 * MsgCallback: Callback triggered by the core once a new debug message is
336 * ready to be displayed. We store everything in a NSArray in our Cocoa part
338 *****************************************************************************/
339 static void MsgCallback(void *data, int type, const vlc_log_t *item, const char *format, va_list ap)
341 int canc = vlc_savecancel();
344 if (vasprintf(&str, format, ap) == -1) {
345 vlc_restorecancel(canc);
349 NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
350 [[VLCMain sharedInstance] processReceivedlibvlcMessage: item ofType: type withStr: str];
353 vlc_restorecancel(canc);
357 static int InputEvent(vlc_object_t *p_this, const char *psz_var,
358 vlc_value_t oldval, vlc_value_t new_val, void *param)
360 NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
361 switch (new_val.i_int) {
362 case INPUT_EVENT_STATE:
363 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(playbackStatusUpdated) withObject: nil waitUntilDone:NO];
365 case INPUT_EVENT_RATE:
366 [[[VLCMain sharedInstance] mainMenu] performSelectorOnMainThread:@selector(updatePlaybackRate) withObject: nil waitUntilDone:NO];
368 case INPUT_EVENT_POSITION:
369 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(updatePlaybackPosition) withObject: nil waitUntilDone:NO];
371 case INPUT_EVENT_TITLE:
372 case INPUT_EVENT_CHAPTER:
373 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(updateMainMenu) withObject: nil waitUntilDone:NO];
375 case INPUT_EVENT_CACHE:
376 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(updateMainWindow) withObject: nil waitUntilDone: NO];
378 case INPUT_EVENT_STATISTICS:
379 [[[VLCMain sharedInstance] info] performSelectorOnMainThread:@selector(updateStatistics) withObject: nil waitUntilDone: NO];
383 case INPUT_EVENT_TELETEXT:
385 case INPUT_EVENT_AOUT:
387 case INPUT_EVENT_VOUT:
389 case INPUT_EVENT_ITEM_META:
390 case INPUT_EVENT_ITEM_INFO:
391 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(updateMainMenu) withObject: nil waitUntilDone:NO];
392 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(updateName) withObject: nil waitUntilDone:NO];
393 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(updateInfoandMetaPanel) withObject: nil waitUntilDone:NO];
395 case INPUT_EVENT_BOOKMARK:
397 case INPUT_EVENT_RECORD:
398 [[VLCMain sharedInstance] updateRecordState: var_GetBool(p_this, "record")];
400 case INPUT_EVENT_PROGRAM:
401 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(updateMainMenu) withObject: nil waitUntilDone:NO];
403 case INPUT_EVENT_ITEM_EPG:
405 case INPUT_EVENT_SIGNAL:
408 case INPUT_EVENT_ITEM_NAME:
409 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(updateName) withObject: nil waitUntilDone:NO];
410 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(playlistUpdated) withObject: nil waitUntilDone:NO];
413 case INPUT_EVENT_AUDIO_DELAY:
414 case INPUT_EVENT_SUBTITLE_DELAY:
415 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(updateDelays) withObject:nil waitUntilDone:NO];
418 case INPUT_EVENT_DEAD:
419 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(updateName) withObject: nil waitUntilDone:NO];
420 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(updatePlaybackPosition) withObject:nil waitUntilDone:NO];
423 case INPUT_EVENT_ABORT:
424 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(updateName) withObject: nil waitUntilDone:NO];
425 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(updatePlaybackPosition) withObject:nil waitUntilDone:NO];
429 //msg_Warn(p_this, "unhandled input event (%lld)", new_val.i_int);
437 static int PLItemChanged(vlc_object_t *p_this, const char *psz_var,
438 vlc_value_t oldval, vlc_value_t new_val, void *param)
440 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
442 /* Due to constraints within NSAttributedString's main loop runtime handling
443 * and other issues, we need to wait for -PlaylistItemChanged to finish and
444 * then -informInputChanged on this non-main thread. */
445 [o_plItemChangedLock lock];
446 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(PlaylistItemChanged) withObject:nil waitUntilDone:YES];
447 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(informInputChanged) withObject:nil waitUntilDone:YES];
448 [o_plItemChangedLock unlock];
454 static int PlaylistUpdated(vlc_object_t *p_this, const char *psz_var,
455 vlc_value_t oldval, vlc_value_t new_val, void *param)
457 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
459 /* Avoid event queue flooding with playlistUpdated selectors, leading to UI freezes.
460 * Therefore, only enqueue if no selector already enqueued.
462 VLCMain *o_main = [VLCMain sharedInstance];
463 @synchronized(o_main) {
464 if(![o_main playlistUpdatedSelectorInQueue]) {
465 [o_main setPlaylistUpdatedSelectorInQueue:YES];
466 [o_main performSelectorOnMainThread:@selector(playlistUpdated) withObject:nil waitUntilDone:NO];
474 static int PlaybackModeUpdated(vlc_object_t *p_this, const char *psz_var,
475 vlc_value_t oldval, vlc_value_t new_val, void *param)
477 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
478 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(playbackModeUpdated) withObject:nil waitUntilDone:NO];
484 static int VolumeUpdated(vlc_object_t *p_this, const char *psz_var,
485 vlc_value_t oldval, vlc_value_t new_val, void *param)
487 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
488 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(updateVolume) withObject:nil waitUntilDone:NO];
494 static int BossCallback(vlc_object_t *p_this, const char *psz_var,
495 vlc_value_t oldval, vlc_value_t new_val, void *param)
497 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
499 [[VLCCoreInteraction sharedInstance] performSelectorOnMainThread:@selector(pause) withObject:nil waitUntilDone:NO];
500 [[VLCApplication sharedApplication] hide:nil];
506 /*****************************************************************************
507 * ShowController: Callback triggered by the show-intf playlist variable
508 * through the ShowIntf-control-intf, to let us show the controller-win;
509 * usually when in fullscreen-mode
510 *****************************************************************************/
511 static int ShowController(vlc_object_t *p_this, const char *psz_variable,
512 vlc_value_t old_val, vlc_value_t new_val, void *param)
514 intf_thread_t * p_intf = VLCIntf;
515 if (p_intf && p_intf->p_sys) {
516 playlist_t * p_playlist = pl_Get(p_intf);
517 BOOL b_fullscreen = var_GetBool(p_playlist, "fullscreen");
518 if (strcmp(psz_variable, "intf-toggle-fscontrol") || b_fullscreen)
519 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(showFullscreenController) withObject:nil waitUntilDone:NO];
521 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(showMainWindow) withObject:nil waitUntilDone:NO];
526 /*****************************************************************************
527 * DialogCallback: Callback triggered by the "dialog-*" variables
528 * to let the intf display error and interaction dialogs
529 *****************************************************************************/
530 static int DialogCallback(vlc_object_t *p_this, const char *type, vlc_value_t previous, vlc_value_t value, void *data)
532 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
533 VLCMain *interface = (VLCMain *)data;
535 if ([@(type) isEqualToString: @"dialog-progress-bar"]) {
536 /* the progress panel needs to update itself and therefore wants special treatment within this context */
537 dialog_progress_bar_t *p_dialog = (dialog_progress_bar_t *)value.p_address;
539 p_dialog->pf_update = updateProgressPanel;
540 p_dialog->pf_check = checkProgressPanel;
541 p_dialog->pf_destroy = destroyProgressPanel;
542 p_dialog->p_sys = VLCIntf->p_libvlc;
545 NSValue *o_value = [NSValue valueWithPointer:value.p_address];
546 [[VLCCoreDialogProvider sharedInstance] performEventWithObject: o_value ofType: type];
552 void updateProgressPanel (void *priv, const char *text, float value)
554 NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
562 [[[VLCMain sharedInstance] coreDialogProvider] updateProgressPanelWithText: o_txt andNumber: (double)(value * 1000.)];
567 void destroyProgressPanel (void *priv)
569 NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
571 if ([[NSApplication sharedApplication] isRunning])
572 [[[VLCMain sharedInstance] coreDialogProvider] performSelectorOnMainThread:@selector(destroyProgressPanel) withObject:nil waitUntilDone:YES];
577 bool checkProgressPanel (void *priv)
579 NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
580 return [[[VLCMain sharedInstance] coreDialogProvider] progressCancelled];
587 input_thread_t *getInput(void)
589 intf_thread_t *p_intf = VLCIntf;
592 return pl_CurrentInput(p_intf);
595 vout_thread_t *getVout(void)
597 input_thread_t *p_input = getInput();
600 vout_thread_t *p_vout = input_GetVout(p_input);
601 vlc_object_release(p_input);
605 vout_thread_t *getVoutForActiveWindow(void)
607 vout_thread_t *p_vout = nil;
609 id currentWindow = [NSApp keyWindow];
610 if ([currentWindow respondsToSelector:@selector(videoView)]) {
611 VLCVoutView *videoView = [currentWindow videoView];
613 p_vout = [videoView voutThread];
623 audio_output_t *getAout(void)
625 intf_thread_t *p_intf = VLCIntf;
628 return playlist_GetAout(pl_Get(p_intf));
634 @interface VLCMain ()
635 - (void)removeOldPreferences;
638 @interface VLCMain (Internal)
639 - (void)handlePortMessage:(NSPortMessage *)o_msg;
640 - (void)resetMediaKeyJump;
641 - (void)coreChangedMediaKeySupportSetting: (NSNotification *)o_notification;
644 /*****************************************************************************
645 * VLCMain implementation
646 *****************************************************************************/
647 @implementation VLCMain
649 @synthesize voutController=o_vout_controller;
650 @synthesize nativeFullscreenMode=b_nativeFullscreenMode;
651 @synthesize playlistUpdatedSelectorInQueue=b_playlist_updated_selector_in_queue;
654 #pragma mark Initialization
656 static VLCMain *_o_sharedMainInstance = nil;
658 + (VLCMain *)sharedInstance
660 return _o_sharedMainInstance ? _o_sharedMainInstance : [[self alloc] init];
665 if (_o_sharedMainInstance) {
667 return _o_sharedMainInstance;
669 _o_sharedMainInstance = [super init];
672 p_current_input = p_input_changed = NULL;
674 o_msg_lock = [[NSLock alloc] init];
675 o_msg_arr = [[NSMutableArray arrayWithCapacity: 600] retain];
677 o_open = [[VLCOpen alloc] init];
678 o_coredialogs = [[VLCCoreDialogProvider alloc] init];
679 o_info = [[VLCInfo alloc] init];
680 o_mainmenu = [[VLCMainMenu alloc] init];
681 o_coreinteraction = [[VLCCoreInteraction alloc] init];
682 o_eyetv = [[VLCEyeTVController alloc] init];
683 o_mainwindow = [[VLCMainWindow alloc] init];
685 /* announce our launch to a potential eyetv plugin */
686 [[NSDistributedNotificationCenter defaultCenter] postNotificationName: @"VLCOSXGUIInit"
687 object: @"VLCEyeTVSupport"
689 deliverImmediately: YES];
691 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
692 NSDictionary *appDefaults = [NSDictionary dictionaryWithObject:@"NO" forKey:@"LiveUpdateTheMessagesPanel"];
693 [defaults registerDefaults:appDefaults];
695 o_vout_controller = [[VLCVoutWindowController alloc] init];
697 return _o_sharedMainInstance;
700 - (void)setIntf: (intf_thread_t *)p_mainintf
705 - (intf_thread_t *)intf
712 playlist_t *p_playlist;
715 var_Create(p_intf, "intf-change", VLC_VAR_BOOL);
717 /* Check if we already did this once. Opening the other nibs calls it too,
718 because VLCMain is the owner */
722 [o_msgs_panel setExcludedFromWindowsMenu: YES];
723 [o_msgs_panel setDelegate: self];
725 p_playlist = pl_Get(p_intf);
729 var_AddCallback(p_intf->p_libvlc, "intf-toggle-fscontrol", ShowController, self);
730 var_AddCallback(p_intf->p_libvlc, "intf-show", ShowController, self);
731 var_AddCallback(p_intf->p_libvlc, "intf-boss", BossCallback, self);
732 // var_AddCallback(p_playlist, "item-change", PLItemChanged, self);
733 var_AddCallback(p_playlist, "activity", PLItemChanged, self);
734 var_AddCallback(p_playlist, "leaf-to-parent", PlaylistUpdated, self);
735 var_AddCallback(p_playlist, "playlist-item-append", PlaylistUpdated, self);
736 var_AddCallback(p_playlist, "playlist-item-deleted", PlaylistUpdated, self);
737 var_AddCallback(p_playlist, "random", PlaybackModeUpdated, self);
738 var_AddCallback(p_playlist, "repeat", PlaybackModeUpdated, self);
739 var_AddCallback(p_playlist, "loop", PlaybackModeUpdated, self);
740 var_AddCallback(p_playlist, "volume", VolumeUpdated, self);
741 var_AddCallback(p_playlist, "mute", VolumeUpdated, self);
743 if (!OSX_SNOW_LEOPARD) {
744 if ([NSApp currentSystemPresentationOptions] & NSApplicationPresentationFullScreen)
745 var_SetBool(p_playlist, "fullscreen", YES);
748 /* load our Core and Shared Dialogs nibs */
749 nib_coredialogs_loaded = [NSBundle loadNibNamed:@"CoreDialogs" owner: NSApp];
750 [NSBundle loadNibNamed:@"SharedDialogs" owner: NSApp];
752 /* subscribe to various interactive dialogues */
753 var_Create(p_intf, "dialog-error", VLC_VAR_ADDRESS);
754 var_AddCallback(p_intf, "dialog-error", DialogCallback, self);
755 var_Create(p_intf, "dialog-critical", VLC_VAR_ADDRESS);
756 var_AddCallback(p_intf, "dialog-critical", DialogCallback, self);
757 var_Create(p_intf, "dialog-login", VLC_VAR_ADDRESS);
758 var_AddCallback(p_intf, "dialog-login", DialogCallback, self);
759 var_Create(p_intf, "dialog-question", VLC_VAR_ADDRESS);
760 var_AddCallback(p_intf, "dialog-question", DialogCallback, self);
761 var_Create(p_intf, "dialog-progress-bar", VLC_VAR_ADDRESS);
762 var_AddCallback(p_intf, "dialog-progress-bar", DialogCallback, self);
763 dialog_Register(p_intf);
765 /* init Apple Remote support */
766 o_remote = [[AppleRemote alloc] init];
767 [o_remote setClickCountEnabledButtons: kRemoteButtonPlay];
768 [o_remote setDelegate: _o_sharedMainInstance];
770 [o_msgs_refresh_btn setImage: [NSImage imageNamed: NSImageNameRefreshTemplate]];
772 /* yeah, we are done */
773 b_nativeFullscreenMode = NO;
774 #ifdef MAC_OS_X_VERSION_10_7
775 if (!OSX_SNOW_LEOPARD)
776 b_nativeFullscreenMode = var_InheritBool(p_intf, "macosx-nativefullscreenmode");
779 if (config_GetInt(VLCIntf, "macosx-icon-change")) {
780 /* After day 354 of the year, the usual VLC cone is replaced by another cone
781 * wearing a Father Xmas hat.
782 * Note: this icon doesn't represent an endorsement of The Coca-Cola Company.
784 NSCalendar *gregorian =
785 [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
786 NSUInteger dayOfYear = [gregorian ordinalityOfUnit:NSDayCalendarUnit inUnit:NSYearCalendarUnit forDate:[NSDate date]];
789 if (dayOfYear >= 354)
790 [[VLCApplication sharedApplication] setApplicationIconImage: [NSImage imageNamed:@"vlc-xmas"]];
795 nib_main_loaded = TRUE;
798 - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
803 [self updateCurrentlyUsedHotkeys];
805 /* init media key support */
806 b_mediaKeySupport = var_InheritBool(VLCIntf, "macosx-mediakeys");
807 if (b_mediaKeySupport) {
808 o_mediaKeyController = [[SPMediaKeyTap alloc] initWithDelegate:self];
809 [[NSUserDefaults standardUserDefaults] registerDefaults:[NSDictionary dictionaryWithObjectsAndKeys:
810 [SPMediaKeyTap defaultMediaKeyUserBundleIdentifiers], kMediaKeyUsingBundleIdentifiersDefaultsKey,
813 [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(coreChangedMediaKeySupportSetting:) name: @"VLCMediaKeySupportSettingChanged" object: nil];
815 [self removeOldPreferences];
817 /* Handle sleep notification */
818 [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(computerWillSleep:)
819 name:NSWorkspaceWillSleepNotification object:nil];
821 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(lookForCrashLog) withObject:nil waitUntilDone:NO];
823 /* we will need this, so let's load it here so the interface appears to be more responsive */
824 nib_open_loaded = [NSBundle loadNibNamed:@"Open" owner: NSApp];
826 /* update the main window */
827 [o_mainwindow updateWindow];
828 [o_mainwindow updateTimeSlider];
829 [o_mainwindow updateVolumeSlider];
838 [o_msgs_panel setTitle: _NS("Messages")];
839 [o_msgs_crashlog_btn setTitle: _NS("Open CrashLog...")];
840 [o_msgs_save_btn setTitle: _NS("Save this Log...")];
842 /* crash reporter panel */
843 [o_crashrep_send_btn setTitle: _NS("Send")];
844 [o_crashrep_dontSend_btn setTitle: _NS("Don't Send")];
845 [o_crashrep_title_txt setStringValue: _NS("VLC crashed previously")];
846 [o_crashrep_win setTitle: _NS("VLC crashed previously")];
847 [o_crashrep_desc_txt setStringValue: _NS("Do you want to send details on the crash to VLC's development team?\n\nIf you want, you can enter a few lines on what you did before VLC crashed along with other helpful information: a link to download a sample file, a URL of a network stream, ...")];
848 [o_crashrep_includeEmail_ckb setTitle: _NS("I agree to be possibly contacted about this bugreport.")];
849 [o_crashrep_includeEmail_txt setStringValue: _NS("Only your default E-Mail address will be submitted, including no further information.")];
850 [o_crashrep_dontaskagain_ckb setTitle: _NS("Don't ask again")];
854 #pragma mark Termination
856 - (void)applicationWillTerminate:(NSNotification *)notification
858 /* don't allow a double termination call. If the user has
859 * already invoked the quit then simply return this time. */
860 static bool f_appExit = false;
864 isTerminating = f_appExit;
871 [self resumeItunesPlayback:nil];
873 if (notification == nil)
874 [[NSNotificationCenter defaultCenter] postNotificationName: NSApplicationWillTerminateNotification object: nil];
876 playlist_t * p_playlist = pl_Get(p_intf);
877 int returnedValue = 0;
879 /* always exit fullscreen on quit, otherwise we get ugly artifacts on the next launch */
880 if (b_nativeFullscreenMode) {
881 [o_mainwindow toggleFullScreen: self];
882 [NSApp setPresentationOptions:(NSApplicationPresentationDefault)];
885 /* save current video and audio profiles */
886 [[VLCVideoEffects sharedInstance] saveCurrentProfile];
887 [[VLCAudioEffects sharedInstance] saveCurrentProfile];
889 /* Save some interface state in configuration, at module quit */
890 config_PutInt(p_intf, "random", var_GetBool(p_playlist, "random"));
891 config_PutInt(p_intf, "loop", var_GetBool(p_playlist, "loop"));
892 config_PutInt(p_intf, "repeat", var_GetBool(p_playlist, "repeat"));
894 msg_Dbg(p_intf, "Terminating");
896 /* unsubscribe from the interactive dialogues */
897 dialog_Unregister(p_intf);
898 var_DelCallback(p_intf, "dialog-error", DialogCallback, self);
899 var_DelCallback(p_intf, "dialog-critical", DialogCallback, self);
900 var_DelCallback(p_intf, "dialog-login", DialogCallback, self);
901 var_DelCallback(p_intf, "dialog-question", DialogCallback, self);
902 var_DelCallback(p_intf, "dialog-progress-bar", DialogCallback, self);
903 //var_DelCallback(p_playlist, "item-change", PLItemChanged, self);
904 var_DelCallback(p_playlist, "activity", PLItemChanged, self);
905 var_DelCallback(p_playlist, "leaf-to-parent", PlaylistUpdated, self);
906 var_DelCallback(p_playlist, "playlist-item-append", PlaylistUpdated, self);
907 var_DelCallback(p_playlist, "playlist-item-deleted", PlaylistUpdated, self);
908 var_DelCallback(p_playlist, "random", PlaybackModeUpdated, self);
909 var_DelCallback(p_playlist, "repeat", PlaybackModeUpdated, self);
910 var_DelCallback(p_playlist, "loop", PlaybackModeUpdated, self);
911 var_DelCallback(p_playlist, "volume", VolumeUpdated, self);
912 var_DelCallback(p_playlist, "mute", VolumeUpdated, self);
913 var_DelCallback(p_intf->p_libvlc, "intf-toggle-fscontrol", ShowController, self);
914 var_DelCallback(p_intf->p_libvlc, "intf-show", ShowController, self);
915 var_DelCallback(p_intf->p_libvlc, "intf-boss", BossCallback, self);
917 if (p_current_input) {
918 var_DelCallback(p_current_input, "intf-event", InputEvent, [VLCMain sharedInstance]);
919 vlc_object_release(p_current_input);
920 p_current_input = NULL;
923 /* remove global observer watching for vout device changes correctly */
924 [[NSNotificationCenter defaultCenter] removeObserver: self];
926 [o_vout_provider_lock lock];
927 // release before o_info!
928 [o_vout_controller release];
929 o_vout_controller = nil;
930 [o_vout_provider_lock unlock];
932 /* release some other objects here, because it isn't sure whether dealloc
933 * will be called later on */
948 [crashLogURLConnection cancel];
949 [crashLogURLConnection release];
951 [o_coredialogs release];
954 /* unsubscribe from libvlc's debug messages */
955 vlc_LogSet(p_intf->p_libvlc, NULL, NULL);
957 [o_msg_arr removeAllObjects];
960 [o_usedHotkeys release];
961 o_usedHotkeys = NULL;
963 [o_mediaKeyController release];
965 [o_msg_lock release];
967 /* write cached user defaults to disk */
968 [[NSUserDefaults standardUserDefaults] synchronize];
971 [o_mainmenu release];
973 libvlc_Quit(p_intf->p_libvlc);
975 [o_mainwindow release];
982 #pragma mark Sparkle delegate
983 /* received directly before the update gets installed, so let's shut down a bit */
984 - (void)updater:(SUUpdater *)updater willInstallUpdate:(SUAppcastItem *)update
986 [NSApp activateIgnoringOtherApps:YES];
987 [o_remote stopListening: self];
988 [[VLCCoreInteraction sharedInstance] stop];
992 #pragma mark Media Key support
994 -(void)mediaKeyTap:(SPMediaKeyTap*)keyTap receivedMediaKeyEvent:(NSEvent*)event
996 if (b_mediaKeySupport) {
997 assert([event type] == NSSystemDefined && [event subtype] == SPSystemDefinedEventMediaKeys);
999 int keyCode = (([event data1] & 0xFFFF0000) >> 16);
1000 int keyFlags = ([event data1] & 0x0000FFFF);
1001 int keyState = (((keyFlags & 0xFF00) >> 8)) == 0xA;
1002 int keyRepeat = (keyFlags & 0x1);
1004 if (keyCode == NX_KEYTYPE_PLAY && keyState == 0)
1005 [[VLCCoreInteraction sharedInstance] playOrPause];
1007 if ((keyCode == NX_KEYTYPE_FAST || keyCode == NX_KEYTYPE_NEXT) && !b_mediakeyJustJumped) {
1008 if (keyState == 0 && keyRepeat == 0)
1009 [[VLCCoreInteraction sharedInstance] next];
1010 else if (keyRepeat == 1) {
1011 [[VLCCoreInteraction sharedInstance] forwardShort];
1012 b_mediakeyJustJumped = YES;
1013 [self performSelector:@selector(resetMediaKeyJump)
1019 if ((keyCode == NX_KEYTYPE_REWIND || keyCode == NX_KEYTYPE_PREVIOUS) && !b_mediakeyJustJumped) {
1020 if (keyState == 0 && keyRepeat == 0)
1021 [[VLCCoreInteraction sharedInstance] previous];
1022 else if (keyRepeat == 1) {
1023 [[VLCCoreInteraction sharedInstance] backwardShort];
1024 b_mediakeyJustJumped = YES;
1025 [self performSelector:@selector(resetMediaKeyJump)
1034 #pragma mark Other notification
1036 /* Listen to the remote in exclusive mode, only when VLC is the active
1038 - (void)applicationDidBecomeActive:(NSNotification *)aNotification
1042 if (var_InheritBool(p_intf, "macosx-appleremote") == YES)
1043 [o_remote startListening: self];
1045 - (void)applicationDidResignActive:(NSNotification *)aNotification
1049 [o_remote stopListening: self];
1052 /* Triggered when the computer goes to sleep */
1053 - (void)computerWillSleep: (NSNotification *)notification
1055 [[VLCCoreInteraction sharedInstance] pause];
1059 #pragma mark File opening over dock icon
1061 - (void)application:(NSApplication *)o_app openFiles:(NSArray *)o_names
1063 BOOL b_autoplay = config_GetInt(VLCIntf, "macosx-autoplay");
1064 char *psz_uri = vlc_path2uri([o_names[0] UTF8String], "file");
1066 // try to add file as subtitle
1067 if ([o_names count] == 1 && psz_uri) {
1068 input_thread_t * p_input = pl_CurrentInput(VLCIntf);
1070 BOOL b_returned = NO;
1071 b_returned = input_AddSubtitle(p_input, psz_uri, true);
1072 vlc_object_release(p_input);
1081 NSArray *o_sorted_names = [o_names sortedArrayUsingSelector: @selector(caseInsensitiveCompare:)];
1082 NSMutableArray *o_result = [NSMutableArray arrayWithCapacity: [o_sorted_names count]];
1083 for (int i = 0; i < [o_sorted_names count]; i++) {
1084 psz_uri = vlc_path2uri([o_sorted_names[i] UTF8String], "file");
1088 NSDictionary *o_dic = [NSDictionary dictionaryWithObject:[NSString stringWithCString:psz_uri encoding:NSUTF8StringEncoding] forKey:@"ITEM_URL"];
1090 [o_result addObject: o_dic];
1094 [o_playlist appendArray: o_result atPos: -1 enqueue: NO];
1096 [o_playlist appendArray: o_result atPos: -1 enqueue: YES];
1101 /* When user click in the Dock icon our double click in the finder */
1102 - (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)hasVisibleWindows
1104 if (!hasVisibleWindows)
1105 [o_mainwindow makeKeyAndOrderFront:self];
1111 #pragma mark Apple Remote Control
1113 /* Helper method for the remote control interface in order to trigger forward/backward and volume
1114 increase/decrease as long as the user holds the left/right, plus/minus button */
1115 - (void) executeHoldActionForRemoteButton: (NSNumber*) buttonIdentifierNumber
1117 if (b_remote_button_hold) {
1118 switch([buttonIdentifierNumber intValue]) {
1119 case kRemoteButtonRight_Hold:
1120 [[VLCCoreInteraction sharedInstance] forward];
1122 case kRemoteButtonLeft_Hold:
1123 [[VLCCoreInteraction sharedInstance] backward];
1125 case kRemoteButtonVolume_Plus_Hold:
1127 var_SetInteger(p_intf->p_libvlc, "key-action", ACTIONID_VOL_UP);
1129 case kRemoteButtonVolume_Minus_Hold:
1131 var_SetInteger(p_intf->p_libvlc, "key-action", ACTIONID_VOL_DOWN);
1134 if (b_remote_button_hold) {
1136 [self performSelector:@selector(executeHoldActionForRemoteButton:)
1137 withObject:buttonIdentifierNumber
1143 /* Apple Remote callback */
1144 - (void) appleRemoteButton: (AppleRemoteEventIdentifier)buttonIdentifier
1145 pressedDown: (BOOL) pressedDown
1146 clickCount: (unsigned int) count
1148 switch(buttonIdentifier) {
1149 case k2009RemoteButtonFullscreen:
1150 [[VLCCoreInteraction sharedInstance] toggleFullscreen];
1152 case k2009RemoteButtonPlay:
1153 [[VLCCoreInteraction sharedInstance] playOrPause];
1155 case kRemoteButtonPlay:
1157 [[VLCCoreInteraction sharedInstance] toggleFullscreen];
1159 [[VLCCoreInteraction sharedInstance] playOrPause];
1161 case kRemoteButtonVolume_Plus:
1162 if (config_GetInt(VLCIntf, "macosx-appleremote-sysvol"))
1163 [NSSound increaseSystemVolume];
1166 var_SetInteger(p_intf->p_libvlc, "key-action", ACTIONID_VOL_UP);
1168 case kRemoteButtonVolume_Minus:
1169 if (config_GetInt(VLCIntf, "macosx-appleremote-sysvol"))
1170 [NSSound decreaseSystemVolume];
1173 var_SetInteger(p_intf->p_libvlc, "key-action", ACTIONID_VOL_DOWN);
1175 case kRemoteButtonRight:
1176 if (config_GetInt(VLCIntf, "macosx-appleremote-prevnext"))
1177 [[VLCCoreInteraction sharedInstance] forward];
1179 [[VLCCoreInteraction sharedInstance] next];
1181 case kRemoteButtonLeft:
1182 if (config_GetInt(VLCIntf, "macosx-appleremote-prevnext"))
1183 [[VLCCoreInteraction sharedInstance] backward];
1185 [[VLCCoreInteraction sharedInstance] previous];
1187 case kRemoteButtonRight_Hold:
1188 case kRemoteButtonLeft_Hold:
1189 case kRemoteButtonVolume_Plus_Hold:
1190 case kRemoteButtonVolume_Minus_Hold:
1191 /* simulate an event as long as the user holds the button */
1192 b_remote_button_hold = pressedDown;
1194 NSNumber* buttonIdentifierNumber = @(buttonIdentifier);
1195 [self performSelector:@selector(executeHoldActionForRemoteButton:)
1196 withObject:buttonIdentifierNumber];
1199 case kRemoteButtonMenu:
1200 [o_controls showPosition: self]; //FIXME
1202 case kRemoteButtonPlay_Sleep:
1204 NSAppleScript * script = [[NSAppleScript alloc] initWithSource:@"tell application \"System Events\" to sleep"];
1205 [script executeAndReturnError:nil];
1210 /* Add here whatever you want other buttons to do */
1216 #pragma mark Key Shortcuts
1218 /*****************************************************************************
1219 * hasDefinedShortcutKey: Check to see if the key press is a defined VLC
1220 * shortcut key. If it is, pass it off to VLC for handling and return YES,
1221 * otherwise ignore it and return NO (where it will get handled by Cocoa).
1222 *****************************************************************************/
1223 - (BOOL)hasDefinedShortcutKey:(NSEvent *)o_event force:(BOOL)b_force
1227 unsigned int i_pressed_modifiers = 0;
1230 i_pressed_modifiers = [o_event modifierFlags];
1232 if (i_pressed_modifiers & NSControlKeyMask)
1233 val.i_int |= KEY_MODIFIER_CTRL;
1235 if (i_pressed_modifiers & NSAlternateKeyMask)
1236 val.i_int |= KEY_MODIFIER_ALT;
1238 if (i_pressed_modifiers & NSShiftKeyMask)
1239 val.i_int |= KEY_MODIFIER_SHIFT;
1241 if (i_pressed_modifiers & NSCommandKeyMask)
1242 val.i_int |= KEY_MODIFIER_COMMAND;
1244 NSString * characters = [o_event charactersIgnoringModifiers];
1245 if ([characters length] > 0) {
1246 key = [[characters lowercaseString] characterAtIndex: 0];
1248 /* handle Lion's default key combo for fullscreen-toggle in addition to our own hotkeys */
1249 if (key == 'f' && i_pressed_modifiers & NSControlKeyMask && i_pressed_modifiers & NSCommandKeyMask) {
1250 [[VLCCoreInteraction sharedInstance] toggleFullscreen];
1256 case NSDeleteCharacter:
1257 case NSDeleteFunctionKey:
1258 case NSDeleteCharFunctionKey:
1259 case NSBackspaceCharacter:
1260 case NSUpArrowFunctionKey:
1261 case NSDownArrowFunctionKey:
1262 case NSEnterCharacter:
1263 case NSCarriageReturnCharacter:
1268 val.i_int |= CocoaKeyToVLC(key);
1270 BOOL b_found_key = NO;
1271 for (int i = 0; i < [o_usedHotkeys count]; i++) {
1272 NSString *str = o_usedHotkeys[i];
1273 unsigned int i_keyModifiers = [[VLCStringUtility sharedInstance] VLCModifiersToCocoa: str];
1275 if ([[characters lowercaseString] isEqualToString: [[VLCStringUtility sharedInstance] VLCKeyToString: str]] &&
1276 (i_keyModifiers & NSShiftKeyMask) == (i_pressed_modifiers & NSShiftKeyMask) &&
1277 (i_keyModifiers & NSControlKeyMask) == (i_pressed_modifiers & NSControlKeyMask) &&
1278 (i_keyModifiers & NSAlternateKeyMask) == (i_pressed_modifiers & NSAlternateKeyMask) &&
1279 (i_keyModifiers & NSCommandKeyMask) == (i_pressed_modifiers & NSCommandKeyMask)) {
1286 var_SetInteger(p_intf->p_libvlc, "key-pressed", val.i_int);
1294 - (void)updateCurrentlyUsedHotkeys
1296 NSMutableArray *o_tempArray = [[NSMutableArray alloc] init];
1297 /* Get the main Module */
1298 module_t *p_main = module_get_main();
1301 module_config_t *p_config;
1303 p_config = module_config_get (p_main, &confsize);
1305 for (size_t i = 0; i < confsize; i++) {
1306 module_config_t *p_item = p_config + i;
1308 if (CONFIG_ITEM(p_item->i_type) && p_item->psz_name != NULL
1309 && !strncmp(p_item->psz_name , "key-", 4)
1310 && !EMPTY_STR(p_item->psz_text)) {
1311 if (p_item->value.psz)
1312 [o_tempArray addObject: @(p_item->value.psz)];
1315 module_config_free (p_config);
1318 [o_usedHotkeys release];
1319 o_usedHotkeys = [[NSArray alloc] initWithArray: o_tempArray copyItems: YES];
1320 [o_tempArray release];
1324 #pragma mark Interface updaters
1326 - (void)PlaylistItemChanged
1328 if (p_current_input && (p_current_input->b_dead || !vlc_object_alive(p_current_input))) {
1329 var_DelCallback(p_current_input, "intf-event", InputEvent, [VLCMain sharedInstance]);
1330 p_input_changed = p_current_input;
1331 p_current_input = NULL;
1333 [o_mainmenu setRateControlsEnabled: NO];
1335 else if (!p_current_input) {
1336 // object is hold here and released then it is dead
1337 p_current_input = playlist_CurrentInput(pl_Get(VLCIntf));
1338 if (p_current_input) {
1339 var_AddCallback(p_current_input, "intf-event", InputEvent, [VLCMain sharedInstance]);
1340 [self playbackStatusUpdated];
1341 [o_mainmenu setRateControlsEnabled: YES];
1342 if ([self activeVideoPlayback] && [[o_mainwindow videoView] isHidden])
1343 [o_mainwindow performSelectorOnMainThread:@selector(togglePlaylist:) withObject: nil waitUntilDone:NO];
1344 p_input_changed = vlc_object_hold(p_current_input);
1348 [o_playlist updateRowSelection];
1349 [o_mainwindow updateWindow];
1350 [self updateDelays];
1351 [self updateMainMenu];
1354 - (void)informInputChanged
1356 if (p_input_changed) {
1357 [[ExtensionsManager getInstance:p_intf] inputChanged:p_input_changed];
1358 vlc_object_release(p_input_changed);
1359 p_input_changed = NULL;
1363 - (void)updateMainMenu
1365 [o_mainmenu setupMenus];
1366 [o_mainmenu updatePlaybackRate];
1367 [[VLCCoreInteraction sharedInstance] resetAtoB];
1370 - (void)updateMainWindow
1372 [o_mainwindow updateWindow];
1375 - (void)showMainWindow
1377 [o_mainwindow performSelectorOnMainThread:@selector(makeKeyAndOrderFront:) withObject:nil waitUntilDone:NO];
1380 - (void)showFullscreenController
1382 [o_mainwindow performSelectorOnMainThread:@selector(showFullscreenController) withObject:nil waitUntilDone:NO];
1385 - (void)updateDelays
1387 [[VLCTrackSynchronization sharedInstance] performSelectorOnMainThread: @selector(updateValues) withObject: nil waitUntilDone:NO];
1392 [o_mainwindow updateName];
1395 - (void)updatePlaybackPosition
1397 [o_mainwindow updateTimeSlider];
1398 [[VLCCoreInteraction sharedInstance] updateAtoB];
1401 - (void)updateVolume
1403 [o_mainwindow updateVolumeSlider];
1406 - (void)playlistUpdated
1408 @synchronized(self) {
1409 b_playlist_updated_selector_in_queue = NO;
1412 [self playbackStatusUpdated];
1413 [o_playlist playlistUpdated];
1414 [o_mainwindow updateWindow];
1415 [o_mainwindow updateName];
1417 [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCMediaKeySupportSettingChanged"
1422 - (void)updateRecordState: (BOOL)b_value
1424 [o_mainmenu updateRecordState:b_value];
1427 - (void)updateInfoandMetaPanel
1429 [o_playlist outlineViewSelectionDidChange:nil];
1432 - (void)resumeItunesPlayback:(id)sender
1434 if (b_has_itunes_paused && var_InheritInteger(p_intf, "macosx-control-itunes") > 1) {
1435 iTunesApplication *iTunesApp = [SBApplication applicationWithBundleIdentifier:@"com.apple.iTunes"];
1436 if (iTunesApp && [iTunesApp isRunning]) {
1437 if ([iTunesApp playerState] == iTunesEPlSPaused) {
1438 msg_Dbg(p_intf, "Unpause iTunes...");
1439 [iTunesApp playpause];
1445 b_has_itunes_paused = NO;
1446 o_itunes_play_timer = nil;
1449 - (void)playbackStatusUpdated
1452 if (p_current_input) {
1453 state = var_GetInteger(p_current_input, "state");
1456 int i_control_itunes = var_InheritInteger(p_intf, "macosx-control-itunes");
1457 // cancel itunes timer if next item starts playing
1458 if (state > -1 && state != END_S && i_control_itunes > 0) {
1459 if (o_itunes_play_timer) {
1460 [o_itunes_play_timer invalidate];
1461 o_itunes_play_timer = nil;
1465 if (state == PLAYING_S) {
1467 if (i_control_itunes > 0 && !b_has_itunes_paused) {
1468 iTunesApplication *iTunesApp = [SBApplication applicationWithBundleIdentifier:@"com.apple.iTunes"];
1469 if (iTunesApp && [iTunesApp isRunning]) {
1470 if ([iTunesApp playerState] == iTunesEPlSPlaying) {
1471 msg_Dbg(p_intf, "Pause iTunes...");
1473 b_has_itunes_paused = YES;
1479 /* Declare user activity.
1480 This wakes the display if it is off, and postpones display sleep according to the users system preferences
1481 Available from 10.7.3 */
1482 #ifdef MAC_OS_X_VERSION_10_7
1483 if ([self activeVideoPlayback] && IOPMAssertionDeclareUserActivity)
1485 CFStringRef reasonForActivity = CFStringCreateWithCString(kCFAllocatorDefault, _("VLC media playback"), kCFStringEncodingUTF8);
1486 IOPMAssertionDeclareUserActivity(reasonForActivity,
1487 kIOPMUserActiveLocal,
1488 &userActivityAssertionID);
1489 CFRelease(reasonForActivity);
1493 /* prevent the system from sleeping */
1494 if (systemSleepAssertionID > 0) {
1495 msg_Dbg(VLCIntf, "releasing old sleep blocker (%i)" , systemSleepAssertionID);
1496 IOPMAssertionRelease(systemSleepAssertionID);
1500 /* 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 */
1501 if ((NSAppKitVersionNumber >= 1115.2 && NSAppKitVersionNumber < 1138.45) || OSX_MOUNTAIN_LION || OSX_SNOW_LEOPARD) {
1502 CFStringRef reasonForActivity = CFStringCreateWithCString(kCFAllocatorDefault, _("VLC media playback"), kCFStringEncodingUTF8);
1503 if ([self activeVideoPlayback])
1504 success = IOPMAssertionCreateWithName(kIOPMAssertionTypeNoDisplaySleep, kIOPMAssertionLevelOn, reasonForActivity, &systemSleepAssertionID);
1506 success = IOPMAssertionCreateWithName(kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn, reasonForActivity, &systemSleepAssertionID);
1507 CFRelease(reasonForActivity);
1509 /* fall-back on the 10.5 mode, which also works on 10.7.4 and 10.7.5 */
1510 if ([self activeVideoPlayback])
1511 success = IOPMAssertionCreate(kIOPMAssertionTypeNoDisplaySleep, kIOPMAssertionLevelOn, &systemSleepAssertionID);
1513 success = IOPMAssertionCreate(kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn, &systemSleepAssertionID);
1516 if (success == kIOReturnSuccess)
1517 msg_Dbg(VLCIntf, "prevented sleep through IOKit (%i)", systemSleepAssertionID);
1519 msg_Warn(VLCIntf, "failed to prevent system sleep through IOKit");
1521 [[self mainMenu] setPause];
1522 [o_mainwindow setPause];
1524 [o_mainmenu setSubmenusEnabled: FALSE];
1525 [[self mainMenu] setPlay];
1526 [o_mainwindow setPlay];
1528 /* allow the system to sleep again */
1529 if (systemSleepAssertionID > 0) {
1530 msg_Dbg(VLCIntf, "releasing sleep blocker (%i)" , systemSleepAssertionID);
1531 IOPMAssertionRelease(systemSleepAssertionID);
1534 if (state == END_S || state == -1) {
1535 if (i_control_itunes > 0) {
1536 if (o_itunes_play_timer) {
1537 [o_itunes_play_timer invalidate];
1539 o_itunes_play_timer = [NSTimer scheduledTimerWithTimeInterval: 0.5
1541 selector: @selector(resumeItunesPlayback:)
1548 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(updateMainWindow) withObject: nil waitUntilDone: NO];
1549 [self performSelectorOnMainThread:@selector(sendDistributedNotificationWithUpdatedPlaybackStatus) withObject: nil waitUntilDone: NO];
1552 - (void)sendDistributedNotificationWithUpdatedPlaybackStatus
1554 [[NSDistributedNotificationCenter defaultCenter] postNotificationName:@"VLCPlayerStateDidChange"
1557 deliverImmediately:YES];
1560 - (void)playbackModeUpdated
1562 vlc_value_t looping,repeating;
1563 playlist_t * p_playlist = pl_Get(VLCIntf);
1565 bool loop = var_GetBool(p_playlist, "loop");
1566 bool repeat = var_GetBool(p_playlist, "repeat");
1568 [[o_mainwindow controlsBar] setRepeatOne];
1569 [o_mainmenu setRepeatOne];
1571 [[o_mainwindow controlsBar] setRepeatAll];
1572 [o_mainmenu setRepeatAll];
1574 [[o_mainwindow controlsBar] setRepeatOff];
1575 [o_mainmenu setRepeatOff];
1578 [[o_mainwindow controlsBar] setShuffle];
1579 [o_mainmenu setShuffle];
1583 #pragma mark Window updater
1585 - (void)setActiveVideoPlayback:(BOOL)b_value
1587 b_active_videoplayback = b_value;
1589 [o_mainwindow performSelectorOnMainThread:@selector(setVideoplayEnabled) withObject:nil waitUntilDone:YES];
1590 [o_mainwindow performSelectorOnMainThread:@selector(togglePlaylist:) withObject:nil waitUntilDone:NO];
1593 // update sleep blockers
1594 [self performSelectorOnMainThread:@selector(playbackStatusUpdated) withObject:nil waitUntilDone:NO];
1598 #pragma mark Other objects getters
1605 - (VLCMainWindow *)mainWindow
1607 return o_mainwindow;
1621 o_bookmarks = [[VLCBookmarks alloc] init];
1623 if (!nib_bookmarks_loaded)
1624 nib_bookmarks_loaded = [NSBundle loadNibNamed:@"Bookmarks" owner: NSApp];
1634 if (!nib_open_loaded)
1635 nib_open_loaded = [NSBundle loadNibNamed:@"Open" owner: NSApp];
1640 - (id)simplePreferences
1643 o_sprefs = [[VLCSimplePrefs alloc] init];
1645 if (!nib_prefs_loaded)
1646 nib_prefs_loaded = [NSBundle loadNibNamed:@"Preferences" owner: NSApp];
1654 o_prefs = [[VLCPrefs alloc] init];
1656 if (!nib_prefs_loaded)
1657 nib_prefs_loaded = [NSBundle loadNibNamed:@"Preferences" owner: NSApp];
1672 if (! nib_info_loaded)
1673 nib_info_loaded = [NSBundle loadNibNamed:@"MediaInfo" owner: NSApp];
1684 o_wizard = [[VLCWizard alloc] init];
1686 if (!nib_wizard_loaded) {
1687 nib_wizard_loaded = [NSBundle loadNibNamed:@"Wizard" owner: NSApp];
1688 [o_wizard initStrings];
1693 - (id)coreDialogProvider
1696 return o_coredialogs;
1701 - (id)eyeTVController
1709 - (id)appleRemoteController
1714 - (BOOL)activeVideoPlayback
1716 return b_active_videoplayback;
1720 #pragma mark Crash Log
1721 - (void)sendCrashLog:(NSString *)crashLog withUserComment:(NSString *)userComment
1723 NSString *urlStr = @"http://crash.videolan.org/crashlog/sendcrashreport.php";
1724 NSURL *url = [NSURL URLWithString:urlStr];
1726 NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
1727 [req setHTTPMethod:@"POST"];
1730 if ([o_crashrep_includeEmail_ckb state] == NSOnState) {
1731 ABPerson * contact = [[ABAddressBook sharedAddressBook] me];
1732 ABMultiValue *emails = [contact valueForProperty:kABEmailProperty];
1733 email = [emails valueAtIndex:[emails indexForIdentifier:
1734 [emails primaryIdentifier]]];
1737 email = [NSString string];
1740 postBody = [NSString stringWithFormat:@"CrashLog=%@&Comment=%@&Email=%@\r\n",
1741 [crashLog stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
1742 [userComment stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
1743 [email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
1745 [req setHTTPBody:[postBody dataUsingEncoding:NSUTF8StringEncoding]];
1747 /* Released from delegate */
1748 crashLogURLConnection = [[NSURLConnection alloc] initWithRequest:req delegate:self];
1751 - (void)connectionDidFinishLoading:(NSURLConnection *)connection
1753 msg_Dbg(p_intf, "crash report successfully sent");
1754 [crashLogURLConnection release];
1755 crashLogURLConnection = nil;
1758 - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
1760 msg_Warn (p_intf, "Error when sending the crash report: %s (%li)", [[error localizedDescription] UTF8String], [error code]);
1761 [crashLogURLConnection release];
1762 crashLogURLConnection = nil;
1765 - (NSString *)latestCrashLogPathPreviouslySeen:(BOOL)previouslySeen
1767 NSString * crashReporter;
1768 if (OSX_MOUNTAIN_LION)
1769 crashReporter = [@"~/Library/Logs/DiagnosticReports" stringByExpandingTildeInPath];
1771 crashReporter = [@"~/Library/Logs/CrashReporter" stringByExpandingTildeInPath];
1772 NSDirectoryEnumerator *direnum = [[NSFileManager defaultManager] enumeratorAtPath:crashReporter];
1774 NSString * latestLog = nil;
1775 NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
1776 int year = !previouslySeen ? [defaults integerForKey:@"LatestCrashReportYear"] : 0;
1777 int month = !previouslySeen ? [defaults integerForKey:@"LatestCrashReportMonth"]: 0;
1778 int day = !previouslySeen ? [defaults integerForKey:@"LatestCrashReportDay"] : 0;
1779 int hours = !previouslySeen ? [defaults integerForKey:@"LatestCrashReportHours"]: 0;
1781 while (fname = [direnum nextObject]) {
1782 [direnum skipDescendents];
1783 if ([fname hasPrefix:@"VLC"] && [fname hasSuffix:@"crash"]) {
1784 NSArray * compo = [fname componentsSeparatedByString:@"_"];
1785 if ([compo count] < 3)
1787 compo = [compo[1] componentsSeparatedByString:@"-"];
1788 if ([compo count] < 4)
1792 if (year < [compo[0] intValue] ||
1793 (year ==[compo[0] intValue] &&
1794 (month < [compo[1] intValue] ||
1795 (month ==[compo[1] intValue] &&
1796 (day < [compo[2] intValue] ||
1797 (day ==[compo[2] intValue] &&
1798 hours < [compo[3] intValue])))))) {
1799 year = [compo[0] intValue];
1800 month = [compo[1] intValue];
1801 day = [compo[2] intValue];
1802 hours = [compo[3] intValue];
1803 latestLog = [crashReporter stringByAppendingPathComponent:fname];
1808 if (!(latestLog && [[NSFileManager defaultManager] fileExistsAtPath:latestLog]))
1811 if (!previouslySeen) {
1812 [defaults setInteger:year forKey:@"LatestCrashReportYear"];
1813 [defaults setInteger:month forKey:@"LatestCrashReportMonth"];
1814 [defaults setInteger:day forKey:@"LatestCrashReportDay"];
1815 [defaults setInteger:hours forKey:@"LatestCrashReportHours"];
1820 - (NSString *)latestCrashLogPath
1822 return [self latestCrashLogPathPreviouslySeen:YES];
1825 - (void)lookForCrashLog
1827 NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
1828 // This pref key doesn't exists? this VLC is an upgrade, and this crash log come from previous version
1829 NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
1830 BOOL areCrashLogsTooOld = ![defaults integerForKey:@"LatestCrashReportYear"];
1831 NSString * latestLog = [self latestCrashLogPathPreviouslySeen:NO];
1832 if (latestLog && !areCrashLogsTooOld) {
1833 if ([defaults integerForKey:@"AlwaysSendCrashReports"] > 0)
1834 [self sendCrashLog:[NSString stringWithContentsOfFile: [self latestCrashLogPath] encoding: NSUTF8StringEncoding error: NULL] withUserComment: [o_crashrep_fld string]];
1835 else if ([defaults integerForKey:@"AlwaysSendCrashReports"] == 0)
1836 [NSApp runModalForWindow: o_crashrep_win];
1837 // bail out, the user doesn't want us to send reports
1843 - (IBAction)crashReporterAction:(id)sender
1845 if (sender == o_crashrep_send_btn) {
1846 [self sendCrashLog:[NSString stringWithContentsOfFile: [self latestCrashLogPath] encoding: NSUTF8StringEncoding error: NULL] withUserComment: [o_crashrep_fld string]];
1847 if ([o_crashrep_dontaskagain_ckb state])
1848 [[NSUserDefaults standardUserDefaults] setInteger:1 forKey:@"AlwaysSendCrashReports"];
1850 if ([o_crashrep_dontaskagain_ckb state])
1851 [[NSUserDefaults standardUserDefaults] setInteger:-1 forKey:@"AlwaysSendCrashReports"];
1855 [o_crashrep_win orderOut: sender];
1858 - (IBAction)openCrashLog:(id)sender
1860 NSString * latestLog = [self latestCrashLogPath];
1862 [[NSWorkspace sharedWorkspace] openFile: latestLog withApplication: @"Console"];
1864 NSBeginInformationalAlertSheet(_NS("No CrashLog found"), _NS("Continue"), nil, nil, o_msgs_panel, self, NULL, NULL, nil, @"%@", _NS("Couldn't find any trace of a previous crash."));
1869 #pragma mark Remove old prefs
1871 - (void)removeOldPreferences
1873 static NSString * kVLCPreferencesVersion = @"VLCPreferencesVersion";
1874 static const int kCurrentPreferencesVersion = 2;
1875 NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
1876 int version = [defaults integerForKey:kVLCPreferencesVersion];
1877 if (version >= kCurrentPreferencesVersion)
1881 [defaults setInteger:kCurrentPreferencesVersion forKey:kVLCPreferencesVersion];
1882 [defaults synchronize];
1884 if (![[VLCCoreInteraction sharedInstance] fixPreferences])
1887 config_SaveConfigFile(VLCIntf); // we need to do manually, since we won't quit libvlc cleanly
1889 NSArray *libraries = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,
1890 NSUserDomainMask, YES);
1891 if (!libraries || [libraries count] == 0) return;
1892 NSString * preferences = [libraries[0] stringByAppendingPathComponent:@"Preferences"];
1894 /* File not found, don't attempt anything */
1895 if (![[NSFileManager defaultManager] fileExistsAtPath:[preferences stringByAppendingPathComponent:@"org.videolan.vlc"]] &&
1896 ![[NSFileManager defaultManager] fileExistsAtPath:[preferences stringByAppendingPathComponent:@"org.videolan.vlc.plist"]]) {
1897 [defaults setInteger:kCurrentPreferencesVersion forKey:kVLCPreferencesVersion];
1901 int res = NSRunInformationalAlertPanel(_NS("Remove old preferences?"),
1902 _NS("We just found an older version of VLC's preferences files."),
1903 _NS("Move To Trash and Relaunch VLC"), _NS("Ignore"), nil, nil);
1904 if (res != NSOKButton) {
1905 [defaults setInteger:kCurrentPreferencesVersion forKey:kVLCPreferencesVersion];
1909 NSArray * ourPreferences = @[@"org.videolan.vlc.plist", @"VLC", @"org.videolan.vlc"];
1911 /* Move the file to trash so that user can find them later */
1912 [[NSWorkspace sharedWorkspace] performFileOperation:NSWorkspaceRecycleOperation source:preferences destination:nil files:ourPreferences tag:0];
1914 /* really reset the defaults from now on */
1915 [NSUserDefaults resetStandardUserDefaults];
1917 [defaults setInteger:kCurrentPreferencesVersion forKey:kVLCPreferencesVersion];
1918 [defaults synchronize];
1922 const char * path = [[[NSBundle mainBundle] executablePath] UTF8String];
1924 /* For some reason we need to fork(), not just execl(), which reports a ENOTSUP then. */
1929 execl(path, path, NULL);
1933 #pragma mark Errors, warnings and messages
1934 - (IBAction)updateMessagesPanel:(id)sender
1936 [self windowDidBecomeKey:nil];
1939 - (IBAction)showMessagesPanel:(id)sender
1941 /* subscribe to LibVLCCore's messages */
1942 vlc_LogSet(p_intf->p_libvlc, MsgCallback, NULL);
1945 [o_msgs_panel makeKeyAndOrderFront: sender];
1948 - (void)windowDidBecomeKey:(NSNotification *)o_notification
1950 [o_msgs_table reloadData];
1951 [o_msgs_table scrollRowToVisible: [o_msg_arr count] - 1];
1954 - (void)windowWillClose:(NSNotification *)o_notification
1956 /* unsubscribe from LibVLCCore's messages */
1957 vlc_LogSet( p_intf->p_libvlc, NULL, NULL );
1960 - (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView
1962 if (aTableView == o_msgs_table)
1963 return [o_msg_arr count];
1967 - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
1969 NSMutableAttributedString *result = NULL;
1972 if (rowIndex < [o_msg_arr count])
1973 result = o_msg_arr[rowIndex];
1974 [o_msg_lock unlock];
1982 - (void)processReceivedlibvlcMessage:(const vlc_log_t *) item ofType: (int)i_type withStr: (char *)str
1985 NSColor *o_white = [NSColor whiteColor];
1986 NSColor *o_red = [NSColor redColor];
1987 NSColor *o_yellow = [NSColor yellowColor];
1988 NSColor *o_gray = [NSColor grayColor];
1989 NSString * firstString, * secondString;
1991 NSColor * pp_color[4] = { o_white, o_red, o_yellow, o_gray };
1992 static const char * ppsz_type[4] = { ": ", " error: ", " warning: ", " debug: " };
1994 NSDictionary *o_attr;
1995 NSMutableAttributedString *o_msg_color;
1999 if ([o_msg_arr count] > 600) {
2000 [o_msg_arr removeObjectAtIndex: 0];
2001 [o_msg_arr removeObjectAtIndex: 1];
2003 firstString = [NSString stringWithFormat:@"%s%s", item->psz_module, ppsz_type[i_type]];
2004 secondString = [NSString stringWithFormat:@"%@%s\n", firstString, str];
2006 o_attr = [NSDictionary dictionaryWithObject: pp_color[i_type] forKey: NSForegroundColorAttributeName];
2007 o_msg_color = [[NSMutableAttributedString alloc] initWithString: secondString attributes: o_attr];
2008 o_attr = [NSDictionary dictionaryWithObject: pp_color[3] forKey: NSForegroundColorAttributeName];
2009 [o_msg_color setAttributes: o_attr range: NSMakeRange(0, [firstString length])];
2010 [o_msg_arr addObject: [o_msg_color autorelease]];
2012 b_msg_arr_changed = YES;
2013 [o_msg_lock unlock];
2017 - (IBAction)saveDebugLog:(id)sender
2019 NSSavePanel * saveFolderPanel = [[NSSavePanel alloc] init];
2021 [saveFolderPanel setCanSelectHiddenExtension: NO];
2022 [saveFolderPanel setCanCreateDirectories: YES];
2023 [saveFolderPanel setAllowedFileTypes: @[@"rtf"]];
2024 [saveFolderPanel setNameFieldStringValue:[NSString stringWithFormat: _NS("VLC Debug Log (%s).rtf"), VERSION_MESSAGE]];
2025 [saveFolderPanel beginSheetModalForWindow: o_msgs_panel completionHandler:^(NSInteger returnCode) {
2026 if (returnCode == NSOKButton) {
2027 NSUInteger count = [o_msg_arr count];
2028 NSMutableAttributedString * string = [[NSMutableAttributedString alloc] init];
2029 for (NSUInteger i = 0; i < count; i++)
2030 [string appendAttributedString: o_msg_arr[i]];
2032 NSData *data = [string RTFFromRange:NSMakeRange(0, [string length])
2033 documentAttributes:[NSDictionary dictionaryWithObject: NSRTFTextDocumentType forKey: NSDocumentTypeDocumentAttribute]];
2035 if ([data writeToFile: [[saveFolderPanel URL] path] atomically: YES] == NO)
2036 msg_Warn(p_intf, "Error while saving the debug log");
2041 [saveFolderPanel release];
2045 #pragma mark Playlist toggling
2047 - (void)updateTogglePlaylistState
2049 [[self playlist] outlineViewSelectionDidChange: NULL];
2056 @implementation VLCMain (Internal)
2058 - (void)handlePortMessage:(NSPortMessage *)o_msg
2063 NSInvocation * o_inv;
2064 NSConditionLock * o_lock;
2066 o_data = [[o_msg components] lastObject];
2067 o_inv = *((NSInvocation **)[o_data bytes]);
2068 [o_inv getArgument: &o_value atIndex: 2];
2069 val = (id **)[o_value pointerValue];
2070 [o_inv setArgument: val[1] atIndex: 2];
2075 [o_lock unlockWithCondition: 1];
2078 - (void)resetMediaKeyJump
2080 b_mediakeyJustJumped = NO;
2083 - (void)coreChangedMediaKeySupportSetting: (NSNotification *)o_notification
2085 b_mediaKeySupport = var_InheritBool(VLCIntf, "macosx-mediakeys");
2086 if (b_mediaKeySupport) {
2087 if (!o_mediaKeyController)
2088 o_mediaKeyController = [[SPMediaKeyTap alloc] initWithDelegate:self];
2090 if ([[[VLCMain sharedInstance] playlist] currentPlaylistRoot]->i_children > 0 ||
2092 [o_mediaKeyController startWatchingMediaKeys];
2094 [o_mediaKeyController stopWatchingMediaKeys];
2096 else if (!b_mediaKeySupport && o_mediaKeyController)
2097 [o_mediaKeyController stopWatchingMediaKeys];
2102 /*****************************************************************************
2103 * VLCApplication interface
2104 *****************************************************************************/
2106 @implementation VLCApplication
2107 // when user selects the quit menu from dock it sends a terminate:
2108 // but we need to send a stop: to properly exits libvlc.
2109 // However, we are not able to change the action-method sent by this standard menu item.
2110 // thus we override terminate: to send a stop:
2111 // see [af97f24d528acab89969d6541d83f17ce1ecd580] that introduced the removal of setjmp() and longjmp()
2112 - (void)terminate:(id)sender
2114 [self activateIgnoringOtherApps:YES];