menus.cpp 40.6 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
    objects.push_back( VLC_OBJECT(p_object) )
160 161

#define PUSH_INPUTVAR( var ) varnames.push_back( var ); \
162
    objects.push_back( VLC_OBJECT(p_input) );
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<vlc_object_t *> &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<vlc_object_t *> &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
        /* 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 )
207
        {
208 209 210 211 212 213 214 215 216 217 218
            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 );
219
        }
220 221 222 223 224
    }
    return VLC_SUCCESS;
}

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

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

247 248
/*****************************************************************************
 * All normal menus
249
 * Simple Code
250 251 252
 *****************************************************************************/

#define BAR_ADD( func, title ) { \
253
    QMenu *_menu = func; _menu->setTitle( title ); bar->addMenu( _menu ); }
254 255

#define BAR_DADD( func, title, id ) { \
256 257 258 259 260 261 262 263
    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 ); }
264

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

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

282
    BAR_ADD( PlaylistMenu( p_intf, mi ), qtr( "&Playlist" ) );
283
    BAR_ADD( ToolsMenu( p_intf, NULL, mi, visual_selector_enabled, true ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
284
             qtr( "&Tools" ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
285

286
    BAR_ADD( HelpMenu( NULL ), qtr( "&Help" ) );
287
}
288 289
#undef BAR_ADD
#undef BAR_DADD
290 291

/**
292
 * Media ( File ) Menu
293 294
 * Opening, streaming and quit
 **/
295 296 297
QMenu *QVLCMenu::FileMenu()
{
    QMenu *menu = new QMenu();
298

299
    addDPStaticEntry( menu, qtr( "&Open File..." ), "",
300 301 302 303
#ifdef WIN32
        ":/file-asym", SLOT( simpleOpenDialog() ), "Ctrl+O" );
    addDPStaticEntry( menu, qtr( "Advanced Open File..." ), "",
        ":/file-asym", SLOT( openFileDialog() ), "" );
304 305 306
#else
        ":/file-asym", SLOT( openFileDialog() ), "Ctrl+0" );
#endif
307
    addDPStaticEntry( menu, qtr( I_OPEN_FOLDER ), "",
308
        ":/folder-grey", SLOT( PLOpenDir() ), "Ctrl+F" );
309
    addDPStaticEntry( menu, qtr( "Open &Disc..." ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
310
        ":/disc", SLOT( openDiscDialog() ), "Ctrl+D" );
311
    addDPStaticEntry( menu, qtr( "Open &Network..." ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
312
        ":/network", SLOT( openNetDialog() ), "Ctrl+N" );
313
    addDPStaticEntry( menu, qtr( "Open &Capture Device..." ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
314
        ":/capture-card", SLOT( openCaptureDialog() ),
315
        "Ctrl+C" );
316
    menu->addSeparator();
317

318 319
    addDPStaticEntry( menu, qtr( "Conve&rt / Save..." ), "", "",
        SLOT( openThenTranscodingDialogs() ), "Ctrl+R" );
320
    addDPStaticEntry( menu, qtr( "&Streaming..." ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
321
        ":/stream", SLOT( openThenStreamingDialogs() ),
322
        "Ctrl+S" );
323
    menu->addSeparator();
324 325

    addDPStaticEntry( menu, qtr( "&Quit" ) , "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
326
        ":/quit", SLOT( quit() ), "Ctrl+Q" );
327 328 329
    return menu;
}

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
330
/* Playlist/MediaLibrary Control */
331
QMenu *QVLCMenu::PlaylistMenu( intf_thread_t *p_intf, MainInterface *mi )
Clément Stenac's avatar
Clément Stenac committed
332 333 334
{
    QMenu *menu = new QMenu();
    menu->addMenu( SDMenu( p_intf ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
335
    menu->addAction( QIcon( ":/playlist_menu" ),
336
                     qtr( "Show P&laylist" ), mi, SLOT( togglePlaylist() ) );
Clément Stenac's avatar
Clément Stenac committed
337 338
    menu->addSeparator();

339 340 341 342
    addDPStaticEntry( menu, qtr( I_PL_LOAD ), "", "", SLOT( openAPlaylist() ),
        "Ctrl+X" );
    addDPStaticEntry( menu, qtr( I_PL_SAVE ), "", "", SLOT( saveAPlaylist() ),
        "Ctrl+Y" );
343
    /*menu->addSeparator();
344
    menu->addAction( qtr( "Undock from Interface" ), mi,
345
                     SLOT( undockPlaylist() ), qtr( "Ctrl+U" ) );*/
Clément Stenac's avatar
Clément Stenac committed
346 347 348
    return menu;
}

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

    menu->addSeparator();

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

393
        /* FullScreen View */
394
        action = menu->addAction( qtr( "&Fullscreen Interface" ), mi,
395
                                  SLOT( toggleFullScreen() ), QString( "F11" ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
396
        action->setCheckable( true );
397
        action->setData( "_static_" );
398

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

414 415
    menu->addSeparator();

416
    addDPStaticEntry( menu, qtr( I_MENU_MSG ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
417
        ":/messages", SLOT( messagesDialog() ),
418
        "Ctrl+M" );
419
    addDPStaticEntry( menu, qtr( I_MENU_INFO ) , "", ":/info",
420 421
        SLOT( mediaInfoDialog() ), "Ctrl+I" );
    addDPStaticEntry( menu, qtr( I_MENU_CODECINFO ) , "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
422
        ":/info", SLOT( mediaCodecDialog() ), "Ctrl+J" );
423
    addDPStaticEntry( menu, qtr( I_MENU_BOOKMARK ), "","",
424
                      SLOT( bookmarksDialog() ), "Ctrl+B" );
425
#ifdef ENABLE_VLM
426
    addDPStaticEntry( menu, qtr( I_MENU_VLM ), "", "", SLOT( vlmDialog() ),
427
        "Ctrl+W" );
428
#endif
429

430
    menu->addSeparator();
431
    addDPStaticEntry( menu, qtr( "&Preferences..." ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
432
        ":/preferences", SLOT( prefsDialog() ), "Ctrl+P" );
433 434 435
    return menu;
}

436 437 438
/**
 * Interface Sub-Menu, to list extras interface and skins
 **/
439 440
QMenu *QVLCMenu::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
{
441
    vector<vlc_object_t *> objects;
442 443 444
    vector<const char *> varnames;
    /** \todo add "switch to XXX" */
    varnames.push_back( "intf-add" );
445
    objects.push_back( VLC_OBJECT(p_intf) );
Clément Stenac's avatar
Qt4:  
Clément Stenac committed
446

447
    return Populate( p_intf, current, varnames, objects );
448 449
}

450 451 452
/**
 * Main Audio Menu
 */
453 454
QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QMenu * current )
{
455
    vector<vlc_object_t *> objects;
456
    vector<const char *> varnames;
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
457
    vlc_object_t *p_aout;
458 459
    input_thread_t *p_input;

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

462
    if( current->isEmpty() )
463
    {
464 465 466
        ACT_ADD( current, "audio-es", qtr( "Audio &Track" ) );
        ACT_ADD( current, "audio-device", qtr( "Audio &Device" ) );
        ACT_ADD( current, "audio-channels", qtr( "Audio &Channels" ) );
467 468
        current->addSeparator();
        ACT_ADD( current, "visual", qtr( "&Visualizations" ) );
469 470
    }

471 472
    p_input = THEMIM->getInput();
    if( p_input )
473
        vlc_object_hold( p_input );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
474 475 476
    p_aout = ( vlc_object_t * ) vlc_object_find( p_intf,
                                                 VLC_OBJECT_AOUT,
                                                 FIND_ANYWHERE );
477

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

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
480 481
    if( p_aout )
        vlc_object_release( p_aout );
482 483 484
    if( p_input )
        vlc_object_release( p_input );

485 486 487
    return Populate( p_intf, current, varnames, objects );
}

488 489 490 491
/**
 * Main Video Menu
 * Subtitles are part of Video.
 **/
492
QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current )
493
{
494
    vlc_object_t *p_vout;
495
    input_thread_t *p_input;
496
    vector<vlc_object_t *> objects;
497 498
    vector<const char *> varnames;

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
499
    if( !current ) current = new QMenu();
500 501

    if( current->isEmpty() )
502
    {
503
        ACT_ADD( current, "video-es", qtr( "Video &Track" ) );
504 505 506 507 508

        QAction *action;
        QMenu *submenu = new QMenu( qtr( "&Subtitles Track" ), current );
        action = current->addMenu( submenu );
        action->setData( "spu-es" );
509
        addDPStaticEntry( submenu, qtr( "Open File..." ), "", "",
510
                          SLOT( loadSubtitlesFile() ) );
511
        submenu->addSeparator();
512

513
        ACT_ADD( current, "fullscreen", qtr( "&Fullscreen" ) );
514 515 516 517 518
        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" ) );
519 520 521
#ifdef WIN32
        ACT_ADD( current, "directx-wallpaper", qtr( "DirectX Wallpaper" ) );
#endif
522
        ACT_ADD( current, "video-snapshot", qtr( "Sna&pshot" ) );
523
        ACT_ADD( current, "postproc-q", qtr( "Post processing" ) );
524
    }
525

526 527
    p_input = THEMIM->getInput();
    if( p_input )
528
        vlc_object_hold( p_input );
529
    p_vout = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_VOUT,
530
            FIND_ANYWHERE );
531

532
    VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
533

534 535
    if( p_vout )
        vlc_object_release( p_vout );
536 537 538
    if( p_input )
        vlc_object_release( p_input );

539
    return Populate( p_intf, current, varnames, objects );
540 541
}

542 543 544 545
/**
 * Navigation Menu
 * For DVD, MP4, MOV and other chapter based format
 **/
546
QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *menu )
547 548
{
    vlc_object_t *p_object;
549
    vector<vlc_object_t *> objects;
550
    vector<const char *> varnames;
551

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
552
    if( !menu ) menu = new QMenu();
553 554 555

    if( menu->isEmpty() )
    {
556 557 558
        addDPStaticEntry( menu, qtr( I_MENU_GOTOTIME ), "","",
                          SLOT( gotoTimeDialog() ), "Ctrl+T" );
        menu->addSeparator();
559 560

        ACT_ADD( menu, "bookmark", qtr( "&Bookmarks" ) );
561
        ACT_ADD( menu, "title", qtr( "T&itle" ) );
562 563 564
        ACT_ADD( menu, "chapter", qtr( "&Chapter" ) );
        ACT_ADD( menu, "program", qtr( "&Program" ) );
        ACT_ADD( menu, "navigation", qtr( "&Navigation" ) );
565 566
    }

567
    p_object = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_INPUT,
568
            FIND_ANYWHERE );
569 570 571 572 573
    InputAutoMenuBuilder(  p_object, objects, varnames );
    PUSH_VAR( "prev-title" );
    PUSH_VAR( "next-title" );
    PUSH_VAR( "prev-chapter" );
    PUSH_VAR( "next-chapter" );
574
    EnableDPStaticEntries( menu, ( p_object != NULL ) );
575
    if( p_object )
576
    {
577
        vlc_object_release( p_object );
578 579
    }
    return Populate( p_intf, menu, varnames, objects, true );
580
}
581

582
/**
583
 * Service Discovery SubMenu
584
 **/
Clément Stenac's avatar
Clément Stenac committed
585 586 587
QMenu *QVLCMenu::SDMenu( intf_thread_t *p_intf )
{
    QMenu *menu = new QMenu();
588
    menu->setTitle( qtr( I_PL_SD ) );
589 590 591
    char **ppsz_longnames;
    char **ppsz_names = services_discovery_GetServicesNames( p_intf,
                                                             &ppsz_longnames );
592 593 594
    if( !ppsz_names )
        return menu;

595 596
    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
597
    {
598
        QAction *a = new QAction( qfu( *ppsz_longname ), menu );
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
599
        a->setCheckable( true );
600
        if( playlist_IsServicesDiscoveryLoaded( THEPL, *ppsz_name ) )
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
601 602
            a->setChecked( true );
        CONNECT( a , triggered(), THEDP->SDMapper, map() );
603
        THEDP->SDMapper->setMapping( a, QString( *ppsz_name ) );
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
604
        menu->addAction( a );
605

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

638
/*****************************************************************************
639
 * Popup menus - Right Click menus                                           *
640
 *****************************************************************************/
641 642
#define POPUP_BOILERPLATE \
    unsigned int i_last_separator = 0; \
643
    vector<vlc_object_t *> objects; \
644 645 646 647 648 649 650
    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() ); \
651
    p_intf->p_sys->p_popup_menu = NULL; \
652
    i_last_separator = 0;
653

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
654 655 656 657 658 659 660 661 662 663
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
664
                    ":/pause", SLOT( togglePlayPause() ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
665 666
        else
            addMIMStaticEntry( p_intf, menu, qtr( "Play" ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
667
                    ":/play", SLOT( togglePlayPause() ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
668
    }
669
    else if( THEPL->items.i_size )
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
670
        addMIMStaticEntry( p_intf, menu, qtr( "Play" ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
671
                ":/play", SLOT( togglePlayPause() ) );
672 673
    else
        addDPStaticEntry( menu, qtr( "Play" ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
674
                ":/play", SLOT( openDialog() ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
675 676

    addMIMStaticEntry( p_intf, menu, qtr( "Stop" ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
677
            ":/stop", SLOT( stop() ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
678
    addMIMStaticEntry( p_intf, menu, qtr( "Previous" ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
679
            ":/previous", SLOT( prev() ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
680
    addMIMStaticEntry( p_intf, menu, qtr( "Next" ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
681
            ":/next", SLOT( next() ) );
682
}
683 684 685

void QVLCMenu::PopupMenuStaticEntries( intf_thread_t *p_intf, QMenu *menu )
{
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
686
#if 0
687
    QMenu *toolsmenu = ToolsMenu( p_intf, menu, false, true );
688 689
    toolsmenu->setTitle( qtr( "Tools" ) );
    menu->addMenu( toolsmenu );
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
690
#endif
691

692
    QMenu *openmenu = new QMenu( qtr( "Open" ), menu );
693
    addDPStaticEntry( openmenu, qtr( "&Open File..." ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
694
        ":/file-asym", SLOT( openFileDialog() ) );
695
    addDPStaticEntry( openmenu, qtr( I_OPEN_FOLDER ), "",
696
        ":/folder-grey", SLOT( PLOpenDir() ) );
697
    addDPStaticEntry( openmenu, qtr( "Open &Disc..." ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
698
        ":/disc", SLOT( openDiscDialog() ) );
699
    addDPStaticEntry( openmenu, qtr( "Open &Network..." ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
700
        ":/network", SLOT( openNetDialog() ) );
701
    addDPStaticEntry( openmenu, qtr( "Open &Capture Device..." ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
702
        ":/capture-card", SLOT( openCaptureDialog() ) );
703 704 705
    menu->addMenu( openmenu );

    menu->addSeparator();
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
706
#if 0
707
    QMenu *helpmenu = HelpMenu( menu );
708 709
    helpmenu->setTitle( qtr( "Help" ) );
    menu->addMenu( helpmenu );
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
710
#endif
711

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
712
    addDPStaticEntry( menu, qtr( "Quit" ), "", ":/quit",
713
                      SLOT( quit() ), "Ctrl+Q" );
714
}
Clément Stenac's avatar
Qt4:  
Clément Stenac committed
715

716
/* Video Tracks and Subtitles tracks */
717
void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf )
718 719 720 721
{
    POPUP_BOILERPLATE;
    if( p_input )
    {
722
        vlc_object_hold( p_input );
723
        vlc_object_t *p_vout = ( vlc_object_t * )vlc_object_find( p_input,
724
                VLC_OBJECT_VOUT, FIND_CHILD );
725 726
        if( p_vout )
        {
727
            VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
728 729 730 731
            vlc_object_release( p_vout );
        }
        vlc_object_release( p_input );
    }
732
    QMenu *menu = new QMenu();
733
    CREATE_POPUP;
734 735
}

736
/* Audio Tracks */
737
void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf )
738 739 740 741
{
    POPUP_BOILERPLATE;
    if( p_input )
    {
742
        vlc_object_hold( p_input );
743
        vlc_object_t *p_aout = ( vlc_object_t * )vlc_object_find( p_input,
744
                VLC_OBJECT_AOUT, FIND_ANYWHERE );
745
        AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
746 747 748 749
        if( p_aout )
            vlc_object_release( p_aout );
        vlc_object_release( p_input );
    }
750
    QMenu *menu = new QMenu();
751
    CREATE_POPUP;
752 753
}

754
/* Navigation stuff, and general menus ( open ) */
755
void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf )
756
{
757
    vlc_value_t val;
758
    POPUP_BOILERPLATE;
759

760 761
    if( p_input )
    {
762
        vlc_object_hold( p_input );
763
        varnames.push_back( "audio-es" );
764
        InputAutoMenuBuilder( VLC_OBJECT( p_input ), objects, varnames );
765 766 767
        PUSH_SEPARATOR;
    }

768 769
    QMenu *menu = new QMenu();
    Populate( p_intf, menu, varnames, objects );
770

771
    menu->addSeparator();
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
772
    PopupMenuControlEntries( menu, p_intf, p_input );
773 774

    menu->addSeparator();
775