[Sugar-devel] [PATCH v2] Simple NetworkManager-0.9 port

Simon Schampijer simon at schampijer.de
Mon Nov 14 10:01:55 EST 2011


El 11/11/11 18:17, Daniel Drake escribió:
> Adapt sugar to NetworkManager-0.9 API changes.
>
> The major change here is the removal of the user-level connections
> mechanism; instead of storing connection information in Sugar,
> NetworkManager now Manages our Networks for us.
>
> However, some level of interfacing/monitoring NM is now needed,
> implemented with the Connections and Connection classes in
> jarabe.model.network.
>
> If found, connections in sugar's connections.cfg are automatically
> migrated, and then connections.cfg is deleted. Similarly, if modem
> connection details are found in gconf, they are migrated into NM
> and then the gconf keys are unset.
>
> The existing network code is far from perfect and actually quite messy.
> In this port I've tried not to make fundamental changes to improve this,
> in order to keep task complexity down and aid review.
> In the medium term I do plan to improve this code, by moving it to
> use gobject-introspection on libnm, and rewriting/restructuring at the
> same time. By letting libnm do most of the work for us, this layer can
> be greatly simplified. However, libnm and gobject-introspection
> improvements are needed first, which I will continue to work on.
>
> Modem PUK configuration has been removed as NetworkManager no longer
> has configuration for this. It hasn't been used (and was marked
> deprecated) throughout the NM-0.8 release series.
> ---
>   data/sugar.schemas.in                            |   24 +-
>   extensions/cpsection/modemconfiguration/model.py |  106 ++--
>   extensions/cpsection/modemconfiguration/view.py  |  207 ++-----
>   extensions/cpsection/network/model.py            |   14 +-
>   extensions/deviceicon/network.py                 |  179 +++---
>   src/jarabe/desktop/keydialog.py                  |   32 +-
>   src/jarabe/desktop/meshbox.py                    |   60 +-
>   src/jarabe/desktop/networkviews.py               |  169 ++---
>   src/jarabe/model/adhoc.py                        |  115 ++--
>   src/jarabe/model/network.py                      |  754 +++++++++++-----------
>   src/jarabe/model/olpcmesh.py                     |  159 +++--
>   11 files changed, 844 insertions(+), 975 deletions(-)
>
> v2: handle review comments from Simon and Sascha's Oct 24 mail. Only non-minor
> resulting change is a refactoring of modem setting handling so that undo
> is supported again.
[...]
> diff --git a/extensions/deviceicon/network.py b/extensions/deviceicon/network.py
> index 789ea13..c002d5f 100644
> --- a/extensions/deviceicon/network.py
> +++ b/extensions/deviceicon/network.py
> @@ -48,17 +48,6 @@ from jarabe.view.pulsingicon import PulsingIcon
>
>   IP_ADDRESS_TEXT_TEMPLATE = _('IP address: %s')
>
> -_NM_SERVICE = 'org.freedesktop.NetworkManager'
> -_NM_IFACE = 'org.freedesktop.NetworkManager'
> -_NM_PATH = '/org/freedesktop/NetworkManager'
> -_NM_DEVICE_IFACE = 'org.freedesktop.NetworkManager.Device'
> -_NM_WIRED_IFACE = 'org.freedesktop.NetworkManager.Device.Wired'
> -_NM_WIRELESS_IFACE = 'org.freedesktop.NetworkManager.Device.Wireless'
> -_NM_SERIAL_IFACE = 'org.freedesktop.NetworkManager.Device.Serial'
> -_NM_OLPC_MESH_IFACE = 'org.freedesktop.NetworkManager.Device.OlpcMesh'
> -_NM_ACCESSPOINT_IFACE = 'org.freedesktop.NetworkManager.AccessPoint'
> -_NM_ACTIVE_CONN_IFACE = 'org.freedesktop.NetworkManager.Connection.Active'
> -
>   _GSM_STATE_NOT_READY = 0
>   _GSM_STATE_DISCONNECTED = 1
>   _GSM_STATE_CONNECTING = 2
> @@ -413,24 +402,24 @@ class WirelessDeviceView(ToolButton):
>
>           self._device_props = dbus.Interface(self._device,
>                                               dbus.PROPERTIES_IFACE)
> -        self._device_props.GetAll(_NM_DEVICE_IFACE, byte_arrays=True,
> +        self._device_props.GetAll(network.NM_DEVICE_IFACE, byte_arrays=True,
>                                 reply_handler=self.__get_device_props_reply_cb,
>                                 error_handler=self.__get_device_props_error_cb)
>
> -        self._device_props.Get(_NM_WIRELESS_IFACE, 'ActiveAccessPoint',
> +        self._device_props.Get(network.NM_WIRELESS_IFACE, 'ActiveAccessPoint',
>                                  reply_handler=self.__get_active_ap_reply_cb,
>                                  error_handler=self.__get_active_ap_error_cb)
>
>           self._bus.add_signal_receiver(self.__state_changed_cb,
>                                         signal_name='StateChanged',
>                                         path=self._device.object_path,
> -                                      dbus_interface=_NM_DEVICE_IFACE)
> +                                      dbus_interface=network.NM_DEVICE_IFACE)
>
>       def disconnect(self):
>           self._bus.remove_signal_receiver(self.__state_changed_cb,
>                                            signal_name='StateChanged',
>                                            path=self._device.object_path,
> -                                         dbus_interface=_NM_DEVICE_IFACE)
> +                                         dbus_interface=network.NM_DEVICE_IFACE)
>
>       def __get_device_props_reply_cb(self, properties):
>           if 'State' in properties:
> @@ -447,22 +436,22 @@ class WirelessDeviceView(ToolButton):
>                       self.__ap_properties_changed_cb,
>                       signal_name='PropertiesChanged',
>                       path=self._active_ap_op,
> -                    dbus_interface=_NM_ACCESSPOINT_IFACE)
> +                    dbus_interface=network.NM_ACCESSPOINT_IFACE)
>               if active_ap_op == '/':
>                   self._active_ap_op = None
>                   return
>               self._active_ap_op = active_ap_op
> -            active_ap = self._bus.get_object(_NM_SERVICE, active_ap_op)
> +            active_ap = self._bus.get_object(network.NM_SERVICE, active_ap_op)
>               props = dbus.Interface(active_ap, dbus.PROPERTIES_IFACE)
>
> -            props.GetAll(_NM_ACCESSPOINT_IFACE, byte_arrays=True,
> +            props.GetAll(network.NM_ACCESSPOINT_IFACE, byte_arrays=True,
>                            reply_handler=self.__get_all_ap_props_reply_cb,
>                            error_handler=self.__get_all_ap_props_error_cb)
>
>               self._bus.add_signal_receiver(self.__ap_properties_changed_cb,
>                                             signal_name='PropertiesChanged',
>                                             path=self._active_ap_op,
> -                                          dbus_interface=_NM_ACCESSPOINT_IFACE)
> +                                          dbus_interface=network.NM_ACCESSPOINT_IFACE)
>
>       def __get_active_ap_error_cb(self, err):
>           logging.error('Error getting the active access point: %s', err)
> @@ -470,7 +459,7 @@ class WirelessDeviceView(ToolButton):
>       def __state_changed_cb(self, new_state, old_state, reason):
>           self._device_state = new_state
>           self._update_state()
> -        self._device_props.Get(_NM_WIRELESS_IFACE, 'ActiveAccessPoint',
> +        self._device_props.Get(network.NM_WIRELESS_IFACE, 'ActiveAccessPoint',
>                                  reply_handler=self.__get_active_ap_reply_cb,
>                                  error_handler=self.__get_active_ap_error_cb)
>
> @@ -528,11 +517,11 @@ class WirelessDeviceView(ToolButton):
>           if self._active_ap_op is not None:
>               state = self._device_state
>           else:
> -            state = network.DEVICE_STATE_UNKNOWN
> +            state = network.NM_DEVICE_STATE_UNKNOWN
>
>           if self._mode != network.NM_802_11_MODE_ADHOC and \
>                   network.is_sugar_adhoc_network(self._name) == False:
> -            if state == network.DEVICE_STATE_ACTIVATED:
> +            if state == network.NM_DEVICE_STATE_ACTIVATED:
>                   icon_name = '%s-connected' % 'network-wireless'
>               else:
>                   icon_name = 'network-wireless'
> @@ -542,21 +531,20 @@ class WirelessDeviceView(ToolButton):
>                   self._icon.props.icon_name = icon_name
>           else:
>               channel = network.frequency_to_channel(self._frequency)
> -            if state == network.DEVICE_STATE_ACTIVATED:
> +            if state == network.NM_DEVICE_STATE_ACTIVATED:
>                   self._icon.props.icon_name = 'network-adhoc-%s-connected' \
>                           % channel
>               else:
>                   self._icon.props.icon_name = 'network-adhoc-%s' % channel
>               self._icon.props.base_color = profile.get_color()
>
> -        if state == network.DEVICE_STATE_PREPARE or \
> -           state == network.DEVICE_STATE_CONFIG or \
> -           state == network.DEVICE_STATE_NEED_AUTH or \
> -           state == network.DEVICE_STATE_IP_CONFIG:
> +
> +        if (state>= network.NM_DEVICE_STATE_PREPARE) and \
> +           (state<= network.NM_DEVICE_STATE_IP_CONFIG):
>               self._palette.set_connecting()
>               self._icon.props.pulsing = True
> -        elif state == network.DEVICE_STATE_ACTIVATED:
> -            address = self._device_props.Get(_NM_DEVICE_IFACE, 'Ip4Address')
> +        elif state == network.NM_DEVICE_STATE_ACTIVATED:
> +            address = self._device_props.Get(network.NM_DEVICE_IFACE, 'Ip4Address')
>               self._palette.set_connected_with_frequency(self._frequency,
>                                                          address)
>               self._icon.props.pulsing = False
> @@ -571,11 +559,6 @@ class WirelessDeviceView(ToolButton):
>           self._icon.props.base_color = self._color
>
>       def __deactivate_connection_cb(self, palette, data=None):
> -        if self._mode == network.NM_802_11_MODE_INFRA:
> -            connection = network.find_connection_by_ssid(self._name)
> -            if connection:
> -                connection.disable_autoconnect()
> -
>           network.disconnect_access_points([self._active_ap_op])
>
>       def __activate_reply_cb(self, connection):
> @@ -620,20 +603,20 @@ class OlpcMeshDeviceView(ToolButton):
>
>           self._device_props = dbus.Interface(self._device,
>                                               dbus.PROPERTIES_IFACE)
> -        self._device_props.Get(_NM_OLPC_MESH_IFACE, 'ActiveChannel',
> +        self._device_props.Get(network.NM_OLPC_MESH_IFACE, 'ActiveChannel',
>                               reply_handler=self.__get_active_channel_reply_cb,
>                               error_handler=self.__get_active_channel_error_cb)
>
>           self._bus.add_signal_receiver(self.__wireless_properties_changed_cb,
>                                         signal_name='PropertiesChanged',
>                                         path=device.object_path,
> -                                      dbus_interface=_NM_OLPC_MESH_IFACE)
> +                                      dbus_interface=network.NM_OLPC_MESH_IFACE)
>
>       def disconnect(self):
>           self._bus.remove_signal_receiver(self.__wireless_properties_changed_cb,
>                                            signal_name='PropertiesChanged',
>                                            path=self._device.object_path,
> -                                         dbus_interface=_NM_OLPC_MESH_IFACE)
> +                                         dbus_interface=network.NM_OLPC_MESH_IFACE)
>
>       def __get_active_channel_reply_cb(self, channel):
>           self._channel = channel
> @@ -659,16 +642,14 @@ class OlpcMeshDeviceView(ToolButton):
>       def _update(self):
>           state = self._device_state
>
> -        if state in [network.DEVICE_STATE_PREPARE,
> -                     network.DEVICE_STATE_CONFIG,
> -                     network.DEVICE_STATE_NEED_AUTH,
> -                     network.DEVICE_STATE_IP_CONFIG]:
> +        if (state>= network.NM_DEVICE_STATE_PREPARE) and \
> +           (state<= network.NM_DEVICE_STATE_IP_CONFIG):
>               self._icon.props.base_color = self._inactive_color
>               self._icon.props.pulse_color = profile.get_color()
>               self._palette.set_connecting()
>               self._icon.props.pulsing = True
> -        elif state == network.DEVICE_STATE_ACTIVATED:
> -            address = self._device_props.Get(_NM_DEVICE_IFACE, 'Ip4Address')
> +        elif state == network.NM_DEVICE_STATE_ACTIVATED:
> +            address = self._device_props.Get(network.NM_DEVICE_IFACE, 'Ip4Address')
>               self._palette.set_connected_with_channel(self._channel, address)
>               self._icon.props.base_color = profile.get_color()
>               self._icon.props.pulsing = False
> @@ -679,23 +660,23 @@ class OlpcMeshDeviceView(ToolButton):
>           self._update()
>
>       def __deactivate_connection(self, palette, data=None):
> -        obj = self._bus.get_object(_NM_SERVICE, _NM_PATH)
> -        netmgr = dbus.Interface(obj, _NM_IFACE)
> +        obj = self._bus.get_object(network.NM_SERVICE, network.NM_PATH)
> +        netmgr = dbus.Interface(obj, network.NM_IFACE)
>           netmgr_props = dbus.Interface(netmgr, dbus.PROPERTIES_IFACE)
> -        active_connections_o = netmgr_props.Get(_NM_IFACE,
> +        active_connections_o = netmgr_props.Get(network.NM_IFACE,
>                                                   'ActiveConnections')
>
>           for conn_o in active_connections_o:
>               # The connection path for a mesh connection is the device itself.
> -            obj = self._bus.get_object(_NM_IFACE, conn_o)
> +            obj = self._bus.get_object(network.NM_IFACE, conn_o)
>               props = dbus.Interface(obj, dbus.PROPERTIES_IFACE)
> -            ap_op = props.Get(_NM_ACTIVE_CONN_IFACE, 'SpecificObject')
> +            ap_op = props.Get(network.NM_ACTIVE_CONN_IFACE, 'SpecificObject')
>
>               try:
> -                obj = self._bus.get_object(_NM_IFACE, ap_op)
> +                obj = self._bus.get_object(network.NM_IFACE, ap_op)
>                   props = dbus.Interface(obj, dbus.PROPERTIES_IFACE)
> -                device_type = props.Get(_NM_DEVICE_IFACE, 'DeviceType')
> -                if device_type == network.DEVICE_TYPE_802_11_OLPC_MESH:
> +                device_type = props.Get(network.NM_DEVICE_IFACE, 'DeviceType')
> +                if device_type == network.NM_DEVICE_TYPE_OLPC_MESH:
>                       netmgr.DeactivateConnection(conn_o)
>                       break
>               except dbus.exceptions.DBusException:
> @@ -742,11 +723,11 @@ class GsmDeviceView(TrayIcon):
>           self._bus.add_signal_receiver(self.__state_changed_cb,
>                                         signal_name='StateChanged',
>                                         path=self._device.object_path,
> -                                      dbus_interface=_NM_DEVICE_IFACE)
> +                                      dbus_interface=network.NM_DEVICE_IFACE)
>           self._bus.add_signal_receiver(self.__ppp_stats_changed_cb,
>                                         signal_name='PppStats',
>                                         path=self._device.object_path,
> -                                      dbus_interface=_NM_SERIAL_IFACE)
> +                                      dbus_interface=network.NM_MODEM_IFACE)
>
>       def create_palette(self):
>           palette = GsmPalette()
> @@ -758,7 +739,7 @@ class GsmDeviceView(TrayIcon):
>           self._palette = palette
>
>           props = dbus.Interface(self._device, dbus.PROPERTIES_IFACE)
> -        props.GetAll(_NM_DEVICE_IFACE, byte_arrays=True,
> +        props.GetAll(network.NM_DEVICE_IFACE, byte_arrays=True,
>                        reply_handler=self.__current_state_check_cb,
>                        error_handler=self.__current_state_check_error_cb)
>
> @@ -767,14 +748,9 @@ class GsmDeviceView(TrayIcon):
>       def __gsm_connect_cb(self, palette, data=None):
>           connection = network.find_gsm_connection()
>           if connection is not None:
> -            obj = self._bus.get_object(_NM_SERVICE, _NM_PATH)
> -            netmgr = dbus.Interface(obj, _NM_IFACE)
> -            netmgr.ActivateConnection(network.SETTINGS_SERVICE,
> -                                        connection.path,
> -                                        self._device.object_path,
> -                                        '/',
> -                                        reply_handler=self.__connect_cb,
> -                                        error_handler=self.__connect_error_cb)
> +            connection.activate(self._device.object_path,
> +                                reply_handler=self.__connect_cb,
> +                                error_handler=self.__connect_error_cb)
>           else:
>               self._palette.add_alert(_('No GSM connection available.'), \
>                                           _('Create a connection in the ' \
> @@ -788,15 +764,15 @@ class GsmDeviceView(TrayIcon):
>           raise RuntimeError('Error when connecting to gsm device, %s' % error)
>
>       def __gsm_disconnect_cb(self, palette, data=None):
> -        obj = self._bus.get_object(_NM_SERVICE, _NM_PATH)
> -        netmgr = dbus.Interface(obj, _NM_IFACE)
> +        obj = self._bus.get_object(network.NM_SERVICE, network.NM_PATH)
> +        netmgr = dbus.Interface(obj, network.NM_IFACE)
>           netmgr_props = dbus.Interface(netmgr, dbus.PROPERTIES_IFACE)
> -        active_connections_o = netmgr_props.Get(_NM_IFACE, 'ActiveConnections')
> +        active_connections_o = netmgr_props.Get(network.NM_IFACE, 'ActiveConnections')
>
>           for conn_o in active_connections_o:
> -            obj = self._bus.get_object(_NM_IFACE, conn_o)
> +            obj = self._bus.get_object(network.NM_IFACE, conn_o)
>               props = dbus.Interface(obj, dbus.PROPERTIES_IFACE)
> -            devices = props.Get(_NM_ACTIVE_CONN_IFACE, 'Devices')
> +            devices = props.Get(network.NM_ACTIVE_CONN_IFACE, 'Devices')
>               if self._device.object_path in devices:
>                   netmgr.DeactivateConnection(
>                           conn_o,
> @@ -824,13 +800,12 @@ class GsmDeviceView(TrayIcon):
>       def _update_state(self, state, old_state, reason):
>           gsm_state = None
>
> -        if state is network.DEVICE_STATE_ACTIVATED:
> +        if state is network.NM_DEVICE_STATE_ACTIVATED:
>               gsm_state = _GSM_STATE_CONNECTED
>               connection = network.find_gsm_connection()
>               if connection is not None:
> -                connection.set_connected()
>                   self._connection_timestamp = time.time() - \
> -                        connection.get_settings().connection.timestamp
> +                        connection.get_settings('connection')['timestamp']
>                   self._connection_time_handler = gobject.timeout_add_seconds( \
>                           1, self.__connection_timecount_cb)
>                   self._palette.update_connection_time()
> @@ -838,7 +813,7 @@ class GsmDeviceView(TrayIcon):
>                   if self._palette is not None:
>                       self._palette.connection_info_box.show()
>
> -        elif state is network.DEVICE_STATE_DISCONNECTED:
> +        elif state is network.NM_DEVICE_STATE_DISCONNECTED:
>               gsm_state = _GSM_STATE_DISCONNECTED
>               self._connection_timestamp = 0
>               if self._connection_time_handler is not None:
> @@ -846,18 +821,16 @@ class GsmDeviceView(TrayIcon):
>               if self._palette is not None:
>                   self._palette.connection_info_box.hide()
>
> -        elif state in [network.DEVICE_STATE_UNMANAGED,
> -                       network.DEVICE_STATE_UNAVAILABLE,
> -                       network.DEVICE_STATE_UNKNOWN]:
> +        elif state in [network.NM_DEVICE_STATE_UNMANAGED,
> +                       network.NM_DEVICE_STATE_UNAVAILABLE,
> +                       network.NM_DEVICE_STATE_UNKNOWN]:
>               gsm_state = _GSM_STATE_NOT_READY
>
> -        elif state in [network.DEVICE_STATE_PREPARE,
> -                       network.DEVICE_STATE_CONFIG,
> -                       network.DEVICE_STATE_IP_CONFIG,
> -                       network.DEVICE_STATE_NEED_AUTH]:
> +        elif (state>= network.NM_DEVICE_STATE_PREPARE) and \
> +             (state<= network.NM_DEVICE_STATE_IP_CONFIG):
>               gsm_state = _GSM_STATE_CONNECTING
>
> -        elif state == network.DEVICE_STATE_FAILED:
> +        elif state == network.NM_DEVICE_STATE_FAILED:
>               gsm_state = _GSM_STATE_FAILED
>
>           if self._palette is not None:
> @@ -867,7 +840,7 @@ class GsmDeviceView(TrayIcon):
>           self._bus.remove_signal_receiver(self.__state_changed_cb,
>                                            signal_name='StateChanged',
>                                            path=self._device.object_path,
> -                                         dbus_interface=_NM_DEVICE_IFACE)
> +                                         dbus_interface=network.NM_DEVICE_IFACE)
>
>       def __ppp_stats_changed_cb(self, in_bytes, out_bytes):
>           self._palette.update_stats(in_bytes, out_bytes)
> @@ -903,14 +876,14 @@ class MeshDeviceObserver(object):
>           self._tray = tray
>
>           props = dbus.Interface(self._device, dbus.PROPERTIES_IFACE)
> -        props.GetAll(_NM_DEVICE_IFACE, byte_arrays=True,
> +        props.GetAll(network.NM_DEVICE_IFACE, byte_arrays=True,
>                        reply_handler=self.__get_device_props_reply_cb,
>                        error_handler=self.__get_device_props_error_cb)
>
>           self._bus.add_signal_receiver(self.__state_changed_cb,
>                                         signal_name='StateChanged',
>                                         path=self._device.object_path,
> -                                      dbus_interface=_NM_DEVICE_IFACE)
> +                                      dbus_interface=network.NM_DEVICE_IFACE)
>
>       def _remove_device_view(self):
>           self._device_view.disconnect()
> @@ -924,7 +897,7 @@ class MeshDeviceObserver(object):
>           self._bus.remove_signal_receiver(self.__state_changed_cb,
>                                            signal_name='StateChanged',
>                                            path=self._device.object_path,
> -                                         dbus_interface=_NM_DEVICE_IFACE)
> +                                         dbus_interface=network.NM_DEVICE_IFACE)
>
>       def __get_device_props_reply_cb(self, properties):
>           if 'State' in properties:
> @@ -937,10 +910,8 @@ class MeshDeviceObserver(object):
>           self._update_state(new_state)
>
>       def _update_state(self, state):
> -        if state in (network.DEVICE_STATE_PREPARE, network.DEVICE_STATE_CONFIG,
> -                     network.DEVICE_STATE_NEED_AUTH,
> -                     network.DEVICE_STATE_IP_CONFIG,
> -                     network.DEVICE_STATE_ACTIVATED):
> +        if (state>= network.NM_DEVICE_STATE_PREPARE) and \
> +           (state<= network.NM_DEVICE_STATE_ACTIVATED):
>               if self._device_view is not None:
>                   self._device_view.update_state(state)
>                   return
> @@ -961,20 +932,20 @@ class WiredDeviceObserver(object):
>           self._tray = tray
>
>           props = dbus.Interface(self._device, dbus.PROPERTIES_IFACE)
> -        props.GetAll(_NM_DEVICE_IFACE, byte_arrays=True,
> +        props.GetAll(network.NM_DEVICE_IFACE, byte_arrays=True,
>                        reply_handler=self.__get_device_props_reply_cb,
>                        error_handler=self.__get_device_props_error_cb)
>
>           self._bus.add_signal_receiver(self.__state_changed_cb,
>                                         signal_name='StateChanged',
>                                         path=self._device.object_path,
> -                                      dbus_interface=_NM_DEVICE_IFACE)
> +                                      dbus_interface=network.NM_DEVICE_IFACE)
>
>       def disconnect(self):
>           self._bus.remove_signal_receiver(self.__state_changed_cb,
>                                            signal_name='StateChanged',
>                                            path=self._device.object_path,
> -                                         dbus_interface=_NM_DEVICE_IFACE)
> +                                         dbus_interface=network.NM_DEVICE_IFACE)
>
>       def __get_device_props_reply_cb(self, properties):
>           if 'State' in properties:
> @@ -987,10 +958,10 @@ class WiredDeviceObserver(object):
>           self._update_state(new_state)
>
>       def _update_state(self, state):
> -        if state == network.DEVICE_STATE_ACTIVATED:
> +        if state == network.NM_DEVICE_STATE_ACTIVATED:
>               props = dbus.Interface(self._device, dbus.PROPERTIES_IFACE)
> -            address = props.Get(_NM_DEVICE_IFACE, 'Ip4Address')
> -            speed = props.Get(_NM_WIRED_IFACE, 'Speed')
> +            address = props.Get(network.NM_DEVICE_IFACE, 'Ip4Address')
> +            speed = props.Get(network.NM_WIRED_IFACE, 'Speed')
>               self._device_view = WiredDeviceView(speed, address)
>               self._tray.add_device(self._device_view)
>           else:
> @@ -1023,10 +994,10 @@ class NetworkManagerObserver(object):
>           self._tray = tray
>
>           try:
> -            obj = self._bus.get_object(_NM_SERVICE, _NM_PATH)
> -            self._netmgr = dbus.Interface(obj, _NM_IFACE)
> +            obj = self._bus.get_object(network.NM_SERVICE, network.NM_PATH)
> +            self._netmgr = dbus.Interface(obj, network.NM_IFACE)
>           except dbus.DBusException:
> -            logging.error('%s service not available', _NM_SERVICE)
> +            logging.error('%s service not available', network.NM_SERVICE)
>               return
>
>           self._netmgr.GetDevices(reply_handler=self.__get_devices_reply_cb,
> @@ -1034,10 +1005,10 @@ class NetworkManagerObserver(object):
>
>           self._bus.add_signal_receiver(self.__device_added_cb,
>                                         signal_name='DeviceAdded',
> -                                      dbus_interface=_NM_IFACE)
> +                                      dbus_interface=network.NM_IFACE)
>           self._bus.add_signal_receiver(self.__device_removed_cb,
>                                         signal_name='DeviceRemoved',
> -                                      dbus_interface=_NM_IFACE)
> +                                      dbus_interface=network.NM_IFACE)
>
>       def __get_devices_reply_cb(self, devices):
>           for device_op in devices:
> @@ -1047,20 +1018,20 @@ class NetworkManagerObserver(object):
>           logging.error('Failed to get devices: %s', err)
>
>       def _check_device(self, device_op):
> -        nm_device = self._bus.get_object(_NM_SERVICE, device_op)
> +        nm_device = self._bus.get_object(network.NM_SERVICE, device_op)
>           props = dbus.Interface(nm_device, dbus.PROPERTIES_IFACE)
>
> -        device_type = props.Get(_NM_DEVICE_IFACE, 'DeviceType')
> -        if device_type == network.DEVICE_TYPE_802_3_ETHERNET:
> +        device_type = props.Get(network.NM_DEVICE_IFACE, 'DeviceType')
> +        if device_type == network.NM_DEVICE_TYPE_ETHERNET:
>               device = WiredDeviceObserver(nm_device, self._tray)
>               self._devices[device_op] = device
> -        elif device_type == network.DEVICE_TYPE_802_11_WIRELESS:
> +        elif device_type == network.NM_DEVICE_TYPE_WIFI:
>               device = WirelessDeviceObserver(nm_device, self._tray)
>               self._devices[device_op] = device
> -        elif device_type == network.DEVICE_TYPE_802_11_OLPC_MESH:
> +        elif device_type == network.NM_DEVICE_TYPE_OLPC_MESH:
>               device = MeshDeviceObserver(nm_device, self._tray)
>               self._devices[device_op] = device
> -        elif device_type == network.DEVICE_TYPE_GSM_MODEM:
> +        elif device_type == network.NM_DEVICE_TYPE_MODEM:
>               device = GsmDeviceObserver(nm_device, self._tray)
>               self._devices[device_op] = device

