1 /*****************************************************************************
2 * preferences_widgets.cpp : Widgets for preferences displays
3 ****************************************************************************
4 * Copyright (C) 2006 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
8 * Antoine Cellerier <dionoea@videolan.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
27 * - Finish implementation (see WX)
28 * - Improvements over WX
29 * - Password field implementation (through "pwd" bool param
30 * - Validator for modulelist
31 * - Implement update stuff using a general Updated signal
34 #include "components/preferences_widgets.hpp"
39 #include <QDoubleSpinBox>
42 #include <QGridLayout>
44 ConfigControl *ConfigControl::createControl( vlc_object_t *p_this,
45 module_config_t *p_item,
49 return createControl( p_this, p_item, parent, NULL, i );
52 ConfigControl *ConfigControl::createControl( vlc_object_t *p_this,
53 module_config_t *p_item,
55 QGridLayout *l, int &line )
57 ConfigControl *p_control = NULL;
58 if( p_item->psz_current ) return NULL;
60 switch( p_item->i_type )
62 case CONFIG_ITEM_MODULE:
63 p_control = new ModuleConfigControl( p_this, p_item, parent, false,
66 case CONFIG_ITEM_MODULE_CAT:
67 p_control = new ModuleConfigControl( p_this, p_item, parent, true,
70 case CONFIG_ITEM_MODULE_LIST:
71 p_control = new ModuleListConfigControl( p_this, p_item, parent, false,
74 case CONFIG_ITEM_MODULE_LIST_CAT:
75 p_control = new ModuleListConfigControl( p_this, p_item, parent, true,
78 case CONFIG_ITEM_STRING:
80 p_control = new StringConfigControl( p_this, p_item, parent,
83 p_control = new StringListConfigControl( p_this, p_item,
84 parent, false, l, line );
86 case CONFIG_ITEM_INTEGER:
88 p_control = new IntegerListConfigControl( p_this, p_item,
89 parent, false, l, line );
90 else if( p_item->i_min || p_item->i_max )
91 p_control = new IntegerRangeConfigControl( p_this, p_item, parent,
94 p_control = new IntegerConfigControl( p_this, p_item, parent,
97 case CONFIG_ITEM_FILE:
98 fprintf( stderr, "Todo (CONFIG_ITEM_FILE)\n" );
100 case CONFIG_ITEM_DIRECTORY:
101 fprintf( stderr, "Todo (CONFIG_ITEM_DIRECTORY)\n" );
103 case CONFIG_ITEM_BOOL:
104 p_control = new BoolConfigControl( p_this, p_item, parent, l, line );
106 case CONFIG_ITEM_FLOAT:
107 if( p_item->f_min || p_item->f_max )
108 p_control = new FloatRangeConfigControl( p_this, p_item, parent,
111 p_control = new FloatConfigControl( p_this, p_item, parent,
120 void ConfigControl::doApply( intf_thread_t *p_intf )
126 VIntConfigControl *vicc = qobject_cast<VIntConfigControl *>(this);
127 config_PutInt( p_intf, vicc->getName(), vicc->getValue() );
132 VFloatConfigControl *vfcc =
133 qobject_cast<VFloatConfigControl *>(this);
134 config_PutFloat( p_intf, vfcc->getName(), vfcc->getValue() );
139 VStringConfigControl *vscc =
140 qobject_cast<VStringConfigControl *>(this);
141 config_PutPsz( p_intf, vscc->getName(), qta( vscc->getValue() ) );
146 /**************************************************************************
147 * String-based controls
148 *************************************************************************/
150 /*********** String **************/
151 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
152 module_config_t *_p_item,
153 QWidget *_parent, QGridLayout *l,
154 int &line, bool pwd ) :
155 VStringConfigControl( _p_this, _p_item, _parent )
157 label = new QLabel( qfu(p_item->psz_text) );
158 text = new QLineEdit( qfu(p_item->psz_value) );
163 QHBoxLayout *layout = new QHBoxLayout();
164 layout->addWidget( label, 0 ); layout->addWidget( text, 1 );
165 widget->setLayout( layout );
169 l->addWidget( label, line, 0 ); l->addWidget( text, line, 1 );
173 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
174 module_config_t *_p_item,
175 QLabel *_label, QLineEdit *_text, bool pwd ):
176 VStringConfigControl( _p_this, _p_item )
183 void StringConfigControl::finish()
185 text->setText( qfu(p_item->psz_value) );
186 text->setToolTip( qfu(p_item->psz_longtext) );
188 label->setToolTip( qfu(p_item->psz_longtext) );
191 /********* String / choice list **********/
192 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
193 module_config_t *_p_item, QWidget *_parent, bool bycat,
194 QGridLayout *l, int &line) :
195 VStringConfigControl( _p_this, _p_item, _parent )
197 label = new QLabel( qfu(p_item->psz_text) );
198 combo = new QComboBox();
202 QHBoxLayout *layout = new QHBoxLayout();
203 layout->addWidget( label ); layout->addWidget( combo );
204 widget->setLayout( layout );
208 l->addWidget( label, line, 0 );
209 l->addWidget( combo, line, 1, Qt::AlignRight );
212 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
213 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
214 bool bycat ) : VStringConfigControl( _p_this, _p_item )
221 void StringListConfigControl::finish( bool bycat )
223 combo->setEditable( false );
225 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
227 combo->addItem( qfu(p_item->ppsz_list_text ?
228 p_item->ppsz_list_text[i_index] :
229 p_item->ppsz_list[i_index] ),
230 QVariant( p_item->ppsz_list[i_index] ) );
231 if( p_item->psz_value && !strcmp( p_item->psz_value,
232 p_item->ppsz_list[i_index] ) )
233 combo->setCurrentIndex( combo->count() - 1 );
235 combo->setToolTip( qfu(p_item->psz_longtext) );
237 label->setToolTip( qfu(p_item->psz_longtext) );
240 QString StringListConfigControl::getValue()
242 return combo->itemData( combo->currentIndex() ).toString();
245 /********* Module **********/
246 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
247 module_config_t *_p_item, QWidget *_parent, bool bycat,
248 QGridLayout *l, int &line) :
249 VStringConfigControl( _p_this, _p_item, _parent )
251 label = new QLabel( qfu(p_item->psz_text) );
252 combo = new QComboBox();
256 QHBoxLayout *layout = new QHBoxLayout();
257 layout->addWidget( label ); layout->addWidget( combo );
258 widget->setLayout( layout );
262 l->addWidget( label, line, 0 );
263 l->addWidget( combo, line, 1, Qt::AlignRight );
266 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
267 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
268 bool bycat ) : VStringConfigControl( _p_this, _p_item )
275 void ModuleConfigControl::finish( bool bycat )
280 combo->setEditable( false );
282 /* build a list of available modules */
283 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
284 combo->addItem( qtr("Default") );
285 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
287 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
291 if( !strcmp( p_parser->psz_object_name, "main" ) ) continue;
293 module_config_t *p_config = p_parser->p_config;
296 /* Hack: required subcategory is stored in i_min */
297 if( p_config->i_type == CONFIG_SUBCATEGORY &&
298 p_config->i_value == p_item->i_min )
299 combo->addItem( qfu(p_parser->psz_longname),
300 QVariant( p_parser->psz_object_name ) );
301 if( p_item->psz_value && !strcmp( p_item->psz_value,
302 p_parser->psz_object_name) )
303 combo->setCurrentIndex( combo->count() - 1 );
304 } while( p_config->i_type != CONFIG_HINT_END && p_config++ );
306 else if( !strcmp( p_parser->psz_capability, p_item->psz_type ) )
308 combo->addItem( qfu(p_parser->psz_longname),
309 QVariant( p_parser->psz_object_name ) );
310 if( p_item->psz_value && !strcmp( p_item->psz_value,
311 p_parser->psz_object_name) )
312 combo->setCurrentIndex( combo->count() - 1 );
315 vlc_list_release( p_list );
316 combo->setToolTip( qfu(p_item->psz_longtext) );
318 label->setToolTip( qfu(p_item->psz_longtext) );
321 QString ModuleConfigControl::getValue()
323 return combo->itemData( combo->currentIndex() ).toString();
326 /********* Module list **********/
327 ModuleListConfigControl::ModuleListConfigControl( vlc_object_t *_p_this,
328 module_config_t *_p_item, QWidget *_parent, bool bycat,
329 QGridLayout *l, int &line) :
330 VStringConfigControl( _p_this, _p_item, _parent )
332 label = new QLabel( qfu(p_item->psz_text) );
333 text = new QLineEdit();
339 l = new QGridLayout();
343 for( QVector<QCheckBox*>::iterator it = modules.begin();
344 it != modules.end(); it++ )
346 l->addWidget( *it, line++, 1 );
348 l->addWidget( label, line, 0 );
349 l->addWidget( text, line, 1 );
351 widget->setLayout( l );
354 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
355 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
356 bool bycat ) : VStringConfigControl( _p_this, _p_item )
364 ModuleListConfigControl::~ModuleListConfigControl()
366 for( QVector<QCheckBox*>::iterator it = modules.begin();
367 it != modules.end(); it++ )
375 void ModuleListConfigControl::finish( bool bycat )
380 /* build a list of available modules */
381 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
382 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
384 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
388 if( !strcmp( p_parser->psz_object_name, "main" ) ) continue;
390 module_config_t *p_config = p_parser->p_config;
393 /* Hack: required subcategory is stored in i_min */
394 if( p_config->i_type == CONFIG_SUBCATEGORY &&
395 p_config->i_value == p_item->i_min )
398 new QCheckBox( qfu( p_parser->psz_object_name ) );
399 cb->setToolTip( qfu(p_parser->psz_longname) );
400 modules.push_back( cb );
402 } while( p_config->i_type != CONFIG_HINT_END && p_config++ );
404 else if( !strcmp( p_parser->psz_capability, p_item->psz_type ) )
407 new QCheckBox( qfu( p_parser->psz_object_name ) );
408 cb->setToolTip( qfu(p_parser->psz_longname) );
409 modules.push_back( cb );
412 vlc_list_release( p_list );
413 text->setToolTip( qfu(p_item->psz_longtext) );
415 label->setToolTip( qfu(p_item->psz_longtext) );
418 QString ModuleListConfigControl::getValue()
423 void ModuleListConfigControl::hide()
425 for( QVector<QCheckBox*>::iterator it = modules.begin();
426 it != modules.end(); it++ )
434 void ModuleListConfigControl::show()
436 for( QVector<QCheckBox*>::iterator it = modules.begin();
437 it != modules.end(); it++ )
446 void ModuleListConfigControl::wakeUp_TheUserJustClickedOnSomething( int value )
449 for( QVector<QCheckBox*>::iterator it = modules.begin();
450 it != modules.end(); it++ )
455 /**************************************************************************
456 * Integer-based controls
457 *************************************************************************/
459 /*********** Integer **************/
460 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
461 module_config_t *_p_item,
462 QWidget *_parent, QGridLayout *l,
464 VIntConfigControl( _p_this, _p_item, _parent )
466 label = new QLabel( qfu(p_item->psz_text) );
467 spin = new QSpinBox; spin->setMinimumWidth( 80 );
468 spin->setMaximumWidth( 90 );
473 QHBoxLayout *layout = new QHBoxLayout();
474 layout->addWidget( label, 0 ); layout->addWidget( spin, 1 );
475 widget->setLayout( layout );
479 l->addWidget( label, line, 0 );
480 l->addWidget( spin, line, 1, Qt::AlignRight );
483 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
484 module_config_t *_p_item,
485 QLabel *_label, QSpinBox *_spin ) :
486 VIntConfigControl( _p_this, _p_item )
493 void IntegerConfigControl::finish()
495 spin->setMaximum( 2000000000 );
496 spin->setMinimum( -2000000000 );
497 spin->setValue( p_item->i_value );
498 spin->setToolTip( qfu(p_item->psz_longtext) );
500 label->setToolTip( qfu(p_item->psz_longtext) );
503 int IntegerConfigControl::getValue()
505 return spin->value();
508 /********* Integer range **********/
509 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
510 module_config_t *_p_item,
511 QWidget *_parent, QGridLayout *l,
513 IntegerConfigControl( _p_this, _p_item, _parent, l, line )
518 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
519 module_config_t *_p_item,
520 QLabel *_label, QSpinBox *_spin ) :
521 IntegerConfigControl( _p_this, _p_item, _label, _spin )
526 void IntegerRangeConfigControl::finish()
528 spin->setMaximum( p_item->i_max );
529 spin->setMinimum( p_item->i_min );
532 /********* Integer / choice list **********/
533 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
534 module_config_t *_p_item, QWidget *_parent, bool bycat,
535 QGridLayout *l, int &line) :
536 VIntConfigControl( _p_this, _p_item, _parent )
538 label = new QLabel( qfu(p_item->psz_text) );
539 combo = new QComboBox();
543 QHBoxLayout *layout = new QHBoxLayout();
544 layout->addWidget( label ); layout->addWidget( combo );
545 widget->setLayout( layout );
549 l->addWidget( label, line, 0 );
550 l->addWidget( combo, line, 1, Qt::AlignRight );
553 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
554 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
555 bool bycat ) : VIntConfigControl( _p_this, _p_item )
562 void IntegerListConfigControl::finish( bool bycat )
564 combo->setEditable( false );
566 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
568 combo->addItem( qfu(p_item->ppsz_list_text[i_index] ),
569 QVariant( p_item->pi_list[i_index] ) );
570 if( p_item->i_value == p_item->pi_list[i_index] )
571 combo->setCurrentIndex( combo->count() - 1 );
573 combo->setToolTip( qfu(p_item->psz_longtext) );
575 label->setToolTip( qfu(p_item->psz_longtext) );
578 int IntegerListConfigControl::getValue()
580 return combo->itemData( combo->currentIndex() ).toInt();
583 /*********** Boolean **************/
584 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
585 module_config_t *_p_item,
586 QWidget *_parent, QGridLayout *l,
588 VIntConfigControl( _p_this, _p_item, _parent )
590 checkbox = new QCheckBox( qfu(p_item->psz_text) );
595 QHBoxLayout *layout = new QHBoxLayout();
596 layout->addWidget( checkbox, 0 );
597 widget->setLayout( layout );
601 l->addWidget( checkbox, line, 0 );
604 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
605 module_config_t *_p_item,
607 QCheckBox *_checkbox,
609 VIntConfigControl( _p_this, _p_item )
611 checkbox = _checkbox;
615 void BoolConfigControl::finish()
617 checkbox->setCheckState( p_item->i_value == VLC_TRUE ? Qt::Checked
619 checkbox->setToolTip( qfu(p_item->psz_longtext) );
622 int BoolConfigControl::getValue()
624 return checkbox->checkState() == Qt::Checked ? VLC_TRUE : VLC_FALSE;
627 /**************************************************************************
628 * Float-based controls
629 *************************************************************************/
631 /*********** Float **************/
632 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
633 module_config_t *_p_item,
634 QWidget *_parent, QGridLayout *l,
636 VFloatConfigControl( _p_this, _p_item, _parent )
638 label = new QLabel( qfu(p_item->psz_text) );
639 spin = new QDoubleSpinBox; spin->setMinimumWidth( 80 );
640 spin->setMaximumWidth( 90 );
645 QHBoxLayout *layout = new QHBoxLayout();
646 layout->addWidget( label, 0 ); layout->addWidget( spin, 1 );
647 widget->setLayout( layout );
651 l->addWidget( label, line, 0 );
652 l->addWidget( spin, line, 1, Qt::AlignRight );
656 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
657 module_config_t *_p_item,
659 QDoubleSpinBox *_spin ) :
660 VFloatConfigControl( _p_this, _p_item )
667 void FloatConfigControl::finish()
669 spin->setMaximum( 2000000000. );
670 spin->setMinimum( -2000000000. );
671 spin->setSingleStep( 0.1 );
672 spin->setValue( (double)p_item->f_value );
673 spin->setToolTip( qfu(p_item->psz_longtext) );
675 label->setToolTip( qfu(p_item->psz_longtext) );
678 float FloatConfigControl::getValue()
680 return (float)spin->value();
683 /*********** Float with range **************/
684 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
685 module_config_t *_p_item,
686 QWidget *_parent, QGridLayout *l,
688 FloatConfigControl( _p_this, _p_item, _parent, l, line )
693 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
694 module_config_t *_p_item,
696 QDoubleSpinBox *_spin ) :
697 FloatConfigControl( _p_this, _p_item, _label, _spin )
702 void FloatRangeConfigControl::finish()
704 spin->setMaximum( (double)p_item->f_max );
705 spin->setMinimum( (double)p_item->f_min );