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 */
43 #include "bookmarks.h"
45 #include "interaction.h"
46 /*#include "update.h"*/
48 /*****************************************************************************
50 *****************************************************************************/
51 static void Run ( intf_thread_t *p_intf );
53 /*****************************************************************************
54 * OpenIntf: initialize interface
55 *****************************************************************************/
56 int E_(OpenIntf) ( vlc_object_t *p_this )
58 intf_thread_t *p_intf = (intf_thread_t*) p_this;
60 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
61 if( p_intf->p_sys == NULL )
66 memset( p_intf->p_sys, 0, sizeof( *p_intf->p_sys ) );
68 p_intf->p_sys->o_pool = [[NSAutoreleasePool alloc] init];
70 /* Put Cocoa into multithread mode as soon as possible.
71 * http://developer.apple.com/techpubs/macosx/Cocoa/
72 * TasksAndConcepts/ProgrammingTopics/Multithreading/index.html
73 * This thread does absolutely nothing at all. */
74 [NSThread detachNewThreadSelector:@selector(self) toTarget:[NSString string] withObject:nil];
76 p_intf->p_sys->o_sendport = [[NSPort port] retain];
77 p_intf->p_sys->p_sub = msg_Subscribe( p_intf );
78 p_intf->b_play = VLC_TRUE;
84 /*****************************************************************************
85 * CloseIntf: destroy interface
86 *****************************************************************************/
87 void E_(CloseIntf) ( vlc_object_t *p_this )
89 intf_thread_t *p_intf = (intf_thread_t*) p_this;
91 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
93 [p_intf->p_sys->o_sendport release];
94 [p_intf->p_sys->o_pool release];
96 free( p_intf->p_sys );
99 /*****************************************************************************
101 *****************************************************************************/
102 static void Run( intf_thread_t *p_intf )
104 /* Do it again - for some unknown reason, vlc_thread_create() often
105 * fails to go to real-time priority with the first launched thread
107 vlc_thread_set_priority( p_intf, VLC_THREAD_PRIORITY_LOW );
108 [[VLCMain sharedInstance] setIntf: p_intf];
109 [NSBundle loadNibNamed: @"MainMenu" owner: NSApp];
111 [[VLCMain sharedInstance] terminate];
114 int ExecuteOnMainThread( id target, SEL sel, void * p_arg )
118 //NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
120 if( [target respondsToSelector: @selector(performSelectorOnMainThread:
121 withObject:waitUntilDone:)] )
123 [target performSelectorOnMainThread: sel
124 withObject: [NSValue valueWithPointer: p_arg]
127 else if( NSApp != nil && [[VLCMain sharedInstance] respondsToSelector: @selector(getIntf)] )
132 NSPort * o_recv_port;
133 NSInvocation * o_inv;
134 NSPortMessage * o_msg;
135 intf_thread_t * p_intf;
136 NSConditionLock * o_lock;
137 NSMethodSignature * o_sig;
139 id * val[] = { &o_lock, &o_v2 };
141 p_intf = (intf_thread_t *)VLCIntf;
143 o_recv_port = [[NSPort port] retain];
144 o_v1 = [NSValue valueWithPointer: val];
145 o_v2 = [NSValue valueWithPointer: p_arg];
147 o_sig = [target methodSignatureForSelector: sel];
148 o_inv = [NSInvocation invocationWithMethodSignature: o_sig];
149 [o_inv setArgument: &o_v1 atIndex: 2];
150 [o_inv setTarget: target];
151 [o_inv setSelector: sel];
153 o_array = [NSArray arrayWithObject:
154 [NSData dataWithBytes: &o_inv length: sizeof(o_inv)]];
155 o_msg = [[NSPortMessage alloc]
156 initWithSendPort: p_intf->p_sys->o_sendport
157 receivePort: o_recv_port components: o_array];
159 o_lock = [[NSConditionLock alloc] initWithCondition: 0];
160 [o_msg sendBeforeDate: [NSDate distantPast]];
161 [o_lock lockWhenCondition: 1];
166 [o_recv_port release];
178 /*****************************************************************************
179 * playlistChanged: Callback triggered by the intf-change playlist
180 * variable, to let the intf update the playlist.
181 *****************************************************************************/
182 static int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,
183 vlc_value_t old_val, vlc_value_t new_val, void *param )
185 intf_thread_t * p_intf = VLCIntf;
186 p_intf->p_sys->b_playlist_update = TRUE;
187 p_intf->p_sys->b_intf_update = TRUE;
188 p_intf->p_sys->b_playmode_update = TRUE;
192 /*****************************************************************************
193 * FullscreenChanged: Callback triggered by the fullscreen-change playlist
194 * variable, to let the intf update the controller.
195 *****************************************************************************/
196 static int FullscreenChanged( vlc_object_t *p_this, const char *psz_variable,
197 vlc_value_t old_val, vlc_value_t new_val, void *param )
199 intf_thread_t * p_intf = VLCIntf;
200 p_intf->p_sys->b_fullscreen_update = TRUE;
204 /*****************************************************************************
205 * InteractCallback: Callback triggered by the interaction
206 * variable, to let the intf display error and interaction dialogs
207 *****************************************************************************/
208 static int InteractCallback( vlc_object_t *p_this, const char *psz_variable,
209 vlc_value_t old_val, vlc_value_t new_val, void *param )
211 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
212 VLCMain *interface = (VLCMain *)param;
213 interaction_dialog_t *p_dialog = (interaction_dialog_t *)(new_val.p_address);
214 NSValue *o_value = [NSValue valueWithPointer:p_dialog];
216 [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCNewInteractionEventNotification" object:[interface getInteractionList]
217 userInfo:[NSDictionary dictionaryWithObject:o_value forKey:@"VLCDialogPointer"]];
226 unsigned int i_vlckey;
227 } nskeys_to_vlckeys[] =
229 { NSUpArrowFunctionKey, KEY_UP },
230 { NSDownArrowFunctionKey, KEY_DOWN },
231 { NSLeftArrowFunctionKey, KEY_LEFT },
232 { NSRightArrowFunctionKey, KEY_RIGHT },
233 { NSF1FunctionKey, KEY_F1 },
234 { NSF2FunctionKey, KEY_F2 },
235 { NSF3FunctionKey, KEY_F3 },
236 { NSF4FunctionKey, KEY_F4 },
237 { NSF5FunctionKey, KEY_F5 },
238 { NSF6FunctionKey, KEY_F6 },
239 { NSF7FunctionKey, KEY_F7 },
240 { NSF8FunctionKey, KEY_F8 },
241 { NSF9FunctionKey, KEY_F9 },
242 { NSF10FunctionKey, KEY_F10 },
243 { NSF11FunctionKey, KEY_F11 },
244 { NSF12FunctionKey, KEY_F12 },
245 { NSHomeFunctionKey, KEY_HOME },
246 { NSEndFunctionKey, KEY_END },
247 { NSPageUpFunctionKey, KEY_PAGEUP },
248 { NSPageDownFunctionKey, KEY_PAGEDOWN },
249 { NSTabCharacter, KEY_TAB },
250 { NSCarriageReturnCharacter, KEY_ENTER },
251 { NSEnterCharacter, KEY_ENTER },
252 { NSBackspaceCharacter, KEY_BACKSPACE },
253 { (unichar) ' ', KEY_SPACE },
254 { (unichar) 0x1b, KEY_ESC },
258 unichar VLCKeyToCocoa( unsigned int i_key )
262 for( i = 0; nskeys_to_vlckeys[i].i_vlckey != 0; i++ )
264 if( nskeys_to_vlckeys[i].i_vlckey == (i_key & ~KEY_MODIFIER) )
266 return nskeys_to_vlckeys[i].i_nskey;
269 return (unichar)(i_key & ~KEY_MODIFIER);
272 unsigned int CocoaKeyToVLC( unichar i_key )
276 for( i = 0; nskeys_to_vlckeys[i].i_nskey != 0; i++ )
278 if( nskeys_to_vlckeys[i].i_nskey == i_key )
280 return nskeys_to_vlckeys[i].i_vlckey;
283 return (unsigned int)i_key;
286 unsigned int VLCModifiersToCocoa( unsigned int i_key )
288 unsigned int new = 0;
289 if( i_key & KEY_MODIFIER_COMMAND )
290 new |= NSCommandKeyMask;
291 if( i_key & KEY_MODIFIER_ALT )
292 new |= NSAlternateKeyMask;
293 if( i_key & KEY_MODIFIER_SHIFT )
294 new |= NSShiftKeyMask;
295 if( i_key & KEY_MODIFIER_CTRL )
296 new |= NSControlKeyMask;
300 /*****************************************************************************
301 * VLCMain implementation
302 *****************************************************************************/
303 @implementation VLCMain
305 static VLCMain *_o_sharedMainInstance = nil;
307 + (VLCMain *)sharedInstance
309 return _o_sharedMainInstance ? _o_sharedMainInstance : [[self alloc] init];
314 if( _o_sharedMainInstance) {
317 _o_sharedMainInstance = [super init];
320 o_about = [[VLAboutBox alloc] init];
322 o_open = [[VLCOpen alloc] init];
323 o_wizard = [[VLCWizard alloc] init];
325 o_bookmarks = [[VLCBookmarks alloc] init];
326 o_embedded_list = [[VLCEmbeddedList alloc] init];
327 o_interaction_list = [[VLCInteractionList alloc] init];
329 /*o_update = [[VLCUpdate alloc] init];*/
331 i_lastShownVolume = -1;
332 return _o_sharedMainInstance;
335 - (void)setIntf: (intf_thread_t *)p_mainintf {
339 - (intf_thread_t *)getIntf {
345 unsigned int i_key = 0;
346 playlist_t *p_playlist;
349 /* Check if we already did this once. Opening the other nibs calls it too, because VLCMain is the owner */
350 if( nib_main_loaded ) return;
353 [o_window setExcludedFromWindowsMenu: TRUE];
354 [o_msgs_panel setExcludedFromWindowsMenu: TRUE];
355 [o_msgs_panel setDelegate: self];
357 i_key = config_GetInt( p_intf, "key-quit" );
358 [o_mi_quit setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
359 [o_mi_quit setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
360 i_key = config_GetInt( p_intf, "key-play-pause" );
361 [o_mi_play setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
362 [o_mi_play setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
363 i_key = config_GetInt( p_intf, "key-stop" );
364 [o_mi_stop setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
365 [o_mi_stop setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
366 i_key = config_GetInt( p_intf, "key-faster" );
367 [o_mi_faster setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
368 [o_mi_faster setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
369 i_key = config_GetInt( p_intf, "key-slower" );
370 [o_mi_slower setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
371 [o_mi_slower setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
372 i_key = config_GetInt( p_intf, "key-prev" );
373 [o_mi_previous setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
374 [o_mi_previous setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
375 i_key = config_GetInt( p_intf, "key-next" );
376 [o_mi_next setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
377 [o_mi_next setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
378 i_key = config_GetInt( p_intf, "key-jump+short" );
379 [o_mi_fwd setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
380 [o_mi_fwd setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
381 i_key = config_GetInt( p_intf, "key-jump-short" );
382 [o_mi_bwd setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
383 [o_mi_bwd setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
384 i_key = config_GetInt( p_intf, "key-jump+medium" );
385 [o_mi_fwd1m setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
386 [o_mi_fwd1m setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
387 i_key = config_GetInt( p_intf, "key-jump-medium" );
388 [o_mi_bwd1m setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
389 [o_mi_bwd1m setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
390 i_key = config_GetInt( p_intf, "key-jump+long" );
391 [o_mi_fwd5m setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
392 [o_mi_fwd5m setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
393 i_key = config_GetInt( p_intf, "key-jump-long" );
394 [o_mi_bwd5m setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
395 [o_mi_bwd5m setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
396 i_key = config_GetInt( p_intf, "key-vol-up" );
397 [o_mi_vol_up setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
398 [o_mi_vol_up setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
399 i_key = config_GetInt( p_intf, "key-vol-down" );
400 [o_mi_vol_down setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
401 [o_mi_vol_down setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
402 i_key = config_GetInt( p_intf, "key-vol-mute" );
403 [o_mi_mute setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
404 [o_mi_mute setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
405 i_key = config_GetInt( p_intf, "key-fullscreen" );
406 [o_mi_fullscreen setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
407 [o_mi_fullscreen setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
408 i_key = config_GetInt( p_intf, "key-snapshot" );
409 [o_mi_snapshot setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
410 [o_mi_snapshot setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
412 var_Create( p_intf, "intf-change", VLC_VAR_BOOL );
414 [self setSubmenusEnabled: FALSE];
415 [self manageVolumeSlider];
416 [o_window setDelegate: self];
418 if( [o_window frame].size.height <= 200 )
420 b_small_window = YES;
421 [o_window setFrame: NSMakeRect( [o_window frame].origin.x,
422 [o_window frame].origin.y, [o_window frame].size.width,
423 [o_window minSize].height ) display: YES animate:YES];
424 [o_playlist_view setAutoresizesSubviews: NO];
429 [o_playlist_view setFrame: NSMakeRect( 10, 10, [o_window frame].size.width - 20, [o_window frame].size.height - 105 )];
430 [o_playlist_view setNeedsDisplay:YES];
431 [o_playlist_view setAutoresizesSubviews: YES];
432 [[o_window contentView] addSubview: o_playlist_view];
434 [self updateTogglePlaylistState];
436 o_size_with_playlist = [o_window frame].size;
438 p_playlist = (playlist_t *) vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
442 /* Check if we need to start playing */
445 playlist_LockControl( p_playlist, PLAYLIST_AUTOPLAY );
447 var_Create( p_playlist, "fullscreen", VLC_VAR_BOOL | VLC_VAR_DOINHERIT);
448 val.b_bool = VLC_FALSE;
450 var_AddCallback( p_playlist, "fullscreen", FullscreenChanged, self);
452 [o_btn_fullscreen setState: ( var_Get( p_playlist, "fullscreen", &val )>=0 && val.b_bool )];
453 vlc_object_release( p_playlist );
456 var_Create( p_intf, "interaction", VLC_VAR_ADDRESS );
457 var_AddCallback( p_intf, "interaction", InteractCallback, self );
458 p_intf->b_interaction = VLC_TRUE;
460 nib_main_loaded = TRUE;
465 [o_window setTitle: _NS("VLC - Controller")];
466 [self setScrollField:_NS("VLC media player") stopAfter:-1];
468 /* button controls */
469 [o_btn_prev setToolTip: _NS("Previous")];
470 [o_btn_rewind setToolTip: _NS("Rewind")];
471 [o_btn_play setToolTip: _NS("Play")];
472 [o_btn_stop setToolTip: _NS("Stop")];
473 [o_btn_ff setToolTip: _NS("Fast Forward")];
474 [o_btn_next setToolTip: _NS("Next")];
475 [o_btn_fullscreen setToolTip: _NS("Fullscreen")];
476 [o_volumeslider setToolTip: _NS("Volume")];
477 [o_timeslider setToolTip: _NS("Position")];
478 [o_btn_playlist setToolTip: _NS("Playlist")];
481 [o_msgs_panel setTitle: _NS("Messages")];
482 [o_msgs_btn_crashlog setTitle: _NS("Open CrashLog")];
485 [o_mi_about setTitle: [_NS("About VLC media player") \
486 stringByAppendingString: @"..."]];
487 /* [o_mi_checkForUpdate setTitle: _NS("Check for Update...")];*/
488 [o_mi_prefs setTitle: _NS("Preferences...")];
489 [o_mi_add_intf setTitle: _NS("Add Interface")];
490 [o_mu_add_intf setTitle: _NS("Add Interface")];
491 [o_mi_services setTitle: _NS("Services")];
492 [o_mi_hide setTitle: _NS("Hide VLC")];
493 [o_mi_hide_others setTitle: _NS("Hide Others")];
494 [o_mi_show_all setTitle: _NS("Show All")];
495 [o_mi_quit setTitle: _NS("Quit VLC")];
497 [o_mu_file setTitle: _ANS("1:File")];
498 [o_mi_open_generic setTitle: _NS("Open File...")];
499 [o_mi_open_file setTitle: _NS("Quick Open File...")];
500 [o_mi_open_disc setTitle: _NS("Open Disc...")];
501 [o_mi_open_net setTitle: _NS("Open Network...")];
502 [o_mi_open_recent setTitle: _NS("Open Recent")];
503 [o_mi_open_recent_cm setTitle: _NS("Clear Menu")];
504 [o_mi_open_wizard setTitle: _NS("Streaming/Exporting Wizard...")];
506 [o_mu_edit setTitle: _NS("Edit")];
507 [o_mi_cut setTitle: _NS("Cut")];
508 [o_mi_copy setTitle: _NS("Copy")];
509 [o_mi_paste setTitle: _NS("Paste")];
510 [o_mi_clear setTitle: _NS("Clear")];
511 [o_mi_select_all setTitle: _NS("Select All")];
513 [o_mu_controls setTitle: _NS("Playback")];
514 [o_mi_play setTitle: _NS("Play")];
515 [o_mi_stop setTitle: _NS("Stop")];
516 [o_mi_faster setTitle: _NS("Faster")];
517 [o_mi_slower setTitle: _NS("Slower")];
518 [o_mi_previous setTitle: _NS("Previous")];
519 [o_mi_next setTitle: _NS("Next")];
520 [o_mi_random setTitle: _NS("Random")];
521 [o_mi_repeat setTitle: _NS("Repeat One")];
522 [o_mi_loop setTitle: _NS("Repeat All")];
523 [o_mi_fwd setTitle: _NS("Step Forward")];
524 [o_mi_bwd setTitle: _NS("Step Backward")];
526 [o_mi_program setTitle: _NS("Program")];
527 [o_mu_program setTitle: _NS("Program")];
528 [o_mi_title setTitle: _NS("Title")];
529 [o_mu_title setTitle: _NS("Title")];
530 [o_mi_chapter setTitle: _NS("Chapter")];
531 [o_mu_chapter setTitle: _NS("Chapter")];
533 [o_mu_audio setTitle: _NS("Audio")];
534 [o_mi_vol_up setTitle: _NS("Volume Up")];
535 [o_mi_vol_down setTitle: _NS("Volume Down")];
536 [o_mi_mute setTitle: _NS("Mute")];
537 [o_mi_audiotrack setTitle: _NS("Audio Track")];
538 [o_mu_audiotrack setTitle: _NS("Audio Track")];
539 [o_mi_channels setTitle: _NS("Audio Channels")];
540 [o_mu_channels setTitle: _NS("Audio Channels")];
541 [o_mi_device setTitle: _NS("Audio Device")];
542 [o_mu_device setTitle: _NS("Audio Device")];
543 [o_mi_visual setTitle: _NS("Visualizations")];
544 [o_mu_visual setTitle: _NS("Visualizations")];
546 [o_mu_video setTitle: _NS("Video")];
547 [o_mi_half_window setTitle: _NS("Half Size")];
548 [o_mi_normal_window setTitle: _NS("Normal Size")];
549 [o_mi_double_window setTitle: _NS("Double Size")];
550 [o_mi_fittoscreen setTitle: _NS("Fit to Screen")];
551 [o_mi_fullscreen setTitle: _NS("Fullscreen")];
552 [o_mi_floatontop setTitle: _NS("Float on Top")];
553 [o_mi_snapshot setTitle: _NS("Snapshot")];
554 [o_mi_videotrack setTitle: _NS("Video Track")];
555 [o_mu_videotrack setTitle: _NS("Video Track")];
556 [o_mi_screen setTitle: _NS("Video Device")];
557 [o_mu_screen setTitle: _NS("Video Device")];
558 [o_mi_subtitle setTitle: _NS("Subtitles Track")];
559 [o_mu_subtitle setTitle: _NS("Subtitles Track")];
560 [o_mi_deinterlace setTitle: _NS("Deinterlace")];
561 [o_mu_deinterlace setTitle: _NS("Deinterlace")];
562 [o_mi_ffmpeg_pp setTitle: _NS("Post processing")];
563 [o_mu_ffmpeg_pp setTitle: _NS("Post processing")];
565 [o_mu_window setTitle: _NS("Window")];
566 [o_mi_minimize setTitle: _NS("Minimize Window")];
567 [o_mi_close_window setTitle: _NS("Close Window")];
568 [o_mi_controller setTitle: _NS("Controller")];
569 [o_mi_equalizer setTitle: _NS("Equalizer")];
570 [o_mi_extended setTitle: _NS("Extended Controls")];
571 [o_mi_bookmarks setTitle: _NS("Bookmarks")];
572 [o_mi_playlist setTitle: _NS("Playlist")];
573 [o_mi_info setTitle: _NS("Info")];
574 [o_mi_messages setTitle: _NS("Messages")];
576 [o_mi_bring_atf setTitle: _NS("Bring All to Front")];
578 [o_mu_help setTitle: _NS("Help")];
579 [o_mi_readme setTitle: _NS("ReadMe...")];
580 [o_mi_documentation setTitle: _NS("Online Documentation")];
581 [o_mi_reportabug setTitle: _NS("Report a Bug")];
582 [o_mi_website setTitle: _NS("VideoLAN Website")];
583 [o_mi_license setTitle: _NS("License")];
584 [o_mi_donation setTitle: _NS("Make a donation")];
585 [o_mi_forum setTitle: _NS("Online Forum")];
588 [o_dmi_play setTitle: _NS("Play")];
589 [o_dmi_stop setTitle: _NS("Stop")];
590 [o_dmi_next setTitle: _NS("Next")];
591 [o_dmi_previous setTitle: _NS("Previous")];
592 [o_dmi_mute setTitle: _NS("Mute")];
595 [o_error setTitle: _NS("Error")];
596 [o_err_lbl setStringValue: _NS("An error has occurred which probably " \
597 "prevented the execution of your request:")];
598 [o_err_bug_lbl setStringValue: _NS("If you believe that it is a bug, " \
599 "please follow the instructions at:")];
600 [o_err_btn_msgs setTitle: _NS("Open Messages Window")];
601 [o_err_btn_dismiss setTitle: _NS("Dismiss")];
602 [o_err_ckbk_surpress setTitle: _NS("Suppress further errors")];
604 [o_info_window setTitle: _NS("Info")];
607 - (void)applicationWillFinishLaunching:(NSNotification *)o_notification
609 o_msg_lock = [[NSLock alloc] init];
610 o_msg_arr = [[NSMutableArray arrayWithCapacity: 200] retain];
612 o_img_play = [[NSImage imageNamed: @"play"] retain];
613 o_img_play_pressed = [[NSImage imageNamed: @"play_blue"] retain];
614 o_img_pause = [[NSImage imageNamed: @"pause"] retain];
615 o_img_pause_pressed = [[NSImage imageNamed: @"pause_blue"] retain];
617 [p_intf->p_sys->o_sendport setDelegate: self];
618 [[NSRunLoop currentRunLoop]
619 addPort: p_intf->p_sys->o_sendport
620 forMode: NSDefaultRunLoopMode];
622 [NSTimer scheduledTimerWithTimeInterval: 0.5
623 target: self selector: @selector(manageIntf:)
624 userInfo: nil repeats: FALSE];
626 [NSThread detachNewThreadSelector: @selector(manage)
627 toTarget: self withObject: nil];
629 [o_controls setupVarMenuItem: o_mi_add_intf target: (vlc_object_t *)p_intf
630 var: "intf-add" selector: @selector(toggleVar:)];
632 vlc_thread_set_priority( p_intf, VLC_THREAD_PRIORITY_LOW );
635 - (BOOL)application:(NSApplication *)o_app openFile:(NSString *)o_filename
637 NSDictionary *o_dic = [NSDictionary dictionaryWithObjectsAndKeys: o_filename, @"ITEM_URL", nil];
638 [o_playlist appendArray:
639 [NSArray arrayWithObject: o_dic] atPos: -1 enqueue: NO];
644 - (NSString *)localizedString:(char *)psz
646 NSString * o_str = nil;
650 o_str = [[[NSString alloc] initWithUTF8String: psz] autorelease];
654 msg_Err( VLCIntf, "could not translate: %s", psz );
660 - (char *)delocalizeString:(NSString *)id
662 NSData * o_data = [id dataUsingEncoding: NSUTF8StringEncoding
663 allowLossyConversion: NO];
668 o_data = [id dataUsingEncoding: NSUTF8StringEncoding
669 allowLossyConversion: YES];
670 psz_string = malloc( [o_data length] + 1 );
671 [o_data getBytes: psz_string];
672 psz_string[ [o_data length] ] = '\0';
673 msg_Err( VLCIntf, "cannot convert to wanted encoding: %s",
678 psz_string = malloc( [o_data length] + 1 );
679 [o_data getBytes: psz_string];
680 psz_string[ [o_data length] ] = '\0';
686 /* i_width is in pixels */
687 - (NSString *)wrapString: (NSString *)o_in_string toWidth: (int) i_width
689 NSMutableString *o_wrapped;
690 NSString *o_out_string;
691 NSRange glyphRange, effectiveRange, charRange;
692 NSRect lineFragmentRect;
693 unsigned glyphIndex, breaksInserted = 0;
695 NSTextStorage *o_storage = [[NSTextStorage alloc] initWithString: o_in_string
696 attributes: [NSDictionary dictionaryWithObjectsAndKeys:
697 [NSFont labelFontOfSize: 0.0], NSFontAttributeName, nil]];
698 NSLayoutManager *o_layout_manager = [[NSLayoutManager alloc] init];
699 NSTextContainer *o_container = [[NSTextContainer alloc]
700 initWithContainerSize: NSMakeSize(i_width, 2000)];
702 [o_layout_manager addTextContainer: o_container];
703 [o_container release];
704 [o_storage addLayoutManager: o_layout_manager];
705 [o_layout_manager release];
707 o_wrapped = [o_in_string mutableCopy];
708 glyphRange = [o_layout_manager glyphRangeForTextContainer: o_container];
710 for( glyphIndex = glyphRange.location ; glyphIndex < NSMaxRange(glyphRange) ;
711 glyphIndex += effectiveRange.length) {
712 lineFragmentRect = [o_layout_manager lineFragmentRectForGlyphAtIndex: glyphIndex
713 effectiveRange: &effectiveRange];
714 charRange = [o_layout_manager characterRangeForGlyphRange: effectiveRange
715 actualGlyphRange: &effectiveRange];
716 if ([o_wrapped lineRangeForRange:
717 NSMakeRange(charRange.location + breaksInserted, charRange.length)].length > charRange.length) {
718 [o_wrapped insertString: @"\n" atIndex: NSMaxRange(charRange) + breaksInserted];
722 o_out_string = [NSString stringWithString: o_wrapped];
730 /*****************************************************************************
731 * hasDefinedShortcutKey: Check to see if the key press is a defined VLC
732 * shortcut key. If it is, pass it off to VLC for handling and return YES,
733 * otherwise ignore it and return NO (where it will get handled by Cocoa).
734 *****************************************************************************/
735 - (BOOL)hasDefinedShortcutKey:(NSEvent *)o_event
739 unsigned int i_pressed_modifiers = 0;
740 struct hotkey *p_hotkeys;
744 p_hotkeys = p_intf->p_vlc->p_hotkeys;
746 i_pressed_modifiers = [o_event modifierFlags];
748 if( i_pressed_modifiers & NSShiftKeyMask )
749 val.i_int |= KEY_MODIFIER_SHIFT;
750 if( i_pressed_modifiers & NSControlKeyMask )
751 val.i_int |= KEY_MODIFIER_CTRL;
752 if( i_pressed_modifiers & NSAlternateKeyMask )
753 val.i_int |= KEY_MODIFIER_ALT;
754 if( i_pressed_modifiers & NSCommandKeyMask )
755 val.i_int |= KEY_MODIFIER_COMMAND;
757 key = [[o_event charactersIgnoringModifiers] characterAtIndex: 0];
761 case NSDeleteCharacter:
762 case NSDeleteFunctionKey:
763 case NSDeleteCharFunctionKey:
764 case NSBackspaceCharacter:
765 case NSUpArrowFunctionKey:
766 case NSDownArrowFunctionKey:
767 case NSRightArrowFunctionKey:
768 case NSLeftArrowFunctionKey:
769 case NSEnterCharacter:
770 case NSCarriageReturnCharacter:
774 val.i_int |= CocoaKeyToVLC( key );
776 for( i = 0; p_hotkeys[i].psz_action != NULL; i++ )
778 if( p_hotkeys[i].i_key == val.i_int )
780 var_Set( p_intf->p_vlc, "key-pressed", val );
833 - (id)getEmbeddedList
835 if( o_embedded_list )
837 return o_embedded_list;
842 - (id)getInteractionList
844 if( o_interaction_list )
846 return o_interaction_list;
853 playlist_t * p_playlist;
855 /* new thread requires a new pool */
856 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
858 vlc_thread_set_priority( p_intf, VLC_THREAD_PRIORITY_LOW );
860 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
863 if( p_playlist != NULL )
865 var_AddCallback( p_playlist, "intf-change", PlaylistChanged, self );
866 var_AddCallback( p_playlist, "item-change", PlaylistChanged, self );
867 var_AddCallback( p_playlist, "item-append", PlaylistChanged, self );
868 var_AddCallback( p_playlist, "item-deleted", PlaylistChanged, self );
869 var_AddCallback( p_playlist, "playlist-current", PlaylistChanged, self );
871 vlc_object_release( p_playlist );
874 while( !p_intf->b_die )
876 vlc_mutex_lock( &p_intf->change_lock );
878 #define p_input p_intf->p_sys->p_input
880 if( p_input == NULL )
882 p_input = (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
885 /* Refresh the interface */
888 msg_Dbg( p_intf, "input has changed, refreshing interface" );
889 p_intf->p_sys->b_input_update = VLC_TRUE;
892 else if( p_input->b_die || p_input->b_dead )
895 p_intf->p_sys->b_intf_update = VLC_TRUE;
896 p_intf->p_sys->i_play_status = END_S;
897 [self setScrollField: _NS("VLC media player") stopAfter:-1];
898 vlc_object_release( p_input );
903 /* Manage volume status */
904 [self manageVolumeSlider];
906 vlc_mutex_unlock( &p_intf->change_lock );
912 - (void)manageIntf:(NSTimer *)o_timer
916 if( p_intf->p_vlc->b_die == VLC_TRUE )
918 [o_timer invalidate];
922 #define p_input p_intf->p_sys->p_input
923 if( p_intf->p_sys->b_input_update )
925 /* Called when new input is opened */
926 p_intf->p_sys->b_current_title_update = VLC_TRUE;
927 p_intf->p_sys->b_intf_update = VLC_TRUE;
928 p_intf->p_sys->b_input_update = VLC_FALSE;
930 if( p_intf->p_sys->b_intf_update )
932 vlc_bool_t b_input = VLC_FALSE;
933 vlc_bool_t b_plmul = VLC_FALSE;
934 vlc_bool_t b_control = VLC_FALSE;
935 vlc_bool_t b_seekable = VLC_FALSE;
936 vlc_bool_t b_chapters = VLC_FALSE;
938 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
940 b_plmul = p_playlist->i_size > 1;
942 vlc_object_release( p_playlist );
944 if( ( b_input = ( p_input != NULL ) ) )
946 /* seekable streams */
947 var_Get( p_input, "seekable", &val);
948 b_seekable = val.b_bool;
950 /* check wether slow/fast motion is possible*/
951 b_control = p_input->input.b_can_pace_control;
953 /* chapters & titles */
954 //b_chapters = p_input->stream.i_area_nb > 1;
957 [o_btn_stop setEnabled: b_input];
958 [o_btn_ff setEnabled: b_seekable];
959 [o_btn_rewind setEnabled: b_seekable];
960 [o_btn_prev setEnabled: (b_plmul || b_chapters)];
961 [o_btn_next setEnabled: (b_plmul || b_chapters)];
963 [o_timeslider setFloatValue: 0.0];
964 [o_timeslider setEnabled: b_seekable];
965 [o_timefield setStringValue: @"0:00:00"];
967 p_intf->p_sys->b_intf_update = VLC_FALSE;
970 if( p_intf->p_sys->b_playmode_update )
972 [o_playlist playModeUpdated];
973 p_intf->p_sys->b_playmode_update = VLC_FALSE;
975 if( p_intf->p_sys->b_playlist_update )
977 [o_playlist playlistUpdated];
978 p_intf->p_sys->b_playlist_update = VLC_FALSE;
981 if( p_intf->p_sys->b_fullscreen_update )
983 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
985 var_Get( p_playlist, "fullscreen", &val );
986 [o_btn_fullscreen setState: val.b_bool];
987 vlc_object_release( p_playlist );
989 p_intf->p_sys->b_fullscreen_update = VLC_FALSE;
992 if( p_input && !p_input->b_die )
996 if( p_intf->p_sys->b_current_title_update )
999 vout_thread_t *p_vout;
1000 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1003 if( p_playlist == NULL || p_playlist->status.p_item == NULL )
1007 o_temp = [NSString stringWithUTF8String:
1008 p_playlist->status.p_item->input.psz_name];
1009 if( o_temp == NULL )
1010 o_temp = [NSString stringWithCString:
1011 p_playlist->status.p_item->input.psz_name];
1012 [self setScrollField: o_temp stopAfter:-1];
1014 p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
1016 if( p_vout != NULL )
1019 NSEnumerator * o_enum = [[NSApp orderedWindows] objectEnumerator];
1021 while( ( o_vout_wnd = [o_enum nextObject] ) )
1023 if( [[o_vout_wnd className] isEqualToString: @"VLCWindow"] )
1025 [o_vout_wnd updateTitle];
1028 vlc_object_release( (vlc_object_t *)p_vout );
1030 [o_playlist updateRowSelection];
1031 vlc_object_release( p_playlist );
1032 p_intf->p_sys->b_current_title_update = FALSE;
1035 if( p_input && [o_timeslider isEnabled] )
1037 /* Update the slider */
1044 var_Get( p_input, "position", &pos );
1045 f_updated = 10000. * pos.f_float;
1046 [o_timeslider setFloatValue: f_updated];
1048 var_Get( p_input, "time", &time );
1049 i_seconds = time.i_time / 1000000;
1051 o_time = [NSString stringWithFormat: @"%d:%02d:%02d",
1052 (int) (i_seconds / (60 * 60)),
1053 (int) (i_seconds / 60 % 60),
1054 (int) (i_seconds % 60)];
1055 [o_timefield setStringValue: o_time];
1058 if( p_intf->p_sys->b_volume_update )
1061 int i_volume_step = 0;
1062 o_text = [NSString stringWithFormat: _NS("Volume: %d%%"), i_lastShownVolume * 400 / AOUT_VOLUME_MAX];
1063 if( i_lastShownVolume != -1 )
1064 [self setScrollField:o_text stopAfter:1000000];
1065 i_volume_step = config_GetInt( p_intf->p_vlc, "volume-step" );
1066 [o_volumeslider setFloatValue: (float)i_lastShownVolume / i_volume_step];
1067 [o_volumeslider setEnabled: TRUE];
1068 p_intf->p_sys->b_mute = ( i_lastShownVolume == 0 );
1069 p_intf->p_sys->b_volume_update = FALSE;
1072 /* Manage Playing status */
1073 var_Get( p_input, "state", &val );
1074 if( p_intf->p_sys->i_play_status != val.i_int )
1076 p_intf->p_sys->i_play_status = val.i_int;
1077 [self playStatusUpdated: p_intf->p_sys->i_play_status];
1082 p_intf->p_sys->i_play_status = END_S;
1083 p_intf->p_sys->b_intf_update = VLC_TRUE;
1084 [self playStatusUpdated: p_intf->p_sys->i_play_status];
1085 [self setSubmenusEnabled: FALSE];
1090 [self updateMessageArray];
1092 if( (i_end_scroll != -1) && (mdate() > i_end_scroll) )
1093 [self resetScrollField];
1096 [NSTimer scheduledTimerWithTimeInterval: 0.3
1097 target: self selector: @selector(manageIntf:)
1098 userInfo: nil repeats: FALSE];
1103 #define p_input p_intf->p_sys->p_input
1104 if( p_input != NULL )
1106 [o_controls setupVarMenuItem: o_mi_program target: (vlc_object_t *)p_input
1107 var: "program" selector: @selector(toggleVar:)];
1109 [o_controls setupVarMenuItem: o_mi_title target: (vlc_object_t *)p_input
1110 var: "title" selector: @selector(toggleVar:)];
1112 [o_controls setupVarMenuItem: o_mi_chapter target: (vlc_object_t *)p_input
1113 var: "chapter" selector: @selector(toggleVar:)];
1115 [o_controls setupVarMenuItem: o_mi_audiotrack target: (vlc_object_t *)p_input
1116 var: "audio-es" selector: @selector(toggleVar:)];
1118 [o_controls setupVarMenuItem: o_mi_videotrack target: (vlc_object_t *)p_input
1119 var: "video-es" selector: @selector(toggleVar:)];
1121 [o_controls setupVarMenuItem: o_mi_subtitle target: (vlc_object_t *)p_input
1122 var: "spu-es" selector: @selector(toggleVar:)];
1124 aout_instance_t * p_aout = vlc_object_find( p_intf, VLC_OBJECT_AOUT,
1126 if ( p_aout != NULL )
1128 [o_controls setupVarMenuItem: o_mi_channels target: (vlc_object_t *)p_aout
1129 var: "audio-channels" selector: @selector(toggleVar:)];
1131 [o_controls setupVarMenuItem: o_mi_device target: (vlc_object_t *)p_aout
1132 var: "audio-device" selector: @selector(toggleVar:)];
1134 [o_controls setupVarMenuItem: o_mi_visual target: (vlc_object_t *)p_aout
1135 var: "visual" selector: @selector(toggleVar:)];
1136 vlc_object_release( (vlc_object_t *)p_aout );
1139 vout_thread_t * p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
1142 if ( p_vout != NULL )
1144 vlc_object_t * p_dec_obj;
1146 [o_controls setupVarMenuItem: o_mi_screen target: (vlc_object_t *)p_vout
1147 var: "video-device" selector: @selector(toggleVar:)];
1149 [o_controls setupVarMenuItem: o_mi_deinterlace target: (vlc_object_t *)p_vout
1150 var: "deinterlace" selector: @selector(toggleVar:)];
1152 p_dec_obj = (vlc_object_t *)vlc_object_find(
1153 (vlc_object_t *)p_vout,
1156 if ( p_dec_obj != NULL )
1158 [o_controls setupVarMenuItem: o_mi_ffmpeg_pp target:
1159 (vlc_object_t *)p_dec_obj var:"ffmpeg-pp-q" selector:
1160 @selector(toggleVar:)];
1162 vlc_object_release(p_dec_obj);
1164 vlc_object_release( (vlc_object_t *)p_vout );
1170 - (void)setScrollField:(NSString *)o_string stopAfter:(int)timeout
1173 i_end_scroll = mdate() + timeout;
1176 [o_scrollfield setStringValue: o_string];
1179 - (void)resetScrollField
1182 #define p_input p_intf->p_sys->p_input
1183 if( p_input && !p_input->b_die )
1186 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1188 if( p_playlist == NULL )
1192 o_temp = [NSString stringWithUTF8String:
1193 p_playlist->status.p_item->input.psz_name];
1194 if( o_temp == NULL )
1195 o_temp = [NSString stringWithCString:
1196 p_playlist->status.p_item->input.psz_name];
1197 [self setScrollField: o_temp stopAfter:-1];
1198 vlc_object_release( p_playlist );
1202 [self setScrollField: _NS("VLC media player") stopAfter:-1];
1205 - (void)updateMessageArray
1207 int i_start, i_stop;
1210 vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
1211 i_stop = *p_intf->p_sys->p_sub->pi_stop;
1212 vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
1214 if( p_intf->p_sys->p_sub->i_start != i_stop )
1216 NSColor *o_white = [NSColor whiteColor];
1217 NSColor *o_red = [NSColor redColor];
1218 NSColor *o_yellow = [NSColor yellowColor];
1219 NSColor *o_gray = [NSColor grayColor];
1221 NSColor * pp_color[4] = { o_white, o_red, o_yellow, o_gray };
1222 static const char * ppsz_type[4] = { ": ", " error: ",
1223 " warning: ", " debug: " };
1225 for( i_start = p_intf->p_sys->p_sub->i_start;
1227 i_start = (i_start+1) % VLC_MSG_QSIZE )
1230 NSDictionary *o_attr;
1231 NSAttributedString *o_msg_color;
1233 int i_type = p_intf->p_sys->p_sub->p_msg[i_start].i_type;
1237 if( [o_msg_arr count] + 2 > 400 )
1239 unsigned rid[] = { 0, 1 };
1240 [o_msg_arr removeObjectsFromIndices: (unsigned *)&rid
1241 numIndices: sizeof(rid)/sizeof(rid[0])];
1244 o_attr = [NSDictionary dictionaryWithObject: o_gray
1245 forKey: NSForegroundColorAttributeName];
1246 o_msg = [NSString stringWithFormat: @"%s%s",
1247 p_intf->p_sys->p_sub->p_msg[i_start].psz_module,
1249 o_msg_color = [[NSAttributedString alloc]
1250 initWithString: o_msg attributes: o_attr];
1251 [o_msg_arr addObject: [o_msg_color autorelease]];
1253 o_attr = [NSDictionary dictionaryWithObject: pp_color[i_type]
1254 forKey: NSForegroundColorAttributeName];
1255 o_msg = [NSString stringWithFormat: @"%s\n",
1256 p_intf->p_sys->p_sub->p_msg[i_start].psz_msg];
1257 o_msg_color = [[NSAttributedString alloc]
1258 initWithString: o_msg attributes: o_attr];
1259 [o_msg_arr addObject: [o_msg_color autorelease]];
1261 [o_msg_lock unlock];
1263 var_Get( p_intf->p_vlc, "verbose", &quiet );
1265 if( i_type == 1 && quiet.i_int > -1 )
1267 NSString *o_my_msg = [NSString stringWithFormat: @"%s: %s\n",
1268 p_intf->p_sys->p_sub->p_msg[i_start].psz_module,
1269 p_intf->p_sys->p_sub->p_msg[i_start].psz_msg];
1271 NSRange s_r = NSMakeRange( [[o_err_msg string] length], 0 );
1272 [o_err_msg setEditable: YES];
1273 [o_err_msg setSelectedRange: s_r];
1274 [o_err_msg insertText: o_my_msg];
1276 [o_error makeKeyAndOrderFront: self];
1277 [o_err_msg setEditable: NO];
1281 vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
1282 p_intf->p_sys->p_sub->i_start = i_start;
1283 vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
1287 - (void)playStatusUpdated:(int)i_status
1289 if( i_status == PLAYING_S )
1291 [o_btn_play setImage: o_img_pause];
1292 [o_btn_play setAlternateImage: o_img_pause_pressed];
1293 [o_btn_play setToolTip: _NS("Pause")];
1294 [o_mi_play setTitle: _NS("Pause")];
1295 [o_dmi_play setTitle: _NS("Pause")];
1299 [o_btn_play setImage: o_img_play];
1300 [o_btn_play setAlternateImage: o_img_play_pressed];
1301 [o_btn_play setToolTip: _NS("Play")];
1302 [o_mi_play setTitle: _NS("Play")];
1303 [o_dmi_play setTitle: _NS("Play")];
1307 - (void)setSubmenusEnabled:(BOOL)b_enabled
1309 [o_mi_program setEnabled: b_enabled];
1310 [o_mi_title setEnabled: b_enabled];
1311 [o_mi_chapter setEnabled: b_enabled];
1312 [o_mi_audiotrack setEnabled: b_enabled];
1313 [o_mi_visual setEnabled: b_enabled];
1314 [o_mi_videotrack setEnabled: b_enabled];
1315 [o_mi_subtitle setEnabled: b_enabled];
1316 [o_mi_channels setEnabled: b_enabled];
1317 [o_mi_deinterlace setEnabled: b_enabled];
1318 [o_mi_ffmpeg_pp setEnabled: b_enabled];
1319 [o_mi_device setEnabled: b_enabled];
1320 [o_mi_screen setEnabled: b_enabled];
1323 - (void)manageVolumeSlider
1325 audio_volume_t i_volume;
1326 aout_VolumeGet( p_intf, &i_volume );
1328 if( i_volume != i_lastShownVolume )
1330 i_lastShownVolume = i_volume;
1331 p_intf->p_sys->b_volume_update = TRUE;
1335 - (IBAction)timesliderUpdate:(id)sender
1337 #define p_input p_intf->p_sys->p_input
1340 switch( [[NSApp currentEvent] type] )
1343 case NSLeftMouseDown:
1344 case NSLeftMouseDragged:
1345 f_updated = [sender floatValue];
1352 if( p_input != NULL )
1359 pos.f_float = f_updated / 10000.;
1360 var_Set( p_input, "position", pos );
1361 [o_timeslider setFloatValue: f_updated];
1363 var_Get( p_input, "time", &time );
1364 i_seconds = time.i_time / 1000000;
1366 o_time = [NSString stringWithFormat: @"%d:%02d:%02d",
1367 (int) (i_seconds / (60 * 60)),
1368 (int) (i_seconds / 60 % 60),
1369 (int) (i_seconds % 60)];
1370 [o_timefield setStringValue: o_time];
1377 playlist_t * p_playlist;
1378 vout_thread_t * p_vout;
1380 #define p_input p_intf->p_sys->p_input
1383 vlc_object_release( p_input );
1389 if( ( p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1392 playlist_Stop( p_playlist );
1393 vlc_object_release( p_playlist );
1396 /* FIXME - Wait here until all vouts are terminated because
1397 libvlc's VLC_CleanUp destroys interfaces before vouts, which isn't
1398 good on OS X. We definitly need a cleaner way to handle this,
1399 but this may hopefully be good enough for now.
1400 -- titer 2003/11/22 */
1401 while( ( p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
1404 vlc_object_release( p_vout );
1409 /* save the prefs if they were changed in the extended panel */
1410 if (o_extended && [o_extended getConfigChanged])
1412 [o_extended savePrefs];
1415 p_intf->b_interaction = VLC_FALSE;
1416 var_DelCallback( p_intf, "interaction", InteractCallback, self );
1418 /* release some other objects here, because it isn't sure whether dealloc
1419 * will be called later on -- FK (10/6/05) */
1420 if( nib_about_loaded && o_about )
1423 if( nib_open_loaded && o_open )
1426 if( nib_extended_loaded && o_extended )
1428 [o_extended collapsAll];
1429 [o_extended release];
1432 if( nib_bookmarks_loaded && o_bookmarks )
1433 [o_bookmarks release];
1435 if( nib_wizard_loaded && o_wizard )
1438 if( o_embedded_list != nil )
1439 [o_embedded_list release];
1441 if( o_interaction_list != nil )
1442 [o_interaction_list release];
1444 if( o_img_pause_pressed != nil )
1446 [o_img_pause_pressed release];
1447 o_img_pause_pressed = nil;
1450 if( o_img_pause_pressed != nil )
1452 [o_img_pause_pressed release];
1453 o_img_pause_pressed = nil;
1456 if( o_img_pause != nil )
1458 [o_img_pause release];
1462 if( o_img_play != nil )
1464 [o_img_play release];
1468 if( o_msg_arr != nil )
1470 [o_msg_arr removeAllObjects];
1471 [o_msg_arr release];
1475 if( o_msg_lock != nil )
1477 [o_msg_lock release];
1481 /* write cached user defaults to disk */
1482 [[NSUserDefaults standardUserDefaults] synchronize];
1484 p_intf->b_die = VLC_TRUE;
1487 - (IBAction)clearRecentItems:(id)sender
1489 [[NSDocumentController sharedDocumentController]
1490 clearRecentDocuments: nil];
1493 - (void)openRecentItem:(id)sender
1495 [self application: nil openFile: [sender title]];
1498 - (IBAction)intfOpenFile:(id)sender
1500 if (!nib_open_loaded)
1502 nib_open_loaded = [NSBundle loadNibNamed:@"Open" owner:self];
1503 [o_open awakeFromNib];
1510 - (IBAction)intfOpenFileGeneric:(id)sender
1512 if (!nib_open_loaded)
1514 nib_open_loaded = [NSBundle loadNibNamed:@"Open" owner:self];
1515 [o_open awakeFromNib];
1516 [o_open openFileGeneric];
1518 [o_open openFileGeneric];
1522 - (IBAction)intfOpenDisc:(id)sender
1524 if (!nib_open_loaded)
1526 nib_open_loaded = [NSBundle loadNibNamed:@"Open" owner:self];
1527 [o_open awakeFromNib];
1534 - (IBAction)intfOpenNet:(id)sender
1536 if (!nib_open_loaded)
1538 nib_open_loaded = [NSBundle loadNibNamed:@"Open" owner:self];
1539 [o_open awakeFromNib];
1546 - (IBAction)showWizard:(id)sender
1548 if (!nib_wizard_loaded)
1550 nib_wizard_loaded = [NSBundle loadNibNamed:@"Wizard" owner:self];
1551 [o_wizard initStrings];
1552 [o_wizard resetWizard];
1553 [o_wizard showWizard];
1555 [o_wizard resetWizard];
1556 [o_wizard showWizard];
1560 - (IBAction)showExtended:(id)sender
1562 if ( o_extended == nil )
1564 o_extended = [[VLCExtended alloc] init];
1566 if (!nib_extended_loaded)
1568 nib_extended_loaded = [NSBundle loadNibNamed:@"Extended" owner:self];
1569 [o_extended initStrings];
1570 [o_extended showPanel];
1572 [o_extended showPanel];
1576 - (IBAction)showSFilters:(id)sender
1578 if ( o_sfilters == nil )
1580 o_sfilters = [[VLCsFilters alloc] init];
1582 if (!nib_sfilters_loaded)
1584 nib_sfilters_loaded = [NSBundle loadNibNamed:@"SFilters" owner:self];
1585 [o_sfilters initStrings];
1586 [o_sfilters showAsPanel];
1588 [o_sfilters showAsPanel];
1592 - (IBAction)showBookmarks:(id)sender
1594 /* we need the wizard-nib for the bookmarks's extract functionality */
1595 if (!nib_wizard_loaded)
1597 nib_wizard_loaded = [NSBundle loadNibNamed:@"Wizard" owner:self];
1598 [o_wizard initStrings];
1601 if (!nib_bookmarks_loaded)
1603 nib_bookmarks_loaded = [NSBundle loadNibNamed:@"Bookmarks" owner:self];
1604 [o_bookmarks showBookmarks];
1606 [o_bookmarks showBookmarks];
1610 - (IBAction)viewAbout:(id)sender
1612 if (!nib_about_loaded)
1614 nib_about_loaded = [NSBundle loadNibNamed:@"About" owner:self];
1615 [o_about showPanel];
1617 [o_about showPanel];
1621 - (IBAction)viewPreferences:(id)sender
1624 if( o_prefs == nil )
1625 o_prefs = [[VLCPrefs alloc] init];
1626 [o_prefs showPrefs];
1629 /*- (IBAction)checkForUpdate:(id)sender
1631 if (!nib_update_loaded)
1633 nib_update_loaded = [NSBundle loadNibNamed:@"Update" owner:self];
1634 [o_update showUpdateWindow];
1636 [o_update showUpdateWindow];
1640 - (IBAction)closeError:(id)sender
1644 if( [o_err_ckbk_surpress state] == NSOnState )
1647 var_Set( p_intf->p_vlc, "verbose", val );
1649 [o_err_msg setString: @""];
1650 [o_error performClose: self];
1653 - (IBAction)openReadMe:(id)sender
1655 NSString * o_path = [[NSBundle mainBundle]
1656 pathForResource: @"README.MacOSX" ofType: @"rtf"];
1658 [[NSWorkspace sharedWorkspace] openFile: o_path
1659 withApplication: @"TextEdit"];
1662 - (IBAction)openDocumentation:(id)sender
1664 NSURL * o_url = [NSURL URLWithString:
1665 @"http://www.videolan.org/doc/"];
1667 [[NSWorkspace sharedWorkspace] openURL: o_url];
1670 - (IBAction)reportABug:(id)sender
1672 NSURL * o_url = [NSURL URLWithString:
1673 @"http://www.videolan.org/support/bug-reporting.html"];
1675 [[NSWorkspace sharedWorkspace] openURL: o_url];
1678 - (IBAction)openWebsite:(id)sender
1680 NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org/"];
1682 [[NSWorkspace sharedWorkspace] openURL: o_url];
1685 - (IBAction)openLicense:(id)sender
1687 NSString * o_path = [[NSBundle mainBundle]
1688 pathForResource: @"COPYING" ofType: nil];
1690 [[NSWorkspace sharedWorkspace] openFile: o_path
1691 withApplication: @"TextEdit"];
1694 - (IBAction)openForum:(id)sender
1696 NSURL * o_url = [NSURL URLWithString: @"http://forum.videolan.org/"];
1698 [[NSWorkspace sharedWorkspace] openURL: o_url];
1701 - (IBAction)openDonate:(id)sender
1703 NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org/contribute.html#paypal"];
1705 [[NSWorkspace sharedWorkspace] openURL: o_url];
1708 - (IBAction)openCrashLog:(id)sender
1710 NSString * o_path = [@"~/Library/Logs/CrashReporter/VLC.crash.log"
1711 stringByExpandingTildeInPath];
1714 if ( [[NSFileManager defaultManager] fileExistsAtPath: o_path ] )
1716 [[NSWorkspace sharedWorkspace] openFile: o_path
1717 withApplication: @"Console"];
1721 NSBeginInformationalAlertSheet(_NS("No CrashLog found"), @"Continue", nil, nil, o_msgs_panel, self, NULL, NULL, nil, _NS("You haven't experienced any heavy crashes yet.") );
1726 - (void)windowDidBecomeKey:(NSNotification *)o_notification
1728 if( [o_notification object] == o_msgs_panel )
1731 NSEnumerator * o_enum;
1733 [o_messages setString: @""];
1737 o_enum = [o_msg_arr objectEnumerator];
1739 while( ( o_msg = [o_enum nextObject] ) != nil )
1741 [o_messages insertText: o_msg];
1744 [o_msg_lock unlock];
1748 - (IBAction)togglePlaylist:(id)sender
1750 NSRect o_rect = [o_window frame];
1751 /*First, check if the playlist is visible*/
1752 if( o_rect.size.height <= 200 )
1754 b_small_window = YES; /* we know we are small, make sure this is actually set (see case below) */
1756 if ( o_size_with_playlist.height > 200 )
1758 o_rect.size.height = o_size_with_playlist.height;
1760 o_rect.size.height = 500;
1763 if ( o_size_with_playlist.width > [o_window minSize].width )
1765 o_rect.size.width = o_size_with_playlist.width;
1767 o_rect.size.width = 500;
1770 o_rect.size.height = (o_size_with_playlist.height > 200) ?
1771 o_size_with_playlist.height : 500;
1772 o_rect.origin.x = [o_window frame].origin.x;
1773 o_rect.origin.y = [o_window frame].origin.y - o_rect.size.height +
1774 [o_window minSize].height;
1775 [o_btn_playlist setState: YES];
1780 o_rect.size.height = [o_window minSize].height;
1781 o_rect.size.width = [o_window minSize].width;
1782 o_rect.origin.x = [o_window frame].origin.x;
1783 /* Calculate the position of the lower right corner after resize */
1784 o_rect.origin.y = [o_window frame].origin.y +
1785 [o_window frame].size.height - [o_window minSize].height;
1787 [o_playlist_view setAutoresizesSubviews: NO];
1788 [o_playlist_view removeFromSuperview];
1789 [o_btn_playlist setState: NO];
1790 b_small_window = NO; /* we aren't small here just yet. we are doing an animated resize after this */
1793 [o_window setFrame: o_rect display:YES animate: YES];
1796 - (void)updateTogglePlaylistState
1798 if( [o_window frame].size.height <= 200 )
1800 [o_btn_playlist setState: NO];
1804 [o_btn_playlist setState: YES];
1808 - (NSSize)windowWillResize:(NSWindow *)sender toSize:(NSSize)proposedFrameSize
1810 /* Not triggered on a window resize or maxification of the window. only by window mouse dragging resize */
1812 /*Stores the size the controller one resize, to be able to restore it when
1813 toggling the playlist*/
1814 o_size_with_playlist = proposedFrameSize;
1816 if( proposedFrameSize.height <= 200 )
1818 if( b_small_window == NO )
1820 /* if large and going to small then hide */
1821 b_small_window = YES;
1822 [o_playlist_view setAutoresizesSubviews: NO];
1823 [o_playlist_view removeFromSuperview];
1825 return NSMakeSize( proposedFrameSize.width, [o_window minSize].height);
1827 return proposedFrameSize;
1830 - (void)windowDidResize:(NSNotification *)notif
1832 if( [o_window frame].size.height > 200 && b_small_window )
1834 /* If large and coming from small then show */
1835 [o_playlist_view setAutoresizesSubviews: YES];
1836 [o_playlist_view setFrame: NSMakeRect( 10, 10, [o_window frame].size.width - 20, [o_window frame].size.height - [o_window minSize].height - 10 )];
1837 [o_playlist_view setNeedsDisplay:YES];
1838 [[o_window contentView] addSubview: o_playlist_view];
1839 b_small_window = NO;
1841 [self updateTogglePlaylistState];
1846 @implementation VLCMain (NSMenuValidation)
1848 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
1850 NSString *o_title = [o_mi title];
1851 BOOL bEnabled = TRUE;
1853 /* Recent Items Menu */
1854 if( [o_title isEqualToString: _NS("Clear Menu")] )
1856 NSMenu * o_menu = [o_mi_open_recent submenu];
1857 int i_nb_items = [o_menu numberOfItems];
1858 NSArray * o_docs = [[NSDocumentController sharedDocumentController]
1859 recentDocumentURLs];
1860 UInt32 i_nb_docs = [o_docs count];
1862 if( i_nb_items > 1 )
1864 while( --i_nb_items )
1866 [o_menu removeItemAtIndex: 0];
1875 [o_menu insertItem: [NSMenuItem separatorItem] atIndex: 0];
1881 o_url = [o_docs objectAtIndex: i_nb_docs];
1883 if( [o_url isFileURL] )
1885 o_doc = [o_url path];
1889 o_doc = [o_url absoluteString];
1892 [o_menu insertItemWithTitle: o_doc
1893 action: @selector(openRecentItem:)
1894 keyEquivalent: @"" atIndex: 0];
1896 if( i_nb_docs == 0 )
1912 @implementation VLCMain (Internal)
1914 - (void)handlePortMessage:(NSPortMessage *)o_msg
1919 NSInvocation * o_inv;
1920 NSConditionLock * o_lock;
1922 o_data = [[o_msg components] lastObject];
1923 o_inv = *((NSInvocation **)[o_data bytes]);
1924 [o_inv getArgument: &o_value atIndex: 2];
1925 val = (id **)[o_value pointerValue];
1926 [o_inv setArgument: val[1] atIndex: 2];
1931 [o_lock unlockWithCondition: 1];