diff --git a/app/batchextract.h b/app/batchextract.h --- a/app/batchextract.h +++ b/app/batchextract.h @@ -74,6 +74,8 @@ */ void addExtraction(const QUrl& url); + bool doKill() Q_DECL_OVERRIDE; + /** * A wrapper that calls slotStartJob() when the event loop has started. */ diff --git a/app/batchextract.cpp b/app/batchextract.cpp --- a/app/batchextract.cpp +++ b/app/batchextract.cpp @@ -80,6 +80,15 @@ 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/kerfuffle/jobs.h b/kerfuffle/jobs.h --- a/kerfuffle/jobs.h +++ b/kerfuffle/jobs.h @@ -166,14 +166,25 @@ 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; diff --git a/kerfuffle/jobs.cpp b/kerfuffle/jobs.cpp --- a/kerfuffle/jobs.cpp +++ b/kerfuffle/jobs.cpp @@ -367,6 +367,15 @@ 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 @@ 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(); }