More fixes, and convert python PS bindings to more glib style method names

This commit is contained in:
Dan Williams 2006-07-23 09:21:00 -05:00
parent 1d0b4e12b8
commit 7c996b0011
12 changed files with 116 additions and 72 deletions

View File

@ -57,7 +57,7 @@ class BrowserActivity(Activity):
vbox.show()
self._pservice = PresenceService()
self._pservice.connect('ServiceAppeared', self._service_appeared_cb)
self._pservice.connect('service-appeared', self._service_appeared_cb)
# Join the shared activity if we were started from one
if self._initial_service:

View File

@ -54,17 +54,14 @@ class ChatListener:
self._chats = {}
self._pservice = PresenceService.get_instance()
self._pservice.start()
self._pservice.track_service_type(BuddyChat.SERVICE_TYPE)
self._pservice = PresenceService()
self._pservice.register_service_type(BuddyChat.SERVICE_TYPE)
def start(self):
port = random.randint(5000, 65535)
service = Service.Service(sugar.env.get_nick_name(), BuddyChat.SERVICE_TYPE,
'local', '', port)
self._buddy_stream = Stream.new_from_service(service)
self._service = self._pservice.register_service(sugar.env.get_nick_name(),
BuddyChat.SERVICE_TYPE)
self._buddy_stream = Stream.new_from_service(self._service)
self._buddy_stream.set_data_listener(self._recv_message)
self._pservice.register_service(service)
def _recv_message(self, address, message):
[nick, msg] = Chat.deserialize_message(message)

View File

@ -36,7 +36,7 @@ class ActivitiesModel(gobject.GObject):
self._activities = []
self._pservice = PresenceService()
self._pservice.connect("ActivityAppeared", self._on_activity_announced_cb)
self._pservice.connect("activity-appeared", self._on_activity_announced_cb)
def add_activity(self, service):
activity_info = ActivityInfo(service)

View File

@ -32,7 +32,7 @@ class ShellOwner(object):
# Create and announce our presence
self._pservice = PresenceService.PresenceService()
self._service = self._pservice.registerService(nick, PRESENCE_SERVICE_TYPE)
self._service = self._pservice.register_service(nick, PRESENCE_SERVICE_TYPE)
print "Owner '%s' using port %d" % (nick, self._service.get_port())
self._icon_stream = Stream.Stream.new_from_service(self._service)
self._icon_stream.register_reader_handler(self._handle_buddy_icon_request, "get_buddy_icon")

View File

@ -182,6 +182,17 @@ class PresenceServiceDBusHelper(dbus.service.Object):
port, domain)
return service.object_path()
@dbus.service.method(_PRESENCE_DBUS_INTERFACE,
in_signature="s", out_signature="")
def registerServiceType(self, stype):
self._parent.register_service_type(stype)
@dbus.service.method(_PRESENCE_DBUS_INTERFACE,
in_signature="s", out_signature="")
def unregisterServiceType(self, stype):
self._parent.unregister_service_type(stype)
class PresenceService(object):
def __init__(self):
# interface -> IP address: interfaces we've gotten events on so far

View File

@ -21,8 +21,8 @@ class PresenceView(gtk.VBox):
self._shell = shell
self._pservice = PresenceService()
self._pservice.connect("BuddyAppeared", self._on_buddy_appeared_cb)
self._pservice.connect("BuddyDisappeared", self._on_buddy_disappeared_cb)
self._pservice.connect("buddy-appeared", self._on_buddy_appeared_cb)
self._pservice.connect("buddy-disappeared", self._on_buddy_disappeared_cb)
self._setup_ui()

View File

@ -10,7 +10,7 @@ class ActivityChat(GroupChat):
self._chat_service = None
self._activity = activity
self._pservice.connect('ServiceAppeared', self._service_appeared_cb)
self._pservice.connect('service-appeared', self._service_appeared_cb)
# Find an existing activity chat to latch onto
#activity_ps = self._pservice.getActivity(activity.get_id())

View File

@ -233,7 +233,7 @@ class Chat(gtk.VBox):
return
if self._stream_writer:
self._stream_writer.write(self.serialize_message(svgdata))
owner = PresenceService.get_instance().get_owner()
owner = self._pservice.get_owner()
if owner:
self._insert_sketch(owner, svgdata)
@ -245,12 +245,12 @@ class Chat(gtk.VBox):
self._stream_writer.write(self.serialize_message(text))
else:
print 'Cannot send message, there is no stream writer'
owner = PresenceService.get_instance().get_owner()
owner = self._pservice.get_owner()
if owner:
self._insert_rich_message(owner, text)
def serialize_message(self, message):
owner = PresenceService.get_instance().get_owner()
owner = self._pservice.get_owner()
return owner.get_nick_name() + '||' + message
def deserialize_message(message):

