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
|
/***************************************************************************
maintain a document in vocabbox format
-----------------------------------------------------------------------
begin : Thr Mar 23 21:00:53 MET 1999
copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de>
(C) 2001 The KDE-EDU team
(C) 2004 Peter Hedlund <peter.hedlund@kdemail.net>
-----------------------------------------------------------------------
***************************************************************************/
/***************************************************************************
* *
* 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 <klocale.h>
#include <kapplication.h>
#include <kmessagebox.h>
#include "kvoctraindoc.h"
#include "kvoctraincore.h"
bool kvoctrainDoc::saveTypeNameVcb (TQTextStream &/*os*/)
{
return true;
}
bool kvoctrainDoc::loadTypeNameVcb (TQTextStream &/*is*/)
{
return true;
}
bool kvoctrainDoc::saveLessonVcb (TQTextStream &/*os*/)
{
return true;
}
bool kvoctrainDoc::loadLessonVcb (TQTextStream &/*is*/)
{
return true;
}
bool kvoctrainDoc::saveToVcb (TQTextStream& os, TQString &/*title*/)
{
saveTypeNameVcb (os);
saveLessonVcb (os);
int ent_no = 0;
int ent_percent = (int) vocabulary.size () / 100;
float f_ent_percent = (int) vocabulary.size () / 100.0;
emit progressChanged(this, 0);
vector<kvoctrainExpr>::const_iterator first = vocabulary.begin ();
while (first != vocabulary.end ()) {
ent_no++;
if (ent_percent != 0 && (ent_no % ent_percent) == 0 )
emit progressChanged(this, int(ent_no / f_ent_percent));
TQString s, exp;
exp = (*first).getOriginal()+VCB_SEPARATOR;
exp += (*first).getTranslation(1)+VCB_SEPARATOR;
exp += (*first).gradeStr (1, false)+VCB_SEPARATOR;
exp += (*first).gradeStr (1, true)+VCB_SEPARATOR;
s.setNum ((*first).getQueryDate (1, false));
exp += s+VCB_SEPARATOR;
s.setNum ((*first).getQueryDate (1, true));
exp += s;
os << exp << "\n";
first++;
}
setModified (false);
return os.tqdevice()->status() == IO_Ok;
}
bool kvoctrainDoc::loadFromVcb (TQTextStream& is)
{
langs.clear();
vocabulary.clear();
loadTypeNameVcb (is);
loadLessonVcb (is);
int size = is.tqdevice()->size ();
int ln = size / 40 / 100; // assume each line about 40 chars
float f_ent_percent = size / 100.0;
emit progressChanged (this, 0);
for (int l = 0; !is.eof(); l++) {
TQString s = is.readLine();
ln--;
if (ln <= 0) {
ln = size / 40 / 100; // assume each line about 40 chars
emit progressChanged(this, int(is.tqdevice()->at() / f_ent_percent));
}
if (!s.stripWhiteSpace().isEmpty()) {
TQString o, t;
grade_t ograde = KV_LEV1_GRADE,
tgrade = KV_LEV1_GRADE;
size_t odate = time(0),
tdate = time(0);
int pos = s.tqfind (VCB_SEPARATOR);
if (pos >= 0) {
o = s.left(pos);
s.remove (0, pos+TQString(VCB_SEPARATOR).length());
}
pos = s.tqfind (VCB_SEPARATOR);
if (pos >= 0) {
t = s.left(pos);
s.remove (0, pos+TQString(VCB_SEPARATOR).length());
}
else {
t = s;
}
pos = s.tqfind (VCB_SEPARATOR);
if (pos >= 0) {
ograde = s.left(pos).toInt();
s.remove (0, pos+TQString(VCB_SEPARATOR).length());
}
pos = s.tqfind (VCB_SEPARATOR);
if (pos >= 0) {
tgrade = s.left(pos).toInt();
s.remove (0, pos+TQString(VCB_SEPARATOR).length());
}
pos = s.tqfind (VCB_SEPARATOR);
if (pos >= 0) {
odate = s.left(pos).toInt();
s.remove (0, pos+TQString(VCB_SEPARATOR).length());
}
if (s.stripWhiteSpace().length() > 0) {
tdate = s.toInt();
}
kvoctrainExpr bucket;
bucket.setOriginal(o);
bucket.addTranslation(t);
bucket.setGrade(1, ograde, false);
if (ograde != 0)
bucket.setQueryCount(1, 1, false);
bucket.setGrade(1, tgrade, true);
if (tgrade != 0)
bucket.setQueryCount(1, 1, true);
bucket.setQueryDate(1, odate, false);
bucket.setQueryDate(1, tdate, true);
appendEntry (&bucket);
}
}
langs.push_back("en");
langs.push_back("en");
setModified (false);
return is.tqdevice()->status() == IO_Ok;
}
void kvoctrainDoc::errorVcb (int /*line*/, const TQString &text )
{
unknown_elem = true;
TQApplication::setOverrideCursor( arrowCursor, true );
TQString s = kapp->makeStdCaption(i18n("Error in vocabbox file"));
TQString msg = text;
KMessageBox::error(0, msg, s);
TQApplication::restoreOverrideCursor();
}
|