Commit d78e151c authored by Ragnar Thomsen's avatar Ragnar Thomsen

Add number of folders to PropertiesDialog and fix bugs

The number of folders is now also shown in PropertiesDialog. There was a
bug where number of files/folders and total uncompressed size didn't get
updated after adding/deleting files from archive. This is now fixed by
counting the files/folders and uncompressed size in
ArchiveModel::countEntriesAndSize().

BUG: 363368
FIXED-IN: 16.08.0
Differential Revision: D2130
GUI:
parent af3ba6c2
......@@ -130,6 +130,7 @@ Archive::Archive(ReadOnlyArchiveInterface *archiveInterface, bool isReadOnly, QO
, m_error(NoError)
, m_encryptionType(Unencrypted)
, m_numberOfFiles(0)
, m_numberOfFolders(0)
{
qCDebug(ARK) << "Created archive instance";
......@@ -246,6 +247,16 @@ qulonglong Archive::numberOfFiles()
return m_numberOfFiles;
}
qulonglong Archive::numberOfFolders()
{
if (!isValid()) {
return 0;
}
listIfNotListed();
return m_numberOfFolders;
}
qulonglong Archive::unpackedSize()
{
if (!isValid()) {
......@@ -273,9 +284,7 @@ QString Archive::subfolderName()
void Archive::onNewEntry(const ArchiveEntry &entry)
{
if (!entry[IsDirectory].toBool()) {
m_numberOfFiles++;
}
entry[IsDirectory].toBool() ? m_numberOfFolders++ : m_numberOfFiles++;
}
bool Archive::isValid() const
......
......@@ -153,6 +153,7 @@ class KERFUFFLE_EXPORT Archive : public QObject
Q_PROPERTY(bool isSingleFolderArchive READ isSingleFolderArchive)
Q_PROPERTY(EncryptionType encryptionType READ encryptionType)
Q_PROPERTY(qulonglong numberOfFiles READ numberOfFiles)
Q_PROPERTY(qulonglong numberOfFolders READ numberOfFolders)
Q_PROPERTY(qulonglong unpackedSize READ unpackedSize)
Q_PROPERTY(qulonglong packedSize READ packedSize)
Q_PROPERTY(QString subfolderName READ subfolderName)
......@@ -175,6 +176,7 @@ public:
bool hasComment() const;
EncryptionType encryptionType();
qulonglong numberOfFiles();
qulonglong numberOfFolders();
qulonglong unpackedSize();
qulonglong packedSize() const;
QString subfolderName();
......@@ -253,6 +255,7 @@ private:
ArchiveError m_error;
EncryptionType m_encryptionType;
qulonglong m_numberOfFiles;
qulonglong m_numberOfFolders;
QMimeType m_mimeType;
};
......
......@@ -49,7 +49,7 @@ public:
}
};
PropertiesDialog::PropertiesDialog(QWidget *parent, Archive *archive)
PropertiesDialog::PropertiesDialog(QWidget *parent, Archive *archive, qulonglong numberOfFiles, qulonglong numberOfFolders, qulonglong size)
: QDialog(parent, Qt::Dialog)
{
qCDebug(ARK) << "PropertiesDialog loaded";
......@@ -65,8 +65,9 @@ PropertiesDialog::PropertiesDialog(QWidget *parent, Archive *archive)
m_ui->lblMimetype->setText(archive->mimeType().name());
m_ui->lblReadOnly->setText(archive->isReadOnly() ? i18n("yes") : i18n("no"));
m_ui->lblHasComment->setText(archive->hasComment() ? i18n("yes") : i18n("no"));
m_ui->lblNumberOfFiles->setText(QString::number(archive->numberOfFiles()));
m_ui->lblUnpackedSize->setText(KIO::convertSize(archive->unpackedSize()));
m_ui->lblNumberOfEntries->setText(i18np("%1 file", "%1 files", numberOfFiles) +
i18np(", %1 folder", ", %1 folders", numberOfFolders));
m_ui->lblUnpackedSize->setText(KIO::convertSize(size));
m_ui->lblPackedSize->setText(KIO::convertSize(archive->packedSize()));
m_ui->lblCompressionRatio->setText(QString::number(float(archive->unpackedSize()) / float(archive->packedSize()), 'f', 1));
m_ui->lblLastModified->setText(fi.lastModified().toString(QStringLiteral("yyyy-MM-dd HH:mm")));
......
......@@ -42,7 +42,7 @@ class KERFUFFLE_EXPORT PropertiesDialog : public QDialog
Q_OBJECT
public:
explicit PropertiesDialog(QWidget *parent, Archive *archive);
explicit PropertiesDialog(QWidget *parent, Archive *archive, qulonglong numberOfFiles, qulonglong numberOfFolders, qulonglong size);
private:
QString calcHash(QCryptographicHash::Algorithm algorithm, const QString &path);
......
......@@ -38,6 +38,13 @@
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="lblArchiveName">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
......@@ -111,12 +118,12 @@
<item row="6" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Number of files:</string>
<string>Number of entries:</string>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QLabel" name="lblNumberOfFiles">
<widget class="QLabel" name="lblNumberOfEntries">
<property name="text">
<string/>
</property>
......@@ -232,13 +239,6 @@
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="lblArchiveName">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
<item>
......
......@@ -32,6 +32,7 @@
#include <QDateTime>
#include <QDBusConnection>
#include <QElapsedTimer>
#include <QMimeData>
#include <QMimeDatabase>
#include <QPersistentModelIndex>
......@@ -283,6 +284,8 @@ ArchiveModel::ArchiveModel(const QString &dbusPathName, QObject *parent)
: QAbstractItemModel(parent)
, m_rootNode(new ArchiveDirNode(0, ArchiveEntry()))
, m_dbusPathName(dbusPathName)
, m_numberOfFiles(0)
, m_numberOfFolders(0)
{
}
......@@ -1012,4 +1015,51 @@ void ArchiveModel::slotCleanupEmptyDirs()
}
}
void ArchiveModel::countEntriesAndSize() {
// This function is used to count the number of folders/files and
// the total compressed size. This is needed for PropertiesDialog
// to update the corresponding values after adding/deleting files.
// When ArchiveModel has been properly fixed, this code can likely
// be removed.
m_numberOfFiles = 0;
m_numberOfFolders = 0;
m_uncompressedSize = 0;
QElapsedTimer timer;
timer.start();
traverseAndCountDirNode(m_rootNode);
qCDebug(ARK) << "Time to count entries and size:" << timer.elapsed() << "ms";
}
void ArchiveModel::traverseAndCountDirNode(ArchiveDirNode *dir)
{
foreach(ArchiveNode *node, dir->entries()) {
if (node->isDir()) {
traverseAndCountDirNode(dynamic_cast<ArchiveDirNode*>(node));
m_numberOfFolders++;
} else {
m_numberOfFiles++;
m_uncompressedSize += node->entry()[Size].toULongLong();
}
}
}
qulonglong ArchiveModel::numberOfFiles() const
{
return m_numberOfFiles;
}
qulonglong ArchiveModel::numberOfFolders() const
{
return m_numberOfFolders;
}
qulonglong ArchiveModel::uncompressedSize() const
{
return m_uncompressedSize;
}
......@@ -85,6 +85,11 @@ public:
*/
void encryptArchive(const QString &password, bool encryptHeader);
void countEntriesAndSize();
qulonglong numberOfFiles() const;
qulonglong numberOfFolders() const;
qulonglong uncompressedSize() const;
signals:
void loadingStarted();
void loadingFinished(KJob *);
......@@ -124,12 +129,18 @@ private:
void insertNode(ArchiveNode *node, InsertBehaviour behaviour = NotifyViews);
void newEntry(const Kerfuffle::ArchiveEntry& entry, InsertBehaviour behaviour);
void traverseAndCountDirNode(ArchiveDirNode *dir);
QList<Kerfuffle::ArchiveEntry> m_newArchiveEntries; // holds entries from opening a new archive until it's totally open
QList<int> m_showColumns;
QScopedPointer<Kerfuffle::Archive> m_archive;
ArchiveDirNode *m_rootNode;
QString m_dbusPathName;
qulonglong m_numberOfFiles;
qulonglong m_numberOfFolders;
qulonglong m_uncompressedSize;
};
#endif // ARCHIVEMODEL_H
......@@ -1307,8 +1307,12 @@ void Part::slotDeleteFiles()
void Part::slotShowProperties()
{
m_model->countEntriesAndSize();
QPointer<Kerfuffle::PropertiesDialog> dialog(new Kerfuffle::PropertiesDialog(0,
m_model->archive()));
m_model->archive(),
m_model->numberOfFiles(),
m_model->numberOfFolders(),
m_model->uncompressedSize()));
dialog.data()->show();
}
......
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