From 7c7b5d3bdda9db6f41a2c3ff56b78b3b05733fed Mon Sep 17 00:00:00 2001 From: Reto Zingg Date: Sat, 15 Dec 2012 19:28:48 +0200 Subject: [PATCH] adapt qmvockvtml2reader.cpp for querymee --- qmvockvtml2reader.cpp | 191 ++++++++++++++++++++++-------------------- 1 file changed, 101 insertions(+), 90 deletions(-) diff --git a/qmvockvtml2reader.cpp b/qmvockvtml2reader.cpp index 6fd6758..b61369e 100644 --- a/qmvockvtml2reader.cpp +++ b/qmvockvtml2reader.cpp @@ -1,11 +1,17 @@ /*************************************************************************** - read a KEduVocDocument from a KVTML file +* this file is from kdeedu project. Filename: keduvockvtml2reader.cpp +***************************************************************************/ + +/*************************************************************************** + read a QmVocDocument from a KVTML file ----------------------------------------------------------------------- copyright : (C) 1999-2001 Ewald Arnold (C) 2005 Eric Pignet (C) 2007 Peter Hedlund Copyright 2007-2010 Frederik Gladhorn + Copyright 2010, 2012 Reto Zingg + ***************************************************************************/ /*************************************************************************** @@ -17,46 +23,50 @@ * * ***************************************************************************/ -#include "keduvockvtml2reader.h" +#include "qmvockvtml2reader.h" #include #include -#include +// #include +#include +#include -#include +// #include -#include "keduvocdocument.h" -#include "keduvoclesson.h" -#include "keduvocleitnerbox.h" -#include "keduvocwordtype.h" +#include "qmvocdocument.h" +#include "qmvoclesson.h" +#include "qmvocleitnerbox.h" +#include "qmvocwordtype.h" #include "kvtml2defs.h" -#include "keduvockvtmlreader.h" -#include "keduvoccommon_p.h" +#include "qmvockvtmlreader.h" +#include "qmvoccommon_p.h" -#include +// #include -KEduVocKvtml2Reader::KEduVocKvtml2Reader( QIODevice *file ) +QmVocKvtml2Reader::QmVocKvtml2Reader( QFile *file ) : m_inputFile( file ) { // the file must be already open if ( !m_inputFile->isOpen() ) { - m_errorMessage = i18n( "file must be opened first" ); + m_errorMessage = "file must be opened first" ; } + qDebug("QmVocKvtml2Reader constructor"); } -bool KEduVocKvtml2Reader::readDoc( KEduVocDocument *doc ) +bool QmVocKvtml2Reader::readDoc( QmVocDocument *doc ) { + qDebug("QmVocKvtml2Reader::readDoc"); m_doc = doc; - QDomDocument domDoc( "KEduVocDocument" ); + QDomDocument domDoc( "QmVocDocument" ); if ( !domDoc.setContent( m_inputFile, &m_errorMessage ) ) return false; QDomElement domElementKvtml = domDoc.documentElement(); if ( domElementKvtml.tagName() != KVTML_TAG ) { - m_errorMessage = i18n( "This is not a KDE Vocabulary document." ); + m_errorMessage = "This is not a KDE Vocabulary document." ; return false; } @@ -65,7 +75,7 @@ bool KEduVocKvtml2Reader::readDoc( KEduVocDocument *doc ) // first reset the file to the beginning m_inputFile->seek( 0 ); - KEduVocKvtmlReader oldFormat( m_inputFile ); + QmVocKvtmlReader oldFormat( m_inputFile ); // get the return value bool retval = oldFormat.readDoc( doc ); @@ -90,7 +100,7 @@ bool KEduVocKvtml2Reader::readDoc( KEduVocDocument *doc ) return result; } -bool KEduVocKvtml2Reader::readInformation( QDomElement &informationElement ) +bool QmVocKvtml2Reader::readInformation( QDomElement &informationElement ) { // read the generator QDomElement currentElement = informationElement.firstChildElement( KVTML_GENERATOR ); @@ -141,7 +151,7 @@ bool KEduVocKvtml2Reader::readInformation( QDomElement &informationElement ) return true; } -bool KEduVocKvtml2Reader::readGroups( QDomElement &domElementParent ) +bool QmVocKvtml2Reader::readGroups( QDomElement &domElementParent ) { bool result = false; @@ -161,7 +171,7 @@ bool KEduVocKvtml2Reader::readGroups( QDomElement &domElementParent ) if ( !groupElement.isNull() ) { QDomNodeList entryList = groupElement.elementsByTagName( KVTML_IDENTIFIER ); if ( entryList.length() <= 0 ) { - m_errorMessage = i18n( "missing identifier elements from identifiers tag" ); + m_errorMessage = "missing identifier elements from identifiers tag" ; return false; } @@ -210,10 +220,10 @@ bool KEduVocKvtml2Reader::readGroups( QDomElement &domElementParent ) } // Additional cleanup: Put orphaned entries without a lesson into a default lesson. - KEduVocLesson *defaultLesson = new KEduVocLesson(i18n("Default Lesson"), m_doc->lesson()); + QmVocLesson *defaultLesson = new QmVocLesson("Default Lesson", m_doc->lesson()); // now make sure we don't have any orphan entries - foreach (KEduVocExpression * entry, m_allEntries) { + foreach (QmVocExpression * entry, m_allEntries) { if (!entry->lesson()) { defaultLesson->appendEntry(entry); @@ -231,18 +241,18 @@ bool KEduVocKvtml2Reader::readGroups( QDomElement &domElementParent ) } -bool KEduVocKvtml2Reader::readIdentifier( QDomElement &identifierElement ) +bool QmVocKvtml2Reader::readIdentifier( QDomElement &identifierElement ) { bool result = true; int id = identifierElement.attribute( KVTML_ID ).toInt( &result ); if ( !result ) { - m_errorMessage = i18n( "identifier missing id" ); + m_errorMessage = "identifier missing id" ; return false; } // generate empty identifiers in the doc for ( int i = m_doc->identifierCount(); i <= id; i++ ) { - m_doc->appendIdentifier( KEduVocIdentifier() ); + m_doc->appendIdentifier( QmVocIdentifier() ); } // the first element, create the identifier, even if empty @@ -265,7 +275,7 @@ bool KEduVocKvtml2Reader::readIdentifier( QDomElement &identifierElement ) currentElement = identifierElement.firstChildElement( KVTML_PERSONALPRONOUNS ); if ( !currentElement.isNull() ) { - KEduVocPersonalPronoun personalPronoun; + QmVocPersonalPronoun personalPronoun; readPersonalPronoun( currentElement, personalPronoun ); m_doc->identifier(id).setPersonalPronouns( personalPronoun ); } @@ -277,7 +287,7 @@ bool KEduVocKvtml2Reader::readIdentifier( QDomElement &identifierElement ) return result; } -bool KEduVocKvtml2Reader::readEntry( QDomElement &entryElement ) +bool QmVocKvtml2Reader::readEntry( QDomElement &entryElement ) { QDomElement currentElement; bool result = true; @@ -285,11 +295,11 @@ bool KEduVocKvtml2Reader::readEntry( QDomElement &entryElement ) // get entry id int id = entryElement.attribute( KVTML_ID ).toInt( &result ); if ( !result ) { - m_errorMessage = i18n( "entry missing id" ); + m_errorMessage = "entry missing id" ; return false; } - KEduVocExpression *expr = new KEduVocExpression; + QmVocExpression *expr = new QmVocExpression; // read info tags: inactive, inquery, and sizehint currentElement = entryElement.firstChildElement( KVTML_DEACTIVATED ); @@ -315,7 +325,7 @@ bool KEduVocKvtml2Reader::readEntry( QDomElement &entryElement ) } if ( expr->translationIndices().size() == 0 ) { - kDebug() << "Found entry with no words in it." << id; + qDebug() << "Found entry with no words in it." << id; expr->setTranslation(0, QString()); } @@ -327,8 +337,8 @@ bool KEduVocKvtml2Reader::readEntry( QDomElement &entryElement ) return result; } -bool KEduVocKvtml2Reader::readTranslation( QDomElement &translationElement, - KEduVocExpression *expr, int index ) +bool QmVocKvtml2Reader::readTranslation( QDomElement &translationElement, + QmVocExpression *expr, int index ) { // read the text, grade, declension and conjugation expr->translation(index)->fromKVTML2(translationElement); @@ -337,7 +347,7 @@ bool KEduVocKvtml2Reader::readTranslation( QDomElement &translationElement, // article grade currentElement = translationElement.firstChildElement( KVTML_ARTICLE ); if ( !currentElement.isNull() ) { - KEduVocText article; + QmVocText article; article.fromKVTML2(currentElement); expr->translation(index)->setArticle(article); } @@ -357,19 +367,21 @@ bool KEduVocKvtml2Reader::readTranslation( QDomElement &translationElement, // image currentElement = translationElement.firstChildElement( KVTML_IMAGE ); if ( !currentElement.isNull() ) { - expr->translation(index)->setImageUrl( KUrl( m_doc->url(), currentElement.text() ) ); + qCritical("Fixme: get image path..."); + // expr->translation(index)->setImageUrl( KUrl( m_doc->url(), currentElement.text() ) ); } // sound currentElement = translationElement.firstChildElement( KVTML_SOUND ); if ( !currentElement.isNull() ) { - expr->translation(index)->setSoundUrl( KUrl( m_doc->url(), currentElement.text() ) ); + qCritical("Fixme: get sound path..."); + // expr->translation(index)->setSoundUrl( KUrl( m_doc->url(), currentElement.text() ) ); } return true; } -bool KEduVocKvtml2Reader::readChildLessons( KEduVocLesson* parentLesson, QDomElement &lessonElement ) +bool QmVocKvtml2Reader::readChildLessons( QmVocLesson* parentLesson, QDomElement &lessonElement ) { QDomElement currentElement = lessonElement.firstChildElement( KVTML_CONTAINER ); while ( !currentElement.isNull() ) { @@ -379,11 +391,11 @@ bool KEduVocKvtml2Reader::readChildLessons( KEduVocLesson* parentLesson, QDomEle return true; } -bool KEduVocKvtml2Reader::readLesson( KEduVocLesson* parentLesson, QDomElement &lessonElement ) +bool QmVocKvtml2Reader::readLesson( QmVocLesson* parentLesson, QDomElement &lessonElement ) { //Lesson name QDomElement currentElement = lessonElement.firstChildElement( KVTML_NAME ); - KEduVocLesson * lesson = new KEduVocLesson(currentElement.text(), parentLesson); + QmVocLesson * lesson = new QmVocLesson(currentElement.text(), parentLesson); parentLesson->appendChildContainer( lesson ); readChildLessons( lesson, lessonElement ); @@ -407,18 +419,18 @@ bool KEduVocKvtml2Reader::readLesson( KEduVocLesson* parentLesson, QDomElement & return true; } -bool KEduVocKvtml2Reader::readSynonymsAntonymsFalseFriends( QDomElement &rootElement ) +bool QmVocKvtml2Reader::readSynonymsAntonymsFalseFriends( QDomElement &rootElement ) { QDomElement pairElement; - for(int type = KEduVocTranslation::Synonym; type <= KEduVocTranslation::FalseFriend; type++) { + for(int type = QmVocTranslation::Synonym; type <= QmVocTranslation::FalseFriend; type++) { switch (type) { - case KEduVocTranslation::Synonym: + case QmVocTranslation::Synonym: pairElement= rootElement.firstChildElement( KVTML_SYNONYM ); break; - case KEduVocTranslation::Antonym: + case QmVocTranslation::Antonym: pairElement= rootElement.firstChildElement( KVTML_ANTONYM ); break; - case KEduVocTranslation::FalseFriend: + case QmVocTranslation::FalseFriend: pairElement= rootElement.firstChildElement( KVTML_FALSEFRIEND ); break; } @@ -439,19 +451,19 @@ bool KEduVocKvtml2Reader::readSynonymsAntonymsFalseFriends( QDomElement &rootEle int secondTranslationId = translationElement.attribute( KVTML_ID ).toInt(); // pair them up - KEduVocTranslation *first = m_allEntries[firstEntryId]->translation(firstTranslationId); - KEduVocTranslation *second = m_allEntries[secondEntryId]->translation(secondTranslationId); + QmVocTranslation *first = m_allEntries[firstEntryId]->translation(firstTranslationId); + QmVocTranslation *second = m_allEntries[secondEntryId]->translation(secondTranslationId); switch (type) { - case KEduVocTranslation::Synonym: + case QmVocTranslation::Synonym: first->addSynonym(second); second->addSynonym(first); break; - case KEduVocTranslation::Antonym: + case QmVocTranslation::Antonym: first->addAntonym(second); second->addAntonym(first); break; - case KEduVocTranslation::FalseFriend: + case QmVocTranslation::FalseFriend: first->addFalseFriend(second); second->addFalseFriend(first); break; @@ -462,7 +474,7 @@ bool KEduVocKvtml2Reader::readSynonymsAntonymsFalseFriends( QDomElement &rootEle return true; } -bool KEduVocKvtml2Reader::readArticle( QDomElement &articleElement, int identifierNum ) +bool QmVocKvtml2Reader::readArticle( QDomElement &articleElement, int identifierNum ) /*
@@ -482,17 +494,17 @@ bool KEduVocKvtml2Reader::readArticle( QDomElement &articleElement, int identifi
*/ { - QMap numbers; - numbers[0] = KEduVocWordFlag::Singular; - numbers[1] = KEduVocWordFlag::Dual; - numbers[2] = KEduVocWordFlag::Plural; - QMap genders; - genders[0] = KEduVocWordFlag::Masculine; - genders[1] = KEduVocWordFlag::Feminine; - genders[2] = KEduVocWordFlag::Neuter; - QMap defs; - defs[0] = KEduVocWordFlag::Definite; - defs[1] = KEduVocWordFlag::Indefinite; + QMap numbers; + numbers[0] = QmVocWordFlag::Singular; + numbers[1] = QmVocWordFlag::Dual; + numbers[2] = QmVocWordFlag::Plural; + QMap genders; + genders[0] = QmVocWordFlag::Masculine; + genders[1] = QmVocWordFlag::Feminine; + genders[2] = QmVocWordFlag::Neuter; + QMap defs; + defs[0] = QmVocWordFlag::Definite; + defs[1] = QmVocWordFlag::Indefinite; for ( int num = 0; num <= 2; ++num) { QDomElement numberElement = articleElement.firstChildElement( KVTML_GRAMMATICAL_NUMBER[num] ); @@ -517,7 +529,7 @@ bool KEduVocKvtml2Reader::readArticle( QDomElement &articleElement, int identifi } -bool KEduVocKvtml2Reader::readChildWordTypes(KEduVocWordType* parentContainer, QDomElement &lessonElement) +bool QmVocKvtml2Reader::readChildWordTypes(QmVocWordType* parentContainer, QDomElement &lessonElement) { QDomElement currentElement = lessonElement.firstChildElement( KVTML_CONTAINER ); while ( !currentElement.isNull() ) { @@ -527,13 +539,13 @@ bool KEduVocKvtml2Reader::readChildWordTypes(KEduVocWordType* parentContainer, Q return true; } -bool KEduVocKvtml2Reader::readLeitner( KEduVocLeitnerBox* parentContainer, QDomElement &leitnerParentElement ) +bool QmVocKvtml2Reader::readLeitner( QmVocLeitnerBox* parentContainer, QDomElement &leitnerParentElement ) { QDomElement leitnerElement = leitnerParentElement.firstChildElement( KVTML_CONTAINER ); while ( !leitnerElement.isNull() ) { QString name = leitnerElement.firstChildElement( KVTML_NAME ).text(); - KEduVocLeitnerBox * leitner = new KEduVocLeitnerBox(name, parentContainer); + QmVocLeitnerBox * leitner = new QmVocLeitnerBox(name, parentContainer); parentContainer->appendChildContainer(leitner); // for leitner we only allow a flat list, no sub boxes. @@ -556,41 +568,41 @@ bool KEduVocKvtml2Reader::readLeitner( KEduVocLeitnerBox* parentContainer, QDomE return true; } -bool KEduVocKvtml2Reader::readWordType( KEduVocWordType* parentContainer, QDomElement &typeElement ) +bool QmVocKvtml2Reader::readWordType( QmVocWordType* parentContainer, QDomElement &typeElement ) { // set type and specialtype QString typeName = typeElement.firstChildElement( KVTML_NAME ).text(); - KEduVocWordType * wordTypeContainer = new KEduVocWordType(typeName, parentContainer); + QmVocWordType * wordTypeContainer = new QmVocWordType(typeName, parentContainer); parentContainer->appendChildContainer(wordTypeContainer); QString specialType = typeElement.firstChildElement( KVTML_SPECIALWORDTYPE ).text(); if ( !specialType.isEmpty() ) { // get the localized version if ( specialType == KVTML_SPECIALWORDTYPE_NOUN ) { - wordTypeContainer->setWordType(KEduVocWordFlag::Noun); + wordTypeContainer->setWordType(QmVocWordFlag::Noun); } if ( specialType == KVTML_SPECIALWORDTYPE_VERB ) { - wordTypeContainer->setWordType(KEduVocWordFlag::Verb); + wordTypeContainer->setWordType(QmVocWordFlag::Verb); } if ( specialType == KVTML_SPECIALWORDTYPE_ADVERB ) { - wordTypeContainer->setWordType(KEduVocWordFlag::Adverb); + wordTypeContainer->setWordType(QmVocWordFlag::Adverb); } if ( specialType == KVTML_SPECIALWORDTYPE_ADJECTIVE ) { - wordTypeContainer->setWordType(KEduVocWordFlag::Adjective); + wordTypeContainer->setWordType(QmVocWordFlag::Adjective); } if ( specialType == KVTML_SPECIALWORDTYPE_NOUN_MALE ) { - wordTypeContainer->setWordType(KEduVocWordFlag::Noun | KEduVocWordFlag::Masculine); + wordTypeContainer->setWordType(QmVocWordFlag::Noun | QmVocWordFlag::Masculine); } if ( specialType == KVTML_SPECIALWORDTYPE_NOUN_FEMALE ) { - wordTypeContainer->setWordType(KEduVocWordFlag::Noun | KEduVocWordFlag::Feminine); + wordTypeContainer->setWordType(QmVocWordFlag::Noun | QmVocWordFlag::Feminine); } if ( specialType == KVTML_SPECIALWORDTYPE_NOUN_NEUTRAL ) { - wordTypeContainer->setWordType(KEduVocWordFlag::Noun| KEduVocWordFlag::Neuter); + wordTypeContainer->setWordType(QmVocWordFlag::Noun| QmVocWordFlag::Neuter); } if ( specialType == KVTML_SPECIALWORDTYPE_CONJUNCTION ) { - wordTypeContainer->setWordType(KEduVocWordFlag::Conjunction); + wordTypeContainer->setWordType(QmVocWordFlag::Conjunction); } } // special type @@ -614,7 +626,7 @@ bool KEduVocKvtml2Reader::readWordType( KEduVocWordType* parentContainer, QDomEl return true; } -QStringList KEduVocKvtml2Reader::readTenses( QDomElement &tensesElement ) +QStringList QmVocKvtml2Reader::readTenses( QDomElement &tensesElement ) { QStringList tenses; @@ -629,7 +641,7 @@ QStringList KEduVocKvtml2Reader::readTenses( QDomElement &tensesElement ) return tenses; } -bool KEduVocKvtml2Reader::readComparison( QDomElement &domElementParent, KEduVocTranslation* translation ) +bool QmVocKvtml2Reader::readComparison( QDomElement &domElementParent, QmVocTranslation* translation ) /* better @@ -642,7 +654,7 @@ bool KEduVocKvtml2Reader::readComparison( QDomElement &domElementParent, KEduVoc currentElement = domElementParent.firstChildElement( KVTML_COMPARATIVE ); if ( !currentElement.isNull() ) { - KEduVocText comparative; + QmVocText comparative; comparative.fromKVTML2(currentElement); // be compatible for KDE < 4.5 @@ -655,7 +667,7 @@ bool KEduVocKvtml2Reader::readComparison( QDomElement &domElementParent, KEduVoc currentElement = domElementParent.firstChildElement( KVTML_SUPERLATIVE ); if ( !currentElement.isNull() ) { - KEduVocText superlative; + QmVocText superlative; superlative.fromKVTML2(currentElement); // be compatible for KDE < 4.5 @@ -667,7 +679,7 @@ bool KEduVocKvtml2Reader::readComparison( QDomElement &domElementParent, KEduVoc return true; } -bool KEduVocKvtml2Reader::readMultipleChoice( QDomElement &multipleChoiceElement, KEduVocTranslation* translation ) +bool QmVocKvtml2Reader::readMultipleChoice( QDomElement &multipleChoiceElement, QmVocTranslation* translation ) /* good @@ -691,7 +703,7 @@ bool KEduVocKvtml2Reader::readMultipleChoice( QDomElement &multipleChoiceElement } -bool KEduVocKvtml2Reader::readPersonalPronoun(QDomElement & pronounElement, KEduVocPersonalPronoun & pronoun) +bool QmVocKvtml2Reader::readPersonalPronoun(QDomElement & pronounElement, QmVocPersonalPronoun & pronoun) { pronoun.setMaleFemaleDifferent(!pronounElement.firstChildElement( KVTML_THIRD_PERSON_MALE_FEMALE_DIFFERENT).isNull()); @@ -702,30 +714,30 @@ bool KEduVocKvtml2Reader::readPersonalPronoun(QDomElement & pronounElement, KEdu QDomElement personElement = pronounElement.firstChildElement( KVTML_GRAMMATICAL_NUMBER[0] ); if ( !personElement.isNull() ) { - readPersonalPronounChild( personElement, pronoun, KEduVocWordFlag::Singular ); + readPersonalPronounChild( personElement, pronoun, QmVocWordFlag::Singular ); } personElement = pronounElement.firstChildElement( KVTML_GRAMMATICAL_NUMBER[1] ); if ( !personElement.isNull() ) { - readPersonalPronounChild( personElement, pronoun, KEduVocWordFlag::Dual ); + readPersonalPronounChild( personElement, pronoun, QmVocWordFlag::Dual ); } personElement = pronounElement.firstChildElement( KVTML_GRAMMATICAL_NUMBER[2] ); if ( !personElement.isNull() ) { - readPersonalPronounChild( personElement, pronoun, KEduVocWordFlag::Plural ); + readPersonalPronounChild( personElement, pronoun, QmVocWordFlag::Plural ); } return true; } -bool KEduVocKvtml2Reader::readPersonalPronounChild(QDomElement & personElement, KEduVocPersonalPronoun & pronoun, KEduVocWordFlags number) +bool QmVocKvtml2Reader::readPersonalPronounChild(QDomElement & personElement, QmVocPersonalPronoun & pronoun, QmVocWordFlags number) { - QMap persons; - persons[0] = KEduVocWordFlag::First; - persons[1] = KEduVocWordFlag::Second; - persons[2] = (KEduVocWordFlag::Flags)((int)KEduVocWordFlag::Third | (int)KEduVocWordFlag::Masculine); - persons[3] = (KEduVocWordFlag::Flags)((int)KEduVocWordFlag::Third | (int)KEduVocWordFlag::Feminine); - persons[4] = (KEduVocWordFlag::Flags)((int)KEduVocWordFlag::Third | (int)KEduVocWordFlag::Neuter); + QMap persons; + persons[0] = QmVocWordFlag::First; + persons[1] = QmVocWordFlag::Second; + persons[2] = (QmVocWordFlag::Flags)((int)QmVocWordFlag::Third | (int)QmVocWordFlag::Masculine); + persons[3] = (QmVocWordFlag::Flags)((int)QmVocWordFlag::Third | (int)QmVocWordFlag::Feminine); + persons[4] = (QmVocWordFlag::Flags)((int)QmVocWordFlag::Third | (int)QmVocWordFlag::Neuter); @@ -738,4 +750,3 @@ bool KEduVocKvtml2Reader::readPersonalPronounChild(QDomElement & personElement, } -#include "keduvockvtml2reader.moc" -- 2.47.3