menus.cpp 40 KB
Newer Older
1 2 3
/*****************************************************************************
 * menus.cpp : Qt menus
 *****************************************************************************
4
 * Copyright ( C ) 2006-2007 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
enum
{
    ITEM_NORMAL,
    ITEM_CHECK,
    ITEM_RADIO
};

static QActionGroup *currentGroup;

59
// Add static entries to menus
60 61
void addDPStaticEntry( QMenu *menu,
                       const QString text,
62 63
                       const char *help,
                       const char *icon,
64
                       const char *member,
65
                       const char *shortcut = NULL )
66
{
67
    QAction *action = NULL;
68 69 70
    if( !EMPTY_STR( icon ) > 0 )
    {
        if( !EMPTY_STR( shortcut ) > 0 )
71 72
            action = menu->addAction( QIcon( icon ), text, THEDP,
                                      member, qtr( shortcut ) );
73
        else
74
            action = menu->addAction( QIcon( icon ), text, THEDP, member );
75 76 77 78
    }
    else
    {
        if( !EMPTY_STR( shortcut ) > 0 )
79
            action = menu->addAction( text, THEDP, member, qtr( shortcut ) );
80
        else
81
            action = menu->addAction( text, THEDP, member );
82
    }
83
    action->setData( "_static_" );
84
}
85 86

void addMIMStaticEntry( intf_thread_t *p_intf,
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
87 88
                        QMenu *menu,
                        const QString text,
89 90
                        const char *help,
                        const char *icon,
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
91
                        const char *member )
92 93 94
{
    if( strlen( icon ) > 0 )
    {
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
95
        QAction *action = menu->addAction( text, THEMIM,  member );
96 97 98 99
        action->setIcon( QIcon( icon ) );
    }
    else
    {
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
100
        menu->addAction( text, THEMIM, member );
101
    }
102
}
103

104 105 106 107 108 109
void EnableDPStaticEntries( QMenu *menu, bool enable = true )
{
    if( !menu )
        return;

    QAction *action;
110
    foreach( action, menu->actions() )
111 112 113 114 115 116
    {
        if( action->data().toString() == "_static_" )
            action->setEnabled( enable );
    }
}

117 118 119 120 121 122 123 124 125
/**
 * \return Number of static entries
 */
int DeleteNonStaticEntries( QMenu *menu )
{
    int i_ret = 0;
    QAction *action;
    if( !menu )
        return VLC_EGENERIC;
126
    foreach( action, menu->actions() )
127 128 129 130 131 132 133 134
    {
        if( action->data().toString() != "_static_" )
            delete action;
        else
            i_ret++;
    }
}

135
/*****************************************************************************
136
 * Definitions of variables for the dynamic menus
137
 *****************************************************************************/
138
#define PUSH_VAR( var ) varnames.push_back( var ); \
139 140 141 142
    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 );
143 144

#define PUSH_SEPARATOR if( objects.size() != i_last_separator ) { \
145
    objects.push_back( 0 ); varnames.push_back( "" ); \
146
    i_last_separator = objects.size(); }
147 148

static int InputAutoMenuBuilder( vlc_object_t *p_object,
149
        vector<int> &objects,
150
        vector<const char *> &varnames )
151
{
152
    PUSH_VAR( "bookmark" );
153
    PUSH_VAR( "title" );
154
    PUSH_VAR( "chapter" );
155 156 157 158 159 160
    PUSH_VAR( "program" );
    PUSH_VAR( "navigation" );
    PUSH_VAR( "dvd_menus" );
    return VLC_SUCCESS;
}

Clément Stenac's avatar
Qt4:  
Clément Stenac committed
161
static int VideoAutoMenuBuilder( vlc_object_t *p_object,
162
        input_thread_t *p_input,
163
        vector<int> &objects,
164
        vector<const char *> &varnames )
165
{
166 167
    PUSH_INPUTVAR( "video-es" );
    PUSH_INPUTVAR( "spu-es" );
168 169 170 171 172 173 174 175 176
    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" );

177
    if( p_object )
178
    {
179 180 181 182 183 184 185 186 187
        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 );
        }
188 189 190 191 192
    }
    return VLC_SUCCESS;
}

static int AudioAutoMenuBuilder( vlc_object_t *p_object,
193
        input_thread_t *p_input,
194
        vector<int> &objects,
195
        vector<const char *> &varnames )
