menus.cpp 43.5 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

Clément Stenac's avatar
Clément Stenac committed
37
#include "menus.hpp"
38 39

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

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

53 54 55 56 57 58 59 60 61 62 63 64 65 66
/*
  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.
  */

67 68 69
#define STATIC_ENTRY "__static__"
#define ENTRY_ALWAYS_ENABLED "__ignore__"

70 71 72 73 74 75 76 77 78
enum
{
    ITEM_NORMAL,
    ITEM_CHECK,
    ITEM_RADIO
};

static QActionGroup *currentGroup;

Ludovic Fauvet's avatar
Ludovic Fauvet committed
79 80
QMenu *QVLCMenu::recentsMenu = NULL;

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

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

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

Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
142 143
    QList< QAction* > actions = menu->actions();
    for( int i = 0; i < actions.size(); ++i )
144
    {
145 146 147 148
        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 ) ) );
149 150 151
    }
}

152 153 154 155 156
/**
 * \return Number of static entries
 */
int DeleteNonStaticEntries( QMenu *menu )
{
157 158
    if( !menu ) return VLC_EGENERIC;

159
    int i_ret = 0;
160

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

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

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

#define PUSH_INPUTVAR( var ) varnames.push_back( var ); \
193
    objects.push_back( VLC_OBJECT(p_input) );
194 195

#define PUSH_SEPARATOR if( objects.size() != i_last_separator ) { \
196
    objects.push_back( 0 ); varnames.push_back( "" ); \
197
    i_last_separator = objects.size(); }
198

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

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

231 232 233
    return VLC_SUCCESS;
}

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

246 247
/*****************************************************************************
 * All normal menus
248
 * Simple Code
249 250 251
 *****************************************************************************/

#define BAR_ADD( func, title ) { \
252
    QMenu *_menu = func; _menu->setTitle( title ); bar->addMenu( _menu ); }
253 254

#define BAR_DADD( func, title, id ) { \
255 256 257 258 259 260 261 262
    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 ); }
263

264 265
#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
266
    _action->setMenu( new QMenu( _menu ) ); _menu->addAction( _action ); }
267 268 269 270 271

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

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

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

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

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

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

305
    addDPStaticEntry( menu, qtr( "&Open File..." ),
306
        ":/file-asym", SLOT( simpleOpenDialog() ), "Ctrl+O" );
307
    addDPStaticEntry( menu, qtr( "Advanced Open File..." ),
308
        ":/file-asym", SLOT( openFileDialog() ), "Ctrl+Shift+O" );
309
    addDPStaticEntry( menu, qtr( I_OPEN_FOLDER ),
310
        ":/folder-grey", SLOT( PLOpenDir() ), "Ctrl+F" );
