feature:function of wired switch is finished.
This commit is contained in:
parent
d30ce7b3dd
commit
ed82533377
|
@ -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;
|
||||
|
||||
|
@ -173,8 +173,6 @@ void KyNetworkDeviceResourse::DeviceSpeed(QString deviceName, KyConnectItem *wir
|
|||
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void KyNetworkDeviceResourse::disconnectDevice()
|
||||
{
|
||||
|
@ -248,6 +246,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->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;
|
||||
}
|
||||
|
||||
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
|
||||
|
|
|
@ -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([=]() {
|
||||
|
|
|
@ -22,22 +22,26 @@ LanPage::LanPage(QWidget *parent) : TabPage(parent)
|
|||
m_activeResourse = new KyActiveConnectResourse(this);
|
||||
m_connectResourse = new KyConnectResourse(this);
|
||||
m_device = new KyNetworkDeviceResourse(this);
|
||||
m_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!";
|
||||
}
|
||||
|
||||
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_device, &KyNetworkDeviceResourse::deviceAdd, this, &LanPage::onDeviceAdd);
|
||||
connect(m_device, &KyNetworkDeviceResourse::deviceRemove, this, &LanPage::onDeviceRemove);
|
||||
connect(m_device, &KyNetworkDeviceResourse::deviceNameUpdate, this, &LanPage::onDeviceNameUpdate);
|
||||
|
@ -62,17 +66,30 @@ 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();
|
||||
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();
|
||||
}
|
||||
|
||||
m_netSwitch->setSwitchStatus(isOn);
|
||||
m_netSwitch->blockSignals(false);
|
||||
}
|
||||
|
@ -80,15 +97,24 @@ 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();
|
||||
|
||||
KyWiredConnectOperation wiredOperation;
|
||||
|
||||
if (m_netSwitch->getSwitchStatus()) {
|
||||
m_device->setDeviceAutoConnect();
|
||||
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();
|
||||
m_switchGsettings->set(WIRED_SWITCH,true);
|
||||
initDeviceCombox();
|
||||
} else {
|
||||
qDebug()<<"[LanPage]Switch off! Disconnect Device!";
|
||||
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();
|
||||
m_switchGsettings->set(WIRED_SWITCH,false);
|
||||
|
@ -183,6 +209,7 @@ void LanPage::initDeviceCombox()
|
|||
m_deviceComboBox->addItem(m_devList.at(i));
|
||||
}
|
||||
}
|
||||
|
||||
qDebug() << "[LanPage]Current device:" << m_deviceComboBox->currentText();
|
||||
m_deviceName = m_deviceComboBox->currentText();
|
||||
initList(m_deviceName);
|
||||
|
@ -191,13 +218,15 @@ void LanPage::initDeviceCombox()
|
|||
|
||||
void LanPage::onDeviceAdd(QString deviceName, NetworkManager::Device::Type deviceType)
|
||||
{
|
||||
qDebug() << "[LanPage] Begin add device:" << deviceName;
|
||||
if (deviceType != NetworkManager::Device::Type::Ethernet) {
|
||||
return;
|
||||
}
|
||||
|
||||
qDebug() << "[LanPage] Begin add device:" << deviceName;
|
||||
|
||||
m_devList << deviceName;
|
||||
if (getDefaultDevice().isEmpty())
|
||||
{
|
||||
|
||||
if (getDefaultDevice().isEmpty()) {
|
||||
updateDefaultDevice(deviceName);
|
||||
setDefaultDevice(WIRED, deviceName);
|
||||
}
|
||||
|
@ -208,8 +237,7 @@ void LanPage::onDeviceAdd(QString deviceName, NetworkManager::Device::Type devic
|
|||
void LanPage::onDeviceRemove(QString deviceName)
|
||||
{
|
||||
qDebug() << "[LanPage] deviceRemove:" << deviceName;
|
||||
if (getDefaultDevice() == deviceName)
|
||||
{
|
||||
if (getDefaultDevice() == deviceName) {
|
||||
QStringList list;
|
||||
QString newDefaultDevice = "";
|
||||
list.empty();
|
||||
|
@ -220,9 +248,11 @@ void LanPage::onDeviceRemove(QString deviceName)
|
|||
updateDefaultDevice(newDefaultDevice);
|
||||
setDefaultDevice(WIRED, newDefaultDevice);
|
||||
}
|
||||
|
||||
if (m_devList.contains(deviceName)) {
|
||||
m_devList.removeOne(deviceName);
|
||||
}
|
||||
|
||||
emit deviceStatusChanged();
|
||||
initDeviceCombox();
|
||||
}
|
||||
|
@ -303,11 +333,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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue