controls.m 23.3 KB
Newer Older
1
2
3
/*****************************************************************************
 * controls.m: MacOS X interface plugin
 *****************************************************************************
hartman's avatar
hartman committed
4
 * Copyright (C) 2002-2003 VideoLAN
hartman's avatar
hartman committed
5
 * $Id: controls.m,v 1.45 2003/07/09 01:31:25 hartman Exp $
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 <thedj@users.sourceforge.net>
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
38
39
40
41
42
43
44
45

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

- (IBAction)play:(id)sender
{
    intf_thread_t * p_intf = [NSApp getIntf];
46

47
48
49
50
51
52
53
    playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                                       FIND_ANYWHERE );
    if( p_playlist == NULL )
    {
        return;
    }

54
    if( playlist_IsPlaying( p_playlist ) )
55
    {
56
        playlist_Pause( p_playlist );
57
        vlc_object_release( p_playlist );
58
59
60
    }
    else
    {
61
        if( !playlist_IsEmpty( p_playlist ) )
hartman's avatar
hartman committed
62
63
        {
            playlist_Play( p_playlist );
64
            vlc_object_release( p_playlist );
hartman's avatar
hartman committed
65
66
67
        }
        else
        {
68
            vlc_object_release( p_playlist );
hartman's avatar
hartman committed
69
            [o_open openFileGeneric: nil];
hartman's avatar
hartman committed
70
        }
71
72
73
74
75
76
    }
}

- (IBAction)stop:(id)sender
{
    intf_thread_t * p_intf = [NSApp getIntf];
77

78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
    playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                                       FIND_ANYWHERE );
    if( p_playlist == NULL )
    {
        return;
    }

    playlist_Stop( p_playlist );
    vlc_object_release( p_playlist );
}

- (IBAction)faster:(id)sender
{
    intf_thread_t * p_intf = [NSApp getIntf];

93
94
95
    playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                                       FIND_ANYWHERE );
    if( p_playlist == NULL )
96
97
98
99
    {
        return;
    }

100
101
102
103
104
105
106
107
    vlc_mutex_lock( &p_playlist->object_lock );
    if( p_playlist->p_input != NULL )
    {
        input_SetStatus( p_playlist->p_input, INPUT_STATUS_FASTER );
    } 
    vlc_mutex_unlock( &p_playlist->object_lock );

    vlc_object_release( p_playlist );
108
109
110
111
112
113
}

- (IBAction)slower:(id)sender
{
    intf_thread_t * p_intf = [NSApp getIntf];

114
115
116
    playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                                       FIND_ANYWHERE );
    if( p_playlist == NULL )
117
118
119
120
    {
        return;
    }

121
122
    vlc_mutex_lock( &p_playlist->object_lock );
    if( p_playlist->p_input != NULL )
hartman's avatar
hartman committed
123
    {
124
        input_SetStatus( p_playlist->p_input, INPUT_STATUS_SLOWER );
hartman's avatar
hartman committed
125
    }
126
    vlc_mutex_unlock( &p_playlist->object_lock );
hartman's avatar
hartman committed
127

128
    vlc_object_release( p_playlist );
hartman's avatar
hartman committed
129
130
}

131
132
- (IBAction)prev:(id)sender
{
hartman's avatar
hartman committed
133
    vlc_value_t val;
134
    intf_thread_t * p_intf = [NSApp getIntf];
135

136
137
    playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                                       FIND_ANYWHERE );
138
139
140
141
142
143
144
145
146
147
148
149
150
    if( p_playlist == NULL )
    {
        return;
    }

    vlc_mutex_lock( &p_playlist->object_lock );

    if( p_playlist->p_input == NULL )
    {
        vlc_mutex_unlock( &p_playlist->object_lock );
        vlc_object_release( p_playlist );  
        return;
    }
151

152
    vlc_mutex_lock( &p_playlist->p_input->stream.stream_lock );
153

154
#define p_area p_playlist->p_input->stream.p_selected_area
hartman's avatar
hartman committed
155
    if( p_area->i_part > 0 && p_area->i_part_nb > 1)
156
    {
hartman's avatar
hartman committed
157
158
159
160
161
162
163
        vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
        vlc_mutex_unlock( &p_playlist->object_lock );
        var_Get( p_playlist->p_input, "prev-chapter", &val );
        var_Set( p_playlist->p_input, "prev-chapter", val );
    }
    else if( p_area->i_id > 1 )
    {
164
165
        vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
        vlc_mutex_unlock( &p_playlist->object_lock );
hartman's avatar
hartman committed
166
167
        var_Get( p_playlist->p_input, "prev-title", &val );
        var_Set( p_playlist->p_input, "prev-title", val );
168
169
170
    }
    else
    {
171
172
173
        vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
        vlc_mutex_unlock( &p_playlist->object_lock );
        playlist_Prev( p_playlist );
174
    }
175
176
177
#undef p_area

    vlc_object_release( p_playlist );
178
179
180
181
}

- (IBAction)next:(id)sender
{
hartman's avatar
hartman committed
182
    vlc_value_t val;
183
    intf_thread_t * p_intf = [NSApp getIntf];
184

185
186
    playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                                       FIND_ANYWHERE );
187
188
189
190
    if( p_playlist == NULL )
    {
        return;
    }
hartman's avatar
hartman committed
191
    
192
    vlc_mutex_lock( &p_playlist->object_lock );
193

194
195
196
197
198
199
200
201
202
203
    if( p_playlist->p_input == NULL )
    {
        vlc_mutex_unlock( &p_playlist->object_lock );
        vlc_object_release( p_playlist );  
        return;
    }

    vlc_mutex_lock( &p_playlist->p_input->stream.stream_lock );

#define p_area p_playlist->p_input->stream.p_selected_area
hartman's avatar
hartman committed
204
    if( p_area->i_part < p_area->i_part_nb && p_area->i_part_nb > 1 )
205
    {
hartman's avatar
hartman committed
206
207
208
209
210
        vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
        vlc_mutex_unlock( &p_playlist->object_lock );
        var_Get( p_playlist->p_input, "next-chapter", &val );
        var_Set( p_playlist->p_input, "next-chapter", val );
    }
211
    else if( p_area->i_id < p_playlist->p_input->stream.i_area_nb && p_playlist->p_input->stream.i_area_nb > 1 )
hartman's avatar
hartman committed
212
    {
213
214
        vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
        vlc_mutex_unlock( &p_playlist->object_lock );
hartman's avatar
hartman committed
215
216
        var_Get( p_playlist->p_input, "next-title", &val );
        var_Set( p_playlist->p_input, "next-title", val );
217
218
219
    }
    else
    {
220
221
222
        vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
        vlc_mutex_unlock( &p_playlist->object_lock );
        playlist_Next( p_playlist );
223
    }
224
225
226
#undef p_area

    vlc_object_release( p_playlist );
227
228
229
230
231
}

- (IBAction)loop:(id)sender
{
    intf_thread_t * p_intf = [NSApp getIntf];
232

233
234
235
236
237
238
239
    playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                                       FIND_ANYWHERE );
    if( p_playlist == NULL )
    {
        return;
    }

240
241
    config_PutInt( p_playlist, "loop",
                   !config_GetInt( p_playlist, "loop" ) );
242
243
244
245

    vlc_object_release( p_playlist );
}

246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
- (IBAction)forward:(id)sender
{
    intf_thread_t * p_intf = [NSApp getIntf];
    playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                                       FIND_ANYWHERE );
    if( p_playlist == NULL || p_playlist->p_input == NULL )
    {
        if ( p_playlist != NULL ) vlc_object_release( p_playlist );
        return;
    }

    input_Seek( p_playlist->p_input, 5, INPUT_SEEK_SECONDS | INPUT_SEEK_CUR );
    vlc_object_release( p_playlist );
}

- (IBAction)backward:(id)sender
{
    intf_thread_t * p_intf = [NSApp getIntf];
    playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                                       FIND_ANYWHERE );
    if( p_playlist == NULL || p_playlist->p_input == NULL )
    {
        if ( p_playlist != NULL ) vlc_object_release( p_playlist );
        return;
    }

    input_Seek( p_playlist->p_input, -5, INPUT_SEEK_SECONDS | INPUT_SEEK_CUR );
    vlc_object_release( p_playlist );
}

276
277
278
- (IBAction)volumeUp:(id)sender
{
    intf_thread_t * p_intf = [NSApp getIntf];
279

280
281
282
    if( p_intf->p_sys->b_mute )
    {
        [self mute: nil];
283
    }
284

hartman's avatar
hartman committed
285
286
    aout_VolumeUp( p_intf, 1, NULL );

287
    [self updateVolumeSlider];
288
289
290
291
292
}

- (IBAction)volumeDown:(id)sender
{
    intf_thread_t * p_intf = [NSApp getIntf];
293

294
295
296
    if( p_intf->p_sys->b_mute )
    {
        [self mute: nil];
297
    }
hartman's avatar
hartman committed
298
299
    
    aout_VolumeDown( p_intf, 1, NULL );
300
301

    [self updateVolumeSlider];
302
303
304
305
}

- (IBAction)mute:(id)sender
{
306
    intf_thread_t * p_intf = [NSApp getIntf];
307
    audio_volume_t i_volume;
308

309
310
    aout_VolumeMute( p_intf, &i_volume );
    p_intf->p_sys->b_mute = ( i_volume == 0 );
311

312
    [self updateVolumeSlider];
hartman's avatar
hartman committed
313
314
}

315
- (IBAction)volumeSliderUpdated:(id)sender
hartman's avatar
hartman committed
316
317
{
    intf_thread_t * p_intf = [NSApp getIntf];
318
    audio_volume_t i_volume = (audio_volume_t)[sender intValue];
hartman's avatar
hartman committed
319

320
    aout_VolumeSet( p_intf, i_volume * AOUT_VOLUME_STEP );
hartman's avatar
hartman committed
321
322
}

323
- (void)updateVolumeSlider
hartman's avatar
hartman committed
324
325
{
    intf_thread_t * p_intf = [NSApp getIntf];
326
    audio_volume_t i_volume;
327

328
    aout_VolumeGet( p_intf, &i_volume );
329

330
    [o_volumeslider setFloatValue: (float)(i_volume / AOUT_VOLUME_STEP)]; 
331
332
}

333
- (IBAction)windowAction:(id)sender
334
335
{
    id o_window = [NSApp keyWindow];
336
    NSString *o_title = [sender title];
337
338
    NSArray *o_windows = [NSApp windows];
    NSEnumerator *o_enumerator = [o_windows objectEnumerator];
339
340
    vout_thread_t   *p_vout = vlc_object_find( [NSApp getIntf], VLC_OBJECT_VOUT,
                                              FIND_ANYWHERE );
341

342
    if( p_vout != NULL )
343
    {
344
        while ((o_window = [o_enumerator nextObject]))
hartman's avatar
hartman committed
345
        {
346
347
348
349
350
351
352
353
354
355
356
357
            if( [[o_window className] isEqualToString: @"VLCWindow"] )
            {
                if( [o_title isEqualToString: _NS("Fullscreen") ] )
                    [o_window toggleFullscreen];
                else if( [o_title isEqualToString: _NS("Half Size") ] )
                    [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];
                else if( [o_title isEqualToString: _NS("Float On Top") ] )
                    [o_window toggleFloatOnTop];
358
359
360
361
362
                else if( [o_title isEqualToString: _NS("Fit To Screen") ] )
                {
                    if( ![o_window isZoomed] )
                        [o_window performZoom:self];
                }
363
            }
hartman's avatar
hartman committed
364
        }
365
        vlc_object_release( (vlc_object_t *)p_vout );
hartman's avatar
hartman committed
366
367
368
    }
}

hartman's avatar
* ALL:    
hartman committed
369
370
371
372
- (void)setupVarMenuItem:(NSMenuItem *)o_mi
                    target:(vlc_object_t *)p_object
                    var:(const char *)psz_variable
                    selector:(SEL)pf_callback
373
{
hartman's avatar
* ALL:    
hartman committed
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
    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 );
    [o_mi setTitle: [NSApp localizedString: text.psz_string ?
                                        text.psz_string : strdup( psz_variable ) ]];
403

hartman's avatar
* ALL:    
hartman committed
404
405
    var_Get( p_object, psz_variable, &val );
    if( i_type & VLC_VAR_HASCHOICE )
406
    {
hartman's avatar
* ALL:    
hartman committed
407
408
409
410
411
412
413
        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;
414
    }
hartman's avatar
* ALL:    
hartman committed
415
416
417

    VLCMenuExt *o_data;
    switch( i_type & VLC_VAR_TYPE )
418
    {
hartman's avatar
* ALL:    
hartman committed
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
    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]]];
        [o_mi setState: val.b_bool ? TRUE : FALSE ];
        break;

    default:
        if( text.psz_string ) free( text.psz_string );
        return;
435
    }
hartman's avatar
* ALL:    
hartman committed
436
437
438

    if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
    if( text.psz_string ) free( text.psz_string );
439
}
440

hartman's avatar
* ALL:    
hartman committed
441
442
443
444
445
446

- (void)setupVarMenu:(NSMenu *)o_menu
                    forMenuItem: (NSMenuItem *)o_parent
                    target:(vlc_object_t *)p_object
                    var:(const char *)psz_variable
                    selector:(SEL)pf_callback
447
{
hartman's avatar
* ALL:    
hartman committed
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
    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 )
475
    {
hartman's avatar
* ALL:    
hartman committed
476
477
478
479
480
481
482
483
484
485
    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;
    }
486

hartman's avatar
* ALL:    
hartman committed
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
    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 )
510
        {
hartman's avatar
* ALL:    
hartman committed
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
        case VLC_VAR_VARIABLE:

            /* This is causing crashes for the moment.
            o_title = [NSApp localizedString: text_list.p_list->p_values[i].psz_string ?
                text_list.p_list->p_values[i].psz_string : val_list.p_list->p_values[i].psz_string ];
            
            o_data = [[VLCMenuExt alloc] initWithVar: strdup(psz_variable) Object: p_object->i_object_id
                Value: val ofType: i_type];
            [o_lmi setRepresentedObject: [NSValue valueWithPointer:[o_data retain]]];

            // Create a submenu
            NSMenu *o_menu = [o_lmi submenu];

            [self setupVarMenu: o_menu forMenuItem: o_lmi target:p_object
                            var:psz_variable selector:pf_callback];
*/
            return;

        case VLC_VAR_STRING:
            another_val.psz_string =
                strdup(val_list.p_list->p_values[i].psz_string);

            o_title = [NSApp localizedString: text_list.p_list->p_values[i].psz_string ?
                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];
            
            if( !strcmp( val.psz_string, val_list.p_list->p_values[i].psz_string ) )
                [o_lmi setState: TRUE ];

            break;

        case VLC_VAR_INTEGER:

             o_title = text_list.p_list->p_values[i].psz_string ?
                                 [NSApp localizedString: strdup( text_list.p_list->p_values[i].psz_string )] :
                                 [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];

            if( val_list.p_list->p_values[i].i_int == val.i_int )
                [o_lmi setState: TRUE ];
            break;

        default:
          break;
