]> git.sesse.net Git - vlc/blob - modules/gui/qt4/menus.cpp
1c4520a42645c0c8a891450ba4806682194195d0
[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(), qtr("File") );
121     BAR_ADD( ToolsMenu( p_intf ), qtr("Tools") );
122     BAR_DADD( VideoMenu( p_intf, NULL ), qtr("Video"), 1 );
123     BAR_DADD( AudioMenu( p_intf, NULL ), qtr("Audio"), 2 );
124     BAR_DADD( NavigMenu( p_intf, NULL ), qtr("Navigation"), 3 );
125
126     //    BAR_ADD( HelpMenu(), qtr("Help" ) );
127 }
128
129 QMenu *QVLCMenu::FileMenu()
130 {
131     QMenu *menu = new QMenu();
132     DP_SADD( qtr("Quick &Open File...") , "", "", simpleOpenDialog() );
133     DP_SADD( qtr("&Advanced Open..." ), "", "", openDialog() );
134     menu->addSeparator();
135     DP_SADD( qtr("Streaming..."), "", "", streamingDialog() );
136     menu->addSeparator();
137     DP_SADD( qtr("&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( qtr("Interfaces" ) );
148         menu->addMenu( intfmenu );
149         /** \todo ADD EXT GUI HERE */
150         menu->addSeparator();
151     }
152     DP_SADD( qtr("Messages" ), "", "", messagesDialog() );
153     DP_SADD( qtr("Information") , "", "", streaminfoDialog() );
154     DP_SADD( qtr("Bookmarks"), "", "", bookmarksDialog() );
155     menu->addSeparator();
156     DP_SADD( qtr("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( qtr("Stop"), "", "", stop() ); \
265     MIM_SADD( qtr("Previous"), "", "", prev() ); \
266     MIM_SADD( qtr("Next"), "", "", next() ); \
267     if( p_input ) \
268     { \
269         var_Get( p_input, "state", &val ); \
270         if( val.i_int == PAUSE_S ) \
271             MIM_SADD( qtr("Play"), "", "", togglePlayPause() ) \
272         else \
273             MIM_SADD( qtr("Pause"), "", "", togglePlayPause() ) \
274     } \
275     else if( THEPL->i_size && THEPL->i_enabled ) \
276         MIM_SADD( qtr("Play"), "", "", togglePlayPause() ) \
277     \
278     QMenu *intfmenu = InterfacesMenu( p_intf, NULL ); \
279     intfmenu->setTitle( qtr("Interfaces" ) ); \
280     menu->addMenu( intfmenu ); \
281     \
282     QMenu *toolsmenu = ToolsMenu( p_intf, false ); \
283     toolsmenu->setTitle( qtr("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( qtr("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( qfu( text.psz_string ? 
545                                     text.psz_string : psz_var ) );
546             if( CreateChoicesMenu( submenu, psz_var, p_object, true ) == 0)
547                 menu->addMenu( submenu );
548         }
549         else
550             CreateChoicesMenu( menu, psz_var, p_object, true );
551         FREE( text.psz_string );
552         return;
553     }
554
555 #define TEXT_OR_VAR qfu ( text.psz_string ? text.psz_string : psz_var )
556
557     switch( i_type & VLC_VAR_TYPE )
558     {
559     case VLC_VAR_VOID:
560         var_Get( p_object, psz_var, &val );
561         CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_NORMAL,
562                           p_object->i_object_id, val, i_type );
563         break;
564
565     case VLC_VAR_BOOL:
566         var_Get( p_object, psz_var, &val );
567         val.b_bool = !val.b_bool;
568         CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_CHECK,
569                           p_object->i_object_id, val, i_type, val.b_bool );
570         break;
571     }
572     FREE( text.psz_string );
573 }
574
575
576 int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var, 
577                                  vlc_object_t *p_object, bool b_root )
578 {
579     vlc_value_t val, val_list, text_list;
580     int i_type, i;
581
582     /* Check the type of the object variable */
583     i_type = var_Type( p_object, psz_var );
584
585     /* Make sure we want to display the variable */
586     if( IsMenuEmpty( psz_var, p_object, b_root ) ) return VLC_EGENERIC;
587
588     switch( i_type & VLC_VAR_TYPE )
589     {
590     case VLC_VAR_VOID:
591     case VLC_VAR_BOOL:
592     case VLC_VAR_VARIABLE:
593     case VLC_VAR_STRING:
594     case VLC_VAR_INTEGER:
595     case VLC_VAR_FLOAT:
596         break;
597     default:
598         /* Variable doesn't exist or isn't handled */
599         return VLC_EGENERIC;
600     }
601
602     if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
603                     &val_list, &text_list ) < 0 )
604     {
605         return VLC_EGENERIC;
606     }
607 #define NORMAL_OR_RADIO i_type & VLC_VAR_ISCOMMAND ? ITEM_NORMAL: ITEM_RADIO
608 #define NOTCOMMAND !(i_type & VLC_VAR_ISCOMMAND) 
609 #define CURVAL val_list.p_list->p_values[i]
610 #define CURTEXT text_list.p_list->p_values[i].psz_string
611
612     for( i = 0; i < val_list.p_list->i_count; i++ )
613     {
614         vlc_value_t another_val;
615         QString menutext;
616         QMenu *subsubmenu = new QMenu();
617
618         switch( i_type & VLC_VAR_TYPE )
619         {
620         case VLC_VAR_VARIABLE:
621             CreateChoicesMenu( subsubmenu, CURVAL.psz_string, p_object, false );
622             subsubmenu->setTitle( qfu( CURTEXT ? CURTEXT :CURVAL.psz_string ) );
623             submenu->addMenu( subsubmenu );
624             break;
625
626         case VLC_VAR_STRING:
627           var_Get( p_object, psz_var, &val );
628           another_val.psz_string = strdup( CURVAL.psz_string );
629
630           menutext = qfu( CURTEXT ? CURTEXT : another_val.psz_string );
631           CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
632                             p_object->i_object_id, another_val, i_type, 
633                             NOTCOMMAND && val.psz_string &&
634                             !strcmp( val.psz_string, CURVAL.psz_string ) );
635
636           if( val.psz_string ) free( val.psz_string );
637           break;
638
639         case VLC_VAR_INTEGER:
640           var_Get( p_object, psz_var, &val );
641           if( CURTEXT ) menutext = qfu( CURTEXT );
642           else menutext.sprintf( "%d", CURVAL.i_int);
643           CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
644                             p_object->i_object_id, CURVAL, i_type,
645                             NOTCOMMAND && CURVAL.i_int == val.i_int );
646           break;
647
648         case VLC_VAR_FLOAT:
649           var_Get( p_object, psz_var, &val );
650           if( CURTEXT ) menutext = qfu( CURTEXT );
651           else menutext.sprintf( "%.2f", CURVAL.f_float );
652           CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
653                             p_object->i_object_id, CURVAL, i_type,
654                             NOTCOMMAND && CURVAL.f_float == val.f_float );
655           break;
656
657         default:
658           break;
659         }
660     }
661
662     /* clean up everything */
663     var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
664
665 #undef NORMAL_OR_RADIO
666 #undef NOTCOMMAND
667 #undef CURVAL
668 #undef CURTEXT
669     return VLC_SUCCESS;
670 }
671
672 void QVLCMenu::CreateAndConnect( QMenu *menu, const char *psz_var,
673                                  QString text, QString help,
674                                  int i_item_type, int i_object_id, 
675                                  vlc_value_t val, int i_val_type,
676                                  bool checked )
677 {
678     QAction *action = new QAction( text, menu );
679     action->setText( text );
680     action->setToolTip( help );
681
682     if( i_item_type == ITEM_CHECK )
683     {
684         action->setCheckable( true );
685         currentGroup = NULL;
686     }
687     else if( i_item_type == ITEM_RADIO )
688     {
689         action->setCheckable( true );
690         if( !currentGroup )
691             currentGroup = new QActionGroup(menu);
692         currentGroup->addAction( action );
693     }
694     else
695         currentGroup = NULL;
696     if( checked ) action->setChecked( true );
697
698     MenuItemData *itemData = new MenuItemData( i_object_id, i_val_type,
699                                                val, psz_var );
700     connect( action, SIGNAL(triggered()), THEDP->menusMapper, SLOT(map()) ); 
701     THEDP->menusMapper->setMapping( action, itemData );
702     
703     menu->addAction( action );
704 }
705
706 void QVLCMenu::DoAction( intf_thread_t *p_intf, QObject *data )
707 {
708     MenuItemData *itemData = qobject_cast<MenuItemData *>(data);
709     
710     vlc_object_t *p_object = (vlc_object_t *)vlc_object_get( p_intf,
711                                            itemData->i_object_id );
712     if( p_object == NULL ) return;
713
714     fprintf( stderr, "Setting %s on %i\n", itemData->psz_var, 
715                    p_object->i_object_id );
716     var_Set( p_object, itemData->psz_var, itemData->val );
717     vlc_object_release( p_object );
718 }