]> Git trees. - libqmvoc.git/commitdiff
Enable the readers including kvtml-1 also in code and finish porting it
authorFrederik Gladhorn <gladhorn@kde.org>
Sat, 5 Jan 2008 14:29:58 +0000 (14:29 +0000)
committerFrederik Gladhorn <gladhorn@kde.org>
Sat, 5 Jan 2008 14:29:58 +0000 (14:29 +0000)
to a works somewhat state.
Reading subwordtypes is still not working because they are not created
correctly in the init section of the compability class.
Remove last references to usage stuff (no one will miss it).
Some cleanup of the horrible horrible kvtml-1 reader code.
I will have to drop the kvtml-1 writer. Too much effort and too many
things that cannot be saved in the old format.

svn path=/branches/work/kdeedu_parley/libkdeedu/; revision=757614

keduvocdocument/CMakeLists.txt
keduvocdocument/keduvocdocument.cpp
keduvocdocument/keduvocdocument.h
keduvocdocument/keduvockvtml2reader.cpp
keduvocdocument/keduvockvtmlcompability.cpp
keduvocdocument/keduvockvtmlcompability.h
keduvocdocument/keduvockvtmlreader.cpp
keduvocdocument/keduvockvtmlreader.h
keduvocdocument/keduvocwordtype.cpp

index 8fd2e3571b2bd38918fc8be939cf2c5bb068ec79..265ffb514bd177fcc630fb3f22278b3976b5eabf 100644 (file)
@@ -16,7 +16,7 @@ keduvocdocument.cpp
    keduvocdeclination.cpp
    keduvocwordtype.cpp
    keduvockvtmlcompability.cpp
-   #keduvockvtmlreader.cpp
+   keduvockvtmlreader.cpp
    keduvockvtml2reader.cpp
    #keduvockvtmlwriter.cpp
    keduvockvtml2writer.cpp
index c94fa22c90c35fe26c9f2903c114859f8d16ade4..264769ffd1930414bf3c174892c081be4ff0f5ab 100644 (file)
@@ -73,7 +73,6 @@ public:
     // save these to document
     QList<KEduVocIdentifier>  m_identifiers;
 
-    int                       m_currentLesson;
     QList<int>                m_extraSizeHints;
     QList<int>                m_sizeHints;
 
@@ -123,7 +122,6 @@ void KEduVocDocument::KEduVocDocumentPrivate::init()
     m_extraSizeHints.clear();
     m_sizeHints.clear();
     m_dirty = false;
-    m_currentLesson = 0;
     m_queryorg = "";
     m_querytrans = "";
     m_url.setFileName( i18n( "Untitled" ) );
@@ -266,8 +264,7 @@ kDebug() << "open";
                 }
             }
             break;
