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