1 /*****************************************************************************
2 * intf.m: MacOS X interface plugin
3 *****************************************************************************
4 * Copyright (C) 2002-2003 VideoLAN
5 * $Id: intf.m,v 1.55 2003/02/13 00:09:51 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 */
38 /*****************************************************************************
40 *****************************************************************************/
41 static void Run ( intf_thread_t *p_intf );
43 /*****************************************************************************
44 * OpenIntf: initialize interface
45 *****************************************************************************/
46 int E_(OpenIntf) ( vlc_object_t *p_this )
48 intf_thread_t *p_intf = (intf_thread_t*) p_this;
50 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
51 if( p_intf->p_sys == NULL )
56 memset( p_intf->p_sys, 0, sizeof( *p_intf->p_sys ) );
58 p_intf->p_sys->o_pool = [[NSAutoreleasePool alloc] init];
59 p_intf->p_sys->o_sendport = [[NSPort port] retain];
61 p_intf->p_sys->p_sub = msg_Subscribe( p_intf );
65 [[VLCApplication sharedApplication] autorelease];
66 [NSApp initIntlSupport];
67 [NSApp setIntf: p_intf];
69 [NSBundle loadNibNamed: @"MainMenu" owner: NSApp];
74 /*****************************************************************************
75 * CloseIntf: destroy interface
76 *****************************************************************************/
77 void E_(CloseIntf) ( vlc_object_t *p_this )
79 intf_thread_t *p_intf = (intf_thread_t*) p_this;
81 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
83 config_SaveConfigFile( p_intf, MODULE_STRING );
85 [p_intf->p_sys->o_sendport release];
86 [p_intf->p_sys->o_pool release];
88 free( p_intf->p_sys );
91 /*****************************************************************************
93 *****************************************************************************/
94 static void Run( intf_thread_t *p_intf )
96 /* Do it again - for some unknown reason, vlc_thread_create() often
97 * fails to go to real-time priority with the first launched thread
99 vlc_thread_set_priority( p_intf, VLC_THREAD_PRIORITY_LOW );
104 /*****************************************************************************
105 * VLCApplication implementation
106 *****************************************************************************/
107 @implementation VLCApplication
111 /* default encoding: ISO-8859-1 */
112 i_encoding = NSISOLatin1StringEncoding;
114 return( [super init] );
117 - (void)initIntlSupport
119 char *psz_lang = getenv( "LANG" );
121 if( psz_lang == NULL )
126 if( strncmp( psz_lang, "pl", 2 ) == 0 )
128 i_encoding = NSISOLatin2StringEncoding;
130 else if( strncmp( psz_lang, "ja", 2 ) == 0 )
132 i_encoding = NSJapaneseEUCStringEncoding;
134 else if( strncmp( psz_lang, "ru", 2 ) == 0 )
136 #define CFSENC2NSSENC(e) CFStringConvertEncodingToNSStringEncoding(e)
137 i_encoding = CFSENC2NSSENC( kCFStringEncodingKOI8_R );
142 - (NSString *)localizedString:(char *)psz
144 NSString * o_str = nil;
148 UInt32 uiLength = (UInt32)strlen( psz );
149 NSData * o_data = [NSData dataWithBytes: psz length: uiLength];
150 o_str = [[[NSString alloc] initWithData: o_data
151 encoding: i_encoding] autorelease];
157 - (char *)delocalizeString:(NSString *)id
159 NSData * o_data = [id dataUsingEncoding: i_encoding
160 allowLossyConversion: NO];
165 o_data = [id dataUsingEncoding: i_encoding
166 allowLossyConversion: YES];
167 psz_string = malloc( [o_data length] + 1 );
168 [o_data getBytes: psz_string];
169 psz_string[ [o_data length] ] = '\0';
170 msg_Err( p_intf, "cannot convert to wanted encoding: %s",
175 psz_string = malloc( [o_data length] + 1 );
176 [o_data getBytes: psz_string];
177 psz_string[ [o_data length] ] = '\0';
183 - (void)setIntf:(intf_thread_t *)_p_intf
188 - (intf_thread_t *)getIntf
193 - (void)terminate:(id)sender
195 p_intf->p_vlc->b_die = VLC_TRUE;
200 int ExecuteOnMainThread( id target, SEL sel, void * p_arg )
204 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
206 if( [target respondsToSelector: @selector(performSelectorOnMainThread:
207 withObject:waitUntilDone:)] )
209 [target performSelectorOnMainThread: sel
210 withObject: [NSValue valueWithPointer: p_arg]
213 else if( NSApp != nil && [NSApp respondsToSelector: @selector(getIntf)] )
218 NSPort * o_recv_port;
219 NSInvocation * o_inv;
220 NSPortMessage * o_msg;
221 intf_thread_t * p_intf;
222 NSConditionLock * o_lock;
223 NSMethodSignature * o_sig;
225 id * val[] = { &o_lock, &o_v2 };
227 p_intf = (intf_thread_t *)[NSApp getIntf];
229 o_recv_port = [[NSPort port] retain];
230 o_v1 = [NSValue valueWithPointer: val];
231 o_v2 = [NSValue valueWithPointer: p_arg];
233 o_sig = [target methodSignatureForSelector: sel];
234 o_inv = [NSInvocation invocationWithMethodSignature: o_sig];
235 [o_inv setArgument: &o_v1 atIndex: 2];
236 [o_inv setTarget: target];
237 [o_inv setSelector: sel];
239 o_array = [NSArray arrayWithObject:
240 [NSData dataWithBytes: &o_inv length: sizeof(o_inv)]];
241 o_msg = [[NSPortMessage alloc]
242 initWithSendPort: p_intf->p_sys->o_sendport
243 receivePort: o_recv_port components: o_array];
245 o_lock = [[NSConditionLock alloc] initWithCondition: 0];
246 [o_msg sendBeforeDate: [NSDate distantPast]];
247 [o_lock lockWhenCondition: 1];
252 [o_recv_port release];
264 /*****************************************************************************
265 * VLCMain implementation
266 *****************************************************************************/
267 @implementation VLCMain
271 [o_window setTitle: _NS("VLC - Controller")];
272 [o_window setExcludedFromWindowsMenu: TRUE];
274 /* button controls */
275 [o_btn_playlist setToolTip: _NS("Playlist")];
276 [o_btn_prev setToolTip: _NS("Previous")];
277 [o_btn_slower setToolTip: _NS("Slower")];
278 [o_btn_play setToolTip: _NS("Play")];
279 [o_btn_stop setToolTip: _NS("Stop")];
280 [o_btn_faster setToolTip: _NS("Faster")];
281 [o_btn_next setToolTip: _NS("Next")];
282 [o_btn_prefs setToolTip: _NS("Preferences")];
283 [o_volumeslider setToolTip: _NS("Volume")];
284 [o_timeslider setToolTip: _NS("Position")];
287 [o_msgs_panel setDelegate: self];
288 [o_msgs_panel setTitle: _NS("Messages")];
289 [o_msgs_panel setExcludedFromWindowsMenu: TRUE];
290 [o_msgs_btn_ok setTitle: _NS("Close")];
291 [o_msgs_btn_crashlog setTitle: _NS("Open CrashLog")];
294 [o_mi_about setTitle: _NS("About VLC media player")];
295 [o_mi_prefs setTitle: _NS("Preferences...")];
296 [o_mi_hide setTitle: _NS("Hide VLC")];
297 [o_mi_hide_others setTitle: _NS("Hide Others")];
298 [o_mi_show_all setTitle: _NS("Show All")];
299 [o_mi_quit setTitle: _NS("Quit VLC")];
301 [o_mu_file setTitle: _NS("File")];
302 [o_mi_open_generic setTitle: _NS("Open...")];
303 [o_mi_open_file setTitle: _NS("Open File...")];
304 [o_mi_open_disc setTitle: _NS("Open Disc...")];
305 [o_mi_open_net setTitle: _NS("Open Network...")];
306 [o_mi_open_recent setTitle: _NS("Open Recent")];
307 [o_mi_open_recent_cm setTitle: _NS("Clear Menu")];
309 [o_mu_edit setTitle: _NS("Edit")];
310 [o_mi_cut setTitle: _NS("Cut")];
311 [o_mi_copy setTitle: _NS("Copy")];
312 [o_mi_paste setTitle: _NS("Paste")];
313 [o_mi_clear setTitle: _NS("Clear")];
314 [o_mi_select_all setTitle: _NS("Select All")];
316 [o_mu_controls setTitle: _NS("Controls")];
317 [o_mi_play setTitle: _NS("Play")];
318 [o_mi_stop setTitle: _NS("Stop")];
319 [o_mi_faster setTitle: _NS("Faster")];
320 [o_mi_slower setTitle: _NS("Slower")];
321 [o_mi_previous setTitle: _NS("Previous")];
322 [o_mi_next setTitle: _NS("Next")];
323 [o_mi_loop setTitle: _NS("Loop")];
324 [o_mi_fwd setTitle: _NS("Step Forward")];
325 [o_mi_bwd setTitle: _NS("Step Backward")];
326 [o_mi_program setTitle: _NS("Program")];
327 [o_mi_title setTitle: _NS("Title")];
328 [o_mi_chapter setTitle: _NS("Chapter")];
329 [o_mi_language setTitle: _NS("Language")];
330 [o_mi_subtitle setTitle: _NS("Subtitles")];
332 [o_mu_audio setTitle: _NS("Audio")];
333 [o_mi_vol_up setTitle: _NS("Volume Up")];
334 [o_mi_vol_down setTitle: _NS("Volume Down")];
335 [o_mi_mute setTitle: _NS("Mute")];
336 [o_mi_channels setTitle: _NS("Channels")];
337 [o_mi_device setTitle: _NS("Device")];
339 [o_mu_video setTitle: _NS("Video")];
340 [o_mi_half_window setTitle: _NS("Half Size")];
341 [o_mi_normal_window setTitle: _NS("Normal Size")];
342 [o_mi_double_window setTitle: _NS("Double Size")];
343 [o_mi_fullscreen setTitle: _NS("Fullscreen")];
344 [o_mi_screen setTitle: _NS("Screen")];
345 [o_mi_deinterlace setTitle: _NS("Deinterlace")];
347 [o_mu_window setTitle: _NS("Window")];
348 [o_mi_minimize setTitle: _NS("Minimize Window")];
349 [o_mi_close_window setTitle: _NS("Close Window")];
350 [o_mi_controller setTitle: _NS("Controller")];
351 [o_mi_playlist setTitle: _NS("Playlist")];
352 [o_mi_messages setTitle: _NS("Messages")];
354 [o_mi_bring_atf setTitle: _NS("Bring All to Front")];
356 [o_mu_help setTitle: _NS("Help")];
357 [o_mi_readme setTitle: _NS("ReadMe...")];
358 [o_mi_reportabug setTitle: _NS("Report a Bug")];
359 [o_mi_website setTitle: _NS("VideoLAN Website")];
360 [o_mi_license setTitle: _NS("License")];
363 [o_dmi_play setTitle: _NS("Play")];
364 [o_dmi_stop setTitle: _NS("Stop")];
365 [o_dmi_next setTitle: _NS("Next")];
366 [o_dmi_previous setTitle: _NS("Previous")];
369 [o_error setTitle: _NS("Error")];
370 [o_err_lbl setStringValue: _NS("An error has occurred which probably prevented the execution of your request:")];
371 [o_err_bug_lbl setStringValue: _NS("If you believe that it is a bug, please follow the instructions at:")];
372 [o_err_btn_msgs setTitle: _NS("Open Messages Window")];
373 [o_err_btn_dismiss setTitle: _NS("Dismiss")];
375 [self setSubmenusEnabled: FALSE];
376 [self manageVolumeSlider];
379 - (void)applicationWillFinishLaunching:(NSNotification *)o_notification
381 intf_thread_t * p_intf = [NSApp getIntf];
383 o_msg_lock = [[NSLock alloc] init];
384 o_msg_arr = [[NSMutableArray arrayWithCapacity: 200] retain];
386 o_img_play = [[NSImage imageNamed: @"play"] retain];
387 o_img_pause = [[NSImage imageNamed: @"pause"] retain];
389 [p_intf->p_sys->o_sendport setDelegate: self];
390 [[NSRunLoop currentRunLoop]
391 addPort: p_intf->p_sys->o_sendport
392 forMode: NSDefaultRunLoopMode];
394 [NSTimer scheduledTimerWithTimeInterval: 0.5
395 target: self selector: @selector(manageIntf:)
396 userInfo: nil repeats: TRUE];
398 [NSThread detachNewThreadSelector: @selector(manage)
399 toTarget: self withObject: nil];
402 - (BOOL)application:(NSApplication *)o_app openFile:(NSString *)o_filename
404 [o_playlist appendArray:
405 [NSArray arrayWithObject: o_filename] atPos: -1 enqueue: NO];
412 NSDate * o_sleep_date;
413 intf_thread_t * p_intf = [NSApp getIntf];
414 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
416 vlc_thread_set_priority( p_intf, VLC_THREAD_PRIORITY_LOW );
418 while( !p_intf->b_die )
420 playlist_t * p_playlist;
422 vlc_mutex_lock( &p_intf->change_lock );
424 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
427 if( p_playlist != NULL )
431 if( var_Get( (vlc_object_t *)p_playlist, "intf-change", &val )
434 p_intf->p_sys->b_playlist_update = 1;
435 p_intf->p_sys->b_intf_update = VLC_TRUE;
438 vlc_mutex_lock( &p_playlist->object_lock );
440 [self manage: p_playlist];
442 vlc_mutex_unlock( &p_playlist->object_lock );
443 vlc_object_release( p_playlist );
446 vlc_mutex_unlock( &p_intf->change_lock );
448 o_sleep_date = [NSDate dateWithTimeIntervalSinceNow: .5];
449 [NSThread sleepUntilDate: o_sleep_date];
457 - (void)manage:(playlist_t *)p_playlist
459 intf_thread_t * p_intf = [NSApp getIntf];
461 #define p_input p_playlist->p_input
465 vout_thread_t * p_vout = NULL;
466 aout_instance_t * p_aout = NULL;
467 vlc_bool_t b_need_menus = VLC_FALSE;
469 vlc_mutex_lock( &p_input->stream.stream_lock );
471 if( !p_input->b_die )
473 audio_volume_t i_volume;
475 /* New input or stream map change */
476 if( p_input->stream.b_changed )
478 p_intf->p_sys->b_playing = 1;
479 [self manageMode: p_playlist];
480 b_need_menus = VLC_TRUE;
483 if( p_intf->p_sys->i_part !=
484 p_input->stream.p_selected_area->i_part )
486 p_intf->p_sys->b_chapter_update = 1;
487 b_need_menus = VLC_TRUE;
490 p_aout = vlc_object_find( p_intf, VLC_OBJECT_AOUT,
496 if( var_Get( (vlc_object_t *)p_aout, "intf-change", &val )
499 p_intf->p_sys->b_aout_update = 1;
500 b_need_menus = VLC_TRUE;
502 vlc_object_release( (vlc_object_t *)p_aout );
504 aout_VolumeGet( p_intf, &i_volume );
505 p_intf->p_sys->b_mute = ( i_volume == 0 );
507 p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
513 if( var_Get( (vlc_object_t *)p_vout, "intf-change", &val )
516 p_intf->p_sys->b_vout_update = 1;
517 b_need_menus = VLC_TRUE;
520 vlc_object_release( (vlc_object_t *)p_vout );
525 [self setupMenus: p_input];
529 vlc_mutex_unlock( &p_input->stream.stream_lock );
531 else if( p_intf->p_sys->b_playing && !p_intf->b_die )
533 p_intf->p_sys->b_playing = 0;
534 [self manageMode: p_playlist];
540 - (void)manageMode:(playlist_t *)p_playlist
542 intf_thread_t * p_intf = [NSApp getIntf];
544 if( p_playlist->p_input != NULL )
546 /* get ready for menu regeneration */
547 p_intf->p_sys->b_program_update = 1;
548 p_intf->p_sys->b_title_update = 1;
549 p_intf->p_sys->b_chapter_update = 1;
550 p_intf->p_sys->b_audio_update = 1;
551 p_intf->p_sys->b_spu_update = 1;
552 p_intf->p_sys->i_part = 0;
554 p_playlist->p_input->stream.b_changed = 0;
555 msg_Dbg( p_intf, "stream has changed, refreshing interface" );
559 vout_thread_t * p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
563 vlc_object_detach( p_vout );
564 vlc_object_release( p_vout );
566 vlc_mutex_unlock( &p_playlist->object_lock );
567 vout_Destroy( p_vout );
568 vlc_mutex_lock( &p_playlist->object_lock );
571 aout_instance_t * p_aout = vlc_object_find( p_intf, VLC_OBJECT_AOUT,
575 vlc_object_detach( (vlc_object_t *)p_aout );
576 vlc_object_release( (vlc_object_t *)p_aout );
577 aout_Delete( p_aout );
581 p_intf->p_sys->b_intf_update = VLC_TRUE;
584 - (void)manageIntf:(NSTimer *)o_timer
586 intf_thread_t * p_intf = [NSApp getIntf];
588 if( p_intf->p_vlc->b_die == VLC_TRUE )
590 [o_timer invalidate];
594 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
597 if( p_playlist == NULL )
602 vlc_mutex_lock( &p_playlist->object_lock );
604 if ( p_intf->p_sys->b_playlist_update )
609 var_Set( (vlc_object_t *)p_playlist, "intf-change", val );
611 [o_playlist playlistUpdated];
612 p_intf->p_sys->b_playlist_update = VLC_FALSE;
615 #define p_input p_playlist->p_input
617 if( p_input != NULL )
619 vlc_mutex_lock( &p_input->stream.stream_lock );
622 if( p_intf->p_sys->b_intf_update )
624 vlc_bool_t b_input = VLC_FALSE;
625 vlc_bool_t b_plmul = VLC_FALSE;
626 vlc_bool_t b_control = VLC_FALSE;
627 vlc_bool_t b_seekable = VLC_FALSE;
628 vlc_bool_t b_chapters = VLC_FALSE;
630 b_plmul = p_playlist->i_size > 1;
632 if( ( b_input = ( p_input != NULL ) ) )
634 /* seekable streams */
635 b_seekable = p_input->stream.b_seekable;
637 /* control buttons for free pace streams */
638 b_control = p_input->stream.b_pace_control;
641 b_chapters = p_input->stream.p_selected_area->i_part_nb > 1;
644 p_intf->p_sys->b_play_status =
645 p_input->stream.control.i_status != PAUSE_S;
650 p_intf->p_sys->b_play_status = VLC_FALSE;
652 [self setSubmenusEnabled: FALSE];
655 [self playStatusUpdated: p_intf->p_sys->b_play_status];
657 [o_btn_stop setEnabled: b_input];
658 [o_btn_faster setEnabled: b_control];
659 [o_btn_slower setEnabled: b_control];
660 [o_btn_prev setEnabled: (b_plmul || b_chapters)];
661 [o_btn_next setEnabled: (b_plmul || b_chapters)];
663 [o_timeslider setFloatValue: 0.0];
664 [o_timeslider setEnabled: b_seekable];
665 [o_timefield setStringValue: @"0:00:00"];
667 [self manageVolumeSlider];
669 p_intf->p_sys->b_intf_update = VLC_FALSE;
672 #define p_area p_input->stream.p_selected_area
674 if( p_intf->p_sys->b_playing && p_input != NULL )
676 vlc_bool_t b_field_update = VLC_TRUE;
678 if( !p_input->b_die && ( p_intf->p_sys->b_play_status !=
679 ( p_input->stream.control.i_status != PAUSE_S ) ) )
681 p_intf->p_sys->b_play_status =
682 !p_intf->p_sys->b_play_status;
684 [self playStatusUpdated: p_intf->p_sys->b_play_status];
687 if( p_input->stream.b_seekable )
689 if( f_slider == f_slider_old )
691 float f_updated = ( 100. * p_area->i_tell ) /
694 if( f_slider != f_updated )
696 [o_timeslider setFloatValue: f_updated];
701 off_t i_seek = ( f_slider * p_area->i_size ) / 100;
703 /* release the lock to be able to seek */
704 vlc_mutex_unlock( &p_input->stream.stream_lock );
705 input_Seek( p_input, i_seek, INPUT_SEEK_SET );
706 vlc_mutex_lock( &p_input->stream.stream_lock );
708 /* update the old value */
709 f_slider_old = f_slider;
711 b_field_update = VLC_FALSE;
718 char psz_time[ OFFSETTOTIME_MAX_SIZE ];
720 input_OffsetToTime( p_input, psz_time, p_area->i_tell );
722 o_time = [NSString stringWithCString: psz_time];
723 [o_timefield setStringValue: o_time];
726 /* disable screen saver */
727 UpdateSystemActivity( UsrActivity );
732 if( p_input != NULL )
734 vlc_mutex_unlock( &p_input->stream.stream_lock );
739 vlc_mutex_unlock( &p_playlist->object_lock );
740 vlc_object_release( p_playlist );
742 [self updateMessageArray];
745 - (void)updateMessageArray
748 intf_thread_t * p_intf = [NSApp getIntf];
750 vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
751 i_stop = *p_intf->p_sys->p_sub->pi_stop;
752 vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
754 if( p_intf->p_sys->p_sub->i_start != i_stop )
756 NSColor *o_white = [NSColor whiteColor];
757 NSColor *o_red = [NSColor redColor];
758 NSColor *o_yellow = [NSColor yellowColor];
759 NSColor *o_gray = [NSColor grayColor];
761 NSColor * pp_color[4] = { o_white, o_red, o_yellow, o_gray };
762 static const char * ppsz_type[4] = { ": ", " error: ",
763 " warning: ", " debug: " };
765 for( i_start = p_intf->p_sys->p_sub->i_start;
767 i_start = (i_start+1) % VLC_MSG_QSIZE )
770 NSDictionary *o_attr;
771 NSAttributedString *o_msg_color;
773 int i_type = p_intf->p_sys->p_sub->p_msg[i_start].i_type;
777 if( [o_msg_arr count] + 2 > 200 )
779 unsigned rid[] = { 0, 1 };
780 [o_msg_arr removeObjectsFromIndices: (unsigned *)&rid
781 numIndices: sizeof(rid)/sizeof(rid[0])];
784 o_attr = [NSDictionary dictionaryWithObject: o_gray
785 forKey: NSForegroundColorAttributeName];
786 o_msg = [NSString stringWithFormat: @"%s%s",
787 p_intf->p_sys->p_sub->p_msg[i_start].psz_module,
789 o_msg_color = [[NSAttributedString alloc]
790 initWithString: o_msg attributes: o_attr];
791 [o_msg_arr addObject: [o_msg_color autorelease]];
793 o_attr = [NSDictionary dictionaryWithObject: pp_color[i_type]
794 forKey: NSForegroundColorAttributeName];
795 o_msg = [NSString stringWithFormat: @"%s\n",
796 p_intf->p_sys->p_sub->p_msg[i_start].psz_msg];
797 o_msg_color = [[NSAttributedString alloc]
798 initWithString: o_msg attributes: o_attr];
799 [o_msg_arr addObject: [o_msg_color autorelease]];
805 NSString *o_my_msg = [NSString stringWithFormat: @"%s: %s\n",
806 p_intf->p_sys->p_sub->p_msg[i_start].psz_module,
807 p_intf->p_sys->p_sub->p_msg[i_start].psz_msg];
809 NSRange s_r = NSMakeRange( [[o_err_msg string] length], 0 );
810 [o_err_msg setEditable: YES];
811 [o_err_msg setSelectedRange: s_r];
812 [o_err_msg insertText: o_my_msg];
814 [o_error makeKeyAndOrderFront: self];
815 [o_err_msg setEditable: NO];
819 vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
820 p_intf->p_sys->p_sub->i_start = i_start;
821 vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
825 - (void)playStatusUpdated:(BOOL)b_pause
829 [o_btn_play setImage: o_img_pause];
830 [o_btn_play setToolTip: _NS("Pause")];
831 [o_mi_play setTitle: _NS("Pause")];
832 [o_dmi_play setTitle: _NS("Pause")];
836 [o_btn_play setImage: o_img_play];
837 [o_btn_play setToolTip: _NS("Play")];
838 [o_mi_play setTitle: _NS("Play")];
839 [o_dmi_play setTitle: _NS("Play")];
843 - (void)setSubmenusEnabled:(BOOL)b_enabled
845 [o_mi_program setEnabled: b_enabled];
846 [o_mi_title setEnabled: b_enabled];
847 [o_mi_chapter setEnabled: b_enabled];
848 [o_mi_language setEnabled: b_enabled];
849 [o_mi_subtitle setEnabled: b_enabled];
850 [o_mi_channels setEnabled: b_enabled];
851 [o_mi_device setEnabled: b_enabled];
852 [o_mi_screen setEnabled: b_enabled];
855 - (void)manageVolumeSlider
857 audio_volume_t i_volume;
858 intf_thread_t * p_intf = [NSApp getIntf];
860 aout_VolumeGet( p_intf, &i_volume );
862 [o_volumeslider setFloatValue: (float)i_volume / AOUT_VOLUME_STEP];
863 [o_volumeslider setEnabled: 1];
865 p_intf->p_sys->b_mute = ( i_volume == 0 );
871 vout_thread_t * p_vout;
872 playlist_t * p_playlist;
873 intf_thread_t * p_intf = [NSApp getIntf];
878 msg_Dbg( p_intf, "removing all playlists" );
879 while( (p_playlist = vlc_object_find( p_intf->p_vlc, VLC_OBJECT_PLAYLIST,
882 vlc_object_detach( p_playlist );
883 vlc_object_release( p_playlist );
884 playlist_Destroy( p_playlist );
890 msg_Dbg( p_intf, "removing all video outputs" );
891 while( (p_vout = vlc_object_find( p_intf->p_vlc,
892 VLC_OBJECT_VOUT, FIND_CHILD )) )
894 vlc_object_detach( p_vout );
895 vlc_object_release( p_vout );
896 vout_Destroy( p_vout );
899 if( o_img_pause != nil )
901 [o_img_pause release];
905 if( o_img_play != nil )
907 [o_img_play release];
911 if( o_msg_arr != nil )
913 [o_msg_arr removeAllObjects];
918 if( o_msg_lock != nil )
920 [o_msg_lock release];
932 /* write cached user defaults to disk */
933 [[NSUserDefaults standardUserDefaults] synchronize];
935 /* send a dummy event to break out of the event loop */
936 o_event = [NSEvent mouseEventWithType: NSLeftMouseDown
937 location: NSMakePoint( 1, 1 ) modifierFlags: 0
938 timestamp: 1 windowNumber: [[NSApp mainWindow] windowNumber]
939 context: [NSGraphicsContext currentContext] eventNumber: 1
940 clickCount: 1 pressure: 0.0];
941 [NSApp postEvent: o_event atStart: YES];
944 - (void)setupMenus:(input_thread_t *)p_input
946 unsigned int i, i_nb_items;
948 NSString * o_menu_title;
949 char psz_title[ 256 ];
951 es_descriptor_t * p_audio_es = NULL;
952 es_descriptor_t * p_spu_es = NULL;
954 intf_thread_t * p_intf = [NSApp getIntf];
956 p_intf->p_sys->b_chapter_update |= p_intf->p_sys->b_title_update;
957 p_intf->p_sys->b_audio_update |= p_intf->p_sys->b_title_update |
958 p_intf->p_sys->b_program_update;
959 p_intf->p_sys->b_spu_update |= p_intf->p_sys->b_title_update |
960 p_intf->p_sys->b_program_update;
962 if( p_intf->p_sys->b_program_update )
965 SEL pf_toggle_program;
966 pgrm_descriptor_t * p_pgrm;
968 if( p_input->stream.p_new_program )
970 p_pgrm = p_input->stream.p_new_program;
974 p_pgrm = p_input->stream.p_selected_program;
977 o_program = [o_mi_program submenu];
978 pf_toggle_program = @selector(toggleProgram:);
980 /* remove previous program items */
981 i_nb_items = [o_program numberOfItems];
982 for( i = 0; i < i_nb_items; i++ )
984 [o_program removeItemAtIndex: 0];
987 /* make (un)sensitive */
988 [o_mi_program setEnabled:
989 p_input->stream.i_pgrm_number > 1];
991 /* add program items */
992 for( i = 0 ; i < p_input->stream.i_pgrm_number ; i++ )
994 snprintf( psz_title, sizeof(psz_title), "id %d",
995 p_input->stream.pp_programs[i]->i_number );
996 psz_title[sizeof(psz_title) - 1] = '\0';
998 o_menu_title = [NSApp localizedString: psz_title];
1000 o_item = [o_program addItemWithTitle: o_menu_title
1001 action: pf_toggle_program keyEquivalent: @""];
1002 [o_item setTag: p_input->stream.pp_programs[i]->i_number];
1003 [o_item setTarget: o_controls];
1005 if( p_pgrm == p_input->stream.pp_programs[i] )
1007 [o_item setState: NSOnState];
1011 p_intf->p_sys->b_program_update = 0;
1014 if( p_intf->p_sys->b_title_update )
1017 SEL pf_toggle_title;
1019 o_title = [o_mi_title submenu];
1020 pf_toggle_title = @selector(toggleTitle:);
1022 /* remove previous title items */
1023 i_nb_items = [o_title numberOfItems];
1024 for( i = 0; i < i_nb_items; i++ )
1026 [o_title removeItemAtIndex: 0];
1029 /* make (un)sensitive */
1030 [o_mi_title setEnabled:
1031 p_input->stream.i_area_nb > 1];
1033 /* add title items */
1034 for( i = 1 ; i < p_input->stream.i_area_nb ; i++ )
1036 snprintf( psz_title, sizeof(psz_title), "Title %d (%d)", i,
1037 p_input->stream.pp_areas[i]->i_part_nb );
1038 psz_title[sizeof(psz_title) - 1] = '\0';
1040 o_menu_title = [NSApp localizedString: psz_title];
1042 o_item = [o_title addItemWithTitle: o_menu_title
1043 action: pf_toggle_title keyEquivalent: @""];
1045 [o_item setTarget: o_controls];
1047 if( ( p_input->stream.pp_areas[i] ==
1048 p_input->stream.p_selected_area ) )
1050 [o_item setState: NSOnState];
1054 p_intf->p_sys->b_title_update = 0;
1057 if( p_intf->p_sys->b_chapter_update )
1060 SEL pf_toggle_chapter;
1062 o_chapter = [o_mi_chapter submenu];
1063 pf_toggle_chapter = @selector(toggleChapter:);
1065 /* remove previous chapter items */
1066 i_nb_items = [o_chapter numberOfItems];
1067 for( i = 0; i < i_nb_items; i++ )
1069 [o_chapter removeItemAtIndex: 0];
1072 /* make (un)sensitive */
1073 [o_mi_chapter setEnabled:
1074 p_input->stream.p_selected_area->i_part_nb > 1];
1076 /* add chapter items */
1077 for( i = 0 ; i < p_input->stream.p_selected_area->i_part_nb ; i++ )
1079 snprintf( psz_title, sizeof(psz_title), "Chapter %d", i + 1 );
1080 psz_title[sizeof(psz_title) - 1] = '\0';
1082 o_menu_title = [NSApp localizedString: psz_title];
1084 o_item = [o_chapter addItemWithTitle: o_menu_title
1085 action: pf_toggle_chapter keyEquivalent: @""];
1086 [o_item setTag: i + 1];
1087 [o_item setTarget: o_controls];
1089 if( ( p_input->stream.p_selected_area->i_part == i + 1 ) )
1091 [o_item setState: NSOnState];
1095 p_intf->p_sys->i_part =
1096 p_input->stream.p_selected_area->i_part;
1098 p_intf->p_sys->b_chapter_update = 0;
1101 for( i = 0 ; i < p_input->stream.i_selected_es_number ; i++ )
1103 if( p_input->stream.pp_selected_es[i]->i_cat == AUDIO_ES )
1105 p_audio_es = p_input->stream.pp_selected_es[i];
1107 else if( p_input->stream.pp_selected_es[i]->i_cat == SPU_ES )
1109 p_spu_es = p_input->stream.pp_selected_es[i];
1113 if( p_intf->p_sys->b_audio_update )
1115 [self setupLangMenu: p_input mi: o_mi_language es: p_audio_es
1116 category: AUDIO_ES selector: @selector(toggleLanguage:)];
1118 p_intf->p_sys->b_audio_update = 0;
1121 if( p_intf->p_sys->b_spu_update )
1123 [self setupLangMenu: p_input mi: o_mi_subtitle es: p_spu_es
1124 category: SPU_ES selector: @selector(toggleLanguage:)];
1126 p_intf->p_sys->b_spu_update = 0;
1129 if ( p_intf->p_sys->b_aout_update )
1131 aout_instance_t * p_aout = vlc_object_find( p_intf, VLC_OBJECT_AOUT,
1134 if ( p_aout != NULL )
1139 var_Set( (vlc_object_t *)p_aout, "intf-change", val );
1141 [self setupVarMenu: o_mi_channels target: (vlc_object_t *)p_aout
1142 var: "audio-channels" selector: @selector(toggleVar:)];
1144 [self setupVarMenu: o_mi_device target: (vlc_object_t *)p_aout
1145 var: "audio-device" selector: @selector(toggleVar:)];
1147 vlc_object_release( (vlc_object_t *)p_aout );
1150 p_intf->p_sys->b_aout_update = 0;
1153 if( p_intf->p_sys->b_vout_update )
1155 vout_thread_t * p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
1158 if ( p_vout != NULL )
1163 var_Set( (vlc_object_t *)p_vout, "intf-change", val );
1165 [self setupVarMenu: o_mi_screen target: (vlc_object_t *)p_vout
1166 var: "video-device" selector: @selector(toggleVar:)];
1168 vlc_object_release( (vlc_object_t *)p_vout );
1170 [o_mi_close_window setEnabled: TRUE];
1173 p_intf->p_sys->b_vout_update = 0;
1179 - (void)setupLangMenu:(input_thread_t *)p_input
1180 mi:(NSMenuItem *)o_mi
1181 es:(es_descriptor_t *)p_es
1183 selector:(SEL)pf_callback
1185 unsigned int i, i_nb_items;
1186 NSMenu * o_menu = [o_mi submenu];
1188 /* remove previous language items */
1189 i_nb_items = [o_menu numberOfItems];
1190 for( i = 0; i < i_nb_items; i++ )
1192 [o_menu removeItemAtIndex: 0];
1195 /* make sensitive : we can't change it after we build the menu, and
1196 * before, we don't yet how many items we will have. So make it
1197 * always sensitive. --Meuuh */
1198 [o_mi setEnabled: TRUE];
1201 /* We do not use this code, because you need to start stop .avi for
1202 * it to work, so not very useful now --hartman */
1203 if ( o_mi == o_mi_subtitle ) {
1205 [o_mi setEnabled: TRUE ];
1208 o_title = _NS("Load from file..");
1209 o_lmi = [o_menu addItemWithTitle: o_title
1210 action: pf_callback keyEquivalent: @""];
1211 [o_lmi setTag: 2000];
1212 [o_lmi setTarget: o_controls];
1216 #define ES p_input->stream.pp_es[i]
1217 for( i = 0 ; i < p_input->stream.i_es_number ; i++ )
1219 if( ( ES->i_cat == i_cat ) &&
1222 p_input->stream.p_selected_program ) )
1229 o_title = [NSApp localizedString: ES->psz_desc];
1233 char psz_title[ 256 ];
1235 snprintf( psz_title, sizeof(psz_title), _("Language 0x%x"),
1237 psz_title[sizeof(psz_title) - 1] = '\0';
1239 o_title = [NSApp localizedString: psz_title];
1242 o_lmi = [o_menu addItemWithTitle: o_title
1243 action: pf_callback keyEquivalent: @""];
1244 [o_lmi setRepresentedObject:
1245 [NSValue valueWithPointer: ES]];
1246 [o_lmi setTarget: o_controls];
1247 [o_lmi setTag: i_cat];
1249 if( /*p_es == ES*/ ES->p_decoder_fifo != NULL )
1251 [o_lmi setState: NSOnState];
1258 - (void)setupVarMenu:(NSMenuItem *)o_mi
1259 target:(vlc_object_t *)p_object
1260 var:(const char *)psz_variable
1261 selector:(SEL)pf_callback
1264 NSMenu * o_menu = [o_mi submenu];
1268 /* remove previous items */
1269 i_nb_items = [o_menu numberOfItems];
1270 for( i = 0; i < i_nb_items; i++ )
1272 [o_menu removeItemAtIndex: 0];
1275 if ( var_Get( p_object, psz_variable, &val ) < 0 )
1279 psz_value = val.psz_string;
1281 if ( var_Change( p_object, psz_variable,
1282 VLC_VAR_GETLIST, &val ) < 0 )
1288 /* make (un)sensitive */
1289 [o_mi setEnabled: ( val.p_list->i_count > 0 )];
1291 for ( i = 0; i < val.p_list->i_count; i++ )
1296 o_title = [NSApp localizedString: val.p_list->p_values[i].psz_string];
1297 o_lmi = [o_menu addItemWithTitle: o_title
1298 action: pf_callback keyEquivalent: @""];
1299 /* FIXME: this isn't 64-bit clean ! */
1300 [o_lmi setTag: (int)psz_variable];
1301 [o_lmi setRepresentedObject:
1302 [NSValue valueWithPointer: p_object]];
1303 [o_lmi setTarget: o_controls];
1305 if ( !strcmp( psz_value, val.p_list->p_values[i].psz_string ) )
1306 [o_lmi setState: NSOnState];
1309 var_Change( p_object, psz_variable, VLC_VAR_FREELIST,
1315 - (IBAction)clearRecentItems:(id)sender
1317 [[NSDocumentController sharedDocumentController]
1318 clearRecentDocuments: nil];
1321 - (void)openRecentItem:(id)sender
1323 [self application: nil openFile: [sender title]];
1326 - (IBAction)viewPreferences:(id)sender
1328 if( o_prefs == nil )
1330 o_prefs = [[VLCPrefs alloc] init];
1333 [o_prefs createPrefPanel: @"main"];
1336 - (IBAction)timesliderUpdate:(id)sender
1340 switch( [[NSApp currentEvent] type] )
1343 case NSLeftMouseDown:
1344 f_slider = [sender floatValue];
1347 case NSLeftMouseDragged:
1348 f_updated = [sender floatValue];
1355 intf_thread_t * p_intf = [NSApp getIntf];
1357 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1360 if( p_playlist == NULL )
1365 vlc_mutex_lock( &p_playlist->object_lock );
1367 if( p_playlist->p_input != NULL )
1371 char psz_time[ OFFSETTOTIME_MAX_SIZE ];
1373 #define p_area p_playlist->p_input->stream.p_selected_area
1374 vlc_mutex_lock( &p_playlist->p_input->stream.stream_lock );
1375 i_tell = f_updated / 100. * p_area->i_size;
1376 input_OffsetToTime( p_playlist->p_input, psz_time, i_tell );
1377 vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
1380 o_time = [NSString stringWithCString: psz_time];
1381 [o_timefield setStringValue: o_time];
1384 vlc_mutex_unlock( &p_playlist->object_lock );
1385 vlc_object_release( p_playlist );
1388 - (IBAction)closeError:(id)sender
1390 [o_err_msg setString: @""];
1391 [o_error performClose: self];
1394 - (IBAction)openReadMe:(id)sender
1396 NSString * o_path = [[NSBundle mainBundle]
1397 pathForResource: @"README.MacOSX" ofType: @"rtf"];
1399 [[NSWorkspace sharedWorkspace] openFile: o_path
1400 withApplication: @"TextEdit"];
1403 - (IBAction)reportABug:(id)sender
1405 NSURL * o_url = [NSURL URLWithString:
1406 @"http://www.videolan.org/support/bug-reporting.html"];
1408 [[NSWorkspace sharedWorkspace] openURL: o_url];
1411 - (IBAction)openWebsite:(id)sender
1413 NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org"];
1415 [[NSWorkspace sharedWorkspace] openURL: o_url];
1418 - (IBAction)openLicense:(id)sender
1420 NSString * o_path = [[NSBundle mainBundle]
1421 pathForResource: @"COPYING" ofType: nil];
1423 [[NSWorkspace sharedWorkspace] openFile: o_path
1424 withApplication: @"TextEdit"];
1427 - (IBAction)openCrashLog:(id)sender
1429 NSString * o_path = [@"~/Library/Logs/CrashReporter/VLC.crash.log"
1430 stringByExpandingTildeInPath];
1433 if ( [[NSFileManager defaultManager] fileExistsAtPath: o_path ] )
1435 [[NSWorkspace sharedWorkspace] openFile: o_path
1436 withApplication: @"Console"];
1440 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.") );
1445 - (void)windowDidBecomeKey:(NSNotification *)o_notification
1447 if( [o_notification object] == o_msgs_panel )
1450 NSEnumerator * o_enum;
1452 [o_messages setString: @""];
1456 o_enum = [o_msg_arr objectEnumerator];
1458 while( ( o_msg = [o_enum nextObject] ) != nil )
1460 [o_messages insertText: o_msg];
1463 [o_msg_lock unlock];
1469 @implementation VLCMain (NSMenuValidation)
1471 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
1473 BOOL bEnabled = TRUE;
1475 /* Recent Items Menu */
1477 if( [[o_mi title] isEqualToString: _NS("Clear Menu")] )
1479 NSMenu * o_menu = [o_mi_open_recent submenu];
1480 int i_nb_items = [o_menu numberOfItems];
1481 NSArray * o_docs = [[NSDocumentController sharedDocumentController]
1482 recentDocumentURLs];
1483 UInt32 i_nb_docs = [o_docs count];
1485 if( i_nb_items > 1 )
1487 while( --i_nb_items )
1489 [o_menu removeItemAtIndex: 0];
1498 [o_menu insertItem: [NSMenuItem separatorItem] atIndex: 0];
1504 o_url = [o_docs objectAtIndex: i_nb_docs];
1506 if( [o_url isFileURL] )
1508 o_doc = [o_url path];
1512 o_doc = [o_url absoluteString];
1515 [o_menu insertItemWithTitle: o_doc
1516 action: @selector(openRecentItem:)
1517 keyEquivalent: @"" atIndex: 0];
1519 if( i_nb_docs == 0 )
1536 @implementation VLCMain (Internal)
1538 - (void)handlePortMessage:(NSPortMessage *)o_msg
1543 NSInvocation * o_inv;
1544 NSConditionLock * o_lock;
1546 o_data = [[o_msg components] lastObject];
1547 o_inv = *((NSInvocation **)[o_data bytes]);
1548 [o_inv getArgument: &o_value atIndex: 2];
1549 val = (id **)[o_value pointerValue];
1550 [o_inv setArgument: val[1] atIndex: 2];
1555 [o_lock unlockWithCondition: 1];