r14392 by jghali - #8606 related : better error reporting when loading file fail

scribus-commit scribus-commit at lists.scribus.net
Thu Dec 10 01:20:45 CET 2009


Revision: 14392
Author: jghali
Date: 2009-12-09T13:34:55.177370Z
Commit message: #8606 related : better error reporting when loading file fail

Changeset: 
M  /trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.cpp
M  /trunk/Scribus/scribus/scplugin.h
M  /trunk/Scribus/scribus/loadsaveplugin.cpp
M  /trunk/Scribus/scribus/plugins/fileloader/scribus134format/scribus134format.cpp
M  /trunk/Scribus/scribus/loadsaveplugin.h
M  /trunk/Scribus/scribus/plugins/fileloader/scribus12format/scribus12format.cpp
M  /trunk/Scribus/scribus/scplugin.cpp
M  /trunk/Scribus/scribus/plugins/fileloader/scribus13format/scribus13format.cpp

Diffs:
Index: scribus/loadsaveplugin.h
===================================================================
--- scribus/loadsaveplugin.h	(revision 14391)
+++ scribus/loadsaveplugin.h	(revision 14392)
@@ -114,6 +114,9 @@
 
 		/// Unregister all formats owned by the calling plugin
 		void unregisterAll();
+
+		// Set standard message for dom style errors with line and column
+		virtual void setDomParsingError(const QString& msg, int line, int column);
 		
 		ScribusDoc*        m_Doc;
 		ScribusView*       m_View; //For 1.2.x loader at the moment
Index: scribus/scplugin.h
===================================================================
--- scribus/scplugin.h	(revision 14391)
+++ scribus/scplugin.h	(revision 14392)
@@ -196,6 +196,12 @@
 		 */
 		const QString & lastError() const;
 
+		//! \brief Returns if lastError message is not empty
+		bool hasLastError() const;
+
+		//! \brief Clear last error message
+		void clearLastError();
+
 		/*! @brief Update all user-visible text to reflect current UI language
 		 *
 		 * Updates the text on all widgets on the plug-in to reflect the new
Index: scribus/loadsaveplugin.cpp
===================================================================
--- scribus/loadsaveplugin.cpp	(revision 14391)
+++ scribus/loadsaveplugin.cpp	(revision 14392)
@@ -5,8 +5,8 @@
 for which a new license (GPL+exception) is in place.
 */
 #include "loadsaveplugin.h"
-//#include "loadsaveplugin.moc"
-//Added by qt3to4:
+#include "commonstrings.h"
+#include "scribuscore.h"
 #include <QList>
 
 QList<FileFormat> LoadSavePlugin::formats;
@@ -88,6 +88,11 @@
 	return false;
 }
 
+void LoadSavePlugin::setDomParsingError(const QString& msg, int line, int column)
+{
+	m_lastError = tr("An error occured while parsing file at line %1, column %2 :\n%3").arg(line).arg(column).arg(msg);
+}
+
 const QString& LoadSavePlugin::lastSavedFile(void)
 {
 	return m_lastSavedFile;
@@ -253,7 +258,25 @@
 
 bool FileFormat::loadFile(const QString & fileName, int flags, int index) const
 {
-	return (plug && load) ? plug->loadFile(fileName, *this, flags, index) : false;
+	if (plug && load)
+	{
+		plug->clearLastError();
+		bool success = plug->loadFile(fileName, *this, flags, index);
+		if (!success && plug->hasLastError())
+		{
+			if (ScCore->usingGUI())
+			{
+				QMessageBox::warning(ScCore->primaryMainWindow(), CommonStrings::trWarning,
+				                     plug->lastError(), CommonStrings::tr_OK);
+			}
+			else
+			{
+				qDebug() << plug->lastError();
+			}
+		}
+		return success;
+	}
+	return false;
 }
 
 bool FileFormat::saveFile(const QString & fileName) const
@@ -282,7 +305,25 @@
 
 bool FileFormat::loadPage(const QString & fileName, int pageNumber, bool Mpage, QString renamedPageName) const
 {
-	return (plug && load) ? plug->loadPage(fileName, pageNumber, Mpage, renamedPageName) : false;
+	if (plug && load)
+	{
+		plug->clearLastError();
+		bool success = plug->loadPage(fileName, pageNumber, Mpage, renamedPageName);
+		if (!success && plug->hasLastError())
+		{
+			if (ScCore->usingGUI())
+			{
+				QMessageBox::warning(ScCore->primaryMainWindow(), CommonStrings::trWarning,
+				                     plug->lastError(), CommonStrings::tr_OK);
+			}
+			else
+			{
+				qDebug() << plug->lastError();
+			}
+		}
+		return success;
+	}
+	return false;
 }
 
 bool FileFormat::readStyles(const QString& fileName, ScribusDoc* doc, StyleSet<ParagraphStyle> &docParagraphStyles) const
Index: scribus/scplugin.cpp
===================================================================
--- scribus/scplugin.cpp	(revision 14391)
+++ scribus/scplugin.cpp	(revision 14392)
@@ -9,8 +9,8 @@
 #include "deferredtask.h"
 #include "scribus.h"
 #include "scribusapp.h"
+#include "selection.h"
 #include "ui/prefspanel.h"
-#include "selection.h"
 
 //=====================================================//
 //                        ScPlugin                     //
@@ -38,6 +38,16 @@
 	return m_lastError;
 }
 
