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

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

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

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

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

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

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

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

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

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

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

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

static QActionGroup *currentGroup;

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

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

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

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

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

169 170
/**
 * \return Number of static entries
171
 **/
172
inline int DeleteNonStaticEntries( QMenu *menu )
173
{
174 175
    if( !menu ) return VLC_EGENERIC;

176
    int i_ret = 0;
177

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

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

203
/*****************************************************************************
204
 * Definitions of variables for the dynamic menus
205
 *****************************************************************************/
206 207
#define PUSH_VAR( var ) varnames.append( var ); \
    objects.append( VLC_OBJECT(p_object) )
208

209 210
#define PUSH_INPUTVAR( var ) varnames.append( var ); \
    objects.append( VLC_OBJECT(p_input) );
211

212
static int InputAutoMenuBuilder( input_thread_t *p_object,
213 214
        QVector<vlc_object_t *> &objects,
        QVector<const char *> &varnames )
215
{
216
    PUSH_VAR( "bookmark" );
217
    PUSH_VAR( "title" );
218
    PUSH_VAR( "chapter" );
219
    PUSH_VAR( "navigation" );
220
    PUSH_VAR( "program" );
221 222 223
    return VLC_SUCCESS;
}

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

243 244 245
    return VLC_SUCCESS;
}

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

258 259
/*****************************************************************************
 * All normal menus
260
 * Simple Code
261 262
 *****************************************************************************/

263
// Static menu
264 265 266 267
static inline void addMenuToMainbar( QMenu *func, QString title, QMenuBar *bar ) {
    func->setTitle( title );
    bar->addMenu( func);
}
268

269
// Dynamic menu
270
#define BAR_DADD( func, title, id ) { \
271 272 273 274 275
    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 ); }

276
// Add a simple action
277 278 279 280 281
static inline void addAction( QMenu *_menu, QVariant val, QString title ) {
    QAction *_action = new QAction( title, _menu );
    _action->setData( val );
    _menu->addAction( _action );
}
282

283
// Add an action with a submenu
284
static inline QMenu *addActionWithSubmenu( QMenu *_menu, QVariant val, QString title ) {
285
    QAction *_action = new QAction( title, _menu );
286
    QMenu *_submenu = new QMenu( _menu );
287
    _action->setData( val );
288
    _action->setMenu( _submenu );
289
    _menu->addAction( _action );
290
    return _submenu;
291
}
292

293
// Add an action that is a checkbox
294 295 296 297 298 299
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 );
}
300

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

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

314
    /* Dynamic menus, rebuilt before being showed */
315
    BAR_DADD( NavigMenu( p_intf, bar ), qtr( "P&layback" ), 3 );
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
316 317
    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
318

319
    addMenuToMainbar( ToolsMenu( bar ), qtr( "&Tools" ), bar );
320 321

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

324
    addMenuToMainbar( HelpMenu( bar ), qtr( "&Help" ), bar );
325

326
}
327 328

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

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

348
    menu->addSeparator();
349 350 351 352 353

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

354
    addDPStaticEntry( menu, qtr( "Open &Location from clipboard" ),
355
                      NULL, SLOT( openUrlDialog() ), "Ctrl+V" );
356

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
357
    if( var_InheritBool( p_intf, "qt-recentplay" ) )
358
    {
359
        recentsMenu = new QMenu( qtr( "Open &Recent Media" ), menu );
360 361 362
        updateRecents( p_intf );
        menu->addMenu( recentsMenu );
    }
363
    menu->addSeparator();
364

365 366 367 368
    addDPStaticEntry( menu, qtr( I_PL_SAVE ), "", SLOT( saveAPlaylist() ),
        "Ctrl+Y" );
    menu->addSeparator();

369
#ifdef ENABLE_SOUT
370
    addDPStaticEntry( menu, qtr( "Conve&rt / Save..." ), "",
371
        SLOT( openAndTranscodingDialogs() ), "Ctrl+R" );
372
    addDPStaticEntry( menu, qtr( "&Stream..." ),
373
        ":/menu/stream", SLOT( openAndStreamingDialogs() ), "Ctrl+S" );
374
    menu->addSeparator();
375
#endif
376

377 378 379 380 381
    action = addMIMStaticEntry( p_intf, menu, qtr( "Quit at the end of playlist" ), "",
                               SLOT( activatePlayQuit( bool ) ) );
    action->setCheckable( true );
    action->setChecked( THEMIM->getPlayExitState() );

382 383 384 385 386 387
    if( mi->getSysTray() )
    {
        action = menu->addAction( qtr( "Close to systray"), mi,
                                 SLOT( toggleUpdateSystrayMenu() ) );
    }

388
    addDPStaticEntry( menu, qtr( "&Quit" ) ,
389
        ":/menu/quit", SLOT( quit() ), "Ctrl+Q" );
390 391 392
    return menu;
}

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