311
    addDPStaticEntry( menu, qtr( "Open &Disc..." ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
312
        ":/disc", SLOT( openDiscDialog() ), "Ctrl+D" );
313
    addDPStaticEntry( menu, qtr( "Open &Network Stream..." ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
314
        ":/network", SLOT( openNetDialog() ), "Ctrl+N" );
315
    addDPStaticEntry( menu, qtr( "Open &Capture Device..." ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
316
        ":/capture-card", SLOT( openCaptureDialog() ),
317
        "Ctrl+C" );
318

319
    menu->addSeparator();
320
    addDPStaticEntry( menu, qtr( "Open &Location from clipboard" ),
321
                      NULL, SLOT( openUrlDialog() ), "Ctrl+V" );
322

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

332 333 334 335
    addDPStaticEntry( menu, qtr( I_PL_SAVE ), "", SLOT( saveAPlaylist() ),
        "Ctrl+Y" );
    menu->addSeparator();

336
    addDPStaticEntry( menu, qtr( "Conve&rt / Save..." ), "",
337
        SLOT( openAndTranscodingDialogs() ), "Ctrl+R" );
338
    addDPStaticEntry( menu, qtr( "&Streaming..." ),
339
        ":/stream", SLOT( openAndStreamingDialogs() ),
340
        "Ctrl+S" );
341
    menu->addSeparator();
342

343
    addDPStaticEntry( menu, qtr( "&Quit" ) ,
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
344
        ":/quit", SLOT( quit() ), "Ctrl+Q" );
345 346 347
    return menu;
}

348 349 350
/**
 * Tools, like Media Information, Preferences or Messages 
 **/
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
351
QMenu *QVLCMenu::ToolsMenu( QMenu *menu )
Clément Stenac's avatar
Clément Stenac committed
352
{
353
    addDPStaticEntry( menu, qtr( "&Effects and Filters"), ":/settings",
354
            SLOT( extendedDialog() ), "Ctrl+E" );
355

356
    addDPStaticEntry( menu, qtr( "&Track Synchronization"), ":/settings",
357 358
            SLOT( synchroDialog() ), "" );

359
    addDPStaticEntry( menu, qtr( I_MENU_INFO ) , ":/info",
360
        SLOT( mediaInfoDialog() ), "Ctrl+I" );
361
    addDPStaticEntry( menu, qtr( I_MENU_CODECINFO ) ,
362
        ":/info", SLOT( mediaCodecDialog() ), "Ctrl+J" );
363

364
    addDPStaticEntry( menu, qtr( I_MENU_BOOKMARK ),"",
365 366
                      SLOT( bookmarksDialog() ), "Ctrl+B" );
#ifdef ENABLE_VLM
367
    addDPStaticEntry( menu, qtr( I_MENU_VLM ), "", SLOT( vlmDialog() ),
368 369
        "Ctrl+W" );
#endif
370 371 372 373 374

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

375 376
    addDPStaticEntry( menu, qtr( "Plu&gins and extensions" ),
        "", SLOT( pluginDialog() ) );
Clément Stenac's avatar
Clément Stenac committed
377 378
    menu->addSeparator();

379
    addDPStaticEntry( menu, qtr( "&Preferences" ),
380 381
        ":/preferences", SLOT( prefsDialog() ), "Ctrl+P" );

Clément Stenac's avatar
Clément Stenac committed
382 383 384
    return menu;
}

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
385 386 387 388 389
QMenu *QVLCMenu::ToolsMenu( QWidget *parent )
{
    return ToolsMenu( new QMenu( parent ) );
}

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

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

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

406 407 408 409
    /*menu->addSeparator();
    menu->addAction( qtr( "Undock from Interface" ), mi,
                     SLOT( undockPlaylist() ), qtr( "Ctrl+U" ) );*/

410 411
    menu->addSeparator();

412 413
    if( with_intf )
    {
414
        QMenu *intfmenu = InterfacesMenu( p_intf, menu );
415 416 417
        MenuFunc *f = new MenuFunc( intfmenu, 4 );
        CONNECT( intfmenu, aboutToShow(), THEDP->menusUpdateMapper, map() );
        THEDP->menusUpdateMapper->setMapping( intfmenu, f );
418 419
        menu->addSeparator();
    }
420

421
    /* Minimal View */
422 423
    QAction *action = menu->addAction( qtr( "Mi&nimal View" ) );
    action->setShortcut( qtr( "Ctrl+H" ) );
424
    action->setCheckable( true );
425
    action->setChecked( !with_intf &&
426
            (mi->getControlsVisibilityStatus() & CONTROLS_HIDDEN ) );
427

428 429
    CONNECT( action, triggered( bool ), mi, toggleMinimalView( bool ) );
    CONNECT( mi, minimalViewToggled( bool ), action, setChecked( bool ) );
430 431 432 433 434

    /* FullScreen View */
    action = menu->addAction( qtr( "&Fullscreen Interface" ), mi,
            SLOT( toggleFullScreen() ), QString( "F11" ) );
    action->setCheckable( true );
435 436 437
    action->setChecked( mi->isFullScreen() );
    CONNECT( mi, fullscreenInterfaceToggled( bool ),
             action, setChecked( bool ) );
438 439 440 441 442 443 444 445

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

446 447 448 449 450 451 452 453
    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 ) );
    }

454
#if 0 /* For Visualisations. Not yet working */
455 456 457 458
    adv = menu->addAction( qtr( "Visualizations selector" ),
            mi, SLOT( visual() ) );
    adv->setCheckable( true );
    if( visual_selector_enabled ) adv->setChecked( true );
459
#endif
460

461
    menu->addSeparator();
462 463 464
    addDPStaticEntry( menu, qtr( "Customi&ze Interface..." ),
        ":/preferences", SLOT( toolbarDialog() ) );
    menu->addSeparator();
465

466 467 468
    return menu;
}

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

479
    return Populate( p_intf, current, varnames, objects );
480 481
}

482 483
/**
 * Main Audio Menu
484
 **/
