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>
39 #include "main_interface.hpp" /* View modifications */
40 #include "dialogs_provider.hpp" /* Dialogs display */
41 #include "input_manager.hpp" /* Input Management */
42 #include "recents.hpp" /* Recent Items */
43 #include "actions_manager.hpp"
48 #include <QActionGroup>
49 #include <QSignalMapper>
50 #include <QSystemTrayIcon>
54 This file defines the main menus and the pop-up menu (right-click menu)
55 and the systray menu (in that order in the file)
57 There are 3 menus that have to be rebuilt everytime there are called:
58 Audio, Video, Navigation
59 3 functions are building those menus: AudioMenu, VideoMenu, NavigMenu
60 and 3 functions associated are collecting the objects :
61 InputAutoMenuBuilder, AudioAutoMenuBuilder, VideoAutoMenuBuilder.
63 A QSignalMapper decides when to rebuild those menus cf MenuFunc in the .hpp
64 Just before one of those menus are aboutToShow(), they are rebuild.
67 #define STATIC_ENTRY "__static__"
68 #define ENTRY_ALWAYS_ENABLED "__ignore__"
77 static QActionGroup *currentGroup;
79 QMenu *QVLCMenu::recentsMenu = NULL;
81 /****************************************************************************
83 ****************************************************************************
84 * Add static entries to DP in menus
85 ***************************************************************************/
86 void addDPStaticEntry( QMenu *menu,
90 const char *shortcut = NULL )
92 QAction *action = NULL;
93 if( !EMPTY_STR( icon ) )
95 if( !EMPTY_STR( shortcut ) )
96 action = menu->addAction( QIcon( icon ), text, THEDP,
97 member, qtr( shortcut ) );
99 action = menu->addAction( QIcon( icon ), text, THEDP, member );
103 if( !EMPTY_STR( shortcut ) )
104 action = menu->addAction( text, THEDP, member, qtr( shortcut ) );
106 action = menu->addAction( text, THEDP, member );
108 action->setData( STATIC_ENTRY );
114 QAction* addMIMStaticEntry( intf_thread_t *p_intf,
119 bool bStatic = false )
122 if( strlen( icon ) > 0 )
124 action = menu->addAction( text, THEMIM, member );
125 action->setIcon( QIcon( icon ) );
129 action = menu->addAction( text, THEMIM, member );
131 action->setData( bStatic ? STATIC_ENTRY : ENTRY_ALWAYS_ENABLED );
136 * @brief Enable all static entries, disable the others
137 * @param enable if false, disable all entries
139 void EnableStaticEntries( QMenu *menu, bool enable = true )
143 QList< QAction* > actions = menu->actions();
144 for( int i = 0; i < actions.size(); ++i )
146 actions[i]->setEnabled( actions[i]->data().toString()
147 == ENTRY_ALWAYS_ENABLED ||
148 /* Be careful here, because data("string").toBool is true */
149 ( enable && (actions[i]->data().toString() == STATIC_ENTRY ) ) );
154 * \return Number of static entries
156 int DeleteNonStaticEntries( QMenu *menu )
158 if( !menu ) return VLC_EGENERIC;
162 QList< QAction* > actions = menu->actions();
163 for( int i = 0; i < actions.size(); ++i )
165 if( actions[i]->data().toString() != STATIC_ENTRY )
174 * \return QAction associated to psz_var variable
176 static QAction * FindActionWithVar( QMenu *menu, const char *psz_var )
178 QList< QAction* > actions = menu->actions();
179 for( int i = 0; i < actions.size(); ++i )
181 if( actions[i]->data().toString() == psz_var )
187 /*****************************************************************************
188 * Definitions of variables for the dynamic menus
189 *****************************************************************************/
190 #define PUSH_VAR( var ) varnames.push_back( var ); \
191 objects.push_back( VLC_OBJECT(p_object) )
193 #define PUSH_INPUTVAR( var ) varnames.push_back( var ); \
194 objects.push_back( VLC_OBJECT(p_input) );
196 #define PUSH_SEPARATOR if( objects.size() != i_last_separator ) { \
197 objects.push_back( 0 ); varnames.push_back( "" ); \
198 i_last_separator = objects.size(); }
200 static int InputAutoMenuBuilder( input_thread_t *p_object,
201 vector<vlc_object_t *> &objects,
202 vector<const char *> &varnames )
204 PUSH_VAR( "bookmark" );
206 PUSH_VAR( "chapter" );
207 PUSH_VAR( "navigation" );
208 PUSH_VAR( "program" );
212 static int VideoAutoMenuBuilder( vout_thread_t *p_object,
213 input_thread_t *p_input,
214 vector<vlc_object_t *> &objects,
215 vector<const char *> &varnames )
217 PUSH_INPUTVAR( "video-es" );
218 PUSH_INPUTVAR( "spu-es" );
219 PUSH_VAR( "fullscreen" );
220 PUSH_VAR( "video-on-top" );
222 PUSH_VAR( "directx-wallpaper" );
223 PUSH_VAR( "direct3d-desktop" );
225 PUSH_VAR( "video-snapshot" );
227 PUSH_VAR( "autoscale" );
228 PUSH_VAR( "aspect-ratio" );
230 PUSH_VAR( "deinterlace" );
231 PUSH_VAR( "postprocess" );
236 static int AudioAutoMenuBuilder( aout_instance_t *p_object,
237 input_thread_t *p_input,
238 vector<vlc_object_t *> &objects,
239 vector<const char *> &varnames )
241 PUSH_INPUTVAR( "audio-es" );
242 PUSH_VAR( "audio-channels" );
243 PUSH_VAR( "audio-device" );
244 PUSH_VAR( "visual" );
248 /*****************************************************************************
251 *****************************************************************************/
253 #define BAR_ADD( func, title ) { \
254 QMenu *_menu = func; _menu->setTitle( title ); bar->addMenu( _menu ); }
256 #define BAR_DADD( func, title, id ) { \
257 QMenu *_menu = func; _menu->setTitle( title ); bar->addMenu( _menu ); \
258 MenuFunc *f = new MenuFunc( _menu, id ); \
259 CONNECT( _menu, aboutToShow(), THEDP->menusUpdateMapper, map() ); \
260 THEDP->menusUpdateMapper->setMapping( _menu, f ); }
262 #define ACT_ADD( _menu, val, title ) { \
263 QAction *_action = new QAction( title, _menu ); _action->setData( val ); \
264 _menu->addAction( _action ); }
266 #define ACT_ADDMENU( _menu, val, title ) { \
267 QAction *_action = new QAction( title, _menu ); _action->setData( val ); \
268 _action->setMenu( new QMenu( _menu ) ); _menu->addAction( _action ); }
270 #define ACT_ADDCHECK( _menu, val, title ) { \
271 QAction *_action = new QAction( title, _menu ); _action->setData( val ); \
272 _action->setCheckable( true ); _menu->addAction( _action ); }
275 * Main Menu Bar Creation
277 void QVLCMenu::createMenuBar( MainInterface *mi,
278 intf_thread_t *p_intf )
280 /* QMainWindows->menuBar()
281 gives the QProcess::destroyed timeout issue on Cleanlooks style with
282 setDesktopAware set to false */
283 QMenuBar *bar = mi->menuBar();
285 BAR_ADD( FileMenu( p_intf, bar ), qtr( "&Media" ) );
287 /* Dynamic menus, rebuilt before being showed */
288 BAR_DADD( NavigMenu( p_intf, bar ), qtr( "P&layback" ), 3 );
289 BAR_DADD( AudioMenu( p_intf, bar ), qtr( "&Audio" ), 1 );
290 BAR_DADD( VideoMenu( p_intf, bar ), qtr( "&Video" ), 2 );
292 BAR_ADD( ToolsMenu( bar ), qtr( "&Tools" ) );
293 BAR_ADD( ViewMenu( p_intf, mi ), qtr( "V&iew" ) );
294 BAR_ADD( HelpMenu( bar ), qtr( "&Help" ) );
300 * Media ( File ) Menu
301 * Opening, streaming and quit
303 QMenu *QVLCMenu::FileMenu( intf_thread_t *p_intf, QWidget *parent )
305 QMenu *menu = new QMenu( parent );
307 addDPStaticEntry( menu, qtr( "&Open File..." ),
308 ":/type/file-asym", SLOT( simpleOpenDialog() ), "Ctrl+O" );
309 addDPStaticEntry( menu, qtr( "Advanced Open File..." ),
310 ":/type/file-asym", SLOT( openFileDialog() ), "Ctrl+Shift+O" );
311 addDPStaticEntry( menu, qtr( I_OPEN_FOLDER ),
312 ":/type/folder-grey", SLOT( PLOpenDir() ), "Ctrl+F" );
313 addDPStaticEntry( menu, qtr( "Open &Disc..." ),
314 ":/type/disc", SLOT( openDiscDialog() ), "Ctrl+D" );
315 addDPStaticEntry( menu, qtr( "Open &Network Stream..." ),
316 ":/type/network", SLOT( openNetDialog() ), "Ctrl+N" );
317 addDPStaticEntry( menu, qtr( "Open &Capture Device..." ),
318 ":/type/capture-card", SLOT( openCaptureDialog() ),
321 menu->addSeparator();
322 addDPStaticEntry( menu, qtr( "Open &Location from clipboard" ),
323 NULL, SLOT( openUrlDialog() ), "Ctrl+V" );
325 if( config_GetInt( p_intf, "qt-recentplay" ) )
327 recentsMenu = new QMenu( qtr( "&Recent Media" ), menu );
328 updateRecents( p_intf );
329 menu->addMenu( recentsMenu );
331 menu->addMenu( SDMenu( p_intf, menu ) );
332 menu->addSeparator();
334 addDPStaticEntry( menu, qtr( I_PL_SAVE ), "", SLOT( saveAPlaylist() ),
336 menu->addSeparator();
339 addDPStaticEntry( menu, qtr( "Conve&rt / Save..." ), "",
340 SLOT( openAndTranscodingDialogs() ), "Ctrl+R" );
341 addDPStaticEntry( menu, qtr( "&Streaming..." ),
342 ":/menu/stream", SLOT( openAndStreamingDialogs() ),
344 menu->addSeparator();
347 addDPStaticEntry( menu, qtr( "&Quit" ) ,
348 ":/menu/quit", SLOT( quit() ), "Ctrl+Q" );
353 * Tools, like Media Information, Preferences or Messages
355 QMenu *QVLCMenu::ToolsMenu( QMenu *menu )
357 addDPStaticEntry( menu, qtr( "&Effects and Filters"), ":/menu/settings",
358 SLOT( extendedDialog() ), "Ctrl+E" );
360 addDPStaticEntry( menu, qtr( "&Track Synchronization"), ":/menu/settings",
361 SLOT( synchroDialog() ), "" );
363 addDPStaticEntry( menu, qtr( I_MENU_INFO ) , ":/menu/info",
364 SLOT( mediaInfoDialog() ), "Ctrl+I" );
365 addDPStaticEntry( menu, qtr( I_MENU_CODECINFO ) ,
366 ":/menu/info", SLOT( mediaCodecDialog() ), "Ctrl+J" );
368 addDPStaticEntry( menu, qtr( I_MENU_BOOKMARK ),"",
369 SLOT( bookmarksDialog() ), "Ctrl+B" );
371 addDPStaticEntry( menu, qtr( I_MENU_VLM ), "", SLOT( vlmDialog() ),
375 addDPStaticEntry( menu, qtr( I_MENU_MSG ),
376 ":/menu/messages", SLOT( messagesDialog() ),
379 addDPStaticEntry( menu, qtr( "Plu&gins and extensions" ),
380 "", SLOT( pluginDialog() ) );
381 menu->addSeparator();
383 addDPStaticEntry( menu, qtr( "&Preferences" ),
384 ":/menu/preferences", SLOT( prefsDialog() ), "Ctrl+P" );
389 QMenu *QVLCMenu::ToolsMenu( QWidget *parent )
391 return ToolsMenu( new QMenu( parent ) );
396 * Interface Modification
398 QMenu *QVLCMenu::ViewMenu( intf_thread_t *p_intf,
404 QMenu *menu = new QMenu( qtr( "V&iew" ), mi );
406 QAction *act = menu->addAction( QIcon( ":/menu/playlist_menu" ),
407 qtr( "Play&list" ), mi,
408 SLOT( togglePlaylist() ), qtr( "Ctrl+L" ) );
410 /*menu->addSeparator();
411 menu->addAction( qtr( "Undock from Interface" ), mi,
412 SLOT( undockPlaylist() ), qtr( "Ctrl+U" ) );*/
414 menu->addSeparator();
418 QMenu *intfmenu = InterfacesMenu( p_intf, menu );
419 MenuFunc *f = new MenuFunc( intfmenu, 4 );
420 CONNECT( intfmenu, aboutToShow(), THEDP->menusUpdateMapper, map() );
421 THEDP->menusUpdateMapper->setMapping( intfmenu, f );
422 menu->addSeparator();
426 QAction *action = menu->addAction( qtr( "Mi&nimal View" ) );
427 action->setShortcut( qtr( "Ctrl+H" ) );
428 action->setCheckable( true );
429 action->setChecked( !with_intf &&
430 (mi->getControlsVisibilityStatus() & CONTROLS_HIDDEN ) );
432 CONNECT( action, triggered( bool ), mi, toggleMinimalView( bool ) );
433 CONNECT( mi, minimalViewToggled( bool ), action, setChecked( bool ) );
435 /* FullScreen View */
436 action = menu->addAction( qtr( "&Fullscreen Interface" ), mi,
437 SLOT( toggleFullScreen() ), QString( "F11" ) );
438 action->setCheckable( true );
439 action->setChecked( mi->isFullScreen() );
440 CONNECT( mi, fullscreenInterfaceToggled( bool ),
441 action, setChecked( bool ) );
443 /* Advanced Controls */
444 action = menu->addAction( qtr( "&Advanced Controls" ), mi,
445 SLOT( toggleAdvanced() ) );
446 action->setCheckable( true );
447 if( mi->getControlsVisibilityStatus() & CONTROLS_ADVANCED )
448 action->setChecked( true );
451 // I don't want to manage consistency between menus, so no popup-menu
453 action = menu->addAction( qtr( "Quit after Playback" ) );
454 action->setCheckable( true );
455 CONNECT( action, triggered( bool ), THEMIM, activatePlayQuit( bool ) );
458 #if 0 /* For Visualisations. Not yet working */
459 adv = menu->addAction( qtr( "Visualizations selector" ),
460 mi, SLOT( visual() ) );
461 adv->setCheckable( true );
462 if( visual_selector_enabled ) adv->setChecked( true );
465 menu->addSeparator();
466 addDPStaticEntry( menu, qtr( "Customi&ze Interface..." ),
467 ":/menu/preferences", SLOT( toolbarDialog() ) );
468 menu->addSeparator();
474 * Interface Sub-Menu, to list extras interface and skins
476 QMenu *QVLCMenu::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
478 vector<vlc_object_t *> objects;
479 vector<const char *> varnames;
480 varnames.push_back( "intf-add" );
481 objects.push_back( VLC_OBJECT(p_intf) );
483 return Populate( p_intf, current, varnames, objects );
489 QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QMenu * current )
491 vector<vlc_object_t *> objects;
492 vector<const char *> varnames;
493 aout_instance_t *p_aout;
494 input_thread_t *p_input;
496 if( current->isEmpty() )
498 ACT_ADDMENU( current, "audio-es", qtr( "Audio &Track" ) );
499 ACT_ADDMENU( current, "audio-channels", qtr( "Audio &Channels" ) );
500 ACT_ADDMENU( current, "audio-device", qtr( "Audio &Device" ) );
501 current->addSeparator();
503 ACT_ADDMENU( current, "visual", qtr( "&Visualizations" ) );
504 current->addSeparator();
506 QAction *action = current->addAction( qtr( "Increase Volume" ),
507 ActionsManager::getInstance( p_intf ), SLOT( AudioUp() ) );
508 action->setData( STATIC_ENTRY );
509 action = current->addAction( qtr( "Decrease Volume" ),
510 ActionsManager::getInstance( p_intf ), SLOT( AudioDown() ) );
511 action->setData( STATIC_ENTRY );
512 action = current->addAction( qtr( "Mute" ),
513 ActionsManager::getInstance( p_intf ), SLOT( toggleMuteAudio() ) );
514 action->setData( STATIC_ENTRY );
517 p_input = THEMIM->getInput();
518 p_aout = THEMIM->getAout();
519 EnableStaticEntries( current, ( p_aout != NULL ) );
520 AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
523 vlc_object_release( p_aout );
526 return Populate( p_intf, current, varnames, objects );
529 QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QWidget *parent )
531 return AudioMenu( p_intf, new QMenu( parent ) );
536 * Subtitles are part of Video.
538 QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current )
540 vout_thread_t *p_vout;
541 input_thread_t *p_input;
542 vector<vlc_object_t *> objects;
543 vector<const char *> varnames;
545 if( current->isEmpty() )
547 ACT_ADDMENU( current, "video-es", qtr( "Video &Track" ) );
550 QMenu *submenu = new QMenu( qtr( "&Subtitles Track" ), current );
551 action = current->addMenu( submenu );
552 action->setData( "spu-es" );
553 addDPStaticEntry( submenu, qtr( "Open File..." ), "",
554 SLOT( loadSubtitlesFile() ) );
555 submenu->addSeparator();
556 current->addSeparator();
558 ACT_ADDCHECK( current, "fullscreen", qtr( "&Fullscreen" ) );
559 ACT_ADDCHECK( current, "video-on-top", qtr( "Always &On Top" ) );
561 ACT_ADDCHECK( current, "directx-wallpaper", qtr( "DirectX Wallpaper" ) );
562 ACT_ADDCHECK( current, "direct3d-desktop", qtr( "Direct3D Desktop mode" ) );
564 ACT_ADD( current, "video-snapshot", qtr( "Sna&pshot" ) );
566 current->addSeparator();
568 ACT_ADDMENU( current, "zoom", qtr( "&Zoom" ) );
569 ACT_ADDCHECK( current, "autoscale", qtr( "Sca&le" ) );
570 ACT_ADDMENU( current, "aspect-ratio", qtr( "&Aspect Ratio" ) );
571 ACT_ADDMENU( current, "crop", qtr( "&Crop" ) );
572 ACT_ADDMENU( current, "deinterlace", qtr( "&Deinterlace" ) );
573 ACT_ADDMENU( current, "postprocess", qtr( "&Post processing" ) );
576 p_input = THEMIM->getInput();
578 p_vout = THEMIM->getVout();
579 VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
582 vlc_object_release( p_vout );
584 return Populate( p_intf, current, varnames, objects );
587 QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QWidget *parent )
589 return VideoMenu( p_intf, new QMenu( parent ) );
594 * For DVD, MP4, MOV and other chapter based format
596 QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *menu )
600 QMenu *submenu = new QMenu( qtr( "&Bookmarks" ), menu );
601 addDPStaticEntry( submenu, qtr( "Manage &bookmarks" ), "",
602 SLOT( bookmarksDialog() ) );
603 submenu->addSeparator();
604 action = menu->addMenu( submenu );
605 action->setData( "bookmark" );
607 ACT_ADDMENU( menu, "title", qtr( "T&itle" ) );
608 ACT_ADDMENU( menu, "chapter", qtr( "&Chapter" ) );
609 ACT_ADDMENU( menu, "navigation", qtr( "&Navigation" ) );
610 ACT_ADDMENU( menu, "program", qtr( "&Program" ) );
612 menu->addSeparator();
613 PopupMenuPlaylistControlEntries( menu, p_intf );
614 PopupMenuControlEntries( menu, p_intf );
616 EnableStaticEntries( menu, ( THEMIM->getInput() != NULL ) );
617 return RebuildNavigMenu( p_intf, menu );
620 QMenu *QVLCMenu::RebuildNavigMenu( intf_thread_t *p_intf, QMenu *menu )
623 input_thread_t *p_object;
624 vector<vlc_object_t *> objects;
625 vector<const char *> varnames;
627 /* Get the input and hold it */
628 p_object = THEMIM->getInput();
630 InputAutoMenuBuilder( p_object, objects, varnames );
632 menu->addSeparator();
634 /* Title and so on */
635 PUSH_VAR( "prev-title" );
636 PUSH_VAR( "next-title" );
637 PUSH_VAR( "prev-chapter" );
638 PUSH_VAR( "next-chapter" );
640 EnableStaticEntries( menu, (p_object != NULL ) );
641 return Populate( p_intf, menu, varnames, objects );
644 QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QWidget *parent )
646 return NavigMenu( p_intf, new QMenu( parent ) );
650 * Service Discovery SubMenu
652 QMenu *QVLCMenu::SDMenu( intf_thread_t *p_intf, QWidget *parent )
654 QMenu *menu = new QMenu( parent );
655 menu->setTitle( qtr( I_PL_SD ) );
657 char **ppsz_longnames;
658 char **ppsz_names = vlc_sd_GetNames( &ppsz_longnames );
662 char **ppsz_name = ppsz_names, **ppsz_longname = ppsz_longnames;
663 for( ; *ppsz_name; ppsz_name++, ppsz_longname++ )
665 QAction *a = new QAction( qfu( *ppsz_longname ), menu );
666 a->setCheckable( true );
667 if( playlist_IsServicesDiscoveryLoaded( THEPL, *ppsz_name ) )
668 a->setChecked( true );
669 CONNECT( a, triggered(), THEDP->SDMapper, map() );
670 THEDP->SDMapper->setMapping( a, QString( *ppsz_name ) );
671 menu->addAction( a );
673 /* Special case for podcast */
674 if( !strcmp( *ppsz_name, "podcast" ) )
676 QAction *b = new QAction( qtr( "Configure podcasts..." ), menu );
677 //b->setEnabled( a->isChecked() );
678 menu->addAction( b );
679 CONNECT( b, triggered(), THEDP, podcastConfigureDialog() );
682 free( *ppsz_longname );
685 free( ppsz_longnames );
692 QMenu *QVLCMenu::HelpMenu( QWidget *parent )
694 QMenu *menu = new QMenu( parent );
695 addDPStaticEntry( menu, qtr( "&Help..." ) ,
696 ":/menu/help", SLOT( helpDialog() ), "F1" );
698 addDPStaticEntry( menu, qtr( "Check for &Updates..." ) , "",
699 SLOT( updateDialog() ) );
701 menu->addSeparator();
702 addDPStaticEntry( menu, qtr( I_MENU_ABOUT ), ":/menu/info",
703 SLOT( aboutDialog() ), "Shift+F1" );
707 /*****************************************************************************
708 * Popup menus - Right Click menus *
709 *****************************************************************************/
710 #define POPUP_BOILERPLATE \
711 unsigned int i_last_separator = 0; \
712 vector<vlc_object_t *> objects; \
713 vector<const char *> varnames; \
714 input_thread_t *p_input = THEMIM->getInput();
716 #define CREATE_POPUP \
717 Populate( p_intf, menu, varnames, objects ); \
718 p_intf->p_sys->p_popup_menu = menu; \
719 menu->popup( QCursor::pos() ); \
720 p_intf->p_sys->p_popup_menu = NULL; \
721 i_last_separator = 0;
723 void QVLCMenu::PopupPlayEntries( QMenu *menu,
724 intf_thread_t *p_intf,
725 input_thread_t *p_input )
729 /* Play or Pause action and icon */
730 if( !p_input || var_GetInteger( p_input, "state" ) != PLAYING_S )
732 action = menu->addAction( qtr( "Play" ),
733 ActionsManager::getInstance( p_intf ), SLOT( play() ) );
734 action->setIcon( QIcon( ":/menu/play" ) );
738 addMIMStaticEntry( p_intf, menu, qtr( "Pause" ),
739 ":/menu/pause", SLOT( togglePlayPause() ) );
743 void QVLCMenu::PopupMenuControlEntries( QMenu *menu, intf_thread_t *p_intf )
748 action = menu->addAction( qtr( "&Faster" ), THEMIM->getIM(),
750 action->setIcon( QIcon( ":/toolbar/faster") );
751 action->setData( STATIC_ENTRY );
753 action = menu->addAction( qtr( "Faster (fine)" ), THEMIM->getIM(),
754 SLOT( littlefaster() ) );
755 action->setData( STATIC_ENTRY );
757 action = menu->addAction( qtr( "N&ormal Speed" ), THEMIM->getIM(),
758 SLOT( normalRate() ) );
759 action->setData( STATIC_ENTRY );
761 action = menu->addAction( qtr( "Slower (fine)" ), THEMIM->getIM(),
762 SLOT( littleslower() ) );
763 action->setData( STATIC_ENTRY );
765 action = menu->addAction( qtr( "Slo&wer" ), THEMIM->getIM(),
767 action->setIcon( QIcon( ":/toolbar/slower") );
768 action->setData( STATIC_ENTRY );
770 menu->addSeparator();
772 action = menu->addAction( qtr( "&Jump Forward" ), THEMIM->getIM(),
774 action->setIcon( QIcon( ":/toolbar/skip_fw") );
775 action->setData( STATIC_ENTRY );
777 action = menu->addAction( qtr( "Jump Bac&kward" ), THEMIM->getIM(),
779 action->setIcon( QIcon( ":/toolbar/skip_back") );
780 action->setData( STATIC_ENTRY );
781 addDPStaticEntry( menu, qtr( I_MENU_GOTOTIME ),"",
782 SLOT( gotoTimeDialog() ), "Ctrl+T" );
783 menu->addSeparator();
787 void QVLCMenu::PopupMenuPlaylistControlEntries( QMenu *menu,
788 intf_thread_t *p_intf )
790 bool bEnable = THEMIM->getInput() != NULL;
792 addMIMStaticEntry( p_intf, menu, qtr( "&Stop" ), ":/menu/stop",
793 SLOT( stop() ), true );
794 /* Disable Stop in the right-click popup menu */
796 action->setEnabled( false );
798 /* Next / Previous */
799 addMIMStaticEntry( p_intf, menu, qtr( "Pre&vious" ),
800 ":/menu/previous", SLOT( prev() ) );
801 addMIMStaticEntry( p_intf, menu, qtr( "Ne&xt" ),
802 ":/menu/next", SLOT( next() ) );
803 menu->addSeparator();
806 void QVLCMenu::PopupMenuStaticEntries( QMenu *menu )
808 QMenu *openmenu = new QMenu( qtr( "Open Media" ), menu );
809 addDPStaticEntry( openmenu, qtr( "&Open File..." ),
810 ":/type/file-asym", SLOT( openFileDialog() ) );
811 addDPStaticEntry( openmenu, qtr( I_OPEN_FOLDER ),
812 ":/type/folder-grey", SLOT( PLOpenDir() ) );
813 addDPStaticEntry( openmenu, qtr( "Open &Disc..." ),
814 ":/type/disc", SLOT( openDiscDialog() ) );
815 addDPStaticEntry( openmenu, qtr( "Open &Network..." ),
816 ":/type/network", SLOT( openNetDialog() ) );
817 addDPStaticEntry( openmenu, qtr( "Open &Capture Device..." ),
818 ":/type/capture-card", SLOT( openCaptureDialog() ) );
819 menu->addMenu( openmenu );
821 menu->addSeparator();
823 QMenu *helpmenu = HelpMenu( menu );
824 helpmenu->setTitle( qtr( "Help" ) );
825 menu->addMenu( helpmenu );
828 addDPStaticEntry( menu, qtr( "Quit" ), ":/menu/quit",
829 SLOT( quit() ), "Ctrl+Q" );
832 /* Video Tracks and Subtitles tracks */
833 void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf )
838 vout_thread_t *p_vout = THEMIM->getVout();
841 VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
842 vlc_object_release( p_vout );
845 QMenu *menu = new QMenu();
850 void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf )
855 aout_instance_t *p_aout = THEMIM->getAout();
856 AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
858 vlc_object_release( p_aout );
860 QMenu *menu = new QMenu();
864 /* Navigation stuff, and general menus ( open ), used only for skins */
865 void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf )
871 varnames.push_back( "audio-es" );
872 InputAutoMenuBuilder( p_input, objects, varnames );
876 QMenu *menu = new QMenu();
877 Populate( p_intf, menu, varnames, objects );
879 menu->addSeparator();
880 PopupPlayEntries( menu, p_intf, p_input );
881 PopupMenuPlaylistControlEntries( menu, p_intf);
883 menu->addSeparator();
884 PopupMenuControlEntries( menu, p_intf );
886 menu->addSeparator();
887 PopupMenuStaticEntries( menu );
889 p_intf->p_sys->p_popup_menu = menu;
890 menu->popup( QCursor::pos() );
891 p_intf->p_sys->p_popup_menu = NULL;
894 /* Main Menu that sticks everything together */
895 void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show )
897 /* Delete old popup if there is one */
898 delete p_intf->p_sys->p_popup_menu;
902 p_intf->p_sys->p_popup_menu = NULL;
907 QMenu *menu = new QMenu();
909 bool b_isFullscreen = false;
910 MainInterface *mi = p_intf->p_sys->p_mi;
914 PopupPlayEntries( menu, p_intf, p_input );
915 PopupMenuPlaylistControlEntries( menu, p_intf );
916 menu->addSeparator();
921 vout_thread_t *p_vout = THEMIM->getVout();
923 /* Add a fullscreen switch button, since it is the most used function */
926 vlc_value_t val; var_Get( p_vout, "fullscreen", &val );
928 b_isFullscreen = !( !val.b_bool );
930 CreateAndConnect( menu, "fullscreen",
931 qtr( "Leave Fullscreen" ),"" , ITEM_NORMAL,
932 VLC_OBJECT(p_vout), val, VLC_VAR_BOOL, b_isFullscreen );
933 vlc_object_release( p_vout );
935 menu->addSeparator();
939 InputAutoMenuBuilder( p_input, objects, varnames );
942 submenu = new QMenu( menu );
943 action = menu->addMenu( AudioMenu( p_intf, submenu ) );
944 action->setText( qtr( "&Audio" ) );
945 if( action->menu()->isEmpty() )
946 action->setEnabled( false );
949 submenu = new QMenu( menu );
950 action = menu->addMenu( VideoMenu( p_intf, submenu ) );
951 action->setText( qtr( "&Video" ) );
952 if( action->menu()->isEmpty() )
953 action->setEnabled( false );
955 /* Playback menu for chapters */
956 submenu = new QMenu( menu );
957 action = menu->addMenu( NavigMenu( p_intf, submenu ) );
958 action->setText( qtr( "&Playback" ) );
959 if( action->menu()->isEmpty() )
960 action->setEnabled( false );
963 menu->addSeparator();
965 /* Add some special entries for windowed mode: Interface Menu */
966 if( !b_isFullscreen )
968 QMenu *submenu = new QMenu( qtr( "Interface" ), menu );
969 QMenu *tools = ToolsMenu( submenu );
970 submenu->addSeparator();
972 /* In skins interface, append some items */
975 if( p_intf->p_sys->b_isDialogProvider )
977 vlc_object_t* p_object = p_intf->p_parent;
979 objects.clear(); varnames.clear();
980 objects.push_back( p_object );
981 varnames.push_back( "intf-skins" );
982 Populate( p_intf, submenu, varnames, objects );
984 objects.clear(); varnames.clear();
985 objects.push_back( p_object );
986 varnames.push_back( "intf-skins-interactive" );
987 Populate( p_intf, submenu, varnames, objects );
990 msg_Warn( p_intf, "could not find parent interface" );
993 menu->addMenu( ViewMenu( p_intf, mi, false ));
995 menu->addMenu( submenu );
998 /* Static entries for ending, like open */
999 PopupMenuStaticEntries( menu );
1001 p_intf->p_sys->p_popup_menu = menu;
1002 p_intf->p_sys->p_popup_menu->popup( QCursor::pos() );
1009 /************************************************************************
1011 ************************************************************************/
1013 void QVLCMenu::updateSystrayMenu( MainInterface *mi,
1014 intf_thread_t *p_intf,
1015 bool b_force_visible )
1019 /* Get the systray menu and clean it */
1020 QMenu *sysMenu = mi->getSysTrayMenu();
1023 /* Hide / Show VLC and cone */
1024 if( mi->isVisible() || b_force_visible )
1026 sysMenu->addAction( QIcon( ":/logo/vlc16.png" ),
1027 qtr( "Hide VLC media player in taskbar" ), mi,
1028 SLOT( toggleUpdateSystrayMenu() ) );
1032 sysMenu->addAction( QIcon( ":/logo/vlc16.png" ),
1033 qtr( "Show VLC media player" ), mi,
1034 SLOT( toggleUpdateSystrayMenu() ) );
1037 sysMenu->addSeparator();
1038 PopupPlayEntries( sysMenu, p_intf, p_input );
1039 PopupMenuPlaylistControlEntries( sysMenu, p_intf);
1040 PopupMenuControlEntries( sysMenu, p_intf);
1042 sysMenu->addSeparator();
1043 addDPStaticEntry( sysMenu, qtr( "&Open Media" ),
1044 ":/type/file-wide", SLOT( openFileDialog() ) );
1045 addDPStaticEntry( sysMenu, qtr( "&Quit" ) ,
1046 ":/menu/quit", SLOT( quit() ) );
1049 mi->getSysTray()->setContextMenu( sysMenu );
1053 #undef POPUP_BOILERPLATE
1056 #undef PUSH_SEPARATOR
1058 /*************************************************************************
1059 * Builders for automenus
1060 *************************************************************************/
1061 QMenu * QVLCMenu::Populate( intf_thread_t *p_intf,
1063 vector< const char *> & varnames,
1064 vector<vlc_object_t *> & objects )
1066 QMenu *menu = current;
1069 currentGroup = NULL;
1071 vlc_object_t *p_object;
1073 for( int i = 0; i < ( int )objects.size() ; i++ )
1075 if( !varnames[i] || !*varnames[i] )
1077 menu->addSeparator();
1080 p_object = objects[i];
1082 UpdateItem( p_intf, menu, varnames[i], p_object, true );
1087 /*****************************************************************************
1089 *****************************************************************************/
1091 static bool IsMenuEmpty( const char *psz_var,
1092 vlc_object_t *p_object,
1093 bool b_root = true )
1095 vlc_value_t val, val_list;
1096 int i_type, i_result, i;
1098 /* Check the type of the object variable */
1099 i_type = var_Type( p_object, psz_var );
1101 /* Check if we want to display the variable */
1102 if( !( i_type & VLC_VAR_HASCHOICE ) ) return false;
1104 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
1105 if( val.i_int == 0 ) return true;
1107 if( ( i_type & VLC_VAR_TYPE ) != VLC_VAR_VARIABLE )
1109 if( val.i_int == 1 && b_root ) return true;
1113 /* Check children variables in case of VLC_VAR_VARIABLE */
1114 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
1119 for( i = 0, i_result = true; i < val_list.p_list->i_count; i++ )
1121 if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
1129 /* clean up everything */
1130 var_FreeList( &val_list, NULL );
1135 #define TEXT_OR_VAR qfu ( text.psz_string ? text.psz_string : psz_var )
1137 void QVLCMenu::UpdateItem( intf_thread_t *p_intf, QMenu *menu,
1138 const char *psz_var, vlc_object_t *p_object, bool b_submenu )
1140 vlc_value_t val, text;
1143 QAction *action = FindActionWithVar( menu, psz_var );
1145 DeleteNonStaticEntries( action->menu() );
1150 action->setEnabled( false );
1154 /* Check the type of the object variable */
1155 /* This HACK is needed so we have a radio button for audio and video tracks
1156 instread of a checkbox */
1157 if( !strcmp( psz_var, "audio-es" )
1158 || !strcmp( psz_var, "video-es" ) )
1159 i_type = VLC_VAR_INTEGER | VLC_VAR_HASCHOICE;
1161 i_type = var_Type( p_object, psz_var );
1163 switch( i_type & VLC_VAR_TYPE )
1167 case VLC_VAR_VARIABLE:
1168 case VLC_VAR_STRING:
1169 case VLC_VAR_INTEGER:
1173 /* Variable doesn't exist or isn't handled */
1175 action->setEnabled( false );
1179 /* Make sure we want to display the variable */
1180 if( menu->isEmpty() && IsMenuEmpty( psz_var, p_object ) )
1183 action->setEnabled( false );
1187 /* Get the descriptive name of the variable */
1188 int i_ret = var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
1189 if( i_ret != VLC_SUCCESS )
1191 text.psz_string = NULL;
1196 action = new QAction( TEXT_OR_VAR, menu );
1197 menu->addAction( action );
1198 action->setData( psz_var );
1201 /* Some specific stuff */
1202 bool forceDisabled = false;
1203 if( !strcmp( psz_var, "spu-es" ) )
1205 vout_thread_t *p_vout = THEMIM->getVout();
1206 forceDisabled = ( p_vout == NULL );
1208 vlc_object_release( p_vout );
1211 if( i_type & VLC_VAR_HASCHOICE )
1213 /* Append choices menu */
1217 submenu = action->menu();
1220 submenu = new QMenu( menu );
1221 action->setMenu( submenu );
1225 CreateChoicesMenu( submenu, psz_var, p_object, true ) == 0 );
1227 action->setEnabled( false );
1232 CreateChoicesMenu( menu, psz_var, p_object, true ) == 0 );
1234 FREENULL( text.psz_string );
1238 switch( i_type & VLC_VAR_TYPE )
1241 var_Get( p_object, psz_var, &val );
1242 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_NORMAL,
1243 p_object, val, i_type );
1247 var_Get( p_object, psz_var, &val );
1248 val.b_bool = !val.b_bool;
1249 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_CHECK,
1250 p_object, val, i_type, !val.b_bool );
1253 FREENULL( text.psz_string );
1258 /** HACK for the navigation submenu:
1259 * "title %2i" variables take the value 0 if not set
1261 static bool CheckTitle( vlc_object_t *p_object, const char *psz_var )
1264 if( sscanf( psz_var, "title %2i", &i_title ) <= 0 )
1267 int i_current_title = var_GetInteger( p_object, "title" );
1268 return ( i_title == i_current_title );
1272 int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
1273 vlc_object_t *p_object, bool b_root )
1275 vlc_value_t val, val_list, text_list;
1278 /* Check the type of the object variable */
1279 i_type = var_Type( p_object, psz_var );
1281 /* Make sure we want to display the variable */
1282 if( submenu->isEmpty() && IsMenuEmpty( psz_var, p_object, b_root ) )
1283 return VLC_EGENERIC;
1285 switch( i_type & VLC_VAR_TYPE )
1289 case VLC_VAR_VARIABLE:
1290 case VLC_VAR_STRING:
1291 case VLC_VAR_INTEGER:
1295 /* Variable doesn't exist or isn't handled */
1296 return VLC_EGENERIC;
1299 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
1300 &val_list, &text_list ) < 0 )
1302 return VLC_EGENERIC;
1305 #define CURVAL val_list.p_list->p_values[i]
1306 #define CURTEXT text_list.p_list->p_values[i].psz_string
1308 for( i = 0; i < val_list.p_list->i_count; i++ )
1310 vlc_value_t another_val;
1312 QMenu *subsubmenu = new QMenu( submenu );
1314 switch( i_type & VLC_VAR_TYPE )
1316 case VLC_VAR_VARIABLE:
1317 CreateChoicesMenu( subsubmenu, CURVAL.psz_string, p_object, false );
1318 subsubmenu->setTitle( qfu( CURTEXT ? CURTEXT :CURVAL.psz_string ) );
1319 submenu->addMenu( subsubmenu );
1322 case VLC_VAR_STRING:
1323 var_Get( p_object, psz_var, &val );
1324 another_val.psz_string = strdup( CURVAL.psz_string );
1325 menutext = qfu( CURTEXT ? CURTEXT : another_val.psz_string );
1326 CreateAndConnect( submenu, psz_var, menutext, "", ITEM_RADIO,
1327 p_object, another_val, i_type,
1328 val.psz_string && !strcmp( val.psz_string, CURVAL.psz_string ) );
1330 free( val.psz_string );
1333 case VLC_VAR_INTEGER:
1334 var_Get( p_object, psz_var, &val );
1335 if( CURTEXT ) menutext = qfu( CURTEXT );
1336 else menutext.sprintf( "%d", CURVAL.i_int );
1337 CreateAndConnect( submenu, psz_var, menutext, "", ITEM_RADIO,
1338 p_object, CURVAL, i_type,
1339 ( CURVAL.i_int == val.i_int )
1340 && CheckTitle( p_object, psz_var ) );
1344 var_Get( p_object, psz_var, &val );
1345 if( CURTEXT ) menutext = qfu( CURTEXT );
1346 else menutext.sprintf( "%.2f", CURVAL.f_float );
1347 CreateAndConnect( submenu, psz_var, menutext, "", ITEM_RADIO,
1348 p_object, CURVAL, i_type,
1349 CURVAL.f_float == val.f_float );
1356 currentGroup = NULL;
1358 /* clean up everything */
1359 var_FreeList( &val_list, &text_list );
1363 return submenu->isEmpty() ? VLC_EGENERIC : VLC_SUCCESS;
1366 void QVLCMenu::CreateAndConnect( QMenu *menu, const char *psz_var,
1367 const QString& text, const QString& help,
1368 int i_item_type, vlc_object_t *p_obj,
1369 vlc_value_t val, int i_val_type,
1372 QAction *action = FindActionWithVar( menu, psz_var );
1377 action = new QAction( text, menu );
1378 menu->addAction( action );
1382 action->setToolTip( help );
1383 action->setEnabled( p_obj != NULL );
1385 if( i_item_type == ITEM_CHECK )
1387 action->setCheckable( true );
1389 else if( i_item_type == ITEM_RADIO )
1391 action->setCheckable( true );
1393 currentGroup = new QActionGroup( menu );
1394 currentGroup->addAction( action );
1397 action->setChecked( checked );
1399 MenuItemData *itemData = new MenuItemData( THEDP->menusMapper, p_obj, i_val_type,
1402 /* remove previous signal-slot connection(s) if any */
1403 action->disconnect( );
1405 CONNECT( action, triggered(), THEDP->menusMapper, map() );
1406 THEDP->menusMapper->setMapping( action, itemData );
1409 menu->addAction( action );
1412 void QVLCMenu::DoAction( QObject *data )
1414 MenuItemData *itemData = qobject_cast<MenuItemData *>( data );
1415 vlc_object_t *p_object = itemData->p_obj;
1416 if( p_object == NULL ) return;
1418 var_Set( p_object, itemData->psz_var, itemData->val );
1421 void QVLCMenu::updateRecents( intf_thread_t *p_intf )
1426 RecentsMRL* rmrl = RecentsMRL::getInstance( p_intf );
1427 QList<QString> l = rmrl->recents();
1429 recentsMenu->clear();
1433 action = recentsMenu->addAction( qtr(" - Empty - ") );
1434 action->setEnabled( false );
1438 for( int i = 0; i < l.size(); ++i )
1440 action = recentsMenu->addAction(
1441 QString( "&%1: " ).arg( i + 1 ) + l.at( i ),
1444 rmrl->signalMapper->setMapping( action, l.at( i ) );
1447 recentsMenu->addSeparator();
1448 recentsMenu->addAction( qtr("&Clear"), rmrl, SLOT( clear() ) );