566
567
        }
    }
hartman's avatar
* ALL:    
hartman committed
568
569
570
571
572
573
574
575
576
577
    
    /* clean up everything */
    if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
    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];
578
579
580
581
582
583
584
585
    [NSThread detachNewThreadSelector: @selector(toggleVarThread:)
        toTarget: self withObject: o_data];

    return;
}

- (int)toggleVarThread: (id)_o_data
{
hartman's avatar
* ALL:    
hartman committed
586
    vlc_object_t *p_object;
587
588
589
590
    NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
    VLCMenuExt *o_data = (VLCMenuExt *)_o_data;

    vlc_thread_set_priority( [NSApp getIntf] , VLC_THREAD_PRIORITY_LOW );
hartman's avatar
* ALL:    
hartman committed
591
592
593
594

    p_object = (vlc_object_t *)vlc_object_get( [NSApp getIntf],
                                    [o_data objectID] );

595
596
597
598
599
600
601
602
603
    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;
604
605
}

606
607
608
609
610
611
612
613
614
@end

@implementation VLCControls (NSMenuValidation)
 
- (BOOL)validateMenuItem:(NSMenuItem *)o_mi
{
    BOOL bEnabled = TRUE;
    intf_thread_t * p_intf = [NSApp getIntf];

615
616
617
618
619
620
621
622
    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 );
    }

