]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/preferences_widgets.hpp
Qt4 - Preferences and SPrefs. Add the necessary handler for CONFIG_FILE_ITEMs.
[vlc] / modules / gui / qt4 / components / preferences_widgets.hpp
1 /*****************************************************************************
2  * preferences_widgets.hpp : Widgets for preferences panels
3  ****************************************************************************
4  * Copyright (C) 2006 the VideoLAN team
5  * $Id$
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
8  *          Antoine Cellerier <dionoea@videolan.org>
9  *
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.
14  *
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.
19  *
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  *****************************************************************************/
24
25 #ifndef _INFOPANELS_H_
26 #define _INFOPANELS_H_
27 #include <vlc/vlc.h>
28 #include <QWidget>
29 #include <QTreeWidget>
30 #include <QLineEdit>
31 #include <QSpinBox>
32 #include <QDoubleSpinBox>
33 #include <QComboBox>
34 #include <QCheckBox>
35 #include <QVector>
36 #include <QDialog>
37 #include <QLabel>
38 #include <QFile>
39
40 #include "qt4.hpp"
41 #include <assert.h>
42
43 class QGridLayout;
44
45 class ConfigControl : public QObject
46 {
47     Q_OBJECT;
48 public:
49     ConfigControl( vlc_object_t *_p_this, module_config_t *_p_conf,
50                    QWidget *p ) : p_this( _p_this ), p_item( _p_conf )
51     {
52         widget = new QWidget( p );
53     }
54     ConfigControl( vlc_object_t *_p_this, module_config_t *_p_conf ) :
55                             p_this (_p_this ), p_item( _p_conf )
56     {
57         widget = NULL;
58     }
59     virtual ~ConfigControl() {};
60     virtual int getType() = 0;
61     const char * getName() { return  p_item->psz_name; }
62     QWidget *getWidget() { assert( widget ); return widget; }
63     bool isAdvanced() { return p_item->b_advanced; }
64     virtual void hide() { getWidget()->hide(); };
65     virtual void show() { getWidget()->show(); };
66
67     static ConfigControl * createControl( vlc_object_t*,
68                                           module_config_t*,QWidget* );
69     static ConfigControl * createControl( vlc_object_t*,
70                                           module_config_t*,QWidget*,
71                                           QGridLayout *, int& );
72     void doApply( intf_thread_t *);
73 protected:
74     vlc_object_t *p_this;
75     module_config_t *p_item;
76     QString _name;
77     QWidget *widget;
78     bool _advanced;
79 signals:
80     void Updated();
81 };
82
83 /*******************************************************
84  * Integer-based controls
85  *******************************************************/
86 class VIntConfigControl : public ConfigControl
87 {
88 public:
89     VIntConfigControl( vlc_object_t *a, module_config_t *b, QWidget *c ) :
90             ConfigControl(a,b,c) {};
91     VIntConfigControl( vlc_object_t *a, module_config_t *b ) :
92                 ConfigControl(a,b) {};
93     virtual ~VIntConfigControl() {};
94     virtual int getValue() = 0;
95     virtual int getType() { return 1; }
96 };
97
98 class IntegerConfigControl : public VIntConfigControl
99 {
100 public:
101     IntegerConfigControl( vlc_object_t *, module_config_t *, QWidget *,
102                           QGridLayout *, int& );
103     IntegerConfigControl( vlc_object_t *, module_config_t *,
104                           QLabel*, QSpinBox* );
105     IntegerConfigControl( vlc_object_t *, module_config_t *,
106                           QLabel*, QSlider* );
107     virtual ~IntegerConfigControl() {};
108     virtual int getValue();
109     virtual void show() { spin->show(); label->show(); }
110     virtual void hide() { spin->hide(); label->hide(); }
111
112 protected:
113     QSpinBox *spin;
114 private:
115     QLabel *label;
116     void finish();
117 };
118
119 class IntegerRangeConfigControl : public IntegerConfigControl
120 {
121 public:
122     IntegerRangeConfigControl( vlc_object_t *, module_config_t *, QWidget *,
123                                QGridLayout *, int& );
124     IntegerRangeConfigControl( vlc_object_t *, module_config_t *,
125                                QLabel*, QSpinBox* );
126 private:
127     void finish();
128 };
129
130 class IntegerRangeSliderConfigControl : public VIntConfigControl
131 {
132 public:
133     IntegerRangeSliderConfigControl( vlc_object_t *, module_config_t *,
134                                 QLabel *, QSlider * );
135     virtual ~IntegerRangeSliderConfigControl() {};
136     virtual int getValue();
137 protected:
138          QSlider *slider;
139 private:
140          QLabel *label;
141          void finish();
142 };
143
144 class IntegerListConfigControl : public VIntConfigControl
145 {
146 public:
147     IntegerListConfigControl( vlc_object_t *, module_config_t *, QWidget *,
148                               bool, QGridLayout*, int& );
149     IntegerListConfigControl( vlc_object_t *, module_config_t *, QLabel *,
150                               QComboBox*, bool );
151     virtual ~IntegerListConfigControl() {};
152     virtual int getValue();
153     virtual void hide() { combo->hide(); label->hide(); }
154     virtual void show() { combo->show(); label->show(); }
155 private:
156     void finish( bool );
157     QLabel *label;
158     QComboBox *combo;
159 };
160
161 class BoolConfigControl : public VIntConfigControl
162 {
163 public:
164     BoolConfigControl( vlc_object_t *, module_config_t *, QWidget *,
165                        QGridLayout *, int& );
166     BoolConfigControl( vlc_object_t *, module_config_t *,
167                        QLabel *, QCheckBox*, bool );
168     virtual ~BoolConfigControl() {};
169     virtual int getValue();
170     virtual void show() { checkbox->show(); }
171     virtual void hide() { checkbox->hide(); }
172 private:
173     QCheckBox *checkbox;
174     void finish();
175 };
176
177 /*******************************************************
178  * Float-based controls
179  *******************************************************/
180 class VFloatConfigControl : public ConfigControl
181 {
182 public:
183     VFloatConfigControl( vlc_object_t *a, module_config_t *b, QWidget *c ) :
184                 ConfigControl(a,b,c) {};
185     VFloatConfigControl( vlc_object_t *a, module_config_t *b ) :
186                 ConfigControl(a,b) {};
187     virtual ~VFloatConfigControl() {};
188     virtual float getValue() = 0;
189     virtual int getType() { return 2; }
190 };
191
192 class FloatConfigControl : public VFloatConfigControl
193 {
194 public:
195     FloatConfigControl( vlc_object_t *, module_config_t *, QWidget *,
196                         QGridLayout *, int& );
197     FloatConfigControl( vlc_object_t *, module_config_t *,
198                         QLabel*, QDoubleSpinBox* );
199     virtual ~FloatConfigControl() {};
200     virtual float getValue();
201     virtual void show() { spin->show(); label->show(); }
202     virtual void hide() { spin->hide(); label->hide(); }
203
204 protected:
205     QDoubleSpinBox *spin;
206
207 private:
208     QLabel *label;
209     void finish();
210 };
211
212 class FloatRangeConfigControl : public FloatConfigControl
213 {
214 public:
215     FloatRangeConfigControl( vlc_object_t *, module_config_t *, QWidget *,
216                              QGridLayout *, int& );
217     FloatRangeConfigControl( vlc_object_t *, module_config_t *,
218                              QLabel*, QDoubleSpinBox* );
219 private:
220     void finish();
221 };
222
223 /*******************************************************
224  * String-based controls
225  *******************************************************/
226 class VStringConfigControl : public ConfigControl
227 {
228 public:
229     VStringConfigControl( vlc_object_t *a, module_config_t *b, QWidget *c ) :
230                 ConfigControl(a,b,c) {};
231     VStringConfigControl( vlc_object_t *a, module_config_t *b ) :
232                 ConfigControl(a,b) {};
233     virtual ~VStringConfigControl() {};
234     virtual QString getValue() = 0;
235     virtual int getType() { return 3; }
236 };
237
238 class StringConfigControl : public VStringConfigControl
239 {
240 public:
241     StringConfigControl( vlc_object_t *, module_config_t *, QWidget *,
242                          QGridLayout *, int&,  bool pwd );
243     StringConfigControl( vlc_object_t *, module_config_t *, QLabel *,
244                          QLineEdit*,  bool pwd );
245     virtual ~StringConfigControl() {};
246     virtual QString getValue() { return text->text(); };
247     virtual void show() { text->show(); label->show(); }
248     virtual void hide() { text->hide(); label->hide(); }
249 private:
250     void finish();
251     QLineEdit *text;
252     QLabel *label;
253 };
254
255 class FileConfigControl : public VStringConfigControl
256 {
257     Q_OBJECT;
258 public:
259     FileConfigControl( vlc_object_t *, module_config_t *, QWidget *,
260                          QGridLayout *, int&, bool pwd );
261     FileConfigControl( vlc_object_t *, module_config_t *, QLabel *,
262                         QLineEdit*, bool pwd );
263     virtual ~FileConfigControl() {};
264     virtual QString getValue() { return text->text(); };
265     virtual void show() { text->show(); label->show(); }
266     virtual void hide() { text->hide(); label->hide(); }
267 public slots: 
268     void updateField();
269 private:
270     void finish();
271     QLineEdit *text;
272     QLabel *label;
273     QPushButton *browse;
274 };
275
276
277 class ModuleConfigControl : public VStringConfigControl
278 {
279 public:
280     ModuleConfigControl( vlc_object_t *, module_config_t *, QWidget *, bool,
281                          QGridLayout*, int& );
282     ModuleConfigControl( vlc_object_t *, module_config_t *, QLabel *,
283                          QComboBox*, bool );
284     virtual ~ModuleConfigControl() {};
285     virtual QString getValue();
286     virtual void hide() { combo->hide(); label->hide(); }
287     virtual void show() { combo->show(); label->show(); }
288 private:
289     void finish( bool );
290     QLabel *label;
291     QComboBox *combo;
292 };
293
294 class ModuleListConfigControl : public VStringConfigControl
295 {
296     Q_OBJECT;
297 public:
298     ModuleListConfigControl( vlc_object_t *, module_config_t *, QWidget *,
299                              bool, QGridLayout*, int& );
300 //    ModuleListConfigControl( vlc_object_t *, module_config_t *, QLabel *,
301 //                         QComboBox*, bool );
302     virtual ~ModuleListConfigControl();
303     virtual QString getValue();
304     virtual void hide();
305     virtual void show();
306 public slots:
307     void wakeUp_TheUserJustClickedOnSomething( int value );
308 private:
309     void finish( bool );
310     QVector<QCheckBox*> modules;
311     QLabel *label;
312     QLineEdit *text;
313 };
314
315 class StringListConfigControl : public VStringConfigControl
316 {
317 public:
318     StringListConfigControl( vlc_object_t *, module_config_t *, QWidget *,
319                              bool, QGridLayout*, int& );
320     StringListConfigControl( vlc_object_t *, module_config_t *, QLabel *,
321                              QComboBox*, bool );
322     virtual ~StringListConfigControl() {};
323     virtual QString getValue();
324     virtual void hide() { combo->hide(); label->hide(); }
325     virtual void show() { combo->show(); label->show(); }
326 private:
327     void finish( bool );
328     QLabel *label;
329     QComboBox *combo;
330 };
331 #if 0
332 struct ModuleCheckBox {
333     QCheckBox *checkbox;
334     QString module;
335 };
336
337 class ModuleListConfigControl : public ConfigControl
338 {
339 public:
340     StringConfigControl( vlc_object_t *, module_config_t *, QWidget *, bool
341                          bycat );
342     virtual ~StringConfigControl();
343     virtual QString getValue();
344 private:
345     std::vector<ModuleCheckBox> checkboxes;
346     QLineEdit *text;
347 private slot:
348     void OnUpdate();
349 };
350 #endif
351
352 /**********************************************************************
353  * Key selector widget
354  **********************************************************************/
355 class KeyInputDialog : public QDialog
356 {
357 public:
358     KeyInputDialog( QList<module_config_t *> &, const char * );
359     int keyValue;
360     bool conflicts;
361 private:
362     void keyPressEvent( QKeyEvent *);
363     QLabel *selected;
364     QLabel *warning;
365     const char * keyToChange;
366     QList<module_config_t*> values;
367 };
368
369 class KeySelectorControl : public ConfigControl
370 {
371     Q_OBJECT;
372 public:
373     KeySelectorControl( vlc_object_t *, module_config_t *, QWidget *,
374                         QGridLayout*, int& );
375     virtual int getType() { return 4; }
376     virtual ~KeySelectorControl() {};
377     virtual void hide() { table->hide(); label->hide(); }
378     virtual void show() { table->show(); label->show(); }
379     void doApply();
380 private:
381     void finish();
382     QLabel *label;
383     QTreeWidget *table;
384     QList<module_config_t *> values;
385 private slots:
386     void selectKey( QTreeWidgetItem *);
387 };
388
389 #endif