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