623
624
#define p_input p_playlist->p_input

hartman's avatar
hartman committed
625
    if( [[o_mi title] isEqualToString: _NS("Faster")] ||
626
627
        [[o_mi title] isEqualToString: _NS("Slower")] )
    {
628
        if( p_playlist != NULL && p_input != NULL )
629
        {
630
631
632
            vlc_mutex_lock( &p_input->stream.stream_lock );
            bEnabled = p_input->stream.b_pace_control;
            vlc_mutex_unlock( &p_input->stream.stream_lock );
633
634
635
636
637
638
639
640
        }
        else
        {
            bEnabled = FALSE;
        }
    }
    else if( [[o_mi title] isEqualToString: _NS("Stop")] )
    {
641
        if( p_playlist == NULL || p_input == NULL )
642
643
644
        {
            bEnabled = FALSE;
        }
645
    }
Jon Lech Johansen's avatar
Jon Lech Johansen committed
646
    else if( [[o_mi title] isEqualToString: _NS("Previous")] ||
647
648
649
650
651
652
653
654
655
             [[o_mi title] isEqualToString: _NS("Next")] )
    {
        if( p_playlist == NULL )
        {
            bEnabled = FALSE;
        }
        else
        {
            bEnabled = p_playlist->i_size > 1;
656
657
658
659

            if( p_input != NULL )
            {
                vlc_mutex_lock( &p_input->stream.stream_lock );
hartman's avatar
hartman committed
660
                bEnabled |= p_input->stream.i_area_nb > 1;
661
662
                vlc_mutex_unlock( &p_input->stream.stream_lock );
            }
663
664
        }
    }
