Get the wireless device to show.

This commit is contained in:
Marco Pesenti Gritti 2007-02-25 02:28:14 +01:00
parent 755250947a
commit 6a4170a51e
3 changed files with 43 additions and 7 deletions

View File

@ -156,8 +156,6 @@ class Device(gobject.GObject):
self._type = props[2] self._type = props[2]
self._udi = props[3] self._udi = props[3]
self._active = props[4] self._active = props[4]
if self._active:
self.emit('activated')
self._link = props[15] self._link = props[15]
self._caps = props[17] self._caps = props[17]
@ -170,6 +168,9 @@ class Device(gobject.GObject):
self._valid = True self._valid = True
if self._active:
self.emit('activated')
def _update_networks(self, net_ops, active_op): def _update_networks(self, net_ops, active_op):
for op in net_ops: for op in net_ops:
net = Network(op) net = Network(op)
@ -261,8 +262,19 @@ NM_STATE_CONNECTING = 2
NM_STATE_CONNECTED = 3 NM_STATE_CONNECTED = 3
NM_STATE_DISCONNECTED = 4 NM_STATE_DISCONNECTED = 4
class NMClient(object): class NMClient(gobject.GObject):
__gsignals__ = {
'device-activated' : (gobject.SIGNAL_RUN_FIRST,
gobject.TYPE_NONE,
([gobject.TYPE_PYOBJECT])),
'device-removed' : (gobject.SIGNAL_RUN_FIRST,
gobject.TYPE_NONE,
([gobject.TYPE_PYOBJECT]))
}
def __init__(self): def __init__(self):
gobject.GObject.__init__(self)
self.nminfo = None self.nminfo = None
self._nm_present = False self._nm_present = False
self._nm_state = NM_STATE_UNKNOWN self._nm_state = NM_STATE_UNKNOWN
@ -329,6 +341,8 @@ class NMClient(object):
dev.disconnect('strength-changed') dev.disconnect('strength-changed')
del self._devices[dev_op] del self._devices[dev_op]
self.emit('device-removed', dev)
def _dev_activated_cb(self, dev): def _dev_activated_cb(self, dev):
op = dev.get_op() op = dev.get_op()
if not self._devices.has_key(op): if not self._devices.has_key(op):
@ -337,6 +351,8 @@ class NMClient(object):
return return
self._active_device = op self._active_device = op
self.emit('device-activated', dev)
def _dev_strength_changed_cb(self, dev, strength): def _dev_strength_changed_cb(self, dev, strength):
op = dev.get_op() op = dev.get_op()
if not self._devices.has_key(op): if not self._devices.has_key(op):

View File

@ -5,6 +5,7 @@ from model.devices import wirednetwork
from model.devices import wirelessnetwork from model.devices import wirelessnetwork
from model.devices import battery from model.devices import battery
from hardware import hardwaremanager from hardware import hardwaremanager
from hardware import nmclient
class DevicesModel(gobject.GObject): class DevicesModel(gobject.GObject):
__gsignals__ = { __gsignals__ = {
@ -26,16 +27,22 @@ class DevicesModel(gobject.GObject):
def _observe_network_manager(self): def _observe_network_manager(self):
network_manager = hardwaremanager.get_network_manager() network_manager = hardwaremanager.get_network_manager()
for device in network_manager.get_devices(): for device in network_manager.get_devices():
self._check_network_device(device) self._check_network_device(device)
network_manager.connect('device-activated',
self._network_device_added_cb)
def _network_device_added_cb(self, network_manager, device):
self._check_network_device(device)
def _check_network_device(self, device): def _check_network_device(self, device):
if not device.is_valid(): if not device.is_valid():
return return
if device.get_type() == DEVICE_TYPE_802_11_WIRELESS: if device.get_type() == nmclient.DEVICE_TYPE_802_11_WIRELESS:
if device.get_active(): self.add_device(wirelessnetwork.Device(device))
self._add_device(device)
def __iter__(self): def __iter__(self):
return iter(self._devices) return iter(self._devices)

View File

@ -46,14 +46,27 @@ class HomeBox(hippo.CanvasBox, hippo.CanvasItem):
self._shell_state_changed_cb) self._shell_state_changed_cb)
self._device_icons = [] self._device_icons = []
for device in shell_model.get_devices():
devices_model = shell_model.get_devices()
for device in devices_model:
self._add_device(device) self._add_device(device)
devices_model.connect('device-appeared',
self._device_appeared_cb)
devices_model.connect('device-disappeared',
self._device_disappeared_cb)
def _add_device(self, device): def _add_device(self, device):
view = deviceview.create(device) view = deviceview.create(device)
self.append(view, hippo.PACK_FIXED) self.append(view, hippo.PACK_FIXED)
self._device_icons.append(view) self._device_icons.append(view)
def _device_appeared_cb(self, model, device):
self._add_device(device)
def _device_disappeared_cb(self, model, device):
pass
def _shell_state_changed_cb(self, model, pspec): def _shell_state_changed_cb(self, model, pspec):
# FIXME handle all possible mode switches # FIXME handle all possible mode switches
if model.props.state == ShellModel.STATE_SHUTDOWN: if model.props.state == ShellModel.STATE_SHUTDOWN: