menus.cpp 41.9 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
#include "menus.hpp"
#include "dialogs_provider.hpp"
#include "input_manager.hpp"
Ludovic Fauvet's avatar
Ludovic Fauvet committed
42
#include "recents.hpp"
Clément Stenac's avatar
Clément Stenac committed
43

44 45 46 47 48 49
#include <QMenu>
#include <QMenuBar>
#include <QAction>
#include <QActionGroup>
#include <QSignalMapper>
#include <QSystemTrayIcon>
Ludovic Fauvet's avatar
Ludovic Fauvet committed
50
#include <QList>
51

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


  */

68 69 70 71 72 73 74 75 76
enum
{
    ITEM_NORMAL,
    ITEM_CHECK,
    ITEM_RADIO
};

static QActionGroup *currentGroup;

77 78 79 80
/* HACK for minimalView to go around a Qt bug/feature
 * that doesn't update the QAction checked state when QMenu is hidden */
QAction *QVLCMenu::minimalViewAction = NULL;

Ludovic Fauvet's avatar
Ludovic Fauvet committed
81 82
QMenu *QVLCMenu::recentsMenu = NULL;

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

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

128 129 130 131 132 133
void EnableDPStaticEntries( QMenu *menu, bool enable = true )
{
    if( !menu )
        return;

    QAction *action;
134
    foreach( action, menu->actions() )
135 136 137 138 139 140
    {
        if( action->data().toString() == "_static_" )
            action->setEnabled( enable );
    }
}

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

159
/*****************************************************************************
160
 * Definitions of variables for the dynamic menus
161
 *****************************************************************************/
162
#define PUSH_VAR( var ) varnames.push_back( var ); \
163
    objects.push_back( VLC_OBJECT(p_object) )
164 165

#define PUSH_INPUTVAR( var ) varnames.push_back( var ); \
166
    objects.push_back( VLC_OBJECT(p_input) );
167 168

#define PUSH_SEPARATOR if( objects.size() != i_last_separator ) { \
169
    objects.push_back( 0 ); varnames.push_back( "" ); \
170
    i_last_separator = objects.size(); }
171 172

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

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

203
    if( p_object )
204
    {
205 206 207 208 209 210
        /* p_object is the vout, so the decoder is our parent and the
         * postproc filter one of the decoder's children */
        vlc_object_t *p_dec = (vlc_object_t *)
                              vlc_object_find( p_object, VLC_OBJECT_DECODER,
                                               FIND_PARENT );
        if( p_dec )
211
        {
212 213 214 215 216 217 218 219 220 221 222
            vlc_object_t *p_pp = (vlc_object_t *)
                                 vlc_object_find_name( p_dec, "postproc",
                                                       FIND_CHILD );
            if( p_pp )
            {
                p_object = p_pp;
                PUSH_VAR( "postproc-q" );
                vlc_object_release( p_pp );
            }

            vlc_object_release( p_dec );
223
        }
224 225 226 227 228
    }
    return VLC_SUCCESS;
}

static int AudioAutoMenuBuilder( vlc_object_t *p_object,
229
        input_thread_t *p_input,
230
        vector<vlc_object_t *> &objects,
231
        vector<const char *> &varnames )
232
{
233
    PUSH_INPUTVAR( "audio-es" );
234 235
    PUSH_VAR( "audio-device" );
    PUSH_VAR( "audio-channels" );
236
    PUSH_VAR( "visual" );
237 238 239
    return VLC_SUCCESS;
}

240 241 242
static QAction * FindActionWithVar( QMenu *menu, const char *psz_var )
{
    QAction *action;
243
    foreach( action, menu->actions() )
244 245 246 247 248 249 250
    {
        if( action->data().toString() == psz_var )
            return action;
    }
    return NULL;
}

251 252
/*****************************************************************************
 * All normal menus
253
 * Simple Code
254 255 256
 *****************************************************************************/

#define BAR_ADD( func, title ) { \
257
    QMenu *_menu = func; _menu->setTitle( title ); bar->addMenu( _menu ); }
258 259

#define BAR_DADD( func, title, id ) { \
260 261 262 263 264 265 266 267
    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 ); }
268

269 270 271
/**
 * Main Menu Bar Creation
 **/
272 273 274
void QVLCMenu::createMenuBar( MainInterface *mi,
                              intf_thread_t *p_intf,
                              bool visual_selector_enabled )
