1 /*****************************************************************************
2 * intf.m: MacOS X interface module
3 *****************************************************************************
4 * Copyright (C) 2002-2007 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 */
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 E_(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->o_sendport = [[NSPort port] retain];
109 p_intf->p_sys->p_sub = msg_Subscribe( p_intf, MSG_QUEUE_NORMAL );
110 p_intf->b_play = VLC_TRUE;
111 p_intf->pf_run = Run;
112 p_intf->b_should_run_on_first_thread = VLC_TRUE;
117 /*****************************************************************************
118 * CloseIntf: destroy interface
119 *****************************************************************************/
120 void E_(CloseIntf) ( vlc_object_t *p_this )
122 intf_thread_t *p_intf = (intf_thread_t*) p_this;
124 [[VLCMain sharedInstance] setIntf: nil];
126 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
128 [p_intf->p_sys->o_sendport release];
129 [p_intf->p_sys->o_pool release];
131 free( p_intf->p_sys );
134 /*****************************************************************************
135 * KillerThread: Thread that kill the application
136 *****************************************************************************/
137 static void * KillerThread( void *user_data )
139 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
141 intf_thread_t *p_intf = user_data;
143 vlc_object_lock ( p_intf );
144 while( vlc_object_alive( p_intf ) )
145 vlc_object_wait( p_intf );
146 vlc_object_unlock( p_intf );
148 msg_Dbg( p_intf, "Killing the Mac OS X module\n" );
150 /* We are dead, terminate */
151 [NSApp terminate: nil];
155 /*****************************************************************************
157 *****************************************************************************/
160 static void Run( intf_thread_t *p_intf )
164 /* Do it again - for some unknown reason, vlc_thread_create() often
165 * fails to go to real-time priority with the first launched thread
167 vlc_thread_set_priority( p_intf, VLC_THREAD_PRIORITY_LOW );
169 /* Make sure the "force quit" menu item does quit instantly.
170 * VLC overrides SIGTERM which is sent by the "force quit"
171 * menu item to make sure deamon mode quits gracefully, so
172 * we un-override SIGTERM here. */
174 sigaddset( &set, SIGTERM );
175 pthread_sigmask( SIG_UNBLOCK, &set, NULL );
177 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
179 /* Install a jmpbuffer to where we can go back before the NSApp exit
180 * see applicationWillTerminate: */
181 /* We need that code to run on main thread */
182 [VLCApplication sharedApplication];
183 [NSApp setVLC: p_intf->p_libvlc];
185 [[VLCMain sharedInstance] setIntf: p_intf];
186 [NSBundle loadNibNamed: @"MainMenu" owner: NSApp];
188 /* Setup a thread that will monitor the module killing */
189 pthread_t killer_thread;
190 pthread_create( &killer_thread, NULL, KillerThread, p_intf );
192 /* Install a jmpbuffer to where we can go back before the NSApp exit
193 * see applicationWillTerminate: */
194 if(setjmp(jmpbuffer) == 0)
200 int ExecuteOnMainThread( id target, SEL sel, void * p_arg )
204 //NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
206 if( [target respondsToSelector: @selector(performSelectorOnMainThread:
207 withObject:waitUntilDone:)] )
209 [target performSelectorOnMainThread: sel
210 withObject: [NSValue valueWithPointer: p_arg]
213 else if( NSApp != nil && [[VLCMain sharedInstance] respondsToSelector: @selector(getIntf)] )
218 NSPort * o_recv_port;
219 NSInvocation * o_inv;
220 NSPortMessage * o_msg;
221 intf_thread_t * p_intf;
222 NSConditionLock * o_lock;
223 NSMethodSignature * o_sig;
225 id * val[] = { &o_lock, &o_v2 };
227 p_intf = (intf_thread_t *)VLCIntf;
229 o_recv_port = [[NSPort port] retain];
230 o_v1 = [NSValue valueWithPointer: val];
231 o_v2 = [NSValue valueWithPointer: p_arg];
233 o_sig = [target methodSignatureForSelector: sel];
234 o_inv = [NSInvocation invocationWithMethodSignature: o_sig];
235 [o_inv setArgument: &o_v1 atIndex: 2];
236 [o_inv setTarget: target];
237 [o_inv setSelector: sel];
239 o_array = [NSArray arrayWithObject:
240 [NSData dataWithBytes: &o_inv length: sizeof(o_inv)]];
241 o_msg = [[NSPortMessage alloc]
242 initWithSendPort: p_intf->p_sys->o_sendport
243 receivePort: o_recv_port components: o_array];
245 o_lock = [[NSConditionLock alloc] initWithCondition: 0];
246 [o_msg sendBeforeDate: [NSDate distantPast]];
247 [o_lock lockWhenCondition: 1];
252 [o_recv_port release];
264 /*****************************************************************************
265 * playlistChanged: Callback triggered by the intf-change playlist
266 * variable, to let the intf update the playlist.
267 *****************************************************************************/
268 static int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,
269 vlc_value_t old_val, vlc_value_t new_val, void *param )
271 intf_thread_t * p_intf = VLCIntf;
272 p_intf->p_sys->b_playlist_update = VLC_TRUE;
273 p_intf->p_sys->b_intf_update = VLC_TRUE;
274 p_intf->p_sys->b_playmode_update = VLC_TRUE;
275 p_intf->p_sys->b_current_title_update = VLC_TRUE;
279 /*****************************************************************************
280 * ShowController: Callback triggered by the show-intf playlist variable
281 * through the ShowIntf-control-intf, to let us show the controller-win;
282 * usually when in fullscreen-mode
283 *****************************************************************************/
284 static int ShowController( vlc_object_t *p_this, const char *psz_variable,
285 vlc_value_t old_val, vlc_value_t new_val, void *param )
287 intf_thread_t * p_intf = VLCIntf;
288 p_intf->p_sys->b_intf_show = VLC_TRUE;
292 /*****************************************************************************
293 * FullscreenChanged: Callback triggered by the fullscreen-change playlist
294 * variable, to let the intf update the controller.
295 *****************************************************************************/
296 static int FullscreenChanged( vlc_object_t *p_this, const char *psz_variable,
297 vlc_value_t old_val, vlc_value_t new_val, void *param )
299 intf_thread_t * p_intf = VLCIntf;
300 p_intf->p_sys->b_fullscreen_update = VLC_TRUE;
304 /*****************************************************************************
305 * InteractCallback: Callback triggered by the interaction
306 * variable, to let the intf display error and interaction dialogs
307 *****************************************************************************/
308 static int InteractCallback( vlc_object_t *p_this, const char *psz_variable,
309 vlc_value_t old_val, vlc_value_t new_val, void *param )
311 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
312 VLCMain *interface = (VLCMain *)param;
313 interaction_dialog_t *p_dialog = (interaction_dialog_t *)(new_val.p_address);
314 NSValue *o_value = [NSValue valueWithPointer:p_dialog];
316 [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCNewInteractionEventNotification" object:[interface getInteractionList]
317 userInfo:[NSDictionary dictionaryWithObject:o_value forKey:@"VLCDialogPointer"]];
326 unsigned int i_vlckey;
327 } nskeys_to_vlckeys[] =
329 { NSUpArrowFunctionKey, KEY_UP },
330 { NSDownArrowFunctionKey, KEY_DOWN },
331 { NSLeftArrowFunctionKey, KEY_LEFT },
332 { NSRightArrowFunctionKey, KEY_RIGHT },
333 { NSF1FunctionKey, KEY_F1 },
334 { NSF2FunctionKey, KEY_F2 },
335 { NSF3FunctionKey, KEY_F3 },
336 { NSF4FunctionKey, KEY_F4 },
337 { NSF5FunctionKey, KEY_F5 },
338 { NSF6FunctionKey, KEY_F6 },
339 { NSF7FunctionKey, KEY_F7 },
340 { NSF8FunctionKey, KEY_F8 },
341 { NSF9FunctionKey, KEY_F9 },
342 { NSF10FunctionKey, KEY_F10 },
343 { NSF11FunctionKey, KEY_F11 },
344 { NSF12FunctionKey, KEY_F12 },
345 { NSHomeFunctionKey, KEY_HOME },
346 { NSEndFunctionKey, KEY_END },
347 { NSPageUpFunctionKey, KEY_PAGEUP },
348 { NSPageDownFunctionKey, KEY_PAGEDOWN },
349 { NSTabCharacter, KEY_TAB },
350 { NSCarriageReturnCharacter, KEY_ENTER },
351 { NSEnterCharacter, KEY_ENTER },
352 { NSBackspaceCharacter, KEY_BACKSPACE },
353 { (unichar) ' ', KEY_SPACE },
354 { (unichar) 0x1b, KEY_ESC },
358 unichar VLCKeyToCocoa( unsigned int i_key )
362 for( i = 0; nskeys_to_vlckeys[i].i_vlckey != 0; i++ )
364 if( nskeys_to_vlckeys[i].i_vlckey == (i_key & ~KEY_MODIFIER) )
366 return nskeys_to_vlckeys[i].i_nskey;
369 return (unichar)(i_key & ~KEY_MODIFIER);
372 unsigned int CocoaKeyToVLC( unichar i_key )
376 for( i = 0; nskeys_to_vlckeys[i].i_nskey != 0; i++ )
378 if( nskeys_to_vlckeys[i].i_nskey == i_key )
380 return nskeys_to_vlckeys[i].i_vlckey;
383 return (unsigned int)i_key;
386 unsigned int VLCModifiersToCocoa( unsigned int i_key )
388 unsigned int new = 0;
389 if( i_key & KEY_MODIFIER_COMMAND )
390 new |= NSCommandKeyMask;
391 if( i_key & KEY_MODIFIER_ALT )
392 new |= NSAlternateKeyMask;
393 if( i_key & KEY_MODIFIER_SHIFT )
394 new |= NSShiftKeyMask;
395 if( i_key & KEY_MODIFIER_CTRL )
396 new |= NSControlKeyMask;
400 /*****************************************************************************
401 * VLCMain implementation
402 *****************************************************************************/
403 @implementation VLCMain
405 static VLCMain *_o_sharedMainInstance = nil;
407 + (VLCMain *)sharedInstance
409 return _o_sharedMainInstance ? _o_sharedMainInstance : [[self alloc] init];
414 if( _o_sharedMainInstance)
417 return _o_sharedMainInstance;
420 _o_sharedMainInstance = [super init];
422 o_about = [[VLAboutBox alloc] init];
423 o_prefs = [[VLCPrefs alloc] init];
424 o_open = [[VLCOpen alloc] init];
425 o_wizard = [[VLCWizard alloc] init];
427 o_bookmarks = [[VLCBookmarks alloc] init];
428 o_embedded_list = [[VLCEmbeddedList alloc] init];
429 o_interaction_list = [[VLCInteractionList alloc] init];
432 o_update = [[VLCUpdate alloc] init];
435 i_lastShownVolume = -1;
437 o_remote = [[AppleRemote alloc] init];
438 [o_remote setClickCountEnabledButtons: kRemoteButtonPlay];
439 [o_remote setDelegate: _o_sharedMainInstance];
441 o_eyetv = [[VLCEyeTVController alloc] init];
443 /* announce our launch to a potential eyetv plugin */
444 [[NSDistributedNotificationCenter defaultCenter] postNotificationName: @"VLCOSXGUIInit"
445 object: @"VLCEyeTVSupport"
447 deliverImmediately: YES];
449 return _o_sharedMainInstance;
452 - (void)setIntf: (intf_thread_t *)p_mainintf {
456 - (intf_thread_t *)getIntf {
462 unsigned int i_key = 0;
463 playlist_t *p_playlist;
466 /* Check if we already did this once. Opening the other nibs calls it too, because VLCMain is the owner */
467 if( nib_main_loaded ) return;
470 [o_window setExcludedFromWindowsMenu: TRUE];
471 [o_msgs_panel setExcludedFromWindowsMenu: TRUE];
472 [o_msgs_panel setDelegate: self];
474 i_key = config_GetInt( p_intf, "key-quit" );
475 [o_mi_quit setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
476 [o_mi_quit setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
477 i_key = config_GetInt( p_intf, "key-play-pause" );
478 [o_mi_play setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
479 [o_mi_play setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
480 i_key = config_GetInt( p_intf, "key-stop" );
481 [o_mi_stop setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
482 [o_mi_stop setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
483 i_key = config_GetInt( p_intf, "key-faster" );
484 [o_mi_faster setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
485 [o_mi_faster setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
486 i_key = config_GetInt( p_intf, "key-slower" );
487 [o_mi_slower setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
488 [o_mi_slower setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
489 i_key = config_GetInt( p_intf, "key-prev" );
490 [o_mi_previous setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
491 [o_mi_previous setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
492 i_key = config_GetInt( p_intf, "key-next" );
493 [o_mi_next setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
494 [o_mi_next setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
495 i_key = config_GetInt( p_intf, "key-jump+short" );
496 [o_mi_fwd setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
497 [o_mi_fwd setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
498 i_key = config_GetInt( p_intf, "key-jump-short" );
499 [o_mi_bwd setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
500 [o_mi_bwd setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
501 i_key = config_GetInt( p_intf, "key-jump+medium" );
502 [o_mi_fwd1m setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
503 [o_mi_fwd1m setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
504 i_key = config_GetInt( p_intf, "key-jump-medium" );
505 [o_mi_bwd1m setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
506 [o_mi_bwd1m setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
507 i_key = config_GetInt( p_intf, "key-jump+long" );
508 [o_mi_fwd5m setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
509 [o_mi_fwd5m setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
510 i_key = config_GetInt( p_intf, "key-jump-long" );
511 [o_mi_bwd5m setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
512 [o_mi_bwd5m setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
513 i_key = config_GetInt( p_intf, "key-vol-up" );
514 [o_mi_vol_up setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
515 [o_mi_vol_up setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
516 i_key = config_GetInt( p_intf, "key-vol-down" );
517 [o_mi_vol_down setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
518 [o_mi_vol_down setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
519 i_key = config_GetInt( p_intf, "key-vol-mute" );
520 [o_mi_mute setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
521 [o_mi_mute setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
522 i_key = config_GetInt( p_intf, "key-fullscreen" );
523 [o_mi_fullscreen setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
524 [o_mi_fullscreen setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
525 i_key = config_GetInt( p_intf, "key-snapshot" );
526 [o_mi_snapshot setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
527 [o_mi_snapshot setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
529 var_Create( p_intf, "intf-change", VLC_VAR_BOOL );
531 [self setSubmenusEnabled: FALSE];
532 [self manageVolumeSlider];
533 [o_window setDelegate: self];
535 b_restore_size = false;
536 if( [o_window frame].size.height <= 200 )
538 b_small_window = YES;
539 [o_window setFrame: NSMakeRect( [o_window frame].origin.x,
540 [o_window frame].origin.y, [o_window frame].size.width,
541 [o_window minSize].height ) display: YES animate:YES];
542 [o_playlist_view setAutoresizesSubviews: NO];
547 [o_playlist_view setFrame: NSMakeRect( 10, 10, [o_window frame].size.width - 20, [o_window frame].size.height - 105 )];
548 [o_playlist_view setNeedsDisplay:YES];
549 [o_playlist_view setAutoresizesSubviews: YES];
550 [[o_window contentView] addSubview: o_playlist_view];
552 [self updateTogglePlaylistState];
554 o_size_with_playlist = [o_window frame].size;
556 p_playlist = pl_Yield( p_intf );
558 /* Check if we need to start playing */
561 playlist_Control( p_playlist, PLAYLIST_PLAY, VLC_FALSE );
563 var_Create( p_playlist, "fullscreen", VLC_VAR_BOOL | VLC_VAR_DOINHERIT);
564 val.b_bool = VLC_FALSE;
566 var_AddCallback( p_playlist, "fullscreen", FullscreenChanged, self);
567 var_AddCallback( p_playlist, "intf-show", ShowController, self);
569 vlc_object_release( p_playlist );
571 var_Create( p_intf, "interaction", VLC_VAR_ADDRESS );
572 var_AddCallback( p_intf, "interaction", InteractCallback, self );
573 p_intf->b_interaction = VLC_TRUE;
575 /* update the playmode stuff */
576 p_intf->p_sys->b_playmode_update = VLC_TRUE;
578 [[NSNotificationCenter defaultCenter] addObserver: self
579 selector: @selector(refreshVoutDeviceMenu:)
580 name: NSApplicationDidChangeScreenParametersNotification
583 o_img_play = [NSImage imageNamed: @"play"];
584 o_img_pause = [NSImage imageNamed: @"pause"];
586 [self controlTintChanged];
588 [[NSNotificationCenter defaultCenter] addObserver: self
589 selector: @selector( controlTintChanged )
590 name: NSControlTintDidChangeNotification
593 nib_main_loaded = TRUE;
596 - (void)controlTintChanged
600 if( [o_btn_play alternateImage] == o_img_play_pressed )
603 if( [NSColor currentControlTint] == NSGraphiteControlTint )
605 o_img_play_pressed = [NSImage imageNamed: @"play_graphite"];
606 o_img_pause_pressed = [NSImage imageNamed: @"pause_graphite"];
608 [o_btn_prev setAlternateImage: [NSImage imageNamed: @"previous_graphite"]];
609 [o_btn_rewind setAlternateImage: [NSImage imageNamed: @"skip_previous_graphite"]];
610 [o_btn_stop setAlternateImage: [NSImage imageNamed: @"stop_graphite"]];
611 [o_btn_ff setAlternateImage: [NSImage imageNamed: @"skip_forward_graphite"]];
612 [o_btn_next setAlternateImage: [NSImage imageNamed: @"next_graphite"]];
613 [o_btn_fullscreen setAlternateImage: [NSImage imageNamed: @"fullscreen_graphite"]];
614 [o_btn_playlist setAlternateImage: [NSImage imageNamed: @"playlistdrawer_graphite"]];
615 [o_btn_equalizer setAlternateImage: [NSImage imageNamed: @"equalizerdrawer_graphite"]];
619 o_img_play_pressed = [NSImage imageNamed: @"play_blue"];
620 o_img_pause_pressed = [NSImage imageNamed: @"pause_blue"];
622 [o_btn_prev setAlternateImage: [NSImage imageNamed: @"previous_blue"]];
623 [o_btn_rewind setAlternateImage: [NSImage imageNamed: @"skip_previous_blue"]];
624 [o_btn_stop setAlternateImage: [NSImage imageNamed: @"stop_blue"]];
625 [o_btn_ff setAlternateImage: [NSImage imageNamed: @"skip_forward_blue"]];
626 [o_btn_next setAlternateImage: [NSImage imageNamed: @"next_blue"]];
627 [o_btn_fullscreen setAlternateImage: [NSImage imageNamed: @"fullscreen_blue"]];
628 [o_btn_playlist setAlternateImage: [NSImage imageNamed: @"playlistdrawer_blue"]];
629 [o_btn_equalizer setAlternateImage: [NSImage imageNamed: @"equalizerdrawer_blue"]];
633 [o_btn_play setAlternateImage: o_img_play_pressed];
635 [o_btn_play setAlternateImage: o_img_pause_pressed];
640 [o_window setTitle: _NS("VLC - Controller")];
641 [self setScrollField:_NS("VLC media player") stopAfter:-1];
643 /* button controls */
644 [o_btn_prev setToolTip: _NS("Previous")];
645 [o_btn_rewind setToolTip: _NS("Rewind")];
646 [o_btn_play setToolTip: _NS("Play")];
647 [o_btn_stop setToolTip: _NS("Stop")];
648 [o_btn_ff setToolTip: _NS("Fast Forward")];
649 [o_btn_next setToolTip: _NS("Next")];
650 [o_btn_fullscreen setToolTip: _NS("Fullscreen")];
651 [o_volumeslider setToolTip: _NS("Volume")];
652 [o_timeslider setToolTip: _NS("Position")];
653 [o_btn_playlist setToolTip: _NS("Playlist")];
656 [o_msgs_panel setTitle: _NS("Messages")];
657 [o_msgs_btn_crashlog setTitle: _NS("Open CrashLog...")];
660 [o_mi_about setTitle: [_NS("About VLC media player") \
661 stringByAppendingString: @"..."]];
662 [o_mi_checkForUpdate setTitle: _NS("Check for Update...")];
663 [o_mi_prefs setTitle: _NS("Preferences...")];
664 [o_mi_add_intf setTitle: _NS("Add Interface")];
665 [o_mu_add_intf setTitle: _NS("Add Interface")];
666 [o_mi_services setTitle: _NS("Services")];
667 [o_mi_hide setTitle: _NS("Hide VLC")];
668 [o_mi_hide_others setTitle: _NS("Hide Others")];
669 [o_mi_show_all setTitle: _NS("Show All")];
670 [o_mi_quit setTitle: _NS("Quit VLC")];
672 [o_mu_file setTitle: _ANS("1:File")];
673 [o_mi_open_generic setTitle: _NS("Open File...")];
674 [o_mi_open_file setTitle: _NS("Quick Open File...")];
675 [o_mi_open_disc setTitle: _NS("Open Disc...")];
676 [o_mi_open_net setTitle: _NS("Open Network...")];
677 [o_mi_open_recent setTitle: _NS("Open Recent")];
678 [o_mi_open_recent_cm setTitle: _NS("Clear Menu")];
679 [o_mi_open_wizard setTitle: _NS("Streaming/Exporting Wizard...")];
681 [o_mu_edit setTitle: _NS("Edit")];
682 [o_mi_cut setTitle: _NS("Cut")];
683 [o_mi_copy setTitle: _NS("Copy")];
684 [o_mi_paste setTitle: _NS("Paste")];
685 [o_mi_clear setTitle: _NS("Clear")];
686 [o_mi_select_all setTitle: _NS("Select All")];
688 [o_mu_controls setTitle: _NS("Playback")];
689 [o_mi_play setTitle: _NS("Play")];
690 [o_mi_stop setTitle: _NS("Stop")];
691 [o_mi_faster setTitle: _NS("Faster")];
692 [o_mi_slower setTitle: _NS("Slower")];
693 [o_mi_previous setTitle: _NS("Previous")];
694 [o_mi_next setTitle: _NS("Next")];
695 [o_mi_random setTitle: _NS("Random")];
696 [o_mi_repeat setTitle: _NS("Repeat One")];
697 [o_mi_loop setTitle: _NS("Repeat All")];
698 [o_mi_fwd setTitle: _NS("Step Forward")];
699 [o_mi_bwd setTitle: _NS("Step Backward")];
701 [o_mi_program setTitle: _NS("Program")];
702 [o_mu_program setTitle: _NS("Program")];
703 [o_mi_title setTitle: _NS("Title")];
704 [o_mu_title setTitle: _NS("Title")];
705 [o_mi_chapter setTitle: _NS("Chapter")];
706 [o_mu_chapter setTitle: _NS("Chapter")];
708 [o_mu_audio setTitle: _NS("Audio")];
709 [o_mi_vol_up setTitle: _NS("Volume Up")];
710 [o_mi_vol_down setTitle: _NS("Volume Down")];
711 [o_mi_mute setTitle: _NS("Mute")];
712 [o_mi_audiotrack setTitle: _NS("Audio Track")];
713 [o_mu_audiotrack setTitle: _NS("Audio Track")];
714 [o_mi_channels setTitle: _NS("Audio Channels")];
715 [o_mu_channels setTitle: _NS("Audio Channels")];
716 [o_mi_device setTitle: _NS("Audio Device")];
717 [o_mu_device setTitle: _NS("Audio Device")];
718 [o_mi_visual setTitle: _NS("Visualizations")];
719 [o_mu_visual setTitle: _NS("Visualizations")];
721 [o_mu_video setTitle: _NS("Video")];
722 [o_mi_half_window setTitle: _NS("Half Size")];
723 [o_mi_normal_window setTitle: _NS("Normal Size")];
724 [o_mi_double_window setTitle: _NS("Double Size")];
725 [o_mi_fittoscreen setTitle: _NS("Fit to Screen")];
726 [o_mi_fullscreen setTitle: _NS("Fullscreen")];
727 [o_mi_floatontop setTitle: _NS("Float on Top")];
728 [o_mi_snapshot setTitle: _NS("Snapshot")];
729 [o_mi_videotrack setTitle: _NS("Video Track")];
730 [o_mu_videotrack setTitle: _NS("Video Track")];
731 [o_mi_aspect_ratio setTitle: _NS("Aspect-ratio")];
732 [o_mu_aspect_ratio setTitle: _NS("Aspect-ratio")];
733 [o_mi_crop setTitle: _NS("Crop")];
734 [o_mu_crop setTitle: _NS("Crop")];
735 [o_mi_screen setTitle: _NS("Video Device")];
736 [o_mu_screen setTitle: _NS("Video Device")];
737 [o_mi_subtitle setTitle: _NS("Subtitles Track")];
738 [o_mu_subtitle setTitle: _NS("Subtitles Track")];
739 [o_mi_deinterlace setTitle: _NS("Deinterlace")];
740 [o_mu_deinterlace setTitle: _NS("Deinterlace")];
741 [o_mi_ffmpeg_pp setTitle: _NS("Post processing")];
742 [o_mu_ffmpeg_pp setTitle: _NS("Post processing")];
744 [o_mu_window setTitle: _NS("Window")];
745 [o_mi_minimize setTitle: _NS("Minimize Window")];
746 [o_mi_close_window setTitle: _NS("Close Window")];
747 [o_mi_controller setTitle: _NS("Controller...")];
748 [o_mi_equalizer setTitle: _NS("Equalizer...")];
749 [o_mi_extended setTitle: _NS("Extended Controls...")];
750 [o_mi_bookmarks setTitle: _NS("Bookmarks...")];
751 [o_mi_playlist setTitle: _NS("Playlist...")];
752 [o_mi_info setTitle: _NS("Media Information...")];
753 [o_mi_messages setTitle: _NS("Messages...")];
754 [o_mi_errorsAndWarnings setTitle: _NS("Errors and Warnings...")];
756 [o_mi_bring_atf setTitle: _NS("Bring All to Front")];
758 [o_mu_help setTitle: _NS("Help")];
759 [o_mi_help setTitle: _NS("VLC media player Help...")];
760 [o_mi_readme setTitle: _NS("ReadMe / FAQ...")];
761 [o_mi_license setTitle: _NS("License")];
762 [o_mi_documentation setTitle: _NS("Online Documentation...")];
763 [o_mi_website setTitle: _NS("VideoLAN Website...")];
764 [o_mi_donation setTitle: _NS("Make a donation...")];
765 [o_mi_forum setTitle: _NS("Online Forum...")];
768 [o_dmi_play setTitle: _NS("Play")];
769 [o_dmi_stop setTitle: _NS("Stop")];
770 [o_dmi_next setTitle: _NS("Next")];
771 [o_dmi_previous setTitle: _NS("Previous")];
772 [o_dmi_mute setTitle: _NS("Mute")];
775 [o_vmi_play setTitle: _NS("Play")];
776 [o_vmi_stop setTitle: _NS("Stop")];
777 [o_vmi_prev setTitle: _NS("Previous")];
778 [o_vmi_next setTitle: _NS("Next")];
779 [o_vmi_volup setTitle: _NS("Volume Up")];
780 [o_vmi_voldown setTitle: _NS("Volume Down")];
781 [o_vmi_mute setTitle: _NS("Mute")];
782 [o_vmi_fullscreen setTitle: _NS("Fullscreen")];
783 [o_vmi_snapshot setTitle: _NS("Snapshot")];
785 [o_info_window setTitle: _NS("Media Information")];
788 - (void)applicationWillFinishLaunching:(NSNotification *)o_notification
790 o_msg_lock = [[NSLock alloc] init];
791 o_msg_arr = [[NSMutableArray arrayWithCapacity: 200] retain];
793 [p_intf->p_sys->o_sendport setDelegate: self];
794 [[NSRunLoop currentRunLoop]
795 addPort: p_intf->p_sys->o_sendport
796 forMode: NSDefaultRunLoopMode];
798 [NSTimer scheduledTimerWithTimeInterval: 0.5
799 target: self selector: @selector(manageIntf:)
800 userInfo: nil repeats: FALSE];
802 [NSThread detachNewThreadSelector: @selector(manage)
803 toTarget: self withObject: nil];
805 [o_controls setupVarMenuItem: o_mi_add_intf target: (vlc_object_t *)p_intf
806 var: "intf-add" selector: @selector(toggleVar:)];
808 /* check whether the user runs a valid version of OSX; alert is auto-released */
809 if( MACOS_VERSION < 10.4f )
813 ourAlert = [NSAlert alertWithMessageText: _NS("Your version of Mac OS X is not supported")
814 defaultButton: _NS("Quit")
815 alternateButton: NULL
817 informativeTextWithFormat: _NS("VLC media player requires Mac OS X 10.4 or higher.")];
818 [ourAlert setAlertStyle: NSCriticalAlertStyle];
819 i_returnValue = [ourAlert runModal];
820 [NSApp terminate: self];
823 vlc_thread_set_priority( p_intf, VLC_THREAD_PRIORITY_LOW );
826 - (BOOL)application:(NSApplication *)o_app openFile:(NSString *)o_filename
828 BOOL b_autoplay = config_GetInt( VLCIntf, "macosx-autoplay" );
829 NSDictionary *o_dic = [NSDictionary dictionaryWithObjectsAndKeys: o_filename, @"ITEM_URL", nil];
831 [o_playlist appendArray: [NSArray arrayWithObject: o_dic] atPos: -1 enqueue: NO];
833 [o_playlist appendArray: [NSArray arrayWithObject: o_dic] atPos: -1 enqueue: YES];
838 - (NSString *)localizedString:(const char *)psz
840 NSString * o_str = nil;
844 o_str = [[[NSString alloc] initWithUTF8String: psz] autorelease];
848 msg_Err( VLCIntf, "could not translate: %s", psz );
854 msg_Warn( VLCIntf, "can't translate empty strings" );
861 /* When user click in the Dock icon our double click in the finder */
862 - (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)hasVisibleWindows
864 if(!hasVisibleWindows)
865 [o_window makeKeyAndOrderFront:self];
870 - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
873 /* Check for update silently on startup */
874 if( !nib_update_loaded )
875 nib_update_loaded = [NSBundle loadNibNamed:@"Update" owner:self];
877 if([o_update shouldCheckForUpdate])
878 [NSThread detachNewThreadSelector:@selector(checkForUpdate) toTarget:o_update withObject:NULL];
881 /* Handle sleep notification */
882 [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(computerWillSleep:)
883 name:NSWorkspaceWillSleepNotification object:nil];
886 /* Listen to the remote in exclusive mode, only when VLC is the active
888 - (void)applicationDidBecomeActive:(NSNotification *)aNotification
890 [o_remote startListening: self];
892 - (void)applicationDidResignActive:(NSNotification *)aNotification
894 [o_remote stopListening: self];
897 /* Triggered when the computer goes to sleep */
898 - (void)computerWillSleep: (NSNotification *)notification
901 if( p_intf->p_sys->i_play_status == PLAYING_S )
904 val.i_int = config_GetInt( p_intf, "key-play-pause" );
905 var_Set( p_intf->p_libvlc, "key-pressed", val );
909 /* Helper method for the remote control interface in order to trigger forward/backward and volume
910 increase/decrease as long as the user holds the left/right, plus/minus button */
911 - (void) executeHoldActionForRemoteButton: (NSNumber*) buttonIdentifierNumber
913 if(b_remote_button_hold)
915 switch([buttonIdentifierNumber intValue])
917 case kRemoteButtonRight_Hold:
918 [o_controls forward: self];
920 case kRemoteButtonLeft_Hold:
921 [o_controls backward: self];
923 case kRemoteButtonVolume_Plus_Hold:
924 [o_controls volumeUp: self];
926 case kRemoteButtonVolume_Minus_Hold:
927 [o_controls volumeDown: self];
930 if(b_remote_button_hold)
933 [self performSelector:@selector(executeHoldActionForRemoteButton:)
934 withObject:buttonIdentifierNumber
940 /* Apple Remote callback */
941 - (void) appleRemoteButton: (AppleRemoteEventIdentifier)buttonIdentifier
942 pressedDown: (BOOL) pressedDown
943 clickCount: (unsigned int) count
945 switch( buttonIdentifier )
947 case kRemoteButtonPlay:
949 [o_controls toogleFullscreen:self];
951 [o_controls play: self];
954 case kRemoteButtonVolume_Plus:
955 [o_controls volumeUp: self];
957 case kRemoteButtonVolume_Minus:
958 [o_controls volumeDown: self];
960 case kRemoteButtonRight:
961 [o_controls next: self];
963 case kRemoteButtonLeft:
964 [o_controls prev: self];
966 case kRemoteButtonRight_Hold:
967 case kRemoteButtonLeft_Hold:
968 case kRemoteButtonVolume_Plus_Hold:
969 case kRemoteButtonVolume_Minus_Hold:
970 /* simulate an event as long as the user holds the button */
971 b_remote_button_hold = pressedDown;
974 NSNumber* buttonIdentifierNumber = [NSNumber numberWithInt: buttonIdentifier];
975 [self performSelector:@selector(executeHoldActionForRemoteButton:)
976 withObject:buttonIdentifierNumber];
979 case kRemoteButtonMenu:
980 [o_controls showPosition: self];
983 /* Add here whatever you want other buttons to do */
988 - (char *)delocalizeString:(NSString *)id
990 NSData * o_data = [id dataUsingEncoding: NSUTF8StringEncoding
991 allowLossyConversion: NO];
996 o_data = [id dataUsingEncoding: NSUTF8StringEncoding
997 allowLossyConversion: YES];
998 psz_string = malloc( [o_data length] + 1 );
999 [o_data getBytes: psz_string];
1000 psz_string[ [o_data length] ] = '\0';
1001 msg_Err( VLCIntf, "cannot convert to the requested encoding: %s",
1006 psz_string = malloc( [o_data length] + 1 );
1007 [o_data getBytes: psz_string];
1008 psz_string[ [o_data length] ] = '\0';
1014 /* i_width is in pixels */
1015 - (NSString *)wrapString: (NSString *)o_in_string toWidth: (int) i_width
1017 NSMutableString *o_wrapped;
1018 NSString *o_out_string;
1019 NSRange glyphRange, effectiveRange, charRange;
1020 NSRect lineFragmentRect;
1021 unsigned glyphIndex, breaksInserted = 0;
1023 NSTextStorage *o_storage = [[NSTextStorage alloc] initWithString: o_in_string
1024 attributes: [NSDictionary dictionaryWithObjectsAndKeys:
1025 [NSFont labelFontOfSize: 0.0], NSFontAttributeName, nil]];
1026 NSLayoutManager *o_layout_manager = [[NSLayoutManager alloc] init];
1027 NSTextContainer *o_container = [[NSTextContainer alloc]
1028 initWithContainerSize: NSMakeSize(i_width, 2000)];
1030 [o_layout_manager addTextContainer: o_container];
1031 [o_container release];
1032 [o_storage addLayoutManager: o_layout_manager];
1033 [o_layout_manager release];
1035 o_wrapped = [o_in_string mutableCopy];
1036 glyphRange = [o_layout_manager glyphRangeForTextContainer: o_container];
1038 for( glyphIndex = glyphRange.location ; glyphIndex < NSMaxRange(glyphRange) ;
1039 glyphIndex += effectiveRange.length) {
1040 lineFragmentRect = [o_layout_manager lineFragmentRectForGlyphAtIndex: glyphIndex
1041 effectiveRange: &effectiveRange];
1042 charRange = [o_layout_manager characterRangeForGlyphRange: effectiveRange
1043 actualGlyphRange: &effectiveRange];
1044 if([o_wrapped lineRangeForRange:
1045 NSMakeRange(charRange.location + breaksInserted, charRange.length)].length > charRange.length) {
1046 [o_wrapped insertString: @"\n" atIndex: NSMaxRange(charRange) + breaksInserted];
1050 o_out_string = [NSString stringWithString: o_wrapped];
1051 [o_wrapped release];
1052 [o_storage release];
1054 return o_out_string;
1058 /*****************************************************************************
1059 * hasDefinedShortcutKey: Check to see if the key press is a defined VLC
1060 * shortcut key. If it is, pass it off to VLC for handling and return YES,
1061 * otherwise ignore it and return NO (where it will get handled by Cocoa).
1062 *****************************************************************************/
1063 - (BOOL)hasDefinedShortcutKey:(NSEvent *)o_event
1067 unsigned int i_pressed_modifiers = 0;
1068 struct hotkey *p_hotkeys;
1072 p_hotkeys = p_intf->p_libvlc->p_hotkeys;
1074 i_pressed_modifiers = [o_event modifierFlags];
1076 if( i_pressed_modifiers & NSShiftKeyMask )
1077 val.i_int |= KEY_MODIFIER_SHIFT;
1078 if( i_pressed_modifiers & NSControlKeyMask )
1079 val.i_int |= KEY_MODIFIER_CTRL;
1080 if( i_pressed_modifiers & NSAlternateKeyMask )
1081 val.i_int |= KEY_MODIFIER_ALT;
1082 if( i_pressed_modifiers & NSCommandKeyMask )
1083 val.i_int |= KEY_MODIFIER_COMMAND;
1085 key = [[o_event charactersIgnoringModifiers] characterAtIndex: 0];
1089 case NSDeleteCharacter:
1090 case NSDeleteFunctionKey:
1091 case NSDeleteCharFunctionKey:
1092 case NSBackspaceCharacter:
1093 case NSUpArrowFunctionKey:
1094 case NSDownArrowFunctionKey:
1095 case NSRightArrowFunctionKey:
1096 case NSLeftArrowFunctionKey:
1097 case NSEnterCharacter:
1098 case NSCarriageReturnCharacter:
1102 val.i_int |= CocoaKeyToVLC( key );
1104 for( i = 0; p_hotkeys[i].psz_action != NULL; i++ )
1106 if( p_hotkeys[i].i_key == val.i_int )
1108 var_Set( p_intf->p_libvlc, "key-pressed", val );
1124 - (id)getSimplePreferences
1129 if( !nib_prefs_loaded )
1130 nib_prefs_loaded = [NSBundle loadNibNamed:@"Preferences" owner: self];
1135 - (id)getPreferences
1140 if( !nib_prefs_loaded )
1141 nib_prefs_loaded = [NSBundle loadNibNamed:@"Preferences" owner: self];
1178 - (id)getEmbeddedList
1180 if( o_embedded_list )
1181 return o_embedded_list;
1186 - (id)getInteractionList
1188 if( o_interaction_list )
1189 return o_interaction_list;
1194 - (id)getMainIntfPgbar
1197 return o_main_pgbar;
1202 - (id)getControllerWindow
1214 - (id)getEyeTVController
1224 playlist_t * p_playlist;
1226 /* new thread requires a new pool */
1227 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
1229 vlc_thread_set_priority( p_intf, VLC_THREAD_PRIORITY_LOW );
1231 p_playlist = pl_Yield( p_intf );
1233 var_AddCallback( p_playlist, "intf-change", PlaylistChanged, self );
1234 var_AddCallback( p_playlist, "item-change", PlaylistChanged, self );
1235 var_AddCallback( p_playlist, "item-append", PlaylistChanged, self );
1236 var_AddCallback( p_playlist, "item-deleted", PlaylistChanged, self );
1237 var_AddCallback( p_playlist, "playlist-current", PlaylistChanged, self );
1239 vlc_object_release( p_playlist );
1241 while( (p_intf = VLCIntf) && !intf_ShouldDie( p_intf ) )
1243 vlc_mutex_lock( &p_intf->change_lock );
1246 if( p_intf->p_sys->p_input == NULL )
1248 p_intf->p_sys->p_input = p_playlist->p_input;
1250 /* Refresh the interface */
1251 if( p_intf->p_sys->p_input )
1253 msg_Dbg( p_intf, "input has changed, refreshing interface" );
1254 p_intf->p_sys->b_input_update = VLC_TRUE;
1257 else if( p_intf->p_sys->p_input->b_die || p_intf->p_sys->p_input->b_dead )
1260 p_intf->p_sys->b_intf_update = VLC_TRUE;
1261 p_intf->p_sys->i_play_status = END_S;
1262 msg_Dbg( p_intf, "input has stopped, refreshing interface" );
1263 p_intf->p_sys->p_input = NULL;
1266 /* Manage volume status */
1267 [self manageVolumeSlider];
1269 vlc_mutex_unlock( &p_intf->change_lock );
1275 - (void)manageIntf:(NSTimer *)o_timer
1278 playlist_t * p_playlist;
1279 input_thread_t * p_input;
1281 if( p_intf->p_libvlc->b_die == VLC_TRUE )
1283 [o_timer invalidate];
1287 if( p_intf->p_sys->b_input_update )
1289 /* Called when new input is opened */
1290 p_intf->p_sys->b_current_title_update = VLC_TRUE;
1291 p_intf->p_sys->b_intf_update = VLC_TRUE;
1292 p_intf->p_sys->b_input_update = VLC_FALSE;
1294 if( p_intf->p_sys->b_intf_update )
1296 vlc_bool_t b_input = VLC_FALSE;
1297 vlc_bool_t b_plmul = VLC_FALSE;
1298 vlc_bool_t b_control = VLC_FALSE;
1299 vlc_bool_t b_seekable = VLC_FALSE;
1300 vlc_bool_t b_chapters = VLC_FALSE;
1302 playlist_t * p_playlist = pl_Yield( p_intf );
1303 /* TODO: fix i_size use */
1304 b_plmul = p_playlist->items.i_size > 1;
1305 p_input = p_playlist->p_input;
1307 if( ( b_input = ( p_input != NULL ) ) )
1309 /* seekable streams */
1310 vlc_object_yield( p_input );
1311 b_seekable = var_GetBool( p_input, "seekable" );
1313 /* check whether slow/fast motion is possible */
1314 b_control = p_input->b_can_pace_control;
1316 /* chapters & titles */
1317 //b_chapters = p_input->stream.i_area_nb > 1;
1318 vlc_object_release( p_input );
1320 vlc_object_release( p_playlist );
1322 [o_btn_stop setEnabled: b_input];
1323 [o_btn_ff setEnabled: b_seekable];
1324 [o_btn_rewind setEnabled: b_seekable];
1325 [o_btn_prev setEnabled: (b_plmul || b_chapters)];
1326 [o_btn_next setEnabled: (b_plmul || b_chapters)];
1328 [o_timeslider setFloatValue: 0.0];
1329 [o_timeslider setEnabled: b_seekable];
1330 [o_timefield setStringValue: @"00:00"];
1331 [[[self getControls] getFSPanel] setStreamPos: 0 andTime: @"00:00"];
1332 [[[self getControls] getFSPanel] setSeekable: b_seekable];
1334 [o_embedded_window setSeekable: b_seekable];
1336 p_intf->p_sys->b_current_title_update = VLC_TRUE;
1338 p_intf->p_sys->b_intf_update = VLC_FALSE;
1341 if( p_intf->p_sys->b_playmode_update )
1343 [o_playlist playModeUpdated];
1344 p_intf->p_sys->b_playmode_update = VLC_FALSE;
1346 if( p_intf->p_sys->b_playlist_update )
1348 [o_playlist playlistUpdated];
1349 p_intf->p_sys->b_playlist_update = VLC_FALSE;
1352 if( p_intf->p_sys->b_fullscreen_update )
1354 p_intf->p_sys->b_fullscreen_update = VLC_FALSE;
1357 if( p_intf->p_sys->b_intf_show )
1359 [o_window makeKeyAndOrderFront: self];
1361 p_intf->p_sys->b_intf_show = VLC_FALSE;
1364 p_playlist = pl_Yield( p_intf );
1365 p_input = p_playlist->p_input;
1367 if( p_input && !p_input->b_die )
1370 vlc_object_yield( p_input );
1372 if( p_intf->p_sys->b_current_title_update )
1376 if( p_playlist->status.p_item == NULL )
1378 vlc_object_release( p_input );
1379 vlc_object_release( p_playlist );
1382 if( input_item_GetNowPlaying ( p_playlist->status.p_item->p_input ) )
1383 o_temp = [NSString stringWithUTF8String:
1384 input_item_GetNowPlaying ( p_playlist->status.p_item->p_input )];
1386 o_temp = [NSString stringWithUTF8String:
1387 p_playlist->status.p_item->p_input->psz_name];
1388 [self setScrollField: o_temp stopAfter:-1];
1389 [[[self getControls] getFSPanel] setStreamTitle: o_temp];
1391 [[o_controls getVoutView] updateTitle];
1393 [o_playlist updateRowSelection];
1394 p_intf->p_sys->b_current_title_update = FALSE;
1397 if( [o_timeslider isEnabled] )
1399 /* Update the slider */
1403 char psz_time[MSTRTIME_MAX_SIZE];
1406 var_Get( p_input, "position", &pos );
1407 f_updated = 10000. * pos.f_float;
1408 [o_timeslider setFloatValue: f_updated];
1410 var_Get( p_input, "time", &time );
1412 o_time = [NSString stringWithUTF8String: secstotimestr( psz_time, (time.i_time / 1000000) )];
1414 [o_timefield setStringValue: o_time];
1415 [[[self getControls] getFSPanel] setStreamPos: f_updated andTime: o_time];
1416 [o_embedded_window setTime: o_time position: f_updated];
1419 if( p_intf->p_sys->b_volume_update )
1422 int i_volume_step = 0;
1423 o_text = [NSString stringWithFormat: _NS("Volume: %d%%"), i_lastShownVolume * 400 / AOUT_VOLUME_MAX];
1424 if( i_lastShownVolume != -1 )
1425 [self setScrollField:o_text stopAfter:1000000];
1426 i_volume_step = config_GetInt( p_intf->p_libvlc, "volume-step" );
1427 [o_volumeslider setFloatValue: (float)i_lastShownVolume / i_volume_step];
1428 [o_volumeslider setEnabled: TRUE];
1429 [[[self getControls] getFSPanel] setVolumeLevel: (float)i_lastShownVolume / i_volume_step];
1430 p_intf->p_sys->b_mute = ( i_lastShownVolume == 0 );
1431 p_intf->p_sys->b_volume_update = FALSE;
1434 /* Manage Playing status */
1435 var_Get( p_input, "state", &val );
1436 if( p_intf->p_sys->i_play_status != val.i_int )
1438 p_intf->p_sys->i_play_status = val.i_int;
1439 [self playStatusUpdated: p_intf->p_sys->i_play_status];
1440 [o_embedded_window playStatusUpdated: p_intf->p_sys->i_play_status];
1442 vlc_object_release( p_input );
1446 p_intf->p_sys->i_play_status = END_S;
1447 p_intf->p_sys->b_intf_update = VLC_TRUE;
1448 [self playStatusUpdated: p_intf->p_sys->i_play_status];
1449 [o_embedded_window playStatusUpdated: p_intf->p_sys->i_play_status];
1450 [self setSubmenusEnabled: FALSE];
1452 vlc_object_release( p_playlist );
1454 [self updateMessageArray];
1456 if( ((i_end_scroll != -1) && (mdate() > i_end_scroll)) || !p_input )
1457 [self resetScrollField];
1459 [NSTimer scheduledTimerWithTimeInterval: 0.3
1460 target: self selector: @selector(manageIntf:)
1461 userInfo: nil repeats: FALSE];
1466 playlist_t * p_playlist = pl_Yield( p_intf );
1467 input_thread_t * p_input = p_playlist->p_input;
1468 if( p_input != NULL )
1470 vlc_object_yield( p_input );
1471 [o_controls setupVarMenuItem: o_mi_program target: (vlc_object_t *)p_input
1472 var: "program" selector: @selector(toggleVar:)];
1474 [o_controls setupVarMenuItem: o_mi_title target: (vlc_object_t *)p_input
1475 var: "title" selector: @selector(toggleVar:)];
1477 [o_controls setupVarMenuItem: o_mi_chapter target: (vlc_object_t *)p_input
1478 var: "chapter" selector: @selector(toggleVar:)];
1480 [o_controls setupVarMenuItem: o_mi_audiotrack target: (vlc_object_t *)p_input
1481 var: "audio-es" selector: @selector(toggleVar:)];
1483 [o_controls setupVarMenuItem: o_mi_videotrack target: (vlc_object_t *)p_input
1484 var: "video-es" selector: @selector(toggleVar:)];
1486 [o_controls setupVarMenuItem: o_mi_subtitle target: (vlc_object_t *)p_input
1487 var: "spu-es" selector: @selector(toggleVar:)];
1489 aout_instance_t * p_aout = vlc_object_find( p_intf, VLC_OBJECT_AOUT,
1491 if( p_aout != NULL )
1493 [o_controls setupVarMenuItem: o_mi_channels target: (vlc_object_t *)p_aout
1494 var: "audio-channels" selector: @selector(toggleVar:)];
1496 [o_controls setupVarMenuItem: o_mi_device target: (vlc_object_t *)p_aout
1497 var: "audio-device" selector: @selector(toggleVar:)];
1499 [o_controls setupVarMenuItem: o_mi_visual target: (vlc_object_t *)p_aout
1500 var: "visual" selector: @selector(toggleVar:)];
1501 vlc_object_release( (vlc_object_t *)p_aout );
1504 vout_thread_t * p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
1507 if( p_vout != NULL )
1509 vlc_object_t * p_dec_obj;
1511 [o_controls setupVarMenuItem: o_mi_aspect_ratio target: (vlc_object_t *)p_vout
1512 var: "aspect-ratio" selector: @selector(toggleVar:)];
1514 [o_controls setupVarMenuItem: o_mi_crop target: (vlc_object_t *) p_vout
1515 var: "crop" selector: @selector(toggleVar:)];
1517 [o_controls setupVarMenuItem: o_mi_screen target: (vlc_object_t *)p_vout
1518 var: "video-device" selector: @selector(toggleVar:)];
1520 [o_controls setupVarMenuItem: o_mi_deinterlace target: (vlc_object_t *)p_vout
1521 var: "deinterlace" selector: @selector(toggleVar:)];
1523 p_dec_obj = (vlc_object_t *)vlc_object_find(
1524 (vlc_object_t *)p_vout,
1527 if( p_dec_obj != NULL )
1529 [o_controls setupVarMenuItem: o_mi_ffmpeg_pp target:
1530 (vlc_object_t *)p_dec_obj var:"ffmpeg-pp-q" selector:
1531 @selector(toggleVar:)];
1533 vlc_object_release(p_dec_obj);
1535 vlc_object_release( (vlc_object_t *)p_vout );
1537 vlc_object_release( p_input );
1539 vlc_object_release( p_playlist );
1542 - (void)refreshVoutDeviceMenu:(NSNotification *)o_notification
1545 vout_thread_t * p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
1551 /* clean the menu before adding new entries */
1552 if( [o_mi_screen hasSubmenu] )
1554 y = [[o_mi_screen submenu] numberOfItems] - 1;
1555 msg_Dbg( VLCIntf, "%i items in submenu", y );
1558 msg_Dbg( VLCIntf, "removing item %i of %i", x, y );
1559 [[o_mi_screen submenu] removeItemAtIndex: x];
1564 [o_controls setupVarMenuItem: o_mi_screen target: (vlc_object_t *)p_vout
1565 var: "video-device" selector: @selector(toggleVar:)];
1566 vlc_object_release( (vlc_object_t *)p_vout );
1569 - (void)setScrollField:(NSString *)o_string stopAfter:(int)timeout
1572 i_end_scroll = mdate() + timeout;
1575 [o_scrollfield setStringValue: o_string];
1578 - (void)resetScrollField
1580 playlist_t * p_playlist = pl_Yield( p_intf );
1581 input_thread_t * p_input = p_playlist->p_input;
1584 if( p_input && !p_input->b_die )
1587 vlc_object_yield( p_input );
1588 if( input_item_GetNowPlaying ( p_playlist->status.p_item->p_input ) )
1589 o_temp = [NSString stringWithUTF8String:
1590 input_item_GetNowPlaying ( p_playlist->status.p_item->p_input )];
1592 o_temp = [NSString stringWithUTF8String:
1593 p_playlist->status.p_item->p_input->psz_name];
1594 [self setScrollField: o_temp stopAfter:-1];
1595 vlc_object_release( p_input );
1596 vlc_object_release( p_playlist );
1599 vlc_object_release( p_playlist );
1600 [self setScrollField: _NS("VLC media player") stopAfter:-1];
1603 - (void)updateMessageArray
1605 int i_start, i_stop;
1607 vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
1608 i_stop = *p_intf->p_sys->p_sub->pi_stop;
1609 vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
1611 if( p_intf->p_sys->p_sub->i_start != i_stop )
1613 NSColor *o_white = [NSColor whiteColor];
1614 NSColor *o_red = [NSColor redColor];
1615 NSColor *o_yellow = [NSColor yellowColor];
1616 NSColor *o_gray = [NSColor grayColor];
1618 NSColor * pp_color[4] = { o_white, o_red, o_yellow, o_gray };
1619 static const char * ppsz_type[4] = { ": ", " error: ",
1620 " warning: ", " debug: " };
1622 for( i_start = p_intf->p_sys->p_sub->i_start;
1624 i_start = (i_start+1) % VLC_MSG_QSIZE )
1627 NSDictionary *o_attr;
1628 NSAttributedString *o_msg_color;
1630 int i_type = p_intf->p_sys->p_sub->p_msg[i_start].i_type;
1634 if( [o_msg_arr count] + 2 > 400 )
1636 unsigned rid[] = { 0, 1 };
1637 [o_msg_arr removeObjectsFromIndices: (unsigned *)&rid
1638 numIndices: sizeof(rid)/sizeof(rid[0])];
1641 o_attr = [NSDictionary dictionaryWithObject: o_gray
1642 forKey: NSForegroundColorAttributeName];
1643 o_msg = [NSString stringWithFormat: @"%s%s",
1644 p_intf->p_sys->p_sub->p_msg[i_start].psz_module,
1646 o_msg_color = [[NSAttributedString alloc]
1647 initWithString: o_msg attributes: o_attr];
1648 [o_msg_arr addObject: [o_msg_color autorelease]];
1650 o_attr = [NSDictionary dictionaryWithObject: pp_color[i_type]
1651 forKey: NSForegroundColorAttributeName];
1652 o_msg = [NSString stringWithFormat: @"%s\n",
1653 p_intf->p_sys->p_sub->p_msg[i_start].psz_msg];
1654 o_msg_color = [[NSAttributedString alloc]
1655 initWithString: o_msg attributes: o_attr];
1656 [o_msg_arr addObject: [o_msg_color autorelease]];
1658 [o_msg_lock unlock];
1661 vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
1662 p_intf->p_sys->p_sub->i_start = i_start;
1663 vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
1667 - (void)playStatusUpdated:(int)i_status
1669 if( i_status == PLAYING_S )
1671 [[[self getControls] getFSPanel] setPause];
1672 [o_btn_play setImage: o_img_pause];
1673 [o_btn_play setAlternateImage: o_img_pause_pressed];
1674 [o_btn_play setToolTip: _NS("Pause")];
1675 [o_mi_play setTitle: _NS("Pause")];
1676 [o_dmi_play setTitle: _NS("Pause")];
1677 [o_vmi_play setTitle: _NS("Pause")];
1681 [[[self getControls] getFSPanel] setPlay];
1682 [o_btn_play setImage: o_img_play];
1683 [o_btn_play setAlternateImage: o_img_play_pressed];
1684 [o_btn_play setToolTip: _NS("Play")];
1685 [o_mi_play setTitle: _NS("Play")];
1686 [o_dmi_play setTitle: _NS("Play")];
1687 [o_vmi_play setTitle: _NS("Play")];
1691 - (void)setSubmenusEnabled:(BOOL)b_enabled
1693 [o_mi_program setEnabled: b_enabled];
1694 [o_mi_title setEnabled: b_enabled];
1695 [o_mi_chapter setEnabled: b_enabled];
1696 [o_mi_audiotrack setEnabled: b_enabled];
1697 [o_mi_visual setEnabled: b_enabled];
1698 [o_mi_videotrack setEnabled: b_enabled];
1699 [o_mi_subtitle setEnabled: b_enabled];
1700 [o_mi_channels setEnabled: b_enabled];
1701 [o_mi_deinterlace setEnabled: b_enabled];
1702 [o_mi_ffmpeg_pp setEnabled: b_enabled];
1703 [o_mi_device setEnabled: b_enabled];
1704 [o_mi_screen setEnabled: b_enabled];
1705 [o_mi_aspect_ratio setEnabled: b_enabled];
1706 [o_mi_crop setEnabled: b_enabled];
1709 - (void)manageVolumeSlider
1711 audio_volume_t i_volume;
1712 aout_VolumeGet( p_intf, &i_volume );
1714 if( i_volume != i_lastShownVolume )
1716 i_lastShownVolume = i_volume;
1717 p_intf->p_sys->b_volume_update = TRUE;
1721 - (IBAction)timesliderUpdate:(id)sender
1724 playlist_t * p_playlist;
1725 input_thread_t * p_input;
1727 switch( [[NSApp currentEvent] type] )
1730 case NSLeftMouseDown:
1731 case NSLeftMouseDragged:
1732 f_updated = [sender floatValue];
1738 p_playlist = pl_Yield( p_intf );
1739 p_input = p_playlist->p_input;
1740 if( p_input != NULL )
1745 char psz_time[MSTRTIME_MAX_SIZE];
1746 vlc_object_yield( p_input );
1748 pos.f_float = f_updated / 10000.;
1749 var_Set( p_input, "position", pos );
1750 [o_timeslider setFloatValue: f_updated];
1752 var_Get( p_input, "time", &time );
1754 o_time = [NSString stringWithUTF8String: secstotimestr( psz_time, (time.i_time / 1000000) )];
1755 [o_timefield setStringValue: o_time];
1756 [[[self getControls] getFSPanel] setStreamPos: f_updated andTime: o_time];
1757 [o_embedded_window setTime: o_time position: f_updated];
1758 vlc_object_release( p_input );
1760 vlc_object_release( p_playlist );
1763 - (void)applicationWillTerminate:(NSNotification *)notification
1765 playlist_t * p_playlist;
1766 vout_thread_t * p_vout;
1767 int returnedValue = 0;
1770 p_playlist = pl_Yield( p_intf );
1771 playlist_Stop( p_playlist );
1772 vlc_object_release( p_playlist );
1774 /* make sure that the current volume is saved */
1775 config_PutInt( p_intf->p_libvlc, "volume", i_lastShownVolume );
1776 returnedValue = config_SaveConfigFile( p_intf->p_libvlc, "main" );
1777 if( returnedValue != 0 )
1779 "error while saving volume in osx's terminate method (%i)",
1782 /* save the prefs if they were changed in the extended panel */
1783 if(o_extended && [o_extended getConfigChanged])
1785 [o_extended savePrefs];
1788 p_intf->b_interaction = VLC_FALSE;
1789 var_DelCallback( p_intf, "interaction", InteractCallback, self );
1791 /* remove global observer watching for vout device changes correctly */
1792 [[NSNotificationCenter defaultCenter] removeObserver: self];
1794 /* release some other objects here, because it isn't sure whether dealloc
1795 * will be called later on */
1797 if( nib_about_loaded && o_about )
1800 if( nib_prefs_loaded && o_prefs )
1803 if( nib_open_loaded && o_open )
1806 if( nib_extended_loaded && o_extended )
1808 [o_extended collapsAll];
1809 [o_extended release];
1812 if( nib_bookmarks_loaded && o_bookmarks )
1813 [o_bookmarks release];
1815 if( nib_wizard_loaded && o_wizard )
1818 if( o_embedded_list != nil )
1819 [o_embedded_list release];
1821 if( o_interaction_list != nil )
1822 [o_interaction_list release];
1824 if( o_eyetv != nil )
1827 if( o_img_pause_pressed != nil )
1829 [o_img_pause_pressed release];
1830 o_img_pause_pressed = nil;
1833 if( o_img_play_pressed != nil )
1835 [o_img_pause_pressed release];
1836 o_img_pause_pressed = nil;
1839 if( o_img_pause != nil )
1841 [o_img_pause release];
1845 if( o_img_play != nil )
1847 [o_img_play release];
1851 if( o_msg_arr != nil )
1853 [o_msg_arr removeAllObjects];
1854 [o_msg_arr release];
1858 if( o_msg_lock != nil )
1860 [o_msg_lock release];
1864 /* write cached user defaults to disk */
1865 [[NSUserDefaults standardUserDefaults] synchronize];
1867 vlc_object_kill( p_intf );
1869 /* Go back to Run() and make libvlc exit properly */
1870 longjmp( jmpbuffer, 1 );
1875 - (IBAction)clearRecentItems:(id)sender
1877 [[NSDocumentController sharedDocumentController]
1878 clearRecentDocuments: nil];
1881 - (void)openRecentItem:(id)sender
1883 [self application: nil openFile: [sender title]];
1886 - (IBAction)intfOpenFile:(id)sender
1888 if( !nib_open_loaded )
1890 nib_open_loaded = [NSBundle loadNibNamed:@"Open" owner:self];
1891 [o_open awakeFromNib];
1898 - (IBAction)intfOpenFileGeneric:(id)sender
1900 if( !nib_open_loaded )
1902 nib_open_loaded = [NSBundle loadNibNamed:@"Open" owner:self];
1903 [o_open awakeFromNib];
1904 [o_open openFileGeneric];
1906 [o_open openFileGeneric];
1910 - (IBAction)intfOpenDisc:(id)sender
1912 if( !nib_open_loaded )
1914 nib_open_loaded = [NSBundle loadNibNamed:@"Open" owner:self];
1915 [o_open awakeFromNib];
1922 - (IBAction)intfOpenNet:(id)sender
1924 if( !nib_open_loaded )
1926 nib_open_loaded = [NSBundle loadNibNamed:@"Open" owner:self];
1927 [o_open awakeFromNib];
1934 - (IBAction)showWizard:(id)sender
1936 if( !nib_wizard_loaded )
1938 nib_wizard_loaded = [NSBundle loadNibNamed:@"Wizard" owner:self];
1939 [o_wizard initStrings];
1940 [o_wizard resetWizard];
1941 [o_wizard showWizard];
1943 [o_wizard resetWizard];
1944 [o_wizard showWizard];
1948 - (IBAction)showExtended:(id)sender
1950 if( o_extended == nil )
1952 o_extended = [[VLCExtended alloc] init];
1954 if( !nib_extended_loaded )
1956 nib_extended_loaded = [NSBundle loadNibNamed:@"Extended" owner:self];
1957 [o_extended initStrings];
1958 [o_extended showPanel];
1960 [o_extended showPanel];
1964 - (IBAction)showSFilters:(id)sender
1966 if( o_sfilters == nil )
1968 o_sfilters = [[VLCsFilters alloc] init];
1970 if( !nib_sfilters_loaded )
1972 nib_sfilters_loaded = [NSBundle loadNibNamed:@"SFilters" owner:self];
1973 [o_sfilters initStrings];
1974 [o_sfilters showAsPanel];
1976 [o_sfilters showAsPanel];
1980 - (IBAction)showBookmarks:(id)sender
1982 /* we need the wizard-nib for the bookmarks's extract functionality */
1983 if( !nib_wizard_loaded )
1985 nib_wizard_loaded = [NSBundle loadNibNamed:@"Wizard" owner:self];
1986 [o_wizard initStrings];
1989 if( !nib_bookmarks_loaded )
1990 nib_bookmarks_loaded = [NSBundle loadNibNamed:@"Bookmarks" owner:self];
1992 [o_bookmarks showBookmarks];
1995 - (IBAction)viewAbout:(id)sender
1997 if( !nib_about_loaded )
1998 nib_about_loaded = [NSBundle loadNibNamed:@"About" owner:self];
2000 [o_about showAbout];
2003 - (IBAction)showLicense:(id)sender
2005 if( !nib_about_loaded )
2006 nib_about_loaded = [NSBundle loadNibNamed:@"About" owner:self];
2008 [o_about showGPL: sender];
2011 - (IBAction)viewPreferences:(id)sender
2013 if( !nib_prefs_loaded )
2014 nib_prefs_loaded = [NSBundle loadNibNamed:@"Preferences" owner: self];
2016 if( sender == o_mi_sprefs )
2018 o_sprefs = [[VLCSimplePrefs alloc] init];
2019 [o_sprefs showSimplePrefs];
2022 [o_prefs showPrefs];
2025 - (IBAction)checkForUpdate:(id)sender
2028 if( !nib_update_loaded )
2029 nib_update_loaded = [NSBundle loadNibNamed:@"Update" owner:self];
2030 [o_update showUpdateWindow];
2032 msg_Err( VLCIntf, "Update checker wasn't enabled in this build" );
2033 intf_UserFatal( VLCIntf, VLC_FALSE, _("Update check failed"), _("Checking for updates was not enabled in this build.") );
2037 - (IBAction)viewHelp:(id)sender
2039 if( !nib_about_loaded )
2041 nib_about_loaded = [NSBundle loadNibNamed:@"About" owner:self];
2048 - (IBAction)openReadMe:(id)sender
2050 NSString * o_path = [[NSBundle mainBundle]
2051 pathForResource: @"README.MacOSX" ofType: @"rtf"];
2053 [[NSWorkspace sharedWorkspace] openFile: o_path
2054 withApplication: @"TextEdit"];
2057 - (IBAction)openDocumentation:(id)sender
2059 NSURL * o_url = [NSURL URLWithString:
2060 @"http://www.videolan.org/doc/"];
2062 [[NSWorkspace sharedWorkspace] openURL: o_url];
2065 - (IBAction)openWebsite:(id)sender
2067 NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org/"];
2069 [[NSWorkspace sharedWorkspace] openURL: o_url];
2072 - (IBAction)openForum:(id)sender
2074 NSURL * o_url = [NSURL URLWithString: @"http://forum.videolan.org/"];
2076 [[NSWorkspace sharedWorkspace] openURL: o_url];
2079 - (IBAction)openDonate:(id)sender
2081 NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org/contribute.html#paypal"];
2083 [[NSWorkspace sharedWorkspace] openURL: o_url];
2086 - (IBAction)openCrashLog:(id)sender
2088 NSString * o_path = [@"~/Library/Logs/CrashReporter/VLC.crash.log"
2089 stringByExpandingTildeInPath];
2092 if( [[NSFileManager defaultManager] fileExistsAtPath: o_path ] )
2094 [[NSWorkspace sharedWorkspace] openFile: o_path
2095 withApplication: @"Console"];
2099 NSBeginInformationalAlertSheet(_NS("No CrashLog found"), @"Continue", nil, nil, o_msgs_panel, self, NULL, NULL, nil, _NS("Couldn't find any trace of a previous crash.") );
2104 - (IBAction)viewErrorsAndWarnings:(id)sender
2106 [[[self getInteractionList] getErrorPanel] showPanel];
2109 - (IBAction)showMessagesPanel:(id)sender
2111 [o_msgs_panel makeKeyAndOrderFront: sender];
2114 - (void)windowDidBecomeKey:(NSNotification *)o_notification
2116 if( [o_notification object] == o_msgs_panel )
2119 NSEnumerator * o_enum;
2121 [o_messages setString: @""];
2125 o_enum = [o_msg_arr objectEnumerator];
2127 while( ( o_msg = [o_enum nextObject] ) != nil )
2129 [o_messages insertText: o_msg];
2132 [o_msg_lock unlock];
2136 - (IBAction)togglePlaylist:(id)sender
2138 NSRect o_rect = [o_window frame];
2139 /*First, check if the playlist is visible*/
2140 if( o_rect.size.height <= 200 )
2142 o_restore_rect = o_rect;
2143 b_restore_size = true;
2144 b_small_window = YES; /* we know we are small, make sure this is actually set (see case below) */
2146 if( o_size_with_playlist.height > 200 )
2148 o_rect.size.height = o_size_with_playlist.height;
2150 o_rect.size.height = 500;
2153 if( o_size_with_playlist.width > [o_window minSize].width )
2155 o_rect.size.width = o_size_with_playlist.width;
2157 o_rect.size.width = 500;
2160 o_rect.size.height = (o_size_with_playlist.height > 200) ?
2161 o_size_with_playlist.height : 500;
2162 o_rect.origin.x = [o_window frame].origin.x;
2163 o_rect.origin.y = [o_window frame].origin.y - o_rect.size.height +
2164 [o_window minSize].height;
2166 NSRect screenRect = [[o_window screen] visibleFrame];
2167 if( !NSContainsRect( screenRect, o_rect ) ) {
2168 if( NSMaxX(o_rect) > NSMaxX(screenRect) )
2169 o_rect.origin.x = ( NSMaxX(screenRect) - o_rect.size.width );
2170 if( NSMinY(o_rect) < NSMinY(screenRect) )
2171 o_rect.origin.y = ( NSMinY(screenRect) );
2174 [o_btn_playlist setState: YES];
2178 NSSize curSize = o_rect.size;
2180 o_rect.size.height = [o_window minSize].height;
2181 o_rect.size.width = [o_window minSize].width;
2182 o_rect.origin.x = [o_window frame].origin.x;
2183 /* Calculate the position of the lower right corner after resize */
2184 o_rect.origin.y = [o_window frame].origin.y +
2185 [o_window frame].size.height - [o_window minSize].height;
2187 if( b_restore_size )
2188 o_rect = o_restore_rect;
2190 [o_playlist_view setAutoresizesSubviews: NO];
2191 [o_playlist_view removeFromSuperview];
2192 [o_btn_playlist setState: NO];
2193 b_small_window = NO; /* we aren't small here just yet. we are doing an animated resize after this */
2196 [o_window setFrame: o_rect display:YES animate: YES];
2199 - (void)updateTogglePlaylistState
2201 if( [o_window frame].size.height <= 200 )
2203 [o_btn_playlist setState: NO];
2207 [o_btn_playlist setState: YES];
2211 - (NSSize)windowWillResize:(NSWindow *)sender toSize:(NSSize)proposedFrameSize
2213 /* Not triggered on a window resize or maxification of the window. only by window mouse dragging resize */
2215 /*Stores the size the controller one resize, to be able to restore it when
2216 toggling the playlist*/
2217 o_size_with_playlist = proposedFrameSize;
2219 if( proposedFrameSize.height <= 200 )
2221 if( b_small_window == NO )
2223 /* if large and going to small then hide */
2224 b_small_window = YES;
2225 [o_playlist_view setAutoresizesSubviews: NO];
2226 [o_playlist_view removeFromSuperview];
2228 return NSMakeSize( proposedFrameSize.width, [o_window minSize].height);
2230 return proposedFrameSize;
2233 - (void)windowDidMove:(NSNotification *)notif
2235 b_restore_size = false;
2238 - (void)windowDidResize:(NSNotification *)notif
2240 if( [o_window frame].size.height > 200 && b_small_window )
2242 /* If large and coming from small then show */
2243 [o_playlist_view setAutoresizesSubviews: YES];
2244 [o_playlist_view setFrame: NSMakeRect( 10, 10, [o_window frame].size.width - 20, [o_window frame].size.height - [o_window minSize].height - 10 )];
2245 [o_playlist_view setNeedsDisplay:YES];
2246 [[o_window contentView] addSubview: o_playlist_view];
2247 b_small_window = NO;
2249 [self updateTogglePlaylistState];
2254 @implementation VLCMain (NSMenuValidation)
2256 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
2258 NSString *o_title = [o_mi title];
2259 BOOL bEnabled = TRUE;
2261 /* Recent Items Menu */
2262 if( [o_title isEqualToString: _NS("Clear Menu")] )
2264 NSMenu * o_menu = [o_mi_open_recent submenu];
2265 int i_nb_items = [o_menu numberOfItems];
2266 NSArray * o_docs = [[NSDocumentController sharedDocumentController]
2267 recentDocumentURLs];
2268 UInt32 i_nb_docs = [o_docs count];
2270 if( i_nb_items > 1 )
2272 while( --i_nb_items )
2274 [o_menu removeItemAtIndex: 0];
2283 [o_menu insertItem: [NSMenuItem separatorItem] atIndex: 0];
2289 o_url = [o_docs objectAtIndex: i_nb_docs];
2291 if( [o_url isFileURL] )
2293 o_doc = [o_url path];
2297 o_doc = [o_url absoluteString];
2300 [o_menu insertItemWithTitle: o_doc
2301 action: @selector(openRecentItem:)
2302 keyEquivalent: @"" atIndex: 0];
2304 if( i_nb_docs == 0 )
2320 @implementation VLCMain (Internal)
2322 - (void)handlePortMessage:(NSPortMessage *)o_msg
2327 NSInvocation * o_inv;
2328 NSConditionLock * o_lock;
2330 o_data = [[o_msg components] lastObject];
2331 o_inv = *((NSInvocation **)[o_data bytes]);
2332 [o_inv getArgument: &o_value atIndex: 2];
2333 val = (id **)[o_value pointerValue];
2334 [o_inv setArgument: val[1] atIndex: 2];
2339 [o_lock unlockWithCondition: 1];