View File

@ -4,13 +4,13 @@ import dbus, dbus_bindings
class Activity(gobject.GObject):
__gsignals__ = {
'BuddyJoined': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
'buddy-joined': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
([gobject.TYPE_PYOBJECT])),
'BuddyLeft': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
'buddy-left': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
([gobject.TYPE_PYOBJECT])),
'ServiceAppeared': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
'service-appeared': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
([gobject.TYPE_PYOBJECT])),
'ServiceDisappeared': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
'service-disappeared': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
([gobject.TYPE_PYOBJECT]))
}
@ -33,67 +33,67 @@ class Activity(gobject.GObject):
return self._object_path
def _emit_buddy_joined_signal(self, object_path):
self.emit('BuddyJoined', self._ps_new_object(object_path))
self.emit('buddy-joined', self._ps_new_object(object_path))
return False
def _buddy_joined_cb(self, object_path):
gobject.idle_add(self._emit_buddy_joined_signal, object_path)
def _emit_buddy_left_signal(self, object_path):
self.emit('BuddyLeft', self._ps_new_object(object_path))
self.emit('buddy-left', self._ps_new_object(object_path))
return False
def _buddy_left_cb(self, object_path):
gobject.idle_add(self._emit_buddy_left_signal, object_path)
def _emit_service_appeared_signal(self, object_path):
self.emit('ServiceAppeared', self._ps_new_object(object_path))
self.emit('service-appeared', self._ps_new_object(object_path))
return False
def _service_appeared_cb(self, object_path):
gobject.idle_add(self._emit_service_appeared_signal, object_path)
def _emit_service_disappeared_signal(self, object_path):
self.emit('ServiceDisappeared', self._ps_new_object(object_path))
self.emit('service-disappeared', self._ps_new_object(object_path))
return False
def _service_disappeared_cb(self, object_path):
gobject.idle_add(self._emit_service_disappeared_signal, object_path)
def getId(self):
def get_id(self):
return self._activity.getId()
def getIcon(self):
def get_icon(self):
return self._buddy.getIcon()
def getServiceOfType(self, stype):
def get_service_of_type(self, stype):
try:
object_path = self._buddy.getServiceOfType(stype)
except dbus_bindings.DBusException:
return None
return self._ps_new_object(object_path)
def getServices(self):
def get_services(self):
resp = self._activity.getServices()
servs = []
for item in resp:
servs.append(self._ps_new_object(item))
return servs
def getServicesOfType(self, stype):
def get_services_of_type(self, stype):
resp = self._activity.getServicesOfType(stype)
servs = []
for item in resp:
servs.append(self._ps_new_object(item))
return servs
def getJoinedBuddies(self):
def get_joined_buddies(self):
resp = self._activity.getJoinedBuddies(stype)
buddies = []
for item in resp:
buddies.append(self._ps_new_object(item))
return buddies
def ownerHasJoined(self):
def owner_has_joined(self):
# FIXME
return False

View File

