Commit 6369b556 authored by David Faure's avatar David Faure

Implement delayed loading of slow icons (from .desktop or .directory files)

Thanks to Pierre Sauter for making me fix this, and for testing that it
works over sshfs.

FIXED-IN: 4.10.2
BUG: 290666
parent a6c2fcc8
......@@ -183,7 +183,7 @@ public:
bool m_bIsLocalUrl:1;
mutable bool m_bMimeTypeKnown:1;
bool m_delayedMimeTypes:1;
mutable bool m_delayedMimeTypes:1;
/** True if m_iconName should be used as cache. */
mutable bool m_useIconNameCache:1;
......@@ -792,6 +792,12 @@ KMimeType::Ptr KFileItem::determineMimeType() const
d->m_bMimeTypeKnown = true;
}
if (isSlow() && d->m_delayedMimeTypes) { // if we delayed getting the iconName up till now, this is the right point in time to do so
d->m_delayedMimeTypes = false;
d->m_useIconNameCache = false;
(void)iconName();
}
return d->m_pMimeType;
}
......@@ -806,6 +812,14 @@ bool KFileItem::isMimeTypeKnown() const
return d->m_bMimeTypeKnown && d->m_guessedMimeType.isEmpty();
}
bool KFileItem::isFinalIconKnown() const
{
if (!d) {
return false;
}
return d->m_bMimeTypeKnown && (!d->m_delayedMimeTypes || !isSlow());
}
QString KFileItem::mimeComment() const
{
if (!d)
......@@ -888,7 +902,9 @@ QString KFileItem::iconName() const
mime = mimeTypePtr();
}
if (isLocalUrl && !isSlow() && mime->is("application/x-desktop")) {
const bool delaySlowOperations = isSlow() && d->m_delayedMimeTypes;
if (isLocalUrl && !delaySlowOperations && mime->is("application/x-desktop")) {
d->m_iconName = iconFromDesktopFile(url.toLocalFile());
if (!d->m_iconName.isEmpty()) {
d->m_useIconNameCache = d->m_bMimeTypeKnown;
......@@ -899,7 +915,7 @@ QString KFileItem::iconName() const
// KDE5: handle .directory files here too, and get rid of
// KFolderMimeType and the url argument in KMimeType::iconName().
if (isSlow())
if (delaySlowOperations)
d->m_iconName = mime->iconName();
else
d->m_iconName = mime->iconName(url);
......
......@@ -369,6 +369,12 @@ public:
*/
KMimeType::Ptr mimeTypePtr() const;
/**
* @return true if we have determined the final icon of this file already.
* @since 4.10.2
*/
bool isFinalIconKnown() const;
/**
* @return true if we have determined the mimetype of this file already,
* i.e. if determineMimeType() will be fast. Otherwise it will have to
......
......@@ -182,10 +182,12 @@ void KFileItemTest::testMimeTypeOnDemand()
KFileItem fileItem(KFileItem::Unknown, KFileItem::Unknown, KUrl(file.fileName()), true /*on demand*/);
QCOMPARE(fileItem.mimeTypePtr()->name(), KMimeType::defaultMimeType());
QVERIFY(!fileItem.isMimeTypeKnown());
QVERIFY(!fileItem.isFinalIconKnown());
//kDebug() << fileItem.determineMimeType()->name();
QCOMPARE(fileItem.determineMimeType()->name(), QString("application/x-zerosize"));
QCOMPARE(fileItem.mimetype(), QString("application/x-zerosize"));
QVERIFY(fileItem.isMimeTypeKnown());
QVERIFY(fileItem.isFinalIconKnown());
}
{
......
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