1 /*****************************************************************************
2 * controls.m: MacOS X interface module
3 *****************************************************************************
4 * Copyright (C) 2002-2007 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 Kühne <fkuehne at videolan dot org>
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
26 *****************************************************************************/
28 /*****************************************************************************
30 *****************************************************************************/
31 #include <stdlib.h> /* malloc(), free() */
32 #include <sys/param.h> /* for MAXPATHLEN */
43 /*****************************************************************************
44 * VLCControls implementation
45 *****************************************************************************/
46 @implementation VLCControls
51 o_fs_panel = [[VLCFSPanel alloc] init];
57 [o_specificTime_mi setTitle: _NS("Jump To Time")];
58 [o_specificTime_cancel_btn setTitle: _NS("Cancel")];
59 [o_specificTime_ok_btn setTitle: _NS("OK")];
60 [o_specificTime_sec_lbl setStringValue: _NS("sec.")];
61 [o_specificTime_goTo_lbl setStringValue: _NS("Jump to time")];
63 o_repeat_off = [NSImage imageNamed:@"repeat_embedded"];
65 [self controlTintChanged];
67 [[NSNotificationCenter defaultCenter] addObserver: self
68 selector: @selector( controlTintChanged )
69 name: NSControlTintDidChangeNotification
73 - (void)controlTintChanged
76 if( [o_btn_repeat image] == o_repeat_single )
78 else if( [o_btn_repeat image] == o_repeat_all )
81 if( [NSColor currentControlTint] == NSGraphiteControlTint )
83 o_repeat_single = [NSImage imageNamed:@"repeat_single_embedded_graphite"];
84 o_repeat_all = [NSImage imageNamed:@"repeat_embedded_graphite"];
86 [o_btn_shuffle setAlternateImage: [NSImage imageNamed: @"shuffle_embedded_graphite"]];
87 [o_btn_addNode setAlternateImage: [NSImage imageNamed: @"add_embedded_graphite"]];
91 o_repeat_single = [NSImage imageNamed:@"repeat_single_embedded_blue"];
92 o_repeat_all = [NSImage imageNamed:@"repeat_embedded_blue"];
94 [o_btn_shuffle setAlternateImage: [NSImage imageNamed: @"shuffle_embedded_blue"]];
95 [o_btn_addNode setAlternateImage: [NSImage imageNamed: @"add_embedded_blue"]];
98 /* update the repeat button, but keep its state */
101 else if( i_repeat == 2 )
109 [[NSNotificationCenter defaultCenter] removeObserver: self];
111 [o_repeat_single release];
112 [o_repeat_all release];
113 [o_repeat_off release];
118 - (IBAction)play:(id)sender
120 intf_thread_t * p_intf = VLCIntf;
121 playlist_t * p_playlist = pl_Yield( p_intf );
123 vlc_object_lock( p_playlist );
124 if( playlist_IsEmpty( p_playlist ) )
126 vlc_object_unlock( p_playlist );
127 vlc_object_release( p_playlist );
128 [o_main intfOpenFileGeneric: (id)sender];
132 vlc_object_unlock( p_playlist );
133 vlc_object_release( p_playlist );
136 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_PLAY_PAUSE );
139 /* Small helper method */
144 id o_vout_view = nil;
145 id o_embedded_vout_list = [[VLCMain sharedInstance] getEmbeddedList];
146 NSEnumerator *o_enumerator = [[NSApp orderedWindows] objectEnumerator];
147 while( !o_vout_view && ( o_window = [o_enumerator nextObject] ) )
149 /* We have an embedded vout */
150 if( [o_embedded_vout_list windowContainsEmbedded: o_window] )
152 o_vout_view = [o_embedded_vout_list getViewForWindow: o_window];
154 /* We have a detached vout */
155 else if( [[o_window className] isEqualToString: @"VLCVoutWindow"] )
157 msg_Dbg( VLCIntf, "detached vout controls.m call getVoutView" );
158 o_vout_view = [o_window getVoutView];
164 - (IBAction)stop:(id)sender
166 intf_thread_t * p_intf = VLCIntf;
167 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_STOP );
168 /* Close the window directly, because we do know that there
169 * won't be anymore video. It's currently waiting a bit. */
170 [[[self getVoutView] window] orderOut:self];
173 - (IBAction)faster:(id)sender
175 intf_thread_t * p_intf = VLCIntf;
176 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_FASTER );
179 - (IBAction)slower:(id)sender
181 intf_thread_t * p_intf = VLCIntf;
182 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_SLOWER );
185 - (IBAction)prev:(id)sender
187 intf_thread_t * p_intf = VLCIntf;
188 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_PREV );
191 - (IBAction)next:(id)sender
193 intf_thread_t * p_intf = VLCIntf;
194 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_NEXT );
197 - (IBAction)random:(id)sender
200 intf_thread_t * p_intf = VLCIntf;
201 playlist_t * p_playlist = pl_Yield( p_intf );
203 var_Get( p_playlist, "random", &val );
204 val.b_bool = !val.b_bool;
205 var_Set( p_playlist, "random", val );
208 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Random On" ) );
209 config_PutInt( p_playlist, "random", 1 );
213 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Random Off" ) );
214 config_PutInt( p_playlist, "random", 0 );
217 p_intf->p_sys->b_playmode_update = true;
218 p_intf->p_sys->b_intf_update = true;
219 vlc_object_release( p_playlist );
222 /* three little ugly helpers */
225 [o_btn_repeat setImage: o_repeat_single];
226 [o_btn_repeat setAlternateImage: o_repeat_all];
230 [o_btn_repeat setImage: o_repeat_all];
231 [o_btn_repeat setAlternateImage: o_repeat_off];
235 [o_btn_repeat setImage: o_repeat_off];
236 [o_btn_repeat setAlternateImage: o_repeat_single];
241 playlist_t *p_playlist = pl_Yield( VLCIntf );
242 var_Get( p_playlist, "random", &val );
243 [o_btn_shuffle setState: val.b_bool];
244 vlc_object_release( p_playlist );
247 - (IBAction)repeatButtonAction:(id)sender
249 vlc_value_t looping,repeating;
250 intf_thread_t * p_intf = VLCIntf;
251 playlist_t * p_playlist = pl_Yield( p_intf );
253 var_Get( p_playlist, "repeat", &repeating );
254 var_Get( p_playlist, "loop", &looping );
256 if( !repeating.b_bool && !looping.b_bool )
258 /* was: no repeating at all, switching to Repeat One */
260 /* set our button's look */
263 /* prepare core communication */
264 repeating.b_bool = true;
265 looping.b_bool = false;
266 config_PutInt( p_playlist, "repeat", 1 );
267 config_PutInt( p_playlist, "loop", 0 );
269 /* show the change */
270 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat One" ) );
272 else if( repeating.b_bool && !looping.b_bool )
274 /* was: Repeat One, switching to Repeat All */
276 /* set our button's look */
279 /* prepare core communication */
280 repeating.b_bool = false;
281 looping.b_bool = true;
282 config_PutInt( p_playlist, "repeat", 0 );
283 config_PutInt( p_playlist, "loop", 1 );
285 /* show the change */
286 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat All" ) );
290 /* was: Repeat All or bug in VLC, switching to Repeat Off */
292 /* set our button's look */
295 /* prepare core communication */
296 repeating.b_bool = false;
297 looping.b_bool = false;
298 config_PutInt( p_playlist, "repeat", 0 );
299 config_PutInt( p_playlist, "loop", 0 );
301 /* show the change */
302 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat Off" ) );
305 /* communicate with core and the main intf loop */
306 var_Set( p_playlist, "repeat", repeating );
307 var_Set( p_playlist, "loop", looping );
308 p_intf->p_sys->b_playmode_update = true;
309 p_intf->p_sys->b_intf_update = true;
311 vlc_object_release( p_playlist );
315 - (IBAction)repeat:(id)sender
318 intf_thread_t * p_intf = VLCIntf;
319 playlist_t * p_playlist = pl_Yield( p_intf );
321 var_Get( p_playlist, "repeat", &val );
324 var_Set( p_playlist, "loop", val );
326 val.b_bool = !val.b_bool;
327 var_Set( p_playlist, "repeat", val );
330 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat One" ) );
331 config_PutInt( p_playlist, "repeat", 1 );
335 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat Off" ) );
336 config_PutInt( p_playlist, "repeat", 0 );
339 p_intf->p_sys->b_playmode_update = true;
340 p_intf->p_sys->b_intf_update = true;
341 vlc_object_release( p_playlist );
344 - (IBAction)loop:(id)sender
347 intf_thread_t * p_intf = VLCIntf;
348 playlist_t * p_playlist = pl_Yield( p_intf );
350 var_Get( p_playlist, "loop", &val );
353 var_Set( p_playlist, "repeat", val );
355 val.b_bool = !val.b_bool;
356 var_Set( p_playlist, "loop", val );
359 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat All" ) );
360 config_PutInt( p_playlist, "loop", 1 );
364 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat Off" ) );
365 config_PutInt( p_playlist, "loop", 0 );
368 p_intf->p_sys->b_playmode_update = true;
369 p_intf->p_sys->b_intf_update = true;
370 vlc_object_release( p_playlist );
373 - (IBAction)forward:(id)sender
375 intf_thread_t * p_intf = VLCIntf;
376 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_JUMP_FORWARD_SHORT );
379 - (IBAction)backward:(id)sender
382 intf_thread_t * p_intf = VLCIntf;
383 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_JUMP_BACKWARD_SHORT );
387 - (IBAction)volumeUp:(id)sender
389 intf_thread_t * p_intf = VLCIntf;
390 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_VOL_UP );
391 /* Manage volume status */
392 [o_main manageVolumeSlider];
395 - (IBAction)volumeDown:(id)sender
397 intf_thread_t * p_intf = VLCIntf;
398 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_VOL_DOWN );
399 /* Manage volume status */
400 [o_main manageVolumeSlider];
403 - (IBAction)mute:(id)sender
405 intf_thread_t * p_intf = VLCIntf;
406 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_VOL_MUTE );
407 /* Manage volume status */
408 [o_main manageVolumeSlider];
411 - (IBAction)volumeSliderUpdated:(id)sender
413 intf_thread_t * p_intf = VLCIntf;
414 audio_volume_t i_volume = (audio_volume_t)[sender intValue];
415 int i_volume_step = 0;
416 i_volume_step = config_GetInt( p_intf->p_libvlc, "volume-step" );
417 aout_VolumeSet( p_intf, i_volume * i_volume_step );
418 /* Manage volume status */
419 [o_main manageVolumeSlider];
422 - (IBAction)showPosition: (id)sender
424 vout_thread_t *p_vout = vlc_object_find( VLCIntf, VLC_OBJECT_VOUT,
428 intf_thread_t * p_intf = VLCIntf;
429 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_POSITION );
430 vlc_object_release( (vlc_object_t *)p_vout );
434 - (IBAction)toogleFullscreen:(id)sender {
435 NSMenuItem *o_mi = [[NSMenuItem alloc] initWithTitle: _NS("Fullscreen") action: nil keyEquivalent:@""];
436 [self windowAction: [o_mi autorelease]];
439 - (BOOL) isFullscreen {
440 id o_vout_view = [self getVoutView];
443 return [o_vout_view isFullscreen];
448 - (IBAction)windowAction:(id)sender
450 NSString *o_title = [sender title];
452 vout_thread_t *p_vout = vlc_object_find( VLCIntf, VLC_OBJECT_VOUT,
456 id o_vout_view = [self getVoutView];
459 if( [o_title isEqualToString: _NS("Half Size") ] )
460 [o_vout_view scaleWindowWithFactor: 0.5 animate: YES];
461 else if( [o_title isEqualToString: _NS("Normal Size") ] )
462 [o_vout_view scaleWindowWithFactor: 1.0 animate: YES];
463 else if( [o_title isEqualToString: _NS("Double Size") ] )
464 [o_vout_view scaleWindowWithFactor: 2.0 animate: YES];
465 else if( [o_title isEqualToString: _NS("Float on Top") ] )
466 [o_vout_view toggleFloatOnTop];
467 else if( [o_title isEqualToString: _NS("Fit to Screen") ] )
469 id o_window = [o_vout_view getWindow];
470 if( ![o_window isZoomed] )
471 [o_window performZoom:self];
473 else if( [o_title isEqualToString: _NS("Snapshot") ] )
475 [o_vout_view snapshot];
479 /* Fullscreen state for next time will be saved here too */
480 [o_vout_view toggleFullscreen];
483 vlc_object_release( (vlc_object_t *)p_vout );
487 playlist_t * p_playlist = pl_Yield( VLCIntf );
489 if( [o_title isEqualToString: _NS("Fullscreen")] ||
490 [sender isKindOfClass:[NSButton class]] )
493 var_Get( p_playlist, "fullscreen", &val );
494 var_Set( p_playlist, "fullscreen", (vlc_value_t)!val.b_bool );
497 pl_Release( VLCIntf );
502 - (void)scrollWheel:(NSEvent *)theEvent
504 intf_thread_t * p_intf = VLCIntf;
505 float f_yabsvalue = [theEvent deltaY] > 0.0f ? [theEvent deltaY] : -[theEvent deltaY];
506 float f_xabsvalue = [theEvent deltaX] > 0.0f ? [theEvent deltaX] : -[theEvent deltaX];
507 int i, i_yvlckey, i_xvlckey;
509 if ([theEvent deltaY] < 0.0f)
510 i_yvlckey = KEY_MOUSEWHEELDOWN;
512 i_yvlckey = KEY_MOUSEWHEELUP;
514 if ([theEvent deltaX] < 0.0f)
515 i_xvlckey = KEY_MOUSEWHEELRIGHT;
517 i_xvlckey = KEY_MOUSEWHEELLEFT;
519 /* Send multiple key event, depending on the intensity of the event */
520 for (i = 0; i < (int)(f_yabsvalue/4.+1.) && f_yabsvalue > 0.05 ; i++)
521 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_yvlckey );
523 /* Prioritize Y event (sound volume) over X event */
524 if (f_yabsvalue < 0.05)
526 for (i = 0; i < (int)(f_xabsvalue/6.+1.) && f_xabsvalue > 0.05; i++)
527 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_xvlckey );
531 - (BOOL)keyEvent:(NSEvent *)o_event
533 BOOL eventHandled = NO;
534 unichar key = [[o_event charactersIgnoringModifiers] characterAtIndex: 0];
538 vout_thread_t *p_vout = vlc_object_find( VLCIntf, VLC_OBJECT_VOUT,
543 if( key == (unichar) 0x1b )
545 id o_vout_view = [self getVoutView];
546 if( o_vout_view && [o_vout_view isFullscreen] )
548 [o_vout_view toggleFullscreen];
552 else if( key == ' ' )
557 vlc_object_release( (vlc_object_t *)p_vout );
563 - (void)setupVarMenuItem:(NSMenuItem *)o_mi
564 target:(vlc_object_t *)p_object
565 var:(const char *)psz_variable
566 selector:(SEL)pf_callback
568 vlc_value_t val, text;
569 int i_type = var_Type( p_object, psz_variable );
571 switch( i_type & VLC_VAR_TYPE )
575 case VLC_VAR_VARIABLE:
577 case VLC_VAR_INTEGER:
580 /* Variable doesn't exist or isn't handled */
584 /* Make sure we want to display the variable */
585 if( i_type & VLC_VAR_HASCHOICE )
587 var_Change( p_object, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL );
588 if( val.i_int == 0 ) return;
589 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
593 /* Get the descriptive name of the variable */
594 var_Change( p_object, psz_variable, VLC_VAR_GETTEXT, &text, NULL );
595 [o_mi setTitle: [[VLCMain sharedInstance] localizedString: text.psz_string ?
596 text.psz_string : strdup( psz_variable ) ]];
598 var_Get( p_object, psz_variable, &val );
599 if( i_type & VLC_VAR_HASCHOICE )
601 NSMenu *o_menu = [o_mi submenu];
603 [self setupVarMenu: o_menu forMenuItem: o_mi target:p_object
604 var:psz_variable selector:pf_callback];
606 free( text.psz_string );
611 switch( i_type & VLC_VAR_TYPE )
614 o_data = [[VLCMenuExt alloc] initWithVar: psz_variable Object: p_object->i_object_id
615 Value: val ofType: i_type];
616 [o_mi setRepresentedObject: [NSValue valueWithPointer:[o_data retain]]];
620 o_data = [[VLCMenuExt alloc] initWithVar: psz_variable Object: p_object->i_object_id
621 Value: val ofType: i_type];
622 [o_mi setRepresentedObject: [NSValue valueWithPointer:[o_data retain]]];
623 if( !( i_type & VLC_VAR_ISCOMMAND ) )
624 [o_mi setState: val.b_bool ? TRUE : FALSE ];
628 free( text.psz_string );
632 if( ( i_type & VLC_VAR_TYPE ) == VLC_VAR_STRING ) free( val.psz_string );
633 free( text.psz_string );
637 - (void)setupVarMenu:(NSMenu *)o_menu
638 forMenuItem: (NSMenuItem *)o_parent
639 target:(vlc_object_t *)p_object
640 var:(const char *)psz_variable
641 selector:(SEL)pf_callback
643 vlc_value_t val, val_list, text_list;
644 int i_type, i, i_nb_items;
646 /* remove previous items */
647 i_nb_items = [o_menu numberOfItems];
648 for( i = 0; i < i_nb_items; i++ )
650 [o_menu removeItemAtIndex: 0];
653 /* Check the type of the object variable */
654 i_type = var_Type( p_object, psz_variable );
656 /* Make sure we want to display the variable */
657 if( i_type & VLC_VAR_HASCHOICE )
659 var_Change( p_object, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL );
660 if( val.i_int == 0 ) return;
661 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
669 switch( i_type & VLC_VAR_TYPE )
673 case VLC_VAR_VARIABLE:
675 case VLC_VAR_INTEGER:
678 /* Variable doesn't exist or isn't handled */
682 if( var_Get( p_object, psz_variable, &val ) < 0 )
687 if( var_Change( p_object, psz_variable, VLC_VAR_GETLIST,
688 &val_list, &text_list ) < 0 )
690 if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
694 /* make (un)sensitive */
695 [o_parent setEnabled: ( val_list.p_list->i_count > 1 )];
697 for( i = 0; i < val_list.p_list->i_count; i++ )
699 vlc_value_t another_val;
701 NSString *o_title = @"";
704 switch( i_type & VLC_VAR_TYPE )
707 another_val.psz_string =
708 strdup(val_list.p_list->p_values[i].psz_string);
710 o_title = [[VLCMain sharedInstance] localizedString: text_list.p_list->p_values[i].psz_string ?
711 text_list.p_list->p_values[i].psz_string : val_list.p_list->p_values[i].psz_string ];
713 o_lmi = [o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""];
714 o_data = [[VLCMenuExt alloc] initWithVar: strdup(psz_variable) Object: p_object->i_object_id
715 Value: another_val ofType: i_type];
716 [o_lmi setRepresentedObject: [NSValue valueWithPointer:[o_data retain]]];
717 [o_lmi setTarget: self];
719 if( !strcmp( val.psz_string, val_list.p_list->p_values[i].psz_string ) && !( i_type & VLC_VAR_ISCOMMAND ) )
720 [o_lmi setState: TRUE ];
724 case VLC_VAR_INTEGER:
726 o_title = text_list.p_list->p_values[i].psz_string ?
727 [[VLCMain sharedInstance] localizedString: strdup( text_list.p_list->p_values[i].psz_string )] :
728 [NSString stringWithFormat: @"%d",
729 val_list.p_list->p_values[i].i_int];
731 o_lmi = [[o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""] retain ];
732 o_data = [[VLCMenuExt alloc] initWithVar: strdup(psz_variable) Object: p_object->i_object_id
733 Value: val_list.p_list->p_values[i] ofType: i_type];
734 [o_lmi setRepresentedObject: [NSValue valueWithPointer:[ o_data retain]]];
735 [o_lmi setTarget: self];
737 if( val_list.p_list->p_values[i].i_int == val.i_int && !( i_type & VLC_VAR_ISCOMMAND ) )
738 [o_lmi setState: TRUE ];
746 /* clean up everything */
747 if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
748 var_Change( p_object, psz_variable, VLC_VAR_FREELIST, &val_list, &text_list );
751 - (IBAction)toggleVar:(id)sender
753 NSMenuItem *o_mi = (NSMenuItem *)sender;
754 VLCMenuExt *o_data = [[o_mi representedObject] pointerValue];
755 [NSThread detachNewThreadSelector: @selector(toggleVarThread:)
756 toTarget: self withObject: o_data];
761 - (int)toggleVarThread: (id)_o_data
763 vlc_object_t *p_object;
764 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
765 VLCMenuExt *o_data = (VLCMenuExt *)_o_data;
767 vlc_thread_set_priority( VLCIntf , VLC_THREAD_PRIORITY_LOW );
769 p_object = (vlc_object_t *)vlc_object_get( [o_data objectID] );
771 if( p_object != NULL )
773 var_Set( p_object, strdup([o_data name]), [o_data value] );
774 vlc_object_release( p_object );
782 - (IBAction)goToSpecificTime:(id)sender
784 if( sender == o_specificTime_cancel_btn )
786 [NSApp endSheet: o_specificTime_win];
787 [o_specificTime_win close];
789 else if( sender == o_specificTime_ok_btn )
791 input_thread_t * p_input = pl_CurrentInput( VLCIntf );
794 unsigned int timeInSec = 0;
795 NSString * fieldContent = [o_specificTime_enter_fld stringValue];
796 if( [[fieldContent componentsSeparatedByString: @":"] count] > 1 &&
797 [[fieldContent componentsSeparatedByString: @":"] count] <= 3 )
799 NSArray * ourTempArray = \
800 [fieldContent componentsSeparatedByString: @":"];
802 if( [[fieldContent componentsSeparatedByString: @":"] count] == 3 )
804 timeInSec += ([[ourTempArray objectAtIndex: 0] intValue] * 3600); //h
805 timeInSec += ([[ourTempArray objectAtIndex: 1] intValue] * 60); //m
806 timeInSec += [[ourTempArray objectAtIndex: 2] intValue]; //s
810 timeInSec += ([[ourTempArray objectAtIndex: 0] intValue] * 60); //m
811 timeInSec += [[ourTempArray objectAtIndex: 1] intValue]; //s
815 timeInSec = [fieldContent intValue];
817 input_Control( p_input, INPUT_SET_TIME, (int64_t)(timeInSec * 1000000));
818 vlc_object_release( p_input );
821 [NSApp endSheet: o_specificTime_win];
822 [o_specificTime_win close];
826 input_thread_t * p_input = pl_CurrentInput( VLCIntf );
829 /* we can obviously only do that if an input is available */
830 vlc_value_t pos, length;
831 var_Get( p_input, "time", &pos );
832 [o_specificTime_enter_fld setIntValue: (pos.i_time / 1000000)];
833 var_Get( p_input, "length", &length );
834 [o_specificTime_stepper setMaxValue: (length.i_time / 1000000)];
836 [NSApp beginSheet: o_specificTime_win modalForWindow: \
837 [NSApp mainWindow] modalDelegate: self didEndSelector: nil \
839 [o_specificTime_win makeKeyWindow];
840 vlc_object_release( p_input );
851 msg_Err( VLCIntf, "FSPanel is nil" );
858 @implementation VLCControls (NSMenuValidation)
860 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
862 BOOL bEnabled = TRUE;
864 intf_thread_t * p_intf = VLCIntf;
865 playlist_t * p_playlist = pl_Yield( p_intf );
866 input_thread_t * p_input = playlist_CurrentInput( p_playlist );
868 if( [[o_mi title] isEqualToString: _NS("Faster")] ||
869 [[o_mi title] isEqualToString: _NS("Slower")] )
871 if( p_input != NULL )
873 bEnabled = p_input->b_can_pace_control;
880 else if( [[o_mi title] isEqualToString: _NS("Stop")] )
882 if( p_input == NULL )
886 [o_main setupMenus]; /* Make sure input menu is up to date */
888 else if( [[o_mi title] isEqualToString: _NS("Previous")] ||
889 [[o_mi title] isEqualToString: _NS("Next")] )
891 /** \todo fix i_size use */
893 bEnabled = p_playlist->items.i_size > 1;
896 else if( [[o_mi title] isEqualToString: _NS("Random")] )
899 var_Get( p_playlist, "random", &val );
900 i_state = val.b_bool ? NSOnState : NSOffState;
901 [o_mi setState: i_state];
903 else if( [[o_mi title] isEqualToString: _NS("Repeat One")] )
906 var_Get( p_playlist, "repeat", &val );
907 i_state = val.b_bool ? NSOnState : NSOffState;
908 [o_mi setState: i_state];
910 else if( [[o_mi title] isEqualToString: _NS("Repeat All")] )
913 var_Get( p_playlist, "loop", &val );
914 i_state = val.b_bool ? NSOnState : NSOffState;
915 [o_mi setState: i_state];
917 else if( [[o_mi title] isEqualToString: _NS("Step Forward")] ||
918 [[o_mi title] isEqualToString: _NS("Step Backward")] ||
919 [[o_mi title] isEqualToString: _NS("Jump To Time")])
921 if( p_input != NULL )
923 var_Get( p_input, "seekable", &val);
924 bEnabled = val.b_bool;
926 else bEnabled = FALSE;
928 else if( [[o_mi title] isEqualToString: _NS("Mute")] )
930 [o_mi setState: p_intf->p_sys->b_mute ? NSOnState : NSOffState];
931 [o_main setupMenus]; /* Make sure audio menu is up to date */
933 else if( [[o_mi title] isEqualToString: _NS("Half Size")] ||
934 [[o_mi title] isEqualToString: _NS("Normal Size")] ||
935 [[o_mi title] isEqualToString: _NS("Double Size")] ||
936 [[o_mi title] isEqualToString: _NS("Fit to Screen")] ||
937 [[o_mi title] isEqualToString: _NS("Snapshot")] ||
938 [[o_mi title] isEqualToString: _NS("Fullscreen")] ||
939 [[o_mi title] isEqualToString: _NS("Float on Top")] )
942 NSArray *o_windows = [NSApp orderedWindows];
943 NSEnumerator *o_enumerator = [o_windows objectEnumerator];
946 vout_thread_t *p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
950 if( [[o_mi title] isEqualToString: _NS("Float on Top")] )
952 var_Get( p_vout, "video-on-top", &val );
953 [o_mi setState: val.b_bool ? NSOnState : NSOffState];
956 while( (o_window = [o_enumerator nextObject]))
958 if( [[o_window className] isEqualToString: @"VLCVoutWindow"] ||
959 [[[VLCMain sharedInstance] getEmbeddedList]
960 windowContainsEmbedded: o_window])
967 vlc_object_release( (vlc_object_t *)p_vout );
969 if( [[o_mi title] isEqualToString: _NS("Fullscreen")] )
971 var_Get( p_playlist, "fullscreen", &val );
972 [o_mi setState: val.b_bool];
975 [o_main setupMenus]; /* Make sure video menu is up to date */
978 if( p_input ) vlc_object_release( p_input );
979 vlc_object_release( p_playlist );
986 /*****************************************************************************
987 * VLCMenuExt implementation
988 *****************************************************************************
989 * Object connected to a playlistitem which remembers the data belonging to
990 * the variable of the autogenerated menu
991 *****************************************************************************/
992 @implementation VLCMenuExt
994 - (id)initWithVar: (const char *)_psz_name Object: (int)i_id
995 Value: (vlc_value_t)val ofType: (int)_i_type
1001 psz_name = strdup( _psz_name );
1026 - (vlc_value_t)value
1039 /*****************************************************************************
1040 * VLCTimeField implementation
1041 *****************************************************************************
1042 * we need this to catch our click-event in the controller window
1043 *****************************************************************************/
1045 @implementation VLCTimeField
1046 - (void)mouseDown: (NSEvent *)ourEvent
1048 if( [ourEvent clickCount] > 1 )
1049 [[[VLCMain sharedInstance] getControls] goToSpecificTime: nil];