]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinplacesmodelsingleton.h
13e1193423d23a6655717344d6ff8d89e99b2703
[dolphin.git] / src / dolphinplacesmodelsingleton.h
1 /*
2 * SPDX-FileCopyrightText: 2018 Kai Uwe Broulik <kde@privat.broulik.de>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7 #ifndef DOLPHINPLACESMODELSINGLETON_H
8 #define DOLPHINPLACESMODELSINGLETON_H
9
10 #include <QString>
11 #include <QScopedPointer>
12
13 #include <KFilePlacesModel>
14
15 /**
16 * @brief Dolphin's special-cased KFilePlacesModel
17 *
18 * It returns the trash's icon based on whether
19 * it is full or not.
20 */
21 class DolphinPlacesModel : public KFilePlacesModel
22 {
23 Q_OBJECT
24
25 public:
26 explicit DolphinPlacesModel(const QString &alternativeApplicationName, QObject *parent = nullptr);
27 ~DolphinPlacesModel() override;
28
29 bool panelsLocked() const;
30 void setPanelsLocked(bool locked);
31
32 QStringList mimeTypes() const override;
33 bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override;
34
35 protected:
36 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
37
38 private Q_SLOTS:
39 void slotTrashEmptinessChanged(bool isEmpty);
40
41 private:
42 bool isTrash(const QModelIndex &index) const;
43
44 bool m_isEmpty = false;
45 bool m_panelsLocked = true; // common-case, panels are locked
46 };
47
48 /**
49 * @brief Provides a global KFilePlacesModel instance.
50 */
51 class DolphinPlacesModelSingleton
52 {
53
54 public:
55 static DolphinPlacesModelSingleton& instance();
56
57 DolphinPlacesModel *placesModel() const;
58 /** A suffix to the application-name of the stored bookmarks is
59 added, which is only read by PlacesItemModel. */
60 static QString applicationNameSuffix();
61
62 DolphinPlacesModelSingleton(const DolphinPlacesModelSingleton&) = delete;
63 DolphinPlacesModelSingleton& operator=(const DolphinPlacesModelSingleton&) = delete;
64
65 private:
66 DolphinPlacesModelSingleton();
67
68 QScopedPointer<DolphinPlacesModel> m_placesModel;
69 };
70
71 #endif // DOLPHINPLACESMODELSINGLETON_H