]> git.sesse.net Git - vlc/blob - modules/gui/qt4/menus.cpp
d93c8c076a92f42db681ec745850071b0c1c091e
[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( p_intf, 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( intf_thread_t *p_intf, 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     if( !p_intf->p_sys->b_isDialogProvider )
436         addDPStaticEntry( menu, qtr( "Customi&ze Interface..." ),
437             ":/menu/preferences", SLOT( toolbarDialog() ) );
438
439     addDPStaticEntry( menu, qtr( "&Preferences" ),
440         ":/menu/preferences", SLOT( prefsDialog() ), "Ctrl+P", QAction::PreferencesRole );
441
442     return menu;
443 }
444
445 /**
446  * View Menu
447  * Interface modification, load other interfaces, activate Extensions
448  * \param current, set to NULL for menu creation, else for menu update
449  **/
450 QMenu *VLCMenuBar::ViewMenu( intf_thread_t *p_intf, QMenu *current, MainInterface *_mi )
451 {
452     QAction *action;
453     QMenu *menu;
454
455     MainInterface *mi = _mi ? _mi : p_intf->p_sys->p_mi;
456     assert( mi );
457
458     if( !current )
459     {
460         menu = new QMenu( qtr( "&View" ), mi );
461     }
462     else
463     {
464         menu = current;
465         //menu->clear();
466         //HACK menu->clear() does not delete submenus
467         QList<QAction*> actions = menu->actions();
468         foreach( QAction *a, actions )
469         {
470             QMenu *m = a->menu();
471             if( a->parent() == menu ) delete a;
472             else menu->removeAction( a );
473             if( m && m->parent() == menu ) delete m;
474         }
475     }
476
477     menu->addAction(
478 #ifndef __APPLE__
479             QIcon( ":/menu/playlist_menu" ),
480 #endif
481             qtr( "Play&list" ), mi,
482             SLOT( togglePlaylist() ), qtr( "Ctrl+L" ) );
483
484     /* Docked Playlist */
485     action = menu->addAction( qtr( "Docked Playlist" ) );
486     action->setCheckable( true );
487     action->setChecked( mi->isPlDocked() );
488     CONNECT( action, triggered( bool ), mi, dockPlaylist( bool ) );
489
490     if( mi->getPlaylistView() )
491         menu->addMenu( StandardPLPanel::viewSelectionMenu( mi->getPlaylistView() ) );
492
493     menu->addSeparator();
494
495     /* Minimal View */
496     action = menu->addAction( qtr( "Mi&nimal Interface" ) );
497     action->setShortcut( qtr( "Ctrl+H" ) );
498     action->setCheckable( true );
499     action->setChecked( (mi->getControlsVisibilityStatus()
500                          & MainInterface::CONTROLS_HIDDEN ) );
501
502     CONNECT( action, triggered( bool ), mi, toggleMinimalView( bool ) );
503     CONNECT( mi, minimalViewToggled( bool ), action, setChecked( bool ) );
504
505     /* FullScreen View */
506     action = menu->addAction( qtr( "&Fullscreen Interface" ), mi,
507             SLOT( toggleInterfaceFullScreen() ), QString( "F11" ) );
508     action->setCheckable( true );
509     action->setChecked( mi->isInterfaceFullScreen() );
510     CONNECT( mi, fullscreenInterfaceToggled( bool ),
511              action, setChecked( bool ) );
512
513     /* Advanced Controls */
514     action = menu->addAction( qtr( "&Advanced Controls" ), mi,
515             SLOT( toggleAdvancedButtons() ) );
516     action->setCheckable( true );
517     if( mi->getControlsVisibilityStatus() & MainInterface::CONTROLS_ADVANCED )
518         action->setChecked( true );
519
520     action = menu->addAction( qtr( "Status Bar" ) );
521     action->setCheckable( true );
522     action->setChecked( mi->statusBar()->isVisible() );
523     CONNECT( action, triggered( bool ), mi, setStatusBarVisibility( bool) );
524 #if 0 /* For Visualisations. Not yet working */
525     adv = menu->addAction( qtr( "Visualizations selector" ), mi,
526                            SLOT( visual() ) );
527     adv->setCheckable( true );
528     if( visual_selector_enabled ) adv->setChecked( true );
529 #endif
530
531     menu->addSeparator();
532
533     InterfacesMenu( p_intf, menu );
534     menu->addSeparator();
535
536     /* Extensions */
537     ExtensionsMenu( p_intf, menu );
538
539     return menu;
540 }
541
542 /**
543  * Interface Sub-Menu, to list extras interface and skins
544  **/
545 QMenu *VLCMenuBar::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
546 {
547     QVector<vlc_object_t *> objects;
548     QVector<const char *> varnames;
549     varnames.append( "intf-add" );
550     objects.append( VLC_OBJECT(p_intf) );
551
552     return Populate( p_intf, current, varnames, objects );
553 }
554
555 /**
556  * Extensions menu: populate the current menu with extensions
557  **/
558 void VLCMenuBar::ExtensionsMenu( intf_thread_t *p_intf, QMenu *extMenu )
559 {
560     /* Get ExtensionsManager and load extensions if needed */
561     ExtensionsManager *extMgr = ExtensionsManager::getInstance( p_intf );
562
563     if( !var_InheritBool( p_intf, "qt-autoload-extensions")
564         && !extMgr->isLoaded() )
565     {
566         return;
567     }
568
569     if( !extMgr->isLoaded() && !extMgr->cannotLoad() )
570     {
571         extMgr->loadExtensions();
572     }
573
574     /* Let the ExtensionsManager build itself the menu */
575     extMenu->addSeparator();
576     extMgr->menu( extMenu );
577 }
578
579 static inline void VolumeEntries( intf_thread_t *p_intf, QMenu *current )
580 {
581     current->addSeparator();
582
583     QAction *action = current->addAction( qtr( "&Increase Volume" ),
584                 ActionsManager::getInstance( p_intf ), SLOT( AudioUp() ) );
585     action->setData( VLCMenuBar::ACTION_STATIC );
586     action = current->addAction( qtr( "&Decrease Volume" ),
587                 ActionsManager::getInstance( p_intf ), SLOT( AudioDown() ) );
588     action->setData( VLCMenuBar::ACTION_STATIC );
589     action = current->addAction( qtr( "&Mute" ),
590                 ActionsManager::getInstance( p_intf ), SLOT( toggleMuteAudio() ) );
591     action->setData( VLCMenuBar::ACTION_STATIC );
592 }
593
594 /**
595  * Main Audio Menu
596  **/
597 QMenu *VLCMenuBar::AudioMenu( intf_thread_t *p_intf, QMenu * current )
598 {
599     QVector<vlc_object_t *> objects;
600     QVector<const char *> varnames;
601     audio_output_t *p_aout;
602     input_thread_t *p_input;
603
604     if( current->isEmpty() )
605     {
606         addActionWithSubmenu( current, "audio-es", qtr( "Audio &Track" ) );
607         audioDeviceMenu = current->addMenu( qtr( "Audio &Device" ) );
608         addActionWithSubmenu( current, "stereo-mode", qtr( "&Stereo Mode" ) );
609         current->addSeparator();
610
611         addActionWithSubmenu( current, "visual", qtr( "&Visualizations" ) );
612         VolumeEntries( p_intf, current );
613     }
614
615     p_input = THEMIM->getInput();
616     p_aout = THEMIM->getAout();
617     EnableStaticEntries( current, ( p_aout != NULL ) );
618     AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
619     updateAudioDevice( p_intf, p_aout, audioDeviceMenu );
620     if( p_aout )
621     {
622         vlc_object_release( p_aout );
623     }
624
625     return Populate( p_intf, current, varnames, objects );
626 }
627
628 /* Subtitles */
629 QMenu *VLCMenuBar::SubtitleMenu( intf_thread_t *p_intf, QMenu *current )
630 {
631     input_thread_t *p_input;
632     QVector<vlc_object_t *> objects;
633     QVector<const char *> varnames;
634
635     if( current->isEmpty() )
636     {
637         addDPStaticEntry( current, qtr( "Add &Subtitle File..." ), "",
638                 SLOT( loadSubtitlesFile() ) );
639         addActionWithSubmenu( current, "spu-es", qtr( "Sub &Track" ) );
640         current->addSeparator();
641     }
642
643     p_input = THEMIM->getInput();
644     SubsAutoMenuBuilder( p_input, objects, varnames );
645
646     return Populate( p_intf, current, varnames, objects );
647 }
648
649 /**
650  * Main Video Menu
651  * Subtitles are part of Video.
652  **/
653 QMenu *VLCMenuBar::VideoMenu( intf_thread_t *p_intf, QMenu *current )
654 {
655     vout_thread_t *p_vout;
656     input_thread_t *p_input;
657     QVector<vlc_object_t *> objects;
658     QVector<const char *> varnames;
659
660     if( current->isEmpty() )
661     {
662         addActionWithSubmenu( current, "video-es", qtr( "Video &Track" ) );
663
664         current->addSeparator();
665         /* Surface modifiers */
666         addActionWithCheckbox( current, "fullscreen", qtr( "&Fullscreen" ) );
667         addActionWithCheckbox( current, "autoscale", qtr( "Always Fit &Window" ) );
668         addActionWithCheckbox( current, "video-on-top", qtr( "Always &on Top" ) );
669         addActionWithCheckbox( current, "video-wallpaper", qtr( "Set as Wall&paper" ) );
670
671         current->addSeparator();
672         /* Size modifiers */
673         addActionWithSubmenu( current, "zoom", qtr( "&Zoom" ) );
674         addActionWithSubmenu( current, "aspect-ratio", qtr( "&Aspect Ratio" ) );
675         addActionWithSubmenu( current, "crop", qtr( "&Crop" ) );
676
677         current->addSeparator();
678         /* Rendering modifiers */
679         addActionWithSubmenu( current, "deinterlace", qtr( "&Deinterlace" ) );
680         addActionWithSubmenu( current, "deinterlace-mode", qtr( "&Deinterlace mode" ) );
681         addActionWithSubmenu( current, "postprocess", qtr( "&Post processing" ) );
682
683         current->addSeparator();
684         /* Other actions */
685         addAction( current, "video-snapshot", qtr( "Take &Snapshot" ) );
686     }
687
688     p_input = THEMIM->getInput();
689
690     p_vout = THEMIM->getVout();
691     VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
692
693     if( p_vout )
694         vlc_object_release( p_vout );
695
696     return Populate( p_intf, current, varnames, objects );
697 }
698
699 /**
700  * Navigation Menu
701  * For DVD, MP4, MOV and other chapter based format
702  **/
703 QMenu *VLCMenuBar::NavigMenu( intf_thread_t *p_intf, QMenu *menu )
704 {
705     QAction *action;
706     QMenu *submenu;
707
708     addActionWithSubmenu( menu, "title", qtr( "T&itle" ) );
709     submenu = addActionWithSubmenu( menu, "chapter", qtr( "&Chapter" ) );
710     submenu->setTearOffEnabled( true );
711     addActionWithSubmenu( menu, "program", qtr( "&Program" ) );
712
713     submenu = new QMenu( qtr( I_MENU_BOOKMARK ), 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( I_OP_OPF ),
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 ) );
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( p_intf, 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                 /* list of skins available */
1078                 vlc_object_t* p_object = p_intf->p_parent;
1079
1080                 objects.clear(); varnames.clear();
1081                 objects.append( p_object );
1082                 varnames.append( "intf-skins" );
1083                 Populate( p_intf, submenu, varnames, objects );
1084
1085                 objects.clear(); varnames.clear();
1086                 objects.append( p_object );
1087                 varnames.append( "intf-skins-interactive" );
1088                 Populate( p_intf, submenu, varnames, objects );
1089
1090                 submenu->addSeparator();
1091
1092                 /* Extensions */
1093                 ExtensionsMenu( p_intf, submenu );
1094
1095             }
1096             else
1097                 msg_Warn( p_intf, "could not find parent interface" );
1098         }
1099         else
1100         {
1101             QMenu *bar = menu; // Needed for next macro
1102             BAR_DADD( ViewMenu( p_intf, NULL, mi ), qtr( "V&iew" ), 4 );
1103         }
1104
1105         menu->addMenu( submenu );
1106     }
1107
1108     /* */
1109     QMenuView *plMenu = new QMenuView( menu, 25 );
1110     plMenu->setTitle( qtr("Playlist") );
1111     PLModel *model = PLModel::getPLModel( p_intf );
1112     plMenu->setModel( model );
1113     CONNECT( plMenu, activated(const QModelIndex&),
1114              model, activateItem(const QModelIndex&));
1115     menu->addMenu( plMenu );
1116
1117     /* Static entries for ending, like open */
1118     PopupMenuStaticEntries( menu );
1119
1120     menu->popup( QCursor::pos() );
1121 }
1122
1123 #undef CREATE_POPUP
1124 #undef POPUP_BOILERPLATE
1125 #undef BAR_DADD
1126
1127 /************************************************************************
1128  * Systray Menu                                                         *
1129  ************************************************************************/
1130
1131 void VLCMenuBar::updateSystrayMenu( MainInterface *mi,
1132                                   intf_thread_t *p_intf,
1133                                   bool b_force_visible )
1134 {
1135     input_thread_t *p_input = THEMIM->getInput();
1136
1137     /* Get the systray menu and clean it */
1138     QMenu *sysMenu = mi->getSysTrayMenu();
1139     sysMenu->clear();
1140
1141 #ifndef Q_WS_MAC
1142     /* Hide / Show VLC and cone */
1143     if( mi->isVisible() || b_force_visible )
1144     {
1145         sysMenu->addAction( QIcon( ":/logo/vlc16.png" ),
1146                             qtr( "&Hide VLC media player in taskbar" ), mi,
1147                             SLOT( hideUpdateSystrayMenu() ) );
1148     }
1149     else
1150     {
1151         sysMenu->addAction( QIcon( ":/logo/vlc16.png" ),
1152                             qtr( "Sho&w VLC media player" ), mi,
1153                             SLOT( showUpdateSystrayMenu() ) );
1154     }
1155     sysMenu->addSeparator();
1156 #endif
1157
1158     PopupMenuPlaylistEntries( sysMenu, p_intf, p_input );
1159     PopupMenuControlEntries( sysMenu, p_intf, false );
1160
1161     VolumeEntries( p_intf, sysMenu );
1162     sysMenu->addSeparator();
1163     addDPStaticEntry( sysMenu, qtr( "&Open Media" ),
1164             ":/type/file-wide", SLOT( openFileDialog() ) );
1165     addDPStaticEntry( sysMenu, qtr( "&Quit" ) ,
1166             ":/menu/exit", SLOT( quit() ) );
1167
1168     /* Set the menu */
1169     mi->getSysTray()->setContextMenu( sysMenu );
1170 }
1171
1172
1173 #undef PUSH_VAR
1174
1175 /*************************************************************************
1176  * Builders for automenus
1177  *************************************************************************/
1178 QMenu * VLCMenuBar::Populate( intf_thread_t *p_intf,
1179                             QMenu *current,
1180                             QVector< const char *> & varnames,
1181                             QVector<vlc_object_t *> & objects )
1182 {
1183     QMenu *menu = current;
1184     assert( menu );
1185
1186     currentGroup = NULL;
1187
1188     for( int i = 0; i < (int)objects.count() ; i++ )
1189     {
1190         if( !varnames[i] || !*varnames[i] )
1191         {
1192             menu->addSeparator();
1193             continue;
1194         }
1195
1196         UpdateItem( p_intf, menu, varnames[i], objects[i], true );
1197     }
1198     return menu;
1199 }
1200
1201 /*****************************************************************************
1202  * Private methods.
1203  *****************************************************************************/
1204
1205 static bool IsMenuEmpty( const char *psz_var,
1206                          vlc_object_t *p_object,
1207                          bool b_root = true )
1208 {
1209     vlc_value_t val, val_list;
1210     int i_type, i_result, i;
1211
1212     /* Check the type of the object variable */
1213     i_type = var_Type( p_object, psz_var );
1214
1215     /* Check if we want to display the variable */
1216     if( !( i_type & VLC_VAR_HASCHOICE ) ) return false;
1217
1218     var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
1219     if( val.i_int == 0 ) return true;
1220
1221     if( ( i_type & VLC_VAR_TYPE ) != VLC_VAR_VARIABLE )
1222     {
1223         if( val.i_int == 1 && b_root ) return true;
1224         else return false;
1225     }
1226
1227     /* Check children variables in case of VLC_VAR_VARIABLE */
1228     if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
1229     {
1230         return true;
1231     }
1232
1233     for( i = 0, i_result = true; i < val_list.p_list->i_count; i++ )
1234     {
1235         if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
1236                     p_object, false ) )
1237         {
1238             i_result = false;
1239             break;
1240         }
1241     }
1242
1243     /* clean up everything */
1244     var_FreeList( &val_list, NULL );
1245
1246     return i_result;
1247 }
1248
1249 #define TEXT_OR_VAR qfue ( text.psz_string ? text.psz_string : psz_var )
1250
1251 void VLCMenuBar::UpdateItem( intf_thread_t *p_intf, QMenu *menu,
1252         const char *psz_var, vlc_object_t *p_object, bool b_submenu )
1253 {
1254     vlc_value_t val, text;
1255     int i_type;
1256
1257     QAction *action = FindActionWithVar( menu, psz_var );
1258     if( action )
1259         DeleteNonStaticEntries( action->menu() );
1260
1261     if( !p_object )
1262     {
1263         if( action )
1264             action->setEnabled( false );
1265         return;
1266     }
1267
1268     /* Check the type of the object variable */
1269     /* This HACK is needed so we have a radio button for audio and video tracks
1270        instread of a checkbox */
1271     if( !strcmp( psz_var, "audio-es" )
1272      || !strcmp( psz_var, "video-es" ) )
1273         i_type = VLC_VAR_INTEGER | VLC_VAR_HASCHOICE;
1274     else
1275         i_type = var_Type( p_object, psz_var );
1276
1277     switch( i_type & VLC_VAR_TYPE )
1278     {
1279         case VLC_VAR_VOID:
1280         case VLC_VAR_BOOL:
1281         case VLC_VAR_VARIABLE:
1282         case VLC_VAR_STRING:
1283         case VLC_VAR_INTEGER:
1284         case VLC_VAR_FLOAT:
1285             break;
1286         default:
1287             /* Variable doesn't exist or isn't handled */
1288             if( action )
1289                 action->setEnabled( false );
1290             return;
1291     }
1292
1293     /* Make sure we want to display the variable */
1294     if( menu->isEmpty() && IsMenuEmpty( psz_var, p_object ) )
1295     {
1296         if( action )
1297             action->setEnabled( false );
1298         return;
1299     }
1300
1301     /* Get the descriptive name of the variable */
1302     int i_ret = var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
1303     if( i_ret != VLC_SUCCESS )
1304     {
1305         text.psz_string = NULL;
1306     }
1307
1308     if( !action )
1309     {
1310         action = new QAction( TEXT_OR_VAR, menu );
1311         menu->addAction( action );
1312         action->setData( psz_var );
1313     }
1314
1315     /* Some specific stuff */
1316     bool forceDisabled = false;
1317     if( !strcmp( psz_var, "spu-es" ) )
1318     {
1319         vout_thread_t *p_vout = THEMIM->getVout();
1320         forceDisabled = ( p_vout == NULL );
1321         if( p_vout )
1322             vlc_object_release( p_vout );
1323     }
1324
1325     if( i_type & VLC_VAR_HASCHOICE )
1326     {
1327         /* Append choices menu */
1328         if( b_submenu )
1329         {
1330             QMenu *submenu;
1331             submenu = action->menu();
1332             if( !submenu )
1333             {
1334                 submenu = new QMenu( menu );
1335                 action->setMenu( submenu );
1336             }
1337
1338             action->setEnabled(
1339                CreateChoicesMenu( submenu, psz_var, p_object, true ) == 0 );
1340             if( forceDisabled )
1341                 action->setEnabled( false );
1342         }
1343         else
1344         {
1345             action->setEnabled(
1346                 CreateChoicesMenu( menu, psz_var, p_object, true ) == 0 );
1347         }
1348         FREENULL( text.psz_string );
1349         return;
1350     }
1351
1352     switch( i_type & VLC_VAR_TYPE )
1353     {
1354         case VLC_VAR_VOID:
1355             val.i_int = 0;  // Prevent the copy of an uninitialized value
1356             CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_NORMAL,
1357                     p_object, val, i_type );
1358             break;
1359
1360         case VLC_VAR_BOOL:
1361             var_Get( p_object, psz_var, &val );
1362             val.b_bool = !val.b_bool;
1363             CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_CHECK,
1364                     p_object, val, i_type, !val.b_bool );
1365             break;
1366     }
1367     FREENULL( text.psz_string );
1368 }
1369
1370 #undef TEXT_OR_VAR
1371
1372 /** HACK for the navigation submenu:
1373  * "title %2i" variables take the value 0 if not set
1374  */
1375 static bool CheckTitle( vlc_object_t *p_object, const char *psz_var )
1376 {
1377     int i_title = 0;
1378     if( sscanf( psz_var, "title %2i", &i_title ) <= 0 )
1379         return true;
1380
1381     int i_current_title = var_GetInteger( p_object, "title" );
1382     return ( i_title == i_current_title );
1383 }
1384
1385
1386 int VLCMenuBar::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
1387         vlc_object_t *p_object, bool b_root )
1388 {
1389     vlc_value_t val, val_list, text_list;
1390     int i_type, i;
1391
1392     /* Check the type of the object variable */
1393     i_type = var_Type( p_object, psz_var );
1394
1395     /* Make sure we want to display the variable */
1396     if( submenu->isEmpty() && IsMenuEmpty( psz_var, p_object, b_root ) )
1397         return VLC_EGENERIC;
1398
1399     switch( i_type & VLC_VAR_TYPE )
1400     {
1401         case VLC_VAR_VOID:
1402         case VLC_VAR_BOOL:
1403         case VLC_VAR_VARIABLE:
1404         case VLC_VAR_STRING:
1405         case VLC_VAR_INTEGER:
1406         case VLC_VAR_FLOAT:
1407             break;
1408         default:
1409             /* Variable doesn't exist or isn't handled */
1410             return VLC_EGENERIC;
1411     }
1412
1413     if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
1414                     &val_list, &text_list ) < 0 )
1415     {
1416         return VLC_EGENERIC;
1417     }
1418
1419 #define CURVAL val_list.p_list->p_values[i]
1420 #define CURTEXT text_list.p_list->p_values[i].psz_string
1421 #define RADIO_OR_COMMAND  ( i_type & ( VLC_VAR_ISCOMMAND | VLC_VAR_HASCHOICE ) ) ? ITEM_RADIO : ITEM_NORMAL
1422
1423     for( i = 0; i < val_list.p_list->i_count; i++ )
1424     {
1425         vlc_value_t another_val;
1426         QString menutext;
1427         QMenu *subsubmenu = new QMenu( submenu );
1428
1429         switch( i_type & VLC_VAR_TYPE )
1430         {
1431             case VLC_VAR_VARIABLE:
1432                 CreateChoicesMenu( subsubmenu, CURVAL.psz_string, p_object, false );
1433                 subsubmenu->setTitle( qfue( CURTEXT ? CURTEXT :CURVAL.psz_string ) );
1434                 submenu->addMenu( subsubmenu );
1435                 break;
1436
1437             case VLC_VAR_STRING:
1438                 var_Get( p_object, psz_var, &val );
1439                 another_val.psz_string = strdup( CURVAL.psz_string );
1440                 menutext = qfue( CURTEXT ? CURTEXT : another_val.psz_string );
1441                 CreateAndConnect( submenu, psz_var, menutext, "", RADIO_OR_COMMAND,
1442                         p_object, another_val, i_type,
1443                         val.psz_string && !strcmp( val.psz_string, CURVAL.psz_string ) );
1444
1445                 free( val.psz_string );
1446                 break;
1447
1448             case VLC_VAR_INTEGER:
1449                 var_Get( p_object, psz_var, &val );
1450                 if( CURTEXT ) menutext = qfue( CURTEXT );
1451                 else menutext = QString::number( CURVAL.i_int );
1452                 CreateAndConnect( submenu, psz_var, menutext, "", RADIO_OR_COMMAND,
1453                         p_object, CURVAL, i_type,
1454                         ( CURVAL.i_int == val.i_int )
1455                         && CheckTitle( p_object, psz_var ) );
1456                 break;
1457
1458             case VLC_VAR_FLOAT:
1459                 var_Get( p_object, psz_var, &val );
1460                 if( CURTEXT ) menutext = qfue( CURTEXT );
1461                 else menutext.sprintf( "%.2f", CURVAL.f_float );
1462                 CreateAndConnect( submenu, psz_var, menutext, "", RADIO_OR_COMMAND,
1463                         p_object, CURVAL, i_type,
1464                         CURVAL.f_float == val.f_float );
1465                 break;
1466
1467             default:
1468                 break;
1469         }
1470     }
1471     currentGroup = NULL;
1472
1473     /* clean up everything */
1474     var_FreeList( &val_list, &text_list );
1475
1476 #undef RADIO_OR_COMMAND
1477 #undef CURVAL
1478 #undef CURTEXT
1479
1480     return submenu->isEmpty() ? VLC_EGENERIC : VLC_SUCCESS;
1481 }
1482
1483 void VLCMenuBar::CreateAndConnect( QMenu *menu, const char *psz_var,
1484         const QString& text, const QString& help,
1485         int i_item_type, vlc_object_t *p_obj,
1486         vlc_value_t val, int i_val_type,
1487         bool checked )
1488 {
1489     QAction *action = FindActionWithVar( menu, psz_var );
1490
1491     bool b_new = false;
1492     if( !action )
1493     {
1494         action = new QAction( text, menu );
1495         menu->addAction( action );
1496         b_new = true;
1497     }
1498
1499     action->setToolTip( help );
1500     action->setEnabled( p_obj != NULL );
1501
1502     if( i_item_type == ITEM_CHECK )
1503     {
1504         action->setCheckable( true );
1505     }
1506     else if( i_item_type == ITEM_RADIO )
1507     {
1508         action->setCheckable( true );
1509         if( !currentGroup )
1510             currentGroup = new QActionGroup( menu );
1511         currentGroup->addAction( action );
1512     }
1513
1514     action->setChecked( checked );
1515
1516     MenuItemData *itemData = qFindChild<MenuItemData*>( action, QString() );
1517     delete itemData;
1518     itemData = new MenuItemData( action, p_obj, i_val_type, val, psz_var );
1519
1520     /* remove previous signal-slot connection(s) if any */
1521     action->disconnect( );
1522
1523     CONNECT( action, triggered(), THEDP->menusMapper, map() );
1524     THEDP->menusMapper->setMapping( action, itemData );
1525
1526     if( b_new )
1527         menu->addAction( action );
1528 }
1529
1530 void VLCMenuBar::DoAction( QObject *data )
1531 {
1532     MenuItemData *itemData = qobject_cast<MenuItemData *>( data );
1533     vlc_object_t *p_object = itemData->p_obj;
1534     if( p_object == NULL ) return;
1535     const char *var = itemData->psz_var;
1536     vlc_value_t val = itemData->val;
1537
1538     /* Preserve settings across vouts via the playlist object: */
1539     if( !strcmp( var, "fullscreen" )
1540      || !strcmp( var, "video-on-top" ) )
1541         var_Set( pl_Get( p_object ), var, val );
1542
1543     if ((var_Type( p_object, var) & VLC_VAR_CLASS) == VLC_VAR_VOID)
1544         var_TriggerCallback( p_object, var );
1545     else
1546         var_Set( p_object, var, val );
1547 }
1548
1549 void VLCMenuBar::updateAudioDevice( intf_thread_t * p_intf, audio_output_t *p_aout, QMenu *current )
1550 {
1551     char **ids, **names;
1552     char *selected;
1553
1554     if( !p_aout )
1555         return;
1556
1557     current->clear();
1558     int i_result = aout_DevicesList( p_aout, &ids, &names);
1559     selected = aout_DeviceGet( p_aout );
1560
1561     QActionGroup *actionGroup = new QActionGroup(current);
1562     QAction *action;
1563
1564     for( int i = 0; i < i_result; i++ )
1565     {
1566         action = new QAction( qfue( names[i] ), NULL );
1567         action->setData( ids[i] );
1568         action->setCheckable( true );
1569         if( selected && !strcmp( ids[i], selected ) )
1570             action->setChecked( true );
1571         actionGroup->addAction( action );
1572         current->addAction( action );
1573         CONNECT(action, changed(), THEMIM->menusAudioMapper, map());
1574         THEMIM->menusAudioMapper->setMapping(action, ids[i]);
1575         free( ids[i] );
1576         free( names[i] );
1577     }
1578     free( ids );
1579     free( names );
1580     free( selected );
1581 }
1582
1583 void VLCMenuBar::updateRecents( intf_thread_t *p_intf )
1584 {
1585     if( recentsMenu )
1586     {
1587         QAction* action;
1588         RecentsMRL* rmrl = RecentsMRL::getInstance( p_intf );
1589         QStringList l = rmrl->recents();
1590
1591         recentsMenu->clear();
1592
1593         if( !l.count() )
1594         {
1595             recentsMenu->setEnabled( false );
1596         }
1597         else
1598         {
1599             for( int i = 0; i < l.count(); ++i )
1600             {
1601                 QString mrl = l.at( i );
1602                 char *psz = decode_URI_duplicate( qtu( mrl ) );
1603                 QString text = qfu( psz );
1604
1605                 free( psz );
1606                 action = recentsMenu->addAction(
1607                         QString( i < 9 ? "&%1: ": "%1: " ).arg( i + 1 ) +
1608                             QApplication::fontMetrics().elidedText( text,
1609                                                           Qt::ElideLeft, 400 ),
1610                         rmrl->signalMapper, SLOT( map() ),
1611                         i < 9 ? QString( "Ctrl+%1" ).arg( i + 1 ) : "" );
1612                 rmrl->signalMapper->setMapping( action, l.at( i ) );
1613             }
1614
1615             recentsMenu->addSeparator();
1616             recentsMenu->addAction( qtr("&Clear"), rmrl, SLOT( clear() ) );
1617             recentsMenu->setEnabled( true );
1618         }
1619     }
1620 }