menus.cpp 42.1 KB
Newer Older
zorglub's avatar
zorglub committed
1
2
3
/*****************************************************************************
 * menus.cpp : Qt menus
 *****************************************************************************
4
 * Copyright © 2006-2008 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

34
#include <vlc_common.h>
35

zorglub's avatar
zorglub committed
36
#include <vlc_intf_strings.h>
zorglub's avatar
zorglub committed
37

zorglub's avatar
zorglub committed
38
#include "main_interface.hpp"
zorglub's avatar
zorglub committed
39
40
41
#include "menus.hpp"
#include "dialogs_provider.hpp"
#include "input_manager.hpp"
Ludovic Fauvet's avatar
Ludovic Fauvet committed
42
#include "recents.hpp"
zorglub's avatar
zorglub 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.
  */

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

static QActionGroup *currentGroup;

75
76
77
78
/* HACK for minimalView to go around a Qt bug/feature
 * that doesn't update the QAction checked state when QMenu is hidden */
QAction *QVLCMenu::minimalViewAction = NULL;

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

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

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

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

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

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

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

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

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

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

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

208
    /* Special case for postproc */
209
    if( p_object )
zorglub's avatar
zorglub committed
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
223
224
225
226
227
228
            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 );
229
        }
zorglub's avatar
zorglub committed
230
231
232
233
234
    }
    return VLC_SUCCESS;
}

static int AudioAutoMenuBuilder( vlc_object_t *p_object,
235
        input_thread_t *p_input,
236
        vector<vlc_object_t *> &objects,
237
        vector<const char *> &varnames )
