controls.m 21.6 KB
Newer Older
1
/*****************************************************************************
2
 * controls.m: MacOS X interface module
3
 *****************************************************************************
4
 * Copyright (C) 2002-2005 the VideoLAN team
5
 * $Id$
6
7
8
 *
 * Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
 *          Christophe Massiot <massiot@via.ecp.fr>
hartman's avatar
hartman committed
9
 *          Derk-Jan Hartman <hartman at videolan dot org>
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
 *****************************************************************************/

/*****************************************************************************
 * Preamble
 *****************************************************************************/
#include <stdlib.h>                                      /* malloc(), free() */
#include <sys/param.h>                                    /* for MAXPATHLEN */
#include <string.h>

#include "intf.h"
#include "vout.h"
hartman's avatar
hartman committed
35
#include "open.h"
hartman's avatar
hartman committed
36
#include "controls.h"
37
#include <vlc_osd.h>
38
39
40
41
42
43
44
45

/*****************************************************************************
 * VLCControls implementation 
 *****************************************************************************/
@implementation VLCControls

- (IBAction)play:(id)sender
{
hartman's avatar
hartman committed
46
    vlc_value_t val;
hartman's avatar
hartman committed
47
    intf_thread_t * p_intf = VLCIntf;
48
    playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
hartman's avatar
hartman committed
49
                                        FIND_ANYWHERE );
50
51
52
53
    if( p_playlist )
    {
        vlc_mutex_lock( &p_playlist->object_lock );
        if( p_playlist->i_size <= 0 )
hartman's avatar
hartman committed
54
        {
55
56
            vlc_mutex_unlock( &p_playlist->object_lock );
            vlc_object_release( p_playlist );
57
            [o_main intfOpenFileGeneric: (id)sender];
hartman's avatar
hartman committed
58
        }
59
60
61
62
63
64
        else
        {
            vlc_mutex_unlock( &p_playlist->object_lock );
            vlc_object_release( p_playlist );
        }

65
    }
66
67
    val.i_int = config_GetInt( p_intf, "key-play-pause" );
    var_Set( p_intf->p_vlc, "key-pressed", val );
68
69
70
71
}

- (IBAction)stop:(id)sender
{
72
    vlc_value_t val;
hartman's avatar
hartman committed
73
    intf_thread_t * p_intf = VLCIntf;
74
75
    val.i_int = config_GetInt( p_intf, "key-stop" );
    var_Set( p_intf->p_vlc, "key-pressed", val );
76
77
78
79
}

- (IBAction)faster:(id)sender
{
80
    vlc_value_t val;
hartman's avatar
hartman committed
81
    intf_thread_t * p_intf = VLCIntf;
82
83
    val.i_int = config_GetInt( p_intf, "key-faster" );
    var_Set( p_intf->p_vlc, "key-pressed", val );
84
85
86
87
}

- (IBAction)slower:(id)sender
{
88
    vlc_value_t val;
hartman's avatar
hartman committed
89
    intf_thread_t * p_intf = VLCIntf;
90
91
    val.i_int = config_GetInt( p_intf, "key-slower" );
    var_Set( p_intf->p_vlc, "key-pressed", val );
hartman's avatar
hartman committed
92
93
}

94
95
- (IBAction)prev:(id)sender
{
96
    vlc_value_t val;
hartman's avatar
hartman committed
97
    intf_thread_t * p_intf = VLCIntf;
98
99
    val.i_int = config_GetInt( p_intf, "key-prev" );
    var_Set( p_intf->p_vlc, "key-pressed", val );
100
101
102
103
}

- (IBAction)next:(id)sender
{
104
    vlc_value_t val;
hartman's avatar
hartman committed
105
    intf_thread_t * p_intf = VLCIntf;
106
107
    val.i_int = config_GetInt( p_intf, "key-next" );
    var_Set( p_intf->p_vlc, "key-pressed", val );
108
109
}

