1 /*****************************************************************************
2 * intf.m: MacOS X interface module
3 *****************************************************************************
4 * Copyright (C) 2002-2009 the VideoLAN team
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 *****************************************************************************/
30 #include <stdlib.h> /* malloc(), free() */
31 #include <sys/param.h> /* for MAXPATHLEN */
33 #include <vlc_common.h>
35 #include <vlc_dialog.h>
36 #include <unistd.h> /* execl() */
37 #import <vlc_dialog.h>
44 #import "playlistinfo.h"
51 #import "coredialogs.h"
52 #import "embeddedwindow.h"
54 #import "AppleRemote.h"
56 #import "simple_prefs.h"
59 #import <AddressBook/AddressBook.h> /* for crashlog send mechanism */
60 #import <IOKit/hidsystem/ev_keymap.h> /* for the media key support */
62 /*****************************************************************************
64 *****************************************************************************/
65 static void Run ( intf_thread_t *p_intf );
67 static void * ManageThread( void *user_data );
69 static unichar VLCKeyToCocoa( unsigned int i_key );
70 static unsigned int VLCModifiersToCocoa( unsigned int i_key );
72 static void updateProgressPanel (void *, const char *, float);
73 static bool checkProgressPanel (void *);
74 static void destroyProgressPanel (void *);
76 static void MsgCallback( msg_cb_data_t *, msg_item_t *, unsigned );
79 #pragma mark VLC Interface Object Callbacks
81 /*****************************************************************************
82 * OpenIntf: initialize interface
83 *****************************************************************************/
84 int OpenIntf ( vlc_object_t *p_this )
86 intf_thread_t *p_intf = (intf_thread_t*) p_this;
88 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
89 if( p_intf->p_sys == NULL )
92 memset( p_intf->p_sys, 0, sizeof( *p_intf->p_sys ) );
94 p_intf->p_sys->o_pool = [[NSAutoreleasePool alloc] init];
96 /* subscribe to LibVLCCore's messages */
97 p_intf->p_sys->p_sub = msg_Subscribe( p_intf->p_libvlc, MsgCallback, NULL );
99 p_intf->b_should_run_on_first_thread = true;
104 /*****************************************************************************
105 * CloseIntf: destroy interface
106 *****************************************************************************/
107 void CloseIntf ( vlc_object_t *p_this )
109 intf_thread_t *p_intf = (intf_thread_t*) p_this;
111 [p_intf->p_sys->o_pool release];
113 free( p_intf->p_sys );
116 /*****************************************************************************
118 *****************************************************************************/
121 static void Run( intf_thread_t *p_intf )
125 /* Do it again - for some unknown reason, vlc_thread_create() often
126 * fails to go to real-time priority with the first launched thread
128 vlc_thread_set_priority( p_intf, VLC_THREAD_PRIORITY_LOW );
130 /* Make sure the "force quit" menu item does quit instantly.
131 * VLC overrides SIGTERM which is sent by the "force quit"
132 * menu item to make sure deamon mode quits gracefully, so
133 * we un-override SIGTERM here. */
135 sigaddset( &set, SIGTERM );
136 pthread_sigmask( SIG_UNBLOCK, &set, NULL );
138 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
140 /* Install a jmpbuffer to where we can go back before the NSApp exit
141 * see applicationWillTerminate: */
142 [VLCApplication sharedApplication];
144 [[VLCMain sharedInstance] setIntf: p_intf];
145 [NSBundle loadNibNamed: @"MainMenu" owner: NSApp];
147 /* Install a jmpbuffer to where we can go back before the NSApp exit
148 * see applicationWillTerminate: */
149 if(setjmp(jmpbuffer) == 0)
156 #pragma mark Variables Callback
158 /*****************************************************************************
159 * MsgCallback: Callback triggered by the core once a new debug message is
160 * ready to be displayed. We store everything in a NSArray in our Cocoa part
161 * of this file, so we are forwarding everything through notifications.
162 *****************************************************************************/
163 static void MsgCallback( msg_cb_data_t *data, msg_item_t *item, unsigned int i )
165 int canc = vlc_savecancel();
166 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
168 /* this may happen from time to time, let's bail out as info would be useless anyway */
169 if( !item->psz_module || !item->psz_msg )
172 NSDictionary *o_dict = [NSDictionary dictionaryWithObjectsAndKeys:
173 [NSString stringWithUTF8String: item->psz_module], @"Module",
174 [NSString stringWithUTF8String: item->psz_msg], @"Message",
175 [NSNumber numberWithInt: item->i_type], @"Type", nil];
177 [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCCoreMessageReceived"
182 vlc_restorecancel( canc );
185 /*****************************************************************************
186 * playlistChanged: Callback triggered by the intf-change playlist
187 * variable, to let the intf update the playlist.
188 *****************************************************************************/
189 static int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,
190 vlc_value_t old_val, vlc_value_t new_val, void *param )
192 intf_thread_t * p_intf = VLCIntf;
193 if( p_intf && p_intf->p_sys )
195 p_intf->p_sys->b_intf_update = true;
196 p_intf->p_sys->b_playlist_update = true;
197 p_intf->p_sys->b_playmode_update = true;
198 p_intf->p_sys->b_current_title_update = true;
203 /*****************************************************************************
204 * ShowController: Callback triggered by the show-intf playlist variable
205 * through the ShowIntf-control-intf, to let us show the controller-win;
206 * usually when in fullscreen-mode
207 *****************************************************************************/
208 static int ShowController( vlc_object_t *p_this, const char *psz_variable,
209 vlc_value_t old_val, vlc_value_t new_val, void *param )
211 intf_thread_t * p_intf = VLCIntf;
212 if( p_intf && p_intf->p_sys )
213 p_intf->p_sys->b_intf_show = true;
217 /*****************************************************************************
218 * FullscreenChanged: Callback triggered by the fullscreen-change playlist
219 * variable, to let the intf update the controller.
220 *****************************************************************************/
221 static int FullscreenChanged( vlc_object_t *p_this, const char *psz_variable,
222 vlc_value_t old_val, vlc_value_t new_val, void *param )
224 intf_thread_t * p_intf = VLCIntf;
225 if( p_intf && p_intf->p_sys )
226 p_intf->p_sys->b_fullscreen_update = true;
230 /*****************************************************************************
231 * DialogCallback: Callback triggered by the "dialog-*" variables
232 * to let the intf display error and interaction dialogs
233 *****************************************************************************/
234 static int DialogCallback( vlc_object_t *p_this, const char *type, vlc_value_t previous, vlc_value_t value, void *data )
236 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
237 VLCMain *interface = (VLCMain *)data;
239 if( [[NSString stringWithUTF8String: type] isEqualToString: @"dialog-progress-bar"] )
241 /* the progress panel needs to update itself and therefore wants special treatment within this context */
242 dialog_progress_bar_t *p_dialog = (dialog_progress_bar_t *)value.p_address;
244 p_dialog->pf_update = updateProgressPanel;
245 p_dialog->pf_check = checkProgressPanel;
246 p_dialog->pf_destroy = destroyProgressPanel;
247 p_dialog->p_sys = VLCIntf->p_libvlc;
250 NSValue *o_value = [NSValue valueWithPointer:value.p_address];
251 [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCNewCoreDialogEventNotification" object:[interface coreDialogProvider] userInfo:[NSDictionary dictionaryWithObjectsAndKeys: o_value, @"VLCDialogPointer", [NSString stringWithUTF8String: type], @"VLCDialogType", nil]];
257 void updateProgressPanel (void *priv, const char *text, float value)
259 NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
263 o_txt = [NSString stringWithUTF8String: text];
267 [[[VLCMain sharedInstance] coreDialogProvider] updateProgressPanelWithText: o_txt andNumber: (double)(value * 1000.)];
272 void destroyProgressPanel (void *priv)
274 NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
275 [[[VLCMain sharedInstance] coreDialogProvider] destroyProgressPanel];
279 bool checkProgressPanel (void *priv)
281 NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
282 return [[[VLCMain sharedInstance] coreDialogProvider] progressCancelled];
289 @interface VLCMain ()
290 - (void)_removeOldPreferences;
293 /*****************************************************************************
294 * VLCMain implementation
295 *****************************************************************************/
296 @implementation VLCMain
299 #pragma mark Initialization
301 static VLCMain *_o_sharedMainInstance = nil;
303 + (VLCMain *)sharedInstance
305 return _o_sharedMainInstance ? _o_sharedMainInstance : [[self alloc] init];
310 if( _o_sharedMainInstance)
313 return _o_sharedMainInstance;
316 _o_sharedMainInstance = [super init];
318 o_msg_lock = [[NSLock alloc] init];
319 o_msg_arr = [[NSMutableArray arrayWithCapacity: 200] retain];
320 /* subscribe to LibVLC's debug messages as early as possible (for us) */
321 [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(libvlcMessageReceived:) name: @"VLCCoreMessageReceived" object: nil];
323 o_about = [[VLAboutBox alloc] init];
325 o_open = [[VLCOpen alloc] init];
326 o_wizard = [[VLCWizard alloc] init];
327 o_vlm = [[VLCVLMController alloc] init];
329 o_bookmarks = [[VLCBookmarks alloc] init];
330 o_embedded_list = [[VLCEmbeddedList alloc] init];
331 o_coredialogs = [[VLCCoreDialogProvider alloc] init];
332 o_info = [[VLCInfo alloc] init];
334 o_update = [[VLCUpdate alloc] init];
337 i_lastShownVolume = -1;
340 o_remote = [[AppleRemote alloc] init];
341 [o_remote setClickCountEnabledButtons: kRemoteButtonPlay];
342 [o_remote setDelegate: _o_sharedMainInstance];
345 o_eyetv = [[VLCEyeTVController alloc] init];
347 /* announce our launch to a potential eyetv plugin */
348 [[NSDistributedNotificationCenter defaultCenter] postNotificationName: @"VLCOSXGUIInit"
349 object: @"VLCEyeTVSupport"
351 deliverImmediately: YES];
353 return _o_sharedMainInstance;
356 - (void)setIntf: (intf_thread_t *)p_mainintf {
360 - (intf_thread_t *)intf {
366 unsigned int i_key = 0;
367 playlist_t *p_playlist;
370 /* Check if we already did this once. Opening the other nibs calls it too, because VLCMain is the owner */
371 if( nib_main_loaded ) return;
373 /* check whether the user runs a valid version of OS X */
374 if( MACOS_VERSION < 10.5f )
379 if( MACOS_VERSION == 10.4f )
380 o_blabla = _NS("VLC's last release for your OS is the 0.9 series." );
381 else if( MACOS_VERSION == 10.3f )
382 o_blabla = _NS("VLC's last release for your OS is VLC 0.8.6i, which is prone to known security issues." );
383 else // 10.2 and 10.1, still 3% of the OS X market share
384 o_blabla = _NS("VLC's last release for your OS is VLC 0.7.2, which is highly out of date and prone to " \
385 "known security issues. We recommend you to update your Mac to a modern version of Mac OS X.");
386 ourAlert = [NSAlert alertWithMessageText: _NS("Your version of Mac OS X is no longer supported")
387 defaultButton: _NS("Quit")
388 alternateButton: NULL
390 informativeTextWithFormat: _NS("VLC media player %s requires Mac OS X 10.5 or higher.\n\n%@"), VLC_Version(), o_blabla];
391 [ourAlert setAlertStyle: NSCriticalAlertStyle];
392 i_returnValue = [ourAlert runModal];
393 [NSApp performSelectorOnMainThread: @selector(terminate:) withObject:nil waitUntilDone:NO];
399 [o_window setExcludedFromWindowsMenu: YES];
400 [o_msgs_panel setExcludedFromWindowsMenu: YES];
401 [o_msgs_panel setDelegate: self];
403 /* In code and not in Nib for 10.4 compat */
404 NSToolbar * toolbar = [[[NSToolbar alloc] initWithIdentifier:@"mainControllerToolbar"] autorelease];
405 [toolbar setDelegate:self];
406 [toolbar setShowsBaselineSeparator:NO];
407 [toolbar setAllowsUserCustomization:NO];
408 [toolbar setDisplayMode:NSToolbarDisplayModeIconOnly];
409 [toolbar setAutosavesConfiguration:YES];
410 [o_window setToolbar:toolbar];
412 i_key = config_GetInt( p_intf, "key-quit" );
413 [o_mi_quit setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
414 [o_mi_quit setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
415 i_key = config_GetInt( p_intf, "key-play-pause" );
416 [o_mi_play setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
417 [o_mi_play setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
418 i_key = config_GetInt( p_intf, "key-stop" );
419 [o_mi_stop setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
420 [o_mi_stop setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
421 i_key = config_GetInt( p_intf, "key-faster" );
422 [o_mi_faster setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
423 [o_mi_faster setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
424 i_key = config_GetInt( p_intf, "key-slower" );
425 [o_mi_slower setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
426 [o_mi_slower setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
427 i_key = config_GetInt( p_intf, "key-prev" );
428 [o_mi_previous setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
429 [o_mi_previous setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
430 i_key = config_GetInt( p_intf, "key-next" );
431 [o_mi_next setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
432 [o_mi_next setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
433 i_key = config_GetInt( p_intf, "key-jump+short" );
434 [o_mi_fwd setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
435 [o_mi_fwd setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
436 i_key = config_GetInt( p_intf, "key-jump-short" );
437 [o_mi_bwd setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
438 [o_mi_bwd setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
439 i_key = config_GetInt( p_intf, "key-jump+medium" );
440 [o_mi_fwd1m setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
441 [o_mi_fwd1m setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
442 i_key = config_GetInt( p_intf, "key-jump-medium" );
443 [o_mi_bwd1m setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
444 [o_mi_bwd1m setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
445 i_key = config_GetInt( p_intf, "key-jump+long" );
446 [o_mi_fwd5m setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
447 [o_mi_fwd5m setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
448 i_key = config_GetInt( p_intf, "key-jump-long" );
449 [o_mi_bwd5m setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
450 [o_mi_bwd5m setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
451 i_key = config_GetInt( p_intf, "key-vol-up" );
452 [o_mi_vol_up setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
453 [o_mi_vol_up setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
454 i_key = config_GetInt( p_intf, "key-vol-down" );
455 [o_mi_vol_down setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
456 [o_mi_vol_down setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
457 i_key = config_GetInt( p_intf, "key-vol-mute" );
458 [o_mi_mute setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
459 [o_mi_mute setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
460 i_key = config_GetInt( p_intf, "key-fullscreen" );
461 [o_mi_fullscreen setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
462 [o_mi_fullscreen setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
463 i_key = config_GetInt( p_intf, "key-snapshot" );
464 [o_mi_snapshot setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
465 [o_mi_snapshot setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
467 var_Create( p_intf, "intf-change", VLC_VAR_BOOL );
469 [self setSubmenusEnabled: FALSE];
470 [o_volumeslider setEnabled: YES];
471 [self manageVolumeSlider];
472 [o_window setDelegate: self];
474 b_restore_size = false;
476 // Set that here as IB seems to be buggy
477 [o_window setContentMinSize:NSMakeSize(338., 30.)];
479 if( [o_window contentRectForFrameRect:[o_window frame]].size.height <= 169. )
481 b_small_window = YES;
482 [o_window setFrame: NSMakeRect( [o_window frame].origin.x,
483 [o_window frame].origin.y, [o_window frame].size.width,
484 [o_window minSize].height ) display: YES animate:YES];
485 [o_playlist_view setAutoresizesSubviews: NO];
490 NSRect contentRect = [o_window contentRectForFrameRect:[o_window frame]];
491 [o_playlist_view setFrame: NSMakeRect( 0, 0, contentRect.size.width, contentRect.size.height - [o_window contentMinSize].height )];
492 [o_playlist_view setNeedsDisplay:YES];
493 [o_playlist_view setAutoresizesSubviews: YES];
494 [[o_window contentView] addSubview: o_playlist_view];
497 [self updateTogglePlaylistState];
499 o_size_with_playlist = [o_window contentRectForFrameRect:[o_window frame]].size;
501 p_playlist = pl_Hold( p_intf );
503 var_Create( p_playlist, "fullscreen", VLC_VAR_BOOL | VLC_VAR_DOINHERIT);
506 var_AddCallback( p_playlist, "fullscreen", FullscreenChanged, self);
507 var_AddCallback( p_intf->p_libvlc, "intf-show", ShowController, self);
509 pl_Release( p_intf );
511 /* load our Core Dialogs nib */
512 nib_coredialogs_loaded = [NSBundle loadNibNamed:@"CoreDialogs" owner: NSApp];
514 /* subscribe to various interactive dialogues */
515 var_Create( p_intf, "dialog-fatal", VLC_VAR_ADDRESS );
516 var_AddCallback( p_intf, "dialog-fatal", DialogCallback, self );
517 var_Create( p_intf, "dialog-login", VLC_VAR_ADDRESS );
518 var_AddCallback( p_intf, "dialog-login", DialogCallback, self );
519 var_Create( p_intf, "dialog-question", VLC_VAR_ADDRESS );
520 var_AddCallback( p_intf, "dialog-question", DialogCallback, self );
521 var_Create( p_intf, "dialog-progress-bar", VLC_VAR_ADDRESS );
522 var_AddCallback( p_intf, "dialog-progress-bar", DialogCallback, self );
523 dialog_Register( p_intf );
525 /* update the playmode stuff */
526 p_intf->p_sys->b_playmode_update = true;
528 [[NSNotificationCenter defaultCenter] addObserver: self
529 selector: @selector(refreshVoutDeviceMenu:)
530 name: NSApplicationDidChangeScreenParametersNotification
533 /* take care of tint changes during runtime */
534 o_img_play = [NSImage imageNamed: @"play"];
535 o_img_pause = [NSImage imageNamed: @"pause"];
536 [self controlTintChanged];
537 [[NSNotificationCenter defaultCenter] addObserver: self
538 selector: @selector( controlTintChanged )
539 name: NSControlTintDidChangeNotification
542 /* yeah, we are done */
543 nib_main_loaded = TRUE;
546 - (void)applicationWillFinishLaunching:(NSNotification *)o_notification
548 /* FIXME: don't poll */
549 interfaceTimer = [[NSTimer scheduledTimerWithTimeInterval: 0.5
550 target: self selector: @selector(manageIntf:)
551 userInfo: nil repeats: FALSE] retain];
553 /* Note: we use the pthread API to support pre-10.5 */
554 pthread_create( &manage_thread, NULL, ManageThread, self );
556 [o_controls setupVarMenuItem: o_mi_add_intf target: (vlc_object_t *)p_intf
557 var: "intf-add" selector: @selector(toggleVar:)];
559 vlc_thread_set_priority( p_intf, VLC_THREAD_PRIORITY_LOW );
562 - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
564 [self _removeOldPreferences];
567 /* Check for update silently on startup */
568 if( !nib_update_loaded )
569 nib_update_loaded = [NSBundle loadNibNamed:@"Update" owner: NSApp];
571 if([o_update shouldCheckForUpdate])
572 [NSThread detachNewThreadSelector:@selector(checkForUpdate) toTarget:o_update withObject:nil];
575 /* Handle sleep notification */
576 [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(computerWillSleep:)
577 name:NSWorkspaceWillSleepNotification object:nil];
579 [NSThread detachNewThreadSelector:@selector(lookForCrashLog) toTarget:self withObject:nil];
584 [o_window setTitle: _NS("VLC media player")];
585 [self setScrollField:_NS("VLC media player") stopAfter:-1];
587 /* button controls */
588 [o_btn_prev setToolTip: _NS("Previous")];
589 [o_btn_rewind setToolTip: _NS("Rewind")];
590 [o_btn_play setToolTip: _NS("Play")];
591 [o_btn_stop setToolTip: _NS("Stop")];
592 [o_btn_ff setToolTip: _NS("Fast Forward")];
593 [o_btn_next setToolTip: _NS("Next")];
594 [o_btn_fullscreen setToolTip: _NS("Fullscreen")];
595 [o_volumeslider setToolTip: _NS("Volume")];
596 [o_timeslider setToolTip: _NS("Position")];
597 [o_btn_playlist setToolTip: _NS("Playlist")];
600 [o_msgs_panel setTitle: _NS("Messages")];
601 [o_msgs_crashlog_btn setTitle: _NS("Open CrashLog...")];
602 [o_msgs_save_btn setTitle: _NS("Save this Log...")];
605 [o_mi_about setTitle: [_NS("About VLC media player") \
606 stringByAppendingString: @"..."]];
607 [o_mi_checkForUpdate setTitle: _NS("Check for Update...")];
608 [o_mi_prefs setTitle: _NS("Preferences...")];
609 [o_mi_add_intf setTitle: _NS("Add Interface")];
610 [o_mu_add_intf setTitle: _NS("Add Interface")];
611 [o_mi_services setTitle: _NS("Services")];
612 [o_mi_hide setTitle: _NS("Hide VLC")];
613 [o_mi_hide_others setTitle: _NS("Hide Others")];
614 [o_mi_show_all setTitle: _NS("Show All")];
615 [o_mi_quit setTitle: _NS("Quit VLC")];
617 [o_mu_file setTitle: _ANS("1:File")];
618 [o_mi_open_generic setTitle: _NS("Advanced Open File...")];
619 [o_mi_open_file setTitle: _NS("Open File...")];
620 [o_mi_open_disc setTitle: _NS("Open Disc...")];
621 [o_mi_open_net setTitle: _NS("Open Network...")];
622 [o_mi_open_capture setTitle: _NS("Open Capture Device...")];
623 [o_mi_open_recent setTitle: _NS("Open Recent")];
624 [o_mi_open_recent_cm setTitle: _NS("Clear Menu")];
625 [o_mi_open_wizard setTitle: _NS("Streaming/Exporting Wizard...")];
627 [o_mu_edit setTitle: _NS("Edit")];
628 [o_mi_cut setTitle: _NS("Cut")];
629 [o_mi_copy setTitle: _NS("Copy")];
630 [o_mi_paste setTitle: _NS("Paste")];
631 [o_mi_clear setTitle: _NS("Clear")];
632 [o_mi_select_all setTitle: _NS("Select All")];
634 [o_mu_controls setTitle: _NS("Playback")];
635 [o_mi_play setTitle: _NS("Play")];
636 [o_mi_stop setTitle: _NS("Stop")];
637 [o_mi_faster setTitle: _NS("Faster")];
638 [o_mi_slower setTitle: _NS("Slower")];
639 [o_mi_previous setTitle: _NS("Previous")];
640 [o_mi_next setTitle: _NS("Next")];
641 [o_mi_random setTitle: _NS("Random")];
642 [o_mi_repeat setTitle: _NS("Repeat One")];
643 [o_mi_loop setTitle: _NS("Repeat All")];
644 [o_mi_fwd setTitle: _NS("Step Forward")];
645 [o_mi_bwd setTitle: _NS("Step Backward")];
647 [o_mi_program setTitle: _NS("Program")];
648 [o_mu_program setTitle: _NS("Program")];
649 [o_mi_title setTitle: _NS("Title")];
650 [o_mu_title setTitle: _NS("Title")];
651 [o_mi_chapter setTitle: _NS("Chapter")];
652 [o_mu_chapter setTitle: _NS("Chapter")];
654 [o_mu_audio setTitle: _NS("Audio")];
655 [o_mi_vol_up setTitle: _NS("Increase Volume")];
656 [o_mi_vol_down setTitle: _NS("Decrease Volume")];
657 [o_mi_mute setTitle: _NS("Mute")];
658 [o_mi_audiotrack setTitle: _NS("Audio Track")];
659 [o_mu_audiotrack setTitle: _NS("Audio Track")];
660 [o_mi_channels setTitle: _NS("Audio Channels")];
661 [o_mu_channels setTitle: _NS("Audio Channels")];
662 [o_mi_device setTitle: _NS("Audio Device")];
663 [o_mu_device setTitle: _NS("Audio Device")];
664 [o_mi_visual setTitle: _NS("Visualizations")];
665 [o_mu_visual setTitle: _NS("Visualizations")];
667 [o_mu_video setTitle: _NS("Video")];
668 [o_mi_half_window setTitle: _NS("Half Size")];
669 [o_mi_normal_window setTitle: _NS("Normal Size")];
670 [o_mi_double_window setTitle: _NS("Double Size")];
671 [o_mi_fittoscreen setTitle: _NS("Fit to Screen")];
672 [o_mi_fullscreen setTitle: _NS("Fullscreen")];
673 [o_mi_floatontop setTitle: _NS("Float on Top")];
674 [o_mi_snapshot setTitle: _NS("Snapshot")];
675 [o_mi_videotrack setTitle: _NS("Video Track")];
676 [o_mu_videotrack setTitle: _NS("Video Track")];
677 [o_mi_aspect_ratio setTitle: _NS("Aspect-ratio")];
678 [o_mu_aspect_ratio setTitle: _NS("Aspect-ratio")];
679 [o_mi_crop setTitle: _NS("Crop")];
680 [o_mu_crop setTitle: _NS("Crop")];
681 [o_mi_screen setTitle: _NS("Fullscreen Video Device")];
682 [o_mu_screen setTitle: _NS("Fullscreen Video Device")];
683 [o_mi_subtitle setTitle: _NS("Subtitles Track")];
684 [o_mu_subtitle setTitle: _NS("Subtitles Track")];
685 [o_mi_addSub setTitle: _NS("Open File...")];
686 [o_mi_deinterlace setTitle: _NS("Deinterlace")];
687 [o_mu_deinterlace setTitle: _NS("Deinterlace")];
688 [o_mi_ffmpeg_pp setTitle: _NS("Post processing")];
689 [o_mu_ffmpeg_pp setTitle: _NS("Post processing")];
690 [o_mi_teletext setTitle: _NS("Teletext")];
691 [o_mi_teletext_transparent setTitle: _NS("Transparent")];
692 [o_mi_teletext_index setTitle: _NS("Index")];
693 [o_mi_teletext_red setTitle: _NS("Red")];
694 [o_mi_teletext_green setTitle: _NS("Green")];
695 [o_mi_teletext_yellow setTitle: _NS("Yellow")];
696 [o_mi_teletext_blue setTitle: _NS("Blue")];
698 [o_mu_window setTitle: _NS("Window")];
699 [o_mi_minimize setTitle: _NS("Minimize Window")];
700 [o_mi_close_window setTitle: _NS("Close Window")];
701 [o_mi_player setTitle: _NS("Player...")];
702 [o_mi_controller setTitle: _NS("Controller...")];
703 [o_mi_equalizer setTitle: _NS("Equalizer...")];
704 [o_mi_extended setTitle: _NS("Extended Controls...")];
705 [o_mi_bookmarks setTitle: _NS("Bookmarks...")];
706 [o_mi_playlist setTitle: _NS("Playlist...")];
707 [o_mi_info setTitle: _NS("Media Information...")];
708 [o_mi_messages setTitle: _NS("Messages...")];
709 [o_mi_errorsAndWarnings setTitle: _NS("Errors and Warnings...")];
711 [o_mi_bring_atf setTitle: _NS("Bring All to Front")];
713 [o_mu_help setTitle: _NS("Help")];
714 [o_mi_help setTitle: _NS("VLC media player Help...")];
715 [o_mi_readme setTitle: _NS("ReadMe / FAQ...")];
716 [o_mi_license setTitle: _NS("License")];
717 [o_mi_documentation setTitle: _NS("Online Documentation...")];
718 [o_mi_website setTitle: _NS("VideoLAN Website...")];
719 [o_mi_donation setTitle: _NS("Make a donation...")];
720 [o_mi_forum setTitle: _NS("Online Forum...")];
723 [o_dmi_play setTitle: _NS("Play")];
724 [o_dmi_stop setTitle: _NS("Stop")];
725 [o_dmi_next setTitle: _NS("Next")];
726 [o_dmi_previous setTitle: _NS("Previous")];
727 [o_dmi_mute setTitle: _NS("Mute")];
730 [o_vmi_play setTitle: _NS("Play")];
731 [o_vmi_stop setTitle: _NS("Stop")];
732 [o_vmi_prev setTitle: _NS("Previous")];
733 [o_vmi_next setTitle: _NS("Next")];
734 [o_vmi_volup setTitle: _NS("Volume Up")];
735 [o_vmi_voldown setTitle: _NS("Volume Down")];
736 [o_vmi_mute setTitle: _NS("Mute")];
737 [o_vmi_fullscreen setTitle: _NS("Fullscreen")];
738 [o_vmi_snapshot setTitle: _NS("Snapshot")];
740 /* crash reporter panel */
741 [o_crashrep_send_btn setTitle: _NS("Send")];
742 [o_crashrep_dontSend_btn setTitle: _NS("Don't Send")];
743 [o_crashrep_title_txt setStringValue: _NS("VLC crashed previously")];
744 [o_crashrep_win setTitle: _NS("VLC crashed previously")];
745 [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, ...")];
746 [o_crashrep_includeEmail_ckb setTitle: _NS("I agree to be possibly contacted about this bugreport.")];
747 [o_crashrep_includeEmail_txt setStringValue: _NS("Only your default E-Mail address will be submitted, including no further information.")];
751 #pragma mark Termination
753 - (void)releaseRepresentedObjects:(NSMenu *)the_menu
755 NSArray *menuitems_array = [the_menu itemArray];
756 for( int i=0; i<[menuitems_array count]; i++ )
758 NSMenuItem *one_item = [menuitems_array objectAtIndex: i];
759 if( [one_item hasSubmenu] )
760 [self releaseRepresentedObjects: [one_item submenu]];
762 [one_item setRepresentedObject:NULL];
766 - (void)applicationWillTerminate:(NSNotification *)notification
768 playlist_t * p_playlist;
769 vout_thread_t * p_vout;
770 int returnedValue = 0;
772 msg_Dbg( p_intf, "Terminating" );
774 /* Make sure the manage_thread won't call -terminate: again */
775 pthread_cancel( manage_thread );
777 /* Make sure the intf object is getting killed */
778 vlc_object_kill( p_intf );
780 /* Make sure our manage_thread ends */
781 pthread_join( manage_thread, NULL );
783 /* Make sure the interfaceTimer is destroyed */
784 [interfaceTimer invalidate];
785 [interfaceTimer release];
786 interfaceTimer = nil;
788 /* make sure that the current volume is saved */
789 config_PutInt( p_intf->p_libvlc, "volume", i_lastShownVolume );
791 /* save the prefs if they were changed in the extended panel */
792 if(o_extended && [o_extended configChanged])
794 [o_extended savePrefs];
797 /* unsubscribe from the interactive dialogues */
798 dialog_Unregister( p_intf );
799 var_DelCallback( p_intf, "dialog-fatal", DialogCallback, self );
800 var_DelCallback( p_intf, "dialog-login", DialogCallback, self );
801 var_DelCallback( p_intf, "dialog-question", DialogCallback, self );
802 var_DelCallback( p_intf, "dialog-progress-bar", DialogCallback, self );
804 /* remove global observer watching for vout device changes correctly */
805 [[NSNotificationCenter defaultCenter] removeObserver: self];
811 /* release some other objects here, because it isn't sure whether dealloc
812 * will be called later on */
813 if( nib_about_loaded )
816 if( nib_prefs_loaded )
822 if( nib_open_loaded )
825 if( nib_extended_loaded )
827 [o_extended release];
830 if( nib_bookmarks_loaded )
831 [o_bookmarks release];
839 if( nib_wizard_loaded )
842 [crashLogURLConnection cancel];
843 [crashLogURLConnection release];
845 [o_embedded_list release];
846 [o_coredialogs release];
849 [o_img_pause_pressed release];
850 [o_img_play_pressed release];
851 [o_img_pause release];
852 [o_img_play release];
854 /* unsubscribe from libvlc's debug messages */
855 msg_Unsubscribe( p_intf->p_sys->p_sub );
857 [o_msg_arr removeAllObjects];
860 [o_msg_lock release];
862 /* write cached user defaults to disk */
863 [[NSUserDefaults standardUserDefaults] synchronize];
865 /* Make sure the Menu doesn't have any references to vlc objects anymore */
866 [self releaseRepresentedObjects:[NSApp mainMenu]];
868 /* Kill the playlist, so that it doesn't accept new request
869 * such as the play request from vlc.c (we are a blocking interface). */
870 p_playlist = pl_Hold( p_intf );
871 vlc_object_kill( p_playlist );
872 pl_Release( p_intf );
874 libvlc_Quit( p_intf->p_libvlc );
878 /* Go back to Run() and make libvlc exit properly */
880 longjmp( jmpbuffer, 1 );
885 #pragma mark Toolbar delegate
887 /* Our item identifiers */
888 static NSString * VLCToolbarMediaControl = @"VLCToolbarMediaControl";
890 - (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar *)toolbar
892 return [NSArray arrayWithObjects:
893 // NSToolbarCustomizeToolbarItemIdentifier,
894 // NSToolbarFlexibleSpaceItemIdentifier,
895 // NSToolbarSpaceItemIdentifier,
896 // NSToolbarSeparatorItemIdentifier,
897 VLCToolbarMediaControl,
901 - (NSArray *) toolbarDefaultItemIdentifiers: (NSToolbar *) toolbar
903 return [NSArray arrayWithObjects:
904 VLCToolbarMediaControl,
908 - (NSToolbarItem *) toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier willBeInsertedIntoToolbar:(BOOL)flag
910 NSToolbarItem *toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier: itemIdentifier] autorelease];
913 if( [itemIdentifier isEqual: VLCToolbarMediaControl] )
915 [toolbarItem setLabel:@"Media Controls"];
916 [toolbarItem setPaletteLabel:@"Media Controls"];
918 NSSize size = toolbarMediaControl.frame.size;
919 [toolbarItem setView:toolbarMediaControl];
920 [toolbarItem setMinSize:size];
922 [toolbarItem setMaxSize:size];
924 // Hack: For some reason we need to make sure
925 // that the those element are on top
926 // Add them again will put them frontmost
927 [toolbarMediaControl addSubview:o_scrollfield];
928 [toolbarMediaControl addSubview:o_timeslider];
929 [toolbarMediaControl addSubview:o_timefield];
930 [toolbarMediaControl addSubview:o_main_pgbar];
932 /* TODO: setup a menu */
936 /* itemIdentifier referred to a toolbar item that is not
937 * provided or supported by us or Cocoa
938 * Returning nil will inform the toolbar
939 * that this kind of item is not supported */
946 #pragma mark Other notification
948 - (void)controlTintChanged
952 if( [o_btn_play alternateImage] == o_img_play_pressed )
955 if( [NSColor currentControlTint] == NSGraphiteControlTint )
957 o_img_play_pressed = [NSImage imageNamed: @"play_graphite"];
958 o_img_pause_pressed = [NSImage imageNamed: @"pause_graphite"];
960 [o_btn_prev setAlternateImage: [NSImage imageNamed: @"previous_graphite"]];
961 [o_btn_rewind setAlternateImage: [NSImage imageNamed: @"skip_previous_graphite"]];
962 [o_btn_stop setAlternateImage: [NSImage imageNamed: @"stop_graphite"]];
963 [o_btn_ff setAlternateImage: [NSImage imageNamed: @"skip_forward_graphite"]];
964 [o_btn_next setAlternateImage: [NSImage imageNamed: @"next_graphite"]];
965 [o_btn_fullscreen setAlternateImage: [NSImage imageNamed: @"fullscreen_graphite"]];
966 [o_btn_playlist setAlternateImage: [NSImage imageNamed: @"playlistdrawer_graphite"]];
967 [o_btn_equalizer setAlternateImage: [NSImage imageNamed: @"equalizerdrawer_graphite"]];
971 o_img_play_pressed = [NSImage imageNamed: @"play_blue"];
972 o_img_pause_pressed = [NSImage imageNamed: @"pause_blue"];
974 [o_btn_prev setAlternateImage: [NSImage imageNamed: @"previous_blue"]];
975 [o_btn_rewind setAlternateImage: [NSImage imageNamed: @"skip_previous_blue"]];
976 [o_btn_stop setAlternateImage: [NSImage imageNamed: @"stop_blue"]];
977 [o_btn_ff setAlternateImage: [NSImage imageNamed: @"skip_forward_blue"]];
978 [o_btn_next setAlternateImage: [NSImage imageNamed: @"next_blue"]];
979 [o_btn_fullscreen setAlternateImage: [NSImage imageNamed: @"fullscreen_blue"]];
980 [o_btn_playlist setAlternateImage: [NSImage imageNamed: @"playlistdrawer_blue"]];
981 [o_btn_equalizer setAlternateImage: [NSImage imageNamed: @"equalizerdrawer_blue"]];
985 [o_btn_play setAlternateImage: o_img_play_pressed];
987 [o_btn_play setAlternateImage: o_img_pause_pressed];
990 /* Listen to the remote in exclusive mode, only when VLC is the active
992 - (void)applicationDidBecomeActive:(NSNotification *)aNotification
995 [o_remote startListening: self];
998 - (void)applicationDidResignActive:(NSNotification *)aNotification
1001 [o_remote stopListening: self];
1005 /* Triggered when the computer goes to sleep */
1006 - (void)computerWillSleep: (NSNotification *)notification
1009 if( p_intf->p_sys->i_play_status == PLAYING_S )
1012 val.i_int = config_GetInt( p_intf, "key-play-pause" );
1013 var_Set( p_intf->p_libvlc, "key-pressed", val );
1018 #pragma mark File opening
1020 - (BOOL)application:(NSApplication *)o_app openFile:(NSString *)o_filename
1022 BOOL b_autoplay = config_GetInt( VLCIntf, "macosx-autoplay" );
1023 NSDictionary *o_dic = [NSDictionary dictionaryWithObjectsAndKeys: o_filename, @"ITEM_URL", nil];
1025 [o_playlist appendArray: [NSArray arrayWithObject: o_dic] atPos: -1 enqueue: NO];
1027 [o_playlist appendArray: [NSArray arrayWithObject: o_dic] atPos: -1 enqueue: YES];
1032 /* When user click in the Dock icon our double click in the finder */
1033 - (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)hasVisibleWindows
1035 if(!hasVisibleWindows)
1036 [o_window makeKeyAndOrderFront:self];
1042 #pragma mark Apple Remote Control
1044 /* Helper method for the remote control interface in order to trigger forward/backward and volume
1045 increase/decrease as long as the user holds the left/right, plus/minus button */
1046 - (void) executeHoldActionForRemoteButton: (NSNumber*) buttonIdentifierNumber
1048 if(b_remote_button_hold)
1050 switch([buttonIdentifierNumber intValue])
1052 case kRemoteButtonRight_Hold:
1053 [o_controls forward: self];
1055 case kRemoteButtonLeft_Hold:
1056 [o_controls backward: self];
1058 case kRemoteButtonVolume_Plus_Hold:
1059 [o_controls volumeUp: self];
1061 case kRemoteButtonVolume_Minus_Hold:
1062 [o_controls volumeDown: self];
1065 if(b_remote_button_hold)
1068 [self performSelector:@selector(executeHoldActionForRemoteButton:)
1069 withObject:buttonIdentifierNumber
1075 /* Apple Remote callback */
1076 - (void) appleRemoteButton: (AppleRemoteEventIdentifier)buttonIdentifier
1077 pressedDown: (BOOL) pressedDown
1078 clickCount: (unsigned int) count
1080 switch( buttonIdentifier )
1082 case kRemoteButtonPlay:
1084 [o_controls toogleFullscreen:self];
1086 [o_controls play: self];
1089 case kRemoteButtonVolume_Plus:
1090 [o_controls volumeUp: self];
1092 case kRemoteButtonVolume_Minus:
1093 [o_controls volumeDown: self];
1095 case kRemoteButtonRight:
1096 [o_controls next: self];
1098 case kRemoteButtonLeft:
1099 [o_controls prev: self];
1101 case kRemoteButtonRight_Hold:
1102 case kRemoteButtonLeft_Hold:
1103 case kRemoteButtonVolume_Plus_Hold:
1104 case kRemoteButtonVolume_Minus_Hold:
1105 /* simulate an event as long as the user holds the button */
1106 b_remote_button_hold = pressedDown;
1109 NSNumber* buttonIdentifierNumber = [NSNumber numberWithInt: buttonIdentifier];
1110 [self performSelector:@selector(executeHoldActionForRemoteButton:)
1111 withObject:buttonIdentifierNumber];
1114 case kRemoteButtonMenu:
1115 [o_controls showPosition: self];
1118 /* Add here whatever you want other buttons to do */
1124 #pragma mark String utility
1125 // FIXME: this has nothing to do here
1127 - (NSString *)localizedString:(const char *)psz
1129 NSString * o_str = nil;
1133 o_str = [[[NSString alloc] initWithUTF8String: psz] autorelease];
1137 msg_Err( VLCIntf, "could not translate: %s", psz );
1143 msg_Warn( VLCIntf, "can't translate empty strings" );
1152 - (char *)delocalizeString:(NSString *)id
1154 NSData * o_data = [id dataUsingEncoding: NSUTF8StringEncoding
1155 allowLossyConversion: NO];
1160 o_data = [id dataUsingEncoding: NSUTF8StringEncoding
1161 allowLossyConversion: YES];
1162 psz_string = malloc( [o_data length] + 1 );
1163 [o_data getBytes: psz_string];
1164 psz_string[ [o_data length] ] = '\0';
1165 msg_Err( VLCIntf, "cannot convert to the requested encoding: %s",
1170 psz_string = malloc( [o_data length] + 1 );
1171 [o_data getBytes: psz_string];
1172 psz_string[ [o_data length] ] = '\0';
1178 /* i_width is in pixels */
1179 - (NSString *)wrapString: (NSString *)o_in_string toWidth: (int) i_width
1181 NSMutableString *o_wrapped;
1182 NSString *o_out_string;
1183 NSRange glyphRange, effectiveRange, charRange;
1184 NSRect lineFragmentRect;
1185 unsigned glyphIndex, breaksInserted = 0;
1187 NSTextStorage *o_storage = [[NSTextStorage alloc] initWithString: o_in_string
1188 attributes: [NSDictionary dictionaryWithObjectsAndKeys:
1189 [NSFont labelFontOfSize: 0.0], NSFontAttributeName, nil]];
1190 NSLayoutManager *o_layout_manager = [[NSLayoutManager alloc] init];
1191 NSTextContainer *o_container = [[NSTextContainer alloc]
1192 initWithContainerSize: NSMakeSize(i_width, 2000)];
1194 [o_layout_manager addTextContainer: o_container];
1195 [o_container release];
1196 [o_storage addLayoutManager: o_layout_manager];
1197 [o_layout_manager release];
1199 o_wrapped = [o_in_string mutableCopy];
1200 glyphRange = [o_layout_manager glyphRangeForTextContainer: o_container];
1202 for( glyphIndex = glyphRange.location ; glyphIndex < NSMaxRange(glyphRange) ;
1203 glyphIndex += effectiveRange.length) {
1204 lineFragmentRect = [o_layout_manager lineFragmentRectForGlyphAtIndex: glyphIndex
1205 effectiveRange: &effectiveRange];
1206 charRange = [o_layout_manager characterRangeForGlyphRange: effectiveRange
1207 actualGlyphRange: &effectiveRange];
1208 if([o_wrapped lineRangeForRange:
1209 NSMakeRange(charRange.location + breaksInserted, charRange.length)].length > charRange.length) {
1210 [o_wrapped insertString: @"\n" atIndex: NSMaxRange(charRange) + breaksInserted];
1214 o_out_string = [NSString stringWithString: o_wrapped];
1215 [o_wrapped release];
1216 [o_storage release];
1218 return o_out_string;
1223 #pragma mark Key Shortcuts
1228 unsigned int i_vlckey;
1229 } nskeys_to_vlckeys[] =
1231 { NSUpArrowFunctionKey, KEY_UP },
1232 { NSDownArrowFunctionKey, KEY_DOWN },
1233 { NSLeftArrowFunctionKey, KEY_LEFT },
1234 { NSRightArrowFunctionKey, KEY_RIGHT },
1235 { NSF1FunctionKey, KEY_F1 },
1236 { NSF2FunctionKey, KEY_F2 },
1237 { NSF3FunctionKey, KEY_F3 },
1238 { NSF4FunctionKey, KEY_F4 },
1239 { NSF5FunctionKey, KEY_F5 },
1240 { NSF6FunctionKey, KEY_F6 },
1241 { NSF7FunctionKey, KEY_F7 },
1242 { NSF8FunctionKey, KEY_F8 },
1243 { NSF9FunctionKey, KEY_F9 },
1244 { NSF10FunctionKey, KEY_F10 },
1245 { NSF11FunctionKey, KEY_F11 },
1246 { NSF12FunctionKey, KEY_F12 },
1247 { NSInsertFunctionKey, KEY_INSERT },
1248 { NSHomeFunctionKey, KEY_HOME },
1249 { NSEndFunctionKey, KEY_END },
1250 { NSPageUpFunctionKey, KEY_PAGEUP },
1251 { NSPageDownFunctionKey, KEY_PAGEDOWN },
1252 { NSMenuFunctionKey, KEY_MENU },
1253 { NSTabCharacter, KEY_TAB },
1254 { NSCarriageReturnCharacter, KEY_ENTER },
1255 { NSEnterCharacter, KEY_ENTER },
1256 { NSBackspaceCharacter, KEY_BACKSPACE },
1257 { (unichar) ' ', KEY_SPACE },
1258 { (unichar) 0x1b, KEY_ESC },
1262 static unichar VLCKeyToCocoa( unsigned int i_key )
1266 for( i = 0; nskeys_to_vlckeys[i].i_vlckey != 0; i++ )
1268 if( nskeys_to_vlckeys[i].i_vlckey == (i_key & ~KEY_MODIFIER) )
1270 return nskeys_to_vlckeys[i].i_nskey;
1273 return (unichar)(i_key & ~KEY_MODIFIER);
1276 unsigned int CocoaKeyToVLC( unichar i_key )
1280 for( i = 0; nskeys_to_vlckeys[i].i_nskey != 0; i++ )
1282 if( nskeys_to_vlckeys[i].i_nskey == i_key )
1284 return nskeys_to_vlckeys[i].i_vlckey;
1287 return (unsigned int)i_key;
1290 static unsigned int VLCModifiersToCocoa( unsigned int i_key )
1292 unsigned int new = 0;
1293 if( i_key & KEY_MODIFIER_COMMAND )
1294 new |= NSCommandKeyMask;
1295 if( i_key & KEY_MODIFIER_ALT )
1296 new |= NSAlternateKeyMask;
1297 if( i_key & KEY_MODIFIER_SHIFT )
1298 new |= NSShiftKeyMask;
1299 if( i_key & KEY_MODIFIER_CTRL )
1300 new |= NSControlKeyMask;
1304 /*****************************************************************************
1305 * hasDefinedShortcutKey: Check to see if the key press is a defined VLC
1306 * shortcut key. If it is, pass it off to VLC for handling and return YES,
1307 * otherwise ignore it and return NO (where it will get handled by Cocoa).
1308 *****************************************************************************/
1309 - (BOOL)hasDefinedShortcutKey:(NSEvent *)o_event
1313 unsigned int i_pressed_modifiers = 0;
1314 struct hotkey *p_hotkeys;
1318 p_hotkeys = p_intf->p_libvlc->p_hotkeys;
1320 i_pressed_modifiers = [o_event modifierFlags];
1322 if( i_pressed_modifiers & NSShiftKeyMask )
1323 val.i_int |= KEY_MODIFIER_SHIFT;
1324 if( i_pressed_modifiers & NSControlKeyMask )
1325 val.i_int |= KEY_MODIFIER_CTRL;
1326 if( i_pressed_modifiers & NSAlternateKeyMask )
1327 val.i_int |= KEY_MODIFIER_ALT;
1328 if( i_pressed_modifiers & NSCommandKeyMask )
1329 val.i_int |= KEY_MODIFIER_COMMAND;
1331 key = [[o_event charactersIgnoringModifiers] characterAtIndex: 0];
1335 case NSDeleteCharacter:
1336 case NSDeleteFunctionKey:
1337 case NSDeleteCharFunctionKey:
1338 case NSBackspaceCharacter:
1339 case NSUpArrowFunctionKey:
1340 case NSDownArrowFunctionKey:
1341 case NSRightArrowFunctionKey:
1342 case NSLeftArrowFunctionKey:
1343 case NSEnterCharacter:
1344 case NSCarriageReturnCharacter:
1348 val.i_int |= CocoaKeyToVLC( key );
1350 for( i = 0; p_hotkeys[i].psz_action != NULL; i++ )
1352 if( p_hotkeys[i].i_key == val.i_int )
1354 var_Set( p_intf->p_libvlc, "key-pressed", val );
1363 #pragma mark Other objects getters
1373 - (id)simplePreferences
1378 if( !nib_prefs_loaded )
1379 nib_prefs_loaded = [NSBundle loadNibNamed:@"Preferences" owner: NSApp];
1389 if( !nib_prefs_loaded )
1390 nib_prefs_loaded = [NSBundle loadNibNamed:@"Preferences" owner: NSApp];
1403 - (BOOL)isPlaylistCollapsed
1405 return ![o_btn_playlist state];
1439 if( o_embedded_list )
1440 return o_embedded_list;
1445 - (id)coreDialogProvider
1448 return o_coredialogs;
1456 return o_main_pgbar;
1461 - (id)controllerWindow
1473 - (id)eyeTVController
1482 #pragma mark Polling
1484 /*****************************************************************************
1485 * ManageThread: An ugly thread that polls
1486 *****************************************************************************/
1487 static void * ManageThread( void *user_data )
1489 id self = user_data;
1496 struct manage_cleanup_stack {
1497 intf_thread_t * p_intf;
1498 input_thread_t ** p_input;
1499 playlist_t * p_playlist;
1503 static void manage_cleanup( void * args )
1505 struct manage_cleanup_stack * manage_cleanup_stack = args;
1506 intf_thread_t * p_intf = manage_cleanup_stack->p_intf;
1507 input_thread_t * p_input = *manage_cleanup_stack->p_input;
1508 id self = manage_cleanup_stack->self;
1509 playlist_t * p_playlist = manage_cleanup_stack->p_playlist;
1511 var_AddCallback( p_playlist, "item-current", PlaylistChanged, self );
1512 var_AddCallback( p_playlist, "intf-change", PlaylistChanged, self );
1513 var_AddCallback( p_playlist, "item-change", PlaylistChanged, self );
1514 var_AddCallback( p_playlist, "playlist-item-append", PlaylistChanged, self );
1515 var_AddCallback( p_playlist, "playlist-item-deleted", PlaylistChanged, self );
1517 pl_Release( p_intf );
1519 if( p_input ) vlc_object_release( p_input );
1524 playlist_t * p_playlist;
1525 input_thread_t * p_input = NULL;
1527 /* new thread requires a new pool */
1529 vlc_thread_set_priority( p_intf, VLC_THREAD_PRIORITY_LOW );
1531 p_playlist = pl_Hold( p_intf );
1533 var_AddCallback( p_playlist, "item-current", PlaylistChanged, self );
1534 var_AddCallback( p_playlist, "intf-change", PlaylistChanged, self );
1535 var_AddCallback( p_playlist, "item-change", PlaylistChanged, self );
1536 var_AddCallback( p_playlist, "playlist-item-append", PlaylistChanged, self );
1537 var_AddCallback( p_playlist, "playlist-item-deleted", PlaylistChanged, self );
1539 struct manage_cleanup_stack stack = { p_intf, &p_input, p_playlist, self };
1540 pthread_cleanup_push(manage_cleanup, &stack);
1544 NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
1548 p_input = playlist_CurrentInput( p_playlist );
1550 /* Refresh the interface */
1553 msg_Dbg( p_intf, "input has changed, refreshing interface" );
1554 p_intf->p_sys->b_input_update = true;
1557 else if( !vlc_object_alive (p_input) || p_input->b_dead )
1560 p_intf->p_sys->b_intf_update = true;
1561 p_intf->p_sys->i_play_status = END_S;
1562 msg_Dbg( p_intf, "input has stopped, refreshing interface" );
1563 vlc_object_release( p_input );
1566 else if( cachedInputState != input_GetState( p_input ) )
1568 p_intf->p_sys->b_intf_update = true;
1571 /* Manage volume status */
1572 [self manageVolumeSlider];
1574 msleep( INTF_IDLE_SLEEP );
1579 pthread_cleanup_pop(1);
1581 msg_Dbg( p_intf, "Killing the Mac OS X module" );
1583 /* We are dead, terminate */
1584 [NSApp performSelectorOnMainThread: @selector(terminate:) withObject:nil waitUntilDone:NO];
1587 - (void)manageVolumeSlider
1589 audio_volume_t i_volume;
1590 aout_VolumeGet( p_intf, &i_volume );
1592 if( i_volume != i_lastShownVolume )
1594 i_lastShownVolume = i_volume;
1595 p_intf->p_sys->b_volume_update = TRUE;
1599 - (void)manageIntf:(NSTimer *)o_timer
1602 playlist_t * p_playlist;
1603 input_thread_t * p_input;
1605 if( p_intf->p_sys->b_input_update )
1607 /* Called when new input is opened */
1608 p_intf->p_sys->b_current_title_update = true;
1609 p_intf->p_sys->b_intf_update = true;
1610 p_intf->p_sys->b_input_update = false;
1611 [self setupMenus]; /* Make sure input menu is up to date */
1613 /* update our info-panel to reflect the new item, if we don't show
1614 * the playlist or the selection is empty */
1615 if( [self isPlaylistCollapsed] == YES )
1617 playlist_t * p_playlist = pl_Hold( p_intf );
1619 playlist_item_t * p_item = playlist_CurrentPlayingItem( p_playlist );
1622 [[self info] updatePanelWithItem: p_item->p_input];
1623 pl_Release( p_intf );
1626 if( p_intf->p_sys->b_intf_update )
1628 bool b_input = false;
1629 bool b_plmul = false;
1630 bool b_control = false;
1631 bool b_seekable = false;
1632 bool b_chapters = false;
1634 playlist_t * p_playlist = pl_Hold( p_intf );
1637 b_plmul = playlist_CurrentSize( p_playlist ) > 1;
1640 p_input = playlist_CurrentInput( p_playlist );
1642 bool b_buffering = NO;
1644 if( ( b_input = ( p_input != NULL ) ) )
1646 /* seekable streams */
1647 cachedInputState = input_GetState( p_input );
1648 if ( cachedInputState == INIT_S ||
1649 cachedInputState == OPENING_S )
1654 /* seekable streams */
1655 b_seekable = var_GetBool( p_input, "can-seek" );
1657 /* check whether slow/fast motion is possible */
1658 b_control = var_GetBool( p_input, "can-rate" );
1660 /* chapters & titles */
1661 //b_chapters = p_input->stream.i_area_nb > 1;
1662 vlc_object_release( p_input );
1664 pl_Release( p_intf );
1668 [o_main_pgbar startAnimation:self];
1669 [o_main_pgbar setIndeterminate:YES];
1670 [o_main_pgbar setHidden:NO];
1674 [o_main_pgbar stopAnimation:self];
1675 [o_main_pgbar setHidden:YES];
1678 [o_btn_stop setEnabled: b_input];
1679 [o_embedded_window setStop: b_input];
1680 [o_btn_ff setEnabled: b_seekable];
1681 [o_btn_rewind setEnabled: b_seekable];
1682 [o_btn_prev setEnabled: (b_plmul || b_chapters)];
1683 [o_embedded_window setPrev: (b_plmul || b_chapters)];
1684 [o_btn_next setEnabled: (b_plmul || b_chapters)];
1685 [o_embedded_window setNext: (b_plmul || b_chapters)];
1687 [o_timeslider setFloatValue: 0.0];
1688 [o_timeslider setEnabled: b_seekable];
1689 [o_timefield setStringValue: @"00:00"];
1690 [[[self controls] fspanel] setStreamPos: 0 andTime: @"00:00"];
1691 [[[self controls] fspanel] setSeekable: b_seekable];
1693 [o_embedded_window setSeekable: b_seekable];
1694 [o_embedded_window setTime:@"00:00" position:0.0];
1696 p_intf->p_sys->b_current_title_update = true;
1698 p_intf->p_sys->b_intf_update = false;
1701 if( p_intf->p_sys->b_playmode_update )
1703 [o_playlist playModeUpdated];
1704 p_intf->p_sys->b_playmode_update = false;
1706 if( p_intf->p_sys->b_playlist_update )
1708 [o_playlist playlistUpdated];
1709 p_intf->p_sys->b_playlist_update = false;
1712 if( p_intf->p_sys->b_fullscreen_update )
1714 p_intf->p_sys->b_fullscreen_update = false;
1717 if( p_intf->p_sys->b_intf_show )
1719 if( [[o_controls voutView] isFullscreen] && config_GetInt( VLCIntf, "macosx-fspanel" ) )
1720 [[o_controls fspanel] fadeIn];
1722 [o_window makeKeyAndOrderFront: self];
1724 p_intf->p_sys->b_intf_show = false;
1727 p_input = pl_CurrentInput( p_intf );
1728 if( p_input && vlc_object_alive (p_input) )
1732 if( p_intf->p_sys->b_current_title_update )
1735 input_item_t * p_item = input_GetItem( p_input );
1736 char * name = input_item_GetNowPlaying( p_item );
1739 name = input_item_GetName( p_item );
1741 aString = [NSString stringWithUTF8String:name];
1745 [self setScrollField: aString stopAfter:-1];
1746 [[[self controls] fspanel] setStreamTitle: aString];
1748 [[o_controls voutView] updateTitle];
1750 [o_playlist updateRowSelection];
1752 p_intf->p_sys->b_current_title_update = FALSE;
1755 if( [o_timeslider isEnabled] )
1757 /* Update the slider */
1761 char psz_time[MSTRTIME_MAX_SIZE];
1764 var_Get( p_input, "position", &pos );
1765 f_updated = 10000. * pos.f_float;
1766 [o_timeslider setFloatValue: f_updated];
1768 var_Get( p_input, "time", &time );
1770 mtime_t dur = input_item_GetDuration( input_GetItem( p_input ) );
1771 if( b_time_remaining && dur != -1 )
1773 o_time = [NSString stringWithFormat: @"-%s", secstotimestr( psz_time, ((dur - time.i_time) / 1000000))];
1776 o_time = [NSString stringWithUTF8String: secstotimestr( psz_time, (time.i_time / 1000000) )];
1778 [o_timefield setStringValue: o_time];
1779 [[[self controls] fspanel] setStreamPos: f_updated andTime: o_time];
1780 [o_embedded_window setTime: o_time position: f_updated];
1783 /* Manage Playing status */
1784 var_Get( p_input, "state", &val );
1785 if( p_intf->p_sys->i_play_status != val.i_int )
1787 p_intf->p_sys->i_play_status = val.i_int;
1788 [self playStatusUpdated: p_intf->p_sys->i_play_status];
1789 [o_embedded_window playStatusUpdated: p_intf->p_sys->i_play_status];
1791 vlc_object_release( p_input );
1795 vlc_object_release( p_input );
1799 p_intf->p_sys->i_play_status = END_S;
1800 [self playStatusUpdated: p_intf->p_sys->i_play_status];
1801 [o_embedded_window playStatusUpdated: p_intf->p_sys->i_play_status];
1802 [self setSubmenusEnabled: FALSE];
1805 if( p_intf->p_sys->b_volume_update )
1808 int i_volume_step = 0;
1809 o_text = [NSString stringWithFormat: _NS("Volume: %d%%"), i_lastShownVolume * 400 / AOUT_VOLUME_MAX];
1810 if( i_lastShownVolume != -1 )
1811 [self setScrollField:o_text stopAfter:1000000];
1812 i_volume_step = config_GetInt( p_intf->p_libvlc, "volume-step" );
1813 [o_volumeslider setFloatValue: (float)i_lastShownVolume / i_volume_step];
1814 [o_volumeslider setEnabled: TRUE];
1815 [o_embedded_window setVolumeSlider: (float)i_lastShownVolume / i_volume_step];
1816 [o_embedded_window setVolumeEnabled: TRUE];
1817 [[[self controls] fspanel] setVolumeLevel: (float)i_lastShownVolume / i_volume_step];
1818 p_intf->p_sys->b_mute = ( i_lastShownVolume == 0 );
1819 p_intf->p_sys->b_volume_update = FALSE;
1823 [self updateMessageDisplay];
1825 if( ((i_end_scroll != -1) && (mdate() > i_end_scroll)) || !p_input )
1826 [self resetScrollField];
1828 [interfaceTimer autorelease];
1830 interfaceTimer = [[NSTimer scheduledTimerWithTimeInterval: 0.3
1831 target: self selector: @selector(manageIntf:)
1832 userInfo: nil repeats: FALSE] retain];
1836 #pragma mark Interface update
1840 playlist_t * p_playlist = pl_Hold( p_intf );
1841 input_thread_t * p_input = playlist_CurrentInput( p_playlist );
1842 if( p_input != NULL )
1844 [o_controls setupVarMenuItem: o_mi_program target: (vlc_object_t *)p_input
1845 var: "program" selector: @selector(toggleVar:)];
1847 [o_controls setupVarMenuItem: o_mi_title target: (vlc_object_t *)p_input
1848 var: "title" selector: @selector(toggleVar:)];
1850 [o_controls setupVarMenuItem: o_mi_chapter target: (vlc_object_t *)p_input
1851 var: "chapter" selector: @selector(toggleVar:)];
1853 [o_controls setupVarMenuItem: o_mi_audiotrack target: (vlc_object_t *)p_input
1854 var: "audio-es" selector: @selector(toggleVar:)];
1856 [o_controls setupVarMenuItem: o_mi_videotrack target: (vlc_object_t *)p_input
1857 var: "video-es" selector: @selector(toggleVar:)];
1859 [o_controls setupVarMenuItem: o_mi_subtitle target: (vlc_object_t *)p_input
1860 var: "spu-es" selector: @selector(toggleVar:)];
1862 /* special case for "Open File" inside the subtitles menu item */
1863 if( [o_mi_videotrack isEnabled] == YES )
1864 [o_mi_subtitle setEnabled: YES];
1866 aout_instance_t * p_aout = input_GetAout( p_input );
1867 if( p_aout != NULL )
1869 [o_controls setupVarMenuItem: o_mi_channels target: (vlc_object_t *)p_aout
1870 var: "audio-channels" selector: @selector(toggleVar:)];
1872 [o_controls setupVarMenuItem: o_mi_device target: (vlc_object_t *)p_aout
1873 var: "audio-device" selector: @selector(toggleVar:)];
1875 [o_controls setupVarMenuItem: o_mi_visual target: (vlc_object_t *)p_aout
1876 var: "visual" selector: @selector(toggleVar:)];
1877 vlc_object_release( (vlc_object_t *)p_aout );
1880 vout_thread_t * p_vout = input_GetVout( p_input );
1882 if( p_vout != NULL )
1884 vlc_object_t * p_dec_obj;
1886 [o_controls setupVarMenuItem: o_mi_aspect_ratio target: (vlc_object_t *)p_vout
1887 var: "aspect-ratio" selector: @selector(toggleVar:)];
1889 [o_controls setupVarMenuItem: o_mi_crop target: (vlc_object_t *) p_vout
1890 var: "crop" selector: @selector(toggleVar:)];
1892 [o_controls setupVarMenuItem: o_mi_screen target: (vlc_object_t *)p_vout
1893 var: "video-device" selector: @selector(toggleVar:)];
1895 [o_controls setupVarMenuItem: o_mi_deinterlace target: (vlc_object_t *)p_vout
1896 var: "deinterlace" selector: @selector(toggleVar:)];
1899 /* FIXME Post processing. */
1900 p_dec_obj = (vlc_object_t *)vlc_object_find(
1901 (vlc_object_t *)p_vout,
1904 if( p_dec_obj != NULL )
1906 [o_controls setupVarMenuItem: o_mi_ffmpeg_pp target:
1907 (vlc_object_t *)p_dec_obj var:"ffmpeg-pp-q" selector:
1908 @selector(toggleVar:)];
1910 vlc_object_release(p_dec_obj);
1913 vlc_object_release( (vlc_object_t *)p_vout );
1915 vlc_object_release( p_input );
1917 pl_Release( p_intf );
1920 - (void)refreshVoutDeviceMenu:(NSNotification *)o_notification
1923 vout_thread_t * p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
1929 /* clean the menu before adding new entries */
1930 if( [o_mi_screen hasSubmenu] )
1932 y = [[o_mi_screen submenu] numberOfItems] - 1;
1933 msg_Dbg( VLCIntf, "%i items in submenu", y );
1936 msg_Dbg( VLCIntf, "removing item %i of %i", x, y );
1937 [[o_mi_screen submenu] removeItemAtIndex: x];
1942 [o_controls setupVarMenuItem: o_mi_screen target: (vlc_object_t *)p_vout
1943 var: "video-device" selector: @selector(toggleVar:)];
1944 vlc_object_release( (vlc_object_t *)p_vout );
1947 - (void)setScrollField:(NSString *)o_string stopAfter:(int)timeout
1950 i_end_scroll = mdate() + timeout;
1953 [o_scrollfield setStringValue: o_string];
1956 - (void)resetScrollField
1958 playlist_t * p_playlist = pl_Hold( p_intf );
1959 input_thread_t * p_input = playlist_CurrentInput( p_playlist );
1962 if( p_input && vlc_object_alive (p_input) )
1966 playlist_item_t * p_item = playlist_CurrentPlayingItem( p_playlist );
1967 if( input_item_GetNowPlaying( p_item->p_input ) )
1968 o_temp = [NSString stringWithUTF8String:input_item_GetNowPlaying( p_item->p_input )];
1970 o_temp = [NSString stringWithUTF8String:p_item->p_input->psz_name];
1972 [self setScrollField: o_temp stopAfter:-1];
1973 [[[self controls] fspanel] setStreamTitle: o_temp];
1974 vlc_object_release( p_input );
1975 pl_Release( p_intf );
1978 pl_Release( p_intf );
1979 [self setScrollField: _NS("VLC media player") stopAfter:-1];
1982 - (void)playStatusUpdated:(int)i_status
1984 if( i_status == PLAYING_S )
1986 [[[self controls] fspanel] setPause];
1987 [o_btn_play setImage: o_img_pause];
1988 [o_btn_play setAlternateImage: o_img_pause_pressed];
1989 [o_btn_play setToolTip: _NS("Pause")];
1990 [o_mi_play setTitle: _NS("Pause")];
1991 [o_dmi_play setTitle: _NS("Pause")];
1992 [o_vmi_play setTitle: _NS("Pause")];
1996 [[[self controls] fspanel] setPlay];
1997 [o_btn_play setImage: o_img_play];
1998 [o_btn_play setAlternateImage: o_img_play_pressed];
1999 [o_btn_play setToolTip: _NS("Play")];
2000 [o_mi_play setTitle: _NS("Play")];
2001 [o_dmi_play setTitle: _NS("Play")];
2002 [o_vmi_play setTitle: _NS("Play")];
2006 - (void)setSubmenusEnabled:(BOOL)b_enabled
2008 [o_mi_program setEnabled: b_enabled];
2009 [o_mi_title setEnabled: b_enabled];
2010 [o_mi_chapter setEnabled: b_enabled];
2011 [o_mi_audiotrack setEnabled: b_enabled];
2012 [o_mi_visual setEnabled: b_enabled];
2013 [o_mi_videotrack setEnabled: b_enabled];
2014 [o_mi_subtitle setEnabled: b_enabled];
2015 [o_mi_channels setEnabled: b_enabled];
2016 [o_mi_deinterlace setEnabled: b_enabled];
2017 [o_mi_ffmpeg_pp setEnabled: b_enabled];
2018 [o_mi_device setEnabled: b_enabled];
2019 [o_mi_screen setEnabled: b_enabled];
2020 [o_mi_aspect_ratio setEnabled: b_enabled];
2021 [o_mi_crop setEnabled: b_enabled];
2022 [o_mi_teletext setEnabled: b_enabled];
2025 - (IBAction)timesliderUpdate:(id)sender
2028 playlist_t * p_playlist;
2029 input_thread_t * p_input;
2031 switch( [[NSApp currentEvent] type] )
2034 case NSLeftMouseDown:
2035 case NSLeftMouseDragged:
2036 f_updated = [sender floatValue];
2042 p_playlist = pl_Hold( p_intf );
2043 p_input = playlist_CurrentInput( p_playlist );
2044 if( p_input != NULL )
2049 char psz_time[MSTRTIME_MAX_SIZE];
2051 pos.f_float = f_updated / 10000.;
2052 var_Set( p_input, "position", pos );
2053 [o_timeslider setFloatValue: f_updated];
2055 var_Get( p_input, "time", &time );
2057 mtime_t dur = input_item_GetDuration( input_GetItem( p_input ) );
2058 if( b_time_remaining && dur != -1 )
2060 o_time = [NSString stringWithFormat: @"-%s", secstotimestr( psz_time, ((dur - time.i_time) / 1000000) )];
2063 o_time = [NSString stringWithUTF8String: secstotimestr( psz_time, (time.i_time / 1000000) )];
2065 [o_timefield setStringValue: o_time];
2066 [[[self controls] fspanel] setStreamPos: f_updated andTime: o_time];
2067 [o_embedded_window setTime: o_time position: f_updated];
2068 vlc_object_release( p_input );
2070 pl_Release( p_intf );
2073 - (IBAction)timeFieldWasClicked:(id)sender
2075 b_time_remaining = !b_time_remaining;
2080 #pragma mark Recent Items
2082 - (IBAction)clearRecentItems:(id)sender
2084 [[NSDocumentController sharedDocumentController]
2085 clearRecentDocuments: nil];
2088 - (void)openRecentItem:(id)sender
2090 [self application: nil openFile: [sender title]];
2096 - (IBAction)intfOpenFile:(id)sender
2098 if( !nib_open_loaded )
2100 nib_open_loaded = [NSBundle loadNibNamed:@"Open" owner: NSApp];
2101 [o_open awakeFromNib];
2108 - (IBAction)intfOpenFileGeneric:(id)sender
2110 if( !nib_open_loaded )
2112 nib_open_loaded = [NSBundle loadNibNamed:@"Open" owner: NSApp];
2113 [o_open awakeFromNib];
2114 [o_open openFileGeneric];
2116 [o_open openFileGeneric];
2120 - (IBAction)intfOpenDisc:(id)sender
2122 if( !nib_open_loaded )
2124 nib_open_loaded = [NSBundle loadNibNamed:@"Open" owner: NSApp];
2125 [o_open awakeFromNib];
2132 - (IBAction)intfOpenNet:(id)sender
2134 if( !nib_open_loaded )
2136 nib_open_loaded = [NSBundle loadNibNamed:@"Open" owner: NSApp];
2137 [o_open awakeFromNib];
2144 - (IBAction)intfOpenCapture:(id)sender
2146 if( !nib_open_loaded )
2148 nib_open_loaded = [NSBundle loadNibNamed:@"Open" owner: NSApp];
2149 [o_open awakeFromNib];
2150 [o_open openCapture];
2152 [o_open openCapture];
2156 - (IBAction)showWizard:(id)sender
2158 if( !nib_wizard_loaded )
2160 nib_wizard_loaded = [NSBundle loadNibNamed:@"Wizard" owner: NSApp];
2161 [o_wizard initStrings];
2162 [o_wizard resetWizard];
2163 [o_wizard showWizard];
2165 [o_wizard resetWizard];
2166 [o_wizard showWizard];
2170 - (IBAction)showVLM:(id)sender
2172 if( !nib_vlm_loaded )
2173 nib_vlm_loaded = [NSBundle loadNibNamed:@"VLM" owner: NSApp];
2175 [o_vlm showVLMWindow];
2178 - (IBAction)showExtended:(id)sender
2180 if( o_extended == nil )
2181 o_extended = [[VLCExtended alloc] init];
2183 if( !nib_extended_loaded )
2184 nib_extended_loaded = [NSBundle loadNibNamed:@"Extended" owner: NSApp];
2186 [o_extended showPanel];
2189 - (IBAction)showBookmarks:(id)sender
2191 /* we need the wizard-nib for the bookmarks's extract functionality */
2192 if( !nib_wizard_loaded )
2194 nib_wizard_loaded = [NSBundle loadNibNamed:@"Wizard" owner: NSApp];
2195 [o_wizard initStrings];
2198 if( !nib_bookmarks_loaded )
2199 nib_bookmarks_loaded = [NSBundle loadNibNamed:@"Bookmarks" owner: NSApp];
2201 [o_bookmarks showBookmarks];
2204 - (IBAction)viewPreferences:(id)sender
2206 if( !nib_prefs_loaded )
2208 nib_prefs_loaded = [NSBundle loadNibNamed:@"Preferences" owner: NSApp];
2209 o_sprefs = [[VLCSimplePrefs alloc] init];
2210 o_prefs= [[VLCPrefs alloc] init];
2213 [o_sprefs showSimplePrefs];
2219 - (IBAction)checkForUpdate:(id)sender
2222 if( !nib_update_loaded )
2223 nib_update_loaded = [NSBundle loadNibNamed:@"Update" owner: NSApp];
2224 [o_update showUpdateWindow];
2226 msg_Err( VLCIntf, "Update checker wasn't enabled in this build" );
2227 dialog_FatalWait( VLCIntf, _("Update check failed"), _("Checking for updates was not enabled in this build.") );
2232 #pragma mark Help and Docs
2234 - (IBAction)viewAbout:(id)sender
2236 if( !nib_about_loaded )
2237 nib_about_loaded = [NSBundle loadNibNamed:@"About" owner: NSApp];
2239 [o_about showAbout];
2242 - (IBAction)showLicense:(id)sender
2244 if( !nib_about_loaded )
2245 nib_about_loaded = [NSBundle loadNibNamed:@"About" owner: NSApp];
2247 [o_about showGPL: sender];
2250 - (IBAction)viewHelp:(id)sender
2252 if( !nib_about_loaded )
2254 nib_about_loaded = [NSBundle loadNibNamed:@"About" owner: NSApp];
2261 - (IBAction)openReadMe:(id)sender
2263 NSString * o_path = [[NSBundle mainBundle]
2264 pathForResource: @"README.MacOSX" ofType: @"rtf"];
2266 [[NSWorkspace sharedWorkspace] openFile: o_path
2267 withApplication: @"TextEdit"];
2270 - (IBAction)openDocumentation:(id)sender
2272 NSURL * o_url = [NSURL URLWithString:
2273 @"http://www.videolan.org/doc/"];
2275 [[NSWorkspace sharedWorkspace] openURL: o_url];
2278 - (IBAction)openWebsite:(id)sender
2280 NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org/"];
2282 [[NSWorkspace sharedWorkspace] openURL: o_url];
2285 - (IBAction)openForum:(id)sender
2287 NSURL * o_url = [NSURL URLWithString: @"http://forum.videolan.org/"];
2289 [[NSWorkspace sharedWorkspace] openURL: o_url];
2292 - (IBAction)openDonate:(id)sender
2294 NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org/contribute.html#paypal"];
2296 [[NSWorkspace sharedWorkspace] openURL: o_url];
2300 #pragma mark Crash Log
2301 - (void)sendCrashLog:(NSString *)crashLog withUserComment:(NSString *)userComment
2303 NSString *urlStr = @"http://jones.videolan.org/crashlog/sendcrashreport.php";
2304 NSURL *url = [NSURL URLWithString:urlStr];
2306 NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
2307 [req setHTTPMethod:@"POST"];
2310 if( [o_crashrep_includeEmail_ckb state] == NSOnState )
2312 ABPerson * contact = [[ABAddressBook sharedAddressBook] me];
2313 ABMultiValue *emails = [contact valueForProperty:kABEmailProperty];
2314 email = [emails valueAtIndex:[emails indexForIdentifier:
2315 [emails primaryIdentifier]]];
2318 email = [NSString string];
2321 postBody = [NSString stringWithFormat:@"CrashLog=%@&Comment=%@&Email=%@\r\n",
2322 [crashLog stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
2323 [userComment stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
2324 [email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
2326 [req setHTTPBody:[postBody dataUsingEncoding:NSUTF8StringEncoding]];
2328 /* Released from delegate */
2329 crashLogURLConnection = [[NSURLConnection alloc] initWithRequest:req delegate:self];
2332 - (void)connectionDidFinishLoading:(NSURLConnection *)connection
2334 NSRunInformationalAlertPanel(_NS("Crash Report successfully sent"),
2335 _NS("Thanks for your report!"),
2336 _NS("OK"), nil, nil, nil);
2337 [crashLogURLConnection release];
2338 crashLogURLConnection = nil;
2341 - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
2343 NSRunCriticalAlertPanel(_NS("Error when sending the Crash Report"), [error localizedDescription], @"OK", nil, nil);
2344 [crashLogURLConnection release];
2345 crashLogURLConnection = nil;
2348 - (NSString *)latestCrashLogPathPreviouslySeen:(BOOL)previouslySeen
2350 NSString * crashReporter = [@"~/Library/Logs/CrashReporter" stringByExpandingTildeInPath];
2351 NSDirectoryEnumerator *direnum = [[NSFileManager defaultManager] enumeratorAtPath:crashReporter];
2353 NSString * latestLog = nil;
2354 int year = !previouslySeen ? [[NSUserDefaults standardUserDefaults] integerForKey:@"LatestCrashReportYear"] : 0;
2355 int month = !previouslySeen ? [[NSUserDefaults standardUserDefaults] integerForKey:@"LatestCrashReportMonth"]: 0;
2356 int day = !previouslySeen ? [[NSUserDefaults standardUserDefaults] integerForKey:@"LatestCrashReportDay"] : 0;
2357 int hours = !previouslySeen ? [[NSUserDefaults standardUserDefaults] integerForKey:@"LatestCrashReportHours"]: 0;
2359 while (fname = [direnum nextObject])
2361 [direnum skipDescendents];
2362 if([fname hasPrefix:@"VLC"] && [fname hasSuffix:@"crash"])
2364 NSArray * compo = [fname componentsSeparatedByString:@"_"];
2365 if( [compo count] < 3 ) continue;
2366 compo = [[compo objectAtIndex:1] componentsSeparatedByString:@"-"];
2367 if( [compo count] < 4 ) continue;
2370 if( year < [[compo objectAtIndex:0] intValue] ||
2371 (year ==[[compo objectAtIndex:0] intValue] &&
2372 (month < [[compo objectAtIndex:1] intValue] ||
2373 (month ==[[compo objectAtIndex:1] intValue] &&
2374 (day < [[compo objectAtIndex:2] intValue] ||
2375 (day ==[[compo objectAtIndex:2] intValue] &&
2376 hours < [[compo objectAtIndex:3] intValue] ))))))
2378 year = [[compo objectAtIndex:0] intValue];
2379 month = [[compo objectAtIndex:1] intValue];
2380 day = [[compo objectAtIndex:2] intValue];
2381 hours = [[compo objectAtIndex:3] intValue];
2382 latestLog = [crashReporter stringByAppendingPathComponent:fname];
2387 if(!(latestLog && [[NSFileManager defaultManager] fileExistsAtPath:latestLog]))
2390 if( !previouslySeen )
2392 [[NSUserDefaults standardUserDefaults] setInteger:year forKey:@"LatestCrashReportYear"];
2393 [[NSUserDefaults standardUserDefaults] setInteger:month forKey:@"LatestCrashReportMonth"];
2394 [[NSUserDefaults standardUserDefaults] setInteger:day forKey:@"LatestCrashReportDay"];
2395 [[NSUserDefaults standardUserDefaults] setInteger:hours forKey:@"LatestCrashReportHours"];
2400 - (NSString *)latestCrashLogPath
2402 return [self latestCrashLogPathPreviouslySeen:YES];
2405 - (void)lookForCrashLog
2407 NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
2408 // This pref key doesn't exists? this VLC is an upgrade, and this crash log come from previous version
2409 BOOL areCrashLogsTooOld = ![[NSUserDefaults standardUserDefaults] integerForKey:@"LatestCrashReportYear"];
2410 NSString * latestLog = [self latestCrashLogPathPreviouslySeen:NO];
2411 if( latestLog && !areCrashLogsTooOld )
2412 [NSApp runModalForWindow: o_crashrep_win];
2416 - (IBAction)crashReporterAction:(id)sender
2418 if( sender == o_crashrep_send_btn )
2419 [self sendCrashLog:[NSString stringWithContentsOfFile: [self latestCrashLogPath] encoding: NSUTF8StringEncoding error: NULL] withUserComment: [o_crashrep_fld string]];
2422 [o_crashrep_win orderOut: sender];
2425 - (IBAction)openCrashLog:(id)sender
2427 NSString * latestLog = [self latestCrashLogPath];
2430 [[NSWorkspace sharedWorkspace] openFile: latestLog withApplication: @"Console"];
2434 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.") );
2439 #pragma mark Remove old prefs
2441 - (void)_removeOldPreferences
2443 static NSString * kVLCPreferencesVersion = @"VLCPreferencesVersion";
2444 static const int kCurrentPreferencesVersion = 1;
2445 int version = [[NSUserDefaults standardUserDefaults] integerForKey:kVLCPreferencesVersion];
2446 if( version >= kCurrentPreferencesVersion ) return;
2448 NSArray *libraries = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,
2449 NSUserDomainMask, YES);
2450 if( !libraries || [libraries count] == 0) return;
2451 NSString * preferences = [[libraries objectAtIndex:0] stringByAppendingPathComponent:@"Preferences"];
2453 /* File not found, don't attempt anything */
2454 if(![[NSFileManager defaultManager] fileExistsAtPath:[preferences stringByAppendingPathComponent:@"VLC"]] &&
2455 ![[NSFileManager defaultManager] fileExistsAtPath:[preferences stringByAppendingPathComponent:@"org.videolan.vlc.plist"]] )
2457 [[NSUserDefaults standardUserDefaults] setInteger:kCurrentPreferencesVersion forKey:kVLCPreferencesVersion];
2461 int res = NSRunInformationalAlertPanel(_NS("Remove old preferences?"),
2462 _NS("We just found an older version of VLC's preferences files."),
2463 _NS("Move To Trash and Relaunch VLC"), _NS("Ignore"), nil, nil);
2464 if( res != NSOKButton )
2466 [[NSUserDefaults standardUserDefaults] setInteger:kCurrentPreferencesVersion forKey:kVLCPreferencesVersion];
2470 NSArray * ourPreferences = [NSArray arrayWithObjects:@"org.videolan.vlc.plist", @"VLC", nil];
2472 /* Move the file to trash so that user can find them later */
2473 [[NSWorkspace sharedWorkspace] performFileOperation:NSWorkspaceRecycleOperation source:preferences destination:nil files:ourPreferences tag:0];
2475 /* really reset the defaults from now on */
2476 [NSUserDefaults resetStandardUserDefaults];
2478 [[NSUserDefaults standardUserDefaults] setInteger:kCurrentPreferencesVersion forKey:kVLCPreferencesVersion];
2479 [[NSUserDefaults standardUserDefaults] synchronize];
2482 const char * path = [[[NSBundle mainBundle] executablePath] UTF8String];
2484 /* For some reason we need to fork(), not just execl(), which reports a ENOTSUP then. */
2490 execl(path, path, NULL);
2494 #pragma mark Errors, warnings and messages
2496 - (IBAction)viewErrorsAndWarnings:(id)sender
2498 [[[self coreDialogProvider] errorPanel] showPanel];
2501 - (IBAction)showMessagesPanel:(id)sender
2503 [o_msgs_panel makeKeyAndOrderFront: sender];
2506 - (IBAction)showInformationPanel:(id)sender
2508 if(! nib_info_loaded )
2509 nib_info_loaded = [NSBundle loadNibNamed:@"MediaInfo" owner: NSApp];
2514 - (void)windowDidBecomeKey:(NSNotification *)o_notification
2516 if( [o_notification object] == o_msgs_panel )
2517 [self updateMessageDisplay];
2520 - (void)updateMessageDisplay
2522 if( [o_msgs_panel isVisible] && b_msg_arr_changed )
2525 NSEnumerator * o_enum;
2527 [o_messages setString: @""];
2531 o_enum = [o_msg_arr objectEnumerator];
2533 while( ( o_msg = [o_enum nextObject] ) != nil )
2535 [o_messages insertText: o_msg];
2538 b_msg_arr_changed = NO;
2539 [o_msg_lock unlock];
2543 - (void)libvlcMessageReceived: (NSNotification *)o_notification
2545 NSColor *o_white = [NSColor whiteColor];
2546 NSColor *o_red = [NSColor redColor];
2547 NSColor *o_yellow = [NSColor yellowColor];
2548 NSColor *o_gray = [NSColor grayColor];
2550 NSColor * pp_color[4] = { o_white, o_red, o_yellow, o_gray };
2551 static const char * ppsz_type[4] = { ": ", " error: ",
2552 " warning: ", " debug: " };
2555 NSDictionary *o_attr;
2556 NSAttributedString *o_msg_color;
2558 int i_type = [[[o_notification userInfo] objectForKey: @"Type"] intValue];
2562 if( [o_msg_arr count] + 2 > 600 )
2564 [o_msg_arr removeObjectAtIndex: 0];
2565 [o_msg_arr removeObjectAtIndex: 1];
2568 o_attr = [NSDictionary dictionaryWithObject: o_gray
2569 forKey: NSForegroundColorAttributeName];
2570 o_msg = [NSString stringWithFormat: @"%@%s",
2571 [[o_notification userInfo] objectForKey: @"Module"],
2573 o_msg_color = [[NSAttributedString alloc]
2574 initWithString: o_msg attributes: o_attr];
2575 [o_msg_arr addObject: [o_msg_color autorelease]];
2577 o_attr = [NSDictionary dictionaryWithObject: pp_color[i_type]
2578 forKey: NSForegroundColorAttributeName];
2579 o_msg = [[[o_notification userInfo] objectForKey: @"Message"] stringByAppendingString: @"\n"];
2580 o_msg_color = [[NSAttributedString alloc]
2581 initWithString: o_msg attributes: o_attr];
2582 [o_msg_arr addObject: [o_msg_color autorelease]];
2584 b_msg_arr_changed = YES;
2585 [o_msg_lock unlock];
2588 - (IBAction)saveDebugLog:(id)sender
2590 NSOpenPanel * saveFolderPanel = [[NSSavePanel alloc] init];
2592 [saveFolderPanel setCanChooseDirectories: NO];
2593 [saveFolderPanel setCanChooseFiles: YES];
2594 [saveFolderPanel setCanSelectHiddenExtension: NO];
2595 [saveFolderPanel setCanCreateDirectories: YES];
2596 [saveFolderPanel setRequiredFileType: @"rtfd"];
2597 [saveFolderPanel beginSheetForDirectory:nil file: [NSString stringWithFormat: _NS("VLC Debug Log (%s).rtfd"), VLC_Version()] modalForWindow: o_msgs_panel modalDelegate:self didEndSelector:@selector(saveDebugLogAsRTF:returnCode:contextInfo:) contextInfo:nil];
2600 - (void)saveDebugLogAsRTF: (NSSavePanel *)sheet returnCode: (int)returnCode contextInfo: (void *)contextInfo
2603 if( returnCode == NSOKButton )
2605 b_returned = [o_messages writeRTFDToFile: [sheet filename] atomically: YES];
2607 msg_Warn( p_intf, "Error while saving the debug log" );
2612 #pragma mark Playlist toggling
2614 - (IBAction)togglePlaylist:(id)sender
2616 NSRect contentRect = [o_window contentRectForFrameRect:[o_window frame]];
2617 NSRect o_rect = [o_window contentRectForFrameRect:[o_window frame]];
2618 /*First, check if the playlist is visible*/
2619 if( contentRect.size.height <= 169. )
2621 o_restore_rect = contentRect;
2622 b_restore_size = true;
2623 b_small_window = YES; /* we know we are small, make sure this is actually set (see case below) */
2626 if( o_size_with_playlist.height > 169. )
2627 o_rect.size.height = o_size_with_playlist.height;
2629 o_rect.size.height = 500.;
2631 if( o_size_with_playlist.width >= [o_window contentMinSize].width )
2632 o_rect.size.width = o_size_with_playlist.width;
2634 o_rect.size.width = [o_window contentMinSize].width;
2636 o_rect.origin.x = contentRect.origin.x;
2637 o_rect.origin.y = contentRect.origin.y - o_rect.size.height +
2638 [o_window contentMinSize].height;
2640 o_rect = [o_window frameRectForContentRect:o_rect];
2642 NSRect screenRect = [[o_window screen] visibleFrame];
2643 if( !NSContainsRect( screenRect, o_rect ) ) {
2644 if( NSMaxX(o_rect) > NSMaxX(screenRect) )
2645 o_rect.origin.x = ( NSMaxX(screenRect) - o_rect.size.width );
2646 if( NSMinY(o_rect) < NSMinY(screenRect) )
2647 o_rect.origin.y = ( NSMinY(screenRect) );
2650 [o_btn_playlist setState: YES];
2654 NSSize curSize = o_rect.size;
2655 if( b_restore_size )
2657 o_rect = o_restore_rect;
2658 if( o_rect.size.height < [o_window contentMinSize].height )
2659 o_rect.size.height = [o_window contentMinSize].height;
2660 if( o_rect.size.width < [o_window contentMinSize].width )
2661 o_rect.size.width = [o_window contentMinSize].width;
2665 NSRect contentRect = [o_window contentRectForFrameRect:[o_window frame]];
2667 o_rect.size.height = [o_window contentMinSize].height;
2668 o_rect.size.width = [o_window contentMinSize].width;
2669 o_rect.origin.x = contentRect.origin.x;
2670 /* Calculate the position of the lower right corner after resize */
2671 o_rect.origin.y = contentRect.origin.y +
2672 contentRect.size.height - [o_window contentMinSize].height;
2675 [o_playlist_view setAutoresizesSubviews: NO];
2676 [o_playlist_view removeFromSuperview];
2677 [o_btn_playlist setState: NO];
2678 b_small_window = NO; /* we aren't small here just yet. we are doing an animated resize after this */
2679 o_rect = [o_window frameRectForContentRect:o_rect];
2682 [o_window setFrame: o_rect display:YES animate: YES];
2685 - (void)updateTogglePlaylistState
2687 if( [o_window contentRectForFrameRect:[o_window frame]].size.height <= 169. )
2688 [o_btn_playlist setState: NO];
2690 [o_btn_playlist setState: YES];
2692 [[self playlist] outlineViewSelectionDidChange: NULL];
2695 - (NSSize)windowWillResize:(NSWindow *)sender toSize:(NSSize)proposedFrameSize
2698 /* Not triggered on a window resize or maxification of the window. only by window mouse dragging resize */
2700 /*Stores the size the controller one resize, to be able to restore it when
2701 toggling the playlist*/
2702 o_size_with_playlist = proposedFrameSize;
2705 rect.size = proposedFrameSize;
2706 if( [o_window contentRectForFrameRect:rect].size.height <= 169. )
2708 if( b_small_window == NO )
2710 /* if large and going to small then hide */
2711 b_small_window = YES;
2712 [o_playlist_view setAutoresizesSubviews: NO];
2713 [o_playlist_view removeFromSuperview];
2715 return NSMakeSize( proposedFrameSize.width, [o_window minSize].height);
2717 return proposedFrameSize;
2720 - (void)windowDidMove:(NSNotification *)notif
2722 b_restore_size = false;
2725 - (void)windowDidResize:(NSNotification *)notif
2727 if( [o_window contentRectForFrameRect:[o_window frame]].size.height > 169. && b_small_window )
2729 /* If large and coming from small then show */
2730 [o_playlist_view setAutoresizesSubviews: YES];
2731 NSRect contentRect = [o_window contentRectForFrameRect:[o_window frame]];
2732 [o_playlist_view setFrame: NSMakeRect( 0, 0, contentRect.size.width, contentRect.size.height - [o_window contentMinSize].height )];
2733 [o_playlist_view setNeedsDisplay:YES];
2734 [[o_window contentView] addSubview: o_playlist_view];
2735 b_small_window = NO;
2737 [self updateTogglePlaylistState];
2744 @implementation VLCMain (NSMenuValidation)
2746 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
2748 NSString *o_title = [o_mi title];
2749 BOOL bEnabled = TRUE;
2751 /* Recent Items Menu */
2752 if( [o_title isEqualToString: _NS("Clear Menu")] )
2754 NSMenu * o_menu = [o_mi_open_recent submenu];
2755 int i_nb_items = [o_menu numberOfItems];
2756 NSArray * o_docs = [[NSDocumentController sharedDocumentController]
2757 recentDocumentURLs];
2758 UInt32 i_nb_docs = [o_docs count];
2760 if( i_nb_items > 1 )
2762 while( --i_nb_items )
2764 [o_menu removeItemAtIndex: 0];
2773 [o_menu insertItem: [NSMenuItem separatorItem] atIndex: 0];
2779 o_url = [o_docs objectAtIndex: i_nb_docs];
2781 if( [o_url isFileURL] )
2783 o_doc = [o_url path];
2787 o_doc = [o_url absoluteString];
2790 [o_menu insertItemWithTitle: o_doc
2791 action: @selector(openRecentItem:)
2792 keyEquivalent: @"" atIndex: 0];
2794 if( i_nb_docs == 0 )
2810 @implementation VLCMain (Internal)
2812 - (void)handlePortMessage:(NSPortMessage *)o_msg
2817 NSInvocation * o_inv;
2818 NSConditionLock * o_lock;
2820 o_data = [[o_msg components] lastObject];
2821 o_inv = *((NSInvocation **)[o_data bytes]);
2822 [o_inv getArgument: &o_value atIndex: 2];
2823 val = (id **)[o_value pointerValue];
2824 [o_inv setArgument: val[1] atIndex: 2];
2829 [o_lock unlockWithCondition: 1];
2834 /*****************************************************************************
2835 * VLCApplication interface
2836 * exclusively used to implement media key support on Al Apple keyboards
2837 * b_justJumped is required as the keyboard send its events faster than
2838 * the user can actually jump through his media
2839 *****************************************************************************/
2841 @implementation VLCApplication
2843 - (void)sendEvent: (NSEvent*)event
2845 if( [event type] == NSSystemDefined && [event subtype] == 8 )
2847 int keyCode = (([event data1] & 0xFFFF0000) >> 16);
2848 int keyFlags = ([event data1] & 0x0000FFFF);
2849 int keyState = (((keyFlags & 0xFF00) >> 8)) == 0xA;
2850 int keyRepeat = (keyFlags & 0x1);
2852 if( keyCode == NX_KEYTYPE_PLAY && keyState == 0 )
2853 var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_PLAY_PAUSE );
2855 if( keyCode == NX_KEYTYPE_FAST && !b_justJumped )
2857 if( keyState == 0 && keyRepeat == 0 )
2859 var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_NEXT );
2861 else if( keyRepeat == 1 )
2863 var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_JUMP_FORWARD_SHORT );
2865 [self performSelector:@selector(resetJump)
2871 if( keyCode == NX_KEYTYPE_REWIND && !b_justJumped )
2873 if( keyState == 0 && keyRepeat == 0 )
2875 var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_PREV );
2877 else if( keyRepeat == 1 )
2879 var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_JUMP_BACKWARD_SHORT );
2881 [self performSelector:@selector(resetJump)
2887 [super sendEvent: event];