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 );
357 combo->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Preferred );
361 QHBoxLayout *layout = new QHBoxLayout();
362 layout->addWidget( label ); layout->addWidget( combo );
363 widget->setLayout( layout );
367 l->addWidget( label, line, 0 );
368 l->addWidget( combo, line, 1, Qt::AlignRight );
371 if( p_item->i_action )
373 QSignalMapper *signalMapper = new QSignalMapper(this);
375 /* Some stringLists like Capture listings have action associated */
376 for( int i = 0; i < p_item->i_action; i++ )
378 QPushButton *button =
379 new QPushButton( qfu( p_item->ppsz_action_text[i] ));
380 CONNECT( button, clicked(), signalMapper, map() );
381 signalMapper->setMapping( button, i );
382 l->addWidget( button, line, 2 + i, Qt::AlignRight );
384 CONNECT( signalMapper, mapped( int ),
385 this, actionRequested( int ) );
389 void StringListConfigControl::actionRequested( int i_action )
391 /* Supplementary check for boundaries */
392 if( i_action < 0 || i_action >= p_item->i_action ) return;
396 qtu( (combo->itemData( combo->currentIndex() ).toString() ) );
398 p_item->ppf_action[i_action]( p_this, getName(), val, val, 0 );
400 if( p_item->b_dirty )
404 p_item->b_dirty = VLC_FALSE;
407 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
408 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
409 bool bycat ) : VStringConfigControl( _p_this, _p_item )
416 void StringListConfigControl::finish( bool bycat )
418 combo->setEditable( false );
420 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
422 combo->addItem( qfu(p_item->ppsz_list_text ?
423 p_item->ppsz_list_text[i_index] :
424 p_item->ppsz_list[i_index] ),
425 QVariant( p_item->ppsz_list[i_index] ) );
426 if( p_item->value.psz && !strcmp( p_item->value.psz,
427 p_item->ppsz_list[i_index] ) )
428 combo->setCurrentIndex( combo->count() - 1 );
430 combo->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
432 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
435 QString StringListConfigControl::getValue()
437 return combo->itemData( combo->currentIndex() ).toString();
440 void setfillVLCConfigCombo( const char *configname, intf_thread_t *p_intf,
441 QComboBox *combo, QWidget *parent )
443 module_config_t *p_config =
444 config_FindConfig( VLC_OBJECT(p_intf), configname );
447 for ( int i_index = 0; i_index < p_config->i_list; i_index++ )
449 combo->addItem( qfu( p_config->ppsz_list_text[i_index] ),
450 QVariant( p_config->pi_list[i_index] ) );
451 if( p_config->value.i == p_config->pi_list[i_index] )
453 combo->setCurrentIndex( i_index );
456 combo->setToolTip( qfu( p_config->psz_longtext ) );
460 /********* Module **********/
461 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
462 module_config_t *_p_item, QWidget *_parent, bool bycat,
463 QGridLayout *l, int &line) :
464 VStringConfigControl( _p_this, _p_item, _parent )
466 label = new QLabel( qtr(p_item->psz_text) );
467 combo = new QComboBox();
468 combo->setMinimumWidth( 80 );
472 QHBoxLayout *layout = new QHBoxLayout();
473 layout->addWidget( label ); layout->addWidget( combo );
474 widget->setLayout( layout );
478 l->addWidget( label, line, 0 );
479 l->addWidget( combo, line, 1, Qt::AlignRight );
483 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
484 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
485 bool bycat ) : VStringConfigControl( _p_this, _p_item )
492 void ModuleConfigControl::finish( bool bycat )
497 combo->setEditable( false );
499 /* build a list of available modules */
500 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
501 combo->addItem( qtr("Default") );
502 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
504 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
508 if( !strcmp( module_GetObjName( p_parser ), "main" ) ) continue;
511 module_config_t *p_config;
513 p_config = module_GetConfig (p_parser, &confsize);
514 for (size_t i = 0; i < confsize; i++)
516 /* Hack: required subcategory is stored in i_min */
517 const module_config_t *p_cfg = p_config + i;
518 if( p_cfg->i_type == CONFIG_SUBCATEGORY &&
519 p_cfg->value.i == p_item->min.i )
520 combo->addItem( qtr( module_GetLongName( p_parser )),
521 QVariant( module_GetObjName( p_parser ) ) );
522 if( p_item->value.psz && !strcmp( p_item->value.psz,
523 module_GetObjName( p_parser ) ) )
524 combo->setCurrentIndex( combo->count() - 1 );
526 module_PutConfig (p_config);
528 else if( module_IsCapable( p_parser, p_item->psz_type ) )
530 combo->addItem( qtr(module_GetLongName( p_parser ) ),
531 QVariant( module_GetObjName( p_parser ) ) );
532 if( p_item->value.psz && !strcmp( p_item->value.psz,
533 module_GetObjName( p_parser ) ) )
534 combo->setCurrentIndex( combo->count() - 1 );
537 vlc_list_release( p_list );
538 combo->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
540 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
543 QString ModuleConfigControl::getValue()
545 return combo->itemData( combo->currentIndex() ).toString();
548 /********* Module list **********/
549 ModuleListConfigControl::ModuleListConfigControl( vlc_object_t *_p_this,
550 module_config_t *_p_item, QWidget *_parent, bool bycat,
551 QGridLayout *l, int &line) :
552 VStringConfigControl( _p_this, _p_item, _parent )
554 groupBox = new QGroupBox ( qtr(p_item->psz_text) );
555 text = new QLineEdit();
556 QGridLayout *layoutGroupBox = new QGridLayout( groupBox );
561 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
562 it != modules.end(); it++ )
564 layoutGroupBox->addWidget( (*it)->checkBox, boxline++, 0 );
566 layoutGroupBox->addWidget( text, boxline, 0 );
570 QVBoxLayout *layout = new QVBoxLayout();
571 layout->addWidget( groupBox, line, 0 );
572 widget->setLayout( layout );
576 l->addWidget( groupBox, line, 0, 1, -1 );
579 text->setToolTip( formatTooltip( qtr( p_item->psz_longtext) ) );
582 ModuleListConfigControl::~ModuleListConfigControl()
584 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
585 it != modules.end(); it++ )
593 #define CHECKBOX_LISTS \
595 QCheckBox *cb = new QCheckBox( qtr( module_GetLongName( p_parser ) ) );\
596 checkBoxListItem *cbl = new checkBoxListItem; \
598 CONNECT( cb, stateChanged( int ), this, onUpdate( int ) );\
599 cb->setToolTip( formatTooltip( qtr( module_GetLongName( p_parser ))));\
600 cbl->checkBox = cb; \
602 cbl->psz_module = strdup( module_GetObjName( p_parser ) ); \
603 modules.push_back( cbl ); \
607 void ModuleListConfigControl::finish( bool bycat )
612 /* build a list of available modules */
613 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
614 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
616 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
620 if( !strcmp( module_GetObjName( p_parser ), "main" ) ) continue;
623 module_config_t *p_config = module_GetConfig (p_parser, &confsize);
625 for (size_t i = 0; i < confsize; i++)
627 module_config_t *p_cfg = p_config + i;
628 /* Hack: required subcategory is stored in i_min */
629 if( p_cfg->i_type == CONFIG_SUBCATEGORY &&
630 p_cfg->value.i == p_item->min.i )
635 module_PutConfig (p_config);
637 else if( module_IsCapable( p_parser, p_item->psz_type ) )
642 vlc_list_release( p_list );
643 text->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
645 groupBox->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
647 #undef CHECKBOX_LISTS
649 QString ModuleListConfigControl::getValue()
654 void ModuleListConfigControl::hide()
656 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
657 it != modules.end(); it++ )
659 (*it)->checkBox->hide();
664 void ModuleListConfigControl::show()
666 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
667 it != modules.end(); it++ )
669 (*it)->checkBox->show();
675 void ModuleListConfigControl::onUpdate( int value )
680 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
681 it != modules.end(); it++ )
683 if( (*it)->checkBox->isChecked() )
687 text->setText( text->text() + (*it)->psz_module );
692 text->setText( text->text() + ":" + (*it)->psz_module );
698 /**************************************************************************
699 * Integer-based controls
700 *************************************************************************/
702 /*********** Integer **************/
703 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
704 module_config_t *_p_item,
705 QWidget *_parent, QGridLayout *l,
707 VIntConfigControl( _p_this, _p_item, _parent )
709 label = new QLabel( qtr(p_item->psz_text) );
710 spin = new QSpinBox; spin->setMinimumWidth( 80 );
711 spin->setAlignment( Qt::AlignRight );
712 spin->setMaximumWidth( 90 );
717 QHBoxLayout *layout = new QHBoxLayout();
718 layout->addWidget( label, 0 ); layout->addWidget( spin, 1 );
719 widget->setLayout( layout );
723 l->addWidget( label, line, 0 );
724 l->addWidget( spin, line, 1, Qt::AlignRight );
727 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
728 module_config_t *_p_item,
729 QLabel *_label, QSpinBox *_spin ) :
730 VIntConfigControl( _p_this, _p_item )
737 void IntegerConfigControl::finish()
739 spin->setMaximum( 2000000000 );
740 spin->setMinimum( -2000000000 );
741 spin->setValue( p_item->value.i );
742 spin->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
744 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
747 int IntegerConfigControl::getValue()
749 return spin->value();
752 /********* Integer range **********/
753 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
754 module_config_t *_p_item,
755 QWidget *_parent, QGridLayout *l,
757 IntegerConfigControl( _p_this, _p_item, _parent, l, line )
762 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
763 module_config_t *_p_item,
764 QLabel *_label, QSpinBox *_spin ) :
765 IntegerConfigControl( _p_this, _p_item, _label, _spin )
770 void IntegerRangeConfigControl::finish()
772 spin->setMaximum( p_item->max.i );
773 spin->setMinimum( p_item->min.i );
776 IntegerRangeSliderConfigControl::IntegerRangeSliderConfigControl(
777 vlc_object_t *_p_this,
778 module_config_t *_p_item,
779 QLabel *_label, QSlider *_slider ):
780 VIntConfigControl( _p_this, _p_item )
784 slider->setMaximum( p_item->max.i );
785 slider->setMinimum( p_item->min.i );
786 slider->setValue( p_item->value.i );
787 slider->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
789 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
792 int IntegerRangeSliderConfigControl::getValue()
794 return slider->value();
798 /********* Integer / choice list **********/
799 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
800 module_config_t *_p_item, QWidget *_parent, bool bycat,
801 QGridLayout *l, int &line) :
802 VIntConfigControl( _p_this, _p_item, _parent )
804 label = new QLabel( qtr(p_item->psz_text) );
805 combo = new QComboBox();
806 combo->setMinimumWidth( 80 );
810 QHBoxLayout *layout = new QHBoxLayout();
811 layout->addWidget( label ); layout->addWidget( combo );
812 widget->setLayout( layout );
816 l->addWidget( label, line, 0 );
817 l->addWidget( combo, line, 1, Qt::AlignRight );
820 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
821 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
822 bool bycat ) : VIntConfigControl( _p_this, _p_item )
829 void IntegerListConfigControl::finish( bool bycat )
831 combo->setEditable( false );
833 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
835 combo->addItem( qtr(p_item->ppsz_list_text[i_index] ),
836 QVariant( p_item->pi_list[i_index] ) );
837 if( p_item->value.i == p_item->pi_list[i_index] )
838 combo->setCurrentIndex( combo->count() - 1 );
840 combo->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
842 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
845 int IntegerListConfigControl::getValue()
847 return combo->itemData( combo->currentIndex() ).toInt();
850 /*********** Boolean **************/
851 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
852 module_config_t *_p_item,
853 QWidget *_parent, QGridLayout *l,
855 VIntConfigControl( _p_this, _p_item, _parent )
857 checkbox = new QCheckBox( qtr(p_item->psz_text) );
862 QHBoxLayout *layout = new QHBoxLayout();
863 layout->addWidget( checkbox, 0 );
864 widget->setLayout( layout );
868 l->addWidget( checkbox, line, 0 );
871 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
872 module_config_t *_p_item,
874 QCheckBox *_checkbox,
876 VIntConfigControl( _p_this, _p_item )
878 checkbox = _checkbox;
882 void BoolConfigControl::finish()
884 checkbox->setCheckState( p_item->value.i == VLC_TRUE ? Qt::Checked
886 checkbox->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
889 int BoolConfigControl::getValue()
891 return checkbox->checkState() == Qt::Checked ? VLC_TRUE : VLC_FALSE;
894 /**************************************************************************
895 * Float-based controls
896 *************************************************************************/
898 /*********** Float **************/
899 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
900 module_config_t *_p_item,
901 QWidget *_parent, QGridLayout *l,
903 VFloatConfigControl( _p_this, _p_item, _parent )
905 label = new QLabel( qtr(p_item->psz_text) );
906 spin = new QDoubleSpinBox;
907 spin->setMinimumWidth( 80 );
908 spin->setMaximumWidth( 90 );
909 spin->setAlignment( Qt::AlignRight );
914 QHBoxLayout *layout = new QHBoxLayout();
915 layout->addWidget( label, 0 ); layout->addWidget( spin, 1 );
916 widget->setLayout( layout );
920 l->addWidget( label, line, 0 );
921 l->addWidget( spin, line, 1, Qt::AlignRight );
925 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
926 module_config_t *_p_item,
928 QDoubleSpinBox *_spin ) :
929 VFloatConfigControl( _p_this, _p_item )
936 void FloatConfigControl::finish()
938 spin->setMaximum( 2000000000. );
939 spin->setMinimum( -2000000000. );
940 spin->setSingleStep( 0.1 );
941 spin->setValue( (double)p_item->value.f );
942 spin->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
944 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
947 float FloatConfigControl::getValue()
949 return (float)spin->value();
952 /*********** Float with range **************/
953 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
954 module_config_t *_p_item,
955 QWidget *_parent, QGridLayout *l,
957 FloatConfigControl( _p_this, _p_item, _parent, l, line )
962 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
963 module_config_t *_p_item,
965 QDoubleSpinBox *_spin ) :
966 FloatConfigControl( _p_this, _p_item, _label, _spin )
971 void FloatRangeConfigControl::finish()
973 spin->setMaximum( (double)p_item->max.f );
974 spin->setMinimum( (double)p_item->min.f );
978 /**********************************************************************
979 * Key selector widget
980 **********************************************************************/
981 KeySelectorControl::KeySelectorControl( vlc_object_t *_p_this,
982 module_config_t *_p_item,
983 QWidget *_parent, QGridLayout *l,
985 ConfigControl( _p_this, _p_item, _parent )
988 QWidget *keyContainer = new QWidget;
989 QGridLayout *gLayout = new QGridLayout( keyContainer );
992 qtr( "Select an action to change the associated hotkey") );
994 /* Deactivated for now
995 QLabel *searchLabel = new QLabel( qtr( "Search" ) );
996 QLineEdit *actionSearch = new QLineEdit;*/
998 table = new QTreeWidget;
999 table->setColumnCount(2);
1000 table->headerItem()->setText( 0, qtr( "Action" ) );
1001 table->headerItem()->setText( 1, qtr( "Shortcut" ) );
1003 shortcutValue = new KeyShortcutEdit;
1004 shortcutValue->setReadOnly(true);
1006 QPushButton *clearButton = new QPushButton( qtr( "Clear" ) );
1007 QPushButton *setButton = new QPushButton( qtr( "Set" ) );
1010 gLayout->addWidget( label, 0, 0, 1, 4 );
1011 /* deactivated for now
1012 gLayout->addWidget( searchLabel, 1, 0, 1, 2 );
1013 gLayout->addWidget( actionSearch, 1, 2, 1, 2 ); */
1014 gLayout->addWidget( table, 2, 0, 1, 4 );
1015 gLayout->addWidget( clearButton, 3, 0, 1, 1 );
1016 gLayout->addWidget( shortcutValue, 3, 1, 1, 2 );
1017 gLayout->addWidget( setButton, 3, 3, 1, 1 );
1019 l->addWidget( keyContainer, line, 0, 1, 2 );
1021 CONNECT( clearButton, clicked(), shortcutValue, clear() );
1022 BUTTONACT( setButton, setTheKey() );
1025 void KeySelectorControl::finish()
1028 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
1030 /* Fill the table */
1031 table->setColumnCount( 2 );
1032 table->setAlternatingRowColors( true );
1034 module_t *p_main = module_Find( p_this, "main" );
1038 module_config_t *p_config;
1040 p_config = module_GetConfig (p_main, &confsize);
1042 for (size_t i = 0; i < confsize; i++)
1044 module_config_t *p_item = p_config + i;
1046 if( p_item->i_type & CONFIG_ITEM && p_item->psz_name &&
1047 strstr( p_item->psz_name , "key-" ) && !EMPTY_STR( p_item->psz_text ) )
1049 QTreeWidgetItem *treeItem = new QTreeWidgetItem();
1050 treeItem->setText( 0, qtr( p_item->psz_text ) );
1051 treeItem->setText( 1, VLCKeyToString( p_item->value.i ) );
1052 treeItem->setData( 0, Qt::UserRole,
1053 QVariant::fromValue( (void*)p_item ) );
1055 table->addTopLevelItem( treeItem );
1058 module_PutConfig (p_config);
1059 module_Put (p_main);
1061 table->resizeColumnToContents( 0 );
1063 CONNECT( table, itemClicked( QTreeWidgetItem *, int ),
1064 this, select1Key( QTreeWidgetItem * ) );
1065 CONNECT( table, itemDoubleClicked( QTreeWidgetItem *, int ),
1066 this, selectKey( QTreeWidgetItem * ) );
1067 CONNECT( shortcutValue, pressed(), this, selectKey() );
1070 void KeySelectorControl::select1Key( QTreeWidgetItem *keyItem )
1072 shortcutValue->setText( keyItem->text( 1 ) );
1075 void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem )
1077 /* This happens when triggered by ClickEater */
1078 if( keyItem == NULL ) keyItem = table->currentItem();
1080 /* This can happen when nothing is selected on the treeView
1081 and the shortcutValue is clicked */
1082 if( !keyItem ) return;
1084 module_config_t *p_keyItem = static_cast<module_config_t*>
1085 (keyItem->data( 0, Qt::UserRole ).value<void*>());
1087 KeyInputDialog *d = new KeyInputDialog( values, p_keyItem->psz_text, widget );
1089 if( d->result() == QDialog::Accepted )
1091 p_keyItem->value.i = d->keyValue;
1094 for( int i = 0; i < table->topLevelItemCount() ; i++ )
1096 QTreeWidgetItem *it = table->topLevelItem(i);
1097 module_config_t *p_item = static_cast<module_config_t*>
1098 (it->data( 0, Qt::UserRole ).value<void*>());
1099 if( p_keyItem != p_item && p_item->value.i == d->keyValue )
1100 p_item->value.i = 0;
1101 shortcutValue->setText( VLCKeyToString( p_item->value.i ) );
1105 shortcutValue->setText( VLCKeyToString( p_keyItem->value.i ) );
1110 void KeySelectorControl::setTheKey()
1112 table->currentItem()->setText( 1, shortcutValue->text() );
1115 void KeySelectorControl::doApply()
1117 foreach( module_config_t *p_current, values )
1119 config_PutInt( p_this, p_current->psz_name, p_current->value.i );
1123 KeyInputDialog::KeyInputDialog( QList<module_config_t*>& _values,
1124 const char * _keyToChange,
1125 QWidget *_parent ) :
1126 QDialog( _parent ), keyValue(0)
1131 keyToChange = _keyToChange;
1133 setWindowTitle( qtr( "Hotkey for " ) + qfu( keyToChange) );
1135 vLayout = new QVBoxLayout( this );
1136 selected = new QLabel( qtr("Press the new keys for ") + qfu( keyToChange ) );
1137 vLayout->addWidget( selected , Qt::AlignCenter );
1139 buttonBox = new QDialogButtonBox;
1140 QPushButton *ok = new QPushButton( qtr("OK") );
1141 QPushButton *cancel = new QPushButton( qtr("Cancel") );
1142 buttonBox->addButton( ok, QDialogButtonBox::AcceptRole );
1143 buttonBox->addButton( cancel, QDialogButtonBox::RejectRole );
1145 vLayout->addWidget( buttonBox );
1148 CONNECT( buttonBox, accepted(), this, accept() );
1149 CONNECT( buttonBox, rejected(), this, reject() );
1152 void KeyInputDialog::checkForConflicts( int i_vlckey )
1155 module_config_t *p_current = NULL;
1156 /* Search for conflicts */
1157 foreach( p_current, values )
1159 if( p_current->value.i == i_vlckey && strcmp( p_current->psz_text,
1169 QLabel *warning = new QLabel(
1170 qtr("Warning: the key is already assigned to \"") +
1171 qfu( p_current->psz_text ) + "\"" );
1172 warning->setWordWrap( true );
1173 vLayout->insertWidget( 1, warning );
1179 void KeyInputDialog::keyPressEvent( QKeyEvent *e )
1181 if( e->key() == Qt::Key_Tab ) return;
1182 int i_vlck = qtEventToVLCKey( e );
1183 selected->setText( VLCKeyToString( i_vlck ) );
1184 checkForConflicts( i_vlck );
1188 void KeyInputDialog::wheelEvent( QWheelEvent *e )
1190 int i_vlck = qtWheelEventToVLCKey( e );
1191 selected->setText( VLCKeyToString( i_vlck ) );
1192 checkForConflicts( i_vlck );
1196 void KeyShortcutEdit::mousePressEvent( QMouseEvent *)