Merge branch '0922' into 'dbus-interface'

0922

See merge request kylin-desktop/kylin-nm!270
This commit is contained in:
ren peijia 2021-09-23 06:28:18 +00:00
commit 0b22f57104
4 changed files with 123 additions and 113 deletions

View File

@ -88,13 +88,13 @@ void LanListItem::onInfoButtonClicked()
void LanListItem::onLanStatusChange(QString uuid, NetworkManager::ActiveConnection::State state, NetworkManager::ActiveConnection::Reason reason)
{
qDebug() <<"[LanListItem]:Connection State Change to:" << state;
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;
qDebug() << "[LanListItem]Activating!Loading!" << state;
m_netButton->startLoading();
} else {
qDebug() << "[LanListItem]:Stop!" << state;
qDebug() << "[LanListItem]Stop!" << state;
m_netButton->stopLoading();
if (state == NetworkManager::ActiveConnection::State::Activated) {
setIcon(true);

View File

@ -15,7 +15,6 @@
#define ITEM_HEIGHT 48
const QString WIRED_SWITCH = "wiredswitch";
//const QByteArray GSETTINGS_SCHEMA = "org.ukui.kylin-nm.switch";
LanPage::LanPage(QWidget *parent) : TabPage(parent)
{
@ -43,7 +42,7 @@ LanPage::LanPage(QWidget *parent) : TabPage(parent)
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_connectResourse, &KyConnectResourse::connectionUpdate, this, &LanPage::onLanDataChange);
connect(m_device, &KyNetworkDeviceResourse::deviceAdd, this, &LanPage::onDeviceAdd);
connect(m_device, &KyNetworkDeviceResourse::deviceRemove, this, &LanPage::onDeviceRemove);
@ -83,17 +82,13 @@ void LanPage::onSwithGsettingsChanged(const QString &key)
qDebug()<<"[LanPage] open wired device "<< m_devList.at(index);
wiredOperation.openWiredNetworkWithDevice(m_devList.at(index));
}
m_inactivatedLanListWidget->show();
initDeviceCombox();
} else {
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();
}
initDeviceCombox();
m_netSwitch->setSwitchStatus(isOn);
m_netSwitch->blockSignals(false);
}
@ -171,66 +166,6 @@ void LanPage::addConnectionSlot(QString uuid) //新增一个有线
qDebug()<<"[LanPage] GetConnectionItemByUuid is empty when add a new!";
}
}
void LanPage::connectionUpdateSlot(QString uuid)
{
//for dbus
QStringList devNameList;
if (m_activeResourse->isActiveConnection(uuid, devNameList)) {
for (int i = 0; i < devNameList.size(); ++i) {
KyConnectItem *item = nullptr;
item = m_activeResourse->getActiveConnectionByUuid(uuid, devNameList.at(i));
if (nullptr != item) {
if (item->m_itemType != NetworkManager::ConnectionSettings::ConnectionType::Wired) {
return;
}
QStringList info;
info << item->m_connectName << uuid << item->m_connectPath;
emit lanUpdate(devNameList.at(i), info);
}
}
} else {
QString devName;
NetworkManager::ConnectionSettings::ConnectionType type;
if (!m_connectResourse->getInterfaceByUuid(devName, type, uuid)) {
return;
}
if (type != NetworkManager::ConnectionSettings::ConnectionType::Wired) {
return;
}
KyConnectItem *item = nullptr;
item = m_connectResourse->getConnectionItemByUuid(uuid, devName);
if (nullptr != item) {
QStringList info;
info << item->m_connectName << uuid << item->m_connectPath;
emit lanUpdate(devName, info);
}
}
}
//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 < m_devList.size(); ++i) {
// qDebug() << "[LanPage] Device: " << m_devList.at(i);
// }
//}
void LanPage::initDeviceCombox()
{
@ -250,6 +185,10 @@ void LanPage::initDeviceCombox()
bool isOn = m_switchGsettings->get(WIRED_SWITCH).toBool();
if (!isOn) {
m_deviceFrame->hide();
m_activatedNetFrame->hide();
m_inactivatedNetFrame->hide();
m_activatedNetDivider->hide();
m_inactivatedNetDivider->hide();
} else {
m_device->getNetworkDeviceList(NetworkManager::Device::Type::Ethernet, m_devList);
for (int i=0; i<m_devList.size(); ++i) {
@ -272,25 +211,25 @@ void LanPage::initDeviceCombox()
m_activatedNetDivider->hide();
m_inactivatedNetDivider->hide();
return;
}
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_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));
}
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);
@ -359,7 +298,7 @@ void LanPage::onDeviceComboxIndexChanged(int currentIndex)
{
//TODO 设备变更时更新设备和列表
m_deviceName = m_deviceComboBox->currentText();
qDebug() << "[LanPage]Device Changed:" << m_deviceName;
qDebug() << "[LanPage]Current Device Changed to:" << m_deviceName;
initList(m_deviceName);
}
@ -469,7 +408,7 @@ void LanPage::updateLanlist(QString uuid, NetworkManager::ActiveConnection::Stat
if (nullptr != item) {
QStringList info;
info << item->m_connectName << uuid << item->m_connectPath;
emit lanActiveConnectionStateChanged(devNameList.at(i), uuid, state);
emit lanActiveConnectionStateChanged(devNameList.at(i), uuid, state);
}
}
} else {
@ -580,35 +519,104 @@ void LanPage::getWiredList(QMap<QString, QVector<QStringList> > &map)
return;
}
void LanPage::onLanDataChange(QString uuid)
void LanPage::connectionUpdateSlot(QString uuid)
{
QString devName;
NetworkManager::ConnectionSettings::ConnectionType type;
QStringList devNameList;
bool isCurrentDevice = false;
KyConnectItem *item = nullptr;
if(m_connectResourse->getInterfaceByUuid(devName, type, uuid)) {
if (type != NetworkManager::ConnectionSettings::ConnectionType::Wired) {
qDebug() << "[LanPage] Connection data changed but type is not Wired";
qDebug() << "[LanPage]:Connection Changed !" << Q_FUNC_INFO << __LINE__;
if (m_activeResourse->isActiveConnection(uuid, devNameList)) { //从activeResourse里找
for (int i = 0; i < devNameList.size(); ++i) {
item = m_activeResourse->getActiveConnectionByUuid(uuid, devNameList.at(i));
if (nullptr != item) {
if (item->m_itemType != NetworkManager::ConnectionSettings::ConnectionType::Wired) {
return;
}
if (devNameList.at(i) == m_deviceName) {
qDebug() << "[LanPage]:Connection's device:" << devNameList.at(i) << Q_FUNC_INFO << __LINE__;
isCurrentDevice = true;
}
//for dbus
QStringList info;
info << item->m_connectName << uuid << item->m_connectPath;
emit lanUpdate(devNameList.at(i), info);
}
}
} else {
QString devName;
NetworkManager::ConnectionSettings::ConnectionType type;
if (!m_connectResourse->getInterfaceByUuid(devName, type, uuid)) { //从connectResourse里找
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;
if (type != NetworkManager::ConnectionSettings::ConnectionType::Wired) {
return;
}
item = m_connectResourse->getConnectionItemByUuid(uuid, devName);
if (nullptr != item) {
if (devName == m_deviceName) {
qDebug() << "[LanPage]:Connection's device:" << devName << Q_FUNC_INFO << __LINE__;
isCurrentDevice = true;
}
//for dbus
QStringList info;
info << item->m_connectName << uuid << item->m_connectPath;
emit lanUpdate(devName, info);
}
}
qDebug() << "[LanPage]:Connection belong to current device:" << isCurrentDevice;
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) {
if (!isCurrentDevice) { //当前未激活连接的设备改变
m_inactivatedLanListWidget->removeItemWidget(iter.value());
delete iter.value();
m_deactiveMap.erase(iter);
qDebug() << "[LanPage]:Deactive Connection's device change, remove it" << Q_FUNC_INFO << __LINE__;
return;
} else {
if (m_item->m_connectName != item->m_connectName || m_item->m_connectPath != item->m_connectPath) { //当前未激活连接的其他数据改变(除了激活状态外)
qDebug() << "[LanPage]:Deactive Connection's name or path changed." << Q_FUNC_INFO << __LINE__;
qDebug() << "new:" << item->m_connectUuid << item->m_connectName << item->m_connectPath << item->m_connectState << item->m_ifaceName;
qDebug() << "old:" << m_item->m_connectUuid << m_item->m_connectName << m_item->m_connectPath << m_item->m_connectState << m_item->m_ifaceName;
m_inactivatedLanListWidget->removeItemWidget(iter.value());
delete iter.value();
m_deactiveMap.erase(iter);
// 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;
// }
// }
addNewItem(item, m_inactivatedLanListWidget);
m_deactiveMap.insert(item, m_listWidgetItem);
break;
}
}
}
}
QMap<KyConnectItem *, QListWidgetItem *>::iterator iters;
for (iters = m_activeMap.begin(); iters != m_activeMap.constEnd(); ++iters) {
KyConnectItem *m_item = iters.key();
if (m_item->m_connectUuid == uuid) {
if (!isCurrentDevice) { //当前激活连接的设备改变
m_activatedLanListWidget->removeItemWidget(iters.value());
delete iters.value();
m_activeMap.erase(iters);
qDebug() << "[LanPage]:Active Connection's device change, remove it" << Q_FUNC_INFO << __LINE__;
return;
} else {
if (m_item->m_connectName != item->m_connectName || m_item->m_connectPath != item->m_connectPath) { //当前激活连接的其他数据改变(除了激活状态外)
qDebug() << "[LanPage]:Active Connection's name or path changed." << Q_FUNC_INFO << __LINE__;
qDebug() << "new:" << item->m_connectUuid << item->m_connectName << item->m_connectPath << item->m_connectState << item->m_ifaceName;
qDebug() << "old:" << m_item->m_connectUuid << m_item->m_connectName << m_item->m_connectPath << m_item->m_connectState << m_item->m_ifaceName;
m_activatedLanListWidget->removeItemWidget(iters.value());
delete iters.value();
m_activeMap.erase(iters);
addNewItem(item, m_activatedLanListWidget);
m_activeMap.insert(item, m_listWidgetItem);
break;
}
}
}
}
}

View File

@ -80,7 +80,7 @@ private slots:
void onDeviceRemove(QString deviceName);
void onDeviceNameUpdate(QString oldName, QString newName);
void onDeviceComboxIndexChanged(int currentIndex);
void onLanDataChange(QString uuid);
// void onLanDataChange(QString uuid);
};
#endif // LANPAGE_H

View File

@ -77,6 +77,7 @@ void TabPage::initUI()
m_inactivatedNetDivider = new Divider(this);
m_settingsFrame = new QFrame(this);
m_settingsFrame->setFixedHeight(TITLE_FRAME_HEIGHT);
m_settingsLayout = new QHBoxLayout(m_settingsFrame);
m_settingsLayout->setContentsMargins(SETTINGS_LAYOUT_MARGINS);
m_settingsLabel = new QLabel(m_settingsFrame);
@ -92,6 +93,7 @@ void TabPage::initUI()
m_mainLayout->addWidget(m_activatedNetDivider);
m_mainLayout->addWidget(m_inactivatedNetFrame);
m_mainLayout->addWidget(m_inactivatedNetDivider);
m_mainLayout->addStretch();
m_mainLayout->addWidget(m_settingsFrame);
}