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
/*
  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;

Ludovic Fauvet's avatar
Ludovic Fauvet committed
79 80
QMenu *QVLCMenu::recentsMenu = NULL;

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

112 113
void EnableDPStaticEntries( QMenu *menu, bool enable = true )
{
114
    if( !menu ) return;
115 116

    QAction *action;
117
    foreach( action, menu->actions() )
118 119 120 121 122 123
    {
        if( action->data().toString() == "_static_" )
            action->setEnabled( enable );
    }
}

124 125 126 127 128 129 130 131 132
/**
 * \return Number of static entries
 */
int DeleteNonStaticEntries( QMenu *menu )
{
    int i_ret = 0;
    QAction *action;
    if( !menu )
        return VLC_EGENERIC;
133
    foreach( action, menu->actions() )
134 135 136 137 138 139 140 141
    {
        if( action->data().toString() != "_static_" )
            delete action;
        else
            i_ret++;
    }
}

142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
/***
 * Same for MIM
 ***/
void addMIMStaticEntry( intf_thread_t *p_intf,
                        QMenu *menu,
                        const QString text,
                        const char *help,
                        const char *icon,
                        const char *member )
{
    if( strlen( icon ) > 0 )
    {
        QAction *action = menu->addAction( text, THEMIM,  member );
        action->setIcon( QIcon( icon ) );
    }
    else
    {
        menu->addAction( text, THEMIM, member );
    }
}

163
/*****************************************************************************
164
 * Definitions of variables for the dynamic menus
165
 *****************************************************************************/
166
#define PUSH_VAR( var ) varnames.push_back( var ); \
167
    objects.push_back( VLC_OBJECT(p_object) )
168 169

#define PUSH_INPUTVAR( var ) varnames.push_back( var ); \
170
    objects.push_back( VLC_OBJECT(p_input) );
171 172

#define PUSH_SEPARATOR if( objects.size() != i_last_separator ) { \
173
    objects.push_back( 0 ); varnames.push_back( "" ); \
174
    i_last_separator = objects.size(); }
175 176

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

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

207
    /* Special case for postproc */
208
    if( p_object )
209
    {
210 211 212 213 214 215
        /* 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 )
216
        {
217 218 219 220 221 222 223 224 225 226 227
            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 );
228
        }
229 230 231 232 233
    }
    return VLC_SUCCESS;
}

static int AudioAutoMenuBuilder( vlc_object_t *p_object,
234
        input_thread_t *p_input,
235
        vector<vlc_object_t *> &objects,
236
        vector<const char *> &varnames )
237
{
238
    PUSH_INPUTVAR( "audio-es" );
239 240
    PUSH_VAR( "audio-device" );
    PUSH_VAR( "audio-channels" );
241
    PUSH_VAR( "visual" );
242 243 244
    return VLC_SUCCESS;
}

245 246 247
static QAction * FindActionWithVar( QMenu *menu, const char *psz_var )
{
    QAction *action;
248
    foreach( action, menu->actions() )
249 250 251 252 253 254 255
    {
        if( action->data().toString() == psz_var )
            return action;
    }
    return NULL;
}

256 257
/*****************************************************************************
 * All normal menus
258
 * Simple Code
259 260 261
 *****************************************************************************/

#define BAR_ADD( func, title ) { \
262
    QMenu *_menu = func; _menu->setTitle( title ); bar->addMenu( _menu ); }
263 264

#define BAR_DADD( func, title, id ) { \
265 266 267 268 269 270 271 272
    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 ); }
273

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

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