hartman's avatar
hartman committed
110
- (IBAction)random:(id)sender
111
{
hartman's avatar
hartman committed
112
    vlc_value_t val;
113
    intf_thread_t * p_intf = VLCIntf;
hartman's avatar
hartman committed
114
115
116
117
118
119
120
121
122
123
    playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                                       FIND_ANYWHERE );
    if( p_playlist == NULL )
    {
        return;
    }

    var_Get( p_playlist, "random", &val );
    val.b_bool = !val.b_bool;
    var_Set( p_playlist, "random", val );
124
125
    if( val.b_bool )
    {
126
        vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Random On" ) );
127
128
129
    }
    else
    {
130
        vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Random Off" ) );
131
    }
hartman's avatar
hartman committed
132

133
    p_intf->p_sys->b_playmode_update = VLC_TRUE;
bigben's avatar
bigben committed
134
    p_intf->p_sys->b_intf_update = VLC_TRUE;
hartman's avatar
hartman committed
135
136
    vlc_object_release( p_playlist );
}
137

hartman's avatar
hartman committed
138
139
140
- (IBAction)repeat:(id)sender
{
    vlc_value_t val;
141
    intf_thread_t * p_intf = VLCIntf;
142
143
144
145
146
147
148
    playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                                       FIND_ANYWHERE );
    if( p_playlist == NULL )
    {
        return;
    }

hartman's avatar
hartman committed
149
    var_Get( p_playlist, "repeat", &val );
150
    if (!val.b_bool)
151
    {
152
        var_Set( p_playlist, "loop", val );
153
    }
hartman's avatar
hartman committed
154
155
    val.b_bool = !val.b_bool;
    var_Set( p_playlist, "repeat", val );
156
157
    if( val.b_bool )
    {
158
        vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat One" ) );
159
160
161
    }
    else
    {
162
        vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat Off" ) );
bigben's avatar
bigben committed
163
    }
hartman's avatar
hartman committed
164

165
    p_intf->p_sys->b_playmode_update = VLC_TRUE;
bigben's avatar
bigben committed
166
    p_intf->p_sys->b_intf_update = VLC_TRUE;
hartman's avatar
hartman committed
167
168
169
170
171
172
    vlc_object_release( p_playlist );
}

- (IBAction)loop:(id)sender
{
    vlc_value_t val;
173
    intf_thread_t * p_intf = VLCIntf;
hartman's avatar
hartman committed
174
175
176
177
178
179
180
181
    playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                                       FIND_ANYWHERE );
    if( p_playlist == NULL )
    {
        return;
    }

    var_Get( p_playlist, "loop", &val );
182
183
184
185
    if (!val.b_bool)
    {
        var_Set( p_playlist, "repeat", val );
    }
hartman's avatar
hartman committed
186
187
    val.b_bool = !val.b_bool;
    var_Set( p_playlist, "loop", val );
188
189
    if( val.b_bool )
    {
190
        vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat All" ) );
191
192
193
    }
    else
    {
194
        vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat Off" ) );
195
    }
196

197
    p_intf->p_sys->b_playmode_update = VLC_TRUE;
bigben's avatar
bigben committed
198
    p_intf->p_sys->b_intf_update = VLC_TRUE;
199
200
201
    vlc_object_release( p_playlist );
}

202
203
- (IBAction)forward:(id)sender
{
204
    vlc_value_t val;
hartman's avatar
hartman committed
205
    intf_thread_t * p_intf = VLCIntf;
206
    val.i_int = config_GetInt( p_intf, "key-jump+short" );
207
    var_Set( p_intf->p_vlc, "key-pressed", val );
208
209
}

210
211
- (IBAction)backward:(id)sender
{
212
    vlc_value_t val;
hartman's avatar
hartman committed
213
    intf_thread_t * p_intf = VLCIntf;
214
    val.i_int = config_GetInt( p_intf, "key-jump-short" );
215
    var_Set( p_intf->p_vlc, "key-pressed", val );
216
217
}

218

219
220
- (IBAction)volumeUp:(id)sender
{
221
    vlc_value_t val;
hartman's avatar
hartman committed
222
    intf_thread_t * p_intf = VLCIntf;
223
224
    val.i_int = config_GetInt( p_intf, "key-vol-up" );
    var_Set( p_intf->p_vlc, "key-pressed", val );
225
226
    /* Manage volume status */
    [o_main manageVolumeSlider];
227
228
229
230
}

