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(), "Ctrl+S" );
205 menu->addSeparator();
206 DP_SADD( qtr("&Quit") , "", "", quit(), "Ctrl+Q");
210 QMenu *QVLCMenu::PlaylistMenu( MainInterface *mi, intf_thread_t *p_intf )
212 QMenu *menu = new QMenu();
213 menu->addMenu( SDMenu( p_intf ) );
214 menu->addSeparator();
216 DP_SADD( qtr(I_PL_LOAD), "", "", openPlaylist(), "Ctrl+L" );
217 DP_SADD( qtr(I_PL_SAVE), "", "", savePlaylist(), "Ctrl+K" );
218 menu->addSeparator();
219 menu->addAction( qtr("Undock from interface"), mi,
220 SLOT( undockPlaylist() ), qtr("Ctrl+U") );
224 QMenu *QVLCMenu::ToolsMenu( intf_thread_t *p_intf, MainInterface *mi,
225 bool adv_controls_enabled,
226 bool visual_selector_enabled, bool with_intf )
228 QMenu *menu = new QMenu();
231 QMenu *intfmenu = InterfacesMenu( p_intf, NULL );
232 intfmenu->setTitle( qtr("Interfaces" ) );
233 menu->addMenu( intfmenu );
234 menu->addSeparator();
236 DP_SADD( qtr(I_MENU_MSG), "", "", messagesDialog(), "Ctrl+M" );
237 DP_SADD( qtr(I_MENU_INFO) , "", "", mediaInfoDialog(), "Ctrl+J" );
238 DP_SADD( qtr(I_MENU_CODECINFO) , "", "", mediaCodecDialog(), "Ctrl+I" );
239 menu->addSeparator();
242 QAction *adv = menu->addAction( qtr("Advanced controls" ),
243 mi, SLOT( advanced() ) );
244 adv->setCheckable( true );
245 if( adv_controls_enabled ) adv->setChecked( true );
247 adv = menu->addAction( qtr("Visualizations selector" ),
248 mi, SLOT( visual() ) );
249 adv->setCheckable( true );
250 if( visual_selector_enabled ) adv->setChecked( true );
253 DP_SADD( qtr(I_MENU_EXT), "","",extendedDialog(), "Ctrl+E" );
254 DP_SADD( qtr(I_MENU_GOTOTIME), "","",gotoTimeDialog(), "Ctrl+T" );
255 menu->addSeparator();
256 DP_SADD( qtr("Preferences"), "", "", prefsDialog(), "Ctrl+P" );
260 QMenu *QVLCMenu::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
263 vector<const char *> varnames;
264 /** \todo add "switch to XXX" */
265 varnames.push_back( "intf-add" );
266 objects.push_back( p_intf->i_object_id );
268 QMenu *menu = Populate( p_intf, current, varnames, objects );
270 if( !p_intf->pf_show_dialog )
272 menu->addSeparator();
273 menu->addAction( qtr("Switch to skins"), THEDP, SLOT(switchToSkins()),
277 CONNECT( menu, aboutToShow(), THEDP->menusUpdateMapper, map() );
278 THEDP->menusUpdateMapper->setMapping( menu, 4 );
282 QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QMenu * current )
285 vector<const char *> varnames;
287 vlc_object_t *p_object = (vlc_object_t *)vlc_object_find( p_intf,
288 VLC_OBJECT_INPUT, FIND_ANYWHERE );
289 if( p_object != NULL )
291 PUSH_VAR( "audio-es" );
292 vlc_object_release( p_object );
295 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_AOUT,
299 AudioAutoMenuBuilder( p_object, objects, varnames );
300 vlc_object_release( p_object );
302 return Populate( p_intf, current, varnames, objects );
306 QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current )
308 vlc_object_t *p_object;
310 vector<const char *> varnames;
312 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
314 if( p_object != NULL )
316 PUSH_VAR( "video-es" );
317 PUSH_VAR( "spu-es" );
318 vlc_object_release( p_object );
321 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT,
323 if( p_object != NULL )
325 VideoAutoMenuBuilder( p_object, objects, varnames );
326 vlc_object_release( p_object );
328 return Populate( p_intf, current, varnames, objects );
331 QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *current )
333 vlc_object_t *p_object;
335 vector<const char *> varnames;
338 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
340 if( p_object != NULL )
342 InputAutoMenuBuilder( p_object, objects, varnames );
343 PUSH_VAR( "prev-title"); PUSH_VAR ( "next-title" );
344 PUSH_VAR( "prev-chapter"); PUSH_VAR( "next-chapter" );
345 vlc_object_release( p_object );
347 return Populate( p_intf, current, varnames, objects );
350 QMenu *QVLCMenu::SDMenu( intf_thread_t *p_intf )
352 QMenu *menu = new QMenu();
353 menu->setTitle( qtr(I_PL_SD) );
354 vlc_list_t *p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE,
357 for( int i_index = 0 ; i_index < p_list->i_count; i_index++ )
359 module_t * p_parser = (module_t *)p_list->p_values[i_index].p_object ;
360 if( !strcmp( p_parser->psz_capability, "services_discovery" ) )
363 for( int i_index = 0 ; i_index < p_list->i_count; i_index++ )
365 module_t * p_parser = (module_t *)p_list->p_values[i_index].p_object;
366 if( !strcmp( p_parser->psz_capability, "services_discovery" ) )
368 QAction *a = new QAction( qfu( p_parser->psz_longname ), menu );
369 a->setCheckable( true );
370 /* hack to handle submodules properly */
372 while( p_parser->pp_shortcuts[++i] != NULL );
374 if( playlist_IsServicesDiscoveryLoaded( THEPL,
375 i>=0?p_parser->pp_shortcuts[i] : p_parser->psz_object_name ) )
377 a->setChecked( true );
379 CONNECT( a , triggered(), THEDP->SDMapper, map() );
380 THEDP->SDMapper->setMapping( a, i>=0? p_parser->pp_shortcuts[i] :
381 p_parser->psz_object_name );
382 menu->addAction( a );
385 vlc_list_release( p_list );
389 QMenu *QVLCMenu::HelpMenu()
391 QMenu *menu = new QMenu();
392 DP_SADD( qtr("Help") , "", "", helpDialog(), "F1" );
393 menu->addSeparator();
394 DP_SADD( qtr(I_MENU_ABOUT), "", "", aboutDialog(), "Ctrl+Shift+F1");
399 /*****************************************************************************
401 *****************************************************************************/
402 #define POPUP_BOILERPLATE \
403 unsigned int i_last_separator = 0; \
404 vector<int> objects; \
405 vector<const char *> varnames; \
406 input_thread_t *p_input = THEMIM->getInput();
408 #define CREATE_POPUP \
409 QMenu *menu = new QMenu(); \
410 Populate( p_intf, menu, varnames, objects ); \
411 p_intf->p_sys->p_popup_menu = menu; \
412 menu->popup( QCursor::pos() ); \
413 p_intf->p_sys->p_popup_menu = NULL; \
414 i_last_separator = 0;
416 #define POPUP_STATIC_ENTRIES \
420 var_Get( p_input, "state", &val ); \
421 if( val.i_int == PAUSE_S ) \
422 MIM_SADD( qtr("Play"), "", "", togglePlayPause() ) \
424 MIM_SADD( qtr("Pause"), "", "", togglePlayPause() ) \
426 else if( THEPL->items.i_size && THEPL->i_enabled ) \
427 MIM_SADD( qtr("Play"), "", "", togglePlayPause() );\
429 MIM_SADD( qtr("Stop"), "", "", stop() ); \
430 MIM_SADD( qtr("Previous"), "", "", prev() ); \
431 MIM_SADD( qtr("Next"), "", "", next() ); \
432 menu->addSeparator(); \
433 QMenu *intfmenu = InterfacesMenu( p_intf, NULL ); \
434 intfmenu->setTitle( qtr("Interfaces" ) ); \
435 menu->addMenu( intfmenu ); \
437 QMenu *toolsmenu = ToolsMenu( p_intf, NULL, false, false ); \
438 toolsmenu->setTitle( qtr("Tools" ) ); \
439 menu->addMenu( toolsmenu ); \
440 DP_SADD( qtr("Quit"), "", "", quit() , NULL );
442 void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf )
447 vlc_object_yield( p_input );
448 varnames.push_back( "video-es" );
449 objects.push_back( p_input->i_object_id );
450 varnames.push_back( "spu-es" );
451 objects.push_back( p_input->i_object_id );
452 vlc_object_t *p_vout = (vlc_object_t *)vlc_object_find( p_input,
453 VLC_OBJECT_VOUT, FIND_CHILD );
456 VideoAutoMenuBuilder( p_vout, objects, varnames );
457 vlc_object_release( p_vout );
459 vlc_object_release( p_input );
464 void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf )
469 vlc_object_yield( p_input );
470 varnames.push_back( "audio-es" );
471 objects.push_back( p_input->i_object_id );
472 vlc_object_t *p_aout = (vlc_object_t *)vlc_object_find( p_input,
473 VLC_OBJECT_AOUT, FIND_ANYWHERE );
476 AudioAutoMenuBuilder( p_aout, objects, varnames );
477 vlc_object_release( p_aout );
479 vlc_object_release( p_input );
484 /* Navigation stuff, and general */
485 void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf )
490 vlc_object_yield( p_input );
491 varnames.push_back( "audio-es" );
492 InputAutoMenuBuilder( VLC_OBJECT(p_input), objects, varnames );
496 QMenu *menu = new QMenu();
497 Populate( p_intf, menu, varnames, objects );
498 menu->addSeparator();
499 POPUP_STATIC_ENTRIES;
501 p_intf->p_sys->p_popup_menu = menu;
502 menu->popup( QCursor::pos() );
503 p_intf->p_sys->p_popup_menu = NULL;
506 void QVLCMenu::PopupMenu( intf_thread_t *p_intf )
511 vlc_object_yield( p_input );
512 InputAutoMenuBuilder( VLC_OBJECT(p_input), objects, varnames );
516 varnames.push_back( "video-es" );
517 objects.push_back( p_input->i_object_id );
518 varnames.push_back( "spu-es" );
519 objects.push_back( p_input->i_object_id );
520 vlc_object_t *p_vout = (vlc_object_t *)vlc_object_find( p_input,
521 VLC_OBJECT_VOUT, FIND_CHILD );
524 VideoAutoMenuBuilder( p_vout, objects, varnames );
525 vlc_object_release( p_vout );
529 varnames.push_back( "audio-es" );
530 objects.push_back( p_input->i_object_id );
531 vlc_object_t *p_aout = (vlc_object_t *)vlc_object_find( p_input,
532 VLC_OBJECT_AOUT, FIND_ANYWHERE );
535 AudioAutoMenuBuilder( p_aout, objects, varnames );
536 vlc_object_release( p_aout );
540 QMenu *menu = new QMenu();
541 Populate( p_intf, menu, varnames, objects );
542 menu->addSeparator();
543 POPUP_STATIC_ENTRIES;
545 p_intf->p_sys->p_popup_menu = menu;
546 menu->popup( QCursor::pos() );
547 p_intf->p_sys->p_popup_menu = NULL;
551 #undef PUSH_SEPARATOR
553 /*************************************************************************
554 * Builders for automenus
555 *************************************************************************/
556 QMenu * QVLCMenu::Populate( intf_thread_t *p_intf, QMenu *current,
557 vector< const char *> & varnames,
558 vector<int> & objects, bool append )
560 QMenu *menu = current;
568 vlc_object_t *p_object;
569 vlc_bool_t b_section_empty = VLC_FALSE;
572 #define APPEND_EMPTY { QAction *action = menu->addAction( qtr("Empty" ) ); \
573 action->setEnabled( false ); }
575 for( i = 0; i < (int)objects.size() ; i++ )
577 if( !varnames[i] || !*varnames[i] )
579 if( b_section_empty )
581 menu->addSeparator();
582 b_section_empty = VLC_TRUE;
586 if( objects[i] == 0 )
588 /// \bug What is this ?
589 // Append( menu, varnames[i], NULL );
590 b_section_empty = VLC_FALSE;
594 p_object = (vlc_object_t *)vlc_object_get( p_intf,
596 if( p_object == NULL ) continue;
598 b_section_empty = VLC_FALSE;
599 /* Ugly specific stuff */
600 if( strstr(varnames[i], "intf-add" ) )
601 CreateItem( menu, varnames[i], p_object, false );
603 CreateItem( menu, varnames[i], p_object, true );
604 vlc_object_release( p_object );
607 /* Special case for empty menus */
608 if( menu->actions().size() == 0 || b_section_empty )
614 /*****************************************************************************
616 *****************************************************************************/
618 static bool IsMenuEmpty( const char *psz_var, vlc_object_t *p_object,
621 vlc_value_t val, val_list;
622 int i_type, i_result, i;
624 /* Check the type of the object variable */
625 i_type = var_Type( p_object, psz_var );
627 /* Check if we want to display the variable */
628 if( !(i_type & VLC_VAR_HASCHOICE) ) return FALSE;
630 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
631 if( val.i_int == 0 ) return TRUE;
633 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE )
635 /* Very evil hack ! intf-switch can have only one value */
636 if( !strcmp( psz_var, "intf-switch" ) ) return FALSE;
637 if( val.i_int == 1 && b_root ) return TRUE;
641 /* Check children variables in case of VLC_VAR_VARIABLE */
642 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
647 for( i = 0, i_result = TRUE; i < val_list.p_list->i_count; i++ )
649 if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
657 /* clean up everything */
658 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, NULL );
663 void QVLCMenu::CreateItem( QMenu *menu, const char *psz_var,
664 vlc_object_t *p_object, bool b_submenu )
666 vlc_value_t val, text;
669 /* Check the type of the object variable */
670 i_type = var_Type( p_object, psz_var );
672 switch( i_type & VLC_VAR_TYPE )
676 case VLC_VAR_VARIABLE:
678 case VLC_VAR_INTEGER:
682 /* Variable doesn't exist or isn't handled */
686 /* Make sure we want to display the variable */
687 if( IsMenuEmpty( psz_var, p_object ) ) return;
689 /* Get the descriptive name of the variable */
690 var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
692 if( i_type & VLC_VAR_HASCHOICE )
694 /* Append choices menu */
697 QMenu *submenu = new QMenu();
698 submenu->setTitle( qfu( text.psz_string ?
699 text.psz_string : psz_var ) );
700 if( CreateChoicesMenu( submenu, psz_var, p_object, true ) == 0)
701 menu->addMenu( submenu );
704 CreateChoicesMenu( menu, psz_var, p_object, true );
705 FREENULL( text.psz_string );
709 #define TEXT_OR_VAR qfu ( text.psz_string ? text.psz_string : psz_var )
711 switch( i_type & VLC_VAR_TYPE )
714 var_Get( p_object, psz_var, &val );
715 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_NORMAL,
716 p_object->i_object_id, val, i_type );
720 var_Get( p_object, psz_var, &val );
721 val.b_bool = !val.b_bool;
722 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_CHECK,
723 p_object->i_object_id, val, i_type, !val.b_bool );
726 FREENULL( text.psz_string );
730 int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
731 vlc_object_t *p_object, bool b_root )
733 vlc_value_t val, val_list, text_list;
736 /* Check the type of the object variable */
737 i_type = var_Type( p_object, psz_var );
739 /* Make sure we want to display the variable */
740 if( IsMenuEmpty( psz_var, p_object, b_root ) ) return VLC_EGENERIC;
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 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
757 &val_list, &text_list ) < 0 )
761 #define NORMAL_OR_RADIO i_type & VLC_VAR_ISCOMMAND ? ITEM_NORMAL: ITEM_RADIO
762 #define NOTCOMMAND !(i_type & VLC_VAR_ISCOMMAND)
763 #define CURVAL val_list.p_list->p_values[i]
764 #define CURTEXT text_list.p_list->p_values[i].psz_string
766 for( i = 0; i < val_list.p_list->i_count; i++ )
768 vlc_value_t another_val;
770 QMenu *subsubmenu = new QMenu();
772 switch( i_type & VLC_VAR_TYPE )
774 case VLC_VAR_VARIABLE:
775 CreateChoicesMenu( subsubmenu, CURVAL.psz_string, p_object, false );
776 subsubmenu->setTitle( qfu( CURTEXT ? CURTEXT :CURVAL.psz_string ) );
777 submenu->addMenu( subsubmenu );
781 var_Get( p_object, psz_var, &val );
782 another_val.psz_string = strdup( CURVAL.psz_string );
783 menutext = qfu( CURTEXT ? CURTEXT : another_val.psz_string );
784 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
785 p_object->i_object_id, another_val, i_type,
786 NOTCOMMAND && val.psz_string &&
787 !strcmp( val.psz_string, CURVAL.psz_string ) );
789 if( val.psz_string ) free( val.psz_string );
792 case VLC_VAR_INTEGER:
793 var_Get( p_object, psz_var, &val );
794 if( CURTEXT ) menutext = qfu( CURTEXT );
795 else menutext.sprintf( "%d", CURVAL.i_int);
796 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
797 p_object->i_object_id, CURVAL, i_type,
798 NOTCOMMAND && CURVAL.i_int == val.i_int );
802 var_Get( p_object, psz_var, &val );
803 if( CURTEXT ) menutext = qfu( CURTEXT );
804 else menutext.sprintf( "%.2f", CURVAL.f_float );
805 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
806 p_object->i_object_id, CURVAL, i_type,
807 NOTCOMMAND && CURVAL.f_float == val.f_float );
816 /* clean up everything */
817 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
819 #undef NORMAL_OR_RADIO
826 void QVLCMenu::CreateAndConnect( QMenu *menu, const char *psz_var,
827 QString text, QString help,
828 int i_item_type, int i_object_id,
829 vlc_value_t val, int i_val_type,
832 QAction *action = new QAction( text, menu );
833 action->setText( text );
834 action->setToolTip( help );
836 if( i_item_type == ITEM_CHECK )
838 action->setCheckable( true );
840 else if( i_item_type == ITEM_RADIO )
842 action->setCheckable( true );
844 currentGroup = new QActionGroup(menu);
845 currentGroup->addAction( action );
850 action->setChecked( true );
852 MenuItemData *itemData = new MenuItemData( i_object_id, i_val_type,
854 CONNECT( action, triggered(), THEDP->menusMapper, map() );
855 THEDP->menusMapper->setMapping( action, itemData );
856 menu->addAction( action );
859 void QVLCMenu::DoAction( intf_thread_t *p_intf, QObject *data )
861 MenuItemData *itemData = qobject_cast<MenuItemData *>(data);
862 vlc_object_t *p_object = (vlc_object_t *)vlc_object_get( p_intf,
863 itemData->i_object_id );
864 if( p_object == NULL ) return;
866 var_Set( p_object, itemData->psz_var, itemData->val );
867 vlc_object_release( p_object );