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.
|
|
|
|
|
2008-10-28 14:19:01 +01:00
|
|
|
"""UI interface to an activity in the presence service
|
|
|
|
|
|
|
|
STABLE.
|
|
|
|
"""
|
|
|
|
|
2007-08-30 13:14:35 +02:00
|
|
|
import logging
|
2010-06-28 16:42:23 +02:00
|
|
|
from functools import partial
|
2007-08-30 13:14:35 +02:00
|
|
|
|
2006-07-25 22:52:45 +02:00
|
|
|
import dbus
|
2007-10-29 18:21:33 +01:00
|
|
|
import gobject
|
|
|
|
import telepathy
|
2010-06-22 16:31:21 +02:00
|
|
|
from telepathy.client import Channel
|
|
|
|
from telepathy.interfaces import CHANNEL, \
|
|
|
|
CHANNEL_TYPE_TUBES, \
|
|
|
|
CHANNEL_TYPE_TEXT, \
|
|
|
|
CONNECTION
|
|
|
|
from telepathy.constants import HANDLE_TYPE_ROOM
|
2006-07-19 21:27:37 +02:00
|
|
|
|
2010-06-22 16:31:21 +02:00
|
|
|
CONN_INTERFACE_ACTIVITY_PROPERTIES = 'org.laptop.Telepathy.ActivityProperties'
|
2010-06-28 16:42:23 +02:00
|
|
|
CONN_INTERFACE_BUDDY_INFO = 'org.laptop.Telepathy.BuddyInfo'
|
2009-08-25 21:12:40 +02:00
|
|
|
|
2007-08-30 13:14:35 +02:00
|
|
|
_logger = logging.getLogger('sugar.presence.activity')
|
|
|
|
|
2009-08-25 21:12:40 +02:00
|
|
|
|
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
|
2009-08-25 19:55:48 +02:00
|
|
|
|
2007-10-15 11:18:34 +02:00
|
|
|
Activities in the presence service represent your and other user's
|
|
|
|
shared activities.
|
2009-08-25 19:55:48 +02:00
|
|
|
|
2007-04-15 06:27:48 +02:00
|
|
|
Properties:
|
2009-08-25 19:55:48 +02:00
|
|
|
id
|
|
|
|
color
|
|
|
|
name
|
|
|
|
type
|
|
|
|
joined
|
2007-04-15 06:27:48 +02:00
|
|
|
"""
|
2006-12-04 20:12:24 +01:00
|
|
|
__gsignals__ = {
|
|
|
|
'buddy-joined': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
|
2009-08-25 21:12:40 +02:00
|
|
|
([gobject.TYPE_PYOBJECT])),
|
|
|
|
'buddy-left': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
|
|
|
|
([gobject.TYPE_PYOBJECT])),
|
|
|
|
'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__ = {
|
2009-08-25 21:12:40 +02:00
|
|
|
'id': (str, None, None, None, gobject.PARAM_READABLE),
|
|
|
|
'name': (str, None, None, None, gobject.PARAM_READWRITE),
|
|
|
|
'tags': (str, None, None, None, gobject.PARAM_READWRITE),
|
|
|
|
'color': (str, None, None, None, gobject.PARAM_READWRITE),
|
|
|
|
'type': (str, None, None, None, gobject.PARAM_READABLE),
|
|
|
|
'private': (bool, None, None, True, gobject.PARAM_READWRITE),
|
|
|
|
'joined': (bool, None, None, False, gobject.PARAM_READABLE),
|
2007-04-24 17:49:43 +02:00
|
|
|
}
|
|
|
|
|
2010-06-28 16:42:23 +02:00
|
|
|
def __init__(self, connection, room_handle=None, properties=None):
|
|
|
|
if room_handle is None and properties is None:
|
|
|
|
raise ValueError('Need to pass one of room_handle or properties')
|
|
|
|
|
|
|
|
if properties is None:
|
|
|
|
properties = {}
|
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
gobject.GObject.__init__(self)
|
2007-04-09 20:40:56 +02:00
|
|
|
|
2010-06-22 16:31:21 +02:00
|
|
|
self.telepathy_conn = connection
|
|
|
|
self.telepathy_text_chan = None
|
|
|
|
self.telepathy_tubes_chan = None
|
|
|
|
|
|
|
|
self._room_handle = room_handle
|
2010-06-28 16:42:23 +02:00
|
|
|
self._id = properties.get('id', None)
|
|
|
|
self._color = properties.get('color', None)
|
|
|
|
self._name = properties.get('name', None)
|
|
|
|
self._type = properties.get('type', None)
|
|
|
|
self._tags = properties.get('tags', None)
|
|
|
|
self._private = properties.get('private', True)
|
|
|
|
self._joined = properties.get('joined', False)
|
2007-10-16 18:51:36 +02:00
|
|
|
|
2010-06-28 16:42:23 +02:00
|
|
|
self._get_properties_call = None
|
|
|
|
if not self._room_handle is None:
|
|
|
|
self._start_tracking_properties()
|
|
|
|
|
|
|
|
def _start_tracking_properties(self):
|
2010-06-22 16:31:21 +02:00
|
|
|
bus = dbus.SessionBus()
|
|
|
|
self._get_properties_call = bus.call_async(
|
2010-06-28 16:42:23 +02:00
|
|
|
self.telepathy_conn.requested_bus_name,
|
|
|
|
self.telepathy_conn.object_path,
|
2010-06-22 16:31:21 +02:00
|
|
|
CONN_INTERFACE_ACTIVITY_PROPERTIES,
|
|
|
|
'GetProperties',
|
|
|
|
'u',
|
|
|
|
(self._room_handle,),
|
|
|
|
reply_handler=self._got_properties_cb,
|
|
|
|
error_handler=self._error_handler_cb,
|
|
|
|
utf8_strings=True)
|
|
|
|
|
2010-06-28 16:42:23 +02:00
|
|
|
# As only one Activity instance is needed per activity process,
|
|
|
|
# we can afford listening to ActivityPropertiesChanged like this.
|
|
|
|
self.telepathy_conn.connect_to_signal(
|
|
|
|
'ActivityPropertiesChanged',
|
|
|
|
self.__activity_properties_changed_cb,
|
|
|
|
dbus_interface=CONN_INTERFACE_ACTIVITY_PROPERTIES)
|
|
|
|
|
|
|
|
def __activity_properties_changed_cb(self, room_handle, properties):
|
|
|
|
_logger.debug('%r: Activity properties changed to %r', self, properties)
|
|
|
|
self._update_properties(properties)
|
|
|
|
|
2010-06-22 16:31:21 +02:00
|
|
|
def _got_properties_cb(self, properties):
|
2010-06-28 16:42:23 +02:00
|
|
|
_logger.debug('_got_properties_cb %r', properties)
|
2007-08-30 13:14:35 +02:00
|
|
|
self._get_properties_call = None
|
2010-06-22 16:31:21 +02:00
|
|
|
self._update_properties(properties)
|
2007-08-30 13:14:35 +02:00
|
|
|
|
2010-06-22 16:31:21 +02:00
|
|
|
def _error_handler_cb(self, error):
|
2010-06-28 16:42:23 +02:00
|
|
|
_logger.debug('_error_handler_cb %r', error)
|
2010-06-22 16:31:21 +02:00
|
|
|
|
|
|
|
def _update_properties(self, new_props):
|
2007-08-30 13:14:35 +02:00
|
|
|
val = new_props.get('name', self._name)
|
|
|
|
if isinstance(val, str) and val != self._name:
|
|
|
|
self._name = val
|
|
|
|
self.notify('name')
|
|
|
|
val = new_props.get('tags', self._tags)
|
|
|
|
if isinstance(val, str) and val != self._tags:
|
|
|
|
self._tags = val
|
|
|
|
self.notify('tags')
|
|
|
|
val = new_props.get('color', self._color)
|
|
|
|
if isinstance(val, str) and val != self._color:
|
|
|
|
self._color = val
|
|
|
|
self.notify('color')
|
|
|
|
val = bool(new_props.get('private', self._private))
|
|
|
|
if val != self._private:
|
|
|
|
self._private = val
|
|
|
|
self.notify('private')
|
|
|
|
val = new_props.get('id', self._id)
|
|
|
|
if isinstance(val, str) and self._id is None:
|
|
|
|
self._id = val
|
|
|
|
self.notify('id')
|
|
|
|
val = new_props.get('type', self._type)
|
|
|
|
if isinstance(val, str) and self._type is None:
|
|
|
|
self._type = val
|
|
|
|
self.notify('type')
|
|
|
|
|
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"""
|
2007-08-30 13:14:35 +02:00
|
|
|
|
|
|
|
if pspec.name == "joined":
|
|
|
|
return self._joined
|
|
|
|
|
|
|
|
if self._get_properties_call is not None:
|
2007-10-16 18:51:36 +02:00
|
|
|
_logger.debug('%r: Blocking on GetProperties() because someone '
|
|
|
|
'wants property %s', self, pspec.name)
|
2007-08-30 13:14:35 +02:00
|
|
|
self._get_properties_call.block()
|
|
|
|
|
2007-04-24 17:49:43 +02:00
|
|
|
if pspec.name == "id":
|
|
|
|
return self._id
|
|
|
|
elif pspec.name == "name":
|
|
|
|
return self._name
|
|
|
|
elif pspec.name == "color":
|
|
|
|
return self._color
|
|
|
|
elif pspec.name == "type":
|
|
|
|
return self._type
|
2007-08-30 13:14:35 +02:00
|
|
|
elif pspec.name == "tags":
|
|
|
|
return self._tags
|
|
|
|
elif pspec.name == "private":
|
|
|
|
return self._private
|
|
|
|
|
|
|
|
def do_set_property(self, pspec, val):
|
|
|
|
"""Set a particular property in our property dictionary"""
|
2009-08-25 21:12:40 +02:00
|
|
|
# FIXME: need an asynchronous API to set these properties,
|
|
|
|
# particularly 'private'
|
2010-06-28 16:42:23 +02:00
|
|
|
|
2007-08-30 13:14:35 +02:00
|
|
|
if pspec.name == "name":
|
|
|
|
self._name = val
|
|
|
|
elif pspec.name == "color":
|
|
|
|
self._color = val
|
|
|
|
elif pspec.name == "tags":
|
|
|
|
self._tags = val
|
|
|
|
elif pspec.name == "private":
|
|
|
|
self._private = val
|
2010-06-28 16:42:23 +02:00
|
|
|
else:
|
|
|
|
raise ValueError('Unknown property "%s"', pspec.name)
|
|
|
|
|
|
|
|
self._publish_properties()
|
2007-04-24 17:49:43 +02:00
|
|
|
|
2007-10-29 18:21:33 +01:00
|
|
|
def set_private(self, val, reply_handler, error_handler):
|
2010-06-28 16:42:23 +02:00
|
|
|
_logger.debug('set_private %r', val)
|
2007-10-29 18:21:33 +01:00
|
|
|
self._activity.SetProperties({'private': bool(val)},
|
|
|
|
reply_handler=reply_handler,
|
|
|
|
error_handler=error_handler)
|
|
|
|
|
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
|
|
|
|
|
2007-10-11 22:55:04 +02:00
|
|
|
def _buddy_handle_joined_cb(self, object_path, handle):
|
2007-10-16 18:51:36 +02:00
|
|
|
_logger.debug('%r: buddy %s joined with handle %u', self, object_path,
|
|
|
|
handle)
|
2006-12-04 20:12:24 +01:00
|
|
|
gobject.idle_add(self._emit_buddy_joined_signal, object_path)
|
2007-10-12 17:33:52 +02:00
|
|
|
self._handle_to_buddy_path[handle] = object_path
|
|
|
|
self._buddy_path_to_handle[object_path] = handle
|
2006-12-04 20:12:24 +01:00
|
|
|
|
|
|
|
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
|
2009-08-25 19:55:48 +02:00
|
|
|
|
2007-04-15 06:27:48 +02:00
|
|
|
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
|
|
|
|
|
2007-10-12 17:11:59 +02:00
|
|
|
def _buddy_left_cb(self, object_path):
|
2007-10-16 18:51:36 +02:00
|
|
|
_logger.debug('%r: buddy %s left', self, object_path)
|
2006-12-04 20:12:24 +01:00
|
|
|
gobject.idle_add(self._emit_buddy_left_signal, object_path)
|
2007-10-22 14:22:32 +02:00
|
|
|
handle = self._buddy_path_to_handle.pop(object_path, None)
|
|
|
|
if handle:
|
|
|
|
self._handle_to_buddy_path.pop(handle, None)
|
2006-12-04 20:12:24 +01:00
|
|
|
|
2007-04-09 20:40:56 +02:00
|
|
|
def _emit_new_channel_signal(self, object_path):
|
2009-08-25 19:55:48 +02:00
|
|
|
"""Generate new-channel GObject signal with channel object path
|
|
|
|
|
2007-04-15 06:27:48 +02:00
|
|
|
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):
|
2007-10-16 18:51:36 +02:00
|
|
|
_logger.debug('%r: new channel created at %s', self, object_path)
|
2007-04-09 20:40:56 +02:00
|
|
|
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
|
2007-10-16 18:51:36 +02:00
|
|
|
|
2008-07-10 15:20:50 +02:00
|
|
|
returns list of presence Buddy objects that we can successfully
|
|
|
|
create from the buddy object paths that PS has for this activity.
|
2007-04-15 06:27:48 +02:00
|
|
|
"""
|
2010-06-22 16:31:21 +02:00
|
|
|
logging.info('KILL_PS return joined buddies')
|
|
|
|
return []
|
2006-12-04 20:12:24 +01:00
|
|
|
|
2007-10-03 13:14:47 +02:00
|
|
|
def get_buddy_by_handle(self, handle):
|
2007-10-03 21:39:07 +02:00
|
|
|
"""Retrieve the Buddy object given a telepathy handle.
|
2009-08-25 19:55:48 +02:00
|
|
|
|
2007-10-12 17:33:52 +02:00
|
|
|
buddy object paths are cached in self._handle_to_buddy_path,
|
|
|
|
so we can get the buddy without calling PS.
|
2007-10-03 21:39:07 +02:00
|
|
|
"""
|
2007-10-12 17:33:52 +02:00
|
|
|
object_path = self._handle_to_buddy_path.get(handle, None)
|
2007-10-12 17:43:11 +02:00
|
|
|
if object_path:
|
|
|
|
buddy = self._ps_new_object(object_path)
|
|
|
|
return buddy
|
|
|
|
return None
|
2007-10-03 13:14:47 +02:00
|
|
|
|
2007-08-30 13:14:35 +02:00
|
|
|
def invite(self, buddy, message, response_cb):
|
|
|
|
"""Invite the given buddy to join this activity.
|
|
|
|
|
|
|
|
The callback will be called with one parameter: None on success,
|
|
|
|
or an exception on failure.
|
|
|
|
"""
|
2007-10-16 18:51:36 +02:00
|
|
|
op = buddy.object_path()
|
|
|
|
_logger.debug('%r: inviting %s', self, op)
|
|
|
|
self._activity.Invite(op, message,
|
2007-08-30 13:14:35 +02:00
|
|
|
reply_handler=lambda: response_cb(None),
|
|
|
|
error_handler=response_cb)
|
|
|
|
|
2007-10-29 18:21:33 +01:00
|
|
|
# Joining and sharing (FIXME: sharing is actually done elsewhere)
|
|
|
|
|
|
|
|
def set_up_tubes(self, reply_handler, error_handler):
|
|
|
|
|
2010-06-28 16:42:23 +02:00
|
|
|
if self._room_handle is None:
|
|
|
|
raise ValueError("Don't have a handle for the room yet")
|
|
|
|
|
2008-05-14 15:07:48 +02:00
|
|
|
chans = []
|
2007-10-29 18:21:33 +01:00
|
|
|
|
2008-05-14 15:07:48 +02:00
|
|
|
def tubes_ready():
|
|
|
|
if self.telepathy_text_chan is None or \
|
2008-08-11 00:50:29 +02:00
|
|
|
self.telepathy_tubes_chan is None:
|
|
|
|
return
|
2007-10-29 18:21:33 +01:00
|
|
|
|
|
|
|
_logger.debug('%r: finished setting up tubes', self)
|
|
|
|
reply_handler()
|
|
|
|
|
2010-06-22 16:31:21 +02:00
|
|
|
def tubes_channel_ready_cb(channel):
|
|
|
|
_logger.debug('%r: Tubes channel %r is ready', self, channel)
|
|
|
|
self.telepathy_tubes_chan = channel
|
2008-05-14 15:07:48 +02:00
|
|
|
tubes_ready()
|
2007-10-29 18:21:33 +01:00
|
|
|
|
2010-06-22 16:31:21 +02:00
|
|
|
def text_channel_ready_cb(channel):
|
|
|
|
_logger.debug('%r: Text channel %r is ready', self, channel)
|
|
|
|
self.telepathy_text_chan = channel
|
2008-05-14 15:07:48 +02:00
|
|
|
tubes_ready()
|
2007-10-29 18:21:33 +01:00
|
|
|
|
2010-06-22 16:31:21 +02:00
|
|
|
def create_text_channel_cb(channel_path):
|
|
|
|
Channel(self.telepathy_conn.requested_bus_name, channel_path,
|
|
|
|
ready_handler=text_channel_ready_cb)
|
|
|
|
|
|
|
|
def create_tubes_channel_cb(channel_path):
|
|
|
|
Channel(self.telepathy_conn.requested_bus_name, channel_path,
|
|
|
|
ready_handler=tubes_channel_ready_cb)
|
|
|
|
|
|
|
|
def error_handler_cb(error):
|
|
|
|
raise RuntimeError(error)
|
|
|
|
|
|
|
|
self.telepathy_conn.RequestChannel(CHANNEL_TYPE_TEXT,
|
|
|
|
HANDLE_TYPE_ROOM, self._room_handle, True,
|
|
|
|
reply_handler=create_text_channel_cb,
|
|
|
|
error_handler=error_handler_cb,
|
|
|
|
dbus_interface=CONNECTION)
|
|
|
|
|
|
|
|
self.telepathy_conn.RequestChannel(CHANNEL_TYPE_TUBES,
|
|
|
|
HANDLE_TYPE_ROOM, self._room_handle, True,
|
|
|
|
reply_handler=create_tubes_channel_cb,
|
|
|
|
error_handler=error_handler_cb,
|
|
|
|
dbus_interface=CONNECTION)
|
2007-10-29 18:21:33 +01:00
|
|
|
|
2007-05-03 05:25:15 +02:00
|
|
|
def _join_cb(self):
|
2007-10-29 18:21:33 +01:00
|
|
|
_logger.debug('%r: Join finished', self)
|
2007-05-03 05:25:15 +02:00
|
|
|
self._joined = True
|
|
|
|
self.emit("joined", True, None)
|
|
|
|
|
|
|
|
def _join_error_cb(self, err):
|
2007-10-29 18:21:33 +01:00
|
|
|
_logger.debug('%r: Join failed because: %s', self, err)
|
2007-05-03 05:25:15 +02:00
|
|
|
self.emit("joined", False, str(err))
|
|
|
|
|
2007-04-09 20:40:56 +02:00
|
|
|
def join(self):
|
2007-10-29 18:21:33 +01:00
|
|
|
"""Join this activity.
|
|
|
|
|
|
|
|
Emits 'joined' and otherwise does nothing if we're already joined.
|
2007-04-15 06:27:48 +02:00
|
|
|
"""
|
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-10-29 18:21:33 +01:00
|
|
|
|
2007-10-16 18:51:36 +02:00
|
|
|
_logger.debug('%r: joining', self)
|
2007-10-29 18:21:33 +01:00
|
|
|
|
2010-06-22 16:31:21 +02:00
|
|
|
self.set_up_tubes(reply_handler=self._join_cb,
|
2010-06-28 16:42:23 +02:00
|
|
|
error_handler=self._join_error_cb)
|
|
|
|
|
|
|
|
def share(self, share_activity_cb, share_activity_error_cb):
|
|
|
|
if not self._room_handle is None:
|
|
|
|
raise ValueError('Already have a room handle')
|
|
|
|
|
|
|
|
""" TODO: Check we don't need this
|
|
|
|
# We shouldn't have to do this, but Gabble sometimes finds the IRC
|
|
|
|
# transport and goes "that has chatrooms, that'll do nicely". Work
|
|
|
|
# around it til Gabble gets better at finding the MUC service.
|
|
|
|
return '%s@%s' % (activity_id,
|
|
|
|
self._account['fallback-conference-server'])
|
|
|
|
"""
|
|
|
|
|
|
|
|
self.telepathy_conn.RequestHandles(
|
|
|
|
HANDLE_TYPE_ROOM,
|
|
|
|
[self._id],
|
|
|
|
reply_handler=partial(self.__got_handles_cb, share_activity_cb, share_activity_error_cb),
|
|
|
|
error_handler=partial(self.__share_error_cb, share_activity_error_cb),
|
|
|
|
dbus_interface=CONNECTION)
|
|
|
|
|
|
|
|
def __got_handles_cb(self, share_activity_cb, share_activity_error_cb, handles):
|
|
|
|
logging.debug('__got_handles_cb %r', handles)
|
|
|
|
self._room_handle = handles[0]
|
|
|
|
self._joined = True
|
|
|
|
|
|
|
|
self.set_up_tubes(
|
|
|
|
partial(self.__tubes_set_up_cb, share_activity_cb, share_activity_error_cb),
|
|
|
|
share_activity_error_cb)
|
|
|
|
|
|
|
|
def __tubes_set_up_cb(self, share_activity_cb, share_activity_error_cb):
|
|
|
|
self.telepathy_conn.AddActivity(
|
|
|
|
self._id,
|
|
|
|
self._room_handle,
|
|
|
|
reply_handler=partial(self.__added_activity_cb, share_activity_cb),
|
|
|
|
error_handler=partial(self.__share_error_cb, share_activity_error_cb),
|
|
|
|
dbus_interface=CONN_INTERFACE_BUDDY_INFO)
|
|
|
|
|
|
|
|
def __added_activity_cb(self, share_activity_cb):
|
|
|
|
self._publish_properties()
|
|
|
|
self._start_tracking_properties()
|
|
|
|
share_activity_cb(self)
|
|
|
|
|
|
|
|
def _publish_properties(self):
|
|
|
|
properties = {}
|
|
|
|
|
|
|
|
if self._color is not None:
|
|
|
|
properties['color'] = self._color
|
|
|
|
if self._name is not None:
|
|
|
|
properties['name'] = self._name
|
|
|
|
if self._type is not None:
|
|
|
|
properties['type'] = self._type
|
|
|
|
if self._tags is not None:
|
|
|
|
properties['tags'] = self._tags
|
|
|
|
properties['private'] = self._private
|
|
|
|
|
|
|
|
logging.debug('_publish_properties calling SetProperties')
|
|
|
|
self.telepathy_conn.SetProperties(
|
|
|
|
self._room_handle,
|
|
|
|
properties,
|
|
|
|
dbus_interface=CONN_INTERFACE_ACTIVITY_PROPERTIES)
|
|
|
|
|
|
|
|
def __share_error_cb(self, share_activity_error_cb, error):
|
|
|
|
logging.debug('%r: Share failed because: %s', self, error)
|
|
|
|
share_activity_error_cb(self, error)
|
2007-10-29 18:21:33 +01:00
|
|
|
|
|
|
|
# GetChannels() wrapper
|
2007-04-09 20:40:56 +02:00
|
|
|
|
|
|
|
def get_channels(self):
|
2009-08-25 19:55:48 +02:00
|
|
|
"""Retrieve communications channel descriptions for the activity
|
|
|
|
|
2007-10-02 11:56:36 +02:00
|
|
|
Returns a tuple containing:
|
|
|
|
- the D-Bus well-known service name of the connection
|
|
|
|
(FIXME: this is redundant; in Telepathy it can be derived
|
|
|
|
from that of the connection)
|
|
|
|
- the D-Bus object path of the connection
|
|
|
|
- a list of D-Bus object paths representing the channels
|
|
|
|
associated with this activity
|
2007-04-15 06:27:48 +02:00
|
|
|
"""
|
2007-04-09 20:40:56 +02:00
|
|
|
(bus_name, connection, channels) = self._activity.GetChannels()
|
2007-10-16 18:51:36 +02:00
|
|
|
_logger.debug('%r: bus name is %s, connection is %s, channels are %r',
|
|
|
|
self, bus_name, connection, channels)
|
2007-04-09 20:40:56 +02:00
|
|
|
return bus_name, connection, channels
|
|
|
|
|
2007-10-29 18:21:33 +01:00
|
|
|
# Leaving
|
|
|
|
|
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-10-02 11:28:12 +02:00
|
|
|
"""Callback for error in async leaving of shared activity."""
|
|
|
|
_logger.debug('Failed to leave activity: %s', err)
|
2007-07-03 14:22:30 +02:00
|
|
|
|
2007-05-03 05:25:15 +02:00
|
|
|
def leave(self):
|
2007-07-03 14:22:30 +02:00
|
|
|
"""Leave this shared activity"""
|
2007-10-16 18:51:36 +02:00
|
|
|
_logger.debug('%r: leaving', self)
|
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)
|