- (IBAction)volumeDown:(id)sender
{
231
    vlc_value_t val;
hartman's avatar
hartman committed
232
    intf_thread_t * p_intf = VLCIntf;
233
234
    val.i_int = config_GetInt( p_intf, "key-vol-down" );
    var_Set( p_intf->p_vlc, "key-pressed", val );
235
236
    /* Manage volume status */
    [o_main manageVolumeSlider];
237
238
239
240
}

- (IBAction)mute:(id)sender
{
241
    vlc_value_t val;
hartman's avatar
hartman committed
242
    intf_thread_t * p_intf = VLCIntf;
243
244
    val.i_int = config_GetInt( p_intf, "key-vol-mute" );
    var_Set( p_intf->p_vlc, "key-pressed", val );
245
246
    /* Manage volume status */
    [o_main manageVolumeSlider];
hartman's avatar
hartman committed
247
248
}

249
- (IBAction)volumeSliderUpdated:(id)sender
hartman's avatar
hartman committed
250
{
hartman's avatar
hartman committed
251
    intf_thread_t * p_intf = VLCIntf;
252
    audio_volume_t i_volume = (audio_volume_t)[sender intValue];
253
254
255
    int i_volume_step = 0;
    i_volume_step = config_GetInt( p_intf->p_vlc, "volume-step" );
    aout_VolumeSet( p_intf, i_volume * i_volume_step );
256
257
    /* Manage volume status */
    [o_main manageVolumeSlider];
258
259
}

260
- (IBAction)windowAction:(id)sender
261
262
{
    id o_window = [NSApp keyWindow];
263
    NSString *o_title = [sender title];
264
    NSArray *o_windows = [NSApp orderedWindows];
265
    NSEnumerator *o_enumerator = [o_windows objectEnumerator];
266
    vout_thread_t *p_vout = vlc_object_find( VLCIntf, VLC_OBJECT_VOUT,
267
                                              FIND_ANYWHERE );
268

269
    if( p_vout != NULL )
270
    {
271
        while ((o_window = [o_enumerator nextObject]))
hartman's avatar
hartman committed
272
        {
273
274
            if( [[o_window className] isEqualToString: @"VLCWindow"] )
            {
hartman's avatar
hartman committed
275
                if( [o_title isEqualToString: _NS("Half Size") ] )
276
277
278
279
280
                    [o_window scaleWindowWithFactor: 0.5];
                else if( [o_title isEqualToString: _NS("Normal Size") ] )
                    [o_window scaleWindowWithFactor: 1.0];
                else if( [o_title isEqualToString: _NS("Double Size") ] )
                    [o_window scaleWindowWithFactor: 2.0];
281
                else if( [o_title isEqualToString: _NS("Float on Top") ] )
282
                    [o_window toggleFloatOnTop];
283
                else if( [o_title isEqualToString: _NS("Fit to Screen") ] )
284
285
286
287
                {
                    if( ![o_window isZoomed] )
                        [o_window performZoom:self];
                }
288
289
290
291
                else if( [o_title isEqualToString: _NS("Snapshot") ] )
                {
                    [o_window snapshot];
                }
hartman's avatar
hartman committed
292
                else
293
                {
294
                    [o_window toggleFullscreen];
295
                }
296
                break;
297
            }
hartman's avatar
hartman committed
298
        }
299
        vlc_object_release( (vlc_object_t *)p_vout );
hartman's avatar
hartman committed
300
    }
301
    else
bigben's avatar
bigben committed
302
    {
303
304
305
306
307
        playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
                                              FIND_ANYWHERE );

        if( p_playlist && ( [o_title isEqualToString: _NS("Fullscreen")] ||
            [sender isKindOfClass:[NSButton class]] ) )
bigben's avatar
bigben committed
308
309
310
311
312
        {
            vlc_value_t val;
            var_Get( p_playlist, "fullscreen", &val );
            var_Set( p_playlist, "fullscreen", (vlc_value_t)!val.b_bool );
        }
313
        if( p_playlist ) vlc_object_release( (vlc_object_t *)p_playlist );
bigben's avatar
bigben committed
314
315
    }

