menus.cpp 52 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
 */

30 31 32 33
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

34
#include <vlc_common.h>
35
#include <vlc_intf_strings.h>
36 37
#include <vlc_vout.h>                             /* vout_thread_t */
#include <vlc_aout.h>                             /* audio_output_t */
38

39
#include "menus.hpp"
40

41 42 43 44 45 46 47 48
#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 */
49
#include "components/playlist/standardpanel.hpp"  /* PLView getter */
50
#include "components/extended_panels.hpp"
51

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

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

63 64 65
  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
66 67 68 69 70 71 72
  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.
  */

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

static QActionGroup *currentGroup;

82
QMenu *VLCMenuBar::recentsMenu = NULL;
83
QMenu *VLCMenuBar::audioDeviceMenu = NULL;
84 85
QMenu *VLCMenuBar::rendererMenu = NULL;
QActionGroup *VLCMenuBar::rendererGroup = NULL;
Ludovic Fauvet's avatar
Ludovic Fauvet committed
86

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

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

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

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

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

183
    int i_ret = 0;
184

185
    QList< QAction* > actions = menu->actions();
186
    for( int i = 0; i < actions.count(); ++i )
187
    {
188
        if( actions[i]->data().toInt() & VLCMenuBar::ACTION_NO_CLEANUP )
189
            i_ret++;
190 191
        else
            delete actions[i];
192
    }
193
    return i_ret;
194 195
}

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

210
/*****************************************************************************
211
 * Definitions of variables for the dynamic menus
212
 *****************************************************************************/
213 214 215 216 217 218 219 220
#define PUSH_OBJVAR(object,var) \
    do { \
        varnames.append(var); \
        objects.append(VLC_OBJECT(object)); \
    } while (0)

#define PUSH_VAR(var) PUSH_OBJVAR(p_object, var)
#define PUSH_INPUTVAR(var) PUSH_OBJVAR(p_input, var)
221
#define PUSH_PLVAR(var) PUSH_OBJVAR(pl, var)
222

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
223 224
static int InputAutoMenuBuilder( input_thread_t *p_input,
        QVector<vlc_object_t *> &objects, QVector<const char *> &varnames )
225
{
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
226 227 228 229 230
    PUSH_INPUTVAR( "bookmark" );
    PUSH_INPUTVAR( "title" );
    PUSH_INPUTVAR( "chapter" );
    PUSH_INPUTVAR( "program" );

231 232 233
    return VLC_SUCCESS;
}

234
static int VideoAutoMenuBuilder( playlist_t *pl, input_thread_t *p_input,
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
235
        QVector<vlc_object_t *> &objects, QVector<const char *> &varnames )
236
{
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
237 238
    vout_thread_t *p_object = p_input ? input_GetVout( p_input ) : NULL;

239
    PUSH_INPUTVAR( "video-es" );
240
    PUSH_PLVAR( "fullscreen" );
241
    PUSH_PLVAR( "video-wallpaper" );
242
    PUSH_VAR( "video-snapshot" );
243
    PUSH_VAR( "zoom" );
244
    PUSH_VAR( "autoscale" );
245 246
    PUSH_VAR( "aspect-ratio" );
    PUSH_VAR( "crop" );
247
    PUSH_VAR( "deinterlace" );
248
    PUSH_VAR( "deinterlace-mode" );
249

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
250 251
    if( p_object )
        vlc_object_release( p_object );
252 253 254
    return VLC_SUCCESS;
}

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
255 256
static int SubsAutoMenuBuilder( input_thread_t *p_input,
        QVector<vlc_object_t *> &objects, QVector<const char *> &varnames )
257
{
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
258
    PUSH_INPUTVAR( "spu-es" );
259 260 261 262

    return VLC_SUCCESS;
}

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
263 264
static int AudioAutoMenuBuilder( input_thread_t *p_input,
        QVector<vlc_object_t *> &objects, QVector<const char *> &varnames )
265
{
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
266 267
    audio_output_t *p_object = p_input ? input_GetAout( p_input ) : NULL;

268
    PUSH_INPUTVAR( "audio-es" );
269
    PUSH_VAR( "stereo-mode" );
270
    PUSH_VAR( "visual" );
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
271 272 273

    if( p_object )
        vlc_object_release( p_object );
274 275 276
    return VLC_SUCCESS;
}

277 278
/*****************************************************************************
 * All normal menus
279
 * Simple Code
280 281
 *****************************************************************************/

