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 // Add static entries to menus
76 void addDPStaticEntry( QMenu *menu,
81 const char *shortcut = NULL )
83 QAction *action = NULL;
84 if( !EMPTY_STR( icon ) > 0 )
86 if( !EMPTY_STR( shortcut ) > 0 )
87 action = menu->addAction( QIcon( icon ), text, THEDP,
88 member, qtr( shortcut ) );
90 action = menu->addAction( QIcon( icon ), text, THEDP, member );
94 if( !EMPTY_STR( shortcut ) > 0 )
95 action = menu->addAction( text, THEDP, member, qtr( shortcut ) );
97 action = menu->addAction( text, THEDP, member );
99 action->setData( "_static_" );
102 void addMIMStaticEntry( intf_thread_t *p_intf,
109 if( strlen( icon ) > 0 )
111 QAction *action = menu->addAction( text, THEMIM, member );
112 action->setIcon( QIcon( icon ) );
116 menu->addAction( text, THEMIM, member );
120 void EnableDPStaticEntries( QMenu *menu, bool enable = true )
126 foreach( action, menu->actions() )
128 if( action->data().toString() == "_static_" )
129 action->setEnabled( enable );
134 * \return Number of static entries
136 int DeleteNonStaticEntries( QMenu *menu )
142 foreach( action, menu->actions() )
144 if( action->data().toString() != "_static_" )
151 /*****************************************************************************
152 * Definitions of variables for the dynamic menus
153 *****************************************************************************/
154 #define PUSH_VAR( var ) varnames.push_back( var ); \
155 objects.push_back( p_object ? p_object->i_object_id : 0 )
157 #define PUSH_INPUTVAR( var ) varnames.push_back( var ); \
158 objects.push_back( p_input ? p_input->i_object_id : 0 );
160 #define PUSH_SEPARATOR if( objects.size() != i_last_separator ) { \
161 objects.push_back( 0 ); varnames.push_back( "" ); \
162 i_last_separator = objects.size(); }
164 static int InputAutoMenuBuilder( vlc_object_t *p_object,
165 vector<int> &objects,
166 vector<const char *> &varnames )
168 PUSH_VAR( "bookmark" );
170 PUSH_VAR( "chapter" );
171 PUSH_VAR( "program" );
172 PUSH_VAR( "navigation" );
173 PUSH_VAR( "dvd_menus" );
177 static int VideoAutoMenuBuilder( vlc_object_t *p_object,
178 input_thread_t *p_input,
179 vector<int> &objects,
180 vector<const char *> &varnames )
182 PUSH_INPUTVAR( "video-es" );
183 PUSH_INPUTVAR( "spu-es" );
184 PUSH_VAR( "fullscreen" );
186 PUSH_VAR( "deinterlace" );
187 PUSH_VAR( "aspect-ratio" );
189 PUSH_VAR( "video-on-top" );
190 PUSH_VAR( "directx-wallpaper" );
191 PUSH_VAR( "video-snapshot" );
195 vlc_object_t *p_dec_obj = ( vlc_object_t * )vlc_object_find( p_object,
200 vlc_object_t *p_object = p_dec_obj;
201 PUSH_VAR( "ffmpeg-pp-q" );
202 vlc_object_release( p_dec_obj );
208 static int AudioAutoMenuBuilder( vlc_object_t *p_object,
209 input_thread_t *p_input,
210 vector<int> &objects,
211 vector<const char *> &varnames )
213 PUSH_INPUTVAR( "audio-es" );
214 PUSH_VAR( "audio-device" );
215 PUSH_VAR( "audio-channels" );
216 PUSH_VAR( "equalizer" );
217 PUSH_VAR( "visual" );
221 static QAction * FindActionWithVar( QMenu *menu, const char *psz_var )
224 foreach( action, menu->actions() )
226 if( action->data().toString() == psz_var )
232 static QAction * FindActionWithText( QMenu *menu, QString &text )
235 foreach( action, menu->actions() )
237 if( action->text() == text )
243 /*****************************************************************************
246 *****************************************************************************/
248 #define BAR_ADD( func, title ) { \
249 QMenu *_menu = func; _menu->setTitle( title ); bar->addMenu( _menu ); }
251 #define BAR_DADD( func, title, id ) { \
252 QMenu *_menu = func; _menu->setTitle( title ); bar->addMenu( _menu ); \
253 MenuFunc *f = new MenuFunc( _menu, id ); \
254 CONNECT( _menu, aboutToShow(), THEDP->menusUpdateMapper, map() ); \
255 THEDP->menusUpdateMapper->setMapping( _menu, f ); }
257 #define ACT_ADD( _menu, val, title ) { \
258 QAction *_action = new QAction( title, _menu ); _action->setData( val ); \
259 _menu->addAction( _action ); }
262 * Main Menu Bar Creation
264 void QVLCMenu::createMenuBar( MainInterface *mi,
265 intf_thread_t *p_intf,
266 bool visual_selector_enabled )
268 /* QMainWindows->menuBar()
269 gives the QProcess::destroyed timeout issue on Cleanlooks style with
270 setDesktopAware set to false */
271 QMenuBar *bar = mi->menuBar();
272 BAR_ADD( FileMenu(), qtr( "&Media" ) );
273 BAR_ADD( PlaylistMenu( p_intf, mi ), qtr( "&Playlist" ) );
274 BAR_ADD( ToolsMenu( p_intf, NULL, mi, visual_selector_enabled, true ),
276 BAR_DADD( AudioMenu( p_intf, NULL ), qtr( "&Audio" ), 1 );
277 BAR_DADD( VideoMenu( p_intf, NULL ), qtr( "&Video" ), 2 );
278 BAR_DADD( NavigMenu( p_intf, NULL ), qtr( "&Playback" ), 3 );
279 BAR_ADD( HelpMenu( NULL ), qtr( "&Help" ) );
285 * Media ( File ) Menu
286 * Opening, streaming and quit
288 QMenu *QVLCMenu::FileMenu()
290 QMenu *menu = new QMenu();
292 addDPStaticEntry( menu, qtr( "&Open File..." ), "",
293 ":/pixmaps/file-asym_16px.png", SLOT( openFileDialog() ), "Ctrl+O" );
294 addDPStaticEntry( menu, qtr( I_OPEN_FOLDER ), "",
295 ":/pixmaps/folder-grey_16px.png", SLOT( PLAppendDir() ), "Ctrl+F" );
296 addDPStaticEntry( menu, qtr( "Open &Disc..." ), "",
297 ":/pixmaps/disc_16px.png", SLOT( openDiscDialog() ), "Ctrl+D" );
298 addDPStaticEntry( menu, qtr( "Open &Network..." ), "",
299 ":/pixmaps/network_16px.png", SLOT( openNetDialog() ), "Ctrl+N" );
300 addDPStaticEntry( menu, qtr( "Open &Capture Device..." ), "",
301 ":/pixmaps/capture-card_16px.png", SLOT( openCaptureDialog() ),
303 menu->addSeparator();
305 addDPStaticEntry( menu, qtr( "&Streaming..." ), "",
306 ":/pixmaps/menus_stream_16px.png", SLOT( openThenStreamingDialogs() ),
308 addDPStaticEntry( menu, qtr( "Conve&rt / Save..." ), "", "",
309 SLOT( openThenTranscodingDialogs() ), "Ctrl+R" );
310 menu->addSeparator();
312 addDPStaticEntry( menu, qtr( "&Quit" ) , "",
313 ":/pixmaps/menus_quit_16px.png", SLOT( quit() ), "Ctrl+Q" );
317 /* Playlist/MediaLibrary Control */
318 QMenu *QVLCMenu::PlaylistMenu( intf_thread_t *p_intf, MainInterface *mi )
320 QMenu *menu = new QMenu();
321 menu->addMenu( SDMenu( p_intf ) );
322 menu->addAction( QIcon( ":/pixmaps/playlist_16px.png" ),
323 qtr( "Show Playlist" ), mi, SLOT( togglePlaylist() ) );
324 menu->addSeparator();
326 addDPStaticEntry( menu, qtr( I_PL_LOAD ), "", "", SLOT( openAPlaylist() ),
328 addDPStaticEntry( menu, qtr( I_PL_SAVE ), "", "", SLOT( saveAPlaylist() ),
330 /*menu->addSeparator();
331 menu->addAction( qtr( "Undock from Interface" ), mi,
332 SLOT( undockPlaylist() ), qtr( "Ctrl+U" ) );*/
338 * This is kept in the same menu for now, but could change if it gets much
340 * This menu can be an interface menu but also a right click menu.
342 QMenu *QVLCMenu::ToolsMenu( intf_thread_t *p_intf,
345 bool visual_selector_enabled,
348 QMenu *menu = new QMenu( current );
351 menu->addAction( QIcon( ":/pixmaps/playlist_16px.png" ),
352 qtr( "Playlist..." ), mi, SLOT( togglePlaylist() ),
355 addDPStaticEntry( menu, qtr( I_MENU_EXT ), "",
356 ":/pixmaps/menus_settings_16px.png", SLOT( extendedDialog() ),
359 menu->addSeparator();
363 QMenu *intfmenu = InterfacesMenu( p_intf, menu );
364 intfmenu->setTitle( qtr( "Add Interfaces" ) );
365 MenuFunc *f = new MenuFunc( intfmenu, 4 );
366 CONNECT( intfmenu, aboutToShow(), THEDP->menusUpdateMapper, map() );
367 THEDP->menusUpdateMapper->setMapping( intfmenu, f );
368 menu->addMenu( intfmenu );
369 menu->addSeparator();
374 QAction *action = menu->addAction( qtr( "Minimal View..." ), mi,
375 SLOT( toggleMinimalView() ), qtr( "Ctrl+H" ) );
376 action->setCheckable( true );
377 if( mi->getControlsVisibilityStatus() & CONTROLS_VISIBLE )
378 action->setChecked( true );
380 /* FullScreen View */
381 action = menu->addAction( qtr( "Fullscreen Interface" ), mi,
382 SLOT( toggleFullScreen() ), QString( "F11" ) );
383 action->setCheckable( true );
385 /* Advanced Controls */
386 action = menu->addAction( qtr( "Advanced Controls" ), mi,
387 SLOT( toggleAdvanced() ) );
388 action->setCheckable( true );
389 if( mi->getControlsVisibilityStatus() & CONTROLS_ADVANCED )
390 action->setChecked( true );
391 #if 0 /* For Visualisations. Not yet working */
392 adv = menu->addAction( qtr( "Visualizations selector" ),
393 mi, SLOT( visual() ) );
394 adv->setCheckable( true );
395 if( visual_selector_enabled ) adv->setChecked( true );
399 menu->addSeparator();
401 addDPStaticEntry( menu, qtr( I_MENU_MSG ), "",
402 ":/pixmaps/menus_messages_16px.png", SLOT( messagesDialog() ),
404 addDPStaticEntry( menu, qtr( I_MENU_INFO ) , "", "",
405 SLOT( mediaInfoDialog() ), "Ctrl+I" );
406 addDPStaticEntry( menu, qtr( I_MENU_CODECINFO ) , "",
407 ":/pixmaps/menus_info_16px.png", SLOT( mediaCodecDialog() ), "Ctrl+J" );
408 addDPStaticEntry( menu, qtr( I_MENU_BOOKMARK ), "","",
409 SLOT( bookmarksDialog() ), "Ctrl+B" );
411 addDPStaticEntry( menu, qtr( I_MENU_VLM ), "", "", SLOT( vlmDialog() ),
415 menu->addSeparator();
416 addDPStaticEntry( menu, qtr( "Preferences..." ), "",
417 ":/pixmaps/menus_preferences_16px.png", SLOT( prefsDialog() ), "Ctrl+P" );
422 * Interface Sub-Menu, to list extras interface and skins
424 QMenu *QVLCMenu::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
427 vector<const char *> varnames;
428 /** \todo add "switch to XXX" */
429 varnames.push_back( "intf-add" );
430 objects.push_back( p_intf->i_object_id );
432 QMenu *submenu = new QMenu( current );
433 QMenu *menu = Populate( p_intf, submenu, varnames, objects );
441 QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QMenu * current )
444 vector<const char *> varnames;
445 vlc_object_t *p_aout;
446 input_thread_t *p_input;
448 if( !current ) current = new QMenu();
450 if( current->isEmpty() )
452 ACT_ADD( current, "audio-es", qtr( "Audio &Track" ) );
453 ACT_ADD( current, "audio-device", qtr( "Audio &Device" ) );
454 ACT_ADD( current, "audio-channels", qtr( "Audio &Channels" ) );
455 ACT_ADD( current, "equalizer", qtr( "&Equalizer" ) );
456 current->addSeparator();
457 ACT_ADD( current, "visual", qtr( "&Visualizations" ) );
460 p_input = THEMIM->getInput();
462 vlc_object_yield( p_input );
463 p_aout = ( vlc_object_t * ) vlc_object_find( p_intf,
467 AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
470 vlc_object_release( p_aout );
472 vlc_object_release( p_input );
474 return Populate( p_intf, current, varnames, objects );
479 * Subtitles are part of Video.
481 QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current )
483 vlc_object_t *p_vout;
484 input_thread_t *p_input;
486 vector<const char *> varnames;
488 if( !current ) current = new QMenu();
490 if( current->isEmpty() )
492 ACT_ADD( current, "video-es", qtr( "Video &Track" ) );
495 QMenu *submenu = new QMenu( qtr( "&Subtitles Track" ), current );
496 action = current->addMenu( submenu );
497 action->setData( "spu-es" );
498 addDPStaticEntry( submenu, qtr( "Load File..." ), "", "",
499 SLOT( loadSubtitlesFile() ) );
500 submenu->addSeparator();
502 ACT_ADD( current, "fullscreen", qtr( "Toggle &Fullscreen" ) );
503 ACT_ADD( current, "zoom", qtr( "&Zoom" ) );
504 ACT_ADD( current, "deinterlace", qtr( "&Deinterlace" ) );
505 ACT_ADD( current, "aspect-ratio", qtr( "&Aspect Ratio" ) );
506 ACT_ADD( current, "crop", qtr( "&Crop" ) );
507 ACT_ADD( current, "video-on-top", qtr( "Always &On Top" ) );
508 /* ACT_ADD( current, "directx-wallpaper", qtr( "DirectX Wallpaper" ) ); */
509 ACT_ADD( current, "video-snapshot", qtr( "Snapshot" ) );
510 /* ACT_ADD( current, "ffmpeg-pp-q", qtr( "Decoder" ) ); */
513 p_input = THEMIM->getInput();
515 vlc_object_yield( p_input );
516 p_vout = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_VOUT,
519 VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
522 vlc_object_release( p_vout );
524 vlc_object_release( p_input );
526 return Populate( p_intf, current, varnames, objects );
531 * For DVD, MP4, MOV and other chapter based format
533 QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *menu )
535 vlc_object_t *p_object;
537 vector<const char *> varnames;
539 if( !menu ) menu = new QMenu();
541 if( menu->isEmpty() )
543 addDPStaticEntry( menu, qtr( I_MENU_GOTOTIME ), "","",
544 SLOT( gotoTimeDialog() ), "Ctrl+T" );
545 menu->addSeparator();
547 ACT_ADD( menu, "bookmark", qtr( "&Bookmarks" ) );
548 ACT_ADD( menu, "title", qtr( "&Title" ) );
549 ACT_ADD( menu, "chapter", qtr( "&Chapter" ) );
550 ACT_ADD( menu, "program", qtr( "&Program" ) );
551 ACT_ADD( menu, "navigation", qtr( "&Navigation" ) );
554 p_object = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_INPUT,
556 InputAutoMenuBuilder( p_object, objects, varnames );
557 PUSH_VAR( "prev-title" );
558 PUSH_VAR( "next-title" );
559 PUSH_VAR( "prev-chapter" );
560 PUSH_VAR( "next-chapter" );
561 EnableDPStaticEntries( menu, ( p_object != NULL ) );
564 vlc_object_release( p_object );
566 return Populate( p_intf, menu, varnames, objects, true );
570 * Service Discovery SubMenu
572 QMenu *QVLCMenu::SDMenu( intf_thread_t *p_intf )
574 QMenu *menu = new QMenu();
575 menu->setTitle( qtr( I_PL_SD ) );
576 char **ppsz_longnames;
577 char **ppsz_names = services_discovery_GetServicesNames( p_intf,
582 char **ppsz_name = ppsz_names, **ppsz_longname = ppsz_longnames;
583 for( ; *ppsz_name; ppsz_name++, ppsz_longname++ )
585 QAction *a = new QAction( qfu( *ppsz_longname ), menu );
586 a->setCheckable( true );
587 if( playlist_IsServicesDiscoveryLoaded( THEPL, *ppsz_name ) )
588 a->setChecked( true );
589 CONNECT( a , triggered(), THEDP->SDMapper, map() );
590 THEDP->SDMapper->setMapping( a, QString( *ppsz_name ) );
591 menu->addAction( a );
593 if( !strcmp( *ppsz_name, "podcast" ) )
595 QAction *b = new QAction( qtr( "Configure podcasts..." ), menu );
596 //b->setEnabled( a->isChecked() );
597 menu->addAction( b );
598 CONNECT( b, triggered(), THEDP, podcastConfigureDialog() );
601 free( *ppsz_longname );
604 free( ppsz_longnames );
610 QMenu *QVLCMenu::HelpMenu( QMenu *current )
612 QMenu *menu = new QMenu( current );
613 addDPStaticEntry( menu, qtr( "Help..." ) , "",
614 ":/pixmaps/menus_help_16px.png", SLOT( helpDialog() ), "F1" );
616 addDPStaticEntry( menu, qtr( "Check for Updates..." ) , "", "",
617 SLOT( updateDialog() ), "");
619 menu->addSeparator();
620 addDPStaticEntry( menu, qtr( I_MENU_ABOUT ), "", "", SLOT( aboutDialog() ),
625 /*****************************************************************************
626 * Popup menus - Right Click menus *
627 *****************************************************************************/
628 #define POPUP_BOILERPLATE \
629 unsigned int i_last_separator = 0; \
630 vector<int> objects; \
631 vector<const char *> varnames; \
632 input_thread_t *p_input = THEMIM->getInput();
634 #define CREATE_POPUP \
635 Populate( p_intf, menu, varnames, objects ); \
636 p_intf->p_sys->p_popup_menu = menu; \
637 menu->popup( QCursor::pos() ); \
638 p_intf->p_sys->p_popup_menu = NULL; \
639 i_last_separator = 0;
641 void QVLCMenu::PopupMenuControlEntries( QMenu *menu,
642 intf_thread_t *p_intf,
643 input_thread_t *p_input )
648 var_Get( p_input, "state", &val );
649 if( val.i_int == PLAYING_S )
650 addMIMStaticEntry( p_intf, menu, qtr( "Pause" ), "",
651 ":/pixmaps/pause_16px.png", SLOT( togglePlayPause() ) );
653 addMIMStaticEntry( p_intf, menu, qtr( "Play" ), "",
654 ":/pixmaps/play_16px.png", SLOT( togglePlayPause() ) );
656 else if( THEPL->items.i_size )
657 addMIMStaticEntry( p_intf, menu, qtr( "Play" ), "",
658 ":/pixmaps/play_16px.png", SLOT( togglePlayPause() ) );
660 addDPStaticEntry( menu, qtr( "Play" ), "",
661 ":/pixmaps/play_16px.png", SLOT( openDialog() ) );
663 addMIMStaticEntry( p_intf, menu, qtr( "Stop" ), "",
664 ":/pixmaps/stop_16px.png", SLOT( stop() ) );
665 addMIMStaticEntry( p_intf, menu, qtr( "Previous" ), "",
666 ":/pixmaps/previous_16px.png", SLOT( prev() ) );
667 addMIMStaticEntry( p_intf, menu, qtr( "Next" ), "",
668 ":/pixmaps/next_16px.png", SLOT( next() ) );
671 void QVLCMenu::PopupMenuStaticEntries( intf_thread_t *p_intf, QMenu *menu )
674 QMenu *toolsmenu = ToolsMenu( p_intf, menu, false, true );
675 toolsmenu->setTitle( qtr( "Tools" ) );
676 menu->addMenu( toolsmenu );
679 QMenu *openmenu = new QMenu( qtr( "Open" ), menu );
680 addDPStaticEntry( openmenu, qtr( "&Open File..." ), "",
681 ":/pixmaps/file-asym_16px.png", SLOT( openFileDialog() ) );
682 addDPStaticEntry( openmenu, qtr( I_OPEN_FOLDER ), "",
683 ":/pixmaps/folder-grey_16px.png", SLOT( PLAppendDir() ) );
684 addDPStaticEntry( openmenu, qtr( "Open &Disc..." ), "",
685 ":/pixmaps/disc_16px.png", SLOT( openDiscDialog() ) );
686 addDPStaticEntry( openmenu, qtr( "Open &Network..." ), "",
687 ":/pixmaps/network_16px.png", SLOT( openNetDialog() ) );
688 addDPStaticEntry( openmenu, qtr( "Open &Capture Device..." ), "",
689 ":/pixmaps/capture-card_16px.png", SLOT( openCaptureDialog() ) );
690 menu->addMenu( openmenu );
692 menu->addSeparator();
694 QMenu *helpmenu = HelpMenu( menu );
695 helpmenu->setTitle( qtr( "Help" ) );
696 menu->addMenu( helpmenu );
699 addDPStaticEntry( menu, qtr( "Quit" ), "", ":/pixmaps/menus_quit_16px.png",
700 SLOT( quit() ), "Ctrl+Q" );
703 /* Video Tracks and Subtitles tracks */
704 void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf )
709 vlc_object_yield( p_input );
710 vlc_object_t *p_vout = ( vlc_object_t * )vlc_object_find( p_input,
711 VLC_OBJECT_VOUT, FIND_CHILD );
714 VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
715 vlc_object_release( p_vout );
717 vlc_object_release( p_input );
719 QMenu *menu = new QMenu();
724 void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf )
729 vlc_object_yield( p_input );
730 vlc_object_t *p_aout = ( vlc_object_t * )vlc_object_find( p_input,
731 VLC_OBJECT_AOUT, FIND_ANYWHERE );
732 AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
734 vlc_object_release( p_aout );
735 vlc_object_release( p_input );
737 QMenu *menu = new QMenu();
741 /* Navigation stuff, and general menus ( open ) */
742 void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf )
749 vlc_object_yield( p_input );
750 varnames.push_back( "audio-es" );
751 InputAutoMenuBuilder( VLC_OBJECT( p_input ), objects, varnames );
755 QMenu *menu = new QMenu();
756 Populate( p_intf, menu, varnames, objects );
758 menu->addSeparator();
759 PopupMenuControlEntries( menu, p_intf, p_input );
761 menu->addSeparator();
762 PopupMenuStaticEntries( p_intf, menu );
764 p_intf->p_sys->p_popup_menu = menu;
765 menu->popup( QCursor::pos() );
766 p_intf->p_sys->p_popup_menu = NULL;
769 /* Main Menu that sticks everything together */
770 void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show )
772 MainInterface *mi = p_intf->p_sys->p_mi;
775 /* Delete and recreate a popup if there is one */
776 if( p_intf->p_sys->p_popup_menu )
777 delete p_intf->p_sys->p_popup_menu;
779 QMenu *menu = new QMenu();
782 bool b_isFullscreen = false;
786 PopupMenuControlEntries( menu, p_intf, p_input );
787 menu->addSeparator();
791 vlc_object_t *p_vout = (vlc_object_t *)
792 vlc_object_find( p_input, VLC_OBJECT_VOUT, FIND_CHILD );
794 /* Add a fullscreen switch button */
798 var_Get( p_vout, "fullscreen", &val );
799 b_isFullscreen = !( !val.b_bool );
801 CreateAndConnect( menu, "fullscreen",
802 qtr( "Leave Fullscreen" ),"" , ITEM_NORMAL,
803 p_vout->i_object_id, val, VLC_VAR_BOOL,
805 vlc_object_release( p_vout );
808 menu->addSeparator();
810 vlc_object_yield( p_input );
811 InputAutoMenuBuilder( VLC_OBJECT( p_input ), objects, varnames );
812 vlc_object_release( p_input );
814 submenu = new QMenu( menu );
815 action = menu->addMenu( AudioMenu( p_intf, submenu ) );
816 action->setText( qtr( "&Audio" ) );
817 if( action->menu()->isEmpty() )
818 action->setEnabled( false );
820 submenu = new QMenu( menu );
821 action = menu->addMenu( VideoMenu( p_intf, submenu ) );
822 action->setText( qtr( "&Video" ) );
823 if( action->menu()->isEmpty() )
824 action->setEnabled( false );
826 submenu = new QMenu( menu );
827 action = menu->addMenu( NavigMenu( p_intf, submenu ) );
828 action->setText( qtr( "&Playback" ) );
829 if( action->menu()->isEmpty() )
830 action->setEnabled( false );
833 menu->addSeparator();
835 /* Add some special entries for windowed mode: Interface Menu */
836 if( !b_isFullscreen )
838 submenu = new QMenu( qtr( "Interface" ), menu );
839 submenu->addAction( QIcon( ":/pixmaps/playlist_16px.png" ),
840 qtr( "Show Playlist" ), mi, SLOT( togglePlaylist() ) );
841 addDPStaticEntry( submenu, qtr( I_MENU_EXT ), "",
842 ":/pixmaps/menus_settings_16px.png", SLOT( extendedDialog() ) );
843 action = submenu->addAction( QIcon( "" ),
844 qtr( "Minimal View..." ), mi, SLOT( toggleMinimalView() ) );
845 action->setCheckable( true );
846 action->setChecked( !( mi->getControlsVisibilityStatus() &
847 CONTROLS_VISIBLE ) );
848 action = submenu->addAction( QIcon( "" ),
849 qtr( "Toggle Fullscreen Interface" ),
850 mi, SLOT( toggleFullScreen() ) );
851 action->setCheckable( true );
852 action->setChecked( mi->isFullScreen() );
853 menu->addMenu( submenu );
856 PopupMenuStaticEntries( p_intf, menu );
858 p_intf->p_sys->p_popup_menu = menu;
859 p_intf->p_sys->p_popup_menu->popup( QCursor::pos() );
863 // destroy popup if there is one
864 delete p_intf->p_sys->p_popup_menu;
865 p_intf->p_sys->p_popup_menu = NULL;
871 /************************************************************************
873 ************************************************************************/
875 void QVLCMenu::updateSystrayMenu( MainInterface *mi,
876 intf_thread_t *p_intf,
877 bool b_force_visible )
881 /* Get the systray menu and clean it */
882 QMenu *sysMenu = mi->getSysTrayMenu();
885 /* Hide / Show VLC and cone */
886 if( mi->isVisible() || b_force_visible )
888 sysMenu->addAction( QIcon( ":/vlc16.png" ),
889 qtr( "Hide VLC media player in taskbar" ), mi,
890 SLOT( toggleUpdateSystrayMenu() ) );
894 sysMenu->addAction( QIcon( ":/vlc16.png" ),
895 qtr( "Show VLC media player" ), mi,
896 SLOT( toggleUpdateSystrayMenu() ) );
899 sysMenu->addSeparator();
900 PopupMenuControlEntries( sysMenu, p_intf, p_input );
902 sysMenu->addSeparator();
903 addDPStaticEntry( sysMenu, qtr( "&Open Media" ), "",
904 ":/pixmaps/file-wide_16px.png", SLOT( openFileDialog() ), "" );
905 addDPStaticEntry( sysMenu, qtr( "&Quit" ) , "",
906 ":/pixmaps/menus_quit_16px.png", SLOT( quit() ), "" );
909 mi->getSysTray()->setContextMenu( sysMenu );
913 #undef PUSH_SEPARATOR
915 /*************************************************************************
916 * Builders for automenus
917 *************************************************************************/
918 QMenu * QVLCMenu::Populate( intf_thread_t *p_intf,
920 vector< const char *> & varnames,
921 vector<int> & objects,
924 QMenu *menu = current;
925 if( !menu ) menu = new QMenu();
927 /* Disable all non static entries */
929 foreach( p_action, menu->actions() )
931 if( p_action->data().toString() != "_static_" )
932 p_action->setEnabled( false );
937 vlc_object_t *p_object;
940 for( i = 0; i < ( int )objects.size() ; i++ )
942 if( !varnames[i] || !*varnames[i] )
944 menu->addSeparator();
948 if( objects[i] == 0 )
954 p_object = ( vlc_object_t * )vlc_object_get( objects[i] );
957 msg_Dbg( p_intf, "object %d not found !", objects[i] );
962 /* Ugly specific stuff */
963 if( strstr( varnames[i], "intf-add" ) )
964 UpdateItem( p_intf, menu, varnames[i], p_object, false );
966 UpdateItem( p_intf, menu, varnames[i], p_object, true );
968 vlc_object_release( p_object );
973 /*****************************************************************************
975 *****************************************************************************/
977 static bool IsMenuEmpty( const char *psz_var,
978 vlc_object_t *p_object,
981 vlc_value_t val, val_list;
982 int i_type, i_result, i;
984 /* Check the type of the object variable */
985 i_type = var_Type( p_object, psz_var );
987 /* Check if we want to display the variable */
988 if( !( i_type & VLC_VAR_HASCHOICE ) ) return false;
990 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
991 if( val.i_int == 0 ) return true;
993 if( ( i_type & VLC_VAR_TYPE ) != VLC_VAR_VARIABLE )
995 if( val.i_int == 1 && b_root ) return true;
999 /* Check children variables in case of VLC_VAR_VARIABLE */
1000 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
1005 for( i = 0, i_result = true; i < val_list.p_list->i_count; i++ )
1007 if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
1015 /* clean up everything */
1016 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, NULL );
1021 #define TEXT_OR_VAR qfu ( text.psz_string ? text.psz_string : psz_var )
1023 void QVLCMenu::UpdateItem( intf_thread_t *p_intf, QMenu *menu,
1024 const char *psz_var, vlc_object_t *p_object, bool b_submenu )
1026 vlc_value_t val, text;
1029 QAction *action = FindActionWithVar( menu, psz_var );
1031 DeleteNonStaticEntries( action->menu() );
1036 /* Check the type of the object variable */
1037 if( !strcmp( psz_var, "audio-es" )
1038 || !strcmp( psz_var, "video-es" ) )
1039 i_type = VLC_VAR_INTEGER | VLC_VAR_HASCHOICE;
1041 i_type = var_Type( p_object, psz_var );
1043 switch( i_type & VLC_VAR_TYPE )
1047 case VLC_VAR_VARIABLE:
1048 case VLC_VAR_STRING:
1049 case VLC_VAR_INTEGER:
1053 /* Variable doesn't exist or isn't handled */
1057 /* Make sure we want to display the variable */
1058 if( menu->isEmpty() && IsMenuEmpty( psz_var, p_object ) )
1061 /* Get the descriptive name of the variable */
1062 int i_ret = var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
1063 if( i_ret != VLC_SUCCESS )
1065 text.psz_string = NULL;
1070 action = new QAction( TEXT_OR_VAR, menu );
1071 menu->addAction( action );
1072 action->setData( psz_var );
1075 /* Some specific stuff */
1076 bool forceDisabled = false;
1077 if( !strcmp( psz_var, "spu-es" ) )
1079 vlc_object_t *p_vout = ( vlc_object_t* )( vlc_object_find( p_intf,
1080 VLC_OBJECT_VOUT, FIND_ANYWHERE ) );
1081 forceDisabled = ( p_vout == NULL );
1083 vlc_object_release( p_vout );
1086 if( i_type & VLC_VAR_HASCHOICE )
1088 /* Append choices menu */
1092 submenu = action->menu();
1095 submenu = new QMenu( menu );
1096 action->setMenu( submenu );
1100 CreateChoicesMenu( submenu, psz_var, p_object, true ) == 0 );
1102 action->setEnabled( false );
1105 CreateChoicesMenu( menu, psz_var, p_object, true );
1106 FREENULL( text.psz_string );
1110 switch( i_type & VLC_VAR_TYPE )
1113 var_Get( p_object, psz_var, &val );
1114 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_NORMAL,
1115 p_object->i_object_id, val, i_type );
1119 var_Get( p_object, psz_var, &val );
1120 val.b_bool = !val.b_bool;
1121 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_CHECK,
1122 p_object->i_object_id, val, i_type, !val.b_bool );
1125 FREENULL( text.psz_string );
1129 int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
1130 vlc_object_t *p_object, bool b_root )
1132 vlc_value_t val, val_list, text_list;
1135 /* Check the type of the object variable */
1136 i_type = var_Type( p_object, psz_var );
1138 /* Make sure we want to display the variable */
1139 if( submenu->isEmpty() && IsMenuEmpty( psz_var, p_object, b_root ) )
1140 return VLC_EGENERIC;
1142 switch( i_type & VLC_VAR_TYPE )
1146 case VLC_VAR_VARIABLE:
1147 case VLC_VAR_STRING:
1148 case VLC_VAR_INTEGER:
1152 /* Variable doesn't exist or isn't handled */
1153 return VLC_EGENERIC;
1156 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
1157 &val_list, &text_list ) < 0 )
1159 return VLC_EGENERIC;
1162 #define NORMAL_OR_RADIO i_type & VLC_VAR_ISCOMMAND ? ITEM_NORMAL: ITEM_RADIO
1163 #define NOTCOMMAND !( i_type & VLC_VAR_ISCOMMAND )
1164 #define CURVAL val_list.p_list->p_values[i]
1165 #define CURTEXT text_list.p_list->p_values[i].psz_string
1167 for( i = 0; i < val_list.p_list->i_count; i++ )
1169 vlc_value_t another_val;
1171 QMenu *subsubmenu = new QMenu( submenu );
1173 switch( i_type & VLC_VAR_TYPE )
1175 case VLC_VAR_VARIABLE:
1176 CreateChoicesMenu( subsubmenu, CURVAL.psz_string, p_object, false );
1177 subsubmenu->setTitle( qfu( CURTEXT ? CURTEXT :CURVAL.psz_string ) );
1178 submenu->addMenu( subsubmenu );
1181 case VLC_VAR_STRING:
1182 var_Get( p_object, psz_var, &val );
1183 another_val.psz_string = strdup( CURVAL.psz_string );
1184 menutext = qfu( CURTEXT ? CURTEXT : another_val.psz_string );
1185 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
1186 p_object->i_object_id, another_val, i_type,
1187 NOTCOMMAND && val.psz_string &&
1188 !strcmp( val.psz_string, CURVAL.psz_string ) );
1190 free( val.psz_string );
1193 case VLC_VAR_INTEGER:
1194 var_Get( p_object, psz_var, &val );
1195 if( CURTEXT ) menutext = qfu( CURTEXT );
1196 else menutext.sprintf( "%d", CURVAL.i_int );
1197 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
1198 p_object->i_object_id, CURVAL, i_type,
1199 NOTCOMMAND && CURVAL.i_int == val.i_int );
1203 var_Get( p_object, psz_var, &val );
1204 if( CURTEXT ) menutext = qfu( CURTEXT );
1205 else menutext.sprintf( "%.2f", CURVAL.f_float );
1206 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
1207 p_object->i_object_id, CURVAL, i_type,
1208 NOTCOMMAND && CURVAL.f_float == val.f_float );
1215 currentGroup = NULL;
1217 /* clean up everything */
1218 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
1220 #undef NORMAL_OR_RADIO
1227 void QVLCMenu::CreateAndConnect( QMenu *menu, const char *psz_var,
1228 QString text, QString help,
1229 int i_item_type, int i_object_id,
1230 vlc_value_t val, int i_val_type,
1233 QAction *action = FindActionWithVar( menu, psz_var );
1236 /* This is a value */
1237 action = FindActionWithText( menu, text );
1240 action = new QAction( text, menu );
1241 menu->addAction( action );
1245 action->setText( text );
1246 action->setToolTip( help );
1248 action->setEnabled( i_object_id != 0 );
1250 if( i_item_type == ITEM_CHECK )
1252 action->setCheckable( true );
1254 else if( i_item_type == ITEM_RADIO )
1256 action->setCheckable( true );
1258 currentGroup = new QActionGroup( menu );
1259 currentGroup->addAction( action );
1262 action->setChecked( checked );
1264 MenuItemData *itemData = new MenuItemData( i_object_id, i_val_type,
1266 CONNECT( action, triggered(), THEDP->menusMapper, map() );
1267 THEDP->menusMapper->setMapping( action, itemData );
1268 menu->addAction( action );
1271 void QVLCMenu::DoAction( intf_thread_t *p_intf, QObject *data )
1273 MenuItemData *itemData = qobject_cast<MenuItemData *>( data );
1274 vlc_object_t *p_object = ( vlc_object_t * )vlc_object_get( itemData->i_object_id );
1275 if( p_object == NULL ) return;
1277 var_Set( p_object, itemData->psz_var, itemData->val );
1278 vlc_object_release( p_object );