Please run pylint for the 'Line to long' stuff. The rest looks great.

> diff --git a/src/jarabe/desktop/keydialog.py b/src/jarabe/desktop/keydialog.py
> index c72f498..8183076 100644
> --- a/src/jarabe/desktop/keydialog.py
> +++ b/src/jarabe/desktop/keydialog.py
> @@ -22,7 +22,6 @@ import gtk
>   import dbus
>
>   from jarabe.model import network
> -from jarabe.model.network import Secrets
>
>
>   IW_AUTH_ALG_OPEN_SYSTEM = 'open'
> @@ -74,12 +73,10 @@ class CanceledKeyRequestError(dbus.DBusException):
>
>
>   class KeyDialog(gtk.Dialog):
> -    def __init__(self, ssid, flags, wpa_flags, rsn_flags, dev_caps, settings,
> -                 response):
> +    def __init__(self, ssid, flags, wpa_flags, rsn_flags, dev_caps, response):
>           gtk.Dialog.__init__(self, flags=gtk.DIALOG_MODAL)
>           self.set_title('Wireless Key Required')
>
> -        self._settings = settings
>           self._response = response
>           self._entry = None
>           self._ssid = ssid
> @@ -121,10 +118,9 @@ class KeyDialog(gtk.Dialog):
>
>
>   class WEPKeyDialog(KeyDialog):
> -    def __init__(self, ssid, flags, wpa_flags, rsn_flags, dev_caps, settings,
> -                 response):
> +    def __init__(self, ssid, flags, wpa_flags, rsn_flags, dev_caps, response):
>           KeyDialog.__init__(self, ssid, flags, wpa_flags, rsn_flags,
> -                           dev_caps, settings, response)
> +                           dev_caps, response)
>
>           # WEP key type
>           self.key_store = gtk.ListStore(str, int)
> @@ -192,10 +188,8 @@ class WEPKeyDialog(KeyDialog):
>
>       def create_security(self):
>           (key, auth_alg) = self._get_security()
> -        secrets = Secrets(self._settings)
> -        secrets.wep_key = key
> -        secrets.auth_alg = auth_alg
> -        return secrets
> +        wsec = { 'wep-key0' : key, 'auth-alg' : auth_alg }
> +        return { '802-11-wireless-security' : wsec }

