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>
35 #include <vlc_intf_strings.h>
37 #include "main_interface.hpp"
39 #include "dialogs_provider.hpp"
40 #include "input_manager.hpp"
49 static QActionGroup *currentGroup;
51 // Add static entries to menus
52 #define DP_SADD( text, help, icon, slot, shortcut ) \
54 if( strlen(icon) > 0 ) \
56 if( strlen(shortcut) > 0 ) \
58 menu->addAction( QIcon(icon), text, THEDP, SLOT( slot ), \
63 menu->addAction( QIcon(icon), text, THEDP, SLOT( slot ) );\
68 if( strlen(shortcut) > 0 ) \
70 menu->addAction( text, THEDP, SLOT( slot ), \
75 menu->addAction( text, THEDP, SLOT( slot ) ); \
79 #define MIM_SADD( text, help, icon, slot ) \
81 if( strlen(icon) > 0 ) \
83 QAction *action = menu->addAction( text, THEMIM, SLOT( slot ) ); \
84 action->setIcon(QIcon(icon)); \
88 menu->addAction( text, THEMIM, SLOT( slot ) ); \
93 /*****************************************************************************
94 * Definitions of variables for the dynamic menus
95 *****************************************************************************/
96 #define PUSH_VAR( var ) varnames.push_back( var ); \
97 objects.push_back( p_object->i_object_id )
99 #define PUSH_SEPARATOR if( objects.size() != i_last_separator ) { \
100 objects.push_back( 0 ); varnames.push_back( "" ); \
101 i_last_separator = objects.size(); }
103 static int InputAutoMenuBuilder( vlc_object_t *p_object,
104 vector<int> &objects,
105 vector<const char *> &varnames )
107 PUSH_VAR( "bookmark");
109 PUSH_VAR ("chapter" );
110 PUSH_VAR( "program" );
111 PUSH_VAR( "navigation" );
112 PUSH_VAR( "dvd_menus" );
116 static int VideoAutoMenuBuilder( vlc_object_t *p_object,
117 vector<int> &objects,
118 vector<const char *> &varnames )
120 PUSH_VAR( "fullscreen" );
122 PUSH_VAR( "deinterlace" );
123 PUSH_VAR( "aspect-ratio" );
125 PUSH_VAR( "video-on-top" );
126 PUSH_VAR( "directx-wallpaper" );
127 PUSH_VAR( "video-snapshot" );
129 vlc_object_t *p_dec_obj = (vlc_object_t *)vlc_object_find( p_object,
132 if( p_dec_obj != NULL )
134 vlc_object_t *p_object = p_dec_obj;
135 PUSH_VAR( "ffmpeg-pp-q" );
136 vlc_object_release( p_dec_obj );
141 static int AudioAutoMenuBuilder( vlc_object_t *p_object,
142 vector<int> &objects,
143 vector<const char *> &varnames )
145 PUSH_VAR( "audio-device" );
146 PUSH_VAR( "audio-channels" );
147 PUSH_VAR( "visual" );
148 PUSH_VAR( "equalizer" );
152 /*****************************************************************************
154 *****************************************************************************/
156 #define BAR_ADD( func, title ) { \
157 QMenu *menu = func; menu->setTitle( title ); bar->addMenu( menu ); }
159 #define BAR_DADD( func, title, id ) { \
160 QMenu *menu = func; menu->setTitle( title ); bar->addMenu( menu ); \
161 MenuFunc *f = new MenuFunc( menu, id ); \
162 CONNECT( menu, aboutToShow(), THEDP->menusUpdateMapper, map() ); \
163 THEDP->menusUpdateMapper->setMapping( menu, f ); }
165 void QVLCMenu::createMenuBar( MainInterface *mi, intf_thread_t *p_intf,
166 bool playlist, bool adv_controls_enabled,
167 bool visual_selector_enabled )
171 * Remove SIGCHLD from the ignored signal the time to initialise
172 * Qt because it call gconf to get the icon theme */
176 sigaddset( &set, SIGCHLD );
177 pthread_sigmask (SIG_UNBLOCK, &set, NULL);
179 QMenuBar *bar = mi->menuBar();
181 pthread_sigmask (SIG_BLOCK, &set, NULL);
183 BAR_ADD( FileMenu(), qtr("&Media") );
186 BAR_ADD( PlaylistMenu( mi,p_intf ), qtr("&Playlist" ) );
188 BAR_ADD( ToolsMenu( p_intf, mi, adv_controls_enabled,
189 visual_selector_enabled ), qtr("&Tools") );
190 BAR_DADD( VideoMenu( p_intf, NULL ), qtr("&Video"), 1 );
191 BAR_DADD( AudioMenu( p_intf, NULL ), qtr("&Audio"), 2 );
192 BAR_DADD( NavigMenu( p_intf, NULL ), qtr("&Navigation"), 3 );
194 BAR_ADD( HelpMenu(), qtr("&Help" ) );
196 QMenu *QVLCMenu::FileMenu()
198 QMenu *menu = new QMenu();
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..."), "", "", openThenStreamingDialogs(),
207 DP_SADD( qtr("Conve&rt / Save..."), "", "", openThenTranscodingDialogs(),
209 menu->addSeparator();
210 DP_SADD( qtr("&Quit") , "", "", quit(), "Ctrl+Q");
214 QMenu *QVLCMenu::PlaylistMenu( MainInterface *mi, intf_thread_t *p_intf )
216 QMenu *menu = new QMenu();
217 menu->addMenu( SDMenu( p_intf ) );
218 menu->addSeparator();
220 DP_SADD( qtr(I_PL_LOAD), "", "", openPlaylist(), "Ctrl+L" );
221 DP_SADD( qtr(I_PL_SAVE), "", "", savePlaylist(), "Ctrl+K" );
222 menu->addSeparator();
223 menu->addAction( qtr("Undock from interface"), mi,
224 SLOT( undockPlaylist() ), qtr("Ctrl+U") );
228 QMenu *QVLCMenu::ToolsMenu( intf_thread_t *p_intf, MainInterface *mi,
229 bool adv_controls_enabled,
230 bool visual_selector_enabled, bool with_intf )
232 QMenu *menu = new QMenu();
235 QMenu *intfmenu = InterfacesMenu( p_intf, NULL );
236 intfmenu->setTitle( qtr("Interfaces" ) );
237 menu->addMenu( intfmenu );
238 menu->addSeparator();
240 DP_SADD( qtr(I_MENU_MSG), "", "", messagesDialog(), "Ctrl+M" );
241 DP_SADD( qtr(I_MENU_INFO) , "", "", mediaInfoDialog(), "Ctrl+J" );
242 DP_SADD( qtr(I_MENU_CODECINFO) , "", "", mediaCodecDialog(), "Ctrl+I" );
243 menu->addSeparator();
246 QAction *adv = menu->addAction( qtr("Advanced controls" ),
247 mi, SLOT( advanced() ) );
248 adv->setCheckable( true );
249 if( adv_controls_enabled ) adv->setChecked( true );
251 adv = menu->addAction( qtr("Visualizations selector" ),
252 mi, SLOT( visual() ) );
253 adv->setCheckable( true );
254 if( visual_selector_enabled ) adv->setChecked( true );
257 DP_SADD( qtr(I_MENU_EXT), "","",extendedDialog(), "Ctrl+E" );
258 DP_SADD( qtr(I_MENU_GOTOTIME), "","",gotoTimeDialog(), "Ctrl+T" );
259 menu->addSeparator();
260 DP_SADD( qtr("Preferences"), "", "", prefsDialog(), "Ctrl+P" );
264 QMenu *QVLCMenu::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
267 vector<const char *> varnames;
268 /** \todo add "switch to XXX" */
269 varnames.push_back( "intf-add" );
270 objects.push_back( p_intf->i_object_id );
272 QMenu *menu = Populate( p_intf, current, varnames, objects );
274 if( !p_intf->pf_show_dialog )
276 menu->addSeparator();
277 menu->addAction( qtr("Switch to skins"), THEDP, SLOT(switchToSkins()),
281 CONNECT( menu, aboutToShow(), THEDP->menusUpdateMapper, map() );
282 THEDP->menusUpdateMapper->setMapping( menu, 4 );
286 QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QMenu * current )
289 vector<const char *> varnames;
291 vlc_object_t *p_object = (vlc_object_t *)vlc_object_find( p_intf,
292 VLC_OBJECT_INPUT, FIND_ANYWHERE );
293 if( p_object != NULL )
295 PUSH_VAR( "audio-es" );
296 vlc_object_release( p_object );
299 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_AOUT,
303 AudioAutoMenuBuilder( p_object, objects, varnames );
304 vlc_object_release( p_object );
306 return Populate( p_intf, current, varnames, objects );
310 QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current )
312 vlc_object_t *p_object;
314 vector<const char *> varnames;
316 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
318 if( p_object != NULL )
320 PUSH_VAR( "video-es" );
321 PUSH_VAR( "spu-es" );
322 vlc_object_release( p_object );
325 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT,
327 if( p_object != NULL )
329 VideoAutoMenuBuilder( p_object, objects, varnames );
330 vlc_object_release( p_object );
332 return Populate( p_intf, current, varnames, objects );
335 QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *current )
337 vlc_object_t *p_object;
339 vector<const char *> varnames;
342 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
344 if( p_object != NULL )
346 InputAutoMenuBuilder( p_object, objects, varnames );
347 PUSH_VAR( "prev-title"); PUSH_VAR ( "next-title" );
348 PUSH_VAR( "prev-chapter"); PUSH_VAR( "next-chapter" );
349 vlc_object_release( p_object );
351 return Populate( p_intf, current, varnames, objects );
354 QMenu *QVLCMenu::SDMenu( intf_thread_t *p_intf )
356 QMenu *menu = new QMenu();
357 menu->setTitle( qtr(I_PL_SD) );
358 vlc_list_t *p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE,
361 for( int i_index = 0 ; i_index < p_list->i_count; i_index++ )
363 module_t * p_parser = (module_t *)p_list->p_values[i_index].p_object ;
364 if( !strcmp( p_parser->psz_capability, "services_discovery" ) )
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" ) )
372 QAction *a = new QAction( qfu( p_parser->psz_longname ), menu );
373 a->setCheckable( true );
374 /* hack to handle submodules properly */
376 while( p_parser->pp_shortcuts[++i] != NULL );
378 if( playlist_IsServicesDiscoveryLoaded( THEPL,
379 i>=0?p_parser->pp_shortcuts[i] : p_parser->psz_object_name ) )
381 a->setChecked( true );
383 CONNECT( a , triggered(), THEDP->SDMapper, map() );
384 THEDP->SDMapper->setMapping( a, i>=0? p_parser->pp_shortcuts[i] :
385 p_parser->psz_object_name );
386 menu->addAction( a );
389 vlc_list_release( p_list );
393 QMenu *QVLCMenu::HelpMenu()
395 QMenu *menu = new QMenu();
396 DP_SADD( qtr("Help") , "", "", helpDialog(), "F1" );
397 menu->addSeparator();
398 DP_SADD( qtr(I_MENU_ABOUT), "", "", aboutDialog(), "Ctrl+F1");
403 /*****************************************************************************
405 *****************************************************************************/
406 #define POPUP_BOILERPLATE \
407 unsigned int i_last_separator = 0; \
408 vector<int> objects; \
409 vector<const char *> varnames; \
410 input_thread_t *p_input = THEMIM->getInput();
412 #define CREATE_POPUP \
413 QMenu *menu = new QMenu(); \
414 Populate( p_intf, menu, varnames, objects ); \
415 p_intf->p_sys->p_popup_menu = menu; \
416 menu->popup( QCursor::pos() ); \
417 p_intf->p_sys->p_popup_menu = NULL; \
418 i_last_separator = 0;
420 #define POPUP_STATIC_ENTRIES \
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 MIM_SADD( qtr("Stop"), "", "", stop() ); \
434 MIM_SADD( qtr("Previous"), "", "", prev() ); \
435 MIM_SADD( qtr("Next"), "", "", next() ); \
436 menu->addSeparator(); \
437 QMenu *intfmenu = InterfacesMenu( p_intf, NULL ); \
438 intfmenu->setTitle( qtr("Interfaces" ) ); \
439 menu->addMenu( intfmenu ); \
441 QMenu *toolsmenu = ToolsMenu( p_intf, NULL, false, false ); \
442 toolsmenu->setTitle( qtr("Tools" ) ); \
443 menu->addMenu( toolsmenu ); \
444 DP_SADD( qtr("Quit"), "", "", quit() , "Ctrl+Q" );
446 void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf )
451 vlc_object_yield( p_input );
452 varnames.push_back( "video-es" );
453 objects.push_back( p_input->i_object_id );
454 varnames.push_back( "spu-es" );
455 objects.push_back( p_input->i_object_id );
456 vlc_object_t *p_vout = (vlc_object_t *)vlc_object_find( p_input,
457 VLC_OBJECT_VOUT, FIND_CHILD );
460 VideoAutoMenuBuilder( p_vout, objects, varnames );
461 vlc_object_release( p_vout );
463 vlc_object_release( p_input );
468 void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf )
473 vlc_object_yield( p_input );
474 varnames.push_back( "audio-es" );
475 objects.push_back( p_input->i_object_id );
476 vlc_object_t *p_aout = (vlc_object_t *)vlc_object_find( p_input,
477 VLC_OBJECT_AOUT, FIND_ANYWHERE );
480 AudioAutoMenuBuilder( p_aout, objects, varnames );
481 vlc_object_release( p_aout );
483 vlc_object_release( p_input );
488 /* Navigation stuff, and general */
489 void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf )
494 vlc_object_yield( p_input );
495 varnames.push_back( "audio-es" );
496 InputAutoMenuBuilder( VLC_OBJECT(p_input), objects, varnames );
500 QMenu *menu = new QMenu();
501 Populate( p_intf, menu, varnames, objects );
502 menu->addSeparator();
503 POPUP_STATIC_ENTRIES;
505 p_intf->p_sys->p_popup_menu = menu;
506 menu->popup( QCursor::pos() );
507 p_intf->p_sys->p_popup_menu = NULL;
510 void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show )
514 // create a popup if there is none
515 if( ! p_intf->p_sys->p_popup_menu )
520 vlc_object_yield( p_input );
521 InputAutoMenuBuilder( VLC_OBJECT(p_input), objects, varnames );
525 varnames.push_back( "video-es" );
526 objects.push_back( p_input->i_object_id );
527 varnames.push_back( "spu-es" );
528 objects.push_back( p_input->i_object_id );
529 vlc_object_t *p_vout = (vlc_object_t *)vlc_object_find( p_input,
530 VLC_OBJECT_VOUT, FIND_CHILD );
533 VideoAutoMenuBuilder( p_vout, objects, varnames );
534 vlc_object_release( p_vout );
538 varnames.push_back( "audio-es" );
539 objects.push_back( p_input->i_object_id );
540 vlc_object_t *p_aout = (vlc_object_t *)vlc_object_find( p_input,
541 VLC_OBJECT_AOUT, FIND_ANYWHERE );
544 AudioAutoMenuBuilder( p_aout, objects, varnames );
545 vlc_object_release( p_aout );
549 QMenu *menu = new QMenu();
550 Populate( p_intf, menu, varnames, objects );
551 menu->addSeparator();
552 POPUP_STATIC_ENTRIES;
554 p_intf->p_sys->p_popup_menu = menu;
556 p_intf->p_sys->p_popup_menu->popup( QCursor::pos() );
560 // destroy popup if there is one
561 delete p_intf->p_sys->p_popup_menu;
562 p_intf->p_sys->p_popup_menu = NULL;
567 #undef PUSH_SEPARATOR
569 /*************************************************************************
570 * Builders for automenus
571 *************************************************************************/
572 QMenu * QVLCMenu::Populate( intf_thread_t *p_intf, QMenu *current,
573 vector< const char *> & varnames,
574 vector<int> & objects, bool append )
576 QMenu *menu = current;
584 vlc_object_t *p_object;
585 vlc_bool_t b_section_empty = VLC_FALSE;
588 #define APPEND_EMPTY { QAction *action = menu->addAction( qtr("Empty" ) ); \
589 action->setEnabled( false ); }
591 for( i = 0; i < (int)objects.size() ; i++ )
593 if( !varnames[i] || !*varnames[i] )
595 if( b_section_empty )
597 menu->addSeparator();
598 b_section_empty = VLC_TRUE;
602 if( objects[i] == 0 )
604 /// \bug What is this ?
605 // Append( menu, varnames[i], NULL );
606 b_section_empty = VLC_FALSE;
610 p_object = (vlc_object_t *)vlc_object_get( p_intf,
612 if( p_object == NULL ) continue;
614 b_section_empty = VLC_FALSE;
615 /* Ugly specific stuff */
616 if( strstr(varnames[i], "intf-add" ) )
617 CreateItem( menu, varnames[i], p_object, false );
619 CreateItem( menu, varnames[i], p_object, true );
620 vlc_object_release( p_object );
623 /* Special case for empty menus */
624 if( menu->actions().size() == 0 || b_section_empty )
630 /*****************************************************************************
632 *****************************************************************************/
634 static bool IsMenuEmpty( const char *psz_var, vlc_object_t *p_object,
637 vlc_value_t val, val_list;
638 int i_type, i_result, i;
640 /* Check the type of the object variable */
641 i_type = var_Type( p_object, psz_var );
643 /* Check if we want to display the variable */
644 if( !(i_type & VLC_VAR_HASCHOICE) ) return FALSE;
646 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
647 if( val.i_int == 0 ) return TRUE;
649 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE )
651 /* Very evil hack ! intf-switch can have only one value */
652 if( !strcmp( psz_var, "intf-switch" ) ) return FALSE;
653 if( val.i_int == 1 && b_root ) return TRUE;
657 /* Check children variables in case of VLC_VAR_VARIABLE */
658 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
663 for( i = 0, i_result = TRUE; i < val_list.p_list->i_count; i++ )
665 if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
673 /* clean up everything */
674 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, NULL );
679 void QVLCMenu::CreateItem( QMenu *menu, const char *psz_var,
680 vlc_object_t *p_object, bool b_submenu )
682 vlc_value_t val, text;
685 /* Check the type of the object variable */
686 i_type = var_Type( p_object, psz_var );
688 switch( i_type & VLC_VAR_TYPE )
692 case VLC_VAR_VARIABLE:
694 case VLC_VAR_INTEGER:
698 /* Variable doesn't exist or isn't handled */
702 /* Make sure we want to display the variable */
703 if( IsMenuEmpty( psz_var, p_object ) ) return;
705 /* Get the descriptive name of the variable */
706 var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
708 if( i_type & VLC_VAR_HASCHOICE )
710 /* Append choices menu */
713 QMenu *submenu = new QMenu();
714 submenu->setTitle( qfu( text.psz_string ?
715 text.psz_string : psz_var ) );
716 if( CreateChoicesMenu( submenu, psz_var, p_object, true ) == 0)
717 menu->addMenu( submenu );
720 CreateChoicesMenu( menu, psz_var, p_object, true );
721 FREENULL( text.psz_string );
725 #define TEXT_OR_VAR qfu ( text.psz_string ? text.psz_string : psz_var )
727 switch( i_type & VLC_VAR_TYPE )
730 var_Get( p_object, psz_var, &val );
731 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_NORMAL,
732 p_object->i_object_id, val, i_type );
736 var_Get( p_object, psz_var, &val );
737 val.b_bool = !val.b_bool;
738 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_CHECK,
739 p_object->i_object_id, val, i_type, !val.b_bool );
742 FREENULL( text.psz_string );
746 int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
747 vlc_object_t *p_object, bool b_root )
749 vlc_value_t val, val_list, text_list;
752 /* Check the type of the object variable */
753 i_type = var_Type( p_object, psz_var );
755 /* Make sure we want to display the variable */
756 if( IsMenuEmpty( psz_var, p_object, b_root ) ) return VLC_EGENERIC;
758 switch( i_type & VLC_VAR_TYPE )
762 case VLC_VAR_VARIABLE:
764 case VLC_VAR_INTEGER:
768 /* Variable doesn't exist or isn't handled */
772 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
773 &val_list, &text_list ) < 0 )
777 #define NORMAL_OR_RADIO i_type & VLC_VAR_ISCOMMAND ? ITEM_NORMAL: ITEM_RADIO
778 #define NOTCOMMAND !(i_type & VLC_VAR_ISCOMMAND)
779 #define CURVAL val_list.p_list->p_values[i]
780 #define CURTEXT text_list.p_list->p_values[i].psz_string
782 for( i = 0; i < val_list.p_list->i_count; i++ )
784 vlc_value_t another_val;
786 QMenu *subsubmenu = new QMenu();
788 switch( i_type & VLC_VAR_TYPE )
790 case VLC_VAR_VARIABLE:
791 CreateChoicesMenu( subsubmenu, CURVAL.psz_string, p_object, false );
792 subsubmenu->setTitle( qfu( CURTEXT ? CURTEXT :CURVAL.psz_string ) );
793 submenu->addMenu( subsubmenu );
797 var_Get( p_object, psz_var, &val );
798 another_val.psz_string = strdup( CURVAL.psz_string );
799 menutext = qfu( CURTEXT ? CURTEXT : another_val.psz_string );
800 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
801 p_object->i_object_id, another_val, i_type,
802 NOTCOMMAND && val.psz_string &&
803 !strcmp( val.psz_string, CURVAL.psz_string ) );
805 if( val.psz_string ) free( val.psz_string );
808 case VLC_VAR_INTEGER:
809 var_Get( p_object, psz_var, &val );
810 if( CURTEXT ) menutext = qfu( CURTEXT );
811 else menutext.sprintf( "%d", CURVAL.i_int);
812 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
813 p_object->i_object_id, CURVAL, i_type,
814 NOTCOMMAND && CURVAL.i_int == val.i_int );
818 var_Get( p_object, psz_var, &val );
819 if( CURTEXT ) menutext = qfu( CURTEXT );
820 else menutext.sprintf( "%.2f", CURVAL.f_float );
821 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
822 p_object->i_object_id, CURVAL, i_type,
823 NOTCOMMAND && CURVAL.f_float == val.f_float );
832 /* clean up everything */
833 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
835 #undef NORMAL_OR_RADIO
842 void QVLCMenu::CreateAndConnect( QMenu *menu, const char *psz_var,
843 QString text, QString help,
844 int i_item_type, int i_object_id,
845 vlc_value_t val, int i_val_type,
848 QAction *action = new QAction( text, menu );
849 action->setText( text );
850 action->setToolTip( help );
852 if( i_item_type == ITEM_CHECK )
854 action->setCheckable( true );
856 else if( i_item_type == ITEM_RADIO )
858 action->setCheckable( true );
860 currentGroup = new QActionGroup(menu);
861 currentGroup->addAction( action );
866 action->setChecked( true );
868 MenuItemData *itemData = new MenuItemData( i_object_id, i_val_type,
870 CONNECT( action, triggered(), THEDP->menusMapper, map() );
871 THEDP->menusMapper->setMapping( action, itemData );
872 menu->addAction( action );
875 void QVLCMenu::DoAction( intf_thread_t *p_intf, QObject *data )
877 MenuItemData *itemData = qobject_cast<MenuItemData *>(data);
878 vlc_object_t *p_object = (vlc_object_t *)vlc_object_get( p_intf,
879 itemData->i_object_id );
880 if( p_object == NULL ) return;
882 var_Set( p_object, itemData->psz_var, itemData->val );
883 vlc_object_release( p_object );