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