Commit bb5db7ce authored by Dmitry Kazakov's avatar Dmitry Kazakov

Implement asynchronous saving of Krita documents

Now all the saving operations work in the following way:
1) Make a shallow copy of the image
2) Create a separate document with it
3) Save it in a separate thread in background

The functionality basically works, except the following parts:

1) Cloning the image "forgets" some image stuff. I don't have a list of what
   is forgotten yet (layer styles?).
2) Closing the image while Krita is saving will most probably cause a crash.
3) D&D of layers is not tested, though it should work.
4) There was some option to provide "real name" for json export plugin,
   it is not supported anymore.
parent 97087ccd
......@@ -44,7 +44,7 @@ void KisProjectionBenchmark::benchmarkProjection()
KisDocument *doc = KisPart::instance()->createDocument();
doc->loadNativeFormat(QString(FILES_DATA_DIR) + QDir::separator() + "load_test.kra");
doc->image()->refreshGraph();
doc->exportDocument(QUrl::fromLocalFile(QString(FILES_OUTPUT_DIR) + QDir::separator() + "save_test.kra"));
doc->exportDocument(QUrl::fromLocalFile(QString(FILES_OUTPUT_DIR) + QDir::separator() + "save_test.kra"), doc->mimeType());
delete doc;
}
}
......
......@@ -46,6 +46,7 @@
#include <kis_shape_layer.h>
#include <kis_filter_configuration.h>
#include <kis_selection.h>
#include <KisMimeDatabase.h>
#include <KoColorSpace.h>
#include <KoColorProfile.h>
......@@ -382,7 +383,11 @@ void Document::crop(int x, int y, int w, int h)
bool Document::exportImage(const QString &filename, const InfoObject &exportConfiguration)
{
if (!d->document) return false;
return d->document->exportDocument(QUrl::fromLocalFile(filename), exportConfiguration.configuration());
const QString outputFormatString = KisMimeDatabase::mimeTypeForFile(filename);
const QByteArray outputFormat = outputFormatString.toLatin1();
return d->document->exportDocument(QUrl::fromLocalFile(filename), outputFormat, exportConfiguration.configuration());
}
void Document::flatten()
......@@ -412,7 +417,11 @@ bool Document::save()
bool Document::saveAs(const QString &filename)
{
if (!d->document) return false;
return d->document->saveAs(QUrl::fromLocalFile(filename), true);
const QString outputFormatString = KisMimeDatabase::mimeTypeForFile(filename);
const QByteArray outputFormat = outputFormatString.toLatin1();
return d->document->saveAs(QUrl::fromLocalFile(filename), outputFormat, true);
}
Node* Document::createNode(const QString &name, const QString &nodeType)
......
......@@ -444,7 +444,7 @@ bool Node::save(const QString &filename, double xRes, double yRes)
KisPaintDeviceSP projection = d->node->projection();
QRect bounds = d->node->exactBounds();
QString mimefilter = KisMimeDatabase::mimeTypeForFile(filename);;
QString mimeType = KisMimeDatabase::mimeTypeForFile(filename);
QScopedPointer<KisDocument> doc(KisPart::instance()->createDocument());
KisImageSP dst = new KisImage(doc->createUndoStore(),
......@@ -459,9 +459,8 @@ bool Node::save(const QString &filename, double xRes, double yRes)
paintLayer->paintDevice()->makeCloneFrom(projection, bounds);
dst->addNode(paintLayer, dst->rootLayer(), KisLayerSP(0));
dst->initialRefreshGraph();
doc->setOutputMimeType(mimefilter.toLatin1());
bool r = doc->exportDocument(QUrl::fromLocalFile(filename));
bool r = doc->exportDocument(QUrl::fromLocalFile(filename), mimeType.toLatin1());
if (!r) {
qWarning() << doc->errorMessage();
}
......
......@@ -94,17 +94,6 @@ public:
virtual void setMimeType(const QByteArray & mimeType) = 0;
virtual QString localFilePath() const = 0;
/**
* @brief Set the format in which the document should be saved.
*
* This is called on loading, and in "save as", so you shouldn't
* have to call it.
*
* @param mimeType the mime type (format) to use.
*/
virtual void setOutputMimeType(const QByteArray & mimeType) = 0;
virtual QByteArray outputMimeType() const = 0;
private:
class Private;
......
......@@ -330,6 +330,7 @@ set(kritaui_LIB_SRCS
KisImportExportFilter.cpp
KisFilterEntry.cpp
KisImportExportManager.cpp
KisImportExportUtils.cpp
kis_async_action_feedback.cpp
KisMainWindow.cpp
KisOpenPane.cpp
......
......@@ -467,8 +467,7 @@ bool KisApplication::start(const KisApplicationArguments &args)
qApp->processEvents(); // For vector layers to be updated
doc->setFileBatchMode(true);
doc->setOutputMimeType(outputMimetype.toLatin1());
if (!doc->exportDocument(QUrl::fromLocalFile(exportFileName))) {
if (!doc->exportDocument(QUrl::fromLocalFile(exportFileName), outputMimetype.toLatin1())) {
dbgKrita << "Could not export " << fileName << "to" << exportFileName << ":" << doc->errorMessage();
}
nPrinted++;
......
This diff is collapsed.
......@@ -36,6 +36,7 @@
#include <kis_types.h>
#include <kis_painting_assistant.h>
#include <kis_debug.h>
#include <KisImportExportUtils.h>
#include "kritaui_export.h"
......@@ -138,7 +139,9 @@ public:
* KisParts::ReadWritePart::saveAs() to implement KisMainWindow's
* File --> Export feature.
*/
bool exportDocument(const QUrl &url, KisPropertiesConfigurationSP exportConfiguration = 0);
bool exportDocument(const QUrl &url, const QByteArray &mimeType, bool showWarnings = false, KisPropertiesConfigurationSP exportConfiguration = 0);
bool exportDocumentImpl(const KritaUtils::ExportFileJob &job, KisPropertiesConfigurationSP exportConfiguration);
/**
* @brief Sets whether the document can be edited or is read only.
......@@ -177,17 +180,6 @@ public:
*/
void setMimeType(const QByteArray & mimeType);
/**
* @brief Set the format in which the document should be saved.
*
* This is called on loading, and in "save as", so you shouldn't
* have to call it.
*
* @param mimeType the mime type (format) to use.
*/
void setOutputMimeType(const QByteArray & mimeType);
QByteArray outputMimeType() const;
/**
* @return true if file operations should inhibit the option dialog
*/
......@@ -451,18 +443,31 @@ Q_SIGNALS:
void sigGuidesConfigChanged(const KisGuidesConfig &config);
void sigBackgroundSavingFinished(KisImportExportFilter::ConversionStatus status);
void sigBackgroundSavingFinished(KisImportExportFilter::ConversionStatus status, const QString &errorMessage);
void sigCompleteBackgroundSaving(const KritaUtils::ExportFileJob &job, KisImportExportFilter::ConversionStatus status, const QString &errorMessage);
private Q_SLOTS:
void finishExportInBackground();
void slotChildCompletedSavingInBackground(KisImportExportFilter::ConversionStatus status);
void slotChildCompletedSavingInBackground(KisImportExportFilter::ConversionStatus status, const QString &errorMessage);
void slotCompleteAutoSaving(const KritaUtils::ExportFileJob &job, KisImportExportFilter::ConversionStatus status, const QString &errorMessage);
void slotCompleteSavingDocument(const KritaUtils::ExportFileJob &job, KisImportExportFilter::ConversionStatus status, const QString &errorMessage);
private:
friend class KisPart;
friend class SafeSavingLocker;
bool startExportInBackground(const QUrl &url,
const QByteArray &mimeType);
bool initiateSavingInBackground(const QString statusMessage,
const QObject *receiverObject, const char *receiverMethod,
const KritaUtils::ExportFileJob &job,
KisPropertiesConfigurationSP exportConfiguration);
bool startExportInBackground(const QString &location,
const QString &realLocation,
const QByteArray &mimeType,
bool showWarnings,
KisPropertiesConfigurationSP exportConfiguration);
/**
* Generate a name for the document.
......@@ -483,15 +488,6 @@ private:
*/
bool openFile();
/**
* Saves a document
*
* Applies a filter if necessary, and calls exportDocument in any case
* You should not have to reimplement, except for very special cases.
*/
bool saveFile(const QString &filePath, bool showWarnings, KisPropertiesConfigurationSP exportConfiguration = 0);
/** @internal */
void setModified();
......@@ -513,7 +509,7 @@ public:
bool closeUrl(bool promptToSave = true);
bool saveAs(const QUrl &url, bool showWarnings, KisPropertiesConfigurationSP exportConfigration = 0);
bool saveAs(const QUrl &url, const QByteArray &mimeType, bool showWarnings, KisPropertiesConfigurationSP exportConfigration = 0);
/**
* Create a new image that has this document as a parent and
......@@ -600,17 +596,16 @@ private Q_SLOTS:
void slotAutoSave();
/// Called by the undo stack when undo or redo is called
void slotUndoStackIndexChanged(int idx);
void slotUndoStackCleanChanged(bool value);
void slotConfigChanged();
private:
bool prepareLocksForSaving();
KisDocument *safeCreateClone();
void unlockAfterSaving();
QString exportErrorToUserMessage(KisImportExportFilter::ConversionStatus status, const QString &errorMessage);
QString prettyPathOrUrl() const;
......
......@@ -314,7 +314,7 @@ KisImportExportManager::ConversionResult KisImportExportManager::convert(KisImpo
// async importing is not yet supported!
KIS_SAFE_ASSERT_RECOVER_NOOP(!isAsync);
if (!batchMode()) {
if (0 && !batchMode()) {
KisAsyncActionFeedback f(i18n("Opening document..."), 0);
result = f.runAction(std::bind(&KisImportExportManager::doImport, this, location, filter));
} else {
......
/*
* Copyright (c) 2017 Dmitry Kazakov <dimula73@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "KisImportExportUtils.h"
namespace KritaUtils {
}
/*
* Copyright (c) 2017 Dmitry Kazakov <dimula73@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef KISIMPORTEXPORTUTILS_H
#define KISIMPORTEXPORTUTILS_H
#include <QFlags>
#include <QString>
namespace KritaUtils {
enum SaveFlag {
SaveNone = 0,
SaveShowWarnings = 0x1,
SaveIsExporting = 0x2
};
Q_DECLARE_FLAGS(SaveFlags, SaveFlag)
Q_DECLARE_OPERATORS_FOR_FLAGS(SaveFlags)
struct ExportFileJob {
ExportFileJob()
: flags(SaveNone)
{
}
ExportFileJob(QString _filePath, QByteArray _mimeType, SaveFlags _flags = SaveNone)
: filePath(_filePath), mimeType(_mimeType), flags(_flags)
{
}
bool isValid() const {
return !filePath.isEmpty();
}
QString filePath;
QByteArray mimeType;
SaveFlags flags;
};
}
#endif // KISIMPORTEXPORTUTILS_H
......@@ -697,17 +697,23 @@ void KisMainWindow::updateCaption()
updateCaption(QString(), false);
}
else if (d->activeView && d->activeView->document()){
QString caption( d->activeView->document()->caption() );
KisDocument *doc = d->activeView->document();
QString caption(doc->caption());
if (d->readOnly) {
caption += ' ' + i18n("(write protected)");
}
if (doc->isRecovered()) {
caption += ' ' + i18n("[RECOVERED]");
}
d->activeView->setWindowTitle(caption);
updateCaption(caption, d->activeView->document()->isModified());
updateCaption(caption, doc->isModified());
if (!d->activeView->document()->url().fileName().isEmpty())
d->saveAction->setToolTip(i18n("Save as %1", d->activeView->document()->url().fileName()));
if (!doc->url().fileName().isEmpty())
d->saveAction->setToolTip(i18n("Save as %1", doc->url().fileName()));
else
d->saveAction->setToolTip(i18n("Save"));
}
......@@ -926,8 +932,8 @@ bool KisMainWindow::saveDocument(KisDocument *document, bool saveas, bool isExpo
QUrl oldURL = document->url();
QString oldFile = document->localFilePath();
QByteArray _native_format = document->nativeFormatMimeType();
QByteArray oldOutputFormat = document->outputMimeType();
QByteArray nativeFormat = document->nativeFormatMimeType();
QByteArray oldMimeFormat = document->mimeType();
QUrl suggestedURL = document->url();
......@@ -935,8 +941,8 @@ bool KisMainWindow::saveDocument(KisDocument *document, bool saveas, bool isExpo
mimeFilter = KisImportExportManager::mimeFilter(KisImportExportManager::Export);
if (!mimeFilter.contains(oldOutputFormat) && !isExporting) {
dbgUI << "KisMainWindow::saveDocument no export filter for" << oldOutputFormat;
if (!mimeFilter.contains(oldMimeFormat) && !isExporting) {
dbgUI << "KisMainWindow::saveDocument no export filter for" << oldMimeFormat;
// --- don't setOutputMimeType in case the user cancels the Save As
// dialog and then tries to just plain Save ---
......@@ -947,7 +953,7 @@ bool KisMainWindow::saveDocument(KisDocument *document, bool saveas, bool isExpo
if (!suggestedFilename.isEmpty()) { // ".kra" looks strange for a name
int c = suggestedFilename.lastIndexOf('.');
const QString ext = KisMimeDatabase::suffixesForMimeType(_native_format).first();
const QString ext = KisMimeDatabase::suffixesForMimeType(nativeFormat).first();
if (!ext.isEmpty()) {
if (c < 0)
suggestedFilename = suggestedFilename + "." + ext;
......@@ -984,13 +990,13 @@ bool KisMainWindow::saveDocument(KisDocument *document, bool saveas, bool isExpo
dialog.setDefaultDir(suggestedURL.toLocalFile());
}
// Default to all supported file types if user is exporting, otherwise use Krita default
dialog.setMimeTypeFilters(mimeFilter, QString(_native_format));
dialog.setMimeTypeFilters(mimeFilter, QString(nativeFormat));
QUrl newURL = QUrl::fromUserInput(dialog.filename());
if (newURL.isLocalFile()) {
QString fn = newURL.toLocalFile();
if (QFileInfo(fn).completeSuffix().isEmpty()) {
fn.append(KisMimeDatabase::suffixesForMimeType(_native_format).first());
fn.append(KisMimeDatabase::suffixesForMimeType(nativeFormat).first());
newURL = QUrl::fromLocalFile(fn);
}
}
......@@ -1001,7 +1007,7 @@ bool KisMainWindow::saveDocument(KisDocument *document, bool saveas, bool isExpo
document->documentInfo()->setAboutInfo("title", info.baseName());
}
QByteArray outputFormat = _native_format;
QByteArray outputFormat = nativeFormat;
QString outputFormatString = KisMimeDatabase::mimeTypeForFile(newURL.toLocalFile());
outputFormat = outputFormatString.toLatin1();
......@@ -1052,9 +1058,8 @@ bool KisMainWindow::saveDocument(KisDocument *document, bool saveas, bool isExpo
//
// - Clarence
//
document->setOutputMimeType(outputFormat);
if (!isExporting) { // Save As
ret = document->saveAs(newURL, true);
ret = document->saveAs(newURL, outputFormat, true);
if (ret) {
dbgUI << "Successful Save As!";
......@@ -1064,19 +1069,15 @@ bool KisMainWindow::saveDocument(KisDocument *document, bool saveas, bool isExpo
dbgUI << "Failed Save As!";
document->setUrl(oldURL);
document->setLocalFilePath(oldFile);
document->setOutputMimeType(oldOutputFormat);
}
} else { // Export
ret = document->exportDocument(newURL);
ret = document->exportDocument(newURL, outputFormat);
if (ret) {
// a few file dialog convenience things
d->lastExportUrl = newURL;
d->lastExportedFormat = outputFormat;
}
// always restore output format
document->setOutputMimeType(oldOutputFormat);
}
} // if (wantToSave) {
......@@ -2220,12 +2221,8 @@ void KisMainWindow::applyDefaultSettings(QPrinter &printer) {
QString title = d->activeView->document()->documentInfo()->aboutInfo("title");
if (title.isEmpty()) {
title = d->activeView->document()->url().fileName();
// strip off the native extension (I don't want foobar.kwd.ps when printing into a file)
QString extension = KisMimeDatabase::suffixesForMimeType(d->activeView->document()->outputMimeType()).first();
if (title.endsWith(extension)) {
title.chop(extension.length());
}
QFileInfo info(d->activeView->document()->url().fileName());
title = info.baseName();
}
if (title.isEmpty()) {
......
......@@ -115,12 +115,13 @@ bool KisSaveGroupVisitor::visit(KisGroupLayer *layer)
dst->refreshGraph();
exportDocument->setOutputMimeType(m_mimeFilter.toLatin1());
exportDocument->setFileBatchMode(true);
QString path = m_path + "/" + m_baseName + "_" + layer->name().replace(' ', '_') + '.' + m_extension;
QUrl url = QUrl::fromLocalFile(path);
exportDocument->exportDocument(url);
exportDocument->setFileBatchMode(true);
exportDocument->exportDocument(url, m_mimeFilter.toLatin1());
if (!m_saveTopLevelOnly) {
KisGroupLayerSP child = dynamic_cast<KisGroupLayer*>(layer->firstChild().data());
......
......@@ -207,7 +207,7 @@ void KisTemplateCreateDia::createTemplate(const QString &templatesResourcePath,
}
fileName = tempFile.fileName();
}
bool retval = document->exportDocument(QUrl::fromLocalFile(fileName));
bool retval = document->exportDocument(QUrl::fromLocalFile(fileName), document->mimeType());
if (!retval) {
qWarning("Could not save template");
return;
......
......@@ -713,7 +713,7 @@ bool KisView::queryClose()
switch (res) {
case QMessageBox::Yes : {
bool isNative = (document()->outputMimeType() == document()->nativeFormatMimeType());
bool isNative = (document()->mimeType() == document()->nativeFormatMimeType());
if (!viewManager()->mainWindow()->saveDocument(document(), !isNative, false))
return false;
break;
......
......@@ -871,6 +871,7 @@ void KisViewManager::slotSaveIncremental()
}
version.remove(0, 1); // Trim "_"
} else {
// TODO: this will not work with files extensions like jp2
// ...else, simply add a version to it so the next loop works
QRegExp regex2("[.][a-z]{2,4}$"); // Heuristic to find file extension
regex2.indexIn(fileName);
......@@ -917,7 +918,7 @@ void KisViewManager::slotSaveIncremental()
return;
}
document()->setFileBatchMode(true);
document()->saveAs(QUrl::fromUserInput(fileName), true);
document()->saveAs(QUrl::fromUserInput(fileName), document()->mimeType(), true);
document()->setFileBatchMode(false);
if (mainWindow()) {
......@@ -988,7 +989,7 @@ void KisViewManager::slotSaveIncrementalBackup()
return;
}
QFile::copy(fileName, backupFileName);
document()->saveAs(QUrl::fromUserInput(fileName), true);
document()->saveAs(QUrl::fromUserInput(fileName), document()->mimeType(), true);
if (mainWindow()) mainWindow()->updateCaption();
}
......@@ -1026,7 +1027,7 @@ void KisViewManager::slotSaveIncrementalBackup()
// Save both as backup and on current file for interapplication workflow
document()->setFileBatchMode(true);
QFile::copy(fileName, backupFileName);
document()->saveAs(QUrl::fromUserInput(fileName), true);
document()->saveAs(QUrl::fromUserInput(fileName), document()->mimeType(), true);
document()->setFileBatchMode(false);
if (mainWindow()) mainWindow()->updateCaption();
......
......@@ -267,6 +267,7 @@ struct KisAnimationExportSaver::Private
QScopedPointer<KisDocument> tmpDoc;
KisImageSP tmpImage;
KisPaintDeviceSP tmpDevice;
QByteArray outputMimeType;
KisAnimationExporter exporter;
......@@ -285,8 +286,7 @@ KisAnimationExportSaver::KisAnimationExportSaver(KisDocument *document, const QS
m_d->filenamePrefix = baseFilename;
}
QString mimefilter = KisMimeDatabase::mimeTypeForFile(baseFilename);
m_d->tmpDoc->setOutputMimeType(mimefilter.toLatin1());
m_d->outputMimeType = KisMimeDatabase::mimeTypeForFile(baseFilename).toLatin1();
m_d->tmpDoc->setFileBatchMode(true);
using namespace std::placeholders; // For _1 placeholder
......@@ -365,7 +365,7 @@ KisImportExportFilter::ConversionStatus KisAnimationExportSaver::saveFrameCallba
QRect rc = m_d->image->bounds();
KisPainter::copyAreaOptimized(rc.topLeft(), frame, m_d->tmpDevice, rc);
if (!m_d->tmpDoc->exportDocument(QUrl::fromLocalFile(filename), exportConfiguration)) {
if (!m_d->tmpDoc->exportDocument(QUrl::fromLocalFile(filename), m_d->outputMimeType, exportConfiguration)) {
status = KisImportExportFilter::InternalError;
}
......
......@@ -990,8 +990,7 @@ void KisNodeManager::Private::saveDeviceAsImage(KisPaintDeviceSP device,
dst->initialRefreshGraph();
doc->setOutputMimeType(mimefilter.toLatin1());
doc->exportDocument(url);
doc->exportDocument(url, mimefilter.toLatin1());
}
void KisNodeManager::saveNodeAsImage()
......
......@@ -227,10 +227,10 @@ void CompositionDockerDock::exportClicked()
dst->refreshGraph();
d->setOutputMimeType("image/png");
d->setFileBatchMode(true);
d->exportDocument(QUrl::fromLocalFile(path + composition->name() + ".png"));
const QByteArray outputFormat("image/png");
d->exportDocument(QUrl::fromLocalFile(path + composition->name() + ".png"), outputFormat);
delete d;
......
......@@ -76,9 +76,8 @@ bool Imagesplit::saveAsImage(const QRect &imgSize, const QString &mimeType, cons
dst->addNode(paintLayer, KisNodeSP(0));
dst->refreshGraph();
document->setOutputMimeType(mimeType.toLatin1());
document->setFileBatchMode(true);
if (!document->exportDocument(QUrl::fromLocalFile(url))) {
if (!document->exportDocument(QUrl::fromLocalFile(url), mimeType.toLatin1())) {
if (document->errorMessage().isEmpty()) {
QMessageBox::critical(0, i18nc("@title:window", "Krita"), i18n("Could not save\n%1", document->localFilePath()));
} else {
......
......@@ -243,7 +243,7 @@ void KisChannelSeparator::separate(KoUpdater * progressUpdater, enumSepAlphaOpti
if (url.isEmpty())
return;
QString mimefilter = KisMimeDatabase::mimeTypeForFile(url.toLocalFile());
const QString mimeType = KisMimeDatabase::mimeTypeForFile(url.toLocalFile());
KisPaintLayerSP l = KisPaintLayerSP(new KisPaintLayer(image.data(), ch->name(), OPACITY_OPAQUE_U8, *deviceIt));
QRect r = l->exactBounds();
......@@ -254,8 +254,7 @@ void KisChannelSeparator::separate(KoUpdater * progressUpdater, enumSepAlphaOpti
d->setCurrentImage(dst);
dst->addNode(l->clone().data(), dst->rootLayer());
d->setOutputMimeType(mimefilter.toLatin1());
d->exportDocument(url);
d->exportDocument(url, mimeType.toLatin1());
delete d;
......
......@@ -445,7 +445,6 @@ KisImageBuilder_Result CSVSaver::getLayer(CSVLayerRecord* layer, KisDocument* ex
void CSVSaver::createTempImage(KisDocument* exportDoc)
{
exportDoc->setAutoSaveDelay(0);
exportDoc->setOutputMimeType("image/png");
exportDoc->setFileBatchMode(true);
KisImageSP exportImage = new KisImage(exportDoc->createUndoStore(),
......
......@@ -82,7 +82,7 @@ void KisKraSaverTest::testRoundTrip()
KisDocument* doc = createCompleteDocument();
KoColor bgColor(Qt::red, doc->image()->colorSpace());
doc->image()->setDefaultProjectionColor(bgColor);
doc->exportDocument(QUrl::fromLocalFile("roundtriptest.kra"));
doc->exportDocument(QUrl::fromLocalFile("roundtriptest.kra"), doc->mimeType());
QStringList list;
KisCountVisitor cv1(list, KoProperties());
......@@ -119,7 +119,7 @@ void KisKraSaverTest::testRoundTrip()
void KisKraSaverTest::testSaveEmpty()
{
KisDocument* doc = createEmptyDocument();
doc->exportDocument(QUrl::fromLocalFile("emptytest.kra"));
doc->exportDocument(QUrl::fromLocalFile("emptytest.kra"), doc->mimeType());
QStringList list;
KisCountVisitor cv1(list, KoProperties());
doc->image()->rootLayer()->accept(cv1);
......@@ -162,7 +162,7 @@ void testRoundTripFillLayerImpl(const QString &testName, KisFilterConfigurationS
p.image->waitForDone();
chk.checkImage(p.image, "00_initial_layer_update");
doc->exportDocument(QUrl::fromLocalFile("roundtrip_fill_layer_test.kra"));
doc->exportDocument(QUrl::fromLocalFile("roundtrip_fill_layer_test.kra"), doc->mimeType());
QScopedPointer<KisDocument> doc2(KisPart::instance()->createDocument());
doc2->loadNativeFormat("roundtrip_fill_layer_test.kra");
......@@ -254,7 +254,7 @@ void KisKraSaverTest::testRoundTripLayerStyles()
image->initialRefreshGraph();
chk.checkImage(image, "00_initial_layers");
doc->exportDocument(QUrl::fromLocalFile("roundtrip_layer_styles.kra"));
doc->exportDocument(QUrl::fromLocalFile("roundtrip_layer_styles.kra"), doc->mimeType());
QScopedPointer<KisDocument> doc2(KisPart::instance()->createDocument());
......@@ -303,7 +303,7 @@ void KisKraSaverTest::testRoundTripAnimation()
layer1->setUseInTimeline(true);
doc->setCurrentImage(image);
doc->exportDocument(QUrl::fromLocalFile("roundtrip_animation.kra"));
doc->exportDocument(QUrl::fromLocalFile("roundtrip_animation.kra"), doc->mimeType());
QScopedPointer<KisDocument> doc2(KisPart::instance()->createDocument());
doc2->loadNativeFormat("roundtrip_animation.kra");
......@@ -393,7 +393,7 @@ void KisKraSaverTest::testRoundTripColorizeMask()
doc->exportDocument(QUrl::fromLocalFile("roundtrip_colorize.kra"));
doc->exportDocument(QUrl::fromLocalFile("roundtrip_colorize.kra"), doc->mimeType());
QScopedPointer<KisDocument> doc2(KisPart::instance()->createDocument());
doc2->loadNativeFormat("roundtrip_colorize.kra");
......@@ -466,7 +466,7 @@ void KisKraSaverTest::testRoundTripShapeLayer()
chk.checkImage(p.image, "00_initial_layer_update");
doc->exportDocument(QUrl::fromLocalFile("roundtrip_shapelayer_test.kra"));
doc->exportDocument(QUrl::fromLocalFile("roundtrip_shapelayer_test.kra"), doc->mimeType());
QScopedPointer<KisDocument> doc2(KisPart::instance()->createDocument());
doc2->loadNativeFormat("roundtrip_shapelayer_test.kra");
......@@ -526,7 +526,7 @@ void KisKraSaverTest::testRoundTripShapeSelection()
chk.checkImage(p.image, "00_initial_shape_selection");
doc->exportDocument(QUrl::fromLocalFile("roundtrip_shapeselection_test.kra"));
doc->exportDocument(QUrl::fromLocalFile("roundtrip_shapeselection_test.kra"), doc->mimeType());
QScopedPointer<KisDocument> doc2(KisPart::instance()->createDocument());
doc2->loadNativeFormat("roundtrip_shapeselection_test.kra");
......
......@@ -82,9 +82,9 @@ void KisPSDTest::testTransparencyMask()
QVERIFY(TestUtil::checkQImageExternal(result, "psd_test", "transparency_masks", "kiki_single"));
doc->setFileBatchMode(true);
doc->setOutputMimeType("image/vnd.adobe.photoshop");
const QByteArray mimeType("image/vnd.adobe.photoshop");
QFileInfo dstFileInfo(QDir::currentPath() + QDir::separator() + "test_tmask.psd");
bool retval = doc->saveAs(QUrl::fromLocalFile(dstFileInfo.absoluteFilePath()), false);
bool retval = doc->saveAs(QUrl::fromLocalFile(dstFileInfo.absoluteFilePath()), mimeType, false);
QVERIFY(retval);
{
......@@ -205,9 +205,9 @@ void KisPSDTest::testSaveLayerStylesWithPatternMulti()
QVERIFY(layer->layerStyle()->stroke()->pattern()->valid());
doc->setFileBatchMode(true);
doc->setOutputMimeType("image/vnd.adobe.photoshop");
const QByteArray mimeType("image/vnd.adobe.photoshop");
QFileInfo dstFileInfo(QDir::currentPath() + QDir::separator() + "test_save_styles.psd");
bool retval = doc->saveAs(QUrl::fromLocalFile(dstFileInfo.absoluteFilePath()), false);
bool retval = doc->saveAs(QUrl::fromLocalFile(dstFileInfo.absoluteFilePath()), mimeType, false);
QVERIFY(retval);
{
......@@ -311,12 +311,12 @@ void KisPSDTest::testSavingAllFormats()