menus.cpp 42.1 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 122 123 124 125 126 127 128 129 130 131 132
/***
 * 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 );
    }
}

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

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

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

157
    int i_ret = 0;
158

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

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

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

#define PUSH_INPUTVAR( var ) varnames.push_back( var ); \
191
    objects.push_back( VLC_OBJECT(p_input) );
192 193

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

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

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

229 230 231
    return VLC_SUCCESS;
}

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

244 245
/*****************************************************************************
 * All normal menus
246
 * Simple Code
247 248 249
 *****************************************************************************/

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

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

262 263 264 265 266 267 268 269
#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 ); }

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

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

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

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

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

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

317
    menu->addSeparator();
318 319
    addDPStaticEntry( menu, qtr( "Paste &MRL" ),
                      NULL, SLOT( openUrlDialog() ), "Ctrl+V" );
320

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

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

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

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

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

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

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

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

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

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

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

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

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

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

403 404
    menu->addSeparator();

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

414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435
    /* 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 );

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

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

448 449 450
    return menu;
}

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

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

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

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

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

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

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

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

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

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

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

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

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

547 548
        current->addSeparator();

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

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

561
    p_vout = THEMIM->getVout();
562 563
    VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
    EnableStaticEntries( current, ( p_vout != NULL ) );
564
    if( p_vout )
565
    {
566
        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 601 602 603 604 605 606 607
    menu->addSeparator();
    PopupMenuControlEntries( menu, p_intf );//, THEMIM->getInput() );
    PopupMenuPlaylistControlEntries( menu, p_intf );

    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

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
631
    return Populate( p_intf, menu, varnames, objects );
632
}
633

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

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

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

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

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

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

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

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

730 731 732 733 734
}

void QVLCMenu::PopupMenuControlEntries( QMenu *menu, intf_thread_t *p_intf )
{
    QAction *action;
735
    /* Stop */
736
    addMIMStaticEntry( p_intf, menu, qtr( "Stop" ), ":/stop", SLOT( stop() ) );
737 738 739 740 741 742 743

    /* Faster/Slower */
    action = menu->addAction( qtr( "Faster" ), THEMIM->getIM(), SLOT( faster() ) );
    action->setIcon( QIcon( ":/faster") );
    menu->addAction( qtr( "Normal Speed" ), THEMIM->getIM(), SLOT( normalRate() ) );
    action = menu->addAction( qtr( "Slower" ), THEMIM->getIM(), SLOT( slower() ) );
    action->setIcon( QIcon( ":/slower") );
744 745 746 747 748 749 750 751

    menu->addSeparator();
    action = menu->addAction( qtr( "Jump Forward" ), THEMIM->getIM(),
             SLOT( jumpFwd() ) );
    action->setIcon( QIcon( ":/skip_fw") );
    action = menu->addAction( qtr( "Jump Backward" ), THEMIM->getIM(),
             SLOT( jumpBwd() ) );
    action->setIcon( QIcon( ":/skip_back") );
752 753 754 755
}


void QVLCMenu::PopupMenuPlaylistControlEntries( QMenu *menu,
756
                                        intf_thread_t *p_intf )
757
{
758 759 760 761
    addDPStaticEntry( menu, qtr( I_MENU_GOTOTIME ),"",
                      SLOT( gotoTimeDialog() ), "Ctrl+T" );
    menu->addSeparator();

762
    /* Next / Previous */
763
    addMIMStaticEntry( p_intf, menu, qtr( "Previous" ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
764
            ":/previous", SLOT( prev() ) );
765
    addMIMStaticEntry( p_intf, menu, qtr( "Next" ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
766
            ":/next", SLOT( next() ) );
767
}
768

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
769
void QVLCMenu::PopupMenuStaticEntries( QMenu *menu )
770
{
771
    QMenu *openmenu = new QMenu( qtr( "Open Media" ), menu );
772
    addDPStaticEntry( openmenu, qtr( "&Open File..." ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
773
        ":/file-asym", SLOT( openFileDialog() ) );
774
    addDPStaticEntry( openmenu, qtr( I_OPEN_FOLDER ),
775
        ":/folder-grey", SLOT( PLOpenDir() ) );
776
    addDPStaticEntry( openmenu, qtr( "Open &Disc..." ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
777
        ":/disc", SLOT( openDiscDialog() ) );
778
    addDPStaticEntry( openmenu, qtr( "Open &Network..." ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
779
        ":/network", SLOT( openNetDialog() ) );
780
    addDPStaticEntry( openmenu, qtr( "Open &Capture Device..." ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
781
        ":/capture-card", SLOT( openCaptureDialog() ) );
782 783 784
    menu->addMenu( openmenu );

    menu->addSeparator();
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
785
#if 0
786
    QMenu *helpmenu = HelpMenu( menu );
787 788
    helpmenu->setTitle( qtr( "Help" ) );
    menu->addMenu( helpmenu );
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
789
#endif
790

791
    addDPStaticEntry( menu, qtr( "Quit" ), ":/quit",
792
                      SLOT( quit() ), "Ctrl+Q" );
793
}
Clément Stenac's avatar
Qt4:  
Clément Stenac committed
794

795
/* Video Tracks and Subtitles tracks */
796
void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf )
797 798 799 800
{
    POPUP_BOILERPLATE;
    if( p_input )
    {
801
        vlc_object_hold( p_input );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed