menus.cpp 39.8 KB
Newer Older
1 2 3
/*****************************************************************************
 * menus.cpp : Qt menus
 *****************************************************************************
4
 * Copyright © 2006-2008 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_common.h>
35

36
#include <vlc_intf_strings.h>
37

38
#include "main_interface.hpp"
Clément Stenac's avatar
Clément Stenac committed
39 40 41 42
#include "menus.hpp"
#include "dialogs_provider.hpp"
#include "input_manager.hpp"

43 44 45 46 47 48 49
#include <QMenu>
#include <QMenuBar>
#include <QAction>
#include <QActionGroup>
#include <QSignalMapper>
#include <QSystemTrayIcon>

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


  */

66 67 68 69 70 71 72 73 74
enum
{
    ITEM_NORMAL,
    ITEM_CHECK,
    ITEM_RADIO
};

static QActionGroup *currentGroup;

75 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
// Add static entries to menus
80 81
void addDPStaticEntry( QMenu *menu,
                       const QString text,
82 83
                       const char *help,
                       const char *icon,
84
                       const char *member,
85
                       const char *shortcut = NULL )
86
{
87
    QAction *action = NULL;
88 89 90
    if( !EMPTY_STR( icon ) > 0 )
    {
        if( !EMPTY_STR( shortcut ) > 0 )
91 92
            action = menu->addAction( QIcon( icon ), text, THEDP,
                                      member, qtr( shortcut ) );
93
        else
94
            action = menu->addAction( QIcon( icon ), text, THEDP, member );
95 96 97 98
    }
    else
    {
        if( !EMPTY_STR( shortcut ) > 0 )
99
            action = menu->addAction( text, THEDP, member, qtr( shortcut ) );
100
        else
101
            action = menu->addAction( text, THEDP, member );
102
    }
103
    action->setData( "_static_" );
104
}
105 106

void addMIMStaticEntry( intf_thread_t *p_intf,
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
107 108
                        QMenu *menu,
                        const QString text,
109 110
                        const char *help,
                        const char *icon,
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
111
                        const char *member )
112 113 114
{
    if( strlen( icon ) > 0 )
    {
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
115
        QAction *action = menu->addAction( text, THEMIM,  member );
116 117 118 119
        action->setIcon( QIcon( icon ) );
    }
    else
    {
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
120
        menu->addAction( text, THEMIM, member );
121
    }
122
}
123

124 125 126 127 128 129
void EnableDPStaticEntries( QMenu *menu, bool enable = true )
{
    if( !menu )
        return;

    QAction *action;
130
    foreach( action, menu->actions() )
131 132 133 134 135 136
    {
        if( action->data().toString() == "_static_" )
            action->setEnabled( enable );
    }
}

137 138 139 140 141 142 143 144 145
/**
 * \return Number of static entries
 */
int DeleteNonStaticEntries( QMenu *menu )
{
    int i_ret = 0;
    QAction *action;
    if( !menu )
        return VLC_EGENERIC;
146
    foreach( action, menu->actions() )
147 148 149 150 151 152 153 154
    {
        if( action->data().toString() != "_static_" )
            delete action;
        else
            i_ret++;
    }
}

155
/*****************************************************************************
156
 * Definitions of variables for the dynamic menus
157
 *****************************************************************************/
158
#define PUSH_VAR( var ) varnames.push_back( var ); \
159 160 161 162
    objects.push_back( p_object ? p_object->i_object_id : 0 )

#define PUSH_INPUTVAR( var ) varnames.push_back( var ); \
    objects.push_back( p_input ? p_input->i_object_id : 0 );
163 164

#define PUSH_SEPARATOR if( objects.size() != i_last_separator ) { \
165
    objects.push_back( 0 ); varnames.push_back( "" ); \
166
    i_last_separator = objects.size(); }
167 168

static int InputAutoMenuBuilder( vlc_object_t *p_object,
169
        vector<int> &objects,
170
        vector<const char *> &varnames )
