MainMenu.m 58.2 KB
Newer Older
1 2 3
/*****************************************************************************
 * MainMenu.m: MacOS X interface module
 *****************************************************************************
4
 * Copyright (C) 2011-2014 Felix Paul Kühne
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
 * $Id$
 *
 * Authors: Felix Paul Kühne <fkuehne -at- videolan -dot- org>
 *
 * 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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

#import "MainMenu.h"
25 26
#import "intf.h"

27 28
#import <vlc_common.h>
#import <vlc_playlist.h>
29
#import <vlc_input.h>
30 31 32 33 34 35 36 37 38 39 40

#import "open.h"
#import "wizard.h"
#import "about.h"
#import "AudioEffects.h"
#import "TrackSynchronization.h"
#import "VideoEffects.h"
#import "bookmarks.h"
#import "simple_prefs.h"
#import "coredialogs.h"
#import "controls.h"
41
#import "playlist.h"
42
#import "playlistinfo.h"
43
#import "VideoView.h"
44
#import "CoreInteraction.h"
45
#import "MainWindow.h"
46
#import "ControlsBar.h"
47
#import "ExtensionsManager.h"
48
#import "ConvertAndSave.h"
49
#import "DebugMessageVisualizer.h"
50
#import "AddonsWindowController.h"
51

52
#ifdef HAVE_SPARKLE
53 54 55
#import <Sparkle/Sparkle.h>
#endif

56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
@interface VLCMainMenu()
{
    intf_thread_t *p_intf;
    BOOL b_mainMenu_setup;
    BOOL b_nib_videoeffects_loaded;
    BOOL b_nib_audioeffects_loaded;
    BOOL b_nib_tracksynchro_loaded;
    BOOL b_nib_bookmarks_loaded;
    BOOL b_nib_convertandsave_loaded;

    AboutWindowController *o_about;
    HelpWindowController  *o_helpWin;
    id o_videoeffects;          /* VLCVideoEffects */
    id o_audioeffects;          /* VLCAudioEffects */
    id o_trackSynchronization;  /* VLCTrackSynchronization */
    id o_bookmarks;             /* VLCBookmarks */
    id o_convertandsave;        /* VLCConvertAndSave */
    AddonsWindowController *o_addonsController;

    id o_extMgr;                /* Extensions Manager */

    // information for playlist table columns menu
    NSDictionary * o_ptc_translation_dict;
    NSArray * o_ptc_menuorder;
}
@end

83 84 85 86 87 88 89 90
@implementation VLCMainMenu
static VLCMainMenu *_o_sharedInstance = nil;

+ (VLCMainMenu *)sharedInstance
{
    return _o_sharedInstance ? _o_sharedInstance : [[self alloc] init];
}

91
#pragma mark - Initialization
92 93 94

- (id)init
{
95
    if (!_o_sharedInstance) {
96
        _o_sharedInstance = [super init];
97

98
        o_ptc_translation_dict = [[NSDictionary alloc] initWithObjectsAndKeys:
99 100
                      _NS("Track Number"),  TRACKNUM_COLUMN,
                      _NS("Title"),         TITLE_COLUMN,
101
                      _NS("Author"),        ARTIST_COLUMN,
102 103 104 105 106 107 108
                      _NS("Duration"),      DURATION_COLUMN,
                      _NS("Genre"),         GENRE_COLUMN,
                      _NS("Album"),         ALBUM_COLUMN,
                      _NS("Description"),   DESCRIPTION_COLUMN,
                      _NS("Date"),          DATE_COLUMN,
                      _NS("Language"),      LANGUAGE_COLUMN,
                      _NS("URI"),           URI_COLUMN,
109
                      _NS("File Size"),     FILESIZE_COLUMN,
110 111
                      nil];
        // this array also assigns tags (index) to type of menu item
112 113
        o_ptc_menuorder = [[NSArray alloc] initWithObjects: TRACKNUM_COLUMN, TITLE_COLUMN,
                           ARTIST_COLUMN, DURATION_COLUMN, GENRE_COLUMN, ALBUM_COLUMN,
114 115
                           DESCRIPTION_COLUMN, DATE_COLUMN, LANGUAGE_COLUMN, URI_COLUMN,
                           FILESIZE_COLUMN,nil];
116 117 118 119 120 121 122 123
    }

    return _o_sharedInstance;
}

- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver: self];
124

125
    [self releaseRepresentedObjects:[NSApp mainMenu]];
126 127 128 129
}

- (void)awakeFromNib
{
130
    [[NSNotificationCenter defaultCenter] addObserver: self
131 132 133
                                             selector: @selector(applicationWillFinishLaunching:)
                                                 name: NSApplicationWillFinishLaunchingNotification
                                               object: nil];
134 135 136

    /* check whether the user runs OSX with a RTL language */
    NSArray* languages = [NSLocale preferredLanguages];
137
    NSString* preferredLanguage = [languages objectAtIndex:0];
138 139 140 141 142

    if ([NSLocale characterDirectionForLanguage:preferredLanguage] == NSLocaleLanguageDirectionRightToLeft) {
        msg_Dbg(VLCIntf, "adapting interface since '%s' is a RTL language", [preferredLanguage UTF8String]);
        [o_mi_rate_fld setAlignment: NSLeftTextAlignment];
    }
143 144

    [self setRateControlsEnabled:NO];
145 146

    p_intf = VLCIntf;
147

148
#ifdef HAVE_SPARKLE
149 150 151 152 153
    [o_mi_checkForUpdate setAction:@selector(checkForUpdates:)];
    [o_mi_checkForUpdate setTarget:[SUUpdater sharedUpdater]];
#else
    [o_mi_checkForUpdate setEnabled:NO];
#endif
154 155 156 157 158 159 160
}

