Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port to TelepathyGLib #837

Merged
merged 14 commits into from
Jul 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 29 additions & 5 deletions src/jarabe/model/buddy.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@

from gi.repository import GObject
import dbus
from telepathy.client import Connection
from telepathy.interfaces import CONNECTION

from gi.repository import TelepathyGLib
CONNECTION = TelepathyGLib.IFACE_CONNECTION
CONNECTION_STATUS_CONNECTED = TelepathyGLib.ConnectionStatus.CONNECTED

from sugar3 import profile

Expand Down Expand Up @@ -113,16 +115,38 @@ def __init__(self):
dbus_interface=dbus.BUS_DAEMON_IFACE):
if service.startswith(CONNECTION + '.'):
path = '/%s' % service.replace('.', '/')
Connection(service, path, bus,
ready_handler=self.__connection_ready_cb)
conn_proxy = bus.get_object(service, path)
self._prepare_conn(path, conn_proxy)

def _prepare_conn(self, object_path, conn_proxy):
self.connection = {}
self.object_path = object_path
self.conn_proxy = conn_proxy
self.conn_ready = False
self.connection[CONNECTION] = \
dbus.Interface(self.conn_proxy, CONNECTION)
self.connection[CONNECTION].GetInterfaces(
reply_handler=self.__conn_get_interfaces_reply_cb,
error_handler=self.__error_handler_cb)

def __conn_get_interfaces_reply_cb(self, interfaces):
for interface in interfaces:
self.connection[interface] = dbus.Interface(
self.conn_proxy, interface)
self.conn_ready = True
self.__connection_ready_cb(self.connection)

def __connection_ready_cb(self, connection):
if not self.conn_ready:
return

self._sync_properties_on_connection(connection)

def __name_owner_changed_cb(self, name, old, new):
if name.startswith(CONNECTION + '.') and not old and new:
path = '/' + name.replace('.', '/')
Connection(name, path, ready_handler=self.__connection_ready_cb)
self.conn_proxy = dbus.Bus().get_object(name, path)
self._prepare_conn(path, self.conn_proxy)

def __property_changed_cb(self, buddy, pspec):
self._sync_properties()
Expand Down
53 changes: 36 additions & 17 deletions src/jarabe/model/filetransfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,18 @@
from gi.repository import Gio
from gi.repository import GLib
import dbus
from telepathy.interfaces import \
CONNECTION_INTERFACE_REQUESTS, \
CHANNEL, \
CHANNEL_DISPATCHER
from telepathy.constants import CONNECTION_HANDLE_TYPE_CONTACT, \
SOCKET_ADDRESS_TYPE_UNIX, \
SOCKET_ACCESS_CONTROL_LOCALHOST
from telepathy.client import Connection, Channel

from gi.repository import TelepathyGLib
CONNECTION_INTERFACE_REQUESTS = \
TelepathyGLib.IFACE_CONNECTION_INTERFACE_REQUESTS
CHANNEL = TelepathyGLib.IFACE_CHANNEL
CHANNEL_DISPATCHER = TelepathyGLib.IFACE_CHANNEL_DISPATCHER
CONNECTION_HANDLE_TYPE_CONTACT = TelepathyGLib.HandleType.CONTACT
SOCKET_ADDRESS_TYPE_UNIX = TelepathyGLib.SocketAddressType.UNIX
SOCKET_ACCESS_CONTROL_LOCALHOST = TelepathyGLib.SocketAccessControl.LOCALHOST
CHANNEL_TYPE_FILE_TRANSFER = TelepathyGLib.IFACE_CHANNEL_TYPE_FILE_TRANSFER
CONNECTION = TelepathyGLib.IFACE_CONNECTION
CONNECTION_STATUS_CONNECTED = TelepathyGLib.ConnectionStatus.CONNECTED

from sugar3.presence import presenceservice
from sugar3 import dispatch
Expand All @@ -53,9 +57,6 @@
FT_REASON_LOCAL_ERROR = 5
FT_REASON_REMOTE_ERROR = 6

# FIXME: use constants from tp-python once the spec is undrafted
CHANNEL_TYPE_FILE_TRANSFER = \
'org.freedesktop.Telepathy.Channel.Type.FileTransfer'

