Skip to content

armgit / krita

Public Imported from GitHub
0

Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.

C++

Video Import: Allow import process to be canceled.

Emmet O'Neill4c62b784bae5
diff --git a/libs/ui/animation/KisDlgImportVideoAnimation.cpp b/libs/ui/animation/KisDlgImportVideoAnimation.cpp
index e7f5bc1aed..d884d01604 100644
--- a/libs/ui/animation/KisDlgImportVideoAnimation.cpp
+++ b/libs/ui/animation/KisDlgImportVideoAnimation.cpp
@@ -235,8 +235,13 @@ RenderedFrames KisDlgImportVideoAnimation::renderFrames(const QDir& directory)
, "Extracted %1 frames from %2 video.", "[progress]", "[suffix]");
QScopedPointer<KisFFMpegWrapper> ffmpeg(new KisFFMpegWrapper(this));
+
ffmpeg->startNonBlocking(ffmpegSettings);
- ffmpeg->waitForFinished();
+
+ bool ffmpegSuccess = ffmpeg->waitForFinished();
+ if (!ffmpegSuccess) {
+ return RenderedFrames();
+ }
frameFileList = directory.entryList(QStringList() << "output_*.png",QDir::Files);
frameFileList.replaceInStrings("output_", directory.absolutePath() + QDir::separator() + "output_");
@@ -274,8 +279,13 @@ RenderedFrames KisDlgImportVideoAnimation::renderFrames(const QDir& directory)
}
}
});
+
ffmpeg->startNonBlocking(ffmpegSettings);
- ffmpeg->waitForFinished();
+
+ bool ffmpegSuccess = ffmpeg->waitForFinished();
+ if (!ffmpegSuccess) {
+ return RenderedFrames();
+ }
dbgFile << "Assign to frames:" << ppVar(frameTimeList);
}
diff --git a/libs/ui/animation/KisFFMpegWrapper.cpp b/libs/ui/animation/KisFFMpegWrapper.cpp
index 4f34fe8db6..dfe5de5d36 100644
--- a/libs/ui/animation/KisFFMpegWrapper.cpp
+++ b/libs/ui/animation/KisFFMpegWrapper.cpp
@@ -128,6 +128,8 @@ void KisFFMpegWrapper::startNonBlocking(const KisFFMpegWrapperSettings &settings
m_progress->setRange(0, 100);
}
+ connect(m_progress.data(), SIGNAL(canceled()), m_process.data(), SLOT(kill()));
+
m_progress->show();
dbgFile << "Open progress dialog!";
@@ -190,11 +192,15 @@ KisImportExportErrorCode KisFFMpegWrapper::start(const KisFFMpegWrapperSettings
}
}
-void KisFFMpegWrapper::waitForFinished(int msecs)
+bool KisFFMpegWrapper::waitForFinished(int msecs)
{
- if (!m_process) return;
+ if (!m_process) return false;
+
+ if (m_process->waitForStarted(msecs)) {
+ return (m_process->waitForFinished(msecs) && m_process->exitStatus() == QProcess::ExitStatus::NormalExit);
+ }
- if (m_process->waitForStarted(msecs)) m_process->waitForFinished(msecs);
+ return false;
}
void KisFFMpegWrapper::updateProgressDialog(int progressValue) {
diff --git a/libs/ui/animation/KisFFMpegWrapper.h b/libs/ui/animation/KisFFMpegWrapper.h
index 67079c6c34..569893e597 100644
--- a/libs/ui/animation/KisFFMpegWrapper.h
+++ b/libs/ui/animation/KisFFMpegWrapper.h
@@ -52,7 +52,7 @@ public:
void startNonBlocking(const KisFFMpegWrapperSettings &settings);
KisImportExportErrorCode start(const KisFFMpegWrapperSettings &settings);
- void waitForFinished(int msecs = FFMPEG_TIMEOUT);
+ bool waitForFinished(int msecs = FFMPEG_TIMEOUT);
void reset();
static QJsonObject findProcessPath(const QString &processName, const QString &customLocation, bool processInfo);