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>
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", K3Icon::NoGroup
, K3Icon::SizeMedium
);
123 KHBox
*pageGeneral
= addHBoxPage( i18n("General Options"), QString(), iconGeneral
);
125 //addGridPage (1, Qt::Horizontal, i18n("General Options"), QString(), 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", K3Icon::NoGroup
, K3Icon::SizeMedium
);
138 KHBox
*pageCompletion
= addHBoxPage (i18n("Word Completion"), QString(), iconCompletion
);
139 completionWidget
= new WordCompletionWidget(pageCompletion
, "Word Completion widget");
143 QPixmap iconKttsd
= KGlobal::iconLoader()->loadIcon("multimedia", K3Icon::NoGroup
, K3Icon::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() {
155 void OptionsDialog::slotCancel() {
156 KDialogBase::slotCancel();
157 commandWidget
->cancel();
158 behaviourWidget
->cancel();
159 completionWidget
->load();
164 void OptionsDialog::slotOk() {
165 KDialogBase::slotOk();
167 behaviourWidget
->ok();
168 completionWidget
->save();
169 emit
configurationChanged();
175 void OptionsDialog::slotApply() {
176 KDialogBase::slotApply();
178 behaviourWidget
->ok();
179 completionWidget
->save();
180 emit
configurationChanged();
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
);
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
));
211 libname
= "libkcm_kttsd";
212 lib
= loader
->library(QFile::encodeName("libkcm_kttsd"));
216 QString
initSym("init_");
219 if (lib
->hasSymbol(QFile::encodeName(initSym
))) {
220 // Reuse "lib" instead of letting createInstanceFromLibrary recreate it
221 KLibFactory
*factory
= lib
->factory();
223 KCModule
*module
= factory
->create
<KCModule
> (factory
);
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"