Commit b46a3e6d authored by Agata Cacko's avatar Agata Cacko

Add a simple progress bar for saving as .kra file

This commit adds a simple progress bar to be shown
when Krita is saving a .kra file.
It shows only a few values, but it provides more feedback
than there was before.
parent aa34d6da
......@@ -249,6 +249,11 @@ void KisImportExportFilter::setUpdater(QPointer<KoUpdater> updater)
d->updater = updater;
}
QPointer<KoUpdater> KisImportExportFilter::updater()
{
return d->updater;
}
void KisImportExportFilter::setProgress(int value)
{
if (d->updater) {
......
......@@ -104,6 +104,7 @@ public:
void setRealFilename(const QString &filename);
void setMimeType(const QString &mime);
void setUpdater(QPointer<KoUpdater> updater);
QPointer<KoUpdater> updater();
/**
* The filter chain calls this method to perform the actual conversion.
......
......@@ -46,6 +46,13 @@ KraConverter::KraConverter(KisDocument *doc)
{
}
KraConverter::KraConverter(KisDocument *doc, QPointer<KoUpdater> updater)
: m_doc(doc)
, m_image(doc->savingImage())
, m_updater(updater)
{
}
KraConverter::~KraConverter()
{
delete m_store;
......@@ -109,6 +116,7 @@ QList<KisPaintingAssistantSP> KraConverter::assistants()
KisImportExportErrorCode KraConverter::buildFile(QIODevice *io, const QString &filename)
{
setProgress(5);
m_store = KoStore::createStore(io, KoStore::Write, m_doc->nativeFormatMimeType(), KoStore::Zip);
if (m_store->bad()) {
......@@ -116,6 +124,7 @@ KisImportExportErrorCode KraConverter::buildFile(QIODevice *io, const QString &f
return ImportExportCodes::CannotCreateFile;
}
setProgress(20);
m_kraSaver = new KisKraSaver(m_doc, filename);
......@@ -125,21 +134,25 @@ KisImportExportErrorCode KraConverter::buildFile(QIODevice *io, const QString &f
return resultCode;
}
setProgress(40);
bool result;
result = m_kraSaver->saveKeyframes(m_store, m_doc->url().toLocalFile(), true);
if (!result) {
qWarning() << "saving key frames failed";
}
setProgress(60);
result = m_kraSaver->saveBinaryData(m_store, m_image, m_doc->url().toLocalFile(), true, m_doc->isAutosaving());
if (!result) {
qWarning() << "saving binary data failed";
}
setProgress(70);
result = m_kraSaver->savePalettes(m_store, m_image, m_doc->url().toLocalFile());
if (!result) {
qWarning() << "saving palettes data failed";
}
setProgress(80);
if (!m_store->finalize()) {
return ImportExportCodes::Failure;
}
......@@ -148,6 +161,7 @@ KisImportExportErrorCode KraConverter::buildFile(QIODevice *io, const QString &f
m_doc->setErrorMessage(m_kraSaver->errorMessages().join(".\n"));
return ImportExportCodes::Failure;
}
setProgress(90);
return ImportExportCodes::OK;
}
......@@ -384,4 +398,10 @@ void KraConverter::cancel()
m_stop = true;
}
void KraConverter::setProgress(int progress)
{
if (m_updater) {
m_updater->setProgress(progress);
}
}
......@@ -30,6 +30,10 @@
#include <kis_types.h>
#include <kis_kra_saver.h>
#include <kis_kra_loader.h>
#include <KoProgressUpdater.h>
#include <QPointer>
#include <KoUpdater.h>
class KisDocument;
......@@ -40,6 +44,7 @@ class KraConverter : public QObject
public:
KraConverter(KisDocument *doc);
KraConverter(KisDocument *doc, QPointer<KoUpdater> updater);
~KraConverter() override;
KisImportExportErrorCode buildImage(QIODevice *io);
......@@ -65,6 +70,8 @@ private:
KisImportExportErrorCode loadXML(const KoXmlDocument &doc, KoStore *store);
bool completeLoading(KoStore *store);
void setProgress(int progress);
KisDocument *m_doc {0};
KisImageSP m_image;
......@@ -75,6 +82,7 @@ private:
KoStore *m_store {0};
KisKraSaver *m_kraSaver {0};
KisKraLoader *m_kraLoader {0};
QPointer<KoUpdater> m_updater;
};
#endif
......@@ -58,7 +58,7 @@ KisImportExportErrorCode KraExport::convert(KisDocument *document, QIODevice *io
KisImageSP image = document->savingImage();
KIS_ASSERT_RECOVER_RETURN_VALUE(image, ImportExportCodes::InternalError);
KraConverter kraConverter(document);
KraConverter kraConverter(document, updater());
KisImportExportErrorCode res = kraConverter.buildFile(io, filename());
dbgFile << "KraExport::convert result =" << res;
return res;
......
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