196
{
197
    PUSH_INPUTVAR( "audio-es" );
198 199 200 201 202 203 204
    PUSH_VAR( "audio-device" );
    PUSH_VAR( "audio-channels" );
    PUSH_VAR( "visual" );
    PUSH_VAR( "equalizer" );
    return VLC_SUCCESS;
}

205 206 207
static QAction * FindActionWithVar( QMenu *menu, const char *psz_var )
{
    QAction *action;
208
    foreach( action, menu->actions() )
209 210 211 212 213 214 215 216 217 218
    {
        if( action->data().toString() == psz_var )
            return action;
    }
    return NULL;
}

static QAction * FindActionWithText( QMenu *menu, QString &text )
{
    QAction *action;
219
    foreach( action, menu->actions() )
220 221 222 223 224 225 226
    {
        if( action->text() == text )
            return action;
    }
    return NULL;
}

227 228
/*****************************************************************************
 * All normal menus
229
 * Simple Code
230 231 232
 *****************************************************************************/

#define BAR_ADD( func, title ) { \
233
    QMenu *_menu = func; _menu->setTitle( title ); bar->addMenu( _menu ); }
234 235

#define BAR_DADD( func, title, id ) { \
236 237 238 239 240 241 242 243
    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 ); }
244

245 246 247
/**
 * Main Menu Bar Creation
 **/
248 249 250
void QVLCMenu::createMenuBar( MainInterface *mi,
                              intf_thread_t *p_intf,
                              bool visual_selector_enabled )
