VLCMainMenu.m 57.9 KB
Newer Older
1
/*****************************************************************************
2
 *MainMenu.m: MacOS X interface module
3
 *****************************************************************************
4 5
 *Copyright (C) 2011-2015 Felix Paul Kühne
 *$Id$
6
 *
7
 *Authors: Felix Paul Kühne <fkuehne -at- videolan -dot- org>
8
 *
9 10 11 12
 *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.
13
 *
14 15 16 17
 *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.
18
 *
19 20 21
 *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.
22 23
 *****************************************************************************/

24
#import "VLCMainMenu.h"
25
#import "VLCMain.h"
26

27 28
#import <vlc_common.h>
#import <vlc_playlist.h>
29
#import <vlc_input.h>
30

31
#import "VLCAboutWindowController.h"
32
#import "VLCOpenWindowController.h"
33
#import "VLCAudioEffectsWindowController.h"
34
#import "VLCErrorWindowController.h"
35
#import "VLCTrackSynchronizationWindowController.h"
36
#import "VLCHelpWindowController.h"
37
#import "VLCVideoEffectsWindowController.h"
38
#import "VLCBookmarksWindowController.h"
39
#import "VLCSimplePrefsController.h"
40 41
#import "VLCPlaylist.h"
#import "VLCPlaylistInfo.h"
42
#import "VLCVoutView.h"
43
#import "VLCCoreDialogProvider.h"
44
#import "VLCCoreInteraction.h"
45
#import "VLCMainWindow.h"
46
#import "VLCMainWindowControlsBar.h"
47
#import "VLCExtensionsManager.h"
48
#import "VLCConvertAndSaveWindowController.h"
49
#import "VLCLogWindowController.h"
50
#import "VLCAddonsWindowController.h"
51
#import "VLCTimeSelectionPanelController.h"
52
#import "NSScreen+VLCAdditions.h"
53

54
#ifdef HAVE_SPARKLE
55 56 57
#import <Sparkle/Sparkle.h>
#endif

58 59
@interface VLCMainMenu()
{
60
    VLCAboutWindowController *_aboutWindowController;
61
    VLCHelpWindowController  *_helpWindowController;
62
    VLCAddonsWindowController *_addonsController;
63

64
    NSMenu *_playlistTableColumnsContextMenu;
65 66 67

    __strong VLCTimeSelectionPanelController *_timeSelectionPanel;

68 69 70
}
@end

71 72
@implementation VLCMainMenu

73
#pragma mark - Initialization
74 75 76

- (void)dealloc
{
77
    msg_Dbg(getIntf(), "Deinitializing main menu");
78
    [[NSNotificationCenter defaultCenter] removeObserver: self];
79

80
    [self releaseRepresentedObjects:[NSApp mainMenu]];
81 82 83 84
}

