VLCMainMenu.m 57.1 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 26
#import "intf.h"

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

31
#import "VLCAboutWindowController.h"
32
#import "open.h"
33
#import "VLCAudioEffectsWindowController.h"
34
#import "VLCTrackSynchronizationWindowController.h"
35
#import "VLCHelpWindowController.h"
36
#import "VLCVideoEffectsWindowController.h"
37
#import "VLCBookmarksWindowController.h"
38
#import "simple_prefs.h"
39 40
#import "VLCPlaylist.h"
#import "VLCPlaylistInfo.h"
41
#import "VideoView.h"
42
#import "VLCCoreInteraction.h"
43
#import "VLCMainWindow.h"
44
#import "ControlsBar.h"
45
#import "ExtensionsManager.h"
46
#import "VLCConvertAndSaveWindowController.h"
47
#import "VLCDebugMessageWindowController.h"
48
#import "VLCAddonsWindowController.h"
49
#import "VLCTimeSelectionPanelController.h"
50
#import "VLCRendererDialog.h"
51

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

56 57
@interface VLCMainMenu()
{
58
    VLCAboutWindowController *_aboutWindowController;
59
    VLCHelpWindowController  *_helpWindowController;
60
    VLCAddonsWindowController *_addonsController;
61
    VLCRendererDialog *_rendererDialog;
62

63
    NSMenu *_playlistTableColumnsContextMenu;
64 65 66

    __strong VLCTimeSelectionPanelController *_timeSelectionPanel;

67 68 69
}
@end

70 71
@implementation VLCMainMenu

72
#pragma mark - Initialization
73 74 75

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

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

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

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

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

    [self setRateControlsEnabled:NO];
96

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

104
    NSString* keyString;
105 106
    playlist_t *p_playlist;
    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 220
    ExtensionsManager *extMgr = [[VLCMain sharedInstance] extensionsManager];
    [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
#warning subtitles styles menu disabled due to missing adaptation to VLC 3.0
#if 0
264 265 266 267 268
    [self setupMenu: _subtitle_sizeMenu withIntList:"freetype-rel-fontsize" andSelector:@selector(switchSubtitleOption:)];
    [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:)];
269
#endif
270 271 272 273 274 275 276
}

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

    [menu removeAllItems];
277
    p_item = config_FindConfig(VLC_OBJECT(getIntf()), psz_name);
278

279 280 281 282
    if (!p_item) {
        msg_Err(getIntf(), "couldn't create menu int list for item '%s' as it does not exist", psz_name);
        return;
    }
283 284 285 286 287 288 289

    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: @""];
290
        else {
291
            msg_Err(getIntf(), "item %d of pref %s failed to be created", i, psz_name);
292 293 294
            continue;
        }

295 296 297
        [mi setTarget:self];
        [mi setAction:selector];
        [mi setTag:p_item->list.i[i]];
298
        [mi setRepresentedObject:toNSStr(psz_name)];
299
        [menu addItem:mi];
300 301 302
        if (p_item->value.i == p_item->list.i[i])
            [mi setState:NSOnState];
    }
303 304 305 306 307
}

