menus.cpp 41.5 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_intf_strings.h>
35
#include <vlc_services_discovery.h>
36

Clément Stenac's avatar
Clément Stenac committed
37
#include "menus.hpp"
38 39

#include "main_interface.hpp"    /* View modifications */
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
40 41 42
#include "dialogs_provider.hpp"  /* Dialogs display */
#include "input_manager.hpp"     /* Input Management */
#include "recents.hpp"           /* Recent Items */
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
                       const char *icon,
89
                       const char *member,
90
                       const char *shortcut = NULL )
91
{
92
    QAction *action = NULL;
93 94 95
    if( !EMPTY_STR( icon ) > 0 )
    {
        if( !EMPTY_STR( shortcut ) > 0 )
96 97
            action = menu->addAction( QIcon( icon ), text, THEDP,
                                      member, qtr( shortcut ) );
98
        else
99
            action = menu->addAction( QIcon( icon ), text, THEDP, member );
100 101 102 103
    }
    else
    {
        if( !EMPTY_STR( shortcut ) > 0 )
104
            action = menu->addAction( text, THEDP, member, qtr( shortcut ) );
105
        else
106
            action = menu->addAction( text, THEDP, member );
107
    }
108
    action->setData( "_static_" );
109
}
110

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

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

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

142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
/***
 * Same for MIM
 ***/
void addMIMStaticEntry( intf_thread_t *p_intf,
                        QMenu *menu,
                        const QString text,
                        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 );
    }
}

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

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

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

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

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
188
static int VideoAutoMenuBuilder( vout_thread_t *p_object,
189
        input_thread_t *p_input,
190
        vector<vlc_object_t *> &objects,
191
        vector<const char *> &varnames )
