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