171
{
172
    PUSH_VAR( "bookmark" );
173
    PUSH_VAR( "title" );
174
    PUSH_VAR( "chapter" );
175 176 177 178 179 180
    PUSH_VAR( "program" );
    PUSH_VAR( "navigation" );
    PUSH_VAR( "dvd_menus" );
    return VLC_SUCCESS;
}

Clément Stenac's avatar
Qt4:  
Clément Stenac committed
181
static int VideoAutoMenuBuilder( vlc_object_t *p_object,
182
        input_thread_t *p_input,
183
        vector<int> &objects,
184
        vector<const char *> &varnames )
185
{
186 187
    PUSH_INPUTVAR( "video-es" );
    PUSH_INPUTVAR( "spu-es" );
188 189 190 191 192 193 194 195 196
    PUSH_VAR( "fullscreen" );
    PUSH_VAR( "zoom" );
    PUSH_VAR( "deinterlace" );
    PUSH_VAR( "aspect-ratio" );
    PUSH_VAR( "crop" );
    PUSH_VAR( "video-on-top" );
    PUSH_VAR( "directx-wallpaper" );
    PUSH_VAR( "video-snapshot" );

197
    if( p_object )
198
    {
199 200 201 202 203 204 205 206 207
        vlc_object_t *p_dec_obj = ( vlc_object_t * )vlc_object_find( p_object,
                VLC_OBJECT_DECODER,
                FIND_PARENT );
        if( p_dec_obj )
        {
            vlc_object_t *p_object = p_dec_obj;
            PUSH_VAR( "ffmpeg-pp-q" );
            vlc_object_release( p_dec_obj );
        }
208 209 210 211 212
    }
    return VLC_SUCCESS;
}

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

224 225 226
static QAction * FindActionWithVar( QMenu *menu, const char *psz_var )
{
    QAction *action;
227
    foreach( action, menu->actions() )
228 229 230 231 232 233 234 235 236 237
    {
        if( action->data().toString() == psz_var )
            return action;
    }
    return NULL;
}

static QAction * FindActionWithText( QMenu *menu, QString &text )
{
    QAction *action;
238
    foreach( action, menu->actions() )
239 240 241 242 243 244 245
    {
        if( action->text() == text )
            return action;
    }
    return NULL;
}

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
/**
 * Main Menu Bar Creation
 **/
267 268 269
void QVLCMenu::createMenuBar( MainInterface *mi,
                              intf_thread_t *p_intf,
                              bool visual_selector_enabled )
