1 /*****************************************************************************
2 * preferences.cpp: preferences window for the kde gui
3 *****************************************************************************
4 * Copyright (C) 2001 VideoLAN
5 * $Id: preferences.cpp,v 1.5 2002/10/03 10:15:01 sigmunau Exp $
7 * Authors: Sigmund Augdal <sigmunau@idi.ntnu.no> Mon Aug 12 2002
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
23 #include <kdialogbase.h>
25 #include <qcheckbox.h>
27 #include <qgroupbox.h>
30 #include <qlistview.h>
31 #include <qnamespace.h>
32 #include <qobjectlist.h>
37 #include <kbuttonbox.h>
38 #include <klineedit.h>
40 #include <knuminput.h>
42 #include "QConfigItem.h"
43 #include "pluginsbox.h"
44 #include "preferences.h"
47 construct a new configuration window for the given module
49 KPreferences::KPreferences(intf_thread_t *p_intf, const char *psz_module_name,
50 QWidget *parent, const QString &caption) :
51 KDialogBase ( Tabbed, caption, Ok| Apply|Cancel|User1, Ok, parent,
52 "vlc preferences", true, false, "Save")
56 module_config_t *p_item;
57 QVBox *category_table = NULL;
58 QString *category_label;
60 this->p_intf = p_intf;
62 /* List all modules */
63 p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
65 /* Look for the selected module */
66 for( pp_parser = (module_t **)p_list->pp_objects ;
72 && !strcmp( psz_module_name, (*pp_parser)->psz_object_name ) )
80 vlc_list_release( p_list );
84 p_item = (*pp_parser)->p_config;
87 switch( p_item->i_type )
90 case CONFIG_HINT_CATEGORY:
94 * Now we can start taking care of the new category
96 if( p_item->i_type == CONFIG_HINT_CATEGORY )
98 category_label = new QString( p_item->psz_text );
99 QFrame *page = addPage( *category_label );
100 QVBoxLayout *toplayout = new QVBoxLayout( page);
101 QScrollView *sv = new QScrollView(page);
102 sv->setResizePolicy(QScrollView::AutoOneFit);
103 sv->setFrameStyle(QScrollView::NoFrame);
104 toplayout->addWidget(sv);
105 category_table = new QVBox(sv->viewport());
106 sv->addChild(category_table);
107 toplayout->addStretch(10);
108 category_table->setSpacing(spacingHint());
113 case CONFIG_ITEM_MODULE:
117 vlc_mutex_lock( p_item->p_lock );
118 KPluginsBox *item_frame =
119 new KPluginsBox( p_intf, p_item->psz_text,
120 p_item->psz_value ? p_item->psz_value :"",
124 QConfigItem *ci = new QConfigItem(this,
128 connect(item_frame, SIGNAL(selectionChanged(const QString &)),
129 ci, SLOT(setValue(const QString &)));
132 /* build a list of available plugins */
133 for( pp_parser = (module_t **)p_list->pp_objects ;
137 if( !strcmp( (*pp_parser)->psz_capability,
140 new QListViewItem(item_frame->getListView(),
141 (*pp_parser)->psz_object_name,
142 (*pp_parser)->psz_longname);
146 vlc_mutex_unlock( p_item->p_lock );
150 case CONFIG_ITEM_STRING:
151 case CONFIG_ITEM_FILE:
154 QHBox *hb = new QHBox(category_table);
155 hb->setSpacing(spacingHint());
156 new QLabel(p_item->psz_text, hb);
157 /* add input box with default value */
158 vlc_mutex_lock( p_item->p_lock );
160 KLineEdit *kl = new KLineEdit( p_item->psz_value ?
161 p_item->psz_value : "", hb);
162 QConfigItem *ci = new QConfigItem(this, p_item->psz_name,
165 p_item->psz_value : "");
166 connect(kl, SIGNAL(textChanged ( const QString & )),
167 ci, SLOT(setValue( const QString &)));
168 QToolTip::add(kl, p_item->psz_longtext);
169 kl->setMaxLength(10);
171 vlc_mutex_unlock( p_item->p_lock );
176 case CONFIG_ITEM_INTEGER:
177 /* add input box with default value */
179 QHBox *hb = new QHBox(category_table);
180 hb->setSpacing(spacingHint());
181 new QLabel(p_item->psz_text, hb);
182 QSpinBox *item_adj = new QSpinBox(-1, 99999, 1, hb);
183 QConfigItem *ci = new QConfigItem(this, p_item->psz_name,
186 connect(item_adj, SIGNAL(valueChanged( int)),
187 ci, SLOT(setValue(int)));
188 QToolTip::add(item_adj, p_item->psz_longtext);
189 item_adj->setValue( p_item->i_value );
193 case CONFIG_ITEM_FLOAT:
195 QHBox *hb = new QHBox(category_table);
196 hb->setSpacing(spacingHint());
197 new QLabel(p_item->psz_text, hb);
198 KDoubleNumInput *kdi= new KDoubleNumInput(p_item->f_value, hb);
199 kdi->setRange(-1, 99999, 0.01, false);
200 QConfigItem *ci = new QConfigItem(this, p_item->psz_name,
203 connect(kdi, SIGNAL(valueChanged(double)),
204 ci, SLOT(setValue(double)));
205 QToolTip::add(kdi, p_item->psz_longtext);
211 case CONFIG_ITEM_BOOL:
213 /* add check button */
215 QCheckBox *bool_checkbutton =
216 new QCheckBox(QString(p_item->psz_text), category_table);
217 QConfigItem *ci = new QConfigItem(this, p_item->psz_name,
220 bool_checkbutton->setChecked(p_item->i_value);
221 connect(bool_checkbutton, SIGNAL(stateChanged( int)),
222 ci, SLOT(setValue(int)));
223 QToolTip::add(bool_checkbutton, p_item->psz_longtext);
232 while( p_item->i_type != CONFIG_HINT_END );
234 vlc_list_release( p_list );
240 empty destructor, qt takes care of this (I think)
242 KPreferences::~KPreferences()
247 return true if the give module is configureable
249 bool KPreferences::isConfigureable(QString module)
251 module_t **pp_parser;
254 p_list = vlc_list_find( this->p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
256 for( pp_parser = (module_t **)p_list->pp_objects ;
260 if( !module.compare( (*pp_parser)->psz_object_name ) )
262 bool ret = (*pp_parser)->i_config_items != 0;
263 vlc_list_release( p_list );
268 vlc_list_release( p_list );
273 run when the Apply button is pressed, and by the methods for the ok
276 void KPreferences::slotApply()
278 QObjectList * l = queryList( "QConfigItem" );
279 QObjectListIt it( *l ); // iterate over the config items
281 while ( (obj=it.current()) != 0 ) {
283 QConfigItem *p_config = (QConfigItem *)obj;
284 msg_Dbg( p_intf, const_cast<char *>(p_config->name()));
285 msg_Dbg( p_intf, "%d", p_config->getType());
287 switch( p_config->getType() ) {
289 case CONFIG_ITEM_STRING:
290 case CONFIG_ITEM_FILE:
291 case CONFIG_ITEM_MODULE:
292 if (p_config->sValue()) {
293 config_PutPsz( p_intf, p_config->name(),
294 strdup(p_config->sValue().latin1()));
297 config_PutPsz( p_intf, p_config->name(), NULL );
300 case CONFIG_ITEM_INTEGER:
301 case CONFIG_ITEM_BOOL:
302 config_PutInt( p_intf, p_config->name(), p_config->iValue() );
304 case CONFIG_ITEM_FLOAT:
305 config_PutFloat( p_intf, p_config->name(), p_config->fValue() );
313 run when the Ok button is pressed
315 void KPreferences::slotOk()
322 run when the save button is pressed
324 void KPreferences::slotUser1()
327 config_SaveConfigFile( p_intf, NULL );