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

46 lines
1.4 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
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()
for device in network_manager.get_devices():
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)
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)