- (void)initStrings
{
    /* main menu */
308
    [_about setTitle: [_NS("About VLC media player") \
309
                           stringByAppendingString: @"..."]];
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338
    [_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")];
339
    [_clearItem setTitle: _NS("Delete")];
340
    [_select_all setTitle: _NS("Select All")];
341
    [_findItem setTitle: _NS("Find")];
342 343 344

    [_viewMenu setTitle: _NS("View")];
    [_toggleJumpButtons setTitle: _NS("Show Previous & Next Buttons")];
345
    [_toggleJumpButtons setState: config_GetInt(getIntf(), "macosx-show-playback-buttons")];
346
    [_togglePlaymodeButtons setTitle: _NS("Show Shuffle & Repeat Buttons")];
347
    [_togglePlaymodeButtons setState: config_GetInt(getIntf(), "macosx-show-playmode-buttons")];
348
    [_toggleEffectsButton setTitle: _NS("Show Audio Effects Button")];
349
    [_toggleEffectsButton setState: config_GetInt(getIntf(), "macosx-show-effects-button")];
350
    [_toggleSidebar setTitle: _NS("Show Sidebar")];
351
    [_toggleSidebar setState: config_GetInt(getIntf(), "macosx-show-sidebar")];
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379
    [_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")];
380
    [_renderer setTitle: _NS("Select Renderer…")];
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

    [_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...")];
    [_readme setTitle: _NS("ReadMe / FAQ...")];
    [_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...")];
460 461

    /* dock menu */
462 463 464 465 466
    [_dockMenuplay setTitle: _NS("Play")];
    [_dockMenustop setTitle: _NS("Stop")];
    [_dockMenunext setTitle: _NS("Next")];
    [_dockMenuprevious setTitle: _NS("Previous")];
    [_dockMenumute setTitle: _NS("Mute")];
467 468

    /* vout menu */
469 470 471 472 473 474 475 476 477
    [_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")];
478 479
}

480
#pragma mark - Termination
481 482 483 484

- (void)releaseRepresentedObjects:(NSMenu *)the_menu
{
    NSArray *menuitems_array = [the_menu itemArray];
485
    NSUInteger menuItemCount = [menuitems_array count];
486
    for (NSUInteger i=0; i < menuItemCount; i++) {
487
        NSMenuItem *one_item = [menuitems_array objectAtIndex:i];
488
        if ([one_item hasSubmenu])
489 490 491 492 493 494
            [self releaseRepresentedObjects: [one_item submenu]];

        [one_item setRepresentedObject:NULL];
    }
}

495
#pragma mark - Interface update
496 497 498

- (void)setupMenus
{
499
    playlist_t *p_playlist = pl_Get(getIntf());
500
    input_thread_t *p_input = playlist_CurrentInput(p_playlist);
501
    if (p_input != NULL) {
502 503
        [self setupVarMenuItem:_program target: (vlc_object_t *)p_input
                                 var:"program" selector: @selector(toggleVar:)];
504

505 506
        [self setupVarMenuItem:_title target: (vlc_object_t *)p_input
                                 var:"title" selector: @selector(toggleVar:)];
507

508 509
        [self setupVarMenuItem:_chapter target: (vlc_object_t *)p_input
                                 var:"chapter" selector: @selector(toggleVar:)];
510

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

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

517 518
        [self setupVarMenuItem:_subtitle_track target: (vlc_object_t *)p_input
                                 var:"spu-es" selector: @selector(toggleVar:)];
519

520
        audio_output_t *p_aout = playlist_GetAout(p_playlist);
521
        if (p_aout != NULL) {
522 523
            [self setupVarMenuItem:_channels target: (vlc_object_t *)p_aout
                                     var:"stereo-mode" selector: @selector(toggleVar:)];
524

525 526
            [self setupVarMenuItem:_visual target: (vlc_object_t *)p_aout
                                     var:"visual" selector: @selector(toggleVar:)];
527
            vlc_object_release(p_aout);
528 529
        }

530
        vout_thread_t *p_vout = getVoutForActiveWindow();
531

532
        if (p_vout != NULL) {
533 534
            [self setupVarMenuItem:_aspect_ratio target: (vlc_object_t *)p_vout
                                     var:"aspect-ratio" selector: @selector(toggleVar:)];
535

536 537
            [self setupVarMenuItem:_crop target: (vlc_object_t *) p_vout
                                     var:"crop" selector: @selector(toggleVar:)];
538

539 540
            [self setupVarMenuItem:_deinterlace target: (vlc_object_t *)p_vout
                                     var:"deinterlace" selector: @selector(toggleVar:)];
541

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

545
            vlc_object_release(p_vout);
546 547

            [self refreshVoutDeviceMenu:nil];
548
        }
549
        [_postprocessing setEnabled:YES];
550
        vlc_object_release(p_input);
551
    } else {
552
        [_postprocessing setEnabled:NO];
553
    }
554 555
}

556
- (void)refreshVoutDeviceMenu:(NSNotification *)notification
557
{
558 559
    NSUInteger count = (NSUInteger) [_screenMenu numberOfItems];
    NSMenu *submenu = _screenMenu;
560
    if (count > 0)
561 562 563 564 565 566 567 568 569 570 571
        [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];
572
    NSRect s_rect;
573
    for (NSUInteger i = 0; i < count; i++) {
574 575
        s_rect = [[screens objectAtIndex:i] frame];
        [submenu addItemWithTitle: [NSString stringWithFormat: @"%@ %li (%ix%i)", _NS("Screen"), i+1,
576
                                      (int)s_rect.size.width, (int)s_rect.size.height] action:@selector(toggleFullscreenDevice:) keyEquivalent:@""];
577 578 579 580
        mitem = [submenu itemAtIndex:i+1];
        [mitem setTag: (int)[[screens objectAtIndex:i] displayID]];
        [mitem setEnabled: YES];
        [mitem setTarget: self];
581
    }
582
    [[submenu itemWithTag: var_InheritInteger(getIntf(), "macosx-vdev")] setState: NSOnState];
583 584 585 586
}

- (void)setSubmenusEnabled:(BOOL)b_enabled
{
587 588 589 590 591 592 593 594 595 596 597 598 599
    [_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];
600 601 602 603
}

- (void)setSubtitleMenuEnabled:(BOOL)b_enabled
{
604
    [_openSubtitleFile setEnabled: b_enabled];
605
    if (b_enabled) {
606 607
        [_subtitle_bgopacityLabel_gray setHidden: YES];
        [_subtitle_bgopacityLabel setHidden: NO];
608
    } else {
609 610
        [_subtitle_bgopacityLabel_gray setHidden: NO];
        [_subtitle_bgopacityLabel setHidden: YES];
611
    }
612 613
    [_subtitle_bgopacity_sld setEnabled: b_enabled];
    [_teletext setEnabled: b_enabled];
614 615
}

616 617
- (void)setRateControlsEnabled:(BOOL)b_enabled
{
618 619
    [_rate_sld setEnabled: b_enabled];
    [_rate_sld setIntValue: [[VLCCoreInteraction sharedInstance] playbackRate]];
620
    int i = [[VLCCoreInteraction sharedInstance] playbackRate];
621
    double speed =  pow(2, (double)i / 17);
622
    [_rateTextField setStringValue: [NSString stringWithFormat:@"%.2fx", speed]];
623

624
    NSColor *color = b_enabled ? [NSColor controlTextColor] : [NSColor disabledControlTextColor];
625

626 627 628 629 630
    [_rateLabel setTextColor:color];
    [_rate_slowerLabel setTextColor:color];
    [_rate_normalLabel setTextColor:color];
    [_rate_fasterLabel setTextColor:color];
    [_rateTextField setTextColor:color];
631

632
    [self setSubtitleMenuEnabled: b_enabled];
633 634
}

635
#pragma mark - View
636 637 638

- (IBAction)toggleEffectsButton:(id)sender
{
639 640
    BOOL b_value = !config_GetInt(getIntf(), "macosx-show-effects-button");
    config_PutInt(getIntf(), "macosx-show-effects-button", b_value);
641
    [(VLCMainWindowControlsBar *)[[[VLCMain sharedInstance] mainWindow] controlsBar] toggleEffectsButton];
642
    [_toggleEffectsButton setState: b_value];
643 644
}

645 646
- (IBAction)toggleJumpButtons:(id)sender
{
647 648
    BOOL b_value = !config_GetInt(getIntf(), "macosx-show-playback-buttons");
    config_PutInt(getIntf(), "macosx-show-playback-buttons", b_value);
649

650
    [(VLCMainWindowControlsBar *)[[[VLCMain sharedInstance] mainWindow] controlsBar] toggleJumpButtons];
651 652
    [[[VLCMain sharedInstance] voutController] updateWindowsUsingBlock:^(VLCVideoWindowCommon *window) {
        [[window controlsBar] toggleForwardBackwardMode: b_value];
653 654
    }];

655
    [_toggleJumpButtons setState: b_value];
656 657
}

658 659
- (IBAction)togglePlaymodeButtons:(id)sender
{
660 661
    BOOL b_value = !config_GetInt(getIntf(), "macosx-show-playmode-buttons");
    config_PutInt(getIntf(), "macosx-show-playmode-buttons", b_value);
662
    [(VLCMainWindowControlsBar *)[[[VLCMain sharedInstance] mainWindow] controlsBar] togglePlaymodeButtons];
663
    [_togglePlaymodeButtons setState: b_value];
664 665
}

666 667 668 669 670 671 672
- (IBAction)toggleSidebar:(id)sender
{
    [[[VLCMain sharedInstance] mainWindow] toggleLeftSubSplitView];
}

- (void)updateSidebarMenuItem
{
673
    [_toggleSidebar setState: config_GetInt(getIntf(), "macosx-show-sidebar")];
674 675
}

676
#pragma mark - Playback
677

678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705
- (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;
706
    intf_thread_t *p_intf = getIntf();
707 708 709 710 711 712 713 714 715 716 717 718
    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;
719
    intf_thread_t *p_intf = getIntf();
720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759
    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]];
}

760 761
- (IBAction)quitAfterPlayback:(id)sender
{
762
    playlist_t *p_playlist = pl_Get(getIntf());
763 764
    bool b_value = !var_CreateGetBool(p_playlist, "play-and-exit");
    var_SetBool(p_playlist, "play-and-exit", b_value);
765
    config_PutInt(getIntf(), "play-and-exit", b_value);
766 767
}

768 769 770 771 772 773 774
- (IBAction)toggleRecord:(id)sender
{
    [[VLCCoreInteraction sharedInstance] toggleRecord];
}

- (void)updateRecordState:(BOOL)b_value
{
775
    [_record setState:b_value];
776 777 778 779
}

- (IBAction)setPlaybackRate:(id)sender
{
780
    [[VLCCoreInteraction sharedInstance] setPlaybackRate: [_rate_sld intValue]];
781
    int i = [[VLCCoreInteraction sharedInstance] playbackRate];
782
    double speed =  pow(2, (double)i / 17);
783
    [_rateTextField setStringValue: [NSString stringWithFormat:@"%.2fx", speed]];
784 785 786 787 788
}

- (void)updatePlaybackRate
{
    int i = [[VLCCoreInteraction sharedInstance] playbackRate];
789
    double speed =  pow(2, (double)i / 17);
790 791
    [_rateTextField setStringValue: [NSString stringWithFormat:@"%.2fx", speed]];
    [_rate_sld setIntValue: i];
792 793
}

794 795 796 797 798
- (IBAction)toggleAtoBloop:(id)sender
{
    [[VLCCoreInteraction sharedInstance] setAtoB];
}

799 800
- (IBAction)goToSpecificTime:(id)sender
{
801
    input_thread_t *p_input = pl_CurrentInput(getIntf());
802 803 804 805 806 807 808 809 810 811 812 813
    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;

814
            input_thread_t *p_input = pl_CurrentInput(getIntf());
815 816 817
            if (p_input) {
                input_Control(p_input, INPUT_SET_TIME, (int64_t)(returnTime *1000000));
                vlc_object_release(p_input);
818
            }
819
        }];
820

821
        vlc_object_release(p_input);
822 823 824
    }
}

