LibKEduVocDocument

keduvockvtmlcompability.cpp
1/*
2 * C++ Implementation: keduvockvtml1compability_p
3 * SPDX-FileCopyrightText: 2007 Frederik Gladhorn <frederik.gladhorn@kdemail.net>
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
7#include "keduvocwordtype.h"
8
9#include <KLocalizedString>
10
11#include <QDebug>
12
13const QString KEduVocKvtmlCompability::KVTML_1_USER_DEFINED = QStringLiteral("#");
14const QString KEduVocKvtmlCompability::KVTML_1_SEPERATOR = QStringLiteral(":");
15
16KEduVocKvtmlCompability::KEduVocKvtmlCompability()
17{
18 m_userdefinedTenseCounter = 0;
19 m_userdefinedTypeCounter = 0;
20
21 initOldTypeLists();
22 initOldTenses();
23}
24
25////////////////// TYPES /////////////////////////////////////////
26void KEduVocKvtmlCompability::initOldTypeLists()
27{
28 m_oldMainTypeNames.clear();
29 m_oldMainTypeNames.insert(QStringLiteral("v"), i18nc("@item:inlistbox The grammatical type of a word", "Verb"));
30 m_oldMainTypeNames.insert(QStringLiteral("n"), i18nc("@item:inlistbox The grammatical type of a word", "Noun"));
31 m_oldMainTypeNames.insert(QStringLiteral("nm"), i18nc("@item:inlistbox The grammatical type of a word", "Name"));
32 m_oldMainTypeNames.insert(QStringLiteral("ar"), i18nc("@item:inlistbox The grammatical type of a word", "Article"));
33 m_oldMainTypeNames.insert(QStringLiteral("aj"), i18nc("@item:inlistbox The grammatical type of a word", "Adjective"));
34 m_oldMainTypeNames.insert(QStringLiteral("av"), i18nc("@item:inlistbox The grammatical type of a word", "Adverb"));
35 m_oldMainTypeNames.insert(QStringLiteral("pr"), i18nc("@item:inlistbox The grammatical type of a word", "Pronoun"));
36 m_oldMainTypeNames.insert(QStringLiteral("ph"), i18nc("@item:inlistbox The grammatical type of an entry", "Phrase"));
37 m_oldMainTypeNames.insert(QStringLiteral("num"), i18nc("@item:inlistbox The grammatical type of a word", "Numeral"));
38 m_oldMainTypeNames.insert(QStringLiteral("con"), i18nc("@item:inlistbox The grammatical type of a word", "Conjunction"));
39 m_oldMainTypeNames.insert(QStringLiteral("pre"), i18nc("@item:inlistbox The grammatical type of a word", "Preposition"));
40 m_oldMainTypeNames.insert(QStringLiteral("qu"), i18nc("@item:inlistbox The grammatical type of an entry", "Question"));
41
42 m_oldSubTypeNames.clear();
43 m_oldSubTypeNames.insert(QStringLiteral("ord"),
44 i18nc("@item:inlistbox A subtype of the grammatical word type: Numeral Ordinal (first, second, third, ...)", "Ordinal"));
45 m_oldSubTypeNames.insert(QStringLiteral("crd"),
46 i18nc("@item:inlistbox A subtype of the grammatical word type: Numeral Cardinal (one, two, three, ...)", "Cardinal"));
47 m_oldSubTypeNames.insert(QStringLiteral("def"), i18nc("@item:inlistbox A subtype of the grammatical word type: Article (the)", "Definite"));
48 m_oldSubTypeNames.insert(QStringLiteral("ind"), i18nc("@item:inlistbox A subtype of the grammatical word type: Article (a)", "Indefinite"));
49 m_oldSubTypeNames.insert(QStringLiteral("re"), i18nc("@item:inlistbox A subtype of the grammatical word type: Verb with regular conjugation", "Regular"));
50 m_oldSubTypeNames.insert(QStringLiteral("ir"),
51 i18nc("@item:inlistbox A subtype of the grammatical word type: Verb with irregular conjugation", "Irregular"));
52 m_oldSubTypeNames.insert(QStringLiteral("pos"),
53 i18nc("@item:inlistbox A subtype of the grammatical word type: Pronoun (my, your, his, her...)", "Possessive"));
54 m_oldSubTypeNames.insert(QStringLiteral("per"), i18nc("@item:inlistbox A subtype of the grammatical word type: Pronoun (I, you, he...)", "Personal"));
55 m_oldSubTypeNames.insert(QStringLiteral("m"), i18nc("@item:inlistbox A subtype of the grammatical word type: Noun", "Male"));
56 m_oldSubTypeNames.insert(QStringLiteral("f"), i18nc("@item:inlistbox A subtype of the grammatical word type: Noun", "Female"));
57 m_oldSubTypeNames.insert(QStringLiteral("s"), i18nc("@item:inlistbox A subtype of the grammatical word type: Noun", "Neutral"));
58}
59
60KEduVocWordType *KEduVocKvtmlCompability::typeFromOldFormat(KEduVocWordType *parent, const QString &typeSubtypeString) const
61{
62 // check if it's user defined
63 if (typeSubtypeString.length() >= 2 && typeSubtypeString.left(1) == QM_USER_TYPE) {
64 // they started counting at 1, we need to know which index we are dealing with:
65 int selfDefinedTypeIndex = QStringView(typeSubtypeString).right(typeSubtypeString.length() - 1).toInt() - 1;
66 return static_cast<KEduVocWordType *>(parent->childContainer(selfDefinedTypeIndex));
67 }
68
69 // assume the parent is set up to contain the old types correctly
70 QString mainType;
71 QString subType;
72 int i;
73
74 if ((i = typeSubtypeString.indexOf(KVTML_1_SEPERATOR)) >= 0) {
75 mainType = typeSubtypeString.left(i);
76 subType = typeSubtypeString.right(i + 1);
77 } else {
78 mainType = typeSubtypeString;
79 }
80
81 // convert from pre-0.5 versions (I guess we can just leave that in here.
82 // I seriously doubt that any such documents exist...
83 if (mainType == QLatin1Char('1')) {
84 mainType = QM_VERB;
85 } else if (mainType == QLatin1Char('2')) {
86 mainType = QM_NOUN;
87 } else if (mainType == QLatin1Char('3')) {
88 mainType = QM_NAME;
89 }
90
91 QString typeName = m_oldMainTypeNames.value(mainType);
92 if (typeName.isEmpty()) {
93 qDebug() << "Unknown old maintype: " << typeSubtypeString;
94 return nullptr;
95 }
96
97 QString subTypeName = m_oldSubTypeNames.value(subType);
98
99 foreach (KEduVocContainer *wordType, parent->childContainers()) {
100 if (wordType->name() == typeName) {
101 if (subType.isEmpty()) {
102 return static_cast<KEduVocWordType *>(wordType);
103 } else {
104 foreach (KEduVocContainer *subWordType, wordType->childContainers()) {
105 if (subWordType->name() == subTypeName) {
106 return static_cast<KEduVocWordType *>(subWordType);
107 }
108 }
109 }
110 }
111 }
112
113 return nullptr;
114}
115
116/*
117if ( type.length() >= 2 && type.left( 1 ) == QM_USER_TYPE ) {
118 // they started counting at 1, we need to know which index we are dealing with:
119 int selfDefinedTypeIndex = type.right( type.count()-1 ).toInt() -1;
120
121 // append invented types (do we not trust our own writer?)
122 if ( selfDefinedTypeIndex >= m_oldSelfDefinedTypes.count() ) {
123 while ( selfDefinedTypeIndex >= m_oldSelfDefinedTypes.count() ) {
124 m_oldSelfDefinedTypes.append( i18n( "User defined word type %1", m_oldSelfDefinedTypes.count() - 1 ) );
125 }
126 }
127 type = m_oldSelfDefinedTypes.value( selfDefinedTypeIndex );
128 } else {
129 type = m_compability.mainTypeFromOldFormat( oldType );
130 subType = m_compability.subTypeFromOldFormat( oldType );
131 } // not user defined - preset types
132
133
134if ( oldType.length() >= 2 && type.left( 1 ) == QM_USER_TYPE ) {
135 // they started counting at 1
136 int selfDefinedTypeIndex = oldType.right( type.count()-1 ).toInt() -1;
137 // append invented types (do we not trust our own writer?)
138 if ( selfDefinedTypeIndex >= m_oldSelfDefinedTypes.count() ) {
139 while ( selfDefinedTypeIndex >= m_oldSelfDefinedTypes.count() ) {
140 m_oldSelfDefinedTypes.append( i18n( "User defined word type %1", m_oldSelfDefinedTypes.count() - 1 ) );
141 }
142 }
143 type = m_oldSelfDefinedTypes.value( selfDefinedTypeIndex );
144 } else {
145 type = m_compability.mainTypeFromOldFormat( oldType );
146 subType = m_compability.subTypeFromOldFormat( oldType );
147 } // not user defined - preset types
148 }
149*/
150
151void KEduVocKvtmlCompability::initOldTenses()
152{
153 m_oldTenses[QStringLiteral("PrSi")] = i18n("Simple Present");
154 m_oldTenses[QStringLiteral("PrPr")] = i18n("Present Progressive");
155 m_oldTenses[QStringLiteral("PrPe")] = i18n("Present Perfect");
156 m_oldTenses[QStringLiteral("PaSi")] = i18n("Simple Past");
157 m_oldTenses[QStringLiteral("PaPr")] = i18n("Past Progressive");
158 m_oldTenses[QStringLiteral("PaPa")] = i18n("Past Participle");
159 m_oldTenses[QStringLiteral("FuSi")] = i18n("Future");
160}
161
162void KEduVocKvtmlCompability::addUserdefinedTense(const QString &tense)
163{
164 m_userdefinedTenseCounter++;
165 m_oldTenses[KVTML_1_USER_DEFINED + QString::number(m_userdefinedTenseCounter)] = tense;
166 m_tenses.insert(tense);
167
168 qDebug() << " Add tense: " << KVTML_1_USER_DEFINED + QString::number(m_userdefinedTenseCounter) << " - " << tense;
169}
170
171QString KEduVocKvtmlCompability::tenseFromKvtml1(const QString &oldTense)
172{
173 // in case the document got changed, at least make up something as tense
174 if (!m_oldTenses.keys().contains(oldTense)) {
175 m_oldTenses[oldTense] = oldTense;
176 qDebug() << "Warning, tense " << oldTense << " not found in document!";
177 }
178 m_tenses.insert(m_oldTenses.value(oldTense));
179 return m_oldTenses.value(oldTense);
180}
181
182QStringList KEduVocKvtmlCompability::documentTenses() const
183{
184 return m_tenses.values();
185}
186
187QString KEduVocKvtmlCompability::oldTense(const QString &tense)
188{
189 ///@todo writing of the user defined tenses is probably messed up
190 if (!m_oldTenses.values().contains(tense)) {
191 m_userdefinedTenseCounter++;
192 m_oldTenses[KVTML_1_USER_DEFINED + QString::number(m_userdefinedTenseCounter)] = tense;
193 }
194 return m_oldTenses.key(tense);
195}
196
197void KEduVocKvtmlCompability::setupWordTypes(KEduVocWordType *parent)
198{
199 QStringList wordTypeNames;
200 wordTypeNames << i18nc("The grammatical type of a word", "Verb") // 0
201 << i18nc("The grammatical type of a word", "Noun") // 1
202 << i18nc("The grammatical type of a word", "Name") << i18nc("The grammatical type of a word", "Article") // 3
203 << i18nc("The grammatical type of a word", "Adjective") // 4
204 << i18nc("The grammatical type of a word", "Adverb") // 5
205 << i18nc("The grammatical type of a word", "Pronoun") // 6
206 << i18nc("The grammatical type of an entry", "Phrase") << i18nc("The grammatical type of a word", "Numeral") // 8
207 << i18nc("The grammatical type of a word", "Conjunction") << i18nc("The grammatical type of a word", "Preposition")
208 << i18nc("The grammatical type of an entry", "Question");
209
210 foreach (const QString &typeName, wordTypeNames) {
211 KEduVocWordType *wordType = new KEduVocWordType(typeName, parent);
212 parent->appendChildContainer(wordType);
213 m_userdefinedTypeCounter++;
214 }
215 static_cast<KEduVocWordType *>(parent->childContainer(4))->setWordType(KEduVocWordFlag::Adjective);
216 static_cast<KEduVocWordType *>(parent->childContainer(5))->setWordType(KEduVocWordFlag::Adverb);
217
218 KEduVocWordType *numeral = static_cast<KEduVocWordType *>(parent->childContainer(8));
219 KEduVocWordType *wordType =
220 new KEduVocWordType(i18nc("@item:inlistbox A subtype of the grammatical word type: Numeral Ordinal (first, second, third, ...)", "Ordinal"), numeral);
221 wordType->setWordType(KEduVocWordFlag::Adjective);
222 numeral->appendChildContainer(wordType);
223 wordType =
224 new KEduVocWordType(i18nc("@item:inlistbox A subtype of the grammatical word type: Numeral Cardinal (one, two, three, ...)", "Cardinal"), numeral);
225
226 wordType->setWordType(KEduVocWordFlag::Adjective);
227 numeral->appendChildContainer(wordType);
228
229 KEduVocWordType *article = static_cast<KEduVocWordType *>(parent->childContainer(3));
230 wordType = new KEduVocWordType(i18nc("@item:inlistbox A subtype of the grammatical word type: Article (the)", "Definite"), article);
231 wordType->setWordType(KEduVocWordFlag::Article | KEduVocWordFlag::Definite);
232 article->appendChildContainer(wordType);
233 wordType = new KEduVocWordType(i18nc("@item:inlistbox A subtype of the grammatical word type: Article (a)", "Indefinite"), article);
234 wordType->setWordType(KEduVocWordFlag::Article | KEduVocWordFlag::Indefinite);
235 article->appendChildContainer(wordType);
236
237 KEduVocWordType *verb = static_cast<KEduVocWordType *>(parent->childContainer(0));
238 verb->setWordType(KEduVocWordFlag::Verb);
239 wordType = new KEduVocWordType(i18nc("@item:inlistbox A subtype of the grammatical word type: Verb with regular conjugation", "Regular"), verb);
240 wordType->setWordType(KEduVocWordFlag::Verb | KEduVocWordFlag::Regular);
241 verb->appendChildContainer(wordType);
242 wordType = new KEduVocWordType(i18nc("@item:inlistbox A subtype of the grammatical word type: Verb with irregular conjugation", "Irregular"), verb);
243 verb->appendChildContainer(wordType);
244 wordType->setWordType(KEduVocWordFlag::Verb | KEduVocWordFlag::Irregular);
245
246 KEduVocWordType *noun = static_cast<KEduVocWordType *>(parent->childContainer(1));
247 noun->setWordType(KEduVocWordFlag::Noun);
248 wordType = new KEduVocWordType(i18nc("@item:inlistbox A subtype of the grammatical word type: Noun", "Male"), noun);
249 noun->appendChildContainer(wordType);
250 wordType->setWordType(KEduVocWordFlag::Noun | KEduVocWordFlag::Masculine);
251 wordType = new KEduVocWordType(i18nc("@item:inlistbox A subtype of the grammatical word type: Noun", "Female"), noun);
252 noun->appendChildContainer(wordType);
253 wordType->setWordType(KEduVocWordFlag::Noun | KEduVocWordFlag::Feminine);
254 wordType = new KEduVocWordType(i18nc("@item:inlistbox A subtype of the grammatical word type: Noun", "Neutral"), noun);
255 noun->appendChildContainer(wordType);
256 wordType->setWordType(KEduVocWordFlag::Noun | KEduVocWordFlag::Neuter);
257
258 KEduVocWordType *pronoun = static_cast<KEduVocWordType *>(parent->childContainer(6));
259 wordType = new KEduVocWordType(i18nc("@item:inlistbox A subtype of the grammatical word type: Pronoun (my, your, his, her...)", "Possessive"), pronoun);
260 wordType->setWordType(KEduVocWordFlag::Pronoun);
261 pronoun->appendChildContainer(wordType);
262 wordType = new KEduVocWordType(i18nc("@item:inlistbox A subtype of the grammatical word type: Pronoun (I, you, he...)", "Personal"), pronoun);
263 wordType->setWordType(KEduVocWordFlag::Pronoun);
264 pronoun->appendChildContainer(wordType);
265}
class to store information about a container - that can be a lesson or word types
QString name()
get the container name
class to store translation word types
void setWordType(KEduVocWordFlags flags)
assignment operator
contains defines and constants necessary for reading kvtml files prior to KDE4.
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
KOSM_EXPORT const char * typeName(Type type)
bool contains(const AT &value) const const
void clear()
iterator insert(const Key &key, const T &value)
Key key(const T &value, const Key &defaultKey) const const
QList< Key > keys() const const
T value(const Key &key, const T &defaultValue) const const
QList< T > values() const const
iterator insert(const T &value)
QList< T > values() const const
qsizetype indexOf(QChar ch, qsizetype from, Qt::CaseSensitivity cs) const const
bool isEmpty() const const
QString left(qsizetype n) const const
qsizetype length() const const
QString number(double n, char format, int precision)
QString right(qsizetype n) const const
QStringView right(qsizetype length) const const
int toInt(bool *ok, int base) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 17 2024 11:55:29 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.