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, there might be missing a
29 * i_action handler for IntegerLists, but I don't see any module using it...
30 * - Improvements over WX
31 * - Validator for modulelist
34 #include "components/preferences_widgets.hpp"
35 #include "util/customwidgets.hpp"
41 #include <QGridLayout>
43 #include <QFileDialog>
44 #include <QFontDialog>
46 #include <QTreeWidgetItem>
47 #include <QSignalMapper>
48 #include <QDialogButtonBox>
50 QString formatTooltip(const QString & tooltip)
53 "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">"
54 " p, li { white-space: pre-wrap; } </style></head><body style=\" font-family:'Sans Serif';"
55 " font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;\">"
56 "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; "
57 "-qt-block-indent:0; text-indent:0px;\">" +
63 ConfigControl *ConfigControl::createControl( vlc_object_t *p_this,
64 module_config_t *p_item,
68 return createControl( p_this, p_item, parent, NULL, i );
71 ConfigControl *ConfigControl::createControl( vlc_object_t *p_this,
72 module_config_t *p_item,
74 QGridLayout *l, int &line )
76 ConfigControl *p_control = NULL;
78 switch( p_item->i_type )
80 case CONFIG_ITEM_MODULE:
81 p_control = new ModuleConfigControl( p_this, p_item, parent, false,
84 case CONFIG_ITEM_MODULE_CAT:
85 p_control = new ModuleConfigControl( p_this, p_item, parent, true,
88 case CONFIG_ITEM_MODULE_LIST:
89 p_control = new ModuleListConfigControl( p_this, p_item, parent, false,
92 case CONFIG_ITEM_MODULE_LIST_CAT:
93 p_control = new ModuleListConfigControl( p_this, p_item, parent, true,
96 case CONFIG_ITEM_STRING:
98 p_control = new StringConfigControl( p_this, p_item, parent,
101 p_control = new StringListConfigControl( p_this, p_item,
102 parent, false, l, line );
104 case CONFIG_ITEM_PASSWORD:
105 if( !p_item->i_list )
106 p_control = new StringConfigControl( p_this, p_item, parent,
109 p_control = new StringListConfigControl( p_this, p_item,
110 parent, true, l, line );
112 case CONFIG_ITEM_INTEGER:
114 p_control = new IntegerListConfigControl( p_this, p_item,
115 parent, false, l, line );
116 else if( p_item->min.i || p_item->max.i )
117 p_control = new IntegerRangeConfigControl( p_this, p_item, parent,
120 p_control = new IntegerConfigControl( p_this, p_item, parent,
123 case CONFIG_ITEM_FILE:
124 p_control = new FileConfigControl( p_this, p_item, parent, l,
127 case CONFIG_ITEM_DIRECTORY:
128 p_control = new DirectoryConfigControl( p_this, p_item, parent, l,
131 case CONFIG_ITEM_FONT:
132 p_control = new FontConfigControl( p_this, p_item, parent, l,
135 case CONFIG_ITEM_KEY:
136 p_control = new KeySelectorControl( p_this, p_item, parent, l, line );
138 case CONFIG_ITEM_BOOL:
139 p_control = new BoolConfigControl( p_this, p_item, parent, l, line );
141 case CONFIG_ITEM_FLOAT:
142 if( p_item->min.f || p_item->max.f )
143 p_control = new FloatRangeConfigControl( p_this, p_item, parent,
146 p_control = new FloatConfigControl( p_this, p_item, parent,
155 void ConfigControl::doApply( intf_thread_t *p_intf )
159 case CONFIG_ITEM_INTEGER:
160 case CONFIG_ITEM_BOOL:
162 VIntConfigControl *vicc = qobject_cast<VIntConfigControl *>(this);
164 config_PutInt( p_intf, vicc->getName(), vicc->getValue() );
167 case CONFIG_ITEM_FLOAT:
169 VFloatConfigControl *vfcc =
170 qobject_cast<VFloatConfigControl *>(this);
172 config_PutFloat( p_intf, vfcc->getName(), vfcc->getValue() );
175 case CONFIG_ITEM_STRING:
177 VStringConfigControl *vscc =
178 qobject_cast<VStringConfigControl *>(this);
180 config_PutPsz( p_intf, vscc->getName(), qta( vscc->getValue() ) );
183 case CONFIG_ITEM_KEY:
185 KeySelectorControl *ksc = qobject_cast<KeySelectorControl *>(this);
192 /**************************************************************************
193 * String-based controls
194 *************************************************************************/
196 /*********** String **************/
197 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
198 module_config_t *_p_item,
199 QWidget *_parent, QGridLayout *l,
200 int &line, bool pwd ) :
201 VStringConfigControl( _p_this, _p_item, _parent )
203 label = new QLabel( qtr(p_item->psz_text) );
204 text = new QLineEdit( qfu(p_item->value.psz) );
205 if( pwd ) text->setEchoMode( QLineEdit::Password );
210 QHBoxLayout *layout = new QHBoxLayout();
211 layout->addWidget( label, 0 ); layout->addWidget( text, 1 );
212 widget->setLayout( layout );
216 l->addWidget( label, line, 0 ); l->addWidget( text, line, 1 );
220 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
221 module_config_t *_p_item,
222 QLabel *_label, QLineEdit *_text, bool pwd ):
223 VStringConfigControl( _p_this, _p_item )
230 void StringConfigControl::finish()
232 text->setText( qfu(p_item->value.psz) );
233 text->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
235 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
238 /*********** File **************/
239 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
240 module_config_t *_p_item,
241 QWidget *_parent, QGridLayout *l,
242 int &line, bool pwd ) :
243 VStringConfigControl( _p_this, _p_item, _parent )
245 label = new QLabel( qtr(p_item->psz_text) );
246 text = new QLineEdit( qfu(p_item->value.psz) );
247 browse = new QPushButton( qtr( "Browse..." ) );
248 QHBoxLayout *textAndButton = new QHBoxLayout();
249 textAndButton->setMargin( 0 );
250 textAndButton->addWidget( text, 2 );
251 textAndButton->addWidget( browse, 0 );
253 BUTTONACT( browse, updateField() );
259 QHBoxLayout *layout = new QHBoxLayout();
260 layout->addWidget( label, 0 );
261 layout->addLayout( textAndButton, 1 );
262 widget->setLayout( layout );
266 l->addWidget( label, line, 0 );
267 l->addLayout( textAndButton, line, 1 );
272 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
273 module_config_t *_p_item,
274 QLabel *_label, QLineEdit *_text,
275 QPushButton *_button, bool pwd ):
276 VStringConfigControl( _p_this, _p_item )
282 BUTTONACT( browse, updateField() );
287 void FileConfigControl::updateField()
289 QString file = QFileDialog::getOpenFileName( NULL,
290 qtr( "Select File" ), qfu( p_this->p_libvlc->psz_homedir ) );
291 if( file.isNull() ) return;
292 text->setText( file );
295 void FileConfigControl::finish()
297 text->setText( qfu(p_item->value.psz) );
298 text->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
300 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
303 /********* String / Directory **********/
304 DirectoryConfigControl::DirectoryConfigControl( 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 DirectoryConfigControl::DirectoryConfigControl( 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 DirectoryConfigControl::updateField()
318 QString dir = QFileDialog::getExistingDirectory( NULL,
319 qtr( "Select Directory" ),
320 text->text().isEmpty() ?
321 qfu( p_this->p_libvlc->psz_homedir ) : text->text(),
322 QFileDialog::ShowDirsOnly |
323 QFileDialog::DontResolveSymlinks );
324 if( dir.isNull() ) return;
325 text->setText( dir );
328 /********* String / Font **********/
329 FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
330 module_config_t *_p_item, QWidget *_p_widget,
331 QGridLayout *_p_layout, int& _int, bool _pwd ) :
332 FileConfigControl( _p_this, _p_item, _p_widget, _p_layout, _int, _pwd)
335 FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
336 module_config_t *_p_item, QLabel *_p_label,
337 QLineEdit *_p_line, QPushButton *_p_button, bool _pwd ):
338 FileConfigControl( _p_this, _p_item, _p_label, _p_line, _p_button, _pwd)
341 void FontConfigControl::updateField()
344 QFont font = QFontDialog::getFont( &ok, QFont( text->text() ), NULL );
346 text->setText( font.family() );
349 /********* String / choice list **********/
350 StringListConfigControl::StringListConfigControl( 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( qtr(p_item->psz_text) );
356 combo = new QComboBox();
357 combo->setMinimumWidth( 80 );
358 combo->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Preferred );
362 QHBoxLayout *layout = new QHBoxLayout();
363 layout->addWidget( label ); layout->addWidget( combo );
364 widget->setLayout( layout );
368 l->addWidget( label, line, 0 );
369 l->addWidget( combo, line, 1, Qt::AlignRight );
372 if( p_item->i_action )
374 QSignalMapper *signalMapper = new QSignalMapper(this);
376 /* Some stringLists like Capture listings have action associated */
377 for( int i = 0; i < p_item->i_action; i++ )
379 QPushButton *button =
380 new QPushButton( qfu( p_item->ppsz_action_text[i] ));
381 CONNECT( button, clicked(), signalMapper, map() );
382 signalMapper->setMapping( button, i );
383 l->addWidget( button, line, 2 + i, Qt::AlignRight );
385 CONNECT( signalMapper, mapped( int ),
386 this, actionRequested( int ) );
390 void StringListConfigControl::actionRequested( int i_action )
392 /* Supplementary check for boundaries */
393 if( i_action < 0 || i_action >= p_item->i_action ) return;
397 qtu( (combo->itemData( combo->currentIndex() ).toString() ) );
399 p_item->ppf_action[i_action]( p_this, getName(), val, val, 0 );
401 if( p_item->b_dirty )
405 p_item->b_dirty = VLC_FALSE;
408 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
409 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
410 bool bycat ) : VStringConfigControl( _p_this, _p_item )
417 void StringListConfigControl::finish( bool bycat )
419 combo->setEditable( false );
421 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
423 combo->addItem( qfu(p_item->ppsz_list_text ?
424 p_item->ppsz_list_text[i_index] :
425 p_item->ppsz_list[i_index] ),
426 QVariant( p_item->ppsz_list[i_index] ) );
427 if( p_item->value.psz && !strcmp( p_item->value.psz,
428 p_item->ppsz_list[i_index] ) )
429 combo->setCurrentIndex( combo->count() - 1 );
431 combo->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
433 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
436 QString StringListConfigControl::getValue()
438 return combo->itemData( combo->currentIndex() ).toString();
441 void setfillVLCConfigCombo( const char *configname, intf_thread_t *p_intf,
442 QComboBox *combo, QWidget *parent )
444 module_config_t *p_config =
445 config_FindConfig( VLC_OBJECT(p_intf), configname );
448 for ( int i_index = 0; i_index < p_config->i_list; i_index++ )
450 combo->addItem( qfu( p_config->ppsz_list_text[i_index] ),
451 QVariant( p_config->pi_list[i_index] ) );
452 if( p_config->value.i == p_config->pi_list[i_index] )
454 combo->setCurrentIndex( i_index );
457 combo->setToolTip( qfu( p_config->psz_longtext ) );
461 /********* Module **********/
462 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
463 module_config_t *_p_item, QWidget *_parent, bool bycat,
464 QGridLayout *l, int &line) :
465 VStringConfigControl( _p_this, _p_item, _parent )
467 label = new QLabel( qtr(p_item->psz_text) );
468 combo = new QComboBox();
469 combo->setMinimumWidth( 80 );
473 QHBoxLayout *layout = new QHBoxLayout();
474 layout->addWidget( label ); layout->addWidget( combo );
475 widget->setLayout( layout );
479 l->addWidget( label, line, 0 );
480 l->addWidget( combo, line, 1, Qt::AlignRight );
484 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
485 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
486 bool bycat ) : VStringConfigControl( _p_this, _p_item )
493 void ModuleConfigControl::finish( bool bycat )
498 combo->setEditable( false );
500 /* build a list of available modules */
501 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
502 combo->addItem( qtr("Default") );
503 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
505 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
509 if( !strcmp( module_GetObjName( p_parser ), "main" ) ) continue;
512 module_config_t *p_config;
514 p_config = module_GetConfig (p_parser, &confsize);
515 for (size_t i = 0; i < confsize; i++)
517 /* Hack: required subcategory is stored in i_min */
518 const module_config_t *p_cfg = p_config + i;
519 if( p_cfg->i_type == CONFIG_SUBCATEGORY &&
520 p_cfg->value.i == p_item->min.i )
521 combo->addItem( qtr( module_GetLongName( p_parser )),
522 QVariant( module_GetObjName( p_parser ) ) );
523 if( p_item->value.psz && !strcmp( p_item->value.psz,
524 module_GetObjName( p_parser ) ) )
525 combo->setCurrentIndex( combo->count() - 1 );
527 module_PutConfig (p_config);
529 else if( module_IsCapable( p_parser, p_item->psz_type ) )
531 combo->addItem( qtr(module_GetLongName( p_parser ) ),
532 QVariant( module_GetObjName( p_parser ) ) );
533 if( p_item->value.psz && !strcmp( p_item->value.psz,
534 module_GetObjName( p_parser ) ) )
535 combo->setCurrentIndex( combo->count() - 1 );
538 vlc_list_release( p_list );
539 combo->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
541 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
544 QString ModuleConfigControl::getValue()
546 return combo->itemData( combo->currentIndex() ).toString();
549 /********* Module list **********/
550 ModuleListConfigControl::ModuleListConfigControl( vlc_object_t *_p_this,
551 module_config_t *_p_item, QWidget *_parent, bool bycat,
552 QGridLayout *l, int &line) :
553 VStringConfigControl( _p_this, _p_item, _parent )
555 groupBox = new QGroupBox ( qtr(p_item->psz_text) );
556 text = new QLineEdit();
557 QGridLayout *layoutGroupBox = new QGridLayout( groupBox );
562 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
563 it != modules.end(); it++ )
565 layoutGroupBox->addWidget( (*it)->checkBox, boxline++, 0 );
567 layoutGroupBox->addWidget( text, boxline, 0 );
571 QVBoxLayout *layout = new QVBoxLayout();
572 layout->addWidget( groupBox, line, 0 );
573 widget->setLayout( layout );
577 l->addWidget( groupBox, line, 0, 1, -1 );
580 text->setToolTip( formatTooltip( qtr( p_item->psz_longtext) ) );
583 ModuleListConfigControl::~ModuleListConfigControl()
585 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
586 it != modules.end(); it++ )
594 #define CHECKBOX_LISTS \
596 QCheckBox *cb = new QCheckBox( qtr( module_GetLongName( p_parser ) ) );\
597 checkBoxListItem *cbl = new checkBoxListItem; \
599 CONNECT( cb, stateChanged( int ), this, onUpdate( int ) );\
600 cb->setToolTip( formatTooltip( qtr( module_GetLongName( p_parser ))));\
601 cbl->checkBox = cb; \
603 cbl->psz_module = strdup( module_GetObjName( p_parser ) ); \
604 modules.push_back( cbl ); \
608 void ModuleListConfigControl::finish( bool bycat )
613 /* build a list of available modules */
614 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
615 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
617 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
621 if( !strcmp( module_GetObjName( p_parser ), "main" ) ) continue;
624 module_config_t *p_config = module_GetConfig (p_parser, &confsize);
626 for (size_t i = 0; i < confsize; i++)
628 module_config_t *p_cfg = p_config + i;
629 /* Hack: required subcategory is stored in i_min */
630 if( p_cfg->i_type == CONFIG_SUBCATEGORY &&
631 p_cfg->value.i == p_item->min.i )
636 module_PutConfig (p_config);
638 else if( module_IsCapable( p_parser, p_item->psz_type ) )
643 vlc_list_release( p_list );
644 text->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
646 groupBox->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
648 #undef CHECKBOX_LISTS
650 QString ModuleListConfigControl::getValue()
655 void ModuleListConfigControl::hide()
657 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
658 it != modules.end(); it++ )
660 (*it)->checkBox->hide();
665 void ModuleListConfigControl::show()
667 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
668 it != modules.end(); it++ )
670 (*it)->checkBox->show();
676 void ModuleListConfigControl::onUpdate( int value )
681 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
682 it != modules.end(); it++ )
684 if( (*it)->checkBox->isChecked() )
688 text->setText( text->text() + (*it)->psz_module );
693 text->setText( text->text() + ":" + (*it)->psz_module );
699 /**************************************************************************
700 * Integer-based controls
701 *************************************************************************/
703 /*********** Integer **************/
704 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
705 module_config_t *_p_item,
706 QWidget *_parent, QGridLayout *l,
708 VIntConfigControl( _p_this, _p_item, _parent )
710 label = new QLabel( qtr(p_item->psz_text) );
711 spin = new QSpinBox; spin->setMinimumWidth( 80 );
712 spin->setAlignment( Qt::AlignRight );
713 spin->setMaximumWidth( 90 );
718 QHBoxLayout *layout = new QHBoxLayout();
719 layout->addWidget( label, 0 ); layout->addWidget( spin, 1 );
720 widget->setLayout( layout );
724 l->addWidget( label, line, 0 );
725 l->addWidget( spin, line, 1, Qt::AlignRight );
728 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
729 module_config_t *_p_item,
730 QLabel *_label, QSpinBox *_spin ) :
731 VIntConfigControl( _p_this, _p_item )
738 void IntegerConfigControl::finish()
740 spin->setMaximum( 2000000000 );
741 spin->setMinimum( -2000000000 );
742 spin->setValue( p_item->value.i );
743 spin->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
745 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
748 int IntegerConfigControl::getValue()
750 return spin->value();
753 /********* Integer range **********/
754 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
755 module_config_t *_p_item,
756 QWidget *_parent, QGridLayout *l,
758 IntegerConfigControl( _p_this, _p_item, _parent, l, line )
763 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
764 module_config_t *_p_item,
765 QLabel *_label, QSpinBox *_spin ) :
766 IntegerConfigControl( _p_this, _p_item, _label, _spin )
771 void IntegerRangeConfigControl::finish()
773 spin->setMaximum( p_item->max.i );
774 spin->setMinimum( p_item->min.i );
777 IntegerRangeSliderConfigControl::IntegerRangeSliderConfigControl(
778 vlc_object_t *_p_this,
779 module_config_t *_p_item,
780 QLabel *_label, QSlider *_slider ):
781 VIntConfigControl( _p_this, _p_item )
785 slider->setMaximum( p_item->max.i );
786 slider->setMinimum( p_item->min.i );
787 slider->setValue( p_item->value.i );
788 slider->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
790 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
793 int IntegerRangeSliderConfigControl::getValue()
795 return slider->value();
799 /********* Integer / choice list **********/
800 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
801 module_config_t *_p_item, QWidget *_parent, bool bycat,
802 QGridLayout *l, int &line) :
803 VIntConfigControl( _p_this, _p_item, _parent )
805 label = new QLabel( qtr(p_item->psz_text) );
806 combo = new QComboBox();
807 combo->setMinimumWidth( 80 );
811 QHBoxLayout *layout = new QHBoxLayout();
812 layout->addWidget( label ); layout->addWidget( combo );
813 widget->setLayout( layout );
817 l->addWidget( label, line, 0 );
818 l->addWidget( combo, line, 1, Qt::AlignRight );
821 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
822 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
823 bool bycat ) : VIntConfigControl( _p_this, _p_item )
830 void IntegerListConfigControl::finish( bool bycat )
832 combo->setEditable( false );
834 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
836 combo->addItem( qtr(p_item->ppsz_list_text[i_index] ),
837 QVariant( p_item->pi_list[i_index] ) );
838 if( p_item->value.i == p_item->pi_list[i_index] )
839 combo->setCurrentIndex( combo->count() - 1 );
841 combo->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
843 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
846 int IntegerListConfigControl::getValue()
848 return combo->itemData( combo->currentIndex() ).toInt();
851 /*********** Boolean **************/
852 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
853 module_config_t *_p_item,
854 QWidget *_parent, QGridLayout *l,
856 VIntConfigControl( _p_this, _p_item, _parent )
858 checkbox = new QCheckBox( qtr(p_item->psz_text) );
863 QHBoxLayout *layout = new QHBoxLayout();
864 layout->addWidget( checkbox, 0 );
865 widget->setLayout( layout );
869 l->addWidget( checkbox, line, 0 );
872 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
873 module_config_t *_p_item,
875 QCheckBox *_checkbox,
877 VIntConfigControl( _p_this, _p_item )
879 checkbox = _checkbox;
883 void BoolConfigControl::finish()
885 checkbox->setCheckState( p_item->value.i == VLC_TRUE ? Qt::Checked
887 checkbox->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
890 int BoolConfigControl::getValue()
892 return checkbox->checkState() == Qt::Checked ? VLC_TRUE : VLC_FALSE;
895 /**************************************************************************
896 * Float-based controls
897 *************************************************************************/
899 /*********** Float **************/
900 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
901 module_config_t *_p_item,
902 QWidget *_parent, QGridLayout *l,
904 VFloatConfigControl( _p_this, _p_item, _parent )
906 label = new QLabel( qtr(p_item->psz_text) );
907 spin = new QDoubleSpinBox;
908 spin->setMinimumWidth( 80 );
909 spin->setMaximumWidth( 90 );
910 spin->setAlignment( Qt::AlignRight );
915 QHBoxLayout *layout = new QHBoxLayout();
916 layout->addWidget( label, 0 ); layout->addWidget( spin, 1 );
917 widget->setLayout( layout );
921 l->addWidget( label, line, 0 );
922 l->addWidget( spin, line, 1, Qt::AlignRight );
926 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
927 module_config_t *_p_item,
929 QDoubleSpinBox *_spin ) :
930 VFloatConfigControl( _p_this, _p_item )
937 void FloatConfigControl::finish()
939 spin->setMaximum( 2000000000. );
940 spin->setMinimum( -2000000000. );
941 spin->setSingleStep( 0.1 );
942 spin->setValue( (double)p_item->value.f );
943 spin->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
945 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
948 float FloatConfigControl::getValue()
950 return (float)spin->value();
953 /*********** Float with range **************/
954 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
955 module_config_t *_p_item,
956 QWidget *_parent, QGridLayout *l,
958 FloatConfigControl( _p_this, _p_item, _parent, l, line )
963 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
964 module_config_t *_p_item,
966 QDoubleSpinBox *_spin ) :
967 FloatConfigControl( _p_this, _p_item, _label, _spin )
972 void FloatRangeConfigControl::finish()
974 spin->setMaximum( (double)p_item->max.f );
975 spin->setMinimum( (double)p_item->min.f );
979 /**********************************************************************
980 * Key selector widget
981 **********************************************************************/
982 KeySelectorControl::KeySelectorControl( vlc_object_t *_p_this,
983 module_config_t *_p_item,
984 QWidget *_parent, QGridLayout *l,
986 ConfigControl( _p_this, _p_item, _parent )
989 QWidget *keyContainer = new QWidget;
990 QGridLayout *gLayout = new QGridLayout( keyContainer );
993 qtr( "Select an action to change the associated hotkey") );
995 /* Deactivated for now
996 QLabel *searchLabel = new QLabel( qtr( "Search" ) );
997 QLineEdit *actionSearch = new QLineEdit;*/
999 table = new QTreeWidget;
1000 table->setColumnCount(2);
1001 table->headerItem()->setText( 0, qtr( "Action" ) );
1002 table->headerItem()->setText( 1, qtr( "Shortcut" ) );
1004 shortcutValue = new KeyShortcutEdit;
1005 shortcutValue->setReadOnly(true);
1007 QPushButton *clearButton = new QPushButton( qtr( "Clear" ) );
1008 QPushButton *setButton = new QPushButton( qtr( "Set" ) );
1011 gLayout->addWidget( label, 0, 0, 1, 4 );
1012 /* deactivated for now
1013 gLayout->addWidget( searchLabel, 1, 0, 1, 2 );
1014 gLayout->addWidget( actionSearch, 1, 2, 1, 2 ); */
1015 gLayout->addWidget( table, 2, 0, 1, 4 );
1016 gLayout->addWidget( clearButton, 3, 0, 1, 1 );
1017 gLayout->addWidget( shortcutValue, 3, 1, 1, 2 );
1018 gLayout->addWidget( setButton, 3, 3, 1, 1 );
1020 l->addWidget( keyContainer, line, 0, 1, 2 );
1022 CONNECT( clearButton, clicked(), shortcutValue, clear() );
1023 BUTTONACT( setButton, setTheKey() );
1026 void KeySelectorControl::finish()
1029 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
1031 /* Fill the table */
1032 table->setColumnCount( 2 );
1033 table->setAlternatingRowColors( true );
1035 module_t *p_main = module_Find( p_this, "main" );
1039 module_config_t *p_config;
1041 p_config = module_GetConfig (p_main, &confsize);
1043 for (size_t i = 0; i < confsize; i++)
1045 module_config_t *p_item = p_config + i;
1047 if( p_item->i_type & CONFIG_ITEM && p_item->psz_name &&
1048 strstr( p_item->psz_name , "key-" ) && !EMPTY_STR( p_item->psz_text ) )
1050 QTreeWidgetItem *treeItem = new QTreeWidgetItem();
1051 treeItem->setText( 0, qtr( p_item->psz_text ) );
1052 treeItem->setText( 1, VLCKeyToString( p_item->value.i ) );
1053 treeItem->setData( 0, Qt::UserRole,
1054 QVariant::fromValue( (void*)p_item ) );
1056 table->addTopLevelItem( treeItem );
1059 module_PutConfig (p_config);
1060 module_Put (p_main);
1062 table->resizeColumnToContents( 0 );
1064 CONNECT( table, itemClicked( QTreeWidgetItem *, int ),
1065 this, select1Key( QTreeWidgetItem * ) );
1066 CONNECT( table, itemDoubleClicked( QTreeWidgetItem *, int ),
1067 this, selectKey( QTreeWidgetItem * ) );
1068 CONNECT( shortcutValue, pressed(), this, selectKey() );
1071 void KeySelectorControl::select1Key( QTreeWidgetItem *keyItem )
1073 shortcutValue->setText( keyItem->text( 1 ) );
1076 void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem )
1078 /* This happens when triggered by ClickEater */
1079 if( keyItem == NULL ) keyItem = table->currentItem();
1081 /* This can happen when nothing is selected on the treeView
1082 and the shortcutValue is clicked */
1083 if( !keyItem ) return;
1085 module_config_t *p_keyItem = static_cast<module_config_t*>
1086 (keyItem->data( 0, Qt::UserRole ).value<void*>());
1088 KeyInputDialog *d = new KeyInputDialog( values, p_keyItem->psz_text, widget );
1090 if( d->result() == QDialog::Accepted )
1092 p_keyItem->value.i = d->keyValue;
1095 for( int i = 0; i < table->topLevelItemCount() ; i++ )
1097 QTreeWidgetItem *it = table->topLevelItem(i);
1098 module_config_t *p_item = static_cast<module_config_t*>
1099 (it->data( 0, Qt::UserRole ).value<void*>());
1100 if( p_keyItem != p_item && p_item->value.i == d->keyValue )
1101 p_item->value.i = 0;
1102 shortcutValue->setText( VLCKeyToString( p_item->value.i ) );
1106 shortcutValue->setText( VLCKeyToString( p_keyItem->value.i ) );
1111 void KeySelectorControl::setTheKey()
1113 table->currentItem()->setText( 1, shortcutValue->text() );
1116 void KeySelectorControl::doApply()
1118 foreach( module_config_t *p_current, values )
1120 config_PutInt( p_this, p_current->psz_name, p_current->value.i );
1124 KeyInputDialog::KeyInputDialog( QList<module_config_t*>& _values,
1125 const char * _keyToChange,
1126 QWidget *_parent ) :
1127 QDialog( _parent ), keyValue(0)
1132 keyToChange = _keyToChange;
1134 setWindowTitle( qtr( "Hotkey for " ) + qfu( keyToChange) );
1136 vLayout = new QVBoxLayout( this );
1137 selected = new QLabel( qtr("Press the new keys for ") + qfu( keyToChange ) );
1138 vLayout->addWidget( selected , Qt::AlignCenter );
1140 buttonBox = new QDialogButtonBox;
1141 QPushButton *ok = new QPushButton( qtr("OK") );
1142 QPushButton *cancel = new QPushButton( qtr("Cancel") );
1143 buttonBox->addButton( ok, QDialogButtonBox::AcceptRole );
1144 buttonBox->addButton( cancel, QDialogButtonBox::RejectRole );
1146 vLayout->addWidget( buttonBox );
1149 CONNECT( buttonBox, accepted(), this, accept() );
1150 CONNECT( buttonBox, rejected(), this, reject() );
1153 void KeyInputDialog::checkForConflicts( int i_vlckey )
1156 module_config_t *p_current = NULL;
1157 /* Search for conflicts */
1158 foreach( p_current, values )
1160 if( p_current->value.i == i_vlckey && strcmp( p_current->psz_text,
1170 QLabel *warning = new QLabel(
1171 qtr("Warning: the key is already assigned to \"") +
1172 qfu( p_current->psz_text ) + "\"" );
1173 warning->setWordWrap( true );
1174 vLayout->insertWidget( 1, warning );
1180 void KeyInputDialog::keyPressEvent( QKeyEvent *e )
1182 if( e->key() == Qt::Key_Tab ) return;
1183 int i_vlck = qtEventToVLCKey( e );
1184 selected->setText( VLCKeyToString( i_vlck ) );
1185 checkForConflicts( i_vlck );
1189 void KeyInputDialog::wheelEvent( QWheelEvent *e )
1191 int i_vlck = qtWheelEventToVLCKey( e );
1192 selected->setText( VLCKeyToString( i_vlck ) );
1193 checkForConflicts( i_vlck );
1197 void KeyShortcutEdit::mousePressEvent( QMouseEvent *)