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