]> Git trees. - libqmvoc.git/commitdiff
Cleanup and work on the kvtml reader
authorPeter Hedlund <peter@peterandlinda.com>
Wed, 21 Feb 2007 23:46:37 +0000 (23:46 +0000)
committerPeter Hedlund <peter@peterandlinda.com>
Wed, 21 Feb 2007 23:46:37 +0000 (23:46 +0000)
svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=636119

kdeeducore/keduvoccsvreader.cpp
kdeeducore/keduvocdocument.cpp
kdeeducore/keduvocdocument.h
kdeeducore/keduvockvtmlreader.cpp
kdeeducore/keduvockvtmlreader.h

index 4c644a1be6cfbf4c8fb6650a959c3946dee7bd34..a7b2414899b154fb43010ed9cd7e6c079c39928f 100644 (file)
@@ -42,6 +42,7 @@ bool KEduVocCsvReader::readDoc(KEduVocDocument *doc)
 {
   m_doc = doc;
 
+  ///@todo handle more delimiters
   QString separator = QString(",");
 
   QTextStream inputStream(m_inputFile);
index 90ff4615d41c0b45af9eca9b336c5d448b8d7ea3..dd96fd4de95ba6ce31d2bf39a0cea32cbdbeb597 100644 (file)
@@ -106,8 +106,6 @@ void KEduVocDocument::Init ()
   m_vocabulary.clear();
   m_dirty = false;
   m_sortingEnabled = true;
-  m_unknownAttribute = false;
-  m_unknownElement = false;
   m_sortLesson = false;
   setCurrentLesson (0);
   m_queryorg = "";
@@ -117,6 +115,7 @@ void KEduVocDocument::Init ()
   m_author = "";
   m_remark = "";
   m_version = "";
+  m_generator = "";
   m_font = NULL;
 
   m_activeLeitnerSystem = false;
@@ -203,6 +202,8 @@ bool KEduVocDocument::open(const KUrl& url, bool /*append*/)
         {
           KEduVocKvtmlReader kvtmlReader(f);
           read = kvtmlReader.readDoc(this);
+          if (!read)
+            errorMessage = kvtmlReader.errorMessage();
         }
         break;
 
@@ -246,16 +247,14 @@ bool KEduVocDocument::open(const KUrl& url, bool /*append*/)
         {
           KEduVocKvtmlReader kvtmlReader(f);
           read = kvtmlReader.readDoc(this);
+          if (!read)
+            errorMessage = kvtmlReader.errorMessage();
         }
       }
 
       QApplication::restoreOverrideCursor();
 
       if (!read) {
-        if (m_unknownAttribute || m_unknownElement ) {
-          Init();
-          return false;
-        }
         QString msg = i18n("Could not open \"%1\"\nDo you want to try again?\n(Error reported: %2)", url.path(), errorMessage);
         int result = KMessageBox::warningContinueCancel(0, msg, i18n("Error Opening File"), KGuiItem(i18n("&Retry")));
         if (result == KMessageBox::Cancel) {
index 9f456020b5133da83764e7a70e7c6e42cee01773..3e15fe9e1700f12bba83ba9b7b52e0fdf788c8c4 100644 (file)
@@ -250,7 +250,6 @@ class KDEEDUCORE_EXPORT KEduVocDocument : public QObject
   Q_OBJECT
   friend class KEduVocKvtmlWriter;
   friend class KEduVocKvtmlReader;
-  friend class KEduVocWqlReader;
 
 public:
 
@@ -745,37 +744,11 @@ protected:
    */
   void setVersion(const QString & ver);
 
-  /* TODO
-  bool saveToLex     (QTextStream& os, QString &title);
-  bool loadFromLex   (QTextStream& is);
-  bool loadLessonLex (QTextStream& is);
-  bool saveLessonLex (QTextStream& os);
-  bool saveTypeNameLex   (QTextStream& os);
-  bool loadTypeNameLex   (QTextStream& is);
-
-  bool saveToCsv     (QTextStream& os, QString &title);
-  bool loadFromCsv   (QTextStream& is);
-  bool loadLessonCsv (QTextStream& is);
-  bool saveLessonCsv (QTextStream& os);
-  bool saveTypeNameCsv   (QTextStream& os);
-  bool loadTypeNameCsv   (QTextStream& is);
-
-  bool saveTypeNameVcb (QTextStream &os);
-  bool loadTypeNameVcb (QTextStream &is);
-  bool saveLessonVcb (QTextStream &os);
-  bool loadLessonVcb (QTextStream &is);
-  bool saveToVcb (QTextStream& os, QString &title);
-  bool loadFromVcb (QTextStream& is);
-  void errorVcb (int line, const QString &text );
-  */
-
- private:
+private:
   bool                      m_dirty;
   KUrl                      m_url;
   QList<bool>               m_sortIdentifier;
   bool                      m_sortLesson;
-  bool                      m_unknownAttribute;
-  bool                      m_unknownElement;
   bool                      m_sortingEnabled;
 
   // save these to document
index 4d306b5f938e0a908048ecb4823985ce45943204..e7a01800cc13ef3ec20bb7a20f5cadbaa0580cf8 100644 (file)
@@ -31,6 +31,97 @@ KEduVocKvtmlReader::KEduVocKvtmlReader(QIODevice *file)
 {
   // the file must be already open
   m_inputFile = file;
+  m_errorMessage = "";
+}
+
+
+bool KEduVocKvtmlReader::readDoc(KEduVocDocument *doc)
+{
+  m_doc = doc;
+  m_doc->m_cols = 0;
+  m_doc->m_lines = 0;
+
+  QDomDocument domDoc("Kvtml");
+
+  if (!domDoc.setContent(m_inputFile, &m_errorMessage))
+    return false;
+
+  QDomElement domElementKvtml = domDoc.documentElement();
+  if( domElementKvtml.tagName() != KV_DOCTYPE )
+  {
+    domError(i18n("Tag <%1> was expected "
+            "but tag <%2> was read." , QString(KV_DOCTYPE), domElementKvtml.tagName()));
+    return false;
+  }
+
+  //-------------------------------------------------------------------------
+  // Attributes
+  //-------------------------------------------------------------------------
+
+  QDomAttr domAttrEncoding = domElementKvtml.attributeNode(KV_ENCODING);
+  if (!domAttrEncoding.isNull())
+  {
+    // TODO handle old encodings
+    // Qt DOM API autodetects encoding, so is there anything to do ?
+  }
+
+  QDomAttr domAttrTitle = domElementKvtml.attributeNode(KV_TITLE);
+  if (!domAttrTitle.isNull())
+  {
+    m_doc->m_title = domAttrTitle.value();
+  }
+
+  QDomAttr domAttrAuthor = domElementKvtml.attributeNode(KV_AUTHOR);
+  if (!domAttrAuthor.isNull())
+  {
+    m_doc->m_author = domAttrAuthor.value();
+  }
+
+  QDomAttr domAttrLicence = domElementKvtml.attributeNode(KV_LICENSE);
+  if (!domAttrLicence.isNull())
+  {
+    m_doc->m_license = domAttrLicence.value();
+  }
+
+  QDomAttr domAttrRemark = domElementKvtml.attributeNode(KV_DOC_REM);
+  if (!domAttrRemark.isNull())
+  {
+    m_doc->m_remark = domAttrRemark.value();
+  }
+
+  QDomAttr domAttrGenerator = domElementKvtml.attributeNode(KV_GENERATOR);
+  if (!domAttrGenerator.isNull())
+  {
+    m_doc->m_generator = domAttrGenerator.value();
+    int pos = m_doc->m_generator.lastIndexOf(KVD_VERS_PREFIX);
+    if (pos >= 0)
+    {
+      m_doc->m_version = m_doc->m_generator;
+      m_doc->m_version.remove (0, pos+2);
+    }
+  }
+
+  QDomAttr domAttrCols = domElementKvtml.attributeNode(KV_COLS);
+  if (!domAttrCols.isNull())
+  {
+    m_doc->m_cols = domAttrCols.value().toInt();
+  }
+
+  QDomAttr domAttrLines = domElementKvtml.attributeNode(KV_LINES);
+  if (!domAttrLines.isNull())
+  {
+    m_doc->m_lines = domAttrLines.value().toInt();
+  }
+
+
+  //-------------------------------------------------------------------------
+  // Children
+  //-------------------------------------------------------------------------
+
+  bool result = readBody(domElementKvtml);  // read vocabulary
+
+  // TODO EPT setModified (false);
+  return result;
 }
 
 
@@ -1550,109 +1641,6 @@ if (lines != 0)
 }
 
 
-bool KEduVocKvtmlReader::readDoc(KEduVocDocument *doc)
-{
-  m_doc = doc;
-
-  QDomDocument domDoc("Kvtml" );
-  QString errorMsg;
-  if( !domDoc.setContent( m_inputFile, &errorMsg ) )
-  {
-    domError(errorMsg);
-    return false;
-  }
-
-  m_doc->m_identifiers.clear();
-  m_doc->m_vocabulary.clear();
-
-  m_doc->m_generator = "";
-  m_doc->m_cols = 0;
-  m_doc->m_lines = 0;
-  m_doc->m_title = "";
-  m_doc->m_author = "";
-  m_doc->m_license = "";
-  m_doc->m_remark = "";
-
-
-  QDomElement domElementKvtml = domDoc.documentElement();
-  if( domElementKvtml.tagName() != KV_DOCTYPE )
-  {
-    domError(i18n("Tag <%1> was expected "
-            "but tag <%2> was read." , QString(KV_DOCTYPE), domElementKvtml.tagName()));
-    return false;
-  }
-
-  //-------------------------------------------------------------------------
-  // Attributes
-  //-------------------------------------------------------------------------
-
-  QDomAttr domAttrEncoding = domElementKvtml.attributeNode(KV_ENCODING);
-  if (!domAttrEncoding.isNull())
-  {
-    // TODO handle old encodings
-    // Qt DOM API autodetects encoding, so is there anything to do ?
-  }
-
-  QDomAttr domAttrTitle = domElementKvtml.attributeNode(KV_TITLE);
-  if (!domAttrTitle.isNull())
-  {
-    m_doc->m_title = domAttrTitle.value();
-  }
-
-  QDomAttr domAttrAuthor = domElementKvtml.attributeNode(KV_AUTHOR);
-  if (!domAttrAuthor.isNull())
-  {
-    m_doc->m_author = domAttrAuthor.value();
-  }
-
-  QDomAttr domAttrLicence = domElementKvtml.attributeNode(KV_LICENSE);
-  if (!domAttrLicence.isNull())
-  {
-    m_doc->m_license = domAttrLicence.value();
-  }
-
-  QDomAttr domAttrRemark = domElementKvtml.attributeNode(KV_DOC_REM);
-  if (!domAttrRemark.isNull())
-  {
-    m_doc->m_remark = domAttrRemark.value();
-  }
-
-  QDomAttr domAttrGenerator = domElementKvtml.attributeNode(KV_GENERATOR);
-  if (!domAttrGenerator.isNull())
-  {
-    m_doc->m_generator = domAttrGenerator.value();
-    int pos = m_doc->m_generator.lastIndexOf(KVD_VERS_PREFIX);
-    if (pos >= 0)
-    {
-      m_doc->m_version = m_doc->m_generator;
-      m_doc->m_version.remove (0, pos+2);
-    }
-  }
-
-  QDomAttr domAttrCols = domElementKvtml.attributeNode(KV_COLS);
-  if (!domAttrCols.isNull())
-  {
-    m_doc->m_cols = domAttrCols.value().toInt();
-  }
-
-  QDomAttr domAttrLines = domElementKvtml.attributeNode(KV_LINES);
-  if (!domAttrLines.isNull())
-  {
-    m_doc->m_lines = domAttrLines.value().toInt();
-  }
-
-
-  //-------------------------------------------------------------------------
-  // Children
-  //-------------------------------------------------------------------------
-
-  bool result = readBody(domElementKvtml);  // read vocabulary
-
-  // TODO EPT setModified (false);
-  return result;
-}
-
-
 void KEduVocKvtmlReader::domErrorUnknownElement(const QString &elem)
 {
   QString ln = i18n("File:\t%1\n", m_doc->URL().path());
index 1ad52570df77f13d8bb2886691d5f2100224c4a6..618968a63cea5fead9c623d54aa7473735e872b2 100644 (file)
@@ -111,9 +111,12 @@ public:
   void domErrorUnknownElement(const QString &elem);
   void domError(const QString &text );
 
+  QString errorMessage() const {return m_errorMessage;};
+
 private:
   QIODevice *m_inputFile;
   KEduVocDocument *m_doc;
+  QString m_errorMessage;
 };
 
 #endif