First go at access points on the mesh view
This commit is contained in:
parent
6a4170a51e
commit
06e0923687
@ -126,10 +126,19 @@ class Network(gobject.GObject):
|
||||
|
||||
class Device(gobject.GObject):
|
||||
__gsignals__ = {
|
||||
'init-failed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])),
|
||||
'activated': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])),
|
||||
'strength-changed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
|
||||
([gobject.TYPE_PYOBJECT]))
|
||||
'init-failed': (gobject.SIGNAL_RUN_FIRST,
|
||||
gobject.TYPE_NONE, ([])),
|
||||
'activated': (gobject.SIGNAL_RUN_FIRST,
|
||||
gobject.TYPE_NONE, ([])),
|
||||
'strength-changed': (gobject.SIGNAL_RUN_FIRST,
|
||||
gobject.TYPE_NONE,
|
||||
([gobject.TYPE_PYOBJECT])),
|
||||
'network-appeared': (gobject.SIGNAL_RUN_FIRST,
|
||||
gobject.TYPE_NONE,
|
||||
([gobject.TYPE_PYOBJECT])),
|
||||
'network-disappeared': (gobject.SIGNAL_RUN_FIRST,
|
||||
gobject.TYPE_NONE,
|
||||
([gobject.TYPE_PYOBJECT]))
|
||||
}
|
||||
|
||||
def __init__(self, op):
|
||||
@ -195,6 +204,9 @@ class Device(gobject.GObject):
|
||||
def get_op(self):
|
||||
return self._op
|
||||
|
||||
def get_networks(self):
|
||||
return self._networks.values()
|
||||
|
||||
def get_network(self, op):
|
||||
if self._networks.has_key(op):
|
||||
return self._networks[op]
|
||||
@ -223,12 +235,16 @@ class Device(gobject.GObject):
|
||||
net = Network(network)
|
||||
self._networks[network] = net
|
||||
net.connect('init-failed', self._net_init_failed)
|
||||
self.emit('network-appeared', net)
|
||||
|
||||
def network_disappeared(self, network):
|
||||
if not self._networks.has_key(network):
|
||||
return
|
||||
if network == self._active_net:
|
||||
self._active_net = None
|
||||
|
||||
self.emit('network-disappeared', self._networks[network])
|
||||
|
||||
del self._networks[network]
|
||||
|
||||
def get_active(self):
|
||||
|
@ -20,6 +20,17 @@ from sugar.graphics.xocolor import XoColor
|
||||
from sugar.presence import PresenceService
|
||||
from sugar.activity import bundleregistry
|
||||
from model.BuddyModel import BuddyModel
|
||||
from hardware import hardwaremanager
|
||||
|
||||
class AccessPointModel:
|
||||
def __init__(self, nm_network):
|
||||
self._nm_network = nm_network
|
||||
|
||||
def get_id(self):
|
||||
return self._nm_network.get_op()
|
||||
|
||||
def get_name(self):
|
||||
return self._nm_network.get_ssid()
|
||||
|
||||
class ActivityModel:
|
||||
def __init__(self, activity, bundle, service):
|
||||
@ -41,17 +52,22 @@ class ActivityModel:
|
||||
|
||||
class MeshModel(gobject.GObject):
|
||||
__gsignals__ = {
|
||||
'activity-added': (gobject.SIGNAL_RUN_FIRST,
|
||||
gobject.TYPE_NONE, ([gobject.TYPE_PYOBJECT])),
|
||||
'activity-removed': (gobject.SIGNAL_RUN_FIRST,
|
||||
gobject.TYPE_NONE, ([gobject.TYPE_PYOBJECT])),
|
||||
'buddy-added': (gobject.SIGNAL_RUN_FIRST,
|
||||
gobject.TYPE_NONE, ([gobject.TYPE_PYOBJECT])),
|
||||
'buddy-moved': (gobject.SIGNAL_RUN_FIRST,
|
||||
gobject.TYPE_NONE, ([gobject.TYPE_PYOBJECT,
|
||||
gobject.TYPE_PYOBJECT])),
|
||||
'buddy-removed': (gobject.SIGNAL_RUN_FIRST,
|
||||
gobject.TYPE_NONE, ([gobject.TYPE_PYOBJECT]))
|
||||
'activity-added': (gobject.SIGNAL_RUN_FIRST,
|
||||
gobject.TYPE_NONE, ([gobject.TYPE_PYOBJECT])),
|
||||
'activity-removed': (gobject.SIGNAL_RUN_FIRST,
|
||||
gobject.TYPE_NONE, ([gobject.TYPE_PYOBJECT])),
|
||||
'buddy-added': (gobject.SIGNAL_RUN_FIRST,
|
||||
gobject.TYPE_NONE, ([gobject.TYPE_PYOBJECT])),
|
||||
'buddy-moved': (gobject.SIGNAL_RUN_FIRST,
|
||||
gobject.TYPE_NONE,
|
||||
([gobject.TYPE_PYOBJECT,
|
||||
gobject.TYPE_PYOBJECT])),
|
||||
'buddy-removed': (gobject.SIGNAL_RUN_FIRST,
|
||||
gobject.TYPE_NONE, ([gobject.TYPE_PYOBJECT])),
|
||||
'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]))
|
||||
}
|
||||
|
||||
def __init__(self):
|
||||
@ -59,6 +75,7 @@ class MeshModel(gobject.GObject):
|
||||
|
||||
self._activities = {}
|
||||
self._buddies = {}
|
||||
self._access_points = {}
|
||||
self._bundle_registry = bundleregistry.get_registry()
|
||||
|
||||
self._pservice = PresenceService.get_instance()
|
||||
@ -78,6 +95,42 @@ class MeshModel(gobject.GObject):
|
||||
for service in self._pservice.get_services():
|
||||
self._check_service(service)
|
||||
|
||||
network_manager = hardwaremanager.get_network_manager()
|
||||
for nm_device in network_manager.get_devices():
|
||||
self._add_network_device(nm_device)
|
||||
network_manager.connect('device-activated',
|
||||
self._nm_device_activated_cb)
|
||||
|
||||
def _nm_device_activated_cb(self, manager, nm_device):
|
||||
self._add_network_device(nm_device)
|
||||
|
||||
def _nm_network_appeared_cb(self, manager, nm_network):
|
||||
self._add_access_point(nm_network)
|
||||
|
||||
def _nm_network_disappeared_cb(self, manager, nm_network):
|
||||
self._remove_access_point(nm_network)
|
||||
|
||||
def _add_network_device(self, nm_device):
|
||||
for network in nm_device.get_networks():
|
||||
self._add_access_point(network)
|
||||
nm_device.connect('network-appeared',
|
||||
self._nm_network_appeared_cb)
|
||||
nm_device.connect('network-disappeared',
|
||||
self._nm_network_disappeared_cb)
|
||||
|
||||
def _add_access_point(self, nm_network):
|
||||
model = AccessPointModel(nm_network)
|
||||
self._access_points[nm_network.get_op()] = model
|
||||
self.emit('access-point-added', model)
|
||||
|
||||
def _remove_access_point(self, nm_network):
|
||||
self.emit('access-point-removed',
|
||||
self._access_points[nm_network.get_op()])
|
||||
del self._access_points[nm_network.get_op()]
|
||||
|
||||
def get_access_points(self):
|
||||
return self._access_points.values()
|
||||
|
||||
def get_activities(self):
|
||||
return self._activities.values()
|
||||
|
||||
|
@ -24,6 +24,14 @@ from sugar.graphics.snowflakebox import SnowflakeBox
|
||||
from sugar.graphics.canvasicon import CanvasIcon
|
||||
from view.BuddyIcon import BuddyIcon
|
||||
|
||||
class AccessPointView(CanvasIcon):
|
||||
def __init__(self, model):
|
||||
CanvasIcon.__init__(self)
|
||||
self._update_icon()
|
||||
|
||||
def _update_icon(self):
|
||||
self.props.icon_name = 'theme:stock-net-wireless-00'
|
||||
|
||||
class ActivityView(SnowflakeBox):
|
||||
def __init__(self, shell, menu_shell, model):
|
||||
SnowflakeBox.__init__(self)
|
||||
@ -63,6 +71,7 @@ class MeshBox(SpreadBox):
|
||||
self._model = shell.get_model().get_mesh()
|
||||
self._buddies = {}
|
||||
self._activities = {}
|
||||
self._access_points = {}
|
||||
self._buddy_to_activity = {}
|
||||
|
||||
for buddy_model in self._model.get_buddies():
|
||||
@ -78,6 +87,14 @@ class MeshBox(SpreadBox):
|
||||
self._model.connect('activity-added', self._activity_added_cb)
|
||||
self._model.connect('activity-removed', self._activity_removed_cb)
|
||||
|
||||
for ap_model in self._model.get_access_points():
|
||||
self._add_access_point(ap_model)
|
||||
|
||||
self._model.connect('access-point-added',
|
||||
self._access_point_added_cb)
|
||||
self._model.connect('access-point-removed',
|
||||
self._access_point_removed_cb)
|
||||
|
||||
def _buddy_added_cb(self, model, buddy_model):
|
||||
self._add_alone_buddy(buddy_model)
|
||||
|
||||
@ -93,6 +110,12 @@ class MeshBox(SpreadBox):
|
||||
def _activity_removed_cb(self, model, activity_model):
|
||||
self._remove_activity(activity_model)
|
||||
|
||||
def _access_point_added_cb(self, model, ap_model):
|
||||
self._add_access_point(ap_model)
|
||||
|
||||
def _access_point_removed_cb(self, model, ap_model):
|
||||
self._add_access_point(ap_model)
|
||||
|
||||
def _add_alone_buddy(self, buddy_model):
|
||||
icon = BuddyIcon(self._shell, self._menu_shell, buddy_model)
|
||||
self.add_item(icon)
|
||||
@ -136,3 +159,14 @@ class MeshBox(SpreadBox):
|
||||
icon = self._activities[activity_model.get_id()]
|
||||
self.remove_item(icon)
|
||||
del self._activities[activity_model.get_id()]
|
||||
|
||||
def _add_access_point(self, ap_model):
|
||||
icon = AccessPointView(ap_model)
|
||||
self.add_item(icon)
|
||||
|
||||
self._access_points[ap_model.get_id()] = icon
|
||||
|
||||
def _remove_access_point(self, ap_model):
|
||||
icon = self._access_points[ap_model.get_id()]
|
||||
self.remove_item(icon)
|
||||
del self._access_points[ap_model.get_id()]
|
||||
|
Loading…
Reference in New Issue
Block a user