-///@todo port me
-/*
+
             case Wql: {
                 kDebug(1100) << "Reading WordQuiz (WQL) document...";
                 KEduVocWqlReader wqlReader( f );
@@ -320,7 +317,7 @@ kDebug() << "open";
                     errorMessage = i18n( "Parse error at line %1, column %2:\n%3", xdxfReader.lineNumber(), xdxfReader.columnNumber(), xdxfReader.errorString() );
                 }
             }
-            break;*/
+            break;
 
             default: {
                 kDebug(1100) << "Reading KVTML document (fallback)...";
index f0eb2a5312d9f8e3bac3aa702beb28b336066d8a..f0c8468e68a96efba0871be311e7a1c8587ed88f 100644 (file)
@@ -241,16 +241,6 @@ public:
      */
     int indexOfIdentifier( const QString &name ) const;
 
-    // *** type methods ***
-
-    /**
-     * Returns the type handling class. See KEduVocWordType.
-     *
-     * @returns the KEduVocWordType* type handling class
-     */
-    KEduVocWordType& wordTypes();
-
-
     // *** tense methods ***
 
     /**
@@ -279,42 +269,9 @@ public:
      */
     QStringList tenseDescriptions() const;
 
-    // *** usage methods ***
-
-    /**
-     * Gets the descriptions of the usages.
-     * Usages are context information in a dictionary you may find [biol.]
-     * [am.] and the like to hint at the context in which the word is usually used.
-     */
-    QStringList usages() const;
-
-    /**
-     * Adds a usage label to the doc.
-     *
-     * @param usage    name of the usage
-     */
-    void addUsage( const QString &usage );
-
-    /**
-     * Rename a usage label.
-     * Actually changes the label in the vocabulary as well.
-     *
-     * @param oldName    old name of the usage label
-     * @param newName    new name of the usage label
-     */
-    void renameUsage( const QString &oldName, const QString &newName );
-
-    /**
-     * Remove a usage label.
-     * Also removes the label from all translations.
-     *
-     * @param name    new name of the usage label
-     */
-    void removeUsage( const QString &name );
 
     // *** grade methods ***
 
-
     /**
      * Retrieves the identifiers for the current query
      * not written in the new version!
index c483b2ae28b6f160df6d7305452af6f1ab985176..be0331d28afc43bf0d21a3e3467701c06aace9c9 100644 (file)
@@ -58,21 +58,21 @@ bool KEduVocKvtml2Reader::readDoc( KEduVocDocument *doc )
         m_errorMessage = i18n( "This is not a KDE Vocabulary document." );
         return false;
     }
-///@todo port me
-//     if ( domElementKvtml.attribute( KVTML_VERSION ).toFloat() < 2.0 ) {
-//         // read the file with the old format
-//
-//         // first reset the file to the beginning
-//         m_inputFile->seek( 0 );
-//         KEduVocKvtmlReader oldFormat( m_inputFile );
-//
-//         // get the return value
-//         bool retval = oldFormat.readDoc( doc );
-//
-//         // pass the errormessage up
-//         m_errorMessage = oldFormat.errorMessage();
-//         return retval;
-//     }
+
+    if ( domElementKvtml.attribute( KVTML_VERSION ).toFloat() < 2.0 ) {
+        // read the file with the old format
+
+        // first reset the file to the beginning
+        m_inputFile->seek( 0 );
+        KEduVocKvtmlReader oldFormat( m_inputFile );
+
+        // get the return value
+        bool retval = oldFormat.readDoc( doc );
+
+        // pass the errormessage up
+        m_errorMessage = oldFormat.errorMessage();
+        return retval;
+    }
 
     //-------------------------------------------------------------------------
     // Information
index c1f8a84bb36f839c3b4fce29ae6f080acc776600..840354272fad16c7bb651014f3731a3d4a0ca551 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "keduvockvtmlcompability.h"
 
+#include "keduvocwordtype.h"
 #include <KDebug>
 
 const QString KEduVocKvtmlCompability::KVTML_1_USER_DEFINED = QString( "#" );
@@ -31,98 +32,17 @@ const QString KEduVocKvtmlCompability::KVTML_1_SEPERATOR = QString( ":" );
 
 KEduVocKvtmlCompability::KEduVocKvtmlCompability()
 {
-    m_usages = usageMap();
-    m_userdefinedUsageCounter = 0;
     m_userdefinedTenseCounter = 0;
+    m_userdefinedTypeCounter = 0;
 
     initOldTypeLists();
     initOldTenses();
 }
 
 
-QSet<QString> KEduVocKvtmlCompability::usageFromKvtml1( const QString & oldUsage ) const
-{
-    QSet<QString> usages;
-    foreach( QString usage , oldUsage.split( KVTML_1_SEPERATOR, QString::SkipEmptyParts ) ) {
-        usages.insert( m_usages[usage] );
-    }
-    return usages;
-}
-
-
-QMap< QString, QString > KEduVocKvtmlCompability::usageMap()
-{
-    QMap< QString, QString > usages;
-
-    usages["Am"    ] = i18nc("usage label - context in which a word is used", "Americanism" );
-    usages["abbr"  ] = i18nc("usage label - context in which a word is used", "abbreviation" );
-    usages["anat"  ] = i18nc("usage label - context in which a word is used", "anatomy" );
-    usages["astr"  ] = i18nc("usage label - context in which a word is used", "astronomy" );
-    usages["biol"  ] = i18nc("usage label - context in which a word is used", "biology" );
-    usages["bs"    ] = i18nc("usage label - context in which a word is used", "bad sense" );
-    usages["contp" ] = i18nc("usage label - context in which a word is used", "contemptuously" );
-    usages["eccl"  ] = i18nc("usage label - context in which a word is used", "ecclesiastical" );
-    usages["fig"   ] = i18nc("usage label - context in which a word is used", "figuratively" );
-    usages["geol"  ] = i18nc("usage label - context in which a word is used", "geology" );
-    usages["hist"  ] = i18nc("usage label - context in which a word is used", "historical" );
-    usages["icht"  ] = i18nc("usage label - context in which a word is used", "ichthyology" );
-    usages["ifm"   ] = i18nc("usage label - context in which a word is used", "informal" );
-    usages["iro"   ] = i18nc("usage label - context in which a word is used", "ironic" );
-    usages["irr"   ] = i18nc("usage label - context in which a word is used", "irregular" );
-    usages["lit"   ] = i18nc("usage label - context in which a word is used", "literary" );
-    usages["metal" ] = i18nc("usage label - context in which a word is used", "metallurgy" );
-    usages["meteo" ] = i18nc("usage label - context in which a word is used", "meteorology" );
-    usages["miner" ] = i18nc("usage label - context in which a word is used", "mineralogy" );
-    usages["mot"   ] = i18nc("usage label - context in which a word is used", "motoring" );
-    usages["mount" ] = i18nc("usage label - context in which a word is used", "mountaineering" );
-    usages["myth"  ] = i18nc("usage label - context in which a word is used", "mythology" );
-    usages["npr"   ] = i18nc("usage label - context in which a word is used", "proper name" );
-    usages["opt"   ] = i18nc("usage label - context in which a word is used", "optics" );
-    usages["orn"   ] = i18nc("usage label - context in which a word is used", "ornithology" );
-    usages["os"    ] = i18nc("usage label - context in which a word is used", "oneself" );
-    usages["p"     ] = i18nc("usage label - context in which a word is used", "person" );
-    usages["parl"  ] = i18nc("usage label - context in which a word is used", "parliamentary" );
-    usages["pharm" ] = i18nc("usage label - context in which a word is used", "pharmacy" );
-    usages["phls"  ] = i18nc("usage label - context in which a word is used", "philosophy" );
-    usages["phot"  ] = i18nc("usage label - context in which a word is used", "photography" );
-    usages["phys"  ] = i18nc("usage label - context in which a word is used", "physics" );
-    usages["physio"] = i18nc("usage label - context in which a word is used", "physiology" );
-    usages["pl"    ] = i18nc("usage label - context in which a word is used", "plural" );
-    usages["poet"  ] = i18nc("usage label - context in which a word is used", "poetry" );
-    usages["pol"   ] = i18nc("usage label - context in which a word is used", "politics" );
-    usages["prov"  ] = i18nc("usage label - context in which a word is used", "provincialism" );
-    usages["psych" ] = i18nc("usage label - context in which a word is used", "psychology" );
-    usages["rhet"  ] = i18nc("usage label - context in which a word is used", "rhetoric" );
-    usages["surv"  ] = i18nc("usage label - context in which a word is used", "surveying" );
-    usages["telg"  ] = i18nc("usage label - context in which a word is used", "telegraphy" );
-    usages["telph" ] = i18nc("usage label - context in which a word is used", "telephony" );
-    usages["thea"  ] = i18nc("usage label - context in which a word is used", "theater" );
-    usages["typo"  ] = i18nc("usage label - context in which a word is used", "typography" );
-    usages["univ"  ] = i18nc("usage label - context in which a word is used", "university" );
-    usages["vet"   ] = i18nc("usage label - context in which a word is used", "veterinary medicine" );
-    usages["zoo"   ] = i18nc("usage label - context in which a word is used", "zoology" );
-
-    return usages;
-}
-
-void KEduVocKvtmlCompability::addUserdefinedUsage( const QString & usage )
-{
-    // start counting at 1 !!!
-    m_userdefinedUsageCounter++;
-    m_usages[KVTML_1_USER_DEFINED + QString::number( m_userdefinedUsageCounter )] = usage;
-}
-
-QSet< QString > KEduVocKvtmlCompability::documentUsages() const
-{
-    return QSet<QString>::fromList( m_usages.values() );
-}
-
-
-
 ////////////////// TYPES /////////////////////////////////////////
 void KEduVocKvtmlCompability::initOldTypeLists()
 {
-
     m_oldMainTypeNames.clear();
     m_oldMainTypeNames.insert( "v", i18nc( "@item:inlistbox The grammatical type of a word", "Verb" ) );
     m_oldMainTypeNames.insert( "n", i18nc( "@item:inlistbox The grammatical type of a word", "Noun" ) );
@@ -153,15 +73,26 @@ void KEduVocKvtmlCompability::initOldTypeLists()
 }
 
 
-QString KEduVocKvtmlCompability::mainTypeFromOldFormat( const QString & typeSubtypeString ) const
+KEduVocWordType* KEduVocKvtmlCompability::typeFromOldFormat(KEduVocWordType* parent, const QString & typeSubtypeString ) const
 {
+    // check if it's user defined
+    if ( typeSubtypeString.length() >= 2 && typeSubtypeString.left( 1 ) == QM_USER_TYPE ) {
+        // they started counting at 1, we need to know which index we are dealing with:
+        int selfDefinedTypeIndex = typeSubtypeString.right( typeSubtypeString.count()-1 ).toInt() -1;
+        return static_cast<KEduVocWordType*>(parent->childContainer(selfDefinedTypeIndex));
+    }
+
+    // assume the parent is set up to contain the old types correctly
     QString mainType;
+    QString subType;
     int i;
 
-    if (( i = typeSubtypeString.indexOf( KVTML_1_SEPERATOR ) ) >= 0 )
+    if (( i = typeSubtypeString.indexOf( KVTML_1_SEPERATOR ) ) >= 0 ) {
         mainType = typeSubtypeString.left( i );
-    else
+        subType = typeSubtypeString.right( i+1 );
+    } else {
         mainType = typeSubtypeString;
+    }
 
     // convert from pre-0.5 versions (I guess we can just leave that in here.
     // I seriously doubt that any such documents exist...
@@ -173,45 +104,72 @@ QString KEduVocKvtmlCompability::mainTypeFromOldFormat( const QString & typeSubt
         mainType = QM_NAME;
     }
 
-    QString wt = m_oldMainTypeNames.value( mainType );
-    if ( wt == QString() ) {
+    QString typeName = m_oldMainTypeNames.value( mainType );
+    if ( typeName == QString() ) {
         kDebug() << "Unknown old maintype: " << typeSubtypeString;
-        return typeSubtypeString;
+        return 0;
     }
-    return wt;
-}
-
 
-QString KEduVocKvtmlCompability::subTypeFromOldFormat( const QString & typeSubtypeString ) const
-{
-    int i;
-    QString t = typeSubtypeString;
-    if (( i = t.indexOf( KVTML_1_SEPERATOR ) ) >= 0 ) {
-        t.remove( 0, i+1 );
-    } else {
-        return QString();
+    QString subTypeName = m_oldSubTypeNames.value( subType );
+
+    foreach (KEduVocContainer* wordType, parent->childContainers()) {
+        if (wordType->name() == typeName) {
+            if (subType.isEmpty()) {
+                return static_cast<KEduVocWordType*>(wordType);
+            } else {
+                foreach (KEduVocContainer* subWordType, wordType->childContainers()) {
+                    if (subWordType->name() == subTypeName) {
+                        return static_cast<KEduVocWordType*>(subWordType);
+                    }
+                }
+            }
+        }
     }
 
-    QString wt = m_oldSubTypeNames.value( t );
-    if ( wt == QString() ) {
-        kDebug() << "Unknown old maintype: " << typeSubtypeString;
-        return typeSubtypeString;
-    }
-    return wt;
+    return 0;
 }
 
-QString KEduVocKvtmlCompability::oldType( const QString & mainType, const QString & subType ) const
-{
-    QString oldType;
-    QString oldSubType;
-    oldType = m_oldMainTypeNames.key( mainType );
-    oldSubType = m_oldSubTypeNames.key( subType );
-    if ( !oldSubType.isEmpty() ) {
-        return oldType + KVTML_1_SEPERATOR + oldSubType;
+
+
+
+
+
+/*
+if ( type.length() >= 2 && type.left( 1 ) == QM_USER_TYPE ) {
+                // they started counting at 1, we need to know which index we are dealing with:
+                int selfDefinedTypeIndex = type.right( type.count()-1 ).toInt() -1;
+
+                // append invented types (do we not trust our own writer?)
+                if ( selfDefinedTypeIndex >= m_oldSelfDefinedTypes.count() ) {
+                    while ( selfDefinedTypeIndex >= m_oldSelfDefinedTypes.count() ) {
+                        m_oldSelfDefinedTypes.append( i18n( "User defined word type %1", m_oldSelfDefinedTypes.count() - 1 ) );
+                    }
+                }
+                type = m_oldSelfDefinedTypes.value( selfDefinedTypeIndex );
+            } else {
+                type = m_compability.mainTypeFromOldFormat( oldType );
+                subType = m_compability.subTypeFromOldFormat( oldType );
+            } // not user defined - preset types
+
+
+if ( oldType.length() >= 2 && type.left( 1 ) == QM_USER_TYPE ) {
+            // they started counting at 1
+            int selfDefinedTypeIndex = oldType.right( type.count()-1 ).toInt() -1;
+            // append invented types (do we not trust our own writer?)
+            if ( selfDefinedTypeIndex >= m_oldSelfDefinedTypes.count() ) {
+                while ( selfDefinedTypeIndex >= m_oldSelfDefinedTypes.count() ) {
+                    m_oldSelfDefinedTypes.append( i18n( "User defined word type %1", m_oldSelfDefinedTypes.count() - 1 ) );
+                }
+            }
+            type = m_oldSelfDefinedTypes.value( selfDefinedTypeIndex );
+        } else {
+            type = m_compability.mainTypeFromOldFormat( oldType );
+            subType = m_compability.subTypeFromOldFormat( oldType );
+        } // not user defined - preset types
     }
-    return oldType;
+*/
+
 
-}
 
 void KEduVocKvtmlCompability::initOldTenses()
 {
@@ -262,3 +220,40 @@ QString KEduVocKvtmlCompability::oldTense(const QString & tense)
     }
     return m_oldTenses.key(tense);
 }
