Port to TelepathyGLib
Co-authored-by: tonadev <tonadevv@gmail.com> [initial port] Co-authored-by: Aniket21mathur <aniketmathur320@gmail.com> [further work] Co-authored-by: James Cameron <quozl@laptop.org> [minimising changes]
This commit is contained in:
parent
ac7482081e
commit
88ea8e1f4f
@ -172,22 +172,17 @@ import json
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
gi.require_version('Gdk', '3.0')
|
||||
gi.require_version('TelepathyGLib', '0.12')
|
||||
gi.require_version('SugarExt', '1.0')
|
||||
|
||||
from gi.repository import GLib
|
||||
from gi.repository import GObject
|
||||
from gi.repository import Gdk
|
||||
from gi.repository import Gtk
|
||||
from gi.repository import TelepathyGLib
|
||||
import dbus
|
||||
import dbus.service
|
||||
from dbus import PROPERTIES_IFACE
|
||||
from telepathy.server import DBusProperties
|
||||
from telepathy.interfaces import CHANNEL, \
|
||||
CHANNEL_TYPE_TEXT, \
|
||||
CLIENT, \
|
||||
CLIENT_HANDLER
|
||||
from telepathy.constants import CONNECTION_HANDLE_TYPE_CONTACT
|
||||
from telepathy.constants import CONNECTION_HANDLE_TYPE_ROOM
|
||||
|
||||
from sugar3 import util
|
||||
from sugar3 import power
|
||||
@ -222,6 +217,14 @@ N_BUS_NAME = 'org.freedesktop.Notifications'
|
||||
N_OBJ_PATH = '/org/freedesktop/Notifications'
|
||||
N_IFACE_NAME = 'org.freedesktop.Notifications'
|
||||
|
||||
CHANNEL = TelepathyGLib.IFACE_CHANNEL
|
||||
CHANNEL_TYPE_TEXT = TelepathyGLib.IFACE_CHANNEL_TYPE_TEXT
|
||||
CLIENT = TelepathyGLib.IFACE_CLIENT
|
||||
CLIENT_HANDLER = TelepathyGLib.IFACE_CLIENT_HANDLER
|
||||
|
||||
CONNECTION_HANDLE_TYPE_CONTACT = TelepathyGLib.HandleType.CONTACT
|
||||
CONNECTION_HANDLE_TYPE_ROOM = TelepathyGLib.HandleType.ROOM
|
||||
|
||||
CONN_INTERFACE_ACTIVITY_PROPERTIES = 'org.laptop.Telepathy.ActivityProperties'
|
||||
|
||||
PREVIEW_SIZE = style.zoom(300), style.zoom(225)
|
||||
@ -1418,7 +1421,7 @@ class Activity(Window, Gtk.Container):
|
||||
Gdk.flush()
|
||||
|
||||
|
||||
class _ClientHandler(dbus.service.Object, DBusProperties):
|
||||
class _ClientHandler(dbus.service.Object):
|
||||
def __init__(self, bundle_id, got_channel_cb):
|
||||
self._interfaces = set([CLIENT, CLIENT_HANDLER, PROPERTIES_IFACE])
|
||||
self._got_channel_cb = got_channel_cb
|
||||
@ -1429,12 +1432,13 @@ class _ClientHandler(dbus.service.Object, DBusProperties):
|
||||
|
||||
path = '/' + name.replace('.', '/')
|
||||
dbus.service.Object.__init__(self, bus_name, path)
|
||||
DBusProperties.__init__(self)
|
||||
|
||||
self._implement_property_get(CLIENT, {
|
||||
self._prop_getters = {}
|
||||
self._prop_setters = {}
|
||||
self._prop_getters.setdefault(CLIENT, {}).update({
|
||||
'Interfaces': lambda: list(self._interfaces),
|
||||
})
|
||||
self._implement_property_get(CLIENT_HANDLER, {
|
||||
self._prop_getters.setdefault(CLIENT_HANDLER, {}).update({
|
||||
'HandlerChannelFilter': self.__get_filters_cb,
|
||||
})
|
||||
|
||||
@ -1465,6 +1469,34 @@ class _ClientHandler(dbus.service.Object, DBusProperties):
|
||||
except Exception as e:
|
||||
logging.exception(e)
|
||||
|
||||
@dbus.service.method(dbus_interface=dbus.PROPERTIES_IFACE,
|
||||
in_signature='ss', out_signature='v')
|
||||
def Get(self, interface_name, property_name):
|
||||
if interface_name in self._prop_getters \
|
||||
and property_name in self._prop_getters[interface_name]:
|
||||
return self._prop_getters[interface_name][property_name]()
|
||||
else:
|
||||
logging.debug('InvalidArgument')
|
||||
|
||||
@dbus.service.method(dbus_interface=dbus.PROPERTIES_IFACE,
|
||||
in_signature='ssv', out_signature='')
|
||||
def Set(self, interface_name, property_name, value):
|
||||
if interface_name in self._prop_setters \
|
||||
and property_name in self._prop_setters[interface_name]:
|
||||
self._prop_setters[interface_name][property_name](value)
|
||||
else:
|
||||
logging.debug('PermissionDenied')
|
||||
|
||||
@dbus.service.method(dbus_interface=dbus.PROPERTIES_IFACE,
|
||||
in_signature='s', out_signature='a{sv}')
|
||||
def GetAll(self, interface_name):
|
||||
if interface_name in self._prop_getters:
|
||||
r = {}
|
||||
for k, v in self._prop_getters[interface_name].items():
|
||||
r[k] = v()
|
||||
return r
|
||||
else:
|
||||
logging.debug('InvalidArgument')
|
||||
|
||||
_session = None
|
||||
|
||||
|
@ -25,27 +25,32 @@ import six
|
||||
import logging
|
||||
from functools import partial
|
||||
|
||||
import gi
|
||||
gi.require_version('TelepathyGLib', '0.12')
|
||||
import dbus
|
||||
from dbus import PROPERTIES_IFACE
|
||||
from gi.repository import GObject
|
||||
from telepathy.client import Channel
|
||||
from telepathy.interfaces import CHANNEL, \
|
||||
CHANNEL_INTERFACE_GROUP, \
|
||||
CHANNEL_TYPE_TUBES, \
|
||||
CHANNEL_TYPE_TEXT, \
|
||||
CONNECTION, \
|
||||
PROPERTIES_INTERFACE
|
||||
from telepathy.constants import CHANNEL_GROUP_FLAG_CHANNEL_SPECIFIC_HANDLES, \
|
||||
HANDLE_TYPE_ROOM, \
|
||||
HANDLE_TYPE_CONTACT, \
|
||||
PROPERTY_FLAG_WRITE
|
||||
from gi.repository import TelepathyGLib
|
||||
|
||||
from sugar3.presence.buddy import Buddy
|
||||
|
||||
CHANNEL = TelepathyGLib.IFACE_CHANNEL
|
||||
CHANNEL_INTERFACE_GROUP = TelepathyGLib.IFACE_CHANNEL_INTERFACE_GROUP
|
||||
CONN_INTERFACE_ROOM_CONFIG = \
|
||||
TelepathyGLib.IFACE_CHANNEL_INTERFACE_ROOM_CONFIG
|
||||
CHANNEL_TYPE_TUBES = TelepathyGLib.IFACE_CHANNEL_TYPE_TUBES
|
||||
CHANNEL_TYPE_TEXT = TelepathyGLib.IFACE_CHANNEL_TYPE_TEXT
|
||||
CONNECTION = TelepathyGLib.IFACE_CONNECTION
|
||||
PROPERTIES_INTERFACE = TelepathyGLib.IFACE_PROPERTIES_INTERFACE
|
||||
|
||||
CHANNEL_GROUP_FLAG_CHANNEL_SPECIFIC_HANDLES = \
|
||||
TelepathyGLib.ChannelGroupFlags.CHANNEL_SPECIFIC_HANDLES
|
||||
HANDLE_TYPE_CONTACT = TelepathyGLib.HandleType.CONTACT
|
||||
HANDLE_TYPE_ROOM = TelepathyGLib.HandleType.ROOM
|
||||
PROPERTY_FLAG_WRITE = TelepathyGLib.PropertyFlags.WRITE
|
||||
|
||||
CONN_INTERFACE_ACTIVITY_PROPERTIES = 'org.laptop.Telepathy.ActivityProperties'
|
||||
CONN_INTERFACE_BUDDY_INFO = 'org.laptop.Telepathy.BuddyInfo'
|
||||
CONN_INTERFACE_ROOM_CONFIG = \
|
||||
'org.freedesktop.Telepathy.Channel.Interface.RoomConfig1'
|
||||
|
||||
_logger = logging.getLogger('sugar3.presence.activity')
|
||||
|
||||
@ -274,7 +279,7 @@ class Activity(GObject.GObject):
|
||||
if not self._joined:
|
||||
raise RuntimeError('Cannot invite a buddy to an activity that is'
|
||||
'not shared.')
|
||||
self.telepathy_text_chan.AddMembers(
|
||||
self.telepathy_text_chan[CHANNEL].AddMembers(
|
||||
[buddy.contact_handle], message,
|
||||
dbus_interface=CHANNEL_INTERFACE_GROUP,
|
||||
reply_handler=partial(
|
||||
@ -489,7 +494,7 @@ class Activity(GObject.GObject):
|
||||
def leave(self):
|
||||
"""Leave this shared activity"""
|
||||
_logger.debug('%r: leaving' % self)
|
||||
self.telepathy_text_chan.Close()
|
||||
self.telepathy_text_chan[CHANNEL].Close()
|
||||
|
||||
|
||||
class _BaseCommand(GObject.GObject):
|
||||
@ -586,6 +591,7 @@ class _JoinCommand(_BaseCommand):
|
||||
def __get_self_handle_cb(self, handle):
|
||||
self._global_self_handle = handle
|
||||
|
||||
self._text_ready = False
|
||||
self._connection.RequestChannel(
|
||||
CHANNEL_TYPE_TEXT,
|
||||
HANDLE_TYPE_ROOM,
|
||||
@ -594,6 +600,7 @@ class _JoinCommand(_BaseCommand):
|
||||
error_handler=self.__error_handler_cb,
|
||||
dbus_interface=CONNECTION)
|
||||
|
||||
self._tubes_ready = False
|
||||
self._connection.RequestChannel(
|
||||
CHANNEL_TYPE_TUBES,
|
||||
HANDLE_TYPE_ROOM,
|
||||
@ -604,18 +611,52 @@ class _JoinCommand(_BaseCommand):
|
||||
dbus_interface=CONNECTION)
|
||||
|
||||
def __create_text_channel_cb(self, channel_path):
|
||||
Channel(self._connection.requested_bus_name, channel_path,
|
||||
ready_handler=self.__text_channel_ready_cb)
|
||||
self.text_channel = {}
|
||||
self.text_proxy = dbus.Bus().get_object(
|
||||
self._connection.requested_bus_name, channel_path)
|
||||
self.text_channel[PROPERTIES_IFACE] = dbus.Interface(
|
||||
self.text_proxy, PROPERTIES_IFACE)
|
||||
self.text_channel[CHANNEL_TYPE_TEXT] = \
|
||||
dbus.Interface(self.text_proxy, CHANNEL_TYPE_TEXT)
|
||||
self.text_channel[CHANNEL] = dbus.Interface(self.text_proxy, CHANNEL)
|
||||
self.text_channel[CHANNEL].GetInterfaces(
|
||||
reply_handler=self.__text_get_interfaces_reply_cb,
|
||||
error_handler=self.__error_handler_cb)
|
||||
|
||||
def __text_get_interfaces_reply_cb(self, interfaces):
|
||||
for interface in interfaces:
|
||||
self.text_channel[interface] = dbus.Interface(
|
||||
self.text_proxy, interface)
|
||||
_logger.debug('%r: Text channel is ready' % (self))
|
||||
self._text_ready = True
|
||||
self._ready()
|
||||
|
||||
def __create_tubes_channel_cb(self, channel_path):
|
||||
Channel(self._connection.requested_bus_name, channel_path,
|
||||
ready_handler=self.__tubes_channel_ready_cb)
|
||||
self.tubes_channel = {}
|
||||
self.tubes_proxy = dbus.Bus().get_object(
|
||||
self._connection.requested_bus_name, channel_path)
|
||||
self.tubes_channel[PROPERTIES_IFACE] = dbus.Interface(
|
||||
self.tubes_proxy, PROPERTIES_IFACE)
|
||||
self.tubes_channel[CHANNEL_TYPE_TUBES] = \
|
||||
dbus.Interface(self.tubes_proxy, CHANNEL_TYPE_TUBES)
|
||||
self.tubes_channel[CHANNEL] = dbus.Interface(self.tubes_proxy, CHANNEL)
|
||||
self.tubes_channel[CHANNEL].GetInterfaces(
|
||||
reply_handler=self.__tubes_get_interfaces_reply_cb,
|
||||
error_handler=self.__error_handler_cb)
|
||||
|
||||
def __tubes_get_interfaces_reply_cb(self, interfaces):
|
||||
for interface in interfaces:
|
||||
self.tubes_channel[interface] = dbus.Interface(
|
||||
self.tubes_proxy, interface)
|
||||
_logger.debug('%r: Tubes channel is ready' % (self))
|
||||
self._tubes_ready = True
|
||||
self._ready()
|
||||
|
||||
def __tubes_error_handler_cb(self, error):
|
||||
if (error.get_dbus_name() ==
|
||||
'org.freedesktop.Telepathy.Error.NotImplemented'):
|
||||
self._tubes_supported = False
|
||||
self._tubes_ready()
|
||||
self._ready()
|
||||
else:
|
||||
self._finished = True
|
||||
self.emit('finished', error)
|
||||
@ -624,22 +665,12 @@ class _JoinCommand(_BaseCommand):
|
||||
self._finished = True
|
||||
self.emit('finished', error)
|
||||
|
||||
def __tubes_channel_ready_cb(self, channel):
|
||||
_logger.debug('%r: Tubes channel %r is ready' % (self, channel))
|
||||
self.tubes_channel = channel
|
||||
self._tubes_ready()
|
||||
|
||||
def __text_channel_ready_cb(self, channel):
|
||||
_logger.debug('%r: Text channel %r is ready' % (self, channel))
|
||||
self.text_channel = channel
|
||||
self._tubes_ready()
|
||||
|
||||
def _tubes_ready(self):
|
||||
if self.text_channel is None or \
|
||||
(self._tubes_supported and self.tubes_channel is None):
|
||||
def _ready(self):
|
||||
if not self._text_ready or \
|
||||
(self._tubes_supported and not self._tubes_ready):
|
||||
return
|
||||
|
||||
_logger.debug('%r: finished setting up tubes' % self)
|
||||
_logger.debug('%r: finished setting up channel' % self)
|
||||
|
||||
self._add_self_to_channel()
|
||||
|
||||
|
@ -22,18 +22,26 @@ STABLE.
|
||||
"""
|
||||
|
||||
import logging
|
||||
|
||||
import six
|
||||
import gi
|
||||
gi.require_version('TelepathyGLib', '0.12')
|
||||
from gi.repository import GObject
|
||||
import dbus
|
||||
from telepathy.interfaces import CONNECTION, \
|
||||
CONNECTION_INTERFACE_ALIASING, \
|
||||
CONNECTION_INTERFACE_CONTACTS
|
||||
from telepathy.constants import HANDLE_TYPE_CONTACT
|
||||
|
||||
from sugar3.presence.connectionmanager import get_connection_manager
|
||||
from sugar3.profile import get_color, get_nick_name
|
||||
|
||||
ACCOUNT_MANAGER_SERVICE = 'org.freedesktop.Telepathy.AccountManager'
|
||||
from gi.repository import TelepathyGLib
|
||||
|
||||
CONNECTION = TelepathyGLib.IFACE_CONNECTION
|
||||
CONNECTION_INTERFACE_ALIASING = \
|
||||
TelepathyGLib.IFACE_CONNECTION_INTERFACE_ALIASING
|
||||
CONNECTION_INTERFACE_CONTACTS = \
|
||||
TelepathyGLib.IFACE_CONNECTION_INTERFACE_CONTACTS
|
||||
|
||||
HANDLE_TYPE_CONTACT = TelepathyGLib.HandleType.CONTACT
|
||||
|
||||
CONN_INTERFACE_BUDDY_INFO = 'org.laptop.Telepathy.BuddyInfo'
|
||||
|
||||
_logger = logging.getLogger('sugar3.presence.buddy')
|
||||
|
@ -23,12 +23,20 @@ from functools import partial
|
||||
|
||||
import dbus
|
||||
from dbus import PROPERTIES_IFACE
|
||||
from telepathy.interfaces import ACCOUNT, \
|
||||
ACCOUNT_MANAGER
|
||||
from telepathy.constants import CONNECTION_STATUS_CONNECTED
|
||||
|
||||
ACCOUNT_MANAGER_SERVICE = 'org.freedesktop.Telepathy.AccountManager'
|
||||
ACCOUNT_MANAGER_PATH = '/org/freedesktop/Telepathy/AccountManager'
|
||||
from gi.repository import TelepathyGLib
|
||||
|
||||
ACCOUNT_MANAGER_SERVICE = TelepathyGLib.ACCOUNT_MANAGER_BUS_NAME
|
||||
ACCOUNT_MANAGER_PATH = TelepathyGLib.ACCOUNT_MANAGER_OBJECT_PATH
|
||||
ACCOUNT_MANAGER = TelepathyGLib.IFACE_ACCOUNT_MANAGER
|
||||
|
||||
ACCOUNT = TelepathyGLib.IFACE_ACCOUNT
|
||||
|
||||
HANDLE_TYPE_CONTACT = TelepathyGLib.HandleType.CONTACT
|
||||
|
||||
CONNECTION = TelepathyGLib.IFACE_CONNECTION
|
||||
|
||||
CONNECTION_STATUS_CONNECTED = TelepathyGLib.ConnectionStatus.CONNECTED
|
||||
|
||||
|
||||
class Connection(object):
|
||||
|
@ -21,8 +21,6 @@ STABLE.
|
||||
"""
|
||||
|
||||
import logging
|
||||
|
||||
from gi.repository import GObject
|
||||
import dbus
|
||||
import dbus.exceptions
|
||||
from dbus import PROPERTIES_IFACE
|
||||
@ -31,16 +29,20 @@ from sugar3.presence.buddy import Buddy, Owner
|
||||
from sugar3.presence.activity import Activity
|
||||
from sugar3.presence.connectionmanager import get_connection_manager
|
||||
|
||||
from telepathy.interfaces import ACCOUNT, \
|
||||
ACCOUNT_MANAGER, \
|
||||
CONNECTION
|
||||
from telepathy.constants import HANDLE_TYPE_CONTACT
|
||||
|
||||
from gi.repository import GObject
|
||||
from gi.repository import TelepathyGLib
|
||||
|
||||
_logger = logging.getLogger('sugar3.presence.presenceservice')
|
||||
|
||||
ACCOUNT_MANAGER_SERVICE = 'org.freedesktop.Telepathy.AccountManager'
|
||||
ACCOUNT_MANAGER_PATH = '/org/freedesktop/Telepathy/AccountManager'
|
||||
ACCOUNT_MANAGER_SERVICE = TelepathyGLib.ACCOUNT_MANAGER_BUS_NAME
|
||||
ACCOUNT_MANAGER_PATH = TelepathyGLib.ACCOUNT_MANAGER_OBJECT_PATH
|
||||
ACCOUNT_MANAGER = TelepathyGLib.IFACE_ACCOUNT_MANAGER
|
||||
|
||||
ACCOUNT = TelepathyGLib.IFACE_ACCOUNT
|
||||
|
||||
HANDLE_TYPE_CONTACT = TelepathyGLib.HandleType.CONTACT
|
||||
|
||||
CONNECTION = TelepathyGLib.IFACE_CONNECTION
|
||||
|
||||
CONN_INTERFACE_ACTIVITY_PROPERTIES = 'org.laptop.Telepathy.ActivityProperties'
|
||||
|
||||
|
@ -19,11 +19,12 @@
|
||||
STABLE.
|
||||
"""
|
||||
|
||||
from telepathy.constants import (
|
||||
CHANNEL_GROUP_FLAG_CHANNEL_SPECIFIC_HANDLES)
|
||||
|
||||
from sugar3.presence.tubeconn import TubeConnection
|
||||
from sugar3.presence import presenceservice
|
||||
from gi.repository import TelepathyGLib
|
||||
|
||||
CHANNEL_GROUP_FLAG_CHANNEL_SPECIFIC_HANDLES = \
|
||||
TelepathyGLib.ChannelGroupFlags.CHANNEL_SPECIFIC_HANDLES
|
||||
|
||||
|
||||
class SugarTubeConnection(TubeConnection):
|
||||
|
Loading…
Reference in New Issue
Block a user