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 *****************************************************************************/
27 #include <vlc_intf_strings.h>
29 #include "main_interface.hpp"
31 #include "dialogs_provider.hpp"
32 #include "input_manager.hpp"
37 #include <QActionGroup>
38 #include <QSignalMapper>
39 #include <QSystemTrayIcon>
48 static QActionGroup *currentGroup;
50 // Add static entries to menus
51 void addDPStaticEntry( QMenu *menu,
58 if( !EMPTY_STR( icon ) > 0 )
60 if( !EMPTY_STR( shortcut ) > 0 )
61 menu->addAction( QIcon( icon ), text, THEDP, member, qtr( shortcut ) );
63 menu->addAction( QIcon( icon ), text, THEDP, member );
67 if( !EMPTY_STR( shortcut ) > 0 )
68 menu->addAction( text, THEDP, member, qtr( shortcut ) );
70 menu->addAction( text, THEDP, member );
74 void addMIMStaticEntry( intf_thread_t *p_intf,
81 if( strlen( icon ) > 0 )
83 QAction *action = menu->addAction( text, THEMIM, member );
84 action->setIcon( QIcon( icon ) );
88 menu->addAction( text, THEMIM, member );
92 /*****************************************************************************
93 * Definitions of variables for the dynamic menus
94 *****************************************************************************/
95 #define PUSH_VAR( var ) varnames.push_back( var ); \
96 objects.push_back( p_object->i_object_id )
98 #define PUSH_SEPARATOR if( objects.size() != i_last_separator ) { \
99 objects.push_back( 0 ); varnames.push_back( "" ); \
100 i_last_separator = objects.size(); }
102 static int InputAutoMenuBuilder( vlc_object_t *p_object,
103 vector<int> &objects,
104 vector<const char *> &varnames )
106 PUSH_VAR( "bookmark" );
108 PUSH_VAR( "chapter" );
109 PUSH_VAR( "program" );
110 PUSH_VAR( "navigation" );
111 PUSH_VAR( "dvd_menus" );
115 static int VideoAutoMenuBuilder( vlc_object_t *p_object,
116 vector<int> &objects,
117 vector<const char *> &varnames )
119 PUSH_VAR( "fullscreen" );
121 PUSH_VAR( "deinterlace" );
122 PUSH_VAR( "aspect-ratio" );
124 PUSH_VAR( "video-on-top" );
125 PUSH_VAR( "directx-wallpaper" );
126 PUSH_VAR( "video-snapshot" );
128 vlc_object_t *p_dec_obj = ( vlc_object_t * )vlc_object_find( p_object,
131 if( p_dec_obj != NULL )
133 vlc_object_t *p_object = p_dec_obj;
134 PUSH_VAR( "ffmpeg-pp-q" );
135 vlc_object_release( p_dec_obj );
140 static int AudioAutoMenuBuilder( vlc_object_t *p_object,
141 vector<int> &objects,
142 vector<const char *> &varnames )
144 PUSH_VAR( "audio-device" );
145 PUSH_VAR( "audio-channels" );
146 PUSH_VAR( "visual" );
147 PUSH_VAR( "equalizer" );
151 /*****************************************************************************
154 *****************************************************************************/
156 #define BAR_ADD( func, title ) { \
157 QMenu *menu = func; menu->setTitle( title ); bar->addMenu( menu ); }
159 #define BAR_DADD( func, title, id ) { \
160 QMenu *menu = func; menu->setTitle( title ); bar->addMenu( menu ); \
161 MenuFunc *f = new MenuFunc( menu, id ); \
162 CONNECT( menu, aboutToShow(), THEDP->menusUpdateMapper, map() ); \
163 THEDP->menusUpdateMapper->setMapping( menu, f ); }
166 * Main Menu Bar Creation
168 void QVLCMenu::createMenuBar( MainInterface *mi,
169 intf_thread_t *p_intf,
170 bool visual_selector_enabled )
172 QMenuBar *bar = mi->menuBar();
173 BAR_ADD( FileMenu(), qtr( "&Media" ) );
174 BAR_ADD( PlaylistMenu( p_intf, mi ), qtr( "&Playlist" ) );
175 BAR_ADD( ToolsMenu( p_intf, mi, visual_selector_enabled, true ), qtr( "&Tools" ) );
176 BAR_DADD( AudioMenu( p_intf, NULL ), qtr( "&Audio" ), 2 );
177 BAR_DADD( VideoMenu( p_intf, NULL ), qtr( "&Video" ), 1 );
178 BAR_DADD( NavigMenu( p_intf, NULL ), qtr( "&Playback" ), 3 );
180 BAR_ADD( HelpMenu(), qtr( "&Help" ) );
186 * Media ( File ) Menu
187 * Opening, streaming and quit
189 QMenu *QVLCMenu::FileMenu()
191 QMenu *menu = new QMenu();
193 addDPStaticEntry( menu, qtr( "&Open File..." ), "",
194 ":/pixmaps/file-asym_16px.png", SLOT( openFileDialog() ), "Ctrl+O" );
195 addDPStaticEntry( menu, qtr( I_OPEN_FOLDER ), "",
196 ":/pixmaps/folder-grey_16px.png", SLOT( PLAppendDir() ), "Ctrl+F" );
197 addDPStaticEntry( menu, qtr( "Open &Disc..." ), "",
198 ":/pixmaps/disc_16px.png", SLOT( openDiscDialog() ), "Ctrl+D" );
199 addDPStaticEntry( menu, qtr( "Open &Network..." ), "",
200 ":/pixmaps/network_16px.png", SLOT( openNetDialog() ), "Ctrl+N" );
201 addDPStaticEntry( menu, qtr( "Open &Capture Device..." ), "",
202 ":/pixmaps/capture-card_16px.png", SLOT( openCaptureDialog() ),
204 menu->addSeparator();
206 addDPStaticEntry( menu, qtr( "&Streaming..." ), "",
207 ":/pixmaps/menus_stream_16px.png", SLOT( openThenStreamingDialogs() ),
209 addDPStaticEntry( menu, qtr( "Conve&rt / Save..." ), "", "",
210 SLOT( openThenTranscodingDialogs() ), "Ctrl+R" );
211 menu->addSeparator();
213 addDPStaticEntry( menu, qtr( "&Quit" ) , "",
214 ":/pixmaps/menus_quit_16px.png", SLOT( quit() ), "Ctrl+Q" );
218 /* Playlist/MediaLibrary Control */
219 QMenu *QVLCMenu::PlaylistMenu( intf_thread_t *p_intf, MainInterface *mi )
221 QMenu *menu = new QMenu();
222 menu->addMenu( SDMenu( p_intf ) );
223 menu->addAction( QIcon( ":/pixmaps/playlist_16px.png" ),
224 qtr( "Show Playlist" ), mi, SLOT( togglePlaylist() ) );
225 menu->addSeparator();
227 addDPStaticEntry( menu, qtr( I_PL_LOAD ), "", "", SLOT( openAPlaylist() ),
229 addDPStaticEntry( menu, qtr( I_PL_SAVE ), "", "", SLOT( saveAPlaylist() ),
231 menu->addSeparator();
232 menu->addAction( qtr( "Undock from interface" ), mi,
233 SLOT( undockPlaylist() ), qtr( "Ctrl+U" ) );
239 * This is kept in the same menu for now, but could change if it gets much
241 * This menu can be an interface menu but also a right click menu.
243 QMenu *QVLCMenu::ToolsMenu( intf_thread_t *p_intf,
245 bool visual_selector_enabled,
248 QMenu *menu = new QMenu;
251 menu->addAction( QIcon( ":/pixmaps/playlist_16px.png" ),
252 qtr( "Playlist..." ), mi, SLOT( togglePlaylist() ),
255 addDPStaticEntry( menu, qtr( I_MENU_EXT ), "",
256 ":/pixmaps/menus_settings_16px.png", SLOT( extendedDialog() ),
259 menu->addSeparator();
263 QMenu *intfmenu = InterfacesMenu( p_intf, NULL );
264 intfmenu->setTitle( qtr( "Add Interfaces" ) );
265 menu->addMenu( intfmenu );
266 menu->addSeparator();
271 QAction *action=menu->addAction( qtr( "Minimal View..." ), mi,
272 SLOT( toggleMinimalView() ), qtr( "Ctrl+H" ) );
273 action->setCheckable( true );
274 if( mi->getControlsVisibilityStatus() & CONTROLS_VISIBLE )
275 action->setChecked( true );
277 /* Advanced Controls */
278 action = menu->addAction( qtr( "Advanced controls" ), mi,
279 SLOT( toggleAdvanced() ) );
280 action->setCheckable( true );
281 if( mi->getControlsVisibilityStatus() & CONTROLS_ADVANCED )
282 action->setChecked( true );
283 #if 0 /* For Visualisations. Not yet working */
284 adv = menu->addAction( qtr( "Visualizations selector" ),
285 mi, SLOT( visual() ) );
286 adv->setCheckable( true );
287 if( visual_selector_enabled ) adv->setChecked( true );
291 menu->addSeparator();
293 addDPStaticEntry( menu, qtr( I_MENU_MSG ), "",
294 ":/pixmaps/menus_messages_16px.png", SLOT( messagesDialog() ),
296 addDPStaticEntry( menu, qtr( I_MENU_INFO ) , "", "",
297 SLOT( mediaInfoDialog() ), "Ctrl+I" );
298 addDPStaticEntry( menu, qtr( I_MENU_CODECINFO ) , "",
299 ":/pixmaps/menus_info_16px.png", SLOT( mediaCodecDialog() ), "Ctrl+J" );
302 addDPStaticEntry( menu, qtr( I_MENU_BOOKMARK ), "","",
303 SLOT( bookmarksDialog() ), "Ctrl+B" );
305 addDPStaticEntry( menu, qtr( I_MENU_VLM ), "", "", SLOT( vlmDialog() ),
309 menu->addSeparator();
310 addDPStaticEntry( menu, qtr( "Preferences..." ), "",
311 ":/pixmaps/menus_preferences_16px.png", SLOT( prefsDialog() ), "Ctrl+P" );
316 * Interface Sub-Menu, to list extras interface and skins
318 QMenu *QVLCMenu::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
321 vector<const char *> varnames;
322 /** \todo add "switch to XXX" */
323 varnames.push_back( "intf-add" );
324 objects.push_back( p_intf->i_object_id );
326 QMenu *menu = Populate( p_intf, current, varnames, objects );
328 if( !p_intf->pf_show_dialog )
330 menu->addSeparator();
331 menu->addAction( qtr( "Switch to skins" ), THEDP, SLOT( switchToSkins() ),
332 QString( "Ctrl+Z" ) );
335 CONNECT( menu, aboutToShow(), THEDP->menusUpdateMapper, map() );
336 THEDP->menusUpdateMapper->setMapping( menu, 4 );
343 QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QMenu * current )
346 vector<const char *> varnames;
348 vlc_object_t *p_object = ( vlc_object_t * )vlc_object_find( p_intf,
349 VLC_OBJECT_INPUT, FIND_ANYWHERE );
350 if( p_object != NULL )
352 PUSH_VAR( "audio-es" );
353 vlc_object_release( p_object );
356 p_object = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_AOUT,
360 AudioAutoMenuBuilder( p_object, objects, varnames );
361 vlc_object_release( p_object );
363 return Populate( p_intf, current, varnames, objects );
368 * Subtitles are part of Video.
370 QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current )
372 vlc_object_t *p_object;
374 vector<const char *> varnames;
376 p_object = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_INPUT,
378 if( p_object != NULL )
380 PUSH_VAR( "video-es" );
381 PUSH_VAR( "spu-es" );
382 vlc_object_release( p_object );
385 p_object = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_VOUT,
387 if( p_object != NULL )
389 VideoAutoMenuBuilder( p_object, objects, varnames );
390 vlc_object_release( p_object );
392 return Populate( p_intf, current, varnames, objects );
397 * For DVD, MP4, MOV and other chapter based format
399 QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *navMenu )
401 vlc_object_t *p_object;
403 vector<const char *> varnames;
405 p_object = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_INPUT,
407 if( p_object != NULL )
409 InputAutoMenuBuilder( p_object, objects, varnames );
410 PUSH_VAR( "prev-title" ); PUSH_VAR ( "next-title" );
411 PUSH_VAR( "prev-chapter" ); PUSH_VAR( "next-chapter" );
412 vlc_object_release( p_object );
414 navMenu = new QMenu();
415 addDPStaticEntry( navMenu, qtr( I_MENU_GOTOTIME ), "","",
416 SLOT( gotoTimeDialog() ), "Ctrl+T" );
417 navMenu->addSeparator();
418 return Populate( p_intf, navMenu, varnames, objects, true );
422 * Service Discovery SubMenu
424 QMenu *QVLCMenu::SDMenu( intf_thread_t *p_intf )
426 QMenu *menu = new QMenu();
427 menu->setTitle( qtr( I_PL_SD ) );
428 char **ppsz_longnames;
429 char **ppsz_names = services_discovery_GetServicesNames( p_intf,
431 char **ppsz_name = ppsz_names, **ppsz_longname = ppsz_longnames;
432 for( ; *ppsz_name; ppsz_name++, ppsz_longname++ )
434 QAction *a = new QAction( qfu( *ppsz_longname ), menu );
435 a->setCheckable( true );
436 if( playlist_IsServicesDiscoveryLoaded( THEPL, *ppsz_name ) )
437 a->setChecked( true );
438 CONNECT( a , triggered(), THEDP->SDMapper, map() );
439 THEDP->SDMapper->setMapping( a, QString( *ppsz_name ) );
440 menu->addAction( a );
442 if( !strcmp( *ppsz_name, "podcast" ) )
444 QAction *b = new QAction( qfu( "Configure podcasts..." ), menu );
445 //b->setEnabled( a->isChecked() );
446 menu->addAction( b );
447 CONNECT( b, triggered(), THEDP, podcastConfigureDialog() );
450 free( *ppsz_longname );
453 free( ppsz_longnames );
459 QMenu *QVLCMenu::HelpMenu()
461 QMenu *menu = new QMenu();
462 addDPStaticEntry( menu, qtr( "Help..." ) , "",
463 ":/pixmaps/menus_help_16px.png", SLOT( helpDialog() ), "F1" );
465 addDPStaticEntry( menu, qtr( "Update" ) , "", "", SLOT( updateDialog() ), "");
467 menu->addSeparator();
468 addDPStaticEntry( menu, qtr( I_MENU_ABOUT ), "", "", SLOT( aboutDialog() ),
474 /*****************************************************************************
475 * Popup menus - Right Click menus *
476 *****************************************************************************/
477 #define POPUP_BOILERPLATE \
478 unsigned int i_last_separator = 0; \
479 vector<int> objects; \
480 vector<const char *> varnames; \
481 input_thread_t *p_input = THEMIM->getInput();
483 #define CREATE_POPUP \
484 Populate( p_intf, menu, varnames, objects ); \
485 p_intf->p_sys->p_popup_menu = menu; \
486 menu->popup( QCursor::pos() ); \
487 p_intf->p_sys->p_popup_menu = NULL; \
488 i_last_separator = 0;
490 void QVLCMenu::PopupMenuControlEntries( QMenu *menu,
491 intf_thread_t *p_intf,
492 input_thread_t *p_input )
497 var_Get( p_input, "state", &val );
498 if( val.i_int == PLAYING_S )
499 addMIMStaticEntry( p_intf, menu, qtr( "Pause" ), "",
500 ":/pixmaps/pause_16px.png", SLOT( togglePlayPause() ) );
502 addMIMStaticEntry( p_intf, menu, qtr( "Play" ), "",
503 ":/pixmaps/play_16px.png", SLOT( togglePlayPause() ) );
505 else if( THEPL->items.i_size && THEPL->i_enabled )
506 addMIMStaticEntry( p_intf, menu, qtr( "Play" ), "",
507 ":/pixmaps/play_16px.png", SLOT( togglePlayPause() ) );
509 addMIMStaticEntry( p_intf, menu, qtr( "Stop" ), "",
510 ":/pixmaps/stop_16px.png", SLOT( stop() ) );
511 addMIMStaticEntry( p_intf, menu, qtr( "Previous" ), "",
512 ":/pixmaps/previous_16px.png", SLOT( prev() ) );
513 addMIMStaticEntry( p_intf, menu, qtr( "Next" ), "",
514 ":/pixmaps/next_16px.png", SLOT( next() ) );
517 void QVLCMenu::PopupMenuStaticEntries( intf_thread_t *p_intf, QMenu *menu )
519 QMenu *toolsmenu = ToolsMenu( p_intf, NULL, false, true );
520 toolsmenu->setTitle( qtr( "Tools" ) );
521 menu->addMenu( toolsmenu );
523 QMenu *openmenu = new QMenu( qtr( "Open" ) );
524 openmenu->addAction( qtr( "Open &File..." ), THEDP,
525 SLOT( openFileDialog() ) );
526 openmenu->addAction( qtr( "Open &Disc..." ), THEDP,
527 SLOT( openDiscDialog() ) );
528 openmenu->addAction( qtr( "Open &Network..." ), THEDP,
529 SLOT( openNetDialog() ) );
530 openmenu->addAction( qtr( "Open &Capture Device..." ), THEDP,
531 SLOT( openCaptureDialog() ) );
532 menu->addMenu( openmenu );
534 menu->addSeparator();
535 QMenu *helpmenu = HelpMenu();
536 helpmenu->setTitle( qtr( "Help" ) );
537 menu->addMenu( helpmenu );
539 addDPStaticEntry( menu, qtr( "Quit" ), "", "", SLOT( quit() ) , "Ctrl+Q" );
542 /* Video Tracks and Subtitles tracks */
543 void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf )
548 vlc_object_yield( p_input );
549 varnames.push_back( "video-es" );
550 objects.push_back( p_input->i_object_id );
551 varnames.push_back( "spu-es" );
552 objects.push_back( p_input->i_object_id );
553 vlc_object_t *p_vout = ( vlc_object_t * )vlc_object_find( p_input,
554 VLC_OBJECT_VOUT, FIND_CHILD );
557 VideoAutoMenuBuilder( p_vout, objects, varnames );
558 vlc_object_release( p_vout );
560 vlc_object_release( p_input );
562 QMenu *menu = new QMenu();
567 void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf )
572 vlc_object_yield( p_input );
573 varnames.push_back( "audio-es" );
574 objects.push_back( p_input->i_object_id );
575 vlc_object_t *p_aout = ( vlc_object_t * )vlc_object_find( p_input,
576 VLC_OBJECT_AOUT, FIND_ANYWHERE );
579 AudioAutoMenuBuilder( p_aout, objects, varnames );
580 vlc_object_release( p_aout );
582 vlc_object_release( p_input );
584 QMenu *menu = new QMenu();
588 /* Navigation stuff, and general menus ( open ) */
589 void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf )
596 vlc_object_yield( p_input );
597 varnames.push_back( "audio-es" );
598 InputAutoMenuBuilder( VLC_OBJECT( p_input ), objects, varnames );
602 QMenu *menu = new QMenu();
603 Populate( p_intf, menu, varnames, objects );
605 menu->addSeparator();
606 PopupMenuControlEntries( menu, p_intf, p_input );
608 menu->addSeparator();
609 PopupMenuStaticEntries( p_intf, menu );
611 p_intf->p_sys->p_popup_menu = menu;
612 menu->popup( QCursor::pos() );
613 p_intf->p_sys->p_popup_menu = NULL;
616 /* Main Menu that sticks everything together */
617 void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show )
621 // create a popup if there is none
622 if( ! p_intf->p_sys->p_popup_menu )
627 vlc_object_yield( p_input );
628 InputAutoMenuBuilder( VLC_OBJECT( p_input ), objects, varnames );
632 varnames.push_back( "audio-es" );
633 objects.push_back( p_input->i_object_id );
634 vlc_object_t *p_aout = ( vlc_object_t * )
635 vlc_object_find( p_input, VLC_OBJECT_AOUT, FIND_ANYWHERE );
638 AudioAutoMenuBuilder( p_aout, objects, varnames );
639 vlc_object_release( p_aout );
644 varnames.push_back( "video-es" );
645 objects.push_back( p_input->i_object_id );
646 varnames.push_back( "spu-es" );
647 objects.push_back( p_input->i_object_id );
648 vlc_object_t *p_vout = ( vlc_object_t * )
649 vlc_object_find( p_input, VLC_OBJECT_VOUT, FIND_CHILD );
652 VideoAutoMenuBuilder( p_vout, objects, varnames );
653 vlc_object_release( p_vout );
657 QMenu *menu = new QMenu();
658 Populate( p_intf, menu, varnames, objects );
659 menu->addSeparator();
660 PopupMenuControlEntries( menu, p_intf, p_input );
661 menu->addSeparator();
662 PopupMenuStaticEntries( p_intf, menu );
664 p_intf->p_sys->p_popup_menu = menu;
666 p_intf->p_sys->p_popup_menu->popup( QCursor::pos() );
670 // destroy popup if there is one
671 delete p_intf->p_sys->p_popup_menu;
672 p_intf->p_sys->p_popup_menu = NULL;
676 /************************************************************************
678 ************************************************************************/
680 void QVLCMenu::updateSystrayMenu( MainInterface *mi,
681 intf_thread_t *p_intf,
682 bool b_force_visible )
686 /* Get the systray menu and clean it */
687 QMenu *sysMenu = mi->getSysTrayMenu();
690 /* Hide / Show VLC and cone */
691 if( mi->isVisible() || b_force_visible )
693 sysMenu->addAction( QIcon( ":/vlc16.png" ),
694 qtr( "Hide VLC media player in taskbar" ), mi,
695 SLOT( toggleUpdateSystrayMenu() ) );
699 sysMenu->addAction( QIcon( ":/vlc16.png" ),
700 qtr( "Show VLC media player" ), mi,
701 SLOT( toggleUpdateSystrayMenu() ) );
704 sysMenu->addSeparator();
705 PopupMenuControlEntries( sysMenu, p_intf, p_input );
707 sysMenu->addSeparator();
708 addDPStaticEntry( sysMenu, qtr( "&Open Media" ), "",
709 ":/pixmaps/file-wide_16px.png", SLOT( openFileDialog() ), "" );
710 addDPStaticEntry( sysMenu, qtr( "&Quit" ) , "",
711 ":/pixmaps/menus_quit_16px.png", SLOT( quit() ), "" );
714 mi->getSysTray()->setContextMenu( sysMenu );
718 #undef PUSH_SEPARATOR
721 /*************************************************************************
722 * Builders for automenus
723 *************************************************************************/
724 QMenu * QVLCMenu::Populate( intf_thread_t *p_intf,
726 vector< const char *> & varnames,
727 vector<int> & objects,
730 QMenu *menu = current;
738 vlc_object_t *p_object;
739 vlc_bool_t b_section_empty = VLC_FALSE;
742 #define APPEND_EMPTY { QAction *action = menu->addAction( qtr( "Empty" ) ); \
743 action->setEnabled( false ); }
745 for( i = 0; i < ( int )objects.size() ; i++ )
747 if( !varnames[i] || !*varnames[i] )
749 if( b_section_empty )
751 menu->addSeparator();
752 b_section_empty = VLC_TRUE;
756 if( objects[i] == 0 )
758 /// \bug What is this ?
759 // Append( menu, varnames[i], NULL );
760 b_section_empty = VLC_FALSE;
764 p_object = ( vlc_object_t * )vlc_object_get( p_intf, objects[i] );
765 if( p_object == NULL ) continue;
767 b_section_empty = VLC_FALSE;
768 /* Ugly specific stuff */
769 if( strstr( varnames[i], "intf-add" ) )
770 CreateItem( menu, varnames[i], p_object, false );
772 CreateItem( menu, varnames[i], p_object, true );
773 vlc_object_release( p_object );
776 /* Special case for empty menus */
777 if( menu->actions().size() == 0 || b_section_empty )
784 /*****************************************************************************
786 *****************************************************************************/
788 static bool IsMenuEmpty( const char *psz_var,
789 vlc_object_t *p_object,
792 vlc_value_t val, val_list;
793 int i_type, i_result, i;
795 /* Check the type of the object variable */
796 i_type = var_Type( p_object, psz_var );
798 /* Check if we want to display the variable */
799 if( !( i_type & VLC_VAR_HASCHOICE ) ) return false;
801 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
802 if( val.i_int == 0 ) return true;
804 if( ( i_type & VLC_VAR_TYPE ) != VLC_VAR_VARIABLE )
806 /* Very evil hack ! intf-switch can have only one value */
807 if( !strcmp( psz_var, "intf-switch" ) ) return false;
808 if( val.i_int == 1 && b_root ) return true;
812 /* Check children variables in case of VLC_VAR_VARIABLE */
813 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
818 for( i = 0, i_result = true; i < val_list.p_list->i_count; i++ )
820 if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
828 /* clean up everything */
829 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, NULL );
834 void QVLCMenu::CreateItem( QMenu *menu, const char *psz_var,
835 vlc_object_t *p_object, bool b_submenu )
837 vlc_value_t val, text;
840 /* Check the type of the object variable */
841 i_type = var_Type( p_object, psz_var );
843 switch( i_type & VLC_VAR_TYPE )
847 case VLC_VAR_VARIABLE:
849 case VLC_VAR_INTEGER:
853 /* Variable doesn't exist or isn't handled */
857 /* Make sure we want to display the variable */
858 if( IsMenuEmpty( psz_var, p_object ) ) return;
860 /* Get the descriptive name of the variable */
861 var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
863 if( i_type & VLC_VAR_HASCHOICE )
865 /* Append choices menu */
868 QMenu *submenu = new QMenu();
869 submenu->setTitle( qfu( text.psz_string ?
870 text.psz_string : psz_var ) );
871 if( CreateChoicesMenu( submenu, psz_var, p_object, true ) == 0 )
872 menu->addMenu( submenu );
875 CreateChoicesMenu( menu, psz_var, p_object, true );
876 FREENULL( text.psz_string );
880 #define TEXT_OR_VAR qfu ( text.psz_string ? text.psz_string : psz_var )
882 switch( i_type & VLC_VAR_TYPE )
885 var_Get( p_object, psz_var, &val );
886 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_NORMAL,
887 p_object->i_object_id, val, i_type );
891 var_Get( p_object, psz_var, &val );
892 val.b_bool = !val.b_bool;
893 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_CHECK,
894 p_object->i_object_id, val, i_type, !val.b_bool );
897 FREENULL( text.psz_string );
901 int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
902 vlc_object_t *p_object, bool b_root )
904 vlc_value_t val, val_list, text_list;
907 /* Check the type of the object variable */
908 i_type = var_Type( p_object, psz_var );
910 /* Make sure we want to display the variable */
911 if( IsMenuEmpty( psz_var, p_object, b_root ) ) return VLC_EGENERIC;
913 switch( i_type & VLC_VAR_TYPE )
917 case VLC_VAR_VARIABLE:
919 case VLC_VAR_INTEGER:
923 /* Variable doesn't exist or isn't handled */
927 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
928 &val_list, &text_list ) < 0 )
933 #define NORMAL_OR_RADIO i_type & VLC_VAR_ISCOMMAND ? ITEM_NORMAL: ITEM_RADIO
934 #define NOTCOMMAND !( i_type & VLC_VAR_ISCOMMAND )
935 #define CURVAL val_list.p_list->p_values[i]
936 #define CURTEXT text_list.p_list->p_values[i].psz_string
938 for( i = 0; i < val_list.p_list->i_count; i++ )
940 vlc_value_t another_val;
942 QMenu *subsubmenu = new QMenu();
944 switch( i_type & VLC_VAR_TYPE )
946 case VLC_VAR_VARIABLE:
947 CreateChoicesMenu( subsubmenu, CURVAL.psz_string, p_object, false );
948 subsubmenu->setTitle( qfu( CURTEXT ? CURTEXT :CURVAL.psz_string ) );
949 submenu->addMenu( subsubmenu );
953 var_Get( p_object, psz_var, &val );
954 another_val.psz_string = strdup( CURVAL.psz_string );
955 menutext = qfu( CURTEXT ? CURTEXT : another_val.psz_string );
956 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
957 p_object->i_object_id, another_val, i_type,
958 NOTCOMMAND && val.psz_string &&
959 !strcmp( val.psz_string, CURVAL.psz_string ) );
961 if( val.psz_string ) free( val.psz_string );
964 case VLC_VAR_INTEGER:
965 var_Get( p_object, psz_var, &val );
966 if( CURTEXT ) menutext = qfu( CURTEXT );
967 else menutext.sprintf( "%d", CURVAL.i_int );
968 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
969 p_object->i_object_id, CURVAL, i_type,
970 NOTCOMMAND && CURVAL.i_int == val.i_int );
974 var_Get( p_object, psz_var, &val );
975 if( CURTEXT ) menutext = qfu( CURTEXT );
976 else menutext.sprintf( "%.2f", CURVAL.f_float );
977 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
978 p_object->i_object_id, CURVAL, i_type,
979 NOTCOMMAND && CURVAL.f_float == val.f_float );
988 /* clean up everything */
989 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
991 #undef NORMAL_OR_RADIO
998 void QVLCMenu::CreateAndConnect( QMenu *menu, const char *psz_var,
999 QString text, QString help,
1000 int i_item_type, int i_object_id,
1001 vlc_value_t val, int i_val_type,
1004 QAction *action = new QAction( text, menu );
1005 action->setText( text );
1006 action->setToolTip( help );
1008 if( i_item_type == ITEM_CHECK )
1010 action->setCheckable( true );
1012 else if( i_item_type == ITEM_RADIO )
1014 action->setCheckable( true );
1016 currentGroup = new QActionGroup( menu );
1017 currentGroup->addAction( action );
1022 action->setChecked( true );
1024 MenuItemData *itemData = new MenuItemData( i_object_id, i_val_type,
1026 CONNECT( action, triggered(), THEDP->menusMapper, map() );
1027 THEDP->menusMapper->setMapping( action, itemData );
1028 menu->addAction( action );
1031 void QVLCMenu::DoAction( intf_thread_t *p_intf, QObject *data )
1033 MenuItemData *itemData = qobject_cast<MenuItemData *>( data );
1034 vlc_object_t *p_object = ( vlc_object_t * )vlc_object_get( p_intf,
1035 itemData->i_object_id );
1036 if( p_object == NULL ) return;
1038 var_Set( p_object, itemData->psz_var, itemData->val );
1039 vlc_object_release( p_object );