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,
247 QPushButton *_button, bool pwd ):
248 VStringConfigControl( _p_this, _p_item )
254 BUTTONACT( browse, updateField() );
259 void FileConfigControl::updateField()
261 QString file = QFileDialog::getOpenFileName( NULL,
262 qtr( "Select File" ), qfu( p_this->p_libvlc->psz_homedir ) );
263 if( file.isNull() ) return;
264 text->setText( file );
267 void FileConfigControl::finish()
269 text->setText( qfu(p_item->value.psz) );
270 text->setToolTip( qfu(p_item->psz_longtext) );
272 label->setToolTip( qfu(p_item->psz_longtext) );
275 /********* String / Directory **********/
277 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
278 module_config_t *_p_item, QWidget *_p_widget,
279 QGridLayout *_p_layout, int& _int, bool _pwd ) :
280 FileConfigControl( _p_this, _p_item, _p_widget, _p_layout, _int, _pwd)
283 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
284 module_config_t *_p_item, QLabel *_p_label,
285 QLineEdit *_p_line, QPushButton *_p_button, bool _pwd ):
286 FileConfigControl( _p_this, _p_item, _p_label, _p_line, _p_button, _pwd)
290 void DirectoryConfigControl::updateField()
292 text->setText( QFileDialog::getOpenFileName( NULL,
293 qtr( "Select File" ), qfu( p_this->p_libvlc->psz_homedir ),
294 NULL, 0, QFileDialog::ShowDirsOnly ) );
297 /********* String / choice list **********/
298 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
299 module_config_t *_p_item, QWidget *_parent, bool bycat,
300 QGridLayout *l, int &line) :
301 VStringConfigControl( _p_this, _p_item, _parent )
303 label = new QLabel( qfu(p_item->psz_text) );
304 combo = new QComboBox();
308 QHBoxLayout *layout = new QHBoxLayout();
309 layout->addWidget( label ); layout->addWidget( combo );
310 widget->setLayout( layout );
314 l->addWidget( label, line, 0 );
315 l->addWidget( combo, line, 1, Qt::AlignRight );
318 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
319 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
320 bool bycat ) : VStringConfigControl( _p_this, _p_item )
327 void StringListConfigControl::finish( bool bycat )
329 combo->setEditable( false );
331 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
333 combo->addItem( qfu(p_item->ppsz_list_text ?
334 p_item->ppsz_list_text[i_index] :
335 p_item->ppsz_list[i_index] ),
336 QVariant( p_item->ppsz_list[i_index] ) );
337 if( p_item->value.psz && !strcmp( p_item->value.psz,
338 p_item->ppsz_list[i_index] ) )
339 combo->setCurrentIndex( combo->count() - 1 );
341 combo->setToolTip( qfu(p_item->psz_longtext) );
343 label->setToolTip( qfu(p_item->psz_longtext) );
346 QString StringListConfigControl::getValue()
348 return combo->itemData( combo->currentIndex() ).toString();
351 /********* Module **********/
352 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
353 module_config_t *_p_item, QWidget *_parent, bool bycat,
354 QGridLayout *l, int &line) :
355 VStringConfigControl( _p_this, _p_item, _parent )
357 label = new QLabel( qfu(p_item->psz_text) );
358 combo = new QComboBox();
362 QHBoxLayout *layout = new QHBoxLayout();
363 layout->addWidget( label ); layout->addWidget( combo );
364 widget->setLayout( layout );
368 l->addWidget( label, line, 0 );
369 l->addWidget( combo, line, 1, Qt::AlignRight );
372 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
373 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
374 bool bycat ) : VStringConfigControl( _p_this, _p_item )
381 void ModuleConfigControl::finish( bool bycat )
386 combo->setEditable( false );
388 /* build a list of available modules */
389 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
390 combo->addItem( qtr("Default") );
391 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
393 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
397 if( !strcmp( p_parser->psz_object_name, "main" ) ) continue;
399 for (size_t i = 0; i < p_parser->confsize; i++)
401 module_config_t *p_config = p_parser->p_config + i;
402 /* Hack: required subcategory is stored in i_min */
403 if( p_config->i_type == CONFIG_SUBCATEGORY &&
404 p_config->value.i == p_item->min.i )
405 combo->addItem( qfu(p_parser->psz_longname),
406 QVariant( p_parser->psz_object_name ) );
407 if( p_item->value.psz && !strcmp( p_item->value.psz,
408 p_parser->psz_object_name) )
409 combo->setCurrentIndex( combo->count() - 1 );
412 else if( !strcmp( p_parser->psz_capability, p_item->psz_type ) )
414 combo->addItem( qfu(p_parser->psz_longname),
415 QVariant( p_parser->psz_object_name ) );
416 if( p_item->value.psz && !strcmp( p_item->value.psz,
417 p_parser->psz_object_name) )
418 combo->setCurrentIndex( combo->count() - 1 );
421 vlc_list_release( p_list );
422 combo->setToolTip( qfu(p_item->psz_longtext) );
424 label->setToolTip( qfu(p_item->psz_longtext) );
427 QString ModuleConfigControl::getValue()
429 return combo->itemData( combo->currentIndex() ).toString();
432 /********* Module list **********/
433 ModuleListConfigControl::ModuleListConfigControl( vlc_object_t *_p_this,
434 module_config_t *_p_item, QWidget *_parent, bool bycat,
435 QGridLayout *l, int &line) :
436 VStringConfigControl( _p_this, _p_item, _parent )
438 label = new QLabel( qfu(p_item->psz_text) );
439 text = new QLineEdit();
445 l = new QGridLayout();
449 for( QVector<QCheckBox*>::iterator it = modules.begin();
450 it != modules.end(); it++ )
452 l->addWidget( *it, line++, 1 );
454 l->addWidget( label, line, 0 );
455 l->addWidget( text, line, 1 );
457 widget->setLayout( l );
460 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
461 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
462 bool bycat ) : VStringConfigControl( _p_this, _p_item )
470 ModuleListConfigControl::~ModuleListConfigControl()
472 for( QVector<QCheckBox*>::iterator it = modules.begin();
473 it != modules.end(); it++ )
481 void ModuleListConfigControl::finish( bool bycat )
486 /* build a list of available modules */
487 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
488 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
490 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
494 if( !strcmp( p_parser->psz_object_name, "main" ) ) continue;
496 for (size_t i = 0; i < p_parser->confsize; i++)
498 module_config_t *p_config = p_parser->p_config + i;
499 /* Hack: required subcategory is stored in i_min */
500 if( p_config->i_type == CONFIG_SUBCATEGORY &&
501 p_config->value.i == p_item->min.i )
504 new QCheckBox( qfu( p_parser->psz_object_name ) );
505 cb->setToolTip( qfu(p_parser->psz_longname) );
506 modules.push_back( cb );
510 else if( !strcmp( p_parser->psz_capability, p_item->psz_type ) )
513 new QCheckBox( qfu( p_parser->psz_object_name ) );
514 cb->setToolTip( qfu(p_parser->psz_longname) );
515 modules.push_back( cb );
518 vlc_list_release( p_list );
519 text->setToolTip( qfu(p_item->psz_longtext) );
521 label->setToolTip( qfu(p_item->psz_longtext) );
524 QString ModuleListConfigControl::getValue()
529 void ModuleListConfigControl::hide()
531 for( QVector<QCheckBox*>::iterator it = modules.begin();
532 it != modules.end(); it++ )
540 void ModuleListConfigControl::show()
542 for( QVector<QCheckBox*>::iterator it = modules.begin();
543 it != modules.end(); it++ )
552 void ModuleListConfigControl::wakeUp_TheUserJustClickedOnSomething( int value )
555 for( QVector<QCheckBox*>::iterator it = modules.begin();
556 it != modules.end(); it++ )
561 /**************************************************************************
562 * Integer-based controls
563 *************************************************************************/
565 /*********** Integer **************/
566 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
567 module_config_t *_p_item,
568 QWidget *_parent, QGridLayout *l,
570 VIntConfigControl( _p_this, _p_item, _parent )
572 label = new QLabel( qfu(p_item->psz_text) );
573 spin = new QSpinBox; spin->setMinimumWidth( 80 );
574 spin->setMaximumWidth( 90 );
579 QHBoxLayout *layout = new QHBoxLayout();
580 layout->addWidget( label, 0 ); layout->addWidget( spin, 1 );
581 widget->setLayout( layout );
585 l->addWidget( label, line, 0 );
586 l->addWidget( spin, line, 1, Qt::AlignRight );
589 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
590 module_config_t *_p_item,
591 QLabel *_label, QSpinBox *_spin ) :
592 VIntConfigControl( _p_this, _p_item )
599 void IntegerConfigControl::finish()
601 spin->setMaximum( 2000000000 );
602 spin->setMinimum( -2000000000 );
603 spin->setValue( p_item->value.i );
604 spin->setToolTip( qfu(p_item->psz_longtext) );
606 label->setToolTip( qfu(p_item->psz_longtext) );
609 int IntegerConfigControl::getValue()
611 return spin->value();
614 /********* Integer range **********/
615 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
616 module_config_t *_p_item,
617 QWidget *_parent, QGridLayout *l,
619 IntegerConfigControl( _p_this, _p_item, _parent, l, line )
624 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
625 module_config_t *_p_item,
626 QLabel *_label, QSpinBox *_spin ) :
627 IntegerConfigControl( _p_this, _p_item, _label, _spin )
632 void IntegerRangeConfigControl::finish()
634 spin->setMaximum( p_item->max.i );
635 spin->setMinimum( p_item->min.i );
638 IntegerRangeSliderConfigControl::IntegerRangeSliderConfigControl(
639 vlc_object_t *_p_this,
640 module_config_t *_p_item,
641 QLabel *_label, QSlider *_slider ):
642 VIntConfigControl( _p_this, _p_item )
646 slider->setMaximum( p_item->max.i );
647 slider->setMinimum( p_item->min.i );
648 slider->setValue( p_item->value.i );
649 slider->setToolTip( qfu(p_item->psz_longtext) );
651 label->setToolTip( qfu(p_item->psz_longtext) );
654 int IntegerRangeSliderConfigControl::getValue()
656 return slider->value();
660 /********* Integer / choice list **********/
661 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
662 module_config_t *_p_item, QWidget *_parent, bool bycat,
663 QGridLayout *l, int &line) :
664 VIntConfigControl( _p_this, _p_item, _parent )
666 label = new QLabel( qfu(p_item->psz_text) );
667 combo = new QComboBox();
671 QHBoxLayout *layout = new QHBoxLayout();
672 layout->addWidget( label ); layout->addWidget( combo );
673 widget->setLayout( layout );
677 l->addWidget( label, line, 0 );
678 l->addWidget( combo, line, 1, Qt::AlignRight );
681 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
682 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
683 bool bycat ) : VIntConfigControl( _p_this, _p_item )
690 void IntegerListConfigControl::finish( bool bycat )
692 combo->setEditable( false );
694 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
696 combo->addItem( qfu(p_item->ppsz_list_text[i_index] ),
697 QVariant( p_item->pi_list[i_index] ) );
698 if( p_item->value.i == p_item->pi_list[i_index] )
699 combo->setCurrentIndex( combo->count() - 1 );
701 combo->setToolTip( qfu(p_item->psz_longtext) );
703 label->setToolTip( qfu(p_item->psz_longtext) );
706 int IntegerListConfigControl::getValue()
708 return combo->itemData( combo->currentIndex() ).toInt();
711 /*********** Boolean **************/
712 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
713 module_config_t *_p_item,
714 QWidget *_parent, QGridLayout *l,
716 VIntConfigControl( _p_this, _p_item, _parent )
718 checkbox = new QCheckBox( qfu(p_item->psz_text) );
723 QHBoxLayout *layout = new QHBoxLayout();
724 layout->addWidget( checkbox, 0 );
725 widget->setLayout( layout );
729 l->addWidget( checkbox, line, 0 );
732 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
733 module_config_t *_p_item,
735 QCheckBox *_checkbox,
737 VIntConfigControl( _p_this, _p_item )
739 checkbox = _checkbox;
743 void BoolConfigControl::finish()
745 checkbox->setCheckState( p_item->value.i == VLC_TRUE ? Qt::Checked
747 checkbox->setToolTip( qfu(p_item->psz_longtext) );
750 int BoolConfigControl::getValue()
752 return checkbox->checkState() == Qt::Checked ? VLC_TRUE : VLC_FALSE;
755 /**************************************************************************
756 * Float-based controls
757 *************************************************************************/
759 /*********** Float **************/
760 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
761 module_config_t *_p_item,
762 QWidget *_parent, QGridLayout *l,
764 VFloatConfigControl( _p_this, _p_item, _parent )
766 label = new QLabel( qfu(p_item->psz_text) );
767 spin = new QDoubleSpinBox; spin->setMinimumWidth( 80 );
768 spin->setMaximumWidth( 90 );
773 QHBoxLayout *layout = new QHBoxLayout();
774 layout->addWidget( label, 0 ); layout->addWidget( spin, 1 );
775 widget->setLayout( layout );
779 l->addWidget( label, line, 0 );
780 l->addWidget( spin, line, 1, Qt::AlignRight );
784 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
785 module_config_t *_p_item,
787 QDoubleSpinBox *_spin ) :
788 VFloatConfigControl( _p_this, _p_item )
795 void FloatConfigControl::finish()
797 spin->setMaximum( 2000000000. );
798 spin->setMinimum( -2000000000. );
799 spin->setSingleStep( 0.1 );
800 spin->setValue( (double)p_item->value.f );
801 spin->setToolTip( qfu(p_item->psz_longtext) );
803 label->setToolTip( qfu(p_item->psz_longtext) );
806 float FloatConfigControl::getValue()
808 return (float)spin->value();
811 /*********** Float with range **************/
812 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
813 module_config_t *_p_item,
814 QWidget *_parent, QGridLayout *l,
816 FloatConfigControl( _p_this, _p_item, _parent, l, line )
821 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
822 module_config_t *_p_item,
824 QDoubleSpinBox *_spin ) :
825 FloatConfigControl( _p_this, _p_item, _label, _spin )
830 void FloatRangeConfigControl::finish()
832 spin->setMaximum( (double)p_item->max.f );
833 spin->setMinimum( (double)p_item->min.f );
837 /**********************************************************************
838 * Key selector widget
839 **********************************************************************/
840 KeySelectorControl::KeySelectorControl( vlc_object_t *_p_this,
841 module_config_t *_p_item,
842 QWidget *_parent, QGridLayout *l,
844 ConfigControl( _p_this, _p_item, _parent )
847 label = new QLabel( qtr("Select an action to change the associated hotkey") );
848 table = new QTreeWidget( 0 );
853 QVBoxLayout *layout = new QVBoxLayout();
854 layout->addWidget( label, 0 ); layout->addWidget( table, 1 );
855 widget->setLayout( layout );
859 l->addWidget( label, line, 0, 1, 2 );
860 l->addWidget( table, line+1, 0, 1,2 );
864 void KeySelectorControl::finish()
867 label->setToolTip( qfu(p_item->psz_longtext) );
870 table->setColumnCount( 2 );
871 table->setAlternatingRowColors( true );
873 module_t *p_main = config_FindModule( p_this, "main" );
876 for (size_t i = 0; i < p_main->confsize; i++)
878 module_config_t *p_item = p_main->p_config + i;
880 if( p_item->i_type & CONFIG_ITEM && p_item->psz_name &&
881 strstr( p_item->psz_name , "key-" ) )
883 QTreeWidgetItem *treeItem = new QTreeWidgetItem();
884 treeItem->setText( 0, qfu( p_item->psz_text ) );
885 treeItem->setText( 1, VLCKeyToString( p_item->value.i ) );
886 treeItem->setData( 0, Qt::UserRole,
887 QVariant::fromValue( (void*)p_item ) );
889 table->addTopLevelItem( treeItem );
892 table->resizeColumnToContents( 0 );
894 CONNECT( table, itemDoubleClicked( QTreeWidgetItem *, int ),
895 this, selectKey( QTreeWidgetItem * ) );
898 void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem )
900 module_config_t *p_keyItem = static_cast<module_config_t*>
901 (keyItem->data( 0, Qt::UserRole ).value<void*>());
903 KeyInputDialog *d = new KeyInputDialog( values, p_keyItem->psz_text );
905 if( d->result() == QDialog::Accepted )
907 p_keyItem->value.i = d->keyValue;
910 for( int i = 0; i < table->topLevelItemCount() ; i++ )
912 QTreeWidgetItem *it = table->topLevelItem(i);
913 module_config_t *p_item = static_cast<module_config_t*>
914 (it->data( 0, Qt::UserRole ).value<void*>());
915 it->setText( 1, VLCKeyToString( p_item->value.i ) );
919 keyItem->setText( 1, VLCKeyToString( p_keyItem->value.i ) );
924 void KeySelectorControl::doApply()
926 foreach( module_config_t *p_current, values )
928 config_PutInt( p_this, p_current->psz_name, p_current->value.i );
932 KeyInputDialog::KeyInputDialog( QList<module_config_t*>& _values,
933 const char * _keyToChange ) :
934 QDialog(0), keyValue(0)
939 keyToChange = _keyToChange;
940 setWindowTitle( qtr( "Hotkey for " ) + qfu( keyToChange) );
942 QVBoxLayout *l = new QVBoxLayout( this );
943 selected = new QLabel( qtr("Press the new keys for ") + qfu(keyToChange) );
944 warning = new QLabel();
945 l->addWidget( selected , Qt::AlignCenter );
946 l->addWidget( warning, Qt::AlignCenter );
948 QHBoxLayout *l2 = new QHBoxLayout();
949 QPushButton *ok = new QPushButton( qtr("OK") );
951 QPushButton *cancel = new QPushButton( qtr("Cancel") );
952 l2->addWidget( cancel );
954 BUTTONACT( ok, accept() );
955 BUTTONACT( cancel, reject() );
960 void KeyInputDialog::keyPressEvent( QKeyEvent *e )
962 if( e->key() == Qt::Key_Tab ) return;
963 int i_vlck = qtEventToVLCKey( e );
964 selected->setText( VLCKeyToString( i_vlck ) );
966 module_config_t *p_current = NULL;
967 foreach( p_current, values )
969 if( p_current->value.i == i_vlck && strcmp( p_current->psz_text,
972 p_current->value.i = 0;
980 qtr("Warning: the key is already assigned to \"") +
981 QString( p_current->psz_text ) + "\"" );
983 else warning->setText( "" );