282
// Static menu
283 284 285 286
static inline void addMenuToMainbar( QMenu *func, QString title, QMenuBar *bar ) {
    func->setTitle( title );
    bar->addMenu( func);
}
287

288
// Dynamic menu
289
#define BAR_DADD( func, title, id ) { \
290 291 292 293 294
    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 ); }

295
// Add a simple action
296 297 298 299 300
static inline void addAction( QMenu *_menu, QVariant val, QString title ) {
    QAction *_action = new QAction( title, _menu );
    _action->setData( val );
    _menu->addAction( _action );
}
301

302
// Add an action with a submenu
303
static inline QMenu *addActionWithSubmenu( QMenu *_menu, QVariant val, QString title ) {
304
    QAction *_action = new QAction( title, _menu );
305
    QMenu *_submenu = new QMenu( _menu );
306
    _action->setData( val );
307
    _action->setMenu( _submenu );
308
    _menu->addAction( _action );
309
    return _submenu;
310
}
311

312
// Add an action that is a checkbox
313 314 315 316 317 318
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 );
}
319

320 321 322
/**
 * Main Menu Bar Creation
 **/
323
void VLCMenuBar::createMenuBar( MainInterface *mi,
324
                              intf_thread_t *p_intf )
Clément Stenac's avatar
Qt4:  
Clément Stenac committed
325
{
326 327 328
    /* QMainWindows->menuBar()
       gives the QProcess::destroyed timeout issue on Cleanlooks style with
       setDesktopAware set to false */
329
    QMenuBar *bar = mi->menuBar();
330

331
    addMenuToMainbar( FileMenu( p_intf, bar, mi ), qtr( "&Media" ), bar );
332

333
    /* Dynamic menus, rebuilt before being showed */
334
    BAR_DADD( NavigMenu( p_intf, bar ), qtr( "P&layback" ), 3 );
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
335 336
    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
337
    BAR_DADD( SubtitleMenu( p_intf, bar ), qtr( "Subti&tle" ), 5 );
338

339
    addMenuToMainbar( ToolsMenu( p_intf, bar ), qtr( "Tool&s" ), bar );
340 341

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

344
    addMenuToMainbar( HelpMenu( bar ), qtr( "&Help" ), bar );
345

346
}
347 348

/**
349
 * Media ( File ) Menu
350 351
 * Opening, streaming and quit
 **/
352
QMenu *VLCMenuBar::FileMenu( intf_thread_t *p_intf, QWidget *parent, MainInterface *mi )
353
{
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
354
    QMenu *menu = new QMenu( parent );
355
    QAction *action;
356

357
    addDPStaticEntry( menu, qtr( "Open &File..." ),
358
        ":/type/file-asym.svg", SLOT( simpleOpenDialog() ), "Ctrl+O" );
359
    addDPStaticEntry( menu, qtr( "&Open Multiple Files..." ),
360
        ":/type/file-asym.svg", SLOT( openFileDialog() ), "Ctrl+Shift+O" );
361
    addDPStaticEntry( menu, qtr( I_OP_OPDIR ),
362
        ":/type/folder-grey.svg", SLOT( PLOpenDir() ), "Ctrl+F" );
363
    addDPStaticEntry( menu, qtr( "Open &Disc..." ),
364
        ":/type/disc.svg", SLOT( openDiscDialog() ), "Ctrl+D" );
365
    addDPStaticEntry( menu, qtr( "Open &Network Stream..." ),
366
        ":/type/network.svg", SLOT( openNetDialog() ), "Ctrl+N" );
367
    addDPStaticEntry( menu, qtr( "Open &Capture Device..." ),
368
        ":/type/capture-card.svg", SLOT( openCaptureDialog() ), "Ctrl+C" );
369

370
    addDPStaticEntry( menu, qtr( "Open &Location from clipboard" ),
371
                      NULL, SLOT( openUrlDialog() ), "Ctrl+V" );
372

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
373
    if( var_InheritBool( p_intf, "qt-recentplay" ) )
374
    {
375
        recentsMenu = new QMenu( qtr( "Open &Recent Media" ), menu );
376 377 378
        updateRecents( p_intf );
        menu->addMenu( recentsMenu );
    }
379
    menu->addSeparator();
380

381
    addDPStaticEntry( menu, qtr( I_PL_SAVE ), "", SLOT( savePlayingToPlaylist() ),
382 383
        "Ctrl+Y" );

384
#ifdef ENABLE_SOUT
385
    addDPStaticEntry( menu, qtr( "Conve&rt / Save..." ), "",
386
        SLOT( openAndTranscodingDialogs() ), "Ctrl+R" );
387
    addDPStaticEntry( menu, qtr( "&Stream..." ),
388
        ":/menu/stream.svg", SLOT( openAndStreamingDialogs() ), "Ctrl+S" );
389
    menu->addSeparator();
390
#endif
391

392 393 394 395 396
    action = addMIMStaticEntry( p_intf, menu, qtr( "Quit at the end of playlist" ), "",
                               SLOT( activatePlayQuit( bool ) ) );
    action->setCheckable( true );
    action->setChecked( THEMIM->getPlayExitState() );

397
    if( mi && mi->getSysTray() )
398 399 400 401 402
    {
        action = menu->addAction( qtr( "Close to systray"), mi,
                                 SLOT( toggleUpdateSystrayMenu() ) );
    }

403
    addDPStaticEntry( menu, qtr( "&Quit" ) ,
404
        ":/menu/exit.svg", SLOT( quit() ), "Ctrl+Q" );
405 406 407
    return menu;
}

