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