1 /*****************************************************************************
2 * controls.m: MacOS X interface module
3 *****************************************************************************
4 * Copyright (C) 2002-2009 the VideoLAN team
7 * Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
8 * Christophe Massiot <massiot@via.ecp.fr>
9 * Derk-Jan Hartman <hartman at videolan dot org>
10 * Benjamin Pracht <bigben at videolan doit org>
11 * Felix Paul Kühne <fkuehne at videolan dot org>
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
26 *****************************************************************************/
28 /*****************************************************************************
30 *****************************************************************************/
31 #include <stdlib.h> /* malloc(), free() */
32 #include <sys/param.h> /* for MAXPATHLEN */
43 /*****************************************************************************
44 * VLCAutoGeneratedMenuContent interface
45 *****************************************************************************
46 * This holds our data for autogenerated menus
47 *****************************************************************************/
48 @interface VLCAutoGeneratedMenuContent : NSObject
51 vlc_object_t * _vlc_object;
56 - (id)initWithVariableName: (const char *)name
57 ofObject: (vlc_object_t *)object
58 andValue: (vlc_value_t)value
62 - (vlc_object_t *)vlcObject;
68 /*****************************************************************************
69 * VLCControls implementation
70 *****************************************************************************/
71 @implementation VLCControls
76 o_fs_panel = [[VLCFSPanel alloc] init];
82 [o_specificTime_mi setTitle: _NS("Jump To Time")];
83 [o_specificTime_cancel_btn setTitle: _NS("Cancel")];
84 [o_specificTime_ok_btn setTitle: _NS("OK")];
85 [o_specificTime_sec_lbl setStringValue: _NS("sec.")];
86 [o_specificTime_goTo_lbl setStringValue: _NS("Jump to time")];
88 o_repeat_off = [NSImage imageNamed:@"repeat_embedded"];
90 [self controlTintChanged];
92 [[NSNotificationCenter defaultCenter] addObserver: self
93 selector: @selector( controlTintChanged )
94 name: NSControlTintDidChangeNotification
98 - (void)controlTintChanged
101 if( [o_btn_repeat image] == o_repeat_single )
103 else if( [o_btn_repeat image] == o_repeat_all )
106 if( [NSColor currentControlTint] == NSGraphiteControlTint )
108 o_repeat_single = [NSImage imageNamed:@"repeat_single_embedded_graphite"];
109 o_repeat_all = [NSImage imageNamed:@"repeat_embedded_graphite"];
111 [o_btn_shuffle setAlternateImage: [NSImage imageNamed: @"shuffle_embedded_graphite"]];
112 [o_btn_addNode setAlternateImage: [NSImage imageNamed: @"add_embedded_graphite"]];
116 o_repeat_single = [NSImage imageNamed:@"repeat_single_embedded_blue"];
117 o_repeat_all = [NSImage imageNamed:@"repeat_embedded_blue"];
119 [o_btn_shuffle setAlternateImage: [NSImage imageNamed: @"shuffle_embedded_blue"]];
120 [o_btn_addNode setAlternateImage: [NSImage imageNamed: @"add_embedded_blue"]];
123 /* update the repeat button, but keep its state */
126 else if( i_repeat == 2 )
134 [[NSNotificationCenter defaultCenter] removeObserver: self];
136 [o_repeat_single release];
137 [o_repeat_all release];
138 [o_repeat_off release];
143 - (IBAction)play:(id)sender
145 intf_thread_t * p_intf = VLCIntf;
146 playlist_t * p_playlist = pl_Hold( p_intf );
150 empty = playlist_IsEmpty( p_playlist );
153 pl_Release( p_intf );
156 [o_main intfOpenFileGeneric: (id)sender];
158 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_PLAY_PAUSE );
165 id embeddedViewList = [[VLCMain sharedInstance] embeddedList];
166 NSEnumerator *enumerator = [[NSApp orderedWindows] objectEnumerator];
167 while( !voutView && ( window = [enumerator nextObject] ) )
169 /* We have an embedded vout */
170 if( [embeddedViewList windowContainsEmbedded: window] )
172 voutView = [embeddedViewList viewForWindow: window];
174 /* We have a detached vout */
175 else if( [[window className] isEqualToString: @"VLCVoutWindow"] )
177 voutView = [window voutView];
180 return [[voutView retain] autorelease];
183 - (IBAction)stop:(id)sender
185 intf_thread_t * p_intf = VLCIntf;
186 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_STOP );
187 /* Close the window directly, because we do know that there
188 * won't be anymore video. It's currently waiting a bit. */
189 [[[self voutView] window] orderOut:self];
192 - (IBAction)faster:(id)sender
194 intf_thread_t * p_intf = VLCIntf;
195 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_FASTER );
198 - (IBAction)slower:(id)sender
200 intf_thread_t * p_intf = VLCIntf;
201 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_SLOWER );
204 - (IBAction)prev:(id)sender
206 intf_thread_t * p_intf = VLCIntf;
207 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_PREV );
210 - (IBAction)next:(id)sender
212 intf_thread_t * p_intf = VLCIntf;
213 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_NEXT );
216 - (IBAction)random:(id)sender
219 intf_thread_t * p_intf = VLCIntf;
220 playlist_t * p_playlist = pl_Hold( p_intf );
222 var_Get( p_playlist, "random", &val );
223 val.b_bool = !val.b_bool;
224 var_Set( p_playlist, "random", val );
227 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Random On" ) );
228 config_PutInt( p_playlist, "random", 1 );
232 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Random Off" ) );
233 config_PutInt( p_playlist, "random", 0 );
236 p_intf->p_sys->b_playmode_update = true;
237 p_intf->p_sys->b_intf_update = true;
238 pl_Release( p_intf );
241 /* three little ugly helpers */
244 [o_btn_repeat setImage: o_repeat_single];
245 [o_btn_repeat setAlternateImage: o_repeat_all];
249 [o_btn_repeat setImage: o_repeat_all];
250 [o_btn_repeat setAlternateImage: o_repeat_off];
254 [o_btn_repeat setImage: o_repeat_off];
255 [o_btn_repeat setAlternateImage: o_repeat_single];
260 playlist_t *p_playlist = pl_Hold( VLCIntf );
261 var_Get( p_playlist, "random", &val );
262 [o_btn_shuffle setState: val.b_bool];
263 pl_Release( VLCIntf );
266 - (IBAction)repeatButtonAction:(id)sender
268 vlc_value_t looping,repeating;
269 intf_thread_t * p_intf = VLCIntf;
270 playlist_t * p_playlist = pl_Hold( p_intf );
272 var_Get( p_playlist, "repeat", &repeating );
273 var_Get( p_playlist, "loop", &looping );
275 if( !repeating.b_bool && !looping.b_bool )
277 /* was: no repeating at all, switching to Repeat One */
279 /* set our button's look */
282 /* prepare core communication */
283 repeating.b_bool = true;
284 looping.b_bool = false;
285 config_PutInt( p_playlist, "repeat", 1 );
286 config_PutInt( p_playlist, "loop", 0 );
288 /* show the change */
289 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat One" ) );
291 else if( repeating.b_bool && !looping.b_bool )
293 /* was: Repeat One, switching to Repeat All */
295 /* set our button's look */
298 /* prepare core communication */
299 repeating.b_bool = false;
300 looping.b_bool = true;
301 config_PutInt( p_playlist, "repeat", 0 );
302 config_PutInt( p_playlist, "loop", 1 );
304 /* show the change */
305 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat All" ) );
309 /* was: Repeat All or bug in VLC, switching to Repeat Off */
311 /* set our button's look */
314 /* prepare core communication */
315 repeating.b_bool = false;
316 looping.b_bool = false;
317 config_PutInt( p_playlist, "repeat", 0 );
318 config_PutInt( p_playlist, "loop", 0 );
320 /* show the change */
321 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat Off" ) );
324 /* communicate with core and the main intf loop */
325 var_Set( p_playlist, "repeat", repeating );
326 var_Set( p_playlist, "loop", looping );
327 p_intf->p_sys->b_playmode_update = true;
328 p_intf->p_sys->b_intf_update = true;
330 pl_Release( p_intf );
334 - (IBAction)repeat:(id)sender
337 intf_thread_t * p_intf = VLCIntf;
338 playlist_t * p_playlist = pl_Hold( p_intf );
340 var_Get( p_playlist, "repeat", &val );
343 var_Set( p_playlist, "loop", val );
345 val.b_bool = !val.b_bool;
346 var_Set( p_playlist, "repeat", val );
349 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat One" ) );
350 config_PutInt( p_playlist, "repeat", 1 );
354 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat Off" ) );
355 config_PutInt( p_playlist, "repeat", 0 );
358 p_intf->p_sys->b_playmode_update = true;
359 p_intf->p_sys->b_intf_update = true;
360 pl_Release( p_intf );
363 - (IBAction)loop:(id)sender
366 intf_thread_t * p_intf = VLCIntf;
367 playlist_t * p_playlist = pl_Hold( p_intf );
369 var_Get( p_playlist, "loop", &val );
372 var_Set( p_playlist, "repeat", val );
374 val.b_bool = !val.b_bool;
375 var_Set( p_playlist, "loop", val );
378 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat All" ) );
379 config_PutInt( p_playlist, "loop", 1 );
383 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat Off" ) );
384 config_PutInt( p_playlist, "loop", 0 );
387 p_intf->p_sys->b_playmode_update = true;
388 p_intf->p_sys->b_intf_update = true;
389 pl_Release( p_intf );
392 - (IBAction)forward:(id)sender
394 intf_thread_t * p_intf = VLCIntf;
395 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_JUMP_FORWARD_SHORT );
398 - (IBAction)backward:(id)sender
401 intf_thread_t * p_intf = VLCIntf;
402 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_JUMP_BACKWARD_SHORT );
406 - (IBAction)volumeUp:(id)sender
408 intf_thread_t * p_intf = VLCIntf;
409 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_VOL_UP );
410 /* Manage volume status */
411 [o_main manageVolumeSlider];
414 - (IBAction)volumeDown:(id)sender
416 intf_thread_t * p_intf = VLCIntf;
417 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_VOL_DOWN );
418 /* Manage volume status */
419 [o_main manageVolumeSlider];
422 - (IBAction)mute:(id)sender
424 intf_thread_t * p_intf = VLCIntf;
425 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_VOL_MUTE );
426 /* Manage volume status */
427 [o_main manageVolumeSlider];
430 - (IBAction)volumeSliderUpdated:(id)sender
432 intf_thread_t * p_intf = VLCIntf;
433 audio_volume_t i_volume = (audio_volume_t)[sender intValue];
434 int i_volume_step = 0;
435 i_volume_step = config_GetInt( p_intf->p_libvlc, "volume-step" );
436 aout_VolumeSet( p_intf, i_volume * i_volume_step );
437 /* Manage volume status */
438 [o_main manageVolumeSlider];
441 - (IBAction)showPosition: (id)sender
443 vout_thread_t *p_vout = vlc_object_find( VLCIntf, VLC_OBJECT_VOUT,
447 intf_thread_t * p_intf = VLCIntf;
448 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_POSITION );
449 vlc_object_release( (vlc_object_t *)p_vout );
453 - (IBAction)toogleFullscreen:(id)sender {
454 NSMenuItem *o_mi = [[NSMenuItem alloc] initWithTitle: _NS("Fullscreen") action: nil keyEquivalent:@""];
455 [self windowAction: [o_mi autorelease]];
458 - (BOOL) isFullscreen {
459 id o_vout_view = [self voutView];
462 return [o_vout_view isFullscreen];
467 - (IBAction)windowAction:(id)sender
469 NSString *o_title = [sender title];
471 vout_thread_t *p_vout = vlc_object_find( VLCIntf, VLC_OBJECT_VOUT,
475 id o_vout_view = [self voutView];
478 if( [o_title isEqualToString: _NS("Half Size") ] )
479 [o_vout_view scaleWindowWithFactor: 0.5 animate: YES];
480 else if( [o_title isEqualToString: _NS("Normal Size") ] )
481 [o_vout_view scaleWindowWithFactor: 1.0 animate: YES];
482 else if( [o_title isEqualToString: _NS("Double Size") ] )
483 [o_vout_view scaleWindowWithFactor: 2.0 animate: YES];
484 else if( [o_title isEqualToString: _NS("Float on Top") ] )
485 [o_vout_view toggleFloatOnTop];
486 else if( [o_title isEqualToString: _NS("Fit to Screen") ] )
488 id o_window = [o_vout_view voutWindow];
489 if( ![o_window isZoomed] )
490 [o_window performZoom:self];
492 else if( [o_title isEqualToString: _NS("Snapshot") ] )
494 [o_vout_view snapshot];
498 /* Fullscreen state for next time will be saved here too */
499 [o_vout_view toggleFullscreen];
502 vlc_object_release( (vlc_object_t *)p_vout );
506 playlist_t * p_playlist = pl_Hold( VLCIntf );
508 if( [o_title isEqualToString: _NS("Fullscreen")] ||
509 [sender isKindOfClass:[NSButton class]] )
512 var_Get( p_playlist, "fullscreen", &val );
513 var_Set( p_playlist, "fullscreen", (vlc_value_t)!val.b_bool );
516 pl_Release( VLCIntf );
521 - (IBAction)telxTransparent:(id)sender
523 intf_thread_t * p_intf = VLCIntf;
525 p_vbi = (vlc_object_t *) vlc_object_find_name( p_intf,
526 "zvbi", FIND_ANYWHERE );
529 var_SetBool( p_vbi, "vbi-opaque", [sender state] );
530 [sender setState: ![sender state]];
531 vlc_object_release( p_vbi );
535 - (IBAction)telxNavLink:(id)sender
537 intf_thread_t * p_intf = VLCIntf;
541 if( [[sender title] isEqualToString: _NS("Index")] )
543 else if( [[sender title] isEqualToString: _NS("Red")] )
545 else if( [[sender title] isEqualToString: _NS("Green")] )
547 else if( [[sender title] isEqualToString: _NS("Yellow")] )
549 else if( [[sender title] isEqualToString: _NS("Blue")] )
551 if( i_page == 0 ) return;
553 p_vbi = (vlc_object_t *) vlc_object_find_name( p_intf,
554 "zvbi", FIND_ANYWHERE );
557 var_SetInteger( p_vbi, "vbi-page", i_page );
558 vlc_object_release( p_vbi );
562 - (IBAction)addSubtitleFile:(id)sender
564 NSInteger i_returnValue = 0;
565 input_thread_t * p_input = pl_CurrentInput( VLCIntf );
566 if( !p_input ) return;
568 input_item_t *p_item = input_GetItem( p_input );
569 if( !p_item ) return;
571 char *path = input_item_GetURI( p_item );
572 if( !path ) path = strdup( "" );
574 NSOpenPanel * openPanel = [NSOpenPanel openPanel];
575 [openPanel setCanChooseFiles: YES];
576 [openPanel setCanChooseDirectories: NO];
577 [openPanel setAllowsMultipleSelection: YES];
578 i_returnValue = [openPanel runModalForDirectory: [NSString stringWithUTF8String: path] file: nil types: [NSArray arrayWithObjects: @"cdg",@"@idx",@"srt",@"sub",@"utf",@"ass",@"ssa",@"aqt",@"jss",@"psb",@"rt",@"smi", nil]];
581 if( i_returnValue == NSOKButton )
584 if( !p_input ) return;
586 c = [[openPanel filenames] count];
587 NSLog( @"count: %i", c );
588 for (int i = 0; [[openPanel filenames] count] > i ; i++)
590 msg_Dbg( VLCIntf, "loading subs from %s", [[[openPanel filenames] objectAtIndex: i] UTF8String] );
591 if( input_AddSubtitle( p_input, [[[openPanel filenames] objectAtIndex: i] UTF8String], TRUE ) )
592 msg_Warn( VLCIntf, "unable to load subtitles from '%s'",
593 [[[openPanel filenames] objectAtIndex: i] UTF8String] );
599 - (void)scrollWheel:(NSEvent *)theEvent
601 intf_thread_t * p_intf = VLCIntf;
602 float f_yabsvalue = [theEvent deltaY] > 0.0f ? [theEvent deltaY] : -[theEvent deltaY];
603 float f_xabsvalue = [theEvent deltaX] > 0.0f ? [theEvent deltaX] : -[theEvent deltaX];
604 int i, i_yvlckey, i_xvlckey;
606 if ([theEvent deltaY] < 0.0f)
607 i_yvlckey = KEY_MOUSEWHEELDOWN;
609 i_yvlckey = KEY_MOUSEWHEELUP;
611 if ([theEvent deltaX] < 0.0f)
612 i_xvlckey = KEY_MOUSEWHEELRIGHT;
614 i_xvlckey = KEY_MOUSEWHEELLEFT;
616 /* Send multiple key event, depending on the intensity of the event */
617 for (i = 0; i < (int)(f_yabsvalue/4.+1.) && f_yabsvalue > 0.05 ; i++)
618 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_yvlckey );
620 /* Prioritize Y event (sound volume) over X event */
621 if (f_yabsvalue < 0.05)
623 for (i = 0; i < (int)(f_xabsvalue/6.+1.) && f_xabsvalue > 0.05; i++)
624 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_xvlckey );
628 - (BOOL)keyEvent:(NSEvent *)o_event
630 BOOL eventHandled = NO;
631 unichar key = [[o_event charactersIgnoringModifiers] characterAtIndex: 0];
635 vout_thread_t *p_vout = vlc_object_find( VLCIntf, VLC_OBJECT_VOUT,
640 if( key == (unichar) 0x1b )
642 id o_vout_view = [self voutView];
643 if( o_vout_view && [o_vout_view isFullscreen] )
645 [o_vout_view toggleFullscreen];
649 else if( key == ' ' )
654 vlc_object_release( (vlc_object_t *)p_vout );
660 - (void)setupVarMenuItem:(NSMenuItem *)o_mi
661 target:(vlc_object_t *)p_object
662 var:(const char *)psz_variable
663 selector:(SEL)pf_callback
665 vlc_value_t val, text;
666 int i_type = var_Type( p_object, psz_variable );
668 switch( i_type & VLC_VAR_TYPE )
672 case VLC_VAR_VARIABLE:
674 case VLC_VAR_INTEGER:
677 /* Variable doesn't exist or isn't handled */
681 /* Make sure we want to display the variable */
682 if( i_type & VLC_VAR_HASCHOICE )
684 var_Change( p_object, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL );
685 if( val.i_int == 0 ) return;
686 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
690 /* Get the descriptive name of the variable */
691 var_Change( p_object, psz_variable, VLC_VAR_GETTEXT, &text, NULL );
692 [o_mi setTitle: [[VLCMain sharedInstance] localizedString: text.psz_string ?
693 text.psz_string : strdup( psz_variable ) ]];
695 var_Get( p_object, psz_variable, &val );
696 if( i_type & VLC_VAR_HASCHOICE )
698 NSMenu *o_menu = [o_mi submenu];
700 [self setupVarMenu: o_menu forMenuItem: o_mi target:p_object
701 var:psz_variable selector:pf_callback];
703 free( text.psz_string );
707 VLCAutoGeneratedMenuContent *o_data;
708 switch( i_type & VLC_VAR_TYPE )
711 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
712 andValue: val ofType: i_type];
713 [o_mi setRepresentedObject: [o_data autorelease]];
717 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
718 andValue: val ofType: i_type];
719 [o_mi setRepresentedObject: [o_data autorelease]];
720 if( !( i_type & VLC_VAR_ISCOMMAND ) )
721 [o_mi setState: val.b_bool ? TRUE : FALSE ];
725 free( text.psz_string );
729 if( ( i_type & VLC_VAR_TYPE ) == VLC_VAR_STRING ) free( val.psz_string );
730 free( text.psz_string );
734 - (void)setupVarMenu:(NSMenu *)o_menu
735 forMenuItem: (NSMenuItem *)o_parent
736 target:(vlc_object_t *)p_object
737 var:(const char *)psz_variable
738 selector:(SEL)pf_callback
740 vlc_value_t val, val_list, text_list;
741 int i_type, i, i_nb_items;
743 /* remove previous items */
744 i_nb_items = [o_menu numberOfItems];
745 for( i = 0; i < i_nb_items; i++ )
747 [o_menu removeItemAtIndex: 0];
750 /* Check the type of the object variable */
751 i_type = var_Type( p_object, psz_variable );
753 /* Make sure we want to display the variable */
754 if( i_type & VLC_VAR_HASCHOICE )
756 var_Change( p_object, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL );
757 if( val.i_int == 0 ) return;
758 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
766 switch( i_type & VLC_VAR_TYPE )
770 case VLC_VAR_VARIABLE:
772 case VLC_VAR_INTEGER:
775 /* Variable doesn't exist or isn't handled */
779 if( var_Get( p_object, psz_variable, &val ) < 0 )
784 if( var_Change( p_object, psz_variable, VLC_VAR_GETLIST,
785 &val_list, &text_list ) < 0 )
787 if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
791 /* make (un)sensitive */
792 [o_parent setEnabled: ( val_list.p_list->i_count > 1 )];
794 /* special case for the subtitles items */
795 if( [[o_parent title] isEqualToString: _NS("Subtitles Track")] == YES )
797 NSMenuItem * o_lmi_tmp;
798 o_lmi_tmp = [o_menu addItemWithTitle: _NS("Open File...") action: @selector(addSubtitleFile:) keyEquivalent: @""];
799 [o_lmi_tmp setTarget: self];
800 [o_lmi_tmp setEnabled: YES];
801 [o_parent setEnabled: YES];
802 [o_menu addItem: [NSMenuItem separatorItem]];
805 for( i = 0; i < val_list.p_list->i_count; i++ )
807 vlc_value_t another_val;
809 NSString *o_title = @"";
810 VLCAutoGeneratedMenuContent *o_data;
812 switch( i_type & VLC_VAR_TYPE )
815 another_val.psz_string =
816 strdup(val_list.p_list->p_values[i].psz_string);
818 o_title = [[VLCMain sharedInstance] localizedString: text_list.p_list->p_values[i].psz_string ?
819 text_list.p_list->p_values[i].psz_string : val_list.p_list->p_values[i].psz_string ];
821 o_lmi = [o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""];
822 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: strdup(psz_variable) ofObject: p_object
823 andValue: another_val ofType: i_type];
824 [o_lmi setRepresentedObject: [o_data autorelease]];
825 [o_lmi setTarget: self];
827 if( !strcmp( val.psz_string, val_list.p_list->p_values[i].psz_string ) && !( i_type & VLC_VAR_ISCOMMAND ) )
828 [o_lmi setState: TRUE ];
832 case VLC_VAR_INTEGER:
834 o_title = text_list.p_list->p_values[i].psz_string ?
835 [[VLCMain sharedInstance] localizedString: strdup( text_list.p_list->p_values[i].psz_string )] :
836 [NSString stringWithFormat: @"%d",
837 val_list.p_list->p_values[i].i_int];
839 o_lmi = [o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""];
840 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: strdup(psz_variable) ofObject: p_object
841 andValue: val_list.p_list->p_values[i] ofType: i_type];
842 [o_lmi setRepresentedObject: [o_data autorelease]];
843 [o_lmi setTarget: self];
845 if( val_list.p_list->p_values[i].i_int == val.i_int && !( i_type & VLC_VAR_ISCOMMAND ) )
846 [o_lmi setState: TRUE ];
854 /* special case for the subtitles sub-menu
855 * In case that we don't have any subs, we don't want a separator item at the end */
856 if( [[o_parent title] isEqualToString: _NS("Subtitles Track")] == YES )
858 if( [o_menu numberOfItems] == 2 )
859 [o_menu removeItemAtIndex: 1];
862 /* clean up everything */
863 if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
864 var_Change( p_object, psz_variable, VLC_VAR_FREELIST, &val_list, &text_list );
867 - (IBAction)toggleVar:(id)sender
869 NSMenuItem *o_mi = (NSMenuItem *)sender;
870 VLCAutoGeneratedMenuContent *o_data = [o_mi representedObject];
871 [NSThread detachNewThreadSelector: @selector(toggleVarThread:)
872 toTarget: self withObject: o_data];
877 - (int)toggleVarThread: (id)data
879 vlc_object_t *p_object;
880 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
882 assert([data isKindOfClass:[VLCAutoGeneratedMenuContent class]]);
883 VLCAutoGeneratedMenuContent *menuContent = (VLCAutoGeneratedMenuContent *)data;
885 vlc_thread_set_priority( VLCIntf , VLC_THREAD_PRIORITY_LOW );
887 p_object = [menuContent vlcObject];
889 if( p_object != NULL )
891 var_Set( p_object, [menuContent name], [menuContent value] );
892 vlc_object_release( p_object );
900 - (IBAction)goToSpecificTime:(id)sender
902 if( sender == o_specificTime_cancel_btn )
904 [NSApp endSheet: o_specificTime_win];
905 [o_specificTime_win close];
907 else if( sender == o_specificTime_ok_btn )
909 input_thread_t * p_input = pl_CurrentInput( VLCIntf );
912 unsigned int timeInSec = 0;
913 NSString * fieldContent = [o_specificTime_enter_fld stringValue];
914 if( [[fieldContent componentsSeparatedByString: @":"] count] > 1 &&
915 [[fieldContent componentsSeparatedByString: @":"] count] <= 3 )
917 NSArray * ourTempArray = \
918 [fieldContent componentsSeparatedByString: @":"];
920 if( [[fieldContent componentsSeparatedByString: @":"] count] == 3 )
922 timeInSec += ([[ourTempArray objectAtIndex: 0] intValue] * 3600); //h
923 timeInSec += ([[ourTempArray objectAtIndex: 1] intValue] * 60); //m
924 timeInSec += [[ourTempArray objectAtIndex: 2] intValue]; //s
928 timeInSec += ([[ourTempArray objectAtIndex: 0] intValue] * 60); //m
929 timeInSec += [[ourTempArray objectAtIndex: 1] intValue]; //s
933 timeInSec = [fieldContent intValue];
935 input_Control( p_input, INPUT_SET_TIME, (int64_t)(timeInSec * 1000000));
936 vlc_object_release( p_input );
939 [NSApp endSheet: o_specificTime_win];
940 [o_specificTime_win close];
944 input_thread_t * p_input = pl_CurrentInput( VLCIntf );
947 /* we can obviously only do that if an input is available */
948 vlc_value_t pos, length;
949 var_Get( p_input, "time", &pos );
950 [o_specificTime_enter_fld setIntValue: (pos.i_time / 1000000)];
951 var_Get( p_input, "length", &length );
952 [o_specificTime_stepper setMaxValue: (length.i_time / 1000000)];
954 [NSApp beginSheet: o_specificTime_win modalForWindow: \
955 [NSApp mainWindow] modalDelegate: self didEndSelector: nil \
957 [o_specificTime_win makeKeyWindow];
958 vlc_object_release( p_input );
969 msg_Err( VLCIntf, "FSPanel is nil" );
976 @implementation VLCControls (NSMenuValidation)
978 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
980 BOOL bEnabled = TRUE;
982 intf_thread_t * p_intf = VLCIntf;
983 playlist_t * p_playlist = pl_Hold( p_intf );
984 input_thread_t * p_input = playlist_CurrentInput( p_playlist );
986 if( [[o_mi title] isEqualToString: _NS("Faster")] ||
987 [[o_mi title] isEqualToString: _NS("Slower")] )
989 if( p_input != NULL )
991 bEnabled = var_GetBool( p_input, "can-rate" );
998 else if( [[o_mi title] isEqualToString: _NS("Stop")] )
1000 if( p_input == NULL )
1004 [o_main setupMenus]; /* Make sure input menu is up to date */
1006 else if( [[o_mi title] isEqualToString: _NS("Previous")] ||
1007 [[o_mi title] isEqualToString: _NS("Next")] )
1009 /** \todo fix i_size use */
1011 bEnabled = p_playlist->items.i_size > 1;
1014 else if( [[o_mi title] isEqualToString: _NS("Random")] )
1017 var_Get( p_playlist, "random", &val );
1018 i_state = val.b_bool ? NSOnState : NSOffState;
1019 [o_mi setState: i_state];
1021 else if( [[o_mi title] isEqualToString: _NS("Repeat One")] )
1024 var_Get( p_playlist, "repeat", &val );
1025 i_state = val.b_bool ? NSOnState : NSOffState;
1026 [o_mi setState: i_state];
1028 else if( [[o_mi title] isEqualToString: _NS("Repeat All")] )
1031 var_Get( p_playlist, "loop", &val );
1032 i_state = val.b_bool ? NSOnState : NSOffState;
1033 [o_mi setState: i_state];
1035 else if( [[o_mi title] isEqualToString: _NS("Step Forward")] ||
1036 [[o_mi title] isEqualToString: _NS("Step Backward")] ||
1037 [[o_mi title] isEqualToString: _NS("Jump To Time")])
1039 if( p_input != NULL )
1041 var_Get( p_input, "can-seek", &val);
1042 bEnabled = val.b_bool;
1044 else bEnabled = FALSE;
1046 else if( [[o_mi title] isEqualToString: _NS("Mute")] )
1048 [o_mi setState: p_intf->p_sys->b_mute ? NSOnState : NSOffState];
1049 [o_main setupMenus]; /* Make sure audio menu is up to date */
1051 else if( [[o_mi title] isEqualToString: _NS("Half Size")] ||
1052 [[o_mi title] isEqualToString: _NS("Normal Size")] ||
1053 [[o_mi title] isEqualToString: _NS("Double Size")] ||
1054 [[o_mi title] isEqualToString: _NS("Fit to Screen")] ||
1055 [[o_mi title] isEqualToString: _NS("Snapshot")] ||
1056 [[o_mi title] isEqualToString: _NS("Fullscreen")] ||
1057 [[o_mi title] isEqualToString: _NS("Float on Top")] )
1060 NSArray *o_windows = [NSApp orderedWindows];
1061 NSEnumerator *o_enumerator = [o_windows objectEnumerator];
1064 vout_thread_t *p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
1066 if( p_vout != NULL )
1068 if( [[o_mi title] isEqualToString: _NS("Float on Top")] )
1070 var_Get( p_vout, "video-on-top", &val );
1071 [o_mi setState: val.b_bool ? NSOnState : NSOffState];
1074 while( (o_window = [o_enumerator nextObject]))
1076 if( [[o_window className] isEqualToString: @"VLCVoutWindow"] ||
1077 [[[VLCMain sharedInstance] embeddedList]
1078 windowContainsEmbedded: o_window])
1085 vlc_object_release( (vlc_object_t *)p_vout );
1087 if( [[o_mi title] isEqualToString: _NS("Fullscreen")] )
1089 var_Get( p_playlist, "fullscreen", &val );
1090 [o_mi setState: val.b_bool];
1093 [o_main setupMenus]; /* Make sure video menu is up to date */
1096 /* Special case for telx menu */
1097 if( [[o_mi title] isEqualToString: _NS("Normal Size")] );
1099 NSMenuItem *item = [[o_mi menu] itemWithTitle:_NS("Teletext")];
1100 bool b_telx = p_input && var_GetInteger( p_input, "teletext-es" ) >= 0;
1102 [[item submenu] setAutoenablesItems:NO];
1103 for( int k=0; k < [[item submenu] numberOfItems]; k++ )
1105 [[[item submenu] itemAtIndex:k] setEnabled: b_telx];
1109 if( p_input ) vlc_object_release( p_input );
1110 pl_Release( p_intf );
1117 /*****************************************************************************
1118 * VLCAutoGeneratedMenuContent implementation
1119 *****************************************************************************
1120 * Object connected to a playlistitem which remembers the data belonging to
1121 * the variable of the autogenerated menu
1122 *****************************************************************************/
1123 @implementation VLCAutoGeneratedMenuContent
1125 -(id) initWithVariableName:(const char *)name ofObject:(vlc_object_t *)object
1126 andValue:(vlc_value_t)val ofType:(int)type
1128 self = [super init];
1132 psz_name = strdup( name );
1133 _vlc_object = vlc_object_hold( object );
1143 vlc_object_release( _vlc_object );
1148 - (const char *)name
1153 - (vlc_value_t)value
1158 - (vlc_object_t *)vlcObject
1160 return vlc_object_hold( _vlc_object );
1172 /*****************************************************************************
1173 * VLCTimeField implementation
1174 *****************************************************************************
1175 * we need this to catch our click-event in the controller window
1176 *****************************************************************************/
1178 @implementation VLCTimeField
1179 - (void)mouseDown: (NSEvent *)ourEvent
1181 if( [ourEvent clickCount] > 1 )
1182 [[[VLCMain sharedInstance] controls] goToSpecificTime: nil];
1184 [[VLCMain sharedInstance] timeFieldWasClicked: self];