More new PS fixes

This commit is contained in:
Dan Williams 2007-04-09 16:05:32 -04:00
parent 4cf8f321f0
commit 76a0f45aa8
8 changed files with 48 additions and 38 deletions

View File

@ -1,4 +1,4 @@
[D-BUS Service]
Name = org.laptop.Presence
Name = org.laptop.Sugar.Presence
Exec = @bindir@/sugar-presence-service

View File

@ -326,6 +326,7 @@ class ServerPlugin(gobject.GObject):
if not cur_activity_handle:
# dont advertise a current activity that's not shared
cur_activity = ""
print "cur_activity is '%s', handle is %s" % (cur_activity, cur_activity_handle)
self._conn[CONN_INTERFACE_BUDDY_INFO].SetCurrentActivity(cur_activity, cur_activity_handle)
self._upload_avatar()
@ -404,6 +405,16 @@ class ServerPlugin(gobject.GObject):
if not props.has_key('key'):
raise InvalidBuddyError("no key")
# Convert from D-Bus array types to a standard python byte array
key = ""
for item in props["key"]:
try:
# int type
key = key + "%s" % chr(item)
except TypeError:
# string type
key = key + str(item)
jid = self._conn[CONN_INTERFACE].InspectHandles(CONNECTION_HANDLE_TYPE_CONTACT, [handle])[0]
nick = self._conn[CONN_INTERFACE_ALIASING].RequestAliases([handle])[0]
if not nick:
@ -411,6 +422,8 @@ class ServerPlugin(gobject.GObject):
props['nick'] = nick
self._online_contacts[handle] = jid
# Any properties that are returned by TP as dbus.ByteArray or dbus.Array
# must be converted before emitting signals
self.emit("contact-online", handle, props)
activities = self._conn[CONN_INTERFACE_BUDDY_INFO].GetActivities(handle)

View File

@ -52,7 +52,10 @@ class BuddyModel(gobject.GObject):
if not buddy:
self._name = name
# FIXME: use public key, not name
buddy = self._pservice.get_buddy_by_name(self._name)
for iter_buddy in self._pservice.get_buddies():
if iter_buddy.props.nick == name:
buddy = iter_buddy
break
# If successful, copy properties from the PS buddy object
if buddy:

View File

@ -25,8 +25,7 @@ from hardware import hardwaremanager
from hardware import nmclient
class ActivityModel:
def __init__(self, activity, bundle, service):
self._service = service
def __init__(self, activity, bundle):
self._activity = activity
self._bundle = bundle
@ -39,8 +38,6 @@ class ActivityModel:
def get_color(self):
return XoColor(self._activity.get_color())
def get_service(self):
return self._service
class MeshModel(gobject.GObject):
__gsignals__ = {
@ -75,8 +72,8 @@ class MeshModel(gobject.GObject):
self._bundle_registry = bundleregistry.get_registry()
self._pservice = presenceservice.get_instance()
self._pservice.connect("service-appeared",
self._service_appeared_cb)
self._pservice.connect("activity-appeared",
self._activity_appeared_cb)
self._pservice.connect('activity-disappeared',
self._activity_disappeared_cb)
self._pservice.connect("buddy-appeared",
@ -88,8 +85,8 @@ class MeshModel(gobject.GObject):
for buddy in self._pservice.get_buddies():
self._buddy_appeared_cb(self._pservice, buddy)
for service in self._pservice.get_services():
self._check_service(service)
for activity in self._pservice.get_activities():
self._check_activity(activity)
network_manager = hardwaremanager.get_network_manager()
if network_manager:
@ -196,18 +193,18 @@ class MeshModel(gobject.GObject):
self.emit('buddy-removed', buddy)
del self._buddies[buddy.get_name()]
def _service_appeared_cb(self, pservice, service):
self._check_service(service)
def _activity_appeared_cb(self, pservice, activity):
self._check_activity(activity)
def _check_service(self, service):
service_type = service.get_type()
bundle = self._bundle_registry.find_by_default_type(service_type)
if bundle != None:
activity_id = service.get_activity_id()
if not self.has_activity(activity_id):
activity = self._pservice.get_activity(activity_id)
if activity != None:
self.add_activity(bundle, activity, service)
def _check_activity(self, activity):
atype = activity.get_type()
bundle = self._bundle_registry.get_bundle(atype)
if not bundle:
return
activity_id = activity.get_id()
if self.has_activity(activity_id):
return
self.add_activity(bundle, activity)
def has_activity(self, activity_id):
return self._activities.has_key(activity_id)
@ -218,14 +215,14 @@ class MeshModel(gobject.GObject):
else:
return None
def add_activity(self, bundle, activity, service):
model = ActivityModel(activity, bundle, service)
def add_activity(self, bundle, activity):
model = ActivityModel(activity, bundle)
self._activities[model.get_id()] = model
self.emit('activity-added', model)
for buddy in self._pservice.get_buddies():
cur_activity = buddy.get_current_activity()
name = buddy.get_name()
cur_activity = buddy.props.current_activity
name = buddy.props.nick
if cur_activity == activity and self._buddies.has_key(name):
buddy_model = self._buddies[name]
self.emit('buddy-moved', buddy_model, model)

View File

@ -47,7 +47,6 @@ class ShellModel(gobject.GObject):
self._pservice = presenceservice.get_instance()
self._owner = ShellOwner()
self._owner.announce()
self._friends = Friends()
self._mesh = MeshModel()

View File

@ -45,12 +45,8 @@ class FriendView(hippo.CanvasBox):
self._buddy.connect('color-changed', self._buddy_color_changed_cb)
def _get_new_icon_name(self, activity):
# FIXME: do something better here; we probably need to use "flagship"
# services like mDNS where activities default services are marked
# somehow.
activity_registry = shell.get_model().get_bundle_registry()
for serv in activity.get_services():
bundle = activity_registry.get_bundle(serv.get_type())
registry = shell.get_model().get_bundle_registry()
bundle = registry.get_bundle(activity.get_type())
if bundle:
return bundle.get_icon()
return None

View File

@ -53,7 +53,9 @@ class LogWriter:
elif level == STDOUT_LEVEL:
level_txt = 'STDOUT'
fmt = "%s - %s\n" % (level_txt, msg)
if msg[len(msg) - 1] != '\n':
msg += "\n"
fmt = "%s - %s" % (level_txt, msg)
fmt = fmt.encode("utf8")
self._log_file.write(fmt)
self._log_file.flush()

View File

@ -83,10 +83,10 @@ class PresenceService(gobject.GObject):
obj = self._objcache.get(object_path)
if not obj:
if object_path.startswith(self._PS_BUDDY_OP):
obj = Buddy.Buddy(self._bus, self._new_object,
obj = buddy.Buddy(self._bus, self._new_object,
self._del_object, object_path)
elif object_path.startswith(self._PS_ACTIVITY_OP):
obj = Activity.Activity(self._bus, self._new_object,
obj = activity.Activity(self._bus, self._new_object,
self._del_object, object_path)
else:
raise RuntimeError("Unknown object type")
@ -158,7 +158,7 @@ class PresenceService(gobject.GObject):
return self._new_object(act_op)
def get_buddies(self):
resp = self._ps.getBuddies()
resp = self._ps.GetBuddies()
buddies = []
for item in resp:
buddies.append(self._new_object(item))