Commit 87bbda52 authored by Boudewijn Rempt's avatar Boudewijn Rempt

Add error messages for loading document.

parent fe1f823b
......@@ -267,13 +267,14 @@ bool KisKraLoadVisitor::loadPaintDevice(KisPaintDeviceSP device, const QString&
// Layer data
if (m_store->open(location)) {
if (!device->read(m_store->device())) {
m_errorMessages << i18n("Could not read pixel data: %1.", location);
device->disconnect();
m_store->close();
return false;
}
m_store->close();
} else {
kError() << "No image data: that's an error! " << device << ", " << location;
m_errorMessages << i18n("Could not load pixel data: %1.", location);
return false;
}
if (m_store->open(location + ".defaultpixel")) {
......@@ -311,6 +312,7 @@ bool KisKraLoadVisitor::loadProfile(KisPaintDeviceSP device, const QString& loca
return true;
}
}
m_errorMessages << i18n("Could not load profile %1.", location);
return false;
}
......@@ -334,6 +336,7 @@ bool KisKraLoadVisitor::loadFilterConfiguration(KisFilterConfiguration* kfc, con
return true;
}
}
m_errorMessages << i18n("Could not filter configuration %1.", location);
return false;
}
......@@ -367,7 +370,6 @@ bool KisKraLoadVisitor::loadMetaData(KisNode* node)
}
}
return result;
}
......@@ -379,6 +381,10 @@ bool KisKraLoadVisitor::loadSelection(const QString& location, KisSelectionSP ds
if (m_store->hasFile(pixelSelectionLocation)) {
KisPixelSelectionSP pixelSelection = dstSelection->pixelSelection();
result = loadPaintDevice(pixelSelection, pixelSelectionLocation);
if (!result) {
m_errorMessages << i18n("Could not load raster selection %1.", location);
}
}
// Shape selection
......@@ -391,6 +397,10 @@ bool KisKraLoadVisitor::loadSelection(const QString& location, KisSelectionSP ds
dstSelection->setShapeSelection(shapeSelection);
result = shapeSelection->loadSelection(m_store);
m_store->popDirectory();
if (!result) {
m_errorMessages << i18n("Could not vector selection %1.", location);
}
}
return result;
}
......
......@@ -178,31 +178,38 @@ KisImageWSP KisKraLoader::loadXML(const KoXmlElement& element)
if ((attr = element.attribute(MIME)) == NATIVE_MIMETYPE) {
if ((m_d->imageName = element.attribute(NAME)).isNull())
if ((m_d->imageName = element.attribute(NAME)).isNull()) {
m_d->errorMessages << i18n("Image does not have a name.");
return KisImageWSP(0);
}
if ((attr = element.attribute(WIDTH)).isNull()) {
m_d->errorMessages << i18n("Image does not specify a width.");
return KisImageWSP(0);
}
width = attr.toInt();
if ((attr = element.attribute(HEIGHT)).isNull()) {
m_d->errorMessages << i18n("Image does not specify a height.");
return KisImageWSP(0);
}
height = attr.toInt();
m_d->imageComment = element.attribute(DESCRIPTION);
xres = 100.0 / 72.0;
if (!(attr = element.attribute(X_RESOLUTION)).isNull()) {
if (attr.toDouble() > 1.0)
if (attr.toDouble() > 1.0) {
xres = attr.toDouble() / 72.0;
}
}
yres = 100.0;
if (!(attr = element.attribute(Y_RESOLUTION)).isNull()) {
if (attr.toDouble() > 1.0)
if (attr.toDouble() > 1.0) {
yres = attr.toDouble() / 72.0;
}
}
if ((colorspacename = element.attribute(COLORSPACE_NAME)).isNull()) {
......@@ -230,7 +237,8 @@ KisImageWSP KisKraLoader::loadXML(const KoXmlElement& element)
// try once more without the profile
cs = KoColorSpaceRegistry::instance()->colorSpace(colorspaceModel, colorspaceDepth, "");
if (cs == 0) {
warnFile << "Could not open colorspace";
qDebug() << "!!!!!!!!!!!!!!!!!";
m_d->errorMessages << i18n("Image specifies an unssupported color model: %1.", colorspacename);
return KisImageWSP(0);
}
}
......@@ -289,10 +297,14 @@ void KisKraLoader::loadBinaryData(KoStore * store, KisImageWSP image, const QStr
// Load the layers data: if there is a profile associated with a layer it will be set now.
KisKraLoadVisitor visitor(image, store, m_d->layerFilenames, m_d->imageName, m_d->syntaxVersion);
if (external)
if (external) {
visitor.setExternalUri(uri);
}
image->rootLayer()->accept(visitor);
if (!visitor.errorMessages().isEmpty()) {
m_d->errorMessages.append(visitor.errorMessages());
}
// annotations
// exif
......@@ -311,6 +323,7 @@ void KisKraLoader::loadBinaryData(KoStore * store, KisImageWSP image, const QStr
m_d->document->documentInfo()->setAboutInfo("title", m_d->imageName);
if (m_d->document && m_d->document->documentInfo()->aboutInfo("comment").isNull())
m_d->document->documentInfo()->setAboutInfo("comment", m_d->imageComment);
loadAssistants(store, uri, external);
}
......@@ -399,7 +412,8 @@ KisNodeSP KisKraLoader::loadNode(const KoXmlElement& element, KisImageWSP image,
if ((element.attribute(COLORSPACE_NAME)).isNull()) {
dbgFile << "No attribute color space for layer: " << name;
colorSpace = image->colorSpace();
} else {
}
else {
QString colorspacename = element.attribute(COLORSPACE_NAME);
QString profileProductName;
......@@ -413,7 +427,7 @@ KisNodeSP KisKraLoader::loadNode(const KoXmlElement& element, KisImageWSP image,
colorSpace = KoColorSpaceRegistry::instance()->colorSpace(colorspaceModel, colorspaceDepth, "");
dbgFile << "found colorspace" << colorSpace;
if (!colorSpace) {
warnFile << "Could not create a colorspace for" << colorspacename;
m_d->errorMessages << i18n("Layer %1 specifies an unsupported color model: %2.", name, colorspacename);
return 0;
}
}
......@@ -430,12 +444,15 @@ KisNodeSP KisKraLoader::loadNode(const KoXmlElement& element, KisImageWSP image,
if (nodeType.isEmpty()) {
nodeType = PAINT_LAYER;
}
} else {
}
else {
nodeType = element.attribute(NODE_TYPE);
}
Q_ASSERT(!nodeType.isEmpty());
if (nodeType.isEmpty()) return 0;
if (nodeType.isEmpty()) {
m_d->errorMessages << i18n("Layer %1 is an unsupported type.", name);
return 0;
}
KisNodeSP node = 0;
......@@ -461,12 +478,17 @@ KisNodeSP KisKraLoader::loadNode(const KoXmlElement& element, KisImageWSP image,
else if (nodeType == FILE_LAYER) {
node = loadFileLayer(element, image, name, opacity);
}
else
warnKrita << "Trying to load layer of unsupported type " << nodeType;
else {
m_d->errorMessages << i18n("Layer %1 is an unsupported type: %2.", name, nodeType);
return 0;
}
// Loading the node went wrong. Return empty node and leave to
// upstream to complain to the user
if (!node) return 0;
if (!node) {
m_d->errorMessages << i18n("Failure loading layer %1 of type: %2.", name, nodeType);
return 0;
}
node->setVisible(visible, true);
node->setUserLocked(locked);
......
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