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->module_bank.first ; p_module != NULL ;
41 p_module = p_module->next )
44 if( psz_module_name && !strcmp( psz_module_name, p_module->psz_name ) )
47 if( !p_module ) return;
48 p_item = p_module->p_config;
51 switch( p_item->i_type )
54 case MODULE_CONFIG_HINT_CATEGORY:
55 case MODULE_CONFIG_HINT_END:
58 * Now we can start taking care of the new category
60 if( p_item->i_type == MODULE_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 MODULE_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 */
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);
107 vlc_mutex_unlock( p_item->p_lock );
111 case MODULE_CONFIG_ITEM_STRING:
112 case MODULE_CONFIG_ITEM_FILE:
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 );
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,
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);
132 vlc_mutex_unlock( p_item->p_lock );
137 case MODULE_CONFIG_ITEM_INTEGER:
138 /* add input box with default value */
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,
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 );
154 case MODULE_CONFIG_ITEM_FLOAT:
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,
164 connect(kdi, SIGNAL(valueChanged(double)),
165 ci, SLOT(setValue(double)));
166 QToolTip::add(kdi, p_item->psz_longtext);
172 case MODULE_CONFIG_ITEM_BOOL:
174 /* add check button */
176 QCheckBox *bool_checkbutton =
177 new QCheckBox(QString(p_item->psz_text), category_table);
178 QConfigItem *ci = new QConfigItem(this, p_item->psz_name,
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);
193 while( p_item->i_type != MODULE_CONFIG_HINT_END );
199 empty destructor, qt takes care of this (I think)
201 KPreferences::~KPreferences()
206 return true if the give module is configureable
208 bool KPreferences::isConfigureable(QString module)
211 for( p_module = p_intf->p_vlc->module_bank.first ;
213 p_module = p_module->next ) {
214 if( !module.compare( p_module->psz_name ) ) {
215 return p_module->i_config_items != 0;
223 run when the Apply button is pressed, and by the methods for the ok
226 void KPreferences::slotApply()
228 QObjectList * l = queryList( "QConfigItem" );
229 QObjectListIt it( *l ); // iterate over the config items
231 while ( (obj=it.current()) != 0 ) {
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());
237 switch( p_config->getType() ) {
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()));
247 config_PutPsz( p_intf, p_config->name(), NULL );
250 case MODULE_CONFIG_ITEM_INTEGER:
251 case MODULE_CONFIG_ITEM_BOOL:
252 config_PutInt( p_intf, p_config->name(), p_config->iValue() );
254 case MODULE_CONFIG_ITEM_FLOAT:
255 config_PutFloat( p_intf, p_config->name(), p_config->fValue() );
263 run when the Ok button is pressed
265 void KPreferences::slotOk()
272 run when the save button is pressed
274 void KPreferences::slotUser1()
277 config_SaveConfigFile( p_intf, NULL );