- (void)applicationWillFinishLaunching:(NSNotification *)o_notification
{
    NSString* o_key;
    playlist_t *p_playlist;
    vlc_value_t val;
161
    id o_vlcstringutility = [VLCStringUtility sharedInstance];
162
    char * key;
163 164 165

    /* Check if we already did this once. Opening the other nibs calls it too,
     because VLCMain is the owner */
166 167
    if (b_mainMenu_setup)
        return;
168

169 170 171
    /* Get ExtensionsManager */
    o_extMgr = [ExtensionsManager getInstance:p_intf];

172 173
    [self initStrings];

174
    key = config_GetPsz(p_intf, "key-quit");
175
    o_key = [NSString stringWithFormat:@"%s", key];
176 177
    [o_mi_quit setKeyEquivalent: [o_vlcstringutility VLCKeyToString: o_key]];
    [o_mi_quit setKeyEquivalentModifierMask: [o_vlcstringutility VLCModifiersToCocoa:o_key]];
178
    FREENULL(key);
179

180
    // do not assign play/pause key
181

182
    key = config_GetPsz(p_intf, "key-stop");
183
    o_key = [NSString stringWithFormat:@"%s", key];
184 185
    [o_mi_stop setKeyEquivalent: [o_vlcstringutility VLCKeyToString: o_key]];
    [o_mi_stop setKeyEquivalentModifierMask: [o_vlcstringutility VLCModifiersToCocoa:o_key]];
186
    FREENULL(key);
187

188
    key = config_GetPsz(p_intf, "key-prev");
189
    o_key = [NSString stringWithFormat:@"%s", key];
190 191
    [o_mi_previous setKeyEquivalent: [o_vlcstringutility VLCKeyToString: o_key]];
    [o_mi_previous setKeyEquivalentModifierMask: [o_vlcstringutility VLCModifiersToCocoa:o_key]];
192
    FREENULL(key);
193

194
    key = config_GetPsz(p_intf, "key-next");
195
    o_key = [NSString stringWithFormat:@"%s", key];
196 197
    [o_mi_next setKeyEquivalent: [o_vlcstringutility VLCKeyToString: o_key]];
    [o_mi_next setKeyEquivalentModifierMask: [o_vlcstringutility VLCModifiersToCocoa:o_key]];
198
    FREENULL(key);
199

200
    key = config_GetPsz(p_intf, "key-jump+short");
201
    o_key = [NSString stringWithFormat:@"%s", key];
202 203
    [o_mi_fwd setKeyEquivalent: [o_vlcstringutility VLCKeyToString: o_key]];
    [o_mi_fwd setKeyEquivalentModifierMask: [o_vlcstringutility VLCModifiersToCocoa:o_key]];
204
    FREENULL(key);
205

206
    key = config_GetPsz(p_intf, "key-jump-short");
207
    o_key = [NSString stringWithFormat:@"%s", key];
208 209
    [o_mi_bwd setKeyEquivalent: [o_vlcstringutility VLCKeyToString: o_key]];
    [o_mi_bwd setKeyEquivalentModifierMask: [o_vlcstringutility VLCModifiersToCocoa:o_key]];
210
    FREENULL(key);
211

212
    key = config_GetPsz(p_intf, "key-vol-up");
213
    o_key = [NSString stringWithFormat:@"%s", key];
214 215
    [o_mi_vol_up setKeyEquivalent: [o_vlcstringutility VLCKeyToString: o_key]];
    [o_mi_vol_up setKeyEquivalentModifierMask: [o_vlcstringutility VLCModifiersToCocoa:o_key]];
216
    FREENULL(key);
217

218
    key = config_GetPsz(p_intf, "key-vol-down");
219
    o_key = [NSString stringWithFormat:@"%s", key];
220 221
    [o_mi_vol_down setKeyEquivalent: [o_vlcstringutility VLCKeyToString: o_key]];
    [o_mi_vol_down setKeyEquivalentModifierMask: [o_vlcstringutility VLCModifiersToCocoa:o_key]];
222
    FREENULL(key);
223

224
    key = config_GetPsz(p_intf, "key-vol-mute");
225
    o_key = [NSString stringWithFormat:@"%s", key];
226 227
    [o_mi_mute setKeyEquivalent: [o_vlcstringutility VLCKeyToString: o_key]];
    [o_mi_mute setKeyEquivalentModifierMask: [o_vlcstringutility VLCModifiersToCocoa:o_key]];
228
    FREENULL(key);
229

230
    key = config_GetPsz(p_intf, "key-toggle-fullscreen");
231
    o_key = [NSString stringWithFormat:@"%s", key];
232 233
    [o_mi_fullscreen setKeyEquivalent: [o_vlcstringutility VLCKeyToString: o_key]];
    [o_mi_fullscreen setKeyEquivalentModifierMask: [o_vlcstringutility VLCModifiersToCocoa:o_key]];
234
    FREENULL(key);
235

236
    key = config_GetPsz(p_intf, "key-snapshot");
237
    o_key = [NSString stringWithFormat:@"%s", key];
238 239
    [o_mi_snapshot setKeyEquivalent: [o_vlcstringutility VLCKeyToString: o_key]];
    [o_mi_snapshot setKeyEquivalentModifierMask: [o_vlcstringutility VLCModifiersToCocoa:o_key]];
240
    FREENULL(key);
241

242
    key = config_GetPsz(p_intf, "key-random");
243
    o_key = [NSString stringWithFormat:@"%s", key];
244 245
    [o_mi_random setKeyEquivalent: [o_vlcstringutility VLCKeyToString: o_key]];
    [o_mi_random setKeyEquivalentModifierMask: [o_vlcstringutility VLCModifiersToCocoa:o_key]];
246
    FREENULL(key);
247

248
    key = config_GetPsz(p_intf, "key-zoom-half");
249
    o_key = [NSString stringWithFormat:@"%s", key];
250 251
    [o_mi_half_window setKeyEquivalent: [o_vlcstringutility VLCKeyToString: o_key]];
    [o_mi_half_window setKeyEquivalentModifierMask: [o_vlcstringutility VLCModifiersToCocoa:o_key]];
252
    FREENULL(key);
253

254
    key = config_GetPsz(p_intf, "key-zoom-original");
255
    o_key = [NSString stringWithFormat:@"%s", key];
256 257
    [o_mi_normal_window setKeyEquivalent: [o_vlcstringutility VLCKeyToString: o_key]];
    [o_mi_normal_window setKeyEquivalentModifierMask: [o_vlcstringutility VLCModifiersToCocoa:o_key]];
258
    FREENULL(key);
259

260
    key = config_GetPsz(p_intf, "key-zoom-double");
261
    o_key = [NSString stringWithFormat:@"%s", key];
262 263
    [o_mi_double_window setKeyEquivalent: [o_vlcstringutility VLCKeyToString: o_key]];
    [o_mi_double_window setKeyEquivalentModifierMask: [o_vlcstringutility VLCModifiersToCocoa:o_key]];
264
    FREENULL(key);
265 266 267 268 269 270 271 272 273 274 275 276 277

    [self setSubmenusEnabled: FALSE];

    [[NSNotificationCenter defaultCenter] addObserver: self
                                             selector: @selector(refreshVoutDeviceMenu:)
                                                 name: NSApplicationDidChangeScreenParametersNotification
                                               object: nil];

    /* we're done */
    b_mainMenu_setup = YES;

    [self setupVarMenuItem: o_mi_add_intf target: (vlc_object_t *)p_intf
                             var: "intf-add" selector: @selector(toggleVar:)];
278

279 280 281 282 283 284 285 286
    /* setup extensions menu */
    // FIXME: Implement preference for autoloading extensions on mac
    if (![o_extMgr isLoaded] && ![o_extMgr cannotLoad])
        [o_extMgr loadExtensions];

    /* Let the ExtensionsManager itself build the menu */
    [o_extMgr buildMenu:o_mu_extensions];
    [o_mi_extensions setEnabled: ([o_mu_extensions numberOfItems] > 0)];
287

288
    /* setup post-proc menu */
289 290 291 292 293 294 295 296 297 298 299
    NSUInteger count = (NSUInteger) [o_mu_ffmpeg_pp numberOfItems];
    if (count > 0)
        [o_mu_ffmpeg_pp removeAllItems];

    NSMenuItem * o_mitem;
    [o_mu_ffmpeg_pp setAutoenablesItems: YES];
    [o_mu_ffmpeg_pp addItemWithTitle: _NS("Disable") action:@selector(togglePostProcessing:) keyEquivalent:@""];
    o_mitem = [o_mu_ffmpeg_pp itemAtIndex: 0];
    [o_mitem setTag: -1];
    [o_mitem setEnabled: YES];
    [o_mitem setTarget: self];
300
    for (NSUInteger x = 1; x < 7; x++) {
301 302 303
        [o_mu_ffmpeg_pp addItemWithTitle:[NSString stringWithFormat:_NS("Level %i"), x]
                                               action:@selector(togglePostProcessing:)
                                        keyEquivalent:@""];
304
        o_mitem = [o_mu_ffmpeg_pp itemAtIndex:x];
305
        [o_mitem setEnabled:YES];
306
        [o_mitem setTag:x];
307
        [o_mitem setTarget:self];
308 309 310
    }
    char *psz_config = config_GetPsz(p_intf, "video-filter");
    if (psz_config) {
311
        if (!strstr(psz_config, "postproc"))
312 313 314 315 316 317 318 319
            [[o_mu_ffmpeg_pp itemAtIndex:0] setState:NSOnState];
        else
            [[o_mu_ffmpeg_pp itemWithTag:config_GetInt(p_intf, "postproc-q")] setState:NSOnState];
        free(psz_config);
    } else
        [[o_mu_ffmpeg_pp itemAtIndex:0] setState:NSOnState];
    [o_mi_ffmpeg_pp setEnabled: NO];

320
    [self refreshAudioDeviceList];
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

    /* setup subtitles menu */
    [self setupMenu: o_mu_subtitle_size withIntList:"freetype-rel-fontsize" andSelector:@selector(switchSubtitleOption:)];
    [self setupMenu: o_mu_subtitle_textcolor withIntList:"freetype-color" andSelector:@selector(switchSubtitleOption:)];
    [o_mi_subtitle_bgopacity_sld setIntValue: config_GetInt(VLC_OBJECT(p_intf), "freetype-background-opacity")];
    [self setupMenu: o_mu_subtitle_bgcolor withIntList:"freetype-background-color" andSelector:@selector(switchSubtitleOption:)];
    [self setupMenu: o_mu_subtitle_outlinethickness withIntList:"freetype-outline-thickness" andSelector:@selector(switchSubtitleOption:)];
}

