From: Sascha Silbe <sascha-pgp@silbe.org>
Subject: [PATCH] fix network disconnect and discard buttons (quozl) (SL#1608)
Original patch from James Cameron <quozl@laptop.org>.
Implement missing neighbourhood view access point disconnect button, by
turning off the autoconnect flag for the connection and requesting
disconnect. Disconnection was not implemented.
Fix frame access point disconnect button, by turning off the autoconnect
flag for the connection. Disconnection was already being requested but
the autoconnect flag was causing an immediate reconnection.
On network history discard, advise NetworkManager that the connections
are deleted in order to ensure the network connection collapses.
Properly advise NetworkManager when the autoconnect setting is
set or cleared.
Tested on XO-1 with two access points (one using WPA2, one unsecured).
Signed-off-by: Sascha Silbe <sascha-pgp@silbe.org>
---
extensions/deviceicon/network.py | 5 +++++
src/jarabe/desktop/meshbox.py | 30 +++++++++++++++++++++++++++++-
src/jarabe/model/network.py | 27 ++++++++++++++++++++++++---
3 files changed, 58 insertions(+), 4 deletions(-)
diff --git a/extensions/deviceicon/network.py b/extensions/deviceicon/network.py
index 94a4293..831c35c 100644
a
|
b
|
class WirelessDeviceView(ToolButton): |
508 | 508 | self._icon.props.base_color = self._color |
509 | 509 | |
510 | 510 | def __deactivate_connection_cb(self, palette, data=None): |
| 511 | connection = network.find_connection_by_ssid(self._name) |
| 512 | if connection: |
| 513 | if self._mode == network.NM_802_11_MODE_INFRA: |
| 514 | connection.set_disconnected() |
| 515 | |
511 | 516 | if self._active_ap_op is not None: |
512 | 517 | obj = self._bus.get_object(_NM_SERVICE, _NM_PATH) |
513 | 518 | netmgr = dbus.Interface(obj, _NM_IFACE) |
diff --git a/src/jarabe/desktop/meshbox.py b/src/jarabe/desktop/meshbox.py
index a04922b..d3c1dea 100644
a
|
b
|
class WirelessNetworkView(CanvasPulsingIcon): |
267 | 267 | self.props.base_color = self._color |
268 | 268 | |
269 | 269 | def _disconnect_activate_cb(self, item): |
270 | | pass |
| 270 | connection = network.find_connection_by_ssid(self._name) |
| 271 | if connection: |
| 272 | if self._mode == network.NM_802_11_MODE_INFRA: |
| 273 | connection.set_disconnected() |
| 274 | |
| 275 | obj = self._bus.get_object(_NM_SERVICE, _NM_PATH) |
| 276 | netmgr = dbus.Interface(obj, _NM_IFACE) |
| 277 | |
| 278 | if self._connection is not None: |
| 279 | netmgr.DeactivateConnection(self._connection) |
| 280 | return |
| 281 | |
| 282 | netmgr_props = dbus.Interface(netmgr, 'org.freedesktop.DBus.Properties') |
| 283 | active_connections_o = netmgr_props.Get(_NM_IFACE, 'ActiveConnections') |
| 284 | |
| 285 | for conn_o in active_connections_o: |
| 286 | obj = self._bus.get_object(_NM_IFACE, conn_o) |
| 287 | props = dbus.Interface(obj, 'org.freedesktop.DBus.Properties') |
| 288 | state = props.Get(_NM_ACTIVE_CONN_IFACE, 'State') |
| 289 | if state == network.NM_ACTIVE_CONNECTION_STATE_ACTIVATED: |
| 290 | ap_o = props.Get(_NM_ACTIVE_CONN_IFACE, 'SpecificObject') |
| 291 | found = False |
| 292 | if ap_o != '/' and self.find_ap(ap_o) is not None: |
| 293 | found = True |
| 294 | netmgr.DeactivateConnection(conn_o) |
| 295 | if not found: |
| 296 | logging.error('Could not determine AP for' |
| 297 | ' specific object %s' % conn_o) |
271 | 298 | |
272 | 299 | def _add_ciphers_from_flags(self, flags, pairwise): |
273 | 300 | ciphers = [] |
… |
… |
class WirelessNetworkView(CanvasPulsingIcon): |
373 | 400 | error_handler=self.__activate_error_cb) |
374 | 401 | |
375 | 402 | def __activate_reply_cb(self, connection): |
| 403 | self._connection = connection |
376 | 404 | logging.debug('Connection activated: %s', connection) |
377 | 405 | |
378 | 406 | def __activate_error_cb(self, err): |
diff --git a/src/jarabe/model/network.py b/src/jarabe/model/network.py
index 82a7e7d..3fa2c89 100644
a
|
b
|
class NMSettings(dbus.service.Object): |
330 | 330 | self.secrets_request.send(self, connection=sender, |
331 | 331 | response=kwargs['response']) |
332 | 332 | |
| 333 | def clear_connections(self): |
| 334 | for connection in self.connections.values(): |
| 335 | connection.Removed() |
| 336 | self.connections = {} |
| 337 | |
333 | 338 | class SecretsResponse(object): |
334 | 339 | ''' Intermediate object to report the secrets from the dialog |
335 | 340 | back to the connection object and which will inform NM |
… |
… |
class NMSettingsConnection(dbus.service.Object): |
358 | 363 | self._settings = settings |
359 | 364 | self._secrets = secrets |
360 | 365 | |
| 366 | @dbus.service.signal(dbus_interface=NM_CONNECTION_IFACE, |
| 367 | signature='') |
| 368 | def Removed(self): |
| 369 | pass |
| 370 | |
| 371 | @dbus.service.signal(dbus_interface=NM_CONNECTION_IFACE, |
| 372 | signature='a{sa{sv}}') |
| 373 | def Updated(self, settings): |
| 374 | pass |
| 375 | |
361 | 376 | def set_connected(self): |
362 | 377 | if self._settings.connection.type == NM_CONNECTION_TYPE_GSM: |
363 | 378 | self._settings.connection.timestamp = int(time.time()) |
… |
… |
class NMSettingsConnection(dbus.service.Object): |
366 | 381 | self._settings.connection.autoconnect = True |
367 | 382 | self._settings.connection.timestamp = int(time.time()) |
368 | 383 | if self._settings.connection.type == NM_CONNECTION_TYPE_802_11_WIRELESS: |
| 384 | self.Updated(self._settings.get_dict()) |
369 | 385 | self.save() |
370 | 386 | |
| 387 | def set_disconnected(self): |
| 388 | if self._settings.connection.autoconnect: |
| 389 | self._settings.connection.autoconnect = False |
| 390 | self._settings.connection.timestamp = None |
| 391 | self.Updated(self._settings.get_dict()) |
| 392 | self.save() |
| 393 | |
371 | 394 | def set_secrets(self, secrets): |
372 | 395 | self._secrets = secrets |
373 | 396 | if self._settings.connection.type == NM_CONNECTION_TYPE_802_11_WIRELESS: |
… |
… |
class NMSettingsConnection(dbus.service.Object): |
454 | 477 | else: |
455 | 478 | reply(self._secrets.get_dict()) |
456 | 479 | |
457 | | |
458 | 480 | class AccessPoint(gobject.GObject): |
459 | 481 | __gsignals__ = { |
460 | 482 | 'props-changed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, |
… |
… |
def load_wifi_connections(): |
659 | 681 | |
660 | 682 | |
661 | 683 | def clear_networks(): |
662 | | global _nm_settings |
663 | | _nm_settings = None |
| 684 | _nm_settings.clear_connections() |
664 | 685 | |
665 | 686 | profile_path = env.get_profile_path() |
666 | 687 | config_path = os.path.join(profile_path, 'nm', 'connections.cfg') |