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("Quick &Open File...") , "", "", simpleOpenDialog() );*/
199 DP_SADD( qtr("Open &File..." ), "", "", openFileDialog(), "Ctrl+O" );
200 DP_SADD( qtr("Open &Disc..." ), "", "", openDiscDialog(), "Ctrl+D" );
201 DP_SADD( qtr("Open &Network..." ), "", "", openNetDialog(), "Ctrl+N" );
202 DP_SADD( qtr("Open &Capture Device..." ), "", "", openCaptureDialog(),
204 menu->addSeparator();
205 DP_SADD( qtr("&Streaming..."), "", "", streamingDialog(), "Ctrl+S" );
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 DP_SADD( qtr(I_MENU_EXT), "","",extendedDialog(), "Ctrl+G" );
243 menu->addSeparator();
244 QAction *adv = menu->addAction( qtr("Advanced controls" ),
245 mi, SLOT( advanced() ) );
246 adv->setCheckable( true );
247 if( adv_controls_enabled ) adv->setChecked( true );
249 adv = menu->addAction( qtr("Visualizations selector" ),
250 mi, SLOT( visual() ) );
251 adv->setCheckable( true );
252 if( visual_selector_enabled ) adv->setChecked( true );
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()) );
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 \
418 MIM_SADD( qtr("Stop"), "", "", stop() ); \
419 MIM_SADD( qtr("Previous"), "", "", prev() ); \
420 MIM_SADD( qtr("Next"), "", "", next() ); \
423 var_Get( p_input, "state", &val ); \
424 if( val.i_int == PAUSE_S ) \
425 MIM_SADD( qtr("Play"), "", "", togglePlayPause() ) \
427 MIM_SADD( qtr("Pause"), "", "", togglePlayPause() ) \
429 else if( THEPL->items.i_size && THEPL->i_enabled ) \
430 MIM_SADD( qtr("Play"), "", "", togglePlayPause() ) \
432 QMenu *intfmenu = InterfacesMenu( p_intf, NULL ); \
433 intfmenu->setTitle( qtr("Interfaces" ) ); \
434 menu->addMenu( intfmenu ); \
436 QMenu *toolsmenu = ToolsMenu( p_intf, NULL, false, false ); \
437 toolsmenu->setTitle( qtr("Tools" ) ); \
438 menu->addMenu( toolsmenu ); \
440 void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf )
445 vlc_object_yield( p_input );
446 varnames.push_back( "video-es" );
447 objects.push_back( p_input->i_object_id );
448 varnames.push_back( "spu-es" );
449 objects.push_back( p_input->i_object_id );
450 vlc_object_t *p_vout = (vlc_object_t *)vlc_object_find( p_input,
451 VLC_OBJECT_VOUT, FIND_CHILD );
454 VideoAutoMenuBuilder( p_vout, objects, varnames );
455 vlc_object_release( p_vout );
457 vlc_object_release( p_input );
462 void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf )
467 vlc_object_yield( p_input );
468 varnames.push_back( "audio-es" );
469 objects.push_back( p_input->i_object_id );
470 vlc_object_t *p_aout = (vlc_object_t *)vlc_object_find( p_input,
471 VLC_OBJECT_AOUT, FIND_ANYWHERE );
474 AudioAutoMenuBuilder( p_aout, objects, varnames );
475 vlc_object_release( p_aout );
477 vlc_object_release( p_input );
482 /* Navigation stuff, and general */
483 void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf )
488 vlc_object_yield( p_input );
489 varnames.push_back( "audio-es" );
490 InputAutoMenuBuilder( VLC_OBJECT(p_input), objects, varnames );
494 QMenu *menu = new QMenu();
495 Populate( p_intf, menu, varnames, objects );
496 menu->addSeparator();
497 POPUP_STATIC_ENTRIES;
499 p_intf->p_sys->p_popup_menu = menu;
500 menu->popup( QCursor::pos() );
501 p_intf->p_sys->p_popup_menu = NULL;
504 void QVLCMenu::PopupMenu( intf_thread_t *p_intf )
509 vlc_object_yield( p_input );
510 InputAutoMenuBuilder( VLC_OBJECT(p_input), objects, varnames );
514 varnames.push_back( "video-es" );
515 objects.push_back( p_input->i_object_id );
516 varnames.push_back( "spu-es" );
517 objects.push_back( p_input->i_object_id );
518 vlc_object_t *p_vout = (vlc_object_t *)vlc_object_find( p_input,
519 VLC_OBJECT_VOUT, FIND_CHILD );
522 VideoAutoMenuBuilder( p_vout, objects, varnames );
523 vlc_object_release( p_vout );
527 varnames.push_back( "audio-es" );
528 objects.push_back( p_input->i_object_id );
529 vlc_object_t *p_aout = (vlc_object_t *)vlc_object_find( p_input,
530 VLC_OBJECT_AOUT, FIND_ANYWHERE );
533 AudioAutoMenuBuilder( p_aout, objects, varnames );
534 vlc_object_release( p_aout );
538 QMenu *menu = new QMenu();
539 Populate( p_intf, menu, varnames, objects );
540 menu->addSeparator();
541 POPUP_STATIC_ENTRIES;
543 p_intf->p_sys->p_popup_menu = menu;
544 menu->popup( QCursor::pos() );
545 p_intf->p_sys->p_popup_menu = NULL;
549 #undef PUSH_SEPARATOR
551 /*************************************************************************
552 * Builders for automenus
553 *************************************************************************/
554 QMenu * QVLCMenu::Populate( intf_thread_t *p_intf, QMenu *current,
555 vector< const char *> & varnames,
556 vector<int> & objects, bool append )
558 QMenu *menu = current;
566 vlc_object_t *p_object;
567 vlc_bool_t b_section_empty = VLC_FALSE;
570 #define APPEND_EMPTY { QAction *action = menu->addAction( qtr("Empty" ) ); \
571 action->setEnabled( false ); }
573 for( i = 0; i < (int)objects.size() ; i++ )
575 if( !varnames[i] || !*varnames[i] )
577 if( b_section_empty )
579 menu->addSeparator();
580 b_section_empty = VLC_TRUE;
584 if( objects[i] == 0 )
586 /// \bug What is this ?
587 // Append( menu, varnames[i], NULL );
588 b_section_empty = VLC_FALSE;
592 p_object = (vlc_object_t *)vlc_object_get( p_intf,
594 if( p_object == NULL ) continue;
596 b_section_empty = VLC_FALSE;
597 /* Ugly specific stuff */
598 if( strstr(varnames[i], "intf-add" ) )
599 CreateItem( menu, varnames[i], p_object, false );
601 CreateItem( menu, varnames[i], p_object, true );
602 vlc_object_release( p_object );
605 /* Special case for empty menus */
606 if( menu->actions().size() == 0 || b_section_empty )
612 /*****************************************************************************
614 *****************************************************************************/
616 static bool IsMenuEmpty( const char *psz_var, vlc_object_t *p_object,
619 vlc_value_t val, val_list;
620 int i_type, i_result, i;
622 /* Check the type of the object variable */
623 i_type = var_Type( p_object, psz_var );
625 /* Check if we want to display the variable */
626 if( !(i_type & VLC_VAR_HASCHOICE) ) return FALSE;
628 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
629 if( val.i_int == 0 ) return TRUE;
631 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE )
633 /* Very evil hack ! intf-switch can have only one value */
634 if( !strcmp( psz_var, "intf-switch" ) ) return FALSE;
635 if( val.i_int == 1 && b_root ) return TRUE;
639 /* Check children variables in case of VLC_VAR_VARIABLE */
640 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
645 for( i = 0, i_result = TRUE; i < val_list.p_list->i_count; i++ )
647 if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
655 /* clean up everything */
656 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, NULL );
661 void QVLCMenu::CreateItem( QMenu *menu, const char *psz_var,
662 vlc_object_t *p_object, bool b_submenu )
664 vlc_value_t val, text;
667 /* Check the type of the object variable */
668 i_type = var_Type( p_object, psz_var );
670 switch( i_type & VLC_VAR_TYPE )
674 case VLC_VAR_VARIABLE:
676 case VLC_VAR_INTEGER:
680 /* Variable doesn't exist or isn't handled */
684 /* Make sure we want to display the variable */
685 if( IsMenuEmpty( psz_var, p_object ) ) return;
687 /* Get the descriptive name of the variable */
688 var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
690 if( i_type & VLC_VAR_HASCHOICE )
692 /* Append choices menu */
695 QMenu *submenu = new QMenu();
696 submenu->setTitle( qfu( text.psz_string ?
697 text.psz_string : psz_var ) );
698 if( CreateChoicesMenu( submenu, psz_var, p_object, true ) == 0)
699 menu->addMenu( submenu );
702 CreateChoicesMenu( menu, psz_var, p_object, true );
703 FREENULL( text.psz_string );
707 #define TEXT_OR_VAR qfu ( text.psz_string ? text.psz_string : psz_var )
709 switch( i_type & VLC_VAR_TYPE )
712 var_Get( p_object, psz_var, &val );
713 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_NORMAL,
714 p_object->i_object_id, val, i_type );
718 var_Get( p_object, psz_var, &val );
719 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_CHECK,
720 p_object->i_object_id, val, i_type, val.b_bool );
723 FREENULL( text.psz_string );
727 int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
728 vlc_object_t *p_object, bool b_root )
730 vlc_value_t val, val_list, text_list;
733 /* Check the type of the object variable */
734 i_type = var_Type( p_object, psz_var );
736 /* Make sure we want to display the variable */
737 if( IsMenuEmpty( psz_var, p_object, b_root ) ) return VLC_EGENERIC;
739 switch( i_type & VLC_VAR_TYPE )
743 case VLC_VAR_VARIABLE:
745 case VLC_VAR_INTEGER:
749 /* Variable doesn't exist or isn't handled */
753 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
754 &val_list, &text_list ) < 0 )
758 #define NORMAL_OR_RADIO i_type & VLC_VAR_ISCOMMAND ? ITEM_NORMAL: ITEM_RADIO
759 #define NOTCOMMAND !(i_type & VLC_VAR_ISCOMMAND)
760 #define CURVAL val_list.p_list->p_values[i]
761 #define CURTEXT text_list.p_list->p_values[i].psz_string
763 for( i = 0; i < val_list.p_list->i_count; i++ )
765 vlc_value_t another_val;
767 QMenu *subsubmenu = new QMenu();
769 switch( i_type & VLC_VAR_TYPE )
771 case VLC_VAR_VARIABLE:
772 CreateChoicesMenu( subsubmenu, CURVAL.psz_string, p_object, false );
773 subsubmenu->setTitle( qfu( CURTEXT ? CURTEXT :CURVAL.psz_string ) );
774 submenu->addMenu( subsubmenu );
778 var_Get( p_object, psz_var, &val );
779 another_val.psz_string = strdup( CURVAL.psz_string );
780 menutext = qfu( CURTEXT ? CURTEXT : another_val.psz_string );
781 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
782 p_object->i_object_id, another_val, i_type,
783 NOTCOMMAND && val.psz_string &&
784 !strcmp( val.psz_string, CURVAL.psz_string ) );
786 if( val.psz_string ) free( val.psz_string );
789 case VLC_VAR_INTEGER:
790 var_Get( p_object, psz_var, &val );
791 if( CURTEXT ) menutext = qfu( CURTEXT );
792 else menutext.sprintf( "%d", CURVAL.i_int);
793 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
794 p_object->i_object_id, CURVAL, i_type,
795 NOTCOMMAND && CURVAL.i_int == val.i_int );
799 var_Get( p_object, psz_var, &val );
800 if( CURTEXT ) menutext = qfu( CURTEXT );
801 else menutext.sprintf( "%.2f", CURVAL.f_float );
802 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
803 p_object->i_object_id, CURVAL, i_type,
804 NOTCOMMAND && CURVAL.f_float == val.f_float );
813 /* clean up everything */
814 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
816 #undef NORMAL_OR_RADIO
823 void QVLCMenu::CreateAndConnect( QMenu *menu, const char *psz_var,
824 QString text, QString help,
825 int i_item_type, int i_object_id,
826 vlc_value_t val, int i_val_type,
829 QAction *action = new QAction( text, menu );
830 action->setText( text );
831 action->setToolTip( help );
833 if( i_item_type == ITEM_CHECK )
835 action->setCheckable( true );
837 else if( i_item_type == ITEM_RADIO )
839 action->setCheckable( true );
841 currentGroup = new QActionGroup(menu);
842 currentGroup->addAction( action );
847 action->setChecked( true );
849 MenuItemData *itemData = new MenuItemData( i_object_id, i_val_type,
851 CONNECT( action, triggered(), THEDP->menusMapper, map() );
852 THEDP->menusMapper->setMapping( action, itemData );
853 menu->addAction( action );
856 void QVLCMenu::DoAction( intf_thread_t *p_intf, QObject *data )
858 MenuItemData *itemData = qobject_cast<MenuItemData *>(data);
859 vlc_object_t *p_object = (vlc_object_t *)vlc_object_get( p_intf,
860 itemData->i_object_id );
861 if( p_object == NULL ) return;
863 var_Set( p_object, itemData->psz_var, itemData->val );
864 vlc_object_release( p_object );