summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonny Lamb <jonny.lamb@collabora.co.uk>2010-11-17 14:34:38 +0000
committerJonny Lamb <jonny.lamb@collabora.co.uk>2010-11-17 14:34:38 +0000
commit6222bb49cf0aae509e23a5b020291e3ffc3dd151 (patch)
tree29721e372ea292cc3895bba2175692063fc9d1a4
parent092e6b471dd58aa252ac43db960e2a8720b7af1c (diff)
client-types: initial draftclient-types
Signed-off-by: Jonny Lamb <jonny.lamb@collabora.co.uk>
-rw-r--r--butterfly/Connection_Interface_Client_Types.py126
-rw-r--r--butterfly/Makefile.am4
-rw-r--r--butterfly/client_types.py75
-rw-r--r--butterfly/connection.py3
-rw-r--r--butterfly/contacts.py9
5 files changed, 214 insertions, 3 deletions
diff --git a/butterfly/Connection_Interface_Client_Types.py b/butterfly/Connection_Interface_Client_Types.py
new file mode 100644
index 0000000..88bcfa4
--- /dev/null
+++ b/butterfly/Connection_Interface_Client_Types.py
@@ -0,0 +1,126 @@
+# -*- coding: utf-8 -*-
+# Generated from the Telepathy spec
+"""Copyright (C) 2010 Collabora Ltd.
+
+ 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.1 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+"""
+
+import dbus.service
+
+
+class ConnectionInterfaceClientTypes(dbus.service.Interface):
+ """\
+ An interface on connections to support protocols which allows users to
+ subscribe to the client types of their contacts.
+
+ One can connect to instant messaging networks on a huge variety of
+ devices, from PCs, to phones to consoles. It can be useful for users
+ to know what kind of device a contact is using so that he or she
+ can decide not to send that big file or start a video chat. This
+ interface exposes exactly this information for clients to display.
+
+ The client types are represented in strings, using the values
+
+ documented by the XMPP registrar with some additional types
+ added for other protocols. A contact can set one or more client types
+ so this interface returns a list of strings to denote client types
+ for a contact. The well-known client types to be used are:
+
+
+ bot
+ console (minimal non-GUI client used on dumb terminals or
+ text-only screens, not a games console)
+ handheld
+ pc
+ phone
+ web
+ sms (the client is not actually an instant messaging client
+ but all messages sent to this contact will be delivered as SMSs)
+ game (a gaming device)
+
+
+ If the empty list is given as the client types, this means that
+ details about the contact's client types are unknown. If there are
+ multiple resources of a contact online at one point in time, the
+ client types of the most available resource will be returned. In
+ other words, the client types are the types of the client whose
+ SimplePresence we see. For example, if a contact has two
+ resources:
+
+
+ one his phone, with presence "available", and
+ one his pc, with presence "busy",
+
+
+ then the methods in this interface will return an array (with
+ one element: "phone") as the client types as that is the more
+ available resource. If some time later his phone's presence
+ moves to "away", then the
+ ClientTypesUpdated signal will
+ notify that his client type have changed from "phone" to "pc",
+ because "busy" is a more available presence than "away".
+
+ """
+
+ def __init__(self):
+ self._interfaces.add('org.freedesktop.Telepathy.Connection.Interface.ClientTypes.DRAFT')
+
+ @dbus.service.method('org.freedesktop.Telepathy.Connection.Interface.ClientTypes.DRAFT', in_signature='au', out_signature='a{uas}')
+ def GetClientTypes(self, Contacts):
+ """
+ Return the client types of the given contacts, if they are
+ already known. If any of the given contacts' client types are
+ not known, request their current client types, but return
+ immediately without waiting for a reply; if a reply with a
+ non-empty client type array is later received for those
+ contacts, the
+ ClientTypesUpdated signal will
+ be emitted for them.
+
+
+ This method is appropriate for "lazy" client type finding, for instance
+ displaying the client types (if available) of everyone in your contact
+ list.
+
+
+ """
+ raise NotImplementedError
+
+ @dbus.service.method('org.freedesktop.Telepathy.Connection.Interface.ClientTypes.DRAFT', in_signature='u', out_signature='as')
+ def RequestClientTypes(self, Contact):
+ """
+ Return the current client types of the given contact. If necessary, make
+ a request to the server for up-to-date information, and wait for a
+ reply.
+
+
+ This method is appropriate for use in a "Contact Information..."
+ dialog; it can be used to show progress information (while waiting
+ for the method to return), and can distinguish between various error
+ conditions.
+
+
+ """
+ raise NotImplementedError
+
+ @dbus.service.signal('org.freedesktop.Telepathy.Connection.Interface.ClientTypes.DRAFT', signature='uas')
+ def ClientTypesUpdated(self, Contact, Client_Types):
+ """
+ Emitted when a contact's client types change or become known.
+
+ """
+ pass
+ \ No newline at end of file
diff --git a/butterfly/Makefile.am b/butterfly/Makefile.am
index b2bbbb3..80e5215 100644
--- a/butterfly/Makefile.am
+++ b/butterfly/Makefile.am
@@ -6,6 +6,7 @@ butterfly_PYTHON = \
capabilities.py \
Channel_Interface_Conference.py \
Connection_Interface_Mail_Notification.py \
+ Connection_Interface_Client_Types.py \
connection.py \
debug.py \
__init__.py \
@@ -15,4 +16,5 @@ butterfly_PYTHON = \
connection_manager.py \
contacts.py \
handle.py \
- mail_notification.py
+ mail_notification.py \
+ client_types
diff --git a/butterfly/client_types.py b/butterfly/client_types.py
new file mode 100644
index 0000000..a22d397
--- /dev/null
+++ b/butterfly/client_types.py
@@ -0,0 +1,75 @@
+# 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 dbus
+import papyon
+import telepathy
+
+import logging
+
+from butterfly.Connection_Interface_Client_Types import ConnectionInterfaceClientTypes
+
+__all__ = ['ButterflyClientTypes']
+
+logger = logging.getLogger('Butterfly.ClientTypes')
+
+CONN_IFACE_CLIENT_TYPES = \
+ 'org.freedesktop.Telepathy.Connection.Interface.ClientTypes.DRAFT'
+
+class ButterflyClientTypes(
+ telepathy.server.DBusProperties,
+ ConnectionInterfaceClientTypes):
+
+ def __init__(self):
+ telepathy.server.DBusProperties.__init__(self)
+ ConnectionInterfaceClientTypes.__init__(self)
+
+ def _get_type(self, contact):
+ caps = contact.client_capabilities
+
+ if caps.is_bot:
+ return "bot"
+ elif caps.is_media_center:
+ return "pc" # this might need reviewing later
+ elif caps.is_mobile_device:
+ return "phone"
+ elif caps.is_web_client:
+ return "web"
+ elif caps.is_msn_mobile:
+ return "phone"
+ elif caps.is_msn_direct_device:
+ return "console"
+
+ # there's no "I'm a PC", so let's just fallback on this.
+ return "pc"
+
+ def GetClientTypes(self, handles):
+ for h in handles:
+ self.check_handle(telepathy.HANDLE_TYPE_CONTACT, h)
+
+ out = dbus.Dictionary({}, signature='uas')
+
+ for h in handles:
+ handle = self.handle(telepathy.HANDLE_TYPE_CONTACT, h)
+ contact = handle.contact
+
+ out[dbus.UInt32(h)] = dbus.Array([self._get_type(contact)], signature='s')
+
+ return out
+
+
diff --git a/butterfly/connection.py b/butterfly/connection.py
index 044790f..2c1adbf 100644
--- a/butterfly/connection.py
+++ b/butterfly/connection.py
@@ -33,6 +33,7 @@ from butterfly.handle import ButterflyHandleFactory, network_to_extension
from butterfly.contacts import ButterflyContacts
from butterfly.channel_manager import ButterflyChannelManager
from butterfly.mail_notification import ButterflyMailNotification
+from butterfly.client_types import ButterflyClientTypes
__all__ = ['ButterflyConnection']
@@ -47,6 +48,7 @@ class ButterflyConnection(telepathy.server.Connection,
ButterflyCapabilities,
ButterflyContacts,
ButterflyMailNotification,
+ ButterflyClientTypes,
papyon.event.ClientEventInterface,
papyon.event.InviteEventInterface,
papyon.event.OfflineMessagesEventInterface):
@@ -118,6 +120,7 @@ class ButterflyConnection(telepathy.server.Connection,
ButterflyCapabilities.__init__(self)
ButterflyContacts.__init__(self)
ButterflyMailNotification.__init__(self)
+ ButterflyClientTypes.__init__(self)
self.set_self_handle(ButterflyHandleFactory(self, 'self'))
diff --git a/butterfly/contacts.py b/butterfly/contacts.py
index 57df7f8..18808f2 100644
--- a/butterfly/contacts.py
+++ b/butterfly/contacts.py
@@ -25,6 +25,8 @@ import telepathy.errors
import papyon
import dbus
+from butterfly.client_types import CONN_IFACE_CLIENT_TYPES
+
__all__ = ['ButterflyContacts']
logger = logging.getLogger('Butterfly.Contacts')
@@ -40,7 +42,8 @@ class ButterflyContacts(
telepathy.CONNECTION_INTERFACE_ALIASING : 'alias',
telepathy.CONNECTION_INTERFACE_AVATARS : 'token',
telepathy.CONNECTION_INTERFACE_CAPABILITIES : 'caps',
- telepathy.CONNECTION_INTERFACE_CONTACT_CAPABILITIES : 'capabilities'
+ telepathy.CONNECTION_INTERFACE_CONTACT_CAPABILITIES : 'capabilities',
+ CONN_IFACE_CLIENT_TYPES: 'client-types'
}
def __init__(self):
@@ -82,7 +85,9 @@ class ButterflyContacts(
telepathy.CONNECTION_INTERFACE_CAPABILITIES :
lambda x: self.GetCapabilities(x).items(),
telepathy.CONNECTION_INTERFACE_CONTACT_CAPABILITIES :
- lambda x: self.GetContactCapabilities(x).items()
+ lambda x: self.GetContactCapabilities(x).items(),
+ CONN_IFACE_CLIENT_TYPES:
+ lambda x: self.GetClientTypes(x).items(),
}
#Hold handles if needed