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 /* HACK for minimalView to go around a Qt bug/feature
77 * that doesn't update the QAction checked state when QMenu is hidden */
78 QAction *QVLCMenu::minimalViewAction = NULL;
79 QAction *QVLCMenu::fullscreenViewAction = NULL;
81 QMenu *QVLCMenu::recentsMenu = NULL;
83 /****************************************************************************
85 ****************************************************************************
86 * Add static entries to DP in menus
87 ***************************************************************************/
88 void addDPStaticEntry( QMenu *menu,
92 const char *shortcut = NULL )
94 QAction *action = NULL;
95 if( !EMPTY_STR( icon ) > 0 )
97 if( !EMPTY_STR( shortcut ) > 0 )
98 action = menu->addAction( QIcon( icon ), text, THEDP,
99 member, qtr( shortcut ) );
101 action = menu->addAction( QIcon( icon ), text, THEDP, member );
105 if( !EMPTY_STR( shortcut ) > 0 )
106 action = menu->addAction( text, THEDP, member, qtr( shortcut ) );
108 action = menu->addAction( text, THEDP, member );
110 action->setData( true );
116 void addMIMStaticEntry( intf_thread_t *p_intf,
123 if( strlen( icon ) > 0 )
125 action = menu->addAction( text, THEMIM, member );
126 action->setIcon( QIcon( icon ) );
130 menu->addAction( text, THEMIM, member );
132 action->setData( "ignore" );
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() == "ignore" ||
147 /* Be careful here, because data("string").toBool is true */
148 ( enable && (actions[i]->data().toString() == "true" ) ) );
153 * \return Number of static entries
155 int DeleteNonStaticEntries( QMenu *menu )
157 if( !menu ) return VLC_EGENERIC;
161 QList< QAction* > actions = menu->actions();
162 for( int i = 0; i < actions.size(); ++i )
164 if( !actions[i]->data().toBool() )
173 * \return QAction associated to psz_var variable
175 static QAction * FindActionWithVar( QMenu *menu, const char *psz_var )
177 QList< QAction* > actions = menu->actions();
178 for( int i = 0; i < actions.size(); ++i )
180 if( actions[i]->data().toString() == psz_var )
186 /*****************************************************************************
187 * Definitions of variables for the dynamic menus
188 *****************************************************************************/
189 #define PUSH_VAR( var ) varnames.push_back( var ); \
190 objects.push_back( VLC_OBJECT(p_object) )
192 #define PUSH_INPUTVAR( var ) varnames.push_back( var ); \
193 objects.push_back( VLC_OBJECT(p_input) );
195 #define PUSH_SEPARATOR if( objects.size() != i_last_separator ) { \
196 objects.push_back( 0 ); varnames.push_back( "" ); \
197 i_last_separator = objects.size(); }
199 static int InputAutoMenuBuilder( input_thread_t *p_object,
200 vector<vlc_object_t *> &objects,
201 vector<const char *> &varnames )
203 PUSH_VAR( "bookmark" );
205 PUSH_VAR( "chapter" );
206 PUSH_VAR( "navigation" );
207 PUSH_VAR( "program" );
211 static int VideoAutoMenuBuilder( vout_thread_t *p_object,
212 input_thread_t *p_input,
213 vector<vlc_object_t *> &objects,
214 vector<const char *> &varnames )
216 PUSH_INPUTVAR( "video-es" );
217 PUSH_INPUTVAR( "spu-es" );
218 PUSH_VAR( "fullscreen" );
219 PUSH_VAR( "video-on-top" );
221 PUSH_VAR( "directx-wallpaper" );
223 PUSH_VAR( "video-snapshot" );
225 PUSH_VAR( "autoscale" );
226 PUSH_VAR( "aspect-ratio" );
228 PUSH_VAR( "deinterlace" );
229 PUSH_VAR( "postprocess" );
234 static int AudioAutoMenuBuilder( aout_instance_t *p_object,
235 input_thread_t *p_input,
236 vector<vlc_object_t *> &objects,
237 vector<const char *> &varnames )
239 PUSH_INPUTVAR( "audio-es" );
240 PUSH_VAR( "audio-channels" );
241 PUSH_VAR( "audio-device" );
242 PUSH_VAR( "visual" );
246 /*****************************************************************************
249 *****************************************************************************/
251 #define BAR_ADD( func, title ) { \
252 QMenu *_menu = func; _menu->setTitle( title ); bar->addMenu( _menu ); }
254 #define BAR_DADD( func, title, id ) { \
255 QMenu *_menu = func; _menu->setTitle( title ); bar->addMenu( _menu ); \
256 MenuFunc *f = new MenuFunc( _menu, id ); \
257 CONNECT( _menu, aboutToShow(), THEDP->menusUpdateMapper, map() ); \
258 THEDP->menusUpdateMapper->setMapping( _menu, f ); }
260 #define ACT_ADD( _menu, val, title ) { \
261 QAction *_action = new QAction( title, _menu ); _action->setData( val ); \
262 _menu->addAction( _action ); }
264 #define ACT_ADDMENU( _menu, val, title ) { \
265 QAction *_action = new QAction( title, _menu ); _action->setData( val ); \
266 _action->setMenu( new QMenu() ); _menu->addAction( _action ); }
268 #define ACT_ADDCHECK( _menu, val, title ) { \
269 QAction *_action = new QAction( title, _menu ); _action->setData( val ); \
270 _action->setCheckable( true ); _menu->addAction( _action ); }
273 * Main Menu Bar Creation
275 void QVLCMenu::createMenuBar( MainInterface *mi,
276 intf_thread_t *p_intf )
278 /* QMainWindows->menuBar()
279 gives the QProcess::destroyed timeout issue on Cleanlooks style with
280 setDesktopAware set to false */
281 QMenuBar *bar = mi->menuBar();
283 BAR_ADD( FileMenu( p_intf, bar ), qtr( "&Media" ) );
285 /* Dynamic menus, rebuilt before being showed */
286 BAR_DADD( NavigMenu( p_intf, bar ), qtr( "P&layback" ), 3 );
287 BAR_DADD( AudioMenu( p_intf, bar ), qtr( "&Audio" ), 1 );
288 BAR_DADD( VideoMenu( p_intf, bar ), qtr( "&Video" ), 2 );
290 BAR_ADD( ToolsMenu( bar ), qtr( "&Tools" ) );
291 BAR_ADD( ViewMenu( p_intf, mi ), qtr( "V&iew" ) );
292 BAR_ADD( HelpMenu( bar ), qtr( "&Help" ) );
298 * Media ( File ) Menu
299 * Opening, streaming and quit
301 QMenu *QVLCMenu::FileMenu( intf_thread_t *p_intf, QWidget *parent )
303 QMenu *menu = new QMenu( parent );
305 addDPStaticEntry( menu, qtr( "&Open File..." ),
306 ":/file-asym", SLOT( simpleOpenDialog() ), "Ctrl+O" );
307 addDPStaticEntry( menu, qtr( "Advanced Open File..." ),
308 ":/file-asym", SLOT( openFileDialog() ), "Ctrl+Shift+O" );
309 addDPStaticEntry( menu, qtr( I_OPEN_FOLDER ),
310 ":/folder-grey", SLOT( PLOpenDir() ), "Ctrl+F" );
311 addDPStaticEntry( menu, qtr( "Open &Disc..." ),
312 ":/disc", SLOT( openDiscDialog() ), "Ctrl+D" );
313 addDPStaticEntry( menu, qtr( "Open &Network..." ),
314 ":/network", SLOT( openNetDialog() ), "Ctrl+N" );
315 addDPStaticEntry( menu, qtr( "Open &Capture Device..." ),
316 ":/capture-card", SLOT( openCaptureDialog() ),
319 menu->addSeparator();
320 addDPStaticEntry( menu, qtr( "Paste &MRL" ),
321 NULL, SLOT( openUrlDialog() ), "Ctrl+V" );
323 recentsMenu = new QMenu( qtr( "&Recent Media" ), menu );
324 updateRecents( p_intf );
325 menu->addMenu( recentsMenu );
326 menu->addMenu( SDMenu( p_intf, menu ) );
327 menu->addSeparator();
329 addDPStaticEntry( menu, qtr( I_PL_SAVE ), "", SLOT( saveAPlaylist() ),
331 menu->addSeparator();
333 addDPStaticEntry( menu, qtr( "Conve&rt / Save..." ), "",
334 SLOT( openAndTranscodingDialogs() ), "Ctrl+R" );
335 addDPStaticEntry( menu, qtr( "&Streaming..." ),
336 ":/stream", SLOT( openAndStreamingDialogs() ),
338 menu->addSeparator();
340 addDPStaticEntry( menu, qtr( "&Quit" ) ,
341 ":/quit", SLOT( quit() ), "Ctrl+Q" );
346 * Tools, like Media Information, Preferences or Messages
348 QMenu *QVLCMenu::ToolsMenu( QMenu *menu )
350 addDPStaticEntry( menu, qtr( I_MENU_EXT ), ":/settings",
351 SLOT( extendedDialog() ), "Ctrl+E" );
353 addDPStaticEntry( menu, qtr( I_MENU_INFO ) , ":/info",
354 SLOT( mediaInfoDialog() ), "Ctrl+I" );
355 addDPStaticEntry( menu, qtr( I_MENU_CODECINFO ) ,
356 ":/info", SLOT( mediaCodecDialog() ), "Ctrl+J" );
358 addDPStaticEntry( menu, qtr( I_MENU_BOOKMARK ),"",
359 SLOT( bookmarksDialog() ), "Ctrl+B" );
361 addDPStaticEntry( menu, qtr( I_MENU_VLM ), "", SLOT( vlmDialog() ),
365 addDPStaticEntry( menu, qtr( I_MENU_MSG ),
366 ":/messages", SLOT( messagesDialog() ),
369 addDPStaticEntry( menu, qtr( "Plu&gins and extensions" ),
370 "", SLOT( pluginDialog() ) );
371 menu->addSeparator();
373 addDPStaticEntry( menu, qtr( "&Preferences" ),
374 ":/preferences", SLOT( prefsDialog() ), "Ctrl+P" );
379 QMenu *QVLCMenu::ToolsMenu( QWidget *parent )
381 return ToolsMenu( new QMenu( parent ) );
386 * Interface Modification
388 QMenu *QVLCMenu::ViewMenu( intf_thread_t *p_intf,
394 QMenu *menu = new QMenu( qtr( "V&iew" ), mi );
396 QAction *act = menu->addAction( QIcon( ":/playlist_menu" ),
397 qtr( "Play&list" ), mi,
398 SLOT( togglePlaylist() ), qtr( "Ctrl+L" ) );
400 /*menu->addSeparator();
401 menu->addAction( qtr( "Undock from Interface" ), mi,
402 SLOT( undockPlaylist() ), qtr( "Ctrl+U" ) );*/
404 menu->addSeparator();
408 QMenu *intfmenu = InterfacesMenu( p_intf, menu );
409 MenuFunc *f = new MenuFunc( intfmenu, 4 );
410 CONNECT( intfmenu, aboutToShow(), THEDP->menusUpdateMapper, map() );
411 THEDP->menusUpdateMapper->setMapping( intfmenu, f );
412 menu->addSeparator();
416 QAction *action = menu->addAction( qtr( "Mi&nimal View" ), mi,
417 SLOT( toggleMinimalView() ), qtr( "Ctrl+H" ) );
418 action->setCheckable( true );
420 if( mi->getControlsVisibilityStatus() & CONTROLS_VISIBLE )
421 action->setChecked( true );
422 minimalViewAction = action; /* HACK for minimalView */
424 /* FullScreen View */
425 action = menu->addAction( qtr( "&Fullscreen Interface" ), mi,
426 SLOT( toggleFullScreen() ), QString( "F11" ) );
427 fullscreenViewAction = action;
428 action->setCheckable( true );
430 /* Advanced Controls */
431 action = menu->addAction( qtr( "&Advanced Controls" ), mi,
432 SLOT( toggleAdvanced() ) );
433 action->setCheckable( true );
434 if( mi->getControlsVisibilityStatus() & CONTROLS_ADVANCED )
435 action->setChecked( true );
437 #if 0 /* For Visualisations. Not yet working */
438 adv = menu->addAction( qtr( "Visualizations selector" ),
439 mi, SLOT( visual() ) );
440 adv->setCheckable( true );
441 if( visual_selector_enabled ) adv->setChecked( true );
444 menu->addSeparator();
445 addDPStaticEntry( menu, qtr( "Customi&ze Interface..." ),
446 ":/preferences", SLOT( toolbarDialog() ) );
447 menu->addSeparator();
453 * Interface Sub-Menu, to list extras interface and skins
455 QMenu *QVLCMenu::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
457 vector<vlc_object_t *> objects;
458 vector<const char *> varnames;
459 varnames.push_back( "intf-add" );
460 objects.push_back( VLC_OBJECT(p_intf) );
462 return Populate( p_intf, current, varnames, objects );
468 QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QMenu * current )
470 vector<vlc_object_t *> objects;
471 vector<const char *> varnames;
472 aout_instance_t *p_aout;
473 input_thread_t *p_input;
475 if( current->isEmpty() )
477 ACT_ADDMENU( current, "audio-es", qtr( "Audio &Track" ) );
478 ACT_ADDMENU( current, "audio-channels", qtr( "Audio &Channels" ) );
479 ACT_ADDMENU( current, "audio-device", qtr( "Audio &Device" ) );
480 current->addSeparator();
482 ACT_ADDMENU( current, "visual", qtr( "&Visualizations" ) );
483 current->addSeparator();
485 QAction *action = current->addAction( qtr( "Increase Volume" ),
486 ActionsManager::getInstance( p_intf ), SLOT( AudioUp() ) );
487 action->setData( true );
488 action = current->addAction( qtr( "Decrease Volume" ),
489 ActionsManager::getInstance( p_intf ), SLOT( AudioDown() ) );
490 action->setData( true );
491 action = current->addAction( qtr( "Mute" ),
492 ActionsManager::getInstance( p_intf ), SLOT( toggleMuteAudio() ) );
493 action->setData( true );
496 p_input = THEMIM->getInput();
498 vlc_object_hold( p_input );
499 p_aout = THEMIM->getAout();
500 EnableStaticEntries( current, ( p_aout != NULL ) );
501 AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
504 vlc_object_release( p_aout );
507 vlc_object_release( p_input );
509 return Populate( p_intf, current, varnames, objects );
512 QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QWidget *parent )
514 return AudioMenu( p_intf, new QMenu( parent ) );
519 * Subtitles are part of Video.
521 QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current )
523 vout_thread_t *p_vout;
524 input_thread_t *p_input;
525 vector<vlc_object_t *> objects;
526 vector<const char *> varnames;
528 if( current->isEmpty() )
530 ACT_ADDMENU( current, "video-es", qtr( "Video &Track" ) );
533 QMenu *submenu = new QMenu( qtr( "&Subtitles Track" ), current );
534 action = current->addMenu( submenu );
535 action->setData( "spu-es" );
536 addDPStaticEntry( submenu, qtr( "Open File..." ), "",
537 SLOT( loadSubtitlesFile() ) );
538 submenu->addSeparator();
539 current->addSeparator();
541 ACT_ADDCHECK( current, "fullscreen", qtr( "&Fullscreen" ) );
542 ACT_ADDCHECK( current, "video-on-top", qtr( "Always &On Top" ) );
544 ACT_ADDCHECK( current, "directx-wallpaper", qtr( "DirectX Wallpaper" ) );
546 ACT_ADD( current, "video-snapshot", qtr( "Sna&pshot" ) );
548 current->addSeparator();
550 ACT_ADDMENU( current, "zoom", qtr( "&Zoom" ) );
551 ACT_ADDCHECK( current, "autoscale", qtr( "Sca&le" ) );
552 ACT_ADDMENU( current, "aspect-ratio", qtr( "&Aspect Ratio" ) );
553 ACT_ADDMENU( current, "crop", qtr( "&Crop" ) );
554 ACT_ADDMENU( current, "deinterlace", qtr( "&Deinterlace" ) );
555 ACT_ADDMENU( current, "postprocess", qtr( "&Post processing" ) );
558 p_input = THEMIM->getInput();
560 vlc_object_hold( p_input );
562 p_vout = THEMIM->getVout();
563 VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
566 vlc_object_release( p_vout );
569 vlc_object_release( p_input );
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 vlc_object_hold( p_object );
618 InputAutoMenuBuilder( p_object, objects, varnames );
620 menu->addSeparator();
622 /* Title and so on */
623 PUSH_VAR( "prev-title" );
624 PUSH_VAR( "next-title" );
625 PUSH_VAR( "prev-chapter" );
626 PUSH_VAR( "next-chapter" );
629 vlc_object_release( p_object );
631 EnableStaticEntries( menu, (p_object != NULL ) );
632 return Populate( p_intf, menu, varnames, objects );
635 QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QWidget *parent )
637 return NavigMenu( p_intf, new QMenu( parent ) );
641 * Service Discovery SubMenu
643 QMenu *QVLCMenu::SDMenu( intf_thread_t *p_intf, QWidget *parent )
645 QMenu *menu = new QMenu( parent );
646 menu->setTitle( qtr( I_PL_SD ) );
648 char **ppsz_longnames;
649 char **ppsz_names = vlc_sd_GetNames( &ppsz_longnames );
653 char **ppsz_name = ppsz_names, **ppsz_longname = ppsz_longnames;
654 for( ; *ppsz_name; ppsz_name++, ppsz_longname++ )
656 QAction *a = new QAction( qfu( *ppsz_longname ), menu );
657 a->setCheckable( true );
658 if( playlist_IsServicesDiscoveryLoaded( THEPL, *ppsz_name ) )
659 a->setChecked( true );
660 CONNECT( a, triggered(), THEDP->SDMapper, map() );
661 THEDP->SDMapper->setMapping( a, QString( *ppsz_name ) );
662 menu->addAction( a );
664 /* Special case for podcast */
665 if( !strcmp( *ppsz_name, "podcast" ) )
667 QAction *b = new QAction( qtr( "Configure podcasts..." ), menu );
668 //b->setEnabled( a->isChecked() );
669 menu->addAction( b );
670 CONNECT( b, triggered(), THEDP, podcastConfigureDialog() );
673 free( *ppsz_longname );
676 free( ppsz_longnames );
683 QMenu *QVLCMenu::HelpMenu( QWidget *parent )
685 QMenu *menu = new QMenu( parent );
686 addDPStaticEntry( menu, qtr( "&Help..." ) ,
687 ":/help", SLOT( helpDialog() ), "F1" );
689 addDPStaticEntry( menu, qtr( "Check for &Updates..." ) , "",
690 SLOT( updateDialog() ) );
692 menu->addSeparator();
693 addDPStaticEntry( menu, qtr( I_MENU_ABOUT ), ":/info",
694 SLOT( aboutDialog() ), "Shift+F1" );
698 /*****************************************************************************
699 * Popup menus - Right Click menus *
700 *****************************************************************************/
701 #define POPUP_BOILERPLATE \
702 unsigned int i_last_separator = 0; \
703 vector<vlc_object_t *> objects; \
704 vector<const char *> varnames; \
705 input_thread_t *p_input = THEMIM->getInput();
707 #define CREATE_POPUP \
708 Populate( p_intf, menu, varnames, objects ); \
709 p_intf->p_sys->p_popup_menu = menu; \
710 menu->popup( QCursor::pos() ); \
711 p_intf->p_sys->p_popup_menu = NULL; \
712 i_last_separator = 0;
714 void QVLCMenu::PopupPlayEntries( QMenu *menu,
715 intf_thread_t *p_intf,
716 input_thread_t *p_input )
720 /* Play or Pause action and icon */
721 if( !p_input || var_GetInteger( p_input, "state" ) != PLAYING_S )
723 action = menu->addAction( qtr( "Play" ),
724 ActionsManager::getInstance( p_intf ), SLOT( play() ) );
725 action->setIcon( QIcon( ":/play" ) );
729 addMIMStaticEntry( p_intf, menu, qtr( "Pause" ),
730 ":/pause", SLOT( togglePlayPause() ) );
734 void QVLCMenu::PopupMenuControlEntries( QMenu *menu, intf_thread_t *p_intf )
739 action = menu->addAction( qtr( "&Faster" ), THEMIM->getIM(),
741 action->setIcon( QIcon( ":/faster") );
742 action->setData( true );
744 action = menu->addAction( qtr( "N&ormal Speed" ), THEMIM->getIM(),
745 SLOT( normalRate() ) );
746 action->setData( true );
748 action = menu->addAction( qtr( "Slo&wer" ), THEMIM->getIM(),
750 action->setIcon( QIcon( ":/slower") );
751 action->setData( true );
753 menu->addSeparator();
755 action = menu->addAction( qtr( "&Jump Forward" ), THEMIM->getIM(),
757 action->setIcon( QIcon( ":/skip_fw") );
758 action->setData( true );
760 action = menu->addAction( qtr( "Jump Bac&kward" ), THEMIM->getIM(),
762 action->setIcon( QIcon( ":/skip_back") );
763 action->setData( true );
764 addDPStaticEntry( menu, qtr( I_MENU_GOTOTIME ),"",
765 SLOT( gotoTimeDialog() ), "Ctrl+T" );
766 menu->addSeparator();
770 void QVLCMenu::PopupMenuPlaylistControlEntries( QMenu *menu,
771 intf_thread_t *p_intf )
773 addMIMStaticEntry( p_intf, menu, qtr( "&Stop" ), ":/stop", SLOT( stop() ) );
775 /* Next / Previous */
776 addMIMStaticEntry( p_intf, menu, qtr( "Pre&vious" ),
777 ":/previous", SLOT( prev() ) );
778 addMIMStaticEntry( p_intf, menu, qtr( "Ne&xt" ),
779 ":/next", SLOT( next() ) );
780 menu->addSeparator();
783 void QVLCMenu::PopupMenuStaticEntries( QMenu *menu )
785 QMenu *openmenu = new QMenu( qtr( "Open Media" ), menu );
786 addDPStaticEntry( openmenu, qtr( "&Open File..." ),
787 ":/file-asym", SLOT( openFileDialog() ) );
788 addDPStaticEntry( openmenu, qtr( I_OPEN_FOLDER ),
789 ":/folder-grey", SLOT( PLOpenDir() ) );
790 addDPStaticEntry( openmenu, qtr( "Open &Disc..." ),
791 ":/disc", SLOT( openDiscDialog() ) );
792 addDPStaticEntry( openmenu, qtr( "Open &Network..." ),
793 ":/network", SLOT( openNetDialog() ) );
794 addDPStaticEntry( openmenu, qtr( "Open &Capture Device..." ),
795 ":/capture-card", SLOT( openCaptureDialog() ) );
796 menu->addMenu( openmenu );
798 menu->addSeparator();
800 QMenu *helpmenu = HelpMenu( menu );
801 helpmenu->setTitle( qtr( "Help" ) );
802 menu->addMenu( helpmenu );
805 addDPStaticEntry( menu, qtr( "Quit" ), ":/quit",
806 SLOT( quit() ), "Ctrl+Q" );
809 /* Video Tracks and Subtitles tracks */
810 void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf )
815 vlc_object_hold( p_input );
816 vout_thread_t *p_vout = THEMIM->getVout();
819 VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
820 vlc_object_release( p_vout );
822 vlc_object_release( p_input );
824 QMenu *menu = new QMenu();
829 void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf )
834 vlc_object_hold( p_input );
835 aout_instance_t *p_aout = THEMIM->getAout();
836 AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
838 vlc_object_release( p_aout );
839 vlc_object_release( p_input );
841 QMenu *menu = new QMenu();
845 /* Navigation stuff, and general menus ( open ), used only for skins */
846 void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf )
852 vlc_object_hold( p_input );
853 varnames.push_back( "audio-es" );
854 InputAutoMenuBuilder( p_input, objects, varnames );
858 QMenu *menu = new QMenu();
859 Populate( p_intf, menu, varnames, objects );
861 menu->addSeparator();
862 PopupPlayEntries( menu, p_intf, p_input );
863 PopupMenuPlaylistControlEntries( menu, p_intf);
865 menu->addSeparator();
866 PopupMenuControlEntries( menu, p_intf );
868 menu->addSeparator();
869 PopupMenuStaticEntries( menu );
871 p_intf->p_sys->p_popup_menu = menu;
872 menu->popup( QCursor::pos() );
873 p_intf->p_sys->p_popup_menu = NULL;
876 /* Main Menu that sticks everything together */
877 void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show )
879 /* Destroy popup menu if there is one */
882 delete p_intf->p_sys->p_popup_menu;
883 p_intf->p_sys->p_popup_menu = NULL;
887 /* Delete and recreate a popup if there is one */
888 if( p_intf->p_sys->p_popup_menu )
889 delete p_intf->p_sys->p_popup_menu;
892 QMenu *menu = new QMenu();
895 bool b_isFullscreen = false;
896 MainInterface *mi = p_intf->p_sys->p_mi;
900 PopupPlayEntries( menu, p_intf, p_input );
901 PopupMenuPlaylistControlEntries( menu, p_intf );
902 menu->addSeparator();
906 vout_thread_t *p_vout = THEMIM->getVout();
908 /* Add a fullscreen switch button, since it is the most used function */
911 vlc_value_t val; var_Get( p_vout, "fullscreen", &val );
913 b_isFullscreen = !( !val.b_bool );
915 CreateAndConnect( menu, "fullscreen",
916 qtr( "Leave Fullscreen" ),"" , ITEM_NORMAL,
917 VLC_OBJECT(p_vout), val, VLC_VAR_BOOL, b_isFullscreen );
918 vlc_object_release( p_vout );
920 menu->addSeparator();
924 vlc_object_hold( p_input );
925 InputAutoMenuBuilder( p_input, objects, varnames );
926 vlc_object_release( p_input );
929 submenu = new QMenu( menu );
930 action = menu->addMenu( AudioMenu( p_intf, submenu ) );
931 action->setText( qtr( "&Audio" ) );
932 if( action->menu()->isEmpty() )
933 action->setEnabled( false );
936 submenu = new QMenu( menu );
937 action = menu->addMenu( VideoMenu( p_intf, submenu ) );
938 action->setText( qtr( "&Video" ) );
939 if( action->menu()->isEmpty() )
940 action->setEnabled( false );
942 /* Playback menu for chapters */
943 submenu = new QMenu( menu );
944 action = menu->addMenu( NavigMenu( p_intf, submenu ) );
945 action->setText( qtr( "&Playback" ) );
946 if( action->menu()->isEmpty() )
947 action->setEnabled( false );
950 menu->addSeparator();
952 /* Add some special entries for windowed mode: Interface Menu */
953 if( !b_isFullscreen )
955 submenu = new QMenu( qtr( "Interface" ), menu );
956 QMenu *tools = ToolsMenu( submenu );
957 submenu->addSeparator();
959 /* In skins interface, append some items */
962 objects.clear(); varnames.clear();
964 vlc_object_t *p_object = ( vlc_object_t* )
965 vlc_object_find_name( p_intf, "skins2", FIND_PARENT );
968 objects.push_back( p_object );
969 varnames.push_back( "intf-skins" );
970 Populate( p_intf, submenu, varnames, objects );
971 vlc_object_release( p_object );
974 msg_Warn( p_intf, "could not find parent interface" );
977 menu->addMenu( ViewMenu( p_intf, mi, false ));
979 menu->addMenu( submenu );
982 /* Static entries for ending, like open */
983 PopupMenuStaticEntries( menu );
985 p_intf->p_sys->p_popup_menu = menu;
986 p_intf->p_sys->p_popup_menu->popup( QCursor::pos() );
993 /************************************************************************
995 ************************************************************************/
997 void QVLCMenu::updateSystrayMenu( MainInterface *mi,
998 intf_thread_t *p_intf,
999 bool b_force_visible )
1003 /* Get the systray menu and clean it */
1004 QMenu *sysMenu = mi->getSysTrayMenu();
1007 /* Hide / Show VLC and cone */
1008 if( mi->isVisible() || b_force_visible )
1010 sysMenu->addAction( QIcon( ":/vlc16.png" ),
1011 qtr( "Hide VLC media player in taskbar" ), mi,
1012 SLOT( toggleUpdateSystrayMenu() ) );
1016 sysMenu->addAction( QIcon( ":/vlc16.png" ),
1017 qtr( "Show VLC media player" ), mi,
1018 SLOT( toggleUpdateSystrayMenu() ) );
1021 sysMenu->addSeparator();
1022 PopupPlayEntries( sysMenu, p_intf, p_input );
1023 PopupMenuPlaylistControlEntries( sysMenu, p_intf);
1024 PopupMenuControlEntries( sysMenu, p_intf);
1026 sysMenu->addSeparator();
1027 addDPStaticEntry( sysMenu, qtr( "&Open Media" ),
1028 ":/file-wide", SLOT( openFileDialog() ) );
1029 addDPStaticEntry( sysMenu, qtr( "&Quit" ) ,
1030 ":/quit", SLOT( quit() ) );
1033 mi->getSysTray()->setContextMenu( sysMenu );
1037 #undef PUSH_SEPARATOR
1039 /*************************************************************************
1040 * Builders for automenus
1041 *************************************************************************/
1042 QMenu * QVLCMenu::Populate( intf_thread_t *p_intf,
1044 vector< const char *> & varnames,
1045 vector<vlc_object_t *> & objects )
1047 QMenu *menu = current;
1050 currentGroup = NULL;
1052 vlc_object_t *p_object;
1054 for( int i = 0; i < ( int )objects.size() ; i++ )
1056 if( !varnames[i] || !*varnames[i] )
1058 menu->addSeparator();
1061 p_object = objects[i];
1063 UpdateItem( p_intf, menu, varnames[i], p_object, true );
1068 /*****************************************************************************
1070 *****************************************************************************/
1072 static bool IsMenuEmpty( const char *psz_var,
1073 vlc_object_t *p_object,
1074 bool b_root = true )
1076 vlc_value_t val, val_list;
1077 int i_type, i_result, i;
1079 /* Check the type of the object variable */
1080 i_type = var_Type( p_object, psz_var );
1082 /* Check if we want to display the variable */
1083 if( !( i_type & VLC_VAR_HASCHOICE ) ) return false;
1085 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
1086 if( val.i_int == 0 ) return true;
1088 if( ( i_type & VLC_VAR_TYPE ) != VLC_VAR_VARIABLE )
1090 if( val.i_int == 1 && b_root ) return true;
1094 /* Check children variables in case of VLC_VAR_VARIABLE */
1095 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
1100 for( i = 0, i_result = true; i < val_list.p_list->i_count; i++ )
1102 if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
1110 /* clean up everything */
1111 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, NULL );
1116 #define TEXT_OR_VAR qfu ( text.psz_string ? text.psz_string : psz_var )
1118 void QVLCMenu::UpdateItem( intf_thread_t *p_intf, QMenu *menu,
1119 const char *psz_var, vlc_object_t *p_object, bool b_submenu )
1121 vlc_value_t val, text;
1124 QAction *action = FindActionWithVar( menu, psz_var );
1126 DeleteNonStaticEntries( action->menu() );
1131 action->setEnabled( false );
1135 /* Check the type of the object variable */
1136 /* What is the following HACK needed for? */
1137 if( !strcmp( psz_var, "audio-es" )
1138 || !strcmp( psz_var, "video-es" ) )
1139 i_type = VLC_VAR_INTEGER | VLC_VAR_HASCHOICE;
1141 i_type = var_Type( p_object, psz_var );
1143 switch( i_type & VLC_VAR_TYPE )
1147 case VLC_VAR_VARIABLE:
1148 case VLC_VAR_STRING:
1149 case VLC_VAR_INTEGER:
1153 /* Variable doesn't exist or isn't handled */
1155 action->setEnabled( false );
1159 /* Make sure we want to display the variable */
1160 if( menu->isEmpty() && IsMenuEmpty( psz_var, p_object ) )
1163 action->setEnabled( false );
1167 /* Get the descriptive name of the variable */
1168 int i_ret = var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
1169 if( i_ret != VLC_SUCCESS )
1171 text.psz_string = NULL;
1176 action = new QAction( TEXT_OR_VAR, menu );
1177 menu->addAction( action );
1178 action->setData( psz_var );
1181 /* Some specific stuff */
1182 bool forceDisabled = false;
1183 if( !strcmp( psz_var, "spu-es" ) )
1185 vout_thread_t *p_vout = THEMIM->getVout();
1186 forceDisabled = ( p_vout == NULL );
1188 vlc_object_release( p_vout );
1191 if( i_type & VLC_VAR_HASCHOICE )
1193 /* Append choices menu */
1197 submenu = action->menu();
1200 submenu = new QMenu( menu );
1201 action->setMenu( submenu );
1205 CreateChoicesMenu( submenu, psz_var, p_object, true ) == 0 );
1207 action->setEnabled( false );
1212 CreateChoicesMenu( menu, psz_var, p_object, true ) == 0 );
1214 FREENULL( text.psz_string );
1218 switch( i_type & VLC_VAR_TYPE )
1221 var_Get( p_object, psz_var, &val );
1222 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_NORMAL,
1223 p_object, val, i_type );
1227 var_Get( p_object, psz_var, &val );
1228 val.b_bool = !val.b_bool;
1229 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_CHECK,
1230 p_object, val, i_type, !val.b_bool );
1233 FREENULL( text.psz_string );
1237 int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
1238 vlc_object_t *p_object, bool b_root )
1240 vlc_value_t val, val_list, text_list;
1243 /* Check the type of the object variable */
1244 i_type = var_Type( p_object, psz_var );
1246 /* Make sure we want to display the variable */
1247 if( submenu->isEmpty() && IsMenuEmpty( psz_var, p_object, b_root ) )
1248 return VLC_EGENERIC;
1250 switch( i_type & VLC_VAR_TYPE )
1254 case VLC_VAR_VARIABLE:
1255 case VLC_VAR_STRING:
1256 case VLC_VAR_INTEGER:
1260 /* Variable doesn't exist or isn't handled */
1261 return VLC_EGENERIC;
1264 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
1265 &val_list, &text_list ) < 0 )
1267 return VLC_EGENERIC;
1270 #define CURVAL val_list.p_list->p_values[i]
1271 #define CURTEXT text_list.p_list->p_values[i].psz_string
1273 for( i = 0; i < val_list.p_list->i_count; i++ )
1275 vlc_value_t another_val;
1277 QMenu *subsubmenu = new QMenu( submenu );
1279 switch( i_type & VLC_VAR_TYPE )
1281 case VLC_VAR_VARIABLE:
1282 CreateChoicesMenu( subsubmenu, CURVAL.psz_string, p_object, false );
1283 subsubmenu->setTitle( qfu( CURTEXT ? CURTEXT :CURVAL.psz_string ) );
1284 submenu->addMenu( subsubmenu );
1287 case VLC_VAR_STRING:
1288 var_Get( p_object, psz_var, &val );
1289 another_val.psz_string = strdup( CURVAL.psz_string );
1290 menutext = qfu( CURTEXT ? CURTEXT : another_val.psz_string );
1291 CreateAndConnect( submenu, psz_var, menutext, "", ITEM_RADIO,
1292 p_object, another_val, i_type,
1293 val.psz_string && !strcmp( val.psz_string, CURVAL.psz_string ) );
1295 free( val.psz_string );
1298 case VLC_VAR_INTEGER:
1299 var_Get( p_object, psz_var, &val );
1300 if( CURTEXT ) menutext = qfu( CURTEXT );
1301 else menutext.sprintf( "%d", CURVAL.i_int );
1302 CreateAndConnect( submenu, psz_var, menutext, "", ITEM_RADIO,
1303 p_object, CURVAL, i_type,
1304 CURVAL.i_int == val.i_int );
1308 var_Get( p_object, psz_var, &val );
1309 if( CURTEXT ) menutext = qfu( CURTEXT );
1310 else menutext.sprintf( "%.2f", CURVAL.f_float );
1311 CreateAndConnect( submenu, psz_var, menutext, "", ITEM_RADIO,
1312 p_object, CURVAL, i_type,
1313 CURVAL.f_float == val.f_float );
1320 currentGroup = NULL;
1322 /* clean up everything */
1323 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
1327 return submenu->isEmpty() ? VLC_EGENERIC : VLC_SUCCESS;
1330 void QVLCMenu::CreateAndConnect( QMenu *menu, const char *psz_var,
1331 QString text, QString help,
1332 int i_item_type, vlc_object_t *p_obj,
1333 vlc_value_t val, int i_val_type,
1336 QAction *action = FindActionWithVar( menu, psz_var );
1341 action = new QAction( text, menu );
1342 menu->addAction( action );
1346 action->setToolTip( help );
1347 action->setEnabled( p_obj != NULL );
1349 if( i_item_type == ITEM_CHECK )
1351 action->setCheckable( true );
1353 else if( i_item_type == ITEM_RADIO )
1355 action->setCheckable( true );
1357 currentGroup = new QActionGroup( menu );
1358 currentGroup->addAction( action );
1361 action->setChecked( checked );
1363 MenuItemData *itemData = new MenuItemData( THEDP->menusMapper, p_obj, i_val_type,
1365 CONNECT( action, triggered(), THEDP->menusMapper, map() );
1366 THEDP->menusMapper->setMapping( action, itemData );
1369 menu->addAction( action );
1372 void QVLCMenu::DoAction( QObject *data )
1374 MenuItemData *itemData = qobject_cast<MenuItemData *>( data );
1375 vlc_object_t *p_object = itemData->p_obj;
1376 if( p_object == NULL ) return;
1378 var_Set( p_object, itemData->psz_var, itemData->val );
1381 void QVLCMenu::updateRecents( intf_thread_t *p_intf )
1386 RecentsMRL* rmrl = RecentsMRL::getInstance( p_intf );
1387 QList<QString> l = rmrl->recents();
1389 recentsMenu->clear();
1392 action = recentsMenu->addAction( qtr(" - Empty - ") );
1393 action->setEnabled( false );
1397 for( int i = 0; i < l.size(); ++i )
1399 action = recentsMenu->addAction(
1400 QString( "&%1: " ).arg( i + 1 ) + l.at( i ),
1403 rmrl->signalMapper->setMapping( action, l.at( i ) );
1406 recentsMenu->addSeparator();
1407 recentsMenu->addAction( qtr("&Clear"), rmrl, SLOT( clear() ) );