Clément Stenac's avatar
Qt4:  
Clément Stenac committed
251
{
252 253 254
    /* QMainWindows->menuBar()
       gives the QProcess::destroyed timeout issue on Cleanlooks style with
       setDesktopAware set to false */
255
    QMenuBar *bar = mi->menuBar();
256
    BAR_ADD( FileMenu(), qtr( "&Media" ) );
257
    BAR_ADD( PlaylistMenu( p_intf, mi ), qtr( "&Playlist" ) );
258
    BAR_ADD( ToolsMenu( p_intf, NULL, mi, visual_selector_enabled, true ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
259
             qtr( "&Tools" ) );
260 261
    BAR_DADD( AudioMenu( p_intf, NULL ), qtr( "&Audio" ), 1 );
    BAR_DADD( VideoMenu( p_intf, NULL ), qtr( "&Video" ), 2 );
262
    BAR_DADD( NavigMenu( p_intf, NULL ), qtr( "&Playback" ), 3 );
263
    BAR_ADD( HelpMenu( NULL ), qtr( "&Help" ) );
264
}
265 266
#undef BAR_ADD
#undef BAR_DADD
267 268

/**
269
 * Media ( File ) Menu
270 271
 * Opening, streaming and quit
 **/
272 273 274
QMenu *QVLCMenu::FileMenu()
{
    QMenu *menu = new QMenu();
275

276 277 278 279 280 281 282 283 284 285 286
    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" );
287
    menu->addSeparator();
288

289 290 291 292 293
    addDPStaticEntry( menu, qtr( "&Streaming..." ), "",
        ":/pixmaps/menus_stream_16px.png", SLOT( openThenStreamingDialogs() ),
        "Ctrl+S" );
    addDPStaticEntry( menu, qtr( "Conve&rt / Save..." ), "", "",
        SLOT( openThenTranscodingDialogs() ), "Ctrl+R" );
294
    menu->addSeparator();
295 296 297

    addDPStaticEntry( menu, qtr( "&Quit" ) , "",
        ":/pixmaps/menus_quit_16px.png", SLOT( quit() ), "Ctrl+Q" );
298 299 300
    return menu;
}

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
301
/* Playlist/MediaLibrary Control */
302
QMenu *QVLCMenu::PlaylistMenu( intf_thread_t *p_intf, MainInterface *mi )
Clément Stenac's avatar
Clément Stenac committed
303 304 305
{
    QMenu *menu = new QMenu();
    menu->addMenu( SDMenu( p_intf ) );
306 307
    menu->addAction( QIcon( ":/pixmaps/playlist_16px.png" ),
                     qtr( "Show Playlist" ), mi, SLOT( togglePlaylist() ) );
Clément Stenac's avatar
Clément Stenac committed
308 309
    menu->addSeparator();

310 311 312 313
    addDPStaticEntry( menu, qtr( I_PL_LOAD ), "", "", SLOT( openAPlaylist() ),
        "Ctrl+X" );
    addDPStaticEntry( menu, qtr( I_PL_SAVE ), "", "", SLOT( saveAPlaylist() ),
        "Ctrl+Y" );
314
    menu->addSeparator();
315
    menu->addAction( qtr( "Undock from interface" ), mi,
316
                     SLOT( undockPlaylist() ), qtr( "Ctrl+U" ) );
Clément Stenac's avatar
Clément Stenac committed
317 318 319
    return menu;
}

320 321
/**
 * Tools/View Menu
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
322
 * This is kept in the same menu for now, but could change if it gets much
323
 * longer.
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
324
 * This menu can be an interface menu but also a right click menu.
325
 **/
326
QMenu *QVLCMenu::ToolsMenu( intf_thread_t *p_intf,
327
                            QMenu *current,
328 329 330
                            MainInterface *mi,
                            bool visual_selector_enabled,
                            bool with_intf )
331
{
332
    QMenu *menu = new QMenu( current );
333 334
    if( mi )
    {
335
        menu->addAction( QIcon( ":/pixmaps/playlist_16px.png" ),
336 337 338
                         qtr( "Playlist..." ), mi, SLOT( togglePlaylist() ),
                         qtr( "Ctrl+L" ) );
    }
339 340 341
    addDPStaticEntry( menu, qtr( I_MENU_EXT ), "",
        ":/pixmaps/menus_settings_16px.png", SLOT( extendedDialog() ),
        "Ctrl+E" );
342 343 344

    menu->addSeparator();

345 346
    if( with_intf )
    {
347
        QMenu *intfmenu = InterfacesMenu( p_intf, menu );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
348
        intfmenu->setTitle( qtr( "Add Interfaces" ) );
349 350 351
        MenuFunc *f = new MenuFunc( intfmenu, 4 );
        CONNECT( intfmenu, aboutToShow(), THEDP->menusUpdateMapper, map() );
        THEDP->menusUpdateMapper->setMapping( intfmenu, f );
352 353 354
        menu->addMenu( intfmenu );
        menu->addSeparator();
    }
Clément Stenac's avatar
Clément Stenac committed
355 356
    if( mi )
    {
357
        /* Minimal View */
358
        QAction *action=menu->addAction( qtr( "Minimal View..." ), mi,
359
                SLOT( toggleMinimalView() ), qtr( "Ctrl+H" ) );
360
        action->setCheckable( true );
361
        if( mi->getControlsVisibilityStatus() & CONTROLS_VISIBLE )
362
            action->setChecked( true );
363

364 365 366 367
        /* FullScreen View */
        action = menu->addAction( qtr( "Toggle Fullscreen Interface" ), mi,
                SLOT( toggleFullScreen() ), qtr( "F11" ) );

368
        /* Advanced Controls */
369 370
        action = menu->addAction( qtr( "Advanced controls" ), mi,
                SLOT( toggleAdvanced() ) );
371
        action->setCheckable( true );
372 373
        if( mi->getControlsVisibilityStatus() & CONTROLS_ADVANCED )
            action->setChecked( true );
374
#if 0 /* For Visualisations. Not yet working */
375
        adv = menu->addAction( qtr( "Visualizations selector" ),
376
                mi, SLOT( visual() ) );
377 378
        adv->setCheckable( true );
        if( visual_selector_enabled ) adv->setChecked( true );
379
#endif
Clément Stenac's avatar
Clément Stenac committed
380
    }
381

382 383
    menu->addSeparator();

384 385 386 387 388 389 390
    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" );
391
    addDPStaticEntry( menu, qtr( I_MENU_BOOKMARK ), "","",
392
                      SLOT( bookmarksDialog() ), "Ctrl+B" );
393
#ifdef ENABLE_VLM
394
    addDPStaticEntry( menu, qtr( I_MENU_VLM ), "", "", SLOT( vlmDialog() ),
395
        "Ctrl+W" );
396
#endif
397

398
    menu->addSeparator();
399 400
    addDPStaticEntry( menu, qtr( "Preferences..." ), "",
        ":/pixmaps/menus_preferences_16px.png", SLOT( prefsDialog() ), "Ctrl+P" );
401 402 403
    return menu;
}

404 405 406
/**
 * Interface Sub-Menu, to list extras interface and skins
 **/
407 408
QMenu *QVLCMenu::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
{
409
    vector<int> objects;
410 411 412
    vector<const char *> varnames;
    /** \todo add "switch to XXX" */
    varnames.push_back( "intf-add" );
413
    objects.push_back( p_intf->i_object_id );
Clément Stenac's avatar
Qt4:  
Clément Stenac committed
414

415 416
    QMenu *submenu = new QMenu( current );
    QMenu *menu = Populate( p_intf, submenu, varnames, objects );
Clément Stenac's avatar
Clément Stenac committed
417

418 419 420
    return menu;
}

421 422 423
/**
 * Main Audio Menu
 */
424 425
QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QMenu * current )
{
426
    vector<int> objects;
427
    vector<const char *> varnames;
428 429 430 431 432
    vlc_object_t *p_object;
    input_thread_t *p_input;

    if( !current )
        current = new QMenu();
433

434
    if( current->isEmpty() )
435
    {
436 437 438 439 440
        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, "visual", qtr( "&Visualizations" ) );
        ACT_ADD( current, "equalizer", qtr( "&Equalizer" ) );
441 442
    }

