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"
43 #include <QGridLayout>
45 #include <QFileDialog>
47 #include <QTreeWidgetItem>
48 #include <QSignalMapper>
49 #include <QDialogButtonBox>
51 #define MINWIDTH_BOX 90
52 #define LAST_COLUMN 10
54 QString formatTooltip(const QString & tooltip)
57 "<html><head><meta name=\"qrichtext\" content=\"1\" />"
58 "<style type=\"text/css\"> p, li { white-space: pre-wrap; } </style></head>"
59 "<body style=\" font-family:'Sans Serif'; font-size:9pt; font-weight:400; "
60 "font-style:normal; text-decoration:none;\">"
61 "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; "
62 "margin-right:0px; -qt-block-indent:0; text-indent:0px;\">" +
68 ConfigControl *ConfigControl::createControl( vlc_object_t *p_this,
69 module_config_t *p_item,
73 return createControl( p_this, p_item, parent, NULL, i );
76 ConfigControl *ConfigControl::createControl( vlc_object_t *p_this,
77 module_config_t *p_item,
79 QGridLayout *l, int &line )
81 ConfigControl *p_control = NULL;
83 switch( p_item->i_type )
85 case CONFIG_ITEM_MODULE:
86 p_control = new ModuleConfigControl( p_this, p_item, parent, false,
89 case CONFIG_ITEM_MODULE_CAT:
90 p_control = new ModuleConfigControl( p_this, p_item, parent, true,
93 case CONFIG_ITEM_MODULE_LIST:
94 p_control = new ModuleListConfigControl( p_this, p_item, parent, false,
97 case CONFIG_ITEM_MODULE_LIST_CAT:
98 p_control = new ModuleListConfigControl( p_this, p_item, parent, true,
100 /* Special Hack for a bug in video-filter */
101 if( qobject_cast<ModuleListConfigControl *>( p_control )->groupBox == NULL )
104 case CONFIG_ITEM_STRING:
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, false, l, line );
112 case CONFIG_ITEM_PASSWORD:
113 if( !p_item->i_list )
114 p_control = new StringConfigControl( p_this, p_item, parent,
117 p_control = new StringListConfigControl( p_this, p_item,
118 parent, true, l, line );
120 case CONFIG_ITEM_INTEGER:
122 p_control = new IntegerListConfigControl( p_this, p_item,
123 parent, false, l, line );
124 else if( p_item->min.i || p_item->max.i )
125 p_control = new IntegerRangeConfigControl( p_this, p_item, parent,
128 p_control = new IntegerConfigControl( p_this, p_item, parent,
131 case CONFIG_ITEM_FILE:
132 p_control = new FileConfigControl( p_this, p_item, parent, l,
135 case CONFIG_ITEM_DIRECTORY:
136 p_control = new DirectoryConfigControl( p_this, p_item, parent, l,
140 case CONFIG_ITEM_FONT:
141 p_control = new FontConfigControl( p_this, p_item, parent, l,
145 case CONFIG_ITEM_KEY:
146 p_control = new KeySelectorControl( p_this, p_item, parent, l, line );
148 case CONFIG_ITEM_BOOL:
149 p_control = new BoolConfigControl( p_this, p_item, parent, l, line );
151 case CONFIG_ITEM_FLOAT:
152 if( p_item->min.f || p_item->max.f )
153 p_control = new FloatRangeConfigControl( p_this, p_item, parent,
156 p_control = new FloatConfigControl( p_this, p_item, parent,
165 void ConfigControl::doApply( intf_thread_t *p_intf )
169 case CONFIG_ITEM_INTEGER:
170 case CONFIG_ITEM_BOOL:
172 VIntConfigControl *vicc = qobject_cast<VIntConfigControl *>(this);
174 config_PutInt( p_intf, vicc->getName(), vicc->getValue() );
177 case CONFIG_ITEM_FLOAT:
179 VFloatConfigControl *vfcc =
180 qobject_cast<VFloatConfigControl *>(this);
182 config_PutFloat( p_intf, vfcc->getName(), vfcc->getValue() );
185 case CONFIG_ITEM_STRING:
187 VStringConfigControl *vscc =
188 qobject_cast<VStringConfigControl *>(this);
190 config_PutPsz( p_intf, vscc->getName(), qtu( vscc->getValue() ) );
193 case CONFIG_ITEM_KEY:
195 KeySelectorControl *ksc = qobject_cast<KeySelectorControl *>(this);
202 /**************************************************************************
203 * String-based controls
204 *************************************************************************/
206 /*********** String **************/
207 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
208 module_config_t *_p_item,
209 QWidget *_parent, QGridLayout *l,
210 int &line, bool pwd ) :
211 VStringConfigControl( _p_this, _p_item, _parent )
213 label = new QLabel( qtr(p_item->psz_text) );
214 text = new QLineEdit( qfu(p_item->value.psz) );
215 if( pwd ) text->setEchoMode( QLineEdit::Password );
220 QHBoxLayout *layout = new QHBoxLayout();
221 layout->addWidget( label, 0 ); layout->insertSpacing( 1, 10 );
222 layout->addWidget( text, LAST_COLUMN );
223 widget->setLayout( layout );
227 l->addWidget( label, line, 0 );
228 l->setColumnMinimumWidth( 1, 10 );
229 l->addWidget( text, line, LAST_COLUMN );
233 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
234 module_config_t *_p_item,
235 QLabel *_label, QLineEdit *_text, bool pwd ):
236 VStringConfigControl( _p_this, _p_item )
243 void StringConfigControl::finish()
245 text->setText( qfu(p_item->value.psz) );
246 text->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
248 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
251 /*********** File **************/
252 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
253 module_config_t *_p_item,
254 QWidget *_parent, QGridLayout *l,
255 int &line, bool pwd ) :
256 VStringConfigControl( _p_this, _p_item, _parent )
258 label = new QLabel( qtr(p_item->psz_text) );
259 text = new QLineEdit( qfu(p_item->value.psz) );
260 browse = new QPushButton( qtr( "Browse..." ) );
261 QHBoxLayout *textAndButton = new QHBoxLayout();
262 textAndButton->setMargin( 0 );
263 textAndButton->addWidget( text, 2 );
264 textAndButton->addWidget( browse, 0 );
266 BUTTONACT( browse, updateField() );
272 QHBoxLayout *layout = new QHBoxLayout();
273 layout->addWidget( label, 0 );
274 layout->insertSpacing( 1, 10 );
275 layout->addLayout( textAndButton, LAST_COLUMN );
276 widget->setLayout( layout );
280 l->addWidget( label, line, 0 );
281 l->setColumnMinimumWidth( 1, 10 );
282 l->addLayout( textAndButton, line, LAST_COLUMN );
287 FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
288 module_config_t *_p_item,
289 QLabel *_label, QLineEdit *_text,
290 QPushButton *_button, bool pwd ):
291 VStringConfigControl( _p_this, _p_item )
297 BUTTONACT( browse, updateField() );
302 void FileConfigControl::updateField()
304 QString file = QFileDialog::getOpenFileName( NULL,
305 qtr( "Select File" ), qfu( config_GetHomeDir() ) );
306 if( file.isNull() ) return;
307 text->setText( toNativeSeparators( file ) );
310 void FileConfigControl::finish()
312 text->setText( qfu(p_item->value.psz) );
313 text->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
315 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
318 /********* String / Directory **********/
319 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
320 module_config_t *_p_item, QWidget *_p_widget,
321 QGridLayout *_p_layout, int& _int, bool _pwd ) :
322 FileConfigControl( _p_this, _p_item, _p_widget, _p_layout, _int, _pwd)
325 DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
326 module_config_t *_p_item, QLabel *_p_label,
327 QLineEdit *_p_line, QPushButton *_p_button, bool _pwd ):
328 FileConfigControl( _p_this, _p_item, _p_label, _p_line, _p_button, _pwd)
331 void DirectoryConfigControl::updateField()
333 QString dir = QFileDialog::getExistingDirectory( NULL,
334 qtr( "Select Directory" ),
335 text->text().isEmpty() ?
336 qfu( config_GetHomeDir() ) : text->text(),
337 QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks );
339 if( dir.isNull() ) return;
340 text->setText( toNativeSepNoSlash( dir ) );
344 #include <QFontDialog>
346 /********* String / Font **********/
347 FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
348 module_config_t *_p_item, QWidget *_p_widget,
349 QGridLayout *_p_layout, int& _int, bool _pwd ) :
350 FileConfigControl( _p_this, _p_item, _p_widget, _p_layout, _int, _pwd)
353 FontConfigControl::FontConfigControl( vlc_object_t *_p_this,
354 module_config_t *_p_item, QLabel *_p_label,
355 QLineEdit *_p_line, QPushButton *_p_button, bool _pwd ):
356 FileConfigControl( _p_this, _p_item, _p_label, _p_line, _p_button, _pwd)
359 void FontConfigControl::updateField()
362 QFont font = QFontDialog::getFont( &ok, QFont( text->text() ), NULL );
364 text->setText( font.family() );
368 /********* String / choice list **********/
369 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
370 module_config_t *_p_item, QWidget *_parent, bool bycat,
371 QGridLayout *l, int &line) :
372 VStringConfigControl( _p_this, _p_item, _parent )
374 label = new QLabel( qtr(p_item->psz_text) );
375 combo = new QComboBox();
376 combo->setMinimumWidth( MINWIDTH_BOX );
377 combo->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Preferred );
379 module_config_t *p_module_config = config_FindConfig( p_this, p_item->psz_name );
380 if(p_module_config && p_module_config->pf_update_list)
383 val.psz_string = strdup(p_module_config->value.psz);
385 p_module_config->pf_update_list(p_this, p_item->psz_name, val, val, NULL);
387 // assume in any case that dirty was set to true
388 // because lazy programmes will use the same callback for
389 // this, like the one behind the refresh push button?
390 p_module_config->b_dirty = false;
392 free( val.psz_string );
395 finish( p_module_config, bycat );
398 l = new QGridLayout();
399 l->addWidget( label, 0, 0 ); l->addWidget( combo, 0, LAST_COLUMN );
400 widget->setLayout( l );
404 l->addWidget( label, line, 0 );
405 l->addWidget( combo, line, LAST_COLUMN, Qt::AlignRight );
408 if( p_item->i_action )
410 QSignalMapper *signalMapper = new QSignalMapper(this);
412 /* Some stringLists like Capture listings have action associated */
413 for( int i = 0; i < p_item->i_action; i++ )
415 QPushButton *button =
416 new QPushButton( qfu( p_item->ppsz_action_text[i] ));
417 CONNECT( button, clicked(), signalMapper, map() );
418 signalMapper->setMapping( button, i );
419 l->addWidget( button, line, LAST_COLUMN - p_item->i_action + i,
422 CONNECT( signalMapper, mapped( int ),
423 this, actionRequested( int ) );
427 void StringListConfigControl::actionRequested( int i_action )
429 /* Supplementary check for boundaries */
430 if( i_action < 0 || i_action >= p_item->i_action ) return;
432 module_config_t *p_module_config = config_FindConfig( p_this, getName() );
433 if(!p_module_config) return;
437 qtu( (combo->itemData( combo->currentIndex() ).toString() ) );
439 p_module_config->ppf_action[i_action]( p_this, getName(), val, val, 0 );
441 if( p_module_config->b_dirty )
444 finish( p_module_config, true );
445 p_module_config->b_dirty = false;
448 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
449 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
450 bool bycat ) : VStringConfigControl( _p_this, _p_item )
455 module_config_t *p_module_config = config_FindConfig( p_this, getName() );
457 finish( p_module_config, bycat );
460 void StringListConfigControl::finish(module_config_t *p_module_config, bool bycat )
462 combo->setEditable( false );
464 if(!p_module_config) return;
466 for( int i_index = 0; i_index < p_module_config->i_list; i_index++ )
468 combo->addItem( qfu((p_module_config->ppsz_list_text &&
469 p_module_config->ppsz_list_text[i_index])?
470 p_module_config->ppsz_list_text[i_index] :
471 p_module_config->ppsz_list[i_index] ),
472 QVariant( qfu(p_module_config->ppsz_list[i_index] )) );
473 if( p_item->value.psz && !strcmp( p_module_config->value.psz,
474 p_module_config->ppsz_list[i_index] ) )
475 combo->setCurrentIndex( combo->count() - 1 );
477 combo->setToolTip( formatTooltip(qtr(p_module_config->psz_longtext)) );
479 label->setToolTip( formatTooltip(qtr(p_module_config->psz_longtext)) );
482 QString StringListConfigControl::getValue()
484 return combo->itemData( combo->currentIndex() ).toString();
487 void setfillVLCConfigCombo( const char *configname, intf_thread_t *p_intf,
488 QComboBox *combo, QWidget *parent )
490 module_config_t *p_config =
491 config_FindConfig( VLC_OBJECT(p_intf), configname );
494 if(p_config->pf_update_list)
497 val.i_int = p_config->value.i;
498 p_config->pf_update_list(VLC_OBJECT(p_intf), configname, val, val, NULL);
499 // assume in any case that dirty was set to true
500 // because lazy programmes will use the same callback for
501 // this, like the one behind the refresh push button?
502 p_config->b_dirty = false;
505 for ( int i_index = 0; i_index < p_config->i_list; i_index++ )
507 combo->addItem( qfu( p_config->ppsz_list_text[i_index] ),
508 QVariant( p_config->pi_list[i_index] ) );
509 if( p_config->value.i == p_config->pi_list[i_index] )
511 combo->setCurrentIndex( i_index );
514 combo->setToolTip( qfu( p_config->psz_longtext ) );
518 /********* Module **********/
519 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
520 module_config_t *_p_item, QWidget *_parent, bool bycat,
521 QGridLayout *l, int &line) :
522 VStringConfigControl( _p_this, _p_item, _parent )
524 label = new QLabel( qtr(p_item->psz_text) );
525 combo = new QComboBox();
526 combo->setMinimumWidth( MINWIDTH_BOX );
530 QHBoxLayout *layout = new QHBoxLayout();
531 layout->addWidget( label ); layout->addWidget( combo, LAST_COLUMN );
532 widget->setLayout( layout );
536 l->addWidget( label, line, 0 );
537 l->addWidget( combo, line, LAST_COLUMN, Qt::AlignRight );
541 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
542 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
543 bool bycat ) : VStringConfigControl( _p_this, _p_item )
550 void ModuleConfigControl::finish( bool bycat )
554 combo->setEditable( false );
556 /* build a list of available modules */
557 module_t **p_list = module_list_get( NULL );
558 combo->addItem( qtr("Default") );
559 for( size_t i = 0; (p_parser = p_list[i]) != NULL; i++ )
563 if( !strcmp( module_get_object( p_parser ), "main" ) ) continue;
566 module_config_t *p_config;
568 p_config = module_config_get (p_parser, &confsize);
569 for (size_t i = 0; i < confsize; i++)
571 /* Hack: required subcategory is stored in i_min */
572 const module_config_t *p_cfg = p_config + i;
573 if( p_cfg->i_type == CONFIG_SUBCATEGORY &&
574 p_cfg->value.i == p_item->min.i )
575 combo->addItem( qtr( module_GetLongName( p_parser )),
576 QVariant( module_get_object( p_parser ) ) );
577 if( p_item->value.psz && !strcmp( p_item->value.psz,
578 module_get_object( p_parser ) ) )
579 combo->setCurrentIndex( combo->count() - 1 );
581 module_config_free (p_config);
583 else if( module_provides( p_parser, p_item->psz_type ) )
585 combo->addItem( qtr(module_GetLongName( p_parser ) ),
586 QVariant( module_get_object( p_parser ) ) );
587 if( p_item->value.psz && !strcmp( p_item->value.psz,
588 module_get_object( p_parser ) ) )
589 combo->setCurrentIndex( combo->count() - 1 );
592 module_list_free( p_list );
593 combo->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
595 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
598 QString ModuleConfigControl::getValue()
600 return combo->itemData( combo->currentIndex() ).toString();
603 /********* Module list **********/
604 ModuleListConfigControl::ModuleListConfigControl( vlc_object_t *_p_this,
605 module_config_t *_p_item, QWidget *_parent, bool bycat,
606 QGridLayout *l, int &line) :
607 VStringConfigControl( _p_this, _p_item, _parent )
611 if( !p_item->psz_text ) return;
613 groupBox = new QGroupBox ( qtr(p_item->psz_text), _parent );
614 text = new QLineEdit;
615 QGridLayout *layoutGroupBox = new QGridLayout( groupBox );
620 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
621 it != modules.end(); it++ )
623 layoutGroupBox->addWidget( (*it)->checkBox, boxline++, 0 );
625 layoutGroupBox->addWidget( text, boxline, 0 );
629 QVBoxLayout *layout = new QVBoxLayout();
630 layout->addWidget( groupBox, line, 0 );
631 widget->setLayout( layout );
635 l->addWidget( groupBox, line, 0, 1, -1 );
638 text->setToolTip( formatTooltip( qtr( p_item->psz_longtext) ) );
641 ModuleListConfigControl::~ModuleListConfigControl()
643 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
644 it != modules.end(); it++ )
651 #define CHECKBOX_LISTS \
653 QCheckBox *cb = new QCheckBox( qtr( module_GetLongName( p_parser ) ) );\
654 checkBoxListItem *cbl = new checkBoxListItem; \
656 CONNECT( cb, stateChanged( int ), this, onUpdate( int ) );\
657 cb->setToolTip( formatTooltip( qtr( module_get_help( p_parser ))));\
658 cbl->checkBox = cb; \
660 cbl->psz_module = strdup( module_get_object( p_parser ) ); \
661 modules.push_back( cbl ); \
663 if( p_item->value.psz && strstr( p_item->value.psz, cbl->psz_module ) ) \
664 cbl->checkBox->setChecked( true ); \
668 void ModuleListConfigControl::finish( bool bycat )
672 /* build a list of available modules */
673 module_t **p_list = module_list_get( NULL );
674 for( size_t i = 0; (p_parser = p_list[i]) != NULL; i++ )
678 if( !strcmp( module_get_object( p_parser ), "main" ) ) continue;
681 module_config_t *p_config = module_config_get (p_parser, &confsize);
683 for (size_t i = 0; i < confsize; i++)
685 module_config_t *p_cfg = p_config + i;
686 /* Hack: required subcategory is stored in i_min */
687 if( p_cfg->i_type == CONFIG_SUBCATEGORY &&
688 p_cfg->value.i == p_item->min.i )
693 module_config_free (p_config);
695 else if( module_provides( p_parser, p_item->psz_type ) )
700 module_list_free( p_list );
701 text->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
703 groupBox->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
705 #undef CHECKBOX_LISTS
707 QString ModuleListConfigControl::getValue()
713 void ModuleListConfigControl::hide()
715 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
716 it != modules.end(); it++ )
718 (*it)->checkBox->hide();
723 void ModuleListConfigControl::show()
725 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
726 it != modules.end(); it++ )
728 (*it)->checkBox->show();
734 void ModuleListConfigControl::onUpdate( int value )
739 for( QVector<checkBoxListItem*>::iterator it = modules.begin();
740 it != modules.end(); it++ )
742 if( (*it)->checkBox->isChecked() )
746 text->setText( text->text() + (*it)->psz_module );
751 text->setText( text->text() + ":" + (*it)->psz_module );
757 /**************************************************************************
758 * Integer-based controls
759 *************************************************************************/
761 /*********** Integer **************/
762 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
763 module_config_t *_p_item,
764 QWidget *_parent, QGridLayout *l,
766 VIntConfigControl( _p_this, _p_item, _parent )
768 label = new QLabel( qtr(p_item->psz_text) );
769 spin = new QSpinBox; spin->setMinimumWidth( MINWIDTH_BOX );
770 spin->setAlignment( Qt::AlignRight );
771 spin->setMaximumWidth( MINWIDTH_BOX );
776 QHBoxLayout *layout = new QHBoxLayout();
777 layout->addWidget( label, 0 ); layout->addWidget( spin, LAST_COLUMN );
778 widget->setLayout( layout );
782 l->addWidget( label, line, 0 );
783 l->addWidget( spin, line, LAST_COLUMN, Qt::AlignRight );
786 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
787 module_config_t *_p_item,
788 QLabel *_label, QSpinBox *_spin ) :
789 VIntConfigControl( _p_this, _p_item )
796 void IntegerConfigControl::finish()
798 spin->setMaximum( 2000000000 );
799 spin->setMinimum( -2000000000 );
800 spin->setValue( p_item->value.i );
801 spin->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
803 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
806 int IntegerConfigControl::getValue()
808 return spin->value();
811 /********* Integer range **********/
812 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
813 module_config_t *_p_item,
814 QWidget *_parent, QGridLayout *l,
816 IntegerConfigControl( _p_this, _p_item, _parent, l, line )
821 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
822 module_config_t *_p_item,
823 QLabel *_label, QSpinBox *_spin ) :
824 IntegerConfigControl( _p_this, _p_item, _label, _spin )
829 void IntegerRangeConfigControl::finish()
831 spin->setMaximum( p_item->max.i );
832 spin->setMinimum( p_item->min.i );
835 IntegerRangeSliderConfigControl::IntegerRangeSliderConfigControl(
836 vlc_object_t *_p_this,
837 module_config_t *_p_item,
838 QLabel *_label, QSlider *_slider ):
839 VIntConfigControl( _p_this, _p_item )
843 slider->setMaximum( p_item->max.i );
844 slider->setMinimum( p_item->min.i );
845 slider->setValue( p_item->value.i );
846 slider->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
848 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
851 int IntegerRangeSliderConfigControl::getValue()
853 return slider->value();
857 /********* Integer / choice list **********/
858 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
859 module_config_t *_p_item, QWidget *_parent, bool bycat,
860 QGridLayout *l, int &line) :
861 VIntConfigControl( _p_this, _p_item, _parent )
863 label = new QLabel( qtr(p_item->psz_text) );
864 combo = new QComboBox();
865 combo->setMinimumWidth( MINWIDTH_BOX );
867 module_config_t *p_module_config = config_FindConfig( p_this, p_item->psz_name );
868 if(p_module_config && p_module_config->pf_update_list)
871 val.i_int = p_module_config->value.i;
873 p_module_config->pf_update_list(p_this, p_item->psz_name, val, val, NULL);
875 // assume in any case that dirty was set to true
876 // because lazy programmes will use the same callback for
877 // this, like the one behind the refresh push button?
878 p_module_config->b_dirty = false;
882 finish( p_module_config, bycat );
885 QHBoxLayout *layout = new QHBoxLayout();
886 layout->addWidget( label ); layout->addWidget( combo, LAST_COLUMN );
887 widget->setLayout( layout );
891 l->addWidget( label, line, 0 );
892 l->addWidget( combo, line, LAST_COLUMN, Qt::AlignRight );
895 if( p_item->i_action )
897 QSignalMapper *signalMapper = new QSignalMapper(this);
899 /* Some stringLists like Capture listings have action associated */
900 for( int i = 0; i < p_item->i_action; i++ )
902 QPushButton *button =
903 new QPushButton( qfu( p_item->ppsz_action_text[i] ));
904 CONNECT( button, clicked(), signalMapper, map() );
905 signalMapper->setMapping( button, i );
906 l->addWidget( button, line, LAST_COLUMN - p_item->i_action + i,
909 CONNECT( signalMapper, mapped( int ),
910 this, actionRequested( int ) );
914 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
915 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
916 bool bycat ) : VIntConfigControl( _p_this, _p_item )
921 module_config_t *p_module_config = config_FindConfig( p_this, getName() );
923 finish( p_module_config, bycat );
926 void IntegerListConfigControl::finish(module_config_t *p_module_config, bool bycat )
928 combo->setEditable( false );
930 if(!p_module_config) return;
932 for( int i_index = 0; i_index < p_module_config->i_list; i_index++ )
934 combo->addItem( qtr(p_module_config->ppsz_list_text[i_index] ),
935 QVariant( p_module_config->pi_list[i_index] ) );
936 if( p_module_config->value.i == p_module_config->pi_list[i_index] )
937 combo->setCurrentIndex( combo->count() - 1 );
939 combo->setToolTip( formatTooltip(qtr(p_module_config->psz_longtext)) );
941 label->setToolTip( formatTooltip(qtr(p_module_config->psz_longtext)) );
944 void IntegerListConfigControl::actionRequested( int i_action )
946 /* Supplementary check for boundaries */
947 if( i_action < 0 || i_action >= p_item->i_action ) return;
949 module_config_t *p_module_config = config_FindConfig( p_this, getName() );
950 if(!p_module_config) return;
954 val.i_int = combo->itemData( combo->currentIndex() ).toInt();
956 p_module_config->ppf_action[i_action]( p_this, getName(), val, val, 0 );
958 if( p_module_config->b_dirty )
961 finish( p_module_config, true );
962 p_module_config->b_dirty = false;
966 int IntegerListConfigControl::getValue()
968 return combo->itemData( combo->currentIndex() ).toInt();
971 /*********** Boolean **************/
972 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
973 module_config_t *_p_item,
974 QWidget *_parent, QGridLayout *l,
976 VIntConfigControl( _p_this, _p_item, _parent )
978 checkbox = new QCheckBox( qtr(p_item->psz_text) );
983 QHBoxLayout *layout = new QHBoxLayout();
984 layout->addWidget( checkbox, 0 );
985 widget->setLayout( layout );
989 l->addWidget( checkbox, line, 0 );
992 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
993 module_config_t *_p_item,
995 QCheckBox *_checkbox,
997 VIntConfigControl( _p_this, _p_item )
999 checkbox = _checkbox;
1003 void BoolConfigControl::finish()
1005 checkbox->setCheckState( p_item->value.i == true ? Qt::Checked
1007 checkbox->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
1010 int BoolConfigControl::getValue()
1012 return checkbox->checkState() == Qt::Checked ? true : false;
1015 /**************************************************************************
1016 * Float-based controls
1017 *************************************************************************/
1019 /*********** Float **************/
1020 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
1021 module_config_t *_p_item,
1022 QWidget *_parent, QGridLayout *l,
1024 VFloatConfigControl( _p_this, _p_item, _parent )
1026 label = new QLabel( qtr(p_item->psz_text) );
1027 spin = new QDoubleSpinBox;
1028 spin->setMinimumWidth( MINWIDTH_BOX );
1029 spin->setMaximumWidth( MINWIDTH_BOX );
1030 spin->setAlignment( Qt::AlignRight );
1035 QHBoxLayout *layout = new QHBoxLayout();
1036 layout->addWidget( label, 0 ); layout->addWidget( spin, LAST_COLUMN );
1037 widget->setLayout( layout );
1041 l->addWidget( label, line, 0 );
1042 l->addWidget( spin, line, LAST_COLUMN, Qt::AlignRight );
1046 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
1047 module_config_t *_p_item,
1049 QDoubleSpinBox *_spin ) :
1050 VFloatConfigControl( _p_this, _p_item )
1057 void FloatConfigControl::finish()
1059 spin->setMaximum( 2000000000. );
1060 spin->setMinimum( -2000000000. );
1061 spin->setSingleStep( 0.1 );
1062 spin->setValue( (double)p_item->value.f );
1063 spin->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
1065 label->setToolTip( formatTooltip(qtr(p_item->psz_longtext)) );
1068 float FloatConfigControl::getValue()
1070 return (float)spin->value();
1073 /*********** Float with range **************/
1074 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
1075 module_config_t *_p_item,
1076 QWidget *_parent, QGridLayout *l,
1078 FloatConfigControl( _p_this, _p_item, _parent, l, line )
1083 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
1084 module_config_t *_p_item,
1086 QDoubleSpinBox *_spin ) :
1087 FloatConfigControl( _p_this, _p_item, _label, _spin )
1092 void FloatRangeConfigControl::finish()
1094 spin->setMaximum( (double)p_item->max.f );
1095 spin->setMinimum( (double)p_item->min.f );
1099 /**********************************************************************
1100 * Key selector widget
1101 **********************************************************************/
1102 KeySelectorControl::KeySelectorControl( vlc_object_t *_p_this,
1103 module_config_t *_p_item,
1104 QWidget *_parent, QGridLayout *l,
1106 ConfigControl( _p_this, _p_item, _parent )
1109 QWidget *keyContainer = new QWidget;
1110 QGridLayout *gLayout = new QGridLayout( keyContainer );
1113 qtr( "Select an action to change the associated hotkey") );
1115 /* Deactivated for now
1116 QLabel *searchLabel = new QLabel( qtr( "Search" ) );
1117 QLineEdit *actionSearch = new QLineEdit;*/
1119 table = new QTreeWidget;
1120 table->setColumnCount(2);
1121 table->headerItem()->setText( 0, qtr( "Action" ) );
1122 table->headerItem()->setText( 1, qtr( "Shortcut" ) );
1124 shortcutValue = new KeyShortcutEdit;
1125 shortcutValue->setReadOnly(true);
1127 QPushButton *clearButton = new QPushButton( qtr( "Clear" ) );
1128 QPushButton *setButton = new QPushButton( qtr( "Set" ) );
1129 setButton->setDefault( true );
1132 gLayout->addWidget( label, 0, 0, 1, 4 );
1133 /* deactivated for now
1134 gLayout->addWidget( searchLabel, 1, 0, 1, 2 );
1135 gLayout->addWidget( actionSearch, 1, 2, 1, 2 ); */
1136 gLayout->addWidget( table, 2, 0, 1, 4 );
1137 gLayout->addWidget( clearButton, 3, 0, 1, 1 );
1138 gLayout->addWidget( shortcutValue, 3, 1, 1, 2 );
1139 gLayout->addWidget( setButton, 3, 3, 1, 1 );
1141 l->addWidget( keyContainer, line, 0, 1, 2 );
1143 CONNECT( clearButton, clicked(), shortcutValue, clear() );
1144 CONNECT( clearButton, clicked(), this, setTheKey() );
1145 BUTTONACT( setButton, setTheKey() );
1148 void KeySelectorControl::finish()
1151 label->setToolTip( formatTooltip( qtr( p_item->psz_longtext ) ) );
1153 /* Fill the table */
1154 table->setColumnCount( 2 );
1155 table->setAlternatingRowColors( true );
1157 /* Get the main Module */
1158 module_t *p_main = module_find( p_this, "main" );
1161 /* Access to the module_config_t */
1163 module_config_t *p_config;
1165 p_config = module_config_get (p_main, &confsize);
1167 for (size_t i = 0; i < confsize; i++)
1169 module_config_t *p_item = p_config + i;
1171 /* If we are a key option not empty */
1172 if( p_item->i_type & CONFIG_ITEM && p_item->psz_name
1173 && strstr( p_item->psz_name , "key-" )
1174 && !EMPTY_STR( p_item->psz_text ) )
1178 - QString text in column 0
1179 - QString name in data of column 0
1180 - KeyValue in String in column 1
1181 - KeyValue in int in column 1
1183 QTreeWidgetItem *treeItem = new QTreeWidgetItem();
1184 treeItem->setText( 0, qtr( p_item->psz_text ) );
1185 treeItem->setData( 0, Qt::UserRole,
1186 QVariant( qfu( p_item->psz_name ) ) );
1187 treeItem->setText( 1, VLCKeyToString( p_item->value.i ) );
1188 treeItem->setData( 1, Qt::UserRole, QVariant( p_item->value.i ) );
1189 table->addTopLevelItem( treeItem );
1192 module_config_free (p_config);
1193 module_release (p_main);
1195 table->resizeColumnToContents( 0 );
1197 CONNECT( table, itemDoubleClicked( QTreeWidgetItem *, int ),
1198 this, selectKey( QTreeWidgetItem * ) );
1199 CONNECT( table, itemSelectionChanged (),
1200 this, select1Key() );
1202 CONNECT( shortcutValue, pressed(), this, selectKey() );
1205 /* Show the key selected from the table in the keySelector */
1206 void KeySelectorControl::select1Key()
1208 QTreeWidgetItem *keyItem = table->currentItem();
1209 shortcutValue->setText( keyItem->text( 1 ) );
1210 shortcutValue->setValue( keyItem->data( 1, Qt::UserRole ).toInt() );
1213 void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem )
1215 /* This happens when triggered by ClickEater */
1216 if( keyItem == NULL ) keyItem = table->currentItem();
1218 /* This can happen when nothing is selected on the treeView
1219 and the shortcutValue is clicked */
1220 if( !keyItem ) return;
1222 /* Launch a small dialog to ask for a new key */
1223 KeyInputDialog *d = new KeyInputDialog( table, keyItem->text( 0 ), widget );
1226 if( d->result() == QDialog::Accepted )
1228 int newValue = d->keyValue;
1229 shortcutValue->setText( VLCKeyToString( newValue ) );
1230 shortcutValue->setValue( newValue );
1234 QTreeWidgetItem *it;
1235 for( int i = 0; i < table->topLevelItemCount() ; i++ )
1237 it = table->topLevelItem(i);
1238 if( ( keyItem != it )
1239 && ( it->data( 1, Qt::UserRole ).toInt() == newValue ) )
1241 it->setData( 1, Qt::UserRole, QVariant( -1 ) );
1242 it->setText( 1, qtr( "Unset" ) );
1245 /* We already made an OK once. */
1252 void KeySelectorControl::setTheKey()
1254 table->currentItem()->setText( 1, shortcutValue->text() );
1255 table->currentItem()->setData( 1, Qt::UserRole, shortcutValue->getValue() );
1258 void KeySelectorControl::doApply()
1260 QTreeWidgetItem *it;
1261 for( int i = 0; i < table->topLevelItemCount() ; i++ )
1263 it = table->topLevelItem(i);
1264 if( it->data( 1, Qt::UserRole ).toInt() >= 0 )
1265 config_PutInt( p_this,
1266 qtu( it->data( 0, Qt::UserRole ).toString() ),
1267 it->data( 1, Qt::UserRole ).toInt() );
1271 KeyInputDialog::KeyInputDialog( QTreeWidget *_table,
1272 QString keyToChange,
1273 QWidget *_parent ) :
1274 QDialog( _parent ), keyValue(0)
1280 setWindowTitle( qtr( "Hotkey for " ) + keyToChange );
1282 vLayout = new QVBoxLayout( this );
1283 selected = new QLabel( qtr( "Press the new keys for " ) + keyToChange );
1284 vLayout->addWidget( selected , Qt::AlignCenter );
1286 buttonBox = new QDialogButtonBox;
1287 QPushButton *ok = new QPushButton( qtr("OK") );
1288 QPushButton *cancel = new QPushButton( qtr("Cancel") );
1289 buttonBox->addButton( ok, QDialogButtonBox::AcceptRole );
1290 buttonBox->addButton( cancel, QDialogButtonBox::RejectRole );
1291 ok->setDefault( true );
1293 vLayout->addWidget( buttonBox );
1296 CONNECT( buttonBox, accepted(), this, accept() );
1297 CONNECT( buttonBox, rejected(), this, reject() );
1300 void KeyInputDialog::checkForConflicts( int i_vlckey )
1302 QList<QTreeWidgetItem *> conflictList =
1303 table->findItems( VLCKeyToString( i_vlckey ), Qt::MatchExactly, 1 );
1305 if( conflictList.size() )
1307 QLabel *warning = new QLabel(
1308 qtr("Warning: the key is already assigned to \"") +
1309 conflictList[0]->text( 0 ) + "\"" );
1310 vLayout->insertWidget( 1, warning );
1318 void KeyInputDialog::keyPressEvent( QKeyEvent *e )
1320 if( e->key() == Qt::Key_Tab ||
1321 e->key() == Qt::Key_Shift ||
1322 e->key() == Qt::Key_Control ||
1323 e->key() == Qt::Key_Meta ||
1324 e->key() == Qt::Key_Alt ||
1325 e->key() == Qt::Key_AltGr )
1327 int i_vlck = qtEventToVLCKey( e );
1328 selected->setText( qtr( "Key: " ) + VLCKeyToString( i_vlck ) );
1329 checkForConflicts( i_vlck );
1333 void KeyInputDialog::wheelEvent( QWheelEvent *e )
1335 int i_vlck = qtWheelEventToVLCKey( e );
1336 selected->setText( qtr( "Key: " ) + VLCKeyToString( i_vlck ) );
1337 checkForConflicts( i_vlck );
1341 void KeyShortcutEdit::mousePressEvent( QMouseEvent *)