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