]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/preferences_widgets.cpp
Qt4 - spaces removing.
[vlc] / modules / gui / qt4 / components / preferences_widgets.cpp
1 /*****************************************************************************
2  * preferences_widgets.cpp : Widgets for preferences displays
3  ****************************************************************************
4  * Copyright (C) 2006-2007 the VideoLAN team
5  * $Id$
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
8  *          Antoine Cellerier <dionoea@videolan.org>
9  *          Jean-Baptiste Kempf <jb@videolan.org>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24  *****************************************************************************/
25
26 /**
27  * Todo:
28  *  - Finish implementation (see WX)
29  *  - Improvements over WX
30  *      - Validator for modulelist
31  *  - Implement update stuff using a general Updated signal
32  */
33
34 #include "components/preferences_widgets.hpp"
35 #include "util/customwidgets.hpp"
36
37 #include <vlc_keys.h>
38
39 #include <QString>
40 #include <QVariant>
41 #include <QGridLayout>
42 #include <QSlider>
43 #include <QFileDialog>
44 #include <QFontDialog>
45 #include <QGroupBox>
46 #include <QTreeWidgetItem>
47 #include <QSignalMapper>
48 QString formatTooltip(const QString & tooltip)
49 {
50     QString formatted =
51     "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">"
52     " p, li { white-space: pre-wrap; } </style></head><body style=\" font-family:'Sans Serif';"
53     " font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;\">"
54     "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; "
55     "-qt-block-indent:0; text-indent:0px;\">" +
56     tooltip +
57     "</p></body></html>";
58     return formatted;
59 }
60
61 ConfigControl *ConfigControl::createControl( vlc_object_t *p_this,
62                                              module_config_t *p_item,
63                                              QWidget *parent )
64 {
65     int i=0;
66     return createControl( p_this, p_item, parent, NULL, i );
67 }
68
69 ConfigControl *ConfigControl::createControl( vlc_object_t *p_this,
70                                              module_config_t *p_item,
71                                              QWidget *parent,
72                                              QGridLayout *l, int &line )
73 {
74     ConfigControl *p_control = NULL;
75     if( p_item->psz_current || p_item->b_unsaveable ) return NULL;
76
77     switch( p_item->i_type )
78     {
79     case CONFIG_ITEM_MODULE:
80         p_control = new ModuleConfigControl( p_this, p_item, parent, false,
81                                              l, line );
82         break;
83     case CONFIG_ITEM_MODULE_CAT:
84         p_control = new ModuleConfigControl( p_this, p_item, parent, true,
85                                              l, line );
86         break;
87     case CONFIG_ITEM_MODULE_LIST:
88         p_control = new ModuleListConfigControl( p_this, p_item, parent, false,
89                                              l, line );
90         break;
91     case CONFIG_ITEM_MODULE_LIST_CAT:
92         p_control = new ModuleListConfigControl( p_this, p_item, parent, true,
93                                              l, line );
94         break;
95     case CONFIG_ITEM_STRING:
96         if( !p_item->i_list )
97             p_control = new StringConfigControl( p_this, p_item, parent,
98                                                  l, line, false );
99         else
100             p_control = new StringListConfigControl( p_this, p_item,
101                                             parent, false, l, line );
102         break;
103     case CONFIG_ITEM_PASSWORD:
104         if( !p_item->i_list )
105             p_control = new StringConfigControl( p_this, p_item, parent,
106                                                  l, line, true );
107         else
108             p_control = new StringListConfigControl( p_this, p_item,
109                                             parent, true, l, line );
110         break;
111     case CONFIG_ITEM_INTEGER:
112         if( p_item->i_list )
113             p_control = new IntegerListConfigControl( p_this, p_item,
114                                             parent, false, l, line );
115         else if( p_item->min.i || p_item->max.i )
116             p_control = new IntegerRangeConfigControl( p_this, p_item, parent,
117                                                        l, line );
118         else
119             p_control = new IntegerConfigControl( p_this, p_item, parent,
120                                                   l, line );
121         break;
122     case CONFIG_ITEM_FILE:
123         p_control = new FileConfigControl( p_this, p_item, parent, l,
124                                                 line, false );
125         break;
126     case CONFIG_ITEM_DIRECTORY:
127         p_control = new DirectoryConfigControl( p_this, p_item, parent, l,
128                                                 line, false );
129         break;
130     case CONFIG_ITEM_FONT:
131         p_control = new FontConfigControl( p_this, p_item, parent, l,
132                                            line, false );
133         break;
134     case CONFIG_ITEM_KEY:
135         p_control = new KeySelectorControl( p_this, p_item, parent, l, line );
136         break;
137     case CONFIG_ITEM_BOOL:
138         p_control = new BoolConfigControl( p_this, p_item, parent, l, line );
139         break;
140     case CONFIG_ITEM_FLOAT:
141         if( p_item->min.f || p_item->max.f )
142             p_control = new FloatRangeConfigControl( p_this, p_item, parent,
143                                                      l, line );
144         else
145             p_control = new FloatConfigControl( p_this, p_item, parent,
146                                                   l, line );
147         break;
148     default:
149         break;
150     }
151     return p_control;
152 }
153
154 void ConfigControl::doApply( intf_thread_t *p_intf )
155 {
156     switch( getType() )
157     {
158         case 1:
159         {
160             VIntConfigControl *vicc = qobject_cast<VIntConfigControl *>(this);
161             assert( vicc );
162             config_PutInt( p_intf, vicc->getName(), vicc->getValue() );
163             break;
164         }
165         case 2:
166         {
167             VFloatConfigControl *vfcc =
168                                     qobject_cast<VFloatConfigControl *>(this);
169             assert( vfcc );
170             config_PutFloat( p_intf, vfcc->getName(), vfcc->getValue() );
171             break;
172         }
173         case 3:
174         {
175             VStringConfigControl *vscc =
176                             qobject_cast<VStringConfigControl *>(this);
177             assert( vscc );
178             config_PutPsz( p_intf, vscc->getName(), qta( vscc->getValue() ) );
179             break;
180         }
181         case 4:
182         {
183             KeySelectorControl *ksc = qobject_cast<KeySelectorControl *>(this);
184             assert( ksc );
185             ksc->doApply();
186         }
187     }
188 }
189
190 /**************************************************************************
191  * String-based controls
192  *************************************************************************/
193
194 /*********** String **************/
195 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
196                                           module_config_t *_p_item,
197                                           QWidget *_parent, QGridLayout *l,
198                                           int &line, bool pwd ) :
199                            VStringConfigControl( _p_this, _p_item, _parent )
200 {
201     label = new QLabel( qtr(p_item->psz_text) );
202     text = new QLineEdit( qfu(p_item->value.psz) );
203     if( pwd ) text->setEchoMode( QLineEdit::Password );
204     finish();
205
206     if( !l )
207     {
208         QHBoxLayout *layout = new QHBoxLayout();
209         layout->addWidget( label, 0 ); layout->addWidget( text, 1 );
210         widget->setLayout( layout );
211     }
212     else
213     {
214         l->addWidget( label, line, 0 ); l->addWidget( text, line, 1 );
215     }
216 }
217
218 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
219                                    module_config_t *_p_item,
220                                    QLabel *_label, QLineEdit *_text, bool pwd ):
221                            VStringConfigControl( _p_this, _p_item )
222 {
223     text = _text;
224     label = _label;
225     finish( );
226 }
227
228 void StringConfigControl::finish()
229 {
230     text->setText( qfu(p_item->value.psz) );
231     text->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
232     if( label )
233         label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
234 }
235
236 /*********** File **************/
237 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
238                                           module_config_t *_p_item,
239                                           QWidget *_parent, QGridLayout *l,
240                                           int &line, bool pwd ) :
241                            VStringConfigControl( _p_this, _p_item, _parent )
242 {
243     label = new QLabel( qtr(p_item->psz_text) );
244     text = new QLineEdit( qfu(p_item->value.psz) );
245     browse = new QPushButton( qtr( "Browse..." ) );
246     QHBoxLayout *textAndButton = new QHBoxLayout();
247     textAndButton->setMargin( 0 );
248     textAndButton->addWidget( text, 2 );
249     textAndButton->addWidget( browse, 0 );
250
251     BUTTONACT( browse, updateField() );
252
253     finish();
254
255     if( !l )
256     {
257         QHBoxLayout *layout = new QHBoxLayout();
258         layout->addWidget( label, 0 );
259         layout->addLayout( textAndButton, 1 );
260         widget->setLayout( layout );
261     }
262     else
263     {
264         l->addWidget( label, line, 0 );
265         l->addLayout( textAndButton, line, 1 );
266     }
267 }
268
269
270 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
271                                    module_config_t *_p_item,
272                                    QLabel *_label, QLineEdit *_text,
273                                    QPushButton *_button, bool pwd ):
274                            VStringConfigControl( _p_this, _p_item )
275 {
276     browse = _button;
277     text = _text;
278     label = _label;
279
280     BUTTONACT( browse, updateField() );
281
282     finish( );
283 }
284
285 void FileConfigControl::updateField()
286 {
287     QString file = QFileDialog::getOpenFileName( NULL,
288                   qtr( "Select File" ), qfu( p_this->p_libvlc->psz_homedir ) );
289     if( file.isNull() ) return;
290     text->setText( file );
291 }
292
293 void FileConfigControl::finish()
294 {
295     text->setText( qfu(p_item->value.psz) );
296     text->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
297     if( label )
298         label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
299 }
300
301 /********* String / Directory **********/
302 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
303                         module_config_t *_p_item, QWidget *_p_widget,
304                         QGridLayout *_p_layout, int& _int, bool _pwd ) :
305      FileConfigControl( _p_this, _p_item, _p_widget, _p_layout, _int, _pwd)
306 {}
307
308 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
309                         module_config_t *_p_item, QLabel *_p_label,
310                         QLineEdit *_p_line, QPushButton *_p_button, bool _pwd ):
311      FileConfigControl( _p_this, _p_item, _p_label, _p_line, _p_button, _pwd)
312 {}
313
314 void DirectoryConfigControl::updateField()
315 {
316     QString dir = QFileDialog::getExistingDirectory( NULL,
317                       qtr( "Select Directory" ),
318                       text->text().isEmpty() ?
319                         qfu( p_this->p_libvlc->psz_homedir ) : text->text(),
320                       QFileDialog::ShowDirsOnly |
321                         QFileDialog::DontResolveSymlinks );
322     if( dir.isNull() ) return;
323     text->setText( dir );
324 }
325
326 /********* String / Font **********/
327 FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
328                         module_config_t *_p_item, QWidget *_p_widget,
329                         QGridLayout *_p_layout, int& _int, bool _pwd ) :
330      FileConfigControl( _p_this, _p_item, _p_widget, _p_layout, _int, _pwd)
331 {}
332
333 FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
334                         module_config_t *_p_item, QLabel *_p_label,
335                         QLineEdit *_p_line, QPushButton *_p_button, bool _pwd ):
336      FileConfigControl( _p_this, _p_item, _p_label, _p_line, _p_button, _pwd)
337 {}
338
339 void FontConfigControl::updateField()
340 {
341     bool ok;
342     QFont font = QFontDialog::getFont( &ok, QFont( text->text() ), NULL );
343     if( !ok ) return;
344     text->setText( font.family() );
345 }
346
347 /********* String / choice list **********/
348 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
349                module_config_t *_p_item, QWidget *_parent, bool bycat,
350                QGridLayout *l, int &line) :
351                VStringConfigControl( _p_this, _p_item, _parent )
352 {
353     label = new QLabel( qtr(p_item->psz_text) );
354     combo = new QComboBox();
355     finish( bycat );
356     if( !l )
357     {
358         QHBoxLayout *layout = new QHBoxLayout();
359         layout->addWidget( label ); layout->addWidget( combo );
360         widget->setLayout( layout );
361     }
362     else
363     {
364         l->addWidget( label, line, 0 );
365         l->addWidget( combo, line, 1, Qt::AlignRight );
366     }
367
368     if( p_item->i_action )
369     {
370         QSignalMapper *signalMapper = new QSignalMapper(this);
371
372         /* Some stringLists like Capture listings have action associated */
373         for( int i = 0; i < p_item->i_action; i++ )
374         {
375             QPushButton *button =
376                 new QPushButton( qfu( p_item->ppsz_action_text[i] ));
377             CONNECT( button, clicked(), signalMapper, map() );
378             signalMapper->setMapping( button, i );
379             l->addWidget( button, line, 2 + i, Qt::AlignRight );
380         }
381         CONNECT( signalMapper, mapped( int ),
382                 this, actionRequested( int ) );
383     }
384 }
385
386 void StringListConfigControl::actionRequested( int i_action )
387 {
388     /* Supplementary check for boundaries */
389     if( i_action < 0 || i_action >= p_item->i_action ) return;
390
391     vlc_value_t val;
392     val.psz_string = qtu( (combo->itemData( combo->currentIndex() ).toString() ) );
393
394     p_item->ppf_action[i_action]( p_this, getName(), val, val, 0 );
395
396     if( p_item->b_dirty )
397     {
398         combo->clear();
399         finish( true );
400         p_item->b_dirty = VLC_FALSE;
401
402     }
403 }
404 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
405                 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
406                 bool bycat ) : VStringConfigControl( _p_this, _p_item )
407 {
408     combo = _combo;
409     label = _label;
410     finish( bycat );
411 }
412
413 void StringListConfigControl::finish( bool bycat )
414 {
415     combo->setEditable( false );
416
417     for( int i_index = 0; i_index < p_item->i_list; i_index++ )
418     {
419         combo->addItem( qfu(p_item->ppsz_list_text ?
420                             p_item->ppsz_list_text[i_index] :
421                             p_item->ppsz_list[i_index] ),
422                         QVariant( p_item->ppsz_list[i_index] ) );
423         if( p_item->value.psz && !strcmp( p_item->value.psz,
424                                           p_item->ppsz_list[i_index] ) )
425             combo->setCurrentIndex( combo->count() - 1 );
426     }
427     combo->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
428     if( label )
429         label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
430 }
431
432 QString StringListConfigControl::getValue()
433 {
434     return combo->itemData( combo->currentIndex() ).toString();
435 }
436
437 void setfillVLCConfigCombo( const char *configname, intf_thread_t *p_intf,
438                         QComboBox *combo, QWidget *parent )
439 {
440     module_config_t *p_config =
441                       config_FindConfig( VLC_OBJECT(p_intf), configname );
442     if( p_config )
443     {
444         for ( int i_index = 0; i_index < p_config->i_list; i_index++ )
445         {
446             combo->addItem( qfu( p_config->ppsz_list_text[i_index] ),
447                     QVariant( p_config->pi_list[i_index] ) );
448             if( p_config->value.i == p_config->pi_list[i_index] )
449             {
450                 combo->setCurrentIndex( i_index );
451             }
452         }
453         combo->setToolTip( qfu( p_config->psz_longtext ) );
454     }
455 }
456
457 /********* Module **********/
458 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
459                module_config_t *_p_item, QWidget *_parent, bool bycat,
460                QGridLayout *l, int &line) :
461                VStringConfigControl( _p_this, _p_item, _parent )
462 {
463     label = new QLabel( qtr(p_item->psz_text) );
464     combo = new QComboBox();
465     finish( bycat );
466     if( !l )
467     {
468         QHBoxLayout *layout = new QHBoxLayout();
469         layout->addWidget( label ); layout->addWidget( combo );
470         widget->setLayout( layout );
471     }
472     else
473     {
474         l->addWidget( label, line, 0 );
475         l->addWidget( combo, line, 1, Qt::AlignRight );
476     }
477 }
478
479 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
480                 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
481                 bool bycat ) : VStringConfigControl( _p_this, _p_item )
482 {
483     combo = _combo;
484     label = _label;
485     finish( bycat );
486 }
487
488 void ModuleConfigControl::finish( bool bycat )
489 {
490     vlc_list_t *p_list;
491     module_t *p_parser;
492
493     combo->setEditable( false );
494
495     /* build a list of available modules */
496     p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
497     combo->addItem( qtr("Default") );
498     for( int i_index = 0; i_index < p_list->i_count; i_index++ )
499     {
500         p_parser = (module_t *)p_list->p_values[i_index].p_object ;
501
502         if( bycat )
503         {
504             if( !strcmp( module_GetObjName( p_parser ), "main" ) ) continue;
505
506             for (size_t i = 0; i < p_parser->confsize; i++)
507             {
508                 module_config_t *p_config = p_parser->p_config + i;
509                 /* Hack: required subcategory is stored in i_min */
510                 if( p_config->i_type == CONFIG_SUBCATEGORY &&
511                     p_config->value.i == p_item->min.i )
512                     combo->addItem( qtr( module_GetLongName( p_parser )),
513                                     QVariant( module_GetObjName( p_parser ) ) );
514                 if( p_item->value.psz && !strcmp( p_item->value.psz,
515                                                   module_GetObjName( p_parser ) ) )
516                     combo->setCurrentIndex( combo->count() - 1 );
517             }
518         }
519         else if( module_IsCapable( p_parser, p_item->psz_type ) )
520         {
521             combo->addItem( qtr(module_GetLongName( p_parser ) ),
522                             QVariant( module_GetObjName( p_parser ) ) );
523             if( p_item->value.psz && !strcmp( p_item->value.psz,
524                                               module_GetObjName( p_parser ) ) )
525                 combo->setCurrentIndex( combo->count() - 1 );
526         }
527     }
528     vlc_list_release( p_list );
529     combo->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
530     if( label )
531         label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
532 }
533
534 QString ModuleConfigControl::getValue()
535 {
536     return combo->itemData( combo->currentIndex() ).toString();
537 }
538
539 /********* Module list **********/
540 ModuleListConfigControl::ModuleListConfigControl( vlc_object_t *_p_this,
541         module_config_t *_p_item, QWidget *_parent, bool bycat,
542         QGridLayout *l, int &line) :
543     VStringConfigControl( _p_this, _p_item, _parent )
544 {
545     groupBox = new QGroupBox ( qtr(p_item->psz_text) );
546     text = new QLineEdit();
547     QGridLayout *layoutGroupBox = new QGridLayout( groupBox );
548
549     finish( bycat );
550
551     int boxline = 0;
552     for( QVector<checkBoxListItem*>::iterator it = modules.begin();
553             it != modules.end(); it++ )
554     {
555         layoutGroupBox->addWidget( (*it)->checkBox, boxline++, 0 );
556     }
557     layoutGroupBox->addWidget( text, boxline, 0 );
558
559     if( !l )
560     {
561         QVBoxLayout *layout = new QVBoxLayout();
562         layout->addWidget( groupBox, line, 0 );
563         widget->setLayout( layout );
564     }
565     else
566     {
567         l->addWidget( groupBox, line, 0, 1, -1 );
568     }
569
570     text->setToolTip( formatTooltip( qtr( p_item->psz_longtext) ) );
571 }
572
573 ModuleListConfigControl::~ModuleListConfigControl()
574 {
575     for( QVector<checkBoxListItem*>::iterator it = modules.begin();
576             it != modules.end(); it++ )
577     {
578         delete *it;
579     }
580     delete groupBox;
581     delete text;
582 }
583
584 #define CHECKBOX_LISTS \
585 { \
586        QCheckBox *cb = new QCheckBox( qtr( module_GetLongName( p_parser ) ) );\
587        checkBoxListItem *cbl = new checkBoxListItem; \
588 \
589        CONNECT( cb, stateChanged( int ), this, onUpdate( int ) );\
590        cb->setToolTip( formatTooltip( qtr( module_GetLongName( p_parser ))));\
591        cbl->checkBox = cb; \
592 \
593        int i = -1; \
594        while( p_parser->pp_shortcuts[++i] != NULL); \
595        i--; \
596 \
597        cbl->psz_module = strdup( i>=0?p_parser->pp_shortcuts[i] \
598                                  : module_GetObjName( p_parser ) ); \
599        modules.push_back( cbl ); \
600 }
601
602
603 void ModuleListConfigControl::finish( bool bycat )
604 {
605     vlc_list_t *p_list;
606     module_t *p_parser;
607
608     /* build a list of available modules */
609     p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
610     for( int i_index = 0; i_index < p_list->i_count; i_index++ )
611     {
612         p_parser = (module_t *)p_list->p_values[i_index].p_object ;
613
614         if( bycat )
615         {
616             if( !strcmp( module_GetObjName( p_parser ), "main" ) ) continue;
617
618             for (size_t i = 0; i < p_parser->confsize; i++)
619             {
620                 module_config_t *p_config = p_parser->p_config + i;
621                 /* Hack: required subcategory is stored in i_min */
622                 if( p_config->i_type == CONFIG_SUBCATEGORY &&
623                         p_config->value.i == p_item->min.i )
624                 {
625                     CHECKBOX_LISTS;
626                 }
627             }
628         }
629         else if( module_IsCapable( p_parser, p_item->psz_type ) )
630         {
631             CHECKBOX_LISTS;
632         }
633     }
634     vlc_list_release( p_list );
635     text->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
636     if( groupBox )
637         groupBox->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
638 }
639 #undef CHECKBOX_LISTS
640
641 QString ModuleListConfigControl::getValue()
642 {
643     return text->text();
644 }
645
646 void ModuleListConfigControl::hide()
647 {
648     for( QVector<checkBoxListItem*>::iterator it = modules.begin();
649          it != modules.end(); it++ )
650     {
651         (*it)->checkBox->hide();
652     }
653     groupBox->hide();
654 }
655
656 void ModuleListConfigControl::show()
657 {
658     for( QVector<checkBoxListItem*>::iterator it = modules.begin();
659          it != modules.end(); it++ )
660     {
661         (*it)->checkBox->show();
662     }
663     groupBox->show();
664 }
665
666
667 void ModuleListConfigControl::onUpdate( int value )
668 {
669     text->clear();
670     bool first = true;
671
672     for( QVector<checkBoxListItem*>::iterator it = modules.begin();
673          it != modules.end(); it++ )
674     {
675         if( (*it)->checkBox->isChecked() )
676         {
677             if( first )
678             {
679                 text->setText( text->text() + (*it)->psz_module );
680                 first = false;
681             }
682             else
683             {
684                 text->setText( text->text() + ":" + (*it)->psz_module );
685             }
686         }
687     }
688     emit Updated();
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     label = new QLabel( qtr("Select an action to change the associated hotkey") );
980     table = new QTreeWidget( 0 );
981     finish();
982
983     if( !l )
984     {
985         QVBoxLayout *layout = new QVBoxLayout();
986         layout->addWidget( label, 0 ); layout->addWidget( table, 1 );
987         widget->setLayout( layout );
988     }
989     else
990     {
991         l->addWidget( label, line, 0, 1, 2 );
992         l->addWidget( table, line+1, 0, 1,2 );
993     }
994 }
995
996 void KeySelectorControl::finish()
997 {
998     if( label )
999         label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
1000
1001     /* Fill the table */
1002     table->setColumnCount( 2 );
1003     table->setAlternatingRowColors( true );
1004
1005     module_t *p_main = config_FindModule( p_this, "main" );
1006     assert( p_main );
1007
1008     for (size_t i = 0; i < p_main->confsize; i++)
1009     {
1010         module_config_t *p_item = p_main->p_config + i;
1011
1012         if( p_item->i_type & CONFIG_ITEM && p_item->psz_name &&
1013             strstr( p_item->psz_name , "key-" ) )
1014         {
1015             QTreeWidgetItem *treeItem = new QTreeWidgetItem();
1016             treeItem->setText( 0, qtr( p_item->psz_text ) );
1017             treeItem->setText( 1, VLCKeyToString( p_item->value.i ) );
1018             treeItem->setData( 0, Qt::UserRole,
1019                                   QVariant::fromValue( (void*)p_item ) );
1020             values += p_item;
1021             table->addTopLevelItem( treeItem );
1022         }
1023     }
1024     table->resizeColumnToContents( 0 );
1025
1026     CONNECT( table, itemDoubleClicked( QTreeWidgetItem *, int ),
1027              this, selectKey( QTreeWidgetItem * ) );
1028 }
1029
1030 void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem )
1031 {
1032    module_config_t *p_keyItem = static_cast<module_config_t*>
1033                           (keyItem->data( 0, Qt::UserRole ).value<void*>());
1034
1035     KeyInputDialog *d = new KeyInputDialog( values, p_keyItem->psz_text );
1036     d->exec();
1037     if( d->result() == QDialog::Accepted )
1038     {
1039         p_keyItem->value.i = d->keyValue;
1040         if( d->conflicts )
1041         {
1042             for( int i = 0; i < table->topLevelItemCount() ; i++ )
1043             {
1044                 QTreeWidgetItem *it = table->topLevelItem(i);
1045                 module_config_t *p_item = static_cast<module_config_t*>
1046                               (it->data( 0, Qt::UserRole ).value<void*>());
1047                 if( p_keyItem != p_item && p_item->value.i == d->keyValue )
1048                     p_item->value.i = 0;
1049                 it->setText( 1, VLCKeyToString( p_item->value.i ) );
1050             }
1051         }
1052         else
1053             keyItem->setText( 1, VLCKeyToString( p_keyItem->value.i ) );
1054     }
1055     delete d;
1056 }
1057
1058 void KeySelectorControl::doApply()
1059 {
1060     foreach( module_config_t *p_current, values )
1061     {
1062         config_PutInt( p_this, p_current->psz_name, p_current->value.i );
1063     }
1064 }
1065
1066 KeyInputDialog::KeyInputDialog( QList<module_config_t*>& _values,
1067                                 const char * _keyToChange ) :
1068                                                 QDialog(0), keyValue(0)
1069 {
1070     setModal( true );
1071     values = _values;
1072     conflicts = false;
1073     keyToChange = _keyToChange;
1074     setWindowTitle( qtr( "Hotkey for " ) + qfu( keyToChange)  );
1075
1076     QVBoxLayout *l = new QVBoxLayout( this );
1077     selected = new QLabel( qtr("Press the new keys for ")  + qfu(keyToChange) );
1078     warning = new QLabel();
1079     l->addWidget( selected , Qt::AlignCenter );
1080     l->addWidget( warning, Qt::AlignCenter );
1081
1082     QHBoxLayout *l2 = new QHBoxLayout();
1083     QPushButton *ok = new QPushButton( qtr("OK") );
1084     l2->addWidget( ok );
1085     QPushButton *cancel = new QPushButton( qtr("Cancel") );
1086     l2->addWidget( cancel );
1087
1088     BUTTONACT( ok, accept() );
1089     BUTTONACT( cancel, reject() );
1090
1091     l->addLayout( l2 );
1092 }
1093
1094 void KeyInputDialog::checkForConflicts( int i_vlckey )
1095 {
1096     conflicts = false;
1097     module_config_t *p_current = NULL;
1098     foreach( p_current, values )
1099     {
1100         if( p_current->value.i == i_vlckey && strcmp( p_current->psz_text,
1101                                                     keyToChange ) )
1102         {
1103             conflicts = true;
1104             break;
1105         }
1106     }
1107     if( conflicts )
1108     {
1109         warning->setText(
1110           qtr("Warning: the  key is already assigned to \"") +
1111           QString( p_current->psz_text ) + "\"" );
1112     }
1113     else warning->setText( "" );
1114 }
1115
1116 void KeyInputDialog::keyPressEvent( QKeyEvent *e )
1117 {
1118     if( e->key() == Qt::Key_Tab ) return;
1119     int i_vlck = qtEventToVLCKey( e );
1120     selected->setText( VLCKeyToString( i_vlck ) );
1121     checkForConflicts( i_vlck );
1122     keyValue = i_vlck;
1123 }
1124
1125 void KeyInputDialog::wheelEvent( QWheelEvent *e )
1126 {
1127     int i_vlck = qtWheelEventToVLCKey( e );
1128     selected->setText( VLCKeyToString( i_vlck ) );
1129     checkForConflicts( i_vlck );
1130     keyValue = i_vlck;
1131 }