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