menus.cpp 44.3 KB
Newer Older
1 2 3
/*****************************************************************************
 * menus.cpp : Qt menus
 *****************************************************************************
4
 * Copyright © 2006-2009 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_intf_strings.h>
35
#include <vlc_services_discovery.h>
36
#include <vlc_aout.h>
37
#include <vlc_vout.h>
38

Clément Stenac's avatar
Clément Stenac committed
39
#include "menus.hpp"
40 41

#include "main_interface.hpp"    /* View modifications */
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
42 43 44
#include "dialogs_provider.hpp"  /* Dialogs display */
#include "input_manager.hpp"     /* Input Management */
#include "recents.hpp"           /* Recent Items */
45
#include "actions_manager.hpp"
Clément Stenac's avatar
Clément Stenac committed
46

47 48 49 50 51 52
#include <QMenu>
#include <QMenuBar>
#include <QAction>
#include <QActionGroup>
#include <QSignalMapper>
#include <QSystemTrayIcon>
Ludovic Fauvet's avatar
Ludovic Fauvet committed
53
#include <QList>
54

55 56 57 58 59 60 61 62 63 64 65 66 67 68
/*
  This file defines the main menus and the pop-up menu (right-click menu)
  and the systray menu (in that order in the file)

  There are 3 menus that have to be rebuilt everytime there are called:
  Audio, Video, Navigation
  3 functions are building those menus: AudioMenu, VideoMenu, NavigMenu
  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.
  */

69 70 71
#define STATIC_ENTRY "__static__"
#define ENTRY_ALWAYS_ENABLED "__ignore__"

72 73 74 75 76 77 78 79 80
enum
{
    ITEM_NORMAL,
    ITEM_CHECK,
    ITEM_RADIO
};

static QActionGroup *currentGroup;

Ludovic Fauvet's avatar
Ludovic Fauvet committed
81 82
QMenu *QVLCMenu::recentsMenu = NULL;

83 84 85 86 87
/****************************************************************************
 * Menu code helpers:
 ****************************************************************************
 * Add static entries to DP in menus
 ***************************************************************************/
88
void addDPStaticEntry( QMenu *menu,
89
                       const QString& text,
90
                       const char *icon,
91
                       const char *member,
92
                       const char *shortcut = NULL )
93
{
94
    QAction *action = NULL;
Rémi Duraffort's avatar
Rémi Duraffort committed
95
    if( !EMPTY_STR( icon ) )
96
    {
Rémi Duraffort's avatar
Rémi Duraffort committed
97
        if( !EMPTY_STR( shortcut ) )
98 99
            action = menu->addAction( QIcon( icon ), text, THEDP,
                                      member, qtr( shortcut ) );
100
        else
101
            action = menu->addAction( QIcon( icon ), text, THEDP, member );
102 103 104
    }
    else
    {
Rémi Duraffort's avatar
Rémi Duraffort committed
105
        if( !EMPTY_STR( shortcut ) )
106
            action = menu->addAction( text, THEDP, member, qtr( shortcut ) );
107
        else
108
            action = menu->addAction( text, THEDP, member );
109
    }
110
    action->setData( STATIC_ENTRY );
111
}
112

113 114 115
/***
 * Same for MIM
 ***/
116 117
QAction* addMIMStaticEntry( intf_thread_t *p_intf,
                            QMenu *menu,
118
                            const QString& text,
119 120 121
                            const char *icon,
                            const char *member,
                            bool bStatic = false )
122
{
123
    QAction *action;
124 125
    if( strlen( icon ) > 0 )
    {
126
        action = menu->addAction( text, THEMIM,  member );
127 128 129 130
        action->setIcon( QIcon( icon ) );
    }
    else
    {
Rémi Duraffort's avatar
Rémi Duraffort committed
131
        action = menu->addAction( text, THEMIM, member );
132
    }
133
    action->setData( bStatic ? STATIC_ENTRY : ENTRY_ALWAYS_ENABLED );
134
    return action;
135 136
}