zorglub's avatar
zorglub committed
238
{
239
    PUSH_INPUTVAR( "audio-es" );
zorglub's avatar
zorglub committed
240
241
    PUSH_VAR( "audio-device" );
    PUSH_VAR( "audio-channels" );
242
    PUSH_VAR( "visual" );
zorglub's avatar
zorglub committed
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 )
zorglub's avatar
Qt4:    
zorglub committed
281
{
282
283
284
    /* QMainWindows->menuBar()
       gives the QProcess::destroyed timeout issue on Cleanlooks style with
       setDesktopAware set to false */
zorglub's avatar
zorglub committed
285
    QMenuBar *bar = mi->menuBar();
Ludovic Fauvet's avatar
Ludovic Fauvet committed
286
    BAR_ADD( FileMenu( p_intf ), qtr( "&Media" ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
287
288
289

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

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

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

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

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

327
328
    menu->addSeparator();

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

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

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

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
346
/* Playlist/MediaLibrary Control */
347
QMenu *QVLCMenu::ToolsMenu( intf_thread_t *p_intf )
zorglub's avatar
zorglub committed
348
349
{
    QMenu *menu = new QMenu();
350
351
352
353
354
355

    addDPStaticEntry( menu, qtr( I_MENU_EXT ), "", ":/settings",
            SLOT( extendedDialog() ), "Ctrl+E" );
    addDPStaticEntry( menu, qtr( I_MENU_MSG ), "",
        ":/messages", SLOT( messagesDialog() ),
        "Ctrl+M" );
356
357
358
    addDPStaticEntry( menu, qtr( "Plugins and extensions" ), "",
        "", SLOT( pluginDialog() ),
        "" );
359
360
361
362
363
364
365
366
367
368
    addDPStaticEntry( menu, qtr( I_MENU_INFO ) , "", ":/info",
        SLOT( mediaInfoDialog() ), "Ctrl+I" );
    addDPStaticEntry( menu, qtr( I_MENU_CODECINFO ) , "",
        ":/info", SLOT( mediaCodecDialog() ), "Ctrl+J" );
    addDPStaticEntry( menu, qtr( I_MENU_BOOKMARK ), "","",
                      SLOT( bookmarksDialog() ), "Ctrl+B" );
#ifdef ENABLE_VLM
    addDPStaticEntry( menu, qtr( I_MENU_VLM ), "", "", SLOT( vlmDialog() ),
        "Ctrl+W" );
#endif
zorglub's avatar
zorglub committed
369
370
    menu->addSeparator();

371
    addDPStaticEntry( menu, qtr( "Customi&ze Interface..." ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
372
        ":/preferences", SLOT( toolbarDialog() ), "" );
373
374
375
    addDPStaticEntry( menu, qtr( "&Preferences..." ), "",
        ":/preferences", SLOT( prefsDialog() ), "Ctrl+P" );

zorglub's avatar
zorglub committed
376
377
378
    return menu;
}

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

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

410
411
412

    menu->addSeparator();

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

432
        /* FullScreen View */
433
        action = menu->addAction( qtr( "&Fullscreen Interface" ), mi,
434
                                  SLOT( toggleFullScreen() ), QString( "F11" ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
435
        action->setCheckable( true );
436
        action->setData( "_static_" );
437

438
        /* Advanced Controls */
439
        action = menu->addAction( qtr( "&Advanced Controls" ), mi,
440
                                  SLOT( toggleAdvanced() ) );
441
        action->setCheckable( true );
442
        action->setData( "_static_" );
443
444
        if( mi->getControlsVisibilityStatus() & CONTROLS_ADVANCED )
            action->setChecked( true );
445
#if 0 /* For Visualisations. Not yet working */
446
        adv = menu->addAction( qtr( "Visualizations selector" ),
447
                mi, SLOT( visual() ) );
448
449
        adv->setCheckable( true );
        if( visual_selector_enabled ) adv->setChecked( true );
450
#endif
zorglub's avatar
zorglub committed
451
    }
452

453
454
    menu->addSeparator();

455
456
457
    return menu;
}

458
459
460
/**
 * Interface Sub-Menu, to list extras interface and skins
 **/
461
462
QMenu *QVLCMenu::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
{
463
    vector<vlc_object_t *> objects;
464
465
466
    vector<const char *> varnames;
    /** \todo add "switch to XXX" */
    varnames.push_back( "intf-add" );
467
    objects.push_back( VLC_OBJECT(p_intf) );
zorglub's avatar
Qt4:    
zorglub committed
468

469
    return Populate( p_intf, current, varnames, objects );
470
471
}

472
473
474
/**
 * Main Audio Menu
 */
475
476
QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QMenu * current )
{
477
    vector<vlc_object_t *> objects;
478
    vector<const char *> varnames;
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
479
    vlc_object_t *p_aout;
480
481
    input_thread_t *p_input;

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

484
    if( current->isEmpty() )
485
    {
486
487
488
        ACT_ADD( current, "audio-es", qtr( "Audio &Track" ) );
        ACT_ADD( current, "audio-device", qtr( "Audio &Device" ) );
        ACT_ADD( current, "audio-channels", qtr( "Audio &Channels" ) );
489
490
        current->addSeparator();
        ACT_ADD( current, "visual", qtr( "&Visualizations" ) );
491
492
    }

493
494
    p_input = THEMIM->getInput();
    if( p_input )
495
        vlc_object_hold( p_input );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
496
497
498
    p_aout = ( vlc_object_t * ) vlc_object_find( p_intf,
                                                 VLC_OBJECT_AOUT,
                                                 FIND_ANYWHERE );
499

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

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
502
503
    if( p_aout )
        vlc_object_release( p_aout );
504
505
506
    if( p_input )
        vlc_object_release( p_input );

507
508
509
    return Populate( p_intf, current, varnames, objects );
}

510
511
512
513
/**
 * Main Video Menu
 * Subtitles are part of Video.
 **/
514
QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current )
zorglub's avatar
zorglub committed
515
{
516
    vlc_object_t *p_vout;
517
    input_thread_t *p_input;
518
    vector<vlc_object_t *> objects;
519
520
    vector<const char *> varnames;

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
521
    if( !current ) current = new QMenu();
522
523

    if( current->isEmpty() )
zorglub's avatar
zorglub committed
524
    {
525
        ACT_ADD( current, "video-es", qtr( "Video &Track" ) );
526
527
528
529
530

        QAction *action;
        QMenu *submenu = new QMenu( qtr( "&Subtitles Track" ), current );
        action = current->addMenu( submenu );
        action->setData( "spu-es" );
531
        addDPStaticEntry( submenu, qtr( "Open File..." ), "", "",
532
                          SLOT( loadSubtitlesFile() ) );
533
        submenu->addSeparator();
534

535
        ACT_ADD( current, "fullscreen", qtr( "&Fullscreen" ) );
536
537
538
539
540
        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" ) );
541
542
543
#ifdef WIN32
        ACT_ADD( current, "directx-wallpaper", qtr( "DirectX Wallpaper" ) );
#endif
544
        ACT_ADD( current, "video-snapshot", qtr( "Sna&pshot" ) );
545
        ACT_ADD( current, "postproc-q", qtr( "Post processing" ) );
zorglub's avatar
zorglub committed
546
    }
547

548
549
    p_input = THEMIM->getInput();
    if( p_input )
550
        vlc_object_hold( p_input );
551
    p_vout = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_VOUT,
552
            FIND_ANYWHERE );
553

554
    VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
555

556
557
    if( p_vout )
        vlc_object_release( p_vout );
558
559
560
    if( p_input )
        vlc_object_release( p_input );

561
    return Populate( p_intf, current, varnames, objects );
zorglub's avatar
zorglub committed
562
563
}

564
565
566
567
/**
 * Navigation Menu
 * For DVD, MP4, MOV and other chapter based format
 **/
568
QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *menu )
569
570
{
    vlc_object_t *p_object;
571
    vector<vlc_object_t *> objects;
572
    vector<const char *> varnames;
zorglub's avatar
zorglub committed
573

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
574
    if( !menu ) menu = new QMenu();
575
576
577

    if( menu->isEmpty() )
    {
578
579
580
        addDPStaticEntry( menu, qtr( I_MENU_GOTOTIME ), "","",
                          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
    p_object = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_INPUT,
590
            FIND_ANYWHERE );
591
592
593
594
595
    InputAutoMenuBuilder(  p_object, objects, varnames );
    PUSH_VAR( "prev-title" );
    PUSH_VAR( "next-title" );
    PUSH_VAR( "prev-chapter" );
    PUSH_VAR( "next-chapter" );
596
    EnableDPStaticEntries( menu, ( p_object != NULL ) );
597
    if( p_object )
598
    {
599
        vlc_object_release( p_object );
600
601
    }
    return Populate( p_intf, menu, varnames, objects, true );
602
}
zorglub's avatar
zorglub committed
603

604
/**
605
 * Service Discovery SubMenu
606
 **/
zorglub's avatar
zorglub committed
607
608
609
QMenu *QVLCMenu::SDMenu( intf_thread_t *p_intf )
{
    QMenu *menu = new QMenu();
610
    menu->setTitle( qtr( I_PL_SD ) );
611
612
613
    char **ppsz_longnames;
    char **ppsz_names = services_discovery_GetServicesNames( p_intf,
                                                             &ppsz_longnames );
614
615
616
    if( !ppsz_names )
        return menu;

617
618
    char **ppsz_name = ppsz_names, **ppsz_longname = ppsz_longnames;
    for( ; *ppsz_name; ppsz_name++, ppsz_longname++ )
zorglub's avatar
zorglub committed
619
    {
620
        QAction *a = new QAction( qfu( *ppsz_longname ), menu );
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
621
        a->setCheckable( true );
622
        if( playlist_IsServicesDiscoveryLoaded( THEPL, *ppsz_name ) )
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
623
624
            a->setChecked( true );
        CONNECT( a , triggered(), THEDP->SDMapper, map() );
625
        THEDP->SDMapper->setMapping( a, QString( *ppsz_name ) );
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
626
        menu->addAction( a );
627

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

660
/*****************************************************************************
661
 * Popup menus - Right Click menus                                           *
662
 *****************************************************************************/
zorglub's avatar
zorglub committed
663
664
#define POPUP_BOILERPLATE \
    unsigned int i_last_separator = 0; \
665
    vector<vlc_object_t *> objects; \
666
667
668
669
670
671
672
    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
673
    p_intf->p_sys->p_popup_menu = NULL; \
674
    i_last_separator = 0;
zorglub's avatar
zorglub committed
675

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

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

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

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

    menu->addSeparator();
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
728
#if 0
729
    QMenu *helpmenu = HelpMenu( menu );
730
731
    helpmenu->setTitle( qtr( "Help" ) );
    menu->addMenu( helpmenu );
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
732
#endif
733

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
734
    addDPStaticEntry( menu, qtr( "Quit" ), "", ":/quit",
735
                      SLOT( quit() ), "Ctrl+Q" );
736
}
zorglub's avatar
Qt4:    
zorglub committed
737

738
/* Video Tracks and Subtitles tracks */
739
void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf )
zorglub's avatar
zorglub committed
740
741
742
743
{
    POPUP_BOILERPLATE;
    if( p_input )
    {
744
        vlc_object_hold( p_input );
745
        vlc_object_t *p_vout = ( vlc_object_t * )vlc_object_find( p_input,
746
                VLC_OBJECT_VOUT, FIND_CHILD );
zorglub's avatar
zorglub committed
747
748
        if( p_vout )
        {
749
            VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
zorglub's avatar
zorglub committed
750
751
752
753
            vlc_object_release( p_vout );
        }
        vlc_object_release( p_input );
    }
754
    QMenu *menu = new QMenu();
755
    CREATE_POPUP;
zorglub's avatar
zorglub committed
756
757
}

758
/* Audio Tracks */
759
void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf )
zorglub's avatar
zorglub committed
760
761
762
763
{
    POPUP_BOILERPLATE;
    if( p_input )
    {
764
        vlc_object_hold( p_input );
765
        vlc_object_t *p_aout = ( vlc_object_t * )vlc_object_find( p_input,
766
                VLC_OBJECT_AOUT, FIND_ANYWHERE );
767
        AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
zorglub's avatar
zorglub committed
768
769
770
771
        if( p_aout )
            vlc_object_release( p_aout );
        vlc_object_release( p_input );
    }
772
    QMenu *menu = new QMenu();
773
    CREATE_POPUP;
zorglub's avatar
zorglub committed
774
775
}

