menus.cpp 42.6 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 70 71 72 73 74 75
enum
{
    ITEM_NORMAL,
    ITEM_CHECK,
    ITEM_RADIO
};

static QActionGroup *currentGroup;

76 77 78
/* HACK for minimalView to go around a Qt bug/feature
 * that doesn't update the QAction checked state when QMenu is hidden */
QAction *QVLCMenu::minimalViewAction = NULL;
79
QAction *QVLCMenu::fullscreenViewAction = NULL;
80

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 89
void addDPStaticEntry( QMenu *menu,
                       const QString text,
90
                       const char *icon,
91
                       const char *member,
92
                       const char *shortcut = NULL )
93
{
94
    QAction *action = NULL;
95 96 97
    if( !EMPTY_STR( icon ) > 0 )
    {
        if( !EMPTY_STR( shortcut ) > 0 )
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 105
    }
    else
    {
        if( !EMPTY_STR( shortcut ) > 0 )
106
            action = menu->addAction( text, THEDP, member, qtr( shortcut ) );
107
        else
108
            action = menu->addAction( text, THEDP, member );
109
    }
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
110
    action->setData( true );
111
}
112

113 114 115 116 117
/**
 * @brief Enable all static entries, disable the others
 * @param enable if false, disable all entries
 */
void EnableStaticEntries( QMenu *menu, bool enable = true )
118
{
119
    if( !menu ) return;
120

Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
121 122
    QList< QAction* > actions = menu->actions();
    for( int i = 0; i < actions.size(); ++i )
123
    {
124
        actions[i]->setEnabled( enable && actions[i]->data().toBool() );
125 126 127
    }
}

128 129 130 131 132 133 134 135
/**
 * \return Number of static entries
 */
int DeleteNonStaticEntries( QMenu *menu )
{
    int i_ret = 0;
    if( !menu )
        return VLC_EGENERIC;
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
136 137
    QList< QAction* > actions = menu->actions();
    for( int i = 0; i < actions.size(); ++i )
138
    {
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
139 140
        if( !actions[i]->data().toBool() )
            delete actions[i];
141 142 143
        else
            i_ret++;
    }
144
    return i_ret;
145 146
}

147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
/***
 * Same for MIM
 ***/
void addMIMStaticEntry( intf_thread_t *p_intf,
                        QMenu *menu,
                        const QString text,
                        const char *icon,
                        const char *member )
{
    if( strlen( icon ) > 0 )
    {
        QAction *action = menu->addAction( text, THEMIM,  member );
        action->setIcon( QIcon( icon ) );
    }
    else
    {
        menu->addAction( text, THEMIM, member );
    }
}

167
/*****************************************************************************
168
 * Definitions of variables for the dynamic menus
169
 *****************************************************************************/
170
#define PUSH_VAR( var ) varnames.push_back( var ); \
171
    objects.push_back( VLC_OBJECT(p_object) )
172 173

#define PUSH_INPUTVAR( var ) varnames.push_back( var ); \
174
    objects.push_back( VLC_OBJECT(p_input) );
175 176

#define PUSH_SEPARATOR if( objects.size() != i_last_separator ) { \
177
    objects.push_back( 0 ); varnames.push_back( "" ); \
178
    i_last_separator = objects.size(); }
179

180
static int InputAutoMenuBuilder( input_thread_t *p_object,
181
        vector<vlc_object_t *> &objects,
182
        vector<const char *> &varnames )
183
{
184
    PUSH_VAR( "bookmark" );
185
    PUSH_VAR( "title" );
186
    PUSH_VAR( "chapter" );
187
    PUSH_VAR( "navigation" );
188
    PUSH_VAR( "program" );
189 190 191 192
    PUSH_VAR( "dvd_menus" );
    return VLC_SUCCESS;
}

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
193
static int VideoAutoMenuBuilder( vout_thread_t *p_object,
194
        input_thread_t *p_input,
195
        vector<vlc_object_t *> &objects,
196
        vector<const char *> &varnames )
