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>
59 This file defines the main menus and the pop-up menu (right-click menu)
60 and the systray menu (in that order in the file)
62 There are 4 menus that have to be rebuilt everytime there are called:
63 Audio, Video, Navigation, view
64 4 functions are building those menus: AudioMenu, VideoMenu, NavigMenu, View
65 and 3 functions associated are collecting the objects :
66 InputAutoMenuBuilder, AudioAutoMenuBuilder, VideoAutoMenuBuilder.
68 A QSignalMapper decides when to rebuild those menus cf MenuFunc in the .hpp
69 Just before one of those menus are aboutToShow(), they are rebuild.
72 #define STATIC_ENTRY "__static__"
73 #define ENTRY_ALWAYS_ENABLED "__ignore__"
77 ITEM_NORMAL, /* not a checkbox, nor a radio */
78 ITEM_CHECK, /* Checkbox */
79 ITEM_RADIO /* Radiobox */
82 static QActionGroup *currentGroup;
84 QMenu *QVLCMenu::recentsMenu = NULL;
87 * @brief Add static entries to DP in menus
89 QAction *addDPStaticEntry( QMenu *menu,
93 const char *shortcut = NULL,
94 QAction::MenuRole = QAction::NoRole
97 QAction *action = NULL;
98 #ifndef __APPLE__ /* We don't set icons in menus in MacOS X */
99 if( !EMPTY_STR( icon ) )
101 if( !EMPTY_STR( shortcut ) )
102 action = menu->addAction( QIcon( icon ), text, THEDP,
103 member, qtr( shortcut ) );
105 action = menu->addAction( QIcon( icon ), text, THEDP, member );
110 if( !EMPTY_STR( shortcut ) )
111 action = menu->addAction( text, THEDP, member, qtr( shortcut ) );
113 action = menu->addAction( text, THEDP, member );
115 action->setData( STATIC_ENTRY );
120 * @brief Add static entries to MIM in menus
122 QAction* addMIMStaticEntry( intf_thread_t *p_intf,
127 bool bStatic = false )
130 #ifndef __APPLE__ /* We don't set icons in menus in MacOS X */
131 if( !EMPTY_STR( icon ) )
133 action = menu->addAction( text, THEMIM, member );
134 action->setIcon( QIcon( icon ) );
139 action = menu->addAction( text, THEMIM, member );
141 action->setData( bStatic ? STATIC_ENTRY : ENTRY_ALWAYS_ENABLED );
146 * @brief Enable all static entries of a menu, disable the others
147 * @param menu the menu in which the entries will be disabled
148 * @param enable if false, disable all entries
150 void EnableStaticEntries( QMenu *menu, bool enable = true )
154 QList< QAction* > actions = menu->actions();
155 for( int i = 0; i < actions.size(); ++i )
157 actions[i]->setEnabled( actions[i]->data().toString()
158 == ENTRY_ALWAYS_ENABLED ||
159 /* Be careful here, because data("string").toBool is true */
160 ( enable && (actions[i]->data().toString() == STATIC_ENTRY ) ) );
165 * \return Number of static entries
167 inline int DeleteNonStaticEntries( QMenu *menu )
169 if( !menu ) return VLC_EGENERIC;
173 QList< QAction* > actions = menu->actions();
174 for( int i = 0; i < actions.size(); ++i )
176 if( actions[i]->data().toString() != STATIC_ENTRY )
185 * \return QAction associated to psz_var variable
187 static QAction * FindActionWithVar( QMenu *menu, const char *psz_var )
189 QList< QAction* > actions = menu->actions();
190 for( int i = 0; i < actions.size(); ++i )
192 if( actions[i]->data().toString() == psz_var )
198 /*****************************************************************************
199 * Definitions of variables for the dynamic menus
200 *****************************************************************************/
201 #define PUSH_VAR( var ) varnames.push_back( var ); \
202 objects.push_back( VLC_OBJECT(p_object) )
204 #define PUSH_INPUTVAR( var ) varnames.push_back( var ); \
205 objects.push_back( VLC_OBJECT(p_input) );
207 #define PUSH_SEPARATOR if( objects.size() != i_last_separator ) { \
208 objects.push_back( 0 ); varnames.push_back( "" ); \
209 i_last_separator = objects.size(); }
211 static int InputAutoMenuBuilder( input_thread_t *p_object,
212 vector<vlc_object_t *> &objects,
213 vector<const char *> &varnames )
215 PUSH_VAR( "bookmark" );
217 PUSH_VAR( "chapter" );
218 PUSH_VAR( "navigation" );
219 PUSH_VAR( "program" );
223 static int VideoAutoMenuBuilder( vout_thread_t *p_object,
224 input_thread_t *p_input,
225 vector<vlc_object_t *> &objects,
226 vector<const char *> &varnames )
228 PUSH_INPUTVAR( "video-es" );
229 PUSH_INPUTVAR( "spu-es" );
230 PUSH_VAR( "fullscreen" );
231 PUSH_VAR( "video-on-top" );
232 PUSH_VAR( "video-wallpaper" );
234 PUSH_VAR( "direct3d-desktop" );
236 PUSH_VAR( "video-snapshot" );
238 PUSH_VAR( "autoscale" );
239 PUSH_VAR( "aspect-ratio" );
241 PUSH_VAR( "deinterlace" );
242 PUSH_VAR( "deinterlace-mode" );
243 PUSH_VAR( "postprocess" );
248 static int AudioAutoMenuBuilder( aout_instance_t *p_object,
249 input_thread_t *p_input,
250 vector<vlc_object_t *> &objects,
251 vector<const char *> &varnames )
253 PUSH_INPUTVAR( "audio-es" );
254 PUSH_VAR( "audio-channels" );
255 PUSH_VAR( "audio-device" );
256 PUSH_VAR( "visual" );
260 /*****************************************************************************
263 *****************************************************************************/
266 static inline void addMenuToMainbar( QMenu *func, QString title, QMenuBar *bar ) {
267 func->setTitle( title );
272 #define BAR_DADD( func, title, id ) { \
273 QMenu *_menu = func; _menu->setTitle( title ); bar->addMenu( _menu ); \
274 MenuFunc *f = new MenuFunc( _menu, id ); \
275 CONNECT( _menu, aboutToShow(), THEDP->menusUpdateMapper, map() ); \
276 THEDP->menusUpdateMapper->setMapping( _menu, f ); }
278 // Add a simple action
279 static inline void addAction( QMenu *_menu, QVariant val, QString title ) {
280 QAction *_action = new QAction( title, _menu );
281 _action->setData( val );
282 _menu->addAction( _action );
285 // Add an action with a submenu
286 static inline void addActionWithSubmenu( QMenu *_menu, QVariant val, QString title ) {
287 QAction *_action = new QAction( title, _menu );
288 _action->setData( val );
289 _action->setMenu( new QMenu( _menu ) );
290 _menu->addAction( _action );
293 // Add an action that is a checkbox
294 static inline void addActionWithCheckbox( QMenu *_menu, QVariant val, QString title ) {
295 QAction *_action = new QAction( title, _menu );
296 _action->setData( val );
297 _action->setCheckable( true );
298 _menu->addAction( _action );
302 * Main Menu Bar Creation
304 void QVLCMenu::createMenuBar( MainInterface *mi,
305 intf_thread_t *p_intf )
307 /* QMainWindows->menuBar()
308 gives the QProcess::destroyed timeout issue on Cleanlooks style with
309 setDesktopAware set to false */
310 QMenuBar *bar = mi->menuBar();
312 addMenuToMainbar( FileMenu( p_intf, bar ), qtr( "&Media" ), bar );
314 /* Dynamic menus, rebuilt before being showed */
315 BAR_DADD( NavigMenu( p_intf, bar ), qtr( "P&layback" ), 3 );
316 BAR_DADD( AudioMenu( p_intf, bar ), qtr( "&Audio" ), 1 );
317 BAR_DADD( VideoMenu( p_intf, bar ), qtr( "&Video" ), 2 );
319 addMenuToMainbar( ToolsMenu( bar ), qtr( "&Tools" ), bar );
321 /* View menu, a bit different */
322 BAR_DADD( ViewMenu( p_intf, _menu, mi ), qtr( "V&iew" ), 4 );
324 addMenuToMainbar( HelpMenu( bar ), qtr( "&Help" ), bar );
329 * Media ( File ) Menu
330 * Opening, streaming and quit
332 QMenu *QVLCMenu::FileMenu( intf_thread_t *p_intf, QWidget *parent )
334 QMenu *menu = new QMenu( parent );
337 addDPStaticEntry( menu, qtr( "Open &File..." ),
338 ":/type/file-asym", SLOT( simpleOpenDialog() ), "Ctrl+O" );
339 addDPStaticEntry( menu, qtr( I_OP_OPDIR ),
340 ":/type/folder-grey", SLOT( PLOpenDir() ), "Ctrl+F" );
341 addDPStaticEntry( menu, qtr( "Open &Disc..." ),
342 ":/type/disc", SLOT( openDiscDialog() ), "Ctrl+D" );
343 addDPStaticEntry( menu, qtr( "Open &Network Stream..." ),
344 ":/type/network", SLOT( openNetDialog() ), "Ctrl+N" );
345 addDPStaticEntry( menu, qtr( "Open &Capture Device..." ),
346 ":/type/capture-card", SLOT( openCaptureDialog() ), "Ctrl+C" );
348 menu->addSeparator();
350 addDPStaticEntry( menu, qtr( "&Open (advanced)..." ),
351 ":/type/file-asym", SLOT( openFileDialog() ), "Ctrl+Shift+O" );
352 menu->addSeparator();
354 addDPStaticEntry( menu, qtr( "Open &Location from clipboard" ),
355 NULL, SLOT( openUrlDialog() ), "Ctrl+V" );
357 if( var_InheritBool( p_intf, "qt-recentplay" ) )
359 recentsMenu = new QMenu( qtr( "Open &Recent Media" ), menu );
360 updateRecents( p_intf );
361 menu->addMenu( recentsMenu );
363 menu->addSeparator();
365 addDPStaticEntry( menu, qtr( I_PL_SAVE ), "", SLOT( saveAPlaylist() ),
367 menu->addSeparator();
370 addDPStaticEntry( menu, qtr( "Conve&rt / Save..." ), "",
371 SLOT( openAndTranscodingDialogs() ), "Ctrl+R" );
372 addDPStaticEntry( menu, qtr( "&Stream..." ),
373 ":/menu/stream", SLOT( openAndStreamingDialogs() ), "Ctrl+S" );
374 menu->addSeparator();
377 action = addMIMStaticEntry( p_intf, menu, qtr( "Quit at the end of playlist" ), "",
378 SLOT( activatePlayQuit( bool ) ) );
379 action->setCheckable( true );
380 action->setChecked( THEMIM->getPlayExitState() );
382 addDPStaticEntry( menu, qtr( "&Quit" ) ,
383 ":/menu/quit", SLOT( quit() ), "Ctrl+Q" );
388 * Tools, like Media Information, Preferences or Messages
390 QMenu *QVLCMenu::ToolsMenu( QMenu *menu )
392 addDPStaticEntry( menu, qtr( "&Effects and Filters"), ":/menu/settings",
393 SLOT( extendedDialog() ), "Ctrl+E" );
395 addDPStaticEntry( menu, qtr( "&Track Synchronization"), ":/menu/settings",
396 SLOT( synchroDialog() ), "" );
398 addDPStaticEntry( menu, qtr( I_MENU_INFO ) , ":/menu/info",
399 SLOT( mediaInfoDialog() ), "Ctrl+I" );
400 addDPStaticEntry( menu, qtr( I_MENU_CODECINFO ) ,
401 ":/menu/info", SLOT( mediaCodecDialog() ), "Ctrl+J" );
404 addDPStaticEntry( menu, qtr( I_MENU_VLM ), "", SLOT( vlmDialog() ),
408 addDPStaticEntry( menu, qtr( "Program Guide" ), "", SLOT( epgDialog() ),
411 addDPStaticEntry( menu, qtr( I_MENU_MSG ),
412 ":/menu/messages", SLOT( messagesDialog() ), "Ctrl+M" );
414 addDPStaticEntry( menu, qtr( "Plu&gins and extensions" ),
415 "", SLOT( pluginDialog() ) );
416 menu->addSeparator();
418 addDPStaticEntry( menu, qtr( "Customi&ze Interface..." ),
419 ":/menu/preferences", SLOT( toolbarDialog() ) );
421 addDPStaticEntry( menu, qtr( "&Preferences" ),
422 ":/menu/preferences", SLOT( prefsDialog() ), "Ctrl+P", QAction::PreferencesRole );
429 * Interface modification, load other interfaces, activate Extensions
431 QMenu *QVLCMenu::ViewMenu( intf_thread_t *p_intf, QMenu *current, MainInterface *_mi )
436 MainInterface *mi = _mi ? _mi : p_intf->p_sys->p_mi;
441 menu = new QMenu( qtr( "&View" ), mi );
447 //HACK menu->clear() does not delete submenus
448 QList<QAction*> actions = menu->actions();
449 foreach( QAction *a, actions )
451 QMenu *m = a->menu();
452 if( a->parent() == menu ) delete a;
453 else menu->removeAction( a );
454 if( m && m->parent() == menu ) delete m;
460 QIcon( ":/menu/playlist_menu" ),
462 qtr( "Play&list" ), mi,
463 SLOT( togglePlaylist() ), qtr( "Ctrl+L" ) );
465 menu->addSeparator();
468 action = menu->addAction( qtr( "Mi&nimal Interface" ) );
469 action->setShortcut( qtr( "Ctrl+H" ) );
470 action->setCheckable( true );
471 action->setChecked( (mi->getControlsVisibilityStatus() & CONTROLS_HIDDEN ) );
473 CONNECT( action, triggered( bool ), mi, toggleMinimalView( bool ) );
474 CONNECT( mi, minimalViewToggled( bool ), action, setChecked( bool ) );
476 /* FullScreen View */
477 action = menu->addAction( qtr( "&Fullscreen Interface" ), mi,
478 SLOT( toggleInterfaceFullScreen() ), QString( "F11" ) );
479 action->setCheckable( true );
480 action->setChecked( mi->isInterfaceFullScreen() );
481 CONNECT( mi, fullscreenInterfaceToggled( bool ),
482 action, setChecked( bool ) );
484 /* Advanced Controls */
485 action = menu->addAction( qtr( "&Advanced Controls" ), mi,
486 SLOT( toggleAdvancedButtons() ) );
487 action->setCheckable( true );
488 if( mi->getControlsVisibilityStatus() & CONTROLS_ADVANCED )
489 action->setChecked( true );
491 /* Docked Playlist */
492 action = menu->addAction( qtr( "Docked Playlist" ) );
493 action->setCheckable( true );
494 action->setChecked( mi->isPlDocked() );
495 CONNECT( action, triggered( bool ), mi, dockPlaylist( bool ) );
497 action = menu->addAction( qtr( "Status Bar" ) );
498 action->setCheckable( true );
499 action->setChecked( mi->statusBar()->isVisible() );
500 CONNECT( action, triggered( bool ), mi, setStatusBarVisibility( bool) );
501 #if 0 /* For Visualisations. Not yet working */
502 adv = menu->addAction( qtr( "Visualizations selector" ), mi,
504 adv->setCheckable( true );
505 if( visual_selector_enabled ) adv->setChecked( true );
508 menu->addSeparator();
510 InterfacesMenu( p_intf, menu );
511 menu->addSeparator();
514 ExtensionsMenu( p_intf, menu );
520 * Interface Sub-Menu, to list extras interface and skins
522 QMenu *QVLCMenu::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
524 vector<vlc_object_t *> objects;
525 vector<const char *> varnames;
526 varnames.push_back( "intf-add" );
527 objects.push_back( VLC_OBJECT(p_intf) );
529 return Populate( p_intf, current, varnames, objects );
533 * Extensions menu: populate the current menu with extensions
535 void QVLCMenu::ExtensionsMenu( intf_thread_t *p_intf, QMenu *extMenu )
537 /* Get ExtensionsManager and load extensions if needed */
538 ExtensionsManager *extMgr = ExtensionsManager::getInstance( p_intf );
540 if( !var_InheritBool( p_intf, "qt-autoload-extensions")
541 && !extMgr->isLoaded() )
546 if( !extMgr->isLoaded() && !extMgr->cannotLoad() )
548 extMgr->loadExtensions();
551 /* Let the ExtensionsManager build itself the menu */
552 extMenu->addSeparator();
553 extMgr->menu( extMenu );
559 QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QMenu * current )
561 vector<vlc_object_t *> objects;
562 vector<const char *> varnames;
563 aout_instance_t *p_aout;
564 input_thread_t *p_input;
566 if( current->isEmpty() )
568 addActionWithSubmenu( current, "audio-es", qtr( "Audio &Track" ) );
569 addActionWithSubmenu( current, "audio-channels", qtr( "Audio &Channels" ) );
570 addActionWithSubmenu( current, "audio-device", qtr( "Audio &Device" ) );
571 current->addSeparator();
573 addActionWithSubmenu( current, "visual", qtr( "&Visualizations" ) );
574 current->addSeparator();
576 QAction *action = current->addAction( qtr( "Increase Volume" ),
577 ActionsManager::getInstance( p_intf ), SLOT( AudioUp() ) );
578 action->setData( STATIC_ENTRY );
579 action = current->addAction( qtr( "Decrease Volume" ),
580 ActionsManager::getInstance( p_intf ), SLOT( AudioDown() ) );
581 action->setData( STATIC_ENTRY );
582 action = current->addAction( qtr( "Mute" ),
583 ActionsManager::getInstance( p_intf ), SLOT( toggleMuteAudio() ) );
584 action->setData( STATIC_ENTRY );
587 p_input = THEMIM->getInput();
588 p_aout = THEMIM->getAout();
589 EnableStaticEntries( current, ( p_aout != NULL ) );
590 AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
593 vlc_object_release( p_aout );
596 return Populate( p_intf, current, varnames, objects );
600 QMenu *QVLCMenu::SubtitleMenu( intf_thread_t *p_intf, QMenu *current )
603 QMenu *submenu = new QMenu( qtr( "&Subtitles Track" ), current );
604 action = current->addMenu( submenu );
605 action->setData( "spu-es" );
606 addDPStaticEntry( submenu, qtr( "Open File..." ), "",
607 SLOT( loadSubtitlesFile() ) );
608 submenu->addSeparator();
614 * Subtitles are part of Video.
616 QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current, bool b_subtitle )
618 vout_thread_t *p_vout;
619 input_thread_t *p_input;
620 vector<vlc_object_t *> objects;
621 vector<const char *> varnames;
623 if( current->isEmpty() )
625 addActionWithSubmenu( current, "video-es", qtr( "Video &Track" ) );
627 SubtitleMenu( p_intf, current );
629 current->addSeparator();
631 addActionWithCheckbox( current, "fullscreen", qtr( "&Fullscreen" ) );
632 addActionWithCheckbox( current, "autoscale", qtr( "Always Fit &Window" ) );
633 addActionWithCheckbox( current, "video-on-top", qtr( "Always &on Top" ) );
635 addActionWithCheckbox( current, "direct3d-desktop", qtr( "Display on &Desktop" ) );
637 addAction( current, "video-snapshot", qtr( "Take &Snapshot" ) );
639 addActionWithCheckbox( current, "video-wallpaper", qtr( "Set as Wall&paper" ) );
641 current->addSeparator();
643 addActionWithSubmenu( current, "zoom", qtr( "&Zoom" ) );
644 addActionWithSubmenu( current, "aspect-ratio", qtr( "&Aspect Ratio" ) );
645 addActionWithSubmenu( current, "crop", qtr( "&Crop" ) );
646 addActionWithSubmenu( current, "deinterlace", qtr( "&Deinterlace" ) );
647 addActionWithSubmenu( current, "deinterlace-mode", qtr( "&Deinterlace mode" ) );
648 addActionWithSubmenu( current, "postprocess", qtr( "&Post processing" ) );
651 p_input = THEMIM->getInput();
653 p_vout = THEMIM->getVout();
654 VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
657 vlc_object_release( p_vout );
659 return Populate( p_intf, current, varnames, objects );
664 * For DVD, MP4, MOV and other chapter based format
666 QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *menu )
670 addActionWithSubmenu( menu, "title", qtr( "T&itle" ) );
671 addActionWithSubmenu( menu, "chapter", qtr( "&Chapter" ) );
672 addActionWithSubmenu( menu, "navigation", qtr( "&Navigation" ) );
673 addActionWithSubmenu( menu, "program", qtr( "&Program" ) );
675 /* FixMe: sync I_MENU_BOOKMARK string */
676 QMenu *submenu = new QMenu( qtr( "Custom &Bookmarks" ), menu );
677 addDPStaticEntry( submenu, qtr( "&Manage" ), "",
678 SLOT( bookmarksDialog() ), "Ctrl+B" );
679 submenu->addSeparator();
680 action = menu->addMenu( submenu );
681 action->setData( "bookmark" );
683 menu->addSeparator();
684 PopupMenuPlaylistControlEntries( menu, p_intf );
685 PopupMenuControlEntries( menu, p_intf );
687 EnableStaticEntries( menu, ( THEMIM->getInput() != NULL ) );
688 return RebuildNavigMenu( p_intf, menu );
691 QMenu *QVLCMenu::RebuildNavigMenu( intf_thread_t *p_intf, QMenu *menu )
694 input_thread_t *p_object;
695 vector<vlc_object_t *> objects;
696 vector<const char *> varnames;
698 /* Get the input and hold it */
699 p_object = THEMIM->getInput();
701 InputAutoMenuBuilder( p_object, objects, varnames );
703 menu->addSeparator();
705 /* Title and so on */
706 PUSH_VAR( "prev-title" );
707 PUSH_VAR( "next-title" );
708 PUSH_VAR( "prev-chapter" );
709 PUSH_VAR( "next-chapter" );
711 EnableStaticEntries( menu, (p_object != NULL ) );
712 return Populate( p_intf, menu, varnames, objects );
718 QMenu *QVLCMenu::HelpMenu( QWidget *parent )
720 QMenu *menu = new QMenu( parent );
721 addDPStaticEntry( menu, qtr( "&Help..." ) ,
722 ":/menu/help", SLOT( helpDialog() ), "F1" );
724 addDPStaticEntry( menu, qtr( "Check for &Updates..." ) , "",
725 SLOT( updateDialog() ) );
727 menu->addSeparator();
728 addDPStaticEntry( menu, qtr( I_MENU_ABOUT ), ":/menu/info",
729 SLOT( aboutDialog() ), "Shift+F1", QAction::AboutRole );
733 /*****************************************************************************
734 * Popup menus - Right Click menus *
735 *****************************************************************************/
736 #define POPUP_BOILERPLATE \
737 static QMenu* menu = NULL; \
738 delete menu; menu = NULL; \
741 unsigned int i_last_separator = 0; \
742 vector<vlc_object_t *> objects; \
743 vector<const char *> varnames; \
744 input_thread_t *p_input = THEMIM->getInput();
746 #define CREATE_POPUP \
747 menu = new QMenu(); \
748 Populate( p_intf, menu, varnames, objects ); \
749 menu->popup( QCursor::pos() ); \
750 i_last_separator = 0;
752 void QVLCMenu::PopupPlayEntries( QMenu *menu,
753 intf_thread_t *p_intf,
754 input_thread_t *p_input )
758 /* Play or Pause action and icon */
759 if( !p_input || var_GetInteger( p_input, "state" ) != PLAYING_S )
761 action = menu->addAction( qtr( "Play" ),
762 ActionsManager::getInstance( p_intf ), SLOT( play() ) );
763 #ifndef __APPLE__ /* No icons in menus in Mac */
764 action->setIcon( QIcon( ":/menu/play" ) );
769 addMIMStaticEntry( p_intf, menu, qtr( "Pause" ),
770 ":/menu/pause", SLOT( togglePlayPause() ) );
774 void QVLCMenu::PopupMenuControlEntries( QMenu *menu, intf_thread_t *p_intf )
779 action = menu->addAction( qtr( "&Faster" ), THEMIM->getIM(),
781 #ifndef __APPLE__ /* No icons in menus in Mac */
782 action->setIcon( QIcon( ":/toolbar/faster") );
784 action->setData( STATIC_ENTRY );
786 action = menu->addAction( qtr( "Faster (fine)" ), THEMIM->getIM(),
787 SLOT( littlefaster() ) );
788 action->setData( STATIC_ENTRY );
790 action = menu->addAction( qtr( "N&ormal Speed" ), THEMIM->getIM(),
791 SLOT( normalRate() ) );
792 action->setData( STATIC_ENTRY );
794 action = menu->addAction( qtr( "Slower (fine)" ), THEMIM->getIM(),
795 SLOT( littleslower() ) );
796 action->setData( STATIC_ENTRY );
798 action = menu->addAction( qtr( "Slo&wer" ), THEMIM->getIM(),
800 #ifndef __APPLE__ /* No icons in menus in Mac */
801 action->setIcon( QIcon( ":/toolbar/slower") );
803 action->setData( STATIC_ENTRY );
805 menu->addSeparator();
807 action = menu->addAction( qtr( "&Jump Forward" ), THEMIM->getIM(),
809 #ifndef __APPLE__ /* No icons in menus in Mac */
810 action->setIcon( QIcon( ":/toolbar/skip_fw") );
812 action->setData( STATIC_ENTRY );
814 action = menu->addAction( qtr( "Jump Bac&kward" ), THEMIM->getIM(),
816 #ifndef __APPLE__ /* No icons in menus in Mac */
817 action->setIcon( QIcon( ":/toolbar/skip_back") );
819 action->setData( STATIC_ENTRY );
820 addDPStaticEntry( menu, qtr( I_MENU_GOTOTIME ),"",
821 SLOT( gotoTimeDialog() ), "Ctrl+T" );
822 menu->addSeparator();
826 void QVLCMenu::PopupMenuPlaylistControlEntries( QMenu *menu,
827 intf_thread_t *p_intf )
829 bool bEnable = THEMIM->getInput() != NULL;
831 addMIMStaticEntry( p_intf, menu, qtr( "&Stop" ), ":/menu/stop",
832 SLOT( stop() ), true );
833 /* Disable Stop in the right-click popup menu */
835 action->setEnabled( false );
837 /* Next / Previous */
838 addMIMStaticEntry( p_intf, menu, qtr( "Pre&vious" ),
839 ":/menu/previous", SLOT( prev() ) );
840 addMIMStaticEntry( p_intf, menu, qtr( "Ne&xt" ),
841 ":/menu/next", SLOT( next() ) );
843 menu->addSeparator();
846 void QVLCMenu::PopupMenuStaticEntries( QMenu *menu )
848 QMenu *openmenu = new QMenu( qtr( "Open a Media" ), menu );
849 addDPStaticEntry( openmenu, qtr( "&Open File..." ),
850 ":/type/file-asym", SLOT( openFileDialog() ) );
851 addDPStaticEntry( openmenu, qtr( I_OP_OPDIR ),
852 ":/type/folder-grey", SLOT( PLOpenDir() ) );
853 addDPStaticEntry( openmenu, qtr( "Open &Disc..." ),
854 ":/type/disc", SLOT( openDiscDialog() ) );
855 addDPStaticEntry( openmenu, qtr( "Open &Network..." ),
856 ":/type/network", SLOT( openNetDialog() ) );
857 addDPStaticEntry( openmenu, qtr( "Open &Capture Device..." ),
858 ":/type/capture-card", SLOT( openCaptureDialog() ) );
859 menu->addMenu( openmenu );
861 menu->addSeparator();
863 QMenu *helpmenu = HelpMenu( menu );
864 helpmenu->setTitle( qtr( "Help" ) );
865 menu->addMenu( helpmenu );
868 addDPStaticEntry( menu, qtr( "Quit" ), ":/menu/quit",
869 SLOT( quit() ), "Ctrl+Q", QAction::QuitRole );
872 /* Video Tracks and Subtitles tracks */
873 void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf, bool show )
878 vout_thread_t *p_vout = THEMIM->getVout();
881 VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
882 vlc_object_release( p_vout );
889 void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf, bool show )
894 aout_instance_t *p_aout = THEMIM->getAout();
895 AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
897 vlc_object_release( p_aout );
902 /* Navigation stuff, and general menus ( open ), used only for skins */
903 void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf, bool show )
909 varnames.push_back( "audio-es" );
910 InputAutoMenuBuilder( p_input, objects, varnames );
915 Populate( p_intf, menu, varnames, objects );
917 menu->addSeparator();
918 PopupPlayEntries( menu, p_intf, p_input );
919 PopupMenuPlaylistControlEntries( menu, p_intf);
921 menu->addSeparator();
922 PopupMenuControlEntries( menu, p_intf );
924 menu->addSeparator();
925 PopupMenuStaticEntries( menu );
927 menu->popup( QCursor::pos() );
930 /* Main Menu that sticks everything together */
931 void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show )
938 bool b_isFullscreen = false;
939 MainInterface *mi = p_intf->p_sys->p_mi;
941 PopupPlayEntries( menu, p_intf, p_input );
942 PopupMenuPlaylistControlEntries( menu, p_intf );
943 menu->addSeparator();
948 vout_thread_t *p_vout = THEMIM->getVout();
950 /* Add a fullscreen switch button, since it is the most used function */
953 vlc_value_t val; var_Get( p_vout, "fullscreen", &val );
955 b_isFullscreen = !( !val.b_bool );
959 CreateAndConnect( menu, "fullscreen",
960 qtr( "Leave Fullscreen" ),"" , ITEM_NORMAL,
961 VLC_OBJECT(p_vout), val, VLC_VAR_BOOL, b_isFullscreen );
963 vlc_object_release( p_vout );
965 menu->addSeparator();
969 InputAutoMenuBuilder( p_input, objects, varnames );
972 submenu = new QMenu( menu );
973 action = menu->addMenu( AudioMenu( p_intf, submenu ) );
974 action->setText( qtr( "&Audio" ) );
975 if( action->menu()->isEmpty() )
976 action->setEnabled( false );
979 submenu = new QMenu( menu );
980 action = menu->addMenu( VideoMenu( p_intf, submenu, false ) );
981 action->setText( qtr( "&Video" ) );
982 if( action->menu()->isEmpty() )
983 action->setEnabled( false );
985 submenu = SubtitleMenu( p_intf, menu );
986 submenu->setTitle( qtr( "Subti&tle") );
987 UpdateItem( p_intf, menu, "spu-es", VLC_OBJECT(p_input), true );
989 /* Playback menu for chapters */
990 submenu = new QMenu( menu );
991 action = menu->addMenu( NavigMenu( p_intf, submenu ) );
992 action->setText( qtr( "&Playback" ) );
993 if( action->menu()->isEmpty() )
994 action->setEnabled( false );
997 menu->addSeparator();
999 /* Add some special entries for windowed mode: Interface Menu */
1000 if( !b_isFullscreen )
1002 QMenu *submenu = new QMenu( qtr( "Tools" ), menu );
1003 /*QMenu *tools =*/ ToolsMenu( submenu );
1004 submenu->addSeparator();
1006 /* In skins interface, append some items */
1009 submenu->setTitle( qtr( "Interface" ) );
1010 if( p_intf->p_sys->b_isDialogProvider )
1012 vlc_object_t* p_object = p_intf->p_parent;
1014 objects.clear(); varnames.clear();
1015 objects.push_back( p_object );
1016 varnames.push_back( "intf-skins" );
1017 Populate( p_intf, submenu, varnames, objects );
1019 objects.clear(); varnames.clear();
1020 objects.push_back( p_object );
1021 varnames.push_back( "intf-skins-interactive" );
1022 Populate( p_intf, submenu, varnames, objects );
1025 msg_Warn( p_intf, "could not find parent interface" );
1029 QMenu *bar = menu; // Needed for next macro
1030 BAR_DADD( ViewMenu( p_intf, _menu, mi ), qtr( "V&iew" ), 4 );
1033 menu->addMenu( submenu );
1036 /* Static entries for ending, like open */
1037 PopupMenuStaticEntries( menu );
1039 menu->popup( QCursor::pos() );
1043 #undef POPUP_BOILERPLATE
1047 /************************************************************************
1049 ************************************************************************/
1051 void QVLCMenu::updateSystrayMenu( MainInterface *mi,
1052 intf_thread_t *p_intf,
1053 bool b_force_visible )
1055 input_thread_t *p_input = THEMIM->getInput();
1057 /* Get the systray menu and clean it */
1058 QMenu *sysMenu = mi->getSysTrayMenu();
1062 /* Hide / Show VLC and cone */
1063 if( mi->isVisible() || b_force_visible )
1065 sysMenu->addAction( QIcon( ":/logo/vlc16.png" ),
1066 qtr( "Hide VLC media player in taskbar" ), mi,
1067 SLOT( hideUpdateSystrayMenu() ) );
1071 sysMenu->addAction( QIcon( ":/logo/vlc16.png" ),
1072 qtr( "Show VLC media player" ), mi,
1073 SLOT( showUpdateSystrayMenu() ) );
1075 sysMenu->addSeparator();
1078 PopupPlayEntries( sysMenu, p_intf, p_input );
1079 PopupMenuPlaylistControlEntries( sysMenu, p_intf);
1080 PopupMenuControlEntries( sysMenu, p_intf);
1082 addDPStaticEntry( sysMenu, qtr( "&Open a Media" ),
1083 ":/type/file-wide", SLOT( openFileDialog() ) );
1084 addDPStaticEntry( sysMenu, qtr( "&Quit" ) ,
1085 ":/menu/quit", SLOT( quit() ) );
1088 mi->getSysTray()->setContextMenu( sysMenu );
1094 #undef PUSH_SEPARATOR
1096 /*************************************************************************
1097 * Builders for automenus
1098 *************************************************************************/
1099 QMenu * QVLCMenu::Populate( intf_thread_t *p_intf,
1101 vector< const char *> & varnames,
1102 vector<vlc_object_t *> & objects )
1104 QMenu *menu = current;
1107 currentGroup = NULL;
1109 for( int i = 0; i < (int)objects.size() ; i++ )
1111 if( !varnames[i] || !*varnames[i] )
1113 menu->addSeparator();
1117 UpdateItem( p_intf, menu, varnames[i], objects[i], true );
1122 /*****************************************************************************
1124 *****************************************************************************/
1126 static bool IsMenuEmpty( const char *psz_var,
1127 vlc_object_t *p_object,
1128 bool b_root = true )
1130 vlc_value_t val, val_list;
1131 int i_type, i_result, i;
1133 /* Check the type of the object variable */
1134 i_type = var_Type( p_object, psz_var );
1136 /* Check if we want to display the variable */
1137 if( !( i_type & VLC_VAR_HASCHOICE ) ) return false;
1139 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
1140 if( val.i_int == 0 ) return true;
1142 if( ( i_type & VLC_VAR_TYPE ) != VLC_VAR_VARIABLE )
1144 if( val.i_int == 1 && b_root ) return true;
1148 /* Check children variables in case of VLC_VAR_VARIABLE */
1149 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
1154 for( i = 0, i_result = true; i < val_list.p_list->i_count; i++ )
1156 if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
1164 /* clean up everything */
1165 var_FreeList( &val_list, NULL );
1170 #define TEXT_OR_VAR qfu ( text.psz_string ? text.psz_string : psz_var )
1172 void QVLCMenu::UpdateItem( intf_thread_t *p_intf, QMenu *menu,
1173 const char *psz_var, vlc_object_t *p_object, bool b_submenu )
1175 vlc_value_t val, text;
1178 QAction *action = FindActionWithVar( menu, psz_var );
1180 DeleteNonStaticEntries( action->menu() );
1185 action->setEnabled( false );
1189 /* Check the type of the object variable */
1190 /* This HACK is needed so we have a radio button for audio and video tracks
1191 instread of a checkbox */
1192 if( !strcmp( psz_var, "audio-es" )
1193 || !strcmp( psz_var, "video-es" ) )
1194 i_type = VLC_VAR_INTEGER | VLC_VAR_HASCHOICE;
1196 i_type = var_Type( p_object, psz_var );
1198 switch( i_type & VLC_VAR_TYPE )
1202 case VLC_VAR_VARIABLE:
1203 case VLC_VAR_STRING:
1204 case VLC_VAR_INTEGER:
1208 /* Variable doesn't exist or isn't handled */
1210 action->setEnabled( false );
1214 /* Make sure we want to display the variable */
1215 if( menu->isEmpty() && IsMenuEmpty( psz_var, p_object ) )
1218 action->setEnabled( false );
1222 /* Get the descriptive name of the variable */
1223 int i_ret = var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
1224 if( i_ret != VLC_SUCCESS )
1226 text.psz_string = NULL;
1231 action = new QAction( TEXT_OR_VAR, menu );
1232 menu->addAction( action );
1233 action->setData( psz_var );
1236 /* Some specific stuff */
1237 bool forceDisabled = false;
1238 if( !strcmp( psz_var, "spu-es" ) )
1240 vout_thread_t *p_vout = THEMIM->getVout();
1241 forceDisabled = ( p_vout == NULL );
1243 vlc_object_release( p_vout );
1246 if( i_type & VLC_VAR_HASCHOICE )
1248 /* Append choices menu */
1252 submenu = action->menu();
1255 submenu = new QMenu( menu );
1256 action->setMenu( submenu );
1260 CreateChoicesMenu( submenu, psz_var, p_object, true ) == 0 );
1262 action->setEnabled( false );
1267 CreateChoicesMenu( menu, psz_var, p_object, true ) == 0 );
1269 FREENULL( text.psz_string );
1273 switch( i_type & VLC_VAR_TYPE )
1276 val.i_int = 0; // Prevent the copy of an uninitialized value
1277 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_NORMAL,
1278 p_object, val, i_type );
1282 var_Get( p_object, psz_var, &val );
1283 val.b_bool = !val.b_bool;
1284 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_CHECK,
1285 p_object, val, i_type, !val.b_bool );
1288 FREENULL( text.psz_string );
1293 /** HACK for the navigation submenu:
1294 * "title %2i" variables take the value 0 if not set
1296 static bool CheckTitle( vlc_object_t *p_object, const char *psz_var )
1299 if( sscanf( psz_var, "title %2i", &i_title ) <= 0 )
1302 int i_current_title = var_GetInteger( p_object, "title" );
1303 return ( i_title == i_current_title );
1307 int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
1308 vlc_object_t *p_object, bool b_root )
1310 vlc_value_t val, val_list, text_list;
1313 /* Check the type of the object variable */
1314 i_type = var_Type( p_object, psz_var );
1316 /* Make sure we want to display the variable */
1317 if( submenu->isEmpty() && IsMenuEmpty( psz_var, p_object, b_root ) )
1318 return VLC_EGENERIC;
1320 switch( i_type & VLC_VAR_TYPE )
1324 case VLC_VAR_VARIABLE:
1325 case VLC_VAR_STRING:
1326 case VLC_VAR_INTEGER:
1330 /* Variable doesn't exist or isn't handled */
1331 return VLC_EGENERIC;
1334 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
1335 &val_list, &text_list ) < 0 )
1337 return VLC_EGENERIC;
1340 #define CURVAL val_list.p_list->p_values[i]
1341 #define CURTEXT text_list.p_list->p_values[i].psz_string
1342 #define RADIO_OR_COMMAND ( i_type & VLC_VAR_ISCOMMAND ) ? ITEM_NORMAL : ITEM_RADIO
1344 for( i = 0; i < val_list.p_list->i_count; i++ )
1346 vlc_value_t another_val;
1348 QMenu *subsubmenu = new QMenu( submenu );
1350 switch( i_type & VLC_VAR_TYPE )
1352 case VLC_VAR_VARIABLE:
1353 CreateChoicesMenu( subsubmenu, CURVAL.psz_string, p_object, false );
1354 subsubmenu->setTitle( qfu( CURTEXT ? CURTEXT :CURVAL.psz_string ) );
1355 submenu->addMenu( subsubmenu );
1358 case VLC_VAR_STRING:
1359 var_Get( p_object, psz_var, &val );
1360 another_val.psz_string = strdup( CURVAL.psz_string );
1361 menutext = qfu( CURTEXT ? CURTEXT : another_val.psz_string );
1362 CreateAndConnect( submenu, psz_var, menutext, "", RADIO_OR_COMMAND,
1363 p_object, another_val, i_type,
1364 val.psz_string && !strcmp( val.psz_string, CURVAL.psz_string ) );
1366 free( val.psz_string );
1369 case VLC_VAR_INTEGER:
1370 var_Get( p_object, psz_var, &val );
1371 if( CURTEXT ) menutext = qfu( CURTEXT );
1372 else menutext.sprintf( "%"PRId64, CURVAL.i_int );
1373 CreateAndConnect( submenu, psz_var, menutext, "", RADIO_OR_COMMAND,
1374 p_object, CURVAL, i_type,
1375 ( CURVAL.i_int == val.i_int )
1376 && CheckTitle( p_object, psz_var ) );
1380 var_Get( p_object, psz_var, &val );
1381 if( CURTEXT ) menutext = qfu( CURTEXT );
1382 else menutext.sprintf( "%.2f", CURVAL.f_float );
1383 CreateAndConnect( submenu, psz_var, menutext, "", RADIO_OR_COMMAND,
1384 p_object, CURVAL, i_type,
1385 CURVAL.f_float == val.f_float );
1392 currentGroup = NULL;
1394 /* clean up everything */
1395 var_FreeList( &val_list, &text_list );
1397 #undef RADIO_OR_COMMAND
1400 return submenu->isEmpty() ? VLC_EGENERIC : VLC_SUCCESS;
1403 void QVLCMenu::CreateAndConnect( QMenu *menu, const char *psz_var,
1404 const QString& text, const QString& help,
1405 int i_item_type, vlc_object_t *p_obj,
1406 vlc_value_t val, int i_val_type,
1409 QAction *action = FindActionWithVar( menu, psz_var );
1414 action = new QAction( text, menu );
1415 menu->addAction( action );
1419 action->setToolTip( help );
1420 action->setEnabled( p_obj != NULL );
1422 if( i_item_type == ITEM_CHECK )
1424 action->setCheckable( true );
1426 else if( i_item_type == ITEM_RADIO )
1428 action->setCheckable( true );
1430 currentGroup = new QActionGroup( menu );
1431 currentGroup->addAction( action );
1434 action->setChecked( checked );
1436 MenuItemData *itemData = qFindChild<MenuItemData*>( action, QString() );
1438 itemData = new MenuItemData( action, p_obj, i_val_type, val, psz_var );
1440 /* remove previous signal-slot connection(s) if any */
1441 action->disconnect( );
1443 CONNECT( action, triggered(), THEDP->menusMapper, map() );
1444 THEDP->menusMapper->setMapping( action, itemData );
1447 menu->addAction( action );
1450 void QVLCMenu::DoAction( QObject *data )
1452 MenuItemData *itemData = qobject_cast<MenuItemData *>( data );
1453 vlc_object_t *p_object = itemData->p_obj;
1454 if( p_object == NULL ) return;
1456 /* Preserve settings across vouts via the playlist object: */
1457 if( !strcmp( itemData->psz_var, "fullscreen" )
1458 || !strcmp( itemData->psz_var, "video-on-top" ) )
1459 var_Set( pl_Get( p_object ), itemData->psz_var, itemData->val );
1461 var_Set( p_object, itemData->psz_var, itemData->val );
1464 void QVLCMenu::updateRecents( intf_thread_t *p_intf )
1469 RecentsMRL* rmrl = RecentsMRL::getInstance( p_intf );
1470 QStringList l = rmrl->recents();
1472 recentsMenu->clear();
1476 action = recentsMenu->addAction( qtr(" - Empty - ") );
1477 action->setEnabled( false );
1481 for( int i = 0; i < l.size(); ++i )
1483 action = recentsMenu->addAction(
1484 QString( "&%1: " ).arg( i + 1 ) + l.at( i ),
1485 rmrl->signalMapper, SLOT( map() ),
1486 i <= 9 ? QString( "Ctrl+%1" ).arg( i + 1 ) : "" );
1487 rmrl->signalMapper->setMapping( action, l.at( i ) );
1490 recentsMenu->addSeparator();
1491 recentsMenu->addAction( qtr("&Clear"), rmrl, SLOT( clear() ) );