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,
48 return createControl( p_this, p_item, parent, NULL, 0 );
51 ConfigControl *ConfigControl::createControl( vlc_object_t *p_this,
52 module_config_t *p_item,
54 QGridLayout *l, int line )
56 ConfigControl *p_control = NULL;
57 if( p_item->psz_current ) return NULL;
59 switch( p_item->i_type )
61 case CONFIG_ITEM_MODULE:
62 p_control = new ModuleConfigControl( p_this, p_item, parent, false,
65 case CONFIG_ITEM_MODULE_CAT:
66 p_control = new ModuleConfigControl( p_this, p_item, parent, true,
69 case CONFIG_ITEM_STRING:
71 p_control = new StringConfigControl( p_this, p_item, parent,
74 p_control = new StringListConfigControl( p_this, p_item,
75 parent, false, l, line );
77 case CONFIG_ITEM_INTEGER:
79 p_control = new IntegerListConfigControl( p_this, p_item,
80 parent, false, l, line );
81 else if( p_item->i_min || p_item->i_max )
82 p_control = new IntegerRangeConfigControl( p_this, p_item, parent,
85 p_control = new IntegerConfigControl( p_this, p_item, parent,
88 case CONFIG_ITEM_FILE:
89 fprintf( stderr, "Todo\n" );
91 case CONFIG_ITEM_BOOL:
92 p_control = new BoolConfigControl( p_this, p_item, parent, l, line );
94 case CONFIG_ITEM_FLOAT:
95 if( p_item->f_min || p_item->f_max )
96 p_control = new FloatRangeConfigControl( p_this, p_item, parent,
99 p_control = new FloatConfigControl( p_this, p_item, parent,
108 /**************************************************************************
109 * String-based controls
110 *************************************************************************/
112 /*********** String **************/
113 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
114 module_config_t *_p_item,
115 QWidget *_parent, QGridLayout *l,
116 int line, bool pwd ) :
117 VStringConfigControl( _p_this, _p_item, _parent )
119 label = new QLabel( qfu(p_item->psz_text) );
120 text = new QLineEdit( qfu(p_item->psz_value) );
125 QHBoxLayout *layout = new QHBoxLayout();
126 layout->addWidget( label, 0 ); layout->addWidget( text, 1 );
127 widget->setLayout( layout );
131 l->addWidget( label, line, 0 ); l->addWidget( text, line, 1 );
135 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
136 module_config_t *_p_item,
137 QLabel *_label, QLineEdit *_text, bool pwd ):
138 VStringConfigControl( _p_this, _p_item )
145 void StringConfigControl::finish()
147 text->setText( qfu(p_item->psz_value) );
148 text->setToolTip( qfu(p_item->psz_longtext) );
150 label->setToolTip( qfu(p_item->psz_longtext) );
153 /********* String / choice list **********/
154 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
155 module_config_t *_p_item, QWidget *_parent, bool bycat,
156 QGridLayout *l, int line) :
157 VStringConfigControl( _p_this, _p_item, _parent )
159 label = new QLabel( qfu(p_item->psz_text) );
160 combo = new QComboBox();
164 QHBoxLayout *layout = new QHBoxLayout();
165 layout->addWidget( label ); layout->addWidget( combo );
166 widget->setLayout( layout );
170 l->addWidget( label, line, 0 );
171 l->addWidget( combo, line, 1, Qt::AlignRight );
174 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
175 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
176 bool bycat ) : VStringConfigControl( _p_this, _p_item )
183 void StringListConfigControl::finish( bool bycat )
185 combo->setEditable( false );
187 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
189 combo->addItem( qfu(p_item->ppsz_list_text ?
190 p_item->ppsz_list_text[i_index] :
191 p_item->ppsz_list[i_index] ),
192 QVariant( p_item->ppsz_list[i_index] ) );
193 if( p_item->psz_value && !strcmp( p_item->psz_value,
194 p_item->ppsz_list[i_index] ) )
195 combo->setCurrentIndex( combo->count() - 1 );
197 combo->setToolTip( qfu(p_item->psz_longtext) );
199 label->setToolTip( qfu(p_item->psz_longtext) );
202 QString StringListConfigControl::getValue()
204 return combo->itemData( combo->currentIndex() ).toString();
207 /********* Module **********/
208 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
209 module_config_t *_p_item, QWidget *_parent, bool bycat,
210 QGridLayout *l, int line) :
211 VStringConfigControl( _p_this, _p_item, _parent )
213 label = new QLabel( qfu(p_item->psz_text) );
214 combo = new QComboBox();
218 QHBoxLayout *layout = new QHBoxLayout();
219 layout->addWidget( label ); layout->addWidget( combo );
220 widget->setLayout( layout );
224 l->addWidget( label, line, 0 );
225 l->addWidget( combo, line, 1, Qt::AlignRight );
228 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
229 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
230 bool bycat ) : VStringConfigControl( _p_this, _p_item )
237 void ModuleConfigControl::finish( bool bycat )
242 combo->setEditable( false );
244 /* build a list of available modules */
245 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
246 combo->addItem( qtr("Default") );
247 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
249 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
253 if( !strcmp( p_parser->psz_object_name, "main" ) ) continue;
255 module_config_t *p_config = p_parser->p_config;
258 /* Hack: required subcategory is stored in i_min */
259 if( p_config->i_type == CONFIG_SUBCATEGORY &&
260 p_config->i_value == p_item->i_min )
261 combo->addItem( qfu(p_parser->psz_longname),
262 QVariant( p_parser->psz_object_name ) );
263 if( p_item->psz_value && !strcmp( p_item->psz_value,
264 p_parser->psz_object_name) )
265 combo->setCurrentIndex( combo->count() - 1 );
266 } while( p_config->i_type != CONFIG_HINT_END && p_config++ );
268 else if( !strcmp( p_parser->psz_capability, p_item->psz_type ) )
270 combo->addItem( qfu(p_parser->psz_longname),
271 QVariant( p_parser->psz_object_name ) );
272 if( p_item->psz_value && !strcmp( p_item->psz_value,
273 p_parser->psz_object_name) )
274 combo->setCurrentIndex( combo->count() - 1 );
277 vlc_list_release( p_list );
278 combo->setToolTip( qfu(p_item->psz_longtext) );
280 label->setToolTip( qfu(p_item->psz_longtext) );
283 QString ModuleConfigControl::getValue()
285 return combo->itemData( combo->currentIndex() ).toString();
288 /**************************************************************************
289 * Integer-based controls
290 *************************************************************************/
292 /*********** Integer **************/
293 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
294 module_config_t *_p_item,
295 QWidget *_parent, QGridLayout *l,
297 VIntConfigControl( _p_this, _p_item, _parent )
299 label = new QLabel( qfu(p_item->psz_text) );
300 spin = new QSpinBox; spin->setMinimumWidth( 80 );
301 spin->setMaximumWidth( 90 );
306 QHBoxLayout *layout = new QHBoxLayout();
307 layout->addWidget( label, 0 ); layout->addWidget( spin, 1 );
308 widget->setLayout( layout );
312 l->addWidget( label, line, 0 );
313 l->addWidget( spin, line, 1, Qt::AlignRight );
316 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
317 module_config_t *_p_item,
318 QLabel *_label, QSpinBox *_spin ) :
319 VIntConfigControl( _p_this, _p_item )
326 void IntegerConfigControl::finish()
328 spin->setMaximum( 2000000000 );
329 spin->setMinimum( -2000000000 );
330 spin->setValue( p_item->i_value );
331 spin->setToolTip( qfu(p_item->psz_longtext) );
333 label->setToolTip( qfu(p_item->psz_longtext) );
336 int IntegerConfigControl::getValue()
338 return spin->value();
341 /********* Integer range **********/
342 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
343 module_config_t *_p_item,
344 QWidget *_parent, QGridLayout *l,
346 IntegerConfigControl( _p_this, _p_item, _parent, l, line )
351 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
352 module_config_t *_p_item,
353 QLabel *_label, QSpinBox *_spin ) :
354 IntegerConfigControl( _p_this, _p_item, _label, _spin )
359 void IntegerRangeConfigControl::finish()
361 spin->setMaximum( p_item->i_max );
362 spin->setMinimum( p_item->i_min );
365 /********* Integer / choice list **********/
366 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
367 module_config_t *_p_item, QWidget *_parent, bool bycat,
368 QGridLayout *l, int line) :
369 VIntConfigControl( _p_this, _p_item, _parent )
371 label = new QLabel( qfu(p_item->psz_text) );
372 combo = new QComboBox();
376 QHBoxLayout *layout = new QHBoxLayout();
377 layout->addWidget( label ); layout->addWidget( combo );
378 widget->setLayout( layout );
382 l->addWidget( label, line, 0 );
383 l->addWidget( combo, line, 1, Qt::AlignRight );
386 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
387 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
388 bool bycat ) : VIntConfigControl( _p_this, _p_item )
395 void IntegerListConfigControl::finish( bool bycat )
397 combo->setEditable( false );
399 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
401 combo->addItem( qfu(p_item->ppsz_list_text[i_index] ),
402 QVariant( p_item->pi_list[i_index] ) );
403 if( p_item->i_value == p_item->pi_list[i_index] )
404 combo->setCurrentIndex( combo->count() - 1 );
406 combo->setToolTip( qfu(p_item->psz_longtext) );
408 label->setToolTip( qfu(p_item->psz_longtext) );
411 int IntegerListConfigControl::getValue()
413 return combo->itemData( combo->currentIndex() ).toInt();
416 /*********** Boolean **************/
417 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
418 module_config_t *_p_item,
419 QWidget *_parent, QGridLayout *l,
421 VIntConfigControl( _p_this, _p_item, _parent )
423 checkbox = new QCheckBox( qfu(p_item->psz_text) );
428 QHBoxLayout *layout = new QHBoxLayout();
429 layout->addWidget( checkbox, 0 );
430 widget->setLayout( layout );
434 l->addWidget( checkbox, line, 0 );
437 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
438 module_config_t *_p_item,
440 QCheckBox *_checkbox,
442 VIntConfigControl( _p_this, _p_item )
444 checkbox = _checkbox;
448 void BoolConfigControl::finish()
450 checkbox->setCheckState( p_item->i_value == VLC_TRUE ? Qt::Checked
452 checkbox->setToolTip( qfu(p_item->psz_longtext) );
455 int BoolConfigControl::getValue()
457 return checkbox->checkState() == Qt::Checked ? VLC_TRUE : VLC_FALSE;
460 /**************************************************************************
461 * Float-based controls
462 *************************************************************************/
464 /*********** Float **************/
465 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
466 module_config_t *_p_item,
467 QWidget *_parent, QGridLayout *l,
469 VFloatConfigControl( _p_this, _p_item, _parent )
471 label = new QLabel( qfu(p_item->psz_text) );
472 spin = new QDoubleSpinBox; spin->setMinimumWidth( 80 );
473 spin->setMaximumWidth( 90 );
478 QHBoxLayout *layout = new QHBoxLayout();
479 layout->addWidget( label, 0 ); layout->addWidget( spin, 1 );
480 widget->setLayout( layout );
484 l->addWidget( label, line, 0 );
485 l->addWidget( spin, line, 1, Qt::AlignRight );
489 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
490 module_config_t *_p_item,
492 QDoubleSpinBox *_spin ) :
493 VFloatConfigControl( _p_this, _p_item )
500 void FloatConfigControl::finish()
502 spin->setMaximum( 2000000000. );
503 spin->setMinimum( -2000000000. );
504 spin->setSingleStep( 0.1 );
505 spin->setValue( (double)p_item->f_value );
506 spin->setToolTip( qfu(p_item->psz_longtext) );
508 label->setToolTip( qfu(p_item->psz_longtext) );
511 float FloatConfigControl::getValue()
513 return (float)spin->value();
516 /*********** Float with range **************/
517 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
518 module_config_t *_p_item,
519 QWidget *_parent, QGridLayout *l,
521 FloatConfigControl( _p_this, _p_item, _parent, l, line )
526 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
527 module_config_t *_p_item,
529 QDoubleSpinBox *_spin ) :
530 FloatConfigControl( _p_this, _p_item, _label, _spin )
535 void FloatRangeConfigControl::finish()
537 spin->setMaximum( (double)p_item->f_max );
538 spin->setMinimum( (double)p_item->f_min );