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