┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/dolphinplacesmodelsingleton.cpp
diff options
context:
space:
mode:
authorKai Uwe Broulik <[email protected]>2021-12-16 19:29:22 +0100
committerKai Uwe Broulik <[email protected]>2022-01-09 18:09:10 +0100
commit0603e18cd4e36b988196a99810f2e3e803fe3125 (patch)
tree6d70829efea053cb36c9e6618d8feadd45569a91 /src/dolphinplacesmodelsingleton.cpp
parent3abc4cfcd49df45c856e1b5f01da8de8f970ccb2 (diff)
Port back to KFilePlacesView
This removes the custom-view engine version of the places panel and replaces it with the upstream `KFilePlacesView` from KIO.
Diffstat (limited to 'src/dolphinplacesmodelsingleton.cpp')
-rw-r--r--src/dolphinplacesmodelsingleton.cpp51
1 files changed, 50 insertions, 1 deletions
diff --git a/src/dolphinplacesmodelsingleton.cpp b/src/dolphinplacesmodelsingleton.cpp
index 30ec1b9b6..754070c92 100644
--- a/src/dolphinplacesmodelsingleton.cpp
+++ b/src/dolphinplacesmodelsingleton.cpp
@@ -5,12 +5,61 @@
*/
#include "dolphinplacesmodelsingleton.h"
+#include "trash/dolphintrash.h"
#include <KAboutData>
#include <KFilePlacesModel>
+#include <QIcon>
+
+DolphinPlacesModel::DolphinPlacesModel(const QString &alternativeApplicationName, QObject *parent)
+ : KFilePlacesModel(alternativeApplicationName, parent)
+{
+ connect(&Trash::instance(), &Trash::emptinessChanged, this, &DolphinPlacesModel::slotTrashEmptinessChanged);
+}
+
+DolphinPlacesModel::~DolphinPlacesModel() = default;
+
+QVariant DolphinPlacesModel::data(const QModelIndex &index, int role) const
+{
+ if (role == Qt::DecorationRole) {
+ if (isTrash(index)) {
+ if (m_isEmpty) {
+ return QIcon::fromTheme(QStringLiteral("user-trash"));
+ } else {
+ return QIcon::fromTheme(QStringLiteral("user-trash-full"));
+ }
+ }
+ }
+
+ return KFilePlacesModel::data(index, role);
+}
+
+void DolphinPlacesModel::slotTrashEmptinessChanged(bool isEmpty)
+{
+ if (m_isEmpty == isEmpty) {
+ return;
+ }
+
+ // NOTE Trash::isEmpty() reads the config file whereas emptinessChanged is
+ // hooked up to whether a dirlister in trash:/ has any files and they disagree...
+ m_isEmpty = isEmpty;
+
+ for (int i = 0; i < rowCount(); ++i) {
+ const QModelIndex index = this->index(i, 0);
+ if (isTrash(index)) {
+ Q_EMIT dataChanged(index, index, {Qt::DecorationRole});
+ }
+ }
+}
+
+bool DolphinPlacesModel::isTrash(const QModelIndex &index) const
+{
+ return url(index) == QUrl(QStringLiteral("trash:/"));
+}
+
DolphinPlacesModelSingleton::DolphinPlacesModelSingleton()
- : m_placesModel(new KFilePlacesModel(KAboutData::applicationData().componentName() + applicationNameSuffix()))
+ : m_placesModel(new DolphinPlacesModel(KAboutData::applicationData().componentName() + applicationNameSuffix()))
{
}