Clément Stenac's avatar
Qt4:  
Clément Stenac committed
275
{
276 277 278
    /* QMainWindows->menuBar()
       gives the QProcess::destroyed timeout issue on Cleanlooks style with
       setDesktopAware set to false */
279
    QMenuBar *bar = mi->menuBar();
Ludovic Fauvet's avatar
Ludovic Fauvet committed
280
    BAR_ADD( FileMenu( p_intf ), qtr( "&Media" ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
281 282 283

    BAR_DADD( AudioMenu( p_intf, NULL ), qtr( "&Audio" ), 1 );
    BAR_DADD( VideoMenu( p_intf, NULL ), qtr( "&Video" ), 2 );
284
    BAR_DADD( NavigMenu( p_intf, NULL ), qtr( "P&layback" ), 3 );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
285

286
    BAR_ADD( PlaylistMenu( p_intf, mi ), qtr( "&Playlist" ) );
287
    BAR_ADD( ToolsMenu( p_intf, NULL, mi, visual_selector_enabled, true ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
288
             qtr( "&Tools" ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
289

290
    BAR_ADD( HelpMenu( NULL ), qtr( "&Help" ) );
291
}
292 293
#undef BAR_ADD
#undef BAR_DADD
294 295

/**
296
 * Media ( File ) Menu
297 298
 * Opening, streaming and quit
 **/
Ludovic Fauvet's avatar
Ludovic Fauvet committed
299
QMenu *QVLCMenu::FileMenu( intf_thread_t *p_intf )
300 301
{
    QMenu *menu = new QMenu();
302

303
    addDPStaticEntry( menu, qtr( "&Open File..." ), "",
304 305 306 307
#ifdef WIN32
        ":/file-asym", SLOT( simpleOpenDialog() ), "Ctrl+O" );
    addDPStaticEntry( menu, qtr( "Advanced Open File..." ), "",
        ":/file-asym", SLOT( openFileDialog() ), "" );
308 309 310
#else
        ":/file-asym", SLOT( openFileDialog() ), "Ctrl+0" );
#endif
311
    addDPStaticEntry( menu, qtr( I_OPEN_FOLDER ), "",
312
        ":/folder-grey", SLOT( PLOpenDir() ), "Ctrl+F" );
313
    addDPStaticEntry( menu, qtr( "Open &Disc..." ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
314
        ":/disc", SLOT( openDiscDialog() ), "Ctrl+D" );
315
    addDPStaticEntry( menu, qtr( "Open &Network..." ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
316
        ":/network", SLOT( openNetDialog() ), "Ctrl+N" );
317
    addDPStaticEntry( menu, qtr( "Open &Capture Device..." ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
318
        ":/capture-card", SLOT( openCaptureDialog() ),
319
        "Ctrl+C" );
Ludovic Fauvet's avatar
Ludovic Fauvet committed
320 321 322
    recentsMenu = new QMenu( qtr( "Recently played" ), menu );
    updateRecents( p_intf );
    menu->addMenu( recentsMenu );
323
    menu->addSeparator();
324

325 326
    addDPStaticEntry( menu, qtr( "Conve&rt / Save..." ), "", "",
        SLOT( openThenTranscodingDialogs() ), "Ctrl+R" );
327
    addDPStaticEntry( menu, qtr( "&Streaming..." ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
328
        ":/stream", SLOT( openThenStreamingDialogs() ),
329
        "Ctrl+S" );
330
    menu->addSeparator();
331 332

    addDPStaticEntry( menu, qtr( "&Quit" ) , "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
333
        ":/quit", SLOT( quit() ), "Ctrl+Q" );
334 335 336
    return menu;
}

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
337
/* Playlist/MediaLibrary Control */
338
QMenu *QVLCMenu::PlaylistMenu( intf_thread_t *p_intf, MainInterface *mi )
Clément Stenac's avatar
Clément Stenac committed
339 340 341
{
    QMenu *menu = new QMenu();
    menu->addMenu( SDMenu( p_intf ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
342
    menu->addAction( QIcon( ":/playlist_menu" ),
343
                     qtr( "Show P&laylist" ), mi, SLOT( togglePlaylist() ) );
Clément Stenac's avatar
Clément Stenac committed
344 345
    menu->addSeparator();

346 347 348 349
    addDPStaticEntry( menu, qtr( I_PL_LOAD ), "", "", SLOT( openAPlaylist() ),
        "Ctrl+X" );
    addDPStaticEntry( menu, qtr( I_PL_SAVE ), "", "", SLOT( saveAPlaylist() ),
        "Ctrl+Y" );
350
    /*menu->addSeparator();
351
    menu->addAction( qtr( "Undock from Interface" ), mi,
352
                     SLOT( undockPlaylist() ), qtr( "Ctrl+U" ) );*/
Clément Stenac's avatar
Clément Stenac committed
353 354 355
    return menu;
}

356 357
/**
 * Tools/View Menu
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
358
 * This is kept in the same menu for now, but could change if it gets much
359
 * longer.
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
360
 * This menu can be an interface menu but also a right click menu.
361
 **/
362
QMenu *QVLCMenu::ToolsMenu( intf_thread_t *p_intf,
363
                            QMenu *current,
364 365 366
                            MainInterface *mi,
                            bool visual_selector_enabled,
                            bool with_intf )
367
{
368
    QMenu *menu = new QMenu( current );
369 370
    if( mi )
    {
371
        QAction *act=
372 373
            menu->addAction( QIcon( ":/playlist_menu" ), qtr( "Play&list..." ),
                    mi, SLOT( togglePlaylist() ), qtr( "Ctrl+L" ) );
374
        act->setData( "_static_" );
375
    }
376 377
    addDPStaticEntry( menu, qtr( I_MENU_EXT ), "", ":/settings",
            SLOT( extendedDialog() ), "Ctrl+E" );
378 379 380

    menu->addSeparator();

381 382
    if( with_intf )
    {
383
        QMenu *intfmenu = InterfacesMenu( p_intf, menu );
384 385 386
        MenuFunc *f = new MenuFunc( intfmenu, 4 );
        CONNECT( intfmenu, aboutToShow(), THEDP->menusUpdateMapper, map() );
        THEDP->menusUpdateMapper->setMapping( intfmenu, f );
387 388
        menu->addSeparator();
    }
Clément Stenac's avatar
Clément Stenac committed
389 390
    if( mi )
    {
391
        /* Minimal View */
392
        QAction *action = menu->addAction( qtr( "Mi&nimal View" ), mi,
393
                                SLOT( toggleMinimalView() ), qtr( "Ctrl+H" ) );
394
        action->setCheckable( true );
395
        action->setData( "_static_" );
396
        if( mi->getControlsVisibilityStatus() & CONTROLS_VISIBLE )
397
            action->setChecked( true );
398
        minimalViewAction = action; /* HACK for minimalView */
399

400
        /* FullScreen View */
401
        action = menu->addAction( qtr( "&Fullscreen Interface" ), mi,
402
                                  SLOT( toggleFullScreen() ), QString( "F11" ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
403
        action->setCheckable( true );
404
        action->setData( "_static_" );
405

406
        /* Advanced Controls */
407
        action = menu->addAction( qtr( "&Advanced Controls" ), mi,
408
                                  SLOT( toggleAdvanced() ) );
409
        action->setCheckable( true );
410
        action->setData( "_static_" );
411 412
        if( mi->getControlsVisibilityStatus() & CONTROLS_ADVANCED )
            action->setChecked( true );
413
#if 0 /* For Visualisations. Not yet working */
414
        adv = menu->addAction( qtr( "Visualizations selector" ),
415
                mi, SLOT( visual() ) );
416 417
        adv->setCheckable( true );
        if( visual_selector_enabled ) adv->setChecked( true );
418
#endif
Clément Stenac's avatar
Clément Stenac committed
419
    }
420

421 422
    menu->addSeparator();

423
    addDPStaticEntry( menu, qtr( I_MENU_MSG ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
424
        ":/messages", SLOT( messagesDialog() ),
425
        "Ctrl+M" );
426
    addDPStaticEntry( menu, qtr( I_MENU_INFO ) , "", ":/info",
427 428
        SLOT( mediaInfoDialog() ), "Ctrl+I" );
    addDPStaticEntry( menu, qtr( I_MENU_CODECINFO ) , "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
429
        ":/info", SLOT( mediaCodecDialog() ), "Ctrl+J" );
430
    addDPStaticEntry( menu, qtr( I_MENU_BOOKMARK ), "","",
431
                      SLOT( bookmarksDialog() ), "Ctrl+B" );
432
#ifdef ENABLE_VLM
433
    addDPStaticEntry( menu, qtr( I_MENU_VLM ), "", "", SLOT( vlmDialog() ),
434
        "Ctrl+W" );
435
#endif
436

437
    menu->addSeparator();
438
    addDPStaticEntry( menu, qtr( "&Preferences..." ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
439
        ":/preferences", SLOT( prefsDialog() ), "Ctrl+P" );
440 441 442
    return menu;
}

443 444 445
/**
 * Interface Sub-Menu, to list extras interface and skins
 **/
446 447
QMenu *QVLCMenu::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
{
448
    vector<vlc_object_t *> objects;
449 450 451
    vector<const char *> varnames;
    /** \todo add "switch to XXX" */
    varnames.push_back( "intf-add" );
452
    objects.push_back( VLC_OBJECT(p_intf) );
Clément Stenac's avatar
Qt4:  
Clément Stenac committed
453

454
    return Populate( p_intf, current, varnames, objects );
455 456
}

457 458 459
/**
 * Main Audio Menu
 */
460 461
QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QMenu * current )
{
462
    vector<vlc_object_t *> objects;
463
    vector<const char *> varnames;
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
464
    vlc_object_t *p_aout;
465 466
    input_thread_t *p_input;

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

469
    if( current->isEmpty() )
470
    {
471 472 473
        ACT_ADD( current, "audio-es", qtr( "Audio &Track" ) );
        ACT_ADD( current, "audio-device", qtr( "Audio &Device" ) );
        ACT_ADD( current, "audio-channels", qtr( "Audio &Channels" ) );
474 475
        current->addSeparator();
        ACT_ADD( current, "visual", qtr( "&Visualizations" ) );
476 477
    }

478 479
    p_input = THEMIM->getInput();
    if( p_input )
480
        vlc_object_hold( p_input );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
481 482 483
    p_aout = ( vlc_object_t * ) vlc_object_find( p_intf,
                                                 VLC_OBJECT_AOUT,
                                                 FIND_ANYWHERE );
484

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

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
487 488
    if( p_aout )
        vlc_object_release( p_aout );
489 490 491
    if( p_input )
        vlc_object_release( p_input );

492 493 494
    return Populate( p_intf, current, varnames, objects );
}

495 496 497 498
/**
 * Main Video Menu
 * Subtitles are part of Video.
 **/
499
QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current )
500
{
501
    vlc_object_t *p_vout;
502
    input_thread_t *p_input;
503
    vector<vlc_object_t *> objects;
504 505
    vector<const char *> varnames;

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
506
    if( !current ) current = new QMenu();
507 508

    if( current->isEmpty() )
509
    {
510
        ACT_ADD( current, "video-es", qtr( "Video &Track" ) );
511 512 513 514 515

        QAction *action;
        QMenu *submenu = new QMenu( qtr( "&Subtitles Track" ), current );
        action = current->addMenu( submenu );
        action->setData( "spu-es" );
516
        addDPStaticEntry( submenu, qtr( "Open File..." ), "", "",
517
                          SLOT( loadSubtitlesFile() ) );
518
        submenu->addSeparator();
519

520
        ACT_ADD( current, "fullscreen", qtr( "&Fullscreen" ) );
521 522 523 524 525
        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" ) );
526 527 528
#ifdef WIN32
        ACT_ADD( current, "directx-wallpaper", qtr( "DirectX Wallpaper" ) );
#endif
529
        ACT_ADD( current, "video-snapshot", qtr( "Sna&pshot" ) );
530
        ACT_ADD( current, "postproc-q", qtr( "Post processing" ) );
531
    }
532

533 534
    p_input = THEMIM->getInput();
    if( p_input )
535
        vlc_object_hold( p_input );
536
    p_vout = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_VOUT,
537
            FIND_ANYWHERE );
538

539
    VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
540

541 542
    if( p_vout )
        vlc_object_release( p_vout );
543 544 545
    if( p_input )
        vlc_object_release( p_input );

546
    return Populate( p_intf, current, varnames, objects );
547 548
}

549 550 551 552
/**
 * Navigation Menu
 * For DVD, MP4, MOV and other chapter based format
 **/
553
QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *menu )
554 555
{
    vlc_object_t *p_object;
556
    vector<vlc_object_t *> objects;
557
    vector<const char *> varnames;
558

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
559
    if( !menu ) menu = new QMenu();
560 561 562

    if( menu->isEmpty() )
    {
563 564 565
        addDPStaticEntry( menu, qtr( I_MENU_GOTOTIME ), "","",
                          SLOT( gotoTimeDialog() ), "Ctrl+T" );
        menu->addSeparator();
566 567

        ACT_ADD( menu, "bookmark", qtr( "&Bookmarks" ) );
568
        ACT_ADD( menu, "title", qtr( "T&itle" ) );
569 570 571
        ACT_ADD( menu, "chapter", qtr( "&Chapter" ) );
        ACT_ADD( menu, "program", qtr( "&Program" ) );
        ACT_ADD( menu, "navigation", qtr( "&Navigation" ) );
572 573
    }

574
    p_object = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_INPUT,
575
            FIND_ANYWHERE );
576 577 578 579 580
    InputAutoMenuBuilder(  p_object, objects, varnames );
    PUSH_VAR( "prev-title" );
    PUSH_VAR( "next-title" );
    PUSH_VAR( "prev-chapter" );
    PUSH_VAR( "next-chapter" );
581
    EnableDPStaticEntries( menu, ( p_object != NULL ) );
582
    if( p_object )
583
    {
584
        vlc_object_release( p_object );
585 586
    }
    return Populate( p_intf, menu, varnames, objects, true );
587
}
588

589
/**
590
 * Service Discovery SubMenu
591
 **/
Clément Stenac's avatar
Clément Stenac committed
592 593 594
QMenu *QVLCMenu::SDMenu( intf_thread_t *p_intf )
{
    QMenu *menu = new QMenu();
595
    menu->setTitle( qtr( I_PL_SD ) );
596 597 598
    char **ppsz_longnames;
    char **ppsz_names = services_discovery_GetServicesNames( p_intf,
                                                             &ppsz_longnames );
599 600 601
    if( !ppsz_names )
        return menu;

602 603
    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
604
    {
605
        QAction *a = new QAction( qfu( *ppsz_longname ), menu );
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
606
        a->setCheckable( true );
607
        if( playlist_IsServicesDiscoveryLoaded( THEPL, *ppsz_name ) )
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
608 609
            a->setChecked( true );
        CONNECT( a , triggered(), THEDP->SDMapper, map() );
610
        THEDP->SDMapper->setMapping( a, QString( *ppsz_name ) );
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
611
        menu->addAction( a );
612

613
        if( !strcmp( *ppsz_name, "podcast" ) )
614
        {
Christophe Mutricy's avatar
Christophe Mutricy committed
615
            QAction *b = new QAction( qtr( "Configure podcasts..." ), menu );
616 617 618 619
            //b->setEnabled( a->isChecked() );
            menu->addAction( b );
            CONNECT( b, triggered(), THEDP, podcastConfigureDialog() );
        }
620 621
        free( *ppsz_name );
        free( *ppsz_longname );
Clément Stenac's avatar
Clément Stenac committed
622
    }
623 624
    free( ppsz_names );
    free( ppsz_longnames );
Clément Stenac's avatar
Clément Stenac committed
625 626
    return menu;
}
627 628 629
/**
 * Help/About Menu
**/
630
QMenu *QVLCMenu::HelpMenu( QMenu *current )
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
631
{
632
    QMenu *menu = new QMenu( current );
633
    addDPStaticEntry( menu, qtr( "&Help..." ) , "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
634
        ":/help", SLOT( helpDialog() ), "F1" );
635
#ifdef UPDATE_CHECK
636
    addDPStaticEntry( menu, qtr( "Check for &Updates..." ) , "", "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
637
                      SLOT( updateDialog() ), "");
638
#endif
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
639
    menu->addSeparator();
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
640
    addDPStaticEntry( menu, qtr( I_MENU_ABOUT ), "", ":/info",
641
            SLOT( aboutDialog() ), "Shift+F1" );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
642 643 644
    return menu;
}

645
/*****************************************************************************
646
 * Popup menus - Right Click menus                                           *
647
 *****************************************************************************/
648 649
#define POPUP_BOILERPLATE \
    unsigned int i_last_separator = 0; \
650
    vector<vlc_object_t *> objects; \
651 652 653 654 655 656 657
    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() ); \
658
    p_intf->p_sys->p_popup_menu = NULL; \
659
    i_last_separator = 0;
660

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
661 662 663 664 665 666 667 668 669 670
void QVLCMenu::PopupMenuControlEntries( QMenu *menu,
                                        intf_thread_t *p_intf,
                                        input_thread_t *p_input )
{
    if( p_input )
    {
        vlc_value_t val;
        var_Get( p_input, "state", &val );
        if( val.i_int == PLAYING_S )
            addMIMStaticEntry( p_intf, menu, qtr( "Pause" ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
671
                    ":/pause", SLOT( togglePlayPause() ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
672 673
        else
            addMIMStaticEntry( p_intf, menu, qtr( "Play" ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
674
                    ":/play", SLOT( togglePlayPause() ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
675
    }
676
    else if( THEPL->items.i_size )
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
677
        addMIMStaticEntry( p_intf, menu, qtr( "Play" ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
678
                ":/play", SLOT( togglePlayPause() ) );
679 680
    else
        addDPStaticEntry( menu, qtr( "Play" ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
681
                ":/play", SLOT( openDialog() ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
682 683

    addMIMStaticEntry( p_intf, menu, qtr( "Stop" ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
684
            ":/stop", SLOT( stop() ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
685
    addMIMStaticEntry( p_intf, menu, qtr( "Previous" ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
686
            ":/previous", SLOT( prev() ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
687
    addMIMStaticEntry( p_intf, menu, qtr( "Next" ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
688
            ":/next", SLOT( next() ) );
689
}
690 691 692

void QVLCMenu::PopupMenuStaticEntries( intf_thread_t *p_intf, QMenu *menu )
{
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
693
#if 0
694
    QMenu *toolsmenu = ToolsMenu( p_intf, menu, false, true );
695 696
    toolsmenu->setTitle( qtr( "Tools" ) );
    menu->addMenu( toolsmenu );
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
697
#endif
698

699
    QMenu *openmenu = new QMenu( qtr( "Open" ), menu );
700
    addDPStaticEntry( openmenu, qtr( "&Open File..." ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
701
        ":/file-asym", SLOT( openFileDialog() ) );
702
    addDPStaticEntry( openmenu, qtr( I_OPEN_FOLDER ), "",
703
        ":/folder-grey", SLOT( PLOpenDir() ) );
704
    addDPStaticEntry( openmenu, qtr( "Open &Disc..." ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
705
        ":/disc", SLOT( openDiscDialog() ) );
706
    addDPStaticEntry( openmenu, qtr( "Open &Network..." ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
707
        ":/network", SLOT( openNetDialog() ) );
708
    addDPStaticEntry( openmenu, qtr( "Open &Capture Device..." ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
709
        ":/capture-card", SLOT( openCaptureDialog() ) );
710 711 712
    menu->addMenu( openmenu );

    menu->addSeparator();
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
713
#if 0
714
    QMenu *helpmenu = HelpMenu( menu );
715 716
    helpmenu->setTitle( qtr( "Help" ) );
    menu->addMenu( helpmenu );
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
717
#endif
718

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
719
    addDPStaticEntry( menu, qtr( "Quit" ), "", ":/quit",
720
                      SLOT( quit() ), "Ctrl+Q" );
721
}
Clément Stenac's avatar
Qt4:  
Clément Stenac committed
722

723
/* Video Tracks and Subtitles tracks */
724
void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf )
725 726 727 728
{
    POPUP_BOILERPLATE;
    if( p_input )
    {
729
        vlc_object_hold( p_input );
730
        vlc_object_t *p_vout = ( vlc_object_t * )vlc_object_find( p_input,
731
                VLC_OBJECT_VOUT, FIND_CHILD );
732 733
        if( p_vout )
        {
734
            VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
735 736 737 738
            vlc_object_release( p_vout );
        }
        vlc_object_release( p_input );
    }
739
    QMenu *menu = new QMenu();
740
    CREATE_POPUP;
741 742
}

743
/* Audio Tracks */
744
void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf )
745 746 747 748
{
    POPUP_BOILERPLATE;
    if( p_input )
    {
749
        vlc_object_hold( p_input );