- (void)setupMenu: (NSMenu*)menu withIntList: (char *)psz_name andSelector:(SEL)selector
{
    module_config_t *p_item;

    [menu removeAllItems];
    p_item = config_FindConfig(VLC_OBJECT(p_intf), psz_name);

    /* serious problem, if no item found */
    assert(p_item);

    for (int i = 0; i < p_item->list_count; i++) {
        NSMenuItem *mi;
        if (p_item->list_text != NULL)
            mi = [[NSMenuItem alloc] initWithTitle: _NS(p_item->list_text[i]) action:NULL keyEquivalent: @""];
        else if (p_item->list.i[i])
            mi = [[NSMenuItem alloc] initWithTitle: [NSString stringWithFormat: @"%d", p_item->list.i[i]] action:NULL keyEquivalent: @""];
346
        else {
347
            msg_Err(p_intf, "item %d of pref %s failed to be created", i, psz_name);
348 349 350
            continue;
        }

351 352 353
        [mi setTarget:self];
        [mi setAction:selector];
        [mi setTag:p_item->list.i[i]];
354
        [mi setRepresentedObject:[NSString stringWithUTF8String:psz_name]];
355
        [menu addItem:mi];
356 357 358
        if (p_item->value.i == p_item->list.i[i])
            [mi setState:NSOnState];
    }
359 360 361 362 363 364 365 366 367
}