401
    addDPStaticEntry( menu, qtr( "&Track Synchronization"), ":/menu/settings",
402 403
            SLOT( synchroDialog() ), "" );

404
    addDPStaticEntry( menu, qtr( I_MENU_INFO ) , ":/menu/info",
405
        SLOT( mediaInfoDialog() ), "Ctrl+I" );
406
    addDPStaticEntry( menu, qtr( I_MENU_CODECINFO ) ,
407
        ":/menu/info", SLOT( mediaCodecDialog() ), "Ctrl+J" );
408

409
#ifdef ENABLE_VLM
410
    addDPStaticEntry( menu, qtr( I_MENU_VLM ), "", SLOT( vlmDialog() ),
411 412
        "Ctrl+W" );
#endif
413

414 415 416
    addDPStaticEntry( menu, qtr( "Program Guide" ), "", SLOT( epgDialog() ),
        "" );

417
    addDPStaticEntry( menu, qtr( I_MENU_MSG ),
418
        ":/menu/messages", SLOT( messagesDialog() ), "Ctrl+M" );
419

420 421
    addDPStaticEntry( menu, qtr( "Plu&gins and extensions" ),
        "", SLOT( pluginDialog() ) );
Clément Stenac's avatar
Clément Stenac committed
422 423
    menu->addSeparator();

424 425 426
    addDPStaticEntry( menu, qtr( "Customi&ze Interface..." ),
        ":/menu/preferences", SLOT( toolbarDialog() ) );

427
    addDPStaticEntry( menu, qtr( "&Preferences" ),
428
        ":/menu/preferences", SLOT( prefsDialog() ), "Ctrl+P", QAction::PreferencesRole );
429

Clément Stenac's avatar
Clément Stenac committed
430 431 432
    return menu;
}

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

443 444 445
    MainInterface *mi = _mi ? _mi : p_intf->p_sys->p_mi;
    assert( mi );

446 447
    if( !current )
    {
448
        menu = new QMenu( qtr( "&View" ), mi );
449
    }
450 451 452
    else
    {
        menu = current;
453 454 455 456 457 458 459 460
        //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 );
461
            if( m && m->parent() == menu ) delete m;
462
        }
463
    }
464

465 466 467 468
    menu->addAction(
#ifndef __APPLE__
            QIcon( ":/menu/playlist_menu" ),
#endif
469 470 471
            qtr( "Play&list" ), mi,
            SLOT( togglePlaylist() ), qtr( "Ctrl+L" ) );

472 473
    menu->addSeparator();

474
    /* Minimal View */
475
    action = menu->addAction( qtr( "Mi&nimal Interface" ) );
476
    action->setShortcut( qtr( "Ctrl+H" ) );
477
    action->setCheckable( true );
478
    action->setChecked( (mi->getControlsVisibilityStatus() & CONTROLS_HIDDEN ) );
479

480 481
    CONNECT( action, triggered( bool ), mi, toggleMinimalView( bool ) );
    CONNECT( mi, minimalViewToggled( bool ), action, setChecked( bool ) );
482 483 484

    /* FullScreen View */
    action = menu->addAction( qtr( "&Fullscreen Interface" ), mi,
485
            SLOT( toggleInterfaceFullScreen() ), QString( "F11" ) );
486
    action->setCheckable( true );
487
    action->setChecked( mi->isInterfaceFullScreen() );
488 489
    CONNECT( mi, fullscreenInterfaceToggled( bool ),
             action, setChecked( bool ) );
490 491 492

    /* Advanced Controls */
    action = menu->addAction( qtr( "&Advanced Controls" ), mi,
493
            SLOT( toggleAdvancedButtons() ) );
494 495 496 497
    action->setCheckable( true );
    if( mi->getControlsVisibilityStatus() & CONTROLS_ADVANCED )
        action->setChecked( true );

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
498 499 500 501 502 503
    /* Docked Playlist */
    action = menu->addAction( qtr( "Docked Playlist" ) );
    action->setCheckable( true );
    action->setChecked( mi->isPlDocked() );
    CONNECT( action, triggered( bool ), mi, dockPlaylist( bool ) );

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

515
    menu->addSeparator();
516 517 518 519

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

520
    /* Extensions */
521
    ExtensionsMenu( p_intf, menu );
522

523 524 525
    return menu;
}

526 527 528
/**
 * Interface Sub-Menu, to list extras interface and skins
 **/
529
QMenu *VLCMenuBar::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
530
{
531 532 533 534
    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
535

536
    return Populate( p_intf, current, varnames, objects );
537 538
}

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

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

553
    if( !extMgr->isLoaded() && !extMgr->cannotLoad() )
554
    {
555
        extMgr->loadExtensions();
556
    }
557

558
    /* Let the ExtensionsManager build itself the menu */
559
    extMenu->addSeparator();
560
    extMgr->menu( extMenu );
561 562
}

