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