new_file_transfer = dispatch.Signal()

Expand Down Expand Up @@ -139,7 +140,14 @@ class IncomingFileTransfer(BaseFileTransfer):
def __init__(self, connection, object_path, props):
BaseFileTransfer.__init__(self, connection)

channel = Channel(connection.service_name, object_path)
channel = {}
text_proxy = dbus.Bus().get_object(connection["service_name"], object_path)
channel[dbus.PROPERTIES_IFACE] = \
dbus.Interface(text_proxy, dbus.PROPERTIES_IFACE)
channel[CHANNEL_TYPE_FILE_TRANSFER] = \
dbus.Interface(text_proxy, CHANNEL_TYPE_FILE_TRANSFER)
channel[CHANNEL] = dbus.Interface(text_proxy, CHANNEL)

self.set_channel(channel)

self.connect('notify::state', self.__notify_state_cb)
Expand Down Expand Up @@ -193,12 +201,15 @@ def __init__(self, buddy, file_name, title, description, mime_type):

presence_service = presenceservice.get_instance()
name, path = presence_service.get_preferred_connection()
connection = Connection(name, path,
ready_handler=self.__connection_ready_cb)
connection = {}
conn_proxy = dbus.Bus().get_object(name, path)
connection[CONNECTION_INTERFACE_REQUESTS] = \
dbus.Interface(conn_proxy, CONNECTION_INTERFACE_REQUESTS)

BaseFileTransfer.__init__(self, connection)
self.connect('notify::state', self.__notify_state_cb)

self._service_name = name
self._file_name = file_name
self._socket_address = None
self._socket = None
Expand All @@ -211,6 +222,8 @@ def __init__(self, buddy, file_name, title, description, mime_type):
self.description = description
self.mime_type = mime_type

self.__connection_ready_cb(connection)

def __connection_ready_cb(self, connection):
requests = connection[CONNECTION_INTERFACE_REQUESTS]
object_path, properties_ = requests.CreateChannel({
Expand All @@ -223,7 +236,14 @@ def __connection_ready_cb(self, connection):
CHANNEL_TYPE_FILE_TRANSFER + '.Description': self.description,
CHANNEL_TYPE_FILE_TRANSFER + '.InitialOffset': 0})

self.set_channel(Channel(connection.service_name, object_path))
channel = {}
text_proxy = dbus.Bus().get_object(self._service_name, object_path)
channel[dbus.PROPERTIES_IFACE] = \
dbus.Interface(text_proxy, dbus.PROPERTIES_IFACE)
channel[CHANNEL_TYPE_FILE_TRANSFER] = \
dbus.Interface(text_proxy, CHANNEL_TYPE_FILE_TRANSFER)
channel[CHANNEL] = dbus.Interface(text_proxy, CHANNEL)
self.set_channel(channel)

