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