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