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" );
194 PUSH_VAR( "directx-wallpaper" );
195 PUSH_VAR( "video-snapshot" );
199 vlc_object_t *p_dec_obj = ( vlc_object_t * )vlc_object_find( p_object,
204 vlc_object_t *p_object = p_dec_obj;
205 PUSH_VAR( "ffmpeg-pp-q" );
206 vlc_object_release( p_dec_obj );
212 static int AudioAutoMenuBuilder( vlc_object_t *p_object,
213 input_thread_t *p_input,
214 vector<int> &objects,
215 vector<const char *> &varnames )
217 PUSH_INPUTVAR( "audio-es" );
218 PUSH_VAR( "audio-device" );
219 PUSH_VAR( "audio-channels" );
220 PUSH_VAR( "equalizer" );
221 PUSH_VAR( "visual" );
225 static QAction * FindActionWithVar( QMenu *menu, const char *psz_var )
228 foreach( action, menu->actions() )
230 if( action->data().toString() == psz_var )
236 static QAction * FindActionWithText( QMenu *menu, QString &text )
239 foreach( action, menu->actions() )
241 if( action->text() == text )
247 /*****************************************************************************
250 *****************************************************************************/
252 #define BAR_ADD( func, title ) { \
253 QMenu *_menu = func; _menu->setTitle( title ); bar->addMenu( _menu ); }
255 #define BAR_DADD( func, title, id ) { \
256 QMenu *_menu = func; _menu->setTitle( title ); bar->addMenu( _menu ); \
257 MenuFunc *f = new MenuFunc( _menu, id ); \
258 CONNECT( _menu, aboutToShow(), THEDP->menusUpdateMapper, map() ); \
259 THEDP->menusUpdateMapper->setMapping( _menu, f ); }
261 #define ACT_ADD( _menu, val, title ) { \
262 QAction *_action = new QAction( title, _menu ); _action->setData( val ); \
263 _menu->addAction( _action ); }
266 * Main Menu Bar Creation
268 void QVLCMenu::createMenuBar( MainInterface *mi,
269 intf_thread_t *p_intf,
270 bool visual_selector_enabled )
272 /* QMainWindows->menuBar()
273 gives the QProcess::destroyed timeout issue on Cleanlooks style with
274 setDesktopAware set to false */
275 QMenuBar *bar = mi->menuBar();
276 BAR_ADD( FileMenu(), qtr( "&Media" ) );
277 BAR_ADD( PlaylistMenu( p_intf, mi ), qtr( "&Playlist" ) );
278 BAR_ADD( ToolsMenu( p_intf, NULL, mi, visual_selector_enabled, true ),
280 BAR_DADD( AudioMenu( p_intf, NULL ), qtr( "&Audio" ), 1 );
281 BAR_DADD( VideoMenu( p_intf, NULL ), qtr( "&Video" ), 2 );
282 BAR_DADD( NavigMenu( p_intf, NULL ), qtr( "&Playback" ), 3 );
283 BAR_ADD( HelpMenu( NULL ), qtr( "&Help" ) );
289 * Media ( File ) Menu
290 * Opening, streaming and quit
292 QMenu *QVLCMenu::FileMenu()
294 QMenu *menu = new QMenu();
296 addDPStaticEntry( menu, qtr( "&Open File..." ), "",
297 ":/pixmaps/file-asym_16px.png", SLOT( openFileDialog() ), "Ctrl+O" );
298 addDPStaticEntry( menu, qtr( I_OPEN_FOLDER ), "",
299 ":/pixmaps/folder-grey_16px.png", SLOT( PLAppendDir() ), "Ctrl+F" );
300 addDPStaticEntry( menu, qtr( "Open &Disc..." ), "",
301 ":/pixmaps/disc_16px.png", SLOT( openDiscDialog() ), "Ctrl+D" );
302 addDPStaticEntry( menu, qtr( "Open &Network..." ), "",
303 ":/pixmaps/network_16px.png", SLOT( openNetDialog() ), "Ctrl+N" );
304 addDPStaticEntry( menu, qtr( "Open &Capture Device..." ), "",
305 ":/pixmaps/capture-card_16px.png", SLOT( openCaptureDialog() ),
307 menu->addSeparator();
309 addDPStaticEntry( menu, qtr( "&Streaming..." ), "",
310 ":/pixmaps/menus_stream_16px.png", SLOT( openThenStreamingDialogs() ),
312 addDPStaticEntry( menu, qtr( "Conve&rt / Save..." ), "", "",
313 SLOT( openThenTranscodingDialogs() ), "Ctrl+R" );
314 menu->addSeparator();
316 addDPStaticEntry( menu, qtr( "&Quit" ) , "",
317 ":/pixmaps/menus_quit_16px.png", SLOT( quit() ), "Ctrl+Q" );
321 /* Playlist/MediaLibrary Control */
322 QMenu *QVLCMenu::PlaylistMenu( intf_thread_t *p_intf, MainInterface *mi )
324 QMenu *menu = new QMenu();
325 menu->addMenu( SDMenu( p_intf ) );
326 menu->addAction( QIcon( ":/pixmaps/playlist_16px.png" ),
327 qtr( "Show Playlist" ), mi, SLOT( togglePlaylist() ) );
328 menu->addSeparator();
330 addDPStaticEntry( menu, qtr( I_PL_LOAD ), "", "", SLOT( openAPlaylist() ),
332 addDPStaticEntry( menu, qtr( I_PL_SAVE ), "", "", SLOT( saveAPlaylist() ),
334 /*menu->addSeparator();
335 menu->addAction( qtr( "Undock from Interface" ), mi,
336 SLOT( undockPlaylist() ), qtr( "Ctrl+U" ) );*/
342 * This is kept in the same menu for now, but could change if it gets much
344 * This menu can be an interface menu but also a right click menu.
346 QMenu *QVLCMenu::ToolsMenu( intf_thread_t *p_intf,
349 bool visual_selector_enabled,
352 QMenu *menu = new QMenu( current );
355 menu->addAction( QIcon( ":/pixmaps/playlist_16px.png" ),
356 qtr( "Playlist..." ), mi, SLOT( togglePlaylist() ),
359 addDPStaticEntry( menu, qtr( I_MENU_EXT ), "",
360 ":/pixmaps/menus_settings_16px.png", SLOT( extendedDialog() ),
363 menu->addSeparator();
367 QMenu *intfmenu = InterfacesMenu( p_intf, menu );
368 intfmenu->setTitle( qtr( "Add Interfaces" ) );
369 MenuFunc *f = new MenuFunc( intfmenu, 4 );
370 CONNECT( intfmenu, aboutToShow(), THEDP->menusUpdateMapper, map() );
371 THEDP->menusUpdateMapper->setMapping( intfmenu, f );
372 menu->addMenu( intfmenu );
373 menu->addSeparator();
378 QAction *action = menu->addAction( qtr( "Minimal View..." ), mi,
379 SLOT( toggleMinimalView() ), qtr( "Ctrl+H" ) );
380 action->setCheckable( true );
381 if( mi->getControlsVisibilityStatus() & CONTROLS_VISIBLE )
382 action->setChecked( true );
383 minimalViewAction = action; /* HACK for minimalView */
385 /* FullScreen View */
386 action = menu->addAction( qtr( "Fullscreen Interface" ), mi,
387 SLOT( toggleFullScreen() ), QString( "F11" ) );
388 action->setCheckable( true );
390 /* Advanced Controls */
391 action = menu->addAction( qtr( "Advanced Controls" ), mi,
392 SLOT( toggleAdvanced() ) );
393 action->setCheckable( true );
394 if( mi->getControlsVisibilityStatus() & CONTROLS_ADVANCED )
395 action->setChecked( true );
396 #if 0 /* For Visualisations. Not yet working */
397 adv = menu->addAction( qtr( "Visualizations selector" ),
398 mi, SLOT( visual() ) );
399 adv->setCheckable( true );
400 if( visual_selector_enabled ) adv->setChecked( true );
404 menu->addSeparator();
406 addDPStaticEntry( menu, qtr( I_MENU_MSG ), "",
407 ":/pixmaps/menus_messages_16px.png", SLOT( messagesDialog() ),
409 addDPStaticEntry( menu, qtr( I_MENU_INFO ) , "", "",
410 SLOT( mediaInfoDialog() ), "Ctrl+I" );
411 addDPStaticEntry( menu, qtr( I_MENU_CODECINFO ) , "",
412 ":/pixmaps/menus_info_16px.png", SLOT( mediaCodecDialog() ), "Ctrl+J" );
413 addDPStaticEntry( menu, qtr( I_MENU_BOOKMARK ), "","",
414 SLOT( bookmarksDialog() ), "Ctrl+B" );
416 addDPStaticEntry( menu, qtr( I_MENU_VLM ), "", "", SLOT( vlmDialog() ),
420 menu->addSeparator();
421 addDPStaticEntry( menu, qtr( "Preferences..." ), "",
422 ":/pixmaps/menus_preferences_16px.png", SLOT( prefsDialog() ), "Ctrl+P" );
427 * Interface Sub-Menu, to list extras interface and skins
429 QMenu *QVLCMenu::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
432 vector<const char *> varnames;
433 /** \todo add "switch to XXX" */
434 varnames.push_back( "intf-add" );
435 objects.push_back( p_intf->i_object_id );
437 QMenu *submenu = new QMenu( current );
438 QMenu *menu = Populate( p_intf, submenu, varnames, objects );
446 QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QMenu * current )
449 vector<const char *> varnames;
450 vlc_object_t *p_aout;
451 input_thread_t *p_input;
453 if( !current ) current = new QMenu();
455 if( current->isEmpty() )
457 ACT_ADD( current, "audio-es", qtr( "Audio &Track" ) );
458 ACT_ADD( current, "audio-device", qtr( "Audio &Device" ) );
459 ACT_ADD( current, "audio-channels", qtr( "Audio &Channels" ) );
460 ACT_ADD( current, "equalizer", qtr( "&Equalizer" ) );
461 current->addSeparator();
462 ACT_ADD( current, "visual", qtr( "&Visualizations" ) );
465 p_input = THEMIM->getInput();
467 vlc_object_yield( p_input );
468 p_aout = ( vlc_object_t * ) vlc_object_find( p_intf,
472 AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
475 vlc_object_release( p_aout );
477 vlc_object_release( p_input );
479 return Populate( p_intf, current, varnames, objects );
484 * Subtitles are part of Video.
486 QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current )
488 vlc_object_t *p_vout;
489 input_thread_t *p_input;
491 vector<const char *> varnames;
493 if( !current ) current = new QMenu();
495 if( current->isEmpty() )
497 ACT_ADD( current, "video-es", qtr( "Video &Track" ) );
500 QMenu *submenu = new QMenu( qtr( "&Subtitles Track" ), current );
501 action = current->addMenu( submenu );
502 action->setData( "spu-es" );
503 addDPStaticEntry( submenu, qtr( "Load File..." ), "", "",
504 SLOT( loadSubtitlesFile() ) );
505 submenu->addSeparator();
507 ACT_ADD( current, "fullscreen", qtr( "Toggle &Fullscreen" ) );
508 ACT_ADD( current, "zoom", qtr( "&Zoom" ) );
509 ACT_ADD( current, "deinterlace", qtr( "&Deinterlace" ) );
510 ACT_ADD( current, "aspect-ratio", qtr( "&Aspect Ratio" ) );
511 ACT_ADD( current, "crop", qtr( "&Crop" ) );
512 ACT_ADD( current, "video-on-top", qtr( "Always &On Top" ) );
513 /* ACT_ADD( current, "directx-wallpaper", qtr( "DirectX Wallpaper" ) ); */
514 ACT_ADD( current, "video-snapshot", qtr( "Snapshot" ) );
515 /* ACT_ADD( current, "ffmpeg-pp-q", qtr( "Decoder" ) ); */
518 p_input = THEMIM->getInput();
520 vlc_object_yield( p_input );
521 p_vout = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_VOUT,
524 VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
527 vlc_object_release( p_vout );
529 vlc_object_release( p_input );
531 return Populate( p_intf, current, varnames, objects );
536 * For DVD, MP4, MOV and other chapter based format
538 QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *menu )
540 vlc_object_t *p_object;
542 vector<const char *> varnames;
544 if( !menu ) menu = new QMenu();
546 if( menu->isEmpty() )
548 addDPStaticEntry( menu, qtr( I_MENU_GOTOTIME ), "","",
549 SLOT( gotoTimeDialog() ), "Ctrl+T" );
550 menu->addSeparator();
552 ACT_ADD( menu, "bookmark", qtr( "&Bookmarks" ) );
553 ACT_ADD( menu, "title", qtr( "&Title" ) );
554 ACT_ADD( menu, "chapter", qtr( "&Chapter" ) );
555 ACT_ADD( menu, "program", qtr( "&Program" ) );
556 ACT_ADD( menu, "navigation", qtr( "&Navigation" ) );
559 p_object = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_INPUT,
561 InputAutoMenuBuilder( p_object, objects, varnames );
562 PUSH_VAR( "prev-title" );
563 PUSH_VAR( "next-title" );
564 PUSH_VAR( "prev-chapter" );
565 PUSH_VAR( "next-chapter" );
566 EnableDPStaticEntries( menu, ( p_object != NULL ) );
569 vlc_object_release( p_object );
571 return Populate( p_intf, menu, varnames, objects, true );
575 * Service Discovery SubMenu
577 QMenu *QVLCMenu::SDMenu( intf_thread_t *p_intf )
579 QMenu *menu = new QMenu();
580 menu->setTitle( qtr( I_PL_SD ) );
581 char **ppsz_longnames;
582 char **ppsz_names = services_discovery_GetServicesNames( p_intf,
587 char **ppsz_name = ppsz_names, **ppsz_longname = ppsz_longnames;
588 for( ; *ppsz_name; ppsz_name++, ppsz_longname++ )
590 QAction *a = new QAction( qfu( *ppsz_longname ), menu );
591 a->setCheckable( true );
592 if( playlist_IsServicesDiscoveryLoaded( THEPL, *ppsz_name ) )
593 a->setChecked( true );
594 CONNECT( a , triggered(), THEDP->SDMapper, map() );
595 THEDP->SDMapper->setMapping( a, QString( *ppsz_name ) );
596 menu->addAction( a );
598 if( !strcmp( *ppsz_name, "podcast" ) )
600 QAction *b = new QAction( qtr( "Configure podcasts..." ), menu );
601 //b->setEnabled( a->isChecked() );
602 menu->addAction( b );
603 CONNECT( b, triggered(), THEDP, podcastConfigureDialog() );
606 free( *ppsz_longname );
609 free( ppsz_longnames );
615 QMenu *QVLCMenu::HelpMenu( QMenu *current )
617 QMenu *menu = new QMenu( current );
618 addDPStaticEntry( menu, qtr( "Help..." ) , "",
619 ":/pixmaps/menus_help_16px.png", SLOT( helpDialog() ), "F1" );
621 addDPStaticEntry( menu, qtr( "Check for Updates..." ) , "", "",
622 SLOT( updateDialog() ), "");
624 menu->addSeparator();
625 addDPStaticEntry( menu, qtr( I_MENU_ABOUT ), "", "", SLOT( aboutDialog() ),
630 /*****************************************************************************
631 * Popup menus - Right Click menus *
632 *****************************************************************************/
633 #define POPUP_BOILERPLATE \
634 unsigned int i_last_separator = 0; \
635 vector<int> objects; \
636 vector<const char *> varnames; \
637 input_thread_t *p_input = THEMIM->getInput();
639 #define CREATE_POPUP \
640 Populate( p_intf, menu, varnames, objects ); \
641 p_intf->p_sys->p_popup_menu = menu; \
642 menu->popup( QCursor::pos() ); \
643 p_intf->p_sys->p_popup_menu = NULL; \
644 i_last_separator = 0;
646 void QVLCMenu::PopupMenuControlEntries( QMenu *menu,
647 intf_thread_t *p_intf,
648 input_thread_t *p_input )
653 var_Get( p_input, "state", &val );
654 if( val.i_int == PLAYING_S )
655 addMIMStaticEntry( p_intf, menu, qtr( "Pause" ), "",
656 ":/pixmaps/pause_16px.png", SLOT( togglePlayPause() ) );
658 addMIMStaticEntry( p_intf, menu, qtr( "Play" ), "",
659 ":/pixmaps/play_16px.png", SLOT( togglePlayPause() ) );
661 else if( THEPL->items.i_size )
662 addMIMStaticEntry( p_intf, menu, qtr( "Play" ), "",
663 ":/pixmaps/play_16px.png", SLOT( togglePlayPause() ) );
665 addDPStaticEntry( menu, qtr( "Play" ), "",
666 ":/pixmaps/play_16px.png", SLOT( openDialog() ) );
668 addMIMStaticEntry( p_intf, menu, qtr( "Stop" ), "",
669 ":/pixmaps/stop_16px.png", SLOT( stop() ) );
670 addMIMStaticEntry( p_intf, menu, qtr( "Previous" ), "",
671 ":/pixmaps/previous_16px.png", SLOT( prev() ) );
672 addMIMStaticEntry( p_intf, menu, qtr( "Next" ), "",
673 ":/pixmaps/next_16px.png", SLOT( next() ) );
676 void QVLCMenu::PopupMenuStaticEntries( intf_thread_t *p_intf, QMenu *menu )
679 QMenu *toolsmenu = ToolsMenu( p_intf, menu, false, true );
680 toolsmenu->setTitle( qtr( "Tools" ) );
681 menu->addMenu( toolsmenu );
684 QMenu *openmenu = new QMenu( qtr( "Open" ), menu );
685 addDPStaticEntry( openmenu, qtr( "&Open File..." ), "",
686 ":/pixmaps/file-asym_16px.png", SLOT( openFileDialog() ) );
687 addDPStaticEntry( openmenu, qtr( I_OPEN_FOLDER ), "",
688 ":/pixmaps/folder-grey_16px.png", SLOT( PLAppendDir() ) );
689 addDPStaticEntry( openmenu, qtr( "Open &Disc..." ), "",
690 ":/pixmaps/disc_16px.png", SLOT( openDiscDialog() ) );
691 addDPStaticEntry( openmenu, qtr( "Open &Network..." ), "",
692 ":/pixmaps/network_16px.png", SLOT( openNetDialog() ) );
693 addDPStaticEntry( openmenu, qtr( "Open &Capture Device..." ), "",
694 ":/pixmaps/capture-card_16px.png", SLOT( openCaptureDialog() ) );
695 menu->addMenu( openmenu );
697 menu->addSeparator();
699 QMenu *helpmenu = HelpMenu( menu );
700 helpmenu->setTitle( qtr( "Help" ) );
701 menu->addMenu( helpmenu );
704 addDPStaticEntry( menu, qtr( "Quit" ), "", ":/pixmaps/menus_quit_16px.png",
705 SLOT( quit() ), "Ctrl+Q" );
708 /* Video Tracks and Subtitles tracks */
709 void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf )
714 vlc_object_yield( p_input );
715 vlc_object_t *p_vout = ( vlc_object_t * )vlc_object_find( p_input,
716 VLC_OBJECT_VOUT, FIND_CHILD );
719 VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
720 vlc_object_release( p_vout );
722 vlc_object_release( p_input );
724 QMenu *menu = new QMenu();
729 void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf )
734 vlc_object_yield( p_input );
735 vlc_object_t *p_aout = ( vlc_object_t * )vlc_object_find( p_input,
736 VLC_OBJECT_AOUT, FIND_ANYWHERE );
737 AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
739 vlc_object_release( p_aout );
740 vlc_object_release( p_input );
742 QMenu *menu = new QMenu();
746 /* Navigation stuff, and general menus ( open ) */
747 void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf )
754 vlc_object_yield( p_input );
755 varnames.push_back( "audio-es" );
756 InputAutoMenuBuilder( VLC_OBJECT( p_input ), objects, varnames );
760 QMenu *menu = new QMenu();
761 Populate( p_intf, menu, varnames, objects );
763 menu->addSeparator();
764 PopupMenuControlEntries( menu, p_intf, p_input );
766 menu->addSeparator();
767 PopupMenuStaticEntries( p_intf, menu );
769 p_intf->p_sys->p_popup_menu = menu;
770 menu->popup( QCursor::pos() );
771 p_intf->p_sys->p_popup_menu = NULL;
774 /* Main Menu that sticks everything together */
775 void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show )
777 MainInterface *mi = p_intf->p_sys->p_mi;
780 /* Delete and recreate a popup if there is one */
781 if( p_intf->p_sys->p_popup_menu )
782 delete p_intf->p_sys->p_popup_menu;
784 QMenu *menu = new QMenu();
787 bool b_isFullscreen = false;
791 PopupMenuControlEntries( menu, p_intf, p_input );
792 menu->addSeparator();
796 vlc_object_t *p_vout = (vlc_object_t *)
797 vlc_object_find( p_input, VLC_OBJECT_VOUT, FIND_CHILD );
799 /* Add a fullscreen switch button */
803 var_Get( p_vout, "fullscreen", &val );
804 b_isFullscreen = !( !val.b_bool );
806 CreateAndConnect( menu, "fullscreen",
807 qtr( "Leave Fullscreen" ),"" , ITEM_NORMAL,
808 p_vout->i_object_id, val, VLC_VAR_BOOL,
810 vlc_object_release( p_vout );
813 menu->addSeparator();
815 vlc_object_yield( p_input );
816 InputAutoMenuBuilder( VLC_OBJECT( p_input ), objects, varnames );
817 vlc_object_release( p_input );
819 submenu = new QMenu( menu );
820 action = menu->addMenu( AudioMenu( p_intf, submenu ) );
821 action->setText( qtr( "&Audio" ) );
822 if( action->menu()->isEmpty() )
823 action->setEnabled( false );
825 submenu = new QMenu( menu );
826 action = menu->addMenu( VideoMenu( p_intf, submenu ) );
827 action->setText( qtr( "&Video" ) );
828 if( action->menu()->isEmpty() )
829 action->setEnabled( false );
831 submenu = new QMenu( menu );
832 action = menu->addMenu( NavigMenu( p_intf, submenu ) );
833 action->setText( qtr( "&Playback" ) );
834 if( action->menu()->isEmpty() )
835 action->setEnabled( false );
838 menu->addSeparator();
840 /* Add some special entries for windowed mode: Interface Menu */
841 if( !b_isFullscreen )
843 submenu = new QMenu( qtr( "Interface" ), menu );
844 submenu->addAction( QIcon( ":/pixmaps/playlist_16px.png" ),
845 qtr( "Show Playlist" ), mi, SLOT( togglePlaylist() ) );
846 addDPStaticEntry( submenu, qtr( I_MENU_EXT ), "",
847 ":/pixmaps/menus_settings_16px.png", SLOT( extendedDialog() ) );
848 action = submenu->addAction( QIcon( "" ),
849 qtr( "Minimal View..." ), mi, SLOT( toggleMinimalView() ) );
850 action->setCheckable( true );
851 action->setChecked( !( mi->getControlsVisibilityStatus() &
852 CONTROLS_VISIBLE ) );
853 action = submenu->addAction( QIcon( "" ),
854 qtr( "Toggle Fullscreen Interface" ),
855 mi, SLOT( toggleFullScreen() ) );
856 action->setCheckable( true );
857 action->setChecked( mi->isFullScreen() );
858 menu->addMenu( submenu );
861 PopupMenuStaticEntries( p_intf, menu );
863 p_intf->p_sys->p_popup_menu = menu;
864 p_intf->p_sys->p_popup_menu->popup( QCursor::pos() );
868 // destroy popup if there is one
869 delete p_intf->p_sys->p_popup_menu;
870 p_intf->p_sys->p_popup_menu = NULL;
876 /************************************************************************
878 ************************************************************************/
880 void QVLCMenu::updateSystrayMenu( MainInterface *mi,
881 intf_thread_t *p_intf,
882 bool b_force_visible )
886 /* Get the systray menu and clean it */
887 QMenu *sysMenu = mi->getSysTrayMenu();
890 /* Hide / Show VLC and cone */
891 if( mi->isVisible() || b_force_visible )
893 sysMenu->addAction( QIcon( ":/vlc16.png" ),
894 qtr( "Hide VLC media player in taskbar" ), mi,
895 SLOT( toggleUpdateSystrayMenu() ) );
899 sysMenu->addAction( QIcon( ":/vlc16.png" ),
900 qtr( "Show VLC media player" ), mi,
901 SLOT( toggleUpdateSystrayMenu() ) );
904 sysMenu->addSeparator();
905 PopupMenuControlEntries( sysMenu, p_intf, p_input );
907 sysMenu->addSeparator();
908 addDPStaticEntry( sysMenu, qtr( "&Open Media" ), "",
909 ":/pixmaps/file-wide_16px.png", SLOT( openFileDialog() ), "" );
910 addDPStaticEntry( sysMenu, qtr( "&Quit" ) , "",
911 ":/pixmaps/menus_quit_16px.png", SLOT( quit() ), "" );
914 mi->getSysTray()->setContextMenu( sysMenu );
918 #undef PUSH_SEPARATOR
920 /*************************************************************************
921 * Builders for automenus
922 *************************************************************************/
923 QMenu * QVLCMenu::Populate( intf_thread_t *p_intf,
925 vector< const char *> & varnames,
926 vector<int> & objects,
929 QMenu *menu = current;
930 if( !menu ) menu = new QMenu();
932 /* Disable all non static entries */
934 foreach( p_action, menu->actions() )
936 if( p_action->data().toString() != "_static_" )
937 p_action->setEnabled( false );
942 vlc_object_t *p_object;
945 for( i = 0; i < ( int )objects.size() ; i++ )
947 if( !varnames[i] || !*varnames[i] )
949 menu->addSeparator();
953 if( objects[i] == 0 )
959 p_object = ( vlc_object_t * )vlc_object_get( objects[i] );
962 msg_Dbg( p_intf, "object %d not found !", objects[i] );
967 /* Ugly specific stuff */
968 if( strstr( varnames[i], "intf-add" ) )
969 UpdateItem( p_intf, menu, varnames[i], p_object, false );
971 UpdateItem( p_intf, menu, varnames[i], p_object, true );
973 vlc_object_release( p_object );
978 /*****************************************************************************
980 *****************************************************************************/
982 static bool IsMenuEmpty( const char *psz_var,
983 vlc_object_t *p_object,
986 vlc_value_t val, val_list;
987 int i_type, i_result, i;
989 /* Check the type of the object variable */
990 i_type = var_Type( p_object, psz_var );
992 /* Check if we want to display the variable */
993 if( !( i_type & VLC_VAR_HASCHOICE ) ) return false;
995 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
996 if( val.i_int == 0 ) return true;
998 if( ( i_type & VLC_VAR_TYPE ) != VLC_VAR_VARIABLE )
1000 if( val.i_int == 1 && b_root ) return true;
1004 /* Check children variables in case of VLC_VAR_VARIABLE */
1005 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
1010 for( i = 0, i_result = true; i < val_list.p_list->i_count; i++ )
1012 if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
1020 /* clean up everything */
1021 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, NULL );
1026 #define TEXT_OR_VAR qfu ( text.psz_string ? text.psz_string : psz_var )
1028 void QVLCMenu::UpdateItem( intf_thread_t *p_intf, QMenu *menu,
1029 const char *psz_var, vlc_object_t *p_object, bool b_submenu )
1031 vlc_value_t val, text;
1034 QAction *action = FindActionWithVar( menu, psz_var );
1036 DeleteNonStaticEntries( action->menu() );
1041 /* Check the type of the object variable */
1042 if( !strcmp( psz_var, "audio-es" )
1043 || !strcmp( psz_var, "video-es" ) )
1044 i_type = VLC_VAR_INTEGER | VLC_VAR_HASCHOICE;
1046 i_type = var_Type( p_object, psz_var );
1048 switch( i_type & VLC_VAR_TYPE )
1052 case VLC_VAR_VARIABLE:
1053 case VLC_VAR_STRING:
1054 case VLC_VAR_INTEGER:
1058 /* Variable doesn't exist or isn't handled */
1062 /* Make sure we want to display the variable */
1063 if( menu->isEmpty() && IsMenuEmpty( psz_var, p_object ) )
1066 /* Get the descriptive name of the variable */
1067 int i_ret = var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
1068 if( i_ret != VLC_SUCCESS )
1070 text.psz_string = NULL;
1075 action = new QAction( TEXT_OR_VAR, menu );
1076 menu->addAction( action );
1077 action->setData( psz_var );
1080 /* Some specific stuff */
1081 bool forceDisabled = false;
1082 if( !strcmp( psz_var, "spu-es" ) )
1084 vlc_object_t *p_vout = ( vlc_object_t* )( vlc_object_find( p_intf,
1085 VLC_OBJECT_VOUT, FIND_ANYWHERE ) );
1086 forceDisabled = ( p_vout == NULL );
1088 vlc_object_release( p_vout );
1091 if( i_type & VLC_VAR_HASCHOICE )
1093 /* Append choices menu */
1097 submenu = action->menu();
1100 submenu = new QMenu( menu );
1101 action->setMenu( submenu );
1105 CreateChoicesMenu( submenu, psz_var, p_object, true ) == 0 );
1107 action->setEnabled( false );
1110 CreateChoicesMenu( menu, psz_var, p_object, true );
1111 FREENULL( text.psz_string );
1115 switch( i_type & VLC_VAR_TYPE )
1118 var_Get( p_object, psz_var, &val );
1119 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_NORMAL,
1120 p_object->i_object_id, val, i_type );
1124 var_Get( p_object, psz_var, &val );
1125 val.b_bool = !val.b_bool;
1126 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_CHECK,
1127 p_object->i_object_id, val, i_type, !val.b_bool );
1130 FREENULL( text.psz_string );
1134 int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
1135 vlc_object_t *p_object, bool b_root )
1137 vlc_value_t val, val_list, text_list;
1140 /* Check the type of the object variable */
1141 i_type = var_Type( p_object, psz_var );
1143 /* Make sure we want to display the variable */
1144 if( submenu->isEmpty() && IsMenuEmpty( psz_var, p_object, b_root ) )
1145 return VLC_EGENERIC;
1147 switch( i_type & VLC_VAR_TYPE )
1151 case VLC_VAR_VARIABLE:
1152 case VLC_VAR_STRING:
1153 case VLC_VAR_INTEGER:
1157 /* Variable doesn't exist or isn't handled */
1158 return VLC_EGENERIC;
1161 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
1162 &val_list, &text_list ) < 0 )
1164 return VLC_EGENERIC;
1167 #define NORMAL_OR_RADIO i_type & VLC_VAR_ISCOMMAND ? ITEM_NORMAL: ITEM_RADIO
1168 #define NOTCOMMAND !( i_type & VLC_VAR_ISCOMMAND )
1169 #define CURVAL val_list.p_list->p_values[i]
1170 #define CURTEXT text_list.p_list->p_values[i].psz_string
1172 for( i = 0; i < val_list.p_list->i_count; i++ )
1174 vlc_value_t another_val;
1176 QMenu *subsubmenu = new QMenu( submenu );
1178 switch( i_type & VLC_VAR_TYPE )
1180 case VLC_VAR_VARIABLE:
1181 CreateChoicesMenu( subsubmenu, CURVAL.psz_string, p_object, false );
1182 subsubmenu->setTitle( qfu( CURTEXT ? CURTEXT :CURVAL.psz_string ) );
1183 submenu->addMenu( subsubmenu );
1186 case VLC_VAR_STRING:
1187 var_Get( p_object, psz_var, &val );
1188 another_val.psz_string = strdup( CURVAL.psz_string );
1189 menutext = qfu( CURTEXT ? CURTEXT : another_val.psz_string );
1190 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
1191 p_object->i_object_id, another_val, i_type,
1192 NOTCOMMAND && val.psz_string &&
1193 !strcmp( val.psz_string, CURVAL.psz_string ) );
1195 free( val.psz_string );
1198 case VLC_VAR_INTEGER:
1199 var_Get( p_object, psz_var, &val );
1200 if( CURTEXT ) menutext = qfu( CURTEXT );
1201 else menutext.sprintf( "%d", CURVAL.i_int );
1202 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
1203 p_object->i_object_id, CURVAL, i_type,
1204 NOTCOMMAND && CURVAL.i_int == val.i_int );
1208 var_Get( p_object, psz_var, &val );
1209 if( CURTEXT ) menutext = qfu( CURTEXT );
1210 else menutext.sprintf( "%.2f", CURVAL.f_float );
1211 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
1212 p_object->i_object_id, CURVAL, i_type,
1213 NOTCOMMAND && CURVAL.f_float == val.f_float );
1220 currentGroup = NULL;
1222 /* clean up everything */
1223 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
1225 #undef NORMAL_OR_RADIO
1232 void QVLCMenu::CreateAndConnect( QMenu *menu, const char *psz_var,
1233 QString text, QString help,
1234 int i_item_type, int i_object_id,
1235 vlc_value_t val, int i_val_type,
1238 QAction *action = FindActionWithVar( menu, psz_var );
1241 /* This is a value */
1242 action = FindActionWithText( menu, text );
1245 action = new QAction( text, menu );
1246 menu->addAction( action );
1250 action->setText( text );
1251 action->setToolTip( help );
1253 action->setEnabled( i_object_id != 0 );
1255 if( i_item_type == ITEM_CHECK )
1257 action->setCheckable( true );
1259 else if( i_item_type == ITEM_RADIO )
1261 action->setCheckable( true );
1263 currentGroup = new QActionGroup( menu );
1264 currentGroup->addAction( action );
1267 action->setChecked( checked );
1269 MenuItemData *itemData = new MenuItemData( i_object_id, i_val_type,
1271 CONNECT( action, triggered(), THEDP->menusMapper, map() );
1272 THEDP->menusMapper->setMapping( action, itemData );
1273 menu->addAction( action );
1276 void QVLCMenu::DoAction( intf_thread_t *p_intf, QObject *data )
1278 MenuItemData *itemData = qobject_cast<MenuItemData *>( data );
1279 vlc_object_t *p_object = ( vlc_object_t * )vlc_object_get( itemData->i_object_id );
1280 if( p_object == NULL ) return;
1282 var_Set( p_object, itemData->psz_var, itemData->val );
1283 vlc_object_release( p_object );