Ticket #1608: 1608.patch

File 1608.patch, 6.5 KB (added by sascha_silbe, 14 years ago)

fix network disconnect and discard buttons (quozl)

  • extensions/deviceicon/network.py

    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): 
    508508        self._icon.props.base_color = self._color
    509509
    510510    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
    511516        if self._active_ap_op is not None:
    512517            obj = self._bus.get_object(_NM_SERVICE, _NM_PATH)
    513518            netmgr = dbus.Interface(obj, _NM_IFACE)
  • src/jarabe/desktop/meshbox.py

    diff --git a/src/jarabe/desktop/meshbox.py b/src/jarabe/desktop/meshbox.py
    index a04922b..d3c1dea 100644
    a b class WirelessNetworkView(CanvasPulsingIcon): 
    267267            self.props.base_color = self._color
    268268
    269269    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)
    271298
    272299    def _add_ciphers_from_flags(self, flags, pairwise):
    273300        ciphers = []
    class WirelessNetworkView(CanvasPulsingIcon): 
    373400                                  error_handler=self.__activate_error_cb)
    374401
    375402    def __activate_reply_cb(self, connection):
     403        self._connection = connection
    376404        logging.debug('Connection activated: %s', connection)
    377405
    378406    def __activate_error_cb(self, err):
  • src/jarabe/model/network.py

    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): 
    330330        self.secrets_request.send(self, connection=sender,
    331331                                  response=kwargs['response'])
    332332
     333    def clear_connections(self):
     334        for connection in self.connections.values():
     335            connection.Removed()
     336        self.connections = {}
     337
    333338class SecretsResponse(object):
    334339    ''' Intermediate object to report the secrets from the dialog
    335340    back to the connection object and which will inform NM
    class NMSettingsConnection(dbus.service.Object): 
    358363        self._settings = settings
    359364        self._secrets = secrets
    360365
     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
    361376    def set_connected(self):
    362377        if self._settings.connection.type == NM_CONNECTION_TYPE_GSM:
    363378            self._settings.connection.timestamp = int(time.time())
    class NMSettingsConnection(dbus.service.Object): 
    366381                self._settings.connection.autoconnect = True
    367382                self._settings.connection.timestamp = int(time.time())
    368383                if self._settings.connection.type == NM_CONNECTION_TYPE_802_11_WIRELESS:
     384                    self.Updated(self._settings.get_dict())
    369385                    self.save()
    370386
     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
    371394    def set_secrets(self, secrets):
    372395        self._secrets = secrets
    373396        if self._settings.connection.type == NM_CONNECTION_TYPE_802_11_WIRELESS:
    class NMSettingsConnection(dbus.service.Object): 
    454477        else:
    455478            reply(self._secrets.get_dict())
    456479
    457 
    458480class AccessPoint(gobject.GObject):
    459481    __gsignals__ = {
    460482        'props-changed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
    def load_wifi_connections(): 
    659681
    660682
    661683def clear_networks():
    662     global _nm_settings
    663     _nm_settings = None
     684    _nm_settings.clear_connections()
    664685
    665686    profile_path = env.get_profile_path()
    666687    config_path = os.path.join(profile_path, 'nm', 'connections.cfg')