137 138 139 140 141
/**
 * @brief Enable all static entries, disable the others
 * @param enable if false, disable all entries
 */
void EnableStaticEntries( QMenu *menu, bool enable = true )
142
{
143
    if( !menu ) return;
144

Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
145 146
    QList< QAction* > actions = menu->actions();
    for( int i = 0; i < actions.size(); ++i )
147
    {
148 149 150 151
        actions[i]->setEnabled( actions[i]->data().toString()
                                == ENTRY_ALWAYS_ENABLED ||
            /* Be careful here, because data("string").toBool is true */
            ( enable && (actions[i]->data().toString() == STATIC_ENTRY ) ) );
152 153 154
    }
}

155 156 157 158 159
/**
 * \return Number of static entries
 */
int DeleteNonStaticEntries( QMenu *menu )
{
160 161
    if( !menu ) return VLC_EGENERIC;

162
    int i_ret = 0;
163

Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
164 165
    QList< QAction* > actions = menu->actions();
    for( int i = 0; i < actions.size(); ++i )
166
    {
167
        if( actions[i]->data().toString() != STATIC_ENTRY )
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
168
            delete actions[i];
169 170 171
        else
            i_ret++;
    }
172
    return i_ret;
173 174
}

175 176 177 178
/**
 * \return QAction associated to psz_var variable
 **/
static QAction * FindActionWithVar( QMenu *menu, const char *psz_var )
179
{
180 181
    QList< QAction* > actions = menu->actions();
    for( int i = 0; i < actions.size(); ++i )
182
    {
183 184
        if( actions[i]->data().toString() == psz_var )
            return actions[i];
185
    }
186
    return NULL;
187 188
}

189
/*****************************************************************************
190
 * Definitions of variables for the dynamic menus
191
 *****************************************************************************/
192
#define PUSH_VAR( var ) varnames.push_back( var ); \
193
    objects.push_back( VLC_OBJECT(p_object) )
194 195

#define PUSH_INPUTVAR( var ) varnames.push_back( var ); \
196
    objects.push_back( VLC_OBJECT(p_input) );
197 198

#define PUSH_SEPARATOR if( objects.size() != i_last_separator ) { \
199
    objects.push_back( 0 ); varnames.push_back( "" ); \
200
    i_last_separator = objects.size(); }
201

202
static int InputAutoMenuBuilder( input_thread_t *p_object,
203
        vector<vlc_object_t *> &objects,
204
        vector<const char *> &varnames )
205
{
206
    PUSH_VAR( "bookmark" );
207
    PUSH_VAR( "title" );
208
    PUSH_VAR( "chapter" );
209
    PUSH_VAR( "navigation" );
210
    PUSH_VAR( "program" );
211 212 213
    return VLC_SUCCESS;
}

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
214
static int VideoAutoMenuBuilder( vout_thread_t *p_object,
215
        input_thread_t *p_input,
216
        vector<vlc_object_t *> &objects,
217
        vector<const char *> &varnames )
218
{
219 220
    PUSH_INPUTVAR( "video-es" );
    PUSH_INPUTVAR( "spu-es" );
221 222
    PUSH_VAR( "fullscreen" );
    PUSH_VAR( "video-on-top" );
223
#ifdef WIN32
224
    PUSH_VAR( "directx-wallpaper" );
225
    PUSH_VAR( "direct3d-desktop" );
226
#endif
227
    PUSH_VAR( "video-snapshot" );
228
    PUSH_VAR( "zoom" );
229
    PUSH_VAR( "autoscale" );
230 231 232
    PUSH_VAR( "aspect-ratio" );
    PUSH_VAR( "crop" );
    PUSH_VAR( "deinterlace" );
233
    PUSH_VAR( "postprocess" );
234

235 236 237
    return VLC_SUCCESS;
}

