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 ***************************************************************************/
8
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 ***************************************************************************/
17
18#include "configwizard.h"
19
20#include <QtGui/QLayout>
21#include <QtGui/QLabel>
22
23#include <k3listview.h>
24#include <klocale.h>
25#include <kapplication.h>
26#include <kstandarddirs.h>
27#include <kconfig.h>
28#include <ktoolinvocation.h>
29
30#include "texttospeechconfigurationwidget.h"
31#include "phrasebook/phrasebookdialog.h"
32#include "wordcompletion/wordcompletion.h"
33#include "wordcompletion/dictionarycreationwizard.h"
34
35ConfigWizard::ConfigWizard (QWidget *parent, const char *name, KConfig *config)
36 : K3Wizard(parent, name, true)
37{
38 setWindowTitle(i18n("Initial Configuration - KMouth"));
39 initCommandPage (config);
40 initBookPage ();
41 initCompletion (config);
42}
43
44ConfigWizard::~ConfigWizard() {
45}
46
47void ConfigWizard::initCommandPage(KConfig *config) {
48 KConfigGroup cg(config, QLatin1String( "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;
53
54 if (displayCommand) {
55 commandWidget = new TextToSpeechConfigurationWidget (this, "ttsPage");
56 commandWidget->readOptions (config, QLatin1String( "TTS System" ));
57 addPage (commandWidget, i18n("Text-to-Speech Configuration"));
58 setHelpEnabled (commandWidget, true);
59 setFinishEnabled (commandWidget, true);
60 }
61 else
62 commandWidget = 0;
63}
64
65void ConfigWizard::initBookPage() {
66 QString standardBook = KGlobal::dirs()->findResource("appdata", QLatin1String( "standard.phrasebook" ));
67 bool displayBook = (standardBook.isNull() || standardBook.isEmpty());
68
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);
76 }
77 else
78 bookWidget = 0;
79}
80
81void ConfigWizard::initCompletion (KConfig *config) {
82 if (!WordCompletion::isConfigured()) {
83 QString dictionaryFile = KGlobal::dirs()->findResource("appdata", QLatin1String( "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();
93 }
94 }
95
96 if (config->hasGroup("Completion")) {
97 completionWidget = 0;
98 return;
99 }
100
101 if (!WordCompletion::isConfigured()) {
102 completionWidget = new CompletionWizardWidget(this, "completionPage");
103 addPage (completionWidget, i18n("Word Completion"));
104 setHelpEnabled (completionWidget, true);
105 setFinishEnabled (completionWidget, true);
106
107 if (commandWidget != 0)
108 setFinishEnabled (commandWidget, false);
109 if (bookWidget != 0)
110 setFinishEnabled (bookWidget, false);
111 }
112 else
113 completionWidget = 0;
114}
115
116void ConfigWizard::saveConfig (KConfig *config) {
117 if (commandWidget != 0) {
118 commandWidget->ok();
119 commandWidget->saveOptions (config, QLatin1String( "TTS System" ));
120 }
121
122 if (bookWidget != 0)
123 bookWidget->createBook();
124
125 if (completionWidget != 0)
126 completionWidget->ok (config);
127}
128
129bool ConfigWizard::requestConfiguration () {
130 if (commandWidget != 0 || bookWidget != 0 || completionWidget != 0)
131 return (exec() == QDialog::Accepted);
132 else
133 return false;
134}
135
136bool ConfigWizard::configurationNeeded () {
137 return (commandWidget != 0 || bookWidget != 0 || completionWidget != 0);
138}
139
140void ConfigWizard::help () {
141 KToolInvocation::invokeHelp (QLatin1String( "Wizard" ));
142}
143
144#include "configwizard.moc"
145