1 /*****************************************************************************
2 * intf.m: MacOS X interface plugin
3 *****************************************************************************
4 * Copyright (C) 2002-2003 VideoLAN
5 * $Id: intf.m,v 1.85 2003/05/20 18:53:03 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];
61 /* Put Cocoa into multithread mode as soon as possible.
62 * http://developer.apple.com/techpubs/macosx/Cocoa/
63 * TasksAndConcepts/ProgrammingTopics/Multithreading/index.html
64 * This thread does absolutely nothing at all. */
65 [NSThread detachNewThreadSelector:@selector(self) toTarget:[NSString string] withObject:nil];
67 p_intf->p_sys->o_sendport = [[NSPort port] retain];
68 p_intf->p_sys->p_sub = msg_Subscribe( p_intf );
71 [[VLCApplication sharedApplication] autorelease];
72 [NSApp initIntlSupport];
73 [NSApp setIntf: p_intf];
75 [NSBundle loadNibNamed: @"MainMenu" owner: NSApp];
80 /*****************************************************************************
81 * CloseIntf: destroy interface
82 *****************************************************************************/
83 void E_(CloseIntf) ( vlc_object_t *p_this )
85 intf_thread_t *p_intf = (intf_thread_t*) p_this;
87 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
89 [p_intf->p_sys->o_sendport release];
90 [p_intf->p_sys->o_pool release];
92 free( p_intf->p_sys );
95 /*****************************************************************************
97 *****************************************************************************/
98 static void Run( intf_thread_t *p_intf )
100 /* Do it again - for some unknown reason, vlc_thread_create() often
101 * fails to go to real-time priority with the first launched thread
103 vlc_thread_set_priority( p_intf, VLC_THREAD_PRIORITY_LOW );
108 /*****************************************************************************
109 * VLCApplication implementation
110 *****************************************************************************/
111 @implementation VLCApplication
115 /* default encoding: ISO-8859-1 */
116 i_encoding = NSISOLatin1StringEncoding;
118 return( [super init] );
121 - (void)initIntlSupport
123 char *psz_lang = getenv( "LANG" );
125 if( psz_lang == NULL )
130 if( strncmp( psz_lang, "pl", 2 ) == 0 )
132 i_encoding = NSISOLatin2StringEncoding;
134 else if( strncmp( psz_lang, "ja", 2 ) == 0 )
136 i_encoding = NSJapaneseEUCStringEncoding;
138 else if( strncmp( psz_lang, "ru", 2 ) == 0 )
140 #define CFSENC2NSSENC(e) CFStringConvertEncodingToNSStringEncoding(e)
141 i_encoding = CFSENC2NSSENC( kCFStringEncodingKOI8_R );
146 - (NSString *)localizedString:(char *)psz
148 NSString * o_str = nil;
152 UInt32 uiLength = (UInt32)strlen( psz );
153 NSData * o_data = [NSData dataWithBytes: psz length: uiLength];
154 o_str = [[[NSString alloc] initWithData: o_data
155 encoding: i_encoding] autorelease];
161 - (char *)delocalizeString:(NSString *)id
163 NSData * o_data = [id dataUsingEncoding: i_encoding
164 allowLossyConversion: NO];
169 o_data = [id dataUsingEncoding: i_encoding
170 allowLossyConversion: YES];
171 psz_string = malloc( [o_data length] + 1 );
172 [o_data getBytes: psz_string];
173 psz_string[ [o_data length] ] = '\0';
174 msg_Err( p_intf, "cannot convert to wanted encoding: %s",
179 psz_string = malloc( [o_data length] + 1 );
180 [o_data getBytes: psz_string];
181 psz_string[ [o_data length] ] = '\0';
187 - (NSStringEncoding)getEncoding
192 - (void)setIntf:(intf_thread_t *)_p_intf
197 - (intf_thread_t *)getIntf
202 - (void)terminate:(id)sender
204 p_intf->p_vlc->b_die = VLC_TRUE;
209 int ExecuteOnMainThread( id target, SEL sel, void * p_arg )
213 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
215 if( [target respondsToSelector: @selector(performSelectorOnMainThread:
216 withObject:waitUntilDone:)] )
218 [target performSelectorOnMainThread: sel
219 withObject: [NSValue valueWithPointer: p_arg]
222 else if( NSApp != nil && [NSApp respondsToSelector: @selector(getIntf)] )
227 NSPort * o_recv_port;
228 NSInvocation * o_inv;
229 NSPortMessage * o_msg;
230 intf_thread_t * p_intf;
231 NSConditionLock * o_lock;
232 NSMethodSignature * o_sig;
234 id * val[] = { &o_lock, &o_v2 };
236 p_intf = (intf_thread_t *)[NSApp getIntf];
238 o_recv_port = [[NSPort port] retain];
239 o_v1 = [NSValue valueWithPointer: val];
240 o_v2 = [NSValue valueWithPointer: p_arg];
242 o_sig = [target methodSignatureForSelector: sel];
243 o_inv = [NSInvocation invocationWithMethodSignature: o_sig];
244 [o_inv setArgument: &o_v1 atIndex: 2];
245 [o_inv setTarget: target];
246 [o_inv setSelector: sel];
248 o_array = [NSArray arrayWithObject:
249 [NSData dataWithBytes: &o_inv length: sizeof(o_inv)]];
250 o_msg = [[NSPortMessage alloc]
251 initWithSendPort: p_intf->p_sys->o_sendport
252 receivePort: o_recv_port components: o_array];
254 o_lock = [[NSConditionLock alloc] initWithCondition: 0];
255 [o_msg sendBeforeDate: [NSDate distantPast]];
256 [o_lock lockWhenCondition: 1];
261 [o_recv_port release];
273 /*****************************************************************************
274 * playlistChanged: Callback triggered by the intf-change playlist
275 * variable, to let the intf update the playlist.
276 *****************************************************************************/
277 int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,
278 vlc_value_t old_val, vlc_value_t new_val, void *param )
280 intf_thread_t * p_intf = [NSApp getIntf];
281 p_intf->p_sys->b_playlist_update = VLC_TRUE;
282 p_intf->p_sys->b_intf_update = VLC_TRUE;
286 /*****************************************************************************
287 * VLCMain implementation
288 *****************************************************************************/
289 @implementation VLCMain
293 [o_window setTitle: _NS("VLC - Controller")];
294 [o_window setExcludedFromWindowsMenu: TRUE];
296 /* button controls */
297 [o_btn_playlist setToolTip: _NS("Playlist")];
298 [o_btn_prev setToolTip: _NS("Previous")];
299 [o_btn_slower setToolTip: _NS("Slower")];
300 [o_btn_play setToolTip: _NS("Play")];
301 [o_btn_stop setToolTip: _NS("Stop")];
302 [o_btn_faster setToolTip: _NS("Faster")];
303 [o_btn_next setToolTip: _NS("Next")];
304 [o_btn_prefs setToolTip: _NS("Preferences")];
305 [o_volumeslider setToolTip: _NS("Volume")];
306 [o_timeslider setToolTip: _NS("Position")];
309 [o_msgs_panel setDelegate: self];
310 [o_msgs_panel setTitle: _NS("Messages")];
311 [o_msgs_panel setExcludedFromWindowsMenu: TRUE];
312 [o_msgs_btn_crashlog setTitle: _NS("Open CrashLog")];
315 [o_mi_about setTitle: _NS("About VLC media player")];
316 [o_mi_prefs setTitle: _NS("Preferences...")];
317 [o_mi_hide setTitle: _NS("Hide VLC")];
318 [o_mi_hide_others setTitle: _NS("Hide Others")];
319 [o_mi_show_all setTitle: _NS("Show All")];
320 [o_mi_quit setTitle: _NS("Quit VLC")];
322 [o_mu_file setTitle: _ANS("1:File")];
323 [o_mi_open_generic setTitle: _NS("Open...")];
324 [o_mi_open_file setTitle: _NS("Open File...")];
325 [o_mi_open_disc setTitle: _NS("Open Disc...")];
326 [o_mi_open_net setTitle: _NS("Open Network...")];
327 [o_mi_open_recent setTitle: _NS("Open Recent")];
328 [o_mi_open_recent_cm setTitle: _NS("Clear Menu")];
330 [o_mu_edit setTitle: _NS("Edit")];
331 [o_mi_cut setTitle: _NS("Cut")];
332 [o_mi_copy setTitle: _NS("Copy")];
333 [o_mi_paste setTitle: _NS("Paste")];
334 [o_mi_clear setTitle: _NS("Clear")];
335 [o_mi_select_all setTitle: _NS("Select All")];
337 [o_mu_controls setTitle: _NS("Controls")];
338 [o_mi_play setTitle: _NS("Play")];
339 [o_mi_stop setTitle: _NS("Stop")];
340 [o_mi_faster setTitle: _NS("Faster")];
341 [o_mi_slower setTitle: _NS("Slower")];
342 [o_mi_previous setTitle: _NS("Previous")];
343 [o_mi_next setTitle: _NS("Next")];
344 [o_mi_loop setTitle: _NS("Loop")];
345 [o_mi_fwd setTitle: _NS("Step Forward")];
346 [o_mi_bwd setTitle: _NS("Step Backward")];
347 [o_mi_program setTitle: _NS("Program")];
348 [o_mu_program setTitle: _NS("Program")];
349 [o_mi_title setTitle: _NS("Title")];
350 [o_mu_title setTitle: _NS("Title")];
351 [o_mi_chapter setTitle: _NS("Chapter")];
352 [o_mu_chapter setTitle: _NS("Chapter")];
354 [o_mu_audio setTitle: _NS("Audio")];
355 [o_mi_vol_up setTitle: _NS("Volume Up")];
356 [o_mi_vol_down setTitle: _NS("Volume Down")];
357 [o_mi_mute setTitle: _NS("Mute")];
358 [o_mi_audiotrack setTitle: _NS("Audio Track")];
359 [o_mu_audiotrack setTitle: _NS("Audio Track")];
360 [o_mi_channels setTitle: _NS("Channels")];
361 [o_mu_channels setTitle: _NS("Channels")];
362 [o_mi_device setTitle: _NS("Device")];
363 [o_mu_device setTitle: _NS("Device")];
365 [o_mu_video setTitle: _NS("Video")];
366 [o_mi_half_window setTitle: _NS("Half Size")];
367 [o_mi_normal_window setTitle: _NS("Normal Size")];
368 [o_mi_double_window setTitle: _NS("Double Size")];
369 [o_mi_fittoscreen setTitle: _NS("Fit To Screen")];
370 [o_mi_fullscreen setTitle: _NS("Fullscreen")];
371 [o_mi_floatontop setTitle: _NS("Float On Top")];
372 [o_mi_videotrack setTitle: _NS("Video Track")];
373 [o_mu_videotrack setTitle: _NS("Video Track")];
374 [o_mi_screen setTitle: _NS("Screen")];
375 [o_mu_screen setTitle: _NS("Screen")];
376 [o_mi_subtitle setTitle: _NS("Subtitles")];
377 [o_mu_subtitle setTitle: _NS("Subtitles")];
378 [o_mi_deinterlace setTitle: _NS("Deinterlace")];
379 [o_mu_deinterlace setTitle: _NS("Deinterlace")];
381 [o_mu_window setTitle: _NS("Window")];
382 [o_mi_minimize setTitle: _NS("Minimize Window")];
383 [o_mi_close_window setTitle: _NS("Close Window")];
384 [o_mi_controller setTitle: _NS("Controller")];
385 [o_mi_playlist setTitle: _NS("Playlist")];
386 [o_mi_info setTitle: _NS("Info")];
387 [o_mi_messages setTitle: _NS("Messages")];
389 [o_mi_bring_atf setTitle: _NS("Bring All to Front")];
391 [o_mu_help setTitle: _NS("Help")];
392 [o_mi_readme setTitle: _NS("ReadMe...")];
393 [o_mi_documentation setTitle: _NS("Online Documentation")];
394 [o_mi_reportabug setTitle: _NS("Report a Bug")];
395 [o_mi_website setTitle: _NS("VideoLAN Website")];
396 [o_mi_license setTitle: _NS("License")];
399 [o_dmi_play setTitle: _NS("Play")];
400 [o_dmi_stop setTitle: _NS("Stop")];
401 [o_dmi_next setTitle: _NS("Next")];
402 [o_dmi_previous setTitle: _NS("Previous")];
405 [o_error setTitle: _NS("Error")];
406 [o_err_lbl setStringValue: _NS("An error has occurred which probably prevented the execution of your request:")];
407 [o_err_bug_lbl setStringValue: _NS("If you believe that it is a bug, please follow the instructions at:")];
408 [o_err_btn_msgs setTitle: _NS("Open Messages Window")];
409 [o_err_btn_dismiss setTitle: _NS("Dismiss")];
411 [o_info_window setTitle: _NS("Info")];
413 [self setSubmenusEnabled: FALSE];
414 [self manageVolumeSlider];
417 - (void)applicationWillFinishLaunching:(NSNotification *)o_notification
419 intf_thread_t * p_intf = [NSApp getIntf];
421 o_msg_lock = [[NSLock alloc] init];
422 o_msg_arr = [[NSMutableArray arrayWithCapacity: 200] retain];
424 o_img_play = [[NSImage imageNamed: @"play"] retain];
425 o_img_pause = [[NSImage imageNamed: @"pause"] retain];
427 [p_intf->p_sys->o_sendport setDelegate: self];
428 [[NSRunLoop currentRunLoop]
429 addPort: p_intf->p_sys->o_sendport
430 forMode: NSDefaultRunLoopMode];
432 [NSTimer scheduledTimerWithTimeInterval: 0.5
433 target: self selector: @selector(manageIntf:)
434 userInfo: nil repeats: FALSE];
436 [NSThread detachNewThreadSelector: @selector(manage)
437 toTarget: self withObject: nil];
439 vlc_thread_set_priority( p_intf, VLC_THREAD_PRIORITY_LOW );
442 - (BOOL)application:(NSApplication *)o_app openFile:(NSString *)o_filename
444 intf_thread_t * p_intf = [NSApp getIntf];
446 config_PutPsz( p_intf, "sub-file", "" );
447 config_PutInt( p_intf, "sub-delay", 0 );
448 config_PutFloat( p_intf, "sub-fps", 0.0 );
449 config_PutPsz( p_intf, "sout", "" );
451 [o_playlist appendArray:
452 [NSArray arrayWithObject: o_filename] atPos: -1 enqueue: NO];
468 NSDate * o_sleep_date;
469 intf_thread_t * p_intf = [NSApp getIntf];
470 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
472 vlc_thread_set_priority( p_intf, VLC_THREAD_PRIORITY_LOW );
474 while( !p_intf->b_die )
476 playlist_t * p_playlist;
478 vlc_mutex_lock( &p_intf->change_lock );
480 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
483 if( p_playlist != NULL )
485 var_AddCallback( p_playlist, "intf-change", PlaylistChanged, self );
486 vlc_mutex_lock( &p_playlist->object_lock );
488 [self manage: p_playlist];
490 vlc_mutex_unlock( &p_playlist->object_lock );
491 vlc_object_release( p_playlist );
494 vlc_mutex_unlock( &p_intf->change_lock );
496 o_sleep_date = [NSDate dateWithTimeIntervalSinceNow: .5];
497 [NSThread sleepUntilDate: o_sleep_date];
505 - (void)manage:(playlist_t *)p_playlist
507 intf_thread_t * p_intf = [NSApp getIntf];
509 #define p_input p_playlist->p_input
513 vout_thread_t * p_vout = NULL;
514 aout_instance_t * p_aout = NULL;
516 vlc_mutex_lock( &p_input->stream.stream_lock );
518 if( !p_input->b_die )
520 audio_volume_t i_volume;
522 /* New input or stream map change */
523 if( p_input->stream.b_changed )
525 p_intf->p_sys->b_playing = TRUE;
526 [self manageMode: p_playlist];
531 if( var_Get( (vlc_object_t *)p_input, "intf-change", &val )
534 p_intf->p_sys->b_input_update = TRUE;
537 p_aout = vlc_object_find( p_intf, VLC_OBJECT_AOUT,
543 if( var_Get( (vlc_object_t *)p_aout, "intf-change", &val )
546 p_intf->p_sys->b_aout_update = TRUE;
549 vlc_object_release( (vlc_object_t *)p_aout );
552 aout_VolumeGet( p_intf, &i_volume );
553 p_intf->p_sys->b_mute = ( i_volume == 0 );
555 p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
561 if( var_Get( (vlc_object_t *)p_vout, "intf-change", &val )
564 p_intf->p_sys->b_vout_update = TRUE;
567 vlc_object_release( (vlc_object_t *)p_vout );
569 [self setupMenus: p_input];
571 vlc_mutex_unlock( &p_input->stream.stream_lock );
573 else if( p_intf->p_sys->b_playing && !p_intf->b_die )
575 p_intf->p_sys->b_playing = FALSE;
576 [self manageMode: p_playlist];
582 - (void)manageMode:(playlist_t *)p_playlist
584 intf_thread_t * p_intf = [NSApp getIntf];
586 if( p_playlist->p_input != NULL )
588 p_intf->p_sys->b_current_title_update = 1;
589 p_playlist->p_input->stream.b_changed = 0;
591 msg_Dbg( p_intf, "stream has changed, refreshing interface" );
595 vout_thread_t * p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
599 vlc_object_detach( p_vout );
600 vlc_object_release( p_vout );
602 vlc_mutex_unlock( &p_playlist->object_lock );
603 vout_Destroy( p_vout );
604 vlc_mutex_lock( &p_playlist->object_lock );
608 p_intf->p_sys->b_intf_update = VLC_TRUE;
611 - (void)manageIntf:(NSTimer *)o_timer
613 intf_thread_t * p_intf = [NSApp getIntf];
615 if( p_intf->p_vlc->b_die == VLC_TRUE )
617 [o_timer invalidate];
621 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
624 if( p_playlist == NULL )
629 if ( p_intf->p_sys->b_playlist_update )
631 [o_playlist playlistUpdated];
632 p_intf->p_sys->b_playlist_update = VLC_FALSE;
635 if( p_intf->p_sys->b_current_title_update )
637 vout_thread_t *p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
642 NSEnumerator * o_enum = [[NSApp windows] objectEnumerator];
644 while( ( o_vout_wnd = [o_enum nextObject] ) )
646 if( [[o_vout_wnd className] isEqualToString: @"VLCWindow"] )
648 [o_vout_wnd updateTitle];
651 vlc_object_release( (vlc_object_t *)p_vout );
653 [o_playlist updateRowSelection];
656 p_intf->p_sys->b_current_title_update = FALSE;
659 vlc_mutex_lock( &p_playlist->object_lock );
661 #define p_input p_playlist->p_input
663 if( p_input != NULL )
665 vlc_mutex_lock( &p_input->stream.stream_lock );
668 if( p_intf->p_sys->b_intf_update )
670 vlc_bool_t b_input = VLC_FALSE;
671 vlc_bool_t b_plmul = VLC_FALSE;
672 vlc_bool_t b_control = VLC_FALSE;
673 vlc_bool_t b_seekable = VLC_FALSE;
674 vlc_bool_t b_chapters = VLC_FALSE;
676 b_plmul = p_playlist->i_size > 1;
678 if( ( b_input = ( p_input != NULL ) ) )
680 /* seekable streams */
681 b_seekable = p_input->stream.b_seekable;
683 /* control buttons for free pace streams */
684 b_control = p_input->stream.b_pace_control;
687 b_chapters = p_input->stream.p_selected_area->i_part_nb > 1;
690 p_intf->p_sys->b_play_status =
691 p_input->stream.control.i_status != PAUSE_S;
696 p_intf->p_sys->b_play_status = FALSE;
697 [self setSubmenusEnabled: FALSE];
700 [self playStatusUpdated: p_intf->p_sys->b_play_status];
702 [o_btn_stop setEnabled: b_input];
703 [o_btn_faster setEnabled: b_control];
704 [o_btn_slower setEnabled: b_control];
705 [o_btn_prev setEnabled: (b_plmul || b_chapters)];
706 [o_btn_next setEnabled: (b_plmul || b_chapters)];
708 [o_timeslider setFloatValue: 0.0];
709 [o_timeslider setEnabled: b_seekable];
710 [o_timefield setStringValue: @"0:00:00"];
712 [self manageVolumeSlider];
714 p_intf->p_sys->b_intf_update = VLC_FALSE;
717 #define p_area p_input->stream.p_selected_area
719 if( p_intf->p_sys->b_playing && p_input != NULL )
721 vlc_bool_t b_field_update = TRUE;
723 if( !p_input->b_die && ( p_intf->p_sys->b_play_status !=
724 ( p_input->stream.control.i_status != PAUSE_S ) ) )
726 p_intf->p_sys->b_play_status =
727 !p_intf->p_sys->b_play_status;
729 [self playStatusUpdated: p_intf->p_sys->b_play_status];
732 if( p_input->stream.b_seekable )
734 if( f_slider == f_slider_old )
736 float f_updated = ( 10000. * p_area->i_tell ) /
739 if( f_slider != f_updated )
741 [o_timeslider setFloatValue: f_updated];
746 off_t i_seek = ( f_slider * p_area->i_size ) / 10000;
748 /* release the lock to be able to seek */
749 vlc_mutex_unlock( &p_input->stream.stream_lock );
750 input_Seek( p_input, i_seek, INPUT_SEEK_SET );
751 vlc_mutex_lock( &p_input->stream.stream_lock );
753 /* update the old value */
754 f_slider_old = f_slider;
756 b_field_update = VLC_FALSE;
763 char psz_time[ OFFSETTOTIME_MAX_SIZE ];
765 input_OffsetToTime( p_input, psz_time, p_area->i_tell );
767 o_time = [NSString stringWithCString: psz_time];
768 [o_timefield setStringValue: o_time];
771 /* disable screen saver */
772 UpdateSystemActivity( UsrActivity );
777 if( p_input != NULL )
779 vlc_mutex_unlock( &p_input->stream.stream_lock );
784 vlc_mutex_unlock( &p_playlist->object_lock );
785 vlc_object_release( p_playlist );
787 [self updateMessageArray];
789 [NSTimer scheduledTimerWithTimeInterval: 0.5
790 target: self selector: @selector(manageIntf:)
791 userInfo: nil repeats: FALSE];
794 - (void)updateMessageArray
797 intf_thread_t * p_intf = [NSApp getIntf];
799 vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
800 i_stop = *p_intf->p_sys->p_sub->pi_stop;
801 vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
803 if( p_intf->p_sys->p_sub->i_start != i_stop )
805 NSColor *o_white = [NSColor whiteColor];
806 NSColor *o_red = [NSColor redColor];
807 NSColor *o_yellow = [NSColor yellowColor];
808 NSColor *o_gray = [NSColor grayColor];
810 NSColor * pp_color[4] = { o_white, o_red, o_yellow, o_gray };
811 static const char * ppsz_type[4] = { ": ", " error: ",
812 " warning: ", " debug: " };
814 for( i_start = p_intf->p_sys->p_sub->i_start;
816 i_start = (i_start+1) % VLC_MSG_QSIZE )
819 NSDictionary *o_attr;
820 NSAttributedString *o_msg_color;
822 int i_type = p_intf->p_sys->p_sub->p_msg[i_start].i_type;
826 if( [o_msg_arr count] + 2 > 400 )
828 unsigned rid[] = { 0, 1 };
829 [o_msg_arr removeObjectsFromIndices: (unsigned *)&rid
830 numIndices: sizeof(rid)/sizeof(rid[0])];
833 o_attr = [NSDictionary dictionaryWithObject: o_gray
834 forKey: NSForegroundColorAttributeName];
835 o_msg = [NSString stringWithFormat: @"%s%s",
836 p_intf->p_sys->p_sub->p_msg[i_start].psz_module,
838 o_msg_color = [[NSAttributedString alloc]
839 initWithString: o_msg attributes: o_attr];
840 [o_msg_arr addObject: [o_msg_color autorelease]];
842 o_attr = [NSDictionary dictionaryWithObject: pp_color[i_type]
843 forKey: NSForegroundColorAttributeName];
844 o_msg = [NSString stringWithFormat: @"%s\n",
845 p_intf->p_sys->p_sub->p_msg[i_start].psz_msg];
846 o_msg_color = [[NSAttributedString alloc]
847 initWithString: o_msg attributes: o_attr];
848 [o_msg_arr addObject: [o_msg_color autorelease]];
854 NSString *o_my_msg = [NSString stringWithFormat: @"%s: %s\n",
855 p_intf->p_sys->p_sub->p_msg[i_start].psz_module,
856 p_intf->p_sys->p_sub->p_msg[i_start].psz_msg];
858 NSRange s_r = NSMakeRange( [[o_err_msg string] length], 0 );
859 [o_err_msg setEditable: YES];
860 [o_err_msg setSelectedRange: s_r];
861 [o_err_msg insertText: o_my_msg];
863 [o_error makeKeyAndOrderFront: self];
864 [o_err_msg setEditable: NO];
868 vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
869 p_intf->p_sys->p_sub->i_start = i_start;
870 vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
874 - (void)playStatusUpdated:(BOOL)b_pause
878 [o_btn_play setImage: o_img_pause];
879 [o_btn_play setToolTip: _NS("Pause")];
880 [o_mi_play setTitle: _NS("Pause")];
881 [o_dmi_play setTitle: _NS("Pause")];
885 [o_btn_play setImage: o_img_play];
886 [o_btn_play setToolTip: _NS("Play")];
887 [o_mi_play setTitle: _NS("Play")];
888 [o_dmi_play setTitle: _NS("Play")];
892 - (void)setSubmenusEnabled:(BOOL)b_enabled
894 [o_mi_program setEnabled: b_enabled];
895 [o_mi_title setEnabled: b_enabled];
896 [o_mi_chapter setEnabled: b_enabled];
897 [o_mi_audiotrack setEnabled: b_enabled];
898 [o_mi_videotrack setEnabled: b_enabled];
899 [o_mi_subtitle setEnabled: b_enabled];
900 [o_mi_channels setEnabled: b_enabled];
901 [o_mi_device setEnabled: b_enabled];
902 [o_mi_screen setEnabled: b_enabled];
905 - (void)manageVolumeSlider
907 audio_volume_t i_volume;
908 intf_thread_t * p_intf = [NSApp getIntf];
910 aout_VolumeGet( p_intf, &i_volume );
912 [o_volumeslider setFloatValue: (float)i_volume / AOUT_VOLUME_STEP];
913 [o_volumeslider setEnabled: TRUE];
915 p_intf->p_sys->b_mute = ( i_volume == 0 );
921 vout_thread_t * p_vout;
922 playlist_t * p_playlist;
923 intf_thread_t * p_intf = [NSApp getIntf];
928 msg_Dbg( p_intf, "removing all playlists" );
929 while( (p_playlist = vlc_object_find( p_intf->p_vlc, VLC_OBJECT_PLAYLIST,
932 vlc_object_detach( p_playlist );
933 vlc_object_release( p_playlist );
934 playlist_Destroy( p_playlist );
940 msg_Dbg( p_intf, "removing all video outputs" );
941 while( (p_vout = vlc_object_find( p_intf->p_vlc,
942 VLC_OBJECT_VOUT, FIND_CHILD )) )
944 vlc_object_detach( p_vout );
945 vlc_object_release( p_vout );
946 vout_Destroy( p_vout );
949 if( o_img_pause != nil )
951 [o_img_pause release];
955 if( o_img_play != nil )
957 [o_img_play release];
961 if( o_msg_arr != nil )
963 [o_msg_arr removeAllObjects];
968 if( o_msg_lock != nil )
970 [o_msg_lock release];
976 /* write cached user defaults to disk */
977 [[NSUserDefaults standardUserDefaults] synchronize];
979 /* send a dummy event to break out of the event loop */
980 o_event = [NSEvent mouseEventWithType: NSLeftMouseDown
981 location: NSMakePoint( 1, 1 ) modifierFlags: 0
982 timestamp: 1 windowNumber: [[NSApp mainWindow] windowNumber]
983 context: [NSGraphicsContext currentContext] eventNumber: 1
984 clickCount: 1 pressure: 0.0];
985 [NSApp postEvent: o_event atStart: YES];
988 - (void)setupMenus:(input_thread_t *)p_input
990 intf_thread_t * p_intf = [NSApp getIntf];
993 if( p_intf->p_sys->b_input_update )
997 [self setupVarMenu: o_mi_program target: (vlc_object_t *)p_input
998 var: "program" selector: @selector(toggleVar:)];
1000 [self setupVarMenu: o_mi_title target: (vlc_object_t *)p_input
1001 var: "title" selector: @selector(toggleVar:)];
1003 [self setupVarMenu: o_mi_chapter target: (vlc_object_t *)p_input
1004 var: "chapter" selector: @selector(toggleVar:)];
1006 [self setupVarMenu: o_mi_audiotrack target: (vlc_object_t *)p_input
1007 var: "audio-es" selector: @selector(toggleVar:)];
1009 [self setupVarMenu: o_mi_videotrack target: (vlc_object_t *)p_input
1010 var: "video-es" selector: @selector(toggleVar:)];
1012 [self setupVarMenu: o_mi_subtitle target: (vlc_object_t *)p_input
1013 var: "spu-es" selector: @selector(toggleVar:)];
1015 p_intf->p_sys->b_input_update = FALSE;
1016 var_Set( (vlc_object_t *)p_input, "intf-change", val );
1019 if ( p_intf->p_sys->b_aout_update )
1021 aout_instance_t * p_aout = vlc_object_find( p_intf, VLC_OBJECT_AOUT,
1024 if ( p_aout != NULL )
1028 [self setupVarMenu: o_mi_channels target: (vlc_object_t *)p_aout
1029 var: "audio-channels" selector: @selector(toggleVar:)];
1031 [self setupVarMenu: o_mi_device target: (vlc_object_t *)p_aout
1032 var: "audio-device" selector: @selector(toggleVar:)];
1033 var_Set( (vlc_object_t *)p_aout, "intf-change", val );
1035 vlc_object_release( (vlc_object_t *)p_aout );
1037 p_intf->p_sys->b_aout_update = FALSE;
1040 if( p_intf->p_sys->b_vout_update )
1042 vout_thread_t * p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
1045 if ( p_vout != NULL )
1049 [self setupVarMenu: o_mi_screen target: (vlc_object_t *)p_vout
1050 var: "video-device" selector: @selector(toggleVar:)];
1051 var_Set( (vlc_object_t *)p_vout, "intf-change", val );
1053 vlc_object_release( (vlc_object_t *)p_vout );
1054 [o_mi_close_window setEnabled: TRUE];
1057 p_intf->p_sys->b_vout_update = FALSE;
1061 - (void)setupVarMenu:(NSMenuItem *)o_mi
1062 target:(vlc_object_t *)p_object
1063 var:(const char *)psz_variable
1064 selector:(SEL)pf_callback
1066 int i, i_nb_items, i_value;
1067 NSMenu * o_menu = [o_mi submenu];
1068 vlc_value_t val, text;
1070 [o_mi setTag: (int)psz_variable];
1072 /* remove previous items */
1073 i_nb_items = [o_menu numberOfItems];
1074 for( i = 0; i < i_nb_items; i++ )
1076 [o_menu removeItemAtIndex: 0];
1079 if ( var_Get( p_object, psz_variable, &val ) < 0 )
1083 i_value = val.i_int;
1085 if ( var_Change( p_object, psz_variable,
1086 VLC_VAR_GETLIST, &val, &text ) < 0 )
1091 /* make (un)sensitive */
1092 [o_mi setEnabled: ( val.p_list->i_count > 1 )];
1094 for ( i = 0; i < val.p_list->i_count; i++ )
1099 if ( text.p_list->p_values[i].psz_string )
1101 o_title = [NSApp localizedString: text.p_list->p_values[i].psz_string];
1105 o_title = [NSString stringWithFormat: @"%s - %d",
1106 strdup(psz_variable), val.p_list->p_values[i].i_int ];
1108 o_lmi = [o_menu addItemWithTitle: [o_title copy]
1109 action: pf_callback keyEquivalent: @""];
1111 /* FIXME: this isn't 64-bit clean ! */
1112 [o_lmi setTag: val.p_list->p_values[i].i_int];
1113 [o_lmi setRepresentedObject:
1114 [NSValue valueWithPointer: p_object]];
1115 [o_lmi setTarget: o_controls];
1117 if ( i_value == val.p_list->p_values[i].i_int )
1118 [o_lmi setState: NSOnState];
1121 var_Change( p_object, psz_variable, VLC_VAR_FREELIST,
1126 - (IBAction)clearRecentItems:(id)sender
1128 [[NSDocumentController sharedDocumentController]
1129 clearRecentDocuments: nil];
1132 - (void)openRecentItem:(id)sender
1134 [self application: nil openFile: [sender title]];
1137 - (IBAction)viewPreferences:(id)sender
1139 [o_prefs showPrefs];
1142 - (IBAction)timesliderUpdate:(id)sender
1146 switch( [[NSApp currentEvent] type] )
1149 case NSLeftMouseDown:
1150 f_slider = [sender floatValue];
1153 case NSLeftMouseDragged:
1154 f_updated = [sender floatValue];
1161 intf_thread_t * p_intf = [NSApp getIntf];
1163 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1166 if( p_playlist == NULL )
1171 vlc_mutex_lock( &p_playlist->object_lock );
1173 if( p_playlist->p_input != NULL )
1177 char psz_time[ OFFSETTOTIME_MAX_SIZE ];
1179 #define p_area p_playlist->p_input->stream.p_selected_area
1180 vlc_mutex_lock( &p_playlist->p_input->stream.stream_lock );
1181 i_tell = f_updated / 10000. * p_area->i_size;
1182 input_OffsetToTime( p_playlist->p_input, psz_time, i_tell );
1183 vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
1186 o_time = [NSString stringWithCString: psz_time];
1187 [o_timefield setStringValue: o_time];
1190 vlc_mutex_unlock( &p_playlist->object_lock );
1191 vlc_object_release( p_playlist );
1194 - (IBAction)closeError:(id)sender
1196 [o_err_msg setString: @""];
1197 [o_error performClose: self];
1200 - (IBAction)openReadMe:(id)sender
1202 NSString * o_path = [[NSBundle mainBundle]
1203 pathForResource: @"README.MacOSX" ofType: @"rtf"];
1205 [[NSWorkspace sharedWorkspace] openFile: o_path
1206 withApplication: @"TextEdit"];
1209 - (IBAction)openDocumentation:(id)sender
1211 NSURL * o_url = [NSURL URLWithString:
1212 @"http://www.videolan.org/doc/"];
1214 [[NSWorkspace sharedWorkspace] openURL: o_url];
1217 - (IBAction)reportABug:(id)sender
1219 NSURL * o_url = [NSURL URLWithString:
1220 @"http://www.videolan.org/support/bug-reporting.html"];
1222 [[NSWorkspace sharedWorkspace] openURL: o_url];
1225 - (IBAction)openWebsite:(id)sender
1227 NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org"];
1229 [[NSWorkspace sharedWorkspace] openURL: o_url];
1232 - (IBAction)openLicense:(id)sender
1234 NSString * o_path = [[NSBundle mainBundle]
1235 pathForResource: @"COPYING" ofType: nil];
1237 [[NSWorkspace sharedWorkspace] openFile: o_path
1238 withApplication: @"TextEdit"];
1241 - (IBAction)openCrashLog:(id)sender
1243 NSString * o_path = [@"~/Library/Logs/CrashReporter/VLC.crash.log"
1244 stringByExpandingTildeInPath];
1247 if ( [[NSFileManager defaultManager] fileExistsAtPath: o_path ] )
1249 [[NSWorkspace sharedWorkspace] openFile: o_path
1250 withApplication: @"Console"];
1254 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.") );
1259 - (void)windowDidBecomeKey:(NSNotification *)o_notification
1261 if( [o_notification object] == o_msgs_panel )
1264 NSEnumerator * o_enum;
1266 [o_messages setString: @""];
1270 o_enum = [o_msg_arr objectEnumerator];
1272 while( ( o_msg = [o_enum nextObject] ) != nil )
1274 [o_messages insertText: o_msg];
1277 [o_msg_lock unlock];
1283 @implementation VLCMain (NSMenuValidation)
1285 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
1287 BOOL bEnabled = TRUE;
1289 /* Recent Items Menu */
1291 if( [[o_mi title] isEqualToString: _NS("Clear Menu")] )
1293 NSMenu * o_menu = [o_mi_open_recent submenu];
1294 int i_nb_items = [o_menu numberOfItems];
1295 NSArray * o_docs = [[NSDocumentController sharedDocumentController]
1296 recentDocumentURLs];
1297 UInt32 i_nb_docs = [o_docs count];
1299 if( i_nb_items > 1 )
1301 while( --i_nb_items )
1303 [o_menu removeItemAtIndex: 0];
1312 [o_menu insertItem: [NSMenuItem separatorItem] atIndex: 0];
1318 o_url = [o_docs objectAtIndex: i_nb_docs];
1320 if( [o_url isFileURL] )
1322 o_doc = [o_url path];
1326 o_doc = [o_url absoluteString];
1329 [o_menu insertItemWithTitle: o_doc
1330 action: @selector(openRecentItem:)
1331 keyEquivalent: @"" atIndex: 0];
1333 if( i_nb_docs == 0 )
1350 @implementation VLCMain (Internal)
1352 - (void)handlePortMessage:(NSPortMessage *)o_msg
1357 NSInvocation * o_inv;
1358 NSConditionLock * o_lock;
1360 o_data = [[o_msg components] lastObject];
1361 o_inv = *((NSInvocation **)[o_data bytes]);
1362 [o_inv getArgument: &o_value atIndex: 2];
1363 val = (id **)[o_value pointerValue];
1364 [o_inv setArgument: val[1] atIndex: 2];
1369 [o_lock unlockWithCondition: 1];