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" );
224 PUSH_VAR( "video-snapshot" );
226 PUSH_VAR( "autoscale" );
227 PUSH_VAR( "aspect-ratio" );
229 PUSH_VAR( "deinterlace" );
230 PUSH_VAR( "postprocess" );
235 static int AudioAutoMenuBuilder( aout_instance_t *p_object,
236 input_thread_t *p_input,
237 vector<vlc_object_t *> &objects,
238 vector<const char *> &varnames )
240 PUSH_INPUTVAR( "audio-es" );
241 PUSH_VAR( "audio-channels" );
242 PUSH_VAR( "audio-device" );
243 PUSH_VAR( "visual" );
247 /*****************************************************************************
250 *****************************************************************************/
252 #define BAR_ADD( func, title ) { \
253 QMenu *_menu = func; _menu->setTitle( title ); bar->addMenu( _menu ); }
255 #define BAR_DADD( func, title, id ) { \
256 QMenu *_menu = func; _menu->setTitle( title ); bar->addMenu( _menu ); \
257 MenuFunc *f = new MenuFunc( _menu, id ); \
258 CONNECT( _menu, aboutToShow(), THEDP->menusUpdateMapper, map() ); \
259 THEDP->menusUpdateMapper->setMapping( _menu, f ); }
261 #define ACT_ADD( _menu, val, title ) { \
262 QAction *_action = new QAction( title, _menu ); _action->setData( val ); \
263 _menu->addAction( _action ); }
265 #define ACT_ADDMENU( _menu, val, title ) { \
266 QAction *_action = new QAction( title, _menu ); _action->setData( val ); \
267 _action->setMenu( new QMenu( _menu ) ); _menu->addAction( _action ); }
269 #define ACT_ADDCHECK( _menu, val, title ) { \
270 QAction *_action = new QAction( title, _menu ); _action->setData( val ); \
271 _action->setCheckable( true ); _menu->addAction( _action ); }
274 * Main Menu Bar Creation
276 void QVLCMenu::createMenuBar( MainInterface *mi,
277 intf_thread_t *p_intf )
279 /* QMainWindows->menuBar()
280 gives the QProcess::destroyed timeout issue on Cleanlooks style with
281 setDesktopAware set to false */
282 QMenuBar *bar = mi->menuBar();
284 BAR_ADD( FileMenu( p_intf, bar ), qtr( "&Media" ) );
286 /* Dynamic menus, rebuilt before being showed */
287 BAR_DADD( NavigMenu( p_intf, bar ), qtr( "P&layback" ), 3 );
288 BAR_DADD( AudioMenu( p_intf, bar ), qtr( "&Audio" ), 1 );
289 BAR_DADD( VideoMenu( p_intf, bar ), qtr( "&Video" ), 2 );
291 BAR_ADD( ToolsMenu( bar ), qtr( "&Tools" ) );
292 BAR_ADD( ViewMenu( p_intf, mi ), qtr( "V&iew" ) );
293 BAR_ADD( HelpMenu( bar ), qtr( "&Help" ) );
299 * Media ( File ) Menu
300 * Opening, streaming and quit
302 QMenu *QVLCMenu::FileMenu( intf_thread_t *p_intf, QWidget *parent )
304 QMenu *menu = new QMenu( parent );
306 addDPStaticEntry( menu, qtr( "&Open File..." ),
307 ":/type/file-asym", SLOT( simpleOpenDialog() ), "Ctrl+O" );
308 addDPStaticEntry( menu, qtr( "Advanced Open File..." ),
309 ":/type/file-asym", SLOT( openFileDialog() ), "Ctrl+Shift+O" );
310 addDPStaticEntry( menu, qtr( I_OPEN_FOLDER ),
311 ":/type/folder-grey", SLOT( PLOpenDir() ), "Ctrl+F" );
312 addDPStaticEntry( menu, qtr( "Open &Disc..." ),
313 ":/type/disc", SLOT( openDiscDialog() ), "Ctrl+D" );
314 addDPStaticEntry( menu, qtr( "Open &Network Stream..." ),
315 ":/type/network", SLOT( openNetDialog() ), "Ctrl+N" );
316 addDPStaticEntry( menu, qtr( "Open &Capture Device..." ),
317 ":/type/capture-card", SLOT( openCaptureDialog() ),
320 menu->addSeparator();
321 addDPStaticEntry( menu, qtr( "Open &Location from clipboard" ),
322 NULL, SLOT( openUrlDialog() ), "Ctrl+V" );
324 if( config_GetInt( p_intf, "qt-recentplay" ) )
326 recentsMenu = new QMenu( qtr( "&Recent Media" ), menu );
327 updateRecents( p_intf );
328 menu->addMenu( recentsMenu );
330 menu->addMenu( SDMenu( p_intf, menu ) );
331 menu->addSeparator();
333 addDPStaticEntry( menu, qtr( I_PL_SAVE ), "", SLOT( saveAPlaylist() ),
335 menu->addSeparator();
338 addDPStaticEntry( menu, qtr( "Conve&rt / Save..." ), "",
339 SLOT( openAndTranscodingDialogs() ), "Ctrl+R" );
340 addDPStaticEntry( menu, qtr( "&Streaming..." ),
341 ":/menu/stream", SLOT( openAndStreamingDialogs() ),
343 menu->addSeparator();
346 addDPStaticEntry( menu, qtr( "&Quit" ) ,
347 ":/menu/quit", SLOT( quit() ), "Ctrl+Q" );
352 * Tools, like Media Information, Preferences or Messages
354 QMenu *QVLCMenu::ToolsMenu( QMenu *menu )
356 addDPStaticEntry( menu, qtr( "&Effects and Filters"), ":/menu/settings",
357 SLOT( extendedDialog() ), "Ctrl+E" );
359 addDPStaticEntry( menu, qtr( "&Track Synchronization"), ":/menu/settings",
360 SLOT( synchroDialog() ), "" );
362 addDPStaticEntry( menu, qtr( I_MENU_INFO ) , ":/menu/info",
363 SLOT( mediaInfoDialog() ), "Ctrl+I" );
364 addDPStaticEntry( menu, qtr( I_MENU_CODECINFO ) ,
365 ":/menu/info", SLOT( mediaCodecDialog() ), "Ctrl+J" );
367 addDPStaticEntry( menu, qtr( I_MENU_BOOKMARK ),"",
368 SLOT( bookmarksDialog() ), "Ctrl+B" );
370 addDPStaticEntry( menu, qtr( I_MENU_VLM ), "", SLOT( vlmDialog() ),
374 addDPStaticEntry( menu, qtr( I_MENU_MSG ),
375 ":/menu/messages", SLOT( messagesDialog() ),
378 addDPStaticEntry( menu, qtr( "Plu&gins and extensions" ),
379 "", SLOT( pluginDialog() ) );
380 menu->addSeparator();
382 addDPStaticEntry( menu, qtr( "&Preferences" ),
383 ":/menu/preferences", SLOT( prefsDialog() ), "Ctrl+P" );
388 QMenu *QVLCMenu::ToolsMenu( QWidget *parent )
390 return ToolsMenu( new QMenu( parent ) );
395 * Interface Modification
397 QMenu *QVLCMenu::ViewMenu( intf_thread_t *p_intf,
403 QMenu *menu = new QMenu( qtr( "V&iew" ), mi );
405 QAction *act = menu->addAction( QIcon( ":/menu/playlist_menu" ),
406 qtr( "Play&list" ), mi,
407 SLOT( togglePlaylist() ), qtr( "Ctrl+L" ) );
409 /*menu->addSeparator();
410 menu->addAction( qtr( "Undock from Interface" ), mi,
411 SLOT( undockPlaylist() ), qtr( "Ctrl+U" ) );*/
413 menu->addSeparator();
417 QMenu *intfmenu = InterfacesMenu( p_intf, menu );
418 MenuFunc *f = new MenuFunc( intfmenu, 4 );
419 CONNECT( intfmenu, aboutToShow(), THEDP->menusUpdateMapper, map() );
420 THEDP->menusUpdateMapper->setMapping( intfmenu, f );
421 menu->addSeparator();
425 QAction *action = menu->addAction( qtr( "Mi&nimal View" ) );
426 action->setShortcut( qtr( "Ctrl+H" ) );
427 action->setCheckable( true );
428 action->setChecked( !with_intf &&
429 (mi->getControlsVisibilityStatus() & CONTROLS_HIDDEN ) );
431 CONNECT( action, triggered( bool ), mi, toggleMinimalView( bool ) );
432 CONNECT( mi, minimalViewToggled( bool ), action, setChecked( bool ) );
434 /* FullScreen View */
435 action = menu->addAction( qtr( "&Fullscreen Interface" ), mi,
436 SLOT( toggleFullScreen() ), QString( "F11" ) );
437 action->setCheckable( true );
438 action->setChecked( mi->isFullScreen() );
439 CONNECT( mi, fullscreenInterfaceToggled( bool ),
440 action, setChecked( bool ) );
442 /* Advanced Controls */
443 action = menu->addAction( qtr( "&Advanced Controls" ), mi,
444 SLOT( toggleAdvanced() ) );
445 action->setCheckable( true );
446 if( mi->getControlsVisibilityStatus() & CONTROLS_ADVANCED )
447 action->setChecked( true );
450 // I don't want to manage consistency between menus, so no popup-menu
452 action = menu->addAction( qtr( "Quit after Playback" ) );
453 action->setCheckable( true );
454 CONNECT( action, triggered( bool ), THEMIM, activatePlayQuit( bool ) );
457 #if 0 /* For Visualisations. Not yet working */
458 adv = menu->addAction( qtr( "Visualizations selector" ),
459 mi, SLOT( visual() ) );
460 adv->setCheckable( true );
461 if( visual_selector_enabled ) adv->setChecked( true );
464 menu->addSeparator();
465 addDPStaticEntry( menu, qtr( "Customi&ze Interface..." ),
466 ":/menu/preferences", SLOT( toolbarDialog() ) );
467 menu->addSeparator();
473 * Interface Sub-Menu, to list extras interface and skins
475 QMenu *QVLCMenu::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
477 vector<vlc_object_t *> objects;
478 vector<const char *> varnames;
479 varnames.push_back( "intf-add" );
480 objects.push_back( VLC_OBJECT(p_intf) );
482 return Populate( p_intf, current, varnames, objects );
488 QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QMenu * current )
490 vector<vlc_object_t *> objects;
491 vector<const char *> varnames;
492 aout_instance_t *p_aout;
493 input_thread_t *p_input;
495 if( current->isEmpty() )
497 ACT_ADDMENU( current, "audio-es", qtr( "Audio &Track" ) );
498 ACT_ADDMENU( current, "audio-channels", qtr( "Audio &Channels" ) );
499 ACT_ADDMENU( current, "audio-device", qtr( "Audio &Device" ) );
500 current->addSeparator();
502 ACT_ADDMENU( current, "visual", qtr( "&Visualizations" ) );
503 current->addSeparator();
505 QAction *action = current->addAction( qtr( "Increase Volume" ),
506 ActionsManager::getInstance( p_intf ), SLOT( AudioUp() ) );
507 action->setData( STATIC_ENTRY );
508 action = current->addAction( qtr( "Decrease Volume" ),
509 ActionsManager::getInstance( p_intf ), SLOT( AudioDown() ) );
510 action->setData( STATIC_ENTRY );
511 action = current->addAction( qtr( "Mute" ),
512 ActionsManager::getInstance( p_intf ), SLOT( toggleMuteAudio() ) );
513 action->setData( STATIC_ENTRY );
516 p_input = THEMIM->getInput();
517 p_aout = THEMIM->getAout();
518 EnableStaticEntries( current, ( p_aout != NULL ) );
519 AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
522 vlc_object_release( p_aout );
525 return Populate( p_intf, current, varnames, objects );
528 QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QWidget *parent )
530 return AudioMenu( p_intf, new QMenu( parent ) );
535 * Subtitles are part of Video.
537 QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current )
539 vout_thread_t *p_vout;
540 input_thread_t *p_input;
541 vector<vlc_object_t *> objects;
542 vector<const char *> varnames;
544 if( current->isEmpty() )
546 ACT_ADDMENU( current, "video-es", qtr( "Video &Track" ) );
549 QMenu *submenu = new QMenu( qtr( "&Subtitles Track" ), current );
550 action = current->addMenu( submenu );
551 action->setData( "spu-es" );
552 addDPStaticEntry( submenu, qtr( "Open File..." ), "",
553 SLOT( loadSubtitlesFile() ) );
554 submenu->addSeparator();
555 current->addSeparator();
557 ACT_ADDCHECK( current, "fullscreen", qtr( "&Fullscreen" ) );
558 ACT_ADDCHECK( current, "video-on-top", qtr( "Always &On Top" ) );
560 ACT_ADDCHECK( current, "directx-wallpaper", qtr( "DirectX Wallpaper" ) );
562 ACT_ADD( current, "video-snapshot", qtr( "Sna&pshot" ) );
564 current->addSeparator();
566 ACT_ADDMENU( current, "zoom", qtr( "&Zoom" ) );
567 ACT_ADDCHECK( current, "autoscale", qtr( "Sca&le" ) );
568 ACT_ADDMENU( current, "aspect-ratio", qtr( "&Aspect Ratio" ) );
569 ACT_ADDMENU( current, "crop", qtr( "&Crop" ) );
570 ACT_ADDMENU( current, "deinterlace", qtr( "&Deinterlace" ) );
571 ACT_ADDMENU( current, "postprocess", qtr( "&Post processing" ) );
574 p_input = THEMIM->getInput();
576 p_vout = THEMIM->getVout();
577 VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
580 vlc_object_release( p_vout );
582 return Populate( p_intf, current, varnames, objects );
585 QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QWidget *parent )
587 return VideoMenu( p_intf, new QMenu( parent ) );
592 * For DVD, MP4, MOV and other chapter based format
594 QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *menu )
598 QMenu *submenu = new QMenu( qtr( "&Bookmarks" ), menu );
599 addDPStaticEntry( submenu, qtr( "Manage &bookmarks" ), "",
600 SLOT( bookmarksDialog() ) );
601 submenu->addSeparator();
602 action = menu->addMenu( submenu );
603 action->setData( "bookmark" );
605 ACT_ADDMENU( menu, "title", qtr( "T&itle" ) );
606 ACT_ADDMENU( menu, "chapter", qtr( "&Chapter" ) );
607 ACT_ADDMENU( menu, "navigation", qtr( "&Navigation" ) );
608 ACT_ADDMENU( menu, "program", qtr( "&Program" ) );
610 menu->addSeparator();
611 PopupMenuPlaylistControlEntries( menu, p_intf );
612 PopupMenuControlEntries( menu, p_intf );
614 EnableStaticEntries( menu, ( THEMIM->getInput() != NULL ) );
615 return RebuildNavigMenu( p_intf, menu );
618 QMenu *QVLCMenu::RebuildNavigMenu( intf_thread_t *p_intf, QMenu *menu )
621 input_thread_t *p_object;
622 vector<vlc_object_t *> objects;
623 vector<const char *> varnames;
625 /* Get the input and hold it */
626 p_object = THEMIM->getInput();
628 InputAutoMenuBuilder( p_object, objects, varnames );
630 menu->addSeparator();
632 /* Title and so on */
633 PUSH_VAR( "prev-title" );
634 PUSH_VAR( "next-title" );
635 PUSH_VAR( "prev-chapter" );
636 PUSH_VAR( "next-chapter" );
638 EnableStaticEntries( menu, (p_object != NULL ) );
639 return Populate( p_intf, menu, varnames, objects );
642 QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QWidget *parent )
644 return NavigMenu( p_intf, new QMenu( parent ) );
648 * Service Discovery SubMenu
650 QMenu *QVLCMenu::SDMenu( intf_thread_t *p_intf, QWidget *parent )
652 QMenu *menu = new QMenu( parent );
653 menu->setTitle( qtr( I_PL_SD ) );
655 char **ppsz_longnames;
656 char **ppsz_names = vlc_sd_GetNames( &ppsz_longnames );
660 char **ppsz_name = ppsz_names, **ppsz_longname = ppsz_longnames;
661 for( ; *ppsz_name; ppsz_name++, ppsz_longname++ )
663 QAction *a = new QAction( qfu( *ppsz_longname ), menu );
664 a->setCheckable( true );
665 if( playlist_IsServicesDiscoveryLoaded( THEPL, *ppsz_name ) )
666 a->setChecked( true );
667 CONNECT( a, triggered(), THEDP->SDMapper, map() );
668 THEDP->SDMapper->setMapping( a, QString( *ppsz_name ) );
669 menu->addAction( a );
671 /* Special case for podcast */
672 if( !strcmp( *ppsz_name, "podcast" ) )
674 QAction *b = new QAction( qtr( "Configure podcasts..." ), menu );
675 //b->setEnabled( a->isChecked() );
676 menu->addAction( b );
677 CONNECT( b, triggered(), THEDP, podcastConfigureDialog() );
680 free( *ppsz_longname );
683 free( ppsz_longnames );
690 QMenu *QVLCMenu::HelpMenu( QWidget *parent )
692 QMenu *menu = new QMenu( parent );
693 addDPStaticEntry( menu, qtr( "&Help..." ) ,
694 ":/menu/help", SLOT( helpDialog() ), "F1" );
696 addDPStaticEntry( menu, qtr( "Check for &Updates..." ) , "",
697 SLOT( updateDialog() ) );
699 menu->addSeparator();
700 addDPStaticEntry( menu, qtr( I_MENU_ABOUT ), ":/menu/info",
701 SLOT( aboutDialog() ), "Shift+F1" );
705 /*****************************************************************************
706 * Popup menus - Right Click menus *
707 *****************************************************************************/
708 #define POPUP_BOILERPLATE \
709 unsigned int i_last_separator = 0; \
710 vector<vlc_object_t *> objects; \
711 vector<const char *> varnames; \
712 input_thread_t *p_input = THEMIM->getInput();
714 #define CREATE_POPUP \
715 Populate( p_intf, menu, varnames, objects ); \
716 p_intf->p_sys->p_popup_menu = menu; \
717 menu->popup( QCursor::pos() ); \
718 p_intf->p_sys->p_popup_menu = NULL; \
719 i_last_separator = 0;
721 void QVLCMenu::PopupPlayEntries( QMenu *menu,
722 intf_thread_t *p_intf,
723 input_thread_t *p_input )
727 /* Play or Pause action and icon */
728 if( !p_input || var_GetInteger( p_input, "state" ) != PLAYING_S )
730 action = menu->addAction( qtr( "Play" ),
731 ActionsManager::getInstance( p_intf ), SLOT( play() ) );
732 action->setIcon( QIcon( ":/menu/play" ) );
736 addMIMStaticEntry( p_intf, menu, qtr( "Pause" ),
737 ":/menu/pause", SLOT( togglePlayPause() ) );
741 void QVLCMenu::PopupMenuControlEntries( QMenu *menu, intf_thread_t *p_intf )
746 action = menu->addAction( qtr( "&Faster" ), THEMIM->getIM(),
748 action->setIcon( QIcon( ":/toolbar/faster") );
749 action->setData( STATIC_ENTRY );
751 action = menu->addAction( qtr( "Faster (fine)" ), THEMIM->getIM(),
752 SLOT( littlefaster() ) );
753 action->setData( STATIC_ENTRY );
755 action = menu->addAction( qtr( "N&ormal Speed" ), THEMIM->getIM(),
756 SLOT( normalRate() ) );
757 action->setData( STATIC_ENTRY );
759 action = menu->addAction( qtr( "Slower (fine)" ), THEMIM->getIM(),
760 SLOT( littleslower() ) );
761 action->setData( STATIC_ENTRY );
763 action = menu->addAction( qtr( "Slo&wer" ), THEMIM->getIM(),
765 action->setIcon( QIcon( ":/toolbar/slower") );
766 action->setData( STATIC_ENTRY );
768 menu->addSeparator();
770 action = menu->addAction( qtr( "&Jump Forward" ), THEMIM->getIM(),
772 action->setIcon( QIcon( ":/toolbar/skip_fw") );
773 action->setData( STATIC_ENTRY );
775 action = menu->addAction( qtr( "Jump Bac&kward" ), THEMIM->getIM(),
777 action->setIcon( QIcon( ":/toolbar/skip_back") );
778 action->setData( STATIC_ENTRY );
779 addDPStaticEntry( menu, qtr( I_MENU_GOTOTIME ),"",
780 SLOT( gotoTimeDialog() ), "Ctrl+T" );
781 menu->addSeparator();
785 void QVLCMenu::PopupMenuPlaylistControlEntries( QMenu *menu,
786 intf_thread_t *p_intf )
788 bool bEnable = THEMIM->getInput() != NULL;
790 addMIMStaticEntry( p_intf, menu, qtr( "&Stop" ), ":/menu/stop",
791 SLOT( stop() ), true );
792 /* Disable Stop in the right-click popup menu */
794 action->setEnabled( false );
796 /* Next / Previous */
797 addMIMStaticEntry( p_intf, menu, qtr( "Pre&vious" ),
798 ":/menu/previous", SLOT( prev() ) );
799 addMIMStaticEntry( p_intf, menu, qtr( "Ne&xt" ),
800 ":/menu/next", SLOT( next() ) );
801 menu->addSeparator();
804 void QVLCMenu::PopupMenuStaticEntries( QMenu *menu )
806 QMenu *openmenu = new QMenu( qtr( "Open Media" ), menu );
807 addDPStaticEntry( openmenu, qtr( "&Open File..." ),
808 ":/type/file-asym", SLOT( openFileDialog() ) );
809 addDPStaticEntry( openmenu, qtr( I_OPEN_FOLDER ),
810 ":/type/folder-grey", SLOT( PLOpenDir() ) );
811 addDPStaticEntry( openmenu, qtr( "Open &Disc..." ),
812 ":/type/disc", SLOT( openDiscDialog() ) );
813 addDPStaticEntry( openmenu, qtr( "Open &Network..." ),
814 ":/type/network", SLOT( openNetDialog() ) );
815 addDPStaticEntry( openmenu, qtr( "Open &Capture Device..." ),
816 ":/type/capture-card", SLOT( openCaptureDialog() ) );
817 menu->addMenu( openmenu );
819 menu->addSeparator();
821 QMenu *helpmenu = HelpMenu( menu );
822 helpmenu->setTitle( qtr( "Help" ) );
823 menu->addMenu( helpmenu );
826 addDPStaticEntry( menu, qtr( "Quit" ), ":/menu/quit",
827 SLOT( quit() ), "Ctrl+Q" );
830 /* Video Tracks and Subtitles tracks */
831 void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf )
836 vout_thread_t *p_vout = THEMIM->getVout();
839 VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
840 vlc_object_release( p_vout );
843 QMenu *menu = new QMenu();
848 void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf )
853 aout_instance_t *p_aout = THEMIM->getAout();
854 AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
856 vlc_object_release( p_aout );
858 QMenu *menu = new QMenu();
862 /* Navigation stuff, and general menus ( open ), used only for skins */
863 void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf )
869 varnames.push_back( "audio-es" );
870 InputAutoMenuBuilder( p_input, objects, varnames );
874 QMenu *menu = new QMenu();
875 Populate( p_intf, menu, varnames, objects );
877 menu->addSeparator();
878 PopupPlayEntries( menu, p_intf, p_input );
879 PopupMenuPlaylistControlEntries( menu, p_intf);
881 menu->addSeparator();
882 PopupMenuControlEntries( menu, p_intf );
884 menu->addSeparator();
885 PopupMenuStaticEntries( menu );
887 p_intf->p_sys->p_popup_menu = menu;
888 menu->popup( QCursor::pos() );
889 p_intf->p_sys->p_popup_menu = NULL;
892 /* Main Menu that sticks everything together */
893 void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show )
895 /* Delete old popup if there is one */
896 if( p_intf->p_sys->p_popup_menu )
897 delete p_intf->p_sys->p_popup_menu;
901 p_intf->p_sys->p_popup_menu = NULL;
906 QMenu *menu = new QMenu();
908 bool b_isFullscreen = false;
909 MainInterface *mi = p_intf->p_sys->p_mi;
913 PopupPlayEntries( menu, p_intf, p_input );
914 PopupMenuPlaylistControlEntries( menu, p_intf );
915 menu->addSeparator();
920 vout_thread_t *p_vout = THEMIM->getVout();
922 /* Add a fullscreen switch button, since it is the most used function */
925 vlc_value_t val; var_Get( p_vout, "fullscreen", &val );
927 b_isFullscreen = !( !val.b_bool );
929 CreateAndConnect( menu, "fullscreen",
930 qtr( "Leave Fullscreen" ),"" , ITEM_NORMAL,
931 VLC_OBJECT(p_vout), val, VLC_VAR_BOOL, b_isFullscreen );
932 vlc_object_release( p_vout );
934 menu->addSeparator();
938 InputAutoMenuBuilder( p_input, objects, varnames );
941 submenu = new QMenu( menu );
942 action = menu->addMenu( AudioMenu( p_intf, submenu ) );
943 action->setText( qtr( "&Audio" ) );
944 if( action->menu()->isEmpty() )
945 action->setEnabled( false );
948 submenu = new QMenu( menu );
949 action = menu->addMenu( VideoMenu( p_intf, submenu ) );
950 action->setText( qtr( "&Video" ) );
951 if( action->menu()->isEmpty() )
952 action->setEnabled( false );
954 /* Playback menu for chapters */
955 submenu = new QMenu( menu );
956 action = menu->addMenu( NavigMenu( p_intf, submenu ) );
957 action->setText( qtr( "&Playback" ) );
958 if( action->menu()->isEmpty() )
959 action->setEnabled( false );
962 menu->addSeparator();
964 /* Add some special entries for windowed mode: Interface Menu */
965 if( !b_isFullscreen )
967 QMenu *submenu = new QMenu( qtr( "Interface" ), menu );
968 QMenu *tools = ToolsMenu( submenu );
969 submenu->addSeparator();
971 /* In skins interface, append some items */
975 vlc_object_t *p_object = ( vlc_object_t* )
976 vlc_object_find_name( p_intf, "skins2", FIND_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 );
989 vlc_object_release( p_object );
992 msg_Warn( p_intf, "could not find parent interface" );
995 menu->addMenu( ViewMenu( p_intf, mi, false ));
997 menu->addMenu( submenu );
1000 /* Static entries for ending, like open */
1001 PopupMenuStaticEntries( menu );
1003 p_intf->p_sys->p_popup_menu = menu;
1004 p_intf->p_sys->p_popup_menu->popup( QCursor::pos() );
1011 /************************************************************************
1013 ************************************************************************/
1015 void QVLCMenu::updateSystrayMenu( MainInterface *mi,
1016 intf_thread_t *p_intf,
1017 bool b_force_visible )
1021 /* Get the systray menu and clean it */
1022 QMenu *sysMenu = mi->getSysTrayMenu();
1025 /* Hide / Show VLC and cone */
1026 if( mi->isVisible() || b_force_visible )
1028 sysMenu->addAction( QIcon( ":/logo/vlc16.png" ),
1029 qtr( "Hide VLC media player in taskbar" ), mi,
1030 SLOT( toggleUpdateSystrayMenu() ) );
1034 sysMenu->addAction( QIcon( ":/logo/vlc16.png" ),
1035 qtr( "Show VLC media player" ), mi,
1036 SLOT( toggleUpdateSystrayMenu() ) );
1039 sysMenu->addSeparator();
1040 PopupPlayEntries( sysMenu, p_intf, p_input );
1041 PopupMenuPlaylistControlEntries( sysMenu, p_intf);
1042 PopupMenuControlEntries( sysMenu, p_intf);
1044 sysMenu->addSeparator();
1045 addDPStaticEntry( sysMenu, qtr( "&Open Media" ),
1046 ":/type/file-wide", SLOT( openFileDialog() ) );
1047 addDPStaticEntry( sysMenu, qtr( "&Quit" ) ,
1048 ":/menu/quit", SLOT( quit() ) );
1051 mi->getSysTray()->setContextMenu( sysMenu );
1055 #undef POPUP_BOILERPLATE
1058 #undef PUSH_SEPARATOR
1060 /*************************************************************************
1061 * Builders for automenus
1062 *************************************************************************/
1063 QMenu * QVLCMenu::Populate( intf_thread_t *p_intf,
1065 vector< const char *> & varnames,
1066 vector<vlc_object_t *> & objects )
1068 QMenu *menu = current;
1071 currentGroup = NULL;
1073 vlc_object_t *p_object;
1075 for( int i = 0; i < ( int )objects.size() ; i++ )
1077 if( !varnames[i] || !*varnames[i] )
1079 menu->addSeparator();
1082 p_object = objects[i];
1084 UpdateItem( p_intf, menu, varnames[i], p_object, true );
1089 /*****************************************************************************
1091 *****************************************************************************/
1093 static bool IsMenuEmpty( const char *psz_var,
1094 vlc_object_t *p_object,
1095 bool b_root = true )
1097 vlc_value_t val, val_list;
1098 int i_type, i_result, i;
1100 /* Check the type of the object variable */
1101 i_type = var_Type( p_object, psz_var );
1103 /* Check if we want to display the variable */
1104 if( !( i_type & VLC_VAR_HASCHOICE ) ) return false;
1106 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
1107 if( val.i_int == 0 ) return true;
1109 if( ( i_type & VLC_VAR_TYPE ) != VLC_VAR_VARIABLE )
1111 if( val.i_int == 1 && b_root ) return true;
1115 /* Check children variables in case of VLC_VAR_VARIABLE */
1116 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
1121 for( i = 0, i_result = true; i < val_list.p_list->i_count; i++ )
1123 if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
1131 /* clean up everything */
1132 var_FreeList( &val_list, NULL );
1137 #define TEXT_OR_VAR qfu ( text.psz_string ? text.psz_string : psz_var )
1139 void QVLCMenu::UpdateItem( intf_thread_t *p_intf, QMenu *menu,
1140 const char *psz_var, vlc_object_t *p_object, bool b_submenu )
1142 vlc_value_t val, text;
1145 QAction *action = FindActionWithVar( menu, psz_var );
1147 DeleteNonStaticEntries( action->menu() );
1152 action->setEnabled( false );
1156 /* Check the type of the object variable */
1157 /* This HACK is needed so we have a radio button for audio and video tracks
1158 instread of a checkbox */
1159 if( !strcmp( psz_var, "audio-es" )
1160 || !strcmp( psz_var, "video-es" ) )
1161 i_type = VLC_VAR_INTEGER | VLC_VAR_HASCHOICE;
1163 i_type = var_Type( p_object, psz_var );
1165 switch( i_type & VLC_VAR_TYPE )
1169 case VLC_VAR_VARIABLE:
1170 case VLC_VAR_STRING:
1171 case VLC_VAR_INTEGER:
1175 /* Variable doesn't exist or isn't handled */
1177 action->setEnabled( false );
1181 /* Make sure we want to display the variable */
1182 if( menu->isEmpty() && IsMenuEmpty( psz_var, p_object ) )
1185 action->setEnabled( false );
1189 /* Get the descriptive name of the variable */
1190 int i_ret = var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
1191 if( i_ret != VLC_SUCCESS )
1193 text.psz_string = NULL;
1198 action = new QAction( TEXT_OR_VAR, menu );
1199 menu->addAction( action );
1200 action->setData( psz_var );
1203 /* Some specific stuff */
1204 bool forceDisabled = false;
1205 if( !strcmp( psz_var, "spu-es" ) )
1207 vout_thread_t *p_vout = THEMIM->getVout();
1208 forceDisabled = ( p_vout == NULL );
1210 vlc_object_release( p_vout );
1213 if( i_type & VLC_VAR_HASCHOICE )
1215 /* Append choices menu */
1219 submenu = action->menu();
1222 submenu = new QMenu( menu );
1223 action->setMenu( submenu );
1227 CreateChoicesMenu( submenu, psz_var, p_object, true ) == 0 );
1229 action->setEnabled( false );
1234 CreateChoicesMenu( menu, psz_var, p_object, true ) == 0 );
1236 FREENULL( text.psz_string );
1240 switch( i_type & VLC_VAR_TYPE )
1243 var_Get( p_object, psz_var, &val );
1244 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_NORMAL,
1245 p_object, val, i_type );
1249 var_Get( p_object, psz_var, &val );
1250 val.b_bool = !val.b_bool;
1251 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_CHECK,
1252 p_object, val, i_type, !val.b_bool );
1255 FREENULL( text.psz_string );
1261 int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
1262 vlc_object_t *p_object, bool b_root )
1264 vlc_value_t val, val_list, text_list;
1267 /* Check the type of the object variable */
1268 i_type = var_Type( p_object, psz_var );
1270 /* Make sure we want to display the variable */
1271 if( submenu->isEmpty() && IsMenuEmpty( psz_var, p_object, b_root ) )
1272 return VLC_EGENERIC;
1274 switch( i_type & VLC_VAR_TYPE )
1278 case VLC_VAR_VARIABLE:
1279 case VLC_VAR_STRING:
1280 case VLC_VAR_INTEGER:
1284 /* Variable doesn't exist or isn't handled */
1285 return VLC_EGENERIC;
1288 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
1289 &val_list, &text_list ) < 0 )
1291 return VLC_EGENERIC;
1294 #define CURVAL val_list.p_list->p_values[i]
1295 #define CURTEXT text_list.p_list->p_values[i].psz_string
1297 for( i = 0; i < val_list.p_list->i_count; i++ )
1299 vlc_value_t another_val;
1301 QMenu *subsubmenu = new QMenu( submenu );
1303 switch( i_type & VLC_VAR_TYPE )
1305 case VLC_VAR_VARIABLE:
1306 CreateChoicesMenu( subsubmenu, CURVAL.psz_string, p_object, false );
1307 subsubmenu->setTitle( qfu( CURTEXT ? CURTEXT :CURVAL.psz_string ) );
1308 submenu->addMenu( subsubmenu );
1311 case VLC_VAR_STRING:
1312 var_Get( p_object, psz_var, &val );
1313 another_val.psz_string = strdup( CURVAL.psz_string );
1314 menutext = qfu( CURTEXT ? CURTEXT : another_val.psz_string );
1315 CreateAndConnect( submenu, psz_var, menutext, "", ITEM_RADIO,
1316 p_object, another_val, i_type,
1317 val.psz_string && !strcmp( val.psz_string, CURVAL.psz_string ) );
1319 free( val.psz_string );
1322 case VLC_VAR_INTEGER:
1323 var_Get( p_object, psz_var, &val );
1324 if( CURTEXT ) menutext = qfu( CURTEXT );
1325 else menutext.sprintf( "%d", CURVAL.i_int );
1326 CreateAndConnect( submenu, psz_var, menutext, "", ITEM_RADIO,
1327 p_object, CURVAL, i_type,
1328 CURVAL.i_int == val.i_int );
1332 var_Get( p_object, psz_var, &val );
1333 if( CURTEXT ) menutext = qfu( CURTEXT );
1334 else menutext.sprintf( "%.2f", CURVAL.f_float );
1335 CreateAndConnect( submenu, psz_var, menutext, "", ITEM_RADIO,
1336 p_object, CURVAL, i_type,
1337 CURVAL.f_float == val.f_float );
1344 currentGroup = NULL;
1346 /* clean up everything */
1347 var_FreeList( &val_list, &text_list );
1351 return submenu->isEmpty() ? VLC_EGENERIC : VLC_SUCCESS;
1354 void QVLCMenu::CreateAndConnect( QMenu *menu, const char *psz_var,
1355 QString text, QString help,
1356 int i_item_type, vlc_object_t *p_obj,
1357 vlc_value_t val, int i_val_type,
1360 QAction *action = FindActionWithVar( menu, psz_var );
1365 action = new QAction( text, menu );
1366 menu->addAction( action );
1370 action->setToolTip( help );
1371 action->setEnabled( p_obj != NULL );
1373 if( i_item_type == ITEM_CHECK )
1375 action->setCheckable( true );
1377 else if( i_item_type == ITEM_RADIO )
1379 action->setCheckable( true );
1381 currentGroup = new QActionGroup( menu );
1382 currentGroup->addAction( action );
1385 action->setChecked( checked );
1387 MenuItemData *itemData = new MenuItemData( THEDP->menusMapper, p_obj, i_val_type,
1390 /* remove previous signal-slot connection(s) if any */
1391 action->disconnect( );
1393 CONNECT( action, triggered(), THEDP->menusMapper, map() );
1394 THEDP->menusMapper->setMapping( action, itemData );
1397 menu->addAction( action );
1400 void QVLCMenu::DoAction( QObject *data )
1402 MenuItemData *itemData = qobject_cast<MenuItemData *>( data );
1403 vlc_object_t *p_object = itemData->p_obj;
1404 if( p_object == NULL ) return;
1406 var_Set( p_object, itemData->psz_var, itemData->val );
1409 void QVLCMenu::updateRecents( intf_thread_t *p_intf )
1414 RecentsMRL* rmrl = RecentsMRL::getInstance( p_intf );
1415 QList<QString> l = rmrl->recents();
1417 recentsMenu->clear();
1421 action = recentsMenu->addAction( qtr(" - Empty - ") );
1422 action->setEnabled( false );
1426 for( int i = 0; i < l.size(); ++i )
1428 action = recentsMenu->addAction(
1429 QString( "&%1: " ).arg( i + 1 ) + l.at( i ),
1432 rmrl->signalMapper->setMapping( action, l.at( i ) );
1435 recentsMenu->addSeparator();
1436 recentsMenu->addAction( qtr("&Clear"), rmrl, SLOT( clear() ) );