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