825 826
#pragma mark - audio menu

827 828 829 830 831
- (void)refreshAudioDeviceList
{
    char **ids, **names;
    char *currentDevice;

832
    [_audioDeviceMenu removeAllItems];
833

834
    audio_output_t *p_aout = getAout();
835 836 837 838
    if (!p_aout)
        return;

    int n = aout_DevicesList(p_aout, &ids, &names);
839 840
    if (n == -1) {
        vlc_object_release(p_aout);
841
        return;
842
    }
843 844

    currentDevice = aout_DeviceGet(p_aout);
845
    NSMenuItem *_tmp;
846 847

    for (NSUInteger x = 0; x < n; x++) {
848 849 850
        _tmp = [_audioDeviceMenu addItemWithTitle:toNSStr(names[x]) action:@selector(toggleAudioDevice:) keyEquivalent:@""];
        [_tmp setTarget:self];
        [_tmp setTag:[[NSString stringWithFormat:@"%s", ids[x]] intValue]];
851 852 853
    }
    vlc_object_release(p_aout);

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

856 857
    free(currentDevice);

858 859 860 861 862 863 864
    for (NSUInteger x = 0; x < n; x++) {
        free(ids[x]);
        free(names[x]);
    }
    free(ids);
    free(names);

865 866
    [_audioDeviceMenu setAutoenablesItems:YES];
    [_audioDevice setEnabled:YES];
867 868
}

