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.
74 static QActionGroup *currentGroup;
76 QMenu *QVLCMenu::recentsMenu = NULL;
78 /****************************************************************************
80 ****************************************************************************
81 * Add static entries to DP in menus
82 ***************************************************************************/
83 void addDPStaticEntry( QMenu *menu,
87 const char *shortcut = NULL )
89 QAction *action = NULL;
90 if( !EMPTY_STR( icon ) > 0 )
92 if( !EMPTY_STR( shortcut ) > 0 )
93 action = menu->addAction( QIcon( icon ), text, THEDP,
94 member, qtr( shortcut ) );
96 action = menu->addAction( QIcon( icon ), text, THEDP, member );
100 if( !EMPTY_STR( shortcut ) > 0 )
101 action = menu->addAction( text, THEDP, member, qtr( shortcut ) );
103 action = menu->addAction( text, THEDP, member );
105 action->setData( true );
111 void addMIMStaticEntry( intf_thread_t *p_intf,
118 if( strlen( icon ) > 0 )
120 action = menu->addAction( text, THEMIM, member );
121 action->setIcon( QIcon( icon ) );
125 menu->addAction( text, THEMIM, member );
127 action->setData( "ignore" );
131 * @brief Enable all static entries, disable the others
132 * @param enable if false, disable all entries
134 void EnableStaticEntries( QMenu *menu, bool enable = true )
138 QList< QAction* > actions = menu->actions();
139 for( int i = 0; i < actions.size(); ++i )
141 actions[i]->setEnabled( actions[i]->data().toString() == "ignore" ||
142 /* Be careful here, because data("string").toBool is true */
143 ( enable && (actions[i]->data().toString() == "true" ) ) );
148 * \return Number of static entries
150 int DeleteNonStaticEntries( QMenu *menu )
152 if( !menu ) return VLC_EGENERIC;
156 QList< QAction* > actions = menu->actions();
157 for( int i = 0; i < actions.size(); ++i )
159 if( !actions[i]->data().toBool() )
168 * \return QAction associated to psz_var variable
170 static QAction * FindActionWithVar( QMenu *menu, const char *psz_var )
172 QList< QAction* > actions = menu->actions();
173 for( int i = 0; i < actions.size(); ++i )
175 if( actions[i]->data().toString() == psz_var )
181 /*****************************************************************************
182 * Definitions of variables for the dynamic menus
183 *****************************************************************************/
184 #define PUSH_VAR( var ) varnames.push_back( var ); \
185 objects.push_back( VLC_OBJECT(p_object) )
187 #define PUSH_INPUTVAR( var ) varnames.push_back( var ); \
188 objects.push_back( VLC_OBJECT(p_input) );
190 #define PUSH_SEPARATOR if( objects.size() != i_last_separator ) { \
191 objects.push_back( 0 ); varnames.push_back( "" ); \
192 i_last_separator = objects.size(); }
194 static int InputAutoMenuBuilder( input_thread_t *p_object,
195 vector<vlc_object_t *> &objects,
196 vector<const char *> &varnames )
198 PUSH_VAR( "bookmark" );
200 PUSH_VAR( "chapter" );
201 PUSH_VAR( "navigation" );
202 PUSH_VAR( "program" );
206 static int VideoAutoMenuBuilder( vout_thread_t *p_object,
207 input_thread_t *p_input,
208 vector<vlc_object_t *> &objects,
209 vector<const char *> &varnames )
211 PUSH_INPUTVAR( "video-es" );
212 PUSH_INPUTVAR( "spu-es" );
213 PUSH_VAR( "fullscreen" );
214 PUSH_VAR( "video-on-top" );
216 PUSH_VAR( "directx-wallpaper" );
218 PUSH_VAR( "video-snapshot" );
220 PUSH_VAR( "autoscale" );
221 PUSH_VAR( "aspect-ratio" );
223 PUSH_VAR( "deinterlace" );
224 PUSH_VAR( "postprocess" );
229 static int AudioAutoMenuBuilder( aout_instance_t *p_object,
230 input_thread_t *p_input,
231 vector<vlc_object_t *> &objects,
232 vector<const char *> &varnames )
234 PUSH_INPUTVAR( "audio-es" );
235 PUSH_VAR( "audio-channels" );
236 PUSH_VAR( "audio-device" );
237 PUSH_VAR( "visual" );
241 /*****************************************************************************
244 *****************************************************************************/
246 #define BAR_ADD( func, title ) { \
247 QMenu *_menu = func; _menu->setTitle( title ); bar->addMenu( _menu ); }
249 #define BAR_DADD( func, title, id ) { \
250 QMenu *_menu = func; _menu->setTitle( title ); bar->addMenu( _menu ); \
251 MenuFunc *f = new MenuFunc( _menu, id ); \
252 CONNECT( _menu, aboutToShow(), THEDP->menusUpdateMapper, map() ); \
253 THEDP->menusUpdateMapper->setMapping( _menu, f ); }
255 #define ACT_ADD( _menu, val, title ) { \
256 QAction *_action = new QAction( title, _menu ); _action->setData( val ); \
257 _menu->addAction( _action ); }
259 #define ACT_ADDMENU( _menu, val, title ) { \
260 QAction *_action = new QAction( title, _menu ); _action->setData( val ); \
261 _action->setMenu( new QMenu( _menu ) ); _menu->addAction( _action ); }
263 #define ACT_ADDCHECK( _menu, val, title ) { \
264 QAction *_action = new QAction( title, _menu ); _action->setData( val ); \
265 _action->setCheckable( true ); _menu->addAction( _action ); }
268 * Main Menu Bar Creation
270 void QVLCMenu::createMenuBar( MainInterface *mi,
271 intf_thread_t *p_intf )
273 /* QMainWindows->menuBar()
274 gives the QProcess::destroyed timeout issue on Cleanlooks style with
275 setDesktopAware set to false */
276 QMenuBar *bar = mi->menuBar();
278 BAR_ADD( FileMenu( p_intf, bar ), qtr( "&Media" ) );
280 /* Dynamic menus, rebuilt before being showed */
281 BAR_DADD( NavigMenu( p_intf, bar ), qtr( "P&layback" ), 3 );
282 BAR_DADD( AudioMenu( p_intf, bar ), qtr( "&Audio" ), 1 );
283 BAR_DADD( VideoMenu( p_intf, bar ), qtr( "&Video" ), 2 );
285 BAR_ADD( ToolsMenu( bar ), qtr( "&Tools" ) );
286 BAR_ADD( ViewMenu( p_intf, mi ), qtr( "V&iew" ) );
287 BAR_ADD( HelpMenu( bar ), qtr( "&Help" ) );
293 * Media ( File ) Menu
294 * Opening, streaming and quit
296 QMenu *QVLCMenu::FileMenu( intf_thread_t *p_intf, QWidget *parent )
298 QMenu *menu = new QMenu( parent );
300 addDPStaticEntry( menu, qtr( "&Open File..." ),
301 ":/file-asym", SLOT( simpleOpenDialog() ), "Ctrl+O" );
302 addDPStaticEntry( menu, qtr( "Advanced Open File..." ),
303 ":/file-asym", SLOT( openFileDialog() ), "Ctrl+Shift+O" );
304 addDPStaticEntry( menu, qtr( I_OPEN_FOLDER ),
305 ":/folder-grey", SLOT( PLOpenDir() ), "Ctrl+F" );
306 addDPStaticEntry( menu, qtr( "Open &Disc..." ),
307 ":/disc", SLOT( openDiscDialog() ), "Ctrl+D" );
308 addDPStaticEntry( menu, qtr( "Open &Network Stream..." ),
309 ":/network", SLOT( openNetDialog() ), "Ctrl+N" );
310 addDPStaticEntry( menu, qtr( "Open &Capture Device..." ),
311 ":/capture-card", SLOT( openCaptureDialog() ),
314 menu->addSeparator();
315 addDPStaticEntry( menu, qtr( "Open &Location from clipboard" ),
316 NULL, SLOT( openUrlDialog() ), "Ctrl+V" );
318 recentsMenu = new QMenu( qtr( "&Recent Media" ), menu );
319 updateRecents( p_intf );
320 menu->addMenu( recentsMenu );
321 menu->addMenu( SDMenu( p_intf, menu ) );
322 menu->addSeparator();
324 addDPStaticEntry( menu, qtr( I_PL_SAVE ), "", SLOT( saveAPlaylist() ),
326 menu->addSeparator();
328 addDPStaticEntry( menu, qtr( "Conve&rt / Save..." ), "",
329 SLOT( openAndTranscodingDialogs() ), "Ctrl+R" );
330 addDPStaticEntry( menu, qtr( "&Streaming..." ),
331 ":/stream", SLOT( openAndStreamingDialogs() ),
333 menu->addSeparator();
335 addDPStaticEntry( menu, qtr( "&Quit" ) ,
336 ":/quit", SLOT( quit() ), "Ctrl+Q" );
341 * Tools, like Media Information, Preferences or Messages
343 QMenu *QVLCMenu::ToolsMenu( QMenu *menu )
345 addDPStaticEntry( menu, qtr( "&Effects and Filters"), ":/settings",
346 SLOT( extendedDialog() ), "Ctrl+E" );
348 addDPStaticEntry( menu, qtr( "&Track Synchronization"), ":/settings",
349 SLOT( synchroDialog() ), "" );
351 addDPStaticEntry( menu, qtr( I_MENU_INFO ) , ":/info",
352 SLOT( mediaInfoDialog() ), "Ctrl+I" );
353 addDPStaticEntry( menu, qtr( I_MENU_CODECINFO ) ,
354 ":/info", SLOT( mediaCodecDialog() ), "Ctrl+J" );
356 addDPStaticEntry( menu, qtr( I_MENU_BOOKMARK ),"",
357 SLOT( bookmarksDialog() ), "Ctrl+B" );
359 addDPStaticEntry( menu, qtr( I_MENU_VLM ), "", SLOT( vlmDialog() ),
363 addDPStaticEntry( menu, qtr( I_MENU_MSG ),
364 ":/messages", SLOT( messagesDialog() ),
367 addDPStaticEntry( menu, qtr( "Plu&gins and extensions" ),
368 "", SLOT( pluginDialog() ) );
369 menu->addSeparator();
371 addDPStaticEntry( menu, qtr( "&Preferences" ),
372 ":/preferences", SLOT( prefsDialog() ), "Ctrl+P" );
377 QMenu *QVLCMenu::ToolsMenu( QWidget *parent )
379 return ToolsMenu( new QMenu( parent ) );
384 * Interface Modification
386 QMenu *QVLCMenu::ViewMenu( intf_thread_t *p_intf,
392 QMenu *menu = new QMenu( qtr( "V&iew" ), mi );
394 QAction *act = menu->addAction( QIcon( ":/playlist_menu" ),
395 qtr( "Play&list" ), mi,
396 SLOT( togglePlaylist() ), qtr( "Ctrl+L" ) );
398 /*menu->addSeparator();
399 menu->addAction( qtr( "Undock from Interface" ), mi,
400 SLOT( undockPlaylist() ), qtr( "Ctrl+U" ) );*/
402 menu->addSeparator();
406 QMenu *intfmenu = InterfacesMenu( p_intf, menu );
407 MenuFunc *f = new MenuFunc( intfmenu, 4 );
408 CONNECT( intfmenu, aboutToShow(), THEDP->menusUpdateMapper, map() );
409 THEDP->menusUpdateMapper->setMapping( intfmenu, f );
410 menu->addSeparator();
414 QAction *action = menu->addAction( qtr( "Mi&nimal View" ) );
415 action->setShortcut( qtr( "Ctrl+H" ) );
416 action->setCheckable( true );
417 action->setChecked( !with_intf &&
418 (mi->getControlsVisibilityStatus() & CONTROLS_HIDDEN ) );
420 CONNECT( action, triggered( bool ), mi, toggleMinimalView( bool ) );
421 CONNECT( mi, minimalViewToggled( bool ), action, setChecked( bool ) );
423 /* FullScreen View */
424 action = menu->addAction( qtr( "&Fullscreen Interface" ), mi,
425 SLOT( toggleFullScreen() ), QString( "F11" ) );
426 action->setCheckable( true );
427 action->setChecked( mi->isFullScreen() );
428 CONNECT( mi, fullscreenInterfaceToggled( bool ),
429 action, setChecked( bool ) );
431 /* Advanced Controls */
432 action = menu->addAction( qtr( "&Advanced Controls" ), mi,
433 SLOT( toggleAdvanced() ) );
434 action->setCheckable( true );
435 if( mi->getControlsVisibilityStatus() & CONTROLS_ADVANCED )
436 action->setChecked( true );
439 // I don't want to manage consistency between menus, so no popup-menu
441 action = menu->addAction( qtr( "Quit after Playback" ) );
442 action->setCheckable( true );
443 CONNECT( action, triggered( bool ), THEMIM, activatePlayQuit( bool ) );
446 #if 0 /* For Visualisations. Not yet working */
447 adv = menu->addAction( qtr( "Visualizations selector" ),
448 mi, SLOT( visual() ) );
449 adv->setCheckable( true );
450 if( visual_selector_enabled ) adv->setChecked( true );
453 menu->addSeparator();
454 addDPStaticEntry( menu, qtr( "Customi&ze Interface..." ),
455 ":/preferences", SLOT( toolbarDialog() ) );
456 menu->addSeparator();
462 * Interface Sub-Menu, to list extras interface and skins
464 QMenu *QVLCMenu::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
466 vector<vlc_object_t *> objects;
467 vector<const char *> varnames;
468 varnames.push_back( "intf-add" );
469 objects.push_back( VLC_OBJECT(p_intf) );
471 return Populate( p_intf, current, varnames, objects );
477 QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QMenu * current )
479 vector<vlc_object_t *> objects;
480 vector<const char *> varnames;
481 aout_instance_t *p_aout;
482 input_thread_t *p_input;
484 if( current->isEmpty() )
486 ACT_ADDMENU( current, "audio-es", qtr( "Audio &Track" ) );
487 ACT_ADDMENU( current, "audio-channels", qtr( "Audio &Channels" ) );
488 ACT_ADDMENU( current, "audio-device", qtr( "Audio &Device" ) );
489 current->addSeparator();
491 ACT_ADDMENU( current, "visual", qtr( "&Visualizations" ) );
492 current->addSeparator();
494 QAction *action = current->addAction( qtr( "Increase Volume" ),
495 ActionsManager::getInstance( p_intf ), SLOT( AudioUp() ) );
496 action->setData( true );
497 action = current->addAction( qtr( "Decrease Volume" ),
498 ActionsManager::getInstance( p_intf ), SLOT( AudioDown() ) );
499 action->setData( true );
500 action = current->addAction( qtr( "Mute" ),
501 ActionsManager::getInstance( p_intf ), SLOT( toggleMuteAudio() ) );
502 action->setData( true );
505 p_input = THEMIM->getInput();
506 p_aout = THEMIM->getAout();
507 EnableStaticEntries( current, ( p_aout != NULL ) );
508 AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
511 vlc_object_release( p_aout );
514 return Populate( p_intf, current, varnames, objects );
517 QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QWidget *parent )
519 return AudioMenu( p_intf, new QMenu( parent ) );
524 * Subtitles are part of Video.
526 QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current )
528 vout_thread_t *p_vout;
529 input_thread_t *p_input;
530 vector<vlc_object_t *> objects;
531 vector<const char *> varnames;
533 if( current->isEmpty() )
535 ACT_ADDMENU( current, "video-es", qtr( "Video &Track" ) );
538 QMenu *submenu = new QMenu( qtr( "&Subtitles Track" ), current );
539 action = current->addMenu( submenu );
540 action->setData( "spu-es" );
541 addDPStaticEntry( submenu, qtr( "Open File..." ), "",
542 SLOT( loadSubtitlesFile() ) );
543 submenu->addSeparator();
544 current->addSeparator();
546 ACT_ADDCHECK( current, "fullscreen", qtr( "&Fullscreen" ) );
547 ACT_ADDCHECK( current, "video-on-top", qtr( "Always &On Top" ) );
549 ACT_ADDCHECK( current, "directx-wallpaper", qtr( "DirectX Wallpaper" ) );
551 ACT_ADD( current, "video-snapshot", qtr( "Sna&pshot" ) );
553 current->addSeparator();
555 ACT_ADDMENU( current, "zoom", qtr( "&Zoom" ) );
556 ACT_ADDCHECK( current, "autoscale", qtr( "Sca&le" ) );
557 ACT_ADDMENU( current, "aspect-ratio", qtr( "&Aspect Ratio" ) );
558 ACT_ADDMENU( current, "crop", qtr( "&Crop" ) );
559 ACT_ADDMENU( current, "deinterlace", qtr( "&Deinterlace" ) );
560 ACT_ADDMENU( current, "postprocess", qtr( "&Post processing" ) );
563 p_input = THEMIM->getInput();
565 p_vout = THEMIM->getVout();
566 VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
569 vlc_object_release( p_vout );
571 return Populate( p_intf, current, varnames, objects );
574 QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QWidget *parent )
576 return VideoMenu( p_intf, new QMenu( parent ) );
581 * For DVD, MP4, MOV and other chapter based format
583 QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *menu )
587 QMenu *submenu = new QMenu( qtr( "&Bookmarks" ), menu );
588 addDPStaticEntry( submenu, qtr( "Manage &bookmarks" ), "",
589 SLOT( bookmarksDialog() ) );
590 submenu->addSeparator();
591 action = menu->addMenu( submenu );
592 action->setData( "bookmark" );
594 ACT_ADDMENU( menu, "title", qtr( "T&itle" ) );
595 ACT_ADDMENU( menu, "chapter", qtr( "&Chapter" ) );
596 ACT_ADDMENU( menu, "navigation", qtr( "&Navigation" ) );
597 ACT_ADDMENU( menu, "program", qtr( "&Program" ) );
599 menu->addSeparator();
600 PopupMenuPlaylistControlEntries( menu, p_intf );
601 PopupMenuControlEntries( menu, p_intf );
606 QMenu *QVLCMenu::RebuildNavigMenu( intf_thread_t *p_intf, QMenu *menu )
609 input_thread_t *p_object;
610 vector<vlc_object_t *> objects;
611 vector<const char *> varnames;
613 /* Get the input and hold it */
614 p_object = THEMIM->getInput();
616 InputAutoMenuBuilder( p_object, objects, varnames );
618 menu->addSeparator();
620 /* Title and so on */
621 PUSH_VAR( "prev-title" );
622 PUSH_VAR( "next-title" );
623 PUSH_VAR( "prev-chapter" );
624 PUSH_VAR( "next-chapter" );
626 EnableStaticEntries( menu, (p_object != NULL ) );
627 return Populate( p_intf, menu, varnames, objects );
630 QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QWidget *parent )
632 return NavigMenu( p_intf, new QMenu( parent ) );
636 * Service Discovery SubMenu
638 QMenu *QVLCMenu::SDMenu( intf_thread_t *p_intf, QWidget *parent )
640 QMenu *menu = new QMenu( parent );
641 menu->setTitle( qtr( I_PL_SD ) );
643 char **ppsz_longnames;
644 char **ppsz_names = vlc_sd_GetNames( &ppsz_longnames );
648 char **ppsz_name = ppsz_names, **ppsz_longname = ppsz_longnames;
649 for( ; *ppsz_name; ppsz_name++, ppsz_longname++ )
651 QAction *a = new QAction( qfu( *ppsz_longname ), menu );
652 a->setCheckable( true );
653 if( playlist_IsServicesDiscoveryLoaded( THEPL, *ppsz_name ) )
654 a->setChecked( true );
655 CONNECT( a, triggered(), THEDP->SDMapper, map() );
656 THEDP->SDMapper->setMapping( a, QString( *ppsz_name ) );
657 menu->addAction( a );
659 /* Special case for podcast */
660 if( !strcmp( *ppsz_name, "podcast" ) )
662 QAction *b = new QAction( qtr( "Configure podcasts..." ), menu );
663 //b->setEnabled( a->isChecked() );
664 menu->addAction( b );
665 CONNECT( b, triggered(), THEDP, podcastConfigureDialog() );
668 free( *ppsz_longname );
671 free( ppsz_longnames );
678 QMenu *QVLCMenu::HelpMenu( QWidget *parent )
680 QMenu *menu = new QMenu( parent );
681 addDPStaticEntry( menu, qtr( "&Help..." ) ,
682 ":/help", SLOT( helpDialog() ), "F1" );
684 addDPStaticEntry( menu, qtr( "Check for &Updates..." ) , "",
685 SLOT( updateDialog() ) );
687 menu->addSeparator();
688 addDPStaticEntry( menu, qtr( I_MENU_ABOUT ), ":/info",
689 SLOT( aboutDialog() ), "Shift+F1" );
693 /*****************************************************************************
694 * Popup menus - Right Click menus *
695 *****************************************************************************/
696 #define POPUP_BOILERPLATE \
697 unsigned int i_last_separator = 0; \
698 vector<vlc_object_t *> objects; \
699 vector<const char *> varnames; \
700 input_thread_t *p_input = THEMIM->getInput();
702 #define CREATE_POPUP \
703 Populate( p_intf, menu, varnames, objects ); \
704 p_intf->p_sys->p_popup_menu = menu; \
705 menu->popup( QCursor::pos() ); \
706 p_intf->p_sys->p_popup_menu = NULL; \
707 i_last_separator = 0;
709 void QVLCMenu::PopupPlayEntries( QMenu *menu,
710 intf_thread_t *p_intf,
711 input_thread_t *p_input )
715 /* Play or Pause action and icon */
716 if( !p_input || var_GetInteger( p_input, "state" ) != PLAYING_S )
718 action = menu->addAction( qtr( "Play" ),
719 ActionsManager::getInstance( p_intf ), SLOT( play() ) );
720 action->setIcon( QIcon( ":/play" ) );
724 addMIMStaticEntry( p_intf, menu, qtr( "Pause" ),
725 ":/pause", SLOT( togglePlayPause() ) );
729 void QVLCMenu::PopupMenuControlEntries( QMenu *menu, intf_thread_t *p_intf )
734 action = menu->addAction( qtr( "&Faster" ), THEMIM->getIM(),
736 action->setIcon( QIcon( ":/faster") );
737 action->setData( true );
739 action = menu->addAction( qtr( "Faster (fine)" ), THEMIM->getIM(),
740 SLOT( littlefaster() ) );
741 action->setData( true );
743 action = menu->addAction( qtr( "N&ormal Speed" ), THEMIM->getIM(),
744 SLOT( normalRate() ) );
745 action->setData( true );
747 action = menu->addAction( qtr( "Slower (fine)" ), THEMIM->getIM(),
748 SLOT( littleslower() ) );
749 action->setData( true );
751 action = menu->addAction( qtr( "Slo&wer" ), THEMIM->getIM(),
753 action->setIcon( QIcon( ":/slower") );
754 action->setData( true );
756 menu->addSeparator();
758 action = menu->addAction( qtr( "&Jump Forward" ), THEMIM->getIM(),
760 action->setIcon( QIcon( ":/skip_fw") );
761 action->setData( true );
763 action = menu->addAction( qtr( "Jump Bac&kward" ), THEMIM->getIM(),
765 action->setIcon( QIcon( ":/skip_back") );
766 action->setData( true );
767 addDPStaticEntry( menu, qtr( I_MENU_GOTOTIME ),"",
768 SLOT( gotoTimeDialog() ), "Ctrl+T" );
769 menu->addSeparator();
773 void QVLCMenu::PopupMenuPlaylistControlEntries( QMenu *menu,
774 intf_thread_t *p_intf )
776 addMIMStaticEntry( p_intf, menu, qtr( "&Stop" ), ":/stop", SLOT( stop() ) );
778 /* Next / Previous */
779 addMIMStaticEntry( p_intf, menu, qtr( "Pre&vious" ),
780 ":/previous", SLOT( prev() ) );
781 addMIMStaticEntry( p_intf, menu, qtr( "Ne&xt" ),
782 ":/next", SLOT( next() ) );
783 menu->addSeparator();
786 void QVLCMenu::PopupMenuStaticEntries( QMenu *menu )
788 QMenu *openmenu = new QMenu( qtr( "Open Media" ), menu );
789 addDPStaticEntry( openmenu, qtr( "&Open File..." ),
790 ":/file-asym", SLOT( openFileDialog() ) );
791 addDPStaticEntry( openmenu, qtr( I_OPEN_FOLDER ),
792 ":/folder-grey", SLOT( PLOpenDir() ) );
793 addDPStaticEntry( openmenu, qtr( "Open &Disc..." ),
794 ":/disc", SLOT( openDiscDialog() ) );
795 addDPStaticEntry( openmenu, qtr( "Open &Network..." ),
796 ":/network", SLOT( openNetDialog() ) );
797 addDPStaticEntry( openmenu, qtr( "Open &Capture Device..." ),
798 ":/capture-card", SLOT( openCaptureDialog() ) );
799 menu->addMenu( openmenu );
801 menu->addSeparator();
803 QMenu *helpmenu = HelpMenu( menu );
804 helpmenu->setTitle( qtr( "Help" ) );
805 menu->addMenu( helpmenu );
808 addDPStaticEntry( menu, qtr( "Quit" ), ":/quit",
809 SLOT( quit() ), "Ctrl+Q" );
812 /* Video Tracks and Subtitles tracks */
813 void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf )
818 vout_thread_t *p_vout = THEMIM->getVout();
821 VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
822 vlc_object_release( p_vout );
825 QMenu *menu = new QMenu();
830 void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf )
835 aout_instance_t *p_aout = THEMIM->getAout();
836 AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
838 vlc_object_release( p_aout );
840 QMenu *menu = new QMenu();
844 /* Navigation stuff, and general menus ( open ), used only for skins */
845 void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf )
851 varnames.push_back( "audio-es" );
852 InputAutoMenuBuilder( p_input, objects, varnames );
856 QMenu *menu = new QMenu();
857 Populate( p_intf, menu, varnames, objects );
859 menu->addSeparator();
860 PopupPlayEntries( menu, p_intf, p_input );
861 PopupMenuPlaylistControlEntries( menu, p_intf);
863 menu->addSeparator();
864 PopupMenuControlEntries( menu, p_intf );
866 menu->addSeparator();
867 PopupMenuStaticEntries( menu );
869 p_intf->p_sys->p_popup_menu = menu;
870 menu->popup( QCursor::pos() );
871 p_intf->p_sys->p_popup_menu = NULL;
874 /* Main Menu that sticks everything together */
875 void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show )
877 /* Destroy popup menu if there is one */
880 delete p_intf->p_sys->p_popup_menu;
881 p_intf->p_sys->p_popup_menu = NULL;
885 /* Delete and recreate a popup if there is one */
886 if( p_intf->p_sys->p_popup_menu )
887 delete p_intf->p_sys->p_popup_menu;
890 QMenu *menu = new QMenu();
893 bool b_isFullscreen = false;
894 MainInterface *mi = p_intf->p_sys->p_mi;
898 PopupPlayEntries( menu, p_intf, p_input );
899 PopupMenuPlaylistControlEntries( menu, p_intf );
900 menu->addSeparator();
904 vout_thread_t *p_vout = THEMIM->getVout();
906 /* Add a fullscreen switch button, since it is the most used function */
909 vlc_value_t val; var_Get( p_vout, "fullscreen", &val );
911 b_isFullscreen = !( !val.b_bool );
913 CreateAndConnect( menu, "fullscreen",
914 qtr( "Leave Fullscreen" ),"" , ITEM_NORMAL,
915 VLC_OBJECT(p_vout), val, VLC_VAR_BOOL, b_isFullscreen );
916 vlc_object_release( p_vout );
918 menu->addSeparator();
922 InputAutoMenuBuilder( p_input, objects, varnames );
925 submenu = new QMenu( menu );
926 action = menu->addMenu( AudioMenu( p_intf, submenu ) );
927 action->setText( qtr( "&Audio" ) );
928 if( action->menu()->isEmpty() )
929 action->setEnabled( false );
932 submenu = new QMenu( menu );
933 action = menu->addMenu( VideoMenu( p_intf, submenu ) );
934 action->setText( qtr( "&Video" ) );
935 if( action->menu()->isEmpty() )
936 action->setEnabled( false );
938 /* Playback menu for chapters */
939 submenu = new QMenu( menu );
940 action = menu->addMenu( NavigMenu( p_intf, submenu ) );
941 action->setText( qtr( "&Playback" ) );
942 if( action->menu()->isEmpty() )
943 action->setEnabled( false );
946 menu->addSeparator();
948 /* Add some special entries for windowed mode: Interface Menu */
949 if( !b_isFullscreen )
951 submenu = new QMenu( qtr( "Interface" ), menu );
952 QMenu *tools = ToolsMenu( submenu );
953 submenu->addSeparator();
955 /* In skins interface, append some items */
958 objects.clear(); varnames.clear();
960 vlc_object_t *p_object = ( vlc_object_t* )
961 vlc_object_find_name( p_intf, "skins2", FIND_PARENT );
964 objects.push_back( p_object );
965 varnames.push_back( "intf-skins" );
966 Populate( p_intf, submenu, varnames, objects );
967 vlc_object_release( p_object );
970 msg_Warn( p_intf, "could not find parent interface" );
973 menu->addMenu( ViewMenu( p_intf, mi, false ));
975 menu->addMenu( submenu );
978 /* Static entries for ending, like open */
979 PopupMenuStaticEntries( menu );
981 p_intf->p_sys->p_popup_menu = menu;
982 p_intf->p_sys->p_popup_menu->popup( QCursor::pos() );
989 /************************************************************************
991 ************************************************************************/
993 void QVLCMenu::updateSystrayMenu( MainInterface *mi,
994 intf_thread_t *p_intf,
995 bool b_force_visible )
999 /* Get the systray menu and clean it */
1000 QMenu *sysMenu = mi->getSysTrayMenu();
1003 /* Hide / Show VLC and cone */
1004 if( mi->isVisible() || b_force_visible )
1006 sysMenu->addAction( QIcon( ":/vlc16.png" ),
1007 qtr( "Hide VLC media player in taskbar" ), mi,
1008 SLOT( toggleUpdateSystrayMenu() ) );
1012 sysMenu->addAction( QIcon( ":/vlc16.png" ),
1013 qtr( "Show VLC media player" ), mi,
1014 SLOT( toggleUpdateSystrayMenu() ) );
1017 sysMenu->addSeparator();
1018 PopupPlayEntries( sysMenu, p_intf, p_input );
1019 PopupMenuPlaylistControlEntries( sysMenu, p_intf);
1020 PopupMenuControlEntries( sysMenu, p_intf);
1022 sysMenu->addSeparator();
1023 addDPStaticEntry( sysMenu, qtr( "&Open Media" ),
1024 ":/file-wide", SLOT( openFileDialog() ) );
1025 addDPStaticEntry( sysMenu, qtr( "&Quit" ) ,
1026 ":/quit", SLOT( quit() ) );
1029 mi->getSysTray()->setContextMenu( sysMenu );
1033 #undef PUSH_SEPARATOR
1035 /*************************************************************************
1036 * Builders for automenus
1037 *************************************************************************/
1038 QMenu * QVLCMenu::Populate( intf_thread_t *p_intf,
1040 vector< const char *> & varnames,
1041 vector<vlc_object_t *> & objects )
1043 QMenu *menu = current;
1046 currentGroup = NULL;
1048 vlc_object_t *p_object;
1050 for( int i = 0; i < ( int )objects.size() ; i++ )
1052 if( !varnames[i] || !*varnames[i] )
1054 menu->addSeparator();
1057 p_object = objects[i];
1059 UpdateItem( p_intf, menu, varnames[i], p_object, true );
1064 /*****************************************************************************
1066 *****************************************************************************/
1068 static bool IsMenuEmpty( const char *psz_var,
1069 vlc_object_t *p_object,
1070 bool b_root = true )
1072 vlc_value_t val, val_list;
1073 int i_type, i_result, i;
1075 /* Check the type of the object variable */
1076 i_type = var_Type( p_object, psz_var );
1078 /* Check if we want to display the variable */
1079 if( !( i_type & VLC_VAR_HASCHOICE ) ) return false;
1081 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
1082 if( val.i_int == 0 ) return true;
1084 if( ( i_type & VLC_VAR_TYPE ) != VLC_VAR_VARIABLE )
1086 if( val.i_int == 1 && b_root ) return true;
1090 /* Check children variables in case of VLC_VAR_VARIABLE */
1091 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
1096 for( i = 0, i_result = true; i < val_list.p_list->i_count; i++ )
1098 if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
1106 /* clean up everything */
1107 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, NULL );
1112 #define TEXT_OR_VAR qfu ( text.psz_string ? text.psz_string : psz_var )
1114 void QVLCMenu::UpdateItem( intf_thread_t *p_intf, QMenu *menu,
1115 const char *psz_var, vlc_object_t *p_object, bool b_submenu )
1117 vlc_value_t val, text;
1120 QAction *action = FindActionWithVar( menu, psz_var );
1122 DeleteNonStaticEntries( action->menu() );
1127 action->setEnabled( false );
1131 /* Check the type of the object variable */
1132 /* This HACK is needed so we have a radio button for audio and video tracks
1133 instread of a checkbox */
1134 if( !strcmp( psz_var, "audio-es" )
1135 || !strcmp( psz_var, "video-es" ) )
1136 i_type = VLC_VAR_INTEGER | VLC_VAR_HASCHOICE;
1138 i_type = var_Type( p_object, psz_var );
1140 switch( i_type & VLC_VAR_TYPE )
1144 case VLC_VAR_VARIABLE:
1145 case VLC_VAR_STRING:
1146 case VLC_VAR_INTEGER:
1150 /* Variable doesn't exist or isn't handled */
1152 action->setEnabled( false );
1156 /* Make sure we want to display the variable */
1157 if( menu->isEmpty() && IsMenuEmpty( psz_var, p_object ) )
1160 action->setEnabled( false );
1164 /* Get the descriptive name of the variable */
1165 int i_ret = var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
1166 if( i_ret != VLC_SUCCESS )
1168 text.psz_string = NULL;
1173 action = new QAction( TEXT_OR_VAR, menu );
1174 menu->addAction( action );
1175 action->setData( psz_var );
1178 /* Some specific stuff */
1179 bool forceDisabled = false;
1180 if( !strcmp( psz_var, "spu-es" ) )
1182 vout_thread_t *p_vout = THEMIM->getVout();
1183 forceDisabled = ( p_vout == NULL );
1185 vlc_object_release( p_vout );
1188 if( i_type & VLC_VAR_HASCHOICE )
1190 /* Append choices menu */
1194 submenu = action->menu();
1197 submenu = new QMenu( menu );
1198 action->setMenu( submenu );
1202 CreateChoicesMenu( submenu, psz_var, p_object, true ) == 0 );
1204 action->setEnabled( false );
1209 CreateChoicesMenu( menu, psz_var, p_object, true ) == 0 );
1211 FREENULL( text.psz_string );
1215 switch( i_type & VLC_VAR_TYPE )
1218 var_Get( p_object, psz_var, &val );
1219 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_NORMAL,
1220 p_object, val, i_type );
1224 var_Get( p_object, psz_var, &val );
1225 val.b_bool = !val.b_bool;
1226 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_CHECK,
1227 p_object, val, i_type, !val.b_bool );
1230 FREENULL( text.psz_string );
1234 int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
1235 vlc_object_t *p_object, bool b_root )
1237 vlc_value_t val, val_list, text_list;
1240 /* Check the type of the object variable */
1241 i_type = var_Type( p_object, psz_var );
1243 /* Make sure we want to display the variable */
1244 if( submenu->isEmpty() && IsMenuEmpty( psz_var, p_object, b_root ) )
1245 return VLC_EGENERIC;
1247 switch( i_type & VLC_VAR_TYPE )
1251 case VLC_VAR_VARIABLE:
1252 case VLC_VAR_STRING:
1253 case VLC_VAR_INTEGER:
1257 /* Variable doesn't exist or isn't handled */
1258 return VLC_EGENERIC;
1261 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
1262 &val_list, &text_list ) < 0 )
1264 return VLC_EGENERIC;
1267 #define CURVAL val_list.p_list->p_values[i]
1268 #define CURTEXT text_list.p_list->p_values[i].psz_string
1270 for( i = 0; i < val_list.p_list->i_count; i++ )
1272 vlc_value_t another_val;
1274 QMenu *subsubmenu = new QMenu( submenu );
1276 switch( i_type & VLC_VAR_TYPE )
1278 case VLC_VAR_VARIABLE:
1279 CreateChoicesMenu( subsubmenu, CURVAL.psz_string, p_object, false );
1280 subsubmenu->setTitle( qfu( CURTEXT ? CURTEXT :CURVAL.psz_string ) );
1281 submenu->addMenu( subsubmenu );
1284 case VLC_VAR_STRING:
1285 var_Get( p_object, psz_var, &val );
1286 another_val.psz_string = strdup( CURVAL.psz_string );
1287 menutext = qfu( CURTEXT ? CURTEXT : another_val.psz_string );
1288 CreateAndConnect( submenu, psz_var, menutext, "", ITEM_RADIO,
1289 p_object, another_val, i_type,
1290 val.psz_string && !strcmp( val.psz_string, CURVAL.psz_string ) );
1292 free( val.psz_string );
1295 case VLC_VAR_INTEGER:
1296 var_Get( p_object, psz_var, &val );
1297 if( CURTEXT ) menutext = qfu( CURTEXT );
1298 else menutext.sprintf( "%d", CURVAL.i_int );
1299 CreateAndConnect( submenu, psz_var, menutext, "", ITEM_RADIO,
1300 p_object, CURVAL, i_type,
1301 CURVAL.i_int == val.i_int );
1305 var_Get( p_object, psz_var, &val );
1306 if( CURTEXT ) menutext = qfu( CURTEXT );
1307 else menutext.sprintf( "%.2f", CURVAL.f_float );
1308 CreateAndConnect( submenu, psz_var, menutext, "", ITEM_RADIO,
1309 p_object, CURVAL, i_type,
1310 CURVAL.f_float == val.f_float );
1317 currentGroup = NULL;
1319 /* clean up everything */
1320 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
1324 return submenu->isEmpty() ? VLC_EGENERIC : VLC_SUCCESS;
1327 void QVLCMenu::CreateAndConnect( QMenu *menu, const char *psz_var,
1328 QString text, QString help,
1329 int i_item_type, vlc_object_t *p_obj,
1330 vlc_value_t val, int i_val_type,
1333 QAction *action = FindActionWithVar( menu, psz_var );
1338 action = new QAction( text, menu );
1339 menu->addAction( action );
1343 action->setToolTip( help );
1344 action->setEnabled( p_obj != NULL );
1346 if( i_item_type == ITEM_CHECK )
1348 action->setCheckable( true );
1350 else if( i_item_type == ITEM_RADIO )
1352 action->setCheckable( true );
1354 currentGroup = new QActionGroup( menu );
1355 currentGroup->addAction( action );
1358 action->setChecked( checked );
1360 MenuItemData *itemData = new MenuItemData( THEDP->menusMapper, p_obj, i_val_type,
1362 CONNECT( action, triggered(), THEDP->menusMapper, map() );
1363 THEDP->menusMapper->setMapping( action, itemData );
1366 menu->addAction( action );
1369 void QVLCMenu::DoAction( QObject *data )
1371 MenuItemData *itemData = qobject_cast<MenuItemData *>( data );
1372 vlc_object_t *p_object = itemData->p_obj;
1373 if( p_object == NULL ) return;
1375 var_Set( p_object, itemData->psz_var, itemData->val );
1378 void QVLCMenu::updateRecents( intf_thread_t *p_intf )
1383 RecentsMRL* rmrl = RecentsMRL::getInstance( p_intf );
1384 QList<QString> l = rmrl->recents();
1386 recentsMenu->clear();
1389 action = recentsMenu->addAction( qtr(" - Empty - ") );
1390 action->setEnabled( false );
1394 for( int i = 0; i < l.size(); ++i )
1396 action = recentsMenu->addAction(
1397 QString( "&%1: " ).arg( i + 1 ) + l.at( i ),
1400 rmrl->signalMapper->setMapping( action, l.at( i ) );
1403 recentsMenu->addSeparator();
1404 recentsMenu->addAction( qtr("&Clear"), rmrl, SLOT( clear() ) );