No white spaces needed here wsec = {'wep-key0': key, 'auth-alg': auth_alg}.

>       def _update_response_sensitivity(self, ignored=None):
>           key = self._entry.get_text()
> @@ -219,10 +213,9 @@ class WEPKeyDialog(KeyDialog):
>
>
>   class WPAKeyDialog(KeyDialog):
> -    def __init__(self, ssid, flags, wpa_flags, rsn_flags, dev_caps, settings,
> -                 response):
> +    def __init__(self, ssid, flags, wpa_flags, rsn_flags, dev_caps, response):
>           KeyDialog.__init__(self, ssid, flags, wpa_flags, rsn_flags,
> -                           dev_caps, settings, response)
> +                           dev_caps, response)
>           self.add_key_entry()
>
>           self.store = gtk.ListStore(str)
> @@ -272,9 +265,8 @@ class WPAKeyDialog(KeyDialog):
>           print 'Key: %s' % key
>
>       def create_security(self):
> -        secrets = Secrets(self._settings)
> -        secrets.psk = self._get_security()
> -        return secrets
> +        wsec = { 'psk' : self._get_security() }
> +        return { '802-11-wireless-security' : wsec }

No white spaces needed here.

>       def _update_response_sensitivity(self, ignored=None):
>           key = self._entry.get_text()
> @@ -291,14 +283,14 @@ class WPAKeyDialog(KeyDialog):
>           return False
>
>
> -def create(ssid, flags, wpa_flags, rsn_flags, dev_caps, settings, response):
> +def create(ssid, flags, wpa_flags, rsn_flags, dev_caps, response):
>       if wpa_flags == network.NM_802_11_AP_SEC_NONE and \
>               rsn_flags == network.NM_802_11_AP_SEC_NONE:
>           key_dialog = WEPKeyDialog(ssid, flags, wpa_flags, rsn_flags,
> -                                  dev_caps, settings, response)
> +                                  dev_caps, response)
>       else:
>           key_dialog = WPAKeyDialog(ssid, flags, wpa_flags, rsn_flags,
> -                                  dev_caps, settings, response)
> +                                  dev_caps, response)
>
>       key_dialog.connect('response', _key_dialog_response_cb)
>       key_dialog.show_all()
> diff --git a/src/jarabe/desktop/meshbox.py b/src/jarabe/desktop/meshbox.py
> index 6d5bb48..3c408c4 100644
> --- a/src/jarabe/desktop/meshbox.py
> +++ b/src/jarabe/desktop/meshbox.py
> @@ -48,15 +48,6 @@ from jarabe.model.adhoc import get_adhoc_manager_instance
>   from jarabe.journal import misc
>
>
> -_NM_SERVICE = 'org.freedesktop.NetworkManager'
> -_NM_IFACE = 'org.freedesktop.NetworkManager'
> -_NM_PATH = '/org/freedesktop/NetworkManager'
> -_NM_DEVICE_IFACE = 'org.freedesktop.NetworkManager.Device'
> -_NM_WIRELESS_IFACE = 'org.freedesktop.NetworkManager.Device.Wireless'
> -_NM_OLPC_MESH_IFACE = 'org.freedesktop.NetworkManager.Device.OlpcMesh'
> -_NM_ACCESSPOINT_IFACE = 'org.freedesktop.NetworkManager.AccessPoint'
> -_NM_ACTIVE_CONN_IFACE = 'org.freedesktop.NetworkManager.Connection.Active'
> -
>   _AP_ICON_NAME = 'network-wireless'
>   _OLPC_MESH_ICON_NAME = 'network-mesh'
>
> @@ -244,7 +235,7 @@ class DeviceObserver(gobject.GObject):
>           self._bus = dbus.SystemBus()
>           self.device = device
>
> -        wireless = dbus.Interface(device, _NM_WIRELESS_IFACE)
> +        wireless = dbus.Interface(device, network.NM_WIRELESS_IFACE)
>           wireless.GetAccessPoints(
>               reply_handler=self._get_access_points_reply_cb,
>               error_handler=self._get_access_points_error_cb)
> @@ -252,22 +243,22 @@ class DeviceObserver(gobject.GObject):
>           self._bus.add_signal_receiver(self.__access_point_added_cb,
>                                         signal_name='AccessPointAdded',
>                                         path=device.object_path,
> -                                      dbus_interface=_NM_WIRELESS_IFACE)
> +                                      dbus_interface=network.NM_WIRELESS_IFACE)
>           self._bus.add_signal_receiver(self.__access_point_removed_cb,
>                                         signal_name='AccessPointRemoved',
>                                         path=device.object_path,
> -                                      dbus_interface=_NM_WIRELESS_IFACE)
> +                                      dbus_interface=network.NM_WIRELESS_IFACE)
>
>       def _get_access_points_reply_cb(self, access_points_o):
>           for ap_o in access_points_o:
> -            ap = self._bus.get_object(_NM_SERVICE, ap_o)
> +            ap = self._bus.get_object(network.NM_SERVICE, ap_o)
>               self.emit('access-point-added', ap)
>
>       def _get_access_points_error_cb(self, err):
>           logging.error('Failed to get access points: %s', err)
>
>       def __access_point_added_cb(self, access_point_o):
> -        ap = self._bus.get_object(_NM_SERVICE, access_point_o)
> +        ap = self._bus.get_object(network.NM_SERVICE, access_point_o)
>           self.emit('access-point-added', ap)
>
>       def __access_point_removed_cb(self, access_point_o):
> @@ -277,11 +268,11 @@ class DeviceObserver(gobject.GObject):
>           self._bus.remove_signal_receiver(self.__access_point_added_cb,
>                                            signal_name='AccessPointAdded',
>                                            path=self.device.object_path,
> -                                         dbus_interface=_NM_WIRELESS_IFACE)
> +                                         dbus_interface=network.NM_WIRELESS_IFACE)
>           self._bus.remove_signal_receiver(self.__access_point_removed_cb,
>                                            signal_name='AccessPointRemoved',
>                                            path=self.device.object_path,
> -                                         dbus_interface=_NM_WIRELESS_IFACE)
> +                                         dbus_interface=network.NM_WIRELESS_IFACE)
>
>
>   class NetworkManagerObserver(object):
> @@ -290,7 +281,6 @@ class NetworkManagerObserver(object):
>
>       def __init__(self, box):
>           self._box = box
> -        self._bus = None

