]> Git trees. - libqmvoc.git/commitdiff
be more tolerant when reading kvtml
authorFrederik Gladhorn <gladhorn@kde.org>
Thu, 25 Jun 2009 12:30:21 +0000 (12:30 +0000)
committerFrederik Gladhorn <gladhorn@kde.org>
Thu, 25 Jun 2009 12:30:21 +0000 (12:30 +0000)
entries without translation would crash
<entry id="123" />
BUG: 191485

svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=987047

keduvocdocument/keduvockvtml2reader.cpp

index 3aa8beada97c2158178a3e0142054a4b9afdbe08..30b6ce4521b543106ef92fabab2488d5b123a815 100644 (file)
@@ -303,14 +303,8 @@ bool KEduVocKvtml2Reader::readEntry( QDomElement &entryElement )
         }
     }
 
-
     // read translation children
     QDomNodeList translationList = entryElement.elementsByTagName( KVTML_TRANSLATION );
-    if ( translationList.length() <= 0 ) {
-        delete expr;
-        m_errorMessage = i18n( "no translations found" );
-        return false; // at least one translation is required
-    }
 
     for ( int i = 0; i < translationList.count(); ++i ) {
         currentElement = translationList.item( i ).toElement();
@@ -321,6 +315,13 @@ bool KEduVocKvtml2Reader::readEntry( QDomElement &entryElement )
         }
     }
 
+    if ( expr->translationIndices().size() == 0 ) {
+        kDebug() << "Found entry with no words in it." << id;
+        expr->setTranslation(0, QString());
+    }
+
+    Q_ASSERT(expr);
+
     // TODO: probably should insert at id position with a check to see if it exists
     // may be useful for detecting corrupt documents
     m_allEntries[id] = expr;
@@ -398,7 +399,9 @@ bool KEduVocKvtml2Reader::readLesson( KEduVocLesson* parentLesson, QDomElement &
         bool result = false;
         int entryId = currentElement.attribute( KVTML_ID ).toInt( &result );
         if(result) {
-            lesson->appendEntry( m_allEntries[entryId] );
+            if (m_allEntries[entryId]) {
+                lesson->appendEntry( m_allEntries[entryId] );
+            }
         }
         currentElement = currentElement.nextSiblingElement( KVTML_ENTRY );
     }