menus.cpp 40.3 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 381
        /* FullScreen View */
        action = menu->addAction( qtr( "Toggle Fullscreen Interface" ), mi,
382
                                  SLOT( toggleFullScreen() ), QString( "F11" ) );
383

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

398 399
    menu->addSeparator();

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

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

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

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

434 435 436
    return menu;
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        POPUP_BOILERPLATE;

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

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

            menu->addSeparator();

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

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

819 820
            submenu = new QMenu( menu );
            action = menu->addMenu( VideoMenu( p_intf, submenu ) );
821 822
            action->setText( qtr( "&Video" ) );
            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( NavigMenu( p_intf, submenu ) );
827 828 829
            action->setText( qtr( "&Playback" ) );
            if( action->menu()->isEmpty() )
                action->setEnabled( false );
830
        }
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
831 832

        menu->addSeparator();
833

834 835