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>
49 #include <QFontDialog>
53 ConfigControl *ConfigControl::createControl( vlc_object_t *p_this,
54 module_config_t *p_item,
58 return createControl( p_this, p_item, parent, NULL, i );
61 ConfigControl *ConfigControl::createControl( vlc_object_t *p_this,
62 module_config_t *p_item,
64 QGridLayout *l, int &line )
66 ConfigControl *p_control = NULL;
67 if( p_item->psz_current ) return NULL;
69 switch( p_item->i_type )
71 case CONFIG_ITEM_MODULE:
72 p_control = new ModuleConfigControl( p_this, p_item, parent, false,
75 case CONFIG_ITEM_MODULE_CAT:
76 p_control = new ModuleConfigControl( p_this, p_item, parent, true,
79 case CONFIG_ITEM_MODULE_LIST:
80 p_control = new ModuleListConfigControl( p_this, p_item, parent, false,
83 case CONFIG_ITEM_MODULE_LIST_CAT:
84 p_control = new ModuleListConfigControl( p_this, p_item, parent, true,
87 case CONFIG_ITEM_STRING:
89 p_control = new StringConfigControl( p_this, p_item, parent,
92 p_control = new StringListConfigControl( p_this, p_item,
93 parent, false, l, line );
95 case CONFIG_ITEM_INTEGER:
97 p_control = new IntegerListConfigControl( p_this, p_item,
98 parent, false, l, line );
99 else if( p_item->min.i || p_item->max.i )
100 p_control = new IntegerRangeConfigControl( p_this, p_item, parent,
103 p_control = new IntegerConfigControl( p_this, p_item, parent,
106 case CONFIG_ITEM_FILE:
107 p_control = new FileConfigControl( p_this, p_item, parent, l,
110 case CONFIG_ITEM_DIRECTORY:
111 p_control = new DirectoryConfigControl( p_this, p_item, parent, l,
114 case CONFIG_ITEM_FONT:
115 p_control = new FontConfigControl( p_this, p_item, parent, l,
118 case CONFIG_ITEM_KEY:
119 p_control = new KeySelectorControl( p_this, p_item, parent, l, line );
121 case CONFIG_ITEM_BOOL:
122 p_control = new BoolConfigControl( p_this, p_item, parent, l, line );
124 case CONFIG_ITEM_FLOAT:
125 if( p_item->min.f || p_item->max.f )
126 p_control = new FloatRangeConfigControl( p_this, p_item, parent,
129 p_control = new FloatConfigControl( p_this, p_item, parent,
138 void ConfigControl::doApply( intf_thread_t *p_intf )
144 VIntConfigControl *vicc = qobject_cast<VIntConfigControl *>(this);
146 config_PutInt( p_intf, vicc->getName(), vicc->getValue() );
151 VFloatConfigControl *vfcc =
152 qobject_cast<VFloatConfigControl *>(this);
154 config_PutFloat( p_intf, vfcc->getName(), vfcc->getValue() );
159 VStringConfigControl *vscc =
160 qobject_cast<VStringConfigControl *>(this);
162 config_PutPsz( p_intf, vscc->getName(), qta( vscc->getValue() ) );
167 KeySelectorControl *ksc = qobject_cast<KeySelectorControl *>(this);
174 /**************************************************************************
175 * String-based controls
176 *************************************************************************/
178 /*********** String **************/
179 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
180 module_config_t *_p_item,
181 QWidget *_parent, QGridLayout *l,
182 int &line, bool pwd ) :
183 VStringConfigControl( _p_this, _p_item, _parent )
185 label = new QLabel( qfu(p_item->psz_text) );
186 text = new QLineEdit( qfu(p_item->value.psz) );
191 QHBoxLayout *layout = new QHBoxLayout();
192 layout->addWidget( label, 0 ); layout->addWidget( text, 1 );
193 widget->setLayout( layout );
197 l->addWidget( label, line, 0 ); l->addWidget( text, line, 1 );
201 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
202 module_config_t *_p_item,
203 QLabel *_label, QLineEdit *_text, bool pwd ):
204 VStringConfigControl( _p_this, _p_item )
211 void StringConfigControl::finish()
213 text->setText( qfu(p_item->value.psz) );
214 text->setToolTip( qfu(p_item->psz_longtext) );
216 label->setToolTip( qfu(p_item->psz_longtext) );
219 /*********** File **************/
220 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
221 module_config_t *_p_item,
222 QWidget *_parent, QGridLayout *l,
223 int &line, bool pwd ) :
224 VStringConfigControl( _p_this, _p_item, _parent )
226 label = new QLabel( qfu(p_item->psz_text) );
227 text = new QLineEdit( qfu(p_item->value.psz) );
228 browse = new QPushButton( qtr( "Browse" ) );
230 BUTTONACT( browse, updateField() );
236 QHBoxLayout *layout = new QHBoxLayout();
237 layout->addWidget( label, 0 ); layout->addWidget( text, 1 );
238 layout->addWidget( browse, 2 );
239 widget->setLayout( layout );
243 l->addWidget( label, line, 0 ); l->addWidget( text, line, 1 );
244 l->addWidget( browse, line, 2 );
249 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
250 module_config_t *_p_item,
251 QLabel *_label, QLineEdit *_text,
252 QPushButton *_button, bool pwd ):
253 VStringConfigControl( _p_this, _p_item )
259 BUTTONACT( browse, updateField() );
264 void FileConfigControl::updateField()
266 QString file = QFileDialog::getOpenFileName( NULL,
267 qtr( "Select File" ), qfu( p_this->p_libvlc->psz_homedir ) );
268 if( file.isNull() ) return;
269 text->setText( file );
272 void FileConfigControl::finish()
274 text->setText( qfu(p_item->value.psz) );
275 text->setToolTip( qfu(p_item->psz_longtext) );
277 label->setToolTip( qfu(p_item->psz_longtext) );
280 /********* String / Directory **********/
281 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
282 module_config_t *_p_item, QWidget *_p_widget,
283 QGridLayout *_p_layout, int& _int, bool _pwd ) :
284 FileConfigControl( _p_this, _p_item, _p_widget, _p_layout, _int, _pwd)
287 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
288 module_config_t *_p_item, QLabel *_p_label,
289 QLineEdit *_p_line, QPushButton *_p_button, bool _pwd ):
290 FileConfigControl( _p_this, _p_item, _p_label, _p_line, _p_button, _pwd)
293 void DirectoryConfigControl::updateField()
295 QString dir = QFileDialog::getExistingDirectory( NULL,
296 qtr( "Select Directory" ),
297 qfu( p_this->p_libvlc->psz_homedir ),
298 QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks );
299 if( dir.isNull() ) return;
300 text->setText( dir );
303 /********* String / Font **********/
304 FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
305 module_config_t *_p_item, QWidget *_p_widget,
306 QGridLayout *_p_layout, int& _int, bool _pwd ) :
307 FileConfigControl( _p_this, _p_item, _p_widget, _p_layout, _int, _pwd)
310 FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
311 module_config_t *_p_item, QLabel *_p_label,
312 QLineEdit *_p_line, QPushButton *_p_button, bool _pwd ):
313 FileConfigControl( _p_this, _p_item, _p_label, _p_line, _p_button, _pwd)
316 void FontConfigControl::updateField()
319 QFont font = QFontDialog::getFont( &ok, QFont( text->text() ), NULL );
321 text->setText( font.family() );
324 /********* String / choice list **********/
325 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
326 module_config_t *_p_item, QWidget *_parent, bool bycat,
327 QGridLayout *l, int &line) :
328 VStringConfigControl( _p_this, _p_item, _parent )
330 label = new QLabel( qfu(p_item->psz_text) );
331 combo = new QComboBox();
335 QHBoxLayout *layout = new QHBoxLayout();
336 layout->addWidget( label ); layout->addWidget( combo );
337 widget->setLayout( layout );
341 l->addWidget( label, line, 0 );
342 l->addWidget( combo, line, 1, Qt::AlignRight );
345 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
346 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
347 bool bycat ) : VStringConfigControl( _p_this, _p_item )
354 void StringListConfigControl::finish( bool bycat )
356 combo->setEditable( false );
358 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
360 combo->addItem( qfu(p_item->ppsz_list_text ?
361 p_item->ppsz_list_text[i_index] :
362 p_item->ppsz_list[i_index] ),
363 QVariant( p_item->ppsz_list[i_index] ) );
364 if( p_item->value.psz && !strcmp( p_item->value.psz,
365 p_item->ppsz_list[i_index] ) )
366 combo->setCurrentIndex( combo->count() - 1 );
368 combo->setToolTip( qfu(p_item->psz_longtext) );
370 label->setToolTip( qfu(p_item->psz_longtext) );
373 QString StringListConfigControl::getValue()
375 return combo->itemData( combo->currentIndex() ).toString();
378 /********* Module **********/
379 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
380 module_config_t *_p_item, QWidget *_parent, bool bycat,
381 QGridLayout *l, int &line) :
382 VStringConfigControl( _p_this, _p_item, _parent )
384 label = new QLabel( qfu(p_item->psz_text) );
385 combo = new QComboBox();
389 QHBoxLayout *layout = new QHBoxLayout();
390 layout->addWidget( label ); layout->addWidget( combo );
391 widget->setLayout( layout );
395 l->addWidget( label, line, 0 );
396 l->addWidget( combo, line, 1, Qt::AlignRight );
399 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
400 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
401 bool bycat ) : VStringConfigControl( _p_this, _p_item )
408 void ModuleConfigControl::finish( bool bycat )
413 combo->setEditable( false );
415 /* build a list of available modules */
416 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
417 combo->addItem( qtr("Default") );
418 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
420 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
424 if( !strcmp( p_parser->psz_object_name, "main" ) ) continue;
426 for (size_t i = 0; i < p_parser->confsize; i++)
428 module_config_t *p_config = p_parser->p_config + i;
429 /* Hack: required subcategory is stored in i_min */
430 if( p_config->i_type == CONFIG_SUBCATEGORY &&
431 p_config->value.i == p_item->min.i )
432 combo->addItem( qfu(p_parser->psz_longname),
433 QVariant( p_parser->psz_object_name ) );
434 if( p_item->value.psz && !strcmp( p_item->value.psz,
435 p_parser->psz_object_name) )
436 combo->setCurrentIndex( combo->count() - 1 );
439 else if( !strcmp( p_parser->psz_capability, p_item->psz_type ) )
441 combo->addItem( qfu(p_parser->psz_longname),
442 QVariant( p_parser->psz_object_name ) );
443 if( p_item->value.psz && !strcmp( p_item->value.psz,
444 p_parser->psz_object_name) )
445 combo->setCurrentIndex( combo->count() - 1 );
448 vlc_list_release( p_list );
449 combo->setToolTip( qfu(p_item->psz_longtext) );
451 label->setToolTip( qfu(p_item->psz_longtext) );
454 QString ModuleConfigControl::getValue()
456 return combo->itemData( combo->currentIndex() ).toString();
459 /********* Module list **********/
460 ModuleListConfigControl::ModuleListConfigControl( vlc_object_t *_p_this,
461 module_config_t *_p_item, QWidget *_parent, bool bycat,
462 QGridLayout *l, int &line) :
463 VStringConfigControl( _p_this, _p_item, _parent )
465 label = new QLabel( qfu(p_item->psz_text) );
466 text = new QLineEdit();
472 l = new QGridLayout();
476 for( QVector<QCheckBox*>::iterator it = modules.begin();
477 it != modules.end(); it++ )
479 l->addWidget( *it, line++, 1 );
481 l->addWidget( label, line, 0 );
482 l->addWidget( text, line, 1 );
484 widget->setLayout( l );
487 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
488 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
489 bool bycat ) : VStringConfigControl( _p_this, _p_item )
497 ModuleListConfigControl::~ModuleListConfigControl()
499 for( QVector<QCheckBox*>::iterator it = modules.begin();
500 it != modules.end(); it++ )
508 void ModuleListConfigControl::finish( bool bycat )
513 /* build a list of available modules */
514 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
515 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
517 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
521 if( !strcmp( p_parser->psz_object_name, "main" ) ) continue;
523 for (size_t i = 0; i < p_parser->confsize; i++)
525 module_config_t *p_config = p_parser->p_config + i;
526 /* Hack: required subcategory is stored in i_min */
527 if( p_config->i_type == CONFIG_SUBCATEGORY &&
528 p_config->value.i == p_item->min.i )
531 new QCheckBox( qfu( p_parser->psz_object_name ) );
532 cb->setToolTip( qfu(p_parser->psz_longname) );
533 modules.push_back( cb );
537 else if( !strcmp( p_parser->psz_capability, p_item->psz_type ) )
540 new QCheckBox( qfu( p_parser->psz_object_name ) );
541 cb->setToolTip( qfu(p_parser->psz_longname) );
542 modules.push_back( cb );
545 vlc_list_release( p_list );
546 text->setToolTip( qfu(p_item->psz_longtext) );
548 label->setToolTip( qfu(p_item->psz_longtext) );
551 QString ModuleListConfigControl::getValue()
556 void ModuleListConfigControl::hide()
558 for( QVector<QCheckBox*>::iterator it = modules.begin();
559 it != modules.end(); it++ )
567 void ModuleListConfigControl::show()
569 for( QVector<QCheckBox*>::iterator it = modules.begin();
570 it != modules.end(); it++ )
579 void ModuleListConfigControl::wakeUp_TheUserJustClickedOnSomething( int value )
582 for( QVector<QCheckBox*>::iterator it = modules.begin();
583 it != modules.end(); it++ )
588 /**************************************************************************
589 * Integer-based controls
590 *************************************************************************/
592 /*********** Integer **************/
593 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
594 module_config_t *_p_item,
595 QWidget *_parent, QGridLayout *l,
597 VIntConfigControl( _p_this, _p_item, _parent )
599 label = new QLabel( qfu(p_item->psz_text) );
600 spin = new QSpinBox; spin->setMinimumWidth( 80 );
601 spin->setMaximumWidth( 90 );
606 QHBoxLayout *layout = new QHBoxLayout();
607 layout->addWidget( label, 0 ); layout->addWidget( spin, 1 );
608 widget->setLayout( layout );
612 l->addWidget( label, line, 0 );
613 l->addWidget( spin, line, 1, Qt::AlignRight );
616 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
617 module_config_t *_p_item,
618 QLabel *_label, QSpinBox *_spin ) :
619 VIntConfigControl( _p_this, _p_item )
626 void IntegerConfigControl::finish()
628 spin->setMaximum( 2000000000 );
629 spin->setMinimum( -2000000000 );
630 spin->setValue( p_item->value.i );
631 spin->setToolTip( qfu(p_item->psz_longtext) );
633 label->setToolTip( qfu(p_item->psz_longtext) );
636 int IntegerConfigControl::getValue()
638 return spin->value();
641 /********* Integer range **********/
642 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
643 module_config_t *_p_item,
644 QWidget *_parent, QGridLayout *l,
646 IntegerConfigControl( _p_this, _p_item, _parent, l, line )
651 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
652 module_config_t *_p_item,
653 QLabel *_label, QSpinBox *_spin ) :
654 IntegerConfigControl( _p_this, _p_item, _label, _spin )
659 void IntegerRangeConfigControl::finish()
661 spin->setMaximum( p_item->max.i );
662 spin->setMinimum( p_item->min.i );
665 IntegerRangeSliderConfigControl::IntegerRangeSliderConfigControl(
666 vlc_object_t *_p_this,
667 module_config_t *_p_item,
668 QLabel *_label, QSlider *_slider ):
669 VIntConfigControl( _p_this, _p_item )
673 slider->setMaximum( p_item->max.i );
674 slider->setMinimum( p_item->min.i );
675 slider->setValue( p_item->value.i );
676 slider->setToolTip( qfu(p_item->psz_longtext) );
678 label->setToolTip( qfu(p_item->psz_longtext) );
681 int IntegerRangeSliderConfigControl::getValue()
683 return slider->value();
687 /********* Integer / choice list **********/
688 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
689 module_config_t *_p_item, QWidget *_parent, bool bycat,
690 QGridLayout *l, int &line) :
691 VIntConfigControl( _p_this, _p_item, _parent )
693 label = new QLabel( qfu(p_item->psz_text) );
694 combo = new QComboBox();
698 QHBoxLayout *layout = new QHBoxLayout();
699 layout->addWidget( label ); layout->addWidget( combo );
700 widget->setLayout( layout );
704 l->addWidget( label, line, 0 );
705 l->addWidget( combo, line, 1, Qt::AlignRight );
708 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
709 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
710 bool bycat ) : VIntConfigControl( _p_this, _p_item )
717 void IntegerListConfigControl::finish( bool bycat )
719 combo->setEditable( false );
721 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
723 combo->addItem( qfu(p_item->ppsz_list_text[i_index] ),
724 QVariant( p_item->pi_list[i_index] ) );
725 if( p_item->value.i == p_item->pi_list[i_index] )
726 combo->setCurrentIndex( combo->count() - 1 );
728 combo->setToolTip( qfu(p_item->psz_longtext) );
730 label->setToolTip( qfu(p_item->psz_longtext) );
733 int IntegerListConfigControl::getValue()
735 return combo->itemData( combo->currentIndex() ).toInt();
738 /*********** Boolean **************/
739 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
740 module_config_t *_p_item,
741 QWidget *_parent, QGridLayout *l,
743 VIntConfigControl( _p_this, _p_item, _parent )
745 checkbox = new QCheckBox( qfu(p_item->psz_text) );
750 QHBoxLayout *layout = new QHBoxLayout();
751 layout->addWidget( checkbox, 0 );
752 widget->setLayout( layout );
756 l->addWidget( checkbox, line, 0 );
759 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
760 module_config_t *_p_item,
762 QCheckBox *_checkbox,
764 VIntConfigControl( _p_this, _p_item )
766 checkbox = _checkbox;
770 void BoolConfigControl::finish()
772 checkbox->setCheckState( p_item->value.i == VLC_TRUE ? Qt::Checked
774 checkbox->setToolTip( qfu(p_item->psz_longtext) );
777 int BoolConfigControl::getValue()
779 return checkbox->checkState() == Qt::Checked ? VLC_TRUE : VLC_FALSE;
782 /**************************************************************************
783 * Float-based controls
784 *************************************************************************/
786 /*********** Float **************/
787 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
788 module_config_t *_p_item,
789 QWidget *_parent, QGridLayout *l,
791 VFloatConfigControl( _p_this, _p_item, _parent )
793 label = new QLabel( qfu(p_item->psz_text) );
794 spin = new QDoubleSpinBox; spin->setMinimumWidth( 80 );
795 spin->setMaximumWidth( 90 );
800 QHBoxLayout *layout = new QHBoxLayout();
801 layout->addWidget( label, 0 ); layout->addWidget( spin, 1 );
802 widget->setLayout( layout );
806 l->addWidget( label, line, 0 );
807 l->addWidget( spin, line, 1, Qt::AlignRight );
811 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
812 module_config_t *_p_item,
814 QDoubleSpinBox *_spin ) :
815 VFloatConfigControl( _p_this, _p_item )
822 void FloatConfigControl::finish()
824 spin->setMaximum( 2000000000. );
825 spin->setMinimum( -2000000000. );
826 spin->setSingleStep( 0.1 );
827 spin->setValue( (double)p_item->value.f );
828 spin->setToolTip( qfu(p_item->psz_longtext) );
830 label->setToolTip( qfu(p_item->psz_longtext) );
833 float FloatConfigControl::getValue()
835 return (float)spin->value();
838 /*********** Float with range **************/
839 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
840 module_config_t *_p_item,
841 QWidget *_parent, QGridLayout *l,
843 FloatConfigControl( _p_this, _p_item, _parent, l, line )
848 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
849 module_config_t *_p_item,
851 QDoubleSpinBox *_spin ) :
852 FloatConfigControl( _p_this, _p_item, _label, _spin )
857 void FloatRangeConfigControl::finish()
859 spin->setMaximum( (double)p_item->max.f );
860 spin->setMinimum( (double)p_item->min.f );
864 /**********************************************************************
865 * Key selector widget
866 **********************************************************************/
867 KeySelectorControl::KeySelectorControl( vlc_object_t *_p_this,
868 module_config_t *_p_item,
869 QWidget *_parent, QGridLayout *l,
871 ConfigControl( _p_this, _p_item, _parent )
874 label = new QLabel( qtr("Select an action to change the associated hotkey") );
875 table = new QTreeWidget( 0 );
880 QVBoxLayout *layout = new QVBoxLayout();
881 layout->addWidget( label, 0 ); layout->addWidget( table, 1 );
882 widget->setLayout( layout );
886 l->addWidget( label, line, 0, 1, 2 );
887 l->addWidget( table, line+1, 0, 1,2 );
891 void KeySelectorControl::finish()
894 label->setToolTip( qfu(p_item->psz_longtext) );
897 table->setColumnCount( 2 );
898 table->setAlternatingRowColors( true );
900 module_t *p_main = config_FindModule( p_this, "main" );
903 for (size_t i = 0; i < p_main->confsize; i++)
905 module_config_t *p_item = p_main->p_config + i;
907 if( p_item->i_type & CONFIG_ITEM && p_item->psz_name &&
908 strstr( p_item->psz_name , "key-" ) )
910 QTreeWidgetItem *treeItem = new QTreeWidgetItem();
911 treeItem->setText( 0, qfu( p_item->psz_text ) );
912 treeItem->setText( 1, VLCKeyToString( p_item->value.i ) );
913 treeItem->setData( 0, Qt::UserRole,
914 QVariant::fromValue( (void*)p_item ) );
916 table->addTopLevelItem( treeItem );
919 table->resizeColumnToContents( 0 );
921 CONNECT( table, itemDoubleClicked( QTreeWidgetItem *, int ),
922 this, selectKey( QTreeWidgetItem * ) );
925 void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem )
927 module_config_t *p_keyItem = static_cast<module_config_t*>
928 (keyItem->data( 0, Qt::UserRole ).value<void*>());
930 KeyInputDialog *d = new KeyInputDialog( values, p_keyItem->psz_text );
932 if( d->result() == QDialog::Accepted )
934 p_keyItem->value.i = d->keyValue;
937 for( int i = 0; i < table->topLevelItemCount() ; i++ )
939 QTreeWidgetItem *it = table->topLevelItem(i);
940 module_config_t *p_item = static_cast<module_config_t*>
941 (it->data( 0, Qt::UserRole ).value<void*>());
942 it->setText( 1, VLCKeyToString( p_item->value.i ) );
946 keyItem->setText( 1, VLCKeyToString( p_keyItem->value.i ) );
951 void KeySelectorControl::doApply()
953 foreach( module_config_t *p_current, values )
955 config_PutInt( p_this, p_current->psz_name, p_current->value.i );
959 KeyInputDialog::KeyInputDialog( QList<module_config_t*>& _values,
960 const char * _keyToChange ) :
961 QDialog(0), keyValue(0)
966 keyToChange = _keyToChange;
967 setWindowTitle( qtr( "Hotkey for " ) + qfu( keyToChange) );
969 QVBoxLayout *l = new QVBoxLayout( this );
970 selected = new QLabel( qtr("Press the new keys for ") + qfu(keyToChange) );
971 warning = new QLabel();
972 l->addWidget( selected , Qt::AlignCenter );
973 l->addWidget( warning, Qt::AlignCenter );
975 QHBoxLayout *l2 = new QHBoxLayout();
976 QPushButton *ok = new QPushButton( qtr("OK") );
978 QPushButton *cancel = new QPushButton( qtr("Cancel") );
979 l2->addWidget( cancel );
981 BUTTONACT( ok, accept() );
982 BUTTONACT( cancel, reject() );
987 void KeyInputDialog::keyPressEvent( QKeyEvent *e )
989 if( e->key() == Qt::Key_Tab ) return;
990 int i_vlck = qtEventToVLCKey( e );
991 selected->setText( VLCKeyToString( i_vlck ) );
993 module_config_t *p_current = NULL;
994 foreach( p_current, values )
996 if( p_current->value.i == i_vlck && strcmp( p_current->psz_text,
999 p_current->value.i = 0;
1007 qtr("Warning: the key is already assigned to \"") +
1008 QString( p_current->psz_text ) + "\"" );
1010 else warning->setText( "" );