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