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_common.h>
36 #include <vlc_intf_strings.h>
38 #include "main_interface.hpp"
40 #include "dialogs_provider.hpp"
41 #include "input_manager.hpp"
46 #include <QActionGroup>
47 #include <QSignalMapper>
48 #include <QSystemTrayIcon>
51 This file defines the main menus and the pop-up menu (right-click menu)
52 and the systray menu (in that order in the file)
54 There are 3 menus that have to be rebuilt everytime there are called:
55 Audio, Video, Navigation
56 3 functions are building those menus: AudioMenu, VideoMenu, NavigMenu
57 and 3 functions associated are collecting the objects :
58 InputAutoMenuBuilder, AudioAutoMenuBuilder, VideoAutoMenuBuilder.
60 A QSignalMapper decides when to rebuild those menus cf MenuFunc in the .hpp
61 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 // Add static entries to menus
80 void addDPStaticEntry( QMenu *menu,
85 const char *shortcut = NULL )
87 QAction *action = NULL;
88 if( !EMPTY_STR( icon ) > 0 )
90 if( !EMPTY_STR( shortcut ) > 0 )
91 action = menu->addAction( QIcon( icon ), text, THEDP,
92 member, qtr( shortcut ) );
94 action = menu->addAction( QIcon( icon ), text, THEDP, member );
98 if( !EMPTY_STR( shortcut ) > 0 )
99 action = menu->addAction( text, THEDP, member, qtr( shortcut ) );
101 action = menu->addAction( text, THEDP, member );
103 action->setData( "_static_" );
106 void addMIMStaticEntry( intf_thread_t *p_intf,
113 if( strlen( icon ) > 0 )
115 QAction *action = menu->addAction( text, THEMIM, member );
116 action->setIcon( QIcon( icon ) );
120 menu->addAction( text, THEMIM, member );
124 void EnableDPStaticEntries( QMenu *menu, bool enable = true )
130 foreach( action, menu->actions() )
132 if( action->data().toString() == "_static_" )
133 action->setEnabled( enable );
138 * \return Number of static entries
140 int DeleteNonStaticEntries( QMenu *menu )
146 foreach( action, menu->actions() )
148 if( action->data().toString() != "_static_" )
155 /*****************************************************************************
156 * Definitions of variables for the dynamic menus
157 *****************************************************************************/
158 #define PUSH_VAR( var ) varnames.push_back( var ); \
159 objects.push_back( p_object ? p_object->i_object_id : 0 )
161 #define PUSH_INPUTVAR( var ) varnames.push_back( var ); \
162 objects.push_back( p_input ? p_input->i_object_id : 0 );
164 #define PUSH_SEPARATOR if( objects.size() != i_last_separator ) { \
165 objects.push_back( 0 ); varnames.push_back( "" ); \
166 i_last_separator = objects.size(); }
168 static int InputAutoMenuBuilder( vlc_object_t *p_object,
169 vector<int> &objects,
170 vector<const char *> &varnames )
172 PUSH_VAR( "bookmark" );
174 PUSH_VAR( "chapter" );
175 PUSH_VAR( "program" );
176 PUSH_VAR( "navigation" );
177 PUSH_VAR( "dvd_menus" );
181 static int VideoAutoMenuBuilder( vlc_object_t *p_object,
182 input_thread_t *p_input,
183 vector<int> &objects,
184 vector<const char *> &varnames )
186 PUSH_INPUTVAR( "video-es" );
187 PUSH_INPUTVAR( "spu-es" );
188 PUSH_VAR( "fullscreen" );
190 PUSH_VAR( "deinterlace" );
191 PUSH_VAR( "aspect-ratio" );
193 PUSH_VAR( "video-on-top" );
195 PUSH_VAR( "directx-wallpaper" );
197 PUSH_VAR( "video-snapshot" );
201 vlc_object_t *p_dec_obj = ( vlc_object_t * )vlc_object_find( p_object,
206 vlc_object_t *p_object = p_dec_obj;
207 PUSH_VAR( "ffmpeg-pp-q" );
208 vlc_object_release( p_dec_obj );
214 static int AudioAutoMenuBuilder( vlc_object_t *p_object,
215 input_thread_t *p_input,
216 vector<int> &objects,
217 vector<const char *> &varnames )
219 PUSH_INPUTVAR( "audio-es" );
220 PUSH_VAR( "audio-device" );
221 PUSH_VAR( "audio-channels" );
222 PUSH_VAR( "visual" );
226 static QAction * FindActionWithVar( QMenu *menu, const char *psz_var )
229 foreach( action, menu->actions() )
231 if( action->data().toString() == psz_var )
237 /*****************************************************************************
240 *****************************************************************************/
242 #define BAR_ADD( func, title ) { \
243 QMenu *_menu = func; _menu->setTitle( title ); bar->addMenu( _menu ); }
245 #define BAR_DADD( func, title, id ) { \
246 QMenu *_menu = func; _menu->setTitle( title ); bar->addMenu( _menu ); \
247 MenuFunc *f = new MenuFunc( _menu, id ); \
248 CONNECT( _menu, aboutToShow(), THEDP->menusUpdateMapper, map() ); \
249 THEDP->menusUpdateMapper->setMapping( _menu, f ); }
251 #define ACT_ADD( _menu, val, title ) { \
252 QAction *_action = new QAction( title, _menu ); _action->setData( val ); \
253 _menu->addAction( _action ); }
256 * Main Menu Bar Creation
258 void QVLCMenu::createMenuBar( MainInterface *mi,
259 intf_thread_t *p_intf,
260 bool visual_selector_enabled )
262 /* QMainWindows->menuBar()
263 gives the QProcess::destroyed timeout issue on Cleanlooks style with
264 setDesktopAware set to false */
265 QMenuBar *bar = mi->menuBar();
266 BAR_ADD( FileMenu(), qtr( "&Media" ) );
268 BAR_DADD( AudioMenu( p_intf, NULL ), qtr( "&Audio" ), 1 );
269 BAR_DADD( VideoMenu( p_intf, NULL ), qtr( "&Video" ), 2 );
270 BAR_DADD( NavigMenu( p_intf, NULL ), qtr( "P&layback" ), 3 );
272 BAR_ADD( PlaylistMenu( p_intf, mi ), qtr( "&Playlist" ) );
273 BAR_ADD( ToolsMenu( p_intf, NULL, mi, visual_selector_enabled, true ),
276 BAR_ADD( HelpMenu( NULL ), qtr( "&Help" ) );
282 * Media ( File ) Menu
283 * Opening, streaming and quit
285 QMenu *QVLCMenu::FileMenu()
287 QMenu *menu = new QMenu();
289 addDPStaticEntry( menu, qtr( "&Open File..." ), "",
290 ":/file-asym", SLOT( openFileDialog() ), "Ctrl+O" );
291 addDPStaticEntry( menu, qtr( I_OPEN_FOLDER ), "",
292 ":/folder-grey", SLOT( PLOpenDir() ), "Ctrl+F" );
293 addDPStaticEntry( menu, qtr( "Open &Disc..." ), "",
294 ":/disc", SLOT( openDiscDialog() ), "Ctrl+D" );
295 addDPStaticEntry( menu, qtr( "Open &Network..." ), "",
296 ":/network", SLOT( openNetDialog() ), "Ctrl+N" );
297 addDPStaticEntry( menu, qtr( "Open &Capture Device..." ), "",
298 ":/capture-card", SLOT( openCaptureDialog() ),
300 menu->addSeparator();
302 addDPStaticEntry( menu, qtr( "Conve&rt / Save..." ), "", "",
303 SLOT( openThenTranscodingDialogs() ), "Ctrl+R" );
304 addDPStaticEntry( menu, qtr( "&Streaming..." ), "",
305 ":/stream", SLOT( openThenStreamingDialogs() ),
307 menu->addSeparator();
309 addDPStaticEntry( menu, qtr( "&Quit" ) , "",
310 ":/quit", SLOT( quit() ), "Ctrl+Q" );
314 /* Playlist/MediaLibrary Control */
315 QMenu *QVLCMenu::PlaylistMenu( intf_thread_t *p_intf, MainInterface *mi )
317 QMenu *menu = new QMenu();
318 menu->addMenu( SDMenu( p_intf ) );
319 menu->addAction( QIcon( ":/playlist_menu" ),
320 qtr( "Show P&laylist" ), mi, SLOT( togglePlaylist() ) );
321 menu->addSeparator();
323 addDPStaticEntry( menu, qtr( I_PL_LOAD ), "", "", SLOT( openAPlaylist() ),
325 addDPStaticEntry( menu, qtr( I_PL_SAVE ), "", "", SLOT( saveAPlaylist() ),
327 /*menu->addSeparator();
328 menu->addAction( qtr( "Undock from Interface" ), mi,
329 SLOT( undockPlaylist() ), qtr( "Ctrl+U" ) );*/
335 * This is kept in the same menu for now, but could change if it gets much
337 * This menu can be an interface menu but also a right click menu.
339 QMenu *QVLCMenu::ToolsMenu( intf_thread_t *p_intf,
342 bool visual_selector_enabled,
345 QMenu *menu = new QMenu( current );
349 menu->addAction( QIcon( ":/playlist_menu" ), qtr( "Play&list..." ),
350 mi, SLOT( togglePlaylist() ), qtr( "Ctrl+L" ) );
351 act->setData( "_static_" );
353 addDPStaticEntry( menu, qtr( I_MENU_EXT ), "", ":/settings",
354 SLOT( extendedDialog() ), "Ctrl+E" );
356 menu->addSeparator();
360 QMenu *intfmenu = InterfacesMenu( p_intf, menu );
361 MenuFunc *f = new MenuFunc( intfmenu, 4 );
362 CONNECT( intfmenu, aboutToShow(), THEDP->menusUpdateMapper, map() );
363 THEDP->menusUpdateMapper->setMapping( intfmenu, f );
364 menu->addSeparator();
369 QAction *action = menu->addAction( qtr( "Mi&nimal View" ), mi,
370 SLOT( toggleMinimalView() ), qtr( "Ctrl+H" ) );
371 action->setCheckable( true );
372 action->setData( "_static_" );
373 if( mi->getControlsVisibilityStatus() & CONTROLS_VISIBLE )
374 action->setChecked( true );
375 minimalViewAction = action; /* HACK for minimalView */
377 /* FullScreen View */
378 action = menu->addAction( qtr( "&Fullscreen Interface" ), mi,
379 SLOT( toggleFullScreen() ), QString( "F11" ) );
380 action->setCheckable( true );
381 action->setData( "_static_" );
383 /* Advanced Controls */
384 action = menu->addAction( qtr( "&Advanced Controls" ), mi,
385 SLOT( toggleAdvanced() ) );
386 action->setCheckable( true );
387 action->setData( "_static_" );
388 if( mi->getControlsVisibilityStatus() & CONTROLS_ADVANCED )
389 action->setChecked( true );
390 #if 0 /* For Visualisations. Not yet working */
391 adv = menu->addAction( qtr( "Visualizations selector" ),
392 mi, SLOT( visual() ) );
393 adv->setCheckable( true );
394 if( visual_selector_enabled ) adv->setChecked( true );
398 menu->addSeparator();
400 addDPStaticEntry( menu, qtr( I_MENU_MSG ), "",
401 ":/messages", SLOT( messagesDialog() ),
403 addDPStaticEntry( menu, qtr( I_MENU_INFO ) , "", ":/info",
404 SLOT( mediaInfoDialog() ), "Ctrl+I" );
405 addDPStaticEntry( menu, qtr( I_MENU_CODECINFO ) , "",
406 ":/info", SLOT( mediaCodecDialog() ), "Ctrl+J" );
407 addDPStaticEntry( menu, qtr( I_MENU_BOOKMARK ), "","",
408 SLOT( bookmarksDialog() ), "Ctrl+B" );
410 addDPStaticEntry( menu, qtr( I_MENU_VLM ), "", "", SLOT( vlmDialog() ),
414 menu->addSeparator();
415 addDPStaticEntry( menu, qtr( "&Preferences..." ), "",
416 ":/preferences", SLOT( prefsDialog() ), "Ctrl+P" );
421 * Interface Sub-Menu, to list extras interface and skins
423 QMenu *QVLCMenu::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
426 vector<const char *> varnames;
427 /** \todo add "switch to XXX" */
428 varnames.push_back( "intf-add" );
429 objects.push_back( p_intf->i_object_id );
431 return Populate( p_intf, current, varnames, objects );
437 QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QMenu * current )
440 vector<const char *> varnames;
441 vlc_object_t *p_aout;
442 input_thread_t *p_input;
444 if( !current ) current = new QMenu();
446 if( current->isEmpty() )
448 ACT_ADD( current, "audio-es", qtr( "Audio &Track" ) );
449 ACT_ADD( current, "audio-device", qtr( "Audio &Device" ) );
450 ACT_ADD( current, "audio-channels", qtr( "Audio &Channels" ) );
451 current->addSeparator();
452 ACT_ADD( current, "visual", qtr( "&Visualizations" ) );
455 p_input = THEMIM->getInput();
457 vlc_object_yield( p_input );
458 p_aout = ( vlc_object_t * ) vlc_object_find( p_intf,
462 AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
465 vlc_object_release( p_aout );
467 vlc_object_release( p_input );
469 return Populate( p_intf, current, varnames, objects );
474 * Subtitles are part of Video.
476 QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current )
478 vlc_object_t *p_vout;
479 input_thread_t *p_input;
481 vector<const char *> varnames;
483 if( !current ) current = new QMenu();
485 if( current->isEmpty() )
487 ACT_ADD( current, "video-es", qtr( "Video &Track" ) );
490 QMenu *submenu = new QMenu( qtr( "&Subtitles Track" ), current );
491 action = current->addMenu( submenu );
492 action->setData( "spu-es" );
493 addDPStaticEntry( submenu, qtr( "Open File..." ), "", "",
494 SLOT( loadSubtitlesFile() ) );
495 submenu->addSeparator();
497 ACT_ADD( current, "fullscreen", qtr( "&Fullscreen" ) );
498 ACT_ADD( current, "zoom", qtr( "&Zoom" ) );
499 ACT_ADD( current, "deinterlace", qtr( "&Deinterlace" ) );
500 ACT_ADD( current, "aspect-ratio", qtr( "&Aspect Ratio" ) );
501 ACT_ADD( current, "crop", qtr( "&Crop" ) );
502 ACT_ADD( current, "video-on-top", qtr( "Always &On Top" ) );
504 ACT_ADD( current, "directx-wallpaper", qtr( "DirectX Wallpaper" ) );
506 ACT_ADD( current, "video-snapshot", qtr( "Sna&pshot" ) );
507 /* ACT_ADD( current, "ffmpeg-pp-q", qtr( "Decoder" ) ); */
510 p_input = THEMIM->getInput();
512 vlc_object_yield( p_input );
513 p_vout = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_VOUT,
516 VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
519 vlc_object_release( p_vout );
521 vlc_object_release( p_input );
523 return Populate( p_intf, current, varnames, objects );
528 * For DVD, MP4, MOV and other chapter based format
530 QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *menu )
532 vlc_object_t *p_object;
534 vector<const char *> varnames;
536 if( !menu ) menu = new QMenu();
538 if( menu->isEmpty() )
540 addDPStaticEntry( menu, qtr( I_MENU_GOTOTIME ), "","",
541 SLOT( gotoTimeDialog() ), "Ctrl+T" );
542 menu->addSeparator();
544 ACT_ADD( menu, "bookmark", qtr( "&Bookmarks" ) );
545 ACT_ADD( menu, "title", qtr( "T&itle" ) );
546 ACT_ADD( menu, "chapter", qtr( "&Chapter" ) );
547 ACT_ADD( menu, "program", qtr( "&Program" ) );
548 ACT_ADD( menu, "navigation", qtr( "&Navigation" ) );
551 p_object = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_INPUT,
553 InputAutoMenuBuilder( p_object, objects, varnames );
554 PUSH_VAR( "prev-title" );
555 PUSH_VAR( "next-title" );
556 PUSH_VAR( "prev-chapter" );
557 PUSH_VAR( "next-chapter" );
558 EnableDPStaticEntries( menu, ( p_object != NULL ) );
561 vlc_object_release( p_object );
563 return Populate( p_intf, menu, varnames, objects, true );
567 * Service Discovery SubMenu
569 QMenu *QVLCMenu::SDMenu( intf_thread_t *p_intf )
571 QMenu *menu = new QMenu();
572 menu->setTitle( qtr( I_PL_SD ) );
573 char **ppsz_longnames;
574 char **ppsz_names = services_discovery_GetServicesNames( p_intf,
579 char **ppsz_name = ppsz_names, **ppsz_longname = ppsz_longnames;
580 for( ; *ppsz_name; ppsz_name++, ppsz_longname++ )
582 QAction *a = new QAction( qfu( *ppsz_longname ), menu );
583 a->setCheckable( true );
584 if( playlist_IsServicesDiscoveryLoaded( THEPL, *ppsz_name ) )
585 a->setChecked( true );
586 CONNECT( a , triggered(), THEDP->SDMapper, map() );
587 THEDP->SDMapper->setMapping( a, QString( *ppsz_name ) );
588 menu->addAction( a );
590 if( !strcmp( *ppsz_name, "podcast" ) )
592 QAction *b = new QAction( qtr( "Configure podcasts..." ), menu );
593 //b->setEnabled( a->isChecked() );
594 menu->addAction( b );
595 CONNECT( b, triggered(), THEDP, podcastConfigureDialog() );
598 free( *ppsz_longname );
601 free( ppsz_longnames );
607 QMenu *QVLCMenu::HelpMenu( QMenu *current )
609 QMenu *menu = new QMenu( current );
610 addDPStaticEntry( menu, qtr( "&Help..." ) , "",
611 ":/help", SLOT( helpDialog() ), "F1" );
613 addDPStaticEntry( menu, qtr( "Check for &Updates..." ) , "", "",
614 SLOT( updateDialog() ), "");
616 menu->addSeparator();
617 addDPStaticEntry( menu, qtr( I_MENU_ABOUT ), "", ":/info",
618 SLOT( aboutDialog() ), "Shift+F1" );
622 /*****************************************************************************
623 * Popup menus - Right Click menus *
624 *****************************************************************************/
625 #define POPUP_BOILERPLATE \
626 unsigned int i_last_separator = 0; \
627 vector<int> objects; \
628 vector<const char *> varnames; \
629 input_thread_t *p_input = THEMIM->getInput();
631 #define CREATE_POPUP \
632 Populate( p_intf, menu, varnames, objects ); \
633 p_intf->p_sys->p_popup_menu = menu; \
634 menu->popup( QCursor::pos() ); \
635 p_intf->p_sys->p_popup_menu = NULL; \
636 i_last_separator = 0;
638 void QVLCMenu::PopupMenuControlEntries( QMenu *menu,
639 intf_thread_t *p_intf,
640 input_thread_t *p_input )
645 var_Get( p_input, "state", &val );
646 if( val.i_int == PLAYING_S )
647 addMIMStaticEntry( p_intf, menu, qtr( "Pause" ), "",
648 ":/pause", SLOT( togglePlayPause() ) );
650 addMIMStaticEntry( p_intf, menu, qtr( "Play" ), "",
651 ":/play", SLOT( togglePlayPause() ) );
653 else if( THEPL->items.i_size )
654 addMIMStaticEntry( p_intf, menu, qtr( "Play" ), "",
655 ":/play", SLOT( togglePlayPause() ) );
657 addDPStaticEntry( menu, qtr( "Play" ), "",
658 ":/play", SLOT( openDialog() ) );
660 addMIMStaticEntry( p_intf, menu, qtr( "Stop" ), "",
661 ":/stop", SLOT( stop() ) );
662 addMIMStaticEntry( p_intf, menu, qtr( "Previous" ), "",
663 ":/previous", SLOT( prev() ) );
664 addMIMStaticEntry( p_intf, menu, qtr( "Next" ), "",
665 ":/next", SLOT( next() ) );
668 void QVLCMenu::PopupMenuStaticEntries( intf_thread_t *p_intf, QMenu *menu )
671 QMenu *toolsmenu = ToolsMenu( p_intf, menu, false, true );
672 toolsmenu->setTitle( qtr( "Tools" ) );
673 menu->addMenu( toolsmenu );
676 QMenu *openmenu = new QMenu( qtr( "Open" ), menu );
677 addDPStaticEntry( openmenu, qtr( "&Open File..." ), "",
678 ":/file-asym", SLOT( openFileDialog() ) );
679 addDPStaticEntry( openmenu, qtr( I_OPEN_FOLDER ), "",
680 ":/folder-grey", SLOT( PLOpenDir() ) );
681 addDPStaticEntry( openmenu, qtr( "Open &Disc..." ), "",
682 ":/disc", SLOT( openDiscDialog() ) );
683 addDPStaticEntry( openmenu, qtr( "Open &Network..." ), "",
684 ":/network", SLOT( openNetDialog() ) );
685 addDPStaticEntry( openmenu, qtr( "Open &Capture Device..." ), "",
686 ":/capture-card", SLOT( openCaptureDialog() ) );
687 menu->addMenu( openmenu );
689 menu->addSeparator();
691 QMenu *helpmenu = HelpMenu( menu );
692 helpmenu->setTitle( qtr( "Help" ) );
693 menu->addMenu( helpmenu );
696 addDPStaticEntry( menu, qtr( "Quit" ), "", ":/quit",
697 SLOT( quit() ), "Ctrl+Q" );
700 /* Video Tracks and Subtitles tracks */
701 void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf )
706 vlc_object_yield( p_input );
707 vlc_object_t *p_vout = ( vlc_object_t * )vlc_object_find( p_input,
708 VLC_OBJECT_VOUT, FIND_CHILD );
711 VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
712 vlc_object_release( p_vout );
714 vlc_object_release( p_input );
716 QMenu *menu = new QMenu();
721 void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf )
726 vlc_object_yield( p_input );
727 vlc_object_t *p_aout = ( vlc_object_t * )vlc_object_find( p_input,
728 VLC_OBJECT_AOUT, FIND_ANYWHERE );
729 AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
731 vlc_object_release( p_aout );
732 vlc_object_release( p_input );
734 QMenu *menu = new QMenu();
738 /* Navigation stuff, and general menus ( open ) */
739 void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf )
746 vlc_object_yield( p_input );
747 varnames.push_back( "audio-es" );
748 InputAutoMenuBuilder( VLC_OBJECT( p_input ), objects, varnames );
752 QMenu *menu = new QMenu();
753 Populate( p_intf, menu, varnames, objects );
755 menu->addSeparator();
756 PopupMenuControlEntries( menu, p_intf, p_input );
758 menu->addSeparator();
759 PopupMenuStaticEntries( p_intf, menu );
761 p_intf->p_sys->p_popup_menu = menu;
762 menu->popup( QCursor::pos() );
763 p_intf->p_sys->p_popup_menu = NULL;
766 /* Main Menu that sticks everything together */
767 void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show )
769 MainInterface *mi = p_intf->p_sys->p_mi;
772 /* Delete and recreate a popup if there is one */
773 if( p_intf->p_sys->p_popup_menu )
774 delete p_intf->p_sys->p_popup_menu;
776 QMenu *menu = new QMenu();
779 bool b_isFullscreen = false;
783 PopupMenuControlEntries( menu, p_intf, p_input );
784 menu->addSeparator();
788 vlc_object_t *p_vout = (vlc_object_t *)
789 vlc_object_find( p_input, VLC_OBJECT_VOUT, FIND_CHILD );
791 /* Add a fullscreen switch button */
795 var_Get( p_vout, "fullscreen", &val );
796 b_isFullscreen = !( !val.b_bool );
798 CreateAndConnect( menu, "fullscreen",
799 qtr( "Leave Fullscreen" ),"" , ITEM_NORMAL,
800 p_vout->i_object_id, val, VLC_VAR_BOOL,
802 vlc_object_release( p_vout );
805 menu->addSeparator();
807 vlc_object_yield( p_input );
808 InputAutoMenuBuilder( VLC_OBJECT( p_input ), objects, varnames );
809 vlc_object_release( p_input );
811 submenu = new QMenu( menu );
812 action = menu->addMenu( AudioMenu( p_intf, submenu ) );
813 action->setText( qtr( "&Audio" ) );
814 if( action->menu()->isEmpty() )
815 action->setEnabled( false );
817 submenu = new QMenu( menu );
818 action = menu->addMenu( VideoMenu( p_intf, submenu ) );
819 action->setText( qtr( "&Video" ) );
820 if( action->menu()->isEmpty() )
821 action->setEnabled( false );
823 submenu = new QMenu( menu );
824 action = menu->addMenu( NavigMenu( p_intf, submenu ) );
825 action->setText( qtr( "&Playback" ) );
826 if( action->menu()->isEmpty() )
827 action->setEnabled( false );
830 menu->addSeparator();
832 /* Add some special entries for windowed mode: Interface Menu */
833 if( !b_isFullscreen )
835 submenu = new QMenu( qtr( "Interface" ), menu );
838 submenu->addAction( QIcon( ":/playlist" ),
839 qtr( "Show Playlist" ), mi, SLOT( togglePlaylist() ) );
841 addDPStaticEntry( submenu, qtr( I_MENU_EXT ), "",
842 ":/settings", SLOT( extendedDialog() ) );
845 action = submenu->addAction( QIcon( "" ),
846 qtr( "Minimal View" ), mi, SLOT( toggleMinimalView() ) );
847 action->setCheckable( true );
848 action->setChecked( !( mi->getControlsVisibilityStatus() &
849 CONTROLS_VISIBLE ) );
850 action = submenu->addAction( QIcon( "" ),
851 qtr( "Toggle Fullscreen Interface" ),
852 mi, SLOT( toggleFullScreen() ) );
853 action->setCheckable( true );
854 action->setChecked( mi->isFullScreen() );
856 else /* We are using the skins interface.
857 If not, this entry will not show. */
861 vlc_object_t *p_object = ( vlc_object_t* )
862 vlc_object_find( p_intf, VLC_OBJECT_INTF, FIND_PARENT );
865 objects.push_back( p_object->i_object_id );
866 varnames.push_back( "intf-skins" );
867 Populate( p_intf, submenu, varnames, objects );
868 vlc_object_release( p_object );
872 msg_Dbg( p_intf, "could not find parent interface" );
875 menu->addMenu( submenu );
878 PopupMenuStaticEntries( p_intf, menu );
880 p_intf->p_sys->p_popup_menu = menu;
881 p_intf->p_sys->p_popup_menu->popup( QCursor::pos() );
885 // destroy popup if there is one
886 delete p_intf->p_sys->p_popup_menu;
887 p_intf->p_sys->p_popup_menu = NULL;
893 /************************************************************************
895 ************************************************************************/
897 void QVLCMenu::updateSystrayMenu( MainInterface *mi,
898 intf_thread_t *p_intf,
899 bool b_force_visible )
903 /* Get the systray menu and clean it */
904 QMenu *sysMenu = mi->getSysTrayMenu();
907 /* Hide / Show VLC and cone */
908 if( mi->isVisible() || b_force_visible )
910 sysMenu->addAction( QIcon( ":/vlc16.png" ),
911 qtr( "Hide VLC media player in taskbar" ), mi,
912 SLOT( toggleUpdateSystrayMenu() ) );
916 sysMenu->addAction( QIcon( ":/vlc16.png" ),
917 qtr( "Show VLC media player" ), mi,
918 SLOT( toggleUpdateSystrayMenu() ) );
921 sysMenu->addSeparator();
922 PopupMenuControlEntries( sysMenu, p_intf, p_input );
924 sysMenu->addSeparator();
925 addDPStaticEntry( sysMenu, qtr( "&Open Media" ), "",
926 ":/file-wide", SLOT( openFileDialog() ), "" );
927 addDPStaticEntry( sysMenu, qtr( "&Quit" ) , "",
928 ":/quit", SLOT( quit() ), "" );
931 mi->getSysTray()->setContextMenu( sysMenu );
935 #undef PUSH_SEPARATOR
937 /*************************************************************************
938 * Builders for automenus
939 *************************************************************************/
940 QMenu * QVLCMenu::Populate( intf_thread_t *p_intf,
942 vector< const char *> & varnames,
943 vector<int> & objects,
946 QMenu *menu = current;
947 if( !menu ) menu = new QMenu();
949 /* Disable all non static entries */
951 foreach( p_action, menu->actions() )
953 if( p_action->data().toString() != "_static_" )
954 p_action->setEnabled( false );
959 vlc_object_t *p_object;
962 for( i = 0; i < ( int )objects.size() ; i++ )
964 if( !varnames[i] || !*varnames[i] )
966 menu->addSeparator();
970 if( objects[i] == 0 )
976 p_object = ( vlc_object_t * )vlc_object_get( p_intf->p_libvlc, objects[i] );
979 msg_Warn( p_intf, "object %d not found !", objects[i] );
984 UpdateItem( p_intf, menu, varnames[i], p_object, true );
986 vlc_object_release( p_object );
991 /*****************************************************************************
993 *****************************************************************************/
995 static bool IsMenuEmpty( const char *psz_var,
996 vlc_object_t *p_object,
999 vlc_value_t val, val_list;
1000 int i_type, i_result, i;
1002 /* Check the type of the object variable */
1003 i_type = var_Type( p_object, psz_var );
1005 /* Check if we want to display the variable */
1006 if( !( i_type & VLC_VAR_HASCHOICE ) ) return false;
1008 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
1009 if( val.i_int == 0 ) return true;
1011 if( ( i_type & VLC_VAR_TYPE ) != VLC_VAR_VARIABLE )
1013 if( val.i_int == 1 && b_root ) return true;
1017 /* Check children variables in case of VLC_VAR_VARIABLE */
1018 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
1023 for( i = 0, i_result = true; i < val_list.p_list->i_count; i++ )
1025 if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
1033 /* clean up everything */
1034 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, NULL );
1039 #define TEXT_OR_VAR qfu ( text.psz_string ? text.psz_string : psz_var )
1041 void QVLCMenu::UpdateItem( intf_thread_t *p_intf, QMenu *menu,
1042 const char *psz_var, vlc_object_t *p_object, bool b_submenu )
1044 vlc_value_t val, text;
1047 QAction *action = FindActionWithVar( menu, psz_var );
1049 DeleteNonStaticEntries( action->menu() );
1054 /* Check the type of the object variable */
1055 if( !strcmp( psz_var, "audio-es" )
1056 || !strcmp( psz_var, "video-es" ) )
1057 i_type = VLC_VAR_INTEGER | VLC_VAR_HASCHOICE;
1059 i_type = var_Type( p_object, psz_var );
1061 switch( i_type & VLC_VAR_TYPE )
1065 case VLC_VAR_VARIABLE:
1066 case VLC_VAR_STRING:
1067 case VLC_VAR_INTEGER:
1071 /* Variable doesn't exist or isn't handled */
1075 /* Make sure we want to display the variable */
1076 if( menu->isEmpty() && IsMenuEmpty( psz_var, p_object ) )
1079 /* Get the descriptive name of the variable */
1080 int i_ret = var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
1081 if( i_ret != VLC_SUCCESS )
1083 text.psz_string = NULL;
1088 action = new QAction( TEXT_OR_VAR, menu );
1089 menu->addAction( action );
1090 action->setData( psz_var );
1093 /* Some specific stuff */
1094 bool forceDisabled = false;
1095 if( !strcmp( psz_var, "spu-es" ) )
1097 vlc_object_t *p_vout = ( vlc_object_t* )( vlc_object_find( p_intf,
1098 VLC_OBJECT_VOUT, FIND_ANYWHERE ) );
1099 forceDisabled = ( p_vout == NULL );
1101 vlc_object_release( p_vout );
1104 if( i_type & VLC_VAR_HASCHOICE )
1106 /* Append choices menu */
1110 submenu = action->menu();
1113 submenu = new QMenu( menu );
1114 action->setMenu( submenu );
1118 CreateChoicesMenu( submenu, psz_var, p_object, true ) == 0 );
1120 action->setEnabled( false );
1123 CreateChoicesMenu( menu, psz_var, p_object, true );
1124 FREENULL( text.psz_string );
1128 switch( i_type & VLC_VAR_TYPE )
1131 var_Get( p_object, psz_var, &val );
1132 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_NORMAL,
1133 p_object->i_object_id, val, i_type );
1137 var_Get( p_object, psz_var, &val );
1138 val.b_bool = !val.b_bool;
1139 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_CHECK,
1140 p_object->i_object_id, val, i_type, !val.b_bool );
1143 FREENULL( text.psz_string );
1147 int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
1148 vlc_object_t *p_object, bool b_root )
1150 vlc_value_t val, val_list, text_list;
1153 /* Check the type of the object variable */
1154 i_type = var_Type( p_object, psz_var );
1156 /* Make sure we want to display the variable */
1157 if( submenu->isEmpty() && IsMenuEmpty( psz_var, p_object, b_root ) )
1158 return VLC_EGENERIC;
1160 switch( i_type & VLC_VAR_TYPE )
1164 case VLC_VAR_VARIABLE:
1165 case VLC_VAR_STRING:
1166 case VLC_VAR_INTEGER:
1170 /* Variable doesn't exist or isn't handled */
1171 return VLC_EGENERIC;
1174 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
1175 &val_list, &text_list ) < 0 )
1177 return VLC_EGENERIC;
1180 #define CURVAL val_list.p_list->p_values[i]
1181 #define CURTEXT text_list.p_list->p_values[i].psz_string
1183 for( i = 0; i < val_list.p_list->i_count; i++ )
1185 vlc_value_t another_val;
1187 QMenu *subsubmenu = new QMenu( submenu );
1189 switch( i_type & VLC_VAR_TYPE )
1191 case VLC_VAR_VARIABLE:
1192 CreateChoicesMenu( subsubmenu, CURVAL.psz_string, p_object, false );
1193 subsubmenu->setTitle( qfu( CURTEXT ? CURTEXT :CURVAL.psz_string ) );
1194 submenu->addMenu( subsubmenu );
1197 case VLC_VAR_STRING:
1198 var_Get( p_object, psz_var, &val );
1199 another_val.psz_string = strdup( CURVAL.psz_string );
1200 menutext = qfu( CURTEXT ? CURTEXT : another_val.psz_string );
1201 CreateAndConnect( submenu, psz_var, menutext, "", ITEM_RADIO,
1202 p_object->i_object_id, another_val, i_type,
1203 val.psz_string && !strcmp( val.psz_string, CURVAL.psz_string ) );
1205 free( val.psz_string );
1208 case VLC_VAR_INTEGER:
1209 var_Get( p_object, psz_var, &val );
1210 if( CURTEXT ) menutext = qfu( CURTEXT );
1211 else menutext.sprintf( "%d", CURVAL.i_int );
1212 CreateAndConnect( submenu, psz_var, menutext, "", ITEM_RADIO,
1213 p_object->i_object_id, CURVAL, i_type,
1214 CURVAL.i_int == val.i_int );
1218 var_Get( p_object, psz_var, &val );
1219 if( CURTEXT ) menutext = qfu( CURTEXT );
1220 else menutext.sprintf( "%.2f", CURVAL.f_float );
1221 CreateAndConnect( submenu, psz_var, menutext, "", ITEM_RADIO,
1222 p_object->i_object_id, CURVAL, i_type,
1223 CURVAL.f_float == val.f_float );
1230 currentGroup = NULL;
1232 /* clean up everything */
1233 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
1240 void QVLCMenu::CreateAndConnect( QMenu *menu, const char *psz_var,
1241 QString text, QString help,
1242 int i_item_type, int i_object_id,
1243 vlc_value_t val, int i_val_type,
1246 QAction *action = FindActionWithVar( menu, psz_var );
1249 action = new QAction( text, menu );
1250 menu->addAction( action );
1253 action->setToolTip( help );
1254 action->setEnabled( i_object_id != 0 );
1256 if( i_item_type == ITEM_CHECK )
1258 action->setCheckable( true );
1260 else if( i_item_type == ITEM_RADIO )
1262 action->setCheckable( true );
1264 currentGroup = new QActionGroup( menu );
1265 currentGroup->addAction( action );
1268 action->setChecked( checked );
1270 MenuItemData *itemData = new MenuItemData( THEDP->menusMapper, i_object_id, i_val_type,
1272 CONNECT( action, triggered(), THEDP->menusMapper, map() );
1273 THEDP->menusMapper->setMapping( action, itemData );
1274 menu->addAction( action );
1277 void QVLCMenu::DoAction( intf_thread_t *p_intf, QObject *data )
1279 MenuItemData *itemData = qobject_cast<MenuItemData *>( data );
1280 vlc_object_t *p_object = ( vlc_object_t * )vlc_object_get( p_intf->p_libvlc, itemData->i_object_id );
1281 if( p_object == NULL ) return;
1283 var_Set( p_object, itemData->psz_var, itemData->val );
1284 vlc_object_release( p_object );