summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElvis Angelaccio <elvis.angelaccio@kde.org>2016-11-27 11:12:13 (GMT)
committerElvis Angelaccio <elvis.angelaccio@kde.org>2016-11-27 11:20:46 (GMT)
commit660076c4c297a6bd1c12612b524d6168ae8dc09e (patch)
tree474348968bb408a3bca2ba75ec4abf11ae8d9fab
parent32439e4d7a751063fa5f345b42df47f0d3210571 (diff)
Don't show two progress bars with batch extractions
BatchExtractJob runs a LoadJob first and an ExtractJob after, which results in two different progress bars in the notification tray. This patch changes how the percentage is computed: the first 50% is from the LoadJob, the 2nd 50% from the ExtractJob. This ensures that only one progress bar shows up while the wrapper job is running. This will only work if the interface is able to report progress for both LoadJobs and ExtractJobs (currently only libarchive and clirar). Differential Revision: D3518
-rw-r--r--kerfuffle/archiveinterface.cpp5
-rw-r--r--kerfuffle/archiveinterface.h5
-rw-r--r--kerfuffle/jobs.cpp24
-rw-r--r--kerfuffle/jobs.h3
-rw-r--r--plugins/clirarplugin/cliplugin.cpp5
-rw-r--r--plugins/clirarplugin/cliplugin.h1
-rw-r--r--plugins/libarchive/libarchiveplugin.cpp5
-rw-r--r--plugins/libarchive/libarchiveplugin.h1
8 files changed, 47 insertions, 2 deletions
diff --git a/kerfuffle/archiveinterface.cpp b/kerfuffle/archiveinterface.cpp
index 6728135..dbfe5dc 100644
--- a/kerfuffle/archiveinterface.cpp
+++ b/kerfuffle/archiveinterface.cpp
@@ -264,6 +264,11 @@ QMimeType ReadOnlyArchiveInterface::mimetype() const
return m_mimetype;
}
+bool ReadOnlyArchiveInterface::hasBatchExtractionProgress() const
+{
+ return false;
+}
+
bool ReadWriteArchiveInterface::isReadOnly() const
{
// We set corrupt archives to read-only to avoid add/delete actions, that
diff --git a/kerfuffle/archiveinterface.h b/kerfuffle/archiveinterface.h
index 64f9177..04998ff 100644
--- a/kerfuffle/archiveinterface.h
+++ b/kerfuffle/archiveinterface.h
@@ -159,6 +159,11 @@ public:
int numberOfEntries() const;
QMimeType mimetype() const;
+ /**
+ * @return Whether the interface supports progress reporting for BatchExtractJobs.
+ */
+ virtual bool hasBatchExtractionProgress() const;
+
signals:
void cancelled();
void error(const QString &message, const QString &details = QString());
diff --git a/kerfuffle/jobs.cpp b/kerfuffle/jobs.cpp
index a85c7ef..8cd2d11 100644
--- a/kerfuffle/jobs.cpp
+++ b/kerfuffle/jobs.cpp
@@ -356,8 +356,10 @@ BatchExtractJob::BatchExtractJob(LoadJob *loadJob, const QString &destination, b
void BatchExtractJob::doWork()
{
connect(m_loadJob, &KJob::result, this, &BatchExtractJob::slotLoadingFinished);
- // progress() will be actually emitted by the ExtractJob, but the archiveInterface() is the same.
- connect(archiveInterface(), &ReadOnlyArchiveInterface::progress, this, &BatchExtractJob::onProgress);
+ if (archiveInterface()->hasBatchExtractionProgress()) {
+ // progress() will be actually emitted by the LoadJob, but the archiveInterface() is the same.
+ connect(archiveInterface(), &ReadOnlyArchiveInterface::progress, this, &BatchExtractJob::slotLoadingProgress);
+ }
// Forward LoadJob's signals.
connect(m_loadJob, &Kerfuffle::Job::newEntry, this, &BatchExtractJob::newEntry);
@@ -365,6 +367,19 @@ void BatchExtractJob::doWork()
m_loadJob->start();
}
+void BatchExtractJob::slotLoadingProgress(double progress)
+{
+ // Progress from LoadJob counts only for 50% of the BatchExtractJob's duration.
+ m_lastPercentage = static_cast<unsigned long>(50.0*progress);
+ setPercent(m_lastPercentage);
+}
+
+void BatchExtractJob::slotExtractProgress(double progress)
+{
+ // The 2nd 50% of the BatchExtractJob's duration comes from the ExtractJob.
+ setPercent(m_lastPercentage + static_cast<unsigned long>(50.0*progress));
+}
+
void BatchExtractJob::slotLoadingFinished(KJob *job)
{
if (job->error()) {
@@ -384,6 +399,11 @@ void BatchExtractJob::slotLoadingFinished(KJob *job)
if (extractJob) {
connect(extractJob, &KJob::result, this, &BatchExtractJob::emitResult);
connect(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();
} else {
emitResult();
diff --git a/kerfuffle/jobs.h b/kerfuffle/jobs.h
index d5f0db6..174b55f 100644
--- a/kerfuffle/jobs.h
+++ b/kerfuffle/jobs.h
@@ -167,6 +167,8 @@ public slots:
virtual void doWork() Q_DECL_OVERRIDE;
private slots:
+ void slotLoadingProgress(double progress);
+ void slotExtractProgress(double progress);
void slotLoadingFinished(KJob *job);
private:
@@ -176,6 +178,7 @@ private:
QString m_destination;
bool m_autoSubfolder;
bool m_preservePaths;
+ unsigned long m_lastPercentage = 0;
};
/**
diff --git a/plugins/clirarplugin/cliplugin.cpp b/plugins/clirarplugin/cliplugin.cpp
index d0eb730..311edb5 100644
--- a/plugins/clirarplugin/cliplugin.cpp
+++ b/plugins/clirarplugin/cliplugin.cpp
@@ -570,6 +570,11 @@ bool CliPlugin::readExtractLine(const QString &line)
return true;
}
+bool CliPlugin::hasBatchExtractionProgress() const
+{
+ return true;
+}
+
void CliPlugin::ignoreLines(int lines, ParseState nextState)
{
m_remainingIgnoreLines = lines;
diff --git a/plugins/clirarplugin/cliplugin.h b/plugins/clirarplugin/cliplugin.h
index 59d5e52..f597f8d 100644
--- a/plugins/clirarplugin/cliplugin.h
+++ b/plugins/clirarplugin/cliplugin.h
@@ -38,6 +38,7 @@ public:
virtual void resetParsing() Q_DECL_OVERRIDE;
virtual bool readListLine(const QString &line) Q_DECL_OVERRIDE;
virtual bool readExtractLine(const QString &line) Q_DECL_OVERRIDE;
+ virtual bool hasBatchExtractionProgress() const Q_DECL_OVERRIDE;
private:
diff --git a/plugins/libarchive/libarchiveplugin.cpp b/plugins/libarchive/libarchiveplugin.cpp
index 1d889e5..5894e2f 100644
--- a/plugins/libarchive/libarchiveplugin.cpp
+++ b/plugins/libarchive/libarchiveplugin.cpp
@@ -145,6 +145,11 @@ bool LibarchivePlugin::testArchive()
return false;
}
+bool LibarchivePlugin::hasBatchExtractionProgress() const
+{
+ return true;
+}
+
bool LibarchivePlugin::doKill()
{
return true;
diff --git a/plugins/libarchive/libarchiveplugin.h b/plugins/libarchive/libarchiveplugin.h
index 85a5ec4..2b00385 100644
--- a/plugins/libarchive/libarchiveplugin.h
+++ b/plugins/libarchive/libarchiveplugin.h
@@ -55,6 +55,7 @@ public:
virtual bool deleteFiles(const QVector<Archive::Entry*> &files) Q_DECL_OVERRIDE;
virtual bool addComment(const QString &comment) Q_DECL_OVERRIDE;
virtual bool testArchive() Q_DECL_OVERRIDE;
+ virtual bool hasBatchExtractionProgress() const Q_DECL_OVERRIDE;
protected:
struct ArchiveReadCustomDeleter