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 text->setText( QFileDialog::getOpenFileName( NULL,
262 qtr( "Select File" ), qfu( p_this->p_libvlc->psz_homedir ) ) );
265 void FileConfigControl::finish()
267 text->setText( qfu(p_item->value.psz) );
268 text->setToolTip( qfu(p_item->psz_longtext) );
270 label->setToolTip( qfu(p_item->psz_longtext) );
273 /********* String / Directory **********/
275 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
276 module_config_t *_p_item, QWidget *_p_widget,
277 QGridLayout *_p_layout, int& _int, bool _pwd ) :
278 FileConfigControl( _p_this, _p_item, _p_widget, _p_layout, _int, _pwd)
281 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
282 module_config_t *_p_item, QLabel *_p_label,
283 QLineEdit *_p_line, QPushButton *_p_button, bool _pwd ):
284 FileConfigControl( _p_this, _p_item, _p_label, _p_line, _p_button, _pwd)
288 void DirectoryConfigControl::updateField()
290 text->setText( QFileDialog::getOpenFileName( NULL,
291 qtr( "Select File" ), qfu( p_this->p_libvlc->psz_homedir ),
292 NULL, 0, QFileDialog::ShowDirsOnly ) );
295 /********* String / choice list **********/
296 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
297 module_config_t *_p_item, QWidget *_parent, bool bycat,
298 QGridLayout *l, int &line) :
299 VStringConfigControl( _p_this, _p_item, _parent )
301 label = new QLabel( qfu(p_item->psz_text) );
302 combo = new QComboBox();
306 QHBoxLayout *layout = new QHBoxLayout();
307 layout->addWidget( label ); layout->addWidget( combo );
308 widget->setLayout( layout );
312 l->addWidget( label, line, 0 );
313 l->addWidget( combo, line, 1, Qt::AlignRight );
316 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
317 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
318 bool bycat ) : VStringConfigControl( _p_this, _p_item )
325 void StringListConfigControl::finish( bool bycat )
327 combo->setEditable( false );
329 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
331 combo->addItem( qfu(p_item->ppsz_list_text ?
332 p_item->ppsz_list_text[i_index] :
333 p_item->ppsz_list[i_index] ),
334 QVariant( p_item->ppsz_list[i_index] ) );
335 if( p_item->value.psz && !strcmp( p_item->value.psz,
336 p_item->ppsz_list[i_index] ) )
337 combo->setCurrentIndex( combo->count() - 1 );
339 combo->setToolTip( qfu(p_item->psz_longtext) );
341 label->setToolTip( qfu(p_item->psz_longtext) );
344 QString StringListConfigControl::getValue()
346 return combo->itemData( combo->currentIndex() ).toString();
349 /********* Module **********/
350 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
351 module_config_t *_p_item, QWidget *_parent, bool bycat,
352 QGridLayout *l, int &line) :
353 VStringConfigControl( _p_this, _p_item, _parent )
355 label = new QLabel( qfu(p_item->psz_text) );
356 combo = new QComboBox();
360 QHBoxLayout *layout = new QHBoxLayout();
361 layout->addWidget( label ); layout->addWidget( combo );
362 widget->setLayout( layout );
366 l->addWidget( label, line, 0 );
367 l->addWidget( combo, line, 1, Qt::AlignRight );
370 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
371 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
372 bool bycat ) : VStringConfigControl( _p_this, _p_item )
379 void ModuleConfigControl::finish( bool bycat )
384 combo->setEditable( false );
386 /* build a list of available modules */
387 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
388 combo->addItem( qtr("Default") );
389 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
391 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
395 if( !strcmp( p_parser->psz_object_name, "main" ) ) continue;
397 for (size_t i = 0; i < p_parser->confsize; i++)
399 module_config_t *p_config = p_parser->p_config + i;
400 /* Hack: required subcategory is stored in i_min */
401 if( p_config->i_type == CONFIG_SUBCATEGORY &&
402 p_config->value.i == p_item->min.i )
403 combo->addItem( qfu(p_parser->psz_longname),
404 QVariant( p_parser->psz_object_name ) );
405 if( p_item->value.psz && !strcmp( p_item->value.psz,
406 p_parser->psz_object_name) )
407 combo->setCurrentIndex( combo->count() - 1 );
410 else if( !strcmp( p_parser->psz_capability, p_item->psz_type ) )
412 combo->addItem( qfu(p_parser->psz_longname),
413 QVariant( p_parser->psz_object_name ) );
414 if( p_item->value.psz && !strcmp( p_item->value.psz,
415 p_parser->psz_object_name) )
416 combo->setCurrentIndex( combo->count() - 1 );
419 vlc_list_release( p_list );
420 combo->setToolTip( qfu(p_item->psz_longtext) );
422 label->setToolTip( qfu(p_item->psz_longtext) );
425 QString ModuleConfigControl::getValue()
427 return combo->itemData( combo->currentIndex() ).toString();
430 /********* Module list **********/
431 ModuleListConfigControl::ModuleListConfigControl( vlc_object_t *_p_this,
432 module_config_t *_p_item, QWidget *_parent, bool bycat,
433 QGridLayout *l, int &line) :
434 VStringConfigControl( _p_this, _p_item, _parent )
436 label = new QLabel( qfu(p_item->psz_text) );
437 text = new QLineEdit();
443 l = new QGridLayout();
447 for( QVector<QCheckBox*>::iterator it = modules.begin();
448 it != modules.end(); it++ )
450 l->addWidget( *it, line++, 1 );
452 l->addWidget( label, line, 0 );
453 l->addWidget( text, line, 1 );
455 widget->setLayout( l );
458 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
459 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
460 bool bycat ) : VStringConfigControl( _p_this, _p_item )
468 ModuleListConfigControl::~ModuleListConfigControl()
470 for( QVector<QCheckBox*>::iterator it = modules.begin();
471 it != modules.end(); it++ )
479 void ModuleListConfigControl::finish( bool bycat )
484 /* build a list of available modules */
485 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
486 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
488 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
492 if( !strcmp( p_parser->psz_object_name, "main" ) ) continue;
494 for (size_t i = 0; i < p_parser->confsize; i++)
496 module_config_t *p_config = p_parser->p_config + i;
497 /* Hack: required subcategory is stored in i_min */
498 if( p_config->i_type == CONFIG_SUBCATEGORY &&
499 p_config->value.i == p_item->min.i )
502 new QCheckBox( qfu( p_parser->psz_object_name ) );
503 cb->setToolTip( qfu(p_parser->psz_longname) );
504 modules.push_back( cb );
508 else if( !strcmp( p_parser->psz_capability, p_item->psz_type ) )
511 new QCheckBox( qfu( p_parser->psz_object_name ) );
512 cb->setToolTip( qfu(p_parser->psz_longname) );
513 modules.push_back( cb );
516 vlc_list_release( p_list );
517 text->setToolTip( qfu(p_item->psz_longtext) );
519 label->setToolTip( qfu(p_item->psz_longtext) );
522 QString ModuleListConfigControl::getValue()
527 void ModuleListConfigControl::hide()
529 for( QVector<QCheckBox*>::iterator it = modules.begin();
530 it != modules.end(); it++ )
538 void ModuleListConfigControl::show()
540 for( QVector<QCheckBox*>::iterator it = modules.begin();
541 it != modules.end(); it++ )
550 void ModuleListConfigControl::wakeUp_TheUserJustClickedOnSomething( int value )
553 for( QVector<QCheckBox*>::iterator it = modules.begin();
554 it != modules.end(); it++ )
559 /**************************************************************************
560 * Integer-based controls
561 *************************************************************************/
563 /*********** Integer **************/
564 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
565 module_config_t *_p_item,
566 QWidget *_parent, QGridLayout *l,
568 VIntConfigControl( _p_this, _p_item, _parent )
570 label = new QLabel( qfu(p_item->psz_text) );
571 spin = new QSpinBox; spin->setMinimumWidth( 80 );
572 spin->setMaximumWidth( 90 );
577 QHBoxLayout *layout = new QHBoxLayout();
578 layout->addWidget( label, 0 ); layout->addWidget( spin, 1 );
579 widget->setLayout( layout );
583 l->addWidget( label, line, 0 );
584 l->addWidget( spin, line, 1, Qt::AlignRight );
587 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
588 module_config_t *_p_item,
589 QLabel *_label, QSpinBox *_spin ) :
590 VIntConfigControl( _p_this, _p_item )
597 void IntegerConfigControl::finish()
599 spin->setMaximum( 2000000000 );
600 spin->setMinimum( -2000000000 );
601 spin->setValue( p_item->value.i );
602 spin->setToolTip( qfu(p_item->psz_longtext) );
604 label->setToolTip( qfu(p_item->psz_longtext) );
607 int IntegerConfigControl::getValue()
609 return spin->value();
612 /********* Integer range **********/
613 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
614 module_config_t *_p_item,
615 QWidget *_parent, QGridLayout *l,
617 IntegerConfigControl( _p_this, _p_item, _parent, l, line )
622 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
623 module_config_t *_p_item,
624 QLabel *_label, QSpinBox *_spin ) :
625 IntegerConfigControl( _p_this, _p_item, _label, _spin )
630 void IntegerRangeConfigControl::finish()
632 spin->setMaximum( p_item->max.i );
633 spin->setMinimum( p_item->min.i );
636 IntegerRangeSliderConfigControl::IntegerRangeSliderConfigControl(
637 vlc_object_t *_p_this,
638 module_config_t *_p_item,
639 QLabel *_label, QSlider *_slider ):
640 VIntConfigControl( _p_this, _p_item )
644 slider->setMaximum( p_item->max.i );
645 slider->setMinimum( p_item->min.i );
646 slider->setValue( p_item->value.i );
647 slider->setToolTip( qfu(p_item->psz_longtext) );
649 label->setToolTip( qfu(p_item->psz_longtext) );
652 int IntegerRangeSliderConfigControl::getValue()
654 return slider->value();
658 /********* Integer / choice list **********/
659 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
660 module_config_t *_p_item, QWidget *_parent, bool bycat,
661 QGridLayout *l, int &line) :
662 VIntConfigControl( _p_this, _p_item, _parent )
664 label = new QLabel( qfu(p_item->psz_text) );
665 combo = new QComboBox();
669 QHBoxLayout *layout = new QHBoxLayout();
670 layout->addWidget( label ); layout->addWidget( combo );
671 widget->setLayout( layout );
675 l->addWidget( label, line, 0 );
676 l->addWidget( combo, line, 1, Qt::AlignRight );
679 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
680 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
681 bool bycat ) : VIntConfigControl( _p_this, _p_item )
688 void IntegerListConfigControl::finish( bool bycat )
690 combo->setEditable( false );
692 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
694 combo->addItem( qfu(p_item->ppsz_list_text[i_index] ),
695 QVariant( p_item->pi_list[i_index] ) );
696 if( p_item->value.i == p_item->pi_list[i_index] )
697 combo->setCurrentIndex( combo->count() - 1 );
699 combo->setToolTip( qfu(p_item->psz_longtext) );
701 label->setToolTip( qfu(p_item->psz_longtext) );
704 int IntegerListConfigControl::getValue()
706 return combo->itemData( combo->currentIndex() ).toInt();
709 /*********** Boolean **************/
710 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
711 module_config_t *_p_item,
712 QWidget *_parent, QGridLayout *l,
714 VIntConfigControl( _p_this, _p_item, _parent )
716 checkbox = new QCheckBox( qfu(p_item->psz_text) );
721 QHBoxLayout *layout = new QHBoxLayout();
722 layout->addWidget( checkbox, 0 );
723 widget->setLayout( layout );
727 l->addWidget( checkbox, line, 0 );
730 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
731 module_config_t *_p_item,
733 QCheckBox *_checkbox,
735 VIntConfigControl( _p_this, _p_item )
737 checkbox = _checkbox;
741 void BoolConfigControl::finish()
743 checkbox->setCheckState( p_item->value.i == VLC_TRUE ? Qt::Checked
745 checkbox->setToolTip( qfu(p_item->psz_longtext) );
748 int BoolConfigControl::getValue()
750 return checkbox->checkState() == Qt::Checked ? VLC_TRUE : VLC_FALSE;
753 /**************************************************************************
754 * Float-based controls
755 *************************************************************************/
757 /*********** Float **************/
758 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
759 module_config_t *_p_item,
760 QWidget *_parent, QGridLayout *l,
762 VFloatConfigControl( _p_this, _p_item, _parent )
764 label = new QLabel( qfu(p_item->psz_text) );
765 spin = new QDoubleSpinBox; spin->setMinimumWidth( 80 );
766 spin->setMaximumWidth( 90 );
771 QHBoxLayout *layout = new QHBoxLayout();
772 layout->addWidget( label, 0 ); layout->addWidget( spin, 1 );
773 widget->setLayout( layout );
777 l->addWidget( label, line, 0 );
778 l->addWidget( spin, line, 1, Qt::AlignRight );
782 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
783 module_config_t *_p_item,
785 QDoubleSpinBox *_spin ) :
786 VFloatConfigControl( _p_this, _p_item )
793 void FloatConfigControl::finish()
795 spin->setMaximum( 2000000000. );
796 spin->setMinimum( -2000000000. );
797 spin->setSingleStep( 0.1 );
798 spin->setValue( (double)p_item->value.f );
799 spin->setToolTip( qfu(p_item->psz_longtext) );
801 label->setToolTip( qfu(p_item->psz_longtext) );
804 float FloatConfigControl::getValue()
806 return (float)spin->value();
809 /*********** Float with range **************/
810 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
811 module_config_t *_p_item,
812 QWidget *_parent, QGridLayout *l,
814 FloatConfigControl( _p_this, _p_item, _parent, l, line )
819 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
820 module_config_t *_p_item,
822 QDoubleSpinBox *_spin ) :
823 FloatConfigControl( _p_this, _p_item, _label, _spin )
828 void FloatRangeConfigControl::finish()
830 spin->setMaximum( (double)p_item->max.f );
831 spin->setMinimum( (double)p_item->min.f );
835 /**********************************************************************
836 * Key selector widget
837 **********************************************************************/
838 KeySelectorControl::KeySelectorControl( vlc_object_t *_p_this,
839 module_config_t *_p_item,
840 QWidget *_parent, QGridLayout *l,
842 ConfigControl( _p_this, _p_item, _parent )
845 label = new QLabel( qtr("Select an action to change the associated hotkey") );
846 table = new QTreeWidget( 0 );
851 QVBoxLayout *layout = new QVBoxLayout();
852 layout->addWidget( label, 0 ); layout->addWidget( table, 1 );
853 widget->setLayout( layout );
857 l->addWidget( label, line, 0, 1, 2 );
858 l->addWidget( table, line+1, 0, 1,2 );
862 void KeySelectorControl::finish()
865 label->setToolTip( qfu(p_item->psz_longtext) );
868 table->setColumnCount( 2 );
869 table->setAlternatingRowColors( true );
871 module_t *p_main = config_FindModule( p_this, "main" );
874 for (size_t i = 0; i < p_main->confsize; i++)
876 module_config_t *p_item = p_main->p_config + i;
878 if( p_item->i_type & CONFIG_ITEM && p_item->psz_name &&
879 strstr( p_item->psz_name , "key-" ) )
881 QTreeWidgetItem *treeItem = new QTreeWidgetItem();
882 treeItem->setText( 0, qfu( p_item->psz_text ) );
883 treeItem->setText( 1, VLCKeyToString( p_item->value.i ) );
884 treeItem->setData( 0, Qt::UserRole,
885 QVariant::fromValue( (void*)p_item ) );
887 table->addTopLevelItem( treeItem );
890 table->resizeColumnToContents( 0 );
892 CONNECT( table, itemDoubleClicked( QTreeWidgetItem *, int ),
893 this, selectKey( QTreeWidgetItem * ) );
896 void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem )
898 module_config_t *p_keyItem = static_cast<module_config_t*>
899 (keyItem->data( 0, Qt::UserRole ).value<void*>());
901 KeyInputDialog *d = new KeyInputDialog( values, p_keyItem->psz_text );
903 if( d->result() == QDialog::Accepted )
905 p_keyItem->value.i = d->keyValue;
908 for( int i = 0; i < table->topLevelItemCount() ; i++ )
910 QTreeWidgetItem *it = table->topLevelItem(i);
911 module_config_t *p_item = static_cast<module_config_t*>
912 (it->data( 0, Qt::UserRole ).value<void*>());
913 it->setText( 1, VLCKeyToString( p_item->value.i ) );
917 keyItem->setText( 1, VLCKeyToString( p_keyItem->value.i ) );
922 void KeySelectorControl::doApply()
924 foreach( module_config_t *p_current, values )
926 config_PutInt( p_this, p_current->psz_name, p_current->value.i );
930 KeyInputDialog::KeyInputDialog( QList<module_config_t*>& _values,
931 const char * _keyToChange ) :
932 QDialog(0), keyValue(0)
937 keyToChange = _keyToChange;
938 setWindowTitle( qtr( "Hotkey for " ) + qfu( keyToChange) );
940 QVBoxLayout *l = new QVBoxLayout( this );
941 selected = new QLabel( qtr("Press the new keys for ") + qfu(keyToChange) );
942 warning = new QLabel();
943 l->addWidget( selected , Qt::AlignCenter );
944 l->addWidget( warning, Qt::AlignCenter );
946 QHBoxLayout *l2 = new QHBoxLayout();
947 QPushButton *ok = new QPushButton( qtr("OK") );
949 QPushButton *cancel = new QPushButton( qtr("Cancel") );
950 l2->addWidget( cancel );
952 BUTTONACT( ok, accept() );
953 BUTTONACT( cancel, reject() );
958 void KeyInputDialog::keyPressEvent( QKeyEvent *e )
960 if( e->key() == Qt::Key_Tab ) return;
961 int i_vlck = qtEventToVLCKey( e );
962 selected->setText( VLCKeyToString( i_vlck ) );
964 module_config_t *p_current = NULL;
965 foreach( p_current, values )
967 if( p_current->value.i == i_vlck && strcmp( p_current->psz_text,
970 p_current->value.i = 0;
978 qtr("Warning: the key is already assigned to \"") +
979 QString( p_current->psz_text ) + "\"" );
981 else warning->setText( "" );