- (void)initStrings
{
    /* main menu */
    [o_mi_about setTitle: [_NS("About VLC media player") \
                           stringByAppendingString: @"..."]];
    [o_mi_checkForUpdate setTitle: _NS("Check for Update...")];
    [o_mi_prefs setTitle: _NS("Preferences...")];
368 369
    [o_mi_extensions setTitle: _NS("Extensions")];
    [o_mu_extensions setTitle: _NS("Extensions")];
David Fuhrmann's avatar
David Fuhrmann committed
370
    [o_mi_addonManager setTitle: _NS("Addons Manager")];
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385
    [o_mi_add_intf setTitle: _NS("Add Interface")];
    [o_mu_add_intf setTitle: _NS("Add Interface")];
    [o_mi_services setTitle: _NS("Services")];
    [o_mi_hide setTitle: _NS("Hide VLC")];
    [o_mi_hide_others setTitle: _NS("Hide Others")];
    [o_mi_show_all setTitle: _NS("Show All")];
    [o_mi_quit setTitle: _NS("Quit VLC")];

    [o_mu_file setTitle: _ANS("1:File")];
    [o_mi_open_generic setTitle: _NS("Advanced Open File...")];
    [o_mi_open_file setTitle: _NS("Open File...")];
    [o_mi_open_disc setTitle: _NS("Open Disc...")];
    [o_mi_open_net setTitle: _NS("Open Network...")];
    [o_mi_open_capture setTitle: _NS("Open Capture Device...")];
    [o_mi_open_recent setTitle: _NS("Open Recent")];
386
    [o_mi_close_window setTitle: _NS("Close Window")];
387
    [o_mi_open_wizard setTitle: _NS("Streaming/Exporting Wizard...")];
388
    [o_mi_convertandsave setTitle: _NS("Convert / Stream...")];
389
    [o_mi_save_playlist setTitle: _NS("Save Playlist...")];
390
    [o_mi_revealInFinder setTitle: _NS("Reveal in Finder")];
391 392 393 394 395 396 397 398

    [o_mu_edit setTitle: _NS("Edit")];
    [o_mi_cut setTitle: _NS("Cut")];
    [o_mi_copy setTitle: _NS("Copy")];
    [o_mi_paste setTitle: _NS("Paste")];
    [o_mi_clear setTitle: _NS("Clear")];
    [o_mi_select_all setTitle: _NS("Select All")];

399 400
    [o_mu_view setTitle: _NS("View")];
    [o_mi_toggleJumpButtons setTitle: _NS("Show Previous & Next Buttons")];
401
    [o_mi_toggleJumpButtons setState: config_GetInt(VLCIntf, "macosx-show-playback-buttons")];
402
    [o_mi_togglePlaymodeButtons setTitle: _NS("Show Shuffle & Repeat Buttons")];
403
    [o_mi_togglePlaymodeButtons setState: config_GetInt(VLCIntf, "macosx-show-playmode-buttons")];
404 405
    [o_mi_toggleEffectsButton setTitle: _NS("Show Audio Effects Button")];
    [o_mi_toggleEffectsButton setState: config_GetInt(VLCIntf, "macosx-show-effects-button")];
406 407
    [o_mi_toggleSidebar setTitle: _NS("Show Sidebar")];
    [o_mi_toggleSidebar setState: config_GetInt(VLCIntf, "macosx-show-sidebar")];
408
    [o_mu_playlistTableColumns setTitle: _NS("Playlist Table Columns")];
409
    [o_mi_playlistTableColumns setTitle: _NS("Playlist Table Columns")];
410

411 412 413
    [o_mu_controls setTitle: _NS("Playback")];
    [o_mi_play setTitle: _NS("Play")];
    [o_mi_stop setTitle: _NS("Stop")];
414
    [o_mi_record setTitle: _NS("Record")];
415 416 417 418 419
    [o_mi_rate setView: o_mi_rate_view];
    [o_mi_rate_lbl setStringValue: _NS("Playback Speed")];
    [o_mi_rate_slower_lbl setStringValue: _NS("Slower")];
    [o_mi_rate_normal_lbl setStringValue: _NS("Normal")];
    [o_mi_rate_faster_lbl setStringValue: _NS("Faster")];
420 421 422 423 424 425
    [o_mi_trackSynchronization setTitle: _NS("Track Synchronization")];
    [o_mi_previous setTitle: _NS("Previous")];
    [o_mi_next setTitle: _NS("Next")];
    [o_mi_random setTitle: _NS("Random")];
    [o_mi_repeat setTitle: _NS("Repeat One")];
    [o_mi_loop setTitle: _NS("Repeat All")];
426
    [o_mi_AtoBloop setTitle: _NS("A→B Loop")];
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443
    [o_mi_quitAfterPB setTitle: _NS("Quit after Playback")];
    [o_mi_fwd setTitle: _NS("Step Forward")];
    [o_mi_bwd setTitle: _NS("Step Backward")];

    [o_mi_program setTitle: _NS("Program")];
    [o_mu_program setTitle: _NS("Program")];
    [o_mi_title setTitle: _NS("Title")];
    [o_mu_title setTitle: _NS("Title")];
    [o_mi_chapter setTitle: _NS("Chapter")];
    [o_mu_chapter setTitle: _NS("Chapter")];

    [o_mu_audio setTitle: _NS("Audio")];
    [o_mi_vol_up setTitle: _NS("Increase Volume")];
    [o_mi_vol_down setTitle: _NS("Decrease Volume")];
    [o_mi_mute setTitle: _NS("Mute")];
    [o_mi_audiotrack setTitle: _NS("Audio Track")];
    [o_mu_audiotrack setTitle: _NS("Audio Track")];
444 445
    [o_mi_channels setTitle: _NS("Stereo audio mode")];
    [o_mu_channels setTitle: _NS("Stereo audio mode")];
446 447 448 449 450 451 452 453 454 455 456 457 458 459 460
    [o_mi_device setTitle: _NS("Audio Device")];
    [o_mu_device setTitle: _NS("Audio Device")];
    [o_mi_visual setTitle: _NS("Visualizations")];
    [o_mu_visual setTitle: _NS("Visualizations")];

    [o_mu_video setTitle: _NS("Video")];
    [o_mi_half_window setTitle: _NS("Half Size")];
    [o_mi_normal_window setTitle: _NS("Normal Size")];
    [o_mi_double_window setTitle: _NS("Double Size")];
    [o_mi_fittoscreen setTitle: _NS("Fit to Screen")];
    [o_mi_fullscreen setTitle: _NS("Fullscreen")];
    [o_mi_floatontop setTitle: _NS("Float on Top")];
    [o_mi_snapshot setTitle: _NS("Snapshot")];
    [o_mi_videotrack setTitle: _NS("Video Track")];
    [o_mu_videotrack setTitle: _NS("Video Track")];
Christoph Miebach's avatar
Christoph Miebach committed
461 462
    [o_mi_aspect_ratio setTitle: _NS("Aspect ratio")];
    [o_mu_aspect_ratio setTitle: _NS("Aspect ratio")];
463 464 465 466 467 468 469 470 471 472
    [o_mi_crop setTitle: _NS("Crop")];
    [o_mu_crop setTitle: _NS("Crop")];
    [o_mi_screen setTitle: _NS("Fullscreen Video Device")];
    [o_mu_screen setTitle: _NS("Fullscreen Video Device")];
    [o_mi_deinterlace setTitle: _NS("Deinterlace")];
    [o_mu_deinterlace setTitle: _NS("Deinterlace")];
    [o_mi_deinterlace_mode setTitle: _NS("Deinterlace mode")];
    [o_mu_deinterlace_mode setTitle: _NS("Deinterlace mode")];
    [o_mi_ffmpeg_pp setTitle: _NS("Post processing")];
    [o_mu_ffmpeg_pp setTitle: _NS("Post processing")];
473 474

    [o_mu_subtitles setTitle:_NS("Subtitles")];
475
    [o_mi_openSubtitleFile setTitle: _NS("Add Subtitle File...")];
476 477
    [o_mi_subtitle_track setTitle: _NS("Subtitles Track")];
    [o_mu_subtitle_tracks setTitle: _NS("Subtitles Track")];
478 479 480
    [o_mi_subtitle_size setTitle: _NS("Text Size")];
    [o_mi_subtitle_textcolor setTitle: _NS("Text Color")];
    [o_mi_subtitle_outlinethickness setTitle: _NS("Outline Thickness")];
481
    [o_mi_subtitle_bgopacity setView: o_mi_subtitle_bgopacity_view];
482 483 484
    [o_mi_subtitle_bgopacity_lbl setStringValue: _NS("Background Opacity")];
    [o_mi_subtitle_bgopacity_lbl_gray setStringValue: _NS("Background Opacity")];
    [o_mi_subtitle_bgcolor setTitle: _NS("Background Color")];
485 486 487 488 489 490 491 492 493
    [o_mi_teletext setTitle: _NS("Teletext")];
    [o_mi_teletext_transparent setTitle: _NS("Transparent")];
    [o_mi_teletext_index setTitle: _NS("Index")];
    [o_mi_teletext_red setTitle: _NS("Red")];
    [o_mi_teletext_green setTitle: _NS("Green")];
    [o_mi_teletext_yellow setTitle: _NS("Yellow")];
    [o_mi_teletext_blue setTitle: _NS("Blue")];

    [o_mu_window setTitle: _NS("Window")];
494 495
    [o_mi_minimize setTitle: _NS("Minimize")];
    [o_mi_zoom_window setTitle: _NS("Zoom")];
496
    [o_mi_player setTitle: _NS("Player...")];
497
    [o_mi_controller setTitle: _NS("Main Window...")];
498
    [o_mi_audioeffects setTitle: _NS("Audio Effects...")];
499
    [o_mi_videoeffects setTitle: _NS("Video Effects...")];
500 501 502 503 504 505 506 507 508 509 510 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
    [o_mi_bookmarks setTitle: _NS("Bookmarks...")];
    [o_mi_playlist setTitle: _NS("Playlist...")];
    [o_mi_info setTitle: _NS("Media Information...")];
    [o_mi_messages setTitle: _NS("Messages...")];
    [o_mi_errorsAndWarnings setTitle: _NS("Errors and Warnings...")];

    [o_mi_bring_atf setTitle: _NS("Bring All to Front")];

    [o_mu_help setTitle: _NS("Help")];
    [o_mi_help setTitle: _NS("VLC media player Help...")];
    [o_mi_readme setTitle: _NS("ReadMe / FAQ...")];
    [o_mi_license setTitle: _NS("License")];
    [o_mi_documentation setTitle: _NS("Online Documentation...")];
    [o_mi_website setTitle: _NS("VideoLAN Website...")];
    [o_mi_donation setTitle: _NS("Make a donation...")];
    [o_mi_forum setTitle: _NS("Online Forum...")];

    /* dock menu */
    [o_dmi_play setTitle: _NS("Play")];
    [o_dmi_stop setTitle: _NS("Stop")];
    [o_dmi_next setTitle: _NS("Next")];
    [o_dmi_previous setTitle: _NS("Previous")];
    [o_dmi_mute setTitle: _NS("Mute")];

    /* vout menu */
    [o_vmi_play setTitle: _NS("Play")];
    [o_vmi_stop setTitle: _NS("Stop")];
    [o_vmi_prev setTitle: _NS("Previous")];
    [o_vmi_next setTitle: _NS("Next")];
    [o_vmi_volup setTitle: _NS("Volume Up")];
    [o_vmi_voldown setTitle: _NS("Volume Down")];
    [o_vmi_mute setTitle: _NS("Mute")];
    [o_vmi_fullscreen setTitle: _NS("Fullscreen")];
    [o_vmi_snapshot setTitle: _NS("Snapshot")];
}

