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