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