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