menus.cpp 42.1 KB
Newer Older
zorglub's avatar
zorglub committed
1
2
3
/*****************************************************************************
 * menus.cpp : Qt menus
 *****************************************************************************
4
 * Copyright © 2006-2009 the VideoLAN team
5
 * $Id$
zorglub's avatar
zorglub committed
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>
zorglub's avatar
zorglub committed
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.
zorglub's avatar
zorglub committed
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

zorglub's avatar
zorglub committed
34
#include <vlc_intf_strings.h>
35
#include <vlc_services_discovery.h>
zorglub's avatar
zorglub committed
36

zorglub's avatar
zorglub 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 */
43
#include "actions_manager.hpp"
zorglub's avatar
zorglub committed
44

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

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

zorglub's avatar
zorglub committed
67
68
69
70
71
72
73
74
75
enum
{
    ITEM_NORMAL,
    ITEM_CHECK,
    ITEM_RADIO
};

static QActionGroup *currentGroup;

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
QAction *QVLCMenu::fullscreenViewAction = NULL;
80

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

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

113
114
115
116
117
/**
 * @brief Enable all static entries, disable the others
 * @param enable if false, disable all entries
 */
void EnableStaticEntries( QMenu *menu, bool enable = true )
118
{
119
    if( !menu ) return;
120

Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
121
122
    QList< QAction* > actions = menu->actions();
    for( int i = 0; i < actions.size(); ++i )
123
    {
124
        actions[i]->setEnabled( enable && actions[i]->data().toBool() );
125
126
127
    }
}

128
129
130
131
132
133
134
135
/**
 * \return Number of static entries
 */
int DeleteNonStaticEntries( QMenu *menu )
{
    int i_ret = 0;
    if( !menu )
        return VLC_EGENERIC;
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
136
137
    QList< QAction* > actions = menu->actions();
    for( int i = 0; i < actions.size(); ++i )
138
    {
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
139
140
        if( !actions[i]->data().toBool() )
            delete actions[i];
141
142
143
        else
            i_ret++;
    }
144
    return i_ret;
145
146
}

147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/***
 * 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 );
    }
}

zorglub's avatar
zorglub committed
167
/*****************************************************************************
168
 * Definitions of variables for the dynamic menus
zorglub's avatar
zorglub committed
169
 *****************************************************************************/
170
#define PUSH_VAR( var ) varnames.push_back( var ); \
171
    objects.push_back( VLC_OBJECT(p_object) )
172
173

#define PUSH_INPUTVAR( var ) varnames.push_back( var ); \
174
    objects.push_back( VLC_OBJECT(p_input) );
175
176

#define PUSH_SEPARATOR if( objects.size() != i_last_separator ) { \
177
    objects.push_back( 0 ); varnames.push_back( "" ); \
178
    i_last_separator = objects.size(); }
zorglub's avatar
zorglub committed
179

180
static int InputAutoMenuBuilder( input_thread_t *p_object,
181
        vector<vlc_object_t *> &objects,
182
        vector<const char *> &varnames )
zorglub's avatar
zorglub committed
183
{
184
    PUSH_VAR( "bookmark" );
zorglub's avatar
zorglub committed
185
    PUSH_VAR( "title" );
186
    PUSH_VAR( "chapter" );
zorglub's avatar
zorglub committed
187
188
189
190
191
192
    PUSH_VAR( "program" );
    PUSH_VAR( "navigation" );
    PUSH_VAR( "dvd_menus" );
    return VLC_SUCCESS;
}

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
193
static int VideoAutoMenuBuilder( vout_thread_t *p_object,
194
        input_thread_t *p_input,
195
        vector<vlc_object_t *> &objects,
196
        vector<const char *> &varnames )
