menus.cpp 41.5 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

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 */
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
                       const char *icon,
89
                       const char *member,
90
                       const char *shortcut = NULL )
91
{
92
    QAction *action = NULL;
93
94
95
    if( !EMPTY_STR( icon ) > 0 )
    {
        if( !EMPTY_STR( shortcut ) > 0 )
96
97
            action = menu->addAction( QIcon( icon ), text, THEDP,
                                      member, qtr( shortcut ) );
98
        else
99
            action = menu->addAction( QIcon( icon ), text, THEDP, member );
100
101
102
103
    }
    else
    {
        if( !EMPTY_STR( shortcut ) > 0 )
104
            action = menu->addAction( text, THEDP, member, qtr( shortcut ) );
105
        else
106
            action = menu->addAction( text, THEDP, member );
107
    }
108
    action->setData( "_static_" );
109
}
110

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

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

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

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

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

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

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

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

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

206
    /* Special case for postproc */
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
207
    // FIXME
208
    if( p_object )
zorglub's avatar
zorglub committed
209
    {
210
211
212
213
214
215
        /* 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 )
216
        {
217
218
219
220
221
            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
222
                vlc_object_t *p_object = p_pp;
223
224
225
226
227
                PUSH_VAR( "postproc-q" );
                vlc_object_release( p_pp );
            }

            vlc_object_release( p_dec );
228
        }
zorglub's avatar
zorglub committed
229
230
231
232
    }
    return VLC_SUCCESS;
}

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

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

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

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

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

274
275
276
/**
 * Main Menu Bar Creation
 **/
277
278
279
void QVLCMenu::createMenuBar( MainInterface *mi,
                              intf_thread_t *p_intf,
                              bool visual_selector_enabled )
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
280
/* FIXME remove this visual dependency */
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
#ifdef WIN32
        ":/file-asym", SLOT( simpleOpenDialog() ), "Ctrl+O" );
312
313
    addDPStaticEntry( menu, qtr( "Advanced Open File..." ),
        ":/file-asym", SLOT( openFileDialog() ) );
314
#else
315
        ":/file-asym", SLOT( openFileDialog() ), "Ctrl+O" );
316
#endif
317
318
    addDPStaticEntry( menu, qtr( "Open &URL" ),
                      NULL, SLOT( openUrlDialog() ), "Ctrl+V" );
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
330
    menu->addSeparator();

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

    menu->addSeparator();

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

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

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

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
355
/* Playlist/MediaLibrary Control */
356
QMenu *QVLCMenu::ToolsMenu( intf_thread_t *p_intf )
zorglub's avatar
zorglub committed
357
{
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
358
    VLC_UNUSED( p_intf ); //TODO remove
zorglub's avatar
zorglub committed
359
    QMenu *menu = new QMenu();
360

361
    addDPStaticEntry( menu, qtr( I_MENU_EXT ), ":/settings",
362
            SLOT( extendedDialog() ), "Ctrl+E" );
363

364
    addDPStaticEntry( menu, qtr( I_MENU_INFO ) , ":/info",
365
        SLOT( mediaInfoDialog() ), "Ctrl+I" );
366
    addDPStaticEntry( menu, qtr( I_MENU_CODECINFO ) ,
367
        ":/info", SLOT( mediaCodecDialog() ), "Ctrl+J" );
368

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

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

380
381
    addDPStaticEntry( menu, qtr( "Plu&gins and extensions" ),
        "", SLOT( pluginDialog() ) );
zorglub's avatar
zorglub committed
382
383
    menu->addSeparator();

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

zorglub's avatar
zorglub committed
389
390
391
    return menu;
}

392
393
/**
 * Tools/View Menu
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
394
 * This is kept in the same menu for now, but could change if it gets much
395
 * longer.
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" ) );
411
        act->setData( "_static_" );
412
    }
413
414
    act = menu->addMenu( SDMenu( p_intf ) );
    act->setData( "_static_" );
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 );
436
        action->setData( "_static_" );
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" ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
444
        action->setCheckable( true );
445
        action->setData( "_static_" );
446

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

462
463
    menu->addSeparator();

464
465
466
    return menu;
}

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

478
    return Populate( p_intf, current, varnames, objects );
479
480
}

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

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

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

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

514
515
516
    return Populate( p_intf, current, varnames, objects );
}

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

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
528
    if( !current ) current = new QMenu();
529
530

    if( current->isEmpty() )
zorglub's avatar
zorglub committed
531
    {
532
        ACT_ADD( current, "video-es", qtr( "Video &Track" ) );
533
534
535
536
537

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

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

555
556
    p_input = THEMIM->getInput();
    if( p_input )
557
        vlc_object_hold( p_input );
558

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

568
    return Populate( p_intf, current, varnames, objects );
zorglub's avatar
zorglub committed
569
570
}

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

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

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

592
593
594
595
596
    input_thread_t *p_object;
    vector<vlc_object_t *> objects;
    vector<const char *> varnames;

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

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

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

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

667
/*****************************************************************************
668
 * Popup menus - Right Click menus                                           *
669
 *****************************************************************************/
zorglub's avatar
zorglub committed
670
671
#define POPUP_BOILERPLATE \
    unsigned int i_last_separator = 0; \
672
    vector<vlc_object_t *> objects; \
673
674
675
676
677
678
679
    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
680
    p_intf->p_sys->p_popup_menu = NULL; \
681
    i_last_separator = 0;
zorglub's avatar
zorglub committed
682

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

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

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

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

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

741
    addDPStaticEntry( menu, qtr( "Quit" ), ":/quit",
742
                      SLOT( quit() ), "Ctrl+Q" );
743
}
zorglub's avatar
Qt4:    
zorglub committed
744

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

764
/* Audio Tracks */
765
void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf )
zorglub's avatar
zorglub committed
766
767
768
769
{
    POPUP_BOILERPLATE;
    if( p_input )
    {
770
        vlc_object_hold( p_input );
771
        aout_instance_t *p_aout = THEMIM->getAout();
772
        AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
zorglub's avatar
zorglub committed
773
774
775
776
        if( p_aout )
            vlc_object_release( p_aout );
        vlc_object_release( p_input );
    }
777
    QMenu *menu = new QMenu();
778
    CREATE_POPUP;
zorglub's avatar
zorglub committed
779
780
}

781
/* Navigation stuff, and general menus ( open ) */
782
void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf )
zorglub's avatar
zorglub committed
783
784
{
    POPUP_BOILERPLATE;
785

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

794
795
    QMenu *menu = new QMenu();
    Populate( p_intf, menu, varnames, objects );
796

797
    menu->addSeparator();
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
798
    PopupMenuControlEntries( menu, p_intf, p_input );
799
800

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

803
804
    p_intf->p_sys->p_popup_menu = menu;
    menu->popup( QCursor::pos() );
zorglub's avatar
zorglub committed
805
806
807
    p_intf->p_sys->p_popup_menu = NULL;
}

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

        POPUP_BOILERPLATE;

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

        if( p_input )
829
        {
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
830
            vout_thread_t *p_vout = THEMIM->getVout();
831
832
833
834
835
836
837
838
839
840

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

            menu->addSeparator();

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

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

Jean-Philippe Andre's avatar