summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElvis Angelaccio <elvis.angelaccio@kde.org>2016-11-27 16:14:02 (GMT)
committerElvis Angelaccio <elvis.angelaccio@kde.org>2016-11-27 16:14:02 (GMT)
commit864d77f14c28ef48d8d8c6c9a2ebca4928e92a09 (patch)
treeb3b0a9a4cb10b86aadbd54e253906e47d13eb93b
parenta188149abf80140955ec66275bffe8d4e912b172 (diff)
Properly kill BatchExtract jobs
We need to reimplement `KJob::doKill()` both in `BatchExtract` and `BatchExtractJob`. In the latter class we use an enum to keep track of which sub-job we are running and kill it when necessary. Differential Revision: https://phabricator.kde.org/D3521
-rw-r--r--app/batchextract.cpp9
-rw-r--r--app/batchextract.h2
-rw-r--r--kerfuffle/jobs.cpp20
-rw-r--r--kerfuffle/jobs.h11
4 files changed, 37 insertions, 5 deletions
diff --git a/app/batchextract.cpp b/app/batchextract.cpp
index 52cb73a..d8e40b6 100644
--- a/app/batchextract.cpp
+++ b/app/batchextract.cpp
@@ -80,6 +80,15 @@ void BatchExtract::addExtraction(const QUrl& url)
this, &BatchExtract::slotUserQuery);
}
+bool BatchExtract::doKill()
+{
+ if (subjobs().isEmpty()) {
+ return false;
+ }
+
+ return subjobs().first()->kill();
+}
+
void BatchExtract::slotUserQuery(Kerfuffle::Query *query)
{
query->execute();
diff --git a/app/batchextract.h b/app/batchextract.h
index 33efe17..72d3440 100644
--- a/app/batchextract.h
+++ b/app/batchextract.h
@@ -74,6 +74,8 @@ public:
*/
void addExtraction(const QUrl& url);
+ bool doKill() Q_DECL_OVERRIDE;
+
/**
* A wrapper that calls slotStartJob() when the event loop has started.
*/
diff --git a/kerfuffle/jobs.cpp b/kerfuffle/jobs.cpp
index 8cd2d11..dd7fbea 100644
--- a/kerfuffle/jobs.cpp
+++ b/kerfuffle/jobs.cpp
@@ -367,6 +367,15 @@ void BatchExtractJob::doWork()
m_loadJob->start();
}
+bool BatchExtractJob::doKill()
+{
+ if (m_step == Loading) {
+ return m_loadJob->kill();
+ }
+
+ return m_extractJob->kill();
+}
+
void BatchExtractJob::slotLoadingProgress(double progress)
{
// Progress from LoadJob counts only for 50% of the BatchExtractJob's duration.
@@ -395,16 +404,17 @@ void BatchExtractJob::slotLoadingFinished(KJob *job)
Kerfuffle::ExtractionOptions options;
options.setPreservePaths(m_preservePaths);
- auto extractJob = archive()->extractFiles({}, m_destination, options);
- if (extractJob) {
- connect(extractJob, &KJob::result, this, &BatchExtractJob::emitResult);
- connect(extractJob, &Kerfuffle::Job::userQuery, this, &BatchExtractJob::userQuery);
+ m_extractJob = archive()->extractFiles({}, m_destination, options);
+ if (m_extractJob) {
+ connect(m_extractJob, &KJob::result, this, &BatchExtractJob::emitResult);
+ connect(m_extractJob, &Kerfuffle::Job::userQuery, this, &BatchExtractJob::userQuery);
if (archiveInterface()->hasBatchExtractionProgress()) {
// The LoadJob is done, change slot and start setting the percentage from m_lastPercentage on.
disconnect(archiveInterface(), &ReadOnlyArchiveInterface::progress, this, &BatchExtractJob::slotLoadingProgress);
connect(archiveInterface(), &ReadOnlyArchiveInterface::progress, this, &BatchExtractJob::slotExtractProgress);
}
- extractJob->start();
+ m_step = Extracting;
+ m_extractJob->start();
} else {
emitResult();
}
diff --git a/kerfuffle/jobs.h b/kerfuffle/jobs.h
index 174b55f..fe9bbb5 100644
--- a/kerfuffle/jobs.h
+++ b/kerfuffle/jobs.h
@@ -166,14 +166,25 @@ signals:
public slots:
virtual void doWork() Q_DECL_OVERRIDE;
+protected:
+ virtual bool doKill() Q_DECL_OVERRIDE;
+
private slots:
void slotLoadingProgress(double progress);
void slotExtractProgress(double progress);
void slotLoadingFinished(KJob *job);
private:
+
+ /**
+ * Tracks whether the job is loading or extracting the archive.
+ */
+ enum Step {Loading, Extracting};
+
void setupDestination();
+ Step m_step = Loading;
+ ExtractJob *m_extractJob = Q_NULLPTR;
LoadJob *m_loadJob;
QString m_destination;
bool m_autoSubfolder;