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 79
/* 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;

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

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

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

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

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

146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
/***
 * 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 );
    }
}

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

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

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

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

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

211
    /* Special case for postproc */
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
212
    // FIXME
213
    if( p_object )
214
    {
215 216 217 218 219 220
        /* p_object is the vout, so the decoder is our parent and the
         * postproc filter one of the decoder's children */
        vlc_object_t *p_dec = (vlc_object_t *)
                              vlc_object_find( p_object, VLC_OBJECT_DECODER,
                                               FIND_PARENT );
        if( p_dec )
221
        {
222 223 224 225 226
            vlc_object_t *p_pp = (vlc_object_t *)
                                 vlc_object_find_name( p_dec, "postproc",
                                                       FIND_CHILD );
            if( p_pp )
            {
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
227
                vlc_object_t *p_object = p_pp;
228 229 230 231 232
                PUSH_VAR( "postproc-q" );
                vlc_object_release( p_pp );
            }

            vlc_object_release( p_dec );
233
        }
234 235 236 237
    }
    return VLC_SUCCESS;
}

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

250 251
static QAction * FindActionWithVar( QMenu *menu, const char *psz_var )
{
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
252 253
    QList< QAction* > actions = menu->actions();
    for( int i = 0; i < actions.size(); ++i )
254
    {
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
255 256
        if( actions[i]->data().toString() == psz_var )
            return actions[i];
257 258 259 260
    }
    return NULL;
}

261 262
/*****************************************************************************
 * All normal menus
263
 * Simple Code
264 265 266
 *****************************************************************************/

#define BAR_ADD( func, title ) { \
267
    QMenu *_menu = func; _menu->setTitle( title ); bar->addMenu( _menu ); }
268 269

#define BAR_DADD( func, title, id ) { \
270 271 272 273 274 275 276 277
    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 ); }
278

279 280 281
/**
 * Main Menu Bar Creation
 **/
