]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/preferences_widgets.cpp
Qt4 - Preferences, improve a bit the Hotkeys. Preparatory work to merge the Hotkeys...
[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
49 QString formatTooltip(const QString & tooltip)
50 {
51     QString formatted =
52     "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">"
53     " p, li { white-space: pre-wrap; } </style></head><body style=\" font-family:'Sans Serif';"
54     " font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;\">"
55     "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; "
56     "-qt-block-indent:0; text-indent:0px;\">" +
57     tooltip +
58     "</p></body></html>";
59     return formatted;
60 }
61
62 ConfigControl *ConfigControl::createControl( vlc_object_t *p_this,
63                                              module_config_t *p_item,
64                                              QWidget *parent )
65 {
66     int i=0;
67     return createControl( p_this, p_item, parent, NULL, i );
68 }
69
70 ConfigControl *ConfigControl::createControl( vlc_object_t *p_this,
71                                              module_config_t *p_item,
72                                              QWidget *parent,
73                                              QGridLayout *l, int &line )
74 {
75     ConfigControl *p_control = NULL;
76     if( p_item->psz_current || p_item->b_unsaveable ) return NULL;
77
78     switch( p_item->i_type )
79     {
80     case CONFIG_ITEM_MODULE:
81         p_control = new ModuleConfigControl( p_this, p_item, parent, false,
82                                              l, line );
83         break;
84     case CONFIG_ITEM_MODULE_CAT:
85         p_control = new ModuleConfigControl( p_this, p_item, parent, true,
86                                              l, line );
87         break;
88     case CONFIG_ITEM_MODULE_LIST:
89         p_control = new ModuleListConfigControl( p_this, p_item, parent, false,
90                                              l, line );
91         break;
92     case CONFIG_ITEM_MODULE_LIST_CAT:
93         p_control = new ModuleListConfigControl( p_this, p_item, parent, true,
94                                              l, line );
95         break;
96     case CONFIG_ITEM_STRING:
97         if( !p_item->i_list )
98             p_control = new StringConfigControl( p_this, p_item, parent,
99                                                  l, line, false );
100         else
101             p_control = new StringListConfigControl( p_this, p_item,
102                                             parent, false, l, line );
103         break;
104     case CONFIG_ITEM_PASSWORD:
105         if( !p_item->i_list )
106             p_control = new StringConfigControl( p_this, p_item, parent,
107                                                  l, line, true );
108         else
109             p_control = new StringListConfigControl( p_this, p_item,
110                                             parent, true, l, line );
111         break;
112     case CONFIG_ITEM_INTEGER:
113         if( p_item->i_list )
114             p_control = new IntegerListConfigControl( p_this, p_item,
115                                             parent, false, l, line );
116         else if( p_item->min.i || p_item->max.i )
117             p_control = new IntegerRangeConfigControl( p_this, p_item, parent,
118                                                        l, line );
119         else
120             p_control = new IntegerConfigControl( p_this, p_item, parent,
121                                                   l, line );
122         break;
123     case CONFIG_ITEM_FILE:
124         p_control = new FileConfigControl( p_this, p_item, parent, l,
125                                                 line, false );
126         break;
127     case CONFIG_ITEM_DIRECTORY:
128         p_control = new DirectoryConfigControl( p_this, p_item, parent, l,
129                                                 line, false );
130         break;
131     case CONFIG_ITEM_FONT:
132         p_control = new FontConfigControl( p_this, p_item, parent, l,
133                                            line, false );
134         break;
135     case CONFIG_ITEM_KEY:
136         p_control = new KeySelectorControl( p_this, p_item, parent, l, line );
137         break;
138     case CONFIG_ITEM_BOOL:
139         p_control = new BoolConfigControl( p_this, p_item, parent, l, line );
140         break;
141     case CONFIG_ITEM_FLOAT:
142         if( p_item->min.f || p_item->max.f )
143             p_control = new FloatRangeConfigControl( p_this, p_item, parent,
144                                                      l, line );
145         else
146             p_control = new FloatConfigControl( p_this, p_item, parent,
147                                                   l, line );
148         break;
149     default:
150         break;
151     }
152     return p_control;
153 }
154
155 void ConfigControl::doApply( intf_thread_t *p_intf )
156 {
157     switch( getType() )
158     {
159         case 1:
160         {
161             VIntConfigControl *vicc = qobject_cast<VIntConfigControl *>(this);
162             assert( vicc );
163             config_PutInt( p_intf, vicc->getName(), vicc->getValue() );
164             break;
165         }
166         case 2:
167         {
168             VFloatConfigControl *vfcc =
169                                     qobject_cast<VFloatConfigControl *>(this);
170             assert( vfcc );
171             config_PutFloat( p_intf, vfcc->getName(), vfcc->getValue() );
172             break;
173         }
174         case 3:
175         {
176             VStringConfigControl *vscc =
177                             qobject_cast<VStringConfigControl *>(this);
178             assert( vscc );
179             config_PutPsz( p_intf, vscc->getName(), qta( vscc->getValue() ) );
180             break;
181         }
182         case 4:
183         {
184             KeySelectorControl *ksc = qobject_cast<KeySelectorControl *>(this);
185             assert( ksc );
186             ksc->doApply();
187         }
188     }
189 }
190
191 /**************************************************************************
192  * String-based controls
193  *************************************************************************/
194
195 /*********** String **************/
196 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
197                                           module_config_t *_p_item,
198                                           QWidget *_parent, QGridLayout *l,
199                                           int &line, bool pwd ) :
200                            VStringConfigControl( _p_this, _p_item, _parent )
201 {
202     label = new QLabel( qtr(p_item->psz_text) );
203     text = new QLineEdit( qfu(p_item->value.psz) );
204     if( pwd ) text->setEchoMode( QLineEdit::Password );
205     finish();
206
207     if( !l )
208     {
209         QHBoxLayout *layout = new QHBoxLayout();
210         layout->addWidget( label, 0 ); layout->addWidget( text, 1 );
211         widget->setLayout( layout );
212     }
213     else
214     {
215         l->addWidget( label, line, 0 ); l->addWidget( text, line, 1 );
216     }
217 }
218
219 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
220                                    module_config_t *_p_item,
221                                    QLabel *_label, QLineEdit *_text, bool pwd ):
222                            VStringConfigControl( _p_this, _p_item )
223 {
224     text = _text;
225     label = _label;
226     finish( );
227 }
228
229 void StringConfigControl::finish()
230 {
231     text->setText( qfu(p_item->value.psz) );
232     text->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
233     if( label )
234         label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
235 }
236
237 /*********** File **************/
238 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
239                                           module_config_t *_p_item,
240                                           QWidget *_parent, QGridLayout *l,
241                                           int &line, bool pwd ) :
242                            VStringConfigControl( _p_this, _p_item, _parent )
243 {
244     label = new QLabel( qtr(p_item->psz_text) );
245     text = new QLineEdit( qfu(p_item->value.psz) );
246     browse = new QPushButton( qtr( "Browse..." ) );
247     QHBoxLayout *textAndButton = new QHBoxLayout();
248     textAndButton->setMargin( 0 );
249     textAndButton->addWidget( text, 2 );
250     textAndButton->addWidget( browse, 0 );
251
252     BUTTONACT( browse, updateField() );
253
254     finish();
255
256     if( !l )
257     {
258         QHBoxLayout *layout = new QHBoxLayout();
259         layout->addWidget( label, 0 );
260         layout->addLayout( textAndButton, 1 );
261         widget->setLayout( layout );
262     }
263     else
264     {
265         l->addWidget( label, line, 0 );
266         l->addLayout( textAndButton, line, 1 );
267     }
268 }
269
270
271 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
272                                    module_config_t *_p_item,
273                                    QLabel *_label, QLineEdit *_text,
274                                    QPushButton *_button, bool pwd ):
275                            VStringConfigControl( _p_this, _p_item )
276 {
277     browse = _button;
278     text = _text;
279     label = _label;
280
281     BUTTONACT( browse, updateField() );
282
283     finish( );
284 }
285
286 void FileConfigControl::updateField()
287 {
288     QString file = QFileDialog::getOpenFileName( NULL,
289                   qtr( "Select File" ), qfu( p_this->p_libvlc->psz_homedir ) );
290     if( file.isNull() ) return;
291     text->setText( file );
292 }
293
294 void FileConfigControl::finish()
295 {
296     text->setText( qfu(p_item->value.psz) );
297     text->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
298     if( label )
299         label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
300 }
301
302 /********* String / Directory **********/
303 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
304                         module_config_t *_p_item, QWidget *_p_widget,
305                         QGridLayout *_p_layout, int& _int, bool _pwd ) :
306      FileConfigControl( _p_this, _p_item, _p_widget, _p_layout, _int, _pwd)
307 {}
308
309 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
310                         module_config_t *_p_item, QLabel *_p_label,
311                         QLineEdit *_p_line, QPushButton *_p_button, bool _pwd ):
312      FileConfigControl( _p_this, _p_item, _p_label, _p_line, _p_button, _pwd)
313 {}
314
315 void DirectoryConfigControl::updateField()
316 {
317     QString dir = QFileDialog::getExistingDirectory( NULL,
318                       qtr( "Select Directory" ),
319                       text->text().isEmpty() ?
320                         qfu( p_this->p_libvlc->psz_homedir ) : text->text(),
321                       QFileDialog::ShowDirsOnly |
322                         QFileDialog::DontResolveSymlinks );
323     if( dir.isNull() ) return;
324     text->setText( dir );
325 }
326
327 /********* String / Font **********/
328 FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
329                         module_config_t *_p_item, QWidget *_p_widget,
330                         QGridLayout *_p_layout, int& _int, bool _pwd ) :
331      FileConfigControl( _p_this, _p_item, _p_widget, _p_layout, _int, _pwd)
332 {}
333
334 FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
335                         module_config_t *_p_item, QLabel *_p_label,
336                         QLineEdit *_p_line, QPushButton *_p_button, bool _pwd ):
337      FileConfigControl( _p_this, _p_item, _p_label, _p_line, _p_button, _pwd)
338 {}
339
340 void FontConfigControl::updateField()
341 {
342     bool ok;
343     QFont font = QFontDialog::getFont( &ok, QFont( text->text() ), NULL );
344     if( !ok ) return;
345     text->setText( font.family() );
346 }
347
348 /********* String / choice list **********/
349 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
350                module_config_t *_p_item, QWidget *_parent, bool bycat,
351                QGridLayout *l, int &line) :
352                VStringConfigControl( _p_this, _p_item, _parent )
353 {
354     label = new QLabel( qtr(p_item->psz_text) );
355     combo = new QComboBox();
356     finish( bycat );
357     if( !l )
358     {
359         QHBoxLayout *layout = new QHBoxLayout();
360         layout->addWidget( label ); layout->addWidget( combo );
361         widget->setLayout( layout );
362     }
363     else
364     {
365         l->addWidget( label, line, 0 );
366         l->addWidget( combo, line, 1, Qt::AlignRight );
367     }
368
369     if( p_item->i_action )
370     {
371         QSignalMapper *signalMapper = new QSignalMapper(this);
372
373         /* Some stringLists like Capture listings have action associated */
374         for( int i = 0; i < p_item->i_action; i++ )
375         {
376             QPushButton *button =
377                 new QPushButton( qfu( p_item->ppsz_action_text[i] ));
378             CONNECT( button, clicked(), signalMapper, map() );
379             signalMapper->setMapping( button, i );
380             l->addWidget( button, line, 2 + i, Qt::AlignRight );
381         }
382         CONNECT( signalMapper, mapped( int ),
383                 this, actionRequested( int ) );
384     }
385 }
386
387 void StringListConfigControl::actionRequested( int i_action )
388 {
389     /* Supplementary check for boundaries */
390     if( i_action < 0 || i_action >= p_item->i_action ) return;
391
392     vlc_value_t val;
393     val.psz_string = 
394         qtu( (combo->itemData( combo->currentIndex() ).toString() ) );
395
396     p_item->ppf_action[i_action]( p_this, getName(), val, val, 0 );
397
398     if( p_item->b_dirty )
399     {
400         combo->clear();
401         finish( true );
402         p_item->b_dirty = VLC_FALSE;
403     }
404 }
405 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
406                 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
407                 bool bycat ) : VStringConfigControl( _p_this, _p_item )
408 {
409     combo = _combo;
410     label = _label;
411     finish( bycat );
412 }
413
414 void StringListConfigControl::finish( bool bycat )
415 {
416     combo->setEditable( false );
417
418     for( int i_index = 0; i_index < p_item->i_list; i_index++ )
419     {
420         combo->addItem( qfu(p_item->ppsz_list_text ?
421                             p_item->ppsz_list_text[i_index] :
422                             p_item->ppsz_list[i_index] ),
423                         QVariant( p_item->ppsz_list[i_index] ) );
424         if( p_item->value.psz && !strcmp( p_item->value.psz,
425                                           p_item->ppsz_list[i_index] ) )
426             combo->setCurrentIndex( combo->count() - 1 );
427     }
428     combo->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
429     if( label )
430         label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
431 }
432
433 QString StringListConfigControl::getValue()
434 {
435     return combo->itemData( combo->currentIndex() ).toString();
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 }
690
691 /**************************************************************************
692  * Integer-based controls
693  *************************************************************************/
694
695 /*********** Integer **************/
696 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
697                                             module_config_t *_p_item,
698                                             QWidget *_parent, QGridLayout *l,
699                                             int &line ) :
700                            VIntConfigControl( _p_this, _p_item, _parent )
701 {
702     label = new QLabel( qtr(p_item->psz_text) );
703     spin = new QSpinBox; spin->setMinimumWidth( 80 );
704     spin->setAlignment( Qt::AlignRight );
705     spin->setMaximumWidth( 90 );
706     finish();
707
708     if( !l )
709     {
710         QHBoxLayout *layout = new QHBoxLayout();
711         layout->addWidget( label, 0 ); layout->addWidget( spin, 1 );
712         widget->setLayout( layout );
713     }
714     else
715     {
716         l->addWidget( label, line, 0 );
717         l->addWidget( spin, line, 1, Qt::AlignRight );
718     }
719 }
720 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
721                                             module_config_t *_p_item,
722                                             QLabel *_label, QSpinBox *_spin ) :
723                                       VIntConfigControl( _p_this, _p_item )
724 {
725     spin = _spin;
726     label = _label;
727     finish();
728 }
729
730 void IntegerConfigControl::finish()
731 {
732     spin->setMaximum( 2000000000 );
733     spin->setMinimum( -2000000000 );
734     spin->setValue( p_item->value.i );
735     spin->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
736     if( label )
737         label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
738 }
739
740 int IntegerConfigControl::getValue()
741 {
742     return spin->value();
743 }
744
745 /********* Integer range **********/
746 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
747                                             module_config_t *_p_item,
748                                             QWidget *_parent, QGridLayout *l,
749                                             int &line ) :
750             IntegerConfigControl( _p_this, _p_item, _parent, l, line )
751 {
752     finish();
753 }
754
755 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
756                                             module_config_t *_p_item,
757                                             QLabel *_label, QSpinBox *_spin ) :
758             IntegerConfigControl( _p_this, _p_item, _label, _spin )
759 {
760     finish();
761 }
762
763 void IntegerRangeConfigControl::finish()
764 {
765     spin->setMaximum( p_item->max.i );
766     spin->setMinimum( p_item->min.i );
767 }
768
769 IntegerRangeSliderConfigControl::IntegerRangeSliderConfigControl(
770                                             vlc_object_t *_p_this,
771                                             module_config_t *_p_item,
772                                             QLabel *_label, QSlider *_slider ):
773                     VIntConfigControl( _p_this, _p_item )
774 {
775     slider = _slider;
776     label = _label;
777     slider->setMaximum( p_item->max.i );
778     slider->setMinimum( p_item->min.i );
779     slider->setValue( p_item->value.i );
780     slider->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
781     if( label )
782         label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
783 }
784
785 int IntegerRangeSliderConfigControl::getValue()
786 {
787         return slider->value();
788 }
789
790
791 /********* Integer / choice list **********/
792 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
793                module_config_t *_p_item, QWidget *_parent, bool bycat,
794                QGridLayout *l, int &line) :
795                VIntConfigControl( _p_this, _p_item, _parent )
796 {
797     label = new QLabel( qtr(p_item->psz_text) );
798     combo = new QComboBox();
799     finish( bycat );
800     if( !l )
801     {
802         QHBoxLayout *layout = new QHBoxLayout();
803         layout->addWidget( label ); layout->addWidget( combo );
804         widget->setLayout( layout );
805     }
806     else
807     {
808         l->addWidget( label, line, 0 );
809         l->addWidget( combo, line, 1, Qt::AlignRight );
810     }
811 }
812 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
813                 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
814                 bool bycat ) : VIntConfigControl( _p_this, _p_item )
815 {
816     combo = _combo;
817     label = _label;
818     finish( bycat );
819 }
820
821 void IntegerListConfigControl::finish( bool bycat )
822 {
823     combo->setEditable( false );
824
825     for( int i_index = 0; i_index < p_item->i_list; i_index++ )
826     {
827         combo->addItem( qtr(p_item->ppsz_list_text[i_index] ),
828                         QVariant( p_item->pi_list[i_index] ) );
829         if( p_item->value.i == p_item->pi_list[i_index] )
830             combo->setCurrentIndex( combo->count() - 1 );
831     }
832     combo->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
833     if( label )
834         label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
835 }
836
837 int IntegerListConfigControl::getValue()
838 {
839     return combo->itemData( combo->currentIndex() ).toInt();
840 }
841
842 /*********** Boolean **************/
843 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
844                                       module_config_t *_p_item,
845                                       QWidget *_parent, QGridLayout *l,
846                                       int &line ) :
847                     VIntConfigControl( _p_this, _p_item, _parent )
848 {
849     checkbox = new QCheckBox( qtr(p_item->psz_text) );
850     finish();
851
852     if( !l )
853     {
854         QHBoxLayout *layout = new QHBoxLayout();
855         layout->addWidget( checkbox, 0 );
856         widget->setLayout( layout );
857     }
858     else
859     {
860         l->addWidget( checkbox, line, 0 );
861     }
862 }
863 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
864                                       module_config_t *_p_item,
865                                       QLabel *_label,
866                                       QCheckBox *_checkbox,
867                                       bool bycat ) :
868                    VIntConfigControl( _p_this, _p_item )
869 {
870     checkbox = _checkbox;
871     finish();
872 }
873
874 void BoolConfigControl::finish()
875 {
876     checkbox->setCheckState( p_item->value.i == VLC_TRUE ? Qt::Checked
877                                                         : Qt::Unchecked );
878     checkbox->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
879 }
880
881 int BoolConfigControl::getValue()
882 {
883     return checkbox->checkState() == Qt::Checked ? VLC_TRUE : VLC_FALSE;
884 }
885
886 /**************************************************************************
887  * Float-based controls
888  *************************************************************************/
889
890 /*********** Float **************/
891 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
892                                         module_config_t *_p_item,
893                                         QWidget *_parent, QGridLayout *l,
894                                         int &line ) :
895                     VFloatConfigControl( _p_this, _p_item, _parent )
896 {
897     label = new QLabel( qtr(p_item->psz_text) );
898     spin = new QDoubleSpinBox; spin->setMinimumWidth( 80 );
899     spin->setMaximumWidth( 90 );
900     spin->setAlignment( Qt::AlignRight );
901     finish();
902
903     if( !l )
904     {
905         QHBoxLayout *layout = new QHBoxLayout();
906         layout->addWidget( label, 0 ); layout->addWidget( spin, 1 );
907         widget->setLayout( layout );
908     }
909     else
910     {
911         l->addWidget( label, line, 0 );
912         l->addWidget( spin, line, 1, Qt::AlignRight );
913     }
914 }
915
916 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
917                                         module_config_t *_p_item,
918                                         QLabel *_label,
919                                         QDoubleSpinBox *_spin ) :
920                     VFloatConfigControl( _p_this, _p_item )
921 {
922     spin = _spin;
923     label = _label;
924     finish();
925 }
926
927 void FloatConfigControl::finish()
928 {
929     spin->setMaximum( 2000000000. );
930     spin->setMinimum( -2000000000. );
931     spin->setSingleStep( 0.1 );
932     spin->setValue( (double)p_item->value.f );
933     spin->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
934     if( label )
935         label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
936 }
937
938 float FloatConfigControl::getValue()
939 {
940     return (float)spin->value();
941 }
942
943 /*********** Float with range **************/
944 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
945                                         module_config_t *_p_item,
946                                         QWidget *_parent, QGridLayout *l,
947                                         int &line ) :
948                 FloatConfigControl( _p_this, _p_item, _parent, l, line )
949 {
950     finish();
951 }
952
953 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
954                                         module_config_t *_p_item,
955                                         QLabel *_label,
956                                         QDoubleSpinBox *_spin ) :
957                 FloatConfigControl( _p_this, _p_item, _label, _spin )
958 {
959     finish();
960 }
961
962 void FloatRangeConfigControl::finish()
963 {
964     spin->setMaximum( (double)p_item->max.f );
965     spin->setMinimum( (double)p_item->min.f );
966 }
967
968
969 /**********************************************************************
970  * Key selector widget
971  **********************************************************************/
972 KeySelectorControl::KeySelectorControl( vlc_object_t *_p_this,
973                                       module_config_t *_p_item,
974                                       QWidget *_parent, QGridLayout *l,
975                                       int &line ) :
976                                 ConfigControl( _p_this, _p_item, _parent )
977
978 {
979     QWidget *keyContainer = new QWidget;
980     QGridLayout *gLayout = new QGridLayout( keyContainer );
981     
982     label = new QLabel( qtr("Select an action to change the associated hotkey") );
983     QLabel *searchLabel = new QLabel( qtr( "Search" ) );
984     
985     table = new QTreeWidget;
986     table->setColumnCount(2);
987     table->headerItem()->setText( 0, qtr( "Action" ) );
988     table->headerItem()->setText( 1, qtr( "Shortcut" ) );
989     
990     QLineEdit *shortcutValue = new QLineEdit;
991     shortcutValue->setReadOnly(true);
992     QLineEdit *actionSearch = new QLineEdit;
993     
994     QPushButton *clearButton = new QPushButton( qtr( "Clear" ) );
995     QPushButton *setButton = new QPushButton( qtr( "Set" ) );
996     finish();
997     
998     gLayout->addWidget( label, 0, 0, 1, 4 );
999     gLayout->addWidget( searchLabel, 1, 0, 1, 2 );
1000     gLayout->addWidget( actionSearch, 1, 2, 1, 2 ); 
1001     gLayout->addWidget( table, 2, 0, 1, 4 );
1002     gLayout->addWidget( clearButton, 3, 0, 1, 1 );
1003     gLayout->addWidget( shortcutValue, 3, 1, 1, 2 ); 
1004     gLayout->addWidget( setButton, 3, 3, 1, 1 );
1005     
1006     if( !l ) /* This shouldn't happen */
1007     {
1008         QVBoxLayout *layout = new QVBoxLayout();
1009         layout->addWidget( label, 0 ); layout->addWidget( table, 1 );
1010         widget->setLayout( layout );
1011     }
1012     else
1013     {
1014         l->addWidget( keyContainer, 0, 0, 1, 2 );
1015     }
1016 }
1017
1018 void KeySelectorControl::finish()
1019 {
1020     if( label )
1021         label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
1022
1023     /* Fill the table */
1024     table->setColumnCount( 2 );
1025     table->setAlternatingRowColors( true );
1026
1027     module_t *p_main = config_FindModule( p_this, "main" );
1028     assert( p_main );
1029
1030     for (size_t i = 0; i < p_main->confsize; i++)
1031     {
1032         module_config_t *p_item = p_main->p_config + i;
1033
1034         if( p_item->i_type & CONFIG_ITEM && p_item->psz_name &&
1035             strstr( p_item->psz_name , "key-" ) )
1036         {
1037             QTreeWidgetItem *treeItem = new QTreeWidgetItem();
1038             treeItem->setText( 0, qtr( p_item->psz_text ) );
1039             treeItem->setText( 1, VLCKeyToString( p_item->value.i ) );
1040             treeItem->setData( 0, Qt::UserRole,
1041                                   QVariant::fromValue( (void*)p_item ) );
1042             values += p_item;
1043             table->addTopLevelItem( treeItem );
1044         }
1045     }
1046     table->resizeColumnToContents( 0 );
1047
1048     CONNECT( table, itemDoubleClicked( QTreeWidgetItem *, int ),
1049              this, selectKey( QTreeWidgetItem * ) );
1050 }
1051
1052 void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem )
1053 {
1054    module_config_t *p_keyItem = static_cast<module_config_t*>
1055                           (keyItem->data( 0, Qt::UserRole ).value<void*>());
1056
1057     KeyInputDialog *d = new KeyInputDialog( values, p_keyItem->psz_text );
1058     d->exec();
1059     if( d->result() == QDialog::Accepted )
1060     {
1061         p_keyItem->value.i = d->keyValue;
1062         if( d->conflicts )
1063         {
1064             for( int i = 0; i < table->topLevelItemCount() ; i++ )
1065             {
1066                 QTreeWidgetItem *it = table->topLevelItem(i);
1067                 module_config_t *p_item = static_cast<module_config_t*>
1068                               (it->data( 0, Qt::UserRole ).value<void*>());
1069                 if( p_keyItem != p_item && p_item->value.i == d->keyValue )
1070                     p_item->value.i = 0;
1071                 it->setText( 1, VLCKeyToString( p_item->value.i ) );
1072             }
1073         }
1074         else
1075             keyItem->setText( 1, VLCKeyToString( p_keyItem->value.i ) );
1076     }
1077     delete d;
1078 }
1079
1080 void KeySelectorControl::doApply()
1081 {
1082     foreach( module_config_t *p_current, values )
1083     {
1084         config_PutInt( p_this, p_current->psz_name, p_current->value.i );
1085     }
1086 }
1087
1088 KeyInputDialog::KeyInputDialog( QList<module_config_t*>& _values,
1089                                 const char * _keyToChange ) :
1090                                                 QDialog(0), keyValue(0)
1091 {
1092     setModal( true );
1093     values = _values;
1094     conflicts = false;
1095     keyToChange = _keyToChange;
1096     setWindowTitle( qtr( "Hotkey for " ) + qfu( keyToChange)  );
1097
1098     QVBoxLayout *l = new QVBoxLayout( this );
1099     selected = new QLabel( qtr("Press the new keys for ")  + qfu(keyToChange) );
1100     warning = new QLabel();
1101     l->addWidget( selected , Qt::AlignCenter );
1102     l->addWidget( warning, Qt::AlignCenter );
1103
1104     QHBoxLayout *l2 = new QHBoxLayout();
1105     QPushButton *ok = new QPushButton( qtr("OK") );
1106     l2->addWidget( ok );
1107     QPushButton *cancel = new QPushButton( qtr("Cancel") );
1108     l2->addWidget( cancel );
1109
1110     BUTTONACT( ok, accept() );
1111     BUTTONACT( cancel, reject() );
1112
1113     l->addLayout( l2 );
1114 }
1115
1116 void KeyInputDialog::checkForConflicts( int i_vlckey )
1117 {
1118     conflicts = false;
1119     module_config_t *p_current = NULL;
1120     foreach( p_current, values )
1121     {
1122         if( p_current->value.i == i_vlckey && strcmp( p_current->psz_text,
1123                                                     keyToChange ) )
1124         {
1125             conflicts = true;
1126             break;
1127         }
1128     }
1129     if( conflicts )
1130     {
1131         warning->setText(
1132           qtr("Warning: the  key is already assigned to \"") +
1133           QString( p_current->psz_text ) + "\"" );
1134     }
1135     else warning->setText( "" );
1136 }
1137
1138 void KeyInputDialog::keyPressEvent( QKeyEvent *e )
1139 {
1140     if( e->key() == Qt::Key_Tab ) return;
1141     int i_vlck = qtEventToVLCKey( e );
1142     selected->setText( VLCKeyToString( i_vlck ) );
1143     checkForConflicts( i_vlck );
1144     keyValue = i_vlck;
1145 }
1146
1147 void KeyInputDialog::wheelEvent( QWheelEvent *e )
1148 {
1149     int i_vlck = qtWheelEventToVLCKey( e );
1150     selected->setText( VLCKeyToString( i_vlck ) );
1151     checkForConflicts( i_vlck );
1152     keyValue = i_vlck;
1153 }