443 444 445 446 447 448 449 450 451
    p_input = THEMIM->getInput();
    if( p_input )
        vlc_object_yield( p_input );
    p_object = ( vlc_object_t * ) vlc_object_find( p_intf,
                                                   VLC_OBJECT_AOUT,
                                                   FIND_ANYWHERE );

    AudioAutoMenuBuilder( p_object, p_input, objects, varnames );

452 453
    if( p_object )
        vlc_object_release( p_object );
454 455 456
    if( p_input )
        vlc_object_release( p_input );

457 458 459
    return Populate( p_intf, current, varnames, objects );
}

460 461 462 463
/**
 * Main Video Menu
 * Subtitles are part of Video.
 **/
464
QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current )
465 466
{
    vlc_object_t *p_object;
467
    input_thread_t *p_input;
468
    vector<int> objects;
469 470
    vector<const char *> varnames;

471 472 473 474
    if( !current )
        current = new QMenu();

    if( current->isEmpty() )
475
    {
476
        ACT_ADD( current, "video-es", qtr( "Video &Track" ) );
477 478 479 480 481

        QAction *action;
        QMenu *submenu = new QMenu( qtr( "&Subtitles Track" ), current );
        action = current->addMenu( submenu );
        action->setData( "spu-es" );
482 483
        addDPStaticEntry( submenu, qtr( "Load File..." ), "", "",
                          SLOT( loadSubtitlesFile() ) );
484

485
        ACT_ADD( current, "fullscreen", qtr( "Toggle &Fullscreen" ) );
486 487 488 489 490
        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" ) );
491 492 493
        /* ACT_ADD( current, "directx-wallpaper", qtr( "DirectX Wallpaper" ) ); */
        ACT_ADD( current, "video-snapshot", qtr( "Snapshot" ) );
        /* ACT_ADD( current, "ffmpeg-pp-q", qtr( "Decoder" ) ); */
494
    }
495

496 497 498
    p_input = THEMIM->getInput();
    if( p_input )
        vlc_object_yield( p_input );
499
    p_object = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_VOUT,
500
            FIND_ANYWHERE );
501 502 503 504

    VideoAutoMenuBuilder( p_object, p_input, objects, varnames );

    if( p_object )
505
        vlc_object_release( p_object );
506 507 508
    if( p_input )
        vlc_object_release( p_input );

509
    return Populate( p_intf, current, varnames, objects );
510 511
}

512 513 514 515
/**
 * Navigation Menu
 * For DVD, MP4, MOV and other chapter based format
 **/
516
QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *menu )
517 518
{
    vlc_object_t *p_object;
519
    vector<int> objects;
520
    vector<const char *> varnames;
521

522 523 524
    if( !menu )
    {
        menu = new QMenu();
525 526 527 528
    }

    if( menu->isEmpty() )
    {
529 530 531
        addDPStaticEntry( menu, qtr( I_MENU_GOTOTIME ), "","",
                          SLOT( gotoTimeDialog() ), "Ctrl+T" );
        menu->addSeparator();
532 533 534 535 536 537

        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" ) );
538 539
    }

540
    p_object = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_INPUT,
541
            FIND_ANYWHERE );