+bool ScPlugin::hasLastError() const
+{
+	return (!m_lastError.isEmpty());
+}
+
+void ScPlugin::clearLastError()
+{
+	m_lastError.clear();
+}
+
 const QString ScPlugin::pluginTypeName() const
 {
 	// These tests must be in reverse order of inheritance,
Index: scribus/plugins/fileloader/scribus12format/scribus12format.cpp
===================================================================
--- scribus/plugins/fileloader/scribus12format/scribus12format.cpp	(revision 14391)
+++ scribus/plugins/fileloader/scribus12format/scribus12format.cpp	(revision 14392)
@@ -230,8 +230,13 @@
 	if (f.isEmpty())
 		return false;
 	// Build the DOM from it
-	if (!docu.setContent(f))
+	QString errorMsg;
+	int errorLine, errorColumn;
+	if (!docu.setContent(f, &errorMsg, &errorLine, &errorColumn))
+	{
+		setDomParsingError(errorMsg, errorLine, errorColumn);
 		return false;
+	}
 	// Get file directory
 	QString fileDir = QFileInfo(fileName).absolutePath();
 	// and begin loading the doc
@@ -1193,8 +1198,13 @@
 	QString f(readSLA(fileName));
 	if (f.isEmpty())
 		return false;
-	if(!docu.setContent(f))
+	QString errorMsg;
+	int errorLine, errorColumn;
+	if (!docu.setContent(f, &errorMsg, &errorLine, &errorColumn))
+	{
+		setDomParsingError(errorMsg, errorLine, errorColumn);
 		return false;
+	}
 	QString fileDir = QFileInfo(fileName).absolutePath();
 	ScColor lf = ScColor();
 	QDomElement elem=docu.documentElement();
Index: scribus/plugins/fileloader/scribus13format/scribus13format.cpp
===================================================================
--- scribus/plugins/fileloader/scribus13format/scribus13format.cpp	(revision 14391)
+++ scribus/plugins/fileloader/scribus13format/scribus13format.cpp	(revision 14392)
@@ -199,8 +199,13 @@
 	QString fileDir = QFileInfo(fileName).absolutePath();
 	/* 2004/10/02 - petr vanek - bug #1092 - missing <PAGE> crash Scribus. The check constraint moved into IsScribus()
 	FIXME: I've add test on containig tag PAGE but returning false freezes S. in scribus.cpp need some hack too...  */
-	if (!docu.setContent(f))
+	QString errorMsg;
+	int errorLine, errorColumn;
+	if (!docu.setContent(f, &errorMsg, &errorLine, &errorColumn))
+	{
+		setDomParsingError(errorMsg, errorLine, errorColumn);
 		return false;
+	}
 	m_Doc->PageColors.clear();
 	m_Doc->Layers.clear();
 	int layerToSetActive=0;
@@ -2620,8 +2625,13 @@
  	QString f(readSLA(fileName));
 	if (f.isEmpty())
 		return false;
-	if(!docu.setContent(f))
+	QString errorMsg;
+	int errorLine, errorColumn;
+	if (!docu.setContent(f, &errorMsg, &errorLine, &errorColumn))
+	{
+		setDomParsingError(errorMsg, errorLine, errorColumn);
 		return false;
+	}
 	QString fileDir = QFileInfo(fileName).absolutePath();
 	ScColor lf = ScColor();
 	QDomElement elem=docu.documentElement();
Index: scribus/plugins/fileloader/scribus150format/scribus150format.cpp
===================================================================
--- scribus/plugins/fileloader/scribus150format/scribus150format.cpp	(revision 14391)
+++ scribus/plugins/fileloader/scribus150format/scribus150format.cpp	(revision 14392)
@@ -451,7 +451,10 @@
 	}
 
 	if (reader.hasError())
+	{
+		setDomParsingError(reader.errorString(), reader.lineNumber(), reader.columnNumber());
 		return false;
+	}
 
 	QMap<int, ScribusDoc::BookMa>::Iterator it;
 	for (it = bookmarks.begin(); it != bookmarks.end(); ++it)
@@ -3186,7 +3189,10 @@
 	}
 
 	if (reader.hasError())
+	{
+		setDomParsingError(reader.errorString(), reader.lineNumber(), reader.columnNumber());
 		return false;
+	}
 
 	QMap<int, ScribusDoc::BookMa>::Iterator it;
 	for (it = bookmarks.begin(); it != bookmarks.end(); ++it)
Index: scribus/plugins/fileloader/scribus134format/scribus134format.cpp
===================================================================
--- scribus/plugins/fileloader/scribus134format/scribus134format.cpp	(revision 14391)
+++ scribus/plugins/fileloader/scribus134format/scribus134format.cpp	(revision 14392)
@@ -442,7 +442,10 @@
 	}
 
 	if (reader.hasError())
+	{
+		setDomParsingError(reader.errorString(), reader.lineNumber(), reader.columnNumber());
 		return false;
+	}
 
 	QMap<int, ScribusDoc::BookMa>::Iterator it;
 	for (it = bookmarks.begin(); it != bookmarks.end(); ++it)
@@ -3150,7 +3153,10 @@
 	}
 
 	if (reader.hasError())
+	{
+		setDomParsingError(reader.errorString(), reader.lineNumber(), reader.columnNumber());
 		return false;
+	}
 
 	QMap<int, ScribusDoc::BookMa>::Iterator it;
 	for (it = bookmarks.begin(); it != bookmarks.end(); ++it)




More information about the scribus-commit mailing list