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 *****************************************************************************/
28 #include <QActionGroup>
29 #include <QSignalMapper>
30 #include <QSystemTrayIcon>
36 #include <vlc_intf_strings.h>
38 #include "main_interface.hpp"
40 #include "dialogs_provider.hpp"
41 #include "input_manager.hpp"
50 static QActionGroup *currentGroup;
52 // Add static entries to menus
53 #define DP_SADD( menu, text, help, icon, slot, shortcut ) \
55 if( strlen(icon) > 0 ) \
57 if( strlen(shortcut) > 0 ) \
59 menu->addAction( QIcon(icon), text, THEDP, SLOT( slot ), \
64 menu->addAction( QIcon(icon), text, THEDP, SLOT( slot ) );\
69 if( strlen(shortcut) > 0 ) \
71 menu->addAction( text, THEDP, SLOT( slot ), \
76 menu->addAction( text, THEDP, SLOT( slot ) ); \
80 #define MIM_SADD( menu, text, help, icon, slot ) \
82 if( strlen(icon) > 0 ) \
84 QAction *action = menu->addAction( text, THEMIM, SLOT( slot ) ); \
85 action->setIcon(QIcon(icon)); \
89 menu->addAction( text, THEMIM, SLOT( slot ) ); \
94 /*****************************************************************************
95 * Definitions of variables for the dynamic menus
96 *****************************************************************************/
97 #define PUSH_VAR( var ) varnames.push_back( var ); \
98 objects.push_back( p_object->i_object_id )
100 #define PUSH_SEPARATOR if( objects.size() != i_last_separator ) { \
101 objects.push_back( 0 ); varnames.push_back( "" ); \
102 i_last_separator = objects.size(); }
104 static int InputAutoMenuBuilder( vlc_object_t *p_object,
105 vector<int> &objects,
106 vector<const char *> &varnames )
108 PUSH_VAR( "bookmark");
110 PUSH_VAR ("chapter" );
111 PUSH_VAR( "program" );
112 PUSH_VAR( "navigation" );
113 PUSH_VAR( "dvd_menus" );
117 static int VideoAutoMenuBuilder( vlc_object_t *p_object,
118 vector<int> &objects,
119 vector<const char *> &varnames )
121 PUSH_VAR( "fullscreen" );
123 PUSH_VAR( "deinterlace" );
124 PUSH_VAR( "aspect-ratio" );
126 PUSH_VAR( "video-on-top" );
127 PUSH_VAR( "directx-wallpaper" );
128 PUSH_VAR( "video-snapshot" );
130 vlc_object_t *p_dec_obj = (vlc_object_t *)vlc_object_find( p_object,
133 if( p_dec_obj != NULL )
135 vlc_object_t *p_object = p_dec_obj;
136 PUSH_VAR( "ffmpeg-pp-q" );
137 vlc_object_release( p_dec_obj );
142 static int AudioAutoMenuBuilder( vlc_object_t *p_object,
143 vector<int> &objects,
144 vector<const char *> &varnames )
146 PUSH_VAR( "audio-device" );
147 PUSH_VAR( "audio-channels" );
148 PUSH_VAR( "visual" );
149 PUSH_VAR( "equalizer" );
153 /*****************************************************************************
155 *****************************************************************************/
157 #define BAR_ADD( func, title ) { \
158 QMenu *menu = func; menu->setTitle( title ); bar->addMenu( menu ); }
160 #define BAR_DADD( func, title, id ) { \
161 QMenu *menu = func; menu->setTitle( title ); bar->addMenu( menu ); \
162 MenuFunc *f = new MenuFunc( menu, id ); \
163 CONNECT( menu, aboutToShow(), THEDP->menusUpdateMapper, map() ); \
164 THEDP->menusUpdateMapper->setMapping( menu, f ); }
166 void QVLCMenu::createMenuBar( MainInterface *mi, intf_thread_t *p_intf,
167 bool playlist, bool adv_controls_enabled,
168 bool visual_selector_enabled )
172 * Remove SIGCHLD from the ignored signal the time to initialise
173 * Qt because it call gconf to get the icon theme */
177 sigaddset( &set, SIGCHLD );
178 pthread_sigmask (SIG_UNBLOCK, &set, NULL);
180 QMenuBar *bar = mi->menuBar();
182 pthread_sigmask (SIG_BLOCK, &set, NULL);
184 BAR_ADD( FileMenu(), qtr("&Media") );
187 BAR_ADD( PlaylistMenu( mi,p_intf ), qtr("&Playlist" ) );
189 BAR_ADD( ToolsMenu( p_intf, mi, adv_controls_enabled,
190 visual_selector_enabled ), qtr("&Tools") );
191 BAR_DADD( VideoMenu( p_intf, NULL ), qtr("&Video"), 1 );
192 BAR_DADD( AudioMenu( p_intf, NULL ), qtr("&Audio"), 2 );
193 BAR_DADD( NavigMenu( p_intf, NULL ), qtr("&Navigation"), 3 );
195 BAR_ADD( HelpMenu(), qtr("&Help" ) );
197 QMenu *QVLCMenu::FileMenu()
199 QMenu *menu = new QMenu();
200 DP_SADD( menu, qtr("Open &File..." ), "", "", openFileDialog(), "Ctrl+O" );
201 DP_SADD( menu, qtr("Open &Disc..." ), "", "", openDiscDialog(), "Ctrl+D" );
202 DP_SADD( menu, qtr("Open &Network..." ), "", "", openNetDialog(), "Ctrl+N" );
203 DP_SADD( menu, qtr("Open &Capture Device..." ), "", "", openCaptureDialog(),
205 menu->addSeparator();
206 DP_SADD( menu, qtr("&Streaming..."), "", "", openThenStreamingDialogs(),
208 DP_SADD( menu, qtr("Conve&rt / Save..."), "", "", openThenTranscodingDialogs(),
210 menu->addSeparator();
211 DP_SADD( menu, qtr("&Quit") , "", "", quit(), "Ctrl+Q");
215 QMenu *QVLCMenu::PlaylistMenu( MainInterface *mi, intf_thread_t *p_intf )
217 QMenu *menu = new QMenu();
218 menu->addMenu( SDMenu( p_intf ) );
219 menu->addSeparator();
221 DP_SADD( menu, qtr(I_PL_LOAD), "", "", openPlaylist(), "Ctrl+L" );
222 DP_SADD( menu, qtr(I_PL_SAVE), "", "", savePlaylist(), "Ctrl+K" );
223 menu->addSeparator();
224 menu->addAction( qtr("Undock from interface"), mi,
225 SLOT( undockPlaylist() ), qtr("Ctrl+U") );
229 QMenu *QVLCMenu::ToolsMenu( intf_thread_t *p_intf, MainInterface *mi,
230 bool adv_controls_enabled,
231 bool visual_selector_enabled, bool with_intf )
233 QMenu *menu = new QMenu();
236 QMenu *intfmenu = InterfacesMenu( p_intf, NULL );
237 intfmenu->setTitle( qtr("Interfaces" ) );
238 menu->addMenu( intfmenu );
239 menu->addSeparator();
241 DP_SADD( menu, qtr(I_MENU_MSG), "", "", messagesDialog(), "Ctrl+M" );
242 DP_SADD( menu, qtr(I_MENU_INFO) , "", "", mediaInfoDialog(), "Ctrl+J" );
243 DP_SADD( menu, qtr(I_MENU_CODECINFO) , "", "", mediaCodecDialog(), "Ctrl+I" );
244 DP_SADD( menu, qtr(I_MENU_GOTOTIME), "","", gotoTimeDialog(), "Ctrl+T" );
245 DP_SADD( menu, qtr(I_MENU_BOOKMARK), "","", bookmarksDialog(), "Ctrl+B" );
246 DP_SADD( menu, qtr(I_MENU_VLM), "","", vlmDialog(), "Ctrl+V" );
248 menu->addSeparator();
251 QAction *adv = menu->addAction( qtr("Advanced controls" ),
252 mi, SLOT( advanced() ) );
253 adv->setCheckable( true );
254 if( adv_controls_enabled ) adv->setChecked( true );
256 adv = menu->addAction( qtr("Visualizations selector" ),
257 mi, SLOT( visual() ) );
258 adv->setCheckable( true );
259 if( visual_selector_enabled ) adv->setChecked( true );
261 menu->addAction ( qtr( "Playlist"), mi, SLOT( playlist() ) );
263 DP_SADD( menu, qtr(I_MENU_EXT), "","",extendedDialog(), "Ctrl+E" );
264 DP_SADD( menu, qtr("Hide Menus..."), "","",hideMenus(), "Ctrl+H" );
265 menu->addSeparator();
266 DP_SADD( menu, qtr("Preferences"), "", "", prefsDialog(), "Ctrl+P" );
270 QMenu *QVLCMenu::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
273 vector<const char *> varnames;
274 /** \todo add "switch to XXX" */
275 varnames.push_back( "intf-add" );
276 objects.push_back( p_intf->i_object_id );
278 QMenu *menu = Populate( p_intf, current, varnames, objects );
280 if( !p_intf->pf_show_dialog )
282 menu->addSeparator();
283 menu->addAction( qtr("Switch to skins"), THEDP, SLOT(switchToSkins()),
287 CONNECT( menu, aboutToShow(), THEDP->menusUpdateMapper, map() );
288 THEDP->menusUpdateMapper->setMapping( menu, 4 );
292 QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QMenu * current )
295 vector<const char *> varnames;
297 vlc_object_t *p_object = (vlc_object_t *)vlc_object_find( p_intf,
298 VLC_OBJECT_INPUT, FIND_ANYWHERE );
299 if( p_object != NULL )
301 PUSH_VAR( "audio-es" );
302 vlc_object_release( p_object );
305 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_AOUT,
309 AudioAutoMenuBuilder( p_object, objects, varnames );
310 vlc_object_release( p_object );
312 return Populate( p_intf, current, varnames, objects );
316 QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current )
318 vlc_object_t *p_object;
320 vector<const char *> varnames;
322 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
324 if( p_object != NULL )
326 PUSH_VAR( "video-es" );
327 PUSH_VAR( "spu-es" );
328 vlc_object_release( p_object );
331 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT,
333 if( p_object != NULL )
335 VideoAutoMenuBuilder( p_object, objects, varnames );
336 vlc_object_release( p_object );
338 return Populate( p_intf, current, varnames, objects );
341 QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *current )
343 vlc_object_t *p_object;
345 vector<const char *> varnames;
348 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
350 if( p_object != NULL )
352 InputAutoMenuBuilder( p_object, objects, varnames );
353 PUSH_VAR( "prev-title"); PUSH_VAR ( "next-title" );
354 PUSH_VAR( "prev-chapter"); PUSH_VAR( "next-chapter" );
355 vlc_object_release( p_object );
357 return Populate( p_intf, current, varnames, objects );
360 QMenu *QVLCMenu::SDMenu( intf_thread_t *p_intf )
362 QMenu *menu = new QMenu();
363 menu->setTitle( qtr(I_PL_SD) );
364 vlc_list_t *p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE,
367 for( int i_index = 0 ; i_index < p_list->i_count; i_index++ )
369 module_t * p_parser = (module_t *)p_list->p_values[i_index].p_object ;
370 if( !strcmp( p_parser->psz_capability, "services_discovery" ) )
373 for( int i_index = 0 ; i_index < p_list->i_count; i_index++ )
375 module_t * p_parser = (module_t *)p_list->p_values[i_index].p_object;
376 if( !strcmp( p_parser->psz_capability, "services_discovery" ) )
378 QAction *a = new QAction( qfu( p_parser->psz_longname ), menu );
379 a->setCheckable( true );
380 /* hack to handle submodules properly */
382 while( p_parser->pp_shortcuts[++i] != NULL );
384 if( playlist_IsServicesDiscoveryLoaded( THEPL,
385 i>=0?p_parser->pp_shortcuts[i] : p_parser->psz_object_name ) )
387 a->setChecked( true );
389 CONNECT( a , triggered(), THEDP->SDMapper, map() );
390 THEDP->SDMapper->setMapping( a, i>=0? p_parser->pp_shortcuts[i] :
391 p_parser->psz_object_name );
392 menu->addAction( a );
395 vlc_list_release( p_list );
399 QMenu *QVLCMenu::HelpMenu()
401 QMenu *menu = new QMenu();
402 DP_SADD( menu, qtr("Help") , "", "", helpDialog(), "F1" );
403 menu->addSeparator();
404 DP_SADD( menu, qtr(I_MENU_ABOUT), "", "", aboutDialog(), "Ctrl+F1");
409 /*****************************************************************************
411 *****************************************************************************/
412 #define POPUP_BOILERPLATE \
413 unsigned int i_last_separator = 0; \
414 vector<int> objects; \
415 vector<const char *> varnames; \
416 input_thread_t *p_input = THEMIM->getInput();
418 #define CREATE_POPUP \
419 QMenu *menu = new QMenu(); \
420 Populate( p_intf, menu, varnames, objects ); \
421 p_intf->p_sys->p_popup_menu = menu; \
422 menu->popup( QCursor::pos() ); \
423 p_intf->p_sys->p_popup_menu = NULL; \
424 i_last_separator = 0;
426 #define POPUP_PLAY_ENTRIES( menu )\
430 var_Get( p_input, "state", &val ); \
431 if( val.i_int == PLAYING_S ) \
432 MIM_SADD( menu, qtr("Pause"), "", "", togglePlayPause() ) \
434 MIM_SADD( menu, qtr("Play"), "", "", togglePlayPause() ) \
436 else if( THEPL->items.i_size && THEPL->i_enabled ) \
437 MIM_SADD( menu, qtr("Play"), "", "", togglePlayPause() ); \
439 MIM_SADD( menu, qtr("Stop"), "", "", stop() ); \
440 MIM_SADD( menu, qtr("Previous"), "", "", prev() ); \
441 MIM_SADD( menu, qtr("Next"), "", "", next() );
443 #define POPUP_STATIC_ENTRIES \
444 POPUP_PLAY_ENTRIES( menu ); \
446 menu->addSeparator(); \
447 QMenu *intfmenu = InterfacesMenu( p_intf, NULL ); \
448 intfmenu->setTitle( qtr("Interfaces" ) ); \
449 menu->addMenu( intfmenu ); \
451 QMenu *toolsmenu = ToolsMenu( p_intf, NULL, false, false, false ); \
452 toolsmenu->setTitle( qtr("Tools" ) ); \
453 menu->addMenu( toolsmenu ); \
455 QMenu *openmenu = new QMenu( qtr("Open") ); \
456 openmenu->addAction( qtr("Open &File..." ), THEDP, SLOT( openFileDialog() ) ); \
457 openmenu->addAction( qtr("Open &Disc..." ), THEDP, SLOT( openDiscDialog() ) ); \
458 openmenu->addAction( qtr("Open &Network..." ), THEDP, SLOT( openNetDialog() ) ); \
459 openmenu->addAction( qtr("Open &Capture Device..." ), THEDP, \
460 SLOT( openCaptureDialog() ) ); \
461 menu->addMenu( openmenu ); \
463 menu->addSeparator(); \
464 QMenu *helpmenu = HelpMenu(); \
465 helpmenu->setTitle( qtr("Help") ); \
466 menu->addMenu( helpmenu ); \
468 DP_SADD( menu, qtr("Quit"), "", "", quit() , "Ctrl+Q" );
470 void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf )
475 vlc_object_yield( p_input );
476 varnames.push_back( "video-es" );
477 objects.push_back( p_input->i_object_id );
478 varnames.push_back( "spu-es" );
479 objects.push_back( p_input->i_object_id );
480 vlc_object_t *p_vout = (vlc_object_t *)vlc_object_find( p_input,
481 VLC_OBJECT_VOUT, FIND_CHILD );
484 VideoAutoMenuBuilder( p_vout, objects, varnames );
485 vlc_object_release( p_vout );
487 vlc_object_release( p_input );
492 void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf )
497 vlc_object_yield( p_input );
498 varnames.push_back( "audio-es" );
499 objects.push_back( p_input->i_object_id );
500 vlc_object_t *p_aout = (vlc_object_t *)vlc_object_find( p_input,
501 VLC_OBJECT_AOUT, FIND_ANYWHERE );
504 AudioAutoMenuBuilder( p_aout, objects, varnames );
505 vlc_object_release( p_aout );
507 vlc_object_release( p_input );
512 /* Navigation stuff, and general */
513 void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf )
518 vlc_object_yield( p_input );
519 varnames.push_back( "audio-es" );
520 InputAutoMenuBuilder( VLC_OBJECT(p_input), objects, varnames );
524 QMenu *menu = new QMenu();
525 Populate( p_intf, menu, varnames, objects );
526 menu->addSeparator();
527 POPUP_STATIC_ENTRIES;
529 p_intf->p_sys->p_popup_menu = menu;
530 menu->popup( QCursor::pos() );
531 p_intf->p_sys->p_popup_menu = NULL;
534 void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show )
538 // create a popup if there is none
539 if( ! p_intf->p_sys->p_popup_menu )
544 vlc_object_yield( p_input );
545 InputAutoMenuBuilder( VLC_OBJECT(p_input), objects, varnames );
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 );
562 varnames.push_back( "audio-es" );
563 objects.push_back( p_input->i_object_id );
564 vlc_object_t *p_aout = (vlc_object_t *)vlc_object_find( p_input,
565 VLC_OBJECT_AOUT, FIND_ANYWHERE );
568 AudioAutoMenuBuilder( p_aout, objects, varnames );
569 vlc_object_release( p_aout );
573 QMenu *menu = new QMenu();
574 Populate( p_intf, menu, varnames, objects );
575 menu->addSeparator();
576 POPUP_STATIC_ENTRIES;
578 p_intf->p_sys->p_popup_menu = menu;
580 p_intf->p_sys->p_popup_menu->popup( QCursor::pos() );
584 // destroy popup if there is one
585 delete p_intf->p_sys->p_popup_menu;
586 p_intf->p_sys->p_popup_menu = NULL;
590 /************************************************************************
592 ************************************************************************/
594 void QVLCMenu::updateSystrayMenu( MainInterface *mi, intf_thread_t *p_intf,
595 bool b_force_visible )
598 QMenu *sysMenu = mi->getSysTrayMenu();
600 POPUP_PLAY_ENTRIES( sysMenu );
601 sysMenu->addSeparator();
603 if( !mi->isVisible() || b_force_visible )
605 sysMenu->addAction( qtr("Hide Interface"), mi,
606 SLOT( toggleUpdateSystrayMenu() ) );
610 sysMenu->addAction( qtr("Show Interface"), mi,
611 SLOT( toggleUpdateSystrayMenu() ) );
613 DP_SADD( sysMenu, qtr("&Open" ), "", "", openFileDialog(), "" );
614 DP_SADD( sysMenu, qtr("&Quit") , "", "", quit(), "" );
616 mi->getSysTray()->setContextMenu( sysMenu );
620 #undef PUSH_SEPARATOR
623 /*************************************************************************
624 * Builders for automenus
625 *************************************************************************/
626 QMenu * QVLCMenu::Populate( intf_thread_t *p_intf, QMenu *current,
627 vector< const char *> & varnames,
628 vector<int> & objects, bool append )
630 QMenu *menu = current;
638 vlc_object_t *p_object;
639 vlc_bool_t b_section_empty = VLC_FALSE;
642 #define APPEND_EMPTY { QAction *action = menu->addAction( qtr("Empty" ) ); \
643 action->setEnabled( false ); }
645 for( i = 0; i < (int)objects.size() ; i++ )
647 if( !varnames[i] || !*varnames[i] )
649 if( b_section_empty )
651 menu->addSeparator();
652 b_section_empty = VLC_TRUE;
656 if( objects[i] == 0 )
658 /// \bug What is this ?
659 // Append( menu, varnames[i], NULL );
660 b_section_empty = VLC_FALSE;
664 p_object = (vlc_object_t *)vlc_object_get( p_intf,
666 if( p_object == NULL ) continue;
668 b_section_empty = VLC_FALSE;
669 /* Ugly specific stuff */
670 if( strstr(varnames[i], "intf-add" ) )
671 CreateItem( menu, varnames[i], p_object, false );
673 CreateItem( menu, varnames[i], p_object, true );
674 vlc_object_release( p_object );
677 /* Special case for empty menus */
678 if( menu->actions().size() == 0 || b_section_empty )
684 /*****************************************************************************
686 *****************************************************************************/
688 static bool IsMenuEmpty( const char *psz_var, vlc_object_t *p_object,
691 vlc_value_t val, val_list;
692 int i_type, i_result, i;
694 /* Check the type of the object variable */
695 i_type = var_Type( p_object, psz_var );
697 /* Check if we want to display the variable */
698 if( !(i_type & VLC_VAR_HASCHOICE) ) return FALSE;
700 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
701 if( val.i_int == 0 ) return TRUE;
703 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE )
705 /* Very evil hack ! intf-switch can have only one value */
706 if( !strcmp( psz_var, "intf-switch" ) ) return FALSE;
707 if( val.i_int == 1 && b_root ) return TRUE;
711 /* Check children variables in case of VLC_VAR_VARIABLE */
712 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
717 for( i = 0, i_result = TRUE; i < val_list.p_list->i_count; i++ )
719 if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
727 /* clean up everything */
728 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, NULL );
733 void QVLCMenu::CreateItem( QMenu *menu, const char *psz_var,
734 vlc_object_t *p_object, bool b_submenu )
736 vlc_value_t val, text;
739 /* Check the type of the object variable */
740 i_type = var_Type( p_object, psz_var );
742 switch( i_type & VLC_VAR_TYPE )
746 case VLC_VAR_VARIABLE:
748 case VLC_VAR_INTEGER:
752 /* Variable doesn't exist or isn't handled */
756 /* Make sure we want to display the variable */
757 if( IsMenuEmpty( psz_var, p_object ) ) return;
759 /* Get the descriptive name of the variable */
760 var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
762 if( i_type & VLC_VAR_HASCHOICE )
764 /* Append choices menu */
767 QMenu *submenu = new QMenu();
768 submenu->setTitle( qfu( text.psz_string ?
769 text.psz_string : psz_var ) );
770 if( CreateChoicesMenu( submenu, psz_var, p_object, true ) == 0)
771 menu->addMenu( submenu );
774 CreateChoicesMenu( menu, psz_var, p_object, true );
775 FREENULL( text.psz_string );
779 #define TEXT_OR_VAR qfu ( text.psz_string ? text.psz_string : psz_var )
781 switch( i_type & VLC_VAR_TYPE )
784 var_Get( p_object, psz_var, &val );
785 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_NORMAL,
786 p_object->i_object_id, val, i_type );
790 var_Get( p_object, psz_var, &val );
791 val.b_bool = !val.b_bool;
792 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_CHECK,
793 p_object->i_object_id, val, i_type, !val.b_bool );
796 FREENULL( text.psz_string );
800 int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
801 vlc_object_t *p_object, bool b_root )
803 vlc_value_t val, val_list, text_list;
806 /* Check the type of the object variable */
807 i_type = var_Type( p_object, psz_var );
809 /* Make sure we want to display the variable */
810 if( IsMenuEmpty( psz_var, p_object, b_root ) ) return VLC_EGENERIC;
812 switch( i_type & VLC_VAR_TYPE )
816 case VLC_VAR_VARIABLE:
818 case VLC_VAR_INTEGER:
822 /* Variable doesn't exist or isn't handled */
826 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
827 &val_list, &text_list ) < 0 )
831 #define NORMAL_OR_RADIO i_type & VLC_VAR_ISCOMMAND ? ITEM_NORMAL: ITEM_RADIO
832 #define NOTCOMMAND !(i_type & VLC_VAR_ISCOMMAND)
833 #define CURVAL val_list.p_list->p_values[i]
834 #define CURTEXT text_list.p_list->p_values[i].psz_string
836 for( i = 0; i < val_list.p_list->i_count; i++ )
838 vlc_value_t another_val;
840 QMenu *subsubmenu = new QMenu();
842 switch( i_type & VLC_VAR_TYPE )
844 case VLC_VAR_VARIABLE:
845 CreateChoicesMenu( subsubmenu, CURVAL.psz_string, p_object, false );
846 subsubmenu->setTitle( qfu( CURTEXT ? CURTEXT :CURVAL.psz_string ) );
847 submenu->addMenu( subsubmenu );
851 var_Get( p_object, psz_var, &val );
852 another_val.psz_string = strdup( CURVAL.psz_string );
853 menutext = qfu( CURTEXT ? CURTEXT : another_val.psz_string );
854 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
855 p_object->i_object_id, another_val, i_type,
856 NOTCOMMAND && val.psz_string &&
857 !strcmp( val.psz_string, CURVAL.psz_string ) );
859 if( val.psz_string ) free( val.psz_string );
862 case VLC_VAR_INTEGER:
863 var_Get( p_object, psz_var, &val );
864 if( CURTEXT ) menutext = qfu( CURTEXT );
865 else menutext.sprintf( "%d", CURVAL.i_int);
866 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
867 p_object->i_object_id, CURVAL, i_type,
868 NOTCOMMAND && CURVAL.i_int == val.i_int );
872 var_Get( p_object, psz_var, &val );
873 if( CURTEXT ) menutext = qfu( CURTEXT );
874 else menutext.sprintf( "%.2f", CURVAL.f_float );
875 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
876 p_object->i_object_id, CURVAL, i_type,
877 NOTCOMMAND && CURVAL.f_float == val.f_float );
886 /* clean up everything */
887 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
889 #undef NORMAL_OR_RADIO
896 void QVLCMenu::CreateAndConnect( QMenu *menu, const char *psz_var,
897 QString text, QString help,
898 int i_item_type, int i_object_id,
899 vlc_value_t val, int i_val_type,
902 QAction *action = new QAction( text, menu );
903 action->setText( text );
904 action->setToolTip( help );
906 if( i_item_type == ITEM_CHECK )
908 action->setCheckable( true );
910 else if( i_item_type == ITEM_RADIO )
912 action->setCheckable( true );
914 currentGroup = new QActionGroup(menu);
915 currentGroup->addAction( action );
920 action->setChecked( true );
922 MenuItemData *itemData = new MenuItemData( i_object_id, i_val_type,
924 CONNECT( action, triggered(), THEDP->menusMapper, map() );
925 THEDP->menusMapper->setMapping( action, itemData );
926 menu->addAction( action );
929 void QVLCMenu::DoAction( intf_thread_t *p_intf, QObject *data )
931 MenuItemData *itemData = qobject_cast<MenuItemData *>(data);
932 vlc_object_t *p_object = (vlc_object_t *)vlc_object_get( p_intf,
933 itemData->i_object_id );
934 if( p_object == NULL ) return;
936 var_Set( p_object, itemData->psz_var, itemData->val );
937 vlc_object_release( p_object );}