Commit ca7fabe4 authored by Boudewijn Rempt's avatar Boudewijn Rempt

Pass the error messages to the KoDocument class

Which apparently can show the error message on loading/saving -- at
least, this is what Karbon does.
parent 3129c99b
......@@ -250,6 +250,9 @@ QDomDocument KisDoc2::saveXML()
m_d->kraSaver = new KisKraSaver(this);
root.appendChild(m_d->kraSaver->saveXML(doc, m_d->image));
if (!m_d->kraSaver->errorMessages().isEmpty()) {
setErrorMessage(m_d->kraLoader->errorMessages().join(".\n"));
}
return doc;
}
......@@ -257,6 +260,7 @@ QDomDocument KisDoc2::saveXML()
bool KisDoc2::loadOdf(KoOdfReadStore & odfStore)
{
Q_UNUSED(odfStore);
setErrorMessage(i18n("Krita does not support the OpenDocument file format."));
return false;
}
......@@ -264,10 +268,11 @@ bool KisDoc2::loadOdf(KoOdfReadStore & odfStore)
bool KisDoc2::saveOdf(SavingContext &documentContext)
{
Q_UNUSED(documentContext);
setErrorMessage(i18n("Krita does not support the OpenDocument file format."));
return false;
}
bool KisDoc2::loadXML(const KoXmlDocument& doc, KoStore *)
bool KisDoc2::loadXML(const KoXmlDocument& doc, KoStore *store)
{
if (m_d->image) {
m_d->shapeController->setImage(0);
......@@ -280,14 +285,19 @@ bool KisDoc2::loadXML(const KoXmlDocument& doc, KoStore *)
init();
if (doc.doctype().name() != "DOC")
if (doc.doctype().name() != "DOC") {
setErrorMessage(i18n("The format is not supported or the file is corrupted"));
return false;
}
root = doc.documentElement();
int syntaxVersion = root.attribute("syntaxVersion", "3").toInt();
if (syntaxVersion > 2)
if (syntaxVersion > 2) {
setErrorMessage(i18n("The file is too new for this version of Krita (%1).", syntaxVersion));
return false;
}
if (!root.hasChildNodes()) {
setErrorMessage(i18n("The file has no layers."));
return false;
}
......@@ -299,10 +309,21 @@ bool KisDoc2::loadXML(const KoXmlDocument& doc, KoStore *)
if (node.isElement()) {
if (node.nodeName() == "IMAGE") {
KoXmlElement elem = node.toElement();
if (!(image = m_d->kraLoader->loadXML(elem)))
if (!(image = m_d->kraLoader->loadXML(elem))) {
if (m_d->kraLoader->errorMessages().isEmpty()) {
setErrorMessage(i18n("Unknown error."));
}
else {
setErrorMessage(m_d->kraLoader->errorMessages().join(".\n"));
}
return false;
}
} else {
}
else {
if (m_d->kraLoader->errorMessages().isEmpty()) {
setErrorMessage(i18n("The file does not contain an image."));
}
return false;
}
}
......@@ -322,6 +343,10 @@ bool KisDoc2::completeSaving(KoStore *store)
QString uri = url().url();
m_d->kraSaver->saveBinaryData(store, m_d->image, url().url(), isStoredExtern());
if (!m_d->kraSaver->errorMessages().isEmpty()) {
setErrorMessage(m_d->kraLoader->errorMessages().join(".\n"));
return false;
}
delete m_d->kraSaver;
m_d->kraSaver = 0;
......@@ -337,10 +362,23 @@ int KisDoc2::supportedSpecialFormats() const
bool KisDoc2::completeLoading(KoStore *store)
{
if (!m_d->image) return false;
if (!m_d->image) {
if (m_d->kraLoader->errorMessages().isEmpty()) {
setErrorMessage(i18n("Unknown error."));
}
else {
setErrorMessage(m_d->kraLoader->errorMessages().join(".\n"));
}
return false;
}
m_d->kraLoader->loadBinaryData(store, m_d->image, url().url(), isStoredExtern());
if (!m_d->kraLoader->errorMessages().isEmpty()) {
setErrorMessage(m_d->kraLoader->errorMessages().join(".\n"));
return false;
}
vKisNodeSP preselectedNodes = m_d->kraLoader->selectedNodes();
if (preselectedNodes.size() > 0) {
m_d->preActivatedNode = preselectedNodes.first();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment