]> git.sesse.net Git - vlc/blob - modules/gui/macosx/controls.m
Adds "Enable/disable item" menu item in playlist contextual menu.
[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
280 - (IBAction)volumeUp:(id)sender
281 {
282     intf_thread_t * p_intf = [NSApp getIntf];
283
284     if( p_intf->p_sys->b_mute )
285     {
286         [self mute: nil];
287     }
288
289     aout_VolumeUp( p_intf, 1, NULL );
290
291     [self updateVolumeSlider];
292 }
293
294 - (IBAction)volumeDown:(id)sender
295 {
296     intf_thread_t * p_intf = [NSApp getIntf];
297
298     if( p_intf->p_sys->b_mute )
299     {
300         [self mute: nil];
301     }
302     
303     aout_VolumeDown( p_intf, 1, NULL );
304
305     [self updateVolumeSlider];
306 }
307
308 - (IBAction)mute:(id)sender
309 {
310     intf_thread_t * p_intf = [NSApp getIntf];
311     audio_volume_t i_volume;
312
313     aout_VolumeMute( p_intf, &i_volume );
314     p_intf->p_sys->b_mute = ( i_volume == 0 );
315
316     [self updateVolumeSlider];
317 }
318
319 - (IBAction)volumeSliderUpdated:(id)sender
320 {
321     intf_thread_t * p_intf = [NSApp getIntf];
322     audio_volume_t i_volume = (audio_volume_t)[sender intValue];
323
324     aout_VolumeSet( p_intf, i_volume * AOUT_VOLUME_STEP );
325 }
326
327 - (void)updateVolumeSlider
328 {
329     intf_thread_t * p_intf = [NSApp getIntf];
330     audio_volume_t i_volume;
331
332     aout_VolumeGet( p_intf, &i_volume );
333
334     [o_volumeslider setFloatValue: (float)(i_volume / AOUT_VOLUME_STEP)];
335
336     vout_OSDMessage( p_intf, "Vol %d%%", i_volume*100/AOUT_VOLUME_MAX );
337 }
338
339 - (IBAction)windowAction:(id)sender
340 {
341     id o_window = [NSApp keyWindow];
342     NSString *o_title = [sender title];
343     NSArray *o_windows = [NSApp orderedWindows];
344     NSEnumerator *o_enumerator = [o_windows objectEnumerator];
345     vout_thread_t   *p_vout = vlc_object_find( [NSApp getIntf], VLC_OBJECT_VOUT,
346                                               FIND_ANYWHERE );
347
348     if( p_vout != NULL )
349     {
350         while ((o_window = [o_enumerator nextObject]))
351         {
352             if( [[o_window className] isEqualToString: @"VLCWindow"] )
353             {
354                 if( [o_title isEqualToString: _NS("Half Size") ] )
355                     [o_window scaleWindowWithFactor: 0.5];
356                 else if( [o_title isEqualToString: _NS("Normal Size") ] )
357                     [o_window scaleWindowWithFactor: 1.0];
358                 else if( [o_title isEqualToString: _NS("Double Size") ] )
359                     [o_window scaleWindowWithFactor: 2.0];
360                 else if( [o_title isEqualToString: _NS("Float on Top") ] )
361                     [o_window toggleFloatOnTop];
362                 else if( [o_title isEqualToString: _NS("Fit to Screen") ] )
363                 {
364                     if( ![o_window isZoomed] )
365                         [o_window performZoom:self];
366                 }
367                 else
368                 {
369                     [o_window toggleFullscreen];
370                 }
371                 break;
372             }
373         }
374         vlc_object_release( (vlc_object_t *)p_vout );
375     }
376 }
377
378 - (void)setupVarMenuItem:(NSMenuItem *)o_mi
379                     target:(vlc_object_t *)p_object
380                     var:(const char *)psz_variable
381                     selector:(SEL)pf_callback
382 {
383     vlc_value_t val, text;
384     int i_type = var_Type( p_object, psz_variable );
385
386     switch( i_type & VLC_VAR_TYPE )
387     {
388     case VLC_VAR_VOID:
389     case VLC_VAR_BOOL:
390     case VLC_VAR_VARIABLE:
391     case VLC_VAR_STRING:
392     case VLC_VAR_INTEGER:
393         break;
394     default:
395         /* Variable doesn't exist or isn't handled */
396         return;
397     }
398     
399     /* Make sure we want to display the variable */
400     if( i_type & VLC_VAR_HASCHOICE )
401     {
402         var_Change( p_object, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL );
403         if( val.i_int == 0 ) return;
404         if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
405             return;
406     }
407     
408     /* Get the descriptive name of the variable */
409     var_Change( p_object, psz_variable, VLC_VAR_GETTEXT, &text, NULL );
410     [o_mi setTitle: [NSApp localizedString: text.psz_string ?
411                                         text.psz_string : strdup( psz_variable ) ]];
412
413     var_Get( p_object, psz_variable, &val );
414     if( i_type & VLC_VAR_HASCHOICE )
415     {
416         NSMenu *o_menu = [o_mi submenu];
417
418         [self setupVarMenu: o_menu forMenuItem: o_mi target:p_object
419                         var:psz_variable selector:pf_callback];
420         
421         if( text.psz_string ) free( text.psz_string );
422         return;
423     }
424
425     VLCMenuExt *o_data;
426     switch( i_type & VLC_VAR_TYPE )
427     {
428     case VLC_VAR_VOID:
429         o_data = [[VLCMenuExt alloc] initWithVar: psz_variable Object: p_object->i_object_id
430                 Value: val ofType: i_type];
431         [o_mi setRepresentedObject: [NSValue valueWithPointer:[o_data retain]]];
432         break;
433
434     case VLC_VAR_BOOL:
435         o_data = [[VLCMenuExt alloc] initWithVar: psz_variable Object: p_object->i_object_id
436                 Value: val ofType: i_type];
437         [o_mi setRepresentedObject: [NSValue valueWithPointer:[o_data retain]]];
438         [o_mi setState: val.b_bool ? TRUE : FALSE ];
439         break;
440
441     default:
442         if( text.psz_string ) free( text.psz_string );
443         return;
444     }
445
446     if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
447     if( text.psz_string ) free( text.psz_string );
448 }
449
450
451 - (void)setupVarMenu:(NSMenu *)o_menu
452                     forMenuItem: (NSMenuItem *)o_parent
453                     target:(vlc_object_t *)p_object
454                     var:(const char *)psz_variable
455                     selector:(SEL)pf_callback
456 {
457     vlc_value_t val, val_list, text_list;
458     int i_type, i, i_nb_items;
459
460     /* remove previous items */
461     i_nb_items = [o_menu numberOfItems];
462     for( i = 0; i < i_nb_items; i++ )
463     {
464         [o_menu removeItemAtIndex: 0];
465     }
466
467     /* Check the type of the object variable */
468     i_type = var_Type( p_object, psz_variable );
469
470     /* Make sure we want to display the variable */
471     if( i_type & VLC_VAR_HASCHOICE )
472     {
473         var_Change( p_object, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL );
474         if( val.i_int == 0 ) return;
475         if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
476             return;
477     }
478     else
479     {
480         return;
481     }
482
483     switch( i_type & VLC_VAR_TYPE )
484     {
485     case VLC_VAR_VOID:
486     case VLC_VAR_BOOL:
487     case VLC_VAR_VARIABLE:
488     case VLC_VAR_STRING:
489     case VLC_VAR_INTEGER:
490         break;
491     default:
492         /* Variable doesn't exist or isn't handled */
493         return;
494     }
495
496     if( var_Get( p_object, psz_variable, &val ) < 0 )
497     {
498         return;
499     }
500
501     if( var_Change( p_object, psz_variable, VLC_VAR_GETLIST,
502                     &val_list, &text_list ) < 0 )
503     {
504         if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
505         return;
506     }
507
508     /* make (un)sensitive */
509     [o_parent setEnabled: ( val_list.p_list->i_count > 1 )];
510
511     for( i = 0; i < val_list.p_list->i_count; i++ )
512     {
513         vlc_value_t another_val;
514         NSMenuItem * o_lmi;
515         NSString *o_title = @"";
516         VLCMenuExt *o_data;
517
518         switch( i_type & VLC_VAR_TYPE )
519         {
520         case VLC_VAR_VARIABLE:
521
522             /* This is causing crashes for the moment.
523             o_title = [NSApp localizedString: text_list.p_list->p_values[i].psz_string ?
524                 text_list.p_list->p_values[i].psz_string : val_list.p_list->p_values[i].psz_string ];
525             
526             o_data = [[VLCMenuExt alloc] initWithVar: strdup(psz_variable) Object: p_object->i_object_id
527                 Value: val ofType: i_type];
528             [o_lmi setRepresentedObject: [NSValue valueWithPointer:[o_data retain]]];
529
530             // Create a submenu
531             NSMenu *o_menu = [o_lmi submenu];
532
533             [self setupVarMenu: o_menu forMenuItem: o_lmi target:p_object
534                             var:psz_variable selector:pf_callback];
535 */
536             return;
537
538         case VLC_VAR_STRING:
539             another_val.psz_string =
540                 strdup(val_list.p_list->p_values[i].psz_string);
541
542             o_title = [NSApp localizedString: text_list.p_list->p_values[i].psz_string ?
543                 text_list.p_list->p_values[i].psz_string : val_list.p_list->p_values[i].psz_string ];
544
545             o_lmi = [o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""];
546             o_data = [[VLCMenuExt alloc] initWithVar: strdup(psz_variable) Object: p_object->i_object_id
547                     Value: another_val ofType: i_type];
548             [o_lmi setRepresentedObject: [NSValue valueWithPointer:[o_data retain]]];
549             [o_lmi setTarget: self];
550             
551             if( !strcmp( val.psz_string, val_list.p_list->p_values[i].psz_string ) )
552                 [o_lmi setState: TRUE ];
553
554             break;
555
556         case VLC_VAR_INTEGER:
557
558              o_title = text_list.p_list->p_values[i].psz_string ?
559                                  [NSApp localizedString: strdup( text_list.p_list->p_values[i].psz_string )] :
560                                  [NSString stringWithFormat: @"%d",
561                                  val_list.p_list->p_values[i].i_int];
562
563             o_lmi = [[o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""] retain ];
564             o_data = [[VLCMenuExt alloc] initWithVar: strdup(psz_variable) Object: p_object->i_object_id
565                     Value: val_list.p_list->p_values[i] ofType: i_type];
566             [o_lmi setRepresentedObject: [NSValue valueWithPointer:[ o_data retain]]];
567             [o_lmi setTarget: self];
568
569             if( val_list.p_list->p_values[i].i_int == val.i_int )
570                 [o_lmi setState: TRUE ];
571             break;
572
573         default:
574           break;
575         }
576     }
577     
578     /* clean up everything */
579     if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
580     var_Change( p_object, psz_variable, VLC_VAR_FREELIST, &val_list, &text_list );
581 }
582
583 - (IBAction)toggleVar:(id)sender
584 {
585     NSMenuItem *o_mi = (NSMenuItem *)sender;
586     VLCMenuExt *o_data = [[o_mi representedObject] pointerValue];
587     [NSThread detachNewThreadSelector: @selector(toggleVarThread:)
588         toTarget: self withObject: o_data];
589
590     return;
591 }
592
593 - (int)toggleVarThread: (id)_o_data
594 {
595     vlc_object_t *p_object;
596     NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
597     VLCMenuExt *o_data = (VLCMenuExt *)_o_data;
598
599     vlc_thread_set_priority( [NSApp getIntf] , VLC_THREAD_PRIORITY_LOW );
600
601     p_object = (vlc_object_t *)vlc_object_get( [NSApp getIntf],
602                                     [o_data objectID] );
603
604     if( p_object != NULL )
605     {
606         var_Set( p_object, strdup([o_data name]), [o_data value] );
607         vlc_object_release( p_object );
608         [o_pool release];
609         return VLC_TRUE;
610     }
611     [o_pool release];
612     return VLC_EGENERIC;
613 }
614
615 @end
616
617 @implementation VLCControls (NSMenuValidation)
618  
619 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
620 {
621     BOOL bEnabled = TRUE;
622     vlc_value_t val;
623     intf_thread_t * p_intf = [NSApp getIntf];
624     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
625                                                        FIND_ANYWHERE );
626
627     if( p_playlist != NULL )
628     {
629         vlc_mutex_lock( &p_playlist->object_lock );
630     }
631
632 #define p_input p_playlist->p_input
633
634     if( [[o_mi title] isEqualToString: _NS("Faster")] ||
635         [[o_mi title] isEqualToString: _NS("Slower")] )
636     {
637         if( p_playlist != NULL && p_input != NULL )
638         {
639             vlc_mutex_lock( &p_input->stream.stream_lock );
640             bEnabled = p_input->stream.b_pace_control;
641             vlc_mutex_unlock( &p_input->stream.stream_lock );
642         }
643         else
644         {
645             bEnabled = FALSE;
646         }
647     }
648     else if( [[o_mi title] isEqualToString: _NS("Stop")] )
649     {
650         if( p_playlist == NULL || p_input == NULL )
651         {
652             bEnabled = FALSE;
653         }
654     }
655     else if( [[o_mi title] isEqualToString: _NS("Previous")] ||
656              [[o_mi title] isEqualToString: _NS("Next")] )
657     {
658         if( p_playlist == NULL )
659         {
660             bEnabled = FALSE;
661         }
662         else
663         {
664             bEnabled = p_playlist->i_size > 1;
665
666             if( p_input != NULL )
667             {
668                 vlc_mutex_lock( &p_input->stream.stream_lock );
669                 bEnabled |= p_input->stream.i_area_nb > 1;
670                 vlc_mutex_unlock( &p_input->stream.stream_lock );
671             }
672         }
673     }
674     else if( [[o_mi title] isEqualToString: _NS("Random")] )
675     {
676         int i_state;
677         var_Get( p_playlist, "random", &val );
678         i_state = val.b_bool ? NSOnState : NSOffState;
679         [o_mi setState: i_state];
680     }
681     else if( [[o_mi title] isEqualToString: _NS("Repeat One")] )
682     {
683         int i_state;
684         var_Get( p_playlist, "repeat", &val );
685         i_state = val.b_bool ? NSOnState : NSOffState;
686         [o_mi setState: i_state];
687     }
688     else if( [[o_mi title] isEqualToString: _NS("Repeat All")] )
689     {
690         int i_state;
691         var_Get( p_playlist, "loop", &val );
692         i_state = val.b_bool ? NSOnState : NSOffState;
693         [o_mi setState: i_state];
694     }
695     else if( [[o_mi title] isEqualToString: _NS("Step Forward")] ||
696              [[o_mi title] isEqualToString: _NS("Step Backward")] )
697     {
698         if( p_playlist != NULL && p_input != NULL )
699         {
700             vlc_mutex_lock( &p_input->stream.stream_lock );
701             bEnabled = p_input->stream.b_seekable;
702             vlc_mutex_unlock( &p_input->stream.stream_lock );
703         }
704         else
705         {
706             bEnabled = FALSE;
707         }
708     }
709     else if( [[o_mi title] isEqualToString: _NS("Mute")] ) 
710     {
711         [o_mi setState: p_intf->p_sys->b_mute ? NSOnState : NSOffState];
712     }
713     else if( [[o_mi title] isEqualToString: _NS("Fullscreen")] ||
714                 [[o_mi title] isEqualToString: _NS("Half Size")] ||
715                 [[o_mi title] isEqualToString: _NS("Normal Size")] ||
716                 [[o_mi title] isEqualToString: _NS("Double Size")] ||
717                 [[o_mi title] isEqualToString: _NS("Fit to Screen")] ||
718                 [[o_mi title] isEqualToString: _NS("Float on Top")] )
719     {
720         id o_window;
721         NSArray *o_windows = [NSApp orderedWindows];
722         NSEnumerator *o_enumerator = [o_windows objectEnumerator];
723         bEnabled = FALSE;
724         
725         if ( [[o_mi title] isEqualToString: _NS("Float on Top")] )
726         {
727             int i_state = config_GetInt( p_playlist, "video-on-top" ) ?
728                       NSOnState : NSOffState;
729             [o_mi setState: i_state];
730         }
731         
732         vout_thread_t   *p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
733                                               FIND_ANYWHERE );
734         if( p_vout != NULL )
735         {
736             while ((o_window = [o_enumerator nextObject]))
737             {
738                 if( [[o_window className] isEqualToString: @"VLCWindow"] )
739                 {
740                     bEnabled = TRUE;
741                     break;
742                 }
743             }
744             vlc_object_release( (vlc_object_t *)p_vout );
745         }
746     }
747
748     if( p_playlist != NULL )
749     {
750         vlc_mutex_unlock( &p_playlist->object_lock );
751         vlc_object_release( p_playlist );
752     }
753
754     return( bEnabled );
755 }
756
757 @end
758
759 /*****************************************************************************
760  * VLCMenuExt implementation 
761  *****************************************************************************
762  * Object connected to a playlistitem which remembers the data belonging to
763  * the variable of the autogenerated menu
764  *****************************************************************************/
765 @implementation VLCMenuExt
766
767 - (id)initWithVar: (const char *)_psz_name Object: (int)i_id
768         Value: (vlc_value_t)val ofType: (int)_i_type
769 {
770     self = [super init];
771
772     if( self != nil )
773     {
774         psz_name = strdup( _psz_name );
775         i_object_id = i_id;
776         value = val;
777         i_type = _i_type;
778     }
779
780     return( self );
781 }
782
783 - (void)dealloc
784 {
785     free( psz_name );
786 }
787
788 - (char *)name
789 {
790     return psz_name;
791 }
792
793 - (int)objectID
794 {
795     return i_object_id;
796 }
797
798 - (vlc_value_t)value
799 {
800     return value;
801 }
802
803 - (int)type
804 {
805     return i_type;
806 }
807
808 @end