1 /*****************************************************************************
2 * controls.m: MacOS X interface module
3 *****************************************************************************
4 * Copyright (C) 2002-2011 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")];
69 [[NSNotificationCenter defaultCenter] removeObserver: self];
76 - (IBAction)play:(id)sender
78 intf_thread_t * p_intf = VLCIntf;
79 playlist_t * p_playlist = pl_Get( p_intf );
83 empty = playlist_IsEmpty( p_playlist );
87 [o_main intfOpenFileGeneric: (id)sender];
89 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_PLAY_PAUSE );
96 id o_embeddedViewList = [[VLCMain sharedInstance] embeddedList];
97 NSEnumerator *o_enumerator = [[NSApp orderedWindows] objectEnumerator];
98 while( !o_voutView && ( o_window = [o_enumerator nextObject] ) )
100 /* We have an embedded vout */
101 if( [o_embeddedViewList windowContainsEmbedded: o_window] )
103 o_voutView = [o_embeddedViewList viewForWindow: o_window];
105 /* We have a detached vout */
106 else if( [[o_window className] isEqualToString: @"VLCVoutWindow"] )
108 o_voutView = [o_window voutView];
111 return [[o_voutView retain] autorelease];
114 - (BOOL)aspectRatioIsLocked
116 return b_lockAspectRatio;
119 - (IBAction)stop:(id)sender
121 intf_thread_t * p_intf = VLCIntf;
122 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_STOP );
123 /* Close the window directly, because we do know that there
124 * won't be anymore video. It's currently waiting a bit. */
125 [[[self voutView] window] orderOut:self];
128 - (IBAction)faster:(id)sender
130 intf_thread_t * p_intf = VLCIntf;
131 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_FASTER );
134 - (IBAction)slower:(id)sender
136 intf_thread_t * p_intf = VLCIntf;
137 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_SLOWER );
140 - (IBAction)normalSpeed:(id)sender
142 intf_thread_t * p_intf = VLCIntf;
143 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_RATE_NORMAL );
146 - (IBAction)prev:(id)sender
148 intf_thread_t * p_intf = VLCIntf;
149 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_PREV );
152 - (IBAction)next:(id)sender
154 intf_thread_t * p_intf = VLCIntf;
155 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_NEXT );
158 - (IBAction)random:(id)sender
161 intf_thread_t * p_intf = VLCIntf;
162 playlist_t * p_playlist = pl_Get( p_intf );
164 var_Get( p_playlist, "random", &val );
165 val.b_bool = !val.b_bool;
166 var_Set( p_playlist, "random", val );
169 //vout_OSDMessage( p_intf, SPU_DEFAULT_CHANNEL, "%s", _( "Random On" ) );
170 config_PutInt( p_playlist, "random", 1 );
174 //vout_OSDMessage( p_intf, SPU_DEFAULT_CHANNEL, "%s", _( "Random Off" ) );
175 config_PutInt( p_playlist, "random", 0 );
178 p_intf->p_sys->b_playmode_update = true;
179 p_intf->p_sys->b_intf_update = true;
182 /* three little ugly helpers */
185 [o_btn_repeat setImage: [NSImage imageNamed:@"repeat_single_embedded_graphite"]];
186 [o_btn_repeat setAlternateImage: [NSImage imageNamed:@"repeat_embedded_graphite"]];
190 [o_btn_repeat setImage: [NSImage imageNamed:@"repeat_embedded_graphite"]];
191 [o_btn_repeat setAlternateImage: [NSImage imageNamed:@"repeat_embedded"]];
195 [o_btn_repeat setImage: [NSImage imageNamed:@"repeat_embedded"]];
196 [o_btn_repeat setAlternateImage: [NSImage imageNamed:@"repeat_embedded_graphite"]];
201 playlist_t *p_playlist = pl_Get( VLCIntf );
202 var_Get( p_playlist, "random", &val );
203 [o_btn_shuffle setState: val.b_bool];
205 [o_btn_shuffle_embed setImage: [NSImage imageNamed:@"shuffle_embedded_graphite"]];
207 [o_btn_shuffle_embed setImage: [NSImage imageNamed:@"shuffle_embedded"]];
210 - (IBAction)repeatButtonAction:(id)sender
212 vlc_value_t looping,repeating;
213 intf_thread_t * p_intf = VLCIntf;
214 playlist_t * p_playlist = pl_Get( p_intf );
216 var_Get( p_playlist, "repeat", &repeating );
217 var_Get( p_playlist, "loop", &looping );
219 if( !repeating.b_bool && !looping.b_bool )
221 /* was: no repeating at all, switching to Repeat One */
223 /* set our button's look */
226 /* prepare core communication */
227 repeating.b_bool = true;
228 looping.b_bool = false;
229 config_PutInt( p_playlist, "repeat", 1 );
230 config_PutInt( p_playlist, "loop", 0 );
232 /* show the change */
233 //vout_OSDMessage( p_intf, SPU_DEFAULT_CHANNEL, "%s", _( "Repeat One" ) );
235 else if( repeating.b_bool && !looping.b_bool )
237 /* was: Repeat One, switching to Repeat All */
239 /* set our button's look */
242 /* prepare core communication */
243 repeating.b_bool = false;
244 looping.b_bool = true;
245 config_PutInt( p_playlist, "repeat", 0 );
246 config_PutInt( p_playlist, "loop", 1 );
248 /* show the change */
249 //vout_OSDMessage( p_intf, SPU_DEFAULT_CHANNEL, "%s", _( "Repeat All" ) );
253 /* was: Repeat All or bug in VLC, switching to Repeat Off */
255 /* set our button's look */
258 /* prepare core communication */
259 repeating.b_bool = false;
260 looping.b_bool = false;
261 config_PutInt( p_playlist, "repeat", 0 );
262 config_PutInt( p_playlist, "loop", 0 );
264 /* show the change */
265 //vout_OSDMessage( p_intf, SPU_DEFAULT_CHANNEL, "%s", _( "Repeat Off" ) );
268 /* communicate with core and the main intf loop */
269 var_Set( p_playlist, "repeat", repeating );
270 var_Set( p_playlist, "loop", looping );
271 p_intf->p_sys->b_playmode_update = true;
272 p_intf->p_sys->b_intf_update = true;
276 - (IBAction)repeat:(id)sender
279 intf_thread_t * p_intf = VLCIntf;
280 playlist_t * p_playlist = pl_Get( p_intf );
282 var_Get( p_playlist, "repeat", &val );
285 var_Set( p_playlist, "loop", val );
287 val.b_bool = !val.b_bool;
288 var_Set( p_playlist, "repeat", val );
291 //vout_OSDMessage( p_intf, SPU_DEFAULT_CHANNEL, "%s", _( "Repeat One" ) );
292 config_PutInt( p_playlist, "repeat", 1 );
296 //vout_OSDMessage( p_intf, SPU_DEFAULT_CHANNEL, "%s", _( "Repeat Off" ) );
297 config_PutInt( p_playlist, "repeat", 0 );
300 p_intf->p_sys->b_playmode_update = true;
301 p_intf->p_sys->b_intf_update = true;
304 - (IBAction)loop:(id)sender
307 intf_thread_t * p_intf = VLCIntf;
308 playlist_t * p_playlist = pl_Get( p_intf );
310 var_Get( p_playlist, "loop", &val );
313 var_Set( p_playlist, "repeat", val );
315 val.b_bool = !val.b_bool;
316 var_Set( p_playlist, "loop", val );
319 //vout_OSDMessage( p_intf, SPU_DEFAULT_CHANNEL, "%s", _( "Repeat All" ) );
320 config_PutInt( p_playlist, "loop", 1 );
324 //vout_OSDMessage( p_intf, SPU_DEFAULT_CHANNEL, "%s", _( "Repeat Off" ) );
325 config_PutInt( p_playlist, "loop", 0 );
328 p_intf->p_sys->b_playmode_update = true;
329 p_intf->p_sys->b_intf_update = true;
332 - (IBAction)quitAfterPlayback:(id)sender
335 playlist_t * p_playlist = pl_Get( VLCIntf );
336 var_ToggleBool( p_playlist, "play-and-exit" );
339 - (IBAction)forward:(id)sender
341 intf_thread_t * p_intf = VLCIntf;
342 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_JUMP_FORWARD_SHORT );
345 - (IBAction)backward:(id)sender
348 intf_thread_t * p_intf = VLCIntf;
349 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_JUMP_BACKWARD_SHORT );
353 - (IBAction)volumeUp:(id)sender
355 intf_thread_t * p_intf = VLCIntf;
356 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_VOL_UP );
357 /* Manage volume status */
358 [o_main manageVolumeSlider];
361 - (IBAction)volumeDown:(id)sender
363 intf_thread_t * p_intf = VLCIntf;
364 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_VOL_DOWN );
365 /* Manage volume status */
366 [o_main manageVolumeSlider];
369 - (IBAction)mute:(id)sender
371 intf_thread_t * p_intf = VLCIntf;
372 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_VOL_MUTE );
373 /* Manage volume status */
374 [o_main manageVolumeSlider];
377 - (IBAction)volumeSliderUpdated:(id)sender
379 intf_thread_t * p_intf = VLCIntf;
380 playlist_t * p_playlist = pl_Get( p_intf );
381 audio_volume_t i_volume = (audio_volume_t)[sender intValue];
384 i_volume_step = config_GetInt( p_intf->p_libvlc, "volume-step" );
385 aout_VolumeSet( p_playlist, i_volume * i_volume_step );
386 /* Manage volume status */
387 [o_main manageVolumeSlider];
390 - (IBAction)showPosition: (id)sender
392 input_thread_t * p_input = pl_CurrentInput( VLCIntf );
393 if( p_input != NULL )
395 vout_thread_t *p_vout = input_GetVout( p_input );
398 var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_POSITION );
399 vlc_object_release( (vlc_object_t *)p_vout );
401 vlc_object_release( p_input );
405 - (IBAction)toogleFullscreen:(id)sender {
406 NSMenuItem *o_mi = [[NSMenuItem alloc] initWithTitle: _NS("Fullscreen") action: nil keyEquivalent:@""];
407 [self windowAction: [o_mi autorelease]];
410 - (BOOL) isFullscreen {
411 id o_vout_view = [self voutView];
414 return [o_vout_view isFullscreen];
419 - (IBAction)windowAction:(id)sender
421 NSString *o_title = [sender title];
422 input_thread_t * p_input = pl_CurrentInput( VLCIntf );
424 if( p_input != NULL )
426 vout_thread_t *p_vout = input_GetVout( p_input );
429 id o_vout_view = [self voutView];
432 if( [o_title isEqualToString: _NS("Half Size") ] )
433 [o_vout_view scaleWindowWithFactor: 0.5 animate: YES];
434 else if( [o_title isEqualToString: _NS("Normal Size") ] )
435 [o_vout_view scaleWindowWithFactor: 1.0 animate: YES];
436 else if( [o_title isEqualToString: _NS("Double Size") ] )
437 [o_vout_view scaleWindowWithFactor: 2.0 animate: YES];
438 else if( [o_title isEqualToString: _NS("Float on Top") ] )
439 [o_vout_view toggleFloatOnTop];
440 else if( [o_title isEqualToString: _NS("Fit to Screen") ] )
442 id o_window = [o_vout_view voutWindow];
443 if( ![o_window isZoomed] )
444 [o_window performZoom:self];
446 else if( [o_title isEqualToString: _NS("Snapshot") ] )
448 [o_vout_view snapshot];
452 /* Fullscreen state for next time will be saved here too */
453 [o_vout_view toggleFullscreen];
456 vlc_object_release( (vlc_object_t *)p_vout );
460 playlist_t * p_playlist = pl_Get( VLCIntf );
462 if( [o_title isEqualToString: _NS("Fullscreen")] ||
463 [sender isKindOfClass:[NSButton class]] )
465 var_ToggleBool( p_playlist, "fullscreen" );
468 vlc_object_release( p_input );
472 - (IBAction)telxTransparent:(id)sender
475 p_vbi = (vlc_object_t *) vlc_object_find_name( pl_Get( VLCIntf ), "zvbi" );
478 var_SetBool( p_vbi, "vbi-opaque", [sender state] );
479 [sender setState: ![sender state]];
480 vlc_object_release( p_vbi );
484 - (IBAction)telxNavLink:(id)sender
486 intf_thread_t * p_intf = VLCIntf;
490 if( [[sender title] isEqualToString: _NS("Index")] )
492 else if( [[sender title] isEqualToString: _NS("Red")] )
494 else if( [[sender title] isEqualToString: _NS("Green")] )
496 else if( [[sender title] isEqualToString: _NS("Yellow")] )
498 else if( [[sender title] isEqualToString: _NS("Blue")] )
500 if( i_page == 0 ) return;
502 p_vbi = (vlc_object_t *) vlc_object_find_name( pl_Get( VLCIntf ), "zvbi" );
505 var_SetInteger( p_vbi, "vbi-page", i_page );
506 vlc_object_release( p_vbi );
510 - (IBAction)lockVideosAspectRatio:(id)sender
512 if( [sender state] == NSOffState )
513 [sender setState: NSOnState];
515 [sender setState: NSOffState];
517 b_lockAspectRatio = !b_lockAspectRatio;
520 - (IBAction)addSubtitleFile:(id)sender
522 NSInteger i_returnValue = 0;
523 input_thread_t * p_input = pl_CurrentInput( VLCIntf );
524 if( !p_input ) return;
526 input_item_t *p_item = input_GetItem( p_input );
527 if( !p_item ) return;
529 char *path = input_item_GetURI( p_item );
530 if( !path ) path = strdup( "" );
532 NSOpenPanel * openPanel = [NSOpenPanel openPanel];
533 [openPanel setCanChooseFiles: YES];
534 [openPanel setCanChooseDirectories: NO];
535 [openPanel setAllowsMultipleSelection: YES];
536 [openPanel setAllowedFileTypes: [NSArray arrayWithObjects: @"cdg",@"@idx",@"srt",@"sub",@"utf",@"ass",@"ssa",@"aqt",@"jss",@"psb",@"rt",@"smi",@"txt",@"smil", nil]];
537 [openPanel setDirectoryURL:[NSURL fileURLWithPath:[[NSString stringWithUTF8String:path] stringByExpandingTildeInPath]]];
538 i_returnValue = [openPanel runModal];
541 if( i_returnValue == NSOKButton )
544 if( !p_input ) return;
546 c = [[openPanel URLs] count];
548 for (int i = 0; i < c ; i++)
550 msg_Dbg( VLCIntf, "loading subs from %s", [[[[openPanel URLs] objectAtIndex: i] path] UTF8String] );
551 if( input_AddSubtitle( p_input, [[[[openPanel URLs] objectAtIndex: i] path] UTF8String], TRUE ) )
552 msg_Warn( VLCIntf, "unable to load subtitles from '%s'",
553 [[[[openPanel URLs] objectAtIndex: i] path] UTF8String] );
558 - (void)scrollWheel:(NSEvent *)theEvent
560 intf_thread_t * p_intf = VLCIntf;
561 float f_yabsvalue = [theEvent deltaY] > 0.0f ? [theEvent deltaY] : -[theEvent deltaY];
562 float f_xabsvalue = [theEvent deltaX] > 0.0f ? [theEvent deltaX] : -[theEvent deltaX];
563 int i, i_yvlckey, i_xvlckey;
565 if ([theEvent deltaY] < 0.0f)
566 i_yvlckey = KEY_MOUSEWHEELDOWN;
568 i_yvlckey = KEY_MOUSEWHEELUP;
570 if ([theEvent deltaX] < 0.0f)
571 i_xvlckey = KEY_MOUSEWHEELRIGHT;
573 i_xvlckey = KEY_MOUSEWHEELLEFT;
575 /* Send multiple key event, depending on the intensity of the event */
576 for (i = 0; i < (int)(f_yabsvalue/4.+1.) && f_yabsvalue > 0.05 ; i++)
577 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_yvlckey );
579 /* Prioritize Y event (sound volume) over X event */
580 if (f_yabsvalue < 0.05)
582 for (i = 0; i < (int)(f_xabsvalue/6.+1.) && f_xabsvalue > 0.05; i++)
583 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_xvlckey );
587 - (BOOL)keyEvent:(NSEvent *)o_event
589 BOOL eventHandled = NO;
590 unichar key = [[o_event charactersIgnoringModifiers] characterAtIndex: 0];
594 input_thread_t * p_input = pl_CurrentInput( VLCIntf );
595 if( p_input != NULL )
597 vout_thread_t *p_vout = input_GetVout( p_input );
602 if( key == (unichar) 0x1b )
604 id o_vout_view = [self voutView];
605 if( o_vout_view && [o_vout_view isFullscreen] )
607 [o_vout_view toggleFullscreen];
611 else if( key == ' ' )
616 vlc_object_release( (vlc_object_t *)p_vout );
618 vlc_object_release( p_input );
624 - (void)setupVarMenuItem:(NSMenuItem *)o_mi
625 target:(vlc_object_t *)p_object
626 var:(const char *)psz_variable
627 selector:(SEL)pf_callback
629 vlc_value_t val, text;
630 int i_type = var_Type( p_object, psz_variable );
632 switch( i_type & VLC_VAR_TYPE )
636 case VLC_VAR_VARIABLE:
638 case VLC_VAR_INTEGER:
641 /* Variable doesn't exist or isn't handled */
645 /* Make sure we want to display the variable */
646 if( i_type & VLC_VAR_HASCHOICE )
648 var_Change( p_object, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL );
649 if( val.i_int == 0 ) return;
650 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
654 /* Get the descriptive name of the variable */
655 var_Change( p_object, psz_variable, VLC_VAR_GETTEXT, &text, NULL );
656 [o_mi setTitle: [[VLCMain sharedInstance] localizedString: text.psz_string ?
657 text.psz_string : psz_variable ]];
659 if( i_type & VLC_VAR_HASCHOICE )
661 NSMenu *o_menu = [o_mi submenu];
663 [self setupVarMenu: o_menu forMenuItem: o_mi target:p_object
664 var:psz_variable selector:pf_callback];
666 free( text.psz_string );
669 if( var_Get( p_object, psz_variable, &val ) < 0 )
674 VLCAutoGeneratedMenuContent *o_data;
675 switch( i_type & VLC_VAR_TYPE )
678 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
679 andValue: val ofType: i_type];
680 [o_mi setRepresentedObject: [o_data autorelease]];
684 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
685 andValue: val ofType: i_type];
686 [o_mi setRepresentedObject: [o_data autorelease]];
687 if( !( i_type & VLC_VAR_ISCOMMAND ) )
688 [o_mi setState: val.b_bool ? TRUE : FALSE ];
695 if( ( i_type & VLC_VAR_TYPE ) == VLC_VAR_STRING ) free( val.psz_string );
696 free( text.psz_string );
700 - (void)setupVarMenu:(NSMenu *)o_menu
701 forMenuItem: (NSMenuItem *)o_parent
702 target:(vlc_object_t *)p_object
703 var:(const char *)psz_variable
704 selector:(SEL)pf_callback
706 vlc_value_t val, val_list, text_list;
707 int i_type, i, i_nb_items;
709 /* remove previous items */
710 i_nb_items = [o_menu numberOfItems];
711 for( i = 0; i < i_nb_items; i++ )
713 [o_menu removeItemAtIndex: 0];
716 /* Check the type of the object variable */
717 i_type = var_Type( p_object, psz_variable );
719 /* Make sure we want to display the variable */
720 if( i_type & VLC_VAR_HASCHOICE )
722 var_Change( p_object, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL );
723 if( val.i_int == 0 ) return;
724 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
732 switch( i_type & VLC_VAR_TYPE )
736 case VLC_VAR_VARIABLE:
738 case VLC_VAR_INTEGER:
741 /* Variable doesn't exist or isn't handled */
745 if( var_Get( p_object, psz_variable, &val ) < 0 )
750 if( var_Change( p_object, psz_variable, VLC_VAR_GETLIST,
751 &val_list, &text_list ) < 0 )
753 if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
757 /* make (un)sensitive */
758 [o_parent setEnabled: ( val_list.p_list->i_count > 1 )];
761 if( [[o_parent title] isEqualToString: _NS("Aspect-ratio")] == YES )
763 NSMenuItem *o_lmi_tmp2;
764 o_lmi_tmp2 = [o_menu addItemWithTitle: _NS("Lock Aspect Ratio") action: @selector(lockVideosAspectRatio:) keyEquivalent: @""];
765 [o_lmi_tmp2 setTarget: self];
766 [o_lmi_tmp2 setEnabled: YES];
767 [o_lmi_tmp2 setState: b_lockAspectRatio];
768 [o_parent setEnabled: YES];
769 [o_menu addItem: [NSMenuItem separatorItem]];
772 /* special case for the subtitles items */
773 if( [[o_parent title] isEqualToString: _NS("Subtitles Track")] == YES )
775 NSMenuItem * o_lmi_tmp;
776 o_lmi_tmp = [o_menu addItemWithTitle: _NS("Open File...") action: @selector(addSubtitleFile:) keyEquivalent: @""];
777 [o_lmi_tmp setTarget: self];
778 [o_lmi_tmp setEnabled: YES];
779 [o_parent setEnabled: YES];
780 [o_menu addItem: [NSMenuItem separatorItem]];
783 for( i = 0; i < val_list.p_list->i_count; i++ )
786 NSString *o_title = @"";
787 VLCAutoGeneratedMenuContent *o_data;
789 switch( i_type & VLC_VAR_TYPE )
793 o_title = [[VLCMain sharedInstance] localizedString: text_list.p_list->p_values[i].psz_string ?
794 text_list.p_list->p_values[i].psz_string : val_list.p_list->p_values[i].psz_string ];
796 o_lmi = [o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""];
797 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
798 andValue: val_list.p_list->p_values[i] ofType: i_type];
799 [o_lmi setRepresentedObject: [o_data autorelease]];
800 [o_lmi setTarget: self];
802 if( !strcmp( val.psz_string, val_list.p_list->p_values[i].psz_string ) && !( i_type & VLC_VAR_ISCOMMAND ) )
803 [o_lmi setState: TRUE ];
807 case VLC_VAR_INTEGER:
809 o_title = text_list.p_list->p_values[i].psz_string ?
810 [[VLCMain sharedInstance] localizedString: text_list.p_list->p_values[i].psz_string] :
811 [NSString stringWithFormat: @"%"PRId64,
812 val_list.p_list->p_values[i].i_int];
814 o_lmi = [o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""];
815 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
816 andValue: val_list.p_list->p_values[i] ofType: i_type];
817 [o_lmi setRepresentedObject: [o_data autorelease]];
818 [o_lmi setTarget: self];
820 if( val_list.p_list->p_values[i].i_int == val.i_int && !( i_type & VLC_VAR_ISCOMMAND ) )
821 [o_lmi setState: TRUE ];
829 /* special case for the subtitles sub-menu
830 * In case that we don't have any subs, we don't want a separator item at the end */
831 if( [[o_parent title] isEqualToString: _NS("Subtitles Track")] == YES )
833 if( [o_menu numberOfItems] == 2 )
834 [o_menu removeItemAtIndex: 1];
837 /* clean up everything */
838 if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
839 var_FreeList( &val_list, &text_list );
842 - (IBAction)toggleVar:(id)sender
844 NSMenuItem *o_mi = (NSMenuItem *)sender;
845 VLCAutoGeneratedMenuContent *o_data = [o_mi representedObject];
846 [NSThread detachNewThreadSelector: @selector(toggleVarThread:)
847 toTarget: self withObject: o_data];
852 - (int)toggleVarThread: (id)data
854 vlc_object_t *p_object;
855 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
857 assert([data isKindOfClass:[VLCAutoGeneratedMenuContent class]]);
858 VLCAutoGeneratedMenuContent *menuContent = (VLCAutoGeneratedMenuContent *)data;
860 p_object = [menuContent vlcObject];
862 if( p_object != NULL )
864 var_Set( p_object, [menuContent name], [menuContent value] );
865 vlc_object_release( p_object );
873 - (IBAction)goToSpecificTime:(id)sender
875 if( sender == o_specificTime_cancel_btn )
877 [NSApp endSheet: o_specificTime_win];
878 [o_specificTime_win close];
880 else if( sender == o_specificTime_ok_btn )
882 input_thread_t * p_input = pl_CurrentInput( VLCIntf );
885 int64_t timeInSec = 0;
886 NSString * fieldContent = [o_specificTime_enter_fld stringValue];
887 if( [[fieldContent componentsSeparatedByString: @":"] count] > 1 &&
888 [[fieldContent componentsSeparatedByString: @":"] count] <= 3 )
890 NSArray * ourTempArray = \
891 [fieldContent componentsSeparatedByString: @":"];
893 if( [[fieldContent componentsSeparatedByString: @":"] count] == 3 )
895 timeInSec += ([[ourTempArray objectAtIndex: 0] intValue] * 3600); //h
896 timeInSec += ([[ourTempArray objectAtIndex: 1] intValue] * 60); //m
897 timeInSec += [[ourTempArray objectAtIndex: 2] intValue]; //s
901 timeInSec += ([[ourTempArray objectAtIndex: 0] intValue] * 60); //m
902 timeInSec += [[ourTempArray objectAtIndex: 1] intValue]; //s
906 timeInSec = [fieldContent intValue];
908 input_Control( p_input, INPUT_SET_TIME, (int64_t)(timeInSec * 1000000));
909 vlc_object_release( p_input );
912 [NSApp endSheet: o_specificTime_win];
913 [o_specificTime_win close];
917 input_thread_t * p_input = pl_CurrentInput( VLCIntf );
920 /* we can obviously only do that if an input is available */
921 vlc_value_t pos, length;
922 var_Get( p_input, "time", &pos );
923 [o_specificTime_enter_fld setIntValue: (pos.i_time / 1000000)];
924 var_Get( p_input, "length", &length );
925 [o_specificTime_stepper setMaxValue: (length.i_time / 1000000)];
927 [NSApp beginSheet: o_specificTime_win modalForWindow: \
928 [NSApp mainWindow] modalDelegate: self didEndSelector: nil \
930 [o_specificTime_win makeKeyWindow];
931 vlc_object_release( p_input );
942 msg_Err( VLCIntf, "FSPanel is nil" );
949 @implementation VLCControls (NSMenuValidation)
951 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
953 BOOL bEnabled = TRUE;
955 intf_thread_t * p_intf = VLCIntf;
956 playlist_t * p_playlist = pl_Get( p_intf );
957 input_thread_t * p_input = playlist_CurrentInput( p_playlist );
959 if( [[o_mi title] isEqualToString: _NS("Faster")] ||
960 [[o_mi title] isEqualToString: _NS("Slower")] ||
961 [[o_mi title] isEqualToString: _NS("Normal rate")] )
963 if( p_input != NULL )
965 bEnabled = var_GetBool( p_input, "can-rate" );
972 else if( [[o_mi title] isEqualToString: _NS("Stop")] )
974 if( p_input == NULL )
978 [o_main setupMenus]; /* Make sure input menu is up to date */
980 else if( [[o_mi title] isEqualToString: _NS("Previous")] ||
981 [[o_mi title] isEqualToString: _NS("Next")] )
984 bEnabled = playlist_CurrentSize( p_playlist ) > 1;
987 else if( [[o_mi title] isEqualToString: _NS("Random")] )
990 var_Get( p_playlist, "random", &val );
991 i_state = val.b_bool ? NSOnState : NSOffState;
992 [o_mi setState: i_state];
994 else if( [[o_mi title] isEqualToString: _NS("Repeat One")] )
997 var_Get( p_playlist, "repeat", &val );
998 i_state = val.b_bool ? NSOnState : NSOffState;
999 [o_mi setState: i_state];
1001 else if( [[o_mi title] isEqualToString: _NS("Repeat All")] )
1004 var_Get( p_playlist, "loop", &val );
1005 i_state = val.b_bool ? NSOnState : NSOffState;
1006 [o_mi setState: i_state];
1008 else if( [[o_mi title] isEqualToString: _NS("Quit after Playback")] )
1011 var_Get( p_playlist, "play-and-exit", &val );
1012 i_state = val.b_bool ? NSOnState : NSOffState;
1013 [o_mi setState: i_state];
1015 else if( [[o_mi title] isEqualToString: _NS("Step Forward")] ||
1016 [[o_mi title] isEqualToString: _NS("Step Backward")] ||
1017 [[o_mi title] isEqualToString: _NS("Jump To Time")])
1019 if( p_input != NULL )
1021 var_Get( p_input, "can-seek", &val);
1022 bEnabled = val.b_bool;
1024 else bEnabled = FALSE;
1026 else if( [[o_mi title] isEqualToString: _NS("Mute")] )
1028 [o_mi setState: p_intf->p_sys->b_mute ? NSOnState : NSOffState];
1029 [o_main setupMenus]; /* Make sure audio menu is up to date */
1031 else if( [[o_mi title] isEqualToString: _NS("Half Size")] ||
1032 [[o_mi title] isEqualToString: _NS("Normal Size")] ||
1033 [[o_mi title] isEqualToString: _NS("Double Size")] ||
1034 [[o_mi title] isEqualToString: _NS("Fit to Screen")] ||
1035 [[o_mi title] isEqualToString: _NS("Snapshot")] ||
1036 [[o_mi title] isEqualToString: _NS("Fullscreen")] ||
1037 [[o_mi title] isEqualToString: _NS("Float on Top")] )
1040 NSArray *o_windows = [NSApp orderedWindows];
1041 NSEnumerator *o_enumerator = [o_windows objectEnumerator];
1044 if( p_input != NULL )
1046 vout_thread_t *p_vout = input_GetVout( p_input );
1047 if( p_vout != NULL )
1049 if( [[o_mi title] isEqualToString: _NS("Float on Top")] )
1051 var_Get( p_vout, "video-on-top", &val );
1052 [o_mi setState: val.b_bool ? NSOnState : NSOffState];
1055 while( (o_window = [o_enumerator nextObject]))
1057 if( [[o_window className] isEqualToString: @"VLCVoutWindow"] ||
1058 [[[VLCMain sharedInstance] embeddedList]
1059 windowContainsEmbedded: o_window])
1066 vlc_object_release( (vlc_object_t *)p_vout );
1069 if( [[o_mi title] isEqualToString: _NS("Fullscreen")] )
1071 var_Get( p_playlist, "fullscreen", &val );
1072 [o_mi setState: val.b_bool];
1075 [o_main setupMenus]; /* Make sure video menu is up to date */
1078 /* Special case for telx menu */
1079 if( [[o_mi title] isEqualToString: _NS("Normal Size")] )
1081 NSMenuItem *item = [[o_mi menu] itemWithTitle:_NS("Teletext")];
1082 bool b_telx = p_input && var_GetInteger( p_input, "teletext-es" ) >= 0;
1084 [[item submenu] setAutoenablesItems:NO];
1085 for( int k=0; k < [[item submenu] numberOfItems]; k++ )
1087 [[[item submenu] itemAtIndex:k] setEnabled: b_telx];
1091 if( p_input ) vlc_object_release( p_input );
1098 /*****************************************************************************
1099 * VLCAutoGeneratedMenuContent implementation
1100 *****************************************************************************
1101 * Object connected to a playlistitem which remembers the data belonging to
1102 * the variable of the autogenerated menu
1103 *****************************************************************************/
1104 @implementation VLCAutoGeneratedMenuContent
1106 -(id) initWithVariableName:(const char *)name ofObject:(vlc_object_t *)object
1107 andValue:(vlc_value_t)val ofType:(int)type
1109 self = [super init];
1113 _vlc_object = vlc_object_hold( object );
1114 psz_name = strdup( name );
1117 if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING )
1118 value.psz_string = strdup( val.psz_string );
1126 vlc_object_release( _vlc_object );
1127 if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING )
1128 free( value.psz_string );
1133 - (const char *)name
1138 - (vlc_value_t)value
1143 - (vlc_object_t *)vlcObject
1145 return vlc_object_hold( _vlc_object );
1157 /*****************************************************************************
1158 * VLCTimeField implementation
1159 *****************************************************************************
1160 * we need this to catch our click-event in the controller window
1161 *****************************************************************************/
1163 @implementation VLCTimeField
1164 - (void)mouseDown: (NSEvent *)ourEvent
1166 if( [ourEvent clickCount] > 1 )
1167 [[[VLCMain sharedInstance] controls] goToSpecificTime: nil];
1169 [[VLCMain sharedInstance] timeFieldWasClicked: self];