[Sugar-devel] [DESIGN] [PATCH sugar] Add support for removing connections / forgetting network credentials
Gary Martin
garycmartin at googlemail.com
Sun Jun 26 22:15:41 EDT 2011
On 26 Jun 2011, at 20:38, Sascha Silbe <silbe at activitycentral.com> wrote:
> Let the user remove the settings for individual networks in addition to the
> all-or-nothing approach "Discard network history" in the Control Panel.
>
> Signed-off-by: Sascha Silbe <silbe at activitycentral.com>
> ---
> First shot at the "Forget this favourite network" option we discussed
> at [1]. There's a screenshot at [2]. What do you think of it?
Thanks for the screen shot. Looks good to me. Question: If I forget a network I'm currently connected to, does the code path also disconnect from it? I think it should forget and disconnect (if it isn't already, I skimmed the patch but it wasn't obvious if a disconnect is also triggered).
--Gary
> Do we want to expose this easy way to destroy your network
> configuration, barring you from further access until you reentered the
> credentials? OTOH the "Discard network history" button is even worse in
> this respect, albeit a bit more hidden. In the long run we should
> version all configuration changes (pervasive undo/redo), but we're not
> there yet.
>
> Regarding implementation details: The backend code is going to die soon
> anyway since NM 0.9 only has system connections.
>
> [1] http://meeting.sugarlabs.org/sugar-meeting/meetings/2011-06-05T16:17:34#i_2671243
> [2] http://wiki.sugarlabs.org/go/File:Sugar-ap-forget.png
>
> src/jarabe/desktop/networkviews.py | 22 ++++++++++++++++++++
> src/jarabe/model/network.py | 39 ++++++++++++++++++++++++++++++++++++
> 2 files changed, 61 insertions(+), 0 deletions(-)
>
> diff --git a/src/jarabe/desktop/networkviews.py b/src/jarabe/desktop/networkviews.py
> index a9fa4d3..da98088 100644
> --- a/src/jarabe/desktop/networkviews.py
> +++ b/src/jarabe/desktop/networkviews.py
> @@ -66,6 +66,7 @@ class WirelessNetworkView(CanvasPulsingIcon):
> self._palette_icon = None
> self._disconnect_item = None
> self._connect_item = None
> + self._forget_item = None
> self._greyed_out = False
> self._name = initial_ap.name
> self._mode = initial_ap.mode
> @@ -142,6 +143,12 @@ class WirelessNetworkView(CanvasPulsingIcon):
> self._disconnect_activate_cb)
> p.menu.append(self._disconnect_item)
>
> + label = glib.markup_escape_text(_('Forget this favorite network'))
> + self._forget_item = MenuItem(label, 'list-remove')
> + self._forget_item.connect('activate',
> + self.__forget_activate_cb)
> + p.menu.append(self._forget_item)
> +
> return p
>
> def __device_state_changed_cb(self, new_state, old_state, reason):
> @@ -217,15 +224,19 @@ class WirelessNetworkView(CanvasPulsingIcon):
> if network.find_connection_by_ssid(self._name) is not None:
> self.props.badge_name = 'emblem-favorite'
> self._palette_icon.props.badge_name = 'emblem-favorite'
> + self._forget_item.show()
> elif self._flags == network.NM_802_11_AP_FLAGS_PRIVACY:
> self.props.badge_name = 'emblem-locked'
> self._palette_icon.props.badge_name = 'emblem-locked'
> + self._forget_item.hide()
> else:
> self.props.badge_name = None
> self._palette_icon.props.badge_name = None
> + self._forget_item.hide()
> else:
> self.props.badge_name = None
> self._palette_icon.props.badge_name = None
> + self._forget_item.hide()
>
> def _update_state(self):
> if self._active_ap is not None:
> @@ -275,6 +286,17 @@ class WirelessNetworkView(CanvasPulsingIcon):
> ap_paths = self._access_points.keys()
> network.disconnect_access_points(ap_paths)
>
> + def __forget_activate_cb(self, item):
> + if self._mode != network.NM_802_11_MODE_INFRA:
> + return
> +
> + connection = network.find_connection_by_ssid(self._name)
> + if not connection:
> + return
> +
> + network.remove_connection(connection)
> + self._update_badge()
> +
> def _add_ciphers_from_flags(self, flags, pairwise):
> ciphers = []
> if pairwise:
> diff --git a/src/jarabe/model/network.py b/src/jarabe/model/network.py
> index f265ae4..f034e77 100644
> --- a/src/jarabe/model/network.py
> +++ b/src/jarabe/model/network.py
> @@ -522,6 +522,41 @@ class NMSettings(dbus.service.Object):
> conn.secrets_request.connect(self.__secrets_request_cb)
> self.NewConnection(conn.path)
>
> + def remove_connection(self, connection):
> + connection_type = connection._settings.connection.type
> + uuid = connection._settings.connection.uuid
> + del self.connections[uuid]
> + if connection_type == NM_CONNECTION_TYPE_802_11_WIRELESS:
> + connection.Removed()
> +
> + self._remove_from_config(connection)
> +
> + def _remove_from_config(self, connection):
> + config_path = _get_wifi_connections_path()
> + config = ConfigParser.ConfigParser()
> +
> + try:
> + if not config.read(config_path):
> + logging.error('Error reading the nm config file')
> + return
> + except ConfigParser.ParsingError:
> + logging.exception('Error reading the nm config file')
> + return
> +
> + identifier = connection._settings.connection.id
> + if identifier not in config.sections():
> + return
> +
> + config.remove_section(identifier)
> +
> + f = open(config_path, 'w')
> + try:
> + config.write(f)
> + except ConfigParser.Error:
> + logging.exception('Can not write %s', config_path)
> +
> + f.close()
> +
> def __secrets_request_cb(self, sender, **kwargs):
> self.secrets_request.send(self, connection=sender,
> response=kwargs['response'])
> @@ -843,6 +878,10 @@ def add_connection(uuid, settings, secrets=None):
> return conn
>
>
> +def remove_connection(connection):
> + _nm_settings.remove_connection(connection)
> +
> +
> def _get_wifi_connections_path():
> profile_path = env.get_profile_path()
> return os.path.join(profile_path, 'nm', 'connections.cfg')
> --
> 1.7.2.5
>
More information about the Sugar-devel
mailing list