1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright ( C ) 2006-2007 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
8 * Jean-Baptiste Kempf <jb@videolan.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * ( at your option ) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
31 #include <vlc_intf_strings.h>
33 #include "main_interface.hpp"
35 #include "dialogs_provider.hpp"
36 #include "input_manager.hpp"
41 #include <QActionGroup>
42 #include <QSignalMapper>
43 #include <QSystemTrayIcon>
52 static QActionGroup *currentGroup;
54 // Add static entries to menus
55 void addDPStaticEntry( QMenu *menu,
62 if( !EMPTY_STR( icon ) > 0 )
64 if( !EMPTY_STR( shortcut ) > 0 )
65 menu->addAction( QIcon( icon ), text, THEDP, member, qtr( shortcut ) );
67 menu->addAction( QIcon( icon ), text, THEDP, member );
71 if( !EMPTY_STR( shortcut ) > 0 )
72 menu->addAction( text, THEDP, member, qtr( shortcut ) );
74 menu->addAction( text, THEDP, member );
78 void addMIMStaticEntry( intf_thread_t *p_intf,
85 if( strlen( icon ) > 0 )
87 QAction *action = menu->addAction( text, THEMIM, member );
88 action->setIcon( QIcon( icon ) );
92 menu->addAction( text, THEMIM, member );
96 /*****************************************************************************
97 * Definitions of variables for the dynamic menus
98 *****************************************************************************/
99 #define PUSH_VAR( var ) varnames.push_back( var ); \
100 objects.push_back( p_object->i_object_id )
102 #define PUSH_SEPARATOR if( objects.size() != i_last_separator ) { \
103 objects.push_back( 0 ); varnames.push_back( "" ); \
104 i_last_separator = objects.size(); }
106 static int InputAutoMenuBuilder( vlc_object_t *p_object,
107 vector<int> &objects,
108 vector<const char *> &varnames )
110 PUSH_VAR( "bookmark" );
112 PUSH_VAR( "chapter" );
113 PUSH_VAR( "program" );
114 PUSH_VAR( "navigation" );
115 PUSH_VAR( "dvd_menus" );
119 static int VideoAutoMenuBuilder( vlc_object_t *p_object,
120 vector<int> &objects,
121 vector<const char *> &varnames )
123 PUSH_VAR( "fullscreen" );
125 PUSH_VAR( "deinterlace" );
126 PUSH_VAR( "aspect-ratio" );
128 PUSH_VAR( "video-on-top" );
129 PUSH_VAR( "directx-wallpaper" );
130 PUSH_VAR( "video-snapshot" );
132 vlc_object_t *p_dec_obj = ( vlc_object_t * )vlc_object_find( p_object,
135 if( p_dec_obj != NULL )
137 vlc_object_t *p_object = p_dec_obj;
138 PUSH_VAR( "ffmpeg-pp-q" );
139 vlc_object_release( p_dec_obj );
144 static int AudioAutoMenuBuilder( vlc_object_t *p_object,
145 vector<int> &objects,
146 vector<const char *> &varnames )
148 PUSH_VAR( "audio-device" );
149 PUSH_VAR( "audio-channels" );
150 PUSH_VAR( "visual" );
151 PUSH_VAR( "equalizer" );
155 /*****************************************************************************
158 *****************************************************************************/
160 #define BAR_ADD( func, title ) { \
161 QMenu *menu = func; menu->setTitle( title ); bar->addMenu( menu ); }
163 #define BAR_DADD( func, title, id ) { \
164 QMenu *menu = func; menu->setTitle( title ); bar->addMenu( menu ); \
165 MenuFunc *f = new MenuFunc( menu, id ); \
166 CONNECT( menu, aboutToShow(), THEDP->menusUpdateMapper, map() ); \
167 THEDP->menusUpdateMapper->setMapping( menu, f ); }
170 * Main Menu Bar Creation
172 void QVLCMenu::createMenuBar( MainInterface *mi,
173 intf_thread_t *p_intf,
174 bool visual_selector_enabled )
176 QMenuBar *bar = mi->menuBar();
177 BAR_ADD( FileMenu(), qtr( "&Media" ) );
178 BAR_ADD( PlaylistMenu( p_intf, mi ), qtr( "&Playlist" ) );
179 BAR_ADD( ToolsMenu( p_intf, mi, visual_selector_enabled, true ),
181 BAR_DADD( AudioMenu( p_intf, NULL ), qtr( "&Audio" ), 2 );
182 BAR_DADD( VideoMenu( p_intf, NULL ), qtr( "&Video" ), 1 );
183 BAR_DADD( NavigMenu( p_intf, NULL ), qtr( "&Playback" ), 3 );
185 BAR_ADD( HelpMenu(), qtr( "&Help" ) );
191 * Media ( File ) Menu
192 * Opening, streaming and quit
194 QMenu *QVLCMenu::FileMenu()
196 QMenu *menu = new QMenu();
198 addDPStaticEntry( menu, qtr( "&Open File..." ), "",
199 ":/pixmaps/file-asym_16px.png", SLOT( openFileDialog() ), "Ctrl+O" );
200 addDPStaticEntry( menu, qtr( I_OPEN_FOLDER ), "",
201 ":/pixmaps/folder-grey_16px.png", SLOT( PLAppendDir() ), "Ctrl+F" );
202 addDPStaticEntry( menu, qtr( "Open &Disc..." ), "",
203 ":/pixmaps/disc_16px.png", SLOT( openDiscDialog() ), "Ctrl+D" );
204 addDPStaticEntry( menu, qtr( "Open &Network..." ), "",
205 ":/pixmaps/network_16px.png", SLOT( openNetDialog() ), "Ctrl+N" );
206 addDPStaticEntry( menu, qtr( "Open &Capture Device..." ), "",
207 ":/pixmaps/capture-card_16px.png", SLOT( openCaptureDialog() ),
209 menu->addSeparator();
211 addDPStaticEntry( menu, qtr( "&Streaming..." ), "",
212 ":/pixmaps/menus_stream_16px.png", SLOT( openThenStreamingDialogs() ),
214 addDPStaticEntry( menu, qtr( "Conve&rt / Save..." ), "", "",
215 SLOT( openThenTranscodingDialogs() ), "Ctrl+R" );
216 menu->addSeparator();
218 addDPStaticEntry( menu, qtr( "&Quit" ) , "",
219 ":/pixmaps/menus_quit_16px.png", SLOT( quit() ), "Ctrl+Q" );
223 /* Playlist/MediaLibrary Control */
224 QMenu *QVLCMenu::PlaylistMenu( intf_thread_t *p_intf, MainInterface *mi )
226 QMenu *menu = new QMenu();
227 menu->addMenu( SDMenu( p_intf ) );
228 menu->addAction( QIcon( ":/pixmaps/playlist_16px.png" ),
229 qtr( "Show Playlist" ), mi, SLOT( togglePlaylist() ) );
230 menu->addSeparator();
232 addDPStaticEntry( menu, qtr( I_PL_LOAD ), "", "", SLOT( openAPlaylist() ),
234 addDPStaticEntry( menu, qtr( I_PL_SAVE ), "", "", SLOT( saveAPlaylist() ),
236 menu->addSeparator();
237 menu->addAction( qtr( "Undock from interface" ), mi,
238 SLOT( undockPlaylist() ), qtr( "Ctrl+U" ) );
244 * This is kept in the same menu for now, but could change if it gets much
246 * This menu can be an interface menu but also a right click menu.
248 QMenu *QVLCMenu::ToolsMenu( intf_thread_t *p_intf,
250 bool visual_selector_enabled,
253 QMenu *menu = new QMenu;
256 menu->addAction( QIcon( ":/pixmaps/playlist_16px.png" ),
257 qtr( "Playlist..." ), mi, SLOT( togglePlaylist() ),
260 addDPStaticEntry( menu, qtr( I_MENU_EXT ), "",
261 ":/pixmaps/menus_settings_16px.png", SLOT( extendedDialog() ),
264 menu->addSeparator();
268 QMenu *intfmenu = InterfacesMenu( p_intf, NULL );
269 intfmenu->setTitle( qtr( "Interfaces" ) );
270 menu->addMenu( intfmenu );
271 menu->addSeparator();
276 QAction *action=menu->addAction( qtr( "Minimal View..." ), mi,
277 SLOT( toggleMinimalView() ), qtr( "Ctrl+H" ) );
278 action->setCheckable( true );
279 if( mi->getControlsVisibilityStatus() & CONTROLS_VISIBLE )
280 action->setChecked( true );
282 /* FullScreen View */
283 action = menu->addAction( qtr( "Toggle Fullscreen Interface" ), mi,
284 SLOT( toggleFullScreen() ), qtr( "F11" ) );
286 /* Advanced Controls */
287 action = menu->addAction( qtr( "Advanced controls" ), mi,
288 SLOT( toggleAdvanced() ) );
289 action->setCheckable( true );
290 if( mi->getControlsVisibilityStatus() & CONTROLS_ADVANCED )
291 action->setChecked( true );
292 #if 0 /* For Visualisations. Not yet working */
293 adv = menu->addAction( qtr( "Visualizations selector" ),
294 mi, SLOT( visual() ) );
295 adv->setCheckable( true );
296 if( visual_selector_enabled ) adv->setChecked( true );
300 menu->addSeparator();
302 addDPStaticEntry( menu, qtr( I_MENU_MSG ), "",
303 ":/pixmaps/menus_messages_16px.png", SLOT( messagesDialog() ),
305 addDPStaticEntry( menu, qtr( I_MENU_INFO ) , "", "",
306 SLOT( mediaInfoDialog() ), "Ctrl+I" );
307 addDPStaticEntry( menu, qtr( I_MENU_CODECINFO ) , "",
308 ":/pixmaps/menus_info_16px.png", SLOT( mediaCodecDialog() ), "Ctrl+J" );
309 addDPStaticEntry( menu, qtr( I_MENU_BOOKMARK ), "","",
310 SLOT( bookmarksDialog() ), "Ctrl+B" );
312 addDPStaticEntry( menu, qtr( I_MENU_VLM ), "", "", SLOT( vlmDialog() ),
316 menu->addSeparator();
317 addDPStaticEntry( menu, qtr( "Preferences..." ), "",
318 ":/pixmaps/menus_preferences_16px.png", SLOT( prefsDialog() ), "Ctrl+P" );
323 * Interface Sub-Menu, to list extras interface and skins
325 QMenu *QVLCMenu::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
328 vector<const char *> varnames;
329 /** \todo add "switch to XXX" */
330 varnames.push_back( "intf-add" );
331 objects.push_back( p_intf->i_object_id );
333 QMenu *menu = Populate( p_intf, current, varnames, objects );
335 if( !p_intf->pf_show_dialog )
337 menu->addSeparator();
338 menu->addAction( qtr( "Switch to skins" ), THEDP,
339 SLOT( switchToSkins() ), QString( "Ctrl+Z" ) );
341 if( module_Exists( VLC_OBJECT( p_intf ), "wxwidgets" ) )
343 menu->addAction( qtr( "Switch to WxWidgets" ), THEDP,
344 SLOT( switchToWx() ) );
349 CONNECT( menu, aboutToShow(), THEDP->menusUpdateMapper, map() );
350 THEDP->menusUpdateMapper->setMapping( menu, 4 );
357 QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QMenu * current )
360 vector<const char *> varnames;
362 vlc_object_t *p_object = ( vlc_object_t * )vlc_object_find( p_intf,
363 VLC_OBJECT_INPUT, FIND_ANYWHERE );
364 if( p_object != NULL )
366 PUSH_VAR( "audio-es" );
367 vlc_object_release( p_object );
370 p_object = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_AOUT,
374 AudioAutoMenuBuilder( p_object, objects, varnames );
375 vlc_object_release( p_object );
377 return Populate( p_intf, current, varnames, objects );
382 * Subtitles are part of Video.
384 QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current )
386 vlc_object_t *p_object;
388 vector<const char *> varnames;
390 p_object = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_INPUT,
392 if( p_object != NULL )
394 PUSH_VAR( "video-es" );
395 PUSH_VAR( "spu-es" );
396 vlc_object_release( p_object );
399 p_object = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_VOUT,
401 if( p_object != NULL )
403 VideoAutoMenuBuilder( p_object, objects, varnames );
404 vlc_object_release( p_object );
406 return Populate( p_intf, current, varnames, objects );
411 * For DVD, MP4, MOV and other chapter based format
413 QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *navMenu )
415 vlc_object_t *p_object;
417 vector<const char *> varnames;
419 p_object = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_INPUT,
421 if( p_object != NULL )
423 InputAutoMenuBuilder( p_object, objects, varnames );
424 PUSH_VAR( "prev-title" ); PUSH_VAR ( "next-title" );
425 PUSH_VAR( "prev-chapter" ); PUSH_VAR( "next-chapter" );
426 vlc_object_release( p_object );
428 navMenu = new QMenu();
429 addDPStaticEntry( navMenu, qtr( I_MENU_GOTOTIME ), "","",
430 SLOT( gotoTimeDialog() ), "Ctrl+T" );
431 navMenu->addSeparator();
432 return Populate( p_intf, navMenu, varnames, objects, true );
436 * Service Discovery SubMenu
438 QMenu *QVLCMenu::SDMenu( intf_thread_t *p_intf )
440 QMenu *menu = new QMenu();
441 menu->setTitle( qtr( I_PL_SD ) );
442 char **ppsz_longnames;
443 char **ppsz_names = services_discovery_GetServicesNames( p_intf,
445 char **ppsz_name = ppsz_names, **ppsz_longname = ppsz_longnames;
446 for( ; *ppsz_name; ppsz_name++, ppsz_longname++ )
448 QAction *a = new QAction( qfu( *ppsz_longname ), menu );
449 a->setCheckable( true );
450 if( playlist_IsServicesDiscoveryLoaded( THEPL, *ppsz_name ) )
451 a->setChecked( true );
452 CONNECT( a , triggered(), THEDP->SDMapper, map() );
453 THEDP->SDMapper->setMapping( a, QString( *ppsz_name ) );
454 menu->addAction( a );
456 if( !strcmp( *ppsz_name, "podcast" ) )
458 QAction *b = new QAction( qfu( "Configure podcasts..." ), menu );
459 //b->setEnabled( a->isChecked() );
460 menu->addAction( b );
461 CONNECT( b, triggered(), THEDP, podcastConfigureDialog() );
464 free( *ppsz_longname );
467 free( ppsz_longnames );
473 QMenu *QVLCMenu::HelpMenu()
475 QMenu *menu = new QMenu();
476 addDPStaticEntry( menu, qtr( "Help..." ) , "",
477 ":/pixmaps/menus_help_16px.png", SLOT( helpDialog() ), "F1" );
479 addDPStaticEntry( menu, qtr( "Update" ) , "", "", SLOT( updateDialog() ), "");
481 menu->addSeparator();
482 addDPStaticEntry( menu, qtr( I_MENU_ABOUT ), "", "", SLOT( aboutDialog() ),
488 /*****************************************************************************
489 * Popup menus - Right Click menus *
490 *****************************************************************************/
491 #define POPUP_BOILERPLATE \
492 unsigned int i_last_separator = 0; \
493 vector<int> objects; \
494 vector<const char *> varnames; \
495 input_thread_t *p_input = THEMIM->getInput();
497 #define CREATE_POPUP \
498 Populate( p_intf, menu, varnames, objects ); \
499 p_intf->p_sys->p_popup_menu = menu; \
500 menu->popup( QCursor::pos() ); \
501 p_intf->p_sys->p_popup_menu = NULL; \
502 i_last_separator = 0;
504 void QVLCMenu::PopupMenuControlEntries( QMenu *menu,
505 intf_thread_t *p_intf,
506 input_thread_t *p_input )
511 var_Get( p_input, "state", &val );
512 if( val.i_int == PLAYING_S )
513 addMIMStaticEntry( p_intf, menu, qtr( "Pause" ), "",
514 ":/pixmaps/pause_16px.png", SLOT( togglePlayPause() ) );
516 addMIMStaticEntry( p_intf, menu, qtr( "Play" ), "",
517 ":/pixmaps/play_16px.png", SLOT( togglePlayPause() ) );
519 else if( THEPL->items.i_size && THEPL->i_enabled )
520 addMIMStaticEntry( p_intf, menu, qtr( "Play" ), "",
521 ":/pixmaps/play_16px.png", SLOT( togglePlayPause() ) );
523 addMIMStaticEntry( p_intf, menu, qtr( "Stop" ), "",
524 ":/pixmaps/stop_16px.png", SLOT( stop() ) );
525 addMIMStaticEntry( p_intf, menu, qtr( "Previous" ), "",
526 ":/pixmaps/previous_16px.png", SLOT( prev() ) );
527 addMIMStaticEntry( p_intf, menu, qtr( "Next" ), "",
528 ":/pixmaps/next_16px.png", SLOT( next() ) );
531 void QVLCMenu::PopupMenuStaticEntries( intf_thread_t *p_intf, QMenu *menu )
533 QMenu *toolsmenu = ToolsMenu( p_intf, NULL, false, true );
534 toolsmenu->setTitle( qtr( "Tools" ) );
535 menu->addMenu( toolsmenu );
537 QMenu *openmenu = new QMenu( qtr( "Open" ) );
538 openmenu->addAction( qtr( "Open &File..." ), THEDP,
539 SLOT( openFileDialog() ) );
540 openmenu->addAction( qtr( "Open &Disc..." ), THEDP,
541 SLOT( openDiscDialog() ) );
542 openmenu->addAction( qtr( "Open &Network..." ), THEDP,
543 SLOT( openNetDialog() ) );
544 openmenu->addAction( qtr( "Open &Capture Device..." ), THEDP,
545 SLOT( openCaptureDialog() ) );
546 menu->addMenu( openmenu );
548 menu->addSeparator();
549 QMenu *helpmenu = HelpMenu();
550 helpmenu->setTitle( qtr( "Help" ) );
551 menu->addMenu( helpmenu );
553 addDPStaticEntry( menu, qtr( "Quit" ), "", "", SLOT( quit() ) , "Ctrl+Q" );
556 /* Video Tracks and Subtitles tracks */
557 void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf )
562 vlc_object_yield( p_input );
563 varnames.push_back( "video-es" );
564 objects.push_back( p_input->i_object_id );
565 varnames.push_back( "spu-es" );
566 objects.push_back( p_input->i_object_id );
567 vlc_object_t *p_vout = ( vlc_object_t * )vlc_object_find( p_input,
568 VLC_OBJECT_VOUT, FIND_CHILD );
571 VideoAutoMenuBuilder( p_vout, objects, varnames );
572 vlc_object_release( p_vout );
574 vlc_object_release( p_input );
576 QMenu *menu = new QMenu();
581 void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf )
586 vlc_object_yield( p_input );
587 varnames.push_back( "audio-es" );
588 objects.push_back( p_input->i_object_id );
589 vlc_object_t *p_aout = ( vlc_object_t * )vlc_object_find( p_input,
590 VLC_OBJECT_AOUT, FIND_ANYWHERE );
593 AudioAutoMenuBuilder( p_aout, objects, varnames );
594 vlc_object_release( p_aout );
596 vlc_object_release( p_input );
598 QMenu *menu = new QMenu();
602 /* Navigation stuff, and general menus ( open ) */
603 void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf )
610 vlc_object_yield( p_input );
611 varnames.push_back( "audio-es" );
612 InputAutoMenuBuilder( VLC_OBJECT( p_input ), objects, varnames );
616 QMenu *menu = new QMenu();
617 Populate( p_intf, menu, varnames, objects );
619 menu->addSeparator();
620 PopupMenuControlEntries( menu, p_intf, p_input );
622 menu->addSeparator();
623 PopupMenuStaticEntries( p_intf, menu );
625 p_intf->p_sys->p_popup_menu = menu;
626 menu->popup( QCursor::pos() );
627 p_intf->p_sys->p_popup_menu = NULL;
630 /* Main Menu that sticks everything together */
631 void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show )
635 // create a popup if there is none
636 if( ! p_intf->p_sys->p_popup_menu )
641 vlc_object_yield( p_input );
642 InputAutoMenuBuilder( VLC_OBJECT( p_input ), objects, varnames );
646 varnames.push_back( "audio-es" );
647 objects.push_back( p_input->i_object_id );
648 vlc_object_t *p_aout = ( vlc_object_t * )
649 vlc_object_find( p_input, VLC_OBJECT_AOUT, FIND_ANYWHERE );
652 AudioAutoMenuBuilder( p_aout, objects, varnames );
653 vlc_object_release( p_aout );
658 varnames.push_back( "video-es" );
659 objects.push_back( p_input->i_object_id );
660 varnames.push_back( "spu-es" );
661 objects.push_back( p_input->i_object_id );
662 vlc_object_t *p_vout = ( vlc_object_t * )
663 vlc_object_find( p_input, VLC_OBJECT_VOUT, FIND_CHILD );
666 VideoAutoMenuBuilder( p_vout, objects, varnames );
667 vlc_object_release( p_vout );
671 QMenu *menu = new QMenu();
672 Populate( p_intf, menu, varnames, objects );
673 menu->addSeparator();
674 PopupMenuControlEntries( menu, p_intf, p_input );
675 menu->addSeparator();
676 PopupMenuStaticEntries( p_intf, menu );
678 p_intf->p_sys->p_popup_menu = menu;
680 p_intf->p_sys->p_popup_menu->popup( QCursor::pos() );
684 // destroy popup if there is one
685 delete p_intf->p_sys->p_popup_menu;
686 p_intf->p_sys->p_popup_menu = NULL;
690 /************************************************************************
692 ************************************************************************/
694 void QVLCMenu::updateSystrayMenu( MainInterface *mi,
695 intf_thread_t *p_intf,
696 bool b_force_visible )
700 /* Get the systray menu and clean it */
701 QMenu *sysMenu = mi->getSysTrayMenu();
704 /* Hide / Show VLC and cone */
705 if( mi->isVisible() || b_force_visible )
707 sysMenu->addAction( QIcon( ":/vlc16.png" ),
708 qtr( "Hide VLC media player in taskbar" ), mi,
709 SLOT( toggleUpdateSystrayMenu() ) );
713 sysMenu->addAction( QIcon( ":/vlc16.png" ),
714 qtr( "Show VLC media player" ), mi,
715 SLOT( toggleUpdateSystrayMenu() ) );
718 sysMenu->addSeparator();
719 PopupMenuControlEntries( sysMenu, p_intf, p_input );
721 sysMenu->addSeparator();
722 addDPStaticEntry( sysMenu, qtr( "&Open Media" ), "",
723 ":/pixmaps/file-wide_16px.png", SLOT( openFileDialog() ), "" );
724 addDPStaticEntry( sysMenu, qtr( "&Quit" ) , "",
725 ":/pixmaps/menus_quit_16px.png", SLOT( quit() ), "" );
728 mi->getSysTray()->setContextMenu( sysMenu );
732 #undef PUSH_SEPARATOR
735 /*************************************************************************
736 * Builders for automenus
737 *************************************************************************/
738 QMenu * QVLCMenu::Populate( intf_thread_t *p_intf,
740 vector< const char *> & varnames,
741 vector<int> & objects,
744 QMenu *menu = current;
752 vlc_object_t *p_object;
753 vlc_bool_t b_section_empty = VLC_FALSE;
756 #define APPEND_EMPTY { QAction *action = menu->addAction( qtr( "Empty" ) ); \
757 action->setEnabled( false ); }
759 for( i = 0; i < ( int )objects.size() ; i++ )
761 if( !varnames[i] || !*varnames[i] )
763 if( b_section_empty )
765 menu->addSeparator();
766 b_section_empty = VLC_TRUE;
770 if( objects[i] == 0 )
772 /// \bug What is this ?
773 // Append( menu, varnames[i], NULL );
774 b_section_empty = VLC_FALSE;
778 p_object = ( vlc_object_t * )vlc_object_get( p_intf, objects[i] );
779 if( p_object == NULL ) continue;
781 b_section_empty = VLC_FALSE;
782 /* Ugly specific stuff */
783 if( strstr( varnames[i], "intf-add" ) )
784 CreateItem( menu, varnames[i], p_object, false );
786 CreateItem( menu, varnames[i], p_object, true );
787 vlc_object_release( p_object );
790 /* Special case for empty menus */
791 if( menu->actions().size() == 0 || b_section_empty )
798 /*****************************************************************************
800 *****************************************************************************/
802 static bool IsMenuEmpty( const char *psz_var,
803 vlc_object_t *p_object,
806 vlc_value_t val, val_list;
807 int i_type, i_result, i;
809 /* Check the type of the object variable */
810 i_type = var_Type( p_object, psz_var );
812 /* Check if we want to display the variable */
813 if( !( i_type & VLC_VAR_HASCHOICE ) ) return false;
815 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
816 if( val.i_int == 0 ) return true;
818 if( ( i_type & VLC_VAR_TYPE ) != VLC_VAR_VARIABLE )
820 /* Very evil hack ! intf-switch can have only one value */
821 if( !strcmp( psz_var, "intf-switch" ) ) return false;
822 if( val.i_int == 1 && b_root ) return true;
826 /* Check children variables in case of VLC_VAR_VARIABLE */
827 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
832 for( i = 0, i_result = true; i < val_list.p_list->i_count; i++ )
834 if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
842 /* clean up everything */
843 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, NULL );
848 void QVLCMenu::CreateItem( QMenu *menu, const char *psz_var,
849 vlc_object_t *p_object, bool b_submenu )
851 vlc_value_t val, text;
854 /* Check the type of the object variable */
855 i_type = var_Type( p_object, psz_var );
857 switch( i_type & VLC_VAR_TYPE )
861 case VLC_VAR_VARIABLE:
863 case VLC_VAR_INTEGER:
867 /* Variable doesn't exist or isn't handled */
871 /* Make sure we want to display the variable */
872 if( IsMenuEmpty( psz_var, p_object ) ) return;
874 /* Get the descriptive name of the variable */
875 var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
877 if( i_type & VLC_VAR_HASCHOICE )
879 /* Append choices menu */
882 QMenu *submenu = new QMenu();
883 submenu->setTitle( qfu( text.psz_string ?
884 text.psz_string : psz_var ) );
885 if( CreateChoicesMenu( submenu, psz_var, p_object, true ) == 0 )
886 menu->addMenu( submenu );
889 CreateChoicesMenu( menu, psz_var, p_object, true );
890 FREENULL( text.psz_string );
894 #define TEXT_OR_VAR qfu ( text.psz_string ? text.psz_string : psz_var )
896 switch( i_type & VLC_VAR_TYPE )
899 var_Get( p_object, psz_var, &val );
900 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_NORMAL,
901 p_object->i_object_id, val, i_type );
905 var_Get( p_object, psz_var, &val );
906 val.b_bool = !val.b_bool;
907 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_CHECK,
908 p_object->i_object_id, val, i_type, !val.b_bool );
911 FREENULL( text.psz_string );
915 int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
916 vlc_object_t *p_object, bool b_root )
918 vlc_value_t val, val_list, text_list;
921 /* Check the type of the object variable */
922 i_type = var_Type( p_object, psz_var );
924 /* Make sure we want to display the variable */
925 if( IsMenuEmpty( psz_var, p_object, b_root ) ) return VLC_EGENERIC;
927 switch( i_type & VLC_VAR_TYPE )
931 case VLC_VAR_VARIABLE:
933 case VLC_VAR_INTEGER:
937 /* Variable doesn't exist or isn't handled */
941 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
942 &val_list, &text_list ) < 0 )
947 #define NORMAL_OR_RADIO i_type & VLC_VAR_ISCOMMAND ? ITEM_NORMAL: ITEM_RADIO
948 #define NOTCOMMAND !( i_type & VLC_VAR_ISCOMMAND )
949 #define CURVAL val_list.p_list->p_values[i]
950 #define CURTEXT text_list.p_list->p_values[i].psz_string
952 for( i = 0; i < val_list.p_list->i_count; i++ )
954 vlc_value_t another_val;
956 QMenu *subsubmenu = new QMenu();
958 switch( i_type & VLC_VAR_TYPE )
960 case VLC_VAR_VARIABLE:
961 CreateChoicesMenu( subsubmenu, CURVAL.psz_string, p_object, false );
962 subsubmenu->setTitle( qfu( CURTEXT ? CURTEXT :CURVAL.psz_string ) );
963 submenu->addMenu( subsubmenu );
967 var_Get( p_object, psz_var, &val );
968 another_val.psz_string = strdup( CURVAL.psz_string );
969 menutext = qfu( "Add " ) /* If this function is more used, FIX*/
970 + qfu( CURTEXT ? CURTEXT : another_val.psz_string );
971 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
972 p_object->i_object_id, another_val, i_type,
973 NOTCOMMAND && val.psz_string &&
974 !strcmp( val.psz_string, CURVAL.psz_string ) );
976 if( val.psz_string ) free( val.psz_string );
979 case VLC_VAR_INTEGER:
980 var_Get( p_object, psz_var, &val );
981 if( CURTEXT ) menutext = qfu( CURTEXT );
982 else menutext.sprintf( "%d", CURVAL.i_int );
983 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
984 p_object->i_object_id, CURVAL, i_type,
985 NOTCOMMAND && CURVAL.i_int == val.i_int );
989 var_Get( p_object, psz_var, &val );
990 if( CURTEXT ) menutext = qfu( CURTEXT );
991 else menutext.sprintf( "%.2f", CURVAL.f_float );
992 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
993 p_object->i_object_id, CURVAL, i_type,
994 NOTCOMMAND && CURVAL.f_float == val.f_float );
1001 currentGroup = NULL;
1003 /* clean up everything */
1004 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
1006 #undef NORMAL_OR_RADIO
1013 void QVLCMenu::CreateAndConnect( QMenu *menu, const char *psz_var,
1014 QString text, QString help,
1015 int i_item_type, int i_object_id,
1016 vlc_value_t val, int i_val_type,
1019 QAction *action = new QAction( text, menu );
1020 action->setText( text );
1021 action->setToolTip( help );
1023 if( i_item_type == ITEM_CHECK )
1025 action->setCheckable( true );
1027 else if( i_item_type == ITEM_RADIO )
1029 action->setCheckable( true );
1031 currentGroup = new QActionGroup( menu );
1032 currentGroup->addAction( action );
1037 action->setChecked( true );
1039 MenuItemData *itemData = new MenuItemData( i_object_id, i_val_type,
1041 CONNECT( action, triggered(), THEDP->menusMapper, map() );
1042 THEDP->menusMapper->setMapping( action, itemData );
1043 menu->addAction( action );
1046 void QVLCMenu::DoAction( intf_thread_t *p_intf, QObject *data )
1048 MenuItemData *itemData = qobject_cast<MenuItemData *>( data );
1049 vlc_object_t *p_object = ( vlc_object_t * )vlc_object_get( p_intf,
1050 itemData->i_object_id );
1051 if( p_object == NULL ) return;
1053 var_Set( p_object, itemData->psz_var, itemData->val );
1054 vlc_object_release( p_object );