]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/preferences_widgets.cpp
* qt: add a FontConfigControl
[vlc] / modules / gui / qt4 / components / preferences_widgets.cpp
1 /*****************************************************************************
2  * preferences_widgets.cpp : Widgets for preferences displays
3  ****************************************************************************
4  * Copyright (C) 2006-2007 the VideoLAN team
5  * $Id$
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
8  *          Antoine Cellerier <dionoea@videolan.org>
9  *          Jean-Baptiste Kempf <jb@videolan.org>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24  *****************************************************************************/
25
26 /**
27  * Todo:
28  *  - Finish implementation (see WX)
29  *  - Improvements over WX
30  *      - Password field implementation (through "pwd" bool param
31  *      - Validator for modulelist
32  *  - Implement update stuff using a general Updated signal
33  */
34
35 #include "components/preferences_widgets.hpp"
36 #include "util/customwidgets.hpp"
37 #include "qt4.hpp"
38
39 #include <QLineEdit>
40 #include <QString>
41 #include <QSpinBox>
42 #include <QDoubleSpinBox>
43 #include <QVariant>
44 #include <QComboBox>
45 #include <QGridLayout>
46 #include <QPushButton>
47 #include <QSlider>
48 #include <QFileDialog>
49 #include <QFontDialog>
50
51 #include <vlc_keys.h>
52
53 ConfigControl *ConfigControl::createControl( vlc_object_t *p_this,
54                                              module_config_t *p_item,
55                                              QWidget *parent )
56 {
57     int i=0;
58     return createControl( p_this, p_item, parent, NULL, i );
59 }
60
61 ConfigControl *ConfigControl::createControl( vlc_object_t *p_this,
62                                              module_config_t *p_item,
63                                              QWidget *parent,
64                                              QGridLayout *l, int &line )
65 {
66     ConfigControl *p_control = NULL;
67     if( p_item->psz_current ) return NULL;
68
69     switch( p_item->i_type )
70     {
71     case CONFIG_ITEM_MODULE:
72         p_control = new ModuleConfigControl( p_this, p_item, parent, false,
73                                              l, line );
74         break;
75     case CONFIG_ITEM_MODULE_CAT:
76         p_control = new ModuleConfigControl( p_this, p_item, parent, true,
77                                              l, line );
78         break;
79     case CONFIG_ITEM_MODULE_LIST:
80         p_control = new ModuleListConfigControl( p_this, p_item, parent, false,
81                                              l, line );
82         break;
83     case CONFIG_ITEM_MODULE_LIST_CAT:
84         p_control = new ModuleListConfigControl( p_this, p_item, parent, true,
85                                              l, line );
86         break;
87     case CONFIG_ITEM_STRING:
88         if( !p_item->i_list )
89             p_control = new StringConfigControl( p_this, p_item, parent,
90                                                  l, line, false );
91         else
92             p_control = new StringListConfigControl( p_this, p_item,
93                                             parent, false, l, line );
94         break;
95     case CONFIG_ITEM_INTEGER:
96         if( p_item->i_list )
97             p_control = new IntegerListConfigControl( p_this, p_item,
98                                             parent, false, l, line );
99         else if( p_item->min.i || p_item->max.i )
100             p_control = new IntegerRangeConfigControl( p_this, p_item, parent,
101                                                        l, line );
102         else
103             p_control = new IntegerConfigControl( p_this, p_item, parent,
104                                                   l, line );
105         break;
106     case CONFIG_ITEM_FILE:
107         p_control = new FileConfigControl( p_this, p_item, parent, l,
108                                                 line, false );
109         break;
110     case CONFIG_ITEM_DIRECTORY:
111         p_control = new DirectoryConfigControl( p_this, p_item, parent, l,
112                                                 line, false );
113         break;
114     case CONFIG_ITEM_FONT:
115         p_control = new FontConfigControl( p_this, p_item, parent, l,
116                                            line, false );
117         break;
118     case CONFIG_ITEM_KEY:
119         p_control = new KeySelectorControl( p_this, p_item, parent, l, line );
120         break;
121     case CONFIG_ITEM_BOOL:
122         p_control = new BoolConfigControl( p_this, p_item, parent, l, line );
123         break;
124     case CONFIG_ITEM_FLOAT:
125         if( p_item->min.f || p_item->max.f )
126             p_control = new FloatRangeConfigControl( p_this, p_item, parent,
127                                                      l, line );
128         else
129             p_control = new FloatConfigControl( p_this, p_item, parent,
130                                                   l, line );
131         break;
132     default:
133         break;
134     }
135     return p_control;
136 }
137
138 void ConfigControl::doApply( intf_thread_t *p_intf )
139 {
140     switch( getType() )
141     {
142         case 1:
143         {
144             VIntConfigControl *vicc = qobject_cast<VIntConfigControl *>(this);
145             assert( vicc );
146             config_PutInt( p_intf, vicc->getName(), vicc->getValue() );
147             break;
148         }
149         case 2:
150         {
151             VFloatConfigControl *vfcc =
152                                     qobject_cast<VFloatConfigControl *>(this);
153             assert( vfcc );
154             config_PutFloat( p_intf, vfcc->getName(), vfcc->getValue() );
155             break;
156         }
157         case 3:
158         {
159             VStringConfigControl *vscc =
160                             qobject_cast<VStringConfigControl *>(this);
161             assert( vscc );
162             config_PutPsz( p_intf, vscc->getName(), qta( vscc->getValue() ) );
163             break;
164         }
165         case 4:
166         {
167             KeySelectorControl *ksc = qobject_cast<KeySelectorControl *>(this);
168             assert( ksc );
169             ksc->doApply();
170         }
171     }
172 }
173
174 /**************************************************************************
175  * String-based controls
176  *************************************************************************/
177
178 /*********** String **************/
179 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
180                                           module_config_t *_p_item,
181                                           QWidget *_parent, QGridLayout *l,
182                                           int &line, bool pwd ) :
183                            VStringConfigControl( _p_this, _p_item, _parent )
184 {
185     label = new QLabel( qfu(p_item->psz_text) );
186     text = new QLineEdit( qfu(p_item->value.psz) );
187     finish();
188
189     if( !l )
190     {
191         QHBoxLayout *layout = new QHBoxLayout();
192         layout->addWidget( label, 0 ); layout->addWidget( text, 1 );
193         widget->setLayout( layout );
194     }
195     else
196     {
197         l->addWidget( label, line, 0 ); l->addWidget( text, line, 1 );
198     }
199 }
200
201 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
202                                    module_config_t *_p_item,
203                                    QLabel *_label, QLineEdit *_text, bool pwd ):
204                            VStringConfigControl( _p_this, _p_item )
205 {
206     text = _text;
207     label = _label;
208     finish( );
209 }
210
211 void StringConfigControl::finish()
212 {
213     text->setText( qfu(p_item->value.psz) );
214     text->setToolTip( qfu(p_item->psz_longtext) );
215     if( label )
216         label->setToolTip( qfu(p_item->psz_longtext) );
217 }
218
219 /*********** File **************/
220 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
221                                           module_config_t *_p_item,
222                                           QWidget *_parent, QGridLayout *l,
223                                           int &line, bool pwd ) :
224                            VStringConfigControl( _p_this, _p_item, _parent )
225 {
226     label = new QLabel( qfu(p_item->psz_text) );
227     text = new QLineEdit( qfu(p_item->value.psz) );
228     browse = new QPushButton( qtr( "Browse" ) );
229
230     BUTTONACT( browse, updateField() );
231
232     finish();
233
234     if( !l )
235     {
236         QHBoxLayout *layout = new QHBoxLayout();
237         layout->addWidget( label, 0 ); layout->addWidget( text, 1 );
238         layout->addWidget( browse, 2 );
239         widget->setLayout( layout );
240     }
241     else
242     {
243         l->addWidget( label, line, 0 ); l->addWidget( text, line, 1 );
244         l->addWidget( browse, line, 2 );
245     }
246 }
247
248
249 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
250                                    module_config_t *_p_item,
251                                    QLabel *_label, QLineEdit *_text,
252                                    QPushButton *_button, bool pwd ):
253                            VStringConfigControl( _p_this, _p_item )
254 {
255     browse = _button;
256     text = _text;
257     label = _label;
258
259     BUTTONACT( browse, updateField() );
260
261     finish( );
262 }
263
264 void FileConfigControl::updateField()
265 {
266     QString file = QFileDialog::getOpenFileName( NULL,
267                   qtr( "Select File" ), qfu( p_this->p_libvlc->psz_homedir ) );
268     if( file.isNull() ) return;
269     text->setText( file );
270 }
271
272 void FileConfigControl::finish()
273 {
274     text->setText( qfu(p_item->value.psz) );
275     text->setToolTip( qfu(p_item->psz_longtext) );
276     if( label )
277         label->setToolTip( qfu(p_item->psz_longtext) );
278 }
279
280 /********* String / Directory **********/
281 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
282                         module_config_t *_p_item, QWidget *_p_widget,
283                         QGridLayout *_p_layout, int& _int, bool _pwd ) :
284      FileConfigControl( _p_this, _p_item, _p_widget, _p_layout, _int, _pwd)
285 {}
286
287 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
288                         module_config_t *_p_item, QLabel *_p_label,
289                         QLineEdit *_p_line, QPushButton *_p_button, bool _pwd ):
290      FileConfigControl( _p_this, _p_item, _p_label, _p_line, _p_button, _pwd)
291 {}
292
293 void DirectoryConfigControl::updateField()
294 {
295     QString dir = QFileDialog::getExistingDirectory( NULL,
296                       qtr( "Select Directory" ),
297                       qfu( p_this->p_libvlc->psz_homedir ),
298                       QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks );
299     if( dir.isNull() ) return;
300     text->setText( dir );
301 }
302
303 /********* String / Font **********/
304 FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
305                         module_config_t *_p_item, QWidget *_p_widget,
306                         QGridLayout *_p_layout, int& _int, bool _pwd ) :
307      FileConfigControl( _p_this, _p_item, _p_widget, _p_layout, _int, _pwd)
308 {}
309
310 FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
311                         module_config_t *_p_item, QLabel *_p_label,
312                         QLineEdit *_p_line, QPushButton *_p_button, bool _pwd ):
313      FileConfigControl( _p_this, _p_item, _p_label, _p_line, _p_button, _pwd)
314 {}
315
316 void FontConfigControl::updateField()
317 {
318     bool ok;
319     QFont font = QFontDialog::getFont( &ok, QFont( text->text() ), NULL );
320     if( !ok ) return;
321     text->setText( font.family() );
322 }
323
324 /********* String / choice list **********/
325 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
326                module_config_t *_p_item, QWidget *_parent, bool bycat,
327                QGridLayout *l, int &line) :
328                VStringConfigControl( _p_this, _p_item, _parent )
329 {
330     label = new QLabel( qfu(p_item->psz_text) );
331     combo = new QComboBox();
332     finish( bycat );
333     if( !l )
334     {
335         QHBoxLayout *layout = new QHBoxLayout();
336         layout->addWidget( label ); layout->addWidget( combo );
337         widget->setLayout( layout );
338     }
339     else
340     {
341         l->addWidget( label, line, 0 );
342         l->addWidget( combo, line, 1, Qt::AlignRight );
343     }
344 }
345 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
346                 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
347                 bool bycat ) : VStringConfigControl( _p_this, _p_item )
348 {
349     combo = _combo;
350     label = _label;
351     finish( bycat );
352 }
353
354 void StringListConfigControl::finish( bool bycat )
355 {
356     combo->setEditable( false );
357
358     for( int i_index = 0; i_index < p_item->i_list; i_index++ )
359     {
360         combo->addItem( qfu(p_item->ppsz_list_text ?
361                             p_item->ppsz_list_text[i_index] :
362                             p_item->ppsz_list[i_index] ),
363                         QVariant( p_item->ppsz_list[i_index] ) );
364         if( p_item->value.psz && !strcmp( p_item->value.psz,
365                                           p_item->ppsz_list[i_index] ) )
366             combo->setCurrentIndex( combo->count() - 1 );
367     }
368     combo->setToolTip( qfu(p_item->psz_longtext) );
369     if( label )
370         label->setToolTip( qfu(p_item->psz_longtext) );
371 }
372
373 QString StringListConfigControl::getValue()
374 {
375     return combo->itemData( combo->currentIndex() ).toString();
376 }
377
378 /********* Module **********/
379 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
380                module_config_t *_p_item, QWidget *_parent, bool bycat,
381                QGridLayout *l, int &line) :
382                VStringConfigControl( _p_this, _p_item, _parent )
383 {
384     label = new QLabel( qfu(p_item->psz_text) );
385     combo = new QComboBox();
386     finish( bycat );
387     if( !l )
388     {
389         QHBoxLayout *layout = new QHBoxLayout();
390         layout->addWidget( label ); layout->addWidget( combo );
391         widget->setLayout( layout );
392     }
393     else
394     {
395         l->addWidget( label, line, 0 );
396         l->addWidget( combo, line, 1, Qt::AlignRight );
397     }
398 }
399 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
400                 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
401                 bool bycat ) : VStringConfigControl( _p_this, _p_item )
402 {
403     combo = _combo;
404     label = _label;
405     finish( bycat );
406 }
407
408 void ModuleConfigControl::finish( bool bycat )
409 {
410     vlc_list_t *p_list;
411     module_t *p_parser;
412
413     combo->setEditable( false );
414
415     /* build a list of available modules */
416     p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
417     combo->addItem( qtr("Default") );
418     for( int i_index = 0; i_index < p_list->i_count; i_index++ )
419     {
420         p_parser = (module_t *)p_list->p_values[i_index].p_object ;
421
422         if( bycat )
423         {
424             if( !strcmp( p_parser->psz_object_name, "main" ) ) continue;
425
426             for (size_t i = 0; i < p_parser->confsize; i++)
427             {
428                 module_config_t *p_config = p_parser->p_config + i;
429                 /* Hack: required subcategory is stored in i_min */
430                 if( p_config->i_type == CONFIG_SUBCATEGORY &&
431                     p_config->value.i == p_item->min.i )
432                     combo->addItem( qfu(p_parser->psz_longname),
433                                     QVariant( p_parser->psz_object_name ) );
434                 if( p_item->value.psz && !strcmp( p_item->value.psz,
435                                                   p_parser->psz_object_name) )
436                     combo->setCurrentIndex( combo->count() - 1 );
437             }
438         }
439         else if( !strcmp( p_parser->psz_capability, p_item->psz_type ) )
440         {
441             combo->addItem( qfu(p_parser->psz_longname),
442                             QVariant( p_parser->psz_object_name ) );
443             if( p_item->value.psz && !strcmp( p_item->value.psz,
444                                               p_parser->psz_object_name) )
445                 combo->setCurrentIndex( combo->count() - 1 );
446         }
447     }
448     vlc_list_release( p_list );
449     combo->setToolTip( qfu(p_item->psz_longtext) );
450     if( label )
451         label->setToolTip( qfu(p_item->psz_longtext) );
452 }
453
454 QString ModuleConfigControl::getValue()
455 {
456     return combo->itemData( combo->currentIndex() ).toString();
457 }
458
459 /********* Module list **********/
460 ModuleListConfigControl::ModuleListConfigControl( vlc_object_t *_p_this,
461                module_config_t *_p_item, QWidget *_parent, bool bycat,
462                QGridLayout *l, int &line) :
463                VStringConfigControl( _p_this, _p_item, _parent )
464 {
465     label = new QLabel( qfu(p_item->psz_text) );
466     text = new QLineEdit();
467     finish( bycat );
468
469     bool pom = false;
470     if( !l )
471     {
472         l = new QGridLayout();
473         line = 0;
474         pom = true;
475     }
476     for( QVector<QCheckBox*>::iterator it = modules.begin();
477          it != modules.end(); it++ )
478     {
479         l->addWidget( *it, line++, 1 );
480     }
481     l->addWidget( label, line, 0 );
482     l->addWidget( text, line, 1 );
483     if( pom )
484         widget->setLayout( l );
485 }
486 #if 0
487 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
488                 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
489                 bool bycat ) : VStringConfigControl( _p_this, _p_item )
490 {
491     combo = _combo;
492     label = _label;
493     finish( bycat );
494 }
495 #endif
496
497 ModuleListConfigControl::~ModuleListConfigControl()
498 {
499     for( QVector<QCheckBox*>::iterator it = modules.begin();
500          it != modules.end(); it++ )
501     {
502         delete *it;
503     }
504     delete label;
505     delete text;
506 }
507
508 void ModuleListConfigControl::finish( bool bycat )
509 {
510     vlc_list_t *p_list;
511     module_t *p_parser;
512
513     /* build a list of available modules */
514     p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
515     for( int i_index = 0; i_index < p_list->i_count; i_index++ )
516     {
517         p_parser = (module_t *)p_list->p_values[i_index].p_object ;
518
519         if( bycat )
520         {
521             if( !strcmp( p_parser->psz_object_name, "main" ) ) continue;
522
523             for (size_t i = 0; i < p_parser->confsize; i++)
524             {
525                 module_config_t *p_config = p_parser->p_config + i;
526                 /* Hack: required subcategory is stored in i_min */
527                 if( p_config->i_type == CONFIG_SUBCATEGORY &&
528                     p_config->value.i == p_item->min.i )
529                 {
530                     QCheckBox *cb =
531                         new QCheckBox( qfu( p_parser->psz_object_name ) );
532                     cb->setToolTip( qfu(p_parser->psz_longname) );
533                     modules.push_back( cb );
534                 }
535             }
536         }
537         else if( !strcmp( p_parser->psz_capability, p_item->psz_type ) )
538         {
539             QCheckBox *cb =
540                 new QCheckBox( qfu( p_parser->psz_object_name ) );
541             cb->setToolTip( qfu(p_parser->psz_longname) );
542             modules.push_back( cb );
543         }
544     }
545     vlc_list_release( p_list );
546     text->setToolTip( qfu(p_item->psz_longtext) );
547     if( label )
548         label->setToolTip( qfu(p_item->psz_longtext) );
549 }
550
551 QString ModuleListConfigControl::getValue()
552 {
553     return text->text();
554 }
555
556 void ModuleListConfigControl::hide()
557 {
558     for( QVector<QCheckBox*>::iterator it = modules.begin();
559          it != modules.end(); it++ )
560     {
561         (*it)->hide();
562     }
563     text->hide();
564     label->hide();
565 }
566
567 void ModuleListConfigControl::show()
568 {
569     for( QVector<QCheckBox*>::iterator it = modules.begin();
570          it != modules.end(); it++ )
571     {
572         (*it)->show();
573     }
574     text->show();
575     label->show();
576 }
577
578
579 void ModuleListConfigControl::wakeUp_TheUserJustClickedOnSomething( int value )
580 {
581     text->clear();
582     for( QVector<QCheckBox*>::iterator it = modules.begin();
583          it != modules.end(); it++ )
584     {
585     }
586 }
587
588 /**************************************************************************
589  * Integer-based controls
590  *************************************************************************/
591
592 /*********** Integer **************/
593 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
594                                             module_config_t *_p_item,
595                                             QWidget *_parent, QGridLayout *l,
596                                             int &line ) :
597                            VIntConfigControl( _p_this, _p_item, _parent )
598 {
599     label = new QLabel( qfu(p_item->psz_text) );
600     spin = new QSpinBox; spin->setMinimumWidth( 80 );
601     spin->setMaximumWidth( 90 );
602     finish();
603
604     if( !l )
605     {
606         QHBoxLayout *layout = new QHBoxLayout();
607         layout->addWidget( label, 0 ); layout->addWidget( spin, 1 );
608         widget->setLayout( layout );
609     }
610     else
611     {
612         l->addWidget( label, line, 0 );
613         l->addWidget( spin, line, 1, Qt::AlignRight );
614     }
615 }
616 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
617                                             module_config_t *_p_item,
618                                             QLabel *_label, QSpinBox *_spin ) :
619                                       VIntConfigControl( _p_this, _p_item )
620 {
621     spin = _spin;
622     label = _label;
623     finish();
624 }
625
626 void IntegerConfigControl::finish()
627 {
628     spin->setMaximum( 2000000000 );
629     spin->setMinimum( -2000000000 );
630     spin->setValue( p_item->value.i );
631     spin->setToolTip( qfu(p_item->psz_longtext) );
632     if( label )
633         label->setToolTip( qfu(p_item->psz_longtext) );
634 }
635
636 int IntegerConfigControl::getValue()
637 {
638     return spin->value();
639 }
640
641 /********* Integer range **********/
642 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
643                                             module_config_t *_p_item,
644                                             QWidget *_parent, QGridLayout *l,
645                                             int &line ) :
646             IntegerConfigControl( _p_this, _p_item, _parent, l, line )
647 {
648     finish();
649 }
650
651 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
652                                             module_config_t *_p_item,
653                                             QLabel *_label, QSpinBox *_spin ) :
654             IntegerConfigControl( _p_this, _p_item, _label, _spin )
655 {
656     finish();
657 }
658
659 void IntegerRangeConfigControl::finish()
660 {
661     spin->setMaximum( p_item->max.i );
662     spin->setMinimum( p_item->min.i );
663 }
664
665 IntegerRangeSliderConfigControl::IntegerRangeSliderConfigControl(
666                                             vlc_object_t *_p_this,
667                                             module_config_t *_p_item,
668                                             QLabel *_label, QSlider *_slider ):
669                     VIntConfigControl( _p_this, _p_item )
670 {
671     slider = _slider;
672     label = _label;
673     slider->setMaximum( p_item->max.i );
674     slider->setMinimum( p_item->min.i );
675     slider->setValue( p_item->value.i );
676     slider->setToolTip( qfu(p_item->psz_longtext) );
677     if( label )
678         label->setToolTip( qfu(p_item->psz_longtext) );
679 }
680
681 int IntegerRangeSliderConfigControl::getValue()
682 {
683         return slider->value();
684 }
685
686
687 /********* Integer / choice list **********/
688 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
689                module_config_t *_p_item, QWidget *_parent, bool bycat,
690                QGridLayout *l, int &line) :
691                VIntConfigControl( _p_this, _p_item, _parent )
692 {
693     label = new QLabel( qfu(p_item->psz_text) );
694     combo = new QComboBox();
695     finish( bycat );
696     if( !l )
697     {
698         QHBoxLayout *layout = new QHBoxLayout();
699         layout->addWidget( label ); layout->addWidget( combo );
700         widget->setLayout( layout );
701     }
702     else
703     {
704         l->addWidget( label, line, 0 );
705         l->addWidget( combo, line, 1, Qt::AlignRight );
706     }
707 }
708 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
709                 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
710                 bool bycat ) : VIntConfigControl( _p_this, _p_item )
711 {
712     combo = _combo;
713     label = _label;
714     finish( bycat );
715 }
716
717 void IntegerListConfigControl::finish( bool bycat )
718 {
719     combo->setEditable( false );
720
721     for( int i_index = 0; i_index < p_item->i_list; i_index++ )
722     {
723         combo->addItem( qfu(p_item->ppsz_list_text[i_index] ),
724                         QVariant( p_item->pi_list[i_index] ) );
725         if( p_item->value.i == p_item->pi_list[i_index] )
726             combo->setCurrentIndex( combo->count() - 1 );
727     }
728     combo->setToolTip( qfu(p_item->psz_longtext) );
729     if( label )
730         label->setToolTip( qfu(p_item->psz_longtext) );
731 }
732
733 int IntegerListConfigControl::getValue()
734 {
735     return combo->itemData( combo->currentIndex() ).toInt();
736 }
737
738 /*********** Boolean **************/
739 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
740                                       module_config_t *_p_item,
741                                       QWidget *_parent, QGridLayout *l,
742                                       int &line ) :
743                     VIntConfigControl( _p_this, _p_item, _parent )
744 {
745     checkbox = new QCheckBox( qfu(p_item->psz_text) );
746     finish();
747
748     if( !l )
749     {
750         QHBoxLayout *layout = new QHBoxLayout();
751         layout->addWidget( checkbox, 0 );
752         widget->setLayout( layout );
753     }
754     else
755     {
756         l->addWidget( checkbox, line, 0 );
757     }
758 }
759 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
760                                       module_config_t *_p_item,
761                                       QLabel *_label,
762                                       QCheckBox *_checkbox,
763                                       bool bycat ) :
764                    VIntConfigControl( _p_this, _p_item )
765 {
766     checkbox = _checkbox;
767     finish();
768 }
769
770 void BoolConfigControl::finish()
771 {
772     checkbox->setCheckState( p_item->value.i == VLC_TRUE ? Qt::Checked
773                                                         : Qt::Unchecked );
774     checkbox->setToolTip( qfu(p_item->psz_longtext) );
775 }
776
777 int BoolConfigControl::getValue()
778 {
779     return checkbox->checkState() == Qt::Checked ? VLC_TRUE : VLC_FALSE;
780 }
781
782 /**************************************************************************
783  * Float-based controls
784  *************************************************************************/
785
786 /*********** Float **************/
787 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
788                                         module_config_t *_p_item,
789                                         QWidget *_parent, QGridLayout *l,
790                                         int &line ) :
791                     VFloatConfigControl( _p_this, _p_item, _parent )
792 {
793     label = new QLabel( qfu(p_item->psz_text) );
794     spin = new QDoubleSpinBox; spin->setMinimumWidth( 80 );
795     spin->setMaximumWidth( 90 );
796     finish();
797
798     if( !l )
799     {
800         QHBoxLayout *layout = new QHBoxLayout();
801         layout->addWidget( label, 0 ); layout->addWidget( spin, 1 );
802         widget->setLayout( layout );
803     }
804     else
805     {
806         l->addWidget( label, line, 0 );
807         l->addWidget( spin, line, 1, Qt::AlignRight );
808     }
809 }
810
811 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
812                                         module_config_t *_p_item,
813                                         QLabel *_label,
814                                         QDoubleSpinBox *_spin ) :
815                     VFloatConfigControl( _p_this, _p_item )
816 {
817     spin = _spin;
818     label = _label;
819     finish();
820 }
821
822 void FloatConfigControl::finish()
823 {
824     spin->setMaximum( 2000000000. );
825     spin->setMinimum( -2000000000. );
826     spin->setSingleStep( 0.1 );
827     spin->setValue( (double)p_item->value.f );
828     spin->setToolTip( qfu(p_item->psz_longtext) );
829     if( label )
830         label->setToolTip( qfu(p_item->psz_longtext) );
831 }
832
833 float FloatConfigControl::getValue()
834 {
835     return (float)spin->value();
836 }
837
838 /*********** Float with range **************/
839 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
840                                         module_config_t *_p_item,
841                                         QWidget *_parent, QGridLayout *l,
842                                         int &line ) :
843                 FloatConfigControl( _p_this, _p_item, _parent, l, line )
844 {
845     finish();
846 }
847
848 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
849                                         module_config_t *_p_item,
850                                         QLabel *_label,
851                                         QDoubleSpinBox *_spin ) :
852                 FloatConfigControl( _p_this, _p_item, _label, _spin )
853 {
854     finish();
855 }
856
857 void FloatRangeConfigControl::finish()
858 {
859     spin->setMaximum( (double)p_item->max.f );
860     spin->setMinimum( (double)p_item->min.f );
861 }
862
863
864 /**********************************************************************
865  * Key selector widget
866  **********************************************************************/
867 KeySelectorControl::KeySelectorControl( vlc_object_t *_p_this,
868                                       module_config_t *_p_item,
869                                       QWidget *_parent, QGridLayout *l,
870                                       int &line ) :
871                                 ConfigControl( _p_this, _p_item, _parent )
872
873 {
874     label = new QLabel( qtr("Select an action to change the associated hotkey") );
875     table = new QTreeWidget( 0 );
876     finish();
877
878     if( !l )
879     {
880         QVBoxLayout *layout = new QVBoxLayout();
881         layout->addWidget( label, 0 ); layout->addWidget( table, 1 );
882         widget->setLayout( layout );
883     }
884     else
885     {
886         l->addWidget( label, line, 0, 1, 2 );
887         l->addWidget( table, line+1, 0, 1,2 );
888     }
889 }
890
891 void KeySelectorControl::finish()
892 {
893     if( label )
894         label->setToolTip( qfu(p_item->psz_longtext) );
895
896     /* Fill the table */
897     table->setColumnCount( 2 );
898     table->setAlternatingRowColors( true );
899
900     module_t *p_main = config_FindModule( p_this, "main" );
901     assert( p_main );
902
903     for (size_t i = 0; i < p_main->confsize; i++)
904     {
905         module_config_t *p_item = p_main->p_config + i;
906
907         if( p_item->i_type & CONFIG_ITEM && p_item->psz_name &&
908             strstr( p_item->psz_name , "key-" ) )
909         {
910             QTreeWidgetItem *treeItem = new QTreeWidgetItem();
911             treeItem->setText( 0, qfu( p_item->psz_text ) );
912             treeItem->setText( 1, VLCKeyToString( p_item->value.i ) );
913             treeItem->setData( 0, Qt::UserRole,
914                                   QVariant::fromValue( (void*)p_item ) );
915             values += p_item;
916             table->addTopLevelItem( treeItem );
917         }
918     }
919     table->resizeColumnToContents( 0 );
920
921     CONNECT( table, itemDoubleClicked( QTreeWidgetItem *, int ),
922              this, selectKey( QTreeWidgetItem * ) );
923 }
924
925 void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem )
926 {
927    module_config_t *p_keyItem = static_cast<module_config_t*>
928                           (keyItem->data( 0, Qt::UserRole ).value<void*>());
929
930     KeyInputDialog *d = new KeyInputDialog( values, p_keyItem->psz_text );
931     d->exec();
932     if( d->result() == QDialog::Accepted )
933     {
934         p_keyItem->value.i = d->keyValue;
935         if( d->conflicts )
936         {
937             for( int i = 0; i < table->topLevelItemCount() ; i++ )
938             {
939                 QTreeWidgetItem *it = table->topLevelItem(i);
940                 module_config_t *p_item = static_cast<module_config_t*>
941                               (it->data( 0, Qt::UserRole ).value<void*>());
942                 it->setText( 1, VLCKeyToString( p_item->value.i ) );
943             }
944         }
945         else
946             keyItem->setText( 1, VLCKeyToString( p_keyItem->value.i ) );
947     }
948     delete d;
949 }
950
951 void KeySelectorControl::doApply()
952 {
953     foreach( module_config_t *p_current, values )
954     {
955         config_PutInt( p_this, p_current->psz_name, p_current->value.i );
956     }
957 }
958
959 KeyInputDialog::KeyInputDialog( QList<module_config_t*>& _values,
960                                 const char * _keyToChange ) :
961                                                 QDialog(0), keyValue(0)
962 {
963     setModal( true );
964     values = _values;
965     conflicts = false;
966     keyToChange = _keyToChange;
967     setWindowTitle( qtr( "Hotkey for " ) + qfu( keyToChange)  );
968
969     QVBoxLayout *l = new QVBoxLayout( this );
970     selected = new QLabel( qtr("Press the new keys for ")  + qfu(keyToChange) );
971     warning = new QLabel();
972     l->addWidget( selected , Qt::AlignCenter );
973     l->addWidget( warning, Qt::AlignCenter );
974
975     QHBoxLayout *l2 = new QHBoxLayout();
976     QPushButton *ok = new QPushButton( qtr("OK") );
977     l2->addWidget( ok );
978     QPushButton *cancel = new QPushButton( qtr("Cancel") );
979     l2->addWidget( cancel );
980
981     BUTTONACT( ok, accept() );
982     BUTTONACT( cancel, reject() );
983
984     l->addLayout( l2 );
985 }
986
987 void KeyInputDialog::keyPressEvent( QKeyEvent *e )
988 {
989     if( e->key() == Qt::Key_Tab ) return;
990     int i_vlck = qtEventToVLCKey( e );
991     selected->setText( VLCKeyToString( i_vlck ) );
992     conflicts = false;
993     module_config_t *p_current = NULL;
994     foreach( p_current, values )
995     {
996         if( p_current->value.i == i_vlck && strcmp( p_current->psz_text,
997                                                     keyToChange ) )
998         {
999             p_current->value.i = 0;
1000             conflicts = true;
1001             break;
1002         }
1003     }
1004     if( conflicts )
1005     {
1006         warning->setText(
1007           qtr("Warning: the  key is already assigned to \"") +
1008           QString( p_current->psz_text ) + "\"" );
1009     }
1010     else warning->setText( "" );
1011     keyValue = i_vlck;
1012 }