menus.cpp 51.6 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 241
    PUSH_PLVAR( "fullscreen" );
    PUSH_PLVAR( "video-on-top" );
242
    PUSH_PLVAR( "video-wallpaper" );
243
    PUSH_VAR( "video-snapshot" );
244
    PUSH_VAR( "zoom" );
245
    PUSH_VAR( "autoscale" );
246 247
    PUSH_VAR( "aspect-ratio" );
    PUSH_VAR( "crop" );
248
    PUSH_VAR( "deinterlace" );
249
    PUSH_VAR( "deinterlace-mode" );
250

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

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

    return VLC_SUCCESS;
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

347
}
348 349

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

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

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

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

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

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

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

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

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

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

417
    addDPStaticEntry( menu, qtr( "&Track Synchronization"), ":/menu/settings",
418 419
            SLOT( synchroDialog() ), "" );

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

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

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

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

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

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

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

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

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

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

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

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

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

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

498 499
    menu->addSeparator();

500
    /* Minimal View */
501
    action = menu->addAction( qtr( "Mi&nimal Interface" ) );
502
    action->setShortcut( qtr( "Ctrl+H" ) );
503
    action->setCheckable( true );
504 505
    action->setChecked( (mi->getControlsVisibilityStatus()
                         & MainInterface::CONTROLS_HIDDEN ) );
506

507 508
    CONNECT( action, triggered( bool ), mi, toggleMinimalView( bool ) );
    CONNECT( mi, minimalViewToggled( bool ), action, setChecked( bool ) );
509 510 511

    /* FullScreen View */
    action = menu->addAction( qtr( "&Fullscreen Interface" ), mi,
512
            SLOT( toggleInterfaceFullScreen() ), QString( "F11" ) );
513
    action->setCheckable( true );
514
    action->setChecked( mi->isInterfaceFullScreen() );
515 516
    CONNECT( mi, fullscreenInterfaceToggled( bool ),
             action, setChecked( bool ) );
517 518 519

    /* Advanced Controls */
    action = menu->addAction( qtr( "&Advanced Controls" ), mi,
520
            SLOT( toggleAdvancedButtons() ) );
521
    action->setCheckable( true );
522
    if( mi->getControlsVisibilityStatus() & MainInterface::CONTROLS_ADVANCED )
523 524
        action->setChecked( true );

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

536
    menu->addSeparator();
537 538 539 540

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

541
    /* Extensions */
542
    ExtensionsMenu( p_intf, menu );
543

544 545 546
    return menu;
}

547 548 549
/**
 * Interface Sub-Menu, to list extras interface and skins
 **/
550
QMenu *VLCMenuBar::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
551
{
552 553 554 555
    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
556

557
    return Populate( p_intf, current, varnames, objects );
558 559
}

560
/**
561
 * Extensions menu: populate the current menu with extensions
562
 **/
563
void VLCMenuBar::ExtensionsMenu( intf_thread_t *p_intf, QMenu *extMenu )
564
{
565
    /* Get ExtensionsManager and load extensions if needed */
566
    ExtensionsManager *extMgr = ExtensionsManager::getInstance( p_intf );
567 568 569 570 571 572 573

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

574
    if( !extMgr->isLoaded() && !extMgr->cannotLoad() )
575
    {
576
        extMgr->loadExtensions();
577
    }
578

579
    /* Let the ExtensionsManager build itself the menu */
580
    extMenu->addSeparator();
581
    extMgr->menu( extMenu );
582 583
}

