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];
53 b_lockAspectRatio = YES;
59 [o_specificTime_mi setTitle: _NS("Jump To Time")];
60 [o_specificTime_cancel_btn setTitle: _NS("Cancel")];
61 [o_specificTime_ok_btn setTitle: _NS("OK")];
62 [o_specificTime_sec_lbl setStringValue: _NS("sec.")];
63 [o_specificTime_goTo_lbl setStringValue: _NS("Jump to time")];
65 o_repeat_off = [NSImage imageNamed:@"repeat_embedded"];
67 [self controlTintChanged];
69 [[NSNotificationCenter defaultCenter] addObserver: self
70 selector: @selector( controlTintChanged )
71 name: NSControlTintDidChangeNotification
75 - (void)controlTintChanged
78 if( [o_btn_repeat image] == o_repeat_single )
80 else if( [o_btn_repeat image] == o_repeat_all )
83 if( [NSColor currentControlTint] == NSGraphiteControlTint )
85 o_repeat_single = [NSImage imageNamed:@"repeat_single_embedded_graphite"];
86 o_repeat_all = [NSImage imageNamed:@"repeat_embedded_graphite"];
88 [o_btn_shuffle setAlternateImage: [NSImage imageNamed: @"shuffle_embedded_graphite"]];
89 [o_btn_addNode setAlternateImage: [NSImage imageNamed: @"add_embedded_graphite"]];
93 o_repeat_single = [NSImage imageNamed:@"repeat_single_embedded_blue"];
94 o_repeat_all = [NSImage imageNamed:@"repeat_embedded_blue"];
96 [o_btn_shuffle setAlternateImage: [NSImage imageNamed: @"shuffle_embedded_blue"]];
97 [o_btn_addNode setAlternateImage: [NSImage imageNamed: @"add_embedded_blue"]];
100 /* update the repeat button, but keep its state */
103 else if( i_repeat == 2 )
111 [[NSNotificationCenter defaultCenter] removeObserver: self];
113 [o_fs_panel release];
114 [o_repeat_single release];
115 [o_repeat_all release];
116 [o_repeat_off release];
121 - (IBAction)play:(id)sender
123 intf_thread_t * p_intf = VLCIntf;
124 playlist_t * p_playlist = pl_Hold( p_intf );
128 empty = playlist_IsEmpty( p_playlist );
131 pl_Release( p_intf );
134 [o_main intfOpenFileGeneric: (id)sender];
136 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_PLAY_PAUSE );
143 id o_embeddedViewList = [[VLCMain sharedInstance] embeddedList];
144 NSEnumerator *o_enumerator = [[NSApp orderedWindows] objectEnumerator];
145 while( !o_voutView && ( o_window = [o_enumerator nextObject] ) )
147 /* We have an embedded vout */
148 if( [o_embeddedViewList windowContainsEmbedded: o_window] )
150 o_voutView = [o_embeddedViewList viewForWindow: o_window];
152 /* We have a detached vout */
153 else if( [[o_window className] isEqualToString: @"VLCVoutWindow"] )
155 o_voutView = [o_window voutView];
158 return [[o_voutView retain] autorelease];
161 - (BOOL)aspectRatioIsLocked
163 return b_lockAspectRatio;
166 - (IBAction)stop:(id)sender
168 intf_thread_t * p_intf = VLCIntf;
169 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_STOP );
170 /* Close the window directly, because we do know that there
171 * won't be anymore video. It's currently waiting a bit. */
172 [[[self voutView] window] orderOut:self];
175 - (IBAction)faster:(id)sender
177 intf_thread_t * p_intf = VLCIntf;
178 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_FASTER );
181 - (IBAction)slower:(id)sender
183 intf_thread_t * p_intf = VLCIntf;
184 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_SLOWER );
187 - (IBAction)prev:(id)sender
189 intf_thread_t * p_intf = VLCIntf;
190 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_PREV );
193 - (IBAction)next:(id)sender
195 intf_thread_t * p_intf = VLCIntf;
196 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_NEXT );
199 - (IBAction)random:(id)sender
202 intf_thread_t * p_intf = VLCIntf;
203 playlist_t * p_playlist = pl_Hold( p_intf );
205 var_Get( p_playlist, "random", &val );
206 val.b_bool = !val.b_bool;
207 var_Set( p_playlist, "random", val );
210 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Random On" ) );
211 config_PutInt( p_playlist, "random", 1 );
215 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Random Off" ) );
216 config_PutInt( p_playlist, "random", 0 );
219 p_intf->p_sys->b_playmode_update = true;
220 p_intf->p_sys->b_intf_update = true;
221 pl_Release( p_intf );
224 /* three little ugly helpers */
227 [o_btn_repeat setImage: o_repeat_single];
228 [o_btn_repeat setAlternateImage: o_repeat_all];
229 [o_btn_repeat_embed setImage: [NSImage imageNamed:@"sidebarRepeatOneOn"]];
233 [o_btn_repeat setImage: o_repeat_all];
234 [o_btn_repeat setAlternateImage: o_repeat_off];
235 [o_btn_repeat_embed setImage: [NSImage imageNamed:@"sidebarRepeatOn"]];
239 [o_btn_repeat setImage: o_repeat_off];
240 [o_btn_repeat setAlternateImage: o_repeat_single];
241 [o_btn_repeat_embed setImage: [NSImage imageNamed:@"sidebarRepeat"]];
246 playlist_t *p_playlist = pl_Hold( VLCIntf );
247 var_Get( p_playlist, "random", &val );
248 [o_btn_shuffle setState: val.b_bool];
250 [o_btn_shuffle_embed setImage: [NSImage imageNamed:@"sidebarShuffleOn"]];
252 [o_btn_shuffle_embed setImage: [NSImage imageNamed:@"sidebarShuffle"]];
253 pl_Release( VLCIntf );
256 - (IBAction)repeatButtonAction:(id)sender
258 vlc_value_t looping,repeating;
259 intf_thread_t * p_intf = VLCIntf;
260 playlist_t * p_playlist = pl_Hold( p_intf );
262 var_Get( p_playlist, "repeat", &repeating );
263 var_Get( p_playlist, "loop", &looping );
265 if( !repeating.b_bool && !looping.b_bool )
267 /* was: no repeating at all, switching to Repeat One */
269 /* set our button's look */
272 /* prepare core communication */
273 repeating.b_bool = true;
274 looping.b_bool = false;
275 config_PutInt( p_playlist, "repeat", 1 );
276 config_PutInt( p_playlist, "loop", 0 );
278 /* show the change */
279 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat One" ) );
281 else if( repeating.b_bool && !looping.b_bool )
283 /* was: Repeat One, switching to Repeat All */
285 /* set our button's look */
288 /* prepare core communication */
289 repeating.b_bool = false;
290 looping.b_bool = true;
291 config_PutInt( p_playlist, "repeat", 0 );
292 config_PutInt( p_playlist, "loop", 1 );
294 /* show the change */
295 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat All" ) );
299 /* was: Repeat All or bug in VLC, switching to Repeat Off */
301 /* set our button's look */
304 /* prepare core communication */
305 repeating.b_bool = false;
306 looping.b_bool = false;
307 config_PutInt( p_playlist, "repeat", 0 );
308 config_PutInt( p_playlist, "loop", 0 );
310 /* show the change */
311 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat Off" ) );
314 /* communicate with core and the main intf loop */
315 var_Set( p_playlist, "repeat", repeating );
316 var_Set( p_playlist, "loop", looping );
317 p_intf->p_sys->b_playmode_update = true;
318 p_intf->p_sys->b_intf_update = true;
320 pl_Release( p_intf );
324 - (IBAction)repeat:(id)sender
327 intf_thread_t * p_intf = VLCIntf;
328 playlist_t * p_playlist = pl_Hold( p_intf );
330 var_Get( p_playlist, "repeat", &val );
333 var_Set( p_playlist, "loop", val );
335 val.b_bool = !val.b_bool;
336 var_Set( p_playlist, "repeat", val );
339 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat One" ) );
340 config_PutInt( p_playlist, "repeat", 1 );
344 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat Off" ) );
345 config_PutInt( p_playlist, "repeat", 0 );
348 p_intf->p_sys->b_playmode_update = true;
349 p_intf->p_sys->b_intf_update = true;
350 pl_Release( p_intf );
353 - (IBAction)loop:(id)sender
356 intf_thread_t * p_intf = VLCIntf;
357 playlist_t * p_playlist = pl_Hold( p_intf );
359 var_Get( p_playlist, "loop", &val );
362 var_Set( p_playlist, "repeat", val );
364 val.b_bool = !val.b_bool;
365 var_Set( p_playlist, "loop", val );
368 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat All" ) );
369 config_PutInt( p_playlist, "loop", 1 );
373 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat Off" ) );
374 config_PutInt( p_playlist, "loop", 0 );
377 p_intf->p_sys->b_playmode_update = true;
378 p_intf->p_sys->b_intf_update = true;
379 pl_Release( p_intf );
382 - (IBAction)quitAfterPlayback:(id)sender
385 playlist_t * p_playlist = pl_Hold( VLCIntf );
386 var_Get( p_playlist, "play-and-exit", &val );
387 val.b_bool = !val.b_bool;
388 var_Set( p_playlist, "play-and-exit", val );
389 pl_Release( VLCIntf );
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 playlist_t * p_playlist = pl_Hold( p_intf );
434 audio_volume_t i_volume = (audio_volume_t)[sender intValue];
437 i_volume_step = config_GetInt( p_intf->p_libvlc, "volume-step" );
438 aout_VolumeSet( p_playlist, i_volume * i_volume_step );
439 pl_Release( p_playlist );
440 /* Manage volume status */
441 [o_main manageVolumeSlider];
444 - (IBAction)showPosition: (id)sender
446 input_thread_t * p_input = pl_CurrentInput( VLCIntf );
447 if( p_input != NULL )
449 vout_thread_t *p_vout = input_GetVout( p_input );
452 var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_POSITION );
453 vlc_object_release( (vlc_object_t *)p_vout );
455 vlc_object_release( p_input );
459 - (IBAction)toogleFullscreen:(id)sender {
460 NSMenuItem *o_mi = [[NSMenuItem alloc] initWithTitle: _NS("Fullscreen") action: nil keyEquivalent:@""];
461 [self windowAction: [o_mi autorelease]];
464 - (BOOL) isFullscreen {
465 id o_vout_view = [self voutView];
468 return [o_vout_view isFullscreen];
473 - (IBAction)windowAction:(id)sender
475 NSString *o_title = [sender title];
476 input_thread_t * p_input = pl_CurrentInput( VLCIntf );
478 if( p_input != NULL )
480 vout_thread_t *p_vout = input_GetVout( p_input );
483 id o_vout_view = [self voutView];
486 if( [o_title isEqualToString: _NS("Half Size") ] )
487 [o_vout_view scaleWindowWithFactor: 0.5 animate: YES];
488 else if( [o_title isEqualToString: _NS("Normal Size") ] )
489 [o_vout_view scaleWindowWithFactor: 1.0 animate: YES];
490 else if( [o_title isEqualToString: _NS("Double Size") ] )
491 [o_vout_view scaleWindowWithFactor: 2.0 animate: YES];
492 else if( [o_title isEqualToString: _NS("Float on Top") ] )
493 [o_vout_view toggleFloatOnTop];
494 else if( [o_title isEqualToString: _NS("Fit to Screen") ] )
496 id o_window = [o_vout_view voutWindow];
497 if( ![o_window isZoomed] )
498 [o_window performZoom:self];
500 else if( [o_title isEqualToString: _NS("Snapshot") ] )
502 [o_vout_view snapshot];
506 /* Fullscreen state for next time will be saved here too */
507 [o_vout_view toggleFullscreen];
510 vlc_object_release( (vlc_object_t *)p_vout );
514 playlist_t * p_playlist = pl_Hold( VLCIntf );
516 if( [o_title isEqualToString: _NS("Fullscreen")] ||
517 [sender isKindOfClass:[NSButton class]] )
519 var_ToggleBool( p_playlist, "fullscreen" );
522 pl_Release( VLCIntf );
524 vlc_object_release( p_input );
528 - (IBAction)telxTransparent:(id)sender
530 intf_thread_t * p_intf = VLCIntf;
532 p_vbi = (vlc_object_t *) vlc_object_find_name( p_intf,
533 "zvbi", FIND_ANYWHERE );
536 var_SetBool( p_vbi, "vbi-opaque", [sender state] );
537 [sender setState: ![sender state]];
538 vlc_object_release( p_vbi );
542 - (IBAction)telxNavLink:(id)sender
544 intf_thread_t * p_intf = VLCIntf;
548 if( [[sender title] isEqualToString: _NS("Index")] )
550 else if( [[sender title] isEqualToString: _NS("Red")] )
552 else if( [[sender title] isEqualToString: _NS("Green")] )
554 else if( [[sender title] isEqualToString: _NS("Yellow")] )
556 else if( [[sender title] isEqualToString: _NS("Blue")] )
558 if( i_page == 0 ) return;
560 p_vbi = (vlc_object_t *) vlc_object_find_name( p_intf,
561 "zvbi", FIND_ANYWHERE );
564 var_SetInteger( p_vbi, "vbi-page", i_page );
565 vlc_object_release( p_vbi );
569 - (IBAction)lockVideosAspectRatio:(id)sender
571 if( [sender state] == NSOffState )
572 [sender setState: NSOnState];
574 [sender setState: NSOffState];
576 b_lockAspectRatio = !b_lockAspectRatio;
579 - (IBAction)addSubtitleFile:(id)sender
581 NSInteger i_returnValue = 0;
582 input_thread_t * p_input = pl_CurrentInput( VLCIntf );
583 if( !p_input ) return;
585 input_item_t *p_item = input_GetItem( p_input );
586 if( !p_item ) return;
588 char *path = input_item_GetURI( p_item );
589 if( !path ) path = strdup( "" );
591 NSOpenPanel * openPanel = [NSOpenPanel openPanel];
592 [openPanel setCanChooseFiles: YES];
593 [openPanel setCanChooseDirectories: NO];
594 [openPanel setAllowsMultipleSelection: YES];
595 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]];
598 if( i_returnValue == NSOKButton )
601 if( !p_input ) return;
603 c = [[openPanel filenames] count];
605 for (int i = 0; i < [[openPanel filenames] count] ; i++)
607 msg_Dbg( VLCIntf, "loading subs from %s", [[[openPanel filenames] objectAtIndex: i] UTF8String] );
608 if( input_AddSubtitle( p_input, [[[openPanel filenames] objectAtIndex: i] UTF8String], TRUE ) )
609 msg_Warn( VLCIntf, "unable to load subtitles from '%s'",
610 [[[openPanel filenames] objectAtIndex: i] UTF8String] );
615 - (void)scrollWheel:(NSEvent *)theEvent
617 intf_thread_t * p_intf = VLCIntf;
618 float f_yabsvalue = [theEvent deltaY] > 0.0f ? [theEvent deltaY] : -[theEvent deltaY];
619 float f_xabsvalue = [theEvent deltaX] > 0.0f ? [theEvent deltaX] : -[theEvent deltaX];
620 int i, i_yvlckey, i_xvlckey;
622 if ([theEvent deltaY] < 0.0f)
623 i_yvlckey = KEY_MOUSEWHEELDOWN;
625 i_yvlckey = KEY_MOUSEWHEELUP;
627 if ([theEvent deltaX] < 0.0f)
628 i_xvlckey = KEY_MOUSEWHEELRIGHT;
630 i_xvlckey = KEY_MOUSEWHEELLEFT;
632 /* Send multiple key event, depending on the intensity of the event */
633 for (i = 0; i < (int)(f_yabsvalue/4.+1.) && f_yabsvalue > 0.05 ; i++)
634 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_yvlckey );
636 /* Prioritize Y event (sound volume) over X event */
637 if (f_yabsvalue < 0.05)
639 for (i = 0; i < (int)(f_xabsvalue/6.+1.) && f_xabsvalue > 0.05; i++)
640 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_xvlckey );
644 - (BOOL)keyEvent:(NSEvent *)o_event
646 BOOL eventHandled = NO;
647 unichar key = [[o_event charactersIgnoringModifiers] characterAtIndex: 0];
651 input_thread_t * p_input = pl_CurrentInput( VLCIntf );
652 if( p_input != NULL )
654 vout_thread_t *p_vout = input_GetVout( p_input );
659 if( key == (unichar) 0x1b )
661 id o_vout_view = [self voutView];
662 if( o_vout_view && [o_vout_view isFullscreen] )
664 [o_vout_view toggleFullscreen];
668 else if( key == ' ' )
673 vlc_object_release( (vlc_object_t *)p_vout );
675 vlc_object_release( p_input );
681 - (void)setupVarMenuItem:(NSMenuItem *)o_mi
682 target:(vlc_object_t *)p_object
683 var:(const char *)psz_variable
684 selector:(SEL)pf_callback
686 vlc_value_t val, text;
687 int i_type = var_Type( p_object, psz_variable );
689 switch( i_type & VLC_VAR_TYPE )
693 case VLC_VAR_VARIABLE:
695 case VLC_VAR_INTEGER:
698 /* Variable doesn't exist or isn't handled */
702 /* Make sure we want to display the variable */
703 if( i_type & VLC_VAR_HASCHOICE )
705 var_Change( p_object, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL );
706 if( val.i_int == 0 ) return;
707 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
711 /* Get the descriptive name of the variable */
712 var_Change( p_object, psz_variable, VLC_VAR_GETTEXT, &text, NULL );
713 [o_mi setTitle: [[VLCMain sharedInstance] localizedString: text.psz_string ?
714 text.psz_string : psz_variable ]];
716 if( i_type & VLC_VAR_HASCHOICE )
718 NSMenu *o_menu = [o_mi submenu];
720 [self setupVarMenu: o_menu forMenuItem: o_mi target:p_object
721 var:psz_variable selector:pf_callback];
723 free( text.psz_string );
726 if( var_Get( p_object, psz_variable, &val ) < 0 )
731 VLCAutoGeneratedMenuContent *o_data;
732 switch( i_type & VLC_VAR_TYPE )
735 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
736 andValue: val ofType: i_type];
737 [o_mi setRepresentedObject: [o_data autorelease]];
741 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
742 andValue: val ofType: i_type];
743 [o_mi setRepresentedObject: [o_data autorelease]];
744 if( !( i_type & VLC_VAR_ISCOMMAND ) )
745 [o_mi setState: val.b_bool ? TRUE : FALSE ];
752 if( ( i_type & VLC_VAR_TYPE ) == VLC_VAR_STRING ) free( val.psz_string );
753 free( text.psz_string );
757 - (void)setupVarMenu:(NSMenu *)o_menu
758 forMenuItem: (NSMenuItem *)o_parent
759 target:(vlc_object_t *)p_object
760 var:(const char *)psz_variable
761 selector:(SEL)pf_callback
763 vlc_value_t val, val_list, text_list;
764 int i_type, i, i_nb_items;
766 /* remove previous items */
767 i_nb_items = [o_menu numberOfItems];
768 for( i = 0; i < i_nb_items; i++ )
770 [o_menu removeItemAtIndex: 0];
773 /* Check the type of the object variable */
774 i_type = var_Type( p_object, psz_variable );
776 /* Make sure we want to display the variable */
777 if( i_type & VLC_VAR_HASCHOICE )
779 var_Change( p_object, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL );
780 if( val.i_int == 0 ) return;
781 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
789 switch( i_type & VLC_VAR_TYPE )
793 case VLC_VAR_VARIABLE:
795 case VLC_VAR_INTEGER:
798 /* Variable doesn't exist or isn't handled */
802 if( var_Get( p_object, psz_variable, &val ) < 0 )
807 if( var_Change( p_object, psz_variable, VLC_VAR_GETLIST,
808 &val_list, &text_list ) < 0 )
810 if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
814 /* make (un)sensitive */
815 [o_parent setEnabled: ( val_list.p_list->i_count > 1 )];
818 if( [[o_parent title] isEqualToString: _NS("Aspect-ratio")] == YES )
820 NSMenuItem *o_lmi_tmp2;
821 o_lmi_tmp2 = [o_menu addItemWithTitle: _NS("Lock Aspect Ratio") action: @selector(lockVideosAspectRatio:) keyEquivalent: @""];
822 [o_lmi_tmp2 setTarget: self];
823 [o_lmi_tmp2 setEnabled: YES];
824 [o_lmi_tmp2 setState: b_lockAspectRatio];
825 [o_parent setEnabled: YES];
826 [o_menu addItem: [NSMenuItem separatorItem]];
829 /* special case for the subtitles items */
830 if( [[o_parent title] isEqualToString: _NS("Subtitles Track")] == YES )
832 NSMenuItem * o_lmi_tmp;
833 o_lmi_tmp = [o_menu addItemWithTitle: _NS("Open File...") action: @selector(addSubtitleFile:) keyEquivalent: @""];
834 [o_lmi_tmp setTarget: self];
835 [o_lmi_tmp setEnabled: YES];
836 [o_parent setEnabled: YES];
837 [o_menu addItem: [NSMenuItem separatorItem]];
840 for( i = 0; i < val_list.p_list->i_count; i++ )
843 NSString *o_title = @"";
844 VLCAutoGeneratedMenuContent *o_data;
846 switch( i_type & VLC_VAR_TYPE )
850 o_title = [[VLCMain sharedInstance] localizedString: text_list.p_list->p_values[i].psz_string ?
851 text_list.p_list->p_values[i].psz_string : val_list.p_list->p_values[i].psz_string ];
853 o_lmi = [o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""];
854 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
855 andValue: val_list.p_list->p_values[i] ofType: i_type];
856 [o_lmi setRepresentedObject: [o_data autorelease]];
857 [o_lmi setTarget: self];
859 if( !strcmp( val.psz_string, val_list.p_list->p_values[i].psz_string ) && !( i_type & VLC_VAR_ISCOMMAND ) )
860 [o_lmi setState: TRUE ];
864 case VLC_VAR_INTEGER:
866 o_title = text_list.p_list->p_values[i].psz_string ?
867 [[VLCMain sharedInstance] localizedString: text_list.p_list->p_values[i].psz_string] :
868 [NSString stringWithFormat: @"%d",
869 val_list.p_list->p_values[i].i_int];
871 o_lmi = [o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""];
872 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
873 andValue: val_list.p_list->p_values[i] ofType: i_type];
874 [o_lmi setRepresentedObject: [o_data autorelease]];
875 [o_lmi setTarget: self];
877 if( val_list.p_list->p_values[i].i_int == val.i_int && !( i_type & VLC_VAR_ISCOMMAND ) )
878 [o_lmi setState: TRUE ];
886 /* special case for the subtitles sub-menu
887 * In case that we don't have any subs, we don't want a separator item at the end */
888 if( [[o_parent title] isEqualToString: _NS("Subtitles Track")] == YES )
890 if( [o_menu numberOfItems] == 2 )
891 [o_menu removeItemAtIndex: 1];
894 /* clean up everything */
895 if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
896 var_FreeList( &val_list, &text_list );
899 - (IBAction)toggleVar:(id)sender
901 NSMenuItem *o_mi = (NSMenuItem *)sender;
902 VLCAutoGeneratedMenuContent *o_data = [o_mi representedObject];
903 [NSThread detachNewThreadSelector: @selector(toggleVarThread:)
904 toTarget: self withObject: o_data];
909 - (int)toggleVarThread: (id)data
911 vlc_object_t *p_object;
912 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
914 assert([data isKindOfClass:[VLCAutoGeneratedMenuContent class]]);
915 VLCAutoGeneratedMenuContent *menuContent = (VLCAutoGeneratedMenuContent *)data;
917 vlc_thread_set_priority( VLCIntf , VLC_THREAD_PRIORITY_LOW );
919 p_object = [menuContent vlcObject];
921 if( p_object != NULL )
923 var_Set( p_object, [menuContent name], [menuContent value] );
924 vlc_object_release( p_object );
932 - (IBAction)goToSpecificTime:(id)sender
934 if( sender == o_specificTime_cancel_btn )
936 [NSApp endSheet: o_specificTime_win];
937 [o_specificTime_win close];
939 else if( sender == o_specificTime_ok_btn )
941 input_thread_t * p_input = pl_CurrentInput( VLCIntf );
944 unsigned int timeInSec = 0;
945 NSString * fieldContent = [o_specificTime_enter_fld stringValue];
946 if( [[fieldContent componentsSeparatedByString: @":"] count] > 1 &&
947 [[fieldContent componentsSeparatedByString: @":"] count] <= 3 )
949 NSArray * ourTempArray = \
950 [fieldContent componentsSeparatedByString: @":"];
952 if( [[fieldContent componentsSeparatedByString: @":"] count] == 3 )
954 timeInSec += ([[ourTempArray objectAtIndex: 0] intValue] * 3600); //h
955 timeInSec += ([[ourTempArray objectAtIndex: 1] intValue] * 60); //m
956 timeInSec += [[ourTempArray objectAtIndex: 2] intValue]; //s
960 timeInSec += ([[ourTempArray objectAtIndex: 0] intValue] * 60); //m
961 timeInSec += [[ourTempArray objectAtIndex: 1] intValue]; //s
965 timeInSec = [fieldContent intValue];
967 input_Control( p_input, INPUT_SET_TIME, (int64_t)(timeInSec * 1000000));
968 vlc_object_release( p_input );
971 [NSApp endSheet: o_specificTime_win];
972 [o_specificTime_win close];
976 input_thread_t * p_input = pl_CurrentInput( VLCIntf );
979 /* we can obviously only do that if an input is available */
980 vlc_value_t pos, length;
981 var_Get( p_input, "time", &pos );
982 [o_specificTime_enter_fld setIntValue: (pos.i_time / 1000000)];
983 var_Get( p_input, "length", &length );
984 [o_specificTime_stepper setMaxValue: (length.i_time / 1000000)];
986 [NSApp beginSheet: o_specificTime_win modalForWindow: \
987 [NSApp mainWindow] modalDelegate: self didEndSelector: nil \
989 [o_specificTime_win makeKeyWindow];
990 vlc_object_release( p_input );
1001 msg_Err( VLCIntf, "FSPanel is nil" );
1008 @implementation VLCControls (NSMenuValidation)
1010 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
1012 BOOL bEnabled = TRUE;
1014 intf_thread_t * p_intf = VLCIntf;
1015 playlist_t * p_playlist = pl_Hold( p_intf );
1016 input_thread_t * p_input = playlist_CurrentInput( p_playlist );
1018 if( [[o_mi title] isEqualToString: _NS("Faster")] ||
1019 [[o_mi title] isEqualToString: _NS("Slower")] )
1021 if( p_input != NULL )
1023 bEnabled = var_GetBool( p_input, "can-rate" );
1030 else if( [[o_mi title] isEqualToString: _NS("Stop")] )
1032 if( p_input == NULL )
1036 [o_main setupMenus]; /* Make sure input menu is up to date */
1038 else if( [[o_mi title] isEqualToString: _NS("Previous")] ||
1039 [[o_mi title] isEqualToString: _NS("Next")] )
1042 bEnabled = playlist_CurrentSize( p_playlist ) > 1;
1045 else if( [[o_mi title] isEqualToString: _NS("Random")] )
1048 var_Get( p_playlist, "random", &val );
1049 i_state = val.b_bool ? NSOnState : NSOffState;
1050 [o_mi setState: i_state];
1052 else if( [[o_mi title] isEqualToString: _NS("Repeat One")] )
1055 var_Get( p_playlist, "repeat", &val );
1056 i_state = val.b_bool ? NSOnState : NSOffState;
1057 [o_mi setState: i_state];
1059 else if( [[o_mi title] isEqualToString: _NS("Repeat All")] )
1062 var_Get( p_playlist, "loop", &val );
1063 i_state = val.b_bool ? NSOnState : NSOffState;
1064 [o_mi setState: i_state];
1066 else if( [[o_mi title] isEqualToString: _NS("Quit after Playback")] )
1069 var_Get( p_playlist, "play-and-exit", &val );
1070 i_state = val.b_bool ? NSOnState : NSOffState;
1071 [o_mi setState: i_state];
1073 else if( [[o_mi title] isEqualToString: _NS("Step Forward")] ||
1074 [[o_mi title] isEqualToString: _NS("Step Backward")] ||
1075 [[o_mi title] isEqualToString: _NS("Jump To Time")])
1077 if( p_input != NULL )
1079 var_Get( p_input, "can-seek", &val);
1080 bEnabled = val.b_bool;
1082 else bEnabled = FALSE;
1084 else if( [[o_mi title] isEqualToString: _NS("Mute")] )
1086 [o_mi setState: p_intf->p_sys->b_mute ? NSOnState : NSOffState];
1087 [o_main setupMenus]; /* Make sure audio menu is up to date */
1089 else if( [[o_mi title] isEqualToString: _NS("Half Size")] ||
1090 [[o_mi title] isEqualToString: _NS("Normal Size")] ||
1091 [[o_mi title] isEqualToString: _NS("Double Size")] ||
1092 [[o_mi title] isEqualToString: _NS("Fit to Screen")] ||
1093 [[o_mi title] isEqualToString: _NS("Snapshot")] ||
1094 [[o_mi title] isEqualToString: _NS("Fullscreen")] ||
1095 [[o_mi title] isEqualToString: _NS("Float on Top")] )
1098 NSArray *o_windows = [NSApp orderedWindows];
1099 NSEnumerator *o_enumerator = [o_windows objectEnumerator];
1102 if( p_input != NULL )
1104 vout_thread_t *p_vout = input_GetVout( p_input );
1105 if( p_vout != NULL )
1107 if( [[o_mi title] isEqualToString: _NS("Float on Top")] )
1109 var_Get( p_vout, "video-on-top", &val );
1110 [o_mi setState: val.b_bool ? NSOnState : NSOffState];
1113 while( (o_window = [o_enumerator nextObject]))
1115 if( [[o_window className] isEqualToString: @"VLCVoutWindow"] ||
1116 [[[VLCMain sharedInstance] embeddedList]
1117 windowContainsEmbedded: o_window])
1124 vlc_object_release( (vlc_object_t *)p_vout );
1126 vlc_object_release( p_input );
1128 if( [[o_mi title] isEqualToString: _NS("Fullscreen")] )
1130 var_Get( p_playlist, "fullscreen", &val );
1131 [o_mi setState: val.b_bool];
1134 [o_main setupMenus]; /* Make sure video menu is up to date */
1137 /* Special case for telx menu */
1138 if( [[o_mi title] isEqualToString: _NS("Normal Size")] )
1140 NSMenuItem *item = [[o_mi menu] itemWithTitle:_NS("Teletext")];
1141 bool b_telx = p_input && var_GetInteger( p_input, "teletext-es" ) >= 0;
1143 [[item submenu] setAutoenablesItems:NO];
1144 for( int k=0; k < [[item submenu] numberOfItems]; k++ )
1146 [[[item submenu] itemAtIndex:k] setEnabled: b_telx];
1150 if( p_input ) vlc_object_release( p_input );
1151 pl_Release( p_intf );
1158 /*****************************************************************************
1159 * VLCAutoGeneratedMenuContent implementation
1160 *****************************************************************************
1161 * Object connected to a playlistitem which remembers the data belonging to
1162 * the variable of the autogenerated menu
1163 *****************************************************************************/
1164 @implementation VLCAutoGeneratedMenuContent
1166 -(id) initWithVariableName:(const char *)name ofObject:(vlc_object_t *)object
1167 andValue:(vlc_value_t)val ofType:(int)type
1169 self = [super init];
1173 _vlc_object = vlc_object_hold( object );
1174 psz_name = strdup( name );
1177 if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING )
1178 value.psz_string = strdup( val.psz_string );
1186 vlc_object_release( _vlc_object );
1187 if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING )
1188 free( value.psz_string );
1193 - (const char *)name
1198 - (vlc_value_t)value
1203 - (vlc_object_t *)vlcObject
1205 return vlc_object_hold( _vlc_object );
1217 /*****************************************************************************
1218 * VLCTimeField implementation
1219 *****************************************************************************
1220 * we need this to catch our click-event in the controller window
1221 *****************************************************************************/
1223 @implementation VLCTimeField
1224 - (void)mouseDown: (NSEvent *)ourEvent
1226 if( [ourEvent clickCount] > 1 )
1227 [[[VLCMain sharedInstance] controls] goToSpecificTime: nil];
1229 [[VLCMain sharedInstance] timeFieldWasClicked: self];