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