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 [o_vout_provider_lock unlock];
183 [[VLCMain sharedInstance] setActiveVideoPlayback: YES];
184 p_wnd->control = WindowControl;
190 static int WindowControl(vout_window_t *p_wnd, int i_query, va_list args)
192 NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
194 [o_vout_provider_lock lock];
195 VLCVoutWindowController *o_vout_controller = [[VLCMain sharedInstance] voutController];
196 if (!o_vout_controller) {
197 [o_vout_provider_lock unlock];
203 case VOUT_WINDOW_SET_STATE:
205 unsigned i_state = va_arg(args, unsigned);
207 NSInteger i_cooca_level = NSNormalWindowLevel;
208 if (i_state & VOUT_WINDOW_STATE_ABOVE)
209 i_cooca_level = NSStatusWindowLevel;
211 SEL sel = @selector(setWindowLevel:forWindow:);
212 NSInvocation *inv = [NSInvocation invocationWithMethodSignature:[o_vout_controller methodSignatureForSelector:sel]];
213 [inv setTarget:o_vout_controller];
214 [inv setSelector:sel];
215 [inv setArgument:&i_cooca_level atIndex:2]; // starting at 2!
216 [inv setArgument:&p_wnd atIndex:3];
217 [inv performSelectorOnMainThread:@selector(invoke) withObject:nil
222 case VOUT_WINDOW_SET_SIZE:
225 unsigned int i_width = va_arg(args, unsigned int);
226 unsigned int i_height = va_arg(args, unsigned int);
228 NSSize newSize = NSMakeSize(i_width, i_height);
229 SEL sel = @selector(setNativeVideoSize:forWindow:);
230 NSInvocation *inv = [NSInvocation invocationWithMethodSignature:[o_vout_controller methodSignatureForSelector:sel]];
231 [inv setTarget:o_vout_controller];
232 [inv setSelector:sel];
233 [inv setArgument:&newSize atIndex:2]; // starting at 2!
234 [inv setArgument:&p_wnd atIndex:3];
235 [inv performSelectorOnMainThread:@selector(invoke) withObject:nil
240 case VOUT_WINDOW_SET_FULLSCREEN:
242 NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
243 int i_full = va_arg(args, int);
245 SEL sel = @selector(setFullscreen:forWindow:);
246 NSInvocation *inv = [NSInvocation invocationWithMethodSignature:[o_vout_controller methodSignatureForSelector:sel]];
247 [inv setTarget:o_vout_controller];
248 [inv setSelector:sel];
249 [inv setArgument:&i_full atIndex:2]; // starting at 2!
250 [inv setArgument:&p_wnd atIndex:3];
251 [inv performSelectorOnMainThread:@selector(invoke) withObject:nil
258 msg_Warn(p_wnd, "unsupported control query");
259 [o_vout_provider_lock unlock];
265 [o_vout_provider_lock unlock];
270 void WindowClose(vout_window_t *p_wnd)
272 NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
274 [o_vout_provider_lock lock];
275 VLCVoutWindowController *o_vout_controller = [[VLCMain sharedInstance] voutController];
276 if (!o_vout_controller) {
277 [o_vout_provider_lock unlock];
282 [o_vout_controller performSelectorOnMainThread:@selector(removeVoutforDisplay:) withObject:[NSValue valueWithPointer:p_wnd] waitUntilDone:NO];
283 [o_vout_provider_lock unlock];
288 /*****************************************************************************
290 *****************************************************************************/
291 static NSLock * o_appLock = nil; // controls access to f_appExit
292 static NSLock * o_plItemChangedLock = nil;
294 static void Run(intf_thread_t *p_intf)
296 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
297 [VLCApplication sharedApplication];
299 o_appLock = [[NSLock alloc] init];
300 o_plItemChangedLock = [[NSLock alloc] init];
301 o_vout_provider_lock = [[NSLock alloc] init];
303 [[VLCMain sharedInstance] setIntf: p_intf];
305 [NSBundle loadNibNamed: @"MainMenu" owner: NSApp];
308 [[VLCMain sharedInstance] applicationWillTerminate:nil];
309 [o_plItemChangedLock release];
311 [o_vout_provider_lock release];
312 o_vout_provider_lock = nil;
319 #pragma mark Variables Callback
321 /*****************************************************************************
322 * MsgCallback: Callback triggered by the core once a new debug message is
323 * ready to be displayed. We store everything in a NSArray in our Cocoa part
325 *****************************************************************************/
326 static void MsgCallback(void *data, int type, const vlc_log_t *item, const char *format, va_list ap)
328 int canc = vlc_savecancel();
331 if (vasprintf(&str, format, ap) == -1) {
332 vlc_restorecancel(canc);
336 NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
337 [[VLCMain sharedInstance] processReceivedlibvlcMessage: item ofType: type withStr: str];
340 vlc_restorecancel(canc);
344 static int InputEvent(vlc_object_t *p_this, const char *psz_var,
345 vlc_value_t oldval, vlc_value_t new_val, void *param)
347 NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
348 switch (new_val.i_int) {
349 case INPUT_EVENT_STATE:
350 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(playbackStatusUpdated) withObject: nil waitUntilDone:NO];
352 case INPUT_EVENT_RATE:
353 [[[VLCMain sharedInstance] mainMenu] performSelectorOnMainThread:@selector(updatePlaybackRate) withObject: nil waitUntilDone:NO];
355 case INPUT_EVENT_POSITION:
356 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(updatePlaybackPosition) withObject: nil waitUntilDone:NO];
358 case INPUT_EVENT_TITLE:
359 case INPUT_EVENT_CHAPTER:
360 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(updateMainMenu) withObject: nil waitUntilDone:NO];
362 case INPUT_EVENT_CACHE:
363 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(updateMainWindow) withObject: nil waitUntilDone: NO];
365 case INPUT_EVENT_STATISTICS:
366 [[[VLCMain sharedInstance] info] performSelectorOnMainThread:@selector(updateStatistics) withObject: nil waitUntilDone: NO];
370 case INPUT_EVENT_TELETEXT:
372 case INPUT_EVENT_AOUT:
374 case INPUT_EVENT_VOUT:
376 case INPUT_EVENT_ITEM_META:
377 case INPUT_EVENT_ITEM_INFO:
378 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(updateMainMenu) withObject: nil waitUntilDone:NO];
379 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(updateName) withObject: nil waitUntilDone:NO];
380 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(updateInfoandMetaPanel) withObject: nil waitUntilDone:NO];
382 case INPUT_EVENT_BOOKMARK:
384 case INPUT_EVENT_RECORD:
385 [[VLCMain sharedInstance] updateRecordState: var_GetBool(p_this, "record")];
387 case INPUT_EVENT_PROGRAM:
388 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(updateMainMenu) withObject: nil waitUntilDone:NO];
390 case INPUT_EVENT_ITEM_EPG:
392 case INPUT_EVENT_SIGNAL:
395 case INPUT_EVENT_ITEM_NAME:
396 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(updateName) withObject: nil waitUntilDone:NO];
397 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(playlistUpdated) withObject: nil waitUntilDone:NO];
400 case INPUT_EVENT_AUDIO_DELAY:
401 case INPUT_EVENT_SUBTITLE_DELAY:
402 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(updateDelays) withObject:nil waitUntilDone:NO];
405 case INPUT_EVENT_DEAD:
406 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(updateName) withObject: nil waitUntilDone:NO];
407 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(updatePlaybackPosition) withObject:nil waitUntilDone:NO];
410 case INPUT_EVENT_ABORT:
411 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(updateName) withObject: nil waitUntilDone:NO];
412 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(updatePlaybackPosition) withObject:nil waitUntilDone:NO];
416 //msg_Warn(p_this, "unhandled input event (%lld)", new_val.i_int);
424 static int PLItemChanged(vlc_object_t *p_this, const char *psz_var,
425 vlc_value_t oldval, vlc_value_t new_val, void *param)
427 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
429 /* Due to constraints within NSAttributedString's main loop runtime handling
430 * and other issues, we need to wait for -PlaylistItemChanged to finish and
431 * then -informInputChanged on this non-main thread. */
432 [o_plItemChangedLock lock];
433 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(PlaylistItemChanged) withObject:nil waitUntilDone:YES];
434 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(informInputChanged) withObject:nil waitUntilDone:YES];
435 [o_plItemChangedLock unlock];
441 static int PlaylistUpdated(vlc_object_t *p_this, const char *psz_var,
442 vlc_value_t oldval, vlc_value_t new_val, void *param)
444 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
446 /* Avoid event queue flooding with playlistUpdated selectors, leading to UI freezes.
447 * Therefore, only enqueue if no selector already enqueued.
449 VLCMain *o_main = [VLCMain sharedInstance];
450 @synchronized(o_main) {
451 if(![o_main playlistUpdatedSelectorInQueue]) {
452 [o_main setPlaylistUpdatedSelectorInQueue:YES];
453 [o_main performSelectorOnMainThread:@selector(playlistUpdated) withObject:nil waitUntilDone:NO];
461 static int PlaybackModeUpdated(vlc_object_t *p_this, const char *psz_var,
462 vlc_value_t oldval, vlc_value_t new_val, void *param)
464 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
465 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(playbackModeUpdated) withObject:nil waitUntilDone:NO];
471 static int VolumeUpdated(vlc_object_t *p_this, const char *psz_var,
472 vlc_value_t oldval, vlc_value_t new_val, void *param)
474 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
475 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(updateVolume) withObject:nil waitUntilDone:NO];
481 static int BossCallback(vlc_object_t *p_this, const char *psz_var,
482 vlc_value_t oldval, vlc_value_t new_val, void *param)
484 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
486 [[VLCCoreInteraction sharedInstance] performSelectorOnMainThread:@selector(pause) withObject:nil waitUntilDone:NO];
487 [[VLCApplication sharedApplication] hide:nil];
493 /*****************************************************************************
494 * ShowController: Callback triggered by the show-intf playlist variable
495 * through the ShowIntf-control-intf, to let us show the controller-win;
496 * usually when in fullscreen-mode
497 *****************************************************************************/
498 static int ShowController(vlc_object_t *p_this, const char *psz_variable,
499 vlc_value_t old_val, vlc_value_t new_val, void *param)
501 intf_thread_t * p_intf = VLCIntf;
502 if (p_intf && p_intf->p_sys) {
503 playlist_t * p_playlist = pl_Get(p_intf);
504 BOOL b_fullscreen = var_GetBool(p_playlist, "fullscreen");
505 if (strcmp(psz_variable, "intf-toggle-fscontrol") || b_fullscreen)
506 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(showFullscreenController) withObject:nil waitUntilDone:NO];
508 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(showMainWindow) withObject:nil waitUntilDone:NO];
513 /*****************************************************************************
514 * DialogCallback: Callback triggered by the "dialog-*" variables
515 * to let the intf display error and interaction dialogs
516 *****************************************************************************/
517 static int DialogCallback(vlc_object_t *p_this, const char *type, vlc_value_t previous, vlc_value_t value, void *data)
519 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
520 VLCMain *interface = (VLCMain *)data;
522 if ([@(type) isEqualToString: @"dialog-progress-bar"]) {
523 /* the progress panel needs to update itself and therefore wants special treatment within this context */
524 dialog_progress_bar_t *p_dialog = (dialog_progress_bar_t *)value.p_address;
526 p_dialog->pf_update = updateProgressPanel;
527 p_dialog->pf_check = checkProgressPanel;
528 p_dialog->pf_destroy = destroyProgressPanel;
529 p_dialog->p_sys = VLCIntf->p_libvlc;
532 NSValue *o_value = [NSValue valueWithPointer:value.p_address];
533 [[VLCCoreDialogProvider sharedInstance] performEventWithObject: o_value ofType: type];
539 void updateProgressPanel (void *priv, const char *text, float value)
541 NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
549 [[[VLCMain sharedInstance] coreDialogProvider] updateProgressPanelWithText: o_txt andNumber: (double)(value * 1000.)];
554 void destroyProgressPanel (void *priv)
556 NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
558 if ([[NSApplication sharedApplication] isRunning])
559 [[[VLCMain sharedInstance] coreDialogProvider] performSelectorOnMainThread:@selector(destroyProgressPanel) withObject:nil waitUntilDone:YES];
564 bool checkProgressPanel (void *priv)
566 NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
567 return [[[VLCMain sharedInstance] coreDialogProvider] progressCancelled];
574 input_thread_t *getInput(void)
576 intf_thread_t *p_intf = VLCIntf;
579 return pl_CurrentInput(p_intf);
582 vout_thread_t *getVout(void)
584 input_thread_t *p_input = getInput();
587 vout_thread_t *p_vout = input_GetVout(p_input);
588 vlc_object_release(p_input);
592 vout_thread_t *getVoutForActiveWindow(void)
594 vout_thread_t *p_vout = nil;
596 id currentWindow = [NSApp keyWindow];
597 if ([currentWindow respondsToSelector:@selector(videoView)]) {
598 VLCVoutView *videoView = [currentWindow videoView];
600 p_vout = [videoView voutThread];
610 audio_output_t *getAout(void)
612 intf_thread_t *p_intf = VLCIntf;
615 return playlist_GetAout(pl_Get(p_intf));
621 @interface VLCMain ()
622 - (void)removeOldPreferences;
625 @interface VLCMain (Internal)
626 - (void)handlePortMessage:(NSPortMessage *)o_msg;
627 - (void)resetMediaKeyJump;
628 - (void)coreChangedMediaKeySupportSetting: (NSNotification *)o_notification;
631 /*****************************************************************************
632 * VLCMain implementation
633 *****************************************************************************/
634 @implementation VLCMain
636 @synthesize voutController=o_vout_controller;
637 @synthesize nativeFullscreenMode=b_nativeFullscreenMode;
638 @synthesize playlistUpdatedSelectorInQueue=b_playlist_updated_selector_in_queue;
641 #pragma mark Initialization
643 static VLCMain *_o_sharedMainInstance = nil;
645 + (VLCMain *)sharedInstance
647 return _o_sharedMainInstance ? _o_sharedMainInstance : [[self alloc] init];
652 if (_o_sharedMainInstance) {
654 return _o_sharedMainInstance;
656 _o_sharedMainInstance = [super init];
659 p_current_input = p_input_changed = NULL;
661 o_msg_lock = [[NSLock alloc] init];
662 o_msg_arr = [[NSMutableArray arrayWithCapacity: 600] retain];
664 o_open = [[VLCOpen alloc] init];
665 o_coredialogs = [[VLCCoreDialogProvider alloc] init];
666 o_info = [[VLCInfo alloc] init];
667 o_mainmenu = [[VLCMainMenu alloc] init];
668 o_coreinteraction = [[VLCCoreInteraction alloc] init];
669 o_eyetv = [[VLCEyeTVController alloc] init];
670 o_mainwindow = [[VLCMainWindow alloc] init];
672 /* announce our launch to a potential eyetv plugin */
673 [[NSDistributedNotificationCenter defaultCenter] postNotificationName: @"VLCOSXGUIInit"
674 object: @"VLCEyeTVSupport"
676 deliverImmediately: YES];
678 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
679 NSDictionary *appDefaults = [NSDictionary dictionaryWithObject:@"NO" forKey:@"LiveUpdateTheMessagesPanel"];
680 [defaults registerDefaults:appDefaults];
682 o_vout_controller = [[VLCVoutWindowController alloc] init];
684 return _o_sharedMainInstance;
687 - (void)setIntf: (intf_thread_t *)p_mainintf
692 - (intf_thread_t *)intf
699 playlist_t *p_playlist;
702 var_Create(p_intf, "intf-change", VLC_VAR_BOOL);
704 /* Check if we already did this once. Opening the other nibs calls it too,
705 because VLCMain is the owner */
709 [o_msgs_panel setExcludedFromWindowsMenu: YES];
710 [o_msgs_panel setDelegate: self];
712 p_playlist = pl_Get(p_intf);
716 var_AddCallback(p_intf->p_libvlc, "intf-toggle-fscontrol", ShowController, self);
717 var_AddCallback(p_intf->p_libvlc, "intf-show", ShowController, self);
718 var_AddCallback(p_intf->p_libvlc, "intf-boss", BossCallback, self);
719 // var_AddCallback(p_playlist, "item-change", PLItemChanged, self);
720 var_AddCallback(p_playlist, "activity", PLItemChanged, self);
721 var_AddCallback(p_playlist, "leaf-to-parent", PlaylistUpdated, self);
722 var_AddCallback(p_playlist, "playlist-item-append", PlaylistUpdated, self);
723 var_AddCallback(p_playlist, "playlist-item-deleted", PlaylistUpdated, self);
724 var_AddCallback(p_playlist, "random", PlaybackModeUpdated, self);
725 var_AddCallback(p_playlist, "repeat", PlaybackModeUpdated, self);
726 var_AddCallback(p_playlist, "loop", PlaybackModeUpdated, self);
727 var_AddCallback(p_playlist, "volume", VolumeUpdated, self);
728 var_AddCallback(p_playlist, "mute", VolumeUpdated, self);
730 if (!OSX_SNOW_LEOPARD) {
731 if ([NSApp currentSystemPresentationOptions] & NSApplicationPresentationFullScreen)
732 var_SetBool(p_playlist, "fullscreen", YES);
735 /* load our Core and Shared Dialogs nibs */
736 nib_coredialogs_loaded = [NSBundle loadNibNamed:@"CoreDialogs" owner: NSApp];
737 [NSBundle loadNibNamed:@"SharedDialogs" owner: NSApp];
739 /* subscribe to various interactive dialogues */
740 var_Create(p_intf, "dialog-error", VLC_VAR_ADDRESS);
741 var_AddCallback(p_intf, "dialog-error", DialogCallback, self);
742 var_Create(p_intf, "dialog-critical", VLC_VAR_ADDRESS);
743 var_AddCallback(p_intf, "dialog-critical", DialogCallback, self);
744 var_Create(p_intf, "dialog-login", VLC_VAR_ADDRESS);
745 var_AddCallback(p_intf, "dialog-login", DialogCallback, self);
746 var_Create(p_intf, "dialog-question", VLC_VAR_ADDRESS);
747 var_AddCallback(p_intf, "dialog-question", DialogCallback, self);
748 var_Create(p_intf, "dialog-progress-bar", VLC_VAR_ADDRESS);
749 var_AddCallback(p_intf, "dialog-progress-bar", DialogCallback, self);
750 dialog_Register(p_intf);
752 /* init Apple Remote support */
753 o_remote = [[AppleRemote alloc] init];
754 [o_remote setClickCountEnabledButtons: kRemoteButtonPlay];
755 [o_remote setDelegate: _o_sharedMainInstance];
757 [o_msgs_refresh_btn setImage: [NSImage imageNamed: NSImageNameRefreshTemplate]];
759 /* yeah, we are done */
760 b_nativeFullscreenMode = NO;
761 #ifdef MAC_OS_X_VERSION_10_7
762 if (!OSX_SNOW_LEOPARD)
763 b_nativeFullscreenMode = var_InheritBool(p_intf, "macosx-nativefullscreenmode");
766 if (config_GetInt(VLCIntf, "macosx-icon-change")) {
767 /* After day 354 of the year, the usual VLC cone is replaced by another cone
768 * wearing a Father Xmas hat.
769 * Note: this icon doesn't represent an endorsement of The Coca-Cola Company.
771 NSCalendar *gregorian =
772 [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
773 NSUInteger dayOfYear = [gregorian ordinalityOfUnit:NSDayCalendarUnit inUnit:NSYearCalendarUnit forDate:[NSDate date]];
776 if (dayOfYear >= 354)
777 [[VLCApplication sharedApplication] setApplicationIconImage: [NSImage imageNamed:@"vlc-xmas"]];
782 nib_main_loaded = TRUE;
785 - (void)applicationWillFinishLaunching:(NSNotification *)aNotification
787 playlist_t * p_playlist = pl_Get(VLCIntf);
789 items_at_launch = p_playlist->p_local_category->i_children;
793 - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
800 [self updateCurrentlyUsedHotkeys];
802 /* init media key support */
803 b_mediaKeySupport = var_InheritBool(VLCIntf, "macosx-mediakeys");
804 if (b_mediaKeySupport) {
805 o_mediaKeyController = [[SPMediaKeyTap alloc] initWithDelegate:self];
806 [[NSUserDefaults standardUserDefaults] registerDefaults:[NSDictionary dictionaryWithObjectsAndKeys:
807 [SPMediaKeyTap defaultMediaKeyUserBundleIdentifiers], kMediaKeyUsingBundleIdentifiersDefaultsKey,
810 [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(coreChangedMediaKeySupportSetting:) name: @"VLCMediaKeySupportSettingChanged" object: nil];
812 [self removeOldPreferences];
814 /* Handle sleep notification */
815 [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(computerWillSleep:)
816 name:NSWorkspaceWillSleepNotification object:nil];
818 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(lookForCrashLog) withObject:nil waitUntilDone:NO];
820 /* we will need this, so let's load it here so the interface appears to be more responsive */
821 nib_open_loaded = [NSBundle loadNibNamed:@"Open" owner: NSApp];
823 /* update the main window */
824 [o_mainwindow updateWindow];
825 [o_mainwindow updateTimeSlider];
826 [o_mainwindow updateVolumeSlider];
835 [o_msgs_panel setTitle: _NS("Messages")];
836 [o_msgs_crashlog_btn setTitle: _NS("Open CrashLog...")];
837 [o_msgs_save_btn setTitle: _NS("Save this Log...")];
839 /* crash reporter panel */
840 [o_crashrep_send_btn setTitle: _NS("Send")];
841 [o_crashrep_dontSend_btn setTitle: _NS("Don't Send")];
842 [o_crashrep_title_txt setStringValue: _NS("VLC crashed previously")];
843 [o_crashrep_win setTitle: _NS("VLC crashed previously")];
844 [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, ...")];
845 [o_crashrep_includeEmail_ckb setTitle: _NS("I agree to be possibly contacted about this bugreport.")];
846 [o_crashrep_includeEmail_txt setStringValue: _NS("Only your default E-Mail address will be submitted, including no further information.")];
847 [o_crashrep_dontaskagain_ckb setTitle: _NS("Don't ask again")];
851 #pragma mark Termination
853 - (void)applicationWillTerminate:(NSNotification *)notification
855 /* don't allow a double termination call. If the user has
856 * already invoked the quit then simply return this time. */
857 static bool f_appExit = false;
861 isTerminating = f_appExit;
868 [self resumeItunesPlayback:nil];
870 if (notification == nil)
871 [[NSNotificationCenter defaultCenter] postNotificationName: NSApplicationWillTerminateNotification object: nil];
873 playlist_t * p_playlist = pl_Get(p_intf);
874 int returnedValue = 0;
876 /* always exit fullscreen on quit, otherwise we get ugly artifacts on the next launch */
877 if (b_nativeFullscreenMode) {
878 [o_mainwindow toggleFullScreen: self];
879 [NSApp setPresentationOptions:(NSApplicationPresentationDefault)];
882 /* save current video and audio profiles */
883 [[VLCVideoEffects sharedInstance] saveCurrentProfile];
884 [[VLCAudioEffects sharedInstance] saveCurrentProfile];
886 /* Save some interface state in configuration, at module quit */
887 config_PutInt(p_intf, "random", var_GetBool(p_playlist, "random"));
888 config_PutInt(p_intf, "loop", var_GetBool(p_playlist, "loop"));
889 config_PutInt(p_intf, "repeat", var_GetBool(p_playlist, "repeat"));
891 msg_Dbg(p_intf, "Terminating");
893 /* unsubscribe from the interactive dialogues */
894 dialog_Unregister(p_intf);
895 var_DelCallback(p_intf, "dialog-error", DialogCallback, self);
896 var_DelCallback(p_intf, "dialog-critical", DialogCallback, self);
897 var_DelCallback(p_intf, "dialog-login", DialogCallback, self);
898 var_DelCallback(p_intf, "dialog-question", DialogCallback, self);
899 var_DelCallback(p_intf, "dialog-progress-bar", DialogCallback, self);
900 //var_DelCallback(p_playlist, "item-change", PLItemChanged, self);
901 var_DelCallback(p_playlist, "activity", PLItemChanged, self);
902 var_DelCallback(p_playlist, "leaf-to-parent", PlaylistUpdated, self);
903 var_DelCallback(p_playlist, "playlist-item-append", PlaylistUpdated, self);
904 var_DelCallback(p_playlist, "playlist-item-deleted", PlaylistUpdated, self);
905 var_DelCallback(p_playlist, "random", PlaybackModeUpdated, self);
906 var_DelCallback(p_playlist, "repeat", PlaybackModeUpdated, self);
907 var_DelCallback(p_playlist, "loop", PlaybackModeUpdated, self);
908 var_DelCallback(p_playlist, "volume", VolumeUpdated, self);
909 var_DelCallback(p_playlist, "mute", VolumeUpdated, self);
910 var_DelCallback(p_intf->p_libvlc, "intf-toggle-fscontrol", ShowController, self);
911 var_DelCallback(p_intf->p_libvlc, "intf-show", ShowController, self);
912 var_DelCallback(p_intf->p_libvlc, "intf-boss", BossCallback, self);
914 if (p_current_input) {
915 var_DelCallback(p_current_input, "intf-event", InputEvent, [VLCMain sharedInstance]);
916 vlc_object_release(p_current_input);
917 p_current_input = NULL;
920 /* remove global observer watching for vout device changes correctly */
921 [[NSNotificationCenter defaultCenter] removeObserver: self];
923 [o_vout_provider_lock lock];
924 // release before o_info!
925 [o_vout_controller release];
926 o_vout_controller = nil;
927 [o_vout_provider_lock unlock];
929 /* release some other objects here, because it isn't sure whether dealloc
930 * will be called later on */
945 [crashLogURLConnection cancel];
946 [crashLogURLConnection release];
948 [o_coredialogs release];
951 /* unsubscribe from libvlc's debug messages */
952 vlc_LogSet(p_intf->p_libvlc, NULL, NULL);
954 [o_msg_arr removeAllObjects];
957 [o_usedHotkeys release];
958 o_usedHotkeys = NULL;
960 [o_mediaKeyController release];
962 [o_msg_lock release];
964 /* write cached user defaults to disk */
965 [[NSUserDefaults standardUserDefaults] synchronize];
968 [o_mainmenu release];
970 libvlc_Quit(p_intf->p_libvlc);
972 [o_mainwindow release];
979 #pragma mark Sparkle delegate
980 /* received directly before the update gets installed, so let's shut down a bit */
981 - (void)updater:(SUUpdater *)updater willInstallUpdate:(SUAppcastItem *)update
983 [NSApp activateIgnoringOtherApps:YES];
984 [o_remote stopListening: self];
985 [[VLCCoreInteraction sharedInstance] stop];
989 #pragma mark Media Key support
991 -(void)mediaKeyTap:(SPMediaKeyTap*)keyTap receivedMediaKeyEvent:(NSEvent*)event
993 if (b_mediaKeySupport) {
994 assert([event type] == NSSystemDefined && [event subtype] == SPSystemDefinedEventMediaKeys);
996 int keyCode = (([event data1] & 0xFFFF0000) >> 16);
997 int keyFlags = ([event data1] & 0x0000FFFF);
998 int keyState = (((keyFlags & 0xFF00) >> 8)) == 0xA;
999 int keyRepeat = (keyFlags & 0x1);
1001 if (keyCode == NX_KEYTYPE_PLAY && keyState == 0)
1002 [[VLCCoreInteraction sharedInstance] playOrPause];
1004 if ((keyCode == NX_KEYTYPE_FAST || keyCode == NX_KEYTYPE_NEXT) && !b_mediakeyJustJumped) {
1005 if (keyState == 0 && keyRepeat == 0)
1006 [[VLCCoreInteraction sharedInstance] next];
1007 else if (keyRepeat == 1) {
1008 [[VLCCoreInteraction sharedInstance] forwardShort];
1009 b_mediakeyJustJumped = YES;
1010 [self performSelector:@selector(resetMediaKeyJump)
1016 if ((keyCode == NX_KEYTYPE_REWIND || keyCode == NX_KEYTYPE_PREVIOUS) && !b_mediakeyJustJumped) {
1017 if (keyState == 0 && keyRepeat == 0)
1018 [[VLCCoreInteraction sharedInstance] previous];
1019 else if (keyRepeat == 1) {
1020 [[VLCCoreInteraction sharedInstance] backwardShort];
1021 b_mediakeyJustJumped = YES;
1022 [self performSelector:@selector(resetMediaKeyJump)
1031 #pragma mark Other notification
1033 /* Listen to the remote in exclusive mode, only when VLC is the active
1035 - (void)applicationDidBecomeActive:(NSNotification *)aNotification
1039 if (var_InheritBool(p_intf, "macosx-appleremote") == YES)
1040 [o_remote startListening: self];
1042 - (void)applicationDidResignActive:(NSNotification *)aNotification
1046 [o_remote stopListening: self];
1049 /* Triggered when the computer goes to sleep */
1050 - (void)computerWillSleep: (NSNotification *)notification
1052 [[VLCCoreInteraction sharedInstance] pause];
1056 #pragma mark File opening over dock icon
1058 - (void)application:(NSApplication *)o_app openFiles:(NSArray *)o_names
1060 char *psz_uri = vlc_path2uri([[o_names objectAtIndex:0] UTF8String], "file");
1062 if (launched == NO) {
1063 if (items_at_launch) {
1064 int items = [o_names count];
1065 if (items > items_at_launch)
1066 items_at_launch = 0;
1068 items_at_launch -= items;
1073 // try to add file as subtitle
1074 if ([o_names count] == 1 && psz_uri) {
1075 input_thread_t * p_input = pl_CurrentInput(VLCIntf);
1077 BOOL b_returned = NO;
1078 b_returned = input_AddSubtitle(p_input, psz_uri, true);
1079 vlc_object_release(p_input);
1088 NSArray *o_sorted_names = [o_names sortedArrayUsingSelector: @selector(caseInsensitiveCompare:)];
1089 NSMutableArray *o_result = [NSMutableArray arrayWithCapacity: [o_sorted_names count]];
1090 for (int i = 0; i < [o_sorted_names count]; i++) {
1091 psz_uri = vlc_path2uri([[o_sorted_names objectAtIndex:i] UTF8String], "file");
1095 NSDictionary *o_dic = [NSDictionary dictionaryWithObject:[NSString stringWithCString:psz_uri encoding:NSUTF8StringEncoding] forKey:@"ITEM_URL"];
1097 [o_result addObject: o_dic];
1100 [o_playlist appendArray: o_result atPos: -1 enqueue: !config_GetInt(VLCIntf, "macosx-autoplay")];
1105 /* When user click in the Dock icon our double click in the finder */
1106 - (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)hasVisibleWindows
1108 if (!hasVisibleWindows)
1109 [o_mainwindow makeKeyAndOrderFront:self];
1115 #pragma mark Apple Remote Control
1117 /* Helper method for the remote control interface in order to trigger forward/backward and volume
1118 increase/decrease as long as the user holds the left/right, plus/minus button */
1119 - (void) executeHoldActionForRemoteButton: (NSNumber*) buttonIdentifierNumber
1121 if (b_remote_button_hold) {
1122 switch([buttonIdentifierNumber intValue]) {
1123 case kRemoteButtonRight_Hold:
1124 [[VLCCoreInteraction sharedInstance] forward];
1126 case kRemoteButtonLeft_Hold:
1127 [[VLCCoreInteraction sharedInstance] backward];
1129 case kRemoteButtonVolume_Plus_Hold:
1131 var_SetInteger(p_intf->p_libvlc, "key-action", ACTIONID_VOL_UP);
1133 case kRemoteButtonVolume_Minus_Hold:
1135 var_SetInteger(p_intf->p_libvlc, "key-action", ACTIONID_VOL_DOWN);
1138 if (b_remote_button_hold) {
1140 [self performSelector:@selector(executeHoldActionForRemoteButton:)
1141 withObject:buttonIdentifierNumber
1147 /* Apple Remote callback */
1148 - (void) appleRemoteButton: (AppleRemoteEventIdentifier)buttonIdentifier
1149 pressedDown: (BOOL) pressedDown
1150 clickCount: (unsigned int) count
1152 switch(buttonIdentifier) {
1153 case k2009RemoteButtonFullscreen:
1154 [[VLCCoreInteraction sharedInstance] toggleFullscreen];
1156 case k2009RemoteButtonPlay:
1157 [[VLCCoreInteraction sharedInstance] playOrPause];
1159 case kRemoteButtonPlay:
1161 [[VLCCoreInteraction sharedInstance] toggleFullscreen];
1163 [[VLCCoreInteraction sharedInstance] playOrPause];
1165 case kRemoteButtonVolume_Plus:
1166 if (config_GetInt(VLCIntf, "macosx-appleremote-sysvol"))
1167 [NSSound increaseSystemVolume];
1170 var_SetInteger(p_intf->p_libvlc, "key-action", ACTIONID_VOL_UP);
1172 case kRemoteButtonVolume_Minus:
1173 if (config_GetInt(VLCIntf, "macosx-appleremote-sysvol"))
1174 [NSSound decreaseSystemVolume];
1177 var_SetInteger(p_intf->p_libvlc, "key-action", ACTIONID_VOL_DOWN);
1179 case kRemoteButtonRight:
1180 if (config_GetInt(VLCIntf, "macosx-appleremote-prevnext"))
1181 [[VLCCoreInteraction sharedInstance] forward];
1183 [[VLCCoreInteraction sharedInstance] next];
1185 case kRemoteButtonLeft:
1186 if (config_GetInt(VLCIntf, "macosx-appleremote-prevnext"))
1187 [[VLCCoreInteraction sharedInstance] backward];
1189 [[VLCCoreInteraction sharedInstance] previous];
1191 case kRemoteButtonRight_Hold:
1192 case kRemoteButtonLeft_Hold:
1193 case kRemoteButtonVolume_Plus_Hold:
1194 case kRemoteButtonVolume_Minus_Hold:
1195 /* simulate an event as long as the user holds the button */
1196 b_remote_button_hold = pressedDown;
1198 NSNumber* buttonIdentifierNumber = @(buttonIdentifier);
1199 [self performSelector:@selector(executeHoldActionForRemoteButton:)
1200 withObject:buttonIdentifierNumber];
1203 case kRemoteButtonMenu:
1204 [o_controls showPosition: self]; //FIXME
1206 case kRemoteButtonPlay_Sleep:
1208 NSAppleScript * script = [[NSAppleScript alloc] initWithSource:@"tell application \"System Events\" to sleep"];
1209 [script executeAndReturnError:nil];
1214 /* Add here whatever you want other buttons to do */
1220 #pragma mark Key Shortcuts
1222 /*****************************************************************************
1223 * hasDefinedShortcutKey: Check to see if the key press is a defined VLC
1224 * shortcut key. If it is, pass it off to VLC for handling and return YES,
1225 * otherwise ignore it and return NO (where it will get handled by Cocoa).
1226 *****************************************************************************/
1227 - (BOOL)hasDefinedShortcutKey:(NSEvent *)o_event force:(BOOL)b_force
1231 unsigned int i_pressed_modifiers = 0;
1234 i_pressed_modifiers = [o_event modifierFlags];
1236 if (i_pressed_modifiers & NSControlKeyMask)
1237 val.i_int |= KEY_MODIFIER_CTRL;
1239 if (i_pressed_modifiers & NSAlternateKeyMask)
1240 val.i_int |= KEY_MODIFIER_ALT;
1242 if (i_pressed_modifiers & NSShiftKeyMask)
1243 val.i_int |= KEY_MODIFIER_SHIFT;
1245 if (i_pressed_modifiers & NSCommandKeyMask)
1246 val.i_int |= KEY_MODIFIER_COMMAND;
1248 NSString * characters = [o_event charactersIgnoringModifiers];
1249 if ([characters length] > 0) {
1250 key = [[characters lowercaseString] characterAtIndex: 0];
1252 /* handle Lion's default key combo for fullscreen-toggle in addition to our own hotkeys */
1253 if (key == 'f' && i_pressed_modifiers & NSControlKeyMask && i_pressed_modifiers & NSCommandKeyMask) {
1254 [[VLCCoreInteraction sharedInstance] toggleFullscreen];
1260 case NSDeleteCharacter:
1261 case NSDeleteFunctionKey:
1262 case NSDeleteCharFunctionKey:
1263 case NSBackspaceCharacter:
1264 case NSUpArrowFunctionKey:
1265 case NSDownArrowFunctionKey:
1266 case NSEnterCharacter:
1267 case NSCarriageReturnCharacter:
1272 val.i_int |= CocoaKeyToVLC(key);
1274 BOOL b_found_key = NO;
1275 for (int i = 0; i < [o_usedHotkeys count]; i++) {
1276 NSString *str = [o_usedHotkeys objectAtIndex:i];
1277 unsigned int i_keyModifiers = [[VLCStringUtility sharedInstance] VLCModifiersToCocoa: str];
1279 if ([[characters lowercaseString] isEqualToString: [[VLCStringUtility sharedInstance] VLCKeyToString: str]] &&
1280 (i_keyModifiers & NSShiftKeyMask) == (i_pressed_modifiers & NSShiftKeyMask) &&
1281 (i_keyModifiers & NSControlKeyMask) == (i_pressed_modifiers & NSControlKeyMask) &&
1282 (i_keyModifiers & NSAlternateKeyMask) == (i_pressed_modifiers & NSAlternateKeyMask) &&
1283 (i_keyModifiers & NSCommandKeyMask) == (i_pressed_modifiers & NSCommandKeyMask)) {
1290 var_SetInteger(p_intf->p_libvlc, "key-pressed", val.i_int);
1298 - (void)updateCurrentlyUsedHotkeys
1300 NSMutableArray *o_tempArray = [[NSMutableArray alloc] init];
1301 /* Get the main Module */
1302 module_t *p_main = module_get_main();
1305 module_config_t *p_config;
1307 p_config = module_config_get (p_main, &confsize);
1309 for (size_t i = 0; i < confsize; i++) {
1310 module_config_t *p_item = p_config + i;
1312 if (CONFIG_ITEM(p_item->i_type) && p_item->psz_name != NULL
1313 && !strncmp(p_item->psz_name , "key-", 4)
1314 && !EMPTY_STR(p_item->psz_text)) {
1315 if (p_item->value.psz)
1316 [o_tempArray addObject: @(p_item->value.psz)];
1319 module_config_free (p_config);
1322 [o_usedHotkeys release];
1323 o_usedHotkeys = [[NSArray alloc] initWithArray: o_tempArray copyItems: YES];
1324 [o_tempArray release];
1328 #pragma mark Interface updaters
1330 - (void)PlaylistItemChanged
1332 if (p_current_input && (p_current_input->b_dead || !vlc_object_alive(p_current_input))) {
1333 var_DelCallback(p_current_input, "intf-event", InputEvent, [VLCMain sharedInstance]);
1334 p_input_changed = p_current_input;
1335 p_current_input = NULL;
1337 [o_mainmenu setRateControlsEnabled: NO];
1339 else if (!p_current_input) {
1340 // object is hold here and released then it is dead
1341 p_current_input = playlist_CurrentInput(pl_Get(VLCIntf));
1342 if (p_current_input) {
1343 var_AddCallback(p_current_input, "intf-event", InputEvent, [VLCMain sharedInstance]);
1344 [self playbackStatusUpdated];
1345 [o_mainmenu setRateControlsEnabled: YES];
1346 if ([self activeVideoPlayback] && [[o_mainwindow videoView] isHidden])
1347 [o_mainwindow performSelectorOnMainThread:@selector(togglePlaylist:) withObject: nil waitUntilDone:NO];
1348 p_input_changed = vlc_object_hold(p_current_input);
1352 [o_playlist updateRowSelection];
1353 [o_mainwindow updateWindow];
1354 [self updateDelays];
1355 [self updateMainMenu];
1358 - (void)informInputChanged
1360 if (p_input_changed) {
1361 [[ExtensionsManager getInstance:p_intf] inputChanged:p_input_changed];
1362 vlc_object_release(p_input_changed);
1363 p_input_changed = NULL;
1367 - (void)updateMainMenu
1369 [o_mainmenu setupMenus];
1370 [o_mainmenu updatePlaybackRate];
1371 [[VLCCoreInteraction sharedInstance] resetAtoB];
1374 - (void)updateMainWindow
1376 [o_mainwindow updateWindow];
1379 - (void)showMainWindow
1381 [o_mainwindow performSelectorOnMainThread:@selector(makeKeyAndOrderFront:) withObject:nil waitUntilDone:NO];
1384 - (void)showFullscreenController
1386 // defer selector here (possibly another time) to ensure that keyWindow is set properly
1387 // (needed for NSApplicationDidBecomeActiveNotification)
1388 [o_mainwindow performSelectorOnMainThread:@selector(showFullscreenController) withObject:nil waitUntilDone:NO];
1391 - (void)updateDelays
1393 [[VLCTrackSynchronization sharedInstance] performSelectorOnMainThread: @selector(updateValues) withObject: nil waitUntilDone:NO];
1398 [o_mainwindow updateName];
1401 - (void)updatePlaybackPosition
1403 [o_mainwindow updateTimeSlider];
1404 [[VLCCoreInteraction sharedInstance] updateAtoB];
1407 - (void)updateVolume
1409 [o_mainwindow updateVolumeSlider];
1412 - (void)playlistUpdated
1414 @synchronized(self) {
1415 b_playlist_updated_selector_in_queue = NO;
1418 [self playbackStatusUpdated];
1419 [o_playlist playlistUpdated];
1420 [o_mainwindow updateWindow];
1421 [o_mainwindow updateName];
1423 [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCMediaKeySupportSettingChanged"
1428 - (void)updateRecordState: (BOOL)b_value
1430 [o_mainmenu updateRecordState:b_value];
1433 - (void)updateInfoandMetaPanel
1435 [o_playlist outlineViewSelectionDidChange:nil];
1438 - (void)resumeItunesPlayback:(id)sender
1440 if (b_has_itunes_paused && var_InheritInteger(p_intf, "macosx-control-itunes") > 1) {
1441 iTunesApplication *iTunesApp = [SBApplication applicationWithBundleIdentifier:@"com.apple.iTunes"];
1442 if (iTunesApp && [iTunesApp isRunning]) {
1443 if ([iTunesApp playerState] == iTunesEPlSPaused) {
1444 msg_Dbg(p_intf, "Unpause iTunes...");
1445 [iTunesApp playpause];
1451 b_has_itunes_paused = NO;
1452 o_itunes_play_timer = nil;
1455 - (void)playbackStatusUpdated
1458 if (p_current_input) {
1459 state = var_GetInteger(p_current_input, "state");
1462 int i_control_itunes = var_InheritInteger(p_intf, "macosx-control-itunes");
1463 // cancel itunes timer if next item starts playing
1464 if (state > -1 && state != END_S && i_control_itunes > 0) {
1465 if (o_itunes_play_timer) {
1466 [o_itunes_play_timer invalidate];
1467 o_itunes_play_timer = nil;
1471 if (state == PLAYING_S) {
1473 if (i_control_itunes > 0 && !b_has_itunes_paused) {
1474 iTunesApplication *iTunesApp = [SBApplication applicationWithBundleIdentifier:@"com.apple.iTunes"];
1475 if (iTunesApp && [iTunesApp isRunning]) {
1476 if ([iTunesApp playerState] == iTunesEPlSPlaying) {
1477 msg_Dbg(p_intf, "Pause iTunes...");
1479 b_has_itunes_paused = YES;
1485 /* Declare user activity.
1486 This wakes the display if it is off, and postpones display sleep according to the users system preferences
1487 Available from 10.7.3 */
1488 #ifdef MAC_OS_X_VERSION_10_7
1489 if ([self activeVideoPlayback] && IOPMAssertionDeclareUserActivity)
1491 CFStringRef reasonForActivity = CFStringCreateWithCString(kCFAllocatorDefault, _("VLC media playback"), kCFStringEncodingUTF8);
1492 IOPMAssertionDeclareUserActivity(reasonForActivity,
1493 kIOPMUserActiveLocal,
1494 &userActivityAssertionID);
1495 CFRelease(reasonForActivity);
1499 /* prevent the system from sleeping */
1500 if (systemSleepAssertionID > 0) {
1501 msg_Dbg(VLCIntf, "releasing old sleep blocker (%i)" , systemSleepAssertionID);
1502 IOPMAssertionRelease(systemSleepAssertionID);
1506 /* 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 */
1507 if ((NSAppKitVersionNumber >= 1115.2 && NSAppKitVersionNumber < 1138.45) || OSX_MOUNTAIN_LION || OSX_SNOW_LEOPARD) {
1508 CFStringRef reasonForActivity = CFStringCreateWithCString(kCFAllocatorDefault, _("VLC media playback"), kCFStringEncodingUTF8);
1509 if ([self activeVideoPlayback])
1510 success = IOPMAssertionCreateWithName(kIOPMAssertionTypeNoDisplaySleep, kIOPMAssertionLevelOn, reasonForActivity, &systemSleepAssertionID);
1512 success = IOPMAssertionCreateWithName(kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn, reasonForActivity, &systemSleepAssertionID);
1513 CFRelease(reasonForActivity);
1515 /* fall-back on the 10.5 mode, which also works on 10.7.4 and 10.7.5 */
1516 if ([self activeVideoPlayback])
1517 success = IOPMAssertionCreate(kIOPMAssertionTypeNoDisplaySleep, kIOPMAssertionLevelOn, &systemSleepAssertionID);
1519 success = IOPMAssertionCreate(kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn, &systemSleepAssertionID);
1522 if (success == kIOReturnSuccess)
1523 msg_Dbg(VLCIntf, "prevented sleep through IOKit (%i)", systemSleepAssertionID);
1525 msg_Warn(VLCIntf, "failed to prevent system sleep through IOKit");
1527 [[self mainMenu] setPause];
1528 [o_mainwindow setPause];
1530 [o_mainmenu setSubmenusEnabled: FALSE];
1531 [[self mainMenu] setPlay];
1532 [o_mainwindow setPlay];
1534 /* allow the system to sleep again */
1535 if (systemSleepAssertionID > 0) {
1536 msg_Dbg(VLCIntf, "releasing sleep blocker (%i)" , systemSleepAssertionID);
1537 IOPMAssertionRelease(systemSleepAssertionID);
1540 if (state == END_S || state == -1) {
1541 if (i_control_itunes > 0) {
1542 if (o_itunes_play_timer) {
1543 [o_itunes_play_timer invalidate];
1545 o_itunes_play_timer = [NSTimer scheduledTimerWithTimeInterval: 0.5
1547 selector: @selector(resumeItunesPlayback:)
1554 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(updateMainWindow) withObject: nil waitUntilDone: NO];
1555 [self performSelectorOnMainThread:@selector(sendDistributedNotificationWithUpdatedPlaybackStatus) withObject: nil waitUntilDone: NO];
1558 - (void)sendDistributedNotificationWithUpdatedPlaybackStatus
1560 [[NSDistributedNotificationCenter defaultCenter] postNotificationName:@"VLCPlayerStateDidChange"
1563 deliverImmediately:YES];
1566 - (void)playbackModeUpdated
1568 vlc_value_t looping,repeating;
1569 playlist_t * p_playlist = pl_Get(VLCIntf);
1571 bool loop = var_GetBool(p_playlist, "loop");
1572 bool repeat = var_GetBool(p_playlist, "repeat");
1574 [[o_mainwindow controlsBar] setRepeatOne];
1575 [o_mainmenu setRepeatOne];
1577 [[o_mainwindow controlsBar] setRepeatAll];
1578 [o_mainmenu setRepeatAll];
1580 [[o_mainwindow controlsBar] setRepeatOff];
1581 [o_mainmenu setRepeatOff];
1584 [[o_mainwindow controlsBar] setShuffle];
1585 [o_mainmenu setShuffle];
1589 #pragma mark Window updater
1591 - (void)setActiveVideoPlayback:(BOOL)b_value
1593 b_active_videoplayback = b_value;
1595 [o_mainwindow performSelectorOnMainThread:@selector(setVideoplayEnabled) withObject:nil waitUntilDone:YES];
1596 [o_mainwindow performSelectorOnMainThread:@selector(togglePlaylist:) withObject:nil waitUntilDone:NO];
1599 // update sleep blockers
1600 [self performSelectorOnMainThread:@selector(playbackStatusUpdated) withObject:nil waitUntilDone:NO];
1604 #pragma mark Other objects getters
1611 - (VLCMainWindow *)mainWindow
1613 return o_mainwindow;
1627 o_bookmarks = [[VLCBookmarks alloc] init];
1629 if (!nib_bookmarks_loaded)
1630 nib_bookmarks_loaded = [NSBundle loadNibNamed:@"Bookmarks" owner: NSApp];
1640 if (!nib_open_loaded)
1641 nib_open_loaded = [NSBundle loadNibNamed:@"Open" owner: NSApp];
1646 - (id)simplePreferences
1649 o_sprefs = [[VLCSimplePrefs alloc] init];
1651 if (!nib_prefs_loaded)
1652 nib_prefs_loaded = [NSBundle loadNibNamed:@"Preferences" owner: NSApp];
1660 o_prefs = [[VLCPrefs alloc] init];
1662 if (!nib_prefs_loaded)
1663 nib_prefs_loaded = [NSBundle loadNibNamed:@"Preferences" owner: NSApp];
1678 if (! nib_info_loaded)
1679 nib_info_loaded = [NSBundle loadNibNamed:@"MediaInfo" owner: NSApp];
1690 o_wizard = [[VLCWizard alloc] init];
1692 if (!nib_wizard_loaded) {
1693 nib_wizard_loaded = [NSBundle loadNibNamed:@"Wizard" owner: NSApp];
1694 [o_wizard initStrings];
1699 - (id)coreDialogProvider
1702 return o_coredialogs;
1707 - (id)eyeTVController
1715 - (id)appleRemoteController
1720 - (BOOL)activeVideoPlayback
1722 return b_active_videoplayback;
1726 #pragma mark Crash Log
1727 - (void)sendCrashLog:(NSString *)crashLog withUserComment:(NSString *)userComment
1729 NSString *urlStr = @"http://crash.videolan.org/crashlog/sendcrashreport.php";
1730 NSURL *url = [NSURL URLWithString:urlStr];
1732 NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
1733 [req setHTTPMethod:@"POST"];
1736 if ([o_crashrep_includeEmail_ckb state] == NSOnState) {
1737 ABPerson * contact = [[ABAddressBook sharedAddressBook] me];
1738 ABMultiValue *emails = [contact valueForProperty:kABEmailProperty];
1739 email = [emails valueAtIndex:[emails indexForIdentifier:
1740 [emails primaryIdentifier]]];
1743 email = [NSString string];
1746 postBody = [NSString stringWithFormat:@"CrashLog=%@&Comment=%@&Email=%@\r\n",
1747 [crashLog stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
1748 [userComment stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
1749 [email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
1751 [req setHTTPBody:[postBody dataUsingEncoding:NSUTF8StringEncoding]];
1753 /* Released from delegate */
1754 crashLogURLConnection = [[NSURLConnection alloc] initWithRequest:req delegate:self];
1757 - (void)connectionDidFinishLoading:(NSURLConnection *)connection
1759 msg_Dbg(p_intf, "crash report successfully sent");
1760 [crashLogURLConnection release];
1761 crashLogURLConnection = nil;
1764 - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
1766 msg_Warn (p_intf, "Error when sending the crash report: %s (%li)", [[error localizedDescription] UTF8String], [error code]);
1767 [crashLogURLConnection release];
1768 crashLogURLConnection = nil;
1771 - (NSString *)latestCrashLogPathPreviouslySeen:(BOOL)previouslySeen
1773 NSString * crashReporter;
1774 if (OSX_MOUNTAIN_LION)
1775 crashReporter = [@"~/Library/Logs/DiagnosticReports" stringByExpandingTildeInPath];
1777 crashReporter = [@"~/Library/Logs/CrashReporter" stringByExpandingTildeInPath];
1778 NSDirectoryEnumerator *direnum = [[NSFileManager defaultManager] enumeratorAtPath:crashReporter];
1780 NSString * latestLog = nil;
1781 NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
1782 int year = !previouslySeen ? [defaults integerForKey:@"LatestCrashReportYear"] : 0;
1783 int month = !previouslySeen ? [defaults integerForKey:@"LatestCrashReportMonth"]: 0;
1784 int day = !previouslySeen ? [defaults integerForKey:@"LatestCrashReportDay"] : 0;
1785 int hours = !previouslySeen ? [defaults integerForKey:@"LatestCrashReportHours"]: 0;
1787 while (fname = [direnum nextObject]) {
1788 [direnum skipDescendents];
1789 if ([fname hasPrefix:@"VLC"] && [fname hasSuffix:@"crash"]) {
1790 NSArray * compo = [fname componentsSeparatedByString:@"_"];
1791 if ([compo count] < 3)
1793 compo = [[compo objectAtIndex:1] componentsSeparatedByString:@"-"];
1794 if ([compo count] < 4)
1798 if (year < [[compo objectAtIndex:0] intValue] ||
1799 (year ==[[compo objectAtIndex:0] intValue] &&
1800 (month < [[compo objectAtIndex:1] intValue] ||
1801 (month ==[[compo objectAtIndex:1] intValue] &&
1802 (day < [[compo objectAtIndex:2] intValue] ||
1803 (day ==[[compo objectAtIndex:2] intValue] &&
1804 hours < [[compo objectAtIndex:3] intValue])))))) {
1805 year = [[compo objectAtIndex:0] intValue];
1806 month = [[compo objectAtIndex:1] intValue];
1807 day = [[compo objectAtIndex:2] intValue];
1808 hours = [[compo objectAtIndex:3] intValue];
1809 latestLog = [crashReporter stringByAppendingPathComponent:fname];
1814 if (!(latestLog && [[NSFileManager defaultManager] fileExistsAtPath:latestLog]))
1817 if (!previouslySeen) {
1818 [defaults setInteger:year forKey:@"LatestCrashReportYear"];
1819 [defaults setInteger:month forKey:@"LatestCrashReportMonth"];
1820 [defaults setInteger:day forKey:@"LatestCrashReportDay"];
1821 [defaults setInteger:hours forKey:@"LatestCrashReportHours"];
1826 - (NSString *)latestCrashLogPath
1828 return [self latestCrashLogPathPreviouslySeen:YES];
1831 - (void)lookForCrashLog
1833 NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
1834 // This pref key doesn't exists? this VLC is an upgrade, and this crash log come from previous version
1835 NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
1836 BOOL areCrashLogsTooOld = ![defaults integerForKey:@"LatestCrashReportYear"];
1837 NSString * latestLog = [self latestCrashLogPathPreviouslySeen:NO];
1838 if (latestLog && !areCrashLogsTooOld) {
1839 if ([defaults integerForKey:@"AlwaysSendCrashReports"] > 0)
1840 [self sendCrashLog:[NSString stringWithContentsOfFile: [self latestCrashLogPath] encoding: NSUTF8StringEncoding error: NULL] withUserComment: [o_crashrep_fld string]];
1841 else if ([defaults integerForKey:@"AlwaysSendCrashReports"] == 0)
1842 [NSApp runModalForWindow: o_crashrep_win];
1843 // bail out, the user doesn't want us to send reports
1849 - (IBAction)crashReporterAction:(id)sender
1851 if (sender == o_crashrep_send_btn) {
1852 [self sendCrashLog:[NSString stringWithContentsOfFile: [self latestCrashLogPath] encoding: NSUTF8StringEncoding error: NULL] withUserComment: [o_crashrep_fld string]];
1853 if ([o_crashrep_dontaskagain_ckb state])
1854 [[NSUserDefaults standardUserDefaults] setInteger:1 forKey:@"AlwaysSendCrashReports"];
1856 if ([o_crashrep_dontaskagain_ckb state])
1857 [[NSUserDefaults standardUserDefaults] setInteger:-1 forKey:@"AlwaysSendCrashReports"];
1861 [o_crashrep_win orderOut: sender];
1864 - (IBAction)openCrashLog:(id)sender
1866 NSString * latestLog = [self latestCrashLogPath];
1868 [[NSWorkspace sharedWorkspace] openFile: latestLog withApplication: @"Console"];
1870 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."));
1875 #pragma mark Remove old prefs
1877 - (void)removeOldPreferences
1879 static NSString * kVLCPreferencesVersion = @"VLCPreferencesVersion";
1880 static const int kCurrentPreferencesVersion = 3;
1881 NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
1882 int version = [defaults integerForKey:kVLCPreferencesVersion];
1883 if (version >= kCurrentPreferencesVersion)
1887 [defaults setInteger:kCurrentPreferencesVersion forKey:kVLCPreferencesVersion];
1888 [defaults synchronize];
1890 if (![[VLCCoreInteraction sharedInstance] fixPreferences])
1893 config_SaveConfigFile(VLCIntf); // we need to do manually, since we won't quit libvlc cleanly
1894 } else if (version == 2) {
1895 /* version 2 (used by VLC 2.0.x and early versions of 2.1) can lead to exceptions within 2.1 or later
1896 * so we reset the OS X specific prefs here - in practice, no user will notice */
1897 [NSUserDefaults resetStandardUserDefaults];
1899 [defaults setInteger:kCurrentPreferencesVersion forKey:kVLCPreferencesVersion];
1900 [defaults synchronize];
1902 NSArray *libraries = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,
1903 NSUserDomainMask, YES);
1904 if (!libraries || [libraries count] == 0) return;
1905 NSString * preferences = [[libraries objectAtIndex:0] stringByAppendingPathComponent:@"Preferences"];
1907 /* File not found, don't attempt anything */
1908 if (![[NSFileManager defaultManager] fileExistsAtPath:[preferences stringByAppendingPathComponent:@"org.videolan.vlc"]] &&
1909 ![[NSFileManager defaultManager] fileExistsAtPath:[preferences stringByAppendingPathComponent:@"org.videolan.vlc.plist"]]) {
1910 [defaults setInteger:kCurrentPreferencesVersion forKey:kVLCPreferencesVersion];
1914 int res = NSRunInformationalAlertPanel(_NS("Remove old preferences?"),
1915 _NS("We just found an older version of VLC's preferences files."),
1916 _NS("Move To Trash and Relaunch VLC"), _NS("Ignore"), nil, nil);
1917 if (res != NSOKButton) {
1918 [defaults setInteger:kCurrentPreferencesVersion forKey:kVLCPreferencesVersion];
1922 NSArray * ourPreferences = @[@"org.videolan.vlc.plist", @"VLC", @"org.videolan.vlc"];
1924 /* Move the file to trash so that user can find them later */
1925 [[NSWorkspace sharedWorkspace] performFileOperation:NSWorkspaceRecycleOperation source:preferences destination:nil files:ourPreferences tag:0];
1927 /* really reset the defaults from now on */
1928 [NSUserDefaults resetStandardUserDefaults];
1930 [defaults setInteger:kCurrentPreferencesVersion forKey:kVLCPreferencesVersion];
1931 [defaults synchronize];
1935 const char * path = [[[NSBundle mainBundle] executablePath] UTF8String];
1937 /* For some reason we need to fork(), not just execl(), which reports a ENOTSUP then. */
1942 execl(path, path, NULL);
1946 #pragma mark Errors, warnings and messages
1947 - (IBAction)updateMessagesPanel:(id)sender
1949 [self windowDidBecomeKey:nil];
1952 - (IBAction)showMessagesPanel:(id)sender
1954 /* subscribe to LibVLCCore's messages */
1955 vlc_LogSet(p_intf->p_libvlc, MsgCallback, NULL);
1958 [o_msgs_panel makeKeyAndOrderFront: sender];
1961 - (void)windowDidBecomeKey:(NSNotification *)o_notification
1963 [o_msgs_table reloadData];
1964 [o_msgs_table scrollRowToVisible: [o_msg_arr count] - 1];
1967 - (void)windowWillClose:(NSNotification *)o_notification
1969 /* unsubscribe from LibVLCCore's messages */
1970 vlc_LogSet( p_intf->p_libvlc, NULL, NULL );
1973 - (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView
1975 if (aTableView == o_msgs_table)
1976 return [o_msg_arr count];
1980 - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
1982 NSMutableAttributedString *result = NULL;
1985 if (rowIndex < [o_msg_arr count])
1986 result = [o_msg_arr objectAtIndex:rowIndex];
1987 [o_msg_lock unlock];
1995 - (void)processReceivedlibvlcMessage:(const vlc_log_t *) item ofType: (int)i_type withStr: (char *)str
1998 NSColor *o_white = [NSColor whiteColor];
1999 NSColor *o_red = [NSColor redColor];
2000 NSColor *o_yellow = [NSColor yellowColor];
2001 NSColor *o_gray = [NSColor grayColor];
2002 NSString * firstString, * secondString;
2004 NSColor * pp_color[4] = { o_white, o_red, o_yellow, o_gray };
2005 static const char * ppsz_type[4] = { ": ", " error: ", " warning: ", " debug: " };
2007 NSDictionary *o_attr;
2008 NSMutableAttributedString *o_msg_color;
2012 if ([o_msg_arr count] > 600) {
2013 [o_msg_arr removeObjectAtIndex: 0];
2014 [o_msg_arr removeObjectAtIndex: 1];
2016 firstString = [NSString stringWithFormat:@"%s%s", item->psz_module, ppsz_type[i_type]];
2017 secondString = [NSString stringWithFormat:@"%@%s\n", firstString, str];
2019 o_attr = [NSDictionary dictionaryWithObject: pp_color[i_type] forKey: NSForegroundColorAttributeName];
2020 o_msg_color = [[NSMutableAttributedString alloc] initWithString: secondString attributes: o_attr];
2021 o_attr = [NSDictionary dictionaryWithObject: pp_color[3] forKey: NSForegroundColorAttributeName];
2022 [o_msg_color setAttributes: o_attr range: NSMakeRange(0, [firstString length])];
2023 [o_msg_arr addObject: [o_msg_color autorelease]];
2025 b_msg_arr_changed = YES;
2026 [o_msg_lock unlock];
2030 - (IBAction)saveDebugLog:(id)sender
2032 NSSavePanel * saveFolderPanel = [[NSSavePanel alloc] init];
2034 [saveFolderPanel setCanSelectHiddenExtension: NO];
2035 [saveFolderPanel setCanCreateDirectories: YES];
2036 [saveFolderPanel setAllowedFileTypes: @[@"rtf"]];
2037 [saveFolderPanel setNameFieldStringValue:[NSString stringWithFormat: _NS("VLC Debug Log (%s).rtf"), VERSION_MESSAGE]];
2038 [saveFolderPanel beginSheetModalForWindow: o_msgs_panel completionHandler:^(NSInteger returnCode) {
2039 if (returnCode == NSOKButton) {
2040 NSUInteger count = [o_msg_arr count];
2041 NSMutableAttributedString * string = [[NSMutableAttributedString alloc] init];
2042 for (NSUInteger i = 0; i < count; i++)
2043 [string appendAttributedString: [o_msg_arr objectAtIndex:i]];
2045 NSData *data = [string RTFFromRange:NSMakeRange(0, [string length])
2046 documentAttributes:[NSDictionary dictionaryWithObject: NSRTFTextDocumentType forKey: NSDocumentTypeDocumentAttribute]];
2048 if ([data writeToFile: [[saveFolderPanel URL] path] atomically: YES] == NO)
2049 msg_Warn(p_intf, "Error while saving the debug log");
2054 [saveFolderPanel release];
2058 #pragma mark Playlist toggling
2060 - (void)updateTogglePlaylistState
2062 [[self playlist] outlineViewSelectionDidChange: NULL];
2069 @implementation VLCMain (Internal)
2071 - (void)handlePortMessage:(NSPortMessage *)o_msg
2076 NSInvocation * o_inv;
2077 NSConditionLock * o_lock;
2079 o_data = [[o_msg components] lastObject];
2080 o_inv = *((NSInvocation **)[o_data bytes]);
2081 [o_inv getArgument: &o_value atIndex: 2];
2082 val = (id **)[o_value pointerValue];
2083 [o_inv setArgument: val[1] atIndex: 2];
2088 [o_lock unlockWithCondition: 1];
2091 - (void)resetMediaKeyJump
2093 b_mediakeyJustJumped = NO;
2096 - (void)coreChangedMediaKeySupportSetting: (NSNotification *)o_notification
2098 b_mediaKeySupport = var_InheritBool(VLCIntf, "macosx-mediakeys");
2099 if (b_mediaKeySupport) {
2100 if (!o_mediaKeyController)
2101 o_mediaKeyController = [[SPMediaKeyTap alloc] initWithDelegate:self];
2103 if ([[[VLCMain sharedInstance] playlist] currentPlaylistRoot]->i_children > 0 ||
2105 [o_mediaKeyController startWatchingMediaKeys];
2107 [o_mediaKeyController stopWatchingMediaKeys];
2109 else if (!b_mediaKeySupport && o_mediaKeyController)
2110 [o_mediaKeyController stopWatchingMediaKeys];
2115 /*****************************************************************************
2116 * VLCApplication interface
2117 *****************************************************************************/
2119 @implementation VLCApplication
2120 // when user selects the quit menu from dock it sends a terminate:
2121 // but we need to send a stop: to properly exits libvlc.
2122 // However, we are not able to change the action-method sent by this standard menu item.
2123 // thus we override terminate: to send a stop:
2124 // see [af97f24d528acab89969d6541d83f17ce1ecd580] that introduced the removal of setjmp() and longjmp()
2125 - (void)terminate:(id)sender
2127 [self activateIgnoringOtherApps:YES];