2 * SPDX-FileCopyrightText: 2018 Kai Uwe Broulik <kde@privat.broulik.de>
4 * SPDX-License-Identifier: GPL-2.0-or-later
7 #include "dolphinplacesmodelsingleton.h"
8 #include "trash/dolphintrash.h"
11 #include <KFilePlacesModel>
15 DolphinPlacesModel::DolphinPlacesModel(const QString
&alternativeApplicationName
, QObject
*parent
)
16 : KFilePlacesModel(alternativeApplicationName
, parent
)
18 connect(&Trash::instance(), &Trash::emptinessChanged
, this, &DolphinPlacesModel::slotTrashEmptinessChanged
);
21 DolphinPlacesModel::~DolphinPlacesModel() = default;
23 QVariant
DolphinPlacesModel::data(const QModelIndex
&index
, int role
) const
25 if (role
== Qt::DecorationRole
) {
28 return QIcon::fromTheme(QStringLiteral("user-trash"));
30 return QIcon::fromTheme(QStringLiteral("user-trash-full"));
35 return KFilePlacesModel::data(index
, role
);
38 void DolphinPlacesModel::slotTrashEmptinessChanged(bool isEmpty
)
40 if (m_isEmpty
== isEmpty
) {
44 // NOTE Trash::isEmpty() reads the config file whereas emptinessChanged is
45 // hooked up to whether a dirlister in trash:/ has any files and they disagree...
48 for (int i
= 0; i
< rowCount(); ++i
) {
49 const QModelIndex index
= this->index(i
, 0);
51 Q_EMIT
dataChanged(index
, index
, {Qt::DecorationRole
});
56 bool DolphinPlacesModel::isTrash(const QModelIndex
&index
) const
58 return url(index
) == QUrl(QStringLiteral("trash:/"));
61 DolphinPlacesModelSingleton::DolphinPlacesModelSingleton()
62 : m_placesModel(new DolphinPlacesModel(KAboutData::applicationData().componentName() + applicationNameSuffix()))
67 DolphinPlacesModelSingleton
&DolphinPlacesModelSingleton::instance()
69 static DolphinPlacesModelSingleton s_self
;
73 KFilePlacesModel
*DolphinPlacesModelSingleton::placesModel() const
75 return m_placesModel
.data();
78 QString
DolphinPlacesModelSingleton::applicationNameSuffix()
80 return QStringLiteral("-places-panel");