- (void)awakeFromNib
{
85 86
    _timeSelectionPanel = [[VLCTimeSelectionPanelController alloc] init];

87 88
    /* check whether the user runs OSX with a RTL language */
    NSArray* languages = [NSLocale preferredLanguages];
89
    NSString* preferredLanguage = [languages firstObject];
90 91

    if ([NSLocale characterDirectionForLanguage:preferredLanguage] == NSLocaleLanguageDirectionRightToLeft) {
92
        msg_Dbg(getIntf(), "adapting interface since '%s' is a RTL language", [preferredLanguage UTF8String]);
93
        [_rateTextField setAlignment: NSLeftTextAlignment];
94
    }
95 96

    [self setRateControlsEnabled:NO];
97

98
#ifdef HAVE_SPARKLE
99 100
    [_checkForUpdate setAction:@selector(checkForUpdates:)];
    [_checkForUpdate setTarget:[SUUpdater sharedUpdater]];
101
#else
102
    [_checkForUpdate setEnabled:NO];
103
#endif
104

105
    NSString* keyString;
106
    vlc_value_t val;
107 108
    VLCStringUtility *stringUtility = [VLCStringUtility sharedInstance];
    char *key;
109

110
    /* Get ExtensionsManager */
111
    intf_thread_t *p_intf = getIntf();
112

113 114
    [self initStrings];

115
    key = config_GetPsz(p_intf, "key-quit");
116 117 118
    keyString = [NSString stringWithFormat:@"%s", key];
    [_quit setKeyEquivalent: [stringUtility VLCKeyToString: keyString]];
    [_quit setKeyEquivalentModifierMask: [stringUtility VLCModifiersToCocoa:keyString]];
119
    FREENULL(key);
120

121
    // do not assign play/pause key
122

123
    key = config_GetPsz(p_intf, "key-stop");
124 125 126
    keyString = [NSString stringWithFormat:@"%s", key];
    [_stop setKeyEquivalent: [stringUtility VLCKeyToString: keyString]];
    [_stop setKeyEquivalentModifierMask: [stringUtility VLCModifiersToCocoa:keyString]];
127
    FREENULL(key);
128

129
    key = config_GetPsz(p_intf, "key-prev");
130 131 132
    keyString = [NSString stringWithFormat:@"%s", key];
    [_previous setKeyEquivalent: [stringUtility VLCKeyToString: keyString]];
    [_previous setKeyEquivalentModifierMask: [stringUtility VLCModifiersToCocoa:keyString]];
133
    FREENULL(key);
134

135
    key = config_GetPsz(p_intf, "key-next");
136 137 138
    keyString = [NSString stringWithFormat:@"%s", key];
    [_next setKeyEquivalent: [stringUtility VLCKeyToString: keyString]];
    [_next setKeyEquivalentModifierMask: [stringUtility VLCModifiersToCocoa:keyString]];
139
    FREENULL(key);
140

141
    key = config_GetPsz(p_intf, "key-jump+short");
142 143 144
    keyString = [NSString stringWithFormat:@"%s", key];
    [_fwd setKeyEquivalent: [stringUtility VLCKeyToString: keyString]];
    [_fwd setKeyEquivalentModifierMask: [stringUtility VLCModifiersToCocoa:keyString]];
145
    FREENULL(key);
146

147
    key = config_GetPsz(p_intf, "key-jump-short");
148 149 150
    keyString = [NSString stringWithFormat:@"%s", key];
    [_bwd setKeyEquivalent: [stringUtility VLCKeyToString: keyString]];
    [_bwd setKeyEquivalentModifierMask: [stringUtility VLCModifiersToCocoa:keyString]];
151
    FREENULL(key);
152

153
    key = config_GetPsz(p_intf, "key-vol-up");
154 155 156
    keyString = [NSString stringWithFormat:@"%s", key];
    [_vol_up setKeyEquivalent: [stringUtility VLCKeyToString: keyString]];
    [_vol_up setKeyEquivalentModifierMask: [stringUtility VLCModifiersToCocoa:keyString]];
157
    FREENULL(key);
158

159
    key = config_GetPsz(p_intf, "key-vol-down");
160 161 162
    keyString = [NSString stringWithFormat:@"%s", key];
    [_vol_down setKeyEquivalent: [stringUtility VLCKeyToString: keyString]];
    [_vol_down setKeyEquivalentModifierMask: [stringUtility VLCModifiersToCocoa:keyString]];
163
    FREENULL(key);
164

165
    key = config_GetPsz(p_intf, "key-vol-mute");
166 167 168
    keyString = [NSString stringWithFormat:@"%s", key];
    [_mute setKeyEquivalent: [stringUtility VLCKeyToString: keyString]];
    [_mute setKeyEquivalentModifierMask: [stringUtility VLCModifiersToCocoa:keyString]];
169
    FREENULL(key);
170

171
    key = config_GetPsz(p_intf, "key-toggle-fullscreen");
172 173 174
    keyString = [NSString stringWithFormat:@"%s", key];
    [_fullscreenItem setKeyEquivalent: [stringUtility VLCKeyToString: keyString]];
    [_fullscreenItem setKeyEquivalentModifierMask: [stringUtility VLCModifiersToCocoa:keyString]];
175
    FREENULL(key);
176

177
    key = config_GetPsz(p_intf, "key-snapshot");
178 179 180
    keyString = [NSString stringWithFormat:@"%s", key];
    [_snapshot setKeyEquivalent: [stringUtility VLCKeyToString: keyString]];
    [_snapshot setKeyEquivalentModifierMask: [stringUtility VLCModifiersToCocoa:keyString]];
181
    FREENULL(key);
182

183
    key = config_GetPsz(p_intf, "key-random");
184 185 186
    keyString = [NSString stringWithFormat:@"%s", key];
    [_random setKeyEquivalent: [stringUtility VLCKeyToString: keyString]];
    [_random setKeyEquivalentModifierMask: [stringUtility VLCModifiersToCocoa:keyString]];
187
    FREENULL(key);
188

189
    key = config_GetPsz(p_intf, "key-zoom-half");
190 191 192
    keyString = [NSString stringWithFormat:@"%s", key];
    [_half_window setKeyEquivalent: [stringUtility VLCKeyToString: keyString]];
    [_half_window setKeyEquivalentModifierMask: [stringUtility VLCModifiersToCocoa:keyString]];
193
    FREENULL(key);
194

195
    key = config_GetPsz(p_intf, "key-zoom-original");
196 197 198
    keyString = [NSString stringWithFormat:@"%s", key];
    [_normal_window setKeyEquivalent: [stringUtility VLCKeyToString: keyString]];
    [_normal_window setKeyEquivalentModifierMask: [stringUtility VLCModifiersToCocoa:keyString]];
199
    FREENULL(key);
200

201
    key = config_GetPsz(p_intf, "key-zoom-double");
202 203 204
    keyString = [NSString stringWithFormat:@"%s", key];
    [_double_window setKeyEquivalent: [stringUtility VLCKeyToString: keyString]];
    [_double_window setKeyEquivalentModifierMask: [stringUtility VLCModifiersToCocoa:keyString]];
205
    FREENULL(key);
206 207 208 209 210 211 212 213

    [self setSubmenusEnabled: FALSE];

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

214 215
    [self setupVarMenuItem:_add_intf target: (vlc_object_t *)p_intf
                             var:"intf-add" selector: @selector(toggleVar:)];
216

217 218
    /* setup extensions menu */
    /* Let the ExtensionsManager itself build the menu */
219
    VLCExtensionsManager *extMgr = [[VLCMain sharedInstance] extensionsManager];
220
    [extMgr buildMenu:_extensionsMenu];
221
    [_extensions setEnabled: ([_extensionsMenu numberOfItems] > 0)];
222

223
    // FIXME: Implement preference for autoloading extensions on mac
224 225
    if (![extMgr isLoaded] && ![extMgr cannotLoad])
        [extMgr loadExtensions];
226

227
    /* setup post-proc menu */
228
    NSUInteger count = (NSUInteger) [_postprocessingMenu numberOfItems];
229
    if (count > 0)
230 231 232 233 234 235 236 237 238
        [_postprocessingMenu removeAllItems];

    NSMenuItem *mitem;
    [_postprocessingMenu setAutoenablesItems: YES];
    [_postprocessingMenu addItemWithTitle: _NS("Disable") action:@selector(togglePostProcessing:) keyEquivalent:@""];
    mitem = [_postprocessingMenu itemAtIndex: 0];
    [mitem setTag: -1];
    [mitem setEnabled: YES];
    [mitem setTarget: self];
239
    for (NSUInteger x = 1; x < 7; x++) {
240
        [_postprocessingMenu addItemWithTitle:[NSString stringWithFormat:_NS("Level %i"), x]
241 242
                                               action:@selector(togglePostProcessing:)
                                        keyEquivalent:@""];
243 244 245 246
        mitem = [_postprocessingMenu itemAtIndex:x];
        [mitem setEnabled:YES];
        [mitem setTag:x];
        [mitem setTarget:self];
247 248 249
    }
    char *psz_config = config_GetPsz(p_intf, "video-filter");
    if (psz_config) {
250
        if (!strstr(psz_config, "postproc"))
251
            [[_postprocessingMenu itemAtIndex:0] setState:NSOnState];
252
        else
253
            [[_postprocessingMenu itemWithTag:config_GetInt(p_intf, "postproc-q")] setState:NSOnState];
254 255
        free(psz_config);
    } else
256 257
        [[_postprocessingMenu itemAtIndex:0] setState:NSOnState];
    [_postprocessing setEnabled: NO];
258

259
    [self refreshAudioDeviceList];
260 261

    /* setup subtitles menu */
262 263 264 265 266 267 268
    // Persist those variables on the playlist
    playlist_t *p_playlist = pl_Get(getIntf());
    var_Create(p_playlist, "freetype-color", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);
    var_Create(p_playlist, "freetype-background-opacity", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);
    var_Create(p_playlist, "freetype-background-color", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);
    var_Create(p_playlist, "freetype-outline-thickness", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);

269 270 271 272
    [self setupMenu: _subtitle_textcolorMenu withIntList:"freetype-color" andSelector:@selector(switchSubtitleOption:)];
    [_subtitle_bgopacity_sld setIntValue: config_GetInt(VLC_OBJECT(p_intf), "freetype-background-opacity")];
    [self setupMenu: _subtitle_bgcolorMenu withIntList:"freetype-background-color" andSelector:@selector(switchSubtitleOption:)];
    [self setupMenu: _subtitle_outlinethicknessMenu withIntList:"freetype-outline-thickness" andSelector:@selector(switchSubtitleOption:)];
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291

    /* Build size menu based on different scale factors */
    struct {
        const char *const name;
        int scaleValue;
    } scaleValues[] = {
        { N_("Smaller"), 50},
        { N_("Small"),   75},
        { N_("Normal"), 100},
        { N_("Large"),  125},
        { N_("Larger"), 150},
        { NULL, 0 }
    };

    for(int i = 0; scaleValues[i].name; i++) {
        NSMenuItem *menuItem = [_subtitle_sizeMenu addItemWithTitle: _NS(scaleValues[i].name) action:@selector(switchSubtitleSize:) keyEquivalent:@""];
        [menuItem setTag:scaleValues[i].scaleValue];
        [menuItem setTarget: self];
    }
292 293 294 295 296 297 298
}

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

    [menu removeAllItems];
