added page to display WireGuard client information
This commit is contained in:
parent
a42beb86c0
commit
8c137ecc52
9 changed files with 216 additions and 76 deletions
|
@ -14,13 +14,22 @@ void ClientManagementModel::clearData()
|
|||
endResetModel();
|
||||
}
|
||||
|
||||
void ClientManagementModel::setContent(const QVector<ClientInfo> &data)
|
||||
void ClientManagementModel::setContent(const QVector<QVariant> &data)
|
||||
{
|
||||
beginResetModel();
|
||||
m_content = data;
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
QJsonObject ClientManagementModel::getContent()
|
||||
{
|
||||
QJsonObject clientsTable;
|
||||
for (const auto &item : m_content) {
|
||||
clientsTable[item.toJsonObject()["openvpnCertId"].toString()] = item.toJsonObject();
|
||||
}
|
||||
return clientsTable;
|
||||
}
|
||||
|
||||
int ClientManagementModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
Q_UNUSED(parent);
|
||||
|
@ -35,14 +44,15 @@ QVariant ClientManagementModel::data(const QModelIndex &index, int role) const
|
|||
}
|
||||
|
||||
if (role == NameRole) {
|
||||
return m_content[index.row()].name;
|
||||
}
|
||||
if (role == CertIdRole) {
|
||||
return m_content[index.row()].certId;
|
||||
}
|
||||
if (role == CertDataRole) {
|
||||
return m_content[index.row()].certData;
|
||||
return m_content[index.row()].toJsonObject()["clientName"].toString();
|
||||
} else if (role == OpenVpnCertIdRole) {
|
||||
return m_content[index.row()].toJsonObject()["openvpnCertId"].toString();
|
||||
} else if (role == OpenVpnCertDataRole) {
|
||||
return m_content[index.row()].toJsonObject()["openvpnCertData"].toString();
|
||||
} else if (role == WireGuardPublicKey) {
|
||||
return m_content[index.row()].toJsonObject()["wireguardPublicKey"].toString();
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
|
@ -53,15 +63,19 @@ void ClientManagementModel::setData(const QModelIndex &index, QVariant data, int
|
|||
return;
|
||||
}
|
||||
|
||||
auto client = m_content[index.row()].toJsonObject();
|
||||
if (role == NameRole) {
|
||||
m_content[index.row()].name = data.toString();
|
||||
}
|
||||
if (role == CertIdRole) {
|
||||
m_content[index.row()].certId = data.toString();
|
||||
}
|
||||
if (role == CertDataRole) {
|
||||
m_content[index.row()].certData = data.toString();
|
||||
client["clientName"] = data.toString();
|
||||
} else if (role == OpenVpnCertIdRole) {
|
||||
client["openvpnCertId"] = data.toString();
|
||||
} else if (role == OpenVpnCertDataRole) {
|
||||
client["openvpnCertData"] = data.toString();
|
||||
} else if (role == WireGuardPublicKey) {
|
||||
client["wireguardPublicKey"] = data.toString();
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
m_content[index.row()] = client;
|
||||
emit dataChanged(index, index);
|
||||
}
|
||||
|
||||
|
@ -69,7 +83,8 @@ QHash<int, QByteArray> ClientManagementModel::roleNames() const
|
|||
{
|
||||
QHash<int, QByteArray> roles;
|
||||
roles[NameRole] = "clientName";
|
||||
roles[CertIdRole] = "certId";
|
||||
roles[CertDataRole] = "certData";
|
||||
roles[OpenVpnCertIdRole] = "openvpnCertId";
|
||||
roles[OpenVpnCertDataRole] = "openvpnCertData";
|
||||
roles[WireGuardPublicKey] = "wireguardPublicKey";
|
||||
return roles;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue