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 76 77 78
/* HACK for minimalView to go around a Qt bug/feature
 * that doesn't update the QAction checked state when QMenu is hidden */
QAction *QVLCMenu::minimalViewAction = NULL;

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

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

124 125 126 127 128 129
void EnableDPStaticEntries( QMenu *menu, bool enable = true )
{
    if( !menu )
        return;

    QAction *action;
130
    foreach( action, menu->actions() )
131 132 133 134 135 136
    {
        if( action->data().toString() == "_static_" )
            action->setEnabled( enable );
    }
}

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

155
/*****************************************************************************
156
 * Definitions of variables for the dynamic menus
157
 *****************************************************************************/
158
#define PUSH_VAR( var ) varnames.push_back( var ); \
159 160 161 162
    objects.push_back( p_object ? p_object->i_object_id : 0 )

#define PUSH_INPUTVAR( var ) varnames.push_back( var ); \
    objects.push_back( p_input ? p_input->i_object_id : 0 );
163 164

#define PUSH_SEPARATOR if( objects.size() != i_last_separator ) { \
165
    objects.push_back( 0 ); varnames.push_back( "" ); \
166
    i_last_separator = objects.size(); }
167 168

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

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

199
    if( p_object )
200
    {
201 202 203 204 205 206 207 208 209
        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 );
        }
210 211 212 213 214
    }
    return VLC_SUCCESS;
}

static int AudioAutoMenuBuilder( vlc_object_t *p_object,
215
        input_thread_t *p_input,
216
        vector<int> &objects,
217
        vector<const char *> &varnames )
218
{
219
    PUSH_INPUTVAR( "audio-es" );
220 221
    PUSH_VAR( "audio-device" );
    PUSH_VAR( "audio-channels" );
222
    PUSH_VAR( "visual" );
223 224 225
    return VLC_SUCCESS;
}

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

237 238
/*****************************************************************************
 * All normal menus
239
 * Simple Code
240 241 242
 *****************************************************************************/

#define BAR_ADD( func, title ) { \
243
    QMenu *_menu = func; _menu->setTitle( title ); bar->addMenu( _menu ); }
244 245

#define BAR_DADD( func, title, id ) { \
246 247 248 249 250 251 252 253
    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 ); }
254

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

/**
279
 * Media ( File ) Menu
280 281
 * Opening, streaming and quit
 **/
