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 );
114 * @brief Enable all static entries, disable the others
115 * @param enable if false, disable all entries
117 void EnableStaticEntries( QMenu *menu, bool enable = true )
121 QList< QAction* > actions = menu->actions();
122 for( int i = 0; i < actions.size(); ++i )
124 actions[i]->setEnabled( enable && actions[i]->data().toBool() );
129 * \return Number of static entries
131 int DeleteNonStaticEntries( QMenu *menu )
136 QList< QAction* > actions = menu->actions();
137 for( int i = 0; i < actions.size(); ++i )
139 if( !actions[i]->data().toBool() )
150 void addMIMStaticEntry( intf_thread_t *p_intf,
156 if( strlen( icon ) > 0 )
158 QAction *action = menu->addAction( text, THEMIM, member );
159 action->setIcon( QIcon( icon ) );
163 menu->addAction( text, THEMIM, member );
167 /*****************************************************************************
168 * Definitions of variables for the dynamic menus
169 *****************************************************************************/
170 #define PUSH_VAR( var ) varnames.push_back( var ); \
171 objects.push_back( VLC_OBJECT(p_object) )
173 #define PUSH_INPUTVAR( var ) varnames.push_back( var ); \
174 objects.push_back( VLC_OBJECT(p_input) );
176 #define PUSH_SEPARATOR if( objects.size() != i_last_separator ) { \
177 objects.push_back( 0 ); varnames.push_back( "" ); \
178 i_last_separator = objects.size(); }
180 static int InputAutoMenuBuilder( input_thread_t *p_object,
181 vector<vlc_object_t *> &objects,
182 vector<const char *> &varnames )
184 PUSH_VAR( "bookmark" );
186 PUSH_VAR( "chapter" );
187 PUSH_VAR( "navigation" );
188 PUSH_VAR( "program" );
189 PUSH_VAR( "dvd_menus" );
193 static int VideoAutoMenuBuilder( vout_thread_t *p_object,
194 input_thread_t *p_input,
195 vector<vlc_object_t *> &objects,
196 vector<const char *> &varnames )
198 PUSH_INPUTVAR( "video-es" );
199 PUSH_INPUTVAR( "spu-es" );
200 PUSH_VAR( "fullscreen" );
201 PUSH_VAR( "video-on-top" );
203 PUSH_VAR( "directx-wallpaper" );
205 PUSH_VAR( "video-snapshot" );
207 PUSH_VAR( "autoscale" );
208 PUSH_VAR( "aspect-ratio" );
210 PUSH_VAR( "deinterlace" );
212 /* Special case for postproc */
216 /* p_object is the vout, so the decoder is our parent and the
217 * postproc filter one of the decoder's children */
218 vlc_object_t *p_dec = (vlc_object_t *)
219 vlc_object_find( p_object, VLC_OBJECT_DECODER,
223 vlc_object_t *p_pp = (vlc_object_t *)
224 vlc_object_find_name( p_dec, "postproc",
228 vlc_object_t *p_object = p_pp;
229 PUSH_VAR( "postproc-q" );
230 vlc_object_release( p_pp );
233 vlc_object_release( p_dec );
240 static int AudioAutoMenuBuilder( aout_instance_t *p_object,
241 input_thread_t *p_input,
242 vector<vlc_object_t *> &objects,
243 vector<const char *> &varnames )
245 PUSH_INPUTVAR( "audio-es" );
246 PUSH_VAR( "audio-channels" );
247 PUSH_VAR( "audio-device" );
248 PUSH_VAR( "visual" );
252 static QAction * FindActionWithVar( QMenu *menu, const char *psz_var )
254 QList< QAction* > actions = menu->actions();
255 for( int i = 0; i < actions.size(); ++i )
257 if( actions[i]->data().toString() == psz_var )
263 /*****************************************************************************
266 *****************************************************************************/
268 #define BAR_ADD( func, title ) { \
269 QMenu *_menu = func; _menu->setTitle( title ); bar->addMenu( _menu ); }
271 #define BAR_DADD( func, title, id ) { \
272 QMenu *_menu = func; _menu->setTitle( title ); bar->addMenu( _menu ); \
273 MenuFunc *f = new MenuFunc( _menu, id ); \
274 CONNECT( _menu, aboutToShow(), THEDP->menusUpdateMapper, map() ); \
275 THEDP->menusUpdateMapper->setMapping( _menu, f ); }
277 #define ACT_ADD( _menu, val, title ) { \
278 QAction *_action = new QAction( title, _menu ); _action->setData( val ); \
279 _menu->addAction( _action ); }
281 #define ACT_ADDMENU( _menu, val, title ) { \
282 QAction *_action = new QAction( title, _menu ); _action->setData( val ); \
283 _action->setMenu( new QMenu() ); _menu->addAction( _action ); }
285 #define ACT_ADDCHECK( _menu, val, title ) { \
286 QAction *_action = new QAction( title, _menu ); _action->setData( val ); \
287 _action->setCheckable( true ); _menu->addAction( _action ); }
290 * Main Menu Bar Creation
292 void QVLCMenu::createMenuBar( MainInterface *mi,
293 intf_thread_t *p_intf,
294 bool visual_selector_enabled )
295 /* FIXME remove this visual dependency */
297 /* QMainWindows->menuBar()
298 gives the QProcess::destroyed timeout issue on Cleanlooks style with
299 setDesktopAware set to false */
300 QMenuBar *bar = mi->menuBar();
301 BAR_ADD( FileMenu( p_intf, bar ), qtr( "&Media" ) );
303 BAR_DADD( NavigMenu( p_intf, bar ), qtr( "P&layback" ), 3 );
304 BAR_DADD( AudioMenu( p_intf, bar ), qtr( "&Audio" ), 1 );
305 BAR_DADD( VideoMenu( p_intf, bar ), qtr( "&Video" ), 2 );
307 BAR_ADD( ToolsMenu( bar ), qtr( "&Tools" ) );
308 BAR_ADD( ViewMenu( p_intf, NULL, mi, visual_selector_enabled, true ),
311 BAR_ADD( HelpMenu( bar ), qtr( "&Help" ) );
317 * Media ( File ) Menu
318 * Opening, streaming and quit
320 QMenu *QVLCMenu::FileMenu( intf_thread_t *p_intf, QWidget *parent )
322 QMenu *menu = new QMenu( parent );
324 addDPStaticEntry( menu, qtr( "&Open File..." ),
325 ":/file-asym", SLOT( simpleOpenDialog() ), "Ctrl+O" );
326 addDPStaticEntry( menu, qtr( "Advanced Open File..." ),
327 ":/file-asym", SLOT( openFileDialog() ), "Ctrl+Shift+O" );
328 addDPStaticEntry( menu, qtr( I_OPEN_FOLDER ),
329 ":/folder-grey", SLOT( PLOpenDir() ), "Ctrl+F" );
330 addDPStaticEntry( menu, qtr( "Open &Disc..." ),
331 ":/disc", SLOT( openDiscDialog() ), "Ctrl+D" );
332 addDPStaticEntry( menu, qtr( "Open &Network..." ),
333 ":/network", SLOT( openNetDialog() ), "Ctrl+N" );
334 addDPStaticEntry( menu, qtr( "Open &Capture Device..." ),
335 ":/capture-card", SLOT( openCaptureDialog() ),
338 menu->addSeparator();
339 addDPStaticEntry( menu, qtr( "Paste &MRL" ),
340 NULL, SLOT( openUrlDialog() ), "Ctrl+V" );
342 recentsMenu = new QMenu( qtr( "&Recent Media" ), menu );
343 updateRecents( p_intf );
344 menu->addMenu( recentsMenu );
345 menu->addSeparator();
346 menu->addMenu( SDMenu( p_intf, menu ) );
347 menu->addSeparator();
349 addDPStaticEntry( menu, qtr( I_PL_SAVE ), "", SLOT( saveAPlaylist() ),
351 menu->addSeparator();
353 addDPStaticEntry( menu, qtr( "Conve&rt / Save..." ), "",
354 SLOT( openAndTranscodingDialogs() ), "Ctrl+R" );
355 addDPStaticEntry( menu, qtr( "&Streaming..." ),
356 ":/stream", SLOT( openAndStreamingDialogs() ),
358 menu->addSeparator();
360 addDPStaticEntry( menu, qtr( "&Quit" ) ,
361 ":/quit", SLOT( quit() ), "Ctrl+Q" );
365 /* Playlist/MediaLibrary Control */
366 QMenu *QVLCMenu::ToolsMenu( QMenu *menu )
368 addDPStaticEntry( menu, qtr( I_MENU_EXT ), ":/settings",
369 SLOT( extendedDialog() ), "Ctrl+E" );
371 addDPStaticEntry( menu, qtr( I_MENU_INFO ) , ":/info",
372 SLOT( mediaInfoDialog() ), "Ctrl+I" );
373 addDPStaticEntry( menu, qtr( I_MENU_CODECINFO ) ,
374 ":/info", SLOT( mediaCodecDialog() ), "Ctrl+J" );
376 addDPStaticEntry( menu, qtr( I_MENU_BOOKMARK ),"",
377 SLOT( bookmarksDialog() ), "Ctrl+B" );
379 addDPStaticEntry( menu, qtr( I_MENU_VLM ), "", SLOT( vlmDialog() ),
383 addDPStaticEntry( menu, qtr( I_MENU_MSG ),
384 ":/messages", SLOT( messagesDialog() ),
387 addDPStaticEntry( menu, qtr( "Plu&gins and extensions" ),
388 "", SLOT( pluginDialog() ) );
389 menu->addSeparator();
391 addDPStaticEntry( menu, qtr( "&Preferences" ),
392 ":/preferences", SLOT( prefsDialog() ), "Ctrl+P" );
397 QMenu *QVLCMenu::ToolsMenu( QWidget *parent )
399 return ToolsMenu( new QMenu( parent ) );
404 * This menu can be an interface menu but also a right click menu.
406 QMenu *QVLCMenu::ViewMenu( intf_thread_t *p_intf,
409 bool visual_selector_enabled,
414 menu = new QMenu( current );
416 menu = new QMenu( mi );
420 act = menu->addAction( QIcon( ":/playlist_menu" ),
421 qtr( "Play&list" ), mi,
422 SLOT( togglePlaylist() ), qtr( "Ctrl+L" ) );
423 act->setData( true );
425 /*menu->addSeparator();
426 menu->addAction( qtr( "Undock from Interface" ), mi,
427 SLOT( undockPlaylist() ), qtr( "Ctrl+U" ) );*/
430 menu->addSeparator();
434 QMenu *intfmenu = InterfacesMenu( p_intf, menu );
435 MenuFunc *f = new MenuFunc( intfmenu, 4 );
436 CONNECT( intfmenu, aboutToShow(), THEDP->menusUpdateMapper, map() );
437 THEDP->menusUpdateMapper->setMapping( intfmenu, f );
438 menu->addSeparator();
443 QAction *action = menu->addAction( qtr( "Mi&nimal View" ), mi,
444 SLOT( toggleMinimalView() ), qtr( "Ctrl+H" ) );
445 action->setCheckable( true );
446 action->setData( true );
447 if( mi->getControlsVisibilityStatus() & CONTROLS_VISIBLE )
448 action->setChecked( true );
449 minimalViewAction = action; /* HACK for minimalView */
451 /* FullScreen View */
452 action = menu->addAction( qtr( "&Fullscreen Interface" ), mi,
453 SLOT( toggleFullScreen() ), QString( "F11" ) );
454 fullscreenViewAction = action;
455 action->setCheckable( true );
456 action->setData( true );
458 /* Advanced Controls */
459 action = menu->addAction( qtr( "&Advanced Controls" ), mi,
460 SLOT( toggleAdvanced() ) );
461 action->setCheckable( true );
462 action->setData( true );
463 if( mi->getControlsVisibilityStatus() & CONTROLS_ADVANCED )
464 action->setChecked( true );
465 #if 0 /* For Visualisations. Not yet working */
466 adv = menu->addAction( qtr( "Visualizations selector" ),
467 mi, SLOT( visual() ) );
468 adv->setCheckable( true );
469 if( visual_selector_enabled ) adv->setChecked( true );
473 menu->addSeparator();
474 addDPStaticEntry( menu, qtr( "Customi&ze Interface..." ),
475 ":/preferences", SLOT( toolbarDialog() ) );
476 menu->addSeparator();
482 * Interface Sub-Menu, to list extras interface and skins
484 QMenu *QVLCMenu::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
486 vector<vlc_object_t *> objects;
487 vector<const char *> varnames;
488 /** \todo add "switch to XXX" */
489 varnames.push_back( "intf-add" );
490 objects.push_back( VLC_OBJECT(p_intf) );
492 return Populate( p_intf, current, varnames, objects );
498 QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QMenu * current )
500 vector<vlc_object_t *> objects;
501 vector<const char *> varnames;
502 aout_instance_t *p_aout;
503 input_thread_t *p_input;
505 if( current->isEmpty() )
507 ACT_ADDMENU( current, "audio-es", qtr( "Audio &Track" ) );
508 ACT_ADDMENU( current, "audio-channels", qtr( "Audio &Channels" ) );
509 ACT_ADDMENU( current, "audio-device", qtr( "Audio &Device" ) );
510 current->addSeparator();
512 ACT_ADDMENU( current, "visual", qtr( "&Visualizations" ) );
513 current->addSeparator();
515 QAction *action = current->addAction( qtr( "Increase Volume" ),
516 ActionsManager::getInstance( p_intf ), SLOT( AudioUp() ) );
517 action->setData( true );
518 action = current->addAction( qtr( "Decrease Volume" ),
519 ActionsManager::getInstance( p_intf ), SLOT( AudioDown() ) );
520 action->setData( true );
521 action = current->addAction( qtr( "Mute" ),
522 ActionsManager::getInstance( p_intf ), SLOT( toggleMuteAudio() ) );
523 action->setData( true );
526 p_input = THEMIM->getInput();
528 vlc_object_hold( p_input );
529 p_aout = THEMIM->getAout();
530 AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
531 EnableStaticEntries( current, ( p_aout != NULL ) );
534 vlc_object_release( p_aout );
537 vlc_object_release( p_input );
539 return Populate( p_intf, current, varnames, objects );
542 QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QWidget *parent )
544 return AudioMenu( p_intf, new QMenu( parent ) );
549 * Subtitles are part of Video.
551 QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current )
553 vout_thread_t *p_vout;
554 input_thread_t *p_input;
555 vector<vlc_object_t *> objects;
556 vector<const char *> varnames;
558 if( current->isEmpty() )
560 ACT_ADDMENU( current, "video-es", qtr( "Video &Track" ) );
563 QMenu *submenu = new QMenu( qtr( "&Subtitles Track" ), current );
564 action = current->addMenu( submenu );
565 action->setData( "spu-es" );
566 addDPStaticEntry( submenu, qtr( "Open File..." ), "",
567 SLOT( loadSubtitlesFile() ) );
568 submenu->addSeparator();
569 current->addSeparator();
571 ACT_ADDCHECK( current, "fullscreen", qtr( "&Fullscreen" ) );
572 ACT_ADDCHECK( current, "video-on-top", qtr( "Always &On Top" ) );
574 ACT_ADDCHECK( current, "directx-wallpaper", qtr( "DirectX Wallpaper" ) );
576 ACT_ADD( current, "video-snapshot", qtr( "Sna&pshot" ) );
578 current->addSeparator();
580 ACT_ADDMENU( current, "zoom", qtr( "&Zoom" ) );
581 ACT_ADDCHECK( current, "autoscale", qtr( "Sca&le" ) );
582 ACT_ADDMENU( current, "aspect-ratio", qtr( "&Aspect Ratio" ) );
583 ACT_ADDMENU( current, "crop", qtr( "&Crop" ) );
584 ACT_ADDMENU( current, "deinterlace", qtr( "&Deinterlace" ) );
585 ACT_ADDMENU( current, "postproc-q", qtr( "&Post processing" ) );
588 p_input = THEMIM->getInput();
590 vlc_object_hold( p_input );
592 p_vout = THEMIM->getVout();
593 VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
594 EnableStaticEntries( current, ( p_vout != NULL ) );
597 vlc_object_release( p_vout );
600 vlc_object_release( p_input );
602 return Populate( p_intf, current, varnames, objects );
605 QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QWidget *parent )
607 return VideoMenu( p_intf, new QMenu( parent ) );
612 * For DVD, MP4, MOV and other chapter based format
614 QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *menu )
616 if( menu->isEmpty() )
619 QMenu *submenu = new QMenu( qtr( "&Bookmarks" ), menu );
620 addDPStaticEntry( submenu, qtr( "Manage &bookmarks" ), "",
621 SLOT( bookmarksDialog() ) );
622 submenu->addSeparator();
623 action = menu->addMenu( submenu );
624 action->setData( "bookmark" );
625 ACT_ADDMENU( menu, "title", qtr( "T&itle" ) );
626 ACT_ADDMENU( menu, "chapter", qtr( "&Chapter" ) );
627 ACT_ADDMENU( menu, "navigation", qtr( "&Navigation" ) );
628 ACT_ADDMENU( menu, "program", qtr( "&Program" ) );
630 menu->addSeparator();
631 addDPStaticEntry( menu, qtr( I_MENU_GOTOTIME ),"",
632 SLOT( gotoTimeDialog() ), "Ctrl+T" );
636 input_thread_t *p_object;
637 vector<vlc_object_t *> objects;
638 vector<const char *> varnames;
640 p_object = THEMIM->getInput();
642 vlc_object_hold( p_object );
643 InputAutoMenuBuilder( p_object, objects, varnames );
644 PUSH_VAR( "prev-title" );
645 PUSH_VAR( "next-title" );
646 PUSH_VAR( "prev-chapter" );
647 PUSH_VAR( "next-chapter" );
648 EnableStaticEntries( menu, ( p_object != NULL ) );
651 vlc_object_release( p_object );
653 return Populate( p_intf, menu, varnames, objects );
656 QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QWidget *parent )
658 return NavigMenu( p_intf, new QMenu( parent ) );
662 * Service Discovery SubMenu
664 QMenu *QVLCMenu::SDMenu( intf_thread_t *p_intf, QWidget *parent )
666 QMenu *menu = new QMenu( parent );
667 menu->setTitle( qtr( I_PL_SD ) );
668 char **ppsz_longnames;
669 char **ppsz_names = vlc_sd_GetNames( &ppsz_longnames );
673 char **ppsz_name = ppsz_names, **ppsz_longname = ppsz_longnames;
674 for( ; *ppsz_name; ppsz_name++, ppsz_longname++ )
676 QAction *a = new QAction( qfu( *ppsz_longname ), menu );
677 a->setCheckable( true );
678 if( playlist_IsServicesDiscoveryLoaded( THEPL, *ppsz_name ) )
679 a->setChecked( true );
680 CONNECT( a , triggered(), THEDP->SDMapper, map() );
681 THEDP->SDMapper->setMapping( a, QString( *ppsz_name ) );
682 menu->addAction( a );
684 if( !strcmp( *ppsz_name, "podcast" ) )
686 QAction *b = new QAction( qtr( "Configure podcasts..." ), menu );
687 //b->setEnabled( a->isChecked() );
688 menu->addAction( b );
689 CONNECT( b, triggered(), THEDP, podcastConfigureDialog() );
692 free( *ppsz_longname );
695 free( ppsz_longnames );
702 QMenu *QVLCMenu::HelpMenu( QWidget *parent )
704 QMenu *menu = new QMenu( parent );
705 addDPStaticEntry( menu, qtr( "&Help..." ) ,
706 ":/help", SLOT( helpDialog() ), "F1" );
708 addDPStaticEntry( menu, qtr( "Check for &Updates..." ) , "",
709 SLOT( updateDialog() ) );
711 menu->addSeparator();
712 addDPStaticEntry( menu, qtr( I_MENU_ABOUT ), ":/info",
713 SLOT( aboutDialog() ), "Shift+F1" );
717 /*****************************************************************************
718 * Popup menus - Right Click menus *
719 *****************************************************************************/
720 #define POPUP_BOILERPLATE \
721 unsigned int i_last_separator = 0; \
722 vector<vlc_object_t *> objects; \
723 vector<const char *> varnames; \
724 input_thread_t *p_input = THEMIM->getInput();
726 #define CREATE_POPUP \
727 Populate( p_intf, menu, varnames, objects ); \
728 p_intf->p_sys->p_popup_menu = menu; \
729 menu->popup( QCursor::pos() ); \
730 p_intf->p_sys->p_popup_menu = NULL; \
731 i_last_separator = 0;
733 void QVLCMenu::PopupMenuControlEntries( QMenu *menu,
734 intf_thread_t *p_intf,
735 input_thread_t *p_input )
740 var_Get( p_input, "state", &val );
741 if( val.i_int == PLAYING_S )
742 addMIMStaticEntry( p_intf, menu, qtr( "Pause" ),
743 ":/pause", SLOT( togglePlayPause() ) );
745 addMIMStaticEntry( p_intf, menu, qtr( "Play" ),
746 ":/play", SLOT( togglePlayPause() ) );
748 else if( THEPL->items.i_size )
749 addMIMStaticEntry( p_intf, menu, qtr( "Play" ),
750 ":/play", SLOT( togglePlayPause() ) );
752 addDPStaticEntry( menu, qtr( "Play" ),
753 ":/play", SLOT( openDialog() ) );
755 addMIMStaticEntry( p_intf, menu, qtr( "Stop" ),
756 ":/stop", SLOT( stop() ) );
757 addMIMStaticEntry( p_intf, menu, qtr( "Previous" ),
758 ":/previous", SLOT( prev() ) );
759 addMIMStaticEntry( p_intf, menu, qtr( "Next" ),
760 ":/next", SLOT( next() ) );
763 void QVLCMenu::PopupMenuStaticEntries( QMenu *menu )
765 QMenu *openmenu = new QMenu( qtr( "Open Media" ), menu );
766 addDPStaticEntry( openmenu, qtr( "&Open File..." ),
767 ":/file-asym", SLOT( openFileDialog() ) );
768 addDPStaticEntry( openmenu, qtr( I_OPEN_FOLDER ),
769 ":/folder-grey", SLOT( PLOpenDir() ) );
770 addDPStaticEntry( openmenu, qtr( "Open &Disc..." ),
771 ":/disc", SLOT( openDiscDialog() ) );
772 addDPStaticEntry( openmenu, qtr( "Open &Network..." ),
773 ":/network", SLOT( openNetDialog() ) );
774 addDPStaticEntry( openmenu, qtr( "Open &Capture Device..." ),
775 ":/capture-card", SLOT( openCaptureDialog() ) );
776 menu->addMenu( openmenu );
778 menu->addSeparator();
780 QMenu *helpmenu = HelpMenu( menu );
781 helpmenu->setTitle( qtr( "Help" ) );
782 menu->addMenu( helpmenu );
785 addDPStaticEntry( menu, qtr( "Quit" ), ":/quit",
786 SLOT( quit() ), "Ctrl+Q" );
789 /* Video Tracks and Subtitles tracks */
790 void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf )
795 vlc_object_hold( p_input );
796 vout_thread_t *p_vout = THEMIM->getVout();
799 VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
800 vlc_object_release( p_vout );
802 vlc_object_release( p_input );
804 QMenu *menu = new QMenu();
809 void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf )
814 vlc_object_hold( p_input );
815 aout_instance_t *p_aout = THEMIM->getAout();
816 AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
818 vlc_object_release( p_aout );
819 vlc_object_release( p_input );
821 QMenu *menu = new QMenu();
825 /* Navigation stuff, and general menus ( open ) */
826 void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf )
832 vlc_object_hold( p_input );
833 varnames.push_back( "audio-es" );
834 InputAutoMenuBuilder( p_input, objects, varnames );
838 QMenu *menu = new QMenu();
839 Populate( p_intf, menu, varnames, objects );
841 menu->addSeparator();
842 PopupMenuControlEntries( menu, p_intf, p_input );
844 menu->addSeparator();
845 PopupMenuStaticEntries( menu );
847 p_intf->p_sys->p_popup_menu = menu;
848 menu->popup( QCursor::pos() );
849 p_intf->p_sys->p_popup_menu = NULL;
852 /* Main Menu that sticks everything together */
853 void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show )
855 MainInterface *mi = p_intf->p_sys->p_mi;
858 /* Delete and recreate a popup if there is one */
859 if( p_intf->p_sys->p_popup_menu )
860 delete p_intf->p_sys->p_popup_menu;
862 QMenu *menu = new QMenu();
865 bool b_isFullscreen = false;
869 PopupMenuControlEntries( menu, p_intf, p_input );
870 menu->addSeparator();
874 vout_thread_t *p_vout = THEMIM->getVout();
876 /* Add a fullscreen switch button */
880 var_Get( p_vout, "fullscreen", &val );
881 b_isFullscreen = !( !val.b_bool );
883 CreateAndConnect( menu, "fullscreen",
884 qtr( "Leave Fullscreen" ),"" , ITEM_NORMAL,
885 VLC_OBJECT(p_vout), val, VLC_VAR_BOOL,
887 vlc_object_release( p_vout );
890 menu->addSeparator();
893 vlc_object_hold( p_input );
894 InputAutoMenuBuilder( p_input, objects, varnames );
895 vlc_object_release( p_input );
898 submenu = new QMenu( menu );
899 action = menu->addMenu( AudioMenu( p_intf, submenu ) );
900 action->setText( qtr( "&Audio" ) );
901 if( action->menu()->isEmpty() )
902 action->setEnabled( false );
905 submenu = new QMenu( menu );
906 action = menu->addMenu( VideoMenu( p_intf, submenu ) );
907 action->setText( qtr( "&Video" ) );
908 if( action->menu()->isEmpty() )
909 action->setEnabled( false );
911 /* Playback menu for chapters */
912 submenu = new QMenu( menu );
913 action = menu->addMenu( NavigMenu( p_intf, submenu ) );
914 action->setText( qtr( "&Playback" ) );
915 if( action->menu()->isEmpty() )
916 action->setEnabled( false );
919 menu->addSeparator();
921 /* Add some special entries for windowed mode: Interface Menu */
922 if( !b_isFullscreen )
924 submenu = new QMenu( qtr( "Interface" ), menu );
927 submenu->addAction( QIcon( ":/playlist" ),
928 qtr( "Show Playlist" ), mi, SLOT( togglePlaylist() ) );
929 action = submenu->addAction( QIcon( "" ),
930 qtr( "Minimal View" ), mi, SLOT( toggleMinimalView() ) );
931 action->setCheckable( true );
932 action->setChecked( !( mi->getControlsVisibilityStatus() &
933 CONTROLS_VISIBLE ) );
934 action = submenu->addAction( QIcon( "" ),
935 qtr( "Fullscreen Interface" ),
936 mi, SLOT( toggleFullScreen() ) );
937 action->setCheckable( true );
938 action->setChecked( mi->isFullScreen() );
940 else /* We are using the skins interface.
941 If not, this entry will not show. */
944 QMenu *tools = ToolsMenu( submenu );
945 submenu->addSeparator();
948 vlc_object_t *p_object = ( vlc_object_t* )
949 vlc_object_find_name( p_intf, "skins2", FIND_PARENT );
952 objects.push_back( p_object );
953 varnames.push_back( "intf-skins" );
954 Populate( p_intf, submenu, varnames, objects );
955 vlc_object_release( p_object );
958 msg_Dbg( p_intf, "could not find parent interface" );
960 menu->addMenu( submenu );
963 /* Static entries for ending, like open */
964 PopupMenuStaticEntries( menu );
966 p_intf->p_sys->p_popup_menu = menu;
967 p_intf->p_sys->p_popup_menu->popup( QCursor::pos() );
971 // destroy popup if there is one
972 delete p_intf->p_sys->p_popup_menu;
973 p_intf->p_sys->p_popup_menu = NULL;
981 /************************************************************************
983 ************************************************************************/
985 void QVLCMenu::updateSystrayMenu( MainInterface *mi,
986 intf_thread_t *p_intf,
987 bool b_force_visible )
991 /* Get the systray menu and clean it */
992 QMenu *sysMenu = mi->getSysTrayMenu();
995 /* Hide / Show VLC and cone */
996 if( mi->isVisible() || b_force_visible )
998 sysMenu->addAction( QIcon( ":/vlc16.png" ),
999 qtr( "Hide VLC media player in taskbar" ), mi,
1000 SLOT( toggleUpdateSystrayMenu() ) );
1004 sysMenu->addAction( QIcon( ":/vlc16.png" ),
1005 qtr( "Show VLC media player" ), mi,
1006 SLOT( toggleUpdateSystrayMenu() ) );
1009 sysMenu->addSeparator();
1010 PopupMenuControlEntries( sysMenu, p_intf, p_input );
1012 sysMenu->addSeparator();
1013 addDPStaticEntry( sysMenu, qtr( "&Open Media" ),
1014 ":/file-wide", SLOT( openFileDialog() ) );
1015 addDPStaticEntry( sysMenu, qtr( "&Quit" ) ,
1016 ":/quit", SLOT( quit() ) );
1019 mi->getSysTray()->setContextMenu( sysMenu );
1023 #undef PUSH_SEPARATOR
1025 /*************************************************************************
1026 * Builders for automenus
1027 *************************************************************************/
1028 QMenu * QVLCMenu::Populate( intf_thread_t *p_intf,
1030 vector< const char *> & varnames,
1031 vector<vlc_object_t *> & objects )
1033 QMenu *menu = current;
1036 msg_Warn( p_intf, "%s leaking a menu", __func__ );
1040 currentGroup = NULL;
1042 vlc_object_t *p_object;
1044 for( int i = 0; i < ( int )objects.size() ; i++ )
1046 if( !varnames[i] || !*varnames[i] )
1048 menu->addSeparator();
1051 p_object = objects[i];
1053 UpdateItem( p_intf, menu, varnames[i], p_object, true );
1058 /*****************************************************************************
1060 *****************************************************************************/
1062 static bool IsMenuEmpty( const char *psz_var,
1063 vlc_object_t *p_object,
1064 bool b_root = true )
1066 vlc_value_t val, val_list;
1067 int i_type, i_result, i;
1069 /* Check the type of the object variable */
1070 i_type = var_Type( p_object, psz_var );
1072 /* Check if we want to display the variable */
1073 if( !( i_type & VLC_VAR_HASCHOICE ) ) return false;
1075 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
1076 if( val.i_int == 0 ) return true;
1078 if( ( i_type & VLC_VAR_TYPE ) != VLC_VAR_VARIABLE )
1080 if( val.i_int == 1 && b_root ) return true;
1084 /* Check children variables in case of VLC_VAR_VARIABLE */
1085 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
1090 for( i = 0, i_result = true; i < val_list.p_list->i_count; i++ )
1092 if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
1100 /* clean up everything */
1101 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, NULL );
1106 #define TEXT_OR_VAR qfu ( text.psz_string ? text.psz_string : psz_var )
1108 void QVLCMenu::UpdateItem( intf_thread_t *p_intf, QMenu *menu,
1109 const char *psz_var, vlc_object_t *p_object, bool b_submenu )
1111 vlc_value_t val, text;
1114 QAction *action = FindActionWithVar( menu, psz_var );
1116 DeleteNonStaticEntries( action->menu() );
1121 action->setEnabled( false );
1125 /* Check the type of the object variable */
1126 /* What is the following HACK needed for? */
1127 if( !strcmp( psz_var, "audio-es" )
1128 || !strcmp( psz_var, "video-es" )
1129 || !strcmp( psz_var, "postproc-q" ) )
1130 i_type = VLC_VAR_INTEGER | VLC_VAR_HASCHOICE;
1132 i_type = var_Type( p_object, psz_var );
1134 switch( i_type & VLC_VAR_TYPE )
1138 case VLC_VAR_VARIABLE:
1139 case VLC_VAR_STRING:
1140 case VLC_VAR_INTEGER:
1144 /* Variable doesn't exist or isn't handled */
1146 action->setEnabled( false );
1150 /* Make sure we want to display the variable */
1151 if( menu->isEmpty() && IsMenuEmpty( psz_var, p_object ) )
1154 action->setEnabled( false );
1158 /* Get the descriptive name of the variable */
1159 int i_ret = var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
1160 if( i_ret != VLC_SUCCESS )
1162 text.psz_string = NULL;
1167 action = new QAction( TEXT_OR_VAR, menu );
1168 menu->addAction( action );
1169 action->setData( psz_var );
1172 /* Some specific stuff */
1173 bool forceDisabled = false;
1174 if( !strcmp( psz_var, "spu-es" ) )
1176 vout_thread_t *p_vout = THEMIM->getVout();
1177 forceDisabled = ( p_vout == NULL );
1179 vlc_object_release( p_vout );
1182 if( i_type & VLC_VAR_HASCHOICE )
1184 /* Append choices menu */
1188 submenu = action->menu();
1191 submenu = new QMenu( menu );
1192 action->setMenu( submenu );
1196 CreateChoicesMenu( submenu, psz_var, p_object, true ) == 0 );
1198 action->setEnabled( false );
1203 CreateChoicesMenu( menu, psz_var, p_object, true ) == 0 );
1205 FREENULL( text.psz_string );
1209 switch( i_type & VLC_VAR_TYPE )
1212 var_Get( p_object, psz_var, &val );
1213 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_NORMAL,
1214 p_object, val, i_type );
1218 var_Get( p_object, psz_var, &val );
1219 val.b_bool = !val.b_bool;
1220 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_CHECK,
1221 p_object, val, i_type, !val.b_bool );
1224 FREENULL( text.psz_string );
1228 int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
1229 vlc_object_t *p_object, bool b_root )
1231 vlc_value_t val, val_list, text_list;
1234 /* Check the type of the object variable */
1235 i_type = var_Type( p_object, psz_var );
1237 /* Make sure we want to display the variable */
1238 if( submenu->isEmpty() && IsMenuEmpty( psz_var, p_object, b_root ) )
1239 return VLC_EGENERIC;
1241 switch( i_type & VLC_VAR_TYPE )
1245 case VLC_VAR_VARIABLE:
1246 case VLC_VAR_STRING:
1247 case VLC_VAR_INTEGER:
1251 /* Variable doesn't exist or isn't handled */
1252 return VLC_EGENERIC;
1255 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
1256 &val_list, &text_list ) < 0 )
1258 return VLC_EGENERIC;
1261 #define CURVAL val_list.p_list->p_values[i]
1262 #define CURTEXT text_list.p_list->p_values[i].psz_string
1264 for( i = 0; i < val_list.p_list->i_count; i++ )
1266 vlc_value_t another_val;
1268 QMenu *subsubmenu = new QMenu( submenu );
1270 switch( i_type & VLC_VAR_TYPE )
1272 case VLC_VAR_VARIABLE:
1273 CreateChoicesMenu( subsubmenu, CURVAL.psz_string, p_object, false );
1274 subsubmenu->setTitle( qfu( CURTEXT ? CURTEXT :CURVAL.psz_string ) );
1275 submenu->addMenu( subsubmenu );
1278 case VLC_VAR_STRING:
1279 var_Get( p_object, psz_var, &val );
1280 another_val.psz_string = strdup( CURVAL.psz_string );
1281 menutext = qfu( CURTEXT ? CURTEXT : another_val.psz_string );
1282 CreateAndConnect( submenu, psz_var, menutext, "", ITEM_RADIO,
1283 p_object, another_val, i_type,
1284 val.psz_string && !strcmp( val.psz_string, CURVAL.psz_string ) );
1286 free( val.psz_string );
1289 case VLC_VAR_INTEGER:
1290 var_Get( p_object, psz_var, &val );
1291 if( CURTEXT ) menutext = qfu( CURTEXT );
1292 else menutext.sprintf( "%d", CURVAL.i_int );
1293 CreateAndConnect( submenu, psz_var, menutext, "", ITEM_RADIO,
1294 p_object, CURVAL, i_type,
1295 CURVAL.i_int == val.i_int );
1299 var_Get( p_object, psz_var, &val );
1300 if( CURTEXT ) menutext = qfu( CURTEXT );
1301 else menutext.sprintf( "%.2f", CURVAL.f_float );
1302 CreateAndConnect( submenu, psz_var, menutext, "", ITEM_RADIO,
1303 p_object, CURVAL, i_type,
1304 CURVAL.f_float == val.f_float );
1311 currentGroup = NULL;
1313 /* clean up everything */
1314 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
1318 return submenu->isEmpty() ? VLC_EGENERIC : VLC_SUCCESS;
1321 void QVLCMenu::CreateAndConnect( QMenu *menu, const char *psz_var,
1322 QString text, QString help,
1323 int i_item_type, vlc_object_t *p_obj,
1324 vlc_value_t val, int i_val_type,
1327 QAction *action = FindActionWithVar( menu, psz_var );
1332 action = new QAction( text, menu );
1333 menu->addAction( action );
1337 action->setToolTip( help );
1338 action->setEnabled( p_obj != NULL );
1340 if( i_item_type == ITEM_CHECK )
1342 action->setCheckable( true );
1344 else if( i_item_type == ITEM_RADIO )
1346 action->setCheckable( true );
1348 currentGroup = new QActionGroup( menu );
1349 currentGroup->addAction( action );
1352 action->setChecked( checked );
1354 MenuItemData *itemData = new MenuItemData( THEDP->menusMapper, p_obj, i_val_type,
1356 CONNECT( action, triggered(), THEDP->menusMapper, map() );
1357 THEDP->menusMapper->setMapping( action, itemData );
1360 menu->addAction( action );
1363 void QVLCMenu::DoAction( QObject *data )
1365 MenuItemData *itemData = qobject_cast<MenuItemData *>( data );
1366 vlc_object_t *p_object = itemData->p_obj;
1367 if( p_object == NULL ) return;
1369 var_Set( p_object, itemData->psz_var, itemData->val );
1372 void QVLCMenu::updateRecents( intf_thread_t *p_intf )
1377 RecentsMRL* rmrl = RecentsMRL::getInstance( p_intf );
1378 QList<QString> l = rmrl->recents();
1380 recentsMenu->clear();
1383 action = recentsMenu->addAction( qtr(" - Empty - ") );
1384 action->setEnabled( false );
1388 for( int i = 0; i < l.size(); ++i )
1390 action = recentsMenu->addAction(
1391 QString( "&%1: " ).arg( i + 1 ) + l.at( i ),
1394 rmrl->signalMapper->setMapping( action, l.at( i ) );
1397 recentsMenu->addSeparator();
1398 recentsMenu->addAction( qtr("&Clear"), rmrl, SLOT( clear() ) );