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>
57 static QActionGroup *currentGroup;
59 // Add static entries to menus
60 void addDPStaticEntry( QMenu *menu,
65 const char *shortcut = NULL )
67 QAction *action = NULL;
68 if( !EMPTY_STR( icon ) > 0 )
70 if( !EMPTY_STR( shortcut ) > 0 )
71 action = menu->addAction( QIcon( icon ), text, THEDP,
72 member, qtr( shortcut ) );
74 action = menu->addAction( QIcon( icon ), text, THEDP, member );
78 if( !EMPTY_STR( shortcut ) > 0 )
79 action = menu->addAction( text, THEDP, member, qtr( shortcut ) );
81 action = menu->addAction( text, THEDP, member );
83 action->setData( "_static_" );
86 void addMIMStaticEntry( intf_thread_t *p_intf,
93 if( strlen( icon ) > 0 )
95 QAction *action = menu->addAction( text, THEMIM, member );
96 action->setIcon( QIcon( icon ) );
100 menu->addAction( text, THEMIM, member );
104 void EnableDPStaticEntries( QMenu *menu, bool enable = true )
110 foreach( action, menu->actions() )
112 if( action->data().toString() == "_static_" )
113 action->setEnabled( enable );
118 * \return Number of static entries
120 int DeleteNonStaticEntries( QMenu *menu )
126 foreach( action, menu->actions() )
128 if( action->data().toString() != "_static_" )
135 /*****************************************************************************
136 * Definitions of variables for the dynamic menus
137 *****************************************************************************/
138 #define PUSH_VAR( var ) varnames.push_back( var ); \
139 objects.push_back( p_object ? p_object->i_object_id : 0 )
141 #define PUSH_INPUTVAR( var ) varnames.push_back( var ); \
142 objects.push_back( p_input ? p_input->i_object_id : 0 );
144 #define PUSH_SEPARATOR if( objects.size() != i_last_separator ) { \
145 objects.push_back( 0 ); varnames.push_back( "" ); \
146 i_last_separator = objects.size(); }
148 static int InputAutoMenuBuilder( vlc_object_t *p_object,
149 vector<int> &objects,
150 vector<const char *> &varnames )
152 PUSH_VAR( "bookmark" );
154 PUSH_VAR( "chapter" );
155 PUSH_VAR( "program" );
156 PUSH_VAR( "navigation" );
157 PUSH_VAR( "dvd_menus" );
161 static int VideoAutoMenuBuilder( vlc_object_t *p_object,
162 input_thread_t *p_input,
163 vector<int> &objects,
164 vector<const char *> &varnames )
166 PUSH_INPUTVAR( "video-es" );
167 PUSH_INPUTVAR( "spu-es" );
168 PUSH_VAR( "fullscreen" );
170 PUSH_VAR( "deinterlace" );
171 PUSH_VAR( "aspect-ratio" );
173 PUSH_VAR( "video-on-top" );
174 PUSH_VAR( "directx-wallpaper" );
175 PUSH_VAR( "video-snapshot" );
179 vlc_object_t *p_dec_obj = ( vlc_object_t * )vlc_object_find( p_object,
184 vlc_object_t *p_object = p_dec_obj;
185 PUSH_VAR( "ffmpeg-pp-q" );
186 vlc_object_release( p_dec_obj );
192 static int AudioAutoMenuBuilder( vlc_object_t *p_object,
193 input_thread_t *p_input,
194 vector<int> &objects,
195 vector<const char *> &varnames )
197 PUSH_INPUTVAR( "audio-es" );
198 PUSH_VAR( "audio-device" );
199 PUSH_VAR( "audio-channels" );
200 PUSH_VAR( "equalizer" );
201 PUSH_VAR( "visual" );
205 static QAction * FindActionWithVar( QMenu *menu, const char *psz_var )
208 foreach( action, menu->actions() )
210 if( action->data().toString() == psz_var )
216 static QAction * FindActionWithText( QMenu *menu, QString &text )
219 foreach( action, menu->actions() )
221 if( action->text() == text )
227 /*****************************************************************************
230 *****************************************************************************/
232 #define BAR_ADD( func, title ) { \
233 QMenu *_menu = func; _menu->setTitle( title ); bar->addMenu( _menu ); }
235 #define BAR_DADD( func, title, id ) { \
236 QMenu *_menu = func; _menu->setTitle( title ); bar->addMenu( _menu ); \
237 MenuFunc *f = new MenuFunc( _menu, id ); \
238 CONNECT( _menu, aboutToShow(), THEDP->menusUpdateMapper, map() ); \
239 THEDP->menusUpdateMapper->setMapping( _menu, f ); }
241 #define ACT_ADD( _menu, val, title ) { \
242 QAction *_action = new QAction( title, _menu ); _action->setData( val ); \
243 _menu->addAction( _action ); }
246 * Main Menu Bar Creation
248 void QVLCMenu::createMenuBar( MainInterface *mi,
249 intf_thread_t *p_intf,
250 bool visual_selector_enabled )
252 /* QMainWindows->menuBar()
253 gives the QProcess::destroyed timeout issue on Cleanlooks style with
254 setDesktopAware set to false */
255 QMenuBar *bar = mi->menuBar();
256 BAR_ADD( FileMenu(), qtr( "&Media" ) );
257 BAR_ADD( PlaylistMenu( p_intf, mi ), qtr( "&Playlist" ) );
258 BAR_ADD( ToolsMenu( p_intf, NULL, mi, visual_selector_enabled, true ),
260 BAR_DADD( AudioMenu( p_intf, NULL ), qtr( "&Audio" ), 1 );
261 BAR_DADD( VideoMenu( p_intf, NULL ), qtr( "&Video" ), 2 );
262 BAR_DADD( NavigMenu( p_intf, NULL ), qtr( "&Playback" ), 3 );
263 BAR_ADD( HelpMenu( NULL ), qtr( "&Help" ) );
269 * Media ( File ) Menu
270 * Opening, streaming and quit
272 QMenu *QVLCMenu::FileMenu()
274 QMenu *menu = new QMenu();
276 addDPStaticEntry( menu, qtr( "&Open File..." ), "",
277 ":/pixmaps/file-asym_16px.png", SLOT( openFileDialog() ), "Ctrl+O" );
278 addDPStaticEntry( menu, qtr( I_OPEN_FOLDER ), "",
279 ":/pixmaps/folder-grey_16px.png", SLOT( PLAppendDir() ), "Ctrl+F" );
280 addDPStaticEntry( menu, qtr( "Open &Disc..." ), "",
281 ":/pixmaps/disc_16px.png", SLOT( openDiscDialog() ), "Ctrl+D" );
282 addDPStaticEntry( menu, qtr( "Open &Network..." ), "",
283 ":/pixmaps/network_16px.png", SLOT( openNetDialog() ), "Ctrl+N" );
284 addDPStaticEntry( menu, qtr( "Open &Capture Device..." ), "",
285 ":/pixmaps/capture-card_16px.png", SLOT( openCaptureDialog() ),
287 menu->addSeparator();
289 addDPStaticEntry( menu, qtr( "&Streaming..." ), "",
290 ":/pixmaps/menus_stream_16px.png", SLOT( openThenStreamingDialogs() ),
292 addDPStaticEntry( menu, qtr( "Conve&rt / Save..." ), "", "",
293 SLOT( openThenTranscodingDialogs() ), "Ctrl+R" );
294 menu->addSeparator();
296 addDPStaticEntry( menu, qtr( "&Quit" ) , "",
297 ":/pixmaps/menus_quit_16px.png", SLOT( quit() ), "Ctrl+Q" );
301 /* Playlist/MediaLibrary Control */
302 QMenu *QVLCMenu::PlaylistMenu( intf_thread_t *p_intf, MainInterface *mi )
304 QMenu *menu = new QMenu();
305 menu->addMenu( SDMenu( p_intf ) );
306 menu->addAction( QIcon( ":/pixmaps/playlist_16px.png" ),
307 qtr( "Show Playlist" ), mi, SLOT( togglePlaylist() ) );
308 menu->addSeparator();
310 addDPStaticEntry( menu, qtr( I_PL_LOAD ), "", "", SLOT( openAPlaylist() ),
312 addDPStaticEntry( menu, qtr( I_PL_SAVE ), "", "", SLOT( saveAPlaylist() ),
314 menu->addSeparator();
315 menu->addAction( qtr( "Undock from interface" ), mi,
316 SLOT( undockPlaylist() ), qtr( "Ctrl+U" ) );
322 * This is kept in the same menu for now, but could change if it gets much
324 * This menu can be an interface menu but also a right click menu.
326 QMenu *QVLCMenu::ToolsMenu( intf_thread_t *p_intf,
329 bool visual_selector_enabled,
332 QMenu *menu = new QMenu( current );
335 menu->addAction( QIcon( ":/pixmaps/playlist_16px.png" ),
336 qtr( "Playlist..." ), mi, SLOT( togglePlaylist() ),
339 addDPStaticEntry( menu, qtr( I_MENU_EXT ), "",
340 ":/pixmaps/menus_settings_16px.png", SLOT( extendedDialog() ),
343 menu->addSeparator();
347 QMenu *intfmenu = InterfacesMenu( p_intf, menu );
348 intfmenu->setTitle( qtr( "Add Interfaces" ) );
349 MenuFunc *f = new MenuFunc( intfmenu, 4 );
350 CONNECT( intfmenu, aboutToShow(), THEDP->menusUpdateMapper, map() );
351 THEDP->menusUpdateMapper->setMapping( intfmenu, f );
352 menu->addMenu( intfmenu );
353 menu->addSeparator();
358 QAction *action=menu->addAction( qtr( "Minimal View..." ), mi,
359 SLOT( toggleMinimalView() ), qtr( "Ctrl+H" ) );
360 action->setCheckable( true );
361 if( mi->getControlsVisibilityStatus() & CONTROLS_VISIBLE )
362 action->setChecked( true );
364 /* FullScreen View */
365 action = menu->addAction( qtr( "Toggle Fullscreen Interface" ), mi,
366 SLOT( toggleFullScreen() ), qtr( "F11" ) );
368 /* Advanced Controls */
369 action = menu->addAction( qtr( "Advanced controls" ), mi,
370 SLOT( toggleAdvanced() ) );
371 action->setCheckable( true );
372 if( mi->getControlsVisibilityStatus() & CONTROLS_ADVANCED )
373 action->setChecked( true );
374 #if 0 /* For Visualisations. Not yet working */
375 adv = menu->addAction( qtr( "Visualizations selector" ),
376 mi, SLOT( visual() ) );
377 adv->setCheckable( true );
378 if( visual_selector_enabled ) adv->setChecked( true );
382 menu->addSeparator();
384 addDPStaticEntry( menu, qtr( I_MENU_MSG ), "",
385 ":/pixmaps/menus_messages_16px.png", SLOT( messagesDialog() ),
387 addDPStaticEntry( menu, qtr( I_MENU_INFO ) , "", "",
388 SLOT( mediaInfoDialog() ), "Ctrl+I" );
389 addDPStaticEntry( menu, qtr( I_MENU_CODECINFO ) , "",
390 ":/pixmaps/menus_info_16px.png", SLOT( mediaCodecDialog() ), "Ctrl+J" );
391 addDPStaticEntry( menu, qtr( I_MENU_BOOKMARK ), "","",
392 SLOT( bookmarksDialog() ), "Ctrl+B" );
394 addDPStaticEntry( menu, qtr( I_MENU_VLM ), "", "", SLOT( vlmDialog() ),
398 menu->addSeparator();
399 addDPStaticEntry( menu, qtr( "Preferences..." ), "",
400 ":/pixmaps/menus_preferences_16px.png", SLOT( prefsDialog() ), "Ctrl+P" );
405 * Interface Sub-Menu, to list extras interface and skins
407 QMenu *QVLCMenu::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
410 vector<const char *> varnames;
411 /** \todo add "switch to XXX" */
412 varnames.push_back( "intf-add" );
413 objects.push_back( p_intf->i_object_id );
415 QMenu *submenu = new QMenu( current );
416 QMenu *menu = Populate( p_intf, submenu, varnames, objects );
424 QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QMenu * current )
427 vector<const char *> varnames;
428 vlc_object_t *p_aout;
429 input_thread_t *p_input;
431 if( !current ) current = new QMenu();
433 if( current->isEmpty() )
435 ACT_ADD( current, "audio-es", qtr( "Audio &Track" ) );
436 ACT_ADD( current, "audio-device", qtr( "Audio &Device" ) );
437 ACT_ADD( current, "audio-channels", qtr( "Audio &Channels" ) );
438 ACT_ADD( current, "equalizer", qtr( "&Equalizer" ) );
439 current->addSeparator();
440 ACT_ADD( current, "visual", qtr( "&Visualizations" ) );
443 p_input = THEMIM->getInput();
445 vlc_object_yield( p_input );
446 p_aout = ( vlc_object_t * ) vlc_object_find( p_intf,
450 AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
453 vlc_object_release( p_aout );
455 vlc_object_release( p_input );
457 return Populate( p_intf, current, varnames, objects );
462 * Subtitles are part of Video.
464 QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current )
466 vlc_object_t *p_object;
467 input_thread_t *p_input;
469 vector<const char *> varnames;
471 if( !current ) current = new QMenu();
473 if( current->isEmpty() )
475 ACT_ADD( current, "video-es", qtr( "Video &Track" ) );
478 QMenu *submenu = new QMenu( qtr( "&Subtitles Track" ), current );
479 action = current->addMenu( submenu );
480 action->setData( "spu-es" );
481 addDPStaticEntry( submenu, qtr( "Load File..." ), "", "",
482 SLOT( loadSubtitlesFile() ) );
483 submenu->addSeparator();
485 ACT_ADD( current, "fullscreen", qtr( "Toggle &Fullscreen" ) );
486 ACT_ADD( current, "zoom", qtr( "&Zoom" ) );
487 ACT_ADD( current, "deinterlace", qtr( "&Deinterlace" ) );
488 ACT_ADD( current, "aspect-ratio", qtr( "&Aspect Ratio" ) );
489 ACT_ADD( current, "crop", qtr( "&Crop" ) );
490 ACT_ADD( current, "video-on-top", qtr( "Always &On Top" ) );
491 /* ACT_ADD( current, "directx-wallpaper", qtr( "DirectX Wallpaper" ) ); */
492 ACT_ADD( current, "video-snapshot", qtr( "Snapshot" ) );
493 /* ACT_ADD( current, "ffmpeg-pp-q", qtr( "Decoder" ) ); */
496 p_input = THEMIM->getInput();
498 vlc_object_yield( p_input );
499 p_object = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_VOUT,
502 VideoAutoMenuBuilder( p_object, p_input, objects, varnames );
505 vlc_object_release( p_object );
507 vlc_object_release( p_input );
509 return Populate( p_intf, current, varnames, objects );
514 * For DVD, MP4, MOV and other chapter based format
516 QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *menu )
518 vlc_object_t *p_object;
520 vector<const char *> varnames;
522 if( !menu ) menu = new QMenu();
524 if( menu->isEmpty() )
526 addDPStaticEntry( menu, qtr( I_MENU_GOTOTIME ), "","",
527 SLOT( gotoTimeDialog() ), "Ctrl+T" );
528 menu->addSeparator();
530 ACT_ADD( menu, "bookmark", qtr( "&Bookmarks" ) );
531 ACT_ADD( menu, "title", qtr( "&Title" ) );
532 ACT_ADD( menu, "chapter", qtr( "&Chapter" ) );
533 ACT_ADD( menu, "program", qtr( "&Program" ) );
534 ACT_ADD( menu, "navigation", qtr( "&Navigation" ) );
537 p_object = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_INPUT,
539 InputAutoMenuBuilder( p_object, objects, varnames );
540 PUSH_VAR( "prev-title" );
541 PUSH_VAR( "next-title" );
542 PUSH_VAR( "prev-chapter" );
543 PUSH_VAR( "next-chapter" );
544 EnableDPStaticEntries( menu, ( p_object != NULL ) );
547 vlc_object_release( p_object );
549 return Populate( p_intf, menu, varnames, objects, true );
553 * Service Discovery SubMenu
555 QMenu *QVLCMenu::SDMenu( intf_thread_t *p_intf )
557 QMenu *menu = new QMenu();
558 menu->setTitle( qtr( I_PL_SD ) );
559 char **ppsz_longnames;
560 char **ppsz_names = services_discovery_GetServicesNames( p_intf,
565 char **ppsz_name = ppsz_names, **ppsz_longname = ppsz_longnames;
566 for( ; *ppsz_name; ppsz_name++, ppsz_longname++ )
568 QAction *a = new QAction( qfu( *ppsz_longname ), menu );
569 a->setCheckable( true );
570 if( playlist_IsServicesDiscoveryLoaded( THEPL, *ppsz_name ) )
571 a->setChecked( true );
572 CONNECT( a , triggered(), THEDP->SDMapper, map() );
573 THEDP->SDMapper->setMapping( a, QString( *ppsz_name ) );
574 menu->addAction( a );
576 if( !strcmp( *ppsz_name, "podcast" ) )
578 QAction *b = new QAction( qfu( "Configure podcasts..." ), menu );
579 //b->setEnabled( a->isChecked() );
580 menu->addAction( b );
581 CONNECT( b, triggered(), THEDP, podcastConfigureDialog() );
584 free( *ppsz_longname );
587 free( ppsz_longnames );
593 QMenu *QVLCMenu::HelpMenu( QMenu *current )
595 QMenu *menu = new QMenu( current );
596 addDPStaticEntry( menu, qtr( "Help..." ) , "",
597 ":/pixmaps/menus_help_16px.png", SLOT( helpDialog() ), "F1" );
599 addDPStaticEntry( menu, qtr( "Check for updates..." ) , "", "",
600 SLOT( updateDialog() ), "");
602 menu->addSeparator();
603 addDPStaticEntry( menu, qtr( I_MENU_ABOUT ), "", "", SLOT( aboutDialog() ),
608 /*****************************************************************************
609 * Popup menus - Right Click menus *
610 *****************************************************************************/
611 #define POPUP_BOILERPLATE \
612 unsigned int i_last_separator = 0; \
613 vector<int> objects; \
614 vector<const char *> varnames; \
615 input_thread_t *p_input = THEMIM->getInput();
617 #define CREATE_POPUP \
618 Populate( p_intf, menu, varnames, objects ); \
619 p_intf->p_sys->p_popup_menu = menu; \
620 menu->popup( QCursor::pos() ); \
621 p_intf->p_sys->p_popup_menu = NULL; \
622 i_last_separator = 0;
624 void QVLCMenu::PopupMenuControlEntries( QMenu *menu,
625 intf_thread_t *p_intf,
626 input_thread_t *p_input )
631 var_Get( p_input, "state", &val );
632 if( val.i_int == PLAYING_S )
633 addMIMStaticEntry( p_intf, menu, qtr( "Pause" ), "",
634 ":/pixmaps/pause_16px.png", SLOT( togglePlayPause() ) );
636 addMIMStaticEntry( p_intf, menu, qtr( "Play" ), "",
637 ":/pixmaps/play_16px.png", SLOT( togglePlayPause() ) );
639 else if( THEPL->items.i_size )
640 addMIMStaticEntry( p_intf, menu, qtr( "Play" ), "",
641 ":/pixmaps/play_16px.png", SLOT( togglePlayPause() ) );
643 addMIMStaticEntry( p_intf, menu, qtr( "Stop" ), "",
644 ":/pixmaps/stop_16px.png", SLOT( stop() ) );
645 addMIMStaticEntry( p_intf, menu, qtr( "Previous" ), "",
646 ":/pixmaps/previous_16px.png", SLOT( prev() ) );
647 addMIMStaticEntry( p_intf, menu, qtr( "Next" ), "",
648 ":/pixmaps/next_16px.png", SLOT( next() ) );
651 void QVLCMenu::PopupMenuStaticEntries( intf_thread_t *p_intf, QMenu *menu )
654 QMenu *toolsmenu = ToolsMenu( p_intf, menu, false, true );
655 toolsmenu->setTitle( qtr( "Tools" ) );
656 menu->addMenu( toolsmenu );
659 QMenu *openmenu = new QMenu( qtr( "Open" ), menu );
660 addDPStaticEntry( openmenu, qtr( "&Open File..." ), "",
661 ":/pixmaps/file-asym_16px.png", SLOT( openFileDialog() ) );
662 addDPStaticEntry( openmenu, qtr( I_OPEN_FOLDER ), "",
663 ":/pixmaps/folder-grey_16px.png", SLOT( PLAppendDir() ) );
664 addDPStaticEntry( openmenu, qtr( "Open &Disc..." ), "",
665 ":/pixmaps/disc_16px.png", SLOT( openDiscDialog() ) );
666 addDPStaticEntry( openmenu, qtr( "Open &Network..." ), "",
667 ":/pixmaps/network_16px.png", SLOT( openNetDialog() ) );
668 addDPStaticEntry( openmenu, qtr( "Open &Capture Device..." ), "",
669 ":/pixmaps/capture-card_16px.png", SLOT( openCaptureDialog() ) );
670 menu->addMenu( openmenu );
672 menu->addSeparator();
674 QMenu *helpmenu = HelpMenu( menu );
675 helpmenu->setTitle( qtr( "Help" ) );
676 menu->addMenu( helpmenu );
679 addDPStaticEntry( menu, qtr( "Quit" ), "", ":/pixmaps/menus_quit_16px.png",
680 SLOT( quit() ), "Ctrl+Q" );
683 /* Video Tracks and Subtitles tracks */
684 void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf )
689 vlc_object_yield( p_input );
690 vlc_object_t *p_vout = ( vlc_object_t * )vlc_object_find( p_input,
691 VLC_OBJECT_VOUT, FIND_CHILD );
694 VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
695 vlc_object_release( p_vout );
697 vlc_object_release( p_input );
699 QMenu *menu = new QMenu();
704 void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf )
709 vlc_object_yield( p_input );
710 vlc_object_t *p_aout = ( vlc_object_t * )vlc_object_find( p_input,
711 VLC_OBJECT_AOUT, FIND_ANYWHERE );
712 AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
714 vlc_object_release( p_aout );
715 vlc_object_release( p_input );
717 QMenu *menu = new QMenu();
721 /* Navigation stuff, and general menus ( open ) */
722 void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf )
729 vlc_object_yield( p_input );
730 varnames.push_back( "audio-es" );
731 InputAutoMenuBuilder( VLC_OBJECT( p_input ), objects, varnames );
735 QMenu *menu = new QMenu();
736 Populate( p_intf, menu, varnames, objects );
738 menu->addSeparator();
739 PopupMenuControlEntries( menu, p_intf, p_input );
741 menu->addSeparator();
742 PopupMenuStaticEntries( p_intf, menu );
744 p_intf->p_sys->p_popup_menu = menu;
745 menu->popup( QCursor::pos() );
746 p_intf->p_sys->p_popup_menu = NULL;
749 /* Main Menu that sticks everything together */
750 void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show )
752 MainInterface *mi = p_intf->p_sys->p_mi;
755 /* Delete and recreate a popup if there is one */
756 if( p_intf->p_sys->p_popup_menu )
757 delete p_intf->p_sys->p_popup_menu;
759 QMenu *menu = new QMenu();
765 PopupMenuControlEntries( menu, p_intf, p_input );
766 menu->addSeparator();
771 vlc_object_yield( p_input );
772 InputAutoMenuBuilder( VLC_OBJECT( p_input ), objects, varnames );
773 vlc_object_release( p_input );
775 submenu = new QMenu( menu );
776 action = menu->addMenu( AudioMenu( p_intf, submenu ) );
777 action->setText( qtr( "&Audio" ) );
778 if( action->menu()->isEmpty() )
779 action->setEnabled( false );
781 submenu = new QMenu( menu );
782 action = menu->addMenu( VideoMenu( p_intf, submenu ) );
783 action->setText( qtr( "&Video" ) );
784 if( action->menu()->isEmpty() )
785 action->setEnabled( false );
787 submenu = new QMenu( menu );
788 action = menu->addMenu( NavigMenu( p_intf, submenu ) );
789 action->setText( qtr( "&Playback" ) );
790 if( action->menu()->isEmpty() )
791 action->setEnabled( false );
794 menu->addSeparator();
796 /* Add some special entries for windowed mode */
799 submenu = new QMenu( qtr( "Interface" ), menu );
800 submenu->addAction( QIcon( ":/pixmaps/playlist_16px.png" ),
801 qtr( "Show Playlist" ), mi, SLOT( togglePlaylist() ) );
802 addDPStaticEntry( submenu, qtr( I_MENU_EXT ), "",
803 ":/pixmaps/menus_settings_16px.png", SLOT( extendedDialog() ) );
804 action = submenu->addAction( QIcon( "" ),
805 qtr( "Minimal View..." ), mi, SLOT( toggleMinimalView() ) );
806 action->setCheckable( true );
807 action->setChecked( !( mi->getControlsVisibilityStatus() &
808 CONTROLS_VISIBLE ) );
809 action = submenu->addAction( QIcon( "" ),
810 qtr( "Toggle Fullscreen Interface" ),
811 mi, SLOT( toggleFullScreen() ) );
812 action->setCheckable( true );
813 action->setChecked( mi->isFullScreen() );
814 menu->addMenu( submenu );
817 PopupMenuStaticEntries( p_intf, menu );
819 p_intf->p_sys->p_popup_menu = menu;
820 p_intf->p_sys->p_popup_menu->popup( QCursor::pos() );
824 // destroy popup if there is one
825 delete p_intf->p_sys->p_popup_menu;
826 p_intf->p_sys->p_popup_menu = NULL;
832 /************************************************************************
834 ************************************************************************/
836 void QVLCMenu::updateSystrayMenu( MainInterface *mi,
837 intf_thread_t *p_intf,
838 bool b_force_visible )
842 /* Get the systray menu and clean it */
843 QMenu *sysMenu = mi->getSysTrayMenu();
846 /* Hide / Show VLC and cone */
847 if( mi->isVisible() || b_force_visible )
849 sysMenu->addAction( QIcon( ":/vlc16.png" ),
850 qtr( "Hide VLC media player in taskbar" ), mi,
851 SLOT( toggleUpdateSystrayMenu() ) );
855 sysMenu->addAction( QIcon( ":/vlc16.png" ),
856 qtr( "Show VLC media player" ), mi,
857 SLOT( toggleUpdateSystrayMenu() ) );
860 sysMenu->addSeparator();
861 PopupMenuControlEntries( sysMenu, p_intf, p_input );
863 sysMenu->addSeparator();
864 addDPStaticEntry( sysMenu, qtr( "&Open Media" ), "",
865 ":/pixmaps/file-wide_16px.png", SLOT( openFileDialog() ), "" );
866 addDPStaticEntry( sysMenu, qtr( "&Quit" ) , "",
867 ":/pixmaps/menus_quit_16px.png", SLOT( quit() ), "" );
870 mi->getSysTray()->setContextMenu( sysMenu );
874 #undef PUSH_SEPARATOR
876 /*************************************************************************
877 * Builders for automenus
878 *************************************************************************/
879 QMenu * QVLCMenu::Populate( intf_thread_t *p_intf,
881 vector< const char *> & varnames,
882 vector<int> & objects,
885 QMenu *menu = current;
886 if( !menu ) menu = new QMenu();
888 /* Disable all non static entries */
890 foreach( p_action, menu->actions() )
892 if( p_action->data().toString() != "_static_" )
893 p_action->setEnabled( false );
898 vlc_object_t *p_object;
901 for( i = 0; i < ( int )objects.size() ; i++ )
903 if( !varnames[i] || !*varnames[i] )
905 menu->addSeparator();
909 if( objects[i] == 0 )
915 p_object = ( vlc_object_t * )vlc_object_get( objects[i] );
918 msg_Dbg( p_intf, "object %d not found !", objects[i] );
923 /* Ugly specific stuff */
924 if( strstr( varnames[i], "intf-add" ) )
925 UpdateItem( p_intf, menu, varnames[i], p_object, false );
927 UpdateItem( p_intf, menu, varnames[i], p_object, true );
929 vlc_object_release( p_object );
934 /*****************************************************************************
936 *****************************************************************************/
938 static bool IsMenuEmpty( const char *psz_var,
939 vlc_object_t *p_object,
942 vlc_value_t val, val_list;
943 int i_type, i_result, i;
945 /* Check the type of the object variable */
946 i_type = var_Type( p_object, psz_var );
948 /* Check if we want to display the variable */
949 if( !( i_type & VLC_VAR_HASCHOICE ) ) return false;
951 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
952 if( val.i_int == 0 ) return true;
954 if( ( i_type & VLC_VAR_TYPE ) != VLC_VAR_VARIABLE )
956 if( val.i_int == 1 && b_root ) return true;
960 /* Check children variables in case of VLC_VAR_VARIABLE */
961 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
966 for( i = 0, i_result = true; i < val_list.p_list->i_count; i++ )
968 if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
976 /* clean up everything */
977 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, NULL );
982 #define TEXT_OR_VAR qfu ( text.psz_string ? text.psz_string : psz_var )
984 void QVLCMenu::UpdateItem( intf_thread_t *p_intf, QMenu *menu,
985 const char *psz_var, vlc_object_t *p_object, bool b_submenu )
987 vlc_value_t val, text;
990 QAction *action = FindActionWithVar( menu, psz_var );
992 DeleteNonStaticEntries( action->menu() );
997 /* Check the type of the object variable */
998 if( !strcmp( psz_var, "audio-es" )
999 || !strcmp( psz_var, "video-es" ) )
1000 i_type = VLC_VAR_INTEGER | VLC_VAR_HASCHOICE;
1002 i_type = var_Type( p_object, psz_var );
1004 switch( i_type & VLC_VAR_TYPE )
1008 case VLC_VAR_VARIABLE:
1009 case VLC_VAR_STRING:
1010 case VLC_VAR_INTEGER:
1014 /* Variable doesn't exist or isn't handled */
1018 /* Make sure we want to display the variable */
1019 if( menu->isEmpty() && IsMenuEmpty( psz_var, p_object ) )
1022 /* Get the descriptive name of the variable */
1023 int i_ret = var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
1024 if( i_ret != VLC_SUCCESS )
1026 text.psz_string = NULL;
1031 action = new QAction( TEXT_OR_VAR, menu );
1032 menu->addAction( action );
1033 action->setData( psz_var );
1036 /* Some specific stuff */
1037 bool forceDisabled = false;
1038 if( !strcmp( psz_var, "spu-es" ) )
1040 vlc_object_t *p_vout = ( vlc_object_t* )( vlc_object_find( p_intf,
1041 VLC_OBJECT_VOUT, FIND_ANYWHERE ) );
1042 forceDisabled = ( p_vout == NULL );
1044 vlc_object_release( p_vout );
1047 if( i_type & VLC_VAR_HASCHOICE )
1049 /* Append choices menu */
1053 submenu = action->menu();
1056 submenu = new QMenu( menu );
1057 action->setMenu( submenu );
1061 CreateChoicesMenu( submenu, psz_var, p_object, true ) == 0 );
1063 action->setEnabled( false );
1066 CreateChoicesMenu( menu, psz_var, p_object, true );
1067 FREENULL( text.psz_string );
1071 switch( i_type & VLC_VAR_TYPE )
1074 var_Get( p_object, psz_var, &val );
1075 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_NORMAL,
1076 p_object->i_object_id, val, i_type );
1080 var_Get( p_object, psz_var, &val );
1081 val.b_bool = !val.b_bool;
1082 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_CHECK,
1083 p_object->i_object_id, val, i_type, !val.b_bool );
1086 FREENULL( text.psz_string );
1090 int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
1091 vlc_object_t *p_object, bool b_root )
1093 vlc_value_t val, val_list, text_list;
1096 /* Check the type of the object variable */
1097 i_type = var_Type( p_object, psz_var );
1099 /* Make sure we want to display the variable */
1100 if( submenu->isEmpty() && IsMenuEmpty( psz_var, p_object, b_root ) )
1101 return VLC_EGENERIC;
1103 switch( i_type & VLC_VAR_TYPE )
1107 case VLC_VAR_VARIABLE:
1108 case VLC_VAR_STRING:
1109 case VLC_VAR_INTEGER:
1113 /* Variable doesn't exist or isn't handled */
1114 return VLC_EGENERIC;
1117 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
1118 &val_list, &text_list ) < 0 )
1120 return VLC_EGENERIC;
1123 #define NORMAL_OR_RADIO i_type & VLC_VAR_ISCOMMAND ? ITEM_NORMAL: ITEM_RADIO
1124 #define NOTCOMMAND !( i_type & VLC_VAR_ISCOMMAND )
1125 #define CURVAL val_list.p_list->p_values[i]
1126 #define CURTEXT text_list.p_list->p_values[i].psz_string
1128 for( i = 0; i < val_list.p_list->i_count; i++ )
1130 vlc_value_t another_val;
1132 QMenu *subsubmenu = new QMenu( submenu );
1134 switch( i_type & VLC_VAR_TYPE )
1136 case VLC_VAR_VARIABLE:
1137 CreateChoicesMenu( subsubmenu, CURVAL.psz_string, p_object, false );
1138 subsubmenu->setTitle( qfu( CURTEXT ? CURTEXT :CURVAL.psz_string ) );
1139 submenu->addMenu( subsubmenu );
1142 case VLC_VAR_STRING:
1143 var_Get( p_object, psz_var, &val );
1144 another_val.psz_string = strdup( CURVAL.psz_string );
1145 menutext = qfu( CURTEXT ? CURTEXT : another_val.psz_string );
1146 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
1147 p_object->i_object_id, another_val, i_type,
1148 NOTCOMMAND && val.psz_string &&
1149 !strcmp( val.psz_string, CURVAL.psz_string ) );
1151 free( val.psz_string );
1154 case VLC_VAR_INTEGER:
1155 var_Get( p_object, psz_var, &val );
1156 if( CURTEXT ) menutext = qfu( CURTEXT );
1157 else menutext.sprintf( "%d", CURVAL.i_int );
1158 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
1159 p_object->i_object_id, CURVAL, i_type,
1160 NOTCOMMAND && CURVAL.i_int == val.i_int );
1164 var_Get( p_object, psz_var, &val );
1165 if( CURTEXT ) menutext = qfu( CURTEXT );
1166 else menutext.sprintf( "%.2f", CURVAL.f_float );
1167 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
1168 p_object->i_object_id, CURVAL, i_type,
1169 NOTCOMMAND && CURVAL.f_float == val.f_float );
1176 currentGroup = NULL;
1178 /* clean up everything */
1179 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
1181 #undef NORMAL_OR_RADIO
1188 void QVLCMenu::CreateAndConnect( QMenu *menu, const char *psz_var,
1189 QString text, QString help,
1190 int i_item_type, int i_object_id,
1191 vlc_value_t val, int i_val_type,
1194 QAction *action = FindActionWithVar( menu, psz_var );
1197 /* This is a value */
1198 action = FindActionWithText( menu, text );
1201 action = new QAction( text, menu );
1202 menu->addAction( action );
1206 action->setText( text );
1207 action->setToolTip( help );
1209 action->setEnabled( i_object_id != 0 );
1211 if( i_item_type == ITEM_CHECK )
1213 action->setCheckable( true );
1215 else if( i_item_type == ITEM_RADIO )
1217 action->setCheckable( true );
1219 currentGroup = new QActionGroup( menu );
1220 currentGroup->addAction( action );
1223 action->setChecked( checked );
1225 MenuItemData *itemData = new MenuItemData( i_object_id, i_val_type,
1227 CONNECT( action, triggered(), THEDP->menusMapper, map() );
1228 THEDP->menusMapper->setMapping( action, itemData );
1229 menu->addAction( action );
1232 void QVLCMenu::DoAction( intf_thread_t *p_intf, QObject *data )
1234 MenuItemData *itemData = qobject_cast<MenuItemData *>( data );
1235 vlc_object_t *p_object = ( vlc_object_t * )vlc_object_get( itemData->i_object_id );
1236 if( p_object == NULL ) return;
1238 var_Set( p_object, itemData->psz_var, itemData->val );
1239 vlc_object_release( p_object );