Git commit d78e151c7d5e2d4b7e8f514c6d488e237a1f14ec by Ragnar Thomsen. Committed on 10/07/2016 at 16:00. Pushed by rthomsen into branch 'master'.
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: M +12 -3 kerfuffle/archive_kerfuffle.cpp M +3 -0 kerfuffle/archive_kerfuffle.h M +4 -3 kerfuffle/propertiesdialog.cpp M +1 -1 kerfuffle/propertiesdialog.h M +9 -9 kerfuffle/propertiesdialog.ui M +50 -0 part/archivemodel.cpp M +11 -0 part/archivemodel.h M +5 -1 part/part.cpp http://commits.kde.org/ark/d78e151c7d5e2d4b7e8f514c6d488e237a1f14ec diff --git a/kerfuffle/archive_kerfuffle.cpp b/kerfuffle/archive_kerfuffle.cpp index fbb5a29..6f81c10 100644 --- a/kerfuffle/archive_kerfuffle.cpp +++ b/kerfuffle/archive_kerfuffle.cpp @@ -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 diff --git a/kerfuffle/archive_kerfuffle.h b/kerfuffle/archive_kerfuffle.h index 3cdacf3..8fcf2dc 100644 --- a/kerfuffle/archive_kerfuffle.h +++ b/kerfuffle/archive_kerfuffle.h @@ -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; }; diff --git a/kerfuffle/propertiesdialog.cpp b/kerfuffle/propertiesdialog.cpp index 9e30da4..7f3c3e8 100644 --- a/kerfuffle/propertiesdialog.cpp +++ b/kerfuffle/propertiesdialog.cpp @@ -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"))); diff --git a/kerfuffle/propertiesdialog.h b/kerfuffle/propertiesdialog.h index 2aef4bd..be797c4 100644 --- a/kerfuffle/propertiesdialog.h +++ b/kerfuffle/propertiesdialog.h @@ -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); diff --git a/kerfuffle/propertiesdialog.ui b/kerfuffle/propertiesdialog.ui index 54451f3..f329441 100644 --- a/kerfuffle/propertiesdialog.ui +++ b/kerfuffle/propertiesdialog.ui @@ -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> diff --git a/part/archivemodel.cpp b/part/archivemodel.cpp index 0599e0a..0e2016a 100644 --- a/part/archivemodel.cpp +++ b/part/archivemodel.cpp @@ -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; +} diff --git a/part/archivemodel.h b/part/archivemodel.h index 9a2b551..b386eb1 100644 --- a/part/archivemodel.h +++ b/part/archivemodel.h @@ -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 diff --git a/part/part.cpp b/part/part.cpp index fc32747..b87bcaf 100644 --- a/part/part.cpp +++ b/part/part.cpp @@ -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(); } _______________________________________________ kde-doc-english mailing list [email protected] https://mail.kde.org/mailman/listinfo/kde-doc-english
