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 vout_thread_t *p_vout = vlc_object_find( VLCIntf, VLC_OBJECT_VOUT,
430 intf_thread_t * p_intf = VLCIntf;
431 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_POSITION );
432 vlc_object_release( (vlc_object_t *)p_vout );
436 - (IBAction)toogleFullscreen:(id)sender {
437 NSMenuItem *o_mi = [[NSMenuItem alloc] initWithTitle: _NS("Fullscreen") action: nil keyEquivalent:@""];
438 [self windowAction: [o_mi autorelease]];
441 - (BOOL) isFullscreen {
442 id o_vout_view = [self voutView];
445 return [o_vout_view isFullscreen];
450 - (IBAction)windowAction:(id)sender
452 NSString *o_title = [sender title];
454 vout_thread_t *p_vout = vlc_object_find( VLCIntf, VLC_OBJECT_VOUT,
458 id o_vout_view = [self voutView];
461 if( [o_title isEqualToString: _NS("Half Size") ] )
462 [o_vout_view scaleWindowWithFactor: 0.5 animate: YES];
463 else if( [o_title isEqualToString: _NS("Normal Size") ] )
464 [o_vout_view scaleWindowWithFactor: 1.0 animate: YES];
465 else if( [o_title isEqualToString: _NS("Double Size") ] )
466 [o_vout_view scaleWindowWithFactor: 2.0 animate: YES];
467 else if( [o_title isEqualToString: _NS("Float on Top") ] )
468 [o_vout_view toggleFloatOnTop];
469 else if( [o_title isEqualToString: _NS("Fit to Screen") ] )
471 id o_window = [o_vout_view voutWindow];
472 if( ![o_window isZoomed] )
473 [o_window performZoom:self];
475 else if( [o_title isEqualToString: _NS("Snapshot") ] )
477 [o_vout_view snapshot];
481 /* Fullscreen state for next time will be saved here too */
482 [o_vout_view toggleFullscreen];
485 vlc_object_release( (vlc_object_t *)p_vout );
489 playlist_t * p_playlist = pl_Hold( VLCIntf );
491 if( [o_title isEqualToString: _NS("Fullscreen")] ||
492 [sender isKindOfClass:[NSButton class]] )
495 var_Get( p_playlist, "fullscreen", &val );
496 var_Set( p_playlist, "fullscreen", (vlc_value_t)!val.b_bool );
499 pl_Release( VLCIntf );
504 - (IBAction)telxTransparent:(id)sender
506 intf_thread_t * p_intf = VLCIntf;
508 p_vbi = (vlc_object_t *) vlc_object_find_name( p_intf,
509 "zvbi", FIND_ANYWHERE );
512 var_SetBool( p_vbi, "vbi-opaque", [sender state] );
513 [sender setState: ![sender state]];
514 vlc_object_release( p_vbi );
518 - (IBAction)telxNavLink:(id)sender
520 intf_thread_t * p_intf = VLCIntf;
524 if( [[sender title] isEqualToString: _NS("Index")] )
526 else if( [[sender title] isEqualToString: _NS("Red")] )
528 else if( [[sender title] isEqualToString: _NS("Green")] )
530 else if( [[sender title] isEqualToString: _NS("Yellow")] )
532 else if( [[sender title] isEqualToString: _NS("Blue")] )
534 if( i_page == 0 ) return;
536 p_vbi = (vlc_object_t *) vlc_object_find_name( p_intf,
537 "zvbi", FIND_ANYWHERE );
540 var_SetInteger( p_vbi, "vbi-page", i_page );
541 vlc_object_release( p_vbi );
545 - (IBAction)addSubtitleFile:(id)sender
547 NSInteger i_returnValue = 0;
548 input_thread_t * p_input = pl_CurrentInput( VLCIntf );
549 if( !p_input ) return;
551 input_item_t *p_item = input_GetItem( p_input );
552 if( !p_item ) return;
554 char *path = input_item_GetURI( p_item );
555 if( !path ) path = strdup( "" );
557 NSOpenPanel * openPanel = [NSOpenPanel openPanel];
558 [openPanel setCanChooseFiles: YES];
559 [openPanel setCanChooseDirectories: NO];
560 [openPanel setAllowsMultipleSelection: YES];
561 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]];
564 if( i_returnValue == NSOKButton )
567 if( !p_input ) return;
569 c = [[openPanel filenames] count];
570 NSLog( @"count: %i", c );
571 for (int i = 0; [[openPanel filenames] count] > i ; i++)
573 msg_Dbg( VLCIntf, "loading subs from %s", [[[openPanel filenames] objectAtIndex: i] UTF8String] );
574 if( input_AddSubtitle( p_input, [[[openPanel filenames] objectAtIndex: i] UTF8String], TRUE ) )
575 msg_Warn( VLCIntf, "unable to load subtitles from '%s'",
576 [[[openPanel filenames] objectAtIndex: i] UTF8String] );
582 - (void)scrollWheel:(NSEvent *)theEvent
584 intf_thread_t * p_intf = VLCIntf;
585 float f_yabsvalue = [theEvent deltaY] > 0.0f ? [theEvent deltaY] : -[theEvent deltaY];
586 float f_xabsvalue = [theEvent deltaX] > 0.0f ? [theEvent deltaX] : -[theEvent deltaX];
587 int i, i_yvlckey, i_xvlckey;
589 if ([theEvent deltaY] < 0.0f)
590 i_yvlckey = KEY_MOUSEWHEELDOWN;
592 i_yvlckey = KEY_MOUSEWHEELUP;
594 if ([theEvent deltaX] < 0.0f)
595 i_xvlckey = KEY_MOUSEWHEELRIGHT;
597 i_xvlckey = KEY_MOUSEWHEELLEFT;
599 /* Send multiple key event, depending on the intensity of the event */
600 for (i = 0; i < (int)(f_yabsvalue/4.+1.) && f_yabsvalue > 0.05 ; i++)
601 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_yvlckey );
603 /* Prioritize Y event (sound volume) over X event */
604 if (f_yabsvalue < 0.05)
606 for (i = 0; i < (int)(f_xabsvalue/6.+1.) && f_xabsvalue > 0.05; i++)
607 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_xvlckey );
611 - (BOOL)keyEvent:(NSEvent *)o_event
613 BOOL eventHandled = NO;
614 unichar key = [[o_event charactersIgnoringModifiers] characterAtIndex: 0];
618 vout_thread_t *p_vout = vlc_object_find( VLCIntf, VLC_OBJECT_VOUT,
623 if( key == (unichar) 0x1b )
625 id o_vout_view = [self voutView];
626 if( o_vout_view && [o_vout_view isFullscreen] )
628 [o_vout_view toggleFullscreen];
632 else if( key == ' ' )
637 vlc_object_release( (vlc_object_t *)p_vout );
643 - (void)setupVarMenuItem:(NSMenuItem *)o_mi
644 target:(vlc_object_t *)p_object
645 var:(const char *)psz_variable
646 selector:(SEL)pf_callback
648 vlc_value_t val, text;
649 int i_type = var_Type( p_object, psz_variable );
651 switch( i_type & VLC_VAR_TYPE )
655 case VLC_VAR_VARIABLE:
657 case VLC_VAR_INTEGER:
660 /* Variable doesn't exist or isn't handled */
664 /* Make sure we want to display the variable */
665 if( i_type & VLC_VAR_HASCHOICE )
667 var_Change( p_object, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL );
668 if( val.i_int == 0 ) return;
669 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
673 /* Get the descriptive name of the variable */
674 var_Change( p_object, psz_variable, VLC_VAR_GETTEXT, &text, NULL );
675 [o_mi setTitle: [[VLCMain sharedInstance] localizedString: text.psz_string ?
676 text.psz_string : strdup( psz_variable ) ]];
678 var_Get( p_object, psz_variable, &val );
679 if( i_type & VLC_VAR_HASCHOICE )
681 NSMenu *o_menu = [o_mi submenu];
683 [self setupVarMenu: o_menu forMenuItem: o_mi target:p_object
684 var:psz_variable selector:pf_callback];
686 free( text.psz_string );
690 VLCAutoGeneratedMenuContent *o_data;
691 switch( i_type & VLC_VAR_TYPE )
694 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
695 andValue: val ofType: i_type];
696 [o_mi setRepresentedObject: [o_data autorelease]];
700 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
701 andValue: val ofType: i_type];
702 [o_mi setRepresentedObject: [o_data autorelease]];
703 if( !( i_type & VLC_VAR_ISCOMMAND ) )
704 [o_mi setState: val.b_bool ? TRUE : FALSE ];
708 free( text.psz_string );
712 if( ( i_type & VLC_VAR_TYPE ) == VLC_VAR_STRING ) free( val.psz_string );
713 free( text.psz_string );
717 - (void)setupVarMenu:(NSMenu *)o_menu
718 forMenuItem: (NSMenuItem *)o_parent
719 target:(vlc_object_t *)p_object
720 var:(const char *)psz_variable
721 selector:(SEL)pf_callback
723 vlc_value_t val, val_list, text_list;
724 int i_type, i, i_nb_items;
726 /* remove previous items */
727 i_nb_items = [o_menu numberOfItems];
728 for( i = 0; i < i_nb_items; i++ )
730 [o_menu removeItemAtIndex: 0];
733 /* Check the type of the object variable */
734 i_type = var_Type( p_object, psz_variable );
736 /* Make sure we want to display the variable */
737 if( i_type & VLC_VAR_HASCHOICE )
739 var_Change( p_object, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL );
740 if( val.i_int == 0 ) return;
741 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
749 switch( i_type & VLC_VAR_TYPE )
753 case VLC_VAR_VARIABLE:
755 case VLC_VAR_INTEGER:
758 /* Variable doesn't exist or isn't handled */
762 if( var_Get( p_object, psz_variable, &val ) < 0 )
767 if( var_Change( p_object, psz_variable, VLC_VAR_GETLIST,
768 &val_list, &text_list ) < 0 )
770 if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
774 /* make (un)sensitive */
775 [o_parent setEnabled: ( val_list.p_list->i_count > 1 )];
777 /* special case for the subtitles items */
778 if( [[o_parent title] isEqualToString: _NS("Subtitles Track")] == YES )
780 NSMenuItem * o_lmi_tmp;
781 o_lmi_tmp = [o_menu addItemWithTitle: _NS("Open File...") action: @selector(addSubtitleFile:) keyEquivalent: @""];
782 [o_lmi_tmp setTarget: self];
783 [o_lmi_tmp setEnabled: YES];
784 [o_parent setEnabled: YES];
785 [o_menu addItem: [NSMenuItem separatorItem]];
788 for( i = 0; i < val_list.p_list->i_count; i++ )
790 vlc_value_t another_val;
792 NSString *o_title = @"";
793 VLCAutoGeneratedMenuContent *o_data;
795 switch( i_type & VLC_VAR_TYPE )
798 another_val.psz_string =
799 strdup(val_list.p_list->p_values[i].psz_string);
801 o_title = [[VLCMain sharedInstance] localizedString: text_list.p_list->p_values[i].psz_string ?
802 text_list.p_list->p_values[i].psz_string : val_list.p_list->p_values[i].psz_string ];
804 o_lmi = [o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""];
805 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: strdup(psz_variable) ofObject: p_object
806 andValue: another_val ofType: i_type];
807 [o_lmi setRepresentedObject: [o_data autorelease]];
808 [o_lmi setTarget: self];
810 if( !strcmp( val.psz_string, val_list.p_list->p_values[i].psz_string ) && !( i_type & VLC_VAR_ISCOMMAND ) )
811 [o_lmi setState: TRUE ];
815 case VLC_VAR_INTEGER:
817 o_title = text_list.p_list->p_values[i].psz_string ?
818 [[VLCMain sharedInstance] localizedString: strdup( text_list.p_list->p_values[i].psz_string )] :
819 [NSString stringWithFormat: @"%d",
820 val_list.p_list->p_values[i].i_int];
822 o_lmi = [o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""];
823 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: strdup(psz_variable) ofObject: p_object
824 andValue: val_list.p_list->p_values[i] ofType: i_type];
825 [o_lmi setRepresentedObject: [o_data autorelease]];
826 [o_lmi setTarget: self];
828 if( val_list.p_list->p_values[i].i_int == val.i_int && !( i_type & VLC_VAR_ISCOMMAND ) )
829 [o_lmi setState: TRUE ];
837 /* special case for the subtitles sub-menu
838 * In case that we don't have any subs, we don't want a separator item at the end */
839 if( [[o_parent title] isEqualToString: _NS("Subtitles Track")] == YES )
841 if( [o_menu numberOfItems] == 2 )
842 [o_menu removeItemAtIndex: 1];
845 /* clean up everything */
846 if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
847 var_FreeList( &val_list, &text_list );
850 - (IBAction)toggleVar:(id)sender
852 NSMenuItem *o_mi = (NSMenuItem *)sender;
853 VLCAutoGeneratedMenuContent *o_data = [o_mi representedObject];
854 [NSThread detachNewThreadSelector: @selector(toggleVarThread:)
855 toTarget: self withObject: o_data];
860 - (int)toggleVarThread: (id)data
862 vlc_object_t *p_object;
863 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
865 assert([data isKindOfClass:[VLCAutoGeneratedMenuContent class]]);
866 VLCAutoGeneratedMenuContent *menuContent = (VLCAutoGeneratedMenuContent *)data;
868 vlc_thread_set_priority( VLCIntf , VLC_THREAD_PRIORITY_LOW );
870 p_object = [menuContent vlcObject];
872 if( p_object != NULL )
874 var_Set( p_object, [menuContent name], [menuContent value] );
875 vlc_object_release( p_object );
883 - (IBAction)goToSpecificTime:(id)sender
885 if( sender == o_specificTime_cancel_btn )
887 [NSApp endSheet: o_specificTime_win];
888 [o_specificTime_win close];
890 else if( sender == o_specificTime_ok_btn )
892 input_thread_t * p_input = pl_CurrentInput( VLCIntf );
895 unsigned int timeInSec = 0;
896 NSString * fieldContent = [o_specificTime_enter_fld stringValue];
897 if( [[fieldContent componentsSeparatedByString: @":"] count] > 1 &&
898 [[fieldContent componentsSeparatedByString: @":"] count] <= 3 )
900 NSArray * ourTempArray = \
901 [fieldContent componentsSeparatedByString: @":"];
903 if( [[fieldContent componentsSeparatedByString: @":"] count] == 3 )
905 timeInSec += ([[ourTempArray objectAtIndex: 0] intValue] * 3600); //h
906 timeInSec += ([[ourTempArray objectAtIndex: 1] intValue] * 60); //m
907 timeInSec += [[ourTempArray objectAtIndex: 2] intValue]; //s
911 timeInSec += ([[ourTempArray objectAtIndex: 0] intValue] * 60); //m
912 timeInSec += [[ourTempArray objectAtIndex: 1] intValue]; //s
916 timeInSec = [fieldContent intValue];
918 input_Control( p_input, INPUT_SET_TIME, (int64_t)(timeInSec * 1000000));
919 vlc_object_release( p_input );
922 [NSApp endSheet: o_specificTime_win];
923 [o_specificTime_win close];
927 input_thread_t * p_input = pl_CurrentInput( VLCIntf );
930 /* we can obviously only do that if an input is available */
931 vlc_value_t pos, length;
932 var_Get( p_input, "time", &pos );
933 [o_specificTime_enter_fld setIntValue: (pos.i_time / 1000000)];
934 var_Get( p_input, "length", &length );
935 [o_specificTime_stepper setMaxValue: (length.i_time / 1000000)];
937 [NSApp beginSheet: o_specificTime_win modalForWindow: \
938 [NSApp mainWindow] modalDelegate: self didEndSelector: nil \
940 [o_specificTime_win makeKeyWindow];
941 vlc_object_release( p_input );
952 msg_Err( VLCIntf, "FSPanel is nil" );
959 @implementation VLCControls (NSMenuValidation)
961 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
963 BOOL bEnabled = TRUE;
965 intf_thread_t * p_intf = VLCIntf;
966 playlist_t * p_playlist = pl_Hold( p_intf );
967 input_thread_t * p_input = playlist_CurrentInput( p_playlist );
969 if( [[o_mi title] isEqualToString: _NS("Faster")] ||
970 [[o_mi title] isEqualToString: _NS("Slower")] )
972 if( p_input != NULL )
974 bEnabled = var_GetBool( p_input, "can-rate" );
981 else if( [[o_mi title] isEqualToString: _NS("Stop")] )
983 if( p_input == NULL )
987 [o_main setupMenus]; /* Make sure input menu is up to date */
989 else if( [[o_mi title] isEqualToString: _NS("Previous")] ||
990 [[o_mi title] isEqualToString: _NS("Next")] )
992 /** \todo fix i_size use */
994 bEnabled = p_playlist->items.i_size > 1;
997 else if( [[o_mi title] isEqualToString: _NS("Random")] )
1000 var_Get( p_playlist, "random", &val );
1001 i_state = val.b_bool ? NSOnState : NSOffState;
1002 [o_mi setState: i_state];
1004 else if( [[o_mi title] isEqualToString: _NS("Repeat One")] )
1007 var_Get( p_playlist, "repeat", &val );
1008 i_state = val.b_bool ? NSOnState : NSOffState;
1009 [o_mi setState: i_state];
1011 else if( [[o_mi title] isEqualToString: _NS("Repeat All")] )
1014 var_Get( p_playlist, "loop", &val );
1015 i_state = val.b_bool ? NSOnState : NSOffState;
1016 [o_mi setState: i_state];
1018 else if( [[o_mi title] isEqualToString: _NS("Step Forward")] ||
1019 [[o_mi title] isEqualToString: _NS("Step Backward")] ||
1020 [[o_mi title] isEqualToString: _NS("Jump To Time")])
1022 if( p_input != NULL )
1024 var_Get( p_input, "can-seek", &val);
1025 bEnabled = val.b_bool;
1027 else bEnabled = FALSE;
1029 else if( [[o_mi title] isEqualToString: _NS("Mute")] )
1031 [o_mi setState: p_intf->p_sys->b_mute ? NSOnState : NSOffState];
1032 [o_main setupMenus]; /* Make sure audio menu is up to date */
1034 else if( [[o_mi title] isEqualToString: _NS("Half Size")] ||
1035 [[o_mi title] isEqualToString: _NS("Normal Size")] ||
1036 [[o_mi title] isEqualToString: _NS("Double Size")] ||
1037 [[o_mi title] isEqualToString: _NS("Fit to Screen")] ||
1038 [[o_mi title] isEqualToString: _NS("Snapshot")] ||
1039 [[o_mi title] isEqualToString: _NS("Fullscreen")] ||
1040 [[o_mi title] isEqualToString: _NS("Float on Top")] )
1043 NSArray *o_windows = [NSApp orderedWindows];
1044 NSEnumerator *o_enumerator = [o_windows objectEnumerator];
1047 vout_thread_t *p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
1049 if( p_vout != NULL )
1051 if( [[o_mi title] isEqualToString: _NS("Float on Top")] )
1053 var_Get( p_vout, "video-on-top", &val );
1054 [o_mi setState: val.b_bool ? NSOnState : NSOffState];
1057 while( (o_window = [o_enumerator nextObject]))
1059 if( [[o_window className] isEqualToString: @"VLCVoutWindow"] ||
1060 [[[VLCMain sharedInstance] embeddedList]
1061 windowContainsEmbedded: o_window])
1068 vlc_object_release( (vlc_object_t *)p_vout );
1070 if( [[o_mi title] isEqualToString: _NS("Fullscreen")] )
1072 var_Get( p_playlist, "fullscreen", &val );
1073 [o_mi setState: val.b_bool];
1076 [o_main setupMenus]; /* Make sure video menu is up to date */
1079 /* Special case for telx menu */
1080 if( [[o_mi title] isEqualToString: _NS("Normal Size")] )
1082 NSMenuItem *item = [[o_mi menu] itemWithTitle:_NS("Teletext")];
1083 bool b_telx = p_input && var_GetInteger( p_input, "teletext-es" ) >= 0;
1085 [[item submenu] setAutoenablesItems:NO];
1086 for( int k=0; k < [[item submenu] numberOfItems]; k++ )
1088 [[[item submenu] itemAtIndex:k] setEnabled: b_telx];
1092 if( p_input ) vlc_object_release( p_input );
1093 pl_Release( p_intf );
1100 /*****************************************************************************
1101 * VLCAutoGeneratedMenuContent implementation
1102 *****************************************************************************
1103 * Object connected to a playlistitem which remembers the data belonging to
1104 * the variable of the autogenerated menu
1105 *****************************************************************************/
1106 @implementation VLCAutoGeneratedMenuContent
1108 -(id) initWithVariableName:(const char *)name ofObject:(vlc_object_t *)object
1109 andValue:(vlc_value_t)val ofType:(int)type
1111 self = [super init];
1115 psz_name = strdup( name );
1116 _vlc_object = vlc_object_hold( object );
1126 vlc_object_release( _vlc_object );
1131 - (const char *)name
1136 - (vlc_value_t)value
1141 - (vlc_object_t *)vlcObject
1143 return vlc_object_hold( _vlc_object );
1155 /*****************************************************************************
1156 * VLCTimeField implementation
1157 *****************************************************************************
1158 * we need this to catch our click-event in the controller window
1159 *****************************************************************************/
1161 @implementation VLCTimeField
1162 - (void)mouseDown: (NSEvent *)ourEvent
1164 if( [ourEvent clickCount] > 1 )
1165 [[[VLCMain sharedInstance] controls] goToSpecificTime: nil];
1167 [[VLCMain sharedInstance] timeFieldWasClicked: self];