增加网线插拔
This commit is contained in:
parent
6306683d00
commit
9a49f2bd3a
|
@ -137,7 +137,7 @@ bool KyNetworkDeviceResourse::wiredDeviceCarriered(QString deviceName)
|
||||||
NetworkManager::Device::Ptr connectDevice =
|
NetworkManager::Device::Ptr connectDevice =
|
||||||
m_networkResourceInstance->findDeviceInterface(deviceName);
|
m_networkResourceInstance->findDeviceInterface(deviceName);
|
||||||
if (connectDevice->isValid()
|
if (connectDevice->isValid()
|
||||||
&& NetworkManager::Ethernet == connectDevice->type()) {
|
&& NetworkManager::Device::Type::Ethernet == connectDevice->type()) {
|
||||||
NetworkManager::WiredDevice *wiredDevicePtr =
|
NetworkManager::WiredDevice *wiredDevicePtr =
|
||||||
qobject_cast<NetworkManager::WiredDevice *>(connectDevice.data());
|
qobject_cast<NetworkManager::WiredDevice *>(connectDevice.data());
|
||||||
return wiredDevicePtr->carrier();
|
return wiredDevicePtr->carrier();
|
||||||
|
|
|
@ -10,6 +10,7 @@ LanListItem::LanListItem(KyConnectItem *data, QString deviceName, QWidget *paren
|
||||||
m_connectOperation = new KyWiredConnectOperation(this);
|
m_connectOperation = new KyWiredConnectOperation(this);
|
||||||
m_activeConnectResource = new KyActiveConnectResourse(this);
|
m_activeConnectResource = new KyActiveConnectResourse(this);
|
||||||
m_connectResource = new KyConnectResourse(this);
|
m_connectResource = new KyConnectResourse(this);
|
||||||
|
m_deviceResource = new KyNetworkDeviceResourse(this);
|
||||||
m_data = data;
|
m_data = data;
|
||||||
m_nameLabel->setText(m_data->m_connectName);
|
m_nameLabel->setText(m_data->m_connectName);
|
||||||
|
|
||||||
|
@ -55,15 +56,19 @@ void LanListItem::onNetButtonClicked()
|
||||||
}
|
}
|
||||||
if (!m_isActive) {
|
if (!m_isActive) {
|
||||||
//未连接,点击后连
|
//未连接,点击后连
|
||||||
m_connectOperation->activateWiredConnection(m_data->m_connectUuid, deviceName);
|
if (m_deviceResource->wiredDeviceCarriered(deviceName)) {
|
||||||
qDebug() << m_data->m_connectName << "Connect after user clicked!" << deviceName;
|
m_connectOperation->activateWiredConnection(m_data->m_connectUuid, deviceName);
|
||||||
// m_data->m_connectState = NetworkManager::ActiveConnection::State::Activating;
|
qDebug() << m_data->m_connectName << "Connect after user clicked!" << deviceName;
|
||||||
m_isActive = true;
|
m_isActive = true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
qDebug() << "[LanListItem] Wired Device not carried";
|
||||||
|
m_isActive = false;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
//连接,点击后断开
|
//连接,点击后断开
|
||||||
m_connectOperation->deactivateWiredConnection(m_data->m_connectName, m_data->m_connectUuid);
|
m_connectOperation->deactivateWiredConnection(m_data->m_connectName, m_data->m_connectUuid);
|
||||||
qDebug() << m_data->m_connectName << "Disconnect after user clicked!" << deviceName;
|
qDebug() << m_data->m_connectName << "Disconnect after user clicked!" << deviceName;
|
||||||
// m_data->m_connectState = NetworkManager::ActiveConnection::State::Deactivated;
|
|
||||||
m_isActive = false;
|
m_isActive = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ public:
|
||||||
KyWiredConnectOperation *m_connectOperation = nullptr;
|
KyWiredConnectOperation *m_connectOperation = nullptr;
|
||||||
KyActiveConnectResourse *m_activeConnectResource = nullptr;
|
KyActiveConnectResourse *m_activeConnectResource = nullptr;
|
||||||
KyConnectResourse *m_connectResource = nullptr;
|
KyConnectResourse *m_connectResource = nullptr;
|
||||||
|
KyNetworkDeviceResourse *m_deviceResource = nullptr;
|
||||||
|
|
||||||
QString deviceName = "";
|
QString deviceName = "";
|
||||||
|
|
||||||
|
|
|
@ -22,10 +22,11 @@ LanPage::LanPage(QWidget *parent) : TabPage(parent)
|
||||||
m_activeResourse = new KyActiveConnectResourse(this);
|
m_activeResourse = new KyActiveConnectResourse(this);
|
||||||
m_connectResourse = new KyConnectResourse(this);
|
m_connectResourse = new KyConnectResourse(this);
|
||||||
m_device = new KyNetworkDeviceResourse(this);
|
m_device = new KyNetworkDeviceResourse(this);
|
||||||
m_nullLanItem = new LanListItem();
|
// m_nullLanItem = new LanListItem();
|
||||||
|
|
||||||
m_devList.empty();
|
m_devList.empty();
|
||||||
|
|
||||||
|
|
||||||
initUI();
|
initUI();
|
||||||
|
|
||||||
if (QGSettings::isSchemaInstalled(GSETTINGS_SCHEMA)) {
|
if (QGSettings::isSchemaInstalled(GSETTINGS_SCHEMA)) {
|
||||||
|
@ -35,7 +36,7 @@ LanPage::LanPage(QWidget *parent) : TabPage(parent)
|
||||||
qDebug()<<"[LanPage] org.ukui.kylin-nm.switch is not installed!";
|
qDebug()<<"[LanPage] org.ukui.kylin-nm.switch is not installed!";
|
||||||
}
|
}
|
||||||
|
|
||||||
initDeviceCombox();
|
// initDeviceCombox();
|
||||||
initList(m_deviceName);
|
initList(m_deviceName);
|
||||||
|
|
||||||
connect(m_activeResourse, &KyActiveConnectResourse::stateChangeReason, this, &LanPage::updateLanlist);
|
connect(m_activeResourse, &KyActiveConnectResourse::stateChangeReason, this, &LanPage::updateLanlist);
|
||||||
|
@ -170,7 +171,7 @@ void LanPage::initDeviceCombox()
|
||||||
//TODO 获取设备列表,单设备时隐藏下拉框,多设备时添加到下拉框;m_devList记录插入的所有设备,deviceMap记录设备状态
|
//TODO 获取设备列表,单设备时隐藏下拉框,多设备时添加到下拉框;m_devList记录插入的所有设备,deviceMap记录设备状态
|
||||||
QMap<QString, bool> deviceMap;
|
QMap<QString, bool> deviceMap;
|
||||||
getDeviceEnableState(0,deviceMap);
|
getDeviceEnableState(0,deviceMap);
|
||||||
QStringList enableDevice;
|
|
||||||
m_deviceComboBox->clear();
|
m_deviceComboBox->clear();
|
||||||
m_devList.clear();
|
m_devList.clear();
|
||||||
enableDevice.clear();
|
enableDevice.clear();
|
||||||
|
@ -217,6 +218,7 @@ void LanPage::initDeviceCombox()
|
||||||
if (enableDevice.count() == 1) {
|
if (enableDevice.count() == 1) {
|
||||||
m_deviceFrame->hide();
|
m_deviceFrame->hide();
|
||||||
m_deviceName = enableDevice.at(0);
|
m_deviceName = enableDevice.at(0);
|
||||||
|
qDebug() << "[LanPage]Current device:" << m_deviceName;
|
||||||
initList(m_deviceName);
|
initList(m_deviceName);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
|
@ -224,7 +226,7 @@ void LanPage::initDeviceCombox()
|
||||||
m_tipsLabel->hide();
|
m_tipsLabel->hide();
|
||||||
m_deviceComboBox->show();
|
m_deviceComboBox->show();
|
||||||
for (int j=0; j<enableDevice.count(); ++j) {
|
for (int j=0; j<enableDevice.count(); ++j) {
|
||||||
m_deviceComboBox->addItem(enableDevice.at(j));
|
m_deviceComboBox->addItem(enableDevice.at(j));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -295,9 +297,11 @@ void LanPage::onDeviceNameUpdate(QString oldName, QString newName)
|
||||||
void LanPage::onDeviceComboxIndexChanged(int currentIndex)
|
void LanPage::onDeviceComboxIndexChanged(int currentIndex)
|
||||||
{
|
{
|
||||||
//TODO 设备变更时更新设备和列表
|
//TODO 设备变更时更新设备和列表
|
||||||
m_deviceName = m_deviceComboBox->currentText();
|
if (enableDevice.count() == m_deviceComboBox->count()) {
|
||||||
qDebug() << "[LanPage]Current Device Changed to:" << m_deviceName;
|
m_deviceName = m_deviceComboBox->currentText();
|
||||||
initList(m_deviceName);
|
qDebug() << "[LanPage]Current Device Changed to:" << m_deviceName;
|
||||||
|
initList(m_deviceName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LanPage::initUI()
|
void LanPage::initUI()
|
||||||
|
@ -339,8 +343,14 @@ void LanPage::addNewItem(KyConnectItem *itemData, QListWidget *listWidget)
|
||||||
m_listWidgetItem->setSizeHint(QSize(listWidget->width(),ITEM_HEIGHT));
|
m_listWidgetItem->setSizeHint(QSize(listWidget->width(),ITEM_HEIGHT));
|
||||||
listWidget->addItem(m_listWidgetItem);
|
listWidget->addItem(m_listWidgetItem);
|
||||||
|
|
||||||
m_testLanItem = new LanListItem(itemData, m_deviceName);
|
if (itemData != nullptr) {
|
||||||
qDebug() << "[LanPage] addNewItem, connection: " << itemData->m_connectName << "deviceName: " << m_deviceName;
|
m_testLanItem = new LanListItem(itemData, m_deviceName);
|
||||||
|
qDebug() << "[LanPage] addNewItem, connection: " << itemData->m_connectName << "deviceName: " << m_deviceName;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
m_testLanItem = new LanListItem();
|
||||||
|
qDebug() << "[LanPage] Add nullItem!";
|
||||||
|
}
|
||||||
listWidget->setItemWidget(m_listWidgetItem, m_testLanItem);
|
listWidget->setItemWidget(m_listWidgetItem, m_testLanItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -353,25 +363,6 @@ void LanPage::initList(QString m_deviceName) //程序拉起,初始化显
|
||||||
m_activedList.clear();
|
m_activedList.clear();
|
||||||
m_deactivedList.clear();
|
m_deactivedList.clear();
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
m_activeMap.insert(activeItemData, m_listWidgetItem);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
m_nullItem = new QListWidgetItem(m_activatedLanListWidget);
|
|
||||||
m_nullItem->setSizeHint(QSize(m_activatedLanListWidget->width(),ITEM_HEIGHT));
|
|
||||||
m_activatedLanListWidget->addItem(m_nullItem);
|
|
||||||
|
|
||||||
m_nullLanItem = new LanListItem();
|
|
||||||
m_activatedLanListWidget->setItemWidget(m_nullItem, m_nullLanItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
m_connectResourse->getConnectionList(m_deviceName, NetworkManager::ConnectionSettings::Wired, m_deactivedList); //未激活列表的显示
|
m_connectResourse->getConnectionList(m_deviceName, NetworkManager::ConnectionSettings::Wired, m_deactivedList); //未激活列表的显示
|
||||||
if (!m_deactivedList.isEmpty()) {
|
if (!m_deactivedList.isEmpty()) {
|
||||||
for (int i = 0; i < m_deactivedList.size(); i++) {
|
for (int i = 0; i < m_deactivedList.size(); i++) {
|
||||||
|
@ -381,6 +372,30 @@ void LanPage::initList(QString m_deviceName) //程序拉起,初始化显
|
||||||
m_deactiveMap.insert(deactiveItemData, m_listWidgetItem);
|
m_deactiveMap.insert(deactiveItemData, m_listWidgetItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isCarriered = true;
|
||||||
|
if (!m_device->wiredDeviceCarriered(m_deviceName)) {
|
||||||
|
isCarriered = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
if (isCarriered) {
|
||||||
|
addNewItem(activeItemData, m_activatedLanListWidget);
|
||||||
|
m_activeMap.insert(activeItemData, m_listWidgetItem);
|
||||||
|
} else {
|
||||||
|
addNewItem(activeItemData, m_inactivatedLanListWidget);
|
||||||
|
m_deactiveMap.insert(activeItemData, m_listWidgetItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
addNewItem(nullptr, m_activatedLanListWidget); //显示一个未激活任何连接的item
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LanPage::updateLanlist(QString uuid, NetworkManager::ActiveConnection::State state, NetworkManager::ActiveConnection::Reason reason)
|
void LanPage::updateLanlist(QString uuid, NetworkManager::ActiveConnection::State state, NetworkManager::ActiveConnection::Reason reason)
|
||||||
|
@ -478,12 +493,7 @@ void LanPage::updateLanlist(QString uuid, NetworkManager::ActiveConnection::Stat
|
||||||
|
|
||||||
if (m_activeMap.count() <= 0) {
|
if (m_activeMap.count() <= 0) {
|
||||||
m_activatedLanListWidget->clear();
|
m_activatedLanListWidget->clear();
|
||||||
m_nullItem = new QListWidgetItem(m_activatedLanListWidget);
|
addNewItem(nullptr, m_activatedLanListWidget); //显示一个未激活任何连接的item
|
||||||
m_nullItem->setSizeHint(QSize(m_activatedLanListWidget->width(),ITEM_HEIGHT));
|
|
||||||
m_activatedLanListWidget->addItem(m_nullItem);
|
|
||||||
m_nullLanItem = new LanListItem();
|
|
||||||
qDebug() << "[LanPage] Add nullItem!";
|
|
||||||
m_activatedLanListWidget->setItemWidget(m_nullItem, m_nullLanItem);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,7 @@ private:
|
||||||
void initUI();
|
void initUI();
|
||||||
void initList(QString m_deviceName);
|
void initList(QString m_deviceName);
|
||||||
void addNewItem(KyConnectItem *itemData, QListWidget *listWidget);
|
void addNewItem(KyConnectItem *itemData, QListWidget *listWidget);
|
||||||
|
void addNUllItem(QListWidget *listWidget);
|
||||||
void initNetSwitch();
|
void initNetSwitch();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -67,6 +68,7 @@ private:
|
||||||
|
|
||||||
QString m_deviceName;
|
QString m_deviceName;
|
||||||
QStringList m_devList;
|
QStringList m_devList;
|
||||||
|
QStringList enableDevice;
|
||||||
QGSettings * m_switchGsettings = nullptr;
|
QGSettings * m_switchGsettings = nullptr;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
|
Loading…
Reference in New Issue