You should keep that, otherwise: 
W0201:293:NetworkManagerObserver.listen: Attribute '_bus' defined 
outside __init__

>           self._devices = {}
>           self._netmgr = None
>           self._olpc_mesh_device_o = None
> @@ -301,10 +291,9 @@ class NetworkManagerObserver(object):
>       def listen(self):
>           try:
>               self._bus = dbus.SystemBus()
> -            obj = self._bus.get_object(_NM_SERVICE, _NM_PATH)
> -            self._netmgr = dbus.Interface(obj, _NM_IFACE)
> +            self._netmgr = network.get_manager()
>           except dbus.DBusException:
> -            logging.debug('%s service not available', _NM_SERVICE)
> +            logging.debug('NetworkManager not available')
>               return
>
>           self._netmgr.GetDevices(reply_handler=self.__get_devices_reply_cb,
> @@ -312,38 +301,37 @@ class NetworkManagerObserver(object):
>
>           self._bus.add_signal_receiver(self.__device_added_cb,
>                                         signal_name='DeviceAdded',
> -                                      dbus_interface=_NM_IFACE)
> +                                      dbus_interface=network.NM_IFACE)
>           self._bus.add_signal_receiver(self.__device_removed_cb,
>                                         signal_name='DeviceRemoved',
> -                                      dbus_interface=_NM_IFACE)
> +                                      dbus_interface=network.NM_IFACE)
>           self._bus.add_signal_receiver(self.__properties_changed_cb,
>                                         signal_name='PropertiesChanged',
> -                                      dbus_interface=_NM_IFACE)
> +                                      dbus_interface=network.NM_IFACE)
>
> -        settings = network.get_settings()
> -        if settings is not None:
> -            settings.secrets_request.connect(self.__secrets_request_cb)
> +        secret_agent = network.get_secret_agent()
> +        if secret_agent is not None:
> +            secret_agent.secrets_request.connect(self.__secrets_request_cb)
>
>       def __secrets_request_cb(self, **kwargs):
>           # FIXME It would be better to do all of this async, but I cannot think
>           # of a good way to. NM could really use some love here.
>
>           netmgr_props = dbus.Interface(self._netmgr, dbus.PROPERTIES_IFACE)
> -        active_connections_o = netmgr_props.Get(_NM_IFACE, 'ActiveConnections')
> +        active_connections_o = netmgr_props.Get(network.NM_IFACE, 'ActiveConnections')
>
>           for conn_o in active_connections_o:
> -            obj = self._bus.get_object(_NM_IFACE, conn_o)
> +            obj = self._bus.get_object(network.NM_IFACE, conn_o)
>               props = dbus.Interface(obj, dbus.PROPERTIES_IFACE)
> -            state = props.Get(_NM_ACTIVE_CONN_IFACE, 'State')
> +            state = props.Get(network.NM_ACTIVE_CONN_IFACE, 'State')
>               if state == network.NM_ACTIVE_CONNECTION_STATE_ACTIVATING:
> -                ap_o = props.Get(_NM_ACTIVE_CONN_IFACE, 'SpecificObject')
> +                ap_o = props.Get(network.NM_ACTIVE_CONN_IFACE, 'SpecificObject')
>                   found = False
>                   if ap_o != '/':
>                       for net in self._box.wireless_networks.values():
>                           if net.find_ap(ap_o) is not None:
>                               found = True
> -                            settings = kwargs['connection'].get_settings()
> -                            net.create_keydialog(settings, kwargs['response'])
> +                            net.create_keydialog(kwargs['response'])
>                   if not found:
>                       logging.error('Could not determine AP for specific object'
>                                     ' %s', conn_o)
> @@ -356,11 +344,11 @@ class NetworkManagerObserver(object):
>           logging.error('Failed to get devices: %s', err)
>
>       def _check_device(self, device_o):
> -        device = self._bus.get_object(_NM_SERVICE, device_o)
> +        device = self._bus.get_object(network.NM_SERVICE, device_o)
>           props = dbus.Interface(device, dbus.PROPERTIES_IFACE)
>
> -        device_type = props.Get(_NM_DEVICE_IFACE, 'DeviceType')
> -        if device_type == network.DEVICE_TYPE_802_11_WIRELESS:
> +        device_type = props.Get(network.NM_DEVICE_IFACE, 'DeviceType')
> +        if device_type == network.NM_DEVICE_TYPE_WIFI:
>               self._devices[device_o] = DeviceObserver(device)
>               self._devices[device_o].connect('access-point-added',
>                                               self.__ap_added_cb)
> @@ -368,7 +356,7 @@ class NetworkManagerObserver(object):
>                                               self.__ap_removed_cb)
>               if self._have_adhoc_networks:
>                   self._box.add_adhoc_networks(device)
> -        elif device_type == network.DEVICE_TYPE_802_11_OLPC_MESH:
> +        elif device_type == network.NM_DEVICE_TYPE_OLPC_MESH:
>               self._olpc_mesh_device_o = device_o
>               self._box.enable_olpc_mesh(device)
>
> diff --git a/src/jarabe/desktop/networkviews.py b/src/jarabe/desktop/networkviews.py
> index 677452d..0e461a3 100644
> --- a/src/jarabe/desktop/networkviews.py
> +++ b/src/jarabe/desktop/networkviews.py
> @@ -42,15 +42,6 @@ from jarabe.model.network import WirelessSecurity
>   from jarabe.model.adhoc import get_adhoc_manager_instance
>
>
> -_NM_SERVICE = 'org.freedesktop.NetworkManager'
> -_NM_IFACE = 'org.freedesktop.NetworkManager'
> -_NM_PATH = '/org/freedesktop/NetworkManager'
> -_NM_DEVICE_IFACE = 'org.freedesktop.NetworkManager.Device'
> -_NM_WIRELESS_IFACE = 'org.freedesktop.NetworkManager.Device.Wireless'
> -_NM_OLPC_MESH_IFACE = 'org.freedesktop.NetworkManager.Device.OlpcMesh'
> -_NM_ACCESSPOINT_IFACE = 'org.freedesktop.NetworkManager.AccessPoint'
> -_NM_ACTIVE_CONN_IFACE = 'org.freedesktop.NetworkManager.Connection.Active'
> -
>   _AP_ICON_NAME = 'network-wireless'
>   _OLPC_MESH_ICON_NAME = 'network-mesh'
>
> @@ -105,24 +96,21 @@ class WirelessNetworkView(CanvasPulsingIcon):
>           self._update_badge()
>
>           interface_props = dbus.Interface(self._device, dbus.PROPERTIES_IFACE)
> -        interface_props.Get(_NM_DEVICE_IFACE, 'State',
> -                            reply_handler=self.__get_device_state_reply_cb,
> -                            error_handler=self.__get_device_state_error_cb)

