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

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

120 121 122 123 124 125
void EnableDPStaticEntries( QMenu *menu, bool enable = true )
{
    if( !menu )
        return;

    QAction *action;
126
    foreach( action, menu->actions() )
127 128 129 130 131 132
    {
        if( action->data().toString() == "_static_" )
            action->setEnabled( enable );
    }
}

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

151
/*****************************************************************************
152
 * Definitions of variables for the dynamic menus
153
 *****************************************************************************/
154
#define PUSH_VAR( var ) varnames.push_back( var ); \
155 156 157 158
    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 );
159 160

#define PUSH_SEPARATOR if( objects.size() != i_last_separator ) { \
161
    objects.push_back( 0 ); varnames.push_back( "" ); \
162
    i_last_separator = objects.size(); }
163 164

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

Clément Stenac's avatar
Qt4:  
Clément Stenac committed
177
static int VideoAutoMenuBuilder( vlc_object_t *p_object,
178
        input_thread_t *p_input,
179
        vector<int> &objects,
180
        vector<const char *> &varnames )
181
{
182 183
    PUSH_INPUTVAR( "video-es" );
    PUSH_INPUTVAR( "spu-es" );
184 185 186 187 188 189 190 191 192
    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" );

193
    if( p_object )
194
    {
195 196 197 198 199 200 201 202 203
        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 );
        }
204 205 206 207 208
    }
    return VLC_SUCCESS;
}

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

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

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

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

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

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

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

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

292 293 294 295 296 297 298 299 300 301 302
    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" );
303
    menu->addSeparator();
304

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

    addDPStaticEntry( menu, qtr( "&Quit" ) , "",
        ":/pixmaps/menus_quit_16px.png", SLOT( quit() ), "Ctrl+Q" );
314 315 316
    return menu;
}

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

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

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

    menu->addSeparator();

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

380
        /* FullScreen View */
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
381
        action = menu->addAction( qtr( "Fullscreen Interface" ), mi,
382
                                  SLOT( toggleFullScreen() ), QString( "F11" ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
383
        action->setCheckable( true );
384

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

399 400
    menu->addSeparator();

401 402 403 404 405 406 407
    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" );
408
    addDPStaticEntry( menu, qtr( I_MENU_BOOKMARK ), "","",
409
                      SLOT( bookmarksDialog() ), "Ctrl+B" );
410
#ifdef ENABLE_VLM
411
    addDPStaticEntry( menu, qtr( I_MENU_VLM ), "", "", SLOT( vlmDialog() ),
412
        "Ctrl+W" );
413
#endif
414

415
    menu->addSeparator();
416 417
    addDPStaticEntry( menu, qtr( "Preferences..." ), "",
        ":/pixmaps/menus_preferences_16px.png", SLOT( prefsDialog() ), "Ctrl+P" );
418 419 420
    return menu;
}

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

432 433
    QMenu *submenu = new QMenu( current );
    QMenu *menu = Populate( p_intf, submenu, varnames, objects );
Clément Stenac's avatar
Clément Stenac committed
434

435 436 437
    return menu;
}

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

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

450
    if( current->isEmpty() )
451
    {
452 453 454 455
        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" ) );
456 457
        current->addSeparator();
        ACT_ADD( current, "visual", qtr( "&Visualizations" ) );
458 459
    }

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

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

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
469 470
    if( p_aout )
        vlc_object_release( p_aout );
471 472 473
    if( p_input )
        vlc_object_release( p_input );

474 475 476
    return Populate( p_intf, current, varnames, objects );
}

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

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
488
    if( !current ) current = new QMenu();
489 490

    if( current->isEmpty() )
491
    {
492
        ACT_ADD( current, "video-es", qtr( "Video &Track" ) );
493 494 495 496 497

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

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

513 514 515
    p_input = THEMIM->getInput();
    if( p_input )
        vlc_object_yield( p_input );
516
    p_vout = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_VOUT,
517
            FIND_ANYWHERE );
518

519
    VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
520

521 522
    if( p_vout )
        vlc_object_release( p_vout );
523 524 525
    if( p_input )
        vlc_object_release( p_input );

526
    return Populate( p_intf, current, varnames, objects );
527 528
}

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

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
539
    if( !menu ) menu = new QMenu();
540 541 542

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

        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" ) );
552 553
    }

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

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

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

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

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

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

    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" ), "",
668
            ":/pixmaps/next_16px.png", SLOT( next() ) );
669
}
670 671 672

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

679
    QMenu *openmenu = new QMenu( qtr( "Open" ), menu );
680 681 682 683 684 685 686 687 688 689
    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() ) );
690 691 692
    menu->addMenu( openmenu );

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

699 700
    addDPStaticEntry( menu, qtr( "Quit" ), "", ":/pixmaps/menus_quit_16px.png",
                      SLOT( quit() ), "Ctrl+Q" );
701
}
Clément Stenac's avatar
Qt4:  
Clément Stenac committed
702

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

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

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

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

755 756
    QMenu *menu = new QMenu();
    Populate( p_intf, menu, varnames, objects );
757

758
    menu->addSeparator();
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
759
    PopupMenuControlEntries( menu, p_intf, p_input );
760 761

    menu->addSeparator();
762
    PopupMenuStaticEntries( p_intf, menu );
763

764 765
    p_intf->p_sys->p_popup_menu = menu;
    menu->popup( QCursor::pos() );
766 767 768
    p_intf->p_sys->p_popup_menu = NULL;
}

769
/* Main Menu that sticks everything together  */
Damien Fouilleul's avatar
Damien Fouilleul committed
770
void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show )
771
{
772
    MainInterface *mi = p_intf->p_sys->p_mi;
Damien Fouilleul's avatar
Damien Fouilleul committed
773
    if( show )
774
    {
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
775 776 777 778 779 780 781
        /* 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;
782
        bool b_isFullscreen = false;
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
783 784 785 786 787 788 789

        POPUP_BOILERPLATE;

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

        if( p_input )
790
        {
791 792 793 794 795 796 797 798 799 800 801 802 803 804
            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 );
805
                vlc_object_release( p_vout );
806 807 808 809
            }

            menu->addSeparator();

Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
810 811
            vlc_object_yield( p_input );
            InputAutoMenuBuilder( VLC_OBJECT( p_input ), objects, varnames );
812
            vlc_object_release( p_input );
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
813

814 815
            submenu = new QMenu( menu );
            action = menu->addMenu( AudioMenu( p_intf, submenu ) );
816 817
            action->setText( qtr( "&Audio" ) );
            if( action->menu()->isEmpty() )
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
818 819
                action->setEnabled( false );

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

826 827
            submenu = new QMenu( menu );
            action = menu->addMenu( NavigMenu( p_intf, submenu ) );
828 829 830
            action->setText( qtr( "&Playback" ) );
            if( action->menu()->isEmpty() )
                action->setEnabled( false );