1 /*****************************************************************************
2 * intf.m: MacOS X interface plugin
3 *****************************************************************************
4 * Copyright (C) 2002 VideoLAN
5 * $Id: intf.m,v 1.8 2002/12/08 05:30:47 jlj Exp $
7 * Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
8 * Christophe Massiot <massiot@via.ecp.fr>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
28 #include <stdlib.h> /* malloc(), free() */
29 #include <sys/param.h> /* for MAXPATHLEN */
32 #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 [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 )
99 /*****************************************************************************
100 * VLCApplication implementation
101 *****************************************************************************/
102 @implementation VLCApplication
106 /* default encoding: ISO-8859-1 */
107 i_encoding = NSISOLatin1StringEncoding;
109 return( [super init] );
112 - (void)initIntlSupport
114 char *psz_lang = getenv( "LANG" );
116 if( psz_lang == NULL )
121 if( strncmp( psz_lang, "pl", 2 ) == 0 )
123 i_encoding = NSISOLatin2StringEncoding;
125 else if( strncmp( psz_lang, "ja", 2 ) == 0 )
127 i_encoding = NSJapaneseEUCStringEncoding;
129 else if( strncmp( psz_lang, "ru", 2 ) == 0 )
131 #define CFSENC2NSSENC(e) CFStringConvertEncodingToNSStringEncoding(e)
132 i_encoding = CFSENC2NSSENC( kCFStringEncodingKOI8_R );
137 - (NSString *)localizedString:(char *)psz
139 UInt32 uiLength = (UInt32)strlen( psz );
140 NSData * o_data = [NSData dataWithBytes: psz length: uiLength];
141 NSString *o_str = [[NSString alloc] initWithData: o_data
142 encoding: i_encoding];
143 return( [o_str autorelease] );
146 - (void)setIntf:(intf_thread_t *)_p_intf
151 - (intf_thread_t *)getIntf
156 - (void)terminate:(id)sender
158 [self getIntf]->p_vlc->b_die = VLC_TRUE;
163 /*****************************************************************************
164 * VLCMain implementation
165 *****************************************************************************/
166 @implementation VLCMain
182 NSString * pTitle = [NSString
183 stringWithCString: VOUT_TITLE " (Cocoa)"];
185 [o_window setTitle: pTitle];
187 [o_msgs_panel setTitle: _NS("Messages")];
188 [o_msgs_btn_ok setTitle: _NS("Close")];
190 [o_mi_about setTitle: _NS("About vlc")];
191 [o_mi_prefs setTitle: _NS("Preferences")];
192 [o_mi_hide setTitle: _NS("Hide vlc")];
193 [o_mi_hide_others setTitle: _NS("Hide Others")];
194 [o_mi_show_all setTitle: _NS("Show All")];
195 [o_mi_quit setTitle: _NS("Quit vlc")];
197 [o_mu_file setTitle: _NS("File")];
198 [o_mi_open_file setTitle: _NS("Open File")];
199 [o_mi_open_disc setTitle: _NS("Open Disc")];
200 [o_mi_open_net setTitle: _NS("Open Network")];
201 [o_mi_open_recent setTitle: _NS("Open Recent")];
202 [o_mi_open_recent_cm setTitle: _NS("Clear Menu")];
204 [o_mu_edit setTitle: _NS("Edit")];
205 [o_mi_cut setTitle: _NS("Cut")];
206 [o_mi_copy setTitle: _NS("Copy")];
207 [o_mi_paste setTitle: _NS("Paste")];
208 [o_mi_clear setTitle: _NS("Clear")];
209 [o_mi_select_all setTitle: _NS("Select All")];
211 [o_mu_view setTitle: _NS("View")];
212 [o_mi_playlist setTitle: _NS("Playlist")];
213 [o_mi_messages setTitle: _NS("Messages")];
215 [o_mu_controls setTitle: _NS("Controls")];
216 [o_mi_play setTitle: _NS("Play")];
217 [o_mi_pause setTitle: _NS("Pause")];
218 [o_mi_stop setTitle: _NS("Stop")];
219 [o_mi_faster setTitle: _NS("Faster")];
220 [o_mi_slower setTitle: _NS("Slower")];
221 [o_mi_previous setTitle: _NS("Prev")];
222 [o_mi_next setTitle: _NS("Next")];
223 [o_mi_loop setTitle: _NS("Loop")];
224 [o_mi_vol_up setTitle: _NS("Louder")];
225 [o_mi_vol_down setTitle: _NS("Softer")];
226 [o_mi_mute setTitle: _NS("Mute")];
227 [o_mi_channels setTitle: _NS("Channels")];
228 [o_mi_fullscreen setTitle: _NS("Fullscreen")];
229 [o_mi_screen setTitle: _NS("Screen")];
230 [o_mi_deinterlace setTitle: _NS("Deinterlace")];
231 [o_mi_program setTitle: _NS("Program")];
232 [o_mi_title setTitle: _NS("Title")];
233 [o_mi_chapter setTitle: _NS("Chapter")];
234 [o_mi_language setTitle: _NS("Language")];
235 [o_mi_subtitle setTitle: _NS("Subtitles")];
237 [o_mu_window setTitle: _NS("Window")];
238 [o_mi_minimize setTitle: _NS("Minimize")];
239 [o_mi_bring_atf setTitle: _NS("Bring All to Front")];
242 [o_dmi_play setTitle: _NS("Play")];
243 [o_dmi_pause setTitle: _NS("Pause")];
244 [o_dmi_stop setTitle: _NS("Stop")];
249 - (void)applicationWillFinishLaunching:(NSNotification *)o_notification
251 intf_thread_t * p_intf = [NSApp getIntf];
253 [NSThread detachNewThreadSelector: @selector(manage)
254 toTarget: self withObject: nil];
256 [p_intf->p_sys->o_sendport setDelegate: self];
257 [[NSRunLoop currentRunLoop]
258 addPort: p_intf->p_sys->o_sendport
259 forMode: NSDefaultRunLoopMode];
261 // Since we need the sound menu now, it's a good time to create the sound system class
262 asystm=[[MacOSXAudioSystem alloc] initWithGUI:self];
267 - (void)noopAction:(id)sender {
271 - (BOOL)application:(NSApplication *)o_app openFile:(NSString *)o_filename
273 [o_playlist appendArray:
274 [NSArray arrayWithObject: o_filename] atPos: -1];
281 NSDate * o_sleep_date;
282 intf_thread_t * p_intf = [NSApp getIntf];
283 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
285 while( !p_intf->b_die )
289 vlc_mutex_lock( &p_intf->change_lock );
291 /* update the input */
292 if( p_intf->p_sys->p_input == NULL )
294 p_intf->p_sys->p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
297 else if( p_intf->p_sys->p_input->b_dead )
299 vlc_object_release( p_intf->p_sys->p_input );
300 p_intf->p_sys->p_input = NULL;
303 if( p_intf->p_sys->p_input != NULL )
305 vlc_bool_t b_need_menus = 0;
306 input_thread_t * p_input = p_intf->p_sys->p_input;
307 aout_instance_t * p_aout = vlc_object_find( p_intf, VLC_OBJECT_AOUT,
309 vout_thread_t * p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
312 vlc_mutex_lock( &p_input->stream.stream_lock );
314 if( !p_input->b_die )
316 /* New input or stream map change */
317 if( p_input->stream.b_changed )
321 p_intf->p_sys->b_playing = 1;
324 if( p_intf->p_sys->i_part !=
325 p_input->stream.p_selected_area->i_part )
327 p_intf->p_sys->b_chapter_update = 1;
332 if ( p_aout != NULL )
335 if ( var_Get( (vlc_object_t *)p_aout, "intf-change", &val )
338 p_intf->p_sys->b_aout_update = 1;
341 vlc_object_release( (vlc_object_t *)p_aout );
344 if ( p_vout != NULL )
347 if ( var_Get( (vlc_object_t *)p_vout, "intf-change", &val )
350 p_intf->p_sys->b_vout_update = 1;
353 vlc_object_release( (vlc_object_t *)p_vout );
359 vlc_mutex_unlock( &p_input->stream.stream_lock );
361 else if( p_intf->p_sys->b_playing && !p_intf->b_die )
364 p_intf->p_sys->b_playing = 0;
367 /* update the log window */
368 vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
369 i_stop = *p_intf->p_sys->p_sub->pi_stop;
370 vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
372 if( p_intf->p_sys->p_sub->i_start != i_stop )
374 NSColor *o_white = [NSColor whiteColor];
375 NSColor *o_red = [NSColor redColor];
376 NSColor *o_yellow = [NSColor yellowColor];
377 NSColor *o_gray = [NSColor grayColor];
379 unsigned int ui_length = [[o_messages string] length];
381 NSColor * pp_color[4] = { o_white, o_red, o_yellow, o_gray };
382 static const char * ppsz_type[4] = { ": ", " error: ",
383 " warning: ", " debug: " };
385 [o_messages setEditable: YES];
386 [o_messages setSelectedRange: NSMakeRange( ui_length, 0 )];
387 [o_messages scrollRangeToVisible: NSMakeRange( ui_length, 0 )];
389 for( i_start = p_intf->p_sys->p_sub->i_start;
391 i_start = (i_start+1) % VLC_MSG_QSIZE )
394 NSDictionary *o_attr;
395 NSAttributedString *o_msg_color;
396 int i_type = p_intf->p_sys->p_sub->p_msg[i_start].i_type;
398 o_attr = [NSDictionary dictionaryWithObject: o_gray
399 forKey: NSForegroundColorAttributeName];
400 o_msg = [NSString stringWithFormat: @"%s%s",
401 p_intf->p_sys->p_sub->p_msg[i_start].psz_module,
403 o_msg_color = [[NSAttributedString alloc]
404 initWithString: o_msg attributes: o_attr];
405 [o_messages insertText: o_msg_color];
407 o_attr = [NSDictionary dictionaryWithObject: pp_color[i_type]
408 forKey: NSForegroundColorAttributeName];
409 o_msg = [NSString stringWithCString:
410 p_intf->p_sys->p_sub->p_msg[i_start].psz_msg];
411 o_msg_color = [[NSAttributedString alloc]
412 initWithString: o_msg attributes: o_attr];
413 [o_messages insertText: o_msg_color];
415 [o_messages insertText: @"\n"];
418 [o_messages setEditable: NO];
420 vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
421 p_intf->p_sys->p_sub->i_start = i_start;
422 vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
425 vlc_mutex_unlock( &p_intf->change_lock );
427 o_sleep_date = [NSDate dateWithTimeIntervalSinceNow: 0.1];
428 [NSThread sleepUntilDate: o_sleep_date];
439 vout_thread_t * p_vout;
440 playlist_t * p_playlist;
441 intf_thread_t * p_intf = [NSApp getIntf];
444 if( p_intf->p_sys->p_input )
446 vlc_object_release( p_intf->p_sys->p_input );
447 p_intf->p_sys->p_input = NULL;
453 msg_Dbg( p_intf, "removing all playlists" );
454 while( (p_playlist = vlc_object_find( p_intf->p_vlc, VLC_OBJECT_PLAYLIST,
457 vlc_object_detach( p_playlist );
458 vlc_object_release( p_playlist );
459 playlist_Destroy( p_playlist );
465 msg_Dbg( p_intf, "removing all video outputs" );
466 while( (p_vout = vlc_object_find( p_intf->p_vlc,
467 VLC_OBJECT_VOUT, FIND_CHILD )) )
469 vlc_object_detach( p_vout );
470 vlc_object_release( p_vout );
471 vout_Destroy( p_vout );
482 /* write cached user defaults to disk */
483 [[NSUserDefaults standardUserDefaults] synchronize];
485 /* send a dummy event to break out of the event loop */
486 pEvent = [NSEvent mouseEventWithType: NSLeftMouseDown
487 location: NSMakePoint( 1, 1 ) modifierFlags: 0
488 timestamp: 1 windowNumber: [[NSApp mainWindow] windowNumber]
489 context: [NSGraphicsContext currentContext] eventNumber: 1
490 clickCount: 1 pressure: 0.0];
491 [NSApp postEvent: pEvent atStart: YES];
498 vlc_bool_t b_control = 0;
499 intf_thread_t * p_intf = [NSApp getIntf];
501 if( p_intf->p_sys->p_input != NULL )
503 /* control buttons for free pace streams */
504 b_control = p_intf->p_sys->p_input->stream.b_pace_control;
506 /* get ready for menu regeneration */
507 p_intf->p_sys->b_program_update = 1;
508 p_intf->p_sys->b_title_update = 1;
509 p_intf->p_sys->b_chapter_update = 1;
510 p_intf->p_sys->b_audio_update = 1;
511 p_intf->p_sys->b_spu_update = 1;
512 p_intf->p_sys->i_part = 0;
514 p_intf->p_sys->p_input->stream.b_changed = 0;
515 msg_Dbg( p_intf, "stream has changed, refreshing interface" );
519 /* unsensitize menus */
520 [o_mi_program setEnabled: FALSE];
521 [o_mi_title setEnabled: FALSE];
522 [o_mi_chapter setEnabled: FALSE];
523 [o_mi_language setEnabled: FALSE];
524 [o_mi_subtitle setEnabled: FALSE];
525 [o_mi_channels setEnabled: FALSE];
526 [o_mi_screen setEnabled: FALSE];
534 NSString * o_menu_title;
535 char psz_title[ 256 ];
537 es_descriptor_t * p_audio_es = NULL;
538 es_descriptor_t * p_spu_es = NULL;
540 intf_thread_t * p_intf = [NSApp getIntf];
542 p_intf->p_sys->b_chapter_update |= p_intf->p_sys->b_title_update;
543 p_intf->p_sys->b_audio_update |= p_intf->p_sys->b_title_update |
544 p_intf->p_sys->b_program_update;
545 p_intf->p_sys->b_spu_update |= p_intf->p_sys->b_title_update |
546 p_intf->p_sys->b_program_update;
548 #define p_input (p_intf->p_sys->p_input)
550 if( p_intf->p_sys->b_program_update )
553 SEL pf_toggle_program;
554 pgrm_descriptor_t * p_pgrm;
556 if( p_input->stream.p_new_program )
558 p_pgrm = p_input->stream.p_new_program;
562 p_pgrm = p_input->stream.p_selected_program;
565 o_program = [o_mi_program submenu];
566 pf_toggle_program = @selector(toggleProgram:);
568 /* remove previous program items */
569 i_nb_items = [o_program numberOfItems];
570 for( i = 0; i < i_nb_items; i++ )
572 [o_program removeItemAtIndex: 0];
575 /* make (un)sensitive */
576 [o_mi_program setEnabled:
577 p_input->stream.i_pgrm_number > 1];
579 /* add program items */
580 for( i = 0 ; i < p_input->stream.i_pgrm_number ; i++ )
582 snprintf( psz_title, sizeof(psz_title), "id %d",
583 p_input->stream.pp_programs[i]->i_number );
584 psz_title[sizeof(psz_title) - 1] = '\0';
586 o_menu_title = [NSString stringWithCString: psz_title];
588 o_item = [o_program addItemWithTitle: o_menu_title
589 action: pf_toggle_program keyEquivalent: @""];
590 [o_item setTag: p_input->stream.pp_programs[i]->i_number];
591 [o_item setTarget: o_controls];
593 if( p_pgrm == p_input->stream.pp_programs[i] )
595 [o_item setState: NSOnState];
599 p_intf->p_sys->b_program_update = 0;
602 if( p_intf->p_sys->b_title_update )
607 o_title = [o_mi_title submenu];
608 pf_toggle_title = @selector(toggleTitle:);
610 /* remove previous title items */
611 i_nb_items = [o_title numberOfItems];
612 for( i = 0; i < i_nb_items; i++ )
614 [o_title removeItemAtIndex: 0];
617 /* make (un)sensitive */
618 [o_mi_title setEnabled:
619 p_input->stream.i_area_nb > 1];
621 /* add title items */
622 for( i = 1 ; i < p_input->stream.i_area_nb ; i++ )
624 snprintf( psz_title, sizeof(psz_title), "Title %d (%d)", i,
625 p_input->stream.pp_areas[i]->i_part_nb );
626 psz_title[sizeof(psz_title) - 1] = '\0';
628 o_menu_title = [NSString stringWithCString: psz_title];
630 o_item = [o_title addItemWithTitle: o_menu_title
631 action: pf_toggle_title keyEquivalent: @""];
633 [o_item setTarget: o_controls];
635 if( ( p_input->stream.pp_areas[i] ==
636 p_input->stream.p_selected_area ) )
638 [o_item setState: NSOnState];
642 p_intf->p_sys->b_title_update = 0;
645 if( p_intf->p_sys->b_chapter_update )
648 SEL pf_toggle_chapter;
650 o_chapter = [o_mi_chapter submenu];
651 pf_toggle_chapter = @selector(toggleChapter:);
653 /* remove previous chapter items */
654 i_nb_items = [o_chapter numberOfItems];
655 for( i = 0; i < i_nb_items; i++ )
657 [o_chapter removeItemAtIndex: 0];
660 /* make (un)sensitive */
661 [o_mi_chapter setEnabled:
662 p_input->stream.p_selected_area->i_part_nb > 1];
664 /* add chapter items */
665 for( i = 0 ; i < p_input->stream.p_selected_area->i_part_nb ; i++ )
667 snprintf( psz_title, sizeof(psz_title), "Chapter %d", i + 1 );
668 psz_title[sizeof(psz_title) - 1] = '\0';
670 o_menu_title = [NSString stringWithCString: psz_title];
672 o_item = [o_chapter addItemWithTitle: o_menu_title
673 action: pf_toggle_chapter keyEquivalent: @""];
674 [o_item setTag: i + 1];
675 [o_item setTarget: o_controls];
677 if( ( p_input->stream.p_selected_area->i_part == i + 1 ) )
679 [o_item setState: NSOnState];
683 p_intf->p_sys->i_part =
684 p_input->stream.p_selected_area->i_part;
686 p_intf->p_sys->b_chapter_update = 0;
689 for( i = 0 ; i < p_input->stream.i_selected_es_number ; i++ )
691 if( p_input->stream.pp_selected_es[i]->i_cat == SPU_ES )
693 p_audio_es = p_input->stream.pp_selected_es[i];
695 else if( p_input->stream.pp_selected_es[i]->i_cat == SPU_ES )
697 p_spu_es = p_input->stream.pp_selected_es[i];
701 vlc_mutex_unlock( &p_input->stream.stream_lock );
703 if( p_intf->p_sys->b_audio_update )
705 [self setupLangMenu: o_mi_language es: p_audio_es
706 category: AUDIO_ES selector: @selector(toggleLanguage:)];
708 p_intf->p_sys->b_audio_update = 0;
711 if( p_intf->p_sys->b_spu_update )
713 [self setupLangMenu: o_mi_subtitle es: p_spu_es
714 category: SPU_ES selector: @selector(toggleLanguage:)];
716 p_intf->p_sys->b_spu_update = 0;
719 if ( p_intf->p_sys->b_aout_update )
721 aout_instance_t * p_aout = vlc_object_find( p_intf, VLC_OBJECT_AOUT,
724 if ( p_aout != NULL )
729 var_Set( (vlc_object_t *)p_aout, "intf-change", val );
731 [self setupVarMenu: o_mi_channels target: (vlc_object_t *)p_aout
732 var: "audio-channels" selector: @selector(toggleVar:)];
734 vlc_object_release( (vlc_object_t *)p_aout );
737 p_intf->p_sys->b_aout_update = 0;
740 if ( p_intf->p_sys->b_vout_update )
742 vout_thread_t * p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
745 if ( p_vout != NULL )
750 var_Set( (vlc_object_t *)p_vout, "intf-change", val );
752 [self setupVarMenu: o_mi_screen target: (vlc_object_t *)p_vout
753 var: "video-device" selector: @selector(toggleVar:)];
755 vlc_object_release( (vlc_object_t *)p_vout );
758 p_intf->p_sys->b_vout_update = 0;
761 vlc_mutex_lock( &p_input->stream.stream_lock );
766 - (void)setupLangMenu:(NSMenuItem *)o_mi
767 es:(es_descriptor_t *)p_es
769 selector:(SEL)pf_callback
772 NSMenu * o_menu = [o_mi submenu];
773 intf_thread_t * p_intf = [NSApp getIntf];
775 /* remove previous language items */
776 i_nb_items = [o_menu numberOfItems];
777 for( i = 0; i < i_nb_items; i++ )
779 [o_menu removeItemAtIndex: 0];
782 /* make sensitive : we can't change it after we build the menu, and
783 * before, we don't yet how many items we will have. So make it
784 * always sensitive. --Meuuh */
785 [o_mi setEnabled: TRUE];
787 vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock );
789 #define ES p_intf->p_sys->p_input->stream.pp_es[i]
790 for( i = 0 ; i < p_intf->p_sys->p_input->stream.i_es_number ; i++ )
792 if( ( ES->i_cat == i_cat ) &&
795 p_intf->p_sys->p_input->stream.p_selected_program ) )
802 o_title = [NSString stringWithCString: ES->psz_desc];
806 char psz_title[ 256 ];
808 snprintf( psz_title, sizeof(psz_title), "Language 0x%x",
810 psz_title[sizeof(psz_title) - 1] = '\0';
812 o_title = [NSString stringWithCString: psz_title];
815 o_lmi = [o_menu addItemWithTitle: o_title
816 action: pf_callback keyEquivalent: @""];
817 [o_lmi setRepresentedObject:
818 [NSValue valueWithPointer: ES]];
819 [o_lmi setTarget: o_controls];
820 [o_lmi setTag: i_cat];
822 if( /*p_es == ES*/ ES->p_decoder_fifo != NULL )
824 [o_lmi setState: NSOnState];
830 vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock );
833 - (void)setupVarMenu:(NSMenuItem *)o_mi
834 target:(vlc_object_t *)p_object
835 var:(const char *)psz_variable
836 selector:(SEL)pf_callback
839 NSMenu * o_menu = [o_mi submenu];
842 vlc_value_t * p_vals;
845 /* remove previous items */
846 i_nb_items = [o_menu numberOfItems];
847 for( i = 0; i < i_nb_items; i++ )
849 [o_menu removeItemAtIndex: 0];
852 if ( var_Get( p_object, psz_variable, &val ) < 0 )
856 psz_value = val.psz_string;
858 if ( var_Change( p_object, psz_variable,
859 VLC_VAR_GETLIST, &val ) < 0 )
865 i_vals = ((vlc_value_t *)val.p_address)[0].i_int;
866 p_vals = &((vlc_value_t *)val.p_address)[1]; /* Starts at index 1 */
868 /* make (un)sensitive */
869 [o_mi setEnabled: (i_vals > 0)];
871 for ( i = 0; i < i_vals; i++ )
876 o_title = [NSString stringWithCString: p_vals[i].psz_string];
877 o_lmi = [o_menu addItemWithTitle: o_title
878 action: pf_callback keyEquivalent: @""];
879 /* FIXME: this isn't 64-bit clean ! */
880 [o_lmi setTag: (int)psz_variable];
881 [o_lmi setRepresentedObject:
882 [NSValue valueWithPointer: p_object]];
883 [o_lmi setTarget: o_controls];
885 if ( !strcmp( psz_value, p_vals[i].psz_string ) )
886 [o_lmi setState: NSOnState];
889 var_Change( p_object, psz_variable, VLC_VAR_FREELIST,
895 - (IBAction)clearRecentItems:(id)sender
897 [[NSDocumentController sharedDocumentController]
898 clearRecentDocuments: nil];
901 - (void)openRecentItem:(id)sender
903 [self application: nil openFile: [sender title]];
906 - (IBAction)viewPreferences:(id)sender
910 o_prefs = [[VLCPrefs alloc] init];
913 [o_prefs createPrefPanel: @"main"];
918 @implementation VLCMain (NSMenuValidation)
920 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
922 BOOL bEnabled = TRUE;
924 /* Recent Items Menu */
926 if( [[o_mi title] isEqualToString: _NS("Clear Menu")] )
928 NSMenu * o_menu = [o_mi_open_recent submenu];
929 int i_nb_items = [o_menu numberOfItems];
930 NSArray * o_docs = [[NSDocumentController sharedDocumentController]
932 UInt32 i_nb_docs = [o_docs count];
936 while( --i_nb_items )
938 [o_menu removeItemAtIndex: 0];
947 [o_menu insertItem: [NSMenuItem separatorItem] atIndex: 0];
953 o_url = [o_docs objectAtIndex: i_nb_docs];
955 if( [o_url isFileURL] )
957 o_doc = [o_url path];
961 o_doc = [o_url absoluteString];
964 [o_menu insertItemWithTitle: o_doc
965 action: @selector(openRecentItem:)
966 keyEquivalent: @"" atIndex: 0];
985 @implementation VLCMain (Internal)
987 - (void)handlePortMessage:(NSPortMessage *)o_msg
991 NSInvocation * o_inv;
992 vout_thread_t * p_vout;
994 o_data = [[o_msg components] lastObject];
995 o_inv = *((NSInvocation **)[o_data bytes]);
996 [o_inv getArgument: &o_value atIndex: 2];
997 p_vout = (vout_thread_t *)[o_value pointerValue];
999 [p_vout->p_sys->o_lock lock];
1001 [p_vout->p_sys->o_lock unlockWithCondition: 1];