197
{
198 199
    PUSH_INPUTVAR( "video-es" );
    PUSH_INPUTVAR( "spu-es" );
200 201
    PUSH_VAR( "fullscreen" );
    PUSH_VAR( "video-on-top" );
202
#ifdef WIN32
203
    PUSH_VAR( "directx-wallpaper" );
204
#endif
205
    PUSH_VAR( "video-snapshot" );
206
    PUSH_VAR( "zoom" );
207
    PUSH_VAR( "autoscale" );
208 209 210
    PUSH_VAR( "aspect-ratio" );
    PUSH_VAR( "crop" );
    PUSH_VAR( "deinterlace" );
211
    PUSH_VAR( "postprocess" );
212

213 214 215
    return VLC_SUCCESS;
}

216
static int AudioAutoMenuBuilder( aout_instance_t *p_object,
217
        input_thread_t *p_input,
218
        vector<vlc_object_t *> &objects,
219
        vector<const char *> &varnames )
220
{
221
    PUSH_INPUTVAR( "audio-es" );
222
    PUSH_VAR( "audio-channels" );
223 224
    PUSH_VAR( "audio-device" );
    PUSH_VAR( "visual" );
225 226 227
    return VLC_SUCCESS;
}

228 229
static QAction * FindActionWithVar( QMenu *menu, const char *psz_var )
{
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
230 231
    QList< QAction* > actions = menu->actions();
    for( int i = 0; i < actions.size(); ++i )
232
    {
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
233 234
        if( actions[i]->data().toString() == psz_var )
            return actions[i];
235 236 237 238
    }
    return NULL;
}

239 240
/*****************************************************************************
 * All normal menus
241
 * Simple Code
242 243 244
 *****************************************************************************/

#define BAR_ADD( func, title ) { \
245
    QMenu *_menu = func; _menu->setTitle( title ); bar->addMenu( _menu ); }
246 247

#define BAR_DADD( func, title, id ) { \
248 249 250 251 252 253 254 255
    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 ); }
256

257 258 259 260 261 262 263 264
#define ACT_ADDMENU( _menu, val, title ) { \
    QAction *_action = new QAction( title, _menu ); _action->setData( val ); \
    _action->setMenu( new QMenu() ); _menu->addAction( _action ); }

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

265 266 267
/**
 * Main Menu Bar Creation
 **/