542 543 544 545 546
    InputAutoMenuBuilder(  p_object, objects, varnames );
    PUSH_VAR( "prev-title" );
    PUSH_VAR( "next-title" );
    PUSH_VAR( "prev-chapter" );
    PUSH_VAR( "next-chapter" );
547
    EnableDPStaticEntries( menu, ( p_object != NULL ) );
548
    if( p_object )
549
    {
550
        vlc_object_release( p_object );
551 552
    }
    return Populate( p_intf, menu, varnames, objects, true );
553
}
554

555
/**
556
 * Service Discovery SubMenu
557
 **/
Clément Stenac's avatar
Clément Stenac committed
558 559 560
QMenu *QVLCMenu::SDMenu( intf_thread_t *p_intf )
{
    QMenu *menu = new QMenu();
561
    menu->setTitle( qtr( I_PL_SD ) );
562 563 564
    char **ppsz_longnames;
    char **ppsz_names = services_discovery_GetServicesNames( p_intf,
                                                             &ppsz_longnames );
565 566 567
    if( !ppsz_names )
        return menu;

568 569
    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
570
    {
571
        QAction *a = new QAction( qfu( *ppsz_longname ), menu );
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
572
        a->setCheckable( true );
573
        if( playlist_IsServicesDiscoveryLoaded( THEPL, *ppsz_name ) )
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
574 575
            a->setChecked( true );
        CONNECT( a , triggered(), THEDP->SDMapper, map() );
576
        THEDP->SDMapper->setMapping( a, QString( *ppsz_name ) );
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
577
        menu->addAction( a );
578

579
        if( !strcmp( *ppsz_name, "podcast" ) )
580 581 582 583 584 585
        {
            QAction *b = new QAction( qfu( "Configure podcasts..." ), menu );
            //b->setEnabled( a->isChecked() );
            menu->addAction( b );
            CONNECT( b, triggered(), THEDP, podcastConfigureDialog() );
        }
586 587
        free( *ppsz_name );
        free( *ppsz_longname );
Clément Stenac's avatar
Clément Stenac committed
588
    }
589 590
    free( ppsz_names );
    free( ppsz_longnames );
Clément Stenac's avatar
Clément Stenac committed
591 592
    return menu;
}
593 594 595
/**
 * Help/About Menu
**/
596
QMenu *QVLCMenu::HelpMenu( QMenu *current )
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
597
{
598
    QMenu *menu = new QMenu( current );
599 600
    addDPStaticEntry( menu, qtr( "Help..." ) , "",
        ":/pixmaps/menus_help_16px.png", SLOT( helpDialog() ), "F1" );
601
#ifdef UPDATE_CHECK
602
    addDPStaticEntry( menu, qtr( "Check for updates..." ) , "", "", SLOT( updateDialog() ), "");
603
#endif
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
604
    menu->addSeparator();
605 606
    addDPStaticEntry( menu, qtr( I_MENU_ABOUT ), "", "", SLOT( aboutDialog() ),
        "Ctrl+F1" );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
607 608 609
    return menu;
}

610
/*****************************************************************************
611
 * Popup menus - Right Click menus                                           *
612
 *****************************************************************************/
613 614
#define POPUP_BOILERPLATE \
    unsigned int i_last_separator = 0; \
615
    vector<int> objects; \
616 617 618 619 620 621 622
    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() ); \
623
    p_intf->p_sys->p_popup_menu = NULL; \
624
    i_last_separator = 0;
625

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
626 627 628 629 630 631 632 633 634 635 636 637 638 639 640
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() ) );
    }
641
    else if( THEPL->items.i_size )
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
642 643 644 645 646 647 648 649
        addMIMStaticEntry( p_intf, menu, qtr( "Play" ), "",
                ":/pixmaps/play_16px.png", SLOT( togglePlayPause() ) );

    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" ), "",
650
            ":/pixmaps/next_16px.png", SLOT( next() ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
651
    }
652 653 654

void QVLCMenu::PopupMenuStaticEntries( intf_thread_t *p_intf, QMenu *menu )
{
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
655
#if 0
656
    QMenu *toolsmenu = ToolsMenu( p_intf, menu, false, true );
657 658
    toolsmenu->setTitle( qtr( "Tools" ) );
    menu->addMenu( toolsmenu );
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
659
#endif
660

661
    QMenu *openmenu = new QMenu( qtr( "Open" ), menu );
662 663 664 665 666 667 668 669 670 671
    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() ) );
