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>
54 ConfigControl *ConfigControl::createControl( vlc_object_t *p_this,
55 module_config_t *p_item,
59 return createControl( p_this, p_item, parent, NULL, i );
62 ConfigControl *ConfigControl::createControl( vlc_object_t *p_this,
63 module_config_t *p_item,
65 QGridLayout *l, int &line )
67 ConfigControl *p_control = NULL;
68 if( p_item->psz_current ) return NULL;
70 switch( p_item->i_type )
72 case CONFIG_ITEM_MODULE:
73 p_control = new ModuleConfigControl( p_this, p_item, parent, false,
76 case CONFIG_ITEM_MODULE_CAT:
77 p_control = new ModuleConfigControl( p_this, p_item, parent, true,
80 case CONFIG_ITEM_MODULE_LIST:
81 p_control = new ModuleListConfigControl( p_this, p_item, parent, false,
84 case CONFIG_ITEM_MODULE_LIST_CAT:
85 p_control = new ModuleListConfigControl( p_this, p_item, parent, true,
88 case CONFIG_ITEM_STRING:
90 p_control = new StringConfigControl( p_this, p_item, parent,
93 p_control = new StringListConfigControl( p_this, p_item,
94 parent, false, l, line );
96 case CONFIG_ITEM_INTEGER:
98 p_control = new IntegerListConfigControl( p_this, p_item,
99 parent, false, l, line );
100 else if( p_item->min.i || p_item->max.i )
101 p_control = new IntegerRangeConfigControl( p_this, p_item, parent,
104 p_control = new IntegerConfigControl( p_this, p_item, parent,
107 case CONFIG_ITEM_FILE:
108 p_control = new FileConfigControl( p_this, p_item, parent, l,
111 case CONFIG_ITEM_DIRECTORY:
112 p_control = new DirectoryConfigControl( p_this, p_item, parent, l,
115 case CONFIG_ITEM_FONT:
116 p_control = new FontConfigControl( p_this, p_item, parent, l,
119 case CONFIG_ITEM_KEY:
120 p_control = new KeySelectorControl( p_this, p_item, parent, l, line );
122 case CONFIG_ITEM_BOOL:
123 p_control = new BoolConfigControl( p_this, p_item, parent, l, line );
125 case CONFIG_ITEM_FLOAT:
126 if( p_item->min.f || p_item->max.f )
127 p_control = new FloatRangeConfigControl( p_this, p_item, parent,
130 p_control = new FloatConfigControl( p_this, p_item, parent,
139 void ConfigControl::doApply( intf_thread_t *p_intf )
145 VIntConfigControl *vicc = qobject_cast<VIntConfigControl *>(this);
147 config_PutInt( p_intf, vicc->getName(), vicc->getValue() );
152 VFloatConfigControl *vfcc =
153 qobject_cast<VFloatConfigControl *>(this);
155 config_PutFloat( p_intf, vfcc->getName(), vfcc->getValue() );
160 VStringConfigControl *vscc =
161 qobject_cast<VStringConfigControl *>(this);
163 config_PutPsz( p_intf, vscc->getName(), qta( vscc->getValue() ) );
168 KeySelectorControl *ksc = qobject_cast<KeySelectorControl *>(this);
175 /**************************************************************************
176 * String-based controls
177 *************************************************************************/
179 /*********** String **************/
180 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
181 module_config_t *_p_item,
182 QWidget *_parent, QGridLayout *l,
183 int &line, bool pwd ) :
184 VStringConfigControl( _p_this, _p_item, _parent )
186 label = new QLabel( qfu(p_item->psz_text) );
187 text = new QLineEdit( qfu(p_item->value.psz) );
192 QHBoxLayout *layout = new QHBoxLayout();
193 layout->addWidget( label, 0 ); layout->addWidget( text, 1 );
194 widget->setLayout( layout );
198 l->addWidget( label, line, 0 ); l->addWidget( text, line, 1 );
202 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
203 module_config_t *_p_item,
204 QLabel *_label, QLineEdit *_text, bool pwd ):
205 VStringConfigControl( _p_this, _p_item )
212 void StringConfigControl::finish()
214 text->setText( qfu(p_item->value.psz) );
215 text->setToolTip( qfu(p_item->psz_longtext) );
217 label->setToolTip( qfu(p_item->psz_longtext) );
220 /*********** File **************/
221 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
222 module_config_t *_p_item,
223 QWidget *_parent, QGridLayout *l,
224 int &line, bool pwd ) :
225 VStringConfigControl( _p_this, _p_item, _parent )
227 label = new QLabel( qfu(p_item->psz_text) );
228 text = new QLineEdit( qfu(p_item->value.psz) );
229 browse = new QPushButton( qtr( "Browse..." ) );
230 QHBoxLayout *textAndButton = new QHBoxLayout();
231 textAndButton->setMargin( 0 );
232 textAndButton->addWidget( text, 2 );
233 textAndButton->addWidget( browse, 0 );
235 BUTTONACT( browse, updateField() );
241 QHBoxLayout *layout = new QHBoxLayout();
242 layout->addWidget( label, 0 );
243 layout->addLayout( textAndButton, 1 );
244 widget->setLayout( layout );
248 l->addWidget( label, line, 0 );
249 l->addLayout( textAndButton, line, 1 );
254 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
255 module_config_t *_p_item,
256 QLabel *_label, QLineEdit *_text,
257 QPushButton *_button, bool pwd ):
258 VStringConfigControl( _p_this, _p_item )
264 BUTTONACT( browse, updateField() );
269 void FileConfigControl::updateField()
271 QString file = QFileDialog::getOpenFileName( NULL,
272 qtr( "Select File" ), qfu( p_this->p_libvlc->psz_homedir ) );
273 if( file.isNull() ) return;
274 text->setText( file );
277 void FileConfigControl::finish()
279 text->setText( qfu(p_item->value.psz) );
280 text->setToolTip( qfu(p_item->psz_longtext) );
282 label->setToolTip( qfu(p_item->psz_longtext) );
285 /********* String / Directory **********/
286 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
287 module_config_t *_p_item, QWidget *_p_widget,
288 QGridLayout *_p_layout, int& _int, bool _pwd ) :
289 FileConfigControl( _p_this, _p_item, _p_widget, _p_layout, _int, _pwd)
292 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
293 module_config_t *_p_item, QLabel *_p_label,
294 QLineEdit *_p_line, QPushButton *_p_button, bool _pwd ):
295 FileConfigControl( _p_this, _p_item, _p_label, _p_line, _p_button, _pwd)
298 void DirectoryConfigControl::updateField()
300 QString dir = QFileDialog::getExistingDirectory( NULL,
301 qtr( "Select Directory" ),
302 text->text().isEmpty() ?
303 qfu( p_this->p_libvlc->psz_homedir ) : text->text(),
304 QFileDialog::ShowDirsOnly |
305 QFileDialog::DontResolveSymlinks );
306 if( dir.isNull() ) return;
307 text->setText( dir );
310 /********* String / Font **********/
311 FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
312 module_config_t *_p_item, QWidget *_p_widget,
313 QGridLayout *_p_layout, int& _int, bool _pwd ) :
314 FileConfigControl( _p_this, _p_item, _p_widget, _p_layout, _int, _pwd)
317 FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
318 module_config_t *_p_item, QLabel *_p_label,
319 QLineEdit *_p_line, QPushButton *_p_button, bool _pwd ):
320 FileConfigControl( _p_this, _p_item, _p_label, _p_line, _p_button, _pwd)
323 void FontConfigControl::updateField()
326 QFont font = QFontDialog::getFont( &ok, QFont( text->text() ), NULL );
328 text->setText( font.family() );
331 /********* String / choice list **********/
332 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
333 module_config_t *_p_item, QWidget *_parent, bool bycat,
334 QGridLayout *l, int &line) :
335 VStringConfigControl( _p_this, _p_item, _parent )
337 label = new QLabel( qfu(p_item->psz_text) );
338 combo = new QComboBox();
342 QHBoxLayout *layout = new QHBoxLayout();
343 layout->addWidget( label ); layout->addWidget( combo );
344 widget->setLayout( layout );
348 l->addWidget( label, line, 0 );
349 l->addWidget( combo, line, 1, Qt::AlignRight );
352 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
353 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
354 bool bycat ) : VStringConfigControl( _p_this, _p_item )
361 void StringListConfigControl::finish( bool bycat )
363 combo->setEditable( false );
365 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
367 combo->addItem( qfu(p_item->ppsz_list_text ?
368 p_item->ppsz_list_text[i_index] :
369 p_item->ppsz_list[i_index] ),
370 QVariant( p_item->ppsz_list[i_index] ) );
371 if( p_item->value.psz && !strcmp( p_item->value.psz,
372 p_item->ppsz_list[i_index] ) )
373 combo->setCurrentIndex( combo->count() - 1 );
375 combo->setToolTip( qfu(p_item->psz_longtext) );
377 label->setToolTip( qfu(p_item->psz_longtext) );
380 QString StringListConfigControl::getValue()
382 return combo->itemData( combo->currentIndex() ).toString();
385 /********* Module **********/
386 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
387 module_config_t *_p_item, QWidget *_parent, bool bycat,
388 QGridLayout *l, int &line) :
389 VStringConfigControl( _p_this, _p_item, _parent )
391 label = new QLabel( qfu(p_item->psz_text) );
392 combo = new QComboBox();
396 QHBoxLayout *layout = new QHBoxLayout();
397 layout->addWidget( label ); layout->addWidget( combo );
398 widget->setLayout( layout );
402 l->addWidget( label, line, 0 );
403 l->addWidget( combo, line, 1, Qt::AlignRight );
406 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
407 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
408 bool bycat ) : VStringConfigControl( _p_this, _p_item )
415 void ModuleConfigControl::finish( bool bycat )
420 combo->setEditable( false );
422 /* build a list of available modules */
423 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
424 combo->addItem( qtr("Default") );
425 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
427 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
431 if( !strcmp( p_parser->psz_object_name, "main" ) ) continue;
433 for (size_t i = 0; i < p_parser->confsize; i++)
435 module_config_t *p_config = p_parser->p_config + i;
436 /* Hack: required subcategory is stored in i_min */
437 if( p_config->i_type == CONFIG_SUBCATEGORY &&
438 p_config->value.i == p_item->min.i )
439 combo->addItem( qfu(p_parser->psz_longname),
440 QVariant( p_parser->psz_object_name ) );
441 if( p_item->value.psz && !strcmp( p_item->value.psz,
442 p_parser->psz_object_name) )
443 combo->setCurrentIndex( combo->count() - 1 );
446 else if( !strcmp( p_parser->psz_capability, p_item->psz_type ) )
448 combo->addItem( qfu(p_parser->psz_longname),
449 QVariant( p_parser->psz_object_name ) );
450 if( p_item->value.psz && !strcmp( p_item->value.psz,
451 p_parser->psz_object_name) )
452 combo->setCurrentIndex( combo->count() - 1 );
455 vlc_list_release( p_list );
456 combo->setToolTip( qfu(p_item->psz_longtext) );
458 label->setToolTip( qfu(p_item->psz_longtext) );
461 QString ModuleConfigControl::getValue()
463 return combo->itemData( combo->currentIndex() ).toString();
466 /********* Module list **********/
467 ModuleListConfigControl::ModuleListConfigControl( vlc_object_t *_p_this,
468 module_config_t *_p_item, QWidget *_parent, bool bycat,
469 QGridLayout *l, int &line) :
470 VStringConfigControl( _p_this, _p_item, _parent )
472 groupBox = new QGroupBox ( qfu(p_item->psz_text) );
473 text = new QLineEdit();
474 QGridLayout *layoutGroupBox = new QGridLayout( groupBox );
479 for( QVector<QCheckBox*>::iterator it = modules.begin();
480 it != modules.end(); it++ )
482 layoutGroupBox->addWidget( *it, boxline++, 0 );
484 layoutGroupBox->addWidget( text, boxline, 0 );
488 QVBoxLayout *layout = new QVBoxLayout();
489 layout->addWidget( groupBox, line, 0 );
490 widget->setLayout( layout );
494 l->addWidget( groupBox, line, 0, 1, -1 );
498 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
499 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
500 bool bycat ) : VStringConfigControl( _p_this, _p_item )
508 ModuleListConfigControl::~ModuleListConfigControl()
510 for( QVector<QCheckBox*>::iterator it = modules.begin();
511 it != modules.end(); it++ )
519 void ModuleListConfigControl::finish( bool bycat )
524 /* build a list of available modules */
525 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
526 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
528 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
532 if( !strcmp( p_parser->psz_object_name, "main" ) ) continue;
534 for (size_t i = 0; i < p_parser->confsize; i++)
536 module_config_t *p_config = p_parser->p_config + i;
537 /* Hack: required subcategory is stored in i_min */
538 if( p_config->i_type == CONFIG_SUBCATEGORY &&
539 p_config->value.i == p_item->min.i )
542 new QCheckBox( qfu( p_parser->psz_object_name ) );
543 cb->setToolTip( qfu(p_parser->psz_longname) );
544 modules.push_back( cb );
548 else if( !strcmp( p_parser->psz_capability, p_item->psz_type ) )
551 new QCheckBox( qfu( p_parser->psz_object_name ) );
552 cb->setToolTip( qfu(p_parser->psz_longname) );
553 modules.push_back( cb );
556 vlc_list_release( p_list );
557 text->setToolTip( qfu(p_item->psz_longtext) );
559 groupBox->setToolTip( qfu(p_item->psz_longtext) );
562 QString ModuleListConfigControl::getValue()
567 void ModuleListConfigControl::hide()
569 for( QVector<QCheckBox*>::iterator it = modules.begin();
570 it != modules.end(); it++ )
577 void ModuleListConfigControl::show()
579 for( QVector<QCheckBox*>::iterator it = modules.begin();
580 it != modules.end(); it++ )
588 void ModuleListConfigControl::wakeUp_TheUserJustClickedOnSomething( int value )
591 for( QVector<QCheckBox*>::iterator it = modules.begin();
592 it != modules.end(); it++ )
597 /**************************************************************************
598 * Integer-based controls
599 *************************************************************************/
601 /*********** Integer **************/
602 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
603 module_config_t *_p_item,
604 QWidget *_parent, QGridLayout *l,
606 VIntConfigControl( _p_this, _p_item, _parent )
608 label = new QLabel( qfu(p_item->psz_text) );
609 spin = new QSpinBox; spin->setMinimumWidth( 80 );
610 spin->setAlignment( Qt::AlignRight );
611 spin->setMaximumWidth( 90 );
616 QHBoxLayout *layout = new QHBoxLayout();
617 layout->addWidget( label, 0 ); layout->addWidget( spin, 1 );
618 widget->setLayout( layout );
622 l->addWidget( label, line, 0 );
623 l->addWidget( spin, line, 1, Qt::AlignRight );
626 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
627 module_config_t *_p_item,
628 QLabel *_label, QSpinBox *_spin ) :
629 VIntConfigControl( _p_this, _p_item )
636 void IntegerConfigControl::finish()
638 spin->setMaximum( 2000000000 );
639 spin->setMinimum( -2000000000 );
640 spin->setValue( p_item->value.i );
641 spin->setToolTip( qfu(p_item->psz_longtext) );
643 label->setToolTip( qfu(p_item->psz_longtext) );
646 int IntegerConfigControl::getValue()
648 return spin->value();
651 /********* Integer range **********/
652 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
653 module_config_t *_p_item,
654 QWidget *_parent, QGridLayout *l,
656 IntegerConfigControl( _p_this, _p_item, _parent, l, line )
661 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
662 module_config_t *_p_item,
663 QLabel *_label, QSpinBox *_spin ) :
664 IntegerConfigControl( _p_this, _p_item, _label, _spin )
669 void IntegerRangeConfigControl::finish()
671 spin->setMaximum( p_item->max.i );
672 spin->setMinimum( p_item->min.i );
675 IntegerRangeSliderConfigControl::IntegerRangeSliderConfigControl(
676 vlc_object_t *_p_this,
677 module_config_t *_p_item,
678 QLabel *_label, QSlider *_slider ):
679 VIntConfigControl( _p_this, _p_item )
683 slider->setMaximum( p_item->max.i );
684 slider->setMinimum( p_item->min.i );
685 slider->setValue( p_item->value.i );
686 slider->setToolTip( qfu(p_item->psz_longtext) );
688 label->setToolTip( qfu(p_item->psz_longtext) );
691 int IntegerRangeSliderConfigControl::getValue()
693 return slider->value();
697 /********* Integer / choice list **********/
698 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
699 module_config_t *_p_item, QWidget *_parent, bool bycat,
700 QGridLayout *l, int &line) :
701 VIntConfigControl( _p_this, _p_item, _parent )
703 label = new QLabel( qfu(p_item->psz_text) );
704 combo = new QComboBox();
708 QHBoxLayout *layout = new QHBoxLayout();
709 layout->addWidget( label ); layout->addWidget( combo );
710 widget->setLayout( layout );
714 l->addWidget( label, line, 0 );
715 l->addWidget( combo, line, 1, Qt::AlignRight );
718 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
719 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
720 bool bycat ) : VIntConfigControl( _p_this, _p_item )
727 void IntegerListConfigControl::finish( bool bycat )
729 combo->setEditable( false );
731 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
733 combo->addItem( qfu(p_item->ppsz_list_text[i_index] ),
734 QVariant( p_item->pi_list[i_index] ) );
735 if( p_item->value.i == p_item->pi_list[i_index] )
736 combo->setCurrentIndex( combo->count() - 1 );
738 combo->setToolTip( qfu(p_item->psz_longtext) );
740 label->setToolTip( qfu(p_item->psz_longtext) );
743 int IntegerListConfigControl::getValue()
745 return combo->itemData( combo->currentIndex() ).toInt();
748 /*********** Boolean **************/
749 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
750 module_config_t *_p_item,
751 QWidget *_parent, QGridLayout *l,
753 VIntConfigControl( _p_this, _p_item, _parent )
755 checkbox = new QCheckBox( qfu(p_item->psz_text) );
760 QHBoxLayout *layout = new QHBoxLayout();
761 layout->addWidget( checkbox, 0 );
762 widget->setLayout( layout );
766 l->addWidget( checkbox, line, 0 );
769 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
770 module_config_t *_p_item,
772 QCheckBox *_checkbox,
774 VIntConfigControl( _p_this, _p_item )
776 checkbox = _checkbox;
780 void BoolConfigControl::finish()
782 checkbox->setCheckState( p_item->value.i == VLC_TRUE ? Qt::Checked
784 checkbox->setToolTip( qfu(p_item->psz_longtext) );
787 int BoolConfigControl::getValue()
789 return checkbox->checkState() == Qt::Checked ? VLC_TRUE : VLC_FALSE;
792 /**************************************************************************
793 * Float-based controls
794 *************************************************************************/
796 /*********** Float **************/
797 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
798 module_config_t *_p_item,
799 QWidget *_parent, QGridLayout *l,
801 VFloatConfigControl( _p_this, _p_item, _parent )
803 label = new QLabel( qfu(p_item->psz_text) );
804 spin = new QDoubleSpinBox; spin->setMinimumWidth( 80 );
805 spin->setMaximumWidth( 90 );
806 spin->setAlignment( Qt::AlignRight );
811 QHBoxLayout *layout = new QHBoxLayout();
812 layout->addWidget( label, 0 ); layout->addWidget( spin, 1 );
813 widget->setLayout( layout );
817 l->addWidget( label, line, 0 );
818 l->addWidget( spin, line, 1, Qt::AlignRight );
822 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
823 module_config_t *_p_item,
825 QDoubleSpinBox *_spin ) :
826 VFloatConfigControl( _p_this, _p_item )
833 void FloatConfigControl::finish()
835 spin->setMaximum( 2000000000. );
836 spin->setMinimum( -2000000000. );
837 spin->setSingleStep( 0.1 );
838 spin->setValue( (double)p_item->value.f );
839 spin->setToolTip( qfu(p_item->psz_longtext) );
841 label->setToolTip( qfu(p_item->psz_longtext) );
844 float FloatConfigControl::getValue()
846 return (float)spin->value();
849 /*********** Float with range **************/
850 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
851 module_config_t *_p_item,
852 QWidget *_parent, QGridLayout *l,
854 FloatConfigControl( _p_this, _p_item, _parent, l, line )
859 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
860 module_config_t *_p_item,
862 QDoubleSpinBox *_spin ) :
863 FloatConfigControl( _p_this, _p_item, _label, _spin )
868 void FloatRangeConfigControl::finish()
870 spin->setMaximum( (double)p_item->max.f );
871 spin->setMinimum( (double)p_item->min.f );
875 /**********************************************************************
876 * Key selector widget
877 **********************************************************************/
878 KeySelectorControl::KeySelectorControl( vlc_object_t *_p_this,
879 module_config_t *_p_item,
880 QWidget *_parent, QGridLayout *l,
882 ConfigControl( _p_this, _p_item, _parent )
885 label = new QLabel( qtr("Select an action to change the associated hotkey") );
886 table = new QTreeWidget( 0 );
891 QVBoxLayout *layout = new QVBoxLayout();
892 layout->addWidget( label, 0 ); layout->addWidget( table, 1 );
893 widget->setLayout( layout );
897 l->addWidget( label, line, 0, 1, 2 );
898 l->addWidget( table, line+1, 0, 1,2 );
902 void KeySelectorControl::finish()
905 label->setToolTip( qfu(p_item->psz_longtext) );
908 table->setColumnCount( 2 );
909 table->setAlternatingRowColors( true );
911 module_t *p_main = config_FindModule( p_this, "main" );
914 for (size_t i = 0; i < p_main->confsize; i++)
916 module_config_t *p_item = p_main->p_config + i;
918 if( p_item->i_type & CONFIG_ITEM && p_item->psz_name &&
919 strstr( p_item->psz_name , "key-" ) )
921 QTreeWidgetItem *treeItem = new QTreeWidgetItem();
922 treeItem->setText( 0, qfu( p_item->psz_text ) );
923 treeItem->setText( 1, VLCKeyToString( p_item->value.i ) );
924 treeItem->setData( 0, Qt::UserRole,
925 QVariant::fromValue( (void*)p_item ) );
927 table->addTopLevelItem( treeItem );
930 table->resizeColumnToContents( 0 );
932 CONNECT( table, itemDoubleClicked( QTreeWidgetItem *, int ),
933 this, selectKey( QTreeWidgetItem * ) );
936 void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem )
938 module_config_t *p_keyItem = static_cast<module_config_t*>
939 (keyItem->data( 0, Qt::UserRole ).value<void*>());
941 KeyInputDialog *d = new KeyInputDialog( values, p_keyItem->psz_text );
943 if( d->result() == QDialog::Accepted )
945 p_keyItem->value.i = d->keyValue;
948 for( int i = 0; i < table->topLevelItemCount() ; i++ )
950 QTreeWidgetItem *it = table->topLevelItem(i);
951 module_config_t *p_item = static_cast<module_config_t*>
952 (it->data( 0, Qt::UserRole ).value<void*>());
953 it->setText( 1, VLCKeyToString( p_item->value.i ) );
957 keyItem->setText( 1, VLCKeyToString( p_keyItem->value.i ) );
962 void KeySelectorControl::doApply()
964 foreach( module_config_t *p_current, values )
966 config_PutInt( p_this, p_current->psz_name, p_current->value.i );
970 KeyInputDialog::KeyInputDialog( QList<module_config_t*>& _values,
971 const char * _keyToChange ) :
972 QDialog(0), keyValue(0)
977 keyToChange = _keyToChange;
978 setWindowTitle( qtr( "Hotkey for " ) + qfu( keyToChange) );
980 QVBoxLayout *l = new QVBoxLayout( this );
981 selected = new QLabel( qtr("Press the new keys for ") + qfu(keyToChange) );
982 warning = new QLabel();
983 l->addWidget( selected , Qt::AlignCenter );
984 l->addWidget( warning, Qt::AlignCenter );
986 QHBoxLayout *l2 = new QHBoxLayout();
987 QPushButton *ok = new QPushButton( qtr("OK") );
989 QPushButton *cancel = new QPushButton( qtr("Cancel") );
990 l2->addWidget( cancel );
992 BUTTONACT( ok, accept() );
993 BUTTONACT( cancel, reject() );
998 void KeyInputDialog::checkForConflicts( int i_vlckey )
1001 module_config_t *p_current = NULL;
1002 foreach( p_current, values )
1004 if( p_current->value.i == i_vlckey && strcmp( p_current->psz_text,
1007 p_current->value.i = 0;
1015 qtr("Warning: the key is already assigned to \"") +
1016 QString( p_current->psz_text ) + "\"" );
1018 else warning->setText( "" );
1021 void KeyInputDialog::keyPressEvent( QKeyEvent *e )
1023 if( e->key() == Qt::Key_Tab ) return;
1024 int i_vlck = qtEventToVLCKey( e );
1025 selected->setText( VLCKeyToString( i_vlck ) );
1026 checkForConflicts( i_vlck );
1030 void KeyInputDialog::wheelEvent( QWheelEvent *e )
1032 int i_vlck = qtWheelEventToVLCKey( e );
1033 selected->setText( VLCKeyToString( i_vlck ) );
1034 checkForConflicts( i_vlck );