@ -1,18 +1,19 @@
import gobject
import gtk
import dbus, dbus_bindings
class Buddy(gobject.GObject):
__gsignals__ = {
'IconChanged': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
'icon-changed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
([])),
'ServiceAppeared': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
'service-appeared': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
([gobject.TYPE_PYOBJECT])),
'ServiceDisappeared': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
'service-disappeared': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
([gobject.TYPE_PYOBJECT])),
'JoinedActivity': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
'joined-activity': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
([gobject.TYPE_PYOBJECT])),
'LeftActivity': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
'left-activity': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
([gobject.TYPE_PYOBJECT]))
}
@ -24,6 +25,7 @@ class Buddy(gobject.GObject):
self._object_path = object_path
self._ps_new_object = new_obj_cb
self._ps_del_object = del_obj_cb
self._properties = {}
bobj = bus.get_object(self._PRESENCE_SERVICE, object_path)
self._buddy = dbus.Interface(bobj, self._BUDDY_DBUS_INTERFACE)
self._buddy.connect_to_signal('IconChanged', self._icon_changed_cb)
@ -31,59 +33,83 @@ class Buddy(gobject.GObject):
self._buddy.connect_to_signal('ServiceDisappeared', self._service_disappeared_cb)
self._buddy.connect_to_signal('JoinedActivity', self._joined_activity_cb)
self._buddy.connect_to_signal('LeftActivity', self._left_activity_cb)
self._buddy.connect_to_signal('PropertyChanged', self._property_changed_cb)
self._properties = self._buddy.getProperties()
def object_path(self):
return self._object_path
def _emit_icon_changed_signal(self):
self.emit('IconChanged')
self.emit('icon-changed')
return False
def _icon_changed_cb(self):
gobject.idle_add(self._emit_icon_changed_signal)
def _emit_service_appeared_signal(self, object_path):
self.emit('ServiceAppeared', self._ps_new_object(object_path))
self.emit('service-appeared', self._ps_new_object(object_path))
return False
def _service_appeared_cb(self, object_path):
gobject.idle_add(self._emit_service_appeared_signal, object_path)
def _emit_service_disappeared_signal(self, object_path):
self.emit('ServiceDisappeared', self._ps_new_object(object_path))
self.emit('service-disappeared', self._ps_new_object(object_path))
return False
def _service_disappeared_cb(self, object_path):
gobject.idle_add(self._emit_service_disappeared_signal, object_path)
def _emit_joined_activity_signal(self, object_path):
self.emit('JoinedActivity', self._ps_new_object(object_path))
self.emit('joined-activity', self._ps_new_object(object_path))
return False
def _joined_activity_cb(self, object_path):
gobject.idle_add(self._emit_joined_activity_signal, object_path)
def _emit_left_activity_signal(self, object_path):
self.emit('LeftActivity', self._ps_new_object(object_path))
self.emit('left-activity', self._ps_new_object(object_path))
return False
def _left_activity_cb(self, object_path):
gobject.idle_add(self._emit_left_activity_signal, object_path)
def getProperties(self):
return self._buddy.getProperties()
def _handle_property_changed_signal(self, prop_list):
self._properties = self._buddy.getProperties()
def getIcon(self):
def _property_changed_cb(self, prop_list):
gobject.idle_add(self._handle_property_changed_signal, prop_list)
def get_name(self):
return self._properties['name']
def get_ip4_address(self):
return self._properties['ip4_address']
def is_owner(self):
return self._properties['owner']
def get_icon(self):
return self._buddy.getIcon()
def getServiceOfType(self, stype):
def get_icon_pixbuf(self):
icon = self._buddy.getIcon()
if icon:
pbl = gtk.gdk.PixbufLoader()
pbl.write(icon)
pbl.close()
return pbl.get_pixbuf()
else:
return None
def get_service_of_type(self, stype):
try:
object_path = self._buddy.getServiceOfType(stype)
except dbus_bindings.DBusException:
return None
return self._ps_new_object(object_path)
def getJoinedActivities(self):
def get_joined_activities(self):
try:
resp = self._buddy.getJoinedActivities()
except dbus_bindings.DBusException:

View File

