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

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>
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;
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 */
100
    if( !EMPTY_STR( icon ) )
101
    {
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
    {
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
    {
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
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

373 374 375 376
    if( !recentsMenu && var_InheritBool( p_intf, "qt-recentplay" ) )
        recentsMenu = new QMenu( qtr( "Open &Recent Media" ) );

    if( recentsMenu )
377 378 379 380
    {
        updateRecents( p_intf );
        menu->addMenu( recentsMenu );
    }
381
    menu->addSeparator();
382

383
    addDPStaticEntry( menu, qtr( I_PL_SAVE ), "", SLOT( savePlayingToPlaylist() ),
384 385
        "Ctrl+Y" );

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

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

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

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

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

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

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

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

431 432 433
    addDPStaticEntry( menu, qtr( "Program Guide" ), "", SLOT( epgDialog() ),
        "" );

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

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

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

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

Clément Stenac's avatar
Clément Stenac committed
448 449 450
    return menu;
}

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

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

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

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

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

496 497
    if( mi->getPlaylistView() )
        menu->addMenu( StandardPLPanel::viewSelectionMenu( mi->getPlaylistView() ) );
498

499 500
    menu->addSeparator();

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

    menu->addSeparator();

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

515 516
    CONNECT( action, triggered( bool ), mi, toggleMinimalView( bool ) );
    CONNECT( mi, minimalViewToggled( bool ), action, setChecked( bool ) );
517 518 519

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

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

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

544
    menu->addSeparator();
545 546 547 548

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

549
    /* Extensions */
550
    ExtensionsMenu( p_intf, menu );
551

552 553 554
    return menu;
}

555 556 557
/**
 * Interface Sub-Menu, to list extras interface and skins
 **/
558
QMenu *VLCMenuBar::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
559
{
560 561 562 563
    QVector<vlc_object_t *> objects;
    QVector<const char *> varnames;
    varnames.append( "intf-add" );
    objects.append( VLC_OBJECT(p_intf) );
Clément Stenac's avatar
Clément Stenac committed
564

565
    return Populate( p_intf, current, varnames, objects );
566 567
}

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

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

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

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

592 593
static inline void VolumeEntries( intf_thread_t *p_intf, QMenu *current )
{
594
    current->addSeparator();
595

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

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

617 618 619
    if (!audioDeviceMenu)
        audioDeviceMenu = new QMenu( qtr( "Audio &Device" ) );

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

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

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

641 642 643
    return Populate( p_intf, current, varnames, objects );
}

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

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

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

    return Populate( p_intf, current, varnames, objects );
663 664
}

665 666 667 668
/**
 * Main Video Menu
 * Subtitles are part of Video.
 **/
669
QMenu *VLCMenuBar::VideoMenu( intf_thread_t *p_intf, QMenu *current )
670
{
671
    input_thread_t *p_input;
672 673
    QVector<vlc_object_t *> objects;
    QVector<const char *> varnames;
674

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

679
        current->addSeparator();
680
        /* Surface modifiers */
681 682 683
        addActionWithCheckbox( current, "fullscreen", qtr( "&Fullscreen" ) );
        addActionWithCheckbox( current, "autoscale", qtr( "Always Fit &Window" ) );
        addActionWithCheckbox( current, "video-wallpaper", qtr( "Set as Wall&paper" ) );
684

685
        current->addSeparator();
686
        /* Size modifiers */
687 688 689
        addActionWithSubmenu( current, "zoom", qtr( "&Zoom" ) );
        addActionWithSubmenu( current, "aspect-ratio", qtr( "&Aspect Ratio" ) );
        addActionWithSubmenu( current, "crop", qtr( "&Crop" ) );
690 691 692

        current->addSeparator();
        /* Rendering modifiers */
693 694
        addActionWithSubmenu( current, "deinterlace", qtr( "&Deinterlace" ) );
        addActionWithSubmenu( current, "deinterlace-mode", qtr( "&Deinterlace mode" ) );
695 696 697 698

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

701 702
    p_input = THEMIM->getInput();

703
    VideoAutoMenuBuilder( THEPL, p_input, objects, varnames );
704

705
    return Populate( p_intf, current, varnames, objects );
706 707
}

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

