menus.cpp 48.2 KB
Newer Older
1 2 3
/*****************************************************************************
 * menus.cpp : Qt menus
 *****************************************************************************
4
 * Copyright © 2006-2011 the VideoLAN team
5
 * $Id$
6
 *
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
7
 * Authors: Clément Stenac <zorglub@videolan.org>
8
 *          Jean-Baptiste Kempf <jb@videolan.org>
9
 *          Jean-Philippe André <jpeg@videolan.org>
10 11 12 13
 *
 * 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
14
 * ( at your option ) any later version.
15 16 17 18 19 20 21 22 23 24 25
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

26 27 28 29
/** \todo
 * - Remove static currentGroup
 */

Rémi Duraffort's avatar
Rémi Duraffort committed
30 31 32
#define __STDC_FORMAT_MACROS 1
#define __STDC_CONSTANT_MACROS 1

33 34 35 36
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

37
#include <vlc_common.h>
38
#include <vlc_intf_strings.h>
39 40
#include <vlc_vout.h>                             /* vout_thread_t */
#include <vlc_aout.h>                             /* audio_output_t */
41

Clément Stenac's avatar
Clément Stenac committed
42
#include "menus.hpp"
43

44 45 46 47 48 49 50 51
#include "main_interface.hpp"                     /* View modifications */
#include "dialogs_provider.hpp"                   /* Dialogs display */
#include "input_manager.hpp"                      /* Input Management */
#include "recents.hpp"                            /* Recent Items */
#include "actions_manager.hpp"                    /* Actions Management: play+volume */
#include "extensions_manager.hpp"                 /* Extensions menu */
#include "util/qmenuview.hpp"                     /* Simple Playlist menu */
#include "components/playlist/playlist_model.hpp" /* PLModel getter */
Clément Stenac's avatar
Clément Stenac committed
52

53 54 55 56 57
#include <QMenu>
#include <QMenuBar>
#include <QAction>
#include <QActionGroup>
#include <QSignalMapper>
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
58
#include <QStatusBar>
59

60 61 62 63
/*
  This file defines the main menus and the pop-up menu (right-click menu)
  and the systray menu (in that order in the file)

64 65 66
  There are 4 menus that have to be rebuilt everytime there are called:
  Audio, Video, Navigation, view
  4 functions are building those menus: AudioMenu, VideoMenu, NavigMenu, View
67 68 69 70 71 72 73
  and 3 functions associated are collecting the objects :
  InputAutoMenuBuilder, AudioAutoMenuBuilder, VideoAutoMenuBuilder.

  A QSignalMapper decides when to rebuild those menus cf MenuFunc in the .hpp
  Just before one of those menus are aboutToShow(), they are rebuild.
  */

74 75
enum
{
76 77 78
    ITEM_NORMAL, /* not a checkbox, nor a radio */
    ITEM_CHECK,  /* Checkbox */
    ITEM_RADIO   /* Radiobox */
79 80 81 82
};

static QActionGroup *currentGroup;

83
QMenu *VLCMenuBar::recentsMenu = NULL;
Ludovic Fauvet's avatar
Ludovic Fauvet committed
84

85 86 87
/**
 * @brief Add static entries to DP in menus
 **/
88
QAction *addDPStaticEntry( QMenu *menu,
89
                       const QString& text,
90
                       const char *icon,
91
                       const char *member,
92
                       const char *shortcut = NULL,
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
93
                       QAction::MenuRole role = QAction::NoRole
94
                       )
95
{
96
    QAction *action = NULL;
97
#ifndef __APPLE__ /* We don't set icons in menus in MacOS X */
Rémi Duraffort's avatar
Rémi Duraffort committed
98
    if( !EMPTY_STR( icon ) )
99
    {
Rémi Duraffort's avatar
Rémi Duraffort committed
100
        if( !EMPTY_STR( shortcut ) )
101 102
            action = menu->addAction( QIcon( icon ), text, THEDP,
                                      member, qtr( shortcut ) );
103
        else
104
            action = menu->addAction( QIcon( icon ), text, THEDP, member );
105 106
    }
    else
107
#endif
108
    {
Rémi Duraffort's avatar
Rémi Duraffort committed
109
        if( !EMPTY_STR( shortcut ) )
110
            action = menu->addAction( text, THEDP, member, qtr( shortcut ) );
111
        else
112
            action = menu->addAction( text, THEDP, member );
113
    }
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
114
#ifdef __APPLE__
David Fuhrmann's avatar
David Fuhrmann committed
115
    action->setMenuRole( role );
Ludovic Fauvet's avatar
Ludovic Fauvet committed
116 117
#else
    Q_UNUSED( role );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
118
#endif
119
    action->setData( VLCMenuBar::ACTION_STATIC );
120
    return action;
121
}
122

