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 void 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 );
118 * @brief Add static entries to MIM in menus
120 QAction* addMIMStaticEntry( intf_thread_t *p_intf,
125 bool bStatic = false )
128 #ifndef __APPLE__ /* We don't set icons in menus in MacOS X */
129 if( !EMPTY_STR( icon ) )
131 action = menu->addAction( text, THEMIM, member );
132 action->setIcon( QIcon( icon ) );
137 action = menu->addAction( text, THEMIM, member );
139 action->setData( bStatic ? STATIC_ENTRY : ENTRY_ALWAYS_ENABLED );
144 * @brief Enable all static entries of a menu, disable the others
145 * @param menu the menu in which the entries will be disabled
146 * @param enable if false, disable all entries
148 void EnableStaticEntries( QMenu *menu, bool enable = true )
152 QList< QAction* > actions = menu->actions();
153 for( int i = 0; i < actions.size(); ++i )
155 actions[i]->setEnabled( actions[i]->data().toString()
156 == ENTRY_ALWAYS_ENABLED ||
157 /* Be careful here, because data("string").toBool is true */
158 ( enable && (actions[i]->data().toString() == STATIC_ENTRY ) ) );
163 * \return Number of static entries
165 inline int DeleteNonStaticEntries( QMenu *menu )
167 if( !menu ) return VLC_EGENERIC;
171 QList< QAction* > actions = menu->actions();
172 for( int i = 0; i < actions.size(); ++i )
174 if( actions[i]->data().toString() != STATIC_ENTRY )
183 * \return QAction associated to psz_var variable
185 static QAction * FindActionWithVar( QMenu *menu, const char *psz_var )
187 QList< QAction* > actions = menu->actions();
188 for( int i = 0; i < actions.size(); ++i )
190 if( actions[i]->data().toString() == psz_var )
196 /*****************************************************************************
197 * Definitions of variables for the dynamic menus
198 *****************************************************************************/
199 #define PUSH_VAR( var ) varnames.push_back( var ); \
200 objects.push_back( VLC_OBJECT(p_object) )
202 #define PUSH_INPUTVAR( var ) varnames.push_back( var ); \
203 objects.push_back( VLC_OBJECT(p_input) );
205 #define PUSH_SEPARATOR if( objects.size() != i_last_separator ) { \
206 objects.push_back( 0 ); varnames.push_back( "" ); \
207 i_last_separator = objects.size(); }
209 static int InputAutoMenuBuilder( input_thread_t *p_object,
210 vector<vlc_object_t *> &objects,
211 vector<const char *> &varnames )
213 PUSH_VAR( "bookmark" );
215 PUSH_VAR( "chapter" );
216 PUSH_VAR( "navigation" );
217 PUSH_VAR( "program" );
221 static int VideoAutoMenuBuilder( vout_thread_t *p_object,
222 input_thread_t *p_input,
223 vector<vlc_object_t *> &objects,
224 vector<const char *> &varnames )
226 PUSH_INPUTVAR( "video-es" );
227 PUSH_INPUTVAR( "spu-es" );
228 PUSH_VAR( "fullscreen" );
229 PUSH_VAR( "video-on-top" );
230 PUSH_VAR( "video-wallpaper" );
232 PUSH_VAR( "direct3d-desktop" );
234 PUSH_VAR( "video-snapshot" );
236 PUSH_VAR( "autoscale" );
237 PUSH_VAR( "aspect-ratio" );
239 PUSH_VAR( "deinterlace" );
240 PUSH_VAR( "deinterlace-mode" );
241 PUSH_VAR( "postprocess" );
246 static int AudioAutoMenuBuilder( aout_instance_t *p_object,
247 input_thread_t *p_input,
248 vector<vlc_object_t *> &objects,
249 vector<const char *> &varnames )
251 PUSH_INPUTVAR( "audio-es" );
252 PUSH_VAR( "audio-channels" );
253 PUSH_VAR( "audio-device" );
254 PUSH_VAR( "visual" );
258 /*****************************************************************************
261 *****************************************************************************/
264 static inline void addMenuToMainbar( QMenu *func, QString title, QMenuBar *bar ) {
265 func->setTitle( title );
270 #define BAR_DADD( func, title, id ) { \
271 QMenu *_menu = func; _menu->setTitle( title ); bar->addMenu( _menu ); \
272 MenuFunc *f = new MenuFunc( _menu, id ); \
273 CONNECT( _menu, aboutToShow(), THEDP->menusUpdateMapper, map() ); \
274 THEDP->menusUpdateMapper->setMapping( _menu, f ); }
276 // Add a simple action
277 static inline void addAction( QMenu *_menu, QVariant val, QString title ) {
278 QAction *_action = new QAction( title, _menu );
279 _action->setData( val );
280 _menu->addAction( _action );
283 // Add an action with a submenu
284 static inline void addActionWithSubmenu( QMenu *_menu, QVariant val, QString title ) {
285 QAction *_action = new QAction( title, _menu );
286 _action->setData( val );
287 _action->setMenu( new QMenu( _menu ) );
288 _menu->addAction( _action );
291 // Add an action that is a checkbox
292 static inline void addActionWithCheckbox( QMenu *_menu, QVariant val, QString title ) {
293 QAction *_action = new QAction( title, _menu );
294 _action->setData( val );
295 _action->setCheckable( true );
296 _menu->addAction( _action );
300 * Main Menu Bar Creation
302 void QVLCMenu::createMenuBar( MainInterface *mi,
303 intf_thread_t *p_intf )
305 /* QMainWindows->menuBar()
306 gives the QProcess::destroyed timeout issue on Cleanlooks style with
307 setDesktopAware set to false */
308 QMenuBar *bar = mi->menuBar();
310 addMenuToMainbar( FileMenu( p_intf, bar ), qtr( "&Media" ), bar );
312 /* Dynamic menus, rebuilt before being showed */
313 BAR_DADD( NavigMenu( p_intf, bar ), qtr( "P&layback" ), 3 );
314 BAR_DADD( AudioMenu( p_intf, bar ), qtr( "&Audio" ), 1 );
315 BAR_DADD( VideoMenu( p_intf, bar ), qtr( "&Video" ), 2 );
317 addMenuToMainbar( ToolsMenu( bar ), qtr( "&Tools" ), bar );
319 /* View menu, a bit different */
320 BAR_DADD( ViewMenu( p_intf, _menu, mi ), qtr( "V&iew" ), 4 );
322 addMenuToMainbar( HelpMenu( bar ), qtr( "&Help" ), bar );
327 * Media ( File ) Menu
328 * Opening, streaming and quit
330 QMenu *QVLCMenu::FileMenu( intf_thread_t *p_intf, QWidget *parent )
332 QMenu *menu = new QMenu( parent );
334 addDPStaticEntry( menu, qtr( "&Open File..." ),
335 ":/type/file-asym", SLOT( simpleOpenDialog() ), "Ctrl+O" );
336 addDPStaticEntry( menu, qtr( "Advanced Open File..." ),
337 ":/type/file-asym", SLOT( openFileDialog() ), "Ctrl+Shift+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();
348 addDPStaticEntry( menu, qtr( "Open &Location from clipboard" ),
349 NULL, SLOT( openUrlDialog() ), "Ctrl+V" );
351 if( var_InheritBool( p_intf, "qt-recentplay" ) )
353 recentsMenu = new QMenu( qtr( "&Recent Media" ), menu );
354 updateRecents( p_intf );
355 menu->addMenu( recentsMenu );
357 menu->addSeparator();
359 addDPStaticEntry( menu, qtr( I_PL_SAVE ), "", SLOT( saveAPlaylist() ),
361 menu->addSeparator();
364 addDPStaticEntry( menu, qtr( "Conve&rt / Save..." ), "",
365 SLOT( openAndTranscodingDialogs() ), "Ctrl+R" );
366 addDPStaticEntry( menu, qtr( "&Streaming..." ),
367 ":/menu/stream", SLOT( openAndStreamingDialogs() ), "Ctrl+S" );
368 menu->addSeparator();
371 addDPStaticEntry( menu, qtr( "&Quit" ) ,
372 ":/menu/quit", SLOT( quit() ), "Ctrl+Q" );
377 * Tools, like Media Information, Preferences or Messages
379 QMenu *QVLCMenu::ToolsMenu( QMenu *menu )
381 addDPStaticEntry( menu, qtr( "&Effects and Filters"), ":/menu/settings",
382 SLOT( extendedDialog() ), "Ctrl+E" );
384 addDPStaticEntry( menu, qtr( "&Track Synchronization"), ":/menu/settings",
385 SLOT( synchroDialog() ), "" );
387 addDPStaticEntry( menu, qtr( I_MENU_INFO ) , ":/menu/info",
388 SLOT( mediaInfoDialog() ), "Ctrl+I" );
389 addDPStaticEntry( menu, qtr( I_MENU_CODECINFO ) ,
390 ":/menu/info", SLOT( mediaCodecDialog() ), "Ctrl+J" );
393 addDPStaticEntry( menu, qtr( I_MENU_VLM ), "", SLOT( vlmDialog() ),
397 addDPStaticEntry( menu, qtr( "Program Guide" ), "", SLOT( epgDialog() ),
400 addDPStaticEntry( menu, qtr( I_MENU_MSG ),
401 ":/menu/messages", SLOT( messagesDialog() ), "Ctrl+M" );
403 addDPStaticEntry( menu, qtr( "Plu&gins and extensions" ),
404 "", SLOT( pluginDialog() ) );
405 menu->addSeparator();
407 addDPStaticEntry( menu, qtr( "Customi&ze Interface..." ),
408 ":/menu/preferences", SLOT( toolbarDialog() ) );
410 addDPStaticEntry( menu, qtr( "&Preferences" ),
411 ":/menu/preferences", SLOT( prefsDialog() ), "Ctrl+P", QAction::PreferencesRole );
418 * Interface modification, load other interfaces, activate Extensions
420 QMenu *QVLCMenu::ViewMenu( intf_thread_t *p_intf, QMenu *current, MainInterface *_mi )
425 MainInterface *mi = _mi ? _mi : p_intf->p_sys->p_mi;
430 menu = new QMenu( qtr( "&View" ), mi );
436 //HACK menu->clear() does not delete submenus
437 QList<QAction*> actions = menu->actions();
438 foreach( QAction *a, actions )
440 QMenu *m = a->menu();
441 if( a->parent() == menu ) delete a;
442 else menu->removeAction( a );
443 if( m && m->parent() == menu ) delete m;
449 QIcon( ":/menu/playlist_menu" ),
451 qtr( "Play&list" ), mi,
452 SLOT( togglePlaylist() ), qtr( "Ctrl+L" ) );
454 menu->addSeparator();
456 InterfacesMenu( p_intf, menu );
457 menu->addSeparator();
460 action = menu->addAction( qtr( "Mi&nimal View" ) );
461 action->setShortcut( qtr( "Ctrl+H" ) );
462 action->setCheckable( true );
463 action->setChecked( (mi->getControlsVisibilityStatus() & CONTROLS_HIDDEN ) );
465 CONNECT( action, triggered( bool ), mi, toggleMinimalView( bool ) );
466 CONNECT( mi, minimalViewToggled( bool ), action, setChecked( bool ) );
468 /* FullScreen View */
469 action = menu->addAction( qtr( "&Fullscreen Interface" ), mi,
470 SLOT( toggleInterfaceFullScreen() ), QString( "F11" ) );
471 action->setCheckable( true );
472 action->setChecked( mi->isInterfaceFullScreen() );
473 CONNECT( mi, fullscreenInterfaceToggled( bool ),
474 action, setChecked( bool ) );
476 /* Advanced Controls */
477 action = menu->addAction( qtr( "&Advanced Controls" ), mi,
478 SLOT( toggleAdvancedButtons() ) );
479 action->setCheckable( true );
480 if( mi->getControlsVisibilityStatus() & CONTROLS_ADVANCED )
481 action->setChecked( true );
483 /* Docked Playlist */
484 action = menu->addAction( qtr( "Docked Playlist" ) );
485 action->setCheckable( true );
486 action->setChecked( mi->isPlDocked() );
487 CONNECT( action, triggered( bool ), mi, dockPlaylist( bool ) );
489 #if 0 /* For Visualisations. Not yet working */
490 adv = menu->addAction( qtr( "Visualizations selector" ), mi,
492 adv->setCheckable( true );
493 if( visual_selector_enabled ) adv->setChecked( true );
496 menu->addSeparator();
498 ExtensionsMenu( p_intf, menu );
504 * Interface Sub-Menu, to list extras interface and skins
506 QMenu *QVLCMenu::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
508 vector<vlc_object_t *> objects;
509 vector<const char *> varnames;
510 varnames.push_back( "intf-add" );
511 objects.push_back( VLC_OBJECT(p_intf) );
513 return Populate( p_intf, current, varnames, objects );
517 * Extensions menu: populate the current menu with extensions
519 void QVLCMenu::ExtensionsMenu( intf_thread_t *p_intf, QMenu *extMenu )
521 /* Get ExtensionsManager and load extensions if needed */
522 ExtensionsManager *extMgr = ExtensionsManager::getInstance( p_intf );
524 if( !var_InheritBool( p_intf, "qt-autoload-extensions")
525 && !extMgr->isLoaded() )
530 if( !extMgr->isLoaded() && !extMgr->cannotLoad() )
532 extMgr->loadExtensions();
535 /* Let the ExtensionsManager build itself the menu */
536 extMenu->addSeparator();
537 extMgr->menu( extMenu );
543 QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QMenu * current )
545 vector<vlc_object_t *> objects;
546 vector<const char *> varnames;
547 aout_instance_t *p_aout;
548 input_thread_t *p_input;
550 if( current->isEmpty() )
552 addActionWithSubmenu( current, "audio-es", qtr( "Audio &Track" ) );
553 addActionWithSubmenu( current, "audio-channels", qtr( "Audio &Channels" ) );
554 addActionWithSubmenu( current, "audio-device", qtr( "Audio &Device" ) );
555 current->addSeparator();
557 addActionWithSubmenu( current, "visual", qtr( "&Visualizations" ) );
558 current->addSeparator();
560 QAction *action = current->addAction( qtr( "Increase Volume" ),
561 ActionsManager::getInstance( p_intf ), SLOT( AudioUp() ) );
562 action->setData( STATIC_ENTRY );
563 action = current->addAction( qtr( "Decrease Volume" ),
564 ActionsManager::getInstance( p_intf ), SLOT( AudioDown() ) );
565 action->setData( STATIC_ENTRY );
566 action = current->addAction( qtr( "Mute" ),
567 ActionsManager::getInstance( p_intf ), SLOT( toggleMuteAudio() ) );
568 action->setData( STATIC_ENTRY );
571 p_input = THEMIM->getInput();
572 p_aout = THEMIM->getAout();
573 EnableStaticEntries( current, ( p_aout != NULL ) );
574 AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
577 vlc_object_release( p_aout );
580 return Populate( p_intf, current, varnames, objects );
585 * Subtitles are part of Video.
587 QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current )
589 vout_thread_t *p_vout;
590 input_thread_t *p_input;
591 vector<vlc_object_t *> objects;
592 vector<const char *> varnames;
594 if( current->isEmpty() )
596 addActionWithSubmenu( current, "video-es", qtr( "Video &Track" ) );
599 QMenu *submenu = new QMenu( qtr( "&Subtitles Track" ), current );
600 action = current->addMenu( submenu );
601 action->setData( "spu-es" );
602 addDPStaticEntry( submenu, qtr( "Open File..." ), "",
603 SLOT( loadSubtitlesFile() ) );
604 submenu->addSeparator();
605 current->addSeparator();
607 addActionWithCheckbox( current, "fullscreen", qtr( "&Fullscreen" ) );
608 addActionWithCheckbox( current, "autoscale", qtr( "Always Fit &Window" ) );
609 addActionWithCheckbox( current, "video-on-top", qtr( "Always &on Top" ) );
611 addActionWithCheckbox( current, "direct3d-desktop", qtr( "Display on &Desktop" ) );
613 addAction( current, "video-snapshot", qtr( "Take &Snapshot" ) );
615 addActionWithCheckbox( current, "video-wallpaper", qtr( "Set as Wall&paper" ) );
617 current->addSeparator();
619 addActionWithSubmenu( current, "zoom", qtr( "&Zoom" ) );
620 addActionWithSubmenu( current, "aspect-ratio", qtr( "&Aspect Ratio" ) );
621 addActionWithSubmenu( current, "crop", qtr( "&Crop" ) );
622 addActionWithSubmenu( current, "deinterlace", qtr( "&Deinterlace" ) );
623 addActionWithSubmenu( current, "deinterlace-mode", qtr( "&Deinterlace mode" ) );
624 addActionWithSubmenu( current, "postprocess", qtr( "&Post processing" ) );
627 p_input = THEMIM->getInput();
629 p_vout = THEMIM->getVout();
630 VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
633 vlc_object_release( p_vout );
635 return Populate( p_intf, current, varnames, objects );
640 * For DVD, MP4, MOV and other chapter based format
642 QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *menu )
646 addActionWithSubmenu( menu, "title", qtr( "T&itle" ) );
647 addActionWithSubmenu( menu, "chapter", qtr( "&Chapter" ) );
648 addActionWithSubmenu( menu, "navigation", qtr( "&Navigation" ) );
649 addActionWithSubmenu( menu, "program", qtr( "&Program" ) );
651 /* FixMe: sync I_MENU_BOOKMARK string */
652 QMenu *submenu = new QMenu( qtr( "Custom &Bookmarks" ), menu );
653 addDPStaticEntry( submenu, qtr( "&Manage" ), "",
654 SLOT( bookmarksDialog() ), "Ctrl+B" );
655 submenu->addSeparator();
656 action = menu->addMenu( submenu );
657 action->setData( "bookmark" );
659 menu->addSeparator();
660 PopupMenuPlaylistControlEntries( menu, p_intf );
661 PopupMenuControlEntries( menu, p_intf );
663 EnableStaticEntries( menu, ( THEMIM->getInput() != NULL ) );
664 return RebuildNavigMenu( p_intf, menu );
667 QMenu *QVLCMenu::RebuildNavigMenu( intf_thread_t *p_intf, QMenu *menu )
670 input_thread_t *p_object;
671 vector<vlc_object_t *> objects;
672 vector<const char *> varnames;
674 /* Get the input and hold it */
675 p_object = THEMIM->getInput();
677 InputAutoMenuBuilder( p_object, objects, varnames );
679 menu->addSeparator();
681 /* Title and so on */
682 PUSH_VAR( "prev-title" );
683 PUSH_VAR( "next-title" );
684 PUSH_VAR( "prev-chapter" );
685 PUSH_VAR( "next-chapter" );
687 EnableStaticEntries( menu, (p_object != NULL ) );
688 return Populate( p_intf, menu, varnames, objects );
694 QMenu *QVLCMenu::HelpMenu( QWidget *parent )
696 QMenu *menu = new QMenu( parent );
697 addDPStaticEntry( menu, qtr( "&Help..." ) ,
698 ":/menu/help", SLOT( helpDialog() ), "F1" );
700 addDPStaticEntry( menu, qtr( "Check for &Updates..." ) , "",
701 SLOT( updateDialog() ) );
703 menu->addSeparator();
704 addDPStaticEntry( menu, qtr( I_MENU_ABOUT ), ":/menu/info",
705 SLOT( aboutDialog() ), "Shift+F1", QAction::AboutRole );
709 /*****************************************************************************
710 * Popup menus - Right Click menus *
711 *****************************************************************************/
712 #define POPUP_BOILERPLATE \
713 static QMenu* menu = NULL; \
714 delete menu; menu = NULL; \
717 unsigned int i_last_separator = 0; \
718 vector<vlc_object_t *> objects; \
719 vector<const char *> varnames; \
720 input_thread_t *p_input = THEMIM->getInput();
722 #define CREATE_POPUP \
723 menu = new QMenu(); \
724 Populate( p_intf, menu, varnames, objects ); \
725 menu->popup( QCursor::pos() ); \
726 i_last_separator = 0;
728 void QVLCMenu::PopupPlayEntries( QMenu *menu,
729 intf_thread_t *p_intf,
730 input_thread_t *p_input )
734 /* Play or Pause action and icon */
735 if( !p_input || var_GetInteger( p_input, "state" ) != PLAYING_S )
737 action = menu->addAction( qtr( "Play" ),
738 ActionsManager::getInstance( p_intf ), SLOT( play() ) );
739 #ifndef __APPLE__ /* No icons in menus in Mac */
740 action->setIcon( QIcon( ":/menu/play" ) );
745 addMIMStaticEntry( p_intf, menu, qtr( "Pause" ),
746 ":/menu/pause", SLOT( togglePlayPause() ) );
750 void QVLCMenu::PopupMenuControlEntries( QMenu *menu, intf_thread_t *p_intf )
755 action = menu->addAction( qtr( "&Faster" ), THEMIM->getIM(),
757 #ifndef __APPLE__ /* No icons in menus in Mac */
758 action->setIcon( QIcon( ":/toolbar/faster") );
760 action->setData( STATIC_ENTRY );
762 action = menu->addAction( qtr( "Faster (fine)" ), THEMIM->getIM(),
763 SLOT( littlefaster() ) );
764 action->setData( STATIC_ENTRY );
766 action = menu->addAction( qtr( "N&ormal Speed" ), THEMIM->getIM(),
767 SLOT( normalRate() ) );
768 action->setData( STATIC_ENTRY );
770 action = menu->addAction( qtr( "Slower (fine)" ), THEMIM->getIM(),
771 SLOT( littleslower() ) );
772 action->setData( STATIC_ENTRY );
774 action = menu->addAction( qtr( "Slo&wer" ), THEMIM->getIM(),
776 #ifndef __APPLE__ /* No icons in menus in Mac */
777 action->setIcon( QIcon( ":/toolbar/slower") );
779 action->setData( STATIC_ENTRY );
781 menu->addSeparator();
783 action = menu->addAction( qtr( "&Jump Forward" ), THEMIM->getIM(),
785 #ifndef __APPLE__ /* No icons in menus in Mac */
786 action->setIcon( QIcon( ":/toolbar/skip_fw") );
788 action->setData( STATIC_ENTRY );
790 action = menu->addAction( qtr( "Jump Bac&kward" ), THEMIM->getIM(),
792 #ifndef __APPLE__ /* No icons in menus in Mac */
793 action->setIcon( QIcon( ":/toolbar/skip_back") );
795 action->setData( STATIC_ENTRY );
796 addDPStaticEntry( menu, qtr( I_MENU_GOTOTIME ),"",
797 SLOT( gotoTimeDialog() ), "Ctrl+T" );
798 menu->addSeparator();
802 void QVLCMenu::PopupMenuPlaylistControlEntries( QMenu *menu,
803 intf_thread_t *p_intf )
805 bool bEnable = THEMIM->getInput() != NULL;
807 addMIMStaticEntry( p_intf, menu, qtr( "&Stop" ), ":/menu/stop",
808 SLOT( stop() ), true );
809 /* Disable Stop in the right-click popup menu */
811 action->setEnabled( false );
813 /* Next / Previous */
814 addMIMStaticEntry( p_intf, menu, qtr( "Pre&vious" ),
815 ":/menu/previous", SLOT( prev() ) );
816 addMIMStaticEntry( p_intf, menu, qtr( "Ne&xt" ),
817 ":/menu/next", SLOT( next() ) );
819 action = addMIMStaticEntry( p_intf, menu, qtr( "Quit after Playback" ), "",
820 SLOT( activatePlayQuit( bool ) ) );
821 action->setCheckable( true );
822 action->setChecked( THEMIM->getPlayExitState() );
824 menu->addSeparator();
827 void QVLCMenu::PopupMenuStaticEntries( QMenu *menu )
829 QMenu *openmenu = new QMenu( qtr( "Open Media" ), menu );
830 addDPStaticEntry( openmenu, qtr( "&Open File..." ),
831 ":/type/file-asym", SLOT( openFileDialog() ) );
832 addDPStaticEntry( openmenu, qtr( I_OP_OPDIR ),
833 ":/type/folder-grey", SLOT( PLOpenDir() ) );
834 addDPStaticEntry( openmenu, qtr( "Open &Disc..." ),
835 ":/type/disc", SLOT( openDiscDialog() ) );
836 addDPStaticEntry( openmenu, qtr( "Open &Network..." ),
837 ":/type/network", SLOT( openNetDialog() ) );
838 addDPStaticEntry( openmenu, qtr( "Open &Capture Device..." ),
839 ":/type/capture-card", SLOT( openCaptureDialog() ) );
840 menu->addMenu( openmenu );
842 menu->addSeparator();
844 QMenu *helpmenu = HelpMenu( menu );
845 helpmenu->setTitle( qtr( "Help" ) );
846 menu->addMenu( helpmenu );
849 addDPStaticEntry( menu, qtr( "Quit" ), ":/menu/quit",
850 SLOT( quit() ), "Ctrl+Q", QAction::QuitRole );
853 /* Video Tracks and Subtitles tracks */
854 void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf, bool show )
859 vout_thread_t *p_vout = THEMIM->getVout();
862 VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
863 vlc_object_release( p_vout );
870 void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf, bool show )
875 aout_instance_t *p_aout = THEMIM->getAout();
876 AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
878 vlc_object_release( p_aout );
883 /* Navigation stuff, and general menus ( open ), used only for skins */
884 void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf, bool show )
890 varnames.push_back( "audio-es" );
891 InputAutoMenuBuilder( p_input, objects, varnames );
896 Populate( p_intf, menu, varnames, objects );
898 menu->addSeparator();
899 PopupPlayEntries( menu, p_intf, p_input );
900 PopupMenuPlaylistControlEntries( menu, p_intf);
902 menu->addSeparator();
903 PopupMenuControlEntries( menu, p_intf );
905 menu->addSeparator();
906 PopupMenuStaticEntries( menu );
908 menu->popup( QCursor::pos() );
911 /* Main Menu that sticks everything together */
912 void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show )
919 bool b_isFullscreen = false;
920 MainInterface *mi = p_intf->p_sys->p_mi;
922 PopupPlayEntries( menu, p_intf, p_input );
923 PopupMenuPlaylistControlEntries( menu, p_intf );
924 menu->addSeparator();
929 vout_thread_t *p_vout = THEMIM->getVout();
931 /* Add a fullscreen switch button, since it is the most used function */
934 vlc_value_t val; var_Get( p_vout, "fullscreen", &val );
936 b_isFullscreen = !( !val.b_bool );
940 CreateAndConnect( menu, "fullscreen",
941 qtr( "Leave Fullscreen" ),"" , ITEM_NORMAL,
942 VLC_OBJECT(p_vout), val, VLC_VAR_BOOL, b_isFullscreen );
944 vlc_object_release( p_vout );
946 menu->addSeparator();
950 InputAutoMenuBuilder( p_input, objects, varnames );
953 submenu = new QMenu( menu );
954 action = menu->addMenu( AudioMenu( p_intf, submenu ) );
955 action->setText( qtr( "&Audio" ) );
956 if( action->menu()->isEmpty() )
957 action->setEnabled( false );
960 submenu = new QMenu( menu );
961 action = menu->addMenu( VideoMenu( p_intf, submenu ) );
962 action->setText( qtr( "&Video" ) );
963 if( action->menu()->isEmpty() )
964 action->setEnabled( false );
966 /* Playback menu for chapters */
967 submenu = new QMenu( menu );
968 action = menu->addMenu( NavigMenu( p_intf, submenu ) );
969 action->setText( qtr( "&Playback" ) );
970 if( action->menu()->isEmpty() )
971 action->setEnabled( false );
974 menu->addSeparator();
976 /* Add some special entries for windowed mode: Interface Menu */
977 if( !b_isFullscreen )
979 QMenu *submenu = new QMenu( qtr( "Tools" ), menu );
980 /*QMenu *tools =*/ ToolsMenu( submenu );
981 submenu->addSeparator();
983 /* In skins interface, append some items */
986 submenu->setTitle( qtr( "Interface" ) );
987 if( p_intf->p_sys->b_isDialogProvider )
989 vlc_object_t* p_object = p_intf->p_parent;
991 objects.clear(); varnames.clear();
992 objects.push_back( p_object );
993 varnames.push_back( "intf-skins" );
994 Populate( p_intf, submenu, varnames, objects );
996 objects.clear(); varnames.clear();
997 objects.push_back( p_object );
998 varnames.push_back( "intf-skins-interactive" );
999 Populate( p_intf, submenu, varnames, objects );
1002 msg_Warn( p_intf, "could not find parent interface" );
1006 QMenu *bar = menu; // Needed for next macro
1007 BAR_DADD( ViewMenu( p_intf, _menu, mi ), qtr( "V&iew" ), 4 );
1010 menu->addMenu( submenu );
1013 /* Static entries for ending, like open */
1014 PopupMenuStaticEntries( menu );
1016 menu->popup( QCursor::pos() );
1020 #undef POPUP_BOILERPLATE
1024 /************************************************************************
1026 ************************************************************************/
1028 void QVLCMenu::updateSystrayMenu( MainInterface *mi,
1029 intf_thread_t *p_intf,
1030 bool b_force_visible )
1032 input_thread_t *p_input = THEMIM->getInput();
1034 /* Get the systray menu and clean it */
1035 QMenu *sysMenu = mi->getSysTrayMenu();
1039 /* Hide / Show VLC and cone */
1040 if( mi->isVisible() || b_force_visible )
1042 sysMenu->addAction( QIcon( ":/logo/vlc16.png" ),
1043 qtr( "Hide VLC media player in taskbar" ), mi,
1044 SLOT( hideUpdateSystrayMenu() ) );
1048 sysMenu->addAction( QIcon( ":/logo/vlc16.png" ),
1049 qtr( "Show VLC media player" ), mi,
1050 SLOT( showUpdateSystrayMenu() ) );
1052 sysMenu->addSeparator();
1055 PopupPlayEntries( sysMenu, p_intf, p_input );
1056 PopupMenuPlaylistControlEntries( sysMenu, p_intf);
1057 PopupMenuControlEntries( sysMenu, p_intf);
1059 addDPStaticEntry( sysMenu, qtr( "&Open Media" ),
1060 ":/type/file-wide", SLOT( openFileDialog() ) );
1061 addDPStaticEntry( sysMenu, qtr( "&Quit" ) ,
1062 ":/menu/quit", SLOT( quit() ) );
1065 mi->getSysTray()->setContextMenu( sysMenu );
1071 #undef PUSH_SEPARATOR
1073 /*************************************************************************
1074 * Builders for automenus
1075 *************************************************************************/
1076 QMenu * QVLCMenu::Populate( intf_thread_t *p_intf,
1078 vector< const char *> & varnames,
1079 vector<vlc_object_t *> & objects )
1081 QMenu *menu = current;
1084 currentGroup = NULL;
1086 for( int i = 0; i < (int)objects.size() ; i++ )
1088 if( !varnames[i] || !*varnames[i] )
1090 menu->addSeparator();
1094 UpdateItem( p_intf, menu, varnames[i], objects[i], true );
1099 /*****************************************************************************
1101 *****************************************************************************/
1103 static bool IsMenuEmpty( const char *psz_var,
1104 vlc_object_t *p_object,
1105 bool b_root = true )
1107 vlc_value_t val, val_list;
1108 int i_type, i_result, i;
1110 /* Check the type of the object variable */
1111 i_type = var_Type( p_object, psz_var );
1113 /* Check if we want to display the variable */
1114 if( !( i_type & VLC_VAR_HASCHOICE ) ) return false;
1116 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
1117 if( val.i_int == 0 ) return true;
1119 if( ( i_type & VLC_VAR_TYPE ) != VLC_VAR_VARIABLE )
1121 if( val.i_int == 1 && b_root ) return true;
1125 /* Check children variables in case of VLC_VAR_VARIABLE */
1126 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
1131 for( i = 0, i_result = true; i < val_list.p_list->i_count; i++ )
1133 if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
1141 /* clean up everything */
1142 var_FreeList( &val_list, NULL );
1147 #define TEXT_OR_VAR qfu ( text.psz_string ? text.psz_string : psz_var )
1149 void QVLCMenu::UpdateItem( intf_thread_t *p_intf, QMenu *menu,
1150 const char *psz_var, vlc_object_t *p_object, bool b_submenu )
1152 vlc_value_t val, text;
1155 QAction *action = FindActionWithVar( menu, psz_var );
1157 DeleteNonStaticEntries( action->menu() );
1162 action->setEnabled( false );
1166 /* Check the type of the object variable */
1167 /* This HACK is needed so we have a radio button for audio and video tracks
1168 instread of a checkbox */
1169 if( !strcmp( psz_var, "audio-es" )
1170 || !strcmp( psz_var, "video-es" ) )
1171 i_type = VLC_VAR_INTEGER | VLC_VAR_HASCHOICE;
1173 i_type = var_Type( p_object, psz_var );
1175 switch( i_type & VLC_VAR_TYPE )
1179 case VLC_VAR_VARIABLE:
1180 case VLC_VAR_STRING:
1181 case VLC_VAR_INTEGER:
1185 /* Variable doesn't exist or isn't handled */
1187 action->setEnabled( false );
1191 /* Make sure we want to display the variable */
1192 if( menu->isEmpty() && IsMenuEmpty( psz_var, p_object ) )
1195 action->setEnabled( false );
1199 /* Get the descriptive name of the variable */
1200 int i_ret = var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
1201 if( i_ret != VLC_SUCCESS )
1203 text.psz_string = NULL;
1208 action = new QAction( TEXT_OR_VAR, menu );
1209 menu->addAction( action );
1210 action->setData( psz_var );
1213 /* Some specific stuff */
1214 bool forceDisabled = false;
1215 if( !strcmp( psz_var, "spu-es" ) )
1217 vout_thread_t *p_vout = THEMIM->getVout();
1218 forceDisabled = ( p_vout == NULL );
1220 vlc_object_release( p_vout );
1223 if( i_type & VLC_VAR_HASCHOICE )
1225 /* Append choices menu */
1229 submenu = action->menu();
1232 submenu = new QMenu( menu );
1233 action->setMenu( submenu );
1237 CreateChoicesMenu( submenu, psz_var, p_object, true ) == 0 );
1239 action->setEnabled( false );
1244 CreateChoicesMenu( menu, psz_var, p_object, true ) == 0 );
1246 FREENULL( text.psz_string );
1250 switch( i_type & VLC_VAR_TYPE )
1253 val.i_int = 0; // Prevent the copy of an uninitialized value
1254 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_NORMAL,
1255 p_object, val, i_type );
1259 var_Get( p_object, psz_var, &val );
1260 val.b_bool = !val.b_bool;
1261 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_CHECK,
1262 p_object, val, i_type, !val.b_bool );
1265 FREENULL( text.psz_string );
1270 /** HACK for the navigation submenu:
1271 * "title %2i" variables take the value 0 if not set
1273 static bool CheckTitle( vlc_object_t *p_object, const char *psz_var )
1276 if( sscanf( psz_var, "title %2i", &i_title ) <= 0 )
1279 int i_current_title = var_GetInteger( p_object, "title" );
1280 return ( i_title == i_current_title );
1284 int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
1285 vlc_object_t *p_object, bool b_root )
1287 vlc_value_t val, val_list, text_list;
1290 /* Check the type of the object variable */
1291 i_type = var_Type( p_object, psz_var );
1293 /* Make sure we want to display the variable */
1294 if( submenu->isEmpty() && IsMenuEmpty( psz_var, p_object, b_root ) )
1295 return VLC_EGENERIC;
1297 switch( i_type & VLC_VAR_TYPE )
1301 case VLC_VAR_VARIABLE:
1302 case VLC_VAR_STRING:
1303 case VLC_VAR_INTEGER:
1307 /* Variable doesn't exist or isn't handled */
1308 return VLC_EGENERIC;
1311 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
1312 &val_list, &text_list ) < 0 )
1314 return VLC_EGENERIC;
1317 #define CURVAL val_list.p_list->p_values[i]
1318 #define CURTEXT text_list.p_list->p_values[i].psz_string
1319 #define RADIO_OR_COMMAND ( i_type & VLC_VAR_ISCOMMAND ) ? ITEM_NORMAL : ITEM_RADIO
1321 for( i = 0; i < val_list.p_list->i_count; i++ )
1323 vlc_value_t another_val;
1325 QMenu *subsubmenu = new QMenu( submenu );
1327 switch( i_type & VLC_VAR_TYPE )
1329 case VLC_VAR_VARIABLE:
1330 CreateChoicesMenu( subsubmenu, CURVAL.psz_string, p_object, false );
1331 subsubmenu->setTitle( qfu( CURTEXT ? CURTEXT :CURVAL.psz_string ) );
1332 submenu->addMenu( subsubmenu );
1335 case VLC_VAR_STRING:
1336 var_Get( p_object, psz_var, &val );
1337 another_val.psz_string = strdup( CURVAL.psz_string );
1338 menutext = qfu( CURTEXT ? CURTEXT : another_val.psz_string );
1339 CreateAndConnect( submenu, psz_var, menutext, "", RADIO_OR_COMMAND,
1340 p_object, another_val, i_type,
1341 val.psz_string && !strcmp( val.psz_string, CURVAL.psz_string ) );
1343 free( val.psz_string );
1346 case VLC_VAR_INTEGER:
1347 var_Get( p_object, psz_var, &val );
1348 if( CURTEXT ) menutext = qfu( CURTEXT );
1349 else menutext.sprintf( "%"PRId64, CURVAL.i_int );
1350 CreateAndConnect( submenu, psz_var, menutext, "", RADIO_OR_COMMAND,
1351 p_object, CURVAL, i_type,
1352 ( CURVAL.i_int == val.i_int )
1353 && CheckTitle( p_object, psz_var ) );
1357 var_Get( p_object, psz_var, &val );
1358 if( CURTEXT ) menutext = qfu( CURTEXT );
1359 else menutext.sprintf( "%.2f", CURVAL.f_float );
1360 CreateAndConnect( submenu, psz_var, menutext, "", RADIO_OR_COMMAND,
1361 p_object, CURVAL, i_type,
1362 CURVAL.f_float == val.f_float );
1369 currentGroup = NULL;
1371 /* clean up everything */
1372 var_FreeList( &val_list, &text_list );
1374 #undef RADIO_OR_COMMAND
1377 return submenu->isEmpty() ? VLC_EGENERIC : VLC_SUCCESS;
1380 void QVLCMenu::CreateAndConnect( QMenu *menu, const char *psz_var,
1381 const QString& text, const QString& help,
1382 int i_item_type, vlc_object_t *p_obj,
1383 vlc_value_t val, int i_val_type,
1386 QAction *action = FindActionWithVar( menu, psz_var );
1391 action = new QAction( text, menu );
1392 menu->addAction( action );
1396 action->setToolTip( help );
1397 action->setEnabled( p_obj != NULL );
1399 if( i_item_type == ITEM_CHECK )
1401 action->setCheckable( true );
1403 else if( i_item_type == ITEM_RADIO )
1405 action->setCheckable( true );
1407 currentGroup = new QActionGroup( menu );
1408 currentGroup->addAction( action );
1411 action->setChecked( checked );
1413 MenuItemData *itemData = qFindChild<MenuItemData*>( action, QString() );
1415 itemData = new MenuItemData( action, p_obj, i_val_type, val, psz_var );
1417 /* remove previous signal-slot connection(s) if any */
1418 action->disconnect( );
1420 CONNECT( action, triggered(), THEDP->menusMapper, map() );
1421 THEDP->menusMapper->setMapping( action, itemData );
1424 menu->addAction( action );
1427 void QVLCMenu::DoAction( QObject *data )
1429 MenuItemData *itemData = qobject_cast<MenuItemData *>( data );
1430 vlc_object_t *p_object = itemData->p_obj;
1431 if( p_object == NULL ) return;
1433 /* Preserve settings across vouts via the playlist object: */
1434 if( !strcmp( itemData->psz_var, "fullscreen" )
1435 || !strcmp( itemData->psz_var, "video-on-top" ) )
1436 var_Set( pl_Get( p_object ), itemData->psz_var, itemData->val );
1438 var_Set( p_object, itemData->psz_var, itemData->val );
1441 void QVLCMenu::updateRecents( intf_thread_t *p_intf )
1446 RecentsMRL* rmrl = RecentsMRL::getInstance( p_intf );
1447 QStringList l = rmrl->recents();
1449 recentsMenu->clear();
1453 action = recentsMenu->addAction( qtr(" - Empty - ") );
1454 action->setEnabled( false );
1458 for( int i = 0; i < l.size(); ++i )
1460 action = recentsMenu->addAction(
1461 QString( "&%1: " ).arg( i + 1 ) + l.at( i ),
1462 rmrl->signalMapper, SLOT( map() ),
1463 i <= 9 ? QString( "Ctrl+%1" ).arg( i + 1 ) : "" );
1464 rmrl->signalMapper->setMapping( action, l.at( i ) );
1467 recentsMenu->addSeparator();
1468 recentsMenu->addAction( qtr("&Clear"), rmrl, SLOT( clear() ) );