Commit 660076c4 authored by Elvis Angelaccio's avatar Elvis Angelaccio
Browse files

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
parent 32439e4d
......@@ -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
......
......@@ -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());
......
......@@ -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();
......
......@@ -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;
};
/**
......
......@@ -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;
......
......@@ -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:
......
......@@ -145,6 +145,11 @@ bool LibarchivePlugin::testArchive()
return false;
}
bool LibarchivePlugin::hasBatchExtractionProgress() const
{
return true;
}
bool LibarchivePlugin::doKill()
{
return true;
......
......@@ -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
......
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