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