665
666
667
668
669
670
671
    else if( [[o_mi title] isEqualToString: _NS("Loop")] )
    {
        int i_state = config_GetInt( p_playlist, "loop" ) ?
                      NSOnState : NSOffState;

        [o_mi setState: i_state];
    }
672
673
674
675
676
677
678
679
680
681
682
683
684
685
    else if( [[o_mi title] isEqualToString: _NS("Step Forward")] ||
             [[o_mi title] isEqualToString: _NS("Step Backward")] )
    {
        if( p_playlist != NULL && p_input != NULL )
        {
            vlc_mutex_lock( &p_input->stream.stream_lock );
            bEnabled = p_input->stream.b_seekable;
            vlc_mutex_unlock( &p_input->stream.stream_lock );
        }
        else
        {
            bEnabled = FALSE;
        }
    }
686
687
688
689
    else if( [[o_mi title] isEqualToString: _NS("Mute")] ) 
    {
        [o_mi setState: p_intf->p_sys->b_mute ? NSOnState : NSOffState];
    }
690
691
692
    else if( [[o_mi title] isEqualToString: _NS("Fullscreen")] ||
                [[o_mi title] isEqualToString: _NS("Half Size")] ||
                [[o_mi title] isEqualToString: _NS("Normal Size")] ||
hartman's avatar
hartman committed
693
                [[o_mi title] isEqualToString: _NS("Double Size")] ||
694
                [[o_mi title] isEqualToString: _NS("Fit To Screen")] ||
hartman's avatar
hartman committed
695
                [[o_mi title] isEqualToString: _NS("Float On Top")] )
