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