]> git.sesse.net Git - vlc/blob - modules/gui/qt4/menus.cpp
deb2ea44d26c314c3dd5fb4638cd0cb11069929d
[vlc] / modules / gui / qt4 / menus.cpp
1 /*****************************************************************************
2  * menus.cpp : Qt menus
3  *****************************************************************************
4  * Copyright © 2006-2009 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Clément Stenac <zorglub@videolan.org>
8  *          Jean-Baptiste Kempf <jb@videolan.org>
9  *          Jean-Philippe André <jpeg@videolan.org>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * ( at your option ) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24  *****************************************************************************/
25
26 /** \todo
27  * - Remove static currentGroup
28  */
29
30 #ifdef HAVE_CONFIG_H
31 # include "config.h"
32 #endif
33
34 #include <vlc_intf_strings.h>
35 #include <vlc_services_discovery.h>
36
37 #include "menus.hpp"
38
39 #include "main_interface.hpp"    /* View modifications */
40 #include "dialogs_provider.hpp"  /* Dialogs display */
41 #include "input_manager.hpp"     /* Input Management */
42 #include "recents.hpp"           /* Recent Items */
43 #include "actions_manager.hpp"
44
45 #include <QMenu>
46 #include <QMenuBar>
47 #include <QAction>
48 #include <QActionGroup>
49 #include <QSignalMapper>
50 #include <QSystemTrayIcon>
51 #include <QList>
52
53 /*
54   This file defines the main menus and the pop-up menu (right-click menu)
55   and the systray menu (in that order in the file)
56
57   There are 3 menus that have to be rebuilt everytime there are called:
58   Audio, Video, Navigation
59   3 functions are building those menus: AudioMenu, VideoMenu, NavigMenu
60   and 3 functions associated are collecting the objects :
61   InputAutoMenuBuilder, AudioAutoMenuBuilder, VideoAutoMenuBuilder.
62
63   A QSignalMapper decides when to rebuild those menus cf MenuFunc in the .hpp
64   Just before one of those menus are aboutToShow(), they are rebuild.
65   */
66
67 enum
68 {
69     ITEM_NORMAL,
70     ITEM_CHECK,
71     ITEM_RADIO
72 };
73
74 static QActionGroup *currentGroup;
75
76 /* HACK for minimalView to go around a Qt bug/feature
77  * that doesn't update the QAction checked state when QMenu is hidden */
78 QAction *QVLCMenu::minimalViewAction = NULL;
79 QAction *QVLCMenu::fullscreenViewAction = NULL;
80
81 QMenu *QVLCMenu::recentsMenu = NULL;
82
83 /****************************************************************************
84  * Menu code helpers:
85  ****************************************************************************
86  * Add static entries to DP in menus
87  ***************************************************************************/
88 void addDPStaticEntry( QMenu *menu,
89                        const QString text,
90                        const char *icon,
91                        const char *member,
92                        const char *shortcut = NULL )
93 {
94     QAction *action = NULL;
95     if( !EMPTY_STR( icon ) > 0 )
96     {
97         if( !EMPTY_STR( shortcut ) > 0 )
98             action = menu->addAction( QIcon( icon ), text, THEDP,
99                                       member, qtr( shortcut ) );
100         else
101             action = menu->addAction( QIcon( icon ), text, THEDP, member );
102     }
103     else
104     {
105         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( true );
111 }
112
113 /**
114  * @brief Enable all static entries, disable the others
115  * @param enable if false, disable all entries
116  */
117 void EnableStaticEntries( QMenu *menu, bool enable = true )
118 {
119     if( !menu ) return;
120
121     QList< QAction* > actions = menu->actions();
122     for( int i = 0; i < actions.size(); ++i )
123     {
124         actions[i]->setEnabled( enable && actions[i]->data().toBool() );
125     }
126 }
127
128 /**
129  * \return Number of static entries
130  */
131 int DeleteNonStaticEntries( QMenu *menu )
132 {
133     int i_ret = 0;
134     if( !menu )
135         return VLC_EGENERIC;
136     QList< QAction* > actions = menu->actions();
137     for( int i = 0; i < actions.size(); ++i )
138     {
139         if( !actions[i]->data().toBool() )
140             delete actions[i];
141         else
142             i_ret++;
143     }
144     return i_ret;
145 }
146
147 /***
148  * Same for MIM
149  ***/
150 void addMIMStaticEntry( intf_thread_t *p_intf,
151                         QMenu *menu,
152                         const QString text,
153                         const char *icon,
154                         const char *member )
155 {
156     if( strlen( icon ) > 0 )
157     {
158         QAction *action = menu->addAction( text, THEMIM,  member );
159         action->setIcon( QIcon( icon ) );
160     }
161     else
162     {
163         menu->addAction( text, THEMIM, member );
164     }
165 }
166
167 /*****************************************************************************
168  * Definitions of variables for the dynamic menus
169  *****************************************************************************/
170 #define PUSH_VAR( var ) varnames.push_back( var ); \
171     objects.push_back( VLC_OBJECT(p_object) )
172
173 #define PUSH_INPUTVAR( var ) varnames.push_back( var ); \
174     objects.push_back( VLC_OBJECT(p_input) );
175
176 #define PUSH_SEPARATOR if( objects.size() != i_last_separator ) { \
177     objects.push_back( 0 ); varnames.push_back( "" ); \
178     i_last_separator = objects.size(); }
179
180 static int InputAutoMenuBuilder( input_thread_t *p_object,
181         vector<vlc_object_t *> &objects,
182         vector<const char *> &varnames )
183 {
184     PUSH_VAR( "bookmark" );
185     PUSH_VAR( "title" );
186     PUSH_VAR( "chapter" );
187     PUSH_VAR( "navigation" );
188     PUSH_VAR( "program" );
189     PUSH_VAR( "dvd_menus" );
190     return VLC_SUCCESS;
191 }
192
193 static int VideoAutoMenuBuilder( vout_thread_t *p_object,
194         input_thread_t *p_input,
195         vector<vlc_object_t *> &objects,
196         vector<const char *> &varnames )
197 {
198     PUSH_INPUTVAR( "video-es" );
199     PUSH_INPUTVAR( "spu-es" );
200     PUSH_VAR( "fullscreen" );
201     PUSH_VAR( "video-on-top" );
202 #ifdef WIN32
203     PUSH_VAR( "directx-wallpaper" );
204 #endif
205     PUSH_VAR( "video-snapshot" );
206     PUSH_VAR( "zoom" );
207     PUSH_VAR( "scale" );
208     PUSH_VAR( "aspect-ratio" );
209     PUSH_VAR( "crop" );
210     PUSH_VAR( "deinterlace" );
211
212     /* Special case for postproc */
213     // FIXME
214     if( p_object )
215     {
216         /* p_object is the vout, so the decoder is our parent and the
217          * postproc filter one of the decoder's children */
218         vlc_object_t *p_dec = (vlc_object_t *)
219                               vlc_object_find( p_object, VLC_OBJECT_DECODER,
220                                                FIND_PARENT );
221         if( p_dec )
222         {
223             vlc_object_t *p_pp = (vlc_object_t *)
224                                  vlc_object_find_name( p_dec, "postproc",
225                                                        FIND_CHILD );
226             if( p_pp )
227             {
228                 vlc_object_t *p_object = p_pp;
229                 PUSH_VAR( "postproc-q" );
230                 vlc_object_release( p_pp );
231             }
232
233             vlc_object_release( p_dec );
234         }
235     }
236     return VLC_SUCCESS;
237 }
238
239 static int AudioAutoMenuBuilder( aout_instance_t *p_object,
240         input_thread_t *p_input,
241         vector<vlc_object_t *> &objects,
242         vector<const char *> &varnames )
243 {
244     PUSH_INPUTVAR( "audio-es" );
245     PUSH_VAR( "audio-channels" );
246     PUSH_VAR( "audio-device" );
247     PUSH_VAR( "visual" );
248     return VLC_SUCCESS;
249 }
250
251 static QAction * FindActionWithVar( QMenu *menu, const char *psz_var )
252 {
253     QList< QAction* > actions = menu->actions();
254     for( int i = 0; i < actions.size(); ++i )
255     {
256         if( actions[i]->data().toString() == psz_var )
257             return actions[i];
258     }
259     return NULL;
260 }
261
262 /*****************************************************************************
263  * All normal menus
264  * Simple Code
265  *****************************************************************************/
266
267 #define BAR_ADD( func, title ) { \
268     QMenu *_menu = func; _menu->setTitle( title ); bar->addMenu( _menu ); }
269
270 #define BAR_DADD( func, title, id ) { \
271     QMenu *_menu = func; _menu->setTitle( title ); bar->addMenu( _menu ); \
272     MenuFunc *f = new MenuFunc( _menu, id ); \
273     CONNECT( _menu, aboutToShow(), THEDP->menusUpdateMapper, map() ); \
274     THEDP->menusUpdateMapper->setMapping( _menu, f ); }
275
276 #define ACT_ADD( _menu, val, title ) { \
277     QAction *_action = new QAction( title, _menu ); _action->setData( val ); \
278     _menu->addAction( _action ); }
279
280 /**
281  * Main Menu Bar Creation
282  **/
283 void QVLCMenu::createMenuBar( MainInterface *mi,
284                               intf_thread_t *p_intf,
285                               bool visual_selector_enabled )
286 /* FIXME remove this visual dependency */
287 {
288     /* QMainWindows->menuBar()
289        gives the QProcess::destroyed timeout issue on Cleanlooks style with
290        setDesktopAware set to false */
291     QMenuBar *bar = mi->menuBar();
292     BAR_ADD( FileMenu( p_intf, bar ), qtr( "&Media" ) );
293
294     BAR_DADD( NavigMenu( p_intf, bar ), qtr( "P&layback" ), 3 );
295     BAR_DADD( AudioMenu( p_intf, bar ), qtr( "&Audio" ), 1 );
296     BAR_DADD( VideoMenu( p_intf, bar ), qtr( "&Video" ), 2 );
297
298     BAR_ADD( ToolsMenu( bar ), qtr( "&Tools" ) );
299     BAR_ADD( ViewMenu( p_intf, NULL, mi, visual_selector_enabled, true ),
300              qtr( "V&iew" ) );
301
302     BAR_ADD( HelpMenu( bar ), qtr( "&Help" ) );
303 }
304 #undef BAR_ADD
305 #undef BAR_DADD
306
307 /**
308  * Media ( File ) Menu
309  * Opening, streaming and quit
310  **/
311 QMenu *QVLCMenu::FileMenu( intf_thread_t *p_intf, QWidget *parent )
312 {
313     QMenu *menu = new QMenu( parent );
314
315     addDPStaticEntry( menu, qtr( "&Open File..." ),
316         ":/file-asym", SLOT( simpleOpenDialog() ), "Ctrl+O" );
317     addDPStaticEntry( menu, qtr( "Advanced Open File..." ),
318         ":/file-asym", SLOT( openFileDialog() ), "Ctrl+Shift+O" );
319     addDPStaticEntry( menu, qtr( I_OPEN_FOLDER ),
320         ":/folder-grey", SLOT( PLOpenDir() ), "Ctrl+F" );
321     addDPStaticEntry( menu, qtr( "Open &Disc..." ),
322         ":/disc", SLOT( openDiscDialog() ), "Ctrl+D" );
323     addDPStaticEntry( menu, qtr( "Open &Network..." ),
324         ":/network", SLOT( openNetDialog() ), "Ctrl+N" );
325     addDPStaticEntry( menu, qtr( "Open &Capture Device..." ),
326         ":/capture-card", SLOT( openCaptureDialog() ),
327         "Ctrl+C" );
328
329     menu->addSeparator();
330     addDPStaticEntry( menu, qtr( "Paste &MRL" ),
331                       NULL, SLOT( openUrlDialog() ), "Ctrl+V" );
332
333     recentsMenu = new QMenu( qtr( "&Recent Media" ), menu );
334     updateRecents( p_intf );
335     menu->addMenu( recentsMenu );
336     menu->addSeparator();
337     menu->addMenu( SDMenu( p_intf, menu ) );
338     menu->addSeparator();
339
340     addDPStaticEntry( menu, qtr( I_PL_SAVE ), "", SLOT( saveAPlaylist() ),
341         "Ctrl+Y" );
342     menu->addSeparator();
343
344     addDPStaticEntry( menu, qtr( "Conve&rt / Save..." ), "",
345         SLOT( openAndTranscodingDialogs() ), "Ctrl+R" );
346     addDPStaticEntry( menu, qtr( "&Streaming..." ),
347         ":/stream", SLOT( openAndStreamingDialogs() ),
348         "Ctrl+S" );
349     menu->addSeparator();
350
351     addDPStaticEntry( menu, qtr( "&Quit" ) ,
352         ":/quit", SLOT( quit() ), "Ctrl+Q" );
353     return menu;
354 }
355
356 /* Playlist/MediaLibrary Control */
357 QMenu *QVLCMenu::ToolsMenu( QMenu *menu )
358 {
359     addDPStaticEntry( menu, qtr( I_MENU_EXT ), ":/settings",
360             SLOT( extendedDialog() ), "Ctrl+E" );
361
362     addDPStaticEntry( menu, qtr( I_MENU_INFO ) , ":/info",
363         SLOT( mediaInfoDialog() ), "Ctrl+I" );
364     addDPStaticEntry( menu, qtr( I_MENU_CODECINFO ) ,
365         ":/info", SLOT( mediaCodecDialog() ), "Ctrl+J" );
366
367     addDPStaticEntry( menu, qtr( I_MENU_BOOKMARK ),"",
368                       SLOT( bookmarksDialog() ), "Ctrl+B" );
369 #ifdef ENABLE_VLM
370     addDPStaticEntry( menu, qtr( I_MENU_VLM ), "", SLOT( vlmDialog() ),
371         "Ctrl+W" );
372 #endif
373
374     addDPStaticEntry( menu, qtr( I_MENU_MSG ),
375         ":/messages", SLOT( messagesDialog() ),
376         "Ctrl+M" );
377
378     addDPStaticEntry( menu, qtr( "Plu&gins and extensions" ),
379         "", SLOT( pluginDialog() ) );
380     menu->addSeparator();
381
382     addDPStaticEntry( menu, qtr( "&Preferences" ),
383         ":/preferences", SLOT( prefsDialog() ), "Ctrl+P" );
384
385     return menu;
386 }
387
388 QMenu *QVLCMenu::ToolsMenu( QWidget *parent )
389 {
390     return ToolsMenu( new QMenu( parent ) );
391 }
392
393 /**
394  * View Menu
395  * This menu can be an interface menu but also a right click menu.
396  **/
397 QMenu *QVLCMenu::ViewMenu( intf_thread_t *p_intf,
398                             QMenu *current,
399                             MainInterface *mi,
400                             bool visual_selector_enabled,
401                             bool with_intf )
402 {
403     QMenu *menu;
404     if( current )
405         menu = new QMenu( current );
406     else
407         menu = new QMenu( mi );
408     QAction *act;
409     if( mi )
410     {
411         act = menu->addAction( QIcon( ":/playlist_menu" ),
412                                qtr( "Play&list" ), mi,
413                                SLOT( togglePlaylist() ), qtr( "Ctrl+L" ) );
414         act->setData( true );
415     }
416     /*menu->addSeparator();
417     menu->addAction( qtr( "Undock from Interface" ), mi,
418                      SLOT( undockPlaylist() ), qtr( "Ctrl+U" ) );*/
419
420
421     menu->addSeparator();
422
423     if( with_intf )
424     {
425         QMenu *intfmenu = InterfacesMenu( p_intf, menu );
426         MenuFunc *f = new MenuFunc( intfmenu, 4 );
427         CONNECT( intfmenu, aboutToShow(), THEDP->menusUpdateMapper, map() );
428         THEDP->menusUpdateMapper->setMapping( intfmenu, f );
429         menu->addSeparator();
430     }
431     if( mi )
432     {
433         /* Minimal View */
434         QAction *action = menu->addAction( qtr( "Mi&nimal View" ), mi,
435                                 SLOT( toggleMinimalView() ), qtr( "Ctrl+H" ) );
436         action->setCheckable( true );
437         action->setData( true );
438         if( mi->getControlsVisibilityStatus() & CONTROLS_VISIBLE )
439             action->setChecked( true );
440         minimalViewAction = action; /* HACK for minimalView */
441
442         /* FullScreen View */
443         action = menu->addAction( qtr( "&Fullscreen Interface" ), mi,
444                                   SLOT( toggleFullScreen() ), QString( "F11" ) );
445         fullscreenViewAction = action;
446         action->setCheckable( true );
447         action->setData( true );
448
449         /* Advanced Controls */
450         action = menu->addAction( qtr( "&Advanced Controls" ), mi,
451                                   SLOT( toggleAdvanced() ) );
452         action->setCheckable( true );
453         action->setData( true );
454         if( mi->getControlsVisibilityStatus() & CONTROLS_ADVANCED )
455             action->setChecked( true );
456 #if 0 /* For Visualisations. Not yet working */
457         adv = menu->addAction( qtr( "Visualizations selector" ),
458                 mi, SLOT( visual() ) );
459         adv->setCheckable( true );
460         if( visual_selector_enabled ) adv->setChecked( true );
461 #endif
462     }
463
464     menu->addSeparator();
465     addDPStaticEntry( menu, qtr( "Customi&ze Interface..." ),
466         ":/preferences", SLOT( toolbarDialog() ) );
467     menu->addSeparator();
468
469     return menu;
470 }
471
472 /**
473  * Interface Sub-Menu, to list extras interface and skins
474  **/
475 QMenu *QVLCMenu::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
476 {
477     vector<vlc_object_t *> objects;
478     vector<const char *> varnames;
479     /** \todo add "switch to XXX" */
480     varnames.push_back( "intf-add" );
481     objects.push_back( VLC_OBJECT(p_intf) );
482
483     return Populate( p_intf, current, varnames, objects );
484 }
485
486 /**
487  * Main Audio Menu
488  */
489 QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QMenu * current )
490 {
491     vector<vlc_object_t *> objects;
492     vector<const char *> varnames;
493     aout_instance_t *p_aout;
494     input_thread_t *p_input;
495
496     if( current->isEmpty() )
497     {
498         ACT_ADD( current, "audio-es", qtr( "Audio &Track" ) );
499         ACT_ADD( current, "audio-channels", qtr( "Audio &Channels" ) );
500         ACT_ADD( current, "audio-device", qtr( "Audio &Device" ) );
501         current->addSeparator();
502
503         ACT_ADD( current, "visual", qtr( "&Visualizations" ) );
504         current->addSeparator();
505
506         QAction *action = current->addAction( qtr( "Increase Volume" ),
507                 ActionsManager::getInstance( p_intf ), SLOT( AudioUp() ) );
508         action->setData( true );
509         action = current->addAction( qtr( "Decrease Volume" ),
510                 ActionsManager::getInstance( p_intf ), SLOT( AudioDown() ) );
511         action->setData( true );
512         action = current->addAction( qtr( "Mute" ),
513                 ActionsManager::getInstance( p_intf ), SLOT( toggleMuteAudio() ) );
514         action->setData( true );
515     }
516
517     p_input = THEMIM->getInput();
518     if( p_input )
519         vlc_object_hold( p_input );
520     p_aout = THEMIM->getAout();
521     AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
522     EnableStaticEntries( current, ( p_aout != NULL ) );
523     if( p_aout )
524     {
525         vlc_object_release( p_aout );
526     }
527     if( p_input )
528         vlc_object_release( p_input );
529
530     return Populate( p_intf, current, varnames, objects );
531 }
532
533 QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QWidget *parent )
534 {
535     return AudioMenu( p_intf, new QMenu( parent ) );
536 }
537
538 /**
539  * Main Video Menu
540  * Subtitles are part of Video.
541  **/
542 QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current )
543 {
544     vout_thread_t *p_vout;
545     input_thread_t *p_input;
546     vector<vlc_object_t *> objects;
547     vector<const char *> varnames;
548
549     if( current->isEmpty() )
550     {
551         ACT_ADD( current, "video-es", qtr( "Video &Track" ) );
552
553         QAction *action;
554         QMenu *submenu = new QMenu( qtr( "&Subtitles Track" ), current );
555         action = current->addMenu( submenu );
556         action->setData( "spu-es" );
557         addDPStaticEntry( submenu, qtr( "Open File..." ), "",
558                           SLOT( loadSubtitlesFile() ) );
559         submenu->addSeparator();
560         current->addSeparator();
561
562         ACT_ADD( current, "fullscreen", qtr( "&Fullscreen" ) );
563         ACT_ADD( current, "video-on-top", qtr( "Always &On Top" ) );
564 #ifdef WIN32
565         ACT_ADD( current, "directx-wallpaper", qtr( "DirectX Wallpaper" ) );
566 #endif
567         ACT_ADD( current, "video-snapshot", qtr( "Sna&pshot" ) );
568
569         current->addSeparator();
570
571         ACT_ADD( current, "zoom", qtr( "&Zoom" ) );
572         ACT_ADD( current, "scale", qtr( "Sca&le" ) );
573         ACT_ADD( current, "aspect-ratio", qtr( "&Aspect Ratio" ) );
574         ACT_ADD( current, "crop", qtr( "&Crop" ) );
575         ACT_ADD( current, "deinterlace", qtr( "&Deinterlace" ) );
576         ACT_ADD( current, "postproc-q", qtr( "&Post processing" ) );
577     }
578
579     p_input = THEMIM->getInput();
580     if( p_input )
581         vlc_object_hold( p_input );
582
583     p_vout = THEMIM->getVout();
584     VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
585     EnableStaticEntries( current, ( p_vout != NULL ) );
586     if( p_vout )
587     {
588         vlc_object_release( p_vout );
589     }
590     if( p_input )
591         vlc_object_release( p_input );
592
593     return Populate( p_intf, current, varnames, objects );
594 }
595
596 QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QWidget *parent )
597 {
598     return VideoMenu( p_intf, new QMenu( parent ) );
599 }
600
601 /**
602  * Navigation Menu
603  * For DVD, MP4, MOV and other chapter based format
604  **/
605 QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *menu )
606 {
607     if( menu->isEmpty() )
608     {
609         ACT_ADD( menu, "bookmark", qtr( "&Bookmarks" ) );
610         ACT_ADD( menu, "title", qtr( "T&itle" ) );
611         ACT_ADD( menu, "chapter", qtr( "&Chapter" ) );
612         ACT_ADD( menu, "navigation", qtr( "&Navigation" ) );
613         ACT_ADD( menu, "program", qtr( "&Program" ) );
614
615         menu->addSeparator();
616         addDPStaticEntry( menu, qtr( I_MENU_GOTOTIME ),"",
617                           SLOT( gotoTimeDialog() ), "Ctrl+T" );
618
619     }
620
621     input_thread_t *p_object;
622     vector<vlc_object_t *> objects;
623     vector<const char *> varnames;
624
625     p_object = THEMIM->getInput();
626     if( p_object )
627         vlc_object_hold( p_object );
628     InputAutoMenuBuilder( p_object, objects, varnames );
629     PUSH_VAR( "prev-title" );
630     PUSH_VAR( "next-title" );
631     PUSH_VAR( "prev-chapter" );
632     PUSH_VAR( "next-chapter" );
633     EnableStaticEntries( menu, ( p_object != NULL ) );
634     if( p_object )
635     {
636         vlc_object_release( p_object );
637     }
638     return Populate( p_intf, menu, varnames, objects );
639 }
640
641 QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QWidget *parent )
642 {
643     return NavigMenu( p_intf, new QMenu( parent ) );
644 }
645
646 /**
647  * Service Discovery SubMenu
648  **/
649 QMenu *QVLCMenu::SDMenu( intf_thread_t *p_intf, QWidget *parent )
650 {
651     QMenu *menu = new QMenu( parent );
652     menu->setTitle( qtr( I_PL_SD ) );
653     char **ppsz_longnames;
654     char **ppsz_names = vlc_sd_GetNames( &ppsz_longnames );
655     if( !ppsz_names )
656         return menu;
657
658     char **ppsz_name = ppsz_names, **ppsz_longname = ppsz_longnames;
659     for( ; *ppsz_name; ppsz_name++, ppsz_longname++ )
660     {
661         QAction *a = new QAction( qfu( *ppsz_longname ), menu );
662         a->setCheckable( true );
663         if( playlist_IsServicesDiscoveryLoaded( THEPL, *ppsz_name ) )
664             a->setChecked( true );
665         CONNECT( a , triggered(), THEDP->SDMapper, map() );
666         THEDP->SDMapper->setMapping( a, QString( *ppsz_name ) );
667         menu->addAction( a );
668
669         if( !strcmp( *ppsz_name, "podcast" ) )
670         {
671             QAction *b = new QAction( qtr( "Configure podcasts..." ), menu );
672             //b->setEnabled( a->isChecked() );
673             menu->addAction( b );
674             CONNECT( b, triggered(), THEDP, podcastConfigureDialog() );
675         }
676         free( *ppsz_name );
677         free( *ppsz_longname );
678     }
679     free( ppsz_names );
680     free( ppsz_longnames );
681     return menu;
682 }
683
684 /**
685  * Help/About Menu
686 **/
687 QMenu *QVLCMenu::HelpMenu( QWidget *parent )
688 {
689     QMenu *menu = new QMenu( parent );
690     addDPStaticEntry( menu, qtr( "&Help..." ) ,
691         ":/help", SLOT( helpDialog() ), "F1" );
692 #ifdef UPDATE_CHECK
693     addDPStaticEntry( menu, qtr( "Check for &Updates..." ) , "",
694                       SLOT( updateDialog() ) );
695 #endif
696     menu->addSeparator();
697     addDPStaticEntry( menu, qtr( I_MENU_ABOUT ), ":/info",
698             SLOT( aboutDialog() ), "Shift+F1" );
699     return menu;
700 }
701
702 /*****************************************************************************
703  * Popup menus - Right Click menus                                           *
704  *****************************************************************************/
705 #define POPUP_BOILERPLATE \
706     unsigned int i_last_separator = 0; \
707     vector<vlc_object_t *> objects; \
708     vector<const char *> varnames; \
709     input_thread_t *p_input = THEMIM->getInput();
710
711 #define CREATE_POPUP \
712     Populate( p_intf, menu, varnames, objects ); \
713     p_intf->p_sys->p_popup_menu = menu; \
714     menu->popup( QCursor::pos() ); \
715     p_intf->p_sys->p_popup_menu = NULL; \
716     i_last_separator = 0;
717
718 void QVLCMenu::PopupMenuControlEntries( QMenu *menu,
719                                         intf_thread_t *p_intf,
720                                         input_thread_t *p_input )
721 {
722     if( p_input )
723     {
724         vlc_value_t val;
725         var_Get( p_input, "state", &val );
726         if( val.i_int == PLAYING_S )
727             addMIMStaticEntry( p_intf, menu, qtr( "Pause" ),
728                     ":/pause", SLOT( togglePlayPause() ) );
729         else
730             addMIMStaticEntry( p_intf, menu, qtr( "Play" ),
731                     ":/play", SLOT( togglePlayPause() ) );
732     }
733     else if( THEPL->items.i_size )
734         addMIMStaticEntry( p_intf, menu, qtr( "Play" ),
735                 ":/play", SLOT( togglePlayPause() ) );
736     else
737         addDPStaticEntry( menu, qtr( "Play" ),
738                 ":/play", SLOT( openDialog() ) );
739
740     addMIMStaticEntry( p_intf, menu, qtr( "Stop" ),
741             ":/stop", SLOT( stop() ) );
742     addMIMStaticEntry( p_intf, menu, qtr( "Previous" ),
743             ":/previous", SLOT( prev() ) );
744     addMIMStaticEntry( p_intf, menu, qtr( "Next" ),
745             ":/next", SLOT( next() ) );
746 }
747
748 void QVLCMenu::PopupMenuStaticEntries( QMenu *menu )
749 {
750     QMenu *openmenu = new QMenu( qtr( "Open Media" ), menu );
751     addDPStaticEntry( openmenu, qtr( "&Open File..." ),
752         ":/file-asym", SLOT( openFileDialog() ) );
753     addDPStaticEntry( openmenu, qtr( I_OPEN_FOLDER ),
754         ":/folder-grey", SLOT( PLOpenDir() ) );
755     addDPStaticEntry( openmenu, qtr( "Open &Disc..." ),
756         ":/disc", SLOT( openDiscDialog() ) );
757     addDPStaticEntry( openmenu, qtr( "Open &Network..." ),
758         ":/network", SLOT( openNetDialog() ) );
759     addDPStaticEntry( openmenu, qtr( "Open &Capture Device..." ),
760         ":/capture-card", SLOT( openCaptureDialog() ) );
761     menu->addMenu( openmenu );
762
763     menu->addSeparator();
764 #if 0
765     QMenu *helpmenu = HelpMenu( menu );
766     helpmenu->setTitle( qtr( "Help" ) );
767     menu->addMenu( helpmenu );
768 #endif
769
770     addDPStaticEntry( menu, qtr( "Quit" ), ":/quit",
771                       SLOT( quit() ), "Ctrl+Q" );
772 }
773
774 /* Video Tracks and Subtitles tracks */
775 void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf )
776 {
777     POPUP_BOILERPLATE;
778     if( p_input )
779     {
780         vlc_object_hold( p_input );
781         vout_thread_t *p_vout = THEMIM->getVout();
782         if( p_vout )
783         {
784             VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
785             vlc_object_release( p_vout );
786         }
787         vlc_object_release( p_input );
788     }
789     QMenu *menu = new QMenu();
790     CREATE_POPUP;
791 }
792
793 /* Audio Tracks */
794 void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf )
795 {
796     POPUP_BOILERPLATE;
797     if( p_input )
798     {
799         vlc_object_hold( p_input );
800         aout_instance_t *p_aout = THEMIM->getAout();
801         AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
802         if( p_aout )
803             vlc_object_release( p_aout );
804         vlc_object_release( p_input );
805     }
806     QMenu *menu = new QMenu();
807     CREATE_POPUP;
808 }
809
810 /* Navigation stuff, and general menus ( open ) */
811 void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf )
812 {
813     POPUP_BOILERPLATE;
814
815     if( p_input )
816     {
817         vlc_object_hold( p_input );
818         varnames.push_back( "audio-es" );
819         InputAutoMenuBuilder( p_input, objects, varnames );
820         PUSH_SEPARATOR;
821     }
822
823     QMenu *menu = new QMenu();
824     Populate( p_intf, menu, varnames, objects );
825
826     menu->addSeparator();
827     PopupMenuControlEntries( menu, p_intf, p_input );
828
829     menu->addSeparator();
830     PopupMenuStaticEntries( menu );
831
832     p_intf->p_sys->p_popup_menu = menu;
833     menu->popup( QCursor::pos() );
834     p_intf->p_sys->p_popup_menu = NULL;
835 }
836
837 /* Main Menu that sticks everything together  */
838 void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show )
839 {
840     MainInterface *mi = p_intf->p_sys->p_mi;
841     if( show )
842     {
843         /* Delete and recreate a popup if there is one */
844         if( p_intf->p_sys->p_popup_menu )
845             delete p_intf->p_sys->p_popup_menu;
846
847         QMenu *menu = new QMenu();
848         QMenu *submenu;
849         QAction *action;
850         bool b_isFullscreen = false;
851
852         POPUP_BOILERPLATE;
853
854         PopupMenuControlEntries( menu, p_intf, p_input );
855         menu->addSeparator();
856
857         if( p_input )
858         {
859             vout_thread_t *p_vout = THEMIM->getVout();
860
861             /* Add a fullscreen switch button */
862             if( p_vout )
863             {
864                 vlc_value_t val;
865                 var_Get( p_vout, "fullscreen", &val );
866                 b_isFullscreen = !( !val.b_bool );
867                 if( b_isFullscreen )
868                     CreateAndConnect( menu, "fullscreen",
869                             qtr( "Leave Fullscreen" ),"" , ITEM_NORMAL,
870                             VLC_OBJECT(p_vout), val, VLC_VAR_BOOL,
871                             b_isFullscreen );
872                 vlc_object_release( p_vout );
873             }
874
875             menu->addSeparator();
876
877             /* Input menu */
878             vlc_object_hold( p_input );
879             InputAutoMenuBuilder( p_input, objects, varnames );
880             vlc_object_release( p_input );
881
882             /* Audio menu */
883             submenu = new QMenu( menu );
884             action = menu->addMenu( AudioMenu( p_intf, submenu ) );
885             action->setText( qtr( "&Audio" ) );
886             if( action->menu()->isEmpty() )
887                 action->setEnabled( false );
888
889             /* Video menu */
890             submenu = new QMenu( menu );
891             action = menu->addMenu( VideoMenu( p_intf, submenu ) );
892             action->setText( qtr( "&Video" ) );
893             if( action->menu()->isEmpty() )
894                 action->setEnabled( false );
895
896             /* Playback menu for chapters */
897             submenu = new QMenu( menu );
898             action = menu->addMenu( NavigMenu( p_intf, submenu ) );
899             action->setText( qtr( "&Playback" ) );
900             if( action->menu()->isEmpty() )
901                 action->setEnabled( false );
902         }
903
904         menu->addSeparator();
905
906         /* Add some special entries for windowed mode: Interface Menu */
907         if( !b_isFullscreen )
908         {
909             submenu = new QMenu( qtr( "Interface" ), menu );
910             if( mi )
911             {
912                 submenu->addAction( QIcon( ":/playlist" ),
913                          qtr( "Show Playlist" ), mi, SLOT( togglePlaylist() ) );
914                 action = submenu->addAction( QIcon( "" ),
915                      qtr( "Minimal View" ), mi, SLOT( toggleMinimalView() ) );
916                 action->setCheckable( true );
917                 action->setChecked( !( mi->getControlsVisibilityStatus() &
918                             CONTROLS_VISIBLE ) );
919                 action = submenu->addAction( QIcon( "" ),
920                         qtr( "Fullscreen Interface" ),
921                         mi, SLOT( toggleFullScreen() ) );
922                 action->setCheckable( true );
923                 action->setChecked( mi->isFullScreen() );
924             }
925             else /* We are using the skins interface.
926                     If not, this entry will not show. */
927             {
928
929                 QMenu *tools = ToolsMenu( submenu );
930                 submenu->addSeparator();
931                 objects.clear();
932                 varnames.clear();
933                 vlc_object_t *p_object = ( vlc_object_t* )
934                      vlc_object_find_name( p_intf, "skins2", FIND_PARENT );
935                 if( p_object )
936                 {
937                     objects.push_back( p_object );
938                     varnames.push_back( "intf-skins" );
939                     Populate( p_intf, submenu, varnames, objects );
940                     vlc_object_release( p_object );
941                 }
942                 else
943                     msg_Dbg( p_intf, "could not find parent interface" );
944             }
945             menu->addMenu( submenu );
946         }
947
948         /* Static entries for ending, like open */
949         PopupMenuStaticEntries( menu );
950
951         p_intf->p_sys->p_popup_menu = menu;
952         p_intf->p_sys->p_popup_menu->popup( QCursor::pos() );
953     }
954     else
955     {
956         // destroy popup if there is one
957         delete p_intf->p_sys->p_popup_menu;
958         p_intf->p_sys->p_popup_menu = NULL;
959     }
960 }
961
962 #undef ACT_ADD
963
964 /************************************************************************
965  * Systray Menu                                                         *
966  ************************************************************************/
967
968 void QVLCMenu::updateSystrayMenu( MainInterface *mi,
969                                   intf_thread_t *p_intf,
970                                   bool b_force_visible )
971 {
972     POPUP_BOILERPLATE;
973
974     /* Get the systray menu and clean it */
975     QMenu *sysMenu = mi->getSysTrayMenu();
976     sysMenu->clear();
977
978     /* Hide / Show VLC and cone */
979     if( mi->isVisible() || b_force_visible )
980     {
981         sysMenu->addAction( QIcon( ":/vlc16.png" ),
982                             qtr( "Hide VLC media player in taskbar" ), mi,
983                             SLOT( toggleUpdateSystrayMenu() ) );
984     }
985     else
986     {
987         sysMenu->addAction( QIcon( ":/vlc16.png" ),
988                             qtr( "Show VLC media player" ), mi,
989                             SLOT( toggleUpdateSystrayMenu() ) );
990     }
991
992     sysMenu->addSeparator();
993     PopupMenuControlEntries( sysMenu, p_intf, p_input );
994
995     sysMenu->addSeparator();
996     addDPStaticEntry( sysMenu, qtr( "&Open Media" ),
997             ":/file-wide", SLOT( openFileDialog() ) );
998     addDPStaticEntry( sysMenu, qtr( "&Quit" ) ,
999             ":/quit", SLOT( quit() ) );
1000
1001     /* Set the menu */
1002     mi->getSysTray()->setContextMenu( sysMenu );
1003 }
1004
1005 #undef PUSH_VAR
1006 #undef PUSH_SEPARATOR
1007
1008 /*************************************************************************
1009  * Builders for automenus
1010  *************************************************************************/
1011 QMenu * QVLCMenu::Populate( intf_thread_t *p_intf,
1012                             QMenu *current,
1013                             vector< const char *> & varnames,
1014                             vector<vlc_object_t *> & objects )
1015 {
1016     QMenu *menu = current;
1017     if( !menu )
1018     {
1019         msg_Warn( p_intf,  "%s leaking a menu", __func__ );
1020         menu = new QMenu();
1021     }
1022
1023     currentGroup = NULL;
1024
1025     vlc_object_t *p_object;
1026
1027     for( int i = 0; i < ( int )objects.size() ; i++ )
1028     {
1029         if( !varnames[i] || !*varnames[i] )
1030         {
1031             menu->addSeparator();
1032             continue;
1033         }
1034         p_object = objects[i];
1035
1036         UpdateItem( p_intf, menu, varnames[i], p_object, true );
1037     }
1038     return menu;
1039 }
1040
1041 /*****************************************************************************
1042  * Private methods.
1043  *****************************************************************************/
1044
1045 static bool IsMenuEmpty( const char *psz_var,
1046                          vlc_object_t *p_object,
1047                          bool b_root = true )
1048 {
1049     vlc_value_t val, val_list;
1050     int i_type, i_result, i;
1051
1052     /* Check the type of the object variable */
1053     i_type = var_Type( p_object, psz_var );
1054
1055     /* Check if we want to display the variable */
1056     if( !( i_type & VLC_VAR_HASCHOICE ) ) return false;
1057
1058     var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
1059     if( val.i_int == 0 ) return true;
1060
1061     if( ( i_type & VLC_VAR_TYPE ) != VLC_VAR_VARIABLE )
1062     {
1063         if( val.i_int == 1 && b_root ) return true;
1064         else return false;
1065     }
1066
1067     /* Check children variables in case of VLC_VAR_VARIABLE */
1068     if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
1069     {
1070         return true;
1071     }
1072
1073     for( i = 0, i_result = true; i < val_list.p_list->i_count; i++ )
1074     {
1075         if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
1076                     p_object, false ) )
1077         {
1078             i_result = false;
1079             break;
1080         }
1081     }
1082
1083     /* clean up everything */
1084     var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, NULL );
1085
1086     return i_result;
1087 }
1088
1089 #define TEXT_OR_VAR qfu ( text.psz_string ? text.psz_string : psz_var )
1090
1091 void QVLCMenu::UpdateItem( intf_thread_t *p_intf, QMenu *menu,
1092         const char *psz_var, vlc_object_t *p_object, bool b_submenu )
1093 {
1094     vlc_value_t val, text;
1095     int i_type;
1096
1097     QAction *action = FindActionWithVar( menu, psz_var );
1098     if( action )
1099         DeleteNonStaticEntries( action->menu() );
1100
1101     if( !p_object )
1102     {
1103         if( action )
1104             action->setEnabled( false );
1105         return;
1106     }
1107
1108     /* Check the type of the object variable */
1109     /* What is the following HACK needed for? */
1110     if( !strcmp( psz_var, "audio-es" )
1111      || !strcmp( psz_var, "video-es" )
1112      || !strcmp( psz_var, "postproc-q" ) )
1113         i_type = VLC_VAR_INTEGER | VLC_VAR_HASCHOICE;
1114     else
1115         i_type = var_Type( p_object, psz_var );
1116
1117     switch( i_type & VLC_VAR_TYPE )
1118     {
1119         case VLC_VAR_VOID:
1120         case VLC_VAR_BOOL:
1121         case VLC_VAR_VARIABLE:
1122         case VLC_VAR_STRING:
1123         case VLC_VAR_INTEGER:
1124         case VLC_VAR_FLOAT:
1125             break;
1126         default:
1127             /* Variable doesn't exist or isn't handled */
1128             if( action )
1129                 action->setEnabled( false );
1130             return;
1131     }
1132
1133     /* Make sure we want to display the variable */
1134     if( menu->isEmpty() && IsMenuEmpty( psz_var, p_object ) )
1135     {
1136         if( action )
1137             action->setEnabled( false );
1138         return;
1139     }
1140
1141     /* Get the descriptive name of the variable */
1142     int i_ret = var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
1143     if( i_ret != VLC_SUCCESS )
1144     {
1145         text.psz_string = NULL;
1146     }
1147
1148     if( !action )
1149     {
1150         action = new QAction( TEXT_OR_VAR, menu );
1151         menu->addAction( action );
1152         action->setData( psz_var );
1153     }
1154
1155     /* Some specific stuff */
1156     bool forceDisabled = false;
1157     if( !strcmp( psz_var, "spu-es" ) )
1158     {
1159         vout_thread_t *p_vout = THEMIM->getVout();
1160         forceDisabled = ( p_vout == NULL );
1161         if( p_vout )
1162             vlc_object_release( p_vout );
1163     }
1164
1165     if( i_type & VLC_VAR_HASCHOICE )
1166     {
1167         /* Append choices menu */
1168         if( b_submenu )
1169         {
1170             QMenu *submenu;
1171             submenu = action->menu();
1172             if( !submenu )
1173             {
1174                 submenu = new QMenu( menu );
1175                 action->setMenu( submenu );
1176             }
1177
1178             action->setEnabled(
1179                CreateChoicesMenu( submenu, psz_var, p_object, true ) == 0 );
1180             if( forceDisabled )
1181                 action->setEnabled( false );
1182         }
1183         else
1184             action->setEnabled(
1185                 CreateChoicesMenu( menu, psz_var, p_object, true ) == 0 );
1186         FREENULL( text.psz_string );
1187         return;
1188     }
1189
1190     switch( i_type & VLC_VAR_TYPE )
1191     {
1192         case VLC_VAR_VOID:
1193             var_Get( p_object, psz_var, &val );
1194             CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_NORMAL,
1195                     p_object, val, i_type );
1196             break;
1197
1198         case VLC_VAR_BOOL:
1199             var_Get( p_object, psz_var, &val );
1200             val.b_bool = !val.b_bool;
1201             CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_CHECK,
1202                     p_object, val, i_type, !val.b_bool );
1203             break;
1204     }
1205     FREENULL( text.psz_string );
1206 }
1207
1208
1209 int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
1210         vlc_object_t *p_object, bool b_root )
1211 {
1212     vlc_value_t val, val_list, text_list;
1213     int i_type, i;
1214
1215     /* Check the type of the object variable */
1216     i_type = var_Type( p_object, psz_var );
1217
1218     /* Make sure we want to display the variable */
1219     if( submenu->isEmpty() && IsMenuEmpty( psz_var, p_object, b_root ) )
1220         return VLC_EGENERIC;
1221
1222     switch( i_type & VLC_VAR_TYPE )
1223     {
1224         case VLC_VAR_VOID:
1225         case VLC_VAR_BOOL:
1226         case VLC_VAR_VARIABLE:
1227         case VLC_VAR_STRING:
1228         case VLC_VAR_INTEGER:
1229         case VLC_VAR_FLOAT:
1230             break;
1231         default:
1232             /* Variable doesn't exist or isn't handled */
1233             return VLC_EGENERIC;
1234     }
1235
1236     if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
1237                     &val_list, &text_list ) < 0 )
1238     {
1239         return VLC_EGENERIC;
1240     }
1241
1242 #define CURVAL val_list.p_list->p_values[i]
1243 #define CURTEXT text_list.p_list->p_values[i].psz_string
1244
1245     for( i = 0; i < val_list.p_list->i_count; i++ )
1246     {
1247         vlc_value_t another_val;
1248         QString menutext;
1249         QMenu *subsubmenu = new QMenu( submenu );
1250
1251         switch( i_type & VLC_VAR_TYPE )
1252         {
1253             case VLC_VAR_VARIABLE:
1254                 CreateChoicesMenu( subsubmenu, CURVAL.psz_string, p_object, false );
1255                 subsubmenu->setTitle( qfu( CURTEXT ? CURTEXT :CURVAL.psz_string ) );
1256                 submenu->addMenu( subsubmenu );
1257                 break;
1258
1259             case VLC_VAR_STRING:
1260                 var_Get( p_object, psz_var, &val );
1261                 another_val.psz_string = strdup( CURVAL.psz_string );
1262                 menutext = qfu( CURTEXT ? CURTEXT : another_val.psz_string );
1263                 CreateAndConnect( submenu, psz_var, menutext, "", ITEM_RADIO,
1264                         p_object, another_val, i_type,
1265                         val.psz_string && !strcmp( val.psz_string, CURVAL.psz_string ) );
1266
1267                 free( val.psz_string );
1268                 break;
1269
1270             case VLC_VAR_INTEGER:
1271                 var_Get( p_object, psz_var, &val );
1272                 if( CURTEXT ) menutext = qfu( CURTEXT );
1273                 else menutext.sprintf( "%d", CURVAL.i_int );
1274                 CreateAndConnect( submenu, psz_var, menutext, "", ITEM_RADIO,
1275                         p_object, CURVAL, i_type,
1276                         CURVAL.i_int == val.i_int );
1277                 break;
1278
1279             case VLC_VAR_FLOAT:
1280                 var_Get( p_object, psz_var, &val );
1281                 if( CURTEXT ) menutext = qfu( CURTEXT );
1282                 else menutext.sprintf( "%.2f", CURVAL.f_float );
1283                 CreateAndConnect( submenu, psz_var, menutext, "", ITEM_RADIO,
1284                         p_object, CURVAL, i_type,
1285                         CURVAL.f_float == val.f_float );
1286                 break;
1287
1288             default:
1289                 break;
1290         }
1291     }
1292     currentGroup = NULL;
1293
1294     /* clean up everything */
1295     var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
1296
1297 #undef CURVAL
1298 #undef CURTEXT
1299     return submenu->isEmpty() ? VLC_EGENERIC : VLC_SUCCESS;
1300 }
1301
1302 void QVLCMenu::CreateAndConnect( QMenu *menu, const char *psz_var,
1303         QString text, QString help,
1304         int i_item_type, vlc_object_t *p_obj,
1305         vlc_value_t val, int i_val_type,
1306         bool checked )
1307 {
1308     QAction *action = FindActionWithVar( menu, psz_var );
1309     if( !action )
1310     {
1311         action = new QAction( text, menu );
1312         menu->addAction( action );
1313     }
1314
1315     action->setToolTip( help );
1316     action->setEnabled( p_obj != NULL );
1317
1318     if( i_item_type == ITEM_CHECK )
1319     {
1320         action->setCheckable( true );
1321     }
1322     else if( i_item_type == ITEM_RADIO )
1323     {
1324         action->setCheckable( true );
1325         if( !currentGroup )
1326             currentGroup = new QActionGroup( menu );
1327         currentGroup->addAction( action );
1328     }
1329
1330     action->setChecked( checked );
1331
1332     MenuItemData *itemData = new MenuItemData( THEDP->menusMapper, p_obj, i_val_type,
1333             val, psz_var );
1334     CONNECT( action, triggered(), THEDP->menusMapper, map() );
1335     THEDP->menusMapper->setMapping( action, itemData );
1336     menu->addAction( action );
1337 }
1338
1339 void QVLCMenu::DoAction( QObject *data )
1340 {
1341     MenuItemData *itemData = qobject_cast<MenuItemData *>( data );
1342     vlc_object_t *p_object = itemData->p_obj;
1343     if( p_object == NULL ) return;
1344
1345     var_Set( p_object, itemData->psz_var, itemData->val );
1346 }
1347
1348 void QVLCMenu::updateRecents( intf_thread_t *p_intf )
1349 {
1350     if (recentsMenu)
1351     {
1352         QAction* action;
1353         RecentsMRL* rmrl = RecentsMRL::getInstance( p_intf );
1354         QList<QString> l = rmrl->recents();
1355
1356         recentsMenu->clear();
1357         if( !l.size() )
1358         {
1359             action = recentsMenu->addAction( qtr(" - Empty - ") );
1360             action->setEnabled( false );
1361         }
1362         else
1363         {
1364             for( int i = 0; i < l.size(); ++i )
1365             {
1366                 action = recentsMenu->addAction(
1367                         QString( "&%1: " ).arg( i + 1 ) + l.at( i ),
1368                         rmrl->signalMapper,
1369                         SLOT( map() ) );
1370                 rmrl->signalMapper->setMapping( action, l.at( i ) );
1371             }
1372
1373             recentsMenu->addSeparator();
1374             recentsMenu->addAction( qtr("&Clear"), rmrl, SLOT( clear() ) );
1375         }
1376     }
1377 }