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