1 #include <kdialogbase.h>
9 #include <qnamespace.h>
10 #include <qobjectlist.h>
15 #include <kbuttonbox.h>
16 #include <klineedit.h>
18 #include <knuminput.h>
20 #include "QConfigItem.h"
21 #include "kde_pluginsbox.h"
22 #include "kde_preferences.h"
25 construkt a new configuration window for the given module
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")
32 module_t *p_module, *p_module_bis;
33 module_config_t *p_item;
34 QVBox *category_table = NULL;
35 QString *category_label;
37 this->p_intf = p_intf;
39 /* Look for the selected module */
40 for( p_module = p_intf->p_vlc->p_module_bank->first ; p_module != NULL ;
41 p_module = p_module->next )
44 if( psz_module_name && !strcmp( psz_module_name, p_module->psz_object_name ) )
47 if( !p_module ) return;
48 p_item = p_module->p_config;
51 switch( p_item->i_type )
54 case CONFIG_HINT_CATEGORY:
58 * Now we can start taking care of the new category
60 if( p_item->i_type == CONFIG_HINT_CATEGORY )
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());
77 case CONFIG_ITEM_MODULE:
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 :"",
88 QConfigItem *ci = new QConfigItem(this,
92 connect(item_frame, SIGNAL(selectionChanged(const QString &)),
93 ci, SLOT(setValue(const QString &)));
96 /* build a list of available plugins */
99 for( p_module_bis = p_intf->p_vlc->p_module_bank->first ;
100 p_module_bis != NULL ;
101 p_module_bis = p_module_bis->next ) {
102 if( p_module_bis->i_capabilities & (1 << p_item->i_value)){
103 new QListViewItem(item_frame->getListView(),
104 p_module_bis->psz_object_name,
105 p_module_bis->psz_longname);
109 vlc_mutex_unlock( p_item->p_lock );
113 case CONFIG_ITEM_STRING:
114 case CONFIG_ITEM_FILE:
117 QHBox *hb = new QHBox(category_table);
118 hb->setSpacing(spacingHint());
119 new QLabel(p_item->psz_text, hb);
120 /* add input box with default value */
121 vlc_mutex_lock( p_item->p_lock );
123 KLineEdit *kl = new KLineEdit( p_item->psz_value ?
124 p_item->psz_value : "", hb);
125 QConfigItem *ci = new QConfigItem(this, p_item->psz_name,
128 p_item->psz_value : "");
129 connect(kl, SIGNAL(textChanged ( const QString & )),
130 ci, SLOT(setValue( const QString &)));
131 QToolTip::add(kl, p_item->psz_longtext);
132 kl->setMaxLength(10);
134 vlc_mutex_unlock( p_item->p_lock );
139 case CONFIG_ITEM_INTEGER:
140 /* add input box with default value */
142 QHBox *hb = new QHBox(category_table);
143 hb->setSpacing(spacingHint());
144 new QLabel(p_item->psz_text, hb);
145 QSpinBox *item_adj = new QSpinBox(-1, 99999, 1, hb);
146 QConfigItem *ci = new QConfigItem(this, p_item->psz_name,
149 connect(item_adj, SIGNAL(valueChanged( int)),
150 ci, SLOT(setValue(int)));
151 QToolTip::add(item_adj, p_item->psz_longtext);
152 item_adj->setValue( p_item->i_value );
156 case CONFIG_ITEM_FLOAT:
158 QHBox *hb = new QHBox(category_table);
159 hb->setSpacing(spacingHint());
160 new QLabel(p_item->psz_text, hb);
161 KDoubleNumInput *kdi= new KDoubleNumInput(p_item->f_value, hb);
162 kdi->setRange(-1, 99999, 0.01, false);
163 QConfigItem *ci = new QConfigItem(this, p_item->psz_name,
166 connect(kdi, SIGNAL(valueChanged(double)),
167 ci, SLOT(setValue(double)));
168 QToolTip::add(kdi, p_item->psz_longtext);
174 case CONFIG_ITEM_BOOL:
176 /* add check button */
178 QCheckBox *bool_checkbutton =
179 new QCheckBox(QString(p_item->psz_text), category_table);
180 QConfigItem *ci = new QConfigItem(this, p_item->psz_name,
183 bool_checkbutton->setChecked(p_item->i_value);
184 connect(bool_checkbutton, SIGNAL(stateChanged( int)),
185 ci, SLOT(setValue(int)));
186 QToolTip::add(bool_checkbutton, p_item->psz_longtext);
195 while( p_item->i_type != CONFIG_HINT_END );
201 empty destructor, qt takes care of this (I think)
203 KPreferences::~KPreferences()
208 return true if the give module is configureable
210 bool KPreferences::isConfigureable(QString module)
213 for( p_module = p_intf->p_vlc->p_module_bank->first ;
215 p_module = p_module->next ) {
216 if( !module.compare( p_module->psz_object_name ) ) {
217 return p_module->i_config_items != 0;
225 run when the Apply button is pressed, and by the methods for the ok
228 void KPreferences::slotApply()
230 QObjectList * l = queryList( "QConfigItem" );
231 QObjectListIt it( *l ); // iterate over the config items
233 while ( (obj=it.current()) != 0 ) {
235 QConfigItem *p_config = (QConfigItem *)obj;
236 msg_Dbg( p_intf, const_cast<char *>(p_config->name()));
237 msg_Dbg( p_intf, "%d", p_config->getType());
239 switch( p_config->getType() ) {
241 case CONFIG_ITEM_STRING:
242 case CONFIG_ITEM_FILE:
243 case CONFIG_ITEM_MODULE:
244 if (p_config->sValue()) {
245 config_PutPsz( p_intf, p_config->name(),
246 strdup(p_config->sValue().latin1()));
249 config_PutPsz( p_intf, p_config->name(), NULL );
252 case CONFIG_ITEM_INTEGER:
253 case CONFIG_ITEM_BOOL:
254 config_PutInt( p_intf, p_config->name(), p_config->iValue() );
256 case CONFIG_ITEM_FLOAT:
257 config_PutFloat( p_intf, p_config->name(), p_config->fValue() );
265 run when the Ok button is pressed
267 void KPreferences::slotOk()
274 run when the save button is pressed
276 void KPreferences::slotUser1()
279 config_SaveConfigFile( p_intf, NULL );