408
/**
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
409
 * Tools, like Media Information, Preferences or Messages
410
 **/
411
QMenu *VLCMenuBar::ToolsMenu( intf_thread_t *p_intf, QMenu *menu )
Clément Stenac's avatar
Clément Stenac committed
412
{
413
    addDPStaticEntry( menu, qtr( "&Effects and Filters"), ":/menu/settings.svg",
414
            SLOT( extendedDialog() ), "Ctrl+E" );
415

416
    addDPStaticEntry( menu, qtr( "&Track Synchronization"), ":/menu/setting.svgs",
417 418
            SLOT( synchroDialog() ), "" );

419
    addDPStaticEntry( menu, qtr( I_MENU_INFO ) , ":/menu/info.svg",
420
        SLOT( mediaInfoDialog() ), "Ctrl+I" );
421
    addDPStaticEntry( menu, qtr( I_MENU_CODECINFO ) ,
422
        ":/menu/info.svg", SLOT( mediaCodecDialog() ), "Ctrl+J" );
423

424
#ifdef ENABLE_VLM
425
    addDPStaticEntry( menu, qtr( I_MENU_VLM ), "", SLOT( vlmDialog() ),
426
        "Ctrl+Shift+W" );
427
#endif
428

429 430 431
    addDPStaticEntry( menu, qtr( "Program Guide" ), "", SLOT( epgDialog() ),
        "" );

432
    addDPStaticEntry( menu, qtr( I_MENU_MSG ),
433
        ":/menu/messages.svg", SLOT( messagesDialog() ), "Ctrl+M" );
434

435 436
    addDPStaticEntry( menu, qtr( "Plu&gins and extensions" ),
        "", SLOT( pluginDialog() ) );
Clément Stenac's avatar
Clément Stenac committed
437 438
    menu->addSeparator();

439 440
    if( !p_intf->p_sys->b_isDialogProvider )
        addDPStaticEntry( menu, qtr( "Customi&ze Interface..." ),
441
            ":/menu/preferences.svg", SLOT( toolbarDialog() ) );
442

443
    addDPStaticEntry( menu, qtr( "&Preferences" ),
444
        ":/menu/preferences.svg", SLOT( prefsDialog() ), "Ctrl+P", QAction::PreferencesRole );
445

Clément Stenac's avatar
Clément Stenac committed
446 447 448
    return menu;
}

449
/**
450
 * View Menu
451
 * Interface modification, load other interfaces, activate Extensions
452
 * \param current, set to NULL for menu creation, else for menu update
453
 **/
454
QMenu *VLCMenuBar::ViewMenu( intf_thread_t *p_intf, QMenu *current, MainInterface *_mi )
455
{
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
456
    QAction *action;
457
    QMenu *menu;
458

459 460 461
    MainInterface *mi = _mi ? _mi : p_intf->p_sys->p_mi;
    assert( mi );

462 463
    if( !current )
    {
464
        menu = new QMenu( qtr( "&View" ), mi );
465
    }
466 467 468
    else
    {
        menu = current;
469 470 471 472 473 474 475 476
        //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 );
477
            if( m && m->parent() == menu ) delete m;
478
        }
479
    }
480

481 482
    menu->addAction(
#ifndef __APPLE__
483
            QIcon( ":/menu/playlist_menu.svg" ),
484
#endif
485 486 487
            qtr( "Play&list" ), mi,
            SLOT( togglePlaylist() ), qtr( "Ctrl+L" ) );

