1 /*****************************************************************************
2 * intf.m: MacOS X interface plugin
3 *****************************************************************************
4 * Copyright (C) 2002-2003 VideoLAN
5 * $Id: intf.m,v 1.62 2003/02/27 08:19:02 massiot Exp $
7 * Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
8 * Christophe Massiot <massiot@via.ecp.fr>
9 * Derk-Jan Hartman <thedj@users.sourceforge.net>
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 */
39 /*****************************************************************************
41 *****************************************************************************/
42 static void Run ( intf_thread_t *p_intf );
44 /*****************************************************************************
45 * OpenIntf: initialize interface
46 *****************************************************************************/
47 int E_(OpenIntf) ( vlc_object_t *p_this )
49 intf_thread_t *p_intf = (intf_thread_t*) p_this;
51 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
52 if( p_intf->p_sys == NULL )
57 memset( p_intf->p_sys, 0, sizeof( *p_intf->p_sys ) );
59 p_intf->p_sys->o_pool = [[NSAutoreleasePool alloc] init];
60 p_intf->p_sys->o_sendport = [[NSPort port] retain];
62 p_intf->p_sys->p_sub = msg_Subscribe( p_intf );
66 [[VLCApplication sharedApplication] autorelease];
67 [NSApp initIntlSupport];
68 [NSApp setIntf: p_intf];
70 [NSBundle loadNibNamed: @"MainMenu" owner: NSApp];
75 /*****************************************************************************
76 * CloseIntf: destroy interface
77 *****************************************************************************/
78 void E_(CloseIntf) ( vlc_object_t *p_this )
80 intf_thread_t *p_intf = (intf_thread_t*) p_this;
82 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
84 config_SaveConfigFile( p_intf, MODULE_STRING );
86 [p_intf->p_sys->o_sendport release];
87 [p_intf->p_sys->o_pool release];
89 free( p_intf->p_sys );
92 /*****************************************************************************
94 *****************************************************************************/
95 static void Run( intf_thread_t *p_intf )
97 /* Do it again - for some unknown reason, vlc_thread_create() often
98 * fails to go to real-time priority with the first launched thread
100 vlc_thread_set_priority( p_intf, VLC_THREAD_PRIORITY_LOW );
105 /*****************************************************************************
106 * VLCApplication implementation
107 *****************************************************************************/
108 @implementation VLCApplication
112 /* default encoding: ISO-8859-1 */
113 i_encoding = NSISOLatin1StringEncoding;
115 return( [super init] );
118 - (void)initIntlSupport
120 char *psz_lang = getenv( "LANG" );
122 if( psz_lang == NULL )
127 if( strncmp( psz_lang, "pl", 2 ) == 0 )
129 i_encoding = NSISOLatin2StringEncoding;
131 else if( strncmp( psz_lang, "ja", 2 ) == 0 )
133 i_encoding = NSJapaneseEUCStringEncoding;
135 else if( strncmp( psz_lang, "ru", 2 ) == 0 )
137 #define CFSENC2NSSENC(e) CFStringConvertEncodingToNSStringEncoding(e)
138 i_encoding = CFSENC2NSSENC( kCFStringEncodingKOI8_R );
143 - (NSString *)localizedString:(char *)psz
145 NSString * o_str = nil;
149 UInt32 uiLength = (UInt32)strlen( psz );
150 NSData * o_data = [NSData dataWithBytes: psz length: uiLength];
151 o_str = [[[NSString alloc] initWithData: o_data
152 encoding: i_encoding] autorelease];
158 - (char *)delocalizeString:(NSString *)id
160 NSData * o_data = [id dataUsingEncoding: i_encoding
161 allowLossyConversion: NO];
166 o_data = [id dataUsingEncoding: i_encoding
167 allowLossyConversion: YES];
168 psz_string = malloc( [o_data length] + 1 );
169 [o_data getBytes: psz_string];
170 psz_string[ [o_data length] ] = '\0';
171 msg_Err( p_intf, "cannot convert to wanted encoding: %s",
176 psz_string = malloc( [o_data length] + 1 );
177 [o_data getBytes: psz_string];
178 psz_string[ [o_data length] ] = '\0';
184 - (NSStringEncoding)getEncoding
189 - (void)setIntf:(intf_thread_t *)_p_intf
194 - (intf_thread_t *)getIntf
199 - (void)terminate:(id)sender
201 p_intf->p_vlc->b_die = VLC_TRUE;
206 int ExecuteOnMainThread( id target, SEL sel, void * p_arg )
210 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
212 if( [target respondsToSelector: @selector(performSelectorOnMainThread:
213 withObject:waitUntilDone:)] )
215 [target performSelectorOnMainThread: sel
216 withObject: [NSValue valueWithPointer: p_arg]
219 else if( NSApp != nil && [NSApp respondsToSelector: @selector(getIntf)] )
224 NSPort * o_recv_port;
225 NSInvocation * o_inv;
226 NSPortMessage * o_msg;
227 intf_thread_t * p_intf;
228 NSConditionLock * o_lock;
229 NSMethodSignature * o_sig;
231 id * val[] = { &o_lock, &o_v2 };
233 p_intf = (intf_thread_t *)[NSApp getIntf];
235 o_recv_port = [[NSPort port] retain];
236 o_v1 = [NSValue valueWithPointer: val];
237 o_v2 = [NSValue valueWithPointer: p_arg];
239 o_sig = [target methodSignatureForSelector: sel];
240 o_inv = [NSInvocation invocationWithMethodSignature: o_sig];
241 [o_inv setArgument: &o_v1 atIndex: 2];
242 [o_inv setTarget: target];
243 [o_inv setSelector: sel];
245 o_array = [NSArray arrayWithObject:
246 [NSData dataWithBytes: &o_inv length: sizeof(o_inv)]];
247 o_msg = [[NSPortMessage alloc]
248 initWithSendPort: p_intf->p_sys->o_sendport
249 receivePort: o_recv_port components: o_array];
251 o_lock = [[NSConditionLock alloc] initWithCondition: 0];
252 [o_msg sendBeforeDate: [NSDate distantPast]];
253 [o_lock lockWhenCondition: 1];
258 [o_recv_port release];
270 /*****************************************************************************
271 * VLCMain implementation
272 *****************************************************************************/
273 @implementation VLCMain
277 [o_window setTitle: _NS("VLC - Controller")];
278 [o_window setExcludedFromWindowsMenu: TRUE];
280 /* button controls */
281 [o_btn_playlist setToolTip: _NS("Playlist")];
282 [o_btn_prev setToolTip: _NS("Previous")];
283 [o_btn_slower setToolTip: _NS("Slower")];
284 [o_btn_play setToolTip: _NS("Play")];
285 [o_btn_stop setToolTip: _NS("Stop")];
286 [o_btn_faster setToolTip: _NS("Faster")];
287 [o_btn_next setToolTip: _NS("Next")];
288 [o_btn_prefs setToolTip: _NS("Preferences")];
289 [o_volumeslider setToolTip: _NS("Volume")];
290 [o_timeslider setToolTip: _NS("Position")];
293 [o_msgs_panel setDelegate: self];
294 [o_msgs_panel setTitle: _NS("Messages")];
295 [o_msgs_panel setExcludedFromWindowsMenu: TRUE];
296 [o_msgs_btn_ok setTitle: _NS("Close")];
297 [o_msgs_btn_crashlog setTitle: _NS("Open CrashLog")];
300 [o_mi_about setTitle: _NS("About VLC media player")];
301 [o_mi_prefs setTitle: _NS("Preferences...")];
302 [o_mi_hide setTitle: _NS("Hide VLC")];
303 [o_mi_hide_others setTitle: _NS("Hide Others")];
304 [o_mi_show_all setTitle: _NS("Show All")];
305 [o_mi_quit setTitle: _NS("Quit VLC")];
307 [o_mu_file setTitle: _NS("File")];
308 [o_mi_open_generic setTitle: _NS("Open...")];
309 [o_mi_open_file setTitle: _NS("Open File...")];
310 [o_mi_open_disc setTitle: _NS("Open Disc...")];
311 [o_mi_open_net setTitle: _NS("Open Network...")];
312 [o_mi_open_recent setTitle: _NS("Open Recent")];
313 [o_mi_open_recent_cm setTitle: _NS("Clear Menu")];
315 [o_mu_edit setTitle: _NS("Edit")];
316 [o_mi_cut setTitle: _NS("Cut")];
317 [o_mi_copy setTitle: _NS("Copy")];
318 [o_mi_paste setTitle: _NS("Paste")];
319 [o_mi_clear setTitle: _NS("Clear")];
320 [o_mi_select_all setTitle: _NS("Select All")];
322 [o_mu_controls setTitle: _NS("Controls")];
323 [o_mi_play setTitle: _NS("Play")];
324 [o_mi_stop setTitle: _NS("Stop")];
325 [o_mi_faster setTitle: _NS("Faster")];
326 [o_mi_slower setTitle: _NS("Slower")];
327 [o_mi_previous setTitle: _NS("Previous")];
328 [o_mi_next setTitle: _NS("Next")];
329 [o_mi_loop setTitle: _NS("Loop")];
330 [o_mi_fwd setTitle: _NS("Step Forward")];
331 [o_mi_bwd setTitle: _NS("Step Backward")];
332 [o_mi_program setTitle: _NS("Program")];
333 [o_mi_title setTitle: _NS("Title")];
334 [o_mi_chapter setTitle: _NS("Chapter")];
335 [o_mi_language setTitle: _NS("Language")];
336 [o_mi_subtitle setTitle: _NS("Subtitles")];
338 [o_mu_audio setTitle: _NS("Audio")];
339 [o_mi_vol_up setTitle: _NS("Volume Up")];
340 [o_mi_vol_down setTitle: _NS("Volume Down")];
341 [o_mi_mute setTitle: _NS("Mute")];
342 [o_mi_channels setTitle: _NS("Channels")];
343 [o_mi_device setTitle: _NS("Device")];
345 [o_mu_video setTitle: _NS("Video")];
346 [o_mi_half_window setTitle: _NS("Half Size")];
347 [o_mi_normal_window setTitle: _NS("Normal Size")];
348 [o_mi_double_window setTitle: _NS("Double Size")];
349 [o_mi_fullscreen setTitle: _NS("Fullscreen")];
350 [o_mi_screen setTitle: _NS("Screen")];
351 [o_mi_deinterlace setTitle: _NS("Deinterlace")];
353 [o_mu_window setTitle: _NS("Window")];
354 [o_mi_minimize setTitle: _NS("Minimize Window")];
355 [o_mi_close_window setTitle: _NS("Close Window")];
356 [o_mi_controller setTitle: _NS("Controller")];
357 [o_mi_playlist setTitle: _NS("Playlist")];
358 [o_mi_info setTitle: _NS("Info")];
359 [o_mi_messages setTitle: _NS("Messages")];
361 [o_mi_bring_atf setTitle: _NS("Bring All to Front")];
363 [o_mu_help setTitle: _NS("Help")];
364 [o_mi_readme setTitle: _NS("ReadMe...")];
365 [o_mi_reportabug setTitle: _NS("Report a Bug")];
366 [o_mi_website setTitle: _NS("VideoLAN Website")];
367 [o_mi_license setTitle: _NS("License")];
370 [o_dmi_play setTitle: _NS("Play")];
371 [o_dmi_stop setTitle: _NS("Stop")];
372 [o_dmi_next setTitle: _NS("Next")];
373 [o_dmi_previous setTitle: _NS("Previous")];
376 [o_error setTitle: _NS("Error")];
377 [o_err_lbl setStringValue: _NS("An error has occurred which probably prevented the execution of your request:")];
378 [o_err_bug_lbl setStringValue: _NS("If you believe that it is a bug, please follow the instructions at:")];
379 [o_err_btn_msgs setTitle: _NS("Open Messages Window")];
380 [o_err_btn_dismiss setTitle: _NS("Dismiss")];
382 [o_info_window setTitle: _NS("Info")];
384 [self setSubmenusEnabled: FALSE];
385 [self manageVolumeSlider];
388 - (void)applicationWillFinishLaunching:(NSNotification *)o_notification
390 intf_thread_t * p_intf = [NSApp getIntf];
392 o_msg_lock = [[NSLock alloc] init];
393 o_msg_arr = [[NSMutableArray arrayWithCapacity: 200] retain];
395 o_img_play = [[NSImage imageNamed: @"play"] retain];
396 o_img_pause = [[NSImage imageNamed: @"pause"] retain];
398 [p_intf->p_sys->o_sendport setDelegate: self];
399 [[NSRunLoop currentRunLoop]
400 addPort: p_intf->p_sys->o_sendport
401 forMode: NSDefaultRunLoopMode];
403 [NSTimer scheduledTimerWithTimeInterval: 0.5
404 target: self selector: @selector(manageIntf:)
405 userInfo: nil repeats: TRUE];
407 [NSThread detachNewThreadSelector: @selector(manage)
408 toTarget: self withObject: nil];
410 vlc_thread_set_priority( p_intf, VLC_THREAD_PRIORITY_LOW );
413 - (BOOL)application:(NSApplication *)o_app openFile:(NSString *)o_filename
415 [o_playlist appendArray:
416 [NSArray arrayWithObject: o_filename] atPos: -1 enqueue: NO];
423 NSDate * o_sleep_date;
424 intf_thread_t * p_intf = [NSApp getIntf];
425 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
427 vlc_thread_set_priority( p_intf, VLC_THREAD_PRIORITY_LOW );
429 while( !p_intf->b_die )
431 playlist_t * p_playlist;
433 vlc_mutex_lock( &p_intf->change_lock );
435 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
438 if( p_playlist != NULL )
440 vlc_mutex_lock( &p_playlist->object_lock );
442 [self manage: p_playlist];
444 vlc_mutex_unlock( &p_playlist->object_lock );
445 vlc_object_release( p_playlist );
448 vlc_mutex_unlock( &p_intf->change_lock );
450 o_sleep_date = [NSDate dateWithTimeIntervalSinceNow: .5];
451 [NSThread sleepUntilDate: o_sleep_date];
459 - (void)manage:(playlist_t *)p_playlist
463 intf_thread_t * p_intf = [NSApp getIntf];
465 if( var_Get( (vlc_object_t *)p_playlist, "intf-change", &val ) >= 0 &&
468 p_intf->p_sys->b_playlist_update = VLC_TRUE;
469 p_intf->p_sys->b_intf_update = VLC_TRUE;
472 #define p_input p_playlist->p_input
476 vout_thread_t * p_vout = NULL;
477 aout_instance_t * p_aout = NULL;
478 vlc_bool_t b_need_menus = VLC_FALSE;
480 vlc_mutex_lock( &p_input->stream.stream_lock );
482 if( !p_input->b_die )
484 audio_volume_t i_volume;
486 /* New input or stream map change */
487 if( p_input->stream.b_changed )
489 p_intf->p_sys->b_playing = 1;
490 [self manageMode: p_playlist];
491 b_need_menus = VLC_TRUE;
494 if( p_intf->p_sys->i_part !=
495 p_input->stream.p_selected_area->i_part )
497 p_intf->p_sys->b_chapter_update = 1;
498 b_need_menus = VLC_TRUE;
501 p_aout = vlc_object_find( p_intf, VLC_OBJECT_AOUT,
507 if( var_Get( (vlc_object_t *)p_aout, "intf-change", &val )
510 p_intf->p_sys->b_aout_update = 1;
511 b_need_menus = VLC_TRUE;
514 vlc_object_release( (vlc_object_t *)p_aout );
517 aout_VolumeGet( p_intf, &i_volume );
518 p_intf->p_sys->b_mute = ( i_volume == 0 );
520 p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
526 if( var_Get( (vlc_object_t *)p_vout, "intf-change", &val )
529 p_intf->p_sys->b_vout_update = 1;
530 b_need_menus = VLC_TRUE;
533 vlc_object_release( (vlc_object_t *)p_vout );
538 [self setupMenus: p_input];
542 vlc_mutex_unlock( &p_input->stream.stream_lock );
544 else if( p_intf->p_sys->b_playing && !p_intf->b_die )
546 p_intf->p_sys->b_playing = 0;
547 [self manageMode: p_playlist];
553 - (void)manageMode:(playlist_t *)p_playlist
555 intf_thread_t * p_intf = [NSApp getIntf];
557 if( p_playlist->p_input != NULL )
559 /* get ready for menu regeneration */
560 p_intf->p_sys->b_program_update = 1;
561 p_intf->p_sys->b_title_update = 1;
562 p_intf->p_sys->b_chapter_update = 1;
563 p_intf->p_sys->b_audio_update = 1;
564 p_intf->p_sys->b_spu_update = 1;
565 p_intf->p_sys->b_current_title_update = 1;
566 p_intf->p_sys->i_part = 0;
568 p_playlist->p_input->stream.b_changed = 0;
570 msg_Dbg( p_intf, "stream has changed, refreshing interface" );
574 vout_thread_t * p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
578 vlc_object_detach( p_vout );
579 vlc_object_release( p_vout );
581 vlc_mutex_unlock( &p_playlist->object_lock );
582 vout_Destroy( p_vout );
583 vlc_mutex_lock( &p_playlist->object_lock );
587 p_intf->p_sys->b_intf_update = VLC_TRUE;
590 - (void)manageIntf:(NSTimer *)o_timer
592 intf_thread_t * p_intf = [NSApp getIntf];
594 if( p_intf->p_vlc->b_die == VLC_TRUE )
596 [o_timer invalidate];
600 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
603 if( p_playlist == NULL )
608 if ( p_intf->p_sys->b_playlist_update )
613 var_Set( (vlc_object_t *)p_playlist, "intf-change", val );
615 [o_playlist playlistUpdated];
617 p_intf->p_sys->b_playlist_update = VLC_FALSE;
620 if( p_intf->p_sys->b_current_title_update )
624 NSEnumerator * o_enum = [[NSApp windows] objectEnumerator];
626 while( ( o_vout_wnd = [o_enum nextObject] ) )
628 if( [[o_vout_wnd className] isEqualToString: @"VLCWindow"] )
630 [o_vout_wnd updateTitle];
634 [o_playlist updateRowSelection];
637 p_intf->p_sys->b_current_title_update = FALSE;
640 vlc_mutex_lock( &p_playlist->object_lock );
642 #define p_input p_playlist->p_input
644 if( p_input != NULL )
646 vlc_mutex_lock( &p_input->stream.stream_lock );
649 if( p_intf->p_sys->b_intf_update )
651 vlc_bool_t b_input = VLC_FALSE;
652 vlc_bool_t b_plmul = VLC_FALSE;
653 vlc_bool_t b_control = VLC_FALSE;
654 vlc_bool_t b_seekable = VLC_FALSE;
655 vlc_bool_t b_chapters = VLC_FALSE;
657 b_plmul = p_playlist->i_size > 1;
659 if( ( b_input = ( p_input != NULL ) ) )
661 /* seekable streams */
662 b_seekable = p_input->stream.b_seekable;
664 /* control buttons for free pace streams */
665 b_control = p_input->stream.b_pace_control;
668 b_chapters = p_input->stream.p_selected_area->i_part_nb > 1;
671 p_intf->p_sys->b_play_status =
672 p_input->stream.control.i_status != PAUSE_S;
677 p_intf->p_sys->b_play_status = VLC_FALSE;
679 [self setSubmenusEnabled: FALSE];
682 [self playStatusUpdated: p_intf->p_sys->b_play_status];
684 [o_btn_stop setEnabled: b_input];
685 [o_btn_faster setEnabled: b_control];
686 [o_btn_slower setEnabled: b_control];
687 [o_btn_prev setEnabled: (b_plmul || b_chapters)];
688 [o_btn_next setEnabled: (b_plmul || b_chapters)];
690 [o_timeslider setFloatValue: 0.0];
691 [o_timeslider setEnabled: b_seekable];
692 [o_timefield setStringValue: @"0:00:00"];
694 [self manageVolumeSlider];
696 p_intf->p_sys->b_intf_update = VLC_FALSE;
699 #define p_area p_input->stream.p_selected_area
701 if( p_intf->p_sys->b_playing && p_input != NULL )
703 vlc_bool_t b_field_update = VLC_TRUE;
705 if( !p_input->b_die && ( p_intf->p_sys->b_play_status !=
706 ( p_input->stream.control.i_status != PAUSE_S ) ) )
708 p_intf->p_sys->b_play_status =
709 !p_intf->p_sys->b_play_status;
711 [self playStatusUpdated: p_intf->p_sys->b_play_status];
714 if( p_input->stream.b_seekable )
716 if( f_slider == f_slider_old )
718 float f_updated = ( 10000. * p_area->i_tell ) /
721 if( f_slider != f_updated )
723 [o_timeslider setFloatValue: f_updated];
728 off_t i_seek = ( f_slider * p_area->i_size ) / 10000;
730 /* release the lock to be able to seek */
731 vlc_mutex_unlock( &p_input->stream.stream_lock );
732 input_Seek( p_input, i_seek, INPUT_SEEK_SET );
733 vlc_mutex_lock( &p_input->stream.stream_lock );
735 /* update the old value */
736 f_slider_old = f_slider;
738 b_field_update = VLC_FALSE;
745 char psz_time[ OFFSETTOTIME_MAX_SIZE ];
747 input_OffsetToTime( p_input, psz_time, p_area->i_tell );
749 o_time = [NSString stringWithCString: psz_time];
750 [o_timefield setStringValue: o_time];
753 /* disable screen saver */
754 UpdateSystemActivity( UsrActivity );
759 if( p_input != NULL )
761 vlc_mutex_unlock( &p_input->stream.stream_lock );
766 vlc_mutex_unlock( &p_playlist->object_lock );
767 vlc_object_release( p_playlist );
769 [self updateMessageArray];
772 - (void)updateMessageArray
775 intf_thread_t * p_intf = [NSApp getIntf];
777 vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
778 i_stop = *p_intf->p_sys->p_sub->pi_stop;
779 vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
781 if( p_intf->p_sys->p_sub->i_start != i_stop )
783 NSColor *o_white = [NSColor whiteColor];
784 NSColor *o_red = [NSColor redColor];
785 NSColor *o_yellow = [NSColor yellowColor];
786 NSColor *o_gray = [NSColor grayColor];
788 NSColor * pp_color[4] = { o_white, o_red, o_yellow, o_gray };
789 static const char * ppsz_type[4] = { ": ", " error: ",
790 " warning: ", " debug: " };
792 for( i_start = p_intf->p_sys->p_sub->i_start;
794 i_start = (i_start+1) % VLC_MSG_QSIZE )
797 NSDictionary *o_attr;
798 NSAttributedString *o_msg_color;
800 int i_type = p_intf->p_sys->p_sub->p_msg[i_start].i_type;
804 if( [o_msg_arr count] + 2 > 200 )
806 unsigned rid[] = { 0, 1 };
807 [o_msg_arr removeObjectsFromIndices: (unsigned *)&rid
808 numIndices: sizeof(rid)/sizeof(rid[0])];
811 o_attr = [NSDictionary dictionaryWithObject: o_gray
812 forKey: NSForegroundColorAttributeName];
813 o_msg = [NSString stringWithFormat: @"%s%s",
814 p_intf->p_sys->p_sub->p_msg[i_start].psz_module,
816 o_msg_color = [[NSAttributedString alloc]
817 initWithString: o_msg attributes: o_attr];
818 [o_msg_arr addObject: [o_msg_color autorelease]];
820 o_attr = [NSDictionary dictionaryWithObject: pp_color[i_type]
821 forKey: NSForegroundColorAttributeName];
822 o_msg = [NSString stringWithFormat: @"%s\n",
823 p_intf->p_sys->p_sub->p_msg[i_start].psz_msg];
824 o_msg_color = [[NSAttributedString alloc]
825 initWithString: o_msg attributes: o_attr];
826 [o_msg_arr addObject: [o_msg_color autorelease]];
832 NSString *o_my_msg = [NSString stringWithFormat: @"%s: %s\n",
833 p_intf->p_sys->p_sub->p_msg[i_start].psz_module,
834 p_intf->p_sys->p_sub->p_msg[i_start].psz_msg];
836 NSRange s_r = NSMakeRange( [[o_err_msg string] length], 0 );
837 [o_err_msg setEditable: YES];
838 [o_err_msg setSelectedRange: s_r];
839 [o_err_msg insertText: o_my_msg];
841 [o_error makeKeyAndOrderFront: self];
842 [o_err_msg setEditable: NO];
846 vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
847 p_intf->p_sys->p_sub->i_start = i_start;
848 vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
852 - (void)playStatusUpdated:(BOOL)b_pause
856 [o_btn_play setImage: o_img_pause];
857 [o_btn_play setToolTip: _NS("Pause")];
858 [o_mi_play setTitle: _NS("Pause")];
859 [o_dmi_play setTitle: _NS("Pause")];
863 [o_btn_play setImage: o_img_play];
864 [o_btn_play setToolTip: _NS("Play")];
865 [o_mi_play setTitle: _NS("Play")];
866 [o_dmi_play setTitle: _NS("Play")];
870 - (void)setSubmenusEnabled:(BOOL)b_enabled
872 [o_mi_program setEnabled: b_enabled];
873 [o_mi_title setEnabled: b_enabled];
874 [o_mi_chapter setEnabled: b_enabled];
875 [o_mi_language setEnabled: b_enabled];
876 [o_mi_subtitle setEnabled: b_enabled];
877 [o_mi_channels setEnabled: b_enabled];
878 [o_mi_device setEnabled: b_enabled];
879 [o_mi_screen setEnabled: b_enabled];
882 - (void)manageVolumeSlider
884 audio_volume_t i_volume;
885 intf_thread_t * p_intf = [NSApp getIntf];
887 aout_VolumeGet( p_intf, &i_volume );
889 [o_volumeslider setFloatValue: (float)i_volume / AOUT_VOLUME_STEP];
890 [o_volumeslider setEnabled: 1];
892 p_intf->p_sys->b_mute = ( i_volume == 0 );
898 vout_thread_t * p_vout;
899 playlist_t * p_playlist;
900 intf_thread_t * p_intf = [NSApp getIntf];
905 msg_Dbg( p_intf, "removing all playlists" );
906 while( (p_playlist = vlc_object_find( p_intf->p_vlc, VLC_OBJECT_PLAYLIST,
909 vlc_object_detach( p_playlist );
910 vlc_object_release( p_playlist );
911 playlist_Destroy( p_playlist );
917 msg_Dbg( p_intf, "removing all video outputs" );
918 while( (p_vout = vlc_object_find( p_intf->p_vlc,
919 VLC_OBJECT_VOUT, FIND_CHILD )) )
921 vlc_object_detach( p_vout );
922 vlc_object_release( p_vout );
923 vout_Destroy( p_vout );
926 if( o_img_pause != nil )
928 [o_img_pause release];
932 if( o_img_play != nil )
934 [o_img_play release];
938 if( o_msg_arr != nil )
940 [o_msg_arr removeAllObjects];
945 if( o_msg_lock != nil )
947 [o_msg_lock release];
959 /* write cached user defaults to disk */
960 [[NSUserDefaults standardUserDefaults] synchronize];
962 /* send a dummy event to break out of the event loop */
963 o_event = [NSEvent mouseEventWithType: NSLeftMouseDown
964 location: NSMakePoint( 1, 1 ) modifierFlags: 0
965 timestamp: 1 windowNumber: [[NSApp mainWindow] windowNumber]
966 context: [NSGraphicsContext currentContext] eventNumber: 1
967 clickCount: 1 pressure: 0.0];
968 [NSApp postEvent: o_event atStart: YES];
971 - (void)setupMenus:(input_thread_t *)p_input
973 unsigned int i, i_nb_items;
975 NSString * o_menu_title;
976 char psz_title[ 256 ];
978 es_descriptor_t * p_audio_es = NULL;
979 es_descriptor_t * p_spu_es = NULL;
981 intf_thread_t * p_intf = [NSApp getIntf];
983 p_intf->p_sys->b_chapter_update |= p_intf->p_sys->b_title_update;
984 p_intf->p_sys->b_audio_update |= p_intf->p_sys->b_title_update |
985 p_intf->p_sys->b_program_update;
986 p_intf->p_sys->b_spu_update |= p_intf->p_sys->b_title_update |
987 p_intf->p_sys->b_program_update;
989 if( p_intf->p_sys->b_program_update )
992 SEL pf_toggle_program;
993 pgrm_descriptor_t * p_pgrm;
995 if( p_input->stream.p_new_program )
997 p_pgrm = p_input->stream.p_new_program;
1001 p_pgrm = p_input->stream.p_selected_program;
1004 o_program = [o_mi_program submenu];
1005 pf_toggle_program = @selector(toggleProgram:);
1007 /* remove previous program items */
1008 i_nb_items = [o_program numberOfItems];
1009 for( i = 0; i < i_nb_items; i++ )
1011 [o_program removeItemAtIndex: 0];
1014 /* make (un)sensitive */
1015 [o_mi_program setEnabled:
1016 p_input->stream.i_pgrm_number > 1];
1018 /* add program items */
1019 for( i = 0 ; i < p_input->stream.i_pgrm_number ; i++ )
1021 snprintf( psz_title, sizeof(psz_title), "id %d",
1022 p_input->stream.pp_programs[i]->i_number );
1023 psz_title[sizeof(psz_title) - 1] = '\0';
1025 o_menu_title = [NSApp localizedString: psz_title];
1027 o_item = [o_program addItemWithTitle: o_menu_title
1028 action: pf_toggle_program keyEquivalent: @""];
1029 [o_item setTag: p_input->stream.pp_programs[i]->i_number];
1030 [o_item setTarget: o_controls];
1032 if( p_pgrm == p_input->stream.pp_programs[i] )
1034 [o_item setState: NSOnState];
1038 p_intf->p_sys->b_program_update = 0;
1041 if( p_intf->p_sys->b_title_update )
1044 SEL pf_toggle_title;
1046 o_title = [o_mi_title submenu];
1047 pf_toggle_title = @selector(toggleTitle:);
1049 /* remove previous title items */
1050 i_nb_items = [o_title numberOfItems];
1051 for( i = 0; i < i_nb_items; i++ )
1053 [o_title removeItemAtIndex: 0];
1056 /* make (un)sensitive */
1057 [o_mi_title setEnabled:
1058 p_input->stream.i_area_nb > 1];
1060 /* add title items */
1061 for( i = 1 ; i < p_input->stream.i_area_nb ; i++ )
1063 snprintf( psz_title, sizeof(psz_title), "Title %d (%d)", i,
1064 p_input->stream.pp_areas[i]->i_part_nb );
1065 psz_title[sizeof(psz_title) - 1] = '\0';
1067 o_menu_title = [NSApp localizedString: psz_title];
1069 o_item = [o_title addItemWithTitle: o_menu_title
1070 action: pf_toggle_title keyEquivalent: @""];
1072 [o_item setTarget: o_controls];
1074 if( ( p_input->stream.pp_areas[i] ==
1075 p_input->stream.p_selected_area ) )
1077 [o_item setState: NSOnState];
1081 p_intf->p_sys->b_title_update = 0;
1084 if( p_intf->p_sys->b_chapter_update )
1087 SEL pf_toggle_chapter;
1089 o_chapter = [o_mi_chapter submenu];
1090 pf_toggle_chapter = @selector(toggleChapter:);
1092 /* remove previous chapter items */
1093 i_nb_items = [o_chapter numberOfItems];
1094 for( i = 0; i < i_nb_items; i++ )
1096 [o_chapter removeItemAtIndex: 0];
1099 /* make (un)sensitive */
1100 [o_mi_chapter setEnabled:
1101 p_input->stream.p_selected_area->i_part_nb > 1];
1103 /* add chapter items */
1104 for( i = 0 ; i < p_input->stream.p_selected_area->i_part_nb ; i++ )
1106 snprintf( psz_title, sizeof(psz_title), "Chapter %d", i + 1 );
1107 psz_title[sizeof(psz_title) - 1] = '\0';
1109 o_menu_title = [NSApp localizedString: psz_title];
1111 o_item = [o_chapter addItemWithTitle: o_menu_title
1112 action: pf_toggle_chapter keyEquivalent: @""];
1113 [o_item setTag: i + 1];
1114 [o_item setTarget: o_controls];
1116 if( ( p_input->stream.p_selected_area->i_part == i + 1 ) )
1118 [o_item setState: NSOnState];
1122 p_intf->p_sys->i_part =
1123 p_input->stream.p_selected_area->i_part;
1125 p_intf->p_sys->b_chapter_update = 0;
1128 for( i = 0 ; i < p_input->stream.i_selected_es_number ; i++ )
1130 if( p_input->stream.pp_selected_es[i]->i_cat == AUDIO_ES )
1132 p_audio_es = p_input->stream.pp_selected_es[i];
1134 else if( p_input->stream.pp_selected_es[i]->i_cat == SPU_ES )
1136 p_spu_es = p_input->stream.pp_selected_es[i];
1140 if( p_intf->p_sys->b_audio_update )
1142 [self setupLangMenu: p_input mi: o_mi_language es: p_audio_es
1143 category: AUDIO_ES selector: @selector(toggleLanguage:)];
1145 p_intf->p_sys->b_audio_update = 0;
1148 if( p_intf->p_sys->b_spu_update )
1150 [self setupLangMenu: p_input mi: o_mi_subtitle es: p_spu_es
1151 category: SPU_ES selector: @selector(toggleLanguage:)];
1153 p_intf->p_sys->b_spu_update = 0;
1156 if ( p_intf->p_sys->b_aout_update )
1158 aout_instance_t * p_aout = vlc_object_find( p_intf, VLC_OBJECT_AOUT,
1161 if ( p_aout != NULL )
1166 var_Set( (vlc_object_t *)p_aout, "intf-change", val );
1168 [self setupVarMenu: o_mi_channels target: (vlc_object_t *)p_aout
1169 var: "audio-channels" selector: @selector(toggleVar:)];
1171 [self setupVarMenu: o_mi_device target: (vlc_object_t *)p_aout
1172 var: "audio-device" selector: @selector(toggleVar:)];
1174 vlc_object_release( (vlc_object_t *)p_aout );
1177 p_intf->p_sys->b_aout_update = 0;
1180 if( p_intf->p_sys->b_vout_update )
1182 vout_thread_t * p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
1185 if ( p_vout != NULL )
1190 var_Set( (vlc_object_t *)p_vout, "intf-change", val );
1192 [self setupVarMenu: o_mi_screen target: (vlc_object_t *)p_vout
1193 var: "video-device" selector: @selector(toggleVar:)];
1195 vlc_object_release( (vlc_object_t *)p_vout );
1197 [o_mi_close_window setEnabled: TRUE];
1200 p_intf->p_sys->b_vout_update = 0;
1206 - (void)setupLangMenu:(input_thread_t *)p_input
1207 mi:(NSMenuItem *)o_mi
1208 es:(es_descriptor_t *)p_es
1210 selector:(SEL)pf_callback
1212 unsigned int i, i_nb_items;
1213 NSMenu * o_menu = [o_mi submenu];
1215 /* remove previous language items */
1216 i_nb_items = [o_menu numberOfItems];
1217 for( i = 0; i < i_nb_items; i++ )
1219 [o_menu removeItemAtIndex: 0];
1222 /* make sensitive : we can't change it after we build the menu, and
1223 * before, we don't yet how many items we will have. So make it
1224 * always sensitive. --Meuuh */
1225 [o_mi setEnabled: TRUE];
1228 /* We do not use this code, because you need to start stop .avi for
1229 * it to work, so not very useful now --hartman */
1230 if ( o_mi == o_mi_subtitle ) {
1232 [o_mi setEnabled: TRUE ];
1235 o_title = _NS("Load from file..");
1236 o_lmi = [o_menu addItemWithTitle: o_title
1237 action: pf_callback keyEquivalent: @""];
1238 [o_lmi setTag: 2000];
1239 [o_lmi setTarget: o_controls];
1243 #define ES p_input->stream.pp_es[i]
1244 for( i = 0 ; i < p_input->stream.i_es_number ; i++ )
1246 if( ( ES->i_cat == i_cat ) &&
1249 p_input->stream.p_selected_program ) )
1256 o_title = [NSApp localizedString: ES->psz_desc];
1260 char psz_title[ 256 ];
1262 snprintf( psz_title, sizeof(psz_title), _("Language 0x%x"),
1264 psz_title[sizeof(psz_title) - 1] = '\0';
1266 o_title = [NSApp localizedString: psz_title];
1269 o_lmi = [o_menu addItemWithTitle: o_title
1270 action: pf_callback keyEquivalent: @""];
1271 [o_lmi setRepresentedObject:
1272 [NSValue valueWithPointer: ES]];
1273 [o_lmi setTarget: o_controls];
1274 [o_lmi setTag: i_cat];
1276 if( /*p_es == ES*/ ES->p_decoder_fifo != NULL )
1278 [o_lmi setState: NSOnState];
1285 - (void)setupVarMenu:(NSMenuItem *)o_mi
1286 target:(vlc_object_t *)p_object
1287 var:(const char *)psz_variable
1288 selector:(SEL)pf_callback
1291 NSMenu * o_menu = [o_mi submenu];
1295 /* remove previous items */
1296 i_nb_items = [o_menu numberOfItems];
1297 for( i = 0; i < i_nb_items; i++ )
1299 [o_menu removeItemAtIndex: 0];
1302 if ( var_Get( p_object, psz_variable, &val ) < 0 )
1306 psz_value = val.psz_string;
1308 if ( var_Change( p_object, psz_variable,
1309 VLC_VAR_GETLIST, &val ) < 0 )
1315 /* make (un)sensitive */
1316 [o_mi setEnabled: ( val.p_list->i_count > 0 )];
1318 for ( i = 0; i < val.p_list->i_count; i++ )
1323 o_title = [NSApp localizedString: val.p_list->p_values[i].psz_string];
1324 o_lmi = [o_menu addItemWithTitle: o_title
1325 action: pf_callback keyEquivalent: @""];
1326 /* FIXME: this isn't 64-bit clean ! */
1327 [o_lmi setTag: (int)psz_variable];
1328 [o_lmi setRepresentedObject:
1329 [NSValue valueWithPointer: p_object]];
1330 [o_lmi setTarget: o_controls];
1332 if ( !strcmp( psz_value, val.p_list->p_values[i].psz_string ) )
1333 [o_lmi setState: NSOnState];
1336 var_Change( p_object, psz_variable, VLC_VAR_FREELIST,
1342 - (IBAction)clearRecentItems:(id)sender
1344 [[NSDocumentController sharedDocumentController]
1345 clearRecentDocuments: nil];
1348 - (void)openRecentItem:(id)sender
1350 [self application: nil openFile: [sender title]];
1353 - (IBAction)viewPreferences:(id)sender
1355 if( o_prefs == nil )
1357 o_prefs = [[VLCPrefs alloc] init];
1360 [o_prefs createPrefPanel: @"main"];
1363 - (IBAction)timesliderUpdate:(id)sender
1367 switch( [[NSApp currentEvent] type] )
1370 case NSLeftMouseDown:
1371 f_slider = [sender floatValue];
1374 case NSLeftMouseDragged:
1375 f_updated = [sender floatValue];
1382 intf_thread_t * p_intf = [NSApp getIntf];
1384 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1387 if( p_playlist == NULL )
1392 vlc_mutex_lock( &p_playlist->object_lock );
1394 if( p_playlist->p_input != NULL )
1398 char psz_time[ OFFSETTOTIME_MAX_SIZE ];
1400 #define p_area p_playlist->p_input->stream.p_selected_area
1401 vlc_mutex_lock( &p_playlist->p_input->stream.stream_lock );
1402 i_tell = f_updated / 10000. * p_area->i_size;
1403 input_OffsetToTime( p_playlist->p_input, psz_time, i_tell );
1404 vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
1407 o_time = [NSString stringWithCString: psz_time];
1408 [o_timefield setStringValue: o_time];
1411 vlc_mutex_unlock( &p_playlist->object_lock );
1412 vlc_object_release( p_playlist );
1415 - (IBAction)closeError:(id)sender
1417 [o_err_msg setString: @""];
1418 [o_error performClose: self];
1421 - (IBAction)openReadMe:(id)sender
1423 NSString * o_path = [[NSBundle mainBundle]
1424 pathForResource: @"README.MacOSX" ofType: @"rtf"];
1426 [[NSWorkspace sharedWorkspace] openFile: o_path
1427 withApplication: @"TextEdit"];
1430 - (IBAction)reportABug:(id)sender
1432 NSURL * o_url = [NSURL URLWithString:
1433 @"http://www.videolan.org/support/bug-reporting.html"];
1435 [[NSWorkspace sharedWorkspace] openURL: o_url];
1438 - (IBAction)openWebsite:(id)sender
1440 NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org"];
1442 [[NSWorkspace sharedWorkspace] openURL: o_url];
1445 - (IBAction)openLicense:(id)sender
1447 NSString * o_path = [[NSBundle mainBundle]
1448 pathForResource: @"COPYING" ofType: nil];
1450 [[NSWorkspace sharedWorkspace] openFile: o_path
1451 withApplication: @"TextEdit"];
1454 - (IBAction)openCrashLog:(id)sender
1456 NSString * o_path = [@"~/Library/Logs/CrashReporter/VLC.crash.log"
1457 stringByExpandingTildeInPath];
1460 if ( [[NSFileManager defaultManager] fileExistsAtPath: o_path ] )
1462 [[NSWorkspace sharedWorkspace] openFile: o_path
1463 withApplication: @"Console"];
1467 NSBeginInformationalAlertSheet(_NS("No CrashLog found"), @"Continue", nil, nil, o_msgs_panel, self, NULL, NULL, nil, _NS("Either you are running Mac OS X pre 10.2 or you haven't experienced any heavy crashes yet.") );
1472 - (void)windowDidBecomeKey:(NSNotification *)o_notification
1474 if( [o_notification object] == o_msgs_panel )
1477 NSEnumerator * o_enum;
1479 [o_messages setString: @""];
1483 o_enum = [o_msg_arr objectEnumerator];
1485 while( ( o_msg = [o_enum nextObject] ) != nil )
1487 [o_messages insertText: o_msg];
1490 [o_msg_lock unlock];
1496 @implementation VLCMain (NSMenuValidation)
1498 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
1500 BOOL bEnabled = TRUE;
1502 /* Recent Items Menu */
1504 if( [[o_mi title] isEqualToString: _NS("Clear Menu")] )
1506 NSMenu * o_menu = [o_mi_open_recent submenu];
1507 int i_nb_items = [o_menu numberOfItems];
1508 NSArray * o_docs = [[NSDocumentController sharedDocumentController]
1509 recentDocumentURLs];
1510 UInt32 i_nb_docs = [o_docs count];
1512 if( i_nb_items > 1 )
1514 while( --i_nb_items )
1516 [o_menu removeItemAtIndex: 0];
1525 [o_menu insertItem: [NSMenuItem separatorItem] atIndex: 0];
1531 o_url = [o_docs objectAtIndex: i_nb_docs];
1533 if( [o_url isFileURL] )
1535 o_doc = [o_url path];
1539 o_doc = [o_url absoluteString];
1542 [o_menu insertItemWithTitle: o_doc
1543 action: @selector(openRecentItem:)
1544 keyEquivalent: @"" atIndex: 0];
1546 if( i_nb_docs == 0 )
1563 @implementation VLCMain (Internal)
1565 - (void)handlePortMessage:(NSPortMessage *)o_msg
1570 NSInvocation * o_inv;
1571 NSConditionLock * o_lock;
1573 o_data = [[o_msg components] lastObject];
1574 o_inv = *((NSInvocation **)[o_data bytes]);
1575 [o_inv getArgument: &o_value atIndex: 2];
1576 val = (id **)[o_value pointerValue];
1577 [o_inv setArgument: val[1] atIndex: 2];
1582 [o_lock unlockWithCondition: 1];