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