Display strength of wireless device/networks

This commit is contained in:
Marco Pesenti Gritti 2007-02-25 14:30:17 +01:00
parent 81e2e9ed8d
commit f907ceeae6
6 changed files with 74 additions and 9 deletions

View File

@ -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

View File

@ -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

View File

@ -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):

View File

@ -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()

View File

@ -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'

View File

@ -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):