485 486
QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QMenu * current )
{
487
    vector<vlc_object_t *> objects;
488
    vector<const char *> varnames;
489
    aout_instance_t *p_aout;
490 491 492
    input_thread_t *p_input;

    if( current->isEmpty() )
493
    {
494 495 496
        ACT_ADDMENU( current, "audio-es", qtr( "Audio &Track" ) );
        ACT_ADDMENU( current, "audio-channels", qtr( "Audio &Channels" ) );
        ACT_ADDMENU( current, "audio-device", qtr( "Audio &Device" ) );
497
        current->addSeparator();
498

499
        ACT_ADDMENU( current, "visual", qtr( "&Visualizations" ) );
500 501
        current->addSeparator();

502
        QAction *action = current->addAction( qtr( "Increase Volume" ),
503
                ActionsManager::getInstance( p_intf ), SLOT( AudioUp() ) );
504
        action->setData( STATIC_ENTRY );
505 506
        action = current->addAction( qtr( "Decrease Volume" ),
                ActionsManager::getInstance( p_intf ), SLOT( AudioDown() ) );
507
        action->setData( STATIC_ENTRY );
508 509
        action = current->addAction( qtr( "Mute" ),
                ActionsManager::getInstance( p_intf ), SLOT( toggleMuteAudio() ) );
510
        action->setData( STATIC_ENTRY );
511 512
    }

513
    p_input = THEMIM->getInput();
514
    p_aout = THEMIM->getAout();
515
    EnableStaticEntries( current, ( p_aout != NULL ) );
516
    AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
517
    if( p_aout )
518
    {
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
519
        vlc_object_release( p_aout );
520
    }
521

522 523 524
    return Populate( p_intf, current, varnames, objects );
}

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
525 526 527 528 529
QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QWidget *parent )
{
    return AudioMenu( p_intf, new QMenu( parent ) );
}

530 531 532 533
/**
 * Main Video Menu
 * Subtitles are part of Video.
 **/
534
QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current )
535
{
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
536
    vout_thread_t *p_vout;
537
    input_thread_t *p_input;
538
    vector<vlc_object_t *> objects;
539 540
    vector<const char *> varnames;

541
    if( current->isEmpty() )
542
    {
543
        ACT_ADDMENU( current, "video-es", qtr( "Video &Track" ) );
544 545 546 547 548

        QAction *action;
        QMenu *submenu = new QMenu( qtr( "&Subtitles Track" ), current );
        action = current->addMenu( submenu );
        action->setData( "spu-es" );
549
        addDPStaticEntry( submenu, qtr( "Open File..." ), "",
550
                          SLOT( loadSubtitlesFile() ) );
551
        submenu->addSeparator();
552
        current->addSeparator();
553

554 555
        ACT_ADDCHECK( current, "fullscreen", qtr( "&Fullscreen" ) );
        ACT_ADDCHECK( current, "video-on-top", qtr( "Always &On Top" ) );
556
#ifdef WIN32
557
        ACT_ADDCHECK( current, "directx-wallpaper", qtr( "DirectX Wallpaper" ) );
558
#endif
559
        ACT_ADD( current, "video-snapshot", qtr( "Sna&pshot" ) );
560

561 562
        current->addSeparator();

563 564 565 566 567
        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" ) );
568
        ACT_ADDMENU( current, "postprocess", qtr( "&Post processing" ) );
569
    }
570

571 572
    p_input = THEMIM->getInput();

573
    p_vout = THEMIM->getVout();
574
    VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
575

576 577
    if( p_vout )
        vlc_object_release( p_vout );
578

579
    return Populate( p_intf, current, varnames, objects );
580 581
}

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
582 583 584 585 586
QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QWidget *parent )
{
    return VideoMenu( p_intf, new QMenu( parent ) );
}

587 588 589 590
/**
 * Navigation Menu
 * For DVD, MP4, MOV and other chapter based format
 **/
591
QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *menu )
592
{
593
    QAction *action;
594

595 596 597 598 599 600
    QMenu *submenu = new QMenu( qtr( "&Bookmarks" ), menu );
    addDPStaticEntry( submenu, qtr( "Manage &bookmarks" ), "",
                      SLOT( bookmarksDialog() ) );
    submenu->addSeparator();
    action = menu->addMenu( submenu );
    action->setData( "bookmark" );
601

602 603 604 605
    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" ) );
606

607 608
    menu->addSeparator();
    PopupMenuPlaylistControlEntries( menu, p_intf );
609
    PopupMenuControlEntries( menu, p_intf );
610 611 612 613 614 615

    return menu;
}

