diff --git a/src/core/global.cpp b/src/core/global.cpp --- a/src/core/global.cpp +++ b/src/core/global.cpp @@ -20,9 +20,12 @@ #include "kioglobal_p.h" #include "faviconscache_p.h" +#include + #include #include #include +#include #include #include #include @@ -305,42 +308,32 @@ if (url.scheme().isEmpty()) { // empty URL or relative URL (e.g. '~') return unknown; } - QMimeDatabase db; - const QMimeType mt = db.mimeTypeForUrl(url); - const QString mimeTypeIcon = mt.iconName(); - QString i = mimeTypeIcon; - // check whether it's a xdg location (e.g. Pictures folder) - if (url.isLocalFile() && mt.inherits(QLatin1String("inode/directory"))) { - i = KIOPrivate::iconForStandardPath(url.toLocalFile()); - } - - // if we don't find an icon, maybe we can use the one for the protocol - if (i == unknown || i.isEmpty() || mt.isDefault() - // and for the root of the protocol (e.g. trash:/) the protocol icon has priority over the mimetype icon - || url.path().length() <= 1) { - i = favIconForUrl(url); // maybe there is a favicon? - - // reflect actual fill state of trash can - if (url.scheme() == QLatin1String("trash") && url.path().length() <= 1) { - KConfig trashConfig(QStringLiteral("trashrc"), KConfig::SimpleConfig); - if (trashConfig.group("Status").readEntry("Empty", true)) { - i = QStringLiteral("user-trash"); - } else { - i = QStringLiteral("user-trash-full"); - } - } - - if (i.isEmpty()) { - i = KProtocolInfo::icon(url.scheme()); + // First, look for a favicon + else if (!url.isLocalFile() && url.scheme().startsWith(QLatin1String("http"))) { + QString favicon = favIconForUrl(url); + if (!favicon.isEmpty()) { + return favicon; } + } - // root of protocol: if we found nothing, revert to mimeTypeIcon (which is usually "folder") - if (url.path().length() <= 1 && (i == unknown || i.isEmpty())) { - i = mimeTypeIcon; + // Next, handle the trash + else if (url.scheme() == QLatin1String("trash") && url.path().length() <= 1) { + KConfig trashConfig(QStringLiteral("trashrc"), KConfig::SimpleConfig); + if (trashConfig.group("Status").readEntry("Empty", true)) { + return QStringLiteral("user-trash"); + } else { + return QStringLiteral("user-trash-full"); } } - return !i.isEmpty() ? i : unknown; + + // KFileItem::iconName can handle all other cases for us + KIO::StatJob *job = KIO::stat(url); + job->exec(); + KIO::UDSEntry entry = job->statResult(); + const KFileItem item = KFileItem(entry, url); + const QString folderIcon = item.iconName(); + return !folderIcon.isEmpty() ? folderIcon : unknown; } QUrl KIO::upUrl(const QUrl &url) diff --git a/src/core/kfileitem.cpp b/src/core/kfileitem.cpp --- a/src/core/kfileitem.cpp +++ b/src/core/kfileitem.cpp @@ -947,6 +947,11 @@ d->m_iconName = mime.iconName(); d->m_useIconNameCache = d->m_bMimeTypeKnown; + + if (d->m_iconName == QStringLiteral("inode-directory")) { + d->m_iconName = QStringLiteral("folder"); + } + return d->m_iconName; } diff --git a/src/ioslaves/trash/tests/testtrash.cpp b/src/ioslaves/trash/tests/testtrash.cpp --- a/src/ioslaves/trash/tests/testtrash.cpp +++ b/src/ioslaves/trash/tests/testtrash.cpp @@ -1303,7 +1303,7 @@ checkIcon(QUrl(QStringLiteral("trash:/")), QStringLiteral("user-trash-full")); } - checkIcon(QUrl(QStringLiteral("trash:/foo/")), QStringLiteral("inode-directory")); + checkIcon(QUrl(QStringLiteral("trash:/foo/")), QStringLiteral("folder")); } QTEST_GUILESS_MAIN(TestTrash)