123 124 125
/**
 * @brief Add static entries to MIM in menus
 **/
126 127
QAction* addMIMStaticEntry( intf_thread_t *p_intf,
                            QMenu *menu,
128
                            const QString& text,
129 130 131
                            const char *icon,
                            const char *member,
                            bool bStatic = false )
132
{
133
    QAction *action;
134
#ifndef __APPLE__ /* We don't set icons in menus in MacOS X */
Rémi Duraffort's avatar
Rémi Duraffort committed
135
    if( !EMPTY_STR( icon ) )
136
    {
137
        action = menu->addAction( text, THEMIM,  member );
138 139 140
        action->setIcon( QIcon( icon ) );
    }
    else
141
#endif
142
    {
Rémi Duraffort's avatar
Rémi Duraffort committed
143
        action = menu->addAction( text, THEMIM, member );
144
    }
145 146 147
    action->setData( VLCMenuBar::ACTION_STATIC |
                     ( bStatic ) ? VLCMenuBar::ACTION_ALWAYS_ENABLED
                                 : VLCMenuBar::ACTION_NONE
148
                   );
149
    return action;
150 151
}

152
/**
153 154
 * @brief Enable all static entries of a menu, disable the others
 * @param menu the menu in which the entries will be disabled
155
 * @param enable if false, disable all entries
156
 **/
157
void VLCMenuBar::EnableStaticEntries( QMenu *menu, bool enable = true )
158
{
159
    if( !menu ) return;
160

Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
161
    QList< QAction* > actions = menu->actions();
162
    for( int i = 0; i < actions.count(); ++i )
163
    {
164 165 166 167 168 169 170
        int actionflags = actions[i]->data().toInt();
        if ( actionflags & ACTION_MANAGED )
            actions[i]->setEnabled(
                ( actionflags & ACTION_ALWAYS_ENABLED )
                ||
                enable
            );
171 172 173
    }
}

174 175
/**
 * \return Number of static entries
176
 **/
177
inline int DeleteNonStaticEntries( QMenu *menu )
178
{
179 180
    if( !menu ) return VLC_EGENERIC;

181
    int i_ret = 0;
182

Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
183
    QList< QAction* > actions = menu->actions();
184
    for( int i = 0; i < actions.count(); ++i )
185
    {
186
        if( actions[i]->data().toInt() & VLCMenuBar::ACTION_NO_CLEANUP )
187
            i_ret++;
188 189
        else
            delete actions[i];
190
    }
191
    return i_ret;
192 193
}

194 195 196 197
/**
 * \return QAction associated to psz_var variable
 **/
static QAction * FindActionWithVar( QMenu *menu, const char *psz_var )
198
{
199
    QList< QAction* > actions = menu->actions();
200
    for( int i = 0; i < actions.count(); ++i )
201
    {
202 203
        if( actions[i]->data().toString() == psz_var )
            return actions[i];
204
    }
205
    return NULL;
206 207
}

208
/*****************************************************************************
209
 * Definitions of variables for the dynamic menus
210
 *****************************************************************************/
211 212
#define PUSH_VAR( var ) varnames.append( var ); \
    objects.append( VLC_OBJECT(p_object) )
213

214 215
#define PUSH_INPUTVAR( var ) varnames.append( var ); \
    objects.append( VLC_OBJECT(p_input) );
216

217
static int InputAutoMenuBuilder( input_thread_t *p_object,
218 219
        QVector<vlc_object_t *> &objects,
        QVector<const char *> &varnames )
220
{
221
    PUSH_VAR( "bookmark" );
222
    PUSH_VAR( "title" );
223
    PUSH_VAR( "chapter" );
224
    PUSH_VAR( "navigation" );
225
    PUSH_VAR( "program" );
226 227 228
    return VLC_SUCCESS;
}

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
229
static int VideoAutoMenuBuilder( vout_thread_t *p_object,
230
        input_thread_t *p_input,
231 232
        QVector<vlc_object_t *> &objects,
        QVector<const char *> &varnames )