776
/* Navigation stuff, and general menus ( open ) */
777
void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf )
zorglub's avatar
zorglub committed
778
{
779
    vlc_value_t val;
zorglub's avatar
zorglub committed
780
    POPUP_BOILERPLATE;
781

zorglub's avatar
zorglub committed
782
783
    if( p_input )
    {
784
        vlc_object_hold( p_input );
785
        varnames.push_back( "audio-es" );
786
        InputAutoMenuBuilder( VLC_OBJECT( p_input ), objects, varnames );
zorglub's avatar
zorglub committed
787
788
789
        PUSH_SEPARATOR;
    }

790
791
    QMenu *menu = new QMenu();
    Populate( p_intf, menu, varnames, objects );
792

793
    menu->addSeparator();
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
794
    PopupMenuControlEntries( menu, p_intf, p_input );
795
796

    menu->addSeparator();
797
    PopupMenuStaticEntries( p_intf, menu );
zorglub's avatar
zorglub committed
798

799
800
    p_intf->p_sys->p_popup_menu = menu;
    menu->popup( QCursor::pos() );
zorglub's avatar
zorglub committed
801
802
803
    p_intf->p_sys->p_popup_menu = NULL;
}

804
/* Main Menu that sticks everything together  */
damienf's avatar
damienf committed
805
void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show )
zorglub's avatar
zorglub committed
806
{
807
    MainInterface *mi = p_intf->p_sys->p_mi;
damienf's avatar
damienf committed
808
    if( show )
zorglub's avatar
zorglub committed
809
    {
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
810
811
812
813
814
815
816
        /* 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;
817
        bool b_isFullscreen = false;
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
818
819
820
821
822
823
824

        POPUP_BOILERPLATE;

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

        if( p_input )
825
        {
826
827
828
829
830
831
832
833
834
835
836
837
            vlc_object_t *p_vout = (vlc_object_t *)
                vlc_object_find( p_input, VLC_OBJECT_VOUT, FIND_CHILD );

            /* 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,
838
                            VLC_OBJECT(p_vout), val, VLC_VAR_BOOL,
839
                            b_isFullscreen );
840
                vlc_object_release( p_vout );
841
842
843
844
            }

            menu->addSeparator();

845
            vlc_object_hold( p_input );
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
846
            InputAutoMenuBuilder( VLC_OBJECT( p_input ), objects, varnames );
847
            vlc_object_release( p_input );
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
848

849
850
            submenu = new QMenu( menu );
            action = menu->addMenu( AudioMenu( p_intf, submenu ) );
851
852
            action->setText( qtr( "&Audio" ) );
            if( action->menu()->isEmpty() )
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
853
854
                action->setEnabled( false );

855
856
            submenu = new QMenu( menu );
            action = menu->addMenu( VideoMenu( p_intf, submenu ) );
857
858
            action->setText( qtr( "&Video" ) );
            if( action->menu()->isEmpty() )
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
859
860
                action->setEnabled( false );

861
862
            submenu = new QMenu( menu );
            action = menu->addMenu( NavigMenu( p_intf, submenu ) );
863
864
865
            action->setText( qtr( "&Playback" ) );
            if( action->menu()->isEmpty() )
                action->setEnabled( false );
866
        }
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
867
868

        menu->addSeparator();
869

870
871
        /* Add some special entries for windowed mode: Interface Menu */
        if( !b_isFullscreen )
872
873
        {
            submenu = new QMenu( qtr( "Interface" ), menu );
874
875
876
877
878
            if( mi )
            {
                submenu->addAction( QIcon( ":/playlist" ),
                         qtr( "Show Playlist" ), mi, SLOT( togglePlaylist() ) );
            }
879
            addDPStaticEntry( submenu, qtr( I_MENU_EXT ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
880
                ":/settings", SLOT( extendedDialog() ) );
881
882
            addDPStaticEntry( submenu, qtr( I_MENU_INFO ) , "", ":/info",
                SLOT( mediaInfoDialog() ), "Ctrl+I" );
883
884
885
            if( mi )
            {
                action = submenu->addAction( QIcon( "" ),
886
                     qtr( "Minimal View" ), mi, SLOT( toggleMinimalView() ) );
887
888
889
890
891
892
893
894
895
                action->setCheckable( true );
                action->setChecked( !( mi->getControlsVisibilityStatus() &
                            CONTROLS_VISIBLE ) );
                action = submenu->addAction( QIcon( "" ),
                        qtr( "Toggle Fullscreen Interface" ),
                        mi, SLOT( toggleFullScreen() ) );
                action->setCheckable( true );
                action->setChecked( mi->isFullScreen() );
            }
896
897
898
            else /* We are using the skins interface.
                    If not, this entry will not show. */
            {
Jean-Baptiste Kempf's avatar