563 564
static inline void VolumeEntries( intf_thread_t *p_intf, QMenu *current )
{
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
565
    current->addSeparator();
566

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

578 579
/**
 * Main Audio Menu
580
 **/
581
QMenu *VLCMenuBar::AudioMenu( intf_thread_t *p_intf, QMenu * current )
582
{
583 584
    QVector<vlc_object_t *> objects;
    QVector<const char *> varnames;
585
    audio_output_t *p_aout;
586 587 588
    input_thread_t *p_input;

    if( current->isEmpty() )
589
    {
590 591 592
        addActionWithSubmenu( current, "audio-es", qtr( "Audio &Track" ) );
        addActionWithSubmenu( current, "audio-channels", qtr( "Audio &Channels" ) );
        addActionWithSubmenu( current, "audio-device", qtr( "Audio &Device" ) );
593
        current->addSeparator();
594

595
        addActionWithSubmenu( current, "visual", qtr( "&Visualizations" ) );
596
        VolumeEntries( p_intf, current );
597 598
    }

599
    p_input = THEMIM->getInput();
600
    p_aout = THEMIM->getAout();
601
    EnableStaticEntries( current, ( p_aout != NULL ) );
602
    AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
603
    if( p_aout )
604
    {
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
605
        vlc_object_release( p_aout );
606
    }
607

608 609 610
    return Populate( p_intf, current, varnames, objects );
}

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

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

635
    if( current->isEmpty() )
636
    {
637
        addActionWithSubmenu( current, "video-es", qtr( "Video &Track" ) );
638
        if( b_subtitle)
639
            SubtitleMenu( current );
640

641
        current->addSeparator();
642
        /* Surface modifiers */
643 644 645 646
        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" ) );
647

648
        current->addSeparator();
649
        /* Size modifiers */
650 651 652
        addActionWithSubmenu( current, "zoom", qtr( "&Zoom" ) );
        addActionWithSubmenu( current, "aspect-ratio", qtr( "&Aspect Ratio" ) );
        addActionWithSubmenu( current, "crop", qtr( "&Crop" ) );
653 654 655

        current->addSeparator();
        /* Rendering modifiers */
656 657 658
        addActionWithSubmenu( current, "deinterlace", qtr( "&Deinterlace" ) );
        addActionWithSubmenu( current, "deinterlace-mode", qtr( "&Deinterlace mode" ) );
        addActionWithSubmenu( current, "postprocess", qtr( "&Post processing" ) );
659 660 661 662

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

665 666
    p_input = THEMIM->getInput();

667
    p_vout = THEMIM->getVout();
668
    VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
669

670 671
    if( p_vout )
        vlc_object_release( p_vout );
672

673
    return Populate( p_intf, current, varnames, objects );
674 675
}

676 677 678 679
/**
 * Navigation Menu
 * For DVD, MP4, MOV and other chapter based format
 **/
680
QMenu *VLCMenuBar::NavigMenu( intf_thread_t *p_intf, QMenu *menu )
681
{
682
    QAction *action;
683
    QMenu *submenu;
684

685 686
    addActionWithSubmenu( menu, "title", qtr( "T&itle" ) );
    addActionWithSubmenu( menu, "chapter", qtr( "&Chapter" ) );
687 688
    submenu = addActionWithSubmenu( menu, "navigation", qtr( "&Navigation" ) );
    submenu->setTearOffEnabled( true );
689
    addActionWithSubmenu( menu, "program", qtr( "&Program" ) );
690

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

700
    menu->addSeparator();
701

702
    PopupMenuControlEntries( menu, p_intf );
703

704
    EnableStaticEntries( menu, ( THEMIM->getInput() != NULL ) );
705
    return RebuildNavigMenu( p_intf, menu, true );
706 707
}

708
QMenu *VLCMenuBar::RebuildNavigMenu( intf_thread_t *p_intf, QMenu *menu, bool b_keep )
709
{
710
    /* */
711
    input_thread_t *p_object;
712 713
    QVector<vlc_object_t *> objects;
    QVector<const char *> varnames;
714

715
    /* Get the input and hold it */
716
    p_object = THEMIM->getInput();
717

718
    InputAutoMenuBuilder( p_object, objects, varnames );
719 720

    /* Title and so on */
721 722 723 724
    PUSH_VAR( "prev-title" );
    PUSH_VAR( "next-title" );
    PUSH_VAR( "prev-chapter" );
    PUSH_VAR( "next-chapter" );
725

726 727 728 729
    /* */
    EnableStaticEntries( menu, (p_object != NULL ) );
    Populate( p_intf, menu, varnames, objects );

730 731 732 733
    /* Remove playback actions to recreate them */
    if( !b_keep )
    {
        QList< QAction* > actions = menu->actions();
734 735
        for( int i = 0; i < actions.count(); i++ )
            if( actions[i]->data().toInt() & ACTION_DELETE_ON_REBUILD )