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 DP_SADD( qtr("Conve&rt / Save..."), "", "", openThenTranscodingDialogs(),
208 menu->addSeparator();
209 DP_SADD( qtr("&Quit") , "", "", quit(), "Ctrl+Q");
213 QMenu *QVLCMenu::PlaylistMenu( MainInterface *mi, intf_thread_t *p_intf )
215 QMenu *menu = new QMenu();
216 menu->addMenu( SDMenu( p_intf ) );
217 menu->addSeparator();
219 DP_SADD( qtr(I_PL_LOAD), "", "", openPlaylist(), "Ctrl+L" );
220 DP_SADD( qtr(I_PL_SAVE), "", "", savePlaylist(), "Ctrl+K" );
221 menu->addSeparator();
222 menu->addAction( qtr("Undock from interface"), mi,
223 SLOT( undockPlaylist() ), qtr("Ctrl+U") );
227 QMenu *QVLCMenu::ToolsMenu( intf_thread_t *p_intf, MainInterface *mi,
228 bool adv_controls_enabled,
229 bool visual_selector_enabled, bool with_intf )
231 QMenu *menu = new QMenu();
234 QMenu *intfmenu = InterfacesMenu( p_intf, NULL );
235 intfmenu->setTitle( qtr("Interfaces" ) );
236 menu->addMenu( intfmenu );
237 menu->addSeparator();
239 DP_SADD( qtr(I_MENU_MSG), "", "", messagesDialog(), "Ctrl+M" );
240 DP_SADD( qtr(I_MENU_INFO) , "", "", mediaInfoDialog(), "Ctrl+J" );
241 DP_SADD( qtr(I_MENU_CODECINFO) , "", "", mediaCodecDialog(), "Ctrl+I" );
242 menu->addSeparator();
245 QAction *adv = menu->addAction( qtr("Advanced controls" ),
246 mi, SLOT( advanced() ) );
247 adv->setCheckable( true );
248 if( adv_controls_enabled ) adv->setChecked( true );
250 adv = menu->addAction( qtr("Visualizations selector" ),
251 mi, SLOT( visual() ) );
252 adv->setCheckable( true );
253 if( visual_selector_enabled ) adv->setChecked( true );
256 DP_SADD( qtr(I_MENU_EXT), "","",extendedDialog(), "Ctrl+E" );
257 DP_SADD( qtr(I_MENU_GOTOTIME), "","",gotoTimeDialog(), "Ctrl+T" );
258 menu->addSeparator();
259 DP_SADD( qtr("Preferences"), "", "", prefsDialog(), "Ctrl+P" );
263 QMenu *QVLCMenu::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
266 vector<const char *> varnames;
267 /** \todo add "switch to XXX" */
268 varnames.push_back( "intf-add" );
269 objects.push_back( p_intf->i_object_id );
271 QMenu *menu = Populate( p_intf, current, varnames, objects );
273 if( !p_intf->pf_show_dialog )
275 menu->addSeparator();
276 menu->addAction( qtr("Switch to skins"), THEDP, SLOT(switchToSkins()),
280 CONNECT( menu, aboutToShow(), THEDP->menusUpdateMapper, map() );
281 THEDP->menusUpdateMapper->setMapping( menu, 4 );
285 QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QMenu * current )
288 vector<const char *> varnames;
290 vlc_object_t *p_object = (vlc_object_t *)vlc_object_find( p_intf,
291 VLC_OBJECT_INPUT, FIND_ANYWHERE );
292 if( p_object != NULL )
294 PUSH_VAR( "audio-es" );
295 vlc_object_release( p_object );
298 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_AOUT,
302 AudioAutoMenuBuilder( p_object, objects, varnames );
303 vlc_object_release( p_object );
305 return Populate( p_intf, current, varnames, objects );
309 QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current )
311 vlc_object_t *p_object;
313 vector<const char *> varnames;
315 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
317 if( p_object != NULL )
319 PUSH_VAR( "video-es" );
320 PUSH_VAR( "spu-es" );
321 vlc_object_release( p_object );
324 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT,
326 if( p_object != NULL )
328 VideoAutoMenuBuilder( p_object, objects, varnames );
329 vlc_object_release( p_object );
331 return Populate( p_intf, current, varnames, objects );
334 QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *current )
336 vlc_object_t *p_object;
338 vector<const char *> varnames;
341 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
343 if( p_object != NULL )
345 InputAutoMenuBuilder( p_object, objects, varnames );
346 PUSH_VAR( "prev-title"); PUSH_VAR ( "next-title" );
347 PUSH_VAR( "prev-chapter"); PUSH_VAR( "next-chapter" );
348 vlc_object_release( p_object );
350 return Populate( p_intf, current, varnames, objects );
353 QMenu *QVLCMenu::SDMenu( intf_thread_t *p_intf )
355 QMenu *menu = new QMenu();
356 menu->setTitle( qtr(I_PL_SD) );
357 vlc_list_t *p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE,
360 for( int i_index = 0 ; i_index < p_list->i_count; i_index++ )
362 module_t * p_parser = (module_t *)p_list->p_values[i_index].p_object ;
363 if( !strcmp( p_parser->psz_capability, "services_discovery" ) )
366 for( int i_index = 0 ; i_index < p_list->i_count; i_index++ )
368 module_t * p_parser = (module_t *)p_list->p_values[i_index].p_object;
369 if( !strcmp( p_parser->psz_capability, "services_discovery" ) )
371 QAction *a = new QAction( qfu( p_parser->psz_longname ), menu );
372 a->setCheckable( true );
373 /* hack to handle submodules properly */
375 while( p_parser->pp_shortcuts[++i] != NULL );
377 if( playlist_IsServicesDiscoveryLoaded( THEPL,
378 i>=0?p_parser->pp_shortcuts[i] : p_parser->psz_object_name ) )
380 a->setChecked( true );
382 CONNECT( a , triggered(), THEDP->SDMapper, map() );
383 THEDP->SDMapper->setMapping( a, i>=0? p_parser->pp_shortcuts[i] :
384 p_parser->psz_object_name );
385 menu->addAction( a );
388 vlc_list_release( p_list );
392 QMenu *QVLCMenu::HelpMenu()
394 QMenu *menu = new QMenu();
395 DP_SADD( qtr("Help") , "", "", helpDialog(), "F1" );
396 menu->addSeparator();
397 DP_SADD( qtr(I_MENU_ABOUT), "", "", aboutDialog(), "Ctrl+F1");
402 /*****************************************************************************
404 *****************************************************************************/
405 #define POPUP_BOILERPLATE \
406 unsigned int i_last_separator = 0; \
407 vector<int> objects; \
408 vector<const char *> varnames; \
409 input_thread_t *p_input = THEMIM->getInput();
411 #define CREATE_POPUP \
412 QMenu *menu = new QMenu(); \
413 Populate( p_intf, menu, varnames, objects ); \
414 p_intf->p_sys->p_popup_menu = menu; \
415 menu->popup( QCursor::pos() ); \
416 p_intf->p_sys->p_popup_menu = NULL; \
417 i_last_separator = 0;
419 #define POPUP_STATIC_ENTRIES \
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 MIM_SADD( qtr("Stop"), "", "", stop() ); \
433 MIM_SADD( qtr("Previous"), "", "", prev() ); \
434 MIM_SADD( qtr("Next"), "", "", next() ); \
435 menu->addSeparator(); \
436 QMenu *intfmenu = InterfacesMenu( p_intf, NULL ); \
437 intfmenu->setTitle( qtr("Interfaces" ) ); \
438 menu->addMenu( intfmenu ); \
440 QMenu *toolsmenu = ToolsMenu( p_intf, NULL, false, false ); \
441 toolsmenu->setTitle( qtr("Tools" ) ); \
442 menu->addMenu( toolsmenu ); \
443 DP_SADD( qtr("Quit"), "", "", quit() , "Ctrl+Q" );
445 void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf )
450 vlc_object_yield( p_input );
451 varnames.push_back( "video-es" );
452 objects.push_back( p_input->i_object_id );
453 varnames.push_back( "spu-es" );
454 objects.push_back( p_input->i_object_id );
455 vlc_object_t *p_vout = (vlc_object_t *)vlc_object_find( p_input,
456 VLC_OBJECT_VOUT, FIND_CHILD );
459 VideoAutoMenuBuilder( p_vout, objects, varnames );
460 vlc_object_release( p_vout );
462 vlc_object_release( p_input );
467 void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf )
472 vlc_object_yield( p_input );
473 varnames.push_back( "audio-es" );
474 objects.push_back( p_input->i_object_id );
475 vlc_object_t *p_aout = (vlc_object_t *)vlc_object_find( p_input,
476 VLC_OBJECT_AOUT, FIND_ANYWHERE );
479 AudioAutoMenuBuilder( p_aout, objects, varnames );
480 vlc_object_release( p_aout );
482 vlc_object_release( p_input );
487 /* Navigation stuff, and general */
488 void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf )
493 vlc_object_yield( p_input );
494 varnames.push_back( "audio-es" );
495 InputAutoMenuBuilder( VLC_OBJECT(p_input), objects, varnames );
499 QMenu *menu = new QMenu();
500 Populate( p_intf, menu, varnames, objects );
501 menu->addSeparator();
502 POPUP_STATIC_ENTRIES;
504 p_intf->p_sys->p_popup_menu = menu;
505 menu->popup( QCursor::pos() );
506 p_intf->p_sys->p_popup_menu = NULL;
509 void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show )
513 // create a popup if there is none
514 if( ! p_intf->p_sys->p_popup_menu )
519 vlc_object_yield( p_input );
520 InputAutoMenuBuilder( VLC_OBJECT(p_input), objects, varnames );
524 varnames.push_back( "video-es" );
525 objects.push_back( p_input->i_object_id );
526 varnames.push_back( "spu-es" );
527 objects.push_back( p_input->i_object_id );
528 vlc_object_t *p_vout = (vlc_object_t *)vlc_object_find( p_input,
529 VLC_OBJECT_VOUT, FIND_CHILD );
532 VideoAutoMenuBuilder( p_vout, objects, varnames );
533 vlc_object_release( p_vout );
537 varnames.push_back( "audio-es" );
538 objects.push_back( p_input->i_object_id );
539 vlc_object_t *p_aout = (vlc_object_t *)vlc_object_find( p_input,
540 VLC_OBJECT_AOUT, FIND_ANYWHERE );
543 AudioAutoMenuBuilder( p_aout, objects, varnames );
544 vlc_object_release( p_aout );
548 QMenu *menu = new QMenu();
549 Populate( p_intf, menu, varnames, objects );
550 menu->addSeparator();
551 POPUP_STATIC_ENTRIES;
553 p_intf->p_sys->p_popup_menu = menu;
555 p_intf->p_sys->p_popup_menu->popup( QCursor::pos() );
559 // destroy popup if there is one
560 delete p_intf->p_sys->p_popup_menu;
561 p_intf->p_sys->p_popup_menu = NULL;
566 #undef PUSH_SEPARATOR
568 /*************************************************************************
569 * Builders for automenus
570 *************************************************************************/
571 QMenu * QVLCMenu::Populate( intf_thread_t *p_intf, QMenu *current,
572 vector< const char *> & varnames,
573 vector<int> & objects, bool append )
575 QMenu *menu = current;
583 vlc_object_t *p_object;
584 vlc_bool_t b_section_empty = VLC_FALSE;
587 #define APPEND_EMPTY { QAction *action = menu->addAction( qtr("Empty" ) ); \
588 action->setEnabled( false ); }
590 for( i = 0; i < (int)objects.size() ; i++ )
592 if( !varnames[i] || !*varnames[i] )
594 if( b_section_empty )
596 menu->addSeparator();
597 b_section_empty = VLC_TRUE;
601 if( objects[i] == 0 )
603 /// \bug What is this ?
604 // Append( menu, varnames[i], NULL );
605 b_section_empty = VLC_FALSE;
609 p_object = (vlc_object_t *)vlc_object_get( p_intf,
611 if( p_object == NULL ) continue;
613 b_section_empty = VLC_FALSE;
614 /* Ugly specific stuff */
615 if( strstr(varnames[i], "intf-add" ) )
616 CreateItem( menu, varnames[i], p_object, false );
618 CreateItem( menu, varnames[i], p_object, true );
619 vlc_object_release( p_object );
622 /* Special case for empty menus */
623 if( menu->actions().size() == 0 || b_section_empty )
629 /*****************************************************************************
631 *****************************************************************************/
633 static bool IsMenuEmpty( const char *psz_var, vlc_object_t *p_object,
636 vlc_value_t val, val_list;
637 int i_type, i_result, i;
639 /* Check the type of the object variable */
640 i_type = var_Type( p_object, psz_var );
642 /* Check if we want to display the variable */
643 if( !(i_type & VLC_VAR_HASCHOICE) ) return FALSE;
645 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
646 if( val.i_int == 0 ) return TRUE;
648 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE )
650 /* Very evil hack ! intf-switch can have only one value */
651 if( !strcmp( psz_var, "intf-switch" ) ) return FALSE;
652 if( val.i_int == 1 && b_root ) return TRUE;
656 /* Check children variables in case of VLC_VAR_VARIABLE */
657 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
662 for( i = 0, i_result = TRUE; i < val_list.p_list->i_count; i++ )
664 if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
672 /* clean up everything */
673 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, NULL );
678 void QVLCMenu::CreateItem( QMenu *menu, const char *psz_var,
679 vlc_object_t *p_object, bool b_submenu )
681 vlc_value_t val, text;
684 /* Check the type of the object variable */
685 i_type = var_Type( p_object, psz_var );
687 switch( i_type & VLC_VAR_TYPE )
691 case VLC_VAR_VARIABLE:
693 case VLC_VAR_INTEGER:
697 /* Variable doesn't exist or isn't handled */
701 /* Make sure we want to display the variable */
702 if( IsMenuEmpty( psz_var, p_object ) ) return;
704 /* Get the descriptive name of the variable */
705 var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
707 if( i_type & VLC_VAR_HASCHOICE )
709 /* Append choices menu */
712 QMenu *submenu = new QMenu();
713 submenu->setTitle( qfu( text.psz_string ?
714 text.psz_string : psz_var ) );
715 if( CreateChoicesMenu( submenu, psz_var, p_object, true ) == 0)
716 menu->addMenu( submenu );
719 CreateChoicesMenu( menu, psz_var, p_object, true );
720 FREENULL( text.psz_string );
724 #define TEXT_OR_VAR qfu ( text.psz_string ? text.psz_string : psz_var )
726 switch( i_type & VLC_VAR_TYPE )
729 var_Get( p_object, psz_var, &val );
730 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_NORMAL,
731 p_object->i_object_id, val, i_type );
735 var_Get( p_object, psz_var, &val );
736 val.b_bool = !val.b_bool;
737 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_CHECK,
738 p_object->i_object_id, val, i_type, !val.b_bool );
741 FREENULL( text.psz_string );
745 int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
746 vlc_object_t *p_object, bool b_root )
748 vlc_value_t val, val_list, text_list;
751 /* Check the type of the object variable */
752 i_type = var_Type( p_object, psz_var );
754 /* Make sure we want to display the variable */
755 if( IsMenuEmpty( psz_var, p_object, b_root ) ) return VLC_EGENERIC;
757 switch( i_type & VLC_VAR_TYPE )
761 case VLC_VAR_VARIABLE:
763 case VLC_VAR_INTEGER:
767 /* Variable doesn't exist or isn't handled */
771 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
772 &val_list, &text_list ) < 0 )
776 #define NORMAL_OR_RADIO i_type & VLC_VAR_ISCOMMAND ? ITEM_NORMAL: ITEM_RADIO
777 #define NOTCOMMAND !(i_type & VLC_VAR_ISCOMMAND)
778 #define CURVAL val_list.p_list->p_values[i]
779 #define CURTEXT text_list.p_list->p_values[i].psz_string
781 for( i = 0; i < val_list.p_list->i_count; i++ )
783 vlc_value_t another_val;
785 QMenu *subsubmenu = new QMenu();
787 switch( i_type & VLC_VAR_TYPE )
789 case VLC_VAR_VARIABLE:
790 CreateChoicesMenu( subsubmenu, CURVAL.psz_string, p_object, false );
791 subsubmenu->setTitle( qfu( CURTEXT ? CURTEXT :CURVAL.psz_string ) );
792 submenu->addMenu( subsubmenu );
796 var_Get( p_object, psz_var, &val );
797 another_val.psz_string = strdup( CURVAL.psz_string );
798 menutext = qfu( CURTEXT ? CURTEXT : another_val.psz_string );
799 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
800 p_object->i_object_id, another_val, i_type,
801 NOTCOMMAND && val.psz_string &&
802 !strcmp( val.psz_string, CURVAL.psz_string ) );
804 if( val.psz_string ) free( val.psz_string );
807 case VLC_VAR_INTEGER:
808 var_Get( p_object, psz_var, &val );
809 if( CURTEXT ) menutext = qfu( CURTEXT );
810 else menutext.sprintf( "%d", CURVAL.i_int);
811 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
812 p_object->i_object_id, CURVAL, i_type,
813 NOTCOMMAND && CURVAL.i_int == val.i_int );
817 var_Get( p_object, psz_var, &val );
818 if( CURTEXT ) menutext = qfu( CURTEXT );
819 else menutext.sprintf( "%.2f", CURVAL.f_float );
820 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
821 p_object->i_object_id, CURVAL, i_type,
822 NOTCOMMAND && CURVAL.f_float == val.f_float );
831 /* clean up everything */
832 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
834 #undef NORMAL_OR_RADIO
841 void QVLCMenu::CreateAndConnect( QMenu *menu, const char *psz_var,
842 QString text, QString help,
843 int i_item_type, int i_object_id,
844 vlc_value_t val, int i_val_type,
847 QAction *action = new QAction( text, menu );
848 action->setText( text );
849 action->setToolTip( help );
851 if( i_item_type == ITEM_CHECK )
853 action->setCheckable( true );
855 else if( i_item_type == ITEM_RADIO )
857 action->setCheckable( true );
859 currentGroup = new QActionGroup(menu);
860 currentGroup->addAction( action );
865 action->setChecked( true );
867 MenuItemData *itemData = new MenuItemData( i_object_id, i_val_type,
869 CONNECT( action, triggered(), THEDP->menusMapper, map() );
870 THEDP->menusMapper->setMapping( action, itemData );
871 menu->addAction( action );
874 void QVLCMenu::DoAction( intf_thread_t *p_intf, QObject *data )
876 MenuItemData *itemData = qobject_cast<MenuItemData *>(data);
877 vlc_object_t *p_object = (vlc_object_t *)vlc_object_get( p_intf,
878 itemData->i_object_id );
879 if( p_object == NULL ) return;
881 var_Set( p_object, itemData->psz_var, itemData->val );
882 vlc_object_release( p_object );