Commit 15baa936 authored by Martin Tobias Holmedahl Sandsmark's avatar Martin Tobias Holmedahl Sandsmark Committed by Elvis Angelaccio
Browse files

make sure we use valid icons

parent 891ebf57
......@@ -17,6 +17,8 @@
#include <QGraphicsView>
#include <QPainter>
#include <QTimer>
#include <QIcon>
#include <QMimeDatabase>
// #define KFILEITEMLISTVIEW_DEBUG
......@@ -168,6 +170,9 @@ QPixmap KFileItemListView::createDragPixmap(const KItemSet& indexes) const
QPixmap pixmap = model()->data(index).value("iconPixmap").value<QPixmap>();
if (pixmap.isNull()) {
QIcon icon = QIcon::fromTheme(model()->data(index).value("iconName").toString());
if (icon.isNull()) {
icon = QIcon::fromTheme("unknown");
}
if (!icon.isNull()) {
pixmap = icon.pixmap(size, size);
} else {
......@@ -210,7 +215,12 @@ void KFileItemListView::initializeItemListWidget(KItemListWidget* item)
KFileItemModel* fileItemModel = static_cast<KFileItemModel*>(model());
const KFileItem fileItem = fileItemModel->fileItem(item->index());
data.insert("iconName", fileItem.iconName());
QString iconName = fileItem.iconName();
if (!QIcon::hasThemeIcon(iconName)) {
QMimeDatabase mimeDb;
iconName = mimeDb.mimeTypeForName(fileItem.mimetype()).genericIconName();
}
data.insert("iconName", iconName);
item->setData(data, {"iconName"});
}
}
......
......@@ -19,9 +19,11 @@
#include <QElapsedTimer>
#include <QMimeData>
#include <QMimeDatabase>
#include <QTimer>
#include <QWidget>
#include <QMutex>
#include <QIcon>
Q_GLOBAL_STATIC_WITH_ARGS(QMutex, s_collatorMutex, (QMutex::Recursive))
......@@ -1657,7 +1659,13 @@ QHash<QByteArray, QVariant> KFileItemModel::retrieveData(const KFileItem& item,
}
if (item.isMimeTypeKnown()) {
data.insert(sharedValue("iconName"), item.iconName());
QString iconName = item.iconName();
if (!QIcon::hasThemeIcon(iconName)) {
QMimeType mimeType = QMimeDatabase().mimeTypeForName(item.mimetype());
iconName = mimeType.genericIconName();
}
data.insert(sharedValue("iconName"), iconName);
if (m_requestRole[TypeRole]) {
data.insert(sharedValue("type"), item.mimeComment());
......
......@@ -27,6 +27,7 @@
#endif
#include <QApplication>
#include <QIcon>
#include <QPainter>
#include <QElapsedTimer>
#include <QTimer>
......@@ -1044,7 +1045,9 @@ bool KFileItemModelRolesUpdater::applyResolvedRoles(int index, ResolveHint hint)
data = rolesData(item);
}
data.insert("iconName", item.iconName());
if (QIcon::hasThemeIcon(item.iconName())) {
data.insert("iconName", item.iconName());
}
if (m_clearPreviews) {
data.insert("iconPixmap", QPixmap());
......
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