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 )
161 VIntConfigControl *vicc = qobject_cast<VIntConfigControl *>(this);
163 config_PutInt( p_intf, vicc->getName(), vicc->getValue() );
168 VFloatConfigControl *vfcc =
169 qobject_cast<VFloatConfigControl *>(this);
171 config_PutFloat( p_intf, vfcc->getName(), vfcc->getValue() );
176 VStringConfigControl *vscc =
177 qobject_cast<VStringConfigControl *>(this);
179 config_PutPsz( p_intf, vscc->getName(), qta( vscc->getValue() ) );
184 KeySelectorControl *ksc = qobject_cast<KeySelectorControl *>(this);
191 /**************************************************************************
192 * String-based controls
193 *************************************************************************/
195 /*********** String **************/
196 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
197 module_config_t *_p_item,
198 QWidget *_parent, QGridLayout *l,
199 int &line, bool pwd ) :
200 VStringConfigControl( _p_this, _p_item, _parent )
202 label = new QLabel( qtr(p_item->psz_text) );
203 text = new QLineEdit( qfu(p_item->value.psz) );
204 if( pwd ) text->setEchoMode( QLineEdit::Password );
209 QHBoxLayout *layout = new QHBoxLayout();
210 layout->addWidget( label, 0 ); layout->addWidget( text, 1 );
211 widget->setLayout( layout );
215 l->addWidget( label, line, 0 ); l->addWidget( text, line, 1 );
219 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
220 module_config_t *_p_item,
221 QLabel *_label, QLineEdit *_text, bool pwd ):
222 VStringConfigControl( _p_this, _p_item )
229 void StringConfigControl::finish()
231 text->setText( qfu(p_item->value.psz) );
232 text->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
234 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
237 /*********** File **************/
238 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
239 module_config_t *_p_item,
240 QWidget *_parent, QGridLayout *l,
241 int &line, bool pwd ) :
242 VStringConfigControl( _p_this, _p_item, _parent )
244 label = new QLabel( qtr(p_item->psz_text) );
245 text = new QLineEdit( qfu(p_item->value.psz) );
246 browse = new QPushButton( qtr( "Browse..." ) );
247 QHBoxLayout *textAndButton = new QHBoxLayout();
248 textAndButton->setMargin( 0 );
249 textAndButton->addWidget( text, 2 );
250 textAndButton->addWidget( browse, 0 );
252 BUTTONACT( browse, updateField() );
258 QHBoxLayout *layout = new QHBoxLayout();
259 layout->addWidget( label, 0 );
260 layout->addLayout( textAndButton, 1 );
261 widget->setLayout( layout );
265 l->addWidget( label, line, 0 );
266 l->addLayout( textAndButton, line, 1 );
271 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
272 module_config_t *_p_item,
273 QLabel *_label, QLineEdit *_text,
274 QPushButton *_button, bool pwd ):
275 VStringConfigControl( _p_this, _p_item )
281 BUTTONACT( browse, updateField() );
286 void FileConfigControl::updateField()
288 QString file = QFileDialog::getOpenFileName( NULL,
289 qtr( "Select File" ), qfu( p_this->p_libvlc->psz_homedir ) );
290 if( file.isNull() ) return;
291 text->setText( file );
294 void FileConfigControl::finish()
296 text->setText( qfu(p_item->value.psz) );
297 text->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
299 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
302 /********* String / Directory **********/
303 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
304 module_config_t *_p_item, QWidget *_p_widget,
305 QGridLayout *_p_layout, int& _int, bool _pwd ) :
306 FileConfigControl( _p_this, _p_item, _p_widget, _p_layout, _int, _pwd)
309 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
310 module_config_t *_p_item, QLabel *_p_label,
311 QLineEdit *_p_line, QPushButton *_p_button, bool _pwd ):
312 FileConfigControl( _p_this, _p_item, _p_label, _p_line, _p_button, _pwd)
315 void DirectoryConfigControl::updateField()
317 QString dir = QFileDialog::getExistingDirectory( NULL,
318 qtr( "Select Directory" ),
319 text->text().isEmpty() ?
320 qfu( p_this->p_libvlc->psz_homedir ) : text->text(),
321 QFileDialog::ShowDirsOnly |
322 QFileDialog::DontResolveSymlinks );
323 if( dir.isNull() ) return;
324 text->setText( dir );
327 /********* String / Font **********/
328 FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
329 module_config_t *_p_item, QWidget *_p_widget,
330 QGridLayout *_p_layout, int& _int, bool _pwd ) :
331 FileConfigControl( _p_this, _p_item, _p_widget, _p_layout, _int, _pwd)
334 FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
335 module_config_t *_p_item, QLabel *_p_label,
336 QLineEdit *_p_line, QPushButton *_p_button, bool _pwd ):
337 FileConfigControl( _p_this, _p_item, _p_label, _p_line, _p_button, _pwd)
340 void FontConfigControl::updateField()
343 QFont font = QFontDialog::getFont( &ok, QFont( text->text() ), NULL );
345 text->setText( font.family() );
348 /********* String / choice list **********/
349 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
350 module_config_t *_p_item, QWidget *_parent, bool bycat,
351 QGridLayout *l, int &line) :
352 VStringConfigControl( _p_this, _p_item, _parent )
354 label = new QLabel( qtr(p_item->psz_text) );
355 combo = new QComboBox();
356 combo->setMinimumWidth( 80 );
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 if( p_item->i_action )
372 QSignalMapper *signalMapper = new QSignalMapper(this);
374 /* Some stringLists like Capture listings have action associated */
375 for( int i = 0; i < p_item->i_action; i++ )
377 QPushButton *button =
378 new QPushButton( qfu( p_item->ppsz_action_text[i] ));
379 CONNECT( button, clicked(), signalMapper, map() );
380 signalMapper->setMapping( button, i );
381 l->addWidget( button, line, 2 + i, Qt::AlignRight );
383 CONNECT( signalMapper, mapped( int ),
384 this, actionRequested( int ) );
388 void StringListConfigControl::actionRequested( int i_action )
390 /* Supplementary check for boundaries */
391 if( i_action < 0 || i_action >= p_item->i_action ) return;
395 qtu( (combo->itemData( combo->currentIndex() ).toString() ) );
397 p_item->ppf_action[i_action]( p_this, getName(), val, val, 0 );
399 if( p_item->b_dirty )
403 p_item->b_dirty = VLC_FALSE;
406 StringListConfigControl::StringListConfigControl( 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 StringListConfigControl::finish( bool bycat )
417 combo->setEditable( false );
419 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
421 combo->addItem( qfu(p_item->ppsz_list_text ?
422 p_item->ppsz_list_text[i_index] :
423 p_item->ppsz_list[i_index] ),
424 QVariant( p_item->ppsz_list[i_index] ) );
425 if( p_item->value.psz && !strcmp( p_item->value.psz,
426 p_item->ppsz_list[i_index] ) )
427 combo->setCurrentIndex( combo->count() - 1 );
429 combo->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
431 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
434 QString StringListConfigControl::getValue()
436 return combo->itemData( combo->currentIndex() ).toString();
439 void setfillVLCConfigCombo( const char *configname, intf_thread_t *p_intf,
440 QComboBox *combo, QWidget *parent )
442 module_config_t *p_config =
443 config_FindConfig( VLC_OBJECT(p_intf), configname );
446 for ( int i_index = 0; i_index < p_config->i_list; i_index++ )
448 combo->addItem( qfu( p_config->ppsz_list_text[i_index] ),
449 QVariant( p_config->pi_list[i_index] ) );
450 if( p_config->value.i == p_config->pi_list[i_index] )
452 combo->setCurrentIndex( i_index );
455 combo->setToolTip( qfu( p_config->psz_longtext ) );
459 /********* Module **********/
460 ModuleConfigControl::ModuleConfigControl( 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( qtr(p_item->psz_text) );
466 combo = new QComboBox();
467 combo->setMinimumWidth( 80 );
471 QHBoxLayout *layout = new QHBoxLayout();
472 layout->addWidget( label ); layout->addWidget( combo );
473 widget->setLayout( layout );
477 l->addWidget( label, line, 0 );
478 l->addWidget( combo, line, 1, Qt::AlignRight );
482 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
483 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
484 bool bycat ) : VStringConfigControl( _p_this, _p_item )
491 void ModuleConfigControl::finish( bool bycat )
496 combo->setEditable( false );
498 /* build a list of available modules */
499 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
500 combo->addItem( qtr("Default") );
501 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
503 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
507 if( !strcmp( module_GetObjName( p_parser ), "main" ) ) continue;
510 module_config_t *p_config;
512 p_config = module_GetConfig (p_parser, &confsize);
513 for (size_t i = 0; i < confsize; i++)
515 /* Hack: required subcategory is stored in i_min */
516 const module_config_t *p_cfg = p_config + i;
517 if( p_cfg->i_type == CONFIG_SUBCATEGORY &&
518 p_cfg->value.i == p_item->min.i )
519 combo->addItem( qtr( module_GetLongName( p_parser )),
520 QVariant( module_GetObjName( p_parser ) ) );
521 if( p_item->value.psz && !strcmp( p_item->value.psz,
522 module_GetObjName( p_parser ) ) )
523 combo->setCurrentIndex( combo->count() - 1 );
525 module_PutConfig (p_config);
527 else if( module_IsCapable( p_parser, p_item->psz_type ) )
529 combo->addItem( qtr(module_GetLongName( p_parser ) ),
530 QVariant( module_GetObjName( p_parser ) ) );
531 if( p_item->value.psz && !strcmp( p_item->value.psz,
532 module_GetObjName( p_parser ) ) )
533 combo->setCurrentIndex( combo->count() - 1 );
536 vlc_list_release( p_list );
537 combo->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
539 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
542 QString ModuleConfigControl::getValue()
544 return combo->itemData( combo->currentIndex() ).toString();
547 /********* Module list **********/
548 ModuleListConfigControl::ModuleListConfigControl( vlc_object_t *_p_this,
549 module_config_t *_p_item, QWidget *_parent, bool bycat,
550 QGridLayout *l, int &line) :
551 VStringConfigControl( _p_this, _p_item, _parent )
553 groupBox = new QGroupBox ( qtr(p_item->psz_text) );
554 text = new QLineEdit();
555 QGridLayout *layoutGroupBox = new QGridLayout( groupBox );
560 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
561 it != modules.end(); it++ )
563 layoutGroupBox->addWidget( (*it)->checkBox, boxline++, 0 );
565 layoutGroupBox->addWidget( text, boxline, 0 );
569 QVBoxLayout *layout = new QVBoxLayout();
570 layout->addWidget( groupBox, line, 0 );
571 widget->setLayout( layout );
575 l->addWidget( groupBox, line, 0, 1, -1 );
578 text->setToolTip( formatTooltip( qtr( p_item->psz_longtext) ) );
581 ModuleListConfigControl::~ModuleListConfigControl()
583 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
584 it != modules.end(); it++ )
592 #define CHECKBOX_LISTS \
594 QCheckBox *cb = new QCheckBox( qtr( module_GetLongName( p_parser ) ) );\
595 checkBoxListItem *cbl = new checkBoxListItem; \
597 CONNECT( cb, stateChanged( int ), this, onUpdate( int ) );\
598 cb->setToolTip( formatTooltip( qtr( module_GetLongName( p_parser ))));\
599 cbl->checkBox = cb; \
601 cbl->psz_module = strdup( module_GetObjName( p_parser ) ); \
602 modules.push_back( cbl ); \
606 void ModuleListConfigControl::finish( bool bycat )
611 /* build a list of available modules */
612 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
613 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
615 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
619 if( !strcmp( module_GetObjName( p_parser ), "main" ) ) continue;
622 module_config_t *p_config = module_GetConfig (p_parser, &confsize);
624 for (size_t i = 0; i < confsize; i++)
626 module_config_t *p_cfg = p_config + i;
627 /* Hack: required subcategory is stored in i_min */
628 if( p_cfg->i_type == CONFIG_SUBCATEGORY &&
629 p_cfg->value.i == p_item->min.i )
634 module_PutConfig (p_config);
636 else if( module_IsCapable( p_parser, p_item->psz_type ) )
641 vlc_list_release( p_list );
642 text->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
644 groupBox->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
646 #undef CHECKBOX_LISTS
648 QString ModuleListConfigControl::getValue()
653 void ModuleListConfigControl::hide()
655 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
656 it != modules.end(); it++ )
658 (*it)->checkBox->hide();
663 void ModuleListConfigControl::show()
665 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
666 it != modules.end(); it++ )
668 (*it)->checkBox->show();
674 void ModuleListConfigControl::onUpdate( int value )
679 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
680 it != modules.end(); it++ )
682 if( (*it)->checkBox->isChecked() )
686 text->setText( text->text() + (*it)->psz_module );
691 text->setText( text->text() + ":" + (*it)->psz_module );
697 /**************************************************************************
698 * Integer-based controls
699 *************************************************************************/
701 /*********** Integer **************/
702 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
703 module_config_t *_p_item,
704 QWidget *_parent, QGridLayout *l,
706 VIntConfigControl( _p_this, _p_item, _parent )
708 label = new QLabel( qtr(p_item->psz_text) );
709 spin = new QSpinBox; spin->setMinimumWidth( 80 );
710 spin->setAlignment( Qt::AlignRight );
711 spin->setMaximumWidth( 90 );
716 QHBoxLayout *layout = new QHBoxLayout();
717 layout->addWidget( label, 0 ); layout->addWidget( spin, 1 );
718 widget->setLayout( layout );
722 l->addWidget( label, line, 0 );
723 l->addWidget( spin, line, 1, Qt::AlignRight );
726 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
727 module_config_t *_p_item,
728 QLabel *_label, QSpinBox *_spin ) :
729 VIntConfigControl( _p_this, _p_item )
736 void IntegerConfigControl::finish()
738 spin->setMaximum( 2000000000 );
739 spin->setMinimum( -2000000000 );
740 spin->setValue( p_item->value.i );
741 spin->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
743 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
746 int IntegerConfigControl::getValue()
748 return spin->value();
751 /********* Integer range **********/
752 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
753 module_config_t *_p_item,
754 QWidget *_parent, QGridLayout *l,
756 IntegerConfigControl( _p_this, _p_item, _parent, l, line )
761 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
762 module_config_t *_p_item,
763 QLabel *_label, QSpinBox *_spin ) :
764 IntegerConfigControl( _p_this, _p_item, _label, _spin )
769 void IntegerRangeConfigControl::finish()
771 spin->setMaximum( p_item->max.i );
772 spin->setMinimum( p_item->min.i );
775 IntegerRangeSliderConfigControl::IntegerRangeSliderConfigControl(
776 vlc_object_t *_p_this,
777 module_config_t *_p_item,
778 QLabel *_label, QSlider *_slider ):
779 VIntConfigControl( _p_this, _p_item )
783 slider->setMaximum( p_item->max.i );
784 slider->setMinimum( p_item->min.i );
785 slider->setValue( p_item->value.i );
786 slider->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
788 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
791 int IntegerRangeSliderConfigControl::getValue()
793 return slider->value();
797 /********* Integer / choice list **********/
798 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
799 module_config_t *_p_item, QWidget *_parent, bool bycat,
800 QGridLayout *l, int &line) :
801 VIntConfigControl( _p_this, _p_item, _parent )
803 label = new QLabel( qtr(p_item->psz_text) );
804 combo = new QComboBox();
805 combo->setMinimumWidth( 80 );
809 QHBoxLayout *layout = new QHBoxLayout();
810 layout->addWidget( label ); layout->addWidget( combo );
811 widget->setLayout( layout );
815 l->addWidget( label, line, 0 );
816 l->addWidget( combo, line, 1, Qt::AlignRight );
819 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
820 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
821 bool bycat ) : VIntConfigControl( _p_this, _p_item )
828 void IntegerListConfigControl::finish( bool bycat )
830 combo->setEditable( false );
832 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
834 combo->addItem( qtr(p_item->ppsz_list_text[i_index] ),
835 QVariant( p_item->pi_list[i_index] ) );
836 if( p_item->value.i == p_item->pi_list[i_index] )
837 combo->setCurrentIndex( combo->count() - 1 );
839 combo->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
841 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
844 int IntegerListConfigControl::getValue()
846 return combo->itemData( combo->currentIndex() ).toInt();
849 /*********** Boolean **************/
850 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
851 module_config_t *_p_item,
852 QWidget *_parent, QGridLayout *l,
854 VIntConfigControl( _p_this, _p_item, _parent )
856 checkbox = new QCheckBox( qtr(p_item->psz_text) );
861 QHBoxLayout *layout = new QHBoxLayout();
862 layout->addWidget( checkbox, 0 );
863 widget->setLayout( layout );
867 l->addWidget( checkbox, line, 0 );
870 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
871 module_config_t *_p_item,
873 QCheckBox *_checkbox,
875 VIntConfigControl( _p_this, _p_item )
877 checkbox = _checkbox;
881 void BoolConfigControl::finish()
883 checkbox->setCheckState( p_item->value.i == VLC_TRUE ? Qt::Checked
885 checkbox->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
888 int BoolConfigControl::getValue()
890 return checkbox->checkState() == Qt::Checked ? VLC_TRUE : VLC_FALSE;
893 /**************************************************************************
894 * Float-based controls
895 *************************************************************************/
897 /*********** Float **************/
898 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
899 module_config_t *_p_item,
900 QWidget *_parent, QGridLayout *l,
902 VFloatConfigControl( _p_this, _p_item, _parent )
904 label = new QLabel( qtr(p_item->psz_text) );
905 spin = new QDoubleSpinBox;
906 spin->setMinimumWidth( 80 );
907 spin->setMaximumWidth( 90 );
908 spin->setAlignment( Qt::AlignRight );
913 QHBoxLayout *layout = new QHBoxLayout();
914 layout->addWidget( label, 0 ); layout->addWidget( spin, 1 );
915 widget->setLayout( layout );
919 l->addWidget( label, line, 0 );
920 l->addWidget( spin, line, 1, Qt::AlignRight );
924 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
925 module_config_t *_p_item,
927 QDoubleSpinBox *_spin ) :
928 VFloatConfigControl( _p_this, _p_item )
935 void FloatConfigControl::finish()
937 spin->setMaximum( 2000000000. );
938 spin->setMinimum( -2000000000. );
939 spin->setSingleStep( 0.1 );
940 spin->setValue( (double)p_item->value.f );
941 spin->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
943 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
946 float FloatConfigControl::getValue()
948 return (float)spin->value();
951 /*********** Float with range **************/
952 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
953 module_config_t *_p_item,
954 QWidget *_parent, QGridLayout *l,
956 FloatConfigControl( _p_this, _p_item, _parent, l, line )
961 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
962 module_config_t *_p_item,
964 QDoubleSpinBox *_spin ) :
965 FloatConfigControl( _p_this, _p_item, _label, _spin )
970 void FloatRangeConfigControl::finish()
972 spin->setMaximum( (double)p_item->max.f );
973 spin->setMinimum( (double)p_item->min.f );
977 /**********************************************************************
978 * Key selector widget
979 **********************************************************************/
980 KeySelectorControl::KeySelectorControl( vlc_object_t *_p_this,
981 module_config_t *_p_item,
982 QWidget *_parent, QGridLayout *l,
984 ConfigControl( _p_this, _p_item, _parent )
987 QWidget *keyContainer = new QWidget;
988 QGridLayout *gLayout = new QGridLayout( keyContainer );
991 qtr( "Select an action to change the associated hotkey") );
993 /* Deactivated for now
994 QLabel *searchLabel = new QLabel( qtr( "Search" ) );
995 QLineEdit *actionSearch = new QLineEdit;*/
997 table = new QTreeWidget;
998 table->setColumnCount(2);
999 table->headerItem()->setText( 0, qtr( "Action" ) );
1000 table->headerItem()->setText( 1, qtr( "Shortcut" ) );
1002 shortcutValue = new KeyShortcutEdit;
1003 shortcutValue->setReadOnly(true);
1005 QPushButton *clearButton = new QPushButton( qtr( "Clear" ) );
1006 QPushButton *setButton = new QPushButton( qtr( "Set" ) );
1009 gLayout->addWidget( label, 0, 0, 1, 4 );
1010 /* deactivated for now
1011 gLayout->addWidget( searchLabel, 1, 0, 1, 2 );
1012 gLayout->addWidget( actionSearch, 1, 2, 1, 2 ); */
1013 gLayout->addWidget( table, 2, 0, 1, 4 );
1014 gLayout->addWidget( clearButton, 3, 0, 1, 1 );
1015 gLayout->addWidget( shortcutValue, 3, 1, 1, 2 );
1016 gLayout->addWidget( setButton, 3, 3, 1, 1 );
1018 l->addWidget( keyContainer, line, 0, 1, 2 );
1020 CONNECT( clearButton, clicked(), shortcutValue, clear() );
1021 BUTTONACT( setButton, setTheKey() );
1024 void KeySelectorControl::finish()
1027 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
1029 /* Fill the table */
1030 table->setColumnCount( 2 );
1031 table->setAlternatingRowColors( true );
1033 module_t *p_main = module_Find( p_this, "main" );
1037 module_config_t *p_config;
1039 p_config = module_GetConfig (p_main, &confsize);
1041 for (size_t i = 0; i < confsize; i++)
1043 module_config_t *p_item = p_config + i;
1045 if( p_item->i_type & CONFIG_ITEM && p_item->psz_name &&
1046 strstr( p_item->psz_name , "key-" ) && !EMPTY_STR( p_item->psz_text ) )
1048 QTreeWidgetItem *treeItem = new QTreeWidgetItem();
1049 treeItem->setText( 0, qtr( p_item->psz_text ) );
1050 treeItem->setText( 1, VLCKeyToString( p_item->value.i ) );
1051 treeItem->setData( 0, Qt::UserRole,
1052 QVariant::fromValue( (void*)p_item ) );
1054 table->addTopLevelItem( treeItem );
1057 module_PutConfig (p_config);
1058 module_Put (p_main);
1060 table->resizeColumnToContents( 0 );
1062 CONNECT( table, itemClicked( QTreeWidgetItem *, int ),
1063 this, select1Key( QTreeWidgetItem * ) );
1064 CONNECT( table, itemDoubleClicked( QTreeWidgetItem *, int ),
1065 this, selectKey( QTreeWidgetItem * ) );
1066 CONNECT( shortcutValue, pressed(), this, selectKey() );
1069 void KeySelectorControl::select1Key( QTreeWidgetItem *keyItem )
1071 shortcutValue->setText( keyItem->text( 1 ) );
1074 void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem )
1076 /* This happens when triggered by ClickEater */
1077 if( keyItem == NULL ) keyItem = table->currentItem();
1079 /* This can happen when nothing is selected on the treeView
1080 and the shortcutValue is clicked */
1081 if( !keyItem ) return;
1083 module_config_t *p_keyItem = static_cast<module_config_t*>
1084 (keyItem->data( 0, Qt::UserRole ).value<void*>());
1086 KeyInputDialog *d = new KeyInputDialog( values, p_keyItem->psz_text, widget );
1088 if( d->result() == QDialog::Accepted )
1090 p_keyItem->value.i = d->keyValue;
1093 for( int i = 0; i < table->topLevelItemCount() ; i++ )
1095 QTreeWidgetItem *it = table->topLevelItem(i);
1096 module_config_t *p_item = static_cast<module_config_t*>
1097 (it->data( 0, Qt::UserRole ).value<void*>());
1098 if( p_keyItem != p_item && p_item->value.i == d->keyValue )
1099 p_item->value.i = 0;
1100 shortcutValue->setText( VLCKeyToString( p_item->value.i ) );
1104 shortcutValue->setText( VLCKeyToString( p_keyItem->value.i ) );
1109 void KeySelectorControl::setTheKey()
1111 table->currentItem()->setText( 1, shortcutValue->text() );
1114 void KeySelectorControl::doApply()
1116 foreach( module_config_t *p_current, values )
1118 config_PutInt( p_this, p_current->psz_name, p_current->value.i );
1122 KeyInputDialog::KeyInputDialog( QList<module_config_t*>& _values,
1123 const char * _keyToChange,
1124 QWidget *_parent ) :
1125 QDialog( _parent ), keyValue(0)
1130 keyToChange = _keyToChange;
1132 setWindowTitle( qtr( "Hotkey for " ) + qfu( keyToChange) );
1134 vLayout = new QVBoxLayout( this );
1135 selected = new QLabel( qtr("Press the new keys for ") + qfu( keyToChange ) );
1136 vLayout->addWidget( selected , Qt::AlignCenter );
1138 buttonBox = new QDialogButtonBox;
1139 QPushButton *ok = new QPushButton( qtr("OK") );
1140 QPushButton *cancel = new QPushButton( qtr("Cancel") );
1141 buttonBox->addButton( ok, QDialogButtonBox::AcceptRole );
1142 buttonBox->addButton( cancel, QDialogButtonBox::RejectRole );
1144 vLayout->addWidget( buttonBox );
1147 CONNECT( buttonBox, accepted(), this, accept() );
1148 CONNECT( buttonBox, rejected(), this, reject() );
1151 void KeyInputDialog::checkForConflicts( int i_vlckey )
1154 module_config_t *p_current = NULL;
1155 /* Search for conflicts */
1156 foreach( p_current, values )
1158 if( p_current->value.i == i_vlckey && strcmp( p_current->psz_text,
1168 QLabel *warning = new QLabel(
1169 qtr("Warning: the key is already assigned to \"") +
1170 qfu( p_current->psz_text ) + "\"" );
1171 warning->setWordWrap( true );
1172 vLayout->insertWidget( 1, warning );
1178 void KeyInputDialog::keyPressEvent( QKeyEvent *e )
1180 if( e->key() == Qt::Key_Tab ) return;
1181 int i_vlck = qtEventToVLCKey( e );
1182 selected->setText( VLCKeyToString( i_vlck ) );
1183 checkForConflicts( i_vlck );
1187 void KeyInputDialog::wheelEvent( QWheelEvent *e )
1189 int i_vlck = qtWheelEventToVLCKey( e );
1190 selected->setText( VLCKeyToString( i_vlck ) );
1191 checkForConflicts( i_vlck );
1195 void KeyShortcutEdit::mousePressEvent( QMouseEvent *)