mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-23 10:22:48 +00:00
kio: handle the special case of trash protocol and protocols in general in KFileItem::iconName()
more conditions are added into the mix but that is how it should be, KMimeType::iconNameForUrl() barely covers some cases (no overlays?) Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
93a71cccd8
commit
c045d9f57b
2 changed files with 36 additions and 13 deletions
|
@ -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)
|
||||
|
|
|
@ -27,9 +27,10 @@
|
|||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <QtCore/QFile>
|
||||
#include <QtDBus/QDBusInterface>
|
||||
#include <QtDBus/QDBusReply>
|
||||
#include <QFile>
|
||||
#include <QDir>
|
||||
#include <QDBusInterface>
|
||||
#include <QDBusReply>
|
||||
|
||||
#include <kdebug.h>
|
||||
#include <kglobal.h>
|
||||
|
@ -43,6 +44,7 @@
|
|||
#include <kconfiggroup.h>
|
||||
#include <kuser.h>
|
||||
#include <ktoolinvocation.h>
|
||||
#include <kprotocolinfo.h>
|
||||
|
||||
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;
|
||||
|
|
Loading…
Add table
Reference in a new issue