536 537 538 539 540
- (NSMenu *)setupPlaylistTableColumnsMenu
{
    NSMenu *o_context_menu = [[NSMenu alloc] init];

    NSMenuItem *o_mi_tmp;
541
    NSUInteger count = [o_ptc_menuorder count];
542
    for (NSUInteger i = 0; i < count; i++) {
543
        NSString *o_title = [o_ptc_translation_dict objectForKey:[o_ptc_menuorder objectAtIndex:i]];
544 545 546
        o_mi_tmp = [o_mu_playlistTableColumns addItemWithTitle:o_title
                                                        action:@selector(togglePlaylistColumnTable:)
                                                 keyEquivalent:@""];
547
        /* don't set a valid target for the title column selector, since we want it to be disabled */
548
        if (![[o_ptc_menuorder objectAtIndex:i] isEqualToString: TITLE_COLUMN])
549
            [o_mi_tmp setTarget:self];
550 551 552 553 554
        [o_mi_tmp setTag:i];

        o_mi_tmp = [o_context_menu addItemWithTitle:o_title
                                             action:@selector(togglePlaylistColumnTable:)
                                      keyEquivalent:@""];
555
        /* don't set a valid target for the title column selector, since we want it to be disabled */
556
        if (![[o_ptc_menuorder objectAtIndex:i] isEqualToString: TITLE_COLUMN])
557
            [o_mi_tmp setTarget:self];
558 559
        [o_mi_tmp setTag:i];
    }
560
    if (!o_mu_playlistTableColumnsContextMenu)
561 562
        o_mu_playlistTableColumnsContextMenu = o_context_menu;
    return o_context_menu;
563 564
}

565
#pragma mark - Termination
566 567 568

- (void)releaseRepresentedObjects:(NSMenu *)the_menu
{
569
    if (!p_intf) return;
570

571
    NSArray *menuitems_array = [the_menu itemArray];
572
    NSUInteger menuItemCount = [menuitems_array count];
573
    for (NSUInteger i=0; i < menuItemCount; i++) {
574
        NSMenuItem *one_item = [menuitems_array objectAtIndex:i];
575
        if ([one_item hasSubmenu])
576 577 578 579 580 581
            [self releaseRepresentedObjects: [one_item submenu]];

        [one_item setRepresentedObject:NULL];
    }
}

582
#pragma mark - Interface update
583 584 585

- (void)setupMenus
{
586 587 588
    playlist_t * p_playlist = pl_Get(p_intf);
    input_thread_t * p_input = playlist_CurrentInput(p_playlist);
    if (p_input != NULL) {
589 590 591 592 593 594 595 596 597 598 599 600 601 602 603
        [self setupVarMenuItem: o_mi_program target: (vlc_object_t *)p_input
                                 var: "program" selector: @selector(toggleVar:)];

        [self setupVarMenuItem: o_mi_title target: (vlc_object_t *)p_input
                                 var: "title" selector: @selector(toggleVar:)];

        [self setupVarMenuItem: o_mi_chapter target: (vlc_object_t *)p_input
                                 var: "chapter" selector: @selector(toggleVar:)];

        [self setupVarMenuItem: o_mi_audiotrack target: (vlc_object_t *)p_input
                                 var: "audio-es" selector: @selector(toggleVar:)];

        [self setupVarMenuItem: o_mi_videotrack target: (vlc_object_t *)p_input
                                 var: "video-es" selector: @selector(toggleVar:)];

604
        [self setupVarMenuItem: o_mi_subtitle_track target: (vlc_object_t *)p_input
605 606
                                 var: "spu-es" selector: @selector(toggleVar:)];

607
        audio_output_t * p_aout = playlist_GetAout(p_playlist);
608
        if (p_aout != NULL) {
609
            [self setupVarMenuItem: o_mi_channels target: (vlc_object_t *)p_aout
610
                                     var: "stereo-mode" selector: @selector(toggleVar:)];
611 612 613

            [self setupVarMenuItem: o_mi_visual target: (vlc_object_t *)p_aout
                                     var: "visual" selector: @selector(toggleVar:)];
614
            vlc_object_release(p_aout);
615 616
        }

617
        vout_thread_t * p_vout = getVoutForActiveWindow();
618

619
        if (p_vout != NULL) {
620 621 622 623 624 625 626 627 628 629 630 631
            [self setupVarMenuItem: o_mi_aspect_ratio target: (vlc_object_t *)p_vout
                                     var: "aspect-ratio" selector: @selector(toggleVar:)];

            [self setupVarMenuItem: o_mi_crop target: (vlc_object_t *) p_vout
                                     var: "crop" selector: @selector(toggleVar:)];

            [self setupVarMenuItem: o_mi_deinterlace target: (vlc_object_t *)p_vout
                                     var: "deinterlace" selector: @selector(toggleVar:)];

            [self setupVarMenuItem: o_mi_deinterlace_mode target: (vlc_object_t *)p_vout
                                     var: "deinterlace-mode" selector: @selector(toggleVar:)];

632
            vlc_object_release(p_vout);
633 634

            [self refreshVoutDeviceMenu:nil];
635
        }
636
        [o_mi_ffmpeg_pp setEnabled:YES];
637
        vlc_object_release(p_input);
638 639 640
    } else {
        [o_mi_ffmpeg_pp setEnabled:NO];
    }
641 642 643 644
}

