feat(wpa-wifi): Add system dbus interface

Description: 添加dbus接口

Log: 添加dbus接口来实现系统配置文件读写
This commit is contained in:
mammonsama666 2020-12-07 16:17:34 +08:00
parent d9333c0c7c
commit 27bb84a144
2 changed files with 53 additions and 0 deletions

View File

@ -32,3 +32,52 @@ SysdbusRegister::~SysdbusRegister()
void SysdbusRegister::systemRun(QString cmd){
QProcess::execute(cmd);
}
QStringList SysdbusRegister::getWifiInfo(QString wifiName) {
//返回名为wifiName的企业wifi的配置信息包括eap,inner和用户列表
QStringList wlist;
QString filename = "/usr/share/kylin-nm/wpaconn.conf";
QFile file(filename);
if(!file.exists()) {
return wlist;
}
QSharedPointer<QSettings> autoSettings = QSharedPointer<QSettings>(new QSettings(filename, QSettings::IniFormat));
wlist << autoSettings.get()->value("eap").toString();
wlist << autoSettings.get()->value("inner").toString();
int size = autoSettings.get()->beginReadArray(wifiName);
for (int i = 0; i < size; ++i) {
autoSettings.get()->setArrayIndex(i);
wlist << autoSettings.get()->value("user").toString();
}
autoSettings.get()->endArray();
return wlist;
}
bool SysdbusRegister::appendWifiInfo(QString name, QString eap, QString inner, QString user) {
//向配置文件添加名为name的wifi配置包括eap,inner和它的第一个用户
QString filename = "/usr/share/kylin-nm/wpaconn.conf";
QSharedPointer<QSettings> autoSettings = QSharedPointer<QSettings>(new QSettings(filename, QSettings::IniFormat));
autoSettings.get()->beginGroup(name);
autoSettings.get()->setValue("eap", eap);
autoSettings.get()->setValue("inner", inner);
//以数组形式写入用户名
autoSettings.get()->beginWriteArray(name);
autoSettings.get()->setArrayIndex(0);
autoSettings.get()->setValue("user", user);
autoSettings.get()->endArray();
return true;
}
bool SysdbusRegister::appendWifiUser(QString name, QString user) {
//向名为name的wifi用户列表添加名为user的用户名
QString filename = "/usr/share/kylin-nm/wpaconn.conf";
QSharedPointer<QSettings> autoSettings = QSharedPointer<QSettings>(new QSettings(filename, QSettings::IniFormat));
autoSettings.get()->beginWriteArray(name);
autoSettings.get()->setArrayIndex(0);
//读到用户名列表长度并在队尾添加一个用户名
int size = autoSettings.get()->beginReadArray(name);
autoSettings.get()->setArrayIndex(size);
autoSettings.get()->setValue("user", user);
autoSettings.get()->endArray();
return true;
}

View File

@ -24,6 +24,7 @@
#include <QDBusConnection>
#include <QDBusReply>
#include <QDBusInterface>
#include <QString>
#include <QFile>
@ -47,6 +48,9 @@ signals:
public slots:
Q_SCRIPTABLE void systemRun(QString cmd);
Q_SCRIPTABLE QStringList getWifiInfo(QString wifiName);
Q_SCRIPTABLE bool appendWifiInfo(QString name, QString eap, QString inner, QString user);
Q_SCRIPTABLE bool appendWifiUser(QString name, QString user);
};