@ -24,17 +24,17 @@ class ObjectCache(object):
class PresenceService(gobject.GObject):
__gsignals__ = {
'BuddyAppeared': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
'buddy-appeared': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
([gobject.TYPE_PYOBJECT])),
'BuddyDisappeared': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
'buddy-disappeared': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
([gobject.TYPE_PYOBJECT])),
'ServiceAppeared': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
'service-appeared': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
([gobject.TYPE_PYOBJECT])),
'ServiceDisappeared': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
'service-disappeared': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
([gobject.TYPE_PYOBJECT])),
'ActivityAppeared': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
'activity-appeared': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
([gobject.TYPE_PYOBJECT])),
'ActivityDisappeared': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
'activity-disappeared': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
([gobject.TYPE_PYOBJECT]))
}
@ -54,6 +54,10 @@ class PresenceService(gobject.GObject):
self._PRESENCE_OBJECT_PATH), self._PRESENCE_DBUS_INTERFACE)
self._ps.connect_to_signal('BuddyAppeared', self._buddy_appeared_cb)
self._ps.connect_to_signal('BuddyDisappeared', self._buddy_disappeared_cb)
self._ps.connect_to_signal('ServiceAppeared', self._service_appeared_cb)
self._ps.connect_to_signal('ServiceDisappeared', self._service_disappeared_cb)
self._ps.connect_to_signal('ActivityAppeared', self._activity_appeared_cb)
self._ps.connect_to_signal('ActivityDisappeared', self._activity_disappeared_cb)
def _new_object(self, object_path):
obj = self._objcache.get(object_path)
@ -77,104 +81,109 @@ class PresenceService(gobject.GObject):
pass
def _emit_buddy_appeared_signal(self, object_path):
self.emit('BuddyAppeared', self._new_object(object_path))
self.emit('buddy-appeared', self._new_object(object_path))
return False
def _buddy_appeared_cb(self, op):
gobject.idle_add(self._emit_buddy_appeared_signal, op)
def _emit_buddy_disappeared_signal(self, object_path):
self.emit('BuddyDisappeared', self._ps_new_object(object_path))
self.emit('buddy-disappeared', self._new_object(object_path))
return False
def _buddy_disappeared_cb(self, object_path):
gobject.idle_add(self._emit_buddy_disappeared_signal, object_path)
def _emit_service_appeared_signal(self, object_path):
self.emit('ServiceAppeared', self._ps_new_object(object_path))
self.emit('service-appeared', self._new_object(object_path))
return False
def _service_appeared_cb(self, object_path):
gobject.idle_add(self._emit_service_appeared_signal, object_path)
def _emit_service_disappeared_signal(self, object_path):
self.emit('ServiceDisappeared', self._ps_new_object(object_path))
self.emit('service-disappeared', self._new_object(object_path))
return False
def _service_disappeared_cb(self, object_path):
gobject.idle_add(self._emit_service_disappeared_signal, object_path)
def _emit_activity_appeared_signal(self, object_path):
self.emit('ActivityAppeared', self._ps_new_object(object_path))
self.emit('activity-appeared', self._new_object(object_path))
return False
def _activity_appeared_cb(self, object_path):
gobject.idle_add(self._emit_activity_appeared_signal, object_path)
def _emit_activity_disappeared_signal(self, object_path):
self.emit('ActivityDisappeared', self._ps_new_object(object_path))
self.emit('activity-disappeared', self._new_object(object_path))
return False
def _activity_disappeared_cb(self, object_path):
gobject.idle_add(self._emit_activity_disappeared_signal, object_path)
def getServices(self):
def get_services(self):
resp = self._ps.getServices()
servs = []
for item in resp:
servs.append(self._new_object(item))
return servs
def getServicesOfType(self, stype):
def get_services_of_type(self, stype):
resp = self._ps.getServicesOfType(stype)
servs = []
for item in resp:
servs.append(self._new_object(item))
return servs
def getActivities(self):
def get_activities(self):
resp = self._ps.getActivities()
acts = []
for item in resp:
acts.append(self._new_object(item))
return acts
def getActivity(self, activity_id):
def get_activity(self, activity_id):
try:
act_op = self._ps.getActivity(activity_id)
except dbus_bindings.DBusException:
return None
return self._new_object(act_op)
def getBuddies(self):
def get_buddies(self):
resp = self._ps.getBuddies()
buddies = []
for item in resp:
buddies.append(self._new_object(item))
return buddies
def getBuddyByName(self, name):
def get_buddy_by_name(self, name):
try:
buddy_op = self._ps.getBuddyByName(name)
except dbus_bindings.DBusException:
return None
return self._new_object(buddy_op)
def getBuddyByAddress(self, addr):
def get_buddy_by_address(self, addr):
try:
buddy_op = self._ps.getBuddyByAddress(addr)
except dbus_bindings.DBusException:
return None
return self._new_object(buddy_op)
def getOwner(self):
def get_owner(self):
try:
owner_op = self._ps.getOwner()
except dbus_bindings.DBusException:
return None
return self._new_object(buddy_op)
return self._new_object(owner_op)
def registerService(self, name, stype, properties={"":""}, address="", port=-1, domain=u"local"):
def register_service(self, name, stype, properties={"":""}, address="", port=-1, domain=u"local"):
serv_op = self._ps.registerService(name, stype, properties, address, port, domain)
return self._new_object(serv_op)
def register_service_type(self, stype):
self._ps.registerServiceType(stype)
def unregister_service_type(self, stype):
self._ps.unregisterServiceType(stype)

View File

@ -14,15 +14,16 @@ class Service(gobject.GObject):
self._ps_del_object = del_obj_cb
sobj = bus.get_object(self._PRESENCE_SERVICE, object_path)
self._service = dbus.Interface(sobj, self._SERVICE_DBUS_INTERFACE)
self._service.connect_to_signal('PropertyChanged', self._property_changed_cb)
self._props = self._service.getProperties()
def object_path(self):
return self._object_path
def getProperties(self):
return self._props
def _property_changed_cb(self, prop_list):
self._props = self._service.getProperties()
def getPublishedValue(self, key):
def get_published_value(self, key):
value = self._service.getPublishedValue(key)
def get_name(self):