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 fprintf( stderr, "Todo\n" );
84 p_control = new IntegerConfigControl( p_this, p_item, parent,
87 case CONFIG_ITEM_FILE:
88 fprintf( stderr, "Todo\n" );
90 case CONFIG_ITEM_BOOL:
91 p_control = new BoolConfigControl( p_this, p_item, parent, l, line );
93 case CONFIG_ITEM_FLOAT:
94 if( p_item->f_min || p_item->f_max )
95 fprintf( stderr, "Todo\n" );
97 fprintf( stderr, "Todo\n" );
105 /**************************************************************************
106 * String-based controls
107 *************************************************************************/
109 /*********** String **************/
110 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
111 module_config_t *_p_item,
112 QWidget *_parent, QGridLayout *l,
113 int line, bool pwd ) :
114 VStringConfigControl( _p_this, _p_item, _parent )
116 label = new QLabel( qfu(p_item->psz_text) );
117 text = new QLineEdit( qfu(p_item->psz_value) );
122 QHBoxLayout *layout = new QHBoxLayout();
123 layout->addWidget( label, 0 ); layout->addWidget( text, 1 );
124 widget->setLayout( layout );
128 l->addWidget( label, line, 0 ); l->addWidget( text, line, 1 );
132 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
133 module_config_t *_p_item,
134 QLabel *_label, QLineEdit *_text, bool pwd ):
135 VStringConfigControl( _p_this, _p_item )
142 void StringConfigControl::finish()
144 text->setText( qfu(p_item->psz_value) );
145 text->setToolTip( qfu(p_item->psz_longtext) );
147 label->setToolTip( qfu(p_item->psz_longtext) );
150 /********* String / choice list **********/
151 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
152 module_config_t *_p_item, QWidget *_parent, bool bycat,
153 QGridLayout *l, int line) :
154 VStringConfigControl( _p_this, _p_item, _parent )
156 label = new QLabel( qfu(p_item->psz_text) );
157 combo = new QComboBox();
161 QHBoxLayout *layout = new QHBoxLayout();
162 layout->addWidget( label ); layout->addWidget( combo );
163 widget->setLayout( layout );
167 l->addWidget( label, line, 0 );
168 l->addWidget( combo, line, 1, Qt::AlignRight );
171 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
172 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
173 bool bycat ) : VStringConfigControl( _p_this, _p_item )
180 void StringListConfigControl::finish( bool bycat )
182 combo->setEditable( false );
184 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
186 combo->addItem( qfu(p_item->ppsz_list_text ?
187 p_item->ppsz_list_text[i_index] :
188 p_item->ppsz_list[i_index] ),
189 QVariant( p_item->ppsz_list[i_index] ) );
190 if( p_item->psz_value && !strcmp( p_item->psz_value,
191 p_item->ppsz_list[i_index] ) )
192 combo->setCurrentIndex( combo->count() - 1 );
194 combo->setToolTip( qfu(p_item->psz_longtext) );
196 label->setToolTip( qfu(p_item->psz_longtext) );
199 QString StringListConfigControl::getValue()
201 return combo->itemData( combo->currentIndex() ).toString();
204 /********* Module **********/
205 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
206 module_config_t *_p_item, QWidget *_parent, bool bycat,
207 QGridLayout *l, int line) :
208 VStringConfigControl( _p_this, _p_item, _parent )
210 label = new QLabel( qfu(p_item->psz_text) );
211 combo = new QComboBox();
215 QHBoxLayout *layout = new QHBoxLayout();
216 layout->addWidget( label ); layout->addWidget( combo );
217 widget->setLayout( layout );
221 l->addWidget( label, line, 0 );
222 l->addWidget( combo, line, 1, Qt::AlignRight );
225 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
226 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
227 bool bycat ) : VStringConfigControl( _p_this, _p_item )
234 void ModuleConfigControl::finish( bool bycat )
239 combo->setEditable( false );
241 /* build a list of available modules */
242 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
243 combo->addItem( qtr("Default") );
244 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
246 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
250 if( !strcmp( p_parser->psz_object_name, "main" ) ) continue;
252 module_config_t *p_config = p_parser->p_config;
255 /* Hack: required subcategory is stored in i_min */
256 if( p_config->i_type == CONFIG_SUBCATEGORY &&
257 p_config->i_value == p_item->i_min )
258 combo->addItem( qfu(p_parser->psz_longname),
259 QVariant( p_parser->psz_object_name ) );
260 if( p_item->psz_value && !strcmp( p_item->psz_value,
261 p_parser->psz_object_name) )
262 combo->setCurrentIndex( combo->count() - 1 );
263 } while( p_config->i_type != CONFIG_HINT_END && p_config++ );
265 else if( !strcmp( p_parser->psz_capability, p_item->psz_type ) )
267 combo->addItem( qfu(p_parser->psz_longname),
268 QVariant( p_parser->psz_object_name ) );
269 if( p_item->psz_value && !strcmp( p_item->psz_value,
270 p_parser->psz_object_name) )
271 combo->setCurrentIndex( combo->count() - 1 );
274 vlc_list_release( p_list );
275 combo->setToolTip( qfu(p_item->psz_longtext) );
277 label->setToolTip( qfu(p_item->psz_longtext) );
280 QString ModuleConfigControl::getValue()
282 return combo->itemData( combo->currentIndex() ).toString();
285 /**************************************************************************
286 * Integer-based controls
287 *************************************************************************/
289 /*********** Integer **************/
290 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
291 module_config_t *_p_item,
292 QWidget *_parent, QGridLayout *l,
294 VIntConfigControl( _p_this, _p_item, _parent )
296 label = new QLabel( qfu(p_item->psz_text) );
297 spin = new QSpinBox; spin->setMinimumWidth( 80 );
298 spin->setMaximumWidth( 90 );
303 QHBoxLayout *layout = new QHBoxLayout();
304 layout->addWidget( label, 0 ); layout->addWidget( spin, 1 );
305 widget->setLayout( layout );
309 l->addWidget( label, line, 0 );
310 l->addWidget( spin, line, 1, Qt::AlignRight );
313 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
314 module_config_t *_p_item,
315 QLabel *_label, QSpinBox *_spin ) :
316 VIntConfigControl( _p_this, _p_item )
323 void IntegerConfigControl::finish()
325 spin->setMaximum( 2000000000 );
326 spin->setValue( p_item->i_value );
327 spin->setToolTip( qfu(p_item->psz_longtext) );
329 label->setToolTip( qfu(p_item->psz_longtext) );
332 int IntegerConfigControl::getValue()
334 return spin->value();
337 /********* Integer / choice list **********/
338 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
339 module_config_t *_p_item, QWidget *_parent, bool bycat,
340 QGridLayout *l, int line) :
341 VIntConfigControl( _p_this, _p_item, _parent )
343 label = new QLabel( qfu(p_item->psz_text) );
344 combo = new QComboBox();
348 QHBoxLayout *layout = new QHBoxLayout();
349 layout->addWidget( label ); layout->addWidget( combo );
350 widget->setLayout( layout );
354 l->addWidget( label, line, 0 );
355 l->addWidget( combo, line, 1, Qt::AlignRight );
358 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
359 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
360 bool bycat ) : VIntConfigControl( _p_this, _p_item )
367 void IntegerListConfigControl::finish( bool bycat )
369 combo->setEditable( false );
371 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
373 combo->addItem( qfu(p_item->ppsz_list_text[i_index] ),
374 QVariant( p_item->pi_list[i_index] ) );
375 if( p_item->i_value == p_item->pi_list[i_index] )
376 combo->setCurrentIndex( combo->count() - 1 );
378 combo->setToolTip( qfu(p_item->psz_longtext) );
380 label->setToolTip( qfu(p_item->psz_longtext) );
383 int IntegerListConfigControl::getValue()
385 return combo->itemData( combo->currentIndex() ).toInt();
388 /*********** Boolean **************/
389 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
390 module_config_t *_p_item,
391 QWidget *_parent, QGridLayout *l,
393 VIntConfigControl( _p_this, _p_item, _parent )
395 checkbox = new QCheckBox( qfu(p_item->psz_text) );
400 QHBoxLayout *layout = new QHBoxLayout();
401 layout->addWidget( checkbox, 0 );
402 widget->setLayout( layout );
406 l->addWidget( checkbox, line, 0 );
409 BoolConfigControl::BoolConfigControl( vlc_object_t *_p_this,
410 module_config_t *_p_item,
412 QCheckBox *_checkbox,
414 VIntConfigControl( _p_this, _p_item )
416 checkbox = _checkbox;
420 void BoolConfigControl::finish()
422 checkbox->setCheckState( p_item->i_value == VLC_TRUE ? Qt::Checked
424 checkbox->setToolTip( qfu(p_item->psz_longtext) );
427 int BoolConfigControl::getValue()
429 return checkbox->checkState() == Qt::Checked ? VLC_TRUE : VLC_FALSE;