299
    p_item = config_FindConfig(psz_name);
300

301 302 303 304
    if (!p_item) {
        msg_Err(getIntf(), "couldn't create menu int list for item '%s' as it does not exist", psz_name);
        return;
    }
305 306 307 308 309 310 311

    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: @""];
312
        else {
313
            msg_Err(getIntf(), "item %d of pref %s failed to be created", i, psz_name);
314 315 316
            continue;
        }

317 318 319
        [mi setTarget:self];
        [mi setAction:selector];
        [mi setTag:p_item->list.i[i]];
320
        [mi setRepresentedObject:toNSStr(psz_name)];
321
        [menu addItem:mi];
322 323 324
        if (p_item->value.i == p_item->list.i[i])
            [mi setState:NSOnState];
    }
325 326 327 328 329
}

- (void)initStrings
{
    /* main menu */
330
    [_about setTitle: [_NS("About VLC media player") \
331
                           stringByAppendingString: @"..."]];
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360
    [_checkForUpdate setTitle: _NS("Check for Update...")];
    [_prefs setTitle: _NS("Preferences...")];
    [_extensions setTitle: _NS("Extensions")];
    [_extensionsMenu setTitle: _NS("Extensions")];
    [_addonManager setTitle: _NS("Addons Manager")];
    [_add_intf setTitle: _NS("Add Interface")];
    [_add_intfMenu setTitle: _NS("Add Interface")];
    [_services setTitle: _NS("Services")];
    [_hide setTitle: _NS("Hide VLC")];
    [_hide_others setTitle: _NS("Hide Others")];
    [_show_all setTitle: _NS("Show All")];
    [_quit setTitle: _NS("Quit VLC")];

    [_fileMenu setTitle: _ANS("1:File")];
    [_open_generic setTitle: _NS("Advanced Open File...")];
    [_open_file setTitle: _NS("Open File...")];
    [_open_disc setTitle: _NS("Open Disc...")];
    [_open_net setTitle: _NS("Open Network...")];
    [_open_capture setTitle: _NS("Open Capture Device...")];
    [_open_recent setTitle: _NS("Open Recent")];
    [_close_window setTitle: _NS("Close Window")];
    [_convertandsave setTitle: _NS("Convert / Stream...")];
    [_save_playlist setTitle: _NS("Save Playlist...")];
    [_revealInFinder setTitle: _NS("Reveal in Finder")];

    [_editMenu setTitle: _NS("Edit")];
    [_cutItem setTitle: _NS("Cut")];
    [_mcopyItem setTitle: _NS("Copy")];
    [_pasteItem setTitle: _NS("Paste")];
361
    [_clearItem setTitle: _NS("Delete")];
362
    [_select_all setTitle: _NS("Select All")];
363
    [_findItem setTitle: _NS("Find")];
364 365 366

    [_viewMenu setTitle: _NS("View")];
    [_toggleJumpButtons setTitle: _NS("Show Previous & Next Buttons")];
367
    [_toggleJumpButtons setState: var_InheritBool(getIntf(), "macosx-show-playback-buttons")];
368
    [_togglePlaymodeButtons setTitle: _NS("Show Shuffle & Repeat Buttons")];
369
    [_togglePlaymodeButtons setState: var_InheritBool(getIntf(), "macosx-show-playmode-buttons")];
370
    [_toggleEffectsButton setTitle: _NS("Show Audio Effects Button")];
371
    [_toggleEffectsButton setState: var_InheritBool(getIntf(), "macosx-show-effects-button")];
372
    [_toggleSidebar setTitle: _NS("Show Sidebar")];
373
    [_toggleSidebar setState: var_InheritBool(getIntf(), "macosx-show-sidebar")];
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 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 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 475 476 477 478 479
    [_playlistTableColumns setTitle: _NS("Playlist Table Columns")];

    [_controlsMenu setTitle: _NS("Playback")];
    [_play setTitle: _NS("Play")];
    [_stop setTitle: _NS("Stop")];
    [_record setTitle: _NS("Record")];
    [_rate setView: _rate_view];
    [_rateLabel setStringValue: _NS("Playback Speed")];
    [_rate_slowerLabel setStringValue: _NS("Slower")];
    [_rate_normalLabel setStringValue: _NS("Normal")];
    [_rate_fasterLabel setStringValue: _NS("Faster")];
    [_trackSynchronization setTitle: _NS("Track Synchronization")];
    [_previous setTitle: _NS("Previous")];
    [_next setTitle: _NS("Next")];
    [_random setTitle: _NS("Random")];
    [_repeat setTitle: _NS("Repeat One")];
    [_loop setTitle: _NS("Repeat All")];
    [_AtoBloop setTitle: _NS("A→B Loop")];
    [_quitAfterPB setTitle: _NS("Quit after Playback")];
    [_fwd setTitle: _NS("Step Forward")];
    [_bwd setTitle: _NS("Step Backward")];
    [_jumpToTime setTitle: _NS("Jump to Time")];
    [_program setTitle: _NS("Program")];
    [_programMenu setTitle: _NS("Program")];
    [_title setTitle: _NS("Title")];
    [_titleMenu setTitle: _NS("Title")];
    [_chapter setTitle: _NS("Chapter")];
    [_chapterMenu setTitle: _NS("Chapter")];

    [_audioMenu setTitle: _NS("Audio")];
    [_vol_up setTitle: _NS("Increase Volume")];
    [_vol_down setTitle: _NS("Decrease Volume")];
    [_mute setTitle: _NS("Mute")];
    [_audiotrack setTitle: _NS("Audio Track")];
    [_audiotrackMenu setTitle: _NS("Audio Track")];
    [_channels setTitle: _NS("Stereo audio mode")];
    [_channelsMenu setTitle: _NS("Stereo audio mode")];
    [_audioDevice setTitle: _NS("Audio Device")];
    [_audioDeviceMenu setTitle: _NS("Audio Device")];
    [_visual setTitle: _NS("Visualizations")];
    [_visualMenu setTitle: _NS("Visualizations")];

    [_videoMenu setTitle: _NS("Video")];
    [_half_window setTitle: _NS("Half Size")];
    [_normal_window setTitle: _NS("Normal Size")];
    [_double_window setTitle: _NS("Double Size")];
    [_fittoscreen setTitle: _NS("Fit to Screen")];
    [_fullscreenItem setTitle: _NS("Fullscreen")];
    [_floatontop setTitle: _NS("Float on Top")];
    [_snapshot setTitle: _NS("Snapshot")];
    [_videotrack setTitle: _NS("Video Track")];
    [_videotrackMenu setTitle: _NS("Video Track")];
    [_aspect_ratio setTitle: _NS("Aspect ratio")];
    [_aspect_ratioMenu setTitle: _NS("Aspect ratio")];
    [_crop setTitle: _NS("Crop")];
    [_cropMenu setTitle: _NS("Crop")];
    [_screen setTitle: _NS("Fullscreen Video Device")];
    [_screenMenu setTitle: _NS("Fullscreen Video Device")];
    [_deinterlace setTitle: _NS("Deinterlace")];
    [_deinterlaceMenu setTitle: _NS("Deinterlace")];
    [_deinterlace_mode setTitle: _NS("Deinterlace mode")];
    [_deinterlace_modeMenu setTitle: _NS("Deinterlace mode")];
    [_postprocessing setTitle: _NS("Post processing")];
    [_postprocessingMenu setTitle: _NS("Post processing")];

    [_subtitlesMenu setTitle:_NS("Subtitles")];
    [_openSubtitleFile setTitle: _NS("Add Subtitle File...")];
    [_subtitle_track setTitle: _NS("Subtitles Track")];
    [_subtitle_tracksMenu setTitle: _NS("Subtitles Track")];
    [_subtitle_size setTitle: _NS("Text Size")];
    [_subtitle_textcolor setTitle: _NS("Text Color")];
    [_subtitle_outlinethickness setTitle: _NS("Outline Thickness")];
    [_subtitle_bgopacity setView: _subtitle_bgopacity_view];
    [_subtitle_bgopacityLabel setStringValue: _NS("Background Opacity")];
    [_subtitle_bgopacityLabel_gray setStringValue: _NS("Background Opacity")];
    [_subtitle_bgcolor setTitle: _NS("Background Color")];
    [_teletext setTitle: _NS("Teletext")];
    [_teletext_transparent setTitle: _NS("Transparent")];
    [_teletext_index setTitle: _NS("Index")];
    [_teletext_red setTitle: _NS("Red")];
    [_teletext_green setTitle: _NS("Green")];
    [_teletext_yellow setTitle: _NS("Yellow")];
    [_teletext_blue setTitle: _NS("Blue")];

    [_windowMenu setTitle: _NS("Window")];
    [_minimize setTitle: _NS("Minimize")];
    [_zoom_window setTitle: _NS("Zoom")];
    [_player setTitle: _NS("Player...")];
    [_controller setTitle: _NS("Main Window...")];
    [_audioeffects setTitle: _NS("Audio Effects...")];
    [_videoeffects setTitle: _NS("Video Effects...")];
    [_bookmarks setTitle: _NS("Bookmarks...")];
    [_playlist setTitle: _NS("Playlist...")];
    [_info setTitle: _NS("Media Information...")];
    [_messages setTitle: _NS("Messages...")];
    [_errorsAndWarnings setTitle: _NS("Errors and Warnings...")];

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

    [_helpMenu setTitle: _NS("Help")];
    [_help setTitle: _NS("VLC media player Help...")];
    [_license setTitle: _NS("License")];
    [_documentation setTitle: _NS("Online Documentation...")];
    [_website setTitle: _NS("VideoLAN Website...")];
    [_donation setTitle: _NS("Make a donation...")];
    [_forum setTitle: _NS("Online Forum...")];
480 481

    /* dock menu */
482 483 484 485 486
    [_dockMenuplay setTitle: _NS("Play")];
    [_dockMenustop setTitle: _NS("Stop")];
    [_dockMenunext setTitle: _NS("Next")];
    [_dockMenuprevious setTitle: _NS("Previous")];
    [_dockMenumute setTitle: _NS("Mute")];
487 488

    /* vout menu */
489 490 491 492 493 494 495 496 497
    [_voutMenuplay setTitle: _NS("Play")];
    [_voutMenustop setTitle: _NS("Stop")];
    [_voutMenuprev setTitle: _NS("Previous")];
    [_voutMenunext setTitle: _NS("Next")];
    [_voutMenuvolup setTitle: _NS("Volume Up")];
    [_voutMenuvoldown setTitle: _NS("Volume Down")];
    [_voutMenumute setTitle: _NS("Mute")];
    [_voutMenufullscreen setTitle: _NS("Fullscreen")];
    [_voutMenusnapshot setTitle: _NS("Snapshot")];
498 499
}

