1 /*****************************************************************************
2 * intf.m: MacOS X interface module
3 *****************************************************************************
4 * Copyright (C) 2002-2012 VLC authors and VideoLAN
7 * Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
8 * Christophe Massiot <massiot@via.ecp.fr>
9 * Derk-Jan Hartman <hartman at videolan.org>
10 * Felix Paul Kühne <fkuehne at videolan dot org>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25 *****************************************************************************/
27 /*****************************************************************************
29 *****************************************************************************/
34 #include <stdlib.h> /* malloc(), free() */
35 #include <sys/param.h> /* for MAXPATHLEN */
37 #include <vlc_common.h>
39 #include <vlc_dialog.h>
41 #include <vlc_modules.h>
42 #include <vlc_plugin.h>
43 #include <vlc_aout_intf.h>
44 #include <vlc_vout_window.h>
45 #include <vlc_vout_display.h>
46 #include <unistd.h> /* execl() */
48 #import "CompatibilityFixes.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"
66 #import <AddressBook/AddressBook.h> /* for crashlog send mechanism */
67 #import <Sparkle/Sparkle.h> /* we're the update delegate */
69 /*****************************************************************************
71 *****************************************************************************/
72 static void Run ( intf_thread_t *p_intf );
74 static void updateProgressPanel (void *, const char *, float);
75 static bool checkProgressPanel (void *);
76 static void destroyProgressPanel (void *);
78 static void MsgCallback( void *data, int type, const msg_item_t *item, const char *format, va_list ap );
80 static int InputEvent( vlc_object_t *, const char *,
81 vlc_value_t, vlc_value_t, void * );
82 static int PLItemChanged( vlc_object_t *, const char *,
83 vlc_value_t, vlc_value_t, void * );
84 static int PlaylistUpdated( vlc_object_t *, const char *,
85 vlc_value_t, vlc_value_t, void * );
86 static int PlaybackModeUpdated( vlc_object_t *, const char *,
87 vlc_value_t, vlc_value_t, void * );
88 static int VolumeUpdated( vlc_object_t *, const char *,
89 vlc_value_t, vlc_value_t, void * );
92 #pragma mark VLC Interface Object Callbacks
94 /*****************************************************************************
95 * OpenIntf: initialize interface
96 *****************************************************************************/
97 int OpenIntf ( vlc_object_t *p_this )
99 NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
100 [VLCApplication sharedApplication];
102 intf_thread_t *p_intf = (intf_thread_t*) p_this;
104 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
105 if( p_intf->p_sys == NULL )
108 memset( p_intf->p_sys, 0, sizeof( *p_intf->p_sys ) );
110 /* subscribe to LibVLCCore's messages */
111 vlc_Subscribe( &p_intf->p_sys->sub, MsgCallback, NULL );
119 /*****************************************************************************
120 * CloseIntf: destroy interface
121 *****************************************************************************/
122 void CloseIntf ( vlc_object_t *p_this )
124 intf_thread_t *p_intf = (intf_thread_t*) p_this;
126 free( p_intf->p_sys );
129 static int WindowControl( vout_window_t *, int i_query, va_list );
131 int WindowOpen( vout_window_t *p_wnd, const vout_window_cfg_t *cfg )
133 NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
134 intf_thread_t *p_intf = VLCIntf;
136 msg_Err( p_wnd, "Mac OS X interface not found" );
142 unsigned i_width = cfg->width;
143 unsigned i_height = cfg->height;
144 p_wnd->handle.nsobject = [[VLCMain sharedInstance] getVideoViewAtPositionX: &i_x Y: &i_y withWidth: &i_width andHeight: &i_height];
146 if ( !p_wnd->handle.nsobject ) {
147 msg_Err( p_wnd, "got no video view from the interface" );
152 [[VLCMain sharedInstance] setNativeVideoSize:NSMakeSize( cfg->width, cfg->height )];
153 [[VLCMain sharedInstance] setActiveVideoPlayback: YES];
154 p_wnd->control = WindowControl;
155 p_wnd->sys = (vout_window_sys_t *)VLCIntf;
160 static int WindowControl( vout_window_t *p_wnd, int i_query, va_list args )
164 case VOUT_WINDOW_SET_STATE:
166 unsigned i_state = va_arg( args, unsigned );
167 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(setWindowLevel:) withObject:[NSNumber numberWithUnsignedInt:i_state] waitUntilDone:NO];
170 case VOUT_WINDOW_SET_SIZE:
172 unsigned int i_width = va_arg( args, unsigned int );
173 unsigned int i_height = va_arg( args, unsigned int );
174 [[VLCMain sharedInstance] setNativeVideoSize:NSMakeSize( i_width, i_height )];
177 case VOUT_WINDOW_SET_FULLSCREEN:
179 NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
180 int i_full = va_arg( args, int );
181 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(checkFullscreenChange:) withObject:[NSNumber numberWithInt: i_full] waitUntilDone:NO];
186 msg_Warn( p_wnd, "unsupported control query" );
191 void WindowClose( vout_window_t *p_wnd )
193 NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
194 [[VLCMain sharedInstance] setActiveVideoPlayback:NO];
199 /*****************************************************************************
201 *****************************************************************************/
202 static NSLock * o_appLock = nil; // controls access to f_appExit
204 static void Run( intf_thread_t *p_intf )
206 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
207 [VLCApplication sharedApplication];
209 o_appLock = [[NSLock alloc] init];
211 [[VLCMain sharedInstance] setIntf: p_intf];
212 [NSBundle loadNibNamed: @"MainMenu" owner: NSApp];
215 [[VLCMain sharedInstance] applicationWillTerminate:nil];
223 #pragma mark Variables Callback
225 /*****************************************************************************
226 * MsgCallback: Callback triggered by the core once a new debug message is
227 * ready to be displayed. We store everything in a NSArray in our Cocoa part
229 *****************************************************************************/
230 static void MsgCallback( void *data, int type, const msg_item_t *item, const char *format, va_list ap )
232 int canc = vlc_savecancel();
235 if (vasprintf( &str, format, ap ) == -1)
237 vlc_restorecancel( canc );
241 NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
242 [[VLCMain sharedInstance] processReceivedlibvlcMessage: item ofType: type withStr: str];
245 vlc_restorecancel( canc );
249 static int InputEvent( vlc_object_t *p_this, const char *psz_var,
250 vlc_value_t oldval, vlc_value_t new_val, void *param )
252 NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
253 switch (new_val.i_int) {
254 case INPUT_EVENT_STATE:
255 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(playbackStatusUpdated) withObject: nil waitUntilDone:NO];
257 case INPUT_EVENT_RATE:
258 [[[VLCMain sharedInstance] mainMenu] performSelectorOnMainThread:@selector(updatePlaybackRate) withObject: nil waitUntilDone:NO];
260 case INPUT_EVENT_POSITION:
261 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(updatePlaybackPosition) withObject: nil waitUntilDone:NO];
263 case INPUT_EVENT_TITLE:
264 case INPUT_EVENT_CHAPTER:
265 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(updateMainMenu) withObject: nil waitUntilDone:NO];
267 case INPUT_EVENT_CACHE:
268 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(updateMainWindow) withObject: nil waitUntilDone: NO];
270 case INPUT_EVENT_STATISTICS:
271 [[[VLCMain sharedInstance] info] performSelectorOnMainThread:@selector(updateStatistics) withObject: nil waitUntilDone: NO];
275 case INPUT_EVENT_TELETEXT:
277 case INPUT_EVENT_AOUT:
279 case INPUT_EVENT_VOUT:
281 case INPUT_EVENT_ITEM_META:
282 case INPUT_EVENT_ITEM_INFO:
283 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(updateMainMenu) withObject: nil waitUntilDone:NO];
284 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(updateName) withObject: nil waitUntilDone:NO];
285 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(updateInfoandMetaPanel) withObject: nil waitUntilDone:NO];
287 case INPUT_EVENT_BOOKMARK:
289 case INPUT_EVENT_RECORD:
290 [[VLCMain sharedInstance] updateRecordState: var_GetBool( p_this, "record" )];
292 case INPUT_EVENT_PROGRAM:
293 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(updateMainMenu) withObject: nil waitUntilDone:NO];
295 case INPUT_EVENT_ITEM_EPG:
297 case INPUT_EVENT_SIGNAL:
300 case INPUT_EVENT_ITEM_NAME:
301 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(updateName) withObject: nil waitUntilDone:NO];
302 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(playlistUpdated) withObject: nil waitUntilDone:NO];
305 case INPUT_EVENT_AUDIO_DELAY:
306 case INPUT_EVENT_SUBTITLE_DELAY:
307 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(updateDelays) withObject:nil waitUntilDone:NO];
310 case INPUT_EVENT_DEAD:
311 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(updateName) withObject: nil waitUntilDone:NO];
312 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(updatePlaybackPosition) withObject:nil waitUntilDone:NO];
315 case INPUT_EVENT_ABORT:
316 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(updateName) withObject: nil waitUntilDone:NO];
317 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(updatePlaybackPosition) withObject:nil waitUntilDone:NO];
321 //msg_Warn( p_this, "unhandled input event (%lld)", new_val.i_int );
329 static int PLItemChanged( vlc_object_t *p_this, const char *psz_var,
330 vlc_value_t oldval, vlc_value_t new_val, void *param )
332 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
333 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(PlaylistItemChanged) withObject:nil waitUntilDone:NO];
339 static int PlaylistUpdated( vlc_object_t *p_this, const char *psz_var,
340 vlc_value_t oldval, vlc_value_t new_val, void *param )
342 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
343 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(playlistUpdated) withObject:nil waitUntilDone:NO];
349 static int PlaybackModeUpdated( vlc_object_t *p_this, const char *psz_var,
350 vlc_value_t oldval, vlc_value_t new_val, void *param )
352 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
353 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(playbackModeUpdated) withObject:nil waitUntilDone:NO];
359 static int VolumeUpdated( vlc_object_t *p_this, const char *psz_var,
360 vlc_value_t oldval, vlc_value_t new_val, void *param )
362 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
363 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(updateVolume) withObject:nil waitUntilDone:NO];
369 /*****************************************************************************
370 * ShowController: Callback triggered by the show-intf playlist variable
371 * through the ShowIntf-control-intf, to let us show the controller-win;
372 * usually when in fullscreen-mode
373 *****************************************************************************/
374 static int ShowController( vlc_object_t *p_this, const char *psz_variable,
375 vlc_value_t old_val, vlc_value_t new_val, void *param )
377 intf_thread_t * p_intf = VLCIntf;
378 if( p_intf && p_intf->p_sys )
380 playlist_t * p_playlist = pl_Get( p_intf );
381 BOOL b_fullscreen = var_GetBool( p_playlist, "fullscreen" );
382 if( strcmp(psz_variable, "intf-toggle-fscontrol") || b_fullscreen )
384 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(showFullscreenController) withObject:nil waitUntilDone:NO];
388 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(showMainWindow) withObject:nil waitUntilDone:NO];
394 /*****************************************************************************
395 * FullscreenChanged: Callback triggered by the fullscreen-change playlist
396 * variable, to let the intf update the controller.
397 *****************************************************************************/
398 static int FullscreenChanged( vlc_object_t *p_this, const char *psz_variable,
399 vlc_value_t old_val, vlc_value_t new_val, void *param )
401 intf_thread_t * p_intf = VLCIntf;
404 NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
405 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(fullscreenChanged) withObject:nil waitUntilDone:NO];
411 /*****************************************************************************
412 * DialogCallback: Callback triggered by the "dialog-*" variables
413 * to let the intf display error and interaction dialogs
414 *****************************************************************************/
415 static int DialogCallback( vlc_object_t *p_this, const char *type, vlc_value_t previous, vlc_value_t value, void *data )
417 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
418 VLCMain *interface = (VLCMain *)data;
420 if( [[NSString stringWithUTF8String: type] isEqualToString: @"dialog-progress-bar"] )
422 /* the progress panel needs to update itself and therefore wants special treatment within this context */
423 dialog_progress_bar_t *p_dialog = (dialog_progress_bar_t *)value.p_address;
425 p_dialog->pf_update = updateProgressPanel;
426 p_dialog->pf_check = checkProgressPanel;
427 p_dialog->pf_destroy = destroyProgressPanel;
428 p_dialog->p_sys = VLCIntf->p_libvlc;
431 NSValue *o_value = [NSValue valueWithPointer:value.p_address];
432 [[VLCCoreDialogProvider sharedInstance] performEventWithObject: o_value ofType: type];
438 void updateProgressPanel (void *priv, const char *text, float value)
440 NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
444 o_txt = [NSString stringWithUTF8String: text];
448 [[[VLCMain sharedInstance] coreDialogProvider] updateProgressPanelWithText: o_txt andNumber: (double)(value * 1000.)];
453 void destroyProgressPanel (void *priv)
455 NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
456 [[[VLCMain sharedInstance] coreDialogProvider] destroyProgressPanel];
460 bool checkProgressPanel (void *priv)
462 NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
463 return [[[VLCMain sharedInstance] coreDialogProvider] progressCancelled];
470 input_thread_t *getInput(void)
472 intf_thread_t *p_intf = VLCIntf;
475 return pl_CurrentInput(p_intf);
478 vout_thread_t *getVout(void)
480 input_thread_t *p_input = getInput();
483 vout_thread_t *p_vout = input_GetVout(p_input);
484 vlc_object_release(p_input);
488 audio_output_t *getAout(void)
490 input_thread_t *p_input = getInput();
493 audio_output_t *p_aout = input_GetAout(p_input);
494 vlc_object_release(p_input);
501 @interface VLCMain ()
502 - (void)_removeOldPreferences;
505 /*****************************************************************************
506 * VLCMain implementation
507 *****************************************************************************/
508 @implementation VLCMain
511 #pragma mark Initialization
513 static VLCMain *_o_sharedMainInstance = nil;
515 + (VLCMain *)sharedInstance
517 return _o_sharedMainInstance ? _o_sharedMainInstance : [[self alloc] init];
522 if( _o_sharedMainInstance)
525 return _o_sharedMainInstance;
528 _o_sharedMainInstance = [super init];
531 p_current_input = NULL;
533 o_msg_lock = [[NSLock alloc] init];
534 o_msg_arr = [[NSMutableArray arrayWithCapacity: 600] retain];
536 o_open = [[VLCOpen alloc] init];
537 //o_embedded_list = [[VLCEmbeddedList alloc] init];
538 o_coredialogs = [[VLCCoreDialogProvider alloc] init];
539 o_info = [[VLCInfo alloc] init];
540 o_mainmenu = [[VLCMainMenu alloc] init];
541 o_coreinteraction = [[VLCCoreInteraction alloc] init];
542 o_eyetv = [[VLCEyeTVController alloc] init];
543 o_mainwindow = [[VLCMainWindow alloc] init];
545 /* announce our launch to a potential eyetv plugin */
546 [[NSDistributedNotificationCenter defaultCenter] postNotificationName: @"VLCOSXGUIInit"
547 object: @"VLCEyeTVSupport"
549 deliverImmediately: YES];
551 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
552 NSDictionary *appDefaults = [NSDictionary dictionaryWithObject:@"NO" forKey:@"LiveUpdateTheMessagesPanel"];
553 [defaults registerDefaults:appDefaults];
555 return _o_sharedMainInstance;
558 - (void)setIntf: (intf_thread_t *)p_mainintf {
562 - (intf_thread_t *)intf {
568 playlist_t *p_playlist;
570 if( !p_intf ) return;
571 var_Create( p_intf, "intf-change", VLC_VAR_BOOL );
573 /* Check if we already did this once. Opening the other nibs calls it too,
574 because VLCMain is the owner */
575 if( nib_main_loaded ) return;
577 [o_msgs_panel setExcludedFromWindowsMenu: YES];
578 [o_msgs_panel setDelegate: self];
580 p_playlist = pl_Get( p_intf );
584 var_AddCallback(p_playlist, "fullscreen", FullscreenChanged, self);
585 var_AddCallback( p_intf->p_libvlc, "intf-toggle-fscontrol", ShowController, self);
586 var_AddCallback( p_intf->p_libvlc, "intf-show", ShowController, self);
587 // var_AddCallback(p_playlist, "item-change", PLItemChanged, self);
588 var_AddCallback(p_playlist, "item-current", PLItemChanged, self);
589 var_AddCallback(p_playlist, "activity", PLItemChanged, self);
590 var_AddCallback(p_playlist, "leaf-to-parent", PlaylistUpdated, self);
591 var_AddCallback(p_playlist, "playlist-item-append", PlaylistUpdated, self);
592 var_AddCallback(p_playlist, "playlist-item-deleted", PlaylistUpdated, self);
593 var_AddCallback(p_playlist, "random", PlaybackModeUpdated, self);
594 var_AddCallback(p_playlist, "repeat", PlaybackModeUpdated, self);
595 var_AddCallback(p_playlist, "loop", PlaybackModeUpdated, self);
596 var_AddCallback(p_playlist, "volume", VolumeUpdated, self);
597 var_AddCallback(p_playlist, "mute", VolumeUpdated, self);
601 if ([NSApp currentSystemPresentationOptions] & NSApplicationPresentationFullScreen)
602 var_SetBool( p_playlist, "fullscreen", YES );
605 /* load our Core Dialogs nib */
606 nib_coredialogs_loaded = [NSBundle loadNibNamed:@"CoreDialogs" owner: NSApp];
608 /* subscribe to various interactive dialogues */
609 var_Create( p_intf, "dialog-error", VLC_VAR_ADDRESS );
610 var_AddCallback( p_intf, "dialog-error", DialogCallback, self );
611 var_Create( p_intf, "dialog-critical", VLC_VAR_ADDRESS );
612 var_AddCallback( p_intf, "dialog-critical", DialogCallback, self );
613 var_Create( p_intf, "dialog-login", VLC_VAR_ADDRESS );
614 var_AddCallback( p_intf, "dialog-login", DialogCallback, self );
615 var_Create( p_intf, "dialog-question", VLC_VAR_ADDRESS );
616 var_AddCallback( p_intf, "dialog-question", DialogCallback, self );
617 var_Create( p_intf, "dialog-progress-bar", VLC_VAR_ADDRESS );
618 var_AddCallback( p_intf, "dialog-progress-bar", DialogCallback, self );
619 dialog_Register( p_intf );
621 /* init Apple Remote support */
622 o_remote = [[AppleRemote alloc] init];
623 [o_remote setClickCountEnabledButtons: kRemoteButtonPlay];
624 [o_remote setDelegate: _o_sharedMainInstance];
626 [o_msgs_refresh_btn setImage: [NSImage imageNamed: NSImageNameRefreshTemplate]];
628 BOOL b_video_deco = var_InheritBool( VLCIntf, "video-deco" );
629 /* yeah, we are done */
630 b_nativeFullscreenMode = NO;
631 #ifdef MAC_OS_X_VERSION_10_7
632 if( OSX_LION && b_video_deco )
633 b_nativeFullscreenMode = var_InheritBool( p_intf, "macosx-nativefullscreenmode" );
636 /* recover stored audio device, if set
637 * in case it was unplugged in the meantime, auhal will fall back on the default */
638 int i_value = config_GetInt( p_intf, "macosx-audio-device" );
640 var_SetInteger( pl_Get( VLCIntf ), "audio-device", i_value );
642 if (config_GetInt( VLCIntf, "macosx-icon-change"))
644 /* After day 354 of the year, the usual VLC cone is replaced by another cone
645 * wearing a Father Xmas hat.
646 * Note: this icon doesn't represent an endorsement of The Coca-Cola Company.
648 NSCalendar *gregorian =
649 [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
650 NSUInteger dayOfYear = [gregorian ordinalityOfUnit:NSDayCalendarUnit inUnit:NSYearCalendarUnit forDate:[NSDate date]];
653 if (dayOfYear >= 354)
654 [[VLCApplication sharedApplication] setApplicationIconImage: [NSImage imageNamed:@"vlc-xmas"]];
659 nib_main_loaded = TRUE;
662 - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
664 if( !p_intf ) return;
666 [self updateCurrentlyUsedHotkeys];
668 /* init media key support */
669 b_mediaKeySupport = var_InheritBool( VLCIntf, "macosx-mediakeys" );
670 if( b_mediaKeySupport )
672 o_mediaKeyController = [[SPMediaKeyTap alloc] initWithDelegate:self];
673 [o_mediaKeyController startWatchingMediaKeys];
674 [[NSUserDefaults standardUserDefaults] registerDefaults:[NSDictionary dictionaryWithObjectsAndKeys:
675 [SPMediaKeyTap defaultMediaKeyUserBundleIdentifiers], kMediaKeyUsingBundleIdentifiersDefaultsKey,
678 [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(coreChangedMediaKeySupportSetting:) name: @"VLCMediaKeySupportSettingChanged" object: nil];
680 [self _removeOldPreferences];
682 /* Handle sleep notification */
683 [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(computerWillSleep:)
684 name:NSWorkspaceWillSleepNotification object:nil];
686 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(lookForCrashLog) withObject:nil waitUntilDone:NO];
688 /* we will need this, so let's load it here so the interface appears to be more responsive */
689 nib_open_loaded = [NSBundle loadNibNamed:@"Open" owner: NSApp];
691 /* update the main window */
692 [o_mainwindow updateWindow];
693 [o_mainwindow updateTimeSlider];
694 [o_mainwindow updateVolumeSlider];
699 if( !p_intf ) return;
702 [o_msgs_panel setTitle: _NS("Messages")];
703 [o_msgs_crashlog_btn setTitle: _NS("Open CrashLog...")];
704 [o_msgs_save_btn setTitle: _NS("Save this Log...")];
706 /* crash reporter panel */
707 [o_crashrep_send_btn setTitle: _NS("Send")];
708 [o_crashrep_dontSend_btn setTitle: _NS("Don't Send")];
709 [o_crashrep_title_txt setStringValue: _NS("VLC crashed previously")];
710 [o_crashrep_win setTitle: _NS("VLC crashed previously")];
711 [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, ...")];
712 [o_crashrep_includeEmail_ckb setTitle: _NS("I agree to be possibly contacted about this bugreport.")];
713 [o_crashrep_includeEmail_txt setStringValue: _NS("Only your default E-Mail address will be submitted, including no further information.")];
714 [o_crashrep_dontaskagain_ckb setTitle: _NS("Don't ask again")];
718 #pragma mark Termination
720 - (void)applicationWillTerminate:(NSNotification *)notification
722 /* don't allow a double termination call. If the user has
723 * already invoked the quit then simply return this time. */
724 static bool f_appExit = false;
728 isTerminating = f_appExit;
735 if (notification == nil)
736 [[NSNotificationCenter defaultCenter] postNotificationName: NSApplicationWillTerminateNotification object: nil];
738 playlist_t * p_playlist = pl_Get( p_intf );
739 int returnedValue = 0;
741 /* always exit fullscreen on quit, otherwise we get ugly artifacts on the next launch */
742 if (b_nativeFullscreenMode)
744 [o_mainwindow toggleFullScreen: self];
745 [NSApp setPresentationOptions:(NSApplicationPresentationDefault)];
748 /* Save some interface state in configuration, at module quit */
749 config_PutInt( p_intf, "random", var_GetBool( p_playlist, "random" ) );
750 config_PutInt( p_intf, "loop", var_GetBool( p_playlist, "loop" ) );
751 config_PutInt( p_intf, "repeat", var_GetBool( p_playlist, "repeat" ) );
753 msg_Dbg( p_intf, "Terminating" );
755 /* unsubscribe from the interactive dialogues */
756 dialog_Unregister( p_intf );
757 var_DelCallback( p_intf, "dialog-error", DialogCallback, self );
758 var_DelCallback( p_intf, "dialog-critical", DialogCallback, self );
759 var_DelCallback( p_intf, "dialog-login", DialogCallback, self );
760 var_DelCallback( p_intf, "dialog-question", DialogCallback, self );
761 var_DelCallback( p_intf, "dialog-progress-bar", DialogCallback, self );
762 //var_DelCallback(p_playlist, "item-change", PLItemChanged, self);
763 var_DelCallback(p_playlist, "item-current", PLItemChanged, self);
764 var_DelCallback(p_playlist, "activity", PLItemChanged, self);
765 var_DelCallback(p_playlist, "leaf-to-parent", PlaylistUpdated, self);
766 var_DelCallback(p_playlist, "playlist-item-append", PlaylistUpdated, self);
767 var_DelCallback(p_playlist, "playlist-item-deleted", PlaylistUpdated, self);
768 var_DelCallback(p_playlist, "random", PlaybackModeUpdated, self);
769 var_DelCallback(p_playlist, "repeat", PlaybackModeUpdated, self);
770 var_DelCallback(p_playlist, "loop", PlaybackModeUpdated, self);
771 var_DelCallback(p_playlist, "volume", VolumeUpdated, self);
772 var_DelCallback(p_playlist, "mute", VolumeUpdated, self);
773 var_DelCallback(p_playlist, "fullscreen", FullscreenChanged, self);
774 var_DelCallback(p_intf->p_libvlc, "intf-toggle-fscontrol", ShowController, self);
775 var_DelCallback(p_intf->p_libvlc, "intf-show", ShowController, self);
777 if( p_current_input )
779 var_DelCallback( p_current_input, "intf-event", InputEvent, [VLCMain sharedInstance] );
780 vlc_object_release( p_current_input );
781 p_current_input = NULL;
784 /* remove global observer watching for vout device changes correctly */
785 [[NSNotificationCenter defaultCenter] removeObserver: self];
787 /* release some other objects here, because it isn't sure whether dealloc
788 * will be called later on */
803 [crashLogURLConnection cancel];
804 [crashLogURLConnection release];
806 [o_embedded_list release];
807 [o_coredialogs release];
810 /* unsubscribe from libvlc's debug messages */
811 vlc_Unsubscribe( &p_intf->p_sys->sub );
813 [o_msg_arr removeAllObjects];
816 [o_usedHotkeys release];
817 o_usedHotkeys = NULL;
819 [o_msg_lock release];
821 /* write cached user defaults to disk */
822 [[NSUserDefaults standardUserDefaults] synchronize];
824 /* Make sure the Menu doesn't have any references to vlc objects anymore */
825 //FIXME: this should be moved to VLCMainMenu
826 [o_mainmenu releaseRepresentedObjects:[NSApp mainMenu]];
827 [o_mainmenu release];
829 libvlc_Quit( p_intf->p_libvlc );
831 [o_mainwindow release];
838 #pragma mark Sparkle delegate
839 /* received directly before the update gets installed, so let's shut down a bit */
840 - (void)updater:(SUUpdater *)updater willInstallUpdate:(SUAppcastItem *)update
842 [NSApp activateIgnoringOtherApps:YES];
843 [o_remote stopListening: self];
844 [[VLCCoreInteraction sharedInstance] stop];
848 #pragma mark Media Key support
850 -(void)mediaKeyTap:(SPMediaKeyTap*)keyTap receivedMediaKeyEvent:(NSEvent*)event
852 if( b_mediaKeySupport )
854 assert([event type] == NSSystemDefined && [event subtype] == SPSystemDefinedEventMediaKeys);
856 int keyCode = (([event data1] & 0xFFFF0000) >> 16);
857 int keyFlags = ([event data1] & 0x0000FFFF);
858 int keyState = (((keyFlags & 0xFF00) >> 8)) == 0xA;
859 int keyRepeat = (keyFlags & 0x1);
861 if( keyCode == NX_KEYTYPE_PLAY && keyState == 0 )
862 [[VLCCoreInteraction sharedInstance] play];
864 if( (keyCode == NX_KEYTYPE_FAST || keyCode == NX_KEYTYPE_NEXT) && !b_mediakeyJustJumped )
866 if( keyState == 0 && keyRepeat == 0 )
867 [[VLCCoreInteraction sharedInstance] next];
868 else if( keyRepeat == 1 )
870 [[VLCCoreInteraction sharedInstance] forwardShort];
871 b_mediakeyJustJumped = YES;
872 [self performSelector:@selector(resetMediaKeyJump)
878 if( (keyCode == NX_KEYTYPE_REWIND || keyCode == NX_KEYTYPE_PREVIOUS) && !b_mediakeyJustJumped )
880 if( keyState == 0 && keyRepeat == 0 )
881 [[VLCCoreInteraction sharedInstance] previous];
882 else if( keyRepeat == 1 )
884 [[VLCCoreInteraction sharedInstance] backwardShort];
885 b_mediakeyJustJumped = YES;
886 [self performSelector:@selector(resetMediaKeyJump)
895 #pragma mark Other notification
897 /* Listen to the remote in exclusive mode, only when VLC is the active
899 - (void)applicationDidBecomeActive:(NSNotification *)aNotification
901 if( !p_intf ) return;
902 if( var_InheritBool( p_intf, "macosx-appleremote" ) == YES )
903 [o_remote startListening: self];
905 - (void)applicationDidResignActive:(NSNotification *)aNotification
907 if( !p_intf ) return;
908 [o_remote stopListening: self];
911 /* Triggered when the computer goes to sleep */
912 - (void)computerWillSleep: (NSNotification *)notification
914 [[VLCCoreInteraction sharedInstance] pause];
918 #pragma mark File opening over dock icon
920 - (void)application:(NSApplication *)o_app openFiles:(NSArray *)o_names
922 BOOL b_autoplay = config_GetInt( VLCIntf, "macosx-autoplay" );
923 char *psz_uri = vlc_path2uri([[o_names objectAtIndex:0] UTF8String], "file" );
925 // try to add file as subtitle
926 if( [o_names count] == 1 && psz_uri )
928 input_thread_t * p_input = pl_CurrentInput( VLCIntf );
931 BOOL b_returned = NO;
932 b_returned = input_AddSubtitle( p_input, psz_uri, true );
933 vlc_object_release( p_input );
943 NSArray *o_sorted_names = [o_names sortedArrayUsingSelector: @selector(caseInsensitiveCompare:)];
944 NSMutableArray *o_result = [NSMutableArray arrayWithCapacity: [o_sorted_names count]];
945 for( int i = 0; i < [o_sorted_names count]; i++ )
947 psz_uri = vlc_path2uri([[o_sorted_names objectAtIndex: i] UTF8String], "file" );
951 NSDictionary *o_dic = [NSDictionary dictionaryWithObject:[NSString stringWithCString:psz_uri encoding:NSUTF8StringEncoding] forKey:@"ITEM_URL"];
953 [o_result addObject: o_dic];
957 [o_playlist appendArray: o_result atPos: -1 enqueue: NO];
959 [o_playlist appendArray: o_result atPos: -1 enqueue: YES];
964 /* When user click in the Dock icon our double click in the finder */
965 - (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)hasVisibleWindows
967 if(!hasVisibleWindows)
968 [o_mainwindow makeKeyAndOrderFront:self];
974 #pragma mark Apple Remote Control
976 /* Helper method for the remote control interface in order to trigger forward/backward and volume
977 increase/decrease as long as the user holds the left/right, plus/minus button */
978 - (void) executeHoldActionForRemoteButton: (NSNumber*) buttonIdentifierNumber
980 if(b_remote_button_hold)
982 switch([buttonIdentifierNumber intValue])
984 case kRemoteButtonRight_Hold:
985 [[VLCCoreInteraction sharedInstance] forward];
987 case kRemoteButtonLeft_Hold:
988 [[VLCCoreInteraction sharedInstance] backward];
990 case kRemoteButtonVolume_Plus_Hold:
992 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_VOL_UP );
994 case kRemoteButtonVolume_Minus_Hold:
996 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_VOL_DOWN );
999 if(b_remote_button_hold)
1002 [self performSelector:@selector(executeHoldActionForRemoteButton:)
1003 withObject:buttonIdentifierNumber
1009 /* Apple Remote callback */
1010 - (void) appleRemoteButton: (AppleRemoteEventIdentifier)buttonIdentifier
1011 pressedDown: (BOOL) pressedDown
1012 clickCount: (unsigned int) count
1014 switch( buttonIdentifier )
1016 case k2009RemoteButtonFullscreen:
1017 [[VLCCoreInteraction sharedInstance] toggleFullscreen];
1019 case k2009RemoteButtonPlay:
1020 [[VLCCoreInteraction sharedInstance] play];
1022 case kRemoteButtonPlay:
1024 [[VLCCoreInteraction sharedInstance] toggleFullscreen];
1026 [[VLCCoreInteraction sharedInstance] play];
1029 case kRemoteButtonVolume_Plus:
1030 if (config_GetInt( VLCIntf, "macosx-appleremote-sysvol"))
1031 [NSSound increaseSystemVolume];
1034 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_VOL_UP );
1036 case kRemoteButtonVolume_Minus:
1037 if (config_GetInt( VLCIntf, "macosx-appleremote-sysvol"))
1038 [NSSound decreaseSystemVolume];
1041 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_VOL_DOWN );
1043 case kRemoteButtonRight:
1044 if (config_GetInt( VLCIntf, "macosx-appleremote-prevnext"))
1045 [[VLCCoreInteraction sharedInstance] forward];
1047 [[VLCCoreInteraction sharedInstance] next];
1049 case kRemoteButtonLeft:
1050 if (config_GetInt( VLCIntf, "macosx-appleremote-prevnext"))
1051 [[VLCCoreInteraction sharedInstance] backward];
1053 [[VLCCoreInteraction sharedInstance] previous];
1055 case kRemoteButtonRight_Hold:
1056 case kRemoteButtonLeft_Hold:
1057 case kRemoteButtonVolume_Plus_Hold:
1058 case kRemoteButtonVolume_Minus_Hold:
1059 /* simulate an event as long as the user holds the button */
1060 b_remote_button_hold = pressedDown;
1063 NSNumber* buttonIdentifierNumber = [NSNumber numberWithInt: buttonIdentifier];
1064 [self performSelector:@selector(executeHoldActionForRemoteButton:)
1065 withObject:buttonIdentifierNumber];
1068 case kRemoteButtonMenu:
1069 [o_controls showPosition: self]; //FIXME
1071 case kRemoteButtonPlay_Sleep:
1073 NSAppleScript * script = [[NSAppleScript alloc] initWithSource:@"tell application \"System Events\" to sleep"];
1074 [script executeAndReturnError:nil];
1079 /* Add here whatever you want other buttons to do */
1085 #pragma mark String utility
1086 // FIXME: this has nothing to do here
1088 - (NSString *)localizedString:(const char *)psz
1090 NSString * o_str = nil;
1094 o_str = [NSString stringWithCString: _(psz) encoding:NSUTF8StringEncoding];
1098 msg_Err( VLCIntf, "could not translate: %s", psz );
1104 msg_Warn( VLCIntf, "can't translate empty strings" );
1113 - (char *)delocalizeString:(NSString *)id
1115 NSData * o_data = [id dataUsingEncoding: NSUTF8StringEncoding
1116 allowLossyConversion: NO];
1121 o_data = [id dataUsingEncoding: NSUTF8StringEncoding
1122 allowLossyConversion: YES];
1123 psz_string = malloc( [o_data length] + 1 );
1124 [o_data getBytes: psz_string];
1125 psz_string[ [o_data length] ] = '\0';
1126 msg_Err( VLCIntf, "cannot convert to the requested encoding: %s",
1131 psz_string = malloc( [o_data length] + 1 );
1132 [o_data getBytes: psz_string];
1133 psz_string[ [o_data length] ] = '\0';
1139 /* i_width is in pixels */
1140 - (NSString *)wrapString: (NSString *)o_in_string toWidth: (int) i_width
1142 NSMutableString *o_wrapped;
1143 NSString *o_out_string;
1144 NSRange glyphRange, effectiveRange, charRange;
1145 NSRect lineFragmentRect;
1146 unsigned glyphIndex, breaksInserted = 0;
1148 NSTextStorage *o_storage = [[NSTextStorage alloc] initWithString: o_in_string
1149 attributes: [NSDictionary dictionaryWithObjectsAndKeys:
1150 [NSFont labelFontOfSize: 0.0], NSFontAttributeName, nil]];
1151 NSLayoutManager *o_layout_manager = [[NSLayoutManager alloc] init];
1152 NSTextContainer *o_container = [[NSTextContainer alloc]
1153 initWithContainerSize: NSMakeSize(i_width, 2000)];
1155 [o_layout_manager addTextContainer: o_container];
1156 [o_container release];
1157 [o_storage addLayoutManager: o_layout_manager];
1158 [o_layout_manager release];
1160 o_wrapped = [o_in_string mutableCopy];
1161 glyphRange = [o_layout_manager glyphRangeForTextContainer: o_container];
1163 for( glyphIndex = glyphRange.location ; glyphIndex < NSMaxRange(glyphRange) ;
1164 glyphIndex += effectiveRange.length) {
1165 lineFragmentRect = [o_layout_manager lineFragmentRectForGlyphAtIndex: glyphIndex
1166 effectiveRange: &effectiveRange];
1167 charRange = [o_layout_manager characterRangeForGlyphRange: effectiveRange
1168 actualGlyphRange: &effectiveRange];
1169 if([o_wrapped lineRangeForRange:
1170 NSMakeRange(charRange.location + breaksInserted, charRange.length)].length > charRange.length) {
1171 [o_wrapped insertString: @"\n" atIndex: NSMaxRange(charRange) + breaksInserted];
1175 o_out_string = [NSString stringWithString: o_wrapped];
1176 [o_wrapped release];
1177 [o_storage release];
1179 return o_out_string;
1184 #pragma mark Key Shortcuts
1189 unsigned int i_vlckey;
1190 } nskeys_to_vlckeys[] =
1192 { NSUpArrowFunctionKey, KEY_UP },
1193 { NSDownArrowFunctionKey, KEY_DOWN },
1194 { NSLeftArrowFunctionKey, KEY_LEFT },
1195 { NSRightArrowFunctionKey, KEY_RIGHT },
1196 { NSF1FunctionKey, KEY_F1 },
1197 { NSF2FunctionKey, KEY_F2 },
1198 { NSF3FunctionKey, KEY_F3 },
1199 { NSF4FunctionKey, KEY_F4 },
1200 { NSF5FunctionKey, KEY_F5 },
1201 { NSF6FunctionKey, KEY_F6 },
1202 { NSF7FunctionKey, KEY_F7 },
1203 { NSF8FunctionKey, KEY_F8 },
1204 { NSF9FunctionKey, KEY_F9 },
1205 { NSF10FunctionKey, KEY_F10 },
1206 { NSF11FunctionKey, KEY_F11 },
1207 { NSF12FunctionKey, KEY_F12 },
1208 { NSInsertFunctionKey, KEY_INSERT },
1209 { NSHomeFunctionKey, KEY_HOME },
1210 { NSEndFunctionKey, KEY_END },
1211 { NSPageUpFunctionKey, KEY_PAGEUP },
1212 { NSPageDownFunctionKey, KEY_PAGEDOWN },
1213 { NSMenuFunctionKey, KEY_MENU },
1214 { NSTabCharacter, KEY_TAB },
1215 { NSCarriageReturnCharacter, KEY_ENTER },
1216 { NSEnterCharacter, KEY_ENTER },
1217 { NSBackspaceCharacter, KEY_BACKSPACE },
1218 { NSDeleteCharacter, KEY_DELETE },
1222 unsigned int CocoaKeyToVLC( unichar i_key )
1226 for( i = 0; nskeys_to_vlckeys[i].i_nskey != 0; i++ )
1228 if( nskeys_to_vlckeys[i].i_nskey == i_key )
1230 return nskeys_to_vlckeys[i].i_vlckey;
1233 return (unsigned int)i_key;
1236 - (unsigned int)VLCModifiersToCocoa:(NSString *)theString
1238 unsigned int new = 0;
1240 if([theString rangeOfString:@"Command"].location != NSNotFound)
1241 new |= NSCommandKeyMask;
1242 if([theString rangeOfString:@"Alt"].location != NSNotFound)
1243 new |= NSAlternateKeyMask;
1244 if([theString rangeOfString:@"Shift"].location != NSNotFound)
1245 new |= NSShiftKeyMask;
1246 if([theString rangeOfString:@"Ctrl"].location != NSNotFound)
1247 new |= NSControlKeyMask;
1251 - (NSString *)VLCKeyToString:(NSString *)theString
1253 if (![theString isEqualToString:@""]) {
1254 if ([theString characterAtIndex:([theString length] - 1)] != 0x2b)
1255 theString = [theString stringByReplacingOccurrencesOfString:@"+" withString:@""];
1258 theString = [theString stringByReplacingOccurrencesOfString:@"+" withString:@""];
1259 theString = [NSString stringWithFormat:@"%@+", theString];
1261 if ([theString characterAtIndex:([theString length] - 1)] != 0x2d)
1262 theString = [theString stringByReplacingOccurrencesOfString:@"-" withString:@""];
1265 theString = [theString stringByReplacingOccurrencesOfString:@"-" withString:@""];
1266 theString = [NSString stringWithFormat:@"%@-", theString];
1268 theString = [theString stringByReplacingOccurrencesOfString:@"Command" withString:@""];
1269 theString = [theString stringByReplacingOccurrencesOfString:@"Alt" withString:@""];
1270 theString = [theString stringByReplacingOccurrencesOfString:@"Shift" withString:@""];
1271 theString = [theString stringByReplacingOccurrencesOfString:@"Ctrl" withString:@""];
1273 if ([theString length] > 1)
1275 if([theString rangeOfString:@"Up"].location != NSNotFound)
1276 return [NSString stringWithFormat:@"%C", NSUpArrowFunctionKey];
1277 else if([theString rangeOfString:@"Down"].location != NSNotFound)
1278 return [NSString stringWithFormat:@"%C", NSDownArrowFunctionKey];
1279 else if([theString rangeOfString:@"Right"].location != NSNotFound)
1280 return [NSString stringWithFormat:@"%C", NSRightArrowFunctionKey];
1281 else if([theString rangeOfString:@"Left"].location != NSNotFound)
1282 return [NSString stringWithFormat:@"%C", NSLeftArrowFunctionKey];
1283 else if([theString rangeOfString:@"Enter"].location != NSNotFound)
1284 return [NSString stringWithFormat:@"%C", NSEnterCharacter]; // we treat NSCarriageReturnCharacter as aquivalent
1285 else if([theString rangeOfString:@"Insert"].location != NSNotFound)
1286 return [NSString stringWithFormat:@"%C", NSInsertFunctionKey];
1287 else if([theString rangeOfString:@"Home"].location != NSNotFound)
1288 return [NSString stringWithFormat:@"%C", NSHomeFunctionKey];
1289 else if([theString rangeOfString:@"End"].location != NSNotFound)
1290 return [NSString stringWithFormat:@"%C", NSEndFunctionKey];
1291 else if([theString rangeOfString:@"Pageup"].location != NSNotFound)
1292 return [NSString stringWithFormat:@"%C", NSPageUpFunctionKey];
1293 else if([theString rangeOfString:@"Pagedown"].location != NSNotFound)
1294 return [NSString stringWithFormat:@"%C", NSPageDownFunctionKey];
1295 else if([theString rangeOfString:@"Menu"].location != NSNotFound)
1296 return [NSString stringWithFormat:@"%C", NSMenuFunctionKey];
1297 else if([theString rangeOfString:@"Tab"].location != NSNotFound)
1298 return [NSString stringWithFormat:@"%C", NSTabCharacter];
1299 else if([theString rangeOfString:@"Backspace"].location != NSNotFound)
1300 return [NSString stringWithFormat:@"%C", NSBackspaceCharacter];
1301 else if([theString rangeOfString:@"Delete"].location != NSNotFound)
1302 return [NSString stringWithFormat:@"%C", NSDeleteCharacter];
1303 else if([theString rangeOfString:@"F12"].location != NSNotFound)
1304 return [NSString stringWithFormat:@"%C", NSF12FunctionKey];
1305 else if([theString rangeOfString:@"F11"].location != NSNotFound)
1306 return [NSString stringWithFormat:@"%C", NSF11FunctionKey];
1307 else if([theString rangeOfString:@"F10"].location != NSNotFound)
1308 return [NSString stringWithFormat:@"%C", NSF10FunctionKey];
1309 else if([theString rangeOfString:@"F9"].location != NSNotFound)
1310 return [NSString stringWithFormat:@"%C", NSF9FunctionKey];
1311 else if([theString rangeOfString:@"F8"].location != NSNotFound)
1312 return [NSString stringWithFormat:@"%C", NSF8FunctionKey];
1313 else if([theString rangeOfString:@"F7"].location != NSNotFound)
1314 return [NSString stringWithFormat:@"%C", NSF7FunctionKey];
1315 else if([theString rangeOfString:@"F6"].location != NSNotFound)
1316 return [NSString stringWithFormat:@"%C", NSF6FunctionKey];
1317 else if([theString rangeOfString:@"F5"].location != NSNotFound)
1318 return [NSString stringWithFormat:@"%C", NSF5FunctionKey];
1319 else if([theString rangeOfString:@"F4"].location != NSNotFound)
1320 return [NSString stringWithFormat:@"%C", NSF4FunctionKey];
1321 else if([theString rangeOfString:@"F3"].location != NSNotFound)
1322 return [NSString stringWithFormat:@"%C", NSF3FunctionKey];
1323 else if([theString rangeOfString:@"F2"].location != NSNotFound)
1324 return [NSString stringWithFormat:@"%C", NSF2FunctionKey];
1325 else if([theString rangeOfString:@"F1"].location != NSNotFound)
1326 return [NSString stringWithFormat:@"%C", NSF1FunctionKey];
1327 /* note that we don't support esc here, since it is reserved for leaving fullscreen */
1334 /*****************************************************************************
1335 * hasDefinedShortcutKey: Check to see if the key press is a defined VLC
1336 * shortcut key. If it is, pass it off to VLC for handling and return YES,
1337 * otherwise ignore it and return NO (where it will get handled by Cocoa).
1338 *****************************************************************************/
1339 - (BOOL)hasDefinedShortcutKey:(NSEvent *)o_event force:(BOOL)b_force
1343 unsigned int i_pressed_modifiers = 0;
1346 i_pressed_modifiers = [o_event modifierFlags];
1348 if( i_pressed_modifiers & NSControlKeyMask ) {
1349 val.i_int |= KEY_MODIFIER_CTRL;
1351 if( i_pressed_modifiers & NSAlternateKeyMask ) {
1352 val.i_int |= KEY_MODIFIER_ALT;
1354 if( i_pressed_modifiers & NSShiftKeyMask ) {
1355 val.i_int |= KEY_MODIFIER_SHIFT;
1357 if( i_pressed_modifiers & NSCommandKeyMask ) {
1358 val.i_int |= KEY_MODIFIER_COMMAND;
1361 NSString * characters = [o_event charactersIgnoringModifiers];
1362 if ([characters length] > 0)
1364 key = [[characters lowercaseString] characterAtIndex: 0];
1366 /* handle Lion's default key combo for fullscreen-toggle in addition to our own hotkeys */
1367 if( key == 'f' && i_pressed_modifiers & NSControlKeyMask && i_pressed_modifiers & NSCommandKeyMask )
1369 [[VLCCoreInteraction sharedInstance] toggleFullscreen];
1377 case NSDeleteCharacter:
1378 case NSDeleteFunctionKey:
1379 case NSDeleteCharFunctionKey:
1380 case NSBackspaceCharacter:
1381 case NSUpArrowFunctionKey:
1382 case NSDownArrowFunctionKey:
1383 case NSRightArrowFunctionKey:
1384 case NSLeftArrowFunctionKey:
1385 case NSEnterCharacter:
1386 case NSCarriageReturnCharacter:
1391 if( key == 0x0020 ) // space key
1393 [[VLCCoreInteraction sharedInstance] play];
1397 val.i_int |= CocoaKeyToVLC( key );
1399 BOOL b_found_key = NO;
1400 for( int i = 0; i < [o_usedHotkeys count]; i++ )
1402 NSString *str = [o_usedHotkeys objectAtIndex: i];
1403 unsigned int i_keyModifiers = [self VLCModifiersToCocoa: str];
1405 if( [[characters lowercaseString] isEqualToString: [self VLCKeyToString: str]] &&
1406 (i_keyModifiers & NSShiftKeyMask) == (i_pressed_modifiers & NSShiftKeyMask) &&
1407 (i_keyModifiers & NSControlKeyMask) == (i_pressed_modifiers & NSControlKeyMask) &&
1408 (i_keyModifiers & NSAlternateKeyMask) == (i_pressed_modifiers & NSAlternateKeyMask) &&
1409 (i_keyModifiers & NSCommandKeyMask) == (i_pressed_modifiers & NSCommandKeyMask) )
1418 var_SetInteger( p_intf->p_libvlc, "key-pressed", val.i_int );
1426 - (void)updateCurrentlyUsedHotkeys
1428 NSMutableArray *o_tempArray = [[NSMutableArray alloc] init];
1429 /* Get the main Module */
1430 module_t *p_main = module_get_main();
1433 module_config_t *p_config;
1435 p_config = module_config_get (p_main, &confsize);
1437 for (size_t i = 0; i < confsize; i++)
1439 module_config_t *p_item = p_config + i;
1441 if( CONFIG_ITEM(p_item->i_type) && p_item->psz_name != NULL
1442 && !strncmp( p_item->psz_name , "key-", 4 )
1443 && !EMPTY_STR( p_item->psz_text ) )
1445 if (p_item->value.psz)
1447 [o_tempArray addObject: [NSString stringWithUTF8String:p_item->value.psz]];
1451 module_config_free (p_config);
1454 [o_usedHotkeys release];
1455 o_usedHotkeys = [[NSArray alloc] initWithArray: o_tempArray copyItems: YES];
1456 [o_tempArray release];
1460 #pragma mark Interface updaters
1461 - (void)fullscreenChanged
1463 playlist_t * p_playlist = pl_Get( VLCIntf );
1464 BOOL b_fullscreen = var_GetBool( p_playlist, "fullscreen" );
1466 if (b_nativeFullscreenMode)
1468 // this is called twice in certain situations, so only toogle if we really need to
1469 if( ( b_fullscreen && !([NSApp currentSystemPresentationOptions] & NSApplicationPresentationFullScreen) ) ||
1470 ( !b_fullscreen && ([NSApp currentSystemPresentationOptions] & NSApplicationPresentationFullScreen) ) )
1471 [o_mainwindow toggleFullScreen: self];
1474 [NSApp setPresentationOptions:(NSApplicationPresentationFullScreen | NSApplicationPresentationAutoHideDock | NSApplicationPresentationAutoHideMenuBar)];
1476 [NSApp setPresentationOptions:(NSApplicationPresentationDefault)];
1482 input_thread_t * p_input = pl_CurrentInput( VLCIntf );
1483 if( p_input != NULL && [self activeVideoPlayback] )
1485 // activate app, as method can also be triggered from outside the app (prevents nasty window layout)
1486 [NSApp activateIgnoringOtherApps:YES];
1487 [o_mainwindow performSelectorOnMainThread:@selector(enterFullscreen) withObject:nil waitUntilDone:NO];
1490 vlc_object_release( p_input );
1494 // leaving fullscreen is always allowed
1495 [o_mainwindow performSelectorOnMainThread:@selector(leaveFullscreen) withObject:nil waitUntilDone:NO];
1500 - (void)checkFullscreenChange:(NSNumber *)o_full
1502 BOOL b_full = [o_full boolValue];
1503 if( p_intf && !var_GetBool( pl_Get( p_intf ), "fullscreen" ) != !b_full )
1505 var_SetBool( pl_Get(p_intf), "fullscreen", b_full );
1509 - (void)PlaylistItemChanged
1511 if( p_current_input && ( p_current_input->b_dead || !vlc_object_alive( p_current_input ) ))
1513 var_DelCallback( p_current_input, "intf-event", InputEvent, [VLCMain sharedInstance] );
1514 vlc_object_release( p_current_input );
1515 p_current_input = NULL;
1517 [o_mainmenu setRateControlsEnabled: NO];
1519 else if( !p_current_input )
1521 // object is hold here and released then it is dead
1522 p_current_input = playlist_CurrentInput( pl_Get( VLCIntf ));
1523 if( p_current_input )
1525 var_AddCallback( p_current_input, "intf-event", InputEvent, [VLCMain sharedInstance] );
1526 [self playbackStatusUpdated];
1527 [o_mainmenu setRateControlsEnabled: YES];
1528 if ( [self activeVideoPlayback] && [[o_mainwindow videoView] isHidden] )
1529 [o_mainwindow performSelectorOnMainThread:@selector(togglePlaylist:) withObject: nil waitUntilDone:NO];
1533 [o_playlist updateRowSelection];
1534 [o_mainwindow updateWindow];
1535 [self updateDelays];
1536 [self updateMainMenu];
1539 - (void)updateMainMenu
1541 [o_mainmenu setupMenus];
1542 [o_mainmenu updatePlaybackRate];
1545 - (void)updateMainWindow
1547 [o_mainwindow updateWindow];
1550 - (void)showMainWindow
1552 [o_mainwindow performSelectorOnMainThread:@selector(makeKeyAndOrderFront:) withObject:nil waitUntilDone:NO];
1555 - (void)showFullscreenController
1557 [o_mainwindow performSelectorOnMainThread:@selector(showFullscreenController) withObject:nil waitUntilDone:NO];
1560 - (void)updateDelays
1562 [[VLCTrackSynchronization sharedInstance] performSelectorOnMainThread: @selector(updateValues) withObject: nil waitUntilDone:NO];
1567 [o_mainwindow updateName];
1570 - (void)updatePlaybackPosition
1572 [o_mainwindow updateTimeSlider];
1574 input_thread_t * p_input;
1575 p_input = pl_CurrentInput( p_intf );
1578 if( var_GetInteger( p_input, "state" ) == PLAYING_S && [self activeVideoPlayback] )
1579 UpdateSystemActivity( UsrActivity );
1580 vlc_object_release( p_input );
1584 - (void)updateVolume
1586 [o_mainwindow updateVolumeSlider];
1589 - (void)playlistUpdated
1591 [self playbackStatusUpdated];
1592 [o_playlist playlistUpdated];
1593 [o_mainwindow updateWindow];
1594 [o_mainwindow updateName];
1597 - (void)updateRecordState: (BOOL)b_value
1599 [o_mainmenu updateRecordState:b_value];
1602 - (void)updateInfoandMetaPanel
1604 [o_playlist outlineViewSelectionDidChange:nil];
1607 - (void)playbackStatusUpdated
1609 input_thread_t * p_input;
1611 p_input = pl_CurrentInput( p_intf );
1614 int state = var_GetInteger( p_input, "state" );
1615 if( state == PLAYING_S )
1617 [[self mainMenu] setPause];
1618 [o_mainwindow setPause];
1623 [o_mainmenu setSubmenusEnabled: FALSE];
1624 [[self mainMenu] setPlay];
1625 [o_mainwindow setPlay];
1627 vlc_object_release( p_input );
1630 [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(updateMainWindow) withObject: nil waitUntilDone: NO];
1631 [self performSelectorOnMainThread:@selector(sendDistributedNotificationWithUpdatedPlaybackStatus) withObject: nil waitUntilDone: NO];
1634 - (void)sendDistributedNotificationWithUpdatedPlaybackStatus
1636 [[NSDistributedNotificationCenter defaultCenter] postNotificationName:@"VLCPlayerStateDidChange"
1639 deliverImmediately:YES];
1642 - (void)playbackModeUpdated
1644 vlc_value_t looping,repeating;
1645 playlist_t * p_playlist = pl_Get( VLCIntf );
1647 bool loop = var_GetBool( p_playlist, "loop" );
1648 bool repeat = var_GetBool( p_playlist, "repeat" );
1650 [o_mainwindow setRepeatOne];
1651 [o_mainmenu setRepeatOne];
1653 [o_mainwindow setRepeatAll];
1654 [o_mainmenu setRepeatAll];
1656 [o_mainwindow setRepeatOff];
1657 [o_mainmenu setRepeatOff];
1660 [o_mainwindow setShuffle];
1661 [o_mainmenu setShuffle];
1666 #pragma mark Window updater
1668 - (void)setWindowLevel:(NSNumber*)state
1670 if( var_InheritBool( p_intf, "macosx-background" ) )
1673 if ([state unsignedIntValue] & VOUT_WINDOW_STATE_ABOVE)
1674 [[[[VLCMainWindow sharedInstance] videoView] window] setLevel: NSStatusWindowLevel];
1676 [[[[VLCMainWindow sharedInstance] videoView] window] setLevel: NSNormalWindowLevel];
1679 - (void)setActiveVideoPlayback:(BOOL)b_value
1681 b_active_videoplayback = b_value;
1684 [o_mainwindow performSelectorOnMainThread:@selector(setVideoplayEnabled) withObject:nil waitUntilDone:YES];
1685 [o_mainwindow performSelectorOnMainThread:@selector(togglePlaylist:) withObject:nil waitUntilDone:NO];
1689 - (void)setNativeVideoSize:(NSSize)size
1691 [o_mainwindow setNativeVideoSize:size];
1695 #pragma mark Other objects getters
1704 return o_mainwindow;
1718 o_bookmarks = [[VLCBookmarks alloc] init];
1720 if( !nib_bookmarks_loaded )
1721 nib_bookmarks_loaded = [NSBundle loadNibNamed:@"Bookmarks" owner: NSApp];
1731 if (!nib_open_loaded)
1732 nib_open_loaded = [NSBundle loadNibNamed:@"Open" owner: NSApp];
1737 - (id)simplePreferences
1740 o_sprefs = [[VLCSimplePrefs alloc] init];
1742 if (!nib_prefs_loaded)
1743 nib_prefs_loaded = [NSBundle loadNibNamed:@"Preferences" owner: NSApp];
1751 o_prefs = [[VLCPrefs alloc] init];
1753 if( !nib_prefs_loaded )
1754 nib_prefs_loaded = [NSBundle loadNibNamed:@"Preferences" owner: NSApp];
1769 if(! nib_info_loaded )
1770 nib_info_loaded = [NSBundle loadNibNamed:@"MediaInfo" owner: NSApp];
1781 o_wizard = [[VLCWizard alloc] init];
1783 if( !nib_wizard_loaded )
1785 nib_wizard_loaded = [NSBundle loadNibNamed:@"Wizard" owner: NSApp];
1786 [o_wizard initStrings];
1791 - (id)getVideoViewAtPositionX: (int *)pi_x Y: (int *)pi_y withWidth: (unsigned int*)pi_width andHeight: (unsigned int*)pi_height
1793 [o_mainwindow performSelectorOnMainThread:@selector(setupVideoView) withObject:nil waitUntilDone:YES];
1794 id videoView = [o_mainwindow videoView];
1795 NSRect videoRect = [videoView frame];
1796 int i_x = (int)videoRect.origin.x;
1797 int i_y = (int)videoRect.origin.y;
1798 unsigned int i_width = (int)videoRect.size.width;
1799 unsigned int i_height = (int)videoRect.size.height;
1802 pi_width = &i_width;
1803 pi_height = &i_height;
1804 msg_Dbg( VLCIntf, "returning videoview with x=%i, y=%i, width=%i, height=%i", i_x, i_y, i_width, i_height );
1810 if( o_embedded_list )
1811 return o_embedded_list;
1816 - (id)coreDialogProvider
1819 return o_coredialogs;
1824 - (id)eyeTVController
1832 - (id)appleRemoteController
1837 - (BOOL)activeVideoPlayback
1839 return b_active_videoplayback;
1843 #pragma mark Crash Log
1844 - (void)sendCrashLog:(NSString *)crashLog withUserComment:(NSString *)userComment
1846 NSString *urlStr = @"http://crash.videolan.org/crashlog/sendcrashreport.php";
1847 NSURL *url = [NSURL URLWithString:urlStr];
1849 NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
1850 [req setHTTPMethod:@"POST"];
1853 if( [o_crashrep_includeEmail_ckb state] == NSOnState )
1855 ABPerson * contact = [[ABAddressBook sharedAddressBook] me];
1856 ABMultiValue *emails = [contact valueForProperty:kABEmailProperty];
1857 email = [emails valueAtIndex:[emails indexForIdentifier:
1858 [emails primaryIdentifier]]];
1861 email = [NSString string];
1864 postBody = [NSString stringWithFormat:@"CrashLog=%@&Comment=%@&Email=%@\r\n",
1865 [crashLog stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
1866 [userComment stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
1867 [email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
1869 [req setHTTPBody:[postBody dataUsingEncoding:NSUTF8StringEncoding]];
1871 /* Released from delegate */
1872 crashLogURLConnection = [[NSURLConnection alloc] initWithRequest:req delegate:self];
1875 - (void)connectionDidFinishLoading:(NSURLConnection *)connection
1877 msg_Dbg( p_intf, "crash report successfully sent" );
1878 [crashLogURLConnection release];
1879 crashLogURLConnection = nil;
1882 - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
1884 msg_Warn (p_intf, "Error when sending the crash report: %s (%li)", [[error localizedDescription] UTF8String], [error code]);
1885 [crashLogURLConnection release];
1886 crashLogURLConnection = nil;
1889 - (NSString *)latestCrashLogPathPreviouslySeen:(BOOL)previouslySeen
1891 NSString * crashReporter;
1892 if( OSX_MOUNTAIN_LION )
1893 crashReporter = [@"~/Library/Logs/DiagnosticReports" stringByExpandingTildeInPath];
1895 crashReporter = [@"~/Library/Logs/CrashReporter" stringByExpandingTildeInPath];
1896 NSDirectoryEnumerator *direnum = [[NSFileManager defaultManager] enumeratorAtPath:crashReporter];
1898 NSString * latestLog = nil;
1899 int year = !previouslySeen ? [[NSUserDefaults standardUserDefaults] integerForKey:@"LatestCrashReportYear"] : 0;
1900 int month = !previouslySeen ? [[NSUserDefaults standardUserDefaults] integerForKey:@"LatestCrashReportMonth"]: 0;
1901 int day = !previouslySeen ? [[NSUserDefaults standardUserDefaults] integerForKey:@"LatestCrashReportDay"] : 0;
1902 int hours = !previouslySeen ? [[NSUserDefaults standardUserDefaults] integerForKey:@"LatestCrashReportHours"]: 0;
1904 while (fname = [direnum nextObject])
1906 [direnum skipDescendents];
1907 if([fname hasPrefix:@"VLC"] && [fname hasSuffix:@"crash"])
1909 NSArray * compo = [fname componentsSeparatedByString:@"_"];
1910 if( [compo count] < 3 ) continue;
1911 compo = [[compo objectAtIndex:1] componentsSeparatedByString:@"-"];
1912 if( [compo count] < 4 ) continue;
1915 if( year < [[compo objectAtIndex:0] intValue] ||
1916 (year ==[[compo objectAtIndex:0] intValue] &&
1917 (month < [[compo objectAtIndex:1] intValue] ||
1918 (month ==[[compo objectAtIndex:1] intValue] &&
1919 (day < [[compo objectAtIndex:2] intValue] ||
1920 (day ==[[compo objectAtIndex:2] intValue] &&
1921 hours < [[compo objectAtIndex:3] intValue] ))))))
1923 year = [[compo objectAtIndex:0] intValue];
1924 month = [[compo objectAtIndex:1] intValue];
1925 day = [[compo objectAtIndex:2] intValue];
1926 hours = [[compo objectAtIndex:3] intValue];
1927 latestLog = [crashReporter stringByAppendingPathComponent:fname];
1932 if(!(latestLog && [[NSFileManager defaultManager] fileExistsAtPath:latestLog]))
1935 if( !previouslySeen )
1937 [[NSUserDefaults standardUserDefaults] setInteger:year forKey:@"LatestCrashReportYear"];
1938 [[NSUserDefaults standardUserDefaults] setInteger:month forKey:@"LatestCrashReportMonth"];
1939 [[NSUserDefaults standardUserDefaults] setInteger:day forKey:@"LatestCrashReportDay"];
1940 [[NSUserDefaults standardUserDefaults] setInteger:hours forKey:@"LatestCrashReportHours"];
1945 - (NSString *)latestCrashLogPath
1947 return [self latestCrashLogPathPreviouslySeen:YES];
1950 - (void)lookForCrashLog
1952 NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
1953 // This pref key doesn't exists? this VLC is an upgrade, and this crash log come from previous version
1954 BOOL areCrashLogsTooOld = ![[NSUserDefaults standardUserDefaults] integerForKey:@"LatestCrashReportYear"];
1955 NSString * latestLog = [self latestCrashLogPathPreviouslySeen:NO];
1956 if( latestLog && !areCrashLogsTooOld )
1958 if ([[NSUserDefaults standardUserDefaults] integerForKey:@"AlwaysSendCrashReports"] > 0)
1959 [self sendCrashLog:[NSString stringWithContentsOfFile: [self latestCrashLogPath] encoding: NSUTF8StringEncoding error: NULL] withUserComment: [o_crashrep_fld string]];
1960 else if ([[NSUserDefaults standardUserDefaults] integerForKey:@"AlwaysSendCrashReports"] == 0)
1961 [NSApp runModalForWindow: o_crashrep_win];
1962 // bail out, the user doesn't want us to send reports
1968 - (IBAction)crashReporterAction:(id)sender
1970 if( sender == o_crashrep_send_btn ) {
1971 [self sendCrashLog:[NSString stringWithContentsOfFile: [self latestCrashLogPath] encoding: NSUTF8StringEncoding error: NULL] withUserComment: [o_crashrep_fld string]];
1972 if ([o_crashrep_dontaskagain_ckb state])
1973 [[NSUserDefaults standardUserDefaults] setInteger:1 forKey:@"AlwaysSendCrashReports"];
1975 if ([o_crashrep_dontaskagain_ckb state])
1976 [[NSUserDefaults standardUserDefaults] setInteger:-1 forKey:@"AlwaysSendCrashReports"];
1980 [o_crashrep_win orderOut: sender];
1983 - (IBAction)openCrashLog:(id)sender
1985 NSString * latestLog = [self latestCrashLogPath];
1988 [[NSWorkspace sharedWorkspace] openFile: latestLog withApplication: @"Console"];
1992 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.") );
1997 #pragma mark Remove old prefs
1999 - (void)_removeOldPreferences
2001 static NSString * kVLCPreferencesVersion = @"VLCPreferencesVersion";
2002 static const int kCurrentPreferencesVersion = 2;
2003 int version = [[NSUserDefaults standardUserDefaults] integerForKey:kVLCPreferencesVersion];
2004 if( version >= kCurrentPreferencesVersion ) return;
2008 [[NSUserDefaults standardUserDefaults] setInteger:kCurrentPreferencesVersion forKey:kVLCPreferencesVersion];
2009 [[NSUserDefaults standardUserDefaults] synchronize];
2011 if (![[VLCCoreInteraction sharedInstance] fixPreferences])
2014 config_SaveConfigFile( VLCIntf ); // we need to do manually, since we won't quit libvlc cleanly
2018 NSArray *libraries = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,
2019 NSUserDomainMask, YES);
2020 if( !libraries || [libraries count] == 0) return;
2021 NSString * preferences = [[libraries objectAtIndex:0] stringByAppendingPathComponent:@"Preferences"];
2023 /* File not found, don't attempt anything */
2024 if(![[NSFileManager defaultManager] fileExistsAtPath:[preferences stringByAppendingPathComponent:@"org.videolan.vlc"]] &&
2025 ![[NSFileManager defaultManager] fileExistsAtPath:[preferences stringByAppendingPathComponent:@"org.videolan.vlc.plist"]] )
2027 [[NSUserDefaults standardUserDefaults] setInteger:kCurrentPreferencesVersion forKey:kVLCPreferencesVersion];
2031 int res = NSRunInformationalAlertPanel(_NS("Remove old preferences?"),
2032 _NS("We just found an older version of VLC's preferences files."),
2033 _NS("Move To Trash and Relaunch VLC"), _NS("Ignore"), nil, nil);
2034 if( res != NSOKButton )
2036 [[NSUserDefaults standardUserDefaults] setInteger:kCurrentPreferencesVersion forKey:kVLCPreferencesVersion];
2040 NSArray * ourPreferences = [NSArray arrayWithObjects:@"org.videolan.vlc.plist", @"VLC", @"org.videolan.vlc", nil];
2042 /* Move the file to trash so that user can find them later */
2043 [[NSWorkspace sharedWorkspace] performFileOperation:NSWorkspaceRecycleOperation source:preferences destination:nil files:ourPreferences tag:0];
2045 /* really reset the defaults from now on */
2046 [NSUserDefaults resetStandardUserDefaults];
2048 [[NSUserDefaults standardUserDefaults] setInteger:kCurrentPreferencesVersion forKey:kVLCPreferencesVersion];
2049 [[NSUserDefaults standardUserDefaults] synchronize];
2053 const char * path = [[[NSBundle mainBundle] executablePath] UTF8String];
2055 /* For some reason we need to fork(), not just execl(), which reports a ENOTSUP then. */
2061 execl(path, path, NULL);
2065 #pragma mark Errors, warnings and messages
2066 - (IBAction)updateMessagesPanel:(id)sender
2068 [self windowDidBecomeKey:nil];
2071 - (IBAction)showMessagesPanel:(id)sender
2073 [o_msgs_panel makeKeyAndOrderFront: sender];
2076 - (void)windowDidBecomeKey:(NSNotification *)o_notification
2078 [o_msgs_table reloadData];
2079 [o_msgs_table scrollRowToVisible: [o_msg_arr count] - 1];
2082 - (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView
2084 if (aTableView == o_msgs_table)
2085 return [o_msg_arr count];
2089 - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
2091 NSMutableAttributedString *result = NULL;
2094 if( rowIndex < [o_msg_arr count] )
2095 result = [o_msg_arr objectAtIndex: rowIndex];
2096 [o_msg_lock unlock];
2098 if( result != NULL )
2104 - (void)processReceivedlibvlcMessage:(const msg_item_t *) item ofType: (int)i_type withStr: (char *)str
2108 NSColor *o_white = [NSColor whiteColor];
2109 NSColor *o_red = [NSColor redColor];
2110 NSColor *o_yellow = [NSColor yellowColor];
2111 NSColor *o_gray = [NSColor grayColor];
2112 NSString * firstString, * secondString;
2114 NSColor * pp_color[4] = { o_white, o_red, o_yellow, o_gray };
2115 static const char * ppsz_type[4] = { ": ", " error: ", " warning: ", " debug: " };
2117 NSDictionary *o_attr;
2118 NSMutableAttributedString *o_msg_color;
2122 if( [o_msg_arr count] > 600 )
2124 [o_msg_arr removeObjectAtIndex: 0];
2125 [o_msg_arr removeObjectAtIndex: 1];
2127 firstString = [NSString stringWithFormat:@"%s%s", item->psz_module, ppsz_type[i_type]];
2128 secondString = [NSString stringWithFormat:@"%@%s\n", firstString, str];
2130 o_attr = [NSDictionary dictionaryWithObject: pp_color[i_type] forKey: NSForegroundColorAttributeName];
2131 o_msg_color = [[NSMutableAttributedString alloc] initWithString: secondString attributes: o_attr];
2132 o_attr = [NSDictionary dictionaryWithObject: pp_color[3] forKey: NSForegroundColorAttributeName];
2133 [o_msg_color setAttributes: o_attr range: NSMakeRange( 0, [firstString length] )];
2134 [o_msg_arr addObject: [o_msg_color autorelease]];
2136 b_msg_arr_changed = YES;
2137 [o_msg_lock unlock];
2141 - (IBAction)saveDebugLog:(id)sender
2143 NSSavePanel * saveFolderPanel = [[NSSavePanel alloc] init];
2145 [saveFolderPanel setCanSelectHiddenExtension: NO];
2146 [saveFolderPanel setCanCreateDirectories: YES];
2147 [saveFolderPanel setAllowedFileTypes: [NSArray arrayWithObject:@"rtf"]];
2148 [saveFolderPanel setNameFieldStringValue:[NSString stringWithFormat: _NS("VLC Debug Log (%s).rtf"), VERSION_MESSAGE]];
2149 [saveFolderPanel beginSheetModalForWindow: o_msgs_panel completionHandler:^(NSInteger returnCode) {
2150 if( returnCode == NSOKButton )
2152 NSUInteger count = [o_msg_arr count];
2153 NSMutableAttributedString * string = [[NSMutableAttributedString alloc] init];
2154 for (NSUInteger i = 0; i < count; i++)
2155 [string appendAttributedString: [o_msg_arr objectAtIndex: i]];
2157 NSData *data = [string RTFFromRange:NSMakeRange( 0, [string length] )
2158 documentAttributes:[NSDictionary dictionaryWithObject: NSRTFTextDocumentType forKey: NSDocumentTypeDocumentAttribute]];
2160 if( [data writeToFile: [[saveFolderPanel URL] path] atomically: YES] == NO )
2161 msg_Warn( p_intf, "Error while saving the debug log" );
2166 [saveFolderPanel release];
2170 #pragma mark Playlist toggling
2172 - (void)updateTogglePlaylistState
2174 [[self playlist] outlineViewSelectionDidChange: NULL];
2181 @implementation VLCMain (Internal)
2183 - (void)handlePortMessage:(NSPortMessage *)o_msg
2188 NSInvocation * o_inv;
2189 NSConditionLock * o_lock;
2191 o_data = [[o_msg components] lastObject];
2192 o_inv = *((NSInvocation **)[o_data bytes]);
2193 [o_inv getArgument: &o_value atIndex: 2];
2194 val = (id **)[o_value pointerValue];
2195 [o_inv setArgument: val[1] atIndex: 2];
2200 [o_lock unlockWithCondition: 1];
2202 - (void)resetMediaKeyJump
2204 b_mediakeyJustJumped = NO;
2206 - (void)coreChangedMediaKeySupportSetting: (NSNotification *)o_notification
2208 b_mediaKeySupport = var_InheritBool( VLCIntf, "macosx-mediakeys" );
2209 if (b_mediaKeySupport)
2211 if (!o_mediaKeyController)
2212 o_mediaKeyController = [[SPMediaKeyTap alloc] initWithDelegate:self];
2213 [o_mediaKeyController startWatchingMediaKeys];
2215 else if (!b_mediaKeySupport && o_mediaKeyController)
2216 [o_mediaKeyController stopWatchingMediaKeys];
2221 /*****************************************************************************
2222 * VLCApplication interface
2223 *****************************************************************************/
2225 @implementation VLCApplication
2226 // when user selects the quit menu from dock it sends a terminate:
2227 // but we need to send a stop: to properly exits libvlc.
2228 // However, we are not able to change the action-method sent by this standard menu item.
2229 // thus we override terminate: to send a stop:
2230 // see [af97f24d528acab89969d6541d83f17ce1ecd580] that introduced the removal of setjmp() and longjmp()
2231 - (void)terminate:(id)sender
2233 [self activateIgnoringOtherApps:YES];