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