Handle device removal
This commit is contained in:
parent
38ac42d665
commit
7c135804bc
@ -130,6 +130,8 @@ class Device(gobject.GObject):
|
|||||||
gobject.TYPE_NONE, ([])),
|
gobject.TYPE_NONE, ([])),
|
||||||
'activated': (gobject.SIGNAL_RUN_FIRST,
|
'activated': (gobject.SIGNAL_RUN_FIRST,
|
||||||
gobject.TYPE_NONE, ([])),
|
gobject.TYPE_NONE, ([])),
|
||||||
|
'deactivated': (gobject.SIGNAL_RUN_FIRST,
|
||||||
|
gobject.TYPE_NONE, ([])),
|
||||||
'strength-changed': (gobject.SIGNAL_RUN_FIRST,
|
'strength-changed': (gobject.SIGNAL_RUN_FIRST,
|
||||||
gobject.TYPE_NONE,
|
gobject.TYPE_NONE,
|
||||||
([gobject.TYPE_PYOBJECT])),
|
([gobject.TYPE_PYOBJECT])),
|
||||||
@ -179,6 +181,8 @@ class Device(gobject.GObject):
|
|||||||
|
|
||||||
if self._active:
|
if self._active:
|
||||||
self.emit('activated')
|
self.emit('activated')
|
||||||
|
else:
|
||||||
|
self.emit('deactivated')
|
||||||
|
|
||||||
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:
|
||||||
|
@ -20,7 +20,7 @@ class DevicesModel(gobject.GObject):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
gobject.GObject.__init__(self)
|
gobject.GObject.__init__(self)
|
||||||
|
|
||||||
self._devices = []
|
self._devices = {}
|
||||||
self.add_device(battery.Device())
|
self.add_device(battery.Device())
|
||||||
|
|
||||||
self._observe_network_manager()
|
self._observe_network_manager()
|
||||||
@ -32,21 +32,44 @@ class DevicesModel(gobject.GObject):
|
|||||||
self._check_network_device(device)
|
self._check_network_device(device)
|
||||||
|
|
||||||
network_manager.connect('device-activated',
|
network_manager.connect('device-activated',
|
||||||
self._network_device_added_cb)
|
self._network_device_activated_cb)
|
||||||
|
network_manager.connect('device-removed',
|
||||||
|
self._network_device_removed_cb)
|
||||||
|
|
||||||
def _network_device_added_cb(self, network_manager, device):
|
def _network_device_activated_cb(self, network_manager, nm_device):
|
||||||
self._check_network_device(device)
|
self._check_network_device(nm_device)
|
||||||
|
|
||||||
def _check_network_device(self, device):
|
def _network_device_removed_cb(self, nm_device):
|
||||||
if not device.is_valid():
|
self._remove_network_device(nm_device)
|
||||||
|
|
||||||
|
def _network_device_deactivated_cb(self, nm_device):
|
||||||
|
self._remove_network_device(nm_device)
|
||||||
|
|
||||||
|
def _check_network_device(self, nm_device):
|
||||||
|
if not nm_device.is_valid():
|
||||||
return
|
return
|
||||||
|
|
||||||
if device.get_type() == nmclient.DEVICE_TYPE_802_11_WIRELESS:
|
if nm_device.get_type() == nmclient.DEVICE_TYPE_802_11_WIRELESS:
|
||||||
self.add_device(wirelessnetwork.Device(device))
|
self._add_network_device(nm_device)
|
||||||
|
|
||||||
|
def _get_network_device(self, nm_device):
|
||||||
|
return self._devices[nm_device.get_op()]
|
||||||
|
|
||||||
|
def _add_network_device(self, nm_device):
|
||||||
|
self.add_device(wirelessnetwork.Device(nm_device))
|
||||||
|
nm_device.connect('deactivated',
|
||||||
|
self._network_device_deactivated_cb)
|
||||||
|
|
||||||
|
def _remove_network_device(self, nm_device):
|
||||||
|
self.remove_device(self._get_network_device(nm_device))
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
return iter(self._devices)
|
return iter(self._devices.values())
|
||||||
|
|
||||||
def add_device(self, device):
|
def add_device(self, device):
|
||||||
self._devices.append(device)
|
self._devices[device.get_id()] = device
|
||||||
self.emit('device-appeared', device)
|
self.emit('device-appeared', device)
|
||||||
|
|
||||||
|
def remove_device(self, device):
|
||||||
|
self.emit('device-disappeared', self._devices[device.get_id()])
|
||||||
|
del self._devices[device.get_id()]
|
||||||
|
@ -5,5 +5,8 @@ class Device(device.Device):
|
|||||||
device.Device.__init__(self)
|
device.Device.__init__(self)
|
||||||
self._nm_device = device
|
self._nm_device = device
|
||||||
|
|
||||||
|
def get_id(self):
|
||||||
|
return self._nm_device.get_op()
|
||||||
|
|
||||||
def get_type(self):
|
def get_type(self):
|
||||||
return 'wirednetwork'
|
return 'wirednetwork'
|
||||||
|
@ -3,10 +3,13 @@ from model.devices import device
|
|||||||
class Device(device.Device):
|
class Device(device.Device):
|
||||||
def __init__(self, nm_device):
|
def __init__(self, nm_device):
|
||||||
device.Device.__init__(self)
|
device.Device.__init__(self)
|
||||||
self._nm_device = device
|
self._nm_device = nm_device
|
||||||
|
|
||||||
def get_type(self):
|
def get_type(self):
|
||||||
return 'wirelessnetwork'
|
return 'wirelessnetwork'
|
||||||
|
|
||||||
|
def get_id(self):
|
||||||
|
return self._nm_device.get_op()
|
||||||
|
|
||||||
def get_level(self):
|
def get_level(self):
|
||||||
return self._nm_device.get_strength()
|
return self._nm_device.get_strength()
|
||||||
|
@ -45,7 +45,7 @@ class HomeBox(hippo.CanvasBox, hippo.CanvasItem):
|
|||||||
shell_model.connect('notify::state',
|
shell_model.connect('notify::state',
|
||||||
self._shell_state_changed_cb)
|
self._shell_state_changed_cb)
|
||||||
|
|
||||||
self._device_icons = []
|
self._device_icons = {}
|
||||||
|
|
||||||
devices_model = shell_model.get_devices()
|
devices_model = shell_model.get_devices()
|
||||||
for device in devices_model:
|
for device in devices_model:
|
||||||
@ -59,13 +59,17 @@ class HomeBox(hippo.CanvasBox, hippo.CanvasItem):
|
|||||||
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[device.get_id()] = view
|
||||||
|
|
||||||
|
def _remove_device(self, device):
|
||||||
|
self.remove(self._device_icons[device.get_id()])
|
||||||
|
del self._device_icons[device.get_id()]
|
||||||
|
|
||||||
def _device_appeared_cb(self, model, device):
|
def _device_appeared_cb(self, model, device):
|
||||||
self._add_device(device)
|
self._add_device(device)
|
||||||
|
|
||||||
def _device_disappeared_cb(self, model, device):
|
def _device_disappeared_cb(self, model, device):
|
||||||
pass
|
self._remove_device(device)
|
||||||
|
|
||||||
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
|
||||||
@ -87,7 +91,7 @@ class HomeBox(hippo.CanvasBox, hippo.CanvasItem):
|
|||||||
(height - icon_height) / 2)
|
(height - icon_height) / 2)
|
||||||
|
|
||||||
i = 0
|
i = 0
|
||||||
for icon in self._device_icons:
|
for icon in self._device_icons.values():
|
||||||
angle = 2 * math.pi / len(self._device_icons) * i + math.pi / 2
|
angle = 2 * math.pi / len(self._device_icons) * i + math.pi / 2
|
||||||
radius = units.grid_to_pixels(5)
|
radius = units.grid_to_pixels(5)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user