1 /*****************************************************************************
2 * preferences_widgets.cpp : Widgets for preferences displays
3 ****************************************************************************
4 * Copyright (C) 2000-2005 the VideoLAN team
5 * $Id: wxwidgets.cpp 15731 2006-05-25 14:43:53Z zorglub $
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 *****************************************************************************/
24 #include "components/preferences_widgets.hpp"
29 #include <QDoubleSpinBox>
33 ConfigControl::ConfigControl( vlc_object_t *_p_this, module_config_t *p_item,
34 QWidget *_parent ) : QWidget( _parent ),
35 p_this( _p_this ), _name( p_item->psz_name )
39 ConfigControl::~ConfigControl() {}
41 ConfigControl *ConfigControl::createControl( vlc_object_t *p_this,
42 module_config_t *p_item, QWidget *parent )
44 ConfigControl *p_control = NULL;
45 if( p_item->psz_current ) return NULL;
47 switch( p_item->i_type )
49 case CONFIG_ITEM_MODULE:
50 p_control = new ModuleConfigControl( p_this, p_item, parent, false );
52 case CONFIG_ITEM_MODULE_CAT:
53 p_control = new ModuleConfigControl( p_this, p_item, parent, true );
55 case CONFIG_ITEM_STRING:
57 p_control = new StringConfigControl( p_this, p_item, parent,false );
67 /**************************************************************************
68 * String-based controls
69 *************************************************************************/
71 /*********** String **************/
72 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
73 module_config_t *p_item, QWidget *_parent, bool pwd )
74 : VStringConfigControl( _p_this, p_item, _parent )
76 QLabel *label = new QLabel( p_item->psz_text );
77 text = new QLineEdit( p_item->psz_value );
78 text->setToolTip( p_item->psz_longtext );
79 label->setToolTip( p_item->psz_longtext );
81 QHBoxLayout *layout = new QHBoxLayout();
82 layout->addWidget( label ); layout->addWidget( text );
86 StringConfigControl::~StringConfigControl() {}
88 QString StringConfigControl::getValue() { return text->text(); };
91 /********* Module **********/
92 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
93 module_config_t *p_item, QWidget *_parent,
94 bool bycat ) : VStringConfigControl( _p_this, p_item, _parent )
99 QLabel *label = new QLabel( p_item->psz_text );
100 combo = new QComboBox();
101 combo->setEditable( false );
103 /* build a list of available modules */
104 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
105 combo->addItem( "Default" );
106 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
108 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
112 if( !strcmp( p_parser->psz_object_name, "main" ) ) continue;
114 module_config_t *p_config = p_parser->p_config;
117 /* Hack: required subcategory is stored in i_min */
118 if( p_config->i_type == CONFIG_SUBCATEGORY &&
119 p_config->i_value == p_item->i_min )
120 combo->addItem( p_parser->psz_longname,
121 QVariant( p_parser->psz_object_name ) );
122 if( p_item->psz_value && !strcmp( p_item->psz_value,
123 p_parser->psz_object_name) )
124 combo->setCurrentIndex( combo->count() - 1 );
125 } while( p_config->i_type != CONFIG_HINT_END && p_config++ );
127 else if( !strcmp( p_parser->psz_capability, p_item->psz_type ) )
129 combo->addItem( p_parser->psz_longname,
130 QVariant( p_parser->psz_object_name ) );
131 if( p_item->psz_value && !strcmp( p_item->psz_value,
132 p_parser->psz_object_name) )
133 combo->setCurrentIndex( combo->count() - 1 );
136 vlc_list_release( p_list );
137 combo->setToolTip( p_item->psz_longtext );
138 label->setToolTip( p_item->psz_longtext );
140 QHBoxLayout *layout = new QHBoxLayout();
141 layout->addWidget( label ); layout->addWidget( combo );
145 ModuleConfigControl::~ModuleConfigControl() {};
147 QString ModuleConfigControl::getValue()
149 return combo->itemData( combo->currentIndex() ).toString();