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