869
- (void)toggleAudioDevice:(id)sender
870
{
871
    audio_output_t *p_aout = getAout();
872 873
    if (!p_aout)
        return;
874 875 876 877

    int returnValue = 0;

    if ([sender tag] > 0)
878
        returnValue = aout_DeviceSet(p_aout, [[NSString stringWithFormat:@"%li", [sender tag]] UTF8String]);
879
    else
880
        returnValue = aout_DeviceSet(p_aout, NULL);
881 882

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

885
    vlc_object_release(p_aout);
886 887 888
    [self refreshAudioDeviceList];
}

889
#pragma mark - video menu
890

891 892 893 894 895 896 897
- (IBAction)toggleFullscreen:(id)sender
{
    [[VLCCoreInteraction sharedInstance] toggleFullscreen];
}

- (IBAction)resizeVideoWindow:(id)sender
{
898
    input_thread_t *p_input = pl_CurrentInput(getIntf());
899
    if (p_input) {
900
        vout_thread_t *p_vout = getVoutForActiveWindow();
901
        if (p_vout) {
902
            if (sender == _half_window)
903
                var_SetFloat(p_vout, "zoom", 0.5);
904
            else if (sender == _normal_window)
905
                var_SetFloat(p_vout, "zoom", 1.0);
906
            else if (sender == _double_window)
907
                var_SetFloat(p_vout, "zoom", 2.0);
908 909
            else
            {
910
                [[NSApp keyWindow] performZoom:sender];
911
            }
912
            vlc_object_release(p_vout);
913
        }
914
        vlc_object_release(p_input);
915 916 917 918 919
    }
}