238
static int AudioAutoMenuBuilder( aout_instance_t *p_object,
239
        input_thread_t *p_input,
240
        vector<vlc_object_t *> &objects,
241
        vector<const char *> &varnames )
242
{
243
    PUSH_INPUTVAR( "audio-es" );
244
    PUSH_VAR( "audio-channels" );
245 246
    PUSH_VAR( "audio-device" );
    PUSH_VAR( "visual" );
247 248 249
    return VLC_SUCCESS;
}

250 251
/*****************************************************************************
 * All normal menus
252
 * Simple Code
253 254 255
 *****************************************************************************/

#define BAR_ADD( func, title ) { \
256
    QMenu *_menu = func; _menu->setTitle( title ); bar->addMenu( _menu ); }
257 258

#define BAR_DADD( func, title, id ) { \
259 260 261 262 263 264 265 266
    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 ); }

#define ACT_ADD( _menu, val, title ) { \
    QAction *_action = new QAction( title, _menu ); _action->setData( val ); \
    _menu->addAction( _action ); }
267

268 269
#define ACT_ADDMENU( _menu, val, title ) { \
    QAction *_action = new QAction( title, _menu ); _action->setData( val ); \
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
270
    _action->setMenu( new QMenu( _menu ) ); _menu->addAction( _action ); }
271 272 273 274 275

#define ACT_ADDCHECK( _menu, val, title ) { \
    QAction *_action = new QAction( title, _menu ); _action->setData( val ); \
    _action->setCheckable( true ); _menu->addAction( _action ); }

276 277 278
/**
 * Main Menu Bar Creation
 **/
279
void QVLCMenu::createMenuBar( MainInterface *mi,
280
                              intf_thread_t *p_intf )