What was the reasoning here, to not getting the state anymore and get it 
when we have the ActiveAccessPoint? Any issue we are fixing?

> -        interface_props.Get(_NM_WIRELESS_IFACE, 'WirelessCapabilities',
> +        interface_props.Get(network.NM_WIRELESS_IFACE, 'WirelessCapabilities',
>                               reply_handler=self.__get_device_caps_reply_cb,
>                               error_handler=self.__get_device_caps_error_cb)
> -        interface_props.Get(_NM_WIRELESS_IFACE, 'ActiveAccessPoint',
> +        interface_props.Get(network.NM_WIRELESS_IFACE, 'ActiveAccessPoint',
>                               reply_handler=self.__get_active_ap_reply_cb,
>                               error_handler=self.__get_active_ap_error_cb)
>
>           self._bus.add_signal_receiver(self.__device_state_changed_cb,
>                                         signal_name='StateChanged',
>                                         path=self._device.object_path,
> -                                      dbus_interface=_NM_DEVICE_IFACE)
> +                                      dbus_interface=network.NM_DEVICE_IFACE)
>           self._bus.add_signal_receiver(self.__wireless_properties_changed_cb,
>                                         signal_name='PropertiesChanged',
>                                         path=self._device.object_path,
> -                                      dbus_interface=_NM_WIRELESS_IFACE)
> +                                      dbus_interface=network.NM_WIRELESS_IFACE)
>
>       def _create_palette(self):
>           icon_name = get_icon_state(_AP_ICON_NAME, self._strength)
> @@ -168,6 +156,10 @@ class WirelessNetworkView(CanvasPulsingIcon):
>
>       def __get_active_ap_reply_cb(self, ap_path):
>           self.__update_active_ap(ap_path)
> +        interface_props = dbus.Interface(self._device, dbus.PROPERTIES_IFACE)
> +        interface_props.Get(network.NM_DEVICE_IFACE, 'State',
> +                            reply_handler=self.__get_device_state_reply_cb,
> +                            error_handler=self.__get_device_state_error_cb)
>
>       def __get_active_ap_error_cb(self, err):
>           logging.error('Error getting the active access point: %s', err)
> @@ -182,6 +174,7 @@ class WirelessNetworkView(CanvasPulsingIcon):
>           self._device_state = state
>           self._update_state()
>           self._update_color()
> +        self._update_icon()
>           self._update_badge()
>
>       def __get_device_state_error_cb(self, err):
> @@ -192,7 +185,7 @@ class WirelessNetworkView(CanvasPulsingIcon):
>                   network.is_sugar_adhoc_network(self._name):
>               channel = max([1] + [ap.channel for ap in
>                                    self._access_points.values()])
> -            if self._device_state == network.DEVICE_STATE_ACTIVATED and \
> +            if self._device_state == network.NM_DEVICE_STATE_ACTIVATED and \
>                       self._active_ap is not None:
>                   icon_name = 'network-adhoc-%s-connected' % channel
>               else:
> @@ -201,7 +194,7 @@ class WirelessNetworkView(CanvasPulsingIcon):
>               icon = self._palette.props.icon
>               icon.props.icon_name = icon_name
>           else:
> -            if self._device_state == network.DEVICE_STATE_ACTIVATED and \
> +            if self._device_state == network.NM_DEVICE_STATE_ACTIVATED and \
>                       self._active_ap is not None:
>                   icon_name = '%s-connected' % _AP_ICON_NAME
>               else:
> @@ -232,22 +225,19 @@ class WirelessNetworkView(CanvasPulsingIcon):
>           if self._active_ap is not None:
>               state = self._device_state
>           else:
> -            state = network.DEVICE_STATE_UNKNOWN
> +            state = network.NM_DEVICE_STATE_UNKNOWN
>
> -        if state == network.DEVICE_STATE_PREPARE or \
> -           state == network.DEVICE_STATE_CONFIG or \
> -           state == network.DEVICE_STATE_NEED_AUTH or \
> -           state == network.DEVICE_STATE_IP_CONFIG:
> +        if state == network.NM_DEVICE_STATE_PREPARE or \
> +           state == network.NM_DEVICE_STATE_CONFIG or \
> +           state == network.NM_DEVICE_STATE_NEED_AUTH or \
> +           state == network.NM_DEVICE_STATE_IP_CONFIG:
>               if self._disconnect_item:
>                   self._disconnect_item.show()
>               self._connect_item.hide()
>               self._palette.props.secondary_text = _('Connecting...')
>               self.props.pulsing = True
> -        elif state == network.DEVICE_STATE_ACTIVATED:
> -            connection = network.find_connection_by_ssid(self._name)
> -            if connection is not None:
> -                if self._mode == network.NM_802_11_MODE_INFRA:
> -                    connection.set_connected()
> +        elif state == network.NM_DEVICE_STATE_ACTIVATED:
> +            network.set_connected()
>               if self._disconnect_item:
>                   self._disconnect_item.show()
>               self._connect_item.hide()
> @@ -269,11 +259,6 @@ class WirelessNetworkView(CanvasPulsingIcon):
>               self.alpha = 1.0
>
>       def _disconnect_activate_cb(self, item):
> -        if self._mode == network.NM_802_11_MODE_INFRA:
> -            connection = network.find_connection_by_ssid(self._name)
> -            if connection:
> -                connection.disable_autoconnect()
> -
>           ap_paths = self._access_points.keys()
>           network.disconnect_access_points(ap_paths)
>
> @@ -317,7 +302,7 @@ class WirelessNetworkView(CanvasPulsingIcon):
>               return None
>
>           if (self._rsn_flags&  network.NM_802_11_AP_SEC_KEY_MGMT_PSK) and \
> -                (self._device_caps&  network.NM_802_11_DEVICE_CAP_RSN):
> +                (self._device_caps&  network.NM_WIFI_DEVICE_CAP_RSN):
>               # WPA2 PSK first
>               pairwise = self._add_ciphers_from_flags(self._rsn_flags, True)
>               group = self._add_ciphers_from_flags(self._rsn_flags, False)
> @@ -329,7 +314,7 @@ class WirelessNetworkView(CanvasPulsingIcon):
>               return wireless_security
>
>           if (self._wpa_flags&  network.NM_802_11_AP_SEC_KEY_MGMT_PSK) and \
> -                (self._device_caps&  network.NM_802_11_DEVICE_CAP_WPA):
> +                (self._device_caps&  network.NM_WIFI_DEVICE_CAP_WPA):
>               # WPA PSK
>               pairwise = self._add_ciphers_from_flags(self._wpa_flags, True)
>               group = self._add_ciphers_from_flags(self._wpa_flags, False)
> @@ -347,54 +332,47 @@ class WirelessNetworkView(CanvasPulsingIcon):
>           self._connect()
>
>       def _connect(self):
> +        # Activate existing connection, if there is one
>           connection = network.find_connection_by_ssid(self._name)
> -        if connection is None:
> -            settings = Settings()
> -            settings.connection.id = 'Auto ' + self._name
> -            uuid = settings.connection.uuid = unique_id()
> -            settings.connection.type = '802-11-wireless'
> -            settings.wireless.ssid = self._name
> -
> -            if self._mode == network.NM_802_11_MODE_INFRA:
> -                settings.wireless.mode = 'infrastructure'
> -            elif self._mode == network.NM_802_11_MODE_ADHOC:
> -                settings.wireless.mode = 'adhoc'
> -                settings.wireless.band = 'bg'
> -                settings.ip4_config = IP4Config()
> -                settings.ip4_config.method = 'link-local'
> -
> -            wireless_security = self._get_security()
> -            settings.wireless_security = wireless_security
> -
> -            if wireless_security is not None:
> -                settings.wireless.security = '802-11-wireless-security'
> +        if connection:
> +            logging.debug("Activating existing connection for %s", self._name)
> +            connection.activate(self._device)
> +            return
>
> -            connection = network.add_connection(uuid, settings)
> +        # Otherwise, create new connection and activate it
> +        logging.debug("Creating new connection for %s", self._name)
> +        settings = Settings()
> +        settings.connection.id = str(self._name)
> +        settings.connection.uuid = unique_id()
> +        settings.connection.type = '802-11-wireless'
> +        settings.wireless.ssid = self._name
>
> -        obj = self._bus.get_object(_NM_SERVICE, _NM_PATH)
> -        netmgr = dbus.Interface(obj, _NM_IFACE)
> +        if self._mode == network.NM_802_11_MODE_INFRA:
> +            settings.wireless.mode = 'infrastructure'
> +            settings.connection.autoconnect = True
> +        elif self._mode == network.NM_802_11_MODE_ADHOC:
> +            settings.wireless.mode = 'adhoc'
> +            settings.wireless.band = 'bg'
> +            settings.ip4_config = IP4Config()
> +            settings.ip4_config.method = 'link-local'
>
> -        netmgr.ActivateConnection(network.SETTINGS_SERVICE, connection.path,
> -                                  self._device.object_path,
> -                                  '/',
> -                                  reply_handler=self.__activate_reply_cb,
> -                                  error_handler=self.__activate_error_cb)
> +        wireless_security = self._get_security()
> +        settings.wireless_security = wireless_security
>
> -    def __activate_reply_cb(self, connection):
> -        logging.debug('Connection activated: %s', connection)
> +        if wireless_security is not None:
> +            settings.wireless.security = '802-11-wireless-security'
>
> -    def __activate_error_cb(self, err):
> -        logging.error('Failed to activate connection: %s', err)
> +        network.add_and_activate_connection(self._device, settings,
> +                                            self.get_first_ap().model)
>
>       def set_filter(self, query):
>           self._filtered = self._name.lower().find(query) == -1
>           self._update_icon()
>           self._update_color()
>
> -    def create_keydialog(self, settings, response):
> +    def create_keydialog(self, response):
>           keydialog.create(self._name, self._flags, self._wpa_flags,
> -                         self._rsn_flags, self._device_caps, settings,
> -                         response)
> +                         self._rsn_flags, self._device_caps, response)
>
>       def update_strength(self):
>           if self._active_ap is not None:
> @@ -431,6 +409,9 @@ class WirelessNetworkView(CanvasPulsingIcon):
>               return None
>           return self._access_points[ap_path]
>
> +    def get_first_ap(self):
> +        return self._access_points.values()[0]
> +
>       def is_olpc_mesh(self):
>           return self._mode == network.NM_802_11_MODE_ADHOC \
>               and self.name == 'olpc-mesh'
> @@ -446,11 +427,11 @@ class WirelessNetworkView(CanvasPulsingIcon):
>           self._bus.remove_signal_receiver(self.__device_state_changed_cb,
>                                            signal_name='StateChanged',
>                                            path=self._device.object_path,
> -                                         dbus_interface=_NM_DEVICE_IFACE)
> +                                         dbus_interface=network.NM_DEVICE_IFACE)
>           self._bus.remove_signal_receiver(self.__wireless_properties_changed_cb,
>                                            signal_name='PropertiesChanged',
>                                            path=self._device.object_path,
> -                                         dbus_interface=_NM_WIRELESS_IFACE)
> +                                         dbus_interface=network.NM_WIRELESS_IFACE)
>
>
>   class SugarAdhocView(CanvasPulsingIcon):
> @@ -526,9 +507,9 @@ class SugarAdhocView(CanvasPulsingIcon):
>           if self._channel == channel:
>               state = device_state
>           else:
> -            state = network.DEVICE_STATE_UNKNOWN
> +            state = network.NM_DEVICE_STATE_UNKNOWN
>
> -        if state == network.DEVICE_STATE_ACTIVATED:
> +        if state == network.NM_DEVICE_STATE_ACTIVATED:
>               icon_name = '%s-connected' % (self._ICON_NAME + str(self._channel))
>           else:
>               icon_name = self._ICON_NAME + str(self._channel)
> @@ -538,16 +519,16 @@ class SugarAdhocView(CanvasPulsingIcon):
>               icon = self._palette.props.icon
>               icon.props.icon_name = icon_name
>
> -        if state in [network.DEVICE_STATE_PREPARE,
> -                     network.DEVICE_STATE_CONFIG,
> -                     network.DEVICE_STATE_NEED_AUTH,
> -                     network.DEVICE_STATE_IP_CONFIG]:
> +        if state in [network.NM_DEVICE_STATE_PREPARE,
> +                     network.NM_DEVICE_STATE_CONFIG,
> +                     network.NM_DEVICE_STATE_NEED_AUTH,
> +                     network.NM_DEVICE_STATE_IP_CONFIG]:

