r14391 by jghali - #8606 related : better error reporting when loading file fail
scribus-commit
scribus-commit at lists.scribus.net
Thu Dec 10 01:15:40 CET 2009
Revision: 14391
Author: jghali
Date: 2009-12-09T13:32:47.096845Z
Commit message: #8606 related : better error reporting when loading file fail
Changeset:
M /branches/Version135/Scribus/scribus/scplugin.h
M /branches/Version135/Scribus/scribus/loadsaveplugin.cpp
M /branches/Version135/Scribus/scribus/plugins/fileloader/scribus134format/scribus134format.cpp
M /branches/Version135/Scribus/scribus/loadsaveplugin.h
M /branches/Version135/Scribus/scribus/plugins/fileloader/scribus12format/scribus12format.cpp
M /branches/Version135/Scribus/scribus/scplugin.cpp
M /branches/Version135/Scribus/scribus/plugins/fileloader/scribus13format/scribus13format.cpp
Diffs:
Index: scribus/loadsaveplugin.h
===================================================================
--- scribus/loadsaveplugin.h (revision 14390)
+++ scribus/loadsaveplugin.h (revision 14391)
@@ -111,6 +111,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 14390)
+++ scribus/scplugin.h (revision 14391)
@@ -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/scplugin.cpp
===================================================================
--- scribus/scplugin.cpp (revision 14390)
+++ scribus/scplugin.cpp (revision 14391)
@@ -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/loadsaveplugin.cpp
===================================================================
--- scribus/loadsaveplugin.cpp (revision 14390)
+++ scribus/loadsaveplugin.cpp (revision 14391)
@@ -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/plugins/fileloader/scribus12format/scribus12format.cpp
===================================================================
--- scribus/plugins/fileloader/scribus12format/scribus12format.cpp (revision 14390)
+++ scribus/plugins/fileloader/scribus12format/scribus12format.cpp (revision 14391)
@@ -229,8 +229,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
@@ -1176,8 +1181,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 14390)
+++ scribus/plugins/fileloader/scribus13format/scribus13format.cpp (revision 14391)
@@ -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;
@@ -2601,8 +2606,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/scribus134format/scribus134format.cpp
===================================================================
--- scribus/plugins/fileloader/scribus134format/scribus134format.cpp (revision 14390)
+++ scribus/plugins/fileloader/scribus134format/scribus134format.cpp (revision 14391)
@@ -175,8 +175,7 @@
int counter;//, Pgc;
//bool AtFl;
bool newVersion = false;
- QString tmp, tmpf, tmp2, tmp3, tmp4, PgNam, Defont, tmf;
- QFont fo;
+ QString tmp, tmpf, PgNam, Defont;
QMap<int,int> TableID;
QList<PageItem*> TableItems;
QMap<int,int> TableIDM;
@@ -206,8 +205,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;
@@ -1744,7 +1748,7 @@
void Scribus134Format::GetItemText(QDomElement *it, ScribusDoc *doc, PageItem* obj, LastStyles* last, bool impo, bool VorLFound)
{
- QString tmp2, tmpf;
+ QString tmp2;
CharStyle newStyle;
GetCStyle(it, doc, newStyle);
@@ -2722,8 +2726,7 @@
itemRemapF.clear();
itemNextF.clear();
itemCountF = 0;
- QString tmV, tmp, tmpf, tmp2, tmp3, tmp4, PgNam, Defont, tmf;
- QFont fo;
+ QString tmp, tmpf, PgNam, Defont;
QMap<int,int> TableID;
QList<PageItem*> TableItems;
QMap<PageItem*, int> groupID;
@@ -2752,8 +2755,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();
QDomElement elem=docu.documentElement();
if (elem.tagName() != "SCRIBUSUTF8NEW")
@@ -3392,7 +3400,7 @@
void Scribus134Format::GetStyle(QDomElement *pg, ParagraphStyle *vg, StyleSet<ParagraphStyle> * tempStyles, ScribusDoc* doc, bool fl)
{
bool fou(false);
- QString tmpf, tmf, tmV;
+ QString tmV;
const StyleSet<ParagraphStyle> * docParagraphStyles = tempStyles? tempStyles : & doc->paragraphStyles();
PrefsManager* prefsManager=PrefsManager::instance();
readParagraphStyle(*vg, *pg, prefsManager->appPrefs.AvailFonts, doc);
@@ -3456,7 +3464,6 @@
{
ParagraphStyle vg;
QDomDocument docu("scridoc");
- QString tmpf, tmf;
QString f (readSLA(fileName));
if (f.isEmpty())
return false;
@@ -3486,7 +3493,6 @@
{
CharStyle cstyle;
QDomDocument docu("scridoc");
- QString tmpf, tmf;
QString f (readSLA(fileName));
if (f.isEmpty())
return false;
More information about the scribus-commit
mailing list