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 position; | ||||
| 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(bool userModified READ userModified NOTIFY userModifiedChanged) | ||||
| 44 | Q_PROPERTY(bool serverModified READ serverModified NOTIFY serverModifiedChanged) | ||||
| 45 | Q_PROPERTY(int rows READ rows WRITE setRows NOTIFY rowsChanged) | ||||
| 46 | | ||||
| 47 | public: | ||||
| 48 | enum AdditionalRoles { | ||||
| 49 | Id = Qt::UserRole + 1, | ||||
| 50 | DesktopRow | ||||
| 51 | }; | ||||
| 52 | Q_ENUM(AdditionalRoles) | ||||
| 53 | | ||||
| 54 | explicit DesktopsModel(QObject *parent = nullptr); | ||||
| 55 | ~DesktopsModel() override; | ||||
| 56 | | ||||
| 57 | QHash<int, QByteArray> roleNames() const override; | ||||
| 58 | | ||||
| 59 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; | ||||
| 60 | int rowCount(const QModelIndex &parent = QModelIndex()) const override; | ||||
| 61 | | ||||
| 62 | bool ready() const; | ||||
| 63 | QString error() const; | ||||
| 64 | | ||||
| 65 | bool userModified() const; | ||||
| 66 | bool serverModified() const; | ||||
| 67 | | ||||
| 68 | int rows() const; | ||||
| 69 | void setRows(int rows); | ||||
| 70 | | ||||
| 71 | Q_INVOKABLE void createDesktop(const QString &name); | ||||
| 72 | Q_INVOKABLE void removeDesktop(const QString &id); | ||||
| 73 | Q_INVOKABLE void setDesktopName(const QString &id, const QString &name); | ||||
| 74 | | ||||
| 75 | Q_INVOKABLE void syncWithServer(); | ||||
| 76 | | ||||
| 77 | Q_SIGNALS: | ||||
| 78 | void needsSaving(bool needsSaving) const; | ||||
| 79 | void readyChanged() const; | ||||
| 80 | void errorChanged() const; | ||||
| 81 | void userModifiedChanged() const; | ||||
| 82 | void serverModifiedChanged() const; | ||||
| 83 | void rowsChanged() const; | ||||
| 84 | | ||||
| 85 | protected Q_SLOTS: | ||||
| 86 | void initialize(const QDBusMessage &msg); | ||||
| 87 | void desktopCreated(const QString &id, const KWin::DBusDesktopDataStruct &data); | ||||
| 88 | void desktopRemoved(const QString &id); | ||||
| 89 | void desktopDataChanged(const QString &id, const KWin::DBusDesktopDataStruct &data); | ||||
| 90 | void desktopRowsChanged(uint rows); | ||||
| 91 | void checkModifiedState(bool server = false); | ||||
| 92 | void handleCallError(); | ||||
| 93 | | ||||
| 94 | private: | ||||
| 95 | QString m_error; | ||||
| 96 | bool m_userModified; | ||||
| 97 | bool m_serverModified; | ||||
| 98 | QStringList m_serverSideDesktops; | ||||
| 99 | QHash<QString,QString> m_serverSideNames; | ||||
| 100 | int m_serverSideRows; | ||||
| 101 | QStringList m_desktops; | ||||
| 102 | QHash<QString,QString> m_names; | ||||
| 103 | int m_rows; | ||||
| 104 | bool m_synchronizing; | ||||
| 105 | }; | ||||
| 106 | | ||||
| 107 | } | ||||
| 108 | | ||||
| 109 | const QDBusArgument &operator<<(QDBusArgument &argument, const KWin::DBusDesktopDataStruct &desk); | ||||
| 110 | const QDBusArgument &operator>>(const QDBusArgument &argument, KWin::DBusDesktopDataStruct &desk); | ||||
| 111 | | ||||
| 112 | Q_DECLARE_METATYPE(KWin::DBusDesktopDataStruct) | ||||
| 113 | | ||||
| 114 | const QDBusArgument &operator<<(QDBusArgument &argument, const KWin::DBusDesktopDataVector &deskVector); | ||||
| 115 | const QDBusArgument &operator>>(const QDBusArgument &argument, KWin::DBusDesktopDataVector &deskVector); | ||||
| 116 | | ||||
| 117 | Q_DECLARE_METATYPE(KWin::DBusDesktopDataVector) | ||||
| 118 | | ||||
| 119 | #endif | ||||