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>
58 This file defines the main menus and the pop-up menu (right-click menu)
59 and the systray menu (in that order in the file)
61 There are 4 menus that have to be rebuilt everytime there are called:
62 Audio, Video, Navigation, view
63 4 functions are building those menus: AudioMenu, VideoMenu, NavigMenu, View
64 and 3 functions associated are collecting the objects :
65 InputAutoMenuBuilder, AudioAutoMenuBuilder, VideoAutoMenuBuilder.
67 A QSignalMapper decides when to rebuild those menus cf MenuFunc in the .hpp
68 Just before one of those menus are aboutToShow(), they are rebuild.
71 #define STATIC_ENTRY "__static__"
72 #define ENTRY_ALWAYS_ENABLED "__ignore__"
76 ITEM_NORMAL, /* not a checkbox, nor a radio */
77 ITEM_CHECK, /* Checkbox */
78 ITEM_RADIO /* Radiobox */
81 static QActionGroup *currentGroup;
83 QMenu *QVLCMenu::recentsMenu = NULL;
86 * @brief Add static entries to DP in menus
88 QAction *addDPStaticEntry( QMenu *menu,
92 const char *shortcut = NULL,
93 QAction::MenuRole = QAction::NoRole
96 QAction *action = NULL;
97 #ifndef __APPLE__ /* We don't set icons in menus in MacOS X */
98 if( !EMPTY_STR( icon ) )
100 if( !EMPTY_STR( shortcut ) )
101 action = menu->addAction( QIcon( icon ), text, THEDP,
102 member, qtr( shortcut ) );
104 action = menu->addAction( QIcon( icon ), text, THEDP, member );
109 if( !EMPTY_STR( shortcut ) )
110 action = menu->addAction( text, THEDP, member, qtr( shortcut ) );
112 action = menu->addAction( text, THEDP, member );
114 action->setData( STATIC_ENTRY );
119 * @brief Add static entries to MIM in menus
121 QAction* addMIMStaticEntry( intf_thread_t *p_intf,
126 bool bStatic = false )
129 #ifndef __APPLE__ /* We don't set icons in menus in MacOS X */
130 if( !EMPTY_STR( icon ) )
132 action = menu->addAction( text, THEMIM, member );
133 action->setIcon( QIcon( icon ) );
138 action = menu->addAction( text, THEMIM, member );
140 action->setData( bStatic ? STATIC_ENTRY : ENTRY_ALWAYS_ENABLED );
145 * @brief Enable all static entries of a menu, disable the others
146 * @param menu the menu in which the entries will be disabled
147 * @param enable if false, disable all entries
149 void EnableStaticEntries( QMenu *menu, bool enable = true )
153 QList< QAction* > actions = menu->actions();
154 for( int i = 0; i < actions.size(); ++i )
156 actions[i]->setEnabled( actions[i]->data().toString()
157 == ENTRY_ALWAYS_ENABLED ||
158 /* Be careful here, because data("string").toBool is true */
159 ( enable && (actions[i]->data().toString() == STATIC_ENTRY ) ) );
164 * \return Number of static entries
166 inline int DeleteNonStaticEntries( QMenu *menu )
168 if( !menu ) return VLC_EGENERIC;
172 QList< QAction* > actions = menu->actions();
173 for( int i = 0; i < actions.size(); ++i )
175 if( actions[i]->data().toString() != STATIC_ENTRY )
184 * \return QAction associated to psz_var variable
186 static QAction * FindActionWithVar( QMenu *menu, const char *psz_var )
188 QList< QAction* > actions = menu->actions();
189 for( int i = 0; i < actions.size(); ++i )
191 if( actions[i]->data().toString() == psz_var )
197 /*****************************************************************************
198 * Definitions of variables for the dynamic menus
199 *****************************************************************************/
200 #define PUSH_VAR( var ) varnames.push_back( var ); \
201 objects.push_back( VLC_OBJECT(p_object) )
203 #define PUSH_INPUTVAR( var ) varnames.push_back( var ); \
204 objects.push_back( VLC_OBJECT(p_input) );
206 #define PUSH_SEPARATOR if( objects.size() != i_last_separator ) { \
207 objects.push_back( 0 ); varnames.push_back( "" ); \
208 i_last_separator = objects.size(); }
210 static int InputAutoMenuBuilder( input_thread_t *p_object,
211 vector<vlc_object_t *> &objects,
212 vector<const char *> &varnames )
214 PUSH_VAR( "bookmark" );
216 PUSH_VAR( "chapter" );
217 PUSH_VAR( "navigation" );
218 PUSH_VAR( "program" );
222 static int VideoAutoMenuBuilder( vout_thread_t *p_object,
223 input_thread_t *p_input,
224 vector<vlc_object_t *> &objects,
225 vector<const char *> &varnames )
227 PUSH_INPUTVAR( "video-es" );
228 PUSH_INPUTVAR( "spu-es" );
229 PUSH_VAR( "fullscreen" );
230 PUSH_VAR( "video-on-top" );
231 PUSH_VAR( "video-wallpaper" );
233 PUSH_VAR( "direct3d-desktop" );
235 PUSH_VAR( "video-snapshot" );
237 PUSH_VAR( "autoscale" );
238 PUSH_VAR( "aspect-ratio" );
240 PUSH_VAR( "deinterlace" );
241 PUSH_VAR( "deinterlace-mode" );
242 PUSH_VAR( "postprocess" );
247 static int AudioAutoMenuBuilder( aout_instance_t *p_object,
248 input_thread_t *p_input,
249 vector<vlc_object_t *> &objects,
250 vector<const char *> &varnames )
252 PUSH_INPUTVAR( "audio-es" );
253 PUSH_VAR( "audio-channels" );
254 PUSH_VAR( "audio-device" );
255 PUSH_VAR( "visual" );
259 /*****************************************************************************
262 *****************************************************************************/
265 static inline void addMenuToMainbar( QMenu *func, QString title, QMenuBar *bar ) {
266 func->setTitle( title );
271 #define BAR_DADD( func, title, id ) { \
272 QMenu *_menu = func; _menu->setTitle( title ); bar->addMenu( _menu ); \
273 MenuFunc *f = new MenuFunc( _menu, id ); \
274 CONNECT( _menu, aboutToShow(), THEDP->menusUpdateMapper, map() ); \
275 THEDP->menusUpdateMapper->setMapping( _menu, f ); }
277 // Add a simple action
278 static inline void addAction( QMenu *_menu, QVariant val, QString title ) {
279 QAction *_action = new QAction( title, _menu );
280 _action->setData( val );
281 _menu->addAction( _action );
284 // Add an action with a submenu
285 static inline void addActionWithSubmenu( QMenu *_menu, QVariant val, QString title ) {
286 QAction *_action = new QAction( title, _menu );
287 _action->setData( val );
288 _action->setMenu( new QMenu( _menu ) );
289 _menu->addAction( _action );
292 // Add an action that is a checkbox
293 static inline void addActionWithCheckbox( QMenu *_menu, QVariant val, QString title ) {
294 QAction *_action = new QAction( title, _menu );
295 _action->setData( val );
296 _action->setCheckable( true );
297 _menu->addAction( _action );
301 * Main Menu Bar Creation
303 void QVLCMenu::createMenuBar( MainInterface *mi,
304 intf_thread_t *p_intf )
306 /* QMainWindows->menuBar()
307 gives the QProcess::destroyed timeout issue on Cleanlooks style with
308 setDesktopAware set to false */
309 QMenuBar *bar = mi->menuBar();
311 addMenuToMainbar( FileMenu( p_intf, bar ), qtr( "&Media" ), bar );
313 /* Dynamic menus, rebuilt before being showed */
314 BAR_DADD( NavigMenu( p_intf, bar ), qtr( "P&layback" ), 3 );
315 BAR_DADD( AudioMenu( p_intf, bar ), qtr( "&Audio" ), 1 );
316 BAR_DADD( VideoMenu( p_intf, bar ), qtr( "&Video" ), 2 );
318 addMenuToMainbar( ToolsMenu( bar ), qtr( "&Tools" ), bar );
320 /* View menu, a bit different */
321 BAR_DADD( ViewMenu( p_intf, _menu, mi ), qtr( "V&iew" ), 4 );
323 addMenuToMainbar( HelpMenu( bar ), qtr( "&Help" ), bar );
328 * Media ( File ) Menu
329 * Opening, streaming and quit
331 QMenu *QVLCMenu::FileMenu( intf_thread_t *p_intf, QWidget *parent )
333 QMenu *menu = new QMenu( parent );
336 addDPStaticEntry( menu, qtr( "&Open (advanced)..." ),
337 ":/type/file-asym", SLOT( openFileDialog() ), "Ctrl+Shift+O" );
338 menu->addSeparator();
339 addDPStaticEntry( menu, qtr( "Open &File..." ),
340 ":/type/file-asym", SLOT( simpleOpenDialog() ), "Ctrl+O" );
341 addDPStaticEntry( menu, qtr( I_OP_OPDIR ),
342 ":/type/folder-grey", SLOT( PLOpenDir() ), "Ctrl+F" );
343 addDPStaticEntry( menu, qtr( "Open &Disc..." ),
344 ":/type/disc", SLOT( openDiscDialog() ), "Ctrl+D" );
345 addDPStaticEntry( menu, qtr( "Open &Network Stream..." ),
346 ":/type/network", SLOT( openNetDialog() ), "Ctrl+N" );
347 addDPStaticEntry( menu, qtr( "Open &Capture Device..." ),
348 ":/type/capture-card", SLOT( openCaptureDialog() ), "Ctrl+C" );
350 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 addDPStaticEntry( menu, qtr( "&Quit" ) ,
380 ":/menu/quit", SLOT( quit() ), "Ctrl+Q" );
385 * Tools, like Media Information, Preferences or Messages
387 QMenu *QVLCMenu::ToolsMenu( QMenu *menu )
389 addDPStaticEntry( menu, qtr( "&Effects and Filters"), ":/menu/settings",
390 SLOT( extendedDialog() ), "Ctrl+E" );
392 addDPStaticEntry( menu, qtr( "&Track Synchronization"), ":/menu/settings",
393 SLOT( synchroDialog() ), "" );
395 addDPStaticEntry( menu, qtr( I_MENU_INFO ) , ":/menu/info",
396 SLOT( mediaInfoDialog() ), "Ctrl+I" );
397 addDPStaticEntry( menu, qtr( I_MENU_CODECINFO ) ,
398 ":/menu/info", SLOT( mediaCodecDialog() ), "Ctrl+J" );
401 addDPStaticEntry( menu, qtr( I_MENU_VLM ), "", SLOT( vlmDialog() ),
405 addDPStaticEntry( menu, qtr( "Program Guide" ), "", SLOT( epgDialog() ),
408 addDPStaticEntry( menu, qtr( I_MENU_MSG ),
409 ":/menu/messages", SLOT( messagesDialog() ), "Ctrl+M" );
411 addDPStaticEntry( menu, qtr( "Plu&gins and extensions" ),
412 "", SLOT( pluginDialog() ) );
413 menu->addSeparator();
415 addDPStaticEntry( menu, qtr( "Customi&ze Interface..." ),
416 ":/menu/preferences", SLOT( toolbarDialog() ) );
418 addDPStaticEntry( menu, qtr( "&Preferences" ),
419 ":/menu/preferences", SLOT( prefsDialog() ), "Ctrl+P", QAction::PreferencesRole );
426 * Interface modification, load other interfaces, activate Extensions
428 QMenu *QVLCMenu::ViewMenu( intf_thread_t *p_intf, QMenu *current, MainInterface *_mi )
433 MainInterface *mi = _mi ? _mi : p_intf->p_sys->p_mi;
438 menu = new QMenu( qtr( "&View" ), mi );
444 //HACK menu->clear() does not delete submenus
445 QList<QAction*> actions = menu->actions();
446 foreach( QAction *a, actions )
448 QMenu *m = a->menu();
449 if( a->parent() == menu ) delete a;
450 else menu->removeAction( a );
451 if( m && m->parent() == menu ) delete m;
457 QIcon( ":/menu/playlist_menu" ),
459 qtr( "Play&list" ), mi,
460 SLOT( togglePlaylist() ), qtr( "Ctrl+L" ) );
462 menu->addSeparator();
465 action = menu->addAction( qtr( "Mi&nimal Interface" ) );
466 action->setShortcut( qtr( "Ctrl+H" ) );
467 action->setCheckable( true );
468 action->setChecked( (mi->getControlsVisibilityStatus() & CONTROLS_HIDDEN ) );
470 CONNECT( action, triggered( bool ), mi, toggleMinimalView( bool ) );
471 CONNECT( mi, minimalViewToggled( bool ), action, setChecked( bool ) );
473 /* FullScreen View */
474 action = menu->addAction( qtr( "&Fullscreen Interface" ), mi,
475 SLOT( toggleInterfaceFullScreen() ), QString( "F11" ) );
476 action->setCheckable( true );
477 action->setChecked( mi->isInterfaceFullScreen() );
478 CONNECT( mi, fullscreenInterfaceToggled( bool ),
479 action, setChecked( bool ) );
481 /* Advanced Controls */
482 action = menu->addAction( qtr( "&Advanced Controls" ), mi,
483 SLOT( toggleAdvancedButtons() ) );
484 action->setCheckable( true );
485 if( mi->getControlsVisibilityStatus() & CONTROLS_ADVANCED )
486 action->setChecked( true );
488 /* Docked Playlist */
489 action = menu->addAction( qtr( "Docked Playlist" ) );
490 action->setCheckable( true );
491 action->setChecked( mi->isPlDocked() );
492 CONNECT( action, triggered( bool ), mi, dockPlaylist( bool ) );
494 #if 0 /* For Visualisations. Not yet working */
495 adv = menu->addAction( qtr( "Visualizations selector" ), mi,
497 adv->setCheckable( true );
498 if( visual_selector_enabled ) adv->setChecked( true );
501 menu->addSeparator();
503 InterfacesMenu( p_intf, menu );
504 menu->addSeparator();
507 ExtensionsMenu( p_intf, menu );
513 * Interface Sub-Menu, to list extras interface and skins
515 QMenu *QVLCMenu::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
517 vector<vlc_object_t *> objects;
518 vector<const char *> varnames;
519 varnames.push_back( "intf-add" );
520 objects.push_back( VLC_OBJECT(p_intf) );
522 return Populate( p_intf, current, varnames, objects );
526 * Extensions menu: populate the current menu with extensions
528 void QVLCMenu::ExtensionsMenu( intf_thread_t *p_intf, QMenu *extMenu )
530 /* Get ExtensionsManager and load extensions if needed */
531 ExtensionsManager *extMgr = ExtensionsManager::getInstance( p_intf );
533 if( !var_InheritBool( p_intf, "qt-autoload-extensions")
534 && !extMgr->isLoaded() )
539 if( !extMgr->isLoaded() && !extMgr->cannotLoad() )
541 extMgr->loadExtensions();
544 /* Let the ExtensionsManager build itself the menu */
545 extMenu->addSeparator();
546 extMgr->menu( extMenu );
552 QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QMenu * current )
554 vector<vlc_object_t *> objects;
555 vector<const char *> varnames;
556 aout_instance_t *p_aout;
557 input_thread_t *p_input;
559 if( current->isEmpty() )
561 addActionWithSubmenu( current, "audio-es", qtr( "Audio &Track" ) );
562 addActionWithSubmenu( current, "audio-channels", qtr( "Audio &Channels" ) );
563 addActionWithSubmenu( current, "audio-device", qtr( "Audio &Device" ) );
564 current->addSeparator();
566 addActionWithSubmenu( current, "visual", qtr( "&Visualizations" ) );
567 current->addSeparator();
569 QAction *action = current->addAction( qtr( "Increase Volume" ),
570 ActionsManager::getInstance( p_intf ), SLOT( AudioUp() ) );
571 action->setData( STATIC_ENTRY );
572 action = current->addAction( qtr( "Decrease Volume" ),
573 ActionsManager::getInstance( p_intf ), SLOT( AudioDown() ) );
574 action->setData( STATIC_ENTRY );
575 action = current->addAction( qtr( "Mute" ),
576 ActionsManager::getInstance( p_intf ), SLOT( toggleMuteAudio() ) );
577 action->setData( STATIC_ENTRY );
580 p_input = THEMIM->getInput();
581 p_aout = THEMIM->getAout();
582 EnableStaticEntries( current, ( p_aout != NULL ) );
583 AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
586 vlc_object_release( p_aout );
589 return Populate( p_intf, current, varnames, objects );
593 QMenu *QVLCMenu::SubMenu( intf_thread_t *p_intf, QMenu *current )
596 QMenu *submenu = new QMenu( qtr( "&Subtitles Track" ), current );
597 action = current->addMenu( submenu );
598 action->setData( "spu-es" );
599 addDPStaticEntry( submenu, qtr( "Open File..." ), "",
600 SLOT( loadSubtitlesFile() ) );
601 submenu->addSeparator();
607 * Subtitles are part of Video.
609 QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current, bool b_subtitle )
611 vout_thread_t *p_vout;
612 input_thread_t *p_input;
613 vector<vlc_object_t *> objects;
614 vector<const char *> varnames;
616 if( current->isEmpty() )
618 addActionWithSubmenu( current, "video-es", qtr( "Video &Track" ) );
620 SubMenu( p_intf, current );
622 current->addSeparator();
624 addActionWithCheckbox( current, "fullscreen", qtr( "&Fullscreen" ) );
625 addActionWithCheckbox( current, "autoscale", qtr( "Always Fit &Window" ) );
626 addActionWithCheckbox( current, "video-on-top", qtr( "Always &on Top" ) );
628 addActionWithCheckbox( current, "direct3d-desktop", qtr( "Display on &Desktop" ) );
630 addAction( current, "video-snapshot", qtr( "Take &Snapshot" ) );
632 addActionWithCheckbox( current, "video-wallpaper", qtr( "Set as Wall&paper" ) );
634 current->addSeparator();
636 addActionWithSubmenu( current, "zoom", qtr( "&Zoom" ) );
637 addActionWithSubmenu( current, "aspect-ratio", qtr( "&Aspect Ratio" ) );
638 addActionWithSubmenu( current, "crop", qtr( "&Crop" ) );
639 addActionWithSubmenu( current, "deinterlace", qtr( "&Deinterlace" ) );
640 addActionWithSubmenu( current, "deinterlace-mode", qtr( "&Deinterlace mode" ) );
641 addActionWithSubmenu( current, "postprocess", qtr( "&Post processing" ) );
644 p_input = THEMIM->getInput();
646 p_vout = THEMIM->getVout();
647 VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
650 vlc_object_release( p_vout );
652 return Populate( p_intf, current, varnames, objects );
657 * For DVD, MP4, MOV and other chapter based format
659 QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *menu )
663 addActionWithSubmenu( menu, "title", qtr( "T&itle" ) );
664 addActionWithSubmenu( menu, "chapter", qtr( "&Chapter" ) );
665 addActionWithSubmenu( menu, "navigation", qtr( "&Navigation" ) );
666 addActionWithSubmenu( menu, "program", qtr( "&Program" ) );
668 /* FixMe: sync I_MENU_BOOKMARK string */
669 QMenu *submenu = new QMenu( qtr( "Custom &Bookmarks" ), menu );
670 addDPStaticEntry( submenu, qtr( "&Manage" ), "",
671 SLOT( bookmarksDialog() ), "Ctrl+B" );
672 submenu->addSeparator();
673 action = menu->addMenu( submenu );
674 action->setData( "bookmark" );
676 menu->addSeparator();
677 PopupMenuPlaylistControlEntries( menu, p_intf );
678 PopupMenuControlEntries( menu, p_intf );
680 EnableStaticEntries( menu, ( THEMIM->getInput() != NULL ) );
681 return RebuildNavigMenu( p_intf, menu );
684 QMenu *QVLCMenu::RebuildNavigMenu( intf_thread_t *p_intf, QMenu *menu )
687 input_thread_t *p_object;
688 vector<vlc_object_t *> objects;
689 vector<const char *> varnames;
691 /* Get the input and hold it */
692 p_object = THEMIM->getInput();
694 InputAutoMenuBuilder( p_object, objects, varnames );
696 menu->addSeparator();
698 /* Title and so on */
699 PUSH_VAR( "prev-title" );
700 PUSH_VAR( "next-title" );
701 PUSH_VAR( "prev-chapter" );
702 PUSH_VAR( "next-chapter" );
704 EnableStaticEntries( menu, (p_object != NULL ) );
705 return Populate( p_intf, menu, varnames, objects );
711 QMenu *QVLCMenu::HelpMenu( QWidget *parent )
713 QMenu *menu = new QMenu( parent );
714 addDPStaticEntry( menu, qtr( "&Help..." ) ,
715 ":/menu/help", SLOT( helpDialog() ), "F1" );
717 addDPStaticEntry( menu, qtr( "Check for &Updates..." ) , "",
718 SLOT( updateDialog() ) );
720 menu->addSeparator();
721 addDPStaticEntry( menu, qtr( I_MENU_ABOUT ), ":/menu/info",
722 SLOT( aboutDialog() ), "Shift+F1", QAction::AboutRole );
726 /*****************************************************************************
727 * Popup menus - Right Click menus *
728 *****************************************************************************/
729 #define POPUP_BOILERPLATE \
730 static QMenu* menu = NULL; \
731 delete menu; menu = NULL; \
734 unsigned int i_last_separator = 0; \
735 vector<vlc_object_t *> objects; \
736 vector<const char *> varnames; \
737 input_thread_t *p_input = THEMIM->getInput();
739 #define CREATE_POPUP \
740 menu = new QMenu(); \
741 Populate( p_intf, menu, varnames, objects ); \
742 menu->popup( QCursor::pos() ); \
743 i_last_separator = 0;
745 void QVLCMenu::PopupPlayEntries( QMenu *menu,
746 intf_thread_t *p_intf,
747 input_thread_t *p_input )
751 /* Play or Pause action and icon */
752 if( !p_input || var_GetInteger( p_input, "state" ) != PLAYING_S )
754 action = menu->addAction( qtr( "Play" ),
755 ActionsManager::getInstance( p_intf ), SLOT( play() ) );
756 #ifndef __APPLE__ /* No icons in menus in Mac */
757 action->setIcon( QIcon( ":/menu/play" ) );
762 addMIMStaticEntry( p_intf, menu, qtr( "Pause" ),
763 ":/menu/pause", SLOT( togglePlayPause() ) );
767 void QVLCMenu::PopupMenuControlEntries( QMenu *menu, intf_thread_t *p_intf )
772 action = menu->addAction( qtr( "&Faster" ), THEMIM->getIM(),
774 #ifndef __APPLE__ /* No icons in menus in Mac */
775 action->setIcon( QIcon( ":/toolbar/faster") );
777 action->setData( STATIC_ENTRY );
779 action = menu->addAction( qtr( "Faster (fine)" ), THEMIM->getIM(),
780 SLOT( littlefaster() ) );
781 action->setData( STATIC_ENTRY );
783 action = menu->addAction( qtr( "N&ormal Speed" ), THEMIM->getIM(),
784 SLOT( normalRate() ) );
785 action->setData( STATIC_ENTRY );
787 action = menu->addAction( qtr( "Slower (fine)" ), THEMIM->getIM(),
788 SLOT( littleslower() ) );
789 action->setData( STATIC_ENTRY );
791 action = menu->addAction( qtr( "Slo&wer" ), THEMIM->getIM(),
793 #ifndef __APPLE__ /* No icons in menus in Mac */
794 action->setIcon( QIcon( ":/toolbar/slower") );
796 action->setData( STATIC_ENTRY );
798 menu->addSeparator();
800 action = menu->addAction( qtr( "&Jump Forward" ), THEMIM->getIM(),
802 #ifndef __APPLE__ /* No icons in menus in Mac */
803 action->setIcon( QIcon( ":/toolbar/skip_fw") );
805 action->setData( STATIC_ENTRY );
807 action = menu->addAction( qtr( "Jump Bac&kward" ), THEMIM->getIM(),
809 #ifndef __APPLE__ /* No icons in menus in Mac */
810 action->setIcon( QIcon( ":/toolbar/skip_back") );
812 action->setData( STATIC_ENTRY );
813 addDPStaticEntry( menu, qtr( I_MENU_GOTOTIME ),"",
814 SLOT( gotoTimeDialog() ), "Ctrl+T" );
815 menu->addSeparator();
819 void QVLCMenu::PopupMenuPlaylistControlEntries( QMenu *menu,
820 intf_thread_t *p_intf )
822 bool bEnable = THEMIM->getInput() != NULL;
824 addMIMStaticEntry( p_intf, menu, qtr( "&Stop" ), ":/menu/stop",
825 SLOT( stop() ), true );
826 /* Disable Stop in the right-click popup menu */
828 action->setEnabled( false );
830 /* Next / Previous */
831 addMIMStaticEntry( p_intf, menu, qtr( "Pre&vious" ),
832 ":/menu/previous", SLOT( prev() ) );
833 addMIMStaticEntry( p_intf, menu, qtr( "Ne&xt" ),
834 ":/menu/next", SLOT( next() ) );
836 menu->addSeparator();
839 void QVLCMenu::PopupMenuStaticEntries( QMenu *menu )
841 QMenu *openmenu = new QMenu( qtr( "Open a Media" ), menu );
842 addDPStaticEntry( openmenu, qtr( "&Open File..." ),
843 ":/type/file-asym", SLOT( openFileDialog() ) );
844 addDPStaticEntry( openmenu, qtr( I_OP_OPDIR ),
845 ":/type/folder-grey", SLOT( PLOpenDir() ) );
846 addDPStaticEntry( openmenu, qtr( "Open &Disc..." ),
847 ":/type/disc", SLOT( openDiscDialog() ) );
848 addDPStaticEntry( openmenu, qtr( "Open &Network..." ),
849 ":/type/network", SLOT( openNetDialog() ) );
850 addDPStaticEntry( openmenu, qtr( "Open &Capture Device..." ),
851 ":/type/capture-card", SLOT( openCaptureDialog() ) );
852 menu->addMenu( openmenu );
854 menu->addSeparator();
856 QMenu *helpmenu = HelpMenu( menu );
857 helpmenu->setTitle( qtr( "Help" ) );
858 menu->addMenu( helpmenu );
861 addDPStaticEntry( menu, qtr( "Quit" ), ":/menu/quit",
862 SLOT( quit() ), "Ctrl+Q", QAction::QuitRole );
865 /* Video Tracks and Subtitles tracks */
866 void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf, bool show )
871 vout_thread_t *p_vout = THEMIM->getVout();
874 VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
875 vlc_object_release( p_vout );
882 void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf, bool show )
887 aout_instance_t *p_aout = THEMIM->getAout();
888 AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
890 vlc_object_release( p_aout );
895 /* Navigation stuff, and general menus ( open ), used only for skins */
896 void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf, bool show )
902 varnames.push_back( "audio-es" );
903 InputAutoMenuBuilder( p_input, objects, varnames );
908 Populate( p_intf, menu, varnames, objects );
910 menu->addSeparator();
911 PopupPlayEntries( menu, p_intf, p_input );
912 PopupMenuPlaylistControlEntries( menu, p_intf);
914 menu->addSeparator();
915 PopupMenuControlEntries( menu, p_intf );
917 menu->addSeparator();
918 PopupMenuStaticEntries( menu );
920 menu->popup( QCursor::pos() );
923 /* Main Menu that sticks everything together */
924 void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show )
931 bool b_isFullscreen = false;
932 MainInterface *mi = p_intf->p_sys->p_mi;
934 PopupPlayEntries( menu, p_intf, p_input );
935 PopupMenuPlaylistControlEntries( menu, p_intf );
936 menu->addSeparator();
941 vout_thread_t *p_vout = THEMIM->getVout();
943 /* Add a fullscreen switch button, since it is the most used function */
946 vlc_value_t val; var_Get( p_vout, "fullscreen", &val );
948 b_isFullscreen = !( !val.b_bool );
952 CreateAndConnect( menu, "fullscreen",
953 qtr( "Leave Fullscreen" ),"" , ITEM_NORMAL,
954 VLC_OBJECT(p_vout), val, VLC_VAR_BOOL, b_isFullscreen );
956 vlc_object_release( p_vout );
958 menu->addSeparator();
962 InputAutoMenuBuilder( p_input, objects, varnames );
965 submenu = new QMenu( menu );
966 action = menu->addMenu( AudioMenu( p_intf, submenu ) );
967 action->setText( qtr( "&Audio" ) );
968 if( action->menu()->isEmpty() )
969 action->setEnabled( false );
972 submenu = new QMenu( menu );
973 action = menu->addMenu( VideoMenu( p_intf, submenu, false ) );
974 action->setText( qtr( "&Video" ) );
975 if( action->menu()->isEmpty() )
976 action->setEnabled( false );
978 SubMenu( p_intf, menu )->setTitle( qtr( "Subti&tle") );
980 /* Playback menu for chapters */
981 submenu = new QMenu( menu );
982 action = menu->addMenu( NavigMenu( p_intf, submenu ) );
983 action->setText( qtr( "&Playback" ) );
984 if( action->menu()->isEmpty() )
985 action->setEnabled( false );
988 menu->addSeparator();
990 /* Add some special entries for windowed mode: Interface Menu */
991 if( !b_isFullscreen )
993 QMenu *submenu = new QMenu( qtr( "Tools" ), menu );
994 /*QMenu *tools =*/ ToolsMenu( submenu );
995 submenu->addSeparator();
997 /* In skins interface, append some items */
1000 submenu->setTitle( qtr( "Interface" ) );
1001 if( p_intf->p_sys->b_isDialogProvider )
1003 vlc_object_t* p_object = p_intf->p_parent;
1005 objects.clear(); varnames.clear();
1006 objects.push_back( p_object );
1007 varnames.push_back( "intf-skins" );
1008 Populate( p_intf, submenu, varnames, objects );
1010 objects.clear(); varnames.clear();
1011 objects.push_back( p_object );
1012 varnames.push_back( "intf-skins-interactive" );
1013 Populate( p_intf, submenu, varnames, objects );
1016 msg_Warn( p_intf, "could not find parent interface" );
1020 QMenu *bar = menu; // Needed for next macro
1021 BAR_DADD( ViewMenu( p_intf, _menu, mi ), qtr( "V&iew" ), 4 );
1024 menu->addMenu( submenu );
1027 /* Static entries for ending, like open */
1028 PopupMenuStaticEntries( menu );
1030 menu->popup( QCursor::pos() );
1034 #undef POPUP_BOILERPLATE
1038 /************************************************************************
1040 ************************************************************************/
1042 void QVLCMenu::updateSystrayMenu( MainInterface *mi,
1043 intf_thread_t *p_intf,
1044 bool b_force_visible )
1046 input_thread_t *p_input = THEMIM->getInput();
1048 /* Get the systray menu and clean it */
1049 QMenu *sysMenu = mi->getSysTrayMenu();
1053 /* Hide / Show VLC and cone */
1054 if( mi->isVisible() || b_force_visible )
1056 sysMenu->addAction( QIcon( ":/logo/vlc16.png" ),
1057 qtr( "Hide VLC media player in taskbar" ), mi,
1058 SLOT( hideUpdateSystrayMenu() ) );
1062 sysMenu->addAction( QIcon( ":/logo/vlc16.png" ),
1063 qtr( "Show VLC media player" ), mi,
1064 SLOT( showUpdateSystrayMenu() ) );
1066 sysMenu->addSeparator();
1069 PopupPlayEntries( sysMenu, p_intf, p_input );
1070 PopupMenuPlaylistControlEntries( sysMenu, p_intf);
1071 PopupMenuControlEntries( sysMenu, p_intf);
1073 addDPStaticEntry( sysMenu, qtr( "&Open a Media" ),
1074 ":/type/file-wide", SLOT( openFileDialog() ) );
1075 addDPStaticEntry( sysMenu, qtr( "&Quit" ) ,
1076 ":/menu/quit", SLOT( quit() ) );
1079 mi->getSysTray()->setContextMenu( sysMenu );
1085 #undef PUSH_SEPARATOR
1087 /*************************************************************************
1088 * Builders for automenus
1089 *************************************************************************/
1090 QMenu * QVLCMenu::Populate( intf_thread_t *p_intf,
1092 vector< const char *> & varnames,
1093 vector<vlc_object_t *> & objects )
1095 QMenu *menu = current;
1098 currentGroup = NULL;
1100 for( int i = 0; i < (int)objects.size() ; i++ )
1102 if( !varnames[i] || !*varnames[i] )
1104 menu->addSeparator();
1108 UpdateItem( p_intf, menu, varnames[i], objects[i], true );
1113 /*****************************************************************************
1115 *****************************************************************************/
1117 static bool IsMenuEmpty( const char *psz_var,
1118 vlc_object_t *p_object,
1119 bool b_root = true )
1121 vlc_value_t val, val_list;
1122 int i_type, i_result, i;
1124 /* Check the type of the object variable */
1125 i_type = var_Type( p_object, psz_var );
1127 /* Check if we want to display the variable */
1128 if( !( i_type & VLC_VAR_HASCHOICE ) ) return false;
1130 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
1131 if( val.i_int == 0 ) return true;
1133 if( ( i_type & VLC_VAR_TYPE ) != VLC_VAR_VARIABLE )
1135 if( val.i_int == 1 && b_root ) return true;
1139 /* Check children variables in case of VLC_VAR_VARIABLE */
1140 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
1145 for( i = 0, i_result = true; i < val_list.p_list->i_count; i++ )
1147 if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
1155 /* clean up everything */
1156 var_FreeList( &val_list, NULL );
1161 #define TEXT_OR_VAR qfu ( text.psz_string ? text.psz_string : psz_var )
1163 void QVLCMenu::UpdateItem( intf_thread_t *p_intf, QMenu *menu,
1164 const char *psz_var, vlc_object_t *p_object, bool b_submenu )
1166 vlc_value_t val, text;
1169 QAction *action = FindActionWithVar( menu, psz_var );
1171 DeleteNonStaticEntries( action->menu() );
1176 action->setEnabled( false );
1180 /* Check the type of the object variable */
1181 /* This HACK is needed so we have a radio button for audio and video tracks
1182 instread of a checkbox */
1183 if( !strcmp( psz_var, "audio-es" )
1184 || !strcmp( psz_var, "video-es" ) )
1185 i_type = VLC_VAR_INTEGER | VLC_VAR_HASCHOICE;
1187 i_type = var_Type( p_object, psz_var );
1189 switch( i_type & VLC_VAR_TYPE )
1193 case VLC_VAR_VARIABLE:
1194 case VLC_VAR_STRING:
1195 case VLC_VAR_INTEGER:
1199 /* Variable doesn't exist or isn't handled */
1201 action->setEnabled( false );
1205 /* Make sure we want to display the variable */
1206 if( menu->isEmpty() && IsMenuEmpty( psz_var, p_object ) )
1209 action->setEnabled( false );
1213 /* Get the descriptive name of the variable */
1214 int i_ret = var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
1215 if( i_ret != VLC_SUCCESS )
1217 text.psz_string = NULL;
1222 action = new QAction( TEXT_OR_VAR, menu );
1223 menu->addAction( action );
1224 action->setData( psz_var );
1227 /* Some specific stuff */
1228 bool forceDisabled = false;
1229 if( !strcmp( psz_var, "spu-es" ) )
1231 vout_thread_t *p_vout = THEMIM->getVout();
1232 forceDisabled = ( p_vout == NULL );
1234 vlc_object_release( p_vout );
1237 if( i_type & VLC_VAR_HASCHOICE )
1239 /* Append choices menu */
1243 submenu = action->menu();
1246 submenu = new QMenu( menu );
1247 action->setMenu( submenu );
1251 CreateChoicesMenu( submenu, psz_var, p_object, true ) == 0 );
1253 action->setEnabled( false );
1258 CreateChoicesMenu( menu, psz_var, p_object, true ) == 0 );
1260 FREENULL( text.psz_string );
1264 switch( i_type & VLC_VAR_TYPE )
1267 val.i_int = 0; // Prevent the copy of an uninitialized value
1268 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_NORMAL,
1269 p_object, val, i_type );
1273 var_Get( p_object, psz_var, &val );
1274 val.b_bool = !val.b_bool;
1275 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_CHECK,
1276 p_object, val, i_type, !val.b_bool );
1279 FREENULL( text.psz_string );
1284 /** HACK for the navigation submenu:
1285 * "title %2i" variables take the value 0 if not set
1287 static bool CheckTitle( vlc_object_t *p_object, const char *psz_var )
1290 if( sscanf( psz_var, "title %2i", &i_title ) <= 0 )
1293 int i_current_title = var_GetInteger( p_object, "title" );
1294 return ( i_title == i_current_title );
1298 int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
1299 vlc_object_t *p_object, bool b_root )
1301 vlc_value_t val, val_list, text_list;
1304 /* Check the type of the object variable */
1305 i_type = var_Type( p_object, psz_var );
1307 /* Make sure we want to display the variable */
1308 if( submenu->isEmpty() && IsMenuEmpty( psz_var, p_object, b_root ) )
1309 return VLC_EGENERIC;
1311 switch( i_type & VLC_VAR_TYPE )
1315 case VLC_VAR_VARIABLE:
1316 case VLC_VAR_STRING:
1317 case VLC_VAR_INTEGER:
1321 /* Variable doesn't exist or isn't handled */
1322 return VLC_EGENERIC;
1325 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
1326 &val_list, &text_list ) < 0 )
1328 return VLC_EGENERIC;
1331 #define CURVAL val_list.p_list->p_values[i]
1332 #define CURTEXT text_list.p_list->p_values[i].psz_string
1333 #define RADIO_OR_COMMAND ( i_type & VLC_VAR_ISCOMMAND ) ? ITEM_NORMAL : ITEM_RADIO
1335 for( i = 0; i < val_list.p_list->i_count; i++ )
1337 vlc_value_t another_val;
1339 QMenu *subsubmenu = new QMenu( submenu );
1341 switch( i_type & VLC_VAR_TYPE )
1343 case VLC_VAR_VARIABLE:
1344 CreateChoicesMenu( subsubmenu, CURVAL.psz_string, p_object, false );
1345 subsubmenu->setTitle( qfu( CURTEXT ? CURTEXT :CURVAL.psz_string ) );
1346 submenu->addMenu( subsubmenu );
1349 case VLC_VAR_STRING:
1350 var_Get( p_object, psz_var, &val );
1351 another_val.psz_string = strdup( CURVAL.psz_string );
1352 menutext = qfu( CURTEXT ? CURTEXT : another_val.psz_string );
1353 CreateAndConnect( submenu, psz_var, menutext, "", RADIO_OR_COMMAND,
1354 p_object, another_val, i_type,
1355 val.psz_string && !strcmp( val.psz_string, CURVAL.psz_string ) );
1357 free( val.psz_string );
1360 case VLC_VAR_INTEGER:
1361 var_Get( p_object, psz_var, &val );
1362 if( CURTEXT ) menutext = qfu( CURTEXT );
1363 else menutext.sprintf( "%"PRId64, CURVAL.i_int );
1364 CreateAndConnect( submenu, psz_var, menutext, "", RADIO_OR_COMMAND,
1365 p_object, CURVAL, i_type,
1366 ( CURVAL.i_int == val.i_int )
1367 && CheckTitle( p_object, psz_var ) );
1371 var_Get( p_object, psz_var, &val );
1372 if( CURTEXT ) menutext = qfu( CURTEXT );
1373 else menutext.sprintf( "%.2f", CURVAL.f_float );
1374 CreateAndConnect( submenu, psz_var, menutext, "", RADIO_OR_COMMAND,
1375 p_object, CURVAL, i_type,
1376 CURVAL.f_float == val.f_float );
1383 currentGroup = NULL;
1385 /* clean up everything */
1386 var_FreeList( &val_list, &text_list );
1388 #undef RADIO_OR_COMMAND
1391 return submenu->isEmpty() ? VLC_EGENERIC : VLC_SUCCESS;
1394 void QVLCMenu::CreateAndConnect( QMenu *menu, const char *psz_var,
1395 const QString& text, const QString& help,
1396 int i_item_type, vlc_object_t *p_obj,
1397 vlc_value_t val, int i_val_type,
1400 QAction *action = FindActionWithVar( menu, psz_var );
1405 action = new QAction( text, menu );
1406 menu->addAction( action );
1410 action->setToolTip( help );
1411 action->setEnabled( p_obj != NULL );
1413 if( i_item_type == ITEM_CHECK )
1415 action->setCheckable( true );
1417 else if( i_item_type == ITEM_RADIO )
1419 action->setCheckable( true );
1421 currentGroup = new QActionGroup( menu );
1422 currentGroup->addAction( action );
1425 action->setChecked( checked );
1427 MenuItemData *itemData = qFindChild<MenuItemData*>( action, QString() );
1429 itemData = new MenuItemData( action, p_obj, i_val_type, val, psz_var );
1431 /* remove previous signal-slot connection(s) if any */
1432 action->disconnect( );
1434 CONNECT( action, triggered(), THEDP->menusMapper, map() );
1435 THEDP->menusMapper->setMapping( action, itemData );
1438 menu->addAction( action );
1441 void QVLCMenu::DoAction( QObject *data )
1443 MenuItemData *itemData = qobject_cast<MenuItemData *>( data );
1444 vlc_object_t *p_object = itemData->p_obj;
1445 if( p_object == NULL ) return;
1447 /* Preserve settings across vouts via the playlist object: */
1448 if( !strcmp( itemData->psz_var, "fullscreen" )
1449 || !strcmp( itemData->psz_var, "video-on-top" ) )
1450 var_Set( pl_Get( p_object ), itemData->psz_var, itemData->val );
1452 var_Set( p_object, itemData->psz_var, itemData->val );
1455 void QVLCMenu::updateRecents( intf_thread_t *p_intf )
1460 RecentsMRL* rmrl = RecentsMRL::getInstance( p_intf );
1461 QStringList l = rmrl->recents();
1463 recentsMenu->clear();
1467 action = recentsMenu->addAction( qtr(" - Empty - ") );
1468 action->setEnabled( false );
1472 for( int i = 0; i < l.size(); ++i )
1474 action = recentsMenu->addAction(
1475 QString( "&%1: " ).arg( i + 1 ) + l.at( i ),
1476 rmrl->signalMapper, SLOT( map() ),
1477 i <= 9 ? QString( "Ctrl+%1" ).arg( i + 1 ) : "" );
1478 rmrl->signalMapper->setMapping( action, l.at( i ) );
1481 recentsMenu->addSeparator();
1482 recentsMenu->addAction( qtr("&Clear"), rmrl, SLOT( clear() ) );