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