1 /***************************************************************************
2 optionsdialog.cpp - description
4 begin : Don Nov 21 2002
5 copyright : (C) 2002 by Gunnar Schmi Dt
6 email : kmouth@schmi-dt.de
7 ***************************************************************************/
9 /***************************************************************************
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
16 ***************************************************************************/
18 #include "optionsdialog.h"
19 #include "wordcompletion/wordcompletionwidget.h"
21 #include "texttospeechconfigurationwidget.h"
24 #include <QtGui/QLayout>
25 #include <QtGui/QLabel>
26 #include <Qt3Support/Q3Grid>
27 #include <QtGui/QTabWidget>
28 #include <QtGui/QPixmap>
29 #include <QtCore/QFile>
31 #include <kcombobox.h>
36 #include <klibloader.h>
38 #include <kpagewidgetmodel.h>
39 #include <kparts/componentfactory.h>
41 PreferencesWidget::PreferencesWidget (QWidget
*parent
, const char *name
)
46 speakCombo
->setCurrentIndex (1);
49 closeCombo
->setCurrentIndex (2);
53 PreferencesWidget::~PreferencesWidget() {
56 void PreferencesWidget::cancel() {
58 speakCombo
->setCurrentIndex (0);
60 speakCombo
->setCurrentIndex (1);
61 closeCombo
->setCurrentIndex (save
);
64 void PreferencesWidget::ok() {
65 speak
= speakCombo
->currentIndex () == 0;
66 save
= closeCombo
->currentIndex ();
69 void PreferencesWidget::readOptions (KConfig
*config
) {
70 KConfigGroup
cg ( config
,"Preferences");
71 if (cg
.hasKey("AutomaticSpeak"))
72 if (cg
.readEntry ("AutomaticSpeak") == "Yes")
79 KConfigGroup
cg2 ( config
,"Notification Messages");
80 if (cg2
.hasKey("AutomaticSave"))
81 if (cg2
.readEntry ("AutomaticSave") == "Yes")
89 speakCombo
->setCurrentIndex (0);
91 speakCombo
->setCurrentIndex (1);
92 closeCombo
->setCurrentIndex (save
);
95 void PreferencesWidget::saveOptions (KConfig
*config
) {
96 KConfigGroup
cg (config
, "Preferences");
98 cg
.writeEntry ("AutomaticSpeak", "Yes");
100 cg
.writeEntry ("AutomaticSpeak", "No");
102 KConfigGroup
cg2 (config
, "Notification Messages");
104 cg2
.writeEntry ("AutomaticSave", "Yes");
106 cg2
.writeEntry ("AutomaticSave", "No");
108 cg2
.deleteEntry ("AutomaticSave");
111 bool PreferencesWidget::isSpeakImmediately () {
115 /***************************************************************************/
117 OptionsDialog::OptionsDialog (QWidget
*parent
)
118 : KPageDialog(parent
)
120 setCaption(i18n("Configuration"));
121 setButtons(KDialog::Ok
|KDialog::Apply
|KDialog::Cancel
|KDialog::Help
);
122 setFaceType(KPageDialog::List
);
123 setHelp ("config-dialog");
126 //addGridPage (1, Qt::Horizontal, i18n("General Options"), QString(), iconGeneral);
128 tabCtl
= new QTabWidget();
129 tabCtl
->setObjectName("general");
131 behaviourWidget
= new PreferencesWidget (tabCtl
, "prefPage");
132 behaviourWidget
->layout()->setMargin(KDialog::marginHint());
133 tabCtl
->addTab (behaviourWidget
, i18n("&Preferences"));
135 commandWidget
= new TextToSpeechConfigurationWidget (tabCtl
, "ttsTab");
136 commandWidget
->layout()->setMargin(KDialog::marginHint());
137 tabCtl
->addTab (commandWidget
, i18n("&Text-to-Speech"));
139 KPageWidgetItem
*pageGeneral
= new KPageWidgetItem(tabCtl
, i18n("General Options"));
140 pageGeneral
->setHeader(i18n("General Options"));
141 pageGeneral
->setIcon(KIcon("configure"));
142 addPage(pageGeneral
);
144 completionWidget
= new WordCompletionWidget(0, "Word Completion widget");
145 KPageWidgetItem
*pageCompletion
= new KPageWidgetItem(completionWidget
, i18n("Word Completion"));
146 pageCompletion
->setHeader(i18n("Word Completion"));
147 pageCompletion
->setIcon(KIcon("keyboard"));
148 addPage(pageCompletion
);
152 KPageWidgetItem
*pageKttsd
= new KPageWidgetItem(kttsd
, i18n("KTTSD Speech Service"));
153 pageKttsd
->setIcon(KIcon("multimedia"));
154 pageKttsd
->setHeader(i18n("KDE Text-to-Speech Daemon Configuration"));
158 setDefaultButton(KDialog::Cancel
);
160 connect(this, SIGNAL(okClicked()), this, SLOT(slotOk()));
161 connect(this, SIGNAL(cancelClicked()), this, SLOT(slotCancel()));
162 connect(this, SIGNAL(applyClicked()), this, SLOT(slotApply()));
165 OptionsDialog::~OptionsDialog() {
169 void OptionsDialog::slotCancel() {
170 // KDialog::slotCancel();
171 commandWidget
->cancel();
172 behaviourWidget
->cancel();
173 completionWidget
->load();
178 void OptionsDialog::slotOk() {
179 // KDialog::slotOk();
181 behaviourWidget
->ok();
182 completionWidget
->save();
183 emit
configurationChanged();
189 void OptionsDialog::slotApply() {
190 // KDialog::slotApply();
192 behaviourWidget
->ok();
193 completionWidget
->save();
194 emit
configurationChanged();
199 TextToSpeechSystem
*OptionsDialog::getTTSSystem() const {
200 return commandWidget
->getTTSSystem();
203 void OptionsDialog::readOptions (KConfig
*config
) {
204 commandWidget
->readOptions (config
, "TTS System");
205 behaviourWidget
->readOptions (config
);
208 void OptionsDialog::saveOptions (KConfig
*config
) {
209 commandWidget
->saveOptions (config
, "TTS System");
210 behaviourWidget
->saveOptions (config
);
214 bool OptionsDialog::isSpeakImmediately () {
215 return behaviourWidget
->isSpeakImmediately ();
218 KCModule
*OptionsDialog::loadKttsd () {
219 KLibLoader
*loader
= KLibLoader::self();
221 QString libname
= "kcm_kttsd";
222 KLibrary
*lib
= loader
->library(QFile::encodeName(libname
));
225 libname
= "libkcm_kttsd";
226 lib
= loader
->library(QFile::encodeName("libkcm_kttsd"));
230 QString
initSym("init_");
233 if (lib
->resolveFunction(QFile::encodeName(initSym
))) {
234 // Reuse "lib" instead of letting createInstanceFromLibrary recreate it
235 KLibFactory
*factory
= lib
->factory();
237 KCModule
*module
= factory
->create
<KCModule
> (factory
);
248 void OptionsDialog::unloadKttsd () {
249 KLibLoader
*loader
= KLibLoader::self();
250 loader
->unloadLibrary(QFile::encodeName("libkcm_kttsd"));
251 loader
->unloadLibrary(QFile::encodeName("kcm_kttsd"));
254 #include "optionsdialog.moc"