696
    {
697
698
699
700
701
        id o_window;
        NSArray *o_windows = [NSApp windows];
        NSEnumerator *o_enumerator = [o_windows objectEnumerator];
        bEnabled = FALSE;
        
hartman's avatar
hartman committed
702
703
704
705
706
707
708
        if ( [[o_mi title] isEqualToString: _NS("Float On Top")] )
        {
            int i_state = config_GetInt( p_playlist, "macosx-float" ) ?
                      NSOnState : NSOffState;
            [o_mi setState: i_state];
        }
        
709
710
711
        vout_thread_t   *p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
                                              FIND_ANYWHERE );
        if( p_vout != NULL )
712
        {
713
            while ((o_window = [o_enumerator nextObject]))
714
            {
715
716
717
718
719
                if( [[o_window className] isEqualToString: @"VLCWindow"] )
                {
                    bEnabled = TRUE;
                    break;
                }
720
            }
721
            vlc_object_release( (vlc_object_t *)p_vout );
722
723
724
        }
    }

725
726
727
728
729
730
    if( p_playlist != NULL )
    {
        vlc_mutex_unlock( &p_playlist->object_lock );
        vlc_object_release( p_playlist );
    }

731
732
733
734
    return( bEnabled );
}

@end
hartman's avatar
* ALL:    
hartman committed
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785

/*****************************************************************************
 * 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