#include <QtCore/QStringList>
-
+///@todo get rid of this old strange prefix thing: used to mark personal pronouns.
#define CONJ_PREFIX "--" // definition of prefixes (I, you, ..)
-#define UL_USER_TENSE "#" // designates number of user tense
-
class KEDUVOCDOCUMENT_EXPORT KEduVocTenseRelation
{
~KEduVocConjugation();
- /**
- * @return
- */
int entryCount() const;
-
- QString getVerbName() const;
-
QString getType( int index );
void setType( int index, const QString & type );
void cleanUp();
#include <KDebug>
-const QString KEduVocKvtmlCompability::KVTML_1_USAGE_USER_DEFINED = QString( "#" );
-const QString KEduVocKvtmlCompability::KVTML_1_USAGE_SEPERATOR = QString( ":" );
-
-const QString KEduVocKvtmlCompability::KVTML_1_TYPE_USER = QString( "#" );
-const QString KEduVocKvtmlCompability::KVTML_1_TYPE_DIV = QString( ":" );
+const QString KEduVocKvtmlCompability::KVTML_1_USER_DEFINED = QString( "#" );
+const QString KEduVocKvtmlCompability::KVTML_1_SEPERATOR = QString( ":" );
KEduVocKvtmlCompability::KEduVocKvtmlCompability()
{
m_usages = usageMap();
m_userdefinedUsageCounter = 0;
+ m_userdefinedTenseCounter = 0;
initOldTypeLists();
- initOldConjugations();
+ initOldTenses();
}
QSet<QString> KEduVocKvtmlCompability::usageFromKvtml1( const QString & oldUsage ) const
{
QSet<QString> usages;
- foreach( QString usage , oldUsage.split( KVTML_1_USAGE_SEPERATOR, QString::SkipEmptyParts ) ) {
+ foreach( QString usage , oldUsage.split( KVTML_1_SEPERATOR, QString::SkipEmptyParts ) ) {
usages.insert( m_usages[usage] );
}
return usages;
{
// start counting at 1 !!!
m_userdefinedUsageCounter++;
- m_usages[KVTML_1_USAGE_USER_DEFINED + QString::number( m_userdefinedUsageCounter )] = usage;
+ m_usages[KVTML_1_USER_DEFINED + QString::number( m_userdefinedUsageCounter )] = usage;
}
QSet< QString > KEduVocKvtmlCompability::documentUsages() const
QString mainType;
int i;
- if (( i = typeSubtypeString.indexOf( KVTML_1_TYPE_DIV ) ) >= 0 )
+ if (( i = typeSubtypeString.indexOf( KVTML_1_SEPERATOR ) ) >= 0 )
mainType = typeSubtypeString.left( i );
else
mainType = typeSubtypeString;
{
int i;
QString t = typeSubtypeString;
- if (( i = t.indexOf( KVTML_1_TYPE_DIV ) ) >= 0 ) {
+ if (( i = t.indexOf( KVTML_1_SEPERATOR ) ) >= 0 ) {
t.remove( 0, i+1 );
} else {
return QString();
oldType = m_oldMainTypeNames.key( mainType );
oldSubType = m_oldSubTypeNames.key( subType );
if ( !oldSubType.isEmpty() ) {
- return oldType + KVTML_1_TYPE_DIV + oldSubType;
+ return oldType + KVTML_1_SEPERATOR + oldSubType;
}
return oldType;
}
-void KEduVocKvtmlCompability::initOldConjugations()
+void KEduVocKvtmlCompability::initOldTenses()
{
m_oldTenses["PrSi"] = i18n( "Simple Present" );
m_oldTenses["PrPr"] = i18n( "Present Progressive" );
m_oldTenses["PaPa"] = i18n( "Past Participle" );
m_oldTenses["FuSi"] = i18n( "Future" );
}
+
+
+void KEduVocKvtmlCompability::addUserdefinedTense(const QString & tense)
+{
+ m_userdefinedTenseCounter++;
+ m_oldTenses[KVTML_1_USER_DEFINED + QString::number( m_userdefinedTenseCounter )] = tense;
+ m_tenses.insert(tense);
+
+ kDebug() << " Add tense: " << KVTML_1_USER_DEFINED + QString::number( m_userdefinedTenseCounter ) << " - " << tense;
+}
+
+
+QString KEduVocKvtmlCompability::tenseFromKvtml1(const QString & oldTense)
+{
+ // in case the document got chaged, at least make up something as tense
+ if (!m_oldTenses.keys().contains(oldTense)) {
+ m_oldTenses[oldTense] = oldTense;
+ kDebug() << "Warning, tense not found in document!";
+ }
+ m_tenses.insert(m_oldTenses.value(oldTense));
+ return m_oldTenses.value(oldTense);
+}
+
+
+QStringList KEduVocKvtmlCompability::documentTenses() const
+{
+ return m_tenses.values();
+}
+
#define UL_USER_USAGE "#" // designates number of user type
-
-
-
/**
* @file contains defines and constants necessary for reading kvtml files prior to KDE4. kvtml version 1.
*/
QString oldType( const QString& mainType, const QString& subType ) const;
+ void addUserdefinedTense( const QString& tense );
+ QString tenseFromKvtml1( const QString & oldTense );
+ QStringList documentTenses() const;
private:
/**
/// 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 KVTML_1_USAGE_USER_DEFINED;
- /// : seperates usages
- static const QString KVTML_1_USAGE_SEPERATOR;
/// only order was decisive, we have to keep count.
int m_userdefinedUsageCounter;
QMap<QString, QString> m_oldMainTypeNames;
QMap<QString, QString> m_oldSubTypeNames;
- static const QString KVTML_1_TYPE_USER;
- static const QString KVTML_1_TYPE_DIV;
-
///////////TENSES/CONJUGATIONS///////
- void initOldConjugations();
- QMap<QString, QString> m_oldTenses;
+ void initOldTenses();
+ QMap<QString, QString> m_oldTenses;
+ int m_userdefinedTenseCounter;
+ QSet<QString> m_tenses;
+ /// # defines user defined usage/word type/tense
+ static const QString KVTML_1_USER_DEFINED;
+ /// : seperates usages/word types
+ static const QString KVTML_1_SEPERATOR;
};
}
}
+ m_doc->setTenseDescriptions(m_compability.documentTenses());
+
return true;
}
QString pers3_f_plur;
QString pers3_n_plur;
QString lang;
- QString type;
+ QString tense; // former type
// this gets a list of keduvocconjugations, count will be the conjug number to be filled.
int count = 0;
{
if ( domElementConjugChild.tagName() == KV_CON_ENTRY ) { // if KV_CON_ENTRY == "e" is found, we are reading a personal pronun definition.
// CONJ_PREFIX is defined as "--"
- type = CONJ_PREFIX;
+ tense = CONJ_PREFIX;
//----------
// Attribute
// "n" == is the type is the tense
QDomAttr domAttrLang = domElementConjugChild.attributeNode( KV_CON_NAME );
- type = domAttrLang.value();
- if ( type.isNull() )
- type = "";
-
- // if it starts with "#" the user typed in the tense name
- if ( type.length() != 0 && type.left( 1 ) == UL_USER_TENSE ) {
- int num = qMin( type.mid( 1, 40 ).toInt(), 1000 ); // paranoia check
- if ( num > m_doc->tenseDescriptions().count() ) {
- // description missing ?
- QString s;
- QStringList sl = m_doc->tenseDescriptions();
- for ( int i = m_doc->tenseDescriptions().count(); i < num; i++ ) {
- s.setNum( i + 1 );
- s.prepend( "#" ); // invent descr according to number
- sl.append( s );
- }
- m_doc->setTenseDescriptions( sl );
- }
- }
+ QString oldShortTense = domAttrLang.value();
+
+ tense = m_compability.tenseFromKvtml1( oldShortTense );
}
pers1_sing = "";
// now set the data: [count] - number of conjug?
// type - the tense?
// finally the person
- curr_conjug[count].setPers3SingularCommon( type, s3_common );
- curr_conjug[count].setPers3PluralCommon( type, p3_common );
- curr_conjug[count].setPers1Singular( type, pers1_sing );
- curr_conjug[count].setPers2Singular( type, pers2_sing );
- curr_conjug[count].setPers3FemaleSingular( type, pers3_f_sing );
- curr_conjug[count].setPers3MaleSingular( type, pers3_m_sing );
- curr_conjug[count].setPers3NaturalSingular( type, pers3_n_sing );
- curr_conjug[count].setPers1Plural( type, pers1_plur );
- curr_conjug[count].setPers2Plural( type, pers2_plur );
- curr_conjug[count].setPers3FemalePlural( type, pers3_f_plur );
- curr_conjug[count].setPers3MalePlural( type, pers3_m_plur );
- curr_conjug[count].setPers3NaturalPlural( type, pers3_n_plur );
+ curr_conjug[count].setPers3SingularCommon( tense, s3_common );
+ curr_conjug[count].setPers3PluralCommon( tense, p3_common );
+ curr_conjug[count].setPers1Singular( tense, pers1_sing );
+ curr_conjug[count].setPers2Singular( tense, pers2_sing );
+ curr_conjug[count].setPers3FemaleSingular( tense, pers3_f_sing );
+ curr_conjug[count].setPers3MaleSingular( tense, pers3_m_sing );
+ curr_conjug[count].setPers3NaturalSingular( tense, pers3_n_sing );
+ curr_conjug[count].setPers1Plural( tense, pers1_plur );
+ curr_conjug[count].setPers2Plural( tense, pers2_plur );
+ curr_conjug[count].setPers3FemalePlural( tense, pers3_f_plur );
+ curr_conjug[count].setPers3MalePlural( tense, pers3_m_plur );
+ curr_conjug[count].setPers3NaturalPlural( tense, pers3_n_plur );
if ( domElementConjugChild.tagName() == KV_CON_ENTRY )
count++;
domElementConjugChild = domElementConjugChild.nextSibling().toElement();
- } // while -> next type, count++
+ } // while -> next tense, count++
return true;
}
bool KEduVocKvtmlReader::readTense( QDomElement &domElementParent )
{
- QString s;
QDomElement currentElement;
- QStringList descriptions;
QDomNodeList entryList = domElementParent.elementsByTagName( KV_TENSE_DESC );
if ( entryList.length() <= 0 )
return false;
- descriptions.clear();
-
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_TENSE_NO );
- if ( !attribute.isNull() )
- no = attribute.value().toInt();
-
- s = currentElement.text();
- if ( s.isNull() )
- s = "";
- descriptions.append( s );
+ m_compability.addUserdefinedTense( currentElement.text() );
}
}
- m_doc->setTenseDescriptions( descriptions );
return true;
}