diff --git a/kdecore/services/kmimetype.cpp b/kdecore/services/kmimetype.cpp index c97931cc..a20a189d 100644 --- a/kdecore/services/kmimetype.cpp +++ b/kdecore/services/kmimetype.cpp @@ -319,7 +319,7 @@ QString KMimeType::iconNameForUrl(const KUrl &_url, mode_t mode) const QString mimeTypeIcon = mt->iconName(_url); QString i = mimeTypeIcon; - // if we don't find an icon, maybe we can use the one for the protocol + // if icon is not found maybe use the one for the protocol if (i == unknown || i.isEmpty() || mt->name() == defaultMimeType() // and for the root of the protocol (e.g. trash:/) the protocol icon has priority over the mimetype icon || _url.path().length() <= 1) diff --git a/kio/kio/kfileitem.cpp b/kio/kio/kfileitem.cpp index 6a63ee5e..0776158e 100644 --- a/kio/kio/kfileitem.cpp +++ b/kio/kio/kfileitem.cpp @@ -27,9 +27,10 @@ #include #include -#include -#include -#include +#include +#include +#include +#include #include #include @@ -43,6 +44,7 @@ #include #include #include +#include static bool isKDirShare(const QString &dirpath) { @@ -58,8 +60,22 @@ static bool isKDirShare(const QString &dirpath) return kdirsharereply.value(); } +static QString kTrashIcon(const QString &emptyIcon) +{ + // need to find if the trash is empty, preferably without using a KIO job. kio_trash leaves an + // entry in its config file + KConfig trashConfig("trashrc", KConfig::SimpleConfig); + if (trashConfig.group("Status").readEntry("Empty", true)) { + return emptyIcon; + } + // the default icon for the protocol + return QString::fromLatin1("user-trash-full"); +} + // avoid creating these QStrings again and again static const QLatin1String s_dot = QLatin1String("."); +static const QLatin1String s_trashprotocol = QLatin1String("trash"); +static const QLatin1String s_usertrash = QLatin1String("user-trash"); class KFileItemPrivate : public QSharedData { @@ -561,15 +577,9 @@ QString KFileItem::iconName() const const QString type = cfg.readPath(); const QString emptyIcon = group.readEntry("EmptyIcon"); if (!emptyIcon.isEmpty()) { - const QString u = cfg.readUrl(); - const KUrl url(u); - if (url.protocol() == "trash") { - // We need to find if the trash is empty, preferably without using a KIO job. - // So instead kio_trash leaves an entry in its config file for us. - KConfig trashConfig("trashrc", KConfig::SimpleConfig); - if (trashConfig.group("Status").readEntry("Empty", true)) { - d->m_iconName = emptyIcon; - } + const KUrl url(cfg.readUrl()); + if (url.protocol() == s_trashprotocol) { + d->m_iconName = kTrashIcon(emptyIcon); } } } @@ -578,6 +588,19 @@ QString KFileItem::iconName() const } } + // root of protocol has priority over the MIME type icon (see KMimeType::iconNameForUrl) + const QString urlPath = d->m_url.path(); + if (urlPath.isEmpty() || urlPath == QDir::separator()) { + if (d->m_url.protocol() == s_trashprotocol) { + d->m_iconName = kTrashIcon(s_usertrash); + } else { + d->m_iconName = KProtocolInfo::icon(d->m_url.protocol()); + } + if (!d->m_iconName.isEmpty()) { + return d->m_iconName; + } + } + // kDebug() << "finding icon for" << d->m_url << ":" << d->m_iconName; d->m_iconName = mime->iconName(d->m_url); return d->m_iconName;