717
    addActionWithSubmenu( menu, "title", qtr( "T&itle" ) );
718
    submenu = addActionWithSubmenu( menu, "chapter", qtr( "&Chapter" ) );
719
    submenu->setTearOffEnabled( true );
720
    addActionWithSubmenu( menu, "program", qtr( "&Program" ) );
721

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

730
    menu->addSeparator();
731

732 733 734 735 736 737 738
    if ( !rendererMenu )
        rendererMenu = RendererMenu( p_intf );

    menu->addMenu( rendererMenu );
    menu->addSeparator();


739
    PopupMenuControlEntries( menu, p_intf );
740

741
    EnableStaticEntries( menu, ( THEMIM->getInput() != NULL ) );
742
    return RebuildNavigMenu( p_intf, menu, true );
743 744
}

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

752
    /* Get the input and hold it */
753
    p_object = THEMIM->getInput();
754

755
    InputAutoMenuBuilder( p_object, objects, varnames );
756 757

    /* Title and so on */
758 759 760 761
    PUSH_VAR( "prev-title" );
    PUSH_VAR( "next-title" );
    PUSH_VAR( "prev-chapter" );
    PUSH_VAR( "next-chapter" );
762

763 764 765 766
    /* */
    EnableStaticEntries( menu, (p_object != NULL ) );
    Populate( p_intf, menu, varnames, objects );

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

776
    PopupMenuPlaylistEntries( menu, p_intf, p_object );
777

778
    return menu;
779
}
780

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

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

#define CREATE_POPUP \
Erwan Tulou's avatar
Erwan Tulou committed
809
    menu = new QMenu(); \
810
    Populate( p_intf, menu, varnames, objects ); \
811 812
    if( show ) \
        menu->popup( QCursor::pos() ); \
813

814
void VLCMenuBar::PopupMenuPlaylistEntries( QMenu *menu,
815 816 817
                                        intf_thread_t *p_intf,
                                        input_thread_t *p_input )
{
818 819 820
    QAction *action;

    /* Play or Pause action and icon */
821 822
    if( !p_input || var_GetInteger( p_input, "state" ) != PLAYING_S )
    {
823
        action = menu->addAction( qtr( "&Play" ),
824
                ActionsManager::getInstance( p_intf ), SLOT( play() ) );
825
#ifndef __APPLE__ /* No icons in menus in Mac */
826
        action->setIcon( QIcon( ":/toolbar/play_b.svg" ) );
827
#endif
828 829
    }
    else
830
    {
831
        action = addMIMStaticEntry( p_intf, menu, qtr( "Pause" ),
832
                ":/toolbar/pause_b.svg", SLOT( togglePlayPause() ) );
833
    }
834
    action->setData( ACTION_DELETE_ON_REBUILD );
835 836 837

    /* Stop */
    action = addMIMStaticEntry( p_intf, menu, qtr( "&Stop" ),
838
            ":/toolbar/stop_b.svg", SLOT( stop() ), true );
839 840
    if( !p_input )
        action->setEnabled( false );
841
    action->setData( ACTION_DELETE_ON_REBUILD );
842 843 844 845

    /* Next / Previous */
    bool bPlaylistEmpty = THEMIM->hasEmptyPlaylist();
    action = addMIMStaticEntry( p_intf, menu, qtr( "Pre&vious" ),
846
            ":/toolbar/previous_b.svg", SLOT( prev() ), true );
847
    action->setEnabled( !bPlaylistEmpty );
848
    action->setData( ACTION_NO_CLEANUP + ACTION_DELETE_ON_REBUILD );
849 850 851
    CONNECT( THEMIM, playlistNotEmpty(bool), action, setEnabled(bool) );

    action = addMIMStaticEntry( p_intf, menu, qtr( "Ne&xt" ),
852
            ":/toolbar/next_b.svg", SLOT( next() ), true );
853
    action->setEnabled( !bPlaylistEmpty );
854
    action->setData( ACTION_NO_CLEANUP + ACTION_DELETE_ON_REBUILD );
855 856
    CONNECT( THEMIM, playlistNotEmpty(bool), action, setEnabled(bool) );

857
    action = menu->addAction( qtr( "Record" ), THEAM, SLOT( record() ) );
858
    action->setIcon( QIcon( ":/toolbar/record.svg" ) );
859 860
    if( !p_input )
        action->setEnabled( false );
861
    action->setData( ACTION_NO_CLEANUP + ACTION_DELETE_ON_REBUILD );
862
    menu->addSeparator();
863 864
}

