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