- (void)refreshVoutDeviceMenu:(NSNotification *)o_notification
{
645
    NSUInteger count = (NSUInteger) [o_mu_screen numberOfItems];
646 647
    NSMenu * o_submenu = o_mu_screen;
    if (count > 0)
648
        [o_submenu removeAllItems];
649

650
    NSArray * o_screens = [NSScreen screens];
651
    NSMenuItem * o_mitem;
652
    count = [o_screens count];
653
    [o_mi_screen setEnabled: YES];
654
    [o_submenu addItemWithTitle: _NS("Default") action:@selector(toggleFullscreenDevice:) keyEquivalent:@""];
655 656 657 658
    o_mitem = [o_submenu itemAtIndex: 0];
    [o_mitem setTag: 0];
    [o_mitem setEnabled: YES];
    [o_mitem setTarget: self];
659
    NSRect s_rect;
660
    for (NSUInteger i = 0; i < count; i++) {
661
        s_rect = [[o_screens objectAtIndex:i] frame];
662
        [o_submenu addItemWithTitle: [NSString stringWithFormat: @"%@ %li (%ix%i)", _NS("Screen"), i+1,
663
                                      (int)s_rect.size.width, (int)s_rect.size.height] action:@selector(toggleFullscreenDevice:) keyEquivalent:@""];
664
        o_mitem = [o_submenu itemAtIndex:i+1];
665
        [o_mitem setTag: (int)[[o_screens objectAtIndex:i] displayID]];
666 667
        [o_mitem setEnabled: YES];
        [o_mitem setTarget: self];
668
    }
669
    [[o_submenu itemWithTag: var_InheritInteger(VLCIntf, "macosx-vdev")] setState: NSOnState];
670 671 672 673 674 675 676 677 678 679
}

- (void)setSubmenusEnabled:(BOOL)b_enabled
{
    [o_mi_program setEnabled: b_enabled];
    [o_mi_title setEnabled: b_enabled];
    [o_mi_chapter setEnabled: b_enabled];
    [o_mi_audiotrack setEnabled: b_enabled];
    [o_mi_visual setEnabled: b_enabled];
    [o_mi_videotrack setEnabled: b_enabled];
680
    [o_mi_subtitle_track setEnabled: b_enabled];
681 682 683 684 685 686
    [o_mi_channels setEnabled: b_enabled];
    [o_mi_deinterlace setEnabled: b_enabled];
    [o_mi_deinterlace_mode setEnabled: b_enabled];
    [o_mi_screen setEnabled: b_enabled];
    [o_mi_aspect_ratio setEnabled: b_enabled];
    [o_mi_crop setEnabled: b_enabled];
687 688 689 690 691
}

- (void)setSubtitleMenuEnabled:(BOOL)b_enabled
{
    [o_mi_openSubtitleFile setEnabled: b_enabled];
692 693 694 695 696 697 698 699
    if (b_enabled) {
        [o_mi_subtitle_bgopacity_lbl_gray setHidden: YES];
        [o_mi_subtitle_bgopacity_lbl setHidden: NO];
    } else {
        [o_mi_subtitle_bgopacity_lbl_gray setHidden: NO];
        [o_mi_subtitle_bgopacity_lbl setHidden: YES];
    }
    [o_mi_subtitle_bgopacity_sld setEnabled: b_enabled];
700 701 702
    [o_mi_teletext setEnabled: b_enabled];
}

703 704 705 706 707
- (void)setRateControlsEnabled:(BOOL)b_enabled
{
    [o_mi_rate_sld setEnabled: b_enabled];
    [o_mi_rate_sld setIntValue: [[VLCCoreInteraction sharedInstance] playbackRate]];
    int i = [[VLCCoreInteraction sharedInstance] playbackRate];
708
    double speed =  pow(2, (double)i / 17);
709
    [o_mi_rate_fld setStringValue: [NSString stringWithFormat:@"%.2fx", speed]];
710 711 712 713 714 715 716 717 718

    NSColor *o_color = b_enabled ? [NSColor controlTextColor] : [NSColor disabledControlTextColor];

    [o_mi_rate_lbl setTextColor:o_color];
    [o_mi_rate_slower_lbl setTextColor:o_color];
    [o_mi_rate_normal_lbl setTextColor:o_color];
    [o_mi_rate_faster_lbl setTextColor:o_color];
    [o_mi_rate_fld setTextColor:o_color];

719
    [self setSubtitleMenuEnabled: b_enabled];
720 721
}

722
#pragma mark - View
723 724 725 726 727 728 729 730 731

- (IBAction)toggleEffectsButton:(id)sender
{
    BOOL b_value = !config_GetInt(VLCIntf, "macosx-show-effects-button");
    config_PutInt(VLCIntf, "macosx-show-effects-button", b_value);
    [[[[VLCMain sharedInstance] mainWindow] controlsBar] toggleEffectsButton];
    [o_mi_toggleEffectsButton setState: b_value];
}

732 733
- (IBAction)toggleJumpButtons:(id)sender
{
734 735
    BOOL b_value = !config_GetInt(VLCIntf, "macosx-show-playback-buttons");
    config_PutInt(VLCIntf, "macosx-show-playback-buttons", b_value);
736

737
    [[[[VLCMain sharedInstance] mainWindow] controlsBar] toggleJumpButtons];
738 739 740 741
    [[[VLCMain sharedInstance] voutController] updateWindowsUsingBlock:^(VLCVideoWindowCommon *o_window) {
        [[o_window controlsBar] toggleForwardBackwardMode: b_value];
    }];

742 743 744
    [o_mi_toggleJumpButtons setState: b_value];
}

745 746
- (IBAction)togglePlaymodeButtons:(id)sender
{
747 748
    BOOL b_value = !config_GetInt(VLCIntf, "macosx-show-playmode-buttons");
    config_PutInt(VLCIntf, "macosx-show-playmode-buttons", b_value);
749
    [[[[VLCMain sharedInstance] mainWindow] controlsBar] togglePlaymodeButtons];
750 751 752
    [o_mi_togglePlaymodeButtons setState: b_value];
}

753 754 755 756 757 758 759 760 761 762
- (IBAction)toggleSidebar:(id)sender
{
    [[[VLCMain sharedInstance] mainWindow] toggleLeftSubSplitView];
}

- (void)updateSidebarMenuItem
{
    [o_mi_toggleSidebar setState: config_GetInt(VLCIntf, "macosx-show-sidebar")];
}

763 764
- (IBAction)togglePlaylistColumnTable:(id)sender
{
765 766 767 768 769
    NSInteger i_new_state = ![sender state];
    NSInteger i_tag = [sender tag];
    [[o_mu_playlistTableColumns            itemWithTag: i_tag] setState: i_new_state];
    [[o_mu_playlistTableColumnsContextMenu itemWithTag: i_tag] setState: i_new_state];

770
    NSString *o_column = [o_ptc_menuorder objectAtIndex:i_tag];
771
    [[[VLCMain sharedInstance] playlist] setColumn: o_column state: i_new_state translationDict: o_ptc_translation_dict];
772 773
}

