Remove this line
[kdeaccessibility.git] / kmouth / configwizard.cpp
blobf612d8627527a247c5585e1719971e5021e4977e
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 ***************************************************************************/
18 #include "configwizard.h"
20 #include <QtGui/QLayout>
21 #include <QtGui/QLabel>
23 #include <k3listview.h>
24 #include <klocale.h>
25 #include <kapplication.h>
26 #include <kstandarddirs.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 setWindowTitle(i18n("Initial Configuration - KMouth"));
39 initCommandPage (config);
40 initBookPage ();
41 initCompletion (config);
44 ConfigWizard::~ConfigWizard() {
47 void ConfigWizard::initCommandPage(KConfig *config) {
48 KConfigGroup cg(config, "TTS System");
49 bool displayCommand = false;
50 if (!cg.hasKey("Command")) displayCommand = true;
51 if (!cg.hasKey("StdIn")) displayCommand = true;
52 if (!cg.hasKey("Codec")) displayCommand = true;
54 if (displayCommand) {
55 commandWidget = new TextToSpeechConfigurationWidget (this, "ttsPage");
56 commandWidget->readOptions (config, "TTS System");
57 addPage (commandWidget, i18n("Text-to-Speech Configuration"));
58 setHelpEnabled (commandWidget, true);
59 setFinishEnabled (commandWidget, true);
61 else
62 commandWidget = 0;
65 void ConfigWizard::initBookPage() {
66 QString standardBook = KGlobal::dirs()->findResource("appdata", "standard.phrasebook");
67 bool displayBook = (standardBook.isNull() || standardBook.isEmpty());
69 if (displayBook) {
70 bookWidget = new InitialPhraseBookWidget (this, "pbPage");
71 addPage (bookWidget, i18n("Initial Phrase Book"));
72 setHelpEnabled (bookWidget, true);
73 setFinishEnabled (bookWidget, true);
74 if (commandWidget != 0)
75 setFinishEnabled (commandWidget, false);
77 else
78 bookWidget = 0;
81 void ConfigWizard::initCompletion (KConfig *config) {
82 if (!WordCompletion::isConfigured()) {
83 QString dictionaryFile = KGlobal::dirs()->findResource("appdata", "dictionary.txt");
84 QFile file(dictionaryFile);
85 if (file.exists()) {
86 // If there is a word completion dictionary but no entry in the
87 // configuration file, we need to add it there.
88 KConfigGroup cg (config ,"Dictionary 0");
89 cg.writeEntry ("Filename", "dictionary.txt");
90 cg.writeEntry ("Name", "Default");
91 cg.writeEntry ("Language", QString());
92 cg.sync();
96 if (config->hasGroup("Completion")) {
97 completionWidget = 0;
98 return;
101 if (!WordCompletion::isConfigured()) {
102 completionWidget = new CompletionWizardWidget(this, "completionPage");
103 addPage (completionWidget, i18n("Word Completion"));
104 setHelpEnabled (completionWidget, true);
105 setFinishEnabled (completionWidget, true);
107 if (commandWidget != 0)
108 setFinishEnabled (commandWidget, false);
109 if (bookWidget != 0)
110 setFinishEnabled (bookWidget, false);
112 else
113 completionWidget = 0;
116 void ConfigWizard::saveConfig (KConfig *config) {
117 if (commandWidget != 0) {
118 commandWidget->ok();
119 commandWidget->saveOptions (config, "TTS System");
122 if (bookWidget != 0)
123 bookWidget->createBook();
125 if (completionWidget != 0)
126 completionWidget->ok (config);
129 bool ConfigWizard::requestConfiguration () {
130 if (commandWidget != 0 || bookWidget != 0 || completionWidget != 0)
131 return (exec() == QDialog::Accepted);
132 else
133 return false;
136 bool ConfigWizard::configurationNeeded () {
137 return (commandWidget != 0 || bookWidget != 0 || completionWidget != 0);
140 void ConfigWizard::help () {
141 KToolInvocation::invokeHelp ("Wizard");
144 #include "configwizard.moc"