menus.cpp 42.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 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 118 119 120 121
/***
 * Same for MIM
 ***/
void addMIMStaticEntry( intf_thread_t *p_intf,
                        QMenu *menu,
                        const QString text,
                        const char *icon,
                        const char *member )
{
122
    QAction *action;
123 124
    if( strlen( icon ) > 0 )
    {
125
        action = menu->addAction( text, THEMIM,  member );
126 127 128 129 130 131
        action->setIcon( QIcon( icon ) );
    }
    else
    {
        menu->addAction( text, THEMIM, member );
    }
132
    action->setData( "ignore" );
133 134
}

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

Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
143 144
    QList< QAction* > actions = menu->actions();
    for( int i = 0; i < actions.size(); ++i )
145
    {
146
        actions[i]->setEnabled( actions[i]->data().toString() == "ignore" ||
147
                /* Be careful here, because data("string").toBool is true */
148
                ( enable && (actions[i]->data().toString() == "true" ) ) );
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
    {
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
164 165
        if( !actions[i]->data().toBool() )
            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 266 267 268 269 270 271
#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 ); }

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..." ),
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( "Paste &Location" ),
321
                      NULL, SLOT( openUrlDialog() ), "Ctrl+V" );
322

323
    recentsMenu = new QMenu( qtr( "&Recent Media" ), menu );
Ludovic Fauvet's avatar
Ludovic Fauvet committed
324 325
    updateRecents( p_intf );
    menu->addMenu( recentsMenu );
326 327
    menu->addMenu( SDMenu( p_intf, menu ) );
    menu->addSeparator();
328

329 330 331 332
    addDPStaticEntry( menu, qtr( I_PL_SAVE ), "", SLOT( saveAPlaylist() ),
        "Ctrl+Y" );
    menu->addSeparator();

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

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

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

353
    addDPStaticEntry( menu, qtr( I_MENU_INFO ) , ":/info",
354
        SLOT( mediaInfoDialog() ), "Ctrl+I" );
355
    addDPStaticEntry( menu, qtr( I_MENU_CODECINFO ) ,
356
        ":/info", SLOT( mediaCodecDialog() ), "Ctrl+J" );
357

358
    addDPStaticEntry( menu, qtr( I_MENU_BOOKMARK ),"",
359 360
                      SLOT( bookmarksDialog() ), "Ctrl+B" );
#ifdef ENABLE_VLM
361
    addDPStaticEntry( menu, qtr( I_MENU_VLM ), "", SLOT( vlmDialog() ),
362 363
        "Ctrl+W" );
#endif
364 365 366 367 368

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

369 370
    addDPStaticEntry( menu, qtr( "Plu&gins and extensions" ),
        "", SLOT( pluginDialog() ) );
Clément Stenac's avatar
Clément Stenac committed
371 372
    menu->addSeparator();

373
    addDPStaticEntry( menu, qtr( "&Preferences" ),
374 375
        ":/preferences", SLOT( prefsDialog() ), "Ctrl+P" );

Clément Stenac's avatar
Clément Stenac committed
376 377 378
    return menu;
}

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
379 380 381 382 383
QMenu *QVLCMenu::ToolsMenu( QWidget *parent )
{
    return ToolsMenu( new QMenu( parent ) );
}

384
/**
385
 * View Menu
386
 * Interface Modification
387
 **/
388
QMenu *QVLCMenu::ViewMenu( intf_thread_t *p_intf,
389 390
                            MainInterface *mi,
                            bool with_intf )
391
{
392 393 394 395 396 397 398 399
    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" ) );

400 401 402 403
    /*menu->addSeparator();
    menu->addAction( qtr( "Undock from Interface" ), mi,
                     SLOT( undockPlaylist() ), qtr( "Ctrl+U" ) );*/

404 405
    menu->addSeparator();

406 407
    if( with_intf )
    {
408
        QMenu *intfmenu = InterfacesMenu( p_intf, menu );
409 410 411
        MenuFunc *f = new MenuFunc( intfmenu, 4 );
        CONNECT( intfmenu, aboutToShow(), THEDP->menusUpdateMapper, map() );
        THEDP->menusUpdateMapper->setMapping( intfmenu, f );
412 413
        menu->addSeparator();
    }
414

415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436
    /* Minimal View */
    QAction *action = menu->addAction( qtr( "Mi&nimal View" ), mi,
            SLOT( toggleMinimalView() ), qtr( "Ctrl+H" ) );
    action->setCheckable( true );

    if( mi->getControlsVisibilityStatus() & CONTROLS_VISIBLE )
        action->setChecked( true );
    minimalViewAction = action; /* HACK for minimalView */

    /* FullScreen View */
    action = menu->addAction( qtr( "&Fullscreen Interface" ), mi,
            SLOT( toggleFullScreen() ), QString( "F11" ) );
    fullscreenViewAction = action;
    action->setCheckable( true );

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

437
#if 0 /* For Visualisations. Not yet working */
438 439 440 441
    adv = menu->addAction( qtr( "Visualizations selector" ),
            mi, SLOT( visual() ) );
    adv->setCheckable( true );
    if( visual_selector_enabled ) adv->setChecked( true );
442
#endif
443

444
    menu->addSeparator();
445 446 447
    addDPStaticEntry( menu, qtr( "Customi&ze Interface..." ),
        ":/preferences", SLOT( toolbarDialog() ) );
    menu->addSeparator();
448

449 450 451
    return menu;
}

