menus.cpp 41.3 KB
Newer Older
zorglub's avatar
zorglub committed
1
2
3
/*****************************************************************************
 * menus.cpp : Qt menus
 *****************************************************************************
4
 * Copyright © 2006-2009 the VideoLAN team
5
 * $Id$
zorglub's avatar
zorglub committed
6
 *
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
7
 * Authors: Clément Stenac <zorglub@videolan.org>
8
 *          Jean-Baptiste Kempf <jb@videolan.org>
9
 *          Jean-Philippe André <jpeg@videolan.org>
zorglub's avatar
zorglub committed
10
11
12
13
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
14
 * ( at your option ) any later version.
zorglub's avatar
zorglub committed
15
16
17
18
19
20
21
22
23
24
25
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

26
27
28
29
/** \todo
 * - Remove static currentGroup
 */

30
31
32
33
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

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

zorglub's avatar
zorglub committed
37
#include "menus.hpp"
38
39

#include "main_interface.hpp"    /* View modifications */
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
40
41
42
#include "dialogs_provider.hpp"  /* Dialogs display */
#include "input_manager.hpp"     /* Input Management */
#include "recents.hpp"           /* Recent Items */
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
    }
Jean-Philippe Andre's avatar
Jean-Philippe Andre committed
108
    action->setData( true );
109
}
110

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

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

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

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
191
static int VideoAutoMenuBuilder( vout_thread_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
    PUSH_VAR( "fullscreen" );
    PUSH_VAR( "zoom" );
200
    PUSH_VAR( "scaling" );
zorglub's avatar
zorglub committed
201
202
203
204
    PUSH_VAR( "deinterlace" );
    PUSH_VAR( "aspect-ratio" );
    PUSH_VAR( "crop" );
    PUSH_VAR( "video-on-top" );
205
#ifdef WIN32
zorglub's avatar
zorglub committed
206
    PUSH_VAR( "directx-wallpaper" );
207
#endif
zorglub's avatar
zorglub committed
208
209
    PUSH_VAR( "video-snapshot" );

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

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

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

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

260
261
/*****************************************************************************
 * All normal menus
262
 * Simple Code
263
264
265
 *****************************************************************************/

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

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

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

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

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

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

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

313
    addDPStaticEntry( menu, qtr( "&Open File..." ),
314
        ":/file-asym", SLOT( simpleOpenDialog() ), "Ctrl+O" );
315
    addDPStaticEntry( menu, qtr( "Advanced Open File..." ),
316
        ":/file-asym", SLOT( openFileDialog() ), "Ctrl+Shift+O" );
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
    menu->addSeparator();
328
329
    addDPStaticEntry( menu, qtr( "Paste &MRL" ),
                      NULL, SLOT( openUrlDialog() ), "Ctrl+V" );
330

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( QMenu *parent )
zorglub's avatar
zorglub committed
357
{
358
359
360
361
362
    QMenu *menu;
    if( parent == NULL )
        menu = new QMenu();
    else
        menu = parent;
363
    addDPStaticEntry( menu, qtr( I_MENU_EXT ), ":/settings",
364
            SLOT( extendedDialog() ), "Ctrl+E" );
365

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

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

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

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

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

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

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

417
418
419

    menu->addSeparator();

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

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

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

460
    menu->addSeparator();
461
462
463
    addDPStaticEntry( menu, qtr( "Customi&ze Interface..." ),
        ":/preferences", SLOT( toolbarDialog() ) );
    menu->addSeparator();
464

465
466
467
    return menu;
}

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

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

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

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

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

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

516
517
518
    return Populate( p_intf, current, varnames, objects );
}

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

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

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

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

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

557
558
    p_input = THEMIM->getInput();
    if( p_input )
559
        vlc_object_hold( p_input );
560

561
    p_vout = THEMIM->getVout();
562
563
    VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
    EnableStaticEntries( current, ( p_vout != NULL ) );
564
    if( p_vout )
565
    {
566
        vlc_object_release( p_vout );
567
    }
568
569
570
    if( p_input )
        vlc_object_release( p_input );

571
    return Populate( p_intf, current, varnames, objects );
zorglub's avatar
zorglub committed
572
573
}

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

    if( menu->isEmpty() )
    {
584
        addDPStaticEntry( menu, qtr( I_MENU_GOTOTIME ),"",
585
586
                          SLOT( gotoTimeDialog() ), "Ctrl+T" );
        menu->addSeparator();
587
588

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

595
596
597
598
599
    input_thread_t *p_object;
    vector<vlc_object_t *> objects;
    vector<const char *> varnames;

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

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

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

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

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

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

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

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

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

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

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

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

778
/* Navigation stuff, and general menus ( open ) */
779
void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf )
zorglub's avatar
zorglub committed
780
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( 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();
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
798
    PopupMenuStaticEntries( 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
        {
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
827
            vout_thread_t *p_vout = THEMIM->getVout();
828
829
830
831
832
833
834
835
836
837

            /* 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 );
846
            InputAutoMenuBuilder( p_input, objects, varnames );
847
            vlc_object_release( p_input );
Jean-Philippe Andre's avatar