| 1 |
/* |
| 2 |
* libkysdk-appconf2's Library |
| 3 |
* |
| 4 |
* Copyright (C) 2024, KylinSoft Co., Ltd. |
| 5 |
* |
| 6 |
* This library is free software; you can redistribute it and/or |
| 7 |
* modify it under the terms of the GNU Lesser General Public |
| 8 |
* License as published by the Free Software Foundation; either |
| 9 |
* version 3 of the License, or (at your option) any later version. |
| 10 |
* |
| 11 |
* This library is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 |
* Lesser General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU General Public License |
| 17 |
* along with this library. If not, see <https://www.gnu.org/licenses/>. |
| 18 |
* |
| 19 |
* Authors: Zhenyu Wang <[email protected]> |
| 20 |
* |
| 21 |
*/ |
| 22 |
|
| 23 |
#ifndef KCONF2_H |
| 24 |
#define KCONF2_H |
| 25 |
|
| 26 |
#include <QObject> |
| 27 |
#include <QVariant> |
| 28 |
|
| 29 |
namespace kdk { |
| 30 |
|
| 31 |
class KConf2Private; |
| 32 |
|
| 33 |
class KConf2 : public QObject |
| 34 |
{ |
| 35 |
Q_OBJECT |
| 36 |
public: |
| 37 |
|
| 38 |
/** |
| 39 |
* @brief 创建KConf2对象 |
| 40 |
* @param schema_id 从应用名开始到目标组的路径,每个组名以"."分割 |
| 41 |
* @param version 指定配置版本号 |
| 42 |
* @param parent 若指定父对象,则自动释放对象内存 |
| 43 |
*/ |
| 44 |
KConf2(const QByteArray &schema_id, const QString version = QString() ,QObject*parent = nullptr); |
| 45 |
|
| 46 |
~KConf2(); |
| 47 |
|
| 48 |
/** |
| 49 |
* @brief 获取配置中指定键所对应的值 |
| 50 |
* @param key 键名 |
| 51 |
* @return 返回值类型为QVariant,需自行转换具体值类型 |
| 52 |
*/ |
| 53 |
QVariant get(const QString &key) const; |
| 54 |
|
| 55 |
/** |
| 56 |
* @brief 设置配置中指定键所对应的值 |
| 57 |
* @param key 键名 |
| 58 |
* @param value 对应值 |
| 59 |
*/ |
| 60 |
void set(const QString &key, const QVariant &value); |
| 61 |
|
| 62 |
/** |
| 63 |
* @brief 设置配置中指定键所对应的值 |
| 64 |
* @param key 键名 |
| 65 |
* @param value 对应值 |
| 66 |
* @return 设置成功返回true, 设置失败返回false |
| 67 |
*/ |
| 68 |
bool trySet(const QString &key, const QVariant &value); |
| 69 |
|
| 70 |
/** |
| 71 |
* @brief 列举配置中的所有键 |
| 72 |
* @return 键列表 |
| 73 |
*/ |
| 74 |
QStringList keys() const; |
| 75 |
|
| 76 |
/** |
| 77 |
* @brief 将指定键的值重置为默认值 |
| 78 |
* @param key 键名 |
| 79 |
*/ |
| 80 |
void reset(const QString &key); |
| 81 |
|
| 82 |
/** |
| 83 |
* @brief 判断该配置是否存在 |
| 84 |
* @param schema_id 配置名 |
| 85 |
* @return |
| 86 |
*/ |
| 87 |
static bool isSettingsAvailable(const QString &schema_id); |
| 88 |
|
| 89 |
/** |
| 90 |
* @brief 递归列举指定应用名下的所有配置项 |
| 91 |
* @param app 应用名 |
| 92 |
* @param version 配置版本 |
| 93 |
* @return |
| 94 |
*/ |
| 95 |
QStringList schemas(const QString &app, const QString &version) const; |
| 96 |
|
| 97 |
/** |
| 98 |
* @brief 获取指定键的详细描述 |
| 99 |
* @param key 键名 |
| 100 |
* @return |
| 101 |
*/ |
| 102 |
QString getDescrition(QString &key); |
| 103 |
|
| 104 |
/** |
| 105 |
* @brief 获取指定键的简要描述 |
| 106 |
* @param key 键名 |
| 107 |
* @return |
| 108 |
*/ |
| 109 |
QString getSummary(QString &key); |
| 110 |
|
| 111 |
/** |
| 112 |
* @brief 获取值类型 |
| 113 |
* @param key 键名 |
| 114 |
* @return |
| 115 |
*/ |
| 116 |
QString getType(QString &key); |
| 117 |
|
| 118 |
/** |
| 119 |
* @brief 检查键值是否可写 |
| 120 |
* @param key 键名 |
| 121 |
* @return |
| 122 |
*/ |
| 123 |
bool isWritable(QString &key); |
| 124 |
|
| 125 |
/** |
| 126 |
* @brief 获取句柄的配置id |
| 127 |
* @return |
| 128 |
*/ |
| 129 |
QString getId(); |
| 130 |
|
| 131 |
/** |
| 132 |
* @brief 获取配置版本 |
| 133 |
* @return |
| 134 |
*/ |
| 135 |
QString getVersion(); |
| 136 |
|
| 137 |
/** |
| 138 |
* @brief 列举配置组的子组 |
| 139 |
* @return |
| 140 |
*/ |
| 141 |
QStringList children() const; |
| 142 |
|
| 143 |
/** |
| 144 |
* @brief 获取指定的子组 |
| 145 |
* @param name 子组名称 |
| 146 |
* @return 子对象 |
| 147 |
*/ |
| 148 |
KConf2* getChild(QString &name); |
| 149 |
|
| 150 |
Q_SIGNALS: |
| 151 |
void changed(const QString &key); |
| 152 |
|
| 153 |
private: |
| 154 |
Q_DECLARE_PRIVATE(KConf2) |
| 155 |
KConf2Private* const d_ptr; |
| 156 |
}; |
| 157 |
|
| 158 |
} |
| 159 |
#endif // KCONF2_H |