Clément Stenac's avatar
Qt4:  
Clément Stenac committed
270
{
271 272 273
    /* QMainWindows->menuBar()
       gives the QProcess::destroyed timeout issue on Cleanlooks style with
       setDesktopAware set to false */
274
    QMenuBar *bar = mi->menuBar();
275
    BAR_ADD( FileMenu(), qtr( "&Media" ) );
276
    BAR_ADD( PlaylistMenu( p_intf, mi ), qtr( "&Playlist" ) );
277
    BAR_ADD( ToolsMenu( p_intf, NULL, mi, visual_selector_enabled, true ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
278
             qtr( "&Tools" ) );
279 280
    BAR_DADD( AudioMenu( p_intf, NULL ), qtr( "&Audio" ), 1 );
    BAR_DADD( VideoMenu( p_intf, NULL ), qtr( "&Video" ), 2 );
281
    BAR_DADD( NavigMenu( p_intf, NULL ), qtr( "&Playback" ), 3 );
282
    BAR_ADD( HelpMenu( NULL ), qtr( "&Help" ) );
283
}
284 285
#undef BAR_ADD
#undef BAR_DADD
286 287

/**
288
 * Media ( File ) Menu
289 290
 * Opening, streaming and quit
 **/
291 292 293
QMenu *QVLCMenu::FileMenu()
{
    QMenu *menu = new QMenu();
294

295
    addDPStaticEntry( menu, qtr( "&Open File..." ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
296
        ":/file-asym", SLOT( openFileDialog() ), "Ctrl+O" );
297
    addDPStaticEntry( menu, qtr( I_OPEN_FOLDER ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
298
        ":/folder-grey", SLOT( PLAppendDir() ), "Ctrl+F" );
299
    addDPStaticEntry( menu, qtr( "Open &Disc..." ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
300
        ":/disc", SLOT( openDiscDialog() ), "Ctrl+D" );
301
    addDPStaticEntry( menu, qtr( "Open &Network..." ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
302
        ":/network", SLOT( openNetDialog() ), "Ctrl+N" );
303
    addDPStaticEntry( menu, qtr( "Open &Capture Device..." ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
304
        ":/capture-card", SLOT( openCaptureDialog() ),
305
        "Ctrl+C" );
306
    menu->addSeparator();
307

308
    addDPStaticEntry( menu, qtr( "&Streaming..." ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
309
        ":/stream", SLOT( openThenStreamingDialogs() ),
310 311 312
        "Ctrl+S" );
    addDPStaticEntry( menu, qtr( "Conve&rt / Save..." ), "", "",
        SLOT( openThenTranscodingDialogs() ), "Ctrl+R" );
313
    menu->addSeparator();
314 315

    addDPStaticEntry( menu, qtr( "&Quit" ) , "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
316
        ":/quit", SLOT( quit() ), "Ctrl+Q" );
317 318 319
    return menu;
}

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
320
/* Playlist/MediaLibrary Control */
321
QMenu *QVLCMenu::PlaylistMenu( intf_thread_t *p_intf, MainInterface *mi )
Clément Stenac's avatar
Clément Stenac committed
322 323 324
{
    QMenu *menu = new QMenu();
    menu->addMenu( SDMenu( p_intf ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
325
    menu->addAction( QIcon( ":/playlist_menu" ),
326
                     qtr( "Show Playlist" ), mi, SLOT( togglePlaylist() ) );
Clément Stenac's avatar
Clément Stenac committed
327 328
    menu->addSeparator();

329 330 331 332
    addDPStaticEntry( menu, qtr( I_PL_LOAD ), "", "", SLOT( openAPlaylist() ),
        "Ctrl+X" );
    addDPStaticEntry( menu, qtr( I_PL_SAVE ), "", "", SLOT( saveAPlaylist() ),
        "Ctrl+Y" );
333
    /*menu->addSeparator();
334
    menu->addAction( qtr( "Undock from Interface" ), mi,
335
                     SLOT( undockPlaylist() ), qtr( "Ctrl+U" ) );*/
Clément Stenac's avatar
Clément Stenac committed
336 337 338
    return menu;
}

339 340
/**
 * Tools/View Menu
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
341
 * This is kept in the same menu for now, but could change if it gets much
342
 * longer.
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
343
 * This menu can be an interface menu but also a right click menu.
344
 **/
345
QMenu *QVLCMenu::ToolsMenu( intf_thread_t *p_intf,
346
                            QMenu *current,
347 348 349
                            MainInterface *mi,
                            bool visual_selector_enabled,
                            bool with_intf )
350
{
351
    QMenu *menu = new QMenu( current );
352 353
    if( mi )
    {
354
        QAction *act=
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
355
            menu->addAction( QIcon( ":/playlist_menu" ),
356 357 358
                             qtr( "Playlist..." ), mi, SLOT( togglePlaylist() ),
                             qtr( "Ctrl+L" ) );
        act->setData( "_static_" );
359
    }
360
    addDPStaticEntry( menu, qtr( I_MENU_EXT ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
361
        ":/settings", SLOT( extendedDialog() ),
362
        "Ctrl+E" );
363 364 365

    menu->addSeparator();

366 367
    if( with_intf )
    {
368
        QMenu *intfmenu = InterfacesMenu( p_intf, menu );
369 370 371
        MenuFunc *f = new MenuFunc( intfmenu, 4 );
        CONNECT( intfmenu, aboutToShow(), THEDP->menusUpdateMapper, map() );
        THEDP->menusUpdateMapper->setMapping( intfmenu, f );
372 373
        menu->addSeparator();
    }
Clément Stenac's avatar
Clément Stenac committed
374 375
    if( mi )
    {
376
        /* Minimal View */
377 378
        QAction *action = menu->addAction( qtr( "Minimal View..." ), mi,
                                SLOT( toggleMinimalView() ), qtr( "Ctrl+H" ) );
379
        action->setCheckable( true );
380
        action->setData( "_static_" );
381
        if( mi->getControlsVisibilityStatus() & CONTROLS_VISIBLE )
382
            action->setChecked( true );
383
        minimalViewAction = action; /* HACK for minimalView */
384

385
        /* FullScreen View */
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
386
        action = menu->addAction( qtr( "Fullscreen Interface" ), mi,
387
                                  SLOT( toggleFullScreen() ), QString( "F11" ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
388
        action->setCheckable( true );
389
        action->setData( "_static_" );
390

391
        /* Advanced Controls */
392
        action = menu->addAction( qtr( "Advanced Controls" ), mi,
393
                                  SLOT( toggleAdvanced() ) );
394
        action->setCheckable( true );
395
        action->setData( "_static_" );
396 397
        if( mi->getControlsVisibilityStatus() & CONTROLS_ADVANCED )
            action->setChecked( true );
398
#if 0 /* For Visualisations. Not yet working */
399
        adv = menu->addAction( qtr( "Visualizations selector" ),
400
                mi, SLOT( visual() ) );
401 402
        adv->setCheckable( true );
        if( visual_selector_enabled ) adv->setChecked( true );
403
#endif
Clément Stenac's avatar
Clément Stenac committed
404
    }
405

406 407
    menu->addSeparator();

408
    addDPStaticEntry( menu, qtr( I_MENU_MSG ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
409
        ":/messages", SLOT( messagesDialog() ),
410
        "Ctrl+M" );
411
    addDPStaticEntry( menu, qtr( I_MENU_INFO ) , "", ":/info",
412 413
        SLOT( mediaInfoDialog() ), "Ctrl+I" );
    addDPStaticEntry( menu, qtr( I_MENU_CODECINFO ) , "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
414
        ":/info", SLOT( mediaCodecDialog() ), "Ctrl+J" );
415
    addDPStaticEntry( menu, qtr( I_MENU_BOOKMARK ), "","",
416
                      SLOT( bookmarksDialog() ), "Ctrl+B" );
417
#ifdef ENABLE_VLM
418
    addDPStaticEntry( menu, qtr( I_MENU_VLM ), "", "", SLOT( vlmDialog() ),
419
        "Ctrl+W" );
420
#endif
421

422
    menu->addSeparator();
423
    addDPStaticEntry( menu, qtr( "Preferences..." ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
424
        ":/preferences", SLOT( prefsDialog() ), "Ctrl+P" );
425 426 427
    return menu;
}

428 429 430
/**
 * Interface Sub-Menu, to list extras interface and skins
 **/
431 432
QMenu *QVLCMenu::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
{
433
    vector<int> objects;
434 435 436
    vector<const char *> varnames;
    /** \todo add "switch to XXX" */
    varnames.push_back( "intf-add" );
437
    objects.push_back( p_intf->i_object_id );
Clément Stenac's avatar
Qt4:  
Clément Stenac committed
438

439
    return Populate( p_intf, current, varnames, objects );
440 441
}

442 443 444
/**
 * Main Audio Menu
 */
445 446
QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QMenu * current )
{
447
    vector<int> objects;
448
    vector<const char *> varnames;
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
449
    vlc_object_t *p_aout;
450 451
    input_thread_t *p_input;

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

454
    if( current->isEmpty() )
455
    {
456 457 458
        ACT_ADD( current, "audio-es", qtr( "Audio &Track" ) );
        ACT_ADD( current, "audio-device", qtr( "Audio &Device" ) );
        ACT_ADD( current, "audio-channels", qtr( "Audio &Channels" ) );
459 460
        current->addSeparator();
        ACT_ADD( current, "visual", qtr( "&Visualizations" ) );
461 462
    }

463 464 465
    p_input = THEMIM->getInput();
    if( p_input )
        vlc_object_yield( p_input );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
466 467 468
    p_aout = ( vlc_object_t * ) vlc_object_find( p_intf,
                                                 VLC_OBJECT_AOUT,
                                                 FIND_ANYWHERE );
469

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
470
    AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
471

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
472 473
    if( p_aout )
        vlc_object_release( p_aout );
474 475 476
    if( p_input )
        vlc_object_release( p_input );

477 478 479
    return Populate( p_intf, current, varnames, objects );
}

480 481 482 483
/**
 * Main Video Menu
 * Subtitles are part of Video.
 **/
484
QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current )
485
{
486
    vlc_object_t *p_vout;
487
    input_thread_t *p_input;
488
    vector<int> objects;
489 490
    vector<const char *> varnames;

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

    if( current->isEmpty() )
494
    {
495
        ACT_ADD( current, "video-es", qtr( "Video &Track" ) );
496 497 498 499 500

        QAction *action;
        QMenu *submenu = new QMenu( qtr( "&Subtitles Track" ), current );
        action = current->addMenu( submenu );
        action->setData( "spu-es" );
501 502
        addDPStaticEntry( submenu, qtr( "Load File..." ), "", "",
                          SLOT( loadSubtitlesFile() ) );
503
        submenu->addSeparator();
504

505
        ACT_ADD( current, "fullscreen", qtr( "Toggle &Fullscreen" ) );
506 507 508 509 510
        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" ) );
511 512 513
        /* ACT_ADD( current, "directx-wallpaper", qtr( "DirectX Wallpaper" ) ); */
        ACT_ADD( current, "video-snapshot", qtr( "Snapshot" ) );
        /* ACT_ADD( current, "ffmpeg-pp-q", qtr( "Decoder" ) ); */
514
    }
515

516 517 518
    p_input = THEMIM->getInput();
    if( p_input )
        vlc_object_yield( p_input );
519
    p_vout = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_VOUT,
520
            FIND_ANYWHERE );
521

522
    VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
523

524 525
    if( p_vout )
        vlc_object_release( p_vout );
526 527 528
    if( p_input )
        vlc_object_release( p_input );

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

532 533 534 535
/**
 * Navigation Menu
 * For DVD, MP4, MOV and other chapter based format
 **/
536
QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *menu )
537 538
{
    vlc_object_t *p_object;
539
    vector<int> objects;
540
    vector<const char *> varnames;
541

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

    if( menu->isEmpty() )
    {
546 547 548
        addDPStaticEntry( menu, qtr( I_MENU_GOTOTIME ), "","",
                          SLOT( gotoTimeDialog() ), "Ctrl+T" );
        menu->addSeparator();
549 550 551 552 553 554

        ACT_ADD( menu, "bookmark", qtr( "&Bookmarks" ) );
        ACT_ADD( menu, "title", qtr( "&Title" ) );
        ACT_ADD( menu, "chapter", qtr( "&Chapter" ) );
        ACT_ADD( menu, "program", qtr( "&Program" ) );
        ACT_ADD( menu, "navigation", qtr( "&Navigation" ) );
555 556
    }

557
    p_object = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_INPUT,
558
            FIND_ANYWHERE );
559 560 561 562 563
    InputAutoMenuBuilder(  p_object, objects, varnames );
    PUSH_VAR( "prev-title" );
    PUSH_VAR( "next-title" );
    PUSH_VAR( "prev-chapter" );
    PUSH_VAR( "next-chapter" );
564
    EnableDPStaticEntries( menu, ( p_object != NULL ) );
565
    if( p_object )
566
    {
567
        vlc_object_release( p_object );
568 569
    }
    return Populate( p_intf, menu, varnames, objects, true );
570
}
571

572
/**
573
 * Service Discovery SubMenu
574
 **/
Clément Stenac's avatar
Clément Stenac committed
575 576 577
QMenu *QVLCMenu::SDMenu( intf_thread_t *p_intf )
{
    QMenu *menu = new QMenu();
578
    menu->setTitle( qtr( I_PL_SD ) );
579 580 581
    char **ppsz_longnames;
    char **ppsz_names = services_discovery_GetServicesNames( p_intf,
                                                             &ppsz_longnames );
582 583 584
    if( !ppsz_names )
        return menu;

585 586
    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
587
    {
588
        QAction *a = new QAction( qfu( *ppsz_longname ), menu );
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
589
        a->setCheckable( true );
590
        if( playlist_IsServicesDiscoveryLoaded( THEPL, *ppsz_name ) )
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
591 592
            a->setChecked( true );
        CONNECT( a , triggered(), THEDP->SDMapper, map() );
593
        THEDP->SDMapper->setMapping( a, QString( *ppsz_name ) );
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
594
        menu->addAction( a );
595

596
        if( !strcmp( *ppsz_name, "podcast" ) )
597
        {
Christophe Mutricy's avatar
Christophe Mutricy committed
598
            QAction *b = new QAction( qtr( "Configure podcasts..." ), menu );
599 600 601 602
            //b->setEnabled( a->isChecked() );
            menu->addAction( b );
            CONNECT( b, triggered(), THEDP, podcastConfigureDialog() );
        }
603 604
        free( *ppsz_name );
        free( *ppsz_longname );
Clément Stenac's avatar
Clément Stenac committed
605
    }
606 607
    free( ppsz_names );
    free( ppsz_longnames );
Clément Stenac's avatar
Clément Stenac committed
608 609
    return menu;
}
610 611 612
/**
 * Help/About Menu
**/
613
QMenu *QVLCMenu::HelpMenu( QMenu *current )
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
614
{
615
    QMenu *menu = new QMenu( current );
616
    addDPStaticEntry( menu, qtr( "Help..." ) , "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
617
        ":/help", SLOT( helpDialog() ), "F1" );
618
#ifdef UPDATE_CHECK
619
    addDPStaticEntry( menu, qtr( "Check for Updates..." ) , "", "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
620
                      SLOT( updateDialog() ), "");
621
#endif
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
622
    menu->addSeparator();
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
623 624
    addDPStaticEntry( menu, qtr( I_MENU_ABOUT ), "", ":/info",
            SLOT( aboutDialog() ), "Ctrl+F1" );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
625 626 627
    return menu;
}

628
/*****************************************************************************
629
 * Popup menus - Right Click menus                                           *
630
 *****************************************************************************/
631 632
#define POPUP_BOILERPLATE \
    unsigned int i_last_separator = 0; \
633
    vector<int> objects; \
634 635 636 637 638 639 640
    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() ); \
641
    p_intf->p_sys->p_popup_menu = NULL; \
642
    i_last_separator = 0;
643

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
644 645 646 647 648 649 650 651 652 653
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 )
            addMIMStaticEntry( p_intf, menu, qtr( "Pause" ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
654
                    ":/pause", SLOT( togglePlayPause() ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
655 656
        else
            addMIMStaticEntry( p_intf, menu, qtr( "Play" ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
657
                    ":/play", SLOT( togglePlayPause() ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
658
    }
659
    else if( THEPL->items.i_size )
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
660
        addMIMStaticEntry( p_intf, menu, qtr( "Play" ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
661
                ":/play", SLOT( togglePlayPause() ) );
662 663
    else
        addDPStaticEntry( menu, qtr( "Play" ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
664
                ":/play", SLOT( openDialog() ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
665 666

    addMIMStaticEntry( p_intf, menu, qtr( "Stop" ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
667
            ":/stop", SLOT( stop() ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
668
    addMIMStaticEntry( p_intf, menu, qtr( "Previous" ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
669
            ":/previous", SLOT( prev() ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
670
    addMIMStaticEntry( p_intf, menu, qtr( "Next" ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
671
            ":/next", SLOT( next() ) );
672
}
673 674 675

void QVLCMenu::PopupMenuStaticEntries( intf_thread_t *p_intf, QMenu *menu )
{
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
676
#if 0
677
    QMenu *toolsmenu = ToolsMenu( p_intf, menu, false, true );
678 679
    toolsmenu->setTitle( qtr( "Tools" ) );
    menu->addMenu( toolsmenu );
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
680
#endif
681

682
    QMenu *openmenu = new QMenu( qtr( "Open" ), menu );
683
    addDPStaticEntry( openmenu, qtr( "&Open File..." ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
684
        ":/file-asym", SLOT( openFileDialog() ) );
685
    addDPStaticEntry( openmenu, qtr( I_OPEN_FOLDER ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
686
        ":/folder-grey", SLOT( PLAppendDir() ) );
687
    addDPStaticEntry( openmenu, qtr( "Open &Disc..." ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
688
        ":/disc", SLOT( openDiscDialog() ) );
689
    addDPStaticEntry( openmenu, qtr( "Open &Network..." ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
690
        ":/network", SLOT( openNetDialog() ) );
691
    addDPStaticEntry( openmenu, qtr( "Open &Capture Device..." ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
692
        ":/capture-card", SLOT( openCaptureDialog() ) );
693 694 695
    menu->addMenu( openmenu );

    menu->addSeparator();
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
696
#if 0
697
    QMenu *helpmenu = HelpMenu( menu );
698 699
    helpmenu->setTitle( qtr( "Help" ) );
    menu->addMenu( helpmenu );
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
700
#endif
701

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
702
    addDPStaticEntry( menu, qtr( "Quit" ), "", ":/quit",
703
                      SLOT( quit() ), "Ctrl+Q" );
704
}
Clément Stenac's avatar
Qt4:  
Clément Stenac committed
705

706
/* Video Tracks and Subtitles tracks */
707
void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf )
708 709 710 711 712
{
    POPUP_BOILERPLATE;
    if( p_input )
    {
        vlc_object_yield( p_input );
713
        vlc_object_t *p_vout = ( vlc_object_t * )vlc_object_find( p_input,
714
                VLC_OBJECT_VOUT, FIND_CHILD );
715 716
        if( p_vout )
        {
717
            VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
718 719 720 721
            vlc_object_release( p_vout );
        }
        vlc_object_release( p_input );
    }
722
    QMenu *menu = new QMenu();
723
    CREATE_POPUP;
724 725
}

726
/* Audio Tracks */
727
void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf )
728 729 730 731 732
{
    POPUP_BOILERPLATE;
    if( p_input )
    {
        vlc_object_yield( p_input );
733
        vlc_object_t *p_aout = ( vlc_object_t * )vlc_object_find( p_input,
734
                VLC_OBJECT_AOUT, FIND_ANYWHERE );
735
        AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
736 737 738 739
        if( p_aout )
            vlc_object_release( p_aout );
        vlc_object_release( p_input );
    }
740
    QMenu *menu = new QMenu();
741
    CREATE_POPUP;
742 743
}

744
/* Navigation stuff, and general menus ( open ) */
745
void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf )
746
{
747
    vlc_value_t val;
748
    POPUP_BOILERPLATE;
749

750 751 752
    if( p_input )
    {
        vlc_object_yield( p_input );
753
        varnames.push_back( "audio-es" );
754
        InputAutoMenuBuilder( VLC_OBJECT( p_input ), objects, varnames );
755 756 757
        PUSH_SEPARATOR;
    }

758 759
    QMenu *menu = new QMenu();
    Populate( p_intf, menu, varnames, objects );
760

761
    menu->addSeparator();
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
762
    PopupMenuControlEntries( menu, p_intf, p_input );
763 764

    menu->addSeparator();
765
    PopupMenuStaticEntries(