zorglub's avatar
zorglub committed
197
{
198
199
    PUSH_INPUTVAR( "video-es" );
    PUSH_INPUTVAR( "spu-es" );
zorglub's avatar
zorglub committed
200
201
    PUSH_VAR( "fullscreen" );
    PUSH_VAR( "zoom" );
202
    PUSH_VAR( "scaling" );
zorglub's avatar
zorglub committed
203
204
205
206
    PUSH_VAR( "deinterlace" );
    PUSH_VAR( "aspect-ratio" );
    PUSH_VAR( "crop" );
    PUSH_VAR( "video-on-top" );
207
#ifdef WIN32
zorglub's avatar
zorglub committed
208
    PUSH_VAR( "directx-wallpaper" );
209
#endif
zorglub's avatar
zorglub committed
210
211
    PUSH_VAR( "video-snapshot" );

212
    /* Special case for postproc */
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
213
    // FIXME
214
    if( p_object )
zorglub's avatar
zorglub committed
215
    {
216
217
218
219
220
221
        /* 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 )
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 )
            {
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
228
                vlc_object_t *p_object = p_pp;
229
230
231
232
233
                PUSH_VAR( "postproc-q" );
                vlc_object_release( p_pp );
            }

            vlc_object_release( p_dec );
234
        }
zorglub's avatar
zorglub committed
235
236
237
238
    }
    return VLC_SUCCESS;
}

239
static int AudioAutoMenuBuilder( aout_instance_t *p_object,
240
        input_thread_t *p_input,
241
        vector<vlc_object_t *> &objects,
242
        vector<const char *> &varnames )
zorglub's avatar
zorglub committed
243
{
244
    PUSH_VAR( "visual" );
245
    PUSH_INPUTVAR( "audio-es" );
zorglub's avatar
zorglub committed
246
247
248
249
250
    PUSH_VAR( "audio-device" );
    PUSH_VAR( "audio-channels" );
    return VLC_SUCCESS;
}

251
252
static QAction * FindActionWithVar( QMenu *menu, const char *psz_var )
{
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
253
254
    QList< QAction* > actions = menu->actions();
    for( int i = 0; i < actions.size(); ++i )
255
    {
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
256
257
        if( actions[i]->data().toString() == psz_var )
            return actions[i];
258
259
260
261
    }
    return NULL;
}

262
263
/*****************************************************************************
 * All normal menus
264
 * Simple Code
265
266
267
 *****************************************************************************/

#define BAR_ADD( func, title ) { \
268
    QMenu *_menu = func; _menu->setTitle( title ); bar->addMenu( _menu ); }
269
270

#define BAR_DADD( func, title, id ) { \
271
272
273
274
275
276
277
278
    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 ); }
279

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

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

298
    BAR_ADD( ToolsMenu( NULL ), qtr( "&Tools" ) );
