]> git.sesse.net Git - vlc/blob - modules/gui/qt4/menus.cpp
Merge branch 1.0-bugfix into master
[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 #ifdef ENABLE_SOUT
338     addDPStaticEntry( menu, qtr( "Conve&rt / Save..." ), "",
339         SLOT( openAndTranscodingDialogs() ), "Ctrl+R" );
340     addDPStaticEntry( menu, qtr( "&Streaming..." ),
341         ":/stream", SLOT( openAndStreamingDialogs() ),
342         "Ctrl+S" );
343     menu->addSeparator();
344 #endif
345
346     addDPStaticEntry( menu, qtr( "&Quit" ) ,
347         ":/quit", SLOT( quit() ), "Ctrl+Q" );
348     return menu;
349 }
350
351 /**
352  * Tools, like Media Information, Preferences or Messages
353  **/
354 QMenu *QVLCMenu::ToolsMenu( QMenu *menu )
355 {
356     addDPStaticEntry( menu, qtr( "&Effects and Filters"), ":/settings",
357             SLOT( extendedDialog() ), "Ctrl+E" );
358
359     addDPStaticEntry( menu, qtr( "&Track Synchronization"), ":/settings",
360             SLOT( synchroDialog() ), "" );
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  * Interface Modification
396  **/
397 QMenu *QVLCMenu::ViewMenu( intf_thread_t *p_intf,
398                             MainInterface *mi,
399                             bool with_intf )
400 {
401     assert( mi );
402
403     QMenu *menu = new QMenu( qtr( "V&iew" ), mi );
404
405     QAction *act = menu->addAction( QIcon( ":/playlist_menu" ),
406             qtr( "Play&list" ), mi,
407             SLOT( togglePlaylist() ), qtr( "Ctrl+L" ) );
408
409     /*menu->addSeparator();
410     menu->addAction( qtr( "Undock from Interface" ), mi,
411                      SLOT( undockPlaylist() ), qtr( "Ctrl+U" ) );*/
412
413     menu->addSeparator();
414
415     if( with_intf )
416     {
417         QMenu *intfmenu = InterfacesMenu( p_intf, menu );
418         MenuFunc *f = new MenuFunc( intfmenu, 4 );
419         CONNECT( intfmenu, aboutToShow(), THEDP->menusUpdateMapper, map() );
420         THEDP->menusUpdateMapper->setMapping( intfmenu, f );
421         menu->addSeparator();
422     }
423
424     /* Minimal View */
425     QAction *action = menu->addAction( qtr( "Mi&nimal View" ) );
426     action->setShortcut( qtr( "Ctrl+H" ) );
427     action->setCheckable( true );
428     action->setChecked( !with_intf &&
429             (mi->getControlsVisibilityStatus() & CONTROLS_HIDDEN ) );
430
431     CONNECT( action, triggered( bool ), mi, toggleMinimalView( bool ) );
432     CONNECT( mi, minimalViewToggled( bool ), action, setChecked( bool ) );
433
434     /* FullScreen View */
435     action = menu->addAction( qtr( "&Fullscreen Interface" ), mi,
436             SLOT( toggleFullScreen() ), QString( "F11" ) );
437     action->setCheckable( true );
438     action->setChecked( mi->isFullScreen() );
439     CONNECT( mi, fullscreenInterfaceToggled( bool ),
440              action, setChecked( bool ) );
441
442     /* Advanced Controls */
443     action = menu->addAction( qtr( "&Advanced Controls" ), mi,
444             SLOT( toggleAdvanced() ) );
445     action->setCheckable( true );
446     if( mi->getControlsVisibilityStatus() & CONTROLS_ADVANCED )
447         action->setChecked( true );
448
449     if( with_intf )
450     // I don't want to manage consistency between menus, so no popup-menu
451     {
452         action = menu->addAction( qtr( "Quit after Playback" ) );
453         action->setCheckable( true );
454         CONNECT( action, triggered( bool ), THEMIM, activatePlayQuit( bool ) );
455     }
456
457 #if 0 /* For Visualisations. Not yet working */
458     adv = menu->addAction( qtr( "Visualizations selector" ),
459             mi, SLOT( visual() ) );
460     adv->setCheckable( true );
461     if( visual_selector_enabled ) adv->setChecked( true );
462 #endif
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     varnames.push_back( "intf-add" );
480     objects.push_back( VLC_OBJECT(p_intf) );
481
482     return Populate( p_intf, current, varnames, objects );
483 }
484
485 /**
486  * Main Audio Menu
487  **/
488 QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QMenu * current )
489 {
490     vector<vlc_object_t *> objects;
491     vector<const char *> varnames;
492     aout_instance_t *p_aout;
493     input_thread_t *p_input;
494
495     if( current->isEmpty() )
496     {
497         ACT_ADDMENU( current, "audio-es", qtr( "Audio &Track" ) );
498         ACT_ADDMENU( current, "audio-channels", qtr( "Audio &Channels" ) );
499         ACT_ADDMENU( current, "audio-device", qtr( "Audio &Device" ) );
500         current->addSeparator();
501
502         ACT_ADDMENU( current, "visual", qtr( "&Visualizations" ) );
503         current->addSeparator();
504
505         QAction *action = current->addAction( qtr( "Increase Volume" ),
506                 ActionsManager::getInstance( p_intf ), SLOT( AudioUp() ) );
507         action->setData( STATIC_ENTRY );
508         action = current->addAction( qtr( "Decrease Volume" ),
509                 ActionsManager::getInstance( p_intf ), SLOT( AudioDown() ) );
510         action->setData( STATIC_ENTRY );
511         action = current->addAction( qtr( "Mute" ),
512                 ActionsManager::getInstance( p_intf ), SLOT( toggleMuteAudio() ) );
513         action->setData( STATIC_ENTRY );
514     }
515
516     p_input = THEMIM->getInput();
517     p_aout = THEMIM->getAout();
518     EnableStaticEntries( current, ( p_aout != NULL ) );
519     AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
520     if( p_aout )
521     {
522         vlc_object_release( p_aout );
523     }
524
525     return Populate( p_intf, current, varnames, objects );
526 }
527
528 QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QWidget *parent )
529 {
530     return AudioMenu( p_intf, new QMenu( parent ) );
531 }
532
533 /**
534  * Main Video Menu
535  * Subtitles are part of Video.
536  **/
537 QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current )
538 {
539     vout_thread_t *p_vout;
540     input_thread_t *p_input;
541     vector<vlc_object_t *> objects;
542     vector<const char *> varnames;
543
544     if( current->isEmpty() )
545     {
546         ACT_ADDMENU( current, "video-es", qtr( "Video &Track" ) );
547
548         QAction *action;
549         QMenu *submenu = new QMenu( qtr( "&Subtitles Track" ), current );
550         action = current->addMenu( submenu );
551         action->setData( "spu-es" );
552         addDPStaticEntry( submenu, qtr( "Open File..." ), "",
553                           SLOT( loadSubtitlesFile() ) );
554         submenu->addSeparator();
555         current->addSeparator();
556
557         ACT_ADDCHECK( current, "fullscreen", qtr( "&Fullscreen" ) );
558         ACT_ADDCHECK( current, "video-on-top", qtr( "Always &On Top" ) );
559 #ifdef WIN32
560         ACT_ADDCHECK( current, "directx-wallpaper", qtr( "DirectX Wallpaper" ) );
561 #endif
562         ACT_ADD( current, "video-snapshot", qtr( "Sna&pshot" ) );
563
564         current->addSeparator();
565
566         ACT_ADDMENU( current, "zoom", qtr( "&Zoom" ) );
567         ACT_ADDCHECK( current, "autoscale", qtr( "Sca&le" ) );
568         ACT_ADDMENU( current, "aspect-ratio", qtr( "&Aspect Ratio" ) );
569         ACT_ADDMENU( current, "crop", qtr( "&Crop" ) );
570         ACT_ADDMENU( current, "deinterlace", qtr( "&Deinterlace" ) );
571         ACT_ADDMENU( current, "postprocess", qtr( "&Post processing" ) );
572     }
573
574     p_input = THEMIM->getInput();
575
576     p_vout = THEMIM->getVout();
577     VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
578
579     if( p_vout )
580         vlc_object_release( p_vout );
581
582     return Populate( p_intf, current, varnames, objects );
583 }
584
585 QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QWidget *parent )
586 {
587     return VideoMenu( p_intf, new QMenu( parent ) );
588 }
589
590 /**
591  * Navigation Menu
592  * For DVD, MP4, MOV and other chapter based format
593  **/
594 QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *menu )
595 {
596     QAction *action;
597
598     QMenu *submenu = new QMenu( qtr( "&Bookmarks" ), menu );
599     addDPStaticEntry( submenu, qtr( "Manage &bookmarks" ), "",
600                       SLOT( bookmarksDialog() ) );
601     submenu->addSeparator();
602     action = menu->addMenu( submenu );
603     action->setData( "bookmark" );
604
605     ACT_ADDMENU( menu, "title", qtr( "T&itle" ) );
606     ACT_ADDMENU( menu, "chapter", qtr( "&Chapter" ) );
607     ACT_ADDMENU( menu, "navigation", qtr( "&Navigation" ) );
608     ACT_ADDMENU( menu, "program", qtr( "&Program" ) );
609
610     menu->addSeparator();
611     PopupMenuPlaylistControlEntries( menu, p_intf );
612     PopupMenuControlEntries( menu, p_intf );
613
614     EnableStaticEntries( menu, ( THEMIM->getInput() != NULL ) );
615     return RebuildNavigMenu( p_intf, menu );
616 }
617
618 QMenu *QVLCMenu::RebuildNavigMenu( intf_thread_t *p_intf, QMenu *menu )
619 {
620     /* */
621     input_thread_t *p_object;
622     vector<vlc_object_t *> objects;
623     vector<const char *> varnames;
624
625     /* Get the input and hold it */
626     p_object = THEMIM->getInput();
627
628     InputAutoMenuBuilder( p_object, objects, varnames );
629
630     menu->addSeparator();
631
632     /* Title and so on */
633     PUSH_VAR( "prev-title" );
634     PUSH_VAR( "next-title" );
635     PUSH_VAR( "prev-chapter" );
636     PUSH_VAR( "next-chapter" );
637
638     EnableStaticEntries( menu, (p_object != NULL ) );
639     return Populate( p_intf, menu, varnames, objects );
640 }
641
642 QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QWidget *parent )
643 {
644     return NavigMenu( p_intf, new QMenu( parent ) );
645 }
646
647 /**
648  * Service Discovery SubMenu
649  **/
650 QMenu *QVLCMenu::SDMenu( intf_thread_t *p_intf, QWidget *parent )
651 {
652     QMenu *menu = new QMenu( parent );
653     menu->setTitle( qtr( I_PL_SD ) );
654
655     char **ppsz_longnames;
656     char **ppsz_names = vlc_sd_GetNames( &ppsz_longnames );
657     if( !ppsz_names )
658         return menu;
659
660     char **ppsz_name = ppsz_names, **ppsz_longname = ppsz_longnames;
661     for( ; *ppsz_name; ppsz_name++, ppsz_longname++ )
662     {
663         QAction *a = new QAction( qfu( *ppsz_longname ), menu );
664         a->setCheckable( true );
665         if( playlist_IsServicesDiscoveryLoaded( THEPL, *ppsz_name ) )
666             a->setChecked( true );
667         CONNECT( a, triggered(), THEDP->SDMapper, map() );
668         THEDP->SDMapper->setMapping( a, QString( *ppsz_name ) );
669         menu->addAction( a );
670
671         /* Special case for podcast */
672         if( !strcmp( *ppsz_name, "podcast" ) )
673         {
674             QAction *b = new QAction( qtr( "Configure podcasts..." ), menu );
675             //b->setEnabled( a->isChecked() );
676             menu->addAction( b );
677             CONNECT( b, triggered(), THEDP, podcastConfigureDialog() );
678         }
679         free( *ppsz_name );
680         free( *ppsz_longname );
681     }
682     free( ppsz_names );
683     free( ppsz_longnames );
684     return menu;
685 }
686
687 /**
688  * Help/About Menu
689 **/
690 QMenu *QVLCMenu::HelpMenu( QWidget *parent )
691 {
692     QMenu *menu = new QMenu( parent );
693     addDPStaticEntry( menu, qtr( "&Help..." ) ,
694         ":/help", SLOT( helpDialog() ), "F1" );
695 #ifdef UPDATE_CHECK
696     addDPStaticEntry( menu, qtr( "Check for &Updates..." ) , "",
697                       SLOT( updateDialog() ) );
698 #endif
699     menu->addSeparator();
700     addDPStaticEntry( menu, qtr( I_MENU_ABOUT ), ":/info",
701             SLOT( aboutDialog() ), "Shift+F1" );
702     return menu;
703 }
704
705 /*****************************************************************************
706  * Popup menus - Right Click menus                                           *
707  *****************************************************************************/
708 #define POPUP_BOILERPLATE \
709     unsigned int i_last_separator = 0; \
710     vector<vlc_object_t *> objects; \
711     vector<const char *> varnames; \
712     input_thread_t *p_input = THEMIM->getInput();
713
714 #define CREATE_POPUP \
715     Populate( p_intf, menu, varnames, objects ); \
716     p_intf->p_sys->p_popup_menu = menu; \
717     menu->popup( QCursor::pos() ); \
718     p_intf->p_sys->p_popup_menu = NULL; \
719     i_last_separator = 0;
720
721 void QVLCMenu::PopupPlayEntries( QMenu *menu,
722                                         intf_thread_t *p_intf,
723                                         input_thread_t *p_input )
724 {
725     QAction *action;
726
727     /* Play or Pause action and icon */
728     if( !p_input || var_GetInteger( p_input, "state" ) != PLAYING_S )
729     {
730         action = menu->addAction( qtr( "Play" ),
731                 ActionsManager::getInstance( p_intf ), SLOT( play() ) );
732         action->setIcon( QIcon( ":/play" ) );
733     }
734     else
735     {
736          addMIMStaticEntry( p_intf, menu, qtr( "Pause" ),
737                     ":/pause", SLOT( togglePlayPause() ) );
738     }
739 }
740
741 void QVLCMenu::PopupMenuControlEntries( QMenu *menu, intf_thread_t *p_intf )
742 {
743     QAction *action;
744
745     /* Faster/Slower */
746     action = menu->addAction( qtr( "&Faster" ), THEMIM->getIM(),
747                               SLOT( faster() ) );
748     action->setIcon( QIcon( ":/faster") );
749     action->setData( STATIC_ENTRY );
750
751     action = menu->addAction( qtr( "Faster (fine)" ), THEMIM->getIM(),
752                               SLOT( littlefaster() ) );
753     action->setData( STATIC_ENTRY );
754
755     action = menu->addAction( qtr( "N&ormal Speed" ), THEMIM->getIM(),
756                               SLOT( normalRate() ) );
757     action->setData( STATIC_ENTRY );
758
759     action = menu->addAction( qtr( "Slower (fine)" ), THEMIM->getIM(),
760                               SLOT( littleslower() ) );
761     action->setData( STATIC_ENTRY );
762
763     action = menu->addAction( qtr( "Slo&wer" ), THEMIM->getIM(),
764                               SLOT( slower() ) );
765     action->setIcon( QIcon( ":/slower") );
766     action->setData( STATIC_ENTRY );
767
768     menu->addSeparator();
769
770     action = menu->addAction( qtr( "&Jump Forward" ), THEMIM->getIM(),
771              SLOT( jumpFwd() ) );
772     action->setIcon( QIcon( ":/skip_fw") );
773     action->setData( STATIC_ENTRY );
774
775     action = menu->addAction( qtr( "Jump Bac&kward" ), THEMIM->getIM(),
776              SLOT( jumpBwd() ) );
777     action->setIcon( QIcon( ":/skip_back") );
778     action->setData( STATIC_ENTRY );
779     addDPStaticEntry( menu, qtr( I_MENU_GOTOTIME ),"",
780                       SLOT( gotoTimeDialog() ), "Ctrl+T" );
781     menu->addSeparator();
782 }
783
784
785 void QVLCMenu::PopupMenuPlaylistControlEntries( QMenu *menu,
786                                                 intf_thread_t *p_intf )
787 {
788     bool bEnable = THEMIM->getInput() != NULL;
789     QAction *action =
790             addMIMStaticEntry( p_intf, menu, qtr( "&Stop" ), ":/stop",
791                                SLOT( stop() ), true );
792     /* Disable Stop in the right-click popup menu */
793     if( !bEnable )
794         action->setEnabled( false );
795
796     /* Next / Previous */
797     addMIMStaticEntry( p_intf, menu, qtr( "Pre&vious" ),
798         ":/previous", SLOT( prev() ) );
799     addMIMStaticEntry( p_intf, menu, qtr( "Ne&xt" ),
800         ":/next", SLOT( next() ) );
801     menu->addSeparator();
802 }
803
804 void QVLCMenu::PopupMenuStaticEntries( QMenu *menu )
805 {
806     QMenu *openmenu = new QMenu( qtr( "Open Media" ), menu );
807     addDPStaticEntry( openmenu, qtr( "&Open File..." ),
808         ":/file-asym", SLOT( openFileDialog() ) );
809     addDPStaticEntry( openmenu, qtr( I_OPEN_FOLDER ),
810         ":/folder-grey", SLOT( PLOpenDir() ) );
811     addDPStaticEntry( openmenu, qtr( "Open &Disc..." ),
812         ":/disc", SLOT( openDiscDialog() ) );
813     addDPStaticEntry( openmenu, qtr( "Open &Network..." ),
814         ":/network", SLOT( openNetDialog() ) );
815     addDPStaticEntry( openmenu, qtr( "Open &Capture Device..." ),
816         ":/capture-card", SLOT( openCaptureDialog() ) );
817     menu->addMenu( openmenu );
818
819     menu->addSeparator();
820 #if 0
821     QMenu *helpmenu = HelpMenu( menu );
822     helpmenu->setTitle( qtr( "Help" ) );
823     menu->addMenu( helpmenu );
824 #endif
825
826     addDPStaticEntry( menu, qtr( "Quit" ), ":/quit",
827                       SLOT( quit() ), "Ctrl+Q" );
828 }
829
830 /* Video Tracks and Subtitles tracks */
831 void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf )
832 {
833     POPUP_BOILERPLATE;
834     if( p_input )
835     {
836         vout_thread_t *p_vout = THEMIM->getVout();
837         if( p_vout )
838         {
839             VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
840             vlc_object_release( p_vout );
841         }
842     }
843     QMenu *menu = new QMenu();
844     CREATE_POPUP;
845 }
846
847 /* Audio Tracks */
848 void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf )
849 {
850     POPUP_BOILERPLATE;
851     if( p_input )
852     {
853         aout_instance_t *p_aout = THEMIM->getAout();
854         AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
855         if( p_aout )
856             vlc_object_release( p_aout );
857     }
858     QMenu *menu = new QMenu();
859     CREATE_POPUP;
860 }
861
862 /* Navigation stuff, and general menus ( open ), used only for skins */
863 void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf )
864 {
865     POPUP_BOILERPLATE;
866
867     if( p_input )
868     {
869         varnames.push_back( "audio-es" );
870         InputAutoMenuBuilder( p_input, objects, varnames );
871         PUSH_SEPARATOR;
872     }
873
874     QMenu *menu = new QMenu();
875     Populate( p_intf, menu, varnames, objects );
876
877     menu->addSeparator();
878     PopupPlayEntries( menu, p_intf, p_input );
879     PopupMenuPlaylistControlEntries( menu, p_intf);
880
881     menu->addSeparator();
882     PopupMenuControlEntries( menu, p_intf );
883
884     menu->addSeparator();
885     PopupMenuStaticEntries( menu );
886
887     p_intf->p_sys->p_popup_menu = menu;
888     menu->popup( QCursor::pos() );
889     p_intf->p_sys->p_popup_menu = NULL;
890 }
891
892 /* Main Menu that sticks everything together  */
893 void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show )
894 {
895     /* Delete old popup if there is one */
896     if( p_intf->p_sys->p_popup_menu )
897         delete p_intf->p_sys->p_popup_menu;
898
899     if( !show )
900     {
901         p_intf->p_sys->p_popup_menu = NULL;
902         return;
903     }
904
905     /* */
906     QMenu *menu = new QMenu();
907     QAction *action;
908     bool b_isFullscreen = false;
909     MainInterface *mi = p_intf->p_sys->p_mi;
910
911     POPUP_BOILERPLATE;
912
913     PopupPlayEntries( menu, p_intf, p_input );
914     PopupMenuPlaylistControlEntries( menu, p_intf );
915     menu->addSeparator();
916
917     if( p_input )
918     {
919         QMenu *submenu;
920         vout_thread_t *p_vout = THEMIM->getVout();
921
922         /* Add a fullscreen switch button, since it is the most used function */
923         if( p_vout )
924         {
925             vlc_value_t val; var_Get( p_vout, "fullscreen", &val );
926
927             b_isFullscreen = !( !val.b_bool );
928             if( b_isFullscreen )
929                 CreateAndConnect( menu, "fullscreen",
930                         qtr( "Leave Fullscreen" ),"" , ITEM_NORMAL,
931                         VLC_OBJECT(p_vout), val, VLC_VAR_BOOL, b_isFullscreen );
932             vlc_object_release( p_vout );
933
934             menu->addSeparator();
935         }
936
937         /* Input menu */
938         InputAutoMenuBuilder( p_input, objects, varnames );
939
940         /* Audio menu */
941         submenu = new QMenu( menu );
942         action = menu->addMenu( AudioMenu( p_intf, submenu ) );
943         action->setText( qtr( "&Audio" ) );
944         if( action->menu()->isEmpty() )
945             action->setEnabled( false );
946
947         /* Video menu */
948         submenu = new QMenu( menu );
949         action = menu->addMenu( VideoMenu( p_intf, submenu ) );
950         action->setText( qtr( "&Video" ) );
951         if( action->menu()->isEmpty() )
952             action->setEnabled( false );
953
954         /* Playback menu for chapters */
955         submenu = new QMenu( menu );
956         action = menu->addMenu( NavigMenu( p_intf, submenu ) );
957         action->setText( qtr( "&Playback" ) );
958         if( action->menu()->isEmpty() )
959             action->setEnabled( false );
960     }
961
962     menu->addSeparator();
963
964     /* Add some special entries for windowed mode: Interface Menu */
965     if( !b_isFullscreen )
966     {
967         QMenu *submenu = new QMenu( qtr( "Interface" ), menu );
968         QMenu *tools = ToolsMenu( submenu );
969         submenu->addSeparator();
970
971         /* In skins interface, append some items */
972         if( !mi )
973         {
974
975             vlc_object_t *p_object = ( vlc_object_t* )
976                 vlc_object_find_name( p_intf, "skins2", FIND_PARENT );
977             if( p_object )
978             {
979                 objects.clear(); varnames.clear();
980                 objects.push_back( p_object );
981                 varnames.push_back( "intf-skins" );
982                 Populate( p_intf, submenu, varnames, objects );
983
984                 objects.clear(); varnames.clear();
985                 objects.push_back( p_object );
986                 varnames.push_back( "intf-skins-interactive" );
987                 Populate( p_intf, submenu, varnames, objects );
988
989                 vlc_object_release( p_object );
990             }
991             else
992                 msg_Warn( p_intf, "could not find parent interface" );
993         }
994         else
995             menu->addMenu( ViewMenu( p_intf, mi, false ));
996
997         menu->addMenu( submenu );
998     }
999
1000     /* Static entries for ending, like open */
1001     PopupMenuStaticEntries( menu );
1002
1003     p_intf->p_sys->p_popup_menu = menu;
1004     p_intf->p_sys->p_popup_menu->popup( QCursor::pos() );
1005 }
1006
1007 #undef ACT_ADD
1008 #undef ACT_ADDMENU
1009 #undef ACT_ADDCHECK
1010
1011 /************************************************************************
1012  * Systray Menu                                                         *
1013  ************************************************************************/
1014
1015 void QVLCMenu::updateSystrayMenu( MainInterface *mi,
1016                                   intf_thread_t *p_intf,
1017                                   bool b_force_visible )
1018 {
1019     POPUP_BOILERPLATE;
1020
1021     /* Get the systray menu and clean it */
1022     QMenu *sysMenu = mi->getSysTrayMenu();
1023     sysMenu->clear();
1024
1025     /* Hide / Show VLC and cone */
1026     if( mi->isVisible() || b_force_visible )
1027     {
1028         sysMenu->addAction( QIcon( ":/vlc16.png" ),
1029                             qtr( "Hide VLC media player in taskbar" ), mi,
1030                             SLOT( toggleUpdateSystrayMenu() ) );
1031     }
1032     else
1033     {
1034         sysMenu->addAction( QIcon( ":/vlc16.png" ),
1035                             qtr( "Show VLC media player" ), mi,
1036                             SLOT( toggleUpdateSystrayMenu() ) );
1037     }
1038
1039     sysMenu->addSeparator();
1040     PopupPlayEntries( sysMenu, p_intf, p_input );
1041     PopupMenuPlaylistControlEntries( sysMenu, p_intf);
1042     PopupMenuControlEntries( sysMenu, p_intf);
1043
1044     sysMenu->addSeparator();
1045     addDPStaticEntry( sysMenu, qtr( "&Open Media" ),
1046             ":/file-wide", SLOT( openFileDialog() ) );
1047     addDPStaticEntry( sysMenu, qtr( "&Quit" ) ,
1048             ":/quit", SLOT( quit() ) );
1049
1050     /* Set the menu */
1051     mi->getSysTray()->setContextMenu( sysMenu );
1052 }
1053
1054 #undef CREATE_POPUP
1055 #undef POPUP_BOILERPLATE
1056
1057 #undef PUSH_VAR
1058 #undef PUSH_SEPARATOR
1059
1060 /*************************************************************************
1061  * Builders for automenus
1062  *************************************************************************/
1063 QMenu * QVLCMenu::Populate( intf_thread_t *p_intf,
1064                             QMenu *current,
1065                             vector< const char *> & varnames,
1066                             vector<vlc_object_t *> & objects )
1067 {
1068     QMenu *menu = current;
1069     assert( menu );
1070
1071     currentGroup = NULL;
1072
1073     vlc_object_t *p_object;
1074
1075     for( int i = 0; i < ( int )objects.size() ; i++ )
1076     {
1077         if( !varnames[i] || !*varnames[i] )
1078         {
1079             menu->addSeparator();
1080             continue;
1081         }
1082         p_object = objects[i];
1083
1084         UpdateItem( p_intf, menu, varnames[i], p_object, true );
1085     }
1086     return menu;
1087 }
1088
1089 /*****************************************************************************
1090  * Private methods.
1091  *****************************************************************************/
1092
1093 static bool IsMenuEmpty( const char *psz_var,
1094                          vlc_object_t *p_object,
1095                          bool b_root = true )
1096 {
1097     vlc_value_t val, val_list;
1098     int i_type, i_result, i;
1099
1100     /* Check the type of the object variable */
1101     i_type = var_Type( p_object, psz_var );
1102
1103     /* Check if we want to display the variable */
1104     if( !( i_type & VLC_VAR_HASCHOICE ) ) return false;
1105
1106     var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
1107     if( val.i_int == 0 ) return true;
1108
1109     if( ( i_type & VLC_VAR_TYPE ) != VLC_VAR_VARIABLE )
1110     {
1111         if( val.i_int == 1 && b_root ) return true;
1112         else return false;
1113     }
1114
1115     /* Check children variables in case of VLC_VAR_VARIABLE */
1116     if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
1117     {
1118         return true;
1119     }
1120
1121     for( i = 0, i_result = true; i < val_list.p_list->i_count; i++ )
1122     {
1123         if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
1124                     p_object, false ) )
1125         {
1126             i_result = false;
1127             break;
1128         }
1129     }
1130
1131     /* clean up everything */
1132     var_FreeList( &val_list, NULL );
1133
1134     return i_result;
1135 }
1136
1137 #define TEXT_OR_VAR qfu ( text.psz_string ? text.psz_string : psz_var )
1138
1139 void QVLCMenu::UpdateItem( intf_thread_t *p_intf, QMenu *menu,
1140         const char *psz_var, vlc_object_t *p_object, bool b_submenu )
1141 {
1142     vlc_value_t val, text;
1143     int i_type;
1144
1145     QAction *action = FindActionWithVar( menu, psz_var );
1146     if( action )
1147         DeleteNonStaticEntries( action->menu() );
1148
1149     if( !p_object )
1150     {
1151         if( action )
1152             action->setEnabled( false );
1153         return;
1154     }
1155
1156     /* Check the type of the object variable */
1157     /* This HACK is needed so we have a radio button for audio and video tracks
1158        instread of a checkbox */
1159     if( !strcmp( psz_var, "audio-es" )
1160      || !strcmp( psz_var, "video-es" ) )
1161         i_type = VLC_VAR_INTEGER | VLC_VAR_HASCHOICE;
1162     else
1163         i_type = var_Type( p_object, psz_var );
1164
1165     switch( i_type & VLC_VAR_TYPE )
1166     {
1167         case VLC_VAR_VOID:
1168         case VLC_VAR_BOOL:
1169         case VLC_VAR_VARIABLE:
1170         case VLC_VAR_STRING:
1171         case VLC_VAR_INTEGER:
1172         case VLC_VAR_FLOAT:
1173             break;
1174         default:
1175             /* Variable doesn't exist or isn't handled */
1176             if( action )
1177                 action->setEnabled( false );
1178             return;
1179     }
1180
1181     /* Make sure we want to display the variable */
1182     if( menu->isEmpty() && IsMenuEmpty( psz_var, p_object ) )
1183     {
1184         if( action )
1185             action->setEnabled( false );
1186         return;
1187     }
1188
1189     /* Get the descriptive name of the variable */
1190     int i_ret = var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
1191     if( i_ret != VLC_SUCCESS )
1192     {
1193         text.psz_string = NULL;
1194     }
1195
1196     if( !action )
1197     {
1198         action = new QAction( TEXT_OR_VAR, menu );
1199         menu->addAction( action );
1200         action->setData( psz_var );
1201     }
1202
1203     /* Some specific stuff */
1204     bool forceDisabled = false;
1205     if( !strcmp( psz_var, "spu-es" ) )
1206     {
1207         vout_thread_t *p_vout = THEMIM->getVout();
1208         forceDisabled = ( p_vout == NULL );
1209         if( p_vout )
1210             vlc_object_release( p_vout );
1211     }
1212
1213     if( i_type & VLC_VAR_HASCHOICE )
1214     {
1215         /* Append choices menu */
1216         if( b_submenu )
1217         {
1218             QMenu *submenu;
1219             submenu = action->menu();
1220             if( !submenu )
1221             {
1222                 submenu = new QMenu( menu );
1223                 action->setMenu( submenu );
1224             }
1225
1226             action->setEnabled(
1227                CreateChoicesMenu( submenu, psz_var, p_object, true ) == 0 );
1228             if( forceDisabled )
1229                 action->setEnabled( false );
1230         }
1231         else
1232         {
1233             action->setEnabled(
1234                 CreateChoicesMenu( menu, psz_var, p_object, true ) == 0 );
1235         }
1236         FREENULL( text.psz_string );
1237         return;
1238     }
1239
1240     switch( i_type & VLC_VAR_TYPE )
1241     {
1242         case VLC_VAR_VOID:
1243             var_Get( p_object, psz_var, &val );
1244             CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_NORMAL,
1245                     p_object, val, i_type );
1246             break;
1247
1248         case VLC_VAR_BOOL:
1249             var_Get( p_object, psz_var, &val );
1250             val.b_bool = !val.b_bool;
1251             CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_CHECK,
1252                     p_object, val, i_type, !val.b_bool );
1253             break;
1254     }
1255     FREENULL( text.psz_string );
1256 }
1257
1258 #undef TEXT_OR_VAR
1259
1260
1261 int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
1262         vlc_object_t *p_object, bool b_root )
1263 {
1264     vlc_value_t val, val_list, text_list;
1265     int i_type, i;
1266
1267     /* Check the type of the object variable */
1268     i_type = var_Type( p_object, psz_var );
1269
1270     /* Make sure we want to display the variable */
1271     if( submenu->isEmpty() && IsMenuEmpty( psz_var, p_object, b_root ) )
1272         return VLC_EGENERIC;
1273
1274     switch( i_type & VLC_VAR_TYPE )
1275     {
1276         case VLC_VAR_VOID:
1277         case VLC_VAR_BOOL:
1278         case VLC_VAR_VARIABLE:
1279         case VLC_VAR_STRING:
1280         case VLC_VAR_INTEGER:
1281         case VLC_VAR_FLOAT:
1282             break;
1283         default:
1284             /* Variable doesn't exist or isn't handled */
1285             return VLC_EGENERIC;
1286     }
1287
1288     if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
1289                     &val_list, &text_list ) < 0 )
1290     {
1291         return VLC_EGENERIC;
1292     }
1293
1294 #define CURVAL val_list.p_list->p_values[i]
1295 #define CURTEXT text_list.p_list->p_values[i].psz_string
1296
1297     for( i = 0; i < val_list.p_list->i_count; i++ )
1298     {
1299         vlc_value_t another_val;
1300         QString menutext;
1301         QMenu *subsubmenu = new QMenu( submenu );
1302
1303         switch( i_type & VLC_VAR_TYPE )
1304         {
1305             case VLC_VAR_VARIABLE:
1306                 CreateChoicesMenu( subsubmenu, CURVAL.psz_string, p_object, false );
1307                 subsubmenu->setTitle( qfu( CURTEXT ? CURTEXT :CURVAL.psz_string ) );
1308                 submenu->addMenu( subsubmenu );
1309                 break;
1310
1311             case VLC_VAR_STRING:
1312                 var_Get( p_object, psz_var, &val );
1313                 another_val.psz_string = strdup( CURVAL.psz_string );
1314                 menutext = qfu( CURTEXT ? CURTEXT : another_val.psz_string );
1315                 CreateAndConnect( submenu, psz_var, menutext, "", ITEM_RADIO,
1316                         p_object, another_val, i_type,
1317                         val.psz_string && !strcmp( val.psz_string, CURVAL.psz_string ) );
1318
1319                 free( val.psz_string );
1320                 break;
1321
1322             case VLC_VAR_INTEGER:
1323                 var_Get( p_object, psz_var, &val );
1324                 if( CURTEXT ) menutext = qfu( CURTEXT );
1325                 else menutext.sprintf( "%d", CURVAL.i_int );
1326                 CreateAndConnect( submenu, psz_var, menutext, "", ITEM_RADIO,
1327                         p_object, CURVAL, i_type,
1328                         CURVAL.i_int == val.i_int );
1329                 break;
1330
1331             case VLC_VAR_FLOAT:
1332                 var_Get( p_object, psz_var, &val );
1333                 if( CURTEXT ) menutext = qfu( CURTEXT );
1334                 else menutext.sprintf( "%.2f", CURVAL.f_float );
1335                 CreateAndConnect( submenu, psz_var, menutext, "", ITEM_RADIO,
1336                         p_object, CURVAL, i_type,
1337                         CURVAL.f_float == val.f_float );
1338                 break;
1339
1340             default:
1341                 break;
1342         }
1343     }
1344     currentGroup = NULL;
1345
1346     /* clean up everything */
1347     var_FreeList( &val_list, &text_list );
1348
1349 #undef CURVAL
1350 #undef CURTEXT
1351     return submenu->isEmpty() ? VLC_EGENERIC : VLC_SUCCESS;
1352 }
1353
1354 void QVLCMenu::CreateAndConnect( QMenu *menu, const char *psz_var,
1355         QString text, QString help,
1356         int i_item_type, vlc_object_t *p_obj,
1357         vlc_value_t val, int i_val_type,
1358         bool checked )
1359 {
1360     QAction *action = FindActionWithVar( menu, psz_var );
1361
1362     bool b_new = false;
1363     if( !action )
1364     {
1365         action = new QAction( text, menu );
1366         menu->addAction( action );
1367         b_new = true;
1368     }
1369
1370     action->setToolTip( help );
1371     action->setEnabled( p_obj != NULL );
1372
1373     if( i_item_type == ITEM_CHECK )
1374     {
1375         action->setCheckable( true );
1376     }
1377     else if( i_item_type == ITEM_RADIO )
1378     {
1379         action->setCheckable( true );
1380         if( !currentGroup )
1381             currentGroup = new QActionGroup( menu );
1382         currentGroup->addAction( action );
1383     }
1384
1385     action->setChecked( checked );
1386
1387     MenuItemData *itemData = new MenuItemData( THEDP->menusMapper, p_obj, i_val_type,
1388             val, psz_var );
1389     CONNECT( action, triggered(), THEDP->menusMapper, map() );
1390     THEDP->menusMapper->setMapping( action, itemData );
1391
1392     if( b_new )
1393         menu->addAction( action );
1394 }
1395
1396 void QVLCMenu::DoAction( QObject *data )
1397 {
1398     MenuItemData *itemData = qobject_cast<MenuItemData *>( data );
1399     vlc_object_t *p_object = itemData->p_obj;
1400     if( p_object == NULL ) return;
1401
1402     var_Set( p_object, itemData->psz_var, itemData->val );
1403 }
1404
1405 void QVLCMenu::updateRecents( intf_thread_t *p_intf )
1406 {
1407     if (recentsMenu)
1408     {
1409         QAction* action;
1410         RecentsMRL* rmrl = RecentsMRL::getInstance( p_intf );
1411         QList<QString> l = rmrl->recents();
1412
1413         recentsMenu->clear();
1414
1415         if( !l.size() )
1416         {
1417             action = recentsMenu->addAction( qtr(" - Empty - ") );
1418             action->setEnabled( false );
1419         }
1420         else
1421         {
1422             for( int i = 0; i < l.size(); ++i )
1423             {
1424                 action = recentsMenu->addAction(
1425                         QString( "&%1: " ).arg( i + 1 ) + l.at( i ),
1426                         rmrl->signalMapper,
1427                         SLOT( map() ) );
1428                 rmrl->signalMapper->setMapping( action, l.at( i ) );
1429             }
1430
1431             recentsMenu->addSeparator();
1432             recentsMenu->addAction( qtr("&Clear"), rmrl, SLOT( clear() ) );
1433         }
1434     }
1435 }