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 "menus.hpp"
39
40

#include "main_interface.hpp"    /* View modifications */
zorglub's avatar
zorglub committed
41
42
#include "dialogs_provider.hpp"
#include "input_manager.hpp"
Ludovic Fauvet's avatar
Ludovic Fauvet committed
43
#include "recents.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
79
/* 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
80
81
QMenu *QVLCMenu::recentsMenu = NULL;

82
83
84
85
86
/****************************************************************************
 * Menu code helpers:
 ****************************************************************************
 * Add static entries to DP in menus
 ***************************************************************************/
87
88
void addDPStaticEntry( QMenu *menu,
                       const QString text,
89
90
                       const char *help,
                       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
    }
110
    action->setData( "_static_" );
111
}
112

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

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

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

144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/***
 * 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
165
/*****************************************************************************
166
 * Definitions of variables for the dynamic menus
zorglub's avatar
zorglub committed
167
 *****************************************************************************/
168
#define PUSH_VAR( var ) varnames.push_back( var ); \
169
    objects.push_back( VLC_OBJECT(p_object) )
170
171

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

328
329
    menu->addSeparator();

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

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

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

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

    addDPStaticEntry( menu, qtr( I_MENU_EXT ), "", ":/settings",
            SLOT( extendedDialog() ), "Ctrl+E" );
    addDPStaticEntry( menu, qtr( I_MENU_MSG ), "",
        ":/messages", SLOT( messagesDialog() ),
        "Ctrl+M" );
357
358
359
    addDPStaticEntry( menu, qtr( "Plugins and extensions" ), "",
        "", SLOT( pluginDialog() ),
        "" );
360
361
362
363
364
365
366
367
368
369
    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
370
371
    menu->addSeparator();

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

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

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

411
412
413

    menu->addSeparator();

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

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

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

454
455
    menu->addSeparator();

456
457
458
    return menu;
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

590
    p_object = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_INPUT,
591
            FIND_ANYWHERE );
592
593
594
595
596
    InputAutoMenuBuilder(  p_object, objects, varnames );
    PUSH_VAR( "prev-title" );
    PUSH_VAR( "next-title" );
    PUSH_VAR( "prev-chapter" );
    PUSH_VAR( "next-chapter" );
597
    EnableDPStaticEntries( menu, ( p_object != NULL ) );
598
    if( p_object )
599
    {
600
        vlc_object_release( p_object );
601
602
    }
    return Populate( p_intf, menu, varnames, objects, true );
603
}
zorglub's avatar
zorglub committed
604

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        POPUP_BOILERPLATE;

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

        if( p_input )
826
        {
827
828
829
830
831
832
833
834
835
836
837
838
            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,
839
                            VLC_OBJECT(p_vout), val, VLC_VAR_BOOL,
840
                            b_isFullscreen );
841
                vlc_object_release( p_vout );
842
843
844
845
            }

            menu->addSeparator();

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

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

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

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

        menu->addSeparator();
870

871
872
        /* Add some special entries for windowed mode: Interface Menu */
        if( !b_isFullscreen )
873
874
        {
            submenu = new QMenu( qtr( "Interface" ), menu );
875
876
877
878
879
            if( mi )
            {
                submenu->addAction( QIcon( ":/playlist" ),
                         qtr( "Show Playlist" ), mi, SLOT( togglePlaylist() ) );
            }
880
            addDPStaticEntry( submenu, qtr( I_MENU_EXT ), "",
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
881
                ":/settings", SLOT( extendedDialog() ) );
882
883
            addDPStaticEntry( submenu, qtr( I_MENU_INFO ) , "", ":/info",
                SLOT( mediaInfoDialog() ), "Ctrl+I" );
884
885
886
            if( mi )
            {
                action = submenu->addAction( QIcon( "" ),
887
                     qtr( "Minimal View" ), mi, SLOT( toggleMinimalView() ) );
888
889
890
891
892
893
894
895
896
                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() );
            }