233
{
234 235
    PUSH_INPUTVAR( "video-es" );
    PUSH_INPUTVAR( "spu-es" );
236 237
    PUSH_VAR( "fullscreen" );
    PUSH_VAR( "video-on-top" );
238
    PUSH_VAR( "video-wallpaper" );
239
    PUSH_VAR( "video-snapshot" );
240
    PUSH_VAR( "zoom" );
241
    PUSH_VAR( "autoscale" );
242 243
    PUSH_VAR( "aspect-ratio" );
    PUSH_VAR( "crop" );
244
    PUSH_VAR( "deinterlace" );
245
    PUSH_VAR( "deinterlace-mode" );
246
    PUSH_VAR( "postprocess" );
247

248 249 250
    return VLC_SUCCESS;
}

251
static int AudioAutoMenuBuilder( audio_output_t *p_object,
252
        input_thread_t *p_input,
253 254
        QVector<vlc_object_t *> &objects,
        QVector<const char *> &varnames )
255
{
256
    PUSH_INPUTVAR( "audio-es" );
257
    PUSH_VAR( "audio-channels" );
258 259
    PUSH_VAR( "audio-device" );
    PUSH_VAR( "visual" );
260 261 262
    return VLC_SUCCESS;
}

263 264
/*****************************************************************************
 * All normal menus
265
 * Simple Code
266 267
 *****************************************************************************/

268
// Static menu
269 270 271 272
static inline void addMenuToMainbar( QMenu *func, QString title, QMenuBar *bar ) {
    func->setTitle( title );
    bar->addMenu( func);
}
273

274
// Dynamic menu
275
#define BAR_DADD( func, title, id ) { \
276 277 278 279 280
    QMenu *_menu = func; _menu->setTitle( title ); bar->addMenu( _menu ); \
    MenuFunc *f = new MenuFunc( _menu, id ); \
    CONNECT( _menu, aboutToShow(), THEDP->menusUpdateMapper, map() ); \
    THEDP->menusUpdateMapper->setMapping( _menu, f ); }

281
// Add a simple action
282 283 284 285 286
static inline void addAction( QMenu *_menu, QVariant val, QString title ) {
    QAction *_action = new QAction( title, _menu );
    _action->setData( val );
    _menu->addAction( _action );
}
287

288
// Add an action with a submenu
289
static inline QMenu *addActionWithSubmenu( QMenu *_menu, QVariant val, QString title ) {
290
    QAction *_action = new QAction( title, _menu );
291
    QMenu *_submenu = new QMenu( _menu );
292
    _action->setData( val );
293
    _action->setMenu( _submenu );
294
    _menu->addAction( _action );
295
    return _submenu;
296
}
297

298
// Add an action that is a checkbox
299 300 301 302 303 304
static inline void addActionWithCheckbox( QMenu *_menu, QVariant val, QString title ) {
    QAction *_action = new QAction( title, _menu );
    _action->setData( val );
    _action->setCheckable( true );
    _menu->addAction( _action );
}
305

306 307 308
/**
 * Main Menu Bar Creation
 **/
309
void VLCMenuBar::createMenuBar( MainInterface *mi,
310
                              intf_thread_t *p_intf )
Clément Stenac's avatar
Qt4:  
Clément Stenac committed
311
{
312 313 314
    /* QMainWindows->menuBar()
       gives the QProcess::destroyed timeout issue on Cleanlooks style with
       setDesktopAware set to false */
315
    QMenuBar *bar = mi->menuBar();
316

317
    addMenuToMainbar( FileMenu( p_intf, bar, mi ), qtr( "&Media" ), bar );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
318

319
    /* Dynamic menus, rebuilt before being showed */
320
    BAR_DADD( NavigMenu( p_intf, bar ), qtr( "P&layback" ), 3 );
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
321 322
    BAR_DADD( AudioMenu( p_intf, bar ), qtr( "&Audio" ), 1 );
    BAR_DADD( VideoMenu( p_intf, bar ), qtr( "&Video" ), 2 );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
323

324
    addMenuToMainbar( ToolsMenu( bar ), qtr( "&Tools" ), bar );
325 326

    /* View menu, a bit different */
Rémi Duraffort's avatar
Rémi Duraffort committed
327
    BAR_DADD( ViewMenu( p_intf, NULL, mi ), qtr( "V&iew" ), 4 );
328

329
    addMenuToMainbar( HelpMenu( bar ), qtr( "&Help" ), bar );
330

331
}
332 333

