Commit 1640e9f4 authored by Méven Car's avatar Méven Car
Browse files

Kicker/Documents optimization: Lazily build KFileItem

Summary:
Save quite a few KFileItem instanciation.
On each document hovering several KFileItem were instanciated for nothing.

Reviewers: #frameworks, apol

Reviewed By: apol

Subscribers: apol, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D26416
parent b7ac0291
...@@ -247,18 +247,17 @@ QVariant RecentUsageModel::docData(const QString &resource, int role) const ...@@ -247,18 +247,17 @@ QVariant RecentUsageModel::docData(const QString &resource, int role) const
url.setScheme(QStringLiteral("file")); url.setScheme(QStringLiteral("file"));
} }
#if KIO_VERSION >= QT_VERSION_CHECK(5,57,0) auto getFileItem = [=] () {
// Avoid calling QT_LSTAT and accessing recent documents // Avoid calling QT_LSTAT and accessing recent documents
const KFileItem fileItem(url, KFileItem::SkipMimeTypeFromContent); return KFileItem(url, KFileItem::SkipMimeTypeFromContent);
#else };
const KFileItem fileItem(url);
#endif
if (!url.isValid()) { if (!url.isValid()) {
return QVariant(); return QVariant();
} }
if (role == Qt::DisplayRole) { if (role == Qt::DisplayRole) {
auto fileItem = getFileItem();
const auto index = m_placesModel->closestItem(fileItem.url()); const auto index = m_placesModel->closestItem(fileItem.url());
if (index.isValid()) { if (index.isValid()) {
const auto parentUrl = m_placesModel->url(index); const auto parentUrl = m_placesModel->url(index);
...@@ -268,12 +267,14 @@ QVariant RecentUsageModel::docData(const QString &resource, int role) const ...@@ -268,12 +267,14 @@ QVariant RecentUsageModel::docData(const QString &resource, int role) const
} }
return fileItem.text(); return fileItem.text();
} else if (role == Qt::DecorationRole) { } else if (role == Qt::DecorationRole) {
auto fileItem = getFileItem();
return QIcon::fromTheme(fileItem.iconName(), QIcon::fromTheme(QStringLiteral("unknown"))); return QIcon::fromTheme(fileItem.iconName(), QIcon::fromTheme(QStringLiteral("unknown")));
} else if (role == Kicker::GroupRole) { } else if (role == Kicker::GroupRole) {
return i18n("Documents"); return i18n("Documents");
} else if (role == Kicker::FavoriteIdRole || role == Kicker::UrlRole) { } else if (role == Kicker::FavoriteIdRole || role == Kicker::UrlRole) {
return url.toString(); return url.toString();
} else if (role == Kicker::DescriptionRole) { } else if (role == Kicker::DescriptionRole) {
auto fileItem = getFileItem();
QString desc = fileItem.localPath(); QString desc = fileItem.localPath();
const auto index = m_placesModel->closestItem(fileItem.url()); const auto index = m_placesModel->closestItem(fileItem.url());
...@@ -297,6 +298,7 @@ QVariant RecentUsageModel::docData(const QString &resource, int role) const ...@@ -297,6 +298,7 @@ QVariant RecentUsageModel::docData(const QString &resource, int role) const
} else if (role == Kicker::HasActionListRole) { } else if (role == Kicker::HasActionListRole) {
return true; return true;
} else if (role == Kicker::ActionListRole) { } else if (role == Kicker::ActionListRole) {
auto fileItem = getFileItem();
QVariantList actionList = Kicker::createActionListForFileItem(fileItem); QVariantList actionList = Kicker::createActionListForFileItem(fileItem);
actionList << Kicker::createSeparatorActionItem(); actionList << Kicker::createSeparatorActionItem();
......
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