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