From bd00f54810ee9be55a63aaeb4c12dd0a32397042 Mon Sep 17 00:00:00 2001 From: Reto Zingg Date: Sat, 15 Dec 2012 19:28:48 +0200 Subject: [PATCH] adapt qmvockvtmlreader.cpp for querymee --- qmvockvtmlreader.cpp | 163 ++++++++++++++++++++++--------------------- 1 file changed, 84 insertions(+), 79 deletions(-) diff --git a/qmvockvtmlreader.cpp b/qmvockvtmlreader.cpp index a73fff9..e927672 100644 --- a/qmvockvtmlreader.cpp +++ b/qmvockvtmlreader.cpp @@ -1,11 +1,16 @@ /*************************************************************************** - 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 (C) 2005 Eric Pignet (C) 2007 Peter Hedlund (C) 2007 Frederik Gladhorn + (C) 2010, 2012 Reto Zingg ***************************************************************************/ /*************************************************************************** @@ -17,45 +22,46 @@ * * ***************************************************************************/ -#include "keduvockvtmlreader.h" +#include "qmvockvtmlreader.h" #include #include #include -#include -#include -#include +// #include +#include +// #include +// #include -#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; } @@ -112,7 +118,7 @@ bool KEduVocKvtmlReader::readDoc( KEduVocDocument *doc ) } -bool KEduVocKvtmlReader::readBody( QDomElement &domElementParent ) +bool QmVocKvtmlReader::readBody( QDomElement &domElementParent ) { bool result = false; @@ -145,7 +151,7 @@ bool KEduVocKvtmlReader::readBody( QDomElement &domElementParent ) return false; } - KEduVocPersonalPronoun pronouns; + QmVocPersonalPronoun pronouns; if (! readPersonalPronouns( domElementConjugChild, pronouns ) ) { return false; } @@ -195,7 +201,7 @@ bool KEduVocKvtmlReader::readBody( QDomElement &domElementParent ) } -bool KEduVocKvtmlReader::readLesson( QDomElement &domElementParent ) +bool QmVocKvtmlReader::readLesson( QDomElement &domElementParent ) { QString s; QDomAttr attribute; @@ -227,11 +233,11 @@ bool KEduVocKvtmlReader::readLesson( QDomElement &domElementParent ) } 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?"; } } } @@ -240,7 +246,7 @@ bool KEduVocKvtmlReader::readLesson( QDomElement &domElementParent ) } -bool KEduVocKvtmlReader::readArticle( QDomElement &domElementParent ) +bool QmVocKvtmlReader::readArticle( QDomElement &domElementParent ) /*
lang determines also lang order in entries !! @@ -266,7 +272,7 @@ bool KEduVocKvtmlReader::readArticle( QDomElement &domElementParent ) 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; @@ -328,7 +334,7 @@ bool KEduVocKvtmlReader::readArticle( QDomElement &domElementParent ) 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 ) ); } } @@ -336,7 +342,7 @@ bool KEduVocKvtmlReader::readArticle( QDomElement &domElementParent ) } -bool KEduVocKvtmlReader::readTranslationConjugations( QDomElement &domElementParent, KEduVocTranslation* translation ) +bool QmVocKvtmlReader::readTranslationConjugations( QDomElement &domElementParent, QmVocTranslation* translation ) { QString tense; @@ -348,7 +354,7 @@ bool KEduVocKvtmlReader::readTranslationConjugations( QDomElement &domElementPar QString oldShortTense = domAttrLang.value(); tense = m_compability.tenseFromKvtml1( oldShortTense ); - KEduVocConjugation conjugation; + QmVocConjugation conjugation; readConjugation(domElementConjugChild, conjugation); translation->setConjugation(tense, conjugation); @@ -357,7 +363,7 @@ bool KEduVocKvtmlReader::readTranslationConjugations( QDomElement &domElementPar return true; } -bool KEduVocKvtmlReader::readConjugation( QDomElement &domElementParent, KEduVocConjugation& conjugation ) +bool QmVocKvtmlReader::readConjugation( QDomElement &domElementParent, QmVocConjugation& conjugation ) /* used in header for definiton of "prefix" lang determines also lang order in entries !! @@ -460,34 +466,34 @@ bool KEduVocKvtmlReader::readConjugation( QDomElement &domElementParent, KEduVoc // 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; @@ -496,7 +502,7 @@ bool KEduVocKvtmlReader::readConjugation( QDomElement &domElementParent, KEduVoc -bool KEduVocKvtmlReader::readPersonalPronouns( QDomElement &domElementParent, KEduVocPersonalPronoun& pronouns ) +bool QmVocKvtmlReader::readPersonalPronouns( QDomElement &domElementParent, QmVocPersonalPronoun& pronouns ) { // QString s; bool p3_common; @@ -568,37 +574,37 @@ bool KEduVocKvtmlReader::readPersonalPronouns( QDomElement &domElementParent, KE // 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); } @@ -606,7 +612,7 @@ bool KEduVocKvtmlReader::readPersonalPronouns( QDomElement &domElementParent, KE } -bool KEduVocKvtmlReader::readType( QDomElement &domElementParent ) +bool QmVocKvtmlReader::readType( QDomElement &domElementParent ) { QString s; QDomElement currentElement; @@ -621,9 +627,9 @@ bool KEduVocKvtmlReader::readType( QDomElement &domElementParent ) // 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 @@ -635,13 +641,13 @@ bool KEduVocKvtmlReader::readType( QDomElement &domElementParent ) } -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 ); } @@ -649,7 +655,7 @@ bool KEduVocKvtmlReader::readTense( QDomElement &domElementParent ) } -bool KEduVocKvtmlReader::readComparison( QDomElement &domElementParent, KEduVocTranslation * translation ) +bool QmVocKvtmlReader::readComparison( QDomElement &domElementParent, QmVocTranslation * translation ) /* good --- this one is dead as it always has to be the word itself @@ -670,7 +676,7 @@ bool KEduVocKvtmlReader::readComparison( QDomElement &domElementParent, KEduVocT } -bool KEduVocKvtmlReader::readMultipleChoice( QDomElement &domElementParent, KEduVocTranslation* translation ) +bool QmVocKvtmlReader::readMultipleChoice( QDomElement &domElementParent, QmVocTranslation* translation ) /* good @@ -713,7 +719,7 @@ bool KEduVocKvtmlReader::readMultipleChoice( QDomElement &domElementParent, KEdu } -bool KEduVocKvtmlReader::readExpressionChildAttributes( QDomElement &domElementExpressionChild, +bool QmVocKvtmlReader::readExpressionChildAttributes( QDomElement &domElementExpressionChild, QString &lang, grade_t &grade, grade_t &rev_grade, int &count, int &rev_count, @@ -854,7 +860,7 @@ bool KEduVocKvtmlReader::readExpressionChildAttributes( QDomElement &domElementE } -bool KEduVocKvtmlReader::readExpression( QDomElement &domElementParent ) +bool QmVocKvtmlReader::readExpression( QDomElement &domElementParent ) { grade_t grade; grade_t r_grade; @@ -901,9 +907,9 @@ bool KEduVocKvtmlReader::readExpression( QDomElement &domElementParent ) ///@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); } } @@ -943,11 +949,11 @@ bool KEduVocKvtmlReader::readExpression( QDomElement &domElementParent ) // 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() ) { @@ -973,10 +979,10 @@ bool KEduVocKvtmlReader::readExpression( QDomElement &domElementParent ) textstr = currentElement.lastChild().toText().data(); if ( i == 0 ) { - entry = new KEduVocExpression( textstr ); + entry = new QmVocExpression( textstr ); entry->setActive( active ); if ( lessonNumber != -1 ) { - static_cast(m_doc->lesson()->childContainer(lessonNumber))->appendEntry(entry); + static_cast(m_doc->lesson()->childContainer(lessonNumber))->appendEntry(entry); } else { m_doc->lesson()->appendEntry(entry); } @@ -984,7 +990,7 @@ bool KEduVocKvtmlReader::readExpression( QDomElement &domElementParent ) 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; @@ -1014,7 +1020,7 @@ bool KEduVocKvtmlReader::readExpression( QDomElement &domElementParent ) } 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); } @@ -1059,7 +1065,7 @@ bool KEduVocKvtmlReader::readExpression( QDomElement &domElementParent ) } -bool KEduVocKvtmlReader::addLanguage( int languageId, const QString& locale) +bool QmVocKvtmlReader::addLanguage( int languageId, const QString& locale) { if ( m_doc->identifierCount() <= languageId ) { m_doc->appendIdentifier(); @@ -1068,23 +1074,23 @@ bool KEduVocKvtmlReader::addLanguage( int languageId, const QString& locale) 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; } } @@ -1093,4 +1099,3 @@ bool KEduVocKvtmlReader::addLanguage( int languageId, const QString& locale) } -#include "keduvockvtmlreader.moc" -- 2.47.3