summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRagnar Thomsen <rthomsen6@gmail.com>2016-08-11 16:18:56 (GMT)
committerRagnar Thomsen <rthomsen6@gmail.com>2016-08-11 16:20:14 (GMT)
commit41e3d16e783b3f61793e21752a883edc3333e1b2 (patch)
tree2d21d62a1527a640ec400c9db88f3a6aebcf7920
parent4171721497331a20bf17f7bcd294123be52bfac0 (diff)
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
-rw-r--r--kerfuffle/jobs.cpp38
1 files changed, 29 insertions, 9 deletions
diff --git a/kerfuffle/jobs.cpp b/kerfuffle/jobs.cpp
index bedc3bf..986b5bc 100644
--- a/kerfuffle/jobs.cpp
+++ b/kerfuffle/jobs.cpp
@@ -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) {