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 */
44 /*****************************************************************************
45 * VLCControls implementation
46 *****************************************************************************/
47 @implementation VLCControls
52 o_fs_panel = [[VLCFSPanel alloc] init];
58 [o_specificTime_mi setTitle: _NS("Jump To Time")];
59 [o_specificTime_cancel_btn setTitle: _NS("Cancel")];
60 [o_specificTime_ok_btn setTitle: _NS("OK")];
61 [o_specificTime_sec_lbl setStringValue: _NS("sec.")];
62 [o_specificTime_goTo_lbl setStringValue: _NS("Jump to time")];
64 o_repeat_off = [NSImage imageNamed:@"repeat_embedded"];
66 [self controlTintChanged];
68 [[NSNotificationCenter defaultCenter] addObserver: self
69 selector: @selector( controlTintChanged )
70 name: NSControlTintDidChangeNotification
74 - (void)controlTintChanged
77 if( [o_btn_repeat image] == o_repeat_single )
79 else if( [o_btn_repeat image] == o_repeat_all )
82 if( [NSColor currentControlTint] == NSGraphiteControlTint )
84 o_repeat_single = [NSImage imageNamed:@"repeat_single_embedded_graphite"];
85 o_repeat_all = [NSImage imageNamed:@"repeat_embedded_graphite"];
87 [o_btn_shuffle setAlternateImage: [NSImage imageNamed: @"shuffle_embedded_graphite"]];
88 [o_btn_addNode setAlternateImage: [NSImage imageNamed: @"add_embedded_graphite"]];
92 o_repeat_single = [NSImage imageNamed:@"repeat_single_embedded_blue"];
93 o_repeat_all = [NSImage imageNamed:@"repeat_embedded_blue"];
95 [o_btn_shuffle setAlternateImage: [NSImage imageNamed: @"shuffle_embedded_blue"]];
96 [o_btn_addNode setAlternateImage: [NSImage imageNamed: @"add_embedded_blue"]];
99 /* update the repeat button, but keep its state */
102 else if( i_repeat == 2 )
110 [[NSNotificationCenter defaultCenter] removeObserver: self];
112 [o_repeat_single release];
113 [o_repeat_all release];
114 [o_repeat_off release];
119 - (IBAction)play:(id)sender
121 intf_thread_t * p_intf = VLCIntf;
122 playlist_t * p_playlist = pl_Hold( p_intf );
126 empty = playlist_IsEmpty( p_playlist );
129 pl_Release( p_intf );
132 [o_main intfOpenFileGeneric: (id)sender];
134 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_PLAY_PAUSE );
141 id o_embeddedViewList = [[VLCMain sharedInstance] embeddedList];
142 NSEnumerator *o_enumerator = [[NSApp orderedWindows] objectEnumerator];
143 while( !o_voutView && ( o_window = [o_enumerator nextObject] ) )
145 /* We have an embedded vout */
146 if( [o_embeddedViewList windowContainsEmbedded: o_window] )
148 o_voutView = [o_embeddedViewList viewForWindow: o_window];
150 /* We have a detached vout */
151 else if( [[o_window className] isEqualToString: @"VLCVoutWindow"] )
153 o_voutView = [o_window voutView];
156 return [[o_voutView retain] autorelease];
159 - (IBAction)stop:(id)sender
161 intf_thread_t * p_intf = VLCIntf;
162 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_STOP );
163 /* Close the window directly, because we do know that there
164 * won't be anymore video. It's currently waiting a bit. */
165 [[[self voutView] window] orderOut:self];
168 - (IBAction)faster:(id)sender
170 intf_thread_t * p_intf = VLCIntf;
171 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_FASTER );
174 - (IBAction)slower:(id)sender
176 intf_thread_t * p_intf = VLCIntf;
177 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_SLOWER );
180 - (IBAction)prev:(id)sender
182 intf_thread_t * p_intf = VLCIntf;
183 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_PREV );
186 - (IBAction)next:(id)sender
188 intf_thread_t * p_intf = VLCIntf;
189 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_NEXT );
192 - (IBAction)random:(id)sender
195 intf_thread_t * p_intf = VLCIntf;
196 playlist_t * p_playlist = pl_Hold( p_intf );
198 var_Get( p_playlist, "random", &val );
199 val.b_bool = !val.b_bool;
200 var_Set( p_playlist, "random", val );
203 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Random On" ) );
204 config_PutInt( p_playlist, "random", 1 );
208 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Random Off" ) );
209 config_PutInt( p_playlist, "random", 0 );
212 p_intf->p_sys->b_playmode_update = true;
213 p_intf->p_sys->b_intf_update = true;
214 pl_Release( p_intf );
217 /* three little ugly helpers */
220 [o_btn_repeat setImage: o_repeat_single];
221 [o_btn_repeat setAlternateImage: o_repeat_all];
222 [o_btn_repeat_embed setImage: [NSImage imageNamed:@"sidebarRepeatOneOn"]];
226 [o_btn_repeat setImage: o_repeat_all];
227 [o_btn_repeat setAlternateImage: o_repeat_off];
228 [o_btn_repeat_embed setImage: [NSImage imageNamed:@"sidebarRepeatOn"]];
232 [o_btn_repeat setImage: o_repeat_off];
233 [o_btn_repeat setAlternateImage: o_repeat_single];
234 [o_btn_repeat_embed setImage: [NSImage imageNamed:@"sidebarRepeat"]];
239 playlist_t *p_playlist = pl_Hold( VLCIntf );
240 var_Get( p_playlist, "random", &val );
241 [o_btn_shuffle setState: val.b_bool];
243 [o_btn_shuffle_embed setImage: [NSImage imageNamed:@"sidebarShuffleOn"]];
245 [o_btn_shuffle_embed setImage: [NSImage imageNamed:@"sidebarShuffle"]];
246 pl_Release( VLCIntf );
249 - (IBAction)repeatButtonAction:(id)sender
251 vlc_value_t looping,repeating;
252 intf_thread_t * p_intf = VLCIntf;
253 playlist_t * p_playlist = pl_Hold( p_intf );
255 var_Get( p_playlist, "repeat", &repeating );
256 var_Get( p_playlist, "loop", &looping );
258 if( !repeating.b_bool && !looping.b_bool )
260 /* was: no repeating at all, switching to Repeat One */
262 /* set our button's look */
265 /* prepare core communication */
266 repeating.b_bool = true;
267 looping.b_bool = false;
268 config_PutInt( p_playlist, "repeat", 1 );
269 config_PutInt( p_playlist, "loop", 0 );
271 /* show the change */
272 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat One" ) );
274 else if( repeating.b_bool && !looping.b_bool )
276 /* was: Repeat One, switching to Repeat All */
278 /* set our button's look */
281 /* prepare core communication */
282 repeating.b_bool = false;
283 looping.b_bool = true;
284 config_PutInt( p_playlist, "repeat", 0 );
285 config_PutInt( p_playlist, "loop", 1 );
287 /* show the change */
288 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat All" ) );
292 /* was: Repeat All or bug in VLC, switching to Repeat Off */
294 /* set our button's look */
297 /* prepare core communication */
298 repeating.b_bool = false;
299 looping.b_bool = false;
300 config_PutInt( p_playlist, "repeat", 0 );
301 config_PutInt( p_playlist, "loop", 0 );
303 /* show the change */
304 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat Off" ) );
307 /* communicate with core and the main intf loop */
308 var_Set( p_playlist, "repeat", repeating );
309 var_Set( p_playlist, "loop", looping );
310 p_intf->p_sys->b_playmode_update = true;
311 p_intf->p_sys->b_intf_update = true;
313 pl_Release( p_intf );
317 - (IBAction)repeat:(id)sender
320 intf_thread_t * p_intf = VLCIntf;
321 playlist_t * p_playlist = pl_Hold( p_intf );
323 var_Get( p_playlist, "repeat", &val );
326 var_Set( p_playlist, "loop", val );
328 val.b_bool = !val.b_bool;
329 var_Set( p_playlist, "repeat", val );
332 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat One" ) );
333 config_PutInt( p_playlist, "repeat", 1 );
337 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat Off" ) );
338 config_PutInt( p_playlist, "repeat", 0 );
341 p_intf->p_sys->b_playmode_update = true;
342 p_intf->p_sys->b_intf_update = true;
343 pl_Release( p_intf );
346 - (IBAction)loop:(id)sender
349 intf_thread_t * p_intf = VLCIntf;
350 playlist_t * p_playlist = pl_Hold( p_intf );
352 var_Get( p_playlist, "loop", &val );
355 var_Set( p_playlist, "repeat", val );
357 val.b_bool = !val.b_bool;
358 var_Set( p_playlist, "loop", val );
361 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat All" ) );
362 config_PutInt( p_playlist, "loop", 1 );
366 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat Off" ) );
367 config_PutInt( p_playlist, "loop", 0 );
370 p_intf->p_sys->b_playmode_update = true;
371 p_intf->p_sys->b_intf_update = true;
372 pl_Release( p_intf );
375 - (IBAction)forward:(id)sender
377 intf_thread_t * p_intf = VLCIntf;
378 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_JUMP_FORWARD_SHORT );
381 - (IBAction)backward:(id)sender
384 intf_thread_t * p_intf = VLCIntf;
385 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_JUMP_BACKWARD_SHORT );
389 - (IBAction)volumeUp:(id)sender
391 intf_thread_t * p_intf = VLCIntf;
392 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_VOL_UP );
393 /* Manage volume status */
394 [o_main manageVolumeSlider];
397 - (IBAction)volumeDown:(id)sender
399 intf_thread_t * p_intf = VLCIntf;
400 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_VOL_DOWN );
401 /* Manage volume status */
402 [o_main manageVolumeSlider];
405 - (IBAction)mute:(id)sender
407 intf_thread_t * p_intf = VLCIntf;
408 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_VOL_MUTE );
409 /* Manage volume status */
410 [o_main manageVolumeSlider];
413 - (IBAction)volumeSliderUpdated:(id)sender
415 intf_thread_t * p_intf = VLCIntf;
416 audio_volume_t i_volume = (audio_volume_t)[sender intValue];
417 int i_volume_step = 0;
418 i_volume_step = config_GetInt( p_intf->p_libvlc, "volume-step" );
419 aout_VolumeSet( p_intf, i_volume * i_volume_step );
420 /* Manage volume status */
421 [o_main manageVolumeSlider];
424 - (IBAction)showPosition: (id)sender
426 input_thread_t * p_input = pl_CurrentInput( VLCIntf );
427 if( p_input != NULL )
429 vout_thread_t *p_vout = input_GetVout( p_input );
432 var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_POSITION );
433 vlc_object_release( (vlc_object_t *)p_vout );
435 vlc_object_release( p_input );
439 - (IBAction)toogleFullscreen:(id)sender {
440 NSMenuItem *o_mi = [[NSMenuItem alloc] initWithTitle: _NS("Fullscreen") action: nil keyEquivalent:@""];
441 [self windowAction: [o_mi autorelease]];
444 - (BOOL) isFullscreen {
445 id o_vout_view = [self voutView];
448 return [o_vout_view isFullscreen];
453 - (IBAction)windowAction:(id)sender
455 NSString *o_title = [sender title];
456 input_thread_t * p_input = pl_CurrentInput( VLCIntf );
458 if( p_input != NULL )
460 vout_thread_t *p_vout = input_GetVout( p_input );
463 id o_vout_view = [self voutView];
466 if( [o_title isEqualToString: _NS("Half Size") ] )
467 [o_vout_view scaleWindowWithFactor: 0.5 animate: YES];
468 else if( [o_title isEqualToString: _NS("Normal Size") ] )
469 [o_vout_view scaleWindowWithFactor: 1.0 animate: YES];
470 else if( [o_title isEqualToString: _NS("Double Size") ] )
471 [o_vout_view scaleWindowWithFactor: 2.0 animate: YES];
472 else if( [o_title isEqualToString: _NS("Float on Top") ] )
473 [o_vout_view toggleFloatOnTop];
474 else if( [o_title isEqualToString: _NS("Fit to Screen") ] )
476 id o_window = [o_vout_view voutWindow];
477 if( ![o_window isZoomed] )
478 [o_window performZoom:self];
480 else if( [o_title isEqualToString: _NS("Snapshot") ] )
482 [o_vout_view snapshot];
486 /* Fullscreen state for next time will be saved here too */
487 [o_vout_view toggleFullscreen];
490 vlc_object_release( (vlc_object_t *)p_vout );
494 playlist_t * p_playlist = pl_Hold( VLCIntf );
496 if( [o_title isEqualToString: _NS("Fullscreen")] ||
497 [sender isKindOfClass:[NSButton class]] )
500 var_Get( p_playlist, "fullscreen", &val );
501 var_Set( p_playlist, "fullscreen", (vlc_value_t)!val.b_bool );
504 pl_Release( VLCIntf );
506 vlc_object_release( p_input );
510 - (IBAction)telxTransparent:(id)sender
512 intf_thread_t * p_intf = VLCIntf;
514 p_vbi = (vlc_object_t *) vlc_object_find_name( p_intf,
515 "zvbi", FIND_ANYWHERE );
518 var_SetBool( p_vbi, "vbi-opaque", [sender state] );
519 [sender setState: ![sender state]];
520 vlc_object_release( p_vbi );
524 - (IBAction)telxNavLink:(id)sender
526 intf_thread_t * p_intf = VLCIntf;
530 if( [[sender title] isEqualToString: _NS("Index")] )
532 else if( [[sender title] isEqualToString: _NS("Red")] )
534 else if( [[sender title] isEqualToString: _NS("Green")] )
536 else if( [[sender title] isEqualToString: _NS("Yellow")] )
538 else if( [[sender title] isEqualToString: _NS("Blue")] )
540 if( i_page == 0 ) return;
542 p_vbi = (vlc_object_t *) vlc_object_find_name( p_intf,
543 "zvbi", FIND_ANYWHERE );
546 var_SetInteger( p_vbi, "vbi-page", i_page );
547 vlc_object_release( p_vbi );
551 - (IBAction)addSubtitleFile:(id)sender
553 NSInteger i_returnValue = 0;
554 input_thread_t * p_input = pl_CurrentInput( VLCIntf );
555 if( !p_input ) return;
557 input_item_t *p_item = input_GetItem( p_input );
558 if( !p_item ) return;
560 char *path = input_item_GetURI( p_item );
561 if( !path ) path = strdup( "" );
563 NSOpenPanel * openPanel = [NSOpenPanel openPanel];
564 [openPanel setCanChooseFiles: YES];
565 [openPanel setCanChooseDirectories: NO];
566 [openPanel setAllowsMultipleSelection: YES];
567 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]];
570 if( i_returnValue == NSOKButton )
573 if( !p_input ) return;
575 c = [[openPanel filenames] count];
576 NSLog( @"count: %i", c );
577 for (int i = 0; [[openPanel filenames] count] > i ; i++)
579 msg_Dbg( VLCIntf, "loading subs from %s", [[[openPanel filenames] objectAtIndex: i] UTF8String] );
580 if( input_AddSubtitle( p_input, [[[openPanel filenames] objectAtIndex: i] UTF8String], TRUE ) )
581 msg_Warn( VLCIntf, "unable to load subtitles from '%s'",
582 [[[openPanel filenames] objectAtIndex: i] UTF8String] );
588 - (void)scrollWheel:(NSEvent *)theEvent
590 intf_thread_t * p_intf = VLCIntf;
591 float f_yabsvalue = [theEvent deltaY] > 0.0f ? [theEvent deltaY] : -[theEvent deltaY];
592 float f_xabsvalue = [theEvent deltaX] > 0.0f ? [theEvent deltaX] : -[theEvent deltaX];
593 int i, i_yvlckey, i_xvlckey;
595 if ([theEvent deltaY] < 0.0f)
596 i_yvlckey = KEY_MOUSEWHEELDOWN;
598 i_yvlckey = KEY_MOUSEWHEELUP;
600 if ([theEvent deltaX] < 0.0f)
601 i_xvlckey = KEY_MOUSEWHEELRIGHT;
603 i_xvlckey = KEY_MOUSEWHEELLEFT;
605 /* Send multiple key event, depending on the intensity of the event */
606 for (i = 0; i < (int)(f_yabsvalue/4.+1.) && f_yabsvalue > 0.05 ; i++)
607 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_yvlckey );
609 /* Prioritize Y event (sound volume) over X event */
610 if (f_yabsvalue < 0.05)
612 for (i = 0; i < (int)(f_xabsvalue/6.+1.) && f_xabsvalue > 0.05; i++)
613 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_xvlckey );
617 - (BOOL)keyEvent:(NSEvent *)o_event
619 BOOL eventHandled = NO;
620 unichar key = [[o_event charactersIgnoringModifiers] characterAtIndex: 0];
624 input_thread_t * p_input = pl_CurrentInput( VLCIntf );
625 if( p_input != NULL )
627 vout_thread_t *p_vout = input_GetVout( p_input );
632 if( key == (unichar) 0x1b )
634 id o_vout_view = [self voutView];
635 if( o_vout_view && [o_vout_view isFullscreen] )
637 [o_vout_view toggleFullscreen];
641 else if( key == ' ' )
646 vlc_object_release( (vlc_object_t *)p_vout );
648 vlc_object_release( p_input );
654 - (void)setupVarMenuItem:(NSMenuItem *)o_mi
655 target:(vlc_object_t *)p_object
656 var:(const char *)psz_variable
657 selector:(SEL)pf_callback
659 vlc_value_t val, text;
660 int i_type = var_Type( p_object, psz_variable );
662 switch( i_type & VLC_VAR_TYPE )
666 case VLC_VAR_VARIABLE:
668 case VLC_VAR_INTEGER:
671 /* Variable doesn't exist or isn't handled */
675 /* Make sure we want to display the variable */
676 if( i_type & VLC_VAR_HASCHOICE )
678 var_Change( p_object, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL );
679 if( val.i_int == 0 ) return;
680 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
684 /* Get the descriptive name of the variable */
685 var_Change( p_object, psz_variable, VLC_VAR_GETTEXT, &text, NULL );
686 [o_mi setTitle: [[VLCMain sharedInstance] localizedString: text.psz_string ?
687 text.psz_string : strdup( psz_variable ) ]];
689 var_Get( p_object, psz_variable, &val );
690 if( i_type & VLC_VAR_HASCHOICE )
692 NSMenu *o_menu = [o_mi submenu];
694 [self setupVarMenu: o_menu forMenuItem: o_mi target:p_object
695 var:psz_variable selector:pf_callback];
697 free( text.psz_string );
701 VLCAutoGeneratedMenuContent *o_data;
702 switch( i_type & VLC_VAR_TYPE )
705 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
706 andValue: val ofType: i_type];
707 [o_mi setRepresentedObject: [o_data autorelease]];
711 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
712 andValue: val ofType: i_type];
713 [o_mi setRepresentedObject: [o_data autorelease]];
714 if( !( i_type & VLC_VAR_ISCOMMAND ) )
715 [o_mi setState: val.b_bool ? TRUE : FALSE ];
719 free( text.psz_string );
723 if( ( i_type & VLC_VAR_TYPE ) == VLC_VAR_STRING ) free( val.psz_string );
724 free( text.psz_string );
728 - (void)setupVarMenu:(NSMenu *)o_menu
729 forMenuItem: (NSMenuItem *)o_parent
730 target:(vlc_object_t *)p_object
731 var:(const char *)psz_variable
732 selector:(SEL)pf_callback
734 vlc_value_t val, val_list, text_list;
735 int i_type, i, i_nb_items;
737 /* remove previous items */
738 i_nb_items = [o_menu numberOfItems];
739 for( i = 0; i < i_nb_items; i++ )
741 [o_menu removeItemAtIndex: 0];
744 /* Check the type of the object variable */
745 i_type = var_Type( p_object, psz_variable );
747 /* Make sure we want to display the variable */
748 if( i_type & VLC_VAR_HASCHOICE )
750 var_Change( p_object, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL );
751 if( val.i_int == 0 ) return;
752 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
760 switch( i_type & VLC_VAR_TYPE )
764 case VLC_VAR_VARIABLE:
766 case VLC_VAR_INTEGER:
769 /* Variable doesn't exist or isn't handled */
773 if( var_Get( p_object, psz_variable, &val ) < 0 )
778 if( var_Change( p_object, psz_variable, VLC_VAR_GETLIST,
779 &val_list, &text_list ) < 0 )
781 if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
785 /* make (un)sensitive */
786 [o_parent setEnabled: ( val_list.p_list->i_count > 1 )];
788 /* special case for the subtitles items */
789 if( [[o_parent title] isEqualToString: _NS("Subtitles Track")] == YES )
791 NSMenuItem * o_lmi_tmp;
792 o_lmi_tmp = [o_menu addItemWithTitle: _NS("Open File...") action: @selector(addSubtitleFile:) keyEquivalent: @""];
793 [o_lmi_tmp setTarget: self];
794 [o_lmi_tmp setEnabled: YES];
795 [o_parent setEnabled: YES];
796 [o_menu addItem: [NSMenuItem separatorItem]];
799 for( i = 0; i < val_list.p_list->i_count; i++ )
801 vlc_value_t another_val;
803 NSString *o_title = @"";
804 VLCAutoGeneratedMenuContent *o_data;
806 switch( i_type & VLC_VAR_TYPE )
809 another_val.psz_string =
810 strdup(val_list.p_list->p_values[i].psz_string);
812 o_title = [[VLCMain sharedInstance] localizedString: text_list.p_list->p_values[i].psz_string ?
813 text_list.p_list->p_values[i].psz_string : val_list.p_list->p_values[i].psz_string ];
815 o_lmi = [o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""];
816 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: strdup(psz_variable) ofObject: p_object
817 andValue: another_val ofType: i_type];
818 [o_lmi setRepresentedObject: [o_data autorelease]];
819 [o_lmi setTarget: self];
821 if( !strcmp( val.psz_string, val_list.p_list->p_values[i].psz_string ) && !( i_type & VLC_VAR_ISCOMMAND ) )
822 [o_lmi setState: TRUE ];
826 case VLC_VAR_INTEGER:
828 o_title = text_list.p_list->p_values[i].psz_string ?
829 [[VLCMain sharedInstance] localizedString: strdup( text_list.p_list->p_values[i].psz_string )] :
830 [NSString stringWithFormat: @"%d",
831 val_list.p_list->p_values[i].i_int];
833 o_lmi = [o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""];
834 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: strdup(psz_variable) ofObject: p_object
835 andValue: val_list.p_list->p_values[i] ofType: i_type];
836 [o_lmi setRepresentedObject: [o_data autorelease]];
837 [o_lmi setTarget: self];
839 if( val_list.p_list->p_values[i].i_int == val.i_int && !( i_type & VLC_VAR_ISCOMMAND ) )
840 [o_lmi setState: TRUE ];
848 /* special case for the subtitles sub-menu
849 * In case that we don't have any subs, we don't want a separator item at the end */
850 if( [[o_parent title] isEqualToString: _NS("Subtitles Track")] == YES )
852 if( [o_menu numberOfItems] == 2 )
853 [o_menu removeItemAtIndex: 1];
856 /* clean up everything */
857 if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
858 var_FreeList( &val_list, &text_list );
861 - (IBAction)toggleVar:(id)sender
863 NSMenuItem *o_mi = (NSMenuItem *)sender;
864 VLCAutoGeneratedMenuContent *o_data = [o_mi representedObject];
865 [NSThread detachNewThreadSelector: @selector(toggleVarThread:)
866 toTarget: self withObject: o_data];
871 - (int)toggleVarThread: (id)data
873 vlc_object_t *p_object;
874 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
876 assert([data isKindOfClass:[VLCAutoGeneratedMenuContent class]]);
877 VLCAutoGeneratedMenuContent *menuContent = (VLCAutoGeneratedMenuContent *)data;
879 vlc_thread_set_priority( VLCIntf , VLC_THREAD_PRIORITY_LOW );
881 p_object = [menuContent vlcObject];
883 if( p_object != NULL )
885 var_Set( p_object, [menuContent name], [menuContent value] );
886 vlc_object_release( p_object );
894 - (IBAction)goToSpecificTime:(id)sender
896 if( sender == o_specificTime_cancel_btn )
898 [NSApp endSheet: o_specificTime_win];
899 [o_specificTime_win close];
901 else if( sender == o_specificTime_ok_btn )
903 input_thread_t * p_input = pl_CurrentInput( VLCIntf );
906 unsigned int timeInSec = 0;
907 NSString * fieldContent = [o_specificTime_enter_fld stringValue];
908 if( [[fieldContent componentsSeparatedByString: @":"] count] > 1 &&
909 [[fieldContent componentsSeparatedByString: @":"] count] <= 3 )
911 NSArray * ourTempArray = \
912 [fieldContent componentsSeparatedByString: @":"];
914 if( [[fieldContent componentsSeparatedByString: @":"] count] == 3 )
916 timeInSec += ([[ourTempArray objectAtIndex: 0] intValue] * 3600); //h
917 timeInSec += ([[ourTempArray objectAtIndex: 1] intValue] * 60); //m
918 timeInSec += [[ourTempArray objectAtIndex: 2] intValue]; //s
922 timeInSec += ([[ourTempArray objectAtIndex: 0] intValue] * 60); //m
923 timeInSec += [[ourTempArray objectAtIndex: 1] intValue]; //s
927 timeInSec = [fieldContent intValue];
929 input_Control( p_input, INPUT_SET_TIME, (int64_t)(timeInSec * 1000000));
930 vlc_object_release( p_input );
933 [NSApp endSheet: o_specificTime_win];
934 [o_specificTime_win close];
938 input_thread_t * p_input = pl_CurrentInput( VLCIntf );
941 /* we can obviously only do that if an input is available */
942 vlc_value_t pos, length;
943 var_Get( p_input, "time", &pos );
944 [o_specificTime_enter_fld setIntValue: (pos.i_time / 1000000)];
945 var_Get( p_input, "length", &length );
946 [o_specificTime_stepper setMaxValue: (length.i_time / 1000000)];
948 [NSApp beginSheet: o_specificTime_win modalForWindow: \
949 [NSApp mainWindow] modalDelegate: self didEndSelector: nil \
951 [o_specificTime_win makeKeyWindow];
952 vlc_object_release( p_input );
963 msg_Err( VLCIntf, "FSPanel is nil" );
970 @implementation VLCControls (NSMenuValidation)
972 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
974 BOOL bEnabled = TRUE;
976 intf_thread_t * p_intf = VLCIntf;
977 playlist_t * p_playlist = pl_Hold( p_intf );
978 input_thread_t * p_input = playlist_CurrentInput( p_playlist );
980 if( [[o_mi title] isEqualToString: _NS("Faster")] ||
981 [[o_mi title] isEqualToString: _NS("Slower")] )
983 if( p_input != NULL )
985 bEnabled = var_GetBool( p_input, "can-rate" );
992 else if( [[o_mi title] isEqualToString: _NS("Stop")] )
994 if( p_input == NULL )
998 [o_main setupMenus]; /* Make sure input menu is up to date */
1000 else if( [[o_mi title] isEqualToString: _NS("Previous")] ||
1001 [[o_mi title] isEqualToString: _NS("Next")] )
1004 bEnabled = playlist_CurrentSize( p_playlist ) > 1;
1007 else if( [[o_mi title] isEqualToString: _NS("Random")] )
1010 var_Get( p_playlist, "random", &val );
1011 i_state = val.b_bool ? NSOnState : NSOffState;
1012 [o_mi setState: i_state];
1014 else if( [[o_mi title] isEqualToString: _NS("Repeat One")] )
1017 var_Get( p_playlist, "repeat", &val );
1018 i_state = val.b_bool ? NSOnState : NSOffState;
1019 [o_mi setState: i_state];
1021 else if( [[o_mi title] isEqualToString: _NS("Repeat All")] )
1024 var_Get( p_playlist, "loop", &val );
1025 i_state = val.b_bool ? NSOnState : NSOffState;
1026 [o_mi setState: i_state];
1028 else if( [[o_mi title] isEqualToString: _NS("Step Forward")] ||
1029 [[o_mi title] isEqualToString: _NS("Step Backward")] ||
1030 [[o_mi title] isEqualToString: _NS("Jump To Time")])
1032 if( p_input != NULL )
1034 var_Get( p_input, "can-seek", &val);
1035 bEnabled = val.b_bool;
1037 else bEnabled = FALSE;
1039 else if( [[o_mi title] isEqualToString: _NS("Mute")] )
1041 [o_mi setState: p_intf->p_sys->b_mute ? NSOnState : NSOffState];
1042 [o_main setupMenus]; /* Make sure audio menu is up to date */
1044 else if( [[o_mi title] isEqualToString: _NS("Half Size")] ||
1045 [[o_mi title] isEqualToString: _NS("Normal Size")] ||
1046 [[o_mi title] isEqualToString: _NS("Double Size")] ||
1047 [[o_mi title] isEqualToString: _NS("Fit to Screen")] ||
1048 [[o_mi title] isEqualToString: _NS("Snapshot")] ||
1049 [[o_mi title] isEqualToString: _NS("Fullscreen")] ||
1050 [[o_mi title] isEqualToString: _NS("Float on Top")] )
1053 NSArray *o_windows = [NSApp orderedWindows];
1054 NSEnumerator *o_enumerator = [o_windows objectEnumerator];
1057 if( p_input != NULL )
1059 vout_thread_t *p_vout = input_GetVout( p_input );
1060 if( p_vout != NULL )
1062 if( [[o_mi title] isEqualToString: _NS("Float on Top")] )
1064 var_Get( p_vout, "video-on-top", &val );
1065 [o_mi setState: val.b_bool ? NSOnState : NSOffState];
1068 while( (o_window = [o_enumerator nextObject]))
1070 if( [[o_window className] isEqualToString: @"VLCVoutWindow"] ||
1071 [[[VLCMain sharedInstance] embeddedList]
1072 windowContainsEmbedded: o_window])
1079 vlc_object_release( (vlc_object_t *)p_vout );
1081 vlc_object_release( p_input );
1083 if( [[o_mi title] isEqualToString: _NS("Fullscreen")] )
1085 var_Get( p_playlist, "fullscreen", &val );
1086 [o_mi setState: val.b_bool];
1089 [o_main setupMenus]; /* Make sure video menu is up to date */
1092 /* Special case for telx menu */
1093 if( [[o_mi title] isEqualToString: _NS("Normal Size")] )
1095 NSMenuItem *item = [[o_mi menu] itemWithTitle:_NS("Teletext")];
1096 bool b_telx = p_input && var_GetInteger( p_input, "teletext-es" ) >= 0;
1098 [[item submenu] setAutoenablesItems:NO];
1099 for( int k=0; k < [[item submenu] numberOfItems]; k++ )
1101 [[[item submenu] itemAtIndex:k] setEnabled: b_telx];
1105 if( p_input ) vlc_object_release( p_input );
1106 pl_Release( p_intf );
1113 /*****************************************************************************
1114 * VLCAutoGeneratedMenuContent implementation
1115 *****************************************************************************
1116 * Object connected to a playlistitem which remembers the data belonging to
1117 * the variable of the autogenerated menu
1118 *****************************************************************************/
1119 @implementation VLCAutoGeneratedMenuContent
1121 -(id) initWithVariableName:(const char *)name ofObject:(vlc_object_t *)object
1122 andValue:(vlc_value_t)val ofType:(int)type
1124 self = [super init];
1128 psz_name = strdup( name );
1129 _vlc_object = vlc_object_hold( object );
1139 vlc_object_release( _vlc_object );
1144 - (const char *)name
1149 - (vlc_value_t)value
1154 - (vlc_object_t *)vlcObject
1156 return vlc_object_hold( _vlc_object );
1168 /*****************************************************************************
1169 * VLCTimeField implementation
1170 *****************************************************************************
1171 * we need this to catch our click-event in the controller window
1172 *****************************************************************************/
1174 @implementation VLCTimeField
1175 - (void)mouseDown: (NSEvent *)ourEvent
1177 if( [ourEvent clickCount] > 1 )
1178 [[[VLCMain sharedInstance] controls] goToSpecificTime: nil];
1180 [[VLCMain sharedInstance] timeFieldWasClicked: self];