Commit 3981425a authored by Andrey Butirsky's avatar Andrey Butirsky
Browse files

Calculate total directory size

BUG: 452352
parent 3b2a6e23
Pipeline #166853 passed with stage
in 5 minutes and 14 seconds
......@@ -71,12 +71,7 @@ QVariant ArchiveModel::data(const QModelIndex &index, int role) const
case FullPath:
return entry->name();
case Size:
if (entry->isDir()) {
uint dirs;
uint files;
entry->countChildren(dirs, files);
return KIO::itemsSummaryString(dirs + files, files, dirs, 0, false);
} else if (!entry->property("link").toString().isEmpty()) {
if (!entry->property("link").toString().isEmpty()) {
return QVariant();
} else {
return KIO::convertSize(entry->property("size").toULongLong());
......@@ -829,28 +824,30 @@ void ArchiveModel::countEntriesAndSize()
m_numberOfFiles = 0;
m_numberOfFolders = 0;
m_uncompressedSize = 0;
QElapsedTimer timer;
timer.start();
traverseAndCountDirNode(m_rootEntry.data());
traverseAndComputeDirSizes(m_rootEntry.data());
qCDebug(ARK) << "Time to count entries and size:" << timer.elapsed() << "ms";
}
void ArchiveModel::traverseAndCountDirNode(Archive::Entry *dir)
qulonglong ArchiveModel::traverseAndComputeDirSizes(Archive::Entry *dir)
{
const auto entries = dir->entries();
qulonglong uncompressedSize = 0;
for (Archive::Entry *entry : entries) {
if (entry->isDir()) {
traverseAndCountDirNode(entry);
m_numberOfFolders++;
uncompressedSize += traverseAndComputeDirSizes(entry);
} else {
m_numberOfFiles++;
m_uncompressedSize += entry->property("size").toULongLong();
uncompressedSize += entry->property("size").toULongLong();
}
}
dir->setProperty("size", uncompressedSize);
return uncompressedSize;
}
qulonglong ArchiveModel::numberOfFiles() const
......@@ -865,7 +862,7 @@ qulonglong ArchiveModel::numberOfFolders() const
qulonglong ArchiveModel::uncompressedSize() const
{
return m_uncompressedSize;
return m_rootEntry.data()->property("size").toULongLong();
}
QList<int> ArchiveModel::shownColumns() const
......
......@@ -162,7 +162,7 @@ private:
void insertEntry(Archive::Entry *entry, InsertBehaviour behaviour = NotifyViews);
void newEntry(Kerfuffle::Archive::Entry *receivedEntry, InsertBehaviour behaviour);
void traverseAndCountDirNode(Archive::Entry *dir);
qulonglong traverseAndComputeDirSizes(Archive::Entry *dir);
QList<int> m_showColumns;
QScopedPointer<Kerfuffle::Archive> m_archive;
......@@ -174,7 +174,6 @@ private:
qulonglong m_numberOfFiles;
qulonglong m_numberOfFolders;
qulonglong m_uncompressedSize;
// Whether a file entry has been listed. Used to ensure all relevant columns are shown,
// since directories might have fewer columns than files.
......
......@@ -98,7 +98,7 @@ void InfoPanel::setIndex(const QModelIndex& index)
uint dirs;
uint files;
entry->countChildren(dirs, files);
additionalInfo->setText(KIO::itemsSummaryString(dirs + files, files, dirs, 0, false));
additionalInfo->setText(KIO::itemsSummaryString(dirs + files, files, dirs, entry->property("size").toULongLong(), true));
} else if (!entry->property("link").toString().isEmpty()) {
additionalInfo->setText(i18n("Symbolic Link"));
} else {
......
......@@ -898,12 +898,13 @@ void Part::slotCompleted()
if (m_model->rowCount() == 0) {
qCWarning(ARK) << "No entry listed by the plugin";
displayMsgWidget(KMessageWidget::Warning, xi18nc("@info", "The archive is empty or Ark could not open its content."));
} else if (m_model->rowCount() == 1) {
if (m_model->archive()->mimeType().inherits(QStringLiteral("application/x-cd-image")) &&
m_model->entryForIndex(m_model->index(0, 0))->fullPath() == QLatin1String("README.TXT")) {
qCWarning(ARK) << "Detected ISO image with UDF filesystem";
displayMsgWidget(KMessageWidget::Warning, xi18nc("@info", "Ark does not currently support ISO files with UDF filesystem."));
}
} else if (m_model->rowCount() == 1 &&
m_model->archive()->mimeType().inherits(QStringLiteral("application/x-cd-image")) &&
m_model->entryForIndex(m_model->index(0, 0))->fullPath() == QLatin1String("README.TXT")) {
qCWarning(ARK) << "Detected ISO image with UDF filesystem";
displayMsgWidget(KMessageWidget::Warning, xi18nc("@info", "Ark does not currently support ISO files with UDF filesystem."));
} else {
m_model->countEntriesAndSize();
}
if (arguments().metaData()[QStringLiteral("showExtractDialog")] == QLatin1String("true")) {
......@@ -1599,6 +1600,8 @@ void Part::slotAddFilesDone(KJob* job)
setArguments(args);
openUrl(QUrl::fromLocalFile(m_model->archive()->multiVolumeName()));
} else {
m_model->countEntriesAndSize();
}
}
m_cutIndexes.clear();
......@@ -1610,6 +1613,8 @@ void Part::slotPasteFilesDone(KJob *job)
{
if (job->error() && job->error() != KJob::KilledJobError) {
KMessageBox::error(widget(), job->errorString());
} else {
m_model->countEntriesAndSize();
}
m_cutIndexes.clear();
m_model->filesToMove.clear();
......@@ -1620,6 +1625,8 @@ void Part::slotDeleteFilesDone(KJob* job)
{
if (job->error() && job->error() != KJob::KilledJobError) {
KMessageBox::error(widget(), job->errorString());
} else {
m_model->countEntriesAndSize();
}
m_cutIndexes.clear();
m_model->filesToMove.clear();
......@@ -1654,7 +1661,6 @@ void Part::slotDeleteFiles()
void Part::slotShowProperties()
{
m_model->countEntriesAndSize();
QPointer<Kerfuffle::PropertiesDialog> dialog(new Kerfuffle::PropertiesDialog(nullptr,
m_model->archive(),
m_model->numberOfFiles(),
......
Supports Markdown
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