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._udi = props[3]
self._active = props[4]
if self._active:
self.emit('activated')
self._link = props[15]
self._caps = props[17]
@ -170,6 +168,9 @@ class Device(gobject.GObject):
self._valid = True
if self._active:
self.emit('activated')
def _update_networks(self, net_ops, active_op):
for op in net_ops:
net = Network(op)
@ -261,8 +262,19 @@ NM_STATE_CONNECTING = 2
NM_STATE_CONNECTED = 3
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):
gobject.GObject.__init__(self)
self.nminfo = None
self._nm_present = False
self._nm_state = NM_STATE_UNKNOWN
@ -329,6 +341,8 @@ class NMClient(object):
dev.disconnect('strength-changed')
del self._devices[dev_op]
self.emit('device-removed', dev)
def _dev_activated_cb(self, dev):
op = dev.get_op()
if not self._devices.has_key(op):
@ -337,6 +351,8 @@ class NMClient(object):
return
self._active_device = op
self.emit('device-activated', dev)
def _dev_strength_changed_cb(self, dev, strength):
op = dev.get_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 battery
from hardware import hardwaremanager
from hardware import nmclient
class DevicesModel(gobject.GObject):
__gsignals__ = {
@ -26,16 +27,22 @@ class DevicesModel(gobject.GObject):
def _observe_network_manager(self):
network_manager = hardwaremanager.get_network_manager()
for device in network_manager.get_devices():
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):
if not device.is_valid():
return
if device.get_type() == DEVICE_TYPE_802_11_WIRELESS:
if device.get_active():
self._add_device(device)
if device.get_type() == nmclient.DEVICE_TYPE_802_11_WIRELESS:
self.add_device(wirelessnetwork.Device(device))
def __iter__(self):
return iter(self._devices)

View File

@ -46,14 +46,27 @@ class HomeBox(hippo.CanvasBox, hippo.CanvasItem):
self._shell_state_changed_cb)
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)
devices_model.connect('device-appeared',
self._device_appeared_cb)
devices_model.connect('device-disappeared',
self._device_disappeared_cb)
def _add_device(self, device):
view = deviceview.create(device)
self.append(view, hippo.PACK_FIXED)
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):
# FIXME handle all possible mode switches
if model.props.state == ShellModel.STATE_SHUTDOWN: