1 /*****************************************************************************
2 * intf.m: MacOS X interface plugin
3 *****************************************************************************
4 * Copyright (C) 2002-2003 VideoLAN
5 * $Id: intf.m,v 1.31 2003/01/23 21:47:59 massiot Exp $
7 * Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
8 * Christophe Massiot <massiot@via.ecp.fr>
9 * Derk-Jan Hartman <thedj@users.sourceforge.net>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
24 *****************************************************************************/
26 /*****************************************************************************
28 *****************************************************************************/
29 #include <stdlib.h> /* malloc(), free() */
30 #include <sys/param.h> /* for MAXPATHLEN */
33 #include <QuickTime/QuickTime.h>
40 /*****************************************************************************
42 *****************************************************************************/
43 static void Run ( intf_thread_t *p_intf );
45 /*****************************************************************************
46 * OpenIntf: initialize interface
47 *****************************************************************************/
48 int E_(OpenIntf) ( vlc_object_t *p_this )
50 intf_thread_t *p_intf = (intf_thread_t*) p_this;
52 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
53 if( p_intf->p_sys == NULL )
58 memset( p_intf->p_sys, 0, sizeof( *p_intf->p_sys ) );
60 p_intf->p_sys->o_pool = [[NSAutoreleasePool alloc] init];
61 p_intf->p_sys->o_sendport = [[NSPort port] retain];
63 p_intf->p_sys->p_sub = msg_Subscribe( p_intf );
67 [[VLCApplication sharedApplication] autorelease];
68 [NSApp initIntlSupport];
69 [NSApp setIntf: p_intf];
71 [NSBundle loadNibNamed: @"MainMenu" owner: NSApp];
76 /*****************************************************************************
77 * CloseIntf: destroy interface
78 *****************************************************************************/
79 void E_(CloseIntf) ( vlc_object_t *p_this )
81 intf_thread_t *p_intf = (intf_thread_t*) p_this;
83 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
85 config_SaveConfigFile( p_intf, MODULE_STRING );
87 [p_intf->p_sys->o_sendport release];
88 [p_intf->p_sys->o_pool release];
90 free( p_intf->p_sys );
93 /*****************************************************************************
95 *****************************************************************************/
96 static void Run( intf_thread_t *p_intf )
98 /* Do it again - for some unknown reason, vlc_thread_create() often
99 * fails to go to real-time priority with the first launched thread
101 vlc_thread_set_priority( p_intf, VLC_THREAD_PRIORITY_LOW );
106 /*****************************************************************************
107 * VLCApplication implementation
108 *****************************************************************************/
109 @implementation VLCApplication
113 /* default encoding: ISO-8859-1 */
114 i_encoding = NSISOLatin1StringEncoding;
116 return( [super init] );
119 - (void)initIntlSupport
121 char *psz_lang = getenv( "LANG" );
123 if( psz_lang == NULL )
128 if( strncmp( psz_lang, "pl", 2 ) == 0 )
130 i_encoding = NSISOLatin2StringEncoding;
132 else if( strncmp( psz_lang, "ja", 2 ) == 0 )
134 i_encoding = NSJapaneseEUCStringEncoding;
136 else if( strncmp( psz_lang, "ru", 2 ) == 0 )
138 #define CFSENC2NSSENC(e) CFStringConvertEncodingToNSStringEncoding(e)
139 i_encoding = CFSENC2NSSENC( kCFStringEncodingKOI8_R );
144 - (NSString *)localizedString:(char *)psz
146 if ( psz == NULL ) return NULL;
147 UInt32 uiLength = (UInt32)strlen( psz );
148 NSData * o_data = [NSData dataWithBytes: psz length: uiLength];
149 NSString *o_str = [[NSString alloc] initWithData: o_data
150 encoding: i_encoding];
151 return( [o_str autorelease] );
154 - (void)setIntf:(intf_thread_t *)_p_intf
159 - (intf_thread_t *)getIntf
164 - (void)terminate:(id)sender
166 [self getIntf]->p_vlc->b_die = VLC_TRUE;
171 /*****************************************************************************
172 * VLCMain implementation
173 *****************************************************************************/
174 @implementation VLCMain
191 pTitle = _NS("VLC - Controller");
193 [o_window setTitle: pTitle];
195 /* button controls */
196 [o_btn_playlist setToolTip: _NS("Playlist")];
197 [o_btn_prev setToolTip: _NS("Previous")];
198 [o_btn_slower setToolTip: _NS("Slowmotion")];
199 [o_btn_play setToolTip: _NS("Play")];
200 [o_btn_stop setToolTip: _NS("Stop")];
201 [o_btn_fastforward setToolTip: _NS("Fast Forward")];
202 [o_btn_fastforward setPeriodicDelay: 0.0 interval: 1];
203 [o_btn_next setToolTip: _NS("Next")];
204 [o_btn_prefs setToolTip: _NS("Preferences")];
205 [o_volumeslider setToolTip: _NS("Volume")];
206 [o_timeslider setToolTip: _NS("Position")];
209 [o_msgs_panel setTitle: _NS("Messages")];
210 [o_msgs_btn_ok setTitle: _NS("Close")];
213 [o_mi_about setTitle: _NS("About VLC Media Player")];
214 [o_mi_prefs setTitle: _NS("Preferences")];
215 [o_mi_hide setTitle: _NS("Hide VLC")];
216 [o_mi_hide_others setTitle: _NS("Hide Others")];
217 [o_mi_show_all setTitle: _NS("Show All")];
218 [o_mi_quit setTitle: _NS("Quit VLC")];
220 [o_mu_file setTitle: _NS("File")];
221 [o_mi_open_generic setTitle: _NS("Open...")];
222 [o_mi_open_file setTitle: _NS("Open File...")];
223 [o_mi_open_disc setTitle: _NS("Open Disc...")];
224 [o_mi_open_net setTitle: _NS("Open Network...")];
225 [o_mi_open_recent setTitle: _NS("Open Recent")];
226 [o_mi_open_recent_cm setTitle: _NS("Clear Menu")];
228 [o_mu_edit setTitle: _NS("Edit")];
229 [o_mi_cut setTitle: _NS("Cut")];
230 [o_mi_copy setTitle: _NS("Copy")];
231 [o_mi_paste setTitle: _NS("Paste")];
232 [o_mi_clear setTitle: _NS("Clear")];
233 [o_mi_select_all setTitle: _NS("Select All")];
235 [o_mu_controls setTitle: _NS("Controls")];
236 [o_mi_play setTitle: _NS("Play")];
237 [o_mi_stop setTitle: _NS("Stop")];
238 [o_mi_faster setTitle: _NS("Faster")];
239 [o_mi_slower setTitle: _NS("Slower")];
240 [o_mi_previous setTitle: _NS("Previous")];
241 [o_mi_next setTitle: _NS("Next")];
242 [o_mi_loop setTitle: _NS("Loop")];
243 [o_mi_program setTitle: _NS("Program")];
244 [o_mi_title setTitle: _NS("Title")];
245 [o_mi_chapter setTitle: _NS("Chapter")];
246 [o_mi_language setTitle: _NS("Language")];
247 [o_mi_subtitle setTitle: _NS("Subtitles")];
249 [o_mu_audio setTitle: _NS("Audio")];
250 [o_mi_vol_up setTitle: _NS("Volume Up")];
251 [o_mi_vol_down setTitle: _NS("Volume Down")];
252 [o_mi_mute setTitle: _NS("Mute")];
253 [o_mi_channels setTitle: _NS("Channels")];
254 [o_mi_device setTitle: _NS("Device")];
256 [o_mu_video setTitle: _NS("Video")];
257 [o_mi_fullscreen setTitle: _NS("Fullscreen")];
258 [o_mi_screen setTitle: _NS("Screen")];
259 [o_mi_deinterlace setTitle: _NS("Deinterlace")];
261 [o_mu_window setTitle: _NS("Window")];
262 [o_mi_minimize setTitle: _NS("Minimize Window")];
263 [o_mi_close_window setTitle: _NS("Close Window")];
264 [o_mi_controller setTitle: _NS("Controller")];
265 [o_mi_playlist setTitle: _NS("Playlist")];
266 [o_mi_messages setTitle: _NS("Messages")];
268 [o_mi_bring_atf setTitle: _NS("Bring All to Front")];
271 [o_dmi_play setTitle: _NS("Play")];
272 [o_dmi_stop setTitle: _NS("Stop")];
275 [o_error setTitle: _NS("Error")];
276 [o_err_lbl setStringValue: _NS("An error has occurred which probably prevented the execution of your request :")];
277 [o_err_bug_lbl setStringValue: _NS("If you believe that it is a bug, please follow the instructions at :")];
278 [o_err_btn_msgs setTitle: _NS("Open Messages Window")];
279 [o_err_btn_dismiss setTitle: _NS("Dismiss")];
284 - (void)applicationWillFinishLaunching:(NSNotification *)o_notification
286 intf_thread_t * p_intf = [NSApp getIntf];
288 f_slider_old = f_slider = 0.0;
290 [NSThread detachNewThreadSelector: @selector(manage)
291 toTarget: self withObject: nil];
293 [p_intf->p_sys->o_sendport setDelegate: self];
294 [[NSRunLoop currentRunLoop]
295 addPort: p_intf->p_sys->o_sendport
296 forMode: NSDefaultRunLoopMode];
299 - (BOOL)application:(NSApplication *)o_app openFile:(NSString *)o_filename
301 [o_playlist appendArray:
302 [NSArray arrayWithObject: o_filename] atPos: -1 enqueue: NO];
309 NSDate * o_sleep_date;
310 intf_thread_t * p_intf = [NSApp getIntf];
311 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
313 while( !p_intf->b_die )
317 vlc_mutex_lock( &p_intf->change_lock );
319 /* update the input */
320 if( p_intf->p_sys->p_input == NULL )
322 p_intf->p_sys->p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
324 [self setControlItems];
326 else if( p_intf->p_sys->p_input->b_dead )
328 vlc_object_release( p_intf->p_sys->p_input );
329 p_intf->p_sys->p_input = NULL;
331 if( p_intf->p_sys->b_stopping )
333 vout_thread_t * p_vout = vlc_object_find( p_intf,
339 vlc_object_detach( p_vout );
340 vlc_object_release( p_vout );
341 vout_Destroy( p_vout );
344 p_intf->p_sys->b_stopping = 0;
345 [self setControlItems];
352 if( p_intf->p_sys->p_input != NULL && !p_intf->p_sys->p_input->b_die )
354 vlc_bool_t b_need_menus = 0;
355 input_thread_t * p_input = p_intf->p_sys->p_input;
356 aout_instance_t * p_aout = vlc_object_find( p_intf, VLC_OBJECT_AOUT,
358 vout_thread_t * p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
361 /* Disable screen saver. */
362 UpdateSystemActivity( UsrActivity );
364 vlc_mutex_lock( &p_input->stream.stream_lock );
368 /* New input or stream map change */
369 if( p_input->stream.b_changed )
373 p_intf->p_sys->b_playing = 1;
376 if( p_intf->p_sys->i_part !=
377 p_input->stream.p_selected_area->i_part )
379 p_intf->p_sys->b_chapter_update = 1;
383 if ( p_aout != NULL )
386 if ( var_Get( (vlc_object_t *)p_aout, "intf-change", &val )
389 p_intf->p_sys->b_aout_update = 1;
392 vlc_object_release( (vlc_object_t *)p_aout );
395 if ( p_vout != NULL )
398 if ( var_Get( (vlc_object_t *)p_vout, "intf-change", &val )
401 p_intf->p_sys->b_vout_update = 1;
404 vlc_object_release( (vlc_object_t *)p_vout );
410 [self setControlItems];
412 vlc_mutex_unlock( &p_input->stream.stream_lock );
414 else if( p_intf->p_sys->b_playing && !p_intf->b_die )
418 p_intf->p_sys->b_playing = 0;
421 /* update the log window */
422 vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
423 i_stop = *p_intf->p_sys->p_sub->pi_stop;
424 vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
426 if( p_intf->p_sys->p_sub->i_start != i_stop )
429 NSColor *o_white = [NSColor whiteColor];
430 NSColor *o_red = [NSColor redColor];
431 NSColor *o_yellow = [NSColor yellowColor];
432 NSColor *o_gray = [NSColor grayColor];
434 unsigned int ui_length = [[o_messages string] length];
436 NSColor * pp_color[4] = { o_white, o_red, o_yellow, o_gray };
437 static const char * ppsz_type[4] = { ": ", " error: ",
438 " warning: ", " debug: " };
440 [o_messages setEditable: YES];
441 [o_messages setSelectedRange: NSMakeRange( ui_length, 0 )];
442 [o_messages scrollRangeToVisible: NSMakeRange( ui_length, 0 )];
445 for( i_start = p_intf->p_sys->p_sub->i_start;
447 i_start = (i_start+1) % VLC_MSG_QSIZE )
451 NSDictionary *o_attr;
452 NSAttributedString *o_msg_color;
454 int i_type = p_intf->p_sys->p_sub->p_msg[i_start].i_type;
457 o_attr = [NSDictionary dictionaryWithObject: o_gray
458 forKey: NSForegroundColorAttributeName];
459 o_msg = [NSString stringWithFormat: @"%s%s",
460 p_intf->p_sys->p_sub->p_msg[i_start].psz_module,
462 o_msg_color = [[NSAttributedString alloc]
463 initWithString: o_msg attributes: o_attr];
464 [o_messages insertText: o_msg_color];
466 o_attr = [NSDictionary dictionaryWithObject: pp_color[i_type]
467 forKey: NSForegroundColorAttributeName];
468 o_msg = [NSString stringWithCString:
469 p_intf->p_sys->p_sub->p_msg[i_start].psz_msg];
470 o_msg_color = [[NSAttributedString alloc]
471 initWithString: o_msg attributes: o_attr];
472 [o_messages insertText: o_msg_color];
474 [o_messages insertText: @"\n"];
481 [NSString stringWithFormat: @"%s: %s\n",
482 p_intf->p_sys->p_sub->p_msg[i_start].psz_module,
483 p_intf->p_sys->p_sub->p_msg[i_start].psz_msg];
485 [o_err_msg setEditable: YES];
486 [o_err_msg setSelectedRange:
487 NSMakeRange( [[o_err_msg string] length], 0 )];
488 [o_err_msg insertText: o_my_msg];
490 [o_error makeKeyAndOrderFront: self];
491 [o_err_msg setEditable: NO];
496 [o_messages setEditable: NO];
499 vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
500 p_intf->p_sys->p_sub->i_start = i_start;
501 vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
504 vlc_mutex_unlock( &p_intf->change_lock );
506 o_sleep_date = [NSDate dateWithTimeIntervalSinceNow: 0.1];
507 [NSThread sleepUntilDate: o_sleep_date];
518 vout_thread_t * p_vout;
519 playlist_t * p_playlist;
520 intf_thread_t * p_intf = [NSApp getIntf];
523 if( p_intf->p_sys->p_input )
525 vlc_object_release( p_intf->p_sys->p_input );
526 p_intf->p_sys->p_input = NULL;
538 msg_Dbg( p_intf, "removing all playlists" );
539 while( (p_playlist = vlc_object_find( p_intf->p_vlc, VLC_OBJECT_PLAYLIST,
542 vlc_object_detach( p_playlist );
543 vlc_object_release( p_playlist );
544 playlist_Destroy( p_playlist );
550 msg_Dbg( p_intf, "removing all video outputs" );
551 while( (p_vout = vlc_object_find( p_intf->p_vlc,
552 VLC_OBJECT_VOUT, FIND_CHILD )) )
554 vlc_object_detach( p_vout );
555 vlc_object_release( p_vout );
556 vout_Destroy( p_vout );
567 /* write cached user defaults to disk */
568 [[NSUserDefaults standardUserDefaults] synchronize];
570 /* send a dummy event to break out of the event loop */
571 pEvent = [NSEvent mouseEventWithType: NSLeftMouseDown
572 location: NSMakePoint( 1, 1 ) modifierFlags: 0
573 timestamp: 1 windowNumber: [[NSApp mainWindow] windowNumber]
574 context: [NSGraphicsContext currentContext] eventNumber: 1
575 clickCount: 1 pressure: 0.0];
576 [NSApp postEvent: pEvent atStart: YES];
582 vlc_bool_t b_control = 0;
583 intf_thread_t * p_intf = [NSApp getIntf];
585 if( ( b_input = ( p_intf->p_sys->p_input != NULL ) ) )
587 /* control buttons for free pace streams */
588 b_control = p_intf->p_sys->p_input->stream.b_pace_control;
590 /* get ready for menu regeneration */
591 p_intf->p_sys->b_program_update = 1;
592 p_intf->p_sys->b_title_update = 1;
593 p_intf->p_sys->b_chapter_update = 1;
594 p_intf->p_sys->b_audio_update = 1;
595 p_intf->p_sys->b_spu_update = 1;
596 p_intf->p_sys->i_part = 0;
598 p_intf->p_sys->p_input->stream.b_changed = 0;
599 msg_Dbg( p_intf, "stream has changed, refreshing interface" );
603 /* unsensitize menus */
604 [o_mi_program setEnabled: FALSE];
605 [o_mi_title setEnabled: FALSE];
606 [o_mi_chapter setEnabled: FALSE];
607 [o_mi_language setEnabled: FALSE];
608 [o_mi_subtitle setEnabled: FALSE];
609 [o_mi_channels setEnabled: FALSE];
610 [o_mi_device setEnabled: FALSE];
611 [o_mi_screen setEnabled: FALSE];
612 [o_mi_close_window setEnabled: FALSE];
614 [self setControlItems];
617 - (void)setControlItems {
618 intf_thread_t * p_intf = [NSApp getIntf];
620 vlc_bool_t b_plmul = 0;
621 vlc_bool_t b_control = 0;
622 playlist_t * p_playlist = NULL;
623 NSImage *playImage = [NSImage imageNamed:@"play"];
624 NSImage *pauseImage = [NSImage imageNamed:@"pause"];
626 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
628 if( p_playlist != NULL )
630 vlc_mutex_lock( &p_playlist->object_lock );
631 b_plmul = p_playlist->i_size > 1;
632 vlc_mutex_unlock( &p_playlist->object_lock );
633 vlc_object_release( p_playlist );
636 if( ( b_input = ( p_intf->p_sys->p_input != NULL ) ) )
638 /* control buttons for free pace streams */
639 b_control = p_intf->p_sys->p_input->stream.b_pace_control;
642 /* set control items */
643 [o_btn_stop setEnabled: b_input];
644 [o_btn_fastforward setEnabled: b_control];
645 [o_btn_slower setEnabled: b_control];
646 [o_btn_prev setEnabled: b_plmul];
647 [o_btn_next setEnabled: b_plmul];
648 [o_controls setVolumeSlider];
649 [o_timeslider setEnabled: b_input];
651 if ( (p_intf->p_sys->b_loop = config_GetInt( p_intf, "loop" )) )
653 [o_mi_loop setState: NSOnState];
657 [o_mi_loop setState: NSOffState];
660 if ( p_intf->p_sys->p_input != NULL &&
661 p_intf->p_sys->p_input->stream.control.i_status != PAUSE_S)
663 [o_btn_play setImage: pauseImage];
664 [o_btn_play setToolTip: _NS("Pause")];
665 [o_mi_play setTitle: _NS("Pause")];
666 [o_dmi_play setTitle: _NS("Pause")];
670 [o_btn_play setImage: playImage];
671 [o_btn_play setToolTip: _NS("Play")];
672 [o_mi_play setTitle: _NS("Play")];
673 [o_dmi_play setTitle: _NS("Play")];
679 unsigned int i, i_nb_items;
681 NSString * o_menu_title;
682 char psz_title[ 256 ];
684 es_descriptor_t * p_audio_es = NULL;
685 es_descriptor_t * p_spu_es = NULL;
687 intf_thread_t * p_intf = [NSApp getIntf];
689 p_intf->p_sys->b_chapter_update |= p_intf->p_sys->b_title_update;
690 p_intf->p_sys->b_audio_update |= p_intf->p_sys->b_title_update |
691 p_intf->p_sys->b_program_update;
692 p_intf->p_sys->b_spu_update |= p_intf->p_sys->b_title_update |
693 p_intf->p_sys->b_program_update;
695 #define p_input (p_intf->p_sys->p_input)
697 if( p_intf->p_sys->b_program_update )
700 SEL pf_toggle_program;
701 pgrm_descriptor_t * p_pgrm;
703 if( p_input->stream.p_new_program )
705 p_pgrm = p_input->stream.p_new_program;
709 p_pgrm = p_input->stream.p_selected_program;
712 o_program = [o_mi_program submenu];
713 pf_toggle_program = @selector(toggleProgram:);
715 /* remove previous program items */
716 i_nb_items = [o_program numberOfItems];
717 for( i = 0; i < i_nb_items; i++ )
719 [o_program removeItemAtIndex: 0];
722 /* make (un)sensitive */
723 [o_mi_program setEnabled:
724 p_input->stream.i_pgrm_number > 1];
726 /* add program items */
727 for( i = 0 ; i < p_input->stream.i_pgrm_number ; i++ )
729 snprintf( psz_title, sizeof(psz_title), "id %d",
730 p_input->stream.pp_programs[i]->i_number );
731 psz_title[sizeof(psz_title) - 1] = '\0';
733 o_menu_title = [NSString stringWithCString: psz_title];
735 o_item = [o_program addItemWithTitle: o_menu_title
736 action: pf_toggle_program keyEquivalent: @""];
737 [o_item setTag: p_input->stream.pp_programs[i]->i_number];
738 [o_item setTarget: o_controls];
740 if( p_pgrm == p_input->stream.pp_programs[i] )
742 [o_item setState: NSOnState];
746 p_intf->p_sys->b_program_update = 0;
749 if( p_intf->p_sys->b_title_update )
754 o_title = [o_mi_title submenu];
755 pf_toggle_title = @selector(toggleTitle:);
757 /* remove previous title items */
758 i_nb_items = [o_title numberOfItems];
759 for( i = 0; i < i_nb_items; i++ )
761 [o_title removeItemAtIndex: 0];
764 /* make (un)sensitive */
765 [o_mi_title setEnabled:
766 p_input->stream.i_area_nb > 1];
768 /* add title items */
769 for( i = 1 ; i < p_input->stream.i_area_nb ; i++ )
771 snprintf( psz_title, sizeof(psz_title), "Title %d (%d)", i,
772 p_input->stream.pp_areas[i]->i_part_nb );
773 psz_title[sizeof(psz_title) - 1] = '\0';
775 o_menu_title = [NSString stringWithCString: psz_title];
777 o_item = [o_title addItemWithTitle: o_menu_title
778 action: pf_toggle_title keyEquivalent: @""];
780 [o_item setTarget: o_controls];
782 if( ( p_input->stream.pp_areas[i] ==
783 p_input->stream.p_selected_area ) )
785 [o_item setState: NSOnState];
789 p_intf->p_sys->b_title_update = 0;
792 if( p_intf->p_sys->b_chapter_update )
795 SEL pf_toggle_chapter;
797 o_chapter = [o_mi_chapter submenu];
798 pf_toggle_chapter = @selector(toggleChapter:);
800 /* remove previous chapter items */
801 i_nb_items = [o_chapter numberOfItems];
802 for( i = 0; i < i_nb_items; i++ )
804 [o_chapter removeItemAtIndex: 0];
807 /* make (un)sensitive */
808 [o_mi_chapter setEnabled:
809 p_input->stream.p_selected_area->i_part_nb > 1];
811 /* add chapter items */
812 for( i = 0 ; i < p_input->stream.p_selected_area->i_part_nb ; i++ )
814 snprintf( psz_title, sizeof(psz_title), "Chapter %d", i + 1 );
815 psz_title[sizeof(psz_title) - 1] = '\0';
817 o_menu_title = [NSString stringWithCString: psz_title];
819 o_item = [o_chapter addItemWithTitle: o_menu_title
820 action: pf_toggle_chapter keyEquivalent: @""];
821 [o_item setTag: i + 1];
822 [o_item setTarget: o_controls];
824 if( ( p_input->stream.p_selected_area->i_part == i + 1 ) )
826 [o_item setState: NSOnState];
830 p_intf->p_sys->i_part =
831 p_input->stream.p_selected_area->i_part;
833 p_intf->p_sys->b_chapter_update = 0;
836 for( i = 0 ; i < p_input->stream.i_selected_es_number ; i++ )
838 if( p_input->stream.pp_selected_es[i]->i_cat == AUDIO_ES )
840 p_audio_es = p_input->stream.pp_selected_es[i];
842 else if( p_input->stream.pp_selected_es[i]->i_cat == SPU_ES )
844 p_spu_es = p_input->stream.pp_selected_es[i];
848 vlc_mutex_unlock( &p_input->stream.stream_lock );
850 if( p_intf->p_sys->b_audio_update )
852 [self setupLangMenu: o_mi_language es: p_audio_es
853 category: AUDIO_ES selector: @selector(toggleLanguage:)];
855 p_intf->p_sys->b_audio_update = 0;
858 if( p_intf->p_sys->b_spu_update )
860 [self setupLangMenu: o_mi_subtitle es: p_spu_es
861 category: SPU_ES selector: @selector(toggleLanguage:)];
863 p_intf->p_sys->b_spu_update = 0;
866 if ( p_intf->p_sys->b_aout_update )
868 aout_instance_t * p_aout = vlc_object_find( p_intf, VLC_OBJECT_AOUT,
871 if ( p_aout != NULL )
876 var_Set( (vlc_object_t *)p_aout, "intf-change", val );
878 [self setupVarMenu: o_mi_channels target: (vlc_object_t *)p_aout
879 var: "audio-channels" selector: @selector(toggleVar:)];
881 [self setupVarMenu: o_mi_device target: (vlc_object_t *)p_aout
882 var: "audio-device" selector: @selector(toggleVar:)];
884 vlc_object_release( (vlc_object_t *)p_aout );
887 p_intf->p_sys->b_aout_update = 0;
890 if ( p_intf->p_sys->b_vout_update )
892 vout_thread_t * p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
895 if ( p_vout != NULL )
900 var_Set( (vlc_object_t *)p_vout, "intf-change", val );
902 [self setupVarMenu: o_mi_screen target: (vlc_object_t *)p_vout
903 var: "video-device" selector: @selector(toggleVar:)];
905 vlc_object_release( (vlc_object_t *)p_vout );
907 [o_mi_close_window setEnabled: TRUE];
910 p_intf->p_sys->b_vout_update = 0;
913 vlc_mutex_lock( &p_input->stream.stream_lock );
918 - (void)setupLangMenu:(NSMenuItem *)o_mi
919 es:(es_descriptor_t *)p_es
921 selector:(SEL)pf_callback
923 unsigned int i, i_nb_items;
924 NSMenu * o_menu = [o_mi submenu];
925 intf_thread_t * p_intf = [NSApp getIntf];
927 /* remove previous language items */
928 i_nb_items = [o_menu numberOfItems];
929 for( i = 0; i < i_nb_items; i++ )
931 [o_menu removeItemAtIndex: 0];
934 /* make sensitive : we can't change it after we build the menu, and
935 * before, we don't yet how many items we will have. So make it
936 * always sensitive. --Meuuh */
937 [o_mi setEnabled: TRUE];
939 vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock );
941 #define ES p_intf->p_sys->p_input->stream.pp_es[i]
942 for( i = 0 ; i < p_intf->p_sys->p_input->stream.i_es_number ; i++ )
944 if( ( ES->i_cat == i_cat ) &&
947 p_intf->p_sys->p_input->stream.p_selected_program ) )
954 o_title = [NSString stringWithCString: ES->psz_desc];
958 char psz_title[ 256 ];
960 snprintf( psz_title, sizeof(psz_title), "Language 0x%x",
962 psz_title[sizeof(psz_title) - 1] = '\0';
964 o_title = [NSString stringWithCString: psz_title];
967 o_lmi = [o_menu addItemWithTitle: o_title
968 action: pf_callback keyEquivalent: @""];
969 [o_lmi setRepresentedObject:
970 [NSValue valueWithPointer: ES]];
971 [o_lmi setTarget: o_controls];
972 [o_lmi setTag: i_cat];
974 if( /*p_es == ES*/ ES->p_decoder_fifo != NULL )
976 [o_lmi setState: NSOnState];
982 vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock );
985 - (void)setupVarMenu:(NSMenuItem *)o_mi
986 target:(vlc_object_t *)p_object
987 var:(const char *)psz_variable
988 selector:(SEL)pf_callback
991 NSMenu * o_menu = [o_mi submenu];
995 /* remove previous items */
996 i_nb_items = [o_menu numberOfItems];
997 for( i = 0; i < i_nb_items; i++ )
999 [o_menu removeItemAtIndex: 0];
1002 if ( var_Get( p_object, psz_variable, &val ) < 0 )
1006 psz_value = val.psz_string;
1008 if ( var_Change( p_object, psz_variable,
1009 VLC_VAR_GETLIST, &val ) < 0 )
1015 /* make (un)sensitive */
1016 [o_mi setEnabled: (val.p_list->i_count > 0)];
1018 for ( i = 0; i < val.p_list->i_count; i++ )
1023 o_title = [NSString stringWithCString: val.p_list->p_values[i].psz_string];
1024 o_lmi = [o_menu addItemWithTitle: o_title
1025 action: pf_callback keyEquivalent: @""];
1026 /* FIXME: this isn't 64-bit clean ! */
1027 [o_lmi setTag: (int)psz_variable];
1028 [o_lmi setRepresentedObject:
1029 [NSValue valueWithPointer: p_object]];
1030 [o_lmi setTarget: o_controls];
1032 if ( !strcmp( psz_value, val.p_list->p_values[i].psz_string ) )
1033 [o_lmi setState: NSOnState];
1036 var_Change( p_object, psz_variable, VLC_VAR_FREELIST,
1042 - (IBAction)clearRecentItems:(id)sender
1044 [[NSDocumentController sharedDocumentController]
1045 clearRecentDocuments: nil];
1048 - (void)openRecentItem:(id)sender
1050 [self application: nil openFile: [sender title]];
1053 - (IBAction)viewPreferences:(id)sender
1055 if( o_prefs == nil )
1057 o_prefs = [[VLCPrefs alloc] init];
1060 [o_prefs createPrefPanel: @"main"];
1063 - (IBAction)timesliderUpdate:(id)sender
1065 switch( [[NSApp currentEvent] type] )
1067 case NSLeftMouseDown:
1068 f_slider = [sender floatValue];
1072 case NSLeftMouseDragged:
1073 f_slider = [sender floatValue];
1078 f_slider = [sender floatValue];
1080 intf_thread_t * p_intf = [NSApp getIntf];
1081 input_thread_t * p_input = p_intf->p_sys->p_input;
1082 vlc_mutex_unlock( &p_input->stream.stream_lock );
1092 intf_thread_t * p_intf = [NSApp getIntf];
1093 input_thread_t * p_input = p_intf->p_sys->p_input;
1095 if( p_input == NULL )
1097 [o_timeslider setEnabled: FALSE];
1098 [o_timeslider setFloatValue: 0.0];
1099 [o_timefield setStringValue: @"0:00:00"];
1104 #define p_area p_input->stream.p_selected_area
1106 if( p_input->stream.b_changed )
1108 [o_timeslider setEnabled: p_input->stream.b_seekable];
1110 else if( p_intf->p_sys->b_playing )
1113 char psz_time[ OFFSETTOTIME_MAX_SIZE ];
1115 input_OffsetToTime( p_input, psz_time, p_area->i_tell );
1117 o_time = [NSString stringWithCString: psz_time];
1118 [o_timefield setStringValue: o_time];
1120 if( p_input->stream.b_seekable )
1122 if( f_slider == f_slider_old )
1124 float f_updated = ( 100. * p_area->i_tell ) /
1127 if( f_slider != f_updated )
1129 [o_timeslider setFloatValue: f_updated];
1134 off_t i_seek = ( f_slider * p_area->i_size ) / 100;
1136 /* release the lock to be able to seek */
1137 vlc_mutex_unlock( &p_input->stream.stream_lock );
1138 input_Seek( p_input, i_seek, INPUT_SEEK_SET );
1139 vlc_mutex_lock( &p_input->stream.stream_lock );
1141 /* Update the old value */
1142 f_slider_old = f_slider;
1149 - (IBAction)closeError:(id)sender
1152 [o_err_msg setEditable: YES];
1153 [o_err_msg setSelectedRange:
1154 NSMakeRange( 0, [[o_err_msg string] length] )];
1155 [o_err_msg insertText: @""];
1156 [o_err_msg setEditable: NO];
1157 [o_error performClose: self];
1162 @implementation VLCMain (NSMenuValidation)
1164 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
1166 BOOL bEnabled = TRUE;
1168 /* Recent Items Menu */
1170 if( [[o_mi title] isEqualToString: _NS("Clear Menu")] )
1172 NSMenu * o_menu = [o_mi_open_recent submenu];
1173 int i_nb_items = [o_menu numberOfItems];
1174 NSArray * o_docs = [[NSDocumentController sharedDocumentController]
1175 recentDocumentURLs];
1176 UInt32 i_nb_docs = [o_docs count];
1178 if( i_nb_items > 1 )
1180 while( --i_nb_items )
1182 [o_menu removeItemAtIndex: 0];
1191 [o_menu insertItem: [NSMenuItem separatorItem] atIndex: 0];
1197 o_url = [o_docs objectAtIndex: i_nb_docs];
1199 if( [o_url isFileURL] )
1201 o_doc = [o_url path];
1205 o_doc = [o_url absoluteString];
1208 [o_menu insertItemWithTitle: o_doc
1209 action: @selector(openRecentItem:)
1210 keyEquivalent: @"" atIndex: 0];
1212 if( i_nb_docs == 0 )
1229 @implementation VLCMain (Internal)
1231 - (void)handlePortMessage:(NSPortMessage *)o_msg
1235 NSInvocation * o_inv;
1236 vout_thread_t * p_vout;
1238 o_data = [[o_msg components] lastObject];
1239 o_inv = *((NSInvocation **)[o_data bytes]);
1240 [o_inv getArgument: &o_value atIndex: 2];
1241 p_vout = (vout_thread_t *)[o_value pointerValue];
1243 [p_vout->p_sys->o_lock lock];
1245 [p_vout->p_sys->o_lock unlockWithCondition: 1];