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