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