1 /*****************************************************************************
2 * intf.m: MacOS X interface module
3 *****************************************************************************
4 * Copyright (C) 2002-2005 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>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
24 *****************************************************************************/
26 /*****************************************************************************
28 *****************************************************************************/
29 #include <stdlib.h> /* malloc(), free() */
30 #include <sys/param.h> /* for MAXPATHLEN */
44 /*****************************************************************************
46 *****************************************************************************/
47 static void Run ( intf_thread_t *p_intf );
49 /*****************************************************************************
50 * OpenIntf: initialize interface
51 *****************************************************************************/
52 int E_(OpenIntf) ( vlc_object_t *p_this )
54 intf_thread_t *p_intf = (intf_thread_t*) p_this;
56 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
57 if( p_intf->p_sys == NULL )
62 memset( p_intf->p_sys, 0, sizeof( *p_intf->p_sys ) );
64 p_intf->p_sys->o_pool = [[NSAutoreleasePool alloc] init];
66 /* Put Cocoa into multithread mode as soon as possible.
67 * http://developer.apple.com/techpubs/macosx/Cocoa/
68 * TasksAndConcepts/ProgrammingTopics/Multithreading/index.html
69 * This thread does absolutely nothing at all. */
70 [NSThread detachNewThreadSelector:@selector(self) toTarget:[NSString string] withObject:nil];
72 p_intf->p_sys->o_sendport = [[NSPort port] retain];
73 p_intf->p_sys->p_sub = msg_Subscribe( p_intf );
74 p_intf->b_play = VLC_TRUE;
80 /*****************************************************************************
81 * CloseIntf: destroy interface
82 *****************************************************************************/
83 void E_(CloseIntf) ( vlc_object_t *p_this )
85 intf_thread_t *p_intf = (intf_thread_t*) p_this;
87 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
89 [p_intf->p_sys->o_sendport release];
90 [p_intf->p_sys->o_pool release];
92 free( p_intf->p_sys );
95 /*****************************************************************************
97 *****************************************************************************/
98 static void Run( intf_thread_t *p_intf )
100 /* Do it again - for some unknown reason, vlc_thread_create() often
101 * fails to go to real-time priority with the first launched thread
103 vlc_thread_set_priority( p_intf, VLC_THREAD_PRIORITY_LOW );
104 [[VLCMain sharedInstance] setIntf: p_intf];
105 [NSBundle loadNibNamed: @"MainMenu" owner: NSApp];
107 [[VLCMain sharedInstance] terminate];
110 int ExecuteOnMainThread( id target, SEL sel, void * p_arg )
114 //NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
116 if( [target respondsToSelector: @selector(performSelectorOnMainThread:
117 withObject:waitUntilDone:)] )
119 [target performSelectorOnMainThread: sel
120 withObject: [NSValue valueWithPointer: p_arg]
123 else if( NSApp != nil && [[VLCMain sharedInstance] respondsToSelector: @selector(getIntf)] )
128 NSPort * o_recv_port;
129 NSInvocation * o_inv;
130 NSPortMessage * o_msg;
131 intf_thread_t * p_intf;
132 NSConditionLock * o_lock;
133 NSMethodSignature * o_sig;
135 id * val[] = { &o_lock, &o_v2 };
137 p_intf = (intf_thread_t *)VLCIntf;
139 o_recv_port = [[NSPort port] retain];
140 o_v1 = [NSValue valueWithPointer: val];
141 o_v2 = [NSValue valueWithPointer: p_arg];
143 o_sig = [target methodSignatureForSelector: sel];
144 o_inv = [NSInvocation invocationWithMethodSignature: o_sig];
145 [o_inv setArgument: &o_v1 atIndex: 2];
146 [o_inv setTarget: target];
147 [o_inv setSelector: sel];
149 o_array = [NSArray arrayWithObject:
150 [NSData dataWithBytes: &o_inv length: sizeof(o_inv)]];
151 o_msg = [[NSPortMessage alloc]
152 initWithSendPort: p_intf->p_sys->o_sendport
153 receivePort: o_recv_port components: o_array];
155 o_lock = [[NSConditionLock alloc] initWithCondition: 0];
156 [o_msg sendBeforeDate: [NSDate distantPast]];
157 [o_lock lockWhenCondition: 1];
162 [o_recv_port release];
174 /*****************************************************************************
175 * playlistChanged: Callback triggered by the intf-change playlist
176 * variable, to let the intf update the playlist.
177 *****************************************************************************/
178 int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,
179 vlc_value_t old_val, vlc_value_t new_val, void *param )
181 intf_thread_t * p_intf = VLCIntf;
182 p_intf->p_sys->b_playlist_update = TRUE;
183 p_intf->p_sys->b_intf_update = TRUE;
184 p_intf->p_sys->b_playmode_update = TRUE;
188 /*****************************************************************************
189 * FullscreenChanged: Callback triggered by the fullscreen-change playlist
190 * variable, to let the intf update the controller.
191 *****************************************************************************/
192 int FullscreenChanged( vlc_object_t *p_this, const char *psz_variable,
193 vlc_value_t old_val, vlc_value_t new_val, void *param )
195 intf_thread_t * p_intf = VLCIntf;
196 p_intf->p_sys->b_fullscreen_update = TRUE;
204 unsigned int i_vlckey;
205 } nskeys_to_vlckeys[] =
207 { NSUpArrowFunctionKey, KEY_UP },
208 { NSDownArrowFunctionKey, KEY_DOWN },
209 { NSLeftArrowFunctionKey, KEY_LEFT },
210 { NSRightArrowFunctionKey, KEY_RIGHT },
211 { NSF1FunctionKey, KEY_F1 },
212 { NSF2FunctionKey, KEY_F2 },
213 { NSF3FunctionKey, KEY_F3 },
214 { NSF4FunctionKey, KEY_F4 },
215 { NSF5FunctionKey, KEY_F5 },
216 { NSF6FunctionKey, KEY_F6 },
217 { NSF7FunctionKey, KEY_F7 },
218 { NSF8FunctionKey, KEY_F8 },
219 { NSF9FunctionKey, KEY_F9 },
220 { NSF10FunctionKey, KEY_F10 },
221 { NSF11FunctionKey, KEY_F11 },
222 { NSF12FunctionKey, KEY_F12 },
223 { NSHomeFunctionKey, KEY_HOME },
224 { NSEndFunctionKey, KEY_END },
225 { NSPageUpFunctionKey, KEY_PAGEUP },
226 { NSPageDownFunctionKey, KEY_PAGEDOWN },
227 { NSTabCharacter, KEY_TAB },
228 { NSCarriageReturnCharacter, KEY_ENTER },
229 { NSEnterCharacter, KEY_ENTER },
230 { NSBackspaceCharacter, KEY_BACKSPACE },
231 { (unichar) ' ', KEY_SPACE },
232 { (unichar) 0x1b, KEY_ESC },
236 unichar VLCKeyToCocoa( unsigned int i_key )
240 for( i = 0; nskeys_to_vlckeys[i].i_vlckey != 0; i++ )
242 if( nskeys_to_vlckeys[i].i_vlckey == (i_key & ~KEY_MODIFIER) )
244 return nskeys_to_vlckeys[i].i_nskey;
247 return (unichar)(i_key & ~KEY_MODIFIER);
250 unsigned int CocoaKeyToVLC( unichar i_key )
254 for( i = 0; nskeys_to_vlckeys[i].i_nskey != 0; i++ )
256 if( nskeys_to_vlckeys[i].i_nskey == i_key )
258 return nskeys_to_vlckeys[i].i_vlckey;
261 return (unsigned int)i_key;
264 unsigned int VLCModifiersToCocoa( unsigned int i_key )
266 unsigned int new = 0;
267 if( i_key & KEY_MODIFIER_COMMAND )
268 new |= NSCommandKeyMask;
269 if( i_key & KEY_MODIFIER_ALT )
270 new |= NSAlternateKeyMask;
271 if( i_key & KEY_MODIFIER_SHIFT )
272 new |= NSShiftKeyMask;
273 if( i_key & KEY_MODIFIER_CTRL )
274 new |= NSControlKeyMask;
278 /*****************************************************************************
279 * VLCMain implementation
280 *****************************************************************************/
281 @implementation VLCMain
283 static VLCMain *_o_sharedMainInstance = nil;
285 + (VLCMain *)sharedInstance
287 return _o_sharedMainInstance ? _o_sharedMainInstance : [[self alloc] init];
292 if( _o_sharedMainInstance) {
295 _o_sharedMainInstance = [super init];
298 o_about = [[VLAboutBox alloc] init];
300 o_open = [[VLCOpen alloc] init];
301 o_wizard = [[VLCWizard alloc] init];
302 o_extended = [[VLCExtended alloc] init];
304 i_lastShownVolume = -1;
305 return _o_sharedMainInstance;
308 - (void)setIntf: (intf_thread_t *)p_mainintf {
312 - (intf_thread_t *)getIntf {
318 unsigned int i_key = 0;
319 playlist_t *p_playlist;
323 [o_window setExcludedFromWindowsMenu: TRUE];
324 [o_msgs_panel setExcludedFromWindowsMenu: TRUE];
325 [o_msgs_panel setDelegate: self];
327 i_key = config_GetInt( p_intf, "key-quit" );
328 [o_mi_quit setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
329 [o_mi_quit setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
330 i_key = config_GetInt( p_intf, "key-play-pause" );
331 [o_mi_play setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
332 [o_mi_play setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
333 i_key = config_GetInt( p_intf, "key-stop" );
334 [o_mi_stop setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
335 [o_mi_stop setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
336 i_key = config_GetInt( p_intf, "key-faster" );
337 [o_mi_faster setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
338 [o_mi_faster setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
339 i_key = config_GetInt( p_intf, "key-slower" );
340 [o_mi_slower setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
341 [o_mi_slower setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
342 i_key = config_GetInt( p_intf, "key-prev" );
343 [o_mi_previous setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
344 [o_mi_previous setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
345 i_key = config_GetInt( p_intf, "key-next" );
346 [o_mi_next setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
347 [o_mi_next setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
348 i_key = config_GetInt( p_intf, "key-jump+10sec" );
349 [o_mi_fwd setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
350 [o_mi_fwd setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
351 i_key = config_GetInt( p_intf, "key-jump-10sec" );
352 [o_mi_bwd setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
353 [o_mi_bwd setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
354 i_key = config_GetInt( p_intf, "key-jump+1min" );
355 [o_mi_fwd1m setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
356 [o_mi_fwd1m setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
357 i_key = config_GetInt( p_intf, "key-jump-1min" );
358 [o_mi_bwd1m setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
359 [o_mi_bwd1m setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
360 i_key = config_GetInt( p_intf, "key-jump+5min" );
361 [o_mi_fwd5m setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
362 [o_mi_fwd5m setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
363 i_key = config_GetInt( p_intf, "key-jump-5min" );
364 [o_mi_bwd5m setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
365 [o_mi_bwd5m setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
366 i_key = config_GetInt( p_intf, "key-vol-up" );
367 [o_mi_vol_up setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
368 [o_mi_vol_up setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
369 i_key = config_GetInt( p_intf, "key-vol-down" );
370 [o_mi_vol_down setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
371 [o_mi_vol_down setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
372 i_key = config_GetInt( p_intf, "key-vol-mute" );
373 [o_mi_mute setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
374 [o_mi_mute setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
375 i_key = config_GetInt( p_intf, "key-fullscreen" );
376 [o_mi_fullscreen setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
377 [o_mi_fullscreen setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
378 i_key = config_GetInt( p_intf, "key-snapshot" );
379 [o_mi_snapshot setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
380 [o_mi_snapshot setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
382 var_Create( p_intf, "intf-change", VLC_VAR_BOOL );
384 [self setSubmenusEnabled: FALSE];
385 [self manageVolumeSlider];
386 [o_window setDelegate: self];
388 if( [o_window frame].size.height <= 200 )
390 b_small_window = YES;
391 [o_window setFrame: NSMakeRect( [o_window frame].origin.x,
392 [o_window frame].origin.y, [o_window frame].size.width,
393 [o_window minSize].height ) display: YES animate:YES];
394 [o_playlist_view setAutoresizesSubviews: NO];
399 [o_playlist_view setFrame: NSMakeRect( 10, 10, [o_window frame].size.width - 20, [o_window frame].size.height - 105 )];
400 [o_playlist_view setNeedsDisplay:YES];
401 [o_playlist_view setAutoresizesSubviews: YES];
402 [[o_window contentView] addSubview: o_playlist_view];
404 [self updateTogglePlaylistState];
406 o_size_with_playlist = [o_window frame].size;
408 p_playlist = (playlist_t *) vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
412 /* Check if we need to start playing */
415 playlist_Play( p_playlist );
417 var_Create( p_playlist, "fullscreen", VLC_VAR_BOOL | VLC_VAR_DOINHERIT);
418 val.b_bool = VLC_FALSE;
420 var_AddCallback( p_playlist, "fullscreen", FullscreenChanged, self);
422 [o_btn_fullscreen setState: ( var_Get( p_playlist, "fullscreen", &val )>=0 && val.b_bool )];
423 vlc_object_release( p_playlist );
429 [o_window setTitle: _NS("VLC - Controller")];
430 [self setScrollField:_NS("VLC media player") stopAfter:-1];
432 /* button controls */
433 [o_btn_prev setToolTip: _NS("Previous")];
434 [o_btn_rewind setToolTip: _NS("Rewind")];
435 [o_btn_play setToolTip: _NS("Play")];
436 [o_btn_stop setToolTip: _NS("Stop")];
437 [o_btn_ff setToolTip: _NS("Fast Forward")];
438 [o_btn_next setToolTip: _NS("Next")];
439 [o_btn_fullscreen setToolTip: _NS("Fullscreen")];
440 [o_volumeslider setToolTip: _NS("Volume")];
441 [o_timeslider setToolTip: _NS("Position")];
442 [o_btn_playlist setToolTip: _NS("Playlist")];
445 [o_msgs_panel setTitle: _NS("Messages")];
446 [o_msgs_btn_crashlog setTitle: _NS("Open CrashLog")];
449 [o_mi_about setTitle: _NS("About VLC media player...")];
450 [o_mi_prefs setTitle: _NS("Preferences...")];
451 [o_mi_add_intf setTitle: _NS("Add Interface")];
452 [o_mu_add_intf setTitle: _NS("Add Interface")];
453 [o_mi_services setTitle: _NS("Services")];
454 [o_mi_hide setTitle: _NS("Hide VLC")];
455 [o_mi_hide_others setTitle: _NS("Hide Others")];
456 [o_mi_show_all setTitle: _NS("Show All")];
457 [o_mi_quit setTitle: _NS("Quit VLC")];
459 [o_mu_file setTitle: _ANS("1:File")];
460 [o_mi_open_generic setTitle: _NS("Open File...")];
461 [o_mi_open_file setTitle: _NS("Quick Open File...")];
462 [o_mi_open_disc setTitle: _NS("Open Disc...")];
463 [o_mi_open_net setTitle: _NS("Open Network...")];
464 [o_mi_open_recent setTitle: _NS("Open Recent")];
465 [o_mi_open_recent_cm setTitle: _NS("Clear Menu")];
466 [o_mi_open_wizard setTitle: _NS("Wizard...")];
468 [o_mu_edit setTitle: _NS("Edit")];
469 [o_mi_cut setTitle: _NS("Cut")];
470 [o_mi_copy setTitle: _NS("Copy")];
471 [o_mi_paste setTitle: _NS("Paste")];
472 [o_mi_clear setTitle: _NS("Clear")];
473 [o_mi_select_all setTitle: _NS("Select All")];
475 [o_mu_controls setTitle: _NS("Controls")];
476 [o_mi_play setTitle: _NS("Play")];
477 [o_mi_stop setTitle: _NS("Stop")];
478 [o_mi_faster setTitle: _NS("Faster")];
479 [o_mi_slower setTitle: _NS("Slower")];
480 [o_mi_previous setTitle: _NS("Previous")];
481 [o_mi_next setTitle: _NS("Next")];
482 [o_mi_random setTitle: _NS("Random")];
483 [o_mi_repeat setTitle: _NS("Repeat One")];
484 [o_mi_loop setTitle: _NS("Repeat All")];
485 [o_mi_fwd setTitle: _NS("Step Forward")];
486 [o_mi_bwd setTitle: _NS("Step Backward")];
488 [o_mi_program setTitle: _NS("Program")];
489 [o_mu_program setTitle: _NS("Program")];
490 [o_mi_title setTitle: _NS("Title")];
491 [o_mu_title setTitle: _NS("Title")];
492 [o_mi_chapter setTitle: _NS("Chapter")];
493 [o_mu_chapter setTitle: _NS("Chapter")];
495 [o_mu_audio setTitle: _NS("Audio")];
496 [o_mi_vol_up setTitle: _NS("Volume Up")];
497 [o_mi_vol_down setTitle: _NS("Volume Down")];
498 [o_mi_mute setTitle: _NS("Mute")];
499 [o_mi_audiotrack setTitle: _NS("Audio Track")];
500 [o_mu_audiotrack setTitle: _NS("Audio Track")];
501 [o_mi_channels setTitle: _NS("Audio Channels")];
502 [o_mu_channels setTitle: _NS("Audio Channels")];
503 [o_mi_device setTitle: _NS("Audio Device")];
504 [o_mu_device setTitle: _NS("Audio Device")];
505 [o_mi_visual setTitle: _NS("Visualizations")];
506 [o_mu_visual setTitle: _NS("Visualizations")];
508 [o_mu_video setTitle: _NS("Video")];
509 [o_mi_half_window setTitle: _NS("Half Size")];
510 [o_mi_normal_window setTitle: _NS("Normal Size")];
511 [o_mi_double_window setTitle: _NS("Double Size")];
512 [o_mi_fittoscreen setTitle: _NS("Fit to Screen")];
513 [o_mi_fullscreen setTitle: _NS("Fullscreen")];
514 [o_mi_floatontop setTitle: _NS("Float on Top")];
515 [o_mi_snapshot setTitle: _NS("Snapshot")];
516 [o_mi_videotrack setTitle: _NS("Video Track")];
517 [o_mu_videotrack setTitle: _NS("Video Track")];
518 [o_mi_screen setTitle: _NS("Video Device")];
519 [o_mu_screen setTitle: _NS("Video Device")];
520 [o_mi_subtitle setTitle: _NS("Subtitles Track")];
521 [o_mu_subtitle setTitle: _NS("Subtitles Track")];
522 [o_mi_deinterlace setTitle: _NS("Deinterlace")];
523 [o_mu_deinterlace setTitle: _NS("Deinterlace")];
524 [o_mi_ffmpeg_pp setTitle: _NS("Post processing")];
525 [o_mu_ffmpeg_pp setTitle: _NS("Post processing")];
527 [o_mu_window setTitle: _NS("Window")];
528 [o_mi_minimize setTitle: _NS("Minimize Window")];
529 [o_mi_close_window setTitle: _NS("Close Window")];
530 [o_mi_controller setTitle: _NS("Controller")];
531 [o_mi_equalizer setTitle: _NS("Equalizer")];
532 [o_mi_extended setTitle: _NS("Extended controls")];
533 [o_mi_playlist setTitle: _NS("Playlist")];
534 [o_mi_info setTitle: _NS("Info")];
535 [o_mi_messages setTitle: _NS("Messages")];
537 [o_mi_bring_atf setTitle: _NS("Bring All to Front")];
539 [o_mu_help setTitle: _NS("Help")];
540 [o_mi_readme setTitle: _NS("ReadMe...")];
541 [o_mi_documentation setTitle: _NS("Online Documentation")];
542 [o_mi_reportabug setTitle: _NS("Report a Bug")];
543 [o_mi_website setTitle: _NS("VideoLAN Website")];
544 [o_mi_license setTitle: _NS("License")];
547 [o_dmi_play setTitle: _NS("Play")];
548 [o_dmi_stop setTitle: _NS("Stop")];
549 [o_dmi_next setTitle: _NS("Next")];
550 [o_dmi_previous setTitle: _NS("Previous")];
551 [o_dmi_mute setTitle: _NS("Mute")];
554 [o_error setTitle: _NS("Error")];
555 [o_err_lbl setStringValue: _NS("An error has occurred which probably prevented the execution of your request:")];
556 [o_err_bug_lbl setStringValue: _NS("If you believe that it is a bug, please follow the instructions at:")];
557 [o_err_btn_msgs setTitle: _NS("Open Messages Window")];
558 [o_err_btn_dismiss setTitle: _NS("Dismiss")];
559 [o_err_ckbk_surpress setTitle: _NS("Suppress further errors")];
561 [o_info_window setTitle: _NS("Info")];
564 - (void)applicationWillFinishLaunching:(NSNotification *)o_notification
566 o_msg_lock = [[NSLock alloc] init];
567 o_msg_arr = [[NSMutableArray arrayWithCapacity: 200] retain];
569 o_img_play = [[NSImage imageNamed: @"play"] retain];
570 o_img_play_pressed = [[NSImage imageNamed: @"play_blue"] retain];
571 o_img_pause = [[NSImage imageNamed: @"pause"] retain];
572 o_img_pause_pressed = [[NSImage imageNamed: @"pause_blue"] retain];
574 [p_intf->p_sys->o_sendport setDelegate: self];
575 [[NSRunLoop currentRunLoop]
576 addPort: p_intf->p_sys->o_sendport
577 forMode: NSDefaultRunLoopMode];
579 [NSTimer scheduledTimerWithTimeInterval: 0.5
580 target: self selector: @selector(manageIntf:)
581 userInfo: nil repeats: FALSE];
583 [NSThread detachNewThreadSelector: @selector(manage)
584 toTarget: self withObject: nil];
586 [o_controls setupVarMenuItem: o_mi_add_intf target: (vlc_object_t *)p_intf
587 var: "intf-add" selector: @selector(toggleVar:)];
589 vlc_thread_set_priority( p_intf, VLC_THREAD_PRIORITY_LOW );
592 - (BOOL)application:(NSApplication *)o_app openFile:(NSString *)o_filename
594 NSDictionary *o_dic = [NSDictionary dictionaryWithObjectsAndKeys: o_filename, @"ITEM_URL", nil];
595 [o_playlist appendArray:
596 [NSArray arrayWithObject: o_dic] atPos: -1 enqueue: NO];
601 - (NSString *)localizedString:(char *)psz
603 NSString * o_str = nil;
607 o_str = [[[NSString alloc] initWithUTF8String: psz] autorelease];
611 msg_Err( VLCIntf, "could not translate: %s", psz );
617 - (char *)delocalizeString:(NSString *)id
619 NSData * o_data = [id dataUsingEncoding: NSUTF8StringEncoding
620 allowLossyConversion: NO];
625 o_data = [id dataUsingEncoding: NSUTF8StringEncoding
626 allowLossyConversion: YES];
627 psz_string = malloc( [o_data length] + 1 );
628 [o_data getBytes: psz_string];
629 psz_string[ [o_data length] ] = '\0';
630 msg_Err( VLCIntf, "cannot convert to wanted encoding: %s",
635 psz_string = malloc( [o_data length] + 1 );
636 [o_data getBytes: psz_string];
637 psz_string[ [o_data length] ] = '\0';
643 /* i_width is in pixels */
644 - (NSString *)wrapString: (NSString *)o_in_string toWidth: (int) i_width
646 NSMutableString *o_wrapped;
647 NSString *o_out_string;
648 NSRange glyphRange, effectiveRange, charRange;
649 NSRect lineFragmentRect;
650 unsigned glyphIndex, breaksInserted = 0;
652 NSTextStorage *o_storage = [[NSTextStorage alloc] initWithString: o_in_string
653 attributes: [NSDictionary dictionaryWithObjectsAndKeys:
654 [NSFont labelFontOfSize: 0.0], NSFontAttributeName, nil]];
655 NSLayoutManager *o_layout_manager = [[NSLayoutManager alloc] init];
656 NSTextContainer *o_container = [[NSTextContainer alloc]
657 initWithContainerSize: NSMakeSize(i_width, 2000)];
659 [o_layout_manager addTextContainer: o_container];
660 [o_container release];
661 [o_storage addLayoutManager: o_layout_manager];
662 [o_layout_manager release];
664 o_wrapped = [o_in_string mutableCopy];
665 glyphRange = [o_layout_manager glyphRangeForTextContainer: o_container];
667 for( glyphIndex = glyphRange.location ; glyphIndex < NSMaxRange(glyphRange) ;
668 glyphIndex += effectiveRange.length) {
669 lineFragmentRect = [o_layout_manager lineFragmentRectForGlyphAtIndex: glyphIndex
670 effectiveRange: &effectiveRange];
671 charRange = [o_layout_manager characterRangeForGlyphRange: effectiveRange
672 actualGlyphRange: &effectiveRange];
673 if ([o_wrapped lineRangeForRange:
674 NSMakeRange(charRange.location + breaksInserted, charRange.length)].length > charRange.length) {
675 [o_wrapped insertString: @"\n" atIndex: NSMaxRange(charRange) + breaksInserted];
679 o_out_string = [NSString stringWithString: o_wrapped];
687 /*****************************************************************************
688 * hasDefinedShortcutKey: Check to see if the key press is a defined VLC
689 * shortcut key. If it is, pass it off to VLC for handling and return YES,
690 * otherwise ignore it and return NO (where it will get handled by Cocoa).
691 *****************************************************************************/
692 - (BOOL)hasDefinedShortcutKey:(NSEvent *)o_event
696 unsigned int i_pressed_modifiers = 0;
697 struct hotkey *p_hotkeys;
701 p_hotkeys = p_intf->p_vlc->p_hotkeys;
703 i_pressed_modifiers = [o_event modifierFlags];
705 if( i_pressed_modifiers & NSShiftKeyMask )
706 val.i_int |= KEY_MODIFIER_SHIFT;
707 if( i_pressed_modifiers & NSControlKeyMask )
708 val.i_int |= KEY_MODIFIER_CTRL;
709 if( i_pressed_modifiers & NSAlternateKeyMask )
710 val.i_int |= KEY_MODIFIER_ALT;
711 if( i_pressed_modifiers & NSCommandKeyMask )
712 val.i_int |= KEY_MODIFIER_COMMAND;
714 key = [[o_event charactersIgnoringModifiers] characterAtIndex: 0];
718 case NSDeleteCharacter:
719 case NSDeleteFunctionKey:
720 case NSDeleteCharFunctionKey:
721 case NSBackspaceCharacter:
722 case NSUpArrowFunctionKey:
723 case NSDownArrowFunctionKey:
724 case NSRightArrowFunctionKey:
725 case NSLeftArrowFunctionKey:
726 case NSEnterCharacter:
727 case NSCarriageReturnCharacter:
731 val.i_int |= CocoaKeyToVLC( key );
733 for( i = 0; p_hotkeys[i].psz_action != NULL; i++ )
735 if( p_hotkeys[i].i_key == val.i_int )
737 var_Set( p_intf->p_vlc, "key-pressed", val );
783 NSDate * o_sleep_date;
784 playlist_t * p_playlist;
786 /* new thread requires a new pool */
787 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
789 vlc_thread_set_priority( p_intf, VLC_THREAD_PRIORITY_LOW );
791 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
794 if( p_playlist != NULL )
796 var_AddCallback( p_playlist, "intf-change", PlaylistChanged, self );
797 var_AddCallback( p_playlist, "item-change", PlaylistChanged, self );
798 var_AddCallback( p_playlist, "item-append", PlaylistChanged, self );
799 var_AddCallback( p_playlist, "item-deleted", PlaylistChanged, self );
800 var_AddCallback( p_playlist, "playlist-current", PlaylistChanged, self );
802 vlc_object_release( p_playlist );
805 while( !p_intf->b_die )
807 vlc_mutex_lock( &p_intf->change_lock );
809 #define p_input p_intf->p_sys->p_input
811 if( p_input == NULL )
813 p_input = (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
816 /* Refresh the interface */
819 msg_Dbg( p_intf, "input has changed, refreshing interface" );
820 p_intf->p_sys->b_input_update = VLC_TRUE;
823 else if( p_input->b_die || p_input->b_dead )
826 p_intf->p_sys->b_intf_update = VLC_TRUE;
827 p_intf->p_sys->i_play_status = END_S;
828 [self setScrollField: _NS("VLC media player") stopAfter:-1];
829 vlc_object_release( p_input );
834 /* Manage volume status */
835 [self manageVolumeSlider];
837 vlc_mutex_unlock( &p_intf->change_lock );
839 o_sleep_date = [NSDate dateWithTimeIntervalSinceNow: .1];
840 [NSThread sleepUntilDate: o_sleep_date];
847 - (void)manageIntf:(NSTimer *)o_timer
851 if( p_intf->p_vlc->b_die == VLC_TRUE )
853 [o_timer invalidate];
857 #define p_input p_intf->p_sys->p_input
858 if( p_intf->p_sys->b_input_update )
860 /* Called when new input is opened */
861 p_intf->p_sys->b_current_title_update = VLC_TRUE;
862 p_intf->p_sys->b_intf_update = VLC_TRUE;
863 p_intf->p_sys->b_input_update = VLC_FALSE;
865 if( p_intf->p_sys->b_intf_update )
867 vlc_bool_t b_input = VLC_FALSE;
868 vlc_bool_t b_plmul = VLC_FALSE;
869 vlc_bool_t b_control = VLC_FALSE;
870 vlc_bool_t b_seekable = VLC_FALSE;
871 vlc_bool_t b_chapters = VLC_FALSE;
873 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
875 b_plmul = p_playlist->i_size > 1;
877 vlc_object_release( p_playlist );
879 if( ( b_input = ( p_input != NULL ) ) )
881 /* seekable streams */
882 var_Get( p_input, "seekable", &val);
883 b_seekable = val.b_bool;
885 /* check wether slow/fast motion is possible*/
886 b_control = p_input->input.b_can_pace_control;
888 /* chapters & titles */
889 //b_chapters = p_input->stream.i_area_nb > 1;
892 [o_btn_stop setEnabled: b_input];
893 [o_btn_ff setEnabled: b_seekable];
894 [o_btn_rewind setEnabled: b_seekable];
895 [o_btn_prev setEnabled: (b_plmul || b_chapters)];
896 [o_btn_next setEnabled: (b_plmul || b_chapters)];
898 [o_timeslider setFloatValue: 0.0];
899 [o_timeslider setEnabled: b_seekable];
900 [o_timefield setStringValue: @"0:00:00"];
902 p_intf->p_sys->b_intf_update = VLC_FALSE;
905 if( p_intf->p_sys->b_playmode_update )
907 [o_playlist playModeUpdated];
908 p_intf->p_sys->b_playmode_update = VLC_FALSE;
910 if( p_intf->p_sys->b_playlist_update )
912 [o_playlist playlistUpdated];
913 p_intf->p_sys->b_playlist_update = VLC_FALSE;
916 if( p_intf->p_sys->b_fullscreen_update )
918 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
920 var_Get( p_playlist, "fullscreen", &val );
921 [o_btn_fullscreen setState: val.b_bool];
922 vlc_object_release( p_playlist );
924 p_intf->p_sys->b_fullscreen_update = VLC_FALSE;
927 if( p_input && !p_input->b_die )
931 if( p_intf->p_sys->b_current_title_update )
934 vout_thread_t *p_vout;
935 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
938 if( p_playlist == NULL || p_playlist->status.p_item == NULL )
942 o_temp = [NSString stringWithUTF8String:
943 p_playlist->status.p_item->input.psz_name];
945 o_temp = [NSString stringWithCString:
946 p_playlist->status.p_item->input.psz_name];
947 [self setScrollField: o_temp stopAfter:-1];
949 p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
954 NSEnumerator * o_enum = [[NSApp orderedWindows] objectEnumerator];
956 while( ( o_vout_wnd = [o_enum nextObject] ) )
958 if( [[o_vout_wnd className] isEqualToString: @"VLCWindow"] )
960 [o_vout_wnd updateTitle];
963 vlc_object_release( (vlc_object_t *)p_vout );
965 [o_playlist updateRowSelection];
966 vlc_object_release( p_playlist );
967 p_intf->p_sys->b_current_title_update = FALSE;
970 if( p_input && [o_timeslider isEnabled] )
972 /* Update the slider */
979 var_Get( p_input, "position", &pos );
980 f_updated = 10000. * pos.f_float;
981 [o_timeslider setFloatValue: f_updated];
983 var_Get( p_input, "time", &time );
984 i_seconds = time.i_time / 1000000;
986 o_time = [NSString stringWithFormat: @"%d:%02d:%02d",
987 (int) (i_seconds / (60 * 60)),
988 (int) (i_seconds / 60 % 60),
989 (int) (i_seconds % 60)];
990 [o_timefield setStringValue: o_time];
993 if( p_intf->p_sys->b_volume_update )
996 o_text = [NSString stringWithFormat: _NS("Volume: %d%%"), i_lastShownVolume * 400 / AOUT_VOLUME_MAX];
997 if( i_lastShownVolume != -1 )
998 [self setScrollField:o_text stopAfter:1000000];
1000 [o_volumeslider setFloatValue: (float)i_lastShownVolume / AOUT_VOLUME_STEP];
1001 [o_volumeslider setEnabled: TRUE];
1002 p_intf->p_sys->b_mute = ( i_lastShownVolume == 0 );
1003 p_intf->p_sys->b_volume_update = FALSE;
1006 /* Manage Playing status */
1007 var_Get( p_input, "state", &val );
1008 if( p_intf->p_sys->i_play_status != val.i_int )
1010 p_intf->p_sys->i_play_status = val.i_int;
1011 [self playStatusUpdated: p_intf->p_sys->i_play_status];
1016 p_intf->p_sys->i_play_status = END_S;
1017 p_intf->p_sys->b_intf_update = VLC_TRUE;
1018 [self playStatusUpdated: p_intf->p_sys->i_play_status];
1019 [self setSubmenusEnabled: FALSE];
1024 [self updateMessageArray];
1026 if( (i_end_scroll != -1) && (mdate() > i_end_scroll) )
1027 [self resetScrollField];
1030 [NSTimer scheduledTimerWithTimeInterval: 0.3
1031 target: self selector: @selector(manageIntf:)
1032 userInfo: nil repeats: FALSE];
1037 #define p_input p_intf->p_sys->p_input
1038 if( p_input != NULL )
1040 [o_controls setupVarMenuItem: o_mi_program target: (vlc_object_t *)p_input
1041 var: "program" selector: @selector(toggleVar:)];
1043 [o_controls setupVarMenuItem: o_mi_title target: (vlc_object_t *)p_input
1044 var: "title" selector: @selector(toggleVar:)];
1046 [o_controls setupVarMenuItem: o_mi_chapter target: (vlc_object_t *)p_input
1047 var: "chapter" selector: @selector(toggleVar:)];
1049 [o_controls setupVarMenuItem: o_mi_audiotrack target: (vlc_object_t *)p_input
1050 var: "audio-es" selector: @selector(toggleVar:)];
1052 [o_controls setupVarMenuItem: o_mi_videotrack target: (vlc_object_t *)p_input
1053 var: "video-es" selector: @selector(toggleVar:)];
1055 [o_controls setupVarMenuItem: o_mi_subtitle target: (vlc_object_t *)p_input
1056 var: "spu-es" selector: @selector(toggleVar:)];
1058 aout_instance_t * p_aout = vlc_object_find( p_intf, VLC_OBJECT_AOUT,
1060 if ( p_aout != NULL )
1062 [o_controls setupVarMenuItem: o_mi_channels target: (vlc_object_t *)p_aout
1063 var: "audio-channels" selector: @selector(toggleVar:)];
1065 [o_controls setupVarMenuItem: o_mi_device target: (vlc_object_t *)p_aout
1066 var: "audio-device" selector: @selector(toggleVar:)];
1068 [o_controls setupVarMenuItem: o_mi_visual target: (vlc_object_t *)p_aout
1069 var: "visual" selector: @selector(toggleVar:)];
1070 vlc_object_release( (vlc_object_t *)p_aout );
1073 vout_thread_t * p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
1076 if ( p_vout != NULL )
1078 vlc_object_t * p_dec_obj;
1080 [o_controls setupVarMenuItem: o_mi_screen target: (vlc_object_t *)p_vout
1081 var: "video-device" selector: @selector(toggleVar:)];
1083 [o_controls setupVarMenuItem: o_mi_deinterlace target: (vlc_object_t *)p_vout
1084 var: "deinterlace" selector: @selector(toggleVar:)];
1086 p_dec_obj = (vlc_object_t *)vlc_object_find(
1087 (vlc_object_t *)p_vout,
1090 if ( p_dec_obj != NULL )
1092 [o_controls setupVarMenuItem: o_mi_ffmpeg_pp target:
1093 (vlc_object_t *)p_dec_obj var:"ffmpeg-pp-q" selector:
1094 @selector(toggleVar:)];
1096 vlc_object_release(p_dec_obj);
1098 vlc_object_release( (vlc_object_t *)p_vout );
1104 - (void)setScrollField:(NSString *)o_string stopAfter:(int)timeout
1107 i_end_scroll = mdate() + timeout;
1110 [o_scrollfield setStringValue: o_string];
1113 - (void)resetScrollField
1116 #define p_input p_intf->p_sys->p_input
1117 if( p_input && !p_input->b_die )
1120 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1122 if( p_playlist == NULL )
1126 o_temp = [NSString stringWithUTF8String:
1127 p_playlist->status.p_item->input.psz_name];
1128 if( o_temp == NULL )
1129 o_temp = [NSString stringWithCString:
1130 p_playlist->status.p_item->input.psz_name];
1131 [self setScrollField: o_temp stopAfter:-1];
1132 vlc_object_release( p_playlist );
1136 [self setScrollField: _NS("VLC media player") stopAfter:-1];
1139 - (void)updateMessageArray
1141 int i_start, i_stop;
1144 vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
1145 i_stop = *p_intf->p_sys->p_sub->pi_stop;
1146 vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
1148 if( p_intf->p_sys->p_sub->i_start != i_stop )
1150 NSColor *o_white = [NSColor whiteColor];
1151 NSColor *o_red = [NSColor redColor];
1152 NSColor *o_yellow = [NSColor yellowColor];
1153 NSColor *o_gray = [NSColor grayColor];
1155 NSColor * pp_color[4] = { o_white, o_red, o_yellow, o_gray };
1156 static const char * ppsz_type[4] = { ": ", " error: ",
1157 " warning: ", " debug: " };
1159 for( i_start = p_intf->p_sys->p_sub->i_start;
1161 i_start = (i_start+1) % VLC_MSG_QSIZE )
1164 NSDictionary *o_attr;
1165 NSAttributedString *o_msg_color;
1167 int i_type = p_intf->p_sys->p_sub->p_msg[i_start].i_type;
1171 if( [o_msg_arr count] + 2 > 400 )
1173 unsigned rid[] = { 0, 1 };
1174 [o_msg_arr removeObjectsFromIndices: (unsigned *)&rid
1175 numIndices: sizeof(rid)/sizeof(rid[0])];
1178 o_attr = [NSDictionary dictionaryWithObject: o_gray
1179 forKey: NSForegroundColorAttributeName];
1180 o_msg = [NSString stringWithFormat: @"%s%s",
1181 p_intf->p_sys->p_sub->p_msg[i_start].psz_module,
1183 o_msg_color = [[NSAttributedString alloc]
1184 initWithString: o_msg attributes: o_attr];
1185 [o_msg_arr addObject: [o_msg_color autorelease]];
1187 o_attr = [NSDictionary dictionaryWithObject: pp_color[i_type]
1188 forKey: NSForegroundColorAttributeName];
1189 o_msg = [NSString stringWithFormat: @"%s\n",
1190 p_intf->p_sys->p_sub->p_msg[i_start].psz_msg];
1191 o_msg_color = [[NSAttributedString alloc]
1192 initWithString: o_msg attributes: o_attr];
1193 [o_msg_arr addObject: [o_msg_color autorelease]];
1195 [o_msg_lock unlock];
1197 var_Get( p_intf->p_vlc, "verbose", &quiet );
1199 if( i_type == 1 && quiet.i_int > -1 )
1201 NSString *o_my_msg = [NSString stringWithFormat: @"%s: %s\n",
1202 p_intf->p_sys->p_sub->p_msg[i_start].psz_module,
1203 p_intf->p_sys->p_sub->p_msg[i_start].psz_msg];
1205 NSRange s_r = NSMakeRange( [[o_err_msg string] length], 0 );
1206 [o_err_msg setEditable: YES];
1207 [o_err_msg setSelectedRange: s_r];
1208 [o_err_msg insertText: o_my_msg];
1210 [o_error makeKeyAndOrderFront: self];
1211 [o_err_msg setEditable: NO];
1215 vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
1216 p_intf->p_sys->p_sub->i_start = i_start;
1217 vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
1221 - (void)playStatusUpdated:(int)i_status
1223 if( i_status == PLAYING_S )
1225 [o_btn_play setImage: o_img_pause];
1226 [o_btn_play setAlternateImage: o_img_pause_pressed];
1227 [o_btn_play setToolTip: _NS("Pause")];
1228 [o_mi_play setTitle: _NS("Pause")];
1229 [o_dmi_play setTitle: _NS("Pause")];
1233 [o_btn_play setImage: o_img_play];
1234 [o_btn_play setAlternateImage: o_img_play_pressed];
1235 [o_btn_play setToolTip: _NS("Play")];
1236 [o_mi_play setTitle: _NS("Play")];
1237 [o_dmi_play setTitle: _NS("Play")];
1241 - (void)setSubmenusEnabled:(BOOL)b_enabled
1243 [o_mi_program setEnabled: b_enabled];
1244 [o_mi_title setEnabled: b_enabled];
1245 [o_mi_chapter setEnabled: b_enabled];
1246 [o_mi_audiotrack setEnabled: b_enabled];
1247 [o_mi_visual setEnabled: b_enabled];
1248 [o_mi_videotrack setEnabled: b_enabled];
1249 [o_mi_subtitle setEnabled: b_enabled];
1250 [o_mi_channels setEnabled: b_enabled];
1251 [o_mi_deinterlace setEnabled: b_enabled];
1252 [o_mi_ffmpeg_pp setEnabled: b_enabled];
1253 [o_mi_device setEnabled: b_enabled];
1254 [o_mi_screen setEnabled: b_enabled];
1257 - (void)manageVolumeSlider
1259 audio_volume_t i_volume;
1260 aout_VolumeGet( p_intf, &i_volume );
1262 if( i_volume != i_lastShownVolume )
1264 i_lastShownVolume = i_volume;
1265 p_intf->p_sys->b_volume_update = TRUE;
1269 - (IBAction)timesliderUpdate:(id)sender
1271 #define p_input p_intf->p_sys->p_input
1274 switch( [[NSApp currentEvent] type] )
1277 case NSLeftMouseDown:
1278 case NSLeftMouseDragged:
1279 f_updated = [sender floatValue];
1286 if( p_input != NULL )
1293 pos.f_float = f_updated / 10000.;
1294 var_Set( p_input, "position", pos );
1295 [o_timeslider setFloatValue: f_updated];
1297 var_Get( p_input, "time", &time );
1298 i_seconds = time.i_time / 1000000;
1300 o_time = [NSString stringWithFormat: @"%d:%02d:%02d",
1301 (int) (i_seconds / (60 * 60)),
1302 (int) (i_seconds / 60 % 60),
1303 (int) (i_seconds % 60)];
1304 [o_timefield setStringValue: o_time];
1311 playlist_t * p_playlist;
1312 vout_thread_t * p_vout;
1314 #define p_input p_intf->p_sys->p_input
1317 vlc_object_release( p_input );
1323 if( ( p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1326 playlist_Stop( p_playlist );
1327 vlc_object_release( p_playlist );
1330 /* FIXME - Wait here until all vouts are terminated because
1331 libvlc's VLC_CleanUp destroys interfaces before vouts, which isn't
1332 good on OS X. We definitly need a cleaner way to handle this,
1333 but this may hopefully be good enough for now.
1334 -- titer 2003/11/22 */
1335 while( ( p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
1338 vlc_object_release( p_vout );
1343 if( o_img_pause_pressed != nil )
1345 [o_img_pause_pressed release];
1346 o_img_pause_pressed = nil;
1349 if( o_img_pause_pressed != nil )
1351 [o_img_pause_pressed release];
1352 o_img_pause_pressed = nil;
1355 if( o_img_pause != nil )
1357 [o_img_pause release];
1361 if( o_img_play != nil )
1363 [o_img_play release];
1367 if( o_msg_arr != nil )
1369 [o_msg_arr removeAllObjects];
1370 [o_msg_arr release];
1374 if( o_msg_lock != nil )
1376 [o_msg_lock release];
1380 /* write cached user defaults to disk */
1381 [[NSUserDefaults standardUserDefaults] synchronize];
1383 p_intf->b_die = VLC_TRUE;
1387 - (IBAction)clearRecentItems:(id)sender
1389 [[NSDocumentController sharedDocumentController]
1390 clearRecentDocuments: nil];
1393 - (void)openRecentItem:(id)sender
1395 [self application: nil openFile: [sender title]];
1398 - (IBAction)intfOpenFile:(id)sender
1400 if (!nib_open_loaded)
1402 nib_open_loaded = [NSBundle loadNibNamed:@"Open" owner:self];
1403 [o_open awakeFromNib];
1410 - (IBAction)intfOpenFileGeneric:(id)sender
1412 if (!nib_open_loaded)
1414 nib_open_loaded = [NSBundle loadNibNamed:@"Open" owner:self];
1415 [o_open awakeFromNib];
1416 [o_open openFileGeneric];
1418 [o_open openFileGeneric];
1422 - (IBAction)intfOpenDisc:(id)sender
1424 if (!nib_open_loaded)
1426 nib_open_loaded = [NSBundle loadNibNamed:@"Open" owner:self];
1427 [o_open awakeFromNib];
1434 - (IBAction)intfOpenNet:(id)sender
1436 if (!nib_open_loaded)
1438 nib_open_loaded = [NSBundle loadNibNamed:@"Open" owner:self];
1439 [o_open awakeFromNib];
1446 - (IBAction)showWizard:(id)sender
1448 if (!nib_wizard_loaded)
1450 nib_wizard_loaded = [NSBundle loadNibNamed:@"Wizard" owner:self];
1451 [o_wizard initStrings];
1452 [o_wizard showWizard];
1454 [o_wizard showWizard];
1458 - (IBAction)showExtended:(id)sender
1460 if (!nib_extended_loaded)
1462 nib_extended_loaded = [NSBundle loadNibNamed:@"Extended" owner:self];
1463 [o_extended initStrings];
1464 [o_extended showPanel];
1466 [o_extended showPanel];
1470 - (IBAction)viewAbout:(id)sender
1472 if (!nib_about_loaded)
1474 nib_about_loaded = [NSBundle loadNibNamed:@"About" owner:self];
1475 [o_about showPanel];
1477 [o_about showPanel];
1481 - (IBAction)viewPreferences:(id)sender
1484 if( o_prefs == nil )
1485 o_prefs = [[VLCPrefs alloc] init];
1486 [o_prefs showPrefs];
1489 - (IBAction)closeError:(id)sender
1493 if( [o_err_ckbk_surpress state] == NSOnState )
1496 var_Set( p_intf->p_vlc, "verbose", val );
1498 [o_err_msg setString: @""];
1499 [o_error performClose: self];
1502 - (IBAction)openReadMe:(id)sender
1504 NSString * o_path = [[NSBundle mainBundle]
1505 pathForResource: @"README.MacOSX" ofType: @"rtf"];
1507 [[NSWorkspace sharedWorkspace] openFile: o_path
1508 withApplication: @"TextEdit"];
1511 - (IBAction)openDocumentation:(id)sender
1513 NSURL * o_url = [NSURL URLWithString:
1514 @"http://www.videolan.org/doc/"];
1516 [[NSWorkspace sharedWorkspace] openURL: o_url];
1519 - (IBAction)reportABug:(id)sender
1521 NSURL * o_url = [NSURL URLWithString:
1522 @"http://www.videolan.org/support/bug-reporting.html"];
1524 [[NSWorkspace sharedWorkspace] openURL: o_url];
1527 - (IBAction)openWebsite:(id)sender
1529 NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org/"];
1531 [[NSWorkspace sharedWorkspace] openURL: o_url];
1534 - (IBAction)openLicense:(id)sender
1536 NSString * o_path = [[NSBundle mainBundle]
1537 pathForResource: @"COPYING" ofType: nil];
1539 [[NSWorkspace sharedWorkspace] openFile: o_path
1540 withApplication: @"TextEdit"];
1543 - (IBAction)openForum:(id)sender
1545 NSURL * o_url = [NSURL URLWithString: @"http://forum.videolan.org/"];
1547 [[NSWorkspace sharedWorkspace] openURL: o_url];
1550 - (IBAction)openDonate:(id)sender
1552 NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org/contribute.html#paypal"];
1554 [[NSWorkspace sharedWorkspace] openURL: o_url];
1557 - (IBAction)openCrashLog:(id)sender
1559 NSString * o_path = [@"~/Library/Logs/CrashReporter/VLC.crash.log"
1560 stringByExpandingTildeInPath];
1563 if ( [[NSFileManager defaultManager] fileExistsAtPath: o_path ] )
1565 [[NSWorkspace sharedWorkspace] openFile: o_path
1566 withApplication: @"Console"];
1570 NSBeginInformationalAlertSheet(_NS("No CrashLog found"), @"Continue", nil, nil, o_msgs_panel, self, NULL, NULL, nil, _NS("You haven't experienced any heavy crashes yet.") );
1575 - (void)windowDidBecomeKey:(NSNotification *)o_notification
1577 if( [o_notification object] == o_msgs_panel )
1580 NSEnumerator * o_enum;
1582 [o_messages setString: @""];
1586 o_enum = [o_msg_arr objectEnumerator];
1588 while( ( o_msg = [o_enum nextObject] ) != nil )
1590 [o_messages insertText: o_msg];
1593 [o_msg_lock unlock];
1597 - (IBAction)togglePlaylist:(id)sender
1599 NSRect o_rect = [o_window frame];
1600 /*First, check if the playlist is visible*/
1601 if( o_rect.size.height <= 200 )
1603 b_small_window = YES; /* we know we are small, make sure this is actually set (see case below) */
1605 if ( o_size_with_playlist.height > 200 )
1607 o_rect.size.height = o_size_with_playlist.height;
1609 o_rect.size.height = 500;
1612 if ( o_size_with_playlist.width > [o_window minSize].width )
1614 o_rect.size.width = o_size_with_playlist.width;
1616 o_rect.size.width = 500;
1619 o_rect.size.height = (o_size_with_playlist.height > 200) ?
1620 o_size_with_playlist.height : 500;
1621 o_rect.origin.x = [o_window frame].origin.x;
1622 o_rect.origin.y = [o_window frame].origin.y - o_rect.size.height +
1623 [o_window minSize].height;
1624 [o_btn_playlist setState: YES];
1629 o_rect.size.height = [o_window minSize].height;
1630 o_rect.size.width = [o_window minSize].width;
1631 o_rect.origin.x = [o_window frame].origin.x;
1632 /* Calculate the position of the lower right corner after resize */
1633 o_rect.origin.y = [o_window frame].origin.y +
1634 [o_window frame].size.height - [o_window minSize].height;
1636 [o_playlist_view setAutoresizesSubviews: NO];
1637 [o_playlist_view removeFromSuperview];
1638 [o_btn_playlist setState: NO];
1639 b_small_window = NO; /* we aren't small here just yet. we are doing an animated resize after this */
1642 [o_window setFrame: o_rect display:YES animate: YES];
1645 - (void)updateTogglePlaylistState
1647 if( [o_window frame].size.height <= 200 )
1649 [o_btn_playlist setState: NO];
1653 [o_btn_playlist setState: YES];
1657 - (NSSize)windowWillResize:(NSWindow *)sender toSize:(NSSize)proposedFrameSize
1659 /* Not triggered on a window resize or maxification of the window. only by window mouse dragging resize */
1661 /*Stores the size the controller one resize, to be able to restore it when
1662 toggling the playlist*/
1663 o_size_with_playlist = proposedFrameSize;
1665 if( proposedFrameSize.height <= 200 )
1667 if( b_small_window == NO )
1669 /* if large and going to small then hide */
1670 b_small_window = YES;
1671 [o_playlist_view setAutoresizesSubviews: NO];
1672 [o_playlist_view removeFromSuperview];
1674 return NSMakeSize( proposedFrameSize.width, [o_window minSize].height);
1676 return proposedFrameSize;
1679 - (void)windowDidResize:(NSNotification *)notif
1681 if( [o_window frame].size.height > 200 && b_small_window )
1683 /* If large and coming from small then show */
1684 [o_playlist_view setAutoresizesSubviews: YES];
1685 [o_playlist_view setFrame: NSMakeRect( 10, 10, [o_window frame].size.width - 20, [o_window frame].size.height - [o_window minSize].height - 10 )];
1686 [o_playlist_view setNeedsDisplay:YES];
1687 [[o_window contentView] addSubview: o_playlist_view];
1688 b_small_window = NO;
1690 [self updateTogglePlaylistState];
1695 @implementation VLCMain (NSMenuValidation)
1697 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
1699 NSString *o_title = [o_mi title];
1700 BOOL bEnabled = TRUE;
1702 /* Recent Items Menu */
1703 if( [o_title isEqualToString: _NS("Clear Menu")] )
1705 NSMenu * o_menu = [o_mi_open_recent submenu];
1706 int i_nb_items = [o_menu numberOfItems];
1707 NSArray * o_docs = [[NSDocumentController sharedDocumentController]
1708 recentDocumentURLs];
1709 UInt32 i_nb_docs = [o_docs count];
1711 if( i_nb_items > 1 )
1713 while( --i_nb_items )
1715 [o_menu removeItemAtIndex: 0];
1724 [o_menu insertItem: [NSMenuItem separatorItem] atIndex: 0];
1730 o_url = [o_docs objectAtIndex: i_nb_docs];
1732 if( [o_url isFileURL] )
1734 o_doc = [o_url path];
1738 o_doc = [o_url absoluteString];
1741 [o_menu insertItemWithTitle: o_doc
1742 action: @selector(openRecentItem:)
1743 keyEquivalent: @"" atIndex: 0];
1745 if( i_nb_docs == 0 )
1761 @implementation VLCMain (Internal)
1763 - (void)handlePortMessage:(NSPortMessage *)o_msg
1768 NSInvocation * o_inv;
1769 NSConditionLock * o_lock;
1771 o_data = [[o_msg components] lastObject];
1772 o_inv = *((NSInvocation **)[o_data bytes]);
1773 [o_inv getArgument: &o_value atIndex: 2];
1774 val = (id **)[o_value pointerValue];
1775 [o_inv setArgument: val[1] atIndex: 2];
1780 [o_lock unlockWithCondition: 1];