282 283 284
void QVLCMenu::createMenuBar( MainInterface *mi,
                              intf_thread_t *p_intf,
                              bool visual_selector_enabled )
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
285
/* FIXME remove this visual dependency */
Clément Stenac's avatar
Qt4:  
Clément Stenac committed
286
{
287 288 289
    /* QMainWindows->menuBar()
       gives the QProcess::destroyed timeout issue on Cleanlooks style with
       setDesktopAware set to false */
290
    QMenuBar *bar = mi->menuBar();
Ludovic Fauvet's avatar
Ludovic Fauvet committed
291
    BAR_ADD( FileMenu( p_intf ), qtr( "&Media" ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
292 293 294

    BAR_DADD( AudioMenu( p_intf, NULL ), qtr( "&Audio" ), 1 );
    BAR_DADD( VideoMenu( p_intf, NULL ), qtr( "&Video" ), 2 );
295
    BAR_DADD( NavigMenu( p_intf, NULL ), qtr( "P&layback" ), 3 );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
296

297
    BAR_ADD( ToolsMenu( NULL ), qtr( "&Tools" ) );
298 299
    BAR_ADD( ViewMenu( p_intf, NULL, mi, visual_selector_enabled, true ),
             qtr( "V&iew" ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
300

301
    BAR_ADD( HelpMenu( NULL ), qtr( "&Help" ) );
302
}
303 304
#undef BAR_ADD
#undef BAR_DADD
305 306

/**
307
 * Media ( File ) Menu
308 309
 * Opening, streaming and quit
 **/
Ludovic Fauvet's avatar
Ludovic Fauvet committed
310
QMenu *QVLCMenu::FileMenu( intf_thread_t *p_intf )
311 312
{
    QMenu *menu = new QMenu();
313

314
    addDPStaticEntry( menu, qtr( "&Open File..." ),
315
        ":/file-asym", SLOT( simpleOpenDialog() ), "Ctrl+O" );
316
    addDPStaticEntry( menu, qtr( "Advanced Open File..." ),
317
        ":/file-asym", SLOT( openFileDialog() ), "Ctrl+Shift+O" );
318
    addDPStaticEntry( menu, qtr( I_OPEN_FOLDER ),
319
        ":/folder-grey", SLOT( PLOpenDir() ), "Ctrl+F" );
320
    addDPStaticEntry( menu, qtr( "Open &Disc..." ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
321
        ":/disc", SLOT( openDiscDialog() ), "Ctrl+D" );
322
    addDPStaticEntry( menu, qtr( "Open &Network..." ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
323
        ":/network", SLOT( openNetDialog() ), "Ctrl+N" );
324
    addDPStaticEntry( menu, qtr( "Open &Capture Device..." ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
325
        ":/capture-card", SLOT( openCaptureDialog() ),
326
        "Ctrl+C" );
327

328
    menu->addSeparator();
329 330
    addDPStaticEntry( menu, qtr( "Paste &MRL" ),
                      NULL, SLOT( openUrlDialog() ), "Ctrl+V" );
331

332 333 334 335 336 337 338
    addDPStaticEntry( menu, qtr( I_PL_LOAD ), "", SLOT( openAPlaylist() ),
        "Ctrl+X" );
    addDPStaticEntry( menu, qtr( I_PL_SAVE ), "", SLOT( saveAPlaylist() ),
        "Ctrl+Y" );

    menu->addSeparator();

339
    recentsMenu = new QMenu( qtr( "Recently &Played" ), menu );
Ludovic Fauvet's avatar
Ludovic Fauvet committed
340 341
    updateRecents( p_intf );
    menu->addMenu( recentsMenu );
342
    menu->addSeparator();
343

344
    addDPStaticEntry( menu, qtr( "Conve&rt / Save..." ), "",
345
        SLOT( openAndTranscodingDialogs() ), "Ctrl+R" );
346
    addDPStaticEntry( menu, qtr( "&Streaming..." ),
347
        ":/stream", SLOT( openAndStreamingDialogs() ),
348
        "Ctrl+S" );
349
    menu->addSeparator();
350

351
    addDPStaticEntry( menu, qtr( "&Quit" ) ,
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
352
        ":/quit", SLOT( quit() ), "Ctrl+Q" );
353 354 355
    return menu;
}

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
356
/* Playlist/MediaLibrary Control */
357
QMenu *QVLCMenu::ToolsMenu( QMenu *parent )
Clément Stenac's avatar
Clément Stenac committed
358
{
359 360 361 362 363
    QMenu *menu;
    if( parent == NULL )
        menu = new QMenu();
    else
        menu = parent;
364
    addDPStaticEntry( menu, qtr( I_MENU_EXT ), ":/settings",
365
            SLOT( extendedDialog() ), "Ctrl+E" );
366

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

372
    addDPStaticEntry( menu, qtr( I_MENU_BOOKMARK ),"",
373 374
                      SLOT( bookmarksDialog() ), "Ctrl+B" );
#ifdef ENABLE_VLM
375
    addDPStaticEntry( menu, qtr( I_MENU_VLM ), "", SLOT( vlmDialog() ),
376 377
        "Ctrl+W" );
#endif
378 379 380 381 382

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

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

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

Clément Stenac's avatar
Clément Stenac committed
390 391 392
    return menu;
}

393
/**
394
 * View Menu
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
395
 * This menu can be an interface menu but also a right click menu.
396
 **/
397
QMenu *QVLCMenu::ViewMenu( intf_thread_t *p_intf,
398
                            QMenu *current,
399 400 401
                            MainInterface *mi,
                            bool visual_selector_enabled,
                            bool with_intf )
402
{
403
    QMenu *menu = new QMenu( current );
404
    QAction *act;
405 406
    if( mi )
    {
407
        act = menu->addAction( QIcon( ":/playlist_menu" ),
408
                               qtr( "Play&list" ), mi,
409
                               SLOT( togglePlaylist() ), qtr( "Ctrl+L" ) );
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
410
        act->setData( true );
411
    }
412
    act = menu->addMenu( SDMenu( p_intf ) );
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
413
    act->setData( true );
414 415 416 417
    /*menu->addSeparator();
    menu->addAction( qtr( "Undock from Interface" ), mi,
                     SLOT( undockPlaylist() ), qtr( "Ctrl+U" ) );*/

418 419 420

    menu->addSeparator();

421 422
    if( with_intf )
    {
423
        QMenu *intfmenu = InterfacesMenu( p_intf, menu );
424 425 426
        MenuFunc *f = new MenuFunc( intfmenu, 4 );
        CONNECT( intfmenu, aboutToShow(), THEDP->menusUpdateMapper, map() );
        THEDP->menusUpdateMapper->setMapping( intfmenu, f );
427 428
        menu->addSeparator();
    }
Clément Stenac's avatar
Clément Stenac committed
429 430
    if( mi )
    {
431
        /* Minimal View */
432
        QAction *action = menu->addAction( qtr( "Mi&nimal View" ), mi,
433
                                SLOT( toggleMinimalView() ), qtr( "Ctrl+H" ) );
434
        action->setCheckable( true );
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
435
        action->setData( true );
436
        if( mi->getControlsVisibilityStatus() & CONTROLS_VISIBLE )
437
            action->setChecked( true );
438
        minimalViewAction = action; /* HACK for minimalView */
439

440
        /* FullScreen View */
441
        action = menu->addAction( qtr( "&Fullscreen Interface" ), mi,
442
                                  SLOT( toggleFullScreen() ), QString( "F11" ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
443
        action->setCheckable( true );
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
444
        action->setData( true );
445

446
        /* Advanced Controls */
447
        action = menu->addAction( qtr( "&Advanced Controls" ), mi,
448
                                  SLOT( toggleAdvanced() ) );
449
        action->setCheckable( true );
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
450
        action->setData( true );
451 452
        if( mi->getControlsVisibilityStatus() & CONTROLS_ADVANCED )
            action->setChecked( true );
453
#if 0 /* For Visualisations. Not yet working */
454
        adv = menu->addAction( qtr( "Visualizations selector" ),
455
                mi, SLOT( visual() ) );
456 457
        adv->setCheckable( true );
        if( visual_selector_enabled ) adv->setChecked( true );
458
#endif
Clément Stenac's avatar
Clément Stenac committed
459
    }
460

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

466 467 468
    return menu;
}

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

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

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

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
493
    if( !current ) current = new QMenu();
494

495
    if( current->isEmpty() )
496
    {
497 498 499 500 501 502 503 504 505 506 507
        QAction *action = current->addAction( qtr( "Mute Audio" ),
                ActionsManager::getInstance( p_intf ), SLOT( toggleMuteAudio() ) );
        action->setData( true );
        action = current->addAction( qtr( "Increase Volume" ),
                ActionsManager::getInstance( p_intf ), SLOT( AudioUp() ) );
        action->setData( true );
        action = current->addAction( qtr( "Decrease Volume" ),
                ActionsManager::getInstance( p_intf ), SLOT( AudioDown() ) );
        action->setData( true );

        current->addSeparator();
508 509
        ACT_ADD( current, "visual", qtr( "&Visualizations" ) );
        current->addSeparator();
510 511 512
        ACT_ADD( current, "audio-es", qtr( "Audio &Track" ) );
        ACT_ADD( current, "audio-device", qtr( "Audio &Device" ) );
        ACT_ADD( current, "audio-channels", qtr( "Audio &Channels" ) );
513 514
    }

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

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

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

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
542
    if( !current ) current = new QMenu();
543 544

    if( current->isEmpty() )
545
    {
546
        ACT_ADD( current, "video-es", qtr( "Video &Track" ) );
547 548 549 550 551

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

556
        ACT_ADD( current, "fullscreen", qtr( "&Fullscreen" ) );
557 558 559 560 561
        ACT_ADD( current, "zoom", qtr( "&Zoom" ) );
        ACT_ADD( current, "deinterlace", qtr( "&Deinterlace" ) );
        ACT_ADD( current, "aspect-ratio", qtr( "&Aspect Ratio" ) );
        ACT_ADD( current, "crop", qtr( "&Crop" ) );
        ACT_ADD( current, "video-on-top", qtr( "Always &On Top" ) );
562 563 564
#ifdef WIN32
        ACT_ADD( current, "directx-wallpaper", qtr( "DirectX Wallpaper" ) );
#endif
565
        ACT_ADD( current, "video-snapshot", qtr( "Sna&pshot" ) );
566
        ACT_ADD( current, "postproc-q", qtr( "Post processing" ) );
567
    }
568

569 570
    p_input = THEMIM->getInput();
    if( p_input )
571
        vlc_object_hold( p_input );
572

573
    p_vout = THEMIM->getVout();
574 575
    VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
    EnableStaticEntries( current, ( p_vout != NULL ) );
576
    if( p_vout )
577
    {
578
        vlc_object_release( p_vout );
579
    }
580 581 582
    if( p_input )
        vlc_object_release( p_input );

583
    return Populate( p_intf, current, varnames, objects );
584 585
}

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
{
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
592
    if( !menu ) menu = new QMenu();
593 594 595

    if( menu->isEmpty() )
    {
596
        addDPStaticEntry( menu, qtr( I_MENU_GOTOTIME ),"",
597 598
                          SLOT( gotoTimeDialog() ), "Ctrl+T" );
        menu->addSeparator();
599 600

        ACT_ADD( menu, "bookmark", qtr( "&Bookmarks" ) );
601
        ACT_ADD( menu, "title", qtr( "T&itle" ) );
602 603 604
        ACT_ADD( menu, "chapter", qtr( "&Chapter" ) );
        ACT_ADD( menu, "program", qtr( "&Program" ) );
        ACT_ADD( menu, "navigation", qtr( "&Navigation" ) );
605 606
    }

607 608 609 610 611
    input_thread_t *p_object;
    vector<vlc_object_t *> objects;
    vector<const char *> varnames;

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

627
/**
628
 * Service Discovery SubMenu
629
 **/
Clément Stenac's avatar
Clément Stenac committed
630 631 632
QMenu *QVLCMenu::SDMenu( intf_thread_t *p_intf )
{
    QMenu *menu = new QMenu();
633
    menu->setTitle( qtr( I_PL_SD ) );
634
    char **ppsz_longnames;
635
    char **ppsz_names = vlc_sd_GetNames( &ppsz_longnames );
636 637 638
    if( !ppsz_names )
        return menu;

639 640
    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
641
    {
642
        QAction *a = new QAction( qfu( *ppsz_longname ), menu );
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
643
        a->setCheckable( true );
644
        if( playlist_IsServicesDiscoveryLoaded( THEPL, *ppsz_name ) )
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
645 646
            a->setChecked( true );
        CONNECT( a , triggered(), THEDP->SDMapper, map() );
647
        THEDP->SDMapper->setMapping( a, QString( *ppsz_name ) );
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
648
        menu->addAction( a );
649

650
        if( !strcmp( *ppsz_name, "podcast" ) )
651
        {
Christophe Mutricy's avatar
Christophe Mutricy committed
652
            QAction *b = new QAction( qtr( "Configure podcasts..." ), menu );
653 654 655 656
            //b->setEnabled( a->isChecked() );
            menu->addAction( b );
            CONNECT( b, triggered(), THEDP, podcastConfigureDialog() );
        }
657 658
        free( *ppsz_name );
        free( *ppsz_longname );
Clément Stenac's avatar
Clément Stenac committed
659
    }
660 661
    free( ppsz_names );
    free( ppsz_longnames );
Clément Stenac's avatar
Clément Stenac committed
662 663
    return menu;
}
664 665 666
/**
 * Help/About Menu
**/
667
QMenu *QVLCMenu::HelpMenu( QMenu *current )
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
668
{
669
    QMenu *menu = new QMenu( current );
670
    addDPStaticEntry( menu, qtr( "&Help..." ) ,
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
671
        ":/help", SLOT( helpDialog() ), "F1" );
672
#ifdef UPDATE_CHECK
673 674
    addDPStaticEntry( menu, qtr( "Check for &Updates..." ) , "",
                      SLOT( updateDialog() ) );
675
#endif
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
676
    menu->addSeparator();
677
    addDPStaticEntry( menu, qtr( I_MENU_ABOUT ), ":/info",
678
            SLOT( aboutDialog() ), "Shift+F1" );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
679 680 681
    return menu;
}

682
/*****************************************************************************
683
 * Popup menus - Right Click menus                                           *
684
 *****************************************************************************/
685 686
#define POPUP_BOILERPLATE \
    unsigned int i_last_separator = 0; \
687
    vector<vlc_object_t *> objects; \
688 689 690 691 692 693 694
    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() ); \
695
    p_intf->p_sys->p_popup_menu = NULL; \
696
    i_last_separator = 0;
697

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
698 699 700 701 702 703 704 705 706
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 )
707
            addMIMStaticEntry( p_intf, menu, qtr( "Pause" ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
708
                    ":/pause", SLOT( togglePlayPause() ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
709
        else
710
            addMIMStaticEntry( p_intf, menu, qtr( "Play" ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
711
                    ":/play", SLOT( togglePlayPause() ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
712
    }
713
    else if( THEPL->items.i_size )
714
        addMIMStaticEntry( p_intf, menu, qtr( "Play" ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
715
                ":/play", SLOT( togglePlayPause() ) );
716
    else
717
        addDPStaticEntry( menu, qtr( "Play" ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
718
                ":/play", SLOT( openDialog() ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
719

720
    addMIMStaticEntry( p_intf, menu, qtr( "Stop" ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
721
            ":/stop", SLOT( stop() ) );
722
    addMIMStaticEntry( p_intf, menu, qtr( "Previous" ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
723
            ":/previous", SLOT( prev() ) );
724
    addMIMStaticEntry( p_intf, menu, qtr( "Next" ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
725
            ":/next", SLOT( next() ) );
726
}
727

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
728
void QVLCMenu::PopupMenuStaticEntries( QMenu *menu )
729
{
730
    QMenu *openmenu = new QMenu( qtr( "Open Media" ), menu );
731
    addDPStaticEntry( openmenu, qtr( "&Open File..." ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
732
        ":/file-asym", SLOT( openFileDialog() ) );
733
    addDPStaticEntry( openmenu, qtr( I_OPEN_FOLDER ),
734
        ":/folder-grey", SLOT( PLOpenDir() ) );
735
    addDPStaticEntry( openmenu, qtr( "Open &Disc..." ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
736
        ":/disc", SLOT( openDiscDialog() ) );
737
    addDPStaticEntry( openmenu, qtr( "Open &Network..." ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
738
        ":/network", SLOT( openNetDialog() ) );
739
    addDPStaticEntry( openmenu, qtr( "Open &Capture Device..." ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
740
        ":/capture-card", SLOT( openCaptureDialog() ) );
741 742 743
    menu->addMenu( openmenu );

    menu->addSeparator();
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
744
#if 0
745
    QMenu *helpmenu = HelpMenu( menu );
746 747
    helpmenu->setTitle( qtr( "Help" ) );
    menu->addMenu( helpmenu );