Fix some error
[kdeaccessibility.git] / kmouth / optionsdialog.cpp
blobbfe62adadf225176218c7fceb15a26c81b1a2e57
1 /***************************************************************************
2 optionsdialog.cpp - description
3 -------------------
4 begin : Don Nov 21 2002
5 copyright : (C) 2002 by Gunnar Schmi Dt
6 email : kmouth@schmi-dt.de
7 ***************************************************************************/
9 /***************************************************************************
10 * *
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. *
15 * *
16 ***************************************************************************/
19 #include <qlayout.h>
20 #include <qlabel.h>
21 #include <q3whatsthis.h>
22 #include <q3grid.h>
23 #include <qtabwidget.h>
24 #include <qpixmap.h>
25 #include <qfile.h>
27 #include <kcombobox.h>
28 #include <klocale.h>
29 #include <kconfig.h>
30 #include <kglobal.h>
31 #include <kiconloader.h>
32 #include <kcmodule.h>
33 #include <klibloader.h>
34 #include <kparts/componentfactory.h>
36 #include "optionsdialog.h"
37 #include "wordcompletion/wordcompletionwidget.h"
39 #include "texttospeechconfigurationwidget.h"
40 #include "speech.h"
42 PreferencesWidget::PreferencesWidget (QWidget *parent, const char *name)
43 : PreferencesUI (parent, name)
45 speakCombo->setCurrentItem (1);
46 speak = false;
48 closeCombo->setCurrentItem (2);
49 save = 2;
52 PreferencesWidget::~PreferencesWidget() {
55 void PreferencesWidget::cancel() {
56 if (speak)
57 speakCombo->setCurrentItem (0);
58 else
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")
72 speak = true;
73 else
74 speak = false;
75 else
76 speak = false;
78 config->setGroup("Notification Messages");
79 if (config->hasKey("AutomaticSave"))
80 if (config->readEntry ("AutomaticSave") == "Yes")
81 save = 0;
82 else
83 save = 1;
84 else
85 save = 2;
87 if (speak)
88 speakCombo->setCurrentItem (0);
89 else
90 speakCombo->setCurrentItem (1);
91 closeCombo->setCurrentItem (save);
94 void PreferencesWidget::saveOptions (KConfig *config) {
95 config->setGroup("Preferences");
96 if (speak)
97 config->writeEntry ("AutomaticSpeak", "Yes");
98 else
99 config->writeEntry ("AutomaticSpeak", "No");
101 config->setGroup("Notification Messages");
102 if (save == 0)
103 config->writeEntry ("AutomaticSave", "Yes");
104 else if (save == 1)
105 config->writeEntry ("AutomaticSave", "No");
106 else
107 config->deleteEntry ("AutomaticSave");
110 bool PreferencesWidget::isSpeakImmediately () {
111 return speak;
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 KHBox *pageGeneral = addHBoxPage( i18n("General Options"), QString::null, iconGeneral);
125 //addGridPage (1, Qt::Horizontal, i18n("General Options"), QString::null, iconGeneral);
127 tabCtl = new QTabWidget (pageGeneral, "general");
129 behaviourWidget = new PreferencesWidget (tabCtl, "prefPage");
130 behaviourWidget->layout()->setMargin(KDialog::marginHint());
131 tabCtl->addTab (behaviourWidget, i18n("&Preferences"));
133 commandWidget = new TextToSpeechConfigurationWidget (tabCtl, "ttsTab");
134 commandWidget->layout()->setMargin(KDialog::marginHint());
135 tabCtl->addTab (commandWidget, i18n("&Text-to-Speech"));
137 QPixmap iconCompletion = KGlobal::iconLoader()->loadIcon("keyboard", KIcon::NoGroup, KIcon::SizeMedium);
138 KHBox *pageCompletion = addHBoxPage (i18n("Word Completion"), QString::null, iconCompletion);
139 completionWidget = new WordCompletionWidget(pageCompletion, "Word Completion widget");
141 kttsd = loadKttsd();
142 if (kttsd != 0) {
143 QPixmap iconKttsd = KGlobal::iconLoader()->loadIcon("multimedia", KIcon::NoGroup, KIcon::SizeMedium);
144 KHBox *pageKttsd = addHBoxPage (i18n("KTTSD Speech Service"),
145 i18n("KDE Text-to-Speech Daemon Configuration"), iconKttsd);
147 kttsd->reparent(pageKttsd,0,QPoint(0,0),true);
151 OptionsDialog::~OptionsDialog() {
152 unloadKttsd();
155 void OptionsDialog::slotCancel() {
156 KDialogBase::slotCancel();
157 commandWidget->cancel();
158 behaviourWidget->cancel();
159 completionWidget->load();
160 if (kttsd != 0)
161 kttsd->load ();
164 void OptionsDialog::slotOk() {
165 KDialogBase::slotOk();
166 commandWidget->ok();
167 behaviourWidget->ok();
168 completionWidget->save();
169 emit configurationChanged();
170 if (kttsd != 0)
171 kttsd->save ();
175 void OptionsDialog::slotApply() {
176 KDialogBase::slotApply();
177 commandWidget->ok();
178 behaviourWidget->ok();
179 completionWidget->save();
180 emit configurationChanged();
181 if (kttsd != 0)
182 kttsd->save ();
185 TextToSpeechSystem *OptionsDialog::getTTSSystem() const {
186 return commandWidget->getTTSSystem();
189 void OptionsDialog::readOptions (KConfig *config) {
190 commandWidget->readOptions (config, "TTS System");
191 behaviourWidget->readOptions (config);
194 void OptionsDialog::saveOptions (KConfig *config) {
195 commandWidget->saveOptions (config, "TTS System");
196 behaviourWidget->saveOptions (config);
197 config->sync();
200 bool OptionsDialog::isSpeakImmediately () {
201 return behaviourWidget->isSpeakImmediately ();
204 KCModule *OptionsDialog::loadKttsd () {
205 KLibLoader *loader = KLibLoader::self();
207 QString libname = "kcm_kttsd";
208 KLibrary *lib = loader->library(QFile::encodeName(libname));
210 if (lib == 0) {
211 libname = "libkcm_kttsd";
212 lib = loader->library(QFile::encodeName("libkcm_kttsd"));
215 if (lib != 0) {
216 QString initSym("init_");
217 initSym += libname;
219 if (lib->hasSymbol(QFile::encodeName(initSym))) {
220 // Reuse "lib" instead of letting createInstanceFromLibrary recreate it
221 KLibFactory *factory = lib->factory();
222 if (factory != 0) {
223 KCModule *module = factory->create<KCModule> (factory);
224 if (module)
225 return module;
229 lib->unload();
231 return 0;
234 void OptionsDialog::unloadKttsd () {
235 KLibLoader *loader = KLibLoader::self();
236 loader->unloadLibrary(QFile::encodeName("libkcm_kttsd"));
237 loader->unloadLibrary(QFile::encodeName("kcm_kttsd"));
240 #include "optionsdialog.moc"