[prev in list] [next in list] [prev in thread] [next in thread] 

List:       koffice-devel
Subject:    [PATCH] KoDocument::loadNative and QDomDocument::setContent
From:       Nicolas Goutte <nicog () snafu ! de>
Date:       2001-11-30 23:33:08
[Download RAW message or body]

The attached patch is for the file lib/kofficecore/koDocument.cc

The new code takes care about the return value of QDomDocument::setContent 
and aborts in case of error.

Information about the error is given through kdError and to the user. The 
user only sees where in the file the parsing error has been but he does not 
see the error message given by QT, as this message is not translated. The 
kdError output however also contains his error message.

Have a nice day/evening/night!


["patch_koDocument_cc.txt" (text/x-diff)]

--- koDocument.cc.orig	Sat Nov 17 21:56:59 2001
+++ koDocument.cc	Sat Dec  1 00:10:05 2001
@@ -910,11 +910,26 @@
   if ( strncasecmp( buf, "<?xm", 4 ) == 0 )
   {
     in.at(0);
+    QString errorMsg;
+    int errorLine;
+    int errorColumn;
     QDomDocument doc;
-    doc.setContent( &in );
-    bool res = loadXML( &in, doc );
-    if ( res )
-      res = completeLoading( 0L );
+    bool res;
+    if ( doc.setContent( &in , &errorMsg, &errorLine, &errorColumn ) )
+    {
+      res = loadXML( &in, doc );
+      if ( res )
+        res = completeLoading( 0L );
+    }
+    else
+    {
+        kdError (30003) << "Parsing Error! Aborting! (in \
KoDocument::loadNativeFormat (QFile))" << endl +          << "  Line: " << errorLine \
<< " Column: " << errorColumn << endl +          << "  Message: " << errorMsg << \
endl; +        d->lastErrorMessage = i18n( "Parsing error in file at line %1, column \
%2" ) +          .arg( errorLine ).arg( errorColumn );
+        res=false;
+    }
 
     QApplication::restoreOverrideCursor();
     in.close();
@@ -935,8 +950,21 @@
 
     if ( store->open( "root" ) )
     {
+      QString errorMsg;
+      int errorLine;
+      int errorColumn;
       QDomDocument doc;
-      doc.setContent( store->device() );
+      if ( !doc.setContent( store->device(), &errorMsg, &errorLine, &errorColumn ) )
+      {
+        kdError (30003) << "Parsing Error! Aborting! (in \
KoDocument::loadNativeFormat (KoStore))" << endl +          << "  Line: " << \
errorLine << " Column: " << errorColumn << endl +          << "  Message: " << \
errorMsg << endl; +        d->lastErrorMessage = i18n( "Parsing error in file at line \
%1, column %2" ) +          .arg( errorLine ).arg( errorColumn );
+        delete store;
+        QApplication::restoreOverrideCursor();
+        return false;
+      }
       if ( !loadXML( store->device(), doc ) )
       {
         delete store;


_______________________________________________
koffice-devel mailing list
koffice-devel@mail.kde.org
http://mail.kde.org/mailman/listinfo/koffice-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic