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