1 /*****************************************************************************
2 * preferences_widgets.cpp : Widgets for preferences displays
3 ****************************************************************************
4 * Copyright (C) 2006-2007 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
8 * Antoine Cellerier <dionoea@videolan.org>
9 * Jean-Baptiste Kempf <jb@videolan.org>
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.
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.
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 *****************************************************************************/
28 * - Finish implementation (see WX)
29 * - Improvements over WX
30 * - Password field implementation (through "pwd" bool param
31 * - Validator for modulelist
32 * - Implement update stuff using a general Updated signal
35 #include "components/preferences_widgets.hpp"
36 #include "util/customwidgets.hpp"
42 #include <QDoubleSpinBox>
45 #include <QGridLayout>
46 #include <QPushButton>
48 #include <QFileDialog>
52 ConfigControl *ConfigControl::createControl( vlc_object_t *p_this,
53 module_config_t *p_item,
57 return createControl( p_this, p_item, parent, NULL, i );
60 ConfigControl *ConfigControl::createControl( vlc_object_t *p_this,
61 module_config_t *p_item,
63 QGridLayout *l, int &line )
65 ConfigControl *p_control = NULL;
66 if( p_item->psz_current ) return NULL;
68 switch( p_item->i_type )
70 case CONFIG_ITEM_MODULE:
71 p_control = new ModuleConfigControl( p_this, p_item, parent, false,
74 case CONFIG_ITEM_MODULE_CAT:
75 p_control = new ModuleConfigControl( p_this, p_item, parent, true,
78 case CONFIG_ITEM_MODULE_LIST:
79 p_control = new ModuleListConfigControl( p_this, p_item, parent, false,
82 case CONFIG_ITEM_MODULE_LIST_CAT:
83 p_control = new ModuleListConfigControl( p_this, p_item, parent, true,
86 case CONFIG_ITEM_STRING:
88 p_control = new StringConfigControl( p_this, p_item, parent,
91 p_control = new StringListConfigControl( p_this, p_item,
92 parent, false, l, line );
94 case CONFIG_ITEM_INTEGER:
96 p_control = new IntegerListConfigControl( p_this, p_item,
97 parent, false, l, line );
98 else if( p_item->min.i || p_item->max.i )
99 p_control = new IntegerRangeConfigControl( p_this, p_item, parent,
102 p_control = new IntegerConfigControl( p_this, p_item, parent,
105 case CONFIG_ITEM_FILE:
106 p_control = new FileConfigControl( p_this, p_item, parent, l,
109 case CONFIG_ITEM_DIRECTORY:
110 p_control = new DirectoryConfigControl( p_this, p_item, parent, l,
113 case CONFIG_ITEM_KEY:
114 p_control = new KeySelectorControl( p_this, p_item, parent, l, line );
116 case CONFIG_ITEM_BOOL:
117 p_control = new BoolConfigControl( p_this, p_item, parent, l, line );
119 case CONFIG_ITEM_FLOAT:
120 if( p_item->min.f || p_item->max.f )
121 p_control = new FloatRangeConfigControl( p_this, p_item, parent,
124 p_control = new FloatConfigControl( p_this, p_item, parent,
133 void ConfigControl::doApply( intf_thread_t *p_intf )
139 VIntConfigControl *vicc = qobject_cast<VIntConfigControl *>(this);
141 config_PutInt( p_intf, vicc->getName(), vicc->getValue() );
146 VFloatConfigControl *vfcc =
147 qobject_cast<VFloatConfigControl *>(this);
149 config_PutFloat( p_intf, vfcc->getName(), vfcc->getValue() );
154 VStringConfigControl *vscc =
155 qobject_cast<VStringConfigControl *>(this);
157 config_PutPsz( p_intf, vscc->getName(), qta( vscc->getValue() ) );
162 KeySelectorControl *ksc = qobject_cast<KeySelectorControl *>(this);
169 /**************************************************************************
170 * String-based controls
171 *************************************************************************/
173 /*********** String **************/
174 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
175 module_config_t *_p_item,
176 QWidget *_parent, QGridLayout *l,
177 int &line, bool pwd ) :
178 VStringConfigControl( _p_this, _p_item, _parent )
180 label = new QLabel( qfu(p_item->psz_text) );
181 text = new QLineEdit( qfu(p_item->value.psz) );
186 QHBoxLayout *layout = new QHBoxLayout();
187 layout->addWidget( label, 0 ); layout->addWidget( text, 1 );
188 widget->setLayout( layout );
192 l->addWidget( label, line, 0 ); l->addWidget( text, line, 1 );
196 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
197 module_config_t *_p_item,
198 QLabel *_label, QLineEdit *_text, bool pwd ):
199 VStringConfigControl( _p_this, _p_item )
206 void StringConfigControl::finish()
208 text->setText( qfu(p_item->value.psz) );
209 text->setToolTip( qfu(p_item->psz_longtext) );
211 label->setToolTip( qfu(p_item->psz_longtext) );
214 /*********** File **************/
215 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
216 module_config_t *_p_item,
217 QWidget *_parent, QGridLayout *l,
218 int &line, bool pwd ) :
219 VStringConfigControl( _p_this, _p_item, _parent )
221 label = new QLabel( qfu(p_item->psz_text) );
222 text = new QLineEdit( qfu(p_item->value.psz) );
223 browse = new QPushButton( qtr( "Browse" ) );
225 BUTTONACT( browse, updateField() );
231 QHBoxLayout *layout = new QHBoxLayout();
232 layout->addWidget( label, 0 ); layout->addWidget( text, 1 );
233 layout->addWidget( browse, 2 );
234 widget->setLayout( layout );
238 l->addWidget( label, line, 0 ); l->addWidget( text, line, 1 );
239 l->addWidget( browse, line, 2 );
244 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
245 module_config_t *_p_item,
246 QLabel *_label, QLineEdit *_text, bool pwd ):
247 VStringConfigControl( _p_this, _p_item )
254 void FileConfigControl::updateField()
256 text->setText( QFileDialog::getOpenFileName( NULL,
257 qtr( "Select File" ), qfu( p_this->p_libvlc->psz_homedir ) ) );
260 void FileConfigControl::finish()
262 text->setText( qfu(p_item->value.psz) );
263 text->setToolTip( qfu(p_item->psz_longtext) );
265 label->setToolTip( qfu(p_item->psz_longtext) );
268 /********* String / Directory **********/
270 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
271 module_config_t *_p_item, QWidget *_p_widget,
272 QGridLayout *_p_layout, int& _int, bool _pwd ) :
273 FileConfigControl( _p_this, _p_item, _p_widget, _p_layout, _int, _pwd)
276 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
277 module_config_t *_p_item, QLabel *_p_label,
278 QLineEdit *_p_line, bool _pwd ) :
279 FileConfigControl( _p_this, _p_item, _p_label, _p_line, _pwd)
283 void DirectoryConfigControl::updateField()
285 text->setText( QFileDialog::getOpenFileName( NULL,
286 qtr( "Select File" ), qfu( p_this->p_libvlc->psz_homedir ),
287 NULL, 0, QFileDialog::ShowDirsOnly ) );
290 /********* String / choice list **********/
291 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
292 module_config_t *_p_item, QWidget *_parent, bool bycat,
293 QGridLayout *l, int &line) :
294 VStringConfigControl( _p_this, _p_item, _parent )
296 label = new QLabel( qfu(p_item->psz_text) );
297 combo = new QComboBox();
301 QHBoxLayout *layout = new QHBoxLayout();
302 layout->addWidget( label ); layout->addWidget( combo );
303 widget->setLayout( layout );
307 l->addWidget( label, line, 0 );
308 l->addWidget( combo, line, 1, Qt::AlignRight );
311 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
312 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
313 bool bycat ) : VStringConfigControl( _p_this, _p_item )
320 void StringListConfigControl::finish( bool bycat )
322 combo->setEditable( false );
324 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
326 combo->addItem( qfu(p_item->ppsz_list_text ?
327 p_item->ppsz_list_text[i_index] :
328 p_item->ppsz_list[i_index] ),
329 QVariant( p_item->ppsz_list[i_index] ) );
330 if( p_item->value.psz && !strcmp( p_item->value.psz,
331 p_item->ppsz_list[i_index] ) )
332 combo->setCurrentIndex( combo->count() - 1 );
334 combo->setToolTip( qfu(p_item->psz_longtext) );
336 label->setToolTip( qfu(p_item->psz_longtext) );
339 QString StringListConfigControl::getValue()
341 return combo->itemData( combo->currentIndex() ).toString();
344 /********* Module **********/
345 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
346 module_config_t *_p_item, QWidget *_parent, bool bycat,
347 QGridLayout *l, int &line) :
348 VStringConfigControl( _p_this, _p_item, _parent )
350 label = new QLabel( qfu(p_item->psz_text) );
351 combo = new QComboBox();
355 QHBoxLayout *layout = new QHBoxLayout();
356 layout->addWidget( label ); layout->addWidget( combo );
357 widget->setLayout( layout );
361 l->addWidget( label, line, 0 );
362 l->addWidget( combo, line, 1, Qt::AlignRight );
365 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
366 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
367 bool bycat ) : VStringConfigControl( _p_this, _p_item )
374 void ModuleConfigControl::finish( bool bycat )
379 combo->setEditable( false );
381 /* build a list of available modules */
382 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
383 combo->addItem( qtr("Default") );
384 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
386 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
390 if( !strcmp( p_parser->psz_object_name, "main" ) ) continue;
392 for (size_t i = 0; i < p_parser->confsize; i++)
394 module_config_t *p_config = p_parser->p_config + i;
395 /* Hack: required subcategory is stored in i_min */
396 if( p_config->i_type == CONFIG_SUBCATEGORY &&
397 p_config->value.i == p_item->min.i )
398 combo->addItem( qfu(p_parser->psz_longname),
399 QVariant( p_parser->psz_object_name ) );
400 if( p_item->value.psz && !strcmp( p_item->value.psz,
401 p_parser->psz_object_name) )
402 combo->setCurrentIndex( combo->count() - 1 );
405 else if( !strcmp( p_parser->psz_capability, p_item->psz_type ) )
407 combo->addItem( qfu(p_parser->psz_longname),
408 QVariant( p_parser->psz_object_name ) );
409 if( p_item->value.psz && !strcmp( p_item->value.psz,
410 p_parser->psz_object_name) )
411 combo->setCurrentIndex( combo->count() - 1 );
414 vlc_list_release( p_list );
415 combo->setToolTip( qfu(p_item->psz_longtext) );
417 label->setToolTip( qfu(p_item->psz_longtext) );
420 QString ModuleConfigControl::getValue()
422 return combo->itemData( combo->currentIndex() ).toString();
425 /********* Module list **********/
426 ModuleListConfigControl::ModuleListConfigControl( vlc_object_t *_p_this,
427 module_config_t *_p_item, QWidget *_parent, bool bycat,
428 QGridLayout *l, int &line) :
429 VStringConfigControl( _p_this, _p_item, _parent )
431 label = new QLabel( qfu(p_item->psz_text) );
432 text = new QLineEdit();
438 l = new QGridLayout();
442 for( QVector<QCheckBox*>::iterator it = modules.begin();
443 it != modules.end(); it++ )
445 l->addWidget( *it, line++, 1 );
447 l->addWidget( label, line, 0 );
448 l->addWidget( text, line, 1 );
450 widget->setLayout( l );
453 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
454 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
455 bool bycat ) : VStringConfigControl( _p_this, _p_item )
463 ModuleListConfigControl::~ModuleListConfigControl()
465 for( QVector<QCheckBox*>::iterator it = modules.begin();
466 it != modules.end(); it++ )
474 void ModuleListConfigControl::finish( bool bycat )
479 /* build a list of available modules */
480 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
481 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
483 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
487 if( !strcmp( p_parser->psz_object_name, "main" ) ) continue;
489 for (size_t i = 0; i < p_parser->confsize; i++)
491 module_config_t *p_config = p_parser->p_config + i;
492 /* Hack: required subcategory is stored in i_min */
493 if( p_config->i_type == CONFIG_SUBCATEGORY &&
494 p_config->value.i == p_item->min.i )
497 new QCheckBox( qfu( p_parser->psz_object_name ) );
498 cb->setToolTip( qfu(p_parser->psz_longname) );
499 modules.push_back( cb );
503 else if( !strcmp( p_parser->psz_capability, p_item->psz_type ) )
506 new QCheckBox( qfu( p_parser->psz_object_name ) );
507 cb->setToolTip( qfu(p_parser->psz_longname) );
508 modules.push_back( cb );
511 vlc_list_release( p_list );
512 text->setToolTip( qfu(p_item->psz_longtext) );
514 label->setToolTip( qfu(p_item->psz_longtext) );
517 QString ModuleListConfigControl::getValue()
522 void ModuleListConfigControl::hide()
524 for( QVector<QCheckBox*>::iterator it = modules.begin();
525 it != modules.end(); it++ )
533 void ModuleListConfigControl::show()
535 for( QVector<QCheckBox*>::iterator it = modules.begin();
536 it != modules.end(); it++ )
545 void ModuleListConfigControl::wakeUp_TheUserJustClickedOnSomething( int value )
548 for( QVector<QCheckBox*>::iterator it = modules.begin();
549 it != modules.end(); it++ )
554 /**************************************************************************
555 * Integer-based controls
556 *************************************************************************/
558 /*********** Integer **************/
559 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
560 module_config_t *_p_item,
561 QWidget *_parent, QGridLayout *l,
563 VIntConfigControl( _p_this, _p_item, _parent )
565 label = new QLabel( qfu(p_item->psz_text) );
566 spin = new QSpinBox; spin->setMinimumWidth( 80 );
567 spin->setMaximumWidth( 90 );
572 QHBoxLayout *layout = new QHBoxLayout();
573 layout->addWidget( label, 0 ); layout->addWidget( spin, 1 );
574 widget->setLayout( layout );
578 l->addWidget( label, line, 0 );
579 l->addWidget( spin, line, 1, Qt::AlignRight );
582 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
583 module_config_t *_p_item,
584 QLabel *_label, QSpinBox *_spin ) :
585 VIntConfigControl( _p_this, _p_item )
592 void IntegerConfigControl::finish()
594 spin->setMaximum( 2000000000 );
595 spin->setMinimum( -2000000000 );
596 spin->setValue( p_item->value.i );
597 spin->setToolTip( qfu(p_item->psz_longtext) );
599 label->setToolTip( qfu(p_item->psz_longtext) );
602 int IntegerConfigControl::getValue()
604 return spin->value();
607 /********* Integer range **********/
608 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
609 module_config_t *_p_item,
610 QWidget *_parent, QGridLayout *l,
612 IntegerConfigControl( _p_this, _p_item, _parent, l, line )
617 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
618 module_config_t *_p_item,
619 QLabel *_label, QSpinBox *_spin ) :
620 IntegerConfigControl( _p_this, _p_item, _label, _spin )
625 void IntegerRangeConfigControl::finish()
627 spin->setMaximum( p_item->max.i );
628 spin->setMinimum( p_item->min.i );
631 IntegerRangeSliderConfigControl::IntegerRangeSliderConfigControl(
632 vlc_object_t *_p_this,
633 module_config_t *_p_item,
634 QLabel *_label, QSlider *_slider ):
635 VIntConfigControl( _p_this, _p_item )
639 slider->setMaximum( p_item->max.i );
640 slider->setMinimum( p_item->min.i );
641 slider->setValue( p_item->value.i );
642 slider->setToolTip( qfu(p_item->psz_longtext) );
644 label->setToolTip( qfu(p_item->psz_longtext) );
647 int IntegerRangeSliderConfigControl::getValue()
649 return slider->value();
653 /********* Integer / choice list **********/
654 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
655 module_config_t *_p_item, QWidget *_parent, bool bycat,
656 QGridLayout *l, int &line) :
657 VIntConfigControl( _p_this, _p_item, _parent )
659 label = new QLabel( qfu(p_item->psz_text) );
660 combo = new QComboBox();
664 QHBoxLayout *layout = new QHBoxLayout();
665 layout->addWidget( label ); layout->addWidget( combo );
666 widget->setLayout( layout );
670 l->addWidget( label, line, 0 );
671 l->addWidget( combo, line, 1, Qt::AlignRight );
674 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
675 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
676 bool bycat ) : VIntConfigControl( _p_this, _p_item )
683 void IntegerListConfigControl::finish( bool bycat )
685 combo->setEditable( false );
687 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
689 combo->addItem( qfu(p_item->ppsz_list_text[i_index] ),
690 QVariant( p_item->pi_list[i_index] ) );
691 if( p_item->value.i == p_item->pi_list[i_index] )
692 combo->setCurrentIndex( combo->count() - 1 );
694 combo->setToolTip( qfu(p_item->psz_longtext) );
696 label->setToolTip( qfu(p_item->psz_longtext) );
699 int IntegerListConfigControl::getValue()
701 return combo->itemData( combo->currentIndex() ).toInt();
704 /*********** Boolean **************/
705 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
706 module_config_t *_p_item,
707 QWidget *_parent, QGridLayout *l,
709 VIntConfigControl( _p_this, _p_item, _parent )
711 checkbox = new QCheckBox( qfu(p_item->psz_text) );
716 QHBoxLayout *layout = new QHBoxLayout();
717 layout->addWidget( checkbox, 0 );
718 widget->setLayout( layout );
722 l->addWidget( checkbox, line, 0 );
725 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
726 module_config_t *_p_item,
728 QCheckBox *_checkbox,
730 VIntConfigControl( _p_this, _p_item )
732 checkbox = _checkbox;
736 void BoolConfigControl::finish()
738 checkbox->setCheckState( p_item->value.i == VLC_TRUE ? Qt::Checked
740 checkbox->setToolTip( qfu(p_item->psz_longtext) );
743 int BoolConfigControl::getValue()
745 return checkbox->checkState() == Qt::Checked ? VLC_TRUE : VLC_FALSE;
748 /**************************************************************************
749 * Float-based controls
750 *************************************************************************/
752 /*********** Float **************/
753 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
754 module_config_t *_p_item,
755 QWidget *_parent, QGridLayout *l,
757 VFloatConfigControl( _p_this, _p_item, _parent )
759 label = new QLabel( qfu(p_item->psz_text) );
760 spin = new QDoubleSpinBox; spin->setMinimumWidth( 80 );
761 spin->setMaximumWidth( 90 );
766 QHBoxLayout *layout = new QHBoxLayout();
767 layout->addWidget( label, 0 ); layout->addWidget( spin, 1 );
768 widget->setLayout( layout );
772 l->addWidget( label, line, 0 );
773 l->addWidget( spin, line, 1, Qt::AlignRight );
777 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
778 module_config_t *_p_item,
780 QDoubleSpinBox *_spin ) :
781 VFloatConfigControl( _p_this, _p_item )
788 void FloatConfigControl::finish()
790 spin->setMaximum( 2000000000. );
791 spin->setMinimum( -2000000000. );
792 spin->setSingleStep( 0.1 );
793 spin->setValue( (double)p_item->value.f );
794 spin->setToolTip( qfu(p_item->psz_longtext) );
796 label->setToolTip( qfu(p_item->psz_longtext) );
799 float FloatConfigControl::getValue()
801 return (float)spin->value();
804 /*********** Float with range **************/
805 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
806 module_config_t *_p_item,
807 QWidget *_parent, QGridLayout *l,
809 FloatConfigControl( _p_this, _p_item, _parent, l, line )
814 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
815 module_config_t *_p_item,
817 QDoubleSpinBox *_spin ) :
818 FloatConfigControl( _p_this, _p_item, _label, _spin )
823 void FloatRangeConfigControl::finish()
825 spin->setMaximum( (double)p_item->max.f );
826 spin->setMinimum( (double)p_item->min.f );
830 /**********************************************************************
831 * Key selector widget
832 **********************************************************************/
833 KeySelectorControl::KeySelectorControl( vlc_object_t *_p_this,
834 module_config_t *_p_item,
835 QWidget *_parent, QGridLayout *l,
837 ConfigControl( _p_this, _p_item, _parent )
840 label = new QLabel( qtr("Select an action to change the associated hotkey") );
841 table = new QTreeWidget( 0 );
846 QVBoxLayout *layout = new QVBoxLayout();
847 layout->addWidget( label, 0 ); layout->addWidget( table, 1 );
848 widget->setLayout( layout );
852 l->addWidget( label, line, 0, 1, 2 );
853 l->addWidget( table, line+1, 0, 1,2 );
857 void KeySelectorControl::finish()
860 label->setToolTip( qfu(p_item->psz_longtext) );
863 table->setColumnCount( 2 );
864 table->setAlternatingRowColors( true );
866 module_t *p_main = config_FindModule( p_this, "main" );
869 for (size_t i = 0; i < p_main->confsize; i++)
871 module_config_t *p_item = p_main->p_config + i;
873 if( p_item->i_type & CONFIG_ITEM && p_item->psz_name &&
874 strstr( p_item->psz_name , "key-" ) )
876 QTreeWidgetItem *treeItem = new QTreeWidgetItem();
877 treeItem->setText( 0, qfu( p_item->psz_text ) );
878 treeItem->setText( 1, VLCKeyToString( p_item->value.i ) );
879 treeItem->setData( 0, Qt::UserRole,
880 QVariant::fromValue( (void*)p_item ) );
882 table->addTopLevelItem( treeItem );
885 table->resizeColumnToContents( 0 );
887 CONNECT( table, itemDoubleClicked( QTreeWidgetItem *, int ),
888 this, selectKey( QTreeWidgetItem * ) );
891 void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem )
893 module_config_t *p_keyItem = static_cast<module_config_t*>
894 (keyItem->data( 0, Qt::UserRole ).value<void*>());
896 KeyInputDialog *d = new KeyInputDialog( values, p_keyItem->psz_text );
898 if( d->result() == QDialog::Accepted )
900 p_keyItem->value.i = d->keyValue;
903 for( int i = 0; i < table->topLevelItemCount() ; i++ )
905 QTreeWidgetItem *it = table->topLevelItem(i);
906 module_config_t *p_item = static_cast<module_config_t*>
907 (it->data( 0, Qt::UserRole ).value<void*>());
908 it->setText( 1, VLCKeyToString( p_item->value.i ) );
912 keyItem->setText( 1, VLCKeyToString( p_keyItem->value.i ) );
917 void KeySelectorControl::doApply()
919 foreach( module_config_t *p_current, values )
921 config_PutInt( p_this, p_current->psz_name, p_current->value.i );
925 KeyInputDialog::KeyInputDialog( QList<module_config_t*>& _values,
926 const char * _keyToChange ) :
927 QDialog(0), keyValue(0)
932 keyToChange = _keyToChange;
933 setWindowTitle( qtr( "Hotkey for " ) + qfu( keyToChange) );
935 QVBoxLayout *l = new QVBoxLayout( this );
936 selected = new QLabel( qtr("Press the new keys for ") + qfu(keyToChange) );
937 warning = new QLabel();
938 l->addWidget( selected , Qt::AlignCenter );
939 l->addWidget( warning, Qt::AlignCenter );
941 QHBoxLayout *l2 = new QHBoxLayout();
942 QPushButton *ok = new QPushButton( qtr("OK") );
944 QPushButton *cancel = new QPushButton( qtr("Cancel") );
945 l2->addWidget( cancel );
947 BUTTONACT( ok, accept() );
948 BUTTONACT( cancel, reject() );
953 void KeyInputDialog::keyPressEvent( QKeyEvent *e )
955 if( e->key() == Qt::Key_Tab ) return;
956 int i_vlck = qtEventToVLCKey( e );
957 selected->setText( VLCKeyToString( i_vlck ) );
959 module_config_t *p_current = NULL;
960 foreach( p_current, values )
962 if( p_current->value.i == i_vlck && strcmp( p_current->psz_text,
965 p_current->value.i = 0;
973 qtr("Warning: the key is already assigned to \"") +
974 QString( p_current->psz_text ) + "\"" );
976 else warning->setText( "" );