compile/link
[kdeaccessibility.git] / kmouth / configwizard.cpp
blobb1a701f49e6d4932d7cf3b14b5d447cb534ec9af
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.h>
21 #include <qlabel.h>
22 #include <klistview.h>
23 #include <klocale.h>
24 #include <kapplication.h>
25 #include <kstandarddirs.h>
26 #include <ksconfig.h>
27 #include <kconfig.h>
28 #include <ktoolinvocation.h>
30 #include "texttospeechconfigurationwidget.h"
31 #include "phrasebook/phrasebookdialog.h"
32 #include "wordcompletion/wordcompletion.h"
33 #include "wordcompletion/dictionarycreationwizard.h"
35 ConfigWizard::ConfigWizard (QWidget *parent, const char *name, KConfig *config)
36 : K3Wizard(parent, name, true)
38 setCaption (i18n("Initial Configuration - KMouth"));
40 initCommandPage (config);
41 initBookPage ();
42 initCompletion (config);
45 ConfigWizard::~ConfigWizard() {
48 void ConfigWizard::initCommandPage(KConfig *config) {
49 config->setGroup("TTS System");
50 bool displayCommand = false;
51 if (!config->hasKey("Command")) displayCommand = true;
52 if (!config->hasKey("StdIn")) displayCommand = true;
53 if (!config->hasKey("Codec")) displayCommand = true;
55 if (displayCommand) {
56 commandWidget = new TextToSpeechConfigurationWidget (this, "ttsPage");
57 commandWidget->readOptions (config, "TTS System");
58 addPage (commandWidget, i18n("Text-to-Speech Configuration"));
59 setHelpEnabled (commandWidget, true);
60 setFinishEnabled (commandWidget, true);
62 else
63 commandWidget = 0;
66 void ConfigWizard::initBookPage() {
67 QString standardBook = KApplication::kApplication()->dirs()->findResource("appdata", "standard.phrasebook");
68 bool displayBook = (standardBook.isNull() || standardBook.isEmpty());
70 if (displayBook) {
71 bookWidget = new InitialPhraseBookWidget (this, "pbPage");
72 addPage (bookWidget, i18n("Initial Phrase Book"));
73 setHelpEnabled (bookWidget, true);
74 setFinishEnabled (bookWidget, true);
75 if (commandWidget != 0)
76 setFinishEnabled (commandWidget, false);
78 else
79 bookWidget = 0;
82 void ConfigWizard::initCompletion (KConfig *config) {
83 if (!WordCompletion::isConfigured()) {
84 QString dictionaryFile = KApplication::kApplication()->dirs()->findResource("appdata", "dictionary.txt");
85 QFile file(dictionaryFile);
86 if (file.exists()) {
87 // If there is a word completion dictionary but no entry in the
88 // configuration file, we need to add it there.
89 config->setGroup("Dictionary 0");
90 config->writeEntry ("Filename", "dictionary.txt");
91 config->writeEntry ("Name", "Default");
92 config->writeEntry ("Language", QString());
93 config->sync();
97 if (config->hasGroup("Completion")) {
98 completionWidget = 0;
99 return;
102 if (!WordCompletion::isConfigured()) {
103 completionWidget = new CompletionWizardWidget(this, "completionPage");
104 addPage (completionWidget, i18n("Word Completion"));
105 setHelpEnabled (completionWidget, true);
106 setFinishEnabled (completionWidget, true);
108 if (commandWidget != 0)
109 setFinishEnabled (commandWidget, false);
110 if (bookWidget != 0)
111 setFinishEnabled (bookWidget, false);
113 else
114 completionWidget = 0;
117 void ConfigWizard::saveConfig (KConfig *config) {
118 if (commandWidget != 0) {
119 commandWidget->ok();
120 commandWidget->saveOptions (config, "TTS System");
123 if (bookWidget != 0)
124 bookWidget->createBook();
126 if (completionWidget != 0)
127 completionWidget->ok (config);
130 bool ConfigWizard::requestConfiguration () {
131 if (commandWidget != 0 || bookWidget != 0 || completionWidget != 0)
132 return (exec() == QDialog::Accepted);
133 else
134 return false;
137 bool ConfigWizard::configurationNeeded () {
138 return (commandWidget != 0 || bookWidget != 0 || completionWidget != 0);
141 void ConfigWizard::help () {
142 KToolInvocation::invokeHelp ("Wizard");
145 #include "configwizard.moc"