网络模式ui和方法

This commit is contained in:
zhangyuanyuan1 2022-07-22 16:11:04 +08:00
parent 786d3dbd1f
commit 011c09a7f4
5 changed files with 279 additions and 0 deletions

View File

@ -0,0 +1,89 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* Copyright (C) 2022 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "firewalldialog.h"
#define ICON_SIZE 16,16
FirewallDialog::FirewallDialog(KDialog *parent)
{
initUI();
this->setWindowIcon(QIcon::fromTheme("kylin-network"));
this->setFixedSize(480, 204);
setAttribute(Qt::WA_DeleteOnClose);
}
FirewallDialog::~FirewallDialog()
{
}
void FirewallDialog::initUI()
{
m_iconLabel = new QLabel(this);
m_contentLabel = new QLabel(this);
m_suggestLabel = new QLabel(this);
m_YesBtn = new QPushButton(this);
m_NoBtn = new QPushButton(this);
m_dialogLayout = new QVBoxLayout(this);
QWidget *contentWidget = new QWidget(this);
QGridLayout *contentLayout = new QGridLayout(contentWidget);
contentLayout->setContentsMargins(0, 0, 0, 0);
contentLayout->addWidget(m_iconLabel, 0, 0, Qt::AlignTop);
contentLayout->addWidget(m_contentLabel, 0, 1);
contentLayout->addWidget(m_suggestLabel, 1, 1);
m_iconLabel->setFixedWidth(16);
QWidget *btnWidget = new QWidget(this);
QHBoxLayout *btnLayout = new QHBoxLayout(btnWidget);
btnLayout->setContentsMargins(0, 0, 0, 0);
btnLayout->setSpacing(16);
btnLayout->addStretch();
btnLayout->addWidget(m_YesBtn);
btnLayout->addWidget(m_NoBtn);
m_dialogLayout->setContentsMargins(24, 0, 24, 24);
m_dialogLayout->setSpacing(0);
m_dialogLayout->addWidget(contentWidget);
m_dialogLayout->addStretch();
m_dialogLayout->addWidget(btnWidget);
QIcon icon = QIcon::fromTheme("dialog-info");
m_iconLabel->setPixmap(icon.pixmap(ICON_SIZE));
QFont font = m_contentLabel->font();
font.setWeight(75);
m_contentLabel->setFont(font);
//是否允许你的电脑被此网络上的其他电脑和设备发现?
m_contentLabel->setText(tr("Allow your computer to be discovered by other computers and devices on this network"));
m_contentLabel->setWordWrap(true);
//建议你在家庭和工作网络上而非公共网络上启用此功能。
m_suggestLabel->setText(tr("It is recommended that you enable this feature on your home and work networks rather than public networks."));
m_suggestLabel->setWordWrap(true);
m_YesBtn->setText(tr("Yse"));
m_NoBtn->setText(tr("No"));
this->closeButton();
this->mainWidget()->setLayout(m_dialogLayout);
connect(m_YesBtn, &QPushButton::clicked, this, &FirewallDialog::setPrivateNetMode);
connect(m_NoBtn, &QPushButton::clicked, this, &FirewallDialog::setPublicNetMode);
}

View File

@ -0,0 +1,53 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* Copyright (C) 2022 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#ifndef FIREWALLDIALOG_H
#define FIREWALLDIALOG_H
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QFormLayout>
#include <QLabel>
#include "kwidget.h"
#include "kdialog.h"
using namespace kdk;
class FirewallDialog : public KDialog
{
Q_OBJECT
public:
explicit FirewallDialog(KDialog *parent = nullptr);
~FirewallDialog();
private:
void initUI();
QLabel * m_iconLabel = nullptr;
QLabel * m_contentLabel = nullptr;
QLabel * m_suggestLabel = nullptr;
QVBoxLayout *m_dialogLayout = nullptr;
QPushButton *m_YesBtn = nullptr;
QPushButton *m_NoBtn = nullptr;
signals:
void setPublicNetMode();
void setPrivateNetMode();
};
#endif // FIREWALLDIALOG_H

View File

@ -0,0 +1,10 @@
INCLUDEPATH += $$PWD
HEADERS += \
$$PWD/firewalldialog.h \
$$PWD/networkmodeconfig.h
SOURCES += \
$$PWD/firewalldialog.cpp \
$$PWD/networkmodeconfig.cpp

View File

@ -0,0 +1,81 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* Copyright (C) 2022 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "networkmodeconfig.h"
#include <QDebug>
NetworkModeConfig *NetworkModeConfig::m_netModeInstance = nullptr;
NetworkModeConfig *NetworkModeConfig::getInstance()
{
if (m_netModeInstance == NULL) {
m_netModeInstance = new NetworkModeConfig();
}
return m_netModeInstance;
}
NetworkModeConfig::NetworkModeConfig(QObject *parent) : QObject(parent)
{
m_dbusInterface = new QDBusInterface("com.ksc.defender",
"/firewall",
"com.ksc.defender.firewall",
QDBusConnection::systemBus());
if(!m_dbusInterface->isValid()) {
qWarning ()<< "init com.ksc.defender dbus error";
}
}
int NetworkModeConfig::getNetworkModeConfig(QString uuid)
{
if (uuid.isEmpty()) {
qWarning()<< /*LOG_FLAG <<*/ "uuid is empty, so can not get network mode config";
return -1;
}
QDBusReply<int> reply = m_dbusInterface->call("get_networkModeConfig", uuid);
if (reply.isValid()) {
return reply.value();
} else {
qWarning() << "call get_networkModeConfig failed" << reply.error().message();
}
return -1;
}
void NetworkModeConfig::setNetworkModeConfig(QString uuid, QString cardName, QString ssid, int mode)
{
QDBusReply<int> reply = m_dbusInterface->call("set_networkModeConfig", uuid, cardName, ssid, mode);
if (reply.isValid()) {
qDebug() << "set_networkModeConfig" << ssid << uuid << cardName << mode << ",result" << reply.value();
} else {
qWarning() << "call set_networkModeConfig" << reply.error().message();
}
}
int NetworkModeConfig::breakNetworkConnect(QString uuid, QString cardName, QString ssid)
{
QDBusReply<int> reply = m_dbusInterface->call("break_networkConnect", uuid, cardName, ssid);
if (reply.isValid()) {
qDebug() << "break_networkConnect" << ssid << uuid << cardName << ",result" << reply.value();
return reply.value();
} else {
qWarning() << "call break_networkConnect failed" << reply.error().message();
return -1;
}
}

View File

@ -0,0 +1,46 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* Copyright (C) 2022 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#ifndef NETWORKMODECONFIG_H
#define NETWORKMODECONFIG_H
#include <QObject>
#include <QDBusInterface>
#include <QDBusReply>
class NetworkModeConfig : public QObject
{
Q_OBJECT
public:
static NetworkModeConfig *getInstance();
//安全中心-获取网络模式配置
int getNetworkModeConfig(QString uuid);
//安全中心-设置网络模式配置
void setNetworkModeConfig(QString uuid, QString cardName, QString ssid, int mode);
//安全中心-解除连接(用于防火墙处从正在使用的网络中删除)
int breakNetworkConnect(QString uuid, QString cardName, QString ssid);
static NetworkModeConfig *m_netModeInstance;
private:
explicit NetworkModeConfig(QObject *parent = nullptr);
QDBusInterface *m_dbusInterface = nullptr;
};
#endif // NETWORKMODECONFIG_H