1 /*****************************************************************************
2 * intf.m: MacOS X interface plugin
3 *****************************************************************************
4 * Copyright (C) 2002-2003 VideoLAN
5 * $Id: intf.m,v 1.77 2003/05/08 17:13:22 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_crashlog setTitle: _NS("Open CrashLog")];
299 [o_mi_about setTitle: _NS("About VLC media player")];
300 [o_mi_prefs setTitle: _NS("Preferences...")];
301 [o_mi_hide setTitle: _NS("Hide VLC")];
302 [o_mi_hide_others setTitle: _NS("Hide Others")];
303 [o_mi_show_all setTitle: _NS("Show All")];
304 [o_mi_quit setTitle: _NS("Quit VLC")];
306 [o_mu_file setTitle: _ANS("1:File")];
307 [o_mi_open_generic setTitle: _NS("Open...")];
308 [o_mi_open_file setTitle: _NS("Open File...")];
309 [o_mi_open_disc setTitle: _NS("Open Disc...")];
310 [o_mi_open_net setTitle: _NS("Open Network...")];
311 [o_mi_open_recent setTitle: _NS("Open Recent")];
312 [o_mi_open_recent_cm setTitle: _NS("Clear Menu")];
314 [o_mu_edit setTitle: _NS("Edit")];
315 [o_mi_cut setTitle: _NS("Cut")];
316 [o_mi_copy setTitle: _NS("Copy")];
317 [o_mi_paste setTitle: _NS("Paste")];
318 [o_mi_clear setTitle: _NS("Clear")];
319 [o_mi_select_all setTitle: _NS("Select All")];
321 [o_mu_controls setTitle: _NS("Controls")];
322 [o_mi_play setTitle: _NS("Play")];
323 [o_mi_stop setTitle: _NS("Stop")];
324 [o_mi_faster setTitle: _NS("Faster")];
325 [o_mi_slower setTitle: _NS("Slower")];
326 [o_mi_previous setTitle: _NS("Previous")];
327 [o_mi_next setTitle: _NS("Next")];
328 [o_mi_loop setTitle: _NS("Loop")];
329 [o_mi_fwd setTitle: _NS("Step Forward")];
330 [o_mi_bwd setTitle: _NS("Step Backward")];
331 [o_mi_program setTitle: _NS("Program")];
332 [o_mu_program setTitle: _NS("Program")];
333 [o_mi_title setTitle: _NS("Title")];
334 [o_mu_title setTitle: _NS("Title")];
335 [o_mi_chapter setTitle: _NS("Chapter")];
336 [o_mu_chapter setTitle: _NS("Chapter")];
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_audiotrack setTitle: _NS("Audio Track")];
343 [o_mu_audiotrack setTitle: _NS("Audio Track")];
344 [o_mi_channels setTitle: _NS("Channels")];
345 [o_mu_channels setTitle: _NS("Channels")];
346 [o_mi_device setTitle: _NS("Device")];
347 [o_mu_device setTitle: _NS("Device")];
349 [o_mu_video setTitle: _NS("Video")];
350 [o_mi_half_window setTitle: _NS("Half Size")];
351 [o_mi_normal_window setTitle: _NS("Normal Size")];
352 [o_mi_double_window setTitle: _NS("Double Size")];
353 [o_mi_fittoscreen setTitle: _NS("Fit To Screen")];
354 [o_mi_fullscreen setTitle: _NS("Fullscreen")];
355 [o_mi_floatontop setTitle: _NS("Float On Top")];
356 [o_mi_videotrack setTitle: _NS("Video Track")];
357 [o_mu_videotrack setTitle: _NS("Video Track")];
358 [o_mi_screen setTitle: _NS("Screen")];
359 [o_mu_screen setTitle: _NS("Screen")];
360 [o_mi_subtitle setTitle: _NS("Subtitles")];
361 [o_mu_subtitle setTitle: _NS("Subtitles")];
362 [o_mi_deinterlace setTitle: _NS("Deinterlace")];
363 [o_mu_deinterlace setTitle: _NS("Deinterlace")];
365 [o_mu_window setTitle: _NS("Window")];
366 [o_mi_minimize setTitle: _NS("Minimize Window")];
367 [o_mi_close_window setTitle: _NS("Close Window")];
368 [o_mi_controller setTitle: _NS("Controller")];
369 [o_mi_playlist setTitle: _NS("Playlist")];
370 [o_mi_info setTitle: _NS("Info")];
371 [o_mi_messages setTitle: _NS("Messages")];
373 [o_mi_bring_atf setTitle: _NS("Bring All to Front")];
375 [o_mu_help setTitle: _NS("Help")];
376 [o_mi_readme setTitle: _NS("ReadMe...")];
377 [o_mi_reportabug setTitle: _NS("Report a Bug")];
378 [o_mi_website setTitle: _NS("VideoLAN Website")];
379 [o_mi_license setTitle: _NS("License")];
382 [o_dmi_play setTitle: _NS("Play")];
383 [o_dmi_stop setTitle: _NS("Stop")];
384 [o_dmi_next setTitle: _NS("Next")];
385 [o_dmi_previous setTitle: _NS("Previous")];
388 [o_error setTitle: _NS("Error")];
389 [o_err_lbl setStringValue: _NS("An error has occurred which probably prevented the execution of your request:")];
390 [o_err_bug_lbl setStringValue: _NS("If you believe that it is a bug, please follow the instructions at:")];
391 [o_err_btn_msgs setTitle: _NS("Open Messages Window")];
392 [o_err_btn_dismiss setTitle: _NS("Dismiss")];
394 [o_info_window setTitle: _NS("Info")];
396 [self setSubmenusEnabled: FALSE];
397 [self manageVolumeSlider];
400 - (void)applicationWillFinishLaunching:(NSNotification *)o_notification
402 intf_thread_t * p_intf = [NSApp getIntf];
404 o_msg_lock = [[NSLock alloc] init];
405 o_msg_arr = [[NSMutableArray arrayWithCapacity: 200] retain];
407 o_img_play = [[NSImage imageNamed: @"play"] retain];
408 o_img_pause = [[NSImage imageNamed: @"pause"] retain];
410 [p_intf->p_sys->o_sendport setDelegate: self];
411 [[NSRunLoop currentRunLoop]
412 addPort: p_intf->p_sys->o_sendport
413 forMode: NSDefaultRunLoopMode];
415 [NSTimer scheduledTimerWithTimeInterval: 0.5
416 target: self selector: @selector(manageIntf:)
417 userInfo: nil repeats: FALSE];
419 [NSThread detachNewThreadSelector: @selector(manage)
420 toTarget: self withObject: nil];
422 vlc_thread_set_priority( p_intf, VLC_THREAD_PRIORITY_LOW );
425 - (BOOL)application:(NSApplication *)o_app openFile:(NSString *)o_filename
427 intf_thread_t * p_intf = [NSApp getIntf];
429 [o_playlist appendArray:
430 [NSArray arrayWithObject: o_filename] atPos: -1 enqueue: NO];
432 config_PutPsz( [NSApp getIntf], "sub-file", "" );
433 config_PutInt( p_intf, "sub-delay", 0 );
434 config_PutFloat( p_intf, "sub-fps", 0.0 );
435 config_PutPsz( p_intf, "sout", "" );
451 NSDate * o_sleep_date;
452 intf_thread_t * p_intf = [NSApp getIntf];
453 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
455 vlc_thread_set_priority( p_intf, VLC_THREAD_PRIORITY_LOW );
457 while( !p_intf->b_die )
459 playlist_t * p_playlist;
461 vlc_mutex_lock( &p_intf->change_lock );
463 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
466 if( p_playlist != NULL )
468 vlc_mutex_lock( &p_playlist->object_lock );
470 [self manage: p_playlist];
472 vlc_mutex_unlock( &p_playlist->object_lock );
473 vlc_object_release( p_playlist );
476 vlc_mutex_unlock( &p_intf->change_lock );
478 o_sleep_date = [NSDate dateWithTimeIntervalSinceNow: .5];
479 [NSThread sleepUntilDate: o_sleep_date];
487 - (void)manage:(playlist_t *)p_playlist
491 intf_thread_t * p_intf = [NSApp getIntf];
493 if( var_Get( (vlc_object_t *)p_playlist, "intf-change", &val ) >= 0 &&
496 p_intf->p_sys->b_playlist_update = VLC_TRUE;
497 p_intf->p_sys->b_intf_update = VLC_TRUE;
500 #define p_input p_playlist->p_input
504 vout_thread_t * p_vout = NULL;
505 aout_instance_t * p_aout = NULL;
506 vlc_bool_t b_need_menus = VLC_FALSE;
508 vlc_mutex_lock( &p_input->stream.stream_lock );
510 if( !p_input->b_die )
512 audio_volume_t i_volume;
514 /* New input or stream map change */
515 if( p_input->stream.b_changed )
517 p_intf->p_sys->b_playing = 1;
518 [self manageMode: p_playlist];
519 b_need_menus = VLC_TRUE;
522 if( p_intf->p_sys->i_part !=
523 p_input->stream.p_selected_area->i_part )
525 p_intf->p_sys->b_chapter_update = 1;
526 b_need_menus = VLC_TRUE;
529 p_aout = vlc_object_find( p_intf, VLC_OBJECT_AOUT,
535 if( var_Get( (vlc_object_t *)p_aout, "intf-change", &val )
538 p_intf->p_sys->b_aout_update = 1;
539 b_need_menus = VLC_TRUE;
542 vlc_object_release( (vlc_object_t *)p_aout );
545 aout_VolumeGet( p_intf, &i_volume );
546 p_intf->p_sys->b_mute = ( i_volume == 0 );
548 p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
554 if( var_Get( (vlc_object_t *)p_vout, "intf-change", &val )
557 p_intf->p_sys->b_vout_update = 1;
558 b_need_menus = VLC_TRUE;
561 vlc_object_release( (vlc_object_t *)p_vout );
566 [self setupMenus: p_input];
570 vlc_mutex_unlock( &p_input->stream.stream_lock );
572 else if( p_intf->p_sys->b_playing && !p_intf->b_die )
574 p_intf->p_sys->b_playing = 0;
575 [self manageMode: p_playlist];
581 - (void)manageMode:(playlist_t *)p_playlist
583 intf_thread_t * p_intf = [NSApp getIntf];
585 if( p_playlist->p_input != NULL )
587 /* get ready for menu regeneration */
588 p_intf->p_sys->b_program_update = 1;
589 p_intf->p_sys->b_title_update = 1;
590 p_intf->p_sys->b_chapter_update = 1;
591 p_intf->p_sys->b_audio_update = 1;
592 p_intf->p_sys->b_video_update = 1;
593 p_intf->p_sys->b_spu_update = 1;
594 p_intf->p_sys->b_current_title_update = 1;
595 p_intf->p_sys->i_part = 0;
597 p_playlist->p_input->stream.b_changed = 0;
599 msg_Dbg( p_intf, "stream has changed, refreshing interface" );
603 vout_thread_t * p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
607 vlc_object_detach( p_vout );
608 vlc_object_release( p_vout );
610 vlc_mutex_unlock( &p_playlist->object_lock );
611 vout_Destroy( p_vout );
612 vlc_mutex_lock( &p_playlist->object_lock );
616 p_intf->p_sys->b_intf_update = VLC_TRUE;
619 - (void)manageIntf:(NSTimer *)o_timer
621 intf_thread_t * p_intf = [NSApp getIntf];
623 if( p_intf->p_vlc->b_die == VLC_TRUE )
625 [o_timer invalidate];
629 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
632 if( p_playlist == NULL )
637 if ( p_intf->p_sys->b_playlist_update )
642 var_Set( (vlc_object_t *)p_playlist, "intf-change", val );
644 [o_playlist playlistUpdated];
646 p_intf->p_sys->b_playlist_update = VLC_FALSE;
649 if( p_intf->p_sys->b_current_title_update )
651 vout_thread_t *p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
656 NSEnumerator * o_enum = [[NSApp windows] objectEnumerator];
658 while( ( o_vout_wnd = [o_enum nextObject] ) )
660 if( [[o_vout_wnd className] isEqualToString: @"VLCWindow"] )
662 [o_vout_wnd updateTitle];
665 vlc_object_release( (vlc_object_t *)p_vout );
667 [o_playlist updateRowSelection];
670 p_intf->p_sys->b_current_title_update = FALSE;
673 vlc_mutex_lock( &p_playlist->object_lock );
675 #define p_input p_playlist->p_input
677 if( p_input != NULL )
679 vlc_mutex_lock( &p_input->stream.stream_lock );
682 if( p_intf->p_sys->b_intf_update )
684 vlc_bool_t b_input = VLC_FALSE;
685 vlc_bool_t b_plmul = VLC_FALSE;
686 vlc_bool_t b_control = VLC_FALSE;
687 vlc_bool_t b_seekable = VLC_FALSE;
688 vlc_bool_t b_chapters = VLC_FALSE;
690 b_plmul = p_playlist->i_size > 1;
692 if( ( b_input = ( p_input != NULL ) ) )
694 /* seekable streams */
695 b_seekable = p_input->stream.b_seekable;
697 /* control buttons for free pace streams */
698 b_control = p_input->stream.b_pace_control;
701 b_chapters = p_input->stream.p_selected_area->i_part_nb > 1;
704 p_intf->p_sys->b_play_status =
705 p_input->stream.control.i_status != PAUSE_S;
710 p_intf->p_sys->b_play_status = VLC_FALSE;
712 [self setSubmenusEnabled: FALSE];
715 [self playStatusUpdated: p_intf->p_sys->b_play_status];
717 [o_btn_stop setEnabled: b_input];
718 [o_btn_faster setEnabled: b_control];
719 [o_btn_slower setEnabled: b_control];
720 [o_btn_prev setEnabled: (b_plmul || b_chapters)];
721 [o_btn_next setEnabled: (b_plmul || b_chapters)];
723 [o_timeslider setFloatValue: 0.0];
724 [o_timeslider setEnabled: b_seekable];
725 [o_timefield setStringValue: @"0:00:00"];
727 [self manageVolumeSlider];
729 p_intf->p_sys->b_intf_update = VLC_FALSE;
732 #define p_area p_input->stream.p_selected_area
734 if( p_intf->p_sys->b_playing && p_input != NULL )
736 vlc_bool_t b_field_update = VLC_TRUE;
738 if( !p_input->b_die && ( p_intf->p_sys->b_play_status !=
739 ( p_input->stream.control.i_status != PAUSE_S ) ) )
741 p_intf->p_sys->b_play_status =
742 !p_intf->p_sys->b_play_status;
744 [self playStatusUpdated: p_intf->p_sys->b_play_status];
747 if( p_input->stream.b_seekable )
749 if( f_slider == f_slider_old )
751 float f_updated = ( 10000. * p_area->i_tell ) /
754 if( f_slider != f_updated )
756 [o_timeslider setFloatValue: f_updated];
761 off_t i_seek = ( f_slider * p_area->i_size ) / 10000;
763 /* release the lock to be able to seek */
764 vlc_mutex_unlock( &p_input->stream.stream_lock );
765 input_Seek( p_input, i_seek, INPUT_SEEK_SET );
766 vlc_mutex_lock( &p_input->stream.stream_lock );
768 /* update the old value */
769 f_slider_old = f_slider;
771 b_field_update = VLC_FALSE;
778 char psz_time[ OFFSETTOTIME_MAX_SIZE ];
780 input_OffsetToTime( p_input, psz_time, p_area->i_tell );
782 o_time = [NSString stringWithCString: psz_time];
783 [o_timefield setStringValue: o_time];
786 /* disable screen saver */
787 UpdateSystemActivity( UsrActivity );
792 if( p_input != NULL )
794 vlc_mutex_unlock( &p_input->stream.stream_lock );
799 vlc_mutex_unlock( &p_playlist->object_lock );
800 vlc_object_release( p_playlist );
802 [self updateMessageArray];
804 [NSTimer scheduledTimerWithTimeInterval: 0.5
805 target: self selector: @selector(manageIntf:)
806 userInfo: nil repeats: FALSE];
809 - (void)updateMessageArray
812 intf_thread_t * p_intf = [NSApp getIntf];
814 vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
815 i_stop = *p_intf->p_sys->p_sub->pi_stop;
816 vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
818 if( p_intf->p_sys->p_sub->i_start != i_stop )
820 NSColor *o_white = [NSColor whiteColor];
821 NSColor *o_red = [NSColor redColor];
822 NSColor *o_yellow = [NSColor yellowColor];
823 NSColor *o_gray = [NSColor grayColor];
825 NSColor * pp_color[4] = { o_white, o_red, o_yellow, o_gray };
826 static const char * ppsz_type[4] = { ": ", " error: ",
827 " warning: ", " debug: " };
829 for( i_start = p_intf->p_sys->p_sub->i_start;
831 i_start = (i_start+1) % VLC_MSG_QSIZE )
834 NSDictionary *o_attr;
835 NSAttributedString *o_msg_color;
837 int i_type = p_intf->p_sys->p_sub->p_msg[i_start].i_type;
841 if( [o_msg_arr count] + 2 > 400 )
843 unsigned rid[] = { 0, 1 };
844 [o_msg_arr removeObjectsFromIndices: (unsigned *)&rid
845 numIndices: sizeof(rid)/sizeof(rid[0])];
848 o_attr = [NSDictionary dictionaryWithObject: o_gray
849 forKey: NSForegroundColorAttributeName];
850 o_msg = [NSString stringWithFormat: @"%s%s",
851 p_intf->p_sys->p_sub->p_msg[i_start].psz_module,
853 o_msg_color = [[NSAttributedString alloc]
854 initWithString: o_msg attributes: o_attr];
855 [o_msg_arr addObject: [o_msg_color autorelease]];
857 o_attr = [NSDictionary dictionaryWithObject: pp_color[i_type]
858 forKey: NSForegroundColorAttributeName];
859 o_msg = [NSString stringWithFormat: @"%s\n",
860 p_intf->p_sys->p_sub->p_msg[i_start].psz_msg];
861 o_msg_color = [[NSAttributedString alloc]
862 initWithString: o_msg attributes: o_attr];
863 [o_msg_arr addObject: [o_msg_color autorelease]];
869 NSString *o_my_msg = [NSString stringWithFormat: @"%s: %s\n",
870 p_intf->p_sys->p_sub->p_msg[i_start].psz_module,
871 p_intf->p_sys->p_sub->p_msg[i_start].psz_msg];
873 NSRange s_r = NSMakeRange( [[o_err_msg string] length], 0 );
874 [o_err_msg setEditable: YES];
875 [o_err_msg setSelectedRange: s_r];
876 [o_err_msg insertText: o_my_msg];
878 [o_error makeKeyAndOrderFront: self];
879 [o_err_msg setEditable: NO];
883 vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
884 p_intf->p_sys->p_sub->i_start = i_start;
885 vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
889 - (void)playStatusUpdated:(BOOL)b_pause
893 [o_btn_play setImage: o_img_pause];
894 [o_btn_play setToolTip: _NS("Pause")];
895 [o_mi_play setTitle: _NS("Pause")];
896 [o_dmi_play setTitle: _NS("Pause")];
900 [o_btn_play setImage: o_img_play];
901 [o_btn_play setToolTip: _NS("Play")];
902 [o_mi_play setTitle: _NS("Play")];
903 [o_dmi_play setTitle: _NS("Play")];
907 - (void)setSubmenusEnabled:(BOOL)b_enabled
909 [o_mi_program setEnabled: b_enabled];
910 [o_mi_title setEnabled: b_enabled];
911 [o_mi_chapter setEnabled: b_enabled];
912 [o_mi_audiotrack setEnabled: b_enabled];
913 [o_mi_videotrack setEnabled: b_enabled];
914 [o_mi_subtitle setEnabled: b_enabled];
915 [o_mi_channels setEnabled: b_enabled];
916 [o_mi_device setEnabled: b_enabled];
917 [o_mi_screen setEnabled: b_enabled];
920 - (void)manageVolumeSlider
922 audio_volume_t i_volume;
923 intf_thread_t * p_intf = [NSApp getIntf];
925 aout_VolumeGet( p_intf, &i_volume );
927 [o_volumeslider setFloatValue: (float)i_volume / AOUT_VOLUME_STEP];
928 [o_volumeslider setEnabled: 1];
930 p_intf->p_sys->b_mute = ( i_volume == 0 );
936 vout_thread_t * p_vout;
937 playlist_t * p_playlist;
938 intf_thread_t * p_intf = [NSApp getIntf];
943 msg_Dbg( p_intf, "removing all playlists" );
944 while( (p_playlist = vlc_object_find( p_intf->p_vlc, VLC_OBJECT_PLAYLIST,
947 vlc_object_detach( p_playlist );
948 vlc_object_release( p_playlist );
949 playlist_Destroy( p_playlist );
955 msg_Dbg( p_intf, "removing all video outputs" );
956 while( (p_vout = vlc_object_find( p_intf->p_vlc,
957 VLC_OBJECT_VOUT, FIND_CHILD )) )
959 vlc_object_detach( p_vout );
960 vlc_object_release( p_vout );
961 vout_Destroy( p_vout );
964 if( o_img_pause != nil )
966 [o_img_pause release];
970 if( o_img_play != nil )
972 [o_img_play release];
976 if( o_msg_arr != nil )
978 [o_msg_arr removeAllObjects];
983 if( o_msg_lock != nil )
985 [o_msg_lock release];
997 /* write cached user defaults to disk */
998 [[NSUserDefaults standardUserDefaults] synchronize];
1000 /* send a dummy event to break out of the event loop */
1001 o_event = [NSEvent mouseEventWithType: NSLeftMouseDown
1002 location: NSMakePoint( 1, 1 ) modifierFlags: 0
1003 timestamp: 1 windowNumber: [[NSApp mainWindow] windowNumber]
1004 context: [NSGraphicsContext currentContext] eventNumber: 1
1005 clickCount: 1 pressure: 0.0];
1006 [NSApp postEvent: o_event atStart: YES];
1009 - (void)setupMenus:(input_thread_t *)p_input
1011 intf_thread_t * p_intf = [NSApp getIntf];
1013 p_intf->p_sys->b_chapter_update |= p_intf->p_sys->b_title_update;
1014 p_intf->p_sys->b_audio_update |= p_intf->p_sys->b_title_update |
1015 p_intf->p_sys->b_program_update;
1016 p_intf->p_sys->b_spu_update |= p_intf->p_sys->b_title_update |
1017 p_intf->p_sys->b_program_update;
1018 p_intf->p_sys->b_video_update |= p_intf->p_sys->b_program_update |
1019 p_intf->p_sys->b_program_update;
1021 if( p_intf->p_sys->b_program_update )
1023 [self setupVarMenu: o_mi_program target: (vlc_object_t *)p_input
1024 var: "program" selector: @selector(toggleVar:)];
1026 p_intf->p_sys->b_program_update = 0;
1029 if( p_intf->p_sys->b_title_update )
1031 [self setupVarMenu: o_mi_title target: (vlc_object_t *)p_input
1032 var: "title" selector: @selector(toggleVar:)];
1034 p_intf->p_sys->b_title_update = 0;
1037 if( p_intf->p_sys->b_chapter_update )
1039 [self setupVarMenu: o_mi_chapter target: (vlc_object_t *)p_input
1040 var: "chapter" selector: @selector(toggleVar:)];\
1042 p_intf->p_sys->i_part = p_input->stream.p_selected_area->i_part;
1043 p_intf->p_sys->b_chapter_update = 0;
1046 if( p_intf->p_sys->b_audio_update )
1048 [self setupVarMenu: o_mi_audiotrack target: (vlc_object_t *)p_input
1049 var: "audio-es" selector: @selector(toggleVar:)];
1051 p_intf->p_sys->b_audio_update = 0;
1054 if( p_intf->p_sys->b_video_update )
1056 [self setupVarMenu: o_mi_videotrack target: (vlc_object_t *)p_input
1057 var: "video-es" selector: @selector(toggleVar:)];
1059 p_intf->p_sys->b_video_update = 0;
1062 if( p_intf->p_sys->b_spu_update )
1064 [self setupVarMenu: o_mi_subtitle target: (vlc_object_t *)p_input
1065 var: "spu-es" selector: @selector(toggleVar:)];
1067 p_intf->p_sys->b_spu_update = 0;
1070 if ( p_intf->p_sys->b_aout_update )
1072 aout_instance_t * p_aout = vlc_object_find( p_intf, VLC_OBJECT_AOUT,
1075 if ( p_aout != NULL )
1080 [self setupVarMenu: o_mi_channels target: (vlc_object_t *)p_aout
1081 var: "audio-channels" selector: @selector(toggleVar:)];
1083 [self setupVarMenu: o_mi_device target: (vlc_object_t *)p_aout
1084 var: "audio-device" selector: @selector(toggleVar:)];
1085 var_Set( (vlc_object_t *)p_aout, "intf-change", val );
1087 vlc_object_release( (vlc_object_t *)p_aout );
1089 p_intf->p_sys->b_aout_update = 0;
1092 if( p_intf->p_sys->b_vout_update )
1094 vout_thread_t * p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
1097 if ( p_vout != NULL )
1102 [self setupVarMenu: o_mi_screen target: (vlc_object_t *)p_vout
1103 var: "video-device" selector: @selector(toggleVar:)];
1104 var_Set( (vlc_object_t *)p_vout, "intf-change", val );
1106 vlc_object_release( (vlc_object_t *)p_vout );
1107 [o_mi_close_window setEnabled: TRUE];
1110 p_intf->p_sys->b_vout_update = 0;
1114 - (void)setupVarMenu:(NSMenuItem *)o_mi
1115 target:(vlc_object_t *)p_object
1116 var:(const char *)psz_variable
1117 selector:(SEL)pf_callback
1119 int i, i_nb_items, i_value;
1120 NSMenu * o_menu = [o_mi submenu];
1121 vlc_value_t val, text;
1123 [o_mi setTag: (int)psz_variable];
1125 /* remove previous items */
1126 i_nb_items = [o_menu numberOfItems];
1127 for( i = 0; i < i_nb_items; i++ )
1129 [o_menu removeItemAtIndex: 0];
1132 if ( var_Get( p_object, psz_variable, &val ) < 0 )
1136 i_value = val.i_int;
1138 if ( var_Change( p_object, psz_variable,
1139 VLC_VAR_GETLIST, &val, &text ) < 0 )
1144 /* make (un)sensitive */
1145 [o_mi setEnabled: ( val.p_list->i_count > 1 )];
1147 for ( i = 0; i < val.p_list->i_count; i++ )
1151 NSLog(@"%d, %s", i_value, psz_variable);
1153 if ( text.p_list->p_values[i].psz_string )
1155 o_title = [NSApp localizedString: text.p_list->p_values[i].psz_string];
1159 o_title = [NSString stringWithFormat: @"%s - %d",
1160 strdup(psz_variable), val.p_list->p_values[i].i_int ];
1162 o_lmi = [o_menu addItemWithTitle: [o_title copy]
1163 action: pf_callback keyEquivalent: @""];
1165 /* FIXME: this isn't 64-bit clean ! */
1166 [o_lmi setTag: val.p_list->p_values[i].i_int];
1167 [o_lmi setRepresentedObject:
1168 [NSValue valueWithPointer: p_object]];
1169 [o_lmi setTarget: o_controls];
1171 if ( i_value == val.p_list->p_values[i].i_int )
1172 [o_lmi setState: NSOnState];
1175 var_Change( p_object, psz_variable, VLC_VAR_FREELIST,
1180 - (IBAction)clearRecentItems:(id)sender
1182 [[NSDocumentController sharedDocumentController]
1183 clearRecentDocuments: nil];
1186 - (void)openRecentItem:(id)sender
1188 [self application: nil openFile: [sender title]];
1191 - (IBAction)viewPreferences:(id)sender
1193 if( o_prefs == nil )
1195 o_prefs = [[VLCPrefs alloc] init];
1198 [o_prefs createPrefPanel: @"main"];
1201 - (IBAction)timesliderUpdate:(id)sender
1205 switch( [[NSApp currentEvent] type] )
1208 case NSLeftMouseDown:
1209 f_slider = [sender floatValue];
1212 case NSLeftMouseDragged:
1213 f_updated = [sender floatValue];
1220 intf_thread_t * p_intf = [NSApp getIntf];
1222 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1225 if( p_playlist == NULL )
1230 vlc_mutex_lock( &p_playlist->object_lock );
1232 if( p_playlist->p_input != NULL )
1236 char psz_time[ OFFSETTOTIME_MAX_SIZE ];
1238 #define p_area p_playlist->p_input->stream.p_selected_area
1239 vlc_mutex_lock( &p_playlist->p_input->stream.stream_lock );
1240 i_tell = f_updated / 10000. * p_area->i_size;
1241 input_OffsetToTime( p_playlist->p_input, psz_time, i_tell );
1242 vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
1245 o_time = [NSString stringWithCString: psz_time];
1246 [o_timefield setStringValue: o_time];
1249 vlc_mutex_unlock( &p_playlist->object_lock );
1250 vlc_object_release( p_playlist );
1253 - (IBAction)closeError:(id)sender
1255 [o_err_msg setString: @""];
1256 [o_error performClose: self];
1259 - (IBAction)openReadMe:(id)sender
1261 NSString * o_path = [[NSBundle mainBundle]
1262 pathForResource: @"README.MacOSX" ofType: @"rtf"];
1264 [[NSWorkspace sharedWorkspace] openFile: o_path
1265 withApplication: @"TextEdit"];
1268 - (IBAction)reportABug:(id)sender
1270 NSURL * o_url = [NSURL URLWithString:
1271 @"http://www.videolan.org/support/bug-reporting.html"];
1273 [[NSWorkspace sharedWorkspace] openURL: o_url];
1276 - (IBAction)openWebsite:(id)sender
1278 NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org"];
1280 [[NSWorkspace sharedWorkspace] openURL: o_url];
1283 - (IBAction)openLicense:(id)sender
1285 NSString * o_path = [[NSBundle mainBundle]
1286 pathForResource: @"COPYING" ofType: nil];
1288 [[NSWorkspace sharedWorkspace] openFile: o_path
1289 withApplication: @"TextEdit"];
1292 - (IBAction)openCrashLog:(id)sender
1294 NSString * o_path = [@"~/Library/Logs/CrashReporter/VLC.crash.log"
1295 stringByExpandingTildeInPath];
1298 if ( [[NSFileManager defaultManager] fileExistsAtPath: o_path ] )
1300 [[NSWorkspace sharedWorkspace] openFile: o_path
1301 withApplication: @"Console"];
1305 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.") );
1310 - (void)windowDidBecomeKey:(NSNotification *)o_notification
1312 if( [o_notification object] == o_msgs_panel )
1315 NSEnumerator * o_enum;
1317 [o_messages setString: @""];
1321 o_enum = [o_msg_arr objectEnumerator];
1323 while( ( o_msg = [o_enum nextObject] ) != nil )
1325 [o_messages insertText: o_msg];
1328 [o_msg_lock unlock];
1334 @implementation VLCMain (NSMenuValidation)
1336 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
1338 BOOL bEnabled = TRUE;
1340 /* Recent Items Menu */
1342 if( [[o_mi title] isEqualToString: _NS("Clear Menu")] )
1344 NSMenu * o_menu = [o_mi_open_recent submenu];
1345 int i_nb_items = [o_menu numberOfItems];
1346 NSArray * o_docs = [[NSDocumentController sharedDocumentController]
1347 recentDocumentURLs];
1348 UInt32 i_nb_docs = [o_docs count];
1350 if( i_nb_items > 1 )
1352 while( --i_nb_items )
1354 [o_menu removeItemAtIndex: 0];
1363 [o_menu insertItem: [NSMenuItem separatorItem] atIndex: 0];
1369 o_url = [o_docs objectAtIndex: i_nb_docs];
1371 if( [o_url isFileURL] )
1373 o_doc = [o_url path];
1377 o_doc = [o_url absoluteString];
1380 [o_menu insertItemWithTitle: o_doc
1381 action: @selector(openRecentItem:)
1382 keyEquivalent: @"" atIndex: 0];
1384 if( i_nb_docs == 0 )
1401 @implementation VLCMain (Internal)
1403 - (void)handlePortMessage:(NSPortMessage *)o_msg
1408 NSInvocation * o_inv;
1409 NSConditionLock * o_lock;
1411 o_data = [[o_msg components] lastObject];
1412 o_inv = *((NSInvocation **)[o_data bytes]);
1413 [o_inv getArgument: &o_value atIndex: 2];
1414 val = (id **)[o_value pointerValue];
1415 [o_inv setArgument: val[1] atIndex: 2];
1420 [o_lock unlockWithCondition: 1];