2007-04-15 06:27:48 +02:00
|
|
|
"""UI interface to an activity in the presence service"""
|
2007-04-09 20:40:56 +02:00
|
|
|
# Copyright (C) 2007, Red Hat, Inc.
|
2006-10-15 01:08:44 +02:00
|
|
|
#
|
|
|
|
# This library is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU Lesser General Public
|
|
|
|
# License as published by the Free Software Foundation; either
|
|
|
|
# version 2 of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This library is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
# Lesser General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Lesser General Public
|
|
|
|
# License along with this library; if not, write to the
|
|
|
|
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
# Boston, MA 02111-1307, USA.
|
|
|
|
|
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):
|
2007-04-15 06:27:48 +02:00
|
|
|
"""UI interface for an Activity in the presence service
|
|
|
|
|
|
|
|
Activities in the presence service represent other user's
|
|
|
|
shared activities and your own activities (XXX shared or
|
|
|
|
otherwise?)
|
|
|
|
|
|
|
|
Properties:
|
|
|
|
id
|
|
|
|
color
|
|
|
|
name
|
|
|
|
type
|
|
|
|
joined
|
|
|
|
"""
|
2006-12-04 20:12:24 +01:00
|
|
|
__gsignals__ = {
|
|
|
|
'buddy-joined': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
|
|
|
|
([gobject.TYPE_PYOBJECT])),
|
2007-05-03 05:25:15 +02:00
|
|
|
'buddy-left': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
|
2006-12-04 20:12:24 +01:00
|
|
|
([gobject.TYPE_PYOBJECT])),
|
2007-05-03 05:25:15 +02:00
|
|
|
'new-channel': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
|
|
|
|
([gobject.TYPE_PYOBJECT])),
|
|
|
|
'joined': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
|
|
|
|
([gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT]))
|
2006-12-04 20:12:24 +01:00
|
|
|
}
|
|
|
|
|
2007-04-24 17:49:43 +02:00
|
|
|
__gproperties__ = {
|
|
|
|
'id' : (str, None, None, None, gobject.PARAM_READABLE),
|
|
|
|
'name' : (str, None, None, None, gobject.PARAM_READABLE),
|
|
|
|
'color' : (str, None, None, None, gobject.PARAM_READABLE),
|
|
|
|
'type' : (str, None, None, None, gobject.PARAM_READABLE),
|
|
|
|
'joined' : (bool, None, None, False, gobject.PARAM_READABLE)
|
|
|
|
}
|
|
|
|
|
2007-04-09 20:40:56 +02:00
|
|
|
_PRESENCE_SERVICE = "org.laptop.Sugar.Presence"
|
|
|
|
_ACTIVITY_DBUS_INTERFACE = "org.laptop.Sugar.Presence.Activity"
|
2006-12-04 20:12:24 +01:00
|
|
|
|
|
|
|
def __init__(self, bus, new_obj_cb, del_obj_cb, object_path):
|
2007-04-15 06:27:48 +02:00
|
|
|
"""Initialse the activity interface, connecting to service"""
|
2006-12-04 20:12:24 +01:00
|
|
|
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)
|
2007-04-09 20:40:56 +02:00
|
|
|
self._activity.connect_to_signal('NewChannel', self._new_channel_cb)
|
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
self._id = None
|
|
|
|
self._color = None
|
2007-04-09 20:40:56 +02:00
|
|
|
self._name = None
|
|
|
|
self._type = None
|
|
|
|
self._joined = False
|
2006-12-04 20:12:24 +01:00
|
|
|
|
|
|
|
def object_path(self):
|
2007-04-15 06:27:48 +02:00
|
|
|
"""Get our dbus object path"""
|
2006-12-04 20:12:24 +01:00
|
|
|
return self._object_path
|
|
|
|
|
2007-04-24 17:49:43 +02:00
|
|
|
def do_get_property(self, pspec):
|
|
|
|
"""Retrieve a particular property from our property dictionary"""
|
|
|
|
if pspec.name == "id":
|
|
|
|
if not self._id:
|
|
|
|
self._id = self._activity.GetId()
|
|
|
|
return self._id
|
|
|
|
elif pspec.name == "name":
|
|
|
|
if not self._name:
|
|
|
|
self._name = self._activity.GetName()
|
|
|
|
return self._name
|
|
|
|
elif pspec.name == "color":
|
|
|
|
if not self._color:
|
|
|
|
self._color = self._activity.GetColor()
|
|
|
|
return self._color
|
|
|
|
elif pspec.name == "type":
|
|
|
|
if not self._type:
|
|
|
|
self._type = self._activity.GetType()
|
|
|
|
return self._type
|
|
|
|
elif pspec.name == "joined":
|
|
|
|
return self._joined
|
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
def _emit_buddy_joined_signal(self, object_path):
|
2007-04-15 06:27:48 +02:00
|
|
|
"""Generate buddy-joined GObject signal with presence Buddy object"""
|
2006-12-04 20:12:24 +01:00
|
|
|
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):
|
2007-04-15 06:27:48 +02:00
|
|
|
"""Generate buddy-left GObject signal with presence Buddy object
|
|
|
|
|
|
|
|
XXX note use of _ps_new_object instead of _ps_del_object here
|
|
|
|
"""
|
2006-12-04 20:12:24 +01:00
|
|
|
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)
|
|
|
|
|
2007-04-09 20:40:56 +02:00
|
|
|
def _emit_new_channel_signal(self, object_path):
|
2007-04-15 06:27:48 +02:00
|
|
|
"""Generate new-channel GObject signal with channel object path
|
|
|
|
|
|
|
|
New telepathy-python communications channel has been opened
|
|
|
|
"""
|
2007-04-09 20:40:56 +02:00
|
|
|
self.emit('new-channel', object_path)
|
2006-12-04 20:12:24 +01:00
|
|
|
return False
|
|
|
|
|
2007-04-09 20:40:56 +02:00
|
|
|
def _new_channel_cb(self, object_path):
|
|
|
|
gobject.idle_add(self._emit_new_channel_signal, object_path)
|
2006-12-04 20:12:24 +01:00
|
|
|
|
|
|
|
def get_joined_buddies(self):
|
2007-04-15 06:27:48 +02:00
|
|
|
"""Retrieve the set of Buddy objects attached to this activity
|
|
|
|
|
|
|
|
returns list of presence Buddy objects
|
|
|
|
"""
|
2007-04-09 20:40:56 +02:00
|
|
|
resp = self._activity.GetJoinedBuddies()
|
2006-12-04 20:12:24 +01:00
|
|
|
buddies = []
|
|
|
|
for item in resp:
|
|
|
|
buddies.append(self._ps_new_object(item))
|
|
|
|
return buddies
|
|
|
|
|
2007-05-03 05:25:15 +02:00
|
|
|
def _join_cb(self):
|
|
|
|
self._joined = True
|
|
|
|
self.emit("joined", True, None)
|
|
|
|
|
|
|
|
def _join_error_cb(self, err):
|
|
|
|
self.emit("joined", False, str(err))
|
|
|
|
|
2007-04-09 20:40:56 +02:00
|
|
|
def join(self):
|
2007-04-15 06:27:48 +02:00
|
|
|
"""Join this activity
|
|
|
|
|
|
|
|
XXX if these are all activities, can I join my own activity?
|
|
|
|
"""
|
2007-04-09 20:40:56 +02:00
|
|
|
if self._joined:
|
2007-05-03 05:25:15 +02:00
|
|
|
self.emit("joined", True, None)
|
2007-04-09 20:40:56 +02:00
|
|
|
return
|
2007-05-03 05:25:15 +02:00
|
|
|
self._activity.Join(reply_handler=self._join_cb, error_handler=self._join_error_cb)
|
2007-04-09 20:40:56 +02:00
|
|
|
|
|
|
|
def get_channels(self):
|
2007-04-15 06:27:48 +02:00
|
|
|
"""Retrieve communications channel descriptions for the activity
|
|
|
|
|
|
|
|
Returns (bus name, connection, channels) for the activity
|
|
|
|
|
|
|
|
XXX what are those values?
|
|
|
|
"""
|
2007-04-09 20:40:56 +02:00
|
|
|
(bus_name, connection, channels) = self._activity.GetChannels()
|
|
|
|
return bus_name, connection, channels
|
|
|
|
|
2007-07-03 14:22:30 +02:00
|
|
|
def _leave_cb(self):
|
2007-08-21 12:39:05 +02:00
|
|
|
"""Callback for async action of leaving shared activity."""
|
2007-07-03 14:22:30 +02:00
|
|
|
self.emit("joined", False, "left activity")
|
|
|
|
|
|
|
|
def _leave_error_cb(self, err):
|
2007-08-21 12:39:05 +02:00
|
|
|
"""Callback for error in async leaving of shared activity.
|
|
|
|
|
|
|
|
XXX Add logging!"""
|
2007-07-03 14:22:30 +02:00
|
|
|
pass
|
|
|
|
|
2007-05-03 05:25:15 +02:00
|
|
|
def leave(self):
|
2007-07-03 14:22:30 +02:00
|
|
|
"""Leave this shared activity"""
|
2007-05-03 05:25:15 +02:00
|
|
|
self._joined = False
|
2007-07-03 14:22:30 +02:00
|
|
|
self._activity.Leave(reply_handler=self._leave_cb,
|
|
|
|
error_handler=self._leave_error_cb)
|