@@ -173,6 +173,90 @@ void NetworkManagerProcesser::sortDevice()
173173 });
174174}
175175
176+ // 无线网卡不管是否down,都显示,因为在开启飞行模式后,需要显示网卡的信息
177+ void NetworkManagerProcesser::createOrRemoveDevice (const QString &path)
178+ {
179+ NetworkManager::Device::Ptr device = NetworkManager::findNetworkInterface (path);
180+ if (device.isNull ())
181+ return ;
182+
183+ auto updateHotspot = [ this ] {
184+ if (m_hotspotController) {
185+ m_hotspotController->updateDevices (m_devices);
186+ }
187+ };
188+
189+ if (device->managed ()
190+ #ifdef USE_DEEPIN_NMQT
191+ && ((device->interfaceFlags () & DEVICE_INTERFACE_FLAG_UP) ||
192+ device->type () == NetworkManager::Device::Wifi)
193+ #endif
194+ ) {
195+ // 如果由非manager变成manager的模式,则新增设备
196+ if (!deviceExist (device->uni ())) {
197+ NetworkDeviceBase *newDevice = createDevice (device);
198+ if (newDevice) {
199+ m_devices << newDevice;
200+ sortDevice ();
201+ updateDeviceName ();
202+ onUpdateNetworkDetail ();
203+ Q_EMIT deviceAdded ({ newDevice });
204+ updateHotspot ();
205+ }
206+ }
207+ } else {
208+ // 如果由manager变成非manager模式,则移除设备
209+ NetworkDeviceBase *rmDevice = nullptr ;
210+ for (NetworkDeviceBase *dev : m_devices) {
211+ if (dev->path () == device->uni ()) {
212+ m_devices.removeOne (dev);
213+ rmDevice = dev;
214+ break ;
215+ }
216+ }
217+ if (rmDevice) {
218+ Q_EMIT rmDevice->removed ();
219+ sortDevice ();
220+ updateDeviceName ();
221+ onUpdateNetworkDetail ();
222+ Q_EMIT deviceRemoved ({ rmDevice });
223+ rmDevice->deleteLater ();
224+ rmDevice = nullptr ;
225+ updateHotspot ();
226+ }
227+ }
228+ }
229+
230+ bool NetworkManagerProcesser::deviceExist (const QString &path) const
231+ {
232+ for (NetworkDeviceBase *device : m_devices) {
233+ if (device->path () == path)
234+ return true ;
235+ }
236+
237+ return false ;
238+ }
239+
240+ NetworkDeviceBase *NetworkManagerProcesser::createDevice (const NetworkManager::Device::Ptr &device)
241+ {
242+ if (device->type () == NetworkManager::Device::Wifi) {
243+ // 无线网络
244+ NetworkManager::WirelessDevice::Ptr wDevice = device.staticCast <NetworkManager::WirelessDevice>();
245+ WirelessDeviceManagerRealize *deviceRealize = new WirelessDeviceManagerRealize (wDevice);
246+ deviceRealize->addProcesser (this );
247+ return new WirelessDevice (deviceRealize, Q_NULLPTR);
248+ }
249+
250+ if (device->type () == NetworkManager::Device::Ethernet) {
251+ // 有线网络
252+ NetworkManager::WiredDevice::Ptr wDevice = device.staticCast <NetworkManager::WiredDevice>();
253+ DeviceManagerRealize *deviceRealize = new WiredDeviceManagerRealize (wDevice);
254+ return new WiredDevice (deviceRealize, Q_NULLPTR);
255+ }
256+
257+ return nullptr ;
258+ }
259+
176260void NetworkManagerProcesser::onUpdateNetworkDetail ()
177261{
178262 if (!m_needDetails)
@@ -212,15 +296,6 @@ void NetworkManagerProcesser::onUpdateNetworkDetail()
212296
213297void NetworkManagerProcesser::onDeviceAdded (const QString &uni)
214298{
215- auto deviceExist = [ this ](const QString &uni)->bool {
216- for (NetworkDeviceBase *device : m_devices) {
217- if (device->path () == uni)
218- return true ;
219- }
220-
221- return false ;
222- };
223-
224299 if (deviceExist (uni))
225300 return ;
226301
@@ -229,74 +304,6 @@ void NetworkManagerProcesser::onDeviceAdded(const QString &uni)
229304 (currentDevice->type () != NetworkManager::Device::Wifi && currentDevice->type () != NetworkManager::Device::Ethernet))
230305 return ;
231306
232- auto updateHotspot = [ this ] {
233- if (m_hotspotController) {
234- m_hotspotController->updateDevices (m_devices);
235- }
236- };
237-
238- auto createDevice = [ = ](const NetworkManager::Device::Ptr &device)->NetworkDeviceBase *{
239- if (device->type () == NetworkManager::Device::Wifi) {
240- // 无线网络
241- NetworkManager::WirelessDevice::Ptr wDevice = device.staticCast <NetworkManager::WirelessDevice>();
242- WirelessDeviceManagerRealize *deviceRealize = new WirelessDeviceManagerRealize (wDevice);
243- deviceRealize->addProcesser (this );
244- return new WirelessDevice (deviceRealize, Q_NULLPTR);
245- }
246-
247- if (device->type () == NetworkManager::Device::Ethernet) {
248- // 有线网络
249- NetworkManager::WiredDevice::Ptr wDevice = device.staticCast <NetworkManager::WiredDevice>();
250- DeviceManagerRealize *deviceRealize = new WiredDeviceManagerRealize (wDevice);
251- return new WiredDevice (deviceRealize, Q_NULLPTR);
252- }
253-
254- return nullptr ;
255- };
256-
257- // 无线网卡不管是否down,都显示,因为在开启飞行模式后,需要显示网卡的信息
258- auto deviceCreateOrRemove = [ this , deviceExist, createDevice, updateHotspot ](const NetworkManager::Device::Ptr &device) {
259- if (device->managed ()
260- #ifdef USE_DEEPIN_NMQT
261- && ((device->interfaceFlags () & DEVICE_INTERFACE_FLAG_UP) ||
262- device->type () == NetworkManager::Device::Wifi)
263- #endif
264- ) {
265- // 如果由非manager变成manager的模式,则新增设备
266- if (!deviceExist (device->uni ())) {
267- NetworkDeviceBase *newDevice = createDevice (device);
268- if (newDevice) {
269- m_devices << newDevice;
270- sortDevice ();
271- updateDeviceName ();
272- onUpdateNetworkDetail ();
273- Q_EMIT deviceAdded ({ newDevice });
274- updateHotspot ();
275- }
276- }
277- } else {
278- // 如果由manager变成非manager模式,则移除设备
279- NetworkDeviceBase *rmDevice = nullptr ;
280- for (NetworkDeviceBase *dev : m_devices) {
281- if (dev->path () == device->uni ()) {
282- m_devices.removeOne (dev);
283- rmDevice = dev;
284- break ;
285- }
286- }
287- if (rmDevice) {
288- Q_EMIT rmDevice->removed ();
289- sortDevice ();
290- updateDeviceName ();
291- onUpdateNetworkDetail ();
292- Q_EMIT deviceRemoved ({ rmDevice });
293- rmDevice->deleteLater ();
294- rmDevice = nullptr ;
295- updateHotspot ();
296- }
297- }
298- };
299-
300307 if (!currentDevice->managed () || currentDevice->interfaceFlags () == 0 ) {
301308 // TODO: 临时解决方案,适用于ARM平台,从根本上解决需要从NetworkManagerQt入手
302309 // 在ARM下存在当前设备的manager为false,interfaceFlags为0,但是该设备实际是manager为true并且interfaceflags不为0,
@@ -318,12 +325,12 @@ void NetworkManagerProcesser::onDeviceAdded(const QString &uni)
318325 }
319326
320327#ifdef USE_DEEPIN_NMQT
321- connect (currentDevice.get (), &NetworkManager::Device::interfaceFlagsChanged, currentDevice.get (), [ currentDevice, deviceCreateOrRemove ] {
322- deviceCreateOrRemove (currentDevice );
328+ connect (currentDevice.get (), &NetworkManager::Device::interfaceFlagsChanged, currentDevice.get (), [ uni, this ] {
329+ createOrRemoveDevice (uni );
323330 });
324331#endif
325- connect (currentDevice.get (), &NetworkManager::Device::managedChanged, currentDevice.get (), [ currentDevice, deviceCreateOrRemove ] {
326- deviceCreateOrRemove (currentDevice );
332+ connect (currentDevice.get (), &NetworkManager::Device::managedChanged, currentDevice.get (), [ uni, this ] {
333+ createOrRemoveDevice (uni );
327334 });
328335
329336 if (currentDevice->managed ()
@@ -341,7 +348,9 @@ void NetworkManagerProcesser::onDeviceAdded(const QString &uni)
341348 updateDeviceName ();
342349 onUpdateNetworkDetail ();
343350 Q_EMIT deviceAdded ({ newDevice });
344- updateHotspot ();
351+ if (m_hotspotController) {
352+ m_hotspotController->updateDevices (m_devices);
353+ }
345354 }
346355}
347356
0 commit comments