add LanConnection loading

This commit is contained in:
ksn 2021-09-17 14:04:14 +08:00
parent 2334cccda7
commit 825b41422e
7 changed files with 83 additions and 40 deletions

View File

@ -8,27 +8,25 @@ LanListItem::LanListItem(KyConnectItem *data, QString deviceName, QWidget *paren
: m_data(data), deviceName(deviceName), ListItem(parent) //item数据传入
{
m_connectOperation = new KyWiredConnectOperation;
m_activeConnectResource = new KyActiveConnectResourse;
m_connectResource = new KyConnectResourse;
m_data = data;
m_nameLabel->setText(m_data->m_connectName);
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)
@ -40,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){
@ -51,43 +58,16 @@ void LanListItem::onNetButtonClicked()
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;
// 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!" << 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()
{
//右键点击事件
@ -105,3 +85,24 @@ 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);
}
}
}
}

View File

@ -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

View File

@ -43,6 +43,8 @@ LanPage::LanPage(QWidget *parent) : TabPage(parent)
connect(m_connectResourse, &KyConnectResourse::connectionAdd, this, &LanPage::addConnectionSlot);
connect(m_connectResourse, &KyConnectResourse::connectionRemove, this, &LanPage::removeConnectionSlot);
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);
@ -322,9 +324,9 @@ 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);
@ -382,6 +384,7 @@ void LanPage::addNewItem(KyConnectItem *itemData, QListWidget *listWidget)
m_testLanItem = new LanListItem(itemData, m_deviceName);
qDebug() << "[LanPage] addNewItem, connection: " << itemData->m_connectName << "deviceName: " << m_deviceName;
listWidget->setItemWidget(m_listWidgetItem, m_testLanItem);
qDebug() << "??????????";
}
void LanPage::initList(QString m_deviceName) //程序拉起,初始化显示
@ -512,8 +515,13 @@ void LanPage::updateLanlist(QString uuid, NetworkManager::ActiveConnection::Stat
}
}
}
else if (state == NetworkManager::ActiveConnection::State::Activating){
else{
// QMap<KyConnectItem *, QListWidgetItem *>::iterator i;
// for (i = m_deactiveMap.begin(); i != m_deactiveMap.constEnd(); ++i) {
// KyConnectItem *m_item = i.key();
// if (m_item->m_connectUuid == uuid) {
// }
}
if (m_activeMap.count() <= 0) {
@ -557,6 +565,36 @@ 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;
}
else {
qDebug() << "[LanPage] Connection data changed!";
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);

View File

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

View File

@ -108,7 +108,7 @@ void RadioItemButton::onLoadingTimerTimeout()
QString qpmQss = ":/res/s/conning-a/";
qpmQss.append(QString::number(this->currentPage));
qpmQss.append(".png");
qDebug()<<qpmQss;
// qDebug()<<qpmQss;
m_iconLabel->setPixmap(QPixmap(qpmQss));
this->currentPage --;

View File

@ -0,0 +1 @@
<クd<>箆!ソ`。スン

Binary file not shown.