summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKrzysztof Klinikowski <kkszysiu@gmail.com>2011-05-07 19:00:14 +0200
committerKrzysztof Klinikowski <kkszysiu@gmail.com>2011-05-07 19:00:14 +0200
commit32d13b51d7839ec38dc8d2b5676ed9864463bb29 (patch)
tree7d1a031ff045a1e1036ebd4a65ea79755689b3f3
parent1f610ce51af99a3cf691e0b8b7459896f032d49e (diff)
Protocol object implemented.
-rw-r--r--sunshine/Makefile.am3
-rw-r--r--sunshine/channel_manager.py74
-rw-r--r--sunshine/connection.py30
-rw-r--r--sunshine/connection_manager.py38
-rw-r--r--sunshine/presence.py45
-rw-r--r--sunshine/protocol.py137
6 files changed, 157 insertions, 170 deletions
diff --git a/sunshine/Makefile.am b/sunshine/Makefile.am
index fe216a4..180617f 100644
--- a/sunshine/Makefile.am
+++ b/sunshine/Makefile.am
@@ -13,4 +13,5 @@ sunshine_PYTHON = aliasing.py \
debug.py \
handle.py \
__init__.py \
- presence.py
+ presence.py \
+ protocol.py
diff --git a/sunshine/channel_manager.py b/sunshine/channel_manager.py
index 6c65b2d..229cedc 100644
--- a/sunshine/channel_manager.py
+++ b/sunshine/channel_manager.py
@@ -80,64 +80,16 @@ class SunshineChannelManager(telepathy.server.ChannelManager):
__text_channel_id = 1
__media_channel_id = 1
- def __init__(self, connection):
+ def __init__(self, connection, protocol):
telepathy.server.ChannelManager.__init__(self, connection)
+ 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)
- 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_ROOM)},
- [telepathy.CHANNEL_INTERFACE + '.TargetHandle',
- telepathy.CHANNEL_INTERFACE + '.TargetID']),
- ]
- 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)
-#
-# fixed = {telepathy.CHANNEL_INTERFACE + '.ChannelType': telepathy.CHANNEL_TYPE_TEXT,
-# telepathy.CHANNEL_INTERFACE + '.TargetHandleType': dbus.UInt32(telepathy.HANDLE_TYPE_CONTACT)}
-# self._implement_channel_class(telepathy.CHANNEL_TYPE_TEXT,
-# self._get_text_channel, fixed, [])
-#
-# fixed = {telepathy.CHANNEL_INTERFACE + '.ChannelType': telepathy.CHANNEL_TYPE_TEXT,
-# telepathy.CHANNEL_INTERFACE + '.TargetHandleType': dbus.UInt32(telepathy.HANDLE_TYPE_ROOM)}
-# self._implement_channel_class(telepathy.CHANNEL_TYPE_TEXT,
-# self._get_text_channel, fixed, [])
-#
-# fixed = {telepathy.CHANNEL_INTERFACE + '.ChannelType': telepathy.CHANNEL_TYPE_CONTACT_LIST}
-# self._implement_channel_class(telepathy.CHANNEL_TYPE_CONTACT_LIST,
-# self._get_list_channel, fixed, [])
-
-# fixed = {telepathy.CHANNEL_INTERFACE + '.ChannelType': telepathy.CHANNEL_TYPE_STREAMED_MEDIA,
-# telepathy.CHANNEL_INTERFACE + '.TargetHandleType': dbus.UInt32(telepathy.HANDLE_TYPE_CONTACT)}
-# self._implement_channel_class(telepathy.CHANNEL_TYPE_STREAMED_MEDIA,
-# self._get_media_channel, fixed, [telepathy.CHANNEL_INTERFACE + '.TargetHandle'])
def _get_list_channel(self, props):
_, surpress_handler, handle = self._get_type_requested_handle(props)
@@ -150,18 +102,6 @@ class SunshineChannelManager(telepathy.server.ChannelManager):
channel = SunshineContactListChannelFactory(self._conn,
self, handle, props)
return channel
-
-# def _get_list_channel(self, props):
-# _, surpress_handler, handle = self._get_type_requested_handle(props)
-#
-# if handle.get_type() == telepathy.HANDLE_TYPE_GROUP:
-# channel = SunshineGroupChannel(self._conn, self, props)
-# logger.debug('New group channel')
-# else:
-# channel = SunshineContactListChannelFactory(self._conn,
-# self, handle, props)
-# logger.debug('New contact list channel: %s' % (handle.name))
-# return channel
def _get_text_channel(self, props, conversation=None):
_, surpress_handler, handle = self._get_type_requested_handle(props)
diff --git a/sunshine/connection.py b/sunshine/connection.py
index 6657572..79dc3ac 100644
--- a/sunshine/connection.py
+++ b/sunshine/connection.py
@@ -128,30 +128,8 @@ class SunshineConnection(telepathy.server.Connection,
SunshineContacts
):
- _secret_parameters = set([
- 'password'
- ])
- _mandatory_parameters = {
- 'account' : 's',
- 'password' : 's'
- }
- _optional_parameters = {
- 'server' : 's',
- 'port' : 'q',
- 'export-contacts' : 'b',
- 'use-ssl' : 'b',
- 'use-specified-server' : 'b'
- }
- _parameter_defaults = {
- 'server' : '91.197.13.67',
- 'port' : 8074,
- 'export-contacts' : False,
- 'use-ssl' : True,
- 'use-specified-server' : 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'])
@@ -202,7 +180,7 @@ class SunshineConnection(telepathy.server.Connection,
if check_requirements() == True:
self.ggapi = GG_Oauth(self.profile.uin, parameters['password'])
- self._channel_manager = SunshineChannelManager(self)
+ self._channel_manager = SunshineChannelManager(self, protocol)
self._recv_id = 0
self._conf_id = 0
@@ -211,7 +189,7 @@ class SunshineConnection(telepathy.server.Connection,
self.profile.contactsLoop = None
# Call parent initializers
- telepathy.server.Connection.__init__(self, 'gadugadu', account, 'sunshine')
+ telepathy.server.Connection.__init__(self, 'gadugadu', account, 'sunshine', protocol)
telepathy.server.ConnectionInterfaceRequests.__init__(self)
SunshinePresence.__init__(self)
SunshineAvatars.__init__(self)
diff --git a/sunshine/connection_manager.py b/sunshine/connection_manager.py
index 1c66aa3..d4eadc0 100644
--- a/sunshine/connection_manager.py
+++ b/sunshine/connection_manager.py
@@ -22,7 +22,7 @@ import gobject
import dbus
import logging
-from sunshine.connection import SunshineConnection
+from sunshine.protocol import SunshineProtocol
__all__ = ['SunshineConnectionManager']
@@ -38,41 +38,9 @@ class SunshineConnectionManager(telepathy.server.ConnectionManager):
"Initializer"
telepathy.server.ConnectionManager.__init__(self, 'sunshine')
- self._protos['gadugadu'] = SunshineConnection
+ self._implement_protocol('gadugadu', SunshineProtocol)
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
+ logger.info("Connection manager created")
def disconnected(self, conn):
def shutdown():
diff --git a/sunshine/presence.py b/sunshine/presence.py
index 860f1ca..3d47267 100644
--- a/sunshine/presence.py
+++ b/sunshine/presence.py
@@ -64,23 +64,6 @@ class SunshinePresenceMapping(object):
}
from_gg_to_tp = {
- # 'NOT_AVAILABLE': 0x0001,
- # 'NOT_AVAILABLE_DESC': 0x0015,
- # 'FFC': 0x0017,
- # 'FFC_DESC': 0x0018,
- # 'AVAILABLE': 0x0002,
- # 'AVAILABLE_DESC': 0x0004,
- # 'BUSY': 0x0003,
- # 'BUSY_DESC': 0x0005,
- # 'DND': 0x0021,
- # 'DND_DESC': 0x0022,
- # 'HIDDEN': 0x0014,
- # 'HIDDEN_DESC': 0x0016,
- # 'DND': 0x0021,
- # 'BLOCKED': 0x0006,
- # 'MASK_FRIEND': 0x8000,
- # 'MASK_GFX': 0x0100,
- # 'MASK_STATUS': 0x4000,
0: OFFLINE,
0x0001: OFFLINE,
0x4015: OFFLINE,
@@ -121,12 +104,13 @@ class SunshinePresence(telepathy.server.ConnectionInterfaceSimplePresence):
def __init__(self):
telepathy.server.ConnectionInterfaceSimplePresence.__init__(self)
- dbus_interface = 'org.freedesktop.Telepathy.Connection.Interface.SimplePresence'
-
self.presence = None
self.personal_message = None
- self._implement_property_get(dbus_interface, {'Statuses' : self.get_statuses})
+ self._implement_property_get(
+ telepathy.CONNECTION_INTERFACE_SIMPLE_PRESENCE, {
+ 'Statuses' : lambda: self._protocol.statuses
+ })
# SimplePresence
@@ -181,27 +165,6 @@ class SunshinePresence(telepathy.server.ConnectionInterfaceSimplePresence):
presences[handle] = dbus.Struct((presence_type, presence, 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({
- SunshinePresenceMapping.ONLINE:(
- telepathy.CONNECTION_PRESENCE_TYPE_AVAILABLE,
- True, True),
- SunshinePresenceMapping.AWAY:(
- telepathy.CONNECTION_PRESENCE_TYPE_AWAY,
- True, True),
- SunshinePresenceMapping.DND:(
- telepathy.CONNECTION_PRESENCE_TYPE_BUSY,
- True, True),
- SunshinePresenceMapping.INVISIBLE:(
- telepathy.CONNECTION_PRESENCE_TYPE_HIDDEN,
- True, True),
- SunshinePresenceMapping.OFFLINE:(
- telepathy.CONNECTION_PRESENCE_TYPE_OFFLINE,
- True, True)
- }, signature='s(ubb)')
-
@async
def _presence_changed(self, handle, presence, personal_message):
try:
diff --git a/sunshine/protocol.py b/sunshine/protocol.py
new file mode 100644
index 0000000..ce7f399
--- /dev/null
+++ b/sunshine/protocol.py
@@ -0,0 +1,137 @@
+# telepathy-sunshine is the GaduGadu connection manager for Telepathy
+#
+# Copyright (C) 2011 Krzysztof Klinikowski <kkszysiu@gmail.com>
+#
+# 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
+
+from sunshine.connection import SunshineConnection
+from sunshine.presence import SunshinePresenceMapping
+
+__all__ = ['SunshineProtocol']
+
+logger = logging.getLogger('Sunshine.Protocol')
+
+class SunshineProtocol(telepathy.server.Protocol,
+ telepathy.server.ProtocolInterfacePresence):
+
+ _proto = "gadugadu"
+ _vcard_field = ""
+ _english_name = "Gadu-Gadu"
+ _icon = "im-gadu"
+
+ _secret_parameters = set([
+ 'password'
+ ])
+ _mandatory_parameters = {
+ 'account' : 's',
+ 'password' : 's'
+ }
+ _optional_parameters = {
+ 'server' : 's',
+ 'port' : 'q',
+ 'export-contacts' : 'b',
+ 'use-ssl' : 'b',
+ 'use-specified-server' : 'b'
+ }
+ _parameter_defaults = {
+ 'server' : '91.197.13.67',
+ 'port' : 8074,
+ 'export-contacts' : False,
+ 'use-ssl' : True,
+ 'use-specified-server' : 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': telepathy.CHANNEL_TYPE_TEXT,
+ telepathy.CHANNEL_INTERFACE + '.TargetHandleType': dbus.UInt32(telepathy.HANDLE_TYPE_ROOM)},
+ [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_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_CONTACT_INFO
+ ]
+
+ _statuses = {
+ SunshinePresenceMapping.ONLINE:(
+ telepathy.CONNECTION_PRESENCE_TYPE_AVAILABLE,
+ True, True),
+ SunshinePresenceMapping.AWAY:(
+ telepathy.CONNECTION_PRESENCE_TYPE_AWAY,
+ True, True),
+ SunshinePresenceMapping.DND:(
+ telepathy.CONNECTION_PRESENCE_TYPE_BUSY,
+ True, True),
+ SunshinePresenceMapping.INVISIBLE:(
+ telepathy.CONNECTION_PRESENCE_TYPE_HIDDEN,
+ True, True),
+ SunshinePresenceMapping.OFFLINE:(
+ telepathy.CONNECTION_PRESENCE_TYPE_OFFLINE,
+ True, True)
+ }
+
+
+ def __init__(self, connection_manager):
+ telepathy.server.Protocol.__init__(self, connection_manager, 'gadugadu')
+ telepathy.server.ProtocolInterfacePresence.__init__(self)
+
+ def create_connection(self, connection_manager, parameters):
+ return SunshineConnection(self, connection_manager, parameters)