Commit 45c420b7 authored by Kai Uwe Broulik's avatar Kai Uwe Broulik 🍇

[Folder View] Hide /home/foo/Desktop place in configuration

Folder View is meant to use desktop:/ and having two entries that behave differently can generate confusion.

CCBUG: 398141

Differential Revision: https://phabricator.kde.org/D15331
parent 2fb93be5
......@@ -67,6 +67,7 @@ Item {
Folder.PlacesModel {
id: placesModel
showDesktopEntry: false
onPlacesChanged: applyConfig(true)
}
......
......@@ -19,6 +19,8 @@
#include "placesmodel.h"
#include <QStandardPaths>
#include <KFilePlacesModel>
#include <KService>
#include <KServiceTypeTrader>
......@@ -59,6 +61,22 @@ bool PlacesModel::activityLinkingEnabled() const
return !services.at(0).data()->noDisplay();
}
bool PlacesModel::showDesktopEntry() const
{
return m_showDesktopEntry;
}
void PlacesModel::setShowDesktopEntry(bool showDesktopEntry)
{
if (m_showDesktopEntry != showDesktopEntry) {
m_showDesktopEntry = showDesktopEntry;
invalidateFilter();
emit showDesktopEntryChanged();
}
}
QString PlacesModel::urlForIndex(int idx) const
{
return m_sourceModel->url(mapToSource(index(idx, 0))).toString();
......@@ -88,5 +106,13 @@ bool PlacesModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParen
{
const QModelIndex index = m_sourceModel->index(sourceRow, 0, sourceParent);
if (!m_showDesktopEntry) {
const QUrl url = index.data(KFilePlacesModel::UrlRole).toUrl();
const QUrl desktopUrl = QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::DesktopLocation));
if (url == desktopUrl) {
return false;
}
}
return !m_sourceModel->isHidden(index);
}
......@@ -29,6 +29,7 @@ class PlacesModel : public QSortFilterProxyModel
Q_OBJECT
Q_PROPERTY(bool activityLinkingEnabled READ activityLinkingEnabled CONSTANT)
Q_PROPERTY(bool showDesktopEntry READ showDesktopEntry WRITE setShowDesktopEntry NOTIFY showDesktopEntryChanged)
public:
explicit PlacesModel(QObject *parent = nullptr);
......@@ -36,18 +37,23 @@ class PlacesModel : public QSortFilterProxyModel
bool activityLinkingEnabled() const;
bool showDesktopEntry() const;
void setShowDesktopEntry(bool showDesktopEntry);
QHash<int, QByteArray> roleNames() const override;
Q_INVOKABLE QString urlForIndex(int idx) const;
Q_INVOKABLE int indexForUrl(const QString &url) const;
Q_SIGNALS:
void placesChanged() const;
void showDesktopEntryChanged() const;
protected:
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
private:
KFilePlacesModel *m_sourceModel;
bool m_showDesktopEntry = true;
};
#endif
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