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 DP_SADD( qtr(I_MENU_GOTOTIME), "","",gotoTimeDialog(), "Ctrl+T" );
244 menu->addSeparator();
247 QAction *adv = menu->addAction( qtr("Advanced controls" ),
248 mi, SLOT( advanced() ) );
249 adv->setCheckable( true );
250 if( adv_controls_enabled ) adv->setChecked( true );
252 adv = menu->addAction( qtr("Visualizations selector" ),
253 mi, SLOT( visual() ) );
254 adv->setCheckable( true );
255 if( visual_selector_enabled ) adv->setChecked( true );
257 menu->addAction ( qtr( "Playlist"), mi, SLOT( playlist() ) );
259 DP_SADD( qtr(I_MENU_EXT), "","",extendedDialog(), "Ctrl+E" );
260 DP_SADD( qtr("Hide Menus..."), "","",hideMenus(), "Ctrl+H" );
261 menu->addSeparator();
262 DP_SADD( qtr("Preferences"), "", "", prefsDialog(), "Ctrl+P" );
266 QMenu *QVLCMenu::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
269 vector<const char *> varnames;
270 /** \todo add "switch to XXX" */
271 varnames.push_back( "intf-add" );
272 objects.push_back( p_intf->i_object_id );
274 QMenu *menu = Populate( p_intf, current, varnames, objects );
276 if( !p_intf->pf_show_dialog )
278 menu->addSeparator();
279 menu->addAction( qtr("Switch to skins"), THEDP, SLOT(switchToSkins()),
283 CONNECT( menu, aboutToShow(), THEDP->menusUpdateMapper, map() );
284 THEDP->menusUpdateMapper->setMapping( menu, 4 );
288 QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QMenu * current )
291 vector<const char *> varnames;
293 vlc_object_t *p_object = (vlc_object_t *)vlc_object_find( p_intf,
294 VLC_OBJECT_INPUT, FIND_ANYWHERE );
295 if( p_object != NULL )
297 PUSH_VAR( "audio-es" );
298 vlc_object_release( p_object );
301 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_AOUT,
305 AudioAutoMenuBuilder( p_object, objects, varnames );
306 vlc_object_release( p_object );
308 return Populate( p_intf, current, varnames, objects );
312 QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current )
314 vlc_object_t *p_object;
316 vector<const char *> varnames;
318 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
320 if( p_object != NULL )
322 PUSH_VAR( "video-es" );
323 PUSH_VAR( "spu-es" );
324 vlc_object_release( p_object );
327 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT,
329 if( p_object != NULL )
331 VideoAutoMenuBuilder( p_object, objects, varnames );
332 vlc_object_release( p_object );
334 return Populate( p_intf, current, varnames, objects );
337 QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *current )
339 vlc_object_t *p_object;
341 vector<const char *> varnames;
344 p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
346 if( p_object != NULL )
348 InputAutoMenuBuilder( p_object, objects, varnames );
349 PUSH_VAR( "prev-title"); PUSH_VAR ( "next-title" );
350 PUSH_VAR( "prev-chapter"); PUSH_VAR( "next-chapter" );
351 vlc_object_release( p_object );
353 return Populate( p_intf, current, varnames, objects );
356 QMenu *QVLCMenu::SDMenu( intf_thread_t *p_intf )
358 QMenu *menu = new QMenu();
359 menu->setTitle( qtr(I_PL_SD) );
360 vlc_list_t *p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE,
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" ) )
369 for( int i_index = 0 ; i_index < p_list->i_count; i_index++ )
371 module_t * p_parser = (module_t *)p_list->p_values[i_index].p_object;
372 if( !strcmp( p_parser->psz_capability, "services_discovery" ) )
374 QAction *a = new QAction( qfu( p_parser->psz_longname ), menu );
375 a->setCheckable( true );
376 /* hack to handle submodules properly */
378 while( p_parser->pp_shortcuts[++i] != NULL );
380 if( playlist_IsServicesDiscoveryLoaded( THEPL,
381 i>=0?p_parser->pp_shortcuts[i] : p_parser->psz_object_name ) )
383 a->setChecked( true );
385 CONNECT( a , triggered(), THEDP->SDMapper, map() );
386 THEDP->SDMapper->setMapping( a, i>=0? p_parser->pp_shortcuts[i] :
387 p_parser->psz_object_name );
388 menu->addAction( a );
391 vlc_list_release( p_list );
395 QMenu *QVLCMenu::HelpMenu()
397 QMenu *menu = new QMenu();
398 DP_SADD( qtr("Help") , "", "", helpDialog(), "F1" );
399 menu->addSeparator();
400 DP_SADD( qtr(I_MENU_ABOUT), "", "", aboutDialog(), "Ctrl+F1");
405 /*****************************************************************************
407 *****************************************************************************/
408 #define POPUP_BOILERPLATE \
409 unsigned int i_last_separator = 0; \
410 vector<int> objects; \
411 vector<const char *> varnames; \
412 input_thread_t *p_input = THEMIM->getInput();
414 #define CREATE_POPUP \
415 QMenu *menu = new QMenu(); \
416 Populate( p_intf, menu, varnames, objects ); \
417 p_intf->p_sys->p_popup_menu = menu; \
418 menu->popup( QCursor::pos() ); \
419 p_intf->p_sys->p_popup_menu = NULL; \
420 i_last_separator = 0;
422 #define POPUP_STATIC_ENTRIES \
426 var_Get( p_input, "state", &val ); \
427 if( val.i_int == PAUSE_S ) \
428 MIM_SADD( qtr("Play"), "", "", togglePlayPause() ) \
430 MIM_SADD( qtr("Pause"), "", "", togglePlayPause() ) \
432 else if( THEPL->items.i_size && THEPL->i_enabled ) \
433 MIM_SADD( qtr("Play"), "", "", togglePlayPause() );\
435 MIM_SADD( qtr("Stop"), "", "", stop() ); \
436 MIM_SADD( qtr("Previous"), "", "", prev() ); \
437 MIM_SADD( qtr("Next"), "", "", next() ); \
438 menu->addSeparator(); \
439 QMenu *intfmenu = InterfacesMenu( p_intf, NULL ); \
440 intfmenu->setTitle( qtr("Interfaces" ) ); \
441 menu->addMenu( intfmenu ); \
443 QMenu *toolsmenu = ToolsMenu( p_intf, NULL, false, false ); \
444 toolsmenu->setTitle( qtr("Tools" ) ); \
445 menu->addMenu( toolsmenu ); \
446 DP_SADD( qtr("Quit"), "", "", quit() , "Ctrl+Q" );
448 void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf )
453 vlc_object_yield( p_input );
454 varnames.push_back( "video-es" );
455 objects.push_back( p_input->i_object_id );
456 varnames.push_back( "spu-es" );
457 objects.push_back( p_input->i_object_id );
458 vlc_object_t *p_vout = (vlc_object_t *)vlc_object_find( p_input,
459 VLC_OBJECT_VOUT, FIND_CHILD );
462 VideoAutoMenuBuilder( p_vout, objects, varnames );
463 vlc_object_release( p_vout );
465 vlc_object_release( p_input );
470 void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf )
475 vlc_object_yield( p_input );
476 varnames.push_back( "audio-es" );
477 objects.push_back( p_input->i_object_id );
478 vlc_object_t *p_aout = (vlc_object_t *)vlc_object_find( p_input,
479 VLC_OBJECT_AOUT, FIND_ANYWHERE );
482 AudioAutoMenuBuilder( p_aout, objects, varnames );
483 vlc_object_release( p_aout );
485 vlc_object_release( p_input );
490 /* Navigation stuff, and general */
491 void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf )
496 vlc_object_yield( p_input );
497 varnames.push_back( "audio-es" );
498 InputAutoMenuBuilder( VLC_OBJECT(p_input), objects, varnames );
502 QMenu *menu = new QMenu();
503 Populate( p_intf, menu, varnames, objects );
504 menu->addSeparator();
505 POPUP_STATIC_ENTRIES;
507 p_intf->p_sys->p_popup_menu = menu;
508 menu->popup( QCursor::pos() );
509 p_intf->p_sys->p_popup_menu = NULL;
512 void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show )
516 // create a popup if there is none
517 if( ! p_intf->p_sys->p_popup_menu )
522 vlc_object_yield( p_input );
523 InputAutoMenuBuilder( VLC_OBJECT(p_input), objects, varnames );
527 varnames.push_back( "video-es" );
528 objects.push_back( p_input->i_object_id );
529 varnames.push_back( "spu-es" );
530 objects.push_back( p_input->i_object_id );
531 vlc_object_t *p_vout = (vlc_object_t *)vlc_object_find( p_input,
532 VLC_OBJECT_VOUT, FIND_CHILD );
535 VideoAutoMenuBuilder( p_vout, objects, varnames );
536 vlc_object_release( p_vout );
540 varnames.push_back( "audio-es" );
541 objects.push_back( p_input->i_object_id );
542 vlc_object_t *p_aout = (vlc_object_t *)vlc_object_find( p_input,
543 VLC_OBJECT_AOUT, FIND_ANYWHERE );
546 AudioAutoMenuBuilder( p_aout, objects, varnames );
547 vlc_object_release( p_aout );
551 QMenu *menu = new QMenu();
552 Populate( p_intf, menu, varnames, objects );
553 menu->addSeparator();
554 POPUP_STATIC_ENTRIES;
556 p_intf->p_sys->p_popup_menu = menu;
558 p_intf->p_sys->p_popup_menu->popup( QCursor::pos() );
562 // destroy popup if there is one
563 delete p_intf->p_sys->p_popup_menu;
564 p_intf->p_sys->p_popup_menu = NULL;
569 #undef PUSH_SEPARATOR
571 /*************************************************************************
572 * Builders for automenus
573 *************************************************************************/
574 QMenu * QVLCMenu::Populate( intf_thread_t *p_intf, QMenu *current,
575 vector< const char *> & varnames,
576 vector<int> & objects, bool append )
578 QMenu *menu = current;
586 vlc_object_t *p_object;
587 vlc_bool_t b_section_empty = VLC_FALSE;
590 #define APPEND_EMPTY { QAction *action = menu->addAction( qtr("Empty" ) ); \
591 action->setEnabled( false ); }
593 for( i = 0; i < (int)objects.size() ; i++ )
595 if( !varnames[i] || !*varnames[i] )
597 if( b_section_empty )
599 menu->addSeparator();
600 b_section_empty = VLC_TRUE;
604 if( objects[i] == 0 )
606 /// \bug What is this ?
607 // Append( menu, varnames[i], NULL );
608 b_section_empty = VLC_FALSE;
612 p_object = (vlc_object_t *)vlc_object_get( p_intf,
614 if( p_object == NULL ) continue;
616 b_section_empty = VLC_FALSE;
617 /* Ugly specific stuff */
618 if( strstr(varnames[i], "intf-add" ) )
619 CreateItem( menu, varnames[i], p_object, false );
621 CreateItem( menu, varnames[i], p_object, true );
622 vlc_object_release( p_object );
625 /* Special case for empty menus */
626 if( menu->actions().size() == 0 || b_section_empty )
632 /*****************************************************************************
634 *****************************************************************************/
636 static bool IsMenuEmpty( const char *psz_var, vlc_object_t *p_object,
639 vlc_value_t val, val_list;
640 int i_type, i_result, i;
642 /* Check the type of the object variable */
643 i_type = var_Type( p_object, psz_var );
645 /* Check if we want to display the variable */
646 if( !(i_type & VLC_VAR_HASCHOICE) ) return FALSE;
648 var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
649 if( val.i_int == 0 ) return TRUE;
651 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE )
653 /* Very evil hack ! intf-switch can have only one value */
654 if( !strcmp( psz_var, "intf-switch" ) ) return FALSE;
655 if( val.i_int == 1 && b_root ) return TRUE;
659 /* Check children variables in case of VLC_VAR_VARIABLE */
660 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
665 for( i = 0, i_result = TRUE; i < val_list.p_list->i_count; i++ )
667 if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
675 /* clean up everything */
676 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, NULL );
681 void QVLCMenu::CreateItem( QMenu *menu, const char *psz_var,
682 vlc_object_t *p_object, bool b_submenu )
684 vlc_value_t val, text;
687 /* Check the type of the object variable */
688 i_type = var_Type( p_object, psz_var );
690 switch( i_type & VLC_VAR_TYPE )
694 case VLC_VAR_VARIABLE:
696 case VLC_VAR_INTEGER:
700 /* Variable doesn't exist or isn't handled */
704 /* Make sure we want to display the variable */
705 if( IsMenuEmpty( psz_var, p_object ) ) return;
707 /* Get the descriptive name of the variable */
708 var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
710 if( i_type & VLC_VAR_HASCHOICE )
712 /* Append choices menu */
715 QMenu *submenu = new QMenu();
716 submenu->setTitle( qfu( text.psz_string ?
717 text.psz_string : psz_var ) );
718 if( CreateChoicesMenu( submenu, psz_var, p_object, true ) == 0)
719 menu->addMenu( submenu );
722 CreateChoicesMenu( menu, psz_var, p_object, true );
723 FREENULL( text.psz_string );
727 #define TEXT_OR_VAR qfu ( text.psz_string ? text.psz_string : psz_var )
729 switch( i_type & VLC_VAR_TYPE )
732 var_Get( p_object, psz_var, &val );
733 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_NORMAL,
734 p_object->i_object_id, val, i_type );
738 var_Get( p_object, psz_var, &val );
739 val.b_bool = !val.b_bool;
740 CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_CHECK,
741 p_object->i_object_id, val, i_type, !val.b_bool );
744 FREENULL( text.psz_string );
748 int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
749 vlc_object_t *p_object, bool b_root )
751 vlc_value_t val, val_list, text_list;
754 /* Check the type of the object variable */
755 i_type = var_Type( p_object, psz_var );
757 /* Make sure we want to display the variable */
758 if( IsMenuEmpty( psz_var, p_object, b_root ) ) return VLC_EGENERIC;
760 switch( i_type & VLC_VAR_TYPE )
764 case VLC_VAR_VARIABLE:
766 case VLC_VAR_INTEGER:
770 /* Variable doesn't exist or isn't handled */
774 if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
775 &val_list, &text_list ) < 0 )
779 #define NORMAL_OR_RADIO i_type & VLC_VAR_ISCOMMAND ? ITEM_NORMAL: ITEM_RADIO
780 #define NOTCOMMAND !(i_type & VLC_VAR_ISCOMMAND)
781 #define CURVAL val_list.p_list->p_values[i]
782 #define CURTEXT text_list.p_list->p_values[i].psz_string
784 for( i = 0; i < val_list.p_list->i_count; i++ )
786 vlc_value_t another_val;
788 QMenu *subsubmenu = new QMenu();
790 switch( i_type & VLC_VAR_TYPE )
792 case VLC_VAR_VARIABLE:
793 CreateChoicesMenu( subsubmenu, CURVAL.psz_string, p_object, false );
794 subsubmenu->setTitle( qfu( CURTEXT ? CURTEXT :CURVAL.psz_string ) );
795 submenu->addMenu( subsubmenu );
799 var_Get( p_object, psz_var, &val );
800 another_val.psz_string = strdup( CURVAL.psz_string );
801 menutext = qfu( CURTEXT ? CURTEXT : another_val.psz_string );
802 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
803 p_object->i_object_id, another_val, i_type,
804 NOTCOMMAND && val.psz_string &&
805 !strcmp( val.psz_string, CURVAL.psz_string ) );
807 if( val.psz_string ) free( val.psz_string );
810 case VLC_VAR_INTEGER:
811 var_Get( p_object, psz_var, &val );
812 if( CURTEXT ) menutext = qfu( CURTEXT );
813 else menutext.sprintf( "%d", CURVAL.i_int);
814 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
815 p_object->i_object_id, CURVAL, i_type,
816 NOTCOMMAND && CURVAL.i_int == val.i_int );
820 var_Get( p_object, psz_var, &val );
821 if( CURTEXT ) menutext = qfu( CURTEXT );
822 else menutext.sprintf( "%.2f", CURVAL.f_float );
823 CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
824 p_object->i_object_id, CURVAL, i_type,
825 NOTCOMMAND && CURVAL.f_float == val.f_float );
834 /* clean up everything */
835 var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
837 #undef NORMAL_OR_RADIO
844 void QVLCMenu::CreateAndConnect( QMenu *menu, const char *psz_var,
845 QString text, QString help,
846 int i_item_type, int i_object_id,
847 vlc_value_t val, int i_val_type,
850 QAction *action = new QAction( text, menu );
851 action->setText( text );
852 action->setToolTip( help );
854 if( i_item_type == ITEM_CHECK )
856 action->setCheckable( true );
858 else if( i_item_type == ITEM_RADIO )
860 action->setCheckable( true );
862 currentGroup = new QActionGroup(menu);
863 currentGroup->addAction( action );
868 action->setChecked( true );
870 MenuItemData *itemData = new MenuItemData( i_object_id, i_val_type,
872 CONNECT( action, triggered(), THEDP->menusMapper, map() );
873 THEDP->menusMapper->setMapping( action, itemData );
874 menu->addAction( action );
877 void QVLCMenu::DoAction( intf_thread_t *p_intf, QObject *data )
879 MenuItemData *itemData = qobject_cast<MenuItemData *>(data);
880 vlc_object_t *p_object = (vlc_object_t *)vlc_object_get( p_intf,
881 itemData->i_object_id );
882 if( p_object == NULL ) return;
884 var_Set( p_object, itemData->psz_var, itemData->val );
885 vlc_object_release( p_object );