New class: KEduVocCompablility to contain all constants needed for the above conversions.
The type and conjugation stuff should also move there, to finall clean up with all scattered defines.
svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=705745
keduvockvtml2reader.cpp
keduvockvtmlwriter.cpp
keduvockvtml2writer.cpp
+ keduvockvtmlcompability.cpp
keduvocmultiplechoice.cpp
keduvocpaukerreader.cpp
keduvocvokabelnreader.cpp
--- /dev/null
+/***************************************************************************
+
+ C++ Implementation: keduvockvtml1compability_p
+
+ -----------------------------------------------------------------------
+
+ begin : Di Aug 28 2007
+
+ copyright : (C) 2007 Frederik Gladhorn <frederik.gladhorn@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 "keduvockvtmlcompability.h"
+
+const QString KEduVocKvtmlCompability::USAGE_USER_DEFINED = QString("#");
+const QString KEduVocKvtmlCompability::USAGE_SEPERATOR = QString(":");
+
+
+KEduVocKvtmlCompability::KEduVocKvtmlCompability()
+{
+ m_usages = usageMap();
+ m_userdefinedUsageCounter = 0;
+}
+
+
+QSet<QString> KEduVocKvtmlCompability::usageFromKvtml1(const QString & oldUsage) const
+{
+ QSet<QString> usages;
+ foreach ( QString usage , oldUsage.split(USAGE_SEPERATOR, QString::SkipEmptyParts) ) {
+ usages.insert( m_usages[usage] );
+ }
+ return usages;
+}
+
+
+QMap< QString, QString > KEduVocKvtmlCompability::usageMap()
+{
+ QMap< QString, QString > usages;
+
+ usages["Am" ] = i18n("Americanism");
+ usages["abbr" ] = i18n("abbreviation");
+ usages["anat" ] = i18n("anatomy");
+ usages["astr" ] = i18n("astronomy");
+ usages["biol" ] = i18n("biology");
+ usages["bs" ] = i18n("bad sense");
+ usages["contp" ] = i18n("contemptuously");
+ usages["eccl" ] = i18n("ecclesiastical");
+ usages["fig" ] = i18n("figuratively");
+ usages["geol" ] = i18n("geology");
+ usages["hist" ] = i18n("historical");
+ usages["icht" ] = i18n("ichthyology");
+ usages["ifm" ] = i18n("informal");
+ usages["iro" ] = i18n("ironic");
+ usages["irr" ] = i18n("irregular");
+ usages["lit" ] = i18n("literary");
+ usages["metal" ] = i18n("metallurgy");
+ usages["meteo" ] = i18n("meteorology");
+ usages["miner" ] = i18n("mineralogy");
+ usages["mot" ] = i18n("motoring");
+ usages["mount" ] = i18n("mountaineering");
+ usages["myth" ] = i18n("mythology");
+ usages["npr" ] = i18n("proper name");
+ usages["opt" ] = i18n("optics");
+ usages["orn" ] = i18n("ornithology");
+ usages["os" ] = i18n("oneself");
+ usages["p" ] = i18n("person");
+ usages["parl" ] = i18n("parliamentary");
+ usages["pharm" ] = i18n("pharmacy");
+ usages["phls" ] = i18n("philosophy");
+ usages["phot" ] = i18n("photography");
+ usages["phys" ] = i18n("physics");
+ usages["physio"] = i18n("physiology");
+ usages["pl" ] = i18n("plural");
+ usages["poet" ] = i18n("poetry");
+ usages["pol" ] = i18n("politics");
+ usages["prov" ] = i18n("provincialism");
+ usages["psych" ] = i18n("psychology");
+ usages["rhet" ] = i18n("rhetoric");
+ usages["surv" ] = i18n("surveying");
+ usages["telg" ] = i18n("telegraphy");
+ usages["telph" ] = i18n("telephony");
+ usages["thea" ] = i18n("theater");
+ usages["typo" ] = i18n("typography");
+ usages["univ" ] = i18n("university");
+ usages["vet" ] = i18n("veterinary medicine");
+ usages["zoo" ] = i18n("zoology");
+
+ return usages;
+}
+
+void KEduVocKvtmlCompability::addUserdefinedUsage(const QString & usage)
+{
+ // start counting at 1 !!!
+ m_userdefinedUsageCounter++;
+ m_usages[USAGE_USER_DEFINED + QString::number(m_userdefinedUsageCounter)] = usage;
+}
+
+QSet< QString > KEduVocKvtmlCompability::documentUsages() const
+{
+ return QSet<QString>::fromList(m_usages.values());
+}
+
+
--- /dev/null
+/***************************************************************************
+
+ C++ Interface: keduvockvtml1compability_p
+
+ -----------------------------------------------------------------------
+
+ begin : Di Aug 28 2007
+
+ copyright : (C) 2007 Frederik Gladhorn <frederik.gladhorn@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. *
+ * *
+ ***************************************************************************/
+
+#ifndef KEDUVOCKVTML1COMPABILITY_P_H
+#define KEDUVOCKVTML1COMPABILITY_P_H
+
+#include <QtCore/QString>
+#include <QtCore/QMap>
+#include <QtCore/QSet>
+
+#include <KLocalizedString>
+
+/**
+ * @file contains defines and constants necessary for reading kvtml files prior to KDE4. kvtml version 1.
+ */
+class KEduVocKvtmlCompability {
+
+public:
+ /**
+ * Constructor, initialize the map.
+ */
+ KEduVocKvtmlCompability();
+
+ /**
+ * In old kvtml documents usages could be added. When parsing the doc,
+ * we need those too. They map "#1" to something meaningful.
+ * Add them in order!
+ * @param usage the old user defined usage.
+ */
+ void addUserdefinedUsage( const QString& usage );
+
+ /**
+ * This "translates" the old usage string found in the files to the
+ * real word/meaning. It will also consider the user defined usages.
+ * Use this method for usages.
+ * @param oldUsage string e.g. "biol:anat:#1"
+ * @return full set e.g. {"biology", "anatomy", "user defined 1"}
+ */
+ QSet<QString> usageFromKvtml1( const QString& oldUsage ) const;
+
+ QSet<QString> documentUsages() const;
+
+private:
+ /**
+ * This gives a map of old abbreviations used in the files and their meaning.
+ * [biol] == biology and so on...
+ * @return the map
+ */
+ static QMap< QString, QString > usageMap();
+
+ /// Map to store usages. Initialized with preset values by the constructor. Later user defined usages can be added.
+ QMap< QString, QString > m_usages;
+
+ /// # defines user defined usage
+ static const QString USAGE_USER_DEFINED;
+ /// : seperates usages
+ static const QString USAGE_SEPERATOR;
+
+ /// only order was decisive, we have to keep count.
+ int m_userdefinedUsageCounter;
+};
+
+
+
+#endif // KEDUVOCKVTML1COMPABILITY_P_H
bool KEduVocKvtmlReader::readUsage(QDomElement &domElementParent)
{
- QString s;
+ // get user defined usages
+
QDomElement currentElement;
- QStringList descriptions;
QDomNodeList entryList = domElementParent.elementsByTagName(KV_USAGE_DESC);
- if (entryList.length() <= 0)
+ if (entryList.length() <= 0) {
return false;
+ }
for (int i = 0; i < entryList.count(); ++i) {
currentElement = entryList.item(i).toElement();
if (currentElement.parentNode() == domElementParent) {
- int no = 0;
-
- QDomAttr attribute = currentElement.attributeNode(KV_USAGE_NO);
- if (!attribute.isNull())
- no = attribute.value().toInt();
-
- s = currentElement.text();
- if (s.isNull())
- s = "";
- m_doc->addUsage(s);
+ m_compability.addUserdefinedUsage(currentElement.text());
}
}
+ foreach ( QString usage, m_compability.documentUsages() ) {
+ m_doc->addUsage(usage);
+ }
+
return true;
}
QString &synonym,
QString &example,
QString &antonym,
- QString &usage,
+ QSet<QString> &usages,
QString ¶phrase)
{
int pos;
example = attribute.value();
///@todo usages
-/*
- usage = "";
+
attribute = domElementExpressionChild.attributeNode(KV_USAGE);
if (!attribute.isNull())
{
+ kDebug() << "Read usages: " << attribute.value();
+ usages = m_compability.usageFromKvtml1(attribute.value());
+
+ /*
usage = attribute.value();
+
if (usage.length() != 0 && usage.left(1) == UL_USER_USAGE)
{
int num = qMin(usage.mid (1, 40).toInt(), 1000); // paranioa check
}
m_doc->setUsageDescriptions(sl);
}
- }
- }*/
+ }*/
+ }
paraphrase = "";
attribute = domElementExpressionChild.attributeNode(KV_PARAPHRASE);
QString synonym;
QString example;
QString antonym;
- QString usage;
+ QSet<QString> usage;
QString paraphrase;
QList<KEduVocConjugation> conjug;
KEduVocComparison comparison;
expr.translation(i).setSynonym (synonym);
if (!example.isEmpty() )
expr.translation(i).setExample (example);
-///@todo enable reading of usages into a qstringlist
-/*
if (!usage.isEmpty() )
- expr.translation(i).setUsageLabel (usage);
-*/
+ expr.translation(i).setUsages (usage);
if (!paraphrase.isEmpty() )
expr.translation(i).setParaphrase (paraphrase);
if (!antonym.isEmpty() )
#include "keduvocgrade.h"
#include "keduvocgrammar.h"
#include "keduvocmultiplechoice.h"
+#include "keduvockvtmlcompability.h"
class QIODevice;
class KEduVocDocument;
QString &synonym,
QString &example,
QString &antonym,
- QString &usage,
+ QSet<QString> &usage,
QString ¶phrase);
bool readExpression(QDomElement &domElementParent);
bool readBody(QDomElement &domElementParent);
int m_cols;
int m_lines;
QStringList m_oldSelfDefinedTypes;
+
+ KEduVocKvtmlCompability m_compability;
};
#endif