452 453 454
/**
 * Interface Sub-Menu, to list extras interface and skins
 **/
455 456
QMenu *QVLCMenu::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
{
457
    vector<vlc_object_t *> objects;
458 459
    vector<const char *> varnames;
    varnames.push_back( "intf-add" );
460
    objects.push_back( VLC_OBJECT(p_intf) );
Clément Stenac's avatar
Qt4:  
Clément Stenac committed
461

462
    return Populate( p_intf, current, varnames, objects );
463 464
}

465 466
/**
 * Main Audio Menu
467
 **/
468 469
QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QMenu * current )
{
470
    vector<vlc_object_t *> objects;
471
    vector<const char *> varnames;
472
    aout_instance_t *p_aout;
473 474 475
    input_thread_t *p_input;

    if( current->isEmpty() )
476
    {
477 478 479
        ACT_ADDMENU( current, "audio-es", qtr( "Audio &Track" ) );
        ACT_ADDMENU( current, "audio-channels", qtr( "Audio &Channels" ) );
        ACT_ADDMENU( current, "audio-device", qtr( "Audio &Device" ) );
480
        current->addSeparator();
481

482
        ACT_ADDMENU( current, "visual", qtr( "&Visualizations" ) );
483 484
        current->addSeparator();

485
        QAction *action = current->addAction( qtr( "Increase Volume" ),
486 487 488 489 490
                ActionsManager::getInstance( p_intf ), SLOT( AudioUp() ) );
        action->setData( true );
        action = current->addAction( qtr( "Decrease Volume" ),
                ActionsManager::getInstance( p_intf ), SLOT( AudioDown() ) );
        action->setData( true );
491 492 493
        action = current->addAction( qtr( "Mute" ),
                ActionsManager::getInstance( p_intf ), SLOT( toggleMuteAudio() ) );
        action->setData( true );
494 495
    }

496 497
    p_input = THEMIM->getInput();
    if( p_input )
498
        vlc_object_hold( p_input );
499
    p_aout = THEMIM->getAout();
500
    EnableStaticEntries( current, ( p_aout != NULL ) );
501
    AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
502
    if( p_aout )
503
    {
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
504
        vlc_object_release( p_aout );
505
    }
506 507 508
    if( p_input )
        vlc_object_release( p_input );

509 510 511
    return Populate( p_intf, current, varnames, objects );
}

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
512 513 514 515 516
QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QWidget *parent )
{
    return AudioMenu( p_intf, new QMenu( parent ) );
}

517 518 519 520
/**
 * Main Video Menu
 * Subtitles are part of Video.
 **/
521
QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current )
522
{
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
523
    vout_thread_t *p_vout;
524
    input_thread_t *p_input;
525
    vector<vlc_object_t *> objects;
526 527
    vector<const char *> varnames;

528
    if( current->isEmpty() )
529
    {
530
        ACT_ADDMENU( current, "video-es", qtr( "Video &Track" ) );
531 532 533 534 535

        QAction *action;
        QMenu *submenu = new QMenu( qtr( "&Subtitles Track" ), current );
        action = current->addMenu( submenu );
        action->setData( "spu-es" );
536
        addDPStaticEntry( submenu, qtr( "Open File..." ), "",
537
                          SLOT( loadSubtitlesFile() ) );
538
        submenu->addSeparator();
539
        current->addSeparator();
540

541 542
        ACT_ADDCHECK( current, "fullscreen", qtr( "&Fullscreen" ) );
        ACT_ADDCHECK( current, "video-on-top", qtr( "Always &On Top" ) );
543
#ifdef WIN32
544
        ACT_ADDCHECK( current, "directx-wallpaper", qtr( "DirectX Wallpaper" ) );
545
#endif
546
        ACT_ADD( current, "video-snapshot", qtr( "Sna&pshot" ) );
547

548 549
        current->addSeparator();

550 551 552 553 554
        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" ) );
555
        ACT_ADDMENU( current, "postprocess", qtr( "&Post processing" ) );
556
    }
557

558 559
    p_input = THEMIM->getInput();
    if( p_input )
560
        vlc_object_hold( p_input );
561

562
    p_vout = THEMIM->getVout();
563
    VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
564

565 566
    if( p_vout )
        vlc_object_release( p_vout );
567

568 569 570
    if( p_input )
        vlc_object_release( p_input );

571
    return Populate( p_intf, current, varnames, objects );
572 573
}

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
574 575 576 577 578
QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QWidget *parent )
{
    return VideoMenu( p_intf, new QMenu( parent ) );
}

