1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright © 2006-2011 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
8 * Jean-Baptiste Kempf <jb@videolan.org>
9 * Jean-Philippe André <jpeg@videolan.org>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * ( at your option ) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
27 * - Remove static currentGroup
30 #define __STDC_FORMAT_MACROS 1
31 #define __STDC_CONSTANT_MACROS 1
37 #include <vlc_common.h>
38 #include <vlc_intf_strings.h>
39 #include <vlc_vout.h> /* vout_thread_t */
43 #include "main_interface.hpp" /* View modifications */
44 #include "dialogs_provider.hpp" /* Dialogs display */
45 #include "input_manager.hpp" /* Input Management */
46 #include "recents.hpp" /* Recent Items */
47 #include "actions_manager.hpp" /* Actions Management: play+volume */
48 #include "extensions_manager.hpp" /* Extensions menu*/
53 #include <QActionGroup>
54 #include <QSignalMapper>
55 #include <QSystemTrayIcon>
57 #include <QFontMetrics>
60 This file defines the main menus and the pop-up menu (right-click menu)
61 and the systray menu (in that order in the file)
63 There are 4 menus that have to be rebuilt everytime there are called:
64 Audio, Video, Navigation, view
65 4 functions are building those menus: AudioMenu, VideoMenu, NavigMenu, View
66 and 3 functions associated are collecting the objects :
67 InputAutoMenuBuilder, AudioAutoMenuBuilder, VideoAutoMenuBuilder.
69 A QSignalMapper decides when to rebuild those menus cf MenuFunc in the .hpp
70 Just before one of those menus are aboutToShow(), they are rebuild.
73 #define STATIC_ENTRY "__static__"
74 #define ENTRY_ALWAYS_ENABLED "__ignore__"
78 ITEM_NORMAL, /* not a checkbox, nor a radio */
79 ITEM_CHECK, /* Checkbox */
80 ITEM_RADIO /* Radiobox */
83 static QActionGroup *currentGroup;
85 QMenu *QVLCMenu::recentsMenu = NULL;
88 * @brief Add static entries to DP in menus
90 QAction *addDPStaticEntry( QMenu *menu,
94 const char *shortcut = NULL,
95 QAction::MenuRole = QAction::NoRole
98 QAction *action = NULL;
99 #ifndef __APPLE__ /* We don't set icons in menus in MacOS X */
100 if( !EMPTY_STR( icon ) )
102 if( !EMPTY_STR( shortcut ) )
103 action = menu->addAction( QIcon( icon ), text, THEDP,
104 member, qtr( shortcut ) );
106 action = menu->addAction( QIcon( icon ), text, THEDP, member );
111 if( !EMPTY_STR( shortcut ) )
112 action = menu->addAction( text, THEDP, member, qtr( shortcut ) );
114 action = menu->addAction( text, THEDP, member );
116 action->setData( STATIC_ENTRY );
121 * @brief Add static entries to MIM in menus
123 QAction* addMIMStaticEntry( intf_thread_t *p_intf,
128 bool bStatic = false )
131 #ifndef __APPLE__ /* We don't set icons in menus in MacOS X */
132 if( !EMPTY_STR( icon ) )
134 action = menu->addAction( text, THEMIM, member );
135 action->setIcon( QIcon( icon ) );
140 action = menu->addAction( text, THEMIM, member );
142 action->setData( bStatic ? STATIC_ENTRY : ENTRY_ALWAYS_ENABLED );
147 * @brief Enable all static entries of a menu, disable the others
148 * @param menu the menu in which the entries will be disabled
149 * @param enable if false, disable all entries
151 void EnableStaticEntries( QMenu *menu, bool enable = true )
155 QList< QAction* > actions = menu->actions();
156 for( int i = 0; i < actions.size(); ++i )
158 actions[i]->setEnabled( actions[i]->data().toString()
159 == ENTRY_ALWAYS_ENABLED ||
160 /* Be careful here, because data("string").toBool is true */
161 ( enable && (actions[i]->data().toString() == STATIC_ENTRY ) ) );
166 * \return Number of static entries
168 inline int DeleteNonStaticEntries( QMenu *menu )
170 if( !menu ) return VLC_EGENERIC;
174 QList< QAction* > actions = menu->actions();
175 for( int i = 0; i < actions.size(); ++i )
177 if( actions[i]->data().toString() != STATIC_ENTRY )
186 * \return QAction associated to psz_var variable
188 static QAction * FindActionWithVar( QMenu *menu, const char *psz_var )
190 QList< QAction* > actions = menu->actions();
191 for( int i = 0; i < actions.size(); ++i )
193 if( actions[i]->data().toString() == psz_var )
199 /*****************************************************************************
200 * Definitions of variables for the dynamic menus
201 *****************************************************************************/
202 #define PUSH_VAR( var ) varnames.push_back( var ); \
203 objects.push_back( VLC_OBJECT(p_object) )
205 #define PUSH_INPUTVAR( var ) varnames.push_back( var ); \
206 objects.push_back( VLC_OBJECT(p_input) );
208 #define PUSH_SEPARATOR if( objects.size() != i_last_separator ) { \
209 objects.push_back( 0 ); varnames.push_back( "" ); \
210 i_last_separator = objects.size(); }
212 static int InputAutoMenuBuilder( input_thread_t *p_object,
213 vector<vlc_object_t *> &objects,
214 vector<const char *> &varnames )
216 PUSH_VAR( "bookmark" );
218 PUSH_VAR( "chapter" );
219 PUSH_VAR( "navigation" );
220 PUSH_VAR( "program" );
224 static int VideoAutoMenuBuilder( vout_thread_t *p_object,
225 input_thread_t *p_input,
226 vector<vlc_object_t *> &objects,
227 vector<const char *> &varnames )
229 PUSH_INPUTVAR( "video-es" );
230 PUSH_INPUTVAR( "spu-es" );
231 PUSH_VAR( "fullscreen" );
232 PUSH_VAR( "video-on-top" );
233 PUSH_VAR( "video-wallpaper" );
235 PUSH_VAR( "direct3d-desktop" );
237 PUSH_VAR( "video-snapshot" );
239 PUSH_VAR( "autoscale" );
240 PUSH_VAR( "aspect-ratio" );
242 PUSH_VAR( "deinterlace" );
243 PUSH_VAR( "deinterlace-mode" );
244 PUSH_VAR( "postprocess" );
249 static int AudioAutoMenuBuilder( aout_instance_t *p_object,
250 input_thread_t *p_input,
251 vector<vlc_object_t *> &objects,
252 vector<const char *> &varnames )
254 PUSH_INPUTVAR( "audio-es" );
255 PUSH_VAR( "audio-channels" );
256 PUSH_VAR( "audio-device" );
257 PUSH_VAR( "visual" );
261 /*****************************************************************************
264 *****************************************************************************/
267 static inline void addMenuToMainbar( QMenu *func, QString title, QMenuBar *bar ) {
268 func->setTitle( title );
273 #define BAR_DADD( func, title, id ) { \
274 QMenu *_menu = func; _menu->setTitle( title ); bar->addMenu( _menu ); \
275 MenuFunc *f = new MenuFunc( _menu, id ); \
276 CONNECT( _menu, aboutToShow(), THEDP->menusUpdateMapper, map() ); \
277 THEDP->menusUpdateMapper->setMapping( _menu, f ); }
279 // Add a simple action
280 static inline void addAction( QMenu *_menu, QVariant val, QString title ) {
281 QAction *_action = new QAction( title, _menu );
282 _action->setData( val );
283 _menu->addAction( _action );
286 // Add an action with a submenu
287 static inline void addActionWithSubmenu( QMenu *_menu, QVariant val, QString title ) {
288 QAction *_action = new QAction( title, _menu );
289 _action->setData( val );
290 _action->setMenu( new QMenu( _menu ) );
291 _menu->addAction( _action );
294 // Add an action that is a checkbox
295 static inline void addActionWithCheckbox( QMenu *_menu, QVariant val, QString title ) {
296 QAction *_action = new QAction( title, _menu );
297 _action->setData( val );
298 _action->setCheckable( true );
299 _menu->addAction( _action );
303 * Main Menu Bar Creation
305 void QVLCMenu::createMenuBar( MainInterface *mi,
306 intf_thread_t *p_intf )
308 /* QMainWindows->menuBar()
309 gives the QProcess::destroyed timeout issue on Cleanlooks style with
310 setDesktopAware set to false */
311 QMenuBar *bar = mi->menuBar();
313 addMenuToMainbar( FileMenu( p_intf, bar, mi ), qtr( "&Media" ), bar );
315 /* Dynamic menus, rebuilt before being showed */
316 BAR_DADD( NavigMenu( p_intf, bar ), qtr( "P&layback" ), 3 );
317 BAR_DADD( AudioMenu( p_intf, bar ), qtr( "&Audio" ), 1 );
318 BAR_DADD( VideoMenu( p_intf, bar ), qtr( "&Video" ), 2 );
320 addMenuToMainbar( ToolsMenu( bar ), qtr( "&Tools" ), bar );
322 /* View menu, a bit different */
323 BAR_DADD( ViewMenu( p_intf, NULL, mi ), qtr( "V&iew" ), 4 );
325 addMenuToMainbar( HelpMenu( bar ), qtr( "&Help" ), bar );
330 * Media ( File ) Menu
331 * Opening, streaming and quit
333 QMenu *QVLCMenu::FileMenu( intf_thread_t *p_intf, QWidget *parent, MainInterface *mi )
335 QMenu *menu = new QMenu( parent );
338 addDPStaticEntry( menu, qtr( "Open &File..." ),
339 ":/type/file-asym", SLOT( simpleOpenDialog() ), "Ctrl+O" );
340 addDPStaticEntry( menu, qtr( I_OP_OPDIR ),
341 ":/type/folder-grey", SLOT( PLOpenDir() ), "Ctrl+F" );
342 addDPStaticEntry( menu, qtr( "Open &Disc..." ),
343 ":/type/disc", SLOT( openDiscDialog() ), "Ctrl+D" );
344 addDPStaticEntry( menu, qtr( "Open &Network Stream..." ),
345 ":/type/network", SLOT( openNetDialog() ), "Ctrl+N" );
346 addDPStaticEntry( menu, qtr( "Open &Capture Device..." ),
347 ":/type/capture-card", SLOT( openCaptureDialog() ), "Ctrl+C" );
349 menu->addSeparator();
351 addDPStaticEntry( menu, qtr( "&Open (advanced)..." ),
352 ":/type/file-asym", SLOT( openFileDialog() ), "Ctrl+Shift+O" );
353 menu->addSeparator();
355 addDPStaticEntry( menu, qtr( "Open &Location from clipboard" ),
356 NULL, SLOT( openUrlDialog() ), "Ctrl+V" );
358 if( var_InheritBool( p_intf, "qt-recentplay" ) )
360 recentsMenu = new QMenu( qtr( "Open &Recent Media" ), menu );
361 updateRecents( p_intf );
362 menu->addMenu( recentsMenu );
364 menu->addSeparator();
366 addDPStaticEntry( menu, qtr( I_PL_SAVE ), "", SLOT( saveAPlaylist() ),
368 menu->addSeparator();
371 addDPStaticEntry( menu, qtr( "Conve&rt / Save..." ), "",
372 SLOT( openAndTranscodingDialogs() ), "Ctrl+R" );
373 addDPStaticEntry( menu, qtr( "&Stream..." ),
374 ":/menu/stream", SLOT( openAndStreamingDialogs() ), "Ctrl+S" );
375 menu->addSeparator();
378 action = addMIMStaticEntry( p_intf, menu, qtr( "Quit at the end of playlist" ), "",
379 SLOT( activatePlayQuit( bool ) ) );
380 action->setCheckable( true );
381 action->setChecked( THEMIM->getPlayExitState() );
383 if( mi->getSysTray() )
385 action = menu->addAction( qtr( "Close to systray"), mi,
386 SLOT( toggleUpdateSystrayMenu() ) );
389 addDPStaticEntry( menu, qtr( "&Quit" ) ,
390 ":/menu/quit", SLOT( quit() ), "Ctrl+Q" );
395 * Tools, like Media Information, Preferences or Messages
397 QMenu *QVLCMenu::ToolsMenu( QMenu *menu )
399 addDPStaticEntry( menu, qtr( "&Effects and Filters"), ":/menu/settings",
400 SLOT( extendedDialog() ), "Ctrl+E" );
402 addDPStaticEntry( menu, qtr( "&Track Synchronization"), ":/menu/settings",
403 SLOT( synchroDialog() ), "" );
405 addDPStaticEntry( menu, qtr( I_MENU_INFO ) , ":/menu/info",
406 SLOT( mediaInfoDialog() ), "Ctrl+I" );
407 addDPStaticEntry( menu, qtr( I_MENU_CODECINFO ) ,
408 ":/menu/info", SLOT( mediaCodecDialog() ), "Ctrl+J" );
411 addDPStaticEntry( menu, qtr( I_MENU_VLM ), "", SLOT( vlmDialog() ),
415 addDPStaticEntry( menu, qtr( "Program Guide" ), "", SLOT( epgDialog() ),
418 addDPStaticEntry( menu, qtr( I_MENU_MSG ),
419 ":/menu/messages", SLOT( messagesDialog() ), "Ctrl+M" );
421 addDPStaticEntry( menu, qtr( "Plu&gins and extensions" ),
422 "", SLOT( pluginDialog() ) );
423 menu->addSeparator();
425 addDPStaticEntry( menu, qtr( "Customi&ze Interface..." ),
426 ":/menu/preferences", SLOT( toolbarDialog() ) );
428 addDPStaticEntry( menu, qtr( "&Preferences" ),
429 ":/menu/preferences", SLOT( prefsDialog() ), "Ctrl+P", QAction::PreferencesRole );
436 * Interface modification, load other interfaces, activate Extensions
437 * \param current, set to NULL for menu creation, else for menu update
439 QMenu *QVLCMenu::ViewMenu( intf_thread_t *p_intf, QMenu *current, MainInterface *_mi )
444 MainInterface *mi = _mi ? _mi : p_intf->p_sys->p_mi;
449 menu = new QMenu( qtr( "&View" ), mi );
455 //HACK menu->clear() does not delete submenus
456 QList<QAction*> actions = menu->actions();
457 foreach( QAction *a, actions )
459 QMenu *m = a->menu();
460 if( a->parent() == menu ) delete a;
461 else menu->removeAction( a );
462 if( m && m->parent() == menu ) delete m;
468 QIcon( ":/menu/playlist_menu" ),
470 qtr( "Play&list" ), mi,
471 SLOT( togglePlaylist() ), qtr( "Ctrl+L" ) );
473 menu->addSeparator();
476 action = menu->addAction( qtr( "Mi&nimal Interface" ) );
477 action->setShortcut( qtr( "Ctrl+H" ) );
478 action->setCheckable( true );
479 action->setChecked( (mi->getControlsVisibilityStatus() & CONTROLS_HIDDEN ) );
481 CONNECT( action, triggered( bool ), mi, toggleMinimalView( bool ) );
482 CONNECT( mi, minimalViewToggled( bool ), action, setChecked( bool ) );
484 /* FullScreen View */
485 action = menu->addAction( qtr( "&Fullscreen Interface" ), mi,
486 SLOT( toggleInterfaceFullScreen() ), QString( "F11" ) );
487 action->setCheckable( true );
488 action->setChecked( mi->isInterfaceFullScreen() );
489 CONNECT( mi, fullscreenInterfaceToggled( bool ),
490 action, setChecked( bool ) );
492 /* Advanced Controls */
493 action = menu->addAction( qtr( "&Advanced Controls" ), mi,
494 SLOT( toggleAdvancedButtons() ) );
495 action->setCheckable( true );
496 if( mi->getControlsVisibilityStatus() & CONTROLS_ADVANCED )
497 action->setChecked( true );
499 /* Docked Playlist */
500 action = menu->addAction( qtr( "Docked Playlist" ) );
501 action->setCheckable( true );
502 action->setChecked( mi->isPlDocked() );
503 CONNECT( action, triggered( bool ), mi, dockPlaylist( bool ) );
505 action = menu->addAction( qtr( "Status Bar" ) );
506 action->setCheckable( true );
507 action->setChecked( mi->statusBar()->isVisible() );
508 CONNECT( action, triggered( bool ), mi, setStatusBarVisibility( bool) );
509 #if 0 /* For Visualisations. Not yet working */
510 adv = menu->addAction( qtr( "Visualizations selector" ), mi,
512 adv->setCheckable( true );
513 if( visual_selector_enabled ) adv->setChecked( true );
516 menu->addSeparator();
518 InterfacesMenu( p_intf, menu );
519 menu->addSeparator();
522 ExtensionsMenu( p_intf, menu );
528 * Interface Sub-Menu, to list extras interface and skins
530 QMenu *QVLCMenu::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
532 vector<vlc_object_t *> objects;
533 vector<const char *> varnames;
534 varnames.push_back( "intf-add" );
535 objects.push_back( VLC_OBJECT(p_intf) );
537 return Populate( p_intf, current, varnames, objects );
541 * Extensions menu: populate the current menu with extensions
543 void QVLCMenu::ExtensionsMenu( intf_thread_t *p_intf, QMenu *extMenu )
545 /* Get ExtensionsManager and load extensions if needed */
546 ExtensionsManager *extMgr = ExtensionsManager::getInstance( p_intf );
548 if( !var_InheritBool( p_intf, "qt-autoload-extensions")
549 && !extMgr->isLoaded() )
554 if( !extMgr->isLoaded() && !extMgr->cannotLoad() )
556 extMgr->loadExtensions();
559 /* Let the ExtensionsManager build itself the menu */
560 extMenu->addSeparator();
561 extMgr->menu( extMenu );
567 QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QMenu * current )
569 vector<vlc_object_t *> objects;
570 vector<const char *> varnames;
571 aout_instance_t *p_aout;
572 input_thread_t *p_input;
574 if( current->isEmpty() )
576 addActionWithSubmenu( current, "audio-es", qtr( "Audio &Track" ) );
577 addActionWithSubmenu( current, "audio-channels", qtr( "Audio &Channels" ) );
578 addActionWithSubmenu( current, "audio-device", qtr( "Audio &Device" ) );
579 current->addSeparator();
581 addActionWithSubmenu( current, "visual", qtr( "&Visualizations" ) );
582 current->addSeparator();
584 QAction *action = current->addAction( qtr( "Increase Volume" ),
585 ActionsManager::getInstance( p_intf ), SLOT( AudioUp() ) );
586 action->setData( STATIC_ENTRY );
587 action = current->addAction( qtr( "Decrease Volume" ),
588 ActionsManager::getInstance( p_intf ), SLOT( AudioDown() ) );
589 action->setData( STATIC_ENTRY );
590 action = current->addAction( qtr( "Mute" ),
591 ActionsManager::getInstance( p_intf ), SLOT( toggleMuteAudio() ) );
592 action->setData( STATIC_ENTRY );
595 p_input = THEMIM->getInput();
596 p_aout = THEMIM->getAout();
597 EnableStaticEntries( current, ( p_aout != NULL ) );
598 AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
601 vlc_object_release( p_aout );
604 return Populate( p_intf, current, varnames, objects );
608 QMenu *QVLCMenu::SubtitleMenu( intf_thread_t *p_intf, QMenu *current )
611 QMenu *submenu = new QMenu( qtr( "&Subtitles Track" ), current );
612 action = current->addMenu( submenu );
613 action->setData( "spu-es" );
614 addDPStaticEntry( submenu, qtr( "Open File..." ), "",
615 SLOT( loadSubtitlesFile() ) );
616 submenu->addSeparator();
622 * Subtitles are part of Video.
624 QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current, bool b_subtitle )
626 vout_thread_t *p_vout;
627 input_thread_t *p_input;
628 vector<vlc_object_t *> objects;
629 vector<const char *> varnames;
631 if( current->isEmpty() )
633 addActionWithSubmenu( current, "video-es", qtr( "Video &Track" ) );
635 SubtitleMenu( p_intf, current );
637 current->addSeparator();
639 addActionWithCheckbox( current, "fullscreen", qtr( "&Fullscreen" ) );
640 addActionWithCheckbox( current, "autoscale", qtr( "Always Fit &Window" ) );
641 addActionWithCheckbox( current, "video-on-top", qtr( "Always &on Top" ) );
643 addActionWithCheckbox( current, "direct3d-desktop", qtr( "Display on &Desktop" ) );
645 addAction( current, "video-snapshot", qtr( "Take &Snapshot" ) );
647 addActionWithCheckbox( current, "video-wallpaper", qtr( "Set as Wall&paper" ) );
649 current->addSeparator();
651 addActionWithSubmenu( current, "zoom", qtr( "&Zoom" ) );
652 addActionWithSubmenu( current, "aspect-ratio", qtr( "&Aspect Ratio" ) );
653 addActionWithSubmenu( current, "crop", qtr( "&Crop" ) );
654 addActionWithSubmenu( current, "deinterlace", qtr( "&Deinterlace" ) );
655 addActionWithSubmenu( current, "deinterlace-mode", qtr( "&Deinterlace mode" ) );
656 addActionWithSubmenu( current, "postprocess", qtr( "&Post processing" ) );
659 p_input = THEMIM->getInput();
661 p_vout = THEMIM->getVout();
662 VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
665 vlc_object_release( p_vout );
667 return Populate( p_intf, current, varnames, objects );
672 * For DVD, MP4, MOV and other chapter based format
674 QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *menu )
678 addActionWithSubmenu( menu, "title", qtr( "T&itle" ) );
679 addActionWithSubmenu( menu, "chapter", qtr( "&Chapter" ) );
680 addActionWithSubmenu( menu, "navigation", qtr( "&Navigation" ) );
681 addActionWithSubmenu( menu, "program", qtr( "&Program" ) );
683 /* FixMe: sync I_MENU_BOOKMARK string */
684 QMenu *submenu = new QMenu( qtr( "Custom &Bookmarks" ), menu );
685 addDPStaticEntry( submenu, qtr( "&Manage" ), "",
686 SLOT( bookmarksDialog() ), "Ctrl+B" );
687 submenu->addSeparator();
688 action = menu->addMenu( submenu );
689 action->setData( "bookmark" );
691 menu->addSeparator();
692 PopupMenuPlaylistControlEntries( menu, p_intf );
693 PopupMenuControlEntries( menu, p_intf );
695 EnableStaticEntries( menu, ( THEMIM->getInput() != NULL ) );
696 return RebuildNavigMenu( p_intf, menu );
699 QMenu *QVLCMenu::RebuildNavigMenu( intf_thread_t *p_intf, QMenu *menu )
702 input_thread_t *p_object;
703 vector<vlc_object_t *> objects;
704 vector<const char *> varnames;
706 /* Get the input and hold it */
707 p_object = THEMIM->getInput();
709 InputAutoMenuBuilder( p_object, objects, varnames );
711 menu->addSeparator();
713 /* Title and so on */
714 PUSH_VAR( "prev-title" );
715 PUSH_VAR( "next-title" );
716 PUSH_VAR( "prev-chapter" );
717 PUSH_VAR( "next-chapter" );
719 EnableStaticEntries( menu, (p_object != NULL ) );
720 return Populate( p_intf, menu, varnames, objects );
726 QMenu *QVLCMenu::HelpMenu( QWidget *parent )
728 QMenu *menu = new QMenu( parent );
729 addDPStaticEntry( menu, qtr( "&Help..." ) ,
730 ":/menu/help", SLOT( helpDialog() ), "F1" );
732 addDPStaticEntry( menu, qtr( "Check for &Updates..." ) , "",
733 SLOT( updateDialog() ) );
735 menu->addSeparator();
736 addDPStaticEntry( menu, qtr( I_MENU_ABOUT ), ":/menu/info",
737 SLOT( aboutDialog() ), "Shift+F1", QAction::AboutRole );
741 /*****************************************************************************
742 * Popup menus - Right Click menus *
743 *****************************************************************************/
744 #define POPUP_BOILERPLATE \
745 static QMenu* menu = NULL; \
746 delete menu; menu = NULL; \
749 unsigned int i_last_separator = 0; \
750 vector<vlc_object_t *> objects; \
751 vector<const char *> varnames; \
752 input_thread_t *p_input = THEMIM->getInput();
754 #define CREATE_POPUP \
755 menu = new QMenu(); \
756 Populate( p_intf, menu, varnames, objects ); \
757 menu->popup( QCursor::pos() ); \
758 i_last_separator = 0;
760 void QVLCMenu::PopupPlayEntries( QMenu *menu,
761 intf_thread_t *p_intf,
762 input_thread_t *p_input )
766 /* Play or Pause action and icon */
767 if( !p_input || var_GetInteger( p_input, "state" ) != PLAYING_S )
769 action = menu->addAction( qtr( "Play" ),
770 ActionsManager::getInstance( p_intf ), SLOT( play() ) );
771 #ifndef __APPLE__ /* No icons in menus in Mac */
772 action->setIcon( QIcon( ":/menu/play" ) );
777 addMIMStaticEntry( p_intf, menu, qtr( "Pause" ),
778 ":/menu/pause", SLOT( togglePlayPause() ) );
782 void QVLCMenu::PopupMenuControlEntries( QMenu *menu, intf_thread_t *p_intf )
787 action = menu->addAction( qtr( "&Faster" ), THEMIM->getIM(),
789 #ifndef __APPLE__ /* No icons in menus in Mac */
790 action->setIcon( QIcon( ":/toolbar/faster") );
792 action->setData( STATIC_ENTRY );
794 action = menu->addAction( qtr( "Faster (fine)" ), THEMIM->getIM(),
795 SLOT( littlefaster() ) );
796 action->setData( STATIC_ENTRY );
798 action = menu->addAction( qtr( "N&ormal Speed" ), THEMIM->getIM(),
799 SLOT( normalRate() ) );
800 action->setData( STATIC_ENTRY );
802 action = menu->addAction( qtr( "Slower (fine)" ), THEMIM->getIM(),
803 SLOT( littleslower() ) );
804 action->setData( STATIC_ENTRY );
806 action = menu->addAction( qtr( "Slo&wer" ), THEMIM->getIM(),
808 #ifndef __APPLE__ /* No icons in menus in Mac */
809 action->setIcon( QIcon( ":/toolbar/slower") );
811 action->setData( STATIC_ENTRY );
813 menu->addSeparator();
815 action = menu->addAction( qtr( "&Jump Forward" ), THEMIM->getIM(),
817 #ifndef __APPLE__ /* No icons in menus in Mac */
818 action->setIcon( QIcon( ":/toolbar/skip_fw") );
820 action->setData( STATIC_ENTRY );
822 action = menu->addAction( qtr( "Jump Bac&kward" ), THEMIM->getIM(),
824 #ifndef __APPLE__ /* No icons in menus in Mac */
825 action->setIcon( QIcon( ":/toolbar/skip_back") );
827 action->setData( STATIC_ENTRY );
828 addDPStaticEntry( menu, qtr( I_MENU_GOTOTIME ),"",
829 SLOT( gotoTimeDialog() ), "Ctrl+T" );
830 menu->addSeparator();
834 void QVLCMenu::PopupMenuPlaylistControlEntries( QMenu *menu,
835 intf_thread_t *p_intf )
837 bool bEnable = THEMIM->getInput() != NULL;
839 addMIMStaticEntry( p_intf, menu, qtr( "&Stop" ), ":/menu/stop",
840 SLOT( stop() ), true );
841 /* Disable Stop in the right-click popup menu */
843 action->setEnabled( false );
845 /* Next / Previous */
846 addMIMStaticEntry( p_intf, menu, qtr( "Pre&vious" ),
847 ":/menu/previous", SLOT( prev() ) );
848 addMIMStaticEntry( p_intf, menu, qtr( "Ne&xt" ),
849 ":/menu/next", SLOT( next() ) );
851 menu->addSeparator();
854 void QVLCMenu::PopupMenuStaticEntries( QMenu *menu )
856 QMenu *openmenu = new QMenu( qtr( "Open a Media" ), menu );
857 addDPStaticEntry( openmenu, qtr( "&Open File..." ),
858 ":/type/file-asym", SLOT( openFileDialog() ) );
859 addDPStaticEntry( openmenu, qtr( I_OP_OPDIR ),
860 ":/type/folder-grey", SLOT( PLOpenDir() ) );
861 addDPStaticEntry( openmenu, qtr( "Open &Disc..." ),
862 ":/type/disc", SLOT( openDiscDialog() ) );
863 addDPStaticEntry( openmenu, qtr( "Open &Network..." ),
864 ":/type/network", SLOT( openNetDialog() ) );
865 addDPStaticEntry( openmenu, qtr( "Open &Capture Device..." ),
866 ":/type/capture-card", SLOT( openCaptureDialog() ) );
867 menu->addMenu( openmenu );
869 menu->addSeparator();
871 QMenu *helpmenu = HelpMenu( menu );
872 helpmenu->setTitle( qtr( "Help" ) );
873 menu->addMenu( helpmenu );
876 addDPStaticEntry( menu, qtr( "Quit" ), ":/menu/quit",
877 SLOT( quit() ), "Ctrl+Q", QAction::QuitRole );
880 /* Video Tracks and Subtitles tracks */
881 void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf, bool show )
886 vout_thread_t *p_vout = THEMIM->getVout();
889 VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
890 vlc_object_release( p_vout );
897 void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf, bool show )
902 aout_instance_t *p_aout = THEMIM->getAout();
903 AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
905 vlc_object_release( p_aout );
910 /* Navigation stuff, and general menus ( open ), used only for skins */
911 void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf, bool show )
917 varnames.push_back( "audio-es" );
918 InputAutoMenuBuilder( p_input, objects, varnames );
923 Populate( p_intf, menu, varnames, objects );
925 menu->addSeparator();
926 PopupPlayEntries( menu, p_intf, p_input );
927 PopupMenuPlaylistControlEntries( menu, p_intf);
929 menu->addSeparator();
930 PopupMenuControlEntries( menu, p_intf );
932 menu->addSeparator();
933 PopupMenuStaticEntries( menu );
935 menu->popup( QCursor::pos() );
938 /* Main Menu that sticks everything together */
939 void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show )
946 bool b_isFullscreen = false;
947 MainInterface *mi = p_intf->p_sys->p_mi;
949 PopupPlayEntries( menu, p_intf, p_input );
950 PopupMenuPlaylistControlEntries( menu, p_intf );
951 menu->addSeparator();
956 vout_thread_t *p_vout = THEMIM->getVout();
958 /* Add a fullscreen switch button, since it is the most used function */
961 vlc_value_t val; var_Get( p_vout, "fullscreen", &val );
963 b_isFullscreen = !( !val.b_bool );
967 CreateAndConnect( menu, "fullscreen",
968 qtr( "Leave Fullscreen" ),"" , ITEM_NORMAL,
969 VLC_OBJECT(p_vout), val, VLC_VAR_BOOL, b_isFullscreen );
971 vlc_object_release( p_vout );
973 menu->addSeparator();
977 InputAutoMenuBuilder( p_input, objects, varnames );
980 submenu = new QMenu( menu );
981 action = menu->addMenu( AudioMenu( p_intf, submenu ) );
982 action->setText( qtr( "&Audio" ) );
983 if( action->menu()->isEmpty() )
984 action->setEnabled( false );
987 submenu = new QMenu( menu );
988 action = menu->addMenu( VideoMenu( p_intf, submenu, false ) );
989 action->setText( qtr( "&Video" ) );
990 if( action->menu()->isEmpty() )
991 action->setEnabled( false );
993 submenu = SubtitleMenu( p_intf, menu );
994 submenu->setTitle( qtr( "Subti&tle") );
995 UpdateItem( p_intf, menu, "spu-es", VLC_OBJECT(p_input), true );
997 /* Playback menu for chapters */
998 submenu = new QMenu( menu );
999 action = menu->addMenu( NavigMenu( p_intf, submenu ) );
1000 action->setText( qtr( "&Playback" ) );
1001 if( action->menu()->isEmpty() )
1002 action->setEnabled( false );
1005 menu->addSeparator();
1007 /* Add some special entries for windowed mode: Interface Menu */
1008 if( !b_isFullscreen )
1010 QMenu *submenu = new QMenu( qtr( "Tools" ), menu );
1011 /*QMenu *tools =*/ ToolsMenu( submenu );
1012 submenu->addSeparator();
1014 /* In skins interface, append some items */
1017 submenu->setTitle( qtr( "Interface" ) );
1018 if( p_intf->p_sys->b_isDialogProvider )
1020 vlc_object_t* p_object = p_intf->p_parent;
1022 objects.clear(); varnames.clear();
1023 objects.push_back( p_object );
1024 varnames.push_back( "intf-skins" );
1025 Populate( p_intf, submenu, varnames, objects );
1027 objects.clear(); varnames.clear();
1028 objects.push_back( p_object );
1029 varnames.push_back( "intf-skins-interactive" );
1030 Populate( p_intf, submenu, varnames, objects );
1033 msg_Warn( p_intf, "could not find parent interface" );
1037 QMenu *bar = menu; // Needed for next macro
1038 BAR_DADD( ViewMenu( p_intf, NULL, mi ), qtr( "V&iew" ), 4 );
1041 menu->addMenu( submenu );
1044 /* Static entries for ending, like open */
1045 PopupMenuStaticEntries( menu );
1047 menu->popup( QCursor::pos() );
1051 #undef POPUP_BOILERPLATE
1055 /************************************************************************
1057 ************************************************************************/
1059 void QVLCMenu::updateSystrayMenu( MainInterface *mi,
1060 intf_thread_t *p_intf,
1061 bool b_force_visible )
1063 input_thread_t *p_input = THEMIM->getInput();
1065 /* Get the systray menu and clean it */
1066 QMenu *sysMenu = mi->getSysTrayMenu();
1070 /* Hide / Show VLC and cone */
1071 if( mi->isVisible() || b_force_visible )
1073 sysMenu->addAction( QIcon( ":/logo/vlc16.png" ),
1074 qtr( "Hide VLC media player in taskbar" ), mi,
1075 SLOT( hideUpdateSystrayMenu() ) );
1079 sysMenu->addAction( QIcon( ":/logo/vlc16.png" ),
1080 qtr( "Show VLC media player" ), mi,
1081 SLOT( showUpdateSystrayMenu() ) );
1083 sysMenu->addSeparator();
1086 PopupPlayEntries( sysMenu, p_intf, p_input );
1087 PopupMenuPlaylistControlEntries( sysMenu, p_intf);
1088 PopupMenuControlEntries( sysMenu, p_intf);
1090 addDPStaticEntry( sysMenu, qtr( "&Open a Media" ),
1091 ":/type/file-wide", SLOT( openFileDialog() ) );
1092 addDPStaticEntry( sysMenu, qtr( "&Quit" ) ,
1093 ":/menu/quit", SLOT( quit() ) );
1096 mi->getSysTray()->setContextMenu( sysMenu );
1102 #undef PUSH_SEPARATOR
1104 /*************************************************************************
1105 * Builders for automenus
1106 *************************************************************************/
1107 QMenu * QVLCMenu::Populate( intf_thread_t *p_intf,
1109 vector< const char *> & varnames,
1110 vector<vlc_object_t *> & objects )
1112 QMenu *menu = current;
1115 currentGroup = NULL;
1117 for( int i = 0; i < (int)objects.size() ; i++ )
1119 if( !varnames[i] || !*varnames[i] )
1121 menu->addSeparator();
1125 UpdateItem( p_intf, menu, varnames[i], objects[i], true );
1130 /*****************************************************************************
1132 *****************************************************************************/
1134 static bool IsMenuEmpty( const char *psz_var,
1135 vlc_object_t *p_object,
1136 bool b_root = true )
1138 vlc_value_t val, val_list;
1139 int i_type, i_result, i;
1141 /* Check the type of the object variable */
1142 i_type = var_Type( p_object, psz_var );
1144 /* Check if we want to display the variable */
1145 if( !( i_type & VLC_VAR_HASCHOICE ) ) return false;
1147 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
1148 if( val.i_int == 0 ) return true;
1150 if( ( i_type & VLC_VAR_TYPE ) != VLC_VAR_VARIABLE )
1152 if( val.i_int == 1 && b_root ) return true;
1156 /* Check children variables in case of VLC_VAR_VARIABLE */
1157 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
1162 for( i = 0, i_result = true; i < val_list.p_list->i_count; i++ )
1164 if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
1172 /* clean up everything */
1173 var_FreeList( &val_list, NULL );
1178 #define TEXT_OR_VAR qfu ( text.psz_string ? text.psz_string : psz_var )
1180 void QVLCMenu::UpdateItem( intf_thread_t *p_intf, QMenu *menu,
1181 const char *psz_var, vlc_object_t *p_object, bool b_submenu )
1183 vlc_value_t val, text;
1186 QAction *action = FindActionWithVar( menu, psz_var );
1188 DeleteNonStaticEntries( action->menu() );
1193 action->setEnabled( false );
1197 /* Check the type of the object variable */
1198 /* This HACK is needed so we have a radio button for audio and video tracks
1199 instread of a checkbox */
1200 if( !strcmp( psz_var, "audio-es" )
1201 || !strcmp( psz_var, "video-es" ) )
1202 i_type = VLC_VAR_INTEGER | VLC_VAR_HASCHOICE;
1204 i_type = var_Type( p_object, psz_var );
1206 switch( i_type & VLC_VAR_TYPE )
1210 case VLC_VAR_VARIABLE:
1211 case VLC_VAR_STRING:
1212 case VLC_VAR_INTEGER:
1216 /* Variable doesn't exist or isn't handled */
1218 action->setEnabled( false );
1222 /* Make sure we want to display the variable */
1223 if( menu->isEmpty() && IsMenuEmpty( psz_var, p_object ) )
1226 action->setEnabled( false );
1230 /* Get the descriptive name of the variable */
1231 int i_ret = var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
1232 if( i_ret != VLC_SUCCESS )
1234 text.psz_string = NULL;
1239 action = new QAction( TEXT_OR_VAR, menu );
1240 menu->addAction( action );
1241 action->setData( psz_var );
1244 /* Some specific stuff */
1245 bool forceDisabled = false;
1246 if( !strcmp( psz_var, "spu-es" ) )
1248 vout_thread_t *p_vout = THEMIM->getVout();
1249 forceDisabled = ( p_vout == NULL );
1251 vlc_object_release( p_vout );
1254 if( i_type & VLC_VAR_HASCHOICE )
1256 /* Append choices menu */
1260 submenu = action->menu();
1263 submenu = new QMenu( menu );
1264 action->setMenu( submenu );
1268 CreateChoicesMenu( submenu, psz_var, p_object, true ) == 0 );
1270 action->setEnabled( false );
1275 CreateChoicesMenu( menu, psz_var, p_object, true ) == 0 );
1277 FREENULL( text.psz_string );
1281 switch( i_type & VLC_VAR_TYPE )
1284 val.i_int = 0; // Prevent the copy of an uninitialized value
1285 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_NORMAL,
1286 p_object, val, i_type );
1290 var_Get( p_object, psz_var, &val );
1291 val.b_bool = !val.b_bool;
1292 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_CHECK,
1293 p_object, val, i_type, !val.b_bool );
1296 FREENULL( text.psz_string );
1301 /** HACK for the navigation submenu:
1302 * "title %2i" variables take the value 0 if not set
1304 static bool CheckTitle( vlc_object_t *p_object, const char *psz_var )
1307 if( sscanf( psz_var, "title %2i", &i_title ) <= 0 )
1310 int i_current_title = var_GetInteger( p_object, "title" );
1311 return ( i_title == i_current_title );
1315 int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
1316 vlc_object_t *p_object, bool b_root )
1318 vlc_value_t val, val_list, text_list;
1321 /* Check the type of the object variable */
1322 i_type = var_Type( p_object, psz_var );
1324 /* Make sure we want to display the variable */
1325 if( submenu->isEmpty() && IsMenuEmpty( psz_var, p_object, b_root ) )
1326 return VLC_EGENERIC;
1328 switch( i_type & VLC_VAR_TYPE )
1332 case VLC_VAR_VARIABLE:
1333 case VLC_VAR_STRING:
1334 case VLC_VAR_INTEGER:
1338 /* Variable doesn't exist or isn't handled */
1339 return VLC_EGENERIC;
1342 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
1343 &val_list, &text_list ) < 0 )
1345 return VLC_EGENERIC;
1348 #define CURVAL val_list.p_list->p_values[i]
1349 #define CURTEXT text_list.p_list->p_values[i].psz_string
1350 #define RADIO_OR_COMMAND ( i_type & VLC_VAR_ISCOMMAND ) ? ITEM_NORMAL : ITEM_RADIO
1352 for( i = 0; i < val_list.p_list->i_count; i++ )
1354 vlc_value_t another_val;
1356 QMenu *subsubmenu = new QMenu( submenu );
1358 switch( i_type & VLC_VAR_TYPE )
1360 case VLC_VAR_VARIABLE:
1361 CreateChoicesMenu( subsubmenu, CURVAL.psz_string, p_object, false );
1362 subsubmenu->setTitle( qfu( CURTEXT ? CURTEXT :CURVAL.psz_string ) );
1363 submenu->addMenu( subsubmenu );
1366 case VLC_VAR_STRING:
1367 var_Get( p_object, psz_var, &val );
1368 another_val.psz_string = strdup( CURVAL.psz_string );
1369 menutext = qfu( CURTEXT ? CURTEXT : another_val.psz_string );
1370 CreateAndConnect( submenu, psz_var, menutext, "", RADIO_OR_COMMAND,
1371 p_object, another_val, i_type,
1372 val.psz_string && !strcmp( val.psz_string, CURVAL.psz_string ) );
1374 free( val.psz_string );
1377 case VLC_VAR_INTEGER:
1378 var_Get( p_object, psz_var, &val );
1379 if( CURTEXT ) menutext = qfu( CURTEXT );
1380 else menutext.sprintf( "%"PRId64, CURVAL.i_int );
1381 CreateAndConnect( submenu, psz_var, menutext, "", RADIO_OR_COMMAND,
1382 p_object, CURVAL, i_type,
1383 ( CURVAL.i_int == val.i_int )
1384 && CheckTitle( p_object, psz_var ) );
1388 var_Get( p_object, psz_var, &val );
1389 if( CURTEXT ) menutext = qfu( CURTEXT );
1390 else menutext.sprintf( "%.2f", CURVAL.f_float );
1391 CreateAndConnect( submenu, psz_var, menutext, "", RADIO_OR_COMMAND,
1392 p_object, CURVAL, i_type,
1393 CURVAL.f_float == val.f_float );
1400 currentGroup = NULL;
1402 /* clean up everything */
1403 var_FreeList( &val_list, &text_list );
1405 #undef RADIO_OR_COMMAND
1408 return submenu->isEmpty() ? VLC_EGENERIC : VLC_SUCCESS;
1411 void QVLCMenu::CreateAndConnect( QMenu *menu, const char *psz_var,
1412 const QString& text, const QString& help,
1413 int i_item_type, vlc_object_t *p_obj,
1414 vlc_value_t val, int i_val_type,
1417 QAction *action = FindActionWithVar( menu, psz_var );
1422 action = new QAction( text, menu );
1423 menu->addAction( action );
1427 action->setToolTip( help );
1428 action->setEnabled( p_obj != NULL );
1430 if( i_item_type == ITEM_CHECK )
1432 action->setCheckable( true );
1434 else if( i_item_type == ITEM_RADIO )
1436 action->setCheckable( true );
1438 currentGroup = new QActionGroup( menu );
1439 currentGroup->addAction( action );
1442 action->setChecked( checked );
1444 MenuItemData *itemData = qFindChild<MenuItemData*>( action, QString() );
1446 itemData = new MenuItemData( action, p_obj, i_val_type, val, psz_var );
1448 /* remove previous signal-slot connection(s) if any */
1449 action->disconnect( );
1451 CONNECT( action, triggered(), THEDP->menusMapper, map() );
1452 THEDP->menusMapper->setMapping( action, itemData );
1455 menu->addAction( action );
1458 void QVLCMenu::DoAction( QObject *data )
1460 MenuItemData *itemData = qobject_cast<MenuItemData *>( data );
1461 vlc_object_t *p_object = itemData->p_obj;
1462 if( p_object == NULL ) return;
1464 /* Preserve settings across vouts via the playlist object: */
1465 if( !strcmp( itemData->psz_var, "fullscreen" )
1466 || !strcmp( itemData->psz_var, "video-on-top" ) )
1467 var_Set( pl_Get( p_object ), itemData->psz_var, itemData->val );
1469 var_Set( p_object, itemData->psz_var, itemData->val );
1472 void QVLCMenu::updateRecents( intf_thread_t *p_intf )
1477 RecentsMRL* rmrl = RecentsMRL::getInstance( p_intf );
1478 QStringList l = rmrl->recents();
1480 recentsMenu->clear();
1484 action = recentsMenu->addAction( qtr(" - Empty - ") );
1485 action->setEnabled( false );
1489 for( int i = 0; i < l.size(); ++i )
1491 char *psz_temp = decode_URI_duplicate( qtu( l.at( i ) ) );
1493 action = recentsMenu->addAction(
1494 QString( "&%1: " ).arg( i + 1 ) +
1495 QApplication::fontMetrics().elidedText( psz_temp, Qt::ElideLeft, 400 ),
1496 rmrl->signalMapper, SLOT( map() ),
1497 i <= 9 ? QString( "Ctrl+%1" ).arg( i + 1 ) : "" );
1498 rmrl->signalMapper->setMapping( action, l.at( i ) );
1503 recentsMenu->addSeparator();
1504 recentsMenu->addAction( qtr("&Clear"), rmrl, SLOT( clear() ) );