1 /*****************************************************************************
2 * intf.m: MacOS X interface plugin
3 *****************************************************************************
4 * Copyright (C) 2002 VideoLAN
5 * $Id: intf.m,v 1.10 2002/12/14 19:34:06 gbazin 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_generic setTitle: _NS("Open Generic...")];
200 [o_mi_open_disc setTitle: _NS("Open Disc...")];
201 [o_mi_open_net setTitle: _NS("Open Network...")];
202 [o_mi_open_recent setTitle: _NS("Open Recent")];
203 [o_mi_open_recent_cm setTitle: _NS("Clear Menu")];
205 [o_mu_edit setTitle: _NS("Edit")];
206 [o_mi_cut setTitle: _NS("Cut")];
207 [o_mi_copy setTitle: _NS("Copy")];
208 [o_mi_paste setTitle: _NS("Paste")];
209 [o_mi_clear setTitle: _NS("Clear")];
210 [o_mi_select_all setTitle: _NS("Select All")];
212 [o_mu_view setTitle: _NS("View")];
213 [o_mi_playlist setTitle: _NS("Playlist")];
214 [o_mi_messages setTitle: _NS("Messages")];
216 [o_mu_controls setTitle: _NS("Controls")];
217 [o_mi_play setTitle: _NS("Play")];
218 [o_mi_pause setTitle: _NS("Pause")];
219 [o_mi_stop setTitle: _NS("Stop")];
220 [o_mi_faster setTitle: _NS("Faster")];
221 [o_mi_slower setTitle: _NS("Slower")];
222 [o_mi_previous setTitle: _NS("Prev")];
223 [o_mi_next setTitle: _NS("Next")];
224 [o_mi_loop setTitle: _NS("Loop")];
225 [o_mi_vol_up setTitle: _NS("Louder")];
226 [o_mi_vol_down setTitle: _NS("Softer")];
227 [o_mi_mute setTitle: _NS("Mute")];
228 [o_mi_channels setTitle: _NS("Channels")];
229 [o_mi_fullscreen setTitle: _NS("Fullscreen")];
230 [o_mi_screen setTitle: _NS("Screen")];
231 [o_mi_deinterlace setTitle: _NS("Deinterlace")];
232 [o_mi_program setTitle: _NS("Program")];
233 [o_mi_title setTitle: _NS("Title")];
234 [o_mi_chapter setTitle: _NS("Chapter")];
235 [o_mi_language setTitle: _NS("Language")];
236 [o_mi_subtitle setTitle: _NS("Subtitles")];
238 [o_mu_window setTitle: _NS("Window")];
239 [o_mi_minimize setTitle: _NS("Minimize")];
240 [o_mi_bring_atf setTitle: _NS("Bring All to Front")];
243 [o_dmi_play setTitle: _NS("Play")];
244 [o_dmi_pause setTitle: _NS("Pause")];
245 [o_dmi_stop setTitle: _NS("Stop")];
250 - (void)applicationWillFinishLaunching:(NSNotification *)o_notification
252 intf_thread_t * p_intf = [NSApp getIntf];
254 [NSThread detachNewThreadSelector: @selector(manage)
255 toTarget: self withObject: nil];
257 [p_intf->p_sys->o_sendport setDelegate: self];
258 [[NSRunLoop currentRunLoop]
259 addPort: p_intf->p_sys->o_sendport
260 forMode: NSDefaultRunLoopMode];
262 // Since we need the sound menu now, it's a good time to create the sound system class
263 asystm=[[MacOSXAudioSystem alloc] initWithGUI:self];
268 - (void)noopAction:(id)sender {
272 - (BOOL)application:(NSApplication *)o_app openFile:(NSString *)o_filename
274 [o_playlist appendArray:
275 [NSArray arrayWithObject: o_filename] atPos: -1];
282 NSDate * o_sleep_date;
283 intf_thread_t * p_intf = [NSApp getIntf];
284 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
286 while( !p_intf->b_die )
290 vlc_mutex_lock( &p_intf->change_lock );
292 /* update the input */
293 if( p_intf->p_sys->p_input == NULL )
295 p_intf->p_sys->p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
298 else if( p_intf->p_sys->p_input->b_dead )
300 vlc_object_release( p_intf->p_sys->p_input );
301 p_intf->p_sys->p_input = NULL;
304 if( p_intf->p_sys->p_input != NULL )
306 vlc_bool_t b_need_menus = 0;
307 input_thread_t * p_input = p_intf->p_sys->p_input;
308 aout_instance_t * p_aout = vlc_object_find( p_intf, VLC_OBJECT_AOUT,
310 vout_thread_t * p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
313 vlc_mutex_lock( &p_input->stream.stream_lock );
315 if( !p_input->b_die )
317 /* New input or stream map change */
318 if( p_input->stream.b_changed )
322 p_intf->p_sys->b_playing = 1;
325 if( p_intf->p_sys->i_part !=
326 p_input->stream.p_selected_area->i_part )
328 p_intf->p_sys->b_chapter_update = 1;
333 if ( p_aout != NULL )
336 if ( var_Get( (vlc_object_t *)p_aout, "intf-change", &val )
339 p_intf->p_sys->b_aout_update = 1;
342 vlc_object_release( (vlc_object_t *)p_aout );
345 if ( p_vout != NULL )
348 if ( var_Get( (vlc_object_t *)p_vout, "intf-change", &val )
351 p_intf->p_sys->b_vout_update = 1;
354 vlc_object_release( (vlc_object_t *)p_vout );
360 vlc_mutex_unlock( &p_input->stream.stream_lock );
362 else if( p_intf->p_sys->b_playing && !p_intf->b_die )
365 p_intf->p_sys->b_playing = 0;
368 /* update the log window */
369 vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
370 i_stop = *p_intf->p_sys->p_sub->pi_stop;
371 vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
373 if( p_intf->p_sys->p_sub->i_start != i_stop )
375 NSColor *o_white = [NSColor whiteColor];
376 NSColor *o_red = [NSColor redColor];
377 NSColor *o_yellow = [NSColor yellowColor];
378 NSColor *o_gray = [NSColor grayColor];
380 unsigned int ui_length = [[o_messages string] length];
382 NSColor * pp_color[4] = { o_white, o_red, o_yellow, o_gray };
383 static const char * ppsz_type[4] = { ": ", " error: ",
384 " warning: ", " debug: " };
386 [o_messages setEditable: YES];
387 [o_messages setSelectedRange: NSMakeRange( ui_length, 0 )];
388 [o_messages scrollRangeToVisible: NSMakeRange( ui_length, 0 )];
390 for( i_start = p_intf->p_sys->p_sub->i_start;
392 i_start = (i_start+1) % VLC_MSG_QSIZE )
395 NSDictionary *o_attr;
396 NSAttributedString *o_msg_color;
397 int i_type = p_intf->p_sys->p_sub->p_msg[i_start].i_type;
399 o_attr = [NSDictionary dictionaryWithObject: o_gray
400 forKey: NSForegroundColorAttributeName];
401 o_msg = [NSString stringWithFormat: @"%s%s",
402 p_intf->p_sys->p_sub->p_msg[i_start].psz_module,
404 o_msg_color = [[NSAttributedString alloc]
405 initWithString: o_msg attributes: o_attr];
406 [o_messages insertText: o_msg_color];
408 o_attr = [NSDictionary dictionaryWithObject: pp_color[i_type]
409 forKey: NSForegroundColorAttributeName];
410 o_msg = [NSString stringWithCString:
411 p_intf->p_sys->p_sub->p_msg[i_start].psz_msg];
412 o_msg_color = [[NSAttributedString alloc]
413 initWithString: o_msg attributes: o_attr];
414 [o_messages insertText: o_msg_color];
416 [o_messages insertText: @"\n"];
419 [o_messages setEditable: NO];
421 vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
422 p_intf->p_sys->p_sub->i_start = i_start;
423 vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
426 vlc_mutex_unlock( &p_intf->change_lock );
428 o_sleep_date = [NSDate dateWithTimeIntervalSinceNow: 0.1];
429 [NSThread sleepUntilDate: o_sleep_date];
440 vout_thread_t * p_vout;
441 playlist_t * p_playlist;
442 intf_thread_t * p_intf = [NSApp getIntf];
445 if( p_intf->p_sys->p_input )
447 vlc_object_release( p_intf->p_sys->p_input );
448 p_intf->p_sys->p_input = NULL;
454 msg_Dbg( p_intf, "removing all playlists" );
455 while( (p_playlist = vlc_object_find( p_intf->p_vlc, VLC_OBJECT_PLAYLIST,
458 vlc_object_detach( p_playlist );
459 vlc_object_release( p_playlist );
460 playlist_Destroy( p_playlist );
466 msg_Dbg( p_intf, "removing all video outputs" );
467 while( (p_vout = vlc_object_find( p_intf->p_vlc,
468 VLC_OBJECT_VOUT, FIND_CHILD )) )
470 vlc_object_detach( p_vout );
471 vlc_object_release( p_vout );
472 vout_Destroy( p_vout );
483 /* write cached user defaults to disk */
484 [[NSUserDefaults standardUserDefaults] synchronize];
486 /* send a dummy event to break out of the event loop */
487 pEvent = [NSEvent mouseEventWithType: NSLeftMouseDown
488 location: NSMakePoint( 1, 1 ) modifierFlags: 0
489 timestamp: 1 windowNumber: [[NSApp mainWindow] windowNumber]
490 context: [NSGraphicsContext currentContext] eventNumber: 1
491 clickCount: 1 pressure: 0.0];
492 [NSApp postEvent: pEvent atStart: YES];
499 vlc_bool_t b_control = 0;
500 intf_thread_t * p_intf = [NSApp getIntf];
502 if( p_intf->p_sys->p_input != NULL )
504 /* control buttons for free pace streams */
505 b_control = p_intf->p_sys->p_input->stream.b_pace_control;
507 /* get ready for menu regeneration */
508 p_intf->p_sys->b_program_update = 1;
509 p_intf->p_sys->b_title_update = 1;
510 p_intf->p_sys->b_chapter_update = 1;
511 p_intf->p_sys->b_audio_update = 1;
512 p_intf->p_sys->b_spu_update = 1;
513 p_intf->p_sys->i_part = 0;
515 p_intf->p_sys->p_input->stream.b_changed = 0;
516 msg_Dbg( p_intf, "stream has changed, refreshing interface" );
520 /* unsensitize menus */
521 [o_mi_program setEnabled: FALSE];
522 [o_mi_title setEnabled: FALSE];
523 [o_mi_chapter setEnabled: FALSE];
524 [o_mi_language setEnabled: FALSE];
525 [o_mi_subtitle setEnabled: FALSE];
526 [o_mi_channels setEnabled: FALSE];
527 [o_mi_screen setEnabled: FALSE];
535 NSString * o_menu_title;
536 char psz_title[ 256 ];
538 es_descriptor_t * p_audio_es = NULL;
539 es_descriptor_t * p_spu_es = NULL;
541 intf_thread_t * p_intf = [NSApp getIntf];
543 p_intf->p_sys->b_chapter_update |= p_intf->p_sys->b_title_update;
544 p_intf->p_sys->b_audio_update |= p_intf->p_sys->b_title_update |
545 p_intf->p_sys->b_program_update;
546 p_intf->p_sys->b_spu_update |= p_intf->p_sys->b_title_update |
547 p_intf->p_sys->b_program_update;
549 #define p_input (p_intf->p_sys->p_input)
551 if( p_intf->p_sys->b_program_update )
554 SEL pf_toggle_program;
555 pgrm_descriptor_t * p_pgrm;
557 if( p_input->stream.p_new_program )
559 p_pgrm = p_input->stream.p_new_program;
563 p_pgrm = p_input->stream.p_selected_program;
566 o_program = [o_mi_program submenu];
567 pf_toggle_program = @selector(toggleProgram:);
569 /* remove previous program items */
570 i_nb_items = [o_program numberOfItems];
571 for( i = 0; i < i_nb_items; i++ )
573 [o_program removeItemAtIndex: 0];
576 /* make (un)sensitive */
577 [o_mi_program setEnabled:
578 p_input->stream.i_pgrm_number > 1];
580 /* add program items */
581 for( i = 0 ; i < p_input->stream.i_pgrm_number ; i++ )
583 snprintf( psz_title, sizeof(psz_title), "id %d",
584 p_input->stream.pp_programs[i]->i_number );
585 psz_title[sizeof(psz_title) - 1] = '\0';
587 o_menu_title = [NSString stringWithCString: psz_title];
589 o_item = [o_program addItemWithTitle: o_menu_title
590 action: pf_toggle_program keyEquivalent: @""];
591 [o_item setTag: p_input->stream.pp_programs[i]->i_number];
592 [o_item setTarget: o_controls];
594 if( p_pgrm == p_input->stream.pp_programs[i] )
596 [o_item setState: NSOnState];
600 p_intf->p_sys->b_program_update = 0;
603 if( p_intf->p_sys->b_title_update )
608 o_title = [o_mi_title submenu];
609 pf_toggle_title = @selector(toggleTitle:);
611 /* remove previous title items */
612 i_nb_items = [o_title numberOfItems];
613 for( i = 0; i < i_nb_items; i++ )
615 [o_title removeItemAtIndex: 0];
618 /* make (un)sensitive */
619 [o_mi_title setEnabled:
620 p_input->stream.i_area_nb > 1];
622 /* add title items */
623 for( i = 1 ; i < p_input->stream.i_area_nb ; i++ )
625 snprintf( psz_title, sizeof(psz_title), "Title %d (%d)", i,
626 p_input->stream.pp_areas[i]->i_part_nb );
627 psz_title[sizeof(psz_title) - 1] = '\0';
629 o_menu_title = [NSString stringWithCString: psz_title];
631 o_item = [o_title addItemWithTitle: o_menu_title
632 action: pf_toggle_title keyEquivalent: @""];
634 [o_item setTarget: o_controls];
636 if( ( p_input->stream.pp_areas[i] ==
637 p_input->stream.p_selected_area ) )
639 [o_item setState: NSOnState];
643 p_intf->p_sys->b_title_update = 0;
646 if( p_intf->p_sys->b_chapter_update )
649 SEL pf_toggle_chapter;
651 o_chapter = [o_mi_chapter submenu];
652 pf_toggle_chapter = @selector(toggleChapter:);
654 /* remove previous chapter items */
655 i_nb_items = [o_chapter numberOfItems];
656 for( i = 0; i < i_nb_items; i++ )
658 [o_chapter removeItemAtIndex: 0];
661 /* make (un)sensitive */
662 [o_mi_chapter setEnabled:
663 p_input->stream.p_selected_area->i_part_nb > 1];
665 /* add chapter items */
666 for( i = 0 ; i < p_input->stream.p_selected_area->i_part_nb ; i++ )
668 snprintf( psz_title, sizeof(psz_title), "Chapter %d", i + 1 );
669 psz_title[sizeof(psz_title) - 1] = '\0';
671 o_menu_title = [NSString stringWithCString: psz_title];
673 o_item = [o_chapter addItemWithTitle: o_menu_title
674 action: pf_toggle_chapter keyEquivalent: @""];
675 [o_item setTag: i + 1];
676 [o_item setTarget: o_controls];
678 if( ( p_input->stream.p_selected_area->i_part == i + 1 ) )
680 [o_item setState: NSOnState];
684 p_intf->p_sys->i_part =
685 p_input->stream.p_selected_area->i_part;
687 p_intf->p_sys->b_chapter_update = 0;
690 for( i = 0 ; i < p_input->stream.i_selected_es_number ; i++ )
692 if( p_input->stream.pp_selected_es[i]->i_cat == SPU_ES )
694 p_audio_es = p_input->stream.pp_selected_es[i];
696 else if( p_input->stream.pp_selected_es[i]->i_cat == SPU_ES )
698 p_spu_es = p_input->stream.pp_selected_es[i];
702 vlc_mutex_unlock( &p_input->stream.stream_lock );
704 if( p_intf->p_sys->b_audio_update )
706 [self setupLangMenu: o_mi_language es: p_audio_es
707 category: AUDIO_ES selector: @selector(toggleLanguage:)];
709 p_intf->p_sys->b_audio_update = 0;
712 if( p_intf->p_sys->b_spu_update )
714 [self setupLangMenu: o_mi_subtitle es: p_spu_es
715 category: SPU_ES selector: @selector(toggleLanguage:)];
717 p_intf->p_sys->b_spu_update = 0;
720 if ( p_intf->p_sys->b_aout_update )
722 aout_instance_t * p_aout = vlc_object_find( p_intf, VLC_OBJECT_AOUT,
725 if ( p_aout != NULL )
730 var_Set( (vlc_object_t *)p_aout, "intf-change", val );
732 [self setupVarMenu: o_mi_channels target: (vlc_object_t *)p_aout
733 var: "audio-channels" selector: @selector(toggleVar:)];
735 vlc_object_release( (vlc_object_t *)p_aout );
738 p_intf->p_sys->b_aout_update = 0;
741 if ( p_intf->p_sys->b_vout_update )
743 vout_thread_t * p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
746 if ( p_vout != NULL )
751 var_Set( (vlc_object_t *)p_vout, "intf-change", val );
753 [self setupVarMenu: o_mi_screen target: (vlc_object_t *)p_vout
754 var: "video-device" selector: @selector(toggleVar:)];
756 vlc_object_release( (vlc_object_t *)p_vout );
759 p_intf->p_sys->b_vout_update = 0;
762 vlc_mutex_lock( &p_input->stream.stream_lock );
767 - (void)setupLangMenu:(NSMenuItem *)o_mi
768 es:(es_descriptor_t *)p_es
770 selector:(SEL)pf_callback
773 NSMenu * o_menu = [o_mi submenu];
774 intf_thread_t * p_intf = [NSApp getIntf];
776 /* remove previous language items */
777 i_nb_items = [o_menu numberOfItems];
778 for( i = 0; i < i_nb_items; i++ )
780 [o_menu removeItemAtIndex: 0];
783 /* make sensitive : we can't change it after we build the menu, and
784 * before, we don't yet how many items we will have. So make it
785 * always sensitive. --Meuuh */
786 [o_mi setEnabled: TRUE];
788 vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock );
790 #define ES p_intf->p_sys->p_input->stream.pp_es[i]
791 for( i = 0 ; i < p_intf->p_sys->p_input->stream.i_es_number ; i++ )
793 if( ( ES->i_cat == i_cat ) &&
796 p_intf->p_sys->p_input->stream.p_selected_program ) )
803 o_title = [NSString stringWithCString: ES->psz_desc];
807 char psz_title[ 256 ];
809 snprintf( psz_title, sizeof(psz_title), "Language 0x%x",
811 psz_title[sizeof(psz_title) - 1] = '\0';
813 o_title = [NSString stringWithCString: psz_title];
816 o_lmi = [o_menu addItemWithTitle: o_title
817 action: pf_callback keyEquivalent: @""];
818 [o_lmi setRepresentedObject:
819 [NSValue valueWithPointer: ES]];
820 [o_lmi setTarget: o_controls];
821 [o_lmi setTag: i_cat];
823 if( /*p_es == ES*/ ES->p_decoder_fifo != NULL )
825 [o_lmi setState: NSOnState];
831 vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock );
834 - (void)setupVarMenu:(NSMenuItem *)o_mi
835 target:(vlc_object_t *)p_object
836 var:(const char *)psz_variable
837 selector:(SEL)pf_callback
840 NSMenu * o_menu = [o_mi submenu];
844 /* remove previous items */
845 i_nb_items = [o_menu numberOfItems];
846 for( i = 0; i < i_nb_items; i++ )
848 [o_menu removeItemAtIndex: 0];
851 if ( var_Get( p_object, psz_variable, &val ) < 0 )
855 psz_value = val.psz_string;
857 if ( var_Change( p_object, psz_variable,
858 VLC_VAR_GETLIST, &val ) < 0 )
864 /* make (un)sensitive */
865 [o_mi setEnabled: (val.p_list->i_count > 0)];
867 for ( i = 0; i < val.p_list->i_count; i++ )
872 o_title = [NSString stringWithCString: val.p_list->p_values[i].psz_string];
873 o_lmi = [o_menu addItemWithTitle: o_title
874 action: pf_callback keyEquivalent: @""];
875 /* FIXME: this isn't 64-bit clean ! */
876 [o_lmi setTag: (int)psz_variable];
877 [o_lmi setRepresentedObject:
878 [NSValue valueWithPointer: p_object]];
879 [o_lmi setTarget: o_controls];
881 if ( !strcmp( psz_value, val.p_list->p_values[i].psz_string ) )
882 [o_lmi setState: NSOnState];
885 var_Change( p_object, psz_variable, VLC_VAR_FREELIST,
891 - (IBAction)clearRecentItems:(id)sender
893 [[NSDocumentController sharedDocumentController]
894 clearRecentDocuments: nil];
897 - (void)openRecentItem:(id)sender
899 [self application: nil openFile: [sender title]];
902 - (IBAction)viewPreferences:(id)sender
906 o_prefs = [[VLCPrefs alloc] init];
909 [o_prefs createPrefPanel: @"main"];
919 @implementation VLCMain (NSMenuValidation)
921 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
923 BOOL bEnabled = TRUE;
925 /* Recent Items Menu */
927 if( [[o_mi title] isEqualToString: _NS("Clear Menu")] )
929 NSMenu * o_menu = [o_mi_open_recent submenu];
930 int i_nb_items = [o_menu numberOfItems];
931 NSArray * o_docs = [[NSDocumentController sharedDocumentController]
933 UInt32 i_nb_docs = [o_docs count];
937 while( --i_nb_items )
939 [o_menu removeItemAtIndex: 0];
948 [o_menu insertItem: [NSMenuItem separatorItem] atIndex: 0];
954 o_url = [o_docs objectAtIndex: i_nb_docs];
956 if( [o_url isFileURL] )
958 o_doc = [o_url path];
962 o_doc = [o_url absoluteString];
965 [o_menu insertItemWithTitle: o_doc
966 action: @selector(openRecentItem:)
967 keyEquivalent: @"" atIndex: 0];
986 @implementation VLCMain (Internal)
988 - (void)handlePortMessage:(NSPortMessage *)o_msg
992 NSInvocation * o_inv;
993 vout_thread_t * p_vout;
995 o_data = [[o_msg components] lastObject];
996 o_inv = *((NSInvocation **)[o_data bytes]);
997 [o_inv getArgument: &o_value atIndex: 2];
998 p_vout = (vout_thread_t *)[o_value pointerValue];
1000 [p_vout->p_sys->o_lock lock];
1002 [p_vout->p_sys->o_lock unlockWithCondition: 1];