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