500
#pragma mark - Termination
501 502 503 504

- (void)releaseRepresentedObjects:(NSMenu *)the_menu
{
    NSArray *menuitems_array = [the_menu itemArray];
505
    NSUInteger menuItemCount = [menuitems_array count];
506
    for (NSUInteger i=0; i < menuItemCount; i++) {
507
        NSMenuItem *one_item = [menuitems_array objectAtIndex:i];
508
        if ([one_item hasSubmenu])
509 510 511 512 513 514
            [self releaseRepresentedObjects: [one_item submenu]];

        [one_item setRepresentedObject:NULL];
    }
}

515
#pragma mark - Interface update
516 517 518

- (void)setupMenus
{
519
    playlist_t *p_playlist = pl_Get(getIntf());
520
    input_thread_t *p_input = playlist_CurrentInput(p_playlist);
521
    if (p_input != NULL) {
522 523
        [self setupVarMenuItem:_program target: (vlc_object_t *)p_input
                                 var:"program" selector: @selector(toggleVar:)];
524

525 526
        [self setupVarMenuItem:_title target: (vlc_object_t *)p_input
                                 var:"title" selector: @selector(toggleVar:)];
527

528 529
        [self setupVarMenuItem:_chapter target: (vlc_object_t *)p_input
                                 var:"chapter" selector: @selector(toggleVar:)];
530

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

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

537 538
        [self setupVarMenuItem:_subtitle_track target: (vlc_object_t *)p_input
                                 var:"spu-es" selector: @selector(toggleVar:)];
539

540
        audio_output_t *p_aout = playlist_GetAout(p_playlist);
541
        if (p_aout != NULL) {
542 543
            [self setupVarMenuItem:_channels target: (vlc_object_t *)p_aout
                                     var:"stereo-mode" selector: @selector(toggleVar:)];
544

545 546
            [self setupVarMenuItem:_visual target: (vlc_object_t *)p_aout
                                     var:"visual" selector: @selector(toggleVar:)];
547
            vlc_object_release(p_aout);
548 549
        }

550
        vout_thread_t *p_vout = getVoutForActiveWindow();
551

552
        if (p_vout != NULL) {
553 554
            [self setupVarMenuItem:_aspect_ratio target: (vlc_object_t *)p_vout
                                     var:"aspect-ratio" selector: @selector(toggleVar:)];
555

556 557
            [self setupVarMenuItem:_crop target: (vlc_object_t *) p_vout
                                     var:"crop" selector: @selector(toggleVar:)];
558

559 560
            [self setupVarMenuItem:_deinterlace target: (vlc_object_t *)p_vout
                                     var:"deinterlace" selector: @selector(toggleVar:)];
561

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

565
            vlc_object_release(p_vout);
566 567

            [self refreshVoutDeviceMenu:nil];
568
        }
569
        [_postprocessing setEnabled:YES];
570
        vlc_object_release(p_input);
571
    } else {
572
        [_postprocessing setEnabled:NO];
573
    }
574 575
}

