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