Clément Stenac's avatar
Qt4:  
Clément Stenac committed
281
{
282 283 284
    /* QMainWindows->menuBar()
       gives the QProcess::destroyed timeout issue on Cleanlooks style with
       setDesktopAware set to false */
285
    QMenuBar *bar = mi->menuBar();
286

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
287
    BAR_ADD( FileMenu( p_intf, bar ), qtr( "&Media" ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
288

289
    /* Dynamic menus, rebuilt before being showed */
290
    BAR_DADD( NavigMenu( p_intf, bar ), qtr( "P&layback" ), 3 );
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
291 292
    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
293

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
294
    BAR_ADD( ToolsMenu( bar ), qtr( "&Tools" ) );
295
    BAR_ADD( ViewMenu( p_intf, mi ), qtr( "V&iew" ) );
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
296
    BAR_ADD( HelpMenu( bar ), qtr( "&Help" ) );
297
}
298 299
#undef BAR_ADD
#undef BAR_DADD
300 301

/**
302
 * Media ( File ) Menu
303 304
 * Opening, streaming and quit
 **/
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
305
QMenu *QVLCMenu::FileMenu( intf_thread_t *p_intf, QWidget *parent )
306
{
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
307
    QMenu *menu = new QMenu( parent );
308

309
    addDPStaticEntry( menu, qtr( "&Open File..." ),
310
        ":/type/file-asym", SLOT( simpleOpenDialog() ), "Ctrl+O" );
311
    addDPStaticEntry( menu, qtr( "Advanced Open File..." ),
312
        ":/type/file-asym", SLOT( openFileDialog() ), "Ctrl+Shift+O" );
313
    addDPStaticEntry( menu, qtr( I_OPEN_FOLDER ),
314
        ":/type/folder-grey", SLOT( PLOpenDir() ), "Ctrl+F" );
315
    addDPStaticEntry( menu, qtr( "Open &Disc..." ),
316
        ":/type/disc", SLOT( openDiscDialog() ), "Ctrl+D" );
317
    addDPStaticEntry( menu, qtr( "Open &Network Stream..." ),
318
        ":/type/network", SLOT( openNetDialog() ), "Ctrl+N" );
319
    addDPStaticEntry( menu, qtr( "Open &Capture Device..." ),
320
        ":/type/capture-card", SLOT( openCaptureDialog() ),
321
        "Ctrl+C" );
322

323
    menu->addSeparator();
324
    addDPStaticEntry( menu, qtr( "Open &Location from clipboard" ),
325
                      NULL, SLOT( openUrlDialog() ), "Ctrl+V" );
326

327 328 329 330 331 332
    if( config_GetInt( p_intf, "qt-recentplay" ) )
    {
        recentsMenu = new QMenu( qtr( "&Recent Media" ), menu );
        updateRecents( p_intf );
        menu->addMenu( recentsMenu );
    }
333 334
    menu->addMenu( SDMenu( p_intf, menu ) );
    menu->addSeparator();
335

336 337 338 339
    addDPStaticEntry( menu, qtr( I_PL_SAVE ), "", SLOT( saveAPlaylist() ),
        "Ctrl+Y" );
    menu->addSeparator();

340
#ifdef ENABLE_SOUT
341
    addDPStaticEntry( menu, qtr( "Conve&rt / Save..." ), "",
342
        SLOT( openAndTranscodingDialogs() ), "Ctrl+R" );
343
    addDPStaticEntry( menu, qtr( "&Streaming..." ),
344
        ":/menu/stream", SLOT( openAndStreamingDialogs() ),
345
        "Ctrl+S" );
346
    menu->addSeparator();
347
#endif
348

349
    addDPStaticEntry( menu, qtr( "&Quit" ) ,
350
        ":/menu/quit", SLOT( quit() ), "Ctrl+Q" );
351 352 353
    return menu;
}

354
/**
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
355
 * Tools, like Media Information, Preferences or Messages
356
 **/
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
357
QMenu *QVLCMenu::ToolsMenu( QMenu *menu )
Clément Stenac's avatar
Clément Stenac committed
358
{
359
    addDPStaticEntry( menu, qtr( "&Effects and Filters"), ":/menu/settings",
360
            SLOT( extendedDialog() ), "Ctrl+E" );
361

362
    addDPStaticEntry( menu, qtr( "&Track Synchronization"), ":/menu/settings",
363 364
            SLOT( synchroDialog() ), "" );

365
    addDPStaticEntry( menu, qtr( I_MENU_INFO ) , ":/menu/info",
366
        SLOT( mediaInfoDialog() ), "Ctrl+I" );
367
    addDPStaticEntry( menu, qtr( I_MENU_CODECINFO ) ,
368
        ":/menu/info", SLOT( mediaCodecDialog() ), "Ctrl+J" );
369

370
    addDPStaticEntry( menu, qtr( I_MENU_BOOKMARK ),"",
371 372
                      SLOT( bookmarksDialog() ), "Ctrl+B" );
#ifdef ENABLE_VLM
373
    addDPStaticEntry( menu, qtr( I_MENU_VLM ), "", SLOT( vlmDialog() ),
374 375
        "Ctrl+W" );
#endif
376 377

    addDPStaticEntry( menu, qtr( I_MENU_MSG ),
378
        ":/menu/messages", SLOT( messagesDialog() ),
379 380
        "Ctrl+M" );

381 382
    addDPStaticEntry( menu, qtr( "Plu&gins and extensions" ),
        "", SLOT( pluginDialog() ) );
Clément Stenac's avatar
Clément Stenac committed
383 384
    menu->addSeparator();

385
    addDPStaticEntry( menu, qtr( "&Preferences" ),
386
        ":/menu/preferences", SLOT( prefsDialog() ), "Ctrl+P" );
387

Clément Stenac's avatar
Clément Stenac committed
388 389 390
    return menu;
}

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
391 392 393 394 395
QMenu *QVLCMenu::ToolsMenu( QWidget *parent )
{
    return ToolsMenu( new QMenu( parent ) );
}

396
/**
397
 * View Menu
398
 * Interface Modification
399
 **/
400
QMenu *QVLCMenu::ViewMenu( intf_thread_t *p_intf,
401 402
                            MainInterface *mi,
                            bool with_intf )
403
{
404 405 406 407
    assert( mi );

    QMenu *menu = new QMenu( qtr( "V&iew" ), mi );

408
    QAction *act = menu->addAction( QIcon( ":/menu/playlist_menu" ),
409 410 411
            qtr( "Play&list" ), mi,
            SLOT( togglePlaylist() ), qtr( "Ctrl+L" ) );

412 413 414 415
    /*menu->addSeparator();
    menu->addAction( qtr( "Undock from Interface" ), mi,
                     SLOT( undockPlaylist() ), qtr( "Ctrl+U" ) );*/

416 417
    menu->addSeparator();

418 419
    if( with_intf )
    {
420
        QMenu *intfmenu = InterfacesMenu( p_intf, menu );
421 422 423
        MenuFunc *f = new MenuFunc( intfmenu, 4 );
        CONNECT( intfmenu, aboutToShow(), THEDP->menusUpdateMapper, map() );
        THEDP->menusUpdateMapper->setMapping( intfmenu, f );
424 425
        menu->addSeparator();
    }
426

427
    /* Minimal View */
428 429
    QAction *action = menu->addAction( qtr( "Mi&nimal View" ) );
    action->setShortcut( qtr( "Ctrl+H" ) );
430
    action->setCheckable( true );
431
    action->setChecked( !with_intf &&
432
            (mi->getControlsVisibilityStatus() & CONTROLS_HIDDEN ) );
433

434 435
    CONNECT( action, triggered( bool ), mi, toggleMinimalView( bool ) );
    CONNECT( mi, minimalViewToggled( bool ), action, setChecked( bool ) );
436 437 438 439 440

    /* FullScreen View */
    action = menu->addAction( qtr( "&Fullscreen Interface" ), mi,
            SLOT( toggleFullScreen() ), QString( "F11" ) );
    action->setCheckable( true );
441 442 443
    action->setChecked( mi->isFullScreen() );
    CONNECT( mi, fullscreenInterfaceToggled( bool ),
             action, setChecked( bool ) );
444 445 446 447 448 449 450 451

    /* Advanced Controls */
    action = menu->addAction( qtr( "&Advanced Controls" ), mi,
            SLOT( toggleAdvanced() ) );
    action->setCheckable( true );
    if( mi->getControlsVisibilityStatus() & CONTROLS_ADVANCED )
        action->setChecked( true );

452 453 454 455 456 457 458 459
    if( with_intf )
    // I don't want to manage consistency between menus, so no popup-menu
    {
        action = menu->addAction( qtr( "Quit after Playback" ) );
        action->setCheckable( true );
        CONNECT( action, triggered( bool ), THEMIM, activatePlayQuit( bool ) );
    }

460
#if 0 /* For Visualisations. Not yet working */
461 462 463 464
    adv = menu->addAction( qtr( "Visualizations selector" ),
            mi, SLOT( visual() ) );
    adv->setCheckable( true );
    if( visual_selector_enabled ) adv->setChecked( true );
465
#endif
466

467
    menu->addSeparator();
468
    addDPStaticEntry( menu, qtr( "Customi&ze Interface..." ),
469
        ":/menu/preferences", SLOT( toolbarDialog() ) );
470
    menu->addSeparator();
471

472 473 474
    return menu;
}

475 476 477
/**
 * Interface Sub-Menu, to list extras interface and skins
 **/
478 479
QMenu *QVLCMenu::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
{
480
    vector<vlc_object_t *> objects;
481 482
    vector<const char *> varnames;
    varnames.push_back( "intf-add" );
483
    objects.push_back( VLC_OBJECT(p_intf) );
Clément Stenac's avatar
Qt4:  
Clément Stenac committed
484

485
    return Populate( p_intf, current, varnames, objects );
486 487
}

488 489
/**
 * Main Audio Menu
490
 **/
491 492
QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QMenu * current )
{
493
    vector<vlc_object_t *> objects;
494
    vector<const char *> varnames;
495
    aout_instance_t *p_aout;
496 497 498
    input_thread_t *p_input;

    if( current->isEmpty() )
499
    {
500 501 502
        ACT_ADDMENU( current, "audio-es", qtr( "Audio &Track" ) );
        ACT_ADDMENU( current, "audio-channels", qtr( "Audio &Channels" ) );
        ACT_ADDMENU( current, "audio-device", qtr( "Audio &Device" ) );
503
        current->addSeparator();
504

505
        ACT_ADDMENU( current, "visual", qtr( "&Visualizations" ) );
506 507
        current->addSeparator();

508
        QAction *action = current->addAction( qtr( "Increase Volume" ),
509
                ActionsManager::getInstance( p_intf ), SLOT( AudioUp() ) );
510
        action->setData( STATIC_ENTRY );
511 512
        action = current->addAction( qtr( "Decrease Volume" ),
                ActionsManager::getInstance( p_intf ), SLOT( AudioDown() ) );
513
        action->setData( STATIC_ENTRY );
514 515
        action = current->addAction( qtr( "Mute" ),
                ActionsManager::getInstance( p_intf ), SLOT( toggleMuteAudio() ) );
516
        action->setData( STATIC_ENTRY );
517 518
    }

519
    p_input = THEMIM->getInput();
520
    p_aout = THEMIM->getAout();
521
    EnableStaticEntries( current, ( p_aout != NULL ) );
522
    AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
523
    if( p_aout )
524
    {
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
525
        vlc_object_release( p_aout );
526
    }
527

528 529 530
    return Populate( p_intf, current, varnames, objects );
}

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
531 532 533 534 535
QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QWidget *parent )
{
    return AudioMenu( p_intf, new QMenu( parent ) );
}