QMenu *QVLCMenu::RebuildNavigMenu( intf_thread_t *p_intf, QMenu *menu )
{
616
    /* */
617 618 619 620
    input_thread_t *p_object;
    vector<vlc_object_t *> objects;
    vector<const char *> varnames;

621
    /* Get the input and hold it */
622
    p_object = THEMIM->getInput();
623

624
    InputAutoMenuBuilder( p_object, objects, varnames );
625

626 627
    menu->addSeparator();

628
    /* Title and so on */
629 630 631 632
    PUSH_VAR( "prev-title" );
    PUSH_VAR( "next-title" );
    PUSH_VAR( "prev-chapter" );
    PUSH_VAR( "next-chapter" );
633

634
    EnableStaticEntries( menu, (p_object != NULL ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
635
    return Populate( p_intf, menu, varnames, objects );
636
}
637

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
638 639 640 641 642
QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QWidget *parent )
{
    return NavigMenu( p_intf, new QMenu( parent ) );
}

643
/**
644
 * Service Discovery SubMenu
645
 **/
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
646
QMenu *QVLCMenu::SDMenu( intf_thread_t *p_intf, QWidget *parent )
Clément Stenac's avatar
Clément Stenac committed
647
{
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
648
    QMenu *menu = new QMenu( parent );
649
    menu->setTitle( qtr( I_PL_SD ) );
650

651
    char **ppsz_longnames;
652
    char **ppsz_names = vlc_sd_GetNames( &ppsz_longnames );
653 654 655
    if( !ppsz_names )
        return menu;

656 657
    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
658
    {
659
        QAction *a = new QAction( qfu( *ppsz_longname ), menu );
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
660
        a->setCheckable( true );
661
        if( playlist_IsServicesDiscoveryLoaded( THEPL, *ppsz_name ) )
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
662
            a->setChecked( true );
663
        CONNECT( a, triggered(), THEDP->SDMapper, map() );
664
        THEDP->SDMapper->setMapping( a, QString( *ppsz_name ) );
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
665
        menu->addAction( a );
666

667
        /* Special case for podcast */
668
        if( !strcmp( *ppsz_name, "podcast" ) )
669
        {
Christophe Mutricy's avatar
Christophe Mutricy committed
670
            QAction *b = new QAction( qtr( "Configure podcasts..." ), menu );
671 672 673 674
            //b->setEnabled( a->isChecked() );
            menu->addAction( b );
            CONNECT( b, triggered(), THEDP, podcastConfigureDialog() );
        }
675 676
        free( *ppsz_name );
        free( *ppsz_longname );
Clément Stenac's avatar
Clément Stenac committed
677
    }
678 679
    free( ppsz_names );
    free( ppsz_longnames );
Clément Stenac's avatar
Clément Stenac committed
680 681
    return menu;
}
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
682

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

701
/*****************************************************************************
702
 * Popup menus - Right Click menus                                           *
703
 *****************************************************************************/
704 705
#define POPUP_BOILERPLATE \
    unsigned int i_last_separator = 0; \
706
    vector<vlc_object_t *> objects; \
707 708 709 710 711 712 713
    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() ); \
714
    p_intf->p_sys->p_popup_menu = NULL; \
715
    i_last_separator = 0;
716

717
void QVLCMenu::PopupPlayEntries( QMenu *menu,
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
718 719 720
                                        intf_thread_t *p_intf,
                                        input_thread_t *p_input )
{
721 722 723
    QAction *action;

    /* Play or Pause action and icon */
724 725
    if( !p_input || var_GetInteger( p_input, "state" ) != PLAYING_S )
    {
726
        action = menu->addAction( qtr( "Play" ),
727 728 729 730
                ActionsManager::getInstance( p_intf ), SLOT( play() ) );
        action->setIcon( QIcon( ":/play" ) );
    }
    else
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
731
    {
732
         addMIMStaticEntry( p_intf, menu, qtr( "Pause" ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
733
                    ":/pause", SLOT( togglePlayPause() ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
734
    }
735 736 737 738 739
}

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

    /* Faster/Slower */
742
    action = menu->addAction( qtr( "&Faster" ), THEMIM->getIM(),
743
                              SLOT( faster() ) );
744
    action->setIcon( QIcon( ":/faster") );
745
    action->setData( STATIC_ENTRY );
746

747 748
    action = menu->addAction( qtr( "Faster (fine)" ), THEMIM->getIM(),
                              SLOT( littlefaster() ) );
749
    action->setData( STATIC_ENTRY );
750

751
    action = menu->addAction( qtr( "N&ormal Speed" ), THEMIM->getIM(),
752
                              SLOT( normalRate() ) );
753
    action->setData( STATIC_ENTRY );
754

755 756
    action = menu->addAction( qtr( "Slower (fine)" ), THEMIM->getIM(),
                              SLOT( littleslower() ) );
757
    action->setData( STATIC_ENTRY );
758

759
    action = menu->addAction( qtr( "Slo&wer" ), THEMIM->getIM(),
760
                              SLOT( slower() ) );
761
    action->setIcon( QIcon( ":/slower") );
762
    action->setData( STATIC_ENTRY );
763 764

    menu->addSeparator();
765

766
    action = menu->addAction( qtr( "&Jump Forward" ), THEMIM->getIM(),
767 768
             SLOT( jumpFwd() ) );
    action->setIcon( QIcon( ":/skip_fw") );