diff --git a/kerfuffle/archiveentry.h b/kerfuffle/archiveentry.h --- a/kerfuffle/archiveentry.h +++ b/kerfuffle/archiveentry.h @@ -29,7 +29,7 @@ #include "archive_kerfuffle.h" #include - +#include namespace Kerfuffle { @@ -94,6 +94,7 @@ int row() const; Entry *find(const QString &name) const; Entry *findByPath(const QStringList & pieces, int index = 0) const; + QIcon icon() const; /** * Fills @p dirs and @p files with the number of directories and files @@ -128,6 +129,7 @@ bool m_isDirectory; bool m_isExecutable; bool m_isPasswordProtected; + mutable QIcon m_icon; }; QDebug KERFUFFLE_EXPORT operator<<(QDebug d, const Kerfuffle::Archive::Entry &entry); diff --git a/kerfuffle/archiveentry.cpp b/kerfuffle/archiveentry.cpp --- a/kerfuffle/archiveentry.cpp +++ b/kerfuffle/archiveentry.cpp @@ -25,6 +25,8 @@ #include "archiveentry.h" +#include + namespace Kerfuffle { Archive::Entry::Entry(QObject *parent, const QString &fullPath, const QString &rootNode) : QObject(parent) @@ -201,6 +203,22 @@ } } +QIcon Archive::Entry::icon() const +{ + if (m_icon.isNull()) { + QMimeDatabase db; + + if (m_isDirectory) { + static QIcon directoryIcon = QIcon::fromTheme(db.mimeTypeForName(QStringLiteral("inode/directory")).iconName()); + m_icon = directoryIcon; + } else { + m_icon = QIcon::fromTheme(db.mimeTypeForFile(m_name, QMimeDatabase::MatchMode::MatchExtension).iconName()); + } + } + + return m_icon; +} + bool Archive::Entry::operator==(const Archive::Entry &right) const { return m_fullPath == right.m_fullPath; diff --git a/part/archivemodel.h b/part/archivemodel.h --- a/part/archivemodel.h +++ b/part/archivemodel.h @@ -134,8 +134,6 @@ static QMap entryMap(const QVector &entries); - const QHash entryIcons() const; - QMap filesToMove; QMap filesToCopy; diff --git a/part/archivemodel.cpp b/part/archivemodel.cpp --- a/part/archivemodel.cpp +++ b/part/archivemodel.cpp @@ -131,9 +131,9 @@ } case Qt::DecorationRole: if (index.column() == 0) { - const Archive::Entry *e = static_cast(index.internalPointer()); + Archive::Entry *e = static_cast(index.internalPointer()); QIcon::Mode mode = (filesToMove.contains(e->fullPath())) ? QIcon::Disabled : QIcon::Normal; - return m_entryIcons.value(e->fullPath(NoTrailingSlash)).pixmap(QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize), mode); + return e->icon().pixmap(QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize), mode); } return QVariant(); case Qt::FontRole: { @@ -454,7 +454,6 @@ Q_UNUSED(index); beginRemoveRows(indexForEntry(parent), entry->row(), entry->row()); - m_entryIcons.remove(parent->entries().at(entry->row())->fullPath(NoTrailingSlash)); parent->removeEntryAt(entry->row()); endRemoveRows(); } @@ -589,14 +588,6 @@ if (behaviour == NotifyViews) { endInsertRows(); } - - // Save an icon for each newly added entry. - QMimeDatabase db; - QIcon icon; - entry->isDir() - ? icon = QIcon::fromTheme(db.mimeTypeForName(QStringLiteral("inode/directory")).iconName()) - : icon = QIcon::fromTheme(db.mimeTypeForFile(entry->fullPath()).iconName()); - m_entryIcons.insert(entry->fullPath(NoTrailingSlash), icon); } Kerfuffle::Archive* ArchiveModel::archive() const @@ -839,11 +830,6 @@ return map; } -const QHash ArchiveModel::entryIcons() const -{ - return m_entryIcons; -} - void ArchiveModel::slotCleanupEmptyDirs() { QList queue; @@ -874,7 +860,6 @@ Archive::Entry *rawEntry = static_cast(node.internalPointer()); qCDebug(ARK) << "Delete with parent entries " << rawEntry->getParent()->entries() << " and row " << rawEntry->row(); beginRemoveRows(parent(node), rawEntry->row(), rawEntry->row()); - m_entryIcons.remove(rawEntry->getParent()->entries().at(rawEntry->row())->fullPath(NoTrailingSlash)); rawEntry->getParent()->removeEntryAt(rawEntry->row()); endRemoveRows(); } diff --git a/part/overwritedialog.h b/part/overwritedialog.h --- a/part/overwritedialog.h +++ b/part/overwritedialog.h @@ -43,7 +43,7 @@ { Q_OBJECT public: - explicit OverwriteDialog(QWidget *parent, const QList &entries, const QHash &icons, bool error = false); + explicit OverwriteDialog(QWidget *parent, const QList &entries, bool error = false); ~OverwriteDialog() override; private: diff --git a/part/overwritedialog.cpp b/part/overwritedialog.cpp --- a/part/overwritedialog.cpp +++ b/part/overwritedialog.cpp @@ -31,7 +31,7 @@ using namespace Kerfuffle; -OverwriteDialog::OverwriteDialog(QWidget *parent, const QList &entries, const QHash &icons, bool error) +OverwriteDialog::OverwriteDialog(QWidget *parent, const QList &entries, bool error) : QDialog(parent) , m_buttonBox(QDialogButtonBox::Cancel, Qt::Horizontal) { @@ -54,7 +54,7 @@ connect(&m_buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); for (const Archive::Entry *entry : entries) { - QListWidgetItem *item = new QListWidgetItem(icons.value(entry->fullPath(NoTrailingSlash)), entry->fullPath(NoTrailingSlash)); + QListWidgetItem *item = new QListWidgetItem(entry->icon(), entry->fullPath(NoTrailingSlash)); m_entriesList.addItem(item); } diff --git a/part/part.cpp b/part/part.cpp --- a/part/part.cpp +++ b/part/part.cpp @@ -1299,7 +1299,7 @@ bool error = m_model->conflictingEntries(conflictingEntries, withChildPaths, true); if (conflictingEntries.count() > 0) { - QPointer overwriteDialog = new OverwriteDialog(widget(), conflictingEntries, m_model->entryIcons(), error); + QPointer overwriteDialog = new OverwriteDialog(widget(), conflictingEntries, error); int ret = overwriteDialog->exec(); delete overwriteDialog; if (ret == QDialog::Rejected) { @@ -1515,7 +1515,7 @@ bool error = m_model->conflictingEntries(conflictingEntries, newPaths, false); if (conflictingEntries.count() != 0) { - QPointer overwriteDialog = new OverwriteDialog(widget(), conflictingEntries, m_model->entryIcons(), error); + QPointer overwriteDialog = new OverwriteDialog(widget(), conflictingEntries, error); int ret = overwriteDialog->exec(); delete overwriteDialog; if (ret == QDialog::Rejected) {