268 269 270
void QVLCMenu::createMenuBar( MainInterface *mi,
                              intf_thread_t *p_intf,
                              bool visual_selector_enabled )
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
271
/* FIXME remove this visual dependency */
Clément Stenac's avatar
Qt4:  
Clément Stenac committed
272
{
273 274 275
    /* QMainWindows->menuBar()
       gives the QProcess::destroyed timeout issue on Cleanlooks style with
       setDesktopAware set to false */
276
    QMenuBar *bar = mi->menuBar();
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
277
    BAR_ADD( FileMenu( p_intf, bar ), qtr( "&Media" ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
278

279
    BAR_DADD( NavigMenu( p_intf, bar ), qtr( "P&layback" ), 3 );
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
280 281
    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
282

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
283
    BAR_ADD( ToolsMenu( bar ), qtr( "&Tools" ) );
284 285
    BAR_ADD( ViewMenu( p_intf, NULL, mi, visual_selector_enabled, true ),
             qtr( "V&iew" ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
286

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
287
    BAR_ADD( HelpMenu( bar ), qtr( "&Help" ) );
288
}
289 290
#undef BAR_ADD
#undef BAR_DADD
291 292

/**
293
 * Media ( File ) Menu
294 295
 * Opening, streaming and quit
 **/
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
296
QMenu *QVLCMenu::FileMenu( intf_thread_t *p_intf, QWidget *parent )
297
{
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
298
    QMenu *menu = new QMenu( parent );
299

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

314
    menu->addSeparator();
315 316
    addDPStaticEntry( menu, qtr( "Paste &MRL" ),
                      NULL, SLOT( openUrlDialog() ), "Ctrl+V" );
317

318
    recentsMenu = new QMenu( qtr( "&Recent Media" ), menu );
Ludovic Fauvet's avatar
Ludovic Fauvet committed
319 320
    updateRecents( p_intf );
    menu->addMenu( recentsMenu );
321
    menu->addSeparator();
322 323
    menu->addMenu( SDMenu( p_intf, menu ) );
    menu->addSeparator();
324

325 326 327 328
    addDPStaticEntry( menu, qtr( I_PL_SAVE ), "", SLOT( saveAPlaylist() ),
        "Ctrl+Y" );
    menu->addSeparator();

329
    addDPStaticEntry( menu, qtr( "Conve&rt / Save..." ), "",
330
        SLOT( openAndTranscodingDialogs() ), "Ctrl+R" );
331
    addDPStaticEntry( menu, qtr( "&Streaming..." ),
332
        ":/stream", SLOT( openAndStreamingDialogs() ),
333
        "Ctrl+S" );
334
    menu->addSeparator();
335

336
    addDPStaticEntry( menu, qtr( "&Quit" ) ,
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
337
        ":/quit", SLOT( quit() ), "Ctrl+Q" );
338 339 340
    return menu;
}

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
341
/* Playlist/MediaLibrary Control */
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
342
QMenu *QVLCMenu::ToolsMenu( QMenu *menu )
Clément Stenac's avatar
Clément Stenac committed
343
{
344
    addDPStaticEntry( menu, qtr( I_MENU_EXT ), ":/settings",
345
            SLOT( extendedDialog() ), "Ctrl+E" );
346

347
    addDPStaticEntry( menu, qtr( I_MENU_INFO ) , ":/info",
348
        SLOT( mediaInfoDialog() ), "Ctrl+I" );
349
    addDPStaticEntry( menu, qtr( I_MENU_CODECINFO ) ,
350
        ":/info", SLOT( mediaCodecDialog() ), "Ctrl+J" );
351

352
    addDPStaticEntry( menu, qtr( I_MENU_BOOKMARK ),"",
353 354
                      SLOT( bookmarksDialog() ), "Ctrl+B" );
#ifdef ENABLE_VLM
355
    addDPStaticEntry( menu, qtr( I_MENU_VLM ), "", SLOT( vlmDialog() ),
356 357
        "Ctrl+W" );
#endif
358 359 360 361 362

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

363 364
    addDPStaticEntry( menu, qtr( "Plu&gins and extensions" ),
        "", SLOT( pluginDialog() ) );
Clément Stenac's avatar
Clément Stenac committed
365 366
    menu->addSeparator();

367
    addDPStaticEntry( menu, qtr( "&Preferences" ),
368 369
        ":/preferences", SLOT( prefsDialog() ), "Ctrl+P" );

Clément Stenac's avatar
Clément Stenac committed
370 371 372
    return menu;
}

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
373 374 375 376 377
QMenu *QVLCMenu::ToolsMenu( QWidget *parent )
{
    return ToolsMenu( new QMenu( parent ) );
}

378
/**
379
 * View Menu
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
380
 * This menu can be an interface menu but also a right click menu.
381
 **/
382
QMenu *QVLCMenu::ViewMenu( intf_thread_t *p_intf,
383
                            QMenu *current,
384 385 386
                            MainInterface *mi,
                            bool visual_selector_enabled,
                            bool with_intf )
387
{
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
388 389 390 391 392
    QMenu *menu;
    if( current )
        menu = new QMenu( current );
    else
        menu = new QMenu( mi );
393
    QAction *act;
394 395
    if( mi )
    {
396
        act = menu->addAction( QIcon( ":/playlist_menu" ),
397
                               qtr( "Play&list" ), mi,
398
                               SLOT( togglePlaylist() ), qtr( "Ctrl+L" ) );
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
399
        act->setData( true );
400
    }
401 402 403 404
    /*menu->addSeparator();
    menu->addAction( qtr( "Undock from Interface" ), mi,
                     SLOT( undockPlaylist() ), qtr( "Ctrl+U" ) );*/

405 406 407

    menu->addSeparator();

408 409
    if( with_intf )
    {
410
        QMenu *intfmenu = InterfacesMenu( p_intf, menu );
411 412 413
        MenuFunc *f = new MenuFunc( intfmenu, 4 );
        CONNECT( intfmenu, aboutToShow(), THEDP->menusUpdateMapper, map() );
        THEDP->menusUpdateMapper->setMapping( intfmenu, f );
414 415
        menu->addSeparator();
    }
Clément Stenac's avatar
Clément Stenac committed
416 417
    if( mi )
    {
418
        /* Minimal View */
419
        QAction *action = menu->addAction( qtr( "Mi&nimal View" ), mi,
420
                                SLOT( toggleMinimalView() ), qtr( "Ctrl+H" ) );
421
        action->setCheckable( true );
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
422
        action->setData( true );
423
        if( mi->getControlsVisibilityStatus() & CONTROLS_VISIBLE )
424
            action->setChecked( true );
425
        minimalViewAction = action; /* HACK for minimalView */
426

427
        /* FullScreen View */
428
        action = menu->addAction( qtr( "&Fullscreen Interface" ), mi,
429
                                  SLOT( toggleFullScreen() ), QString( "F11" ) );
430
        fullscreenViewAction = action;
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
431
        action->setCheckable( true );
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
432
        action->setData( true );
433

434
        /* Advanced Controls */
435
        action = menu->addAction( qtr( "&Advanced Controls" ), mi,
436
                                  SLOT( toggleAdvanced() ) );
437
        action->setCheckable( true );
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
438
        action->setData( true );
439 440
        if( mi->getControlsVisibilityStatus() & CONTROLS_ADVANCED )
            action->setChecked( true );
441
#if 0 /* For Visualisations. Not yet working */
442
        adv = menu->addAction( qtr( "Visualizations selector" ),
443
                mi, SLOT( visual() ) );
444 445
        adv->setCheckable( true );
        if( visual_selector_enabled ) adv->setChecked( true );
446
#endif
Clément Stenac's avatar
Clément Stenac committed
447
    }
448

449
    menu->addSeparator();
450 451 452
    addDPStaticEntry( menu, qtr( "Customi&ze Interface..." ),
        ":/preferences", SLOT( toolbarDialog() ) );
    menu->addSeparator();
453

454 455 456
    return menu;
}

457 458 459
/**
 * Interface Sub-Menu, to list extras interface and skins
 **/
460 461
QMenu *QVLCMenu::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
{
462
    vector<vlc_object_t *> objects;
463 464 465
    vector<const char *> varnames;
    /** \todo add "switch to XXX" */
    varnames.push_back( "intf-add" );
466
    objects.push_back( VLC_OBJECT(p_intf) );
Clément Stenac's avatar
Qt4:  
Clément Stenac committed
467

468
    return Populate( p_intf, current, varnames, objects );
469 470
}

471 472 473
/**
 * Main Audio Menu
 */
474 475
QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QMenu * current )
{
476
    vector<vlc_object_t *> objects;
477
    vector<const char *> varnames;
478
    aout_instance_t *p_aout;
479 480 481
    input_thread_t *p_input;

    if( current->isEmpty() )
482
    {
483 484 485
        ACT_ADDMENU( current, "audio-es", qtr( "Audio &Track" ) );
        ACT_ADDMENU( current, "audio-channels", qtr( "Audio &Channels" ) );
        ACT_ADDMENU( current, "audio-device", qtr( "Audio &Device" ) );
486
        current->addSeparator();
487

488
        ACT_ADDMENU( current, "visual", qtr( "&Visualizations" ) );
489 490
        current->addSeparator();

491
        QAction *action = current->addAction( qtr( "Increase Volume" ),
492 493 494 495 496
                ActionsManager::getInstance( p_intf ), SLOT( AudioUp() ) );
        action->setData( true );
        action = current->addAction( qtr( "Decrease Volume" ),
                ActionsManager::getInstance( p_intf ), SLOT( AudioDown() ) );
        action->setData( true );
497 498 499
        action = current->addAction( qtr( "Mute" ),
                ActionsManager::getInstance( p_intf ), SLOT( toggleMuteAudio() ) );
        action->setData( true );
500 501
    }

502 503
    p_input = THEMIM->getInput();
    if( p_input )
504
        vlc_object_hold( p_input );
505
    p_aout = THEMIM->getAout();
506 507
    AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
    EnableStaticEntries( current, ( p_aout != NULL ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
508
    if( p_aout )
509
    {
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
510
        vlc_object_release( p_aout );
511
    }
512 513 514
    if( p_input )
        vlc_object_release( p_input );

515 516 517
    return Populate( p_intf, current, varnames, objects );
}

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
518 519 520 521 522
QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QWidget *parent )
{
    return AudioMenu( p_intf, new QMenu( parent ) );
}

523 524 525 526
/**
 * Main Video Menu
 * Subtitles are part of Video.
 **/
527
QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current )
528
{
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
529
    vout_thread_t *p_vout;
530
    input_thread_t *p_input;
531
    vector<vlc_object_t *> objects;
532 533
    vector<const char *> varnames;

534
    if( current->isEmpty() )
535
    {
536
        ACT_ADDMENU( current, "video-es", qtr( "Video &Track" ) );
537 538 539 540 541

        QAction *action;
        QMenu *submenu = new QMenu( qtr( "&Subtitles Track" ), current );
        action = current->addMenu( submenu );
        action->setData( "spu-es" );
542
        addDPStaticEntry( submenu, qtr( "Open File..." ), "",
543
                          SLOT( loadSubtitlesFile() ) );
544
        submenu->addSeparator();
545
        current->addSeparator();
546

547 548
        ACT_ADDCHECK( current, "fullscreen", qtr( "&Fullscreen" ) );
        ACT_ADDCHECK( current, "video-on-top", qtr( "Always &On Top" ) );
549
#ifdef WIN32
550
        ACT_ADDCHECK( current, "directx-wallpaper", qtr( "DirectX Wallpaper" ) );
551
#endif
552
        ACT_ADD( current, "video-snapshot", qtr( "Sna&pshot" ) );
553

554 555
        current->addSeparator();

556 557 558 559 560
        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" ) );
561
        ACT_ADDMENU( current, "postprocess", qtr( "&Post processing" ) );
562
    }
563

564 565
    p_input = THEMIM->getInput();
    if( p_input )
566
        vlc_object_hold( p_input );
567

568
    p_vout = THEMIM->getVout();
569 570
    VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
    EnableStaticEntries( current, ( p_vout != NULL ) );
571
    if( p_vout )
572
    {
573
        vlc_object_release( p_vout );
574
    }
575 576 577
    if( p_input )
        vlc_object_release( p_input );

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

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

586 587 588 589
/**
 * Navigation Menu
 * For DVD, MP4, MOV and other chapter based format
 **/
590
QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *menu )
591
{
592 593
    if( menu->isEmpty() )
    {
594 595 596 597 598 599 600
        QAction *action;
        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
        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" ) );
605 606 607 608 609

        menu->addSeparator();
        addDPStaticEntry( menu, qtr( I_MENU_GOTOTIME ),"",
                          SLOT( gotoTimeDialog() ), "Ctrl+T" );

610 611
    }

612 613 614 615 616
    input_thread_t *p_object;
    vector<vlc_object_t *> objects;
    vector<const char *> varnames;

    p_object = THEMIM->getInput();
617 618
    if( p_object )
        vlc_object_hold( p_object );
619
    InputAutoMenuBuilder( p_object, objects, varnames );
620 621 622 623
    PUSH_VAR( "prev-title" );
    PUSH_VAR( "next-title" );
    PUSH_VAR( "prev-chapter" );
    PUSH_VAR( "next-chapter" );
624
    EnableStaticEntries( menu, ( p_object != NULL ) );
625
    if( p_object )
626
    {
627
        vlc_object_release( p_object );
628
    }
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
629
    return Populate( p_intf, menu, varnames, objects );
630
}
631

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
632 633 634 635 636
QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QWidget *parent )
{
    return NavigMenu( p_intf, new QMenu( parent ) );
}

637
/**
638
 * Service Discovery SubMenu
639
 **/
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
640
QMenu *QVLCMenu::SDMenu( intf_thread_t *p_intf, QWidget *parent )
Clément Stenac's avatar
Clément Stenac committed
641
{
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
642
    QMenu *menu = new QMenu( parent );
643
    menu->setTitle( qtr( I_PL_SD ) );
644
    char **ppsz_longnames;
645
    char **ppsz_names = vlc_sd_GetNames( &ppsz_longnames );
646 647 648
    if( !ppsz_names )
        return menu;

649 650
    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
651
    {
652
        QAction *a = new QAction( qfu( *ppsz_longname ), menu );
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
653
        a->setCheckable( true );
654
        if( playlist_IsServicesDiscoveryLoaded( THEPL, *ppsz_name ) )
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
655 656
            a->setChecked( true );
        CONNECT( a , triggered(), THEDP->SDMapper, map() );
657
        THEDP->SDMapper->setMapping( a, QString( *ppsz_name ) );
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
658
        menu->addAction( a );
659

660
        if( !strcmp( *ppsz_name, "podcast" ) )
661
        {
Christophe Mutricy's avatar
Christophe Mutricy committed
662
            QAction *b = new QAction( qtr( "Configure podcasts..." ), menu );
663 664 665 666
            //b->setEnabled( a->isChecked() );
            menu->addAction( b );
            CONNECT( b, triggered(), THEDP, podcastConfigureDialog() );
        }
667 668
        free( *ppsz_name );
        free( *ppsz_longname );
Clément Stenac's avatar
Clément Stenac committed
669
    }
670 671
    free( ppsz_names );
    free( ppsz_longnames );
Clément Stenac's avatar
Clément Stenac committed
672 673
    return menu;
}
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
674

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

693
/*****************************************************************************
694
 * Popup menus - Right Click menus                                           *
695
 *****************************************************************************/
696 697
#define POPUP_BOILERPLATE \
    unsigned int i_last_separator = 0; \
698
    vector<vlc_object_t *> objects; \
699 700 701 702 703 704 705
    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() ); \
706
    p_intf->p_sys->p_popup_menu = NULL; \
707
    i_last_separator = 0;
708

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
709 710 711 712 713 714 715 716 717
void QVLCMenu::PopupMenuControlEntries( QMenu *menu,
                                        intf_thread_t *p_intf,
                                        input_thread_t *p_input )
{
    if( p_input )
    {
        vlc_value_t val;
        var_Get( p_input, "state", &val );
        if( val.i_int == PLAYING_S )
718
            addMIMStaticEntry( p_intf, menu, qtr( "Pause" ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
719
                    ":/pause", SLOT( togglePlayPause() ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
720
        else
721
            addMIMStaticEntry( p_intf, menu, qtr( "Play" ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
722
                    ":/play", SLOT( togglePlayPause() ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
723
    }
724
    else if( THEPL->items.i_size )
725
        addMIMStaticEntry( p_intf, menu, qtr( "Play" ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
726
                ":/play", SLOT( togglePlayPause() ) );
727
    else
728
        addDPStaticEntry( menu, qtr( "Play" ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
729
                ":/play", SLOT( openDialog() ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
730

731
    addMIMStaticEntry( p_intf, menu, qtr( "Stop" ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
732
            ":/stop", SLOT( stop() ) );
733
    addMIMStaticEntry( p_intf, menu, qtr( "Previous" ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
734
            ":/previous", SLOT( prev() ) );
735
    addMIMStaticEntry( p_intf, menu, qtr( "Next" ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
736
            ":/next", SLOT( next() ) );
737
}
738

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
739
void QVLCMenu::PopupMenuStaticEntries( QMenu *menu )
740
{
741
    QMenu *openmenu = new QMenu( qtr( "Open Media" ), menu );
742
    addDPStaticEntry( openmenu, qtr( "&Open File..." ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
743
        ":/file-asym", SLOT( openFileDialog() ) );
744
    addDPStaticEntry( openmenu, qtr( I_OPEN_FOLDER ),
745
        ":/folder-grey", SLOT( PLOpenDir() ) );
746
    addDPStaticEntry( openmenu, qtr( "Open &Disc..." ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
747
        ":/disc", SLOT( openDiscDialog() ) );
748
    addDPStaticEntry( openmenu, qtr( "Open &Network..." ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
749
        ":/network", SLOT( openNetDialog() ) );
750
    addDPStaticEntry( openmenu, qtr( "Open &Capture Device..." ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
751
        ":/capture-card", SLOT( openCaptureDialog() ) );
752 753 754
    menu->addMenu( openmenu );

    menu->addSeparator();
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
755
#if 0
756
    QMenu *helpmenu = HelpMenu( menu );
757 758
    helpmenu->setTitle( qtr( "Help" ) );
    menu->addMenu( helpmenu );
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
759
#endif
760

761
    addDPStaticEntry( menu, qtr( "Quit" ), ":/quit",
762
                      SLOT( quit() ), "Ctrl+Q" );
763
}
Clément Stenac's avatar
Qt4:  
Clément Stenac committed
764

765
/* Video Tracks and Subtitles tracks */
766
void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf )