diff options
author | Louis-Francis Ratté-Boulianne <louis-francis.ratte-boulianne@collabora.co.uk> | 2010-11-09 16:17:31 -0500 |
---|---|---|
committer | Louis-Francis Ratté-Boulianne <louis-francis.ratte-boulianne@collabora.co.uk> | 2010-12-03 15:51:12 -0500 |
commit | fc33649dca51327e47f38781c21bc7e49df94943 (patch) | |
tree | 6b7669b79eaf03814ab78512658e9aa9346239fe | |
parent | 8a09e9d5de751db7ae24326af79aa69cbfa88b35 (diff) |
spec: add implementation for new Protocol object
-rw-r--r-- | butterfly/Makefile.am | 3 | ||||
-rw-r--r-- | butterfly/channel_manager.py | 60 | ||||
-rw-r--r-- | butterfly/connection.py | 36 | ||||
-rw-r--r-- | butterfly/connection_manager.py | 37 | ||||
-rw-r--r-- | butterfly/presence.py | 40 | ||||
-rw-r--r-- | butterfly/protocol.py | 160 |
6 files changed, 181 insertions, 155 deletions
diff --git a/butterfly/Makefile.am b/butterfly/Makefile.am index 4ab8637..0ec7cb2 100644 --- a/butterfly/Makefile.am +++ b/butterfly/Makefile.am @@ -13,4 +13,5 @@ butterfly_PYTHON = \ connection_manager.py \ contacts.py \ handle.py \ - mail_notification.py + mail_notification.py \ + protocol.py diff --git a/butterfly/channel_manager.py b/butterfly/channel_manager.py index c2715be..72d5b5c 100644 --- a/butterfly/channel_manager.py +++ b/butterfly/channel_manager.py @@ -82,61 +82,15 @@ class ButterflyChannelManager(telepathy.server.ChannelManager): __media_channel_id = 1 __ft_channel_id = 1 - def __init__(self, connection): + def __init__(self, connection, protocol): telepathy.server.ChannelManager.__init__(self, connection) - classes = [ - ({telepathy.CHANNEL_INTERFACE + '.ChannelType': telepathy.CHANNEL_TYPE_TEXT, - telepathy.CHANNEL_INTERFACE + '.TargetHandleType': dbus.UInt32(telepathy.HANDLE_TYPE_CONTACT)}, - [telepathy.CHANNEL_INTERFACE + '.TargetHandle', - telepathy.CHANNEL_INTERFACE + '.TargetID']), - - ({telepathy.CHANNEL_INTERFACE + '.ChannelType': telepathy.CHANNEL_TYPE_TEXT, - telepathy.CHANNEL_INTERFACE + '.TargetHandleType': dbus.UInt32(telepathy.HANDLE_TYPE_NONE)}, - [CHANNEL_INTERFACE_CONFERENCE + '.InitialChannels', - CHANNEL_INTERFACE_CONFERENCE + '.InitialInviteeHandles', - CHANNEL_INTERFACE_CONFERENCE + '.InitialInviteeIDs', - CHANNEL_INTERFACE_CONFERENCE + '.InitialMessage', - CHANNEL_INTERFACE_CONFERENCE + '.SupportsNonMerges']) - ] - self.implement_channel_classes(telepathy.CHANNEL_TYPE_TEXT, self._get_text_channel, classes) - - classes = [ - ({telepathy.CHANNEL_INTERFACE + '.ChannelType': telepathy.CHANNEL_TYPE_CONTACT_LIST, - telepathy.CHANNEL_INTERFACE + '.TargetHandleType': dbus.UInt32(telepathy.HANDLE_TYPE_GROUP)}, - [telepathy.CHANNEL_INTERFACE + '.TargetHandle', - telepathy.CHANNEL_INTERFACE + '.TargetID']), - - ({telepathy.CHANNEL_INTERFACE + '.ChannelType': telepathy.CHANNEL_TYPE_CONTACT_LIST, - telepathy.CHANNEL_INTERFACE + '.TargetHandleType': dbus.UInt32(telepathy.HANDLE_TYPE_LIST)}, - [telepathy.CHANNEL_INTERFACE + '.TargetHandle', - telepathy.CHANNEL_INTERFACE + '.TargetID']) - ] - self.implement_channel_classes(telepathy.CHANNEL_TYPE_CONTACT_LIST, self._get_list_channel, classes) - - classes = [ - ({telepathy.CHANNEL_INTERFACE + '.ChannelType': telepathy.CHANNEL_TYPE_STREAMED_MEDIA, - telepathy.CHANNEL_INTERFACE + '.TargetHandleType': dbus.UInt32(telepathy.HANDLE_TYPE_CONTACT)}, - [telepathy.CHANNEL_INTERFACE + '.TargetHandle', - telepathy.CHANNEL_INTERFACE + '.TargetID', - telepathy.CHANNEL_TYPE_STREAMED_MEDIA + '.InitialAudio', - telepathy.CHANNEL_TYPE_STREAMED_MEDIA + '.InitialVideo']) - ] - self.implement_channel_classes(telepathy.CHANNEL_TYPE_STREAMED_MEDIA, self._get_media_channel, classes) - - classes = [ - ({telepathy.CHANNEL_INTERFACE + '.ChannelType': telepathy.CHANNEL_TYPE_FILE_TRANSFER, - telepathy.CHANNEL_INTERFACE + '.TargetHandleType': dbus.UInt32(telepathy.HANDLE_TYPE_CONTACT)}, - [telepathy.CHANNEL_INTERFACE + '.TargetHandle', - telepathy.CHANNEL_INTERFACE + '.TargetID', - telepathy.CHANNEL_TYPE_FILE_TRANSFER + '.ContentType', - telepathy.CHANNEL_TYPE_FILE_TRANSFER + '.Filename', - telepathy.CHANNEL_TYPE_FILE_TRANSFER + '.Size', - telepathy.CHANNEL_TYPE_FILE_TRANSFER + '.ContentHash', - telepathy.CHANNEL_TYPE_FILE_TRANSFER + '.Description', - telepathy.CHANNEL_TYPE_FILE_TRANSFER + '.Date']) - ] - self.implement_channel_classes(telepathy.CHANNEL_TYPE_FILE_TRANSFER, self._get_ft_channel, classes) + self.set_requestable_channel_classes(protocol.requestable_channels) + + self.implement_channel_classes(telepathy.CHANNEL_TYPE_TEXT, self._get_text_channel) + self.implement_channel_classes(telepathy.CHANNEL_TYPE_CONTACT_LIST, self._get_list_channel) + self.implement_channel_classes(telepathy.CHANNEL_TYPE_STREAMED_MEDIA, self._get_media_channel) + self.implement_channel_classes(telepathy.CHANNEL_TYPE_FILE_TRANSFER, self._get_ft_channel) def _get_list_channel(self, props): _, surpress_handler, handle = self._get_type_requested_handle(props) diff --git a/butterfly/connection.py b/butterfly/connection.py index 40f94fc..779454a 100644 --- a/butterfly/connection.py +++ b/butterfly/connection.py @@ -51,36 +51,9 @@ class ButterflyConnection(telepathy.server.Connection, papyon.event.InviteEventInterface, papyon.event.OfflineMessagesEventInterface): - _secret_parameters = set([ - 'password', - 'http-proxy-password', - 'https-proxy-password' - ]) - _mandatory_parameters = { - 'account' : 's', - 'password' : 's' - } - _optional_parameters = { - 'server' : 's', - 'port' : 'q', - 'http-proxy-server' : 's', - 'http-proxy-port' : 'q', - 'http-proxy-username' : 's', - 'http-proxy-password' : 's', - 'https-proxy-server' : 's', - 'https-proxy-port' : 'q', - 'https-proxy-username' : 's', - 'https-proxy-password' : 's', - 'http-method' : 'b', - } - _parameter_defaults = { - 'server' : 'messenger.hotmail.com', - 'port' : 1863, - 'http-method' : False - } - def __init__(self, manager, parameters): - self.check_parameters(parameters) + def __init__(self, protocol, manager, parameters): + protocol.check_parameters(parameters) try: account = unicode(parameters['account']) @@ -109,10 +82,11 @@ class ButterflyConnection(telepathy.server.Connection, self._new_client(use_http=self._try_http) self._account = (parameters['account'].encode('utf-8'), parameters['password'].encode('utf-8')) - self._channel_manager = ButterflyChannelManager(self) + self._channel_manager = ButterflyChannelManager(self, protocol) # Call parent initializers - telepathy.server.Connection.__init__(self, 'msn', account, 'butterfly') + telepathy.server.Connection.__init__(self, 'msn', account, + 'butterfly', protocol) telepathy.server.ConnectionInterfaceRequests.__init__(self) ButterflyPresence.__init__(self) ButterflyAliasing.__init__(self) diff --git a/butterfly/connection_manager.py b/butterfly/connection_manager.py index dddf31b..d984d7e 100644 --- a/butterfly/connection_manager.py +++ b/butterfly/connection_manager.py @@ -21,7 +21,7 @@ import gobject import dbus import logging -from butterfly.connection import ButterflyConnection +from butterfly.protocol import ButterflyProtocol __all__ = ['ButterflyConnectionManager'] @@ -37,42 +37,11 @@ class ButterflyConnectionManager(telepathy.server.ConnectionManager): "Initializer" telepathy.server.ConnectionManager.__init__(self, 'butterfly') - self._protos['msn'] = ButterflyConnection + self._implement_protocol('msn', ButterflyProtocol) + self._shutdown = shutdown_func logger.info("Connection manager created") - def GetParameters(self, proto): - "Returns the mandatory and optional parameters for the given proto." - if proto not in self._protos: - raise telepathy.NotImplemented('unknown protocol %s' % proto) - - result = [] - connection_class = self._protos[proto] - secret_parameters = connection_class._secret_parameters - mandatory_parameters = connection_class._mandatory_parameters - optional_parameters = connection_class._optional_parameters - default_parameters = connection_class._parameter_defaults - - for parameter_name, parameter_type in mandatory_parameters.iteritems(): - flags = telepathy.CONN_MGR_PARAM_FLAG_REQUIRED - if parameter_name in secret_parameters: - flags |= telepathy.CONN_MGR_PARAM_FLAG_SECRET - param = (parameter_name, flags, parameter_type, '') - result.append(param) - - for parameter_name, parameter_type in optional_parameters.iteritems(): - flags = 0 - default = '' - if parameter_name in secret_parameters: - flags |= telepathy.CONN_MGR_PARAM_FLAG_SECRET - if parameter_name in default_parameters: - flags |= telepathy.CONN_MGR_PARAM_FLAG_HAS_DEFAULT - default = default_parameters[parameter_name] - param = (parameter_name, flags, parameter_type, default) - result.append(param) - - return result - def disconnected(self, conn): def shutdown(): if self._shutdown is not None and \ diff --git a/butterfly/presence.py b/butterfly/presence.py index dd1ecac..0ee1e69 100644 --- a/butterfly/presence.py +++ b/butterfly/presence.py @@ -93,9 +93,10 @@ class ButterflyPresence(telepathy.server.ConnectionInterfacePresence, papyon.event.ContactEventInterface.__init__(self, self.msn_client) papyon.event.ProfileEventInterface.__init__(self, self.msn_client) - dbus_interface = 'org.freedesktop.Telepathy.Connection.Interface.SimplePresence' - - self._implement_property_get(dbus_interface, {'Statuses' : self.get_statuses}) + self._implement_property_get( + telepathy.CONNECTION_INTERFACE_SIMPLE_PRESENCE, { + 'Statuses' : lambda: self._protocol.statuses + }) def GetStatuses(self): @@ -227,39 +228,6 @@ class ButterflyPresence(telepathy.server.ConnectionInterfacePresence, personal_message), signature='uss') return presences - def get_statuses(self): - # you get one of these for each status - # {name:(Type, May_Set_On_Self, Can_Have_Message} - return dbus.Dictionary({ - ButterflyPresenceMapping.ONLINE:( - telepathy.CONNECTION_PRESENCE_TYPE_AVAILABLE, - True, True), - ButterflyPresenceMapping.AWAY:( - telepathy.CONNECTION_PRESENCE_TYPE_AWAY, - True, True), - ButterflyPresenceMapping.BUSY:( - telepathy.CONNECTION_PRESENCE_TYPE_BUSY, - True, True), - ButterflyPresenceMapping.IDLE:( - telepathy.CONNECTION_PRESENCE_TYPE_EXTENDED_AWAY, - True, True), - ButterflyPresenceMapping.BRB:( - telepathy.CONNECTION_PRESENCE_TYPE_AWAY, - True, True), - ButterflyPresenceMapping.PHONE:( - telepathy.CONNECTION_PRESENCE_TYPE_AWAY, - True, True), - ButterflyPresenceMapping.LUNCH:( - telepathy.CONNECTION_PRESENCE_TYPE_EXTENDED_AWAY, - True, True), - ButterflyPresenceMapping.INVISIBLE:( - telepathy.CONNECTION_PRESENCE_TYPE_HIDDEN, - True, False), - ButterflyPresenceMapping.OFFLINE:( - telepathy.CONNECTION_PRESENCE_TYPE_OFFLINE, - True, False) - }, signature='s(ubb)') - # papyon.event.ContactEventInterface def on_contact_presence_changed(self, contact): handle = self.ensure_contact_handle(contact) diff --git a/butterfly/protocol.py b/butterfly/protocol.py new file mode 100644 index 0000000..2e3a204 --- /dev/null +++ b/butterfly/protocol.py @@ -0,0 +1,160 @@ +# telepathy-butterfly - an MSN connection manager for Telepathy +# +# Copyright (C) 2010 Collabora Ltd. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +import logging +import dbus + +import telepathy +import papyon +import papyon.event + +from butterfly.connection import ButterflyConnection +from butterfly.presence import ButterflyPresenceMapping + +__all__ = ['ButterflyProtocol'] + +logger = logging.getLogger('Butterfly.Protocol') + +class ButterflyProtocol(telepathy.server.Protocol, + telepathy.server.ProtocolInterfacePresence): + + _proto = "msn" + _vcard_field = "" + _english_name = "MSN" + _icon = "im-msn" + + _secret_parameters = set([ + 'password', + 'http-proxy-password', + 'https-proxy-password' + ]) + _mandatory_parameters = { + 'account' : 's', + 'password' : 's' + } + _optional_parameters = { + 'server' : 's', + 'port' : 'q', + 'http-proxy-server' : 's', + 'http-proxy-port' : 'q', + 'http-proxy-username' : 's', + 'http-proxy-password' : 's', + 'https-proxy-server' : 's', + 'https-proxy-port' : 'q', + 'https-proxy-username' : 's', + 'https-proxy-password' : 's', + 'http-method' : 'b', + } + _parameter_defaults = { + 'server' : u'messenger.hotmail.com', + 'port' : 1863, + 'http-method' : False + } + + _requestable_channel_classes = [ + ({telepathy.CHANNEL_INTERFACE + '.ChannelType': dbus.String(telepathy.CHANNEL_TYPE_TEXT), + telepathy.CHANNEL_INTERFACE + '.TargetHandleType': dbus.UInt32(telepathy.HANDLE_TYPE_CONTACT)}, + [telepathy.CHANNEL_INTERFACE + '.TargetHandle', + telepathy.CHANNEL_INTERFACE + '.TargetID']), + + ({telepathy.CHANNEL_INTERFACE + '.ChannelType': dbus.String(telepathy.CHANNEL_TYPE_TEXT), + telepathy.CHANNEL_INTERFACE + '.TargetHandleType': dbus.UInt32(telepathy.HANDLE_TYPE_NONE)}, + [telepathy.CHANNEL_INTERFACE_CONFERENCE + '.InitialChannels', + telepathy.CHANNEL_INTERFACE_CONFERENCE + '.InitialInviteeHandles', + telepathy.CHANNEL_INTERFACE_CONFERENCE + '.InitialInviteeIDs', + telepathy.CHANNEL_INTERFACE_CONFERENCE + '.InitialMessage', + telepathy.CHANNEL_INTERFACE_CONFERENCE + '.SupportsNonMerges']), + + ({telepathy.CHANNEL_INTERFACE + '.ChannelType': dbus.String(telepathy.CHANNEL_TYPE_CONTACT_LIST), + telepathy.CHANNEL_INTERFACE + '.TargetHandleType': dbus.UInt32(telepathy.HANDLE_TYPE_GROUP)}, + [telepathy.CHANNEL_INTERFACE + '.TargetHandle', + telepathy.CHANNEL_INTERFACE + '.TargetID']), + + ({telepathy.CHANNEL_INTERFACE + '.ChannelType': dbus.String(telepathy.CHANNEL_TYPE_CONTACT_LIST), + telepathy.CHANNEL_INTERFACE + '.TargetHandleType': dbus.UInt32(telepathy.HANDLE_TYPE_LIST)}, + [telepathy.CHANNEL_INTERFACE + '.TargetHandle', + telepathy.CHANNEL_INTERFACE + '.TargetID']), + + ({telepathy.CHANNEL_INTERFACE + '.ChannelType': dbus.String(telepathy.CHANNEL_TYPE_STREAMED_MEDIA), + telepathy.CHANNEL_INTERFACE + '.TargetHandleType': dbus.UInt32(telepathy.HANDLE_TYPE_CONTACT)}, + [telepathy.CHANNEL_INTERFACE + '.TargetHandle', + telepathy.CHANNEL_INTERFACE + '.TargetID', + telepathy.CHANNEL_TYPE_STREAMED_MEDIA + '.InitialAudio', + telepathy.CHANNEL_TYPE_STREAMED_MEDIA + '.InitialVideo']), + + ({telepathy.CHANNEL_INTERFACE + '.ChannelType': dbus.String(telepathy.CHANNEL_TYPE_FILE_TRANSFER), + telepathy.CHANNEL_INTERFACE + '.TargetHandleType': dbus.UInt32(telepathy.HANDLE_TYPE_CONTACT)}, + [telepathy.CHANNEL_INTERFACE + '.TargetHandle', + telepathy.CHANNEL_INTERFACE + '.TargetID', + telepathy.CHANNEL_TYPE_FILE_TRANSFER + '.ContentType', + telepathy.CHANNEL_TYPE_FILE_TRANSFER + '.Filename', + telepathy.CHANNEL_TYPE_FILE_TRANSFER + '.Size', + telepathy.CHANNEL_TYPE_FILE_TRANSFER + '.ContentHash', + telepathy.CHANNEL_TYPE_FILE_TRANSFER + '.Description', + telepathy.CHANNEL_TYPE_FILE_TRANSFER + '.Date']) + ] + + _supported_interfaces = [ + telepathy.CONNECTION_INTERFACE_ALIASING, + telepathy.CONNECTION_INTERFACE_AVATARS, + telepathy.CONNECTION_INTERFACE_CAPABILITIES, + telepathy.CONNECTION_INTERFACE_CONTACT_CAPABILITIES, + telepathy.CONNECTION_INTERFACE_PRESENCE, + telepathy.CONNECTION_INTERFACE_SIMPLE_PRESENCE, + telepathy.CONNECTION_INTERFACE_CONTACTS, + telepathy.CONNECTION_INTERFACE_REQUESTS, + telepathy.CONNECTION_INTERFACE_MAIL_NOTIFICATION + ] + + _statuses = { + ButterflyPresenceMapping.ONLINE:( + telepathy.CONNECTION_PRESENCE_TYPE_AVAILABLE, + True, True), + ButterflyPresenceMapping.AWAY:( + telepathy.CONNECTION_PRESENCE_TYPE_AWAY, + True, True), + ButterflyPresenceMapping.BUSY:( + telepathy.CONNECTION_PRESENCE_TYPE_BUSY, + True, True), + ButterflyPresenceMapping.IDLE:( + telepathy.CONNECTION_PRESENCE_TYPE_EXTENDED_AWAY, + True, True), + ButterflyPresenceMapping.BRB:( + telepathy.CONNECTION_PRESENCE_TYPE_AWAY, + True, True), + ButterflyPresenceMapping.PHONE:( + telepathy.CONNECTION_PRESENCE_TYPE_AWAY, + True, True), + ButterflyPresenceMapping.LUNCH:( + telepathy.CONNECTION_PRESENCE_TYPE_EXTENDED_AWAY, + True, True), + ButterflyPresenceMapping.INVISIBLE:( + telepathy.CONNECTION_PRESENCE_TYPE_HIDDEN, + True, False), + ButterflyPresenceMapping.OFFLINE:( + telepathy.CONNECTION_PRESENCE_TYPE_OFFLINE, + True, False) + } + + + def __init__(self, connection_manager): + telepathy.server.Protocol.__init__(self, connection_manager, 'msn') + telepathy.server.ProtocolInterfacePresence.__init__(self) + + def create_connection(self, connection_manager, parameters): + return ButterflyConnection(self, connection_manager, parameters) |