1 /*****************************************************************************
2 * intf.m: MacOS X interface module
3 *****************************************************************************
4 * Copyright (C) 2002-2008 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 */
44 #import "playlistinfo.h"
51 #import "interaction.h"
52 #import "embeddedwindow.h"
54 #import "AppleRemote.h"
56 #import "simple_prefs.h"
59 #import <vlc_interface.h>
61 /*****************************************************************************
63 *****************************************************************************/
64 static void Run ( intf_thread_t *p_intf );
67 /*****************************************************************************
68 * VLCApplication implementation (this hack is really disgusting now,
70 *****************************************************************************/
71 @interface VLCApplication : NSApplication
73 libvlc_int_t *o_libvlc;
75 - (void)setVLC: (libvlc_int_t *)p_libvlc;
79 @implementation VLCApplication
80 - (void)setVLC: (libvlc_int_t *) p_libvlc
84 - (void)terminate: (id)sender
86 vlc_object_kill( o_libvlc );
87 [super terminate: sender];
91 /*****************************************************************************
92 * OpenIntf: initialize interface
93 *****************************************************************************/
94 int OpenIntf ( vlc_object_t *p_this )
96 intf_thread_t *p_intf = (intf_thread_t*) p_this;
98 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
99 if( p_intf->p_sys == NULL )
104 memset( p_intf->p_sys, 0, sizeof( *p_intf->p_sys ) );
106 p_intf->p_sys->o_pool = [[NSAutoreleasePool alloc] init];
108 p_intf->p_sys->p_sub = msg_Subscribe( p_intf );
109 p_intf->pf_run = Run;
110 p_intf->b_should_run_on_first_thread = true;
115 /*****************************************************************************
116 * CloseIntf: destroy interface
117 *****************************************************************************/
118 void CloseIntf ( vlc_object_t *p_this )
120 intf_thread_t *p_intf = (intf_thread_t*) p_this;
122 [[VLCMain sharedInstance] setIntf: nil];
124 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
126 [p_intf->p_sys->o_pool release];
128 free( p_intf->p_sys );
131 /*****************************************************************************
133 *****************************************************************************/
136 static void Run( intf_thread_t *p_intf )
140 /* Do it again - for some unknown reason, vlc_thread_create() often
141 * fails to go to real-time priority with the first launched thread
143 vlc_thread_set_priority( p_intf, VLC_THREAD_PRIORITY_LOW );
145 /* Make sure the "force quit" menu item does quit instantly.
146 * VLC overrides SIGTERM which is sent by the "force quit"
147 * menu item to make sure deamon mode quits gracefully, so
148 * we un-override SIGTERM here. */
150 sigaddset( &set, SIGTERM );
151 pthread_sigmask( SIG_UNBLOCK, &set, NULL );
153 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
155 /* Install a jmpbuffer to where we can go back before the NSApp exit
156 * see applicationWillTerminate: */
157 /* We need that code to run on main thread */
158 [VLCApplication sharedApplication];
159 [NSApp setVLC: p_intf->p_libvlc];
161 [[VLCMain sharedInstance] setIntf: p_intf];
162 [NSBundle loadNibNamed: @"MainMenu" owner: NSApp];
164 /* Install a jmpbuffer to where we can go back before the NSApp exit
165 * see applicationWillTerminate: */
166 if(setjmp(jmpbuffer) == 0)
172 /*****************************************************************************
173 * ManageThread: An ugly thread that polls
174 *****************************************************************************/
175 static void * ManageThread( void *user_data )
184 /*****************************************************************************
185 * playlistChanged: Callback triggered by the intf-change playlist
186 * variable, to let the intf update the playlist.
187 *****************************************************************************/
188 static int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,
189 vlc_value_t old_val, vlc_value_t new_val, void *param )
191 intf_thread_t * p_intf = VLCIntf;
192 p_intf->p_sys->b_intf_update = true;
193 p_intf->p_sys->b_playlist_update = true;
194 p_intf->p_sys->b_playmode_update = true;
195 p_intf->p_sys->b_current_title_update = true;
199 /*****************************************************************************
200 * ShowController: Callback triggered by the show-intf playlist variable
201 * through the ShowIntf-control-intf, to let us show the controller-win;
202 * usually when in fullscreen-mode
203 *****************************************************************************/
204 static int ShowController( vlc_object_t *p_this, const char *psz_variable,
205 vlc_value_t old_val, vlc_value_t new_val, void *param )
207 intf_thread_t * p_intf = VLCIntf;
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 p_intf->p_sys->b_fullscreen_update = true;
224 /*****************************************************************************
225 * InteractCallback: Callback triggered by the interaction
226 * variable, to let the intf display error and interaction dialogs
227 *****************************************************************************/
228 static int InteractCallback( vlc_object_t *p_this, const char *psz_variable,
229 vlc_value_t old_val, vlc_value_t new_val, void *param )
231 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
232 VLCMain *interface = (VLCMain *)param;
233 interaction_dialog_t *p_dialog = (interaction_dialog_t *)(new_val.p_address);
234 NSValue *o_value = [NSValue valueWithPointer:p_dialog];
236 [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCNewInteractionEventNotification" object:[interface getInteractionList]
237 userInfo:[NSDictionary dictionaryWithObject:o_value forKey:@"VLCDialogPointer"]];
246 unsigned int i_vlckey;
247 } nskeys_to_vlckeys[] =
249 { NSUpArrowFunctionKey, KEY_UP },
250 { NSDownArrowFunctionKey, KEY_DOWN },
251 { NSLeftArrowFunctionKey, KEY_LEFT },
252 { NSRightArrowFunctionKey, KEY_RIGHT },
253 { NSF1FunctionKey, KEY_F1 },
254 { NSF2FunctionKey, KEY_F2 },
255 { NSF3FunctionKey, KEY_F3 },
256 { NSF4FunctionKey, KEY_F4 },
257 { NSF5FunctionKey, KEY_F5 },
258 { NSF6FunctionKey, KEY_F6 },
259 { NSF7FunctionKey, KEY_F7 },
260 { NSF8FunctionKey, KEY_F8 },
261 { NSF9FunctionKey, KEY_F9 },
262 { NSF10FunctionKey, KEY_F10 },
263 { NSF11FunctionKey, KEY_F11 },
264 { NSF12FunctionKey, KEY_F12 },
265 { NSHomeFunctionKey, KEY_HOME },
266 { NSEndFunctionKey, KEY_END },
267 { NSPageUpFunctionKey, KEY_PAGEUP },
268 { NSPageDownFunctionKey, KEY_PAGEDOWN },
269 { NSTabCharacter, KEY_TAB },
270 { NSCarriageReturnCharacter, KEY_ENTER },
271 { NSEnterCharacter, KEY_ENTER },
272 { NSBackspaceCharacter, KEY_BACKSPACE },
273 { (unichar) ' ', KEY_SPACE },
274 { (unichar) 0x1b, KEY_ESC },
278 unichar VLCKeyToCocoa( unsigned int i_key )
282 for( i = 0; nskeys_to_vlckeys[i].i_vlckey != 0; i++ )
284 if( nskeys_to_vlckeys[i].i_vlckey == (i_key & ~KEY_MODIFIER) )
286 return nskeys_to_vlckeys[i].i_nskey;
289 return (unichar)(i_key & ~KEY_MODIFIER);
292 unsigned int CocoaKeyToVLC( unichar i_key )
296 for( i = 0; nskeys_to_vlckeys[i].i_nskey != 0; i++ )
298 if( nskeys_to_vlckeys[i].i_nskey == i_key )
300 return nskeys_to_vlckeys[i].i_vlckey;
303 return (unsigned int)i_key;
306 unsigned int VLCModifiersToCocoa( unsigned int i_key )
308 unsigned int new = 0;
309 if( i_key & KEY_MODIFIER_COMMAND )
310 new |= NSCommandKeyMask;
311 if( i_key & KEY_MODIFIER_ALT )
312 new |= NSAlternateKeyMask;
313 if( i_key & KEY_MODIFIER_SHIFT )
314 new |= NSShiftKeyMask;
315 if( i_key & KEY_MODIFIER_CTRL )
316 new |= NSControlKeyMask;
320 /*****************************************************************************
321 * VLCMain implementation
322 *****************************************************************************/
323 @implementation VLCMain
325 static VLCMain *_o_sharedMainInstance = nil;
327 + (VLCMain *)sharedInstance
329 return _o_sharedMainInstance ? _o_sharedMainInstance : [[self alloc] init];
334 if( _o_sharedMainInstance)
337 return _o_sharedMainInstance;
340 _o_sharedMainInstance = [super init];
342 o_about = [[VLAboutBox alloc] init];
344 o_open = [[VLCOpen alloc] init];
345 o_wizard = [[VLCWizard alloc] init];
347 o_bookmarks = [[VLCBookmarks alloc] init];
348 o_embedded_list = [[VLCEmbeddedList alloc] init];
349 o_interaction_list = [[VLCInteractionList alloc] init];
350 o_info = [[VLCInfo alloc] init];
352 o_update = [[VLCUpdate alloc] init];
355 i_lastShownVolume = -1;
357 o_remote = [[AppleRemote alloc] init];
358 [o_remote setClickCountEnabledButtons: kRemoteButtonPlay];
359 [o_remote setDelegate: _o_sharedMainInstance];
361 o_eyetv = [[VLCEyeTVController alloc] init];
363 /* announce our launch to a potential eyetv plugin */
364 [[NSDistributedNotificationCenter defaultCenter] postNotificationName: @"VLCOSXGUIInit"
365 object: @"VLCEyeTVSupport"
367 deliverImmediately: YES];
369 return _o_sharedMainInstance;
372 - (void)setIntf: (intf_thread_t *)p_mainintf {
376 - (intf_thread_t *)getIntf {
382 unsigned int i_key = 0;
383 playlist_t *p_playlist;
386 /* Check if we already did this once. Opening the other nibs calls it too, because VLCMain is the owner */
387 if( nib_main_loaded ) return;
390 [o_window setExcludedFromWindowsMenu: TRUE];
391 [o_msgs_panel setExcludedFromWindowsMenu: TRUE];
392 [o_msgs_panel setDelegate: self];
394 i_key = config_GetInt( p_intf, "key-quit" );
395 [o_mi_quit setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
396 [o_mi_quit setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
397 i_key = config_GetInt( p_intf, "key-play-pause" );
398 [o_mi_play setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
399 [o_mi_play setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
400 i_key = config_GetInt( p_intf, "key-stop" );
401 [o_mi_stop setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
402 [o_mi_stop setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
403 i_key = config_GetInt( p_intf, "key-faster" );
404 [o_mi_faster setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
405 [o_mi_faster setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
406 i_key = config_GetInt( p_intf, "key-slower" );
407 [o_mi_slower setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
408 [o_mi_slower setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
409 i_key = config_GetInt( p_intf, "key-prev" );
410 [o_mi_previous setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
411 [o_mi_previous setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
412 i_key = config_GetInt( p_intf, "key-next" );
413 [o_mi_next setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
414 [o_mi_next setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
415 i_key = config_GetInt( p_intf, "key-jump+short" );
416 [o_mi_fwd setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
417 [o_mi_fwd setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
418 i_key = config_GetInt( p_intf, "key-jump-short" );
419 [o_mi_bwd setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
420 [o_mi_bwd setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
421 i_key = config_GetInt( p_intf, "key-jump+medium" );
422 [o_mi_fwd1m setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
423 [o_mi_fwd1m setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
424 i_key = config_GetInt( p_intf, "key-jump-medium" );
425 [o_mi_bwd1m setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
426 [o_mi_bwd1m setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
427 i_key = config_GetInt( p_intf, "key-jump+long" );
428 [o_mi_fwd5m setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
429 [o_mi_fwd5m setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
430 i_key = config_GetInt( p_intf, "key-jump-long" );
431 [o_mi_bwd5m setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
432 [o_mi_bwd5m setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
433 i_key = config_GetInt( p_intf, "key-vol-up" );
434 [o_mi_vol_up setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
435 [o_mi_vol_up setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
436 i_key = config_GetInt( p_intf, "key-vol-down" );
437 [o_mi_vol_down setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
438 [o_mi_vol_down setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
439 i_key = config_GetInt( p_intf, "key-vol-mute" );
440 [o_mi_mute setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
441 [o_mi_mute setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
442 i_key = config_GetInt( p_intf, "key-fullscreen" );
443 [o_mi_fullscreen setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
444 [o_mi_fullscreen setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
445 i_key = config_GetInt( p_intf, "key-snapshot" );
446 [o_mi_snapshot setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
447 [o_mi_snapshot setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
449 var_Create( p_intf, "intf-change", VLC_VAR_BOOL );
451 [self setSubmenusEnabled: FALSE];
452 [o_volumeslider setEnabled: YES];
453 [self manageVolumeSlider];
454 [o_window setDelegate: self];
456 b_restore_size = false;
457 if( [o_window frame].size.height <= 200 )
459 b_small_window = YES;
460 [o_window setFrame: NSMakeRect( [o_window frame].origin.x,
461 [o_window frame].origin.y, [o_window frame].size.width,
462 [o_window minSize].height ) display: YES animate:YES];
463 [o_playlist_view setAutoresizesSubviews: NO];
468 [o_playlist_view setFrame: NSMakeRect( 0, 0, [o_window frame].size.width, [o_window frame].size.height - 95 )];
469 [o_playlist_view setNeedsDisplay:YES];
470 [o_playlist_view setAutoresizesSubviews: YES];
471 [[o_window contentView] addSubview: o_playlist_view];
473 [self updateTogglePlaylistState];
475 o_size_with_playlist = [o_window frame].size;
477 p_playlist = pl_Yield( p_intf );
479 var_Create( p_playlist, "fullscreen", VLC_VAR_BOOL | VLC_VAR_DOINHERIT);
482 var_AddCallback( p_playlist, "fullscreen", FullscreenChanged, self);
483 var_AddCallback( p_intf->p_libvlc, "intf-show", ShowController, self);
485 pl_Release( p_intf );
487 var_Create( p_intf, "interaction", VLC_VAR_ADDRESS );
488 var_AddCallback( p_intf, "interaction", InteractCallback, self );
489 p_intf->b_interaction = true;
491 /* update the playmode stuff */
492 p_intf->p_sys->b_playmode_update = true;
494 [[NSNotificationCenter defaultCenter] addObserver: self
495 selector: @selector(refreshVoutDeviceMenu:)
496 name: NSApplicationDidChangeScreenParametersNotification
499 o_img_play = [NSImage imageNamed: @"play"];
500 o_img_pause = [NSImage imageNamed: @"pause"];
502 [self controlTintChanged];
504 [[NSNotificationCenter defaultCenter] addObserver: self
505 selector: @selector( controlTintChanged )
506 name: NSControlTintDidChangeNotification
509 nib_main_loaded = TRUE;
512 - (void)controlTintChanged
516 if( [o_btn_play alternateImage] == o_img_play_pressed )
519 if( [NSColor currentControlTint] == NSGraphiteControlTint )
521 o_img_play_pressed = [NSImage imageNamed: @"play_graphite"];
522 o_img_pause_pressed = [NSImage imageNamed: @"pause_graphite"];
524 [o_btn_prev setAlternateImage: [NSImage imageNamed: @"previous_graphite"]];
525 [o_btn_rewind setAlternateImage: [NSImage imageNamed: @"skip_previous_graphite"]];
526 [o_btn_stop setAlternateImage: [NSImage imageNamed: @"stop_graphite"]];
527 [o_btn_ff setAlternateImage: [NSImage imageNamed: @"skip_forward_graphite"]];
528 [o_btn_next setAlternateImage: [NSImage imageNamed: @"next_graphite"]];
529 [o_btn_fullscreen setAlternateImage: [NSImage imageNamed: @"fullscreen_graphite"]];
530 [o_btn_playlist setAlternateImage: [NSImage imageNamed: @"playlistdrawer_graphite"]];
531 [o_btn_equalizer setAlternateImage: [NSImage imageNamed: @"equalizerdrawer_graphite"]];
535 o_img_play_pressed = [NSImage imageNamed: @"play_blue"];
536 o_img_pause_pressed = [NSImage imageNamed: @"pause_blue"];
538 [o_btn_prev setAlternateImage: [NSImage imageNamed: @"previous_blue"]];
539 [o_btn_rewind setAlternateImage: [NSImage imageNamed: @"skip_previous_blue"]];
540 [o_btn_stop setAlternateImage: [NSImage imageNamed: @"stop_blue"]];
541 [o_btn_ff setAlternateImage: [NSImage imageNamed: @"skip_forward_blue"]];
542 [o_btn_next setAlternateImage: [NSImage imageNamed: @"next_blue"]];
543 [o_btn_fullscreen setAlternateImage: [NSImage imageNamed: @"fullscreen_blue"]];
544 [o_btn_playlist setAlternateImage: [NSImage imageNamed: @"playlistdrawer_blue"]];
545 [o_btn_equalizer setAlternateImage: [NSImage imageNamed: @"equalizerdrawer_blue"]];
549 [o_btn_play setAlternateImage: o_img_play_pressed];
551 [o_btn_play setAlternateImage: o_img_pause_pressed];
556 [o_window setTitle: _NS("VLC - Controller")];
557 [self setScrollField:_NS("VLC media player") stopAfter:-1];
559 /* button controls */
560 [o_btn_prev setToolTip: _NS("Previous")];
561 [o_btn_rewind setToolTip: _NS("Rewind")];
562 [o_btn_play setToolTip: _NS("Play")];
563 [o_btn_stop setToolTip: _NS("Stop")];
564 [o_btn_ff setToolTip: _NS("Fast Forward")];
565 [o_btn_next setToolTip: _NS("Next")];
566 [o_btn_fullscreen setToolTip: _NS("Fullscreen")];
567 [o_volumeslider setToolTip: _NS("Volume")];
568 [o_timeslider setToolTip: _NS("Position")];
569 [o_btn_playlist setToolTip: _NS("Playlist")];
572 [o_msgs_panel setTitle: _NS("Messages")];
573 [o_msgs_btn_crashlog setTitle: _NS("Open CrashLog...")];
576 [o_mi_about setTitle: [_NS("About VLC media player") \
577 stringByAppendingString: @"..."]];
578 [o_mi_checkForUpdate setTitle: _NS("Check for Update...")];
579 [o_mi_prefs setTitle: _NS("Preferences...")];
580 [o_mi_add_intf setTitle: _NS("Add Interface")];
581 [o_mu_add_intf setTitle: _NS("Add Interface")];
582 [o_mi_services setTitle: _NS("Services")];
583 [o_mi_hide setTitle: _NS("Hide VLC")];
584 [o_mi_hide_others setTitle: _NS("Hide Others")];
585 [o_mi_show_all setTitle: _NS("Show All")];
586 [o_mi_quit setTitle: _NS("Quit VLC")];
588 [o_mu_file setTitle: _ANS("1:File")];
589 [o_mi_open_generic setTitle: _NS("Open File...")];
590 [o_mi_open_file setTitle: _NS("Quick Open File...")];
591 [o_mi_open_disc setTitle: _NS("Open Disc...")];
592 [o_mi_open_net setTitle: _NS("Open Network...")];
593 [o_mi_open_capture setTitle: _NS("Open Capture Device...")];
594 [o_mi_open_recent setTitle: _NS("Open Recent")];
595 [o_mi_open_recent_cm setTitle: _NS("Clear Menu")];
596 [o_mi_open_wizard setTitle: _NS("Streaming/Exporting Wizard...")];
598 [o_mu_edit setTitle: _NS("Edit")];
599 [o_mi_cut setTitle: _NS("Cut")];
600 [o_mi_copy setTitle: _NS("Copy")];
601 [o_mi_paste setTitle: _NS("Paste")];
602 [o_mi_clear setTitle: _NS("Clear")];
603 [o_mi_select_all setTitle: _NS("Select All")];
605 [o_mu_controls setTitle: _NS("Playback")];
606 [o_mi_play setTitle: _NS("Play")];
607 [o_mi_stop setTitle: _NS("Stop")];
608 [o_mi_faster setTitle: _NS("Faster")];
609 [o_mi_slower setTitle: _NS("Slower")];
610 [o_mi_previous setTitle: _NS("Previous")];
611 [o_mi_next setTitle: _NS("Next")];
612 [o_mi_random setTitle: _NS("Random")];
613 [o_mi_repeat setTitle: _NS("Repeat One")];
614 [o_mi_loop setTitle: _NS("Repeat All")];
615 [o_mi_fwd setTitle: _NS("Step Forward")];
616 [o_mi_bwd setTitle: _NS("Step Backward")];
618 [o_mi_program setTitle: _NS("Program")];
619 [o_mu_program setTitle: _NS("Program")];
620 [o_mi_title setTitle: _NS("Title")];
621 [o_mu_title setTitle: _NS("Title")];
622 [o_mi_chapter setTitle: _NS("Chapter")];
623 [o_mu_chapter setTitle: _NS("Chapter")];
625 [o_mu_audio setTitle: _NS("Audio")];
626 [o_mi_vol_up setTitle: _NS("Volume Up")];
627 [o_mi_vol_down setTitle: _NS("Volume Down")];
628 [o_mi_mute setTitle: _NS("Mute")];
629 [o_mi_audiotrack setTitle: _NS("Audio Track")];
630 [o_mu_audiotrack setTitle: _NS("Audio Track")];
631 [o_mi_channels setTitle: _NS("Audio Channels")];
632 [o_mu_channels setTitle: _NS("Audio Channels")];
633 [o_mi_device setTitle: _NS("Audio Device")];
634 [o_mu_device setTitle: _NS("Audio Device")];
635 [o_mi_visual setTitle: _NS("Visualizations")];
636 [o_mu_visual setTitle: _NS("Visualizations")];
638 [o_mu_video setTitle: _NS("Video")];
639 [o_mi_half_window setTitle: _NS("Half Size")];
640 [o_mi_normal_window setTitle: _NS("Normal Size")];
641 [o_mi_double_window setTitle: _NS("Double Size")];
642 [o_mi_fittoscreen setTitle: _NS("Fit to Screen")];
643 [o_mi_fullscreen setTitle: _NS("Fullscreen")];
644 [o_mi_floatontop setTitle: _NS("Float on Top")];
645 [o_mi_snapshot setTitle: _NS("Snapshot")];
646 [o_mi_videotrack setTitle: _NS("Video Track")];
647 [o_mu_videotrack setTitle: _NS("Video Track")];
648 [o_mi_aspect_ratio setTitle: _NS("Aspect-ratio")];
649 [o_mu_aspect_ratio setTitle: _NS("Aspect-ratio")];
650 [o_mi_crop setTitle: _NS("Crop")];
651 [o_mu_crop setTitle: _NS("Crop")];
652 [o_mi_screen setTitle: _NS("Fullscreen Video Device")];
653 [o_mu_screen setTitle: _NS("Fullscreen Video Device")];
654 [o_mi_subtitle setTitle: _NS("Subtitles Track")];
655 [o_mu_subtitle setTitle: _NS("Subtitles Track")];
656 [o_mi_deinterlace setTitle: _NS("Deinterlace")];
657 [o_mu_deinterlace setTitle: _NS("Deinterlace")];
658 [o_mi_ffmpeg_pp setTitle: _NS("Post processing")];
659 [o_mu_ffmpeg_pp setTitle: _NS("Post processing")];
661 [o_mu_window setTitle: _NS("Window")];
662 [o_mi_minimize setTitle: _NS("Minimize Window")];
663 [o_mi_close_window setTitle: _NS("Close Window")];
664 [o_mi_controller setTitle: _NS("Controller...")];
665 [o_mi_equalizer setTitle: _NS("Equalizer...")];
666 [o_mi_extended setTitle: _NS("Extended Controls...")];
667 [o_mi_bookmarks setTitle: _NS("Bookmarks...")];
668 [o_mi_playlist setTitle: _NS("Playlist...")];
669 [o_mi_info setTitle: _NS("Media Information...")];
670 [o_mi_messages setTitle: _NS("Messages...")];
671 [o_mi_errorsAndWarnings setTitle: _NS("Errors and Warnings...")];
673 [o_mi_bring_atf setTitle: _NS("Bring All to Front")];
675 [o_mu_help setTitle: _NS("Help")];
676 [o_mi_help setTitle: _NS("VLC media player Help...")];
677 [o_mi_readme setTitle: _NS("ReadMe / FAQ...")];
678 [o_mi_license setTitle: _NS("License")];
679 [o_mi_documentation setTitle: _NS("Online Documentation...")];
680 [o_mi_website setTitle: _NS("VideoLAN Website...")];
681 [o_mi_donation setTitle: _NS("Make a donation...")];
682 [o_mi_forum setTitle: _NS("Online Forum...")];
685 [o_dmi_play setTitle: _NS("Play")];
686 [o_dmi_stop setTitle: _NS("Stop")];
687 [o_dmi_next setTitle: _NS("Next")];
688 [o_dmi_previous setTitle: _NS("Previous")];
689 [o_dmi_mute setTitle: _NS("Mute")];
692 [o_vmi_play setTitle: _NS("Play")];
693 [o_vmi_stop setTitle: _NS("Stop")];
694 [o_vmi_prev setTitle: _NS("Previous")];
695 [o_vmi_next setTitle: _NS("Next")];
696 [o_vmi_volup setTitle: _NS("Volume Up")];
697 [o_vmi_voldown setTitle: _NS("Volume Down")];
698 [o_vmi_mute setTitle: _NS("Mute")];
699 [o_vmi_fullscreen setTitle: _NS("Fullscreen")];
700 [o_vmi_snapshot setTitle: _NS("Snapshot")];
703 - (void)applicationWillFinishLaunching:(NSNotification *)o_notification
705 o_msg_lock = [[NSLock alloc] init];
706 o_msg_arr = [[NSMutableArray arrayWithCapacity: 200] retain];
708 /* FIXME: don't poll */
709 interfaceTimer = [[NSTimer scheduledTimerWithTimeInterval: 0.5
710 target: self selector: @selector(manageIntf:)
711 userInfo: nil repeats: FALSE] retain];
713 /* Note: we use the pthread API to support pre-10.5 */
714 pthread_create( &manage_thread, NULL, ManageThread, self );
716 [o_controls setupVarMenuItem: o_mi_add_intf target: (vlc_object_t *)p_intf
717 var: "intf-add" selector: @selector(toggleVar:)];
719 /* check whether the user runs a valid version of OSX; alert is auto-released */
720 if( MACOS_VERSION < 10.4f )
724 ourAlert = [NSAlert alertWithMessageText: _NS("Your version of Mac OS X is not supported")
725 defaultButton: _NS("Quit")
726 alternateButton: NULL
728 informativeTextWithFormat: _NS("VLC media player requires Mac OS X 10.4 or higher.")];
729 [ourAlert setAlertStyle: NSCriticalAlertStyle];
730 i_returnValue = [ourAlert runModal];
731 [NSApp terminate: self];
734 vlc_thread_set_priority( p_intf, VLC_THREAD_PRIORITY_LOW );
737 - (BOOL)application:(NSApplication *)o_app openFile:(NSString *)o_filename
739 BOOL b_autoplay = config_GetInt( VLCIntf, "macosx-autoplay" );
740 NSDictionary *o_dic = [NSDictionary dictionaryWithObjectsAndKeys: o_filename, @"ITEM_URL", nil];
742 [o_playlist appendArray: [NSArray arrayWithObject: o_dic] atPos: -1 enqueue: NO];
744 [o_playlist appendArray: [NSArray arrayWithObject: o_dic] atPos: -1 enqueue: YES];
749 - (NSString *)localizedString:(const char *)psz
751 NSString * o_str = nil;
755 o_str = [[[NSString alloc] initWithUTF8String: psz] autorelease];
759 msg_Err( VLCIntf, "could not translate: %s", psz );
765 msg_Warn( VLCIntf, "can't translate empty strings" );
772 /* When user click in the Dock icon our double click in the finder */
773 - (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)hasVisibleWindows
775 if(!hasVisibleWindows)
776 [o_window makeKeyAndOrderFront:self];
781 - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
784 /* Check for update silently on startup */
785 if( !nib_update_loaded )
786 nib_update_loaded = [NSBundle loadNibNamed:@"Update" owner:self];
788 if([o_update shouldCheckForUpdate])
789 [NSThread detachNewThreadSelector:@selector(checkForUpdate) toTarget:o_update withObject:NULL];
792 /* Handle sleep notification */
793 [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(computerWillSleep:)
794 name:NSWorkspaceWillSleepNotification object:nil];
797 /* Listen to the remote in exclusive mode, only when VLC is the active
799 - (void)applicationDidBecomeActive:(NSNotification *)aNotification
801 [o_remote startListening: self];
803 - (void)applicationDidResignActive:(NSNotification *)aNotification
805 [o_remote stopListening: self];
808 /* Triggered when the computer goes to sleep */
809 - (void)computerWillSleep: (NSNotification *)notification
812 if( p_intf->p_sys->i_play_status == PLAYING_S )
815 val.i_int = config_GetInt( p_intf, "key-play-pause" );
816 var_Set( p_intf->p_libvlc, "key-pressed", val );
820 /* Helper method for the remote control interface in order to trigger forward/backward and volume
821 increase/decrease as long as the user holds the left/right, plus/minus button */
822 - (void) executeHoldActionForRemoteButton: (NSNumber*) buttonIdentifierNumber
824 if(b_remote_button_hold)
826 switch([buttonIdentifierNumber intValue])
828 case kRemoteButtonRight_Hold:
829 [o_controls forward: self];
831 case kRemoteButtonLeft_Hold:
832 [o_controls backward: self];
834 case kRemoteButtonVolume_Plus_Hold:
835 [o_controls volumeUp: self];
837 case kRemoteButtonVolume_Minus_Hold:
838 [o_controls volumeDown: self];
841 if(b_remote_button_hold)
844 [self performSelector:@selector(executeHoldActionForRemoteButton:)
845 withObject:buttonIdentifierNumber
851 /* Apple Remote callback */
852 - (void) appleRemoteButton: (AppleRemoteEventIdentifier)buttonIdentifier
853 pressedDown: (BOOL) pressedDown
854 clickCount: (unsigned int) count
856 switch( buttonIdentifier )
858 case kRemoteButtonPlay:
860 [o_controls toogleFullscreen:self];
862 [o_controls play: self];
865 case kRemoteButtonVolume_Plus:
866 [o_controls volumeUp: self];
868 case kRemoteButtonVolume_Minus:
869 [o_controls volumeDown: self];
871 case kRemoteButtonRight:
872 [o_controls next: self];
874 case kRemoteButtonLeft:
875 [o_controls prev: self];
877 case kRemoteButtonRight_Hold:
878 case kRemoteButtonLeft_Hold:
879 case kRemoteButtonVolume_Plus_Hold:
880 case kRemoteButtonVolume_Minus_Hold:
881 /* simulate an event as long as the user holds the button */
882 b_remote_button_hold = pressedDown;
885 NSNumber* buttonIdentifierNumber = [NSNumber numberWithInt: buttonIdentifier];
886 [self performSelector:@selector(executeHoldActionForRemoteButton:)
887 withObject:buttonIdentifierNumber];
890 case kRemoteButtonMenu:
891 [o_controls showPosition: self];
894 /* Add here whatever you want other buttons to do */
899 - (char *)delocalizeString:(NSString *)id
901 NSData * o_data = [id dataUsingEncoding: NSUTF8StringEncoding
902 allowLossyConversion: NO];
907 o_data = [id dataUsingEncoding: NSUTF8StringEncoding
908 allowLossyConversion: YES];
909 psz_string = malloc( [o_data length] + 1 );
910 [o_data getBytes: psz_string];
911 psz_string[ [o_data length] ] = '\0';
912 msg_Err( VLCIntf, "cannot convert to the requested encoding: %s",
917 psz_string = malloc( [o_data length] + 1 );
918 [o_data getBytes: psz_string];
919 psz_string[ [o_data length] ] = '\0';
925 /* i_width is in pixels */
926 - (NSString *)wrapString: (NSString *)o_in_string toWidth: (int) i_width
928 NSMutableString *o_wrapped;
929 NSString *o_out_string;
930 NSRange glyphRange, effectiveRange, charRange;
931 NSRect lineFragmentRect;
932 unsigned glyphIndex, breaksInserted = 0;
934 NSTextStorage *o_storage = [[NSTextStorage alloc] initWithString: o_in_string
935 attributes: [NSDictionary dictionaryWithObjectsAndKeys:
936 [NSFont labelFontOfSize: 0.0], NSFontAttributeName, nil]];
937 NSLayoutManager *o_layout_manager = [[NSLayoutManager alloc] init];
938 NSTextContainer *o_container = [[NSTextContainer alloc]
939 initWithContainerSize: NSMakeSize(i_width, 2000)];
941 [o_layout_manager addTextContainer: o_container];
942 [o_container release];
943 [o_storage addLayoutManager: o_layout_manager];
944 [o_layout_manager release];
946 o_wrapped = [o_in_string mutableCopy];
947 glyphRange = [o_layout_manager glyphRangeForTextContainer: o_container];
949 for( glyphIndex = glyphRange.location ; glyphIndex < NSMaxRange(glyphRange) ;
950 glyphIndex += effectiveRange.length) {
951 lineFragmentRect = [o_layout_manager lineFragmentRectForGlyphAtIndex: glyphIndex
952 effectiveRange: &effectiveRange];
953 charRange = [o_layout_manager characterRangeForGlyphRange: effectiveRange
954 actualGlyphRange: &effectiveRange];
955 if([o_wrapped lineRangeForRange:
956 NSMakeRange(charRange.location + breaksInserted, charRange.length)].length > charRange.length) {
957 [o_wrapped insertString: @"\n" atIndex: NSMaxRange(charRange) + breaksInserted];
961 o_out_string = [NSString stringWithString: o_wrapped];
969 /*****************************************************************************
970 * hasDefinedShortcutKey: Check to see if the key press is a defined VLC
971 * shortcut key. If it is, pass it off to VLC for handling and return YES,
972 * otherwise ignore it and return NO (where it will get handled by Cocoa).
973 *****************************************************************************/
974 - (BOOL)hasDefinedShortcutKey:(NSEvent *)o_event
978 unsigned int i_pressed_modifiers = 0;
979 struct hotkey *p_hotkeys;
983 p_hotkeys = p_intf->p_libvlc->p_hotkeys;
985 i_pressed_modifiers = [o_event modifierFlags];
987 if( i_pressed_modifiers & NSShiftKeyMask )
988 val.i_int |= KEY_MODIFIER_SHIFT;
989 if( i_pressed_modifiers & NSControlKeyMask )
990 val.i_int |= KEY_MODIFIER_CTRL;
991 if( i_pressed_modifiers & NSAlternateKeyMask )
992 val.i_int |= KEY_MODIFIER_ALT;
993 if( i_pressed_modifiers & NSCommandKeyMask )
994 val.i_int |= KEY_MODIFIER_COMMAND;
996 key = [[o_event charactersIgnoringModifiers] characterAtIndex: 0];
1000 case NSDeleteCharacter:
1001 case NSDeleteFunctionKey:
1002 case NSDeleteCharFunctionKey:
1003 case NSBackspaceCharacter:
1004 case NSUpArrowFunctionKey:
1005 case NSDownArrowFunctionKey:
1006 case NSRightArrowFunctionKey:
1007 case NSLeftArrowFunctionKey:
1008 case NSEnterCharacter:
1009 case NSCarriageReturnCharacter:
1013 val.i_int |= CocoaKeyToVLC( key );
1015 for( i = 0; p_hotkeys[i].psz_action != NULL; i++ )
1017 if( p_hotkeys[i].i_key == val.i_int )
1019 var_Set( p_intf->p_libvlc, "key-pressed", val );
1035 - (id)getSimplePreferences
1040 if( !nib_prefs_loaded )
1041 nib_prefs_loaded = [NSBundle loadNibNamed:@"Preferences" owner: self];
1046 - (id)getPreferences
1051 if( !nib_prefs_loaded )
1052 nib_prefs_loaded = [NSBundle loadNibNamed:@"Preferences" owner: self];
1089 - (id)getEmbeddedList
1091 if( o_embedded_list )
1092 return o_embedded_list;
1097 - (id)getInteractionList
1099 if( o_interaction_list )
1100 return o_interaction_list;
1105 - (id)getMainIntfPgbar
1108 return o_main_pgbar;
1113 - (id)getControllerWindow
1125 - (id)getEyeTVController
1135 playlist_t * p_playlist;
1136 input_thread_t * p_input = NULL;
1138 /* new thread requires a new pool */
1139 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
1141 vlc_thread_set_priority( p_intf, VLC_THREAD_PRIORITY_LOW );
1143 p_playlist = pl_Yield( p_intf );
1145 var_AddCallback( p_playlist, "playlist-current", PlaylistChanged, self );
1146 var_AddCallback( p_playlist, "intf-change", PlaylistChanged, self );
1147 var_AddCallback( p_playlist, "item-change", PlaylistChanged, self );
1148 var_AddCallback( p_playlist, "item-append", PlaylistChanged, self );
1149 var_AddCallback( p_playlist, "item-deleted", PlaylistChanged, self );
1151 pl_Release( p_intf );
1153 vlc_object_lock( p_intf );
1154 while( vlc_object_alive( p_intf ) )
1156 vlc_mutex_lock( &p_intf->change_lock );
1160 p_input = playlist_CurrentInput( p_playlist );
1162 /* Refresh the interface */
1165 msg_Dbg( p_intf, "input has changed, refreshing interface" );
1166 p_intf->p_sys->b_input_update = true;
1169 else if( !vlc_object_alive (p_input) || p_input->b_dead )
1172 p_intf->p_sys->b_intf_update = true;
1173 p_intf->p_sys->i_play_status = END_S;
1174 msg_Dbg( p_intf, "input has stopped, refreshing interface" );
1175 vlc_object_release( p_input );
1179 /* Manage volume status */
1180 [self manageVolumeSlider];
1182 vlc_mutex_unlock( &p_intf->change_lock );
1184 vlc_object_timedwait( p_intf, 100000 + mdate());
1186 vlc_object_unlock( p_intf );
1189 if( p_input ) vlc_object_release( p_input );
1191 var_DelCallback( p_playlist, "playlist-current", PlaylistChanged, self );
1192 var_DelCallback( p_playlist, "intf-change", PlaylistChanged, self );
1193 var_DelCallback( p_playlist, "item-change", PlaylistChanged, self );
1194 var_DelCallback( p_playlist, "item-append", PlaylistChanged, self );
1195 var_DelCallback( p_playlist, "item-deleted", PlaylistChanged, self );
1197 pthread_testcancel(); /* If we were cancelled stop here */
1199 msg_Dbg( p_intf, "Killing the Mac OS X module" );
1201 /* We are dead, terminate */
1202 [NSApp performSelectorOnMainThread: @selector(terminate:) withObject:nil waitUntilDone:NO];
1205 - (void)manageIntf:(NSTimer *)o_timer
1208 playlist_t * p_playlist;
1209 input_thread_t * p_input;
1211 if( p_intf->p_sys->b_input_update )
1213 /* Called when new input is opened */
1214 p_intf->p_sys->b_current_title_update = true;
1215 p_intf->p_sys->b_intf_update = true;
1216 p_intf->p_sys->b_input_update = false;
1217 [self setupMenus]; /* Make sure input menu is up to date */
1219 if( p_intf->p_sys->b_intf_update )
1221 bool b_input = false;
1222 bool b_plmul = false;
1223 bool b_control = false;
1224 bool b_seekable = false;
1225 bool b_chapters = false;
1227 playlist_t * p_playlist = pl_Yield( p_intf );
1228 /* TODO: fix i_size use */
1229 b_plmul = p_playlist->items.i_size > 1;
1231 p_input = vlc_object_find( p_playlist, VLC_OBJECT_INPUT,
1234 if( ( b_input = ( p_input != NULL ) ) )
1236 /* seekable streams */
1237 b_seekable = var_GetBool( p_input, "seekable" );
1239 /* check whether slow/fast motion is possible */
1240 b_control = p_input->b_can_pace_control;
1242 /* chapters & titles */
1243 //b_chapters = p_input->stream.i_area_nb > 1;
1244 vlc_object_release( p_input );
1246 pl_Release( p_intf );
1248 [o_btn_stop setEnabled: b_input];
1249 [o_btn_ff setEnabled: b_seekable];
1250 [o_btn_rewind setEnabled: b_seekable];
1251 [o_btn_prev setEnabled: (b_plmul || b_chapters)];
1252 [o_btn_next setEnabled: (b_plmul || b_chapters)];
1254 [o_timeslider setFloatValue: 0.0];
1255 [o_timeslider setEnabled: b_seekable];
1256 [o_timefield setStringValue: @"00:00"];
1257 [[[self getControls] getFSPanel] setStreamPos: 0 andTime: @"00:00"];
1258 [[[self getControls] getFSPanel] setSeekable: b_seekable];
1260 [o_embedded_window setSeekable: b_seekable];
1262 p_intf->p_sys->b_current_title_update = true;
1264 p_intf->p_sys->b_intf_update = false;
1267 if( p_intf->p_sys->b_playmode_update )
1269 [o_playlist playModeUpdated];
1270 p_intf->p_sys->b_playmode_update = false;
1272 if( p_intf->p_sys->b_playlist_update )
1274 [o_playlist playlistUpdated];
1275 p_intf->p_sys->b_playlist_update = false;
1278 if( p_intf->p_sys->b_fullscreen_update )
1280 p_intf->p_sys->b_fullscreen_update = false;
1283 if( p_intf->p_sys->b_intf_show )
1285 [o_window makeKeyAndOrderFront: self];
1287 p_intf->p_sys->b_intf_show = false;
1290 p_input = pl_CurrentInput( p_intf );
1291 if( p_input && vlc_object_alive (p_input) )
1295 if( p_intf->p_sys->b_current_title_update )
1298 input_item_t * p_item = input_GetItem( p_input );
1299 char * name = input_item_GetNowPlaying( p_item );
1302 name = input_item_GetName( p_item );
1304 aString = [NSString stringWithUTF8String:name];
1308 [self setScrollField: aString stopAfter:-1];
1309 [[[self getControls] getFSPanel] setStreamTitle: aString];
1311 [[o_controls getVoutView] updateTitle];
1313 [o_playlist updateRowSelection];
1314 p_intf->p_sys->b_current_title_update = FALSE;
1317 if( [o_timeslider isEnabled] )
1319 /* Update the slider */
1323 char psz_time[MSTRTIME_MAX_SIZE];
1326 var_Get( p_input, "position", &pos );
1327 f_updated = 10000. * pos.f_float;
1328 [o_timeslider setFloatValue: f_updated];
1330 var_Get( p_input, "time", &time );
1332 o_time = [NSString stringWithUTF8String: secstotimestr( psz_time, (time.i_time / 1000000) )];
1334 [o_timefield setStringValue: o_time];
1335 [[[self getControls] getFSPanel] setStreamPos: f_updated andTime: o_time];
1336 [o_embedded_window setTime: o_time position: f_updated];
1339 /* Manage Playing status */
1340 var_Get( p_input, "state", &val );
1341 if( p_intf->p_sys->i_play_status != val.i_int )
1343 p_intf->p_sys->i_play_status = val.i_int;
1344 [self playStatusUpdated: p_intf->p_sys->i_play_status];
1345 [o_embedded_window playStatusUpdated: p_intf->p_sys->i_play_status];
1347 vlc_object_release( p_input );
1351 vlc_object_release( p_input );
1355 p_intf->p_sys->i_play_status = END_S;
1356 [self playStatusUpdated: p_intf->p_sys->i_play_status];
1357 [o_embedded_window playStatusUpdated: p_intf->p_sys->i_play_status];
1358 [self setSubmenusEnabled: FALSE];
1361 if( p_intf->p_sys->b_volume_update )
1364 int i_volume_step = 0;
1365 o_text = [NSString stringWithFormat: _NS("Volume: %d%%"), i_lastShownVolume * 400 / AOUT_VOLUME_MAX];
1366 if( i_lastShownVolume != -1 )
1367 [self setScrollField:o_text stopAfter:1000000];
1368 i_volume_step = config_GetInt( p_intf->p_libvlc, "volume-step" );
1369 [o_volumeslider setFloatValue: (float)i_lastShownVolume / i_volume_step];
1370 [o_volumeslider setEnabled: TRUE];
1371 [[[self getControls] getFSPanel] setVolumeLevel: (float)i_lastShownVolume / i_volume_step];
1372 p_intf->p_sys->b_mute = ( i_lastShownVolume == 0 );
1373 p_intf->p_sys->b_volume_update = FALSE;
1377 [self updateMessageArray];
1379 if( ((i_end_scroll != -1) && (mdate() > i_end_scroll)) || !p_input )
1380 [self resetScrollField];
1382 [interfaceTimer autorelease];
1384 interfaceTimer = [[NSTimer scheduledTimerWithTimeInterval: 0.3
1385 target: self selector: @selector(manageIntf:)
1386 userInfo: nil repeats: FALSE] retain];
1391 playlist_t * p_playlist = pl_Yield( p_intf );
1392 input_thread_t * p_input = playlist_CurrentInput( p_playlist );
1393 if( p_input != NULL )
1395 [o_controls setupVarMenuItem: o_mi_program target: (vlc_object_t *)p_input
1396 var: "program" selector: @selector(toggleVar:)];
1398 [o_controls setupVarMenuItem: o_mi_title target: (vlc_object_t *)p_input
1399 var: "title" selector: @selector(toggleVar:)];
1401 [o_controls setupVarMenuItem: o_mi_chapter target: (vlc_object_t *)p_input
1402 var: "chapter" selector: @selector(toggleVar:)];
1404 [o_controls setupVarMenuItem: o_mi_audiotrack target: (vlc_object_t *)p_input
1405 var: "audio-es" selector: @selector(toggleVar:)];
1407 [o_controls setupVarMenuItem: o_mi_videotrack target: (vlc_object_t *)p_input
1408 var: "video-es" selector: @selector(toggleVar:)];
1410 [o_controls setupVarMenuItem: o_mi_subtitle target: (vlc_object_t *)p_input
1411 var: "spu-es" selector: @selector(toggleVar:)];
1413 aout_instance_t * p_aout = vlc_object_find( p_intf, VLC_OBJECT_AOUT,
1415 if( p_aout != NULL )
1417 [o_controls setupVarMenuItem: o_mi_channels target: (vlc_object_t *)p_aout
1418 var: "audio-channels" selector: @selector(toggleVar:)];
1420 [o_controls setupVarMenuItem: o_mi_device target: (vlc_object_t *)p_aout
1421 var: "audio-device" selector: @selector(toggleVar:)];
1423 [o_controls setupVarMenuItem: o_mi_visual target: (vlc_object_t *)p_aout
1424 var: "visual" selector: @selector(toggleVar:)];
1425 vlc_object_release( (vlc_object_t *)p_aout );
1428 vout_thread_t * p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
1431 if( p_vout != NULL )
1433 vlc_object_t * p_dec_obj;
1435 [o_controls setupVarMenuItem: o_mi_aspect_ratio target: (vlc_object_t *)p_vout
1436 var: "aspect-ratio" selector: @selector(toggleVar:)];
1438 [o_controls setupVarMenuItem: o_mi_crop target: (vlc_object_t *) p_vout
1439 var: "crop" selector: @selector(toggleVar:)];
1441 [o_controls setupVarMenuItem: o_mi_screen target: (vlc_object_t *)p_vout
1442 var: "video-device" selector: @selector(toggleVar:)];
1444 [o_controls setupVarMenuItem: o_mi_deinterlace target: (vlc_object_t *)p_vout
1445 var: "deinterlace" selector: @selector(toggleVar:)];
1447 p_dec_obj = (vlc_object_t *)vlc_object_find(
1448 (vlc_object_t *)p_vout,
1451 if( p_dec_obj != NULL )
1453 [o_controls setupVarMenuItem: o_mi_ffmpeg_pp target:
1454 (vlc_object_t *)p_dec_obj var:"ffmpeg-pp-q" selector:
1455 @selector(toggleVar:)];
1457 vlc_object_release(p_dec_obj);
1459 vlc_object_release( (vlc_object_t *)p_vout );
1461 vlc_object_release( p_input );
1463 pl_Release( p_intf );
1466 - (void)refreshVoutDeviceMenu:(NSNotification *)o_notification
1469 vout_thread_t * p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
1475 /* clean the menu before adding new entries */
1476 if( [o_mi_screen hasSubmenu] )
1478 y = [[o_mi_screen submenu] numberOfItems] - 1;
1479 msg_Dbg( VLCIntf, "%i items in submenu", y );
1482 msg_Dbg( VLCIntf, "removing item %i of %i", x, y );
1483 [[o_mi_screen submenu] removeItemAtIndex: x];
1488 [o_controls setupVarMenuItem: o_mi_screen target: (vlc_object_t *)p_vout
1489 var: "video-device" selector: @selector(toggleVar:)];
1490 vlc_object_release( (vlc_object_t *)p_vout );
1493 - (void)setScrollField:(NSString *)o_string stopAfter:(int)timeout
1496 i_end_scroll = mdate() + timeout;
1499 [o_scrollfield setStringValue: o_string];
1502 - (void)resetScrollField
1504 playlist_t * p_playlist = pl_Yield( p_intf );
1505 input_thread_t * p_input = playlist_CurrentInput( p_playlist );
1508 if( p_input && vlc_object_alive (p_input) )
1511 if( input_item_GetNowPlaying ( p_playlist->status.p_item->p_input ) )
1512 o_temp = [NSString stringWithUTF8String:
1513 input_item_GetNowPlaying ( p_playlist->status.p_item->p_input )];
1515 o_temp = [NSString stringWithUTF8String:
1516 p_playlist->status.p_item->p_input->psz_name];
1517 [self setScrollField: o_temp stopAfter:-1];
1518 [[[self getControls] getFSPanel] setStreamTitle: o_temp];
1519 vlc_object_release( p_input );
1520 pl_Release( p_intf );
1523 pl_Release( p_intf );
1524 [self setScrollField: _NS("VLC media player") stopAfter:-1];
1527 - (void)updateMessageArray
1529 int i_start, i_stop;
1531 vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
1532 i_stop = *p_intf->p_sys->p_sub->pi_stop;
1533 vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
1535 if( p_intf->p_sys->p_sub->i_start != i_stop )
1537 NSColor *o_white = [NSColor whiteColor];
1538 NSColor *o_red = [NSColor redColor];
1539 NSColor *o_yellow = [NSColor yellowColor];
1540 NSColor *o_gray = [NSColor grayColor];
1542 NSColor * pp_color[4] = { o_white, o_red, o_yellow, o_gray };
1543 static const char * ppsz_type[4] = { ": ", " error: ",
1544 " warning: ", " debug: " };
1546 for( i_start = p_intf->p_sys->p_sub->i_start;
1548 i_start = (i_start+1) % VLC_MSG_QSIZE )
1551 NSDictionary *o_attr;
1552 NSAttributedString *o_msg_color;
1554 int i_type = p_intf->p_sys->p_sub->p_msg[i_start].i_type;
1558 if( [o_msg_arr count] + 2 > 400 )
1560 unsigned rid[] = { 0, 1 };
1561 [o_msg_arr removeObjectsFromIndices: (unsigned *)&rid
1562 numIndices: sizeof(rid)/sizeof(rid[0])];
1565 o_attr = [NSDictionary dictionaryWithObject: o_gray
1566 forKey: NSForegroundColorAttributeName];
1567 o_msg = [NSString stringWithFormat: @"%s%s",
1568 p_intf->p_sys->p_sub->p_msg[i_start].psz_module,
1570 o_msg_color = [[NSAttributedString alloc]
1571 initWithString: o_msg attributes: o_attr];
1572 [o_msg_arr addObject: [o_msg_color autorelease]];
1574 o_attr = [NSDictionary dictionaryWithObject: pp_color[i_type]
1575 forKey: NSForegroundColorAttributeName];
1576 o_msg = [NSString stringWithFormat: @"%s\n",
1577 p_intf->p_sys->p_sub->p_msg[i_start].psz_msg];
1578 o_msg_color = [[NSAttributedString alloc]
1579 initWithString: o_msg attributes: o_attr];
1580 [o_msg_arr addObject: [o_msg_color autorelease]];
1582 [o_msg_lock unlock];
1585 vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
1586 p_intf->p_sys->p_sub->i_start = i_start;
1587 vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
1591 - (void)playStatusUpdated:(int)i_status
1593 if( i_status == PLAYING_S )
1595 [[[self getControls] getFSPanel] setPause];
1596 [o_btn_play setImage: o_img_pause];
1597 [o_btn_play setAlternateImage: o_img_pause_pressed];
1598 [o_btn_play setToolTip: _NS("Pause")];
1599 [o_mi_play setTitle: _NS("Pause")];
1600 [o_dmi_play setTitle: _NS("Pause")];
1601 [o_vmi_play setTitle: _NS("Pause")];
1605 [[[self getControls] getFSPanel] setPlay];
1606 [o_btn_play setImage: o_img_play];
1607 [o_btn_play setAlternateImage: o_img_play_pressed];
1608 [o_btn_play setToolTip: _NS("Play")];
1609 [o_mi_play setTitle: _NS("Play")];
1610 [o_dmi_play setTitle: _NS("Play")];
1611 [o_vmi_play setTitle: _NS("Play")];
1615 - (void)setSubmenusEnabled:(BOOL)b_enabled
1617 [o_mi_program setEnabled: b_enabled];
1618 [o_mi_title setEnabled: b_enabled];
1619 [o_mi_chapter setEnabled: b_enabled];
1620 [o_mi_audiotrack setEnabled: b_enabled];
1621 [o_mi_visual setEnabled: b_enabled];
1622 [o_mi_videotrack setEnabled: b_enabled];
1623 [o_mi_subtitle setEnabled: b_enabled];
1624 [o_mi_channels setEnabled: b_enabled];
1625 [o_mi_deinterlace setEnabled: b_enabled];
1626 [o_mi_ffmpeg_pp setEnabled: b_enabled];
1627 [o_mi_device setEnabled: b_enabled];
1628 [o_mi_screen setEnabled: b_enabled];
1629 [o_mi_aspect_ratio setEnabled: b_enabled];
1630 [o_mi_crop setEnabled: b_enabled];
1633 - (void)manageVolumeSlider
1635 audio_volume_t i_volume;
1636 aout_VolumeGet( p_intf, &i_volume );
1638 if( i_volume != i_lastShownVolume )
1640 i_lastShownVolume = i_volume;
1641 p_intf->p_sys->b_volume_update = TRUE;
1645 - (IBAction)timesliderUpdate:(id)sender
1648 playlist_t * p_playlist;
1649 input_thread_t * p_input;
1651 switch( [[NSApp currentEvent] type] )
1654 case NSLeftMouseDown:
1655 case NSLeftMouseDragged:
1656 f_updated = [sender floatValue];
1662 p_playlist = pl_Yield( p_intf );
1663 p_input = playlist_CurrentInput( p_playlist );
1664 if( p_input != NULL )
1669 char psz_time[MSTRTIME_MAX_SIZE];
1671 pos.f_float = f_updated / 10000.;
1672 var_Set( p_input, "position", pos );
1673 [o_timeslider setFloatValue: f_updated];
1675 var_Get( p_input, "time", &time );
1677 o_time = [NSString stringWithUTF8String: secstotimestr( psz_time, (time.i_time / 1000000) )];
1678 [o_timefield setStringValue: o_time];
1679 [[[self getControls] getFSPanel] setStreamPos: f_updated andTime: o_time];
1680 [o_embedded_window setTime: o_time position: f_updated];
1681 vlc_object_release( p_input );
1683 pl_Release( p_intf );
1686 - (void)applicationWillTerminate:(NSNotification *)notification
1688 playlist_t * p_playlist;
1689 vout_thread_t * p_vout;
1690 int returnedValue = 0;
1692 msg_Dbg( p_intf, "Terminating" );
1694 /* Make sure the manage_thread won't call -terminate: again */
1695 pthread_cancel( manage_thread );
1697 /* Make sure the intf object is getting killed */
1698 vlc_object_kill( p_intf );
1700 /* Make sure our manage_thread ends */
1701 pthread_join( manage_thread, NULL );
1703 /* Make sure the interfaceTimer is destroyed */
1704 [interfaceTimer invalidate];
1705 [interfaceTimer release];
1706 interfaceTimer = nil;
1708 /* make sure that the current volume is saved */
1709 config_PutInt( p_intf->p_libvlc, "volume", i_lastShownVolume );
1710 returnedValue = config_SaveConfigFile( p_intf->p_libvlc, "main" );
1711 if( returnedValue != 0 )
1713 "error while saving volume in osx's terminate method (%i)",
1716 /* save the prefs if they were changed in the extended panel */
1717 if(o_extended && [o_extended getConfigChanged])
1719 [o_extended savePrefs];
1722 p_intf->b_interaction = false;
1723 var_DelCallback( p_intf, "interaction", InteractCallback, self );
1725 /* remove global observer watching for vout device changes correctly */
1726 [[NSNotificationCenter defaultCenter] removeObserver: self];
1728 /* release some other objects here, because it isn't sure whether dealloc
1729 * will be called later on */
1731 if( nib_about_loaded )
1734 if( nib_prefs_loaded )
1740 if( nib_open_loaded )
1743 if( nib_extended_loaded )
1745 [o_extended release];
1748 if( nib_bookmarks_loaded )
1749 [o_bookmarks release];
1753 [o_info stopTimers];
1757 if( nib_wizard_loaded )
1760 [o_embedded_list release];
1761 [o_interaction_list release];
1764 [o_img_pause_pressed release];
1765 [o_img_play_pressed release];
1766 [o_img_pause release];
1767 [o_img_play release];
1769 [o_msg_arr removeAllObjects];
1770 [o_msg_arr release];
1772 [o_msg_lock release];
1774 /* write cached user defaults to disk */
1775 [[NSUserDefaults standardUserDefaults] synchronize];
1777 /* Kill the playlist, so that it doesn't accept new request
1778 * such as the play request from vlc.c (we are a blocking interface). */
1779 p_playlist = pl_Yield( p_intf );
1780 vlc_object_kill( p_playlist );
1781 pl_Release( p_intf );
1783 vlc_object_kill( p_intf->p_libvlc );
1785 /* Go back to Run() and make libvlc exit properly */
1787 longjmp( jmpbuffer, 1 );
1792 - (IBAction)clearRecentItems:(id)sender
1794 [[NSDocumentController sharedDocumentController]
1795 clearRecentDocuments: nil];
1798 - (void)openRecentItem:(id)sender
1800 [self application: nil openFile: [sender title]];
1803 - (IBAction)intfOpenFile:(id)sender
1805 if( !nib_open_loaded )
1807 nib_open_loaded = [NSBundle loadNibNamed:@"Open" owner:self];
1808 [o_open awakeFromNib];
1815 - (IBAction)intfOpenFileGeneric:(id)sender
1817 if( !nib_open_loaded )
1819 nib_open_loaded = [NSBundle loadNibNamed:@"Open" owner:self];
1820 [o_open awakeFromNib];
1821 [o_open openFileGeneric];
1823 [o_open openFileGeneric];
1827 - (IBAction)intfOpenDisc:(id)sender
1829 if( !nib_open_loaded )
1831 nib_open_loaded = [NSBundle loadNibNamed:@"Open" owner:self];
1832 [o_open awakeFromNib];
1839 - (IBAction)intfOpenNet:(id)sender
1841 if( !nib_open_loaded )
1843 nib_open_loaded = [NSBundle loadNibNamed:@"Open" owner:self];
1844 [o_open awakeFromNib];
1851 - (IBAction)intfOpenCapture:(id)sender
1853 if( !nib_open_loaded )
1855 nib_open_loaded = [NSBundle loadNibNamed:@"Open" owner:self];
1856 [o_open awakeFromNib];
1857 [o_open openCapture];
1859 [o_open openCapture];
1863 - (IBAction)showWizard:(id)sender
1865 if( !nib_wizard_loaded )
1867 nib_wizard_loaded = [NSBundle loadNibNamed:@"Wizard" owner:self];
1868 [o_wizard initStrings];
1869 [o_wizard resetWizard];
1870 [o_wizard showWizard];
1872 [o_wizard resetWizard];
1873 [o_wizard showWizard];
1877 - (IBAction)showExtended:(id)sender
1879 if( o_extended == nil )
1880 o_extended = [[VLCExtended alloc] init];
1882 if( !nib_extended_loaded )
1883 nib_extended_loaded = [NSBundle loadNibNamed:@"Extended" owner:self];
1885 [o_extended showPanel];
1888 - (IBAction)showBookmarks:(id)sender
1890 /* we need the wizard-nib for the bookmarks's extract functionality */
1891 if( !nib_wizard_loaded )
1893 nib_wizard_loaded = [NSBundle loadNibNamed:@"Wizard" owner:self];
1894 [o_wizard initStrings];
1897 if( !nib_bookmarks_loaded )
1898 nib_bookmarks_loaded = [NSBundle loadNibNamed:@"Bookmarks" owner:self];
1900 [o_bookmarks showBookmarks];
1903 - (IBAction)viewAbout:(id)sender
1905 if( !nib_about_loaded )
1906 nib_about_loaded = [NSBundle loadNibNamed:@"About" owner:self];
1908 [o_about showAbout];
1911 - (IBAction)showLicense:(id)sender
1913 if( !nib_about_loaded )
1914 nib_about_loaded = [NSBundle loadNibNamed:@"About" owner:self];
1916 [o_about showGPL: sender];
1919 - (IBAction)viewPreferences:(id)sender
1921 if( !nib_prefs_loaded )
1923 nib_prefs_loaded = [NSBundle loadNibNamed:@"Preferences" owner: self];
1924 o_sprefs = [[VLCSimplePrefs alloc] init];
1925 o_prefs= [[VLCPrefs alloc] init];
1928 [o_sprefs showSimplePrefs];
1931 - (IBAction)checkForUpdate:(id)sender
1934 if( !nib_update_loaded )
1935 nib_update_loaded = [NSBundle loadNibNamed:@"Update" owner:self];
1936 [o_update showUpdateWindow];
1938 msg_Err( VLCIntf, "Update checker wasn't enabled in this build" );
1939 intf_UserFatal( VLCIntf, false, _("Update check failed"), _("Checking for updates was not enabled in this build.") );
1943 - (IBAction)viewHelp:(id)sender
1945 if( !nib_about_loaded )
1947 nib_about_loaded = [NSBundle loadNibNamed:@"About" owner:self];
1954 - (IBAction)openReadMe:(id)sender
1956 NSString * o_path = [[NSBundle mainBundle]
1957 pathForResource: @"README.MacOSX" ofType: @"rtf"];
1959 [[NSWorkspace sharedWorkspace] openFile: o_path
1960 withApplication: @"TextEdit"];
1963 - (IBAction)openDocumentation:(id)sender
1965 NSURL * o_url = [NSURL URLWithString:
1966 @"http://www.videolan.org/doc/"];
1968 [[NSWorkspace sharedWorkspace] openURL: o_url];
1971 - (IBAction)openWebsite:(id)sender
1973 NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org/"];
1975 [[NSWorkspace sharedWorkspace] openURL: o_url];
1978 - (IBAction)openForum:(id)sender
1980 NSURL * o_url = [NSURL URLWithString: @"http://forum.videolan.org/"];
1982 [[NSWorkspace sharedWorkspace] openURL: o_url];
1985 - (IBAction)openDonate:(id)sender
1987 NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org/contribute.html#paypal"];
1989 [[NSWorkspace sharedWorkspace] openURL: o_url];
1992 - (IBAction)openCrashLog:(id)sender
1994 NSString * o_path = [@"~/Library/Logs/CrashReporter/VLC.crash.log"
1995 stringByExpandingTildeInPath];
1998 if( [[NSFileManager defaultManager] fileExistsAtPath: o_path ] )
2000 [[NSWorkspace sharedWorkspace] openFile: o_path
2001 withApplication: @"Console"];
2005 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.") );
2010 - (IBAction)viewErrorsAndWarnings:(id)sender
2012 [[[self getInteractionList] getErrorPanel] showPanel];
2015 - (IBAction)showMessagesPanel:(id)sender
2017 [o_msgs_panel makeKeyAndOrderFront: sender];
2020 - (IBAction)showInformationPanel:(id)sender
2022 if(! nib_info_loaded )
2023 nib_info_loaded = [NSBundle loadNibNamed:@"MediaInfo" owner: self];
2028 - (void)windowDidBecomeKey:(NSNotification *)o_notification
2030 if( [o_notification object] == o_msgs_panel )
2033 NSEnumerator * o_enum;
2035 [o_messages setString: @""];
2039 o_enum = [o_msg_arr objectEnumerator];
2041 while( ( o_msg = [o_enum nextObject] ) != nil )
2043 [o_messages insertText: o_msg];
2046 [o_msg_lock unlock];
2050 - (IBAction)togglePlaylist:(id)sender
2052 NSRect o_rect = [o_window frame];
2053 /*First, check if the playlist is visible*/
2054 if( o_rect.size.height <= 200 )
2056 o_restore_rect = o_rect;
2057 b_restore_size = true;
2058 b_small_window = YES; /* we know we are small, make sure this is actually set (see case below) */
2060 if( o_size_with_playlist.height > 200 )
2062 o_rect.size.height = o_size_with_playlist.height;
2064 o_rect.size.height = 500;
2067 if( o_size_with_playlist.width > [o_window minSize].width )
2069 o_rect.size.width = o_size_with_playlist.width;
2071 o_rect.size.width = 500;
2074 o_rect.size.height = (o_size_with_playlist.height > 200) ?
2075 o_size_with_playlist.height : 500;
2076 o_rect.origin.x = [o_window frame].origin.x;
2077 o_rect.origin.y = [o_window frame].origin.y - o_rect.size.height +
2078 [o_window minSize].height;
2080 NSRect screenRect = [[o_window screen] visibleFrame];
2081 if( !NSContainsRect( screenRect, o_rect ) ) {
2082 if( NSMaxX(o_rect) > NSMaxX(screenRect) )
2083 o_rect.origin.x = ( NSMaxX(screenRect) - o_rect.size.width );
2084 if( NSMinY(o_rect) < NSMinY(screenRect) )
2085 o_rect.origin.y = ( NSMinY(screenRect) );
2088 [o_btn_playlist setState: YES];
2092 NSSize curSize = o_rect.size;
2094 o_rect.size.height = [o_window minSize].height;
2095 o_rect.size.width = [o_window minSize].width;
2096 o_rect.origin.x = [o_window frame].origin.x;
2097 /* Calculate the position of the lower right corner after resize */
2098 o_rect.origin.y = [o_window frame].origin.y +
2099 [o_window frame].size.height - [o_window minSize].height;
2101 if( b_restore_size )
2102 o_rect = o_restore_rect;
2104 [o_playlist_view setAutoresizesSubviews: NO];
2105 [o_playlist_view removeFromSuperview];
2106 [o_btn_playlist setState: NO];
2107 b_small_window = NO; /* we aren't small here just yet. we are doing an animated resize after this */
2110 [o_window setFrame: o_rect display:YES animate: YES];
2113 - (void)updateTogglePlaylistState
2115 if( [o_window frame].size.height <= 200 )
2117 [o_btn_playlist setState: NO];
2121 [o_btn_playlist setState: YES];
2125 - (NSSize)windowWillResize:(NSWindow *)sender toSize:(NSSize)proposedFrameSize
2127 /* Not triggered on a window resize or maxification of the window. only by window mouse dragging resize */
2129 /*Stores the size the controller one resize, to be able to restore it when
2130 toggling the playlist*/
2131 o_size_with_playlist = proposedFrameSize;
2133 if( proposedFrameSize.height <= 200 )
2135 if( b_small_window == NO )
2137 /* if large and going to small then hide */
2138 b_small_window = YES;
2139 [o_playlist_view setAutoresizesSubviews: NO];
2140 [o_playlist_view removeFromSuperview];
2142 return NSMakeSize( proposedFrameSize.width, [o_window minSize].height);
2144 return proposedFrameSize;
2147 - (void)windowDidMove:(NSNotification *)notif
2149 b_restore_size = false;
2152 - (void)windowDidResize:(NSNotification *)notif
2154 if( [o_window frame].size.height > 200 && b_small_window )
2156 /* If large and coming from small then show */
2157 [o_playlist_view setAutoresizesSubviews: YES];
2158 [o_playlist_view setFrame: NSMakeRect( 0, 0, [o_window frame].size.width, [o_window frame].size.height - [o_window minSize].height )];
2159 [o_playlist_view setNeedsDisplay:YES];
2160 [[o_window contentView] addSubview: o_playlist_view];
2161 b_small_window = NO;
2163 [self updateTogglePlaylistState];
2168 @implementation VLCMain (NSMenuValidation)
2170 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
2172 NSString *o_title = [o_mi title];
2173 BOOL bEnabled = TRUE;
2175 /* Recent Items Menu */
2176 if( [o_title isEqualToString: _NS("Clear Menu")] )
2178 NSMenu * o_menu = [o_mi_open_recent submenu];
2179 int i_nb_items = [o_menu numberOfItems];
2180 NSArray * o_docs = [[NSDocumentController sharedDocumentController]
2181 recentDocumentURLs];
2182 UInt32 i_nb_docs = [o_docs count];
2184 if( i_nb_items > 1 )
2186 while( --i_nb_items )
2188 [o_menu removeItemAtIndex: 0];
2197 [o_menu insertItem: [NSMenuItem separatorItem] atIndex: 0];
2203 o_url = [o_docs objectAtIndex: i_nb_docs];
2205 if( [o_url isFileURL] )
2207 o_doc = [o_url path];
2211 o_doc = [o_url absoluteString];
2214 [o_menu insertItemWithTitle: o_doc
2215 action: @selector(openRecentItem:)
2216 keyEquivalent: @"" atIndex: 0];
2218 if( i_nb_docs == 0 )
2234 @implementation VLCMain (Internal)
2236 - (void)handlePortMessage:(NSPortMessage *)o_msg
2241 NSInvocation * o_inv;
2242 NSConditionLock * o_lock;
2244 o_data = [[o_msg components] lastObject];
2245 o_inv = *((NSInvocation **)[o_data bytes]);
2246 [o_inv getArgument: &o_value atIndex: 2];
2247 val = (id **)[o_value pointerValue];
2248 [o_inv setArgument: val[1] atIndex: 2];
2253 [o_lock unlockWithCondition: 1];