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>
42 ConfigControl *ConfigControl::createControl( vlc_object_t *p_this,
43 module_config_t *p_item,
46 ConfigControl *p_control = NULL;
47 if( p_item->psz_current ) return NULL;
49 switch( p_item->i_type )
51 case CONFIG_ITEM_MODULE:
52 p_control = new ModuleConfigControl( p_this, p_item, parent, false );
54 case CONFIG_ITEM_MODULE_CAT:
55 p_control = new ModuleConfigControl( p_this, p_item, parent, true );
57 case CONFIG_ITEM_STRING:
59 p_control = new StringConfigControl( p_this, p_item, parent,false );
61 fprintf(stderr, "TODO\n" );
69 /**************************************************************************
70 * String-based controls
71 *************************************************************************/
73 /*********** String **************/
74 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
75 module_config_t *_p_item,
76 QWidget *_parent, bool pwd ) :
77 VStringConfigControl( _p_this, _p_item, _parent )
79 QLabel *label = new QLabel( qfu(p_item->psz_text) );
80 text = new QLineEdit( qfu(p_item->psz_value) );
83 QHBoxLayout *layout = new QHBoxLayout();
84 layout->addWidget( label, 0 ); layout->addWidget( text, 1 );
85 widget->setLayout( layout );
88 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
89 module_config_t *_p_item,
90 QLabel *label, QLineEdit *_text, bool pwd ):
91 VStringConfigControl( _p_this, _p_item )
97 void StringConfigControl::finish( QLabel *label )
99 text->setToolTip( qfu(p_item->psz_longtext) );
100 label->setToolTip( qfu(p_item->psz_longtext) );
103 /********* Module **********/
104 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
105 module_config_t *_p_item, QWidget *_parent,
106 bool bycat ) : VStringConfigControl( _p_this, _p_item, _parent )
108 QLabel *label = new QLabel( qfu(p_item->psz_text) );
109 combo = new QComboBox();
110 finish( label, bycat );
111 QHBoxLayout *layout = new QHBoxLayout();
112 layout->addWidget( label ); layout->addWidget( combo );
113 widget->setLayout( layout );
115 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
116 module_config_t *_p_item, QLabel *label, QComboBox *_combo,
117 bool bycat ) : VStringConfigControl( _p_this, _p_item )
120 finish( label, bycat );
123 void ModuleConfigControl::finish( QLabel *label, bool bycat )
128 combo->setEditable( false );
130 /* build a list of available modules */
131 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
132 combo->addItem( qtr("Default") );
133 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
135 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
139 if( !strcmp( p_parser->psz_object_name, "main" ) ) continue;
141 module_config_t *p_config = p_parser->p_config;
144 /* Hack: required subcategory is stored in i_min */
145 if( p_config->i_type == CONFIG_SUBCATEGORY &&
146 p_config->i_value == p_item->i_min )
147 combo->addItem( qfu(p_parser->psz_longname),
148 QVariant( p_parser->psz_object_name ) );
149 if( p_item->psz_value && !strcmp( p_item->psz_value,
150 p_parser->psz_object_name) )
151 combo->setCurrentIndex( combo->count() - 1 );
152 } while( p_config->i_type != CONFIG_HINT_END && p_config++ );
154 else if( !strcmp( p_parser->psz_capability, p_item->psz_type ) )
156 combo->addItem( qfu(p_parser->psz_longname),
157 QVariant( p_parser->psz_object_name ) );
158 if( p_item->psz_value && !strcmp( p_item->psz_value,
159 p_parser->psz_object_name) )
160 combo->setCurrentIndex( combo->count() - 1 );
163 vlc_list_release( p_list );
164 combo->setToolTip( qfu(p_item->psz_longtext) );
165 label->setToolTip( qfu(p_item->psz_longtext) );
168 ModuleConfigControl::~ModuleConfigControl() {};
170 QString ModuleConfigControl::getValue()
172 return combo->itemData( combo->currentIndex() ).toString();