]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/preferences_widgets.cpp
Qt4 - Moving function from one file to another...
[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  *      - Validator for modulelist
31  *  - Implement update stuff using a general Updated signal
32  */
33
34 #include "components/preferences_widgets.hpp"
35 #include "util/customwidgets.hpp"
36
37 #include <vlc_keys.h>
38
39 #include <QString>
40 #include <QVariant>
41 #include <QGridLayout>
42 #include <QSlider>
43 #include <QFileDialog>
44 #include <QFontDialog>
45 #include <QGroupBox>
46 #include <QTreeWidgetItem>
47 #include <QSignalMapper>
48 QString formatTooltip(const QString & tooltip)
49 {
50     QString formatted =
51     "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">"
52     " p, li { white-space: pre-wrap; } </style></head><body style=\" font-family:'Sans Serif';"
53     " font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;\">"
54     "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; "
55     "-qt-block-indent:0; text-indent:0px;\">" +
56     tooltip +
57     "</p></body></html>";
58     return formatted;
59 }
60
61 ConfigControl *ConfigControl::createControl( vlc_object_t *p_this,
62                                              module_config_t *p_item,
63                                              QWidget *parent )
64 {
65     int i=0;
66     return createControl( p_this, p_item, parent, NULL, i );
67 }
68
69 ConfigControl *ConfigControl::createControl( vlc_object_t *p_this,
70                                              module_config_t *p_item,
71                                              QWidget *parent,
72                                              QGridLayout *l, int &line )
73 {
74     ConfigControl *p_control = NULL;
75     if( p_item->psz_current || p_item->b_unsaveable ) return NULL;
76
77     switch( p_item->i_type )
78     {
79     case CONFIG_ITEM_MODULE:
80         p_control = new ModuleConfigControl( p_this, p_item, parent, false,
81                                              l, line );
82         break;
83     case CONFIG_ITEM_MODULE_CAT:
84         p_control = new ModuleConfigControl( p_this, p_item, parent, true,
85                                              l, line );
86         break;
87     case CONFIG_ITEM_MODULE_LIST:
88         p_control = new ModuleListConfigControl( p_this, p_item, parent, false,
89                                              l, line );
90         break;
91     case CONFIG_ITEM_MODULE_LIST_CAT:
92         p_control = new ModuleListConfigControl( p_this, p_item, parent, true,
93                                              l, line );
94         break;
95     case CONFIG_ITEM_STRING:
96         if( !p_item->i_list )
97             p_control = new StringConfigControl( p_this, p_item, parent,
98                                                  l, line, false );
99         else
100             p_control = new StringListConfigControl( p_this, p_item,
101                                             parent, false, l, line );
102         break;
103     case CONFIG_ITEM_PASSWORD:
104         if( !p_item->i_list )
105             p_control = new StringConfigControl( p_this, p_item, parent,
106                                                  l, line, true );
107         else
108             p_control = new StringListConfigControl( p_this, p_item,
109                                             parent, true, l, line );
110         break;
111     case CONFIG_ITEM_INTEGER:
112         if( p_item->i_list )
113             p_control = new IntegerListConfigControl( p_this, p_item,
114                                             parent, false, l, line );
115         else if( p_item->min.i || p_item->max.i )
116             p_control = new IntegerRangeConfigControl( p_this, p_item, parent,
117                                                        l, line );
118         else
119             p_control = new IntegerConfigControl( p_this, p_item, parent,
120                                                   l, line );
121         break;
122     case CONFIG_ITEM_FILE:
123         p_control = new FileConfigControl( p_this, p_item, parent, l,
124                                                 line, false );
125         break;
126     case CONFIG_ITEM_DIRECTORY:
127         p_control = new DirectoryConfigControl( p_this, p_item, parent, l,
128                                                 line, false );
129         break;
130     case CONFIG_ITEM_FONT:
131         p_control = new FontConfigControl( p_this, p_item, parent, l,
132                                            line, false );
133         break;
134     case CONFIG_ITEM_KEY:
135         p_control = new KeySelectorControl( p_this, p_item, parent, l, line );
136         break;
137     case CONFIG_ITEM_BOOL:
138         p_control = new BoolConfigControl( p_this, p_item, parent, l, line );
139         break;
140     case CONFIG_ITEM_FLOAT:
141         if( p_item->min.f || p_item->max.f )
142             p_control = new FloatRangeConfigControl( p_this, p_item, parent,
143                                                      l, line );
144         else
145             p_control = new FloatConfigControl( p_this, p_item, parent,
146                                                   l, line );
147         break;
148     default:
149         break;
150     }
151     return p_control;
152 }
153
154 void ConfigControl::doApply( intf_thread_t *p_intf )
155 {
156     switch( getType() )
157     {
158         case 1:
159         {
160             VIntConfigControl *vicc = qobject_cast<VIntConfigControl *>(this);
161             assert( vicc );
162             config_PutInt( p_intf, vicc->getName(), vicc->getValue() );
163             break;
164         }
165         case 2:
166         {
167             VFloatConfigControl *vfcc =
168                                     qobject_cast<VFloatConfigControl *>(this);
169             assert( vfcc );
170             config_PutFloat( p_intf, vfcc->getName(), vfcc->getValue() );
171             break;
172         }
173         case 3:
174         {
175             VStringConfigControl *vscc =
176                             qobject_cast<VStringConfigControl *>(this);
177             assert( vscc );
178             config_PutPsz( p_intf, vscc->getName(), qta( vscc->getValue() ) );
179             break;
180         }
181         case 4:
182         {
183             KeySelectorControl *ksc = qobject_cast<KeySelectorControl *>(this);
184             assert( ksc );
185             ksc->doApply();
186         }
187     }
188 }
189
190 /**************************************************************************
191  * String-based controls
192  *************************************************************************/
193
194 /*********** String **************/
195 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
196                                           module_config_t *_p_item,
197                                           QWidget *_parent, QGridLayout *l,
198                                           int &line, bool pwd ) :
199                            VStringConfigControl( _p_this, _p_item, _parent )
200 {
201     label = new QLabel( qtr(p_item->psz_text) );
202     text = new QLineEdit( qfu(p_item->value.psz) );
203     if( pwd ) text->setEchoMode( QLineEdit::Password );
204     finish();
205
206     if( !l )
207     {
208         QHBoxLayout *layout = new QHBoxLayout();
209         layout->addWidget( label, 0 ); layout->addWidget( text, 1 );
210         widget->setLayout( layout );
211     }
212     else
213     {
214         l->addWidget( label, line, 0 ); l->addWidget( text, line, 1 );
215     }
216 }
217
218 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
219                                    module_config_t *_p_item,
220                                    QLabel *_label, QLineEdit *_text, bool pwd ):
221                            VStringConfigControl( _p_this, _p_item )
222 {
223     text = _text;
224     label = _label;
225     finish( );
226 }
227
228 void StringConfigControl::finish()
229 {
230     text->setText( qfu(p_item->value.psz) );
231     text->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
232     if( label )
233         label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
234 }
235
236 /*********** File **************/
237 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
238                                           module_config_t *_p_item,
239                                           QWidget *_parent, QGridLayout *l,
240                                           int &line, bool pwd ) :
241                            VStringConfigControl( _p_this, _p_item, _parent )
242 {
243     label = new QLabel( qtr(p_item->psz_text) );
244     text = new QLineEdit( qfu(p_item->value.psz) );
245     browse = new QPushButton( qtr( "Browse..." ) );
246     QHBoxLayout *textAndButton = new QHBoxLayout();
247     textAndButton->setMargin( 0 );
248     textAndButton->addWidget( text, 2 );
249     textAndButton->addWidget( browse, 0 );
250
251     BUTTONACT( browse, updateField() );
252
253     finish();
254
255     if( !l )
256     {
257         QHBoxLayout *layout = new QHBoxLayout();
258         layout->addWidget( label, 0 );
259         layout->addLayout( textAndButton, 1 );
260         widget->setLayout( layout );
261     }
262     else
263     {
264         l->addWidget( label, line, 0 );
265         l->addLayout( textAndButton, line, 1 );
266     }
267 }
268
269
270 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
271                                    module_config_t *_p_item,
272                                    QLabel *_label, QLineEdit *_text,
273                                    QPushButton *_button, bool pwd ):
274                            VStringConfigControl( _p_this, _p_item )
275 {
276     browse = _button;
277     text = _text;
278     label = _label;
279
280     BUTTONACT( browse, updateField() );
281
282     finish( );
283 }
284
285 void FileConfigControl::updateField()
286 {
287     QString file = QFileDialog::getOpenFileName( NULL,
288                   qtr( "Select File" ), qfu( p_this->p_libvlc->psz_homedir ) );
289     if( file.isNull() ) return;
290     text->setText( file );
291 }
292
293 void FileConfigControl::finish()
294 {
295     text->setText( qfu(p_item->value.psz) );
296     text->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
297     if( label )
298         label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
299 }
300
301 /********* String / Directory **********/
302 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
303                         module_config_t *_p_item, QWidget *_p_widget,
304                         QGridLayout *_p_layout, int& _int, bool _pwd ) :
305      FileConfigControl( _p_this, _p_item, _p_widget, _p_layout, _int, _pwd)
306 {}
307
308 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
309                         module_config_t *_p_item, QLabel *_p_label,
310                         QLineEdit *_p_line, QPushButton *_p_button, bool _pwd ):
311      FileConfigControl( _p_this, _p_item, _p_label, _p_line, _p_button, _pwd)
312 {}
313
314 void DirectoryConfigControl::updateField()
315 {
316     QString dir = QFileDialog::getExistingDirectory( NULL,
317                       qtr( "Select Directory" ),
318                       text->text().isEmpty() ?
319                         qfu( p_this->p_libvlc->psz_homedir ) : text->text(),
320                       QFileDialog::ShowDirsOnly |
321                         QFileDialog::DontResolveSymlinks );
322     if( dir.isNull() ) return;
323     text->setText( dir );
324 }
325
326 /********* String / Font **********/
327 FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
328                         module_config_t *_p_item, QWidget *_p_widget,
329                         QGridLayout *_p_layout, int& _int, bool _pwd ) :
330      FileConfigControl( _p_this, _p_item, _p_widget, _p_layout, _int, _pwd)
331 {}
332
333 FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
334                         module_config_t *_p_item, QLabel *_p_label,
335                         QLineEdit *_p_line, QPushButton *_p_button, bool _pwd ):
336      FileConfigControl( _p_this, _p_item, _p_label, _p_line, _p_button, _pwd)
337 {}
338
339 void FontConfigControl::updateField()
340 {
341     bool ok;
342     QFont font = QFontDialog::getFont( &ok, QFont( text->text() ), NULL );
343     if( !ok ) return;
344     text->setText( font.family() );
345 }
346
347 /********* String / choice list **********/
348 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
349                module_config_t *_p_item, QWidget *_parent, bool bycat,
350                QGridLayout *l, int &line) :
351                VStringConfigControl( _p_this, _p_item, _parent )
352 {
353     label = new QLabel( qtr(p_item->psz_text) );
354     combo = new QComboBox();
355     finish( bycat );
356     if( !l )
357     {
358         QHBoxLayout *layout = new QHBoxLayout();
359         layout->addWidget( label ); layout->addWidget( combo );
360         widget->setLayout( layout );
361     }
362     else
363     {
364         l->addWidget( label, line, 0 );
365         l->addWidget( combo, line, 1, Qt::AlignRight );
366     }
367
368     if( p_item->i_action )
369     {
370         QSignalMapper *signalMapper = new QSignalMapper(this);
371
372         /* Some stringLists like Capture listings have action associated */
373         for( int i = 0; i < p_item->i_action; i++ )
374         {
375             QPushButton *button =
376                 new QPushButton( qfu( p_item->ppsz_action_text[i] ));
377             CONNECT( button, clicked(), signalMapper, map() );
378             signalMapper->setMapping( button, i );
379             l->addWidget( button, line, 2 + i, Qt::AlignRight );
380         }
381         CONNECT( signalMapper, mapped( int ),
382                 this, actionRequested( int ) );
383     }
384 }
385
386 void StringListConfigControl::actionRequested( int i_action )
387 {
388     /* Supplementary check for boundaries */
389     if( i_action < 0 || i_action >= p_item->i_action ) return;
390
391     vlc_value_t val;
392     val.psz_string = qtu( (combo->itemData( combo->currentIndex() ).toString() ) );
393
394     p_item->ppf_action[i_action]( p_this, getName(), val, val, 0 );
395
396     if( p_item->b_dirty )
397     {
398         combo->clear();
399         finish( true );
400         p_item->b_dirty = VLC_FALSE;
401
402     }
403 }
404 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
405                 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
406                 bool bycat ) : VStringConfigControl( _p_this, _p_item )
407 {
408     combo = _combo;
409     label = _label;
410     finish( bycat );
411 }
412
413 void StringListConfigControl::finish( bool bycat )
414 {
415     combo->setEditable( false );
416
417     for( int i_index = 0; i_index < p_item->i_list; i_index++ )
418     {
419         combo->addItem( qfu(p_item->ppsz_list_text ?
420                             p_item->ppsz_list_text[i_index] :
421                             p_item->ppsz_list[i_index] ),
422                         QVariant( p_item->ppsz_list[i_index] ) );
423         if( p_item->value.psz && !strcmp( p_item->value.psz,
424                                           p_item->ppsz_list[i_index] ) )
425             combo->setCurrentIndex( combo->count() - 1 );
426     }
427     combo->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
428     if( label )
429         label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
430 }
431
432 QString StringListConfigControl::getValue()
433 {
434     return combo->itemData( combo->currentIndex() ).toString();
435 }
436
437
438 void setfillVLCConfigCombo( const char *configname, intf_thread_t *p_intf,
439                         QComboBox *combo, QWidget *parent )
440 {
441     module_config_t *p_config =
442                       config_FindConfig( VLC_OBJECT(p_intf), configname );
443     if( p_config )
444     {
445         for ( int i_index = 0; i_index < p_config->i_list; i_index++ )
446         {
447             combo->addItem( qfu( p_config->ppsz_list_text[i_index] ),
448                     QVariant( p_config->pi_list[i_index] ) );
449             if( p_config->value.i == p_config->pi_list[i_index] )
450             {
451                 combo->setCurrentIndex( i_index );
452             }
453         }
454         combo->setToolTip( qfu( p_config->psz_longtext ) );
455     }
456 }
457
458 /********* Module **********/
459 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
460                module_config_t *_p_item, QWidget *_parent, bool bycat,
461                QGridLayout *l, int &line) :
462                VStringConfigControl( _p_this, _p_item, _parent )
463 {
464     label = new QLabel( qtr(p_item->psz_text) );
465     combo = new QComboBox();
466     finish( bycat );
467     if( !l )
468     {
469         QHBoxLayout *layout = new QHBoxLayout();
470         layout->addWidget( label ); layout->addWidget( combo );
471         widget->setLayout( layout );
472     }
473     else
474     {
475         l->addWidget( label, line, 0 );
476         l->addWidget( combo, line, 1, Qt::AlignRight );
477     }
478 }
479
480 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
481                 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
482                 bool bycat ) : VStringConfigControl( _p_this, _p_item )
483 {
484     combo = _combo;
485     label = _label;
486     finish( bycat );
487 }
488
489 void ModuleConfigControl::finish( bool bycat )
490 {
491     vlc_list_t *p_list;
492     module_t *p_parser;
493
494     combo->setEditable( false );
495
496     /* build a list of available modules */
497     p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
498     combo->addItem( qtr("Default") );
499     for( int i_index = 0; i_index < p_list->i_count; i_index++ )
500     {
501         p_parser = (module_t *)p_list->p_values[i_index].p_object ;
502
503         if( bycat )
504         {
505             if( !strcmp( module_GetObjName( p_parser ), "main" ) ) continue;
506
507             for (size_t i = 0; i < p_parser->confsize; i++)
508             {
509                 module_config_t *p_config = p_parser->p_config + i;
510                 /* Hack: required subcategory is stored in i_min */
511                 if( p_config->i_type == CONFIG_SUBCATEGORY &&
512                     p_config->value.i == p_item->min.i )
513                     combo->addItem( qtr( module_GetLongName( p_parser )),
514                                     QVariant( module_GetObjName( p_parser ) ) );
515                 if( p_item->value.psz && !strcmp( p_item->value.psz,
516                                                   module_GetObjName( p_parser ) ) )
517                     combo->setCurrentIndex( combo->count() - 1 );
518             }
519         }
520         else if( module_IsCapable( p_parser, p_item->psz_type ) )
521         {
522             combo->addItem( qtr(module_GetLongName( p_parser ) ),
523                             QVariant( module_GetObjName( p_parser ) ) );
524             if( p_item->value.psz && !strcmp( p_item->value.psz,
525                                               module_GetObjName( p_parser ) ) )
526                 combo->setCurrentIndex( combo->count() - 1 );
527         }
528     }
529     vlc_list_release( p_list );
530     combo->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
531     if( label )
532         label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
533 }
534
535 QString ModuleConfigControl::getValue()
536 {
537     return combo->itemData( combo->currentIndex() ).toString();
538 }
539
540 /********* Module list **********/
541 ModuleListConfigControl::ModuleListConfigControl( vlc_object_t *_p_this,
542         module_config_t *_p_item, QWidget *_parent, bool bycat,
543         QGridLayout *l, int &line) :
544     VStringConfigControl( _p_this, _p_item, _parent )
545 {
546     groupBox = new QGroupBox ( qtr(p_item->psz_text) );
547     text = new QLineEdit();
548     QGridLayout *layoutGroupBox = new QGridLayout( groupBox );
549
550     finish( bycat );
551
552     int boxline = 0;
553     for( QVector<checkBoxListItem*>::iterator it = modules.begin();
554             it != modules.end(); it++ )
555     {
556         layoutGroupBox->addWidget( (*it)->checkBox, boxline++, 0 );
557     }
558     layoutGroupBox->addWidget( text, boxline, 0 );
559
560     if( !l )
561     {
562         QVBoxLayout *layout = new QVBoxLayout();
563         layout->addWidget( groupBox, line, 0 );
564         widget->setLayout( layout );
565     }
566     else
567     {
568         l->addWidget( groupBox, line, 0, 1, -1 );
569     }
570
571     text->setToolTip( formatTooltip( qtr( p_item->psz_longtext) ) );
572 }
573
574 ModuleListConfigControl::~ModuleListConfigControl()
575 {
576     for( QVector<checkBoxListItem*>::iterator it = modules.begin();
577             it != modules.end(); it++ )
578     {
579         delete *it;
580     }
581     delete groupBox;
582     delete text;
583 }
584
585 #define CHECKBOX_LISTS \
586 { \
587        QCheckBox *cb = new QCheckBox( qtr( module_GetLongName( p_parser ) ) );\
588        checkBoxListItem *cbl = new checkBoxListItem; \
589 \
590        CONNECT( cb, stateChanged( int ), this, onUpdate( int ) );\
591        cb->setToolTip( formatTooltip( qtr( module_GetLongName( p_parser ))));\
592        cbl->checkBox = cb; \
593 \
594        int i = -1; \
595        while( p_parser->pp_shortcuts[++i] != NULL); \
596        i--; \
597 \
598        cbl->psz_module = strdup( i>=0?p_parser->pp_shortcuts[i] \
599                                  : module_GetObjName( p_parser ) ); \
600        modules.push_back( cbl ); \
601 }
602
603
604 void ModuleListConfigControl::finish( bool bycat )
605 {
606     vlc_list_t *p_list;
607     module_t *p_parser;
608
609     /* build a list of available modules */
610     p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
611     for( int i_index = 0; i_index < p_list->i_count; i_index++ )
612     {
613         p_parser = (module_t *)p_list->p_values[i_index].p_object ;
614
615         if( bycat )
616         {
617             if( !strcmp( module_GetObjName( p_parser ), "main" ) ) continue;
618
619             for (size_t i = 0; i < p_parser->confsize; i++)
620             {
621                 module_config_t *p_config = p_parser->p_config + i;
622                 /* Hack: required subcategory is stored in i_min */
623                 if( p_config->i_type == CONFIG_SUBCATEGORY &&
624                         p_config->value.i == p_item->min.i )
625                 {
626                     CHECKBOX_LISTS;
627                 }
628             }
629         }
630         else if( module_IsCapable( p_parser, p_item->psz_type ) )
631         {
632             CHECKBOX_LISTS;
633         }
634     }
635     vlc_list_release( p_list );
636     text->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
637     if( groupBox )
638         groupBox->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
639 }
640 #undef CHECKBOX_LISTS
641
642 QString ModuleListConfigControl::getValue()
643 {
644     return text->text();
645 }
646
647 void ModuleListConfigControl::hide()
648 {
649     for( QVector<checkBoxListItem*>::iterator it = modules.begin();
650          it != modules.end(); it++ )
651     {
652         (*it)->checkBox->hide();
653     }
654     groupBox->hide();
655 }
656
657 void ModuleListConfigControl::show()
658 {
659     for( QVector<checkBoxListItem*>::iterator it = modules.begin();
660          it != modules.end(); it++ )
661     {
662         (*it)->checkBox->show();
663     }
664     groupBox->show();
665 }
666
667
668 void ModuleListConfigControl::onUpdate( int value )
669 {
670     text->clear();
671     bool first = true;
672
673     for( QVector<checkBoxListItem*>::iterator it = modules.begin();
674          it != modules.end(); it++ )
675     {
676         if( (*it)->checkBox->isChecked() )
677         {
678             if( first )
679             {
680                 text->setText( text->text() + (*it)->psz_module );
681                 first = false;
682             }
683             else
684             {
685                 text->setText( text->text() + ":" + (*it)->psz_module );
686             }
687         }
688     }
689     emit Updated();
690 }
691
692 /**************************************************************************
693  * Integer-based controls
694  *************************************************************************/
695
696 /*********** Integer **************/
697 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
698                                             module_config_t *_p_item,
699                                             QWidget *_parent, QGridLayout *l,
700                                             int &line ) :
701                            VIntConfigControl( _p_this, _p_item, _parent )
702 {
703     label = new QLabel( qtr(p_item->psz_text) );
704     spin = new QSpinBox; spin->setMinimumWidth( 80 );
705     spin->setAlignment( Qt::AlignRight );
706     spin->setMaximumWidth( 90 );
707     finish();
708
709     if( !l )
710     {
711         QHBoxLayout *layout = new QHBoxLayout();
712         layout->addWidget( label, 0 ); layout->addWidget( spin, 1 );
713         widget->setLayout( layout );
714     }
715     else
716     {
717         l->addWidget( label, line, 0 );
718         l->addWidget( spin, line, 1, Qt::AlignRight );
719     }
720 }
721 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
722                                             module_config_t *_p_item,
723                                             QLabel *_label, QSpinBox *_spin ) :
724                                       VIntConfigControl( _p_this, _p_item )
725 {
726     spin = _spin;
727     label = _label;
728     finish();
729 }
730
731 void IntegerConfigControl::finish()
732 {
733     spin->setMaximum( 2000000000 );
734     spin->setMinimum( -2000000000 );
735     spin->setValue( p_item->value.i );
736     spin->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
737     if( label )
738         label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
739 }
740
741 int IntegerConfigControl::getValue()
742 {
743     return spin->value();
744 }
745
746 /********* Integer range **********/
747 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
748                                             module_config_t *_p_item,
749                                             QWidget *_parent, QGridLayout *l,
750                                             int &line ) :
751             IntegerConfigControl( _p_this, _p_item, _parent, l, line )
752 {
753     finish();
754 }
755
756 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
757                                             module_config_t *_p_item,
758                                             QLabel *_label, QSpinBox *_spin ) :
759             IntegerConfigControl( _p_this, _p_item, _label, _spin )
760 {
761     finish();
762 }
763
764 void IntegerRangeConfigControl::finish()
765 {
766     spin->setMaximum( p_item->max.i );
767     spin->setMinimum( p_item->min.i );
768 }
769
770 IntegerRangeSliderConfigControl::IntegerRangeSliderConfigControl(
771                                             vlc_object_t *_p_this,
772                                             module_config_t *_p_item,
773                                             QLabel *_label, QSlider *_slider ):
774                     VIntConfigControl( _p_this, _p_item )
775 {
776     slider = _slider;
777     label = _label;
778     slider->setMaximum( p_item->max.i );
779     slider->setMinimum( p_item->min.i );
780     slider->setValue( p_item->value.i );
781     slider->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
782     if( label )
783         label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
784 }
785
786 int IntegerRangeSliderConfigControl::getValue()
787 {
788         return slider->value();
789 }
790
791
792 /********* Integer / choice list **********/
793 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
794                module_config_t *_p_item, QWidget *_parent, bool bycat,
795                QGridLayout *l, int &line) :
796                VIntConfigControl( _p_this, _p_item, _parent )
797 {
798     label = new QLabel( qtr(p_item->psz_text) );
799     combo = new QComboBox();
800     finish( bycat );
801     if( !l )
802     {
803         QHBoxLayout *layout = new QHBoxLayout();
804         layout->addWidget( label ); layout->addWidget( combo );
805         widget->setLayout( layout );
806     }
807     else
808     {
809         l->addWidget( label, line, 0 );
810         l->addWidget( combo, line, 1, Qt::AlignRight );
811     }
812 }
813 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
814                 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
815                 bool bycat ) : VIntConfigControl( _p_this, _p_item )
816 {
817     combo = _combo;
818     label = _label;
819     finish( bycat );
820 }
821
822 void IntegerListConfigControl::finish( bool bycat )
823 {
824     combo->setEditable( false );
825
826     for( int i_index = 0; i_index < p_item->i_list; i_index++ )
827     {
828         combo->addItem( qtr(p_item->ppsz_list_text[i_index] ),
829                         QVariant( p_item->pi_list[i_index] ) );
830         if( p_item->value.i == p_item->pi_list[i_index] )
831             combo->setCurrentIndex( combo->count() - 1 );
832     }
833     combo->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
834     if( label )
835         label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
836 }
837
838 int IntegerListConfigControl::getValue()
839 {
840     return combo->itemData( combo->currentIndex() ).toInt();
841 }
842
843 /*********** Boolean **************/
844 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
845                                       module_config_t *_p_item,
846                                       QWidget *_parent, QGridLayout *l,
847                                       int &line ) :
848                     VIntConfigControl( _p_this, _p_item, _parent )
849 {
850     checkbox = new QCheckBox( qtr(p_item->psz_text) );
851     finish();
852
853     if( !l )
854     {
855         QHBoxLayout *layout = new QHBoxLayout();
856         layout->addWidget( checkbox, 0 );
857         widget->setLayout( layout );
858     }
859     else
860     {
861         l->addWidget( checkbox, line, 0 );
862     }
863 }
864 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
865                                       module_config_t *_p_item,
866                                       QLabel *_label,
867                                       QCheckBox *_checkbox,
868                                       bool bycat ) :
869                    VIntConfigControl( _p_this, _p_item )
870 {
871     checkbox = _checkbox;
872     finish();
873 }
874
875 void BoolConfigControl::finish()
876 {
877     checkbox->setCheckState( p_item->value.i == VLC_TRUE ? Qt::Checked
878                                                         : Qt::Unchecked );
879     checkbox->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
880 }
881
882 int BoolConfigControl::getValue()
883 {
884     return checkbox->checkState() == Qt::Checked ? VLC_TRUE : VLC_FALSE;
885 }
886
887 /**************************************************************************
888  * Float-based controls
889  *************************************************************************/
890
891 /*********** Float **************/
892 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
893                                         module_config_t *_p_item,
894                                         QWidget *_parent, QGridLayout *l,
895                                         int &line ) :
896                     VFloatConfigControl( _p_this, _p_item, _parent )
897 {
898     label = new QLabel( qtr(p_item->psz_text) );
899     spin = new QDoubleSpinBox; spin->setMinimumWidth( 80 );
900     spin->setMaximumWidth( 90 );
901     spin->setAlignment( Qt::AlignRight );
902     finish();
903
904     if( !l )
905     {
906         QHBoxLayout *layout = new QHBoxLayout();
907         layout->addWidget( label, 0 ); layout->addWidget( spin, 1 );
908         widget->setLayout( layout );
909     }
910     else
911     {
912         l->addWidget( label, line, 0 );
913         l->addWidget( spin, line, 1, Qt::AlignRight );
914     }
915 }
916
917 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
918                                         module_config_t *_p_item,
919                                         QLabel *_label,
920                                         QDoubleSpinBox *_spin ) :
921                     VFloatConfigControl( _p_this, _p_item )
922 {
923     spin = _spin;
924     label = _label;
925     finish();
926 }
927
928 void FloatConfigControl::finish()
929 {
930     spin->setMaximum( 2000000000. );
931     spin->setMinimum( -2000000000. );
932     spin->setSingleStep( 0.1 );
933     spin->setValue( (double)p_item->value.f );
934     spin->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
935     if( label )
936         label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
937 }
938
939 float FloatConfigControl::getValue()
940 {
941     return (float)spin->value();
942 }
943
944 /*********** Float with range **************/
945 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
946                                         module_config_t *_p_item,
947                                         QWidget *_parent, QGridLayout *l,
948                                         int &line ) :
949                 FloatConfigControl( _p_this, _p_item, _parent, l, line )
950 {
951     finish();
952 }
953
954 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
955                                         module_config_t *_p_item,
956                                         QLabel *_label,
957                                         QDoubleSpinBox *_spin ) :
958                 FloatConfigControl( _p_this, _p_item, _label, _spin )
959 {
960     finish();
961 }
962
963 void FloatRangeConfigControl::finish()
964 {
965     spin->setMaximum( (double)p_item->max.f );
966     spin->setMinimum( (double)p_item->min.f );
967 }
968
969
970 /**********************************************************************
971  * Key selector widget
972  **********************************************************************/
973 KeySelectorControl::KeySelectorControl( vlc_object_t *_p_this,
974                                       module_config_t *_p_item,
975                                       QWidget *_parent, QGridLayout *l,
976                                       int &line ) :
977                                 ConfigControl( _p_this, _p_item, _parent )
978
979 {
980     label = new QLabel( qtr("Select an action to change the associated hotkey") );
981     table = new QTreeWidget( 0 );
982     finish();
983
984     if( !l )
985     {
986         QVBoxLayout *layout = new QVBoxLayout();
987         layout->addWidget( label, 0 ); layout->addWidget( table, 1 );
988         widget->setLayout( layout );
989     }
990     else
991     {
992         l->addWidget( label, line, 0, 1, 2 );
993         l->addWidget( table, line+1, 0, 1,2 );
994     }
995 }
996
997 void KeySelectorControl::finish()
998 {
999     if( label )
1000         label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
1001
1002     /* Fill the table */
1003     table->setColumnCount( 2 );
1004     table->setAlternatingRowColors( true );
1005
1006     module_t *p_main = config_FindModule( p_this, "main" );
1007     assert( p_main );
1008
1009     for (size_t i = 0; i < p_main->confsize; i++)
1010     {
1011         module_config_t *p_item = p_main->p_config + i;
1012
1013         if( p_item->i_type & CONFIG_ITEM && p_item->psz_name &&
1014             strstr( p_item->psz_name , "key-" ) )
1015         {
1016             QTreeWidgetItem *treeItem = new QTreeWidgetItem();
1017             treeItem->setText( 0, qtr( p_item->psz_text ) );
1018             treeItem->setText( 1, VLCKeyToString( p_item->value.i ) );
1019             treeItem->setData( 0, Qt::UserRole,
1020                                   QVariant::fromValue( (void*)p_item ) );
1021             values += p_item;
1022             table->addTopLevelItem( treeItem );
1023         }
1024     }
1025     table->resizeColumnToContents( 0 );
1026
1027     CONNECT( table, itemDoubleClicked( QTreeWidgetItem *, int ),
1028              this, selectKey( QTreeWidgetItem * ) );
1029 }
1030
1031 void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem )
1032 {
1033    module_config_t *p_keyItem = static_cast<module_config_t*>
1034                           (keyItem->data( 0, Qt::UserRole ).value<void*>());
1035
1036     KeyInputDialog *d = new KeyInputDialog( values, p_keyItem->psz_text );
1037     d->exec();
1038     if( d->result() == QDialog::Accepted )
1039     {
1040         p_keyItem->value.i = d->keyValue;
1041         if( d->conflicts )
1042         {
1043             for( int i = 0; i < table->topLevelItemCount() ; i++ )
1044             {
1045                 QTreeWidgetItem *it = table->topLevelItem(i);
1046                 module_config_t *p_item = static_cast<module_config_t*>
1047                               (it->data( 0, Qt::UserRole ).value<void*>());
1048                 if( p_keyItem != p_item && p_item->value.i == d->keyValue )
1049                     p_item->value.i = 0;
1050                 it->setText( 1, VLCKeyToString( p_item->value.i ) );
1051             }
1052         }
1053         else
1054             keyItem->setText( 1, VLCKeyToString( p_keyItem->value.i ) );
1055     }
1056     delete d;
1057 }
1058
1059 void KeySelectorControl::doApply()
1060 {
1061     foreach( module_config_t *p_current, values )
1062     {
1063         config_PutInt( p_this, p_current->psz_name, p_current->value.i );
1064     }
1065 }
1066
1067 KeyInputDialog::KeyInputDialog( QList<module_config_t*>& _values,
1068                                 const char * _keyToChange ) :
1069                                                 QDialog(0), keyValue(0)
1070 {
1071     setModal( true );
1072     values = _values;
1073     conflicts = false;
1074     keyToChange = _keyToChange;
1075     setWindowTitle( qtr( "Hotkey for " ) + qfu( keyToChange)  );
1076
1077     QVBoxLayout *l = new QVBoxLayout( this );
1078     selected = new QLabel( qtr("Press the new keys for ")  + qfu(keyToChange) );
1079     warning = new QLabel();
1080     l->addWidget( selected , Qt::AlignCenter );
1081     l->addWidget( warning, Qt::AlignCenter );
1082
1083     QHBoxLayout *l2 = new QHBoxLayout();
1084     QPushButton *ok = new QPushButton( qtr("OK") );
1085     l2->addWidget( ok );
1086     QPushButton *cancel = new QPushButton( qtr("Cancel") );
1087     l2->addWidget( cancel );
1088
1089     BUTTONACT( ok, accept() );
1090     BUTTONACT( cancel, reject() );
1091
1092     l->addLayout( l2 );
1093 }
1094
1095 void KeyInputDialog::checkForConflicts( int i_vlckey )
1096 {
1097     conflicts = false;
1098     module_config_t *p_current = NULL;
1099     foreach( p_current, values )
1100     {
1101         if( p_current->value.i == i_vlckey && strcmp( p_current->psz_text,
1102                                                     keyToChange ) )
1103         {
1104             conflicts = true;
1105             break;
1106         }
1107     }
1108     if( conflicts )
1109     {
1110         warning->setText(
1111           qtr("Warning: the  key is already assigned to \"") +
1112           QString( p_current->psz_text ) + "\"" );
1113     }
1114     else warning->setText( "" );
1115 }
1116
1117 void KeyInputDialog::keyPressEvent( QKeyEvent *e )
1118 {
1119     if( e->key() == Qt::Key_Tab ) return;
1120     int i_vlck = qtEventToVLCKey( e );
1121     selected->setText( VLCKeyToString( i_vlck ) );
1122     checkForConflicts( i_vlck );
1123     keyValue = i_vlck;
1124 }
1125
1126 void KeyInputDialog::wheelEvent( QWheelEvent *e )
1127 {
1128     int i_vlck = qtWheelEventToVLCKey( e );
1129     selected->setText( VLCKeyToString( i_vlck ) );
1130     checkForConflicts( i_vlck );
1131     keyValue = i_vlck;
1132 }