579 580 581 582
/**
 * Navigation Menu
 * For DVD, MP4, MOV and other chapter based format
 **/
583
QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *menu )
584
{
585
    QAction *action;
586

587 588 589 590 591 592
    QMenu *submenu = new QMenu( qtr( "&Bookmarks" ), menu );
    addDPStaticEntry( submenu, qtr( "Manage &bookmarks" ), "",
                      SLOT( bookmarksDialog() ) );
    submenu->addSeparator();
    action = menu->addMenu( submenu );
    action->setData( "bookmark" );
593

594 595 596 597
    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" ) );
598

599 600
    menu->addSeparator();
    PopupMenuPlaylistControlEntries( menu, p_intf );
601
    PopupMenuControlEntries( menu, p_intf );
602 603 604 605 606 607

    return menu;
}

QMenu *QVLCMenu::RebuildNavigMenu( intf_thread_t *p_intf, QMenu *menu )
{
608
    /* */
609 610 611 612
    input_thread_t *p_object;
    vector<vlc_object_t *> objects;
    vector<const char *> varnames;

613
    /* Get the input and hold it */
614
    p_object = THEMIM->getInput();
615 616
    if( p_object )
        vlc_object_hold( p_object );
617

618
    InputAutoMenuBuilder( p_object, objects, varnames );
619

620 621
    menu->addSeparator();

622
    /* Title and so on */
623 624 625 626
    PUSH_VAR( "prev-title" );
    PUSH_VAR( "next-title" );
    PUSH_VAR( "prev-chapter" );
    PUSH_VAR( "next-chapter" );
627

628
    if( p_object )
629
        vlc_object_release( p_object );
630

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

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

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

648
    char **ppsz_longnames;
649
    char **ppsz_names = vlc_sd_GetNames( &ppsz_longnames );
650 651 652
    if( !ppsz_names )
        return menu;

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

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

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

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

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

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

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

    /* Faster/Slower */
739
    action = menu->addAction( qtr( "&Faster" ), THEMIM->getIM(),
740
                              SLOT( faster() ) );
741
    action->setIcon( QIcon( ":/faster") );
742 743
    action->setData( true );

744
    action = menu->addAction( qtr( "N&ormal Speed" ), THEMIM->getIM(),
745 746 747
                              SLOT( normalRate() ) );
    action->setData( true );

748
    action = menu->addAction( qtr( "Slo&wer" ), THEMIM->getIM(),
749
                              SLOT( slower() ) );
750
    action->setIcon( QIcon( ":/slower") );
751
    action->setData( true );
752 753

    menu->addSeparator();
754

755
    action = menu->addAction( qtr( "&Jump Forward" ), THEMIM->getIM(),
756 757
             SLOT( jumpFwd() ) );
    action->setIcon( QIcon( ":/skip_fw") );
758 759
    action->setData( true );

760
    action = menu->addAction( qtr( "Jump Bac&kward" ), THEMIM->getIM(),
761 762
             SLOT( jumpBwd() ) );
    action->setIcon( QIcon( ":/skip_back") );
763 764 765 766
    action->setData( true );
    addDPStaticEntry( menu, qtr( I_MENU_GOTOTIME ),"",
                      SLOT( gotoTimeDialog() ), "Ctrl+T" );
    menu->addSeparator();
767 768 769 770
}


void QVLCMenu::PopupMenuPlaylistControlEntries( QMenu *menu,
771
                                                intf_thread_t *p_intf )
772
{
773
    addMIMStaticEntry( p_intf, menu, qtr( "&Stop" ), ":/stop", SLOT( stop() ) );
774

775
    /* Next / Previous */
776
    addMIMStaticEntry( p_intf, menu, qtr( "Pre&vious" ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
777
            ":/previous", SLOT( prev() ) );
778
    addMIMStaticEntry( p_intf, menu, qtr( "Ne&xt" ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
779
            ":/next", SLOT( next() ) );
780
    menu->addSeparator();
781
}
782

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
783
void QVLCMenu::PopupMenuStaticEntries( QMenu *menu )
784
{