1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright © 2006-2011 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
30 #define __STDC_FORMAT_MACROS 1
31 #define __STDC_CONSTANT_MACROS 1
37 #include <vlc_common.h>
38 #include <vlc_intf_strings.h>
39 #include <vlc_vout.h> /* vout_thread_t */
43 #include "main_interface.hpp" /* View modifications */
44 #include "dialogs_provider.hpp" /* Dialogs display */
45 #include "input_manager.hpp" /* Input Management */
46 #include "recents.hpp" /* Recent Items */
47 #include "actions_manager.hpp" /* Actions Management: play+volume */
48 #include "extensions_manager.hpp" /* Extensions menu*/
53 #include <QActionGroup>
54 #include <QSignalMapper>
55 #include <QSystemTrayIcon>
57 #include <QFontMetrics>
60 This file defines the main menus and the pop-up menu (right-click menu)
61 and the systray menu (in that order in the file)
63 There are 4 menus that have to be rebuilt everytime there are called:
64 Audio, Video, Navigation, view
65 4 functions are building those menus: AudioMenu, VideoMenu, NavigMenu, View
66 and 3 functions associated are collecting the objects :
67 InputAutoMenuBuilder, AudioAutoMenuBuilder, VideoAutoMenuBuilder.
69 A QSignalMapper decides when to rebuild those menus cf MenuFunc in the .hpp
70 Just before one of those menus are aboutToShow(), they are rebuild.
73 #define STATIC_ENTRY "__static__"
74 #define ENTRY_ALWAYS_ENABLED "__ignore__"
78 ITEM_NORMAL, /* not a checkbox, nor a radio */
79 ITEM_CHECK, /* Checkbox */
80 ITEM_RADIO /* Radiobox */
83 static QActionGroup *currentGroup;
85 QMenu *QVLCMenu::recentsMenu = NULL;
88 * @brief Add static entries to DP in menus
90 QAction *addDPStaticEntry( QMenu *menu,
94 const char *shortcut = NULL,
95 QAction::MenuRole = QAction::NoRole
98 QAction *action = NULL;
99 #ifndef __APPLE__ /* We don't set icons in menus in MacOS X */
100 if( !EMPTY_STR( icon ) )
102 if( !EMPTY_STR( shortcut ) )
103 action = menu->addAction( QIcon( icon ), text, THEDP,
104 member, qtr( shortcut ) );
106 action = menu->addAction( QIcon( icon ), text, THEDP, member );
111 if( !EMPTY_STR( shortcut ) )
112 action = menu->addAction( text, THEDP, member, qtr( shortcut ) );
114 action = menu->addAction( text, THEDP, member );
116 action->setData( STATIC_ENTRY );
121 * @brief Add static entries to MIM in menus
123 QAction* addMIMStaticEntry( intf_thread_t *p_intf,
128 bool bStatic = false )
131 #ifndef __APPLE__ /* We don't set icons in menus in MacOS X */
132 if( !EMPTY_STR( icon ) )
134 action = menu->addAction( text, THEMIM, member );
135 action->setIcon( QIcon( icon ) );
140 action = menu->addAction( text, THEMIM, member );
142 action->setData( bStatic ? STATIC_ENTRY : ENTRY_ALWAYS_ENABLED );
147 * @brief Enable all static entries of a menu, disable the others
148 * @param menu the menu in which the entries will be disabled
149 * @param enable if false, disable all entries
151 void EnableStaticEntries( QMenu *menu, bool enable = true )
155 QList< QAction* > actions = menu->actions();
156 for( int i = 0; i < actions.size(); ++i )
158 actions[i]->setEnabled( actions[i]->data().toString()
159 == ENTRY_ALWAYS_ENABLED ||
160 /* Be careful here, because data("string").toBool is true */
161 ( enable && (actions[i]->data().toString() == STATIC_ENTRY ) ) );
166 * \return Number of static entries
168 inline int DeleteNonStaticEntries( QMenu *menu )
170 if( !menu ) return VLC_EGENERIC;
174 QList< QAction* > actions = menu->actions();
175 for( int i = 0; i < actions.size(); ++i )
177 if( actions[i]->data().toString() != STATIC_ENTRY )
186 * \return QAction associated to psz_var variable
188 static QAction * FindActionWithVar( QMenu *menu, const char *psz_var )
190 QList< QAction* > actions = menu->actions();
191 for( int i = 0; i < actions.size(); ++i )
193 if( actions[i]->data().toString() == psz_var )
199 /*****************************************************************************
200 * Definitions of variables for the dynamic menus
201 *****************************************************************************/
202 #define PUSH_VAR( var ) varnames.push_back( var ); \
203 objects.push_back( VLC_OBJECT(p_object) )
205 #define PUSH_INPUTVAR( var ) varnames.push_back( var ); \
206 objects.push_back( VLC_OBJECT(p_input) );
208 static int InputAutoMenuBuilder( input_thread_t *p_object,
209 vector<vlc_object_t *> &objects,
210 vector<const char *> &varnames )
212 PUSH_VAR( "bookmark" );
214 PUSH_VAR( "chapter" );
215 PUSH_VAR( "navigation" );
216 PUSH_VAR( "program" );
220 static int VideoAutoMenuBuilder( vout_thread_t *p_object,
221 input_thread_t *p_input,
222 vector<vlc_object_t *> &objects,
223 vector<const char *> &varnames )
225 PUSH_INPUTVAR( "video-es" );
226 PUSH_INPUTVAR( "spu-es" );
227 PUSH_VAR( "fullscreen" );
228 PUSH_VAR( "video-on-top" );
229 PUSH_VAR( "video-wallpaper" );
231 PUSH_VAR( "direct3d-desktop" );
233 PUSH_VAR( "video-snapshot" );
235 PUSH_VAR( "autoscale" );
236 PUSH_VAR( "aspect-ratio" );
238 PUSH_VAR( "deinterlace" );
239 PUSH_VAR( "deinterlace-mode" );
240 PUSH_VAR( "postprocess" );
245 static int AudioAutoMenuBuilder( aout_instance_t *p_object,
246 input_thread_t *p_input,
247 vector<vlc_object_t *> &objects,
248 vector<const char *> &varnames )
250 PUSH_INPUTVAR( "audio-es" );
251 PUSH_VAR( "audio-channels" );
252 PUSH_VAR( "audio-device" );
253 PUSH_VAR( "visual" );
257 /*****************************************************************************
260 *****************************************************************************/
263 static inline void addMenuToMainbar( QMenu *func, QString title, QMenuBar *bar ) {
264 func->setTitle( title );
269 #define BAR_DADD( func, title, id ) { \
270 QMenu *_menu = func; _menu->setTitle( title ); bar->addMenu( _menu ); \
271 MenuFunc *f = new MenuFunc( _menu, id ); \
272 CONNECT( _menu, aboutToShow(), THEDP->menusUpdateMapper, map() ); \
273 THEDP->menusUpdateMapper->setMapping( _menu, f ); }
275 // Add a simple action
276 static inline void addAction( QMenu *_menu, QVariant val, QString title ) {
277 QAction *_action = new QAction( title, _menu );
278 _action->setData( val );
279 _menu->addAction( _action );
282 // Add an action with a submenu
283 static inline void addActionWithSubmenu( QMenu *_menu, QVariant val, QString title ) {
284 QAction *_action = new QAction( title, _menu );
285 _action->setData( val );
286 _action->setMenu( new QMenu( _menu ) );
287 _menu->addAction( _action );
290 // Add an action that is a checkbox
291 static inline void addActionWithCheckbox( QMenu *_menu, QVariant val, QString title ) {
292 QAction *_action = new QAction( title, _menu );
293 _action->setData( val );
294 _action->setCheckable( true );
295 _menu->addAction( _action );
299 * Main Menu Bar Creation
301 void QVLCMenu::createMenuBar( MainInterface *mi,
302 intf_thread_t *p_intf )
304 /* QMainWindows->menuBar()
305 gives the QProcess::destroyed timeout issue on Cleanlooks style with
306 setDesktopAware set to false */
307 QMenuBar *bar = mi->menuBar();
309 addMenuToMainbar( FileMenu( p_intf, bar, mi ), qtr( "&Media" ), bar );
311 /* Dynamic menus, rebuilt before being showed */
312 BAR_DADD( NavigMenu( p_intf, bar ), qtr( "P&layback" ), 3 );
313 BAR_DADD( AudioMenu( p_intf, bar ), qtr( "&Audio" ), 1 );
314 BAR_DADD( VideoMenu( p_intf, bar ), qtr( "&Video" ), 2 );
316 addMenuToMainbar( ToolsMenu( bar ), qtr( "&Tools" ), bar );
318 /* View menu, a bit different */
319 BAR_DADD( ViewMenu( p_intf, NULL, mi ), qtr( "V&iew" ), 4 );
321 addMenuToMainbar( HelpMenu( bar ), qtr( "&Help" ), bar );
326 * Media ( File ) Menu
327 * Opening, streaming and quit
329 QMenu *QVLCMenu::FileMenu( intf_thread_t *p_intf, QWidget *parent, MainInterface *mi )
331 QMenu *menu = new QMenu( parent );
334 addDPStaticEntry( menu, qtr( "Open &File..." ),
335 ":/type/file-asym", SLOT( simpleOpenDialog() ), "Ctrl+O" );
336 addDPStaticEntry( menu, qtr( I_OP_OPDIR ),
337 ":/type/folder-grey", SLOT( PLOpenDir() ), "Ctrl+F" );
338 addDPStaticEntry( menu, qtr( "Open &Disc..." ),
339 ":/type/disc", SLOT( openDiscDialog() ), "Ctrl+D" );
340 addDPStaticEntry( menu, qtr( "Open &Network Stream..." ),
341 ":/type/network", SLOT( openNetDialog() ), "Ctrl+N" );
342 addDPStaticEntry( menu, qtr( "Open &Capture Device..." ),
343 ":/type/capture-card", SLOT( openCaptureDialog() ), "Ctrl+C" );
345 menu->addSeparator();
347 addDPStaticEntry( menu, qtr( "&Open (advanced)..." ),
348 ":/type/file-asym", SLOT( openFileDialog() ), "Ctrl+Shift+O" );
349 menu->addSeparator();
351 addDPStaticEntry( menu, qtr( "Open &Location from clipboard" ),
352 NULL, SLOT( openUrlDialog() ), "Ctrl+V" );
354 if( var_InheritBool( p_intf, "qt-recentplay" ) )
356 recentsMenu = new QMenu( qtr( "Open &Recent Media" ), menu );
357 updateRecents( p_intf );
358 menu->addMenu( recentsMenu );
360 menu->addSeparator();
362 addDPStaticEntry( menu, qtr( I_PL_SAVE ), "", SLOT( saveAPlaylist() ),
364 menu->addSeparator();
367 addDPStaticEntry( menu, qtr( "Conve&rt / Save..." ), "",
368 SLOT( openAndTranscodingDialogs() ), "Ctrl+R" );
369 addDPStaticEntry( menu, qtr( "&Stream..." ),
370 ":/menu/stream", SLOT( openAndStreamingDialogs() ), "Ctrl+S" );
371 menu->addSeparator();
374 action = addMIMStaticEntry( p_intf, menu, qtr( "Quit at the end of playlist" ), "",
375 SLOT( activatePlayQuit( bool ) ) );
376 action->setCheckable( true );
377 action->setChecked( THEMIM->getPlayExitState() );
379 if( mi->getSysTray() )
381 action = menu->addAction( qtr( "Close to systray"), mi,
382 SLOT( toggleUpdateSystrayMenu() ) );
385 addDPStaticEntry( menu, qtr( "&Quit" ) ,
386 ":/menu/quit", SLOT( quit() ), "Ctrl+Q" );
391 * Tools, like Media Information, Preferences or Messages
393 QMenu *QVLCMenu::ToolsMenu( QMenu *menu )
395 addDPStaticEntry( menu, qtr( "&Effects and Filters"), ":/menu/settings",
396 SLOT( extendedDialog() ), "Ctrl+E" );
398 addDPStaticEntry( menu, qtr( "&Track Synchronization"), ":/menu/settings",
399 SLOT( synchroDialog() ), "" );
401 addDPStaticEntry( menu, qtr( I_MENU_INFO ) , ":/menu/info",
402 SLOT( mediaInfoDialog() ), "Ctrl+I" );
403 addDPStaticEntry( menu, qtr( I_MENU_CODECINFO ) ,
404 ":/menu/info", SLOT( mediaCodecDialog() ), "Ctrl+J" );
407 addDPStaticEntry( menu, qtr( I_MENU_VLM ), "", SLOT( vlmDialog() ),
411 addDPStaticEntry( menu, qtr( "Program Guide" ), "", SLOT( epgDialog() ),
414 addDPStaticEntry( menu, qtr( I_MENU_MSG ),
415 ":/menu/messages", SLOT( messagesDialog() ), "Ctrl+M" );
417 addDPStaticEntry( menu, qtr( "Plu&gins and extensions" ),
418 "", SLOT( pluginDialog() ) );
419 menu->addSeparator();
421 addDPStaticEntry( menu, qtr( "Customi&ze Interface..." ),
422 ":/menu/preferences", SLOT( toolbarDialog() ) );
424 addDPStaticEntry( menu, qtr( "&Preferences" ),
425 ":/menu/preferences", SLOT( prefsDialog() ), "Ctrl+P", QAction::PreferencesRole );
432 * Interface modification, load other interfaces, activate Extensions
433 * \param current, set to NULL for menu creation, else for menu update
435 QMenu *QVLCMenu::ViewMenu( intf_thread_t *p_intf, QMenu *current, MainInterface *_mi )
440 MainInterface *mi = _mi ? _mi : p_intf->p_sys->p_mi;
445 menu = new QMenu( qtr( "&View" ), mi );
451 //HACK menu->clear() does not delete submenus
452 QList<QAction*> actions = menu->actions();
453 foreach( QAction *a, actions )
455 QMenu *m = a->menu();
456 if( a->parent() == menu ) delete a;
457 else menu->removeAction( a );
458 if( m && m->parent() == menu ) delete m;
464 QIcon( ":/menu/playlist_menu" ),
466 qtr( "Play&list" ), mi,
467 SLOT( togglePlaylist() ), qtr( "Ctrl+L" ) );
469 menu->addSeparator();
472 action = menu->addAction( qtr( "Mi&nimal Interface" ) );
473 action->setShortcut( qtr( "Ctrl+H" ) );
474 action->setCheckable( true );
475 action->setChecked( (mi->getControlsVisibilityStatus() & CONTROLS_HIDDEN ) );
477 CONNECT( action, triggered( bool ), mi, toggleMinimalView( bool ) );
478 CONNECT( mi, minimalViewToggled( bool ), action, setChecked( bool ) );
480 /* FullScreen View */
481 action = menu->addAction( qtr( "&Fullscreen Interface" ), mi,
482 SLOT( toggleInterfaceFullScreen() ), QString( "F11" ) );
483 action->setCheckable( true );
484 action->setChecked( mi->isInterfaceFullScreen() );
485 CONNECT( mi, fullscreenInterfaceToggled( bool ),
486 action, setChecked( bool ) );
488 /* Advanced Controls */
489 action = menu->addAction( qtr( "&Advanced Controls" ), mi,
490 SLOT( toggleAdvancedButtons() ) );
491 action->setCheckable( true );
492 if( mi->getControlsVisibilityStatus() & CONTROLS_ADVANCED )
493 action->setChecked( true );
495 /* Docked Playlist */
496 action = menu->addAction( qtr( "Docked Playlist" ) );
497 action->setCheckable( true );
498 action->setChecked( mi->isPlDocked() );
499 CONNECT( action, triggered( bool ), mi, dockPlaylist( bool ) );
501 action = menu->addAction( qtr( "Status Bar" ) );
502 action->setCheckable( true );
503 action->setChecked( mi->statusBar()->isVisible() );
504 CONNECT( action, triggered( bool ), mi, setStatusBarVisibility( bool) );
505 #if 0 /* For Visualisations. Not yet working */
506 adv = menu->addAction( qtr( "Visualizations selector" ), mi,
508 adv->setCheckable( true );
509 if( visual_selector_enabled ) adv->setChecked( true );
512 menu->addSeparator();
514 InterfacesMenu( p_intf, menu );
515 menu->addSeparator();
518 ExtensionsMenu( p_intf, menu );
524 * Interface Sub-Menu, to list extras interface and skins
526 QMenu *QVLCMenu::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
528 vector<vlc_object_t *> objects;
529 vector<const char *> varnames;
530 varnames.push_back( "intf-add" );
531 objects.push_back( VLC_OBJECT(p_intf) );
533 return Populate( p_intf, current, varnames, objects );
537 * Extensions menu: populate the current menu with extensions
539 void QVLCMenu::ExtensionsMenu( intf_thread_t *p_intf, QMenu *extMenu )
541 /* Get ExtensionsManager and load extensions if needed */
542 ExtensionsManager *extMgr = ExtensionsManager::getInstance( p_intf );
544 if( !var_InheritBool( p_intf, "qt-autoload-extensions")
545 && !extMgr->isLoaded() )
550 if( !extMgr->isLoaded() && !extMgr->cannotLoad() )
552 extMgr->loadExtensions();
555 /* Let the ExtensionsManager build itself the menu */
556 extMenu->addSeparator();
557 extMgr->menu( extMenu );
563 QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QMenu * current )
565 vector<vlc_object_t *> objects;
566 vector<const char *> varnames;
567 aout_instance_t *p_aout;
568 input_thread_t *p_input;
570 if( current->isEmpty() )
572 addActionWithSubmenu( current, "audio-es", qtr( "Audio &Track" ) );
573 addActionWithSubmenu( current, "audio-channels", qtr( "Audio &Channels" ) );
574 addActionWithSubmenu( current, "audio-device", qtr( "Audio &Device" ) );
575 current->addSeparator();
577 addActionWithSubmenu( current, "visual", qtr( "&Visualizations" ) );
578 current->addSeparator();
580 QAction *action = current->addAction( qtr( "Increase Volume" ),
581 ActionsManager::getInstance( p_intf ), SLOT( AudioUp() ) );
582 action->setData( STATIC_ENTRY );
583 action = current->addAction( qtr( "Decrease Volume" ),
584 ActionsManager::getInstance( p_intf ), SLOT( AudioDown() ) );
585 action->setData( STATIC_ENTRY );
586 action = current->addAction( qtr( "Mute" ),
587 ActionsManager::getInstance( p_intf ), SLOT( toggleMuteAudio() ) );
588 action->setData( STATIC_ENTRY );
591 p_input = THEMIM->getInput();
592 p_aout = THEMIM->getAout();
593 EnableStaticEntries( current, ( p_aout != NULL ) );
594 AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
597 vlc_object_release( p_aout );
600 return Populate( p_intf, current, varnames, objects );
604 QMenu *QVLCMenu::SubtitleMenu( QMenu *current )
607 QMenu *submenu = new QMenu( qtr( "&Subtitles Track" ), current );
608 action = current->addMenu( submenu );
609 action->setData( "spu-es" );
610 addDPStaticEntry( submenu, qtr( "Open File..." ), "",
611 SLOT( loadSubtitlesFile() ) );
612 submenu->addSeparator();
618 * Subtitles are part of Video.
620 QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current, bool b_subtitle )
622 vout_thread_t *p_vout;
623 input_thread_t *p_input;
624 vector<vlc_object_t *> objects;
625 vector<const char *> varnames;
627 if( current->isEmpty() )
629 addActionWithSubmenu( current, "video-es", qtr( "Video &Track" ) );
631 SubtitleMenu( current );
633 current->addSeparator();
635 addActionWithCheckbox( current, "fullscreen", qtr( "&Fullscreen" ) );
636 addActionWithCheckbox( current, "autoscale", qtr( "Always Fit &Window" ) );
637 addActionWithCheckbox( current, "video-on-top", qtr( "Always &on Top" ) );
639 addActionWithCheckbox( current, "direct3d-desktop", qtr( "Display on &Desktop" ) );
641 addAction( current, "video-snapshot", qtr( "Take &Snapshot" ) );
643 addActionWithCheckbox( current, "video-wallpaper", qtr( "Set as Wall&paper" ) );
645 current->addSeparator();
647 addActionWithSubmenu( current, "zoom", qtr( "&Zoom" ) );
648 addActionWithSubmenu( current, "aspect-ratio", qtr( "&Aspect Ratio" ) );
649 addActionWithSubmenu( current, "crop", qtr( "&Crop" ) );
650 addActionWithSubmenu( current, "deinterlace", qtr( "&Deinterlace" ) );
651 addActionWithSubmenu( current, "deinterlace-mode", qtr( "&Deinterlace mode" ) );
652 addActionWithSubmenu( current, "postprocess", qtr( "&Post processing" ) );
655 p_input = THEMIM->getInput();
657 p_vout = THEMIM->getVout();
658 VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
661 vlc_object_release( p_vout );
663 return Populate( p_intf, current, varnames, objects );
668 * For DVD, MP4, MOV and other chapter based format
670 QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *menu )
674 addActionWithSubmenu( menu, "title", qtr( "T&itle" ) );
675 addActionWithSubmenu( menu, "chapter", qtr( "&Chapter" ) );
676 addActionWithSubmenu( menu, "navigation", qtr( "&Navigation" ) );
677 addActionWithSubmenu( menu, "program", qtr( "&Program" ) );
679 /* FixMe: sync I_MENU_BOOKMARK string */
680 QMenu *submenu = new QMenu( qtr( "Custom &Bookmarks" ), menu );
681 addDPStaticEntry( submenu, qtr( "&Manage" ), "",
682 SLOT( bookmarksDialog() ), "Ctrl+B" );
683 submenu->addSeparator();
684 action = menu->addMenu( submenu );
685 action->setData( "bookmark" );
687 menu->addSeparator();
688 PopupMenuPlaylistControlEntries( menu, p_intf );
689 PopupMenuControlEntries( menu, p_intf );
691 EnableStaticEntries( menu, ( THEMIM->getInput() != NULL ) );
692 return RebuildNavigMenu( p_intf, menu );
695 QMenu *QVLCMenu::RebuildNavigMenu( intf_thread_t *p_intf, QMenu *menu )
698 input_thread_t *p_object;
699 vector<vlc_object_t *> objects;
700 vector<const char *> varnames;
702 /* Get the input and hold it */
703 p_object = THEMIM->getInput();
705 InputAutoMenuBuilder( p_object, objects, varnames );
707 menu->addSeparator();
709 /* Title and so on */
710 PUSH_VAR( "prev-title" );
711 PUSH_VAR( "next-title" );
712 PUSH_VAR( "prev-chapter" );
713 PUSH_VAR( "next-chapter" );
715 EnableStaticEntries( menu, (p_object != NULL ) );
716 return Populate( p_intf, menu, varnames, objects );
722 QMenu *QVLCMenu::HelpMenu( QWidget *parent )
724 QMenu *menu = new QMenu( parent );
725 addDPStaticEntry( menu, qtr( "&Help..." ) ,
726 ":/menu/help", SLOT( helpDialog() ), "F1" );
728 addDPStaticEntry( menu, qtr( "Check for &Updates..." ) , "",
729 SLOT( updateDialog() ) );
731 menu->addSeparator();
732 addDPStaticEntry( menu, qtr( I_MENU_ABOUT ), ":/menu/info",
733 SLOT( aboutDialog() ), "Shift+F1", QAction::AboutRole );
737 /*****************************************************************************
738 * Popup menus - Right Click menus *
739 *****************************************************************************/
740 #define POPUP_BOILERPLATE \
741 static QMenu* menu = NULL; \
742 delete menu; menu = NULL; \
745 vector<vlc_object_t *> objects; \
746 vector<const char *> varnames; \
747 input_thread_t *p_input = THEMIM->getInput();
749 #define CREATE_POPUP \
750 menu = new QMenu(); \
751 Populate( p_intf, menu, varnames, objects ); \
752 menu->popup( QCursor::pos() ); \
754 void QVLCMenu::PopupPlayEntries( QMenu *menu,
755 intf_thread_t *p_intf,
756 input_thread_t *p_input )
760 /* Play or Pause action and icon */
761 if( !p_input || var_GetInteger( p_input, "state" ) != PLAYING_S )
763 action = menu->addAction( qtr( "Play" ),
764 ActionsManager::getInstance( p_intf ), SLOT( play() ) );
765 #ifndef __APPLE__ /* No icons in menus in Mac */
766 action->setIcon( QIcon( ":/menu/play" ) );
771 addMIMStaticEntry( p_intf, menu, qtr( "Pause" ),
772 ":/menu/pause", SLOT( togglePlayPause() ) );
776 void QVLCMenu::PopupMenuControlEntries( QMenu *menu, intf_thread_t *p_intf )
781 action = menu->addAction( qtr( "&Faster" ), THEMIM->getIM(),
783 #ifndef __APPLE__ /* No icons in menus in Mac */
784 action->setIcon( QIcon( ":/toolbar/faster") );
786 action->setData( STATIC_ENTRY );
788 action = menu->addAction( qtr( "Faster (fine)" ), THEMIM->getIM(),
789 SLOT( littlefaster() ) );
790 action->setData( STATIC_ENTRY );
792 action = menu->addAction( qtr( "N&ormal Speed" ), THEMIM->getIM(),
793 SLOT( normalRate() ) );
794 action->setData( STATIC_ENTRY );
796 action = menu->addAction( qtr( "Slower (fine)" ), THEMIM->getIM(),
797 SLOT( littleslower() ) );
798 action->setData( STATIC_ENTRY );
800 action = menu->addAction( qtr( "Slo&wer" ), THEMIM->getIM(),
802 #ifndef __APPLE__ /* No icons in menus in Mac */
803 action->setIcon( QIcon( ":/toolbar/slower") );
805 action->setData( STATIC_ENTRY );
807 menu->addSeparator();
809 action = menu->addAction( qtr( "&Jump Forward" ), THEMIM->getIM(),
811 #ifndef __APPLE__ /* No icons in menus in Mac */
812 action->setIcon( QIcon( ":/toolbar/skip_fw") );
814 action->setData( STATIC_ENTRY );
816 action = menu->addAction( qtr( "Jump Bac&kward" ), THEMIM->getIM(),
818 #ifndef __APPLE__ /* No icons in menus in Mac */
819 action->setIcon( QIcon( ":/toolbar/skip_back") );
821 action->setData( STATIC_ENTRY );
822 addDPStaticEntry( menu, qtr( I_MENU_GOTOTIME ),"",
823 SLOT( gotoTimeDialog() ), "Ctrl+T" );
824 menu->addSeparator();
828 void QVLCMenu::PopupMenuPlaylistControlEntries( QMenu *menu,
829 intf_thread_t *p_intf )
831 bool bEnable = THEMIM->getInput() != NULL;
833 addMIMStaticEntry( p_intf, menu, qtr( "&Stop" ), ":/menu/stop",
834 SLOT( stop() ), true );
835 /* Disable Stop in the right-click popup menu */
837 action->setEnabled( false );
839 /* Next / Previous */
840 addMIMStaticEntry( p_intf, menu, qtr( "Pre&vious" ),
841 ":/menu/previous", SLOT( prev() ) );
842 addMIMStaticEntry( p_intf, menu, qtr( "Ne&xt" ),
843 ":/menu/next", SLOT( next() ) );
845 menu->addSeparator();
848 void QVLCMenu::PopupMenuStaticEntries( QMenu *menu )
850 QMenu *openmenu = new QMenu( qtr( "Open a Media" ), menu );
851 addDPStaticEntry( openmenu, qtr( "&Open File..." ),
852 ":/type/file-asym", SLOT( openFileDialog() ) );
853 addDPStaticEntry( openmenu, qtr( I_OP_OPDIR ),
854 ":/type/folder-grey", SLOT( PLOpenDir() ) );
855 addDPStaticEntry( openmenu, qtr( "Open &Disc..." ),
856 ":/type/disc", SLOT( openDiscDialog() ) );
857 addDPStaticEntry( openmenu, qtr( "Open &Network..." ),
858 ":/type/network", SLOT( openNetDialog() ) );
859 addDPStaticEntry( openmenu, qtr( "Open &Capture Device..." ),
860 ":/type/capture-card", SLOT( openCaptureDialog() ) );
861 menu->addMenu( openmenu );
863 menu->addSeparator();
865 QMenu *helpmenu = HelpMenu( menu );
866 helpmenu->setTitle( qtr( "Help" ) );
867 menu->addMenu( helpmenu );
870 addDPStaticEntry( menu, qtr( "Quit" ), ":/menu/quit",
871 SLOT( quit() ), "Ctrl+Q", QAction::QuitRole );
874 /* Video Tracks and Subtitles tracks */
875 void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf, bool show )
880 vout_thread_t *p_vout = THEMIM->getVout();
883 VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
884 vlc_object_release( p_vout );
891 void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf, bool show )
896 aout_instance_t *p_aout = THEMIM->getAout();
897 AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
899 vlc_object_release( p_aout );
904 /* Navigation stuff, and general menus ( open ), used only for skins */
905 void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf, bool show )
911 varnames.push_back( "audio-es" );
912 InputAutoMenuBuilder( p_input, objects, varnames );
913 menu->addSeparator();
917 Populate( p_intf, menu, varnames, objects );
919 menu->addSeparator();
920 PopupPlayEntries( menu, p_intf, p_input );
921 PopupMenuPlaylistControlEntries( menu, p_intf);
923 menu->addSeparator();
924 PopupMenuControlEntries( menu, p_intf );
926 menu->addSeparator();
927 PopupMenuStaticEntries( menu );
929 menu->popup( QCursor::pos() );
932 /* Main Menu that sticks everything together */
933 void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show )
940 bool b_isFullscreen = false;
941 MainInterface *mi = p_intf->p_sys->p_mi;
943 PopupPlayEntries( menu, p_intf, p_input );
944 PopupMenuPlaylistControlEntries( menu, p_intf );
945 menu->addSeparator();
950 vout_thread_t *p_vout = THEMIM->getVout();
952 /* Add a fullscreen switch button, since it is the most used function */
955 vlc_value_t val; var_Get( p_vout, "fullscreen", &val );
957 b_isFullscreen = !( !val.b_bool );
961 CreateAndConnect( menu, "fullscreen",
962 qtr( "Leave Fullscreen" ),"" , ITEM_NORMAL,
963 VLC_OBJECT(p_vout), val, VLC_VAR_BOOL, b_isFullscreen );
965 vlc_object_release( p_vout );
967 menu->addSeparator();
971 InputAutoMenuBuilder( p_input, objects, varnames );
974 submenu = new QMenu( menu );
975 action = menu->addMenu( AudioMenu( p_intf, submenu ) );
976 action->setText( qtr( "&Audio" ) );
977 if( action->menu()->isEmpty() )
978 action->setEnabled( false );
981 submenu = new QMenu( menu );
982 action = menu->addMenu( VideoMenu( p_intf, submenu, false ) );
983 action->setText( qtr( "&Video" ) );
984 if( action->menu()->isEmpty() )
985 action->setEnabled( false );
987 submenu = SubtitleMenu( menu );
988 submenu->setTitle( qtr( "Subti&tle") );
989 UpdateItem( p_intf, menu, "spu-es", VLC_OBJECT(p_input), true );
991 /* Playback menu for chapters */
992 submenu = new QMenu( menu );
993 action = menu->addMenu( NavigMenu( p_intf, submenu ) );
994 action->setText( qtr( "&Playback" ) );
995 if( action->menu()->isEmpty() )
996 action->setEnabled( false );
999 menu->addSeparator();
1001 /* Add some special entries for windowed mode: Interface Menu */
1002 if( !b_isFullscreen )
1004 QMenu *submenu = new QMenu( qtr( "Tools" ), menu );
1005 /*QMenu *tools =*/ ToolsMenu( submenu );
1006 submenu->addSeparator();
1008 /* In skins interface, append some items */
1011 submenu->setTitle( qtr( "Interface" ) );
1012 if( p_intf->p_sys->b_isDialogProvider )
1014 vlc_object_t* p_object = p_intf->p_parent;
1016 objects.clear(); varnames.clear();
1017 objects.push_back( p_object );
1018 varnames.push_back( "intf-skins" );
1019 Populate( p_intf, submenu, varnames, objects );
1021 objects.clear(); varnames.clear();
1022 objects.push_back( p_object );
1023 varnames.push_back( "intf-skins-interactive" );
1024 Populate( p_intf, submenu, varnames, objects );
1027 msg_Warn( p_intf, "could not find parent interface" );
1031 QMenu *bar = menu; // Needed for next macro
1032 BAR_DADD( ViewMenu( p_intf, NULL, mi ), qtr( "V&iew" ), 4 );
1035 menu->addMenu( submenu );
1038 /* Static entries for ending, like open */
1039 PopupMenuStaticEntries( menu );
1041 menu->popup( QCursor::pos() );
1045 #undef POPUP_BOILERPLATE
1049 /************************************************************************
1051 ************************************************************************/
1053 void QVLCMenu::updateSystrayMenu( MainInterface *mi,
1054 intf_thread_t *p_intf,
1055 bool b_force_visible )
1057 input_thread_t *p_input = THEMIM->getInput();
1059 /* Get the systray menu and clean it */
1060 QMenu *sysMenu = mi->getSysTrayMenu();
1064 /* Hide / Show VLC and cone */
1065 if( mi->isVisible() || b_force_visible )
1067 sysMenu->addAction( QIcon( ":/logo/vlc16.png" ),
1068 qtr( "Hide VLC media player in taskbar" ), mi,
1069 SLOT( hideUpdateSystrayMenu() ) );
1073 sysMenu->addAction( QIcon( ":/logo/vlc16.png" ),
1074 qtr( "Show VLC media player" ), mi,
1075 SLOT( showUpdateSystrayMenu() ) );
1077 sysMenu->addSeparator();
1080 PopupPlayEntries( sysMenu, p_intf, p_input );
1081 PopupMenuPlaylistControlEntries( sysMenu, p_intf);
1082 PopupMenuControlEntries( sysMenu, p_intf);
1084 addDPStaticEntry( sysMenu, qtr( "&Open a Media" ),
1085 ":/type/file-wide", SLOT( openFileDialog() ) );
1086 addDPStaticEntry( sysMenu, qtr( "&Quit" ) ,
1087 ":/menu/quit", SLOT( quit() ) );
1090 mi->getSysTray()->setContextMenu( sysMenu );
1097 /*************************************************************************
1098 * Builders for automenus
1099 *************************************************************************/
1100 QMenu * QVLCMenu::Populate( intf_thread_t *p_intf,
1102 vector< const char *> & varnames,
1103 vector<vlc_object_t *> & objects )
1105 QMenu *menu = current;
1108 currentGroup = NULL;
1110 for( int i = 0; i < (int)objects.size() ; i++ )
1112 if( !varnames[i] || !*varnames[i] )
1114 menu->addSeparator();
1118 UpdateItem( p_intf, menu, varnames[i], objects[i], true );
1123 /*****************************************************************************
1125 *****************************************************************************/
1127 static bool IsMenuEmpty( const char *psz_var,
1128 vlc_object_t *p_object,
1129 bool b_root = true )
1131 vlc_value_t val, val_list;
1132 int i_type, i_result, i;
1134 /* Check the type of the object variable */
1135 i_type = var_Type( p_object, psz_var );
1137 /* Check if we want to display the variable */
1138 if( !( i_type & VLC_VAR_HASCHOICE ) ) return false;
1140 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
1141 if( val.i_int == 0 ) return true;
1143 if( ( i_type & VLC_VAR_TYPE ) != VLC_VAR_VARIABLE )
1145 if( val.i_int == 1 && b_root ) return true;
1149 /* Check children variables in case of VLC_VAR_VARIABLE */
1150 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
1155 for( i = 0, i_result = true; i < val_list.p_list->i_count; i++ )
1157 if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
1165 /* clean up everything */
1166 var_FreeList( &val_list, NULL );
1171 #define TEXT_OR_VAR qfu ( text.psz_string ? text.psz_string : psz_var )
1173 void QVLCMenu::UpdateItem( intf_thread_t *p_intf, QMenu *menu,
1174 const char *psz_var, vlc_object_t *p_object, bool b_submenu )
1176 vlc_value_t val, text;
1179 QAction *action = FindActionWithVar( menu, psz_var );
1181 DeleteNonStaticEntries( action->menu() );
1186 action->setEnabled( false );
1190 /* Check the type of the object variable */
1191 /* This HACK is needed so we have a radio button for audio and video tracks
1192 instread of a checkbox */
1193 if( !strcmp( psz_var, "audio-es" )
1194 || !strcmp( psz_var, "video-es" ) )
1195 i_type = VLC_VAR_INTEGER | VLC_VAR_HASCHOICE;
1197 i_type = var_Type( p_object, psz_var );
1199 switch( i_type & VLC_VAR_TYPE )
1203 case VLC_VAR_VARIABLE:
1204 case VLC_VAR_STRING:
1205 case VLC_VAR_INTEGER:
1209 /* Variable doesn't exist or isn't handled */
1211 action->setEnabled( false );
1215 /* Make sure we want to display the variable */
1216 if( menu->isEmpty() && IsMenuEmpty( psz_var, p_object ) )
1219 action->setEnabled( false );
1223 /* Get the descriptive name of the variable */
1224 int i_ret = var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
1225 if( i_ret != VLC_SUCCESS )
1227 text.psz_string = NULL;
1232 action = new QAction( TEXT_OR_VAR, menu );
1233 menu->addAction( action );
1234 action->setData( psz_var );
1237 /* Some specific stuff */
1238 bool forceDisabled = false;
1239 if( !strcmp( psz_var, "spu-es" ) )
1241 vout_thread_t *p_vout = THEMIM->getVout();
1242 forceDisabled = ( p_vout == NULL );
1244 vlc_object_release( p_vout );
1247 if( i_type & VLC_VAR_HASCHOICE )
1249 /* Append choices menu */
1253 submenu = action->menu();
1256 submenu = new QMenu( menu );
1257 action->setMenu( submenu );
1261 CreateChoicesMenu( submenu, psz_var, p_object, true ) == 0 );
1263 action->setEnabled( false );
1268 CreateChoicesMenu( menu, psz_var, p_object, true ) == 0 );
1270 FREENULL( text.psz_string );
1274 switch( i_type & VLC_VAR_TYPE )
1277 val.i_int = 0; // Prevent the copy of an uninitialized value
1278 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_NORMAL,
1279 p_object, val, i_type );
1283 var_Get( p_object, psz_var, &val );
1284 val.b_bool = !val.b_bool;
1285 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_CHECK,
1286 p_object, val, i_type, !val.b_bool );
1289 FREENULL( text.psz_string );
1294 /** HACK for the navigation submenu:
1295 * "title %2i" variables take the value 0 if not set
1297 static bool CheckTitle( vlc_object_t *p_object, const char *psz_var )
1300 if( sscanf( psz_var, "title %2i", &i_title ) <= 0 )
1303 int i_current_title = var_GetInteger( p_object, "title" );
1304 return ( i_title == i_current_title );
1308 int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
1309 vlc_object_t *p_object, bool b_root )
1311 vlc_value_t val, val_list, text_list;
1314 /* Check the type of the object variable */
1315 i_type = var_Type( p_object, psz_var );
1317 /* Make sure we want to display the variable */
1318 if( submenu->isEmpty() && IsMenuEmpty( psz_var, p_object, b_root ) )
1319 return VLC_EGENERIC;
1321 switch( i_type & VLC_VAR_TYPE )
1325 case VLC_VAR_VARIABLE:
1326 case VLC_VAR_STRING:
1327 case VLC_VAR_INTEGER:
1331 /* Variable doesn't exist or isn't handled */
1332 return VLC_EGENERIC;
1335 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
1336 &val_list, &text_list ) < 0 )
1338 return VLC_EGENERIC;
1341 #define CURVAL val_list.p_list->p_values[i]
1342 #define CURTEXT text_list.p_list->p_values[i].psz_string
1343 #define RADIO_OR_COMMAND ( i_type & VLC_VAR_ISCOMMAND ) ? ITEM_NORMAL : ITEM_RADIO
1345 for( i = 0; i < val_list.p_list->i_count; i++ )
1347 vlc_value_t another_val;
1349 QMenu *subsubmenu = new QMenu( submenu );
1351 switch( i_type & VLC_VAR_TYPE )
1353 case VLC_VAR_VARIABLE:
1354 CreateChoicesMenu( subsubmenu, CURVAL.psz_string, p_object, false );
1355 subsubmenu->setTitle( qfu( CURTEXT ? CURTEXT :CURVAL.psz_string ) );
1356 submenu->addMenu( subsubmenu );
1359 case VLC_VAR_STRING:
1360 var_Get( p_object, psz_var, &val );
1361 another_val.psz_string = strdup( CURVAL.psz_string );
1362 menutext = qfu( CURTEXT ? CURTEXT : another_val.psz_string );
1363 CreateAndConnect( submenu, psz_var, menutext, "", RADIO_OR_COMMAND,
1364 p_object, another_val, i_type,
1365 val.psz_string && !strcmp( val.psz_string, CURVAL.psz_string ) );
1367 free( val.psz_string );
1370 case VLC_VAR_INTEGER:
1371 var_Get( p_object, psz_var, &val );
1372 if( CURTEXT ) menutext = qfu( CURTEXT );
1373 else menutext = QString::number( CURVAL.i_int );
1374 CreateAndConnect( submenu, psz_var, menutext, "", RADIO_OR_COMMAND,
1375 p_object, CURVAL, i_type,
1376 ( CURVAL.i_int == val.i_int )
1377 && CheckTitle( p_object, psz_var ) );
1381 var_Get( p_object, psz_var, &val );
1382 if( CURTEXT ) menutext = qfu( CURTEXT );
1383 else menutext.sprintf( "%.2f", CURVAL.f_float );
1384 CreateAndConnect( submenu, psz_var, menutext, "", RADIO_OR_COMMAND,
1385 p_object, CURVAL, i_type,
1386 CURVAL.f_float == val.f_float );
1393 currentGroup = NULL;
1395 /* clean up everything */
1396 var_FreeList( &val_list, &text_list );
1398 #undef RADIO_OR_COMMAND
1401 return submenu->isEmpty() ? VLC_EGENERIC : VLC_SUCCESS;
1404 void QVLCMenu::CreateAndConnect( QMenu *menu, const char *psz_var,
1405 const QString& text, const QString& help,
1406 int i_item_type, vlc_object_t *p_obj,
1407 vlc_value_t val, int i_val_type,
1410 QAction *action = FindActionWithVar( menu, psz_var );
1415 action = new QAction( text, menu );
1416 menu->addAction( action );
1420 action->setToolTip( help );
1421 action->setEnabled( p_obj != NULL );
1423 if( i_item_type == ITEM_CHECK )
1425 action->setCheckable( true );
1427 else if( i_item_type == ITEM_RADIO )
1429 action->setCheckable( true );
1431 currentGroup = new QActionGroup( menu );
1432 currentGroup->addAction( action );
1435 action->setChecked( checked );
1437 MenuItemData *itemData = qFindChild<MenuItemData*>( action, QString() );
1439 itemData = new MenuItemData( action, p_obj, i_val_type, val, psz_var );
1441 /* remove previous signal-slot connection(s) if any */
1442 action->disconnect( );
1444 CONNECT( action, triggered(), THEDP->menusMapper, map() );
1445 THEDP->menusMapper->setMapping( action, itemData );
1448 menu->addAction( action );
1451 void QVLCMenu::DoAction( QObject *data )
1453 MenuItemData *itemData = qobject_cast<MenuItemData *>( data );
1454 vlc_object_t *p_object = itemData->p_obj;
1455 if( p_object == NULL ) return;
1457 /* Preserve settings across vouts via the playlist object: */
1458 if( !strcmp( itemData->psz_var, "fullscreen" )
1459 || !strcmp( itemData->psz_var, "video-on-top" ) )
1460 var_Set( pl_Get( p_object ), itemData->psz_var, itemData->val );
1462 var_Set( p_object, itemData->psz_var, itemData->val );
1465 void QVLCMenu::updateRecents( intf_thread_t *p_intf )
1470 RecentsMRL* rmrl = RecentsMRL::getInstance( p_intf );
1471 QStringList l = rmrl->recents();
1473 recentsMenu->clear();
1477 action = recentsMenu->addAction( qtr(" - Empty - ") );
1478 action->setEnabled( false );
1482 for( int i = 0; i < l.size(); ++i )
1484 char *psz_temp = decode_URI_duplicate( qtu( l.at( i ) ) );
1486 action = recentsMenu->addAction(
1487 QString( "&%1: " ).arg( i + 1 ) +
1488 QApplication::fontMetrics().elidedText( psz_temp, Qt::ElideLeft, 400 ),
1489 rmrl->signalMapper, SLOT( map() ),
1490 i <= 9 ? QString( "Ctrl+%1" ).arg( i + 1 ) : "" );
1491 rmrl->signalMapper->setMapping( action, l.at( i ) );
1496 recentsMenu->addSeparator();
1497 recentsMenu->addAction( qtr("&Clear"), rmrl, SLOT( clear() ) );