File indexing completed on 2024-04-14 04:51:41

0001 /**
0002  * SPDX-FileCopyrightText: 2015 Albert Vaca <albertvaka@gmail.com>
0003  *
0004  * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005  */
0006 
0007 #ifndef KDECONNECTPLUGINCONFIG_H
0008 #define KDECONNECTPLUGINCONFIG_H
0009 
0010 #include <QDir>
0011 #include <QObject>
0012 #include <QString>
0013 #include <QStringList>
0014 #include <QVariant>
0015 
0016 #include "kdeconnectcore_export.h"
0017 #include <memory>
0018 
0019 struct KdeConnectPluginConfigPrivate;
0020 
0021 class KDECONNECTCORE_EXPORT KdeConnectPluginConfig : public QObject
0022 {
0023     Q_OBJECT
0024 
0025     Q_PROPERTY(QString deviceId READ deviceId WRITE setDeviceId NOTIFY deviceIdChanged)
0026     Q_PROPERTY(QString pluginName READ pluginName WRITE setPluginName NOTIFY configChanged)
0027 
0028 public:
0029     explicit KdeConnectPluginConfig(QObject *parent = nullptr);
0030     explicit KdeConnectPluginConfig(const QString &deviceId, const QString &pluginName, QObject *parent = nullptr);
0031     ~KdeConnectPluginConfig() override;
0032 
0033     /**
0034      * Store a key-value pair in this config object
0035      */
0036     Q_SCRIPTABLE void set(const QString &key, const QVariant &value);
0037 
0038     /**
0039      * Store a list of values in this config object under the array name
0040      * specified in key.
0041      */
0042     void setList(const QString &key, const QVariantList &list);
0043 
0044     /**
0045      * Read a key-value pair from this config object
0046      */
0047     Q_SCRIPTABLE QString getString(const QString &key, const QString &defaultValue);
0048     Q_SCRIPTABLE bool getBool(const QString &key, const bool defaultValue);
0049     Q_SCRIPTABLE int getInt(const QString &key, const int defaultValue);
0050     Q_SCRIPTABLE QByteArray getByteArray(const QString &key, const QByteArray defaultValue);
0051 
0052     QVariantList getList(const QString &key, const QVariantList &defaultValue = {});
0053 
0054     QString deviceId();
0055     void setDeviceId(const QString &deviceId);
0056 
0057     QString pluginName();
0058     void setPluginName(const QString &pluginName);
0059 
0060 private Q_SLOTS:
0061     void slotConfigChanged();
0062 
0063 Q_SIGNALS:
0064     void configChanged();
0065     void deviceIdChanged(const QString &value);
0066 
0067 private:
0068     void loadConfig();
0069 
0070     std::unique_ptr<KdeConnectPluginConfigPrivate> d;
0071     QString m_deviceId;
0072     QString m_pluginName;
0073 };
0074 
0075 #endif