@@ -59,33 +59,13 @@ void NMWirelessNetwork::updateReferenceConnection() {
5959 }
6060}
6161
62- void NMWirelessNetwork::setActiveApPath (const QDBusObjectPath& path) {
63- if (this ->mActiveApPath == path) return ;
64- this ->mActiveApPath = path;
65- }
66-
67- void NMWirelessNetwork::setState (NMConnectionState::Enum state) {
68- if (this ->bState == state) return ;
69- this ->bState = state;
70- }
71-
72- void NMWirelessNetwork::setReason (NMConnectionStateReason::Enum reason) {
73- if (this ->bReason == reason) return ;
74- this ->bReason = reason;
75- };
76-
77- void NMWirelessNetwork::setCaps (NMWirelessCapabilities::Enum caps) {
78- if (this ->mCaps == caps) return ;
79- this ->mCaps = caps;
80- }
81-
8262void NMWirelessNetwork::updateReferenceAp () {
8363 quint8 selectedStrength = 0 ;
8464 NMAccessPoint* selectedAp = nullptr ;
8565
8666 for (auto * ap: this ->mAccessPoints .values ()) {
8767 // Always prefer the active AP if found.
88- if (ap->path () == this ->mActiveApPath . path () ) {
68+ if (ap->path () == this ->bActiveApPath ) {
8969 selectedStrength = ap->signalStrength ();
9070 selectedAp = ap;
9171 break ;
@@ -108,7 +88,7 @@ void NMWirelessNetwork::updateReferenceAp() {
10888 // Reference AP is used for security when there's no connection settings.
10989 if (this ->mReferenceConn ) return ;
11090 auto security = findBestWirelessSecurity (
111- this ->mCaps ,
91+ this ->bCaps ,
11292 this ->mReferenceAp ->mode () == NM80211Mode::Adhoc,
11393 this ->mReferenceAp ->flags (),
11494 this ->mReferenceAp ->wpaFlags (),
@@ -123,12 +103,13 @@ void NMWirelessNetwork::addAccessPoint(NMAccessPoint* ap) {
123103 this ->mAccessPoints .insert (ap->path (), ap);
124104 // clang-format off
125105 QObject::connect (ap, &NMAccessPoint::signalStrengthChanged, this , &NMWirelessNetwork::updateReferenceAp);
126- QObject::connect (ap, &NMAccessPoint::disappeared, this , [ this , ap] { this -> removeAccessPoint (ap); } );
106+ QObject::connect (ap, &NMAccessPoint::disappeared, this , &NMWirelessNetwork:: removeAccessPoint);
127107 // clang-format on
128108 this ->updateReferenceAp ();
129109};
130110
131- void NMWirelessNetwork::removeAccessPoint (NMAccessPoint* ap) {
111+ void NMWirelessNetwork::removeAccessPoint () {
112+ auto * ap = qobject_cast<NMAccessPoint*>(sender ());
132113 if (this ->mAccessPoints .take (ap->path ())) {
133114 if (this ->mAccessPoints .isEmpty ()) {
134115 emit this ->disappeared ();
@@ -143,13 +124,14 @@ void NMWirelessNetwork::addConnectionSettings(NMConnectionSettings* conn) {
143124 if (this ->mConnections .contains (conn->path ())) return ;
144125 this ->mConnections .insert (conn->path (), conn);
145126 // clang-format off
146- QObject::connect (conn, &NMConnectionSettings::disappeared, this , [ this , conn]() { this -> removeConnectionSettings (conn); } );
127+ QObject::connect (conn, &NMConnectionSettings::disappeared, this , &NMWirelessNetwork:: removeConnectionSettings);
147128 // clang-format on
148129 this ->updateReferenceConnection ();
149130 this ->bKnown = true ;
150131};
151132
152- void NMWirelessNetwork::removeConnectionSettings (NMConnectionSettings* conn) {
133+ void NMWirelessNetwork::removeConnectionSettings () {
134+ auto * conn = qobject_cast<NMConnectionSettings*>(sender ());
153135 if (this ->mConnections .take (conn->path ())) {
154136 QObject::disconnect (conn, nullptr , this , nullptr );
155137 this ->updateReferenceConnection ();
@@ -161,18 +143,16 @@ void NMWirelessNetwork::removeConnectionSettings(NMConnectionSettings* conn) {
161143
162144void NMWirelessNetwork::addActiveConnection (NMActiveConnection* active) {
163145 if (this ->mActiveConnection ) return ;
164-
165- this ->bState = active->state ();
166- this ->bReason = active->stateReason ();
167146 this ->mActiveConnection = active;
147+ this ->bState .setBinding ([active]() { return active->state (); });
148+ this ->bReason .setBinding ([active]() { return active->stateReason (); });
168149 // clang-format off
169- QObject::connect (active, &NMActiveConnection::stateChanged, this , &NMWirelessNetwork::setState);
170- QObject::connect (active, &NMActiveConnection::stateReasonChanged, this , &NMWirelessNetwork::setReason);
171- QObject::connect (active, &NMActiveConnection::disappeared, this , [this , active] { this ->removeActiveConnection (active); });
150+ QObject::connect (active, &NMActiveConnection::disappeared, this , &NMWirelessNetwork::removeActiveConnection);
172151 // clang-format on
173152};
174153
175- void NMWirelessNetwork::removeActiveConnection (NMActiveConnection* active) {
154+ void NMWirelessNetwork::removeActiveConnection () {
155+ auto * active = qobject_cast<NMActiveConnection*>(sender ());
176156 if (this ->mActiveConnection && this ->mActiveConnection == active) {
177157 QObject::disconnect (active, nullptr , this , nullptr );
178158 this ->bState = NMConnectionState::Deactivated;
@@ -281,25 +261,15 @@ void NMWirelessDevice::registerAccessPoint(const QString& path) {
281261NMWirelessNetwork* NMWirelessDevice::registerNetwork (const QString& ssid) {
282262 // clang-format off
283263 auto * backend = new NMWirelessNetwork (ssid, this );
284- backend->setActiveApPath (this ->activeApPath ());
285- backend->setCaps (this ->capabilities ());
286- QObject::connect (this , &NMWirelessDevice::activeAccessPointChanged, backend, &NMWirelessNetwork::setActiveApPath);
287- QObject::connect (this , &NMWirelessDevice::capabilitiesChanged, backend, &NMWirelessNetwork::setCaps);
264+ backend->bindableActiveApPath ().setBinding ([this ]() { return this ->activeApPath ().path (); });
265+ backend->bindableCapabilities ().setBinding ([this ]() { return this ->capabilities (); });
288266
289267 auto * frontend = new WifiNetwork (ssid, this );
290- frontend->setSignalStrength (backend->signalStrength ());
291- frontend->setConnected (backend->state () != NMConnectionState::Deactivated);
292- frontend->setKnown (backend->known ());
293- frontend->setNmReason (backend->reason ());
294- frontend->setNmSecurity (backend->security ());
295- QObject::connect (backend, &NMWirelessNetwork::signalStrengthChanged, frontend, &WifiNetwork::setSignalStrength);
296- QObject::connect (backend, &NMWirelessNetwork::knownChanged, frontend, &WifiNetwork::setKnown);
297- QObject::connect (backend, &NMWirelessNetwork::reasonChanged, frontend, &WifiNetwork::setNmReason);
298- QObject::connect (backend, &NMWirelessNetwork::securityChanged, frontend, &WifiNetwork::setNmSecurity);
299- QObject::connect (backend, &NMWirelessNetwork::stateChanged, frontend,
300- [frontend](NMConnectionState::Enum state) { frontend->setConnected (state != NMConnectionState::Deactivated ); }
301- );
302- // clang-format on
268+ frontend->bindableSignalStrength ().setBinding ([backend]() { return backend->signalStrength (); });
269+ frontend->bindableConnected ().setBinding ([backend]() { return backend->state () != NMConnectionState::Deactivated; });
270+ frontend->bindableKnown ().setBinding ([backend]() { return backend->known (); });
271+ frontend->bindableNmReason ().setBinding ([backend]() { return backend->reason (); });
272+ frontend->bindableNmSecurity ().setBinding ([backend]() { return backend->security (); });
303273 QObject::connect (backend, &NMWirelessNetwork::disappeared, this , [this , frontend, backend]() {
304274 QObject::disconnect (backend, nullptr , nullptr , nullptr );
305275 emit this ->wifiNetworkRemoved (frontend);
0 commit comments