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