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