| 1 | /* |
| 2 | SPDX-FileCopyrightText: 2013 Marco Martin <notmart@gmail.com> |
| 3 | SPDX-FileCopyrightText: 2020 David Edmundson <davidedmundson@kde.org> |
| 4 | SPDX-FileCopyrightText: 2021 Alexander Lohnau <alexander.lohnau@gmx.de> |
| 5 | |
| 6 | SPDX-License-Identifier: LGPL-2.0-or-later |
| 7 | */ |
| 8 | |
| 9 | #ifndef KCONFIGPROPERTYMAP_H |
| 10 | #define KCONFIGPROPERTYMAP_H |
| 11 | |
| 12 | #include <QQmlPropertyMap> |
| 13 | #include <memory> |
| 14 | #include <qqmlregistration.h> |
| 15 | |
| 16 | class KCoreConfigSkeleton; |
| 17 | |
| 18 | #include <kconfigqml_export.h> |
| 19 | |
| 20 | class KConfigPropertyMapPrivate; |
| 21 | |
| 22 | /*! |
| 23 | * \class KConfigPropertyMap |
| 24 | * \inmodule KConfigQml |
| 25 | * |
| 26 | * \brief An object that (optionally) automatically saves changes in a |
| 27 | * property map to a configuration object (e.g. a KConfig file). |
| 28 | * \since 5.89 |
| 29 | */ |
| 30 | class KCONFIGQML_EXPORT KConfigPropertyMap : public QQmlPropertyMap |
| 31 | { |
| 32 | Q_OBJECT |
| 33 | QML_ANONYMOUS |
| 34 | |
| 35 | public: |
| 36 | /*! |
| 37 | * |
| 38 | */ |
| 39 | KConfigPropertyMap(KCoreConfigSkeleton *config, QObject *parent = nullptr); |
| 40 | ~KConfigPropertyMap() override; |
| 41 | |
| 42 | /*! |
| 43 | * Whether notifications on config changes are enabled. Disabled by default. |
| 44 | * |
| 45 | * Returns \c true if writes send (dbus) notifications |
| 46 | * |
| 47 | * \sa KConfigBase::Notify |
| 48 | */ |
| 49 | bool isNotify() const; |
| 50 | |
| 51 | /*! |
| 52 | * Enable or disable notifications on config changes. |
| 53 | * |
| 54 | * \a notify whether to send notifications |
| 55 | * |
| 56 | * \sa KConfigBase::Notify |
| 57 | */ |
| 58 | void setNotify(bool notify); |
| 59 | |
| 60 | /*! |
| 61 | * Whether the value at the given key is immutable |
| 62 | * |
| 63 | * Returns \c true if the value is immutable, \c false if it isn't or it doesn't exist |
| 64 | */ |
| 65 | Q_INVOKABLE bool isImmutable(const QString &key) const; |
| 66 | |
| 67 | /*! |
| 68 | * Saves the state of the property map on disk. |
| 69 | */ |
| 70 | Q_INVOKABLE void writeConfig(); |
| 71 | |
| 72 | protected: |
| 73 | QVariant updateValue(const QString &key, const QVariant &input) override; |
| 74 | |
| 75 | private: |
| 76 | std::unique_ptr<KConfigPropertyMapPrivate> const d; |
| 77 | }; |
| 78 | |
| 79 | #endif |
| 80 | |