hartman's avatar
hartman committed
316
317
}

hartman's avatar
* ALL:    
hartman committed
318
319
320
321
- (void)setupVarMenuItem:(NSMenuItem *)o_mi
                    target:(vlc_object_t *)p_object
                    var:(const char *)psz_variable
                    selector:(SEL)pf_callback
322
{
hartman's avatar
* ALL:    
hartman committed
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
    vlc_value_t val, text;
    int i_type = var_Type( p_object, psz_variable );

    switch( i_type & VLC_VAR_TYPE )
    {
    case VLC_VAR_VOID:
    case VLC_VAR_BOOL:
    case VLC_VAR_VARIABLE:
    case VLC_VAR_STRING:
    case VLC_VAR_INTEGER:
        break;
    default:
        /* Variable doesn't exist or isn't handled */
        return;
    }
    
    /* Make sure we want to display the variable */
    if( i_type & VLC_VAR_HASCHOICE )
    {
        var_Change( p_object, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL );
        if( val.i_int == 0 ) return;
        if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
            return;
    }
    
    /* Get the descriptive name of the variable */
    var_Change( p_object, psz_variable, VLC_VAR_GETTEXT, &text, NULL );
hartman's avatar
hartman committed
350
    [o_mi setTitle: [[VLCMain sharedInstance] localizedString: text.psz_string ?
hartman's avatar
* ALL:    
hartman committed
351
                                        text.psz_string : strdup( psz_variable ) ]];
352

hartman's avatar
* ALL:    
hartman committed
353
354
    var_Get( p_object, psz_variable, &val );
    if( i_type & VLC_VAR_HASCHOICE )
355
    {
hartman's avatar
* ALL:    
hartman committed
356
357
358
359
360
361
362
        NSMenu *o_menu = [o_mi submenu];

        [self setupVarMenu: o_menu forMenuItem: o_mi target:p_object
                        var:psz_variable selector:pf_callback];
        
        if( text.psz_string ) free( text.psz_string );
        return;
363
    }
hartman's avatar
* ALL:    
hartman committed
364
365
366

    VLCMenuExt *o_data;
    switch( i_type & VLC_VAR_TYPE )
367
    {
hartman's avatar
* ALL:    
hartman committed
368
369
370
371
372
373
374
375
376
377
    case VLC_VAR_VOID:
        o_data = [[VLCMenuExt alloc] initWithVar: psz_variable Object: p_object->i_object_id
                Value: val ofType: i_type];
        [o_mi setRepresentedObject: [NSValue valueWithPointer:[o_data retain]]];
        break;

    case VLC_VAR_BOOL:
        o_data = [[VLCMenuExt alloc] initWithVar: psz_variable Object: p_object->i_object_id
                Value: val ofType: i_type];
        [o_mi setRepresentedObject: [NSValue valueWithPointer:[o_data retain]]];
378
379
        if( !( i_type & VLC_VAR_ISCOMMAND ) )
            [o_mi setState: val.b_bool ? TRUE : FALSE ];
hartman's avatar
* ALL:    
hartman committed
380
381
382
383
384
        break;

    default:
        if( text.psz_string ) free( text.psz_string );
        return;
385
    }
hartman's avatar
* ALL:    
hartman committed
386

387
    if( ( i_type & VLC_VAR_TYPE ) == VLC_VAR_STRING ) free( val.psz_string );
hartman's avatar
* ALL:    
hartman committed
388
    if( text.psz_string ) free( text.psz_string );
389
}
390

hartman's avatar
* ALL:    
hartman committed
391
392
393
394
395
396

- (void)setupVarMenu:(NSMenu *)o_menu
                    forMenuItem: (NSMenuItem *)o_parent
                    target:(vlc_object_t *)p_object
                    var:(const char *)psz_variable
                    selector:(SEL)pf_callback
