diff --git a/shell/hardware/nmclient.py b/shell/hardware/nmclient.py index b3b05c81..c98f1e2d 100644 --- a/shell/hardware/nmclient.py +++ b/shell/hardware/nmclient.py @@ -418,6 +418,21 @@ class NMClient(gobject.GObject): except dbus.DBusException: pass + def set_active_device(self, device, network): + net_op = "" + if network: + net_op = network.get_op() + try: + # NM 0.6.4 and earlier have a bug which returns an + # InvalidArguments error if no security information is passed + # for wireless networks + self._nm_obj.setActiveDevice(device.get_op(), network.get_ssid()) + except dbus.DBusException, e: + if str(e).find("invalid arguments"): + pass + else: + raise dbus.DBusException(e) + def get_key_for_network(self, net, async_cb, async_err_cb): pass diff --git a/shell/model/MeshModel.py b/shell/model/MeshModel.py index 13dc1acd..7c86bbc7 100644 --- a/shell/model/MeshModel.py +++ b/shell/model/MeshModel.py @@ -23,8 +23,9 @@ from model.BuddyModel import BuddyModel from hardware import hardwaremanager class AccessPointModel: - def __init__(self, nm_network): + def __init__(self, nm_device, nm_network): self._nm_network = nm_network + self._nm_device = nm_device def get_id(self): return self._nm_network.get_op() @@ -32,6 +33,12 @@ class AccessPointModel: def get_name(self): return self._nm_network.get_ssid() + def get_nm_device(self): + return self._nm_device + + def get_nm_network(self): + return self._nm_network + class ActivityModel: def __init__(self, activity, bundle, service): self._service = service @@ -104,22 +111,22 @@ class MeshModel(gobject.GObject): def _nm_device_activated_cb(self, manager, nm_device): self._add_network_device(nm_device) - def _nm_network_appeared_cb(self, manager, nm_network): - self._add_access_point(nm_network) + def _nm_network_appeared_cb(self, nm_device, nm_network): + self._add_access_point(nm_device, nm_network) - def _nm_network_disappeared_cb(self, manager, nm_network): - self._remove_access_point(nm_network) + def _nm_network_disappeared_cb(self, nm_device, nm_network): + self._remove_access_point(nm_device, nm_network) def _add_network_device(self, nm_device): - for network in nm_device.get_networks(): - self._add_access_point(network) + for nm_network in nm_device.get_networks(): + self._add_access_point(nm_device, nm_network) nm_device.connect('network-appeared', self._nm_network_appeared_cb) nm_device.connect('network-disappeared', self._nm_network_disappeared_cb) - def _add_access_point(self, nm_network): - model = AccessPointModel(nm_network) + def _add_access_point(self, nm_device, nm_network): + model = AccessPointModel(nm_device, nm_network) self._access_points[nm_network.get_op()] = model self.emit('access-point-added', model) diff --git a/shell/view/home/MeshBox.py b/shell/view/home/MeshBox.py index 39fd63a6..55d8cce1 100644 --- a/shell/view/home/MeshBox.py +++ b/shell/view/home/MeshBox.py @@ -22,13 +22,25 @@ import gobject from sugar.graphics.spreadbox import SpreadBox from sugar.graphics.snowflakebox import SnowflakeBox from sugar.graphics.canvasicon import CanvasIcon +from hardware import hardwaremanager from view.BuddyIcon import BuddyIcon class AccessPointView(CanvasIcon): def __init__(self, model): CanvasIcon.__init__(self, tooltip=model.get_name()) + self._model = model + + self.connect('activated', self._activate_cb) self._update_icon() + def _activate_cb(self, icon): + network_manager = hardwaremanager.get_network_manager() + + device = self._model.get_nm_device() + network = self._model.get_nm_network() + + network_manager.set_active_device(device, network) + def _update_icon(self): self.props.icon_name = 'theme:stock-net-wireless-00'