kdecore: implement MIME type name argument for KMimeType::iconNameForUrl()

because KMimeType::iconNameForUrl() really cannot determine the MIME type
reliably for non-local URLs (can only guess from the name), also the MIME
type is known by KFileItem for such meaning it will not have to be
determined again

on a side note the documentation of the method mentions overlays - that is
not a thing for KMimeType::iconNameForUrl()

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2024-06-04 17:30:27 +03:00
parent 808a1221cd
commit 508ad0d2fd
3 changed files with 10 additions and 11 deletions

View file

@ -322,7 +322,7 @@ bool KMimeType::isBinaryData(const QString &fileName)
return isBufferBinaryData(file.read(32));
}
QString KMimeType::iconNameForUrl(const KUrl &url, mode_t mode)
QString KMimeType::iconNameForUrl(const KUrl &url, mode_t mode, const QString &_mimeType)
{
static const QLatin1String s_trashprotocol = QLatin1String("trash");
static const QString s_usertrash = QString::fromLatin1("user-trash");
@ -340,7 +340,7 @@ QString KMimeType::iconNameForUrl(const KUrl &url, mode_t mode)
return i;
}
const KMimeType::Ptr mt = findByUrl(url, mode);
const KMimeType::Ptr mt = (_mimeType.isEmpty() ? findByUrl(url, mode) : KMimeType::mimeType(_mimeType));
if (!mt) {
return QString();
}

View file

@ -63,12 +63,12 @@ public:
* KIconLoader::loadMimeTypeIcon to load the icon.
*
* @param url URL for the file
* @param mode the mode of the file. The mode may modify the icon with overlays that show
* special properties of the icon. Use 0 for default
* @param mode the mode of the file. Use 0 for default
* @param mimeType the mime type if known. Use empty string to determine it from @p url
* @return the name of the icon. The name of a default icon if there is no icon for the mime
* type
*/
static QString iconNameForUrl(const KUrl &url, mode_t mode = 0);
static QString iconNameForUrl(const KUrl &url, mode_t mode = 0, const QString &mimeType = QString());
/**
* Return the "favicon" for the given @p url if available. Does NOT attempt to download the

View file

@ -537,17 +537,16 @@ QString KFileItem::iconName() const
return d->m_iconName;
}
KMimeType::Ptr mime;
// Use guessed mimetype for the icon
if (!d->m_guessedMimeType.isEmpty()) {
KMimeType::Ptr mime = KMimeType::mimeType(d->m_guessedMimeType);
if (mime) {
d->m_iconName = mime->iconName(d->m_url);
return d->m_iconName;
}
mime = KMimeType::mimeType(d->m_guessedMimeType);
} else {
mime = mimeTypePtr();
}
// kDebug() << "finding icon for" << d->m_url << ":" << d->m_iconName;
d->m_iconName = KMimeType::iconNameForUrl(d->m_url, d->m_fileMode);
d->m_iconName = KMimeType::iconNameForUrl(d->m_url, d->m_fileMode, mime ? mime->name() : QString());
return d->m_iconName;
}