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>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
26 * - Finish implementation (see WX)
27 * - Improvements over WX
28 * - Password field implementation (through "pwd" bool param
29 * - Validator for modulelist
30 * - Implement update stuff using a general Updated signal
33 #include "components/preferences_widgets.hpp"
38 #include <QDoubleSpinBox>
41 #include <QGridLayout>
43 ConfigControl *ConfigControl::createControl( vlc_object_t *p_this,
44 module_config_t *p_item,
47 return createControl( p_this, p_item, parent, NULL, 0 );
50 ConfigControl *ConfigControl::createControl( vlc_object_t *p_this,
51 module_config_t *p_item,
53 QGridLayout *l, int line )
55 ConfigControl *p_control = NULL;
56 if( p_item->psz_current ) return NULL;
58 switch( p_item->i_type )
60 case CONFIG_ITEM_MODULE:
61 p_control = new ModuleConfigControl( p_this, p_item, parent, false,
64 case CONFIG_ITEM_MODULE_CAT:
65 p_control = new ModuleConfigControl( p_this, p_item, parent, true,
68 case CONFIG_ITEM_STRING:
70 p_control = new StringConfigControl( p_this, p_item, parent,
73 fprintf(stderr, "TODO\n" );
75 case CONFIG_ITEM_INTEGER:
77 fprintf( stderr, "Todo\n" );
78 else if( p_item->i_min || p_item->i_max )
79 fprintf( stderr, "Todo\n" );
81 p_control = new IntegerConfigControl( p_this, p_item, parent,
90 /**************************************************************************
91 * String-based controls
92 *************************************************************************/
94 /*********** String **************/
95 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
96 module_config_t *_p_item,
97 QWidget *_parent, QGridLayout *l,
98 int line, bool pwd ) :
99 VStringConfigControl( _p_this, _p_item, _parent )
101 label = new QLabel( qfu(p_item->psz_text) );
102 text = new QLineEdit( qfu(p_item->psz_value) );
107 QHBoxLayout *layout = new QHBoxLayout();
108 layout->addWidget( label, 0 ); layout->addWidget( text, 1 );
109 widget->setLayout( layout );
113 l->addWidget( label, line, 0 ); l->addWidget( text, line, 1 );
117 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
118 module_config_t *_p_item,
119 QLabel *_label, QLineEdit *_text, bool pwd ):
120 VStringConfigControl( _p_this, _p_item )
127 void StringConfigControl::finish()
129 text->setText( qfu(p_item->psz_value) );
130 text->setToolTip( qfu(p_item->psz_longtext) );
131 label->setToolTip( qfu(p_item->psz_longtext) );
134 /********* Module **********/
135 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
136 module_config_t *_p_item, QWidget *_parent, bool bycat,
137 QGridLayout *l, int line) :
138 VStringConfigControl( _p_this, _p_item, _parent )
140 label = new QLabel( qfu(p_item->psz_text) );
141 combo = new QComboBox();
145 QHBoxLayout *layout = new QHBoxLayout();
146 layout->addWidget( label ); layout->addWidget( combo );
147 widget->setLayout( layout );
151 l->addWidget( label, line, 0 );
152 l->addWidget( combo, line, 1, Qt::AlignRight );
155 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
156 module_config_t *_p_item, QLabel *_label, QComboBox *_combo,
157 bool bycat ) : VStringConfigControl( _p_this, _p_item )
164 void ModuleConfigControl::finish( bool bycat )
169 combo->setEditable( false );
171 /* build a list of available modules */
172 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
173 combo->addItem( qtr("Default") );
174 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
176 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
180 if( !strcmp( p_parser->psz_object_name, "main" ) ) continue;
182 module_config_t *p_config = p_parser->p_config;
185 /* Hack: required subcategory is stored in i_min */
186 if( p_config->i_type == CONFIG_SUBCATEGORY &&
187 p_config->i_value == p_item->i_min )
188 combo->addItem( qfu(p_parser->psz_longname),
189 QVariant( p_parser->psz_object_name ) );
190 if( p_item->psz_value && !strcmp( p_item->psz_value,
191 p_parser->psz_object_name) )
192 combo->setCurrentIndex( combo->count() - 1 );
193 } while( p_config->i_type != CONFIG_HINT_END && p_config++ );
195 else if( !strcmp( p_parser->psz_capability, p_item->psz_type ) )
197 combo->addItem( qfu(p_parser->psz_longname),
198 QVariant( p_parser->psz_object_name ) );
199 if( p_item->psz_value && !strcmp( p_item->psz_value,
200 p_parser->psz_object_name) )
201 combo->setCurrentIndex( combo->count() - 1 );
204 vlc_list_release( p_list );
205 combo->setToolTip( qfu(p_item->psz_longtext) );
206 label->setToolTip( qfu(p_item->psz_longtext) );
209 QString ModuleConfigControl::getValue()
211 return combo->itemData( combo->currentIndex() ).toString();
214 /**************************************************************************
215 * Integer-based controls
216 *************************************************************************/
218 /*********** Integer **************/
219 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
220 module_config_t *_p_item,
221 QWidget *_parent, QGridLayout *l,
223 VIntConfigControl( _p_this, _p_item, _parent )
225 label = new QLabel( qfu(p_item->psz_text) );
226 spin = new QSpinBox; spin->setMinimumWidth( 80 );
227 spin->setMaximumWidth( 90 );
232 QHBoxLayout *layout = new QHBoxLayout();
233 layout->addWidget( label, 0 ); layout->addWidget( spin, 1 );
234 widget->setLayout( layout );
238 l->addWidget( label, line, 0 );
239 l->addWidget( spin, line, 1, Qt::AlignRight );
242 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
243 module_config_t *_p_item,
244 QLabel *_label, QSpinBox *_spin ) :
245 VIntConfigControl( _p_this, _p_item )
252 void IntegerConfigControl::finish()
254 spin->setMaximum( 2000000000 );
255 spin->setValue( p_item->i_value );
256 spin->setToolTip( qfu(p_item->psz_longtext) );
257 label->setToolTip( qfu(p_item->psz_longtext) );
260 int IntegerConfigControl::getValue()
262 return spin->value();