576
- (void)refreshVoutDeviceMenu:(NSNotification *)notification
577
{
578 579
    NSUInteger count = (NSUInteger) [_screenMenu numberOfItems];
    NSMenu *submenu = _screenMenu;
580
    if (count > 0)
581 582 583 584 585 586 587 588 589 590 591
        [submenu removeAllItems];

    NSArray *screens = [NSScreen screens];
    NSMenuItem *mitem;
    count = [screens count];
    [_screen setEnabled: YES];
    [submenu addItemWithTitle: _NS("Default") action:@selector(toggleFullscreenDevice:) keyEquivalent:@""];
    mitem = [submenu itemAtIndex: 0];
    [mitem setTag: 0];
    [mitem setEnabled: YES];
    [mitem setTarget: self];
592
    NSRect s_rect;
593
    for (NSUInteger i = 0; i < count; i++) {
594 595
        s_rect = [[screens objectAtIndex:i] frame];
        [submenu addItemWithTitle: [NSString stringWithFormat: @"%@ %li (%ix%i)", _NS("Screen"), i+1,
596
                                      (int)s_rect.size.width, (int)s_rect.size.height] action:@selector(toggleFullscreenDevice:) keyEquivalent:@""];
597 598 599 600
        mitem = [submenu itemAtIndex:i+1];
        [mitem setTag: (int)[[screens objectAtIndex:i] displayID]];
        [mitem setEnabled: YES];
        [mitem setTarget: self];
601
    }
602
    [[submenu itemWithTag: var_InheritInteger(getIntf(), "macosx-vdev")] setState: NSOnState];
603 604 605 606
}

- (void)setSubmenusEnabled:(BOOL)b_enabled
{
607 608 609 610 611 612 613 614 615 616 617 618 619
    [_program setEnabled: b_enabled];
    [_title setEnabled: b_enabled];
    [_chapter setEnabled: b_enabled];
    [_audiotrack setEnabled: b_enabled];
    [_visual setEnabled: b_enabled];
    [_videotrack setEnabled: b_enabled];
    [_subtitle_track setEnabled: b_enabled];
    [_channels setEnabled: b_enabled];
    [_deinterlace setEnabled: b_enabled];
    [_deinterlace_mode setEnabled: b_enabled];
    [_screen setEnabled: b_enabled];
    [_aspect_ratio setEnabled: b_enabled];
    [_crop setEnabled: b_enabled];
620 621 622 623
}

- (void)setSubtitleMenuEnabled:(BOOL)b_enabled
{
624
    [_openSubtitleFile setEnabled: b_enabled];
625
    if (b_enabled) {
626 627
        [_subtitle_bgopacityLabel_gray setHidden: YES];
        [_subtitle_bgopacityLabel setHidden: NO];
628
    } else {
629 630
        [_subtitle_bgopacityLabel_gray setHidden: NO];
        [_subtitle_bgopacityLabel setHidden: YES];
631
    }
632 633
    [_subtitle_bgopacity_sld setEnabled: b_enabled];
    [_teletext setEnabled: b_enabled];
634 635
}

636 637
- (void)setRateControlsEnabled:(BOOL)b_enabled
{
638 639
    [_rate_sld setEnabled: b_enabled];
    [_rate_sld setIntValue: [[VLCCoreInteraction sharedInstance] playbackRate]];
640
    int i = [[VLCCoreInteraction sharedInstance] playbackRate];
641
    double speed =  pow(2, (double)i / 17);
642
    [_rateTextField setStringValue: [NSString stringWithFormat:@"%.2fx", speed]];
643

644
    NSColor *color = b_enabled ? [NSColor controlTextColor] : [NSColor disabledControlTextColor];
645

646 647 648 649 650
    [_rateLabel setTextColor:color];
    [_rate_slowerLabel setTextColor:color];
    [_rate_normalLabel setTextColor:color];
    [_rate_fasterLabel setTextColor:color];
    [_rateTextField setTextColor:color];
651

652
    [self setSubtitleMenuEnabled: b_enabled];
653 654
}

655
#pragma mark - View
656 657 658

- (IBAction)toggleEffectsButton:(id)sender
{
659
    BOOL b_value = !var_InheritBool(getIntf(), "macosx-show-effects-button");
660
    config_PutInt(getIntf(), "macosx-show-effects-button", b_value);
661
    [(VLCMainWindowControlsBar *)[[[VLCMain sharedInstance] mainWindow] controlsBar] toggleEffectsButton];
662
    [_toggleEffectsButton setState: b_value];
663 664
}

