| 1 |
/* |
| 2 |
* |
| 3 |
* Copyright (C) 2024, KylinSoft Co., Ltd. |
| 4 |
* |
| 5 |
* This library is free software; you can redistribute it and/or |
| 6 |
* modify it under the terms of the GNU Lesser General Public |
| 7 |
* License as published by the Free Software Foundation; either |
| 8 |
* version 3 of the License, or (at your option) any later version. |
| 9 |
* |
| 10 |
* This library 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 GNU |
| 13 |
* Lesser General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU General Public License |
| 16 |
* along with this library. If not, see <https://www.gnu.org/licenses/>. |
| 17 |
* |
| 18 |
* Authors: Zhenyu Wang <[email protected]> |
| 19 |
* |
| 20 |
*/ |
| 21 |
|
| 22 |
#include "widget.h" |
| 23 |
#include "kconf2.h" |
| 24 |
#include <QDebug> |
| 25 |
#include <QHBoxLayout> |
| 26 |
#include <QLabel> |
| 27 |
#include <QLineEdit> |
| 28 |
#include <QObject> |
| 29 |
#include <QProgressBar> |
| 30 |
#include <QPushButton> |
| 31 |
#include <libkysettings.h> |
| 32 |
|
| 33 |
using namespace kdk; |
| 34 |
|
| 35 |
Widget::Widget(QWidget *parent) |
| 36 |
: QWidget(parent) |
| 37 |
{ |
| 38 |
|
| 39 |
if (KConf2::isSettingsAvailable("test")) { |
| 40 |
KConf2 *settings = new KConf2("test"); |
| 41 |
connect(settings, &KConf2::changed, this, [=](const QString &key) { |
| 42 |
qDebug() << "恭喜你,gsetting切换成功了,变化的key是" << key << "style-name is" << settings->get("style-name").toString(); |
| 43 |
}); |
| 44 |
} |
| 45 |
|
| 46 |
QVBoxLayout *layout = new QVBoxLayout(this); |
| 47 |
QPushButton *btn1 = new QPushButton("get value"); |
| 48 |
QPushButton *btn2 = new QPushButton("set enabled"); |
| 49 |
QPushButton *btn3 = new QPushButton("get keys"); |
| 50 |
QPushButton *btn4 = new QPushButton("schemas"); |
| 51 |
QPushButton *btn5 = new QPushButton("getDescrition"); |
| 52 |
QPushButton *btn6 = new QPushButton("get summary"); |
| 53 |
QPushButton *btn7 = new QPushButton("get type"); |
| 54 |
QPushButton *btn8 = new QPushButton("is Writable"); |
| 55 |
QPushButton *btn9 = new QPushButton("get id "); |
| 56 |
QPushButton *btn10 = new QPushButton("get version "); |
| 57 |
QPushButton *btn11 = new QPushButton("get child "); |
| 58 |
QPushButton *btn12 = new QPushButton("children "); |
| 59 |
|
| 60 |
layout->addWidget(btn1); |
| 61 |
layout->addWidget(btn2); |
| 62 |
layout->addWidget(btn3); |
| 63 |
layout->addWidget(btn4); |
| 64 |
layout->addWidget(btn5); |
| 65 |
layout->addWidget(btn6); |
| 66 |
layout->addWidget(btn7); |
| 67 |
layout->addWidget(btn8); |
| 68 |
layout->addWidget(btn9); |
| 69 |
layout->addWidget(btn10); |
| 70 |
layout->addWidget(btn11); |
| 71 |
layout->addWidget(btn12); |
| 72 |
|
| 73 |
connect(btn1, &QPushButton::clicked, this, [=] { |
| 74 |
onClicked1(); |
| 75 |
}); |
| 76 |
|
| 77 |
connect(btn2, &QPushButton::clicked, this, [=] { |
| 78 |
onClicked2(); |
| 79 |
}); |
| 80 |
|
| 81 |
connect(btn3, &QPushButton::clicked, this, [=] { |
| 82 |
onClicked3(); |
| 83 |
}); |
| 84 |
|
| 85 |
connect(btn4, &QPushButton::clicked, this, [=] { |
| 86 |
onClicked4(); |
| 87 |
}); |
| 88 |
|
| 89 |
connect(btn5, &QPushButton::clicked, this, [=] { |
| 90 |
onClicked5(); |
| 91 |
}); |
| 92 |
|
| 93 |
connect(btn6, &QPushButton::clicked, this, [=] { |
| 94 |
onClicked6(); |
| 95 |
}); |
| 96 |
|
| 97 |
connect(btn7, &QPushButton::clicked, this, [=] { |
| 98 |
onClicked7(); |
| 99 |
}); |
| 100 |
|
| 101 |
connect(btn8, &QPushButton::clicked, this, [=] { |
| 102 |
onClicked8(); |
| 103 |
}); |
| 104 |
|
| 105 |
connect(btn9, &QPushButton::clicked, this, [=] { |
| 106 |
onClicked9(); |
| 107 |
}); |
| 108 |
|
| 109 |
connect(btn10, &QPushButton::clicked, this, [=] { |
| 110 |
onClicked10(); |
| 111 |
}); |
| 112 |
|
| 113 |
connect(btn11, &QPushButton::clicked, this, [=] { |
| 114 |
onClicked11(); |
| 115 |
}); |
| 116 |
|
| 117 |
connect(btn12, &QPushButton::clicked, this, [=] { |
| 118 |
onClicked12(); |
| 119 |
}); |
| 120 |
} |
| 121 |
|
| 122 |
Widget::~Widget() |
| 123 |
{ |
| 124 |
} |
| 125 |
|
| 126 |
void Widget::onClicked1() |
| 127 |
{ |
| 128 |
if (KConf2::isSettingsAvailable("test")) { |
| 129 |
KConf2 *settings = new KConf2("test.notice"); |
| 130 |
auto stylename = settings->get("int").toString(); |
| 131 |
qDebug() << "stylename =" << stylename; |
| 132 |
} |
| 133 |
} |
| 134 |
|
| 135 |
void Widget::onClicked2() |
| 136 |
{ |
| 137 |
|
| 138 |
if (KConf2::isSettingsAvailable("test")) { |
| 139 |
KConf2 *settings = new KConf2("test.powermanager"); |
| 140 |
if (settings->get("sleep").toBool()) |
| 141 |
settings->set("sleep", "false"); |
| 142 |
else |
| 143 |
settings->set("sleep", "true"); |
| 144 |
qDebug() << "success" << settings->get("int").toString(); |
| 145 |
} |
| 146 |
} |
| 147 |
|
| 148 |
void Widget::onClicked3() |
| 149 |
{ |
| 150 |
if (KConf2::isSettingsAvailable("test")) { |
| 151 |
KConf2 *settings = new KConf2("test.notice"); |
| 152 |
auto list = settings->keys(); |
| 153 |
qDebug() << "keys list is" << list; |
| 154 |
} |
| 155 |
} |
| 156 |
|
| 157 |
void Widget::onClicked4() |
| 158 |
{ |
| 159 |
if (KConf2::isSettingsAvailable("test")) { |
| 160 |
KConf2 *settings = new KConf2("test.notice"); |
| 161 |
auto list = settings->schemas("test", "3.20.1.31"); |
| 162 |
qDebug() << "schemas list is" << list; |
| 163 |
} |
| 164 |
} |
| 165 |
|
| 166 |
void Widget::onClicked5() |
| 167 |
{ |
| 168 |
if (KConf2::isSettingsAvailable("test")) { |
| 169 |
KConf2 *settings = new KConf2("test.notice"); |
| 170 |
QString str("int"); |
| 171 |
QString str1 = settings->getDescrition(str); |
| 172 |
qDebug() << "getDescrition is" << str1; |
| 173 |
} |
| 174 |
} |
| 175 |
|
| 176 |
void Widget::onClicked6() |
| 177 |
{ |
| 178 |
if (KConf2::isSettingsAvailable("test")) { |
| 179 |
KConf2 *settings = new KConf2("test.notice"); |
| 180 |
QString str("int"); |
| 181 |
QString str1 = settings->getSummary(str); |
| 182 |
qDebug() << "getSummary is" << str1; |
| 183 |
} |
| 184 |
} |
| 185 |
|
| 186 |
void Widget::onClicked7() |
| 187 |
{ |
| 188 |
if (KConf2::isSettingsAvailable("test")) { |
| 189 |
KConf2 *settings = new KConf2("test.notice"); |
| 190 |
QString str("int"); |
| 191 |
QString str1 = settings->getType(str); |
| 192 |
qDebug() << "getType is" << str1; |
| 193 |
} |
| 194 |
} |
| 195 |
|
| 196 |
void Widget::onClicked8() |
| 197 |
{ |
| 198 |
if (KConf2::isSettingsAvailable("test")) { |
| 199 |
KConf2 *settings = new KConf2("test.notice"); |
| 200 |
QString str("int"); |
| 201 |
settings->isWritable(str); |
| 202 |
qDebug() << "isWritable " << settings->isWritable(str); |
| 203 |
} |
| 204 |
} |
| 205 |
|
| 206 |
void Widget::onClicked9() |
| 207 |
{ |
| 208 |
if (KConf2::isSettingsAvailable("test")) { |
| 209 |
KConf2 *settings = new KConf2("test.notice"); |
| 210 |
qDebug() << "getId is" << settings->getId(); |
| 211 |
} |
| 212 |
} |
| 213 |
|
| 214 |
void Widget::onClicked10() |
| 215 |
{ |
| 216 |
if (KConf2::isSettingsAvailable("test")) { |
| 217 |
KConf2 *settings = new KConf2("test.notice"); |
| 218 |
qDebug() << "getVersion is" << settings->getVersion(); |
| 219 |
} |
| 220 |
} |
| 221 |
|
| 222 |
void Widget::onClicked11() |
| 223 |
{ |
| 224 |
if (KConf2::isSettingsAvailable("test")) { |
| 225 |
KConf2 *settings = new KConf2("test.notice"); |
| 226 |
QString str("int"); |
| 227 |
KConf2 *gsetting = settings->getChild(str); |
| 228 |
qDebug() << "getChild is" << gsetting; |
| 229 |
} |
| 230 |
} |
| 231 |
|
| 232 |
void Widget::onClicked12() |
| 233 |
{ |
| 234 |
if (KConf2::isSettingsAvailable("test")) { |
| 235 |
KConf2 *settings = new KConf2("test.notice"); |
| 236 |
auto list = settings->children(); |
| 237 |
qDebug() << "children list is" << list; |
| 238 |
} |
| 239 |
} |