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