menus.cpp 40.6 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 220
    PUSH_VAR( "audio-device" );
    PUSH_VAR( "audio-channels" );
    PUSH_VAR( "equalizer" );
221
    PUSH_VAR( "visual" );
222 223 224
    return VLC_SUCCESS;
}

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

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

247 248
/*****************************************************************************
 * All normal menus
249
 * Simple Code
250 251 252
 *****************************************************************************/

#define BAR_ADD( func, title ) { \
253
    QMenu *_menu = func; _menu->setTitle( title ); bar->addMenu( _menu ); }
254 255

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

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

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

296 297 298 299 300 301 302 303 304 305 306
    addDPStaticEntry( menu, qtr( "&Open File..." ), "",
        ":/pixmaps/file-asym_16px.png", SLOT( openFileDialog() ), "Ctrl+O" );
    addDPStaticEntry( menu, qtr( I_OPEN_FOLDER ), "",
        ":/pixmaps/folder-grey_16px.png", SLOT( PLAppendDir() ), "Ctrl+F" );
    addDPStaticEntry( menu, qtr( "Open &Disc..." ), "",
        ":/pixmaps/disc_16px.png", SLOT( openDiscDialog() ), "Ctrl+D" );
    addDPStaticEntry( menu, qtr( "Open &Network..." ), "",
        ":/pixmaps/network_16px.png", SLOT( openNetDialog() ), "Ctrl+N" );
    addDPStaticEntry( menu, qtr( "Open &Capture Device..." ), "",
        ":/pixmaps/capture-card_16px.png", SLOT( openCaptureDialog() ),
        "Ctrl+C" );
307
    menu->addSeparator();
308

309 310 311 312 313
    addDPStaticEntry( menu, qtr( "&Streaming..." ), "",
        ":/pixmaps/menus_stream_16px.png", SLOT( openThenStreamingDialogs() ),
        "Ctrl+S" );
    addDPStaticEntry( menu, qtr( "Conve&rt / Save..." ), "", "",
        SLOT( openThenTranscodingDialogs() ), "Ctrl+R" );
314
    menu->addSeparator();
315 316 317

    addDPStaticEntry( menu, qtr( "&Quit" ) , "",
        ":/pixmaps/menus_quit_16px.png", SLOT( quit() ), "Ctrl+Q" );
318 319 320
    return menu;
}

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

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

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

    menu->addSeparator();

365 366
    if( with_intf )
    {
367
        QMenu *intfmenu = InterfacesMenu( p_intf, menu );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
368
        intfmenu->setTitle( qtr( "Add Interfaces" ) );
369 370 371
        MenuFunc *f = new MenuFunc( intfmenu, 4 );
        CONNECT( intfmenu, aboutToShow(), THEDP->menusUpdateMapper, map() );
        THEDP->menusUpdateMapper->setMapping( intfmenu, f );
372 373 374
        menu->addMenu( intfmenu );
        menu->addSeparator();
    }
Clément Stenac's avatar
Clément Stenac committed
375 376
    if( mi )
    {
377
        /* Minimal View */
378 379
        QAction *action = menu->addAction( qtr( "Minimal View..." ), mi,
                                SLOT( toggleMinimalView() ), qtr( "Ctrl+H" ) );
380
        action->setCheckable( true );
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

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

404 405
    menu->addSeparator();

406 407 408 409 410 411 412
    addDPStaticEntry( menu, qtr( I_MENU_MSG ), "",
        ":/pixmaps/menus_messages_16px.png", SLOT( messagesDialog() ),
        "Ctrl+M" );
    addDPStaticEntry( menu, qtr( I_MENU_INFO ) , "", "",
        SLOT( mediaInfoDialog() ), "Ctrl+I" );
    addDPStaticEntry( menu, qtr( I_MENU_CODECINFO ) , "",
        ":/pixmaps/menus_info_16px.png", SLOT( mediaCodecDialog() ), "Ctrl+J" );
413
    addDPStaticEntry( menu, qtr( I_MENU_BOOKMARK ), "","",
414
                      SLOT( bookmarksDialog() ), "Ctrl+B" );
415
#ifdef ENABLE_VLM
416
    addDPStaticEntry( menu, qtr( I_MENU_VLM ), "", "", SLOT( vlmDialog() ),
417
        "Ctrl+W" );
418
#endif
419

420
    menu->addSeparator();
421 422
    addDPStaticEntry( menu, qtr( "Preferences..." ), "",
        ":/pixmaps/menus_preferences_16px.png", SLOT( prefsDialog() ), "Ctrl+P" );
423 424 425
    return menu;
}

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

437 438
    QMenu *submenu = new QMenu( current );
    QMenu *menu = Populate( p_intf, submenu, varnames, objects );
Clément Stenac's avatar
Clément Stenac committed
439

440 441 442
    return menu;
}

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

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

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

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

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

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

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

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

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

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

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

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

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

524
    VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
525

526 527
    if( p_vout )
        vlc_object_release( p_vout );
528 529 530
    if( p_input )
        vlc_object_release( p_input );

531
    return Populate( p_intf, current, varnames, objects );
532 533
}

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

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

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

        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" ) );
557 558
    }

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

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

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

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

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

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
646 647 648 649 650 651 652 653 654 655 656 657 658 659 660
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" ), "",
                    ":/pixmaps/pause_16px.png", SLOT( togglePlayPause() ) );
        else
            addMIMStaticEntry( p_intf, menu, qtr( "Play" ), "",
                    ":/pixmaps/play_16px.png", SLOT( togglePlayPause() ) );
    }
