Really add mesh device bits

This commit is contained in:
Dan Williams 2007-03-29 10:10:34 -04:00
parent b3a500fd17
commit d0fdf59486
5 changed files with 118 additions and 11 deletions

View File

@ -22,6 +22,7 @@ from sugar.activity import bundleregistry
from model.BuddyModel import BuddyModel
from model.accesspointmodel import AccessPointModel
from hardware import hardwaremanager
from hardware import nmclient
class ActivityModel:
def __init__(self, activity, bundle, service):
@ -58,7 +59,10 @@ class MeshModel(gobject.GObject):
'access-point-added': (gobject.SIGNAL_RUN_FIRST,
gobject.TYPE_NONE, ([gobject.TYPE_PYOBJECT])),
'access-point-removed': (gobject.SIGNAL_RUN_FIRST,
gobject.TYPE_NONE, ([gobject.TYPE_PYOBJECT]))
gobject.TYPE_NONE, ([gobject.TYPE_PYOBJECT])),
'mesh-added': (gobject.SIGNAL_RUN_FIRST,
gobject.TYPE_NONE, ([gobject.TYPE_PYOBJECT])),
'mesh-removed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([]))
}
def __init__(self):
@ -67,6 +71,7 @@ class MeshModel(gobject.GObject):
self._activities = {}
self._buddies = {}
self._access_points = {}
self._mesh = None
self._bundle_registry = bundleregistry.get_registry()
self._pservice = PresenceService.get_instance()
@ -92,10 +97,15 @@ class MeshModel(gobject.GObject):
self._add_network_device(nm_device)
network_manager.connect('device-added',
self._nm_device_added_cb)
network_manager.connect('device-removed',
self._nm_device_removed_cb)
def _nm_device_added_cb(self, manager, nm_device):
self._add_network_device(nm_device)
def _nm_device_removed_cb(self, manager, nm_device):
self._remove_network_device(nm_device)
def _nm_network_appeared_cb(self, nm_device, nm_network):
self._add_access_point(nm_device, nm_network)
@ -103,13 +113,28 @@ class MeshModel(gobject.GObject):
self._remove_access_point(nm_network)
def _add_network_device(self, nm_device):
for nm_network in nm_device.get_networks():
self._add_access_point(nm_device, nm_network)
dtype = nm_device.get_type()
if dtype == nmclient.DEVICE_TYPE_802_11_WIRELESS:
for nm_network in nm_device.get_networks():
self._add_access_point(nm_device, nm_network)
nm_device.connect('network-appeared',
self._nm_network_appeared_cb)
nm_device.connect('network-disappeared',
self._nm_network_disappeared_cb)
nm_device.connect('network-appeared',
self._nm_network_appeared_cb)
nm_device.connect('network-disappeared',
self._nm_network_disappeared_cb)
elif dtype == nmclient.DEVICE_TYPE_802_11_MESH_OLPC:
self._mesh = nm_device
self.emit('mesh-added', self._mesh)
def _remove_network_device(self, nm_device):
if nm_device == self._mesh:
self._mesh = None
self.emit('mesh-removed')
elif nm_device.get_type() == nmclient.DEVICE_TYPE_802_11_WIRELESS:
aplist = self._access_points.values()
for ap in aplist:
if ap.get_nm_device() == nm_device:
self._remove_access_point(ap)
def _add_access_point(self, nm_device, nm_network):
model = AccessPointModel(nm_device, nm_network)
@ -121,6 +146,9 @@ class MeshModel(gobject.GObject):
self._access_points[nm_network.get_op()])
del self._access_points[nm_network.get_op()]
def get_mesh(self):
return self._mesh
def get_access_points(self):
return self._access_points.values()

View File

@ -3,6 +3,7 @@ import gobject
from model.devices import device
from model.devices.network import wired
from model.devices.network import wireless
from model.devices.network import mesh
from model.devices import battery
from hardware import hardwaremanager
from hardware import nmclient
@ -45,21 +46,28 @@ class DevicesModel(gobject.GObject):
self._remove_network_device(nm_device)
def _network_device_state_changed_cb(self, nm_device):
if nm_device.get_state == nmclient.DEVICE_STATE_INACTIVE:
if nm_device.get_state() == nmclient.DEVICE_STATE_INACTIVE:
self._remove_network_device(nm_device)
def _check_network_device(self, nm_device):
if not nm_device.is_valid():
return
if nm_device.get_type() == nmclient.DEVICE_TYPE_802_11_WIRELESS:
dtype = nm_device.get_type()
if dtype == nmclient.DEVICE_TYPE_802_11_WIRELESS \
or dtype == nmclient.DEVICE_TYPE_802_11_MESH_OLPC:
self._add_network_device(nm_device)
def _get_network_device(self, nm_device):
return self._devices[nm_device.get_op()]
return self._devices[str(nm_device.get_op())]
def _add_network_device(self, nm_device):
self.add_device(wireless.Device(nm_device))
dtype = nm_device.get_type()
if dtype == nmclient.DEVICE_TYPE_802_11_WIRELESS:
self.add_device(wireless.Device(nm_device))
if dtype == nmclient.DEVICE_TYPE_802_11_MESH_OLPC:
self.add_device(mesh.Device(nm_device))
nm_device.connect('state-changed',
self._network_device_state_changed_cb)
@ -71,6 +79,8 @@ class DevicesModel(gobject.GObject):
def add_device(self, device):
self._devices[device.get_id()] = device
import logging
logging.debug("adding device %s" % device.get_id())
self.emit('device-appeared', device)
def remove_device(self, device):

