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