665 666
- (IBAction)toggleJumpButtons:(id)sender
{
667
    BOOL b_value = !var_InheritBool(getIntf(), "macosx-show-playback-buttons");
668
    config_PutInt(getIntf(), "macosx-show-playback-buttons", b_value);
669

670
    [(VLCMainWindowControlsBar *)[[[VLCMain sharedInstance] mainWindow] controlsBar] toggleJumpButtons];
671 672
    [[[VLCMain sharedInstance] voutController] updateWindowsUsingBlock:^(VLCVideoWindowCommon *window) {
        [[window controlsBar] toggleForwardBackwardMode: b_value];
673 674
    }];

675
    [_toggleJumpButtons setState: b_value];
676 677
}

678 679
- (IBAction)togglePlaymodeButtons:(id)sender
{
680
    BOOL b_value = !var_InheritBool(getIntf(), "macosx-show-playmode-buttons");
681
    config_PutInt(getIntf(), "macosx-show-playmode-buttons", b_value);
682
    [(VLCMainWindowControlsBar *)[[[VLCMain sharedInstance] mainWindow] controlsBar] togglePlaymodeButtons];
683
    [_togglePlaymodeButtons setState: b_value];
684 685
}

686 687 688 689 690 691 692
- (IBAction)toggleSidebar:(id)sender
{
    [[[VLCMain sharedInstance] mainWindow] toggleLeftSubSplitView];
}

- (void)updateSidebarMenuItem
{
693
    [_toggleSidebar setState: var_InheritBool(getIntf(), "macosx-show-sidebar")];
694 695
}

696
#pragma mark - Playback
697

698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725
- (IBAction)play:(id)sender
{
    [[VLCCoreInteraction sharedInstance] playOrPause];
}

- (IBAction)stop:(id)sender
{
    [[VLCCoreInteraction sharedInstance] stop];
}

- (IBAction)prev:(id)sender
{
    [[VLCCoreInteraction sharedInstance] previous];
}

- (IBAction)next:(id)sender
{
    [[VLCCoreInteraction sharedInstance] next];
}

- (IBAction)random:(id)sender
{
    [[VLCCoreInteraction sharedInstance] shuffle];
}

- (IBAction)repeat:(id)sender
{
    vlc_value_t val;
726
    intf_thread_t *p_intf = getIntf();
727 728 729 730 731 732 733 734 735 736 737 738
    playlist_t *p_playlist = pl_Get(p_intf);

    var_Get(p_playlist, "repeat", &val);
    if (! val.b_bool)
        [[VLCCoreInteraction sharedInstance] repeatOne];
    else
        [[VLCCoreInteraction sharedInstance] repeatOff];
}

- (IBAction)loop:(id)sender
{
    vlc_value_t val;
739
    intf_thread_t *p_intf = getIntf();
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
    playlist_t *p_playlist = pl_Get(p_intf);

    var_Get(p_playlist, "loop", &val);
    if (! val.b_bool)
        [[VLCCoreInteraction sharedInstance] repeatAll];
    else
        [[VLCCoreInteraction sharedInstance] repeatOff];
}

- (IBAction)forward:(id)sender
{
    [[VLCCoreInteraction sharedInstance] forward];
}

- (IBAction)backward:(id)sender
{
    [[VLCCoreInteraction sharedInstance] backward];
}

- (IBAction)volumeUp:(id)sender
{
    [[VLCCoreInteraction sharedInstance] volumeUp];
}

- (IBAction)volumeDown:(id)sender
{
    [[VLCCoreInteraction sharedInstance] volumeDown];
}

- (IBAction)mute:(id)sender
{
    [[VLCCoreInteraction sharedInstance] toggleMute];
}

- (void)lockVideosAspectRatio:(id)sender
{
    [[VLCCoreInteraction sharedInstance] setAspectRatioIsLocked: ![sender state]];
    [sender setState: [[VLCCoreInteraction sharedInstance] aspectRatioIsLocked]];
}

780 781
- (IBAction)quitAfterPlayback:(id)sender
{
782
    playlist_t *p_playlist = pl_Get(getIntf());
783 784
    bool b_value = !var_CreateGetBool(p_playlist, "play-and-exit");
    var_SetBool(p_playlist, "play-and-exit", b_value);
785
    config_PutInt(getIntf(), "play-and-exit", b_value);
786 787
}

788 789 790 791 792 793 794
- (IBAction)toggleRecord:(id)sender
{
    [[VLCCoreInteraction sharedInstance] toggleRecord];
}

- (void)updateRecordState:(BOOL)b_value
{
795
    [_record setState:b_value];
796 797 798 799
}

- (IBAction)setPlaybackRate:(id)sender
{
800
    [[VLCCoreInteraction sharedInstance] setPlaybackRate: [_rate_sld intValue]];
801
    int i = [[VLCCoreInteraction sharedInstance] playbackRate];
802
    double speed =  pow(2, (double)i / 17);
803
    [_rateTextField setStringValue: [NSString stringWithFormat:@"%.2fx", speed]];
804 805 806 807 808
}

- (void)updatePlaybackRate
{
    int i = [[VLCCoreInteraction sharedInstance] playbackRate];
809
    double speed =  pow(2, (double)i / 17);
810 811
    [_rateTextField setStringValue: [NSString stringWithFormat:@"%.2fx", speed]];
    [_rate_sld setIntValue: i];
812 813
}

814 815 816 817 818
- (IBAction)toggleAtoBloop:(id)sender
{
    [[VLCCoreInteraction sharedInstance] setAtoB];
}

819 820
- (IBAction)goToSpecificTime:(id)sender
{
821
    input_thread_t *p_input = pl_CurrentInput(getIntf());
822 823 824 825 826 827 828 829 830 831 832 833
    if (p_input) {
        /* we can obviously only do that if an input is available */
        int64_t length = var_GetInteger(p_input, "length");
        [_timeSelectionPanel setMaxValue:(length / CLOCK_FREQ)];
        int64_t pos = var_GetInteger(p_input, "time");
        [_timeSelectionPanel setJumpTimeValue: (pos / CLOCK_FREQ)];
        [_timeSelectionPanel runModalForWindow:[NSApp mainWindow]
                             completionHandler:^(NSInteger returnCode, int64_t returnTime) {

            if (returnCode != NSOKButton)
                return;

834
            input_thread_t *p_input = pl_CurrentInput(getIntf());
835 836 837
            if (p_input) {
                input_Control(p_input, INPUT_SET_TIME, (int64_t)(returnTime *1000000));
                vlc_object_release(p_input);
838
            }
839
        }];
840

841
        vlc_object_release(p_input);
842 843 844
    }
}