+
+void KEduVocKvtmlCompability::setupWordTypes(KEduVocWordType * parent)
+{
+    QStringList wordTypeNames;
+    wordTypeNames
+        << i18nc( "The grammatical type of a word", "Verb" )
+        << i18nc( "The grammatical type of a word", "Noun" )
+        << i18nc( "The grammatical type of a word", "Name" )
+        << i18nc( "The grammatical type of a word", "Article" )
+        << i18nc( "The grammatical type of a word", "Adjective" )
+        << i18nc( "The grammatical type of a word", "Adverb" )
+        << i18nc( "The grammatical type of a word", "Pronoun" )
+        << i18nc( "The grammatical type of an entry", "Phrase" )
+        << i18nc( "The grammatical type of a word", "Numeral" )
+        << i18nc( "The grammatical type of a word", "Conjunction" )
+        << i18nc( "The grammatical type of a word", "Preposition" )
+        << i18nc( "The grammatical type of an entry", "Question" );
+
+    foreach (QString typeName, wordTypeNames) {
+        KEduVocWordType* wordType = new KEduVocWordType(typeName, parent);
+        parent->appendChildContainer(wordType);
+        m_userdefinedTypeCounter++;
+    }
+/*
+    m_oldSubTypeNames.insert( "ord", i18nc( "@item:inlistbox A subtype of the grammatical word type: Numeral Ordinal  (one, two, three, ...)","Ordinal" ) );
+    m_oldSubTypeNames.insert( "crd", i18nc( "@item:inlistbox A subtype of the grammatical word type: Numeral Cardinal (first, second, third, ...)","Cardinal" ) );
+    m_oldSubTypeNames.insert( "def", i18nc( "@item:inlistbox A subtype of the grammatical word type: Article (the)","Definite" ) );
+    m_oldSubTypeNames.insert( "ind", i18nc( "@item:inlistbox A subtype of the grammatical word type: Article (a)","Indefinite" ) );
+    m_oldSubTypeNames.insert( "re", i18nc( "@item:inlistbox A subtype of the grammatical word type: Verb with regular conjugation","Regular" ) );
+    m_oldSubTypeNames.insert( "ir", i18nc( "@item:inlistbox A subtype of the grammatical word type: Verb with irregular conjugation","Irregular" ) );
+    m_oldSubTypeNames.insert( "pos", i18nc( "@item:inlistbox A subtype of the grammatical word type: Pronoun (my, your, his, her...)", "Possessive" ) );
+    m_oldSubTypeNames.insert( "per", i18nc( "@item:inlistbox A subtype of the grammatical word type: Pronoun (I, you, he...)", "Personal" ) );
+    m_oldSubTypeNames.insert( "m", i18nc( "@item:inlistbox A subtype of the grammatical word type: Noun", "Male" ) );
+    m_oldSubTypeNames.insert( "f", i18nc( "@item:inlistbox A subtype of the grammatical word type: Noun", "Female" ) );
+    m_oldSubTypeNames.insert( "s", i18nc( "@item:inlistbox A subtype of the grammatical word type: Noun", "Neutral" ) );*/
+}
+
index fe42ab4d5e5245acbe247118cf67ec9156af2e9f..4d05a44089949f24f77818b489c197e68f910400 100644 (file)
@@ -67,6 +67,7 @@
 
 #define UL_USER_USAGE  "#"   // designates number of user type
 
