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