]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/preferences_widgets.hpp
Qt4 - Pref: start to track functionnalities missing. Directory still segfaults..
[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 Q_OBJECT
91 public:
92     VIntConfigControl( vlc_object_t *a, module_config_t *b, QWidget *c ) :
93             ConfigControl(a,b,c) {};
94     VIntConfigControl( vlc_object_t *a, module_config_t *b ) :
95                 ConfigControl(a,b) {};
96     virtual ~VIntConfigControl() {};
97     virtual int getValue() = 0;
98     virtual int getType() { return 1; }
99 };
100
101 class IntegerConfigControl : public VIntConfigControl
102 {
103 Q_OBJECT
104 public:
105     IntegerConfigControl( vlc_object_t *, module_config_t *, QWidget *,
106                           QGridLayout *, int& );
107     IntegerConfigControl( vlc_object_t *, module_config_t *,
108                           QLabel*, QSpinBox* );
109     IntegerConfigControl( vlc_object_t *, module_config_t *,
110                           QLabel*, QSlider* );
111     virtual ~IntegerConfigControl() {};
112     virtual int getValue();
113     virtual void show() { spin->show(); label->show(); }
114     virtual void hide() { spin->hide(); label->hide(); }
115
116 protected:
117     QSpinBox *spin;
118 private:
119     QLabel *label;
120     void finish();
121 };
122
123 class IntegerRangeConfigControl : public IntegerConfigControl
124 {
125 public:
126     IntegerRangeConfigControl( vlc_object_t *, module_config_t *, QWidget *,
127                                QGridLayout *, int& );
128     IntegerRangeConfigControl( vlc_object_t *, module_config_t *,
129                                QLabel*, QSpinBox* );
130 private:
131     void finish();
132 };
133
134 class IntegerRangeSliderConfigControl : public VIntConfigControl
135 {
136 public:
137     IntegerRangeSliderConfigControl( vlc_object_t *, module_config_t *,
138                                 QLabel *, QSlider * );
139     virtual ~IntegerRangeSliderConfigControl() {};
140     virtual int getValue();
141 protected:
142          QSlider *slider;
143 private:
144          QLabel *label;
145          void finish();
146 };
147
148 class IntegerListConfigControl : public VIntConfigControl
149 {
150 public:
151     IntegerListConfigControl( vlc_object_t *, module_config_t *, QWidget *,
152                               bool, QGridLayout*, int& );
153     IntegerListConfigControl( vlc_object_t *, module_config_t *, QLabel *,
154                               QComboBox*, bool );
155     virtual ~IntegerListConfigControl() {};
156     virtual int getValue();
157     virtual void hide() { combo->hide(); label->hide(); }
158     virtual void show() { combo->show(); label->show(); }
159 private:
160     void finish( bool );
161     QLabel *label;
162     QComboBox *combo;
163 };
164
165 class BoolConfigControl : public VIntConfigControl
166 {
167 public:
168     BoolConfigControl( vlc_object_t *, module_config_t *, QWidget *,
169                        QGridLayout *, int& );
170     BoolConfigControl( vlc_object_t *, module_config_t *,
171                        QLabel *, QCheckBox*, bool );
172     virtual ~BoolConfigControl() {};
173     virtual int getValue();
174     virtual void show() { checkbox->show(); }
175     virtual void hide() { checkbox->hide(); }
176 private:
177     QCheckBox *checkbox;
178     void finish();
179 };
180
181 /*******************************************************
182  * Float-based controls
183  *******************************************************/
184 class VFloatConfigControl : public ConfigControl
185 {
186     Q_OBJECT
187 public:
188     VFloatConfigControl( vlc_object_t *a, module_config_t *b, QWidget *c ) :
189                 ConfigControl(a,b,c) {};
190     VFloatConfigControl( vlc_object_t *a, module_config_t *b ) :
191                 ConfigControl(a,b) {};
192     virtual ~VFloatConfigControl() {};
193     virtual float getValue() = 0;
194     virtual int getType() { return 2; }
195 };
196
197 class FloatConfigControl : public VFloatConfigControl
198 {
199     Q_OBJECT
200 public:
201     FloatConfigControl( vlc_object_t *, module_config_t *, QWidget *,
202                         QGridLayout *, int& );
203     FloatConfigControl( vlc_object_t *, module_config_t *,
204                         QLabel*, QDoubleSpinBox* );
205     virtual ~FloatConfigControl() {};
206     virtual float getValue();
207     virtual void show() { spin->show(); label->show(); }
208     virtual void hide() { spin->hide(); label->hide(); }
209
210 protected:
211     QDoubleSpinBox *spin;
212
213 private:
214     QLabel *label;
215     void finish();
216 };
217
218 class FloatRangeConfigControl : public FloatConfigControl
219 {
220     Q_OBJECT
221 public:
222     FloatRangeConfigControl( vlc_object_t *, module_config_t *, QWidget *,
223                              QGridLayout *, int& );
224     FloatRangeConfigControl( vlc_object_t *, module_config_t *,
225                              QLabel*, QDoubleSpinBox* );
226 private:
227     void finish();
228 };
229
230 /*******************************************************
231  * String-based controls
232  *******************************************************/
233 class VStringConfigControl : public ConfigControl
234 {
235     Q_OBJECT
236 public:
237     VStringConfigControl( vlc_object_t *a, module_config_t *b, QWidget *c ) :
238                 ConfigControl(a,b,c) {};
239     VStringConfigControl( vlc_object_t *a, module_config_t *b ) :
240                 ConfigControl(a,b) {};
241     virtual ~VStringConfigControl() {};
242     virtual QString getValue() = 0;
243     virtual int getType() { return 3; }
244 };
245
246 class StringConfigControl : public VStringConfigControl
247 {
248     Q_OBJECT
249 public:
250     StringConfigControl( vlc_object_t *, module_config_t *, QWidget *,
251                          QGridLayout *, int&,  bool pwd );
252     StringConfigControl( vlc_object_t *, module_config_t *, QLabel *,
253                          QLineEdit*,  bool pwd );
254     virtual ~StringConfigControl() {};
255     virtual QString getValue() { return text->text(); };
256     virtual void show() { text->show(); label->show(); }
257     virtual void hide() { text->hide(); label->hide(); }
258 private:
259     void finish();
260     QLineEdit *text;
261     QLabel *label;
262 };
263
264 class FileConfigControl : public VStringConfigControl
265 {
266     Q_OBJECT;
267 public:
268     FileConfigControl( vlc_object_t *, module_config_t *, QWidget *,
269                          QGridLayout *, int&, bool pwd );
270     FileConfigControl( vlc_object_t *, module_config_t *, QLabel *,
271                         QLineEdit *, QPushButton *, bool pwd );
272     virtual ~FileConfigControl() {};
273     virtual QString getValue() { return text->text(); };
274     virtual void show() { text->show(); label->show(); browse->show(); }
275     virtual void hide() { text->hide(); label->hide(); browse->hide(); }
276 public slots:
277     virtual void updateField();
278 protected:
279     void finish();
280 private:
281     QLineEdit *text;
282     QLabel *label;
283     QPushButton *browse;
284 };
285
286 class DirectoryConfigControl : public FileConfigControl
287 {
288     Q_OBJECT;
289 public:
290     DirectoryConfigControl( vlc_object_t *, module_config_t *, QWidget *,
291                          QGridLayout *, int&, bool pwd );
292     DirectoryConfigControl( vlc_object_t *, module_config_t *, QLabel *,
293                         QLineEdit *, QPushButton *, bool pwd );
294     virtual ~DirectoryConfigControl() {};
295     virtual QString getValue() { return text->text(); };
296     virtual void show() { text->show(); label->show(); browse->show(); }
297     virtual void hide() { text->hide(); label->hide(); browse->hide(); }
298 public slots:
299     virtual void updateField();
300 private:
301     QLineEdit *text;
302     QLabel *label;
303     QPushButton *browse;
304 };
305
306 class ModuleConfigControl : public VStringConfigControl
307 {
308 public:
309     ModuleConfigControl( vlc_object_t *, module_config_t *, QWidget *, bool,
310                          QGridLayout*, int& );
311     ModuleConfigControl( vlc_object_t *, module_config_t *, QLabel *,
312                          QComboBox*, bool );
313     virtual ~ModuleConfigControl() {};
314     virtual QString getValue();
315     virtual void hide() { combo->hide(); label->hide(); }
316     virtual void show() { combo->show(); label->show(); }
317 private:
318     void finish( bool );
319     QLabel *label;
320     QComboBox *combo;
321 };
322
323 class ModuleListConfigControl : public VStringConfigControl
324 {
325     Q_OBJECT;
326 public:
327     ModuleListConfigControl( vlc_object_t *, module_config_t *, QWidget *,
328                              bool, QGridLayout*, int& );
329 //    ModuleListConfigControl( vlc_object_t *, module_config_t *, QLabel *,
330 //                         QComboBox*, bool );
331     virtual ~ModuleListConfigControl();
332     virtual QString getValue();
333     virtual void hide();
334     virtual void show();
335 public slots:
336     void wakeUp_TheUserJustClickedOnSomething( int value );
337 private:
338     void finish( bool );
339     QVector<QCheckBox*> modules;
340     QLabel *label;
341     QLineEdit *text;
342 };
343
344 class StringListConfigControl : public VStringConfigControl
345 {
346 public:
347     StringListConfigControl( vlc_object_t *, module_config_t *, QWidget *,
348                              bool, QGridLayout*, int& );
349     StringListConfigControl( vlc_object_t *, module_config_t *, QLabel *,
350                              QComboBox*, bool );
351     virtual ~StringListConfigControl() {};
352     virtual QString getValue();
353     virtual void hide() { combo->hide(); label->hide(); }
354     virtual void show() { combo->show(); label->show(); }
355 private:
356     void finish( bool );
357     QLabel *label;
358     QComboBox *combo;
359 };
360 #if 0
361 struct ModuleCheckBox {
362     QCheckBox *checkbox;
363     QString module;
364 };
365
366 class ModuleListConfigControl : public ConfigControl
367 {
368 public:
369     StringConfigControl( vlc_object_t *, module_config_t *, QWidget *, bool
370                          bycat );
371     virtual ~StringConfigControl();
372     virtual QString getValue();
373 private:
374     std::vector<ModuleCheckBox> checkboxes;
375     QLineEdit *text;
376 private slot:
377     void OnUpdate();
378 };
379 #endif
380
381 /**********************************************************************
382  * Key selector widget
383  **********************************************************************/
384 class KeyInputDialog : public QDialog
385 {
386 public:
387     KeyInputDialog( QList<module_config_t *> &, const char * );
388     int keyValue;
389     bool conflicts;
390 private:
391     void keyPressEvent( QKeyEvent *);
392     QLabel *selected;
393     QLabel *warning;
394     const char * keyToChange;
395     QList<module_config_t*> values;
396 };
397
398 class KeySelectorControl : public ConfigControl
399 {
400     Q_OBJECT;
401 public:
402     KeySelectorControl( vlc_object_t *, module_config_t *, QWidget *,
403                         QGridLayout*, int& );
404     virtual int getType() { return 4; }
405     virtual ~KeySelectorControl() {};
406     virtual void hide() { table->hide(); label->hide(); }
407     virtual void show() { table->show(); label->show(); }
408     void doApply();
409 private:
410     void finish();
411     QLabel *label;
412     QTreeWidget *table;
413     QList<module_config_t *> values;
414 private slots:
415     void selectKey( QTreeWidgetItem *);
416 };
417
418 #endif