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