488 489 490 491 492 493
    /* Docked Playlist */
    action = menu->addAction( qtr( "Docked Playlist" ) );
    action->setCheckable( true );
    action->setChecked( mi->isPlDocked() );
    CONNECT( action, triggered( bool ), mi, dockPlaylist( bool ) );

494 495
    if( mi->getPlaylistView() )
        menu->addMenu( StandardPLPanel::viewSelectionMenu( mi->getPlaylistView() ) );
496

497 498
    menu->addSeparator();

499 500 501 502 503 504 505
    action = menu->addAction( qtr( "Always on &top" ) );
    action->setCheckable( true );
    action->setChecked( mi->isInterfaceAlwaysOnTop() );
    CONNECT( action, triggered( bool ), mi, setInterfaceAlwaysOnTop( bool ) );

    menu->addSeparator();

506
    /* Minimal View */
507
    action = menu->addAction( qtr( "Mi&nimal Interface" ) );
508
    action->setShortcut( qtr( "Ctrl+H" ) );
509
    action->setCheckable( true );
510 511
    action->setChecked( (mi->getControlsVisibilityStatus()
                         & MainInterface::CONTROLS_HIDDEN ) );
512

513 514
    CONNECT( action, triggered( bool ), mi, toggleMinimalView( bool ) );
    CONNECT( mi, minimalViewToggled( bool ), action, setChecked( bool ) );
515 516 517

    /* FullScreen View */
    action = menu->addAction( qtr( "&Fullscreen Interface" ), mi,
518
            SLOT( toggleInterfaceFullScreen() ), QString( "F11" ) );
519
    action->setCheckable( true );
520
    action->setChecked( mi->isInterfaceFullScreen() );
521 522
    CONNECT( mi, fullscreenInterfaceToggled( bool ),
             action, setChecked( bool ) );
523 524 525

    /* Advanced Controls */
    action = menu->addAction( qtr( "&Advanced Controls" ), mi,
526
            SLOT( toggleAdvancedButtons() ) );
527
    action->setCheckable( true );
528
    if( mi->getControlsVisibilityStatus() & MainInterface::CONTROLS_ADVANCED )
529 530
        action->setChecked( true );

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
531 532 533 534
    action = menu->addAction( qtr( "Status Bar" ) );
    action->setCheckable( true );
    action->setChecked( mi->statusBar()->isVisible() );
    CONNECT( action, triggered( bool ), mi, setStatusBarVisibility( bool) );
535
#if 0 /* For Visualisations. Not yet working */
536 537
    adv = menu->addAction( qtr( "Visualizations selector" ), mi,
                           SLOT( visual() ) );
538 539
    adv->setCheckable( true );
    if( visual_selector_enabled ) adv->setChecked( true );
540
#endif
541

542
    menu->addSeparator();
543 544 545 546

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

547
    /* Extensions */
548
    ExtensionsMenu( p_intf, menu );
549

550 551 552
    return menu;
}

553 554 555
/**
 * Interface Sub-Menu, to list extras interface and skins
 **/
556
QMenu *VLCMenuBar::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
557
{
558 559 560 561
    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
562

563
    return Populate( p_intf, current, varnames, objects );
564 565
}

566
/**
567
 * Extensions menu: populate the current menu with extensions
568
 **/
569
void VLCMenuBar::ExtensionsMenu( intf_thread_t *p_intf, QMenu *extMenu )
570
{
571
    /* Get ExtensionsManager and load extensions if needed */
572
    ExtensionsManager *extMgr = ExtensionsManager::getInstance( p_intf );
573 574 575 576 577 578 579

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

580
    if( !extMgr->isLoaded() && !extMgr->cannotLoad() )
581
    {
582
        extMgr->loadExtensions();
583
    }
584

585
    /* Let the ExtensionsManager build itself the menu */
586
    extMenu->addSeparator();
587
    extMgr->menu( extMenu );
588 589
}

