From 954dc489c4a75991ccb385efdee41ce3e1777a33 Mon Sep 17 00:00:00 2001
From: James Cameron <quozl@laptop.org>
Date: Wed, 25 Aug 2010 15:49:27 +1000
Subject: [PATCH] fix discard history #1673
User interface changes:
- enable the discard network history button in the network control
panel, which also now forces a disconnect, and will be insensitive
if there are no networks to be discarded, (rather than the button
doing nothing),
Design changes:
- expose trusted access point list count for network control panel,
- changes to the autoconnect connection flag are now cascaded to
NetworkManager using the Updated signal,
- discarding network history is now cascaded to NetworkManager using
the Removed signal,
- factoring of connections.cfg path and empty file creation,
Tested extensively on Sugar 0.84.
Not tested on Sugar 0.88.
References:
http://dev.laptop.org/ticket/9977 (fixes a workaround)
http://bugs.sugarlabs.org/ticket/1673
---
extensions/cpsection/network/model.py | 6 +++-
extensions/cpsection/network/view.py | 8 ++++-
src/jarabe/model/network.py | 58 +++++++++++++++++++++++++++------
3 files changed, 60 insertions(+), 12 deletions(-)
diff --git a/extensions/cpsection/network/model.py b/extensions/cpsection/network/model.py
index e1c3dab..eed0b03 100644
|
a
|
b
|
|
| 17 | 17 | |
| 18 | 18 | import dbus |
| 19 | 19 | from gettext import gettext as _ |
| | 20 | from jarabe.model import network |
| 20 | 21 | import gconf |
| 21 | 22 | |
| 22 | 23 | _NM_SERVICE = 'org.freedesktop.NetworkManager' |
| … |
… |
|
| 116 | 117 | def clear_networks(): |
| 117 | 118 | """Clear saved passwords and network configurations. |
| 118 | 119 | """ |
| 119 | | pass |
| | 120 | network.clear_wifi_connections() |
| | 121 | |
| | 122 | def count_networks(): |
| | 123 | return network.count_wifi_connections() |
| 120 | 124 | |
| 121 | 125 | def get_publish_information(): |
| 122 | 126 | client = gconf.client_get_default() |
diff --git a/extensions/cpsection/network/view.py b/extensions/cpsection/network/view.py
index 588daeb..b0f1336 100644
|
a
|
b
|
|
| 104 | 104 | self._clear_history_button = gtk.Button() |
| 105 | 105 | self._clear_history_button.set_label(_('Discard network history')) |
| 106 | 106 | box_clear_history.pack_start(self._clear_history_button, expand=False) |
| | 107 | if self._model.count_networks() == 0: |
| | 108 | self._clear_history_button.set_sensitive(False) |
| 107 | 109 | self._clear_history_button.show() |
| 108 | 110 | box_wireless.pack_start(box_clear_history, expand=False) |
| 109 | 111 | box_clear_history.show() |
| … |
… |
|
| 217 | 219 | self._radio_alert.props.msg = detail |
| 218 | 220 | self._radio_valid = False |
| 219 | 221 | else: |
| 220 | | self._radio_valid = True |
| | 222 | self._radio_valid = True |
| | 223 | if self._model.count_networks() != 0: |
| | 224 | self._clear_history_button.set_sensitive(True) |
| 221 | 225 | |
| 222 | 226 | self._validate() |
| 223 | 227 | return False |
| … |
… |
|
| 248 | 252 | |
| 249 | 253 | def __network_configuration_reset_cb(self, widget): |
| 250 | 254 | self._model.clear_networks() |
| | 255 | if self._model.count_networks() == 0: |
| | 256 | self._clear_history_button.set_sensitive(False) |
diff --git a/src/jarabe/model/network.py b/src/jarabe/model/network.py
index 66d86d8..2c0afe3 100644
|
a
|
b
|
|
| 508 | 508 | self.secrets_request.send(self, connection=sender, |
| 509 | 509 | response=kwargs['response']) |
| 510 | 510 | |
| | 511 | def clear_wifi_connections(self): |
| | 512 | for uuid in self.connections.keys(): |
| | 513 | conn = self.connections[uuid] |
| | 514 | if conn.type == NM_CONNECTION_TYPE_802_11_WIRELESS: |
| | 515 | conn.Removed() |
| | 516 | self.connections.pop(uuid) |
| | 517 | |
| 511 | 518 | class SecretsResponse(object): |
| 512 | 519 | ''' Intermediate object to report the secrets from the dialog |
| 513 | 520 | back to the connection object and which will inform NM |
| … |
… |
|
| 536 | 543 | self._settings = settings |
| 537 | 544 | self._secrets = secrets |
| 538 | 545 | |
| | 546 | @dbus.service.signal(dbus_interface=NM_CONNECTION_IFACE, |
| | 547 | signature='') |
| | 548 | def Removed(self): |
| | 549 | pass |
| | 550 | |
| | 551 | @dbus.service.signal(dbus_interface=NM_CONNECTION_IFACE, |
| | 552 | signature='a{sa{sv}}') |
| | 553 | def Updated(self, settings): |
| | 554 | pass |
| | 555 | |
| 539 | 556 | def set_connected(self): |
| 540 | 557 | if self._settings.connection.type == NM_CONNECTION_TYPE_GSM: |
| 541 | 558 | self._settings.connection.timestamp = int(time.time()) |
| … |
… |
|
| 544 | 561 | self._settings.connection.autoconnect = True |
| 545 | 562 | self._settings.connection.timestamp = int(time.time()) |
| 546 | 563 | if self._settings.connection.type == NM_CONNECTION_TYPE_802_11_WIRELESS: |
| | 564 | self.Updated(self._settings.get_dict()) |
| 547 | 565 | self.save() |
| 548 | 566 | |
| | 567 | def set_disconnected(self): |
| | 568 | if self._settings.connection.type != NM_CONNECTION_TYPE_GSM and \ |
| | 569 | self._settings.connection.autoconnect: |
| | 570 | self._settings.connection.autoconnect = False |
| | 571 | self._settings.connection.timestamp = None |
| | 572 | self.Updated(self._settings.get_dict()) |
| | 573 | self.save() |
| | 574 | |
| 549 | 575 | def set_secrets(self, secrets): |
| 550 | 576 | self._secrets = secrets |
| 551 | 577 | if self._settings.connection.type == NM_CONNECTION_TYPE_802_11_WIRELESS: |
| … |
… |
|
| 555 | 581 | return self._settings |
| 556 | 582 | |
| 557 | 583 | def save(self): |
| 558 | | profile_path = env.get_profile_path() |
| 559 | | config_path = os.path.join(profile_path, 'nm', 'connections.cfg') |
| | 584 | config_path = get_wifi_connections_path() |
| 560 | 585 | |
| 561 | 586 | config = ConfigParser.ConfigParser() |
| 562 | 587 | try: |
| … |
… |
|
| 777 | 802 | _nm_settings.add_connection(uuid, conn) |
| 778 | 803 | return conn |
| 779 | 804 | |
| 780 | | def load_wifi_connections(): |
| | 805 | def get_wifi_connections_path(): |
| 781 | 806 | profile_path = env.get_profile_path() |
| 782 | | config_path = os.path.join(profile_path, 'nm', 'connections.cfg') |
| | 807 | return os.path.join(profile_path, 'nm', 'connections.cfg') |
| 783 | 808 | |
| 784 | | config = ConfigParser.ConfigParser() |
| | 809 | def create_wifi_connections(config_path): |
| | 810 | if not os.path.exists(os.path.dirname(config_path)): |
| | 811 | os.makedirs(os.path.dirname(config_path), 0755) |
| | 812 | f = open(config_path, 'w') |
| | 813 | f.close() |
| | 814 | |
| | 815 | def load_wifi_connections(): |
| | 816 | config_path = get_wifi_connections_path() |
| 785 | 817 | |
| 786 | 818 | if not os.path.exists(config_path): |
| 787 | | if not os.path.exists(os.path.dirname(config_path)): |
| 788 | | os.makedirs(os.path.dirname(config_path), 0755) |
| 789 | | f = open(config_path, 'w') |
| 790 | | config.write(f) |
| 791 | | f.close() |
| | 819 | create_wifi_connections(config_path) |
| 792 | 820 | |
| | 821 | config = ConfigParser.ConfigParser() |
| 793 | 822 | try: |
| 794 | 823 | if not config.read(config_path): |
| 795 | 824 | logging.error('Error reading the nm config file') |
| … |
… |
|
| 895 | 924 | |
| 896 | 925 | logging.debug('There is no gsm connection in the NMSettings.') |
| 897 | 926 | return None |
| | 927 | |
| | 928 | def count_wifi_connections(): |
| | 929 | return len(get_settings().connections) |
| | 930 | |
| | 931 | def clear_wifi_connections(): |
| | 932 | _nm_settings.clear_wifi_connections() |
| | 933 | |
| | 934 | config_path = get_wifi_connections_path() |
| | 935 | create_wifi_connections(config_path) |