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 void ConfigControl::doApply( intf_thread_t *p_intf )
114 VIntConfigControl *vicc = qobject_cast<VIntConfigControl *>(this);
115 config_PutInt( p_intf, vicc->getName(), vicc->getValue() );
120 VFloatConfigControl *vfcc =
121 qobject_cast<VFloatConfigControl *>(this);
122 config_PutFloat( p_intf, vfcc->getName(), vfcc->getValue() );
127 VStringConfigControl *vscc =
128 qobject_cast<VStringConfigControl *>(this);
129 config_PutPsz( p_intf, vscc->getName(), qta( vscc->getValue() ) );
134 /**************************************************************************
135 * String-based controls
136 *************************************************************************/
138 /*********** String **************/
139 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
140 module_config_t *_p_item,
141 QWidget *_parent, QGridLayout *l,
142 int line, bool pwd ) :
143 VStringConfigControl( _p_this, _p_item, _parent )
145 label = new QLabel( qfu(p_item->psz_text) );
146 text = new QLineEdit( qfu(p_item->psz_value) );
151 QHBoxLayout *layout = new QHBoxLayout();
152 layout->addWidget( label, 0 ); layout->addWidget( text, 1 );
153 widget->setLayout( layout );
157 l->addWidget( label, line, 0 ); l->addWidget( text, line, 1 );
161 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
162 module_config_t *_p_item,
163 QLabel *_label, QLineEdit *_text, bool pwd ):
164 VStringConfigControl( _p_this, _p_item )
171 void StringConfigControl::finish()
173 text->setText( qfu(p_item->psz_value) );
174 text->setToolTip( qfu(p_item->psz_longtext) );
176 label->setToolTip( qfu(p_item->psz_longtext) );
179 /********* String / choice list **********/
180 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
181 module_config_t *_p_item, QWidget *_parent, bool bycat,
182 QGridLayout *l, int line) :
183 VStringConfigControl( _p_this, _p_item, _parent )
185 label = new QLabel( qfu(p_item->psz_text) );
186 combo = new QComboBox();
190 QHBoxLayout *layout = new QHBoxLayout();
191 layout->addWidget( label ); layout->addWidget( combo );
192 widget->setLayout( layout );
196 l->addWidget( label, line, 0 );
197 l->addWidget( combo, line, 1, Qt::AlignRight );
200 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
201 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
202 bool bycat ) : VStringConfigControl( _p_this, _p_item )
209 void StringListConfigControl::finish( bool bycat )
211 combo->setEditable( false );
213 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
215 combo->addItem( qfu(p_item->ppsz_list_text ?
216 p_item->ppsz_list_text[i_index] :
217 p_item->ppsz_list[i_index] ),
218 QVariant( p_item->ppsz_list[i_index] ) );
219 if( p_item->psz_value && !strcmp( p_item->psz_value,
220 p_item->ppsz_list[i_index] ) )
221 combo->setCurrentIndex( combo->count() - 1 );
223 combo->setToolTip( qfu(p_item->psz_longtext) );
225 label->setToolTip( qfu(p_item->psz_longtext) );
228 QString StringListConfigControl::getValue()
230 return combo->itemData( combo->currentIndex() ).toString();
233 /********* Module **********/
234 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
235 module_config_t *_p_item, QWidget *_parent, bool bycat,
236 QGridLayout *l, int line) :
237 VStringConfigControl( _p_this, _p_item, _parent )
239 label = new QLabel( qfu(p_item->psz_text) );
240 combo = new QComboBox();
244 QHBoxLayout *layout = new QHBoxLayout();
245 layout->addWidget( label ); layout->addWidget( combo );
246 widget->setLayout( layout );
250 l->addWidget( label, line, 0 );
251 l->addWidget( combo, line, 1, Qt::AlignRight );
254 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
255 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
256 bool bycat ) : VStringConfigControl( _p_this, _p_item )
263 void ModuleConfigControl::finish( bool bycat )
268 combo->setEditable( false );
270 /* build a list of available modules */
271 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
272 combo->addItem( qtr("Default") );
273 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
275 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
279 if( !strcmp( p_parser->psz_object_name, "main" ) ) continue;
281 module_config_t *p_config = p_parser->p_config;
284 /* Hack: required subcategory is stored in i_min */
285 if( p_config->i_type == CONFIG_SUBCATEGORY &&
286 p_config->i_value == p_item->i_min )
287 combo->addItem( qfu(p_parser->psz_longname),
288 QVariant( p_parser->psz_object_name ) );
289 if( p_item->psz_value && !strcmp( p_item->psz_value,
290 p_parser->psz_object_name) )
291 combo->setCurrentIndex( combo->count() - 1 );
292 } while( p_config->i_type != CONFIG_HINT_END && p_config++ );
294 else if( !strcmp( p_parser->psz_capability, p_item->psz_type ) )
296 combo->addItem( qfu(p_parser->psz_longname),
297 QVariant( p_parser->psz_object_name ) );
298 if( p_item->psz_value && !strcmp( p_item->psz_value,
299 p_parser->psz_object_name) )
300 combo->setCurrentIndex( combo->count() - 1 );
303 vlc_list_release( p_list );
304 combo->setToolTip( qfu(p_item->psz_longtext) );
306 label->setToolTip( qfu(p_item->psz_longtext) );
309 QString ModuleConfigControl::getValue()
311 return combo->itemData( combo->currentIndex() ).toString();
314 /**************************************************************************
315 * Integer-based controls
316 *************************************************************************/
318 /*********** Integer **************/
319 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
320 module_config_t *_p_item,
321 QWidget *_parent, QGridLayout *l,
323 VIntConfigControl( _p_this, _p_item, _parent )
325 label = new QLabel( qfu(p_item->psz_text) );
326 spin = new QSpinBox; spin->setMinimumWidth( 80 );
327 spin->setMaximumWidth( 90 );
332 QHBoxLayout *layout = new QHBoxLayout();
333 layout->addWidget( label, 0 ); layout->addWidget( spin, 1 );
334 widget->setLayout( layout );
338 l->addWidget( label, line, 0 );
339 l->addWidget( spin, line, 1, Qt::AlignRight );
342 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
343 module_config_t *_p_item,
344 QLabel *_label, QSpinBox *_spin ) :
345 VIntConfigControl( _p_this, _p_item )
352 void IntegerConfigControl::finish()
354 spin->setMaximum( 2000000000 );
355 spin->setMinimum( -2000000000 );
356 spin->setValue( p_item->i_value );
357 spin->setToolTip( qfu(p_item->psz_longtext) );
359 label->setToolTip( qfu(p_item->psz_longtext) );
362 int IntegerConfigControl::getValue()
364 return spin->value();
367 /********* Integer range **********/
368 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
369 module_config_t *_p_item,
370 QWidget *_parent, QGridLayout *l,
372 IntegerConfigControl( _p_this, _p_item, _parent, l, line )
377 IntegerRangeConfigControl::IntegerRangeConfigControl( vlc_object_t *_p_this,
378 module_config_t *_p_item,
379 QLabel *_label, QSpinBox *_spin ) :
380 IntegerConfigControl( _p_this, _p_item, _label, _spin )
385 void IntegerRangeConfigControl::finish()
387 spin->setMaximum( p_item->i_max );
388 spin->setMinimum( p_item->i_min );
391 /********* Integer / choice list **********/
392 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
393 module_config_t *_p_item, QWidget *_parent, bool bycat,
394 QGridLayout *l, int line) :
395 VIntConfigControl( _p_this, _p_item, _parent )
397 label = new QLabel( qfu(p_item->psz_text) );
398 combo = new QComboBox();
402 QHBoxLayout *layout = new QHBoxLayout();
403 layout->addWidget( label ); layout->addWidget( combo );
404 widget->setLayout( layout );
408 l->addWidget( label, line, 0 );
409 l->addWidget( combo, line, 1, Qt::AlignRight );
412 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
413 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
414 bool bycat ) : VIntConfigControl( _p_this, _p_item )
421 void IntegerListConfigControl::finish( bool bycat )
423 combo->setEditable( false );
425 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
427 combo->addItem( qfu(p_item->ppsz_list_text[i_index] ),
428 QVariant( p_item->pi_list[i_index] ) );
429 if( p_item->i_value == p_item->pi_list[i_index] )
430 combo->setCurrentIndex( combo->count() - 1 );
432 combo->setToolTip( qfu(p_item->psz_longtext) );
434 label->setToolTip( qfu(p_item->psz_longtext) );
437 int IntegerListConfigControl::getValue()
439 return combo->itemData( combo->currentIndex() ).toInt();
442 /*********** Boolean **************/
443 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
444 module_config_t *_p_item,
445 QWidget *_parent, QGridLayout *l,
447 VIntConfigControl( _p_this, _p_item, _parent )
449 checkbox = new QCheckBox( qfu(p_item->psz_text) );
454 QHBoxLayout *layout = new QHBoxLayout();
455 layout->addWidget( checkbox, 0 );
456 widget->setLayout( layout );
460 l->addWidget( checkbox, line, 0 );
463 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
464 module_config_t *_p_item,
466 QCheckBox *_checkbox,
468 VIntConfigControl( _p_this, _p_item )
470 checkbox = _checkbox;
474 void BoolConfigControl::finish()
476 checkbox->setCheckState( p_item->i_value == VLC_TRUE ? Qt::Checked
478 checkbox->setToolTip( qfu(p_item->psz_longtext) );
481 int BoolConfigControl::getValue()
483 return checkbox->checkState() == Qt::Checked ? VLC_TRUE : VLC_FALSE;
486 /**************************************************************************
487 * Float-based controls
488 *************************************************************************/
490 /*********** Float **************/
491 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
492 module_config_t *_p_item,
493 QWidget *_parent, QGridLayout *l,
495 VFloatConfigControl( _p_this, _p_item, _parent )
497 label = new QLabel( qfu(p_item->psz_text) );
498 spin = new QDoubleSpinBox; spin->setMinimumWidth( 80 );
499 spin->setMaximumWidth( 90 );
504 QHBoxLayout *layout = new QHBoxLayout();
505 layout->addWidget( label, 0 ); layout->addWidget( spin, 1 );
506 widget->setLayout( layout );
510 l->addWidget( label, line, 0 );
511 l->addWidget( spin, line, 1, Qt::AlignRight );
515 FloatConfigControl::FloatConfigControl( vlc_object_t *_p_this,
516 module_config_t *_p_item,
518 QDoubleSpinBox *_spin ) :
519 VFloatConfigControl( _p_this, _p_item )
526 void FloatConfigControl::finish()
528 spin->setMaximum( 2000000000. );
529 spin->setMinimum( -2000000000. );
530 spin->setSingleStep( 0.1 );
531 spin->setValue( (double)p_item->f_value );
532 spin->setToolTip( qfu(p_item->psz_longtext) );
534 label->setToolTip( qfu(p_item->psz_longtext) );
537 float FloatConfigControl::getValue()
539 return (float)spin->value();
542 /*********** Float with range **************/
543 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
544 module_config_t *_p_item,
545 QWidget *_parent, QGridLayout *l,
547 FloatConfigControl( _p_this, _p_item, _parent, l, line )
552 FloatRangeConfigControl::FloatRangeConfigControl( vlc_object_t *_p_this,
553 module_config_t *_p_item,
555 QDoubleSpinBox *_spin ) :
556 FloatConfigControl( _p_this, _p_item, _label, _spin )
561 void FloatRangeConfigControl::finish()
563 spin->setMaximum( (double)p_item->f_max );
564 spin->setMinimum( (double)p_item->f_min );