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