sugar-toolkit-gtk3/shell/model/devices/devicesmodel.py

53 lines
1.6 KiB
Python
Raw Normal View History

import gobject
from model.devices import device
2007-02-25 02:00:40 +01:00
from model.devices import wirednetwork
from model.devices import wirelessnetwork
from model.devices import battery
2007-02-25 02:00:40 +01:00
from hardware import hardwaremanager
2007-02-25 02:28:14 +01:00
from hardware import nmclient
class DevicesModel(gobject.GObject):
__gsignals__ = {
'device-appeared' : (gobject.SIGNAL_RUN_FIRST,
gobject.TYPE_NONE,
([gobject.TYPE_PYOBJECT])),
'device-disappeared': (gobject.SIGNAL_RUN_FIRST,
gobject.TYPE_NONE,
([gobject.TYPE_PYOBJECT]))
}
def __init__(self):
gobject.GObject.__init__(self)
self._devices = []
self.add_device(battery.Device())
2007-02-25 02:00:40 +01:00
self._observe_network_manager()
def _observe_network_manager(self):
network_manager = hardwaremanager.get_network_manager()
2007-02-25 02:28:14 +01:00
2007-02-25 02:00:40 +01:00
for device in network_manager.get_devices():
self._check_network_device(device)
2007-02-25 02:28:14 +01:00
network_manager.connect('device-activated',
self._network_device_added_cb)
def _network_device_added_cb(self, network_manager, device):
self._check_network_device(device)
2007-02-25 02:00:40 +01:00
def _check_network_device(self, device):
if not device.is_valid():
return
2007-02-25 02:28:14 +01:00
if device.get_type() == nmclient.DEVICE_TYPE_802_11_WIRELESS:
self.add_device(wirelessnetwork.Device(device))
2007-02-25 02:00:40 +01:00
def __iter__(self):
return iter(self._devices)
def add_device(self, device):
self._devices.append(device)
2007-02-25 02:00:40 +01:00
self.emit('device-appeared', device)