@@ -46,13 +46,44 @@ NMDeviceAdapter::NMDeviceAdapter(const QString& path, QObject* parent): QObject(
4646
4747 // clang-format off
4848 QObject::connect (this , &NMDeviceAdapter::availableConnectionsChanged, this , &NMDeviceAdapter::onAvailableConnectionsChanged);
49+ QObject::connect (this , &NMDeviceAdapter::activeConnectionChanged, this , &NMDeviceAdapter::onActiveConnectionChanged);
4950 QObject::connect (&this ->deviceProperties , &DBusPropertyGroup::getAllFinished, this , [this ]() { emit this ->ready (); }, Qt::SingleShotConnection);
5051 // clang-format on
5152
5253 this ->deviceProperties .setInterface (this ->proxy );
5354 this ->deviceProperties .updateAllViaGetAll ();
5455}
5556
57+ void NMDeviceAdapter::onActiveConnectionChanged (const QDBusObjectPath& path) {
58+ QString stringPath = path.path ();
59+ if (this ->mActiveConnection ) {
60+ QObject::disconnect (this ->mActiveConnection , nullptr , this , nullptr );
61+ emit this ->activeConnectionRemoved (this ->mActiveConnection );
62+ delete this ->mActiveConnection ;
63+ this ->mActiveConnection = nullptr ;
64+ }
65+
66+ if (stringPath != " /" ) {
67+ auto * active = new NMActiveConnectionAdapter (stringPath, this );
68+ this ->mActiveConnection = active;
69+ qCDebug (logNetworkManager) << " Registered active connection" << stringPath;
70+
71+ QObject::connect (
72+ active,
73+ &NMActiveConnectionAdapter::ready,
74+ this ,
75+ [this , active]() {
76+ QString path = active->connection ().path ();
77+ if (!this ->mConnectionMap .contains (path)) {
78+ this ->registerConnection (path);
79+ }
80+ emit this ->activeConnectionLoaded (active);
81+ },
82+ Qt::SingleShotConnection
83+ );
84+ }
85+ }
86+
5687void NMDeviceAdapter::onAvailableConnectionsChanged (const QList<QDBusObjectPath>& paths) {
5788 QSet<QString> newConnectionPaths;
5889 for (const QDBusObjectPath& path: paths) {
@@ -62,21 +93,7 @@ void NMDeviceAdapter::onAvailableConnectionsChanged(const QList<QDBusObjectPath>
6293 QSet<QString> addedConnections = newConnectionPaths - this ->mConnectionPaths ;
6394 QSet<QString> removedConnections = this ->mConnectionPaths - newConnectionPaths;
6495 for (const QString& path: addedConnections) {
65- auto * connection = new NMConnectionAdapter (path, this );
66- if (!connection->isValid ()) {
67- qCWarning (logNetworkManager) << " Ignoring invalid registration of" << path;
68- delete connection;
69- } else {
70- this ->mConnectionMap .insert (path, connection);
71- QObject::connect (
72- connection,
73- &NMConnectionAdapter::ready,
74- this ,
75- [this , connection]() { emit this ->connectionLoaded (connection); },
76- Qt::SingleShotConnection
77- );
78- qCDebug (logNetworkManager) << " Registered connection" << path;
79- }
96+ registerConnection (path);
8097 }
8198 for (const QString& path: removedConnections) {
8299 auto * connection = this ->mConnectionMap .take (path);
@@ -87,9 +104,29 @@ void NMDeviceAdapter::onAvailableConnectionsChanged(const QList<QDBusObjectPath>
87104 emit this ->connectionRemoved (connection);
88105 delete connection;
89106 }
107+ this ->mConnectionPaths .remove (path);
90108 };
91109}
92110
111+ void NMDeviceAdapter::registerConnection (const QString& path) {
112+ auto * connection = new NMConnectionSettingsAdapter (path, this );
113+ if (!connection->isValid ()) {
114+ qCWarning (logNetworkManager) << " Ignoring invalid registration of" << path;
115+ delete connection;
116+ } else {
117+ this ->mConnectionMap .insert (path, connection);
118+ this ->mConnectionPaths .insert (path);
119+ QObject::connect (
120+ connection,
121+ &NMConnectionSettingsAdapter::ready,
122+ this ,
123+ [this , connection]() { emit this ->connectionLoaded (connection); },
124+ Qt::SingleShotConnection
125+ );
126+ qCDebug (logNetworkManager) << " Registered connection" << path;
127+ }
128+ }
129+
93130void NMDeviceAdapter::disconnect () { this ->proxy ->Disconnect (); }
94131bool NMDeviceAdapter::isValid () const { return this ->proxy && this ->proxy ->isValid (); }
95132QString NMDeviceAdapter::address () const {
0 commit comments