]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/preferences_widgets.cpp
Fix play/pause icons
[vlc] / modules / gui / qt4 / components / preferences_widgets.cpp
1 /*****************************************************************************
2  * preferences_widgets.cpp : Widgets for preferences displays
3  ****************************************************************************
4  * Copyright (C) 2006 the VideoLAN team
5  * $Id$
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24 /**
25  * Todo:
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
31  */
32
33 #include "components/preferences_widgets.hpp"
34 #include "qt4.hpp"
35 #include <QLineEdit>
36 #include <QString>
37 #include <QSpinBox>
38 #include <QDoubleSpinBox>
39 #include <QVariant>
40 #include <QComboBox>
41
42 ConfigControl *ConfigControl::createControl( vlc_object_t *p_this,
43                                              module_config_t *p_item,
44                                              QWidget *parent )
45 {
46     ConfigControl *p_control = NULL;
47     if( p_item->psz_current ) return NULL;
48
49     switch( p_item->i_type )
50     {
51     case CONFIG_ITEM_MODULE:
52         p_control = new ModuleConfigControl( p_this, p_item, parent, false );
53         break;
54     case CONFIG_ITEM_MODULE_CAT:
55         p_control = new ModuleConfigControl( p_this, p_item, parent, true );
56         break;
57     case CONFIG_ITEM_STRING:
58         if( !p_item->i_list )
59             p_control = new StringConfigControl( p_this, p_item, parent,false );
60         else
61             fprintf(stderr, "TODO\n" );
62         break;
63     case CONFIG_ITEM_INTEGER:
64         if( p_item->i_list )
65             fprintf( stderr, "Todo\n" );
66         else if( p_item->i_min || p_item->i_max )
67             fprintf( stderr, "Todo\n" );
68         else
69             p_control = new IntegerConfigControl( p_this, p_item, parent );
70         break;
71     default:
72         break;
73     }
74     return p_control;
75 }
76
77 /**************************************************************************
78  * String-based controls
79  *************************************************************************/
80
81 /*********** String **************/
82 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
83                                           module_config_t *_p_item,
84                                           QWidget *_parent, bool pwd ) :
85                            VStringConfigControl( _p_this, _p_item, _parent )
86 {
87     QLabel *label = new QLabel( qfu(p_item->psz_text) );
88     text = new QLineEdit( qfu(p_item->psz_value) );
89     finish(label);
90
91     QHBoxLayout *layout = new QHBoxLayout();
92     layout->addWidget( label, 0 ); layout->addWidget( text, 1 );
93     widget->setLayout( layout );
94 }
95
96 StringConfigControl::StringConfigControl( vlc_object_t *_p_this,
97                                    module_config_t *_p_item,
98                                    QLabel *label, QLineEdit *_text, bool pwd ):
99                            VStringConfigControl( _p_this, _p_item )
100 {
101     text = _text;
102     finish( label );
103 }
104
105 void StringConfigControl::finish( QLabel *label )
106 {
107     text->setText( qfu(p_item->psz_value) );
108     text->setToolTip( qfu(p_item->psz_longtext) );
109     label->setToolTip( qfu(p_item->psz_longtext) );
110 }
111
112 /********* Module **********/
113 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
114                 module_config_t *_p_item, QWidget *_parent,
115                 bool bycat ) : VStringConfigControl( _p_this, _p_item, _parent )
116 {
117     QLabel *label = new QLabel( qfu(p_item->psz_text) );
118     combo = new QComboBox();
119     finish( label, bycat );
120     QHBoxLayout *layout = new QHBoxLayout();
121     layout->addWidget( label ); layout->addWidget( combo );
122     widget->setLayout( layout );
123 }
124 ModuleConfigControl::ModuleConfigControl( vlc_object_t *_p_this,
125                 module_config_t *_p_item, QLabel *label, QComboBox *_combo,
126                 bool bycat ) : VStringConfigControl( _p_this, _p_item )
127 {
128     combo = _combo;
129     finish( label, bycat );
130 }
131
132 void ModuleConfigControl::finish( QLabel *label, bool bycat )
133 {
134     vlc_list_t *p_list;
135     module_t *p_parser;
136
137     combo->setEditable( false );
138
139     /* build a list of available modules */
140     p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
141     combo->addItem( qtr("Default") );
142     for( int i_index = 0; i_index < p_list->i_count; i_index++ )
143     {
144         p_parser = (module_t *)p_list->p_values[i_index].p_object ;
145
146         if( bycat )
147         {
148             if( !strcmp( p_parser->psz_object_name, "main" ) ) continue;
149
150             module_config_t *p_config = p_parser->p_config;
151             if( p_config ) do
152             {
153                 /* Hack: required subcategory is stored in i_min */
154                 if( p_config->i_type == CONFIG_SUBCATEGORY &&
155                     p_config->i_value == p_item->i_min )
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 );
161             } while( p_config->i_type != CONFIG_HINT_END && p_config++ );
162         }
163         else if( !strcmp( p_parser->psz_capability, p_item->psz_type ) )
164         {
165             combo->addItem( qfu(p_parser->psz_longname),
166                             QVariant( p_parser->psz_object_name ) );
167             if( p_item->psz_value && !strcmp( p_item->psz_value,
168                                               p_parser->psz_object_name) )
169                 combo->setCurrentIndex( combo->count() - 1 );
170         }
171     }
172     vlc_list_release( p_list );
173     combo->setToolTip( qfu(p_item->psz_longtext) );
174     label->setToolTip( qfu(p_item->psz_longtext) );
175 }
176
177 QString ModuleConfigControl::getValue()
178 {
179     return combo->itemData( combo->currentIndex() ).toString();
180 }
181
182 /**************************************************************************
183  * Integer-based controls
184  *************************************************************************/
185
186 /*********** Integer **************/
187 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
188                                             module_config_t *_p_item,
189                                             QWidget *_parent ) :
190                            VIntConfigControl( _p_this, _p_item, _parent )
191 {
192     QLabel *label = new QLabel( qfu(p_item->psz_text) );
193     spin = new QSpinBox;
194     finish( label );
195
196     QHBoxLayout *layout = new QHBoxLayout();
197     layout->addWidget( label, 0 ); layout->addWidget( spin, 1 );
198     widget->setLayout( layout );
199 }
200 IntegerConfigControl::IntegerConfigControl( vlc_object_t *_p_this,
201                                             module_config_t *_p_item,
202                                             QLabel *label, QSpinBox *_spin ) :
203                                       VIntConfigControl( _p_this, _p_item )
204 {
205     spin = _spin;
206     finish(label);
207 }
208
209 void IntegerConfigControl::finish( QLabel *label )
210 {
211     spin->setValue( p_item->i_value );
212     spin->setToolTip( qfu(p_item->psz_longtext) );
213     label->setToolTip( qfu(p_item->psz_longtext) );
214 }
215
216 int IntegerConfigControl::getValue()
217 {
218     return spin->value();
219 }