2006-07-19 21:27:37 +02:00
|
|
|
import gobject
|
2006-07-25 22:52:45 +02:00
|
|
|
import dbus
|
2006-07-19 21:27:37 +02:00
|
|
|
|
|
|
|
class Activity(gobject.GObject):
|
|
|
|
|
|
|
|
__gsignals__ = {
|
2006-07-23 16:21:00 +02:00
|
|
|
'buddy-joined': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
|
2006-07-19 21:27:37 +02:00
|
|
|
([gobject.TYPE_PYOBJECT])),
|
2006-07-23 16:21:00 +02:00
|
|
|
'buddy-left': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
|
2006-07-19 21:27:37 +02:00
|
|
|
([gobject.TYPE_PYOBJECT])),
|
2006-07-23 16:21:00 +02:00
|
|
|
'service-appeared': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
|
2006-07-19 21:27:37 +02:00
|
|
|
([gobject.TYPE_PYOBJECT])),
|
2006-07-23 16:21:00 +02:00
|
|
|
'service-disappeared': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
|
2006-07-19 21:27:37 +02:00
|
|
|
([gobject.TYPE_PYOBJECT]))
|
|
|
|
}
|
|
|
|
|
|
|
|
_PRESENCE_SERVICE = "org.laptop.Presence"
|
|
|
|
_ACTIVITY_DBUS_INTERFACE = "org.laptop.Presence.Activity"
|
|
|
|
|
|
|
|
def __init__(self, bus, new_obj_cb, del_obj_cb, object_path):
|
|
|
|
gobject.GObject.__init__(self)
|
|
|
|
self._object_path = object_path
|
|
|
|
self._ps_new_object = new_obj_cb
|
|
|
|
self._ps_del_object = del_obj_cb
|
|
|
|
bobj = bus.get_object(self._PRESENCE_SERVICE, object_path)
|
|
|
|
self._activity = dbus.Interface(bobj, self._ACTIVITY_DBUS_INTERFACE)
|
|
|
|
self._activity.connect_to_signal('BuddyJoined', self._buddy_joined_cb)
|
|
|
|
self._activity.connect_to_signal('BuddyLeft', self._buddy_left_cb)
|
|
|
|
self._activity.connect_to_signal('ServiceAppeared', self._service_appeared_cb)
|
|
|
|
self._activity.connect_to_signal('ServiceDisappeared', self._service_disappeared_cb)
|
|
|
|
|
|
|
|
def object_path(self):
|
|
|
|
return self._object_path
|
|
|
|
|
|
|
|
def _emit_buddy_joined_signal(self, object_path):
|
2006-07-23 16:21:00 +02:00
|
|
|
self.emit('buddy-joined', self._ps_new_object(object_path))
|
2006-07-19 21:27:37 +02:00
|
|
|
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):
|
2006-07-23 16:21:00 +02:00
|
|
|
self.emit('buddy-left', self._ps_new_object(object_path))
|
2006-07-19 21:27:37 +02:00
|
|
|
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):
|
2006-07-23 16:21:00 +02:00
|
|
|
self.emit('service-appeared', self._ps_new_object(object_path))
|
2006-07-19 21:27:37 +02:00
|
|
|
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):
|
2006-07-23 16:21:00 +02:00
|
|
|
self.emit('service-disappeared', self._ps_new_object(object_path))
|
2006-07-19 21:27:37 +02:00
|
|
|
return False
|
|
|
|
|
|
|
|
def _service_disappeared_cb(self, object_path):
|
|
|
|
gobject.idle_add(self._emit_service_disappeared_signal, object_path)
|
|
|
|
|
2006-07-23 16:21:00 +02:00
|
|
|
def get_id(self):
|
2006-07-19 21:27:37 +02:00
|
|
|
return self._activity.getId()
|
|
|
|
|
2006-07-23 16:21:00 +02:00
|
|
|
def get_icon(self):
|
2006-07-19 21:27:37 +02:00
|
|
|
return self._buddy.getIcon()
|
|
|
|
|
2006-07-23 16:21:00 +02:00
|
|
|
def get_service_of_type(self, stype):
|
2006-07-19 21:27:37 +02:00
|
|
|
try:
|
|
|
|
object_path = self._buddy.getServiceOfType(stype)
|
2006-07-25 22:52:45 +02:00
|
|
|
except dbus.exceptions.DBusException:
|
2006-07-19 21:27:37 +02:00
|
|
|
return None
|
|
|
|
return self._ps_new_object(object_path)
|
|
|
|
|
2006-07-23 16:21:00 +02:00
|
|
|
def get_services(self):
|
2006-07-19 21:27:37 +02:00
|
|
|
resp = self._activity.getServices()
|
|
|
|
servs = []
|
|
|
|
for item in resp:
|
|
|
|
servs.append(self._ps_new_object(item))
|
|
|
|
return servs
|
|
|
|
|
2006-07-23 16:21:00 +02:00
|
|
|
def get_services_of_type(self, stype):
|
2006-07-19 21:27:37 +02:00
|
|
|
resp = self._activity.getServicesOfType(stype)
|
|
|
|
servs = []
|
|
|
|
for item in resp:
|
|
|
|
servs.append(self._ps_new_object(item))
|
|
|
|
return servs
|
|
|
|
|
2006-07-23 16:21:00 +02:00
|
|
|
def get_joined_buddies(self):
|
2006-07-19 21:27:37 +02:00
|
|
|
resp = self._activity.getJoinedBuddies(stype)
|
|
|
|
buddies = []
|
|
|
|
for item in resp:
|
|
|
|
buddies.append(self._ps_new_object(item))
|
|
|
|
return buddies
|
|
|
|
|
2006-07-23 16:21:00 +02:00
|
|
|
def owner_has_joined(self):
|
2006-07-19 21:27:37 +02:00
|
|
|
# FIXME
|
|
|
|
return False
|