672 673 674
    menu->addMenu( openmenu );

    menu->addSeparator();
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
675
#if 0
676
    QMenu *helpmenu = HelpMenu( menu );
677 678
    helpmenu->setTitle( qtr( "Help" ) );
    menu->addMenu( helpmenu );
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
679
#endif
680

681 682
    addDPStaticEntry( menu, qtr( "Quit" ), "", ":/pixmaps/menus_quit_16px.png",
                      SLOT( quit() ), "Ctrl+Q" );
683
}
Clément Stenac's avatar
Qt4:  
Clément Stenac committed
684

685
/* Video Tracks and Subtitles tracks */
686
void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf )
687 688 689 690 691
{
    POPUP_BOILERPLATE;
    if( p_input )
    {
        vlc_object_yield( p_input );
692
        vlc_object_t *p_vout = ( vlc_object_t * )vlc_object_find( p_input,
693
                VLC_OBJECT_VOUT, FIND_CHILD );
694 695
        if( p_vout )
        {
696
            VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
697 698 699 700
            vlc_object_release( p_vout );
        }
        vlc_object_release( p_input );
    }
701
    QMenu *menu = new QMenu();
702
    CREATE_POPUP;
703 704
}

705
/* Audio Tracks */
706
void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf )
707 708 709 710 711
{
    POPUP_BOILERPLATE;
    if( p_input )
    {
        vlc_object_yield( p_input );
712
        vlc_object_t *p_aout = ( vlc_object_t * )vlc_object_find( p_input,
713
                VLC_OBJECT_AOUT, FIND_ANYWHERE );
714
        AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
715 716 717 718
        if( p_aout )
            vlc_object_release( p_aout );
        vlc_object_release( p_input );
    }
719
    QMenu *menu = new QMenu();
720
    CREATE_POPUP;
721 722
}

723
/* Navigation stuff, and general menus ( open ) */
724
void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf )
725
{
726
    vlc_value_t val;
727
    POPUP_BOILERPLATE;
728

729 730 731
    if( p_input )
    {
        vlc_object_yield( p_input );
732
        varnames.push_back( "audio-es" );
733
        InputAutoMenuBuilder( VLC_OBJECT( p_input ), objects, varnames );
734 735 736
        PUSH_SEPARATOR;
    }

737 738
    QMenu *menu = new QMenu();
    Populate( p_intf, menu, varnames, objects );
739

740
    menu->addSeparator();
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
741
    PopupMenuControlEntries( menu, p_intf, p_input );
742 743

    menu->addSeparator();
744
    PopupMenuStaticEntries( p_intf, menu );
745

746 747
    p_intf->p_sys->p_popup_menu = menu;
    menu->popup( QCursor::pos() );
748 749 750
    p_intf->p_sys->p_popup_menu = NULL;
}