397
{
hartman's avatar
* ALL:    
hartman committed
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
    vlc_value_t val, val_list, text_list;
    int i_type, i, i_nb_items;

    /* remove previous items */
    i_nb_items = [o_menu numberOfItems];
    for( i = 0; i < i_nb_items; i++ )
    {
        [o_menu removeItemAtIndex: 0];
    }

    /* Check the type of the object variable */
    i_type = var_Type( p_object, psz_variable );

    /* Make sure we want to display the variable */
    if( i_type & VLC_VAR_HASCHOICE )
    {
        var_Change( p_object, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL );
        if( val.i_int == 0 ) return;
        if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
            return;
    }
    else
    {
        return;
    }

    switch( i_type & VLC_VAR_TYPE )
425
    {
hartman's avatar
* ALL:    
hartman committed
426
427
428
429
430
431
432
433
434
435
    case VLC_VAR_VOID:
    case VLC_VAR_BOOL:
    case VLC_VAR_VARIABLE:
    case VLC_VAR_STRING:
    case VLC_VAR_INTEGER:
        break;
    default:
        /* Variable doesn't exist or isn't handled */
        return;
    }
436

hartman's avatar
* ALL:    
hartman committed
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
    if( var_Get( p_object, psz_variable, &val ) < 0 )
    {
        return;
    }

    if( var_Change( p_object, psz_variable, VLC_VAR_GETLIST,
                    &val_list, &text_list ) < 0 )
    {
        if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
        return;
    }

    /* make (un)sensitive */
    [o_parent setEnabled: ( val_list.p_list->i_count > 1 )];

    for( i = 0; i < val_list.p_list->i_count; i++ )
    {
        vlc_value_t another_val;
        NSMenuItem * o_lmi;
        NSString *o_title = @"";
        VLCMenuExt *o_data;

        switch( i_type & VLC_VAR_TYPE )
460
        {
hartman's avatar
* ALL:    
hartman committed
461
462
463
464
        case VLC_VAR_STRING:
            another_val.psz_string =
                strdup(val_list.p_list->p_values[i].psz_string);

hartman's avatar
hartman committed
465
            o_title = [[VLCMain sharedInstance] localizedString: text_list.p_list->p_values[i].psz_string ?
hartman's avatar
* ALL:    
hartman committed
466
467
468
469
470
471
472
473
                text_list.p_list->p_values[i].psz_string : val_list.p_list->p_values[i].psz_string ];

            o_lmi = [o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""];
            o_data = [[VLCMenuExt alloc] initWithVar: strdup(psz_variable) Object: p_object->i_object_id
                    Value: another_val ofType: i_type];
            [o_lmi setRepresentedObject: [NSValue valueWithPointer:[o_data retain]]];
            [o_lmi setTarget: self];
            
474
            if( !strcmp( val.psz_string, val_list.p_list->p_values[i].psz_string ) && !( i_type & VLC_VAR_ISCOMMAND ) )
hartman's avatar
* ALL:    
hartman committed
475
476
477
478
479
480
481
                [o_lmi setState: TRUE ];

            break;

        case VLC_VAR_INTEGER:

             o_title = text_list.p_list->p_values[i].psz_string ?
hartman's avatar
hartman committed
482
                                 [[VLCMain sharedInstance] localizedString: strdup( text_list.p_list->p_values[i].psz_string )] :
hartman's avatar
* ALL:    
hartman committed
483
484
485
486
487
488
489
490
491
                                 [NSString stringWithFormat: @"%d",
                                 val_list.p_list->p_values[i].i_int];

            o_lmi = [[o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""] retain ];
            o_data = [[VLCMenuExt alloc] initWithVar: strdup(psz_variable) Object: p_object->i_object_id
                    Value: val_list.p_list->p_values[i] ofType: i_type];
            [o_lmi setRepresentedObject: [NSValue valueWithPointer:[ o_data retain]]];
            [o_lmi setTarget: self];

492
            if( val_list.p_list->p_values[i].i_int == val.i_int && !( i_type & VLC_VAR_ISCOMMAND ) )
hartman's avatar
* ALL:    
hartman committed
493
494
495
496
497
                [o_lmi setState: TRUE ];
            break;

        default:
          break;
498
499
        }
    }
hartman's avatar
* ALL:    
hartman committed
500
501
    
    /* clean up everything */
502
    if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
hartman's avatar
* ALL:    
hartman committed
503
504
505
506
507
508
509
    var_Change( p_object, psz_variable, VLC_VAR_FREELIST, &val_list, &text_list );
}