661
    else if( THEPL->items.i_size )
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
662 663
        addMIMStaticEntry( p_intf, menu, qtr( "Play" ), "",
                ":/pixmaps/play_16px.png", SLOT( togglePlayPause() ) );
664 665 666
    else
        addDPStaticEntry( menu, qtr( "Play" ), "",
                ":/pixmaps/play_16px.png", SLOT( openDialog() ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
667 668 669 670 671 672

    addMIMStaticEntry( p_intf, menu, qtr( "Stop" ), "",
            ":/pixmaps/stop_16px.png", SLOT( stop() ) );
    addMIMStaticEntry( p_intf, menu, qtr( "Previous" ), "",
            ":/pixmaps/previous_16px.png", SLOT( prev() ) );
    addMIMStaticEntry( p_intf, menu, qtr( "Next" ), "",
673
            ":/pixmaps/next_16px.png", SLOT( next() ) );
674
}
675 676 677

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

684
    QMenu *openmenu = new QMenu( qtr( "Open" ), menu );
685 686 687 688 689 690 691 692 693 694
    addDPStaticEntry( openmenu, qtr( "&Open File..." ), "",
        ":/pixmaps/file-asym_16px.png", SLOT( openFileDialog() ) );
    addDPStaticEntry( openmenu, qtr( I_OPEN_FOLDER ), "",
        ":/pixmaps/folder-grey_16px.png", SLOT( PLAppendDir() ) );
    addDPStaticEntry( openmenu, qtr( "Open &Disc..." ), "",
        ":/pixmaps/disc_16px.png", SLOT( openDiscDialog() ) );
    addDPStaticEntry( openmenu, qtr( "Open &Network..." ), "",
        ":/pixmaps/network_16px.png", SLOT( openNetDialog() ) );
    addDPStaticEntry( openmenu, qtr( "Open &Capture Device..." ), "",
        ":/pixmaps/capture-card_16px.png", SLOT( openCaptureDialog() ) );
695 696 697
    menu->addMenu( openmenu );

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

704 705
    addDPStaticEntry( menu, qtr( "Quit" ), "", ":/pixmaps/menus_quit_16px.png",
                      SLOT( quit() ), "Ctrl+Q" );
706
}
Clément Stenac's avatar
Qt4:  
Clément Stenac committed
707

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

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

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

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

760 761
    QMenu *menu = new QMenu();
    Populate( p_intf, menu, varnames, objects );
762

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

    menu->addSeparator();
767
    PopupMenuStaticEntries( p_intf, menu );
768

769 770
    p_intf->p_sys->p_popup_menu = menu;
    menu->popup( QCursor::pos() );
771 772 773
    p_intf->p_sys->p_popup_menu = NULL;
}

774
/* Main Menu that sticks everything together  */
Damien Fouilleul's avatar
Damien Fouilleul committed
775
void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show )
776
{
777
    MainInterface *mi = p_intf->p_sys->p_mi;
Damien Fouilleul's avatar
Damien Fouilleul committed
778
    if( show )
779
    {
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
780 781 782 783 784 785 786
        /* Delete and recreate a popup if there is one */
        if( p_intf->p_sys->p_popup_menu )
            delete p_intf->p_sys->p_popup_menu;

        QMenu *menu = new QMenu();
        QMenu *submenu;
        QAction *action;
787
        bool b_isFullscreen = false;
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
788 789 790 791 792 793 794

        POPUP_BOILERPLATE;

        PopupMenuControlEntries( menu, p_intf, p_input );
        menu->addSeparator();

        if( p_input )
795
        {
796 797 798 799 800 801 802 803 804 805 806 807 808 809
            vlc_object_t *p_vout = (vlc_object_t *)
                vlc_object_find( p_input, VLC_OBJECT_VOUT, FIND_CHILD );

            /* Add a fullscreen switch button */
            if( p_vout )
            {
                vlc_value_t val;
                var_Get( p_vout, "fullscreen", &val );
                b_isFullscreen = !( !val.b_bool );
                if( b_isFullscreen )
                    CreateAndConnect( menu, "fullscreen",
                            qtr( "Leave Fullscreen" ),"" , ITEM_NORMAL,
                            p_vout->i_object_id, val, VLC_VAR_BOOL,
                            b_isFullscreen );
810
                vlc_object_release( p_vout );
811 812 813 814
            }

            menu->addSeparator();

Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
815 816
            vlc_object_yield( p_input );
            InputAutoMenuBuilder( VLC_OBJECT( p_input ), objects, varnames );
817
            vlc_object_release( p_input );
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
818

819 820
            submenu = new QMenu( menu );
            action = menu->addMenu( AudioMenu( p_intf, submenu ) );
821 822
            action->setText( qtr( "&Audio" ) );
            if( action->menu()->isEmpty() )
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
823 824
                action->setEnabled( false );

825 826
            submenu = new QMenu( menu );
            action = menu->addMenu( VideoMenu( p_intf, submenu ) );
827 828
            action->setText( qtr( "&Video" ) );
            if( action->menu()->isEmpty() )
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
829 830
                action->setEnabled( false );

831 832
            submenu = new QMenu( menu );
            action = menu->addMenu( NavigMenu( p_intf, submenu ) );
Jean-Baptiste Kempf's avatar