751
/* Main Menu that sticks everything together  */
Damien Fouilleul's avatar
Damien Fouilleul committed
752
void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show )
753
{
754
    MainInterface *mi = p_intf->p_sys->p_mi;
Damien Fouilleul's avatar
Damien Fouilleul committed
755
    if( show )
756
    {
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
757 758 759 760 761 762 763 764 765 766 767 768
        /* 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;

        POPUP_BOILERPLATE;

        PopupMenuControlEntries( menu, p_intf, p_input );
        menu->addSeparator();
769
        bool b_fullscreen;
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
770 771

        if( p_input )
772
        {
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
773 774 775 776 777
            vlc_object_yield( p_input );
            InputAutoMenuBuilder( VLC_OBJECT( p_input ), objects, varnames );

            vlc_object_t *p_aout = ( vlc_object_t * )
                vlc_object_find( p_input, VLC_OBJECT_AOUT, FIND_ANYWHERE );
778 779 780 781 782 783 784 785 786
            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 );
                val.b_bool = !val.b_bool;
787
                CreateAndConnect( menu, "fullscreen", qtr( "Fullscreen" ), "",
788 789 790 791 792 793
                     ITEM_CHECK, p_vout->i_object_id, val, VLC_VAR_BOOL,
                     !val.b_bool );
                b_fullscreen = !val.b_bool;
            }

            /* Audio menu */
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
794 795 796 797 798 799 800 801 802 803 804
            AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
            if( p_aout )
                vlc_object_release( p_aout );
            submenu = Populate( p_intf, NULL, varnames, objects );
            varnames.clear(); objects.clear();
            action = menu->addMenu( submenu );
            action->setText( qtr( "Audio" ) );
            if( submenu->isEmpty() )
                action->setEnabled( false );

            /* Video menu */
805 806 807 808 809 810 811 812
            submenu = new QMenu();
            ACT_ADD( submenu, "video-es", qtr( "Video Track" ) );
            QMenu *subsubmenu = new QMenu( qtr( "&Subtitles Track" ), submenu );
            addDPStaticEntry( subsubmenu, qtr( "Load File..." ), "", "",
                              SLOT( loadSubtitlesFile() ) );
            action = submenu->addMenu( subsubmenu );
            action->setData( "spu-es" );

Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
813 814 815
            VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
            if( p_vout )
                vlc_object_release( p_vout );
816
            Populate( p_intf, submenu, varnames, objects );
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
817 818 819 820 821 822 823
            varnames.clear(); objects.clear();
            action = menu->addMenu( submenu );
            action->setText( qtr( "Video" ) );
            if( submenu->isEmpty() )
                action->setEnabled( false );

            vlc_object_release( p_input );
824
        }
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
825 826

        menu->addSeparator();
827 828 829 830 831 832 833

        /* Add some special entries for windowed mode */
        if( !b_fullscreen )
        {
            submenu = new QMenu( qtr( "Interface" ), menu );
            submenu->addAction( QIcon( ":/pixmaps/playlist_16px.png" ),
                 qtr( "Show Playlist" ), mi, SLOT( togglePlaylist() ) );
834 835 836 837 838 839 840 841 842 843 844 845
            addDPStaticEntry( submenu, qtr( I_MENU_EXT ), "",
                 ":/pixmaps/menus_settings_16px.png", SLOT( extendedDialog() ) );
            action = submenu->addAction( QIcon( "" ),
                 qtr( "Minimal View..." ), mi, SLOT( toggleMinimalView() ) );
            action->setCheckable( true );
            action->setChecked( !( mi->getControlsVisibilityStatus() &
                                   CONTROLS_VISIBLE ) );
            action = submenu->addAction( QIcon( "" ),
                 qtr( "Toggle Fullscreen Interface" ),
                 mi, SLOT( toggleFullScreen() ) );
            action->setCheckable( true );
            action->setChecked( mi->isFullScreen() );
846 847 848
            menu->addMenu( submenu );
        }

Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
849 850 851
        PopupMenuStaticEntries( p_intf, menu );

        p_intf->p_sys->p_popup_menu = menu;
852
        p_intf->p_sys->p_popup_menu->popup( QCursor::pos() );
Damien Fouilleul's avatar
Damien Fouilleul committed
853 854
    }
    else
855
    {
856 857 858
        // destroy popup if there is one
        delete p_intf->p_sys->p_popup_menu;
        p_intf->p_sys->p_popup_menu = NULL;
859 860 861
    }
}

862 863
#undef ACT_ADD

864 865 866 867
/************************************************************************
 * Systray Menu                                                         *
 ************************************************************************/

868 869 870
void QVLCMenu::updateSystrayMenu( MainInterface *mi,
                                  intf_thread_t *p_intf,
                                  bool b_force_visible )
871 872
{
    POPUP_BOILERPLATE;
873 874

    /* Get the systray menu and clean it */
875 876
    QMenu *sysMenu = mi->getSysTrayMenu();
    sysMenu->clear();
877 878

    /* Hide / Show VLC and cone */
879
    if( mi->isVisible() || b_force_visible )
880
    {
881
        sysMenu->addAction( QIcon( ":/vlc16.png" ),
882
                qtr( "Hide VLC media player in taskbar" ), mi,
883
                SLOT( toggleUpdateSystrayMenu() ) );
884 885 886
    }
    else
    {
887
        sysMenu->addAction( QIcon( ":/vlc16.png" ),
888
                qtr( "Show VLC media player" ), mi,
889
                SLOT( toggleUpdateSystrayMenu() ) );
890
    }
891

892
    sysMenu->addSeparator();
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
893
    PopupMenuControlEntries( sysMenu, p_intf, p_input );
894

895
    sysMenu->