1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2006-2007 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
27 #include <QActionGroup>
28 #include <QSignalMapper>
34 #include <vlc_intf_strings.h>
36 #include "main_interface.hpp"
38 #include "dialogs_provider.hpp"
39 #include "input_manager.hpp"
48 static QActionGroup *currentGroup;
50 // Add static entries to menus
51 #define DP_SADD( text, help, icon, slot, shortcut ) \
53 if( strlen(icon) > 0 ) \
55 if( strlen(shortcut) > 0 ) \
57 menu->addAction( QIcon(icon), text, THEDP, SLOT( slot ), \
62 menu->addAction( QIcon(icon), text, THEDP, SLOT( slot ) );\
67 if( strlen(shortcut) > 0 ) \
69 menu->addAction( text, THEDP, SLOT( slot ), \
74 menu->addAction( text, THEDP, SLOT( slot ) ); \
78 #define MIM_SADD( text, help, icon, slot ) \
80 if( strlen(icon) > 0 ) \
82 QAction *action = menu->addAction( text, THEMIM, SLOT( slot ) ); \
83 action->setIcon(QIcon(icon)); \
87 menu->addAction( text, THEMIM, SLOT( slot ) ); \
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 /*****************************************************************************
153 *****************************************************************************/
155 #define BAR_ADD( func, title ) { \
156 QMenu *menu = func; menu->setTitle( title ); bar->addMenu( menu ); }
158 #define BAR_DADD( func, title, id ) { \
159 QMenu *menu = func; menu->setTitle( title ); bar->addMenu( menu ); \
160 MenuFunc *f = new MenuFunc( menu, id ); \
161 CONNECT( menu, aboutToShow(), THEDP->menusUpdateMapper, map() ); \
162 THEDP->menusUpdateMapper->setMapping( menu, f ); }
164 void QVLCMenu::createMenuBar( MainInterface *mi, intf_thread_t *p_intf,
165 bool playlist, bool adv_controls_enabled,
166 bool visual_selector_enabled )
170 * Remove SIGCHLD from the ignored signal the time to initialise
171 * Qt because it call gconf to get the icon theme */
175 sigaddset( &set, SIGCHLD );
176 pthread_sigmask (SIG_UNBLOCK, &set, NULL);
178 QMenuBar *bar = mi->menuBar();
180 pthread_sigmask (SIG_BLOCK, &set, NULL);
182 BAR_ADD( FileMenu(), qtr("Media") );
185 BAR_ADD( PlaylistMenu( mi,p_intf ), qtr("Playlist" ) );
187 BAR_ADD( ToolsMenu( p_intf, mi, adv_controls_enabled,
188 visual_selector_enabled ), qtr("Tools") );
189 BAR_DADD( VideoMenu( p_intf, NULL ), qtr("Video"), 1 );
190 BAR_DADD( AudioMenu( p_intf, NULL ), qtr("Audio"), 2 );
191 BAR_DADD( NavigMenu( p_intf, NULL ), qtr("Navigation"), 3 );
193 BAR_ADD( HelpMenu(), qtr("Help" ) );
195 QMenu *QVLCMenu::FileMenu()
197 QMenu *menu = new QMenu();
198 DP_SADD( qtr("Open &File..." ), "", "", openFileDialog(), "Ctrl+O" );
199 DP_SADD( qtr("Open &Disc..." ), "", "", openDiscDialog(), "Ctrl+D" );
200 DP_SADD( qtr("Open &Network..." ), "", "", openNetDialog(), "Ctrl+N" );
201 DP_SADD( qtr("Open &Capture Device..." ), "", "", openCaptureDialog(),
203 menu->addSeparator();
204 DP_SADD( qtr("&Streaming..."), "", "", openThenStreamingDialogs(),
206 menu->addSeparator();
207 DP_SADD( qtr("&Quit") , "", "", quit(), "Ctrl+Q");
211 QMenu *QVLCMenu::PlaylistMenu( MainInterface *mi, intf_thread_t *p_intf )
213 QMenu *menu = new QMenu();
214 menu->addMenu( SDMenu( p_intf ) );
215 menu->addSeparator();
217 DP_SADD( qtr(I_PL_LOAD), "", "", openPlaylist(), "Ctrl+L" );
218 DP_SADD( qtr(I_PL_SAVE), "", "", savePlaylist(), "Ctrl+K" );
219 menu->addSeparator();
220 menu->addAction( qtr("Undock from interface"), mi,
221 SLOT( undockPlaylist() ), qtr("Ctrl+U") );
225 QMenu *QVLCMenu::ToolsMenu( intf_thread_t *p_intf, MainInterface *mi,
226 bool adv_controls_enabled,
227 bool visual_selector_enabled, bool with_intf )
229 QMenu *menu = new QMenu();
232 QMenu *intfmenu = InterfacesMenu( p_intf, NULL );
233 intfmenu->setTitle( qtr("Interfaces" ) );
234 menu->addMenu( intfmenu );
235 menu->addSeparator();
237 DP_SADD( qtr(I_MENU_MSG), "", "", messagesDialog(), "Ctrl+M" );
238 DP_SADD( qtr(I_MENU_INFO) , "", "", mediaInfoDialog(), "Ctrl+J" );
239 DP_SADD( qtr(I_MENU_CODECINFO) , "", "", mediaCodecDialog(), "Ctrl+I" );
240 menu->addSeparator();
243 QAction *adv = menu->addAction( qtr("Advanced controls" ),
244 mi, SLOT( advanced() ) );
245 adv->setCheckable( true );
246 if( adv_controls_enabled ) adv->setChecked( true );
248 adv = menu->addAction( qtr("Visualizations selector" ),
249 mi, SLOT( visual() ) );
250 adv->setCheckable( true );
251 if( visual_selector_enabled ) adv->setChecked( true );
254 DP_SADD( qtr(I_MENU_EXT), "","",extendedDialog(), "Ctrl+E" );
255 DP_SADD( qtr(I_MENU_GOTOTIME), "","",gotoTimeDialog(), "Ctrl+T" );
256 menu->addSeparator();
257 DP_SADD( qtr("Preferences"), "", "", prefsDialog(), "Ctrl+P" );
261 QMenu *QVLCMenu::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
264 vector<const char *> varnames;
265 /** \todo add "switch to XXX" */
266 varnames.push_back( "intf-add" );
267 objects.push_back( p_intf->i_object_id );
269 QMenu *menu = Populate( p_intf, current, varnames, objects );
271 if( !p_intf->pf_show_dialog )
273 menu->addSeparator();
274 menu->addAction( qtr("Switch to skins"), THEDP, SLOT(switchToSkins()),
278 CONNECT( menu, aboutToShow(), THEDP->menusUpdateMapper, map() );
279 THEDP->menusUpdateMapper->setMapping( menu, 4 );
283 QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QMenu * current )
286 vector<const char *> varnames;
288 vlc_object_t *p_object = (vlc_object_t *)vlc_object_find( p_intf,
289 VLC_OBJECT_INPUT, FIND_ANYWHERE );
290 if( p_object != NULL )
292 PUSH_VAR( "audio-es" );
293 vlc_object_release( p_object );
296 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_AOUT,
300 AudioAutoMenuBuilder( p_object, objects, varnames );
301 vlc_object_release( p_object );
303 return Populate( p_intf, current, varnames, objects );
307 QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current )
309 vlc_object_t *p_object;
311 vector<const char *> varnames;
313 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
315 if( p_object != NULL )
317 PUSH_VAR( "video-es" );
318 PUSH_VAR( "spu-es" );
319 vlc_object_release( p_object );
322 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT,
324 if( p_object != NULL )
326 VideoAutoMenuBuilder( p_object, objects, varnames );
327 vlc_object_release( p_object );
329 return Populate( p_intf, current, varnames, objects );
332 QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *current )
334 vlc_object_t *p_object;
336 vector<const char *> varnames;
339 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
341 if( p_object != NULL )
343 InputAutoMenuBuilder( p_object, objects, varnames );
344 PUSH_VAR( "prev-title"); PUSH_VAR ( "next-title" );
345 PUSH_VAR( "prev-chapter"); PUSH_VAR( "next-chapter" );
346 vlc_object_release( p_object );
348 return Populate( p_intf, current, varnames, objects );
351 QMenu *QVLCMenu::SDMenu( intf_thread_t *p_intf )
353 QMenu *menu = new QMenu();
354 menu->setTitle( qtr(I_PL_SD) );
355 vlc_list_t *p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE,
358 for( int i_index = 0 ; i_index < p_list->i_count; i_index++ )
360 module_t * p_parser = (module_t *)p_list->p_values[i_index].p_object ;
361 if( !strcmp( p_parser->psz_capability, "services_discovery" ) )
364 for( int i_index = 0 ; i_index < p_list->i_count; i_index++ )
366 module_t * p_parser = (module_t *)p_list->p_values[i_index].p_object;
367 if( !strcmp( p_parser->psz_capability, "services_discovery" ) )
369 QAction *a = new QAction( qfu( p_parser->psz_longname ), menu );
370 a->setCheckable( true );
371 /* hack to handle submodules properly */
373 while( p_parser->pp_shortcuts[++i] != NULL );
375 if( playlist_IsServicesDiscoveryLoaded( THEPL,
376 i>=0?p_parser->pp_shortcuts[i] : p_parser->psz_object_name ) )
378 a->setChecked( true );
380 CONNECT( a , triggered(), THEDP->SDMapper, map() );
381 THEDP->SDMapper->setMapping( a, i>=0? p_parser->pp_shortcuts[i] :
382 p_parser->psz_object_name );
383 menu->addAction( a );
386 vlc_list_release( p_list );
390 QMenu *QVLCMenu::HelpMenu()
392 QMenu *menu = new QMenu();
393 DP_SADD( qtr("Help") , "", "", helpDialog(), "F1" );
394 menu->addSeparator();
395 DP_SADD( qtr(I_MENU_ABOUT), "", "", aboutDialog(), "Ctrl+Shift+F1");
400 /*****************************************************************************
402 *****************************************************************************/
403 #define POPUP_BOILERPLATE \
404 unsigned int i_last_separator = 0; \
405 vector<int> objects; \
406 vector<const char *> varnames; \
407 input_thread_t *p_input = THEMIM->getInput();
409 #define CREATE_POPUP \
410 QMenu *menu = new QMenu(); \
411 Populate( p_intf, menu, varnames, objects ); \
412 p_intf->p_sys->p_popup_menu = menu; \
413 menu->popup( QCursor::pos() ); \
414 p_intf->p_sys->p_popup_menu = NULL; \
415 i_last_separator = 0;
417 #define POPUP_STATIC_ENTRIES \
421 var_Get( p_input, "state", &val ); \
422 if( val.i_int == PAUSE_S ) \
423 MIM_SADD( qtr("Play"), "", "", togglePlayPause() ) \
425 MIM_SADD( qtr("Pause"), "", "", togglePlayPause() ) \
427 else if( THEPL->items.i_size && THEPL->i_enabled ) \
428 MIM_SADD( qtr("Play"), "", "", togglePlayPause() );\
430 MIM_SADD( qtr("Stop"), "", "", stop() ); \
431 MIM_SADD( qtr("Previous"), "", "", prev() ); \
432 MIM_SADD( qtr("Next"), "", "", next() ); \
433 menu->addSeparator(); \
434 QMenu *intfmenu = InterfacesMenu( p_intf, NULL ); \
435 intfmenu->setTitle( qtr("Interfaces" ) ); \
436 menu->addMenu( intfmenu ); \
438 QMenu *toolsmenu = ToolsMenu( p_intf, NULL, false, false ); \
439 toolsmenu->setTitle( qtr("Tools" ) ); \
440 menu->addMenu( toolsmenu ); \
441 DP_SADD( qtr("Quit"), "", "", quit() , "Ctrl+Q" );
443 void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf )
448 vlc_object_yield( p_input );
449 varnames.push_back( "video-es" );
450 objects.push_back( p_input->i_object_id );
451 varnames.push_back( "spu-es" );
452 objects.push_back( p_input->i_object_id );
453 vlc_object_t *p_vout = (vlc_object_t *)vlc_object_find( p_input,
454 VLC_OBJECT_VOUT, FIND_CHILD );
457 VideoAutoMenuBuilder( p_vout, objects, varnames );
458 vlc_object_release( p_vout );
460 vlc_object_release( p_input );
465 void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf )
470 vlc_object_yield( p_input );
471 varnames.push_back( "audio-es" );
472 objects.push_back( p_input->i_object_id );
473 vlc_object_t *p_aout = (vlc_object_t *)vlc_object_find( p_input,
474 VLC_OBJECT_AOUT, FIND_ANYWHERE );
477 AudioAutoMenuBuilder( p_aout, objects, varnames );
478 vlc_object_release( p_aout );
480 vlc_object_release( p_input );
485 /* Navigation stuff, and general */
486 void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf )
491 vlc_object_yield( p_input );
492 varnames.push_back( "audio-es" );
493 InputAutoMenuBuilder( VLC_OBJECT(p_input), objects, varnames );
497 QMenu *menu = new QMenu();
498 Populate( p_intf, menu, varnames, objects );
499 menu->addSeparator();
500 POPUP_STATIC_ENTRIES;
502 p_intf->p_sys->p_popup_menu = menu;
503 menu->popup( QCursor::pos() );
504 p_intf->p_sys->p_popup_menu = NULL;
507 void QVLCMenu::PopupMenu( intf_thread_t *p_intf )
512 vlc_object_yield( p_input );
513 InputAutoMenuBuilder( VLC_OBJECT(p_input), objects, varnames );
517 varnames.push_back( "video-es" );
518 objects.push_back( p_input->i_object_id );
519 varnames.push_back( "spu-es" );
520 objects.push_back( p_input->i_object_id );
521 vlc_object_t *p_vout = (vlc_object_t *)vlc_object_find( p_input,
522 VLC_OBJECT_VOUT, FIND_CHILD );
525 VideoAutoMenuBuilder( p_vout, objects, varnames );
526 vlc_object_release( p_vout );
530 varnames.push_back( "audio-es" );
531 objects.push_back( p_input->i_object_id );
532 vlc_object_t *p_aout = (vlc_object_t *)vlc_object_find( p_input,
533 VLC_OBJECT_AOUT, FIND_ANYWHERE );
536 AudioAutoMenuBuilder( p_aout, objects, varnames );
537 vlc_object_release( p_aout );
541 QMenu *menu = new QMenu();
542 Populate( p_intf, menu, varnames, objects );
543 menu->addSeparator();
544 POPUP_STATIC_ENTRIES;
546 p_intf->p_sys->p_popup_menu = menu;
547 menu->popup( QCursor::pos() );
548 p_intf->p_sys->p_popup_menu = NULL;
552 #undef PUSH_SEPARATOR
554 /*************************************************************************
555 * Builders for automenus
556 *************************************************************************/
557 QMenu * QVLCMenu::Populate( intf_thread_t *p_intf, QMenu *current,
558 vector< const char *> & varnames,
559 vector<int> & objects, bool append )
561 QMenu *menu = current;
569 vlc_object_t *p_object;
570 vlc_bool_t b_section_empty = VLC_FALSE;
573 #define APPEND_EMPTY { QAction *action = menu->addAction( qtr("Empty" ) ); \
574 action->setEnabled( false ); }
576 for( i = 0; i < (int)objects.size() ; i++ )
578 if( !varnames[i] || !*varnames[i] )
580 if( b_section_empty )
582 menu->addSeparator();
583 b_section_empty = VLC_TRUE;
587 if( objects[i] == 0 )
589 /// \bug What is this ?
590 // Append( menu, varnames[i], NULL );
591 b_section_empty = VLC_FALSE;
595 p_object = (vlc_object_t *)vlc_object_get( p_intf,
597 if( p_object == NULL ) continue;
599 b_section_empty = VLC_FALSE;
600 /* Ugly specific stuff */
601 if( strstr(varnames[i], "intf-add" ) )
602 CreateItem( menu, varnames[i], p_object, false );
604 CreateItem( menu, varnames[i], p_object, true );
605 vlc_object_release( p_object );
608 /* Special case for empty menus */
609 if( menu->actions().size() == 0 || b_section_empty )
615 /*****************************************************************************
617 *****************************************************************************/
619 static bool IsMenuEmpty( const char *psz_var, vlc_object_t *p_object,
622 vlc_value_t val, val_list;
623 int i_type, i_result, i;
625 /* Check the type of the object variable */
626 i_type = var_Type( p_object, psz_var );
628 /* Check if we want to display the variable */
629 if( !(i_type & VLC_VAR_HASCHOICE) ) return FALSE;
631 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
632 if( val.i_int == 0 ) return TRUE;
634 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE )
636 /* Very evil hack ! intf-switch can have only one value */
637 if( !strcmp( psz_var, "intf-switch" ) ) return FALSE;
638 if( val.i_int == 1 && b_root ) return TRUE;
642 /* Check children variables in case of VLC_VAR_VARIABLE */
643 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
648 for( i = 0, i_result = TRUE; i < val_list.p_list->i_count; i++ )
650 if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
658 /* clean up everything */
659 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, NULL );
664 void QVLCMenu::CreateItem( QMenu *menu, const char *psz_var,
665 vlc_object_t *p_object, bool b_submenu )
667 vlc_value_t val, text;
670 /* Check the type of the object variable */
671 i_type = var_Type( p_object, psz_var );
673 switch( i_type & VLC_VAR_TYPE )
677 case VLC_VAR_VARIABLE:
679 case VLC_VAR_INTEGER:
683 /* Variable doesn't exist or isn't handled */
687 /* Make sure we want to display the variable */
688 if( IsMenuEmpty( psz_var, p_object ) ) return;
690 /* Get the descriptive name of the variable */
691 var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
693 if( i_type & VLC_VAR_HASCHOICE )
695 /* Append choices menu */
698 QMenu *submenu = new QMenu();
699 submenu->setTitle( qfu( text.psz_string ?
700 text.psz_string : psz_var ) );
701 if( CreateChoicesMenu( submenu, psz_var, p_object, true ) == 0)
702 menu->addMenu( submenu );
705 CreateChoicesMenu( menu, psz_var, p_object, true );
706 FREENULL( text.psz_string );
710 #define TEXT_OR_VAR qfu ( text.psz_string ? text.psz_string : psz_var )
712 switch( i_type & VLC_VAR_TYPE )
715 var_Get( p_object, psz_var, &val );
716 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_NORMAL,
717 p_object->i_object_id, val, i_type );
721 var_Get( p_object, psz_var, &val );
722 val.b_bool = !val.b_bool;
723 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_CHECK,
724 p_object->i_object_id, val, i_type, !val.b_bool );
727 FREENULL( text.psz_string );
731 int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
732 vlc_object_t *p_object, bool b_root )
734 vlc_value_t val, val_list, text_list;
737 /* Check the type of the object variable */
738 i_type = var_Type( p_object, psz_var );
740 /* Make sure we want to display the variable */
741 if( IsMenuEmpty( psz_var, p_object, b_root ) ) return VLC_EGENERIC;
743 switch( i_type & VLC_VAR_TYPE )
747 case VLC_VAR_VARIABLE:
749 case VLC_VAR_INTEGER:
753 /* Variable doesn't exist or isn't handled */
757 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
758 &val_list, &text_list ) < 0 )
762 #define NORMAL_OR_RADIO i_type & VLC_VAR_ISCOMMAND ? ITEM_NORMAL: ITEM_RADIO
763 #define NOTCOMMAND !(i_type & VLC_VAR_ISCOMMAND)
764 #define CURVAL val_list.p_list->p_values[i]
765 #define CURTEXT text_list.p_list->p_values[i].psz_string
767 for( i = 0; i < val_list.p_list->i_count; i++ )
769 vlc_value_t another_val;
771 QMenu *subsubmenu = new QMenu();
773 switch( i_type & VLC_VAR_TYPE )
775 case VLC_VAR_VARIABLE:
776 CreateChoicesMenu( subsubmenu, CURVAL.psz_string, p_object, false );
777 subsubmenu->setTitle( qfu( CURTEXT ? CURTEXT :CURVAL.psz_string ) );
778 submenu->addMenu( subsubmenu );
782 var_Get( p_object, psz_var, &val );
783 another_val.psz_string = strdup( CURVAL.psz_string );
784 menutext = qfu( CURTEXT ? CURTEXT : another_val.psz_string );
785 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
786 p_object->i_object_id, another_val, i_type,
787 NOTCOMMAND && val.psz_string &&
788 !strcmp( val.psz_string, CURVAL.psz_string ) );
790 if( val.psz_string ) free( val.psz_string );
793 case VLC_VAR_INTEGER:
794 var_Get( p_object, psz_var, &val );
795 if( CURTEXT ) menutext = qfu( CURTEXT );
796 else menutext.sprintf( "%d", CURVAL.i_int);
797 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
798 p_object->i_object_id, CURVAL, i_type,
799 NOTCOMMAND && CURVAL.i_int == val.i_int );
803 var_Get( p_object, psz_var, &val );
804 if( CURTEXT ) menutext = qfu( CURTEXT );
805 else menutext.sprintf( "%.2f", CURVAL.f_float );
806 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
807 p_object->i_object_id, CURVAL, i_type,
808 NOTCOMMAND && CURVAL.f_float == val.f_float );
817 /* clean up everything */
818 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
820 #undef NORMAL_OR_RADIO
827 void QVLCMenu::CreateAndConnect( QMenu *menu, const char *psz_var,
828 QString text, QString help,
829 int i_item_type, int i_object_id,
830 vlc_value_t val, int i_val_type,
833 QAction *action = new QAction( text, menu );
834 action->setText( text );
835 action->setToolTip( help );
837 if( i_item_type == ITEM_CHECK )
839 action->setCheckable( true );
841 else if( i_item_type == ITEM_RADIO )
843 action->setCheckable( true );
845 currentGroup = new QActionGroup(menu);
846 currentGroup->addAction( action );
851 action->setChecked( true );
853 MenuItemData *itemData = new MenuItemData( i_object_id, i_val_type,
855 CONNECT( action, triggered(), THEDP->menusMapper, map() );
856 THEDP->menusMapper->setMapping( action, itemData );
857 menu->addAction( action );
860 void QVLCMenu::DoAction( intf_thread_t *p_intf, QObject *data )
862 MenuItemData *itemData = qobject_cast<MenuItemData *>(data);
863 vlc_object_t *p_object = (vlc_object_t *)vlc_object_get( p_intf,
864 itemData->i_object_id );
865 if( p_object == NULL ) return;
867 var_Set( p_object, itemData->psz_var, itemData->val );
868 vlc_object_release( p_object );