rk27generic: Disable plugins.
[maemo-rb.git] / rbutil / rbutilqt / encttscfggui.cpp
blob0030c5c206ee985da686e02962f931587d3ace9b
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
9 * Copyright (C) 2007 by Dominik Wenger
10 * $Id: encoders.h 17902 2008-06-30 22:09:45Z bluebrother $
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include "encttscfggui.h"
24 EncTtsCfgGui::EncTtsCfgGui(QDialog* parent,EncTtsSettingInterface* interface,QString name) : QDialog(parent)
26 m_settingInterface = interface;
28 m_busyCnt=0;
29 // create a busy Dialog
30 m_busyDlg= new QProgressDialog("", "", 0, 0,this);
31 m_busyDlg->setWindowTitle(tr("Waiting for engine..."));
32 m_busyDlg->setModal(true);
33 m_busyDlg->setLabel(0);
34 m_busyDlg->setCancelButton(0);
35 m_busyDlg->hide();
36 connect(interface,SIGNAL(busy()),this,SLOT(showBusy()));
37 connect(interface,SIGNAL(busyEnd()),this,SLOT(hideBusy()));
39 //setup the window
40 setWindowTitle(name);
41 setUpWindow();
44 void EncTtsCfgGui::setUpWindow()
46 m_settingsList = m_settingInterface->getSettings();
48 // layout
49 QVBoxLayout *mainLayout = new QVBoxLayout;
51 // groupbox
52 QGroupBox *groupBox = new QGroupBox(this);
53 QGridLayout *gridLayout = new QGridLayout(groupBox);
54 // setting widgets
55 for(int i = 0; i < m_settingsList.size(); i++)
57 QLabel *label = new QLabel(m_settingsList.at(i)->name());
58 gridLayout->addWidget(label, i, 0);
59 QWidget *widget = createWidgets(m_settingsList.at(i));
60 gridLayout->addWidget(widget, i, 1);
61 widget->setLayoutDirection(Qt::LeftToRight);
62 QWidget *btn = createButton(m_settingsList.at(i));
63 if(btn != NULL)
65 gridLayout->addWidget(btn, i, 2);
68 // add hidden spacers to make the dialog scale properly
69 QSpacerItem* spacer = new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding);
70 gridLayout->addItem(spacer, m_settingsList.size(), 0);
71 spacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum);
72 gridLayout->addItem(spacer, m_settingsList.size(), 1);
74 groupBox->setLayout(gridLayout);
75 mainLayout->addWidget(groupBox);
77 // connect browse btn
78 connect(&m_browseBtnMap,SIGNAL(mapped(QObject*)),this,SLOT(browse(QObject*)));
80 // ok - cancel buttons
81 QPushButton* okBtn = new QPushButton(tr("Ok"),this);
82 okBtn->setDefault(true);
83 okBtn->setIcon(QIcon(":icons/go-next.png"));
84 QPushButton* cancelBtn = new QPushButton(tr("Cancel"),this);
85 cancelBtn->setIcon(QIcon(":icons/process-stop.png"));
86 connect(okBtn,SIGNAL(clicked()),this,SLOT(accept()));
87 connect(cancelBtn,SIGNAL(clicked()),this,SLOT(reject()));
89 QHBoxLayout *btnbox = new QHBoxLayout;
90 btnbox->addWidget(okBtn);
91 btnbox->addWidget(cancelBtn);
92 btnbox->insertStretch(0,1);
94 mainLayout->addLayout(btnbox);
96 this->setLayout(mainLayout);
99 QWidget* EncTtsCfgGui::createWidgets(EncTtsSetting* setting)
101 // value display
102 QWidget* value = NULL;
103 switch(setting->type())
105 case EncTtsSetting::eDOUBLE:
107 QDoubleSpinBox *spinBox = new QDoubleSpinBox(this);
108 spinBox->setAccessibleName(setting->name());
109 spinBox->setMinimum(setting->min().toDouble());
110 spinBox->setMaximum(setting->max().toDouble());
111 spinBox->setSingleStep(0.01);
112 spinBox->setValue(setting->current().toDouble());
113 connect(spinBox,SIGNAL(valueChanged(double)),this,SLOT(updateSetting()));
114 value = spinBox;
115 break;
117 case EncTtsSetting::eINT:
119 QSpinBox *spinBox = new QSpinBox(this);
120 spinBox->setAccessibleName(setting->name());
121 spinBox->setMinimum(setting->min().toInt());
122 spinBox->setMaximum(setting->max().toInt());
123 spinBox->setValue(setting->current().toInt());
124 connect(spinBox,SIGNAL(valueChanged(int)),this,SLOT(updateSetting()));
125 value = spinBox;
126 break;
128 case EncTtsSetting::eSTRING:
130 QLineEdit *lineEdit = new QLineEdit(this);
131 lineEdit->setAccessibleName(setting->name());
132 lineEdit->setText(setting->current().toString());
133 connect(lineEdit,SIGNAL(textChanged(QString)),this,SLOT(updateSetting()));
134 value = lineEdit;
135 break;
137 case EncTtsSetting::eREADONLYSTRING:
139 value = new QLabel(setting->current().toString(),this);
140 break;
142 case EncTtsSetting::eSTRINGLIST:
144 QComboBox *comboBox = new QComboBox(this);
145 comboBox->setAccessibleName(setting->name());
146 comboBox->addItems(setting->list());
147 int index = comboBox->findText(setting->current().toString());
148 comboBox->setCurrentIndex(index);
149 connect(comboBox,SIGNAL(currentIndexChanged(QString)),this,SLOT(updateSetting()));
150 value = comboBox;
151 break;
153 case EncTtsSetting::eBOOL:
155 QCheckBox *checkbox = new QCheckBox(this);
156 checkbox->setAccessibleName(setting->name());
157 checkbox->setCheckState(setting->current().toBool() == true ? Qt::Checked : Qt::Unchecked);
158 connect(checkbox,SIGNAL(stateChanged(int)),this,SLOT(updateSetting()));
159 value = checkbox;
160 break;
162 default:
164 qDebug() << "Warning: unknown EncTTsSetting type" << setting->type();
165 break;
169 // remember widget
170 if(value != NULL)
172 m_settingsWidgetsMap.insert(setting,value);
173 connect(setting,SIGNAL(updateGui()),this,SLOT(updateWidget()));
176 return value;
179 QWidget* EncTtsCfgGui::createButton(EncTtsSetting* setting)
181 if(setting->button() == EncTtsSetting::eBROWSEBTN)
183 QPushButton* browsebtn = new QPushButton(tr("Browse"),this);
184 browsebtn->setIcon(QIcon(":/icons/system-search.png"));
185 m_browseBtnMap.setMapping(browsebtn,setting);
186 connect(browsebtn,SIGNAL(clicked()),&m_browseBtnMap,SLOT(map()));
187 return browsebtn;
189 else if(setting->button() == EncTtsSetting::eREFRESHBTN)
191 QPushButton* refreshbtn = new QPushButton(tr("Refresh"),this);
192 refreshbtn->setIcon(QIcon(":/icons/view-refresh.png"));
193 connect(refreshbtn,SIGNAL(clicked()),setting,SIGNAL(refresh()));
194 return refreshbtn;
196 else
197 return NULL;
200 void EncTtsCfgGui::updateSetting()
202 //cast and get the sender widget
203 QWidget* widget = qobject_cast<QWidget*>(QObject::sender());
204 if(widget == NULL) return;
205 // get the corresponding setting
206 EncTtsSetting* setting = m_settingsWidgetsMap.key(widget);
208 // update widget based on setting type
209 switch(setting->type())
211 case EncTtsSetting::eDOUBLE:
213 setting->setCurrent(((QDoubleSpinBox*)widget)->value(),false);
214 break;
216 case EncTtsSetting::eINT:
218 setting->setCurrent(((QSpinBox*)widget)->value(),false);
219 break;
221 case EncTtsSetting::eSTRING:
223 setting->setCurrent(((QLineEdit*)widget)->text(),false);
224 break;
226 case EncTtsSetting::eREADONLYSTRING:
228 setting->setCurrent(((QLabel*)widget)->text(),false);
229 break;
231 case EncTtsSetting::eSTRINGLIST:
233 setting->setCurrent(((QComboBox*)widget)->currentText(),false);
234 break;
236 case EncTtsSetting::eBOOL:
238 setting->setCurrent(((QCheckBox*)widget)->isChecked(),false);
240 default:
242 qDebug() << "unknown Settingtype !!";
243 break;
248 void EncTtsCfgGui::updateWidget()
250 // get sender setting
251 EncTtsSetting* setting = qobject_cast<EncTtsSetting*>(QObject::sender());
252 if(setting == NULL) return;
253 // get corresponding widget
254 QWidget* widget = m_settingsWidgetsMap.value(setting);
256 // update Widget based on setting type
257 switch(setting->type())
259 case EncTtsSetting::eDOUBLE:
261 QDoubleSpinBox* spinbox = (QDoubleSpinBox*) widget;
262 spinbox->setMinimum(setting->min().toDouble());
263 spinbox->setMaximum(setting->max().toDouble());
264 spinbox->blockSignals(true);
265 spinbox->setValue(setting->current().toDouble());
266 spinbox->blockSignals(false);
267 break;
269 case EncTtsSetting::eINT:
271 QSpinBox* spinbox = (QSpinBox*) widget;
272 spinbox->setMinimum(setting->min().toInt());
273 spinbox->setMaximum(setting->max().toInt());
274 spinbox->blockSignals(true);
275 spinbox->setValue(setting->current().toInt());
276 spinbox->blockSignals(false);
277 break;
279 case EncTtsSetting::eSTRING:
281 QLineEdit* lineedit = (QLineEdit*) widget;
283 lineedit->blockSignals(true);
284 lineedit->setText(setting->current().toString());
285 lineedit->blockSignals(false);
286 break;
288 case EncTtsSetting::eREADONLYSTRING:
290 QLabel* label = (QLabel*) widget;
292 label->blockSignals(true);
293 label->setText(setting->current().toString());
294 label->blockSignals(false);
295 break;
297 case EncTtsSetting::eSTRINGLIST:
299 QComboBox* combobox = (QComboBox*) widget;
301 combobox->blockSignals(true);
302 combobox->clear();
303 combobox->addItems(setting->list());
304 int index = combobox->findText(setting->current().toString());
305 combobox->setCurrentIndex(index);
306 combobox->blockSignals(false);
308 break;
310 case EncTtsSetting::eBOOL:
312 QCheckBox* checkbox = (QCheckBox*) widget;
314 checkbox->blockSignals(true);
315 checkbox->setCheckState(setting->current().toBool() == true ? Qt::Checked : Qt::Unchecked);
316 checkbox->blockSignals(false);
317 break;
319 default:
321 qDebug() << "unknown EncTTsSetting";
322 break;
327 void EncTtsCfgGui::showBusy()
329 if(m_busyCnt == 0) m_busyDlg->show();
331 m_busyCnt++;
334 void EncTtsCfgGui::hideBusy()
336 m_busyCnt--;
338 if(m_busyCnt == 0) m_busyDlg->hide();
342 void EncTtsCfgGui::accept(void)
344 m_settingInterface->saveSettings();
345 this->done(0);
348 void EncTtsCfgGui::reject(void)
350 this->done(0);
353 //! takes a QObject because of QsignalMapper
354 void EncTtsCfgGui::browse(QObject* settingObj)
356 // cast top setting
357 EncTtsSetting* setting= qobject_cast<EncTtsSetting*>(settingObj);
358 if(setting == NULL) return;
360 //current path
361 QString curPath = setting->current().toString();
362 // show file dialog
363 QString exe = QFileDialog::getOpenFileName(this, tr("Select executable"), curPath, "*");
364 if(!QFileInfo(exe).isExecutable())
365 return;
366 // set new value, gui will update automatically
367 setting->setCurrent(exe);