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