]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/preferences_widgets.hpp
Qt4- SImple Preferences. Add file and directory configuration.
[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  *          Jean-Baptiste Kempf <jb@videolan.org>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24  *****************************************************************************/
25
26 #ifndef _INFOPANELS_H_
27 #define _INFOPANELS_H_
28 #include <vlc/vlc.h>
29 #include <QWidget>
30 #include <QTreeWidget>
31 #include <QLineEdit>
32 #include <QSpinBox>
33 #include <QDoubleSpinBox>
34 #include <QComboBox>
35 #include <QCheckBox>
36 #include <QVector>
37 #include <QDialog>
38 #include <QLabel>
39 #include <QFile>
40 #include <QPushButton>
41
42 #include "qt4.hpp"
43 #include <assert.h>
44
45 class QGridLayout;
46
47 class ConfigControl : public QObject
48 {
49     Q_OBJECT;
50 public:
51     ConfigControl( vlc_object_t *_p_this, module_config_t *_p_conf,
52                    QWidget *p ) : p_this( _p_this ), p_item( _p_conf )
53     {
54         widget = new QWidget( p );
55     }
56     ConfigControl( vlc_object_t *_p_this, module_config_t *_p_conf ) :
57                             p_this (_p_this ), p_item( _p_conf )
58     {
59         widget = NULL;
60     }
61     virtual ~ConfigControl() {};
62     virtual int getType() = 0;
63     const char * getName() { return  p_item->psz_name; }
64     QWidget *getWidget() { assert( widget ); return widget; }
65     bool isAdvanced() { return p_item->b_advanced; }
66     virtual void hide() { getWidget()->hide(); };
67     virtual void show() { getWidget()->show(); };
68
69     static ConfigControl * createControl( vlc_object_t*,
70                                           module_config_t*,QWidget* );
71     static ConfigControl * createControl( vlc_object_t*,
72                                           module_config_t*,QWidget*,
73                                           QGridLayout *, int& );
74     void doApply( intf_thread_t *);
75 protected:
76     vlc_object_t *p_this;
77     module_config_t *p_item;
78     QString _name;
79     QWidget *widget;
80     bool _advanced;
81 signals:
82     void Updated();
83 };
84
85 /*******************************************************
86  * Integer-based controls
87  *******************************************************/
88 class VIntConfigControl : public ConfigControl
89 {
90 public:
91     VIntConfigControl( vlc_object_t *a, module_config_t *b, QWidget *c ) :
92             ConfigControl(a,b,c) {};
93     VIntConfigControl( vlc_object_t *a, module_config_t *b ) :
94                 ConfigControl(a,b) {};
95     virtual ~VIntConfigControl() {};
96     virtual int getValue() = 0;
97     virtual int getType() { return 1; }
98 };
99
100 class IntegerConfigControl : public VIntConfigControl
101 {
102 public:
103     IntegerConfigControl( vlc_object_t *, module_config_t *, QWidget *,
104                           QGridLayout *, int& );
105     IntegerConfigControl( vlc_object_t *, module_config_t *,
106                           QLabel*, QSpinBox* );
107     IntegerConfigControl( vlc_object_t *, module_config_t *,
108                           QLabel*, QSlider* );
109     virtual ~IntegerConfigControl() {};
110     virtual int getValue();
111     virtual void show() { spin->show(); label->show(); }
112     virtual void hide() { spin->hide(); label->hide(); }
113
114 protected:
115     QSpinBox *spin;
116 private:
117     QLabel *label;
118     void finish();
119 };
120
121 class IntegerRangeConfigControl : public IntegerConfigControl
122 {
123 public:
124     IntegerRangeConfigControl( vlc_object_t *, module_config_t *, QWidget *,
125                                QGridLayout *, int& );
126     IntegerRangeConfigControl( vlc_object_t *, module_config_t *,
127                                QLabel*, QSpinBox* );
128 private:
129     void finish();
130 };
131
132 class IntegerRangeSliderConfigControl : public VIntConfigControl
133 {
134 public:
135     IntegerRangeSliderConfigControl( vlc_object_t *, module_config_t *,
136                                 QLabel *, QSlider * );
137     virtual ~IntegerRangeSliderConfigControl() {};
138     virtual int getValue();
139 protected:
140          QSlider *slider;
141 private:
142          QLabel *label;
143          void finish();
144 };
145
146 class IntegerListConfigControl : public VIntConfigControl
147 {
148 public:
149     IntegerListConfigControl( vlc_object_t *, module_config_t *, QWidget *,
150                               bool, QGridLayout*, int& );
151     IntegerListConfigControl( vlc_object_t *, module_config_t *, QLabel *,
152                               QComboBox*, bool );
153     virtual ~IntegerListConfigControl() {};
154     virtual int getValue();
155     virtual void hide() { combo->hide(); label->hide(); }
156     virtual void show() { combo->show(); label->show(); }
157 private:
158     void finish( bool );
159     QLabel *label;
160     QComboBox *combo;
161 };
162
163 class BoolConfigControl : public VIntConfigControl
164 {
165 public:
166     BoolConfigControl( vlc_object_t *, module_config_t *, QWidget *,
167                        QGridLayout *, int& );
168     BoolConfigControl( vlc_object_t *, module_config_t *,
169                        QLabel *, QCheckBox*, bool );
170     virtual ~BoolConfigControl() {};
171     virtual int getValue();
172     virtual void show() { checkbox->show(); }
173     virtual void hide() { checkbox->hide(); }
174 private:
175     QCheckBox *checkbox;
176     void finish();
177 };
178
179 /*******************************************************
180  * Float-based controls
181  *******************************************************/
182 class VFloatConfigControl : public ConfigControl
183 {
184 public:
185     VFloatConfigControl( vlc_object_t *a, module_config_t *b, QWidget *c ) :
186                 ConfigControl(a,b,c) {};
187     VFloatConfigControl( vlc_object_t *a, module_config_t *b ) :
188                 ConfigControl(a,b) {};
189     virtual ~VFloatConfigControl() {};
190     virtual float getValue() = 0;
191     virtual int getType() { return 2; }
192 };
193
194 class FloatConfigControl : public VFloatConfigControl
195 {
196 public:
197     FloatConfigControl( vlc_object_t *, module_config_t *, QWidget *,
198                         QGridLayout *, int& );
199     FloatConfigControl( vlc_object_t *, module_config_t *,
200                         QLabel*, QDoubleSpinBox* );
201     virtual ~FloatConfigControl() {};
202     virtual float getValue();
203     virtual void show() { spin->show(); label->show(); }
204     virtual void hide() { spin->hide(); label->hide(); }
205
206 protected:
207     QDoubleSpinBox *spin;
208
209 private:
210     QLabel *label;
211     void finish();
212 };
213
214 class FloatRangeConfigControl : public FloatConfigControl
215 {
216 public:
217     FloatRangeConfigControl( vlc_object_t *, module_config_t *, QWidget *,
218                              QGridLayout *, int& );
219     FloatRangeConfigControl( vlc_object_t *, module_config_t *,
220                              QLabel*, QDoubleSpinBox* );
221 private:
222     void finish();
223 };
224
225 /*******************************************************
226  * String-based controls
227  *******************************************************/
228 class VStringConfigControl : public ConfigControl
229 {
230 public:
231     VStringConfigControl( vlc_object_t *a, module_config_t *b, QWidget *c ) :
232                 ConfigControl(a,b,c) {};
233     VStringConfigControl( vlc_object_t *a, module_config_t *b ) :
234                 ConfigControl(a,b) {};
235     virtual ~VStringConfigControl() {};
236     virtual QString getValue() = 0;
237     virtual int getType() { return 3; }
238 };
239
240 class StringConfigControl : public VStringConfigControl
241 {
242 public:
243     StringConfigControl( vlc_object_t *, module_config_t *, QWidget *,
244                          QGridLayout *, int&,  bool pwd );
245     StringConfigControl( vlc_object_t *, module_config_t *, QLabel *,
246                          QLineEdit*,  bool pwd );
247     virtual ~StringConfigControl() {};
248     virtual QString getValue() { return text->text(); };
249     virtual void show() { text->show(); label->show(); }
250     virtual void hide() { text->hide(); label->hide(); }
251 private:
252     void finish();
253     QLineEdit *text;
254     QLabel *label;
255 };
256
257 class FileConfigControl : public VStringConfigControl
258 {
259     Q_OBJECT;
260 public:
261     FileConfigControl( vlc_object_t *, module_config_t *, QWidget *,
262                          QGridLayout *, int&, bool pwd );
263     FileConfigControl( vlc_object_t *, module_config_t *, QLabel *,
264                         QLineEdit *, QPushButton *, bool pwd );
265     virtual ~FileConfigControl() {};
266     virtual QString getValue() { return text->text(); };
267     virtual void show() { text->show(); label->show(); browse->show(); }
268     virtual void hide() { text->hide(); label->hide(); browse->hide(); }
269 public slots:
270     void updateField();
271 protected:
272     void finish();
273 private:
274     QLineEdit *text;
275     QLabel *label;
276     QPushButton *browse;
277 };
278
279 class DirectoryConfigControl : public FileConfigControl
280 {
281     Q_OBJECT;
282 public:
283     DirectoryConfigControl( vlc_object_t *, module_config_t *, QWidget *,
284                          QGridLayout *, int&, bool pwd );
285     DirectoryConfigControl( vlc_object_t *, module_config_t *, QLabel *,
286                         QLineEdit *, QPushButton *, bool pwd );
287     virtual ~DirectoryConfigControl() {};
288     virtual QString getValue() { return text->text(); };
289     virtual void show() { text->show(); label->show(); browse->show(); }
290     virtual void hide() { text->hide(); label->hide(); browse->hide(); }
291 public slots:
292     void updateField();
293 private:
294     QLineEdit *text;
295     QLabel *label;
296     QPushButton *browse;
297 };
298
299 class ModuleConfigControl : public VStringConfigControl
300 {
301 public:
302     ModuleConfigControl( vlc_object_t *, module_config_t *, QWidget *, bool,
303                          QGridLayout*, int& );
304     ModuleConfigControl( vlc_object_t *, module_config_t *, QLabel *,
305                          QComboBox*, bool );
306     virtual ~ModuleConfigControl() {};
307     virtual QString getValue();
308     virtual void hide() { combo->hide(); label->hide(); }
309     virtual void show() { combo->show(); label->show(); }
310 private:
311     void finish( bool );
312     QLabel *label;
313     QComboBox *combo;
314 };
315
316 class ModuleListConfigControl : public VStringConfigControl
317 {
318     Q_OBJECT;
319 public:
320     ModuleListConfigControl( vlc_object_t *, module_config_t *, QWidget *,
321                              bool, QGridLayout*, int& );
322 //    ModuleListConfigControl( vlc_object_t *, module_config_t *, QLabel *,
323 //                         QComboBox*, bool );
324     virtual ~ModuleListConfigControl();
325     virtual QString getValue();
326     virtual void hide();
327     virtual void show();
328 public slots:
329     void wakeUp_TheUserJustClickedOnSomething( int value );
330 private:
331     void finish( bool );
332     QVector<QCheckBox*> modules;
333     QLabel *label;
334     QLineEdit *text;
335 };
336
337 class StringListConfigControl : public VStringConfigControl
338 {
339 public:
340     StringListConfigControl( vlc_object_t *, module_config_t *, QWidget *,
341                              bool, QGridLayout*, int& );
342     StringListConfigControl( vlc_object_t *, module_config_t *, QLabel *,
343                              QComboBox*, bool );
344     virtual ~StringListConfigControl() {};
345     virtual QString getValue();
346     virtual void hide() { combo->hide(); label->hide(); }
347     virtual void show() { combo->show(); label->show(); }
348 private:
349     void finish( bool );
350     QLabel *label;
351     QComboBox *combo;
352 };
353 #if 0
354 struct ModuleCheckBox {
355     QCheckBox *checkbox;
356     QString module;
357 };
358
359 class ModuleListConfigControl : public ConfigControl
360 {
361 public:
362     StringConfigControl( vlc_object_t *, module_config_t *, QWidget *, bool
363                          bycat );
364     virtual ~StringConfigControl();
365     virtual QString getValue();
366 private:
367     std::vector<ModuleCheckBox> checkboxes;
368     QLineEdit *text;
369 private slot:
370     void OnUpdate();
371 };
372 #endif
373
374 /**********************************************************************
375  * Key selector widget
376  **********************************************************************/
377 class KeyInputDialog : public QDialog
378 {
379 public:
380     KeyInputDialog( QList<module_config_t *> &, const char * );
381     int keyValue;
382     bool conflicts;
383 private:
384     void keyPressEvent( QKeyEvent *);
385     QLabel *selected;
386     QLabel *warning;
387     const char * keyToChange;
388     QList<module_config_t*> values;
389 };
390
391 class KeySelectorControl : public ConfigControl
392 {
393     Q_OBJECT;
394 public:
395     KeySelectorControl( vlc_object_t *, module_config_t *, QWidget *,
396                         QGridLayout*, int& );
397     virtual int getType() { return 4; }
398     virtual ~KeySelectorControl() {};
399     virtual void hide() { table->hide(); label->hide(); }
400     virtual void show() { table->show(); label->show(); }
401     void doApply();
402 private:
403     void finish();
404     QLabel *label;
405     QTreeWidget *table;
406     QList<module_config_t *> values;
407 private slots:
408     void selectKey( QTreeWidgetItem *);
409 };
410
411 #endif