+class KEduVocWordType;
 
 /**
   * @file contains defines and constants necessary for reading kvtml files prior to KDE4. kvtml version 1.
@@ -80,43 +81,13 @@ public:
      */
     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;
-
-    /**
-     * Return set of all available usages. Since the doc also needs them.
-     * @return usage set
-     */
-    QSet<QString> documentUsages() const;
-
     ///// TYPES
     /**
      * Get the type from an old type definition
      * @param typeSubtypeString the old string containing everything
-     * @return new main type
-     */
-    QString mainTypeFromOldFormat( const QString& typeSubtypeString ) const;
-
-    /**
-     * Get the subtype from an old type definition
-     * @param typeSubtypeString the old string containing everything
-     * @return new sub type
+     * @return type
      */
-    QString subTypeFromOldFormat( const QString& typeSubtypeString ) const;
+    KEduVocWordType* typeFromOldFormat(KEduVocWordType* parent, const QString & typeSubtypeString ) const;
 
     /**
      * To write old docs: convert a nice new type to the ugly old style.
@@ -132,27 +103,16 @@ public:
     QStringList documentTenses() const;
     QString oldTense( const QString& tense );
 
-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;
-
-
-    /// only order was decisive, we have to keep count.
-    int m_userdefinedUsageCounter;
+    void setupWordTypes(KEduVocWordType* parent);
 
+private:
 
 //////////// TYPES /////////////////
     void initOldTypeLists();
 
     QMap<QString, QString> m_oldMainTypeNames;
     QMap<QString, QString> m_oldSubTypeNames;
+    int m_userdefinedTypeCounter;
 
 ///////////TENSES/CONJUGATIONS///////
     void initOldTenses();
index 4dc27977acb7f78ec08790d868fe6a42268f5caa..bd934c6ba8c7ec08d6df938e00e4a5d192b25428 100644 (file)
@@ -158,7 +158,8 @@ bool KEduVocKvtmlReader::readBody( QDomElement &domElementParent )
     }
 
     // initialize the list of predefined types
-    m_doc->wordTypes().createDefaultWordTypes();
+    m_compability.setupWordTypes(m_doc->wordTypeContainer());
+
     currentElement = domElementParent.firstChildElement( KV_TYPE_GRP );
     if ( !currentElement.isNull() ) {
         result = readType( currentElement );
@@ -173,13 +174,6 @@ bool KEduVocKvtmlReader::readBody( QDomElement &domElementParent )
             return false;
     }
 
-    currentElement = domElementParent.firstChildElement( KV_USAGE_GRP );
-    if ( !currentElement.isNull() ) {
-        result = readUsage( currentElement );
-        if ( !result )
-            return false;
-    }
-
     QDomNodeList entryList = domElementParent.elementsByTagName( KV_EXPR );
     if ( entryList.length() <= 0 )
         return false;
@@ -224,13 +218,6 @@ bool KEduVocKvtmlReader::readLesson( QDomElement &domElementParent )
                 no = attribute.value().toInt();
             }
 
-            attribute = currentElement.attributeNode( KV_LESS_CURR );
-            if ( !attribute.isNull() ) {
-                if ( no != -1 && attribute.value().toInt() != 0 ) {
-                    m_doc->setCurrentLesson( no );
-                }
-            }
-
             bool inQuery = false;
             attribute = currentElement.attributeNode( KV_LESS_QUERY );
             if ( !attribute.isNull() ) {
@@ -238,8 +225,10 @@ bool KEduVocKvtmlReader::readLesson( QDomElement &domElementParent )
             }
 
             s = currentElement.text();
-            int index = m_doc->appendLesson( s, inQuery );
-            if ( index != no-1 ) {
+            KEduVocLesson* lesson = new KEduVocLesson(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?";
             }
         }
@@ -345,7 +334,7 @@ bool KEduVocKvtmlReader::readArticle( QDomElement &domElementParent )
 }
 
 
-bool KEduVocKvtmlReader::readTranslationConjugations( QDomElement &domElementParent, KEduVocTranslation &translation ) {
+bool KEduVocKvtmlReader::readTranslationConjugations( QDomElement &domElementParent, KEduVocTranslationtranslation ) {
 
     QString tense;
 
@@ -359,7 +348,7 @@ bool KEduVocKvtmlReader::readTranslationConjugations( QDomElement &domElementPar
         tense = m_compability.tenseFromKvtml1( oldShortTense );
         KEduVocConjugation conjugation;
         readConjugation(domElementConjugChild, conjugation);
-        translation.setConjugation(tense, conjugation);
+        translation->setConjugation(tense, conjugation);
 
         domElementConjugChild = domElementConjugChild.nextSiblingElement( KV_CON_TYPE );
     } // while -> next tense, count++
@@ -632,7 +621,8 @@ bool KEduVocKvtmlReader::readType( QDomElement &domElementParent )
 
             kDebug() << "Adding old self defined type: " << currentElement.text();
             // add the type to the list of available types
-            m_doc->wordTypes().addType( currentElement.text() );
+            KEduVocWordType* type = new KEduVocWordType(currentElement.text(), m_doc->wordTypeContainer());
+            m_doc->wordTypeContainer()->appendChildContainer( type );
 
             // from this the #1 are transformed to something sensible again
             m_oldSelfDefinedTypes.append( currentElement.text() );
@@ -662,75 +652,28 @@ bool KEduVocKvtmlReader::readTense( QDomElement &domElementParent )
 }
 
 
-bool KEduVocKvtmlReader::readUsage( QDomElement &domElementParent )
-{
-    // get user defined usages
-
-    QDomElement currentElement;
-
-    QDomNodeList entryList = domElementParent.elementsByTagName( KV_USAGE_DESC );
-    if ( entryList.length() <= 0 ) {
-        return false;
-    }
-
-
-    for ( int i = 0; i < entryList.count(); ++i ) {
-        currentElement = entryList.item( i ).toElement();
-        if ( currentElement.parentNode() == domElementParent ) {
-            m_compability.addUserdefinedUsage( currentElement.text() );
-        }
-    }
-
-    foreach( QString usage, m_compability.documentUsages() ) {
-        m_doc->addUsage( usage );
-    }
-
-    return true;
-}
-
-
-bool KEduVocKvtmlReader::readComparison( QDomElement &domElementParent, KEduVocComparison &comp )
+bool KEduVocKvtmlReader::readComparison( QDomElement &domElementParent, KEduVocTranslation * translation )
 /*
  <comparison>
-   <l1>good</l1>
+   <l1>good</l1> --- this one is dead as it always has to be the word itself
    <l2>better</l2>
    <l3>best</l3>
  </comparison>
 */
 {
-    QString s;
-    comp.clear();
-
     QDomElement currentElement;
 
-    currentElement = domElementParent.firstChildElement( KV_COMP_L1 );
-    if ( !currentElement.isNull() ) {
-        s = currentElement.text();
-        if ( s.isNull() )
-            s = "";
-        comp.setL1( s );
-    }
-
     currentElement = domElementParent.firstChildElement( KV_COMP_L2 );
-    if ( !currentElement.isNull() ) {
-        s = currentElement.text();
-        if ( s.isNull() )
-            s = "";
-        comp.setL2( s );
-    }
+    translation->setComparative(currentElement.text());
 
     currentElement = domElementParent.firstChildElement( KV_COMP_L3 );
-    if ( !currentElement.isNull() ) {
-        s = currentElement.text();
-        if ( s.isNull() )
-            s = "";
-        comp.setL3( s );
-    }
+    translation->setSuperlative(currentElement.text());
+
     return true;
 }
 
 
