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
37 #include "components/preferences_widgets.hpp"
38 #include "util/customwidgets.hpp"
44 #include <QGridLayout>
46 #include <QFileDialog>
47 #include <QFontDialog>
49 #include <QTreeWidgetItem>
50 #include <QSignalMapper>
51 #include <QDialogButtonBox>
53 #define MINWIDTH_BOX 90
54 #define LAST_COLUMN 10
56 QString formatTooltip(const QString & tooltip)
59 "<html><head><meta name=\"qrichtext\" content=\"1\" />"
60 "<style type=\"text/css\"> p, li { white-space: pre-wrap; } </style></head>"
61 "<body style=\" font-family:'Sans Serif'; font-size:9pt; font-weight:400; "
62 "font-style:normal; text-decoration:none;\">"
63 "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; "
64 "margin-right:0px; -qt-block-indent:0; text-indent:0px;\">" +
70 ConfigControl *ConfigControl::createControl( vlc_object_t *p_this,
71 module_config_t *p_item,
75 return createControl( p_this, p_item, parent, NULL, i );
78 ConfigControl *ConfigControl::createControl( vlc_object_t *p_this,
79 module_config_t *p_item,
81 QGridLayout *l, int &line )
83 ConfigControl *p_control = NULL;
85 switch( p_item->i_type )
87 case CONFIG_ITEM_MODULE:
88 p_control = new ModuleConfigControl( p_this, p_item, parent, false,
91 case CONFIG_ITEM_MODULE_CAT:
92 p_control = new ModuleConfigControl( p_this, p_item, parent, true,
95 case CONFIG_ITEM_MODULE_LIST:
96 p_control = new ModuleListConfigControl( p_this, p_item, parent, false,
99 case CONFIG_ITEM_MODULE_LIST_CAT:
100 p_control = new ModuleListConfigControl( p_this, p_item, parent, true,
103 case CONFIG_ITEM_STRING:
104 if( !p_item->i_list )
105 p_control = new StringConfigControl( p_this, p_item, parent,
108 p_control = new StringListConfigControl( p_this, p_item,
109 parent, false, l, line );
111 case CONFIG_ITEM_PASSWORD:
112 if( !p_item->i_list )
113 p_control = new StringConfigControl( p_this, p_item, parent,
116 p_control = new StringListConfigControl( p_this, p_item,
117 parent, true, l, line );
119 case CONFIG_ITEM_INTEGER:
121 p_control = new IntegerListConfigControl( p_this, p_item,
122 parent, false, l, line );
123 else if( p_item->min.i || p_item->max.i )
124 p_control = new IntegerRangeConfigControl( p_this, p_item, parent,
127 p_control = new IntegerConfigControl( p_this, p_item, parent,
130 case CONFIG_ITEM_FILE:
131 p_control = new FileConfigControl( p_this, p_item, parent, l,
134 case CONFIG_ITEM_DIRECTORY:
135 p_control = new DirectoryConfigControl( p_this, p_item, parent, l,
138 case CONFIG_ITEM_FONT:
139 p_control = new FontConfigControl( p_this, p_item, parent, l,
142 case CONFIG_ITEM_KEY:
143 p_control = new KeySelectorControl( p_this, p_item, parent, l, line );
145 case CONFIG_ITEM_BOOL:
146 p_control = new BoolConfigControl( p_this, p_item, parent, l, line );
148 case CONFIG_ITEM_FLOAT:
149 if( p_item->min.f || p_item->max.f )
150 p_control = new FloatRangeConfigControl( p_this, p_item, parent,
153 p_control = new FloatConfigControl( p_this, p_item, parent,
162 void ConfigControl::doApply( intf_thread_t *p_intf )
166 case CONFIG_ITEM_INTEGER:
167 case CONFIG_ITEM_BOOL:
169 VIntConfigControl *vicc = qobject_cast<VIntConfigControl *>(this);
171 config_PutInt( p_intf, vicc->getName(), vicc->getValue() );
174 case CONFIG_ITEM_FLOAT:
176 VFloatConfigControl *vfcc =
177 qobject_cast<VFloatConfigControl *>(this);
179 config_PutFloat( p_intf, vfcc->getName(), vfcc->getValue() );
182 case CONFIG_ITEM_STRING:
184 VStringConfigControl *vscc =
185 qobject_cast<VStringConfigControl *>(this);
187 config_PutPsz( p_intf, vscc->getName(), qta( vscc->getValue() ) );
190 case CONFIG_ITEM_KEY:
192 KeySelectorControl *ksc = qobject_cast<KeySelectorControl *>(this);
199 /**************************************************************************
200 * String-based controls
201 *************************************************************************/
203 /*********** String **************/
204 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
205 module_config_t *_p_item,
206 QWidget *_parent, QGridLayout *l,
207 int &line, bool pwd ) :
208 VStringConfigControl( _p_this, _p_item, _parent )
210 label = new QLabel( qtr(p_item->psz_text) );
211 text = new QLineEdit( qfu(p_item->value.psz) );
212 if( pwd ) text->setEchoMode( QLineEdit::Password );
217 QHBoxLayout *layout = new QHBoxLayout();
218 layout->addWidget( label, 0 ); layout->insertSpacing( 1, 10 );
219 layout->addWidget( text, LAST_COLUMN );
220 widget->setLayout( layout );
224 l->addWidget( label, line, 0 );
225 l->setColumnMinimumWidth( 1, 10 );
226 l->addWidget( text, line, LAST_COLUMN );
230 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
231 module_config_t *_p_item,
232 QLabel *_label, QLineEdit *_text, bool pwd ):
233 VStringConfigControl( _p_this, _p_item )
240 void StringConfigControl::finish()
242 text->setText( qfu(p_item->value.psz) );
243 text->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
245 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
248 /*********** File **************/
249 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
250 module_config_t *_p_item,
251 QWidget *_parent, QGridLayout *l,
252 int &line, bool pwd ) :
253 VStringConfigControl( _p_this, _p_item, _parent )
255 label = new QLabel( qtr(p_item->psz_text) );
256 text = new QLineEdit( qfu(p_item->value.psz) );
257 browse = new QPushButton( qtr( "Browse..." ) );
258 QHBoxLayout *textAndButton = new QHBoxLayout();
259 textAndButton->setMargin( 0 );
260 textAndButton->addWidget( text, 2 );
261 textAndButton->addWidget( browse, 0 );
263 BUTTONACT( browse, updateField() );
269 QHBoxLayout *layout = new QHBoxLayout();
270 layout->addWidget( label, 0 );
271 layout->insertSpacing( 1, 10 );
272 layout->addLayout( textAndButton, LAST_COLUMN );
273 widget->setLayout( layout );
277 l->addWidget( label, line, 0 );
278 l->setColumnMinimumWidth( 1, 10 );
279 l->addLayout( textAndButton, line, LAST_COLUMN );
284 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
285 module_config_t *_p_item,
286 QLabel *_label, QLineEdit *_text,
287 QPushButton *_button, bool pwd ):
288 VStringConfigControl( _p_this, _p_item )
294 BUTTONACT( browse, updateField() );
299 void FileConfigControl::updateField()
301 QString file = QFileDialog::getOpenFileName( NULL,
302 qtr( "Select File" ), qfu( p_this->p_libvlc->psz_homedir ) );
303 if( file.isNull() ) return;
304 text->setText( file );
307 void FileConfigControl::finish()
309 text->setText( qfu(p_item->value.psz) );
310 text->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
312 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
315 /********* String / Directory **********/
316 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
317 module_config_t *_p_item, QWidget *_p_widget,
318 QGridLayout *_p_layout, int& _int, bool _pwd ) :
319 FileConfigControl( _p_this, _p_item, _p_widget, _p_layout, _int, _pwd)
322 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
323 module_config_t *_p_item, QLabel *_p_label,
324 QLineEdit *_p_line, QPushButton *_p_button, bool _pwd ):
325 FileConfigControl( _p_this, _p_item, _p_label, _p_line, _p_button, _pwd)
328 void DirectoryConfigControl::updateField()
330 QString dir = QFileDialog::getExistingDirectory( NULL,
331 qtr( "Select Directory" ),
332 text->text().isEmpty() ?
333 qfu( p_this->p_libvlc->psz_homedir ) : text->text(),
334 QFileDialog::ShowDirsOnly |
335 QFileDialog::DontResolveSymlinks );
336 if( dir.isNull() ) return;
337 text->setText( dir );
340 /********* String / Font **********/
341 FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
342 module_config_t *_p_item, QWidget *_p_widget,
343 QGridLayout *_p_layout, int& _int, bool _pwd ) :
344 FileConfigControl( _p_this, _p_item, _p_widget, _p_layout, _int, _pwd)
347 FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
348 module_config_t *_p_item, QLabel *_p_label,
349 QLineEdit *_p_line, QPushButton *_p_button, bool _pwd ):
350 FileConfigControl( _p_this, _p_item, _p_label, _p_line, _p_button, _pwd)
353 void FontConfigControl::updateField()
356 QFont font = QFontDialog::getFont( &ok, QFont( text->text() ), NULL );
358 text->setText( font.family() );
361 /********* String / choice list **********/
362 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
363 module_config_t *_p_item, QWidget *_parent, bool bycat,
364 QGridLayout *l, int &line) :
365 VStringConfigControl( _p_this, _p_item, _parent )
367 label = new QLabel( qtr(p_item->psz_text) );
368 combo = new QComboBox();
369 combo->setMinimumWidth( MINWIDTH_BOX );
370 combo->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Preferred );
374 l = new QGridLayout();
375 l->addWidget( label, 0, 0 ); l->addWidget( combo, 0, LAST_COLUMN );
376 widget->setLayout( l );
380 l->addWidget( label, line, 0 );
381 l->addWidget( combo, line, LAST_COLUMN, Qt::AlignRight );
384 if( p_item->i_action )
386 QSignalMapper *signalMapper = new QSignalMapper(this);
388 /* Some stringLists like Capture listings have action associated */
389 for( int i = 0; i < p_item->i_action; i++ )
391 QPushButton *button =
392 new QPushButton( qfu( p_item->ppsz_action_text[i] ));
393 CONNECT( button, clicked(), signalMapper, map() );
394 signalMapper->setMapping( button, i );
395 l->addWidget( button, line, LAST_COLUMN - p_item->i_action + i,
398 CONNECT( signalMapper, mapped( int ),
399 this, actionRequested( int ) );
403 void StringListConfigControl::actionRequested( int i_action )
405 /* Supplementary check for boundaries */
406 if( i_action < 0 || i_action >= p_item->i_action ) return;
410 qtu( (combo->itemData( combo->currentIndex() ).toString() ) );
412 p_item->ppf_action[i_action]( p_this, getName(), val, val, 0 );
414 if( p_item->b_dirty )
418 p_item->b_dirty = VLC_FALSE;
421 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
422 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
423 bool bycat ) : VStringConfigControl( _p_this, _p_item )
430 void StringListConfigControl::finish( bool bycat )
432 combo->setEditable( false );
434 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
436 combo->addItem( qfu(p_item->ppsz_list_text ?
437 p_item->ppsz_list_text[i_index] :
438 p_item->ppsz_list[i_index] ),
439 QVariant( p_item->ppsz_list[i_index] ) );
440 if( p_item->value.psz && !strcmp( p_item->value.psz,
441 p_item->ppsz_list[i_index] ) )
442 combo->setCurrentIndex( combo->count() - 1 );
444 combo->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
446 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
449 QString StringListConfigControl::getValue()
451 return combo->itemData( combo->currentIndex() ).toString();
454 void setfillVLCConfigCombo( const char *configname, intf_thread_t *p_intf,
455 QComboBox *combo, QWidget *parent )
457 module_config_t *p_config =
458 config_FindConfig( VLC_OBJECT(p_intf), configname );
461 for ( int i_index = 0; i_index < p_config->i_list; i_index++ )
463 combo->addItem( qfu( p_config->ppsz_list_text[i_index] ),
464 QVariant( p_config->pi_list[i_index] ) );
465 if( p_config->value.i == p_config->pi_list[i_index] )
467 combo->setCurrentIndex( i_index );
470 combo->setToolTip( qfu( p_config->psz_longtext ) );
474 /********* Module **********/
475 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
476 module_config_t *_p_item, QWidget *_parent, bool bycat,
477 QGridLayout *l, int &line) :
478 VStringConfigControl( _p_this, _p_item, _parent )
480 label = new QLabel( qtr(p_item->psz_text) );
481 combo = new QComboBox();
482 combo->setMinimumWidth( MINWIDTH_BOX );
486 QHBoxLayout *layout = new QHBoxLayout();
487 layout->addWidget( label ); layout->addWidget( combo, LAST_COLUMN );
488 widget->setLayout( layout );
492 l->addWidget( label, line, 0 );
493 l->addWidget( combo, line, LAST_COLUMN, Qt::AlignRight );
497 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
498 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
499 bool bycat ) : VStringConfigControl( _p_this, _p_item )
506 void ModuleConfigControl::finish( bool bycat )
511 combo->setEditable( false );
513 /* build a list of available modules */
514 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
515 combo->addItem( qtr("Default") );
516 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
518 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
522 if( !strcmp( module_GetObjName( p_parser ), "main" ) ) continue;
525 module_config_t *p_config;
527 p_config = module_GetConfig (p_parser, &confsize);
528 for (size_t i = 0; i < confsize; i++)
530 /* Hack: required subcategory is stored in i_min */
531 const module_config_t *p_cfg = p_config + i;
532 if( p_cfg->i_type == CONFIG_SUBCATEGORY &&
533 p_cfg->value.i == p_item->min.i )
534 combo->addItem( qtr( module_GetLongName( p_parser )),
535 QVariant( module_GetObjName( p_parser ) ) );
536 if( p_item->value.psz && !strcmp( p_item->value.psz,
537 module_GetObjName( p_parser ) ) )
538 combo->setCurrentIndex( combo->count() - 1 );
540 module_PutConfig (p_config);
542 else if( module_IsCapable( p_parser, p_item->psz_type ) )
544 combo->addItem( qtr(module_GetLongName( p_parser ) ),
545 QVariant( module_GetObjName( p_parser ) ) );
546 if( p_item->value.psz && !strcmp( p_item->value.psz,
547 module_GetObjName( p_parser ) ) )
548 combo->setCurrentIndex( combo->count() - 1 );
551 vlc_list_release( p_list );
552 combo->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
554 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
557 QString ModuleConfigControl::getValue()
559 return combo->itemData( combo->currentIndex() ).toString();
562 /********* Module list **********/
563 ModuleListConfigControl::ModuleListConfigControl( vlc_object_t *_p_this,
564 module_config_t *_p_item, QWidget *_parent, bool bycat,
565 QGridLayout *l, int &line) :
566 VStringConfigControl( _p_this, _p_item, _parent )
568 groupBox = new QGroupBox ( qtr(p_item->psz_text) );
569 text = new QLineEdit();
570 QGridLayout *layoutGroupBox = new QGridLayout( groupBox );
575 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
576 it != modules.end(); it++ )
578 layoutGroupBox->addWidget( (*it)->checkBox, boxline++, 0 );
580 layoutGroupBox->addWidget( text, boxline, 0 );
584 QVBoxLayout *layout = new QVBoxLayout();
585 layout->addWidget( groupBox, line, 0 );
586 widget->setLayout( layout );
590 l->addWidget( groupBox, line, 0, 1, -1 );
593 text->setToolTip( formatTooltip( qtr( p_item->psz_longtext) ) );
596 ModuleListConfigControl::~ModuleListConfigControl()
598 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
599 it != modules.end(); it++ )
607 #define CHECKBOX_LISTS \
609 QCheckBox *cb = new QCheckBox( qtr( module_GetLongName( p_parser ) ) );\
610 checkBoxListItem *cbl = new checkBoxListItem; \
612 CONNECT( cb, stateChanged( int ), this, onUpdate( int ) );\
613 cb->setToolTip( formatTooltip( qtr( module_GetHelp( p_parser ))));\
614 cbl->checkBox = cb; \
616 cbl->psz_module = strdup( module_GetObjName( p_parser ) ); \
617 modules.push_back( cbl ); \
619 if( p_item->value.psz && strstr( p_item->value.psz, cbl->psz_module ) ) \
620 cbl->checkBox->setChecked( true ); \
624 void ModuleListConfigControl::finish( bool bycat )
629 /* build a list of available modules */
630 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
631 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
633 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
637 if( !strcmp( module_GetObjName( p_parser ), "main" ) ) continue;
640 module_config_t *p_config = module_GetConfig (p_parser, &confsize);
642 for (size_t i = 0; i < confsize; i++)
644 module_config_t *p_cfg = p_config + i;
645 /* Hack: required subcategory is stored in i_min */
646 if( p_cfg->i_type == CONFIG_SUBCATEGORY &&
647 p_cfg->value.i == p_item->min.i )
652 module_PutConfig (p_config);
654 else if( module_IsCapable( p_parser, p_item->psz_type ) )
659 vlc_list_release( p_list );
660 text->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
662 groupBox->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
664 #undef CHECKBOX_LISTS
666 QString ModuleListConfigControl::getValue()
671 void ModuleListConfigControl::hide()
673 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
674 it != modules.end(); it++ )
676 (*it)->checkBox->hide();
681 void ModuleListConfigControl::show()
683 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
684 it != modules.end(); it++ )
686 (*it)->checkBox->show();
692 void ModuleListConfigControl::onUpdate( int value )
697 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
698 it != modules.end(); it++ )
700 if( (*it)->checkBox->isChecked() )
704 text->setText( text->text() + (*it)->psz_module );
709 text->setText( text->text() + ":" + (*it)->psz_module );
715 /**************************************************************************
716 * Integer-based controls
717 *************************************************************************/
719 /*********** Integer **************/
720 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
721 module_config_t *_p_item,
722 QWidget *_parent, QGridLayout *l,
724 VIntConfigControl( _p_this, _p_item, _parent )
726 label = new QLabel( qtr(p_item->psz_text) );
727 spin = new QSpinBox; spin->setMinimumWidth( MINWIDTH_BOX );
728 spin->setAlignment( Qt::AlignRight );
729 spin->setMaximumWidth( MINWIDTH_BOX );
734 QHBoxLayout *layout = new QHBoxLayout();
735 layout->addWidget( label, 0 ); layout->addWidget( spin, LAST_COLUMN );
736 widget->setLayout( layout );
740 l->addWidget( label, line, 0 );
741 l->addWidget( spin, line, LAST_COLUMN, Qt::AlignRight );
744 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
745 module_config_t *_p_item,
746 QLabel *_label, QSpinBox *_spin ) :
747 VIntConfigControl( _p_this, _p_item )
754 void IntegerConfigControl::finish()
756 spin->setMaximum( 2000000000 );
757 spin->setMinimum( -2000000000 );
758 spin->setValue( p_item->value.i );
759 spin->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
761 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
764 int IntegerConfigControl::getValue()
766 return spin->value();
769 /********* Integer range **********/
770 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
771 module_config_t *_p_item,
772 QWidget *_parent, QGridLayout *l,
774 IntegerConfigControl( _p_this, _p_item, _parent, l, line )
779 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
780 module_config_t *_p_item,
781 QLabel *_label, QSpinBox *_spin ) :
782 IntegerConfigControl( _p_this, _p_item, _label, _spin )
787 void IntegerRangeConfigControl::finish()
789 spin->setMaximum( p_item->max.i );
790 spin->setMinimum( p_item->min.i );
793 IntegerRangeSliderConfigControl::IntegerRangeSliderConfigControl(
794 vlc_object_t *_p_this,
795 module_config_t *_p_item,
796 QLabel *_label, QSlider *_slider ):
797 VIntConfigControl( _p_this, _p_item )
801 slider->setMaximum( p_item->max.i );
802 slider->setMinimum( p_item->min.i );
803 slider->setValue( p_item->value.i );
804 slider->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
806 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
809 int IntegerRangeSliderConfigControl::getValue()
811 return slider->value();
815 /********* Integer / choice list **********/
816 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
817 module_config_t *_p_item, QWidget *_parent, bool bycat,
818 QGridLayout *l, int &line) :
819 VIntConfigControl( _p_this, _p_item, _parent )
821 label = new QLabel( qtr(p_item->psz_text) );
822 combo = new QComboBox();
823 combo->setMinimumWidth( MINWIDTH_BOX );
827 QHBoxLayout *layout = new QHBoxLayout();
828 layout->addWidget( label ); layout->addWidget( combo, LAST_COLUMN );
829 widget->setLayout( layout );
833 l->addWidget( label, line, 0 );
834 l->addWidget( combo, line, LAST_COLUMN, Qt::AlignRight );
837 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
838 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
839 bool bycat ) : VIntConfigControl( _p_this, _p_item )
846 void IntegerListConfigControl::finish( bool bycat )
848 combo->setEditable( false );
850 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
852 combo->addItem( qtr(p_item->ppsz_list_text[i_index] ),
853 QVariant( p_item->pi_list[i_index] ) );
854 if( p_item->value.i == p_item->pi_list[i_index] )
855 combo->setCurrentIndex( combo->count() - 1 );
857 combo->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
859 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
862 int IntegerListConfigControl::getValue()
864 return combo->itemData( combo->currentIndex() ).toInt();
867 /*********** Boolean **************/
868 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
869 module_config_t *_p_item,
870 QWidget *_parent, QGridLayout *l,
872 VIntConfigControl( _p_this, _p_item, _parent )
874 checkbox = new QCheckBox( qtr(p_item->psz_text) );
879 QHBoxLayout *layout = new QHBoxLayout();
880 layout->addWidget( checkbox, 0 );
881 widget->setLayout( layout );
885 l->addWidget( checkbox, line, 0 );
888 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
889 module_config_t *_p_item,
891 QCheckBox *_checkbox,
893 VIntConfigControl( _p_this, _p_item )
895 checkbox = _checkbox;
899 void BoolConfigControl::finish()
901 checkbox->setCheckState( p_item->value.i == VLC_TRUE ? Qt::Checked
903 checkbox->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
906 int BoolConfigControl::getValue()
908 return checkbox->checkState() == Qt::Checked ? VLC_TRUE : VLC_FALSE;
911 /**************************************************************************
912 * Float-based controls
913 *************************************************************************/
915 /*********** Float **************/
916 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
917 module_config_t *_p_item,
918 QWidget *_parent, QGridLayout *l,
920 VFloatConfigControl( _p_this, _p_item, _parent )
922 label = new QLabel( qtr(p_item->psz_text) );
923 spin = new QDoubleSpinBox;
924 spin->setMinimumWidth( MINWIDTH_BOX );
925 spin->setMaximumWidth( MINWIDTH_BOX );
926 spin->setAlignment( Qt::AlignRight );
931 QHBoxLayout *layout = new QHBoxLayout();
932 layout->addWidget( label, 0 ); layout->addWidget( spin, LAST_COLUMN );
933 widget->setLayout( layout );
937 l->addWidget( label, line, 0 );
938 l->addWidget( spin, line, LAST_COLUMN, Qt::AlignRight );
942 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
943 module_config_t *_p_item,
945 QDoubleSpinBox *_spin ) :
946 VFloatConfigControl( _p_this, _p_item )
953 void FloatConfigControl::finish()
955 spin->setMaximum( 2000000000. );
956 spin->setMinimum( -2000000000. );
957 spin->setSingleStep( 0.1 );
958 spin->setValue( (double)p_item->value.f );
959 spin->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
961 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
964 float FloatConfigControl::getValue()
966 return (float)spin->value();
969 /*********** Float with range **************/
970 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
971 module_config_t *_p_item,
972 QWidget *_parent, QGridLayout *l,
974 FloatConfigControl( _p_this, _p_item, _parent, l, line )
979 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
980 module_config_t *_p_item,
982 QDoubleSpinBox *_spin ) :
983 FloatConfigControl( _p_this, _p_item, _label, _spin )
988 void FloatRangeConfigControl::finish()
990 spin->setMaximum( (double)p_item->max.f );
991 spin->setMinimum( (double)p_item->min.f );
995 /**********************************************************************
996 * Key selector widget
997 **********************************************************************/
998 KeySelectorControl::KeySelectorControl( vlc_object_t *_p_this,
999 module_config_t *_p_item,
1000 QWidget *_parent, QGridLayout *l,
1002 ConfigControl( _p_this, _p_item, _parent )
1005 QWidget *keyContainer = new QWidget;
1006 QGridLayout *gLayout = new QGridLayout( keyContainer );
1009 qtr( "Select an action to change the associated hotkey") );
1011 /* Deactivated for now
1012 QLabel *searchLabel = new QLabel( qtr( "Search" ) );
1013 QLineEdit *actionSearch = new QLineEdit;*/
1015 table = new QTreeWidget;
1016 table->setColumnCount(2);
1017 table->headerItem()->setText( 0, qtr( "Action" ) );
1018 table->headerItem()->setText( 1, qtr( "Shortcut" ) );
1020 shortcutValue = new KeyShortcutEdit;
1021 shortcutValue->setReadOnly(true);
1023 QPushButton *clearButton = new QPushButton( qtr( "Clear" ) );
1024 QPushButton *setButton = new QPushButton( qtr( "Set" ) );
1025 setButton->setDefault( true );
1028 gLayout->addWidget( label, 0, 0, 1, 4 );
1029 /* deactivated for now
1030 gLayout->addWidget( searchLabel, 1, 0, 1, 2 );
1031 gLayout->addWidget( actionSearch, 1, 2, 1, 2 ); */
1032 gLayout->addWidget( table, 2, 0, 1, 4 );
1033 gLayout->addWidget( clearButton, 3, 0, 1, 1 );
1034 gLayout->addWidget( shortcutValue, 3, 1, 1, 2 );
1035 gLayout->addWidget( setButton, 3, 3, 1, 1 );
1037 l->addWidget( keyContainer, line, 0, 1, 2 );
1039 CONNECT( clearButton, clicked(), shortcutValue, clear() );
1040 BUTTONACT( setButton, setTheKey() );
1043 void KeySelectorControl::finish()
1046 label->setToolTip( formatTooltip( qtr( p_item->psz_longtext ) ) );
1048 /* Fill the table */
1049 table->setColumnCount( 2 );
1050 table->setAlternatingRowColors( true );
1052 /* Get the main Module */
1053 module_t *p_main = module_Find( p_this, "main" );
1056 /* Access to the module_config_t */
1058 module_config_t *p_config;
1060 p_config = module_GetConfig (p_main, &confsize);
1062 for (size_t i = 0; i < confsize; i++)
1064 module_config_t *p_item = p_config + i;
1066 /* If we are a key option not empty */
1067 if( p_item->i_type & CONFIG_ITEM && p_item->psz_name
1068 && strstr( p_item->psz_name , "key-" )
1069 && !EMPTY_STR( p_item->psz_text ) )
1073 - QString text in column 0
1074 - QString name in data of column 0
1075 - KeyValue in String in column 1
1076 - KeyValue in int in column 1
1078 QTreeWidgetItem *treeItem = new QTreeWidgetItem();
1079 treeItem->setText( 0, qtr( p_item->psz_text ) );
1080 treeItem->setData( 0, Qt::UserRole,
1081 QVariant( qfu( p_item->psz_name ) ) );
1082 treeItem->setText( 1, VLCKeyToString( p_item->value.i ) );
1083 treeItem->setData( 1, Qt::UserRole, QVariant( p_item->value.i ) );
1084 table->addTopLevelItem( treeItem );
1087 module_PutConfig (p_config);
1088 module_Put (p_main);
1090 table->resizeColumnToContents( 0 );
1092 CONNECT( table, itemClicked( QTreeWidgetItem *, int ),
1093 this, select1Key( QTreeWidgetItem * ) );
1094 CONNECT( table, itemDoubleClicked( QTreeWidgetItem *, int ),
1095 this, selectKey( QTreeWidgetItem * ) );
1096 CONNECT( shortcutValue, pressed(), this, selectKey() );
1099 /* Show the key selected from the table in the keySelector */
1100 void KeySelectorControl::select1Key( QTreeWidgetItem *keyItem )
1102 shortcutValue->setText( keyItem->text( 1 ) );
1103 shortcutValue->setValue( keyItem->data( 1, Qt::UserRole ).toInt() );
1106 void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem )
1108 /* This happens when triggered by ClickEater */
1109 if( keyItem == NULL ) keyItem = table->currentItem();
1111 /* This can happen when nothing is selected on the treeView
1112 and the shortcutValue is clicked */
1113 if( !keyItem ) return;
1115 /* Launch a small dialog to ask for a new key */
1116 KeyInputDialog *d = new KeyInputDialog( table, keyItem->text( 0 ), widget );
1119 if( d->result() == QDialog::Accepted )
1121 int newValue = d->keyValue;
1122 shortcutValue->setText( VLCKeyToString( newValue ) );
1123 shortcutValue->setValue( newValue );
1127 QTreeWidgetItem *it;
1128 for( int i = 0; i < table->topLevelItemCount() ; i++ )
1130 it = table->topLevelItem(i);
1131 if( ( keyItem != it )
1132 && ( it->data( 1, Qt::UserRole ).toInt() == newValue ) )
1134 it->setData( 1, Qt::UserRole, QVariant( -1 ) );
1135 it->setText( 1, qtr( "Unset" ) );
1138 /* We already made an OK once. */
1145 void KeySelectorControl::setTheKey()
1147 table->currentItem()->setText( 1, shortcutValue->text() );
1148 table->currentItem()->setData( 1, Qt::UserRole, shortcutValue->getValue() );
1151 void KeySelectorControl::doApply()
1153 QTreeWidgetItem *it;
1154 for( int i = 0; i < table->topLevelItemCount() ; i++ )
1156 it = table->topLevelItem(i);
1157 if( it->data( 1, Qt::UserRole ).toInt() >= 0 )
1158 config_PutInt( p_this,
1159 qtu( it->data( 0, Qt::UserRole ).toString() ),
1160 it->data( 1, Qt::UserRole ).toInt() );
1164 KeyInputDialog::KeyInputDialog( QTreeWidget *_table,
1165 QString keyToChange,
1166 QWidget *_parent ) :
1167 QDialog( _parent ), keyValue(0)
1173 setWindowTitle( qtr( "Hotkey for " ) + keyToChange );
1175 vLayout = new QVBoxLayout( this );
1176 selected = new QLabel( qtr( "Press the new keys for " ) + keyToChange );
1177 vLayout->addWidget( selected , Qt::AlignCenter );
1179 buttonBox = new QDialogButtonBox;
1180 QPushButton *ok = new QPushButton( qtr("OK") );
1181 QPushButton *cancel = new QPushButton( qtr("Cancel") );
1182 buttonBox->addButton( ok, QDialogButtonBox::AcceptRole );
1183 buttonBox->addButton( cancel, QDialogButtonBox::RejectRole );
1184 ok->setDefault( true );
1186 vLayout->addWidget( buttonBox );
1189 CONNECT( buttonBox, accepted(), this, accept() );
1190 CONNECT( buttonBox, rejected(), this, reject() );
1193 void KeyInputDialog::checkForConflicts( int i_vlckey )
1195 QList<QTreeWidgetItem *> conflictList =
1196 table->findItems( VLCKeyToString( i_vlckey ), Qt::MatchExactly, 1 );
1198 if( conflictList.size() )
1200 QLabel *warning = new QLabel(
1201 qtr("Warning: the key is already assigned to \"") +
1202 conflictList[0]->text( 0 ) + "\"" );
1203 vLayout->insertWidget( 1, warning );
1211 void KeyInputDialog::keyPressEvent( QKeyEvent *e )
1213 if( e->key() == Qt::Key_Tab ||
1214 e->key() == Qt::Key_Shift ||
1215 e->key() == Qt::Key_Control ||
1216 e->key() == Qt::Key_Meta ||
1217 e->key() == Qt::Key_Alt ||
1218 e->key() == Qt::Key_AltGr )
1220 int i_vlck = qtEventToVLCKey( e );
1221 selected->setText( qtr( "Key: " ) + VLCKeyToString( i_vlck ) );
1222 checkForConflicts( i_vlck );
1226 void KeyInputDialog::wheelEvent( QWheelEvent *e )
1228 int i_vlck = qtWheelEventToVLCKey( e );
1229 selected->setText( qtr( "Key: " ) + VLCKeyToString( i_vlck ) );
1230 checkForConflicts( i_vlck );
1234 void KeyShortcutEdit::mousePressEvent( QMouseEvent *)