]> git.sesse.net Git - vlc/blob - modules/gui/qt4/menus.cpp
Qt4: find skins interface by name
[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
499     AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
500
501     if( p_aout )
502         vlc_object_release( p_aout );
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     p_vout = THEMIM->getVout();
551
552     VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
553
554     if( p_vout )
555         vlc_object_release( p_vout );
556     if( p_input )
557         vlc_object_release( p_input );
558
559     return Populate( p_intf, current, varnames, objects );
560 }
561
562 /**
563  * Navigation Menu
564  * For DVD, MP4, MOV and other chapter based format
565  **/
566 QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *menu )
567 {
568     if( !menu ) menu = new QMenu();
569
570     if( menu->isEmpty() )
571     {
572         addDPStaticEntry( menu, qtr( I_MENU_GOTOTIME ),"",
573                           SLOT( gotoTimeDialog() ), "Ctrl+T" );
574         menu->addSeparator();
575
576         ACT_ADD( menu, "bookmark", qtr( "&Bookmarks" ) );
577         ACT_ADD( menu, "title", qtr( "T&itle" ) );
578         ACT_ADD( menu, "chapter", qtr( "&Chapter" ) );
579         ACT_ADD( menu, "program", qtr( "&Program" ) );
580         ACT_ADD( menu, "navigation", qtr( "&Navigation" ) );
581     }
582
583     input_thread_t *p_object;
584     vector<vlc_object_t *> objects;
585     vector<const char *> varnames;
586
587     p_object = THEMIM->getInput();
588     InputAutoMenuBuilder( p_object, objects, varnames );
589     PUSH_VAR( "prev-title" );
590     PUSH_VAR( "next-title" );
591     PUSH_VAR( "prev-chapter" );
592     PUSH_VAR( "next-chapter" );
593     EnableDPStaticEntries( menu, ( p_object != NULL ) );
594     if( p_object )
595     {
596         vlc_object_release( p_object );
597     }
598     return Populate( p_intf, menu, varnames, objects );
599 }
600
601 /**
602  * Service Discovery SubMenu
603  **/
604 QMenu *QVLCMenu::SDMenu( intf_thread_t *p_intf )
605 {
606     QMenu *menu = new QMenu();
607     menu->setTitle( qtr( I_PL_SD ) );
608     char **ppsz_longnames;
609     char **ppsz_names = vlc_sd_GetNames( &ppsz_longnames );
610     if( !ppsz_names )
611         return menu;
612
613     char **ppsz_name = ppsz_names, **ppsz_longname = ppsz_longnames;
614     for( ; *ppsz_name; ppsz_name++, ppsz_longname++ )
615     {
616         QAction *a = new QAction( qfu( *ppsz_longname ), menu );
617         a->setCheckable( true );
618         if( playlist_IsServicesDiscoveryLoaded( THEPL, *ppsz_name ) )
619             a->setChecked( true );
620         CONNECT( a , triggered(), THEDP->SDMapper, map() );
621         THEDP->SDMapper->setMapping( a, QString( *ppsz_name ) );
622         menu->addAction( a );
623
624         if( !strcmp( *ppsz_name, "podcast" ) )
625         {
626             QAction *b = new QAction( qtr( "Configure podcasts..." ), menu );
627             //b->setEnabled( a->isChecked() );
628             menu->addAction( b );
629             CONNECT( b, triggered(), THEDP, podcastConfigureDialog() );
630         }
631         free( *ppsz_name );
632         free( *ppsz_longname );
633     }
634     free( ppsz_names );
635     free( ppsz_longnames );
636     return menu;
637 }
638 /**
639  * Help/About Menu
640 **/
641 QMenu *QVLCMenu::HelpMenu( QMenu *current )
642 {
643     QMenu *menu = new QMenu( current );
644     addDPStaticEntry( menu, qtr( "&Help..." ) ,
645         ":/help", SLOT( helpDialog() ), "F1" );
646 #ifdef UPDATE_CHECK
647     addDPStaticEntry( menu, qtr( "Check for &Updates..." ) , "",
648                       SLOT( updateDialog() ) );
649 #endif
650     menu->addSeparator();
651     addDPStaticEntry( menu, qtr( I_MENU_ABOUT ), ":/info",
652             SLOT( aboutDialog() ), "Shift+F1" );
653     return menu;
654 }
655
656 /*****************************************************************************
657  * Popup menus - Right Click menus                                           *
658  *****************************************************************************/
659 #define POPUP_BOILERPLATE \
660     unsigned int i_last_separator = 0; \
661     vector<vlc_object_t *> objects; \
662     vector<const char *> varnames; \
663     input_thread_t *p_input = THEMIM->getInput();
664
665 #define CREATE_POPUP \
666     Populate( p_intf, menu, varnames, objects ); \
667     p_intf->p_sys->p_popup_menu = menu; \
668     menu->popup( QCursor::pos() ); \
669     p_intf->p_sys->p_popup_menu = NULL; \
670     i_last_separator = 0;
671
672 void QVLCMenu::PopupMenuControlEntries( QMenu *menu,
673                                         intf_thread_t *p_intf,
674                                         input_thread_t *p_input )
675 {
676     if( p_input )
677     {
678         vlc_value_t val;
679         var_Get( p_input, "state", &val );
680         if( val.i_int == PLAYING_S )
681             addMIMStaticEntry( p_intf, menu, qtr( "Pause" ),
682                     ":/pause", SLOT( togglePlayPause() ) );
683         else
684             addMIMStaticEntry( p_intf, menu, qtr( "Play" ),
685                     ":/play", SLOT( togglePlayPause() ) );
686     }
687     else if( THEPL->items.i_size )
688         addMIMStaticEntry( p_intf, menu, qtr( "Play" ),
689                 ":/play", SLOT( togglePlayPause() ) );
690     else
691         addDPStaticEntry( menu, qtr( "Play" ),
692                 ":/play", SLOT( openDialog() ) );
693
694     addMIMStaticEntry( p_intf, menu, qtr( "Stop" ),
695             ":/stop", SLOT( stop() ) );
696     addMIMStaticEntry( p_intf, menu, qtr( "Previous" ),
697             ":/previous", SLOT( prev() ) );
698     addMIMStaticEntry( p_intf, menu, qtr( "Next" ),
699             ":/next", SLOT( next() ) );
700 }
701
702 void QVLCMenu::PopupMenuStaticEntries( QMenu *menu )
703 {
704 #if 0
705     QMenu *toolsmenu = ToolsMenu( p_intf, menu, false, true );
706     toolsmenu->setTitle( qtr( "Tools" ) );
707     menu->addMenu( toolsmenu );
708 #endif
709
710     QMenu *openmenu = new QMenu( qtr( "Open" ), menu );
711     addDPStaticEntry( openmenu, qtr( "&Open File..." ),
712         ":/file-asym", SLOT( openFileDialog() ) );
713     addDPStaticEntry( openmenu, qtr( I_OPEN_FOLDER ),
714         ":/folder-grey", SLOT( PLOpenDir() ) );
715     addDPStaticEntry( openmenu, qtr( "Open &Disc..." ),
716         ":/disc", SLOT( openDiscDialog() ) );
717     addDPStaticEntry( openmenu, qtr( "Open &Network..." ),
718         ":/network", SLOT( openNetDialog() ) );
719     addDPStaticEntry( openmenu, qtr( "Open &Capture Device..." ),
720         ":/capture-card", SLOT( openCaptureDialog() ) );
721     menu->addMenu( openmenu );
722
723     menu->addSeparator();
724 #if 0
725     QMenu *helpmenu = HelpMenu( menu );
726     helpmenu->setTitle( qtr( "Help" ) );
727     menu->addMenu( helpmenu );
728 #endif
729
730     addDPStaticEntry( menu, qtr( "Quit" ), ":/quit",
731                       SLOT( quit() ), "Ctrl+Q" );
732 }
733
734 /* Video Tracks and Subtitles tracks */
735 void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf )
736 {
737     POPUP_BOILERPLATE;
738     if( p_input )
739     {
740         vlc_object_hold( p_input );
741         vout_thread_t *p_vout = THEMIM->getVout();
742         if( p_vout )
743         {
744             VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
745             vlc_object_release( p_vout );
746         }
747         vlc_object_release( p_input );
748     }
749     QMenu *menu = new QMenu();
750     CREATE_POPUP;
751 }
752
753 /* Audio Tracks */
754 void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf )
755 {
756     POPUP_BOILERPLATE;
757     if( p_input )
758     {
759         vlc_object_hold( p_input );
760         aout_instance_t *p_aout = THEMIM->getAout();
761         AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
762         if( p_aout )
763             vlc_object_release( p_aout );
764         vlc_object_release( p_input );
765     }
766     QMenu *menu = new QMenu();
767     CREATE_POPUP;
768 }
769
770 /* Navigation stuff, and general menus ( open ) */
771 void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf )
772 {
773     POPUP_BOILERPLATE;
774
775     if( p_input )
776     {
777         vlc_object_hold( p_input );
778         varnames.push_back( "audio-es" );
779         InputAutoMenuBuilder( p_input, objects, varnames );
780         PUSH_SEPARATOR;
781     }
782
783     QMenu *menu = new QMenu();
784     Populate( p_intf, menu, varnames, objects );
785
786     menu->addSeparator();
787     PopupMenuControlEntries( menu, p_intf, p_input );
788
789     menu->addSeparator();
790     PopupMenuStaticEntries( menu );
791
792     p_intf->p_sys->p_popup_menu = menu;
793     menu->popup( QCursor::pos() );
794     p_intf->p_sys->p_popup_menu = NULL;
795 }
796
797 /* Main Menu that sticks everything together  */
798 void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show )
799 {
800     MainInterface *mi = p_intf->p_sys->p_mi;
801     if( show )
802     {
803         /* Delete and recreate a popup if there is one */
804         if( p_intf->p_sys->p_popup_menu )
805             delete p_intf->p_sys->p_popup_menu;
806
807         QMenu *menu = new QMenu();
808         QMenu *submenu;
809         QAction *action;
810         bool b_isFullscreen = false;
811
812         POPUP_BOILERPLATE;
813
814         PopupMenuControlEntries( menu, p_intf, p_input );
815         menu->addSeparator();
816
817         if( p_input )
818         {
819             vout_thread_t *p_vout = THEMIM->getVout();
820
821             /* Add a fullscreen switch button */
822             if( p_vout )
823             {
824                 vlc_value_t val;
825                 var_Get( p_vout, "fullscreen", &val );
826                 b_isFullscreen = !( !val.b_bool );
827                 if( b_isFullscreen )
828                     CreateAndConnect( menu, "fullscreen",
829                             qtr( "Leave Fullscreen" ),"" , ITEM_NORMAL,
830                             VLC_OBJECT(p_vout), val, VLC_VAR_BOOL,
831                             b_isFullscreen );
832                 vlc_object_release( p_vout );
833             }
834
835             menu->addSeparator();
836
837             vlc_object_hold( p_input );
838             InputAutoMenuBuilder( p_input, objects, varnames );
839             vlc_object_release( p_input );
840
841             submenu = new QMenu( menu );
842             action = menu->addMenu( AudioMenu( p_intf, submenu ) );
843             action->setText( qtr( "&Audio" ) );
844             if( action->menu()->isEmpty() )
845                 action->setEnabled( false );
846
847             submenu = new QMenu( menu );
848             action = menu->addMenu( VideoMenu( p_intf, submenu ) );
849             action->setText( qtr( "&Video" ) );
850             if( action->menu()->isEmpty() )
851                 action->setEnabled( false );
852
853             submenu = new QMenu( menu );
854             action = menu->addMenu( NavigMenu( p_intf, submenu ) );
855             action->setText( qtr( "&Playback" ) );
856             if( action->menu()->isEmpty() )
857                 action->setEnabled( false );
858         }
859
860         menu->addSeparator();
861
862         /* Add some special entries for windowed mode: Interface Menu */
863         if( !b_isFullscreen )
864         {
865             submenu = new QMenu( qtr( "Interface" ), menu );
866             if( mi )
867             {
868                 submenu->addAction( QIcon( ":/playlist" ),
869                          qtr( "Show Playlist" ), mi, SLOT( togglePlaylist() ) );
870             }
871             addDPStaticEntry( submenu, qtr( I_MENU_EXT ),
872                 ":/settings", SLOT( extendedDialog() ) );
873             addDPStaticEntry( submenu, qtr( I_MENU_INFO ) , ":/info",
874                 SLOT( mediaInfoDialog() ), "Ctrl+I" );
875             if( mi )
876             {
877                 action = submenu->addAction( QIcon( "" ),
878                      qtr( "Minimal View" ), mi, SLOT( toggleMinimalView() ) );
879                 action->setCheckable( true );
880                 action->setChecked( !( mi->getControlsVisibilityStatus() &
881                             CONTROLS_VISIBLE ) );
882                 action = submenu->addAction( QIcon( "" ),
883                         qtr( "Toggle Fullscreen Interface" ),
884                         mi, SLOT( toggleFullScreen() ) );
885                 action->setCheckable( true );
886                 action->setChecked( mi->isFullScreen() );
887             }
888             else /* We are using the skins interface.
889                     If not, this entry will not show. */
890             {
891                 addDPStaticEntry( submenu, qtr( "&Preferences..." ),
892                     ":/preferences", SLOT( prefsDialog() ), "Ctrl+P" );
893                 submenu->addSeparator();
894                 objects.clear();
895                 varnames.clear();
896                 vlc_object_t *p_object = ( vlc_object_t* )
897                      vlc_object_find_name( p_intf, "skins2", FIND_PARENT );
898                 if( p_object )
899                 {
900                     objects.push_back( p_object );
901                     varnames.push_back( "intf-skins" );
902                     Populate( p_intf, submenu, varnames, objects );
903                     vlc_object_release( p_object );
904                 }
905                 else
906                 {
907                     msg_Dbg( p_intf, "could not find parent interface" );
908                 }
909             }
910             menu->addMenu( submenu );
911         }
912
913         PopupMenuStaticEntries( menu );
914
915         p_intf->p_sys->p_popup_menu = menu;
916         p_intf->p_sys->p_popup_menu->popup( QCursor::pos() );
917     }
918     else
919     {
920         // destroy popup if there is one
921         delete p_intf->p_sys->p_popup_menu;
922         p_intf->p_sys->p_popup_menu = NULL;
923     }
924 }
925
926 #undef ACT_ADD
927
928 /************************************************************************
929  * Systray Menu                                                         *
930  ************************************************************************/
931
932 void QVLCMenu::updateSystrayMenu( MainInterface *mi,
933                                   intf_thread_t *p_intf,
934                                   bool b_force_visible )
935 {
936     POPUP_BOILERPLATE;
937
938     /* Get the systray menu and clean it */
939     QMenu *sysMenu = mi->getSysTrayMenu();
940     sysMenu->clear();
941
942     /* Hide / Show VLC and cone */
943     if( mi->isVisible() || b_force_visible )
944     {
945         sysMenu->addAction( QIcon( ":/vlc16.png" ),
946                             qtr( "Hide VLC media player in taskbar" ), mi,
947                             SLOT( toggleUpdateSystrayMenu() ) );
948     }
949     else
950     {
951         sysMenu->addAction( QIcon( ":/vlc16.png" ),
952                             qtr( "Show VLC media player" ), mi,
953                             SLOT( toggleUpdateSystrayMenu() ) );
954     }
955
956     sysMenu->addSeparator();
957     PopupMenuControlEntries( sysMenu, p_intf, p_input );
958
959     sysMenu->addSeparator();
960     addDPStaticEntry( sysMenu, qtr( "&Open Media" ),
961             ":/file-wide", SLOT( openFileDialog() ) );
962     addDPStaticEntry( sysMenu, qtr( "&Quit" ) ,
963             ":/quit", SLOT( quit() ) );
964
965     /* Set the menu */
966     mi->getSysTray()->setContextMenu( sysMenu );
967 }
968
969 #undef PUSH_VAR
970 #undef PUSH_SEPARATOR
971
972 /*************************************************************************
973  * Builders for automenus
974  *************************************************************************/
975 QMenu * QVLCMenu::Populate( intf_thread_t *p_intf,
976                             QMenu *current,
977                             vector< const char *> & varnames,
978                             vector<vlc_object_t *> & objects )
979 {
980     QMenu *menu = current;
981     if( !menu ) menu = new QMenu();
982
983     /* Disable all non static entries */
984     QAction *p_action;
985     foreach( p_action, menu->actions() )
986     {
987         if( p_action->data().toString() != "_static_" )
988             p_action->setEnabled( false );
989     }
990
991     currentGroup = NULL;
992
993     vlc_object_t *p_object;
994     int i;
995
996     for( i = 0; i < ( int )objects.size() ; i++ )
997     {
998         if( !varnames[i] || !*varnames[i] )
999         {
1000             menu->addSeparator();
1001             continue;
1002         }
1003         p_object = objects[i];
1004
1005         UpdateItem( p_intf, menu, varnames[i], p_object, true );
1006     }
1007     return menu;
1008 }
1009
1010 /*****************************************************************************
1011  * Private methods.
1012  *****************************************************************************/
1013
1014 static bool IsMenuEmpty( const char *psz_var,
1015                          vlc_object_t *p_object,
1016                          bool b_root = true )
1017 {
1018     vlc_value_t val, val_list;
1019     int i_type, i_result, i;
1020
1021     /* Check the type of the object variable */
1022     i_type = var_Type( p_object, psz_var );
1023
1024     /* Check if we want to display the variable */
1025     if( !( i_type & VLC_VAR_HASCHOICE ) ) return false;
1026
1027     var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
1028     if( val.i_int == 0 ) return true;
1029
1030     if( ( i_type & VLC_VAR_TYPE ) != VLC_VAR_VARIABLE )
1031     {
1032         if( val.i_int == 1 && b_root ) return true;
1033         else return false;
1034     }
1035
1036     /* Check children variables in case of VLC_VAR_VARIABLE */
1037     if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
1038     {
1039         return true;
1040     }
1041
1042     for( i = 0, i_result = true; i < val_list.p_list->i_count; i++ )
1043     {
1044         if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
1045                     p_object, false ) )
1046         {
1047             i_result = false;
1048             break;
1049         }
1050     }
1051
1052     /* clean up everything */
1053     var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, NULL );
1054
1055     return i_result;
1056 }
1057
1058 #define TEXT_OR_VAR qfu ( text.psz_string ? text.psz_string : psz_var )
1059
1060 void QVLCMenu::UpdateItem( intf_thread_t *p_intf, QMenu *menu,
1061         const char *psz_var, vlc_object_t *p_object, bool b_submenu )
1062 {
1063     vlc_value_t val, text;
1064     int i_type;
1065
1066     QAction *action = FindActionWithVar( menu, psz_var );
1067     if( action )
1068         DeleteNonStaticEntries( action->menu() );
1069
1070     if( !p_object )
1071         return;
1072
1073     /* Check the type of the object variable */
1074     if( !strcmp( psz_var, "audio-es" )
1075      || !strcmp( psz_var, "video-es" )
1076      || !strcmp( psz_var, "postproc-q" ) )
1077         i_type = VLC_VAR_INTEGER | VLC_VAR_HASCHOICE;
1078     else
1079         i_type = var_Type( p_object, psz_var );
1080
1081     switch( i_type & VLC_VAR_TYPE )
1082     {
1083         case VLC_VAR_VOID:
1084         case VLC_VAR_BOOL:
1085         case VLC_VAR_VARIABLE:
1086         case VLC_VAR_STRING:
1087         case VLC_VAR_INTEGER:
1088         case VLC_VAR_FLOAT:
1089             break;
1090         default:
1091             /* Variable doesn't exist or isn't handled */
1092             return;
1093     }
1094
1095     /* Make sure we want to display the variable */
1096     if( menu->isEmpty() && IsMenuEmpty( psz_var, p_object ) )
1097         return;
1098
1099     /* Get the descriptive name of the variable */
1100     int i_ret = var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
1101     if( i_ret != VLC_SUCCESS )
1102     {
1103         text.psz_string = NULL;
1104     }
1105
1106     if( !action )
1107     {
1108         action = new QAction( TEXT_OR_VAR, menu );
1109         menu->addAction( action );
1110         action->setData( psz_var );
1111     }
1112
1113     /* Some specific stuff */
1114     bool forceDisabled = false;
1115     if( !strcmp( psz_var, "spu-es" ) )
1116     {
1117         vout_thread_t *p_vout = THEMIM->getVout();
1118         forceDisabled = ( p_vout == NULL );
1119         if( p_vout )
1120             vlc_object_release( p_vout );
1121     }
1122
1123     if( i_type & VLC_VAR_HASCHOICE )
1124     {
1125         /* Append choices menu */
1126         if( b_submenu )
1127         {
1128             QMenu *submenu;
1129             submenu = action->menu();
1130             if( !submenu )
1131             {
1132                 submenu = new QMenu( menu );
1133                 action->setMenu( submenu );
1134             }
1135
1136             action->setEnabled(
1137                CreateChoicesMenu( submenu, psz_var, p_object, true ) == 0 );
1138             if( forceDisabled )
1139                 action->setEnabled( false );
1140         }
1141         else
1142             CreateChoicesMenu( menu, psz_var, p_object, true );
1143         FREENULL( text.psz_string );
1144         return;
1145     }
1146
1147     switch( i_type & VLC_VAR_TYPE )
1148     {
1149         case VLC_VAR_VOID:
1150             var_Get( p_object, psz_var, &val );
1151             CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_NORMAL,
1152                     p_object, val, i_type );
1153             break;
1154
1155         case VLC_VAR_BOOL:
1156             var_Get( p_object, psz_var, &val );
1157             val.b_bool = !val.b_bool;
1158             CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_CHECK,
1159                     p_object, val, i_type, !val.b_bool );
1160             break;
1161     }
1162     FREENULL( text.psz_string );
1163 }
1164
1165
1166 int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
1167         vlc_object_t *p_object, bool b_root )
1168 {
1169     vlc_value_t val, val_list, text_list;
1170     int i_type, i;
1171
1172     /* Check the type of the object variable */
1173     i_type = var_Type( p_object, psz_var );
1174
1175     /* Make sure we want to display the variable */
1176     if( submenu->isEmpty() && IsMenuEmpty( psz_var, p_object, b_root ) )
1177         return VLC_EGENERIC;
1178
1179     switch( i_type & VLC_VAR_TYPE )
1180     {
1181         case VLC_VAR_VOID:
1182         case VLC_VAR_BOOL:
1183         case VLC_VAR_VARIABLE:
1184         case VLC_VAR_STRING:
1185         case VLC_VAR_INTEGER:
1186         case VLC_VAR_FLOAT:
1187             break;
1188         default:
1189             /* Variable doesn't exist or isn't handled */
1190             return VLC_EGENERIC;
1191     }
1192
1193     if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
1194                     &val_list, &text_list ) < 0 )
1195     {
1196         return VLC_EGENERIC;
1197     }
1198
1199 #define CURVAL val_list.p_list->p_values[i]
1200 #define CURTEXT text_list.p_list->p_values[i].psz_string
1201
1202     for( i = 0; i < val_list.p_list->i_count; i++ )
1203     {
1204         vlc_value_t another_val;
1205         QString menutext;
1206         QMenu *subsubmenu = new QMenu( submenu );
1207
1208         switch( i_type & VLC_VAR_TYPE )
1209         {
1210             case VLC_VAR_VARIABLE:
1211                 CreateChoicesMenu( subsubmenu, CURVAL.psz_string, p_object, false );
1212                 subsubmenu->setTitle( qfu( CURTEXT ? CURTEXT :CURVAL.psz_string ) );
1213                 submenu->addMenu( subsubmenu );
1214                 break;
1215
1216             case VLC_VAR_STRING:
1217                 var_Get( p_object, psz_var, &val );
1218                 another_val.psz_string = strdup( CURVAL.psz_string );
1219                 menutext = qfu( CURTEXT ? CURTEXT : another_val.psz_string );
1220                 CreateAndConnect( submenu, psz_var, menutext, "", ITEM_RADIO,
1221                         p_object, another_val, i_type,
1222                         val.psz_string && !strcmp( val.psz_string, CURVAL.psz_string ) );
1223
1224                 free( val.psz_string );
1225                 break;
1226
1227             case VLC_VAR_INTEGER:
1228                 var_Get( p_object, psz_var, &val );
1229                 if( CURTEXT ) menutext = qfu( CURTEXT );
1230                 else menutext.sprintf( "%d", CURVAL.i_int );
1231                 CreateAndConnect( submenu, psz_var, menutext, "", ITEM_RADIO,
1232                         p_object, CURVAL, i_type,
1233                         CURVAL.i_int == val.i_int );
1234                 break;
1235
1236             case VLC_VAR_FLOAT:
1237                 var_Get( p_object, psz_var, &val );
1238                 if( CURTEXT ) menutext = qfu( CURTEXT );
1239                 else menutext.sprintf( "%.2f", CURVAL.f_float );
1240                 CreateAndConnect( submenu, psz_var, menutext, "", ITEM_RADIO,
1241                         p_object, CURVAL, i_type,
1242                         CURVAL.f_float == val.f_float );
1243                 break;
1244
1245             default:
1246                 break;
1247         }
1248     }
1249     currentGroup = NULL;
1250
1251     /* clean up everything */
1252     var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
1253
1254 #undef CURVAL
1255 #undef CURTEXT
1256     return VLC_SUCCESS;
1257 }
1258
1259 void QVLCMenu::CreateAndConnect( QMenu *menu, const char *psz_var,
1260         QString text, QString help,
1261         int i_item_type, vlc_object_t *p_obj,
1262         vlc_value_t val, int i_val_type,
1263         bool checked )
1264 {
1265     QAction *action = FindActionWithVar( menu, psz_var );
1266     if( !action )
1267     {
1268         action = new QAction( text, menu );
1269         menu->addAction( action );
1270     }
1271
1272     action->setToolTip( help );
1273     action->setEnabled( p_obj != NULL );
1274
1275     if( i_item_type == ITEM_CHECK )
1276     {
1277         action->setCheckable( true );
1278     }
1279     else if( i_item_type == ITEM_RADIO )
1280     {
1281         action->setCheckable( true );
1282         if( !currentGroup )
1283             currentGroup = new QActionGroup( menu );
1284         currentGroup->addAction( action );
1285     }
1286
1287     action->setChecked( checked );
1288
1289     MenuItemData *itemData = new MenuItemData( THEDP->menusMapper, p_obj, i_val_type,
1290             val, psz_var );
1291     CONNECT( action, triggered(), THEDP->menusMapper, map() );
1292     THEDP->menusMapper->setMapping( action, itemData );
1293     menu->addAction( action );
1294 }
1295
1296 void QVLCMenu::DoAction( QObject *data )
1297 {
1298     MenuItemData *itemData = qobject_cast<MenuItemData *>( data );
1299     vlc_object_t *p_object = itemData->p_obj;
1300     if( p_object == NULL ) return;
1301
1302     var_Set( p_object, itemData->psz_var, itemData->val );
1303 }
1304
1305 void QVLCMenu::updateRecents( intf_thread_t *p_intf )
1306 {
1307     if (recentsMenu)
1308     {
1309         QAction* action;
1310         RecentsMRL* rmrl = RecentsMRL::getInstance( p_intf );
1311         QList<QString> l = rmrl->recents();
1312
1313         recentsMenu->clear();
1314         if( !l.size() )
1315         {
1316             action = recentsMenu->addAction( " - Empty - " );
1317             action->setEnabled( false );
1318         }
1319         else
1320         {
1321             for( int i = 0; i < l.size(); ++i )
1322             {
1323                 action = recentsMenu->addAction(
1324                         QString( "&%1: " ).arg( i + 1 ) + l.at( i ),
1325                         rmrl->signalMapper,
1326                         SLOT( map() ) );
1327                 rmrl->signalMapper->setMapping( action, l.at( i ) );
1328             }
1329
1330             recentsMenu->addSeparator();
1331             recentsMenu->addAction( "&Clear", rmrl, SLOT( clear() ) );
1332         }
1333     }
1334 }