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 */
44 #include "main_interface.hpp" /* View modifications */
45 #include "dialogs_provider.hpp" /* Dialogs display */
46 #include "input_manager.hpp" /* Input Management */
47 #include "recents.hpp" /* Recent Items */
48 #include "actions_manager.hpp" /* Actions Management: play+volume */
49 #include "extensions_manager.hpp" /* Extensions menu*/
54 #include <QActionGroup>
55 #include <QSignalMapper>
56 #include <QSystemTrayIcon>
58 #include <QFontMetrics>
61 This file defines the main menus and the pop-up menu (right-click menu)
62 and the systray menu (in that order in the file)
64 There are 4 menus that have to be rebuilt everytime there are called:
65 Audio, Video, Navigation, view
66 4 functions are building those menus: AudioMenu, VideoMenu, NavigMenu, View
67 and 3 functions associated are collecting the objects :
68 InputAutoMenuBuilder, AudioAutoMenuBuilder, VideoAutoMenuBuilder.
70 A QSignalMapper decides when to rebuild those menus cf MenuFunc in the .hpp
71 Just before one of those menus are aboutToShow(), they are rebuild.
74 #define STATIC_ENTRY "__static__"
75 #define ENTRY_ALWAYS_ENABLED "__ignore__"
79 ITEM_NORMAL, /* not a checkbox, nor a radio */
80 ITEM_CHECK, /* Checkbox */
81 ITEM_RADIO /* Radiobox */
84 static QActionGroup *currentGroup;
86 QMenu *QVLCMenu::recentsMenu = NULL;
89 * @brief Add static entries to DP in menus
91 QAction *addDPStaticEntry( QMenu *menu,
95 const char *shortcut = NULL,
96 QAction::MenuRole = QAction::NoRole
99 QAction *action = NULL;
100 #ifndef __APPLE__ /* We don't set icons in menus in MacOS X */
101 if( !EMPTY_STR( icon ) )
103 if( !EMPTY_STR( shortcut ) )
104 action = menu->addAction( QIcon( icon ), text, THEDP,
105 member, qtr( shortcut ) );
107 action = menu->addAction( QIcon( icon ), text, THEDP, member );
112 if( !EMPTY_STR( shortcut ) )
113 action = menu->addAction( text, THEDP, member, qtr( shortcut ) );
115 action = menu->addAction( text, THEDP, member );
117 action->setData( STATIC_ENTRY );
122 * @brief Add static entries to MIM in menus
124 QAction* addMIMStaticEntry( intf_thread_t *p_intf,
129 bool bStatic = false )
132 #ifndef __APPLE__ /* We don't set icons in menus in MacOS X */
133 if( !EMPTY_STR( icon ) )
135 action = menu->addAction( text, THEMIM, member );
136 action->setIcon( QIcon( icon ) );
141 action = menu->addAction( text, THEMIM, member );
143 action->setData( bStatic ? STATIC_ENTRY : ENTRY_ALWAYS_ENABLED );
148 * @brief Enable all static entries of a menu, disable the others
149 * @param menu the menu in which the entries will be disabled
150 * @param enable if false, disable all entries
152 void EnableStaticEntries( QMenu *menu, bool enable = true )
156 QList< QAction* > actions = menu->actions();
157 for( int i = 0; i < actions.count(); ++i )
159 actions[i]->setEnabled( actions[i]->data().toString()
160 == ENTRY_ALWAYS_ENABLED ||
161 /* Be careful here, because data("string").toBool is true */
162 ( enable && (actions[i]->data().toString() == STATIC_ENTRY ) ) );
167 * \return Number of static entries
169 inline int DeleteNonStaticEntries( QMenu *menu )
171 if( !menu ) return VLC_EGENERIC;
175 QList< QAction* > actions = menu->actions();
176 for( int i = 0; i < actions.count(); ++i )
178 if( actions[i]->data().toString() != STATIC_ENTRY )
187 * \return QAction associated to psz_var variable
189 static QAction * FindActionWithVar( QMenu *menu, const char *psz_var )
191 QList< QAction* > actions = menu->actions();
192 for( int i = 0; i < actions.count(); ++i )
194 if( actions[i]->data().toString() == psz_var )
200 /*****************************************************************************
201 * Definitions of variables for the dynamic menus
202 *****************************************************************************/
203 #define PUSH_VAR( var ) varnames.append( var ); \
204 objects.append( VLC_OBJECT(p_object) )
206 #define PUSH_INPUTVAR( var ) varnames.append( var ); \
207 objects.append( VLC_OBJECT(p_input) );
209 static int InputAutoMenuBuilder( input_thread_t *p_object,
210 QVector<vlc_object_t *> &objects,
211 QVector<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 QVector<vlc_object_t *> &objects,
224 QVector<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( audio_output_t *p_object,
247 input_thread_t *p_input,
248 QVector<vlc_object_t *> &objects,
249 QVector<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 QMenu *addActionWithSubmenu( QMenu *_menu, QVariant val, QString title ) {
285 QAction *_action = new QAction( title, _menu );
286 QMenu *_submenu = new QMenu( _menu );
287 _action->setData( val );
288 _action->setMenu( _submenu );
289 _menu->addAction( _action );
293 // Add an action that is a checkbox
294 static inline void addActionWithCheckbox( QMenu *_menu, QVariant val, QString title ) {
295 QAction *_action = new QAction( title, _menu );
296 _action->setData( val );
297 _action->setCheckable( true );
298 _menu->addAction( _action );
302 * Main Menu Bar Creation
304 void QVLCMenu::createMenuBar( MainInterface *mi,
305 intf_thread_t *p_intf )
307 /* QMainWindows->menuBar()
308 gives the QProcess::destroyed timeout issue on Cleanlooks style with
309 setDesktopAware set to false */
310 QMenuBar *bar = mi->menuBar();
312 addMenuToMainbar( FileMenu( p_intf, bar, mi ), qtr( "&Media" ), bar );
314 /* Dynamic menus, rebuilt before being showed */
315 BAR_DADD( NavigMenu( p_intf, bar ), qtr( "P&layback" ), 3 );
316 BAR_DADD( AudioMenu( p_intf, bar ), qtr( "&Audio" ), 1 );
317 BAR_DADD( VideoMenu( p_intf, bar ), qtr( "&Video" ), 2 );
319 addMenuToMainbar( ToolsMenu( bar ), qtr( "&Tools" ), bar );
321 /* View menu, a bit different */
322 BAR_DADD( ViewMenu( p_intf, NULL, mi ), qtr( "V&iew" ), 4 );
324 addMenuToMainbar( HelpMenu( bar ), qtr( "&Help" ), bar );
329 * Media ( File ) Menu
330 * Opening, streaming and quit
332 QMenu *QVLCMenu::FileMenu( intf_thread_t *p_intf, QWidget *parent, MainInterface *mi )
334 QMenu *menu = new QMenu( parent );
337 addDPStaticEntry( menu, qtr( "Open &File..." ),
338 ":/type/file-asym", SLOT( simpleOpenDialog() ), "Ctrl+O" );
339 addDPStaticEntry( menu, qtr( I_OP_OPDIR ),
340 ":/type/folder-grey", SLOT( PLOpenDir() ), "Ctrl+F" );
341 addDPStaticEntry( menu, qtr( "Open &Disc..." ),
342 ":/type/disc", SLOT( openDiscDialog() ), "Ctrl+D" );
343 addDPStaticEntry( menu, qtr( "Open &Network Stream..." ),
344 ":/type/network", SLOT( openNetDialog() ), "Ctrl+N" );
345 addDPStaticEntry( menu, qtr( "Open &Capture Device..." ),
346 ":/type/capture-card", SLOT( openCaptureDialog() ), "Ctrl+C" );
348 menu->addSeparator();
350 addDPStaticEntry( menu, qtr( "&Open (advanced)..." ),
351 ":/type/file-asym", SLOT( openFileDialog() ), "Ctrl+Shift+O" );
352 menu->addSeparator();
354 addDPStaticEntry( menu, qtr( "Open &Location from clipboard" ),
355 NULL, SLOT( openUrlDialog() ), "Ctrl+V" );
357 if( var_InheritBool( p_intf, "qt-recentplay" ) )
359 recentsMenu = new QMenu( qtr( "Open &Recent Media" ), menu );
360 updateRecents( p_intf );
361 menu->addMenu( recentsMenu );
363 menu->addSeparator();
365 addDPStaticEntry( menu, qtr( I_PL_SAVE ), "", SLOT( saveAPlaylist() ),
367 menu->addSeparator();
370 addDPStaticEntry( menu, qtr( "Conve&rt / Save..." ), "",
371 SLOT( openAndTranscodingDialogs() ), "Ctrl+R" );
372 addDPStaticEntry( menu, qtr( "&Stream..." ),
373 ":/menu/stream", SLOT( openAndStreamingDialogs() ), "Ctrl+S" );
374 menu->addSeparator();
377 action = addMIMStaticEntry( p_intf, menu, qtr( "Quit at the end of playlist" ), "",
378 SLOT( activatePlayQuit( bool ) ) );
379 action->setCheckable( true );
380 action->setChecked( THEMIM->getPlayExitState() );
382 if( mi->getSysTray() )
384 action = menu->addAction( qtr( "Close to systray"), mi,
385 SLOT( toggleUpdateSystrayMenu() ) );
388 addDPStaticEntry( menu, qtr( "&Quit" ) ,
389 ":/menu/quit", SLOT( quit() ), "Ctrl+Q" );
394 * Tools, like Media Information, Preferences or Messages
396 QMenu *QVLCMenu::ToolsMenu( QMenu *menu )
398 addDPStaticEntry( menu, qtr( "&Effects and Filters"), ":/menu/settings",
399 SLOT( extendedDialog() ), "Ctrl+E" );
401 addDPStaticEntry( menu, qtr( "&Track Synchronization"), ":/menu/settings",
402 SLOT( synchroDialog() ), "" );
404 addDPStaticEntry( menu, qtr( I_MENU_INFO ) , ":/menu/info",
405 SLOT( mediaInfoDialog() ), "Ctrl+I" );
406 addDPStaticEntry( menu, qtr( I_MENU_CODECINFO ) ,
407 ":/menu/info", SLOT( mediaCodecDialog() ), "Ctrl+J" );
410 addDPStaticEntry( menu, qtr( I_MENU_VLM ), "", SLOT( vlmDialog() ),
414 addDPStaticEntry( menu, qtr( "Program Guide" ), "", SLOT( epgDialog() ),
417 addDPStaticEntry( menu, qtr( I_MENU_MSG ),
418 ":/menu/messages", SLOT( messagesDialog() ), "Ctrl+M" );
420 addDPStaticEntry( menu, qtr( "Plu&gins and extensions" ),
421 "", SLOT( pluginDialog() ) );
422 menu->addSeparator();
424 addDPStaticEntry( menu, qtr( "Customi&ze Interface..." ),
425 ":/menu/preferences", SLOT( toolbarDialog() ) );
427 addDPStaticEntry( menu, qtr( "&Preferences" ),
428 ":/menu/preferences", SLOT( prefsDialog() ), "Ctrl+P", QAction::PreferencesRole );
435 * Interface modification, load other interfaces, activate Extensions
436 * \param current, set to NULL for menu creation, else for menu update
438 QMenu *QVLCMenu::ViewMenu( intf_thread_t *p_intf, QMenu *current, MainInterface *_mi )
443 MainInterface *mi = _mi ? _mi : p_intf->p_sys->p_mi;
448 menu = new QMenu( qtr( "&View" ), mi );
454 //HACK menu->clear() does not delete submenus
455 QList<QAction*> actions = menu->actions();
456 foreach( QAction *a, actions )
458 QMenu *m = a->menu();
459 if( a->parent() == menu ) delete a;
460 else menu->removeAction( a );
461 if( m && m->parent() == menu ) delete m;
467 QIcon( ":/menu/playlist_menu" ),
469 qtr( "Play&list" ), mi,
470 SLOT( togglePlaylist() ), qtr( "Ctrl+L" ) );
472 menu->addSeparator();
475 action = menu->addAction( qtr( "Mi&nimal Interface" ) );
476 action->setShortcut( qtr( "Ctrl+H" ) );
477 action->setCheckable( true );
478 action->setChecked( (mi->getControlsVisibilityStatus() & CONTROLS_HIDDEN ) );
480 CONNECT( action, triggered( bool ), mi, toggleMinimalView( bool ) );
481 CONNECT( mi, minimalViewToggled( bool ), action, setChecked( bool ) );
483 /* FullScreen View */
484 action = menu->addAction( qtr( "&Fullscreen Interface" ), mi,
485 SLOT( toggleInterfaceFullScreen() ), QString( "F11" ) );
486 action->setCheckable( true );
487 action->setChecked( mi->isInterfaceFullScreen() );
488 CONNECT( mi, fullscreenInterfaceToggled( bool ),
489 action, setChecked( bool ) );
491 /* Advanced Controls */
492 action = menu->addAction( qtr( "&Advanced Controls" ), mi,
493 SLOT( toggleAdvancedButtons() ) );
494 action->setCheckable( true );
495 if( mi->getControlsVisibilityStatus() & CONTROLS_ADVANCED )
496 action->setChecked( true );
498 /* Docked Playlist */
499 action = menu->addAction( qtr( "Docked Playlist" ) );
500 action->setCheckable( true );
501 action->setChecked( mi->isPlDocked() );
502 CONNECT( action, triggered( bool ), mi, dockPlaylist( bool ) );
504 action = menu->addAction( qtr( "Status Bar" ) );
505 action->setCheckable( true );
506 action->setChecked( mi->statusBar()->isVisible() );
507 CONNECT( action, triggered( bool ), mi, setStatusBarVisibility( bool) );
508 #if 0 /* For Visualisations. Not yet working */
509 adv = menu->addAction( qtr( "Visualizations selector" ), mi,
511 adv->setCheckable( true );
512 if( visual_selector_enabled ) adv->setChecked( true );
515 menu->addSeparator();
517 InterfacesMenu( p_intf, menu );
518 menu->addSeparator();
521 ExtensionsMenu( p_intf, menu );
527 * Interface Sub-Menu, to list extras interface and skins
529 QMenu *QVLCMenu::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
531 QVector<vlc_object_t *> objects;
532 QVector<const char *> varnames;
533 varnames.append( "intf-add" );
534 objects.append( VLC_OBJECT(p_intf) );
536 return Populate( p_intf, current, varnames, objects );
540 * Extensions menu: populate the current menu with extensions
542 void QVLCMenu::ExtensionsMenu( intf_thread_t *p_intf, QMenu *extMenu )
544 /* Get ExtensionsManager and load extensions if needed */
545 ExtensionsManager *extMgr = ExtensionsManager::getInstance( p_intf );
547 if( !var_InheritBool( p_intf, "qt-autoload-extensions")
548 && !extMgr->isLoaded() )
553 if( !extMgr->isLoaded() && !extMgr->cannotLoad() )
555 extMgr->loadExtensions();
558 /* Let the ExtensionsManager build itself the menu */
559 extMenu->addSeparator();
560 extMgr->menu( extMenu );
566 QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QMenu * current )
568 QVector<vlc_object_t *> objects;
569 QVector<const char *> varnames;
570 audio_output_t *p_aout;
571 input_thread_t *p_input;
573 if( current->isEmpty() )
575 addActionWithSubmenu( current, "audio-es", qtr( "Audio &Track" ) );
576 addActionWithSubmenu( current, "audio-channels", qtr( "Audio &Channels" ) );
577 addActionWithSubmenu( current, "audio-device", qtr( "Audio &Device" ) );
578 current->addSeparator();
580 addActionWithSubmenu( current, "visual", qtr( "&Visualizations" ) );
581 current->addSeparator();
583 QAction *action = current->addAction( qtr( "Increase Volume" ),
584 ActionsManager::getInstance( p_intf ), SLOT( AudioUp() ) );
585 action->setData( STATIC_ENTRY );
586 action = current->addAction( qtr( "Decrease Volume" ),
587 ActionsManager::getInstance( p_intf ), SLOT( AudioDown() ) );
588 action->setData( STATIC_ENTRY );
589 action = current->addAction( qtr( "Mute" ),
590 ActionsManager::getInstance( p_intf ), SLOT( toggleMuteAudio() ) );
591 action->setData( STATIC_ENTRY );
594 p_input = THEMIM->getInput();
595 p_aout = THEMIM->getAout();
596 EnableStaticEntries( current, ( p_aout != NULL ) );
597 AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
600 vlc_object_release( p_aout );
603 return Populate( p_intf, current, varnames, objects );
607 QMenu *QVLCMenu::SubtitleMenu( QMenu *current )
610 QMenu *submenu = new QMenu( qtr( "&Subtitles Track" ), current );
611 action = current->addMenu( submenu );
612 action->setData( "spu-es" );
613 addDPStaticEntry( submenu, qtr( "Open File..." ), "",
614 SLOT( loadSubtitlesFile() ) );
615 submenu->addSeparator();
621 * Subtitles are part of Video.
623 QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current, bool b_subtitle )
625 vout_thread_t *p_vout;
626 input_thread_t *p_input;
627 QVector<vlc_object_t *> objects;
628 QVector<const char *> varnames;
630 if( current->isEmpty() )
632 addActionWithSubmenu( current, "video-es", qtr( "Video &Track" ) );
634 SubtitleMenu( current );
636 current->addSeparator();
637 /* Surface modifiers */
638 addActionWithCheckbox( current, "fullscreen", qtr( "&Fullscreen" ) );
639 addActionWithCheckbox( current, "autoscale", qtr( "Always Fit &Window" ) );
640 addActionWithCheckbox( current, "video-on-top", qtr( "Always &on Top" ) );
642 addActionWithCheckbox( current, "direct3d-desktop", qtr( "Display on &Desktop" ) );
646 addActionWithCheckbox( current, "video-wallpaper", qtr( "Set as Wall&paper" ) );
648 current->addSeparator();
650 addActionWithSubmenu( current, "zoom", qtr( "&Zoom" ) );
651 addActionWithSubmenu( current, "aspect-ratio", qtr( "&Aspect Ratio" ) );
652 addActionWithSubmenu( current, "crop", qtr( "&Crop" ) );
654 current->addSeparator();
655 /* Rendering modifiers */
656 addActionWithSubmenu( current, "deinterlace", qtr( "&Deinterlace" ) );
657 addActionWithSubmenu( current, "deinterlace-mode", qtr( "&Deinterlace mode" ) );
658 addActionWithSubmenu( current, "postprocess", qtr( "&Post processing" ) );
660 current->addSeparator();
662 addAction( current, "video-snapshot", qtr( "Take &Snapshot" ) );
665 p_input = THEMIM->getInput();
667 p_vout = THEMIM->getVout();
668 VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
671 vlc_object_release( p_vout );
673 return Populate( p_intf, current, varnames, objects );
678 * For DVD, MP4, MOV and other chapter based format
680 QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *menu )
685 addActionWithSubmenu( menu, "title", qtr( "T&itle" ) );
686 addActionWithSubmenu( menu, "chapter", qtr( "&Chapter" ) );
687 submenu = addActionWithSubmenu( menu, "navigation", qtr( "&Navigation" ) );
688 submenu->setTearOffEnabled( true );
689 addActionWithSubmenu( menu, "program", qtr( "&Program" ) );
691 /* FixMe: sync I_MENU_BOOKMARK string */
692 submenu = new QMenu( qtr( "Custom &Bookmarks" ), menu );
693 submenu->setTearOffEnabled( true );
694 addDPStaticEntry( submenu, qtr( "&Manage" ), "",
695 SLOT( bookmarksDialog() ), "Ctrl+B" );
696 submenu->addSeparator();
697 action = menu->addMenu( submenu );
698 action->setData( "bookmark" );
700 menu->addSeparator();
701 PopupMenuPlaylistControlEntries( menu, p_intf );
702 PopupMenuControlEntries( menu, p_intf );
704 EnableStaticEntries( menu, ( THEMIM->getInput() != NULL ) );
705 return RebuildNavigMenu( p_intf, menu );
708 QMenu *QVLCMenu::RebuildNavigMenu( intf_thread_t *p_intf, QMenu *menu )
711 input_thread_t *p_object;
712 QVector<vlc_object_t *> objects;
713 QVector<const char *> varnames;
715 /* Get the input and hold it */
716 p_object = THEMIM->getInput();
718 InputAutoMenuBuilder( p_object, objects, varnames );
720 menu->addSeparator();
722 /* Title and so on */
723 PUSH_VAR( "prev-title" );
724 PUSH_VAR( "next-title" );
725 PUSH_VAR( "prev-chapter" );
726 PUSH_VAR( "next-chapter" );
728 EnableStaticEntries( menu, (p_object != NULL ) );
729 return Populate( p_intf, menu, varnames, objects );
735 QMenu *QVLCMenu::HelpMenu( QWidget *parent )
737 QMenu *menu = new QMenu( parent );
738 addDPStaticEntry( menu, qtr( "&Help..." ) ,
739 ":/menu/help", SLOT( helpDialog() ), "F1" );
741 addDPStaticEntry( menu, qtr( "Check for &Updates..." ) , "",
742 SLOT( updateDialog() ) );
744 menu->addSeparator();
745 addDPStaticEntry( menu, qtr( I_MENU_ABOUT ), ":/menu/info",
746 SLOT( aboutDialog() ), "Shift+F1", QAction::AboutRole );
750 /*****************************************************************************
751 * Popup menus - Right Click menus *
752 *****************************************************************************/
753 #define POPUP_BOILERPLATE \
754 static QMenu* menu = NULL; \
755 delete menu; menu = NULL; \
758 QVector<vlc_object_t *> objects; \
759 QVector<const char *> varnames; \
760 input_thread_t *p_input = THEMIM->getInput();
762 #define CREATE_POPUP \
763 menu = new QMenu(); \
764 Populate( p_intf, menu, varnames, objects ); \
765 menu->popup( QCursor::pos() ); \
767 void QVLCMenu::PopupPlayEntries( QMenu *menu,
768 intf_thread_t *p_intf,
769 input_thread_t *p_input )
773 /* Play or Pause action and icon */
774 if( !p_input || var_GetInteger( p_input, "state" ) != PLAYING_S )
776 action = menu->addAction( qtr( "Play" ),
777 ActionsManager::getInstance( p_intf ), SLOT( play() ) );
778 #ifndef __APPLE__ /* No icons in menus in Mac */
779 action->setIcon( QIcon( ":/menu/play" ) );
784 addMIMStaticEntry( p_intf, menu, qtr( "Pause" ),
785 ":/menu/pause", SLOT( togglePlayPause() ) );
789 void QVLCMenu::PopupMenuControlEntries( QMenu *menu, intf_thread_t *p_intf )
794 action = menu->addAction( qtr( "&Faster" ), THEMIM->getIM(),
796 #ifndef __APPLE__ /* No icons in menus in Mac */
797 action->setIcon( QIcon( ":/toolbar/faster") );
799 action->setData( STATIC_ENTRY );
801 action = menu->addAction( qtr( "Faster (fine)" ), THEMIM->getIM(),
802 SLOT( littlefaster() ) );
803 action->setData( STATIC_ENTRY );
805 action = menu->addAction( qtr( "N&ormal Speed" ), THEMIM->getIM(),
806 SLOT( normalRate() ) );
807 action->setData( STATIC_ENTRY );
809 action = menu->addAction( qtr( "Slower (fine)" ), THEMIM->getIM(),
810 SLOT( littleslower() ) );
811 action->setData( STATIC_ENTRY );
813 action = menu->addAction( qtr( "Slo&wer" ), THEMIM->getIM(),
815 #ifndef __APPLE__ /* No icons in menus in Mac */
816 action->setIcon( QIcon( ":/toolbar/slower") );
818 action->setData( STATIC_ENTRY );
820 menu->addSeparator();
822 action = menu->addAction( qtr( "&Jump Forward" ), THEMIM->getIM(),
824 #ifndef __APPLE__ /* No icons in menus in Mac */
825 action->setIcon( QIcon( ":/toolbar/skip_fw") );
827 action->setData( STATIC_ENTRY );
829 action = menu->addAction( qtr( "Jump Bac&kward" ), THEMIM->getIM(),
831 #ifndef __APPLE__ /* No icons in menus in Mac */
832 action->setIcon( QIcon( ":/toolbar/skip_back") );
834 action->setData( STATIC_ENTRY );
835 addDPStaticEntry( menu, qtr( I_MENU_GOTOTIME ),"",
836 SLOT( gotoTimeDialog() ), "Ctrl+T" );
837 menu->addSeparator();
841 void QVLCMenu::PopupMenuPlaylistControlEntries( QMenu *menu,
842 intf_thread_t *p_intf )
844 bool bEnable = THEMIM->getInput() != NULL;
846 addMIMStaticEntry( p_intf, menu, qtr( "&Stop" ), ":/menu/stop",
847 SLOT( stop() ), true );
848 /* Disable Stop in the right-click popup menu */
850 action->setEnabled( false );
852 /* Next / Previous */
853 addMIMStaticEntry( p_intf, menu, qtr( "Pre&vious" ),
854 ":/menu/previous", SLOT( prev() ) );
855 addMIMStaticEntry( p_intf, menu, qtr( "Ne&xt" ),
856 ":/menu/next", SLOT( next() ) );
858 menu->addSeparator();
861 void QVLCMenu::PopupMenuStaticEntries( QMenu *menu )
863 QMenu *openmenu = new QMenu( qtr( "Open a Media" ), menu );
864 addDPStaticEntry( openmenu, qtr( "&Open File..." ),
865 ":/type/file-asym", SLOT( openFileDialog() ) );
866 addDPStaticEntry( openmenu, qtr( I_OP_OPDIR ),
867 ":/type/folder-grey", SLOT( PLOpenDir() ) );
868 addDPStaticEntry( openmenu, qtr( "Open &Disc..." ),
869 ":/type/disc", SLOT( openDiscDialog() ) );
870 addDPStaticEntry( openmenu, qtr( "Open &Network..." ),
871 ":/type/network", SLOT( openNetDialog() ) );
872 addDPStaticEntry( openmenu, qtr( "Open &Capture Device..." ),
873 ":/type/capture-card", SLOT( openCaptureDialog() ) );
874 menu->addMenu( openmenu );
876 menu->addSeparator();
878 QMenu *helpmenu = HelpMenu( menu );
879 helpmenu->setTitle( qtr( "Help" ) );
880 menu->addMenu( helpmenu );
883 addDPStaticEntry( menu, qtr( "Quit" ), ":/menu/quit",
884 SLOT( quit() ), "Ctrl+Q", QAction::QuitRole );
887 /* Video Tracks and Subtitles tracks */
888 void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf, bool show )
893 vout_thread_t *p_vout = THEMIM->getVout();
896 VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
897 vlc_object_release( p_vout );
904 void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf, bool show )
909 audio_output_t *p_aout = THEMIM->getAout();
910 AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
912 vlc_object_release( p_aout );
917 /* Navigation stuff, and general menus ( open ), used only for skins */
918 void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf, bool show )
924 varnames.append( "audio-es" );
925 InputAutoMenuBuilder( p_input, objects, varnames );
926 menu->addSeparator();
930 Populate( p_intf, menu, varnames, objects );
932 menu->addSeparator();
933 PopupPlayEntries( menu, p_intf, p_input );
934 PopupMenuPlaylistControlEntries( menu, p_intf);
936 menu->addSeparator();
937 PopupMenuControlEntries( menu, p_intf );
939 menu->addSeparator();
940 PopupMenuStaticEntries( menu );
942 menu->popup( QCursor::pos() );
945 /* Main Menu that sticks everything together */
946 void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show )
953 bool b_isFullscreen = false;
954 MainInterface *mi = p_intf->p_sys->p_mi;
956 PopupPlayEntries( menu, p_intf, p_input );
957 PopupMenuPlaylistControlEntries( menu, p_intf );
958 menu->addSeparator();
963 vout_thread_t *p_vout = THEMIM->getVout();
965 /* Add a fullscreen switch button, since it is the most used function */
968 vlc_value_t val; var_Get( p_vout, "fullscreen", &val );
970 b_isFullscreen = !( !val.b_bool );
974 CreateAndConnect( menu, "fullscreen",
975 qtr( "Leave Fullscreen" ),"" , ITEM_NORMAL,
976 VLC_OBJECT(p_vout), val, VLC_VAR_BOOL, b_isFullscreen );
978 vlc_object_release( p_vout );
980 menu->addSeparator();
984 InputAutoMenuBuilder( p_input, objects, varnames );
987 submenu = new QMenu( menu );
988 action = menu->addMenu( AudioMenu( p_intf, submenu ) );
989 action->setText( qtr( "&Audio" ) );
990 if( action->menu()->isEmpty() )
991 action->setEnabled( false );
994 submenu = new QMenu( menu );
995 action = menu->addMenu( VideoMenu( p_intf, submenu, false ) );
996 action->setText( qtr( "&Video" ) );
997 if( action->menu()->isEmpty() )
998 action->setEnabled( false );
1000 submenu = SubtitleMenu( menu );
1001 submenu->setTitle( qtr( "Subti&tle") );
1002 UpdateItem( p_intf, menu, "spu-es", VLC_OBJECT(p_input), true );
1004 /* Playback menu for chapters */
1005 submenu = new QMenu( menu );
1006 action = menu->addMenu( NavigMenu( p_intf, submenu ) );
1007 action->setText( qtr( "&Playback" ) );
1008 if( action->menu()->isEmpty() )
1009 action->setEnabled( false );
1012 menu->addSeparator();
1014 /* Add some special entries for windowed mode: Interface Menu */
1015 if( !b_isFullscreen )
1017 QMenu *submenu = new QMenu( qtr( "Tools" ), menu );
1018 /*QMenu *tools =*/ ToolsMenu( submenu );
1019 submenu->addSeparator();
1021 /* In skins interface, append some items */
1024 submenu->setTitle( qtr( "Interface" ) );
1025 if( p_intf->p_sys->b_isDialogProvider )
1027 vlc_object_t* p_object = p_intf->p_parent;
1029 objects.clear(); varnames.clear();
1030 objects.append( p_object );
1031 varnames.append( "intf-skins" );
1032 Populate( p_intf, submenu, varnames, objects );
1034 objects.clear(); varnames.clear();
1035 objects.append( p_object );
1036 varnames.append( "intf-skins-interactive" );
1037 Populate( p_intf, submenu, varnames, objects );
1040 msg_Warn( p_intf, "could not find parent interface" );
1044 QMenu *bar = menu; // Needed for next macro
1045 BAR_DADD( ViewMenu( p_intf, NULL, mi ), qtr( "V&iew" ), 4 );
1048 menu->addMenu( submenu );
1051 /* Static entries for ending, like open */
1052 PopupMenuStaticEntries( menu );
1054 menu->popup( QCursor::pos() );
1058 #undef POPUP_BOILERPLATE
1062 /************************************************************************
1064 ************************************************************************/
1066 void QVLCMenu::updateSystrayMenu( MainInterface *mi,
1067 intf_thread_t *p_intf,
1068 bool b_force_visible )
1070 input_thread_t *p_input = THEMIM->getInput();
1072 /* Get the systray menu and clean it */
1073 QMenu *sysMenu = mi->getSysTrayMenu();
1077 /* Hide / Show VLC and cone */
1078 if( mi->isVisible() || b_force_visible )
1080 sysMenu->addAction( QIcon( ":/logo/vlc16.png" ),
1081 qtr( "Hide VLC media player in taskbar" ), mi,
1082 SLOT( hideUpdateSystrayMenu() ) );
1086 sysMenu->addAction( QIcon( ":/logo/vlc16.png" ),
1087 qtr( "Show VLC media player" ), mi,
1088 SLOT( showUpdateSystrayMenu() ) );
1090 sysMenu->addSeparator();
1093 PopupPlayEntries( sysMenu, p_intf, p_input );
1094 PopupMenuPlaylistControlEntries( sysMenu, p_intf);
1095 PopupMenuControlEntries( sysMenu, p_intf);
1097 addDPStaticEntry( sysMenu, qtr( "&Open a Media" ),
1098 ":/type/file-wide", SLOT( openFileDialog() ) );
1099 addDPStaticEntry( sysMenu, qtr( "&Quit" ) ,
1100 ":/menu/quit", SLOT( quit() ) );
1103 mi->getSysTray()->setContextMenu( sysMenu );
1110 /*************************************************************************
1111 * Builders for automenus
1112 *************************************************************************/
1113 QMenu * QVLCMenu::Populate( intf_thread_t *p_intf,
1115 QVector< const char *> & varnames,
1116 QVector<vlc_object_t *> & objects )
1118 QMenu *menu = current;
1121 currentGroup = NULL;
1123 for( int i = 0; i < (int)objects.count() ; i++ )
1125 if( !varnames[i] || !*varnames[i] )
1127 menu->addSeparator();
1131 UpdateItem( p_intf, menu, varnames[i], objects[i], true );
1136 /*****************************************************************************
1138 *****************************************************************************/
1140 static bool IsMenuEmpty( const char *psz_var,
1141 vlc_object_t *p_object,
1142 bool b_root = true )
1144 vlc_value_t val, val_list;
1145 int i_type, i_result, i;
1147 /* Check the type of the object variable */
1148 i_type = var_Type( p_object, psz_var );
1150 /* Check if we want to display the variable */
1151 if( !( i_type & VLC_VAR_HASCHOICE ) ) return false;
1153 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
1154 if( val.i_int == 0 ) return true;
1156 if( ( i_type & VLC_VAR_TYPE ) != VLC_VAR_VARIABLE )
1158 if( val.i_int == 1 && b_root ) return true;
1162 /* Check children variables in case of VLC_VAR_VARIABLE */
1163 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
1168 for( i = 0, i_result = true; i < val_list.p_list->i_count; i++ )
1170 if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
1178 /* clean up everything */
1179 var_FreeList( &val_list, NULL );
1184 #define TEXT_OR_VAR qfu ( text.psz_string ? text.psz_string : psz_var )
1186 void QVLCMenu::UpdateItem( intf_thread_t *p_intf, QMenu *menu,
1187 const char *psz_var, vlc_object_t *p_object, bool b_submenu )
1189 vlc_value_t val, text;
1192 QAction *action = FindActionWithVar( menu, psz_var );
1194 DeleteNonStaticEntries( action->menu() );
1199 action->setEnabled( false );
1203 /* Check the type of the object variable */
1204 /* This HACK is needed so we have a radio button for audio and video tracks
1205 instread of a checkbox */
1206 if( !strcmp( psz_var, "audio-es" )
1207 || !strcmp( psz_var, "video-es" ) )
1208 i_type = VLC_VAR_INTEGER | VLC_VAR_HASCHOICE;
1210 i_type = var_Type( p_object, psz_var );
1212 switch( i_type & VLC_VAR_TYPE )
1216 case VLC_VAR_VARIABLE:
1217 case VLC_VAR_STRING:
1218 case VLC_VAR_INTEGER:
1222 /* Variable doesn't exist or isn't handled */
1224 action->setEnabled( false );
1228 /* Make sure we want to display the variable */
1229 if( menu->isEmpty() && IsMenuEmpty( psz_var, p_object ) )
1232 action->setEnabled( false );
1236 /* Get the descriptive name of the variable */
1237 int i_ret = var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
1238 if( i_ret != VLC_SUCCESS )
1240 text.psz_string = NULL;
1245 action = new QAction( TEXT_OR_VAR, menu );
1246 menu->addAction( action );
1247 action->setData( psz_var );
1250 /* Some specific stuff */
1251 bool forceDisabled = false;
1252 if( !strcmp( psz_var, "spu-es" ) )
1254 vout_thread_t *p_vout = THEMIM->getVout();
1255 forceDisabled = ( p_vout == NULL );
1257 vlc_object_release( p_vout );
1260 if( i_type & VLC_VAR_HASCHOICE )
1262 /* Append choices menu */
1266 submenu = action->menu();
1269 submenu = new QMenu( menu );
1270 action->setMenu( submenu );
1274 CreateChoicesMenu( submenu, psz_var, p_object, true ) == 0 );
1276 action->setEnabled( false );
1281 CreateChoicesMenu( menu, psz_var, p_object, true ) == 0 );
1283 FREENULL( text.psz_string );
1287 switch( i_type & VLC_VAR_TYPE )
1290 val.i_int = 0; // Prevent the copy of an uninitialized value
1291 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_NORMAL,
1292 p_object, val, i_type );
1296 var_Get( p_object, psz_var, &val );
1297 val.b_bool = !val.b_bool;
1298 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_CHECK,
1299 p_object, val, i_type, !val.b_bool );
1302 FREENULL( text.psz_string );
1307 /** HACK for the navigation submenu:
1308 * "title %2i" variables take the value 0 if not set
1310 static bool CheckTitle( vlc_object_t *p_object, const char *psz_var )
1313 if( sscanf( psz_var, "title %2i", &i_title ) <= 0 )
1316 int i_current_title = var_GetInteger( p_object, "title" );
1317 return ( i_title == i_current_title );
1321 int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
1322 vlc_object_t *p_object, bool b_root )
1324 vlc_value_t val, val_list, text_list;
1327 /* Check the type of the object variable */
1328 i_type = var_Type( p_object, psz_var );
1330 /* Make sure we want to display the variable */
1331 if( submenu->isEmpty() && IsMenuEmpty( psz_var, p_object, b_root ) )
1332 return VLC_EGENERIC;
1334 switch( i_type & VLC_VAR_TYPE )
1338 case VLC_VAR_VARIABLE:
1339 case VLC_VAR_STRING:
1340 case VLC_VAR_INTEGER:
1344 /* Variable doesn't exist or isn't handled */
1345 return VLC_EGENERIC;
1348 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
1349 &val_list, &text_list ) < 0 )
1351 return VLC_EGENERIC;
1354 #define CURVAL val_list.p_list->p_values[i]
1355 #define CURTEXT text_list.p_list->p_values[i].psz_string
1356 #define RADIO_OR_COMMAND ( i_type & VLC_VAR_ISCOMMAND ) ? ITEM_NORMAL : ITEM_RADIO
1358 for( i = 0; i < val_list.p_list->i_count; i++ )
1360 vlc_value_t another_val;
1362 QMenu *subsubmenu = new QMenu( submenu );
1364 switch( i_type & VLC_VAR_TYPE )
1366 case VLC_VAR_VARIABLE:
1367 CreateChoicesMenu( subsubmenu, CURVAL.psz_string, p_object, false );
1368 subsubmenu->setTitle( qfu( CURTEXT ? CURTEXT :CURVAL.psz_string ) );
1369 submenu->addMenu( subsubmenu );
1372 case VLC_VAR_STRING:
1373 var_Get( p_object, psz_var, &val );
1374 another_val.psz_string = strdup( CURVAL.psz_string );
1375 menutext = qfu( CURTEXT ? CURTEXT : another_val.psz_string );
1376 CreateAndConnect( submenu, psz_var, menutext, "", RADIO_OR_COMMAND,
1377 p_object, another_val, i_type,
1378 val.psz_string && !strcmp( val.psz_string, CURVAL.psz_string ) );
1380 free( val.psz_string );
1383 case VLC_VAR_INTEGER:
1384 var_Get( p_object, psz_var, &val );
1385 if( CURTEXT ) menutext = qfu( CURTEXT );
1386 else menutext = QString::number( CURVAL.i_int );
1387 CreateAndConnect( submenu, psz_var, menutext, "", RADIO_OR_COMMAND,
1388 p_object, CURVAL, i_type,
1389 ( CURVAL.i_int == val.i_int )
1390 && CheckTitle( p_object, psz_var ) );
1394 var_Get( p_object, psz_var, &val );
1395 if( CURTEXT ) menutext = qfu( CURTEXT );
1396 else menutext.sprintf( "%.2f", CURVAL.f_float );
1397 CreateAndConnect( submenu, psz_var, menutext, "", RADIO_OR_COMMAND,
1398 p_object, CURVAL, i_type,
1399 CURVAL.f_float == val.f_float );
1406 currentGroup = NULL;
1408 /* clean up everything */
1409 var_FreeList( &val_list, &text_list );
1411 #undef RADIO_OR_COMMAND
1414 return submenu->isEmpty() ? VLC_EGENERIC : VLC_SUCCESS;
1417 void QVLCMenu::CreateAndConnect( QMenu *menu, const char *psz_var,
1418 const QString& text, const QString& help,
1419 int i_item_type, vlc_object_t *p_obj,
1420 vlc_value_t val, int i_val_type,
1423 QAction *action = FindActionWithVar( menu, psz_var );
1428 action = new QAction( text, menu );
1429 menu->addAction( action );
1433 action->setToolTip( help );
1434 action->setEnabled( p_obj != NULL );
1436 if( i_item_type == ITEM_CHECK )
1438 action->setCheckable( true );
1440 else if( i_item_type == ITEM_RADIO )
1442 action->setCheckable( true );
1444 currentGroup = new QActionGroup( menu );
1445 currentGroup->addAction( action );
1448 action->setChecked( checked );
1450 MenuItemData *itemData = qFindChild<MenuItemData*>( action, QString() );
1452 itemData = new MenuItemData( action, p_obj, i_val_type, val, psz_var );
1454 /* remove previous signal-slot connection(s) if any */
1455 action->disconnect( );
1457 CONNECT( action, triggered(), THEDP->menusMapper, map() );
1458 THEDP->menusMapper->setMapping( action, itemData );
1461 menu->addAction( action );
1464 void QVLCMenu::DoAction( QObject *data )
1466 MenuItemData *itemData = qobject_cast<MenuItemData *>( data );
1467 vlc_object_t *p_object = itemData->p_obj;
1468 if( p_object == NULL ) return;
1470 /* Preserve settings across vouts via the playlist object: */
1471 if( !strcmp( itemData->psz_var, "fullscreen" )
1472 || !strcmp( itemData->psz_var, "video-on-top" ) )
1473 var_Set( pl_Get( p_object ), itemData->psz_var, itemData->val );
1475 var_Set( p_object, itemData->psz_var, itemData->val );
1478 void QVLCMenu::updateRecents( intf_thread_t *p_intf )
1483 RecentsMRL* rmrl = RecentsMRL::getInstance( p_intf );
1484 QStringList l = rmrl->recents();
1486 recentsMenu->clear();
1490 action = recentsMenu->addAction( qtr(" - Empty - ") );
1491 action->setEnabled( false );
1495 for( int i = 0; i < l.count(); ++i )
1497 char *psz_temp = decode_URI_duplicate( qtu( l.at( i ) ) );
1499 action = recentsMenu->addAction(
1500 QString( "&%1: " ).arg( i + 1 ) +
1501 QApplication::fontMetrics().elidedText( psz_temp, Qt::ElideLeft, 400 ),
1502 rmrl->signalMapper, SLOT( map() ),
1503 i <= 9 ? QString( "Ctrl+%1" ).arg( i + 1 ) : "" );
1504 rmrl->signalMapper->setMapping( action, l.at( i ) );
1509 recentsMenu->addSeparator();
1510 recentsMenu->addAction( qtr("&Clear"), rmrl, SLOT( clear() ) );