282 283 284
QMenu *QVLCMenu::FileMenu()
{
    QMenu *menu = new QMenu();
285

286
    addDPStaticEntry( menu, qtr( "&Open File..." ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
287
        ":/file-asym", SLOT( openFileDialog() ), "Ctrl+O" );
288
    addDPStaticEntry( menu, qtr( I_OPEN_FOLDER ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
289
        ":/folder-grey", SLOT( PLAppendDir() ), "Ctrl+F" );
290
    addDPStaticEntry( menu, qtr( "Open &Disc..." ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
291
        ":/disc", SLOT( openDiscDialog() ), "Ctrl+D" );
292
    addDPStaticEntry( menu, qtr( "Open &Network..." ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
293
        ":/network", SLOT( openNetDialog() ), "Ctrl+N" );
294
    addDPStaticEntry( menu, qtr( "Open &Capture Device..." ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
295
        ":/capture-card", SLOT( openCaptureDialog() ),
296
        "Ctrl+C" );
297
    menu->addSeparator();
298

299
    addDPStaticEntry( menu, qtr( "&Streaming..." ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
300
        ":/stream", SLOT( openThenStreamingDialogs() ),
301 302 303
        "Ctrl+S" );
    addDPStaticEntry( menu, qtr( "Conve&rt / Save..." ), "", "",
        SLOT( openThenTranscodingDialogs() ), "Ctrl+R" );
304
    menu->addSeparator();
305 306

    addDPStaticEntry( menu, qtr( "&Quit" ) , "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
307
        ":/quit", SLOT( quit() ), "Ctrl+Q" );
308 309 310
    return menu;
}

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
311
/* Playlist/MediaLibrary Control */
312
QMenu *QVLCMenu::PlaylistMenu( intf_thread_t *p_intf, MainInterface *mi )
Clément Stenac's avatar
Clément Stenac committed
313 314 315
{
    QMenu *menu = new QMenu();
    menu->addMenu( SDMenu( p_intf ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
316
    menu->addAction( QIcon( ":/playlist_menu" ),
317
                     qtr( "Show P&laylist" ), mi, SLOT( togglePlaylist() ) );
Clément Stenac's avatar
Clément Stenac committed
318 319
    menu->addSeparator();

320 321 322 323
    addDPStaticEntry( menu, qtr( I_PL_LOAD ), "", "", SLOT( openAPlaylist() ),
        "Ctrl+X" );
    addDPStaticEntry( menu, qtr( I_PL_SAVE ), "", "", SLOT( saveAPlaylist() ),
        "Ctrl+Y" );
324
    /*menu->addSeparator();
325
    menu->addAction( qtr( "Undock from Interface" ), mi,
326
                     SLOT( undockPlaylist() ), qtr( "Ctrl+U" ) );*/
Clément Stenac's avatar
Clément Stenac committed
327 328 329
    return menu;
}

330 331
/**
 * Tools/View Menu
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
332
 * This is kept in the same menu for now, but could change if it gets much
333
 * longer.
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
334
 * This menu can be an interface menu but also a right click menu.
335
 **/
336
QMenu *QVLCMenu::ToolsMenu( intf_thread_t *p_intf,
337
                            QMenu *current,
338 339 340
                            MainInterface *mi,
                            bool visual_selector_enabled,
                            bool with_intf )
341
{
342
    QMenu *menu = new QMenu( current );
343 344
    if( mi )
    {
345
        QAction *act=
346 347
            menu->addAction( QIcon( ":/playlist_menu" ), qtr( "Play&list..." ),
                    mi, SLOT( togglePlaylist() ), qtr( "Ctrl+L" ) );
348
        act->setData( "_static_" );
349
    }
350 351
    addDPStaticEntry( menu, qtr( I_MENU_EXT ), "", ":/settings",
            SLOT( extendedDialog() ), "Ctrl+E" );
352 353 354

    menu->addSeparator();

355 356
    if( with_intf )
    {
357
        QMenu *intfmenu = InterfacesMenu( p_intf, menu );
358 359 360
        MenuFunc *f = new MenuFunc( intfmenu, 4 );
        CONNECT( intfmenu, aboutToShow(), THEDP->menusUpdateMapper, map() );
        THEDP->menusUpdateMapper->setMapping( intfmenu, f );
361 362
        menu->addSeparator();
    }
Clément Stenac's avatar
Clément Stenac committed
363 364
    if( mi )
    {
365
        /* Minimal View */
366
        QAction *action = menu->addAction( qtr( "Mi&nimal View..." ), mi,
367
                                SLOT( toggleMinimalView() ), qtr( "Ctrl+H" ) );
368
        action->setCheckable( true );
369
        action->setData( "_static_" );
370
        if( mi->getControlsVisibilityStatus() & CONTROLS_VISIBLE )
371
            action->setChecked( true );
372
        minimalViewAction = action; /* HACK for minimalView */
373

374
        /* FullScreen View */
375
        action = menu->addAction( qtr( "&Fullscreen Interface" ), mi,
376
                                  SLOT( toggleFullScreen() ), QString( "F11" ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
377
        action->setCheckable( true );
378
        action->setData( "_static_" );
379

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

395 396
    menu->addSeparator();

397
    addDPStaticEntry( menu, qtr( I_MENU_MSG ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
398
        ":/messages", SLOT( messagesDialog() ),
399
        "Ctrl+M" );
400
    addDPStaticEntry( menu, qtr( I_MENU_INFO ) , "", ":/info",
401 402
        SLOT( mediaInfoDialog() ), "Ctrl+I" );
    addDPStaticEntry( menu, qtr( I_MENU_CODECINFO ) , "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
403
        ":/info", SLOT( mediaCodecDialog() ), "Ctrl+J" );
404
    addDPStaticEntry( menu, qtr( I_MENU_BOOKMARK ), "","",
405
                      SLOT( bookmarksDialog() ), "Ctrl+B" );
406
#ifdef ENABLE_VLM
407
    addDPStaticEntry( menu, qtr( I_MENU_VLM ), "", "", SLOT( vlmDialog() ),
408
        "Ctrl+W" );
409
#endif
410

411
    menu->addSeparator();
412
    addDPStaticEntry( menu, qtr( "&Preferences..." ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
413
        ":/preferences", SLOT( prefsDialog() ), "Ctrl+P" );
414 415 416
    return menu;
}

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

428
    return Populate( p_intf, current, varnames, objects );
429 430
}

431 432 433
/**
 * Main Audio Menu
 */
434 435
QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QMenu * current )
{
436
    vector<int> objects;
437
    vector<const char *> varnames;
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
438
    vlc_object_t *p_aout;
439 440
    input_thread_t *p_input;

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

443
    if( current->isEmpty() )
444
    {
445 446 447
        ACT_ADD( current, "audio-es", qtr( "Audio &Track" ) );
        ACT_ADD( current, "audio-device", qtr( "Audio &Device" ) );
        ACT_ADD( current, "audio-channels", qtr( "Audio &Channels" ) );
448 449
        current->addSeparator();
        ACT_ADD( current, "visual", qtr( "&Visualizations" ) );
450 451
    }

452 453 454
    p_input = THEMIM->getInput();
    if( p_input )
        vlc_object_yield( p_input );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
455 456 457
    p_aout = ( vlc_object_t * ) vlc_object_find( p_intf,
                                                 VLC_OBJECT_AOUT,
                                                 FIND_ANYWHERE );
458

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

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
461 462
    if( p_aout )
        vlc_object_release( p_aout );
463 464 465
    if( p_input )
        vlc_object_release( p_input );

466 467 468
    return Populate( p_intf, current, varnames, objects );
}

469 470 471 472
/**
 * Main Video Menu
 * Subtitles are part of Video.
 **/
473
QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current )
474
{
475
    vlc_object_t *p_vout;
476
    input_thread_t *p_input;
477
    vector<int> objects;
478 479
    vector<const char *> varnames;

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
480
    if( !current ) current = new QMenu();
481 482

    if( current->isEmpty() )
483
    {
484
        ACT_ADD( current, "video-es", qtr( "Video &Track" ) );
485 486 487 488 489

        QAction *action;
        QMenu *submenu = new QMenu( qtr( "&Subtitles Track" ), current );
        action = current->addMenu( submenu );
        action->setData( "spu-es" );
490 491
        addDPStaticEntry( submenu, qtr( "Load File..." ), "", "",
                          SLOT( loadSubtitlesFile() ) );
492
        submenu->addSeparator();
493

494
        ACT_ADD( current, "fullscreen", qtr( "&Fullscreen" ) );
495 496 497 498 499
        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" ) );
500 501 502
#ifdef WIN32
        ACT_ADD( current, "directx-wallpaper", qtr( "DirectX Wallpaper" ) );
#endif
503
        ACT_ADD( current, "video-snapshot", qtr( "Sna&pshot" ) );
504
        /* ACT_ADD( current, "ffmpeg-pp-q", qtr( "Decoder" ) ); */
505
    }
506

507 508 509
    p_input = THEMIM->getInput();
    if( p_input )
        vlc_object_yield( p_input );
510
    p_vout = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_VOUT,
511
            FIND_ANYWHERE );
512

513
    VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
514

515 516
    if( p_vout )
        vlc_object_release( p_vout );
517 518 519
    if( p_input )
        vlc_object_release( p_input );

520
    return Populate( p_intf, current, varnames, objects );
521 522
}

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

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
533
    if( !menu ) menu = new QMenu();
534 535 536

    if( menu->isEmpty() )
    {
537 538 539
        addDPStaticEntry( menu, qtr( I_MENU_GOTOTIME ), "","",
                          SLOT( gotoTimeDialog() ), "Ctrl+T" );
        menu->addSeparator();
540 541

        ACT_ADD( menu, "bookmark", qtr( "&Bookmarks" ) );
542
        ACT_ADD( menu, "title", qtr( "T&itle" ) );
543 544 545
        ACT_ADD( menu, "chapter", qtr( "&Chapter" ) );
        ACT_ADD( menu, "program", qtr( "&Program" ) );
        ACT_ADD( menu, "navigation", qtr( "&Navigation" ) );
546 547
    }

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

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

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

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

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

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
635 636 637 638 639 640 641 642 643 644
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
645
                    ":/pause", SLOT( togglePlayPause() ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
646 647
        else
            addMIMStaticEntry( p_intf, menu, qtr( "Play" ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
648
                    ":/play", SLOT( togglePlayPause() ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
649
    }
650
    else if( THEPL->items.i_size )
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
651
        addMIMStaticEntry( p_intf, menu, qtr( "Play" ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
652
                ":/play", SLOT( togglePlayPause() ) );
653 654
    else
        addDPStaticEntry( menu, qtr( "Play" ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
655
                ":/play", SLOT( openDialog() ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
656 657

    addMIMStaticEntry( p_intf, menu, qtr( "Stop" ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
658
            ":/stop", SLOT( stop() ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
659
    addMIMStaticEntry( p_intf, menu, qtr( "Previous" ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
660
            ":/previous", SLOT( prev() ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
661
    addMIMStaticEntry( p_intf, menu, qtr( "Next" ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
662
            ":/next", SLOT( next() ) );
663
}
664 665 666

void QVLCMenu::PopupMenuStaticEntries( intf_thread_t *p_intf, QMenu *menu )
{
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
667
#if 0
668
    QMenu *toolsmenu = ToolsMenu( p_intf, menu, false, true );
669 670
    toolsmenu->setTitle( qtr( "Tools" ) );
    menu->addMenu( toolsmenu );
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
671
#endif
672

673
    QMenu *openmenu = new QMenu( qtr( "Open" ), menu );
674
    addDPStaticEntry( openmenu, qtr( "&Open File..." ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
675
        ":/file-asym", SLOT( openFileDialog() ) );
676
    addDPStaticEntry( openmenu, qtr( I_OPEN_FOLDER ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
677
        ":/folder-grey", SLOT( PLAppendDir() ) );
678
    addDPStaticEntry( openmenu, qtr( "Open &Disc..." ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
679
        ":/disc", SLOT( openDiscDialog() ) );
680
    addDPStaticEntry( openmenu, qtr( "Open &Network..." ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
681
        ":/network", SLOT( openNetDialog() ) );
682
    addDPStaticEntry( openmenu, qtr( "Open &Capture Device..." ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
683
        ":/capture-card", SLOT( openCaptureDialog() ) );
684 685 686
    menu->addMenu( openmenu );

    menu->addSeparator();
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
687
#if 0
688
    QMenu *helpmenu = HelpMenu( menu );
689 690
    helpmenu->setTitle( qtr( "Help" ) );
    menu->addMenu( helpmenu );
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
691
#endif
692

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
693
    addDPStaticEntry( menu, qtr( "Quit" ), "", ":/quit",
694
                      SLOT( quit() ), "Ctrl+Q" );
695
}
Clément Stenac's avatar
Qt4:  
Clément Stenac committed
696

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

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

735
/* Navigation stuff, and general menus ( open ) */
736
void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf )
737
{
738
    vlc_value_t val;
739
    POPUP_BOILERPLATE;
740

741 742 743
    if( p_input )
    {
        vlc_object_yield( p_input );
744
        varnames.push_back( "audio-es" );
745
        InputAutoMenuBuilder( VLC_OBJECT( p_input ), objects, varnames );
746 747 748
        PUSH_SEPARATOR;
    }

749 750
    QMenu *menu = new QMenu();
    Populate( p_intf, menu, varnames, objects );
751

752
    menu->addSeparator();
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
753
    PopupMenuControlEntries( menu, p_intf, p_input );