Commit 20e980c4 authored by Dmitry Kazakov's avatar Dmitry Kazakov

Don't let Krita close the document if it is still being saved

parent bb5db7ce
......@@ -116,6 +116,7 @@
#include "kis_image_barrier_lock_adapter.h"
#include <mutex>
#include "kis_config_notifier.h"
#include "kis_async_action_feedback.h"
// Define the protocol used here for embedded documents' URL
......@@ -460,6 +461,9 @@ KisDocument::KisDocument(const KisDocument &rhs)
KisDocument::~KisDocument()
{
// wait until all the pending operations are in progress
waitForSavingToComplete();
/**
* Push a timebomb, which will try to release the memory after
* the document has been deleted
......@@ -1544,6 +1548,21 @@ bool KisDocument::newImage(const QString& name,
return true;
}
bool KisDocument::isSaving() const
{
const bool result = d->savingMutex.tryLock();
if (result) {
d->savingMutex.unlock();
}
return !result;
}
void KisDocument::waitForSavingToComplete()
{
KisAsyncActionFeedback f(i18nc("progress dialog message when the user closes the document that is being saved", "Waiting for saving to complete..."), 0);
f.waitForMutex(&d->savingMutex);
}
KoShapeBasedDocumentBase *KisDocument::shapeController() const
{
return d->shapeController;
......
......@@ -518,6 +518,9 @@ public:
bool newImage(const QString& name, qint32 width, qint32 height, const KoColorSpace * cs, const KoColor &bgColor, bool backgroundAsLayer,
int numberOfLayers, const QString &imageDescription, const double imageResolution);
bool isSaving() const;
void waitForSavingToComplete();
KisImageWSP image() const;
......
......@@ -695,6 +695,10 @@ bool KisView::queryClose()
if (!document())
return true;
if (document()->isSaving()) {
document()->waitForSavingToComplete();
}
if (document()->isModified()) {
QString name;
if (document()->documentInfo()) {
......
......@@ -35,6 +35,9 @@ KisAsyncActionFeedback::KisAsyncActionFeedback(const QString &message, QWidget *
m_d->progress->setCancelButton(0);
m_d->progress->setMinimumDuration(1000);
m_d->progress->setValue(0);
// disable close button
m_d->progress->setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowTitleHint);
}
KisAsyncActionFeedback::~KisAsyncActionFeedback()
......@@ -60,3 +63,25 @@ KisImportExportFilter::ConversionStatus KisAsyncActionFeedback::runAction(std::f
{
return runActionImpl(func);
}
void KisAsyncActionFeedback::runVoidAction(std::function<void()> func)
{
QFuture<void> result = QtConcurrent::run(func);
QFutureWatcher<void> watcher;
watcher.setFuture(result);
while (watcher.isRunning()) {
qApp->processEvents();
}
watcher.waitForFinished();
}
void KisAsyncActionFeedback::waitForMutex(QMutex *mutex)
{
while (!mutex->tryLock()) {
qApp->processEvents();
}
mutex->unlock();
}
......@@ -24,6 +24,7 @@
#include "KisImportExportFilter.h"
class QWidget;
class QMutex;
class KisAsyncActionFeedback
{
......@@ -32,6 +33,8 @@ public:
~KisAsyncActionFeedback();
KisImportExportFilter::ConversionStatus runAction(std::function<KisImportExportFilter::ConversionStatus()> func);
void runVoidAction(std::function<void()> func);
void waitForMutex(QMutex *mutex);
private:
struct Private;
......
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