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