channel_file_transfer = self.channel[CHANNEL_TYPE_FILE_TRANSFER]
self._socket_address = channel_file_transfer.ProvideFile(
Expand Down Expand Up @@ -319,8 +339,7 @@ def file_transfer_available():
for connection in conn_watcher.get_connections():

try:
properties_iface = connection[
dbus.PROPERTIES_IFACE]
properties_iface = connection[dbus.PROPERTIES_IFACE]
properties = properties_iface.GetAll(
CONNECTION_INTERFACE_REQUESTS)
except dbus.DBusException as e:
Expand Down
16 changes: 9 additions & 7 deletions src/jarabe/model/invites.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@

from gi.repository import GObject
import dbus
from telepathy.interfaces import CHANNEL, \
CHANNEL_DISPATCHER, \
CHANNEL_DISPATCH_OPERATION, \
CHANNEL_TYPE_CONTACT_LIST, \
CHANNEL_TYPE_TEXT, \
CLIENT
from telepathy.constants import HANDLE_TYPE_ROOM

from gi.repository import TelepathyGLib
CHANNEL = TelepathyGLib.IFACE_CHANNEL
CHANNEL_DISPATCHER = TelepathyGLib.IFACE_CHANNEL_DISPATCHER
CHANNEL_DISPATCH_OPERATION = TelepathyGLib.IFACE_CHANNEL_DISPATCH_OPERATION
CHANNEL_TYPE_CONTACT_LIST = TelepathyGLib.IFACE_CHANNEL_TYPE_CONTACT_LIST
CHANNEL_TYPE_TEXT = TelepathyGLib.IFACE_CHANNEL_TYPE_TEXT
CLIENT = TelepathyGLib.IFACE_CLIENT
HANDLE_TYPE_ROOM = TelepathyGLib.HandleType.ROOM

from sugar3.graphics.xocolor import XoColor
from sugar3 import profile
Expand Down
95 changes: 68 additions & 27 deletions src/jarabe/model/neighborhood.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,30 @@
from gi.repository import Gio
import dbus
from dbus import PROPERTIES_IFACE
from telepathy.interfaces import ACCOUNT, \
ACCOUNT_MANAGER, \
CHANNEL, \
CHANNEL_INTERFACE_GROUP, \
CHANNEL_TYPE_CONTACT_LIST, \
CHANNEL_TYPE_FILE_TRANSFER, \
CLIENT, \
CONNECTION, \
CONNECTION_INTERFACE_ALIASING, \
CONNECTION_INTERFACE_CONTACTS, \
CONNECTION_INTERFACE_CONTACT_CAPABILITIES, \
CONNECTION_INTERFACE_REQUESTS, \
CONNECTION_INTERFACE_SIMPLE_PRESENCE
from telepathy.constants import HANDLE_TYPE_CONTACT, \
HANDLE_TYPE_LIST, \
CONNECTION_PRESENCE_TYPE_OFFLINE, \
CONNECTION_STATUS_CONNECTED, \
CONNECTION_STATUS_DISCONNECTED
from telepathy.client import Connection, Channel
from gi.repository import TelepathyGLib
ACCOUNT = TelepathyGLib.IFACE_ACCOUNT
ACCOUNT_MANAGER = TelepathyGLib.IFACE_ACCOUNT_MANAGER
CHANNEL = TelepathyGLib.IFACE_CHANNEL
CHANNEL_INTERFACE_GROUP = TelepathyGLib.IFACE_CHANNEL_INTERFACE_GROUP
CHANNEL_TYPE_CONTACT_LIST = TelepathyGLib.IFACE_CHANNEL_TYPE_CONTACT_LIST
CHANNEL_TYPE_FILE_TRANSFER = TelepathyGLib.IFACE_CHANNEL_TYPE_FILE_TRANSFER
CLIENT = TelepathyGLib.IFACE_CLIENT
CONNECTION = TelepathyGLib.IFACE_CONNECTION
CONNECTION_INTERFACE_ALIASING = \
TelepathyGLib.IFACE_CONNECTION_INTERFACE_ALIASING
CONNECTION_INTERFACE_CONTACTS = \
TelepathyGLib.IFACE_CONNECTION_INTERFACE_CONTACTS
CONNECTION_INTERFACE_CONTACT_CAPABILITIES = \
TelepathyGLib.IFACE_CONNECTION_INTERFACE_CONTACT_CAPABILITIES
CONNECTION_INTERFACE_REQUESTS = \
TelepathyGLib.IFACE_CONNECTION_INTERFACE_REQUESTS
CONNECTION_INTERFACE_SIMPLE_PRESENCE = \
TelepathyGLib.IFACE_CONNECTION_INTERFACE_SIMPLE_PRESENCE
HANDLE_TYPE_CONTACT = TelepathyGLib.HandleType.CONTACT
HANDLE_TYPE_LIST = TelepathyGLib.HandleType.LIST
CONNECTION_PRESENCE_TYPE_OFFLINE = TelepathyGLib.ConnectionPresenceType.OFFLINE
CONNECTION_STATUS_CONNECTED = TelepathyGLib.ConnectionStatus.CONNECTED
CONNECTION_STATUS_DISCONNECTED = TelepathyGLib.ConnectionStatus.DISCONNECTED

from sugar3.graphics.xocolor import XoColor
from sugar3.profile import get_profile
Expand Down Expand Up @@ -264,13 +269,43 @@ def __account_property_changed_cb(self, properties):
def _prepare_connection(self, connection_path):
connection_name = connection_path.replace('/', '.')[1:]

self._connection = Connection(connection_name, connection_path,
ready_handler=self.__connection_ready_cb)
self._connection = {}
self._object_path = connection_path
self.conn_ready = False
self.conn_proxy = dbus.Bus().get_object(connection_name, connection_path)
self._connection[PROPERTIES_IFACE] = dbus.Interface(
self.conn_proxy, PROPERTIES_IFACE)
self._connection[CONNECTION_INTERFACE_ALIASING] = \
dbus.Interface(self.conn_proxy, CONNECTION_INTERFACE_ALIASING)
self._connection[CONNECTION_INTERFACE_SIMPLE_PRESENCE] = \
dbus.Interface(self.conn_proxy, CONNECTION_INTERFACE_SIMPLE_PRESENCE)
self._connection[CONNECTION_INTERFACE_REQUESTS] = \
dbus.Interface(self.conn_proxy, CONNECTION_INTERFACE_REQUESTS)
self._connection[CONNECTION_INTERFACE_ACTIVITY_PROPERTIES] = \
dbus.Interface(self.conn_proxy, CONNECTION_INTERFACE_ACTIVITY_PROPERTIES)
self._connection[CONNECTION_INTERFACE_CONTACTS] = \
dbus.Interface(self.conn_proxy, CONNECTION_INTERFACE_CONTACTS)
self._connection[CONNECTION] = dbus.Interface(self.conn_proxy, CONNECTION)
self._connection[CONNECTION].GetInterfaces(
reply_handler=self.__conn_get_interfaces_reply_cb,
error_handler=partial(
self.__error_handler_cb,
'dbus.GetInterfaces'))

def __conn_get_interfaces_reply_cb(self, interfaces):
for interface in interfaces:
self._connection[interface] = dbus.Interface(
self.conn_proxy, interface)
self.conn_ready = True
self.__connection_ready_cb(self._connection)

def __connection_ready_cb(self, connection):
if not self.conn_ready:
return

logging.debug('_Account.__connection_ready_cb %r',
connection.object_path)
connection.connect_to_signal('StatusChanged',
self._object_path)
connection[CONNECTION].connect_to_signal('StatusChanged',
self.__status_changed_cb)

connection[PROPERTIES_IFACE].Get(CONNECTION,
Expand All @@ -282,7 +317,7 @@ def __connection_ready_cb(self, connection):

def __get_status_cb(self, status):
logging.debug('_Account.__get_status_cb %r %r',
self._connection.object_path, status)
self._object_path, status)
self._update_status(status)

def __status_changed_cb(self, status, reason):
Expand Down Expand Up @@ -361,7 +396,7 @@ def __get_self_handle_cb(self, self_handle):
self.__active_activity_changed_cb)
else:
logging.warning('Connection %s does not support OLPC buddy '
'properties', self._connection.object_path)
'properties', self._object_path)

if CONNECTION_INTERFACE_ACTIVITY_PROPERTIES in self._connection:
connection = self._connection[
Expand All @@ -371,7 +406,7 @@ def __get_self_handle_cb(self, self_handle):
self.__activity_properties_changed_cb)
else:
logging.warning('Connection %s does not support OLPC activity '
'properties', self._connection.object_path)
'properties', self._object_path)

properties = {
CHANNEL + '.ChannelType': CHANNEL_TYPE_CONTACT_LIST,
Expand All @@ -383,7 +418,13 @@ def __get_self_handle_cb(self, self_handle):
is_ours, channel_path, properties = \
connection.EnsureChannel(properties)

channel = Channel(self._connection.service_name, channel_path)
channel = {}
service_name = self._object_path.replace('/', '.')[1:]
text_proxy = dbus.Bus().get_object(service_name, channel_path)
channel[PROPERTIES_IFACE] = dbus.Interface(text_proxy, PROPERTIES_IFACE)
channel[CHANNEL_INTERFACE_GROUP] = \
dbus.Interface(text_proxy, CHANNEL_INTERFACE_GROUP)

channel[CHANNEL_INTERFACE_GROUP].connect_to_signal(
'MembersChanged', self.__members_changed_cb)

Expand Down
Loading