584 585
static inline void VolumeEntries( intf_thread_t *p_intf, QMenu *current )
{
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
586
    current->addSeparator();
587

588
    QAction *action = current->addAction( QIcon( ":/toolbar/volume-high" ), qtr( "&Increase Volume" ),
589
                ActionsManager::getInstance( p_intf ), SLOT( AudioUp() ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
590
    action->setData( VLCMenuBar::ACTION_STATIC );
591
    action = current->addAction( QIcon( ":/toolbar/volume-low" ), qtr( "D&ecrease Volume" ),
592
                ActionsManager::getInstance( p_intf ), SLOT( AudioDown() ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
593
    action->setData( VLCMenuBar::ACTION_STATIC );
594
    action = current->addAction( QIcon( ":/toolbar/volume-muted" ), qtr( "&Mute" ),
595
                ActionsManager::getInstance( p_intf ), SLOT( toggleMuteAudio() ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
596
    action->setData( VLCMenuBar::ACTION_STATIC );
597 598
}

599 600
/**
 * Main Audio Menu
601
 **/
602
QMenu *VLCMenuBar::AudioMenu( intf_thread_t *p_intf, QMenu * current )
603
{
604 605
    QVector<vlc_object_t *> objects;
    QVector<const char *> varnames;
606
    audio_output_t *p_aout;
607 608 609
    input_thread_t *p_input;

    if( current->isEmpty() )
610
    {
611
        addActionWithSubmenu( current, "audio-es", qtr( "Audio &Track" ) );
612 613
        audioDeviceMenu = new QMenu( qtr( "Audio &Device" ) );
        current->addMenu( audioDeviceMenu );
614
        addActionWithSubmenu( current, "stereo-mode", qtr( "&Stereo Mode" ) );
615
        current->addSeparator();
616

617
        addActionWithSubmenu( current, "visual", qtr( "&Visualizations" ) );
618
        VolumeEntries( p_intf, current );
619 620
    }

621
    p_input = THEMIM->getInput();
622
    p_aout = THEMIM->getAout();
623
    EnableStaticEntries( current, ( p_aout != NULL ) );
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
624
    AudioAutoMenuBuilder( p_input, objects, varnames );
625
    updateAudioDevice( p_intf, p_aout, audioDeviceMenu );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
626
    if( p_aout )
627
    {
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
628
        vlc_object_release( p_aout );
629
    }
630

631 632 633
    return Populate( p_intf, current, varnames, objects );
}

634
/* Subtitles */
635
QMenu *VLCMenuBar::SubtitleMenu( intf_thread_t *p_intf, QMenu *current, bool b_popup )
636
{
637 638 639 640
    input_thread_t *p_input;
    QVector<vlc_object_t *> objects;
    QVector<const char *> varnames;

641
    if( current->isEmpty() || b_popup )
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
642
    {
643
        addDPStaticEntry( current, qtr( "Add &Subtitle File..." ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
644
                SLOT( loadSubtitlesFile() ) );
645 646
        addActionWithSubmenu( current, "spu-es", qtr( "Sub &Track" ) );
        current->addSeparator();
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
647
    }
648 649 650 651 652

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

    return Populate( p_intf, current, varnames, objects );
653 654
}

655 656 657 658
/**
 * Main Video Menu
 * Subtitles are part of Video.
 **/
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
659
QMenu *VLCMenuBar::VideoMenu( intf_thread_t *p_intf, QMenu *current )
660
{
661
    input_thread_t *p_input;
662 663
    QVector<vlc_object_t *> objects;
    QVector<const char *> varnames;
664

665
    if( current->isEmpty() )
666
    {
667
        addActionWithSubmenu( current, "video-es", qtr( "Video &Track" ) );
668

669 670 671 672
        current->addSeparator();
        rendererMenu = RendererMenu( p_intf );
        current->addMenu( rendererMenu );

673
        current->addSeparator();
674
        /* Surface modifiers */
675 676 677 678
        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" ) );
679

680
        current->addSeparator();
681
        /* Size modifiers */
682 683 684
        addActionWithSubmenu( current, "zoom", qtr( "&Zoom" ) );
        addActionWithSubmenu( current, "aspect-ratio", qtr( "&Aspect Ratio" ) );
        addActionWithSubmenu( current, "crop", qtr( "&Crop" ) );
685 686 687

        current->addSeparator();
        /* Rendering modifiers */
688 689
        addActionWithSubmenu( current, "deinterlace", qtr( "&Deinterlace" ) );
        addActionWithSubmenu( current, "deinterlace-mode", qtr( "&Deinterlace mode" ) );
690 691 692 693

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

696 697
    p_input = THEMIM->getInput();

698
    VideoAutoMenuBuilder( THEPL, p_input, objects, varnames );
699

700
    return Populate( p_intf, current, varnames, objects );
701 702
}

703 704 705 706
/**
 * Navigation Menu
 * For DVD, MP4, MOV and other chapter based format
 **/
707
QMenu *VLCMenuBar::NavigMenu( intf_thread_t *p_intf, QMenu *menu )
708
{
709
    QAction *action;
710
    QMenu *submenu;
711

712
    addActionWithSubmenu( menu, "title", qtr( "T&itle" ) );
713
    submenu = addActionWithSubmenu( menu, "chapter", qtr( "&Chapter" ) );
714
    submenu->setTearOffEnabled( true );
715
    addActionWithSubmenu( menu, "program", qtr( "&Program" ) );
716

Christoph Miebach's avatar
Christoph Miebach committed
717
    submenu = new QMenu( qtr( I_MENU_BOOKMARK ), menu );
718
    submenu->setTearOffEnabled( true );
719 720 721 722 723 724
    addDPStaticEntry( submenu, qtr( "&Manage" ), "",
                      SLOT( bookmarksDialog() ), "Ctrl+B" );
    submenu->addSeparator();
    action = menu->addMenu( submenu );
    action->setData( "bookmark" );

725
    menu->addSeparator();
726

727
    PopupMenuControlEntries( menu, p_intf );
728

729
    EnableStaticEntries( menu, ( THEMIM->getInput() != NULL ) );
730
    return RebuildNavigMenu( p_intf, menu, true );
731 732
}

733
QMenu *VLCMenuBar::RebuildNavigMenu( intf_thread_t *p_intf, QMenu *menu, bool b_keep )
734
{
735
    /* */
736
    input_thread_t *p_object;
737 738
    QVector<vlc_object_t *> objects;
    QVector<const char *> varnames;
739

740
    /* Get the input and hold it */
741
    p_object = THEMIM->getInput();
742

743
    InputAutoMenuBuilder( p_object, objects, varnames );
744 745

    /* Title and so on */
746 747 748 749
    PUSH_VAR( "prev-title" );
    PUSH_VAR( "next-title" );
    PUSH_VAR( "prev-chapter" );
    PUSH_VAR( "next-chapter" );
750

751 752 753 754
    /* */
    EnableStaticEntries( menu, (p_object != NULL ) );
    Populate( p_intf, menu, varnames, objects );

755 756 757 758
    /* Remove playback actions to recreate them */
    if( !b_keep )
    {
        QList< QAction* > actions = menu->actions();
759 760
        for( int i = 0; i < actions.count(); i++ )
            if( actions[i]->data().toInt() & ACTION_DELETE_ON_REBUILD )
761 762 763
                delete actions[i];
    }

764
    PopupMenuPlaylistEntries( menu, p_intf, p_object );
765

766
    return menu;
767
}
768

769 770 771
/**
 * Help/About Menu
**/
772
QMenu *VLCMenuBar::HelpMenu( QWidget *parent )
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
773
{
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
774
    QMenu *menu = new QMenu( parent );
775
    addDPStaticEntry( menu, qtr( "&Help" ) ,
776
        ":/menu/help", SLOT( helpDialog() ), "F1" );
777
#ifdef UPDATE_CHECK
778 779
    addDPStaticEntry( menu, qtr( "Check for &Updates..." ) , "",
                      SLOT( updateDialog() ) );
780
#endif
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
781
    menu->addSeparator();
782
    addDPStaticEntry( menu, qtr( I_MENU_ABOUT ), ":/menu/info",
783
            SLOT( aboutDialog() ), "Shift+F1", QAction::AboutRole );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
784 785 786
    return menu;
}

787
/*****************************************************************************
788
 * Popup menus - Right Click menus                                           *
789
 *****************************************************************************/
790
#define POPUP_BOILERPLATE \
791
    QMenu* menu;  \
792 793
    QVector<vlc_object_t *> objects; \
    QVector<const char *> varnames; \
794 795 796
    input_thread_t *p_input = THEMIM->getInput();

#define CREATE_POPUP \
Erwan Tulou's avatar
Erwan Tulou committed
797
    menu = new QMenu(); \
798
    Populate( p_intf, menu, varnames, objects ); \
799 800
    if( show ) \
        menu->popup( QCursor::pos() ); \
801

802
void VLCMenuBar::PopupMenuPlaylistEntries( QMenu *menu,
803 804 805
                                        intf_thread_t *p_intf,
                                        input_thread_t *p_input )
{
806 807 808
    QAction *action;

    /* Play or Pause action and icon */
809 810
    if( !p_input || var_GetInteger( p_input, "state" ) != PLAYING_S )
    {
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
811
        action = menu->addAction( qtr( "&Play" ),
812
                ActionsManager::getInstance( p_intf ), SLOT( play