From f907ceeae67f0a42ddd4a1b4e17ddcaf5cfa8ae8 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Sun, 25 Feb 2007 14:30:17 +0100 Subject: [PATCH] Display strength of wireless device/networks --- shell/hardware/nmclient.py | 7 +++++-- shell/model/MeshModel.py | 18 +++++++++++++++++- shell/model/devices/device.py | 5 ++++- shell/model/devices/wirelessnetwork.py | 20 +++++++++++++++++--- shell/view/devices/wirelessnetwork.py | 21 ++++++++++++++++++++- shell/view/home/MeshBox.py | 12 +++++++++++- 6 files changed, 74 insertions(+), 9 deletions(-) diff --git a/shell/hardware/nmclient.py b/shell/hardware/nmclient.py index 90a21258..41bf5e2e 100644 --- a/shell/hardware/nmclient.py +++ b/shell/hardware/nmclient.py @@ -70,10 +70,12 @@ NM_802_11_CAP_CIPHER_WEP104 = 0x00002000 NM_802_11_CAP_CIPHER_TKIP = 0x00004000 NM_802_11_CAP_CIPHER_CCMP = 0x00008000 - class Network(gobject.GObject): __gsignals__ = { - 'init-failed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])) + 'init-failed' : (gobject.SIGNAL_RUN_FIRST, + gobject.TYPE_NONE, ([])), + 'strength-changed': (gobject.SIGNAL_RUN_FIRST, + gobject.TYPE_NONE, ([])) } def __init__(self, op): @@ -122,6 +124,7 @@ class Network(gobject.GObject): def set_strength(self, strength): self._strength = strength + self.emit('strength-changed') def is_valid(self): return self._valid diff --git a/shell/model/MeshModel.py b/shell/model/MeshModel.py index 7c86bbc7..c2d42ba6 100644 --- a/shell/model/MeshModel.py +++ b/shell/model/MeshModel.py @@ -22,11 +22,23 @@ from sugar.activity import bundleregistry from model.BuddyModel import BuddyModel from hardware import hardwaremanager -class AccessPointModel: +class AccessPointModel(gobject.GObject): + __gproperties__ = { + 'strength' : (int, None, None, 0, 100, 0, + gobject.PARAM_READABLE) + } + def __init__(self, nm_device, nm_network): + gobject.GObject.__init__(self) self._nm_network = nm_network self._nm_device = nm_device + self._nm_network.connect('strength-changed', + self._strength_changed_cb) + + def _strength_changed_cb(self, nm_network): + self.notity('strength') + def get_id(self): return self._nm_network.get_op() @@ -39,6 +51,10 @@ class AccessPointModel: def get_nm_network(self): return self._nm_network + def do_get_property(self, pspec): + if pspec.name == 'strength': + return self._nm_network.get_strength() + class ActivityModel: def __init__(self, activity, bundle, service): self._service = service diff --git a/shell/model/devices/device.py b/shell/model/devices/device.py index 02afd3cd..32bee0d2 100644 --- a/shell/model/devices/device.py +++ b/shell/model/devices/device.py @@ -1,7 +1,10 @@ +import gobject + from sugar import util -class Device(object): +class Device(gobject.GObject): def __init__(self): + gobject.GObject.__init__(self) self._id = util.unique_id() def get_type(self): diff --git a/shell/model/devices/wirelessnetwork.py b/shell/model/devices/wirelessnetwork.py index 97f16cd5..efbc1b10 100644 --- a/shell/model/devices/wirelessnetwork.py +++ b/shell/model/devices/wirelessnetwork.py @@ -1,15 +1,29 @@ +import gobject + from model.devices import device class Device(device.Device): + __gproperties__ = { + 'strength' : (int, None, None, 0, 100, 0, + gobject.PARAM_READABLE) + } + def __init__(self, nm_device): device.Device.__init__(self) self._nm_device = nm_device + self._nm_device.connect('strength-changed', + self._strength_changed_cb) + + def _strength_changed_cb(self, nm_device): + self.notity('strength') + + def do_get_property(self, pspec): + if pspec.name == 'strength': + return self._nm_device.get_strength() + def get_type(self): return 'wirelessnetwork' def get_id(self): return self._nm_device.get_op() - - def get_level(self): - return self._nm_device.get_strength() diff --git a/shell/view/devices/wirelessnetwork.py b/shell/view/devices/wirelessnetwork.py index 659ec6b2..a08de583 100644 --- a/shell/view/devices/wirelessnetwork.py +++ b/shell/view/devices/wirelessnetwork.py @@ -3,4 +3,23 @@ from view.devices import deviceview class DeviceView(deviceview.DeviceView): def __init__(self, model): deviceview.DeviceView.__init__(self, model) - self.props.icon_name = 'theme:stock-net-wireless-00' + self._model = model + + self._update_icon() + model.connect('notify::strength', self._strength_changed_cb) + + def _strength_changed_cb(self, model, pspec): + self._update_icon() + + def _update_icon(self): + strength = self._model.props.strength + if strength < 21: + self.props.icon_name = 'theme:stock-net-wireless-00' + elif strength < 41: + self.props.icon_name = 'theme:stock-net-wireless-21-40' + elif strength < 61: + self.props.icon_name = 'theme:stock-net-wireless-41-60' + elif strength < 81: + self.props.icon_name = 'theme:stock-net-wireless-61-80' + else: + self.props.icon_name = 'theme:stock-net-wireless-81-100' diff --git a/shell/view/home/MeshBox.py b/shell/view/home/MeshBox.py index 55d8cce1..707ad6e4 100644 --- a/shell/view/home/MeshBox.py +++ b/shell/view/home/MeshBox.py @@ -42,7 +42,17 @@ class AccessPointView(CanvasIcon): network_manager.set_active_device(device, network) def _update_icon(self): - self.props.icon_name = 'theme:stock-net-wireless-00' + strength = self._model.props.strength + if strength < 21: + self.props.icon_name = 'theme:stock-net-wireless-00' + elif strength < 41: + self.props.icon_name = 'theme:stock-net-wireless-21-40' + elif strength < 61: + self.props.icon_name = 'theme:stock-net-wireless-41-60' + elif strength < 81: + self.props.icon_name = 'theme:stock-net-wireless-61-80' + else: + self.props.icon_name = 'theme:stock-net-wireless-81-100' class ActivityView(SnowflakeBox): def __init__(self, shell, menu_shell, model):