Byebye Q3CString
[kdeaccessibility.git] / kmouth / optionsdialog.cpp
blobf4b883cfabdc87ce599a1f16c2ad59f587a5bea2
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 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");
139 kttsd = loadKttsd();
140 if (kttsd != 0) {
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() {
150 unloadKttsd();
153 void OptionsDialog::slotCancel() {
154 KDialogBase::slotCancel();
155 commandWidget->cancel();
156 behaviourWidget->cancel();
157 completionWidget->load();
158 if (kttsd != 0)
159 kttsd->load ();
162 void OptionsDialog::slotOk() {
163 KDialogBase::slotOk();
164 commandWidget->ok();
165 behaviourWidget->ok();
166 completionWidget->save();
167 emit configurationChanged();
168 if (kttsd != 0)
169 kttsd->save ();
173 void OptionsDialog::slotApply() {
174 KDialogBase::slotApply();
175 commandWidget->ok();
176 behaviourWidget->ok();
177 completionWidget->save();
178 emit configurationChanged();
179 if (kttsd != 0)
180 kttsd->save ();
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);
195 config->sync();
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));
208 if (lib == 0) {
209 libname = "libkcm_kttsd";
210 lib = loader->library(QFile::encodeName("libkcm_kttsd"));
213 if (lib != 0) {
214 QString initSym("init_");
215 initSym += libname;
217 if (lib->hasSymbol(QFile::encodeName(initSym))) {
218 // Reuse "lib" instead of letting createInstanceFromLibrary recreate it
219 KLibFactory *factory = lib->factory();
220 if (factory != 0) {
221 KCModule *module = KParts::ComponentFactory::createInstanceFromFactory<KCModule> (factory);
222 if (module)
223 return module;
227 lib->unload();
229 return 0;
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"