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