From 36ef032c4ffa7991603fba1b7b6cf505206d857f Mon Sep 17 00:00:00 2001
From: James Cameron <quozl@laptop.org>
Date: Tue, 6 Apr 2010 16:10:37 +1000
Subject: [PATCH] fix network disconnect and discard history
User interface changes:
- enable the disconnect button on the access point menu in the
neighbourhood view, (rather than the button doing nothing),
- fix the disconnect button on the wireless device icon in the frame
so that the disconnection remains effective, (rather than
disconnecting and then reconnecting automatically),
- 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),
- enforce consistency between the neighbourhood view, the frame, and
the control panel, with respect to how the access point is shown.
Design changes:
- expose trusted access point list count for network control panel,
- move mesh box badge update into a separate function, since it must
be redone if the network history is discarded,
- 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,
Review changes:
- simplify earlier code following review comments from Tomeu on
#sugar, including use of dbus.PROPERTIES_IFACE.
Tested on:
- XO-1.5 build os117 on Sugar 0.84.15,
- Ubuntu 9.10 with Sugar 0.88,
References:
http://dev.laptop.org/ticket/9977 (fixes a workaround)
http://bugs.sugarlabs.org/ticket/1673
http://bugs.sugarlabs.org/ticket/1802
http://bugs.sugarlabs.org/ticket/1737
http://bugs.sugarlabs.org/ticket/1736
http://bugs.sugarlabs.org/ticket/1608
http://dev.laptop.org/ticket/9788
---
extensions/cpsection/network/model.py | 12 ++++--
extensions/cpsection/network/view.py | 8 ++++-
extensions/deviceicon/network.py | 37 ++++++++++----------
src/jarabe/desktop/meshbox.py | 61 ++++++++++++++++++++++-----------
src/jarabe/model/network.py | 61 ++++++++++++++++++++++++++------
5 files changed, 124 insertions(+), 55 deletions(-)
diff --git a/extensions/cpsection/network/model.py b/extensions/cpsection/network/model.py
index e1c3dab..2bc5e3a 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' |
… |
… |
def get_radio(): |
68 | 69 | try: |
69 | 70 | bus = dbus.SystemBus() |
70 | 71 | obj = bus.get_object(_NM_SERVICE, _NM_PATH) |
71 | | nm_props = dbus.Interface(obj, 'org.freedesktop.DBus.Properties') |
| 72 | nm_props = dbus.Interface(obj, dbus.PROPERTIES_IFACE) |
72 | 73 | except dbus.DBusException: |
73 | 74 | raise ReadError('%s service not available' % _NM_SERVICE) |
74 | 75 | |
… |
… |
def set_radio(state): |
89 | 90 | try: |
90 | 91 | bus = dbus.SystemBus() |
91 | 92 | obj = bus.get_object(_NM_SERVICE, _NM_PATH) |
92 | | nm_props = dbus.Interface(obj, 'org.freedesktop.DBus.Properties') |
| 93 | nm_props = dbus.Interface(obj, dbus.PROPERTIES_IFACE) |
93 | 94 | except dbus.DBusException: |
94 | 95 | raise ReadError('%s service not available' % _NM_SERVICE) |
95 | 96 | nm_props.Set(_NM_IFACE, 'WirelessEnabled', True) |
… |
… |
def set_radio(state): |
97 | 98 | try: |
98 | 99 | bus = dbus.SystemBus() |
99 | 100 | obj = bus.get_object(_NM_SERVICE, _NM_PATH) |
100 | | nm_props = dbus.Interface(obj, 'org.freedesktop.DBus.Properties') |
| 101 | nm_props = dbus.Interface(obj, dbus.PROPERTIES_IFACE) |
101 | 102 | except dbus.DBusException: |
102 | 103 | raise ReadError('%s service not available' % _NM_SERVICE) |
103 | 104 | nm_props.Set(_NM_IFACE, 'WirelessEnabled', False) |
… |
… |
def clear_registration(): |
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
|
class Network(SectionView): |
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() |
… |
… |
class Network(SectionView): |
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 |
… |
… |
class Network(SectionView): |
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/extensions/deviceicon/network.py b/extensions/deviceicon/network.py
index 94a4293..a828497 100644
a
|
b
|
class WirelessDeviceView(ToolButton): |
352 | 352 | self.set_palette(self._palette) |
353 | 353 | self._palette.set_group_id('frame') |
354 | 354 | |
355 | | self._device_props = dbus.Interface(self._device, |
356 | | 'org.freedesktop.DBus.Properties') |
| 355 | self._device_props = dbus.Interface(self._device, dbus.PROPERTIES_IFACE) |
357 | 356 | self._device_props.GetAll(_NM_DEVICE_IFACE, byte_arrays=True, |
358 | 357 | reply_handler=self.__get_device_props_reply_cb, |
359 | 358 | error_handler=self.__get_device_props_error_cb) |
… |
… |
class WirelessDeviceView(ToolButton): |
394 | 393 | return |
395 | 394 | self._active_ap_op = active_ap_op |
396 | 395 | active_ap = self._bus.get_object(_NM_SERVICE, active_ap_op) |
397 | | props = dbus.Interface(active_ap, 'org.freedesktop.DBus.Properties') |
| 396 | props = dbus.Interface(active_ap, dbus.PROPERTIES_IFACE) |
398 | 397 | |
399 | 398 | props.GetAll(_NM_ACCESSPOINT_IFACE, byte_arrays=True, |
400 | 399 | reply_handler=self.__get_all_ap_props_reply_cb, |
… |
… |
class WirelessDeviceView(ToolButton): |
508 | 507 | self._icon.props.base_color = self._color |
509 | 508 | |
510 | 509 | def __deactivate_connection_cb(self, palette, data=None): |
| 510 | connection = network.find_connection_by_ssid(self._name) |
| 511 | if connection: |
| 512 | if self._mode == network.NM_802_11_MODE_INFRA: |
| 513 | connection.set_disconnected() |
| 514 | |
511 | 515 | if self._active_ap_op is not None: |
512 | 516 | obj = self._bus.get_object(_NM_SERVICE, _NM_PATH) |
513 | 517 | netmgr = dbus.Interface(obj, _NM_IFACE) |
514 | | netmgr_props = dbus.Interface( |
515 | | netmgr, 'org.freedesktop.DBus.Properties') |
| 518 | netmgr_props = dbus.Interface(netmgr, dbus.PROPERTIES_IFACE) |
516 | 519 | active_connections_o = netmgr_props.Get(_NM_IFACE, |
517 | 520 | 'ActiveConnections') |
518 | 521 | |
519 | 522 | for conn_o in active_connections_o: |
520 | 523 | obj = self._bus.get_object(_NM_IFACE, conn_o) |
521 | | props = dbus.Interface(obj, 'org.freedesktop.DBus.Properties') |
| 524 | props = dbus.Interface(obj, dbus.PROPERTIES_IFACE) |
522 | 525 | ap_op = props.Get(_NM_ACTIVE_CONN_IFACE, 'SpecificObject') |
523 | 526 | if ap_op == self._active_ap_op: |
524 | 527 | netmgr.DeactivateConnection(conn_o) |
… |
… |
class OlpcMeshDeviceView(ToolButton): |
608 | 611 | self.set_palette(self._palette) |
609 | 612 | self._palette.set_group_id('frame') |
610 | 613 | |
611 | | self._device_props = dbus.Interface(self._device, |
612 | | 'org.freedesktop.DBus.Properties') |
| 614 | self._device_props = dbus.Interface(self._device, dbus.PROPERTIES_IFACE) |
613 | 615 | self._device_props.GetAll(_NM_DEVICE_IFACE, byte_arrays=True, |
614 | 616 | reply_handler=self.__get_device_props_reply_cb, |
615 | 617 | error_handler=self.__get_device_props_error_cb) |
… |
… |
class OlpcMeshDeviceView(ToolButton): |
681 | 683 | def __deactivate_connection(self, palette, data=None): |
682 | 684 | obj = self._bus.get_object(_NM_SERVICE, _NM_PATH) |
683 | 685 | netmgr = dbus.Interface(obj, _NM_IFACE) |
684 | | netmgr_props = dbus.Interface(netmgr, 'org.freedesktop.DBus.Properties') |
| 686 | netmgr_props = dbus.Interface(netmgr, dbus.PROPERTIES_IFACE) |
685 | 687 | active_connections_o = netmgr_props.Get(_NM_IFACE, |
686 | 688 | 'ActiveConnections') |
687 | 689 | |
688 | 690 | for conn_o in active_connections_o: |
689 | 691 | # The connection path for a mesh connection is the device itself. |
690 | 692 | obj = self._bus.get_object(_NM_IFACE, conn_o) |
691 | | props = dbus.Interface(obj, 'org.freedesktop.DBus.Properties') |
| 693 | props = dbus.Interface(obj, dbus.PROPERTIES_IFACE) |
692 | 694 | ap_op = props.Get(_NM_ACTIVE_CONN_IFACE, 'SpecificObject') |
693 | 695 | |
694 | 696 | try: |
695 | 697 | obj = self._bus.get_object(_NM_IFACE, ap_op) |
696 | | props = dbus.Interface(obj, 'org.freedesktop.DBus.Properties') |
| 698 | props = dbus.Interface(obj, dbus.PROPERTIES_IFACE) |
697 | 699 | type = props.Get(_NM_DEVICE_IFACE, 'DeviceType') |
698 | 700 | if type == network.DEVICE_TYPE_802_11_OLPC_MESH: |
699 | 701 | netmgr.DeactivateConnection(conn_o) |
… |
… |
class GsmDeviceView(TrayIcon): |
756 | 758 | |
757 | 759 | self._palette = palette |
758 | 760 | |
759 | | props = dbus.Interface(self._device, 'org.freedesktop.DBus.Properties') |
| 761 | props = dbus.Interface(self._device, dbus.PROPERTIES_IFACE) |
760 | 762 | props.GetAll(_NM_DEVICE_IFACE, byte_arrays=True, |
761 | 763 | reply_handler=self.__current_state_check_cb, |
762 | 764 | error_handler=self.__current_state_check_error_cb) |
… |
… |
class GsmDeviceView(TrayIcon): |
785 | 787 | def __gsm_disconnect_cb(self, palette, data=None): |
786 | 788 | obj = self._bus.get_object(_NM_SERVICE, _NM_PATH) |
787 | 789 | netmgr = dbus.Interface(obj, _NM_IFACE) |
788 | | netmgr_props = dbus.Interface(netmgr, 'org.freedesktop.DBus.Properties') |
| 790 | netmgr_props = dbus.Interface(netmgr, dbus.PROPERTIES_IFACE) |
789 | 791 | active_connections_o = netmgr_props.Get(_NM_IFACE, 'ActiveConnections') |
790 | 792 | |
791 | 793 | for conn_o in active_connections_o: |
792 | 794 | obj = self._bus.get_object(_NM_IFACE, conn_o) |
793 | | props = dbus.Interface(obj, 'org.freedesktop.DBus.Properties') |
| 795 | props = dbus.Interface(obj, dbus.PROPERTIES_IFACE) |
794 | 796 | devices = props.Get(_NM_ACTIVE_CONN_IFACE, 'Devices') |
795 | 797 | if self._device.object_path in devices: |
796 | 798 | netmgr.DeactivateConnection( |
… |
… |
class WiredDeviceObserver(object): |
910 | 912 | self._device_view = None |
911 | 913 | self._tray = tray |
912 | 914 | |
913 | | props = dbus.Interface(self._device, 'org.freedesktop.DBus.Properties') |
| 915 | props = dbus.Interface(self._device, dbus.PROPERTIES_IFACE) |
914 | 916 | props.GetAll(_NM_DEVICE_IFACE, byte_arrays=True, |
915 | 917 | reply_handler=self.__get_device_props_reply_cb, |
916 | 918 | error_handler=self.__get_device_props_error_cb) |
… |
… |
class WiredDeviceObserver(object): |
938 | 940 | |
939 | 941 | def _update_state(self, state): |
940 | 942 | if state == network.DEVICE_STATE_ACTIVATED: |
941 | | props = dbus.Interface(self._device, |
942 | | 'org.freedesktop.DBus.Properties') |
| 943 | props = dbus.Interface(self._device, dbus.PROPERTIES_IFACE) |
943 | 944 | address = props.Get(_NM_DEVICE_IFACE, 'Ip4Address') |
944 | 945 | speed = props.Get(_NM_WIRED_IFACE, 'Speed') |
945 | 946 | self._device_view = WiredDeviceView(speed, address) |
… |
… |
class NetworkManagerObserver(object): |
997 | 998 | |
998 | 999 | def _check_device(self, device_op): |
999 | 1000 | nm_device = self._bus.get_object(_NM_SERVICE, device_op) |
1000 | | props = dbus.Interface(nm_device, 'org.freedesktop.DBus.Properties') |
| 1001 | props = dbus.Interface(nm_device, dbus.PROPERTIES_IFACE) |
1001 | 1002 | |
1002 | 1003 | device_type = props.Get(_NM_DEVICE_IFACE, 'DeviceType') |
1003 | 1004 | if device_type == network.DEVICE_TYPE_802_3_ETHERNET: |
diff --git a/src/jarabe/desktop/meshbox.py b/src/jarabe/desktop/meshbox.py
index a04922b..280adb9 100644
a
|
b
|
class WirelessNetworkView(CanvasPulsingIcon): |
86 | 86 | self._rsn_flags = initial_ap.rsn_flags |
87 | 87 | self._device_caps = 0 |
88 | 88 | self._device_state = None |
89 | | self._connection = None |
90 | 89 | self._color = None |
91 | 90 | |
92 | 91 | if self._mode == network.NM_802_11_MODE_ADHOC \ |
… |
… |
class WirelessNetworkView(CanvasPulsingIcon): |
115 | 114 | self.set_palette(self._palette) |
116 | 115 | self._palette_icon.props.xo_color = self._color |
117 | 116 | |
118 | | if network.find_connection_by_ssid(self._name) is not None: |
119 | | self.props.badge_name = "emblem-favorite" |
120 | | self._palette_icon.props.badge_name = "emblem-favorite" |
121 | | elif initial_ap.flags == network.NM_802_11_AP_FLAGS_PRIVACY: |
122 | | self.props.badge_name = "emblem-locked" |
123 | | self._palette_icon.props.badge_name = "emblem-locked" |
124 | | else: |
125 | | self.props.badge_name = None |
126 | | self._palette_icon.props.badge_name = None |
| 117 | self._update_badge() |
127 | 118 | |
128 | | interface_props = dbus.Interface(self._device, |
129 | | 'org.freedesktop.DBus.Properties') |
| 119 | interface_props = dbus.Interface(self._device, dbus.PROPERTIES_IFACE) |
130 | 120 | interface_props.Get(_NM_DEVICE_IFACE, 'State', |
131 | 121 | reply_handler=self.__get_device_state_reply_cb, |
132 | 122 | error_handler=self.__get_device_state_error_cb) |
… |
… |
class WirelessNetworkView(CanvasPulsingIcon): |
174 | 164 | def __device_state_changed_cb(self, new_state, old_state, reason): |
175 | 165 | self._device_state = new_state |
176 | 166 | self._update_state() |
| 167 | self._update_badge() |
177 | 168 | |
178 | 169 | def __update_active_ap(self, ap_path): |
179 | 170 | if ap_path in self._access_points: |
… |
… |
class WirelessNetworkView(CanvasPulsingIcon): |
214 | 205 | def _update(self): |
215 | 206 | self._update_state() |
216 | 207 | self._update_color() |
| 208 | self._update_badge() |
217 | 209 | |
218 | 210 | def _update_state(self): |
219 | 211 | if self._active_ap is not None: |
… |
… |
class WirelessNetworkView(CanvasPulsingIcon): |
266 | 258 | else: |
267 | 259 | self.props.base_color = self._color |
268 | 260 | |
| 261 | def _update_badge(self): |
| 262 | if network.find_connection_by_ssid(self._name) is not None: |
| 263 | self.props.badge_name = "emblem-favorite" |
| 264 | self._palette_icon.props.badge_name = "emblem-favorite" |
| 265 | elif self._flags == network.NM_802_11_AP_FLAGS_PRIVACY: |
| 266 | self.props.badge_name = "emblem-locked" |
| 267 | self._palette_icon.props.badge_name = "emblem-locked" |
| 268 | else: |
| 269 | self.props.badge_name = None |
| 270 | self._palette_icon.props.badge_name = None |
| 271 | |
269 | 272 | def _disconnect_activate_cb(self, item): |
270 | | pass |
| 273 | connection = network.find_connection_by_ssid(self._name) |
| 274 | if connection: |
| 275 | if self._mode == network.NM_802_11_MODE_INFRA: |
| 276 | connection.set_disconnected() |
| 277 | |
| 278 | obj = self._bus.get_object(_NM_SERVICE, _NM_PATH) |
| 279 | netmgr = dbus.Interface(obj, _NM_IFACE) |
| 280 | |
| 281 | netmgr_props = dbus.Interface(netmgr, dbus.PROPERTIES_IFACE) |
| 282 | active_connections_o = netmgr_props.Get(_NM_IFACE, 'ActiveConnections') |
| 283 | |
| 284 | for conn_o in active_connections_o: |
| 285 | obj = self._bus.get_object(_NM_IFACE, conn_o) |
| 286 | props = dbus.Interface(obj, dbus.PROPERTIES_IFACE) |
| 287 | state = props.Get(_NM_ACTIVE_CONN_IFACE, 'State') |
| 288 | if state == network.NM_ACTIVE_CONNECTION_STATE_ACTIVATED: |
| 289 | ap_o = props.Get(_NM_ACTIVE_CONN_IFACE, 'SpecificObject') |
| 290 | if ap_o != '/' and self.find_ap(ap_o) is not None: |
| 291 | netmgr.DeactivateConnection(conn_o) |
| 292 | else: |
| 293 | logging.error('Could not determine AP for' |
| 294 | ' specific object %s' % conn_o) |
271 | 295 | |
272 | 296 | def _add_ciphers_from_flags(self, flags, pairwise): |
273 | 297 | ciphers = [] |
… |
… |
class OlpcMeshView(CanvasPulsingIcon): |
456 | 480 | self._greyed_out = False |
457 | 481 | self._name = '' |
458 | 482 | self._device_state = None |
459 | | self._connection = None |
460 | 483 | self._active = False |
461 | 484 | device = mesh_mgr.mesh_device |
462 | 485 | |
463 | 486 | self.connect('button-release-event', self.__button_release_event_cb) |
464 | 487 | |
465 | | interface_props = dbus.Interface(device, |
466 | | 'org.freedesktop.DBus.Properties') |
| 488 | interface_props = dbus.Interface(device, dbus.PROPERTIES_IFACE) |
467 | 489 | interface_props.Get(_NM_DEVICE_IFACE, 'State', |
468 | 490 | reply_handler=self.__get_device_state_reply_cb, |
469 | 491 | error_handler=self.__get_device_state_error_cb) |
… |
… |
class NetworkManagerObserver(object): |
849 | 871 | # FIXME It would be better to do all of this async, but I cannot think |
850 | 872 | # of a good way to. NM could really use some love here. |
851 | 873 | |
852 | | netmgr_props = dbus.Interface( |
853 | | self._netmgr, 'org.freedesktop.DBus.Properties') |
| 874 | netmgr_props = dbus.Interface(self._netmgr, dbus.PROPERTIES_IFACE) |
854 | 875 | active_connections_o = netmgr_props.Get(_NM_IFACE, 'ActiveConnections') |
855 | 876 | |
856 | 877 | for conn_o in active_connections_o: |
857 | 878 | obj = self._bus.get_object(_NM_IFACE, conn_o) |
858 | | props = dbus.Interface(obj, 'org.freedesktop.DBus.Properties') |
| 879 | props = dbus.Interface(obj, dbus.PROPERTIES_IFACE) |
859 | 880 | state = props.Get(_NM_ACTIVE_CONN_IFACE, 'State') |
860 | 881 | if state == network.NM_ACTIVE_CONNECTION_STATE_ACTIVATING: |
861 | 882 | ap_o = props.Get(_NM_ACTIVE_CONN_IFACE, 'SpecificObject') |
… |
… |
class NetworkManagerObserver(object): |
879 | 900 | |
880 | 901 | def _check_device(self, device_o): |
881 | 902 | device = self._bus.get_object(_NM_SERVICE, device_o) |
882 | | props = dbus.Interface(device, 'org.freedesktop.DBus.Properties') |
| 903 | props = dbus.Interface(device, dbus.PROPERTIES_IFACE) |
883 | 904 | |
884 | 905 | device_type = props.Get(_NM_DEVICE_IFACE, 'DeviceType') |
885 | 906 | if device_type == network.DEVICE_TYPE_802_11_WIRELESS: |
diff --git a/src/jarabe/model/network.py b/src/jarabe/model/network.py
index 3a949da..bebd2c1 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_wifi_connections(self): |
| 334 | for uuid in self.connections.keys(): |
| 335 | conn = self.connections[uuid] |
| 336 | if conn.type == NM_CONNECTION_TYPE_802_11_WIRELESS: |
| 337 | conn.Removed() |
| 338 | self.connections.pop(uuid) |
| 339 | |
333 | 340 | class SecretsResponse(object): |
334 | 341 | ''' Intermediate object to report the secrets from the dialog |
335 | 342 | back to the connection object and which will inform NM |
… |
… |
class NMSettingsConnection(dbus.service.Object): |
358 | 365 | self._settings = settings |
359 | 366 | self._secrets = secrets |
360 | 367 | |
| 368 | @dbus.service.signal(dbus_interface=NM_CONNECTION_IFACE, |
| 369 | signature='') |
| 370 | def Removed(self): |
| 371 | pass |
| 372 | |
| 373 | @dbus.service.signal(dbus_interface=NM_CONNECTION_IFACE, |
| 374 | signature='a{sa{sv}}') |
| 375 | def Updated(self, settings): |
| 376 | pass |
| 377 | |
361 | 378 | def set_connected(self): |
362 | 379 | if self._settings.connection.type == NM_CONNECTION_TYPE_GSM: |
363 | 380 | self._settings.connection.timestamp = int(time.time()) |
… |
… |
class NMSettingsConnection(dbus.service.Object): |
366 | 383 | self._settings.connection.autoconnect = True |
367 | 384 | self._settings.connection.timestamp = int(time.time()) |
368 | 385 | if self._settings.connection.type == NM_CONNECTION_TYPE_802_11_WIRELESS: |
| 386 | self.Updated(self._settings.get_dict()) |
369 | 387 | self.save() |
370 | 388 | |
| 389 | def set_disconnected(self): |
| 390 | if self._settings.connection.type != NM_CONNECTION_TYPE_GSM and \ |
| 391 | self._settings.connection.autoconnect: |
| 392 | self._settings.connection.autoconnect = False |
| 393 | self._settings.connection.timestamp = None |
| 394 | self.Updated(self._settings.get_dict()) |
| 395 | self.save() |
| 396 | |
371 | 397 | def set_secrets(self, secrets): |
372 | 398 | self._secrets = secrets |
373 | 399 | if self._settings.connection.type == NM_CONNECTION_TYPE_802_11_WIRELESS: |
… |
… |
class NMSettingsConnection(dbus.service.Object): |
377 | 403 | return self._settings |
378 | 404 | |
379 | 405 | def save(self): |
380 | | profile_path = env.get_profile_path() |
381 | | config_path = os.path.join(profile_path, 'nm', 'connections.cfg') |
| 406 | config_path = get_wifi_connections_path() |
382 | 407 | |
383 | 408 | config = ConfigParser.ConfigParser() |
384 | 409 | try: |
… |
… |
class AccessPoint(gobject.GObject): |
477 | 502 | self.mode = 0 |
478 | 503 | |
479 | 504 | def initialize(self): |
480 | | model_props = dbus.Interface(self.model, |
481 | | 'org.freedesktop.DBus.Properties') |
| 505 | model_props = dbus.Interface(self.model, dbus.PROPERTIES_IFACE) |
482 | 506 | model_props.GetAll(NM_ACCESSPOINT_IFACE, byte_arrays=True, |
483 | 507 | reply_handler=self._ap_properties_changed_cb, |
484 | 508 | error_handler=self._get_all_props_error_cb) |
… |
… |
def add_connection(uuid, settings, secrets=None): |
590 | 614 | _nm_settings.add_connection(uuid, conn) |
591 | 615 | return conn |
592 | 616 | |
593 | | def load_wifi_connections(): |
| 617 | def get_wifi_connections_path(): |
594 | 618 | profile_path = env.get_profile_path() |
595 | | config_path = os.path.join(profile_path, 'nm', 'connections.cfg') |
| 619 | return os.path.join(profile_path, 'nm', 'connections.cfg') |
596 | 620 | |
597 | | config = ConfigParser.ConfigParser() |
| 621 | def create_wifi_connections(config_path): |
| 622 | if not os.path.exists(os.path.dirname(config_path)): |
| 623 | os.makedirs(os.path.dirname(config_path), 0755) |
| 624 | f = open(config_path, 'w') |
| 625 | f.close() |
| 626 | |
| 627 | def load_wifi_connections(): |
| 628 | config_path = get_wifi_connections_path() |
598 | 629 | |
599 | 630 | if not os.path.exists(config_path): |
600 | | if not os.path.exists(os.path.dirname(config_path)): |
601 | | os.makedirs(os.path.dirname(config_path), 0755) |
602 | | f = open(config_path, 'w') |
603 | | config.write(f) |
604 | | f.close() |
| 631 | create_wifi_connections(config_path) |
605 | 632 | |
| 633 | config = ConfigParser.ConfigParser() |
606 | 634 | try: |
607 | 635 | if not config.read(config_path): |
608 | 636 | logging.error('Error reading the nm config file') |
… |
… |
def find_gsm_connection(): |
708 | 736 | |
709 | 737 | logging.debug('There is no gsm connection in the NMSettings.') |
710 | 738 | return None |
| 739 | |
| 740 | def count_wifi_connections(): |
| 741 | return len(get_settings().connections) |
| 742 | |
| 743 | def clear_wifi_connections(): |
| 744 | _nm_settings.clear_wifi_connections() |
| 745 | |
| 746 | config_path = get_wifi_connections_path() |
| 747 | create_wifi_connections(config_path) |