- (IBAction)toggleVar:(id)sender
{
    NSMenuItem *o_mi = (NSMenuItem *)sender;
    VLCMenuExt *o_data = [[o_mi representedObject] pointerValue];
510
511
512
513
514
515
516
517
    [NSThread detachNewThreadSelector: @selector(toggleVarThread:)
        toTarget: self withObject: o_data];

    return;
}

- (int)toggleVarThread: (id)_o_data
{
hartman's avatar
* ALL:    
hartman committed
518
    vlc_object_t *p_object;
519
520
521
    NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
    VLCMenuExt *o_data = (VLCMenuExt *)_o_data;

hartman's avatar
hartman committed
522
    vlc_thread_set_priority( VLCIntf , VLC_THREAD_PRIORITY_LOW );
hartman's avatar
* ALL:    
hartman committed
523

hartman's avatar
hartman committed
524
    p_object = (vlc_object_t *)vlc_object_get( VLCIntf,
hartman's avatar
* ALL:    
hartman committed
525
526
                                    [o_data objectID] );

527
528
529
530
531
532
533
534
535
    if( p_object != NULL )
    {
        var_Set( p_object, strdup([o_data name]), [o_data value] );
        vlc_object_release( p_object );
        [o_pool release];
        return VLC_TRUE;
    }
    [o_pool release];
    return VLC_EGENERIC;
536
537
}

538
539
540
541
542
543
544
@end

@implementation VLCControls (NSMenuValidation)
 
- (BOOL)validateMenuItem:(NSMenuItem *)o_mi
{
    BOOL bEnabled = TRUE;
hartman's avatar
hartman committed
545
    vlc_value_t val;
hartman's avatar
hartman committed
546
    intf_thread_t * p_intf = VLCIntf;
547
548
549
550
551
552
553
    playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                                       FIND_ANYWHERE );

    if( p_playlist != NULL )
    {
        vlc_mutex_lock( &p_playlist->object_lock );
    }
554
    else return FALSE;
555

556
557
#define p_input p_playlist->p_input

hartman's avatar
hartman committed
558
    if( [[o_mi title] isEqualToString: _NS("Faster")] ||
559
560
        [[o_mi title] isEqualToString: _NS("Slower")] )
    {
561
        if( p_input != NULL )
562
        {
563
            bEnabled = p_input->input.b_can_pace_control;
564
565
566
567
568
569
570
571
        }
        else
        {
            bEnabled = FALSE;
        }
    }
    else if( [[o_mi title] isEqualToString: _NS("Stop")] )
    {
572
        if( p_input == NULL )
573
574
575
        {
            bEnabled = FALSE;
        }
576
		[o_main setupMenus]; /* Make sure input menu is up to date */
577
    }
Jon Lech Johansen's avatar
Jon Lech Johansen committed
578
    else if( [[o_mi title] isEqualToString: _NS("Previous")] ||
579
580
581
582
             [[o_mi title] isEqualToString: _NS("Next")] )
    {
            bEnabled = p_playlist->i_size > 1;
    }
583
    else if( [[o_mi title] isEqualToString: _NS("Random")] )
584
    {
hartman's avatar
hartman committed
585
586
587
588
589
        int i_state;
        var_Get( p_playlist, "random", &val );
        i_state = val.b_bool ? NSOnState : NSOffState;
        [o_mi setState: i_state];
    }
590
    else if( [[o_mi title] isEqualToString: _NS("Repeat One")] )
hartman's avatar
hartman committed
591
592
593
594
595
596
    {
        int i_state;
        var_Get( p_playlist, "repeat", &val );
        i_state = val.b_bool ? NSOnState : NSOffState;
        [o_mi setState: i_state];
    }
597
    else if( [[o_mi title] isEqualToString: _NS("Repeat All")] )