- (IBAction)floatOnTop:(id)sender
{
920
    input_thread_t *p_input = pl_CurrentInput(getIntf());
921
    if (p_input) {
922
        vout_thread_t *p_vout = getVoutForActiveWindow();
923
        if (p_vout) {
924
            BOOL b_fs = var_ToggleBool(p_vout, "video-on-top");
925
            var_SetBool(pl_Get(getIntf()), "video-on-top", b_fs);
926

927
            vlc_object_release(p_vout);
928
        }
929
        vlc_object_release(p_input);
930 931 932 933 934
    }
}

- (IBAction)createVideoSnapshot:(id)sender
{
935
    input_thread_t *p_input = pl_CurrentInput(getIntf());
936
    if (p_input) {
937
        vout_thread_t *p_vout = getVoutForActiveWindow();
938 939 940
        if (p_vout) {
            var_TriggerCallback(p_vout, "video-snapshot");
            vlc_object_release(p_vout);
941
        }
942
        vlc_object_release(p_input);
943 944 945
    }
}

946 947
- (void)_disablePostProcessing
{
948
    [[VLCCoreInteraction sharedInstance] setVideoFilter:"postproc" on:false];
949 950 951 952
}

- (void)_enablePostProcessing
{
953
    [[VLCCoreInteraction sharedInstance] setVideoFilter:"postproc" on:true];
954 955
}

956
- (void)togglePostProcessing:(id)sender
957
{
958
    char *psz_name = "postproc";
959
    NSInteger count = [_postprocessingMenu numberOfItems];
960
    for (NSUInteger x = 0; x < count; x++)
961
        [[_postprocessingMenu itemAtIndex:x] setState:NSOffState];
962 963 964 965 966 967 968 969

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

970
        [[VLCCoreInteraction sharedInstance] setVideoFilterProperty:"postproc-q" forFilter:"postproc" integer:[sender tag]];
971 972 973
    }
}

974
- (void)toggleFullscreenDevice:(id)sender
975
{
976
    config_PutInt(getIntf(), "macosx-vdev", [sender tag]);
977 978 979
    [self refreshVoutDeviceMenu: nil];
}

980
#pragma mark - Subtitles Menu
981

982 983 984
- (IBAction)addSubtitleFile:(id)sender
{
    NSInteger i_returnValue = 0;
985
    input_thread_t *p_input = pl_CurrentInput(getIntf());
986 987 988 989 990 991 992 993 994 995
    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);
996

997 998 999
    if (!path)
        path = strdup("");

1000
    NSOpenPanel *openPanel = [NSOpenPanel openPanel];
1001 1002 1003
    [openPanel setCanChooseFiles: YES];
    [openPanel setCanChooseDirectories: NO];
    [openPanel setAllowsMultipleSelection: YES];
1004 1005 1006

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

1007
    NSURL *url = [NSURL URLWithString:[toNSStr(path) stringByExpandingTildeInPath]];
1008 1009
    url = [url URLByDeletingLastPathComponent];
    [openPanel setDirectoryURL: url];