865
void VLCMenuBar::PopupMenuControlEntries( QMenu *menu, intf_thread_t *p_intf,
866
                                        bool b_normal )
867 868
{
    QAction *action;
869
    QMenu *rateMenu = new QMenu( qtr( "Sp&eed" ), menu );
870
    rateMenu->setTearOffEnabled( true );
871

872 873 874
    if( b_normal )
    {
        /* Faster/Slower */
875
        action = rateMenu->addAction( qtr( "&Faster" ), THEMIM->getIM(),
876
                                  SLOT( faster() ) );
877
#ifndef __APPLE__ /* No icons in menus in Mac */
878
        action->setIcon( QIcon( ":/toolbar/faster2.svg") );
879
#endif
880
        action->setData( ACTION_STATIC );
881
    }
882

883
    action = rateMenu->addAction( QIcon( ":/toolbar/faster2.svg" ), qtr( "Faster (fine)" ), THEMIM->getIM(),
884
                              SLOT( littlefaster() ) );
885
    action->setData( ACTION_STATIC );
886

887
    action = rateMenu->addAction( qtr( "N&ormal Speed" ), THEMIM->getIM(),
888
                              SLOT( normalRate() ) );
889
    action->setData( ACTION_STATIC );
890

891
    action = rateMenu->addAction( QIcon( ":/toolbar/slower2.svg" ), qtr( "Slower (fine)" ), THEMIM->getIM(),
892
                              SLOT( littleslower() ) );
893
    action->setData( ACTION_STATIC );
894

895 896
    if( b_normal )
    {
897
        action = rateMenu->addAction( qtr( "Slo&wer" ), THEMIM->getIM(),
898
                                  SLOT( slower() ) );
899
#ifndef __APPLE__ /* No icons in menus in Mac */
900
        action->setIcon( QIcon( ":/toolbar/slower2.svg") );
901
#endif
902
        action->setData( ACTION_STATIC );
903
    }
904

905
    action = menu->addMenu( rateMenu );
906
    action->setData( ACTION_STATIC );
907

908
    menu->addSeparator();
909

910 911
    if( !b_normal ) return;

912
    action = menu->addAction( qtr( "&Jump Forward" ), THEMIM->getIM(),
913
             SLOT( jumpFwd() ) );
914
#ifndef __APPLE__ /* No icons in menus in Mac */
915
    action->setIcon( QIcon( ":/toolbar/skip_fw.svg") );
916
#endif
917
    action->setData( ACTION_STATIC );
918

919
    action = menu->addAction( qtr( "Jump Bac&kward" ), THEMIM->getIM(),
920
             SLOT( jumpBwd() ) );
921
#ifndef __APPLE__ /* No icons in menus in Mac */
922
    action->setIcon( QIcon( ":/toolbar/skip_back.svg") );
923
#endif
924
    action->setData( ACTION_STATIC );
925 926 927 928

    action = menu->addAction( qtr( I_MENU_GOTOTIME ), THEDP, SLOT( gotoTimeDialog() ), qtr( "Ctrl+T" ) );
    action->setData( ACTION_ALWAYS_ENABLED );

929
    menu->addSeparator();
930 931
}

932
void VLCMenuBar::PopupMenuStaticEntries( QMenu *menu )
933
{
934
    QMenu *openmenu = new QMenu( qtr( "Open Media" ), menu );
Christoph Miebach's avatar
Christoph Miebach committed
935
    addDPStaticEntry( openmenu, qtr( I_OP_OPF ),
936
        ":/type/file-asym.svg", SLOT( openFileDialog() ) );
937
    addDPStaticEntry( openmenu, qtr( I_OP_OPDIR ),
938
        ":/type/folder-grey.svg", SLOT( PLOpenDir() ) );
939
    addDPStaticEntry( openmenu, qtr( "Open &Disc..." ),
940
        ":/type/disc.svg", SLOT( openDiscDialog