]> git.sesse.net Git - vlc/blob - modules/gui/macosx/controls.m
Reverses previous patch, which added 1min/5min forward / backward functions, as it...
[vlc] / modules / gui / macosx / controls.m
1 /*****************************************************************************
2  * controls.m: MacOS X interface module
3  *****************************************************************************
4  * Copyright (C) 2002-2003 VideoLAN
5  * $Id$
6  *
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  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  * 
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
24  *****************************************************************************/
25
26 /*****************************************************************************
27  * Preamble
28  *****************************************************************************/
29 #include <stdlib.h>                                      /* malloc(), free() */
30 #include <sys/param.h>                                    /* for MAXPATHLEN */
31 #include <string.h>
32
33 #include "intf.h"
34 #include "vout.h"
35 #include "open.h"
36 #include "controls.h"
37 #include <osd.h>
38
39 /*****************************************************************************
40  * VLCControls implementation 
41  *****************************************************************************/
42 @implementation VLCControls
43
44 - (IBAction)play:(id)sender
45 {
46     vlc_value_t val;
47     playlist_t * p_playlist;
48     intf_thread_t * p_intf = [NSApp getIntf];
49     input_thread_t * p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
50                                                        FIND_ANYWHERE );
51
52     val.i_int = PLAYING_S;
53     if( p_input )
54     {
55         var_Get( p_input, "state", &val );
56     }
57     if( p_input && val.i_int != PAUSE_S )
58     {
59         vout_OSDMessage( p_intf, _( "Pause" ) );
60         val.i_int = PAUSE_S;
61         var_Set( p_input, "state", val );
62     }
63     else
64     {
65         p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
66                                         FIND_ANYWHERE );
67         if( p_playlist )
68         {
69             vlc_mutex_lock( &p_playlist->object_lock );
70             if( p_playlist->i_size )
71             {
72                 vlc_mutex_unlock( &p_playlist->object_lock );
73                 vout_OSDMessage( p_intf, _( "Play" ) );
74                 playlist_Play( p_playlist );
75                 vlc_object_release( p_playlist );
76             }
77             else
78             {
79                 vlc_mutex_unlock( &p_playlist->object_lock );
80                 vlc_object_release( p_playlist );
81                 [o_open openFileGeneric: nil];
82             }
83         }
84     }
85     if( p_input ) vlc_object_release( p_input );
86 }
87
88 - (IBAction)stop:(id)sender
89 {
90     intf_thread_t * p_intf = [NSApp getIntf];
91     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
92                                                        FIND_ANYWHERE );
93     if( p_playlist != NULL )
94     {
95         vout_OSDMessage( p_intf, _( "Stop" ) );
96         playlist_Stop( p_playlist );
97         vlc_object_release( p_playlist );
98     }
99 }
100
101 - (IBAction)faster:(id)sender
102 {
103     intf_thread_t * p_intf = [NSApp getIntf];
104     input_thread_t * p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
105                                                        FIND_ANYWHERE );
106     if( p_input != NULL )
107     {
108         vlc_value_t val; val.b_bool = VLC_TRUE;
109
110         var_Set( p_input, "rate-faster", val );
111         vout_OSDMessage( p_intf, _( "Faster" ) );
112         vlc_object_release( p_input );
113     }
114 }
115
116 - (IBAction)slower:(id)sender
117 {
118     intf_thread_t * p_intf = [NSApp getIntf];
119     input_thread_t * p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
120                                                        FIND_ANYWHERE );
121     if( p_input != NULL )
122     {
123         vlc_value_t val; val.b_bool = VLC_TRUE;
124
125         var_Set( p_input, "rate-slower", val );
126         vout_OSDMessage( p_intf, _( "Slower" ) );
127         vlc_object_release( p_input );
128     }
129 }
130
131 - (IBAction)prev:(id)sender
132 {
133     intf_thread_t * p_intf = [NSApp getIntf];
134     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
135                                                        FIND_ANYWHERE );
136     if( p_playlist )
137     {
138         playlist_Prev( p_playlist );
139         vlc_object_release( p_playlist );
140         vout_OSDMessage( p_intf, _( "Previous" ) );
141     }
142 }
143
144 - (IBAction)next:(id)sender
145 {
146     intf_thread_t * p_intf = [NSApp getIntf];
147     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
148                                                        FIND_ANYWHERE );
149     if( p_playlist )
150     {
151         playlist_Next( p_playlist );
152         vlc_object_release( p_playlist );
153         vout_OSDMessage( p_intf, _( "Next" ) );
154     }
155 }
156
157 - (IBAction)random:(id)sender
158 {
159     intf_thread_t * p_intf = [NSApp getIntf];
160     vlc_value_t val;
161     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
162                                                        FIND_ANYWHERE );
163     if( p_playlist == NULL )
164     {
165         return;
166     }
167
168     var_Get( p_playlist, "random", &val );
169     val.b_bool = !val.b_bool;
170     var_Set( p_playlist, "random", val );
171     if( val.b_bool )
172     {
173         vout_OSDMessage( p_intf, _( "Random On" ) );
174     }
175     else
176     {
177         vout_OSDMessage( p_intf, _( "Random Off" ) );
178     }    
179
180     p_intf->p_sys->b_playlist_update = VLC_TRUE;
181     p_intf->p_sys->b_intf_update = VLC_TRUE;
182     vlc_object_release( p_playlist );
183 }
184
185 - (IBAction)repeat:(id)sender
186 {
187     intf_thread_t * p_intf = [NSApp getIntf];
188     vlc_value_t val;
189     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
190                                                        FIND_ANYWHERE );
191     if( p_playlist == NULL )
192     {
193         return;
194     }
195
196     var_Get( p_playlist, "repeat", &val );
197     if (!val.b_bool)
198     {   
199         var_Set( p_playlist, "loop", val );
200     } 
201     val.b_bool = !val.b_bool;
202     var_Set( p_playlist, "repeat", val );
203     if( val.b_bool )
204     {
205         vout_OSDMessage( p_intf, _( "Repeat All" ) );
206     }
207     else
208     {
209         vout_OSDMessage( p_intf, _( "Repeat Off" ) );
210     }
211
212     p_intf->p_sys->b_playlist_update = VLC_TRUE;    
213     p_intf->p_sys->b_intf_update = VLC_TRUE;
214     vlc_object_release( p_playlist );
215 }
216
217 - (IBAction)loop:(id)sender
218 {
219     intf_thread_t * p_intf = [NSApp getIntf];
220     vlc_value_t val;
221     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
222                                                        FIND_ANYWHERE );
223     if( p_playlist == NULL )
224     {
225         return;
226     }
227
228     var_Get( p_playlist, "loop", &val );
229     if (!val.b_bool)
230     {
231         var_Set( p_playlist, "repeat", val );
232     }
233     val.b_bool = !val.b_bool;
234     var_Set( p_playlist, "loop", val );
235     if( val.b_bool )
236     {
237         vout_OSDMessage( p_intf, _( "Repeat One" ) );
238     }
239     else
240     {
241         vout_OSDMessage( p_intf, _( "Repeat Off" ) );
242     }    
243
244     p_intf->p_sys->b_playlist_update = VLC_TRUE;
245     p_intf->p_sys->b_intf_update = VLC_TRUE;
246     vlc_object_release( p_playlist );
247 }
248
249 - (IBAction)forward:(id)sender
250 {
251     intf_thread_t * p_intf = [NSApp getIntf];
252     input_thread_t * p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
253                                                        FIND_ANYWHERE );
254     if( p_input != NULL )
255     {
256         vlc_value_t time;
257         time.i_time = 10 * 1000000;
258         var_Set( p_input, "time-offset", time );
259         vout_OSDMessage( p_intf, _( "Jump +10 Seconds" ) );
260         vlc_object_release( p_input );
261     }
262 }
263
264 - (IBAction)backward:(id)sender
265 {
266     intf_thread_t * p_intf = [NSApp getIntf];
267     input_thread_t * p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
268                                                        FIND_ANYWHERE );
269     if( p_input != NULL )
270     {
271         vlc_value_t time;
272         time.i_time = -10 * 1000000;
273         var_Set( p_input, "time-offset", time );
274         vout_OSDMessage( p_intf, _( "Jump -10 Seconds" ) );
275         vlc_object_release( p_input );
276     }
277 }
278
279 - (IBAction)volumeUp:(id)sender
280 {
281     intf_thread_t * p_intf = [NSApp getIntf];
282
283     if( p_intf->p_sys->b_mute )
284     {
285         [self mute: nil];
286     }
287
288     aout_VolumeUp( p_intf, 1, NULL );
289
290     [self updateVolumeSlider];
291 }
292
293 - (IBAction)volumeDown:(id)sender
294 {
295     intf_thread_t * p_intf = [NSApp getIntf];
296
297     if( p_intf->p_sys->b_mute )
298     {
299         [self mute: nil];
300     }
301     
302     aout_VolumeDown( p_intf, 1, NULL );
303
304     [self updateVolumeSlider];
305 }
306
307 - (IBAction)mute:(id)sender
308 {
309     intf_thread_t * p_intf = [NSApp getIntf];
310     audio_volume_t i_volume;
311
312     aout_VolumeMute( p_intf, &i_volume );
313     p_intf->p_sys->b_mute = ( i_volume == 0 );
314
315     [self updateVolumeSlider];
316 }
317
318 - (IBAction)volumeSliderUpdated:(id)sender
319 {
320     intf_thread_t * p_intf = [NSApp getIntf];
321     audio_volume_t i_volume = (audio_volume_t)[sender intValue];
322
323     aout_VolumeSet( p_intf, i_volume * AOUT_VOLUME_STEP );
324 }
325
326 - (void)updateVolumeSlider
327 {
328     intf_thread_t * p_intf = [NSApp getIntf];
329     audio_volume_t i_volume;
330
331     aout_VolumeGet( p_intf, &i_volume );
332
333     [o_volumeslider setFloatValue: (float)(i_volume / AOUT_VOLUME_STEP)];
334
335     vout_OSDMessage( p_intf, "Vol %d%%", i_volume*100/AOUT_VOLUME_MAX );
336 }
337
338 - (IBAction)windowAction:(id)sender
339 {
340     id o_window = [NSApp keyWindow];
341     NSString *o_title = [sender title];
342     NSArray *o_windows = [NSApp orderedWindows];
343     NSEnumerator *o_enumerator = [o_windows objectEnumerator];
344     vout_thread_t   *p_vout = vlc_object_find( [NSApp getIntf], VLC_OBJECT_VOUT,
345                                               FIND_ANYWHERE );
346
347     if( p_vout != NULL )
348     {
349         while ((o_window = [o_enumerator nextObject]))
350         {
351             if( [[o_window className] isEqualToString: @"VLCWindow"] )
352             {
353                 if( [o_title isEqualToString: _NS("Half Size") ] )
354                     [o_window scaleWindowWithFactor: 0.5];
355                 else if( [o_title isEqualToString: _NS("Normal Size") ] )
356                     [o_window scaleWindowWithFactor: 1.0];
357                 else if( [o_title isEqualToString: _NS("Double Size") ] )
358                     [o_window scaleWindowWithFactor: 2.0];
359                 else if( [o_title isEqualToString: _NS("Float on Top") ] )
360                     [o_window toggleFloatOnTop];
361                 else if( [o_title isEqualToString: _NS("Fit to Screen") ] )
362                 {
363                     if( ![o_window isZoomed] )
364                         [o_window performZoom:self];
365                 }
366                 else
367                 {
368                     [o_window toggleFullscreen];
369                 }
370                 break;
371             }
372         }
373         vlc_object_release( (vlc_object_t *)p_vout );
374     }
375 }
376
377 - (void)setupVarMenuItem:(NSMenuItem *)o_mi
378                     target:(vlc_object_t *)p_object
379                     var:(const char *)psz_variable
380                     selector:(SEL)pf_callback
381 {
382     vlc_value_t val, text;
383     int i_type = var_Type( p_object, psz_variable );
384
385     switch( i_type & VLC_VAR_TYPE )
386     {
387     case VLC_VAR_VOID:
388     case VLC_VAR_BOOL:
389     case VLC_VAR_VARIABLE:
390     case VLC_VAR_STRING:
391     case VLC_VAR_INTEGER:
392         break;
393     default:
394         /* Variable doesn't exist or isn't handled */
395         return;
396     }
397     
398     /* Make sure we want to display the variable */
399     if( i_type & VLC_VAR_HASCHOICE )
400     {
401         var_Change( p_object, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL );
402         if( val.i_int == 0 ) return;
403         if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
404             return;
405     }
406     
407     /* Get the descriptive name of the variable */
408     var_Change( p_object, psz_variable, VLC_VAR_GETTEXT, &text, NULL );
409     [o_mi setTitle: [NSApp localizedString: text.psz_string ?
410                                         text.psz_string : strdup( psz_variable ) ]];
411
412     var_Get( p_object, psz_variable, &val );
413     if( i_type & VLC_VAR_HASCHOICE )
414     {
415         NSMenu *o_menu = [o_mi submenu];
416
417         [self setupVarMenu: o_menu forMenuItem: o_mi target:p_object
418                         var:psz_variable selector:pf_callback];
419         
420         if( text.psz_string ) free( text.psz_string );
421         return;
422     }
423
424     VLCMenuExt *o_data;
425     switch( i_type & VLC_VAR_TYPE )
426     {
427     case VLC_VAR_VOID:
428         o_data = [[VLCMenuExt alloc] initWithVar: psz_variable Object: p_object->i_object_id
429                 Value: val ofType: i_type];
430         [o_mi setRepresentedObject: [NSValue valueWithPointer:[o_data retain]]];
431         break;
432
433     case VLC_VAR_BOOL:
434         o_data = [[VLCMenuExt alloc] initWithVar: psz_variable Object: p_object->i_object_id
435                 Value: val ofType: i_type];
436         [o_mi setRepresentedObject: [NSValue valueWithPointer:[o_data retain]]];
437         [o_mi setState: val.b_bool ? TRUE : FALSE ];
438         break;
439
440     default:
441         if( text.psz_string ) free( text.psz_string );
442         return;
443     }
444
445     if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
446     if( text.psz_string ) free( text.psz_string );
447 }
448
449
450 - (void)setupVarMenu:(NSMenu *)o_menu
451                     forMenuItem: (NSMenuItem *)o_parent
452                     target:(vlc_object_t *)p_object
453                     var:(const char *)psz_variable
454                     selector:(SEL)pf_callback
455 {
456     vlc_value_t val, val_list, text_list;
457     int i_type, i, i_nb_items;
458
459     /* remove previous items */
460     i_nb_items = [o_menu numberOfItems];
461     for( i = 0; i < i_nb_items; i++ )
462     {
463         [o_menu removeItemAtIndex: 0];
464     }
465
466     /* Check the type of the object variable */
467     i_type = var_Type( p_object, psz_variable );
468
469     /* Make sure we want to display the variable */
470     if( i_type & VLC_VAR_HASCHOICE )
471     {
472         var_Change( p_object, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL );
473         if( val.i_int == 0 ) return;
474         if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
475             return;
476     }
477     else
478     {
479         return;
480     }
481
482     switch( i_type & VLC_VAR_TYPE )
483     {
484     case VLC_VAR_VOID:
485     case VLC_VAR_BOOL:
486     case VLC_VAR_VARIABLE:
487     case VLC_VAR_STRING:
488     case VLC_VAR_INTEGER:
489         break;
490     default:
491         /* Variable doesn't exist or isn't handled */
492         return;
493     }
494
495     if( var_Get( p_object, psz_variable, &val ) < 0 )
496     {
497         return;
498     }
499
500     if( var_Change( p_object, psz_variable, VLC_VAR_GETLIST,
501                     &val_list, &text_list ) < 0 )
502     {
503         if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
504         return;
505     }
506
507     /* make (un)sensitive */
508     [o_parent setEnabled: ( val_list.p_list->i_count > 1 )];
509
510     for( i = 0; i < val_list.p_list->i_count; i++ )
511     {
512         vlc_value_t another_val;
513         NSMenuItem * o_lmi;
514         NSString *o_title = @"";
515         VLCMenuExt *o_data;
516
517         switch( i_type & VLC_VAR_TYPE )
518         {
519         case VLC_VAR_VARIABLE:
520
521             /* This is causing crashes for the moment.
522             o_title = [NSApp localizedString: text_list.p_list->p_values[i].psz_string ?
523                 text_list.p_list->p_values[i].psz_string : val_list.p_list->p_values[i].psz_string ];
524             
525             o_data = [[VLCMenuExt alloc] initWithVar: strdup(psz_variable) Object: p_object->i_object_id
526                 Value: val ofType: i_type];
527             [o_lmi setRepresentedObject: [NSValue valueWithPointer:[o_data retain]]];
528
529             // Create a submenu
530             NSMenu *o_menu = [o_lmi submenu];
531
532             [self setupVarMenu: o_menu forMenuItem: o_lmi target:p_object
533                             var:psz_variable selector:pf_callback];
534 */
535             return;
536
537         case VLC_VAR_STRING:
538             another_val.psz_string =
539                 strdup(val_list.p_list->p_values[i].psz_string);
540
541             o_title = [NSApp localizedString: text_list.p_list->p_values[i].psz_string ?
542                 text_list.p_list->p_values[i].psz_string : val_list.p_list->p_values[i].psz_string ];
543
544             o_lmi = [o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""];
545             o_data = [[VLCMenuExt alloc] initWithVar: strdup(psz_variable) Object: p_object->i_object_id
546                     Value: another_val ofType: i_type];
547             [o_lmi setRepresentedObject: [NSValue valueWithPointer:[o_data retain]]];
548             [o_lmi setTarget: self];
549             
550             if( !strcmp( val.psz_string, val_list.p_list->p_values[i].psz_string ) )
551                 [o_lmi setState: TRUE ];
552
553             break;
554
555         case VLC_VAR_INTEGER:
556
557              o_title = text_list.p_list->p_values[i].psz_string ?
558                                  [NSApp localizedString: strdup( text_list.p_list->p_values[i].psz_string )] :
559                                  [NSString stringWithFormat: @"%d",
560                                  val_list.p_list->p_values[i].i_int];
561
562             o_lmi = [[o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""] retain ];
563             o_data = [[VLCMenuExt alloc] initWithVar: strdup(psz_variable) Object: p_object->i_object_id
564                     Value: val_list.p_list->p_values[i] ofType: i_type];
565             [o_lmi setRepresentedObject: [NSValue valueWithPointer:[ o_data retain]]];
566             [o_lmi setTarget: self];
567
568             if( val_list.p_list->p_values[i].i_int == val.i_int )
569                 [o_lmi setState: TRUE ];
570             break;
571
572         default:
573           break;
574         }
575     }
576     
577     /* clean up everything */
578     if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
579     var_Change( p_object, psz_variable, VLC_VAR_FREELIST, &val_list, &text_list );
580 }
581
582 - (IBAction)toggleVar:(id)sender
583 {
584     NSMenuItem *o_mi = (NSMenuItem *)sender;
585     VLCMenuExt *o_data = [[o_mi representedObject] pointerValue];
586     [NSThread detachNewThreadSelector: @selector(toggleVarThread:)
587         toTarget: self withObject: o_data];
588
589     return;
590 }
591
592 - (int)toggleVarThread: (id)_o_data
593 {
594     vlc_object_t *p_object;
595     NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
596     VLCMenuExt *o_data = (VLCMenuExt *)_o_data;
597
598     vlc_thread_set_priority( [NSApp getIntf] , VLC_THREAD_PRIORITY_LOW );
599
600     p_object = (vlc_object_t *)vlc_object_get( [NSApp getIntf],
601                                     [o_data objectID] );
602
603     if( p_object != NULL )
604     {
605         var_Set( p_object, strdup([o_data name]), [o_data value] );
606         vlc_object_release( p_object );
607         [o_pool release];
608         return VLC_TRUE;
609     }
610     [o_pool release];
611     return VLC_EGENERIC;
612 }
613
614 @end
615
616 @implementation VLCControls (NSMenuValidation)
617  
618 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
619 {
620     BOOL bEnabled = TRUE;
621     vlc_value_t val;
622     intf_thread_t * p_intf = [NSApp getIntf];
623     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
624                                                        FIND_ANYWHERE );
625
626     if( p_playlist != NULL )
627     {
628         vlc_mutex_lock( &p_playlist->object_lock );
629     }
630
631 #define p_input p_playlist->p_input
632
633     if( [[o_mi title] isEqualToString: _NS("Faster")] ||
634         [[o_mi title] isEqualToString: _NS("Slower")] )
635     {
636         if( p_playlist != NULL && p_input != NULL )
637         {
638             vlc_mutex_lock( &p_input->stream.stream_lock );
639             bEnabled = p_input->stream.b_pace_control;
640             vlc_mutex_unlock( &p_input->stream.stream_lock );
641         }
642         else
643         {
644             bEnabled = FALSE;
645         }
646     }
647     else if( [[o_mi title] isEqualToString: _NS("Stop")] )
648     {
649         if( p_playlist == NULL || p_input == NULL )
650         {
651             bEnabled = FALSE;
652         }
653     }
654     else if( [[o_mi title] isEqualToString: _NS("Previous")] ||
655              [[o_mi title] isEqualToString: _NS("Next")] )
656     {
657         if( p_playlist == NULL )
658         {
659             bEnabled = FALSE;
660         }
661         else
662         {
663             bEnabled = p_playlist->i_size > 1;
664
665             if( p_input != NULL )
666             {
667                 vlc_mutex_lock( &p_input->stream.stream_lock );
668                 bEnabled |= p_input->stream.i_area_nb > 1;
669                 vlc_mutex_unlock( &p_input->stream.stream_lock );
670             }
671         }
672     }
673     else if( [[o_mi title] isEqualToString: _NS("Random")] )
674     {
675         int i_state;
676         var_Get( p_playlist, "random", &val );
677         i_state = val.b_bool ? NSOnState : NSOffState;
678         [o_mi setState: i_state];
679     }
680     else if( [[o_mi title] isEqualToString: _NS("Repeat One")] )
681     {
682         int i_state;
683         var_Get( p_playlist, "repeat", &val );
684         i_state = val.b_bool ? NSOnState : NSOffState;
685         [o_mi setState: i_state];
686     }
687     else if( [[o_mi title] isEqualToString: _NS("Repeat All")] )
688     {
689         int i_state;
690         var_Get( p_playlist, "loop", &val );
691         i_state = val.b_bool ? NSOnState : NSOffState;
692         [o_mi setState: i_state];
693     }
694     else if( [[o_mi title] isEqualToString: _NS("Step Forward")] ||
695              [[o_mi title] isEqualToString: _NS("Step Backward")] )
696     {
697         if( p_playlist != NULL && p_input != NULL )
698         {
699             vlc_mutex_lock( &p_input->stream.stream_lock );
700             bEnabled = p_input->stream.b_seekable;
701             vlc_mutex_unlock( &p_input->stream.stream_lock );
702         }
703         else
704         {
705             bEnabled = FALSE;
706         }
707     }
708     else if( [[o_mi title] isEqualToString: _NS("Mute")] ) 
709     {
710         [o_mi setState: p_intf->p_sys->b_mute ? NSOnState : NSOffState];
711     }
712     else if( [[o_mi title] isEqualToString: _NS("Fullscreen")] ||
713                 [[o_mi title] isEqualToString: _NS("Half Size")] ||
714                 [[o_mi title] isEqualToString: _NS("Normal Size")] ||
715                 [[o_mi title] isEqualToString: _NS("Double Size")] ||
716                 [[o_mi title] isEqualToString: _NS("Fit to Screen")] ||
717                 [[o_mi title] isEqualToString: _NS("Float on Top")] )
718     {
719         id o_window;
720         NSArray *o_windows = [NSApp orderedWindows];
721         NSEnumerator *o_enumerator = [o_windows objectEnumerator];
722         bEnabled = FALSE;
723         
724         if ( [[o_mi title] isEqualToString: _NS("Float on Top")] )
725         {
726             int i_state = config_GetInt( p_playlist, "video-on-top" ) ?
727                       NSOnState : NSOffState;
728             [o_mi setState: i_state];
729         }
730         
731         vout_thread_t   *p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
732                                               FIND_ANYWHERE );
733         if( p_vout != NULL )
734         {
735             while ((o_window = [o_enumerator nextObject]))
736             {
737                 if( [[o_window className] isEqualToString: @"VLCWindow"] )
738                 {
739                     bEnabled = TRUE;
740                     break;
741                 }
742             }
743             vlc_object_release( (vlc_object_t *)p_vout );
744         }
745     }
746
747     if( p_playlist != NULL )
748     {
749         vlc_mutex_unlock( &p_playlist->object_lock );
750         vlc_object_release( p_playlist );
751     }
752
753     return( bEnabled );
754 }
755
756 @end
757
758 /*****************************************************************************
759  * VLCMenuExt implementation 
760  *****************************************************************************
761  * Object connected to a playlistitem which remembers the data belonging to
762  * the variable of the autogenerated menu
763  *****************************************************************************/
764 @implementation VLCMenuExt
765
766 - (id)initWithVar: (const char *)_psz_name Object: (int)i_id
767         Value: (vlc_value_t)val ofType: (int)_i_type
768 {
769     self = [super init];
770
771     if( self != nil )
772     {
773         psz_name = strdup( _psz_name );
774         i_object_id = i_id;
775         value = val;
776         i_type = _i_type;
777     }
778
779     return( self );
780 }
781
782 - (void)dealloc
783 {
784     free( psz_name );
785 }
786
787 - (char *)name
788 {
789     return psz_name;
790 }
791
792 - (int)objectID
793 {
794     return i_object_id;
795 }
796
797 - (vlc_value_t)value
798 {
799     return value;
800 }
801
802 - (int)type
803 {
804     return i_type;
805 }
806
807 @end