1010
    free(path);
1011
    vlc_object_release(p_input);
1012

1013 1014
    i_returnValue = [openPanel runModal];

1015 1016
    if (i_returnValue == NSOKButton)
        [[VLCCoreInteraction sharedInstance] addSubtitlesToCurrentInput:[openPanel URLs]];
1017 1018
}

1019
- (void)switchSubtitleOption:(id)sender
1020 1021 1022 1023
{
    int intValue = [sender tag];
    NSString *representedObject = [sender representedObject];

1024
#warning this won't work anymore and is heritably bad
1025
    config_PutInt(getIntf(), [representedObject UTF8String], intValue);
1026 1027

    NSMenu *menu = [sender menu];
1028
    NSUInteger count = (NSUInteger) [menu numberOfItems];
1029 1030 1031
    for (NSUInteger x = 0; x < count; x++)
        [[menu itemAtIndex:x] setState:NSOffState];
    [[menu itemWithTag:intValue] setState:NSOnState];
1032 1033 1034 1035
}

- (IBAction)switchSubtitleBackgroundOpacity:(id)sender
{
1036
    config_PutInt(getIntf(), "freetype-background-opacity", [sender intValue]);
1037 1038
}

1039 1040 1041
- (IBAction)telxTransparent:(id)sender
{
    vlc_object_t *p_vbi;
1042
    p_vbi = (vlc_object_t *) vlc_object_find_name(pl_Get(getIntf()), "zvbi");
1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066
    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;

1067
    p_vbi = (vlc_object_t *) vlc_object_find_name(pl_Get(getIntf()), "zvbi");
1068 1069 1070 1071 1072 1073
    if (p_vbi) {
        var_SetInteger(p_vbi, "vbi-page", i_page);
        vlc_object_release(p_vbi);
    }
}

1074
#pragma mark - Panels
1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100

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

1101 1102
- (IBAction)savePlaylist:(id)sender
{
1103
    playlist_t *p_playlist = pl_Get(getIntf());
1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 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 1164 1165 1166

    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],
                            p_playlist->p_local_category, "export-m3u");
        } 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],
                            p_playlist->p_local_category, "export-xspf");
        } 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],
                            p_playlist->p_local_category, "export-html");
        }
    }
1167 1168
}

1169 1170
- (IBAction)showConvertAndSave:(id)sender
{
1171
    [[[VLCMain sharedInstance] convertAndSaveWindow] showWindow:self];
1172 1173
}

1174 1175
- (IBAction)showVideoEffects:(id)sender
{
1176
    [[[VLCMain sharedInstance] videoEffectsPanel] toggleWindow:sender];
1177 1178 1179 1180
}

- (IBAction)showTrackSynchronization:(id)sender
{
1181
    [[[VLCMain sharedInstance] trackSyncPanel] toggleWindow:sender];
1182 1183 1184 1185
}

- (IBAction)showAudioEffects:(id)sender
{
1186
    [[[VLCMain sharedInstance] audioEffectsPanel] toggleWindow:sender];
1187 1188 1189 1190 1191 1192 1193
}

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

1194
- (IBAction)showPreferences:(id)sender
1195
{
1196
    NSInteger i_level = [[[VLCMain sharedInstance] voutController] currentStatusWindowLevel];
1197
    [[[VLCMain sharedInstance] simplePreferences] showSimplePrefsWithLevel:i_level];
1198 1199
}

1200 1201
- (IBAction)openAddonManager:(id)sender
{
1202
    if (!_addonsController)
1203
        _addonsController = [[VLCAddonsWindowController alloc] init];
1204

1205
    [_addonsController showWindow:self];
1206 1207
}

1208 1209
- (IBAction)showMessagesPanel:(id)showMessagesPanel
{
1210
    [[[VLCMain sharedInstance] debugMsgPanel] showWindow:self];
1211 1212
}

1213 1214
- (IBAction)showMainWindow:(id)sender
{
1215
    [[[VLCMain sharedInstance] mainWindow] makeKeyAndOrderFront:sender];
1216 1217 1218 1219
}

- (IBAction)showPlaylist:(id)sender
{
1220
    [[[VLCMain sharedInstance] mainWindow] changePlaylistState: psUserMenuEvent];
1221 1222
}

1223
#pragma mark - Help and Docs
Felix Paul Kühne's avatar