1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright © 2006-2008 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 */
47 #include <QActionGroup>
48 #include <QSignalMapper>
49 #include <QSystemTrayIcon>
53 This file defines the main menus and the pop-up menu (right-click menu)
54 and the systray menu (in that order in the file)
56 There are 3 menus that have to be rebuilt everytime there are called:
57 Audio, Video, Navigation
58 3 functions are building those menus: AudioMenu, VideoMenu, NavigMenu
59 and 3 functions associated are collecting the objects :
60 InputAutoMenuBuilder, AudioAutoMenuBuilder, VideoAutoMenuBuilder.
62 A QSignalMapper decides when to rebuild those menus cf MenuFunc in the .hpp
63 Just before one of those menus are aboutToShow(), they are rebuild.
73 static QActionGroup *currentGroup;
75 /* HACK for minimalView to go around a Qt bug/feature
76 * that doesn't update the QAction checked state when QMenu is hidden */
77 QAction *QVLCMenu::minimalViewAction = NULL;
79 QMenu *QVLCMenu::recentsMenu = NULL;
81 /****************************************************************************
83 ****************************************************************************
84 * Add static entries to DP in menus
85 ***************************************************************************/
86 void addDPStaticEntry( QMenu *menu,
91 const char *shortcut = NULL )
93 QAction *action = NULL;
94 if( !EMPTY_STR( icon ) > 0 )
96 if( !EMPTY_STR( shortcut ) > 0 )
97 action = menu->addAction( QIcon( icon ), text, THEDP,
98 member, qtr( shortcut ) );
100 action = menu->addAction( QIcon( icon ), text, THEDP, member );
104 if( !EMPTY_STR( shortcut ) > 0 )
105 action = menu->addAction( text, THEDP, member, qtr( shortcut ) );
107 action = menu->addAction( text, THEDP, member );
109 action->setData( "_static_" );
112 void EnableDPStaticEntries( QMenu *menu, bool enable = true )
117 foreach( action, menu->actions() )
119 if( action->data().toString() == "_static_" )
120 action->setEnabled( enable );
125 * \return Number of static entries
127 int DeleteNonStaticEntries( QMenu *menu )
133 foreach( action, menu->actions() )
135 if( action->data().toString() != "_static_" )
146 void addMIMStaticEntry( intf_thread_t *p_intf,
153 if( strlen( icon ) > 0 )
155 QAction *action = menu->addAction( text, THEMIM, member );
156 action->setIcon( QIcon( icon ) );
160 menu->addAction( text, THEMIM, member );
164 /*****************************************************************************
165 * Definitions of variables for the dynamic menus
166 *****************************************************************************/
167 #define PUSH_VAR( var ) varnames.push_back( var ); \
168 objects.push_back( VLC_OBJECT(p_object) )
170 #define PUSH_INPUTVAR( var ) varnames.push_back( var ); \
171 objects.push_back( VLC_OBJECT(p_input) );
173 #define PUSH_SEPARATOR if( objects.size() != i_last_separator ) { \
174 objects.push_back( 0 ); varnames.push_back( "" ); \
175 i_last_separator = objects.size(); }
177 static int InputAutoMenuBuilder( vlc_object_t *p_object,
178 vector<vlc_object_t *> &objects,
179 vector<const char *> &varnames )
181 PUSH_VAR( "bookmark" );
183 PUSH_VAR( "chapter" );
184 PUSH_VAR( "program" );
185 PUSH_VAR( "navigation" );
186 PUSH_VAR( "dvd_menus" );
190 static int VideoAutoMenuBuilder( vlc_object_t *p_object,
191 input_thread_t *p_input,
192 vector<vlc_object_t *> &objects,
193 vector<const char *> &varnames )
195 PUSH_INPUTVAR( "video-es" );
196 PUSH_INPUTVAR( "spu-es" );
197 PUSH_VAR( "fullscreen" );
199 PUSH_VAR( "deinterlace" );
200 PUSH_VAR( "aspect-ratio" );
202 PUSH_VAR( "video-on-top" );
204 PUSH_VAR( "directx-wallpaper" );
206 PUSH_VAR( "video-snapshot" );
208 /* Special case for postproc */
211 /* p_object is the vout, so the decoder is our parent and the
212 * postproc filter one of the decoder's children */
213 vlc_object_t *p_dec = (vlc_object_t *)
214 vlc_object_find( p_object, VLC_OBJECT_DECODER,
218 vlc_object_t *p_pp = (vlc_object_t *)
219 vlc_object_find_name( p_dec, "postproc",
224 PUSH_VAR( "postproc-q" );
225 vlc_object_release( p_pp );
228 vlc_object_release( p_dec );
234 static int AudioAutoMenuBuilder( vlc_object_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-device" );
241 PUSH_VAR( "audio-channels" );
242 PUSH_VAR( "visual" );
246 static QAction * FindActionWithVar( QMenu *menu, const char *psz_var )
249 foreach( action, menu->actions() )
251 if( action->data().toString() == psz_var )
257 /*****************************************************************************
260 *****************************************************************************/
262 #define BAR_ADD( func, title ) { \
263 QMenu *_menu = func; _menu->setTitle( title ); bar->addMenu( _menu ); }
265 #define BAR_DADD( func, title, id ) { \
266 QMenu *_menu = func; _menu->setTitle( title ); bar->addMenu( _menu ); \
267 MenuFunc *f = new MenuFunc( _menu, id ); \
268 CONNECT( _menu, aboutToShow(), THEDP->menusUpdateMapper, map() ); \
269 THEDP->menusUpdateMapper->setMapping( _menu, f ); }
271 #define ACT_ADD( _menu, val, title ) { \
272 QAction *_action = new QAction( title, _menu ); _action->setData( val ); \
273 _menu->addAction( _action ); }
276 * Main Menu Bar Creation
278 void QVLCMenu::createMenuBar( MainInterface *mi,
279 intf_thread_t *p_intf,
280 bool visual_selector_enabled )
282 /* QMainWindows->menuBar()
283 gives the QProcess::destroyed timeout issue on Cleanlooks style with
284 setDesktopAware set to false */
285 QMenuBar *bar = mi->menuBar();
286 BAR_ADD( FileMenu( p_intf ), qtr( "&Media" ) );
288 BAR_DADD( AudioMenu( p_intf, NULL ), qtr( "&Audio" ), 1 );
289 BAR_DADD( VideoMenu( p_intf, NULL ), qtr( "&Video" ), 2 );
290 BAR_DADD( NavigMenu( p_intf, NULL ), qtr( "P&layback" ), 3 );
292 BAR_ADD( ToolsMenu( p_intf ), qtr( "&Tools" ) );
293 BAR_ADD( ViewMenu( p_intf, NULL, mi, visual_selector_enabled, true ),
296 BAR_ADD( HelpMenu( NULL ), qtr( "&Help" ) );
302 * Media ( File ) Menu
303 * Opening, streaming and quit
305 QMenu *QVLCMenu::FileMenu( intf_thread_t *p_intf )
307 QMenu *menu = new QMenu();
309 addDPStaticEntry( menu, qtr( "&Open File..." ), "",
311 ":/file-asym", SLOT( simpleOpenDialog() ), "Ctrl+O" );
312 addDPStaticEntry( menu, qtr( "Advanced Open File..." ), "",
313 ":/file-asym", SLOT( openFileDialog() ), "" );
315 ":/file-asym", SLOT( openFileDialog() ), "Ctrl+0" );
317 addDPStaticEntry( menu, qtr( I_OPEN_FOLDER ), "",
318 ":/folder-grey", SLOT( PLOpenDir() ), "Ctrl+F" );
319 addDPStaticEntry( menu, qtr( "Open &Disc..." ), "",
320 ":/disc", SLOT( openDiscDialog() ), "Ctrl+D" );
321 addDPStaticEntry( menu, qtr( "Open &Network..." ), "",
322 ":/network", SLOT( openNetDialog() ), "Ctrl+N" );
323 addDPStaticEntry( menu, qtr( "Open &Capture Device..." ), "",
324 ":/capture-card", SLOT( openCaptureDialog() ),
327 menu->addSeparator();
329 recentsMenu = new QMenu( qtr( "Recently &Played" ), menu );
330 updateRecents( p_intf );
331 menu->addMenu( recentsMenu );
332 menu->addSeparator();
334 addDPStaticEntry( menu, qtr( "Conve&rt / Save..." ), "", "",
335 SLOT( openAndTranscodingDialogs() ), "Ctrl+R" );
336 addDPStaticEntry( menu, qtr( "&Streaming..." ), "",
337 ":/stream", SLOT( openAndStreamingDialogs() ),
339 menu->addSeparator();
341 addDPStaticEntry( menu, qtr( "&Quit" ) , "",
342 ":/quit", SLOT( quit() ), "Ctrl+Q" );
346 /* Playlist/MediaLibrary Control */
347 QMenu *QVLCMenu::ToolsMenu( intf_thread_t *p_intf )
349 QMenu *menu = new QMenu();
351 addDPStaticEntry( menu, qtr( I_MENU_EXT ), "", ":/settings",
352 SLOT( extendedDialog() ), "Ctrl+E" );
353 addDPStaticEntry( menu, qtr( I_MENU_MSG ), "",
354 ":/messages", SLOT( messagesDialog() ),
356 addDPStaticEntry( menu, qtr( "Plugins and extensions" ), "",
357 "", SLOT( pluginDialog() ),
359 addDPStaticEntry( menu, qtr( I_MENU_INFO ) , "", ":/info",
360 SLOT( mediaInfoDialog() ), "Ctrl+I" );
361 addDPStaticEntry( menu, qtr( I_MENU_CODECINFO ) , "",
362 ":/info", SLOT( mediaCodecDialog() ), "Ctrl+J" );
363 addDPStaticEntry( menu, qtr( I_MENU_BOOKMARK ), "","",
364 SLOT( bookmarksDialog() ), "Ctrl+B" );
366 addDPStaticEntry( menu, qtr( I_MENU_VLM ), "", "", SLOT( vlmDialog() ),
369 menu->addSeparator();
371 addDPStaticEntry( menu, qtr( "Customi&ze Interface..." ), "",
372 ":/preferences", SLOT( toolbarDialog() ), "" );
373 addDPStaticEntry( menu, qtr( "&Preferences..." ), "",
374 ":/preferences", SLOT( prefsDialog() ), "Ctrl+P" );
381 * This is kept in the same menu for now, but could change if it gets much
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,
391 QMenu *menu = new QMenu( current );
395 menu->addAction( QIcon( ":/playlist_menu" ), qtr( "Play&list..." ),
396 mi, SLOT( togglePlaylist() ), qtr( "Ctrl+L" ) );
397 act->setData( "_static_" );
399 menu->addMenu( SDMenu( p_intf ) );
400 menu->addSeparator();
402 addDPStaticEntry( menu, qtr( I_PL_LOAD ), "", "", SLOT( openAPlaylist() ),
404 addDPStaticEntry( menu, qtr( I_PL_SAVE ), "", "", SLOT( saveAPlaylist() ),
406 /*menu->addSeparator();
407 menu->addAction( qtr( "Undock from Interface" ), mi,
408 SLOT( undockPlaylist() ), qtr( "Ctrl+U" ) );*/
411 menu->addSeparator();
415 QMenu *intfmenu = InterfacesMenu( p_intf, menu );
416 MenuFunc *f = new MenuFunc( intfmenu, 4 );
417 CONNECT( intfmenu, aboutToShow(), THEDP->menusUpdateMapper, map() );
418 THEDP->menusUpdateMapper->setMapping( intfmenu, f );
419 menu->addSeparator();
424 QAction *action = menu->addAction( qtr( "Mi&nimal View" ), mi,
425 SLOT( toggleMinimalView() ), qtr( "Ctrl+H" ) );
426 action->setCheckable( true );
427 action->setData( "_static_" );
428 if( mi->getControlsVisibilityStatus() & CONTROLS_VISIBLE )
429 action->setChecked( true );
430 minimalViewAction = action; /* HACK for minimalView */
432 /* FullScreen View */
433 action = menu->addAction( qtr( "&Fullscreen Interface" ), mi,
434 SLOT( toggleFullScreen() ), QString( "F11" ) );
435 action->setCheckable( true );
436 action->setData( "_static_" );
438 /* Advanced Controls */
439 action = menu->addAction( qtr( "&Advanced Controls" ), mi,
440 SLOT( toggleAdvanced() ) );
441 action->setCheckable( true );
442 action->setData( "_static_" );
443 if( mi->getControlsVisibilityStatus() & CONTROLS_ADVANCED )
444 action->setChecked( true );
445 #if 0 /* For Visualisations. Not yet working */
446 adv = menu->addAction( qtr( "Visualizations selector" ),
447 mi, SLOT( visual() ) );
448 adv->setCheckable( true );
449 if( visual_selector_enabled ) adv->setChecked( true );
453 menu->addSeparator();
459 * Interface Sub-Menu, to list extras interface and skins
461 QMenu *QVLCMenu::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
463 vector<vlc_object_t *> objects;
464 vector<const char *> varnames;
465 /** \todo add "switch to XXX" */
466 varnames.push_back( "intf-add" );
467 objects.push_back( VLC_OBJECT(p_intf) );
469 return Populate( p_intf, current, varnames, objects );
475 QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QMenu * current )
477 vector<vlc_object_t *> objects;
478 vector<const char *> varnames;
479 vlc_object_t *p_aout;
480 input_thread_t *p_input;
482 if( !current ) current = new QMenu();
484 if( current->isEmpty() )
486 ACT_ADD( current, "audio-es", qtr( "Audio &Track" ) );
487 ACT_ADD( current, "audio-device", qtr( "Audio &Device" ) );
488 ACT_ADD( current, "audio-channels", qtr( "Audio &Channels" ) );
489 current->addSeparator();
490 ACT_ADD( current, "visual", qtr( "&Visualizations" ) );
493 p_input = THEMIM->getInput();
495 vlc_object_hold( p_input );
496 p_aout = ( vlc_object_t * ) vlc_object_find( p_intf,
500 AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
503 vlc_object_release( p_aout );
505 vlc_object_release( p_input );
507 return Populate( p_intf, current, varnames, objects );
512 * Subtitles are part of Video.
514 QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current )
516 vlc_object_t *p_vout;
517 input_thread_t *p_input;
518 vector<vlc_object_t *> objects;
519 vector<const char *> varnames;
521 if( !current ) current = new QMenu();
523 if( current->isEmpty() )
525 ACT_ADD( current, "video-es", qtr( "Video &Track" ) );
528 QMenu *submenu = new QMenu( qtr( "&Subtitles Track" ), current );
529 action = current->addMenu( submenu );
530 action->setData( "spu-es" );
531 addDPStaticEntry( submenu, qtr( "Open File..." ), "", "",
532 SLOT( loadSubtitlesFile() ) );
533 submenu->addSeparator();
535 ACT_ADD( current, "fullscreen", qtr( "&Fullscreen" ) );
536 ACT_ADD( current, "zoom", qtr( "&Zoom" ) );
537 ACT_ADD( current, "deinterlace", qtr( "&Deinterlace" ) );
538 ACT_ADD( current, "aspect-ratio", qtr( "&Aspect Ratio" ) );
539 ACT_ADD( current, "crop", qtr( "&Crop" ) );
540 ACT_ADD( current, "video-on-top", qtr( "Always &On Top" ) );
542 ACT_ADD( current, "directx-wallpaper", qtr( "DirectX Wallpaper" ) );
544 ACT_ADD( current, "video-snapshot", qtr( "Sna&pshot" ) );
545 ACT_ADD( current, "postproc-q", qtr( "Post processing" ) );
548 p_input = THEMIM->getInput();
550 vlc_object_hold( p_input );
551 p_vout = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_VOUT,
554 VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
557 vlc_object_release( p_vout );
559 vlc_object_release( p_input );
561 return Populate( p_intf, current, varnames, objects );
566 * For DVD, MP4, MOV and other chapter based format
568 QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *menu )
570 vlc_object_t *p_object;
571 vector<vlc_object_t *> objects;
572 vector<const char *> varnames;
574 if( !menu ) menu = new QMenu();
576 if( menu->isEmpty() )
578 addDPStaticEntry( menu, qtr( I_MENU_GOTOTIME ), "","",
579 SLOT( gotoTimeDialog() ), "Ctrl+T" );
580 menu->addSeparator();
582 ACT_ADD( menu, "bookmark", qtr( "&Bookmarks" ) );
583 ACT_ADD( menu, "title", qtr( "T&itle" ) );
584 ACT_ADD( menu, "chapter", qtr( "&Chapter" ) );
585 ACT_ADD( menu, "program", qtr( "&Program" ) );
586 ACT_ADD( menu, "navigation", qtr( "&Navigation" ) );
589 p_object = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_INPUT,
591 InputAutoMenuBuilder( p_object, objects, varnames );
592 PUSH_VAR( "prev-title" );
593 PUSH_VAR( "next-title" );
594 PUSH_VAR( "prev-chapter" );
595 PUSH_VAR( "next-chapter" );
596 EnableDPStaticEntries( menu, ( p_object != NULL ) );
599 vlc_object_release( p_object );
601 return Populate( p_intf, menu, varnames, objects, true );
605 * Service Discovery SubMenu
607 QMenu *QVLCMenu::SDMenu( intf_thread_t *p_intf )
609 QMenu *menu = new QMenu();
610 menu->setTitle( qtr( I_PL_SD ) );
611 char **ppsz_longnames;
612 char **ppsz_names = services_discovery_GetServicesNames( p_intf,
617 char **ppsz_name = ppsz_names, **ppsz_longname = ppsz_longnames;
618 for( ; *ppsz_name; ppsz_name++, ppsz_longname++ )
620 QAction *a = new QAction( qfu( *ppsz_longname ), menu );
621 a->setCheckable( true );
622 if( playlist_IsServicesDiscoveryLoaded( THEPL, *ppsz_name ) )
623 a->setChecked( true );
624 CONNECT( a , triggered(), THEDP->SDMapper, map() );
625 THEDP->SDMapper->setMapping( a, QString( *ppsz_name ) );
626 menu->addAction( a );
628 if( !strcmp( *ppsz_name, "podcast" ) )
630 QAction *b = new QAction( qtr( "Configure podcasts..." ), menu );
631 //b->setEnabled( a->isChecked() );
632 menu->addAction( b );
633 CONNECT( b, triggered(), THEDP, podcastConfigureDialog() );
636 free( *ppsz_longname );
639 free( ppsz_longnames );
645 QMenu *QVLCMenu::HelpMenu( QMenu *current )
647 QMenu *menu = new QMenu( current );
648 addDPStaticEntry( menu, qtr( "&Help..." ) , "",
649 ":/help", SLOT( helpDialog() ), "F1" );
651 addDPStaticEntry( menu, qtr( "Check for &Updates..." ) , "", "",
652 SLOT( updateDialog() ), "");
654 menu->addSeparator();
655 addDPStaticEntry( menu, qtr( I_MENU_ABOUT ), "", ":/info",
656 SLOT( aboutDialog() ), "Shift+F1" );
660 /*****************************************************************************
661 * Popup menus - Right Click menus *
662 *****************************************************************************/
663 #define POPUP_BOILERPLATE \
664 unsigned int i_last_separator = 0; \
665 vector<vlc_object_t *> objects; \
666 vector<const char *> varnames; \
667 input_thread_t *p_input = THEMIM->getInput();
669 #define CREATE_POPUP \
670 Populate( p_intf, menu, varnames, objects ); \
671 p_intf->p_sys->p_popup_menu = menu; \
672 menu->popup( QCursor::pos() ); \
673 p_intf->p_sys->p_popup_menu = NULL; \
674 i_last_separator = 0;
676 void QVLCMenu::PopupMenuControlEntries( QMenu *menu,
677 intf_thread_t *p_intf,
678 input_thread_t *p_input )
683 var_Get( p_input, "state", &val );
684 if( val.i_int == PLAYING_S )
685 addMIMStaticEntry( p_intf, menu, qtr( "Pause" ), "",
686 ":/pause", SLOT( togglePlayPause() ) );
688 addMIMStaticEntry( p_intf, menu, qtr( "Play" ), "",
689 ":/play", SLOT( togglePlayPause() ) );
691 else if( THEPL->items.i_size )
692 addMIMStaticEntry( p_intf, menu, qtr( "Play" ), "",
693 ":/play", SLOT( togglePlayPause() ) );
695 addDPStaticEntry( menu, qtr( "Play" ), "",
696 ":/play", SLOT( openDialog() ) );
698 addMIMStaticEntry( p_intf, menu, qtr( "Stop" ), "",
699 ":/stop", SLOT( stop() ) );
700 addMIMStaticEntry( p_intf, menu, qtr( "Previous" ), "",
701 ":/previous", SLOT( prev() ) );
702 addMIMStaticEntry( p_intf, menu, qtr( "Next" ), "",
703 ":/next", SLOT( next() ) );
706 void QVLCMenu::PopupMenuStaticEntries( intf_thread_t *p_intf, QMenu *menu )
709 QMenu *toolsmenu = ToolsMenu( p_intf, menu, false, true );
710 toolsmenu->setTitle( qtr( "Tools" ) );
711 menu->addMenu( toolsmenu );
714 QMenu *openmenu = new QMenu( qtr( "Open" ), menu );
715 addDPStaticEntry( openmenu, qtr( "&Open File..." ), "",
716 ":/file-asym", SLOT( openFileDialog() ) );
717 addDPStaticEntry( openmenu, qtr( I_OPEN_FOLDER ), "",
718 ":/folder-grey", SLOT( PLOpenDir() ) );
719 addDPStaticEntry( openmenu, qtr( "Open &Disc..." ), "",
720 ":/disc", SLOT( openDiscDialog() ) );
721 addDPStaticEntry( openmenu, qtr( "Open &Network..." ), "",
722 ":/network", SLOT( openNetDialog() ) );
723 addDPStaticEntry( openmenu, qtr( "Open &Capture Device..." ), "",
724 ":/capture-card", SLOT( openCaptureDialog() ) );
725 menu->addMenu( openmenu );
727 menu->addSeparator();
729 QMenu *helpmenu = HelpMenu( menu );
730 helpmenu->setTitle( qtr( "Help" ) );
731 menu->addMenu( helpmenu );
734 addDPStaticEntry( menu, qtr( "Quit" ), "", ":/quit",
735 SLOT( quit() ), "Ctrl+Q" );
738 /* Video Tracks and Subtitles tracks */
739 void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf )
744 vlc_object_hold( p_input );
745 vlc_object_t *p_vout = ( vlc_object_t * )vlc_object_find( p_input,
746 VLC_OBJECT_VOUT, FIND_CHILD );
749 VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
750 vlc_object_release( p_vout );
752 vlc_object_release( p_input );
754 QMenu *menu = new QMenu();
759 void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf )
764 vlc_object_hold( p_input );
765 vlc_object_t *p_aout = ( vlc_object_t * )vlc_object_find( p_input,
766 VLC_OBJECT_AOUT, FIND_ANYWHERE );
767 AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
769 vlc_object_release( p_aout );
770 vlc_object_release( p_input );
772 QMenu *menu = new QMenu();
776 /* Navigation stuff, and general menus ( open ) */
777 void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf )
784 vlc_object_hold( p_input );
785 varnames.push_back( "audio-es" );
786 InputAutoMenuBuilder( VLC_OBJECT( p_input ), objects, varnames );
790 QMenu *menu = new QMenu();
791 Populate( p_intf, menu, varnames, objects );
793 menu->addSeparator();
794 PopupMenuControlEntries( menu, p_intf, p_input );
796 menu->addSeparator();
797 PopupMenuStaticEntries( p_intf, menu );
799 p_intf->p_sys->p_popup_menu = menu;
800 menu->popup( QCursor::pos() );
801 p_intf->p_sys->p_popup_menu = NULL;
804 /* Main Menu that sticks everything together */
805 void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show )
807 MainInterface *mi = p_intf->p_sys->p_mi;
810 /* Delete and recreate a popup if there is one */
811 if( p_intf->p_sys->p_popup_menu )
812 delete p_intf->p_sys->p_popup_menu;
814 QMenu *menu = new QMenu();
817 bool b_isFullscreen = false;
821 PopupMenuControlEntries( menu, p_intf, p_input );
822 menu->addSeparator();
826 vlc_object_t *p_vout = (vlc_object_t *)
827 vlc_object_find( p_input, VLC_OBJECT_VOUT, FIND_CHILD );
829 /* Add a fullscreen switch button */
833 var_Get( p_vout, "fullscreen", &val );
834 b_isFullscreen = !( !val.b_bool );
836 CreateAndConnect( menu, "fullscreen",
837 qtr( "Leave Fullscreen" ),"" , ITEM_NORMAL,
838 VLC_OBJECT(p_vout), val, VLC_VAR_BOOL,
840 vlc_object_release( p_vout );
843 menu->addSeparator();
845 vlc_object_hold( p_input );
846 InputAutoMenuBuilder( VLC_OBJECT( p_input ), objects, varnames );
847 vlc_object_release( p_input );
849 submenu = new QMenu( menu );
850 action = menu->addMenu( AudioMenu( p_intf, submenu ) );
851 action->setText( qtr( "&Audio" ) );
852 if( action->menu()->isEmpty() )
853 action->setEnabled( false );
855 submenu = new QMenu( menu );
856 action = menu->addMenu( VideoMenu( p_intf, submenu ) );
857 action->setText( qtr( "&Video" ) );
858 if( action->menu()->isEmpty() )
859 action->setEnabled( false );
861 submenu = new QMenu( menu );
862 action = menu->addMenu( NavigMenu( p_intf, submenu ) );
863 action->setText( qtr( "&Playback" ) );
864 if( action->menu()->isEmpty() )
865 action->setEnabled( false );
868 menu->addSeparator();
870 /* Add some special entries for windowed mode: Interface Menu */
871 if( !b_isFullscreen )
873 submenu = new QMenu( qtr( "Interface" ), menu );
876 submenu->addAction( QIcon( ":/playlist" ),
877 qtr( "Show Playlist" ), mi, SLOT( togglePlaylist() ) );
879 addDPStaticEntry( submenu, qtr( I_MENU_EXT ), "",
880 ":/settings", SLOT( extendedDialog() ) );
881 addDPStaticEntry( submenu, qtr( I_MENU_INFO ) , "", ":/info",
882 SLOT( mediaInfoDialog() ), "Ctrl+I" );
885 action = submenu->addAction( QIcon( "" ),
886 qtr( "Minimal View" ), mi, SLOT( toggleMinimalView() ) );
887 action->setCheckable( true );
888 action->setChecked( !( mi->getControlsVisibilityStatus() &
889 CONTROLS_VISIBLE ) );
890 action = submenu->addAction( QIcon( "" ),
891 qtr( "Toggle Fullscreen Interface" ),
892 mi, SLOT( toggleFullScreen() ) );
893 action->setCheckable( true );
894 action->setChecked( mi->isFullScreen() );
896 else /* We are using the skins interface.
897 If not, this entry will not show. */
899 addDPStaticEntry( submenu, qtr( "&Preferences..." ), "",
900 ":/preferences", SLOT( prefsDialog() ), "Ctrl+P" );
901 submenu->addSeparator();
904 vlc_object_t *p_object = ( vlc_object_t* )
905 vlc_object_find( p_intf, VLC_OBJECT_INTF, FIND_PARENT );
908 objects.push_back( p_object );
909 varnames.push_back( "intf-skins" );
910 Populate( p_intf, submenu, varnames, objects );
911 vlc_object_release( p_object );
915 msg_Dbg( p_intf, "could not find parent interface" );
918 menu->addMenu( submenu );
921 PopupMenuStaticEntries( p_intf, menu );
923 p_intf->p_sys->p_popup_menu = menu;
924 p_intf->p_sys->p_popup_menu->popup( QCursor::pos() );
928 // destroy popup if there is one
929 delete p_intf->p_sys->p_popup_menu;
930 p_intf->p_sys->p_popup_menu = NULL;
936 /************************************************************************
938 ************************************************************************/
940 void QVLCMenu::updateSystrayMenu( MainInterface *mi,
941 intf_thread_t *p_intf,
942 bool b_force_visible )
946 /* Get the systray menu and clean it */
947 QMenu *sysMenu = mi->getSysTrayMenu();
950 /* Hide / Show VLC and cone */
951 if( mi->isVisible() || b_force_visible )
953 sysMenu->addAction( QIcon( ":/vlc16.png" ),
954 qtr( "Hide VLC media player in taskbar" ), mi,
955 SLOT( toggleUpdateSystrayMenu() ) );
959 sysMenu->addAction( QIcon( ":/vlc16.png" ),
960 qtr( "Show VLC media player" ), mi,
961 SLOT( toggleUpdateSystrayMenu() ) );
964 sysMenu->addSeparator();
965 PopupMenuControlEntries( sysMenu, p_intf, p_input );
967 sysMenu->addSeparator();
968 addDPStaticEntry( sysMenu, qtr( "&Open Media" ), "",
969 ":/file-wide", SLOT( openFileDialog() ), "" );
970 addDPStaticEntry( sysMenu, qtr( "&Quit" ) , "",
971 ":/quit", SLOT( quit() ), "" );
974 mi->getSysTray()->setContextMenu( sysMenu );
978 #undef PUSH_SEPARATOR
980 /*************************************************************************
981 * Builders for automenus
982 *************************************************************************/
983 QMenu * QVLCMenu::Populate( intf_thread_t *p_intf,
985 vector< const char *> & varnames,
986 vector<vlc_object_t *> & objects,
989 QMenu *menu = current;
990 if( !menu ) menu = new QMenu();
992 /* Disable all non static entries */
994 foreach( p_action, menu->actions() )
996 if( p_action->data().toString() != "_static_" )
997 p_action->setEnabled( false );
1000 currentGroup = NULL;
1002 vlc_object_t *p_object;
1005 for( i = 0; i < ( int )objects.size() ; i++ )
1007 if( !varnames[i] || !*varnames[i] )
1009 menu->addSeparator();
1012 p_object = objects[i];
1014 UpdateItem( p_intf, menu, varnames[i], p_object, true );
1019 /*****************************************************************************
1021 *****************************************************************************/
1023 static bool IsMenuEmpty( const char *psz_var,
1024 vlc_object_t *p_object,
1025 bool b_root = true )
1027 vlc_value_t val, val_list;
1028 int i_type, i_result, i;
1030 /* Check the type of the object variable */
1031 i_type = var_Type( p_object, psz_var );
1033 /* Check if we want to display the variable */
1034 if( !( i_type & VLC_VAR_HASCHOICE ) ) return false;
1036 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
1037 if( val.i_int == 0 ) return true;
1039 if( ( i_type & VLC_VAR_TYPE ) != VLC_VAR_VARIABLE )
1041 if( val.i_int == 1 && b_root ) return true;
1045 /* Check children variables in case of VLC_VAR_VARIABLE */
1046 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
1051 for( i = 0, i_result = true; i < val_list.p_list->i_count; i++ )
1053 if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
1061 /* clean up everything */
1062 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, NULL );
1067 #define TEXT_OR_VAR qfu ( text.psz_string ? text.psz_string : psz_var )
1069 void QVLCMenu::UpdateItem( intf_thread_t *p_intf, QMenu *menu,
1070 const char *psz_var, vlc_object_t *p_object, bool b_submenu )
1072 vlc_value_t val, text;
1075 QAction *action = FindActionWithVar( menu, psz_var );
1077 DeleteNonStaticEntries( action->menu() );
1082 /* Check the type of the object variable */
1083 if( !strcmp( psz_var, "audio-es" )
1084 || !strcmp( psz_var, "video-es" )
1085 || !strcmp( psz_var, "postproc-q" ) )
1086 i_type = VLC_VAR_INTEGER | VLC_VAR_HASCHOICE;
1088 i_type = var_Type( p_object, psz_var );
1090 switch( i_type & VLC_VAR_TYPE )
1094 case VLC_VAR_VARIABLE:
1095 case VLC_VAR_STRING:
1096 case VLC_VAR_INTEGER:
1100 /* Variable doesn't exist or isn't handled */
1104 /* Make sure we want to display the variable */
1105 if( menu->isEmpty() && IsMenuEmpty( psz_var, p_object ) )
1108 /* Get the descriptive name of the variable */
1109 int i_ret = var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
1110 if( i_ret != VLC_SUCCESS )
1112 text.psz_string = NULL;
1117 action = new QAction( TEXT_OR_VAR, menu );
1118 menu->addAction( action );
1119 action->setData( psz_var );
1122 /* Some specific stuff */
1123 bool forceDisabled = false;
1124 if( !strcmp( psz_var, "spu-es" ) )
1126 vlc_object_t *p_vout = ( vlc_object_t* )( vlc_object_find( p_intf,
1127 VLC_OBJECT_VOUT, FIND_ANYWHERE ) );
1128 forceDisabled = ( p_vout == NULL );
1130 vlc_object_release( p_vout );
1133 if( i_type & VLC_VAR_HASCHOICE )
1135 /* Append choices menu */
1139 submenu = action->menu();
1142 submenu = new QMenu( menu );
1143 action->setMenu( submenu );
1147 CreateChoicesMenu( submenu, psz_var, p_object, true ) == 0 );
1149 action->setEnabled( false );
1152 CreateChoicesMenu( menu, psz_var, p_object, true );
1153 FREENULL( text.psz_string );
1157 switch( i_type & VLC_VAR_TYPE )
1160 var_Get( p_object, psz_var, &val );
1161 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_NORMAL,
1162 p_object, val, i_type );
1166 var_Get( p_object, psz_var, &val );
1167 val.b_bool = !val.b_bool;
1168 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_CHECK,
1169 p_object, val, i_type, !val.b_bool );
1172 FREENULL( text.psz_string );
1176 int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
1177 vlc_object_t *p_object, bool b_root )
1179 vlc_value_t val, val_list, text_list;
1182 /* Check the type of the object variable */
1183 i_type = var_Type( p_object, psz_var );
1185 /* Make sure we want to display the variable */
1186 if( submenu->isEmpty() && IsMenuEmpty( psz_var, p_object, b_root ) )
1187 return VLC_EGENERIC;
1189 switch( i_type & VLC_VAR_TYPE )
1193 case VLC_VAR_VARIABLE:
1194 case VLC_VAR_STRING:
1195 case VLC_VAR_INTEGER:
1199 /* Variable doesn't exist or isn't handled */
1200 return VLC_EGENERIC;
1203 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
1204 &val_list, &text_list ) < 0 )
1206 return VLC_EGENERIC;
1209 #define CURVAL val_list.p_list->p_values[i]
1210 #define CURTEXT text_list.p_list->p_values[i].psz_string
1212 for( i = 0; i < val_list.p_list->i_count; i++ )
1214 vlc_value_t another_val;
1216 QMenu *subsubmenu = new QMenu( submenu );
1218 switch( i_type & VLC_VAR_TYPE )
1220 case VLC_VAR_VARIABLE:
1221 CreateChoicesMenu( subsubmenu, CURVAL.psz_string, p_object, false );
1222 subsubmenu->setTitle( qfu( CURTEXT ? CURTEXT :CURVAL.psz_string ) );
1223 submenu->addMenu( subsubmenu );
1226 case VLC_VAR_STRING:
1227 var_Get( p_object, psz_var, &val );
1228 another_val.psz_string = strdup( CURVAL.psz_string );
1229 menutext = qfu( CURTEXT ? CURTEXT : another_val.psz_string );
1230 CreateAndConnect( submenu, psz_var, menutext, "", ITEM_RADIO,
1231 p_object, another_val, i_type,
1232 val.psz_string && !strcmp( val.psz_string, CURVAL.psz_string ) );
1234 free( val.psz_string );
1237 case VLC_VAR_INTEGER:
1238 var_Get( p_object, psz_var, &val );
1239 if( CURTEXT ) menutext = qfu( CURTEXT );
1240 else menutext.sprintf( "%d", CURVAL.i_int );
1241 CreateAndConnect( submenu, psz_var, menutext, "", ITEM_RADIO,
1242 p_object, CURVAL, i_type,
1243 CURVAL.i_int == val.i_int );
1247 var_Get( p_object, psz_var, &val );
1248 if( CURTEXT ) menutext = qfu( CURTEXT );
1249 else menutext.sprintf( "%.2f", CURVAL.f_float );
1250 CreateAndConnect( submenu, psz_var, menutext, "", ITEM_RADIO,
1251 p_object, CURVAL, i_type,
1252 CURVAL.f_float == val.f_float );
1259 currentGroup = NULL;
1261 /* clean up everything */
1262 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
1269 void QVLCMenu::CreateAndConnect( QMenu *menu, const char *psz_var,
1270 QString text, QString help,
1271 int i_item_type, vlc_object_t *p_obj,
1272 vlc_value_t val, int i_val_type,
1275 QAction *action = FindActionWithVar( menu, psz_var );
1278 action = new QAction( text, menu );
1279 menu->addAction( action );
1282 action->setToolTip( help );
1283 action->setEnabled( p_obj != NULL );
1285 if( i_item_type == ITEM_CHECK )
1287 action->setCheckable( true );
1289 else if( i_item_type == ITEM_RADIO )
1291 action->setCheckable( true );
1293 currentGroup = new QActionGroup( menu );
1294 currentGroup->addAction( action );
1297 action->setChecked( checked );
1299 MenuItemData *itemData = new MenuItemData( THEDP->menusMapper, p_obj, i_val_type,
1301 CONNECT( action, triggered(), THEDP->menusMapper, map() );
1302 THEDP->menusMapper->setMapping( action, itemData );
1303 menu->addAction( action );
1306 void QVLCMenu::DoAction( intf_thread_t *p_intf, QObject *data )
1308 MenuItemData *itemData = qobject_cast<MenuItemData *>( data );
1309 vlc_object_t *p_object = itemData->p_obj;
1310 if( p_object == NULL ) return;
1312 var_Set( p_object, itemData->psz_var, itemData->val );
1315 void QVLCMenu::updateRecents( intf_thread_t *p_intf )
1320 RecentsMRL* rmrl = RecentsMRL::getInstance( p_intf );
1321 QList<QString> l = rmrl->recents();
1323 recentsMenu->clear();
1326 action = recentsMenu->addAction( " - Empty - " );
1327 action->setEnabled( false );
1331 for( int i = 0; i < l.size(); ++i )
1333 action = recentsMenu->addAction(
1334 QString( "&%1: " ).arg( i + 1 ) + l.at( i ),
1337 rmrl->signalMapper->setMapping( action, l.at( i ) );
1340 recentsMenu->addSeparator();
1341 recentsMenu->addAction( "&Clear", rmrl, SLOT( clear() ) );