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 QString dir = QFileDialog::getExistingDirectory( NULL,
293 qtr( "Select Directory" ),
294 qfu( p_this->p_libvlc->psz_homedir ),
295 QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks );
296 if( dir.isNull() ) return;
297 text->setText( dir );
300 /********* String / choice list **********/
301 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
302 module_config_t *_p_item, QWidget *_parent, bool bycat,
303 QGridLayout *l, int &line) :
304 VStringConfigControl( _p_this, _p_item, _parent )
306 label = new QLabel( qfu(p_item->psz_text) );
307 combo = new QComboBox();
311 QHBoxLayout *layout = new QHBoxLayout();
312 layout->addWidget( label ); layout->addWidget( combo );
313 widget->setLayout( layout );
317 l->addWidget( label, line, 0 );
318 l->addWidget( combo, line, 1, Qt::AlignRight );
321 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
322 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
323 bool bycat ) : VStringConfigControl( _p_this, _p_item )
330 void StringListConfigControl::finish( bool bycat )
332 combo->setEditable( false );
334 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
336 combo->addItem( qfu(p_item->ppsz_list_text ?
337 p_item->ppsz_list_text[i_index] :
338 p_item->ppsz_list[i_index] ),
339 QVariant( p_item->ppsz_list[i_index] ) );
340 if( p_item->value.psz && !strcmp( p_item->value.psz,
341 p_item->ppsz_list[i_index] ) )
342 combo->setCurrentIndex( combo->count() - 1 );
344 combo->setToolTip( qfu(p_item->psz_longtext) );
346 label->setToolTip( qfu(p_item->psz_longtext) );
349 QString StringListConfigControl::getValue()
351 return combo->itemData( combo->currentIndex() ).toString();
354 /********* Module **********/
355 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
356 module_config_t *_p_item, QWidget *_parent, bool bycat,
357 QGridLayout *l, int &line) :
358 VStringConfigControl( _p_this, _p_item, _parent )
360 label = new QLabel( qfu(p_item->psz_text) );
361 combo = new QComboBox();
365 QHBoxLayout *layout = new QHBoxLayout();
366 layout->addWidget( label ); layout->addWidget( combo );
367 widget->setLayout( layout );
371 l->addWidget( label, line, 0 );
372 l->addWidget( combo, line, 1, Qt::AlignRight );
375 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
376 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
377 bool bycat ) : VStringConfigControl( _p_this, _p_item )
384 void ModuleConfigControl::finish( bool bycat )
389 combo->setEditable( false );
391 /* build a list of available modules */
392 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
393 combo->addItem( qtr("Default") );
394 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
396 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
400 if( !strcmp( p_parser->psz_object_name, "main" ) ) continue;
402 for (size_t i = 0; i < p_parser->confsize; i++)
404 module_config_t *p_config = p_parser->p_config + i;
405 /* Hack: required subcategory is stored in i_min */
406 if( p_config->i_type == CONFIG_SUBCATEGORY &&
407 p_config->value.i == p_item->min.i )
408 combo->addItem( qfu(p_parser->psz_longname),
409 QVariant( p_parser->psz_object_name ) );
410 if( p_item->value.psz && !strcmp( p_item->value.psz,
411 p_parser->psz_object_name) )
412 combo->setCurrentIndex( combo->count() - 1 );
415 else if( !strcmp( p_parser->psz_capability, p_item->psz_type ) )
417 combo->addItem( qfu(p_parser->psz_longname),
418 QVariant( p_parser->psz_object_name ) );
419 if( p_item->value.psz && !strcmp( p_item->value.psz,
420 p_parser->psz_object_name) )
421 combo->setCurrentIndex( combo->count() - 1 );
424 vlc_list_release( p_list );
425 combo->setToolTip( qfu(p_item->psz_longtext) );
427 label->setToolTip( qfu(p_item->psz_longtext) );
430 QString ModuleConfigControl::getValue()
432 return combo->itemData( combo->currentIndex() ).toString();
435 /********* Module list **********/
436 ModuleListConfigControl::ModuleListConfigControl( vlc_object_t *_p_this,
437 module_config_t *_p_item, QWidget *_parent, bool bycat,
438 QGridLayout *l, int &line) :
439 VStringConfigControl( _p_this, _p_item, _parent )
441 label = new QLabel( qfu(p_item->psz_text) );
442 text = new QLineEdit();
448 l = new QGridLayout();
452 for( QVector<QCheckBox*>::iterator it = modules.begin();
453 it != modules.end(); it++ )
455 l->addWidget( *it, line++, 1 );
457 l->addWidget( label, line, 0 );
458 l->addWidget( text, line, 1 );
460 widget->setLayout( l );
463 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
464 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
465 bool bycat ) : VStringConfigControl( _p_this, _p_item )
473 ModuleListConfigControl::~ModuleListConfigControl()
475 for( QVector<QCheckBox*>::iterator it = modules.begin();
476 it != modules.end(); it++ )
484 void ModuleListConfigControl::finish( bool bycat )
489 /* build a list of available modules */
490 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
491 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
493 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
497 if( !strcmp( p_parser->psz_object_name, "main" ) ) continue;
499 for (size_t i = 0; i < p_parser->confsize; i++)
501 module_config_t *p_config = p_parser->p_config + i;
502 /* Hack: required subcategory is stored in i_min */
503 if( p_config->i_type == CONFIG_SUBCATEGORY &&
504 p_config->value.i == p_item->min.i )
507 new QCheckBox( qfu( p_parser->psz_object_name ) );
508 cb->setToolTip( qfu(p_parser->psz_longname) );
509 modules.push_back( cb );
513 else if( !strcmp( p_parser->psz_capability, p_item->psz_type ) )
516 new QCheckBox( qfu( p_parser->psz_object_name ) );
517 cb->setToolTip( qfu(p_parser->psz_longname) );
518 modules.push_back( cb );
521 vlc_list_release( p_list );
522 text->setToolTip( qfu(p_item->psz_longtext) );
524 label->setToolTip( qfu(p_item->psz_longtext) );
527 QString ModuleListConfigControl::getValue()
532 void ModuleListConfigControl::hide()
534 for( QVector<QCheckBox*>::iterator it = modules.begin();
535 it != modules.end(); it++ )
543 void ModuleListConfigControl::show()
545 for( QVector<QCheckBox*>::iterator it = modules.begin();
546 it != modules.end(); it++ )
555 void ModuleListConfigControl::wakeUp_TheUserJustClickedOnSomething( int value )
558 for( QVector<QCheckBox*>::iterator it = modules.begin();
559 it != modules.end(); it++ )
564 /**************************************************************************
565 * Integer-based controls
566 *************************************************************************/
568 /*********** Integer **************/
569 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
570 module_config_t *_p_item,
571 QWidget *_parent, QGridLayout *l,
573 VIntConfigControl( _p_this, _p_item, _parent )
575 label = new QLabel( qfu(p_item->psz_text) );
576 spin = new QSpinBox; spin->setMinimumWidth( 80 );
577 spin->setMaximumWidth( 90 );
582 QHBoxLayout *layout = new QHBoxLayout();
583 layout->addWidget( label, 0 ); layout->addWidget( spin, 1 );
584 widget->setLayout( layout );
588 l->addWidget( label, line, 0 );
589 l->addWidget( spin, line, 1, Qt::AlignRight );
592 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
593 module_config_t *_p_item,
594 QLabel *_label, QSpinBox *_spin ) :
595 VIntConfigControl( _p_this, _p_item )
602 void IntegerConfigControl::finish()
604 spin->setMaximum( 2000000000 );
605 spin->setMinimum( -2000000000 );
606 spin->setValue( p_item->value.i );
607 spin->setToolTip( qfu(p_item->psz_longtext) );
609 label->setToolTip( qfu(p_item->psz_longtext) );
612 int IntegerConfigControl::getValue()
614 return spin->value();
617 /********* Integer range **********/
618 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
619 module_config_t *_p_item,
620 QWidget *_parent, QGridLayout *l,
622 IntegerConfigControl( _p_this, _p_item, _parent, l, line )
627 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
628 module_config_t *_p_item,
629 QLabel *_label, QSpinBox *_spin ) :
630 IntegerConfigControl( _p_this, _p_item, _label, _spin )
635 void IntegerRangeConfigControl::finish()
637 spin->setMaximum( p_item->max.i );
638 spin->setMinimum( p_item->min.i );
641 IntegerRangeSliderConfigControl::IntegerRangeSliderConfigControl(
642 vlc_object_t *_p_this,
643 module_config_t *_p_item,
644 QLabel *_label, QSlider *_slider ):
645 VIntConfigControl( _p_this, _p_item )
649 slider->setMaximum( p_item->max.i );
650 slider->setMinimum( p_item->min.i );
651 slider->setValue( p_item->value.i );
652 slider->setToolTip( qfu(p_item->psz_longtext) );
654 label->setToolTip( qfu(p_item->psz_longtext) );
657 int IntegerRangeSliderConfigControl::getValue()
659 return slider->value();
663 /********* Integer / choice list **********/
664 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
665 module_config_t *_p_item, QWidget *_parent, bool bycat,
666 QGridLayout *l, int &line) :
667 VIntConfigControl( _p_this, _p_item, _parent )
669 label = new QLabel( qfu(p_item->psz_text) );
670 combo = new QComboBox();
674 QHBoxLayout *layout = new QHBoxLayout();
675 layout->addWidget( label ); layout->addWidget( combo );
676 widget->setLayout( layout );
680 l->addWidget( label, line, 0 );
681 l->addWidget( combo, line, 1, Qt::AlignRight );
684 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
685 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
686 bool bycat ) : VIntConfigControl( _p_this, _p_item )
693 void IntegerListConfigControl::finish( bool bycat )
695 combo->setEditable( false );
697 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
699 combo->addItem( qfu(p_item->ppsz_list_text[i_index] ),
700 QVariant( p_item->pi_list[i_index] ) );
701 if( p_item->value.i == p_item->pi_list[i_index] )
702 combo->setCurrentIndex( combo->count() - 1 );
704 combo->setToolTip( qfu(p_item->psz_longtext) );
706 label->setToolTip( qfu(p_item->psz_longtext) );
709 int IntegerListConfigControl::getValue()
711 return combo->itemData( combo->currentIndex() ).toInt();
714 /*********** Boolean **************/
715 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
716 module_config_t *_p_item,
717 QWidget *_parent, QGridLayout *l,
719 VIntConfigControl( _p_this, _p_item, _parent )
721 checkbox = new QCheckBox( qfu(p_item->psz_text) );
726 QHBoxLayout *layout = new QHBoxLayout();
727 layout->addWidget( checkbox, 0 );
728 widget->setLayout( layout );
732 l->addWidget( checkbox, line, 0 );
735 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
736 module_config_t *_p_item,
738 QCheckBox *_checkbox,
740 VIntConfigControl( _p_this, _p_item )
742 checkbox = _checkbox;
746 void BoolConfigControl::finish()
748 checkbox->setCheckState( p_item->value.i == VLC_TRUE ? Qt::Checked
750 checkbox->setToolTip( qfu(p_item->psz_longtext) );
753 int BoolConfigControl::getValue()
755 return checkbox->checkState() == Qt::Checked ? VLC_TRUE : VLC_FALSE;
758 /**************************************************************************
759 * Float-based controls
760 *************************************************************************/
762 /*********** Float **************/
763 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
764 module_config_t *_p_item,
765 QWidget *_parent, QGridLayout *l,
767 VFloatConfigControl( _p_this, _p_item, _parent )
769 label = new QLabel( qfu(p_item->psz_text) );
770 spin = new QDoubleSpinBox; spin->setMinimumWidth( 80 );
771 spin->setMaximumWidth( 90 );
776 QHBoxLayout *layout = new QHBoxLayout();
777 layout->addWidget( label, 0 ); layout->addWidget( spin, 1 );
778 widget->setLayout( layout );
782 l->addWidget( label, line, 0 );
783 l->addWidget( spin, line, 1, Qt::AlignRight );
787 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
788 module_config_t *_p_item,
790 QDoubleSpinBox *_spin ) :
791 VFloatConfigControl( _p_this, _p_item )
798 void FloatConfigControl::finish()
800 spin->setMaximum( 2000000000. );
801 spin->setMinimum( -2000000000. );
802 spin->setSingleStep( 0.1 );
803 spin->setValue( (double)p_item->value.f );
804 spin->setToolTip( qfu(p_item->psz_longtext) );
806 label->setToolTip( qfu(p_item->psz_longtext) );
809 float FloatConfigControl::getValue()
811 return (float)spin->value();
814 /*********** Float with range **************/
815 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
816 module_config_t *_p_item,
817 QWidget *_parent, QGridLayout *l,
819 FloatConfigControl( _p_this, _p_item, _parent, l, line )
824 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
825 module_config_t *_p_item,
827 QDoubleSpinBox *_spin ) :
828 FloatConfigControl( _p_this, _p_item, _label, _spin )
833 void FloatRangeConfigControl::finish()
835 spin->setMaximum( (double)p_item->max.f );
836 spin->setMinimum( (double)p_item->min.f );
840 /**********************************************************************
841 * Key selector widget
842 **********************************************************************/
843 KeySelectorControl::KeySelectorControl( vlc_object_t *_p_this,
844 module_config_t *_p_item,
845 QWidget *_parent, QGridLayout *l,
847 ConfigControl( _p_this, _p_item, _parent )
850 label = new QLabel( qtr("Select an action to change the associated hotkey") );
851 table = new QTreeWidget( 0 );
856 QVBoxLayout *layout = new QVBoxLayout();
857 layout->addWidget( label, 0 ); layout->addWidget( table, 1 );
858 widget->setLayout( layout );
862 l->addWidget( label, line, 0, 1, 2 );
863 l->addWidget( table, line+1, 0, 1,2 );
867 void KeySelectorControl::finish()
870 label->setToolTip( qfu(p_item->psz_longtext) );
873 table->setColumnCount( 2 );
874 table->setAlternatingRowColors( true );
876 module_t *p_main = config_FindModule( p_this, "main" );
879 for (size_t i = 0; i < p_main->confsize; i++)
881 module_config_t *p_item = p_main->p_config + i;
883 if( p_item->i_type & CONFIG_ITEM && p_item->psz_name &&
884 strstr( p_item->psz_name , "key-" ) )
886 QTreeWidgetItem *treeItem = new QTreeWidgetItem();
887 treeItem->setText( 0, qfu( p_item->psz_text ) );
888 treeItem->setText( 1, VLCKeyToString( p_item->value.i ) );
889 treeItem->setData( 0, Qt::UserRole,
890 QVariant::fromValue( (void*)p_item ) );
892 table->addTopLevelItem( treeItem );
895 table->resizeColumnToContents( 0 );
897 CONNECT( table, itemDoubleClicked( QTreeWidgetItem *, int ),
898 this, selectKey( QTreeWidgetItem * ) );
901 void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem )
903 module_config_t *p_keyItem = static_cast<module_config_t*>
904 (keyItem->data( 0, Qt::UserRole ).value<void*>());
906 KeyInputDialog *d = new KeyInputDialog( values, p_keyItem->psz_text );
908 if( d->result() == QDialog::Accepted )
910 p_keyItem->value.i = d->keyValue;
913 for( int i = 0; i < table->topLevelItemCount() ; i++ )
915 QTreeWidgetItem *it = table->topLevelItem(i);
916 module_config_t *p_item = static_cast<module_config_t*>
917 (it->data( 0, Qt::UserRole ).value<void*>());
918 it->setText( 1, VLCKeyToString( p_item->value.i ) );
922 keyItem->setText( 1, VLCKeyToString( p_keyItem->value.i ) );
927 void KeySelectorControl::doApply()
929 foreach( module_config_t *p_current, values )
931 config_PutInt( p_this, p_current->psz_name, p_current->value.i );
935 KeyInputDialog::KeyInputDialog( QList<module_config_t*>& _values,
936 const char * _keyToChange ) :
937 QDialog(0), keyValue(0)
942 keyToChange = _keyToChange;
943 setWindowTitle( qtr( "Hotkey for " ) + qfu( keyToChange) );
945 QVBoxLayout *l = new QVBoxLayout( this );
946 selected = new QLabel( qtr("Press the new keys for ") + qfu(keyToChange) );
947 warning = new QLabel();
948 l->addWidget( selected , Qt::AlignCenter );
949 l->addWidget( warning, Qt::AlignCenter );
951 QHBoxLayout *l2 = new QHBoxLayout();
952 QPushButton *ok = new QPushButton( qtr("OK") );
954 QPushButton *cancel = new QPushButton( qtr("Cancel") );
955 l2->addWidget( cancel );
957 BUTTONACT( ok, accept() );
958 BUTTONACT( cancel, reject() );
963 void KeyInputDialog::keyPressEvent( QKeyEvent *e )
965 if( e->key() == Qt::Key_Tab ) return;
966 int i_vlck = qtEventToVLCKey( e );
967 selected->setText( VLCKeyToString( i_vlck ) );
969 module_config_t *p_current = NULL;
970 foreach( p_current, values )
972 if( p_current->value.i == i_vlck && strcmp( p_current->psz_text,
975 p_current->value.i = 0;
983 qtr("Warning: the key is already assigned to \"") +
984 QString( p_current->psz_text ) + "\"" );
986 else warning->setText( "" );