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