]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/preferences_widgets.cpp
Qt4: use config_GetPszChoices() for module items
[vlc] / modules / gui / qt4 / components / preferences_widgets.cpp
1 /*****************************************************************************
2  * preferences_widgets.cpp : Widgets for preferences displays
3  ****************************************************************************
4  * Copyright (C) 2006-2011 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  *  - Validator for modulelist
29  */
30 #ifdef HAVE_CONFIG_H
31 # include "config.h"
32 #endif
33
34 #include "components/preferences_widgets.hpp"
35 #include "util/customwidgets.hpp"
36 #include "util/searchlineedit.hpp"
37 #include "util/qt_dirs.hpp"
38 #include <vlc_keys.h>
39 #include <vlc_intf_strings.h>
40 #include <vlc_modules.h>
41 #include <vlc_plugin.h>
42
43 #include <QString>
44 #include <QVariant>
45 #include <QGridLayout>
46 #include <QSlider>
47 #include <QFileDialog>
48 #include <QGroupBox>
49 #include <QTreeWidgetItem>
50 #include <QSignalMapper>
51 #include <QDialogButtonBox>
52 #include <QKeyEvent>
53 #include <QColorDialog>
54
55 #define MINWIDTH_BOX 90
56 #define LAST_COLUMN 10
57
58 QString formatTooltip(const QString & tooltip)
59 {
60     QString text = tooltip;
61     text.replace("\n", "<br/>");
62
63     QString formatted =
64     "<html><head><meta name=\"qrichtext\" content=\"1\" />"
65     "<style type=\"text/css\"> p, li { white-space: pre-wrap; } </style></head>"
66     "<body style=\" font-family:'Sans Serif'; "
67     "font-style:normal; text-decoration:none;\">"
68     "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; "
69     "margin-right:0px; -qt-block-indent:0; text-indent:0px;\">" +
70     text + "</p></body></html>";
71     return formatted;
72 }
73
74 ConfigControl *ConfigControl::createControl( vlc_object_t *p_this,
75                                              module_config_t *p_item,
76                                              QWidget *parent,
77                                              QGridLayout *l, int line )
78 {
79     ConfigControl *p_control = NULL;
80
81     switch( p_item->i_type )
82     {
83     case CONFIG_ITEM_MODULE:
84         p_control = new StringListConfigControl( p_this, p_item, parent );
85         break;
86     case CONFIG_ITEM_MODULE_CAT:
87         p_control = new ModuleConfigControl( p_this, p_item, parent );
88         break;
89     case CONFIG_ITEM_MODULE_LIST:
90         p_control = new ModuleListConfigControl( p_this, p_item, parent, false );
91         break;
92     case CONFIG_ITEM_MODULE_LIST_CAT:
93         p_control = new ModuleListConfigControl( p_this, p_item, parent, true );
94         break;
95     case CONFIG_ITEM_STRING:
96         if( p_item->list.psz_cb )
97             p_control = new StringListConfigControl( p_this, p_item, parent );
98         else
99             p_control = new StringConfigControl( p_this, p_item, parent, false );
100         break;
101     case CONFIG_ITEM_PASSWORD:
102         p_control = new StringConfigControl( p_this, p_item, parent, true );
103         break;
104     case CONFIG_ITEM_RGB:
105         p_control = new ColorConfigControl( p_this, p_item, parent );
106         break;
107     case CONFIG_ITEM_INTEGER:
108         if( p_item->list.i_cb )
109             p_control = new IntegerListConfigControl( p_this, p_item, parent, false );
110         else if( p_item->min.i || p_item->max.i )
111             p_control = new IntegerRangeConfigControl( p_this, p_item, parent );
112         else
113             p_control = new IntegerConfigControl( p_this, p_item, parent );
114         break;
115     case CONFIG_ITEM_LOADFILE:
116     case CONFIG_ITEM_SAVEFILE:
117         p_control = new FileConfigControl( p_this, p_item, parent );
118         break;
119     case CONFIG_ITEM_DIRECTORY:
120         p_control = new DirectoryConfigControl( p_this, p_item, parent );
121         break;
122     case CONFIG_ITEM_FONT:
123         p_control = new FontConfigControl( p_this, p_item, parent );
124         break;
125     case CONFIG_ITEM_KEY:
126         p_control = new KeySelectorControl( p_this, p_item, parent );
127         break;
128     case CONFIG_ITEM_BOOL:
129         p_control = new BoolConfigControl( p_this, p_item, parent );
130         break;
131     case CONFIG_ITEM_FLOAT:
132         if( p_item->min.f || p_item->max.f )
133             p_control = new FloatRangeConfigControl( p_this, p_item, parent );
134         else
135             p_control = new FloatConfigControl( p_this, p_item, parent );
136         break;
137     default:
138         break;
139     }
140     if ( p_control ) p_control->insertIntoExistingGrid( l, line );
141     return p_control;
142 }
143
144 /* Inserts controls into layouts
145    This is sub-optimal in the OO way, as controls's code still
146    depends on Layout classes. We should use layout inserters [friend]
147    classes, but it's unlikely we had to deal with a different layout.*/
148 void ConfigControl::insertInto( QBoxLayout *layout )
149 {
150     QGridLayout *sublayout = new QGridLayout();
151     fillGrid( sublayout, 0 );
152     layout->addLayout( sublayout );
153 }
154
155 void ConfigControl::insertIntoExistingGrid( QGridLayout *l, int line )
156 {
157     fillGrid( l, line );
158 }
159
160 /*******************************************************
161  * Simple widgets
162  *******************************************************/
163 InterfacePreviewWidget::InterfacePreviewWidget ( QWidget *parent ) : QLabel( parent )
164 {
165     setGeometry( 0, 0, 128, 100 );
166     setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
167 }
168
169 void InterfacePreviewWidget::setNormalPreview( bool b_minimal )
170 {
171     setPreview( ( b_minimal ) ? MINIMAL : COMPLETE );
172 }
173
174 void InterfacePreviewWidget::setPreview( enum_style e_style )
175 {
176     QString pixmapLocationString(":/prefsmenu/");
177
178     switch( e_style )
179     {
180     default:
181     case COMPLETE:
182         pixmapLocationString += "sample_complete";
183         break;
184     case MINIMAL:
185         pixmapLocationString += "sample_minimal";
186         break;
187     case SKINS:
188         pixmapLocationString += "sample_skins";
189         break;
190     }
191
192     setPixmap( QPixmap( pixmapLocationString ) );
193     update();
194 }
195
196
197 /**************************************************************************
198  * String-based controls
199  *************************************************************************/
200
201 void
202 VStringConfigControl::doApply()
203 {
204     config_PutPsz( p_this, getName(), qtu( getValue() ) );
205 }
206
207 /*********** String **************/
208 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
209                                           module_config_t *_p_item,
210                                           QWidget *_parent,
211                                           bool pwd ) :
212                            VStringConfigControl( _p_this, _p_item )
213 {
214     label = new QLabel( qtr(p_item->psz_text), _parent );
215     text = new QLineEdit( qfu(p_item->value.psz), _parent );
216     if( pwd ) text->setEchoMode( QLineEdit::Password );
217     finish();
218 }
219
220 void StringConfigControl::fillGrid( QGridLayout *l, int line )
221 {
222     l->addWidget( label, line, 0 );
223     l->setColumnMinimumWidth( 1, 10 );
224     l->addWidget( text, line, LAST_COLUMN, Qt::AlignRight );
225 }
226
227 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
228                                    module_config_t *_p_item,
229                                    QLabel *_label, QLineEdit *_text, bool pwd ):
230                            VStringConfigControl( _p_this, _p_item )
231 {
232     text = _text;
233     if( pwd ) text->setEchoMode( QLineEdit::Password );
234     label = _label;
235     finish( );
236 }
237
238 int VStringConfigControl::getType() const { return CONFIG_ITEM_STRING; }
239
240 void StringConfigControl::finish()
241 {
242     text->setText( qfu(p_item->value.psz) );
243     if( p_item->psz_longtext )
244     {
245         QString tipText = qtr(p_item->psz_longtext);
246         text->setToolTip( formatTooltip(tipText) );
247         if( label )
248             label->setToolTip( formatTooltip(tipText) );
249     }
250     if( label )
251         label->setBuddy( text );
252 }
253
254 /*********** File **************/
255 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
256                                       module_config_t *_p_item, QWidget *p ) :
257                            VStringConfigControl( _p_this, _p_item )
258 {
259     label = new QLabel( qtr(p_item->psz_text), p );
260     text = new QLineEdit( qfu(p_item->value.psz), p );
261     browse = new QPushButton( qtr( "Browse..." ), p );
262
263     BUTTONACT( browse, updateField() );
264
265     finish();
266 }
267
268 void FileConfigControl::fillGrid( QGridLayout *l, int line )
269 {
270     l->addWidget( label, line, 0 );
271     l->setColumnMinimumWidth( 1, 10 );
272     QHBoxLayout *textAndButton = new QHBoxLayout();
273     textAndButton->setMargin( 0 );
274     textAndButton->addWidget( text, 2 );
275     textAndButton->addWidget( browse, 0 );
276     l->addLayout( textAndButton, line, LAST_COLUMN, 0 );
277 }
278
279 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
280                                    module_config_t *_p_item,
281                                    QLabel *_label, QLineEdit *_text,
282                                    QPushButton *_button ):
283                            VStringConfigControl( _p_this, _p_item )
284 {
285     browse = _button;
286     text = _text;
287     label = _label;
288
289     BUTTONACT( browse, updateField() );
290
291     finish( );
292 }
293
294 void FileConfigControl::updateField()
295 {
296     QString file;
297
298     if (p_item->i_type == CONFIG_ITEM_SAVEFILE)
299         file = QFileDialog::getSaveFileName( NULL, qtr( "Save File" ),
300                                              QVLCUserDir( VLC_HOME_DIR ) );
301     else
302         file = QFileDialog::getOpenFileName( NULL, qtr( "Select File" ),
303                                              QVLCUserDir( VLC_HOME_DIR ) );
304
305     if( file.isNull() ) return;
306     text->setText( toNativeSeparators( file ) );
307 }
308
309 void FileConfigControl::finish()
310 {
311     text->setText( qfu(p_item->value.psz) );
312     if( p_item->psz_longtext )
313     {
314         QString tipText = qtr(p_item->psz_longtext);
315         text->setToolTip( formatTooltip(tipText) );
316         if( label )
317             label->setToolTip( formatTooltip(tipText) );
318     }
319     if( label )
320         label->setBuddy( text );
321 }
322
323 /********* String / Directory **********/
324 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
325                         module_config_t *_p_item, QWidget *p ) :
326      FileConfigControl( _p_this, _p_item, p )
327 {}
328
329 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
330                         module_config_t *_p_item, QLabel *_p_label,
331                         QLineEdit *_p_line, QPushButton *_p_button ):
332      FileConfigControl( _p_this, _p_item, _p_label, _p_line, _p_button)
333 {}
334
335 void DirectoryConfigControl::updateField()
336 {
337     QString dir = QFileDialog::getExistingDirectory( NULL,
338                       qtr( I_OP_SEL_DIR ),
339                       text->text().isEmpty() ?
340                         QVLCUserDir( VLC_HOME_DIR ) : text->text(),
341                   QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks );
342
343     if( dir.isNull() ) return;
344     text->setText( toNativeSepNoSlash( dir ) );
345 }
346
347 /********* String / Font **********/
348 FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
349                         module_config_t *_p_item, QWidget *p ) :
350      VStringConfigControl( _p_this, _p_item )
351 {
352     label = new QLabel( qtr(p_item->psz_text), p );
353     font = new QFontComboBox( p );
354     font->setCurrentFont( QFont( qfu( p_item->value.psz) ) );
355
356     if( p_item->psz_longtext )
357     {
358         label->setToolTip( formatTooltip( qtr(p_item->psz_longtext) ) );
359     }
360 }
361
362 void FontConfigControl::fillGrid( QGridLayout *l, int line )
363 {
364     l->addWidget( label, line, 0 );
365     l->addWidget( font, line, 1, 1, -1 );
366 }
367
368 FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
369                         module_config_t *_p_item, QLabel *_p_label,
370                         QFontComboBox *_p_font):
371      VStringConfigControl( _p_this, _p_item)
372 {
373     label = _p_label;
374     font = _p_font;
375     font->setCurrentFont( QFont( qfu( p_item->value.psz) ) );
376
377     if( p_item->psz_longtext )
378     {
379         label->setToolTip( formatTooltip( qtr(p_item->psz_longtext) ) );
380     }
381 }
382
383 /********* String / choice list **********/
384 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
385                module_config_t *_p_item, QWidget *p ) :
386                VStringConfigControl( _p_this, _p_item )
387 {
388     label = new QLabel( qtr(p_item->psz_text), p );
389     combo = new QComboBox( p );
390     combo->setMinimumWidth( MINWIDTH_BOX );
391     combo->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Preferred );
392
393     module_config_t *p_module_config = config_FindConfig( p_this, p_item->psz_name );
394
395     finish( p_module_config );
396 }
397
398 void StringListConfigControl::fillGrid( QGridLayout *l, int line )
399 {
400     l->addWidget( label, line, 0 );
401     l->addWidget( combo, line, LAST_COLUMN, Qt::AlignRight );
402     int i = 0;
403     foreach( QPushButton *button, buttons )
404         l->addWidget( button, line, LAST_COLUMN + i++,
405                       Qt::AlignRight );
406 }
407
408 void StringListConfigControl::comboIndexChanged( int i_index )
409 {
410     Q_UNUSED( i_index );
411     emit changed();
412 }
413
414 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
415                 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
416                 bool ) : VStringConfigControl( _p_this, _p_item )
417 {
418     combo = _combo;
419     label = _label;
420
421     module_config_t *p_module_config = config_FindConfig( p_this, getName() );
422
423     finish( p_module_config );
424 }
425
426 void StringListConfigControl::finish(module_config_t *p_module_config )
427 {
428     combo->setEditable( false );
429     CONNECT( combo, currentIndexChanged ( int ), this, comboIndexChanged( int ) );
430
431     if(!p_module_config) return;
432
433     char **values, **texts;
434     ssize_t count = config_GetPszChoices( p_this, p_item->psz_name,
435                                           &values, &texts );
436     for( ssize_t i = 0; i < count && texts; i++ )
437     {
438         if( texts[i] == NULL || values[i] == NULL )
439             continue;
440
441         combo->addItem( qfu(texts[i]), QVariant( qfu(values[i])) );
442         if( !strcmp( p_item->value.psz ? p_item->value.psz : "", values[i] ) )
443             combo->setCurrentIndex( combo->count() - 1 );
444         free( texts[i] );
445         free( values[i] );
446     }
447     free( texts );
448     free( values );
449
450     if( p_module_config->psz_longtext  )
451     {
452         QString tipText = qtr(p_module_config->psz_longtext);
453         combo->setToolTip( formatTooltip(tipText) );
454         if( label )
455             label->setToolTip( formatTooltip(tipText) );
456     }
457     if( label )
458         label->setBuddy( combo );
459 }
460
461 QString StringListConfigControl::getValue() const
462 {
463     return combo->itemData( combo->currentIndex() ).toString();
464 }
465
466 void setfillVLCConfigCombo( const char *configname, intf_thread_t *p_intf,
467                             QComboBox *combo )
468 {
469     module_config_t *p_config =
470                       config_FindConfig( VLC_OBJECT(p_intf), configname );
471     if( p_config == NULL )
472         return;
473
474     if( (p_config->i_type & 0xF0) == CONFIG_ITEM_STRING )
475     {
476         char **values, **texts;
477         ssize_t count = config_GetPszChoices(VLC_OBJECT(p_intf),
478                                              configname, &values, &texts);
479         for( ssize_t i = 0; i < count; i++ )
480         {
481             combo->addItem( qtr(texts[i]), QVariant(qfu(values[i])) );
482             if( !strcmp(p_config->value.psz, values[i]) )
483                 combo->setCurrentIndex( i );
484             free( texts[i] );
485             free( values[i] );
486         }
487         free( texts );
488         free( values );
489     }
490     else
491     {
492         int64_t *values;
493         char **texts;
494         ssize_t count = config_GetIntChoices(VLC_OBJECT(p_intf), configname,
495                                              &values, &texts);
496         for( ssize_t i = 0; i < count; i++ )
497         {
498             combo->addItem( qtr(texts[i]), QVariant(qlonglong(values[i])) );
499             if( p_config->value.i == values[i] )
500                 combo->setCurrentIndex( i );
501             free( texts[i] );
502         }
503         free( texts );
504     }
505
506     if( p_config->psz_longtext != NULL )
507         combo->setToolTip( qfu( p_config->psz_longtext ) );
508 }
509
510 /********* Module **********/
511 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
512                module_config_t *_p_item, QWidget *p ) :
513                VStringConfigControl( _p_this, _p_item )
514 {
515     label = new QLabel( qtr(p_item->psz_text), p );
516     combo = new QComboBox( p );
517     combo->setMinimumWidth( MINWIDTH_BOX );
518     finish( );
519 }
520
521 void ModuleConfigControl::fillGrid( QGridLayout *l, int line )
522 {
523     l->addWidget( label, line, 0 );
524     l->addWidget( combo, line, LAST_COLUMN, 0 );
525 }
526
527 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
528                 module_config_t *_p_item, QLabel *_label, QComboBox *_combo )
529                 : VStringConfigControl( _p_this, _p_item )
530 {
531     combo = _combo;
532     label = _label;
533     finish( );
534 }
535
536 void ModuleConfigControl::finish( )
537 {
538     combo->setEditable( false );
539
540     /* build a list of available modules */
541     size_t count;
542     module_t **p_list = module_list_get( &count );
543     combo->addItem( qtr("Default") );
544     for( size_t i = 0; i < count; i++ )
545     {
546         module_t *p_parser = p_list[i];
547
548         if( !strcmp( module_get_object( p_parser ), "main" ) ) continue;
549
550         unsigned confsize;
551         module_config_t *p_config;
552
553         p_config = module_config_get (p_parser, &confsize);
554         for (size_t i = 0; i < confsize; i++)
555         {
556             /* Hack: required subcategory is stored in i_min */
557             const module_config_t *p_cfg = p_config + i;
558             if( p_cfg->i_type == CONFIG_SUBCATEGORY &&
559                 p_cfg->value.i == p_item->min.i )
560                 combo->addItem( qtr( module_GetLongName( p_parser )),
561                                 QVariant( module_get_object( p_parser ) ) );
562             if( p_item->value.psz && !strcmp( p_item->value.psz,
563                                               module_get_object( p_parser ) ) )
564                 combo->setCurrentIndex( combo->count() - 1 );
565         }
566         module_config_free (p_config);
567     }
568     module_list_free( p_list );
569
570     if( p_item->psz_longtext )
571     {
572         QString tipText = qtr(p_item->psz_longtext);
573         combo->setToolTip( formatTooltip(tipText) );
574         if( label )
575             label->setToolTip( formatTooltip(tipText) );
576     }
577     if( label )
578         label->setBuddy( combo );
579 }
580
581 QString ModuleConfigControl::getValue() const
582 {
583     return combo->itemData( combo->currentIndex() ).toString();
584 }
585
586 /********* Module list **********/
587 ModuleListConfigControl::ModuleListConfigControl( vlc_object_t *_p_this,
588         module_config_t *_p_item, QWidget *p, bool bycat ) :
589     VStringConfigControl( _p_this, _p_item )
590 {
591     groupBox = NULL;
592
593     /* Special Hack */
594     if( !p_item->psz_text ) return;
595
596     groupBox = new QGroupBox ( qtr(p_item->psz_text), p );
597     text = new QLineEdit( p );
598     QGridLayout *layoutGroupBox = new QGridLayout( groupBox );
599
600     finish( bycat );
601
602     int boxline = 0;
603     foreach ( checkBoxListItem *it, modules )
604     {
605         layoutGroupBox->addWidget( it->checkBox, boxline / 2, boxline % 2 );
606         boxline++;
607     }
608
609     layoutGroupBox->addWidget( text, boxline, 0, 1, 2 );
610
611     if( p_item->psz_longtext )
612         text->setToolTip( formatTooltip( qtr( p_item->psz_longtext) ) );
613 }
614
615 void ModuleListConfigControl::fillGrid( QGridLayout *l, int line )
616 {
617     l->addWidget( groupBox, line, 0, 1, -1 );
618 }
619
620 ModuleListConfigControl::~ModuleListConfigControl()
621 {
622     qDeleteAll( modules );
623     modules.clear();
624     delete groupBox;
625 }
626
627 void ModuleListConfigControl::checkbox_lists( module_t *p_parser )
628 {
629     const char *help = module_get_help( p_parser );
630     checkbox_lists( qtr( module_GetLongName( p_parser ) ),
631                     help != NULL ? qtr( help ): "",
632                     module_get_object( p_parser ) );
633 }
634
635 void ModuleListConfigControl::checkbox_lists( QString label, QString help, const char* psz_module )
636 {
637     QCheckBox *cb = new QCheckBox( label );
638     checkBoxListItem *cbl = new checkBoxListItem;
639
640     CONNECT( cb, stateChanged( int ), this, onUpdate() );
641     if( !help.isEmpty() )
642         cb->setToolTip( formatTooltip( help ) );
643     cbl->checkBox = cb;
644
645     cbl->psz_module = strdup( psz_module );
646     modules.append( cbl );
647
648     if( p_item->value.psz && strstr( p_item->value.psz, cbl->psz_module ) )
649         cbl->checkBox->setChecked( true );
650 }
651
652 void ModuleListConfigControl::finish( bool bycat )
653 {
654     /* build a list of available modules */
655     size_t count;
656     module_t **p_list = module_list_get( &count );
657     for( size_t i = 0; i < count; i++ )
658     {
659         module_t *p_parser = p_list[i];
660
661         if( bycat )
662         {
663             if( !strcmp( module_get_object( p_parser ), "main" ) ) continue;
664
665             unsigned confsize;
666             module_config_t *p_config = module_config_get (p_parser, &confsize);
667
668             for (size_t i = 0; i < confsize; i++)
669             {
670                 module_config_t *p_cfg = p_config + i;
671                 /* Hack: required subcategory is stored in i_min */
672                 if( p_cfg->i_type == CONFIG_SUBCATEGORY &&
673                         p_cfg->value.i == p_item->min.i )
674                 {
675                     checkbox_lists( p_parser );
676                 }
677
678                 /* Parental Advisory HACK:
679                  * Selecting HTTP, RC and Telnet interfaces is difficult now
680                  * since they are just the lua interface module */
681                 if( p_cfg->i_type == CONFIG_SUBCATEGORY &&
682                     !strcmp( module_get_object( p_parser ), "lua" ) &&
683                     !strcmp( p_item->psz_name, "extraintf" ) &&
684                     p_cfg->value.i == p_item->min.i )
685                 {
686                     checkbox_lists( "Web", "Lua HTTP", "http" );
687                     checkbox_lists( "Telnet", "Lua Telnet", "telnet" );
688 #ifndef WIN32
689                     checkbox_lists( "Console", "Lua CLI", "cli" );
690 #endif
691                 }
692             }
693             module_config_free (p_config);
694         }
695         else if( module_provides( p_parser, p_item->psz_type ) )
696         {
697             checkbox_lists(p_parser);
698         }
699     }
700     module_list_free( p_list );
701
702     if( p_item->psz_longtext )
703     {
704         QString tipText = qtr(p_item->psz_longtext);
705
706         text->setToolTip( formatTooltip(tipText) );
707         assert( groupBox );
708         groupBox->setToolTip( formatTooltip(tipText) );
709    }
710 }
711
712 QString ModuleListConfigControl::getValue() const
713 {
714     assert( text );
715     return text->text();
716 }
717
718 void ModuleListConfigControl::changeVisibility( bool b )
719 {
720     foreach ( checkBoxListItem *it, modules )
721         it->checkBox->setVisible( b );
722     groupBox->setVisible( b );
723 }
724
725 void ModuleListConfigControl::onUpdate()
726 {
727     text->clear();
728     bool first = true;
729
730     foreach ( checkBoxListItem *it, modules )
731     {
732         if( it->checkBox->isChecked() )
733         {
734             if( first )
735             {
736                 text->setText( text->text() + it->psz_module );
737                 first = false;
738             }
739             else
740             {
741                 text->setText( text->text() + ":" + it->psz_module );
742             }
743         }
744     }
745 }
746
747 /**************************************************************************
748  * Integer-based controls
749  *************************************************************************/
750
751 void
752 VIntConfigControl::doApply()
753 {
754     config_PutInt( p_this, getName(), getValue() );
755 }
756
757 /*********** Integer **************/
758 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
759                                             module_config_t *_p_item, QWidget *p ) :
760                            VIntConfigControl( _p_this, _p_item )
761 {
762     label = new QLabel( qtr(p_item->psz_text), p );
763     spin = new QSpinBox( p ); spin->setMinimumWidth( MINWIDTH_BOX );
764     spin->setAlignment( Qt::AlignRight );
765     spin->setMaximumWidth( MINWIDTH_BOX );
766     finish();
767 }
768
769 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
770                                             module_config_t *_p_item,
771                                             QLabel *_label, QSpinBox *_spin ) :
772                                       VIntConfigControl( _p_this, _p_item )
773 {
774     spin = _spin;
775     label = _label;
776     finish();
777 }
778
779 void IntegerConfigControl::fillGrid( QGridLayout *l, int line )
780 {
781     l->addWidget( label, line, 0 );
782     l->addWidget( spin, line, LAST_COLUMN, Qt::AlignRight );
783 }
784
785 void IntegerConfigControl::finish()
786 {
787     spin->setMaximum( 2000000000 );
788     spin->setMinimum( -2000000000 );
789     spin->setValue( p_item->value.i );
790
791     if( p_item->psz_longtext )
792     {
793         QString tipText = qtr(p_item->psz_longtext);
794         spin->setToolTip( formatTooltip(tipText) );
795         if( label )
796             label->setToolTip( formatTooltip(tipText) );
797     }
798     if( label )
799         label->setBuddy( spin );
800 }
801
802 int IntegerConfigControl::getValue() const
803 {
804     return spin->value();
805 }
806
807 int VIntConfigControl::getType() const { return CONFIG_ITEM_INTEGER; }
808
809 /********* Integer range **********/
810 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
811                                             module_config_t *_p_item, QWidget *p ) :
812             IntegerConfigControl( _p_this, _p_item, p )
813 {
814     finish();
815 }
816
817 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
818                                             module_config_t *_p_item,
819                                             QLabel *_label, QSpinBox *_spin ) :
820             IntegerConfigControl( _p_this, _p_item, _label, _spin )
821 {
822     finish();
823 }
824
825 void IntegerRangeConfigControl::finish()
826 {
827     spin->setMaximum( p_item->max.i > INT_MAX ? INT_MAX : p_item->max.i );
828     spin->setMinimum( p_item->min.i < INT_MIN ? INT_MIN : p_item->min.i );
829 }
830
831 IntegerRangeSliderConfigControl::IntegerRangeSliderConfigControl(
832                                             vlc_object_t *_p_this,
833                                             module_config_t *_p_item,
834                                             QLabel *_label, QSlider *_slider ):
835                     VIntConfigControl( _p_this, _p_item )
836 {
837     slider = _slider;
838     label = _label;
839     slider->setMaximum( p_item->max.i > INT_MAX ? INT_MAX : p_item->max.i );
840     slider->setMinimum( p_item->min.i < INT_MIN ? INT_MIN : p_item->min.i );
841     slider->setValue( p_item->value.i );
842     if( p_item->psz_longtext )
843     {
844         QString tipText = qtr(p_item->psz_longtext);
845         slider->setToolTip( formatTooltip(tipText) );
846         if( label )
847             label->setToolTip( formatTooltip(tipText) );
848     }
849     if( label )
850         label->setBuddy( slider );
851 }
852
853 int IntegerRangeSliderConfigControl::getValue() const
854 {
855         return slider->value();
856 }
857
858
859 /********* Integer / choice list **********/
860 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
861                module_config_t *_p_item, QWidget *p, bool ) :
862                VIntConfigControl( _p_this, _p_item )
863 {
864     label = new QLabel( qtr(p_item->psz_text), p );
865     combo = new QComboBox( p );
866     combo->setMinimumWidth( MINWIDTH_BOX );
867
868     module_config_t *p_module_config = config_FindConfig( p_this, p_item->psz_name );
869
870     finish( p_module_config );
871 }
872
873 void IntegerListConfigControl::fillGrid( QGridLayout *l, int line )
874 {
875     l->addWidget( label, line, 0 );
876     l->addWidget( combo, line, LAST_COLUMN, Qt::AlignRight );
877     int i = 0;
878     foreach( QPushButton *button, buttons )
879         l->addWidget( button, line, LAST_COLUMN + i++,
880                       Qt::AlignRight );
881 }
882
883 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
884                 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
885                 bool ) : VIntConfigControl( _p_this, _p_item )
886 {
887     combo = _combo;
888     label = _label;
889
890     module_config_t *p_module_config = config_FindConfig( p_this, getName() );
891
892     finish( p_module_config );
893 }
894
895 void IntegerListConfigControl::finish(module_config_t *p_module_config )
896 {
897     combo->setEditable( false );
898
899     if(!p_module_config) return;
900
901     int64_t *values;
902     char **texts;
903     ssize_t count = config_GetIntChoices( p_this, p_module_config->psz_name,
904                                           &values, &texts );
905     for( ssize_t i = 0; i < count; i++ )
906     {
907         combo->addItem( qtr(texts[i]), qlonglong(values[i]) );
908         if( p_module_config->value.i == values[i] )
909             combo->setCurrentIndex( combo->count() - 1 );
910         free( texts[i] );
911     }
912     free( texts );
913     free( values );
914     if( p_item->psz_longtext )
915     {
916         QString tipText = qtr(p_item->psz_longtext );
917         combo->setToolTip( formatTooltip(tipText) );
918         if( label )
919             label->setToolTip( formatTooltip(tipText) );
920     }
921     if( label )
922         label->setBuddy( combo );
923 }
924
925 int IntegerListConfigControl::getValue() const
926 {
927     return combo->itemData( combo->currentIndex() ).toInt();
928 }
929
930 /*********** Boolean **************/
931 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
932                                       module_config_t *_p_item, QWidget *p ) :
933                     VIntConfigControl( _p_this, _p_item )
934 {
935     checkbox = new QCheckBox( qtr(p_item->psz_text), p );
936     finish();
937 }
938
939 void BoolConfigControl::fillGrid( QGridLayout *l, int line )
940 {
941     l->addWidget( checkbox, line, 0, 1, -1, 0 );
942 }
943
944 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
945                                       module_config_t *_p_item,
946                                       QLabel *_label,
947                                       QAbstractButton *_checkbox ) :
948                    VIntConfigControl( _p_this, _p_item )
949 {
950     checkbox = _checkbox;
951     VLC_UNUSED( _label );
952     finish();
953 }
954
955 int BoolConfigControl::getType() const { return CONFIG_ITEM_BOOL; }
956
957 void BoolConfigControl::finish()
958 {
959     checkbox->setChecked( p_item->value.i );
960     if( p_item->psz_longtext )
961         checkbox->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
962 }
963
964 int BoolConfigControl::getValue() const
965 {
966     return checkbox->isChecked();
967 }
968
969 /************* Color *************/
970 ColorConfigControl::ColorConfigControl( vlc_object_t *_p_this,
971                                         module_config_t *_p_item, QWidget *p ) :
972                            VIntConfigControl( _p_this, _p_item )
973 {
974     label = new QLabel( p );
975     color_but = new QToolButton( p );
976     finish();
977 }
978
979 void ColorConfigControl::fillGrid( QGridLayout *l, int line )
980 {
981     l->addWidget( label, line, 0 );
982     l->addWidget( color_but, line, LAST_COLUMN, Qt::AlignRight );
983 }
984
985 ColorConfigControl::ColorConfigControl( vlc_object_t *_p_this,
986                                             module_config_t *_p_item,
987                                             QLabel *_label, QAbstractButton *_color ):
988                                       VIntConfigControl( _p_this, _p_item )
989 {
990     label = _label;
991     color_but = _color;
992     finish();
993 }
994
995 void ColorConfigControl::finish()
996 {
997     i_color = p_item->value.i;
998
999     color_px = new QPixmap( 34, 20 );
1000     color_px->fill( QColor( i_color ) );
1001     color_but->setIcon( QIcon( *color_px ) );
1002     color_but->setMinimumWidth( 40 );
1003
1004     label->setText( qtr(p_item->psz_text) );
1005     if( p_item->psz_longtext )
1006     {
1007         label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
1008         color_but->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
1009     }
1010
1011     BUTTONACT( color_but, selectColor() );
1012 }
1013
1014 int ColorConfigControl::getValue() const
1015 {
1016     return i_color;
1017 }
1018
1019 void ColorConfigControl::selectColor()
1020 {
1021     QColor color = QColorDialog::getColor( QColor( i_color ) );
1022     if( color.isValid() )
1023     {
1024         i_color = (color.red() << 16) + (color.green() << 8) + color.blue();
1025
1026         color_px->fill( QColor( i_color ) );
1027         color_but->setIcon( QIcon( *color_px ) );
1028     }
1029 }
1030
1031
1032 /**************************************************************************
1033  * Float-based controls
1034  *************************************************************************/
1035
1036 void
1037 VFloatConfigControl::doApply()
1038 {
1039     config_PutFloat( p_this, getName(), getValue() );
1040 }
1041
1042 /*********** Float **************/
1043 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
1044                                         module_config_t *_p_item, QWidget *p ) :
1045                     VFloatConfigControl( _p_this, _p_item )
1046 {
1047     label = new QLabel( qtr(p_item->psz_text), p );
1048     spin = new QDoubleSpinBox( p );
1049     spin->setMinimumWidth( MINWIDTH_BOX );
1050     spin->setMaximumWidth( MINWIDTH_BOX );
1051     spin->setAlignment( Qt::AlignRight );
1052     finish();
1053 }
1054
1055 void FloatConfigControl::fillGrid( QGridLayout *l, int line )
1056 {
1057     l->addWidget( label, line, 0 );
1058     l->addWidget( spin, line, LAST_COLUMN, Qt::AlignRight );
1059 }
1060
1061 int VFloatConfigControl::getType() const { return CONFIG_ITEM_FLOAT; }
1062
1063 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
1064                                         module_config_t *_p_item,
1065                                         QLabel *_label,
1066                                         QDoubleSpinBox *_spin ) :
1067                     VFloatConfigControl( _p_this, _p_item )
1068 {
1069     spin = _spin;
1070     label = _label;
1071     finish();
1072 }
1073
1074 void FloatConfigControl::finish()
1075 {
1076     spin->setMaximum( 2000000000. );
1077     spin->setMinimum( -2000000000. );
1078     spin->setSingleStep( 0.1 );
1079     spin->setValue( (double)p_item->value.f );
1080     if( p_item->psz_longtext )
1081     {
1082         QString tipText = qtr(p_item->psz_longtext);
1083         spin->setToolTip( formatTooltip(tipText) );
1084         if( label )
1085             label->setToolTip( formatTooltip(tipText) );
1086     }
1087     if( label )
1088         label->setBuddy( spin );
1089 }
1090
1091 float FloatConfigControl::getValue() const
1092 {
1093     return (float)spin->value();
1094 }
1095
1096 /*********** Float with range **************/
1097 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
1098                                         module_config_t *_p_item, QWidget *p ) :
1099                 FloatConfigControl( _p_this, _p_item, p )
1100 {
1101     finish();
1102 }
1103
1104 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
1105                                         module_config_t *_p_item,
1106                                         QLabel *_label,
1107                                         QDoubleSpinBox *_spin ) :
1108                 FloatConfigControl( _p_this, _p_item, _label, _spin )
1109 {
1110     finish();
1111 }
1112
1113 void FloatRangeConfigControl::finish()
1114 {
1115     spin->setMaximum( (double)p_item->max.f );
1116     spin->setMinimum( (double)p_item->min.f );
1117 }
1118
1119
1120 /**********************************************************************
1121  * Key selector widget
1122  **********************************************************************/
1123 KeySelectorControl::KeySelectorControl( vlc_object_t *_p_this,
1124                                       module_config_t *_p_item, QWidget *p ) :
1125                                 ConfigControl( _p_this, _p_item )
1126
1127 {
1128     label = new QLabel(
1129         qtr( "Select or double click an action to change the associated "
1130              "hotkey. Use delete key to remove hotkeys"), p );
1131
1132     searchLabel = new QLabel( qtr( "Search" ), p );
1133     actionSearch = new SearchLineEdit();
1134
1135     table = new QTreeWidget( p );
1136     table->setColumnCount(3);
1137     table->headerItem()->setText( 0, qtr( "Action" ) );
1138     table->headerItem()->setText( 1, qtr( "Hotkey" ) );
1139     table->headerItem()->setToolTip( 1, qtr( "Application level hotkey" ) );
1140     table->headerItem()->setText( 2, qtr( "Global" ) );
1141     table->headerItem()->setToolTip( 2, qtr( "Desktop level hotkey" ) );
1142     table->setAlternatingRowColors( true );
1143     table->setSelectionBehavior( QAbstractItemView::SelectItems );
1144
1145     table->installEventFilter( this );
1146
1147     finish();
1148
1149     CONNECT( actionSearch, textChanged( const QString& ),
1150              this, filter( const QString& ) );
1151 }
1152
1153 void KeySelectorControl::fillGrid( QGridLayout *l, int line )
1154 {
1155     QGridLayout *gLayout = new QGridLayout();
1156     gLayout->addWidget( label, 0, 0, 1, 4 );
1157     gLayout->addWidget( searchLabel, 1, 0, 1, 2 );
1158     gLayout->addWidget( actionSearch, 1, 2, 1, 2 );
1159     gLayout->addWidget( table, 2, 0, 1, 4 );
1160     l->addLayout( gLayout, line, 0, 1, -1 );
1161 }
1162
1163 int KeySelectorControl::getType() const { return CONFIG_ITEM_KEY; }
1164
1165 void KeySelectorControl::finish()
1166 {
1167     if( label && p_item->psz_longtext )
1168         label->setToolTip( formatTooltip( qtr( p_item->psz_longtext ) ) );
1169
1170     /* Fill the table */
1171
1172     /* Get the main Module */
1173     module_t *p_main = module_get_main();
1174     assert( p_main );
1175
1176     /* Access to the module_config_t */
1177     unsigned confsize;
1178     module_config_t *p_config;
1179
1180     p_config = module_config_get (p_main, &confsize);
1181
1182     QMap<QString, QString> global_keys;
1183     for (size_t i = 0; i < confsize; i++)
1184     {
1185         module_config_t *p_config_item = p_config + i;
1186
1187         /* If we are a (non-global) key option not empty */
1188         if( CONFIG_ITEM(p_config_item->i_type) && p_config_item->psz_name != NULL
1189          && !strncmp( p_config_item->psz_name , "key-", 4 )
1190          && !EMPTY_STR( p_config_item->psz_text ) )
1191         {
1192             /*
1193                Each tree item has:
1194                 - QString text in column 0
1195                 - QString name in data of column 0
1196                 - KeyValue in String in column 1
1197              */
1198             QTreeWidgetItem *treeItem = new QTreeWidgetItem();
1199             treeItem->setText( 0, qtr( p_config_item->psz_text ) );
1200             treeItem->setData( 0, Qt::UserRole,
1201                                QVariant( qfu( p_config_item->psz_name ) ) );
1202
1203             QString keys = qfu( p_config_item->value.psz );
1204             treeItem->setText( 1, keys );
1205             treeItem->setToolTip( 1, qtr("Double click to change") );
1206             treeItem->setToolTip( 2, qtr("Double click to change") );
1207             treeItem->setData( 1, Qt::UserRole, QVariant( keys ) );
1208             table->addTopLevelItem( treeItem );
1209             continue;
1210         }
1211
1212         if( CONFIG_ITEM(p_config_item->i_type) && p_config_item->psz_name != NULL
1213          && !strncmp( p_config_item->psz_name , "global-key", 10 )
1214          && !EMPTY_STR( p_config_item->psz_text )
1215          && !EMPTY_STR( p_config_item->value.psz ) )
1216         {
1217             global_keys.insertMulti( qtr( p_config_item->psz_text ), qfu( p_config_item->value.psz ) );
1218         }
1219     }
1220
1221     QMap<QString, QString>::const_iterator i = global_keys.constBegin();
1222     while (i != global_keys.constEnd())
1223     {
1224         QList<QTreeWidgetItem *> list = table->findItems( i.key(), Qt::MatchExactly|Qt::MatchWrap, 0 );
1225         if( list.count() >= 1 )
1226         {
1227             QString keys = i.value();
1228             list[0]->setText( 2, keys );
1229             list[0]->setData( 2, Qt::UserRole, keys );
1230         }
1231         if( list.count() >= 2 )
1232             msg_Dbg( p_this, "This is probably wrong, %s", qtu(i.key()) );
1233
1234         i++;
1235     }
1236
1237     module_config_free (p_config);
1238
1239     table->resizeColumnToContents( 0 );
1240
1241     CONNECT( table, itemActivated( QTreeWidgetItem *, int ),
1242              this, selectKey( QTreeWidgetItem *, int ) );
1243 }
1244
1245 void KeySelectorControl::filter( const QString &qs_search )
1246 {
1247     QList<QTreeWidgetItem *> resultList =
1248             table->findItems( qs_search, Qt::MatchContains, 0 );
1249     for( int i = 0; i < table->topLevelItemCount(); i++ )
1250     {
1251         table->topLevelItem( i )->setHidden(
1252                 !resultList.contains( table->topLevelItem( i ) ) );
1253     }
1254 }
1255
1256 void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem, int column )
1257 {
1258     /* This happens when triggered by ClickEater */
1259     if( keyItem == NULL ) keyItem = table->currentItem();
1260
1261     /* This can happen when nothing is selected on the treeView
1262        and the shortcutValue is clicked */
1263     if( !keyItem ) return;
1264
1265     /* If clicked on the first column, assuming user wants the normal hotkey */
1266     if( column == 0 ) column = 1;
1267
1268     bool b_global = ( column == 2 );
1269
1270     /* Launch a small dialog to ask for a new key */
1271     KeyInputDialog *d = new KeyInputDialog( table, keyItem->text( 0 ), table, b_global );
1272     d->exec();
1273
1274     if( d->result() == QDialog::Accepted )
1275     {
1276         QString newKey = VLCKeyToString( d->keyValue );
1277
1278         /* In case of conflict, reset other keys*/
1279         if( d->conflicts )
1280         {
1281             QTreeWidgetItem *it;
1282             for( int i = 0; i < table->topLevelItemCount() ; i++ )
1283             {
1284                 it = table->topLevelItem(i);
1285                 if( ( keyItem != it ) &&
1286                     ( it->data( 1 + b_global, Qt::UserRole ).toString() == newKey ) )
1287                 {
1288                     it->setData( 1 + b_global, Qt::UserRole,
1289                                  QVariant( qfu( "Unset" ) ) );
1290                     it->setText( 1 + b_global, qtr( "Unset" ) );
1291                 }
1292             }
1293         }
1294
1295         keyItem->setText( column, newKey );
1296         keyItem->setData( column, Qt::UserRole, newKey );
1297     }
1298     delete d;
1299 }
1300
1301 void KeySelectorControl::doApply()
1302 {
1303     QTreeWidgetItem *it;
1304     for( int i = 0; i < table->topLevelItemCount() ; i++ )
1305     {
1306         it = table->topLevelItem(i);
1307         if( it->data( 1, Qt::UserRole ).toInt() >= 0 )
1308             config_PutPsz( p_this,
1309                            qtu( it->data( 0, Qt::UserRole ).toString() ),
1310                            qtu( it->data( 1, Qt::UserRole ).toString() ) );
1311         if( !it->data( 2, Qt::UserRole ).toString().isEmpty() )
1312         {
1313             config_PutPsz( p_this,
1314                            qtu( "global-" + it->data( 0, Qt::UserRole ).toString() ),
1315                            qtu( it->data( 2, Qt::UserRole ).toString() ) );
1316         }
1317
1318     }
1319 }
1320
1321 bool KeySelectorControl::eventFilter( QObject *obj, QEvent *e )
1322 {
1323     if( obj != table || e->type() != QEvent::KeyPress )
1324         return ConfigControl::eventFilter(obj, e);
1325
1326     QKeyEvent *keyEv = static_cast<QKeyEvent*>(e);
1327     QTreeWidget *aTable = static_cast<QTreeWidget *>(obj);
1328     if( keyEv->key() == Qt::Key_Escape )
1329     {
1330         aTable->clearFocus();
1331         return true;
1332     }
1333     else if( keyEv->key() == Qt::Key_Return ||
1334              keyEv->key() == Qt::Key_Enter )
1335     {
1336         selectKey( aTable->currentItem(), aTable->currentColumn() );
1337         return true;
1338     }
1339     else if( keyEv->key() == Qt::Key_Delete )
1340     {
1341         if( aTable->currentColumn() != 0 )
1342         {
1343             aTable->currentItem()->setText( aTable->currentColumn(), NULL );
1344             aTable->currentItem()->setData( aTable->currentColumn(), Qt::UserRole, QVariant() );
1345         }
1346         return true;
1347     }
1348     else
1349         return false;
1350 }
1351
1352
1353 /**
1354  * Class KeyInputDialog
1355  **/
1356 KeyInputDialog::KeyInputDialog( QTreeWidget *_table,
1357                                 const QString& keyToChange,
1358                                 QWidget *_parent,
1359                                 bool _b_global ) :
1360                                 QDialog( _parent ), keyValue(0), b_global( _b_global )
1361 {
1362     setModal( true );
1363     conflicts = false;
1364
1365     table = _table;
1366     setWindowTitle( ( b_global ? qtr( "Global" ) + QString(" ") : "" )
1367                     + qtr( "Hotkey change" ) );
1368     setWindowRole( "vlc-key-input" );
1369
1370     QVBoxLayout *vLayout = new QVBoxLayout( this );
1371     selected = new QLabel( qtr( "Press the new key or combination for " )
1372                            + QString("<b>%1</b>").arg( keyToChange ) );
1373     vLayout->addWidget( selected , Qt::AlignCenter );
1374
1375     warning = new QLabel;
1376     warning->hide();
1377     vLayout->insertWidget( 1, warning );
1378
1379     buttonBox = new QDialogButtonBox;
1380     QPushButton *ok = new QPushButton( qtr("Assign") );
1381     QPushButton *cancel = new QPushButton( qtr("Cancel") );
1382     buttonBox->addButton( ok, QDialogButtonBox::AcceptRole );
1383     buttonBox->addButton( cancel, QDialogButtonBox::RejectRole );
1384     ok->setDefault( true );
1385
1386     vLayout->addWidget( buttonBox );
1387     buttonBox->hide();
1388
1389     CONNECT( buttonBox, accepted(), this, accept() );
1390     CONNECT( buttonBox, rejected(), this, reject() );
1391 }
1392
1393 void KeyInputDialog::checkForConflicts( int i_vlckey )
1394 {
1395     QList<QTreeWidgetItem *> conflictList =
1396         table->findItems( VLCKeyToString( i_vlckey ), Qt::MatchExactly,
1397                           b_global ? 2 : 1 );
1398
1399     if( conflictList.count() &&
1400         !conflictList[0]->data( b_global ? 2 : 1, Qt::UserRole ).toString().isEmpty() &&
1401          conflictList[0]->data( b_global ? 2 : 1, Qt::UserRole ).toString() != "Unset" )
1402     {
1403         warning->setText( qtr("Warning: this key or combination is already assigned to ") +
1404                 QString( "\"<b>%1</b>\"" ).arg( conflictList[0]->text( 0 ) ) );
1405         warning->show();
1406         buttonBox->show();
1407
1408         conflicts = true;
1409     }
1410     else accept();
1411 }
1412
1413 void KeyInputDialog::keyPressEvent( QKeyEvent *e )
1414 {
1415     if( e->key() == Qt::Key_Tab ||
1416         e->key() == Qt::Key_Shift ||
1417         e->key() == Qt::Key_Control ||
1418         e->key() == Qt::Key_Meta ||
1419         e->key() == Qt::Key_Alt ||
1420         e->key() == Qt::Key_AltGr )
1421         return;
1422     int i_vlck = qtEventToVLCKey( e );
1423     selected->setText( qtr( "Key or combination: " )
1424                 + QString("<b>%1</b>").arg( VLCKeyToString( i_vlck ) ) );
1425     checkForConflicts( i_vlck );
1426     keyValue = i_vlck;
1427 }
1428
1429 void KeyInputDialog::wheelEvent( QWheelEvent *e )
1430 {
1431     int i_vlck = qtWheelEventToVLCKey( e );
1432     selected->setText( qtr( "Key: " ) + VLCKeyToString( i_vlck ) );
1433     checkForConflicts( i_vlck );
1434     keyValue = i_vlck;
1435 }