summaryrefslogtreecommitdiffstats
path: root/klatin/klatin/klatin.cpp
blob: 09a8a426f917c1ababc79bc291e093c44489bc7c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/***************************************************************************
    begin                : Thu Jul 17
    copyright            : (C) 2001-2004 by George Wright
    email                : gwright@kde.org
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include <tqradiobutton.h>

#include <kapplication.h>
#include <kconfigdialog.h>
#include <kfiledialog.h>
#include <kiconloader.h>
#include <klocale.h>
#include <kpushbutton.h>
#include <kstandarddirs.h>
#include <kstatusbar.h>
#include <kurlrequester.h>

#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>

#include "klatin.h"
#include "settings.h"

KLatin::KLatin(TQWidget* parent, const char *name)
	: KMainWindow(parent, name)
{
	m_section = 0;
	
	// Setup the actions for the menubar
	setupActions();

	// Used for resetting the GUI after leaving
	// a section, but used here to initialise
	// the GUI for the first time.
	resetGUI();
}

KLatin::~KLatin()
{
}

void KLatin::setupActions()
{
	// Setup various menu actions
	KStdAction::preferences(this, TQT_SLOT(loadSettings()), actionCollection());
	m_loadVocab = new KAction(i18n("Load &Vocabulary"), 0, this, TQT_SLOT(loadVocab()),  actionCollection(), "go_vocab");
	m_loadGrammar = new KAction(i18n("Load &Grammar"), 0, this, TQT_SLOT(loadGrammar()),  actionCollection(), "go_grammar");
	m_loadVerbs = new KAction(i18n("Load V&erbs"), 0, this, TQT_SLOT(loadVerbs()),  actionCollection(), "go_verbs");
	m_loadRevision = new KAction(i18n("Load &Revision"), 0, this, TQT_SLOT(loadRevision()),  actionCollection(), "go_revision");
	KStdAction::quit(kapp, TQT_SLOT(quit()), actionCollection());
}

void KLatin::startClicked()
{
	if (klatinchoose->VocabOption->isOn())
		loadVocab();
	if (klatinchoose->GrammarOption->isOn())
		loadGrammar();
	if (klatinchoose->VerbsOption->isOn())
		loadVerbs();
	if (klatinchoose->RevisionOption->isOn())
		loadRevision();
}

// Start of section loading code

void KLatin::loadVocab()
{
	klatinchoose->close();
	
	klatinvocabsection = new KLatinVocab(this);
	klatinvocabsection->show();

	slotWriteMsg(i18n("Ready"));

	// Set this widget as the central widget
	setCentralWidget(klatinvocabsection);

	updateSection(FALSE);
	
	// When the child emits the signal exitted(),
	// then reset the GUI to go back to the menu
	connect(klatinvocabsection, TQT_SIGNAL(exited()), this, TQT_SLOT(resetGUI()));

	// Set the section variable
	m_section = 1;
}

void KLatin::loadGrammar()
{
	klatinchoose->close();
	
	klatingrammarsection = new KLatinGrammar(this);
	klatingrammarsection->show();

	slotWriteMsg(i18n("Grammar"));

	// Disable all the menu entries under Section/
	updateSection(FALSE);
	
	// Set this widget as the central widget
	setCentralWidget(klatingrammarsection);

	// When the child emits the signal exited(),
	// then reset the GUI to go back to the menu
	connect(klatingrammarsection, TQT_SIGNAL(exited()), this, TQT_SLOT(resetGUI()));
	connect(klatingrammarsection, TQT_SIGNAL(statusMsg(const TQString&)), this, TQT_SLOT(slotWriteMsg(const TQString&)));
	// Set the section variable
	m_section = 2;
}

void KLatin::slotWriteMsg(const TQString& message)
{
	statusBar()->message(message);
}

void KLatin::loadVerbs()
{
	klatinchoose->close();
	
	klatinverbssection = new KLatinVerbs(this);
	klatinverbssection->show();

	slotWriteMsg(i18n("Verbs"));

	// Disable all the menu entries under Section/
	updateSection(FALSE);

	// Set this widget as the central widget
	setCentralWidget(klatinverbssection);

	// When the child emits the signal exited(),
	// then reset the GUI to go back to the menu
	connect(klatinverbssection, TQT_SIGNAL(exited()), this, TQT_SLOT(resetGUI()));
	connect(klatinverbssection, TQT_SIGNAL(statusMsg(const TQString&)), this, TQT_SLOT(slotWriteMsg(const TQString&)));

	// Set the section variable
	m_section = 3;
}

void KLatin::loadRevision()
{
	kapp->invokeHelp("klatin-index", "klatin");
}

void KLatin::loadSettings()
{
	if (KConfigDialog::showDialog("settings")) 
		return; 

	KConfigDialog *dialog = new KConfigDialog(this, "settings", Settings::self());
	
	vocabPage = new VocabPage(0); 
	vocabPage->kcfg_DefaultFile->setMode(KFile::File | KFile::LocalOnly);
	vocabPage->kcfg_DefaultFile->setFilter("*.kvtml");
	vocabPage->kcfg_DefaultFile->setCaption(i18n("Load Vocabulary File"));
	dialog->addPage(vocabPage, i18n("Vocabulary"), "kdict"); 
	connect(dialog, TQT_SIGNAL(settingsChanged()), this, TQT_SLOT(settingsChanged())); 
	dialog->show();
}

void KLatin::settingsChanged()
{
	// Only the vocab section so far needs config refreshed for it
	if (m_section == 1) {
		klatinvocabsection->changeVocab(Settings::defaultFile());
	}
}

void KLatin::resetGUI()
{
	// Load the central widget to show the user the
	// various options that are available to choose
	// and setCentralWidget it.
	klatinchoose = new KLatinChoose(this);
	klatinchoose->QuitButton->setIconSet(KGlobal::iconLoader()->loadIconSet("exit", KIcon::Small));
	klatinchoose->show();
	setCentralWidget(klatinchoose);

	// Connect the "Start" button to slot StartPressed()
	connect(klatinchoose->StartButton, TQT_SIGNAL(clicked()), this, TQT_SLOT(startClicked()));
	// Make the quit button quit the application :)
	connect(klatinchoose->QuitButton, TQT_SIGNAL(clicked()), kapp, TQT_SLOT(quit()));
	
	// Enable all the menu entries under Section/
	updateSection(TRUE);

	// Use XML GUI to construct the menubar
	setupGUI();

	// Reset the section variable
	m_section = 0;

	slotWriteMsg(i18n("Ready"));
}

void KLatin::updateSection(bool m_bool)
{
	// Disable all the menu entries under Section/
	m_loadVocab->setEnabled(m_bool);
	m_loadGrammar->setEnabled(m_bool);
	m_loadVerbs->setEnabled(m_bool);
	m_loadRevision->setEnabled(m_bool);
}

#include "klatin.moc"