845 846
#pragma mark - audio menu

847 848 849 850 851
- (void)refreshAudioDeviceList
{
    char **ids, **names;
    char *currentDevice;

852
    [_audioDeviceMenu removeAllItems];
853

854
    audio_output_t *p_aout = getAout();
855 856 857 858
    if (!p_aout)
        return;

    int n = aout_DevicesList(p_aout, &ids, &names);
859 860
    if (n == -1) {
        vlc_object_release(p_aout);
861
        return;
862
    }
863 864

    currentDevice = aout_DeviceGet(p_aout);
865
    NSMenuItem *_tmp;
866 867

    for (NSUInteger x = 0; x < n; x++) {
868 869 870
        _tmp = [_audioDeviceMenu addItemWithTitle:toNSStr(names[x]) action:@selector(toggleAudioDevice:) keyEquivalent:@""];
        [_tmp setTarget:self];
        [_tmp setTag:[[NSString stringWithFormat:@"%s", ids[x]] intValue]];
871 872 873
    }
    vlc_object_release(p_aout);

874
    [[_audioDeviceMenu itemWithTag:[[NSString stringWithFormat:@"%s", currentDevice] intValue]] setState:NSOnState];
875

876 877
    free(currentDevice);

878 879 880 881 882 883 884
    for (NSUInteger x = 0; x < n; x++) {
        free(ids[x]);
        free(names[x]);
    }
    free(ids);
    free(names);

885 886
    [_audioDeviceMenu setAutoenablesItems:YES];
    [_audioDevice setEnabled:YES];
887 888
}

889
- (void)toggleAudioDevice:(id)sender
890
{
891
    audio_output_t *p_aout = getAout();
892 893
    if (!p_aout)
        return;
894 895 896 897

    int returnValue = 0;

    if ([sender tag] > 0)
898
        returnValue = aout_DeviceSet(p_aout, [[NSString stringWithFormat:@"%li", [sender tag]] UTF8String]);
899
    else
900
        returnValue = aout_DeviceSet(p_aout, NULL);
901 902

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

905
    vlc_object_release(p_aout);
906 907 908
    [self refreshAudioDeviceList];
}

909
#pragma mark - video menu
910

911 912 913 914 915 916 917
- (IBAction)toggleFullscreen:(id)sender
{
    [[VLCCoreInteraction sharedInstance] toggleFullscreen];
}

- (IBAction)resizeVideoWindow:(id)sender
{
918
    input_thread_t *p_input = pl_CurrentInput(getIntf());
919
    if (p_input) {
920
        vout_thread_t *p_vout = getVoutForActiveWindow();
921
        if (p_vout) {
922
            if (sender == _half_window)
923
                var_SetFloat(p_vout, "zoom", 0.5);
924
            else if (sender == _normal_window)
925
                var_SetFloat(p_vout, "zoom", 1.0);
926
            else if (sender == _double_window)
927
                var_SetFloat(p_vout, "zoom", 2.0);
928 929
            else
            {
930
                [[NSApp keyWindow] performZoom:sender];
931
            }
932
            vlc_object_release(p_vout);
933
        }
934
        vlc_object_release(p_input);
935 936 937 938 939
    }
}

- (IBAction)floatOnTop:(id)sender
{
940
    input_thread_t *p_input = pl_CurrentInput(getIntf());
941
    if (p_input) {
942
        vout_thread_t *p_vout = getVoutForActiveWindow();
943
        if (p_vout) {
944
            BOOL b_fs = var_ToggleBool(p_vout, "video-on-top");
945
            var_SetBool(pl_Get(getIntf()), "video-on-top", b_fs);
946

947
            vlc_object_release(p_vout);
948
        }
949
        vlc_object_release(p_input);
950 951 952 953 954
    }
}

- (IBAction)createVideoSnapshot:(id)sender
{
955
    input_thread_t *p_input = pl_CurrentInput(getIntf());
956
    if (p_input) {
957
        vout_thread_t *p_vout = getVoutForActiveWindow();
958 959 960
        if (p_vout) {
            var_TriggerCallback(p_vout, "video-snapshot");
            vlc_object_release(p_vout);
961
        }
962
        vlc_object_release(p_input);
963 964 965
    }
}

966 967
- (void)_disablePostProcessing
{
968
    [[VLCCoreInteraction sharedInstance] setVideoFilter:"postproc" on:false];
969 970 971 972
}

- (void)_enablePostProcessing
{
973
    [[VLCCoreInteraction sharedInstance] setVideoFilter:"postproc" on:true];
974 975
}

976
- (void)togglePostProcessing:(id)sender
977
{
978
    char *psz_name = "postproc";
979
    NSInteger count = [_postprocessingMenu numberOfItems];
980
    for (NSUInteger x = 0; x < count; x++)
981
        [[_postprocessingMenu itemAtIndex:x] setState:NSOffState];
982 983 984 985 986 987 988 989

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

990
        [[VLCCoreInteraction sharedInstance] setVideoFilterProperty:"postproc-q" forFilter:"postproc" withValue:(vlc_value_t){ .i_int = [sender tag] }];
991 992 993
    }
}

994
- (void)toggleFullscreenDevice:(id)sender
995
{
996
    config_PutInt(getIntf(), "macosx-vdev", [sender tag]);
997 998 999
    [self refreshVoutDeviceMenu: nil];
}

1000
#pragma mark - Subtitles Menu
1001

1002 1003 1004
- (IBAction)addSubtitleFile:(id)sender
{
    NSInteger i_returnValue = 0;
1005
    input_thread_t *p_input = pl_CurrentInput(getIntf());
1006 1007 1008 1009 1010 1011 1012 1013 1014 1015
    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);
1016

1017 1018 1019
    if (!path)
        path = strdup("");

1020
    NSOpenPanel *openPanel = [NSOpenPanel openPanel];
1021 1022 1023
    [openPanel setCanChooseFiles: YES];
    [openPanel setCanChooseDirectories: NO];
    [openPanel setAllowsMultipleSelection: YES];
1024

1025
    [openPanel setAllowedFileTypes: [NSArray arrayWithObjects:@"cdg",@"idx",@"srt",@"sub",@"utf",@"ass",@"ssa",@"aqt",@"jss",@"psb",@"rt",@"smi",@"txt",@"smil",@"stl",@"usf",@"dks",@"pjs",@"mpl2",@"mks",@"vtt",@"ttml",@"dfxp",nil]];