/**
334
 * Media ( File ) Menu
335 336
 * Opening, streaming and quit
 **/
337
QMenu *VLCMenuBar::FileMenu( intf_thread_t *p_intf, QWidget *parent, MainInterface *mi )
338
{
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
339
    QMenu *menu = new QMenu( parent );
340
    QAction *action;
341

342 343
    addDPStaticEntry( menu, qtr( "Open &File..." ),
        ":/type/file-asym", SLOT( simpleOpenDialog() ), "Ctrl+O" );
344
    addDPStaticEntry( menu, qtr( I_OP_OPDIR ),
345
        ":/type/folder-grey", SLOT( PLOpenDir() ), "Ctrl+F" );
346
    addDPStaticEntry( menu, qtr( "Open &Disc..." ),
347
        ":/type/disc", SLOT( openDiscDialog() ), "Ctrl+D" );
348
    addDPStaticEntry( menu, qtr( "Open &Network Stream..." ),
349
        ":/type/network", SLOT( openNetDialog() ), "Ctrl+N" );
350
    addDPStaticEntry( menu, qtr( "Open &Capture Device..." ),
351
        ":/type/capture-card", SLOT( openCaptureDialog() ), "Ctrl+C" );
352

353
    menu->addSeparator();
354 355 356 357 358

    addDPStaticEntry( menu, qtr( "&Open (advanced)..." ),
        ":/type/file-asym", SLOT( openFileDialog() ), "Ctrl+Shift+O" );
    menu->addSeparator();

359
    addDPStaticEntry( menu, qtr( "Open &Location from clipboard" ),
360
                      NULL, SLOT( openUrlDialog() ), "Ctrl+V" );
361

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
362
    if( var_InheritBool( p_intf, "qt-recentplay" ) )
363
    {
364
        recentsMenu = new QMenu( qtr( "Open &Recent Media" ), menu );
365 366 367
        updateRecents( p_intf );
        menu->addMenu( recentsMenu );
    }
368
    menu->addSeparator();
369

370 371 372 373
    addDPStaticEntry( menu, qtr( I_PL_SAVE ), "", SLOT( saveAPlaylist() ),
        "Ctrl+Y" );
    menu->addSeparator();

374
#ifdef ENABLE_SOUT
375
    addDPStaticEntry( menu, qtr( "Conve&rt / Save..." ), "",
376
        SLOT( openAndTranscodingDialogs() ), "Ctrl+R" );
377
    addDPStaticEntry( menu, qtr( "&Stream..." ),
378
        ":/menu/stream", SLOT( openAndStreamingDialogs() ), "Ctrl+S" );
379
    menu->addSeparator();
380
#endif
381

382 383 384 385 386
    action = addMIMStaticEntry( p_intf, menu, qtr( "Quit at the end of playlist" ), "",
                               SLOT( activatePlayQuit( bool ) ) );
    action->setCheckable( true );
    action->setChecked( THEMIM->getPlayExitState() );

387 388 389 390 391 392
    if( mi->getSysTray() )
    {
        action = menu->addAction( qtr( "Close to systray"), mi,
                                 SLOT( toggleUpdateSystrayMenu() ) );
    }

393
    addDPStaticEntry( menu, qtr( "&Quit" ) ,
394
        ":/menu/quit", SLOT( quit() ), "Ctrl+Q" );
395 396 397
    return menu;
}

398
/**
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
399
 * Tools, like Media Information, Preferences or Messages
400
 **/
