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

Kicker/RecentDocuments display place's icon when resource matches one

Reviewers: #plasma, ngraham, hein

Reviewed By: #plasma, ngraham, hein

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D26580
parent 3328f6a2
......@@ -239,6 +239,19 @@ QVariant RecentUsageModel::appData(const QString &resource, int role) const
return QVariant();
}
QModelIndex RecentUsageModel::findPlaceForKFileItem(const KFileItem &fileItem) const {
const auto index = m_placesModel->closestItem(fileItem.url());
if (index.isValid()) {
const auto parentUrl = m_placesModel->url(index);
if (parentUrl == fileItem.url()) {
return index;
}
}
return QModelIndex();
}
QVariant RecentUsageModel::docData(const QString &resource, int role) const
{
QUrl url(resource);
......@@ -258,16 +271,17 @@ QVariant RecentUsageModel::docData(const QString &resource, int role) const
if (role == Qt::DisplayRole) {
auto fileItem = getFileItem();
const auto index = m_placesModel->closestItem(fileItem.url());
const auto index = findPlaceForKFileItem(fileItem);
if (index.isValid()) {
const auto parentUrl = m_placesModel->url(index);
if (parentUrl == fileItem.url()) {
return m_placesModel->text(index);
}
return m_placesModel->text(index);
}
return fileItem.text();
} else if (role == Qt::DecorationRole) {
auto fileItem = getFileItem();
const auto index = findPlaceForKFileItem(fileItem);
if (index.isValid()) {
return m_placesModel->icon(index);
}
return QIcon::fromTheme(fileItem.iconName(), QIcon::fromTheme(QStringLiteral("unknown")));
} else if (role == Kicker::GroupRole) {
return i18n("Documents");
......
......@@ -26,6 +26,9 @@
#include <QSortFilterProxyModel>
#include <KFilePlacesModel>
class QModelIndex;
class KFileItem;
class GroupSortProxy : public QSortFilterProxyModel
{
Q_OBJECT
......@@ -105,6 +108,8 @@ class RecentUsageModel : public ForwardingModel, public QQmlParserStatus
QString forgetAllActionName() const;
QModelIndex findPlaceForKFileItem(const KFileItem &fileItem) const;
IncludeUsage m_usage;
QPointer<QAbstractItemModel> m_activitiesModel;
......
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