Changeset View
Changeset View
Standalone View
Standalone View
kcmkwin/kwindesktopng/desktopsmodel.h
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright (C) 2018 Eike Hein <hein@kde.org> | ||||
3 | * Copyright (C) 2018 Marco Martin <mart@kde.org> | ||||
4 | * | ||||
5 | * This program is free software; you can redistribute it and/or modify | ||||
6 | * it under the terms of the GNU General Public License as published by | ||||
7 | * the Free Software Foundation; either version 2 of the License, or | ||||
8 | * (at your option) any later version. | ||||
9 | * | ||||
10 | * This program is distributed in the hope that it will be useful, | ||||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
13 | * GNU General Public License for more details. | ||||
14 | * | ||||
15 | * You should have received a copy of the GNU General Public License | ||||
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
17 | */ | ||||
18 | | ||||
19 | #ifndef DESKTOPSMODEL_H | ||||
20 | #define DESKTOPSMODEL_H | ||||
21 | | ||||
22 | #include <QAbstractListModel> | ||||
23 | | ||||
24 | class QDBusArgument; | ||||
25 | class QDBusMessage; | ||||
26 | | ||||
27 | | ||||
28 | namespace KWin { | ||||
29 | | ||||
30 | struct DBusDesktopDataStruct { | ||||
31 | uint x11DesktopNumber; | ||||
32 | QString id; | ||||
33 | QString name; | ||||
34 | }; | ||||
35 | | ||||
36 | typedef QVector<DBusDesktopDataStruct> DBusDesktopDataVector; | ||||
37 | | ||||
38 | class DesktopsModel : public QAbstractListModel | ||||
39 | { | ||||
40 | Q_OBJECT | ||||
41 | Q_PROPERTY(bool ready READ ready NOTIFY readyChanged) | ||||
42 | Q_PROPERTY(QString error READ error NOTIFY errorChanged) | ||||
43 | Q_PROPERTY(int rows READ rows WRITE setRows NOTIFY rowsChanged) | ||||
44 | | ||||
45 | public: | ||||
46 | enum AdditionalRoles { | ||||
47 | Id = Qt::UserRole + 1, | ||||
48 | DesktopRow | ||||
49 | }; | ||||
50 | Q_ENUM(AdditionalRoles) | ||||
51 | | ||||
52 | explicit DesktopsModel(QObject *parent = nullptr); | ||||
53 | ~DesktopsModel() override; | ||||
54 | | ||||
55 | QHash<int, QByteArray> roleNames() const override; | ||||
56 | | ||||
57 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; | ||||
58 | int rowCount(const QModelIndex &parent = QModelIndex()) const override; | ||||
59 | | ||||
60 | bool ready() const; | ||||
61 | QString error() const; | ||||
62 | | ||||
63 | int rows() const; | ||||
64 | void setRows(int rows); | ||||
65 | | ||||
66 | Q_INVOKABLE void createDesktop(const QString &name); | ||||
67 | Q_INVOKABLE void removeDesktop(const QString &id); | ||||
68 | Q_INVOKABLE void setDesktopName(const QString &id, const QString &name); | ||||
69 | | ||||
70 | Q_SIGNALS: | ||||
71 | void readyChanged() const; | ||||
72 | void errorChanged() const; | ||||
73 | void rowsChanged() const; | ||||
74 | | ||||
75 | protected Q_SLOTS: | ||||
76 | void initialize(const QDBusMessage &msg); | ||||
77 | void desktopCreated(const QString &id, const KWin::DBusDesktopDataStruct &data); | ||||
78 | void desktopRemoved(const QString &id); | ||||
79 | void desktopDataChanged(const QString &id, const KWin::DBusDesktopDataStruct &data); | ||||
80 | void desktopRowsChanged(uint rows); | ||||
81 | void handleCallError(); | ||||
82 | | ||||
83 | private: | ||||
84 | QString m_error; | ||||
85 | QStringList m_desktops; | ||||
86 | QHash<QString,QString> m_names; | ||||
87 | int m_rows; | ||||
88 | }; | ||||
89 | | ||||
90 | } | ||||
91 | | ||||
92 | const QDBusArgument &operator<<(QDBusArgument &argument, const KWin::DBusDesktopDataStruct &desk); | ||||
93 | const QDBusArgument &operator>>(const QDBusArgument &argument, KWin::DBusDesktopDataStruct &desk); | ||||
94 | | ||||
95 | Q_DECLARE_METATYPE(KWin::DBusDesktopDataStruct) | ||||
96 | | ||||
97 | const QDBusArgument &operator<<(QDBusArgument &argument, const KWin::DBusDesktopDataVector &deskVector); | ||||
98 | const QDBusArgument &operator>>(const QDBusArgument &argument, KWin::DBusDesktopDataVector &deskVector); | ||||
99 | | ||||
100 | Q_DECLARE_METATYPE(KWin::DBusDesktopDataVector) | ||||
101 | | ||||
102 | #endif |