SVN_SILENT made messages (.desktop file)
[kdeaccessibility.git] / kmouth / configwizard.cpp
blob20abd48e27420cd2fb8c91eadb032588af57fe34
1 /***************************************************************************
2 configwizard.cpp - description
3 -------------------
4 begin : Mit Nov 20 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 "configwizard.h"
20 #include <QLayout>
21 #include <QLabel>
22 #include <k3listview.h>
23 #include <klocale.h>
24 #include <kapplication.h>
25 #include <kstandarddirs.h>
26 #include <kconfig.h>
27 #include <ktoolinvocation.h>
29 #include "texttospeechconfigurationwidget.h"
30 #include "phrasebook/phrasebookdialog.h"
31 #include "wordcompletion/wordcompletion.h"
32 #include "wordcompletion/dictionarycreationwizard.h"
34 ConfigWizard::ConfigWizard (QWidget *parent, const char *name, KConfig *config)
35 : K3Wizard(parent, name, true)
37 setWindowTitle(i18n("Initial Configuration - KMouth"));
38 initCommandPage (config);
39 initBookPage ();
40 initCompletion (config);
43 ConfigWizard::~ConfigWizard() {
46 void ConfigWizard::initCommandPage(KConfig *config) {
47 KConfigGroup cg(config, "TTS System");
48 bool displayCommand = false;
49 if (!cg.hasKey("Command")) displayCommand = true;
50 if (!cg.hasKey("StdIn")) displayCommand = true;
51 if (!cg.hasKey("Codec")) displayCommand = true;
53 if (displayCommand) {
54 commandWidget = new TextToSpeechConfigurationWidget (this, "ttsPage");
55 commandWidget->readOptions (config, "TTS System");
56 addPage (commandWidget, i18n("Text-to-Speech Configuration"));
57 setHelpEnabled (commandWidget, true);
58 setFinishEnabled (commandWidget, true);
60 else
61 commandWidget = 0;
64 void ConfigWizard::initBookPage() {
65 QString standardBook = KGlobal::dirs()->findResource("appdata", "standard.phrasebook");
66 bool displayBook = (standardBook.isNull() || standardBook.isEmpty());
68 if (displayBook) {
69 bookWidget = new InitialPhraseBookWidget (this, "pbPage");
70 addPage (bookWidget, i18n("Initial Phrase Book"));
71 setHelpEnabled (bookWidget, true);
72 setFinishEnabled (bookWidget, true);
73 if (commandWidget != 0)
74 setFinishEnabled (commandWidget, false);
76 else
77 bookWidget = 0;
80 void ConfigWizard::initCompletion (KConfig *config) {
81 if (!WordCompletion::isConfigured()) {
82 QString dictionaryFile = KGlobal::dirs()->findResource("appdata", "dictionary.txt");
83 QFile file(dictionaryFile);
84 if (file.exists()) {
85 // If there is a word completion dictionary but no entry in the
86 // configuration file, we need to add it there.
87 KConfigGroup cg (config ,"Dictionary 0");
88 cg.writeEntry ("Filename", "dictionary.txt");
89 cg.writeEntry ("Name", "Default");
90 cg.writeEntry ("Language", QString());
91 cg.sync();
95 if (config->hasGroup("Completion")) {
96 completionWidget = 0;
97 return;
100 if (!WordCompletion::isConfigured()) {
101 completionWidget = new CompletionWizardWidget(this, "completionPage");
102 addPage (completionWidget, i18n("Word Completion"));
103 setHelpEnabled (completionWidget, true);
104 setFinishEnabled (completionWidget, true);
106 if (commandWidget != 0)
107 setFinishEnabled (commandWidget, false);
108 if (bookWidget != 0)
109 setFinishEnabled (bookWidget, false);
111 else
112 completionWidget = 0;
115 void ConfigWizard::saveConfig (KConfig *config) {
116 if (commandWidget != 0) {
117 commandWidget->ok();
118 commandWidget->saveOptions (config, "TTS System");
121 if (bookWidget != 0)
122 bookWidget->createBook();
124 if (completionWidget != 0)
125 completionWidget->ok (config);
128 bool ConfigWizard::requestConfiguration () {
129 if (commandWidget != 0 || bookWidget != 0 || completionWidget != 0)
130 return (exec() == QDialog::Accepted);
131 else
132 return false;
135 bool ConfigWizard::configurationNeeded () {
136 return (commandWidget != 0 || bookWidget != 0 || completionWidget != 0);
139 void ConfigWizard::help () {
140 KToolInvocation::invokeHelp ("Wizard");
143 #include "configwizard.moc"