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