590 591
static inline void VolumeEntries( intf_thread_t *p_intf, QMenu *current )
{
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
592
    current->addSeparator();
593

594
    QAction *action = current->addAction( QIcon( ":/toolbar/volume-high.svg" ), qtr( "&Increase Volume" ),
595
                ActionsManager::getInstance( p_intf ), SLOT( AudioUp() ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
596
    action->setData( VLCMenuBar::ACTION_STATIC );
597
    action = current->addAction( QIcon( ":/toolbar/volume-low.svg" ), qtr( "D&ecrease Volume" ),
598
                ActionsManager::getInstance( p_intf ), SLOT( AudioDown() ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
599
    action->setData( VLCMenuBar::ACTION_STATIC );
600
    action = current->addAction( QIcon( ":/toolbar/volume-muted.svg" ), qtr( "&Mute" ),
601
                ActionsManager::getInstance( p_intf ), SLOT( toggleMuteAudio() ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
602
    action->setData( VLCMenuBar::ACTION_STATIC );
603 604
}

605 606
/**
 * Main Audio Menu
607
 **/
608
QMenu *VLCMenuBar::AudioMenu( intf_thread_t *p_intf, QMenu * current )
609
{
610 611
    QVector<vlc_object_t *> objects;
    QVector<const char *> varnames;
612
    audio_output_t *p_aout;
613 614
    input_thread_t *p_input;

615 616 617
    if (!audioDeviceMenu)
        audioDeviceMenu = new QMenu( qtr( "Audio &Device" ) );

618
    if( current->isEmpty() )
619
    {
620
        addActionWithSubmenu( current, "audio-es", qtr( "Audio &Track" ) );
621
        current->addMenu( audioDeviceMenu );
622
        addActionWithSubmenu( current, "stereo-mode", qtr( "&Stereo Mode" ) );
623
        current->addSeparator();
624

625
        addActionWithSubmenu( current, "visual", qtr( "&Visualizations" ) );
626
        VolumeEntries( p_intf, current );
627 628
    }

629
    p_input = THEMIM->getInput();
630
    p_aout = THEMIM->getAout();
631
    EnableStaticEntries( current, ( p_aout != NULL ) );
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
632
    AudioAutoMenuBuilder( p_input, objects, varnames );
633
    updateAudioDevice( p_intf, p_aout, audioDeviceMenu );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
634
    if( p_aout )
635
    {
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
636
        vlc_object_release( p_aout );
637
    }
638

639 640 641
    return Populate( p_intf, current, varnames, objects );
}

642
/* Subtitles */
643
QMenu *VLCMenuBar::SubtitleMenu( intf_thread_t *p_intf, QMenu *current, bool b_popup )
644
{
645 646 647 648
    input_thread_t *p_input;
    QVector<vlc_object_t *> objects;
    QVector<const char *> varnames;

649
    if( current->isEmpty() || b_popup )
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
650
    {
651
        addDPStaticEntry( current, qtr( "Add &Subtitle File..." ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
652
                SLOT( loadSubtitlesFile() ) );
653 654
        addActionWithSubmenu( current, "spu-es", qtr( "Sub &Track" ) );
        current->addSeparator();
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
655
    }
656 657 658 659 660

    p_input = THEMIM->getInput();
    SubsAutoMenuBuilder( p_input, objects, varnames );

    return Populate( p_intf, current, varnames, objects );
661 662
}

663 664 665 666
/**
 * Main Video Menu
 * Subtitles are part of Video.
 **/
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
667
QMenu *VLCMenuBar::VideoMenu( intf_thread_t *p_intf, QMenu *current )
668
{
669
    input_thread_t *p_input;
670 671
    QVector<vlc_object_t *> objects;
    QVector<const char *> varnames;
672

673 674 675
    if ( !rendererMenu )
        rendererMenu = RendererMenu( p_intf );

676
    if( current->isEmpty() )
677
    {
678
        addActionWithSubmenu( current, "video-es", qtr( "Video &Track" ) );
679

680 681 682
        current->addSeparator();
        current->addMenu( rendererMenu );

683
        current->addSeparator();
684
        /* Surface modifiers */
685 686 687
        addActionWithCheckbox( current, "fullscreen", qtr( "&Fullscreen" ) );
        addActionWithCheckbox( current, "autoscale", qtr( "Always Fit &Window" ) );
        addActionWithCheckbox( current, "video-wallpaper", qtr( "Set as Wall&paper" ) );
688

689
        current->addSeparator();
690
        /* Size modifiers */
691 692 693
        addActionWithSubmenu( current, "zoom", qtr( "&Zoom" ) );
        addActionWithSubmenu( current, "aspect-ratio", qtr( "&Aspect Ratio" ) );
        addActionWithSubmenu( current, "crop", qtr( "&Crop" ) );
694 695 696

        current->addSeparator();
        /* Rendering modifiers */
697 698
        addActionWithSubmenu( current, "deinterlace", qtr( "&Deinterlace" ) );
        addActionWithSubmenu( current, "deinterlace-mode", qtr( "&Deinterlace mode" ) );
699 700 701 702

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

705 706
    p_input = THEMIM->getInput();

707
    VideoAutoMenuBuilder( THEPL, p_input, objects, varnames );
708

709
    return Populate( p_intf, current, varnames, objects );
710 711
}

712 713 714 715
/**
 * Navigation Menu
 * For DVD, MP4, MOV and other chapter based format
 **/
716
QMenu *VLCMenuBar::NavigMenu( intf_thread_t *p_intf, QMenu *menu )
717
{
718
    QAction *action;
719
    QMenu *submenu;
720

721
    addActionWithSubmenu( menu, "title", qtr( "T&itle" ) );
722
    submenu = addActionWithSubmenu( menu, "chapter", qtr( "&Chapter" ) );
723
    submenu->setTearOffEnabled( true );
724
    addActionWithSubmenu( menu, "program", qtr( "&Program" ) );
725

Christoph Miebach's avatar
Christoph Miebach committed
726
    submenu = new QMenu( qtr( I_MENU_BOOKMARK ), menu );
727
    submenu->setTearOffEnabled( true );
728 729 730 731 732 733
    addDPStaticEntry( submenu, qtr( "&Manage" ), "",
                      SLOT( bookmarksDialog() ), "Ctrl+B" );
    submenu->addSeparator();
    action = menu->addMenu( submenu );
    action->setData( "bookmark" );

734
    menu->addSeparator();
735

736
    PopupMenuControlEntries( menu, p_intf );
737

738
    EnableStaticEntries( menu, ( THEMIM->getInput() != NULL ) );
739
    return RebuildNavigMenu( p_intf, menu, true );
740 741
}

742
QMenu *VLCMenuBar::RebuildNavigMenu( intf_thread_t *p_intf, QMenu *menu, bool b_keep )
743
{
744
    /* */
745
    input_thread_t *p_object;
746 747
    QVector<vlc_object_t *> objects;
    QVector<const char *> varnames;
748

749
    /* Get the input and hold it */
750
    p_object = THEMIM->getInput();
751

752
    InputAutoMenuBuilder( p_object, objects, varnames );
753 754

    /* Title and so on */
755 756 757 758
    PUSH_VAR( "prev-title" );
    PUSH_VAR( "next-title" );
    PUSH_VAR( "prev-chapter" );
    PUSH_VAR( "next-chapter" );
759

760 761 762 763
    /* */
    EnableStaticEntries( menu, (p_object != NULL ) );
    Populate( p_intf, menu, varnames, objects );

764 765 766 767
    /* Remove playback actions to recreate them */
    if( !b_keep )
    {
        QList< QAction* > actions = menu->actions();
768 769
        for( int i = 0; i < actions.count(); i++ )
            if( actions[i]->data().toInt() & ACTION_DELETE_ON_REBUILD )
770 771 772
                delete actions[i];
    }

773
    PopupMenuPlaylistEntries( menu, p_intf, p_object );
774

775
    return menu;
776
}
777

778 779 780
/**
 * Help/About Menu
**/
781
QMenu *VLCMenuBar::HelpMenu( QWidget *parent )
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
782
{
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
783
    QMenu *menu = new QMenu( parent );
784
    addDPStaticEntry( menu, qtr( "&Help" ) ,
785
        ":/menu/help.svg", SLOT( helpDialog() ), "F1" );
786
#ifdef UPDATE_CHECK
787 788
    addDPStaticEntry( menu, qtr( "Check for &Updates..." ) , "",
                      SLOT( updateDialog() ) );
789
#endif
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
790
    menu->addSeparator();
791
    addDPStaticEntry( menu, qtr( I_MENU_ABOUT ), ":/menu/info.svg",
792
            SLOT( aboutDialog() ), "Shift+F1", QAction::AboutRole );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
793 794 795
    return menu;
}

796
/*****************************************************************************
797
 * Popup menus - Right Click menus                                           *
798
 *****************************************************************************/
799
#define POPUP_BOILERPLATE \
800
    QMenu* menu;  \
801 802
    QVector<vlc_object_t *> objects; \
    QVector<const char *> varnames; \
803 804 805
    input_thread_t *p_input = THEMIM->getInput();

#define CREATE_POPUP \
Erwan Tulou's avatar
Erwan Tulou committed
806
    menu = new QMenu(); \