controls.m 21.5 KB
Newer Older
1
/*****************************************************************************
2
 * controls.m: MacOS X interface module
3
 *****************************************************************************
4
 * Copyright (C) 2002-2005 VideoLAN
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 <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 All" ) );
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 One" ) );
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
207
    val.i_int = config_GetInt( p_intf, "key-jump+10sec" );
    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
215
    val.i_int = config_GetInt( p_intf, "key-jump-10sec" );
    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
253
    audio_volume_t i_volume = (audio_volume_t)[sender intValue];
    aout_VolumeSet( p_intf, i_volume * AOUT_VOLUME_STEP );
254
255
    /* Manage volume status */
    [o_main manageVolumeSlider];
256
257
}

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

267
    if( p_vout != NULL )
268
    {
269
        while ((o_window = [o_enumerator nextObject]))
hartman's avatar
hartman committed
270
        {
271
272
            if( [[o_window className] isEqualToString: @"VLCWindow"] )
            {
hartman's avatar
hartman committed
273
                if( [o_title isEqualToString: _NS("Half Size") ] )
274
275
276
277
278
                    [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];
279
                else if( [o_title isEqualToString: _NS("Float on Top") ] )
280
                    [o_window toggleFloatOnTop];
281
                else if( [o_title isEqualToString: _NS("Fit to Screen") ] )
282
283
284
285
                {
                    if( ![o_window isZoomed] )
                        [o_window performZoom:self];
                }
286
287
288
289
                else if( [o_title isEqualToString: _NS("Snapshot") ] )
                {
                    [o_window snapshot];
                }
hartman's avatar
hartman committed
290
                else
291
                {
292
                    [o_window toggleFullscreen];
293
                }
294
                break;
295
            }
hartman's avatar
hartman committed
296
        }
297
        vlc_object_release( (vlc_object_t *)p_vout );
hartman's avatar
hartman committed
298
    }
299
    else
bigben's avatar
bigben committed
300
    {
301
302
303
304
305
        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
306
307
308
309
310
        {
            vlc_value_t val;
            var_Get( p_playlist, "fullscreen", &val );
            var_Set( p_playlist, "fullscreen", (vlc_value_t)!val.b_bool );
        }
311
        if( p_playlist ) vlc_object_release( (vlc_object_t *)p_playlist );
bigben's avatar
bigben committed
312
313
    }

hartman's avatar
hartman committed
314
315
}

hartman's avatar
* ALL:    
hartman committed
316
317
318
319
- (void)setupVarMenuItem:(NSMenuItem *)o_mi
                    target:(vlc_object_t *)p_object
                    var:(const char *)psz_variable
                    selector:(SEL)pf_callback
320
{
hartman's avatar
* ALL:    
hartman committed
321
322
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
    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
348
    [o_mi setTitle: [[VLCMain sharedInstance] localizedString: text.psz_string ?
hartman's avatar
* ALL:    
hartman committed
349
                                        text.psz_string : strdup( psz_variable ) ]];
350

hartman's avatar
* ALL:    
hartman committed
351
352
    var_Get( p_object, psz_variable, &val );
    if( i_type & VLC_VAR_HASCHOICE )
353
    {
hartman's avatar
* ALL:    
hartman committed
354
355
356
357
358
359
360
        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;
361
    }
hartman's avatar
* ALL:    
hartman committed
362
363
364

    VLCMenuExt *o_data;
    switch( i_type & VLC_VAR_TYPE )
365
    {
hartman's avatar
* ALL:    
hartman committed
366
367
368
369
370
371
372
373
374
375
    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]]];
376
377
        if( !( i_type & VLC_VAR_ISCOMMAND ) )
            [o_mi setState: val.b_bool ? TRUE : FALSE ];
hartman's avatar
* ALL:    
hartman committed
378
379
380
381
382
        break;

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

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

hartman's avatar
* ALL:    
hartman committed
389
390
391
392
393
394

- (void)setupVarMenu:(NSMenu *)o_menu
                    forMenuItem: (NSMenuItem *)o_parent
                    target:(vlc_object_t *)p_object
                    var:(const char *)psz_variable
                    selector:(SEL)pf_callback
395
{
hartman's avatar
* ALL:    
hartman committed
396
397
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
    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 )
423
    {
hartman's avatar
* ALL:    
hartman committed
424
425
426
427
428
429
430
431
432
433
    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;
    }
434

hartman's avatar
* ALL:    
hartman committed
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
    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 )
458
        {
hartman's avatar
* ALL:    
hartman committed
459
460
461
462
        case VLC_VAR_STRING:
            another_val.psz_string =
                strdup(val_list.p_list->p_values[i].psz_string);

hartman's avatar
hartman committed
463
            o_title = [[VLCMain sharedInstance] localizedString: text_list.p_list->p_values[i].psz_string ?
hartman's avatar
* ALL:    
hartman committed
464
465
466
467
468
469
470
471
                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];
            
472
            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
473
474
475
476
477
478
479
                [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
480
                                 [[VLCMain sharedInstance] localizedString: strdup( text_list.p_list->p_values[i].psz_string )] :
hartman's avatar
* ALL:    
hartman committed
481
482
483
484
485
486
487
488
489
                                 [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];

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

        default:
          break;
496
497
        }
    }
hartman's avatar
* ALL:    
hartman committed
498
499
    
    /* clean up everything */
500
    if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
hartman's avatar
* ALL:    
hartman committed
501
502
503
504
505
506
507
    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];
508
509
510
511
512
513
514
515
    [NSThread detachNewThreadSelector: @selector(toggleVarThread:)
        toTarget: self withObject: o_data];

    return;
}

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

hartman's avatar
hartman committed
520
    vlc_thread_set_priority( VLCIntf , VLC_THREAD_PRIORITY_LOW );
hartman's avatar
* ALL:    
hartman committed
521

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

525
526
527
528
529
530
531
532
533
    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;
534
535
}

536
537
538
539
540
541
542
@end

@implementation VLCControls (NSMenuValidation)
 
- (BOOL)validateMenuItem:(NSMenuItem *)o_mi
{
    BOOL bEnabled = TRUE;
hartman's avatar
hartman committed
543
    vlc_value_t val;
hartman's avatar
hartman committed
544
    intf_thread_t * p_intf = VLCIntf;
545
546
547
548
549
550
551
    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 );
    }
552
    else return FALSE;
553

554
555
#define p_input p_playlist->p_input

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

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

658
659
    vlc_mutex_unlock( &p_playlist->object_lock );
    vlc_object_release( p_playlist );
660

661
662
663
664
    return( bEnabled );
}

@end
hartman's avatar
* ALL:    
hartman committed
665
666
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
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715

/*****************************************************************************
 * 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 );
}

- (char *)name
{
    return psz_name;
}

- (int)objectID
{
    return i_object_id;
}

- (vlc_value_t)value
{
    return value;
}

- (int)type
{
    return i_type;
}

@end