401
QMenu *VLCMenuBar::ToolsMenu( QMenu *menu )
Clément Stenac's avatar
Clément Stenac committed
402
{
403
    addDPStaticEntry( menu, qtr( "&Effects and Filters"), ":/menu/settings",
404
            SLOT( extendedDialog() ), "Ctrl+E" );
405

406
    addDPStaticEntry( menu, qtr( "&Track Synchronization"), ":/menu/settings",
407 408
            SLOT( synchroDialog() ), "" );

409
    addDPStaticEntry( menu, qtr( I_MENU_INFO ) , ":/menu/info",
410
        SLOT( mediaInfoDialog() ), "Ctrl+I" );
411
    addDPStaticEntry( menu, qtr( I_MENU_CODECINFO ) ,
412
        ":/menu/info", SLOT( mediaCodecDialog() ), "Ctrl+J" );
413

414
#ifdef ENABLE_VLM
415
    addDPStaticEntry( menu, qtr( I_MENU_VLM ), "", SLOT( vlmDialog() ),
416
        "Ctrl+Shift+W" );
417
#endif
418

419 420 421
    addDPStaticEntry( menu, qtr( "Program Guide" ), "", SLOT( epgDialog() ),
        "" );

422
    addDPStaticEntry( menu, qtr( I_MENU_MSG ),
423
        ":/menu/messages", SLOT( messagesDialog() ), "Ctrl+M" );
424

425 426
    addDPStaticEntry( menu, qtr( "Plu&gins and extensions" ),
        "", SLOT( pluginDialog() ) );
Clément Stenac's avatar
Clément Stenac committed
427 428
    menu->addSeparator();

429 430 431
    addDPStaticEntry( menu, qtr( "Customi&ze Interface..." ),
        ":/menu/preferences", SLOT( toolbarDialog() ) );

432
    addDPStaticEntry( menu, qtr( "&Preferences" ),
433
        ":/menu/preferences", SLOT( prefsDialog() ), "Ctrl+P", QAction::PreferencesRole );
434

Clément Stenac's avatar
Clément Stenac committed
435 436 437
    return menu;
}

438
/**
439
 * View Menu
440
 * Interface modification, load other interfaces, activate Extensions
441
 * \param current, set to NULL for menu creation, else for menu update
442
 **/
443
QMenu *VLCMenuBar::ViewMenu( intf_thread_t *p_intf, QMenu *current, MainInterface *_mi )
444
{
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
445
    QAction *action;
446
    QMenu *menu;
447

448 449 450
    MainInterface *mi = _mi ? _mi : p_intf->p_sys->p_mi;
    assert( mi );

451 452
    if( !current )
    {
453
        menu = new QMenu( qtr( "&View" ), mi );
454
    }
455 456 457
    else
    {
        menu = current;
458 459 460 461 462 463 464 465
        //menu->clear();
        //HACK menu->clear() does not delete submenus
        QList<QAction*> actions = menu->actions();
        foreach( QAction *a, actions )
        {
            QMenu *m = a->menu();
            if( a->parent() == menu ) delete a;
            else menu->removeAction( a );
466
            if( m && m->parent() == menu ) delete m;
467
        }
468
    }
469

470 471 472 473
    menu->addAction(
#ifndef __APPLE__
            QIcon( ":/menu/playlist_menu" ),
#endif
474 475 476
            qtr( "Play&list" ), mi,
            SLOT( togglePlaylist() ), qtr( "Ctrl+L" ) );

477 478
    menu->addSeparator();

479
    /* Minimal View */
480
    action = menu->addAction( qtr( "Mi&nimal Interface" ) );
481
    action->setShortcut( qtr( "Ctrl+H" ) );
482
    action->setCheckable( true );
483
    action->setChecked( (mi->getControlsVisibilityStatus() & CONTROLS_HIDDEN ) );
484

485 486
    CONNECT( action, triggered( bool ), mi, toggleMinimalView( bool ) );
    CONNECT( mi, minimalViewToggled( bool ), action, setChecked( bool ) );
487 488 489

    /* FullScreen View */
    action = menu->addAction( qtr( "&Fullscreen Interface" ), mi,
490
            SLOT( toggleInterfaceFullScreen() ), QString( "F11" ) );
491
    action->setCheckable( true );
492
    action->setChecked( mi->isInterfaceFullScreen() );
493 494
    CONNECT( mi, fullscreenInterfaceToggled( bool ),
             action, setChecked( bool ) );
495 496 497

    /* Advanced Controls */
    action = menu->addAction( qtr( "&Advanced Controls" ), mi,
498
            SLOT( toggleAdvancedButtons() ) );
499 500 501 502
    action->setCheckable( true );
    if( mi->getControlsVisibilityStatus() & CONTROLS_ADVANCED )
        action->setChecked( true );

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
503 504 505 506 507 508
    /* Docked Playlist */
    action = menu->addAction( qtr( "Docked Playlist" ) );
    action->setCheckable( true );
    action->setChecked( mi->isPlDocked() );
    CONNECT( action, triggered( bool ), mi, dockPlaylist( bool ) );

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
509 510 511 512
    action = menu->addAction( qtr( "Status Bar" ) );
    action->setCheckable( true );
    action->setChecked( mi->statusBar()->isVisible() );
    CONNECT( action, triggered( bool ), mi, setStatusBarVisibility( bool) );
513
#if 0 /* For Visualisations. Not yet working */
514 515
    adv = menu->addAction( qtr( "Visualizations selector" ), mi,
                           SLOT( visual() ) );
516 517
    adv->setCheckable( true );
    if( visual_selector_enabled ) adv->setChecked( true );
518
#endif
519

520
    menu->addSeparator();
521 522 523 524

    InterfacesMenu( p_intf, menu );
    menu->addSeparator();

525
    /* Extensions */
526
    ExtensionsMenu( p_intf, menu );
527

528 529 530
    return menu;
}