536 537 538 539
/**
 * Main Video Menu
 * Subtitles are part of Video.
 **/
540
QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current )
541
{
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
542
    vout_thread_t *p_vout;
543
    input_thread_t *p_input;
544
    vector<vlc_object_t *> objects;
545 546
    vector<const char *> varnames;

547
    if( current->isEmpty() )
548
    {
549
        ACT_ADDMENU( current, "video-es", qtr( "Video &Track" ) );
550 551 552 553 554

        QAction *action;
        QMenu *submenu = new QMenu( qtr( "&Subtitles Track" ), current );
        action = current->addMenu( submenu );
        action->setData( "spu-es" );
555
        addDPStaticEntry( submenu, qtr( "Open File..." ), "",
556
                          SLOT( loadSubtitlesFile() ) );
557
        submenu->addSeparator();
558
        current->addSeparator();
559

560 561
        ACT_ADDCHECK( current, "fullscreen", qtr( "&Fullscreen" ) );
        ACT_ADDCHECK( current, "video-on-top", qtr( "Always &On Top" ) );
562
#ifdef WIN32
563
        ACT_ADDCHECK( current, "directx-wallpaper", qtr( "DirectX Wallpaper" ) );
564
        ACT_ADDCHECK( current, "direct3d-desktop", qtr( "Direct3D Desktop mode" ) );
565
#endif
566
        ACT_ADD( current, "video-snapshot", qtr( "Sna&pshot" ) );
567

568 569
        current->addSeparator();

570 571 572 573 574
        ACT_ADDMENU( current, "zoom", qtr( "&Zoom" ) );
        ACT_ADDCHECK( current, "autoscale", qtr( "Sca&le" ) );
        ACT_ADDMENU( current, "aspect-ratio", qtr( "&Aspect Ratio" ) );
        ACT_ADDMENU( current, "crop", qtr( "&Crop" ) );
        ACT_ADDMENU( current, "deinterlace", qtr( "&Deinterlace" ) );
575
        ACT_ADDMENU( current, "postprocess", qtr( "&Post processing" ) );
576
    }
577

578 579
    p_input = THEMIM->getInput();

580
    p_vout = THEMIM->getVout();
581
    VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
582

583 584
    if( p_vout )
        vlc_object_release( p_vout );
585

586
    return Populate( p_intf, current, varnames, objects );
587 588
}

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
589 590 591 592 593
QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QWidget *parent )
{
    return VideoMenu( p_intf, new QMenu( parent ) );
}