View File

@ -1,5 +1,6 @@
sugardir = $(pkgdatadir)/shell/model/devices/network
sugar_PYTHON = \
__init__.py \
mesh.py \
wired.py \
wireless.py

View File

@ -1,5 +1,6 @@
sugardir = $(pkgdatadir)/shell/view/devices/network
sugar_PYTHON = \
__init__.py \
mesh.py \
wired.py \
wireless.py

View File

@ -18,6 +18,7 @@ import random
import hippo
import gobject
from gettext import gettext as _
from sugar.graphics.spreadbox import SpreadBox
from sugar.graphics.snowflakebox import SnowflakeBox
@ -25,10 +26,14 @@ from sugar.graphics.canvasicon import CanvasIcon
from sugar.graphics import color
from sugar.graphics import xocolor
from sugar.graphics import canvasicon
from sugar.graphics import units
from model import accesspointmodel
from model.devices.network import mesh
from hardware import hardwaremanager
from hardware import nmclient
from view.BuddyIcon import BuddyIcon
from view.pulsingicon import PulsingIcon
from sugar import profile
_ICON_NAME = 'device-network-wireless'
@ -101,6 +106,39 @@ class AccessPointView(PulsingIcon):
self.props.fill_color = color.HTMLColor(self._inactive_fill_color)
self.props.stroke_color = color.HTMLColor(self._inactive_stroke_color)
class MeshDeviceView(CanvasIcon):
def __init__(self, nm_device):
CanvasIcon.__init__(self, scale=units.MEDIUM_ICON_SCALE,
icon_name='theme:device-network-mesh')
self._nm_device = nm_device
self.props.tooltip = _("Mesh Network")
self.connect('activated', self._activate_cb)
self._nm_device.connect('state-changed', self._state_changed_cb)
self._update_state()
def _activate_cb(self, icon):
network_manager = hardwaremanager.get_network_manager()
network_manager.set_active_device(self._nm_device)
def _state_changed_cb(self, model):
self._update_state()
def _update_state(self):
# FIXME Change icon colors once we have real icons
state = self._nm_device.get_state()
if state == nmclient.DEVICE_STATE_ACTIVATING:
self.props.fill_color = color.ICON_FILL_INACTIVE
self.props.stroke_color = color.ICON_STROKE_INACTIVE
elif state == nmclient.DEVICE_STATE_ACTIVATED:
mycolor = profile.get_color()
self.props.fill_color = color.HTMLColor(mycolor.get_fill_color())
self.props.stroke_color = color.HTMLColor(mycolor.get_stroke_color())
elif state == nmclient.DEVICE_STATE_INACTIVE:
self.props.fill_color = color.ICON_FILL_INACTIVE
self.props.stroke_color = color.ICON_STROKE_INACTIVE
class ActivityView(SnowflakeBox):
def __init__(self, shell, menu_shell, model):
SnowflakeBox.__init__(self)
@ -141,6 +179,7 @@ class MeshBox(SpreadBox):
self._buddies = {}
self._activities = {}
self._access_points = {}
self._mesh = None
self._buddy_to_activity = {}
for buddy_model in self._model.get_buddies():
@ -164,6 +203,20 @@ class MeshBox(SpreadBox):
self._model.connect('access-point-removed',
self._access_point_removed_cb)
if self._model.get_mesh():
self._add_mesh_icon(self._model.get_mesh())
self._model.connect('mesh-added',
self._mesh_added_cb)
self._model.connect('mesh-removed',
self._mesh_removed_cb)
def _mesh_added_cb(self, model, mesh):
self._add_mesh_icon(mesh)
def _mesh_removed_cb(self, model):
self._remove_mesh_icon()
def _buddy_added_cb(self, model, buddy_model):
self._add_alone_buddy(buddy_model)
@ -185,6 +238,20 @@ class MeshBox(SpreadBox):
def _access_point_removed_cb(self, model, ap_model):
self._remove_access_point(ap_model)
def _add_mesh_icon(self, mesh):
if self._mesh:
self._remove_mesh()
if not mesh:
return
self._mesh = MeshDeviceView(mesh)
self.add_item(self._mesh)
def _remove_access_point(self):
if not self._mesh:
return
self.remove_item(self._mesh)
self._mesh = None
def _add_alone_buddy(self, buddy_model):
icon = BuddyIcon(self._shell, self._menu_shell, buddy_model)
self.add_item(icon)