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 ***************************************************************************/
21 #include <q3whatsthis.h>
23 #include <qtabwidget.h>
27 #include <kcombobox.h>
31 #include <kiconloader.h>
33 #include <klibloader.h>
34 #include <kparts/componentfactory.h>
36 #include "optionsdialog.h"
37 #include "wordcompletion/wordcompletionwidget.h"
39 #include "texttospeechconfigurationwidget.h"
42 PreferencesWidget::PreferencesWidget (QWidget
*parent
, const char *name
)
43 : PreferencesUI (parent
, name
)
45 speakCombo
->setCurrentItem (1);
48 closeCombo
->setCurrentItem (2);
52 PreferencesWidget::~PreferencesWidget() {
55 void PreferencesWidget::cancel() {
57 speakCombo
->setCurrentItem (0);
59 speakCombo
->setCurrentItem (1);
60 closeCombo
->setCurrentItem (save
);
63 void PreferencesWidget::ok() {
64 speak
= speakCombo
->currentItem () == 0;
65 save
= closeCombo
->currentItem ();
68 void PreferencesWidget::readOptions (KConfig
*config
) {
69 config
->setGroup("Preferences");
70 if (config
->hasKey("AutomaticSpeak"))
71 if (config
->readEntry ("AutomaticSpeak") == "Yes")
78 config
->setGroup("Notification Messages");
79 if (config
->hasKey("AutomaticSave"))
80 if (config
->readEntry ("AutomaticSave") == "Yes")
88 speakCombo
->setCurrentItem (0);
90 speakCombo
->setCurrentItem (1);
91 closeCombo
->setCurrentItem (save
);
94 void PreferencesWidget::saveOptions (KConfig
*config
) {
95 config
->setGroup("Preferences");
97 config
->writeEntry ("AutomaticSpeak", "Yes");
99 config
->writeEntry ("AutomaticSpeak", "No");
101 config
->setGroup("Notification Messages");
103 config
->writeEntry ("AutomaticSave", "Yes");
105 config
->writeEntry ("AutomaticSave", "No");
107 config
->deleteEntry ("AutomaticSave");
110 bool PreferencesWidget::isSpeakImmediately () {
114 /***************************************************************************/
116 OptionsDialog::OptionsDialog (QWidget
*parent
)
117 : KDialogBase(IconList
, i18n("Configuration"), Ok
|Apply
|Cancel
|Help
, Ok
,
118 parent
, "configuration", false, true)
120 setHelp ("config-dialog");
122 QPixmap iconGeneral
= KGlobal::iconLoader()->loadIcon("configure", KIcon::NoGroup
, KIcon::SizeMedium
);
123 Q3Grid
*pageGeneral
= addGridPage (1, Qt::Horizontal
, i18n("General Options"), QString::null
, iconGeneral
);
125 tabCtl
= new QTabWidget (pageGeneral
, "general");
127 behaviourWidget
= new PreferencesWidget (tabCtl
, "prefPage");
128 behaviourWidget
->layout()->setMargin(KDialog::marginHint());
129 tabCtl
->addTab (behaviourWidget
, i18n("&Preferences"));
131 commandWidget
= new TextToSpeechConfigurationWidget (tabCtl
, "ttsTab");
132 commandWidget
->layout()->setMargin(KDialog::marginHint());
133 tabCtl
->addTab (commandWidget
, i18n("&Text-to-Speech"));
135 QPixmap iconCompletion
= KGlobal::iconLoader()->loadIcon("keyboard", KIcon::NoGroup
, KIcon::SizeMedium
);
136 Q3Grid
*pageCompletion
= addGridPage (1, Qt::Horizontal
, i18n("Word Completion"), QString::null
, iconCompletion
);
137 completionWidget
= new WordCompletionWidget(pageCompletion
, "Word Completion widget");
141 QPixmap iconKttsd
= KGlobal::iconLoader()->loadIcon("multimedia", KIcon::NoGroup
, KIcon::SizeMedium
);
142 Q3Grid
*pageKttsd
= addGridPage (1, Qt::Horizontal
, i18n("KTTSD Speech Service"),
143 i18n("KDE Text-to-Speech Daemon Configuration"), iconKttsd
);
145 kttsd
->reparent(pageKttsd
,0,QPoint(0,0),true);
149 OptionsDialog::~OptionsDialog() {
153 void OptionsDialog::slotCancel() {
154 KDialogBase::slotCancel();
155 commandWidget
->cancel();
156 behaviourWidget
->cancel();
157 completionWidget
->load();
162 void OptionsDialog::slotOk() {
163 KDialogBase::slotOk();
165 behaviourWidget
->ok();
166 completionWidget
->save();
167 emit
configurationChanged();
173 void OptionsDialog::slotApply() {
174 KDialogBase::slotApply();
176 behaviourWidget
->ok();
177 completionWidget
->save();
178 emit
configurationChanged();
183 TextToSpeechSystem
*OptionsDialog::getTTSSystem() const {
184 return commandWidget
->getTTSSystem();
187 void OptionsDialog::readOptions (KConfig
*config
) {
188 commandWidget
->readOptions (config
, "TTS System");
189 behaviourWidget
->readOptions (config
);
192 void OptionsDialog::saveOptions (KConfig
*config
) {
193 commandWidget
->saveOptions (config
, "TTS System");
194 behaviourWidget
->saveOptions (config
);
198 bool OptionsDialog::isSpeakImmediately () {
199 return behaviourWidget
->isSpeakImmediately ();
202 KCModule
*OptionsDialog::loadKttsd () {
203 KLibLoader
*loader
= KLibLoader::self();
205 QString libname
= "kcm_kttsd";
206 KLibrary
*lib
= loader
->library(QFile::encodeName(libname
));
209 libname
= "libkcm_kttsd";
210 lib
= loader
->library(QFile::encodeName("libkcm_kttsd"));
214 QString
initSym("init_");
217 if (lib
->hasSymbol(QFile::encodeName(initSym
))) {
218 // Reuse "lib" instead of letting createInstanceFromLibrary recreate it
219 KLibFactory
*factory
= lib
->factory();
221 KCModule
*module
= KParts::ComponentFactory::createInstanceFromFactory
<KCModule
> (factory
);
232 void OptionsDialog::unloadKttsd () {
233 KLibLoader
*loader
= KLibLoader::self();
234 loader
->unloadLibrary(QFile::encodeName("libkcm_kttsd"));
235 loader
->unloadLibrary(QFile::encodeName("kcm_kttsd"));
238 #include "optionsdialog.moc"