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