root/modules/gui/qt4/menus.cpp

Revision c5ecf50f4a4b42717be5e5cb2d5bd4dcca031ad0, 40.6 kB (checked in by Jean-Baptiste Kempf <jb@videolan.org>, 2 months ago)

Previous strategy to not have to translate does not work.
Too bad. See the French translation for contre-exemple.
Menu accelerator fix.

  • Property mode set to 100644
Line 
1 /*****************************************************************************
2  * menus.cpp : Qt menus
3  *****************************************************************************
4  * Copyright © 2006-2008 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Clément Stenac <zorglub@videolan.org>
8  *          Jean-Baptiste Kempf <jb@videolan.org>
9  *          Jean-Philippe André <jpeg@videolan.org>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * ( at your option ) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24  *****************************************************************************/
25
26 /** \todo
27  * - Remove static currentGroup
28  */
29
30 #ifdef HAVE_CONFIG_H
31 # include "config.h"
32 #endif
33
34 #include <vlc_common.h>
35
36 #include <vlc_intf_strings.h>
37
38 #include "main_interface.hpp"
39 #include "menus.hpp"
40 #include "dialogs_provider.hpp"
41 #include "input_manager.hpp"
42
43 #include <QMenu>
44 #include <QMenuBar>
45 #include <QAction>
46 #include <QActionGroup>
47 #include <QSignalMapper>
48 #include <QSystemTrayIcon>
49
50 /*
51   This file defines the main menus and the pop-up menu (right-click menu)
52   and the systray menu (in that order in the file)
53
54   There are 3 menus that have to be rebuilt everytime there are called:
55   Audio, Video, Navigation
56   3 functions are building those menus: AudioMenu, VideoMenu, NavigMenu
57   and 3 functions associated are collecting the objects :
58   InputAutoMenuBuilder, AudioAutoMenuBuilder, VideoAutoMenuBuilder.
59
60   A QSignalMapper decides when to rebuild those menus cf MenuFunc in the .hpp
61   Just before one of those menus are aboutToShow(), they are rebuild.
62
63
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 // Add static entries to menus
80 void addDPStaticEntry( QMenu *menu,
81                        const QString text,
82                        const char *help,
83                        const char *icon,
84                        const char *member,
85                        const char *shortcut = NULL )
86 {
87     QAction *action = NULL;
88     if( !EMPTY_STR( icon ) > 0 )
89     {
90         if( !EMPTY_STR( shortcut ) > 0 )
91             action = menu->addAction( QIcon( icon ), text, THEDP,
92                                       member, qtr( shortcut ) );
93         else
94             action = menu->addAction( QIcon( icon ), text, THEDP, member );
95     }
96     else
97     {
98         if( !EMPTY_STR( shortcut ) > 0 )
99             action = menu->addAction( text, THEDP, member, qtr( shortcut ) );
100         else
101             action = menu->addAction( text, THEDP, member );
102     }
103     action->setData( "_static_" );
104 }
105
106 void addMIMStaticEntry( intf_thread_t *p_intf,
107                         QMenu *menu,
108                         const QString text,
109                         const char *help,
110                         const char *icon,
111                         const char *member )
112 {
113     if( strlen( icon ) > 0 )
114     {
115         QAction *action = menu->addAction( text, THEMIM,  member );
116         action->setIcon( QIcon( icon ) );
117     }
118     else
119     {
120         menu->addAction( text, THEMIM, member );
121     }
122 }
123
124 void EnableDPStaticEntries( QMenu *menu, bool enable = true )
125 {
126     if( !menu )
127         return;
128
129     QAction *action;
130     foreach( action, menu->actions() )
131     {
132         if( action->data().toString() == "_static_" )
133             action->setEnabled( enable );
134     }
135 }
136
137 /**
138  * \return Number of static entries
139  */
140 int DeleteNonStaticEntries( QMenu *menu )
141 {
142     int i_ret = 0;
143     QAction *action;
144     if( !menu )
145         return VLC_EGENERIC;
146     foreach( action, menu->actions() )
147     {
148         if( action->data().toString() != "_static_" )
149             delete action;
150         else
151             i_ret++;
152     }
153 }
154
155 /*****************************************************************************
156  * Definitions of variables for the dynamic menus
157  *****************************************************************************/
158 #define PUSH_VAR( var ) varnames.push_back( var ); \
159     objects.push_back( VLC_OBJECT(p_object) )
160
161 #define PUSH_INPUTVAR( var ) varnames.push_back( var ); \
162     objects.push_back( VLC_OBJECT(p_input) );
163
164 #define PUSH_SEPARATOR if( objects.size() != i_last_separator ) { \
165     objects.push_back( 0 ); varnames.push_back( "" ); \
166     i_last_separator = objects.size(); }
167
168 static int InputAutoMenuBuilder( vlc_object_t *p_object,
169         vector<vlc_object_t *> &objects,
170         vector<const char *> &varnames )
171 {
172     PUSH_VAR( "bookmark" );
173     PUSH_VAR( "title" );
174     PUSH_VAR( "chapter" );
175     PUSH_VAR( "program" );
176     PUSH_VAR( "navigation" );
177     PUSH_VAR( "dvd_menus" );
178     return VLC_SUCCESS;
179 }
180
181 static int VideoAutoMenuBuilder( vlc_object_t *p_object,
182         input_thread_t *p_input,
183         vector<vlc_object_t *> &objects,
184         vector<const char *> &varnames )
185 {
186     PUSH_INPUTVAR( "video-es" );
187     PUSH_INPUTVAR( "spu-es" );
188     PUSH_VAR( "fullscreen" );
189     PUSH_VAR( "zoom" );
190     PUSH_VAR( "deinterlace" );
191     PUSH_VAR( "aspect-ratio" );
192     PUSH_VAR( "crop" );
193     PUSH_VAR( "video-on-top" );
194 #ifdef WIN32
195     PUSH_VAR( "directx-wallpaper" );
196 #endif
197     PUSH_VAR( "video-snapshot" );
198
199     if( p_object )
200     {
201         /* p_object is the vout, so the decoder is our parent and the
202          * postproc filter one of the decoder's children */
203         vlc_object_t *p_dec = (vlc_object_t *)
204                               vlc_object_find( p_object, VLC_OBJECT_DECODER,
205                                                FIND_PARENT );
206         if( p_dec )
207         {
208             vlc_object_t *p_pp = (vlc_object_t *)
209                                  vlc_object_find_name( p_dec, "postproc",
210                                                        FIND_CHILD );
211             if( p_pp )
212             {
213                 p_object = p_pp;
214                 PUSH_VAR( "postproc-q" );
215                 vlc_object_release( p_pp );
216             }
217
218             vlc_object_release( p_dec );
219         }
220     }
221     return VLC_SUCCESS;
222 }
223
224 static int AudioAutoMenuBuilder( vlc_object_t *p_object,
225         input_thread_t *p_input,
226         vector<vlc_object_t *> &objects,
227         vector<const char *> &varnames )
228 {
229     PUSH_INPUTVAR( "audio-es" );
230     PUSH_VAR( "audio-device" );
231     PUSH_VAR( "audio-channels" );
232     PUSH_VAR( "visual" );
233     return VLC_SUCCESS;
234 }
235
236 static QAction * FindActionWithVar( QMenu *menu, const char *psz_var )
237 {
238     QAction *action;
239     foreach( action, menu->actions() )
240     {
241         if( action->data().toString() == psz_var )
242             return action;
243     }
244     return NULL;
245 }
246
247 /*****************************************************************************
248  * All normal menus
249  * Simple Code
250  *****************************************************************************/
251
252 #define BAR_ADD( func, title ) { \
253     QMenu *_menu = func; _menu->setTitle( title ); bar->addMenu( _menu ); }
254
255 #define BAR_DADD( func, title, id ) { \
256     QMenu *_menu = func; _menu->setTitle( title ); bar->addMenu( _menu ); \
257     MenuFunc *f = new MenuFunc( _menu, id ); \
258     CONNECT( _menu, aboutToShow(), THEDP->menusUpdateMapper, map() ); \
259     THEDP->menusUpdateMapper->setMapping( _menu, f ); }
260
261 #define ACT_ADD( _menu, val, title ) { \
262     QAction *_action = new QAction( title, _menu ); _action->setData( val ); \
263     _menu->addAction( _action ); }
264
265 /**
266  * Main Menu Bar Creation
267  **/
268 void QVLCMenu::createMenuBar( MainInterface *mi,
269                               intf_thread_t *p_intf,
270                               bool visual_selector_enabled )
271 {
272     /* QMainWindows->menuBar()
273        gives the QProcess::destroyed timeout issue on Cleanlooks style with
274        setDesktopAware set to false */
275     QMenuBar *bar = mi->menuBar();
276     BAR_ADD( FileMenu(), qtr( "&Media" ) );
277
278     BAR_DADD( AudioMenu( p_intf, NULL ), qtr( "&Audio" ), 1 );
279     BAR_DADD( VideoMenu( p_intf, NULL ), qtr( "&Video" ), 2 );
280     BAR_DADD( NavigMenu( p_intf, NULL ), qtr( "P&layback" ), 3 );
281
282     BAR_ADD( PlaylistMenu( p_intf, mi ), qtr( "&Playlist" ) );
283     BAR_ADD( ToolsMenu( p_intf, NULL, mi, visual_selector_enabled, true ),
284              qtr( "&Tools" ) );
285
286     BAR_ADD( HelpMenu( NULL ), qtr( "&Help" ) );
287 }
288 #undef BAR_ADD
289 #undef BAR_DADD
290
291 /**
292  * Media ( File ) Menu
293  * Opening, streaming and quit
294  **/
295 QMenu *QVLCMenu::FileMenu()
296 {
297     QMenu *menu = new QMenu();
298
299     addDPStaticEntry( menu, qtr( "&Open File..." ), "",
300 #ifdef WIN32
301         ":/file-asym", SLOT( simpleOpenDialog() ), "Ctrl+O" );
302     addDPStaticEntry( menu, qtr( "Advanced Open File..." ), "",
303         ":/file-asym", SLOT( openFileDialog() ), "" );
304 #else
305         ":/file-asym", SLOT( openFileDialog() ), "Ctrl+0" );
306 #endif
307     addDPStaticEntry( menu, qtr( I_OPEN_FOLDER ), "",
308         ":/folder-grey", SLOT( PLOpenDir() ), "Ctrl+F" );
309     addDPStaticEntry( menu, qtr( "Open &Disc..." ), "",
310         ":/disc", SLOT( openDiscDialog() ), "Ctrl+D" );
311     addDPStaticEntry( menu, qtr( "Open &Network..." ), "",
312         ":/network", SLOT( openNetDialog() ), "Ctrl+N" );
313     addDPStaticEntry( menu, qtr( "Open &Capture Device..." ), "",
314         ":/capture-card", SLOT( openCaptureDialog() ),
315         "Ctrl+C" );
316     menu->addSeparator();
317
318     addDPStaticEntry( menu, qtr( "Conve&rt / Save..." ), "", "",
319         SLOT( openThenTranscodingDialogs() ), "Ctrl+R" );
320     addDPStaticEntry( menu, qtr( "&Streaming..." ), "",
321         ":/stream", SLOT( openThenStreamingDialogs() ),
322         "Ctrl+S" );
323     menu->addSeparator();
324
325     addDPStaticEntry( menu, qtr( "&Quit" ) , "",
326         ":/quit", SLOT( quit() ), "Ctrl+Q" );
327     return menu;
328 }
329
330 /* Playlist/MediaLibrary Control */
331 QMenu *QVLCMenu::PlaylistMenu( intf_thread_t *p_intf, MainInterface *mi )
332 {
333     QMenu *menu = new QMenu();
334     menu->addMenu( SDMenu( p_intf ) );
335     menu->addAction( QIcon( ":/playlist_menu" ),
336                      qtr( "Show P&laylist" ), mi, SLOT( togglePlaylist() ) );
337     menu->addSeparator();
338
339     addDPStaticEntry( menu, qtr( I_PL_LOAD ), "", "", SLOT( openAPlaylist() ),
340         "Ctrl+X" );
341     addDPStaticEntry( menu, qtr( I_PL_SAVE ), "", "", SLOT( saveAPlaylist() ),
342         "Ctrl+Y" );
343     /*menu->addSeparator();
344     menu->addAction( qtr( "Undock from Interface" ), mi,
345                      SLOT( undockPlaylist() ), qtr( "Ctrl+U" ) );*/
346     return menu;
347 }
348
349 /**
350  * Tools/View Menu
351  * This is kept in the same menu for now, but could change if it gets much
352  * longer.
353  * This menu can be an interface menu but also a right click menu.
354  **/
355 QMenu *QVLCMenu::ToolsMenu( intf_thread_t *p_intf,
356                             QMenu *current,
357                             MainInterface *mi,
358                             bool visual_selector_enabled,
359                             bool with_intf )
360 {
361     QMenu *menu = new QMenu( current );
362     if( mi )
363     {
364         QAction *act=
365             menu->addAction( QIcon( ":/playlist_menu" ), qtr( "Play&list..." ),
366                     mi, SLOT( togglePlaylist() ), qtr( "Ctrl+L" ) );
367         act->setData( "_static_" );
368     }
369     addDPStaticEntry( menu, qtr( I_MENU_EXT ), "", ":/settings",
370             SLOT( extendedDialog() ), "Ctrl+E" );
371
372     menu->addSeparator();
373
374     if( with_intf )
375     {
376         QMenu *intfmenu = InterfacesMenu( p_intf, menu );
377         MenuFunc *f = new MenuFunc( intfmenu, 4 );
378         CONNECT( intfmenu, aboutToShow(), THEDP->menusUpdateMapper, map() );
379         THEDP->menusUpdateMapper->setMapping( intfmenu, f );
380         menu->addSeparator();
381     }
382     if( mi )
383     {
384         /* Minimal View */
385         QAction *action = menu->addAction( qtr( "Mi&nimal View" ), mi,
386                                 SLOT( toggleMinimalView() ), qtr( "Ctrl+H" ) );
387         action->setCheckable( true );
388         action->setData( "_static_" );
389         if( mi->getControlsVisibilityStatus() & CONTROLS_VISIBLE )
390             action->setChecked( true );
391         minimalViewAction = action; /* HACK for minimalView */
392
393         /* FullScreen View */
394         action = menu->addAction( qtr( "&Fullscreen Interface" ), mi,
395                                   SLOT( toggleFullScreen() ), QString( "F11" ) );
396         action->setCheckable( true );
397         action->setData( "_static_" );
398
399         /* Advanced Controls */
400         action = menu->addAction( qtr( "&Advanced Controls" ), mi,
401                                   SLOT( toggleAdvanced() ) );
402         action->setCheckable( true );
403         action->setData( "_static_" );
404         if( mi->getControlsVisibilityStatus() & CONTROLS_ADVANCED )
405             action->setChecked( true );
406 #if 0 /* For Visualisations. Not yet working */
407         adv = menu->addAction( qtr( "Visualizations selector" ),
408                 mi, SLOT( visual() ) );
409         adv->setCheckable( true );
410         if( visual_selector_enabled ) adv->setChecked( true );
411 #endif
412     }
413
414     menu->addSeparator();
415
416     addDPStaticEntry( menu, qtr( I_MENU_MSG ), "",
417         ":/messages", SLOT( messagesDialog() ),
418         "Ctrl+M" );
419     addDPStaticEntry( menu, qtr( I_MENU_INFO ) , "", ":/info",
420         SLOT( mediaInfoDialog() ), "Ctrl+I" );
421     addDPStaticEntry( menu, qtr( I_MENU_CODECINFO ) , "",
422         ":/info", SLOT( mediaCodecDialog() ), "Ctrl+J" );
423     addDPStaticEntry( menu, qtr( I_MENU_BOOKMARK ), "","",
424                       SLOT( bookmarksDialog() ), "Ctrl+B" );
425 #ifdef ENABLE_VLM
426     addDPStaticEntry( menu, qtr( I_MENU_VLM ), "", "", SLOT( vlmDialog() ),
427         "Ctrl+W" );
428 #endif
429
430     menu->addSeparator();
431     addDPStaticEntry( menu, qtr( "&Preferences..." ), "",
432         ":/preferences", SLOT( prefsDialog() ), "Ctrl+P" );
433     return menu;
434 }
435
436 /**
437  * Interface Sub-Menu, to list extras interface and skins
438  **/
439 QMenu *QVLCMenu::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
440 {
441     vector<vlc_object_t *> objects;
442     vector<const char *> varnames;
443     /** \todo add "switch to XXX" */
444     varnames.push_back( "intf-add" );
445     objects.push_back( VLC_OBJECT(p_intf) );
446
447     return Populate( p_intf, current, varnames, objects );
448 }
449
450 /**
451  * Main Audio Menu
452  */
453 QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QMenu * current )
454 {
455     vector<vlc_object_t *> objects;
456     vector<const char *> varnames;
457     vlc_object_t *p_aout;
458     input_thread_t *p_input;
459
460     if( !current ) current = new QMenu();
461
462     if( current->isEmpty() )
463     {
464         ACT_ADD( current, "audio-es", qtr( "Audio &Track" ) );
465         ACT_ADD( current, "audio-device", qtr( "Audio &Device" ) );
466         ACT_ADD( current, "audio-channels", qtr( "Audio &Channels" ) );
467         current->addSeparator();
468         ACT_ADD( current, "visual", qtr( "&Visualizations" ) );
469     }
470
471     p_input = THEMIM->getInput();
472     if( p_input )
473         vlc_object_hold( p_input );
474     p_aout = ( vlc_object_t * ) vlc_object_find( p_intf,
475                                                  VLC_OBJECT_AOUT,
476                                                  FIND_ANYWHERE );
477
478     AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
479
480     if( p_aout )
481         vlc_object_release( p_aout );
482     if( p_input )
483         vlc_object_release( p_input );
484
485     return Populate( p_intf, current, varnames, objects );
486 }
487
488 /**
489  * Main Video Menu
490  * Subtitles are part of Video.
491  **/
492 QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current )
493 {
494     vlc_object_t *p_vout;
495     input_thread_t *p_input;
496     vector<vlc_object_t *> objects;
497     vector<const char *> varnames;
498
499     if( !current ) current = new QMenu();
500
501     if( current->isEmpty() )
502     {
503         ACT_ADD( current, "video-es", qtr( "Video &Track" ) );
504
505         QAction *action;
506         QMenu *submenu = new QMenu( qtr( "&Subtitles Track" ), current );
507         action = current->addMenu( submenu );
508         action->setData( "spu-es" );
509         addDPStaticEntry( submenu, qtr( "Open File..." ), "", "",
510                           SLOT( loadSubtitlesFile() ) );
511         submenu->addSeparator();
512
513         ACT_ADD( current, "fullscreen", qtr( "&Fullscreen" ) );
514         ACT_ADD( current, "zoom", qtr( "&Zoom" ) );
515         ACT_ADD( current, "deinterlace", qtr( "&Deinterlace" ) );
516         ACT_ADD( current, "aspect-ratio", qtr( "&Aspect Ratio" ) );
517         ACT_ADD( current, "crop", qtr( "&Crop" ) );
518         ACT_ADD( current, "video-on-top", qtr( "Always &On Top" ) );
519 #ifdef WIN32
520         ACT_ADD( current, "directx-wallpaper", qtr( "DirectX Wallpaper" ) );
521 #endif
522         ACT_ADD( current, "video-snapshot", qtr( "Sna&pshot" ) );
523         ACT_ADD( current, "postproc-q", qtr( "Post processing" ) );
524     }
525
526     p_input = THEMIM->getInput();
527     if( p_input )
528         vlc_object_hold( p_input );
529     p_vout = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_VOUT,
530             FIND_ANYWHERE );
531
532     VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
533
534     if( p_vout )
535         vlc_object_release( p_vout );
536     if( p_input )
537         vlc_object_release( p_input );
538
539     return Populate( p_intf, current, varnames, objects );
540 }
541
542 /**
543  * Navigation Menu
544  * For DVD, MP4, MOV and other chapter based format
545  **/
546 QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *menu )
547 {
548     vlc_object_t *p_object;
549     vector<vlc_object_t *> objects;
550     vector<const char *> varnames;
551
552     if( !menu ) menu = new QMenu();
553
554     if( menu->isEmpty() )
555     {
556         addDPStaticEntry( menu, qtr( I_MENU_GOTOTIME ), "","",
557                           SLOT( gotoTimeDialog() ), "Ctrl+T" );
558         menu->addSeparator();
559
560         ACT_ADD( menu, "bookmark", qtr( "&Bookmarks" ) );
561         ACT_ADD( menu, "title", qtr( "T&itle" ) );
562         ACT_ADD( menu, "chapter", qtr( "&Chapter" ) );
563         ACT_ADD( menu, "program", qtr( "&Program" ) );
564         ACT_ADD( menu, "navigation", qtr( "&Navigation" ) );
565     }
566
567     p_object = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_INPUT,
568             FIND_ANYWHERE );
569     InputAutoMenuBuilder(  p_object, objects, varnames );
570     PUSH_VAR( "prev-title" );
571     PUSH_VAR( "next-title" );
572     PUSH_VAR( "prev-chapter" );
573     PUSH_VAR( "next-chapter" );
574     EnableDPStaticEntries( menu, ( p_object != NULL ) );
575     if( p_object )
576     {
577         vlc_object_release( p_object );
578     }
579     return Populate( p_intf, menu, varnames, objects, true );
580 }
581
582 /**
583  * Service Discovery SubMenu
584  **/
585 QMenu *QVLCMenu::SDMenu( intf_thread_t *p_intf )
586 {
587     QMenu *menu = new QMenu();
588     menu->setTitle( qtr( I_PL_SD ) );
589     char **ppsz_longnames;
590     char **ppsz_names = services_discovery_GetServicesNames( p_intf,
591                                                              &ppsz_longnames );
592     if( !ppsz_names )
593         return menu;
594
595     char **ppsz_name = ppsz_names, **ppsz_longname = ppsz_longnames;
596     for( ; *ppsz_name; ppsz_name++, ppsz_longname++ )
597     {
598         QAction *a = new QAction( qfu( *ppsz_longname ), menu );
599         a->setCheckable( true );
600         if( playlist_IsServicesDiscoveryLoaded( THEPL, *ppsz_name ) )
601             a->setChecked( true );
602         CONNECT( a , triggered(), THEDP->SDMapper, map() );
603         THEDP->SDMapper->setMapping( a, QString( *ppsz_name ) );
604         menu->addAction( a );
605
606         if( !strcmp( *ppsz_name, "podcast" ) )
607         {
608             QAction *b = new QAction( qtr( "Configure podcasts..." ), menu );
609             //b->setEnabled( a->isChecked() );
610             menu->addAction( b );
611             CONNECT( b, triggered(), THEDP, podcastConfigureDialog() );
612         }
613         free( *ppsz_name );
614         free( *ppsz_longname );
615     }
616     free( ppsz_names );
617     free( ppsz_longnames );
618     return menu;
619 }
620 /**
621  * Help/About Menu
622 **/
623 QMenu *QVLCMenu::HelpMenu( QMenu *current )
624 {
625     QMenu *menu = new QMenu( current );
626     addDPStaticEntry( menu, qtr( "&Help..." ) , "",
627         ":/help", SLOT( helpDialog() ), "F1" );
628 #ifdef UPDATE_CHECK
629     addDPStaticEntry( menu, qtr( "Check for &Updates..." ) , "", "",
630                       SLOT( updateDialog() ), "");
631 #endif
632     menu->addSeparator();
633     addDPStaticEntry( menu, qtr( I_MENU_ABOUT ), "", ":/info",
634             SLOT( aboutDialog() ), "Shift+F1" );
635     return menu;
636 }
637
638 /*****************************************************************************
639  * Popup menus - Right Click menus                                           *
640  *****************************************************************************/
641 #define POPUP_BOILERPLATE \
642     unsigned int i_last_separator = 0; \
643     vector<vlc_object_t *> objects; \
644     vector<const char *> varnames; \
645     input_thread_t *p_input = THEMIM->getInput();
646
647 #define CREATE_POPUP \
648     Populate( p_intf, menu, varnames, objects ); \
649     p_intf->p_sys->p_popup_menu = menu; \
650     menu->popup( QCursor::pos() ); \
651     p_intf->p_sys->p_popup_menu = NULL; \
652     i_last_separator = 0;
653
654 void QVLCMenu::PopupMenuControlEntries( QMenu *menu,
655                                         intf_thread_t *p_intf,
656                                         input_thread_t *p_input )
657 {
658     if( p_input )
659     {
660         vlc_value_t val;
661         var_Get( p_input, "state", &val );
662         if( val.i_int == PLAYING_S )
663             addMIMStaticEntry( p_intf, menu, qtr( "Pause" ), "",
664                     ":/pause", SLOT( togglePlayPause() ) );
665         else
666             addMIMStaticEntry( p_intf, menu, qtr( "Play" ), "",
667                     ":/play", SLOT( togglePlayPause() ) );
668     }
669     else if( THEPL->items.i_size )
670         addMIMStaticEntry( p_intf, menu, qtr( "Play" ), "",
671                 ":/play", SLOT( togglePlayPause() ) );
672     else
673         addDPStaticEntry( menu, qtr( "Play" ), "",
674                 ":/play", SLOT( openDialog() ) );
675
676     addMIMStaticEntry( p_intf, menu, qtr( "Stop" ), "",
677             ":/stop", SLOT( stop() ) );
678     addMIMStaticEntry( p_intf, menu, qtr( "Previous" ), "",
679             ":/previous", SLOT( prev() ) );
680     addMIMStaticEntry( p_intf, menu, qtr( "Next" ), "",
681             ":/next", SLOT( next() ) );
682 }
683
684 void QVLCMenu::PopupMenuStaticEntries( intf_thread_t *p_intf, QMenu *menu )
685 {
686 #if 0
687     QMenu *toolsmenu = ToolsMenu( p_intf, menu, false, true );
688     toolsmenu->setTitle( qtr( "Tools" ) );
689     menu->addMenu( toolsmenu );
690 #endif
691
692     QMenu *openmenu = new QMenu( qtr( "Open" ), menu );
693     addDPStaticEntry( openmenu, qtr( "&Open File..." ), "",
694         ":/file-asym", SLOT( openFileDialog() ) );
695     addDPStaticEntry( openmenu, qtr( I_OPEN_FOLDER ), "",
696         ":/folder-grey", SLOT( PLOpenDir() ) );
697     addDPStaticEntry( openmenu, qtr( "Open &Disc..." ), "",
698         ":/disc", SLOT( openDiscDialog() ) );
699     addDPStaticEntry( openmenu, qtr( "Open &Network..." ), "",
700         ":/network", SLOT( openNetDialog() ) );
701     addDPStaticEntry( openmenu, qtr( "Open &Capture Device..." ), "",
702         ":/capture-card", SLOT( openCaptureDialog() ) );
703     menu->addMenu( openmenu );
704
705     menu->addSeparator();
706 #if 0
707     QMenu *helpmenu = HelpMenu( menu );
708     helpmenu->setTitle( qtr( "Help" ) );
709     menu->addMenu( helpmenu );
710 #endif
711
712     addDPStaticEntry( menu, qtr( "Quit" ), "", ":/quit",
713                       SLOT( quit() ), "Ctrl+Q" );
714 }
715
716 /* Video Tracks and Subtitles tracks */
717 void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf )
718 {
719     POPUP_BOILERPLATE;
720     if( p_input )
721     {
722         vlc_object_hold( p_input );
723         vlc_object_t *p_vout = ( vlc_object_t * )vlc_object_find( p_input,
724                 VLC_OBJECT_VOUT, FIND_CHILD );
725         if( p_vout )
726         {
727             VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
728             vlc_object_release( p_vout );
729         }
730         vlc_object_release( p_input );
731     }
732     QMenu *menu = new QMenu();
733     CREATE_POPUP;
734 }
735
736 /* Audio Tracks */
737 void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf )
738 {
739     POPUP_BOILERPLATE;
740     if( p_input )
741     {
742         vlc_object_hold( p_input );
743         vlc_object_t *p_aout = ( vlc_object_t * )vlc_object_find( p_input,
744                 VLC_OBJECT_AOUT, FIND_ANYWHERE );
745         AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
746         if( p_aout )
747             vlc_object_release( p_aout );
748         vlc_object_release( p_input );
749     }
750     QMenu *menu = new QMenu();
751     CREATE_POPUP;
752 }
753
754 /* Navigation stuff, and general menus ( open ) */
755 void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf )
756 {
757     vlc_value_t val;
758     POPUP_BOILERPLATE;
759
760     if( p_input )
761     {
762         vlc_object_hold( p_input );
763         varnames.push_back( "audio-es" );
764         InputAutoMenuBuilder( VLC_OBJECT( p_input ), objects, varnames );
765         PUSH_SEPARATOR;
766     }
767
768     QMenu *menu = new QMenu();
769     Populate( p_intf, menu, varnames, objects );
770
771     menu->addSeparator();
772     PopupMenuControlEntries( menu, p_intf, p_input );
773
774     menu->addSeparator();
775     PopupMenuStaticEntries( p_intf, menu );
776
777     p_intf->p_sys->p_popup_menu = menu;
778     menu->popup( QCursor::pos() );
779     p_intf->p_sys->p_popup_menu = NULL;
780 }
781
782 /* Main Menu that sticks everything together  */
783 void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show )
784 {
785     MainInterface *mi = p_intf->p_sys->p_mi;
786     if( show )
787     {
788         /* Delete and recreate a popup if there is one */
789         if( p_intf->p_sys->p_popup_menu )
790             delete p_intf->p_sys->p_popup_menu;
791
792         QMenu *menu = new QMenu();
793         QMenu *submenu;
794         QAction *action;
795         bool b_isFullscreen = false;
796
797         POPUP_BOILERPLATE;
798
799         PopupMenuControlEntries( menu, p_intf, p_input );
800         menu->addSeparator();
801
802         if( p_input )
803         {
804             vlc_object_t *p_vout = (vlc_object_t *)
805                 vlc_object_find( p_input, VLC_OBJECT_VOUT, FIND_CHILD );
806
807             /* Add a fullscreen switch button */
808             if( p_vout )
809             {
810                 vlc_value_t val;
811                 var_Get( p_vout, "fullscreen", &val );
812                 b_isFullscreen = !( !val.b_bool );
813                 if( b_isFullscreen )
814                     CreateAndConnect( menu, "fullscreen",
815                             qtr( "Leave Fullscreen" ),"" , ITEM_NORMAL,
816                             VLC_OBJECT(p_vout), val, VLC_VAR_BOOL,
817                             b_isFullscreen );
818                 vlc_object_release( p_vout );
819             }
820
821             menu->addSeparator();
822
823             vlc_object_hold( p_input );
824             InputAutoMenuBuilder( VLC_OBJECT( p_input ), objects, varnames );
825             vlc_object_release( p_input );
826
827             submenu = new QMenu( menu );
828             action = menu->addMenu( AudioMenu( p_intf, submenu ) );
829             action->setText( qtr( "&Audio" ) );
830             if( action->menu()->isEmpty() )
831                 action->setEnabled( false );
832
833             submenu = new QMenu( menu );
834             action = menu->addMenu( VideoMenu( p_intf, submenu ) );
835             action->setText( qtr( "&Video" ) );
836             if( action->menu()->isEmpty() )
837                 action->setEnabled( false );
838
839             submenu = new QMenu( menu );
840             action = menu->addMenu( NavigMenu( p_intf, submenu ) );
841             action->setText( qtr( "&Playback" ) );
842             if( action->menu()->isEmpty() )
843                 action->setEnabled( false );
844         }
845
846         menu->addSeparator();
847
848         /* Add some special entries for windowed mode: Interface Menu */
849         if( !b_isFullscreen )
850         {
851             submenu = new QMenu( qtr( "Interface" ), menu );
852             if( mi )
853             {
854                 submenu->addAction( QIcon( ":/playlist" ),
855                          qtr( "Show Playlist" ), mi, SLOT( togglePlaylist() ) );
856             }
857             addDPStaticEntry( submenu, qtr( I_MENU_EXT ), "",
858                 ":/settings", SLOT( extendedDialog() ) );
859             addDPStaticEntry( submenu, qtr( I_MENU_INFO ) , "", ":/info",
860                 SLOT( mediaInfoDialog() ), "Ctrl+I" );
861             if( mi )
862             {
863                 action = submenu->addAction( QIcon( "" ),
864                      qtr( "Minimal View" ), mi, SLOT( toggleMinimalView() ) );
865                 action->setCheckable( true );
866                 action->setChecked( !( mi->getControlsVisibilityStatus() &
867                             CONTROLS_VISIBLE ) );
868                 action = submenu->addAction( QIcon( "" ),
869                         qtr( "Toggle Fullscreen Interface" ),
870                         mi, SLOT( toggleFullScreen() ) );
871                 action->setCheckable( true );
872                 action->setChecked( mi->isFullScreen() );
873             }
874             else /* We are using the skins interface.
875                     If not, this entry will not show. */
876             {
877                 addDPStaticEntry( submenu, qtr( "&Preferences..." ), "",
878                     ":/preferences", SLOT( prefsDialog() ), "Ctrl+P" );
879                 submenu->addSeparator();
880                 objects.clear();
881                 varnames.clear();
882                 vlc_object_t *p_obje