594 595 596 597
/**
 * Navigation Menu
 * For DVD, MP4, MOV and other chapter based format
 **/
598
QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *menu )
599
{
600
    QAction *action;
601

602 603 604 605 606 607
    QMenu *submenu = new QMenu( qtr( "&Bookmarks" ), menu );
    addDPStaticEntry( submenu, qtr( "Manage &bookmarks" ), "",
                      SLOT( bookmarksDialog() ) );
    submenu->addSeparator();
    action = menu->addMenu( submenu );
    action->setData( "bookmark" );
608

609 610 611 612
    ACT_ADDMENU( menu, "title", qtr( "T&itle" ) );
    ACT_ADDMENU( menu, "chapter", qtr( "&Chapter" ) );
    ACT_ADDMENU( menu, "navigation", qtr( "&Navigation" ) );
    ACT_ADDMENU( menu, "program", qtr( "&Program" ) );
613

614 615
    menu->addSeparator();
    PopupMenuPlaylistControlEntries( menu, p_intf );
616
    PopupMenuControlEntries( menu, p_intf );
617

618 619
    EnableStaticEntries( menu, ( THEMIM->getInput() != NULL ) );
    return RebuildNavigMenu( p_intf, menu );
620 621 622 623
}

QMenu *QVLCMenu::RebuildNavigMenu( intf_thread_t *p_intf, QMenu *menu )
{
624
    /* */
625 626 627 628
    input_thread_t *p_object;
    vector<vlc_object_t *> objects;
    vector<const char *> varnames;

629
    /* Get the input and hold it */
630
    p_object = THEMIM->getInput();
631

632
    InputAutoMenuBuilder( p_object, objects, varnames );
633

634 635
    menu->addSeparator();

636
    /* Title and so on */
637 638 639 640
    PUSH_VAR( "prev-title" );
    PUSH_VAR( "next-title" );
    PUSH_VAR( "prev-chapter" );
    PUSH_VAR( "next-chapter" );
641

642
    EnableStaticEntries( menu, (p_object != NULL ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
643
    return Populate( p_intf, menu, varnames, objects );
644
}
645

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
646 647 648 649 650
QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QWidget *parent )
{
    return NavigMenu( p_intf, new QMenu( parent ) );
}

651
/**
652
 * Service Discovery SubMenu
653
 **/
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
654
QMenu *QVLCMenu::SDMenu( intf_thread_t *p_intf, QWidget *parent )
Clément Stenac's avatar
Clément Stenac committed
655
{
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
656
    QMenu *menu = new QMenu( parent );
657
    menu->setTitle( qtr( I_PL_SD ) );
658

659
    char **ppsz_longnames;
660
    char **ppsz_names = vlc_sd_GetNames( &ppsz_longnames );
661 662 663
    if( !ppsz_names )
        return menu;

664 665
    char **ppsz_name = ppsz_names, **ppsz_longname = ppsz_longnames;
    for( ; *ppsz_name; ppsz_name++, ppsz_longname++ )
Clément Stenac's avatar
Clément Stenac committed
666
    {
667
        QAction *a = new QAction( qfu( *ppsz_longname ), menu );
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
668
        a->setCheckable( true );
669
        if( playlist_IsServicesDiscoveryLoaded( THEPL, *ppsz_name ) )
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
670
            a->setChecked( true );
671
        CONNECT( a, triggered(), THEDP->SDMapper, map() );
672
        THEDP->SDMapper->setMapping( a, QString( *ppsz_name ) );
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
673
        menu->addAction( a );
674

675
        /* Special case for podcast */
676
        if( !strcmp( *ppsz_name, "podcast" ) )
677
        {
Christophe Mutricy's avatar
Christophe Mutricy committed
678
            QAction *b = new QAction( qtr( "Configure podcasts..." ), menu );
679 680 681 682
            //b->setEnabled( a->isChecked() );
            menu->addAction( b );
            CONNECT( b, triggered(), THEDP, podcastConfigureDialog() );
        }
683 684
        free( *ppsz_name );
        free( *ppsz_longname );
Clément Stenac's avatar
Clément Stenac committed
685
    }
686 687
    free( ppsz_names );
    free( ppsz_longnames );
Clément Stenac's avatar
Clément Stenac committed
688 689
    return menu;
}
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
690

691 692 693
/**
 * Help/About Menu
**/
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
694
QMenu *QVLCMenu::HelpMenu( QWidget *parent )
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
695
{
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
696
    QMenu *menu = new QMenu( parent );
697
    addDPStaticEntry( menu, qtr( "&Help..." ) ,
698
        ":/menu/help", SLOT( helpDialog() ), "F1" );
699
#ifdef UPDATE_CHECK
700 701
    addDPStaticEntry( menu, qtr( "Check for &Updates..." ) , "",
                      SLOT( updateDialog() ) );
702
#endif
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
703
    menu->addSeparator();
704
    addDPStaticEntry( menu, qtr( I_MENU_ABOUT ), ":/menu/info",
705
            SLOT( aboutDialog() ), "Shift+F1" );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
706 707 708
    return menu;
}

709
/*****************************************************************************
710
 * Popup menus - Right Click menus                                           *
711
 *****************************************************************************/
712 713
#define POPUP_BOILERPLATE \
    unsigned int i_last_separator = 0; \
714
    vector<vlc_object_t *> objects; \
715 716 717 718 719 720 721
    vector<const char *> varnames; \
    input_thread_t *p_input = THEMIM->getInput();

#define CREATE_POPUP \
    Populate( p_intf, menu, varnames, objects ); \
    p_intf->p_sys->p_popup_menu = menu; \
    menu->popup( QCursor::pos() ); \
722
    p_intf->p_sys->p_popup_menu = NULL; \
723
    i_last_separator = 0;
724

725
void QVLCMenu::PopupPlayEntries( QMenu *menu,
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
726 727 728
                                        intf_thread_t *p_intf,
                                        input_thread_t *p_input )
{
729 730 731
    QAction *action;

    /* Play or Pause action and icon */
732 733
    if( !p_input || var_GetInteger( p_input, "state" ) != PLAYING_S )
    {
734
        action = menu->addAction( qtr( "Play" ),
735
                ActionsManager::getInstance( p_intf ), SLOT( play() ) );
736
        action->setIcon( QIcon( ":/menu/play" ) );
737 738
    }
    else
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
739
    {
740
         addMIMStaticEntry( p_intf, menu, qtr( "Pause" ),
741
                    ":/menu/pause", SLOT( togglePlayPause() ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
742
    }
743 744 745 746 747
}

void QVLCMenu::PopupMenuControlEntries( QMenu *menu, intf_thread_t *p_intf )
{
    QAction *action;
748 749

    /* Faster/Slower */
750
    action = menu->addAction( qtr( "&Faster" ), THEMIM->getIM(),
751
                              SLOT( faster() ) );
752
    action->setIcon( QIcon( ":/toolbar/faster") );
753
    action->setData( STATIC_ENTRY );