192
{
193 194
    PUSH_INPUTVAR( "video-es" );
    PUSH_INPUTVAR( "spu-es" );
195 196
    PUSH_VAR( "fullscreen" );
    PUSH_VAR( "zoom" );
197
    PUSH_VAR( "scaling" );
198 199 200 201
    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 */
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
208
    // FIXME
209
    if( p_object )
210
    {
211 212 213 214 215 216
        /* 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 )
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 )
            {
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
223
                vlc_object_t *p_object = p_pp;
224 225 226 227 228
                PUSH_VAR( "postproc-q" );
                vlc_object_release( p_pp );
            }

            vlc_object_release( p_dec );
229
        }
230 231 232 233
    }
    return VLC_SUCCESS;
}

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

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

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

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

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

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

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

293 294 295
    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
296

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

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

310
    addDPStaticEntry( menu, qtr( "&Open File..." ),
311
        ":/file-asym", SLOT( simpleOpenDialog() ), "Ctrl+O" );
312
    addDPStaticEntry( menu, qtr( "Advanced Open File..." ),
313
        ":/file-asym", SLOT( openFileDialog() ), "Ctrl+Shift+O" );
314 315
    addDPStaticEntry( menu, qtr( "Open &URL" ),
                      NULL, SLOT( openUrlDialog() ), "Ctrl+V" );
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

326 327
    menu->addSeparator();

328 329 330 331 332 333 334
    addDPStaticEntry( menu, qtr( I_PL_LOAD ), "", SLOT( openAPlaylist() ),
        "Ctrl+X" );
    addDPStaticEntry( menu, qtr( I_PL_SAVE ), "", SLOT( saveAPlaylist() ),
        "Ctrl+Y" );

    menu->addSeparator();

335
    recentsMenu = new QMenu( qtr( "Recently &Played" ), menu );
Ludovic Fauvet's avatar
Ludovic Fauvet committed
336 337
    updateRecents( p_intf );
    menu->addMenu( recentsMenu );
338
    menu->addSeparator();
339

340
    addDPStaticEntry( menu, qtr( "Conve&rt / Save..." ), "",
341
        SLOT( openAndTranscodingDialogs() ), "Ctrl+R" );
342
    addDPStaticEntry( menu, qtr( "&Streaming..." ),
343
        ":/stream", SLOT( openAndStreamingDialogs() ),
344
        "Ctrl+S" );
345
    menu->addSeparator();
346

347
    addDPStaticEntry( menu, qtr( "&Quit" ) ,
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
348
        ":/quit", SLOT( quit() ), "Ctrl+Q" );
349 350 351
    return menu;
}

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
352
/* Playlist/MediaLibrary Control */
353
QMenu *QVLCMenu::ToolsMenu( intf_thread_t *p_intf )
Clément Stenac's avatar
Clément Stenac committed
354
{
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
355
    VLC_UNUSED( p_intf ); //TODO remove
Clément Stenac's avatar
Clément Stenac committed
356
    QMenu *menu = new QMenu();
357

358
    addDPStaticEntry( menu, qtr( I_MENU_EXT ), ":/settings",
359
            SLOT( extendedDialog() ), "Ctrl+E" );
360

361
    addDPStaticEntry( menu, qtr( I_MENU_INFO ) , ":/info",
362
        SLOT( mediaInfoDialog() ), "Ctrl+I" );
363
    addDPStaticEntry( menu, qtr( I_MENU_CODECINFO ) ,
364
        ":/info", SLOT( mediaCodecDialog() ), "Ctrl+J" );
365

366
    addDPStaticEntry( menu, qtr( I_MENU_BOOKMARK ),"",
367 368
                      SLOT( bookmarksDialog() ), "Ctrl+B" );
#ifdef ENABLE_VLM
369
    addDPStaticEntry( menu, qtr( I_MENU_VLM ), "", SLOT( vlmDialog() ),
370 371
        "Ctrl+W" );
#endif
372 373 374 375 376

    addDPStaticEntry( menu, qtr( I_MENU_MSG ),
        ":/messages", SLOT( messagesDialog() ),
        "Ctrl+M" );

377 378
    addDPStaticEntry( menu, qtr( "Plu&gins and extensions" ),
        "", SLOT( pluginDialog() ) );
Clément Stenac's avatar
Clément Stenac committed
379 380
    menu->addSeparator();

381 382
    addDPStaticEntry( menu, qtr( "Customi&ze Interface..." ),
        ":/preferences", SLOT( toolbarDialog() ) );
383
    addDPStaticEntry( menu, qtr( "&Preferences" ),
384 385
        ":/preferences", SLOT( prefsDialog() ), "Ctrl+P" );

Clément Stenac's avatar
Clément Stenac committed
386 387 388
    return menu;
}

389 390
/**
 * Tools/View Menu
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
391
 * This is kept in the same menu for now, but could change if it gets much
392
 * longer.
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
393
 * This menu can be an interface menu but also a right click menu.
394
 **/
395
QMenu *QVLCMenu::ViewMenu( intf_thread_t *p_intf,
396
                            QMenu *current,
397 398 399
                            MainInterface *mi,
                            bool visual_selector_enabled,
                            bool with_intf )
400
{
401
    QMenu *menu = new QMenu( current );
402
    QAction *act;
403 404
    if( mi )
    {
405
        act = menu->addAction( QIcon( ":/playlist_menu" ),
406
                               qtr( "Play&list" ), mi,
407
                               SLOT( togglePlaylist() ), qtr( "Ctrl+L" ) );
408
        act->setData( "_static_" );
409
    }
410 411
    act = menu->addMenu( SDMenu( p_intf ) );
    act->setData( "_static_" );
412 413 414 415
    /*menu->addSeparator();
    menu->addAction( qtr( "Undock from Interface" ), mi,
                     SLOT( undockPlaylist() ), qtr( "Ctrl+U" ) );*/

416 417 418

    menu->addSeparator();

419 420
    if( with_intf )
    {
421
        QMenu *intfmenu = InterfacesMenu( p_intf, menu );
422 423 424
        MenuFunc *f = new MenuFunc( intfmenu, 4 );
        CONNECT( intfmenu, aboutToShow(), THEDP->menusUpdateMapper, map() );
        THEDP->menusUpdateMapper->setMapping( intfmenu, f );
425 426
        menu->addSeparator();
    }
Clément Stenac's avatar
Clément Stenac committed
427 428
    if( mi )
    {
429
        /* Minimal View */
430
        QAction *action = menu->addAction( qtr( "Mi&nimal View" ), mi,
431
                                SLOT( toggleMinimalView() ), qtr( "Ctrl+H" ) );
432
        action->setCheckable( true );
433
        action->setData( "_static_" );
434
        if( mi->getControlsVisibilityStatus() & CONTROLS_VISIBLE )
435
            action->setChecked( true );
436
        minimalViewAction = action; /* HACK for minimalView */
437

438
        /* FullScreen View */
439
        action = menu->addAction( qtr( "&Fullscreen Interface" ), mi,
440
                                  SLOT( toggleFullScreen() ), QString( "F11" ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
441
        action->setCheckable( true );
442
        action->setData( "_static_" );
443

444
        /* Advanced Controls */
445
        action = menu->addAction( qtr( "&Advanced Controls" ), mi,
446
                                  SLOT( toggleAdvanced() ) );
447
        action->setCheckable( true );
448
        action->setData( "_static_" );
449 450
        if( mi->getControlsVisibilityStatus() & CONTROLS_ADVANCED )
            action->setChecked( true );
451
#if 0 /* For Visualisations. Not yet working */
452
        adv = menu->addAction( qtr( "Visualizations selector" ),
453
                mi, SLOT( visual() ) );
454 455
        adv->setCheckable( true );
        if( visual_selector_enabled ) adv->setChecked( true );
456
#endif
Clément Stenac's avatar
Clément Stenac committed
457
    }
458

459 460
    menu->addSeparator();

461 462 463
    return menu;
}

464 465 466
/**
 * Interface Sub-Menu, to list extras interface and skins
 **/
467 468
QMenu *QVLCMenu::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
{
469
    vector<vlc_object_t *> objects;
470 471 472
    vector<const char *> varnames;
    /** \todo add "switch to XXX" */
    varnames.push_back( "intf-add" );
473
    objects.push_back( VLC_OBJECT(p_intf) );
Clément Stenac's avatar
Qt4:  
Clément Stenac committed
474

475
    return Populate( p_intf, current, varnames, objects );
476 477
}

478 479 480
/**
 * Main Audio Menu
 */
481 482
QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QMenu * current )
{
483
    vector<vlc_object_t *> objects;
484
    vector<const char *> varnames;
485
    aout_instance_t *p_aout;
486 487
    input_thread_t *p_input;

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

490
    if( current->isEmpty() )
491
    {
492 493 494
        ACT_ADD( current, "audio-es", qtr( "Audio &Track" ) );
        ACT_ADD( current, "audio-device", qtr( "Audio &Device" ) );
        ACT_ADD( current, "audio-channels", qtr( "Audio &Channels" ) );
495 496
        current->addSeparator();
        ACT_ADD( current, "visual", qtr( "&Visualizations" ) );
497 498
    }

499 500
    p_input = THEMIM->getInput();
    if( p_input )
501
        vlc_object_hold( p_input );
502
    p_aout = THEMIM->getAout();
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
503
    if( p_aout )
504 505
    {
        AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
506
        vlc_object_release( p_aout );
507
    }
508 509 510
    if( p_input )
        vlc_object_release( p_input );

511 512 513
    return Populate( p_intf, current, varnames, objects );
}

514 515 516 517
/**
 * Main Video Menu
 * Subtitles are part of Video.
 **/
518
QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current )
519
{
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
520
    vout_thread_t *p_vout;
521
    input_thread_t *p_input;
522
    vector<vlc_object_t *> objects;
523 524
    vector<const char *> varnames;

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
525
    if( !current ) current = new QMenu();
526 527

    if( current->isEmpty() )
528
    {
529
        ACT_ADD( current, "video-es", qtr( "Video &Track" ) );
530 531 532 533 534

        QAction *action;
        QMenu *submenu = new QMenu( qtr( "&Subtitles Track" ), current );
        action = current->addMenu( submenu );
        action->setData( "spu-es" );
535
        addDPStaticEntry( submenu, qtr( "Open File..." ), "",
536
                          SLOT( loadSubtitlesFile() ) );
537
        submenu->addSeparator();
538

539
        ACT_ADD( current, "fullscreen", qtr( "&Fullscreen" ) );
540 541 542 543 544
        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" ) );
545 546 547
#ifdef WIN32
        ACT_ADD( current, "directx-wallpaper", qtr( "DirectX Wallpaper" ) );
#endif
548
        ACT_ADD( current, "video-snapshot", qtr( "Sna&pshot" ) );
549
        ACT_ADD( current, "postproc-q", qtr( "Post processing" ) );
550
    }
551

552 553
    p_input = THEMIM->getInput();
    if( p_input )
554
        vlc_object_hold( p_input );
555

556
    p_vout = THEMIM->getVout();
557
    if( p_vout )
558 559
    {
        VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
560
        vlc_object_release( p_vout );
561
    }
562 563 564
    if( p_input )
        vlc_object_release( p_input );

565
    return Populate( p_intf, current, varnames, objects );
566 567
}

568 569 570 571
/**
 * Navigation Menu
 * For DVD, MP4, MOV and other chapter based format
 **/
572
QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *menu )
573
{
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
574
    if( !menu ) menu = new QMenu();
575 576 577

    if( menu->isEmpty() )
    {
578
        addDPStaticEntry( menu, qtr( I_MENU_GOTOTIME ),"",
579 580
                          SLOT( gotoTimeDialog() ), "Ctrl+T" );
        menu->addSeparator();
581 582

        ACT_ADD( menu, "bookmark", qtr( "&Bookmarks" ) );
583
        ACT_ADD( menu, "title", qtr( "T&itle" ) );
584 585 586
        ACT_ADD( menu, "chapter", qtr( "&Chapter" ) );
        ACT_ADD( menu, "program", qtr( "&Program" ) );
        ACT_ADD( menu, "navigation", qtr( "&Navigation" ) );
587 588
    }

589 590 591 592 593
    input_thread_t *p_object;
    vector<vlc_object_t *> objects;
    vector<const char *> varnames;

    p_object = THEMIM->getInput();
594 595
    if( p_object )
        vlc_object_hold( p_object );
596
    InputAutoMenuBuilder( p_object, objects, varnames );
597 598 599 600
    PUSH_VAR( "prev-title" );
    PUSH_VAR( "next-title" );
    PUSH_VAR( "prev-chapter" );
    PUSH_VAR( "next-chapter" );
601
    EnableDPStaticEntries( menu, ( p_object != NULL ) );
602
    if( p_object )
603
    {
604
        vlc_object_release( p_object );
605
    }
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
606
    return Populate( p_intf, menu, varnames, objects );
607
}
608

609
/**
610
 * Service Discovery SubMenu
611
 **/
Clément Stenac's avatar
Clément Stenac committed
612 613 614
QMenu *QVLCMenu::SDMenu( intf_thread_t *p_intf )
{
    QMenu *menu = new QMenu();
615
    menu->setTitle( qtr( I_PL_SD ) );
616
    char **ppsz_longnames;
617
    char **ppsz_names = vlc_sd_GetNames( &ppsz_longnames );
618 619 620
    if( !ppsz_names )
        return menu;

621 622
    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
623
    {
624
        QAction *a = new QAction( qfu( *ppsz_longname ), menu );
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
625
        a->setCheckable( true );
626
        if( playlist_IsServicesDiscoveryLoaded( THEPL, *ppsz_name ) )
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
627 628
            a->setChecked( true );
        CONNECT( a , triggered(), THEDP->SDMapper, map() );
629
        THEDP->SDMapper->setMapping( a, QString( *ppsz_name ) );
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
630
        menu->addAction( a );
631

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

664
/*****************************************************************************
665
 * Popup menus - Right Click menus                                           *
666
 *****************************************************************************/
667 668
#define POPUP_BOILERPLATE \
    unsigned int i_last_separator = 0; \
669
    vector<vlc_object_t *> objects; \
670 671 672 673 674 675 676
    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() ); \
677
    p_intf->p_sys->p_popup_menu = NULL; \
678
    i_last_separator = 0;
679

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
680 681 682 683 684 685 686 687 688
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 )
689
            addMIMStaticEntry( p_intf, menu, qtr( "Pause" ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
690
                    ":/pause", SLOT( togglePlayPause() ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
691
        else
692
            addMIMStaticEntry( p_intf, menu, qtr( "Play" ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
693
                    ":/play", SLOT( togglePlayPause() ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
694
    }
695
    else if( THEPL->items.i_size )
696
        addMIMStaticEntry( p_intf, menu, qtr( "Play" ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
697
                ":/play", SLOT( togglePlayPause() ) );
698
    else
699
        addDPStaticEntry( menu, qtr( "Play" ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
700
                ":/play", SLOT( openDialog() ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
701

702
    addMIMStaticEntry( p_intf, menu, qtr( "Stop" ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
703
            ":/stop", SLOT( stop() ) );
704
    addMIMStaticEntry( p_intf, menu, qtr( "Previous" ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
705
            ":/previous", SLOT( prev() ) );
706
    addMIMStaticEntry( p_intf, menu, qtr( "Next" ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
707
            ":/next", SLOT( next() ) );
708
}
709

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
710
void QVLCMenu::PopupMenuStaticEntries( QMenu *menu )
711
{
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
712
#if 0
713
    QMenu *toolsmenu = ToolsMenu( p_intf, menu, false, true );
714 715
    toolsmenu->setTitle( qtr( "Tools" ) );
    menu->addMenu( toolsmenu );
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
716
#endif
717

718
    QMenu *openmenu = new QMenu( qtr( "Open Media" ), menu );
719
    addDPStaticEntry( openmenu, qtr( "&Open File..." ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
720
        ":/file-asym", SLOT( openFileDialog() ) );
721
    addDPStaticEntry( openmenu, qtr( I_OPEN_FOLDER ),
722
        ":/folder-grey", SLOT( PLOpenDir() ) );
723
    addDPStaticEntry( openmenu, qtr( "Open &Disc..." ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
724
        ":/disc", SLOT( openDiscDialog() ) );
725
    addDPStaticEntry( openmenu, qtr( "Open &Network..." ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
726
        ":/network", SLOT( openNetDialog() ) );
727
    addDPStaticEntry( openmenu, qtr( "Open &Capture Device..." ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
728
        ":/capture-card", SLOT( openCaptureDialog() ) );
729 730 731
    menu->addMenu( openmenu );

    menu->addSeparator();
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
732
#if 0
733
    QMenu *helpmenu = HelpMenu( menu );
734 735
    helpmenu->setTitle( qtr( "Help" ) );
    menu->addMenu( helpmenu );
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
736
#endif
737

738
    addDPStaticEntry( menu, qtr( "Quit" ), ":/quit",
739
                      SLOT( quit() ), "Ctrl+Q" );
740
}
Clément Stenac's avatar
Qt4:  
Clément Stenac committed
741

742
/* Video Tracks and Subtitles tracks */
743
void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf )
744 745 746 747
{
    POPUP_BOILERPLATE;
    if( p_input )
    {
748
        vlc_object_hold( p_input );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
749
        vout_thread_t *p_vout = THEMIM->getVout();
750 751
        if( p_vout )
        {
752
            VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
753 754 755 756
            vlc_object_release( p_vout );
        }
        vlc_object_release( p_input );
    }
757
    QMenu *menu = new QMenu();
758
    CREATE_POPUP;
759 760
}

761
/* Audio Tracks */
762
void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf )
763 764 765 766
{
    POPUP_BOILERPLATE;
    if( p_input )
    {
767
        vlc_object_hold( p_input );
768
        aout_instance_t *p_aout = THEMIM->getAout();
769
        AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
770 771 772 773
        if( p_aout )
            vlc_object_release( p_aout );
        vlc_object_release( p_input );
    }
774
    QMenu *menu = new QMenu();