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