Maybe use here the same >= <= as in the other place:

        if (state>= network.NM_DEVICE_STATE_PREPARE) and \
            (state<= network.NM_DEVICE_STATE_ACTIVATED):

>               if self._disconnect_item:
>                   self._disconnect_item.show()
>               self._connect_item.hide()
>               self._palette.props.secondary_text = _('Connecting...')
>               self.props.pulsing = True
> -        elif state == network.DEVICE_STATE_ACTIVATED:
> +        elif state == network.NM_DEVICE_STATE_ACTIVATED:
>               if self._disconnect_item:
>                   self._disconnect_item.show()
>               self._connect_item.hide()
> @@ -609,21 +590,21 @@ class OlpcMeshView(CanvasPulsingIcon):
>           self.connect('button-release-event', self.__button_release_event_cb)
>
>           interface_props = dbus.Interface(device, dbus.PROPERTIES_IFACE)
> -        interface_props.Get(_NM_DEVICE_IFACE, 'State',
> +        interface_props.Get(network.NM_DEVICE_IFACE, 'State',
>                               reply_handler=self.__get_device_state_reply_cb,
>                               error_handler=self.__get_device_state_error_cb)
> -        interface_props.Get(_NM_OLPC_MESH_IFACE, 'ActiveChannel',
> +        interface_props.Get(network.NM_OLPC_MESH_IFACE, 'ActiveChannel',
>                               reply_handler=self.__get_active_channel_reply_cb,
>                               error_handler=self.__get_active_channel_error_cb)
>
>           self._bus.add_signal_receiver(self.__device_state_changed_cb,
>                                         signal_name='StateChanged',
>                                         path=device.object_path,
> -                                      dbus_interface=_NM_DEVICE_IFACE)
> +                                      dbus_interface=network.NM_DEVICE_IFACE)
>           self._bus.add_signal_receiver(self.__wireless_properties_changed_cb,
>                                         signal_name='PropertiesChanged',
>                                         path=device.object_path,
> -                                      dbus_interface=_NM_OLPC_MESH_IFACE)
> +                                      dbus_interface=network.NM_OLPC_MESH_IFACE)
>
>           pulse_color = XoColor('%s,%s' % (style.COLOR_BUTTON_GREY.get_svg(),
>                                            style.COLOR_TRANSPARENT.get_svg()))
> @@ -671,18 +652,18 @@ class OlpcMeshView(CanvasPulsingIcon):
>           if self._active:
>               state = self._device_state
>           else:
> -            state = network.DEVICE_STATE_UNKNOWN
> +            state = network.NM_DEVICE_STATE_UNKNOWN
>
> -        if state in [network.DEVICE_STATE_PREPARE,
> -                     network.DEVICE_STATE_CONFIG,
> -                     network.DEVICE_STATE_NEED_AUTH,
> -                     network.DEVICE_STATE_IP_CONFIG]:
> +        if state in [network.NM_DEVICE_STATE_PREPARE,
> +                     network.NM_DEVICE_STATE_CONFIG,
> +                     network.NM_DEVICE_STATE_NEED_AUTH,
> +                     network.NM_DEVICE_STATE_IP_CONFIG]:
>               if self._disconnect_item:
>                   self._disconnect_item.show()
>               self._connect_item.hide()
>               self._palette.props.secondary_text = _('Connecting...')
>               self.props.pulsing = True
> -        elif state == network.DEVICE_STATE_ACTIVATED:
> +        elif state == network.NM_DEVICE_STATE_ACTIVATED:
>               if self._disconnect_item:
>                   self._disconnect_item.show()
>               self._connect_item.hide()
> @@ -711,12 +692,6 @@ class OlpcMeshView(CanvasPulsingIcon):
>       def _connect(self):
>           self._mesh_mgr.user_activate_channel(self._channel)
>
> -    def __activate_reply_cb(self, connection):
> -        logging.debug('Connection activated: %s', connection)
> -
> -    def __activate_error_cb(self, err):
> -        logging.error('Failed to activate connection: %s', err)
> -
>       def set_filter(self, query):
>           self._filtered = (query != '')
>           self._update_color()
> @@ -727,8 +702,8 @@ class OlpcMeshView(CanvasPulsingIcon):
>           self._bus.remove_signal_receiver(self.__device_state_changed_cb,
>                                            signal_name='StateChanged',
>                                            path=device_object_path,
> -                                         dbus_interface=_NM_DEVICE_IFACE)
> +                                         dbus_interface=network.NM_DEVICE_IFACE)
>           self._bus.remove_signal_receiver(self.__wireless_properties_changed_cb,
>                                            signal_name='PropertiesChanged',
>                                            path=device_object_path,
> -                                         dbus_interface=_NM_OLPC_MESH_IFACE)
> +                                         dbus_interface=network.NM_OLPC_MESH_IFACE)

Regards,
    Simon


More information about the Sugar-devel mailing list