1026

1027
    NSURL *url = [NSURL URLWithString:[toNSStr(path) stringByExpandingTildeInPath]];
1028 1029
    url = [url URLByDeletingLastPathComponent];
    [openPanel setDirectoryURL: url];
1030
    free(path);
1031
    vlc_object_release(p_input);
1032

1033 1034
    i_returnValue = [openPanel runModal];

1035 1036
    if (i_returnValue == NSOKButton)
        [[VLCCoreInteraction sharedInstance] addSubtitlesToCurrentInput:[openPanel URLs]];
1037 1038
}

1039 1040 1041
- (void)switchSubtitleSize:(id)sender
{
    int intValue = [sender tag];
1042
    var_SetInteger(pl_Get(getIntf()), "sub-text-scale", intValue);
1043 1044 1045
}


1046
- (void)switchSubtitleOption:(id)sender
1047 1048 1049 1050
{
    int intValue = [sender tag];
    NSString *representedObject = [sender representedObject];

1051
    var_SetInteger(pl_Get(getIntf()), [representedObject UTF8String], intValue);
1052 1053

    NSMenu *menu = [sender menu];
1054
    NSUInteger count = (NSUInteger) [menu numberOfItems];
1055 1056 1057
    for (NSUInteger x = 0; x < count; x++)
        [[menu itemAtIndex:x] setState:NSOffState];
    [[menu itemWithTag:intValue] setState:NSOnState];
1058 1059 1060 1061
}

- (IBAction)switchSubtitleBackgroundOpacity:(id)sender
{
1062
    var_SetInteger(pl_Get(getIntf()), "freetype-background-opacity", [sender intValue]);
1063 1064
}

1065 1066 1067
- (IBAction)telxTransparent:(id)sender
{
    vlc_object_t *p_vbi;
1068
    p_vbi = (vlc_object_t *) vlc_object_find_name(pl_Get(getIntf()), "zvbi");
1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092
    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;

1093
    p_vbi = (vlc_object_t *) vlc_object_find_name(pl_Get(getIntf()), "zvbi");
1094 1095 1096 1097 1098 1099
    if (p_vbi) {
        var_SetInteger(p_vbi, "vbi-page", i_page);
        vlc_object_release(p_vbi);
    }
}

1100
#pragma mark - Panels
1101 1102 1103

- (IBAction)intfOpenFile:(id)sender
{
1104 1105 1106
    [[[VLCMain sharedInstance] open] openFileWithAction:^(NSArray *files) {
        [[[VLCMain sharedInstance] playlist] addPlaylistItems:files];
    }];
1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128
}

- (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];
}

1129 1130
- (IBAction)savePlaylist:(id)sender
{
1131
    playlist_t *p_playlist = pl_Get(getIntf());
1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163

    NSSavePanel *savePanel = [NSSavePanel savePanel];
    NSString * name = [NSString stringWithFormat: @"%@", _NS("Untitled")];

    [NSBundle loadNibNamed:@"PlaylistAccessoryView" owner:self];

    [_playlistSaveAccessoryText setStringValue: _NS("File Format:")];
    [[_playlistSaveAccessoryPopup itemAtIndex:0] setTitle: _NS("Extended M3U")];
    [[_playlistSaveAccessoryPopup itemAtIndex:1] setTitle: _NS("XML Shareable Playlist Format (XSPF)")];
    [[_playlistSaveAccessoryPopup itemAtIndex:2] setTitle: _NS("HTML playlist")];

    [savePanel setTitle: _NS("Save Playlist")];
    [savePanel setPrompt: _NS("Save")];
    [savePanel setAccessoryView: _playlistSaveAccessoryView];
    [savePanel setNameFieldStringValue: name];

    if ([savePanel runModal] == NSFileHandlingPanelOKButton) {
        NSString *filename = [[savePanel URL] path];

        if ([_playlistSaveAccessoryPopup indexOfSelectedItem] == 0) {
            NSString *actualFilename;
            NSRange range;
            range.location = [filename length] - [@".m3u" length];
            range.length = [@".m3u" length];

            if ([filename compare:@".m3u" options: NSCaseInsensitiveSearch range: range] != NSOrderedSame)
                actualFilename = [NSString stringWithFormat: @"%@.m3u", filename];
            else
                actualFilename = filename;

            playlist_Export(p_playlist,
                            [actualFilename fileSystemRepresentation],
1164
                            true, "export-m3u");
1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177
        } else if ([_playlistSaveAccessoryPopup indexOfSelectedItem] == 1) {
            NSString *actualFilename;
            NSRange range;
            range.location = [filename length] - [@".xspf" length];
            range.length = [@".xspf" length];

            if ([filename compare:@".xspf" options: NSCaseInsensitiveSearch range: range] != NSOrderedSame)
                actualFilename = [NSString stringWithFormat: @"%@.xspf", filename];
            else
                actualFilename = filename;

            playlist_Export(p_playlist,
                            [actualFilename fileSystemRepresentation],
1178
                            true, "export-xspf");
1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191
        } else {
            NSString *actualFilename;
            NSRange range;
            range.location = [filename length] - [@".html" length];
            range.length = [@".html" length];

            if ([filename compare:@".html" options: NSCaseInsensitiveSearch range: range] != NSOrderedSame)
                actualFilename = [NSString stringWithFormat: @"%@.html", filename];
            else
                actualFilename = filename;

            playlist_Export(p_playlist,
                            [actualFilename fileSystemRepresentation],
1192
                            true, "export-html");
1193 1194
        }
    }
1195 1196
}

1197 1198
- (IBAction)showConvertAndSave:(id)sender
{
1199
    [[[VLCMain sharedInstance] convertAndSaveWindow] showWindow:self];
1200 1201
}

1202 1203
- (IBAction)showVideoEffects:(id)sender
{
1204
    [[[VLCMain sharedInstance] videoEffectsPanel] toggleWindow:sender];
1205 1206 1207 1208
}

- (IBAction)showTrackSynchronization:(id)sender
{
1209
    [[[VLCMain sharedInstance] trackSyncPanel] toggleWindow:sender];
1210 1211 1212 1213
}

- (IBAction)showAudioEffects:(id)sender
{
1214
    [[[VLCMain sharedInstance] audioEffectsPanel] toggleWindow:sender];
1215 1216 1217 1218
}

- (IBAction)showBookmarks:(id)sender
{
1219
    [[[VLCMain sharedInstance] bookmarks] toggleWindow:sender];