/***************************************************************************
- read a KEduVocDocument from a KVTML file
+* this file is from kdeedu project. Filename: keduvockvtmlreader.cpp
+***************************************************************************/
+
+/***************************************************************************
+ read a QmVocDocument from a KVTML file
-----------------------------------------------------------------------
copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de>
(C) 2005 Eric Pignet <eric at erixpage.com>
(C) 2007 Peter Hedlund <peter.hedlund@kdemail.net>
(C) 2007 Frederik Gladhorn <frederik.gladhorn@kdemail.net>
+ (C) 2010, 2012 Reto Zingg <g.d0b3rm4n@gmail.com>
***************************************************************************/
/***************************************************************************
* *
***************************************************************************/
-#include "keduvockvtmlreader.h"
+#include "qmvockvtmlreader.h"
#include <QtCore/QTextStream>
#include <QtCore/QList>
#include <QtCore/QIODevice>
-#include <kdebug.h>
-#include <klocale.h>
-#include <kglobal.h>
+// #include <kdebug.h>
+#include <QDebug>
+// #include <klocale.h>
+// #include <kglobal.h>
-#include "keduvocdocument.h"
-#include "keduvoclesson.h"
-#include "keduvocwordtype.h"
+#include "qmvocdocument.h"
+#include "qmvoclesson.h"
+#include "qmvocwordtype.h"
#include "kvtmldefs.h"
-#include "keduvoccommon_p.h"
+#include "qmvoccommon_p.h"
-KEduVocKvtmlReader::KEduVocKvtmlReader( QIODevice *file )
+QmVocKvtmlReader::QmVocKvtmlReader( QIODevice *file )
{
// the file must be already open
m_inputFile = file;
m_errorMessage = "";
- kDebug() << "KEduVocKvtmlReader for kvtml version 1 files started.";
+ qDebug() << "QmVocKvtmlReader for kvtml version 1 files started.";
}
-bool KEduVocKvtmlReader::readDoc( KEduVocDocument *doc )
+bool QmVocKvtmlReader::readDoc( QmVocDocument *doc )
{
m_doc = doc;
m_cols = 0;
m_lines = 0;
- QDomDocument domDoc( "KEduVocDocument" );
+ QDomDocument domDoc( "QmVocDocument" );
if ( !domDoc.setContent( m_inputFile, &m_errorMessage ) )
return false;
QDomElement domElementKvtml = domDoc.documentElement();
if ( domElementKvtml.tagName() != KV_DOCTYPE ) {
- m_errorMessage = i18n( "This is not a KDE Vocabulary document." );
+ m_errorMessage = "This is not a KDE Vocabulary document." ;
return false;
}
}
-bool KEduVocKvtmlReader::readBody( QDomElement &domElementParent )
+bool QmVocKvtmlReader::readBody( QDomElement &domElementParent )
{
bool result = false;
return false;
}
- KEduVocPersonalPronoun pronouns;
+ QmVocPersonalPronoun pronouns;
if (! readPersonalPronouns( domElementConjugChild, pronouns ) ) {
return false;
}
}
-bool KEduVocKvtmlReader::readLesson( QDomElement &domElementParent )
+bool QmVocKvtmlReader::readLesson( QDomElement &domElementParent )
{
QString s;
QDomAttr attribute;
}
s = currentElement.text();
- KEduVocLesson* lesson = new KEduVocLesson(s, m_doc->lesson());
+ QmVocLesson* lesson = new QmVocLesson(s, m_doc->lesson());
lesson->setInPractice(inQuery);
m_doc->lesson()->appendChildContainer( lesson );
if ( m_doc->lesson()->childContainerCount() != no-1 ) {
- kDebug() << "Warning! Lesson order may be confused. Are all lessons in order in the file?";
+ qDebug() << "Warning! Lesson order may be confused. Are all lessons in order in the file?";
}
}
}
}
-bool KEduVocKvtmlReader::readArticle( QDomElement &domElementParent )
+bool QmVocKvtmlReader::readArticle( QDomElement &domElementParent )
/*
<article>
<e l="de"> lang determines also lang order in entries !!
for ( int i = 0; i < entryList.count(); ++i ) {
-//kDebug() << "KEduVocKvtmlReader::readArticle() read " << entryList.count() << " articles. ";
+//kDebug() << "QmVocKvtmlReader::readArticle() read " << entryList.count() << " articles. ";
currentElement = entryList.item( i ).toElement();
if ( currentElement.parentNode() == domElementParent ) {
QString lang;
nat_indef = "";
}
- m_doc->identifier(i).setArticle( KEduVocArticle( fem_def, fem_indef, mal_def, mal_indef, nat_def, nat_indef ) );
+ m_doc->identifier(i).setArticle( QmVocArticle( fem_def, fem_indef, mal_def, mal_indef, nat_def, nat_indef ) );
}
}
}
-bool KEduVocKvtmlReader::readTranslationConjugations( QDomElement &domElementParent, KEduVocTranslation* translation )
+bool QmVocKvtmlReader::readTranslationConjugations( QDomElement &domElementParent, QmVocTranslation* translation )
{
QString tense;
QString oldShortTense = domAttrLang.value();
tense = m_compability.tenseFromKvtml1( oldShortTense );
- KEduVocConjugation conjugation;
+ QmVocConjugation conjugation;
readConjugation(domElementConjugChild, conjugation);
translation->setConjugation(tense, conjugation);
return true;
}
-bool KEduVocKvtmlReader::readConjugation( QDomElement &domElementParent, KEduVocConjugation& conjugation )
+bool QmVocKvtmlReader::readConjugation( QDomElement &domElementParent, QmVocConjugation& conjugation )
/*
<conjugation> used in header for definiton of "prefix"
<e l="de"> lang determines also lang order in entries !!
// type - the tense?
// finally the person
- const KEduVocWordFlags numS = KEduVocWordFlag::Singular;
- const KEduVocWordFlags numP = KEduVocWordFlag::Plural;
+ const QmVocWordFlags numS = QmVocWordFlag::Singular;
+ const QmVocWordFlags numP = QmVocWordFlag::Plural;
- conjugation.setConjugation( pers1_sing, KEduVocWordFlag::First | numS);
- conjugation.setConjugation( pers2_sing, KEduVocWordFlag::Second | numS);
- conjugation.setConjugation( pers1_plur, KEduVocWordFlag::First | numP);
- conjugation.setConjugation( pers2_plur, KEduVocWordFlag::Second | numP);
+ conjugation.setConjugation( pers1_sing, QmVocWordFlag::First | numS);
+ conjugation.setConjugation( pers2_sing, QmVocWordFlag::Second | numS);
+ conjugation.setConjugation( pers1_plur, QmVocWordFlag::First | numP);
+ conjugation.setConjugation( pers2_plur, QmVocWordFlag::Second | numP);
if ( s3_common ) {
- conjugation.setConjugation( pers3_f_sing, KEduVocWordFlag::Third | KEduVocWordFlag::Neuter | KEduVocWordFlag::Singular );
+ conjugation.setConjugation( pers3_f_sing, QmVocWordFlag::Third | QmVocWordFlag::Neuter | QmVocWordFlag::Singular );
} else {
conjugation.setConjugation( pers3_m_sing,
- KEduVocWordFlag::Third | KEduVocWordFlag::Masculine | KEduVocWordFlag::Singular );
+ QmVocWordFlag::Third | QmVocWordFlag::Masculine | QmVocWordFlag::Singular );
conjugation.setConjugation( pers3_f_sing,
- KEduVocWordFlag::Third | KEduVocWordFlag::Feminine | KEduVocWordFlag::Singular );
+ QmVocWordFlag::Third | QmVocWordFlag::Feminine | QmVocWordFlag::Singular );
conjugation.setConjugation( pers3_n_sing,
- KEduVocWordFlag::Third | KEduVocWordFlag::Neuter | KEduVocWordFlag::Singular );
+ QmVocWordFlag::Third | QmVocWordFlag::Neuter | QmVocWordFlag::Singular );
}
if ( p3_common ) {
- conjugation.setConjugation( pers3_f_plur, KEduVocWordFlag::Third | KEduVocWordFlag::Neuter | KEduVocWordFlag::Plural );
+ conjugation.setConjugation( pers3_f_plur, QmVocWordFlag::Third | QmVocWordFlag::Neuter | QmVocWordFlag::Plural );
} else {
conjugation.setConjugation( pers3_m_plur,
- KEduVocWordFlag::Third | KEduVocWordFlag::Masculine | KEduVocWordFlag::Plural );
+ QmVocWordFlag::Third | QmVocWordFlag::Masculine | QmVocWordFlag::Plural );
conjugation.setConjugation( pers3_f_plur,
- KEduVocWordFlag::Third | KEduVocWordFlag::Feminine | KEduVocWordFlag::Plural );
+ QmVocWordFlag::Third | QmVocWordFlag::Feminine | QmVocWordFlag::Plural );
conjugation.setConjugation( pers3_n_plur,
- KEduVocWordFlag::Third | KEduVocWordFlag::Neuter | KEduVocWordFlag::Plural );
+ QmVocWordFlag::Third | QmVocWordFlag::Neuter | QmVocWordFlag::Plural );
}
return true;
-bool KEduVocKvtmlReader::readPersonalPronouns( QDomElement &domElementParent, KEduVocPersonalPronoun& pronouns )
+bool QmVocKvtmlReader::readPersonalPronouns( QDomElement &domElementParent, QmVocPersonalPronoun& pronouns )
{
// QString s;
bool p3_common;
// type - the tense?
// finally the person
- KEduVocWordFlags numS = KEduVocWordFlag::Singular;
+ QmVocWordFlags numS = QmVocWordFlag::Singular;
pronouns.setMaleFemaleDifferent(false);
- pronouns.setPersonalPronoun( pers1_sing, KEduVocWordFlag::First | numS );
- pronouns.setPersonalPronoun( pers2_sing, KEduVocWordFlag::Second | numS );
+ pronouns.setPersonalPronoun( pers1_sing, QmVocWordFlag::First | numS );
+ pronouns.setPersonalPronoun( pers2_sing, QmVocWordFlag::Second | numS );
// used to have common in female
if ( s3_common ) {
- pronouns.setPersonalPronoun( pers3_f_sing, KEduVocWordFlag::Third | KEduVocWordFlag::Neuter | numS );
+ pronouns.setPersonalPronoun( pers3_f_sing, QmVocWordFlag::Third | QmVocWordFlag::Neuter | numS );
} else {
pronouns.setPersonalPronoun( pers3_m_sing,
- KEduVocWordFlag::Third | KEduVocWordFlag::Masculine | numS );
+ QmVocWordFlag::Third | QmVocWordFlag::Masculine | numS );
pronouns.setPersonalPronoun( pers3_f_sing,
- KEduVocWordFlag::Third | KEduVocWordFlag::Feminine | numS );
+ QmVocWordFlag::Third | QmVocWordFlag::Feminine | numS );
pronouns.setPersonalPronoun( pers3_n_sing,
- KEduVocWordFlag::Third | KEduVocWordFlag::Neuter | numS );
+ QmVocWordFlag::Third | QmVocWordFlag::Neuter | numS );
pronouns.setMaleFemaleDifferent(true);
}
- KEduVocWordFlags numP = KEduVocWordFlag::Plural;
+ QmVocWordFlags numP = QmVocWordFlag::Plural;
- pronouns.setPersonalPronoun( pers1_plur, KEduVocWordFlag::First | numP );
- pronouns.setPersonalPronoun( pers2_plur, KEduVocWordFlag::Second | numP );
+ pronouns.setPersonalPronoun( pers1_plur, QmVocWordFlag::First | numP );
+ pronouns.setPersonalPronoun( pers2_plur, QmVocWordFlag::Second | numP );
if ( p3_common ) {
- pronouns.setPersonalPronoun( pers3_f_plur, KEduVocWordFlag::Third | KEduVocWordFlag::Neuter | numP );
+ pronouns.setPersonalPronoun( pers3_f_plur, QmVocWordFlag::Third | QmVocWordFlag::Neuter | numP );
} else {
pronouns.setPersonalPronoun( pers3_m_plur,
- KEduVocWordFlag::Third | KEduVocWordFlag::Masculine | numP );
+ QmVocWordFlag::Third | QmVocWordFlag::Masculine | numP );
pronouns.setPersonalPronoun( pers3_f_plur,
- KEduVocWordFlag::Third | KEduVocWordFlag::Feminine | numP );
+ QmVocWordFlag::Third | QmVocWordFlag::Feminine | numP );
pronouns.setPersonalPronoun( pers3_n_plur,
- KEduVocWordFlag::Third | KEduVocWordFlag::Neuter | numP );
+ QmVocWordFlag::Third | QmVocWordFlag::Neuter | numP );
pronouns.setMaleFemaleDifferent(true);
}
}
-bool KEduVocKvtmlReader::readType( QDomElement &domElementParent )
+bool QmVocKvtmlReader::readType( QDomElement &domElementParent )
{
QString s;
QDomElement currentElement;
// We need to even add empty elements since the old system relied on
// the order. So "type1" "" "type2" should be just like that.
- kDebug() << "Adding old self defined type: " << currentElement.text();
+ qDebug() << "Adding old self defined type: " << currentElement.text();
// add the type to the list of available types
- KEduVocWordType* type = new KEduVocWordType(currentElement.text(), m_doc->wordTypeContainer());
+ QmVocWordType* type = new QmVocWordType(currentElement.text(), m_doc->wordTypeContainer());
m_doc->wordTypeContainer()->appendChildContainer( type );
// from this the #1 are transformed to something sensible again
}
-bool KEduVocKvtmlReader::readTense( QDomElement &domElementParent )
+bool QmVocKvtmlReader::readTense( QDomElement &domElementParent )
{
QDomElement currentElement;
currentElement = domElementParent.firstChildElement( KV_TENSE_DESC );
while ( !currentElement.isNull() ) {
- kDebug() << "Reading user defined tense description: " << currentElement.text();
+ qDebug() << "Reading user defined tense description: " << currentElement.text();
m_compability.addUserdefinedTense( currentElement.text() );
currentElement = currentElement.nextSiblingElement( KV_TENSE_DESC );
}
}
-bool KEduVocKvtmlReader::readComparison( QDomElement &domElementParent, KEduVocTranslation * translation )
+bool QmVocKvtmlReader::readComparison( QDomElement &domElementParent, QmVocTranslation * translation )
/*
<comparison>
<l1>good</l1> --- this one is dead as it always has to be the word itself
}
-bool KEduVocKvtmlReader::readMultipleChoice( QDomElement &domElementParent, KEduVocTranslation* translation )
+bool QmVocKvtmlReader::readMultipleChoice( QDomElement &domElementParent, QmVocTranslation* translation )
/*
<multiplechoice>
<mc1>good</mc1>
}
-bool KEduVocKvtmlReader::readExpressionChildAttributes( QDomElement &domElementExpressionChild,
+bool QmVocKvtmlReader::readExpressionChildAttributes( QDomElement &domElementExpressionChild,
QString &lang,
grade_t &grade, grade_t &rev_grade,
int &count, int &rev_count,
}
-bool KEduVocKvtmlReader::readExpression( QDomElement &domElementParent )
+bool QmVocKvtmlReader::readExpression( QDomElement &domElementParent )
{
grade_t grade;
grade_t r_grade;
///@todo can this happen? does it need a while loop?
// it's from a lesson that hasn't been added yet
// so make sure this lesson is in the document
- kDebug() << "Warning: lesson > m_doc->lessonCount() in readExpression.";
+ qDebug() << "Warning: lesson > m_doc->lessonCount() in readExpression.";
- KEduVocLesson* lesson = new KEduVocLesson(i18nc("A generic name for a new lesson and its number.", "Lesson %1", lessonNumber ), m_doc->lesson());
+ QmVocLesson* lesson = new QmVocLesson( QString("Lesson %1").arg(lessonNumber) , m_doc->lesson());
m_doc->lesson()->appendChildContainer(lesson);
}
}
// kvtml 1: we always have an original element (required)
currentElement = domElementParent.firstChildElement( KV_ORG );
if ( currentElement.isNull() ) { // sanity check
- m_errorMessage = i18n( "Data for original language missing" );
+ m_errorMessage = "Data for original language missing" ;
return false;
}
- KEduVocExpression* entry = 0;
+ QmVocExpression* entry = 0;
while ( !currentElement.isNull() ) {
textstr = currentElement.lastChild().toText().data();
if ( i == 0 ) {
- entry = new KEduVocExpression( textstr );
+ entry = new QmVocExpression( textstr );
entry->setActive( active );
if ( lessonNumber != -1 ) {
- static_cast<KEduVocLesson*>(m_doc->lesson()->childContainer(lessonNumber))->appendEntry(entry);
+ static_cast<QmVocLesson*>(m_doc->lesson()->childContainer(lessonNumber))->appendEntry(entry);
} else {
m_doc->lesson()->appendEntry(entry);
}
entry->setTranslation( i, textstr );
}
- if ( m_doc->lesson()->entries(KEduVocLesson::Recursive).count() == 1 ) { // this is because in kvtml the languages are saved in the FIRST ENTRY ONLY.
+ if ( m_doc->lesson()->entries(QmVocLesson::Recursive).count() == 1 ) { // this is because in kvtml the languages are saved in the FIRST ENTRY ONLY.
// new translation
if (!addLanguage(i, lang)) {
return false;
}
if ( !type.isEmpty() ) {
- KEduVocWordType* wordType = m_compability.typeFromOldFormat(m_doc->wordTypeContainer(), type);
+ QmVocWordType* wordType = m_compability.typeFromOldFormat(m_doc->wordTypeContainer(), type);
entry->translation(i)->setWordType(wordType);
}
}
-bool KEduVocKvtmlReader::addLanguage( int languageId, const QString& locale)
+bool QmVocKvtmlReader::addLanguage( int languageId, const QString& locale)
{
if ( m_doc->identifierCount() <= languageId ) {
m_doc->appendIdentifier();
m_doc->identifier(languageId).setLocale(locale);
QString languageName;
- if (KGlobal::locale()) {
- // when using from qt-only apps this would crash (converter)
- languageName = KGlobal::locale()->languageCodeToName(locale);
- }
+// if (KGlobal::locale()) {
+// // when using from qt-only apps this would crash (converter)
+// languageName = KGlobal::locale()->languageCodeToName(locale);
+// }
if ( languageName.isEmpty() ) {
languageName = locale;
}
m_doc->identifier(languageId).setName(languageName);
- kDebug() << "addLanguage( " << languageId << ", " << locale << "): " << languageName;
+ qDebug() << "addLanguage( " << languageId << ", " << locale << "): " << languageName;
}
} else {
if ( !locale.isEmpty() ) {
if ( locale != m_doc->identifier(languageId).locale() ) {
// different originals ?
- m_errorMessage = i18n( "Ambiguous definition of language code" );
+ m_errorMessage = "Ambiguous definition of language code" ;
return false;
}
}
}
-#include "keduvockvtmlreader.moc"