]> git.sesse.net Git - vlc/blob - modules/gui/qt4/menus.cpp
d4902f290970bbcf891dc5d9c87fe2e2ac5cd36a
[vlc] / modules / gui / qt4 / menus.cpp
1 /*****************************************************************************
2  * menus.cpp : Qt menus
3  *****************************************************************************
4  * Copyright (C) 2006 the VideoLAN team
5  * $Id$
6  *
7  * Authors: ClÃment Stenac <zorglub@videolan.org>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24 #include "menus.hpp"
25 #include "dialogs_provider.hpp"
26 #include "input_manager.hpp"
27 #include <QMenu>
28 #include <QMenuBar>
29 #include <QAction>
30 #include <QActionGroup>
31 #include <QSignalMapper>
32
33 enum
34 {
35     ITEM_NORMAL,
36     ITEM_CHECK,
37     ITEM_RADIO
38 };
39
40 static QActionGroup *currentGroup;
41
42 // Add static entries to menus
43 #define DP_SADD( text, help, icon, slot ) { if( strlen(icon) > 0 ) { QAction *action = menu->addAction( text, THEDP, SLOT( slot ) ); action->setIcon(QIcon(icon));} else { menu->addAction( text, THEDP, SLOT( slot ) ); } }
44 #define MIM_SADD( text, help, icon, slot ) { if( strlen(icon) > 0 ) { QAction *action = menu->addAction( text, THEMIM, SLOT( slot ) ); action->setIcon(QIcon(icon));} else { menu->addAction( text, THEMIM, SLOT( slot ) ); } }
45
46 /*****************************************************************************
47  * Definitions of variables for the dynamic menus
48  *****************************************************************************/
49 #define PUSH_VAR( var ) varnames.push_back( var ); \
50                         objects.push_back( p_object->i_object_id )
51
52 #define PUSH_SEPARATOR if( objects.size() != i_last_separator ) { \
53                            objects.push_back( 0 ); varnames.push_back( "" ); \
54                            i_last_separator = objects.size(); }
55
56 static int InputAutoMenuBuilder( vlc_object_t *p_object,
57                                  vector<int> &objects,
58                                  vector<const char *> &varnames )
59 {
60     PUSH_VAR( "bookmark");
61     PUSH_VAR( "title" );
62     PUSH_VAR ("chapter" );
63     PUSH_VAR( "program" );
64     PUSH_VAR( "navigation" );
65     PUSH_VAR( "dvd_menus" );
66     return VLC_SUCCESS;
67 }
68
69 static int VideoAutoMenuBuilder( vlc_object_t *p_object, 
70                                  vector<int> &objects,
71                                  vector<const char *> &varnames )
72 {
73     PUSH_VAR( "fullscreen" );
74     PUSH_VAR( "zoom" );
75     PUSH_VAR( "deinterlace" );
76     PUSH_VAR( "aspect-ratio" );
77     PUSH_VAR( "crop" );
78     PUSH_VAR( "video-on-top" );
79     PUSH_VAR( "directx-wallpaper" );
80     PUSH_VAR( "video-snapshot" );
81
82     vlc_object_t *p_dec_obj = (vlc_object_t *)vlc_object_find( p_object,
83                                                  VLC_OBJECT_DECODER,
84                                                  FIND_PARENT );
85     if( p_dec_obj != NULL )
86     {
87         PUSH_VAR( "ffmpeg-pp-q" );
88         vlc_object_release( p_dec_obj );
89     }
90     return VLC_SUCCESS;
91 }
92
93 static int AudioAutoMenuBuilder( vlc_object_t *p_object,
94                                  vector<int> &objects,
95                                  vector<const char *> &varnames )
96 {
97     PUSH_VAR( "audio-device" );
98     PUSH_VAR( "audio-channels" );
99     PUSH_VAR( "visual" );
100     PUSH_VAR( "equalizer" );
101     return VLC_SUCCESS;
102 }
103
104 /*****************************************************************************
105  * All normal menus
106  *****************************************************************************/
107
108 void QVLCMenu::createMenuBar( QMenuBar *bar, intf_thread_t *p_intf )
109 {
110 #define BAR_ADD( func, title ) { \
111     QMenu *menu = func; menu->setTitle( title  ); bar->addMenu( menu ); }
112
113 #define BAR_DADD( func, title, id ) { \
114     QMenu *menu = func; menu->setTitle( title  ); bar->addMenu( menu ); \
115     MenuFunc *f = new MenuFunc( menu, id ); \
116     connect( menu, SIGNAL( aboutToShow() ), \
117             THEDP->menusUpdateMapper, SLOT(map()) ); \
118     THEDP->menusUpdateMapper->setMapping( menu, f ); }
119
120     BAR_ADD( FileMenu(), _("File") );
121     BAR_ADD( ToolsMenu( p_intf ), _("Tools") );
122     BAR_DADD( VideoMenu( p_intf, NULL ), _("Video"), 1 );
123     BAR_DADD( AudioMenu( p_intf, NULL ), _("Audio"), 2 );
124     BAR_DADD( NavigMenu( p_intf, NULL ), _("Navigation"), 3 );
125
126     //    BAR_ADD( HelpMenu(), _("Help" ) );
127 }
128
129 QMenu *QVLCMenu::FileMenu()
130 {
131     QMenu *menu = new QMenu();
132     DP_SADD( _("Quick &Open File...") , "", "", simpleOpenDialog() );
133     DP_SADD( _("&Advanced Open..." ), "", "", openDialog() );
134     menu->addSeparator();
135     DP_SADD( _("Streaming..."), "", "", streamingDialog() );
136     menu->addSeparator();
137     DP_SADD( _("&Quit") , "", "", quit() );
138     return menu;
139 }
140
141 QMenu *QVLCMenu::ToolsMenu( intf_thread_t *p_intf, bool with_intf )
142 {
143     QMenu *menu = new QMenu();
144     if( with_intf )
145     {
146         QMenu *intfmenu = InterfacesMenu( p_intf, NULL );
147         intfmenu->setTitle( _("Interfaces" ) );
148         menu->addMenu( intfmenu );
149         /** \todo ADD EXT GUI HERE */
150         menu->addSeparator();
151     }
152     DP_SADD( _("Messages" ), "", "", messagesDialog() );
153     DP_SADD( _("Information") , "", "", streaminfoDialog() );
154     DP_SADD( _("Bookmarks"), "", "", bookmarksDialog() );
155     menu->addSeparator();
156     DP_SADD( _("Preferences"), "", "", prefsDialog() );
157     return menu;
158 }
159
160 QMenu *QVLCMenu::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
161 {
162     vector<int> objects;
163     vector<const char *> varnames;
164     /** \todo add "switch to XXX" */
165     varnames.push_back( "intf-add" );
166     objects.push_back( p_intf->i_object_id );
167     
168     QMenu *menu = Populate( p_intf, current, varnames, objects );
169     connect( menu, SIGNAL( aboutToShow() ),
170              THEDP->menusUpdateMapper, SLOT(map()) );
171     THEDP->menusUpdateMapper->setMapping( menu, 4 );
172
173     return menu;
174 }
175
176 QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QMenu * current )
177 {
178     vector<int> objects;
179     vector<const char *> varnames;
180
181     vlc_object_t *p_object = (vlc_object_t *)vlc_object_find( p_intf,
182                                         VLC_OBJECT_INPUT, FIND_ANYWHERE );
183     if( p_object != NULL )
184     {
185         PUSH_VAR( "audio-es" );
186         vlc_object_release( p_object );
187     }
188
189     p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_AOUT,
190                                                 FIND_ANYWHERE );
191     if( p_object )
192     {
193         AudioAutoMenuBuilder( p_object, objects, varnames );
194         vlc_object_release( p_object );
195     }
196     return Populate( p_intf, current, varnames, objects );
197 }
198
199
200 QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current )
201 {
202     vlc_object_t *p_object;
203     vector<int> objects;
204     vector<const char *> varnames;
205
206     p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
207                                                 FIND_ANYWHERE );
208     if( p_object != NULL )
209     {
210         PUSH_VAR( "video-es" );
211         PUSH_VAR( "spu-es" );
212         vlc_object_release( p_object );
213     }
214
215     p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT,
216                                                 FIND_ANYWHERE );
217     if( p_object != NULL )
218     {
219         VideoAutoMenuBuilder( p_object, objects, varnames );
220         vlc_object_release( p_object );
221     }
222     return Populate( p_intf, current, varnames, objects );
223 }
224
225 QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *current )
226 {
227     vlc_object_t *p_object;
228     vector<int> objects;
229     vector<const char *> varnames;
230
231     /* FIXME */
232     p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
233                                                 FIND_ANYWHERE );
234     if( p_object != NULL )
235     {
236         InputAutoMenuBuilder( p_object, objects, varnames );
237         PUSH_VAR( "prev-title"); PUSH_VAR ( "next-title" );
238         PUSH_VAR( "prev-chapter"); PUSH_VAR( "next-chapter" );
239         vlc_object_release( p_object );
240     }
241     return Populate( p_intf, current, varnames, objects );
242 }
243
244
245 /*****************************************************************************
246  * Popup menus
247  *****************************************************************************/
248 #define POPUP_BOILERPLATE \
249     unsigned int i_last_separator = 0; \
250     vector<int> objects; \
251     vector<const char *> varnames; \
252     input_thread_t *p_input = THEMIM->getInput();
253
254 #define CREATE_POPUP \
255     QMenu *menu = new QMenu(); \
256     Populate( p_intf, menu, varnames, objects ); \
257     p_intf->p_sys->p_popup_menu = menu; \
258     menu->popup( QCursor::pos() ); \
259     p_intf->p_sys->p_popup_menu = NULL; \
260     i_last_separator = 0;
261
262 #define POPUP_STATIC_ENTRIES \
263     vlc_value_t val; \
264     MIM_SADD( _("Stop"), "", "", stop() ); \
265     MIM_SADD( _("Previous"), "", "", prev() ); \
266     MIM_SADD( _("Next"), "", "", next() ); \
267     if( p_input ) \
268     { \
269         var_Get( p_input, "state", &val ); \
270         if( val.i_int == PAUSE_S ) \
271             MIM_SADD( _("Play"), "", "", togglePlayPause() ) \
272         else \
273             MIM_SADD( _("Pause"), "", "", togglePlayPause() ) \
274     } \
275     else if( THEPL->i_size && THEPL->i_enabled ) \
276         MIM_SADD( _("Play"), "", "", togglePlayPause() ) \
277     \
278     QMenu *intfmenu = InterfacesMenu( p_intf, NULL ); \
279     intfmenu->setTitle( _("Interfaces" ) ); \
280     menu->addMenu( intfmenu ); \
281     \
282     QMenu *toolsmenu = ToolsMenu( p_intf, false ); \
283     toolsmenu->setTitle( _("Tools" ) ); \
284     menu->addMenu( toolsmenu ); \
285      
286 void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf )
287 {
288     POPUP_BOILERPLATE;
289     if( p_input )
290     {
291         vlc_object_yield( p_input );
292         varnames.push_back( "video-es" );
293         objects.push_back( p_input->i_object_id );
294         varnames.push_back( "spu-es" );
295         objects.push_back( p_input->i_object_id );
296         vlc_object_t *p_vout = (vlc_object_t *)vlc_object_find( p_input,
297                                                 VLC_OBJECT_VOUT, FIND_CHILD );
298         if( p_vout )
299         {
300             VideoAutoMenuBuilder( p_vout, objects, varnames );
301             vlc_object_release( p_vout );
302         }
303         vlc_object_release( p_input );
304     }
305     CREATE_POPUP;
306 }
307
308 void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf )
309 {
310     POPUP_BOILERPLATE;
311     if( p_input )
312     {
313         vlc_object_yield( p_input );
314         varnames.push_back( "audio-es" );
315         objects.push_back( p_input->i_object_id );
316         vlc_object_t *p_aout = (vlc_object_t *)vlc_object_find( p_input,
317                                              VLC_OBJECT_AOUT, FIND_ANYWHERE );
318         if( p_aout )
319         {
320             AudioAutoMenuBuilder( p_aout, objects, varnames );
321             vlc_object_release( p_aout );
322         }
323         vlc_object_release( p_input );
324     }
325     CREATE_POPUP;
326 }
327
328 /* Navigation stuff, and general */
329 void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf )
330 {
331     POPUP_BOILERPLATE;
332     if( p_input )
333     {
334         vlc_object_yield( p_input );
335         varnames.push_back( "audio-es" );
336         InputAutoMenuBuilder( VLC_OBJECT(p_input), objects, varnames );
337         PUSH_SEPARATOR;
338     }
339
340     QMenu *menu = new QMenu();
341     Populate( p_intf, menu, varnames, objects );
342     menu->addSeparator();
343     POPUP_STATIC_ENTRIES;
344
345     p_intf->p_sys->p_popup_menu = menu;
346     menu->popup( QCursor::pos() );
347     p_intf->p_sys->p_popup_menu = NULL;
348 }
349
350 void QVLCMenu::PopupMenu( intf_thread_t *p_intf )
351 {
352     POPUP_BOILERPLATE;
353     if( p_input )
354     {
355         vlc_object_yield( p_input );
356         InputAutoMenuBuilder( VLC_OBJECT(p_input), objects, varnames );
357
358         /* Video menu */
359         PUSH_SEPARATOR;
360         varnames.push_back( "video-es" );
361         objects.push_back( p_input->i_object_id );
362         varnames.push_back( "spu-es" );
363         objects.push_back( p_input->i_object_id );
364         vlc_object_t *p_vout = (vlc_object_t *)vlc_object_find( p_input,
365                                                 VLC_OBJECT_VOUT, FIND_CHILD );
366         if( p_vout )
367         {
368             VideoAutoMenuBuilder( p_vout, objects, varnames );
369             vlc_object_release( p_vout );
370         }
371         /* Audio menu */
372         PUSH_SEPARATOR
373         varnames.push_back( "audio-es" );
374         objects.push_back( p_input->i_object_id );
375         vlc_object_t *p_aout = (vlc_object_t *)vlc_object_find( p_input,
376                                              VLC_OBJECT_AOUT, FIND_ANYWHERE );
377         if( p_aout )
378         {
379             AudioAutoMenuBuilder( p_aout, objects, varnames );
380             vlc_object_release( p_aout );
381         }
382     }
383
384     QMenu *menu = new QMenu();
385     Populate( p_intf, menu, varnames, objects );
386     menu->addSeparator();
387     POPUP_STATIC_ENTRIES;
388
389     p_intf->p_sys->p_popup_menu = menu;
390     menu->popup( QCursor::pos() );
391     p_intf->p_sys->p_popup_menu = NULL;
392 }
393
394 #undef PUSH_VAR
395 #undef PUSH_SEPARATOR
396
397 /*************************************************************************
398  * Builders for automenus
399  *************************************************************************/
400 QMenu * QVLCMenu::Populate( intf_thread_t *p_intf, QMenu *current,
401                             vector< const char *> & varnames,
402                             vector<int> & objects, bool append )
403 {
404     QMenu *menu = current;
405     if( !menu )
406         menu = new QMenu();
407     else if( !append )
408         menu->clear();
409
410     currentGroup = NULL;
411
412     vlc_object_t *p_object;
413     vlc_bool_t b_section_empty = VLC_FALSE;
414     int i;
415
416 #define APPEND_EMPTY { QAction *action = menu->addAction( _("Empty" ) ); \
417                        action->setEnabled( false ); }
418
419     for( i = 0; i < (int)objects.size() ; i++ )
420     {
421         if( !varnames[i] || !*varnames[i] )
422         {
423             if( b_section_empty )
424                 APPEND_EMPTY;
425             menu->addSeparator();
426             b_section_empty = VLC_TRUE;
427             continue;
428         }
429
430         if( objects[i] == 0  )
431         {
432             /// \bug What is this ?
433             // Append( menu, varnames[i], NULL );
434             b_section_empty = VLC_FALSE;
435             continue;
436         }
437
438         p_object = (vlc_object_t *)vlc_object_get( p_intf,
439                                                    objects[i] );
440         if( p_object == NULL ) continue;
441
442         b_section_empty = VLC_FALSE;
443         /* Ugly specific stuff */
444         if( strstr(varnames[i], "intf-add" ) )
445             CreateItem( menu, varnames[i], p_object, false );
446         else
447             CreateItem( menu, varnames[i], p_object, true );
448         vlc_object_release( p_object );
449     }
450
451     /* Special case for empty menus */
452     if( menu->actions().size() == 0 || b_section_empty )
453         APPEND_EMPTY
454
455     return menu;
456 }
457
458 /*****************************************************************************
459  * Private methods.
460  *****************************************************************************/
461
462 #define FREE(x) if(x) { free(x);x=NULL;}
463
464 static bool IsMenuEmpty( const char *psz_var, vlc_object_t *p_object,
465                          bool b_root = TRUE )
466 {
467     vlc_value_t val, val_list;
468     int i_type, i_result, i;
469
470     /* Check the type of the object variable */
471     i_type = var_Type( p_object, psz_var );
472
473     /* Check if we want to display the variable */
474     if( !(i_type & VLC_VAR_HASCHOICE) ) return FALSE;
475
476     var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
477     if( val.i_int == 0 ) return TRUE;
478
479     if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE )
480     {
481         /* Very evil hack ! intf-switch can have only one value */ 
482         if( !strcmp( psz_var, "intf-switch" ) ) return FALSE;
483         if( val.i_int == 1 && b_root ) return TRUE;
484         else return FALSE;
485     }
486
487     /* Check children variables in case of VLC_VAR_VARIABLE */
488     if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
489     {
490         return TRUE;
491     }
492
493     for( i = 0, i_result = TRUE; i < val_list.p_list->i_count; i++ )
494     {
495         if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
496                           p_object, FALSE ) )
497         {
498             i_result = FALSE;
499             break;
500         }
501     }
502
503     /* clean up everything */
504     var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, NULL );
505
506     return i_result;
507 }
508
509 void QVLCMenu::CreateItem( QMenu *menu, const char *psz_var,
510                            vlc_object_t *p_object, bool b_submenu )
511 {
512     vlc_value_t val, text;
513     int i_type;
514
515     /* Check the type of the object variable */
516     i_type = var_Type( p_object, psz_var );
517
518     switch( i_type & VLC_VAR_TYPE )
519     {
520     case VLC_VAR_VOID:
521     case VLC_VAR_BOOL:
522     case VLC_VAR_VARIABLE:
523     case VLC_VAR_STRING:
524     case VLC_VAR_INTEGER:
525     case VLC_VAR_FLOAT:
526         break;
527     default:
528         /* Variable doesn't exist or isn't handled */
529         return;
530     }
531
532     /* Make sure we want to display the variable */
533     if( IsMenuEmpty( psz_var, p_object ) )  return;
534
535     /* Get the descriptive name of the variable */
536     var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
537
538     if( i_type & VLC_VAR_HASCHOICE )
539     {
540         /* Append choices menu */
541         if( b_submenu )
542         {
543             QMenu *submenu = new QMenu();
544             submenu->setTitle( text.psz_string ? text.psz_string : psz_var );
545             if( CreateChoicesMenu( submenu, psz_var, p_object, true ) == 0)
546                 menu->addMenu( submenu );
547         }
548         else
549             CreateChoicesMenu( menu, psz_var, p_object, true );
550         FREE( text.psz_string );
551         return;
552     }
553
554 #define TEXT_OR_VAR text.psz_string ? text.psz_string : psz_var
555
556     switch( i_type & VLC_VAR_TYPE )
557     {
558     case VLC_VAR_VOID:
559         var_Get( p_object, psz_var, &val );
560         CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_NORMAL,
561                           p_object->i_object_id, val, i_type );
562         break;
563
564     case VLC_VAR_BOOL:
565         var_Get( p_object, psz_var, &val );
566         val.b_bool = !val.b_bool;
567         CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_CHECK,
568                           p_object->i_object_id, val, i_type, val.b_bool );
569         break;
570     }
571     FREE( text.psz_string );
572 }
573
574
575 int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var, 
576                                  vlc_object_t *p_object, bool b_root )
577 {
578     vlc_value_t val, val_list, text_list;
579     int i_type, i;
580
581     /* Check the type of the object variable */
582     i_type = var_Type( p_object, psz_var );
583
584     /* Make sure we want to display the variable */
585     if( IsMenuEmpty( psz_var, p_object, b_root ) ) return VLC_EGENERIC;
586
587     switch( i_type & VLC_VAR_TYPE )
588     {
589     case VLC_VAR_VOID:
590     case VLC_VAR_BOOL:
591     case VLC_VAR_VARIABLE:
592     case VLC_VAR_STRING:
593     case VLC_VAR_INTEGER:
594     case VLC_VAR_FLOAT:
595         break;
596     default:
597         /* Variable doesn't exist or isn't handled */
598         return VLC_EGENERIC;
599     }
600
601     if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
602                     &val_list, &text_list ) < 0 )
603     {
604         return VLC_EGENERIC;
605     }
606 #define NORMAL_OR_RADIO i_type & VLC_VAR_ISCOMMAND ? ITEM_NORMAL: ITEM_RADIO
607 #define NOTCOMMAND !(i_type & VLC_VAR_ISCOMMAND) 
608 #define CURVAL val_list.p_list->p_values[i]
609 #define CURTEXT text_list.p_list->p_values[i].psz_string
610
611     for( i = 0; i < val_list.p_list->i_count; i++ )
612     {
613         vlc_value_t another_val;
614         QString menutext;
615         QMenu *subsubmenu = new QMenu();
616
617         switch( i_type & VLC_VAR_TYPE )
618         {
619         case VLC_VAR_VARIABLE:
620             CreateChoicesMenu( subsubmenu, CURVAL.psz_string, p_object, false );
621             subsubmenu->setTitle( CURTEXT ? CURTEXT : CURVAL.psz_string );
622             submenu->addMenu( subsubmenu );
623             break;
624
625         case VLC_VAR_STRING:
626           var_Get( p_object, psz_var, &val );
627           another_val.psz_string = strdup( CURVAL.psz_string );
628
629           menutext = CURTEXT ? CURTEXT : another_val.psz_string;
630           CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
631                             p_object->i_object_id, another_val, i_type, 
632                             NOTCOMMAND && val.psz_string &&
633                             !strcmp( val.psz_string, CURVAL.psz_string ) );
634
635           if( val.psz_string ) free( val.psz_string );
636           break;
637
638         case VLC_VAR_INTEGER:
639           var_Get( p_object, psz_var, &val );
640           if( CURTEXT ) menutext = CURTEXT; 
641           else menutext.sprintf( "%d", CURVAL.i_int);
642           CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
643                             p_object->i_object_id, CURVAL, i_type,
644                             NOTCOMMAND && CURVAL.i_int == val.i_int );
645           break;
646
647         case VLC_VAR_FLOAT:
648           var_Get( p_object, psz_var, &val );
649           if( CURTEXT ) menutext = CURTEXT ;
650           else menutext.sprintf( "%.2f", CURVAL.f_float );
651           CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
652                             p_object->i_object_id, CURVAL, i_type,
653                             NOTCOMMAND && CURVAL.f_float == val.f_float );
654           break;
655
656         default:
657           break;
658         }
659     }
660
661     /* clean up everything */
662     var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
663
664 #undef NORMAL_OR_RADIO
665 #undef NOTCOMMAND
666 #undef CURVAL
667 #undef CURTEXT
668     return VLC_SUCCESS;
669 }
670
671 void QVLCMenu::CreateAndConnect( QMenu *menu, const char *psz_var,
672                                  QString text, QString help,
673                                  int i_item_type, int i_object_id, 
674                                  vlc_value_t val, int i_val_type,
675                                  bool checked )
676 {
677     QAction *action = new QAction( text, menu );
678     action->setText( text );
679     action->setToolTip( help );
680
681     if( i_item_type == ITEM_CHECK )
682     {
683         action->setCheckable( true );
684         currentGroup = NULL;
685     }
686     else if( i_item_type == ITEM_RADIO )
687     {
688         action->setCheckable( true );
689         if( !currentGroup )
690             currentGroup = new QActionGroup(menu);
691         currentGroup->addAction( action );
692     }
693     else
694         currentGroup = NULL;
695     if( checked ) action->setChecked( true );
696
697     MenuItemData *itemData = new MenuItemData( i_object_id, i_val_type,
698                                                val, psz_var );
699     connect( action, SIGNAL(triggered()), THEDP->menusMapper, SLOT(map()) ); 
700     THEDP->menusMapper->setMapping( action, itemData );
701     
702     menu->addAction( action );
703 }
704
705 void QVLCMenu::DoAction( intf_thread_t *p_intf, QObject *data )
706 {
707     MenuItemData *itemData = qobject_cast<MenuItemData *>(data);
708     
709     vlc_object_t *p_object = (vlc_object_t *)vlc_object_get( p_intf,
710                                            itemData->i_object_id );
711     if( p_object == NULL ) return;
712
713     var_Set( p_object, itemData->psz_var, itemData->val );
714     vlc_object_release( p_object );
715 }