-bool KEduVocKvtmlReader::readMultipleChoice( QDomElement &domElementParent, KEduVocTranslation &translation )
+bool KEduVocKvtmlReader::readMultipleChoice( QDomElement &domElementParent, KEduVocTranslationtranslation )
 /*
  <multiplechoice>
    <mc1>good</mc1>
@@ -742,39 +685,31 @@ bool KEduVocKvtmlReader::readMultipleChoice( QDomElement &domElementParent, KEdu
 */
 
 {
-    QString s;
-    mc.clear();
-
     QDomElement currentElement;
 
     currentElement = domElementParent.firstChildElement( KV_MC_1 );
     if ( !currentElement.isNull() ) {
-        s = currentElement.text();
-        mc.appendChoice( s );
+        translation->multipleChoice().append( currentElement.text() );
     }
 
     currentElement = domElementParent.firstChildElement( KV_MC_2 );
     if ( !currentElement.isNull() ) {
-        s = currentElement.text();
-        mc.appendChoice( s );
+        translation->multipleChoice().append( currentElement.text() );
     }
 
     currentElement = domElementParent.firstChildElement( KV_MC_3 );
     if ( !currentElement.isNull() ) {
-        s = currentElement.text();
-        mc.appendChoice( s );
+        translation->multipleChoice().append( currentElement.text() );
     }
 
     currentElement = domElementParent.firstChildElement( KV_MC_4 );
     if ( !currentElement.isNull() ) {
-        s = currentElement.text();
-        mc.appendChoice( s );
+        translation->multipleChoice().append( currentElement.text() );
     }
 
     currentElement = domElementParent.firstChildElement( KV_MC_5 );
     if ( !currentElement.isNull() ) {
-        s = currentElement.text();
-        mc.appendChoice( s );
+        translation->multipleChoice().append( currentElement.text() );
     }
 
     return true;
@@ -792,7 +727,6 @@ bool KEduVocKvtmlReader::readExpressionChildAttributes( QDomElement &domElementE
         QString &pronunciation,
         int &width,
         QString &type,
-        QString &subType,
         QString &faux_ami_f,
         QString &faux_ami_t,
         QString &synonym,
@@ -892,35 +826,6 @@ bool KEduVocKvtmlReader::readExpressionChildAttributes( QDomElement &domElementE
     if ( !attribute.isNull() )
         example = attribute.value();
 
-///@todo usages
-
-    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
-          if (num > m_doc->usageDescriptions().count())
-          {
-            // description missing ?
-            QStringList sl = m_doc->usageDescriptions();
-            QString s;
-            for (int i = m_doc->usageDescriptions().count(); i < num; i++)
-            {
-              s.setNum(i + 1);
-              s.prepend("#");  // invent descr according to number
-              sl.append(s);
-            }
-            m_doc->setUsageDescriptions(sl);
-          }
-        }*/
-    }
-
     paraphrase = "";
     attribute = domElementExpressionChild.attributeNode( KV_PARAPHRASE );
     if ( !attribute.isNull() )
@@ -934,21 +839,7 @@ bool KEduVocKvtmlReader::readExpressionChildAttributes( QDomElement &domElementE
     // this is all done by reference - so we have to care about "type" :(
     attribute = domElementExpressionChild.attributeNode( KV_EXPRTYPE );
     if ( !attribute.isNull() ) {
-        QString oldType = attribute.value();
-        if ( oldType.length() >= 2 && type.left( 1 ) == QM_USER_TYPE ) {
-            // they started counting at 1
-            int selfDefinedTypeIndex = oldType.right( type.count()-1 ).toInt() -1;
-            // append invented types (do we not trust our own writer?)
-            if ( selfDefinedTypeIndex >= m_oldSelfDefinedTypes.count() ) {
-                while ( selfDefinedTypeIndex >= m_oldSelfDefinedTypes.count() ) {
-                    m_oldSelfDefinedTypes.append( i18n( "User defined word type %1", m_oldSelfDefinedTypes.count() - 1 ) );
-                }
-            }
-            type = m_oldSelfDefinedTypes.value( selfDefinedTypeIndex );
-        } else {
-            type = m_compability.mainTypeFromOldFormat( oldType );
-            subType = m_compability.subTypeFromOldFormat( oldType );
-        } // not user defined - preset types
+        type = attribute.value();
     }
 
     pronunciation = "";
@@ -984,10 +875,8 @@ bool KEduVocKvtmlReader::readExpression( QDomElement &domElementParent )
     QString                   q_org;
     QString                   q_trans;
     QString                   query_id;
-    int                       lesson = - 1;
     int                       width;
     QString                   type;
-    QString                   subType;
     QString                   faux_ami_f;
     QString                   faux_ami_t;
     QString                   synonym;
@@ -996,14 +885,12 @@ bool KEduVocKvtmlReader::readExpression( QDomElement &domElementParent )
     QSet<QString>             usage;
     QString                   paraphrase;
 
-    KEduVocComparison         comparison;
-    KEduVocMultipleChoice     mc;
-    KEduVocExpression         expr;
-
     QDomAttr                  attribute;
     QDomElement               currentElement;
     QDomElement               currentChild;
 
+    int lessonNumber = -1;
+
     //-------------------------------------------------------------------------
     // Attributes
     //-------------------------------------------------------------------------
@@ -1011,13 +898,15 @@ bool KEduVocKvtmlReader::readExpression( QDomElement &domElementParent )
     attribute = domElementParent.attributeNode( KV_LESS_MEMBER );
     if ( !attribute.isNull() ) {
         // we start conting from 0 in new documents
-        lesson = attribute.value().toInt() - 1;
-        if ( lesson > m_doc->lessonCount() ) {
+        lessonNumber = attribute.value().toInt() - 1;
+        if ( lessonNumber > m_doc->lesson()->childContainerCount() ) {
             ///@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.";
-            m_doc->appendLesson( i18nc("A generic name for a new lesson and its number.", "Lesson %1", lesson ));
+
+            KEduVocLesson* lesson = new KEduVocLesson(i18nc("A generic name for a new lesson and its number.", "Lesson %1", lessonNumber ), m_doc->lesson());
+            m_doc->lesson()->appendChildContainer(lesson);
         }
     }
 
@@ -1036,25 +925,14 @@ bool KEduVocKvtmlReader::readExpression( QDomElement &domElementParent )
     // this is all done by reference - so we have to care about "type" :(
     attribute = domElementParent.attributeNode( KV_EXPRTYPE );
     if ( !attribute.isNull() ) {
-        QString oldType = attribute.value();
-
-        if ( oldType.length() >= 2 && type.left( 1 ) == QM_USER_TYPE ) {
-            // they started counting at 1
-            int selfDefinedTypeIndex = oldType.right( type.count()-1 ).toInt() -1;
-            // append invented types (do we not trust our own writer?)
-            if ( selfDefinedTypeIndex >= m_oldSelfDefinedTypes.count() ) {
-                while ( selfDefinedTypeIndex >= m_oldSelfDefinedTypes.count() ) {
-                    m_oldSelfDefinedTypes.append( i18n( "User defined word type %1", m_oldSelfDefinedTypes.count() - 1 ) );
-                }
-            }
-            type = m_oldSelfDefinedTypes.value( selfDefinedTypeIndex );
-        } else {
-            type = m_compability.mainTypeFromOldFormat( oldType );
-            subType = m_compability.subTypeFromOldFormat( oldType );
-        } // not user defined - preset types
+        type = attribute.value();
     }
 
 
+
+
+
+
     //-------------------------------------------------------------------------
     // Children 'Translation'
     //-------------------------------------------------------------------------
@@ -1071,6 +949,8 @@ bool KEduVocKvtmlReader::readExpression( QDomElement &domElementParent )
         return false;
     }
 
+    KEduVocExpression* entry;
+
     while ( !currentElement.isNull() ) {
 
         //-----------
@@ -1079,27 +959,17 @@ bool KEduVocKvtmlReader::readExpression( QDomElement &domElementParent )
 
         // read attributes - the order of the query grades is interchanged!
         if ( i == 0 && !readExpressionChildAttributes( currentElement, lang, grade, r_grade, qcount, r_qcount, qdate, r_qdate, remark, bcount, r_bcount, query_id,
-                pronunciation, width, type, subType, faux_ami_t, faux_ami_f, synonym, example, antonym, usage, paraphrase ) )
+                pronunciation, width, type, faux_ami_t, faux_ami_f, synonym, example, antonym, usage, paraphrase ) ) {
             return false;
+        }
 
         if ( i != 0 && !readExpressionChildAttributes( currentElement, lang, grade, r_grade, qcount, r_qcount, qdate, r_qdate, remark, bcount, r_bcount, query_id,
-                pronunciation, width, type, subType, faux_ami_f, faux_ami_t, synonym, example, antonym, usage, paraphrase ) )
+                pronunciation, width, type, faux_ami_f, faux_ami_t, synonym, example, antonym, usage, paraphrase ) ) {
             return false;
-
-        if ( m_doc->entryCount() == 0 ) {
-            // only accept in first entry
-            if ( width >= 0 )
-                m_doc->setSizeHint( i, width );
-
-            if ( query_id == KV_O )
-                q_org = lang;
-
-            if ( query_id == KV_T )
-
-                q_trans = lang;
         }
 
-        if ( m_doc->entryCount() == 0 ) { // this is because in kvtml the languages are saved in the FIRST ENTRY ONLY.
+
+        if ( m_doc->lesson()->entriesRecursive().count() == 0 ) { // this is because in kvtml the languages are saved in the FIRST ENTRY ONLY.
 
             // new translation
             if (!addLanguage(i, lang)) {
@@ -1109,81 +979,75 @@ bool KEduVocKvtmlReader::readExpression( QDomElement &domElementParent )
         //---------
         // Children
 
-        currentChild = currentElement.firstChildElement( KV_COMPARISON_GRP );
-        if ( !currentChild.isNull() ) {
-            comparison.clear();
-            if ( !readComparison( currentChild, comparison ) )
-                return false;
-        }
-
-        currentChild = currentElement.firstChildElement( KV_MULTIPLECHOICE_GRP );
-        if ( !currentChild.isNull() ) {
-            mc.clear();
-            if ( !readMultipleChoice( currentChild, mc ) )
-                return false;
-        }
-
         textstr = currentElement.lastChild().toText().data();
 
         if ( i == 0 ) {
-            expr = KEduVocExpression( textstr, lesson );
-            expr.setActive( active );
+            entry = new KEduVocExpression( textstr );
+            entry->setActive( active );
+            if ( lessonNumber != -1 ) {
+                static_cast<KEduVocLesson*>(m_doc->lesson()->childContainer(lessonNumber))->addEntry(entry);
+            } else {
+                m_doc->lesson()->addEntry(entry);
+            }
         } else {
-            expr.setTranslation( i, textstr );
+            entry->setTranslation( i, textstr );
         }
 
         // better make sure, translation(i) already exists...
         currentChild = currentElement.firstChildElement( KV_CONJUG_GRP );
         if ( !currentChild.isNull() ) {
-            if ( !readTranslationConjugations( currentChild, expr.translation(i) ) ) {
+            if ( !readTranslationConjugations( currentChild, entry->translation(i) ) ) {
                 return false;
             }
         }
 
-        if ( !comparison.isEmpty() ) {
-            expr.translation( i ).setComparison( comparison );
-            comparison.clear();
+        currentChild = currentElement.firstChildElement( KV_MULTIPLECHOICE_GRP );
+        if ( !currentChild.isNull() ) {
+            if ( !readMultipleChoice( currentChild, entry->translation(i) ) ) {
+                return false;
+            }
         }
-        if ( !mc.isEmpty() ) {
-            expr.translation( i ).setMultipleChoice( mc );
-            mc.clear();
+
+        currentChild = currentElement.firstChildElement( KV_COMPARISON_GRP );
+        if ( !currentChild.isNull() ) {
+            if ( !readComparison( currentChild, entry->translation(i) ) ) {
+                return false;
+            }
         }
 
         if ( !type.isEmpty() ) {
-            expr.translation( i ).setType( type );
-            if ( !subType.isEmpty() ) {
-                expr.translation( i ).setSubType( subType );
-            }
+            KEduVocWordType* wordType = m_compability.typeFromOldFormat(m_doc->wordTypeContainer(), type);
+            entry->translation(i)->setWordType(wordType);
         }
 
         if ( !remark.isEmpty() )
-            expr.translation( i ).setComment( remark );
+            entry->translation( i )->setComment( remark );
         if ( !pronunciation.isEmpty() )
-            expr.translation( i ).setPronunciation( pronunciation );
+            entry->translation( i )->setPronunciation( pronunciation );
         if ( !faux_ami_f.isEmpty() )
-            expr.translation( i ).setFalseFriend( 0, faux_ami_f );
+            entry->translation( i )->setFalseFriend( 0, faux_ami_f );
         if ( !faux_ami_t.isEmpty() )
-            expr.translation( 0 ).setFalseFriend( i, faux_ami_t );
+            entry->translation( 0 )->setFalseFriend( i, faux_ami_t );
         if ( !synonym.isEmpty() )
-            expr.translation( i ).setSynonym( synonym );
+            entry->translation( i )->setSynonym( synonym );
         if ( !example.isEmpty() )
-            expr.translation( i ).setExample( example );
+            entry->translation( i )->setExample( example );
         if ( !usage.isEmpty() )
-            expr.translation( i ).setUsages( usage );
+            entry->translation( i )->setUsages( usage );
         if ( !paraphrase.isEmpty() )
-            expr.translation( i ).setParaphrase( paraphrase );
+            entry->translation( i )->setParaphrase( paraphrase );
         if ( !antonym.isEmpty() )
-            expr.translation( i ).setAntonym( antonym );
+            entry->translation( i )->setAntonym( antonym );
 
         if ( i != 0 ) {
-            expr.translation( i ).gradeFrom( 0 ).setGrade( grade );
-            expr.translation( 0 ).gradeFrom( i ).setGrade( r_grade );
-            expr.translation( i ).gradeFrom( 0 ).setPracticeCount( qcount );
-            expr.translation( 0 ).gradeFrom( i ).setPracticeCount( r_qcount );
-            expr.translation( i ).gradeFrom( 0 ).setBadCount( bcount );
-            expr.translation( 0 ).gradeFrom( i ).setBadCount( r_bcount );
-            expr.translation( i ).gradeFrom( 0 ).setPracticeDate( qdate );
-            expr.translation( 0 ).gradeFrom( i ).setPracticeDate( r_qdate );
+            entry->translation( i )->gradeFrom( 0 ).setGrade( grade );
+            entry->translation( 0 )->gradeFrom( i ).setGrade( r_grade );
+            entry->translation( i )->gradeFrom( 0 ).setPracticeCount( qcount );
+            entry->translation( 0 )->gradeFrom( i ).setPracticeCount( r_qcount );
+            entry->translation( i )->gradeFrom( 0 ).setBadCount( bcount );
+            entry->translation( 0 )->gradeFrom( i ).setBadCount( r_bcount );
+            entry->translation( i )->gradeFrom( 0 ).setPracticeDate( qdate );
+            entry->translation( 0 )->gradeFrom( i ).setPracticeDate( r_qdate );
         }
 
         // Next translation
@@ -1191,11 +1055,6 @@ bool KEduVocKvtmlReader::readExpression( QDomElement &domElementParent )
         i++;
     }
 
-//     if ( m_doc->entryCount() == 0 ) {
-//         m_doc->setQueryIdentifier( q_org, q_trans );
-//     }
-    m_doc->appendEntry( &expr );
-
     return true;
 }
 
index 38d5a64986e91efc4a0ad45e432ce7ebf4054a12..d59a7dd99bda93c8323c45c7f7b289e6b6943cd9 100644 (file)
@@ -58,12 +58,12 @@ public:
     bool readArticle( QDomElement &domElementParent );
     bool readPersonalPronouns( QDomElement &domElementParent, KEduVocPersonalPronoun& pronouns );
     bool readConjugation( QDomElement &domElementParent, KEduVocConjugation &conjugation );
-    bool readTranslationConjugations( QDomElement &domElementParent, KEduVocTranslation &translation );
+    bool readTranslationConjugations( QDomElement &domElementParent, KEduVocTranslationtranslation );
     bool readType( QDomElement &domElementParent );
     bool readTense( QDomElement &domElementParent );
     bool readUsage( QDomElement &domElementParent );
     bool readComparison( QDomElement &domElementParent, KEduVocTranslation* translation );
-    bool readMultipleChoice( QDomElement &domElementParent, KEduVocMultipleChoice &mc );
+    bool readMultipleChoice( QDomElement &domElementParent, KEduVocTranslation* translation );
     bool readExpressionChildAttributes( QDomElement &domElementExpressionChild,
                                         QString &lang,
                                         grade_t &grade, grade_t &rev_grade,
@@ -75,7 +75,6 @@ public:
                                         QString &pronunciation,
                                         int &width,
                                         QString &type,
-                                        QString &subType,
                                         QString &faux_ami_f,
                                         QString &faux_ami_t,
                                         QString &synonym,
index be4b32bdc2044f1488c605f5ecdc0d938645bd0d..1067b3b5bc23950f5b1422d4bcc0863c6fab84ba 100644 (file)
@@ -77,15 +77,6 @@ KEduVocTranslation * KEduVocWordType::translation(int row)
     return d->m_translations.value(row);
 }
 
-// KEduVocWordType * KEduVocWordType::parent()
-// {
-//     if(KEduVocContainer::parent()) {
-//         ///@todo check if it is a word type container?
-//         return static_cast<KEduVocWordType*>(KEduVocContainer::parent());
-//     }
-//     return 0;
-// }
-
 KEduVocExpression * KEduVocWordType::entry(int row)
 {
     return entries().value(row);