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.size(); ++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.size(); ++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.size(); ++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.push_back( var ); \
204 objects.push_back( VLC_OBJECT(p_object) )
206 #define PUSH_INPUTVAR( var ) varnames.push_back( var ); \
207 objects.push_back( VLC_OBJECT(p_input) );
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, mi ), 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, NULL, 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, MainInterface *mi )
332 QMenu *menu = new QMenu( parent );
335 addDPStaticEntry( menu, qtr( "Open &File..." ),
336 ":/type/file-asym", SLOT( simpleOpenDialog() ), "Ctrl+O" );
337 addDPStaticEntry( menu, qtr( I_OP_OPDIR ),
338 ":/type/folder-grey", SLOT( PLOpenDir() ), "Ctrl+F" );
339 addDPStaticEntry( menu, qtr( "Open &Disc..." ),
340 ":/type/disc", SLOT( openDiscDialog() ), "Ctrl+D" );
341 addDPStaticEntry( menu, qtr( "Open &Network Stream..." ),
342 ":/type/network", SLOT( openNetDialog() ), "Ctrl+N" );
343 addDPStaticEntry( menu, qtr( "Open &Capture Device..." ),
344 ":/type/capture-card", SLOT( openCaptureDialog() ), "Ctrl+C" );
346 menu->addSeparator();
348 addDPStaticEntry( menu, qtr( "&Open (advanced)..." ),
349 ":/type/file-asym", SLOT( openFileDialog() ), "Ctrl+Shift+O" );
350 menu->addSeparator();
352 addDPStaticEntry( menu, qtr( "Open &Location from clipboard" ),
353 NULL, SLOT( openUrlDialog() ), "Ctrl+V" );
355 if( var_InheritBool( p_intf, "qt-recentplay" ) )
357 recentsMenu = new QMenu( qtr( "Open &Recent Media" ), menu );
358 updateRecents( p_intf );
359 menu->addMenu( recentsMenu );
361 menu->addSeparator();
363 addDPStaticEntry( menu, qtr( I_PL_SAVE ), "", SLOT( saveAPlaylist() ),
365 menu->addSeparator();
368 addDPStaticEntry( menu, qtr( "Conve&rt / Save..." ), "",
369 SLOT( openAndTranscodingDialogs() ), "Ctrl+R" );
370 addDPStaticEntry( menu, qtr( "&Stream..." ),
371 ":/menu/stream", SLOT( openAndStreamingDialogs() ), "Ctrl+S" );
372 menu->addSeparator();
375 action = addMIMStaticEntry( p_intf, menu, qtr( "Quit at the end of playlist" ), "",
376 SLOT( activatePlayQuit( bool ) ) );
377 action->setCheckable( true );
378 action->setChecked( THEMIM->getPlayExitState() );
380 if( mi->getSysTray() )
382 action = menu->addAction( qtr( "Close to systray"), mi,
383 SLOT( toggleUpdateSystrayMenu() ) );
386 addDPStaticEntry( menu, qtr( "&Quit" ) ,
387 ":/menu/quit", SLOT( quit() ), "Ctrl+Q" );
392 * Tools, like Media Information, Preferences or Messages
394 QMenu *QVLCMenu::ToolsMenu( QMenu *menu )
396 addDPStaticEntry( menu, qtr( "&Effects and Filters"), ":/menu/settings",
397 SLOT( extendedDialog() ), "Ctrl+E" );
399 addDPStaticEntry( menu, qtr( "&Track Synchronization"), ":/menu/settings",
400 SLOT( synchroDialog() ), "" );
402 addDPStaticEntry( menu, qtr( I_MENU_INFO ) , ":/menu/info",
403 SLOT( mediaInfoDialog() ), "Ctrl+I" );
404 addDPStaticEntry( menu, qtr( I_MENU_CODECINFO ) ,
405 ":/menu/info", SLOT( mediaCodecDialog() ), "Ctrl+J" );
408 addDPStaticEntry( menu, qtr( I_MENU_VLM ), "", SLOT( vlmDialog() ),
412 addDPStaticEntry( menu, qtr( "Program Guide" ), "", SLOT( epgDialog() ),
415 addDPStaticEntry( menu, qtr( I_MENU_MSG ),
416 ":/menu/messages", SLOT( messagesDialog() ), "Ctrl+M" );
418 addDPStaticEntry( menu, qtr( "Plu&gins and extensions" ),
419 "", SLOT( pluginDialog() ) );
420 menu->addSeparator();
422 addDPStaticEntry( menu, qtr( "Customi&ze Interface..." ),
423 ":/menu/preferences", SLOT( toolbarDialog() ) );
425 addDPStaticEntry( menu, qtr( "&Preferences" ),
426 ":/menu/preferences", SLOT( prefsDialog() ), "Ctrl+P", QAction::PreferencesRole );
433 * Interface modification, load other interfaces, activate Extensions
434 * \param current, set to NULL for menu creation, else for menu update
436 QMenu *QVLCMenu::ViewMenu( intf_thread_t *p_intf, QMenu *current, MainInterface *_mi )
441 MainInterface *mi = _mi ? _mi : p_intf->p_sys->p_mi;
446 menu = new QMenu( qtr( "&View" ), mi );
452 //HACK menu->clear() does not delete submenus
453 QList<QAction*> actions = menu->actions();
454 foreach( QAction *a, actions )
456 QMenu *m = a->menu();
457 if( a->parent() == menu ) delete a;
458 else menu->removeAction( a );
459 if( m && m->parent() == menu ) delete m;
465 QIcon( ":/menu/playlist_menu" ),
467 qtr( "Play&list" ), mi,
468 SLOT( togglePlaylist() ), qtr( "Ctrl+L" ) );
470 menu->addSeparator();
473 action = menu->addAction( qtr( "Mi&nimal Interface" ) );
474 action->setShortcut( qtr( "Ctrl+H" ) );
475 action->setCheckable( true );
476 action->setChecked( (mi->getControlsVisibilityStatus() & CONTROLS_HIDDEN ) );
478 CONNECT( action, triggered( bool ), mi, toggleMinimalView( bool ) );
479 CONNECT( mi, minimalViewToggled( bool ), action, setChecked( bool ) );
481 /* FullScreen View */
482 action = menu->addAction( qtr( "&Fullscreen Interface" ), mi,
483 SLOT( toggleInterfaceFullScreen() ), QString( "F11" ) );
484 action->setCheckable( true );
485 action->setChecked( mi->isInterfaceFullScreen() );
486 CONNECT( mi, fullscreenInterfaceToggled( bool ),
487 action, setChecked( bool ) );
489 /* Advanced Controls */
490 action = menu->addAction( qtr( "&Advanced Controls" ), mi,
491 SLOT( toggleAdvancedButtons() ) );
492 action->setCheckable( true );
493 if( mi->getControlsVisibilityStatus() & CONTROLS_ADVANCED )
494 action->setChecked( true );
496 /* Docked Playlist */
497 action = menu->addAction( qtr( "Docked Playlist" ) );
498 action->setCheckable( true );
499 action->setChecked( mi->isPlDocked() );
500 CONNECT( action, triggered( bool ), mi, dockPlaylist( bool ) );
502 action = menu->addAction( qtr( "Status Bar" ) );
503 action->setCheckable( true );
504 action->setChecked( mi->statusBar()->isVisible() );
505 CONNECT( action, triggered( bool ), mi, setStatusBarVisibility( bool) );
506 #if 0 /* For Visualisations. Not yet working */
507 adv = menu->addAction( qtr( "Visualizations selector" ), mi,
509 adv->setCheckable( true );
510 if( visual_selector_enabled ) adv->setChecked( true );
513 menu->addSeparator();
515 InterfacesMenu( p_intf, menu );
516 menu->addSeparator();
519 ExtensionsMenu( p_intf, menu );
525 * Interface Sub-Menu, to list extras interface and skins
527 QMenu *QVLCMenu::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
529 vector<vlc_object_t *> objects;
530 vector<const char *> varnames;
531 varnames.push_back( "intf-add" );
532 objects.push_back( VLC_OBJECT(p_intf) );
534 return Populate( p_intf, current, varnames, objects );
538 * Extensions menu: populate the current menu with extensions
540 void QVLCMenu::ExtensionsMenu( intf_thread_t *p_intf, QMenu *extMenu )
542 /* Get ExtensionsManager and load extensions if needed */
543 ExtensionsManager *extMgr = ExtensionsManager::getInstance( p_intf );
545 if( !var_InheritBool( p_intf, "qt-autoload-extensions")
546 && !extMgr->isLoaded() )
551 if( !extMgr->isLoaded() && !extMgr->cannotLoad() )
553 extMgr->loadExtensions();
556 /* Let the ExtensionsManager build itself the menu */
557 extMenu->addSeparator();
558 extMgr->menu( extMenu );
564 QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QMenu * current )
566 vector<vlc_object_t *> objects;
567 vector<const char *> varnames;
568 aout_instance_t *p_aout;
569 input_thread_t *p_input;
571 if( current->isEmpty() )
573 addActionWithSubmenu( current, "audio-es", qtr( "Audio &Track" ) );
574 addActionWithSubmenu( current, "audio-channels", qtr( "Audio &Channels" ) );
575 addActionWithSubmenu( current, "audio-device", qtr( "Audio &Device" ) );
576 current->addSeparator();
578 addActionWithSubmenu( current, "visual", qtr( "&Visualizations" ) );
579 current->addSeparator();
581 QAction *action = current->addAction( qtr( "Increase Volume" ),
582 ActionsManager::getInstance( p_intf ), SLOT( AudioUp() ) );
583 action->setData( STATIC_ENTRY );
584 action = current->addAction( qtr( "Decrease Volume" ),
585 ActionsManager::getInstance( p_intf ), SLOT( AudioDown() ) );
586 action->setData( STATIC_ENTRY );
587 action = current->addAction( qtr( "Mute" ),
588 ActionsManager::getInstance( p_intf ), SLOT( toggleMuteAudio() ) );
589 action->setData( STATIC_ENTRY );
592 p_input = THEMIM->getInput();
593 p_aout = THEMIM->getAout();
594 EnableStaticEntries( current, ( p_aout != NULL ) );
595 AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
598 vlc_object_release( p_aout );
601 return Populate( p_intf, current, varnames, objects );
605 QMenu *QVLCMenu::SubtitleMenu( QMenu *current )
608 QMenu *submenu = new QMenu( qtr( "&Subtitles Track" ), current );
609 action = current->addMenu( submenu );
610 action->setData( "spu-es" );
611 addDPStaticEntry( submenu, qtr( "Open File..." ), "",
612 SLOT( loadSubtitlesFile() ) );
613 submenu->addSeparator();
619 * Subtitles are part of Video.
621 QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current, bool b_subtitle )
623 vout_thread_t *p_vout;
624 input_thread_t *p_input;
625 vector<vlc_object_t *> objects;
626 vector<const char *> varnames;
628 if( current->isEmpty() )
630 addActionWithSubmenu( current, "video-es", qtr( "Video &Track" ) );
632 SubtitleMenu( current );
634 current->addSeparator();
636 addActionWithCheckbox( current, "fullscreen", qtr( "&Fullscreen" ) );
637 addActionWithCheckbox( current, "autoscale", qtr( "Always Fit &Window" ) );
638 addActionWithCheckbox( current, "video-on-top", qtr( "Always &on Top" ) );
640 addActionWithCheckbox( current, "direct3d-desktop", qtr( "Display on &Desktop" ) );
642 addAction( current, "video-snapshot", qtr( "Take &Snapshot" ) );
644 addActionWithCheckbox( current, "video-wallpaper", qtr( "Set as Wall&paper" ) );
646 current->addSeparator();
648 addActionWithSubmenu( current, "zoom", qtr( "&Zoom" ) );
649 addActionWithSubmenu( current, "aspect-ratio", qtr( "&Aspect Ratio" ) );
650 addActionWithSubmenu( current, "crop", qtr( "&Crop" ) );
651 addActionWithSubmenu( current, "deinterlace", qtr( "&Deinterlace" ) );
652 addActionWithSubmenu( current, "deinterlace-mode", qtr( "&Deinterlace mode" ) );
653 addActionWithSubmenu( current, "postprocess", qtr( "&Post processing" ) );
656 p_input = THEMIM->getInput();
658 p_vout = THEMIM->getVout();
659 VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
662 vlc_object_release( p_vout );
664 return Populate( p_intf, current, varnames, objects );
669 * For DVD, MP4, MOV and other chapter based format
671 QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *menu )
675 addActionWithSubmenu( menu, "title", qtr( "T&itle" ) );
676 addActionWithSubmenu( menu, "chapter", qtr( "&Chapter" ) );
677 addActionWithSubmenu( menu, "navigation", qtr( "&Navigation" ) );
678 addActionWithSubmenu( menu, "program", qtr( "&Program" ) );
680 /* FixMe: sync I_MENU_BOOKMARK string */
681 QMenu *submenu = new QMenu( qtr( "Custom &Bookmarks" ), menu );
682 addDPStaticEntry( submenu, qtr( "&Manage" ), "",
683 SLOT( bookmarksDialog() ), "Ctrl+B" );
684 submenu->addSeparator();
685 action = menu->addMenu( submenu );
686 action->setData( "bookmark" );
688 menu->addSeparator();
689 PopupMenuPlaylistControlEntries( menu, p_intf );
690 PopupMenuControlEntries( menu, p_intf );
692 EnableStaticEntries( menu, ( THEMIM->getInput() != NULL ) );
693 return RebuildNavigMenu( p_intf, menu );
696 QMenu *QVLCMenu::RebuildNavigMenu( intf_thread_t *p_intf, QMenu *menu )
699 input_thread_t *p_object;
700 vector<vlc_object_t *> objects;
701 vector<const char *> varnames;
703 /* Get the input and hold it */
704 p_object = THEMIM->getInput();
706 InputAutoMenuBuilder( p_object, objects, varnames );
708 menu->addSeparator();
710 /* Title and so on */
711 PUSH_VAR( "prev-title" );
712 PUSH_VAR( "next-title" );
713 PUSH_VAR( "prev-chapter" );
714 PUSH_VAR( "next-chapter" );
716 EnableStaticEntries( menu, (p_object != NULL ) );
717 return Populate( p_intf, menu, varnames, objects );
723 QMenu *QVLCMenu::HelpMenu( QWidget *parent )
725 QMenu *menu = new QMenu( parent );
726 addDPStaticEntry( menu, qtr( "&Help..." ) ,
727 ":/menu/help", SLOT( helpDialog() ), "F1" );
729 addDPStaticEntry( menu, qtr( "Check for &Updates..." ) , "",
730 SLOT( updateDialog() ) );
732 menu->addSeparator();
733 addDPStaticEntry( menu, qtr( I_MENU_ABOUT ), ":/menu/info",
734 SLOT( aboutDialog() ), "Shift+F1", QAction::AboutRole );
738 /*****************************************************************************
739 * Popup menus - Right Click menus *
740 *****************************************************************************/
741 #define POPUP_BOILERPLATE \
742 static QMenu* menu = NULL; \
743 delete menu; menu = NULL; \
746 vector<vlc_object_t *> objects; \
747 vector<const char *> varnames; \
748 input_thread_t *p_input = THEMIM->getInput();
750 #define CREATE_POPUP \
751 menu = new QMenu(); \
752 Populate( p_intf, menu, varnames, objects ); \
753 menu->popup( QCursor::pos() ); \
755 void QVLCMenu::PopupPlayEntries( QMenu *menu,
756 intf_thread_t *p_intf,
757 input_thread_t *p_input )
761 /* Play or Pause action and icon */
762 if( !p_input || var_GetInteger( p_input, "state" ) != PLAYING_S )
764 action = menu->addAction( qtr( "Play" ),
765 ActionsManager::getInstance( p_intf ), SLOT( play() ) );
766 #ifndef __APPLE__ /* No icons in menus in Mac */
767 action->setIcon( QIcon( ":/menu/play" ) );
772 addMIMStaticEntry( p_intf, menu, qtr( "Pause" ),
773 ":/menu/pause", SLOT( togglePlayPause() ) );
777 void QVLCMenu::PopupMenuControlEntries( QMenu *menu, intf_thread_t *p_intf )
782 action = menu->addAction( qtr( "&Faster" ), THEMIM->getIM(),
784 #ifndef __APPLE__ /* No icons in menus in Mac */
785 action->setIcon( QIcon( ":/toolbar/faster") );
787 action->setData( STATIC_ENTRY );
789 action = menu->addAction( qtr( "Faster (fine)" ), THEMIM->getIM(),
790 SLOT( littlefaster() ) );
791 action->setData( STATIC_ENTRY );
793 action = menu->addAction( qtr( "N&ormal Speed" ), THEMIM->getIM(),
794 SLOT( normalRate() ) );
795 action->setData( STATIC_ENTRY );
797 action = menu->addAction( qtr( "Slower (fine)" ), THEMIM->getIM(),
798 SLOT( littleslower() ) );
799 action->setData( STATIC_ENTRY );
801 action = menu->addAction( qtr( "Slo&wer" ), THEMIM->getIM(),
803 #ifndef __APPLE__ /* No icons in menus in Mac */
804 action->setIcon( QIcon( ":/toolbar/slower") );
806 action->setData( STATIC_ENTRY );
808 menu->addSeparator();
810 action = menu->addAction( qtr( "&Jump Forward" ), THEMIM->getIM(),
812 #ifndef __APPLE__ /* No icons in menus in Mac */
813 action->setIcon( QIcon( ":/toolbar/skip_fw") );
815 action->setData( STATIC_ENTRY );
817 action = menu->addAction( qtr( "Jump Bac&kward" ), THEMIM->getIM(),
819 #ifndef __APPLE__ /* No icons in menus in Mac */
820 action->setIcon( QIcon( ":/toolbar/skip_back") );
822 action->setData( STATIC_ENTRY );
823 addDPStaticEntry( menu, qtr( I_MENU_GOTOTIME ),"",
824 SLOT( gotoTimeDialog() ), "Ctrl+T" );
825 menu->addSeparator();
829 void QVLCMenu::PopupMenuPlaylistControlEntries( QMenu *menu,
830 intf_thread_t *p_intf )
832 bool bEnable = THEMIM->getInput() != NULL;
834 addMIMStaticEntry( p_intf, menu, qtr( "&Stop" ), ":/menu/stop",
835 SLOT( stop() ), true );
836 /* Disable Stop in the right-click popup menu */
838 action->setEnabled( false );
840 /* Next / Previous */
841 addMIMStaticEntry( p_intf, menu, qtr( "Pre&vious" ),
842 ":/menu/previous", SLOT( prev() ) );
843 addMIMStaticEntry( p_intf, menu, qtr( "Ne&xt" ),
844 ":/menu/next", SLOT( next() ) );
846 menu->addSeparator();
849 void QVLCMenu::PopupMenuStaticEntries( QMenu *menu )
851 QMenu *openmenu = new QMenu( qtr( "Open a Media" ), menu );
852 addDPStaticEntry( openmenu, qtr( "&Open File..." ),
853 ":/type/file-asym", SLOT( openFileDialog() ) );
854 addDPStaticEntry( openmenu, qtr( I_OP_OPDIR ),
855 ":/type/folder-grey", SLOT( PLOpenDir() ) );
856 addDPStaticEntry( openmenu, qtr( "Open &Disc..." ),
857 ":/type/disc", SLOT( openDiscDialog() ) );
858 addDPStaticEntry( openmenu, qtr( "Open &Network..." ),
859 ":/type/network", SLOT( openNetDialog() ) );
860 addDPStaticEntry( openmenu, qtr( "Open &Capture Device..." ),
861 ":/type/capture-card", SLOT( openCaptureDialog() ) );
862 menu->addMenu( openmenu );
864 menu->addSeparator();
866 QMenu *helpmenu = HelpMenu( menu );
867 helpmenu->setTitle( qtr( "Help" ) );
868 menu->addMenu( helpmenu );
871 addDPStaticEntry( menu, qtr( "Quit" ), ":/menu/quit",
872 SLOT( quit() ), "Ctrl+Q", QAction::QuitRole );
875 /* Video Tracks and Subtitles tracks */
876 void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf, bool show )
881 vout_thread_t *p_vout = THEMIM->getVout();
884 VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
885 vlc_object_release( p_vout );
892 void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf, bool show )
897 aout_instance_t *p_aout = THEMIM->getAout();
898 AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
900 vlc_object_release( p_aout );
905 /* Navigation stuff, and general menus ( open ), used only for skins */
906 void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf, bool show )
912 varnames.push_back( "audio-es" );
913 InputAutoMenuBuilder( p_input, objects, varnames );
914 menu->addSeparator();
918 Populate( p_intf, menu, varnames, objects );
920 menu->addSeparator();
921 PopupPlayEntries( menu, p_intf, p_input );
922 PopupMenuPlaylistControlEntries( menu, p_intf);
924 menu->addSeparator();
925 PopupMenuControlEntries( menu, p_intf );
927 menu->addSeparator();
928 PopupMenuStaticEntries( menu );
930 menu->popup( QCursor::pos() );
933 /* Main Menu that sticks everything together */
934 void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show )
941 bool b_isFullscreen = false;
942 MainInterface *mi = p_intf->p_sys->p_mi;
944 PopupPlayEntries( menu, p_intf, p_input );
945 PopupMenuPlaylistControlEntries( menu, p_intf );
946 menu->addSeparator();
951 vout_thread_t *p_vout = THEMIM->getVout();
953 /* Add a fullscreen switch button, since it is the most used function */
956 vlc_value_t val; var_Get( p_vout, "fullscreen", &val );
958 b_isFullscreen = !( !val.b_bool );
962 CreateAndConnect( menu, "fullscreen",
963 qtr( "Leave Fullscreen" ),"" , ITEM_NORMAL,
964 VLC_OBJECT(p_vout), val, VLC_VAR_BOOL, b_isFullscreen );
966 vlc_object_release( p_vout );
968 menu->addSeparator();
972 InputAutoMenuBuilder( p_input, objects, varnames );
975 submenu = new QMenu( menu );
976 action = menu->addMenu( AudioMenu( p_intf, submenu ) );
977 action->setText( qtr( "&Audio" ) );
978 if( action->menu()->isEmpty() )
979 action->setEnabled( false );
982 submenu = new QMenu( menu );
983 action = menu->addMenu( VideoMenu( p_intf, submenu, false ) );
984 action->setText( qtr( "&Video" ) );
985 if( action->menu()->isEmpty() )
986 action->setEnabled( false );
988 submenu = SubtitleMenu( menu );
989 submenu->setTitle( qtr( "Subti&tle") );
990 UpdateItem( p_intf, menu, "spu-es", VLC_OBJECT(p_input), true );
992 /* Playback menu for chapters */
993 submenu = new QMenu( menu );
994 action = menu->addMenu( NavigMenu( p_intf, submenu ) );
995 action->setText( qtr( "&Playback" ) );
996 if( action->menu()->isEmpty() )
997 action->setEnabled( false );
1000 menu->addSeparator();
1002 /* Add some special entries for windowed mode: Interface Menu */
1003 if( !b_isFullscreen )
1005 QMenu *submenu = new QMenu( qtr( "Tools" ), menu );
1006 /*QMenu *tools =*/ ToolsMenu( submenu );
1007 submenu->addSeparator();
1009 /* In skins interface, append some items */
1012 submenu->setTitle( qtr( "Interface" ) );
1013 if( p_intf->p_sys->b_isDialogProvider )
1015 vlc_object_t* p_object = p_intf->p_parent;
1017 objects.clear(); varnames.clear();
1018 objects.push_back( p_object );
1019 varnames.push_back( "intf-skins" );
1020 Populate( p_intf, submenu, varnames, objects );
1022 objects.clear(); varnames.clear();
1023 objects.push_back( p_object );
1024 varnames.push_back( "intf-skins-interactive" );
1025 Populate( p_intf, submenu, varnames, objects );
1028 msg_Warn( p_intf, "could not find parent interface" );
1032 QMenu *bar = menu; // Needed for next macro
1033 BAR_DADD( ViewMenu( p_intf, NULL, mi ), qtr( "V&iew" ), 4 );
1036 menu->addMenu( submenu );
1039 /* Static entries for ending, like open */
1040 PopupMenuStaticEntries( menu );
1042 menu->popup( QCursor::pos() );
1046 #undef POPUP_BOILERPLATE
1050 /************************************************************************
1052 ************************************************************************/
1054 void QVLCMenu::updateSystrayMenu( MainInterface *mi,
1055 intf_thread_t *p_intf,
1056 bool b_force_visible )
1058 input_thread_t *p_input = THEMIM->getInput();
1060 /* Get the systray menu and clean it */
1061 QMenu *sysMenu = mi->getSysTrayMenu();
1065 /* Hide / Show VLC and cone */
1066 if( mi->isVisible() || b_force_visible )
1068 sysMenu->addAction( QIcon( ":/logo/vlc16.png" ),
1069 qtr( "Hide VLC media player in taskbar" ), mi,
1070 SLOT( hideUpdateSystrayMenu() ) );
1074 sysMenu->addAction( QIcon( ":/logo/vlc16.png" ),
1075 qtr( "Show VLC media player" ), mi,
1076 SLOT( showUpdateSystrayMenu() ) );
1078 sysMenu->addSeparator();
1081 PopupPlayEntries( sysMenu, p_intf, p_input );
1082 PopupMenuPlaylistControlEntries( sysMenu, p_intf);
1083 PopupMenuControlEntries( sysMenu, p_intf);
1085 addDPStaticEntry( sysMenu, qtr( "&Open a Media" ),
1086 ":/type/file-wide", SLOT( openFileDialog() ) );
1087 addDPStaticEntry( sysMenu, qtr( "&Quit" ) ,
1088 ":/menu/quit", SLOT( quit() ) );
1091 mi->getSysTray()->setContextMenu( sysMenu );
1098 /*************************************************************************
1099 * Builders for automenus
1100 *************************************************************************/
1101 QMenu * QVLCMenu::Populate( intf_thread_t *p_intf,
1103 vector< const char *> & varnames,
1104 vector<vlc_object_t *> & objects )
1106 QMenu *menu = current;
1109 currentGroup = NULL;
1111 for( int i = 0; i < (int)objects.size() ; i++ )
1113 if( !varnames[i] || !*varnames[i] )
1115 menu->addSeparator();
1119 UpdateItem( p_intf, menu, varnames[i], objects[i], true );
1124 /*****************************************************************************
1126 *****************************************************************************/
1128 static bool IsMenuEmpty( const char *psz_var,
1129 vlc_object_t *p_object,
1130 bool b_root = true )
1132 vlc_value_t val, val_list;
1133 int i_type, i_result, i;
1135 /* Check the type of the object variable */
1136 i_type = var_Type( p_object, psz_var );
1138 /* Check if we want to display the variable */
1139 if( !( i_type & VLC_VAR_HASCHOICE ) ) return false;
1141 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
1142 if( val.i_int == 0 ) return true;
1144 if( ( i_type & VLC_VAR_TYPE ) != VLC_VAR_VARIABLE )
1146 if( val.i_int == 1 && b_root ) return true;
1150 /* Check children variables in case of VLC_VAR_VARIABLE */
1151 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
1156 for( i = 0, i_result = true; i < val_list.p_list->i_count; i++ )
1158 if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
1166 /* clean up everything */
1167 var_FreeList( &val_list, NULL );
1172 #define TEXT_OR_VAR qfu ( text.psz_string ? text.psz_string : psz_var )
1174 void QVLCMenu::UpdateItem( intf_thread_t *p_intf, QMenu *menu,
1175 const char *psz_var, vlc_object_t *p_object, bool b_submenu )
1177 vlc_value_t val, text;
1180 QAction *action = FindActionWithVar( menu, psz_var );
1182 DeleteNonStaticEntries( action->menu() );
1187 action->setEnabled( false );
1191 /* Check the type of the object variable */
1192 /* This HACK is needed so we have a radio button for audio and video tracks
1193 instread of a checkbox */
1194 if( !strcmp( psz_var, "audio-es" )
1195 || !strcmp( psz_var, "video-es" ) )
1196 i_type = VLC_VAR_INTEGER | VLC_VAR_HASCHOICE;
1198 i_type = var_Type( p_object, psz_var );
1200 switch( i_type & VLC_VAR_TYPE )
1204 case VLC_VAR_VARIABLE:
1205 case VLC_VAR_STRING:
1206 case VLC_VAR_INTEGER:
1210 /* Variable doesn't exist or isn't handled */
1212 action->setEnabled( false );
1216 /* Make sure we want to display the variable */
1217 if( menu->isEmpty() && IsMenuEmpty( psz_var, p_object ) )
1220 action->setEnabled( false );
1224 /* Get the descriptive name of the variable */
1225 int i_ret = var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
1226 if( i_ret != VLC_SUCCESS )
1228 text.psz_string = NULL;
1233 action = new QAction( TEXT_OR_VAR, menu );
1234 menu->addAction( action );
1235 action->setData( psz_var );
1238 /* Some specific stuff */
1239 bool forceDisabled = false;
1240 if( !strcmp( psz_var, "spu-es" ) )
1242 vout_thread_t *p_vout = THEMIM->getVout();
1243 forceDisabled = ( p_vout == NULL );
1245 vlc_object_release( p_vout );
1248 if( i_type & VLC_VAR_HASCHOICE )
1250 /* Append choices menu */
1254 submenu = action->menu();
1257 submenu = new QMenu( menu );
1258 action->setMenu( submenu );
1262 CreateChoicesMenu( submenu, psz_var, p_object, true ) == 0 );
1264 action->setEnabled( false );
1269 CreateChoicesMenu( menu, psz_var, p_object, true ) == 0 );
1271 FREENULL( text.psz_string );
1275 switch( i_type & VLC_VAR_TYPE )
1278 val.i_int = 0; // Prevent the copy of an uninitialized value
1279 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_NORMAL,
1280 p_object, val, i_type );
1284 var_Get( p_object, psz_var, &val );
1285 val.b_bool = !val.b_bool;
1286 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_CHECK,
1287 p_object, val, i_type, !val.b_bool );
1290 FREENULL( text.psz_string );
1295 /** HACK for the navigation submenu:
1296 * "title %2i" variables take the value 0 if not set
1298 static bool CheckTitle( vlc_object_t *p_object, const char *psz_var )
1301 if( sscanf( psz_var, "title %2i", &i_title ) <= 0 )
1304 int i_current_title = var_GetInteger( p_object, "title" );
1305 return ( i_title == i_current_title );
1309 int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
1310 vlc_object_t *p_object, bool b_root )
1312 vlc_value_t val, val_list, text_list;
1315 /* Check the type of the object variable */
1316 i_type = var_Type( p_object, psz_var );
1318 /* Make sure we want to display the variable */
1319 if( submenu->isEmpty() && IsMenuEmpty( psz_var, p_object, b_root ) )
1320 return VLC_EGENERIC;
1322 switch( i_type & VLC_VAR_TYPE )
1326 case VLC_VAR_VARIABLE:
1327 case VLC_VAR_STRING:
1328 case VLC_VAR_INTEGER:
1332 /* Variable doesn't exist or isn't handled */
1333 return VLC_EGENERIC;
1336 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
1337 &val_list, &text_list ) < 0 )
1339 return VLC_EGENERIC;
1342 #define CURVAL val_list.p_list->p_values[i]
1343 #define CURTEXT text_list.p_list->p_values[i].psz_string
1344 #define RADIO_OR_COMMAND ( i_type & VLC_VAR_ISCOMMAND ) ? ITEM_NORMAL : ITEM_RADIO
1346 for( i = 0; i < val_list.p_list->i_count; i++ )
1348 vlc_value_t another_val;
1350 QMenu *subsubmenu = new QMenu( submenu );
1352 switch( i_type & VLC_VAR_TYPE )
1354 case VLC_VAR_VARIABLE:
1355 CreateChoicesMenu( subsubmenu, CURVAL.psz_string, p_object, false );
1356 subsubmenu->setTitle( qfu( CURTEXT ? CURTEXT :CURVAL.psz_string ) );
1357 submenu->addMenu( subsubmenu );
1360 case VLC_VAR_STRING:
1361 var_Get( p_object, psz_var, &val );
1362 another_val.psz_string = strdup( CURVAL.psz_string );
1363 menutext = qfu( CURTEXT ? CURTEXT : another_val.psz_string );
1364 CreateAndConnect( submenu, psz_var, menutext, "", RADIO_OR_COMMAND,
1365 p_object, another_val, i_type,
1366 val.psz_string && !strcmp( val.psz_string, CURVAL.psz_string ) );
1368 free( val.psz_string );
1371 case VLC_VAR_INTEGER:
1372 var_Get( p_object, psz_var, &val );
1373 if( CURTEXT ) menutext = qfu( CURTEXT );
1374 else menutext = QString::number( CURVAL.i_int );
1375 CreateAndConnect( submenu, psz_var, menutext, "", RADIO_OR_COMMAND,
1376 p_object, CURVAL, i_type,
1377 ( CURVAL.i_int == val.i_int )
1378 && CheckTitle( p_object, psz_var ) );
1382 var_Get( p_object, psz_var, &val );
1383 if( CURTEXT ) menutext = qfu( CURTEXT );
1384 else menutext.sprintf( "%.2f", CURVAL.f_float );
1385 CreateAndConnect( submenu, psz_var, menutext, "", RADIO_OR_COMMAND,
1386 p_object, CURVAL, i_type,
1387 CURVAL.f_float == val.f_float );
1394 currentGroup = NULL;
1396 /* clean up everything */
1397 var_FreeList( &val_list, &text_list );
1399 #undef RADIO_OR_COMMAND
1402 return submenu->isEmpty() ? VLC_EGENERIC : VLC_SUCCESS;
1405 void QVLCMenu::CreateAndConnect( QMenu *menu, const char *psz_var,
1406 const QString& text, const QString& help,
1407 int i_item_type, vlc_object_t *p_obj,
1408 vlc_value_t val, int i_val_type,
1411 QAction *action = FindActionWithVar( menu, psz_var );
1416 action = new QAction( text, menu );
1417 menu->addAction( action );
1421 action->setToolTip( help );
1422 action->setEnabled( p_obj != NULL );
1424 if( i_item_type == ITEM_CHECK )
1426 action->setCheckable( true );
1428 else if( i_item_type == ITEM_RADIO )
1430 action->setCheckable( true );
1432 currentGroup = new QActionGroup( menu );
1433 currentGroup->addAction( action );
1436 action->setChecked( checked );
1438 MenuItemData *itemData = qFindChild<MenuItemData*>( action, QString() );
1440 itemData = new MenuItemData( action, p_obj, i_val_type, val, psz_var );
1442 /* remove previous signal-slot connection(s) if any */
1443 action->disconnect( );
1445 CONNECT( action, triggered(), THEDP->menusMapper, map() );
1446 THEDP->menusMapper->setMapping( action, itemData );
1449 menu->addAction( action );
1452 void QVLCMenu::DoAction( QObject *data )
1454 MenuItemData *itemData = qobject_cast<MenuItemData *>( data );
1455 vlc_object_t *p_object = itemData->p_obj;
1456 if( p_object == NULL ) return;
1458 /* Preserve settings across vouts via the playlist object: */
1459 if( !strcmp( itemData->psz_var, "fullscreen" )
1460 || !strcmp( itemData->psz_var, "video-on-top" ) )
1461 var_Set( pl_Get( p_object ), itemData->psz_var, itemData->val );
1463 var_Set( p_object, itemData->psz_var, itemData->val );
1466 void QVLCMenu::updateRecents( intf_thread_t *p_intf )
1471 RecentsMRL* rmrl = RecentsMRL::getInstance( p_intf );
1472 QStringList l = rmrl->recents();
1474 recentsMenu->clear();
1478 action = recentsMenu->addAction( qtr(" - Empty - ") );
1479 action->setEnabled( false );
1483 for( int i = 0; i < l.size(); ++i )
1485 char *psz_temp = decode_URI_duplicate( qtu( l.at( i ) ) );
1487 action = recentsMenu->addAction(
1488 QString( "&%1: " ).arg( i + 1 ) +
1489 QApplication::fontMetrics().elidedText( psz_temp, Qt::ElideLeft, 400 ),
1490 rmrl->signalMapper, SLOT( map() ),
1491 i <= 9 ? QString( "Ctrl+%1" ).arg( i + 1 ) : "" );
1492 rmrl->signalMapper->setMapping( action, l.at( i ) );
1497 recentsMenu->addSeparator();
1498 recentsMenu->addAction( qtr("&Clear"), rmrl, SLOT( clear() ) );