Skip to content

Commit a0316bc

Browse files
committed
feat: optimize wireless connection persistence and network details
management 1. Modified connection creation logic to use addAndActivateConnection2 for wireless connections with memory persistence and manual connection flags 2. Simplified network details update mechanism by using object pointers as keys instead of names 3. Added proper null pointer checks and improved memory management 4. Enhanced connection type handling for better wireless network management Log: Improved wireless connection handling and network details display Influence: 1. Test wireless connection creation and activation with different network types 2. Verify network details are properly displayed and updated 3. Check that connection flags are correctly set for manual wireless connections 4. Test network interface changes and ensure details are synchronized 5. Verify memory usage and persistence settings for wireless connections feat: 优化无线连接持久化和网络详情管理 1. 修改连接创建逻辑,对无线连接使用 addAndActivateConnection2 并设置内存 持久化和手动连接标志 2. 简化网络详情更新机制,使用对象指针代替名称作为键值 3. 添加了空指针检查并改进了内存管理 4. 增强了连接类型处理以改善无线网络管理 Log: 改进无线连接处理和网络详情显示 Influence: 1. 测试不同网络类型下的无线连接创建和激活 2. 验证网络详情是否正确显示和更新 3. 检查手动无线连接的连接标志是否正确设置 4. 测试网络接口变化并确保详情同步 5. 验证无线连接的内存使用和持久化设置 PMS: BUG-336853
1 parent b670358 commit a0316bc

File tree

1 file changed

+16
-22
lines changed

1 file changed

+16
-22
lines changed

net-view/operation/private/netmanagerthreadprivate.cpp

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,22 +1547,16 @@ void NetManagerThreadPrivate::doSetConnectInfo(const QString &id, NetType::NetIt
15471547
if (!settings->autoconnect()) {
15481548
usedAdd = true;
15491549
}
1550-
// settings->connectionType()
1551-
// if (settings->connectionType() == ConnectionSettings::Vpn || settings->connectionType() == ConnectionSettings::Pppoe || !settings->autoconnect()) {
1552-
// usedAdd = true;
1553-
// } else if (settings->connectionType() == ConnectionSettings::Wired) {
1554-
// NetworkManager::Device::Ptr device = NetworkManager::findNetworkInterface(devPath);
1555-
// if (device && device->type() == NetworkManager::Device::Type::Ethernet) {
1556-
// // 有线连接且当前网卡没有插入网线的情况下,只调用addConnection而不调用addAndActivateConnection
1557-
// // 否则会无法添加连接
1558-
// usedAdd = !device.staticCast<NetworkManager::WiredDevice>()->carrier();
1559-
// }
1560-
// }
15611550
if (usedAdd || devPath.isEmpty()) {
15621551
reply = NetworkManager::addConnection(settings->toMap());
15631552
} else {
15641553
// 其他场景
1565-
reply = NetworkManager::addAndActivateConnection(settings->toMap(), devPath, QString());
1554+
QVariantMap options;
1555+
if (settings->connectionType() == ConnectionSettings::Wireless) {
1556+
options.insert("persist", "memory");
1557+
options.insert("flags", MANULCONNECTION);
1558+
}
1559+
reply = NetworkManager::addAndActivateConnection2(settings->toMap(), devPath, QString(), options);
15661560
}
15671561
reply.waitForFinished();
15681562
const QString &connPath = reply.argumentAt(0).value<QDBusObjectPath>().path();
@@ -2402,50 +2396,50 @@ void NetManagerThreadPrivate::onDslActiveConnectionChanged()
24022396
void NetManagerThreadPrivate::updateDetails()
24032397
{
24042398
// 使用对象指针作为键,而不是 name()
2405-
QSet<NetworkDetails*> currentDetails;
2399+
QSet<NetworkDetails *> currentDetails;
24062400
for (auto &&details : NetworkController::instance()->networkDetails()) {
24072401
if (!details) // 空指针检查
24082402
continue;
24092403
currentDetails.insert(details);
24102404
}
2411-
2405+
24122406
// 找出需要删除的项(在 m_detailsItemsMap 中但不在 currentDetails 中)
2413-
QList<NetworkDetails*> toRemove;
2407+
QList<NetworkDetails *> toRemove;
24142408
for (auto it = m_detailsItemsMap.begin(); it != m_detailsItemsMap.end(); ++it) {
24152409
if (!currentDetails.contains(it.key())) {
24162410
toRemove.append(it.key());
24172411
}
24182412
}
2419-
2413+
24202414
// 删除不再存在的项
24212415
for (auto *details : toRemove) {
24222416
QString itemId = m_detailsItemsMap.value(details);
24232417
m_detailsItemsMap.remove(details);
24242418
Q_EMIT itemRemoved(itemId);
24252419
}
2426-
2420+
24272421
// 添加新项或更新现有项
24282422
int index = 0;
24292423
for (auto &&details : NetworkController::instance()->networkDetails()) {
24302424
if (!details) // 空指针检查
24312425
continue;
2432-
2426+
24332427
// 生成唯一ID:使用对象指针地址
24342428
QString uniqueId = QString("detail_%1").arg(reinterpret_cast<quintptr>(details));
2435-
2429+
24362430
if (!m_detailsItemsMap.contains(details)) {
24372431
// 新项,创建 NetDetailsInfoItem
24382432
m_detailsItemsMap.insert(details, uniqueId);
24392433
connect(details, &NetworkDetails::infoChanged, this, &NetManagerThreadPrivate::updateDetails, Qt::QueuedConnection);
2440-
2434+
24412435
NetDetailsInfoItemPrivate *item = NetItemNew(DetailsInfoItem, uniqueId);
24422436
item->updatename(details->name());
24432437
item->updateindex(index);
24442438
item->item()->moveToThread(m_parentThread);
2445-
2439+
24462440
Q_EMIT itemAdded("Details", item);
24472441
}
2448-
2442+
24492443
// 更新数据
24502444
QList<QStringList> data;
24512445
for (auto &&info : details->items()) {

0 commit comments

Comments
 (0)