774
- (BOOL)setPlaylistColumnTableState:(NSInteger)i_state forColumn:(NSString *)o_column
775
{
776 777 778 779 780
    NSUInteger i_tag = [o_ptc_menuorder indexOfObject: o_column];
    // prevent setting unknown columns
    if(i_tag == NSNotFound)
        return NO;

781 782
    [[o_mu_playlistTableColumns            itemWithTag: i_tag] setState: i_state];
    [[o_mu_playlistTableColumnsContextMenu itemWithTag: i_tag] setState: i_state];
783
    [[[VLCMain sharedInstance] playlist] setColumn: o_column state: i_state translationDict: o_ptc_translation_dict];
784 785

    return YES;
786 787
}

788
#pragma mark - Playback
789 790 791 792 793 794 795 796 797

- (IBAction)quitAfterPlayback:(id)sender
{
    playlist_t *p_playlist = pl_Get(VLCIntf);
    bool b_value = !var_CreateGetBool(p_playlist, "play-and-exit");
    var_SetBool(p_playlist, "play-and-exit", b_value);
    config_PutInt(p_intf, "play-and-exit", b_value);
}

798 799 800 801 802 803 804 805 806 807 808 809 810 811
- (IBAction)toggleRecord:(id)sender
{
    [[VLCCoreInteraction sharedInstance] toggleRecord];
}

- (void)updateRecordState:(BOOL)b_value
{
    [o_mi_record setState:b_value];
}

- (IBAction)setPlaybackRate:(id)sender
{
    [[VLCCoreInteraction sharedInstance] setPlaybackRate: [o_mi_rate_sld intValue]];
    int i = [[VLCCoreInteraction sharedInstance] playbackRate];
812
    double speed =  pow(2, (double)i / 17);
813 814 815 816 817 818
    [o_mi_rate_fld setStringValue: [NSString stringWithFormat:@"%.2fx", speed]];
}

- (void)updatePlaybackRate
{
    int i = [[VLCCoreInteraction sharedInstance] playbackRate];
819
    double speed =  pow(2, (double)i / 17);
820 821 822 823
    [o_mi_rate_fld setStringValue: [NSString stringWithFormat:@"%.2fx", speed]];
    [o_mi_rate_sld setIntValue: i];
}

824 825 826 827 828
- (IBAction)toggleAtoBloop:(id)sender
{
    [[VLCCoreInteraction sharedInstance] setAtoB];
}

829 830
#pragma mark - audio menu

831 832 833 834 835 836 837 838 839 840 841 842
- (void)refreshAudioDeviceList
{
    char **ids, **names;
    char *currentDevice;

    [o_mu_device removeAllItems];

    audio_output_t * p_aout = getAout();
    if (!p_aout)
        return;

    int n = aout_DevicesList(p_aout, &ids, &names);
843 844
    if (n == -1) {
        vlc_object_release(p_aout);
845
        return;
846
    }
847 848 849 850 851

    currentDevice = aout_DeviceGet(p_aout);
    NSMenuItem * o_mi_tmp;

    for (NSUInteger x = 0; x < n; x++) {
852
        o_mi_tmp = [o_mu_device addItemWithTitle:toNSStr(names[x]) action:@selector(toggleAudioDevice:) keyEquivalent:@""];
853 854 855 856 857
        [o_mi_tmp setTarget:self];
        [o_mi_tmp setTag:[[NSString stringWithFormat:@"%s", ids[x]] intValue]];
    }
    vlc_object_release(p_aout);

858 859
    [[o_mu_device itemWithTag:[[NSString stringWithFormat:@"%s", currentDevice] intValue]] setState:NSOnState];

860 861
    free(currentDevice);

862 863 864 865 866 867 868 869 870 871 872 873 874 875
    for (NSUInteger x = 0; x < n; x++) {
        free(ids[x]);
        free(names[x]);
    }
    free(ids);
    free(names);

    [o_mu_device setAutoenablesItems:YES];
    [o_mi_device setEnabled:YES];
}

- (IBAction)toggleAudioDevice:(id)sender
{
    audio_output_t * p_aout = getAout();
876 877
    if (!p_aout)
        return;
878 879 880 881

    int returnValue = 0;

    if ([sender tag] > 0)
882
        returnValue = aout_DeviceSet(p_aout, [[NSString stringWithFormat:@"%li", [sender tag]] UTF8String]);
883
    else
884
        returnValue = aout_DeviceSet(p_aout, NULL);
885 886 887 888

    if (returnValue != 0)
        msg_Warn(VLCIntf, "failed to set audio device %li", [sender tag]);

889
    vlc_object_release(p_aout);
890 891 892
    [self refreshAudioDeviceList];
}

893
#pragma mark - video menu
894

895 896 897 898 899 900 901
- (IBAction)toggleFullscreen:(id)sender
{
    [[VLCCoreInteraction sharedInstance] toggleFullscreen];
}

- (IBAction)resizeVideoWindow:(id)sender
{
902 903
    input_thread_t *p_input = pl_CurrentInput(VLCIntf);
    if (p_input) {
904
        vout_thread_t *p_vout = getVoutForActiveWindow();
905
        if (p_vout) {
906
            if (sender == o_mi_half_window)
907
                var_SetFloat(p_vout, "zoom", 0.5);
908
            else if (sender == o_mi_normal_window)
909
                var_SetFloat(p_vout, "zoom", 1.0);
910
            else if (sender == o_mi_double_window)
911
                var_SetFloat(p_vout, "zoom", 2.0);
912 913
            else
            {
914
                [[NSApp keyWindow] performZoom:sender];
915
            }
916
            vlc_object_release(p_vout);
917
        }
918
        vlc_object_release(p_input);
919 920 921 922 923
    }
}

- (IBAction)floatOnTop:(id)sender
{
924 925
    input_thread_t *p_input = pl_CurrentInput(VLCIntf);
    if (p_input) {
926
        vout_thread_t *p_vout = getVoutForActiveWindow();
927
        if (p_vout) {
928 929 930
            BOOL b_fs = var_ToggleBool(p_vout, "video-on-top");
            var_SetBool(pl_Get(p_intf), "video-on-top", b_fs);

931
            vlc_object_release(p_vout);
932
        }
933
        vlc_object_release(p_input);
934 935 936 937 938
    }
}

- (IBAction)createVideoSnapshot:(id)sender
{
939 940
    input_thread_t *p_input = pl_CurrentInput(VLCIntf);
    if (p_input) {
941
        vout_thread_t *p_vout = getVoutForActiveWindow();
942 943 944
        if (p_vout) {
            var_TriggerCallback(p_vout, "video-snapshot");
            vlc_object_release(p_vout);
945
        }
946
        vlc_object_release(p_input);
947 948 949
    }
}

