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
121 intf_thread_t * p_intf = VLCIntf;
122 playlist_t * p_playlist = pl_Yield( p_intf );
124 vlc_object_lock( p_playlist );
125 if( playlist_IsEmpty( p_playlist ) )
127 vlc_object_unlock( p_playlist );
128 vlc_object_release( p_playlist );
129 [o_main intfOpenFileGeneric: (id)sender];
133 vlc_object_unlock( p_playlist );
134 vlc_object_release( p_playlist );
137 val.i_int = config_GetInt( p_intf, "key-play-pause" );
138 var_Set( p_intf->p_libvlc, "key-pressed", val );
141 /* Small helper method */
146 id o_vout_view = nil;
147 id o_embedded_vout_list = [[VLCMain sharedInstance] getEmbeddedList];
148 NSEnumerator *o_enumerator = [[NSApp orderedWindows] objectEnumerator];
149 while( !o_vout_view && ( o_window = [o_enumerator nextObject] ) )
151 /* We have an embedded vout */
152 if( [o_embedded_vout_list windowContainsEmbedded: o_window] )
154 o_vout_view = [o_embedded_vout_list getViewForWindow: o_window];
156 /* We have a detached vout */
157 else if( [[o_window className] isEqualToString: @"VLCVoutWindow"] )
159 msg_Dbg( VLCIntf, "detached vout controls.m call getVoutView" );
160 o_vout_view = [o_window getVoutView];
166 - (IBAction)stop:(id)sender
169 intf_thread_t * p_intf = VLCIntf;
170 val.i_int = config_GetInt( p_intf, "key-stop" );
171 var_Set( p_intf->p_libvlc, "key-pressed", val );
172 /* Close the window directly, because we do know that there
173 * won't be anymore video. It's currently waiting a bit. */
174 [[[self getVoutView] window] orderOut:self];
177 - (IBAction)faster:(id)sender
180 intf_thread_t * p_intf = VLCIntf;
181 val.i_int = config_GetInt( p_intf, "key-faster" );
182 var_Set( p_intf->p_libvlc, "key-pressed", val );
185 - (IBAction)slower:(id)sender
188 intf_thread_t * p_intf = VLCIntf;
189 val.i_int = config_GetInt( p_intf, "key-slower" );
190 var_Set( p_intf->p_libvlc, "key-pressed", val );
193 - (IBAction)prev:(id)sender
196 intf_thread_t * p_intf = VLCIntf;
197 val.i_int = config_GetInt( p_intf, "key-prev" );
198 var_Set( p_intf->p_libvlc, "key-pressed", val );
201 - (IBAction)next:(id)sender
204 intf_thread_t * p_intf = VLCIntf;
205 val.i_int = config_GetInt( p_intf, "key-next" );
206 var_Set( p_intf->p_libvlc, "key-pressed", val );
209 - (IBAction)random:(id)sender
212 intf_thread_t * p_intf = VLCIntf;
213 playlist_t * p_playlist = pl_Yield( p_intf );
215 var_Get( p_playlist, "random", &val );
216 val.b_bool = !val.b_bool;
217 var_Set( p_playlist, "random", val );
220 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Random On" ) );
221 config_PutInt( p_playlist, "random", 1 );
225 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Random Off" ) );
226 config_PutInt( p_playlist, "random", 0 );
229 p_intf->p_sys->b_playmode_update = true;
230 p_intf->p_sys->b_intf_update = true;
231 vlc_object_release( p_playlist );
234 /* three little ugly helpers */
237 [o_btn_repeat setImage: o_repeat_single];
238 [o_btn_repeat setAlternateImage: o_repeat_all];
242 [o_btn_repeat setImage: o_repeat_all];
243 [o_btn_repeat setAlternateImage: o_repeat_off];
247 [o_btn_repeat setImage: o_repeat_off];
248 [o_btn_repeat setAlternateImage: o_repeat_single];
253 playlist_t *p_playlist = pl_Yield( VLCIntf );
254 var_Get( p_playlist, "random", &val );
255 [o_btn_shuffle setState: val.b_bool];
256 vlc_object_release( p_playlist );
259 - (IBAction)repeatButtonAction:(id)sender
261 vlc_value_t looping,repeating;
262 intf_thread_t * p_intf = VLCIntf;
263 playlist_t * p_playlist = pl_Yield( p_intf );
265 var_Get( p_playlist, "repeat", &repeating );
266 var_Get( p_playlist, "loop", &looping );
268 if( !repeating.b_bool && !looping.b_bool )
270 /* was: no repeating at all, switching to Repeat One */
272 /* set our button's look */
275 /* prepare core communication */
276 repeating.b_bool = true;
277 looping.b_bool = false;
278 config_PutInt( p_playlist, "repeat", 1 );
279 config_PutInt( p_playlist, "loop", 0 );
281 /* show the change */
282 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat One" ) );
284 else if( repeating.b_bool && !looping.b_bool )
286 /* was: Repeat One, switching to Repeat All */
288 /* set our button's look */
291 /* prepare core communication */
292 repeating.b_bool = false;
293 looping.b_bool = true;
294 config_PutInt( p_playlist, "repeat", 0 );
295 config_PutInt( p_playlist, "loop", 1 );
297 /* show the change */
298 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat All" ) );
302 /* was: Repeat All or bug in VLC, switching to Repeat Off */
304 /* set our button's look */
307 /* prepare core communication */
308 repeating.b_bool = false;
309 looping.b_bool = false;
310 config_PutInt( p_playlist, "repeat", 0 );
311 config_PutInt( p_playlist, "loop", 0 );
313 /* show the change */
314 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat Off" ) );
317 /* communicate with core and the main intf loop */
318 var_Set( p_playlist, "repeat", repeating );
319 var_Set( p_playlist, "loop", looping );
320 p_intf->p_sys->b_playmode_update = true;
321 p_intf->p_sys->b_intf_update = true;
323 vlc_object_release( p_playlist );
327 - (IBAction)repeat:(id)sender
330 intf_thread_t * p_intf = VLCIntf;
331 playlist_t * p_playlist = pl_Yield( p_intf );
333 var_Get( p_playlist, "repeat", &val );
336 var_Set( p_playlist, "loop", val );
338 val.b_bool = !val.b_bool;
339 var_Set( p_playlist, "repeat", val );
342 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat One" ) );
343 config_PutInt( p_playlist, "repeat", 1 );
347 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat Off" ) );
348 config_PutInt( p_playlist, "repeat", 0 );
351 p_intf->p_sys->b_playmode_update = true;
352 p_intf->p_sys->b_intf_update = true;
353 vlc_object_release( p_playlist );
356 - (IBAction)loop:(id)sender
359 intf_thread_t * p_intf = VLCIntf;
360 playlist_t * p_playlist = pl_Yield( p_intf );
362 var_Get( p_playlist, "loop", &val );
365 var_Set( p_playlist, "repeat", val );
367 val.b_bool = !val.b_bool;
368 var_Set( p_playlist, "loop", val );
371 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat All" ) );
372 config_PutInt( p_playlist, "loop", 1 );
376 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat Off" ) );
377 config_PutInt( p_playlist, "loop", 0 );
380 p_intf->p_sys->b_playmode_update = true;
381 p_intf->p_sys->b_intf_update = true;
382 vlc_object_release( p_playlist );
385 - (IBAction)forward:(id)sender
388 intf_thread_t * p_intf = VLCIntf;
389 val.i_int = config_GetInt( p_intf, "key-jump+short" );
390 var_Set( p_intf->p_libvlc, "key-pressed", val );
393 - (IBAction)backward:(id)sender
396 intf_thread_t * p_intf = VLCIntf;
397 val.i_int = config_GetInt( p_intf, "key-jump-short" );
398 var_Set( p_intf->p_libvlc, "key-pressed", val );
402 - (IBAction)volumeUp:(id)sender
405 intf_thread_t * p_intf = VLCIntf;
406 val.i_int = config_GetInt( p_intf, "key-vol-up" );
407 var_Set( p_intf->p_libvlc, "key-pressed", val );
408 /* Manage volume status */
409 [o_main manageVolumeSlider];
412 - (IBAction)volumeDown:(id)sender
415 intf_thread_t * p_intf = VLCIntf;
416 val.i_int = config_GetInt( p_intf, "key-vol-down" );
417 var_Set( p_intf->p_libvlc, "key-pressed", val );
418 /* Manage volume status */
419 [o_main manageVolumeSlider];
422 - (IBAction)mute:(id)sender
425 intf_thread_t * p_intf = VLCIntf;
426 val.i_int = config_GetInt( p_intf, "key-vol-mute" );
427 var_Set( p_intf->p_libvlc, "key-pressed", val );
428 /* Manage volume status */
429 [o_main manageVolumeSlider];
432 - (IBAction)volumeSliderUpdated:(id)sender
434 intf_thread_t * p_intf = VLCIntf;
435 audio_volume_t i_volume = (audio_volume_t)[sender intValue];
436 int i_volume_step = 0;
437 i_volume_step = config_GetInt( p_intf->p_libvlc, "volume-step" );
438 aout_VolumeSet( p_intf, i_volume * i_volume_step );
439 /* Manage volume status */
440 [o_main manageVolumeSlider];
443 - (IBAction)showPosition: (id)sender
445 vout_thread_t *p_vout = vlc_object_find( VLCIntf, VLC_OBJECT_VOUT,
450 intf_thread_t * p_intf = VLCIntf;
451 val.i_int = config_GetInt( p_intf, "key-position" );
452 var_Set( p_intf, "key-pressed", val );
453 vlc_object_release( (vlc_object_t *)p_vout );
457 - (IBAction)toogleFullscreen:(id)sender {
458 NSMenuItem *o_mi = [[NSMenuItem alloc] initWithTitle: _NS("Fullscreen") action: nil keyEquivalent:@""];
459 [self windowAction: [o_mi autorelease]];
462 - (BOOL) isFullscreen {
463 id o_vout_view = [self getVoutView];
466 return [o_vout_view isFullscreen];
471 - (IBAction)windowAction:(id)sender
473 NSString *o_title = [sender title];
475 vout_thread_t *p_vout = vlc_object_find( VLCIntf, VLC_OBJECT_VOUT,
479 id o_vout_view = [self getVoutView];
482 if( [o_title isEqualToString: _NS("Half Size") ] )
483 [o_vout_view scaleWindowWithFactor: 0.5 animate: YES];
484 else if( [o_title isEqualToString: _NS("Normal Size") ] )
485 [o_vout_view scaleWindowWithFactor: 1.0 animate: YES];
486 else if( [o_title isEqualToString: _NS("Double Size") ] )
487 [o_vout_view scaleWindowWithFactor: 2.0 animate: YES];
488 else if( [o_title isEqualToString: _NS("Float on Top") ] )
489 [o_vout_view toggleFloatOnTop];
490 else if( [o_title isEqualToString: _NS("Fit to Screen") ] )
492 id o_window = [o_vout_view getWindow];
493 if( ![o_window isZoomed] )
494 [o_window performZoom:self];
496 else if( [o_title isEqualToString: _NS("Snapshot") ] )
498 [o_vout_view snapshot];
502 playlist_t * p_playlist = pl_Yield( VLCIntf );
503 /* Fullscreen state for next time will be saved here too */
504 [o_vout_view toggleFullscreen];
507 vlc_object_release( (vlc_object_t *)p_vout );
511 playlist_t * p_playlist = pl_Yield( VLCIntf );
513 if( [o_title isEqualToString: _NS("Fullscreen")] ||
514 [sender isKindOfClass:[NSButton class]] )
517 var_Get( p_playlist, "fullscreen", &val );
518 var_Set( p_playlist, "fullscreen", (vlc_value_t)!val.b_bool );
521 pl_Release( VLCIntf );
526 - (void)scrollWheel:(NSEvent *)theEvent
528 intf_thread_t * p_intf = VLCIntf;
529 float f_yabsvalue = [theEvent deltaY] > 0.0f ? [theEvent deltaY] : -[theEvent deltaY];
530 float f_xabsvalue = [theEvent deltaX] > 0.0f ? [theEvent deltaX] : -[theEvent deltaX];
531 int i, i_yvlckey, i_xvlckey;
533 if ([theEvent deltaY] < 0.0f)
534 i_yvlckey = KEY_MOUSEWHEELDOWN;
536 i_yvlckey = KEY_MOUSEWHEELUP;
538 if ([theEvent deltaX] < 0.0f)
539 i_xvlckey = KEY_MOUSEWHEELRIGHT;
541 i_xvlckey = KEY_MOUSEWHEELLEFT;
543 /* Send multiple key event, depending on the intensity of the event */
544 for (i = 0; i < (int)(f_yabsvalue/4.+1.) && f_yabsvalue > 0.05 ; i++)
545 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_yvlckey );
547 /* Prioritize Y event (sound volume) over X event */
548 if (f_yabsvalue < 0.05)
550 for (i = 0; i < (int)(f_xabsvalue/6.+1.) && f_xabsvalue > 0.05; i++)
551 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_xvlckey );
555 - (BOOL)keyEvent:(NSEvent *)o_event
557 BOOL eventHandled = NO;
558 unichar key = [[o_event charactersIgnoringModifiers] characterAtIndex: 0];
562 vout_thread_t *p_vout = vlc_object_find( VLCIntf, VLC_OBJECT_VOUT,
567 if( key == (unichar) 0x1b )
569 id o_vout_view = [self getVoutView];
570 if( o_vout_view && [o_vout_view isFullscreen] )
572 [o_vout_view toggleFullscreen];
576 else if( key == ' ' )
581 vlc_object_release( (vlc_object_t *)p_vout );
587 - (void)setupVarMenuItem:(NSMenuItem *)o_mi
588 target:(vlc_object_t *)p_object
589 var:(const char *)psz_variable
590 selector:(SEL)pf_callback
592 vlc_value_t val, text;
593 int i_type = var_Type( p_object, psz_variable );
595 switch( i_type & VLC_VAR_TYPE )
599 case VLC_VAR_VARIABLE:
601 case VLC_VAR_INTEGER:
604 /* Variable doesn't exist or isn't handled */
608 /* Make sure we want to display the variable */
609 if( i_type & VLC_VAR_HASCHOICE )
611 var_Change( p_object, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL );
612 if( val.i_int == 0 ) return;
613 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
617 /* Get the descriptive name of the variable */
618 var_Change( p_object, psz_variable, VLC_VAR_GETTEXT, &text, NULL );
619 [o_mi setTitle: [[VLCMain sharedInstance] localizedString: text.psz_string ?
620 text.psz_string : strdup( psz_variable ) ]];
622 var_Get( p_object, psz_variable, &val );
623 if( i_type & VLC_VAR_HASCHOICE )
625 NSMenu *o_menu = [o_mi submenu];
627 [self setupVarMenu: o_menu forMenuItem: o_mi target:p_object
628 var:psz_variable selector:pf_callback];
630 free( text.psz_string );
635 switch( i_type & VLC_VAR_TYPE )
638 o_data = [[VLCMenuExt alloc] initWithVar: psz_variable Object: p_object->i_object_id
639 Value: val ofType: i_type];
640 [o_mi setRepresentedObject: [NSValue valueWithPointer:[o_data retain]]];
644 o_data = [[VLCMenuExt alloc] initWithVar: psz_variable Object: p_object->i_object_id
645 Value: val ofType: i_type];
646 [o_mi setRepresentedObject: [NSValue valueWithPointer:[o_data retain]]];
647 if( !( i_type & VLC_VAR_ISCOMMAND ) )
648 [o_mi setState: val.b_bool ? TRUE : FALSE ];
652 free( text.psz_string );
656 if( ( i_type & VLC_VAR_TYPE ) == VLC_VAR_STRING ) free( val.psz_string );
657 free( text.psz_string );
661 - (void)setupVarMenu:(NSMenu *)o_menu
662 forMenuItem: (NSMenuItem *)o_parent
663 target:(vlc_object_t *)p_object
664 var:(const char *)psz_variable
665 selector:(SEL)pf_callback
667 vlc_value_t val, val_list, text_list;
668 int i_type, i, i_nb_items;
670 /* remove previous items */
671 i_nb_items = [o_menu numberOfItems];
672 for( i = 0; i < i_nb_items; i++ )
674 [o_menu removeItemAtIndex: 0];
677 /* Check the type of the object variable */
678 i_type = var_Type( p_object, psz_variable );
680 /* Make sure we want to display the variable */
681 if( i_type & VLC_VAR_HASCHOICE )
683 var_Change( p_object, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL );
684 if( val.i_int == 0 ) return;
685 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
693 switch( i_type & VLC_VAR_TYPE )
697 case VLC_VAR_VARIABLE:
699 case VLC_VAR_INTEGER:
702 /* Variable doesn't exist or isn't handled */
706 if( var_Get( p_object, psz_variable, &val ) < 0 )
711 if( var_Change( p_object, psz_variable, VLC_VAR_GETLIST,
712 &val_list, &text_list ) < 0 )
714 if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
718 /* make (un)sensitive */
719 [o_parent setEnabled: ( val_list.p_list->i_count > 1 )];
721 for( i = 0; i < val_list.p_list->i_count; i++ )
723 vlc_value_t another_val;
725 NSString *o_title = @"";
728 switch( i_type & VLC_VAR_TYPE )
731 another_val.psz_string =
732 strdup(val_list.p_list->p_values[i].psz_string);
734 o_title = [[VLCMain sharedInstance] localizedString: text_list.p_list->p_values[i].psz_string ?
735 text_list.p_list->p_values[i].psz_string : val_list.p_list->p_values[i].psz_string ];
737 o_lmi = [o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""];
738 o_data = [[VLCMenuExt alloc] initWithVar: strdup(psz_variable) Object: p_object->i_object_id
739 Value: another_val ofType: i_type];
740 [o_lmi setRepresentedObject: [NSValue valueWithPointer:[o_data retain]]];
741 [o_lmi setTarget: self];
743 if( !strcmp( val.psz_string, val_list.p_list->p_values[i].psz_string ) && !( i_type & VLC_VAR_ISCOMMAND ) )
744 [o_lmi setState: TRUE ];
748 case VLC_VAR_INTEGER:
750 o_title = text_list.p_list->p_values[i].psz_string ?
751 [[VLCMain sharedInstance] localizedString: strdup( text_list.p_list->p_values[i].psz_string )] :
752 [NSString stringWithFormat: @"%d",
753 val_list.p_list->p_values[i].i_int];
755 o_lmi = [[o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""] retain ];
756 o_data = [[VLCMenuExt alloc] initWithVar: strdup(psz_variable) Object: p_object->i_object_id
757 Value: val_list.p_list->p_values[i] ofType: i_type];
758 [o_lmi setRepresentedObject: [NSValue valueWithPointer:[ o_data retain]]];
759 [o_lmi setTarget: self];
761 if( val_list.p_list->p_values[i].i_int == val.i_int && !( i_type & VLC_VAR_ISCOMMAND ) )
762 [o_lmi setState: TRUE ];
770 /* clean up everything */
771 if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
772 var_Change( p_object, psz_variable, VLC_VAR_FREELIST, &val_list, &text_list );
775 - (IBAction)toggleVar:(id)sender
777 NSMenuItem *o_mi = (NSMenuItem *)sender;
778 VLCMenuExt *o_data = [[o_mi representedObject] pointerValue];
779 [NSThread detachNewThreadSelector: @selector(toggleVarThread:)
780 toTarget: self withObject: o_data];
785 - (int)toggleVarThread: (id)_o_data
787 vlc_object_t *p_object;
788 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
789 VLCMenuExt *o_data = (VLCMenuExt *)_o_data;
791 vlc_thread_set_priority( VLCIntf , VLC_THREAD_PRIORITY_LOW );
793 p_object = (vlc_object_t *)vlc_object_get( [o_data objectID] );
795 if( p_object != NULL )
797 var_Set( p_object, strdup([o_data name]), [o_data value] );
798 vlc_object_release( p_object );
806 - (IBAction)goToSpecificTime:(id)sender
808 if( sender == o_specificTime_cancel_btn )
810 [NSApp endSheet: o_specificTime_win];
811 [o_specificTime_win close];
813 else if( sender == o_specificTime_ok_btn )
815 input_thread_t * p_input = (input_thread_t *)vlc_object_find( VLCIntf, \
816 VLC_OBJECT_INPUT, FIND_ANYWHERE );
819 unsigned int timeInSec = 0;
820 NSString * fieldContent = [o_specificTime_enter_fld stringValue];
821 if( [[fieldContent componentsSeparatedByString: @":"] count] > 1 &&
822 [[fieldContent componentsSeparatedByString: @":"] count] <= 3 )
824 NSArray * ourTempArray = \
825 [fieldContent componentsSeparatedByString: @":"];
827 if( [[fieldContent componentsSeparatedByString: @":"] count] == 3 )
829 timeInSec += ([[ourTempArray objectAtIndex: 0] intValue] * 3600); //h
830 timeInSec += ([[ourTempArray objectAtIndex: 1] intValue] * 60); //m
831 timeInSec += [[ourTempArray objectAtIndex: 2] intValue]; //s
835 timeInSec += ([[ourTempArray objectAtIndex: 0] intValue] * 60); //m
836 timeInSec += [[ourTempArray objectAtIndex: 1] intValue]; //s
840 timeInSec = [fieldContent intValue];
842 input_Control( p_input, INPUT_SET_TIME, (int64_t)(timeInSec * 1000000));
843 vlc_object_release( p_input );
846 [NSApp endSheet: o_specificTime_win];
847 [o_specificTime_win close];
851 input_thread_t * p_input = (input_thread_t *)vlc_object_find( VLCIntf, \
852 VLC_OBJECT_INPUT, FIND_ANYWHERE );
855 /* we can obviously only do that if an input is available */
856 vlc_value_t pos, length;
857 var_Get( p_input, "time", &pos );
858 [o_specificTime_enter_fld setIntValue: (pos.i_time / 1000000)];
859 var_Get( p_input, "length", &length );
860 [o_specificTime_stepper setMaxValue: (length.i_time / 1000000)];
862 [NSApp beginSheet: o_specificTime_win modalForWindow: \
863 [NSApp mainWindow] modalDelegate: self didEndSelector: nil \
865 [o_specificTime_win makeKeyWindow];
866 vlc_object_release( p_input );
877 msg_Err( VLCIntf, "FSPanel is nil" );
884 @implementation VLCControls (NSMenuValidation)
886 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
888 BOOL bEnabled = TRUE;
890 intf_thread_t * p_intf = VLCIntf;
891 playlist_t * p_playlist = pl_Yield( p_intf );
892 input_thread_t * p_input = playlist_CurrentInput( p_playlist );
894 if( [[o_mi title] isEqualToString: _NS("Faster")] ||
895 [[o_mi title] isEqualToString: _NS("Slower")] )
897 if( p_input != NULL )
899 bEnabled = p_input->b_can_pace_control;
906 else if( [[o_mi title] isEqualToString: _NS("Stop")] )
908 if( p_input == NULL )
912 [o_main setupMenus]; /* Make sure input menu is up to date */
914 else if( [[o_mi title] isEqualToString: _NS("Previous")] ||
915 [[o_mi title] isEqualToString: _NS("Next")] )
917 /** \todo fix i_size use */
919 bEnabled = p_playlist->items.i_size > 1;
922 else if( [[o_mi title] isEqualToString: _NS("Random")] )
925 var_Get( p_playlist, "random", &val );
926 i_state = val.b_bool ? NSOnState : NSOffState;
927 [o_mi setState: i_state];
929 else if( [[o_mi title] isEqualToString: _NS("Repeat One")] )
932 var_Get( p_playlist, "repeat", &val );
933 i_state = val.b_bool ? NSOnState : NSOffState;
934 [o_mi setState: i_state];
936 else if( [[o_mi title] isEqualToString: _NS("Repeat All")] )
939 var_Get( p_playlist, "loop", &val );
940 i_state = val.b_bool ? NSOnState : NSOffState;
941 [o_mi setState: i_state];
943 else if( [[o_mi title] isEqualToString: _NS("Step Forward")] ||
944 [[o_mi title] isEqualToString: _NS("Step Backward")] ||
945 [[o_mi title] isEqualToString: _NS("Jump To Time")])
947 if( p_input != NULL )
949 var_Get( p_input, "seekable", &val);
950 bEnabled = val.b_bool;
952 else bEnabled = FALSE;
954 else if( [[o_mi title] isEqualToString: _NS("Mute")] )
956 [o_mi setState: p_intf->p_sys->b_mute ? NSOnState : NSOffState];
957 [o_main setupMenus]; /* Make sure audio menu is up to date */
959 else if( [[o_mi title] isEqualToString: _NS("Half Size")] ||
960 [[o_mi title] isEqualToString: _NS("Normal Size")] ||
961 [[o_mi title] isEqualToString: _NS("Double Size")] ||
962 [[o_mi title] isEqualToString: _NS("Fit to Screen")] ||
963 [[o_mi title] isEqualToString: _NS("Snapshot")] ||
964 [[o_mi title] isEqualToString: _NS("Fullscreen")] ||
965 [[o_mi title] isEqualToString: _NS("Float on Top")] )
968 NSArray *o_windows = [NSApp orderedWindows];
969 NSEnumerator *o_enumerator = [o_windows objectEnumerator];
972 vout_thread_t *p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
976 if( [[o_mi title] isEqualToString: _NS("Float on Top")] )
978 var_Get( p_vout, "video-on-top", &val );
979 [o_mi setState: val.b_bool ? NSOnState : NSOffState];
982 while( (o_window = [o_enumerator nextObject]))
984 if( [[o_window className] isEqualToString: @"VLCVoutWindow"] ||
985 [[[VLCMain sharedInstance] getEmbeddedList]
986 windowContainsEmbedded: o_window])
993 vlc_object_release( (vlc_object_t *)p_vout );
995 if( [[o_mi title] isEqualToString: _NS("Fullscreen")] )
997 var_Get( p_playlist, "fullscreen", &val );
998 [o_mi setState: val.b_bool];
1001 [o_main setupMenus]; /* Make sure video menu is up to date */
1004 if( p_input ) vlc_object_release( p_input );
1005 vlc_object_release( p_playlist );
1012 /*****************************************************************************
1013 * VLCMenuExt implementation
1014 *****************************************************************************
1015 * Object connected to a playlistitem which remembers the data belonging to
1016 * the variable of the autogenerated menu
1017 *****************************************************************************/
1018 @implementation VLCMenuExt
1020 - (id)initWithVar: (const char *)_psz_name Object: (int)i_id
1021 Value: (vlc_value_t)val ofType: (int)_i_type
1023 self = [super init];
1027 psz_name = strdup( _psz_name );
1052 - (vlc_value_t)value
1065 /*****************************************************************************
1066 * VLCTimeField implementation
1067 *****************************************************************************
1068 * we need this to catch our click-event in the controller window
1069 *****************************************************************************/
1071 @implementation VLCTimeField
1072 - (void)mouseDown: (NSEvent *)ourEvent
1074 if( [ourEvent clickCount] > 1 )
1075 [[[VLCMain sharedInstance] getControls] goToSpecificTime: nil];