forked from linuxdeepin/dde-network-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnetmanagerthreadprivate.cpp
2697 lines (2478 loc) · 117 KB
/
netmanagerthreadprivate.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// SPDX-FileCopyrightText: 2019 - 2022 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later
#include "netmanagerthreadprivate.h"
#include "configsetting.h"
#include "dslcontroller.h"
#include "hotspotcontroller.h"
#include "impl/configwatcher.h"
#include "impl/networkmanager/nmnetworkmanager.h"
#include "nethotspotcontroller.h"
#include "netitemprivate.h"
#include "netsecretagent.h"
#include "netsecretagentforui.h"
#include "netwirelessconnect.h"
#include "networkcontroller.h"
#include "networkdetails.h"
#include "networkdevicebase.h"
#include "networkmanagerqt/manager.h"
#include "wireddevice.h"
#include "wirelessdevice.h"
#include <NetworkManagerQt/AccessPoint>
#include <NetworkManagerQt/Ipv6Setting>
#include <NetworkManagerQt/Manager>
#include <NetworkManagerQt/PppSetting>
#include <NetworkManagerQt/PppoeSetting>
#include <NetworkManagerQt/Security8021xSetting>
#include <NetworkManagerQt/Settings>
#include <NetworkManagerQt/Utils>
#include <NetworkManagerQt/VpnSetting>
#include <NetworkManagerQt/WiredDevice>
#include <NetworkManagerQt/WiredSetting>
#include <NetworkManagerQt/WirelessDevice>
#include <NetworkManagerQt/WirelessSetting>
#include <impl/vpncontroller.h>
#include <proxycontroller.h>
#include <QDBusConnection>
#include <QThread>
using namespace NetworkManager;
namespace dde {
namespace network {
enum class NetworkNotifyType {
WiredConnecting, // 有线连接中
WirelessConnecting, // 无线连接中
WiredConnected, // 有线已连接
WirelessConnected, // 无线已连接
WiredDisconnected, // 有线断开
WirelessDisconnected, // 无线断开
WiredUnableConnect, // 有线无法连接
WirelessUnableConnect, // 无线无法连接
WiredConnectionFailed, // 有线连接失败
WirelessConnectionFailed, // 无线连接失败
NoSecrets, // 密码错误
SsidNotFound, // 没找到ssid
Wireless8021X // 企业版认证
};
const QString notifyIconNetworkOffline = "notification-network-offline";
const QString notifyIconWiredConnected = "notification-network-wired-connected";
const QString notifyIconWiredDisconnected = "notification-network-wired-disconnected";
const QString notifyIconWiredError = "notification-network-wired-disconnected";
const QString notifyIconWirelessConnected = "notification-network-wireless-full";
const QString notifyIconWirelessDisconnected = "notification-network-wireless-disconnected";
const QString notifyIconWirelessDisabled = "notification-network-wireless-disabled";
const QString notifyIconWirelessError = "notification-network-wireless-disconnected";
const QString notifyIconVpnConnected = "notification-network-vpn-connected";
const QString notifyIconVpnDisconnected = "notification-network-vpn-disconnected";
const QString notifyIconProxyEnabled = "notification-network-proxy-enabled";
const QString notifyIconProxyDisabled = "notification-network-proxy-disabled";
const QString notifyIconNetworkConnected = "notification-network-wired-connected";
const QString notifyIconNetworkDisconnected = "notification-network-wired-disconnected";
const QString notifyIconMobile2gConnected = "notification-network-mobile-2g-connected";
const QString notifyIconMobile2gDisconnected = "notification-network-mobile-2g-disconnected";
const QString notifyIconMobile3gConnected = "notification-network-mobile-3g-connected";
const QString notifyIconMobile3gDisconnected = "notification-network-mobile-3g-disconnected";
const QString notifyIconMobile4gConnected = "notification-network-mobile-4g-connected";
const QString notifyIconMobile4gDisconnected = "notification-network-mobile-4g-disconnected";
const QString notifyIconMobileUnknownConnected = "notification-network-mobile-unknown-connected";
const QString notifyIconMobileUnknownDisconnected = "notification-network-mobile-unknown-disconnected";
#define MANULCONNECTION 1
NetManagerThreadPrivate::NetManagerThreadPrivate()
: QObject()
, m_thread(new QThread(this))
, m_parentThread(QThread::currentThread())
, m_monitorNetworkNotify(false)
, m_useSecretAgent(true)
, m_network8021XMode(NetManager::ToControlCenter)
, m_autoUpdateHiddenConfig(true)
, m_isInitialized(false)
, m_enabled(true)
, m_autoScanInterval(0)
, m_autoScanEnabled(false)
, m_autoScanTimer(nullptr)
, m_lastThroughTime(0)
, m_lastState(NetworkManager::Device::State::UnknownState)
, m_secretAgent(nullptr)
, m_netCheckAvailable(false)
, m_isSleeping(false)
{
moveToThread(m_thread);
m_thread->start();
}
NetManagerThreadPrivate::~NetManagerThreadPrivate()
{
m_thread->quit();
m_thread->wait(QDeadlineTimer(200));
if (m_thread->isRunning()) {
m_thread->terminate();
}
m_thread->wait(QDeadlineTimer(200));
delete m_thread;
}
// 检查参数,参数有错误的才在QVariantMap里,value暂时为空(预留以后要显示具体错误)
QVariantMap NetManagerThreadPrivate::CheckParamValid(const QVariantMap ¶m)
{
QVariantMap validMap;
for (auto &&it = param.cbegin(); it != param.cend(); ++it) {
const QString &key = it.key();
if (!CheckPasswordValid(key, it.value().toString())) {
validMap.insert(key, QString());
}
}
return validMap;
}
bool NetManagerThreadPrivate::CheckPasswordValid(const QString &key, const QString &password)
{
if (key == "psk") {
return NetworkManager::wpaPskIsValid(password);
} else if (key == "wep-key0" || key == "wep-key1" || key == "wep-key2" || key == "wep-key3") {
return NetworkManager::wepKeyIsValid(password, WirelessSecuritySetting::WepKeyType::Passphrase);
}
return !password.isEmpty();
}
void NetManagerThreadPrivate::getNetCheckAvailableFromDBus()
{
QDBusMessage message = QDBusMessage::createMethodCall("com.deepin.defender.netcheck", "/com/deepin/defender/netcheck", "org.freedesktop.DBus.Properties", "Get");
message << "com.deepin.defender.netcheck"
<< "Availabled";
QDBusConnection::systemBus().callWithCallback(message, this, SLOT(updateNetCheckAvailabled(QDBusVariant)));
}
void NetManagerThreadPrivate::getAirplaneModeEnabled()
{
QDBusMessage message = QDBusMessage::createMethodCall("org.deepin.dde.AirplaneMode1", "/org/deepin/dde/AirplaneMode1", "org.freedesktop.DBus.Properties", "GetAll");
message << "org.deepin.dde.AirplaneMode1";
QDBusConnection::systemBus().callWithCallback(message, this, SLOT(onAirplaneModePropertiesChanged(QVariantMap)));
}
void NetManagerThreadPrivate::setAirplaneModeEnabled(bool enabled)
{
QDBusMessage message = QDBusMessage::createMethodCall("org.deepin.dde.AirplaneMode1", "/org/deepin/dde/AirplaneMode1", "org.deepin.dde.AirplaneMode1", "Enable");
message << enabled;
QDBusConnection::systemBus().callWithCallback(message, this, SLOT(getAirplaneModeEnabled()));
}
AccessPoints *NetManagerThreadPrivate::fromApID(const QString &id)
{
AccessPoints *ap = nullptr;
for (NetworkDeviceBase *device : NetworkController::instance()->devices()) {
if (device->deviceType() == DeviceType::Wireless) {
WirelessDevice *wirelessDev = qobject_cast<WirelessDevice *>(device);
for (auto &&tmpAp : wirelessDev->accessPointItems()) {
if (apID(tmpAp) == id) {
ap = tmpAp;
break;
}
}
if (ap)
break;
}
}
return ap;
}
void NetManagerThreadPrivate::setMonitorNetworkNotify(bool monitor)
{
if (m_isInitialized)
return;
m_monitorNetworkNotify = monitor;
}
void NetManagerThreadPrivate::setUseSecretAgent(bool enabled)
{
if (m_isInitialized)
return;
m_useSecretAgent = enabled;
}
void NetManagerThreadPrivate::setEnabled(bool enabled)
{
m_enabled = enabled;
}
void NetManagerThreadPrivate::setNetwork8021XMode(NetManager::Network8021XMode mode)
{
NetManager::Network8021XMode networkMode = mode;
switch (mode) {
case NetManager::Network8021XMode::ToControlCenterUnderConnect: {
// 如果开起该配置,那么在第一次连接企业网的时候,弹出用户名密码输入框,否则就跳转到控制中心(工行定制)
networkMode = ConfigSetting::instance()->enableEapInput() ? NetManager::Network8021XMode::ToConnect : NetManager::Network8021XMode::ToControlCenter;
break;
}
case NetManager::Network8021XMode::SendNotifyUnderConnect: {
// 如果开启该配置,那么在第一次连接企业网的时候,弹出用户名密码输入框,否则给出提示消息(工行定制)
networkMode = ConfigSetting::instance()->enableEapInput() ? NetManager::Network8021XMode::ToConnect : NetManager::Network8021XMode::SendNotify;
break;
}
default:
break;
}
m_network8021XMode = networkMode;
}
void NetManagerThreadPrivate::setAutoUpdateHiddenConfig(bool autoUpdate)
{
m_autoUpdateHiddenConfig = autoUpdate;
}
void NetManagerThreadPrivate::setAutoScanInterval(int ms)
{
m_autoScanInterval = ms;
if (m_isInitialized)
QMetaObject::invokeMethod(this, "updateAutoScan", Qt::QueuedConnection);
}
void NetManagerThreadPrivate::setAutoScanEnabled(bool enabled)
{
m_autoScanEnabled = enabled;
if (m_isInitialized) {
QMetaObject::invokeMethod(this, "updateAutoScan", Qt::QueuedConnection);
if (m_autoScanEnabled)
QMetaObject::invokeMethod(this, "doAutoScan", Qt::QueuedConnection);
}
}
void NetManagerThreadPrivate::setServerKey(const QString &serverKey)
{
m_serverKey = serverKey;
}
void NetManagerThreadPrivate::init(NetType::NetManagerFlags flags)
{
// 在主线程中先安装翻译器,因为直接在子线程中安装翻译器可能会引起崩溃
// NetworkController::installTranslator(QLocale().name());
m_flags = flags;
QMetaObject::invokeMethod(this, &NetManagerThreadPrivate::doInit, Qt::QueuedConnection);
}
void NetManagerThreadPrivate::setDeviceEnabled(const QString &id, bool enabled)
{
if (m_isInitialized)
QMetaObject::invokeMethod(this, "doSetDeviceEnabled", Qt::QueuedConnection, Q_ARG(QString, id), Q_ARG(bool, enabled));
}
void NetManagerThreadPrivate::requestScan(const QString &id)
{
if (m_isInitialized)
QMetaObject::invokeMethod(this, "doRequestScan", Qt::QueuedConnection, Q_ARG(QString, id));
}
void NetManagerThreadPrivate::disconnectDevice(const QString &id)
{
if (m_isInitialized)
QMetaObject::invokeMethod(this, "doDisconnectDevice", Qt::QueuedConnection, Q_ARG(QString, id));
}
void NetManagerThreadPrivate::connectHidden(const QString &id, const QString &ssid)
{
if (m_isInitialized)
QMetaObject::invokeMethod(this, "doConnectHidden", Qt::QueuedConnection, Q_ARG(QString, id), Q_ARG(QString, ssid));
}
void NetManagerThreadPrivate::connectWired(const QString &id, const QVariantMap ¶m)
{
if (m_isInitialized)
QMetaObject::invokeMethod(this, "doConnectWired", Qt::QueuedConnection, Q_ARG(QString, id), Q_ARG(QVariantMap, param));
}
void NetManagerThreadPrivate::connectWireless(const QString &id, const QVariantMap ¶m)
{
if (m_isInitialized)
QMetaObject::invokeMethod(this, "doConnectWireless", Qt::QueuedConnection, Q_ARG(QString, id), Q_ARG(QVariantMap, param));
}
void NetManagerThreadPrivate::connectHotspot(const QString &id, const QVariantMap ¶m, bool connect)
{
if (m_isInitialized)
QMetaObject::invokeMethod(this, "doConnectHotspot", Qt::QueuedConnection, Q_ARG(QString, id), Q_ARG(QVariantMap, param), Q_ARG(bool, connect));
}
void NetManagerThreadPrivate::gotoControlCenter(const QString &page)
{
QMetaObject::invokeMethod(this, "doGotoControlCenter", Qt::QueuedConnection, Q_ARG(QString, page));
}
void NetManagerThreadPrivate::gotoSecurityTools(const QString &page)
{
QMetaObject::invokeMethod(this, "doGotoSecurityTools", Qt::QueuedConnection, Q_ARG(QString, page));
}
void NetManagerThreadPrivate::userCancelRequest(const QString &id)
{
if (m_isInitialized)
QMetaObject::invokeMethod(this, "doUserCancelRequest", Qt::QueuedConnection, Q_ARG(QString, id));
}
void NetManagerThreadPrivate::retranslate(const QString &locale)
{
NetworkController::installTranslator(QLocale().name());
if (m_isInitialized)
QMetaObject::invokeMethod(this, "doRetranslate", Qt::QueuedConnection, Q_ARG(QString, locale));
}
// clang-format off
void NetManagerThreadPrivate::sendNotify(const QString &appIcon, const QString &body, const QString &summary, const QString &inAppName, int replacesId, const QStringList &actions, const QVariantMap &hints, int expireTimeout)
{
if (!m_enabled)
return;
Q_EMIT networkNotify(inAppName, replacesId, appIcon, summary, body, actions, hints, expireTimeout);
}
// clang-format on
void NetManagerThreadPrivate::onNetCheckPropertiesChanged(QString, QVariantMap properties, QStringList)
{
if (properties.contains("Availabled")) {
updateNetCheckAvailabled(properties.value("Availabled").value<QDBusVariant>());
}
}
void NetManagerThreadPrivate::onAirplaneModeEnabledPropertiesChanged(const QString &, const QVariantMap &properties, const QStringList &)
{
onAirplaneModePropertiesChanged(properties);
}
void NetManagerThreadPrivate::onAirplaneModePropertiesChanged(const QVariantMap &properties)
{
if (properties.contains("Enabled")) {
updateAirplaneModeEnabled(QDBusVariant(properties.value("Enabled").value<bool>()));
}
if (properties.contains("HasAirplaneMode")) {
updateAirplaneModeEnabledable(QDBusVariant(properties.value("HasAirplaneMode").value<bool>()));
}
}
void NetManagerThreadPrivate::connectOrInfo(const QString &id, NetType::NetItemType type, const QVariantMap ¶m)
{
QMetaObject::invokeMethod(this, "doConnectOrInfo", Qt::QueuedConnection, Q_ARG(QString, id), Q_ARG(NetType::NetItemType, type), Q_ARG(QVariantMap, param));
}
void NetManagerThreadPrivate::getConnectInfo(const QString &id, NetType::NetItemType type, const QVariantMap ¶m)
{
QMetaObject::invokeMethod(this, "doGetConnectInfo", Qt::QueuedConnection, Q_ARG(QString, id), Q_ARG(NetType::NetItemType, type), Q_ARG(QVariantMap, param));
}
void NetManagerThreadPrivate::setConnectInfo(const QString &id, NetType::NetItemType type, const QVariantMap ¶m)
{
QMetaObject::invokeMethod(this, "doSetConnectInfo", Qt::QueuedConnection, Q_ARG(QString, id), Q_ARG(NetType::NetItemType, type), Q_ARG(QVariantMap, param));
}
void NetManagerThreadPrivate::deleteConnect(const QString &uuid)
{
QMetaObject::invokeMethod(this, "doDeleteConnect", Qt::QueuedConnection, Q_ARG(QString, uuid));
}
void NetManagerThreadPrivate::importConnect(const QString &id, const QString &file)
{
QMetaObject::invokeMethod(this, "doImportConnect", Qt::QueuedConnection, Q_ARG(QString, id), Q_ARG(QString, file));
}
void NetManagerThreadPrivate::exportConnect(const QString &id, const QString &file)
{
QMetaObject::invokeMethod(this, "doExportConnect", Qt::QueuedConnection, Q_ARG(QString, id), Q_ARG(QString, file));
}
void NetManagerThreadPrivate::doInit()
{
if (m_isInitialized)
return;
m_isInitialized = true;
qRegisterMetaType<NetworkManager::Device::State>("NetworkManager::Device::State");
qRegisterMetaType<NetworkManager::Device::StateChangeReason>("NetworkManager::Device::StateChangeReason");
qRegisterMetaType<Connectivity>("Connectivity");
if (m_flags.testFlag(NetType::NetManagerFlag::Net_ServiceNM)) {
NetworkController::alawaysLoadFromNM();
}
NetworkController::setIPConflictCheck(true);
NetworkController *networkController = NetworkController::instance();
connect(m_thread, &QThread::finished, this, &NetManagerThreadPrivate::clearData);
connect(networkController, &NetworkController::deviceAdded, this, &NetManagerThreadPrivate::onDeviceAdded);
connect(networkController, &NetworkController::deviceRemoved, this, &NetManagerThreadPrivate::onDeviceRemoved);
connect(networkController, &NetworkController::connectivityChanged, this, &NetManagerThreadPrivate::onConnectivityChanged);
if (m_flags.testFlag(NetType::NetManagerFlag::Net_UseSecretAgent)) {
// 密码代理按设置来,不与ConfigSetting::instance()->serviceFromNetworkManager()同步
if (m_flags.testFlag(NetType::NetManagerFlag::Net_ServiceNM)) {
m_secretAgent = new NetSecretAgent(std::bind(&NetManagerThreadPrivate::requestPassword, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3), true, this);
} else {
m_secretAgent = new NetSecretAgentForUI(std::bind(&NetManagerThreadPrivate::requestPassword, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3), m_serverKey, this);
}
}
onDeviceAdded(networkController->devices());
if (m_autoScanInterval == 0) { // 没有设置则以配置中值设置下
m_autoScanInterval = ConfigSetting::instance()->wirelessScanInterval();
connect(ConfigSetting::instance(), &ConfigSetting::wirelessScanIntervalChanged, this, &NetManagerThreadPrivate::setAutoScanInterval);
}
updateAutoScan();
// VPN
if (m_flags.testFlags(NetType::NetManagerFlag::Net_VPN)) {
NetVPNControlItemPrivate *vpnControlItem = NetItemNew(VPNControlItem, "NetVPNControlItem");
vpnControlItem->updatename("VPN");
vpnControlItem->updateenabled(networkController->vpnController()->enabled());
vpnControlItem->item()->moveToThread(m_parentThread);
Q_EMIT itemAdded("Root", vpnControlItem);
connect(networkController->vpnController(), &VPNController::enableChanged, this, &NetManagerThreadPrivate::onVPNEnableChanged);
// connect(networkController->vpnController(), &VPNController::itemChanged, this, vpnItemChanged);
connect(networkController->vpnController(), &VPNController::itemAdded, this, &NetManagerThreadPrivate::onVPNAdded);
connect(networkController->vpnController(), &VPNController::itemRemoved, this, &NetManagerThreadPrivate::onVPNRemoved);
connect(networkController->vpnController(), &VPNController::activeConnectionChanged, this, &NetManagerThreadPrivate::onVpnActiveConnectionChanged);
onVPNAdded(networkController->vpnController()->items());
}
// 系统代理
if (m_flags.testFlags(NetType::NetManagerFlag::Net_SysProxy)) {
networkController->proxyController()->querySysProxyData();
ProxyMethod method = networkController->proxyController()->proxyMethod();
NetSystemProxyControlItemPrivate *item = NetItemNew(SystemProxyControlItem, "NetSystemProxyControlItem");
item->updatename("SystemProxy");
item->updateenabled(method == ProxyMethod::Auto || method == ProxyMethod::Manual);
// item->updateenabledable(networkController->proxyController()->systemProxyExist());
item->item()->moveToThread(m_parentThread);
Q_EMIT itemAdded("Root", item);
onSystemAutoProxyChanged(networkController->proxyController()->autoProxy());
onSystemManualProxyChanged();
// connect(networkController->proxyController(), &ProxyController::systemProxyExistChanged, this, &NetManagerThreadPrivate::onSystemProxyExistChanged);
connect(networkController->proxyController(), &ProxyController::proxyMethodChanged, this, &NetManagerThreadPrivate::onSystemProxyMethodChanged);
connect(networkController->proxyController(), &ProxyController::autoProxyChanged, this, &NetManagerThreadPrivate::onSystemAutoProxyChanged);
connect(networkController->proxyController(), &ProxyController::proxyChanged, this, &NetManagerThreadPrivate::onSystemManualProxyChanged);
connect(networkController->proxyController(), &ProxyController::proxyAuthChanged, this, &NetManagerThreadPrivate::onSystemManualProxyChanged);
connect(networkController->proxyController(), &ProxyController::proxyIgnoreHostsChanged, this, &NetManagerThreadPrivate::onSystemManualProxyChanged);
}
// 应用代理
if (m_flags.testFlags(NetType::NetManagerFlag::Net_AppProxy)) {
networkController->proxyController()->querySysProxyData();
NetAppProxyControlItemPrivate *item = NetItemNew(AppProxyControlItem, "NetAppProxyControlItem");
item->updatename("AppProxy");
item->updateenabled(networkController->proxyController()->appProxyEnabled());
// item->updateenabledable(networkController->proxyController()->appProxyExist());
item->item()->moveToThread(m_parentThread);
Q_EMIT itemAdded("Root", item);
onAppProxyChanged();
connect(networkController->proxyController(), &ProxyController::appEnableChanged, this, &NetManagerThreadPrivate::onAppProxyEnableChanged);
connect(networkController->proxyController(), &ProxyController::appIPChanged, this, &NetManagerThreadPrivate::onAppProxyChanged);
connect(networkController->proxyController(), &ProxyController::appPasswordChanged, this, &NetManagerThreadPrivate::onAppProxyChanged);
connect(networkController->proxyController(), &ProxyController::appTypeChanged, this, &NetManagerThreadPrivate::onAppProxyChanged);
connect(networkController->proxyController(), &ProxyController::appUsernameChanged, this, &NetManagerThreadPrivate::onAppProxyChanged);
connect(networkController->proxyController(), &ProxyController::appPortChanged, this, &NetManagerThreadPrivate::onAppProxyChanged);
}
m_isInitialized = true;
m_netCheckAvailable = false;
getNetCheckAvailableFromDBus();
QDBusConnection::systemBus().connect("com.deepin.defender.netcheck",
"/com/deepin/defender/netcheck",
"org.freedesktop.DBus.Properties",
"PropertiesChanged",
this,
SLOT(onNetCheckPropertiesChanged(QString, QVariantMap, QStringList)));
QDBusConnection::systemBus().connect("org.freedesktop.login1", "/org/freedesktop/login1", "org.freedesktop.login1.Manager", "PrepareForSleep", this, SLOT(onPrepareForSleep(bool)));
// 优先网络
auto updadePrimaryConnectionType = [this] {
Q_EMIT dataChanged(DataChanged::primaryConnectionTypeChanged, "", NetworkManager::primaryConnectionType());
};
connect(NetworkManager::notifier(), &NetworkManager::Notifier::primaryConnectionTypeChanged, this, updadePrimaryConnectionType);
updadePrimaryConnectionType();
// 热点
if (m_flags.testFlags(NetType::NetManagerFlag::Net_Hotspot)) {
networkController->hotspotController();
NetHotspotController *netHotspotController = new NetHotspotController(this);
NetHotspotControlItemPrivate *hotspotcontrolitem = NetItemNew(HotspotControlItem, "NetHotspotControlItem");
hotspotcontrolitem->updateconfig(netHotspotController->config());
hotspotcontrolitem->updateenabledable(netHotspotController->enabledable());
hotspotcontrolitem->updateenabled(netHotspotController->isEnabled());
hotspotcontrolitem->updateoptionalDevice(netHotspotController->optionalDevice());
hotspotcontrolitem->updateshareDevice(netHotspotController->shareDevice());
hotspotcontrolitem->item()->moveToThread(m_parentThread);
Q_EMIT itemAdded("Root", hotspotcontrolitem);
connect(netHotspotController, &NetHotspotController::enabledChanged, this, &NetManagerThreadPrivate::updateHotspotEnabledChanged);
connect(netHotspotController, &NetHotspotController::enabledableChanged, this, &NetManagerThreadPrivate::onHotspotEnabledableChanged);
connect(netHotspotController, &NetHotspotController::configChanged, this, &NetManagerThreadPrivate::onHotspotConfigChanged);
connect(netHotspotController, &NetHotspotController::optionalDeviceChanged, this, &NetManagerThreadPrivate::onHotspotOptionalDeviceChanged);
connect(netHotspotController, &NetHotspotController::shareDeviceChanged, this, &NetManagerThreadPrivate::onHotspotShareDeviceChanged);
}
// Airplane
if (m_flags.testFlags(NetType::NetManagerFlag::Net_Airplane)) {
m_airplaneModeEnabled = false;
getAirplaneModeEnabled();
QDBusConnection::systemBus().connect("org.deepin.dde.AirplaneMode1",
"/org/deepin/dde/AirplaneMode1",
"org.freedesktop.DBus.Properties",
"PropertiesChanged",
this,
SLOT(onAirplaneModeEnabledPropertiesChanged(QString, QVariantMap, QStringList)));
}
// DSL
if (m_flags.testFlags(NetType::NetManagerFlag::Net_DSL)) {
NetDSLControlItemPrivate *vpnControlItem = NetItemNew(DSLControlItem, "NetDSLControlItem");
vpnControlItem->updatename("DSL");
vpnControlItem->updateenabled(networkController->vpnController()->enabled());
vpnControlItem->item()->moveToThread(m_parentThread);
Q_EMIT itemAdded("Root", vpnControlItem);
networkController->dslController()->connectItem("");
// connect(networkController->dslController(), &DSLController::enableChanged, this, &NetManagerThreadPrivate::onVPNEnableChanged);
// connect(networkController->vpnController(), &VPNController::itemChanged, this, vpnItemChanged);
connect(networkController->dslController(), &DSLController::itemAdded, this, &NetManagerThreadPrivate::onDSLAdded);
connect(networkController->dslController(), &DSLController::itemRemoved, this, &NetManagerThreadPrivate::onDSLRemoved);
connect(networkController->dslController(), &DSLController::activeConnectionChanged, this, &NetManagerThreadPrivate::onDslActiveConnectionChanged);
onDSLAdded(networkController->dslController()->items());
}
// Details
if (m_flags.testFlags(NetType::NetManagerFlag::Net_Details)) {
NetDetailsItemPrivate *item = NetItemNew(DetailsItem, "Details");
item->updatename("Details");
item->item()->moveToThread(m_parentThread);
Q_EMIT itemAdded("Root", item);
updateDetails();
// connect(networkController, &NetworkController::deviceAdded, this, &NetManagerThreadPrivate::updateDetails, Qt::QueuedConnection);
// connect(networkController, &NetworkController::deviceRemoved, this, &NetManagerThreadPrivate::updateDetails, Qt::QueuedConnection);
// connect(networkController, &NetworkController::connectivityChanged, this, &NetManagerThreadPrivate::updateDetails, Qt::QueuedConnection);
connect(networkController, &NetworkController::activeConnectionChange, this, &NetManagerThreadPrivate::updateDetails, Qt::QueuedConnection);
}
// 初始化的关键参数,保留格式
qCInfo(DNC) << "Interface Version :" << INTERFACE_VERSION;
qCInfo(DNC) << "Manager Flags :" << m_flags;
qCInfo(DNC) << "Service From NM :" << m_flags.testFlag(NetType::NetManagerFlag::Net_ServiceNM) << "Config:" << ConfigSetting::instance()->serviceFromNetworkManager();
qCInfo(DNC) << "Use Secret Agent :" << m_useSecretAgent;
qCInfo(DNC) << "Secret Agent :" << (dynamic_cast<QObject *>(m_secretAgent));
qCInfo(DNC) << "Auto Scan Interval:" << m_autoScanInterval;
}
void NetManagerThreadPrivate::clearData()
{
// 此函数是在线程中执行,线程中创建的对象应在此delete
if (m_autoScanTimer) {
delete m_autoScanTimer;
m_autoScanTimer = nullptr;
}
if (m_secretAgent) {
delete m_secretAgent;
m_secretAgent = nullptr;
}
NetworkController::free();
}
void NetManagerThreadPrivate::doSetDeviceEnabled(const QString &id, bool enabled)
{
if (id == "NetVPNControlItem") {
NetworkController::instance()->vpnController()->setEnabled(enabled);
return;
}
if (id == "NetSystemProxyControlItem") {
NetworkController::instance()->proxyController()->setProxyMethod(enabled ? ConfigWatcher::instance()->proxyMethod() : ProxyMethod::None);
return;
}
if (id == "NetHotspotControlItem") {
HotspotController *hotspotController = NetworkController::instance()->hotspotController();
for (auto dev : hotspotController->devices()) {
hotspotController->setEnabled(dev, enabled);
}
return;
}
for (NetworkDeviceBase *device : NetworkController::instance()->devices()) {
if (device->path() == id) {
device->setEnabled(enabled);
break;
}
}
}
void NetManagerThreadPrivate::doRequestScan(const QString &id)
{
for (NetworkDeviceBase *device : NetworkController::instance()->devices()) {
if (device->path() == id) {
WirelessDevice *wirelessDevice = qobject_cast<WirelessDevice *>(device);
if (wirelessDevice)
wirelessDevice->scanNetwork();
break;
}
}
}
void NetManagerThreadPrivate::doDisconnectDevice(const QString &id)
{
for (NetworkDeviceBase *device : NetworkController::instance()->devices()) {
if (device->path() == id) {
NetworkDeviceBase *netDevice = qobject_cast<NetworkDeviceBase *>(device);
if (netDevice)
netDevice->disconnectNetwork();
break;
}
}
}
void NetManagerThreadPrivate::doConnectHidden(const QString &id, const QString &ssid)
{
QList<NetworkDeviceBase *> devices = NetworkController::instance()->devices();
auto it = std::find_if(devices.begin(), devices.end(), [id](NetworkDeviceBase *dev) {
return dev->path() == id;
});
if (it == devices.end())
return;
WirelessDevice *wirelessDevice = qobject_cast<WirelessDevice *>(*it);
qCInfo(DNC) << "Wireless connect hidden, id: " << id << "ssid: " << ssid << "wireless device: " << wirelessDevice;
if (!wirelessDevice)
return;
NetWirelessConnect wConnect(wirelessDevice, nullptr, this);
wConnect.setSsid(ssid);
wConnect.initConnection();
wConnect.connectNetwork();
}
void NetManagerThreadPrivate::doConnectWired(const QString &id, const QVariantMap ¶m)
{
Q_UNUSED(param)
QStringList ids = id.split(":");
if (ids.size() != 2)
return;
for (NetworkDeviceBase *device : NetworkController::instance()->devices()) {
if (device->path() == ids.first()) {
WiredDevice *netDevice = qobject_cast<WiredDevice *>(device);
for (auto &&conn : netDevice->items()) {
if (conn->connection() && conn->connection()->path() == ids.at(1)) {
qCInfo(DNC) << "Connect wired, device name: " << netDevice->deviceName() << "connection name: " << conn->connection()->id();
netDevice->connectNetwork(conn);
}
}
break;
}
}
}
void NetManagerThreadPrivate::doConnectWireless(const QString &id, const QVariantMap ¶m)
{
WirelessDevice *wirelessDevice = nullptr;
AccessPoints *ap = nullptr;
for (NetworkDeviceBase *device : NetworkController::instance()->devices()) {
if (device->deviceType() == DeviceType::Wireless) {
WirelessDevice *wirelessDev = qobject_cast<WirelessDevice *>(device);
for (auto &&tmpAp : wirelessDev->accessPointItems()) {
if (apID(tmpAp) == id) {
wirelessDevice = wirelessDev;
ap = tmpAp;
break;
}
}
if (ap)
break;
}
}
if (!wirelessDevice || !ap)
return;
qCInfo(DNC) << "Connect wireless, device name: " << wirelessDevice->deviceName() << "access point ssid: " << ap->ssid();
if (m_secretAgent && m_secretAgent->hasTask()) {
QVariantMap errMap;
for (QVariantMap::const_iterator it = param.constBegin(); it != param.constEnd(); ++it) {
if (it.value().toString().isEmpty()) {
errMap.insert(it.key(), QString());
}
}
if (!errMap.isEmpty()) {
sendRequest(NetManager::InputError, id, errMap);
return;
}
m_secretAgent->inputPassword(ap->ssid(), param, true);
sendRequest(NetManager::CloseInput, id);
return;
}
NetWirelessConnect wConnect(wirelessDevice, ap, this);
wConnect.setSsid(ap->ssid());
wConnect.initConnection();
QString secret = wConnect.needSecrets();
if (param.contains(secret)) {
QVariantMap err = wConnect.connectNetworkParam(param);
if (err.isEmpty())
sendRequest(NetManager::CloseInput, id);
else
sendRequest(NetManager::InputError, id, err);
} else if (wConnect.needInputIdentify()) { // 未配置,需要输入Identify
handle8021xAccessPoint(ap);
if (m_network8021XMode != NetManager::ToConnect)
sendRequest(NetManager::CloseInput, id);
} else if (wConnect.needInputPassword()) {
sendRequest(NetManager::RequestPassword, id, { { "secrets", { secret } } });
} else {
wConnect.connectNetwork();
sendRequest(NetManager::CloseInput, id);
}
}
void NetManagerThreadPrivate::doConnectHotspot(const QString &id, const QVariantMap ¶m, bool connect)
{
auto hotspotController = NetworkController::instance()->hotspotController();
QString uuid = param.value("uuid").toString();
if (uuid.isEmpty()) {
return;
}
for (auto dev : hotspotController->devices()) {
for (auto item : hotspotController->items(dev)) {
if (item->connection()->uuid() == uuid) {
if (connect) {
if (item->status() != ConnectionStatus::Activated && item->status() != ConnectionStatus::Activating) {
hotspotController->connectItem(item);
}
} else {
if (item->status() == ConnectionStatus::Activated || item->status() == ConnectionStatus::Activating) {
hotspotController->disconnectItem(dev);
}
}
break;
}
}
}
}
void NetManagerThreadPrivate::doGotoControlCenter(const QString &page)
{
if (!m_enabled)
return;
QDBusMessage message = QDBusMessage::createMethodCall("com.deepin.dde.ControlCenter", "/com/deepin/dde/ControlCenter", "com.deepin.dde.ControlCenter", "ShowPage");
message << "network" << page;
QDBusConnection::sessionBus().asyncCall(message);
Q_EMIT toControlCenter();
}
void NetManagerThreadPrivate::doGotoSecurityTools(const QString &page)
{
if (!m_enabled)
return;
QDBusMessage message = QDBusMessage::createMethodCall("com.deepin.defender.hmiscreen", "/com/deepin/defender/hmiscreen", "com.deepin.defender.hmiscreen", "ShowPage");
message << "securitytools" << page;
QDBusConnection::sessionBus().asyncCall(message);
}
void NetManagerThreadPrivate::doUserCancelRequest(const QString &id)
{
if (id.isEmpty()) {
m_secretAgent->inputPassword(QString(), {}, false);
return;
}
// 暂只处理无线
WirelessDevice *wirelessDevice = nullptr;
AccessPoints *ap = nullptr;
for (NetworkDeviceBase *device : NetworkController::instance()->devices()) {
if (device->deviceType() != DeviceType::Wireless)
continue;
WirelessDevice *wirelessDev = qobject_cast<WirelessDevice *>(device);
for (auto &&tmpAp : wirelessDev->accessPointItems()) {
if (apID(tmpAp) == id) {
wirelessDevice = wirelessDev;
ap = tmpAp;
break;
}
}
if (ap)
break;
}
if (!wirelessDevice || !ap)
return;
m_secretAgent->inputPassword(ap->ssid(), {}, false);
}
void NetManagerThreadPrivate::doRetranslate(const QString &locale)
{
NetworkController::instance()->retranslate(locale);
}
void NetManagerThreadPrivate::updateNetCheckAvailabled(const QDBusVariant &availabled)
{
if (m_netCheckAvailable != availabled.variant().toBool()) {
m_netCheckAvailable = availabled.variant().toBool();
Q_EMIT netCheckAvailableChanged(m_netCheckAvailable);
}
}
void NetManagerThreadPrivate::updateAirplaneModeEnabled(const QDBusVariant &enabled)
{
m_airplaneModeEnabled = enabled.variant().toBool() && supportAirplaneMode();
Q_EMIT dataChanged(DataChanged::EnabledChanged, "Root", QVariant(m_airplaneModeEnabled));
}
void NetManagerThreadPrivate::updateAirplaneModeEnabledable(const QDBusVariant &enabledable)
{
bool airplaneEnabledable = enabledable.variant().toBool();
Q_EMIT dataChanged(DataChanged::DeviceAvailableChanged, "Root", QVariant(airplaneEnabledable));
}
bool NetManagerThreadPrivate::supportAirplaneMode() const
{
// dde-dconfig配置优先级高于设备优先级
if (!ConfigSetting::instance()->networkAirplaneMode()) {
return false;
}
NetworkManager::Device::List devices = NetworkManager::networkInterfaces();
for (NetworkManager::Device::Ptr device : devices) {
if (device->type() == NetworkManager::Device::Type::Wifi && device->managed())
return true;
}
return false;
}
void NetManagerThreadPrivate::doConnectOrInfo(const QString &id, NetType::NetItemType type, const QVariantMap ¶m)
{
switch (type) {
case NetType::WiredItem:
doConnectWired(id, param);
break;
case NetType::WirelessItem: {
AccessPoints *ap = fromApID(id);
if (!ap) {
qCWarning(DNC) << "not find AccessPoint";
return;
}
QString devPath = ap->devicePath();
NetworkManager::WirelessDevice *netDevice = qobject_cast<NetworkManager::WirelessDevice *>(NetworkManager::findNetworkInterface(devPath).get());
if (!netDevice) {
qCWarning(DNC) << "not find Device";
return;
}
ConnectionSettings::Ptr settings;
for (const NetworkManager::Connection::Ptr &con : netDevice->availableConnections()) {
NetworkManager::WirelessSetting::Ptr wSetting = con->settings()->setting(NetworkManager::Setting::SettingType::Wireless).staticCast<NetworkManager::WirelessSetting>();
if (wSetting->ssid() != ap->ssid()) {
continue;
}
settings = con->settings();
WirelessSecuritySetting::Ptr const sSetting = settings->setting(Setting::SettingType::WirelessSecurity).staticCast<WirelessSecuritySetting>();
sSetting->secretsFromMap(con->secrets(sSetting->name()).value().value(sSetting->name()));
QDBusPendingReply<QDBusObjectPath> reply = NetworkManager::activateConnection(con->path(), devPath, ap->path());
if (reply.isError()) {
qCWarning(DNC) << "activateConnection fiald:" << reply.error().message();
}
break;
}
if (settings.isNull()) {
AccessPoint::Ptr nmAp = netDevice->findAccessPoint(ap->path());
if (nmAp.isNull()) {
qCWarning(DNC) << "not find NetworkManager AccessPoint";
return;
}
WirelessSecuritySetting::KeyMgmt keyMgmt = getKeyMgmtByAp(nmAp.get());
if (keyMgmt == WirelessSecuritySetting::WpaNone) {
NetworkManager::ConnectionSettings::Ptr settings = NetworkManager::ConnectionSettings::Ptr(new ConnectionSettings(ConnectionSettings::Wireless));
settings->setId(ap->ssid());
settings->setting(Setting::SettingType::Wireless).staticCast<WirelessSetting>()->setSsid(ap->ssid().toUtf8());
settings->setting(Setting::SettingType::Wireless).staticCast<WirelessSetting>()->setInitialized(true);
QString uuid = settings->createNewUuid();
while (findConnectionByUuid(uuid)) {
qint64 second = QDateTime::currentDateTime().toSecsSinceEpoch();
uuid.replace(24, QString::number(second).length(), QString::number(second));
}
settings->setUuid(uuid);
QDBusPendingReply<QDBusObjectPath, QDBusObjectPath> reply = NetworkManager::addAndActivateConnection(settings->toMap(), devPath, ap->path());
if (reply.isError()) {
qCWarning(DNC) << "activateConnection fiald:" << reply.error().message();
}
break;
} else {
doGetConnectInfo(id, type, param);
}
}
} break;
case NetType::ConnectionItem: {
NetworkManager::Connection::Ptr conn = findConnection(id);
if (conn) {
QString devicePath;
NetworkManager::isNetworkingEnabled();
for (NetworkManager::Device::Ptr device : NetworkManager::networkInterfaces()) {
NetworkManager::Connection::List connections = device->availableConnections();
NetworkManager::Connection::List::iterator itConnection = std::find_if(connections.begin(), connections.end(), [conn](NetworkManager::Connection::Ptr connection) {
return connection->path() == conn->path();
});
if (itConnection != connections.end()) {
devicePath = device->uni();
break;
}
}
QDBusPendingReply<QDBusObjectPath> reply = NetworkManager::activateConnection(conn->path(), devicePath, QString());
if (reply.isError()) {
qCWarning(DNC) << "activateConnection fiald:" << reply.error().message();
}
}
} break;
default:
doGetConnectInfo(id, type, param);
break;
}
}
void NetManagerThreadPrivate::doGetConnectInfo(const QString &id, NetType::NetItemType type, const QVariantMap ¶m)
{
switch (type) {
case NetType::WiredDeviceItem: // 新建有线网络
for (NetworkDeviceBase *device : NetworkController::instance()->devices()) {
if (device->path() == id) {
NetworkManager::ConnectionSettings::Ptr settings = NetworkManager::ConnectionSettings::Ptr(new ConnectionSettings(ConnectionSettings::Wired));
QString connName = connectionSuffixNum(tr("Wired Connection %1"));
Security8021xSetting::Ptr securitySettings = settings->setting(Setting::Security8021x).dynamicCast<Security8021xSetting>();
// if (securitySettings) {
// securitySettings->setSupportCertifiedEscape(dde::network::ConfigSetting::instance()->supportCertifiedEscape());
// }
settings->setId(connName);
QVariantMap retParam;
const NMVariantMapMap &settingsMap = settings->toMap();
for (auto it = settingsMap.cbegin(); it != settingsMap.cend(); it++) {
retParam.insert(it.key(), it.value());
}
QString mac = device->realHwAdr();
if (mac.isEmpty()) {
mac = device->usingHwAdr();
}
mac = mac + " (" + device->interface() + ")";
QVariantMap typeMap = retParam[settingsMap["connection"]["type"].toString()].value<QVariantMap>();
typeMap.insert("optionalDevice", QStringList(mac));
retParam[settingsMap["connection"]["type"].toString()] = typeMap;
Q_EMIT request(NetManager::ConnectInfo, id, retParam);
}
}
break;
case NetType::WiredItem: {
QStringList ids = id.split(":");
if (ids.size() != 2)
return;
for (NetworkDeviceBase *device : NetworkController::instance()->devices()) {
if (device->path() == ids.first()) {
WiredDevice *netDevice = qobject_cast<WiredDevice *>(device);
for (auto &&conn : netDevice->items()) {
if (conn->connection() && conn->connection()->path() == ids.at(1)) {
qCInfo(DNC) << "ConnectInfo wired, device name: " << netDevice->deviceName() << "connection name: " << conn->connection()->id()
<< "connection uuid: " << conn->connection()->uuid();
auto connection = findConnectionByUuid(conn->connection()->uuid());
if (!connection) {
qCWarning(DNC) << "Can not find connection by uuid, uuid: " << conn->connection()->uuid();
return;
}
auto connectionSettings = connection->settings();
Setting::SettingType sType = Setting::SettingType::Security8021x;
QSharedPointer<Security8021xSetting> sSetting = connectionSettings->setting(sType).staticCast<Security8021xSetting>();
// if (!sSetting->eapMethods().isEmpty()) {
sSetting->secretsFromMap(connection->secrets(sSetting->name()).value().value(sSetting->name()));
// }
QVariantMap retParam;
const NMVariantMapMap &settingsMap = connectionSettings->toMap();
for (auto it = settingsMap.cbegin(); it != settingsMap.cend(); it++) {
retParam.insert(it.key(), it.value());
}
// 可选设备
QString mac = netDevice->realHwAdr();
if (mac.isEmpty()) {
mac = netDevice->usingHwAdr();
}
mac = mac + " (" + netDevice->interface() + ")";
QVariantMap typeMap = retParam[settingsMap["connection"]["type"].toString()].value<QVariantMap>();
typeMap.insert("optionalDevice", QStringList(mac));
retParam[settingsMap["connection"]["type"].toString()] = typeMap;
Ipv6Setting::Ptr ipv6 = connectionSettings->setting(Setting::Ipv6).dynamicCast<Ipv6Setting>();
connection->path();
if (ipv6->method() == Ipv6Setting::Manual) {
// ipv6 gateway未获取,自己获取下
auto msg = QDBusMessage::createMethodCall("org.freedesktop.NetworkManager", connection->path(), "org.freedesktop.NetworkManager.Settings.Connection", "GetSettings");