299
300
    BAR_ADD( ViewMenu( p_intf, NULL, mi, visual_selector_enabled, true ),
             qtr( "V&iew" ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
301

302
    BAR_ADD( HelpMenu( NULL ), qtr( "&Help" ) );
303
}
304
305
#undef BAR_ADD
#undef BAR_DADD
306
307

/**
308
 * Media ( File ) Menu
309
310
 * Opening, streaming and quit
 **/
Ludovic Fauvet's avatar
Ludovic Fauvet committed
311
QMenu *QVLCMenu::FileMenu( intf_thread_t *p_intf )
312
313
{
    QMenu *menu = new QMenu();
314

315
    addDPStaticEntry( menu, qtr( "&Open File..." ),
316
        ":/file-asym", SLOT( simpleOpenDialog() ), "Ctrl+O" );
317
    addDPStaticEntry( menu, qtr( "Advanced Open File..." ),
318
        ":/file-asym", SLOT( openFileDialog() ), "Ctrl+Shift+O" );
319
    addDPStaticEntry( menu, qtr( I_OPEN_FOLDER ),
320
        ":/folder-grey", SLOT( PLOpenDir() ), "Ctrl+F" );
321
    addDPStaticEntry( menu, qtr( "Open &Disc..." ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
322
        ":/disc", SLOT( openDiscDialog() ), "Ctrl+D" );
323
    addDPStaticEntry( menu, qtr( "Open &Network..." ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
324
        ":/network", SLOT( openNetDialog() ), "Ctrl+N" );
325
    addDPStaticEntry( menu, qtr( "Open &Capture Device..." ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
326
        ":/capture-card", SLOT( openCaptureDialog() ),
327
        "Ctrl+C" );
328

329
    menu->addSeparator();
330
331
    addDPStaticEntry( menu, qtr( "Paste &MRL" ),
                      NULL, SLOT( openUrlDialog() ), "Ctrl+V" );
332

333
334
335
336
337
338
339
    addDPStaticEntry( menu, qtr( I_PL_LOAD ), "", SLOT( openAPlaylist() ),
        "Ctrl+X" );
    addDPStaticEntry( menu, qtr( I_PL_SAVE ), "", SLOT( saveAPlaylist() ),
        "Ctrl+Y" );

    menu->addSeparator();

340
    recentsMenu = new QMenu( qtr( "Recently &Played" ), menu );
Ludovic Fauvet's avatar
Ludovic Fauvet committed
341
342
    updateRecents( p_intf );
    menu->addMenu( recentsMenu );
343
    menu->addSeparator();
344

345
    addDPStaticEntry( menu, qtr( "Conve&rt / Save..." ), "",
346
        SLOT( openAndTranscodingDialogs() ), "Ctrl+R" );
347
    addDPStaticEntry( menu, qtr( "&Streaming..." ),
348
        ":/stream", SLOT( openAndStreamingDialogs() ),
349
        "Ctrl+S" );
350
    menu->addSeparator();
351

352
    addDPStaticEntry( menu, qtr( "&Quit" ) ,
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
353
        ":/quit", SLOT( quit() ), "Ctrl+Q" );
354
355
356
    return menu;
}

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
357
/* Playlist/MediaLibrary Control */
358
QMenu *QVLCMenu::ToolsMenu( QMenu *parent )
zorglub's avatar
zorglub committed
359
{
360
361
362
363
364
    QMenu *menu;
    if( parent == NULL )
        menu = new QMenu();
    else
        menu = parent;
365
    addDPStaticEntry( menu, qtr( I_MENU_EXT ), ":/settings",
366
            SLOT( extendedDialog() ), "Ctrl+E" );
367

368
    addDPStaticEntry( menu, qtr( I_MENU_INFO ) , ":/info",
369
        SLOT( mediaInfoDialog() ), "Ctrl+I" );
370
    addDPStaticEntry( menu, qtr( I_MENU_CODECINFO ) ,
371
        ":/info", SLOT( mediaCodecDialog() ), "Ctrl+J" );
372

373
    addDPStaticEntry( menu, qtr( I_MENU_BOOKMARK ),"",
374
375
                      SLOT( bookmarksDialog() ), "Ctrl+B" );
#ifdef ENABLE_VLM
376
    addDPStaticEntry( menu, qtr( I_MENU_VLM ), "", SLOT( vlmDialog() ),
377
378
        "Ctrl+W" );
#endif
379
380
381
382
383

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

384
385
    addDPStaticEntry( menu, qtr( "Plu&gins and extensions" ),
        "", SLOT( pluginDialog() ) );
zorglub's avatar
zorglub committed
386
387
    menu->addSeparator();

388
    addDPStaticEntry( menu, qtr( "&Preferences" ),
389
390
        ":/preferences", SLOT( prefsDialog() ), "Ctrl+P" );

zorglub's avatar
zorglub committed
391
392
393
    return menu;
}

394
/**
395
 * View Menu
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
396
 * This menu can be an interface menu but also a right click menu.
397
 **/
398
QMenu *QVLCMenu::ViewMenu( intf_thread_t *p_intf,
399
                            QMenu *current,
400
401
402
                            MainInterface *mi,
                            bool visual_selector_enabled,
                            bool with_intf )
403
{
404
    QMenu *menu = new QMenu( current );
405
    QAction *act;
406
407
    if( mi )
    {
408
        act = menu->addAction( QIcon( ":/playlist_menu" ),
409
                               qtr( "Play&list" ), mi,
410
                               SLOT( togglePlaylist() ), qtr( "Ctrl+L" ) );
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
411
        act->setData( true );
412
    }
413
    act = menu->addMenu( SDMenu( p_intf ) );
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
414
    act->setData( true );
415
416
417
418
    /*menu->addSeparator();
    menu->addAction( qtr( "Undock from Interface" ), mi,
                     SLOT( undockPlaylist() ), qtr( "Ctrl+U" ) );*/

419
420
421

    menu->addSeparator();

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

441
        /* FullScreen View */
442
        action = menu->addAction( qtr( "&Fullscreen Interface" ), mi,
443
                                  SLOT( toggleFullScreen() ), QString( "F11" ) );
444
        fullscreenViewAction = action;
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
445
        action->setCheckable( true );
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
446
        action->setData( true );
447

448
        /* Advanced Controls */
449
        action = menu->addAction( qtr( "&Advanced Controls" ), mi,
450
                                  SLOT( toggleAdvanced() ) );
451
        action->setCheckable( true );
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
452
        action->setData( true );
453
454
        if( mi->getControlsVisibilityStatus() & CONTROLS_ADVANCED )
            action->setChecked( true );
455
#if 0 /* For Visualisations. Not yet working */
456
        adv = menu->addAction( qtr( "Visualizations selector" ),
457
                mi, SLOT( visual() ) );
458
459
        adv->setCheckable( true );
        if( visual_selector_enabled ) adv->setChecked( true );
460
#endif
zorglub's avatar
zorglub committed
461
    }
462

463
    menu->addSeparator();
464
465
466
    addDPStaticEntry( menu, qtr( "Customi&ze Interface..." ),
        ":/preferences", SLOT( toolbarDialog() ) );
    menu->addSeparator();
467

468
469
470
    return menu;
}

471
472
473
/**
 * Interface Sub-Menu, to list extras interface and skins
 **/
474
475
QMenu *QVLCMenu::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
{
476
    vector<vlc_object_t *> objects;
477
478
479
    vector<const char *> varnames;
    /** \todo add "switch to XXX" */
    varnames.push_back( "intf-add" );
480
    objects.push_back( VLC_OBJECT(p_intf) );
zorglub's avatar
Qt4:    
zorglub committed
481

482
    return Populate( p_intf, current, varnames, objects );
483
484
}

485
486
487
/**
 * Main Audio Menu
 */
488
489
QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QMenu * current )
{
490
    vector<vlc_object_t *> objects;
491
    vector<const char *> varnames;
492
    aout_instance_t *p_aout;
493
494
    input_thread_t *p_input;

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

497
    if( current->isEmpty() )
498
    {
499
500
501
502
503
504
505
506
507
508
509
        QAction *action = current->addAction( qtr( "Mute Audio" ),
                ActionsManager::getInstance( p_intf ), SLOT( toggleMuteAudio() ) );
        action->setData( true );
        action = current->addAction( qtr( "Increase Volume" ),
                ActionsManager::getInstance( p_intf ), SLOT( AudioUp() ) );
        action->setData( true );
        action = current->addAction( qtr( "Decrease Volume" ),
                ActionsManager::getInstance( p_intf ), SLOT( AudioDown() ) );
        action->setData( true );

        current->addSeparator();
510
511
        ACT_ADD( current, "visual", qtr( "&Visualizations" ) );
        current->addSeparator();
512
513
514
        ACT_ADD( current, "audio-es", qtr( "Audio &Track" ) );
        ACT_ADD( current, "audio-device", qtr( "Audio &Device" ) );
        ACT_ADD( current, "audio-channels", qtr( "Audio &Channels" ) );
515
516
    }

517
518
    p_input = THEMIM->getInput();
    if( p_input )
519
        vlc_object_hold( p_input );
520
    p_aout = THEMIM->getAout();
521
522
    AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
    EnableStaticEntries( current, ( p_aout != NULL ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
523
    if( p_aout )
524
    {
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
525
        vlc_object_release( p_aout );
526
    }
527
528
529
    if( p_input )
        vlc_object_release( p_input );

530
531
532
    return Populate( p_intf, current, varnames, objects );
}

533
534
535
536
/**
 * Main Video Menu
 * Subtitles are part of Video.
 **/
537
QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current )
zorglub's avatar
zorglub committed
538
{
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
539
    vout_thread_t *p_vout;
540
    input_thread_t *p_input;
541
    vector<vlc_object_t *> objects;
542
543
    vector<const char *> varnames;

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
544
    if( !current ) current = new QMenu();
545
546

    if( current->isEmpty() )
zorglub's avatar
zorglub committed
547
    {
548
        ACT_ADD( current, "video-es", qtr( "Video &Track" ) );
549
550
551
552
553

        QAction *action;
        QMenu *submenu = new QMenu( qtr( "&Subtitles Track" ), current );
        action = current->addMenu( submenu );
        action->setData( "spu-es" );
554
        addDPStaticEntry( submenu, qtr( "Open File..." ), "",
555
                          SLOT( loadSubtitlesFile() ) );
556
        submenu->addSeparator();
557

558
        ACT_ADD( current, "fullscreen", qtr( "&Fullscreen" ) );
559
560
561
562
563
        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" ) );
564
565
566
#ifdef WIN32
        ACT_ADD( current, "directx-wallpaper", qtr( "DirectX Wallpaper" ) );
#endif
567
        ACT_ADD( current, "video-snapshot", qtr( "Sna&pshot" ) );
568
        ACT_ADD( current, "postproc-q", qtr( "Post processing" ) );
zorglub's avatar
zorglub committed
569
    }
570

571
572
    p_input = THEMIM->getInput();
    if( p_input )
573
        vlc_object_hold( p_input );
574

575
    p_vout = THEMIM->getVout();
576
577
    VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
    EnableStaticEntries( current, ( p_vout != NULL ) );
578
    if( p_vout )
579
    {
580
        vlc_object_release( p_vout );
581
    }
582
583
584
    if( p_input )
        vlc_object_release( p_input );

585
    return Populate( p_intf, current, varnames, objects );
zorglub's avatar
zorglub committed
586
587
}

588
589
590
591
/**
 * Navigation Menu
 * For DVD, MP4, MOV and other chapter based format
 **/
592
QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *menu )
593
{
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
594
    if( !menu ) menu = new QMenu();
595
596
597

    if( menu->isEmpty() )
    {
598
        addDPStaticEntry( menu, qtr( I_MENU_GOTOTIME ),"",
599
600
                          SLOT( gotoTimeDialog() ), "Ctrl+T" );
        menu->addSeparator();
601
602

        ACT_ADD( menu, "bookmark", qtr( "&Bookmarks" ) );
603
        ACT_ADD( menu, "title", qtr( "T&itle" ) );
604
605
606
        ACT_ADD( menu, "chapter", qtr( "&Chapter" ) );
        ACT_ADD( menu, "program", qtr( "&Program" ) );
        ACT_ADD( menu, "navigation", qtr( "&Navigation" ) );
607
608
    }

609
610
611
612
613
    input_thread_t *p_object;
    vector<vlc_object_t *> objects;
    vector<const char *> varnames;

    p_object = THEMIM->getInput();
614
615
    if( p_object )
        vlc_object_hold( p_object );
616
    InputAutoMenuBuilder( p_object, objects, varnames );
617
618
619
620
    PUSH_VAR( "prev-title" );
    PUSH_VAR( "next-title" );
    PUSH_VAR( "prev-chapter" );
    PUSH_VAR( "next-chapter" );
621
    EnableStaticEntries( menu, ( p_object != NULL ) );
622
    if( p_object )
623
    {
624
        vlc_object_release( p_object );
625
    }
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
626
    return Populate( p_intf, menu, varnames, objects );
627
}
zorglub's avatar
zorglub committed
628

629
/**
630
 * Service Discovery SubMenu
631
 **/
zorglub's avatar
zorglub committed
632
633
634
QMenu *QVLCMenu::SDMenu( intf_thread_t *p_intf )
{
    QMenu *menu = new QMenu();
635
    menu->setTitle( qtr( I_PL_SD ) );
636
    char **ppsz_longnames;
637
    char **ppsz_names = vlc_sd_GetNames( &ppsz_longnames );
638
639
640
    if( !ppsz_names )
        return menu;

641
642
    char **ppsz_name = ppsz_names, **ppsz_longname = ppsz_longnames;
    for( ; *ppsz_name; ppsz_name++, ppsz_longname++ )
zorglub's avatar
zorglub committed
643
    {
644
        QAction *a = new QAction( qfu( *ppsz_longname ), menu );
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
645
        a->setCheckable( true );
646
        if( playlist_IsServicesDiscoveryLoaded( THEPL, *ppsz_name ) )
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
647
648
            a->setChecked( true );
        CONNECT( a , triggered(), THEDP->SDMapper, map() );
649
        THEDP->SDMapper->setMapping( a, QString( *ppsz_name ) );
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
650
        menu->addAction( a );
651

652
        if( !strcmp( *ppsz_name, "podcast" ) )
653
        {
Christophe Mutricy's avatar
Christophe Mutricy committed
654
            QAction *b = new QAction( qtr( "Configure podcasts..." ), menu );
655
656
657
658
            //b->setEnabled( a->isChecked() );
            menu->addAction( b );
            CONNECT( b, triggered(), THEDP, podcastConfigureDialog() );
        }
659
660
        free( *ppsz_name );
        free( *ppsz_longname );
zorglub's avatar
zorglub committed
661
    }
662
663
    free( ppsz_names );
    free( ppsz_longnames );
zorglub's avatar
zorglub committed
664
665
    return menu;
}
666
667
668
/**
 * Help/About Menu
**/
669
QMenu *QVLCMenu::HelpMenu( QMenu *current )
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
670
{
671
    QMenu *menu = new QMenu( current );
672
    addDPStaticEntry( menu, qtr( "&Help..." ) ,
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
673
        ":/help", SLOT( helpDialog() ), "F1" );
674
#ifdef UPDATE_CHECK
675
676
    addDPStaticEntry( menu, qtr( "Check for &Updates..." ) , "",
                      SLOT( updateDialog() ) );
677
#endif
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
678
    menu->addSeparator();
679
    addDPStaticEntry( menu, qtr( I_MENU_ABOUT ), ":/info",
680
            SLOT( aboutDialog() ), "Shift+F1" );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
681
682
683
    return menu;
}

684
/*****************************************************************************
685
 * Popup menus - Right Click menus                                           *
686
 *****************************************************************************/
zorglub's avatar
zorglub committed
687
688
#define POPUP_BOILERPLATE \
    unsigned int i_last_separator = 0; \
689
    vector<vlc_object_t *> objects; \
690
691
692
693
694
695
696
    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() ); \
zorglub's avatar
zorglub committed
697
    p_intf->p_sys->p_popup_menu = NULL; \
698
    i_last_separator = 0;
zorglub's avatar
zorglub committed
699

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
700
701
702
703
704
705
706
707
708
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 )
709
            addMIMStaticEntry( p_intf, menu, qtr( "Pause" ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
710
                    ":/pause", SLOT( togglePlayPause() ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
711
        else
712
            addMIMStaticEntry( p_intf, menu, qtr( "Play" ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
713
                    ":/play", SLOT( togglePlayPause() ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
714
    }
715
    else if( THEPL->items.i_size )
716
        addMIMStaticEntry( p_intf, menu, qtr( "Play" ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
717
                ":/play", SLOT( togglePlayPause() ) );
718
    else
719
        addDPStaticEntry( menu, qtr( "Play" ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
720
                ":/play", SLOT( openDialog() ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
721

722
    addMIMStaticEntry( p_intf, menu, qtr( "Stop" ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
723
            ":/stop", SLOT( stop() ) );
724
    addMIMStaticEntry( p_intf, menu, qtr( "Previous" ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
725
            ":/previous", SLOT( prev() ) );
726
    addMIMStaticEntry( p_intf, menu, qtr( "Next" ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
727
            ":/next", SLOT( next() ) );
728
}
729

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
730
void QVLCMenu::PopupMenuStaticEntries( QMenu *menu )
731
{
732
    QMenu *openmenu = new QMenu( qtr( "Open Media" ), menu );
733
    addDPStaticEntry( openmenu, qtr( "&Open File..." ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
734
        ":/file-asym", SLOT( openFileDialog() ) );
735
    addDPStaticEntry( openmenu, qtr( I_OPEN_FOLDER ),
736
        ":/folder-grey", SLOT( PLOpenDir() ) );
737
    addDPStaticEntry( openmenu, qtr( "Open &Disc..." ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
738
        ":/disc", SLOT( openDiscDialog() ) );
739
    addDPStaticEntry( openmenu, qtr( "Open &Network..." ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
740
        ":/network", SLOT( openNetDialog() ) );
741
    addDPStaticEntry( openmenu, qtr( "Open &Capture Device..." ),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
742
        ":/capture-card", SLOT( openCaptureDialog() ) );
743
744
745
    menu->addMenu( openmenu );

    menu->addSeparator();
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
746
#if 0
747
    QMenu *helpmenu = HelpMenu( menu );
748
749
    helpmenu->setTitle( qtr( "Help" ) );
    menu->addMenu( helpmenu );
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
750
#endif
751

752
    addDPStaticEntry( menu, qtr( "Quit" ), ":/quit",
753
                      SLOT( quit() ), "Ctrl+Q" );
754
}
zorglub's avatar
Qt4:    
zorglub committed
755

756
/* Video Tracks and Subtitles tracks */
757
void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf )
zorglub's avatar
zorglub committed
758
759
760
761
{
    POPUP_BOILERPLATE;
    if( p_input )
    {
762
        vlc_object_hold( p_input );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
763
        vout_thread_t *p_vout = THEMIM->getVout();
zorglub's avatar
zorglub committed
764
765
        if( p_vout )
        {
766
            VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
zorglub's avatar
zorglub committed
767
768
769
770
            vlc_object_release( p_vout );
        }
        vlc_object_release( p_input );
    }
771
    QMenu *menu = new QMenu();
772
    CREATE_POPUP;
zorglub's avatar
zorglub committed
773
774
}

775
/* Audio Tracks */
776
void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf )
zorglub's avatar
zorglub committed
777
778
779
780
{
    POPUP_BOILERPLATE;
    if( p_input )
    {
781
        vlc_object_hold( p_input );
782
        aout_instance_t *p_aout = THEMIM->getAout();
783
        AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
zorglub's avatar
zorglub committed
784
785
786
787
        if( p_aout )
            vlc_object_release( p_aout );
        vlc_object_release( p_input );
    }
788
    QMenu *menu = new QMenu();
789
    CREATE_POPUP;
zorglub's avatar
zorglub committed
790
791
}

792
/* Navigation stuff, and general menus ( open ) */
793
void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf )
zorglub's avatar
zorglub committed
794
795
{
    POPUP_BOILERPLATE;
796

zorglub's avatar
zorglub committed
797
798
    if( p_input )
    {
799
        vlc_object_hold( p_input );
800
        varnames.push_back( "audio-es" );
801
        InputAutoMenuBuilder( p_input, objects, varnames );
zorglub's avatar
zorglub committed
802
803
804
        PUSH_SEPARATOR;
    }

805
806
    QMenu *menu = new QMenu();
    Populate( p_intf, menu, varnames, objects );
807

808
    menu->addSeparator();
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
809
    PopupMenuControlEntries( menu, p_intf, p_input );
810
811

    menu->addSeparator();
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
812
    PopupMenuStaticEntries( menu );
zorglub's avatar
zorglub committed
813

814
815
    p_intf->p_sys->p_popup_menu = menu;
    menu->popup( QCursor::pos() );
zorglub's avatar
zorglub committed
816
817
818
    p_intf->p_sys->p_popup_menu = NULL;
}

819
/* Main Menu that sticks everything together  */
damienf's avatar
damienf committed
820
void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show )
zorglub's avatar
zorglub committed
821
{
822
    MainInterface *mi = p_intf->p_sys->p_mi;
damienf's avatar
damienf committed
823
    if( show )
zorglub's avatar
zorglub committed
824
    {
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
825
826
827
828
829
830
831
        /* Delete and recreate a popup if there is one */
        if( p_intf->p_sys->p_popup_menu )
            delete p_intf->p_sys->p_popup_menu;

        QMenu *menu = new QMenu();
        QMenu *submenu;
        QAction *action;
832
        bool b_isFullscreen = false;
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
833
834
835
836
837
838
839

        POPUP_BOILERPLATE;

        PopupMenuControlEntries( menu, p_intf, p_input );
        menu->addSeparator();

        if( p_input )
840
        {
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
841
            vout_thread_t *p_vout = THEMIM->getVout();
842
843
844
845
846
847
848
849
850
851

            /* Add a fullscreen switch button */
            if( p_vout )
            {
                vlc_value_t val;
                var_Get( p_vout, "fullscreen", &val );
                b_isFullscreen = !( !val.b_bool );
                if( b_isFullscreen )
                    CreateAndConnect( menu, "fullscreen",
                            qtr( "Leave Fullscreen" ),"" , ITEM_NORMAL,
852