531 532 533
/**
 * Interface Sub-Menu, to list extras interface and skins
 **/
534
QMenu *VLCMenuBar::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
535
{
536 537 538 539
    QVector<vlc_object_t *> objects;
    QVector<const char *> varnames;
    varnames.append( "intf-add" );
    objects.append( VLC_OBJECT(p_intf) );
Clément Stenac's avatar
Qt4:  
Clément Stenac committed
540

541
    return Populate( p_intf, current, varnames, objects );
542 543
}

544
/**
545
 * Extensions menu: populate the current menu with extensions
546
 **/
547
void VLCMenuBar::ExtensionsMenu( intf_thread_t *p_intf, QMenu *extMenu )
548
{
549
    /* Get ExtensionsManager and load extensions if needed */
550
    ExtensionsManager *extMgr = ExtensionsManager::getInstance( p_intf );
551 552 553 554 555 556 557

    if( !var_InheritBool( p_intf, "qt-autoload-extensions")
        && !extMgr->isLoaded() )
    {
        return;
    }

558
    if( !extMgr->isLoaded() && !extMgr->cannotLoad() )
559
    {
560
        extMgr->loadExtensions();
561
    }
562

563
    /* Let the ExtensionsManager build itself the menu */
564
    extMenu->addSeparator();
565
    extMgr->menu( extMenu );
566 567
}

