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