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,
93 /**************************************************************************
94 * String-based controls
95 *************************************************************************/
97 /*********** String **************/
98 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
99 module_config_t *_p_item,
100 QWidget *_parent, QGridLayout *l,
101 int line, bool pwd ) :
102 VStringConfigControl( _p_this, _p_item, _parent )
104 label = new QLabel( qfu(p_item->psz_text) );
105 text = new QLineEdit( qfu(p_item->psz_value) );
110 QHBoxLayout *layout = new QHBoxLayout();
111 layout->addWidget( label, 0 ); layout->addWidget( text, 1 );
112 widget->setLayout( layout );
116 l->addWidget( label, line, 0 ); l->addWidget( text, line, 1 );
120 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
121 module_config_t *_p_item,
122 QLabel *_label, QLineEdit *_text, bool pwd ):
123 VStringConfigControl( _p_this, _p_item )
130 void StringConfigControl::finish()
132 text->setText( qfu(p_item->psz_value) );
133 text->setToolTip( qfu(p_item->psz_longtext) );
135 label->setToolTip( qfu(p_item->psz_longtext) );
138 /********* String / choice list **********/
139 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
140 module_config_t *_p_item, QWidget *_parent, bool bycat,
141 QGridLayout *l, int line) :
142 VStringConfigControl( _p_this, _p_item, _parent )
144 label = new QLabel( qfu(p_item->psz_text) );
145 combo = new QComboBox();
149 QHBoxLayout *layout = new QHBoxLayout();
150 layout->addWidget( label ); layout->addWidget( combo );
151 widget->setLayout( layout );
155 l->addWidget( label, line, 0 );
156 l->addWidget( combo, line, 1, Qt::AlignRight );
159 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
160 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
161 bool bycat ) : VStringConfigControl( _p_this, _p_item )
168 void StringListConfigControl::finish( bool bycat )
170 combo->setEditable( false );
172 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
174 combo->addItem( qfu(p_item->ppsz_list_text ?
175 p_item->ppsz_list_text[i_index] :
176 p_item->ppsz_list[i_index] ),
177 QVariant( p_item->ppsz_list[i_index] ) );
178 if( p_item->psz_value && !strcmp( p_item->psz_value,
179 p_item->ppsz_list[i_index] ) )
180 combo->setCurrentIndex( combo->count() - 1 );
182 combo->setToolTip( qfu(p_item->psz_longtext) );
184 label->setToolTip( qfu(p_item->psz_longtext) );
187 QString StringListConfigControl::getValue()
189 return combo->itemData( combo->currentIndex() ).toString();
192 /********* Module **********/
193 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
194 module_config_t *_p_item, QWidget *_parent, bool bycat,
195 QGridLayout *l, int line) :
196 VStringConfigControl( _p_this, _p_item, _parent )
198 label = new QLabel( qfu(p_item->psz_text) );
199 combo = new QComboBox();
203 QHBoxLayout *layout = new QHBoxLayout();
204 layout->addWidget( label ); layout->addWidget( combo );
205 widget->setLayout( layout );
209 l->addWidget( label, line, 0 );
210 l->addWidget( combo, line, 1, Qt::AlignRight );
213 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
214 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
215 bool bycat ) : VStringConfigControl( _p_this, _p_item )
222 void ModuleConfigControl::finish( bool bycat )
227 combo->setEditable( false );
229 /* build a list of available modules */
230 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
231 combo->addItem( qtr("Default") );
232 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
234 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
238 if( !strcmp( p_parser->psz_object_name, "main" ) ) continue;
240 module_config_t *p_config = p_parser->p_config;
243 /* Hack: required subcategory is stored in i_min */
244 if( p_config->i_type == CONFIG_SUBCATEGORY &&
245 p_config->i_value == p_item->i_min )
246 combo->addItem( qfu(p_parser->psz_longname),
247 QVariant( p_parser->psz_object_name ) );
248 if( p_item->psz_value && !strcmp( p_item->psz_value,
249 p_parser->psz_object_name) )
250 combo->setCurrentIndex( combo->count() - 1 );
251 } while( p_config->i_type != CONFIG_HINT_END && p_config++ );
253 else if( !strcmp( p_parser->psz_capability, p_item->psz_type ) )
255 combo->addItem( qfu(p_parser->psz_longname),
256 QVariant( p_parser->psz_object_name ) );
257 if( p_item->psz_value && !strcmp( p_item->psz_value,
258 p_parser->psz_object_name) )
259 combo->setCurrentIndex( combo->count() - 1 );
262 vlc_list_release( p_list );
263 combo->setToolTip( qfu(p_item->psz_longtext) );
265 label->setToolTip( qfu(p_item->psz_longtext) );
268 QString ModuleConfigControl::getValue()
270 return combo->itemData( combo->currentIndex() ).toString();
273 /**************************************************************************
274 * Integer-based controls
275 *************************************************************************/
277 /*********** Integer **************/
278 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
279 module_config_t *_p_item,
280 QWidget *_parent, QGridLayout *l,
282 VIntConfigControl( _p_this, _p_item, _parent )
284 label = new QLabel( qfu(p_item->psz_text) );
285 spin = new QSpinBox; spin->setMinimumWidth( 80 );
286 spin->setMaximumWidth( 90 );
291 QHBoxLayout *layout = new QHBoxLayout();
292 layout->addWidget( label, 0 ); layout->addWidget( spin, 1 );
293 widget->setLayout( layout );
297 l->addWidget( label, line, 0 );
298 l->addWidget( spin, line, 1, Qt::AlignRight );
301 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
302 module_config_t *_p_item,
303 QLabel *_label, QSpinBox *_spin ) :
304 VIntConfigControl( _p_this, _p_item )
311 void IntegerConfigControl::finish()
313 spin->setMaximum( 2000000000 );
314 spin->setValue( p_item->i_value );
315 spin->setToolTip( qfu(p_item->psz_longtext) );
317 label->setToolTip( qfu(p_item->psz_longtext) );
320 int IntegerConfigControl::getValue()
322 return spin->value();
325 /********* Integer / choice list **********/
326 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
327 module_config_t *_p_item, QWidget *_parent, bool bycat,
328 QGridLayout *l, int line) :
329 VIntConfigControl( _p_this, _p_item, _parent )
331 label = new QLabel( qfu(p_item->psz_text) );
332 combo = new QComboBox();
336 QHBoxLayout *layout = new QHBoxLayout();
337 layout->addWidget( label ); layout->addWidget( combo );
338 widget->setLayout( layout );
342 l->addWidget( label, line, 0 );
343 l->addWidget( combo, line, 1, Qt::AlignRight );
346 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *_p_this,
347 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
348 bool bycat ) : VIntConfigControl( _p_this, _p_item )
355 void IntegerListConfigControl::finish( bool bycat )
357 combo->setEditable( false );
359 for( int i_index = 0; i_index < p_item->i_list; i_index++ )
361 combo->addItem( qfu(p_item->ppsz_list_text[i_index] ),
362 QVariant( p_item->pi_list[i_index] ) );
363 if( p_item->i_value == p_item->pi_list[i_index] )
364 combo->setCurrentIndex( combo->count() - 1 );
366 combo->setToolTip( qfu(p_item->psz_longtext) );
368 label->setToolTip( qfu(p_item->psz_longtext) );
371 int IntegerListConfigControl::getValue()
373 return combo->itemData( combo->currentIndex() ).toInt();