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,
122 if( strlen( icon ) > 0 )
124 QAction *action = menu->addAction( text, THEMIM, member );
125 action->setIcon( QIcon( icon ) );
129 menu->addAction( text, THEMIM, member );
134 * @brief Enable all static entries, disable the others
135 * @param enable if false, disable all entries
137 void EnableStaticEntries( QMenu *menu, bool enable = true )
141 QList< QAction* > actions = menu->actions();
142 for( int i = 0; i < actions.size(); ++i )
144 actions[i]->setEnabled( enable && actions[i]->data().toBool() );
149 * \return Number of static entries
151 int DeleteNonStaticEntries( QMenu *menu )
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" );
203 PUSH_VAR( "dvd_menus" );
207 static int VideoAutoMenuBuilder( vout_thread_t *p_object,
208 input_thread_t *p_input,
209 vector<vlc_object_t *> &objects,
210 vector<const char *> &varnames )
212 PUSH_INPUTVAR( "video-es" );
213 PUSH_INPUTVAR( "spu-es" );
214 PUSH_VAR( "fullscreen" );
215 PUSH_VAR( "video-on-top" );
217 PUSH_VAR( "directx-wallpaper" );
219 PUSH_VAR( "video-snapshot" );
221 PUSH_VAR( "autoscale" );
222 PUSH_VAR( "aspect-ratio" );
224 PUSH_VAR( "deinterlace" );
225 PUSH_VAR( "postprocess" );
230 static int AudioAutoMenuBuilder( aout_instance_t *p_object,
231 input_thread_t *p_input,
232 vector<vlc_object_t *> &objects,
233 vector<const char *> &varnames )
235 PUSH_INPUTVAR( "audio-es" );
236 PUSH_VAR( "audio-channels" );
237 PUSH_VAR( "audio-device" );
238 PUSH_VAR( "visual" );
242 /*****************************************************************************
245 *****************************************************************************/
247 #define BAR_ADD( func, title ) { \
248 QMenu *_menu = func; _menu->setTitle( title ); bar->addMenu( _menu ); }
250 #define BAR_DADD( func, title, id ) { \
251 QMenu *_menu = func; _menu->setTitle( title ); bar->addMenu( _menu ); \
252 MenuFunc *f = new MenuFunc( _menu, id ); \
253 CONNECT( _menu, aboutToShow(), THEDP->menusUpdateMapper, map() ); \
254 THEDP->menusUpdateMapper->setMapping( _menu, f ); }
256 #define ACT_ADD( _menu, val, title ) { \
257 QAction *_action = new QAction( title, _menu ); _action->setData( val ); \
258 _menu->addAction( _action ); }
260 #define ACT_ADDMENU( _menu, val, title ) { \
261 QAction *_action = new QAction( title, _menu ); _action->setData( val ); \
262 _action->setMenu( new QMenu() ); _menu->addAction( _action ); }
264 #define ACT_ADDCHECK( _menu, val, title ) { \
265 QAction *_action = new QAction( title, _menu ); _action->setData( val ); \
266 _action->setCheckable( true ); _menu->addAction( _action ); }
269 * Main Menu Bar Creation
271 void QVLCMenu::createMenuBar( MainInterface *mi,
272 intf_thread_t *p_intf,
273 bool visual_selector_enabled )
274 /* FIXME remove this visual dependency */
276 /* QMainWindows->menuBar()
277 gives the QProcess::destroyed timeout issue on Cleanlooks style with
278 setDesktopAware set to false */
279 QMenuBar *bar = mi->menuBar();
280 BAR_ADD( FileMenu( p_intf, bar ), qtr( "&Media" ) );
282 BAR_DADD( NavigMenu( p_intf, bar ), qtr( "P&layback" ), 3 );
283 BAR_DADD( AudioMenu( p_intf, bar ), qtr( "&Audio" ), 1 );
284 BAR_DADD( VideoMenu( p_intf, bar ), qtr( "&Video" ), 2 );
286 BAR_ADD( ToolsMenu( bar ), qtr( "&Tools" ) );
287 BAR_ADD( ViewMenu( p_intf, NULL, mi, visual_selector_enabled, true ),
290 BAR_ADD( HelpMenu( bar ), qtr( "&Help" ) );
296 * Media ( File ) Menu
297 * Opening, streaming and quit
299 QMenu *QVLCMenu::FileMenu( intf_thread_t *p_intf, QWidget *parent )
301 QMenu *menu = new QMenu( parent );
303 addDPStaticEntry( menu, qtr( "&Open File..." ),
304 ":/file-asym", SLOT( simpleOpenDialog() ), "Ctrl+O" );
305 addDPStaticEntry( menu, qtr( "Advanced Open File..." ),
306 ":/file-asym", SLOT( openFileDialog() ), "Ctrl+Shift+O" );
307 addDPStaticEntry( menu, qtr( I_OPEN_FOLDER ),
308 ":/folder-grey", SLOT( PLOpenDir() ), "Ctrl+F" );
309 addDPStaticEntry( menu, qtr( "Open &Disc..." ),
310 ":/disc", SLOT( openDiscDialog() ), "Ctrl+D" );
311 addDPStaticEntry( menu, qtr( "Open &Network..." ),
312 ":/network", SLOT( openNetDialog() ), "Ctrl+N" );
313 addDPStaticEntry( menu, qtr( "Open &Capture Device..." ),
314 ":/capture-card", SLOT( openCaptureDialog() ),
317 menu->addSeparator();
318 addDPStaticEntry( menu, qtr( "Paste &MRL" ),
319 NULL, SLOT( openUrlDialog() ), "Ctrl+V" );
321 recentsMenu = new QMenu( qtr( "&Recent Media" ), menu );
322 updateRecents( p_intf );
323 menu->addMenu( recentsMenu );
324 menu->addSeparator();
325 menu->addMenu( SDMenu( p_intf, menu ) );
326 menu->addSeparator();
328 addDPStaticEntry( menu, qtr( I_PL_SAVE ), "", SLOT( saveAPlaylist() ),
330 menu->addSeparator();
332 addDPStaticEntry( menu, qtr( "Conve&rt / Save..." ), "",
333 SLOT( openAndTranscodingDialogs() ), "Ctrl+R" );
334 addDPStaticEntry( menu, qtr( "&Streaming..." ),
335 ":/stream", SLOT( openAndStreamingDialogs() ),
337 menu->addSeparator();
339 addDPStaticEntry( menu, qtr( "&Quit" ) ,
340 ":/quit", SLOT( quit() ), "Ctrl+Q" );
344 /* Playlist/MediaLibrary Control */
345 QMenu *QVLCMenu::ToolsMenu( QMenu *menu )
347 addDPStaticEntry( menu, qtr( I_MENU_EXT ), ":/settings",
348 SLOT( extendedDialog() ), "Ctrl+E" );
350 addDPStaticEntry( menu, qtr( I_MENU_INFO ) , ":/info",
351 SLOT( mediaInfoDialog() ), "Ctrl+I" );
352 addDPStaticEntry( menu, qtr( I_MENU_CODECINFO ) ,
353 ":/info", SLOT( mediaCodecDialog() ), "Ctrl+J" );
355 addDPStaticEntry( menu, qtr( I_MENU_BOOKMARK ),"",
356 SLOT( bookmarksDialog() ), "Ctrl+B" );
358 addDPStaticEntry( menu, qtr( I_MENU_VLM ), "", SLOT( vlmDialog() ),
362 addDPStaticEntry( menu, qtr( I_MENU_MSG ),
363 ":/messages", SLOT( messagesDialog() ),
366 addDPStaticEntry( menu, qtr( "Plu&gins and extensions" ),
367 "", SLOT( pluginDialog() ) );
368 menu->addSeparator();
370 addDPStaticEntry( menu, qtr( "&Preferences" ),
371 ":/preferences", SLOT( prefsDialog() ), "Ctrl+P" );
376 QMenu *QVLCMenu::ToolsMenu( QWidget *parent )
378 return ToolsMenu( new QMenu( parent ) );
383 * This menu can be an interface menu but also a right click menu.
385 QMenu *QVLCMenu::ViewMenu( intf_thread_t *p_intf,
388 bool visual_selector_enabled,
393 menu = new QMenu( current );
395 menu = new QMenu( mi );
399 act = menu->addAction( QIcon( ":/playlist_menu" ),
400 qtr( "Play&list" ), mi,
401 SLOT( togglePlaylist() ), qtr( "Ctrl+L" ) );
402 act->setData( true );
404 /*menu->addSeparator();
405 menu->addAction( qtr( "Undock from Interface" ), mi,
406 SLOT( undockPlaylist() ), qtr( "Ctrl+U" ) );*/
409 menu->addSeparator();
413 QMenu *intfmenu = InterfacesMenu( p_intf, menu );
414 MenuFunc *f = new MenuFunc( intfmenu, 4 );
415 CONNECT( intfmenu, aboutToShow(), THEDP->menusUpdateMapper, map() );
416 THEDP->menusUpdateMapper->setMapping( intfmenu, f );
417 menu->addSeparator();
422 QAction *action = menu->addAction( qtr( "Mi&nimal View" ), mi,
423 SLOT( toggleMinimalView() ), qtr( "Ctrl+H" ) );
424 action->setCheckable( true );
425 action->setData( true );
426 if( mi->getControlsVisibilityStatus() & CONTROLS_VISIBLE )
427 action->setChecked( true );
428 minimalViewAction = action; /* HACK for minimalView */
430 /* FullScreen View */
431 action = menu->addAction( qtr( "&Fullscreen Interface" ), mi,
432 SLOT( toggleFullScreen() ), QString( "F11" ) );
433 fullscreenViewAction = action;
434 action->setCheckable( true );
435 action->setData( true );
437 /* Advanced Controls */
438 action = menu->addAction( qtr( "&Advanced Controls" ), mi,
439 SLOT( toggleAdvanced() ) );
440 action->setCheckable( true );
441 action->setData( true );
442 if( mi->getControlsVisibilityStatus() & CONTROLS_ADVANCED )
443 action->setChecked( true );
444 #if 0 /* For Visualisations. Not yet working */
445 adv = menu->addAction( qtr( "Visualizations selector" ),
446 mi, SLOT( visual() ) );
447 adv->setCheckable( true );
448 if( visual_selector_enabled ) adv->setChecked( true );
452 menu->addSeparator();
453 addDPStaticEntry( menu, qtr( "Customi&ze Interface..." ),
454 ":/preferences", SLOT( toolbarDialog() ) );
455 menu->addSeparator();
461 * Interface Sub-Menu, to list extras interface and skins
463 QMenu *QVLCMenu::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
465 vector<vlc_object_t *> objects;
466 vector<const char *> varnames;
467 /** \todo add "switch to XXX" */
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();
507 vlc_object_hold( p_input );
508 p_aout = THEMIM->getAout();
509 AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
510 EnableStaticEntries( current, ( p_aout != NULL ) );
513 vlc_object_release( p_aout );
516 vlc_object_release( p_input );
518 return Populate( p_intf, current, varnames, objects );
521 QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QWidget *parent )
523 return AudioMenu( p_intf, new QMenu( parent ) );
528 * Subtitles are part of Video.
530 QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current )
532 vout_thread_t *p_vout;
533 input_thread_t *p_input;
534 vector<vlc_object_t *> objects;
535 vector<const char *> varnames;
537 if( current->isEmpty() )
539 ACT_ADDMENU( current, "video-es", qtr( "Video &Track" ) );
542 QMenu *submenu = new QMenu( qtr( "&Subtitles Track" ), current );
543 action = current->addMenu( submenu );
544 action->setData( "spu-es" );
545 addDPStaticEntry( submenu, qtr( "Open File..." ), "",
546 SLOT( loadSubtitlesFile() ) );
547 submenu->addSeparator();
548 current->addSeparator();
550 ACT_ADDCHECK( current, "fullscreen", qtr( "&Fullscreen" ) );
551 ACT_ADDCHECK( current, "video-on-top", qtr( "Always &On Top" ) );
553 ACT_ADDCHECK( current, "directx-wallpaper", qtr( "DirectX Wallpaper" ) );
555 ACT_ADD( current, "video-snapshot", qtr( "Sna&pshot" ) );
557 current->addSeparator();
559 ACT_ADDMENU( current, "zoom", qtr( "&Zoom" ) );
560 ACT_ADDCHECK( current, "autoscale", qtr( "Sca&le" ) );
561 ACT_ADDMENU( current, "aspect-ratio", qtr( "&Aspect Ratio" ) );
562 ACT_ADDMENU( current, "crop", qtr( "&Crop" ) );
563 ACT_ADDMENU( current, "deinterlace", qtr( "&Deinterlace" ) );
564 ACT_ADDMENU( current, "postprocess", qtr( "&Post processing" ) );
567 p_input = THEMIM->getInput();
569 vlc_object_hold( p_input );
571 p_vout = THEMIM->getVout();
572 VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
573 EnableStaticEntries( current, ( p_vout != NULL ) );
576 vlc_object_release( p_vout );
579 vlc_object_release( p_input );
581 return Populate( p_intf, current, varnames, objects );
584 QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QWidget *parent )
586 return VideoMenu( p_intf, new QMenu( parent ) );
591 * For DVD, MP4, MOV and other chapter based format
593 QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *menu )
595 if( menu->isEmpty() )
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" );
604 ACT_ADDMENU( menu, "title", qtr( "T&itle" ) );
605 ACT_ADDMENU( menu, "chapter", qtr( "&Chapter" ) );
606 ACT_ADDMENU( menu, "navigation", qtr( "&Navigation" ) );
607 ACT_ADDMENU( menu, "program", qtr( "&Program" ) );
609 menu->addSeparator();
610 addDPStaticEntry( menu, qtr( I_MENU_GOTOTIME ),"",
611 SLOT( gotoTimeDialog() ), "Ctrl+T" );
615 input_thread_t *p_object;
616 vector<vlc_object_t *> objects;
617 vector<const char *> varnames;
619 p_object = THEMIM->getInput();
621 vlc_object_hold( p_object );
622 InputAutoMenuBuilder( p_object, objects, varnames );
623 PUSH_VAR( "prev-title" );
624 PUSH_VAR( "next-title" );
625 PUSH_VAR( "prev-chapter" );
626 PUSH_VAR( "next-chapter" );
627 EnableStaticEntries( menu, ( p_object != NULL ) );
630 vlc_object_release( p_object );
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 ) );
647 char **ppsz_longnames;
648 char **ppsz_names = vlc_sd_GetNames( &ppsz_longnames );
652 char **ppsz_name = ppsz_names, **ppsz_longname = ppsz_longnames;
653 for( ; *ppsz_name; ppsz_name++, ppsz_longname++ )
655 QAction *a = new QAction( qfu( *ppsz_longname ), menu );
656 a->setCheckable( true );
657 if( playlist_IsServicesDiscoveryLoaded( THEPL, *ppsz_name ) )
658 a->setChecked( true );
659 CONNECT( a , triggered(), THEDP->SDMapper, map() );
660 THEDP->SDMapper->setMapping( a, QString( *ppsz_name ) );
661 menu->addAction( a );
663 if( !strcmp( *ppsz_name, "podcast" ) )
665 QAction *b = new QAction( qtr( "Configure podcasts..." ), menu );
666 //b->setEnabled( a->isChecked() );
667 menu->addAction( b );
668 CONNECT( b, triggered(), THEDP, podcastConfigureDialog() );
671 free( *ppsz_longname );
674 free( ppsz_longnames );
681 QMenu *QVLCMenu::HelpMenu( QWidget *parent )
683 QMenu *menu = new QMenu( parent );
684 addDPStaticEntry( menu, qtr( "&Help..." ) ,
685 ":/help", SLOT( helpDialog() ), "F1" );
687 addDPStaticEntry( menu, qtr( "Check for &Updates..." ) , "",
688 SLOT( updateDialog() ) );
690 menu->addSeparator();
691 addDPStaticEntry( menu, qtr( I_MENU_ABOUT ), ":/info",
692 SLOT( aboutDialog() ), "Shift+F1" );
696 /*****************************************************************************
697 * Popup menus - Right Click menus *
698 *****************************************************************************/
699 #define POPUP_BOILERPLATE \
700 unsigned int i_last_separator = 0; \
701 vector<vlc_object_t *> objects; \
702 vector<const char *> varnames; \
703 input_thread_t *p_input = THEMIM->getInput();
705 #define CREATE_POPUP \
706 Populate( p_intf, menu, varnames, objects ); \
707 p_intf->p_sys->p_popup_menu = menu; \
708 menu->popup( QCursor::pos() ); \
709 p_intf->p_sys->p_popup_menu = NULL; \
710 i_last_separator = 0;
712 void QVLCMenu::PopupMenuControlEntries( QMenu *menu,
713 intf_thread_t *p_intf,
714 input_thread_t *p_input )
719 var_Get( p_input, "state", &val );
720 if( val.i_int == PLAYING_S )
721 addMIMStaticEntry( p_intf, menu, qtr( "Pause" ),
722 ":/pause", SLOT( togglePlayPause() ) );
724 addMIMStaticEntry( p_intf, menu, qtr( "Play" ),
725 ":/play", SLOT( togglePlayPause() ) );
727 else if( THEPL->items.i_size )
728 addMIMStaticEntry( p_intf, menu, qtr( "Play" ),
729 ":/play", SLOT( togglePlayPause() ) );
731 addDPStaticEntry( menu, qtr( "Play" ),
732 ":/play", SLOT( openDialog() ) );
734 addMIMStaticEntry( p_intf, menu, qtr( "Stop" ),
735 ":/stop", SLOT( stop() ) );
736 addMIMStaticEntry( p_intf, menu, qtr( "Previous" ),
737 ":/previous", SLOT( prev() ) );
738 addMIMStaticEntry( p_intf, menu, qtr( "Next" ),
739 ":/next", SLOT( next() ) );
742 void QVLCMenu::PopupMenuStaticEntries( QMenu *menu )
744 QMenu *openmenu = new QMenu( qtr( "Open Media" ), menu );
745 addDPStaticEntry( openmenu, qtr( "&Open File..." ),
746 ":/file-asym", SLOT( openFileDialog() ) );
747 addDPStaticEntry( openmenu, qtr( I_OPEN_FOLDER ),
748 ":/folder-grey", SLOT( PLOpenDir() ) );
749 addDPStaticEntry( openmenu, qtr( "Open &Disc..." ),
750 ":/disc", SLOT( openDiscDialog() ) );
751 addDPStaticEntry( openmenu, qtr( "Open &Network..." ),
752 ":/network", SLOT( openNetDialog() ) );
753 addDPStaticEntry( openmenu, qtr( "Open &Capture Device..." ),
754 ":/capture-card", SLOT( openCaptureDialog() ) );
755 menu->addMenu( openmenu );
757 menu->addSeparator();
759 QMenu *helpmenu = HelpMenu( menu );
760 helpmenu->setTitle( qtr( "Help" ) );
761 menu->addMenu( helpmenu );
764 addDPStaticEntry( menu, qtr( "Quit" ), ":/quit",
765 SLOT( quit() ), "Ctrl+Q" );
768 /* Video Tracks and Subtitles tracks */
769 void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf )
774 vlc_object_hold( p_input );
775 vout_thread_t *p_vout = THEMIM->getVout();
778 VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
779 vlc_object_release( p_vout );
781 vlc_object_release( p_input );
783 QMenu *menu = new QMenu();
788 void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf )
793 vlc_object_hold( p_input );
794 aout_instance_t *p_aout = THEMIM->getAout();
795 AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
797 vlc_object_release( p_aout );
798 vlc_object_release( p_input );
800 QMenu *menu = new QMenu();
804 /* Navigation stuff, and general menus ( open ) */
805 void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf )
811 vlc_object_hold( p_input );
812 varnames.push_back( "audio-es" );
813 InputAutoMenuBuilder( p_input, objects, varnames );
817 QMenu *menu = new QMenu();
818 Populate( p_intf, menu, varnames, objects );
820 menu->addSeparator();
821 PopupMenuControlEntries( menu, p_intf, p_input );
823 menu->addSeparator();
824 PopupMenuStaticEntries( menu );
826 p_intf->p_sys->p_popup_menu = menu;
827 menu->popup( QCursor::pos() );
828 p_intf->p_sys->p_popup_menu = NULL;
831 /* Main Menu that sticks everything together */
832 void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show )
834 MainInterface *mi = p_intf->p_sys->p_mi;
837 /* Delete and recreate a popup if there is one */
838 if( p_intf->p_sys->p_popup_menu )
839 delete p_intf->p_sys->p_popup_menu;
841 QMenu *menu = new QMenu();
844 bool b_isFullscreen = false;
848 PopupMenuControlEntries( menu, p_intf, p_input );
849 menu->addSeparator();
853 vout_thread_t *p_vout = THEMIM->getVout();
855 /* Add a fullscreen switch button */
859 var_Get( p_vout, "fullscreen", &val );
860 b_isFullscreen = !( !val.b_bool );
862 CreateAndConnect( menu, "fullscreen",
863 qtr( "Leave Fullscreen" ),"" , ITEM_NORMAL,
864 VLC_OBJECT(p_vout), val, VLC_VAR_BOOL,
866 vlc_object_release( p_vout );
869 menu->addSeparator();
872 vlc_object_hold( p_input );
873 InputAutoMenuBuilder( p_input, objects, varnames );
874 vlc_object_release( p_input );
877 submenu = new QMenu( menu );
878 action = menu->addMenu( AudioMenu( p_intf, submenu ) );
879 action->setText( qtr( "&Audio" ) );
880 if( action->menu()->isEmpty() )
881 action->setEnabled( false );
884 submenu = new QMenu( menu );
885 action = menu->addMenu( VideoMenu( p_intf, submenu ) );
886 action->setText( qtr( "&Video" ) );
887 if( action->menu()->isEmpty() )
888 action->setEnabled( false );
890 /* Playback menu for chapters */
891 submenu = new QMenu( menu );
892 action = menu->addMenu( NavigMenu( p_intf, submenu ) );
893 action->setText( qtr( "&Playback" ) );
894 if( action->menu()->isEmpty() )
895 action->setEnabled( false );
898 menu->addSeparator();
900 /* Add some special entries for windowed mode: Interface Menu */
901 if( !b_isFullscreen )
903 submenu = new QMenu( qtr( "Interface" ), menu );
906 submenu->addAction( QIcon( ":/playlist" ),
907 qtr( "Show Playlist" ), mi, SLOT( togglePlaylist() ) );
908 action = submenu->addAction( QIcon( "" ),
909 qtr( "Minimal View" ), mi, SLOT( toggleMinimalView() ) );
910 action->setCheckable( true );
911 action->setChecked( !( mi->getControlsVisibilityStatus() &
912 CONTROLS_VISIBLE ) );
913 action = submenu->addAction( QIcon( "" ),
914 qtr( "Fullscreen Interface" ),
915 mi, SLOT( toggleFullScreen() ) );
916 action->setCheckable( true );
917 action->setChecked( mi->isFullScreen() );
919 else /* We are using the skins interface.
920 If not, this entry will not show. */
923 QMenu *tools = ToolsMenu( submenu );
924 submenu->addSeparator();
927 vlc_object_t *p_object = ( vlc_object_t* )
928 vlc_object_find_name( p_intf, "skins2", FIND_PARENT );
931 objects.push_back( p_object );
932 varnames.push_back( "intf-skins" );
933 Populate( p_intf, submenu, varnames, objects );
934 vlc_object_release( p_object );
937 msg_Dbg( p_intf, "could not find parent interface" );
939 menu->addMenu( submenu );
942 /* Static entries for ending, like open */
943 PopupMenuStaticEntries( menu );
945 p_intf->p_sys->p_popup_menu = menu;
946 p_intf->p_sys->p_popup_menu->popup( QCursor::pos() );
950 // destroy popup if there is one
951 delete p_intf->p_sys->p_popup_menu;
952 p_intf->p_sys->p_popup_menu = NULL;
960 /************************************************************************
962 ************************************************************************/
964 void QVLCMenu::updateSystrayMenu( MainInterface *mi,
965 intf_thread_t *p_intf,
966 bool b_force_visible )
970 /* Get the systray menu and clean it */
971 QMenu *sysMenu = mi->getSysTrayMenu();
974 /* Hide / Show VLC and cone */
975 if( mi->isVisible() || b_force_visible )
977 sysMenu->addAction( QIcon( ":/vlc16.png" ),
978 qtr( "Hide VLC media player in taskbar" ), mi,
979 SLOT( toggleUpdateSystrayMenu() ) );
983 sysMenu->addAction( QIcon( ":/vlc16.png" ),
984 qtr( "Show VLC media player" ), mi,
985 SLOT( toggleUpdateSystrayMenu() ) );
988 sysMenu->addSeparator();
989 PopupMenuControlEntries( sysMenu, p_intf, p_input );
991 sysMenu->addSeparator();
992 addDPStaticEntry( sysMenu, qtr( "&Open Media" ),
993 ":/file-wide", SLOT( openFileDialog() ) );
994 addDPStaticEntry( sysMenu, qtr( "&Quit" ) ,
995 ":/quit", SLOT( quit() ) );
998 mi->getSysTray()->setContextMenu( sysMenu );
1002 #undef PUSH_SEPARATOR
1004 /*************************************************************************
1005 * Builders for automenus
1006 *************************************************************************/
1007 QMenu * QVLCMenu::Populate( intf_thread_t *p_intf,
1009 vector< const char *> & varnames,
1010 vector<vlc_object_t *> & objects )
1012 QMenu *menu = current;
1015 msg_Warn( p_intf, "%s leaking a menu", __func__ );
1019 currentGroup = NULL;
1021 vlc_object_t *p_object;
1023 for( int i = 0; i < ( int )objects.size() ; i++ )
1025 if( !varnames[i] || !*varnames[i] )
1027 menu->addSeparator();
1030 p_object = objects[i];
1032 UpdateItem( p_intf, menu, varnames[i], p_object, true );
1037 /*****************************************************************************
1039 *****************************************************************************/
1041 static bool IsMenuEmpty( const char *psz_var,
1042 vlc_object_t *p_object,
1043 bool b_root = true )
1045 vlc_value_t val, val_list;
1046 int i_type, i_result, i;
1048 /* Check the type of the object variable */
1049 i_type = var_Type( p_object, psz_var );
1051 /* Check if we want to display the variable */
1052 if( !( i_type & VLC_VAR_HASCHOICE ) ) return false;
1054 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
1055 if( val.i_int == 0 ) return true;
1057 if( ( i_type & VLC_VAR_TYPE ) != VLC_VAR_VARIABLE )
1059 if( val.i_int == 1 && b_root ) return true;
1063 /* Check children variables in case of VLC_VAR_VARIABLE */
1064 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
1069 for( i = 0, i_result = true; i < val_list.p_list->i_count; i++ )
1071 if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
1079 /* clean up everything */
1080 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, NULL );
1085 #define TEXT_OR_VAR qfu ( text.psz_string ? text.psz_string : psz_var )
1087 void QVLCMenu::UpdateItem( intf_thread_t *p_intf, QMenu *menu,
1088 const char *psz_var, vlc_object_t *p_object, bool b_submenu )
1090 vlc_value_t val, text;
1093 QAction *action = FindActionWithVar( menu, psz_var );
1095 DeleteNonStaticEntries( action->menu() );
1100 action->setEnabled( false );
1104 /* Check the type of the object variable */
1105 /* What is the following HACK needed for? */
1106 if( !strcmp( psz_var, "audio-es" )
1107 || !strcmp( psz_var, "video-es" ) )
1108 i_type = VLC_VAR_INTEGER | VLC_VAR_HASCHOICE;
1110 i_type = var_Type( p_object, psz_var );
1112 switch( i_type & VLC_VAR_TYPE )
1116 case VLC_VAR_VARIABLE:
1117 case VLC_VAR_STRING:
1118 case VLC_VAR_INTEGER:
1122 /* Variable doesn't exist or isn't handled */
1124 action->setEnabled( false );
1128 /* Make sure we want to display the variable */
1129 if( menu->isEmpty() && IsMenuEmpty( psz_var, p_object ) )
1132 action->setEnabled( false );
1136 /* Get the descriptive name of the variable */
1137 int i_ret = var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
1138 if( i_ret != VLC_SUCCESS )
1140 text.psz_string = NULL;
1145 action = new QAction( TEXT_OR_VAR, menu );
1146 menu->addAction( action );
1147 action->setData( psz_var );
1150 /* Some specific stuff */
1151 bool forceDisabled = false;
1152 if( !strcmp( psz_var, "spu-es" ) )
1154 vout_thread_t *p_vout = THEMIM->getVout();
1155 forceDisabled = ( p_vout == NULL );
1157 vlc_object_release( p_vout );
1160 if( i_type & VLC_VAR_HASCHOICE )
1162 /* Append choices menu */
1166 submenu = action->menu();
1169 submenu = new QMenu( menu );
1170 action->setMenu( submenu );
1174 CreateChoicesMenu( submenu, psz_var, p_object, true ) == 0 );
1176 action->setEnabled( false );
1181 CreateChoicesMenu( menu, psz_var, p_object, true ) == 0 );
1183 FREENULL( text.psz_string );
1187 switch( i_type & VLC_VAR_TYPE )
1190 var_Get( p_object, psz_var, &val );
1191 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_NORMAL,
1192 p_object, val, i_type );
1196 var_Get( p_object, psz_var, &val );
1197 val.b_bool = !val.b_bool;
1198 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_CHECK,
1199 p_object, val, i_type, !val.b_bool );
1202 FREENULL( text.psz_string );
1206 int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
1207 vlc_object_t *p_object, bool b_root )
1209 vlc_value_t val, val_list, text_list;
1212 /* Check the type of the object variable */
1213 i_type = var_Type( p_object, psz_var );
1215 /* Make sure we want to display the variable */
1216 if( submenu->isEmpty() && IsMenuEmpty( psz_var, p_object, b_root ) )
1217 return VLC_EGENERIC;
1219 switch( i_type & VLC_VAR_TYPE )
1223 case VLC_VAR_VARIABLE:
1224 case VLC_VAR_STRING:
1225 case VLC_VAR_INTEGER:
1229 /* Variable doesn't exist or isn't handled */
1230 return VLC_EGENERIC;
1233 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
1234 &val_list, &text_list ) < 0 )
1236 return VLC_EGENERIC;
1239 #define CURVAL val_list.p_list->p_values[i]
1240 #define CURTEXT text_list.p_list->p_values[i].psz_string
1242 for( i = 0; i < val_list.p_list->i_count; i++ )
1244 vlc_value_t another_val;
1246 QMenu *subsubmenu = new QMenu( submenu );
1248 switch( i_type & VLC_VAR_TYPE )
1250 case VLC_VAR_VARIABLE:
1251 CreateChoicesMenu( subsubmenu, CURVAL.psz_string, p_object, false );
1252 subsubmenu->setTitle( qfu( CURTEXT ? CURTEXT :CURVAL.psz_string ) );
1253 submenu->addMenu( subsubmenu );
1256 case VLC_VAR_STRING:
1257 var_Get( p_object, psz_var, &val );
1258 another_val.psz_string = strdup( CURVAL.psz_string );
1259 menutext = qfu( CURTEXT ? CURTEXT : another_val.psz_string );
1260 CreateAndConnect( submenu, psz_var, menutext, "", ITEM_RADIO,
1261 p_object, another_val, i_type,
1262 val.psz_string && !strcmp( val.psz_string, CURVAL.psz_string ) );
1264 free( val.psz_string );
1267 case VLC_VAR_INTEGER:
1268 var_Get( p_object, psz_var, &val );
1269 if( CURTEXT ) menutext = qfu( CURTEXT );
1270 else menutext.sprintf( "%d", CURVAL.i_int );
1271 CreateAndConnect( submenu, psz_var, menutext, "", ITEM_RADIO,
1272 p_object, CURVAL, i_type,
1273 CURVAL.i_int == val.i_int );
1277 var_Get( p_object, psz_var, &val );
1278 if( CURTEXT ) menutext = qfu( CURTEXT );
1279 else menutext.sprintf( "%.2f", CURVAL.f_float );
1280 CreateAndConnect( submenu, psz_var, menutext, "", ITEM_RADIO,
1281 p_object, CURVAL, i_type,
1282 CURVAL.f_float == val.f_float );
1289 currentGroup = NULL;
1291 /* clean up everything */
1292 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
1296 return submenu->isEmpty() ? VLC_EGENERIC : VLC_SUCCESS;
1299 void QVLCMenu::CreateAndConnect( QMenu *menu, const char *psz_var,
1300 QString text, QString help,
1301 int i_item_type, vlc_object_t *p_obj,
1302 vlc_value_t val, int i_val_type,
1305 QAction *action = FindActionWithVar( menu, psz_var );
1310 action = new QAction( text, menu );
1311 menu->addAction( action );
1315 action->setToolTip( help );
1316 action->setEnabled( p_obj != NULL );
1318 if( i_item_type == ITEM_CHECK )
1320 action->setCheckable( true );
1322 else if( i_item_type == ITEM_RADIO )
1324 action->setCheckable( true );
1326 currentGroup = new QActionGroup( menu );
1327 currentGroup->addAction( action );
1330 action->setChecked( checked );
1332 MenuItemData *itemData = new MenuItemData( THEDP->menusMapper, p_obj, i_val_type,
1334 CONNECT( action, triggered(), THEDP->menusMapper, map() );
1335 THEDP->menusMapper->setMapping( action, itemData );
1338 menu->addAction( action );
1341 void QVLCMenu::DoAction( QObject *data )
1343 MenuItemData *itemData = qobject_cast<MenuItemData *>( data );
1344 vlc_object_t *p_object = itemData->p_obj;
1345 if( p_object == NULL ) return;
1347 var_Set( p_object, itemData->psz_var, itemData->val );
1350 void QVLCMenu::updateRecents( intf_thread_t *p_intf )
1355 RecentsMRL* rmrl = RecentsMRL::getInstance( p_intf );
1356 QList<QString> l = rmrl->recents();
1358 recentsMenu->clear();
1361 action = recentsMenu->addAction( qtr(" - Empty - ") );
1362 action->setEnabled( false );
1366 for( int i = 0; i < l.size(); ++i )
1368 action = recentsMenu->addAction(
1369 QString( "&%1: " ).arg( i + 1 ) + l.at( i ),
1372 rmrl->signalMapper->setMapping( action, l.at( i ) );
1375 recentsMenu->addSeparator();
1376 recentsMenu->addAction( qtr("&Clear"), rmrl, SLOT( clear() ) );