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 &File..." ),
337 ":/type/file-asym", SLOT( simpleOpenDialog() ), "Ctrl+O" );
338 addDPStaticEntry( menu, qtr( I_OP_OPDIR ),
339 ":/type/folder-grey", SLOT( PLOpenDir() ), "Ctrl+F" );
340 addDPStaticEntry( menu, qtr( "Open &Disc..." ),
341 ":/type/disc", SLOT( openDiscDialog() ), "Ctrl+D" );
342 addDPStaticEntry( menu, qtr( "Open &Network Stream..." ),
343 ":/type/network", SLOT( openNetDialog() ), "Ctrl+N" );
344 addDPStaticEntry( menu, qtr( "Open &Capture Device..." ),
345 ":/type/capture-card", SLOT( openCaptureDialog() ), "Ctrl+C" );
347 menu->addSeparator();
349 addDPStaticEntry( menu, qtr( "&Open (advanced)..." ),
350 ":/type/file-asym", SLOT( openFileDialog() ), "Ctrl+Shift+O" );
351 menu->addSeparator();
353 addDPStaticEntry( menu, qtr( "Open &Location from clipboard" ),
354 NULL, SLOT( openUrlDialog() ), "Ctrl+V" );
356 if( var_InheritBool( p_intf, "qt-recentplay" ) )
358 recentsMenu = new QMenu( qtr( "Open &Recent Media" ), menu );
359 updateRecents( p_intf );
360 menu->addMenu( recentsMenu );
362 menu->addSeparator();
364 addDPStaticEntry( menu, qtr( I_PL_SAVE ), "", SLOT( saveAPlaylist() ),
366 menu->addSeparator();
369 addDPStaticEntry( menu, qtr( "Conve&rt / Save..." ), "",
370 SLOT( openAndTranscodingDialogs() ), "Ctrl+R" );
371 addDPStaticEntry( menu, qtr( "&Stream..." ),
372 ":/menu/stream", SLOT( openAndStreamingDialogs() ), "Ctrl+S" );
373 menu->addSeparator();
376 action = addMIMStaticEntry( p_intf, menu, qtr( "Quit at the end of playlist" ), "",
377 SLOT( activatePlayQuit( bool ) ) );
378 action->setCheckable( true );
379 action->setChecked( THEMIM->getPlayExitState() );
381 addDPStaticEntry( menu, qtr( "&Quit" ) ,
382 ":/menu/quit", SLOT( quit() ), "Ctrl+Q" );
387 * Tools, like Media Information, Preferences or Messages
389 QMenu *QVLCMenu::ToolsMenu( QMenu *menu )
391 addDPStaticEntry( menu, qtr( "&Effects and Filters"), ":/menu/settings",
392 SLOT( extendedDialog() ), "Ctrl+E" );
394 addDPStaticEntry( menu, qtr( "&Track Synchronization"), ":/menu/settings",
395 SLOT( synchroDialog() ), "" );
397 addDPStaticEntry( menu, qtr( I_MENU_INFO ) , ":/menu/info",
398 SLOT( mediaInfoDialog() ), "Ctrl+I" );
399 addDPStaticEntry( menu, qtr( I_MENU_CODECINFO ) ,
400 ":/menu/info", SLOT( mediaCodecDialog() ), "Ctrl+J" );
403 addDPStaticEntry( menu, qtr( I_MENU_VLM ), "", SLOT( vlmDialog() ),
407 addDPStaticEntry( menu, qtr( "Program Guide" ), "", SLOT( epgDialog() ),
410 addDPStaticEntry( menu, qtr( I_MENU_MSG ),
411 ":/menu/messages", SLOT( messagesDialog() ), "Ctrl+M" );
413 addDPStaticEntry( menu, qtr( "Plu&gins and extensions" ),
414 "", SLOT( pluginDialog() ) );
415 menu->addSeparator();
417 addDPStaticEntry( menu, qtr( "Customi&ze Interface..." ),
418 ":/menu/preferences", SLOT( toolbarDialog() ) );
420 addDPStaticEntry( menu, qtr( "&Preferences" ),
421 ":/menu/preferences", SLOT( prefsDialog() ), "Ctrl+P", QAction::PreferencesRole );
428 * Interface modification, load other interfaces, activate Extensions
430 QMenu *QVLCMenu::ViewMenu( intf_thread_t *p_intf, QMenu *current, MainInterface *_mi )
435 MainInterface *mi = _mi ? _mi : p_intf->p_sys->p_mi;
440 menu = new QMenu( qtr( "&View" ), mi );
446 //HACK menu->clear() does not delete submenus
447 QList<QAction*> actions = menu->actions();
448 foreach( QAction *a, actions )
450 QMenu *m = a->menu();
451 if( a->parent() == menu ) delete a;
452 else menu->removeAction( a );
453 if( m && m->parent() == menu ) delete m;
459 QIcon( ":/menu/playlist_menu" ),
461 qtr( "Play&list" ), mi,
462 SLOT( togglePlaylist() ), qtr( "Ctrl+L" ) );
464 menu->addSeparator();
467 action = menu->addAction( qtr( "Mi&nimal Interface" ) );
468 action->setShortcut( qtr( "Ctrl+H" ) );
469 action->setCheckable( true );
470 action->setChecked( (mi->getControlsVisibilityStatus() & CONTROLS_HIDDEN ) );
472 CONNECT( action, triggered( bool ), mi, toggleMinimalView( bool ) );
473 CONNECT( mi, minimalViewToggled( bool ), action, setChecked( bool ) );
475 /* FullScreen View */
476 action = menu->addAction( qtr( "&Fullscreen Interface" ), mi,
477 SLOT( toggleInterfaceFullScreen() ), QString( "F11" ) );
478 action->setCheckable( true );
479 action->setChecked( mi->isInterfaceFullScreen() );
480 CONNECT( mi, fullscreenInterfaceToggled( bool ),
481 action, setChecked( bool ) );
483 /* Advanced Controls */
484 action = menu->addAction( qtr( "&Advanced Controls" ), mi,
485 SLOT( toggleAdvancedButtons() ) );
486 action->setCheckable( true );
487 if( mi->getControlsVisibilityStatus() & CONTROLS_ADVANCED )
488 action->setChecked( true );
490 /* Docked Playlist */
491 action = menu->addAction( qtr( "Docked Playlist" ) );
492 action->setCheckable( true );
493 action->setChecked( mi->isPlDocked() );
494 CONNECT( action, triggered( bool ), mi, dockPlaylist( bool ) );
496 #if 0 /* For Visualisations. Not yet working */
497 adv = menu->addAction( qtr( "Visualizations selector" ), mi,
499 adv->setCheckable( true );
500 if( visual_selector_enabled ) adv->setChecked( true );
503 menu->addSeparator();
505 InterfacesMenu( p_intf, menu );
506 menu->addSeparator();
509 ExtensionsMenu( p_intf, menu );
515 * Interface Sub-Menu, to list extras interface and skins
517 QMenu *QVLCMenu::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
519 vector<vlc_object_t *> objects;
520 vector<const char *> varnames;
521 varnames.push_back( "intf-add" );
522 objects.push_back( VLC_OBJECT(p_intf) );
524 return Populate( p_intf, current, varnames, objects );
528 * Extensions menu: populate the current menu with extensions
530 void QVLCMenu::ExtensionsMenu( intf_thread_t *p_intf, QMenu *extMenu )
532 /* Get ExtensionsManager and load extensions if needed */
533 ExtensionsManager *extMgr = ExtensionsManager::getInstance( p_intf );
535 if( !var_InheritBool( p_intf, "qt-autoload-extensions")
536 && !extMgr->isLoaded() )
541 if( !extMgr->isLoaded() && !extMgr->cannotLoad() )
543 extMgr->loadExtensions();
546 /* Let the ExtensionsManager build itself the menu */
547 extMenu->addSeparator();
548 extMgr->menu( extMenu );
554 QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QMenu * current )
556 vector<vlc_object_t *> objects;
557 vector<const char *> varnames;
558 aout_instance_t *p_aout;
559 input_thread_t *p_input;
561 if( current->isEmpty() )
563 addActionWithSubmenu( current, "audio-es", qtr( "Audio &Track" ) );
564 addActionWithSubmenu( current, "audio-channels", qtr( "Audio &Channels" ) );
565 addActionWithSubmenu( current, "audio-device", qtr( "Audio &Device" ) );
566 current->addSeparator();
568 addActionWithSubmenu( current, "visual", qtr( "&Visualizations" ) );
569 current->addSeparator();
571 QAction *action = current->addAction( qtr( "Increase Volume" ),
572 ActionsManager::getInstance( p_intf ), SLOT( AudioUp() ) );
573 action->setData( STATIC_ENTRY );
574 action = current->addAction( qtr( "Decrease Volume" ),
575 ActionsManager::getInstance( p_intf ), SLOT( AudioDown() ) );
576 action->setData( STATIC_ENTRY );
577 action = current->addAction( qtr( "Mute" ),
578 ActionsManager::getInstance( p_intf ), SLOT( toggleMuteAudio() ) );
579 action->setData( STATIC_ENTRY );
582 p_input = THEMIM->getInput();
583 p_aout = THEMIM->getAout();
584 EnableStaticEntries( current, ( p_aout != NULL ) );
585 AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
588 vlc_object_release( p_aout );
591 return Populate( p_intf, current, varnames, objects );
595 QMenu *QVLCMenu::SubMenu( intf_thread_t *p_intf, QMenu *current )
598 QMenu *submenu = new QMenu( qtr( "&Subtitles Track" ), current );
599 action = current->addMenu( submenu );
600 action->setData( "spu-es" );
601 addDPStaticEntry( submenu, qtr( "Open File..." ), "",
602 SLOT( loadSubtitlesFile() ) );
603 submenu->addSeparator();
609 * Subtitles are part of Video.
611 QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current, bool b_subtitle )
613 vout_thread_t *p_vout;
614 input_thread_t *p_input;
615 vector<vlc_object_t *> objects;
616 vector<const char *> varnames;
618 if( current->isEmpty() )
620 addActionWithSubmenu( current, "video-es", qtr( "Video &Track" ) );
622 SubMenu( p_intf, current );
624 current->addSeparator();
626 addActionWithCheckbox( current, "fullscreen", qtr( "&Fullscreen" ) );
627 addActionWithCheckbox( current, "autoscale", qtr( "Always Fit &Window" ) );
628 addActionWithCheckbox( current, "video-on-top", qtr( "Always &on Top" ) );
630 addActionWithCheckbox( current, "direct3d-desktop", qtr( "Display on &Desktop" ) );
632 addAction( current, "video-snapshot", qtr( "Take &Snapshot" ) );
634 addActionWithCheckbox( current, "video-wallpaper", qtr( "Set as Wall&paper" ) );
636 current->addSeparator();
638 addActionWithSubmenu( current, "zoom", qtr( "&Zoom" ) );
639 addActionWithSubmenu( current, "aspect-ratio", qtr( "&Aspect Ratio" ) );
640 addActionWithSubmenu( current, "crop", qtr( "&Crop" ) );
641 addActionWithSubmenu( current, "deinterlace", qtr( "&Deinterlace" ) );
642 addActionWithSubmenu( current, "deinterlace-mode", qtr( "&Deinterlace mode" ) );
643 addActionWithSubmenu( current, "postprocess", qtr( "&Post processing" ) );
646 p_input = THEMIM->getInput();
648 p_vout = THEMIM->getVout();
649 VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
652 vlc_object_release( p_vout );
654 return Populate( p_intf, current, varnames, objects );
659 * For DVD, MP4, MOV and other chapter based format
661 QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *menu )
665 addActionWithSubmenu( menu, "title", qtr( "T&itle" ) );
666 addActionWithSubmenu( menu, "chapter", qtr( "&Chapter" ) );
667 addActionWithSubmenu( menu, "navigation", qtr( "&Navigation" ) );
668 addActionWithSubmenu( menu, "program", qtr( "&Program" ) );
670 /* FixMe: sync I_MENU_BOOKMARK string */
671 QMenu *submenu = new QMenu( qtr( "Custom &Bookmarks" ), menu );
672 addDPStaticEntry( submenu, qtr( "&Manage" ), "",
673 SLOT( bookmarksDialog() ), "Ctrl+B" );
674 submenu->addSeparator();
675 action = menu->addMenu( submenu );
676 action->setData( "bookmark" );
678 menu->addSeparator();
679 PopupMenuPlaylistControlEntries( menu, p_intf );
680 PopupMenuControlEntries( menu, p_intf );
682 EnableStaticEntries( menu, ( THEMIM->getInput() != NULL ) );
683 return RebuildNavigMenu( p_intf, menu );
686 QMenu *QVLCMenu::RebuildNavigMenu( intf_thread_t *p_intf, QMenu *menu )
689 input_thread_t *p_object;
690 vector<vlc_object_t *> objects;
691 vector<const char *> varnames;
693 /* Get the input and hold it */
694 p_object = THEMIM->getInput();
696 InputAutoMenuBuilder( p_object, objects, varnames );
698 menu->addSeparator();
700 /* Title and so on */
701 PUSH_VAR( "prev-title" );
702 PUSH_VAR( "next-title" );
703 PUSH_VAR( "prev-chapter" );
704 PUSH_VAR( "next-chapter" );
706 EnableStaticEntries( menu, (p_object != NULL ) );
707 return Populate( p_intf, menu, varnames, objects );
713 QMenu *QVLCMenu::HelpMenu( QWidget *parent )
715 QMenu *menu = new QMenu( parent );
716 addDPStaticEntry( menu, qtr( "&Help..." ) ,
717 ":/menu/help", SLOT( helpDialog() ), "F1" );
719 addDPStaticEntry( menu, qtr( "Check for &Updates..." ) , "",
720 SLOT( updateDialog() ) );
722 menu->addSeparator();
723 addDPStaticEntry( menu, qtr( I_MENU_ABOUT ), ":/menu/info",
724 SLOT( aboutDialog() ), "Shift+F1", QAction::AboutRole );
728 /*****************************************************************************
729 * Popup menus - Right Click menus *
730 *****************************************************************************/
731 #define POPUP_BOILERPLATE \
732 static QMenu* menu = NULL; \
733 delete menu; menu = NULL; \
736 unsigned int i_last_separator = 0; \
737 vector<vlc_object_t *> objects; \
738 vector<const char *> varnames; \
739 input_thread_t *p_input = THEMIM->getInput();
741 #define CREATE_POPUP \
742 menu = new QMenu(); \
743 Populate( p_intf, menu, varnames, objects ); \
744 menu->popup( QCursor::pos() ); \
745 i_last_separator = 0;
747 void QVLCMenu::PopupPlayEntries( QMenu *menu,
748 intf_thread_t *p_intf,
749 input_thread_t *p_input )
753 /* Play or Pause action and icon */
754 if( !p_input || var_GetInteger( p_input, "state" ) != PLAYING_S )
756 action = menu->addAction( qtr( "Play" ),
757 ActionsManager::getInstance( p_intf ), SLOT( play() ) );
758 #ifndef __APPLE__ /* No icons in menus in Mac */
759 action->setIcon( QIcon( ":/menu/play" ) );
764 addMIMStaticEntry( p_intf, menu, qtr( "Pause" ),
765 ":/menu/pause", SLOT( togglePlayPause() ) );
769 void QVLCMenu::PopupMenuControlEntries( QMenu *menu, intf_thread_t *p_intf )
774 action = menu->addAction( qtr( "&Faster" ), THEMIM->getIM(),
776 #ifndef __APPLE__ /* No icons in menus in Mac */
777 action->setIcon( QIcon( ":/toolbar/faster") );
779 action->setData( STATIC_ENTRY );
781 action = menu->addAction( qtr( "Faster (fine)" ), THEMIM->getIM(),
782 SLOT( littlefaster() ) );
783 action->setData( STATIC_ENTRY );
785 action = menu->addAction( qtr( "N&ormal Speed" ), THEMIM->getIM(),
786 SLOT( normalRate() ) );
787 action->setData( STATIC_ENTRY );
789 action = menu->addAction( qtr( "Slower (fine)" ), THEMIM->getIM(),
790 SLOT( littleslower() ) );
791 action->setData( STATIC_ENTRY );
793 action = menu->addAction( qtr( "Slo&wer" ), THEMIM->getIM(),
795 #ifndef __APPLE__ /* No icons in menus in Mac */
796 action->setIcon( QIcon( ":/toolbar/slower") );
798 action->setData( STATIC_ENTRY );
800 menu->addSeparator();
802 action = menu->addAction( qtr( "&Jump Forward" ), THEMIM->getIM(),
804 #ifndef __APPLE__ /* No icons in menus in Mac */
805 action->setIcon( QIcon( ":/toolbar/skip_fw") );
807 action->setData( STATIC_ENTRY );
809 action = menu->addAction( qtr( "Jump Bac&kward" ), THEMIM->getIM(),
811 #ifndef __APPLE__ /* No icons in menus in Mac */
812 action->setIcon( QIcon( ":/toolbar/skip_back") );
814 action->setData( STATIC_ENTRY );
815 addDPStaticEntry( menu, qtr( I_MENU_GOTOTIME ),"",
816 SLOT( gotoTimeDialog() ), "Ctrl+T" );
817 menu->addSeparator();
821 void QVLCMenu::PopupMenuPlaylistControlEntries( QMenu *menu,
822 intf_thread_t *p_intf )
824 bool bEnable = THEMIM->getInput() != NULL;
826 addMIMStaticEntry( p_intf, menu, qtr( "&Stop" ), ":/menu/stop",
827 SLOT( stop() ), true );
828 /* Disable Stop in the right-click popup menu */
830 action->setEnabled( false );
832 /* Next / Previous */
833 addMIMStaticEntry( p_intf, menu, qtr( "Pre&vious" ),
834 ":/menu/previous", SLOT( prev() ) );
835 addMIMStaticEntry( p_intf, menu, qtr( "Ne&xt" ),
836 ":/menu/next", SLOT( next() ) );
838 menu->addSeparator();
841 void QVLCMenu::PopupMenuStaticEntries( QMenu *menu )
843 QMenu *openmenu = new QMenu( qtr( "Open a Media" ), menu );
844 addDPStaticEntry( openmenu, qtr( "&Open File..." ),
845 ":/type/file-asym", SLOT( openFileDialog() ) );
846 addDPStaticEntry( openmenu, qtr( I_OP_OPDIR ),
847 ":/type/folder-grey", SLOT( PLOpenDir() ) );
848 addDPStaticEntry( openmenu, qtr( "Open &Disc..." ),
849 ":/type/disc", SLOT( openDiscDialog() ) );
850 addDPStaticEntry( openmenu, qtr( "Open &Network..." ),
851 ":/type/network", SLOT( openNetDialog() ) );
852 addDPStaticEntry( openmenu, qtr( "Open &Capture Device..." ),
853 ":/type/capture-card", SLOT( openCaptureDialog() ) );
854 menu->addMenu( openmenu );
856 menu->addSeparator();
858 QMenu *helpmenu = HelpMenu( menu );
859 helpmenu->setTitle( qtr( "Help" ) );
860 menu->addMenu( helpmenu );
863 addDPStaticEntry( menu, qtr( "Quit" ), ":/menu/quit",
864 SLOT( quit() ), "Ctrl+Q", QAction::QuitRole );
867 /* Video Tracks and Subtitles tracks */
868 void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf, bool show )
873 vout_thread_t *p_vout = THEMIM->getVout();
876 VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
877 vlc_object_release( p_vout );
884 void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf, bool show )
889 aout_instance_t *p_aout = THEMIM->getAout();
890 AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
892 vlc_object_release( p_aout );
897 /* Navigation stuff, and general menus ( open ), used only for skins */
898 void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf, bool show )
904 varnames.push_back( "audio-es" );
905 InputAutoMenuBuilder( p_input, objects, varnames );
910 Populate( p_intf, menu, varnames, objects );
912 menu->addSeparator();
913 PopupPlayEntries( menu, p_intf, p_input );
914 PopupMenuPlaylistControlEntries( menu, p_intf);
916 menu->addSeparator();
917 PopupMenuControlEntries( menu, p_intf );
919 menu->addSeparator();
920 PopupMenuStaticEntries( menu );
922 menu->popup( QCursor::pos() );
925 /* Main Menu that sticks everything together */
926 void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show )
933 bool b_isFullscreen = false;
934 MainInterface *mi = p_intf->p_sys->p_mi;
936 PopupPlayEntries( menu, p_intf, p_input );
937 PopupMenuPlaylistControlEntries( menu, p_intf );
938 menu->addSeparator();
943 vout_thread_t *p_vout = THEMIM->getVout();
945 /* Add a fullscreen switch button, since it is the most used function */
948 vlc_value_t val; var_Get( p_vout, "fullscreen", &val );
950 b_isFullscreen = !( !val.b_bool );
954 CreateAndConnect( menu, "fullscreen",
955 qtr( "Leave Fullscreen" ),"" , ITEM_NORMAL,
956 VLC_OBJECT(p_vout), val, VLC_VAR_BOOL, b_isFullscreen );
958 vlc_object_release( p_vout );
960 menu->addSeparator();
964 InputAutoMenuBuilder( p_input, objects, varnames );
967 submenu = new QMenu( menu );
968 action = menu->addMenu( AudioMenu( p_intf, submenu ) );
969 action->setText( qtr( "&Audio" ) );
970 if( action->menu()->isEmpty() )
971 action->setEnabled( false );
974 submenu = new QMenu( menu );
975 action = menu->addMenu( VideoMenu( p_intf, submenu, false ) );
976 action->setText( qtr( "&Video" ) );
977 if( action->menu()->isEmpty() )
978 action->setEnabled( false );
980 SubMenu( p_intf, menu )->setTitle( qtr( "Subti&tle") );
982 /* Playback menu for chapters */
983 submenu = new QMenu( menu );
984 action = menu->addMenu( NavigMenu( p_intf, submenu ) );
985 action->setText( qtr( "&Playback" ) );
986 if( action->menu()->isEmpty() )
987 action->setEnabled( false );
990 menu->addSeparator();
992 /* Add some special entries for windowed mode: Interface Menu */
993 if( !b_isFullscreen )
995 QMenu *submenu = new QMenu( qtr( "Tools" ), menu );
996 /*QMenu *tools =*/ ToolsMenu( submenu );
997 submenu->addSeparator();
999 /* In skins interface, append some items */
1002 submenu->setTitle( qtr( "Interface" ) );
1003 if( p_intf->p_sys->b_isDialogProvider )
1005 vlc_object_t* p_object = p_intf->p_parent;
1007 objects.clear(); varnames.clear();
1008 objects.push_back( p_object );
1009 varnames.push_back( "intf-skins" );
1010 Populate( p_intf, submenu, varnames, objects );
1012 objects.clear(); varnames.clear();
1013 objects.push_back( p_object );
1014 varnames.push_back( "intf-skins-interactive" );
1015 Populate( p_intf, submenu, varnames, objects );
1018 msg_Warn( p_intf, "could not find parent interface" );
1022 QMenu *bar = menu; // Needed for next macro
1023 BAR_DADD( ViewMenu( p_intf, _menu, mi ), qtr( "V&iew" ), 4 );
1026 menu->addMenu( submenu );
1029 /* Static entries for ending, like open */
1030 PopupMenuStaticEntries( menu );
1032 menu->popup( QCursor::pos() );
1036 #undef POPUP_BOILERPLATE
1040 /************************************************************************
1042 ************************************************************************/
1044 void QVLCMenu::updateSystrayMenu( MainInterface *mi,
1045 intf_thread_t *p_intf,
1046 bool b_force_visible )
1048 input_thread_t *p_input = THEMIM->getInput();
1050 /* Get the systray menu and clean it */
1051 QMenu *sysMenu = mi->getSysTrayMenu();
1055 /* Hide / Show VLC and cone */
1056 if( mi->isVisible() || b_force_visible )
1058 sysMenu->addAction( QIcon( ":/logo/vlc16.png" ),
1059 qtr( "Hide VLC media player in taskbar" ), mi,
1060 SLOT( hideUpdateSystrayMenu() ) );
1064 sysMenu->addAction( QIcon( ":/logo/vlc16.png" ),
1065 qtr( "Show VLC media player" ), mi,
1066 SLOT( showUpdateSystrayMenu() ) );
1068 sysMenu->addSeparator();
1071 PopupPlayEntries( sysMenu, p_intf, p_input );
1072 PopupMenuPlaylistControlEntries( sysMenu, p_intf);
1073 PopupMenuControlEntries( sysMenu, p_intf);
1075 addDPStaticEntry( sysMenu, qtr( "&Open a Media" ),
1076 ":/type/file-wide", SLOT( openFileDialog() ) );
1077 addDPStaticEntry( sysMenu, qtr( "&Quit" ) ,
1078 ":/menu/quit", SLOT( quit() ) );
1081 mi->getSysTray()->setContextMenu( sysMenu );
1087 #undef PUSH_SEPARATOR
1089 /*************************************************************************
1090 * Builders for automenus
1091 *************************************************************************/
1092 QMenu * QVLCMenu::Populate( intf_thread_t *p_intf,
1094 vector< const char *> & varnames,
1095 vector<vlc_object_t *> & objects )
1097 QMenu *menu = current;
1100 currentGroup = NULL;
1102 for( int i = 0; i < (int)objects.size() ; i++ )
1104 if( !varnames[i] || !*varnames[i] )
1106 menu->addSeparator();
1110 UpdateItem( p_intf, menu, varnames[i], objects[i], true );
1115 /*****************************************************************************
1117 *****************************************************************************/
1119 static bool IsMenuEmpty( const char *psz_var,
1120 vlc_object_t *p_object,
1121 bool b_root = true )
1123 vlc_value_t val, val_list;
1124 int i_type, i_result, i;
1126 /* Check the type of the object variable */
1127 i_type = var_Type( p_object, psz_var );
1129 /* Check if we want to display the variable */
1130 if( !( i_type & VLC_VAR_HASCHOICE ) ) return false;
1132 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
1133 if( val.i_int == 0 ) return true;
1135 if( ( i_type & VLC_VAR_TYPE ) != VLC_VAR_VARIABLE )
1137 if( val.i_int == 1 && b_root ) return true;
1141 /* Check children variables in case of VLC_VAR_VARIABLE */
1142 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
1147 for( i = 0, i_result = true; i < val_list.p_list->i_count; i++ )
1149 if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
1157 /* clean up everything */
1158 var_FreeList( &val_list, NULL );
1163 #define TEXT_OR_VAR qfu ( text.psz_string ? text.psz_string : psz_var )
1165 void QVLCMenu::UpdateItem( intf_thread_t *p_intf, QMenu *menu,
1166 const char *psz_var, vlc_object_t *p_object, bool b_submenu )
1168 vlc_value_t val, text;
1171 QAction *action = FindActionWithVar( menu, psz_var );
1173 DeleteNonStaticEntries( action->menu() );
1178 action->setEnabled( false );
1182 /* Check the type of the object variable */
1183 /* This HACK is needed so we have a radio button for audio and video tracks
1184 instread of a checkbox */
1185 if( !strcmp( psz_var, "audio-es" )
1186 || !strcmp( psz_var, "video-es" ) )
1187 i_type = VLC_VAR_INTEGER | VLC_VAR_HASCHOICE;
1189 i_type = var_Type( p_object, psz_var );
1191 switch( i_type & VLC_VAR_TYPE )
1195 case VLC_VAR_VARIABLE:
1196 case VLC_VAR_STRING:
1197 case VLC_VAR_INTEGER:
1201 /* Variable doesn't exist or isn't handled */
1203 action->setEnabled( false );
1207 /* Make sure we want to display the variable */
1208 if( menu->isEmpty() && IsMenuEmpty( psz_var, p_object ) )
1211 action->setEnabled( false );
1215 /* Get the descriptive name of the variable */
1216 int i_ret = var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
1217 if( i_ret != VLC_SUCCESS )
1219 text.psz_string = NULL;
1224 action = new QAction( TEXT_OR_VAR, menu );
1225 menu->addAction( action );
1226 action->setData( psz_var );
1229 /* Some specific stuff */
1230 bool forceDisabled = false;
1231 if( !strcmp( psz_var, "spu-es" ) )
1233 vout_thread_t *p_vout = THEMIM->getVout();
1234 forceDisabled = ( p_vout == NULL );
1236 vlc_object_release( p_vout );
1239 if( i_type & VLC_VAR_HASCHOICE )
1241 /* Append choices menu */
1245 submenu = action->menu();
1248 submenu = new QMenu( menu );
1249 action->setMenu( submenu );
1253 CreateChoicesMenu( submenu, psz_var, p_object, true ) == 0 );
1255 action->setEnabled( false );
1260 CreateChoicesMenu( menu, psz_var, p_object, true ) == 0 );
1262 FREENULL( text.psz_string );
1266 switch( i_type & VLC_VAR_TYPE )
1269 val.i_int = 0; // Prevent the copy of an uninitialized value
1270 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_NORMAL,
1271 p_object, val, i_type );
1275 var_Get( p_object, psz_var, &val );
1276 val.b_bool = !val.b_bool;
1277 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_CHECK,
1278 p_object, val, i_type, !val.b_bool );
1281 FREENULL( text.psz_string );
1286 /** HACK for the navigation submenu:
1287 * "title %2i" variables take the value 0 if not set
1289 static bool CheckTitle( vlc_object_t *p_object, const char *psz_var )
1292 if( sscanf( psz_var, "title %2i", &i_title ) <= 0 )
1295 int i_current_title = var_GetInteger( p_object, "title" );
1296 return ( i_title == i_current_title );
1300 int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
1301 vlc_object_t *p_object, bool b_root )
1303 vlc_value_t val, val_list, text_list;
1306 /* Check the type of the object variable */
1307 i_type = var_Type( p_object, psz_var );
1309 /* Make sure we want to display the variable */
1310 if( submenu->isEmpty() && IsMenuEmpty( psz_var, p_object, b_root ) )
1311 return VLC_EGENERIC;
1313 switch( i_type & VLC_VAR_TYPE )
1317 case VLC_VAR_VARIABLE:
1318 case VLC_VAR_STRING:
1319 case VLC_VAR_INTEGER:
1323 /* Variable doesn't exist or isn't handled */
1324 return VLC_EGENERIC;
1327 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
1328 &val_list, &text_list ) < 0 )
1330 return VLC_EGENERIC;
1333 #define CURVAL val_list.p_list->p_values[i]
1334 #define CURTEXT text_list.p_list->p_values[i].psz_string
1335 #define RADIO_OR_COMMAND ( i_type & VLC_VAR_ISCOMMAND ) ? ITEM_NORMAL : ITEM_RADIO
1337 for( i = 0; i < val_list.p_list->i_count; i++ )
1339 vlc_value_t another_val;
1341 QMenu *subsubmenu = new QMenu( submenu );
1343 switch( i_type & VLC_VAR_TYPE )
1345 case VLC_VAR_VARIABLE:
1346 CreateChoicesMenu( subsubmenu, CURVAL.psz_string, p_object, false );
1347 subsubmenu->setTitle( qfu( CURTEXT ? CURTEXT :CURVAL.psz_string ) );
1348 submenu->addMenu( subsubmenu );
1351 case VLC_VAR_STRING:
1352 var_Get( p_object, psz_var, &val );
1353 another_val.psz_string = strdup( CURVAL.psz_string );
1354 menutext = qfu( CURTEXT ? CURTEXT : another_val.psz_string );
1355 CreateAndConnect( submenu, psz_var, menutext, "", RADIO_OR_COMMAND,
1356 p_object, another_val, i_type,
1357 val.psz_string && !strcmp( val.psz_string, CURVAL.psz_string ) );
1359 free( val.psz_string );
1362 case VLC_VAR_INTEGER:
1363 var_Get( p_object, psz_var, &val );
1364 if( CURTEXT ) menutext = qfu( CURTEXT );
1365 else menutext.sprintf( "%"PRId64, CURVAL.i_int );
1366 CreateAndConnect( submenu, psz_var, menutext, "", RADIO_OR_COMMAND,
1367 p_object, CURVAL, i_type,
1368 ( CURVAL.i_int == val.i_int )
1369 && CheckTitle( p_object, psz_var ) );
1373 var_Get( p_object, psz_var, &val );
1374 if( CURTEXT ) menutext = qfu( CURTEXT );
1375 else menutext.sprintf( "%.2f", CURVAL.f_float );
1376 CreateAndConnect( submenu, psz_var, menutext, "", RADIO_OR_COMMAND,
1377 p_object, CURVAL, i_type,
1378 CURVAL.f_float == val.f_float );
1385 currentGroup = NULL;
1387 /* clean up everything */
1388 var_FreeList( &val_list, &text_list );
1390 #undef RADIO_OR_COMMAND
1393 return submenu->isEmpty() ? VLC_EGENERIC : VLC_SUCCESS;
1396 void QVLCMenu::CreateAndConnect( QMenu *menu, const char *psz_var,
1397 const QString& text, const QString& help,
1398 int i_item_type, vlc_object_t *p_obj,
1399 vlc_value_t val, int i_val_type,
1402 QAction *action = FindActionWithVar( menu, psz_var );
1407 action = new QAction( text, menu );
1408 menu->addAction( action );
1412 action->setToolTip( help );
1413 action->setEnabled( p_obj != NULL );
1415 if( i_item_type == ITEM_CHECK )
1417 action->setCheckable( true );
1419 else if( i_item_type == ITEM_RADIO )
1421 action->setCheckable( true );
1423 currentGroup = new QActionGroup( menu );
1424 currentGroup->addAction( action );
1427 action->setChecked( checked );
1429 MenuItemData *itemData = qFindChild<MenuItemData*>( action, QString() );
1431 itemData = new MenuItemData( action, p_obj, i_val_type, val, psz_var );
1433 /* remove previous signal-slot connection(s) if any */
1434 action->disconnect( );
1436 CONNECT( action, triggered(), THEDP->menusMapper, map() );
1437 THEDP->menusMapper->setMapping( action, itemData );
1440 menu->addAction( action );
1443 void QVLCMenu::DoAction( QObject *data )
1445 MenuItemData *itemData = qobject_cast<MenuItemData *>( data );
1446 vlc_object_t *p_object = itemData->p_obj;
1447 if( p_object == NULL ) return;
1449 /* Preserve settings across vouts via the playlist object: */
1450 if( !strcmp( itemData->psz_var, "fullscreen" )
1451 || !strcmp( itemData->psz_var, "video-on-top" ) )
1452 var_Set( pl_Get( p_object ), itemData->psz_var, itemData->val );
1454 var_Set( p_object, itemData->psz_var, itemData->val );
1457 void QVLCMenu::updateRecents( intf_thread_t *p_intf )
1462 RecentsMRL* rmrl = RecentsMRL::getInstance( p_intf );
1463 QStringList l = rmrl->recents();
1465 recentsMenu->clear();
1469 action = recentsMenu->addAction( qtr(" - Empty - ") );
1470 action->setEnabled( false );
1474 for( int i = 0; i < l.size(); ++i )
1476 action = recentsMenu->addAction(
1477 QString( "&%1: " ).arg( i + 1 ) + l.at( i ),
1478 rmrl->signalMapper, SLOT( map() ),
1479 i <= 9 ? QString( "Ctrl+%1" ).arg( i + 1 ) : "" );
1480 rmrl->signalMapper->setMapping( action, l.at( i ) );
1483 recentsMenu->addSeparator();
1484 recentsMenu->addAction( qtr("&Clear"), rmrl, SLOT( clear() ) );