568 569
static inline void VolumeEntries( intf_thread_t *p_intf, QMenu *current )
{
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
570
    current->addSeparator();
571

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
572
    QAction *action = current->addAction( qtr( "&Increase Volume" ),
573
                ActionsManager::getInstance( p_intf ), SLOT( AudioUp() ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
574
    action->setData( VLCMenuBar::ACTION_STATIC );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
575
    action = current->addAction( qtr( "&Decrease Volume" ),
576
                ActionsManager::getInstance( p_intf ), SLOT( AudioDown() ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
577
    action->setData( VLCMenuBar::ACTION_STATIC );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
578
    action = current->addAction( qtr( "&Mute" ),
579
                ActionsManager::getInstance( p_intf ), SLOT( toggleMuteAudio() ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
580
    action->setData( VLCMenuBar::ACTION_STATIC );
581 582
}

583 584
/**
 * Main Audio Menu
585
 **/
586
QMenu *VLCMenuBar::AudioMenu( intf_thread_t *p_intf, QMenu * current )
587
{
588 589
    QVector<vlc_object_t *> objects;
    QVector<const char *> varnames;
590
    audio_output_t *p_aout;
591 592 593
    input_thread_t *p_input;

    if( current->isEmpty() )
594
    {
595 596 597
        addActionWithSubmenu( current, "audio-es", qtr( "Audio &Track" ) );
        addActionWithSubmenu( current, "audio-channels", qtr( "Audio &Channels" ) );
        addActionWithSubmenu( current, "audio-device", qtr( "Audio &Device" ) );
598
        current->addSeparator();
599

600
        addActionWithSubmenu( current, "visual", qtr( "&Visualizations" ) );
601
        VolumeEntries( p_intf, current );
602 603
    }

604
    p_input = THEMIM->getInput();
605
    p_aout = THEMIM->getAout();
606
    EnableStaticEntries( current, ( p_aout != NULL ) );
607
    AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
608
    if( p_aout )
609
    {
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
610
        vlc_object_release( p_aout );
611
    }
612

613 614 615
    return Populate( p_intf, current, varnames, objects );
}

616
/* Subtitles */
617
QMenu *VLCMenuBar::SubtitleMenu( QMenu *current )
618 619 620 621 622 623 624 625
{
    QAction *action;
    QMenu *submenu = new QMenu( qtr( "&Subtitles Track" ), current );
    action = current->addMenu( submenu );
    action->setData( "spu-es" );
    addDPStaticEntry( submenu, qtr( "Open File..." ), "",
                      SLOT( loadSubtitlesFile() ) );
    submenu->addSeparator();
626
    return submenu;
627 628
}

629 630 631 632
/**
 * Main Video Menu
 * Subtitles are part of Video.
 **/
633
QMenu *VLCMenuBar::VideoMenu( intf_thread_t *p_intf, QMenu *current, bool b_subtitle )
634
{
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
635
    vout_thread_t *p_vout;
636
    input_thread_t *p_input;
637 638
    QVector<vlc_object_t *> objects;
    QVector<const char *> varnames;
639

640
    if( current->isEmpty() )
641
    {
642
        addActionWithSubmenu( current, "video-es", qtr( "Video &Track" ) );
643
        if( b_subtitle)
644
            SubtitleMenu( current );
645

646
        current->addSeparator();
647
        /* Surface modifiers */
648 649 650 651
        addActionWithCheckbox( current, "fullscreen", qtr( "&Fullscreen" ) );
        addActionWithCheckbox( current, "autoscale", qtr( "Always Fit &Window" ) );
        addActionWithCheckbox( current, "video-on-top", qtr( "Always &on Top" ) );
        addActionWithCheckbox( current, "video-wallpaper", qtr( "Set as Wall&paper" ) );
652

653
        current->addSeparator();
654
        /* Size modifiers */
655 656 657
        addActionWithSubmenu( current, "zoom", qtr( "&Zoom" ) );
        addActionWithSubmenu( current, "aspect-ratio", qtr( "&Aspect Ratio" ) );
        addActionWithSubmenu( current, "crop", qtr( "&Crop" ) );
658 659 660

        current->addSeparator();
        /* Rendering modifiers */
661 662 663
        addActionWithSubmenu( current, "deinterlace", qtr( "&Deinterlace" ) );
        addActionWithSubmenu( current, "deinterlace-mode", qtr( "&Deinterlace mode" ) );
        addActionWithSubmenu( current, "postprocess", qtr( "&Post processing" ) );
664 665 666 667

        current->addSeparator();
        /* Other actions */
        addAction( current, "video-snapshot", qtr( "Take &Snapshot" ) );
668
    }
669

670 671
    p_input = THEMIM->getInput();

672
    p_vout = THEMIM->getVout();
673
    VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
674

675 676
    if( p_vout )
        vlc_object_release( p_vout );
677

678
    return Populate( p_intf, current, varnames, objects );
679 680
}

681 682 683 684
/**
 * Navigation Menu
 * For DVD, MP4, MOV and other chapter based format
 **/
685
QMenu *VLCMenuBar::NavigMenu( intf_thread_t *p_intf, QMenu *menu )
686
{
687
    QAction *action;
688
    QMenu *submenu;
689

690 691
    addActionWithSubmenu( menu, "title", qtr( "T&itle" ) );
    addActionWithSubmenu( menu, "chapter", qtr( "&Chapter" ) );
692 693
    submenu = addActionWithSubmenu( menu, "navigation", qtr( "&Navigation" ) );
    submenu->setTearOffEnabled( true );
694
    addActionWithSubmenu( menu, "program", qtr( "&Program" ) );
695

696
    /* FixMe: sync I_MENU_BOOKMARK string */
697 698
    submenu = new QMenu( qtr( "Custom &Bookmarks" ), menu );
    submenu->setTearOffEnabled( true );
699 700 701 702 703 704
    addDPStaticEntry( submenu, qtr( "&Manage" ), "",
                      SLOT( bookmarksDialog() ), "Ctrl+B" );
    submenu->addSeparator();
    action = menu->addMenu( submenu );
    action->setData( "bookmark" );

705
    menu->addSeparator();
706

707
    PopupMenuControlEntries( menu, p_intf );
708

709
    EnableStaticEntries( menu, ( THEMIM->getInput() != NULL ) );
710
    return RebuildNavigMenu( p_intf, menu, true );
711 712
}

713
QMenu *VLCMenuBar::RebuildNavigMenu( intf_thread_t *p_intf, QMenu *menu, bool b_keep )
714
{
715
    /* */
716
    input_thread_t *p_object;
717 718
    QVector<vlc_object_t *> objects;
    QVector<const char *> varnames;
719

720
    /* Get the input and hold it */
721
    p_object = THEMIM->getInput();
722

723
    InputAutoMenuBuilder( p_object, objects, varnames );
724 725

    /* Title and so on */
726 727