SVN_SILENT made messages (.desktop file)
[kdeaccessibility.git] / kmouth / optionsdialog.cpp
blob115aaa66f9150b6da66f7aeee6a085a619e350f8
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 ***************************************************************************/
18 #include "optionsdialog.h"
19 #include "wordcompletion/wordcompletionwidget.h"
21 #include "texttospeechconfigurationwidget.h"
22 #include "speech.h"
24 #include <QtGui/QLayout>
25 #include <QtGui/QLabel>
26 #include <Qt3Support/Q3Grid>
27 #include <QtGui/QPixmap>
28 #include <QtCore/QFile>
30 #include <kcombobox.h>
31 #include <ktabwidget.h>
32 #include <klocale.h>
33 #include <kconfig.h>
34 #include <kglobal.h>
35 #include <kcmodule.h>
36 #include <klibloader.h>
37 #include <kicon.h>
38 #include <kpagewidgetmodel.h>
39 #include <kparts/componentfactory.h>
41 PreferencesWidget::PreferencesWidget (QWidget *parent, const char *name)
42 : QWidget (parent)
44 setObjectName(name);
45 setupUi(this);
46 speakCombo->setCurrentIndex (1);
47 speak = false;
49 closeCombo->setCurrentIndex (2);
50 save = 2;
53 PreferencesWidget::~PreferencesWidget() {
56 void PreferencesWidget::cancel() {
57 if (speak)
58 speakCombo->setCurrentIndex (0);
59 else
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")
73 speak = true;
74 else
75 speak = false;
76 else
77 speak = false;
79 KConfigGroup cg2 ( config ,"Notification Messages");
80 if (cg2.hasKey("AutomaticSave"))
81 if (cg2.readEntry ("AutomaticSave") == "Yes")
82 save = 0;
83 else
84 save = 1;
85 else
86 save = 2;
88 if (speak)
89 speakCombo->setCurrentIndex (0);
90 else
91 speakCombo->setCurrentIndex (1);
92 closeCombo->setCurrentIndex (save);
95 void PreferencesWidget::saveOptions (KConfig *config) {
96 KConfigGroup cg (config, "Preferences");
97 if (speak)
98 cg.writeEntry ("AutomaticSpeak", "Yes");
99 else
100 cg.writeEntry ("AutomaticSpeak", "No");
102 KConfigGroup cg2 (config, "Notification Messages");
103 if (save == 0)
104 cg2.writeEntry ("AutomaticSave", "Yes");
105 else if (save == 1)
106 cg2.writeEntry ("AutomaticSave", "No");
107 else
108 cg2.deleteEntry ("AutomaticSave");
111 bool PreferencesWidget::isSpeakImmediately () {
112 return speak;
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 KTabWidget();
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);
150 kttsd = loadKttsd();
151 if (kttsd != 0) {
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"));
155 addPage(pageKttsd);
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() {
166 unloadKttsd();
169 void OptionsDialog::slotCancel() {
170 // KDialog::slotCancel();
171 commandWidget->cancel();
172 behaviourWidget->cancel();
173 completionWidget->load();
174 if (kttsd != 0)
175 kttsd->load ();
178 void OptionsDialog::slotOk() {
179 // KDialog::slotOk();
180 commandWidget->ok();
181 behaviourWidget->ok();
182 completionWidget->save();
183 emit configurationChanged();
184 if (kttsd != 0)
185 kttsd->save ();
189 void OptionsDialog::slotApply() {
190 // KDialog::slotApply();
191 commandWidget->ok();
192 behaviourWidget->ok();
193 completionWidget->save();
194 emit configurationChanged();
195 if (kttsd != 0)
196 kttsd->save ();
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);
211 config->sync();
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));
224 if (lib == 0) {
225 libname = "libkcm_kttsd";
226 lib = loader->library(QFile::encodeName("libkcm_kttsd"));
229 if (lib != 0) {
230 QString initSym("init_");
231 initSym += libname;
233 if (lib->resolveFunction(QFile::encodeName(initSym))) {
234 // Reuse "lib" instead of letting createInstanceFromLibrary recreate it
235 KLibFactory *factory = lib->factory();
236 if (factory != 0) {
237 KCModule *module = factory->create<KCModule> (factory);
238 if (module)
239 return module;
243 lib->unload();
245 return 0;
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"