]> git.sesse.net Git - vlc/blob - plugins/kde/kde_preferences.cpp
* ALL: got rid of p_object->p_this which is now useless.
[vlc] / plugins / kde / kde_preferences.cpp
1 #include <kdialogbase.h>
2 #include <qmap.h>
3 #include <qcheckbox.h>
4 #include <qframe.h>
5 #include <qgroupbox.h>
6 #include <qlayout.h>
7 #include <qlabel.h>
8 #include <qlistview.h>
9 #include <qnamespace.h>
10 #include <qobjectlist.h>
11 #include <qspinbox.h>
12 #include <qtooltip.h>
13 #include <qvbox.h>
14
15 #include <kbuttonbox.h>
16 #include <klineedit.h>
17 #include <klocale.h>
18 #include <knuminput.h>
19
20 #include "QConfigItem.h"
21 #include "kde_pluginsbox.h"
22 #include "kde_preferences.h"
23
24 /*
25  construkt a new configuration window for the given module
26 */
27 KPreferences::KPreferences(intf_thread_t *p_intf, const char *psz_module_name,
28                            QWidget *parent, const QString &caption) :
29     KDialogBase ( Tabbed, caption, Ok| Apply|Cancel|User1, Ok, parent,
30                   "vlc preferences", true, false, "Save")
31 {
32     module_t *p_module, *p_module_bis;
33     module_config_t *p_item;
34     QVBox *category_table = NULL;
35     QString *category_label;
36
37     this->p_intf = p_intf;
38
39     /* Look for the selected module */
40     for( p_module = p_intf->p_vlc->module_bank.first ; p_module != NULL ;
41          p_module = p_module->next )
42     {
43
44         if( psz_module_name && !strcmp( psz_module_name, p_module->psz_name ) )
45             break;
46     }
47     if( !p_module ) return;
48     p_item = p_module->p_config;
49     do
50     {
51         switch( p_item->i_type )
52         {
53
54         case MODULE_CONFIG_HINT_CATEGORY:
55         case MODULE_CONFIG_HINT_END:
56
57             /*
58              * Now we can start taking care of the new category
59              */
60             if( p_item->i_type == MODULE_CONFIG_HINT_CATEGORY )
61             {
62                 category_label = new QString( p_item->psz_text );
63                 QFrame *page = addPage( *category_label );
64                 QVBoxLayout *toplayout = new QVBoxLayout( page);
65                 QScrollView *sv = new QScrollView(page);
66                 sv->setResizePolicy(QScrollView::AutoOneFit);
67                 sv->setFrameStyle(QScrollView::NoFrame);
68                 toplayout->addWidget(sv);
69                 category_table = new QVBox(sv->viewport());
70                 sv->addChild(category_table);
71                 toplayout->addStretch(10);
72                 category_table->setSpacing(spacingHint());
73             }
74
75             break;
76
77         case MODULE_CONFIG_ITEM_MODULE:
78
79             {
80                 
81                 vlc_mutex_lock( p_item->p_lock );
82                 KPluginsBox *item_frame =
83                     new KPluginsBox( p_intf, p_item->psz_text,
84                                      p_item->psz_value ? p_item->psz_value :"",
85                                      category_table,
86                                      spacingHint(),
87                                      this );
88                 QConfigItem *ci = new QConfigItem(this,
89                                                   p_item->psz_name,
90                                                   p_item->i_type,
91                                                   p_item->psz_value);
92                 connect(item_frame, SIGNAL(selectionChanged(const QString &)),
93                         ci, SLOT(setValue(const QString &)));
94
95                 
96                 /* build a list of available plugins */
97                 
98                 for( p_module_bis = p_intf->p_vlc->module_bank.first ;
99                      p_module_bis != NULL ;
100                      p_module_bis = p_module_bis->next ) {
101                     if( p_module_bis->i_capabilities & (1 << p_item->i_value)){
102                         new QListViewItem(item_frame->getListView(),
103                                           p_module_bis->psz_name,
104                                           p_module_bis->psz_longname);
105                     }
106                 }
107                 vlc_mutex_unlock( p_item->p_lock );
108             }
109             break;
110
111         case MODULE_CONFIG_ITEM_STRING:
112         case MODULE_CONFIG_ITEM_FILE:
113
114             {
115                 QHBox *hb = new QHBox(category_table);
116                 hb->setSpacing(spacingHint());
117                 new QLabel(p_item->psz_text, hb);
118                 /* add input box with default value */
119                 vlc_mutex_lock( p_item->p_lock );
120                 
121                 KLineEdit *kl = new KLineEdit( p_item->psz_value ?
122                                                p_item->psz_value : "", hb);
123                 QConfigItem *ci = new QConfigItem(this, p_item->psz_name,
124                                                   p_item->i_type,
125                                                   p_item->psz_value ?
126                                                   p_item->psz_value : "");
127                 connect(kl, SIGNAL(textChanged ( const QString & )),
128                         ci, SLOT(setValue( const QString &)));
129                 QToolTip::add(kl, p_item->psz_longtext);
130                 kl->setMaxLength(10);
131                 
132                 vlc_mutex_unlock( p_item->p_lock );
133                 
134             }
135             break;
136
137         case MODULE_CONFIG_ITEM_INTEGER:
138             /* add input box with default value */
139             {
140                 QHBox *hb = new QHBox(category_table);
141                 hb->setSpacing(spacingHint());
142                 new QLabel(p_item->psz_text, hb);                
143                 QSpinBox *item_adj = new QSpinBox(-1, 99999, 1, hb);
144                 QConfigItem *ci = new QConfigItem(this, p_item->psz_name,
145                                                   p_item->i_type,
146                                                   p_item->i_value);
147                 connect(item_adj, SIGNAL(valueChanged( int)),
148                         ci, SLOT(setValue(int)));
149                 QToolTip::add(item_adj, p_item->psz_longtext);
150                 item_adj->setValue( p_item->i_value );
151             }
152             break;
153
154         case MODULE_CONFIG_ITEM_FLOAT:
155             {
156                 QHBox *hb = new QHBox(category_table);
157                 hb->setSpacing(spacingHint());
158                 new QLabel(p_item->psz_text, hb);                
159                 KDoubleNumInput *kdi= new KDoubleNumInput(p_item->f_value, hb);
160                 kdi->setRange(-1, 99999, 0.01, false);
161                 QConfigItem *ci = new QConfigItem(this, p_item->psz_name,
162                                                   p_item->i_type,
163                                                   p_item->f_value);
164                 connect(kdi, SIGNAL(valueChanged(double)),
165                         ci, SLOT(setValue(double)));
166                 QToolTip::add(kdi, p_item->psz_longtext);
167                 
168             }
169             break;
170                                                   
171                 
172         case MODULE_CONFIG_ITEM_BOOL:
173
174             /* add check button */
175             {
176                 QCheckBox *bool_checkbutton =
177                     new QCheckBox(QString(p_item->psz_text), category_table);
178                 QConfigItem *ci = new QConfigItem(this, p_item->psz_name,
179                                                   p_item->i_type,
180                                                   p_item->i_value);
181                 bool_checkbutton->setChecked(p_item->i_value);
182                 connect(bool_checkbutton, SIGNAL(stateChanged( int)),
183                         ci, SLOT(setValue(int)));
184                 QToolTip::add(bool_checkbutton, p_item->psz_longtext);
185
186             }
187             break;
188
189         }
190
191         p_item++;
192     }
193     while( p_item->i_type != MODULE_CONFIG_HINT_END );
194     exec();
195     
196 }
197
198 /*
199   empty destructor, qt takes care of this (I think)
200 */
201 KPreferences::~KPreferences()
202 {
203 }
204
205 /*
206   return true if the give module is configureable
207 */
208 bool KPreferences::isConfigureable(QString module)
209 {
210     module_t *p_module;
211     for( p_module = p_intf->p_vlc->module_bank.first ;
212          p_module != NULL ;
213          p_module = p_module->next ) {
214         if( !module.compare( p_module->psz_name ) ) {
215             return p_module->i_config_items != 0;
216         }
217     }
218     return false;
219
220 }
221
222 /*
223   run when the Apply button is pressed, and by the methods for the ok
224   and save buttons
225 */
226 void KPreferences::slotApply()
227 {
228     QObjectList * l = queryList( "QConfigItem" );
229     QObjectListIt it( *l );             // iterate over the config items
230     QObject * obj;
231     while ( (obj=it.current()) != 0 ) {
232         ++it;
233         QConfigItem *p_config = (QConfigItem *)obj;
234         msg_Dbg( p_intf, const_cast<char *>(p_config->name()));
235         msg_Dbg( p_intf, "%d", p_config->getType());
236
237         switch( p_config->getType() ) {
238
239         case MODULE_CONFIG_ITEM_STRING:
240         case MODULE_CONFIG_ITEM_FILE:
241         case MODULE_CONFIG_ITEM_MODULE:
242             if (p_config->sValue()) {
243                 config_PutPsz( p_intf, p_config->name(),
244                                strdup(p_config->sValue().latin1()));
245             }
246             else {
247                 config_PutPsz( p_intf, p_config->name(), NULL );
248             }
249             break;
250         case MODULE_CONFIG_ITEM_INTEGER:
251         case MODULE_CONFIG_ITEM_BOOL:
252             config_PutInt( p_intf, p_config->name(), p_config->iValue() );
253             break;
254         case MODULE_CONFIG_ITEM_FLOAT:
255             config_PutFloat( p_intf, p_config->name(), p_config->fValue() );
256             break;
257         }
258     }
259     delete l;
260 }
261
262 /*
263  run when the Ok button is pressed
264 */
265 void KPreferences::slotOk()
266 {
267     slotApply();
268     accept();
269 }
270
271 /*
272   run when the save button is pressed
273 */
274 void KPreferences::slotUser1()
275 {
276     slotApply();
277     config_SaveConfigFile( p_intf, NULL );
278 }