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 *****************************************************************************/
25 #include <vlc_intf_strings.h>
27 #include "main_interface.hpp"
29 #include "dialogs_provider.hpp"
30 #include "input_manager.hpp"
35 #include <QActionGroup>
36 #include <QSignalMapper>
37 #include <QSystemTrayIcon>
46 static QActionGroup *currentGroup;
48 // Add static entries to menus
49 #define DP_SADD( menu, text, help, icon, slot, shortcut ) \
51 if( strlen( icon ) > 0 ) \
53 if( strlen( shortcut ) > 0 ) \
55 menu->addAction( QIcon( icon ), text, THEDP, SLOT( slot ), \
60 menu->addAction( QIcon( icon ), text, THEDP, SLOT( slot ) );\
65 if( strlen( shortcut ) > 0 ) \
67 menu->addAction( text, THEDP, SLOT( slot ), \
72 menu->addAction( text, THEDP, SLOT( slot ) ); \
76 #define MIM_SADD( menu, text, help, icon, slot ) \
78 if( strlen( icon ) > 0 ) \
80 QAction *action = menu->addAction( text, THEMIM, SLOT( slot ) ); \
81 action->setIcon( QIcon( icon ) ); \
85 menu->addAction( text, THEMIM, SLOT( slot ) ); \
90 /*****************************************************************************
91 * Definitions of variables for the dynamic menus
92 *****************************************************************************/
93 #define PUSH_VAR( var ) varnames.push_back( var ); \
94 objects.push_back( p_object->i_object_id )
96 #define PUSH_SEPARATOR if( objects.size() != i_last_separator ) { \
97 objects.push_back( 0 ); varnames.push_back( "" ); \
98 i_last_separator = objects.size(); }
100 static int InputAutoMenuBuilder( vlc_object_t *p_object,
101 vector<int> &objects,
102 vector<const char *> &varnames )
104 PUSH_VAR( "bookmark");
106 PUSH_VAR ("chapter" );
107 PUSH_VAR( "program" );
108 PUSH_VAR( "navigation" );
109 PUSH_VAR( "dvd_menus" );
113 static int VideoAutoMenuBuilder( vlc_object_t *p_object,
114 vector<int> &objects,
115 vector<const char *> &varnames )
117 PUSH_VAR( "fullscreen" );
119 PUSH_VAR( "deinterlace" );
120 PUSH_VAR( "aspect-ratio" );
122 PUSH_VAR( "video-on-top" );
123 PUSH_VAR( "directx-wallpaper" );
124 PUSH_VAR( "video-snapshot" );
126 vlc_object_t *p_dec_obj = (vlc_object_t *)vlc_object_find( p_object,
129 if( p_dec_obj != NULL )
131 vlc_object_t *p_object = p_dec_obj;
132 PUSH_VAR( "ffmpeg-pp-q" );
133 vlc_object_release( p_dec_obj );
138 static int AudioAutoMenuBuilder( vlc_object_t *p_object,
139 vector<int> &objects,
140 vector<const char *> &varnames )
142 PUSH_VAR( "audio-device" );
143 PUSH_VAR( "audio-channels" );
144 PUSH_VAR( "visual" );
145 PUSH_VAR( "equalizer" );
149 /*****************************************************************************
152 *****************************************************************************/
154 #define BAR_ADD( func, title ) { \
155 QMenu *menu = func; menu->setTitle( title ); bar->addMenu( menu ); }
157 #define BAR_DADD( func, title, id ) { \
158 QMenu *menu = func; menu->setTitle( title ); bar->addMenu( menu ); \
159 MenuFunc *f = new MenuFunc( menu, id ); \
160 CONNECT( menu, aboutToShow(), THEDP->menusUpdateMapper, map() ); \
161 THEDP->menusUpdateMapper->setMapping( menu, f ); }
164 * Main Menu Bar Creation
166 void QVLCMenu::createMenuBar( MainInterface *mi, intf_thread_t *p_intf,
167 bool playlist, bool adv_controls_enabled,
168 bool visual_selector_enabled )
170 QMenuBar *bar = mi->menuBar();
171 BAR_ADD( FileMenu(), qtr("&Media") );
174 BAR_ADD( PlaylistMenu( mi,p_intf ), qtr("&Playlist" ) );
176 BAR_ADD( ToolsMenu( p_intf, mi, adv_controls_enabled,
177 visual_selector_enabled ), qtr("&Tools") );
178 BAR_DADD( VideoMenu( p_intf, NULL ), qtr("&Video"), 1 );
179 BAR_DADD( AudioMenu( p_intf, NULL ), qtr("&Audio"), 2 );
180 BAR_DADD( NavigMenu( p_intf, NULL ), qtr("&Navigation"), 3 );
182 BAR_ADD( HelpMenu(), qtr("&Help" ) );
187 * Opening, streaming and quit
189 QMenu *QVLCMenu::FileMenu()
191 QMenu *menu = new QMenu();
192 DP_SADD( menu, qtr("Open &File..." ), "",
193 ":/pixmaps/vlc_file-asym_16px.png", openFileDialog(), "Ctrl+O" );
195 /* Folder vs. Directory */
197 DP_SADD( menu, qtr( "Open Folder..." ), "",
198 ":/pixmaps/vlc_folder-grey_16px.png", openDirDialog(), "Ctrl+F" );
200 DP_SADD( menu, qtr( "Open Directory..." ), "",
201 ":/pixmaps/vlc_folder-grey_16px.png", openDirDialog(), "Ctrl+F" );
204 DP_SADD( menu, qtr("Open &Disc..." ), "", ":/pixmaps/vlc_disc_16px.png",
205 openDiscDialog(), "Ctrl+D" );
206 DP_SADD( menu, qtr("Open &Network..." ), "",
207 ":/pixmaps/vlc_network_16px.png", openNetDialog(), "Ctrl+N" );
208 DP_SADD( menu, qtr("Open &Capture Device..." ), "",
209 ":/pixmaps/vlc_capture-card_16px.png", openCaptureDialog(),
211 menu->addSeparator();
212 DP_SADD( menu, qtr("&Streaming..."), "", ":/pixmaps/vlc_stream_16px.png",
213 openThenStreamingDialogs(), "Ctrl+S" );
214 DP_SADD( menu, qtr("Conve&rt / Save..."), "", "",
215 openThenTranscodingDialogs(), "Ctrl+R" );
216 menu->addSeparator();
217 DP_SADD( menu, qtr("&Quit") , "", ":/pixmaps/vlc_quit_16px.png", quit(),
222 /* Playlist Menu, undocked when playlist is undocked */
223 QMenu *QVLCMenu::PlaylistMenu( MainInterface *mi, intf_thread_t *p_intf )
225 QMenu *menu = new QMenu();
226 menu->addMenu( SDMenu( p_intf ) );
227 menu->addAction ( QIcon(":/pixmaps/vlc_playlist_16px.png"),
228 qtr( "Show Playlist"), mi, SLOT( togglePlaylist() ) );
229 menu->addSeparator();
231 DP_SADD( menu, qtr( I_PL_LOAD ), "", "", openPlaylist(), "Ctrl+X" );
232 DP_SADD( menu, qtr( I_PL_SAVE ), "", "", savePlaylist(), "Ctrl+Y" );
233 menu->addSeparator();
234 menu->addAction( qtr("Undock from interface"), mi,
235 SLOT( undockPlaylist() ), qtr("Ctrl+U") );
241 * This is kept in the same menu for now, but could change if it gets much
244 QMenu *QVLCMenu::ToolsMenu( intf_thread_t *p_intf, MainInterface *mi,
245 bool adv_controls_enabled,
246 bool visual_selector_enabled, bool with_intf )
248 QMenu *menu = new QMenu();
251 QMenu *intfmenu = InterfacesMenu( p_intf, NULL );
252 intfmenu->setTitle( qtr("Interfaces" ) );
253 menu->addMenu( intfmenu );
254 menu->addSeparator();
256 DP_SADD( menu, qtr( I_MENU_MSG ), "", ":/pixmaps/vlc_messages_16px.png",
257 messagesDialog(), "Ctrl+M" );
258 DP_SADD( menu, qtr( I_MENU_INFO ) , "", "", mediaInfoDialog(), "Ctrl+J" );
259 DP_SADD( menu, qtr( I_MENU_CODECINFO ) , "", ":/pixmaps/vlc_info_16px.png",
260 mediaCodecDialog(), "Ctrl+I" );
261 DP_SADD( menu, qtr( I_MENU_GOTOTIME ), "","", gotoTimeDialog(), "Ctrl+T" );
262 #if 0 /* Not Implemented yet */
263 DP_SADD( menu, qtr( I_MENU_BOOKMARK ), "","", bookmarksDialog(), "Ctrl+B" );
264 DP_SADD( menu, qtr( I_MENU_VLM ), "","", vlmDialog(), "Ctrl+V" );
267 menu->addSeparator();
270 QAction *adv = menu->addAction( qtr("Advanced controls" ),
271 mi, SLOT( toggleAdvanced() ) );
272 adv->setCheckable( true );
273 if( adv_controls_enabled ) adv->setChecked( true );
275 menu->addAction( qtr( "Hide Menus..." ), mi, SLOT( toggleMenus() ),
277 menu->addSeparator();
279 #if 0 /* For Visualisations. Not yet working */
280 adv = menu->addAction( qtr("Visualizations selector" ),
281 mi, SLOT( visual() ) );
282 adv->setCheckable( true );
283 if( visual_selector_enabled ) adv->setChecked( true );
285 menu->addAction ( QIcon(":/pixmaps/vlc_playlist_16px.png"),
286 qtr( "Playlist"), mi, SLOT( togglePlaylist() ),
289 DP_SADD( menu, qtr( I_MENU_EXT ), "", ":/pixmaps/vlc_settings_16px.png",
290 extendedDialog() , "Ctrl+E" );
292 menu->addSeparator();
293 DP_SADD( menu, qtr("Preferences"), "", ":/pixmaps/vlc_preferences_16px.png",
294 prefsDialog(), "Ctrl+P" );
299 * Interface Sub-Menu, to list extras interface and skins
301 QMenu *QVLCMenu::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
304 vector<const char *> varnames;
305 /** \todo add "switch to XXX" */
306 varnames.push_back( "intf-add" );
307 objects.push_back( p_intf->i_object_id );
309 QMenu *menu = Populate( p_intf, current, varnames, objects );
311 if( !p_intf->pf_show_dialog )
313 menu->addSeparator();
314 menu->addAction( qtr("Switch to skins"), THEDP, SLOT( switchToSkins() ),
318 CONNECT( menu, aboutToShow(), THEDP->menusUpdateMapper, map() );
319 THEDP->menusUpdateMapper->setMapping( menu, 4 );
326 QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QMenu * current )
329 vector<const char *> varnames;
331 vlc_object_t *p_object = (vlc_object_t *)vlc_object_find( p_intf,
332 VLC_OBJECT_INPUT, FIND_ANYWHERE );
333 if( p_object != NULL )
335 PUSH_VAR( "audio-es" );
336 vlc_object_release( p_object );
339 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_AOUT,
343 AudioAutoMenuBuilder( p_object, objects, varnames );
344 vlc_object_release( p_object );
346 return Populate( p_intf, current, varnames, objects );
351 * Subtitles are part of Video.
353 QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current )
355 vlc_object_t *p_object;
357 vector<const char *> varnames;
359 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
361 if( p_object != NULL )
363 PUSH_VAR( "video-es" );
364 PUSH_VAR( "spu-es" );
365 vlc_object_release( p_object );
368 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT,
370 if( p_object != NULL )
372 VideoAutoMenuBuilder( p_object, objects, varnames );
373 vlc_object_release( p_object );
375 return Populate( p_intf, current, varnames, objects );
380 * For DVD, MP4, MOV and other chapter based format
382 QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *current )
384 vlc_object_t *p_object;
386 vector<const char *> varnames;
389 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
391 if( p_object != NULL )
393 InputAutoMenuBuilder( p_object, objects, varnames );
394 PUSH_VAR( "prev-title"); PUSH_VAR ( "next-title" );
395 PUSH_VAR( "prev-chapter"); PUSH_VAR( "next-chapter" );
396 vlc_object_release( p_object );
398 return Populate( p_intf, current, varnames, objects );
402 * Service Discovery Menu
404 QMenu *QVLCMenu::SDMenu( intf_thread_t *p_intf )
406 QMenu *menu = new QMenu();
407 menu->setTitle( qtr( I_PL_SD ) );
408 vlc_list_t *p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE,
411 for( int i_index = 0 ; i_index < p_list->i_count; i_index++ )
413 module_t * p_parser = (module_t *)p_list->p_values[i_index].p_object ;
414 if( module_IsCapable( p_parser, "services_discovery" ) )
417 for( int i_index = 0 ; i_index < p_list->i_count; i_index++ )
419 module_t * p_parser = (module_t *)p_list->p_values[i_index].p_object;
420 if( !module_IsCapable( p_parser, "services_discovery" ) )
423 QAction *a = new QAction( qfu( module_GetLongName( p_parser ) ), menu );
424 a->setCheckable( true );
425 /* hack to handle submodules properly */
427 while( p_parser->pp_shortcuts[++i] != NULL );
429 if( playlist_IsServicesDiscoveryLoaded( THEPL,
430 i>=0?p_parser->pp_shortcuts[i]
431 : module_GetObjName( p_parser ) ) )
432 a->setChecked( true );
433 CONNECT( a , triggered(), THEDP->SDMapper, map() );
434 THEDP->SDMapper->setMapping( a, i>=0? p_parser->pp_shortcuts[i] :
435 module_GetObjName( p_parser ) );
436 menu->addAction( a );
438 if( !strcmp( p_parser->psz_object_name, "podcast" ) )
440 QAction *b = new QAction( qfu( "Configure podcasts..." ), menu );
441 //b->setEnabled( a->isChecked() );
442 menu->addAction( b );
443 CONNECT( b, triggered(), THEDP, podcastConfigureDialog() );
446 vlc_list_release( p_list );
452 QMenu *QVLCMenu::HelpMenu()
454 QMenu *menu = new QMenu();
455 DP_SADD( menu, qtr("Help") , "", ":/pixmaps/vlc_help_16px.png",
456 helpDialog(), "F1" );
457 menu->addSeparator();
458 DP_SADD( menu, qtr( I_MENU_ABOUT ), "", "", aboutDialog(), "Ctrl+F1");
463 /*****************************************************************************
464 * Popup menus - Right Click menus *
465 *****************************************************************************/
466 #define POPUP_BOILERPLATE \
467 unsigned int i_last_separator = 0; \
468 vector<int> objects; \
469 vector<const char *> varnames; \
470 input_thread_t *p_input = THEMIM->getInput();
472 #define CREATE_POPUP \
473 QMenu *menu = new QMenu(); \
474 Populate( p_intf, menu, varnames, objects ); \
475 p_intf->p_sys->p_popup_menu = menu; \
476 menu->popup( QCursor::pos() ); \
477 p_intf->p_sys->p_popup_menu = NULL; \
478 i_last_separator = 0;
480 #define POPUP_PLAY_ENTRIES( menu )\
484 var_Get( p_input, "state", &val ); \
485 if( val.i_int == PLAYING_S ) \
486 MIM_SADD( menu, qtr("Pause"), "", ":/pixmaps/vlc_pause_16px.png", \
487 togglePlayPause() ) \
489 MIM_SADD( menu, qtr("Play"), "", ":/pixmaps/vlc_play_16px.png", \
490 togglePlayPause() ) \
492 else if( THEPL->items.i_size && THEPL->i_enabled ) \
493 MIM_SADD( menu, qtr("Play"), "", ":/pixmaps/vlc_play_16px.png", \
494 togglePlayPause() ); \
496 MIM_SADD( menu, qtr("Stop"), "", ":/pixmaps/vlc_stop_16px.png", stop() ); \
497 MIM_SADD( menu, qtr("Previous"), "", ":/pixmaps/vlc_previous_16px.png", \
499 MIM_SADD( menu, qtr("Next"), "", ":/pixmaps/vlc_next_16px.png", next() );
501 #define POPUP_STATIC_ENTRIES( menu ) \
502 QMenu *intfmenu = InterfacesMenu( p_intf, NULL ); \
503 intfmenu->setTitle( qtr("Interfaces" ) ); \
504 menu->addMenu( intfmenu ); \
506 QMenu *toolsmenu = ToolsMenu( p_intf, NULL, false, false, false ); \
507 toolsmenu->setTitle( qtr("Tools" ) ); \
508 menu->addMenu( toolsmenu ); \
510 QMenu *openmenu = new QMenu( qtr("Open") ); \
511 openmenu->addAction( qtr("Open &File..." ), THEDP, SLOT( openFileDialog() ) ); \
512 openmenu->addAction( qtr("Open &Disc..." ), THEDP, SLOT( openDiscDialog() ) ); \
513 openmenu->addAction( qtr("Open &Network..." ), THEDP, SLOT( openNetDialog() ) ); \
514 openmenu->addAction( qtr("Open &Capture Device..." ), THEDP, \
515 SLOT( openCaptureDialog() ) ); \
516 menu->addMenu( openmenu ); \
518 menu->addSeparator(); \
519 QMenu *helpmenu = HelpMenu(); \
520 helpmenu->setTitle( qtr("Help") ); \
521 menu->addMenu( helpmenu ); \
523 DP_SADD( menu, qtr("Quit"), "", "", quit() , "Ctrl+Q" );
525 /* Video Tracks and Subtitles tracks */
526 void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf )
531 vlc_object_yield( p_input );
532 varnames.push_back( "video-es" );
533 objects.push_back( p_input->i_object_id );
534 varnames.push_back( "spu-es" );
535 objects.push_back( p_input->i_object_id );
536 vlc_object_t *p_vout = (vlc_object_t *)vlc_object_find( p_input,
537 VLC_OBJECT_VOUT, FIND_CHILD );
540 VideoAutoMenuBuilder( p_vout, objects, varnames );
541 vlc_object_release( p_vout );
543 vlc_object_release( p_input );
549 void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf )
554 vlc_object_yield( p_input );
555 varnames.push_back( "audio-es" );
556 objects.push_back( p_input->i_object_id );
557 vlc_object_t *p_aout = (vlc_object_t *)vlc_object_find( p_input,
558 VLC_OBJECT_AOUT, FIND_ANYWHERE );
561 AudioAutoMenuBuilder( p_aout, objects, varnames );
562 vlc_object_release( p_aout );
564 vlc_object_release( p_input );
569 /* Navigation stuff, and general menus (open) */
570 void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf )
577 vlc_object_yield( p_input );
578 varnames.push_back( "audio-es" );
579 InputAutoMenuBuilder( VLC_OBJECT(p_input), objects, varnames );
583 QMenu *menu = new QMenu();
584 Populate( p_intf, menu, varnames, objects );
586 menu->addSeparator();
587 POPUP_PLAY_ENTRIES( menu );
589 menu->addSeparator();
590 POPUP_STATIC_ENTRIES( menu );
592 p_intf->p_sys->p_popup_menu = menu;
593 menu->popup( QCursor::pos() );
594 p_intf->p_sys->p_popup_menu = NULL;
597 /* Main Menu that sticks everything together */
598 void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show )
602 // create a popup if there is none
603 if( ! p_intf->p_sys->p_popup_menu )
608 vlc_object_yield( p_input );
609 InputAutoMenuBuilder( VLC_OBJECT(p_input), objects, varnames );
613 varnames.push_back( "video-es" );
614 objects.push_back( p_input->i_object_id );
615 varnames.push_back( "spu-es" );
616 objects.push_back( p_input->i_object_id );
617 vlc_object_t *p_vout = (vlc_object_t *)vlc_object_find( p_input,
618 VLC_OBJECT_VOUT, FIND_CHILD );
621 VideoAutoMenuBuilder( p_vout, objects, varnames );
622 vlc_object_release( p_vout );
626 varnames.push_back( "audio-es" );
627 objects.push_back( p_input->i_object_id );
628 vlc_object_t *p_aout = (vlc_object_t *)vlc_object_find( p_input,
629 VLC_OBJECT_AOUT, FIND_ANYWHERE );
632 AudioAutoMenuBuilder( p_aout, objects, varnames );
633 vlc_object_release( p_aout );
637 QMenu *menu = new QMenu();
638 Populate( p_intf, menu, varnames, objects );
639 menu->addSeparator();
640 POPUP_PLAY_ENTRIES( menu );
641 menu->addSeparator();
642 POPUP_STATIC_ENTRIES( menu );
644 p_intf->p_sys->p_popup_menu = menu;
646 p_intf->p_sys->p_popup_menu->popup( QCursor::pos() );
650 // destroy popup if there is one
651 delete p_intf->p_sys->p_popup_menu;
652 p_intf->p_sys->p_popup_menu = NULL;
656 /************************************************************************
658 ************************************************************************/
660 void QVLCMenu::updateSystrayMenu( MainInterface *mi,
661 intf_thread_t *p_intf,
662 bool b_force_visible )
666 /* Get the systray menu and clean it */
667 QMenu *sysMenu = mi->getSysTrayMenu();
670 /* Hide / Show VLC and cone */
671 if( mi->isVisible() || b_force_visible )
673 sysMenu->addAction( QIcon( ":/vlc16.png" ),
674 qtr("Hide VLC media player"), mi,
675 SLOT( toggleUpdateSystrayMenu() ) );
679 sysMenu->addAction( QIcon( ":/vlc16.png" ),
680 qtr("Show VLC media player"), mi,
681 SLOT( toggleUpdateSystrayMenu() ) );
684 sysMenu->addSeparator();
685 POPUP_PLAY_ENTRIES( sysMenu );
687 sysMenu->addSeparator();
688 DP_SADD( sysMenu, qtr("&Open Media" ), "",
689 ":/pixmaps/vlc_file-wide_16px.png", openFileDialog(), "" );
690 DP_SADD( sysMenu, qtr("&Quit") , "", ":/pixmaps/vlc_quit_16px.png",
694 mi->getSysTray()->setContextMenu( sysMenu );
698 #undef PUSH_SEPARATOR
701 /*************************************************************************
702 * Builders for automenus
703 *************************************************************************/
704 QMenu * QVLCMenu::Populate( intf_thread_t *p_intf, QMenu *current,
705 vector< const char *> & varnames,
706 vector<int> & objects, bool append )
708 QMenu *menu = current;
716 vlc_object_t *p_object;
717 vlc_bool_t b_section_empty = VLC_FALSE;
720 #define APPEND_EMPTY { QAction *action = menu->addAction( qtr("Empty" ) ); \
721 action->setEnabled( false ); }
723 for( i = 0; i < (int)objects.size() ; i++ )
725 if( !varnames[i] || !*varnames[i] )
727 if( b_section_empty )
729 menu->addSeparator();
730 b_section_empty = VLC_TRUE;
734 if( objects[i] == 0 )
736 /// \bug What is this ?
737 // Append( menu, varnames[i], NULL );
738 b_section_empty = VLC_FALSE;
742 p_object = (vlc_object_t *)vlc_object_get( p_intf,
744 if( p_object == NULL ) continue;
746 b_section_empty = VLC_FALSE;
747 /* Ugly specific stuff */
748 if( strstr(varnames[i], "intf-add" ) )
749 CreateItem( menu, varnames[i], p_object, false );
751 CreateItem( menu, varnames[i], p_object, true );
752 vlc_object_release( p_object );
755 /* Special case for empty menus */
756 if( menu->actions().size() == 0 || b_section_empty )
762 /*****************************************************************************
764 *****************************************************************************/
766 static bool IsMenuEmpty( const char *psz_var, vlc_object_t *p_object,
769 vlc_value_t val, val_list;
770 int i_type, i_result, i;
772 /* Check the type of the object variable */
773 i_type = var_Type( p_object, psz_var );
775 /* Check if we want to display the variable */
776 if( !(i_type & VLC_VAR_HASCHOICE) ) return FALSE;
778 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
779 if( val.i_int == 0 ) return TRUE;
781 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE )
783 /* Very evil hack ! intf-switch can have only one value */
784 if( !strcmp( psz_var, "intf-switch" ) ) return FALSE;
785 if( val.i_int == 1 && b_root ) return TRUE;
789 /* Check children variables in case of VLC_VAR_VARIABLE */
790 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
795 for( i = 0, i_result = TRUE; i < val_list.p_list->i_count; i++ )
797 if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
805 /* clean up everything */
806 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, NULL );
811 void QVLCMenu::CreateItem( QMenu *menu, const char *psz_var,
812 vlc_object_t *p_object, bool b_submenu )
814 vlc_value_t val, text;
817 /* Check the type of the object variable */
818 i_type = var_Type( p_object, psz_var );
820 switch( i_type & VLC_VAR_TYPE )
824 case VLC_VAR_VARIABLE:
826 case VLC_VAR_INTEGER:
830 /* Variable doesn't exist or isn't handled */
834 /* Make sure we want to display the variable */
835 if( IsMenuEmpty( psz_var, p_object ) ) return;
837 /* Get the descriptive name of the variable */
838 var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
840 if( i_type & VLC_VAR_HASCHOICE )
842 /* Append choices menu */
845 QMenu *submenu = new QMenu();
846 submenu->setTitle( qfu( text.psz_string ?
847 text.psz_string : psz_var ) );
848 if( CreateChoicesMenu( submenu, psz_var, p_object, true ) == 0)
849 menu->addMenu( submenu );
852 CreateChoicesMenu( menu, psz_var, p_object, true );
853 FREENULL( text.psz_string );
857 #define TEXT_OR_VAR qfu ( text.psz_string ? text.psz_string : psz_var )
859 switch( i_type & VLC_VAR_TYPE )
862 var_Get( p_object, psz_var, &val );
863 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_NORMAL,
864 p_object->i_object_id, val, i_type );
868 var_Get( p_object, psz_var, &val );
869 val.b_bool = !val.b_bool;
870 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_CHECK,
871 p_object->i_object_id, val, i_type, !val.b_bool );
874 FREENULL( text.psz_string );
878 int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
879 vlc_object_t *p_object, bool b_root )
881 vlc_value_t val, val_list, text_list;
884 /* Check the type of the object variable */
885 i_type = var_Type( p_object, psz_var );
887 /* Make sure we want to display the variable */
888 if( IsMenuEmpty( psz_var, p_object, b_root ) ) return VLC_EGENERIC;
890 switch( i_type & VLC_VAR_TYPE )
894 case VLC_VAR_VARIABLE:
896 case VLC_VAR_INTEGER:
900 /* Variable doesn't exist or isn't handled */
904 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
905 &val_list, &text_list ) < 0 )
909 #define NORMAL_OR_RADIO i_type & VLC_VAR_ISCOMMAND ? ITEM_NORMAL: ITEM_RADIO
910 #define NOTCOMMAND !(i_type & VLC_VAR_ISCOMMAND)
911 #define CURVAL val_list.p_list->p_values[i]
912 #define CURTEXT text_list.p_list->p_values[i].psz_string
914 for( i = 0; i < val_list.p_list->i_count; i++ )
916 vlc_value_t another_val;
918 QMenu *subsubmenu = new QMenu();
920 switch( i_type & VLC_VAR_TYPE )
922 case VLC_VAR_VARIABLE:
923 CreateChoicesMenu( subsubmenu, CURVAL.psz_string, p_object, false );
924 subsubmenu->setTitle( qfu( CURTEXT ? CURTEXT :CURVAL.psz_string ) );
925 submenu->addMenu( subsubmenu );
929 var_Get( p_object, psz_var, &val );
930 another_val.psz_string = strdup( CURVAL.psz_string );
931 menutext = qfu( CURTEXT ? CURTEXT : another_val.psz_string );
932 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
933 p_object->i_object_id, another_val, i_type,
934 NOTCOMMAND && val.psz_string &&
935 !strcmp( val.psz_string, CURVAL.psz_string ) );
937 if( val.psz_string ) free( val.psz_string );
940 case VLC_VAR_INTEGER:
941 var_Get( p_object, psz_var, &val );
942 if( CURTEXT ) menutext = qfu( CURTEXT );
943 else menutext.sprintf( "%d", CURVAL.i_int);
944 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
945 p_object->i_object_id, CURVAL, i_type,
946 NOTCOMMAND && CURVAL.i_int == val.i_int );
950 var_Get( p_object, psz_var, &val );
951 if( CURTEXT ) menutext = qfu( CURTEXT );
952 else menutext.sprintf( "%.2f", CURVAL.f_float );
953 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
954 p_object->i_object_id, CURVAL, i_type,
955 NOTCOMMAND && CURVAL.f_float == val.f_float );
964 /* clean up everything */
965 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
967 #undef NORMAL_OR_RADIO
974 void QVLCMenu::CreateAndConnect( QMenu *menu, const char *psz_var,
975 QString text, QString help,
976 int i_item_type, int i_object_id,
977 vlc_value_t val, int i_val_type,
980 QAction *action = new QAction( text, menu );
981 action->setText( text );
982 action->setToolTip( help );
984 if( i_item_type == ITEM_CHECK )
986 action->setCheckable( true );
988 else if( i_item_type == ITEM_RADIO )
990 action->setCheckable( true );
992 currentGroup = new QActionGroup( menu );
993 currentGroup->addAction( action );
998 action->setChecked( true );
1000 MenuItemData *itemData = new MenuItemData( i_object_id, i_val_type,
1002 CONNECT( action, triggered(), THEDP->menusMapper, map() );
1003 THEDP->menusMapper->setMapping( action, itemData );
1004 menu->addAction( action );
1007 void QVLCMenu::DoAction( intf_thread_t *p_intf, QObject *data )
1009 MenuItemData *itemData = qobject_cast<MenuItemData *>(data);
1010 vlc_object_t *p_object = (vlc_object_t *)vlc_object_get( p_intf,
1011 itemData->i_object_id );
1012 if( p_object == NULL ) return;
1014 var_Set( p_object, itemData->psz_var, itemData->val );
1015 vlc_object_release( p_object );