1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright © 2006-2009 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
8 * Jean-Baptiste Kempf <jb@videolan.org>
9 * Jean-Philippe André <jpeg@videolan.org>
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.
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.
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 *****************************************************************************/
27 * - Remove static currentGroup
34 #include <vlc_intf_strings.h>
35 #include <vlc_services_discovery.h>
39 #include "main_interface.hpp" /* View modifications */
40 #include "dialogs_provider.hpp" /* Dialogs display */
41 #include "input_manager.hpp" /* Input Management */
42 #include "recents.hpp" /* Recent Items */
43 #include "actions_manager.hpp"
48 #include <QActionGroup>
49 #include <QSignalMapper>
50 #include <QSystemTrayIcon>
54 This file defines the main menus and the pop-up menu (right-click menu)
55 and the systray menu (in that order in the file)
57 There are 3 menus that have to be rebuilt everytime there are called:
58 Audio, Video, Navigation
59 3 functions are building those menus: AudioMenu, VideoMenu, NavigMenu
60 and 3 functions associated are collecting the objects :
61 InputAutoMenuBuilder, AudioAutoMenuBuilder, VideoAutoMenuBuilder.
63 A QSignalMapper decides when to rebuild those menus cf MenuFunc in the .hpp
64 Just before one of those menus are aboutToShow(), they are rebuild.
74 static QActionGroup *currentGroup;
76 QMenu *QVLCMenu::recentsMenu = NULL;
78 /****************************************************************************
80 ****************************************************************************
81 * Add static entries to DP in menus
82 ***************************************************************************/
83 void addDPStaticEntry( QMenu *menu,
87 const char *shortcut = NULL )
89 QAction *action = NULL;
90 if( !EMPTY_STR( icon ) > 0 )
92 if( !EMPTY_STR( shortcut ) > 0 )
93 action = menu->addAction( QIcon( icon ), text, THEDP,
94 member, qtr( shortcut ) );
96 action = menu->addAction( QIcon( icon ), text, THEDP, member );
100 if( !EMPTY_STR( shortcut ) > 0 )
101 action = menu->addAction( text, THEDP, member, qtr( shortcut ) );
103 action = menu->addAction( text, THEDP, member );
105 action->setData( true );
111 void addMIMStaticEntry( intf_thread_t *p_intf,
118 if( strlen( icon ) > 0 )
120 action = menu->addAction( text, THEMIM, member );
121 action->setIcon( QIcon( icon ) );
125 menu->addAction( text, THEMIM, member );
127 action->setData( "ignore" );
131 * @brief Enable all static entries, disable the others
132 * @param enable if false, disable all entries
134 void EnableStaticEntries( QMenu *menu, bool enable = true )
138 QList< QAction* > actions = menu->actions();
139 for( int i = 0; i < actions.size(); ++i )
141 actions[i]->setEnabled( actions[i]->data().toString() == "ignore" ||
142 /* Be careful here, because data("string").toBool is true */
143 ( enable && (actions[i]->data().toString() == "true" ) ) );
148 * \return Number of static entries
150 int DeleteNonStaticEntries( QMenu *menu )
152 if( !menu ) return VLC_EGENERIC;
156 QList< QAction* > actions = menu->actions();
157 for( int i = 0; i < actions.size(); ++i )
159 if( !actions[i]->data().toBool() )
168 * \return QAction associated to psz_var variable
170 static QAction * FindActionWithVar( QMenu *menu, const char *psz_var )
172 QList< QAction* > actions = menu->actions();
173 for( int i = 0; i < actions.size(); ++i )
175 if( actions[i]->data().toString() == psz_var )
181 /*****************************************************************************
182 * Definitions of variables for the dynamic menus
183 *****************************************************************************/
184 #define PUSH_VAR( var ) varnames.push_back( var ); \
185 objects.push_back( VLC_OBJECT(p_object) )
187 #define PUSH_INPUTVAR( var ) varnames.push_back( var ); \
188 objects.push_back( VLC_OBJECT(p_input) );
190 #define PUSH_SEPARATOR if( objects.size() != i_last_separator ) { \
191 objects.push_back( 0 ); varnames.push_back( "" ); \
192 i_last_separator = objects.size(); }
194 static int InputAutoMenuBuilder( input_thread_t *p_object,
195 vector<vlc_object_t *> &objects,
196 vector<const char *> &varnames )
198 PUSH_VAR( "bookmark" );
200 PUSH_VAR( "chapter" );
201 PUSH_VAR( "navigation" );
202 PUSH_VAR( "program" );
206 static int VideoAutoMenuBuilder( vout_thread_t *p_object,
207 input_thread_t *p_input,
208 vector<vlc_object_t *> &objects,
209 vector<const char *> &varnames )
211 PUSH_INPUTVAR( "video-es" );
212 PUSH_INPUTVAR( "spu-es" );
213 PUSH_VAR( "fullscreen" );
214 PUSH_VAR( "video-on-top" );
216 PUSH_VAR( "directx-wallpaper" );
218 PUSH_VAR( "video-snapshot" );
220 PUSH_VAR( "autoscale" );
221 PUSH_VAR( "aspect-ratio" );
223 PUSH_VAR( "deinterlace" );
224 PUSH_VAR( "postprocess" );
229 static int AudioAutoMenuBuilder( aout_instance_t *p_object,
230 input_thread_t *p_input,
231 vector<vlc_object_t *> &objects,
232 vector<const char *> &varnames )
234 PUSH_INPUTVAR( "audio-es" );
235 PUSH_VAR( "audio-channels" );
236 PUSH_VAR( "audio-device" );
237 PUSH_VAR( "visual" );
241 /*****************************************************************************
244 *****************************************************************************/
246 #define BAR_ADD( func, title ) { \
247 QMenu *_menu = func; _menu->setTitle( title ); bar->addMenu( _menu ); }
249 #define BAR_DADD( func, title, id ) { \
250 QMenu *_menu = func; _menu->setTitle( title ); bar->addMenu( _menu ); \
251 MenuFunc *f = new MenuFunc( _menu, id ); \
252 CONNECT( _menu, aboutToShow(), THEDP->menusUpdateMapper, map() ); \
253 THEDP->menusUpdateMapper->setMapping( _menu, f ); }
255 #define ACT_ADD( _menu, val, title ) { \
256 QAction *_action = new QAction( title, _menu ); _action->setData( val ); \
257 _menu->addAction( _action ); }
259 #define ACT_ADDMENU( _menu, val, title ) { \
260 QAction *_action = new QAction( title, _menu ); _action->setData( val ); \
261 _action->setMenu( new QMenu() ); _menu->addAction( _action ); }
263 #define ACT_ADDCHECK( _menu, val, title ) { \
264 QAction *_action = new QAction( title, _menu ); _action->setData( val ); \
265 _action->setCheckable( true ); _menu->addAction( _action ); }
268 * Main Menu Bar Creation
270 void QVLCMenu::createMenuBar( MainInterface *mi,
271 intf_thread_t *p_intf )
273 /* QMainWindows->menuBar()
274 gives the QProcess::destroyed timeout issue on Cleanlooks style with
275 setDesktopAware set to false */
276 QMenuBar *bar = mi->menuBar();
278 BAR_ADD( FileMenu( p_intf, bar ), qtr( "&Media" ) );
280 /* Dynamic menus, rebuilt before being showed */
281 BAR_DADD( NavigMenu( p_intf, bar ), qtr( "P&layback" ), 3 );
282 BAR_DADD( AudioMenu( p_intf, bar ), qtr( "&Audio" ), 1 );
283 BAR_DADD( VideoMenu( p_intf, bar ), qtr( "&Video" ), 2 );
285 BAR_ADD( ToolsMenu( bar ), qtr( "&Tools" ) );
286 BAR_ADD( ViewMenu( p_intf, mi ), qtr( "V&iew" ) );
287 BAR_ADD( HelpMenu( bar ), qtr( "&Help" ) );
293 * Media ( File ) Menu
294 * Opening, streaming and quit
296 QMenu *QVLCMenu::FileMenu( intf_thread_t *p_intf, QWidget *parent )
298 QMenu *menu = new QMenu( parent );
300 addDPStaticEntry( menu, qtr( "&Open File..." ),
301 ":/file-asym", SLOT( simpleOpenDialog() ), "Ctrl+O" );
302 addDPStaticEntry( menu, qtr( "Advanced Open File..." ),
303 ":/file-asym", SLOT( openFileDialog() ), "Ctrl+Shift+O" );
304 addDPStaticEntry( menu, qtr( I_OPEN_FOLDER ),
305 ":/folder-grey", SLOT( PLOpenDir() ), "Ctrl+F" );
306 addDPStaticEntry( menu, qtr( "Open &Disc..." ),
307 ":/disc", SLOT( openDiscDialog() ), "Ctrl+D" );
308 addDPStaticEntry( menu, qtr( "Open &Network..." ),
309 ":/network", SLOT( openNetDialog() ), "Ctrl+N" );
310 addDPStaticEntry( menu, qtr( "Open &Capture Device..." ),
311 ":/capture-card", SLOT( openCaptureDialog() ),
314 menu->addSeparator();
315 addDPStaticEntry( menu, qtr( "Paste &Location" ),
316 NULL, SLOT( openUrlDialog() ), "Ctrl+V" );
318 recentsMenu = new QMenu( qtr( "&Recent Media" ), menu );
319 updateRecents( p_intf );
320 menu->addMenu( recentsMenu );
321 menu->addMenu( SDMenu( p_intf, menu ) );
322 menu->addSeparator();
324 addDPStaticEntry( menu, qtr( I_PL_SAVE ), "", SLOT( saveAPlaylist() ),
326 menu->addSeparator();
328 addDPStaticEntry( menu, qtr( "Conve&rt / Save..." ), "",
329 SLOT( openAndTranscodingDialogs() ), "Ctrl+R" );
330 addDPStaticEntry( menu, qtr( "&Streaming..." ),
331 ":/stream", SLOT( openAndStreamingDialogs() ),
333 menu->addSeparator();
335 addDPStaticEntry( menu, qtr( "&Quit" ) ,
336 ":/quit", SLOT( quit() ), "Ctrl+Q" );
341 * Tools, like Media Information, Preferences or Messages
343 QMenu *QVLCMenu::ToolsMenu( QMenu *menu )
345 addDPStaticEntry( menu, qtr( I_MENU_EXT ), ":/settings",
346 SLOT( extendedDialog() ), "Ctrl+E" );
348 addDPStaticEntry( menu, qtr( I_MENU_INFO ) , ":/info",
349 SLOT( mediaInfoDialog() ), "Ctrl+I" );
350 addDPStaticEntry( menu, qtr( I_MENU_CODECINFO ) ,
351 ":/info", SLOT( mediaCodecDialog() ), "Ctrl+J" );
353 addDPStaticEntry( menu, qtr( I_MENU_BOOKMARK ),"",
354 SLOT( bookmarksDialog() ), "Ctrl+B" );
356 addDPStaticEntry( menu, qtr( I_MENU_VLM ), "", SLOT( vlmDialog() ),
360 addDPStaticEntry( menu, qtr( I_MENU_MSG ),
361 ":/messages", SLOT( messagesDialog() ),
364 addDPStaticEntry( menu, qtr( "Plu&gins and extensions" ),
365 "", SLOT( pluginDialog() ) );
366 menu->addSeparator();
368 addDPStaticEntry( menu, qtr( "&Preferences" ),
369 ":/preferences", SLOT( prefsDialog() ), "Ctrl+P" );
374 QMenu *QVLCMenu::ToolsMenu( QWidget *parent )
376 return ToolsMenu( new QMenu( parent ) );
381 * Interface Modification
383 QMenu *QVLCMenu::ViewMenu( intf_thread_t *p_intf,
389 QMenu *menu = new QMenu( qtr( "V&iew" ), mi );
391 QAction *act = menu->addAction( QIcon( ":/playlist_menu" ),
392 qtr( "Play&list" ), mi,
393 SLOT( togglePlaylist() ), qtr( "Ctrl+L" ) );
395 /*menu->addSeparator();
396 menu->addAction( qtr( "Undock from Interface" ), mi,
397 SLOT( undockPlaylist() ), qtr( "Ctrl+U" ) );*/
399 menu->addSeparator();
403 QMenu *intfmenu = InterfacesMenu( p_intf, menu );
404 MenuFunc *f = new MenuFunc( intfmenu, 4 );
405 CONNECT( intfmenu, aboutToShow(), THEDP->menusUpdateMapper, map() );
406 THEDP->menusUpdateMapper->setMapping( intfmenu, f );
407 menu->addSeparator();
411 QAction *action = menu->addAction( qtr( "Mi&nimal View" ) );
412 action->setShortcut( qtr( "Ctrl+H" ) );
413 action->setCheckable( true );
414 action->setChecked( !with_intf &&
415 (mi->getControlsVisibilityStatus() & CONTROLS_HIDDEN ) );
417 CONNECT( action, triggered( bool ), mi, toggleMinimalView( bool ) );
418 CONNECT( mi, minimalViewToggled( bool ), action, setChecked( bool ) );
420 /* FullScreen View */
421 action = menu->addAction( qtr( "&Fullscreen Interface" ), mi,
422 SLOT( toggleFullScreen() ), QString( "F11" ) );
423 action->setCheckable( true );
424 action->setChecked( mi->isFullScreen() );
425 CONNECT( mi, fullscreenInterfaceToggled( bool ),
426 action, setChecked( bool ) );
428 /* Advanced Controls */
429 action = menu->addAction( qtr( "&Advanced Controls" ), mi,
430 SLOT( toggleAdvanced() ) );
431 action->setCheckable( true );
432 if( mi->getControlsVisibilityStatus() & CONTROLS_ADVANCED )
433 action->setChecked( true );
436 // I don't want to manage consistency between menus, so no popup-menu
438 action = menu->addAction( qtr( "Quit after Playback" ) );
439 action->setCheckable( true );
440 CONNECT( action, triggered( bool ), THEMIM, activatePlayQuit( bool ) );
443 #if 0 /* For Visualisations. Not yet working */
444 adv = menu->addAction( qtr( "Visualizations selector" ),
445 mi, SLOT( visual() ) );
446 adv->setCheckable( true );
447 if( visual_selector_enabled ) adv->setChecked( true );
450 menu->addSeparator();
451 addDPStaticEntry( menu, qtr( "Customi&ze Interface..." ),
452 ":/preferences", SLOT( toolbarDialog() ) );
453 menu->addSeparator();
459 * Interface Sub-Menu, to list extras interface and skins
461 QMenu *QVLCMenu::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
463 vector<vlc_object_t *> objects;
464 vector<const char *> varnames;
465 varnames.push_back( "intf-add" );
466 objects.push_back( VLC_OBJECT(p_intf) );
468 return Populate( p_intf, current, varnames, objects );
474 QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QMenu * current )
476 vector<vlc_object_t *> objects;
477 vector<const char *> varnames;
478 aout_instance_t *p_aout;
479 input_thread_t *p_input;
481 if( current->isEmpty() )
483 ACT_ADDMENU( current, "audio-es", qtr( "Audio &Track" ) );
484 ACT_ADDMENU( current, "audio-channels", qtr( "Audio &Channels" ) );
485 ACT_ADDMENU( current, "audio-device", qtr( "Audio &Device" ) );
486 current->addSeparator();
488 ACT_ADDMENU( current, "visual", qtr( "&Visualizations" ) );
489 current->addSeparator();
491 QAction *action = current->addAction( qtr( "Increase Volume" ),
492 ActionsManager::getInstance( p_intf ), SLOT( AudioUp() ) );
493 action->setData( true );
494 action = current->addAction( qtr( "Decrease Volume" ),
495 ActionsManager::getInstance( p_intf ), SLOT( AudioDown() ) );
496 action->setData( true );
497 action = current->addAction( qtr( "Mute" ),
498 ActionsManager::getInstance( p_intf ), SLOT( toggleMuteAudio() ) );
499 action->setData( true );
502 p_input = THEMIM->getInput();
504 vlc_object_hold( p_input );
505 p_aout = THEMIM->getAout();
506 EnableStaticEntries( current, ( p_aout != NULL ) );
507 AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
510 vlc_object_release( p_aout );
513 vlc_object_release( p_input );
515 return Populate( p_intf, current, varnames, objects );
518 QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QWidget *parent )
520 return AudioMenu( p_intf, new QMenu( parent ) );
525 * Subtitles are part of Video.
527 QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current )
529 vout_thread_t *p_vout;
530 input_thread_t *p_input;
531 vector<vlc_object_t *> objects;
532 vector<const char *> varnames;
534 if( current->isEmpty() )
536 ACT_ADDMENU( current, "video-es", qtr( "Video &Track" ) );
539 QMenu *submenu = new QMenu( qtr( "&Subtitles Track" ), current );
540 action = current->addMenu( submenu );
541 action->setData( "spu-es" );
542 addDPStaticEntry( submenu, qtr( "Open File..." ), "",
543 SLOT( loadSubtitlesFile() ) );
544 submenu->addSeparator();
545 current->addSeparator();
547 ACT_ADDCHECK( current, "fullscreen", qtr( "&Fullscreen" ) );
548 ACT_ADDCHECK( current, "video-on-top", qtr( "Always &On Top" ) );
550 ACT_ADDCHECK( current, "directx-wallpaper", qtr( "DirectX Wallpaper" ) );
552 ACT_ADD( current, "video-snapshot", qtr( "Sna&pshot" ) );
554 current->addSeparator();
556 ACT_ADDMENU( current, "zoom", qtr( "&Zoom" ) );
557 ACT_ADDCHECK( current, "autoscale", qtr( "Sca&le" ) );
558 ACT_ADDMENU( current, "aspect-ratio", qtr( "&Aspect Ratio" ) );
559 ACT_ADDMENU( current, "crop", qtr( "&Crop" ) );
560 ACT_ADDMENU( current, "deinterlace", qtr( "&Deinterlace" ) );
561 ACT_ADDMENU( current, "postprocess", qtr( "&Post processing" ) );
564 p_input = THEMIM->getInput();
566 vlc_object_hold( p_input );
568 p_vout = THEMIM->getVout();
569 VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
572 vlc_object_release( p_vout );
575 vlc_object_release( p_input );
577 return Populate( p_intf, current, varnames, objects );
580 QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QWidget *parent )
582 return VideoMenu( p_intf, new QMenu( parent ) );
587 * For DVD, MP4, MOV and other chapter based format
589 QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *menu )
593 QMenu *submenu = new QMenu( qtr( "&Bookmarks" ), menu );
594 addDPStaticEntry( submenu, qtr( "Manage &bookmarks" ), "",
595 SLOT( bookmarksDialog() ) );
596 submenu->addSeparator();
597 action = menu->addMenu( submenu );
598 action->setData( "bookmark" );
600 ACT_ADDMENU( menu, "title", qtr( "T&itle" ) );
601 ACT_ADDMENU( menu, "chapter", qtr( "&Chapter" ) );
602 ACT_ADDMENU( menu, "navigation", qtr( "&Navigation" ) );
603 ACT_ADDMENU( menu, "program", qtr( "&Program" ) );
605 menu->addSeparator();
606 PopupMenuPlaylistControlEntries( menu, p_intf );
607 PopupMenuControlEntries( menu, p_intf );
612 QMenu *QVLCMenu::RebuildNavigMenu( intf_thread_t *p_intf, QMenu *menu )
615 input_thread_t *p_object;
616 vector<vlc_object_t *> objects;
617 vector<const char *> varnames;
619 /* Get the input and hold it */
620 p_object = THEMIM->getInput();
622 vlc_object_hold( p_object );
624 InputAutoMenuBuilder( p_object, objects, varnames );
626 menu->addSeparator();
628 /* Title and so on */
629 PUSH_VAR( "prev-title" );
630 PUSH_VAR( "next-title" );
631 PUSH_VAR( "prev-chapter" );
632 PUSH_VAR( "next-chapter" );
635 vlc_object_release( p_object );
637 EnableStaticEntries( menu, (p_object != NULL ) );
638 return Populate( p_intf, menu, varnames, objects );
641 QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QWidget *parent )
643 return NavigMenu( p_intf, new QMenu( parent ) );
647 * Service Discovery SubMenu
649 QMenu *QVLCMenu::SDMenu( intf_thread_t *p_intf, QWidget *parent )
651 QMenu *menu = new QMenu( parent );
652 menu->setTitle( qtr( I_PL_SD ) );
654 char **ppsz_longnames;
655 char **ppsz_names = vlc_sd_GetNames( &ppsz_longnames );
659 char **ppsz_name = ppsz_names, **ppsz_longname = ppsz_longnames;
660 for( ; *ppsz_name; ppsz_name++, ppsz_longname++ )
662 QAction *a = new QAction( qfu( *ppsz_longname ), menu );
663 a->setCheckable( true );
664 if( playlist_IsServicesDiscoveryLoaded( THEPL, *ppsz_name ) )
665 a->setChecked( true );
666 CONNECT( a, triggered(), THEDP->SDMapper, map() );
667 THEDP->SDMapper->setMapping( a, QString( *ppsz_name ) );
668 menu->addAction( a );
670 /* Special case for podcast */
671 if( !strcmp( *ppsz_name, "podcast" ) )
673 QAction *b = new QAction( qtr( "Configure podcasts..." ), menu );
674 //b->setEnabled( a->isChecked() );
675 menu->addAction( b );
676 CONNECT( b, triggered(), THEDP, podcastConfigureDialog() );
679 free( *ppsz_longname );
682 free( ppsz_longnames );
689 QMenu *QVLCMenu::HelpMenu( QWidget *parent )
691 QMenu *menu = new QMenu( parent );
692 addDPStaticEntry( menu, qtr( "&Help..." ) ,
693 ":/help", SLOT( helpDialog() ), "F1" );
695 addDPStaticEntry( menu, qtr( "Check for &Updates..." ) , "",
696 SLOT( updateDialog() ) );
698 menu->addSeparator();
699 addDPStaticEntry( menu, qtr( I_MENU_ABOUT ), ":/info",
700 SLOT( aboutDialog() ), "Shift+F1" );
704 /*****************************************************************************
705 * Popup menus - Right Click menus *
706 *****************************************************************************/
707 #define POPUP_BOILERPLATE \
708 unsigned int i_last_separator = 0; \
709 vector<vlc_object_t *> objects; \
710 vector<const char *> varnames; \
711 input_thread_t *p_input = THEMIM->getInput();
713 #define CREATE_POPUP \
714 Populate( p_intf, menu, varnames, objects ); \
715 p_intf->p_sys->p_popup_menu = menu; \
716 menu->popup( QCursor::pos() ); \
717 p_intf->p_sys->p_popup_menu = NULL; \
718 i_last_separator = 0;
720 void QVLCMenu::PopupPlayEntries( QMenu *menu,
721 intf_thread_t *p_intf,
722 input_thread_t *p_input )
726 /* Play or Pause action and icon */
727 if( !p_input || var_GetInteger( p_input, "state" ) != PLAYING_S )
729 action = menu->addAction( qtr( "Play" ),
730 ActionsManager::getInstance( p_intf ), SLOT( play() ) );
731 action->setIcon( QIcon( ":/play" ) );
735 addMIMStaticEntry( p_intf, menu, qtr( "Pause" ),
736 ":/pause", SLOT( togglePlayPause() ) );
740 void QVLCMenu::PopupMenuControlEntries( QMenu *menu, intf_thread_t *p_intf )
745 action = menu->addAction( qtr( "&Faster" ), THEMIM->getIM(),
747 action->setIcon( QIcon( ":/faster") );
748 action->setData( true );
750 action = menu->addAction( qtr( "N&ormal Speed" ), THEMIM->getIM(),
751 SLOT( normalRate() ) );
752 action->setData( true );
754 action = menu->addAction( qtr( "Slo&wer" ), THEMIM->getIM(),
756 action->setIcon( QIcon( ":/slower") );
757 action->setData( true );
759 menu->addSeparator();
761 action = menu->addAction( qtr( "&Jump Forward" ), THEMIM->getIM(),
763 action->setIcon( QIcon( ":/skip_fw") );
764 action->setData( true );
766 action = menu->addAction( qtr( "Jump Bac&kward" ), THEMIM->getIM(),
768 action->setIcon( QIcon( ":/skip_back") );
769 action->setData( true );
770 addDPStaticEntry( menu, qtr( I_MENU_GOTOTIME ),"",
771 SLOT( gotoTimeDialog() ), "Ctrl+T" );
772 menu->addSeparator();
776 void QVLCMenu::PopupMenuPlaylistControlEntries( QMenu *menu,
777 intf_thread_t *p_intf )
779 addMIMStaticEntry( p_intf, menu, qtr( "&Stop" ), ":/stop", SLOT( stop() ) );
781 /* Next / Previous */
782 addMIMStaticEntry( p_intf, menu, qtr( "Pre&vious" ),
783 ":/previous", SLOT( prev() ) );
784 addMIMStaticEntry( p_intf, menu, qtr( "Ne&xt" ),
785 ":/next", SLOT( next() ) );
786 menu->addSeparator();
789 void QVLCMenu::PopupMenuStaticEntries( QMenu *menu )
791 QMenu *openmenu = new QMenu( qtr( "Open Media" ), menu );
792 addDPStaticEntry( openmenu, qtr( "&Open File..." ),
793 ":/file-asym", SLOT( openFileDialog() ) );
794 addDPStaticEntry( openmenu, qtr( I_OPEN_FOLDER ),
795 ":/folder-grey", SLOT( PLOpenDir() ) );
796 addDPStaticEntry( openmenu, qtr( "Open &Disc..." ),
797 ":/disc", SLOT( openDiscDialog() ) );
798 addDPStaticEntry( openmenu, qtr( "Open &Network..." ),
799 ":/network", SLOT( openNetDialog() ) );
800 addDPStaticEntry( openmenu, qtr( "Open &Capture Device..." ),
801 ":/capture-card", SLOT( openCaptureDialog() ) );
802 menu->addMenu( openmenu );
804 menu->addSeparator();
806 QMenu *helpmenu = HelpMenu( menu );
807 helpmenu->setTitle( qtr( "Help" ) );
808 menu->addMenu( helpmenu );
811 addDPStaticEntry( menu, qtr( "Quit" ), ":/quit",
812 SLOT( quit() ), "Ctrl+Q" );
815 /* Video Tracks and Subtitles tracks */
816 void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf )
821 vlc_object_hold( p_input );
822 vout_thread_t *p_vout = THEMIM->getVout();
825 VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
826 vlc_object_release( p_vout );
828 vlc_object_release( p_input );
830 QMenu *menu = new QMenu();
835 void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf )
840 vlc_object_hold( p_input );
841 aout_instance_t *p_aout = THEMIM->getAout();
842 AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
844 vlc_object_release( p_aout );
845 vlc_object_release( p_input );
847 QMenu *menu = new QMenu();
851 /* Navigation stuff, and general menus ( open ), used only for skins */
852 void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf )
858 vlc_object_hold( p_input );
859 varnames.push_back( "audio-es" );
860 InputAutoMenuBuilder( p_input, objects, varnames );
864 QMenu *menu = new QMenu();
865 Populate( p_intf, menu, varnames, objects );
867 menu->addSeparator();
868 PopupPlayEntries( menu, p_intf, p_input );
869 PopupMenuPlaylistControlEntries( menu, p_intf);
871 menu->addSeparator();
872 PopupMenuControlEntries( menu, p_intf );
874 menu->addSeparator();
875 PopupMenuStaticEntries( menu );
877 p_intf->p_sys->p_popup_menu = menu;
878 menu->popup( QCursor::pos() );
879 p_intf->p_sys->p_popup_menu = NULL;
882 /* Main Menu that sticks everything together */
883 void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show )
885 /* Destroy popup menu if there is one */
888 delete p_intf->p_sys->p_popup_menu;
889 p_intf->p_sys->p_popup_menu = NULL;
893 /* Delete and recreate a popup if there is one */
894 if( p_intf->p_sys->p_popup_menu )
895 delete p_intf->p_sys->p_popup_menu;
898 QMenu *menu = new QMenu();
901 bool b_isFullscreen = false;
902 MainInterface *mi = p_intf->p_sys->p_mi;
906 PopupPlayEntries( menu, p_intf, p_input );
907 PopupMenuPlaylistControlEntries( menu, p_intf );
908 menu->addSeparator();
912 vout_thread_t *p_vout = THEMIM->getVout();
914 /* Add a fullscreen switch button, since it is the most used function */
917 vlc_value_t val; var_Get( p_vout, "fullscreen", &val );
919 b_isFullscreen = !( !val.b_bool );
921 CreateAndConnect( menu, "fullscreen",
922 qtr( "Leave Fullscreen" ),"" , ITEM_NORMAL,
923 VLC_OBJECT(p_vout), val, VLC_VAR_BOOL, b_isFullscreen );
924 vlc_object_release( p_vout );
926 menu->addSeparator();
930 vlc_object_hold( p_input );
931 InputAutoMenuBuilder( p_input, objects, varnames );
932 vlc_object_release( p_input );
935 submenu = new QMenu( menu );
936 action = menu->addMenu( AudioMenu( p_intf, submenu ) );
937 action->setText( qtr( "&Audio" ) );
938 if( action->menu()->isEmpty() )
939 action->setEnabled( false );
942 submenu = new QMenu( menu );
943 action = menu->addMenu( VideoMenu( p_intf, submenu ) );
944 action->setText( qtr( "&Video" ) );
945 if( action->menu()->isEmpty() )
946 action->setEnabled( false );
948 /* Playback menu for chapters */
949 submenu = new QMenu( menu );
950 action = menu->addMenu( NavigMenu( p_intf, submenu ) );
951 action->setText( qtr( "&Playback" ) );
952 if( action->menu()->isEmpty() )
953 action->setEnabled( false );
956 menu->addSeparator();
958 /* Add some special entries for windowed mode: Interface Menu */
959 if( !b_isFullscreen )
961 submenu = new QMenu( qtr( "Interface" ), menu );
962 QMenu *tools = ToolsMenu( submenu );
963 submenu->addSeparator();
965 /* In skins interface, append some items */
968 objects.clear(); varnames.clear();
970 vlc_object_t *p_object = ( vlc_object_t* )
971 vlc_object_find_name( p_intf, "skins2", FIND_PARENT );
974 objects.push_back( p_object );
975 varnames.push_back( "intf-skins" );
976 Populate( p_intf, submenu, varnames, objects );
977 vlc_object_release( p_object );
980 msg_Warn( p_intf, "could not find parent interface" );
983 menu->addMenu( ViewMenu( p_intf, mi, false ));
985 menu->addMenu( submenu );
988 /* Static entries for ending, like open */
989 PopupMenuStaticEntries( menu );
991 p_intf->p_sys->p_popup_menu = menu;
992 p_intf->p_sys->p_popup_menu->popup( QCursor::pos() );
999 /************************************************************************
1001 ************************************************************************/
1003 void QVLCMenu::updateSystrayMenu( MainInterface *mi,
1004 intf_thread_t *p_intf,
1005 bool b_force_visible )
1009 /* Get the systray menu and clean it */
1010 QMenu *sysMenu = mi->getSysTrayMenu();
1013 /* Hide / Show VLC and cone */
1014 if( mi->isVisible() || b_force_visible )
1016 sysMenu->addAction( QIcon( ":/vlc16.png" ),
1017 qtr( "Hide VLC media player in taskbar" ), mi,
1018 SLOT( toggleUpdateSystrayMenu() ) );
1022 sysMenu->addAction( QIcon( ":/vlc16.png" ),
1023 qtr( "Show VLC media player" ), mi,
1024 SLOT( toggleUpdateSystrayMenu() ) );
1027 sysMenu->addSeparator();
1028 PopupPlayEntries( sysMenu, p_intf, p_input );
1029 PopupMenuPlaylistControlEntries( sysMenu, p_intf);
1030 PopupMenuControlEntries( sysMenu, p_intf);
1032 sysMenu->addSeparator();
1033 addDPStaticEntry( sysMenu, qtr( "&Open Media" ),
1034 ":/file-wide", SLOT( openFileDialog() ) );
1035 addDPStaticEntry( sysMenu, qtr( "&Quit" ) ,
1036 ":/quit", SLOT( quit() ) );
1039 mi->getSysTray()->setContextMenu( sysMenu );
1043 #undef PUSH_SEPARATOR
1045 /*************************************************************************
1046 * Builders for automenus
1047 *************************************************************************/
1048 QMenu * QVLCMenu::Populate( intf_thread_t *p_intf,
1050 vector< const char *> & varnames,
1051 vector<vlc_object_t *> & objects )
1053 QMenu *menu = current;
1056 currentGroup = NULL;
1058 vlc_object_t *p_object;
1060 for( int i = 0; i < ( int )objects.size() ; i++ )
1062 if( !varnames[i] || !*varnames[i] )
1064 menu->addSeparator();
1067 p_object = objects[i];
1069 UpdateItem( p_intf, menu, varnames[i], p_object, true );
1074 /*****************************************************************************
1076 *****************************************************************************/
1078 static bool IsMenuEmpty( const char *psz_var,
1079 vlc_object_t *p_object,
1080 bool b_root = true )
1082 vlc_value_t val, val_list;
1083 int i_type, i_result, i;
1085 /* Check the type of the object variable */
1086 i_type = var_Type( p_object, psz_var );
1088 /* Check if we want to display the variable */
1089 if( !( i_type & VLC_VAR_HASCHOICE ) ) return false;
1091 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
1092 if( val.i_int == 0 ) return true;
1094 if( ( i_type & VLC_VAR_TYPE ) != VLC_VAR_VARIABLE )
1096 if( val.i_int == 1 && b_root ) return true;
1100 /* Check children variables in case of VLC_VAR_VARIABLE */
1101 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
1106 for( i = 0, i_result = true; i < val_list.p_list->i_count; i++ )
1108 if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
1116 /* clean up everything */
1117 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, NULL );
1122 #define TEXT_OR_VAR qfu ( text.psz_string ? text.psz_string : psz_var )
1124 void QVLCMenu::UpdateItem( intf_thread_t *p_intf, QMenu *menu,
1125 const char *psz_var, vlc_object_t *p_object, bool b_submenu )
1127 vlc_value_t val, text;
1130 QAction *action = FindActionWithVar( menu, psz_var );
1132 DeleteNonStaticEntries( action->menu() );
1137 action->setEnabled( false );
1141 /* Check the type of the object variable */
1142 /* What is the following HACK needed for? */
1143 if( !strcmp( psz_var, "audio-es" )
1144 || !strcmp( psz_var, "video-es" ) )
1145 i_type = VLC_VAR_INTEGER | VLC_VAR_HASCHOICE;
1147 i_type = var_Type( p_object, psz_var );
1149 switch( i_type & VLC_VAR_TYPE )
1153 case VLC_VAR_VARIABLE:
1154 case VLC_VAR_STRING:
1155 case VLC_VAR_INTEGER:
1159 /* Variable doesn't exist or isn't handled */
1161 action->setEnabled( false );
1165 /* Make sure we want to display the variable */
1166 if( menu->isEmpty() && IsMenuEmpty( psz_var, p_object ) )
1169 action->setEnabled( false );
1173 /* Get the descriptive name of the variable */
1174 int i_ret = var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
1175 if( i_ret != VLC_SUCCESS )
1177 text.psz_string = NULL;
1182 action = new QAction( TEXT_OR_VAR, menu );
1183 menu->addAction( action );
1184 action->setData( psz_var );
1187 /* Some specific stuff */
1188 bool forceDisabled = false;
1189 if( !strcmp( psz_var, "spu-es" ) )
1191 vout_thread_t *p_vout = THEMIM->getVout();
1192 forceDisabled = ( p_vout == NULL );
1194 vlc_object_release( p_vout );
1197 if( i_type & VLC_VAR_HASCHOICE )
1199 /* Append choices menu */
1203 submenu = action->menu();
1206 submenu = new QMenu( menu );
1207 action->setMenu( submenu );
1211 CreateChoicesMenu( submenu, psz_var, p_object, true ) == 0 );
1213 action->setEnabled( false );
1218 CreateChoicesMenu( menu, psz_var, p_object, true ) == 0 );
1220 FREENULL( text.psz_string );
1224 switch( i_type & VLC_VAR_TYPE )
1227 var_Get( p_object, psz_var, &val );
1228 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_NORMAL,
1229 p_object, val, i_type );
1233 var_Get( p_object, psz_var, &val );
1234 val.b_bool = !val.b_bool;
1235 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_CHECK,
1236 p_object, val, i_type, !val.b_bool );
1239 FREENULL( text.psz_string );
1243 int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
1244 vlc_object_t *p_object, bool b_root )
1246 vlc_value_t val, val_list, text_list;
1249 /* Check the type of the object variable */
1250 i_type = var_Type( p_object, psz_var );
1252 /* Make sure we want to display the variable */
1253 if( submenu->isEmpty() && IsMenuEmpty( psz_var, p_object, b_root ) )
1254 return VLC_EGENERIC;
1256 switch( i_type & VLC_VAR_TYPE )
1260 case VLC_VAR_VARIABLE:
1261 case VLC_VAR_STRING:
1262 case VLC_VAR_INTEGER:
1266 /* Variable doesn't exist or isn't handled */
1267 return VLC_EGENERIC;
1270 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
1271 &val_list, &text_list ) < 0 )
1273 return VLC_EGENERIC;
1276 #define CURVAL val_list.p_list->p_values[i]
1277 #define CURTEXT text_list.p_list->p_values[i].psz_string
1279 for( i = 0; i < val_list.p_list->i_count; i++ )
1281 vlc_value_t another_val;
1283 QMenu *subsubmenu = new QMenu( submenu );
1285 switch( i_type & VLC_VAR_TYPE )
1287 case VLC_VAR_VARIABLE:
1288 CreateChoicesMenu( subsubmenu, CURVAL.psz_string, p_object, false );
1289 subsubmenu->setTitle( qfu( CURTEXT ? CURTEXT :CURVAL.psz_string ) );
1290 submenu->addMenu( subsubmenu );
1293 case VLC_VAR_STRING:
1294 var_Get( p_object, psz_var, &val );
1295 another_val.psz_string = strdup( CURVAL.psz_string );
1296 menutext = qfu( CURTEXT ? CURTEXT : another_val.psz_string );
1297 CreateAndConnect( submenu, psz_var, menutext, "", ITEM_RADIO,
1298 p_object, another_val, i_type,
1299 val.psz_string && !strcmp( val.psz_string, CURVAL.psz_string ) );
1301 free( val.psz_string );
1304 case VLC_VAR_INTEGER:
1305 var_Get( p_object, psz_var, &val );
1306 if( CURTEXT ) menutext = qfu( CURTEXT );
1307 else menutext.sprintf( "%d", CURVAL.i_int );
1308 CreateAndConnect( submenu, psz_var, menutext, "", ITEM_RADIO,
1309 p_object, CURVAL, i_type,
1310 CURVAL.i_int == val.i_int );
1314 var_Get( p_object, psz_var, &val );
1315 if( CURTEXT ) menutext = qfu( CURTEXT );
1316 else menutext.sprintf( "%.2f", CURVAL.f_float );
1317 CreateAndConnect( submenu, psz_var, menutext, "", ITEM_RADIO,
1318 p_object, CURVAL, i_type,
1319 CURVAL.f_float == val.f_float );
1326 currentGroup = NULL;
1328 /* clean up everything */
1329 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
1333 return submenu->isEmpty() ? VLC_EGENERIC : VLC_SUCCESS;
1336 void QVLCMenu::CreateAndConnect( QMenu *menu, const char *psz_var,
1337 QString text, QString help,
1338 int i_item_type, vlc_object_t *p_obj,
1339 vlc_value_t val, int i_val_type,
1342 QAction *action = FindActionWithVar( menu, psz_var );
1347 action = new QAction( text, menu );
1348 menu->addAction( action );
1352 action->setToolTip( help );
1353 action->setEnabled( p_obj != NULL );
1355 if( i_item_type == ITEM_CHECK )
1357 action->setCheckable( true );
1359 else if( i_item_type == ITEM_RADIO )
1361 action->setCheckable( true );
1363 currentGroup = new QActionGroup( menu );
1364 currentGroup->addAction( action );
1367 action->setChecked( checked );
1369 MenuItemData *itemData = new MenuItemData( THEDP->menusMapper, p_obj, i_val_type,
1371 CONNECT( action, triggered(), THEDP->menusMapper, map() );
1372 THEDP->menusMapper->setMapping( action, itemData );
1375 menu->addAction( action );
1378 void QVLCMenu::DoAction( QObject *data )
1380 MenuItemData *itemData = qobject_cast<MenuItemData *>( data );
1381 vlc_object_t *p_object = itemData->p_obj;
1382 if( p_object == NULL ) return;
1384 var_Set( p_object, itemData->psz_var, itemData->val );
1387 void QVLCMenu::updateRecents( intf_thread_t *p_intf )
1392 RecentsMRL* rmrl = RecentsMRL::getInstance( p_intf );
1393 QList<QString> l = rmrl->recents();
1395 recentsMenu->clear();
1398 action = recentsMenu->addAction( qtr(" - Empty - ") );
1399 action->setEnabled( false );
1403 for( int i = 0; i < l.size(); ++i )
1405 action = recentsMenu->addAction(
1406 QString( "&%1: " ).arg( i + 1 ) + l.at( i ),
1409 rmrl->signalMapper->setMapping( action, l.at( i ) );
1412 recentsMenu->addSeparator();
1413 recentsMenu->addAction( qtr("&Clear"), rmrl, SLOT( clear() ) );