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 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 \
419 MIM_SADD( qtr("Stop"), "", "", stop() ); \
420 MIM_SADD( qtr("Previous"), "", "", prev() ); \
421 MIM_SADD( qtr("Next"), "", "", next() ); \
424 var_Get( p_input, "state", &val ); \
425 if( val.i_int == PAUSE_S ) \
426 MIM_SADD( qtr("Play"), "", "", togglePlayPause() ) \
428 MIM_SADD( qtr("Pause"), "", "", togglePlayPause() ) \
430 else if( THEPL->items.i_size && THEPL->i_enabled ) \
431 MIM_SADD( qtr("Play"), "", "", togglePlayPause() ) \
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 ); \
441 void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf )
446 vlc_object_yield( p_input );
447 varnames.push_back( "video-es" );
448 objects.push_back( p_input->i_object_id );
449 varnames.push_back( "spu-es" );
450 objects.push_back( p_input->i_object_id );
451 vlc_object_t *p_vout = (vlc_object_t *)vlc_object_find( p_input,
452 VLC_OBJECT_VOUT, FIND_CHILD );
455 VideoAutoMenuBuilder( p_vout, objects, varnames );
456 vlc_object_release( p_vout );
458 vlc_object_release( p_input );
463 void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf )
468 vlc_object_yield( p_input );
469 varnames.push_back( "audio-es" );
470 objects.push_back( p_input->i_object_id );
471 vlc_object_t *p_aout = (vlc_object_t *)vlc_object_find( p_input,
472 VLC_OBJECT_AOUT, FIND_ANYWHERE );
475 AudioAutoMenuBuilder( p_aout, objects, varnames );
476 vlc_object_release( p_aout );
478 vlc_object_release( p_input );
483 /* Navigation stuff, and general */
484 void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf )
489 vlc_object_yield( p_input );
490 varnames.push_back( "audio-es" );
491 InputAutoMenuBuilder( VLC_OBJECT(p_input), objects, varnames );
495 QMenu *menu = new QMenu();
496 Populate( p_intf, menu, varnames, objects );
497 menu->addSeparator();
498 POPUP_STATIC_ENTRIES;
500 p_intf->p_sys->p_popup_menu = menu;
501 menu->popup( QCursor::pos() );
502 p_intf->p_sys->p_popup_menu = NULL;
505 void QVLCMenu::PopupMenu( intf_thread_t *p_intf )
510 vlc_object_yield( p_input );
511 InputAutoMenuBuilder( VLC_OBJECT(p_input), objects, varnames );
515 varnames.push_back( "video-es" );
516 objects.push_back( p_input->i_object_id );
517 varnames.push_back( "spu-es" );
518 objects.push_back( p_input->i_object_id );
519 vlc_object_t *p_vout = (vlc_object_t *)vlc_object_find( p_input,
520 VLC_OBJECT_VOUT, FIND_CHILD );
523 VideoAutoMenuBuilder( p_vout, objects, varnames );
524 vlc_object_release( p_vout );
528 varnames.push_back( "audio-es" );
529 objects.push_back( p_input->i_object_id );
530 vlc_object_t *p_aout = (vlc_object_t *)vlc_object_find( p_input,
531 VLC_OBJECT_AOUT, FIND_ANYWHERE );
534 AudioAutoMenuBuilder( p_aout, objects, varnames );
535 vlc_object_release( p_aout );
539 QMenu *menu = new QMenu();
540 Populate( p_intf, menu, varnames, objects );
541 menu->addSeparator();
542 POPUP_STATIC_ENTRIES;
544 p_intf->p_sys->p_popup_menu = menu;
545 menu->popup( QCursor::pos() );
546 p_intf->p_sys->p_popup_menu = NULL;
550 #undef PUSH_SEPARATOR
552 /*************************************************************************
553 * Builders for automenus
554 *************************************************************************/
555 QMenu * QVLCMenu::Populate( intf_thread_t *p_intf, QMenu *current,
556 vector< const char *> & varnames,
557 vector<int> & objects, bool append )
559 QMenu *menu = current;
567 vlc_object_t *p_object;
568 vlc_bool_t b_section_empty = VLC_FALSE;
571 #define APPEND_EMPTY { QAction *action = menu->addAction( qtr("Empty" ) ); \
572 action->setEnabled( false ); }
574 for( i = 0; i < (int)objects.size() ; i++ )
576 if( !varnames[i] || !*varnames[i] )
578 if( b_section_empty )
580 menu->addSeparator();
581 b_section_empty = VLC_TRUE;
585 if( objects[i] == 0 )
587 /// \bug What is this ?
588 // Append( menu, varnames[i], NULL );
589 b_section_empty = VLC_FALSE;
593 p_object = (vlc_object_t *)vlc_object_get( p_intf,
595 if( p_object == NULL ) continue;
597 b_section_empty = VLC_FALSE;
598 /* Ugly specific stuff */
599 if( strstr(varnames[i], "intf-add" ) )
600 CreateItem( menu, varnames[i], p_object, false );
602 CreateItem( menu, varnames[i], p_object, true );
603 vlc_object_release( p_object );
606 /* Special case for empty menus */
607 if( menu->actions().size() == 0 || b_section_empty )
613 /*****************************************************************************
615 *****************************************************************************/
617 static bool IsMenuEmpty( const char *psz_var, vlc_object_t *p_object,
620 vlc_value_t val, val_list;
621 int i_type, i_result, i;
623 /* Check the type of the object variable */
624 i_type = var_Type( p_object, psz_var );
626 /* Check if we want to display the variable */
627 if( !(i_type & VLC_VAR_HASCHOICE) ) return FALSE;
629 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
630 if( val.i_int == 0 ) return TRUE;
632 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE )
634 /* Very evil hack ! intf-switch can have only one value */
635 if( !strcmp( psz_var, "intf-switch" ) ) return FALSE;
636 if( val.i_int == 1 && b_root ) return TRUE;
640 /* Check children variables in case of VLC_VAR_VARIABLE */
641 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
646 for( i = 0, i_result = TRUE; i < val_list.p_list->i_count; i++ )
648 if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
656 /* clean up everything */
657 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, NULL );
662 void QVLCMenu::CreateItem( QMenu *menu, const char *psz_var,
663 vlc_object_t *p_object, bool b_submenu )
665 vlc_value_t val, text;
668 /* Check the type of the object variable */
669 i_type = var_Type( p_object, psz_var );
671 switch( i_type & VLC_VAR_TYPE )
675 case VLC_VAR_VARIABLE:
677 case VLC_VAR_INTEGER:
681 /* Variable doesn't exist or isn't handled */
685 /* Make sure we want to display the variable */
686 if( IsMenuEmpty( psz_var, p_object ) ) return;
688 /* Get the descriptive name of the variable */
689 var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
691 if( i_type & VLC_VAR_HASCHOICE )
693 /* Append choices menu */
696 QMenu *submenu = new QMenu();
697 submenu->setTitle( qfu( text.psz_string ?
698 text.psz_string : psz_var ) );
699 if( CreateChoicesMenu( submenu, psz_var, p_object, true ) == 0)
700 menu->addMenu( submenu );
703 CreateChoicesMenu( menu, psz_var, p_object, true );
704 FREENULL( text.psz_string );
708 #define TEXT_OR_VAR qfu ( text.psz_string ? text.psz_string : psz_var )
710 switch( i_type & VLC_VAR_TYPE )
713 var_Get( p_object, psz_var, &val );
714 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_NORMAL,
715 p_object->i_object_id, val, i_type );
719 var_Get( p_object, psz_var, &val );
720 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_CHECK,
721 p_object->i_object_id, val, i_type, val.b_bool );
724 FREENULL( text.psz_string );
728 int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
729 vlc_object_t *p_object, bool b_root )
731 vlc_value_t val, val_list, text_list;
734 /* Check the type of the object variable */
735 i_type = var_Type( p_object, psz_var );
737 /* Make sure we want to display the variable */
738 if( IsMenuEmpty( psz_var, p_object, b_root ) ) return VLC_EGENERIC;
740 switch( i_type & VLC_VAR_TYPE )
744 case VLC_VAR_VARIABLE:
746 case VLC_VAR_INTEGER:
750 /* Variable doesn't exist or isn't handled */
754 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
755 &val_list, &text_list ) < 0 )
759 #define NORMAL_OR_RADIO i_type & VLC_VAR_ISCOMMAND ? ITEM_NORMAL: ITEM_RADIO
760 #define NOTCOMMAND !(i_type & VLC_VAR_ISCOMMAND)
761 #define CURVAL val_list.p_list->p_values[i]
762 #define CURTEXT text_list.p_list->p_values[i].psz_string
764 for( i = 0; i < val_list.p_list->i_count; i++ )
766 vlc_value_t another_val;
768 QMenu *subsubmenu = new QMenu();
770 switch( i_type & VLC_VAR_TYPE )
772 case VLC_VAR_VARIABLE:
773 CreateChoicesMenu( subsubmenu, CURVAL.psz_string, p_object, false );
774 subsubmenu->setTitle( qfu( CURTEXT ? CURTEXT :CURVAL.psz_string ) );
775 submenu->addMenu( subsubmenu );
779 var_Get( p_object, psz_var, &val );
780 another_val.psz_string = strdup( CURVAL.psz_string );
781 menutext = qfu( CURTEXT ? CURTEXT : another_val.psz_string );
782 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
783 p_object->i_object_id, another_val, i_type,
784 NOTCOMMAND && val.psz_string &&
785 !strcmp( val.psz_string, CURVAL.psz_string ) );
787 if( val.psz_string ) free( val.psz_string );
790 case VLC_VAR_INTEGER:
791 var_Get( p_object, psz_var, &val );
792 if( CURTEXT ) menutext = qfu( CURTEXT );
793 else menutext.sprintf( "%d", CURVAL.i_int);
794 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
795 p_object->i_object_id, CURVAL, i_type,
796 NOTCOMMAND && CURVAL.i_int == val.i_int );
800 var_Get( p_object, psz_var, &val );
801 if( CURTEXT ) menutext = qfu( CURTEXT );
802 else menutext.sprintf( "%.2f", CURVAL.f_float );
803 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
804 p_object->i_object_id, CURVAL, i_type,
805 NOTCOMMAND && CURVAL.f_float == val.f_float );
814 /* clean up everything */
815 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
817 #undef NORMAL_OR_RADIO
824 void QVLCMenu::CreateAndConnect( QMenu *menu, const char *psz_var,
825 QString text, QString help,
826 int i_item_type, int i_object_id,
827 vlc_value_t val, int i_val_type,
830 QAction *action = new QAction( text, menu );
831 action->setText( text );
832 action->setToolTip( help );
834 if( i_item_type == ITEM_CHECK )
836 action->setCheckable( true );
838 else if( i_item_type == ITEM_RADIO )
840 action->setCheckable( true );
842 currentGroup = new QActionGroup(menu);
843 currentGroup->addAction( action );
848 action->setChecked( true );
850 MenuItemData *itemData = new MenuItemData( i_object_id, i_val_type,
852 CONNECT( action, triggered(), THEDP->menusMapper, map() );
853 THEDP->menusMapper->setMapping( action, itemData );
854 menu->addAction( action );
857 void QVLCMenu::DoAction( intf_thread_t *p_intf, QObject *data )
859 MenuItemData *itemData = qobject_cast<MenuItemData *>(data);
860 vlc_object_t *p_object = (vlc_object_t *)vlc_object_get( p_intf,
861 itemData->i_object_id );
862 if( p_object == NULL ) return;
864 var_Set( p_object, itemData->psz_var, itemData->val );
865 vlc_object_release( p_object );