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