1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright © 2006-2009 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
34 #include <vlc_intf_strings.h>
35 #include <vlc_services_discovery.h>
41 #include "main_interface.hpp" /* View modifications */
42 #include "dialogs_provider.hpp" /* Dialogs display */
43 #include "input_manager.hpp" /* Input Management */
44 #include "recents.hpp" /* Recent Items */
45 #include "actions_manager.hpp"
46 #include "extensions_manager.hpp"
51 #include <QActionGroup>
52 #include <QSignalMapper>
53 #include <QSystemTrayIcon>
57 This file defines the main menus and the pop-up menu (right-click menu)
58 and the systray menu (in that order in the file)
60 There are 3 menus that have to be rebuilt everytime there are called:
61 Audio, Video, Navigation
62 3 functions are building those menus: AudioMenu, VideoMenu, NavigMenu
63 and 3 functions associated are collecting the objects :
64 InputAutoMenuBuilder, AudioAutoMenuBuilder, VideoAutoMenuBuilder.
66 A QSignalMapper decides when to rebuild those menus cf MenuFunc in the .hpp
67 Just before one of those menus are aboutToShow(), they are rebuild.
70 #define STATIC_ENTRY "__static__"
71 #define ENTRY_ALWAYS_ENABLED "__ignore__"
80 static QActionGroup *currentGroup;
82 QMenu *QVLCMenu::recentsMenu = NULL;
84 /****************************************************************************
86 ****************************************************************************
87 * Add static entries to DP in menus
88 ***************************************************************************/
89 void addDPStaticEntry( QMenu *menu,
93 const char *shortcut = NULL )
95 QAction *action = NULL;
96 if( !EMPTY_STR( icon ) )
98 if( !EMPTY_STR( shortcut ) )
99 action = menu->addAction( QIcon( icon ), text, THEDP,
100 member, qtr( shortcut ) );
102 action = menu->addAction( QIcon( icon ), text, THEDP, member );
106 if( !EMPTY_STR( shortcut ) )
107 action = menu->addAction( text, THEDP, member, qtr( shortcut ) );
109 action = menu->addAction( text, THEDP, member );
111 action->setData( STATIC_ENTRY );
117 QAction* addMIMStaticEntry( intf_thread_t *p_intf,
122 bool bStatic = false )
125 if( strlen( icon ) > 0 )
127 action = menu->addAction( text, THEMIM, member );
128 action->setIcon( QIcon( icon ) );
132 action = menu->addAction( text, THEMIM, member );
134 action->setData( bStatic ? STATIC_ENTRY : ENTRY_ALWAYS_ENABLED );
139 * @brief Enable all static entries, disable the others
140 * @param enable if false, disable all entries
142 void EnableStaticEntries( QMenu *menu, bool enable = true )
146 QList< QAction* > actions = menu->actions();
147 for( int i = 0; i < actions.size(); ++i )
149 actions[i]->setEnabled( actions[i]->data().toString()
150 == ENTRY_ALWAYS_ENABLED ||
151 /* Be careful here, because data("string").toBool is true */
152 ( enable && (actions[i]->data().toString() == STATIC_ENTRY ) ) );
157 * \return Number of static entries
159 int DeleteNonStaticEntries( QMenu *menu )
161 if( !menu ) return VLC_EGENERIC;
165 QList< QAction* > actions = menu->actions();
166 for( int i = 0; i < actions.size(); ++i )
168 if( actions[i]->data().toString() != STATIC_ENTRY )
177 * \return QAction associated to psz_var variable
179 static QAction * FindActionWithVar( QMenu *menu, const char *psz_var )
181 QList< QAction* > actions = menu->actions();
182 for( int i = 0; i < actions.size(); ++i )
184 if( actions[i]->data().toString() == psz_var )
190 /*****************************************************************************
191 * Definitions of variables for the dynamic menus
192 *****************************************************************************/
193 #define PUSH_VAR( var ) varnames.push_back( var ); \
194 objects.push_back( VLC_OBJECT(p_object) )
196 #define PUSH_INPUTVAR( var ) varnames.push_back( var ); \
197 objects.push_back( VLC_OBJECT(p_input) );
199 #define PUSH_SEPARATOR if( objects.size() != i_last_separator ) { \
200 objects.push_back( 0 ); varnames.push_back( "" ); \
201 i_last_separator = objects.size(); }
203 static int InputAutoMenuBuilder( input_thread_t *p_object,
204 vector<vlc_object_t *> &objects,
205 vector<const char *> &varnames )
207 PUSH_VAR( "bookmark" );
209 PUSH_VAR( "chapter" );
210 PUSH_VAR( "navigation" );
211 PUSH_VAR( "program" );
215 static int VideoAutoMenuBuilder( vout_thread_t *p_object,
216 input_thread_t *p_input,
217 vector<vlc_object_t *> &objects,
218 vector<const char *> &varnames )
220 PUSH_INPUTVAR( "video-es" );
221 PUSH_INPUTVAR( "spu-es" );
222 PUSH_VAR( "fullscreen" );
223 PUSH_VAR( "video-on-top" );
224 PUSH_VAR( "video-wallpaper" );
226 PUSH_VAR( "direct3d-desktop" );
228 PUSH_VAR( "video-snapshot" );
230 PUSH_VAR( "autoscale" );
231 PUSH_VAR( "aspect-ratio" );
233 PUSH_VAR( "deinterlace" );
234 PUSH_VAR( "deinterlace-mode" );
235 PUSH_VAR( "postprocess" );
240 static int AudioAutoMenuBuilder( aout_instance_t *p_object,
241 input_thread_t *p_input,
242 vector<vlc_object_t *> &objects,
243 vector<const char *> &varnames )
245 PUSH_INPUTVAR( "audio-es" );
246 PUSH_VAR( "audio-channels" );
247 PUSH_VAR( "audio-device" );
248 PUSH_VAR( "visual" );
252 /*****************************************************************************
255 *****************************************************************************/
257 #define BAR_ADD( func, title ) { \
258 QMenu *_menu = func; _menu->setTitle( title ); bar->addMenu( _menu ); }
260 #define BAR_DADD( func, title, id ) { \
261 QMenu *_menu = func; _menu->setTitle( title ); bar->addMenu( _menu ); \
262 MenuFunc *f = new MenuFunc( _menu, id ); \
263 CONNECT( _menu, aboutToShow(), THEDP->menusUpdateMapper, map() ); \
264 THEDP->menusUpdateMapper->setMapping( _menu, f ); }
266 #define ACT_ADD( _menu, val, title ) { \
267 QAction *_action = new QAction( title, _menu ); _action->setData( val ); \
268 _menu->addAction( _action ); }
270 #define ACT_ADDMENU( _menu, val, title ) { \
271 QAction *_action = new QAction( title, _menu ); _action->setData( val ); \
272 _action->setMenu( new QMenu( _menu ) ); _menu->addAction( _action ); }
274 #define ACT_ADDCHECK( _menu, val, title ) { \
275 QAction *_action = new QAction( title, _menu ); _action->setData( val ); \
276 _action->setCheckable( true ); _menu->addAction( _action ); }
279 * Main Menu Bar Creation
281 void QVLCMenu::createMenuBar( MainInterface *mi,
282 intf_thread_t *p_intf )
284 /* QMainWindows->menuBar()
285 gives the QProcess::destroyed timeout issue on Cleanlooks style with
286 setDesktopAware set to false */
287 QMenuBar *bar = mi->menuBar();
289 BAR_ADD( FileMenu( p_intf, bar ), qtr( "&Media" ) );
291 /* Dynamic menus, rebuilt before being showed */
292 BAR_DADD( NavigMenu( p_intf, bar ), qtr( "P&layback" ), 3 );
293 BAR_DADD( AudioMenu( p_intf, bar ), qtr( "&Audio" ), 1 );
294 BAR_DADD( VideoMenu( p_intf, bar ), qtr( "&Video" ), 2 );
296 BAR_ADD( ToolsMenu( bar ), qtr( "&Tools" ) );
297 QMenu *_menu = ViewMenu( p_intf, bar );
298 _menu->setTitle( qtr( "V&iew" ) );
299 bar->addMenu( _menu );
300 ViewMenu( p_intf, _menu, mi );
301 BAR_ADD( HelpMenu( bar ), qtr( "&Help" ) );
308 * Media ( File ) Menu
309 * Opening, streaming and quit
311 QMenu *QVLCMenu::FileMenu( intf_thread_t *p_intf, QWidget *parent )
313 QMenu *menu = new QMenu( parent );
315 addDPStaticEntry( menu, qtr( "&Open File..." ),
316 ":/type/file-asym", SLOT( simpleOpenDialog() ), "Ctrl+O" );
317 addDPStaticEntry( menu, qtr( "Advanced Open File..." ),
318 ":/type/file-asym", SLOT( openFileDialog() ), "Ctrl+Shift+O" );
319 addDPStaticEntry( menu, qtr( I_OP_OPDIR ),
320 ":/type/folder-grey", SLOT( PLOpenDir() ), "Ctrl+F" );
321 addDPStaticEntry( menu, qtr( "Open &Disc..." ),
322 ":/type/disc", SLOT( openDiscDialog() ), "Ctrl+D" );
323 addDPStaticEntry( menu, qtr( "Open &Network Stream..." ),
324 ":/type/network", SLOT( openNetDialog() ), "Ctrl+N" );
325 addDPStaticEntry( menu, qtr( "Open &Capture Device..." ),
326 ":/type/capture-card", SLOT( openCaptureDialog() ),
329 menu->addSeparator();
330 addDPStaticEntry( menu, qtr( "Open &Location from clipboard" ),
331 NULL, SLOT( openUrlDialog() ), "Ctrl+V" );
333 if( var_InheritBool( p_intf, "qt-recentplay" ) )
335 recentsMenu = new QMenu( qtr( "&Recent Media" ), menu );
336 updateRecents( p_intf );
337 menu->addMenu( recentsMenu );
339 menu->addSeparator();
341 addDPStaticEntry( menu, qtr( I_PL_SAVE ), "", SLOT( saveAPlaylist() ),
343 menu->addSeparator();
346 addDPStaticEntry( menu, qtr( "Conve&rt / Save..." ), "",
347 SLOT( openAndTranscodingDialogs() ), "Ctrl+R" );
348 addDPStaticEntry( menu, qtr( "&Streaming..." ),
349 ":/menu/stream", SLOT( openAndStreamingDialogs() ),
351 menu->addSeparator();
354 addDPStaticEntry( menu, qtr( "&Quit" ) ,
355 ":/menu/quit", SLOT( quit() ), "Ctrl+Q" );
360 * Tools, like Media Information, Preferences or Messages
362 QMenu *QVLCMenu::ToolsMenu( QMenu *menu )
364 addDPStaticEntry( menu, qtr( "&Effects and Filters"), ":/menu/settings",
365 SLOT( extendedDialog() ), "Ctrl+E" );
367 addDPStaticEntry( menu, qtr( "&Track Synchronization"), ":/menu/settings",
368 SLOT( synchroDialog() ), "" );
370 addDPStaticEntry( menu, qtr( I_MENU_INFO ) , ":/menu/info",
371 SLOT( mediaInfoDialog() ), "Ctrl+I" );
372 addDPStaticEntry( menu, qtr( I_MENU_CODECINFO ) ,
373 ":/menu/info", SLOT( mediaCodecDialog() ), "Ctrl+J" );
375 addDPStaticEntry( menu, qtr( I_MENU_BOOKMARK ),"",
376 SLOT( bookmarksDialog() ), "Ctrl+B" );
378 addDPStaticEntry( menu, qtr( I_MENU_VLM ), "", SLOT( vlmDialog() ),
382 addDPStaticEntry( menu, qtr( "Program Guide" ), "", SLOT( epgDialog() ),
385 addDPStaticEntry( menu, qtr( I_MENU_MSG ),
386 ":/menu/messages", SLOT( messagesDialog() ),
389 addDPStaticEntry( menu, qtr( "Plu&gins and extensions" ),
390 "", SLOT( pluginDialog() ) );
391 menu->addSeparator();
393 addDPStaticEntry( menu, qtr( "&Preferences" ),
394 ":/menu/preferences", SLOT( prefsDialog() ), "Ctrl+P" );
399 QMenu *QVLCMenu::ToolsMenu( QWidget *parent )
401 return ToolsMenu( new QMenu( parent ) );
406 * Connect signal "aboutToShow" to the creation of the View Menu
408 QMenu *QVLCMenu::ViewMenu( intf_thread_t *p_intf, QWidget* parent )
410 QMenu *viewMenu = new QMenu( parent );
411 MenuFunc *f = new MenuFunc( viewMenu, 4 );
412 CONNECT( viewMenu, aboutToShow(), THEDP->menusUpdateMapper, map() );
413 THEDP->menusUpdateMapper->setMapping( viewMenu, f );
419 * Interface modification, load other interfaces, activate Extensions
421 QMenu *QVLCMenu::ViewMenu( intf_thread_t *p_intf, QMenu *current, MainInterface *_mi )
426 MainInterface *mi = _mi ? _mi : p_intf->p_sys->p_mi;
431 menu = new QMenu( qtr( "&View" ), mi );
437 //HACK menu->clear() does not delete submenus
438 QList<QAction*> actions = menu->actions();
439 foreach( QAction *a, actions )
441 QMenu *m = a->menu();
442 if( a->parent() == menu ) delete a;
443 else menu->removeAction( a );
444 if( m && m->parent() == menu ) delete m;
448 menu->addAction( QIcon( ":/menu/playlist_menu" ),
449 qtr( "Play&list" ), mi,
450 SLOT( togglePlaylist() ), qtr( "Ctrl+L" ) );
452 menu->addSeparator();
454 QMenu *intfmenu = InterfacesMenu( p_intf, menu );
455 menu->addSeparator();
458 action = menu->addAction( qtr( "Mi&nimal View" ) );
459 action->setShortcut( qtr( "Ctrl+H" ) );
460 action->setCheckable( true );
461 action->setChecked( (mi->getControlsVisibilityStatus() & CONTROLS_HIDDEN ) );
463 CONNECT( action, triggered( bool ), mi, toggleMinimalView( bool ) );
464 CONNECT( mi, minimalViewToggled( bool ), action, setChecked( bool ) );
466 /* FullScreen View */
467 action = menu->addAction( qtr( "&Fullscreen Interface" ), mi,
468 SLOT( toggleInterfaceFullScreen() ), QString( "F11" ) );
469 action->setCheckable( true );
470 action->setChecked( mi->isInterfaceFullScreen() );
471 CONNECT( mi, fullscreenInterfaceToggled( bool ),
472 action, setChecked( bool ) );
474 /* Advanced Controls */
475 action = menu->addAction( qtr( "&Advanced Controls" ), mi,
476 SLOT( toggleAdvancedButtons() ) );
477 action->setCheckable( true );
478 if( mi->getControlsVisibilityStatus() & CONTROLS_ADVANCED )
479 action->setChecked( true );
481 /* Docked Playlist */
482 action = menu->addAction( qtr( "Docked Playlist" ) );
483 action->setCheckable( true );
484 action->setChecked( mi->isPlDocked() );
485 CONNECT( action, triggered( bool ), mi, dockPlaylist( bool ) );
488 // I don't want to manage consistency between menus, so no popup-menu
490 action = menu->addAction( qtr( "Quit after Playback" ) );
491 action->setCheckable( true );
492 CONNECT( action, triggered( bool ), THEMIM, activatePlayQuit( bool ) );
495 #if 0 /* For Visualisations. Not yet working */
496 adv = menu->addAction( qtr( "Visualizations selector" ),
497 mi, SLOT( visual() ) );
498 adv->setCheckable( true );
499 if( visual_selector_enabled ) adv->setChecked( true );
502 menu->addSeparator();
503 addDPStaticEntry( menu, qtr( "Customi&ze Interface..." ),
504 ":/menu/preferences", SLOT( toolbarDialog() ) );
507 ExtensionsMenu( p_intf, menu );
513 * Interface Sub-Menu, to list extras interface and skins
515 QMenu *QVLCMenu::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
517 vector<vlc_object_t *> objects;
518 vector<const char *> varnames;
519 varnames.push_back( "intf-add" );
520 objects.push_back( VLC_OBJECT(p_intf) );
522 return Populate( p_intf, current, varnames, objects );
526 * Extensions menu: populate the current menu with extensions
528 void QVLCMenu::ExtensionsMenu( intf_thread_t *p_intf, QMenu *extMenu )
530 /* Get ExtensionsManager and load extensions if needed */
531 ExtensionsManager *extMgr = ExtensionsManager::getInstance( p_intf );
533 if( !var_InheritBool( p_intf, "qt-autoload-extensions")
534 && !extMgr->isLoaded() )
539 if( !extMgr->isLoaded() && !extMgr->cannotLoad() )
541 extMgr->loadExtensions();
544 /* Let the ExtensionsManager build itself the menu */
545 extMenu->addSeparator();
546 extMgr->menu( extMenu );
552 QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QMenu * current )
554 vector<vlc_object_t *> objects;
555 vector<const char *> varnames;
556 aout_instance_t *p_aout;
557 input_thread_t *p_input;
559 if( current->isEmpty() )
561 ACT_ADDMENU( current, "audio-es", qtr( "Audio &Track" ) );
562 ACT_ADDMENU( current, "audio-channels", qtr( "Audio &Channels" ) );
563 ACT_ADDMENU( current, "audio-device", qtr( "Audio &Device" ) );
564 current->addSeparator();
566 ACT_ADDMENU( current, "visual", qtr( "&Visualizations" ) );
567 current->addSeparator();
569 QAction *action = current->addAction( qtr( "Increase Volume" ),
570 ActionsManager::getInstance( p_intf ), SLOT( AudioUp() ) );
571 action->setData( STATIC_ENTRY );
572 action = current->addAction( qtr( "Decrease Volume" ),
573 ActionsManager::getInstance( p_intf ), SLOT( AudioDown() ) );
574 action->setData( STATIC_ENTRY );
575 action = current->addAction( qtr( "Mute" ),
576 ActionsManager::getInstance( p_intf ), SLOT( toggleMuteAudio() ) );
577 action->setData( STATIC_ENTRY );
580 p_input = THEMIM->getInput();
581 p_aout = THEMIM->getAout();
582 EnableStaticEntries( current, ( p_aout != NULL ) );
583 AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
586 vlc_object_release( p_aout );
589 return Populate( p_intf, current, varnames, objects );
592 QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QWidget *parent )
594 return AudioMenu( p_intf, new QMenu( parent ) );
599 * Subtitles are part of Video.
601 QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current )
603 vout_thread_t *p_vout;
604 input_thread_t *p_input;
605 vector<vlc_object_t *> objects;
606 vector<const char *> varnames;
608 if( current->isEmpty() )
610 ACT_ADDMENU( current, "video-es", qtr( "Video &Track" ) );
613 QMenu *submenu = new QMenu( qtr( "&Subtitles Track" ), current );
614 action = current->addMenu( submenu );
615 action->setData( "spu-es" );
616 addDPStaticEntry( submenu, qtr( "Open File..." ), "",
617 SLOT( loadSubtitlesFile() ) );
618 submenu->addSeparator();
619 current->addSeparator();
621 ACT_ADDCHECK( current, "fullscreen", qtr( "&Fullscreen" ) );
622 ACT_ADDCHECK( current, "video-on-top", qtr( "Always &On Top" ) );
623 ACT_ADDCHECK( current, "video-wallpaper", qtr( "DirectX Wallpaper" ) );
625 ACT_ADDCHECK( current, "direct3d-desktop", qtr( "Direct3D Desktop mode" ) );
627 ACT_ADD( current, "video-snapshot", qtr( "Sna&pshot" ) );
629 current->addSeparator();
631 ACT_ADDMENU( current, "zoom", qtr( "&Zoom" ) );
632 ACT_ADDCHECK( current, "autoscale", qtr( "Sca&le" ) );
633 ACT_ADDMENU( current, "aspect-ratio", qtr( "&Aspect Ratio" ) );
634 ACT_ADDMENU( current, "crop", qtr( "&Crop" ) );
635 ACT_ADDMENU( current, "deinterlace", qtr( "&Deinterlace" ) );
636 ACT_ADDMENU( current, "deinterlace-mode", qtr( "&Deinterlace mode" ) );
637 ACT_ADDMENU( current, "postprocess", qtr( "&Post processing" ) );
640 p_input = THEMIM->getInput();
642 p_vout = THEMIM->getVout();
643 VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
646 vlc_object_release( p_vout );
648 return Populate( p_intf, current, varnames, objects );
651 QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QWidget *parent )
653 return VideoMenu( p_intf, new QMenu( parent ) );
658 * For DVD, MP4, MOV and other chapter based format
660 QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *menu )
664 QMenu *submenu = new QMenu( qtr( "&Bookmarks" ), menu );
665 addDPStaticEntry( submenu, qtr( "Manage &bookmarks" ), "",
666 SLOT( bookmarksDialog() ) );
667 submenu->addSeparator();
668 action = menu->addMenu( submenu );
669 action->setData( "bookmark" );
671 ACT_ADDMENU( menu, "title", qtr( "T&itle" ) );
672 ACT_ADDMENU( menu, "chapter", qtr( "&Chapter" ) );
673 ACT_ADDMENU( menu, "navigation", qtr( "&Navigation" ) );
674 ACT_ADDMENU( menu, "program", qtr( "&Program" ) );
676 menu->addSeparator();
677 PopupMenuPlaylistControlEntries( menu, p_intf );
678 PopupMenuControlEntries( menu, p_intf );
680 EnableStaticEntries( menu, ( THEMIM->getInput() != NULL ) );
681 return RebuildNavigMenu( p_intf, menu );
684 QMenu *QVLCMenu::RebuildNavigMenu( intf_thread_t *p_intf, QMenu *menu )
687 input_thread_t *p_object;
688 vector<vlc_object_t *> objects;
689 vector<const char *> varnames;
691 /* Get the input and hold it */
692 p_object = THEMIM->getInput();
694 InputAutoMenuBuilder( p_object, objects, varnames );
696 menu->addSeparator();
698 /* Title and so on */
699 PUSH_VAR( "prev-title" );
700 PUSH_VAR( "next-title" );
701 PUSH_VAR( "prev-chapter" );
702 PUSH_VAR( "next-chapter" );
704 EnableStaticEntries( menu, (p_object != NULL ) );
705 return Populate( p_intf, menu, varnames, objects );
708 QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QWidget *parent )
710 return NavigMenu( p_intf, new QMenu( parent ) );
714 * Service Discovery SubMenu
716 QMenu *QVLCMenu::SDMenu( intf_thread_t *p_intf, QWidget *parent )
718 QMenu *menu = new QMenu( parent );
719 menu->setTitle( qtr( I_PL_SD ) );
721 char **ppsz_longnames;
722 char **ppsz_names = vlc_sd_GetNames( p_intf, &ppsz_longnames, NULL );
726 char **ppsz_name = ppsz_names, **ppsz_longname = ppsz_longnames;
727 for( ; *ppsz_name; ppsz_name++, ppsz_longname++ )
729 if( !strcmp( *ppsz_name, "podcast" ) )
731 QAction *b = new QAction( qtr( "Configure podcasts..." ), menu );
732 //b->setEnabled( a->isChecked() );
733 menu->addAction( b );
734 CONNECT( b, triggered(), THEDP, podcastConfigureDialog() );
737 free( *ppsz_longname );
740 free( ppsz_longnames );
747 QMenu *QVLCMenu::HelpMenu( QWidget *parent )
749 QMenu *menu = new QMenu( parent );
750 addDPStaticEntry( menu, qtr( "&Help..." ) ,
751 ":/menu/help", SLOT( helpDialog() ), "F1" );
753 addDPStaticEntry( menu, qtr( "Check for &Updates..." ) , "",
754 SLOT( updateDialog() ) );
756 menu->addSeparator();
757 addDPStaticEntry( menu, qtr( I_MENU_ABOUT ), ":/menu/info",
758 SLOT( aboutDialog() ), "Shift+F1" );
762 /*****************************************************************************
763 * Popup menus - Right Click menus *
764 *****************************************************************************/
765 #define POPUP_BOILERPLATE \
766 static QMenu* menu = NULL; \
767 delete menu; menu = NULL; \
770 unsigned int i_last_separator = 0; \
771 vector<vlc_object_t *> objects; \
772 vector<const char *> varnames; \
773 input_thread_t *p_input = THEMIM->getInput();
775 #define CREATE_POPUP \
776 menu = new QMenu(); \
777 Populate( p_intf, menu, varnames, objects ); \
778 menu->popup( QCursor::pos() ); \
779 i_last_separator = 0;
781 void QVLCMenu::PopupPlayEntries( QMenu *menu,
782 intf_thread_t *p_intf,
783 input_thread_t *p_input )
787 /* Play or Pause action and icon */
788 if( !p_input || var_GetInteger( p_input, "state" ) != PLAYING_S )
790 action = menu->addAction( qtr( "Play" ),
791 ActionsManager::getInstance( p_intf ), SLOT( play() ) );
792 action->setIcon( QIcon( ":/menu/play" ) );
796 addMIMStaticEntry( p_intf, menu, qtr( "Pause" ),
797 ":/menu/pause", SLOT( togglePlayPause() ) );
801 void QVLCMenu::PopupMenuControlEntries( QMenu *menu, intf_thread_t *p_intf )
806 action = menu->addAction( qtr( "&Faster" ), THEMIM->getIM(),
808 action->setIcon( QIcon( ":/toolbar/faster") );
809 action->setData( STATIC_ENTRY );
811 action = menu->addAction( qtr( "Faster (fine)" ), THEMIM->getIM(),
812 SLOT( littlefaster() ) );
813 action->setData( STATIC_ENTRY );
815 action = menu->addAction( qtr( "N&ormal Speed" ), THEMIM->getIM(),
816 SLOT( normalRate() ) );
817 action->setData( STATIC_ENTRY );
819 action = menu->addAction( qtr( "Slower (fine)" ), THEMIM->getIM(),
820 SLOT( littleslower() ) );
821 action->setData( STATIC_ENTRY );
823 action = menu->addAction( qtr( "Slo&wer" ), THEMIM->getIM(),
825 action->setIcon( QIcon( ":/toolbar/slower") );
826 action->setData( STATIC_ENTRY );
828 menu->addSeparator();
830 action = menu->addAction( qtr( "&Jump Forward" ), THEMIM->getIM(),
832 action->setIcon( QIcon( ":/toolbar/skip_fw") );
833 action->setData( STATIC_ENTRY );
835 action = menu->addAction( qtr( "Jump Bac&kward" ), THEMIM->getIM(),
837 action->setIcon( QIcon( ":/toolbar/skip_back") );
838 action->setData( STATIC_ENTRY );
839 addDPStaticEntry( menu, qtr( I_MENU_GOTOTIME ),"",
840 SLOT( gotoTimeDialog() ), "Ctrl+T" );
841 menu->addSeparator();
845 void QVLCMenu::PopupMenuPlaylistControlEntries( QMenu *menu,
846 intf_thread_t *p_intf )
848 bool bEnable = THEMIM->getInput() != NULL;
850 addMIMStaticEntry( p_intf, menu, qtr( "&Stop" ), ":/menu/stop",
851 SLOT( stop() ), true );
852 /* Disable Stop in the right-click popup menu */
854 action->setEnabled( false );
856 /* Next / Previous */
857 addMIMStaticEntry( p_intf, menu, qtr( "Pre&vious" ),
858 ":/menu/previous", SLOT( prev() ) );
859 addMIMStaticEntry( p_intf, menu, qtr( "Ne&xt" ),
860 ":/menu/next", SLOT( next() ) );
861 menu->addSeparator();
864 void QVLCMenu::PopupMenuStaticEntries( QMenu *menu )
866 QMenu *openmenu = new QMenu( qtr( "Open Media" ), menu );
867 addDPStaticEntry( openmenu, qtr( "&Open File..." ),
868 ":/type/file-asym", SLOT( openFileDialog() ) );
869 addDPStaticEntry( openmenu, qtr( I_OP_OPDIR ),
870 ":/type/folder-grey", SLOT( PLOpenDir() ) );
871 addDPStaticEntry( openmenu, qtr( "Open &Disc..." ),
872 ":/type/disc", SLOT( openDiscDialog() ) );
873 addDPStaticEntry( openmenu, qtr( "Open &Network..." ),
874 ":/type/network", SLOT( openNetDialog() ) );
875 addDPStaticEntry( openmenu, qtr( "Open &Capture Device..." ),
876 ":/type/capture-card", SLOT( openCaptureDialog() ) );
877 menu->addMenu( openmenu );
879 menu->addSeparator();
881 QMenu *helpmenu = HelpMenu( menu );
882 helpmenu->setTitle( qtr( "Help" ) );
883 menu->addMenu( helpmenu );
886 addDPStaticEntry( menu, qtr( "Quit" ), ":/menu/quit",
887 SLOT( quit() ), "Ctrl+Q" );
890 /* Video Tracks and Subtitles tracks */
891 void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf, bool show )
896 vout_thread_t *p_vout = THEMIM->getVout();
899 VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
900 vlc_object_release( p_vout );
907 void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf, bool show )
912 aout_instance_t *p_aout = THEMIM->getAout();
913 AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
915 vlc_object_release( p_aout );
920 /* Navigation stuff, and general menus ( open ), used only for skins */
921 void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf, bool show )
927 varnames.push_back( "audio-es" );
928 InputAutoMenuBuilder( p_input, objects, varnames );
933 Populate( p_intf, menu, varnames, objects );
935 menu->addSeparator();
936 PopupPlayEntries( menu, p_intf, p_input );
937 PopupMenuPlaylistControlEntries( menu, p_intf);
939 menu->addSeparator();
940 PopupMenuControlEntries( menu, p_intf );
942 menu->addSeparator();
943 PopupMenuStaticEntries( menu );
945 menu->popup( QCursor::pos() );
948 /* Main Menu that sticks everything together */
949 void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show )
956 bool b_isFullscreen = false;
957 MainInterface *mi = p_intf->p_sys->p_mi;
959 PopupPlayEntries( menu, p_intf, p_input );
960 PopupMenuPlaylistControlEntries( menu, p_intf );
961 menu->addSeparator();
966 vout_thread_t *p_vout = THEMIM->getVout();
968 /* Add a fullscreen switch button, since it is the most used function */
971 vlc_value_t val; var_Get( p_vout, "fullscreen", &val );
973 b_isFullscreen = !( !val.b_bool );
977 CreateAndConnect( menu, "fullscreen",
978 qtr( "Leave Fullscreen" ),"" , ITEM_NORMAL,
979 VLC_OBJECT(p_vout), val, VLC_VAR_BOOL, b_isFullscreen );
981 vlc_object_release( p_vout );
983 menu->addSeparator();
987 InputAutoMenuBuilder( p_input, objects, varnames );
990 submenu = new QMenu( menu );
991 action = menu->addMenu( AudioMenu( p_intf, submenu ) );
992 action->setText( qtr( "&Audio" ) );
993 if( action->menu()->isEmpty() )
994 action->setEnabled( false );
997 submenu = new QMenu( menu );
998 action = menu->addMenu( VideoMenu( p_intf, submenu ) );
999 action->setText( qtr( "&Video" ) );
1000 if( action->menu()->isEmpty() )
1001 action->setEnabled( false );
1003 /* Playback menu for chapters */
1004 submenu = new QMenu( menu );
1005 action = menu->addMenu( NavigMenu( p_intf, submenu ) );
1006 action->setText( qtr( "&Playback" ) );
1007 if( action->menu()->isEmpty() )
1008 action->setEnabled( false );
1011 menu->addSeparator();
1013 /* Add some special entries for windowed mode: Interface Menu */
1014 if( !b_isFullscreen )
1016 QMenu *submenu = new QMenu( qtr( "Interface" ), menu );
1017 /*QMenu *tools =*/ ToolsMenu( submenu );
1018 submenu->addSeparator();
1020 /* In skins interface, append some items */
1023 if( p_intf->p_sys->b_isDialogProvider )
1025 vlc_object_t* p_object = p_intf->p_parent;
1027 objects.clear(); varnames.clear();
1028 objects.push_back( p_object );
1029 varnames.push_back( "intf-skins" );
1030 Populate( p_intf, submenu, varnames, objects );
1032 objects.clear(); varnames.clear();
1033 objects.push_back( p_object );
1034 varnames.push_back( "intf-skins-interactive" );
1035 Populate( p_intf, submenu, varnames, objects );
1038 msg_Warn( p_intf, "could not find parent interface" );
1042 QMenu *viewmenu = menu->addMenu( qtr( "V&iew" ) );
1043 ViewMenu( p_intf, viewmenu );
1046 menu->addMenu( submenu );
1049 /* Static entries for ending, like open */
1050 PopupMenuStaticEntries( menu );
1052 menu->popup( QCursor::pos() );
1060 #undef POPUP_BOILERPLATE
1063 /************************************************************************
1065 ************************************************************************/
1067 void QVLCMenu::updateSystrayMenu( MainInterface *mi,
1068 intf_thread_t *p_intf,
1069 bool b_force_visible )
1071 unsigned int i_last_separator = 0;
1072 vector<vlc_object_t *> objects;
1073 vector<const char *> varnames;
1074 input_thread_t *p_input = THEMIM->getInput();
1076 /* Get the systray menu and clean it */
1077 QMenu *sysMenu = mi->getSysTrayMenu();
1080 /* Hide / Show VLC and cone */
1081 if( mi->isVisible() || b_force_visible )
1083 sysMenu->addAction( QIcon( ":/logo/vlc16.png" ),
1084 qtr( "Hide VLC media player in taskbar" ), mi,
1085 SLOT( toggleUpdateSystrayMenu() ) );
1089 sysMenu->addAction( QIcon( ":/logo/vlc16.png" ),
1090 qtr( "Show VLC media player" ), mi,
1091 SLOT( toggleUpdateSystrayMenu() ) );
1094 sysMenu->addSeparator();
1095 PopupPlayEntries( sysMenu, p_intf, p_input );
1096 PopupMenuPlaylistControlEntries( sysMenu, p_intf);
1097 PopupMenuControlEntries( sysMenu, p_intf);
1099 sysMenu->addSeparator();
1100 addDPStaticEntry( sysMenu, qtr( "&Open Media" ),
1101 ":/type/file-wide", SLOT( openFileDialog() ) );
1102 addDPStaticEntry( sysMenu, qtr( "&Quit" ) ,
1103 ":/menu/quit", SLOT( quit() ) );
1106 mi->getSysTray()->setContextMenu( sysMenu );
1112 #undef PUSH_SEPARATOR
1114 /*************************************************************************
1115 * Builders for automenus
1116 *************************************************************************/
1117 QMenu * QVLCMenu::Populate( intf_thread_t *p_intf,
1119 vector< const char *> & varnames,
1120 vector<vlc_object_t *> & objects )
1122 QMenu *menu = current;
1125 currentGroup = NULL;
1127 vlc_object_t *p_object;
1129 for( int i = 0; i < ( int )objects.size() ; i++ )
1131 if( !varnames[i] || !*varnames[i] )
1133 menu->addSeparator();
1136 p_object = objects[i];
1138 UpdateItem( p_intf, menu, varnames[i], p_object, true );
1143 /*****************************************************************************
1145 *****************************************************************************/
1147 static bool IsMenuEmpty( const char *psz_var,
1148 vlc_object_t *p_object,
1149 bool b_root = true )
1151 vlc_value_t val, val_list;
1152 int i_type, i_result, i;
1154 /* Check the type of the object variable */
1155 i_type = var_Type( p_object, psz_var );
1157 /* Check if we want to display the variable */
1158 if( !( i_type & VLC_VAR_HASCHOICE ) ) return false;
1160 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
1161 if( val.i_int == 0 ) return true;
1163 if( ( i_type & VLC_VAR_TYPE ) != VLC_VAR_VARIABLE )
1165 if( val.i_int == 1 && b_root ) return true;
1169 /* Check children variables in case of VLC_VAR_VARIABLE */
1170 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
1175 for( i = 0, i_result = true; i < val_list.p_list->i_count; i++ )
1177 if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
1185 /* clean up everything */
1186 var_FreeList( &val_list, NULL );
1191 #define TEXT_OR_VAR qfu ( text.psz_string ? text.psz_string : psz_var )
1193 void QVLCMenu::UpdateItem( intf_thread_t *p_intf, QMenu *menu,
1194 const char *psz_var, vlc_object_t *p_object, bool b_submenu )
1196 vlc_value_t val, text;
1199 QAction *action = FindActionWithVar( menu, psz_var );
1201 DeleteNonStaticEntries( action->menu() );
1206 action->setEnabled( false );
1210 /* Check the type of the object variable */
1211 /* This HACK is needed so we have a radio button for audio and video tracks
1212 instread of a checkbox */
1213 if( !strcmp( psz_var, "audio-es" )
1214 || !strcmp( psz_var, "video-es" ) )
1215 i_type = VLC_VAR_INTEGER | VLC_VAR_HASCHOICE;
1217 i_type = var_Type( p_object, psz_var );
1219 switch( i_type & VLC_VAR_TYPE )
1223 case VLC_VAR_VARIABLE:
1224 case VLC_VAR_STRING:
1225 case VLC_VAR_INTEGER:
1229 /* Variable doesn't exist or isn't handled */
1231 action->setEnabled( false );
1235 /* Make sure we want to display the variable */
1236 if( menu->isEmpty() && IsMenuEmpty( psz_var, p_object ) )
1239 action->setEnabled( false );
1243 /* Get the descriptive name of the variable */
1244 int i_ret = var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
1245 if( i_ret != VLC_SUCCESS )
1247 text.psz_string = NULL;
1252 action = new QAction( TEXT_OR_VAR, menu );
1253 menu->addAction( action );
1254 action->setData( psz_var );
1257 /* Some specific stuff */
1258 bool forceDisabled = false;
1259 if( !strcmp( psz_var, "spu-es" ) )
1261 vout_thread_t *p_vout = THEMIM->getVout();
1262 forceDisabled = ( p_vout == NULL );
1264 vlc_object_release( p_vout );
1267 if( i_type & VLC_VAR_HASCHOICE )
1269 /* Append choices menu */
1273 submenu = action->menu();
1276 submenu = new QMenu( menu );
1277 action->setMenu( submenu );
1281 CreateChoicesMenu( submenu, psz_var, p_object, true ) == 0 );
1283 action->setEnabled( false );
1288 CreateChoicesMenu( menu, psz_var, p_object, true ) == 0 );
1290 FREENULL( text.psz_string );
1294 switch( i_type & VLC_VAR_TYPE )
1297 val.i_int = 0; // Prevent the copy of an uninitialized value
1298 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_NORMAL,
1299 p_object, val, i_type );
1303 var_Get( p_object, psz_var, &val );
1304 val.b_bool = !val.b_bool;
1305 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_CHECK,
1306 p_object, val, i_type, !val.b_bool );
1309 FREENULL( text.psz_string );
1314 /** HACK for the navigation submenu:
1315 * "title %2i" variables take the value 0 if not set
1317 static bool CheckTitle( vlc_object_t *p_object, const char *psz_var )
1320 if( sscanf( psz_var, "title %2i", &i_title ) <= 0 )
1323 int i_current_title = var_GetInteger( p_object, "title" );
1324 return ( i_title == i_current_title );
1328 int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
1329 vlc_object_t *p_object, bool b_root )
1331 vlc_value_t val, val_list, text_list;
1334 /* Check the type of the object variable */
1335 i_type = var_Type( p_object, psz_var );
1337 /* Make sure we want to display the variable */
1338 if( submenu->isEmpty() && IsMenuEmpty( psz_var, p_object, b_root ) )
1339 return VLC_EGENERIC;
1341 switch( i_type & VLC_VAR_TYPE )
1345 case VLC_VAR_VARIABLE:
1346 case VLC_VAR_STRING:
1347 case VLC_VAR_INTEGER:
1351 /* Variable doesn't exist or isn't handled */
1352 return VLC_EGENERIC;
1355 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
1356 &val_list, &text_list ) < 0 )
1358 return VLC_EGENERIC;
1361 #define CURVAL val_list.p_list->p_values[i]
1362 #define CURTEXT text_list.p_list->p_values[i].psz_string
1364 for( i = 0; i < val_list.p_list->i_count; i++ )
1366 vlc_value_t another_val;
1368 QMenu *subsubmenu = new QMenu( submenu );
1370 switch( i_type & VLC_VAR_TYPE )
1372 case VLC_VAR_VARIABLE:
1373 CreateChoicesMenu( subsubmenu, CURVAL.psz_string, p_object, false );
1374 subsubmenu->setTitle( qfu( CURTEXT ? CURTEXT :CURVAL.psz_string ) );
1375 submenu->addMenu( subsubmenu );
1378 case VLC_VAR_STRING:
1379 var_Get( p_object, psz_var, &val );
1380 another_val.psz_string = strdup( CURVAL.psz_string );
1381 menutext = qfu( CURTEXT ? CURTEXT : another_val.psz_string );
1382 CreateAndConnect( submenu, psz_var, menutext, "", ITEM_RADIO,
1383 p_object, another_val, i_type,
1384 val.psz_string && !strcmp( val.psz_string, CURVAL.psz_string ) );
1386 free( val.psz_string );
1389 case VLC_VAR_INTEGER:
1390 var_Get( p_object, psz_var, &val );
1391 if( CURTEXT ) menutext = qfu( CURTEXT );
1392 else menutext.sprintf( "%d", CURVAL.i_int );
1393 CreateAndConnect( submenu, psz_var, menutext, "", ITEM_RADIO,
1394 p_object, CURVAL, i_type,
1395 ( CURVAL.i_int == val.i_int )
1396 && CheckTitle( p_object, psz_var ) );
1400 var_Get( p_object, psz_var, &val );
1401 if( CURTEXT ) menutext = qfu( CURTEXT );
1402 else menutext.sprintf( "%.2f", CURVAL.f_float );
1403 CreateAndConnect( submenu, psz_var, menutext, "", ITEM_RADIO,
1404 p_object, CURVAL, i_type,
1405 CURVAL.f_float == val.f_float );
1412 currentGroup = NULL;
1414 /* clean up everything */
1415 var_FreeList( &val_list, &text_list );
1419 return submenu->isEmpty() ? VLC_EGENERIC : VLC_SUCCESS;
1422 void QVLCMenu::CreateAndConnect( QMenu *menu, const char *psz_var,
1423 const QString& text, const QString& help,
1424 int i_item_type, vlc_object_t *p_obj,
1425 vlc_value_t val, int i_val_type,
1428 QAction *action = FindActionWithVar( menu, psz_var );
1433 action = new QAction( text, menu );
1434 menu->addAction( action );
1438 action->setToolTip( help );
1439 action->setEnabled( p_obj != NULL );
1441 if( i_item_type == ITEM_CHECK )
1443 action->setCheckable( true );
1445 else if( i_item_type == ITEM_RADIO )
1447 action->setCheckable( true );
1449 currentGroup = new QActionGroup( menu );
1450 currentGroup->addAction( action );
1453 action->setChecked( checked );
1455 MenuItemData *itemData = qFindChild<MenuItemData*>( action, QString() );
1457 itemData = new MenuItemData( action, p_obj, i_val_type, val, psz_var );
1459 /* remove previous signal-slot connection(s) if any */
1460 action->disconnect( );
1462 CONNECT( action, triggered(), THEDP->menusMapper, map() );
1463 THEDP->menusMapper->setMapping( action, itemData );
1466 menu->addAction( action );
1469 void QVLCMenu::DoAction( QObject *data )
1471 MenuItemData *itemData = qobject_cast<MenuItemData *>( data );
1472 vlc_object_t *p_object = itemData->p_obj;
1473 if( p_object == NULL ) return;
1475 /* Preserve settings across vouts via the playlist object: */
1476 if( !strcmp( itemData->psz_var, "fullscreen" )
1477 || !strcmp( itemData->psz_var, "video-on-top" ) )
1478 var_Set( pl_Get( p_object ), itemData->psz_var, itemData->val );
1480 var_Set( p_object, itemData->psz_var, itemData->val );
1483 void QVLCMenu::updateRecents( intf_thread_t *p_intf )
1488 RecentsMRL* rmrl = RecentsMRL::getInstance( p_intf );
1489 QStringList l = rmrl->recents();
1491 recentsMenu->clear();
1495 action = recentsMenu->addAction( qtr(" - Empty - ") );
1496 action->setEnabled( false );
1500 for( int i = 0; i < l.size(); ++i )
1502 action = recentsMenu->addAction(
1503 QString( "&%1: " ).arg( i + 1 ) + l.at( i ),
1504 rmrl->signalMapper, SLOT( map() ),
1505 i <= 9 ? QString( "Ctrl+%1" ).arg( i + 1 ) : "" );
1506 rmrl->signalMapper->setMapping( action, l.at( i ) );
1509 recentsMenu->addSeparator();
1510 recentsMenu->addAction( qtr("&Clear"), rmrl, SLOT( clear() ) );