]> git.sesse.net Git - vlc/blob - modules/gui/qt4/menus.cpp
qt4/*: buildsytem fix + cosmetic+ copyright dates + svn Id
[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 <QMenu>
27 #include <QAction>
28 #include <QActionGroup>
29 #include <QSignalMapper>
30
31 enum
32 {
33     ITEM_NORMAL,
34     ITEM_CHECK,
35     ITEM_RADIO
36 };
37
38 static QActionGroup *currentGroup;
39
40 /*****************************************************************************
41  * Static menu helpers
42  * These create already mapped and connected menus
43  *****************************************************************************/
44
45 #define STATIC_ADD( text, help, icon, slot ) { QAction *action = menu->addAction( text, THEDP, SLOT( slot ) ); }
46
47 QMenu *QVLCMenu::FileMenu()
48 {
49     QMenu *menu = new QMenu();
50
51     STATIC_ADD( _("Quick &Open File...") , "", NULL, simpleOpenDialog() );
52     STATIC_ADD( _("&Advanced Open..." ), "", NULL, openDialog() );
53     menu->addSeparator();
54     STATIC_ADD( _("Streaming..."), "", NULL, streamingDialog() );
55     menu->addSeparator();
56     STATIC_ADD( _("&Quit") , "", NULL, quit() );
57
58     return menu;
59 }
60
61 #if 0
62 QMenu *OpenStreamMenu( intf_thread_t *p_intf )
63 {
64     QMenu *menu = new QMenu;
65     menu->Append( OpenFileSimple_Event, wxU(_("Quick &Open File...")) );
66     menu->Append( OpenFile_Event, wxU(_("Open &File...")) );
67     menu->Append( OpenDirectory_Event, wxU(_("Open D&irectory...")) );
68     menu->Append( OpenDisc_Event, wxU(_("Open &Disc...")) );
69     menu->Append( OpenNet_Event, wxU(_("Open &Network Stream...")) );
70     menu->Append( OpenCapture_Event, wxU(_("Open &Capture Device...")) );
71     return menu;
72 }
73
74 wxMenu *MiscMenu( intf_thread_t *p_intf )
75 {
76     wxMenu *menu = new wxMenu;
77     menu->Append( MediaInfo_Event, wxU(_("Media &Info...")) );
78     menu->Append( Messages_Event, wxU(_("&Messages...")) );
79     menu->Append( Preferences_Event, wxU(_("&Preferences...")) );
80     return menu;
81 }
82
83 #endif
84 /*****************************************************************************
85  * Builders for the dynamic menus
86  *****************************************************************************/
87 #define PUSH_VAR( var ) rs_varnames.push_back( var ); \
88                         ri_objects.push_back( p_object->i_object_id )
89
90 static int InputAutoMenuBuilder( vlc_object_t *p_object,
91                                  vector<int> &ri_objects,
92                                  vector<const char *> &rs_varnames )
93 {
94     PUSH_VAR( "bookmark");
95     PUSH_VAR( "title" );
96     PUSH_VAR ("chapter" );
97     PUSH_VAR( "program" );
98     PUSH_VAR( "navigation" );
99     PUSH_VAR( "dvd_menus" );
100     return VLC_SUCCESS;
101 }
102
103 static int VideoAutoMenuBuilder( vlc_object_t *p_object, 
104                                  vector<int> &ri_objects,
105                                  vector<const char *> &rs_varnames )
106 {
107     PUSH_VAR( "fullscreen" );
108     PUSH_VAR( "zoom" );
109     PUSH_VAR( "deinterlace" );
110     PUSH_VAR( "aspect-ratio" );
111     PUSH_VAR( "crop" );
112     PUSH_VAR( "video-on-top" );
113     PUSH_VAR( "directx-wallpaper" );
114     PUSH_VAR( "video-snapshot" );
115
116     vlc_object_t *p_dec_obj = (vlc_object_t *)vlc_object_find( p_object,
117                                                  VLC_OBJECT_DECODER,
118                                                  FIND_PARENT );
119     if( p_dec_obj != NULL )
120     {
121         PUSH_VAR( "ffmpeg-pp-q" );
122         vlc_object_release( p_dec_obj );
123     }
124     return VLC_SUCCESS;
125 }
126
127 static int AudioAutoMenuBuilder( vlc_object_t *p_object,
128                                  vector<int> &ri_objects,
129                                  vector<const char *> &rs_varnames )
130 {
131     PUSH_VAR( "audio-device" );
132     PUSH_VAR( "audio-channels" );
133     PUSH_VAR( "visual" );
134     PUSH_VAR( "equalizer" );
135     return VLC_SUCCESS;
136 }
137
138 static int IntfAutoMenuBuilder( intf_thread_t *p_intf, vector<int> &ri_objects,
139                              vector<const char *> &rs_varnames, bool is_popup )
140 {
141     /* vlc_object_find is needed because of the dialogs provider case */
142     vlc_object_t *p_object;
143     p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_INTF,
144                                                 FIND_PARENT );
145     if( p_object != NULL )
146     {
147         if( is_popup )
148         {
149             PUSH_VAR( "intf-switch" );
150         }
151         else
152         {
153             PUSH_VAR( "intf-switch" );
154         }
155         PUSH_VAR( "intf-add" );
156         PUSH_VAR( "intf-skins" );
157         vlc_object_release( p_object );
158     }
159     return VLC_SUCCESS;
160 }
161
162 #undef PUSH_VAR
163 /*****************************************************************************
164  * Popup menus
165  *****************************************************************************/
166
167 #define PUSH_VAR( var ) as_varnames.push_back( var ); \
168                         ai_objects.push_back( p_object->i_object_id )
169
170 #define PUSH_SEPARATOR if( ai_objects.size() != i_last_separator ) { \
171                             ai_objects.push_back( 0 ); \
172                             as_varnames.push_back( "" ); \
173                             i_last_separator = ai_objects.size(); }
174
175 #define POPUP_BOILERPLATE \
176     unsigned int i_last_separator = 0; \
177     vector<int> ai_objects; \
178     vector<const char *> as_varnames; \
179     playlist_t *p_playlist = (playlist_t *) vlc_object_find( p_intf, \
180                                           VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );\
181     if( !p_playlist ) \
182         return; \
183     input_thread_t *p_input = p_playlist->p_input
184
185 #define CREATE_POPUP    \
186     QMenu *popupmenu = new QMenu(); \
187     QVLCMenu::Populate( popupmenu, as_varnames, ai_objects ); \
188     p_intf->p_sys->p_popup_menu = &popupmenu; \
189     p_intf->p_sys->p_popup_menu = NULL; \
190     i_last_separator = 0 // stop compiler warning 
191 ///    p_parent->PopupMenu( &popupmenu, pos.x, pos.y ); \ /// TODO
192
193 #define POPUP_STATIC_ENTRIES \
194     if( p_input != NULL ) \
195     { \
196         vlc_value_t val; \
197         popupmenu.InsertSeparator( 0 ); \
198         popupmenu.Insert( 0, Stop_Event, wxU(_("Stop")) ); \
199         popupmenu.Insert( 0, Previous_Event, wxU(_("Previous")) ); \
200         popupmenu.Insert( 0, Next_Event, wxU(_("Next")) ); \
201         var_Get( p_input, "state", &val ); \
202         if( val.i_int == PAUSE_S ) \
203             popupmenu.Insert( 0, Play_Event, wxU(_("Play")) ); \
204         else \
205             popupmenu.Insert( 0, Pause_Event, wxU(_("Pause")) ); \
206          \
207         vlc_object_release( p_input ); \
208     } \
209     else \
210     { \
211         if( p_playlist && p_playlist->i_size ) \
212         { \
213             popupmenu.InsertSeparator( 0 ); \
214             popupmenu.Insert( 0, Play_Event, wxU(_("Play")) ); \
215         } \
216         if( p_playlist ) vlc_object_release( p_playlist ); \
217     } \
218     \
219     popupmenu.Append( MenuDummy_Event, wxU(_("Miscellaneous")), \
220                       MiscMenu( p_intf ), wxT("") )
221
222 void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf, const QPoint &pos )
223 {
224     POPUP_BOILERPLATE;
225     if( p_input )
226     {
227         vlc_object_yield( p_input );
228         as_varnames.push_back( "video-es" );
229         ai_objects.push_back( p_input->i_object_id );
230         as_varnames.push_back( "spu-es" );
231         ai_objects.push_back( p_input->i_object_id );
232         vlc_object_t *p_vout = (vlc_object_t *)vlc_object_find( p_input,
233                                                 VLC_OBJECT_VOUT, FIND_CHILD );
234         if( p_vout )
235         {
236             VideoAutoMenuBuilder( p_vout, ai_objects, as_varnames );
237             vlc_object_release( p_vout );
238         }
239         vlc_object_release( p_input );
240     }
241     vlc_object_release( p_playlist );
242     //CREATE_POPUP;
243 }
244
245 void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf, const QPoint &pos )
246 {
247     POPUP_BOILERPLATE;
248     if( p_input )
249     {
250         vlc_object_yield( p_input );
251         as_varnames.push_back( "audio-es" );
252         ai_objects.push_back( p_input->i_object_id );
253         vlc_object_t *p_aout = (vlc_object_t *)vlc_object_find( p_input,
254                                              VLC_OBJECT_AOUT, FIND_ANYWHERE );
255         if( p_aout )
256         {
257             AudioAutoMenuBuilder( p_aout, ai_objects, as_varnames );
258             vlc_object_release( p_aout );
259         }
260         vlc_object_release( p_input );
261     }
262     vlc_object_release( p_playlist );
263     //CREATE_POPUP;
264 }
265
266 #if 0
267 /* Navigation stuff, and general */
268 static void MiscPopupMenu( intf_thread_t *p_intf, const QPoint &pos )
269 {
270     POPUP_BOILERPLATE;
271     if( p_input )
272     {
273         vlc_object_yield( p_input );
274         as_varnames.push_back( "audio-es" );
275         InputAutoMenuBuilder( VLC_OBJECT(p_input), ai_objects, as_varnames );
276         PUSH_SEPARATOR;
277     }
278     IntfAutoMenuBuilder( p_intf, ai_objects, as_varnames, true );
279
280     Menu popupmenu( p_intf, PopupMenu_Events );
281     popupmenu.Populate( as_varnames, ai_objects );
282
283     POPUP_STATIC_ENTRIES;
284     popupmenu.Append( MenuDummy_Event, wxU(_("Open")),
285                       OpenStreamMenu( p_intf ), wxT("") );
286
287     p_intf->p_sys->p_popup_menu = &popupmenu;
288     p_parent->PopupMenu( &popupmenu, pos.x, pos.y );
289     p_intf->p_sys->p_popup_menu = NULL;
290     vlc_object_release( p_playlist );
291 }
292
293 void PopupMenu( intf_thread_t *p_intf, wxWindow *p_parent,
294                 const wxPoint& pos )
295 {
296     POPUP_BOILERPLATE;
297     if( p_input )
298     {
299         vlc_object_yield( p_input );
300         InputAutoMenuBuilder( VLC_OBJECT(p_input), ai_objects, as_varnames );
301
302         /* Video menu */
303         PUSH_SEPARATOR;
304         as_varnames.push_back( "video-es" );
305         ai_objects.push_back( p_input->i_object_id );
306         as_varnames.push_back( "spu-es" );
307         ai_objects.push_back( p_input->i_object_id );
308         vlc_object_t *p_vout = (vlc_object_t *)vlc_object_find( p_input,
309                                                 VLC_OBJECT_VOUT, FIND_CHILD );
310         if( p_vout )
311         {
312             VideoAutoMenuBuilder( p_vout, ai_objects, as_varnames );
313             vlc_object_release( p_vout );
314         }
315         /* Audio menu */
316         PUSH_SEPARATOR
317         as_varnames.push_back( "audio-es" );
318         ai_objects.push_back( p_input->i_object_id );
319         vlc_object_t *p_aout = (vlc_object_t *)vlc_object_find( p_input,
320                                              VLC_OBJECT_AOUT, FIND_ANYWHERE );
321         if( p_aout )
322         {
323             AudioAutoMenuBuilder( p_aout, ai_objects, as_varnames );
324             vlc_object_release( p_aout );
325         }
326     }
327
328     /* Interface menu */
329     PUSH_SEPARATOR
330     IntfAutoMenuBuilder( p_intf, ai_objects, as_varnames, true );
331
332     /* Build menu */
333     Menu popupmenu( p_intf, PopupMenu_Events );
334     popupmenu.Populate( as_varnames, ai_objects );
335     POPUP_STATIC_ENTRIES;
336
337         popupmenu.Append( MenuDummy_Event, wxU(_("Open")),
338                           OpenStreamMenu( p_intf ), wxT("") );
339     p_intf->p_sys->p_popup_menu = &popupmenu;
340     p_parent->PopupMenu( &popupmenu, pos.x, pos.y );
341     p_intf->p_sys->p_popup_menu = NULL;
342     vlc_object_release( p_playlist );
343 }
344 #endif
345
346 /*****************************************************************************
347  * Auto menus
348  *****************************************************************************/
349 QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QMenu * current )
350 {
351     vector<int> ai_objects;
352     vector<const char *> as_varnames;
353
354     vlc_object_t *p_object = (vlc_object_t *)vlc_object_find( p_intf,
355                                         VLC_OBJECT_INPUT, FIND_ANYWHERE );
356     if( p_object != NULL )
357     {
358         PUSH_VAR( "audio-es" );
359         vlc_object_release( p_object );
360     }
361
362     p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_AOUT,
363                                                 FIND_ANYWHERE );
364     if( p_object )
365     {
366         AudioAutoMenuBuilder( p_object, ai_objects, as_varnames );
367         vlc_object_release( p_object );
368     }
369     return Populate( p_intf, current, as_varnames, ai_objects );
370 }
371
372
373 QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current )
374 {
375     vlc_object_t *p_object;
376     vector<int> ai_objects;
377     vector<const char *> as_varnames;
378
379     p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
380                                                 FIND_ANYWHERE );
381     if( p_object != NULL )
382     {
383         PUSH_VAR( "video-es" );
384         PUSH_VAR( "spu-es" );
385         vlc_object_release( p_object );
386     }
387
388     p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT,
389                                                 FIND_ANYWHERE );
390     if( p_object != NULL )
391     {
392         VideoAutoMenuBuilder( p_object, ai_objects, as_varnames );
393         vlc_object_release( p_object );
394     }
395     return Populate( p_intf, current, as_varnames, ai_objects );
396 }
397
398 QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *current )
399 {
400     vlc_object_t *p_object;
401     vector<int> ai_objects;
402     vector<const char *> as_varnames;
403
404     p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
405                                                 FIND_ANYWHERE );
406     if( p_object != NULL )
407     {
408         InputAutoMenuBuilder( p_object, ai_objects, as_varnames );
409         PUSH_VAR( "prev-title"); PUSH_VAR ( "next-title" );
410         PUSH_VAR( "prev-chapter"); PUSH_VAR( "next-chapter" );
411         vlc_object_release( p_object );
412     }
413     return Populate( p_intf, current, as_varnames, ai_objects );
414 }
415 #if 0
416 wxMenu *SettingsMenu( intf_thread_t *_p_intf, wxWindow *p_parent,
417                       wxMenu *p_menu )
418 {
419     vlc_object_t *p_object;
420     vector<int> ai_objects;
421     vector<const char *> as_varnames;
422
423     p_object = (vlc_object_t *)vlc_object_find( _p_intf, VLC_OBJECT_INTF,
424                                                 FIND_PARENT );
425     if( p_object != NULL )
426     {
427         PUSH_VAR( "intf-switch" );
428         PUSH_VAR( "intf-add" );
429         vlc_object_release( p_object );
430     }
431
432     /* Build menu */
433     Menu *p_vlc_menu = (Menu *)p_menu;
434     if( !p_vlc_menu )
435         p_vlc_menu = new Menu( _p_intf, SettingsMenu_Events );
436     else
437         p_vlc_menu->Clear();
438
439     p_vlc_menu->Populate( as_varnames, ai_objects );
440
441     return p_vlc_menu;
442 }
443 #endif
444
445 QMenu * QVLCMenu::Populate( intf_thread_t *p_intf, QMenu *current,
446                             vector< const char *> & ras_varnames,
447                             vector<int> & rai_objects )
448 {
449     QMenu *menu = current;
450     if( !menu )
451         menu = new QMenu();
452     else
453         menu->clear();
454
455     currentGroup = NULL;
456
457     vlc_object_t *p_object;
458     vlc_bool_t b_section_empty = VLC_FALSE;
459     int i;
460
461 #define APPEND_EMPTY { QAction *action = menu->addAction( _("Empty" ) ); \
462                        action->setEnabled( false ); }
463
464     for( i = 0; i < (int)rai_objects.size() ; i++ )
465     {
466         if( !ras_varnames[i] || !*ras_varnames[i] )
467         {
468             if( b_section_empty )
469                 APPEND_EMPTY;
470             menu->addSeparator();
471             b_section_empty = VLC_TRUE;
472             continue;
473         }
474
475         if( rai_objects[i] == 0  )
476         {
477             /// \bug What is this ?
478             // Append( menu, ras_varnames[i], NULL );
479             b_section_empty = VLC_FALSE;
480             continue;
481         }
482
483         p_object = (vlc_object_t *)vlc_object_get( p_intf,
484                                                    rai_objects[i] );
485         if( p_object == NULL ) continue;
486
487         b_section_empty = VLC_FALSE;
488         CreateItem( menu, ras_varnames[i], p_object );
489         vlc_object_release( p_object );
490     }
491
492     /* Special case for empty menus */
493     if( menu->actions().size() == 0 || b_section_empty )
494         APPEND_EMPTY
495
496     return menu;
497 }
498
499 /*****************************************************************************
500  * Private methods.
501  *****************************************************************************/
502
503 #define FREE(x) if(x) { free(x);x=NULL;}
504
505 static bool IsMenuEmpty( const char *psz_var, vlc_object_t *p_object,
506                          bool b_root = TRUE )
507 {
508     vlc_value_t val, val_list;
509     int i_type, i_result, i;
510
511     /* Check the type of the object variable */
512     i_type = var_Type( p_object, psz_var );
513
514     /* Check if we want to display the variable */
515     if( !(i_type & VLC_VAR_HASCHOICE) ) return FALSE;
516
517     var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );
518     if( val.i_int == 0 ) return TRUE;
519
520     if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE )
521     {
522         /* Very evil hack ! intf-switch can have only one value */ 
523         if( !strcmp( psz_var, "intf-switch" ) ) return FALSE;
524         if( val.i_int == 1 && b_root ) return TRUE;
525         else return FALSE;
526     }
527
528     /* Check children variables in case of VLC_VAR_VARIABLE */
529     if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )
530     {
531         return TRUE;
532     }
533
534     for( i = 0, i_result = TRUE; i < val_list.p_list->i_count; i++ )
535     {
536         if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,
537                           p_object, FALSE ) )
538         {
539             i_result = FALSE;
540             break;
541         }
542     }
543
544     /* clean up everything */
545     var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, NULL );
546
547     return i_result;
548 }
549
550 void QVLCMenu::CreateItem( QMenu *menu, const char *psz_var,
551                            vlc_object_t *p_object )
552 {
553     QAction *action;
554     vlc_value_t val, text;
555     int i_type;
556
557     /* Check the type of the object variable */
558     i_type = var_Type( p_object, psz_var );
559
560     switch( i_type & VLC_VAR_TYPE )
561     {
562     case VLC_VAR_VOID:
563     case VLC_VAR_BOOL:
564     case VLC_VAR_VARIABLE:
565     case VLC_VAR_STRING:
566     case VLC_VAR_INTEGER:
567     case VLC_VAR_FLOAT:
568         break;
569     default:
570         /* Variable doesn't exist or isn't handled */
571         return;
572     }
573
574     /* Make sure we want to display the variable */
575     if( IsMenuEmpty( psz_var, p_object ) )  return;
576
577     /* Get the descriptive name of the variable */
578     var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );
579
580     if( i_type & VLC_VAR_HASCHOICE )
581     {
582         /* Append choices menu */
583         QMenu *submenu = CreateChoicesMenu( psz_var, p_object, true );
584         submenu->setTitle( text.psz_string ? text.psz_string : psz_var );
585         menu->addMenu( submenu );
586         FREE( text.psz_string );
587         return;
588     }
589
590 #define TEXT_OR_VAR text.psz_string ? text.psz_string : psz_var
591
592     switch( i_type & VLC_VAR_TYPE )
593     {
594     case VLC_VAR_VOID:
595         var_Get( p_object, psz_var, &val );
596         CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_NORMAL,
597                           p_object->i_object_id, val, i_type );
598         break;
599
600     case VLC_VAR_BOOL:
601         var_Get( p_object, psz_var, &val );
602         val.b_bool = !val.b_bool;
603         CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_CHECK,
604                           p_object->i_object_id, val, i_type, val.b_bool );
605         break;
606     }
607     FREE( text.psz_string );
608 }
609
610
611 QMenu *QVLCMenu::CreateChoicesMenu( const char *psz_var, 
612                                     vlc_object_t *p_object, bool b_root )
613 {
614     vlc_value_t val, val_list, text_list;
615     int i_type, i;
616
617     /* Check the type of the object variable */
618     i_type = var_Type( p_object, psz_var );
619
620     /* Make sure we want to display the variable */
621     if( IsMenuEmpty( psz_var, p_object, b_root ) ) return NULL;
622
623     switch( i_type & VLC_VAR_TYPE )
624     {
625     case VLC_VAR_VOID:
626     case VLC_VAR_BOOL:
627     case VLC_VAR_VARIABLE:
628     case VLC_VAR_STRING:
629     case VLC_VAR_INTEGER:
630     case VLC_VAR_FLOAT:
631         break;
632     default:
633         /* Variable doesn't exist or isn't handled */
634         return NULL;
635     }
636
637     if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,
638                     &val_list, &text_list ) < 0 )
639     {
640         return NULL;
641     }
642 #define NORMAL_OR_RADIO i_type & VLC_VAR_ISCOMMAND ? ITEM_NORMAL: ITEM_RADIO
643 #define NOTCOMMAND !(i_type & VLC_VAR_ISCOMMAND) 
644 #define CURVAL val_list.p_list->p_values[i]
645 #define CURTEXT text_list.p_list->p_values[i].psz_string
646
647     QMenu *submenu = new QMenu();
648     for( i = 0; i < val_list.p_list->i_count; i++ )
649     {
650         vlc_value_t another_val;
651         QString menutext;
652         QMenu *subsubmenu;
653
654         switch( i_type & VLC_VAR_TYPE )
655         {
656         case VLC_VAR_VARIABLE:
657             subsubmenu = CreateChoicesMenu( CURVAL.psz_string,
658                                                    p_object, false );
659             subsubmenu->setTitle( CURTEXT ? CURTEXT : CURVAL.psz_string );
660             submenu->addMenu( subsubmenu );
661             break;
662
663         case VLC_VAR_STRING:
664           var_Get( p_object, psz_var, &val );
665           another_val.psz_string = strdup( CURVAL.psz_string );
666
667           menutext = CURTEXT ? CURTEXT : another_val.psz_string;
668           CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
669                             p_object->i_object_id, another_val, i_type, 
670                             NOTCOMMAND && val.psz_string &&
671                             !strcmp( val.psz_string, CURVAL.psz_string ) );
672
673           if( val.psz_string ) free( val.psz_string );
674           break;
675
676         case VLC_VAR_INTEGER:
677           var_Get( p_object, psz_var, &val );
678           if( CURTEXT ) menutext = CURTEXT; 
679           else menutext.sprintf( "%d", CURVAL.i_int);
680           CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
681                             p_object->i_object_id, CURVAL, i_type,
682                             NOTCOMMAND && CURVAL.i_int == val.i_int );
683           break;
684
685         case VLC_VAR_FLOAT:
686           var_Get( p_object, psz_var, &val );
687           if( CURTEXT ) menutext = CURTEXT ;
688           else menutext.sprintf( "%.2f", CURVAL.f_float );
689           CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,
690                             p_object->i_object_id, CURVAL, i_type,
691                             NOTCOMMAND && CURVAL.f_float == val.f_float );
692           break;
693
694         default:
695           break;
696         }
697     }
698
699     /* clean up everything */
700     var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
701
702 #undef NORMAL_OR_RADIO
703 #undef NOTCOMMAND
704 #undef CURVAL
705 #undef CURTEXT
706     return submenu;
707 }
708
709 void QVLCMenu::CreateAndConnect( QMenu *menu, const char *psz_var,
710                                  QString text, QString help,
711                                  int i_item_type, int i_object_id, 
712                                  vlc_value_t val, int i_val_type,
713                                  bool checked )
714 {
715     QAction *action = new QAction( text, menu );
716     action->setText( text );
717     action->setToolTip( help );
718
719     if( i_item_type == ITEM_CHECK )
720     {
721         action->setCheckable( true );
722         currentGroup = NULL;
723     }
724     else if( i_item_type == ITEM_RADIO )
725     {
726         action->setCheckable( true );
727         if( !currentGroup )
728             currentGroup = new QActionGroup(menu);
729         currentGroup->addAction( action );
730     }
731     else
732         currentGroup = NULL;
733     if( checked ) action->setChecked( true );
734
735     MenuItemData *itemData = new MenuItemData( i_object_id, i_val_type,
736                                                val, psz_var );
737     connect( action, SIGNAL(triggered()), THEDP->menusMapper, SLOT(map()) ); 
738     THEDP->menusMapper->setMapping( action, itemData );
739     
740     menu->addAction( action );
741 }
742
743 void QVLCMenu::DoAction( intf_thread_t *p_intf, QObject *data )
744 {
745     MenuItemData *itemData = qobject_cast<MenuItemData *>(data);
746     
747     vlc_object_t *p_object = (vlc_object_t *)vlc_object_get( p_intf,
748                                            itemData->i_object_id );
749     if( p_object == NULL ) return;
750
751     var_Set( p_object, itemData->psz_var, itemData->val );
752     vlc_object_release( p_object );
753 }
754
755
756 #if 0
757 void MenuEvtHandler::OnMenuEvent( wxCommandEvent& event )
758 {
759     wxMenuItem *p_menuitem = NULL;
760     int i_hotkey_event = p_intf->p_sys->i_first_hotkey_event;
761     int i_hotkeys = p_intf->p_sys->i_hotkeys;
762
763     if( event.GetId() >= Play_Event && event.GetId() <= Stop_Event )
764     {
765         input_thread_t *p_input;
766         playlist_t * p_playlist =
767             (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
768                                            FIND_ANYWHERE );
769         if( !p_playlist ) return;
770
771         switch( event.GetId() )
772         {
773         case Play_Event:
774         case Pause_Event:
775             p_input =
776                 (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
777                                                    FIND_ANYWHERE );
778             if( !p_input ) playlist_Play( p_playlist );
779             else
780             {
781                 vlc_value_t val;
782                 var_Get( p_input, "state", &val );
783                 if( val.i_int != PAUSE_S ) val.i_int = PAUSE_S;
784                 else val.i_int = PLAYING_S;
785                 var_Set( p_input, "state", val );
786                 vlc_object_release( p_input );
787             }
788             break;
789         case Stop_Event:
790             playlist_Stop( p_playlist );
791             break;
792         case Previous_Event:
793             playlist_Prev( p_playlist );
794             break;
795         case Next_Event:
796             playlist_Next( p_playlist );
797             break;
798         }
799
800         vlc_object_release( p_playlist );
801         return;
802     }
803
804     /* Check if this is an auto generated menu item */
805     if( event.GetId() < FirstAutoGenerated_Event )
806     {
807         event.Skip();
808         return;
809     }
810
811     /* Check if this is an hotkey event */
812     if( event.GetId() >= i_hotkey_event &&
813         event.GetId() < i_hotkey_event + i_hotkeys )
814     {
815         vlc_value_t val;
816
817         val.i_int =
818             p_intf->p_vlc->p_hotkeys[event.GetId() - i_hotkey_event].i_key;
819
820         /* Get the key combination and send it to the hotkey handler */
821         var_Set( p_intf->p_vlc, "key-pressed", val );
822         return;
823     }
824
825     if( !p_main_interface ||
826         (p_menuitem = p_main_interface->GetMenuBar()->FindItem(event.GetId()))
827         == NULL )
828     {
829         if( p_intf->p_sys->p_popup_menu )
830         {
831             p_menuitem =
832                 p_intf->p_sys->p_popup_menu->FindItem( event.GetId() );
833         }
834     }
835
836     if( p_menuitem )
837     {
838         wxMenuItemExt *p_menuitemext = (wxMenuItemExt *)p_menuitem;
839         vlc_object_t *p_object;
840
841         p_object = (vlc_object_t *)vlc_object_get( p_intf,
842                                        p_menuitemext->i_object_id );
843         if( p_object == NULL ) return;
844
845         wxMutexGuiLeave(); // We don't want deadlocks
846         var_Set( p_object, p_menuitemext->psz_var, p_menuitemext->val );
847         //wxMutexGuiEnter();
848
849         vlc_object_release( p_object );
850     }
851     else
852         event.Skip();
853 }
854 #endif