First go at access points on the mesh view
This commit is contained in:
parent
6a4170a51e
commit
06e0923687
@ -126,9 +126,18 @@ class Network(gobject.GObject):
|
|||||||
|
|
||||||
class Device(gobject.GObject):
|
class Device(gobject.GObject):
|
||||||
__gsignals__ = {
|
__gsignals__ = {
|
||||||
'init-failed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])),
|
'init-failed': (gobject.SIGNAL_RUN_FIRST,
|
||||||
'activated': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])),
|
gobject.TYPE_NONE, ([])),
|
||||||
'strength-changed': (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]))
|
([gobject.TYPE_PYOBJECT]))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -195,6 +204,9 @@ class Device(gobject.GObject):
|
|||||||
def get_op(self):
|
def get_op(self):
|
||||||
return self._op
|
return self._op
|
||||||
|
|
||||||
|
def get_networks(self):
|
||||||
|
return self._networks.values()
|
||||||
|
|
||||||
def get_network(self, op):
|
def get_network(self, op):
|
||||||
if self._networks.has_key(op):
|
if self._networks.has_key(op):
|
||||||
return self._networks[op]
|
return self._networks[op]
|
||||||
@ -223,12 +235,16 @@ class Device(gobject.GObject):
|
|||||||
net = Network(network)
|
net = Network(network)
|
||||||
self._networks[network] = net
|
self._networks[network] = net
|
||||||
net.connect('init-failed', self._net_init_failed)
|
net.connect('init-failed', self._net_init_failed)
|
||||||
|
self.emit('network-appeared', net)
|
||||||
|
|
||||||
def network_disappeared(self, network):
|
def network_disappeared(self, network):
|
||||||
if not self._networks.has_key(network):
|
if not self._networks.has_key(network):
|
||||||
return
|
return
|
||||||
if network == self._active_net:
|
if network == self._active_net:
|
||||||
self._active_net = None
|
self._active_net = None
|
||||||
|
|
||||||
|
self.emit('network-disappeared', self._networks[network])
|
||||||
|
|
||||||
del self._networks[network]
|
del self._networks[network]
|
||||||
|
|
||||||
def get_active(self):
|
def get_active(self):
|
||||||
|
@ -20,6 +20,17 @@ from sugar.graphics.xocolor import XoColor
|
|||||||
from sugar.presence import PresenceService
|
from sugar.presence import PresenceService
|
||||||
from sugar.activity import bundleregistry
|
from sugar.activity import bundleregistry
|
||||||
from model.BuddyModel import BuddyModel
|
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:
|
class ActivityModel:
|
||||||
def __init__(self, activity, bundle, service):
|
def __init__(self, activity, bundle, service):
|
||||||
@ -48,9 +59,14 @@ class MeshModel(gobject.GObject):
|
|||||||
'buddy-added': (gobject.SIGNAL_RUN_FIRST,
|
'buddy-added': (gobject.SIGNAL_RUN_FIRST,
|
||||||
gobject.TYPE_NONE, ([gobject.TYPE_PYOBJECT])),
|
gobject.TYPE_NONE, ([gobject.TYPE_PYOBJECT])),
|
||||||
'buddy-moved': (gobject.SIGNAL_RUN_FIRST,
|
'buddy-moved': (gobject.SIGNAL_RUN_FIRST,
|
||||||
gobject.TYPE_NONE, ([gobject.TYPE_PYOBJECT,
|
gobject.TYPE_NONE,
|
||||||
|
([gobject.TYPE_PYOBJECT,
|
||||||
gobject.TYPE_PYOBJECT])),
|
gobject.TYPE_PYOBJECT])),
|
||||||
'buddy-removed': (gobject.SIGNAL_RUN_FIRST,
|
'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]))
|
gobject.TYPE_NONE, ([gobject.TYPE_PYOBJECT]))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,6 +75,7 @@ class MeshModel(gobject.GObject):
|
|||||||
|
|
||||||
self._activities = {}
|
self._activities = {}
|
||||||
self._buddies = {}
|
self._buddies = {}
|
||||||
|
self._access_points = {}
|
||||||
self._bundle_registry = bundleregistry.get_registry()
|
self._bundle_registry = bundleregistry.get_registry()
|
||||||
|
|
||||||
self._pservice = PresenceService.get_instance()
|
self._pservice = PresenceService.get_instance()
|
||||||
@ -78,6 +95,42 @@ class MeshModel(gobject.GObject):
|
|||||||
for service in self._pservice.get_services():
|
for service in self._pservice.get_services():
|
||||||
self._check_service(service)
|
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):
|
def get_activities(self):
|
||||||
return self._activities.values()
|
return self._activities.values()
|
||||||
|
|
||||||
|
@ -24,6 +24,14 @@ from sugar.graphics.snowflakebox import SnowflakeBox
|
|||||||
from sugar.graphics.canvasicon import CanvasIcon
|
from sugar.graphics.canvasicon import CanvasIcon
|
||||||
from view.BuddyIcon import BuddyIcon
|
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):
|
class ActivityView(SnowflakeBox):
|
||||||
def __init__(self, shell, menu_shell, model):
|
def __init__(self, shell, menu_shell, model):
|
||||||
SnowflakeBox.__init__(self)
|
SnowflakeBox.__init__(self)
|
||||||
@ -63,6 +71,7 @@ class MeshBox(SpreadBox):
|
|||||||
self._model = shell.get_model().get_mesh()
|
self._model = shell.get_model().get_mesh()
|
||||||
self._buddies = {}
|
self._buddies = {}
|
||||||
self._activities = {}
|
self._activities = {}
|
||||||
|
self._access_points = {}
|
||||||
self._buddy_to_activity = {}
|
self._buddy_to_activity = {}
|
||||||
|
|
||||||
for buddy_model in self._model.get_buddies():
|
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-added', self._activity_added_cb)
|
||||||
self._model.connect('activity-removed', self._activity_removed_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):
|
def _buddy_added_cb(self, model, buddy_model):
|
||||||
self._add_alone_buddy(buddy_model)
|
self._add_alone_buddy(buddy_model)
|
||||||
|
|
||||||
@ -93,6 +110,12 @@ class MeshBox(SpreadBox):
|
|||||||
def _activity_removed_cb(self, model, activity_model):
|
def _activity_removed_cb(self, model, activity_model):
|
||||||
self._remove_activity(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):
|
def _add_alone_buddy(self, buddy_model):
|
||||||
icon = BuddyIcon(self._shell, self._menu_shell, buddy_model)
|
icon = BuddyIcon(self._shell, self._menu_shell, buddy_model)
|
||||||
self.add_item(icon)
|
self.add_item(icon)
|
||||||
@ -136,3 +159,14 @@ class MeshBox(SpreadBox):
|
|||||||
icon = self._activities[activity_model.get_id()]
|
icon = self._activities[activity_model.get_id()]
|
||||||
self.remove_item(icon)
|
self.remove_item(icon)
|
||||||
del self._activities[activity_model.get_id()]
|
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