1 /*****************************************************************************
2 * intf.m: MacOS X interface plugin
3 *****************************************************************************
4 * Copyright (C) 2002-2003 VideoLAN
5 * $Id: intf.m,v 1.76 2003/05/08 01:16:57 hartman 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_mi_title setTitle: _NS("Title")];
333 [o_mi_chapter setTitle: _NS("Chapter")];
335 [o_mu_audio setTitle: _NS("Audio")];
336 [o_mi_vol_up setTitle: _NS("Volume Up")];
337 [o_mi_vol_down setTitle: _NS("Volume Down")];
338 [o_mi_mute setTitle: _NS("Mute")];
339 [o_mi_audiotrack setTitle: _NS("Audio Track")];
340 [o_mi_channels setTitle: _NS("Channels")];
341 [o_mi_device setTitle: _NS("Device")];
343 [o_mu_video setTitle: _NS("Video")];
344 [o_mi_half_window setTitle: _NS("Half Size")];
345 [o_mi_normal_window setTitle: _NS("Normal Size")];
346 [o_mi_double_window setTitle: _NS("Double Size")];
347 [o_mi_fittoscreen setTitle: _NS("Fit To Screen")];
348 [o_mi_fullscreen setTitle: _NS("Fullscreen")];
349 [o_mi_floatontop setTitle: _NS("Float On Top")];
350 [o_mi_videotrack setTitle: _NS("Video Track")];
351 [o_mi_screen setTitle: _NS("Screen")];
352 [o_mi_subtitle setTitle: _NS("Subtitles")];
353 [o_mi_deinterlace setTitle: _NS("Deinterlace")];
354 [o_mu_deinterlace setTitle: _NS("Deinterlace")];
356 [o_mu_window setTitle: _NS("Window")];
357 [o_mi_minimize setTitle: _NS("Minimize Window")];
358 [o_mi_close_window setTitle: _NS("Close Window")];
359 [o_mi_controller setTitle: _NS("Controller")];
360 [o_mi_playlist setTitle: _NS("Playlist")];
361 [o_mi_info setTitle: _NS("Info")];
362 [o_mi_messages setTitle: _NS("Messages")];
364 [o_mi_bring_atf setTitle: _NS("Bring All to Front")];
366 [o_mu_help setTitle: _NS("Help")];
367 [o_mi_readme setTitle: _NS("ReadMe...")];
368 [o_mi_reportabug setTitle: _NS("Report a Bug")];
369 [o_mi_website setTitle: _NS("VideoLAN Website")];
370 [o_mi_license setTitle: _NS("License")];
373 [o_dmi_play setTitle: _NS("Play")];
374 [o_dmi_stop setTitle: _NS("Stop")];
375 [o_dmi_next setTitle: _NS("Next")];
376 [o_dmi_previous setTitle: _NS("Previous")];
379 [o_error setTitle: _NS("Error")];
380 [o_err_lbl setStringValue: _NS("An error has occurred which probably prevented the execution of your request:")];
381 [o_err_bug_lbl setStringValue: _NS("If you believe that it is a bug, please follow the instructions at:")];
382 [o_err_btn_msgs setTitle: _NS("Open Messages Window")];
383 [o_err_btn_dismiss setTitle: _NS("Dismiss")];
385 [o_info_window setTitle: _NS("Info")];
387 [self setSubmenusEnabled: FALSE];
388 [self manageVolumeSlider];
391 - (void)applicationWillFinishLaunching:(NSNotification *)o_notification
393 intf_thread_t * p_intf = [NSApp getIntf];
395 o_msg_lock = [[NSLock alloc] init];
396 o_msg_arr = [[NSMutableArray arrayWithCapacity: 200] retain];
398 o_img_play = [[NSImage imageNamed: @"play"] retain];
399 o_img_pause = [[NSImage imageNamed: @"pause"] retain];
401 [p_intf->p_sys->o_sendport setDelegate: self];
402 [[NSRunLoop currentRunLoop]
403 addPort: p_intf->p_sys->o_sendport
404 forMode: NSDefaultRunLoopMode];
406 [NSTimer scheduledTimerWithTimeInterval: 0.5
407 target: self selector: @selector(manageIntf:)
408 userInfo: nil repeats: FALSE];
410 [NSThread detachNewThreadSelector: @selector(manage)
411 toTarget: self withObject: nil];
413 vlc_thread_set_priority( p_intf, VLC_THREAD_PRIORITY_LOW );
416 - (BOOL)application:(NSApplication *)o_app openFile:(NSString *)o_filename
418 intf_thread_t * p_intf = [NSApp getIntf];
420 [o_playlist appendArray:
421 [NSArray arrayWithObject: o_filename] atPos: -1 enqueue: NO];
423 config_PutPsz( [NSApp getIntf], "sub-file", "" );
424 config_PutInt( p_intf, "sub-delay", 0 );
425 config_PutFloat( p_intf, "sub-fps", 0.0 );
426 config_PutPsz( p_intf, "sout", "" );
442 NSDate * o_sleep_date;
443 intf_thread_t * p_intf = [NSApp getIntf];
444 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
446 vlc_thread_set_priority( p_intf, VLC_THREAD_PRIORITY_LOW );
448 while( !p_intf->b_die )
450 playlist_t * p_playlist;
452 vlc_mutex_lock( &p_intf->change_lock );
454 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
457 if( p_playlist != NULL )
459 vlc_mutex_lock( &p_playlist->object_lock );
461 [self manage: p_playlist];
463 vlc_mutex_unlock( &p_playlist->object_lock );
464 vlc_object_release( p_playlist );
467 vlc_mutex_unlock( &p_intf->change_lock );
469 o_sleep_date = [NSDate dateWithTimeIntervalSinceNow: .5];
470 [NSThread sleepUntilDate: o_sleep_date];
478 - (void)manage:(playlist_t *)p_playlist
482 intf_thread_t * p_intf = [NSApp getIntf];
484 if( var_Get( (vlc_object_t *)p_playlist, "intf-change", &val ) >= 0 &&
487 p_intf->p_sys->b_playlist_update = VLC_TRUE;
488 p_intf->p_sys->b_intf_update = VLC_TRUE;
491 #define p_input p_playlist->p_input
495 vout_thread_t * p_vout = NULL;
496 aout_instance_t * p_aout = NULL;
497 vlc_bool_t b_need_menus = VLC_FALSE;
499 vlc_mutex_lock( &p_input->stream.stream_lock );
501 if( !p_input->b_die )
503 audio_volume_t i_volume;
505 /* New input or stream map change */
506 if( p_input->stream.b_changed )
508 p_intf->p_sys->b_playing = 1;
509 [self manageMode: p_playlist];
510 b_need_menus = VLC_TRUE;
513 if( p_intf->p_sys->i_part !=
514 p_input->stream.p_selected_area->i_part )
516 p_intf->p_sys->b_chapter_update = 1;
517 b_need_menus = VLC_TRUE;
520 p_aout = vlc_object_find( p_intf, VLC_OBJECT_AOUT,
526 if( var_Get( (vlc_object_t *)p_aout, "intf-change", &val )
529 p_intf->p_sys->b_aout_update = 1;
530 b_need_menus = VLC_TRUE;
533 vlc_object_release( (vlc_object_t *)p_aout );
536 aout_VolumeGet( p_intf, &i_volume );
537 p_intf->p_sys->b_mute = ( i_volume == 0 );
539 p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
545 if( var_Get( (vlc_object_t *)p_vout, "intf-change", &val )
548 p_intf->p_sys->b_vout_update = 1;
549 b_need_menus = VLC_TRUE;
552 vlc_object_release( (vlc_object_t *)p_vout );
557 [self setupMenus: p_input];
561 vlc_mutex_unlock( &p_input->stream.stream_lock );
563 else if( p_intf->p_sys->b_playing && !p_intf->b_die )
565 p_intf->p_sys->b_playing = 0;
566 [self manageMode: p_playlist];
572 - (void)manageMode:(playlist_t *)p_playlist
574 intf_thread_t * p_intf = [NSApp getIntf];
576 if( p_playlist->p_input != NULL )
578 /* get ready for menu regeneration */
579 p_intf->p_sys->b_program_update = 1;
580 p_intf->p_sys->b_title_update = 1;
581 p_intf->p_sys->b_chapter_update = 1;
582 p_intf->p_sys->b_audio_update = 1;
583 p_intf->p_sys->b_video_update = 1;
584 p_intf->p_sys->b_spu_update = 1;
585 p_intf->p_sys->b_current_title_update = 1;
586 p_intf->p_sys->i_part = 0;
588 p_playlist->p_input->stream.b_changed = 0;
590 msg_Dbg( p_intf, "stream has changed, refreshing interface" );
594 vout_thread_t * p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
598 vlc_object_detach( p_vout );
599 vlc_object_release( p_vout );
601 vlc_mutex_unlock( &p_playlist->object_lock );
602 vout_Destroy( p_vout );
603 vlc_mutex_lock( &p_playlist->object_lock );
607 p_intf->p_sys->b_intf_update = VLC_TRUE;
610 - (void)manageIntf:(NSTimer *)o_timer
612 intf_thread_t * p_intf = [NSApp getIntf];
614 if( p_intf->p_vlc->b_die == VLC_TRUE )
616 [o_timer invalidate];
620 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
623 if( p_playlist == NULL )
628 if ( p_intf->p_sys->b_playlist_update )
633 var_Set( (vlc_object_t *)p_playlist, "intf-change", val );
635 [o_playlist playlistUpdated];
637 p_intf->p_sys->b_playlist_update = VLC_FALSE;
640 if( p_intf->p_sys->b_current_title_update )
642 vout_thread_t *p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
647 NSEnumerator * o_enum = [[NSApp windows] objectEnumerator];
649 while( ( o_vout_wnd = [o_enum nextObject] ) )
651 if( [[o_vout_wnd className] isEqualToString: @"VLCWindow"] )
653 [o_vout_wnd updateTitle];
656 vlc_object_release( (vlc_object_t *)p_vout );
658 [o_playlist updateRowSelection];
661 p_intf->p_sys->b_current_title_update = FALSE;
664 vlc_mutex_lock( &p_playlist->object_lock );
666 #define p_input p_playlist->p_input
668 if( p_input != NULL )
670 vlc_mutex_lock( &p_input->stream.stream_lock );
673 if( p_intf->p_sys->b_intf_update )
675 vlc_bool_t b_input = VLC_FALSE;
676 vlc_bool_t b_plmul = VLC_FALSE;
677 vlc_bool_t b_control = VLC_FALSE;
678 vlc_bool_t b_seekable = VLC_FALSE;
679 vlc_bool_t b_chapters = VLC_FALSE;
681 b_plmul = p_playlist->i_size > 1;
683 if( ( b_input = ( p_input != NULL ) ) )
685 /* seekable streams */
686 b_seekable = p_input->stream.b_seekable;
688 /* control buttons for free pace streams */
689 b_control = p_input->stream.b_pace_control;
692 b_chapters = p_input->stream.p_selected_area->i_part_nb > 1;
695 p_intf->p_sys->b_play_status =
696 p_input->stream.control.i_status != PAUSE_S;
701 p_intf->p_sys->b_play_status = VLC_FALSE;
703 [self setSubmenusEnabled: FALSE];
706 [self playStatusUpdated: p_intf->p_sys->b_play_status];
708 [o_btn_stop setEnabled: b_input];
709 [o_btn_faster setEnabled: b_control];
710 [o_btn_slower setEnabled: b_control];
711 [o_btn_prev setEnabled: (b_plmul || b_chapters)];
712 [o_btn_next setEnabled: (b_plmul || b_chapters)];
714 [o_timeslider setFloatValue: 0.0];
715 [o_timeslider setEnabled: b_seekable];
716 [o_timefield setStringValue: @"0:00:00"];
718 [self manageVolumeSlider];
720 p_intf->p_sys->b_intf_update = VLC_FALSE;
723 #define p_area p_input->stream.p_selected_area
725 if( p_intf->p_sys->b_playing && p_input != NULL )
727 vlc_bool_t b_field_update = VLC_TRUE;
729 if( !p_input->b_die && ( p_intf->p_sys->b_play_status !=
730 ( p_input->stream.control.i_status != PAUSE_S ) ) )
732 p_intf->p_sys->b_play_status =
733 !p_intf->p_sys->b_play_status;
735 [self playStatusUpdated: p_intf->p_sys->b_play_status];
738 if( p_input->stream.b_seekable )
740 if( f_slider == f_slider_old )
742 float f_updated = ( 10000. * p_area->i_tell ) /
745 if( f_slider != f_updated )
747 [o_timeslider setFloatValue: f_updated];
752 off_t i_seek = ( f_slider * p_area->i_size ) / 10000;
754 /* release the lock to be able to seek */
755 vlc_mutex_unlock( &p_input->stream.stream_lock );
756 input_Seek( p_input, i_seek, INPUT_SEEK_SET );
757 vlc_mutex_lock( &p_input->stream.stream_lock );
759 /* update the old value */
760 f_slider_old = f_slider;
762 b_field_update = VLC_FALSE;
769 char psz_time[ OFFSETTOTIME_MAX_SIZE ];
771 input_OffsetToTime( p_input, psz_time, p_area->i_tell );
773 o_time = [NSString stringWithCString: psz_time];
774 [o_timefield setStringValue: o_time];
777 /* disable screen saver */
778 UpdateSystemActivity( UsrActivity );
783 if( p_input != NULL )
785 vlc_mutex_unlock( &p_input->stream.stream_lock );
790 vlc_mutex_unlock( &p_playlist->object_lock );
791 vlc_object_release( p_playlist );
793 [self updateMessageArray];
795 [NSTimer scheduledTimerWithTimeInterval: 0.5
796 target: self selector: @selector(manageIntf:)
797 userInfo: nil repeats: FALSE];
800 - (void)updateMessageArray
803 intf_thread_t * p_intf = [NSApp getIntf];
805 vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
806 i_stop = *p_intf->p_sys->p_sub->pi_stop;
807 vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
809 if( p_intf->p_sys->p_sub->i_start != i_stop )
811 NSColor *o_white = [NSColor whiteColor];
812 NSColor *o_red = [NSColor redColor];
813 NSColor *o_yellow = [NSColor yellowColor];
814 NSColor *o_gray = [NSColor grayColor];
816 NSColor * pp_color[4] = { o_white, o_red, o_yellow, o_gray };
817 static const char * ppsz_type[4] = { ": ", " error: ",
818 " warning: ", " debug: " };
820 for( i_start = p_intf->p_sys->p_sub->i_start;
822 i_start = (i_start+1) % VLC_MSG_QSIZE )
825 NSDictionary *o_attr;
826 NSAttributedString *o_msg_color;
828 int i_type = p_intf->p_sys->p_sub->p_msg[i_start].i_type;
832 if( [o_msg_arr count] + 2 > 400 )
834 unsigned rid[] = { 0, 1 };
835 [o_msg_arr removeObjectsFromIndices: (unsigned *)&rid
836 numIndices: sizeof(rid)/sizeof(rid[0])];
839 o_attr = [NSDictionary dictionaryWithObject: o_gray
840 forKey: NSForegroundColorAttributeName];
841 o_msg = [NSString stringWithFormat: @"%s%s",
842 p_intf->p_sys->p_sub->p_msg[i_start].psz_module,
844 o_msg_color = [[NSAttributedString alloc]
845 initWithString: o_msg attributes: o_attr];
846 [o_msg_arr addObject: [o_msg_color autorelease]];
848 o_attr = [NSDictionary dictionaryWithObject: pp_color[i_type]
849 forKey: NSForegroundColorAttributeName];
850 o_msg = [NSString stringWithFormat: @"%s\n",
851 p_intf->p_sys->p_sub->p_msg[i_start].psz_msg];
852 o_msg_color = [[NSAttributedString alloc]
853 initWithString: o_msg attributes: o_attr];
854 [o_msg_arr addObject: [o_msg_color autorelease]];
860 NSString *o_my_msg = [NSString stringWithFormat: @"%s: %s\n",
861 p_intf->p_sys->p_sub->p_msg[i_start].psz_module,
862 p_intf->p_sys->p_sub->p_msg[i_start].psz_msg];
864 NSRange s_r = NSMakeRange( [[o_err_msg string] length], 0 );
865 [o_err_msg setEditable: YES];
866 [o_err_msg setSelectedRange: s_r];
867 [o_err_msg insertText: o_my_msg];
869 [o_error makeKeyAndOrderFront: self];
870 [o_err_msg setEditable: NO];
874 vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
875 p_intf->p_sys->p_sub->i_start = i_start;
876 vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
880 - (void)playStatusUpdated:(BOOL)b_pause
884 [o_btn_play setImage: o_img_pause];
885 [o_btn_play setToolTip: _NS("Pause")];
886 [o_mi_play setTitle: _NS("Pause")];
887 [o_dmi_play setTitle: _NS("Pause")];
891 [o_btn_play setImage: o_img_play];
892 [o_btn_play setToolTip: _NS("Play")];
893 [o_mi_play setTitle: _NS("Play")];
894 [o_dmi_play setTitle: _NS("Play")];
898 - (void)setSubmenusEnabled:(BOOL)b_enabled
900 [o_mi_program setEnabled: b_enabled];
901 [o_mi_title setEnabled: b_enabled];
902 [o_mi_chapter setEnabled: b_enabled];
903 [o_mi_audiotrack setEnabled: b_enabled];
904 [o_mi_videotrack setEnabled: b_enabled];
905 [o_mi_subtitle setEnabled: b_enabled];
906 [o_mi_channels setEnabled: b_enabled];
907 [o_mi_device setEnabled: b_enabled];
908 [o_mi_screen setEnabled: b_enabled];
911 - (void)manageVolumeSlider
913 audio_volume_t i_volume;
914 intf_thread_t * p_intf = [NSApp getIntf];
916 aout_VolumeGet( p_intf, &i_volume );
918 [o_volumeslider setFloatValue: (float)i_volume / AOUT_VOLUME_STEP];
919 [o_volumeslider setEnabled: 1];
921 p_intf->p_sys->b_mute = ( i_volume == 0 );
927 vout_thread_t * p_vout;
928 playlist_t * p_playlist;
929 intf_thread_t * p_intf = [NSApp getIntf];
934 msg_Dbg( p_intf, "removing all playlists" );
935 while( (p_playlist = vlc_object_find( p_intf->p_vlc, VLC_OBJECT_PLAYLIST,
938 vlc_object_detach( p_playlist );
939 vlc_object_release( p_playlist );
940 playlist_Destroy( p_playlist );
946 msg_Dbg( p_intf, "removing all video outputs" );
947 while( (p_vout = vlc_object_find( p_intf->p_vlc,
948 VLC_OBJECT_VOUT, FIND_CHILD )) )
950 vlc_object_detach( p_vout );
951 vlc_object_release( p_vout );
952 vout_Destroy( p_vout );
955 if( o_img_pause != nil )
957 [o_img_pause release];
961 if( o_img_play != nil )
963 [o_img_play release];
967 if( o_msg_arr != nil )
969 [o_msg_arr removeAllObjects];
974 if( o_msg_lock != nil )
976 [o_msg_lock release];
988 /* write cached user defaults to disk */
989 [[NSUserDefaults standardUserDefaults] synchronize];
991 /* send a dummy event to break out of the event loop */
992 o_event = [NSEvent mouseEventWithType: NSLeftMouseDown
993 location: NSMakePoint( 1, 1 ) modifierFlags: 0
994 timestamp: 1 windowNumber: [[NSApp mainWindow] windowNumber]
995 context: [NSGraphicsContext currentContext] eventNumber: 1
996 clickCount: 1 pressure: 0.0];
997 [NSApp postEvent: o_event atStart: YES];
1000 - (void)setupMenus:(input_thread_t *)p_input
1002 intf_thread_t * p_intf = [NSApp getIntf];
1004 p_intf->p_sys->b_chapter_update |= p_intf->p_sys->b_title_update;
1005 p_intf->p_sys->b_audio_update |= p_intf->p_sys->b_title_update |
1006 p_intf->p_sys->b_program_update;
1007 p_intf->p_sys->b_spu_update |= p_intf->p_sys->b_title_update |
1008 p_intf->p_sys->b_program_update;
1009 p_intf->p_sys->b_video_update |= p_intf->p_sys->b_program_update |
1010 p_intf->p_sys->b_program_update;
1012 if( p_intf->p_sys->b_program_update )
1014 [self setupVarMenu: o_mi_program target: (vlc_object_t *)p_input
1015 var: "program" selector: @selector(toggleVar:)];
1017 p_intf->p_sys->b_program_update = 0;
1020 if( p_intf->p_sys->b_title_update )
1022 [self setupVarMenu: o_mi_title target: (vlc_object_t *)p_input
1023 var: "title" selector: @selector(toggleVar:)];
1025 p_intf->p_sys->b_title_update = 0;
1028 if( p_intf->p_sys->b_chapter_update )
1030 [self setupVarMenu: o_mi_chapter target: (vlc_object_t *)p_input
1031 var: "chapter" selector: @selector(toggleVar:)];\
1033 p_intf->p_sys->i_part = p_input->stream.p_selected_area->i_part;
1034 p_intf->p_sys->b_chapter_update = 0;
1037 if( p_intf->p_sys->b_audio_update )
1039 [self setupVarMenu: o_mi_audiotrack target: (vlc_object_t *)p_input
1040 var: "audio-es" selector: @selector(toggleVar:)];
1042 p_intf->p_sys->b_audio_update = 0;
1045 if( p_intf->p_sys->b_video_update )
1047 [self setupVarMenu: o_mi_videotrack target: (vlc_object_t *)p_input
1048 var: "video-es" selector: @selector(toggleVar:)];
1050 p_intf->p_sys->b_video_update = 0;
1053 if( p_intf->p_sys->b_spu_update )
1055 [self setupVarMenu: o_mi_subtitle target: (vlc_object_t *)p_input
1056 var: "spu-es" selector: @selector(toggleVar:)];
1058 p_intf->p_sys->b_spu_update = 0;
1061 if ( p_intf->p_sys->b_aout_update )
1063 aout_instance_t * p_aout = vlc_object_find( p_intf, VLC_OBJECT_AOUT,
1066 if ( p_aout != NULL )
1071 [self setupVarMenu: o_mi_channels target: (vlc_object_t *)p_aout
1072 var: "audio-channels" selector: @selector(toggleVar:)];
1074 [self setupVarMenu: o_mi_device target: (vlc_object_t *)p_aout
1075 var: "audio-device" selector: @selector(toggleVar:)];
1076 var_Set( (vlc_object_t *)p_aout, "intf-change", val );
1078 vlc_object_release( (vlc_object_t *)p_aout );
1080 p_intf->p_sys->b_aout_update = 0;
1083 if( p_intf->p_sys->b_vout_update )
1085 vout_thread_t * p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
1088 if ( p_vout != NULL )
1093 [self setupVarMenu: o_mi_screen target: (vlc_object_t *)p_vout
1094 var: "video-device" selector: @selector(toggleVar:)];
1095 var_Set( (vlc_object_t *)p_vout, "intf-change", val );
1097 vlc_object_release( (vlc_object_t *)p_vout );
1098 [o_mi_close_window setEnabled: TRUE];
1101 p_intf->p_sys->b_vout_update = 0;
1105 - (void)setupVarMenu:(NSMenuItem *)o_mi
1106 target:(vlc_object_t *)p_object
1107 var:(const char *)psz_variable
1108 selector:(SEL)pf_callback
1110 int i, i_nb_items, i_value;
1111 NSMenu * o_menu = [o_mi submenu];
1112 vlc_value_t val, text;
1114 [o_mi setTag: (int)psz_variable];
1116 /* remove previous items */
1117 i_nb_items = [o_menu numberOfItems];
1118 for( i = 0; i < i_nb_items; i++ )
1120 [o_menu removeItemAtIndex: 0];
1123 if ( var_Get( p_object, psz_variable, &val ) < 0 )
1127 i_value = val.i_int;
1129 if ( var_Change( p_object, psz_variable,
1130 VLC_VAR_GETLIST, &val, &text ) < 0 )
1135 /* make (un)sensitive */
1136 [o_mi setEnabled: ( val.p_list->i_count > 1 )];
1138 for ( i = 0; i < val.p_list->i_count; i++ )
1142 NSLog(@"%d, %s", i_value, psz_variable);
1144 if ( text.p_list->p_values[i].psz_string )
1146 o_title = [NSApp localizedString: text.p_list->p_values[i].psz_string];
1150 o_title = [NSString stringWithFormat: @"%s - %d",
1151 strdup(psz_variable), val.p_list->p_values[i].i_int ];
1153 o_lmi = [o_menu addItemWithTitle: [o_title copy]
1154 action: pf_callback keyEquivalent: @""];
1156 /* FIXME: this isn't 64-bit clean ! */
1157 [o_lmi setTag: val.p_list->p_values[i].i_int];
1158 [o_lmi setRepresentedObject:
1159 [NSValue valueWithPointer: p_object]];
1160 [o_lmi setTarget: o_controls];
1162 if ( i_value == val.p_list->p_values[i].i_int )
1163 [o_lmi setState: NSOnState];
1166 var_Change( p_object, psz_variable, VLC_VAR_FREELIST,
1171 - (IBAction)clearRecentItems:(id)sender
1173 [[NSDocumentController sharedDocumentController]
1174 clearRecentDocuments: nil];
1177 - (void)openRecentItem:(id)sender
1179 [self application: nil openFile: [sender title]];
1182 - (IBAction)viewPreferences:(id)sender
1184 if( o_prefs == nil )
1186 o_prefs = [[VLCPrefs alloc] init];
1189 [o_prefs createPrefPanel: @"main"];
1192 - (IBAction)timesliderUpdate:(id)sender
1196 switch( [[NSApp currentEvent] type] )
1199 case NSLeftMouseDown:
1200 f_slider = [sender floatValue];
1203 case NSLeftMouseDragged:
1204 f_updated = [sender floatValue];
1211 intf_thread_t * p_intf = [NSApp getIntf];
1213 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1216 if( p_playlist == NULL )
1221 vlc_mutex_lock( &p_playlist->object_lock );
1223 if( p_playlist->p_input != NULL )
1227 char psz_time[ OFFSETTOTIME_MAX_SIZE ];
1229 #define p_area p_playlist->p_input->stream.p_selected_area
1230 vlc_mutex_lock( &p_playlist->p_input->stream.stream_lock );
1231 i_tell = f_updated / 10000. * p_area->i_size;
1232 input_OffsetToTime( p_playlist->p_input, psz_time, i_tell );
1233 vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
1236 o_time = [NSString stringWithCString: psz_time];
1237 [o_timefield setStringValue: o_time];
1240 vlc_mutex_unlock( &p_playlist->object_lock );
1241 vlc_object_release( p_playlist );
1244 - (IBAction)closeError:(id)sender
1246 [o_err_msg setString: @""];
1247 [o_error performClose: self];
1250 - (IBAction)openReadMe:(id)sender
1252 NSString * o_path = [[NSBundle mainBundle]
1253 pathForResource: @"README.MacOSX" ofType: @"rtf"];
1255 [[NSWorkspace sharedWorkspace] openFile: o_path
1256 withApplication: @"TextEdit"];
1259 - (IBAction)reportABug:(id)sender
1261 NSURL * o_url = [NSURL URLWithString:
1262 @"http://www.videolan.org/support/bug-reporting.html"];
1264 [[NSWorkspace sharedWorkspace] openURL: o_url];
1267 - (IBAction)openWebsite:(id)sender
1269 NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org"];
1271 [[NSWorkspace sharedWorkspace] openURL: o_url];
1274 - (IBAction)openLicense:(id)sender
1276 NSString * o_path = [[NSBundle mainBundle]
1277 pathForResource: @"COPYING" ofType: nil];
1279 [[NSWorkspace sharedWorkspace] openFile: o_path
1280 withApplication: @"TextEdit"];
1283 - (IBAction)openCrashLog:(id)sender
1285 NSString * o_path = [@"~/Library/Logs/CrashReporter/VLC.crash.log"
1286 stringByExpandingTildeInPath];
1289 if ( [[NSFileManager defaultManager] fileExistsAtPath: o_path ] )
1291 [[NSWorkspace sharedWorkspace] openFile: o_path
1292 withApplication: @"Console"];
1296 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.") );
1301 - (void)windowDidBecomeKey:(NSNotification *)o_notification
1303 if( [o_notification object] == o_msgs_panel )
1306 NSEnumerator * o_enum;
1308 [o_messages setString: @""];
1312 o_enum = [o_msg_arr objectEnumerator];
1314 while( ( o_msg = [o_enum nextObject] ) != nil )
1316 [o_messages insertText: o_msg];
1319 [o_msg_lock unlock];
1325 @implementation VLCMain (NSMenuValidation)
1327 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
1329 BOOL bEnabled = TRUE;
1331 /* Recent Items Menu */
1333 if( [[o_mi title] isEqualToString: _NS("Clear Menu")] )
1335 NSMenu * o_menu = [o_mi_open_recent submenu];
1336 int i_nb_items = [o_menu numberOfItems];
1337 NSArray * o_docs = [[NSDocumentController sharedDocumentController]
1338 recentDocumentURLs];
1339 UInt32 i_nb_docs = [o_docs count];
1341 if( i_nb_items > 1 )
1343 while( --i_nb_items )
1345 [o_menu removeItemAtIndex: 0];
1354 [o_menu insertItem: [NSMenuItem separatorItem] atIndex: 0];
1360 o_url = [o_docs objectAtIndex: i_nb_docs];
1362 if( [o_url isFileURL] )
1364 o_doc = [o_url path];
1368 o_doc = [o_url absoluteString];
1371 [o_menu insertItemWithTitle: o_doc
1372 action: @selector(openRecentItem:)
1373 keyEquivalent: @"" atIndex: 0];
1375 if( i_nb_docs == 0 )
1392 @implementation VLCMain (Internal)
1394 - (void)handlePortMessage:(NSPortMessage *)o_msg
1399 NSInvocation * o_inv;
1400 NSConditionLock * o_lock;
1402 o_data = [[o_msg components] lastObject];
1403 o_inv = *((NSInvocation **)[o_data bytes]);
1404 [o_inv getArgument: &o_value atIndex: 2];
1405 val = (id **)[o_value pointerValue];
1406 [o_inv setArgument: val[1] atIndex: 2];
1411 [o_lock unlockWithCondition: 1];