Commit 41e3d16e authored by Ragnar Thomsen's avatar Ragnar Thomsen
Browse files

AddJob: Count number of entries to be added

Count the total number of entries to be added using QDirIterator. We can
then use the number to display a correct string in statusbar when adding
files. Also pass the number to AddFiles() so interfaces/plugins can use
it for showing progress in %.

Differential Revision: D2397
parent 41717214
......@@ -29,6 +29,7 @@
#include "ark_debug.h"
#include <QDir>
#include <QDirIterator>
#include <QFileInfo>
#include <QRegularExpression>
#include <QThread>
......@@ -420,15 +421,7 @@ AddJob::AddJob(const QStringList& files, const CompressionOptions& options , Rea
void AddJob::doWork()
{
qCDebug(ARK) << "AddJob: going to add" << m_files.count() << "file(s)";
emit description(this, i18np("Adding a file", "Adding %1 files", m_files.count()));
ReadWriteArchiveInterface *m_writeInterface =
qobject_cast<ReadWriteArchiveInterface*>(archiveInterface());
Q_ASSERT(m_writeInterface);
// Set current dir.
const QString globalWorkDir = m_options.value(QStringLiteral("GlobalWorkDir")).toString();
const QDir workDir = globalWorkDir.isEmpty() ? QDir::current() : QDir(globalWorkDir);
if (!globalWorkDir.isEmpty()) {
......@@ -437,6 +430,33 @@ void AddJob::doWork()
QDir::setCurrent(globalWorkDir);
}
// Count total number of entries to be added.
qulonglong totalCount = 0;
QElapsedTimer timer;
timer.start();
foreach (const QString &f, m_files) {
totalCount++;
if (QFileInfo(f).isDir()) {
QDirIterator it(f, QDir::AllEntries | QDir::Readable | QDir::Hidden |
QDir::NoDotAndDotDot, QDirIterator::Subdirectories);
while (it.hasNext()) {
it.next();
totalCount++;
}
}
}
qCDebug(ARK) << "Counted" << totalCount << "entries in" << timer.elapsed() << "ms";
m_options[QStringLiteral("NumberOfEntries")] = totalCount;
qCDebug(ARK) << "AddJob: going to add" << totalCount << "entries";
emit description(this, i18np("Adding a file", "Adding %1 files", totalCount));
ReadWriteArchiveInterface *m_writeInterface =
qobject_cast<ReadWriteArchiveInterface*>(archiveInterface());
Q_ASSERT(m_writeInterface);
// The file paths must be relative to GlobalWorkDir.
QStringList relativeFiles;
foreach (const QString& file, m_files) {
......
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