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 );
73 #pragma mark VLC Interface Object Callbacks
75 /*****************************************************************************
76 * OpenIntf: initialize interface
77 *****************************************************************************/
78 int OpenIntf ( vlc_object_t *p_this )
80 intf_thread_t *p_intf = (intf_thread_t*) p_this;
82 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
83 if( p_intf->p_sys == NULL )
86 memset( p_intf->p_sys, 0, sizeof( *p_intf->p_sys ) );
88 p_intf->p_sys->o_pool = [[NSAutoreleasePool alloc] init];
90 /* subscribe to LibVLCCore's messages */
91 p_intf->p_sys->p_sub = msg_Subscribe( p_intf->p_libvlc, MsgCallback, NULL );
93 p_intf->b_should_run_on_first_thread = true;
98 /*****************************************************************************
99 * CloseIntf: destroy interface
100 *****************************************************************************/
101 void CloseIntf ( vlc_object_t *p_this )
103 intf_thread_t *p_intf = (intf_thread_t*) p_this;
105 [p_intf->p_sys->o_pool release];
107 free( p_intf->p_sys );
110 /*****************************************************************************
112 *****************************************************************************/
115 static void Run( intf_thread_t *p_intf )
119 /* Do it again - for some unknown reason, vlc_thread_create() often
120 * fails to go to real-time priority with the first launched thread
122 vlc_thread_set_priority( p_intf, VLC_THREAD_PRIORITY_LOW );
124 /* Make sure the "force quit" menu item does quit instantly.
125 * VLC overrides SIGTERM which is sent by the "force quit"
126 * menu item to make sure deamon mode quits gracefully, so
127 * we un-override SIGTERM here. */
129 sigaddset( &set, SIGTERM );
130 pthread_sigmask( SIG_UNBLOCK, &set, NULL );
132 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
134 /* Install a jmpbuffer to where we can go back before the NSApp exit
135 * see applicationWillTerminate: */
136 [VLCApplication sharedApplication];
138 [[VLCMain sharedInstance] setIntf: p_intf];
139 [NSBundle loadNibNamed: @"MainMenu" owner: NSApp];
141 /* Install a jmpbuffer to where we can go back before the NSApp exit
142 * see applicationWillTerminate: */
143 if(setjmp(jmpbuffer) == 0)
150 #pragma mark Variables Callback
152 /*****************************************************************************
153 * MsgCallback: Callback triggered by the core once a new debug message is
154 * ready to be displayed. We store everything in a NSArray in our Cocoa part
155 * of this file, so we are forwarding everything through notifications.
156 *****************************************************************************/
157 static void MsgCallback( msg_cb_data_t *data, msg_item_t *item, unsigned int i )
159 int canc = vlc_savecancel();
160 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
162 /* this may happen from time to time, let's bail out as info would be useless anyway */
163 if( !item->psz_module || !item->psz_msg )
166 NSDictionary *o_dict = [NSDictionary dictionaryWithObjectsAndKeys:
167 [NSString stringWithUTF8String: item->psz_module], @"Module",
168 [NSString stringWithUTF8String: item->psz_msg], @"Message",
169 [NSNumber numberWithInt: item->i_type], @"Type", nil];
171 [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCCoreMessageReceived"
176 vlc_restorecancel( canc );
180 /*****************************************************************************
181 * playlistChanged: Callback triggered by the intf-change playlist
182 * variable, to let the intf update the playlist.
183 *****************************************************************************/
184 static int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,
185 vlc_value_t old_val, vlc_value_t new_val, void *param )
187 intf_thread_t * p_intf = VLCIntf;
188 if( p_intf && p_intf->p_sys )
190 p_intf->p_sys->b_intf_update = true;
191 p_intf->p_sys->b_playlist_update = true;
192 p_intf->p_sys->b_playmode_update = true;
193 p_intf->p_sys->b_current_title_update = true;
198 /*****************************************************************************
199 * ShowController: Callback triggered by the show-intf playlist variable
200 * through the ShowIntf-control-intf, to let us show the controller-win;
201 * usually when in fullscreen-mode
202 *****************************************************************************/
203 static int ShowController( vlc_object_t *p_this, const char *psz_variable,
204 vlc_value_t old_val, vlc_value_t new_val, void *param )
206 intf_thread_t * p_intf = VLCIntf;
207 if( p_intf && p_intf->p_sys )
208 p_intf->p_sys->b_intf_show = true;
212 /*****************************************************************************
213 * FullscreenChanged: Callback triggered by the fullscreen-change playlist
214 * variable, to let the intf update the controller.
215 *****************************************************************************/
216 static int FullscreenChanged( vlc_object_t *p_this, const char *psz_variable,
217 vlc_value_t old_val, vlc_value_t new_val, void *param )
219 intf_thread_t * p_intf = VLCIntf;
220 if( p_intf && p_intf->p_sys )
221 p_intf->p_sys->b_fullscreen_update = true;
225 /*****************************************************************************
226 * DialogCallback: Callback triggered by the "dialog-*" variables
227 * to let the intf display error and interaction dialogs
228 *****************************************************************************/
229 static int DialogCallback( vlc_object_t *p_this, const char *type, vlc_value_t previous, vlc_value_t value, void *data )
231 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
232 VLCMain *interface = (VLCMain *)data;
234 const dialog_fatal_t *p_dialog = (const dialog_fatal_t *)value.p_address;
236 NSValue *o_value = [NSValue valueWithPointer:p_dialog];
237 [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCNewCoreDialogEventNotification" object:[interface coreDialogProvider] userInfo:[NSDictionary dictionaryWithObjectsAndKeys: o_value, @"VLCDialogPointer", [NSString stringWithUTF8String: type], @"VLCDialogType", nil]];
246 @interface VLCMain ()
247 - (void)_removeOldPreferences;
250 /*****************************************************************************
251 * VLCMain implementation
252 *****************************************************************************/
253 @implementation VLCMain
256 #pragma mark Initialization
258 static VLCMain *_o_sharedMainInstance = nil;
260 + (VLCMain *)sharedInstance
262 return _o_sharedMainInstance ? _o_sharedMainInstance : [[self alloc] init];
267 if( _o_sharedMainInstance)
270 return _o_sharedMainInstance;
273 _o_sharedMainInstance = [super init];
275 o_msg_lock = [[NSLock alloc] init];
276 o_msg_arr = [[NSMutableArray arrayWithCapacity: 200] retain];
277 /* subscribe to LibVLC's debug messages as early as possible (for us) */
278 [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(libvlcMessageReceived:) name: @"VLCCoreMessageReceived" object: nil];
280 o_about = [[VLAboutBox alloc] init];
282 o_open = [[VLCOpen alloc] init];
283 o_wizard = [[VLCWizard alloc] init];
284 o_vlm = [[VLCVLMController alloc] init];
286 o_bookmarks = [[VLCBookmarks alloc] init];
287 o_embedded_list = [[VLCEmbeddedList alloc] init];
288 o_coredialogs = [[VLCCoreDialogProvider alloc] init];
289 o_info = [[VLCInfo alloc] init];
291 o_update = [[VLCUpdate alloc] init];
294 i_lastShownVolume = -1;
297 o_remote = [[AppleRemote alloc] init];
298 [o_remote setClickCountEnabledButtons: kRemoteButtonPlay];
299 [o_remote setDelegate: _o_sharedMainInstance];
302 o_eyetv = [[VLCEyeTVController alloc] init];
304 /* announce our launch to a potential eyetv plugin */
305 [[NSDistributedNotificationCenter defaultCenter] postNotificationName: @"VLCOSXGUIInit"
306 object: @"VLCEyeTVSupport"
308 deliverImmediately: YES];
310 return _o_sharedMainInstance;
313 - (void)setIntf: (intf_thread_t *)p_mainintf {
317 - (intf_thread_t *)intf {
323 unsigned int i_key = 0;
324 playlist_t *p_playlist;
327 /* Check if we already did this once. Opening the other nibs calls it too, because VLCMain is the owner */
328 if( nib_main_loaded ) return;
330 /* check whether the user runs a valid version of OS X */
331 if( MACOS_VERSION < 10.5f )
336 if( MACOS_VERSION == 10.4f )
337 o_blabla = _NS("VLC's last release for your OS is the 0.9 series." );
338 else if( MACOS_VERSION == 10.3f )
339 o_blabla = _NS("VLC's last release for your OS is VLC 0.8.6i, which is prone to known security issues." );
340 else // 10.2 and 10.1, still 3% of the OS X market share
341 o_blabla = _NS("VLC's last release for your OS is VLC 0.7.2, which is highly out of date and prone to " \
342 "known security issues. We recommend you to update your Mac to a modern version of Mac OS X.");
343 ourAlert = [NSAlert alertWithMessageText: _NS("Your version of Mac OS X is no longer supported")
344 defaultButton: _NS("Quit")
345 alternateButton: NULL
347 informativeTextWithFormat: _NS("VLC media player %s requires Mac OS X 10.5 or higher.\n\n%@"), VLC_Version(), o_blabla];
348 [ourAlert setAlertStyle: NSCriticalAlertStyle];
349 i_returnValue = [ourAlert runModal];
350 [NSApp performSelectorOnMainThread: @selector(terminate:) withObject:nil waitUntilDone:NO];
356 [o_window setExcludedFromWindowsMenu: YES];
357 [o_msgs_panel setExcludedFromWindowsMenu: YES];
358 [o_msgs_panel setDelegate: self];
360 /* In code and not in Nib for 10.4 compat */
361 NSToolbar * toolbar = [[[NSToolbar alloc] initWithIdentifier:@"mainControllerToolbar"] autorelease];
362 [toolbar setDelegate:self];
363 [toolbar setShowsBaselineSeparator:NO];
364 [toolbar setAllowsUserCustomization:NO];
365 [toolbar setDisplayMode:NSToolbarDisplayModeIconOnly];
366 [toolbar setAutosavesConfiguration:YES];
367 [o_window setToolbar:toolbar];
369 i_key = config_GetInt( p_intf, "key-quit" );
370 [o_mi_quit setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
371 [o_mi_quit setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
372 i_key = config_GetInt( p_intf, "key-play-pause" );
373 [o_mi_play setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
374 [o_mi_play setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
375 i_key = config_GetInt( p_intf, "key-stop" );
376 [o_mi_stop setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
377 [o_mi_stop setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
378 i_key = config_GetInt( p_intf, "key-faster" );
379 [o_mi_faster setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
380 [o_mi_faster setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
381 i_key = config_GetInt( p_intf, "key-slower" );
382 [o_mi_slower setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
383 [o_mi_slower setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
384 i_key = config_GetInt( p_intf, "key-prev" );
385 [o_mi_previous setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
386 [o_mi_previous setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
387 i_key = config_GetInt( p_intf, "key-next" );
388 [o_mi_next setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
389 [o_mi_next setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
390 i_key = config_GetInt( p_intf, "key-jump+short" );
391 [o_mi_fwd setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
392 [o_mi_fwd setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
393 i_key = config_GetInt( p_intf, "key-jump-short" );
394 [o_mi_bwd setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
395 [o_mi_bwd setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
396 i_key = config_GetInt( p_intf, "key-jump+medium" );
397 [o_mi_fwd1m setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
398 [o_mi_fwd1m setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
399 i_key = config_GetInt( p_intf, "key-jump-medium" );
400 [o_mi_bwd1m setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
401 [o_mi_bwd1m setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
402 i_key = config_GetInt( p_intf, "key-jump+long" );
403 [o_mi_fwd5m setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
404 [o_mi_fwd5m setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
405 i_key = config_GetInt( p_intf, "key-jump-long" );
406 [o_mi_bwd5m setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
407 [o_mi_bwd5m setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
408 i_key = config_GetInt( p_intf, "key-vol-up" );
409 [o_mi_vol_up setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
410 [o_mi_vol_up setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
411 i_key = config_GetInt( p_intf, "key-vol-down" );
412 [o_mi_vol_down setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
413 [o_mi_vol_down setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
414 i_key = config_GetInt( p_intf, "key-vol-mute" );
415 [o_mi_mute setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
416 [o_mi_mute setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
417 i_key = config_GetInt( p_intf, "key-fullscreen" );
418 [o_mi_fullscreen setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
419 [o_mi_fullscreen setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
420 i_key = config_GetInt( p_intf, "key-snapshot" );
421 [o_mi_snapshot setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
422 [o_mi_snapshot setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
424 var_Create( p_intf, "intf-change", VLC_VAR_BOOL );
426 [self setSubmenusEnabled: FALSE];
427 [o_volumeslider setEnabled: YES];
428 [self manageVolumeSlider];
429 [o_window setDelegate: self];
431 b_restore_size = false;
433 // Set that here as IB seems to be buggy
434 [o_window setContentMinSize:NSMakeSize(338., 30.)];
436 if( [o_window contentRectForFrameRect:[o_window frame]].size.height <= 169. )
438 b_small_window = YES;
439 [o_window setFrame: NSMakeRect( [o_window frame].origin.x,
440 [o_window frame].origin.y, [o_window frame].size.width,
441 [o_window minSize].height ) display: YES animate:YES];
442 [o_playlist_view setAutoresizesSubviews: NO];
447 NSRect contentRect = [o_window contentRectForFrameRect:[o_window frame]];
448 [o_playlist_view setFrame: NSMakeRect( 0, 0, contentRect.size.width, contentRect.size.height - [o_window contentMinSize].height )];
449 [o_playlist_view setNeedsDisplay:YES];
450 [o_playlist_view setAutoresizesSubviews: YES];
451 [[o_window contentView] addSubview: o_playlist_view];
454 [self updateTogglePlaylistState];
456 o_size_with_playlist = [o_window contentRectForFrameRect:[o_window frame]].size;
458 p_playlist = pl_Hold( p_intf );
460 var_Create( p_playlist, "fullscreen", VLC_VAR_BOOL | VLC_VAR_DOINHERIT);
463 var_AddCallback( p_playlist, "fullscreen", FullscreenChanged, self);
464 var_AddCallback( p_intf->p_libvlc, "intf-show", ShowController, self);
466 pl_Release( p_intf );
468 /* load our Core Dialogs nib */
469 nib_coredialogs_loaded = [NSBundle loadNibNamed:@"CoreDialogs" owner: NSApp];
471 /* subscribe to various interactive dialogues */
472 var_Create( p_intf, "dialog-fatal", VLC_VAR_ADDRESS );
473 var_AddCallback( p_intf, "dialog-fatal", DialogCallback, self );
474 var_Create( p_intf, "dialog-login", VLC_VAR_ADDRESS );
475 var_AddCallback( p_intf, "dialog-login", DialogCallback, self );
476 var_Create( p_intf, "dialog-question", VLC_VAR_ADDRESS );
477 var_AddCallback( p_intf, "dialog-question", DialogCallback, self );
478 var_Create( p_intf, "dialog-progress-bar", VLC_VAR_ADDRESS );
479 var_AddCallback( p_intf, "dialog-progress-bar", DialogCallback, self );
480 dialog_Register( p_intf );
482 /* update the playmode stuff */
483 p_intf->p_sys->b_playmode_update = true;
485 [[NSNotificationCenter defaultCenter] addObserver: self
486 selector: @selector(refreshVoutDeviceMenu:)
487 name: NSApplicationDidChangeScreenParametersNotification
490 /* take care of tint changes during runtime */
491 o_img_play = [NSImage imageNamed: @"play"];
492 o_img_pause = [NSImage imageNamed: @"pause"];
493 [self controlTintChanged];
494 [[NSNotificationCenter defaultCenter] addObserver: self
495 selector: @selector( controlTintChanged )
496 name: NSControlTintDidChangeNotification
499 /* yeah, we are done */
500 nib_main_loaded = TRUE;
503 - (void)applicationWillFinishLaunching:(NSNotification *)o_notification
505 /* FIXME: don't poll */
506 interfaceTimer = [[NSTimer scheduledTimerWithTimeInterval: 0.5
507 target: self selector: @selector(manageIntf:)
508 userInfo: nil repeats: FALSE] retain];
510 /* Note: we use the pthread API to support pre-10.5 */
511 pthread_create( &manage_thread, NULL, ManageThread, self );
513 [o_controls setupVarMenuItem: o_mi_add_intf target: (vlc_object_t *)p_intf
514 var: "intf-add" selector: @selector(toggleVar:)];
516 vlc_thread_set_priority( p_intf, VLC_THREAD_PRIORITY_LOW );
519 - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
521 [self _removeOldPreferences];
524 /* Check for update silently on startup */
525 if( !nib_update_loaded )
526 nib_update_loaded = [NSBundle loadNibNamed:@"Update" owner: NSApp];
528 if([o_update shouldCheckForUpdate])
529 [NSThread detachNewThreadSelector:@selector(checkForUpdate) toTarget:o_update withObject:nil];
532 /* Handle sleep notification */
533 [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(computerWillSleep:)
534 name:NSWorkspaceWillSleepNotification object:nil];
536 [NSThread detachNewThreadSelector:@selector(lookForCrashLog) toTarget:self withObject:nil];
541 [o_window setTitle: _NS("VLC media player")];
542 [self setScrollField:_NS("VLC media player") stopAfter:-1];
544 /* button controls */
545 [o_btn_prev setToolTip: _NS("Previous")];
546 [o_btn_rewind setToolTip: _NS("Rewind")];
547 [o_btn_play setToolTip: _NS("Play")];
548 [o_btn_stop setToolTip: _NS("Stop")];
549 [o_btn_ff setToolTip: _NS("Fast Forward")];
550 [o_btn_next setToolTip: _NS("Next")];
551 [o_btn_fullscreen setToolTip: _NS("Fullscreen")];
552 [o_volumeslider setToolTip: _NS("Volume")];
553 [o_timeslider setToolTip: _NS("Position")];
554 [o_btn_playlist setToolTip: _NS("Playlist")];
557 [o_msgs_panel setTitle: _NS("Messages")];
558 [o_msgs_crashlog_btn setTitle: _NS("Open CrashLog...")];
559 [o_msgs_save_btn setTitle: _NS("Save this Log...")];
562 [o_mi_about setTitle: [_NS("About VLC media player") \
563 stringByAppendingString: @"..."]];
564 [o_mi_checkForUpdate setTitle: _NS("Check for Update...")];
565 [o_mi_prefs setTitle: _NS("Preferences...")];
566 [o_mi_add_intf setTitle: _NS("Add Interface")];
567 [o_mu_add_intf setTitle: _NS("Add Interface")];
568 [o_mi_services setTitle: _NS("Services")];
569 [o_mi_hide setTitle: _NS("Hide VLC")];
570 [o_mi_hide_others setTitle: _NS("Hide Others")];
571 [o_mi_show_all setTitle: _NS("Show All")];
572 [o_mi_quit setTitle: _NS("Quit VLC")];
574 [o_mu_file setTitle: _ANS("1:File")];
575 [o_mi_open_generic setTitle: _NS("Advanced Open File...")];
576 [o_mi_open_file setTitle: _NS("Open File...")];
577 [o_mi_open_disc setTitle: _NS("Open Disc...")];
578 [o_mi_open_net setTitle: _NS("Open Network...")];
579 [o_mi_open_capture setTitle: _NS("Open Capture Device...")];
580 [o_mi_open_recent setTitle: _NS("Open Recent")];
581 [o_mi_open_recent_cm setTitle: _NS("Clear Menu")];
582 [o_mi_open_wizard setTitle: _NS("Streaming/Exporting Wizard...")];
584 [o_mu_edit setTitle: _NS("Edit")];
585 [o_mi_cut setTitle: _NS("Cut")];
586 [o_mi_copy setTitle: _NS("Copy")];
587 [o_mi_paste setTitle: _NS("Paste")];
588 [o_mi_clear setTitle: _NS("Clear")];
589 [o_mi_select_all setTitle: _NS("Select All")];
591 [o_mu_controls setTitle: _NS("Playback")];
592 [o_mi_play setTitle: _NS("Play")];
593 [o_mi_stop setTitle: _NS("Stop")];
594 [o_mi_faster setTitle: _NS("Faster")];
595 [o_mi_slower setTitle: _NS("Slower")];
596 [o_mi_previous setTitle: _NS("Previous")];
597 [o_mi_next setTitle: _NS("Next")];
598 [o_mi_random setTitle: _NS("Random")];
599 [o_mi_repeat setTitle: _NS("Repeat One")];
600 [o_mi_loop setTitle: _NS("Repeat All")];
601 [o_mi_fwd setTitle: _NS("Step Forward")];
602 [o_mi_bwd setTitle: _NS("Step Backward")];
604 [o_mi_program setTitle: _NS("Program")];
605 [o_mu_program setTitle: _NS("Program")];
606 [o_mi_title setTitle: _NS("Title")];
607 [o_mu_title setTitle: _NS("Title")];
608 [o_mi_chapter setTitle: _NS("Chapter")];
609 [o_mu_chapter setTitle: _NS("Chapter")];
611 [o_mu_audio setTitle: _NS("Audio")];
612 [o_mi_vol_up setTitle: _NS("Increase Volume")];
613 [o_mi_vol_down setTitle: _NS("Decrease Volume")];
614 [o_mi_mute setTitle: _NS("Mute")];
615 [o_mi_audiotrack setTitle: _NS("Audio Track")];
616 [o_mu_audiotrack setTitle: _NS("Audio Track")];
617 [o_mi_channels setTitle: _NS("Audio Channels")];
618 [o_mu_channels setTitle: _NS("Audio Channels")];
619 [o_mi_device setTitle: _NS("Audio Device")];
620 [o_mu_device setTitle: _NS("Audio Device")];
621 [o_mi_visual setTitle: _NS("Visualizations")];
622 [o_mu_visual setTitle: _NS("Visualizations")];
624 [o_mu_video setTitle: _NS("Video")];
625 [o_mi_half_window setTitle: _NS("Half Size")];
626 [o_mi_normal_window setTitle: _NS("Normal Size")];
627 [o_mi_double_window setTitle: _NS("Double Size")];
628 [o_mi_fittoscreen setTitle: _NS("Fit to Screen")];
629 [o_mi_fullscreen setTitle: _NS("Fullscreen")];
630 [o_mi_floatontop setTitle: _NS("Float on Top")];
631 [o_mi_snapshot setTitle: _NS("Snapshot")];
632 [o_mi_videotrack setTitle: _NS("Video Track")];
633 [o_mu_videotrack setTitle: _NS("Video Track")];
634 [o_mi_aspect_ratio setTitle: _NS("Aspect-ratio")];
635 [o_mu_aspect_ratio setTitle: _NS("Aspect-ratio")];
636 [o_mi_crop setTitle: _NS("Crop")];
637 [o_mu_crop setTitle: _NS("Crop")];
638 [o_mi_screen setTitle: _NS("Fullscreen Video Device")];
639 [o_mu_screen setTitle: _NS("Fullscreen Video Device")];
640 [o_mi_subtitle setTitle: _NS("Subtitles Track")];
641 [o_mu_subtitle setTitle: _NS("Subtitles Track")];
642 [o_mi_addSub setTitle: _NS("Open File...")];
643 [o_mi_deinterlace setTitle: _NS("Deinterlace")];
644 [o_mu_deinterlace setTitle: _NS("Deinterlace")];
645 [o_mi_ffmpeg_pp setTitle: _NS("Post processing")];
646 [o_mu_ffmpeg_pp setTitle: _NS("Post processing")];
647 [o_mi_teletext setTitle: _NS("Teletext")];
648 [o_mi_teletext_transparent setTitle: _NS("Transparent")];
649 [o_mi_teletext_index setTitle: _NS("Index")];
650 [o_mi_teletext_red setTitle: _NS("Red")];
651 [o_mi_teletext_green setTitle: _NS("Green")];
652 [o_mi_teletext_yellow setTitle: _NS("Yellow")];
653 [o_mi_teletext_blue setTitle: _NS("Blue")];
655 [o_mu_window setTitle: _NS("Window")];
656 [o_mi_minimize setTitle: _NS("Minimize Window")];
657 [o_mi_close_window setTitle: _NS("Close Window")];
658 [o_mi_controller setTitle: _NS("Controller...")];
659 [o_mi_equalizer setTitle: _NS("Equalizer...")];
660 [o_mi_extended setTitle: _NS("Extended Controls...")];
661 [o_mi_bookmarks setTitle: _NS("Bookmarks...")];
662 [o_mi_playlist setTitle: _NS("Playlist...")];
663 [o_mi_info setTitle: _NS("Media Information...")];
664 [o_mi_messages setTitle: _NS("Messages...")];
665 [o_mi_errorsAndWarnings setTitle: _NS("Errors and Warnings...")];
667 [o_mi_bring_atf setTitle: _NS("Bring All to Front")];
669 [o_mu_help setTitle: _NS("Help")];
670 [o_mi_help setTitle: _NS("VLC media player Help...")];
671 [o_mi_readme setTitle: _NS("ReadMe / FAQ...")];
672 [o_mi_license setTitle: _NS("License")];
673 [o_mi_documentation setTitle: _NS("Online Documentation...")];
674 [o_mi_website setTitle: _NS("VideoLAN Website...")];
675 [o_mi_donation setTitle: _NS("Make a donation...")];
676 [o_mi_forum setTitle: _NS("Online Forum...")];
679 [o_dmi_play setTitle: _NS("Play")];
680 [o_dmi_stop setTitle: _NS("Stop")];
681 [o_dmi_next setTitle: _NS("Next")];
682 [o_dmi_previous setTitle: _NS("Previous")];
683 [o_dmi_mute setTitle: _NS("Mute")];
686 [o_vmi_play setTitle: _NS("Play")];
687 [o_vmi_stop setTitle: _NS("Stop")];
688 [o_vmi_prev setTitle: _NS("Previous")];
689 [o_vmi_next setTitle: _NS("Next")];
690 [o_vmi_volup setTitle: _NS("Volume Up")];
691 [o_vmi_voldown setTitle: _NS("Volume Down")];
692 [o_vmi_mute setTitle: _NS("Mute")];
693 [o_vmi_fullscreen setTitle: _NS("Fullscreen")];
694 [o_vmi_snapshot setTitle: _NS("Snapshot")];
696 /* crash reporter panel */
697 [o_crashrep_send_btn setTitle: _NS("Send")];
698 [o_crashrep_dontSend_btn setTitle: _NS("Don't Send")];
699 [o_crashrep_title_txt setStringValue: _NS("VLC crashed previously")];
700 [o_crashrep_win setTitle: _NS("VLC crashed previously")];
701 [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, ...")];
702 [o_crashrep_includeEmail_ckb setTitle: _NS("I agree to be possibly contacted about this bugreport.")];
703 [o_crashrep_includeEmail_txt setStringValue: _NS("Only your default E-Mail address will be submitted, including no further information.")];
707 #pragma mark Termination
709 - (void)releaseRepresentedObjects:(NSMenu *)the_menu
711 NSArray *menuitems_array = [the_menu itemArray];
712 for( int i=0; i<[menuitems_array count]; i++ )
714 NSMenuItem *one_item = [menuitems_array objectAtIndex: i];
715 if( [one_item hasSubmenu] )
716 [self releaseRepresentedObjects: [one_item submenu]];
718 [one_item setRepresentedObject:NULL];
722 - (void)applicationWillTerminate:(NSNotification *)notification
724 playlist_t * p_playlist;
725 vout_thread_t * p_vout;
726 int returnedValue = 0;
728 msg_Dbg( p_intf, "Terminating" );
730 /* Make sure the manage_thread won't call -terminate: again */
731 pthread_cancel( manage_thread );
733 /* Make sure the intf object is getting killed */
734 vlc_object_kill( p_intf );
736 /* Make sure our manage_thread ends */
737 pthread_join( manage_thread, NULL );
739 /* Make sure the interfaceTimer is destroyed */
740 [interfaceTimer invalidate];
741 [interfaceTimer release];
742 interfaceTimer = nil;
744 /* make sure that the current volume is saved */
745 config_PutInt( p_intf->p_libvlc, "volume", i_lastShownVolume );
747 /* save the prefs if they were changed in the extended panel */
748 if(o_extended && [o_extended configChanged])
750 [o_extended savePrefs];
753 /* unsubscribe from the interactive dialogues */
754 dialog_Unregister( p_intf );
755 var_DelCallback( p_intf, "dialog-fatal", DialogCallback, self );
756 var_DelCallback( p_intf, "dialog-login", DialogCallback, self );
757 var_DelCallback( p_intf, "dialog-question", DialogCallback, self );
758 var_DelCallback( p_intf, "dialog-progress-bar", DialogCallback, self );
760 /* remove global observer watching for vout device changes correctly */
761 [[NSNotificationCenter defaultCenter] removeObserver: self];
767 /* release some other objects here, because it isn't sure whether dealloc
768 * will be called later on */
769 if( nib_about_loaded )
772 if( nib_prefs_loaded )
778 if( nib_open_loaded )
781 if( nib_extended_loaded )
783 [o_extended release];
786 if( nib_bookmarks_loaded )
787 [o_bookmarks release];
795 if( nib_wizard_loaded )
798 [crashLogURLConnection cancel];
799 [crashLogURLConnection release];
801 [o_embedded_list release];
802 [o_coredialogs release];
805 [o_img_pause_pressed release];
806 [o_img_play_pressed release];
807 [o_img_pause release];
808 [o_img_play release];
810 /* unsubscribe from libvlc's debug messages */
811 msg_Unsubscribe( p_intf->p_sys->p_sub );
813 [o_msg_arr removeAllObjects];
816 [o_msg_lock release];
818 /* write cached user defaults to disk */
819 [[NSUserDefaults standardUserDefaults] synchronize];
821 /* Make sure the Menu doesn't have any references to vlc objects anymore */
822 [self releaseRepresentedObjects:[NSApp mainMenu]];
824 /* Kill the playlist, so that it doesn't accept new request
825 * such as the play request from vlc.c (we are a blocking interface). */
826 p_playlist = pl_Hold( p_intf );
827 vlc_object_kill( p_playlist );
828 pl_Release( p_intf );
830 libvlc_Quit( p_intf->p_libvlc );
834 /* Go back to Run() and make libvlc exit properly */
836 longjmp( jmpbuffer, 1 );
841 #pragma mark Toolbar delegate
843 /* Our item identifiers */
844 static NSString * VLCToolbarMediaControl = @"VLCToolbarMediaControl";
846 - (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar *)toolbar
848 return [NSArray arrayWithObjects:
849 // NSToolbarCustomizeToolbarItemIdentifier,
850 // NSToolbarFlexibleSpaceItemIdentifier,
851 // NSToolbarSpaceItemIdentifier,
852 // NSToolbarSeparatorItemIdentifier,
853 VLCToolbarMediaControl,
857 - (NSArray *) toolbarDefaultItemIdentifiers: (NSToolbar *) toolbar
859 return [NSArray arrayWithObjects:
860 VLCToolbarMediaControl,
864 - (NSToolbarItem *) toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier willBeInsertedIntoToolbar:(BOOL)flag
866 NSToolbarItem *toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier: itemIdentifier] autorelease];
869 if( [itemIdentifier isEqual: VLCToolbarMediaControl] )
871 [toolbarItem setLabel:@"Media Controls"];
872 [toolbarItem setPaletteLabel:@"Media Controls"];
874 NSSize size = toolbarMediaControl.frame.size;
875 [toolbarItem setView:toolbarMediaControl];
876 [toolbarItem setMinSize:size];
878 [toolbarItem setMaxSize:size];
880 // Hack: For some reason we need to make sure
881 // that the those element are on top
882 // Add them again will put them frontmost
883 [toolbarMediaControl addSubview:o_scrollfield];
884 [toolbarMediaControl addSubview:o_timeslider];
885 [toolbarMediaControl addSubview:o_timefield];
886 [toolbarMediaControl addSubview:o_main_pgbar];
888 /* TODO: setup a menu */
892 /* itemIdentifier referred to a toolbar item that is not
893 * provided or supported by us or Cocoa
894 * Returning nil will inform the toolbar
895 * that this kind of item is not supported */
902 #pragma mark Other notification
904 - (void)controlTintChanged
908 if( [o_btn_play alternateImage] == o_img_play_pressed )
911 if( [NSColor currentControlTint] == NSGraphiteControlTint )
913 o_img_play_pressed = [NSImage imageNamed: @"play_graphite"];
914 o_img_pause_pressed = [NSImage imageNamed: @"pause_graphite"];
916 [o_btn_prev setAlternateImage: [NSImage imageNamed: @"previous_graphite"]];
917 [o_btn_rewind setAlternateImage: [NSImage imageNamed: @"skip_previous_graphite"]];
918 [o_btn_stop setAlternateImage: [NSImage imageNamed: @"stop_graphite"]];
919 [o_btn_ff setAlternateImage: [NSImage imageNamed: @"skip_forward_graphite"]];
920 [o_btn_next setAlternateImage: [NSImage imageNamed: @"next_graphite"]];
921 [o_btn_fullscreen setAlternateImage: [NSImage imageNamed: @"fullscreen_graphite"]];
922 [o_btn_playlist setAlternateImage: [NSImage imageNamed: @"playlistdrawer_graphite"]];
923 [o_btn_equalizer setAlternateImage: [NSImage imageNamed: @"equalizerdrawer_graphite"]];
927 o_img_play_pressed = [NSImage imageNamed: @"play_blue"];
928 o_img_pause_pressed = [NSImage imageNamed: @"pause_blue"];
930 [o_btn_prev setAlternateImage: [NSImage imageNamed: @"previous_blue"]];
931 [o_btn_rewind setAlternateImage: [NSImage imageNamed: @"skip_previous_blue"]];
932 [o_btn_stop setAlternateImage: [NSImage imageNamed: @"stop_blue"]];
933 [o_btn_ff setAlternateImage: [NSImage imageNamed: @"skip_forward_blue"]];
934 [o_btn_next setAlternateImage: [NSImage imageNamed: @"next_blue"]];
935 [o_btn_fullscreen setAlternateImage: [NSImage imageNamed: @"fullscreen_blue"]];
936 [o_btn_playlist setAlternateImage: [NSImage imageNamed: @"playlistdrawer_blue"]];
937 [o_btn_equalizer setAlternateImage: [NSImage imageNamed: @"equalizerdrawer_blue"]];
941 [o_btn_play setAlternateImage: o_img_play_pressed];
943 [o_btn_play setAlternateImage: o_img_pause_pressed];
946 /* Listen to the remote in exclusive mode, only when VLC is the active
948 - (void)applicationDidBecomeActive:(NSNotification *)aNotification
951 [o_remote startListening: self];
954 - (void)applicationDidResignActive:(NSNotification *)aNotification
957 [o_remote stopListening: self];
961 /* Triggered when the computer goes to sleep */
962 - (void)computerWillSleep: (NSNotification *)notification
965 if( p_intf->p_sys->i_play_status == PLAYING_S )
968 val.i_int = config_GetInt( p_intf, "key-play-pause" );
969 var_Set( p_intf->p_libvlc, "key-pressed", val );
974 #pragma mark File opening
976 - (BOOL)application:(NSApplication *)o_app openFile:(NSString *)o_filename
978 BOOL b_autoplay = config_GetInt( VLCIntf, "macosx-autoplay" );
979 NSDictionary *o_dic = [NSDictionary dictionaryWithObjectsAndKeys: o_filename, @"ITEM_URL", nil];
981 [o_playlist appendArray: [NSArray arrayWithObject: o_dic] atPos: -1 enqueue: NO];
983 [o_playlist appendArray: [NSArray arrayWithObject: o_dic] atPos: -1 enqueue: YES];
988 /* When user click in the Dock icon our double click in the finder */
989 - (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)hasVisibleWindows
991 if(!hasVisibleWindows)
992 [o_window makeKeyAndOrderFront:self];
998 #pragma mark Apple Remote Control
1000 /* Helper method for the remote control interface in order to trigger forward/backward and volume
1001 increase/decrease as long as the user holds the left/right, plus/minus button */
1002 - (void) executeHoldActionForRemoteButton: (NSNumber*) buttonIdentifierNumber
1004 if(b_remote_button_hold)
1006 switch([buttonIdentifierNumber intValue])
1008 case kRemoteButtonRight_Hold:
1009 [o_controls forward: self];
1011 case kRemoteButtonLeft_Hold:
1012 [o_controls backward: self];
1014 case kRemoteButtonVolume_Plus_Hold:
1015 [o_controls volumeUp: self];
1017 case kRemoteButtonVolume_Minus_Hold:
1018 [o_controls volumeDown: self];
1021 if(b_remote_button_hold)
1024 [self performSelector:@selector(executeHoldActionForRemoteButton:)
1025 withObject:buttonIdentifierNumber
1031 /* Apple Remote callback */
1032 - (void) appleRemoteButton: (AppleRemoteEventIdentifier)buttonIdentifier
1033 pressedDown: (BOOL) pressedDown
1034 clickCount: (unsigned int) count
1036 switch( buttonIdentifier )
1038 case kRemoteButtonPlay:
1040 [o_controls toogleFullscreen:self];
1042 [o_controls play: self];
1045 case kRemoteButtonVolume_Plus:
1046 [o_controls volumeUp: self];
1048 case kRemoteButtonVolume_Minus:
1049 [o_controls volumeDown: self];
1051 case kRemoteButtonRight:
1052 [o_controls next: self];
1054 case kRemoteButtonLeft:
1055 [o_controls prev: self];
1057 case kRemoteButtonRight_Hold:
1058 case kRemoteButtonLeft_Hold:
1059 case kRemoteButtonVolume_Plus_Hold:
1060 case kRemoteButtonVolume_Minus_Hold:
1061 /* simulate an event as long as the user holds the button */
1062 b_remote_button_hold = pressedDown;
1065 NSNumber* buttonIdentifierNumber = [NSNumber numberWithInt: buttonIdentifier];
1066 [self performSelector:@selector(executeHoldActionForRemoteButton:)
1067 withObject:buttonIdentifierNumber];
1070 case kRemoteButtonMenu:
1071 [o_controls showPosition: self];
1074 /* Add here whatever you want other buttons to do */
1080 #pragma mark String utility
1081 // FIXME: this has nothing to do here
1083 - (NSString *)localizedString:(const char *)psz
1085 NSString * o_str = nil;
1089 o_str = [[[NSString alloc] initWithUTF8String: psz] autorelease];
1093 msg_Err( VLCIntf, "could not translate: %s", psz );
1099 msg_Warn( VLCIntf, "can't translate empty strings" );
1108 - (char *)delocalizeString:(NSString *)id
1110 NSData * o_data = [id dataUsingEncoding: NSUTF8StringEncoding
1111 allowLossyConversion: NO];
1116 o_data = [id dataUsingEncoding: NSUTF8StringEncoding
1117 allowLossyConversion: YES];
1118 psz_string = malloc( [o_data length] + 1 );
1119 [o_data getBytes: psz_string];
1120 psz_string[ [o_data length] ] = '\0';
1121 msg_Err( VLCIntf, "cannot convert to the requested encoding: %s",
1126 psz_string = malloc( [o_data length] + 1 );
1127 [o_data getBytes: psz_string];
1128 psz_string[ [o_data length] ] = '\0';
1134 /* i_width is in pixels */
1135 - (NSString *)wrapString: (NSString *)o_in_string toWidth: (int) i_width
1137 NSMutableString *o_wrapped;
1138 NSString *o_out_string;
1139 NSRange glyphRange, effectiveRange, charRange;
1140 NSRect lineFragmentRect;
1141 unsigned glyphIndex, breaksInserted = 0;
1143 NSTextStorage *o_storage = [[NSTextStorage alloc] initWithString: o_in_string
1144 attributes: [NSDictionary dictionaryWithObjectsAndKeys:
1145 [NSFont labelFontOfSize: 0.0], NSFontAttributeName, nil]];
1146 NSLayoutManager *o_layout_manager = [[NSLayoutManager alloc] init];
1147 NSTextContainer *o_container = [[NSTextContainer alloc]
1148 initWithContainerSize: NSMakeSize(i_width, 2000)];
1150 [o_layout_manager addTextContainer: o_container];
1151 [o_container release];
1152 [o_storage addLayoutManager: o_layout_manager];
1153 [o_layout_manager release];
1155 o_wrapped = [o_in_string mutableCopy];
1156 glyphRange = [o_layout_manager glyphRangeForTextContainer: o_container];
1158 for( glyphIndex = glyphRange.location ; glyphIndex < NSMaxRange(glyphRange) ;
1159 glyphIndex += effectiveRange.length) {
1160 lineFragmentRect = [o_layout_manager lineFragmentRectForGlyphAtIndex: glyphIndex
1161 effectiveRange: &effectiveRange];
1162 charRange = [o_layout_manager characterRangeForGlyphRange: effectiveRange
1163 actualGlyphRange: &effectiveRange];
1164 if([o_wrapped lineRangeForRange:
1165 NSMakeRange(charRange.location + breaksInserted, charRange.length)].length > charRange.length) {
1166 [o_wrapped insertString: @"\n" atIndex: NSMaxRange(charRange) + breaksInserted];
1170 o_out_string = [NSString stringWithString: o_wrapped];
1171 [o_wrapped release];
1172 [o_storage release];
1174 return o_out_string;
1179 #pragma mark Key Shortcuts
1184 unsigned int i_vlckey;
1185 } nskeys_to_vlckeys[] =
1187 { NSUpArrowFunctionKey, KEY_UP },
1188 { NSDownArrowFunctionKey, KEY_DOWN },
1189 { NSLeftArrowFunctionKey, KEY_LEFT },
1190 { NSRightArrowFunctionKey, KEY_RIGHT },
1191 { NSF1FunctionKey, KEY_F1 },
1192 { NSF2FunctionKey, KEY_F2 },
1193 { NSF3FunctionKey, KEY_F3 },
1194 { NSF4FunctionKey, KEY_F4 },
1195 { NSF5FunctionKey, KEY_F5 },
1196 { NSF6FunctionKey, KEY_F6 },
1197 { NSF7FunctionKey, KEY_F7 },
1198 { NSF8FunctionKey, KEY_F8 },
1199 { NSF9FunctionKey, KEY_F9 },
1200 { NSF10FunctionKey, KEY_F10 },
1201 { NSF11FunctionKey, KEY_F11 },
1202 { NSF12FunctionKey, KEY_F12 },
1203 { NSInsertFunctionKey, KEY_INSERT },
1204 { NSHomeFunctionKey, KEY_HOME },
1205 { NSEndFunctionKey, KEY_END },
1206 { NSPageUpFunctionKey, KEY_PAGEUP },
1207 { NSPageDownFunctionKey, KEY_PAGEDOWN },
1208 { NSMenuFunctionKey, KEY_MENU },
1209 { NSTabCharacter, KEY_TAB },
1210 { NSCarriageReturnCharacter, KEY_ENTER },
1211 { NSEnterCharacter, KEY_ENTER },
1212 { NSBackspaceCharacter, KEY_BACKSPACE },
1213 { (unichar) ' ', KEY_SPACE },
1214 { (unichar) 0x1b, KEY_ESC },
1218 static unichar VLCKeyToCocoa( unsigned int i_key )
1222 for( i = 0; nskeys_to_vlckeys[i].i_vlckey != 0; i++ )
1224 if( nskeys_to_vlckeys[i].i_vlckey == (i_key & ~KEY_MODIFIER) )
1226 return nskeys_to_vlckeys[i].i_nskey;
1229 return (unichar)(i_key & ~KEY_MODIFIER);
1232 unsigned int CocoaKeyToVLC( unichar i_key )
1236 for( i = 0; nskeys_to_vlckeys[i].i_nskey != 0; i++ )
1238 if( nskeys_to_vlckeys[i].i_nskey == i_key )
1240 return nskeys_to_vlckeys[i].i_vlckey;
1243 return (unsigned int)i_key;
1246 static unsigned int VLCModifiersToCocoa( unsigned int i_key )
1248 unsigned int new = 0;
1249 if( i_key & KEY_MODIFIER_COMMAND )
1250 new |= NSCommandKeyMask;
1251 if( i_key & KEY_MODIFIER_ALT )
1252 new |= NSAlternateKeyMask;
1253 if( i_key & KEY_MODIFIER_SHIFT )
1254 new |= NSShiftKeyMask;
1255 if( i_key & KEY_MODIFIER_CTRL )
1256 new |= NSControlKeyMask;
1260 /*****************************************************************************
1261 * hasDefinedShortcutKey: Check to see if the key press is a defined VLC
1262 * shortcut key. If it is, pass it off to VLC for handling and return YES,
1263 * otherwise ignore it and return NO (where it will get handled by Cocoa).
1264 *****************************************************************************/
1265 - (BOOL)hasDefinedShortcutKey:(NSEvent *)o_event
1269 unsigned int i_pressed_modifiers = 0;
1270 struct hotkey *p_hotkeys;
1274 p_hotkeys = p_intf->p_libvlc->p_hotkeys;
1276 i_pressed_modifiers = [o_event modifierFlags];
1278 if( i_pressed_modifiers & NSShiftKeyMask )
1279 val.i_int |= KEY_MODIFIER_SHIFT;
1280 if( i_pressed_modifiers & NSControlKeyMask )
1281 val.i_int |= KEY_MODIFIER_CTRL;
1282 if( i_pressed_modifiers & NSAlternateKeyMask )
1283 val.i_int |= KEY_MODIFIER_ALT;
1284 if( i_pressed_modifiers & NSCommandKeyMask )
1285 val.i_int |= KEY_MODIFIER_COMMAND;
1287 key = [[o_event charactersIgnoringModifiers] characterAtIndex: 0];
1291 case NSDeleteCharacter:
1292 case NSDeleteFunctionKey:
1293 case NSDeleteCharFunctionKey:
1294 case NSBackspaceCharacter:
1295 case NSUpArrowFunctionKey:
1296 case NSDownArrowFunctionKey:
1297 case NSRightArrowFunctionKey:
1298 case NSLeftArrowFunctionKey:
1299 case NSEnterCharacter:
1300 case NSCarriageReturnCharacter:
1304 val.i_int |= CocoaKeyToVLC( key );
1306 for( i = 0; p_hotkeys[i].psz_action != NULL; i++ )
1308 if( p_hotkeys[i].i_key == val.i_int )
1310 var_Set( p_intf->p_libvlc, "key-pressed", val );
1319 #pragma mark Other objects getters
1329 - (id)simplePreferences
1334 if( !nib_prefs_loaded )
1335 nib_prefs_loaded = [NSBundle loadNibNamed:@"Preferences" owner: NSApp];
1345 if( !nib_prefs_loaded )
1346 nib_prefs_loaded = [NSBundle loadNibNamed:@"Preferences" owner: NSApp];
1359 - (BOOL)isPlaylistCollapsed
1361 return ![o_btn_playlist state];
1395 if( o_embedded_list )
1396 return o_embedded_list;
1401 - (id)coreDialogProvider
1404 return o_coredialogs;
1412 return o_main_pgbar;
1417 - (id)controllerWindow
1429 - (id)eyeTVController
1438 #pragma mark Polling
1440 /*****************************************************************************
1441 * ManageThread: An ugly thread that polls
1442 *****************************************************************************/
1443 static void * ManageThread( void *user_data )
1445 id self = user_data;
1452 struct manage_cleanup_stack {
1453 intf_thread_t * p_intf;
1454 input_thread_t ** p_input;
1455 playlist_t * p_playlist;
1459 static void manage_cleanup( void * args )
1461 struct manage_cleanup_stack * manage_cleanup_stack = args;
1462 intf_thread_t * p_intf = manage_cleanup_stack->p_intf;
1463 input_thread_t * p_input = *manage_cleanup_stack->p_input;
1464 id self = manage_cleanup_stack->self;
1465 playlist_t * p_playlist = manage_cleanup_stack->p_playlist;
1467 var_AddCallback( p_playlist, "item-current", PlaylistChanged, self );
1468 var_AddCallback( p_playlist, "intf-change", PlaylistChanged, self );
1469 var_AddCallback( p_playlist, "item-change", PlaylistChanged, self );
1470 var_AddCallback( p_playlist, "playlist-item-append", PlaylistChanged, self );
1471 var_AddCallback( p_playlist, "playlist-item-deleted", PlaylistChanged, self );
1473 pl_Release( p_intf );
1475 if( p_input ) vlc_object_release( p_input );
1480 playlist_t * p_playlist;
1481 input_thread_t * p_input = NULL;
1483 /* new thread requires a new pool */
1485 vlc_thread_set_priority( p_intf, VLC_THREAD_PRIORITY_LOW );
1487 p_playlist = pl_Hold( p_intf );
1489 var_AddCallback( p_playlist, "item-current", PlaylistChanged, self );
1490 var_AddCallback( p_playlist, "intf-change", PlaylistChanged, self );
1491 var_AddCallback( p_playlist, "item-change", PlaylistChanged, self );
1492 var_AddCallback( p_playlist, "playlist-item-append", PlaylistChanged, self );
1493 var_AddCallback( p_playlist, "playlist-item-deleted", PlaylistChanged, self );
1495 struct manage_cleanup_stack stack = { p_intf, &p_input, p_playlist, self };
1496 pthread_cleanup_push(manage_cleanup, &stack);
1500 NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
1504 p_input = playlist_CurrentInput( p_playlist );
1506 /* Refresh the interface */
1509 msg_Dbg( p_intf, "input has changed, refreshing interface" );
1510 p_intf->p_sys->b_input_update = true;
1513 else if( !vlc_object_alive (p_input) || p_input->b_dead )
1516 p_intf->p_sys->b_intf_update = true;
1517 p_intf->p_sys->i_play_status = END_S;
1518 msg_Dbg( p_intf, "input has stopped, refreshing interface" );
1519 vlc_object_release( p_input );
1522 else if( cachedInputState != input_GetState( p_input ) )
1524 p_intf->p_sys->b_intf_update = true;
1527 /* Manage volume status */
1528 [self manageVolumeSlider];
1530 msleep( INTF_IDLE_SLEEP );
1535 pthread_cleanup_pop(1);
1537 msg_Dbg( p_intf, "Killing the Mac OS X module" );
1539 /* We are dead, terminate */
1540 [NSApp performSelectorOnMainThread: @selector(terminate:) withObject:nil waitUntilDone:NO];
1543 - (void)manageVolumeSlider
1545 audio_volume_t i_volume;
1546 aout_VolumeGet( p_intf, &i_volume );
1548 if( i_volume != i_lastShownVolume )
1550 i_lastShownVolume = i_volume;
1551 p_intf->p_sys->b_volume_update = TRUE;
1555 - (void)manageIntf:(NSTimer *)o_timer
1558 playlist_t * p_playlist;
1559 input_thread_t * p_input;
1561 if( p_intf->p_sys->b_input_update )
1563 /* Called when new input is opened */
1564 p_intf->p_sys->b_current_title_update = true;
1565 p_intf->p_sys->b_intf_update = true;
1566 p_intf->p_sys->b_input_update = false;
1567 [self setupMenus]; /* Make sure input menu is up to date */
1569 /* update our info-panel to reflect the new item, if we don't show
1570 * the playlist or the selection is empty */
1571 if( [self isPlaylistCollapsed] == YES )
1573 playlist_t * p_playlist = pl_Hold( p_intf );
1575 playlist_item_t * p_item = playlist_CurrentPlayingItem( p_playlist );
1578 [[self info] updatePanelWithItem: p_item->p_input];
1579 pl_Release( p_intf );
1582 if( p_intf->p_sys->b_intf_update )
1584 bool b_input = false;
1585 bool b_plmul = false;
1586 bool b_control = false;
1587 bool b_seekable = false;
1588 bool b_chapters = false;
1590 playlist_t * p_playlist = pl_Hold( p_intf );
1593 b_plmul = playlist_CurrentSize( p_playlist ) > 1;
1596 p_input = playlist_CurrentInput( p_playlist );
1598 bool b_buffering = NO;
1600 if( ( b_input = ( p_input != NULL ) ) )
1602 /* seekable streams */
1603 cachedInputState = input_GetState( p_input );
1604 if ( cachedInputState == INIT_S ||
1605 cachedInputState == OPENING_S )
1610 /* seekable streams */
1611 b_seekable = var_GetBool( p_input, "can-seek" );
1613 /* check whether slow/fast motion is possible */
1614 b_control = var_GetBool( p_input, "can-rate" );
1616 /* chapters & titles */
1617 //b_chapters = p_input->stream.i_area_nb > 1;
1618 vlc_object_release( p_input );
1620 pl_Release( p_intf );
1624 [o_main_pgbar startAnimation:self];
1625 [o_main_pgbar setIndeterminate:YES];
1626 [o_main_pgbar setHidden:NO];
1630 [o_main_pgbar stopAnimation:self];
1631 [o_main_pgbar setHidden:YES];
1634 [o_btn_stop setEnabled: b_input];
1635 [o_btn_ff setEnabled: b_seekable];
1636 [o_btn_rewind setEnabled: b_seekable];
1637 [o_btn_prev setEnabled: (b_plmul || b_chapters)];
1638 [o_btn_next setEnabled: (b_plmul || b_chapters)];
1640 [o_timeslider setFloatValue: 0.0];
1641 [o_timeslider setEnabled: b_seekable];
1642 [o_timefield setStringValue: @"00:00"];
1643 [[[self controls] fspanel] setStreamPos: 0 andTime: @"00:00"];
1644 [[[self controls] fspanel] setSeekable: b_seekable];
1646 [o_embedded_window setSeekable: b_seekable];
1648 p_intf->p_sys->b_current_title_update = true;
1650 p_intf->p_sys->b_intf_update = false;
1653 if( p_intf->p_sys->b_playmode_update )
1655 [o_playlist playModeUpdated];
1656 p_intf->p_sys->b_playmode_update = false;
1658 if( p_intf->p_sys->b_playlist_update )
1660 [o_playlist playlistUpdated];
1661 p_intf->p_sys->b_playlist_update = false;
1664 if( p_intf->p_sys->b_fullscreen_update )
1666 p_intf->p_sys->b_fullscreen_update = false;
1669 if( p_intf->p_sys->b_intf_show )
1671 if( [[o_controls voutView] isFullscreen] && config_GetInt( VLCIntf, "macosx-fspanel" ) )
1672 [[o_controls fspanel] fadeIn];
1674 [o_window makeKeyAndOrderFront: self];
1676 p_intf->p_sys->b_intf_show = false;
1679 p_input = pl_CurrentInput( p_intf );
1680 if( p_input && vlc_object_alive (p_input) )
1684 if( p_intf->p_sys->b_current_title_update )
1687 input_item_t * p_item = input_GetItem( p_input );
1688 char * name = input_item_GetNowPlaying( p_item );
1691 name = input_item_GetName( p_item );
1693 aString = [NSString stringWithUTF8String:name];
1697 [self setScrollField: aString stopAfter:-1];
1698 [[[self controls] fspanel] setStreamTitle: aString];
1700 [[o_controls voutView] updateTitle];
1702 [o_playlist updateRowSelection];
1704 p_intf->p_sys->b_current_title_update = FALSE;
1707 if( [o_timeslider isEnabled] )
1709 /* Update the slider */
1713 char psz_time[MSTRTIME_MAX_SIZE];
1716 var_Get( p_input, "position", &pos );
1717 f_updated = 10000. * pos.f_float;
1718 [o_timeslider setFloatValue: f_updated];
1720 var_Get( p_input, "time", &time );
1722 mtime_t dur = input_item_GetDuration( input_GetItem( p_input ) );
1723 if( b_time_remaining && dur != -1 )
1725 o_time = [NSString stringWithFormat: @"-%s", secstotimestr( psz_time, ((dur - time.i_time) / 1000000))];
1728 o_time = [NSString stringWithUTF8String: secstotimestr( psz_time, (time.i_time / 1000000) )];
1730 [o_timefield setStringValue: o_time];
1731 [[[self controls] fspanel] setStreamPos: f_updated andTime: o_time];
1732 [o_embedded_window setTime: o_time position: f_updated];
1735 /* Manage Playing status */
1736 var_Get( p_input, "state", &val );
1737 if( p_intf->p_sys->i_play_status != val.i_int )
1739 p_intf->p_sys->i_play_status = val.i_int;
1740 [self playStatusUpdated: p_intf->p_sys->i_play_status];
1741 [o_embedded_window playStatusUpdated: p_intf->p_sys->i_play_status];
1743 vlc_object_release( p_input );
1747 vlc_object_release( p_input );
1751 p_intf->p_sys->i_play_status = END_S;
1752 [self playStatusUpdated: p_intf->p_sys->i_play_status];
1753 [o_embedded_window playStatusUpdated: p_intf->p_sys->i_play_status];
1754 [self setSubmenusEnabled: FALSE];
1757 if( p_intf->p_sys->b_volume_update )
1760 int i_volume_step = 0;
1761 o_text = [NSString stringWithFormat: _NS("Volume: %d%%"), i_lastShownVolume * 400 / AOUT_VOLUME_MAX];
1762 if( i_lastShownVolume != -1 )
1763 [self setScrollField:o_text stopAfter:1000000];
1764 i_volume_step = config_GetInt( p_intf->p_libvlc, "volume-step" );
1765 [o_volumeslider setFloatValue: (float)i_lastShownVolume / i_volume_step];
1766 [o_volumeslider setEnabled: TRUE];
1767 [[[self controls] fspanel] setVolumeLevel: (float)i_lastShownVolume / i_volume_step];
1768 p_intf->p_sys->b_mute = ( i_lastShownVolume == 0 );
1769 p_intf->p_sys->b_volume_update = FALSE;
1773 [self updateMessageDisplay];
1775 if( ((i_end_scroll != -1) && (mdate() > i_end_scroll)) || !p_input )
1776 [self resetScrollField];
1778 [interfaceTimer autorelease];
1780 interfaceTimer = [[NSTimer scheduledTimerWithTimeInterval: 0.3
1781 target: self selector: @selector(manageIntf:)
1782 userInfo: nil repeats: FALSE] retain];
1786 #pragma mark Interface update
1790 playlist_t * p_playlist = pl_Hold( p_intf );
1791 input_thread_t * p_input = playlist_CurrentInput( p_playlist );
1792 if( p_input != NULL )
1794 [o_controls setupVarMenuItem: o_mi_program target: (vlc_object_t *)p_input
1795 var: "program" selector: @selector(toggleVar:)];
1797 [o_controls setupVarMenuItem: o_mi_title target: (vlc_object_t *)p_input
1798 var: "title" selector: @selector(toggleVar:)];
1800 [o_controls setupVarMenuItem: o_mi_chapter target: (vlc_object_t *)p_input
1801 var: "chapter" selector: @selector(toggleVar:)];
1803 [o_controls setupVarMenuItem: o_mi_audiotrack target: (vlc_object_t *)p_input
1804 var: "audio-es" selector: @selector(toggleVar:)];
1806 [o_controls setupVarMenuItem: o_mi_videotrack target: (vlc_object_t *)p_input
1807 var: "video-es" selector: @selector(toggleVar:)];
1809 [o_controls setupVarMenuItem: o_mi_subtitle target: (vlc_object_t *)p_input
1810 var: "spu-es" selector: @selector(toggleVar:)];
1812 /* special case for "Open File" inside the subtitles menu item */
1813 if( [o_mi_videotrack isEnabled] == YES )
1814 [o_mi_subtitle setEnabled: YES];
1816 aout_instance_t * p_aout = input_GetAout( p_input );
1817 if( p_aout != NULL )
1819 [o_controls setupVarMenuItem: o_mi_channels target: (vlc_object_t *)p_aout
1820 var: "audio-channels" selector: @selector(toggleVar:)];
1822 [o_controls setupVarMenuItem: o_mi_device target: (vlc_object_t *)p_aout
1823 var: "audio-device" selector: @selector(toggleVar:)];
1825 [o_controls setupVarMenuItem: o_mi_visual target: (vlc_object_t *)p_aout
1826 var: "visual" selector: @selector(toggleVar:)];
1827 vlc_object_release( (vlc_object_t *)p_aout );
1830 vout_thread_t * p_vout = input_GetVout( p_input );
1832 if( p_vout != NULL )
1834 vlc_object_t * p_dec_obj;
1836 [o_controls setupVarMenuItem: o_mi_aspect_ratio target: (vlc_object_t *)p_vout
1837 var: "aspect-ratio" selector: @selector(toggleVar:)];
1839 [o_controls setupVarMenuItem: o_mi_crop target: (vlc_object_t *) p_vout
1840 var: "crop" selector: @selector(toggleVar:)];
1842 [o_controls setupVarMenuItem: o_mi_screen target: (vlc_object_t *)p_vout
1843 var: "video-device" selector: @selector(toggleVar:)];
1845 [o_controls setupVarMenuItem: o_mi_deinterlace target: (vlc_object_t *)p_vout
1846 var: "deinterlace" selector: @selector(toggleVar:)];
1849 /* FIXME Post processing. */
1850 p_dec_obj = (vlc_object_t *)vlc_object_find(
1851 (vlc_object_t *)p_vout,
1854 if( p_dec_obj != NULL )
1856 [o_controls setupVarMenuItem: o_mi_ffmpeg_pp target:
1857 (vlc_object_t *)p_dec_obj var:"ffmpeg-pp-q" selector:
1858 @selector(toggleVar:)];
1860 vlc_object_release(p_dec_obj);
1863 vlc_object_release( (vlc_object_t *)p_vout );
1865 vlc_object_release( p_input );
1867 pl_Release( p_intf );
1870 - (void)refreshVoutDeviceMenu:(NSNotification *)o_notification
1873 vout_thread_t * p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
1879 /* clean the menu before adding new entries */
1880 if( [o_mi_screen hasSubmenu] )
1882 y = [[o_mi_screen submenu] numberOfItems] - 1;
1883 msg_Dbg( VLCIntf, "%i items in submenu", y );
1886 msg_Dbg( VLCIntf, "removing item %i of %i", x, y );
1887 [[o_mi_screen submenu] removeItemAtIndex: x];
1892 [o_controls setupVarMenuItem: o_mi_screen target: (vlc_object_t *)p_vout
1893 var: "video-device" selector: @selector(toggleVar:)];
1894 vlc_object_release( (vlc_object_t *)p_vout );
1897 - (void)setScrollField:(NSString *)o_string stopAfter:(int)timeout
1900 i_end_scroll = mdate() + timeout;
1903 [o_scrollfield setStringValue: o_string];
1906 - (void)resetScrollField
1908 playlist_t * p_playlist = pl_Hold( p_intf );
1909 input_thread_t * p_input = playlist_CurrentInput( p_playlist );
1912 if( p_input && vlc_object_alive (p_input) )
1916 playlist_item_t * p_item = playlist_CurrentPlayingItem( p_playlist );
1917 if( input_item_GetNowPlaying( p_item->p_input ) )
1918 o_temp = [NSString stringWithUTF8String:input_item_GetNowPlaying( p_item->p_input )];
1920 o_temp = [NSString stringWithUTF8String:p_item->p_input->psz_name];
1922 [self setScrollField: o_temp stopAfter:-1];
1923 [[[self controls] fspanel] setStreamTitle: o_temp];
1924 vlc_object_release( p_input );
1925 pl_Release( p_intf );
1928 pl_Release( p_intf );
1929 [self setScrollField: _NS("VLC media player") stopAfter:-1];
1932 - (void)playStatusUpdated:(int)i_status
1934 if( i_status == PLAYING_S )
1936 [[[self controls] fspanel] setPause];
1937 [o_btn_play setImage: o_img_pause];
1938 [o_btn_play setAlternateImage: o_img_pause_pressed];
1939 [o_btn_play setToolTip: _NS("Pause")];
1940 [o_mi_play setTitle: _NS("Pause")];
1941 [o_dmi_play setTitle: _NS("Pause")];
1942 [o_vmi_play setTitle: _NS("Pause")];
1946 [[[self controls] fspanel] setPlay];
1947 [o_btn_play setImage: o_img_play];
1948 [o_btn_play setAlternateImage: o_img_play_pressed];
1949 [o_btn_play setToolTip: _NS("Play")];
1950 [o_mi_play setTitle: _NS("Play")];
1951 [o_dmi_play setTitle: _NS("Play")];
1952 [o_vmi_play setTitle: _NS("Play")];
1956 - (void)setSubmenusEnabled:(BOOL)b_enabled
1958 [o_mi_program setEnabled: b_enabled];
1959 [o_mi_title setEnabled: b_enabled];
1960 [o_mi_chapter setEnabled: b_enabled];
1961 [o_mi_audiotrack setEnabled: b_enabled];
1962 [o_mi_visual setEnabled: b_enabled];
1963 [o_mi_videotrack setEnabled: b_enabled];
1964 [o_mi_subtitle setEnabled: b_enabled];
1965 [o_mi_channels setEnabled: b_enabled];
1966 [o_mi_deinterlace setEnabled: b_enabled];
1967 [o_mi_ffmpeg_pp setEnabled: b_enabled];
1968 [o_mi_device setEnabled: b_enabled];
1969 [o_mi_screen setEnabled: b_enabled];
1970 [o_mi_aspect_ratio setEnabled: b_enabled];
1971 [o_mi_crop setEnabled: b_enabled];
1972 [o_mi_teletext setEnabled: b_enabled];
1975 - (IBAction)timesliderUpdate:(id)sender
1978 playlist_t * p_playlist;
1979 input_thread_t * p_input;
1981 switch( [[NSApp currentEvent] type] )
1984 case NSLeftMouseDown:
1985 case NSLeftMouseDragged:
1986 f_updated = [sender floatValue];
1992 p_playlist = pl_Hold( p_intf );
1993 p_input = playlist_CurrentInput( p_playlist );
1994 if( p_input != NULL )
1999 char psz_time[MSTRTIME_MAX_SIZE];
2001 pos.f_float = f_updated / 10000.;
2002 var_Set( p_input, "position", pos );
2003 [o_timeslider setFloatValue: f_updated];
2005 var_Get( p_input, "time", &time );
2007 mtime_t dur = input_item_GetDuration( input_GetItem( p_input ) );
2008 if( b_time_remaining && dur != -1 )
2010 o_time = [NSString stringWithFormat: @"-%s", secstotimestr( psz_time, ((dur - time.i_time) / 1000000) )];
2013 o_time = [NSString stringWithUTF8String: secstotimestr( psz_time, (time.i_time / 1000000) )];
2015 [o_timefield setStringValue: o_time];
2016 [[[self controls] fspanel] setStreamPos: f_updated andTime: o_time];
2017 [o_embedded_window setTime: o_time position: f_updated];
2018 vlc_object_release( p_input );
2020 pl_Release( p_intf );
2023 - (IBAction)timeFieldWasClicked:(id)sender
2025 b_time_remaining = !b_time_remaining;
2030 #pragma mark Recent Items
2032 - (IBAction)clearRecentItems:(id)sender
2034 [[NSDocumentController sharedDocumentController]
2035 clearRecentDocuments: nil];
2038 - (void)openRecentItem:(id)sender
2040 [self application: nil openFile: [sender title]];
2046 - (IBAction)intfOpenFile:(id)sender
2048 if( !nib_open_loaded )
2050 nib_open_loaded = [NSBundle loadNibNamed:@"Open" owner: NSApp];
2051 [o_open awakeFromNib];
2058 - (IBAction)intfOpenFileGeneric:(id)sender
2060 if( !nib_open_loaded )
2062 nib_open_loaded = [NSBundle loadNibNamed:@"Open" owner: NSApp];
2063 [o_open awakeFromNib];
2064 [o_open openFileGeneric];
2066 [o_open openFileGeneric];
2070 - (IBAction)intfOpenDisc:(id)sender
2072 if( !nib_open_loaded )
2074 nib_open_loaded = [NSBundle loadNibNamed:@"Open" owner: NSApp];
2075 [o_open awakeFromNib];
2082 - (IBAction)intfOpenNet:(id)sender
2084 if( !nib_open_loaded )
2086 nib_open_loaded = [NSBundle loadNibNamed:@"Open" owner: NSApp];
2087 [o_open awakeFromNib];
2094 - (IBAction)intfOpenCapture:(id)sender
2096 if( !nib_open_loaded )
2098 nib_open_loaded = [NSBundle loadNibNamed:@"Open" owner: NSApp];
2099 [o_open awakeFromNib];
2100 [o_open openCapture];
2102 [o_open openCapture];
2106 - (IBAction)showWizard:(id)sender
2108 if( !nib_wizard_loaded )
2110 nib_wizard_loaded = [NSBundle loadNibNamed:@"Wizard" owner: NSApp];
2111 [o_wizard initStrings];
2112 [o_wizard resetWizard];
2113 [o_wizard showWizard];
2115 [o_wizard resetWizard];
2116 [o_wizard showWizard];
2120 - (IBAction)showVLM:(id)sender
2122 if( !nib_vlm_loaded )
2123 nib_vlm_loaded = [NSBundle loadNibNamed:@"VLM" owner: NSApp];
2125 [o_vlm showVLMWindow];
2128 - (IBAction)showExtended:(id)sender
2130 if( o_extended == nil )
2131 o_extended = [[VLCExtended alloc] init];
2133 if( !nib_extended_loaded )
2134 nib_extended_loaded = [NSBundle loadNibNamed:@"Extended" owner: NSApp];
2136 [o_extended showPanel];
2139 - (IBAction)showBookmarks:(id)sender
2141 /* we need the wizard-nib for the bookmarks's extract functionality */
2142 if( !nib_wizard_loaded )
2144 nib_wizard_loaded = [NSBundle loadNibNamed:@"Wizard" owner: NSApp];
2145 [o_wizard initStrings];
2148 if( !nib_bookmarks_loaded )
2149 nib_bookmarks_loaded = [NSBundle loadNibNamed:@"Bookmarks" owner: NSApp];
2151 [o_bookmarks showBookmarks];
2154 - (IBAction)viewPreferences:(id)sender
2156 if( !nib_prefs_loaded )
2158 nib_prefs_loaded = [NSBundle loadNibNamed:@"Preferences" owner: NSApp];
2159 o_sprefs = [[VLCSimplePrefs alloc] init];
2160 o_prefs= [[VLCPrefs alloc] init];
2163 [o_sprefs showSimplePrefs];
2169 - (IBAction)checkForUpdate:(id)sender
2172 if( !nib_update_loaded )
2173 nib_update_loaded = [NSBundle loadNibNamed:@"Update" owner: NSApp];
2174 [o_update showUpdateWindow];
2176 msg_Err( VLCIntf, "Update checker wasn't enabled in this build" );
2177 dialog_FatalWait( VLCIntf, _("Update check failed"), _("Checking for updates was not enabled in this build.") );
2182 #pragma mark Help and Docs
2184 - (IBAction)viewAbout:(id)sender
2186 if( !nib_about_loaded )
2187 nib_about_loaded = [NSBundle loadNibNamed:@"About" owner: NSApp];
2189 [o_about showAbout];
2192 - (IBAction)showLicense:(id)sender
2194 if( !nib_about_loaded )
2195 nib_about_loaded = [NSBundle loadNibNamed:@"About" owner: NSApp];
2197 [o_about showGPL: sender];
2200 - (IBAction)viewHelp:(id)sender
2202 if( !nib_about_loaded )
2204 nib_about_loaded = [NSBundle loadNibNamed:@"About" owner: NSApp];
2211 - (IBAction)openReadMe:(id)sender
2213 NSString * o_path = [[NSBundle mainBundle]
2214 pathForResource: @"README.MacOSX" ofType: @"rtf"];
2216 [[NSWorkspace sharedWorkspace] openFile: o_path
2217 withApplication: @"TextEdit"];
2220 - (IBAction)openDocumentation:(id)sender
2222 NSURL * o_url = [NSURL URLWithString:
2223 @"http://www.videolan.org/doc/"];
2225 [[NSWorkspace sharedWorkspace] openURL: o_url];
2228 - (IBAction)openWebsite:(id)sender
2230 NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org/"];
2232 [[NSWorkspace sharedWorkspace] openURL: o_url];
2235 - (IBAction)openForum:(id)sender
2237 NSURL * o_url = [NSURL URLWithString: @"http://forum.videolan.org/"];
2239 [[NSWorkspace sharedWorkspace] openURL: o_url];
2242 - (IBAction)openDonate:(id)sender
2244 NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org/contribute.html#paypal"];
2246 [[NSWorkspace sharedWorkspace] openURL: o_url];
2250 #pragma mark Crash Log
2251 - (void)sendCrashLog:(NSString *)crashLog withUserComment:(NSString *)userComment
2253 NSString *urlStr = @"http://jones.videolan.org/crashlog/sendcrashreport.php";
2254 NSURL *url = [NSURL URLWithString:urlStr];
2256 NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
2257 [req setHTTPMethod:@"POST"];
2260 if( [o_crashrep_includeEmail_ckb state] == NSOnState )
2262 ABPerson * contact = [[ABAddressBook sharedAddressBook] me];
2263 ABMultiValue *emails = [contact valueForProperty:kABEmailProperty];
2264 email = [emails valueAtIndex:[emails indexForIdentifier:
2265 [emails primaryIdentifier]]];
2268 email = [NSString string];
2271 postBody = [NSString stringWithFormat:@"CrashLog=%@&Comment=%@&Email=%@\r\n",
2272 [crashLog stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
2273 [userComment stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
2274 [email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
2276 [req setHTTPBody:[postBody dataUsingEncoding:NSUTF8StringEncoding]];
2278 /* Released from delegate */
2279 crashLogURLConnection = [[NSURLConnection alloc] initWithRequest:req delegate:self];
2282 - (void)connectionDidFinishLoading:(NSURLConnection *)connection
2284 NSRunInformationalAlertPanel(_NS("Crash Report successfully sent"),
2285 _NS("Thanks for your report!"),
2286 _NS("OK"), nil, nil, nil);
2287 [crashLogURLConnection release];
2288 crashLogURLConnection = nil;
2291 - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
2293 NSRunCriticalAlertPanel(_NS("Error when sending the Crash Report"), [error localizedDescription], @"OK", nil, nil);
2294 [crashLogURLConnection release];
2295 crashLogURLConnection = nil;
2298 - (NSString *)latestCrashLogPathPreviouslySeen:(BOOL)previouslySeen
2300 NSString * crashReporter = [@"~/Library/Logs/CrashReporter" stringByExpandingTildeInPath];
2301 NSDirectoryEnumerator *direnum = [[NSFileManager defaultManager] enumeratorAtPath:crashReporter];
2303 NSString * latestLog = nil;
2304 int year = !previouslySeen ? [[NSUserDefaults standardUserDefaults] integerForKey:@"LatestCrashReportYear"] : 0;
2305 int month = !previouslySeen ? [[NSUserDefaults standardUserDefaults] integerForKey:@"LatestCrashReportMonth"]: 0;
2306 int day = !previouslySeen ? [[NSUserDefaults standardUserDefaults] integerForKey:@"LatestCrashReportDay"] : 0;
2307 int hours = !previouslySeen ? [[NSUserDefaults standardUserDefaults] integerForKey:@"LatestCrashReportHours"]: 0;
2309 while (fname = [direnum nextObject])
2311 [direnum skipDescendents];
2312 if([fname hasPrefix:@"VLC"] && [fname hasSuffix:@"crash"])
2314 NSArray * compo = [fname componentsSeparatedByString:@"_"];
2315 if( [compo count] < 3 ) continue;
2316 compo = [[compo objectAtIndex:1] componentsSeparatedByString:@"-"];
2317 if( [compo count] < 4 ) continue;
2320 if( year < [[compo objectAtIndex:0] intValue] ||
2321 (year ==[[compo objectAtIndex:0] intValue] &&
2322 (month < [[compo objectAtIndex:1] intValue] ||
2323 (month ==[[compo objectAtIndex:1] intValue] &&
2324 (day < [[compo objectAtIndex:2] intValue] ||
2325 (day ==[[compo objectAtIndex:2] intValue] &&
2326 hours < [[compo objectAtIndex:3] intValue] ))))))
2328 year = [[compo objectAtIndex:0] intValue];
2329 month = [[compo objectAtIndex:1] intValue];
2330 day = [[compo objectAtIndex:2] intValue];
2331 hours = [[compo objectAtIndex:3] intValue];
2332 latestLog = [crashReporter stringByAppendingPathComponent:fname];
2337 if(!(latestLog && [[NSFileManager defaultManager] fileExistsAtPath:latestLog]))
2340 if( !previouslySeen )
2342 [[NSUserDefaults standardUserDefaults] setInteger:year forKey:@"LatestCrashReportYear"];
2343 [[NSUserDefaults standardUserDefaults] setInteger:month forKey:@"LatestCrashReportMonth"];
2344 [[NSUserDefaults standardUserDefaults] setInteger:day forKey:@"LatestCrashReportDay"];
2345 [[NSUserDefaults standardUserDefaults] setInteger:hours forKey:@"LatestCrashReportHours"];
2350 - (NSString *)latestCrashLogPath
2352 return [self latestCrashLogPathPreviouslySeen:YES];
2355 - (void)lookForCrashLog
2357 NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
2358 // This pref key doesn't exists? this VLC is an upgrade, and this crash log come from previous version
2359 BOOL areCrashLogsTooOld = ![[NSUserDefaults standardUserDefaults] integerForKey:@"LatestCrashReportYear"];
2360 NSString * latestLog = [self latestCrashLogPathPreviouslySeen:NO];
2361 if( latestLog && !areCrashLogsTooOld )
2362 [NSApp runModalForWindow: o_crashrep_win];
2366 - (IBAction)crashReporterAction:(id)sender
2368 if( sender == o_crashrep_send_btn )
2369 [self sendCrashLog:[NSString stringWithContentsOfFile: [self latestCrashLogPath] encoding: NSUTF8StringEncoding error: NULL] withUserComment: [o_crashrep_fld string]];
2372 [o_crashrep_win orderOut: sender];
2375 - (IBAction)openCrashLog:(id)sender
2377 NSString * latestLog = [self latestCrashLogPath];
2380 [[NSWorkspace sharedWorkspace] openFile: latestLog withApplication: @"Console"];
2384 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.") );
2389 #pragma mark Remove old prefs
2391 - (void)_removeOldPreferences
2393 static NSString * kVLCPreferencesVersion = @"VLCPreferencesVersion";
2394 static const int kCurrentPreferencesVersion = 1;
2395 int version = [[NSUserDefaults standardUserDefaults] integerForKey:kVLCPreferencesVersion];
2396 if( version >= kCurrentPreferencesVersion ) return;
2398 NSArray *libraries = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,
2399 NSUserDomainMask, YES);
2400 if( !libraries || [libraries count] == 0) return;
2401 NSString * preferences = [[libraries objectAtIndex:0] stringByAppendingPathComponent:@"Preferences"];
2403 /* File not found, don't attempt anything */
2404 if(![[NSFileManager defaultManager] fileExistsAtPath:[preferences stringByAppendingPathComponent:@"VLC"]] &&
2405 ![[NSFileManager defaultManager] fileExistsAtPath:[preferences stringByAppendingPathComponent:@"org.videolan.vlc.plist"]] )
2407 [[NSUserDefaults standardUserDefaults] setInteger:kCurrentPreferencesVersion forKey:kVLCPreferencesVersion];
2411 int res = NSRunInformationalAlertPanel(_NS("Remove old preferences?"),
2412 _NS("We just found an older version of VLC's preferences files."),
2413 _NS("Move To Trash and Relaunch VLC"), _NS("Ignore"), nil, nil);
2414 if( res != NSOKButton )
2416 [[NSUserDefaults standardUserDefaults] setInteger:kCurrentPreferencesVersion forKey:kVLCPreferencesVersion];
2420 NSArray * ourPreferences = [NSArray arrayWithObjects:@"org.videolan.vlc.plist", @"VLC", nil];
2422 /* Move the file to trash so that user can find them later */
2423 [[NSWorkspace sharedWorkspace] performFileOperation:NSWorkspaceRecycleOperation source:preferences destination:nil files:ourPreferences tag:0];
2425 /* really reset the defaults from now on */
2426 [NSUserDefaults resetStandardUserDefaults];
2428 [[NSUserDefaults standardUserDefaults] setInteger:kCurrentPreferencesVersion forKey:kVLCPreferencesVersion];
2429 [[NSUserDefaults standardUserDefaults] synchronize];
2432 const char * path = [[[NSBundle mainBundle] executablePath] UTF8String];
2434 /* For some reason we need to fork(), not just execl(), which reports a ENOTSUP then. */
2440 execl(path, path, NULL);
2444 #pragma mark Errors, warnings and messages
2446 - (IBAction)viewErrorsAndWarnings:(id)sender
2448 [[[self coreDialogProvider] errorPanel] showPanel];
2451 - (IBAction)showMessagesPanel:(id)sender
2453 [o_msgs_panel makeKeyAndOrderFront: sender];
2456 - (IBAction)showInformationPanel:(id)sender
2458 if(! nib_info_loaded )
2459 nib_info_loaded = [NSBundle loadNibNamed:@"MediaInfo" owner: NSApp];
2464 - (void)windowDidBecomeKey:(NSNotification *)o_notification
2466 if( [o_notification object] == o_msgs_panel )
2467 [self updateMessageDisplay];
2470 - (void)updateMessageDisplay
2472 if( [o_msgs_panel isVisible] && b_msg_arr_changed )
2475 NSEnumerator * o_enum;
2477 [o_messages setString: @""];
2481 o_enum = [o_msg_arr objectEnumerator];
2483 while( ( o_msg = [o_enum nextObject] ) != nil )
2485 [o_messages insertText: o_msg];
2488 b_msg_arr_changed = NO;
2489 [o_msg_lock unlock];
2493 - (void)libvlcMessageReceived: (NSNotification *)o_notification
2495 NSColor *o_white = [NSColor whiteColor];
2496 NSColor *o_red = [NSColor redColor];
2497 NSColor *o_yellow = [NSColor yellowColor];
2498 NSColor *o_gray = [NSColor grayColor];
2500 NSColor * pp_color[4] = { o_white, o_red, o_yellow, o_gray };
2501 static const char * ppsz_type[4] = { ": ", " error: ",
2502 " warning: ", " debug: " };
2505 NSDictionary *o_attr;
2506 NSAttributedString *o_msg_color;
2508 int i_type = [[[o_notification userInfo] objectForKey: @"Type"] intValue];
2512 if( [o_msg_arr count] + 2 > 600 )
2514 [o_msg_arr removeObjectAtIndex: 0];
2515 [o_msg_arr removeObjectAtIndex: 1];
2518 o_attr = [NSDictionary dictionaryWithObject: o_gray
2519 forKey: NSForegroundColorAttributeName];
2520 o_msg = [NSString stringWithFormat: @"%@%s",
2521 [[o_notification userInfo] objectForKey: @"Module"],
2523 o_msg_color = [[NSAttributedString alloc]
2524 initWithString: o_msg attributes: o_attr];
2525 [o_msg_arr addObject: [o_msg_color autorelease]];
2527 o_attr = [NSDictionary dictionaryWithObject: pp_color[i_type]
2528 forKey: NSForegroundColorAttributeName];
2529 o_msg = [[[o_notification userInfo] objectForKey: @"Message"] stringByAppendingString: @"\n"];
2530 o_msg_color = [[NSAttributedString alloc]
2531 initWithString: o_msg attributes: o_attr];
2532 [o_msg_arr addObject: [o_msg_color autorelease]];
2534 b_msg_arr_changed = YES;
2535 [o_msg_lock unlock];
2538 - (IBAction)saveDebugLog:(id)sender
2540 NSOpenPanel * saveFolderPanel = [[NSSavePanel alloc] init];
2542 [saveFolderPanel setCanChooseDirectories: NO];
2543 [saveFolderPanel setCanChooseFiles: YES];
2544 [saveFolderPanel setCanSelectHiddenExtension: NO];
2545 [saveFolderPanel setCanCreateDirectories: YES];
2546 [saveFolderPanel setRequiredFileType: @"rtfd"];
2547 [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];
2550 - (void)saveDebugLogAsRTF: (NSSavePanel *)sheet returnCode: (int)returnCode contextInfo: (void *)contextInfo
2553 if( returnCode == NSOKButton )
2555 b_returned = [o_messages writeRTFDToFile: [sheet filename] atomically: YES];
2557 msg_Warn( p_intf, "Error while saving the debug log" );
2562 #pragma mark Playlist toggling
2564 - (IBAction)togglePlaylist:(id)sender
2566 NSRect contentRect = [o_window contentRectForFrameRect:[o_window frame]];
2567 NSRect o_rect = [o_window contentRectForFrameRect:[o_window frame]];
2568 /*First, check if the playlist is visible*/
2569 if( contentRect.size.height <= 169. )
2571 o_restore_rect = contentRect;
2572 b_restore_size = true;
2573 b_small_window = YES; /* we know we are small, make sure this is actually set (see case below) */
2576 if( o_size_with_playlist.height > 169. )
2577 o_rect.size.height = o_size_with_playlist.height;
2579 o_rect.size.height = 500.;
2581 if( o_size_with_playlist.width >= [o_window contentMinSize].width )
2582 o_rect.size.width = o_size_with_playlist.width;
2584 o_rect.size.width = [o_window contentMinSize].width;
2586 o_rect.origin.x = contentRect.origin.x;
2587 o_rect.origin.y = contentRect.origin.y - o_rect.size.height +
2588 [o_window contentMinSize].height;
2590 o_rect = [o_window frameRectForContentRect:o_rect];
2592 NSRect screenRect = [[o_window screen] visibleFrame];
2593 if( !NSContainsRect( screenRect, o_rect ) ) {
2594 if( NSMaxX(o_rect) > NSMaxX(screenRect) )
2595 o_rect.origin.x = ( NSMaxX(screenRect) - o_rect.size.width );
2596 if( NSMinY(o_rect) < NSMinY(screenRect) )
2597 o_rect.origin.y = ( NSMinY(screenRect) );
2600 [o_btn_playlist setState: YES];
2604 NSSize curSize = o_rect.size;
2605 if( b_restore_size )
2607 o_rect = o_restore_rect;
2608 if( o_rect.size.height < [o_window contentMinSize].height )
2609 o_rect.size.height = [o_window contentMinSize].height;
2610 if( o_rect.size.width < [o_window contentMinSize].width )
2611 o_rect.size.width = [o_window contentMinSize].width;
2615 NSRect contentRect = [o_window contentRectForFrameRect:[o_window frame]];
2617 o_rect.size.height = [o_window contentMinSize].height;
2618 o_rect.size.width = [o_window contentMinSize].width;
2619 o_rect.origin.x = contentRect.origin.x;
2620 /* Calculate the position of the lower right corner after resize */
2621 o_rect.origin.y = contentRect.origin.y +
2622 contentRect.size.height - [o_window contentMinSize].height;
2625 [o_playlist_view setAutoresizesSubviews: NO];
2626 [o_playlist_view removeFromSuperview];
2627 [o_btn_playlist setState: NO];
2628 b_small_window = NO; /* we aren't small here just yet. we are doing an animated resize after this */
2629 o_rect = [o_window frameRectForContentRect:o_rect];
2632 [o_window setFrame: o_rect display:YES animate: YES];
2635 - (void)updateTogglePlaylistState
2637 if( [o_window contentRectForFrameRect:[o_window frame]].size.height <= 169. )
2638 [o_btn_playlist setState: NO];
2640 [o_btn_playlist setState: YES];
2642 [[self playlist] outlineViewSelectionDidChange: NULL];
2645 - (NSSize)windowWillResize:(NSWindow *)sender toSize:(NSSize)proposedFrameSize
2648 /* Not triggered on a window resize or maxification of the window. only by window mouse dragging resize */
2650 /*Stores the size the controller one resize, to be able to restore it when
2651 toggling the playlist*/
2652 o_size_with_playlist = proposedFrameSize;
2655 rect.size = proposedFrameSize;
2656 if( [o_window contentRectForFrameRect:rect].size.height <= 169. )
2658 if( b_small_window == NO )
2660 /* if large and going to small then hide */
2661 b_small_window = YES;
2662 [o_playlist_view setAutoresizesSubviews: NO];
2663 [o_playlist_view removeFromSuperview];
2665 return NSMakeSize( proposedFrameSize.width, [o_window minSize].height);
2667 return proposedFrameSize;
2670 - (void)windowDidMove:(NSNotification *)notif
2672 b_restore_size = false;
2675 - (void)windowDidResize:(NSNotification *)notif
2677 if( [o_window contentRectForFrameRect:[o_window frame]].size.height > 169. && b_small_window )
2679 /* If large and coming from small then show */
2680 [o_playlist_view setAutoresizesSubviews: YES];
2681 NSRect contentRect = [o_window contentRectForFrameRect:[o_window frame]];
2682 [o_playlist_view setFrame: NSMakeRect( 0, 0, contentRect.size.width, contentRect.size.height - [o_window contentMinSize].height )];
2683 [o_playlist_view setNeedsDisplay:YES];
2684 [[o_window contentView] addSubview: o_playlist_view];
2685 b_small_window = NO;
2687 [self updateTogglePlaylistState];
2694 @implementation VLCMain (NSMenuValidation)
2696 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
2698 NSString *o_title = [o_mi title];
2699 BOOL bEnabled = TRUE;
2701 /* Recent Items Menu */
2702 if( [o_title isEqualToString: _NS("Clear Menu")] )
2704 NSMenu * o_menu = [o_mi_open_recent submenu];
2705 int i_nb_items = [o_menu numberOfItems];
2706 NSArray * o_docs = [[NSDocumentController sharedDocumentController]
2707 recentDocumentURLs];
2708 UInt32 i_nb_docs = [o_docs count];
2710 if( i_nb_items > 1 )
2712 while( --i_nb_items )
2714 [o_menu removeItemAtIndex: 0];
2723 [o_menu insertItem: [NSMenuItem separatorItem] atIndex: 0];
2729 o_url = [o_docs objectAtIndex: i_nb_docs];
2731 if( [o_url isFileURL] )
2733 o_doc = [o_url path];
2737 o_doc = [o_url absoluteString];
2740 [o_menu insertItemWithTitle: o_doc
2741 action: @selector(openRecentItem:)
2742 keyEquivalent: @"" atIndex: 0];
2744 if( i_nb_docs == 0 )
2760 @implementation VLCMain (Internal)
2762 - (void)handlePortMessage:(NSPortMessage *)o_msg
2767 NSInvocation * o_inv;
2768 NSConditionLock * o_lock;
2770 o_data = [[o_msg components] lastObject];
2771 o_inv = *((NSInvocation **)[o_data bytes]);
2772 [o_inv getArgument: &o_value atIndex: 2];
2773 val = (id **)[o_value pointerValue];
2774 [o_inv setArgument: val[1] atIndex: 2];
2779 [o_lock unlockWithCondition: 1];
2784 /*****************************************************************************
2785 * VLCApplication interface
2786 * exclusively used to implement media key support on Al Apple keyboards
2787 * b_justJumped is required as the keyboard send its events faster than
2788 * the user can actually jump through his media
2789 *****************************************************************************/
2791 @implementation VLCApplication
2793 - (void)sendEvent: (NSEvent*)event
2795 if( [event type] == NSSystemDefined && [event subtype] == 8 )
2797 int keyCode = (([event data1] & 0xFFFF0000) >> 16);
2798 int keyFlags = ([event data1] & 0x0000FFFF);
2799 int keyState = (((keyFlags & 0xFF00) >> 8)) == 0xA;
2800 int keyRepeat = (keyFlags & 0x1);
2802 if( keyCode == NX_KEYTYPE_PLAY && keyState == 0 )
2803 var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_PLAY_PAUSE );
2805 if( keyCode == NX_KEYTYPE_FAST && !b_justJumped )
2807 if( keyState == 0 && keyRepeat == 0 )
2809 var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_NEXT );
2811 else if( keyRepeat == 1 )
2813 var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_JUMP_FORWARD_SHORT );
2815 [self performSelector:@selector(resetJump)
2821 if( keyCode == NX_KEYTYPE_REWIND && !b_justJumped )
2823 if( keyState == 0 && keyRepeat == 0 )
2825 var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_PREV );
2827 else if( keyRepeat == 1 )
2829 var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_JUMP_BACKWARD_SHORT );
2831 [self performSelector:@selector(resetJump)
2837 [super sendEvent: event];