291 292 293
    BAR_ADD( ToolsMenu( p_intf ), qtr( "&Tools" ) );
    BAR_ADD( ViewMenu( p_intf, NULL, mi, visual_selector_enabled, true ),
             qtr( "V&iew" ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
294

295
    BAR_ADD( HelpMenu( NULL ), qtr( "&Help" ) );
296
}
297 298
#undef BAR_ADD
#undef BAR_DADD
299 300

/**
301
 * Media ( File ) Menu
302 303
 * Opening, streaming and quit
 **/
Ludovic Fauvet's avatar
Ludovic Fauvet committed
304
QMenu *QVLCMenu::FileMenu( intf_thread_t *p_intf )
305 306
{
    QMenu *menu = new QMenu();
307

308
    addDPStaticEntry( menu, qtr( "&Open File..." ), "",
309 310 311 312
#ifdef WIN32
        ":/file-asym", SLOT( simpleOpenDialog() ), "Ctrl+O" );
    addDPStaticEntry( menu, qtr( "Advanced Open File..." ), "",
        ":/file-asym", SLOT( openFileDialog() ), "" );
313 314 315
#else
        ":/file-asym", SLOT( openFileDialog() ), "Ctrl+0" );
#endif
316
    addDPStaticEntry( menu, qtr( I_OPEN_FOLDER ), "",
317
        ":/folder-grey", SLOT( PLOpenDir() ), "Ctrl+F" );
318
    addDPStaticEntry( menu, qtr( "Open &Disc..." ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
319
        ":/disc", SLOT( openDiscDialog() ), "Ctrl+D" );
320
    addDPStaticEntry( menu, qtr( "Open &Network..." ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
321
        ":/network", SLOT( openNetDialog() ), "Ctrl+N" );
322
    addDPStaticEntry( menu, qtr( "Open &Capture Device..." ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
323
        ":/capture-card", SLOT( openCaptureDialog() ),
324
        "Ctrl+C" );
325

Ludovic Fauvet's avatar
Ludovic Fauvet committed
326 327 328
    recentsMenu = new QMenu( qtr( "Recently played" ), menu );
    updateRecents( p_intf );
    menu->addMenu( recentsMenu );
329
    menu->addSeparator();
330

331
    addDPStaticEntry( menu, qtr( "Conve&rt / Save..." ), "", "",
332
        SLOT( openAndTranscodingDialogs() ), "Ctrl+R" );
333
    addDPStaticEntry( menu, qtr( "&Streaming..." ), "",
334
        ":/stream", SLOT( openAndStreamingDialogs() ),
335
        "Ctrl+S" );
336
    menu->addSeparator();
337 338

    addDPStaticEntry( menu, qtr( "&Quit" ) , "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
339
        ":/quit", SLOT( quit() ), "Ctrl+Q" );
340 341 342
    return menu;
}

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
343
/* Playlist/MediaLibrary Control */
344
QMenu *QVLCMenu::ToolsMenu( intf_thread_t *p_intf )
Clément Stenac's avatar
Clément Stenac committed
345 346
{
    QMenu *menu = new QMenu();
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362

    addDPStaticEntry( menu, qtr( I_MENU_EXT ), "", ":/settings",
            SLOT( extendedDialog() ), "Ctrl+E" );
    addDPStaticEntry( menu, qtr( I_MENU_MSG ), "",
        ":/messages", SLOT( messagesDialog() ),
        "Ctrl+M" );
    addDPStaticEntry( menu, qtr( I_MENU_INFO ) , "", ":/info",
        SLOT( mediaInfoDialog() ), "Ctrl+I" );
    addDPStaticEntry( menu, qtr( I_MENU_CODECINFO ) , "",
        ":/info", SLOT( mediaCodecDialog() ), "Ctrl+J" );
    addDPStaticEntry( menu, qtr( I_MENU_BOOKMARK ), "","",
                      SLOT( bookmarksDialog() ), "Ctrl+B" );
#ifdef ENABLE_VLM
    addDPStaticEntry( menu, qtr( I_MENU_VLM ), "", "", SLOT( vlmDialog() ),
        "Ctrl+W" );
#endif
Clément Stenac's avatar
Clément Stenac committed
363 364
    menu->addSeparator();

365
    addDPStaticEntry( menu, qtr( "Customi&ze Interface..." ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
366
        ":/preferences", SLOT( toolbarDialog() ), "" );
367 368 369
    addDPStaticEntry( menu, qtr( "&Preferences..." ), "",
        ":/preferences", SLOT( prefsDialog() ), "Ctrl+P" );

Clément Stenac's avatar
Clément Stenac committed
370 371 372
    return menu;
}

373 374
/**
 * Tools/View Menu
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
375
 * This is kept in the same menu for now, but could change if it gets much
376
 * longer.
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
377
 * This menu can be an interface menu but also a right click menu.
378
 **/
379
QMenu *QVLCMenu::ViewMenu( intf_thread_t *p_intf,
380
                            QMenu *current,
381 382 383
                            MainInterface *mi,
                            bool visual_selector_enabled,
                            bool with_intf )
384
{
385
    QMenu *menu = new QMenu( current );
386 387
    if( mi )
    {
388
        QAction *act=
389 390
            menu->addAction( QIcon( ":/playlist_menu" ), qtr( "Play&list..." ),
                    mi, SLOT( togglePlaylist() ), qtr( "Ctrl+L" ) );
391
        act->setData( "_static_" );
392
    }
393 394 395 396 397 398 399 400 401 402 403
    menu->addMenu( SDMenu( p_intf ) );
    menu->addSeparator();

    addDPStaticEntry( menu, qtr( I_PL_LOAD ), "", "", SLOT( openAPlaylist() ),
        "Ctrl+X" );
    addDPStaticEntry( menu, qtr( I_PL_SAVE ), "", "", SLOT( saveAPlaylist() ),
        "Ctrl+Y" );
    /*menu->addSeparator();
    menu->addAction( qtr( "Undock from Interface" ), mi,
                     SLOT( undockPlaylist() ), qtr( "Ctrl+U" ) );*/

404 405 406

    menu->addSeparator();

407 408
    if( with_intf )
    {
409
        QMenu *intfmenu = InterfacesMenu( p_intf, menu );
410 411 412
        MenuFunc *f = new MenuFunc( intfmenu, 4 );
        CONNECT( intfmenu, aboutToShow(), THEDP->menusUpdateMapper, map() );
        THEDP->menusUpdateMapper->setMapping( intfmenu, f );
413 414
        menu->addSeparator();
    }
Clément Stenac's avatar
Clément Stenac committed
415 416
    if( mi )
    {
417
        /* Minimal View */
418
        QAction *action = menu->addAction( qtr( "Mi&nimal View" ), mi,
419
                                SLOT( toggleMinimalView() ), qtr( "Ctrl+H" ) );
420
        action->setCheckable( true );
421
        action->setData( "_static_" );
422
        if( mi->getControlsVisibilityStatus() & CONTROLS_VISIBLE )
423
            action->setChecked( true );
424
        minimalViewAction = action; /* HACK for minimalView */
425

426
        /* FullScreen View */
427
        action = menu->addAction( qtr( "&Fullscreen Interface" ), mi,
428
                                  SLOT( toggleFullScreen() ), QString( "F11" ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
429
        action->setCheckable( true );
430
        action->setData( "_static_" );
431

432
        /* Advanced Controls */
433
        action = menu->addAction( qtr( "&Advanced Controls" ), mi,
434
                                  SLOT( toggleAdvanced() ) );
435
        action->setCheckable( true );
436
        action->setData( "_static_" );
437 438
        if( mi->getControlsVisibilityStatus() & CONTROLS_ADVANCED )
            action->setChecked( true );
439
#if 0 /* For Visualisations. Not yet working */
440
        adv = menu->addAction( qtr( "Visualizations selector" ),
441
                mi, SLOT( visual() ) );
442 443
        adv->setCheckable( true );
        if( visual_selector_enabled ) adv->setChecked( true );
444
#endif
Clément Stenac's avatar
Clément Stenac committed
445
    }
446

447 448
    menu->addSeparator();

449 450 451
    return menu;
}

452 453 454
/**
 * Interface Sub-Menu, to list extras interface and skins
 **/
455 456
QMenu *QVLCMenu::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
{
457
    vector<vlc_object_t *> objects;
458 459 460
    vector<const char *> varnames;
    /** \todo add "switch to XXX" */
    varnames.push_back( "intf-add" );
461
    objects.push_back( VLC_OBJECT(p_intf) );
Clément Stenac's avatar
Qt4:  
Clément Stenac committed
462

463
    return Populate( p_intf, current, varnames, objects );
464 465
}

466 467 468
/**
 * Main Audio Menu
 */
469 470
QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QMenu * current )
{
471
    vector<vlc_object_t *> objects;
472
    vector<const char *> varnames;
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
473
    vlc_object_t *p_aout;
474 475
    input_thread_t *p_input;

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

478
    if( current->isEmpty() )
479
    {
480 481 482
        ACT_ADD( current, "audio-es", qtr( "Audio &Track" ) );
        ACT_ADD( current, "audio-device", qtr( "Audio &Device" ) );
        ACT_ADD( current, "audio-channels", qtr( "Audio &Channels" ) );
483 484
        current->addSeparator();
        ACT_ADD( current, "visual", qtr( "&Visualizations" ) );
485 486
    }

487 488
    p_input = THEMIM->getInput();
    if( p_input )
489
        vlc_object_hold( p_input );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
490 491 492
    p_aout = ( vlc_object_t * ) vlc_object_find( p_intf,
                                                 VLC_OBJECT_AOUT,
                                                 FIND_ANYWHERE );
493

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

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
496 497
    if( p_aout )
        vlc_object_release( p_aout );
498 499 500
    if( p_input )
        vlc_object_release( p_input );

501 502 503
    return Populate( p_intf, current, varnames, objects );
}

504 505 506 507
/**
 * Main Video Menu
 * Subtitles are part of Video.
 **/
508
QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current )
509
{
510
    vlc_object_t *p_vout;
511
    input_thread_t *p_input;
512
    vector<vlc_object_t *> objects;
513 514
    vector<const char *> varnames;

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
515
    if( !current ) current = new QMenu();
516 517

    if( current->isEmpty() )
518
    {
519
        ACT_ADD( current, "video-es", qtr( "Video &Track" ) );
520 521 522 523 524

        QAction *action;
        QMenu *submenu = new QMenu( qtr( "&Subtitles Track" ), current );
        action = current->addMenu( submenu );
        action->setData( "spu-es" );
525
        addDPStaticEntry( submenu, qtr( "Open File..." ), "", "",
526
                          SLOT( loadSubtitlesFile() ) );
527
        submenu->addSeparator();
528

529
        ACT_ADD( current, "fullscreen", qtr( "&Fullscreen" ) );
530 531 532 533 534
        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" ) );
535 536 537
#ifdef WIN32
        ACT_ADD( current, "directx-wallpaper", qtr( "DirectX Wallpaper" ) );
#endif
538
        ACT_ADD( current, "video-snapshot", qtr( "Sna&pshot" ) );
539
        ACT_ADD( current, "postproc-q", qtr( "Post processing" ) );
540
    }
541

542 543
    p_input = THEMIM->getInput();
    if( p_input )
544
        vlc_object_hold( p_input );
545
    p_vout = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_VOUT,
546
            FIND_ANYWHERE );
547

548
    VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
549

550 551
    if( p_vout )
        vlc_object_release( p_vout );
552 553 554
    if( p_input )
        vlc_object_release( p_input );

555
    return Populate( p_intf, current, varnames, objects );
556 557
}

558 559 560 561
/**
 * Navigation Menu
 * For DVD, MP4, MOV and other chapter based format
 **/
562
QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *menu )
563 564
{
    vlc_object_t *p_object;
565
    vector<vlc_object_t *> objects;
566
    vector<const char *> varnames;
567

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
568
    if( !menu ) menu = new QMenu();
569 570 571

    if( menu->isEmpty() )
    {
572 573 574
        addDPStaticEntry( menu, qtr( I_MENU_GOTOTIME ), "","",
                          SLOT( gotoTimeDialog() ), "Ctrl+T" );
        menu->addSeparator();
575 576

        ACT_ADD( menu, "bookmark", qtr( "&Bookmarks" ) );
577
        ACT_ADD( menu, "title", qtr( "T&itle" ) );
578 579 580
        ACT_ADD( menu, "chapter", qtr( "&Chapter" ) );
        ACT_ADD( menu, "program", qtr( "&Program" ) );
        ACT_ADD( menu, "navigation", qtr( "&Navigation" ) );
581 582
    }

583
    p_object = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_INPUT,
584
            FIND_ANYWHERE );
585 586 587 588 589
    InputAutoMenuBuilder(  p_object, objects, varnames );
    PUSH_VAR( "prev-title" );
    PUSH_VAR( "next-title" );
    PUSH_VAR( "prev-chapter" );
    PUSH_VAR( "next-chapter" );
590
    EnableDPStaticEntries( menu, ( p_object != NULL ) );
591
    if( p_object )
592
    {
593
        vlc_object_release( p_object );
594 595
    }
    return Populate( p_intf, menu, varnames, objects, true );
596
}
597

598
/**
599
 * Service Discovery SubMenu
600
 **/
Clément Stenac's avatar
Clément Stenac committed
601 602 603
QMenu *QVLCMenu::SDMenu( intf_thread_t *p_intf )
{
    QMenu *menu = new QMenu();
604
    menu->setTitle( qtr( I_PL_SD ) );
605 606 607
    char **ppsz_longnames;
    char **ppsz_names = services_discovery_GetServicesNames( p_intf,
                                                             &ppsz_longnames );
608 609 610
    if( !ppsz_names )
        return menu;

611 612
    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
613
    {
614
        QAction *a = new QAction( qfu( *ppsz_longname ), menu );
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
615
        a->setCheckable( true );
616
        if( playlist_IsServicesDiscoveryLoaded( THEPL, *ppsz_name ) )
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
617 618
            a->setChecked( true );
        CONNECT( a , triggered(), THEDP->SDMapper, map() );
619
        THEDP->SDMapper->setMapping( a, QString( *ppsz_name ) );
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
620
        menu->addAction( a );
621

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

654
/*****************************************************************************
655
 * Popup menus - Right Click menus                                           *
656
 *****************************************************************************/
657 658
#define POPUP_BOILERPLATE \
    unsigned int i_last_separator = 0; \
659
    vector<vlc_object_t *> objects; \
660 661 662 663 664 665 666
    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() ); \
667
    p_intf->p_sys->p_popup_menu = NULL; \
668
    i_last_separator = 0;
669

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
670 671 672 673 674 675 676 677 678 679
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
680
                    ":/pause", SLOT( togglePlayPause() ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
681 682
        else
            addMIMStaticEntry( p_intf, menu, qtr( "Play" ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
683
                    ":/play", SLOT( togglePlayPause() ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
684
    }
685
    else if( THEPL->items.i_size )
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
686
        addMIMStaticEntry( p_intf, menu, qtr( "Play" ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
687
                ":/play", SLOT( togglePlayPause() ) );
688 689
    else
        addDPStaticEntry( menu, qtr( "Play" ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
690
                ":/play", SLOT( openDialog() ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
691 692

    addMIMStaticEntry( p_intf, menu, qtr( "Stop" ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
693
            ":/stop", SLOT( stop() ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
694
    addMIMStaticEntry( p_intf, menu, qtr( "Previous" ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
695
            ":/previous", SLOT( prev() ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
696
    addMIMStaticEntry( p_intf, menu, qtr( "Next" ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
697
            ":/next", SLOT( next() ) );
698
}
699 700 701

void QVLCMenu::PopupMenuStaticEntries( intf_thread_t *p_intf, QMenu *menu )
{
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
702
#if 0
703
    QMenu *toolsmenu = ToolsMenu( p_intf, menu, false, true );
704 705
    toolsmenu->setTitle( qtr( "Tools" ) );
    menu->addMenu( toolsmenu );
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
706
#endif
707

708
    QMenu *openmenu = new QMenu( qtr( "Open" ), menu );
709
    addDPStaticEntry( openmenu, qtr( "&Open File..." ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
710
        ":/file-asym", SLOT( openFileDialog() ) );
711
    addDPStaticEntry( openmenu, qtr( I_OPEN_FOLDER ), "",
712
        ":/folder-grey", SLOT( PLOpenDir() ) );
713
    addDPStaticEntry( openmenu, qtr( "Open &Disc..." ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
714
        ":/disc", SLOT( openDiscDialog() ) );
715
    addDPStaticEntry( openmenu, qtr( "Open &Network..." ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
716
        ":/network", SLOT( openNetDialog() ) );
717
    addDPStaticEntry( openmenu, qtr( "Open &Capture Device..." ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
718
        ":/capture-card", SLOT( openCaptureDialog() ) );
719 720 721
    menu->addMenu( openmenu );

    menu->addSeparator();
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
722
#if 0
723
    QMenu *helpmenu = HelpMenu( menu );
724 725
    helpmenu->setTitle( qtr( "Help" ) );
    menu->addMenu( helpmenu );
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
726
#endif
727

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
728
    addDPStaticEntry( menu, qtr( "Quit" ), "", ":/quit",
729
                      SLOT( quit() ), "Ctrl+Q" );
730
}
Clément Stenac's avatar
Qt4:  
Clément Stenac committed
731

732
/* Video Tracks and Subtitles tracks */
733
void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf )
734 735 736 737
{
    POPUP_BOILERPLATE;
    if( p_input )
    {
738
        vlc_object_hold( p_input );
739
        vlc_object_t *p_vout = ( vlc_object_t * )vlc_object_find( p_input,
740
                VLC_OBJECT_VOUT, FIND_CHILD );
741 742
        if( p_vout )
        {
743
            VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
744 745 746 747
            vlc_object_release( p_vout );
        }
        vlc_object_release( p_input );
    }
748
    QMenu *menu = new QMenu();
749
    CREATE_POPUP;
750 751
}

752
/* Audio Tracks */
753
void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf )
754 755 756 757
{
    POPUP_BOILERPLATE;
    if( p_input )
    {
758
        vlc_object_hold( p_input );
759
        vlc_object_t *p_aout = ( vlc_object_t * )vlc_object_find( p_input,
760
                VLC_OBJECT_AOUT, FIND_ANYWHERE );
761
        AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
762 763 764 765
        if( p_aout )
            vlc_object_release( p_aout );
        vlc_object_release( p_input );
    }
766
    QMenu *menu = new QMenu();
767
    CREATE_POPUP;
768 769
}

770
/* Navigation stuff, and general menus ( open ) */
771
void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf )
772
{
773
    vlc_value_t val;
774
    POPUP_BOILERPLATE;
775

776 777
    if( p_input )
    {
778
        vlc_object_hold( p_input );
779
        varnames.push_back( "audio-es" );
780
        InputAutoMenuBuilder( VLC_OBJECT( p_input ), objects, varnames );