hartman's avatar
hartman committed
598
599
600
601
    {
        int i_state;
        var_Get( p_playlist, "loop", &val );
        i_state = val.b_bool ? NSOnState : NSOffState;
602
603
        [o_mi setState: i_state];
    }
604
605
606
    else if( [[o_mi title] isEqualToString: _NS("Step Forward")] ||
             [[o_mi title] isEqualToString: _NS("Step Backward")] )
    {
607
        if( p_input != NULL )
608
        {
609
            var_Get( p_input, "seekable", &val);
610
            bEnabled = val.b_bool;
611
612
        }
    }
613
614
615
    else if( [[o_mi title] isEqualToString: _NS("Mute")] ) 
    {
        [o_mi setState: p_intf->p_sys->b_mute ? NSOnState : NSOffState];
616
		[o_main setupMenus]; /* Make sure audio menu is up to date */
617
    }
bigben's avatar
bigben committed
618
    else if( [[o_mi title] isEqualToString: _NS("Half Size")] ||
619
                [[o_mi title] isEqualToString: _NS("Normal Size")] ||
hartman's avatar
hartman committed
620
                [[o_mi title] isEqualToString: _NS("Double Size")] ||
621
                [[o_mi title] isEqualToString: _NS("Fit to Screen")] ||
622
                [[o_mi title] isEqualToString: _NS("Snapshot")] ||
623
                [[o_mi title] isEqualToString: _NS("Fullscreen")] ||
624
                [[o_mi title] isEqualToString: _NS("Float on Top")] )
625
    {
626
        id o_window;
627
        NSArray *o_windows = [NSApp orderedWindows];
628
629
630
        NSEnumerator *o_enumerator = [o_windows objectEnumerator];
        bEnabled = FALSE;
        
631
632
633
        vout_thread_t   *p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
                                              FIND_ANYWHERE );
        if( p_vout != NULL )
634
        {
635
            if( [[o_mi title] isEqualToString: _NS("Float on Top")] )
636
637
638
639
640
            {
                var_Get( p_vout, "video-on-top", &val );
                [o_mi setState: val.b_bool ?  NSOnState : NSOffState];
            }

641
            while( (o_window = [o_enumerator nextObject]))
642
            {
643
644
645
646
647
                if( [[o_window className] isEqualToString: @"VLCWindow"] )
                {
                    bEnabled = TRUE;
                    break;
                }
648
            }
649
            vlc_object_release( (vlc_object_t *)p_vout );
650
        }
651
        else if( [[o_mi title] isEqualToString: _NS("Fullscreen")] )
bigben's avatar
bigben committed
652
        {
653
            var_Get( p_playlist, "fullscreen", &val );
bigben's avatar
bigben committed
654
655
656
            [o_mi setState: val.b_bool];
            bEnabled = TRUE;
        }
657
		[o_main setupMenus]; /* Make sure video menu is up to date */
bigben's avatar
bigben committed
658
659
    }

660
661
    vlc_mutex_unlock( &p_playlist->object_lock );
    vlc_object_release( p_playlist );
662

663
664
665
666
    return( bEnabled );
}

@end
hartman's avatar
* ALL:    
hartman committed
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694

/*****************************************************************************
 * VLCMenuExt implementation 
 *****************************************************************************
 * Object connected to a playlistitem which remembers the data belonging to
 * the variable of the autogenerated menu
 *****************************************************************************/
@implementation VLCMenuExt

- (id)initWithVar: (const char *)_psz_name Object: (int)i_id
        Value: (vlc_value_t)val ofType: (int)_i_type
{
    self = [super init];

    if( self != nil )
    {
        psz_name = strdup( _psz_name );
        i_object_id = i_id;
        value = val;
        i_type = _i_type;
    }

    return( self );
}

- (void)dealloc
{
    free( psz_name );
695
    [super dealloc];
hartman's avatar
* ALL:    
hartman committed
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
}

- (char *)name
{
    return psz_name;
}

- (int)objectID
{
    return i_object_id;
}

- (vlc_value_t)value
{
    return value;
}

- (int)type
{
    return i_type;
}

@end