950 951
- (void)_disablePostProcessing
{
952
    [[VLCCoreInteraction sharedInstance] setVideoFilter:"postproc" on:false];
953 954 955 956
}

- (void)_enablePostProcessing
{
957
    [[VLCCoreInteraction sharedInstance] setVideoFilter:"postproc" on:true];
958 959 960 961
}

- (IBAction)togglePostProcessing:(id)sender
{
962
    char *psz_name = "postproc";
963 964 965 966 967 968 969 970 971 972 973
    NSInteger count = [o_mu_ffmpeg_pp numberOfItems];
    for (NSUInteger x = 0; x < count; x++)
        [[o_mu_ffmpeg_pp itemAtIndex:x] setState:NSOffState];

    if ([sender tag] == -1) {
        [self _disablePostProcessing];
        [sender setState:NSOnState];
    } else {
        [self _enablePostProcessing];
        [sender setState:NSOnState];

974
        [[VLCCoreInteraction sharedInstance] setVideoFilterProperty:"postproc-q" forFilter:"postproc" integer:[sender tag]];
975 976 977
    }
}

978 979
- (IBAction)toggleFullscreenDevice:(id)sender
{
980
    config_PutInt(VLCIntf, "macosx-vdev", [sender tag]);
981 982 983
    [self refreshVoutDeviceMenu: nil];
}

984 985 986 987 988
- (id)voutMenu
{
    return o_vout_menu;
}

989
#pragma mark - Subtitles Menu
990

991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004
- (IBAction)addSubtitleFile:(id)sender
{
    NSInteger i_returnValue = 0;
    input_thread_t * p_input = pl_CurrentInput(VLCIntf);
    if (!p_input)
        return;

    input_item_t *p_item = input_GetItem(p_input);
    if (!p_item) {
        vlc_object_release(p_input);
        return;
    }

    char *path = input_item_GetURI(p_item);
1005

1006 1007 1008 1009 1010 1011 1012
    if (!path)
        path = strdup("");

    NSOpenPanel * openPanel = [NSOpenPanel openPanel];
    [openPanel setCanChooseFiles: YES];
    [openPanel setCanChooseDirectories: NO];
    [openPanel setAllowsMultipleSelection: YES];
1013 1014 1015 1016 1017 1018

    [openPanel setAllowedFileTypes: [NSArray arrayWithObjects:@"cdg",@"idx",@"srt",@"sub",@"utf",@"ass",@"ssa",@"aqt",@"jss",@"psb",@"rt",@"smi",@"txt",@"smil",nil]];

    NSURL *o_url = [NSURL URLWithString:[[NSString stringWithUTF8String:path] stringByExpandingTildeInPath]];
    o_url = [o_url URLByDeletingLastPathComponent];
    [openPanel setDirectoryURL: o_url];
1019
    free(path);
1020
    vlc_object_release(p_input);
1021

1022 1023
    i_returnValue = [openPanel runModal];

1024 1025
    if (i_returnValue == NSOKButton)
        [[VLCCoreInteraction sharedInstance] addSubtitlesToCurrentInput:[openPanel URLs]];
1026 1027
}

1028 1029 1030 1031 1032
- (IBAction)switchSubtitleOption:(id)sender
{
    int intValue = [sender tag];
    NSString *representedObject = [sender representedObject];

1033
    config_PutInt(p_intf, [representedObject UTF8String], intValue);
1034 1035

    NSMenu *menu = [sender menu];
1036
    NSUInteger count = (NSUInteger) [menu numberOfItems];
1037 1038 1039
    for (NSUInteger x = 0; x < count; x++)
        [[menu itemAtIndex:x] setState:NSOffState];
    [[menu itemWithTag:intValue] setState:NSOnState];
1040 1041 1042 1043
}

- (IBAction)switchSubtitleBackgroundOpacity:(id)sender
{
1044
    config_PutInt(p_intf, "freetype-background-opacity", [sender intValue]);
1045 1046
}

1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081
- (IBAction)telxTransparent:(id)sender
{
    vlc_object_t *p_vbi;
    p_vbi = (vlc_object_t *) vlc_object_find_name(pl_Get(VLCIntf), "zvbi");
    if (p_vbi) {
        var_SetBool(p_vbi, "vbi-opaque", [sender state]);
        [sender setState: ![sender state]];
        vlc_object_release(p_vbi);
    }
}

- (IBAction)telxNavLink:(id)sender
{
    vlc_object_t *p_vbi;
    int i_page = 0;

    if ([[sender title] isEqualToString: _NS("Index")])
        i_page = 'i' << 16;
    else if ([[sender title] isEqualToString: _NS("Red")])
        i_page = 'r' << 16;
    else if ([[sender title] isEqualToString: _NS("Green")])
        i_page = 'g' << 16;
    else if ([[sender title] isEqualToString: _NS("Yellow")])
        i_page = 'y' << 16;
    else if ([[sender title] isEqualToString: _NS("Blue")])
        i_page = 'b' << 16;
    if (i_page == 0) return;

    p_vbi = (vlc_object_t *) vlc_object_find_name(pl_Get(VLCIntf), "zvbi");
    if (p_vbi) {
        var_SetInteger(p_vbi, "vbi-page", i_page);
        vlc_object_release(p_vbi);
    }
}

1082
#pragma mark - Panels
1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114

- (IBAction)intfOpenFile:(id)sender
{
    [[[VLCMain sharedInstance] open] openFile];
}

- (IBAction)intfOpenFileGeneric:(id)sender
{
    [[[VLCMain sharedInstance] open] openFileGeneric];
}

- (IBAction)intfOpenDisc:(id)sender
{
    [[[VLCMain sharedInstance] open] openDisc];
}

- (IBAction)intfOpenNet:(id)sender
{
    [[[VLCMain sharedInstance] open] openNet];
}

- (IBAction)intfOpenCapture:(id)sender
{
    [[[VLCMain sharedInstance] open] openCapture];
}

- (IBAction)showWizard:(id)sender
{
    [[[VLCMain sharedInstance] wizard] resetWizard];
    [[[VLCMain sharedInstance] wizard] showWizard];
}

1115 1116 1117 1118 1119
- (IBAction)savePlaylist:(id)sender
{
    [[[VLCMain sharedInstance] playlist] savePlaylist:sender];
}

1120 1121 1122 1123 1124
- (IBAction)revealItemInFinder:(id)sender
{
    [[[VLCMain sharedInstance] playlist] revealItemInFinder:sender];
}

1125 1126
- (IBAction)showConvertAndSave:(id)sender
{
1127
    if (o_convertandsave == nil)
1128 1129
        o_convertandsave = [[VLCConvertAndSave alloc] init];

1130
    if (!b_nib_convertandsave_loaded)
1131 1132 1133 1134 1135
        b_nib_convertandsave_loaded = [NSBundle loadNibNamed:@"ConvertAndSave" owner: NSApp];

    [o_convertandsave toggleWindow];
}

1136 1137
- (IBAction)showVideoEffects:(id)sender