merge
This commit is contained in:
commit
e288e0b305
|
@ -6,7 +6,7 @@ KyNetworkDeviceResourse::KyNetworkDeviceResourse(QObject *parent) : QObject(pare
|
|||
m_networkResourceInstance = KyNetworkResourceManager::getInstance();
|
||||
|
||||
// m_activeConnectUuidList.clear();
|
||||
m_activeConnectUuidMap.clear();
|
||||
//m_activeConnectUuidMap.clear();
|
||||
m_deviceMap.clear();
|
||||
//TODO::get uuid from settings for system reboot;
|
||||
|
||||
|
@ -176,8 +176,6 @@ void KyNetworkDeviceResourse::DeviceSpeed(QString deviceName, KyConnectItem *wir
|
|||
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void KyNetworkDeviceResourse::disconnectDevice()
|
||||
{
|
||||
|
@ -251,6 +249,8 @@ void KyNetworkDeviceResourse::setDeviceAutoConnect()
|
|||
return;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void KyNetworkDeviceResourse::onDeviceUpdate(NetworkManager::Device * dev)
|
||||
{
|
||||
QString dbusPath = dev->uni();
|
||||
|
|
|
@ -34,14 +34,14 @@ public:
|
|||
bool wiredDeviceCarriered(QString deviceName);
|
||||
//void DeviceSpeed(QString deviceName, KyWiredConnectItem *wiredItem);
|
||||
void setDeviceRefreshRate(QString deviceName, int ms);
|
||||
void disconnectDevice();
|
||||
void setDeviceAutoConnect();
|
||||
// void disconnectDevice();
|
||||
//void setDeviceAutoConnect();
|
||||
|
||||
private:
|
||||
KyWiredConnectOperation wiredOperation;
|
||||
KyNetworkResourceManager *m_networkResourceInstance = nullptr;
|
||||
QStringList m_activeConnectUuidList;
|
||||
QMap<QString, QString> m_activeConnectUuidMap;
|
||||
// QMap<QString, QString> m_activeConnectUuidMap;
|
||||
QMap<QString, QString> m_deviceMap;
|
||||
|
||||
void initDeviceMap();
|
||||
|
|
|
@ -164,3 +164,92 @@ void KyWiredConnectOperation::activateVpnConnection(const QString connectUuid)
|
|||
|
||||
return;
|
||||
}
|
||||
|
||||
void KyWiredConnectOperation::saveActiveConnection(QString &deviceName, QString &connectUuid)
|
||||
{
|
||||
QSettings *p_settings = new QSettings(WIRED_NETWORK_STATE_CONF_FILE, QSettings::IniFormat);
|
||||
|
||||
QString settingValue = p_settings->value(deviceName).toString();
|
||||
if (settingValue.isEmpty()) {
|
||||
p_settings->setValue(deviceName, connectUuid);
|
||||
p_settings->sync();
|
||||
}
|
||||
|
||||
delete p_settings;
|
||||
p_settings = nullptr;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void KyWiredConnectOperation::getActiveConnection(QString &deviceName, QString &connectUuid)
|
||||
{
|
||||
QSettings *p_settings = new QSettings(WIRED_NETWORK_STATE_CONF_FILE, QSettings::IniFormat);
|
||||
|
||||
connectUuid = p_settings->value(deviceName).toString();
|
||||
p_settings->remove(deviceName);
|
||||
|
||||
delete p_settings;
|
||||
p_settings = nullptr;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int KyWiredConnectOperation::closeWiredNetworkWithDevice(QString deviceName)
|
||||
{
|
||||
NetworkManager::Device::Ptr wiredDevicePtr =
|
||||
m_networkResourceInstance->findDeviceInterface(deviceName);
|
||||
|
||||
if (wiredDevicePtr.isNull()) {
|
||||
qWarning()<<"[KyWiredConnectOperation]"<<"the network device" << deviceName <<"is not exist.";
|
||||
return -ENXIO;
|
||||
}
|
||||
|
||||
if (NetworkManager::Device::Type::Ethernet != wiredDevicePtr->type()) {
|
||||
qWarning()<<"[KyWiredConnectOperation]"<<"the device type"
|
||||
<< wiredDevicePtr->type() <<"is not Ethernet.";
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
NetworkManager::ActiveConnection::Ptr activeConnectPtr = wiredDevicePtr->activeConnection();
|
||||
if (nullptr != activeConnectPtr) {
|
||||
QString activeConnectUuid = activeConnectPtr->uuid();
|
||||
if (!activeConnectUuid.isEmpty()) {
|
||||
qDebug()<<"[KyWiredConnectOperation]" <<"close wired network save connection uuid"
|
||||
<< activeConnectUuid <<"device name " << deviceName;
|
||||
saveActiveConnection(deviceName, activeConnectUuid);
|
||||
}
|
||||
}
|
||||
|
||||
wiredDevicePtr->disconnectInterface();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int KyWiredConnectOperation::openWiredNetworkWithDevice(QString deviceName)
|
||||
{
|
||||
NetworkManager::Device::Ptr wiredDevicePtr =
|
||||
m_networkResourceInstance->findDeviceInterface(deviceName);
|
||||
|
||||
if (!wiredDevicePtr->isValid()) {
|
||||
qWarning()<<"[KyWiredConnectOperation]"<<"the network device" << deviceName <<"is not exist.";
|
||||
return -ENXIO;
|
||||
}
|
||||
|
||||
if (NetworkManager::Device::Type::Ethernet != wiredDevicePtr->type()) {
|
||||
qWarning()<<"[KyWiredConnectOperation]"<<"the device type"
|
||||
<< wiredDevicePtr->type() <<"is not Ethernet.";
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
QString connectUuid;
|
||||
getActiveConnection(deviceName, connectUuid);
|
||||
if (!connectUuid.isEmpty()) {
|
||||
qDebug()<<"[KyWiredConnectOperation]" << "open wired network active connection"
|
||||
<< connectUuid <<"device name" << deviceName;
|
||||
activateConnection(connectUuid, deviceName);
|
||||
}
|
||||
|
||||
wiredDevicePtr->setAutoconnect(true);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,10 +1,15 @@
|
|||
#ifndef KYLINWIREDCONNECTOPERATION_H
|
||||
#define KYLINWIREDCONNECTOPERATION_H
|
||||
|
||||
#include <QSettings>
|
||||
#include <QDir>
|
||||
|
||||
#include "kylinnetworkresourcemanager.h"
|
||||
#include "kylinconnectsetting.h"
|
||||
#include "kylinconnectoperation.h"
|
||||
|
||||
const QString WIRED_NETWORK_STATE_CONF_FILE = QDir::homePath() + "/.config/ukui/kylin-nm-wired.ini";
|
||||
|
||||
class KyWiredConnectOperation : public KyConnectOperation
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -19,6 +24,13 @@ public:
|
|||
void activateWiredConnection(const QString connectUuid, const QString devName);
|
||||
void activateVpnConnection(const QString connectUuid);
|
||||
void deactivateWiredConnection(const QString activeConnectName, const QString &activeConnectUuid);
|
||||
|
||||
int closeWiredNetworkWithDevice(QString deviceName);
|
||||
int openWiredNetworkWithDevice(QString deviceName);
|
||||
|
||||
private:
|
||||
void getActiveConnection(QString &deviceName, QString &connectUuid);
|
||||
void saveActiveConnection(QString &deviceName, QString &connectUuid);
|
||||
};
|
||||
|
||||
#endif // KYLINWIREDCONNECTOPERATION_H
|
||||
|
|
|
@ -117,16 +117,17 @@ void KyWirelessNetResource::getWirelessActiveConnection(NetworkManager::ActiveCo
|
|||
continue;
|
||||
}
|
||||
|
||||
qDebug() << "getWirelessActiveConnection " << activeConnectionPtr->uuid();
|
||||
QString ssid;
|
||||
QString ifaceName = getDeviceIFace(activeConnectionPtr,ssid);
|
||||
if(ifaceName.isEmpty() || ssid.isNull()) {
|
||||
continue;
|
||||
}
|
||||
if (map.contains(ifaceName)) {
|
||||
map[ifaceName].append(ssid);
|
||||
map[ifaceName].append(activeConnectionPtr->uuid());
|
||||
} else {
|
||||
QStringList list;
|
||||
list.append(ssid);
|
||||
list.append(activeConnectionPtr->uuid());
|
||||
map.insert(ifaceName,list);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,37 +7,26 @@
|
|||
LanListItem::LanListItem(KyConnectItem *data, QString deviceName, QWidget *parent)
|
||||
: m_data(data), deviceName(deviceName), ListItem(parent) //item数据传入
|
||||
{
|
||||
m_connectOperation = new KyWiredConnectOperation;
|
||||
m_connectOperation = new KyWiredConnectOperation(this);
|
||||
m_activeConnectResource = new KyActiveConnectResourse(this);
|
||||
m_connectResource = new KyConnectResourse(this);
|
||||
m_data = data;
|
||||
m_nameLabel->setText(m_data->m_connectName);
|
||||
|
||||
// if (m_data != nullptr) {
|
||||
// if (m_data->m_connectState == NetworkManager::ActiveConnection::State::Activated) {
|
||||
// setIcon(true);
|
||||
// m_isActive = true;
|
||||
// } else {
|
||||
// setIcon(false);
|
||||
// m_isActive = false;
|
||||
// }
|
||||
// }
|
||||
if (m_data != nullptr) {
|
||||
if (m_data->m_connectState == NetworkManager::ActiveConnection::State::Activated) {
|
||||
m_netButton->stopLoading();
|
||||
setIcon(true);
|
||||
m_isActive = true;
|
||||
} else if (m_data->m_connectState == NetworkManager::ActiveConnection::State::Deactivated)
|
||||
{
|
||||
m_netButton->stopLoading();
|
||||
setIcon(false);
|
||||
m_isActive = false;
|
||||
} else
|
||||
{
|
||||
// m_netButton->startLoading();
|
||||
setIcon(false);
|
||||
m_isActive = false;
|
||||
}
|
||||
}
|
||||
m_netButton->setActive(m_isActive);
|
||||
m_itemFrame->installEventFilter(this);
|
||||
connect(this->m_infoButton, &InfoButton::clicked, this, &LanListItem::onInfoButtonClicked);
|
||||
connect(m_activeConnectResource, &KyActiveConnectResourse::stateChangeReason, this, &LanListItem::onLanStatusChange);
|
||||
}
|
||||
|
||||
LanListItem::LanListItem(QWidget *parent) : ListItem(parent)
|
||||
|
@ -49,6 +38,15 @@ LanListItem::LanListItem(QWidget *parent) : ListItem(parent)
|
|||
this->m_infoButton->hide();
|
||||
}
|
||||
|
||||
void LanListItem::setIcon(bool isOn)
|
||||
{
|
||||
if (isOn) {
|
||||
m_netButton->setButtonIcon(QIcon::fromTheme("network-wired-connected-symbolic"));
|
||||
} else {
|
||||
m_netButton->setButtonIcon(QIcon::fromTheme("network-wired-disconnected-symbolic"));
|
||||
}
|
||||
}
|
||||
|
||||
void LanListItem::onNetButtonClicked()
|
||||
{
|
||||
if(!m_data){
|
||||
|
@ -58,45 +56,18 @@ void LanListItem::onNetButtonClicked()
|
|||
if (!m_isActive) {
|
||||
//未连接,点击后连
|
||||
m_connectOperation->activateWiredConnection(m_data->m_connectUuid, deviceName);
|
||||
qDebug() << m_data->m_connectName << "Connect after user clicked!";
|
||||
qDebug() << m_data->m_connectName << "Connect after user clicked!" << deviceName;
|
||||
// m_data->m_connectState = NetworkManager::ActiveConnection::State::Activating;
|
||||
// refreshIcon();
|
||||
m_isActive = true;
|
||||
} else {
|
||||
//连接,点击后断开
|
||||
m_connectOperation->deactivateWiredConnection(m_data->m_connectName, m_data->m_connectUuid);
|
||||
qDebug() << m_data->m_connectName << "Disconnect after user clicked!";
|
||||
qDebug() << m_data->m_connectName << "Disconnect after user clicked!" << deviceName;
|
||||
// m_data->m_connectState = NetworkManager::ActiveConnection::State::Deactivated;
|
||||
// refreshIcon();
|
||||
m_isActive = false;
|
||||
}
|
||||
}
|
||||
|
||||
void LanListItem::setIcon(bool isOn)
|
||||
{
|
||||
if (isOn) {
|
||||
m_netButton->setButtonIcon(QIcon::fromTheme("network-wired-connected-symbolic"));
|
||||
} else {
|
||||
m_netButton->setButtonIcon(QIcon::fromTheme("network-wired-disconnected-symbolic"));
|
||||
}
|
||||
}
|
||||
void LanListItem::refreshIcon()
|
||||
{
|
||||
switch (m_data->m_connectState) {
|
||||
case NetworkManager::ActiveConnection::State::Activated:
|
||||
m_netButton->stopLoading();
|
||||
setIcon(true);
|
||||
break;
|
||||
case NetworkManager::ActiveConnection::State::Activating:
|
||||
m_netButton->startLoading();
|
||||
break;
|
||||
case NetworkManager::ActiveConnection::State::Deactivated:
|
||||
m_netButton->stopLoading();
|
||||
setIcon(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void LanListItem::onRightButtonClicked()
|
||||
{
|
||||
//右键点击事件
|
||||
|
@ -114,3 +85,22 @@ void LanListItem::onInfoButtonClicked()
|
|||
qDebug() << "On lan info button clicked! But there is no wlan connect " ;
|
||||
}
|
||||
}
|
||||
|
||||
void LanListItem::onLanStatusChange(QString uuid, NetworkManager::ActiveConnection::State state, NetworkManager::ActiveConnection::Reason reason)
|
||||
{
|
||||
qDebug() <<"[LanListItem]:Connection State Change to:" << state;
|
||||
if (m_data->m_connectUuid == uuid) {
|
||||
if (state == NetworkManager::ActiveConnection::State::Activating || state == NetworkManager::ActiveConnection::State::Deactivating) {
|
||||
qDebug() << "[LanListItem]:Activating!Loading!" << state;
|
||||
m_netButton->startLoading();
|
||||
} else {
|
||||
qDebug() << "[LanListItem]:Stop!" << state;
|
||||
m_netButton->stopLoading();
|
||||
if (state == NetworkManager::ActiveConnection::State::Activated) {
|
||||
setIcon(true);
|
||||
} else {
|
||||
setIcon(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,9 +18,10 @@ public:
|
|||
|
||||
KyConnectItem *m_data = nullptr;
|
||||
KyWiredConnectOperation *m_connectOperation = nullptr;
|
||||
KyActiveConnectResourse *m_activeConnectResource = nullptr;
|
||||
KyConnectResourse *m_connectResource = nullptr;
|
||||
|
||||
QString deviceName = "";
|
||||
void refreshIcon();
|
||||
|
||||
protected:
|
||||
void setIcon(bool isOn);
|
||||
|
@ -32,6 +33,7 @@ private:
|
|||
private slots:
|
||||
void onInfoButtonClicked();
|
||||
void onNetButtonClicked();
|
||||
void onLanStatusChange(QString uuid, NetworkManager::ActiveConnection::State state, NetworkManager::ActiveConnection::Reason reason);
|
||||
};
|
||||
|
||||
#endif // LANLISTITEM_H
|
||||
|
|
|
@ -78,6 +78,9 @@ void WlanListItem::resizeEvent(QResizeEvent *event)
|
|||
|
||||
void WlanListItem::onRightButtonClicked()
|
||||
{
|
||||
if (!m_menu) {
|
||||
return;
|
||||
}
|
||||
m_menu->clear();
|
||||
if (!this->m_data) {
|
||||
return;
|
||||
|
@ -122,8 +125,8 @@ void WlanListItem::initWlanUI()
|
|||
#define CONNECT_BUTTON_WIDTH 96
|
||||
#define FRAME_CONTENT_MARGINS 56,4,16,4
|
||||
#define FRAME_SPACING 8
|
||||
#define PWD_CONTENT_MARGINS 8,0,32,0
|
||||
#define SHOW_PWD_BUTTON_SIZE 16,16
|
||||
#define PWD_CONTENT_MARGINS 8,0,34,0
|
||||
#define SHOW_PWD_BUTTON_SIZE 24,24
|
||||
#define PWD_LAYOUT_MARGINS 8,0,8,0
|
||||
//密码输入区域的UI
|
||||
m_pwdFrame = new QFrame(this);
|
||||
|
@ -136,11 +139,15 @@ void WlanListItem::initWlanUI()
|
|||
connect(m_pwdLineEdit, &QLineEdit::textChanged, this, &WlanListItem::onPwdEditorTextChanged);
|
||||
m_pwdLineEdit->setFixedHeight(PWD_AREA_HEIGHT);
|
||||
m_pwdLineEdit->setEchoMode(QLineEdit::EchoMode::Password);
|
||||
m_pwdLineEdit->setTextMargins(PWD_CONTENT_MARGINS);
|
||||
m_pwdLineEditLyt = new QHBoxLayout(m_pwdLineEdit);
|
||||
m_pwdLineEditLyt->setContentsMargins(PWD_LAYOUT_MARGINS);
|
||||
m_pwdLineEdit->setLayout(m_pwdLineEditLyt);
|
||||
m_showPwdButton = new QPushButton(m_pwdLineEdit);
|
||||
m_showPwdButton->setFixedSize(SHOW_PWD_BUTTON_SIZE);
|
||||
m_showPwdButton->setAutoFillBackground(false);
|
||||
m_showPwdButton->setIcon(QIcon(":/res/h/hide-pwd.png"));
|
||||
m_showPwdButton->setCursor(Qt::PointingHandCursor);
|
||||
connect(m_showPwdButton, &QPushButton::clicked, this, &WlanListItem::onShowPwdButtonClicked);
|
||||
m_pwdLineEditLyt->addStretch();
|
||||
m_pwdLineEditLyt->addWidget(m_showPwdButton);
|
||||
|
@ -329,11 +336,10 @@ void WlanListItem::onShowPwdButtonClicked()
|
|||
return;
|
||||
}
|
||||
if (m_pwdLineEdit->echoMode() == QLineEdit::EchoMode::Password) {
|
||||
//TODO 按钮图标要发生改变
|
||||
|
||||
m_showPwdButton->setIcon(QIcon(":/res/h/show-pwd.png"));
|
||||
m_pwdLineEdit->setEchoMode(QLineEdit::EchoMode::Normal);
|
||||
} else {
|
||||
//TODO 按钮图标要发生改变
|
||||
m_showPwdButton->setIcon(QIcon(":/res/h/hide-pwd.png"));
|
||||
m_pwdLineEdit->setEchoMode(QLineEdit::EchoMode::Password);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1421,7 +1421,7 @@ void OldMainWindow::onBtnLanClicked(int flag)
|
|||
switch (flag) {
|
||||
case 0: {
|
||||
qDebug()<<"On btnWired clicked! will close switch button----------------------------";
|
||||
m_networkDevice.disconnectDevice();
|
||||
// m_networkDevice.disconnectDevice();
|
||||
emit this->onWiredDeviceChanged(false);
|
||||
#if 0
|
||||
QtConcurrent::run([=]() {
|
||||
|
@ -1439,7 +1439,7 @@ void OldMainWindow::onBtnLanClicked(int flag)
|
|||
}
|
||||
case 1: {
|
||||
qDebug()<<"On btnWired clicked! will open switch button++++++++++++++++++++++++++++";
|
||||
m_networkDevice.setDeviceAutoConnect();
|
||||
//m_networkDevice.setDeviceAutoConnect();
|
||||
emit this->onWiredDeviceChanged(true);
|
||||
#if 0
|
||||
QtConcurrent::run([=]() {
|
||||
|
|
|
@ -116,8 +116,19 @@ void MainWindow::initUI()
|
|||
m_lanWidget = new LanPage(m_centralWidget);
|
||||
m_wlanWidget = new WlanPage(m_centralWidget);
|
||||
connect(this, &MainWindow::mainWindowVisibleChanged, m_wlanWidget, &WlanPage::onMainWindowVisibleChanged);
|
||||
m_centralWidget->addTab(m_lanWidget, QIcon::fromTheme("network-wired-connected-symbolic", QIcon::fromTheme("network-wired-symbolic", QIcon(":/res/l/network-online.svg"))), tr("LAN"));
|
||||
m_centralWidget->addTab(m_wlanWidget, QIcon::fromTheme("network-wireless-signal-excellent-symbolic", QIcon(":/res/x/wifi-list-bg.svg")), tr("WLAN"));
|
||||
// m_centralWidget->addTab(m_lanWidget, QIcon::fromTheme("network-wired-connected-symbolic", QIcon::fromTheme("network-wired-symbolic", QIcon(":/res/l/network-online.svg"))), tr("LAN"));
|
||||
// m_centralWidget->addTab(m_wlanWidget, QIcon::fromTheme("network-wireless-signal-excellent-symbolic", QIcon(":/res/x/wifi-list-bg.svg")), tr("WLAN"));
|
||||
|
||||
m_centralWidget->addTab(m_lanWidget, tr(""));
|
||||
m_centralWidget->addTab(m_wlanWidget,tr(""));
|
||||
m_tabBarLayout = new QHBoxLayout(this);
|
||||
m_lanLabel = new QLabel(tr("LAN"));
|
||||
m_lanLabel->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
|
||||
m_wlanLabel = new QLabel(tr("WLAN"));
|
||||
m_wlanLabel->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
|
||||
m_tabBarLayout->addWidget(m_lanLabel);
|
||||
m_tabBarLayout->addWidget(m_wlanLabel);
|
||||
m_centralWidget->tabBar()->setLayout(m_tabBarLayout);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -92,6 +92,9 @@ private:
|
|||
|
||||
//主窗口的主要构成控件
|
||||
QTabWidget * m_centralWidget = nullptr;
|
||||
QHBoxLayout * m_tabBarLayout = nullptr;
|
||||
QLabel * m_lanLabel = nullptr;
|
||||
QLabel * m_wlanLabel = nullptr;
|
||||
|
||||
LanPage * m_lanWidget = nullptr;
|
||||
WlanPage * m_wlanWidget = nullptr;
|
||||
|
|
|
@ -19,27 +19,32 @@ const QString WIRED_SWITCH = "wiredswitch";
|
|||
|
||||
LanPage::LanPage(QWidget *parent) : TabPage(parent)
|
||||
{
|
||||
//释放问题
|
||||
m_activeResourse = new KyActiveConnectResourse(this);
|
||||
m_connectResourse = new KyConnectResourse(this);
|
||||
m_device = new KyNetworkDeviceResourse(this);
|
||||
m_wiredConnectOperation = new KyWiredConnectOperation(this);
|
||||
devList.empty();
|
||||
m_nullLanItem = new LanListItem();
|
||||
|
||||
m_devList.empty();
|
||||
|
||||
initUI();
|
||||
|
||||
if (QGSettings::isSchemaInstalled(GSETTINGS_SCHEMA)) {
|
||||
m_switchGsettings = new QGSettings(GSETTINGS_SCHEMA);
|
||||
initNetSwitch();
|
||||
m_switchGsettings = new QGSettings(GSETTINGS_SCHEMA);
|
||||
initNetSwitch();
|
||||
} else {
|
||||
qDebug()<<"[LanPage] org.ukui.kylin-nm.switch is not installed!";
|
||||
qDebug()<<"[LanPage] org.ukui.kylin-nm.switch is not installed!";
|
||||
}
|
||||
initDevice();
|
||||
|
||||
initDeviceCombox();
|
||||
initList(m_deviceName);
|
||||
|
||||
connect(m_activeResourse, &KyActiveConnectResourse::stateChangeReason, this, &LanPage::updateLanlist);
|
||||
connect(m_connectResourse, &KyConnectResourse::connectionAdd, this, &LanPage::addConnectionSlot);
|
||||
connect(m_connectResourse, &KyConnectResourse::connectionRemove, this, &LanPage::removeConnectionSlot);
|
||||
connect(m_connectResourse, &KyConnectResourse::connectionUpdate, this, &LanPage::connectionUpdateSlot);
|
||||
|
||||
connect(m_connectResourse, &KyConnectResourse::connectionUpdate, this, &LanPage::onLanDataChange);
|
||||
|
||||
connect(m_device, &KyNetworkDeviceResourse::deviceAdd, this, &LanPage::onDeviceAdd);
|
||||
connect(m_device, &KyNetworkDeviceResourse::deviceRemove, this, &LanPage::onDeviceRemove);
|
||||
connect(m_device, &KyNetworkDeviceResourse::deviceNameUpdate, this, &LanPage::onDeviceNameUpdate);
|
||||
|
@ -47,9 +52,6 @@ LanPage::LanPage(QWidget *parent) : TabPage(parent)
|
|||
connect(m_wiredConnectOperation, &KyWiredConnectOperation::activateConnectionError, this, &LanPage::activateFailed);
|
||||
connect(m_wiredConnectOperation, &KyWiredConnectOperation::deactivateConnectionError, this, &LanPage::deactivateFailed);
|
||||
|
||||
|
||||
//为什么同一个类中要用信号槽
|
||||
connect(this, &LanPage::deviceStatusChanged, this, &LanPage::onDeviceChanged);
|
||||
}
|
||||
|
||||
LanPage::~LanPage()
|
||||
|
@ -61,17 +63,7 @@ void LanPage::initNetSwitch()
|
|||
{
|
||||
if (m_switchGsettings->keys().contains(WIRED_SWITCH)) {
|
||||
m_netSwitch->setSwitchStatus(m_switchGsettings->get(WIRED_SWITCH).toBool());
|
||||
if (m_netSwitch->getSwitchStatus()) {
|
||||
if (m_deviceMap.count() <= 1) {
|
||||
m_deviceFrame->hide();
|
||||
} else {
|
||||
m_deviceFrame->show();
|
||||
initDeviceCombox();
|
||||
}
|
||||
} else {
|
||||
m_inactivatedLanListWidget->hide();
|
||||
m_deviceFrame->hide();
|
||||
}
|
||||
initDeviceCombox();
|
||||
connect(m_switchGsettings, &QGSettings::changed, this, &LanPage::onSwithGsettingsChanged);
|
||||
}
|
||||
connect(m_netSwitch, &SwitchButton::clicked, this, &LanPage::onLanSwitchClicked);
|
||||
|
@ -81,20 +73,25 @@ void LanPage::onSwithGsettingsChanged(const QString &key)
|
|||
{
|
||||
if (key == WIRED_SWITCH) {
|
||||
m_netSwitch->blockSignals(true);
|
||||
qDebug()<<"[LanPage] SwitchButton statue changed to ::"<<m_switchGsettings->get(WIRED_SWITCH).toBool();
|
||||
|
||||
qDebug()<<"[LanPage] SwitchButton statue changed to ::" <<m_switchGsettings->get(WIRED_SWITCH).toBool();
|
||||
|
||||
KyWiredConnectOperation wiredOperation;
|
||||
|
||||
bool isOn = m_switchGsettings->get(WIRED_SWITCH).toBool();
|
||||
if (isOn) {
|
||||
m_device->setDeviceAutoConnect();
|
||||
m_inactivatedLanListWidget->show();
|
||||
// m_deviceFrame->show();
|
||||
if (m_deviceMap.count() <= 1) {
|
||||
m_deviceFrame->hide();
|
||||
} else {
|
||||
m_deviceFrame->show();
|
||||
initDeviceCombox();
|
||||
for (int index = 0; index < m_devList.size(); ++index) {
|
||||
qDebug()<<"[LanPage] open wired device "<< m_devList.at(index);
|
||||
wiredOperation.openWiredNetworkWithDevice(m_devList.at(index));
|
||||
}
|
||||
|
||||
m_inactivatedLanListWidget->show();
|
||||
initDeviceCombox();
|
||||
} else {
|
||||
m_device->disconnectDevice();
|
||||
for (int index = 0; index < m_devList.size(); ++index) {
|
||||
qDebug()<<"[LanPage] close wired device "<< m_devList.at(index);
|
||||
wiredOperation.closeWiredNetworkWithDevice(m_devList.at(index));
|
||||
}
|
||||
m_inactivatedLanListWidget->hide();
|
||||
m_deviceFrame->hide();
|
||||
}
|
||||
|
@ -105,23 +102,11 @@ void LanPage::onSwithGsettingsChanged(const QString &key)
|
|||
|
||||
void LanPage::onLanSwitchClicked()
|
||||
{
|
||||
qDebug()<<"[LanPage] On lan switch button clicked! Status:"<<m_netSwitch->getSwitchStatus();
|
||||
qDebug()<<"[LanPage] On lan switch button clicked! Status:" <<m_netSwitch->getSwitchStatus();
|
||||
|
||||
if (m_netSwitch->getSwitchStatus()) {
|
||||
m_device->setDeviceAutoConnect();
|
||||
m_inactivatedLanListWidget->show();
|
||||
// m_deviceFrame->show();
|
||||
if (m_deviceMap.count() <= 1) {
|
||||
m_deviceFrame->hide();
|
||||
} else {
|
||||
m_deviceFrame->show();
|
||||
initDeviceCombox();
|
||||
}
|
||||
m_switchGsettings->set(WIRED_SWITCH,true);
|
||||
} else {
|
||||
qDebug()<<"[LanPage]Switch off! Disconnect Device!";
|
||||
m_device->disconnectDevice();
|
||||
m_inactivatedLanListWidget->hide();
|
||||
m_deviceFrame->hide();
|
||||
m_switchGsettings->set(WIRED_SWITCH,false);
|
||||
}
|
||||
}
|
||||
|
@ -223,75 +208,118 @@ void LanPage::connectionUpdateSlot(QString uuid)
|
|||
}
|
||||
}
|
||||
|
||||
void LanPage::initDevice()
|
||||
{
|
||||
QSettings * m_settings = new QSettings(CONFIG_FILE_PATH, QSettings::IniFormat);
|
||||
m_settings->beginGroup("DEFAULTCARD");
|
||||
QString key("wired");
|
||||
m_deviceName = m_settings->value(key, "").toString();
|
||||
if (m_deviceName.isEmpty()) {
|
||||
qDebug() << "initDevice but defalut wired card is null";
|
||||
if (!devList.isEmpty()) {
|
||||
m_deviceName = devList.at(0);
|
||||
m_settings->setValue(key, m_deviceName);
|
||||
}
|
||||
}
|
||||
updateDefaultDevice(m_deviceName);
|
||||
qDebug() << "[LanPage] initDevice defaultDevice = " << m_deviceName;
|
||||
//void LanPage::initDevice()
|
||||
//{
|
||||
// QSettings * m_settings = new QSettings(CONFIG_FILE_PATH, QSettings::IniFormat);
|
||||
// m_settings->beginGroup("DEFAULTCARD");
|
||||
// QString key("wired");
|
||||
// m_deviceName = m_settings->value(key, "").toString();
|
||||
// if (m_deviceName.isEmpty()) {
|
||||
// qDebug() << "initDevice but defalut wired card is null";
|
||||
// if (!m_devList.isEmpty()) {
|
||||
// m_deviceName = m_devList.at(0);
|
||||
// m_settings->setValue(key, m_deviceName);
|
||||
// }
|
||||
// }
|
||||
// updateDefaultDevice(m_deviceName);
|
||||
// qDebug() << "[LanPage] initDevice defaultDevice = " << m_deviceName;
|
||||
|
||||
m_settings->endGroup();
|
||||
m_settings->sync();
|
||||
delete m_settings;
|
||||
m_settings = nullptr;
|
||||
for (int i = 0; i < devList.size(); ++i) {
|
||||
qDebug() << "[LanPage] Device: " << devList.at(i);
|
||||
}
|
||||
}
|
||||
// m_settings->endGroup();
|
||||
// m_settings->sync();
|
||||
// delete m_settings;
|
||||
// m_settings = nullptr;
|
||||
// for (int i = 0; i < m_devList.size(); ++i) {
|
||||
// qDebug() << "[LanPage] Device: " << m_devList.at(i);
|
||||
// }
|
||||
//}
|
||||
|
||||
void LanPage::initDeviceCombox()
|
||||
{
|
||||
//TODO 获取设备列表,单设备时隐藏下拉框,多设备时添加到下拉框
|
||||
QMap<QString, bool> enableMap;
|
||||
getDeviceEnableState(0,enableMap);
|
||||
//TODO 获取设备列表,单设备时隐藏下拉框,多设备时添加到下拉框;m_devList记录插入的所有设备,deviceMap记录设备状态
|
||||
QMap<QString, bool> deviceMap;
|
||||
getDeviceEnableState(0,deviceMap);
|
||||
QStringList enableDevice;
|
||||
m_deviceComboBox->clear();
|
||||
m_deviceMap.clear();
|
||||
getWiredList(m_deviceMap);
|
||||
m_deviceFrame->show();
|
||||
QMap<QString, QVector<QStringList> >::iterator iter;
|
||||
for (iter = m_deviceMap.begin(); iter != m_deviceMap.constEnd(); ++iter) {
|
||||
if (enableMap.contains(iter.key())) {
|
||||
if (enableMap[iter.key()]) {
|
||||
m_deviceComboBox->addItem(iter.key());
|
||||
}
|
||||
} else {
|
||||
m_deviceComboBox->addItem(iter.key());
|
||||
saveDeviceEnableState(iter.key(), true);
|
||||
}
|
||||
m_devList.clear();
|
||||
enableDevice.clear();
|
||||
|
||||
if (!m_switchGsettings) {
|
||||
qDebug() << "[LanPage]:m_switchGsettings is null" << Q_FUNC_INFO << __LINE__;
|
||||
return;
|
||||
}
|
||||
|
||||
qDebug() << "[LanPage]current:" << m_deviceComboBox->currentText();
|
||||
bool isOn = m_switchGsettings->get(WIRED_SWITCH).toBool();
|
||||
if (!isOn) {
|
||||
m_deviceFrame->hide();
|
||||
} else {
|
||||
m_device->getNetworkDeviceList(NetworkManager::Device::Type::Ethernet, m_devList);
|
||||
for (int i=0; i<m_devList.size(); ++i) {
|
||||
if (deviceMap.contains(m_devList.at(i))) {
|
||||
if (deviceMap[m_devList.at(i)]) {
|
||||
enableDevice << m_devList.at(i);
|
||||
}
|
||||
} else {
|
||||
saveDeviceEnableState(m_devList.at(i), true);
|
||||
enableDevice << m_devList.at(i);
|
||||
}
|
||||
}
|
||||
qDebug() << "[LanPage]device num:" << enableDevice.count();
|
||||
if (enableDevice.count() == 0) {
|
||||
m_deviceFrame->show();
|
||||
m_deviceComboBox->hide();
|
||||
m_tipsLabel->show();
|
||||
m_activatedNetFrame->hide();
|
||||
m_inactivatedNetFrame->hide();
|
||||
m_activatedNetDivider->hide();
|
||||
m_inactivatedNetDivider->hide();
|
||||
return;
|
||||
} else {
|
||||
m_activatedNetFrame->show();
|
||||
m_inactivatedNetFrame->show();
|
||||
m_activatedNetDivider->show();
|
||||
m_inactivatedNetDivider->show();
|
||||
if (enableDevice.count() == 1) {
|
||||
m_deviceFrame->hide();
|
||||
m_deviceName = enableDevice.at(0);
|
||||
initList(m_deviceName);
|
||||
return;
|
||||
} else {
|
||||
m_deviceFrame->show();
|
||||
m_tipsLabel->hide();
|
||||
m_deviceComboBox->show();
|
||||
for (int j=0; j<enableDevice.count(); ++j) {
|
||||
m_deviceComboBox->addItem(enableDevice.at(j));
|
||||
}
|
||||
}
|
||||
}
|
||||
qDebug() << "[LanPage]Current device:" << m_deviceComboBox->currentText();
|
||||
m_deviceName = m_deviceComboBox->currentText();
|
||||
initList(m_deviceName);
|
||||
}
|
||||
}
|
||||
|
||||
void LanPage::onDeviceAdd(QString deviceName, NetworkManager::Device::Type deviceType)
|
||||
{
|
||||
qDebug() << "[LanPage] Begin add device:" << deviceName;
|
||||
if (deviceType != NetworkManager::Device::Type::Ethernet) {
|
||||
return;
|
||||
}
|
||||
devList << deviceName;
|
||||
if (getDefaultDevice().isEmpty())
|
||||
{
|
||||
|
||||
qDebug() << "[LanPage] Begin add device:" << deviceName;
|
||||
|
||||
m_devList << deviceName;
|
||||
|
||||
if (getDefaultDevice().isEmpty()) {
|
||||
updateDefaultDevice(deviceName);
|
||||
setDefaultDevice(WIRED, deviceName);
|
||||
}
|
||||
emit deviceStatusChanged();
|
||||
initDeviceCombox();
|
||||
}
|
||||
|
||||
void LanPage::onDeviceRemove(QString deviceName)
|
||||
{
|
||||
qDebug() << "[LanPage] deviceRemove:" << deviceName;
|
||||
if (getDefaultDevice() == deviceName)
|
||||
{
|
||||
if (getDefaultDevice() == deviceName) {
|
||||
QStringList list;
|
||||
QString newDefaultDevice = "";
|
||||
list.empty();
|
||||
|
@ -302,27 +330,13 @@ void LanPage::onDeviceRemove(QString deviceName)
|
|||
updateDefaultDevice(newDefaultDevice);
|
||||
setDefaultDevice(WIRED, newDefaultDevice);
|
||||
}
|
||||
if (devList.contains(deviceName)) {
|
||||
devList.removeOne(deviceName);
|
||||
}
|
||||
emit deviceStatusChanged();
|
||||
}
|
||||
|
||||
void LanPage::onDeviceChanged()
|
||||
{
|
||||
m_deviceMap.clear();
|
||||
getWiredList(m_deviceMap);
|
||||
qDebug() << "[LanPage]:Device Changed! initDeviceCombox!";
|
||||
if (m_netSwitch->getSwitchStatus()) {
|
||||
if (m_deviceMap.count() <= 1) {
|
||||
m_deviceFrame->hide();
|
||||
} else {
|
||||
m_deviceFrame->show();
|
||||
initDeviceCombox();
|
||||
}
|
||||
} else {
|
||||
m_deviceFrame->hide();
|
||||
if (m_devList.contains(deviceName)) {
|
||||
m_devList.removeOne(deviceName);
|
||||
}
|
||||
|
||||
emit deviceStatusChanged();
|
||||
initDeviceCombox();
|
||||
}
|
||||
|
||||
void LanPage::onDeviceNameUpdate(QString oldName, QString newName)
|
||||
|
@ -332,11 +346,13 @@ void LanPage::onDeviceNameUpdate(QString oldName, QString newName)
|
|||
setDefaultDevice(WIRED, newName);
|
||||
}
|
||||
|
||||
if (devList.contains(oldName)) {
|
||||
devList.removeOne(oldName);
|
||||
devList.append(newName);
|
||||
if (m_devList.contains(oldName)) {
|
||||
m_devList.removeOne(oldName);
|
||||
m_devList.append(newName);
|
||||
qDebug() << "[LanPage] emit deviceNameUpdate " << oldName << newName;
|
||||
|
||||
emit deviceNameChanged(oldName, newName);
|
||||
initDeviceCombox();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -388,6 +404,7 @@ void LanPage::addNewItem(KyConnectItem *itemData, QListWidget *listWidget)
|
|||
listWidget->addItem(m_listWidgetItem);
|
||||
|
||||
m_testLanItem = new LanListItem(itemData, m_deviceName);
|
||||
qDebug() << "[LanPage] addNewItem, connection: " << itemData->m_connectName << "deviceName: " << m_deviceName;
|
||||
listWidget->setItemWidget(m_listWidgetItem, m_testLanItem);
|
||||
}
|
||||
|
||||
|
@ -399,11 +416,12 @@ void LanPage::initList(QString m_deviceName) //程序拉起,初始化显
|
|||
m_deactiveMap.clear();
|
||||
m_activedList.clear();
|
||||
m_deactivedList.clear();
|
||||
m_activeResourse->getActiveConnectionList(m_deviceName,NetworkManager::ConnectionSettings::Wired,m_activedList); //激活列表的显示
|
||||
|
||||
m_activeResourse->getActiveConnectionList(m_deviceName,
|
||||
NetworkManager::ConnectionSettings::Wired, m_activedList); //激活列表的显示
|
||||
qDebug() << "[LanPage]init list! Active list:" << m_activedList.size() << "Deactive list:" << m_deactivedList.size();
|
||||
if (!m_activedList.isEmpty()) {
|
||||
for (int i = 0; i < m_activedList.size(); i++) {
|
||||
|
||||
KyConnectItem *activeItemData = m_activedList.at(i);
|
||||
addNewItem(activeItemData, m_activatedLanListWidget);
|
||||
|
||||
|
@ -460,7 +478,7 @@ void LanPage::updateLanlist(QString uuid, NetworkManager::ActiveConnection::Stat
|
|||
emit lanActiveConnectionStateChanged(devName, uuid, state);
|
||||
}
|
||||
|
||||
|
||||
qDebug() << "[LanPage] Update Device Name:" << m_deviceName;
|
||||
|
||||
if (state == NetworkManager::ActiveConnection::State::Deactivated) {
|
||||
qDebug()<<"Get a deactivate, begin to remove it from activeList";
|
||||
|
@ -518,7 +536,7 @@ void LanPage::updateLanlist(QString uuid, NetworkManager::ActiveConnection::Stat
|
|||
}
|
||||
}
|
||||
}
|
||||
else if (state == NetworkManager::ActiveConnection::State::Activating){
|
||||
else{
|
||||
|
||||
}
|
||||
|
||||
|
@ -528,7 +546,7 @@ void LanPage::updateLanlist(QString uuid, NetworkManager::ActiveConnection::Stat
|
|||
m_nullItem->setSizeHint(QSize(m_activatedLanListWidget->width(),ITEM_HEIGHT));
|
||||
m_activatedLanListWidget->addItem(m_nullItem);
|
||||
m_nullLanItem = new LanListItem();
|
||||
qDebug() << "[LanPage] ADD!";
|
||||
qDebug() << "[LanPage] Add nullItem!";
|
||||
m_activatedLanListWidget->setItemWidget(m_nullItem, m_nullLanItem);
|
||||
}
|
||||
}
|
||||
|
@ -563,10 +581,48 @@ void LanPage::getWiredList(QMap<QString, QVector<QStringList> > &map)
|
|||
return;
|
||||
}
|
||||
|
||||
void LanPage::onLanDataChange(QString uuid)
|
||||
{
|
||||
QString devName;
|
||||
NetworkManager::ConnectionSettings::ConnectionType type;
|
||||
|
||||
if(m_connectResourse->getInterfaceByUuid(devName, type, uuid)) {
|
||||
if (type != NetworkManager::ConnectionSettings::ConnectionType::Wired) {
|
||||
qDebug() << "[LanPage] Connection data changed but type is not Wired";
|
||||
return;
|
||||
}
|
||||
qDebug() << "[LanPage] Connection data changed!";
|
||||
// KyConnectItem *m_itemData = new KyConnectItem(this);
|
||||
// m_itemData = m_connectResourse->getConnectionItemByUuid(uuid, devName);
|
||||
// qDebug() << "[LanPage] DATA" << m_itemData->m_connectState;
|
||||
|
||||
// QMap<KyConnectItem *, QListWidgetItem *>::iterator iter;
|
||||
// for (iter = m_deactiveMap.begin(); iter != m_deactiveMap.constEnd(); ++iter) {
|
||||
// KyConnectItem *m_item = iter.key();
|
||||
// if (m_item->m_connectUuid == uuid) {
|
||||
// m_inactivatedLanListWidget->removeItemWidget(iter.value());
|
||||
// delete iter.value();
|
||||
// m_deactiveMap.erase(iter);
|
||||
// KyConnectItem *m_itemData = new KyConnectItem(this);
|
||||
// m_itemData = m_connectResourse->getConnectionItemByUuid(uuid, devName);
|
||||
// m_deactiveMap.insert(m_itemData, m_listWidgetItem);
|
||||
// addNewItem(m_itemData, m_inactivatedLanListWidget);
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
void LanPage::setWiredDeviceEnable(const QString& devName, bool enable)
|
||||
{
|
||||
saveDeviceEnableState(devName, enable);
|
||||
initDeviceCombox();
|
||||
KyWiredConnectOperation wiredOperation;
|
||||
if (enable) {
|
||||
wiredOperation.openWiredNetworkWithDevice(devName);
|
||||
} else {
|
||||
wiredOperation.closeWiredNetworkWithDevice(devName);
|
||||
}
|
||||
}
|
||||
|
||||
void LanPage::activateWired(const QString& devName, const QString& connUuid)
|
||||
|
|
|
@ -34,12 +34,10 @@ signals:
|
|||
void lanUpdate(QString devName, QStringList info);
|
||||
void lanActiveConnectionStateChanged(QString interface, QString uuid, int status);
|
||||
private:
|
||||
void initDevice();//初始化默认设备
|
||||
void initDeviceCombox();
|
||||
void initUI();
|
||||
void initList(QString m_deviceName);
|
||||
void addNewItem(KyConnectItem *itemData, QListWidget *listWidget);
|
||||
void addNew(LanListItem *item, QListWidget *listWidget);
|
||||
void initNetSwitch();
|
||||
|
||||
private:
|
||||
|
@ -59,7 +57,7 @@ private:
|
|||
QList<KyConnectItem *> m_activedList;
|
||||
QList<KyConnectItem *> m_deactivedList;
|
||||
|
||||
QMap<QString, QVector<QStringList> > m_deviceMap;
|
||||
// QMap<QString, QVector<QStringList> > m_deviceMap;
|
||||
|
||||
QMap<KyConnectItem *, QListWidgetItem *> m_deactiveMap;
|
||||
QMap<KyConnectItem *, QListWidgetItem *> m_activeMap;
|
||||
|
@ -68,7 +66,7 @@ private:
|
|||
// QMap<LanListItem *, QListWidgetItem *> m_activeMap;
|
||||
|
||||
QString m_deviceName;
|
||||
QStringList devList;
|
||||
QStringList m_devList;
|
||||
QGSettings * m_switchGsettings = nullptr;
|
||||
|
||||
private slots:
|
||||
|
@ -80,9 +78,9 @@ private slots:
|
|||
void onLanSwitchClicked();
|
||||
void onDeviceAdd(QString deviceName, NetworkManager::Device::Type deviceType);
|
||||
void onDeviceRemove(QString deviceName);
|
||||
void onDeviceChanged();
|
||||
void onDeviceNameUpdate(QString oldName, QString newName);
|
||||
void onDeviceComboxIndexChanged(int currentIndex);
|
||||
void onLanDataChange(QString uuid);
|
||||
};
|
||||
|
||||
#endif // LANPAGE_H
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "tabpage.h"
|
||||
#include <qsettings.h>
|
||||
#include <QDBusInterface>
|
||||
#include <QLabel>
|
||||
|
||||
TabPage::TabPage(QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
|
@ -34,16 +35,20 @@ void TabPage::initUI()
|
|||
|
||||
//临时增加的下拉框选择网卡区域
|
||||
m_deviceFrame = new QFrame(this);
|
||||
m_deviceFrame->setFixedHeight(TITLE_FRAME_HEIGHT);
|
||||
m_deviceLayout = new QHBoxLayout(m_deviceFrame);
|
||||
m_deviceLayout->setContentsMargins(DEVICE_LAYOUT_MARGINS);
|
||||
m_deviceFrame->setLayout(m_deviceLayout);
|
||||
m_deviceLabel = new QLabel(m_deviceFrame);
|
||||
m_deviceLabel->setText(tr("Current Device"));
|
||||
m_deviceComboBox = new QComboBox(m_deviceFrame);
|
||||
m_deviceComboBox->setFixedWidth(DEVICE_COMBOBOX_WIDTH);
|
||||
m_deviceLabel->setText(tr("Current Device"));
|
||||
m_tipsLabel = new QLabel(m_deviceFrame);
|
||||
m_tipsLabel->setText(tr("Devices Closed!"));
|
||||
m_deviceLayout->addWidget(m_deviceLabel);
|
||||
m_deviceLayout->addStretch();
|
||||
m_deviceLayout->addWidget(m_deviceComboBox);
|
||||
m_deviceLayout->addWidget(m_tipsLabel);
|
||||
connect(m_deviceComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &TabPage::onDeviceComboxIndexChanged);
|
||||
|
||||
m_activatedNetFrame = new QFrame(this);
|
||||
|
@ -57,7 +62,7 @@ void TabPage::initUI()
|
|||
m_activatedNetDivider = new Divider(this);
|
||||
|
||||
m_inactivatedNetFrame = new QFrame(this);
|
||||
m_inactivatedNetFrame->setMinimumHeight(INACTIVE_AREA_MIN_HEIGHT);
|
||||
// m_inactivatedNetFrame->setMinimumHeight(INACTIVE_AREA_MIN_HEIGHT);
|
||||
m_inactivatedNetLayout = new QVBoxLayout(m_inactivatedNetFrame);
|
||||
m_inactivatedNetLayout->setContentsMargins(NET_LAYOUT_MARGINS);
|
||||
m_inactivatedNetLayout->setSpacing(NET_LAYOUT_SPACING);
|
||||
|
@ -166,7 +171,7 @@ void getDeviceEnableState(int type, QMap<QString, bool> &map)
|
|||
{
|
||||
map.clear();
|
||||
if (!QFile::exists(CONFIG_FILE_PATH)) {
|
||||
return;
|
||||
qDebug() << "CONFIG_FILE_PATH not exist";
|
||||
}
|
||||
if (type != WIRED && type != WIRELESS) {
|
||||
qDebug() << "getDeviceEnableState but wrong type";
|
||||
|
@ -185,6 +190,9 @@ void getDeviceEnableState(int type, QMap<QString, bool> &map)
|
|||
kdr->getNetworkDeviceList(NetworkManager::Device::Type::Ethernet, wiredDevList);
|
||||
if (!wiredDevList.isEmpty()) {
|
||||
for (int i = 0; i < wiredDevList.size(); ++i) {
|
||||
if (!m_settings->contains(wiredDevList.at(i))) {
|
||||
saveDeviceEnableState(wiredDevList.at(i),true);
|
||||
}
|
||||
bool enable = m_settings->value(wiredDevList.at(i), true).toBool();
|
||||
map.insert(wiredDevList.at(i), enable);
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ signals:
|
|||
|
||||
protected:
|
||||
void initUI();
|
||||
virtual void initDevice() = 0;//初始化默认设备
|
||||
// virtual void initDevice() = 0;//初始化默认设备
|
||||
virtual void initDeviceCombox() = 0;//初始化设备选择下拉框
|
||||
QVBoxLayout * m_mainLayout = nullptr;
|
||||
QFrame * m_titleFrame = nullptr;
|
||||
|
@ -91,6 +91,7 @@ protected:
|
|||
QHBoxLayout * m_deviceLayout = nullptr;
|
||||
QLabel * m_deviceLabel = nullptr;
|
||||
QComboBox * m_deviceComboBox = nullptr;
|
||||
QLabel * m_tipsLabel = nullptr;
|
||||
|
||||
public slots:
|
||||
virtual void onDeviceComboxIndexChanged(int currentIndex) = 0;
|
||||
|
|
|
@ -149,14 +149,11 @@ void WlanPage::initDevice()
|
|||
QSettings * m_settings = new QSettings(CONFIG_FILE_PATH, QSettings::IniFormat);
|
||||
m_settings->beginGroup("DEFAULTCARD");
|
||||
QString key("wireless");
|
||||
QString deviceName = m_settings->value(key, "").toString();
|
||||
QString deviceName;
|
||||
m_netDeviceResource->getNetworkDeviceList(NetworkManager::Device::Type::Wifi, m_devList);
|
||||
if (deviceName.isEmpty()) {
|
||||
qDebug() << "initDevice but defalut wireless card is null";
|
||||
if (!m_devList.isEmpty()) {
|
||||
deviceName = m_devList.at(0);
|
||||
m_settings->setValue(key, deviceName);
|
||||
}
|
||||
if (!m_devList.isEmpty()) {
|
||||
deviceName = m_devList.at(0);
|
||||
m_settings->setValue(key, deviceName);
|
||||
}
|
||||
updateDefaultDevice(deviceName);
|
||||
qDebug() << "[WlanPage] initDevice defaultDevice = " << deviceName;
|
||||
|
@ -203,8 +200,8 @@ void WlanPage::getActiveWlan()
|
|||
int height = 0;
|
||||
while (iter != actMap.end()) {
|
||||
if (iter.key() == m_defaultDevice && !iter.value().isEmpty()) {
|
||||
QString ssid = iter.value().at(0);
|
||||
appendActiveWlan(ssid, height);
|
||||
QString uuid = iter.value().at(0);
|
||||
appendActiveWlan(uuid, height);
|
||||
break;
|
||||
}
|
||||
iter ++;
|
||||
|
@ -214,6 +211,7 @@ void WlanPage::getActiveWlan()
|
|||
} else {
|
||||
//未连接任何WiFi的情况
|
||||
m_activatedWlanSSid.clear();
|
||||
m_activatedWlanUuid.clear();
|
||||
WlanListItem *wlanItemWidget = new WlanListItem();
|
||||
qDebug() << "There is no activated wlan." << Q_FUNC_INFO << __LINE__ ;
|
||||
QListWidgetItem *wlanItem = new QListWidgetItem(m_activatedNetListWidget);
|
||||
|
@ -224,12 +222,15 @@ void WlanPage::getActiveWlan()
|
|||
}
|
||||
}
|
||||
|
||||
void WlanPage::appendActiveWlan(const QString &ssid, int &height)
|
||||
void WlanPage::appendActiveWlan(const QString &uuid, int &height)
|
||||
{
|
||||
m_activatedWlanSSid = ssid;
|
||||
qDebug() << "appendActiveWlan" << uuid;
|
||||
m_activatedWlanUuid = uuid;
|
||||
m_resource->getSsidByUuid(uuid, m_activatedWlanSSid, m_defaultDevice);
|
||||
|
||||
KyWirelessNetItem data;
|
||||
if (!m_resource->getWifiNetwork(m_defaultDevice, ssid, data)) {
|
||||
if (!m_resource->getWifiNetwork(m_defaultDevice, m_activatedWlanSSid, data)) {
|
||||
qWarning() << "Get activated wlan failed! ssid = " << m_activatedWlanSSid <<"; device = " << m_defaultDevice << "; uuid = " << m_activatedWlanUuid;
|
||||
return;
|
||||
}
|
||||
KyWirelessNetItem *item_data = new KyWirelessNetItem(data);
|
||||
|
@ -257,8 +258,7 @@ void WlanPage::getAllWlan()
|
|||
m_itemsMap.clear();
|
||||
QList<KyWirelessNetItem> wlanList;
|
||||
// if (!m_resource->getAllDeviceWifiNetwork(map))
|
||||
if (!m_resource->getDeviceWifiNetwork(m_defaultDevice, wlanList)) //ZJP_TODO 获取默认网卡并传入
|
||||
{
|
||||
if (!m_resource->getDeviceWifiNetwork(m_defaultDevice, wlanList)) { //ZJP_TODO 获取默认网卡并传入
|
||||
return;
|
||||
}
|
||||
int height = 0;
|
||||
|
@ -302,6 +302,7 @@ void WlanPage::onWlanAdded(QString interface, KyWirelessNetItem &item)
|
|||
KyWirelessNetItem *data = new KyWirelessNetItem(item);
|
||||
WlanListItem *wlanItemWidget = new WlanListItem(m_resource, data, m_defaultDevice);
|
||||
connect(wlanItemWidget, &WlanListItem::itemHeightChanged, this, &WlanPage::onItemHeightChanged);
|
||||
connect(wlanItemWidget, &WlanListItem::connectButtonClicked, this, &WlanPage::onConnectButtonClicked);
|
||||
QListWidgetItem *wlanItem = new QListWidgetItem(m_inactivatedNetListWidget);
|
||||
wlanItem->setSizeHint(QSize(m_inactivatedNetListWidget->width(), wlanItemWidget->height()));
|
||||
m_inactivatedNetListWidget->setItemWidget(wlanItem, wlanItemWidget);
|
||||
|
@ -467,14 +468,27 @@ void WlanPage::onActivatedWlanChanged(QString uuid, NetworkManager::ActiveConnec
|
|||
//onWlanRemoved(m_wlanDevice, ssid);
|
||||
m_activatedNetListWidget->clear();
|
||||
int height = 0;
|
||||
appendActiveWlan(ssid, height);
|
||||
appendActiveWlan(uuid, height);
|
||||
onWlanRemoved(m_defaultDevice, ssid);
|
||||
// this->showDesktopNotify(tr("Connect WLAN succeed"));
|
||||
} else if (state == NetworkManager::ActiveConnection::State::Deactivated) {
|
||||
onWlanUpdated();
|
||||
} else if (state == NetworkManager::ActiveConnection::State::Deactivated && (uuid.isEmpty() || (!uuid.isEmpty() && uuid == m_activatedWlanUuid))) {
|
||||
QString oldActWlanSsid = m_activatedWlanSSid;
|
||||
getActiveWlan();
|
||||
QString newActWlanSsid = m_activatedWlanSSid;
|
||||
if (oldActWlanSsid != newActWlanSsid) {
|
||||
if (!oldActWlanSsid.isEmpty()) {
|
||||
KyWirelessNetItem item;
|
||||
if(m_resource->getWifiNetwork(m_defaultDevice, oldActWlanSsid, item)) {
|
||||
onWlanAdded(m_defaultDevice, item);
|
||||
}
|
||||
}
|
||||
if (!newActWlanSsid.isEmpty()) {
|
||||
onWlanRemoved(m_defaultDevice, newActWlanSsid);
|
||||
}
|
||||
}
|
||||
// this->showDesktopNotify(tr("Disconnect WLAN succeed"));
|
||||
} else {
|
||||
onWlanUpdated();
|
||||
qDebug() << "Unexpected wlan state, will do nothing." << Q_FUNC_INFO << __LINE__;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -63,7 +63,7 @@ private:
|
|||
void initDeviceCombox();
|
||||
|
||||
void getActiveWlan();
|
||||
void appendActiveWlan(const QString &ssid, int &height);
|
||||
void appendActiveWlan(const QString &uuid, int &height);
|
||||
void getAllWlan();
|
||||
QMap<QString, QListWidgetItem*> m_itemsMap;
|
||||
QListWidgetItem *m_expandedItem = nullptr;
|
||||
|
@ -75,6 +75,7 @@ private:
|
|||
QLabel * m_hiddenWlanLabel = nullptr;
|
||||
|
||||
QString m_activatedWlanSSid;
|
||||
QString m_activatedWlanUuid;
|
||||
QStringList m_devList;
|
||||
|
||||
KyWirelessNetResource *m_resource = nullptr;
|
||||
|
|
|
@ -33,6 +33,11 @@ RadioItemButton::RadioItemButton(QWidget *parent) : QPushButton(parent)
|
|||
connect(qApp, &QApplication::paletteChanged, this, &RadioItemButton::onPaletteChanged);
|
||||
}
|
||||
|
||||
RadioItemButton::~RadioItemButton()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void RadioItemButton::startLoading()
|
||||
{
|
||||
emit this->requestStartLoading();
|
||||
|
@ -72,50 +77,33 @@ void RadioItemButton::setActive(const bool &isActive)
|
|||
}
|
||||
void RadioItemButton::onLoadingStarted()
|
||||
{
|
||||
if (!m_loadingTimer) {
|
||||
m_loadingTimer = new QTimer();
|
||||
connect(m_loadingTimer, &QTimer::timeout, this, &RadioItemButton::onLoadingTimerTimeout);
|
||||
#define ANIMATION_SPEED 0.5*1000
|
||||
#define START_ROTATION 0
|
||||
#define END_ROTATION 360
|
||||
#define ANIMATION_LOOP -1 //无限旋转
|
||||
if (!m_iconLabel) {
|
||||
qWarning() << "Start loading failed, iconLabel is null pointer!" << Q_FUNC_INFO << __LINE__;
|
||||
}
|
||||
if (!m_timeoutTimer) {
|
||||
m_timeoutTimer = new QTimer();
|
||||
connect(m_timeoutTimer, &QTimer::timeout, this, &RadioItemButton::onLoadingStopped);
|
||||
if (!m_animation) {
|
||||
m_animation = new QVariantAnimation(m_iconLabel);
|
||||
}
|
||||
if (m_loadingTimer->isActive()) {
|
||||
return;
|
||||
}
|
||||
m_loadingTimer->start(FLASH_SPEED);
|
||||
m_timeoutTimer->stop();
|
||||
m_timeoutTimer->start(TIMEOUT_TIMER);
|
||||
m_animation->setDuration(ANIMATION_SPEED);
|
||||
m_animation->setStartValue(START_ROTATION);
|
||||
m_animation->setEndValue(END_ROTATION);
|
||||
m_animation->setLoopCount(ANIMATION_LOOP);
|
||||
connect(m_animation, &QVariantAnimation::valueChanged, this, &RadioItemButton::onAnimationValueChanged);
|
||||
m_animation->start();
|
||||
}
|
||||
|
||||
void RadioItemButton::onLoadingStopped()
|
||||
{
|
||||
//ZJP_TODO 停止播放转圈动画
|
||||
if (this->m_loadingTimer) {
|
||||
this->m_loadingTimer->stop();
|
||||
if (!m_animation) {
|
||||
qWarning() << "Stop loading failed, m_animation is null pointer!" << Q_FUNC_INFO << __LINE__;
|
||||
return;
|
||||
} else {
|
||||
qWarning() << "Stop loading failed, m_loadingTimer is nullptr." << Q_FUNC_INFO << __LINE__;
|
||||
m_animation->stop();
|
||||
}
|
||||
if (this->m_timeoutTimer) {
|
||||
this->m_timeoutTimer->stop();
|
||||
} else {
|
||||
qWarning() << "Stop timeout_timer failed, m_timeoutTimer is nullptr." << Q_FUNC_INFO << __LINE__;
|
||||
}
|
||||
}
|
||||
|
||||
void RadioItemButton::onLoadingTimerTimeout()
|
||||
{
|
||||
QString qpmQss = ":/res/s/conning-a/";
|
||||
qpmQss.append(QString::number(this->currentPage));
|
||||
qpmQss.append(".png");
|
||||
qDebug()<<qpmQss;
|
||||
m_iconLabel->setPixmap(QPixmap(qpmQss));
|
||||
|
||||
this->currentPage --;
|
||||
|
||||
if (this->currentPage < 1) {
|
||||
this->currentPage = 8; //循环播放
|
||||
}
|
||||
}
|
||||
|
||||
void RadioItemButton::onPaletteChanged()
|
||||
|
@ -129,6 +117,16 @@ void RadioItemButton::onPaletteChanged()
|
|||
}
|
||||
}
|
||||
|
||||
void RadioItemButton::onAnimationValueChanged(const QVariant& value)
|
||||
{
|
||||
if (!m_iconLabel) {
|
||||
return;
|
||||
}
|
||||
QTransform t;
|
||||
t.rotate(value.toReal());
|
||||
m_iconLabel->setPixmap(QIcon(":/res/s/conning-a/1.png").pixmap(ICON_SIZE).transformed(t));
|
||||
}
|
||||
|
||||
void RadioItemButton::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
QPalette pal = this->palette();
|
||||
|
|
|
@ -3,16 +3,18 @@
|
|||
#include <QPushButton>
|
||||
#include <QIcon>
|
||||
#include <QLabel>
|
||||
#include<QTimer>
|
||||
#include <QTimer>
|
||||
#include <QVariantAnimation>
|
||||
|
||||
#define MIDDLE_COLOR 178
|
||||
|
||||
class RadioItemButton : public QPushButton
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
RadioItemButton(QWidget * parent = nullptr);
|
||||
~RadioItemButton() = default;
|
||||
~RadioItemButton();
|
||||
void startLoading();
|
||||
void stopLoading();
|
||||
void setButtonIcon(const QIcon &icon);
|
||||
|
@ -37,18 +39,16 @@ protected:
|
|||
private:
|
||||
bool m_isActivated = false;
|
||||
QLabel * m_iconLabel = nullptr;
|
||||
QTimer * m_loadingTimer = nullptr;
|
||||
QTimer * m_timeoutTimer = nullptr;
|
||||
QColor m_backgroundColor;
|
||||
QVariantAnimation * m_animation = nullptr;
|
||||
|
||||
int currentPage = 8;
|
||||
QPixmap m_pixmap;
|
||||
|
||||
private slots:
|
||||
void onLoadingStarted();
|
||||
void onLoadingStopped();
|
||||
void onLoadingTimerTimeout();
|
||||
void onPaletteChanged();
|
||||
void onAnimationValueChanged(const QVariant& value);
|
||||
};
|
||||
|
||||
#endif // NETBUTTON_H
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
<クdハ<>箆!ソ`。スン
|
Binary file not shown.
Loading…
Reference in New Issue