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