Commit 864d77f1 authored by Elvis Angelaccio's avatar Elvis Angelaccio
Browse files

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
parent a188149a
......@@ -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();
......
......@@ -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.
*/
......
......@@ -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();
}
......
......@@ -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;
......
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