# Path: tphangups/protocol.py
# class HangupsProtocol(telepathy.server.Protocol,
#                       telepathy.server.ProtocolInterfacePresence):
#     _proto_ = "hangouts"
#     _englishName = "Google Hangouts"
#     _vcard_field = ""
#     _icon = "" #FIXME
# 
# 
#     _mandatory_parameters = {"account" : "s"}
# 
#     _supported_interfaces = [
#             telepathy.CONNECTION_INTERFACE_ALIASING,
#             telepathy.CONNECTION_INTERFACE_AVATARS,
#             telepathy.CONNECTION_INTERFACE_SIMPLE_PRESENCE,
#             telepathy.CONNECTION_INTERFACE_CONTACTS
#         ]
# 
#     _statuses = {
#             "online":(
#                 telepathy.CONNECTION_PRESENCE_TYPE_AVAILABLE,
#                 True, True),
#             "offline":(
#                 telepathy.CONNECTION_PRESENCE_TYPE_OFFLINE,
#                 True, False)
#             }
# 
#     #claim to support 1-1 text messages
#     _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'])]
# 
# 
#     def __init__(self, connection_manager):
#         print ("Making protocol")
#         telepathy.server.Protocol.__init__(self, connection_manager, 'hangouts')
#         telepathy.server.ProtocolInterfacePresence.__init__(self)
# 
#     def create_connection(self, connection_manager, parameters):
#         return HangupsConnection(self, connection_manager, parameters)
# 
#     def NormalizeContact(self, contactId):
#         return "BLAH"+contactId
# 
# Path: tphangups/text_channel.py
# class HangupsTextChannel(telepathy.server.ChannelTypeText,
#         telepathy.server.ChannelInterfaceChatState):
# 
#     #TODO probably pass the conversation object from Hangups client
#     def __init__(self, conn, manager, props, object_path=None):
#         telepathy.server.ChannelTypeText.__init__(self, conn, manager, props,
#                     object_path=object_path)
# 
#         self._implement_property_get(telepathy.CHANNEL_INTERFACE_MESSAGES, {
#             'SupportedContentTypes': lambda: ["text/plain"] ,
#             'MessagePartSupportFlags': lambda: 0,
#             'DeliveryReportingSupport': lambda: telepathy.DELIVERY_REPORTING_SUPPORT_FLAG_RECEIVE_FAILURES,
#             'PendingMessages': lambda: dbus.Array(self._pending_messages.values(), signature='aa{sv}')
#             })
# 
#         self._add_immutables({
#             'SupportedContentTypes': telepathy.CHANNEL_INTERFACE_MESSAGES,
#             'MessagePartSupportFlags': telepathy.CHANNEL_INTERFACE_MESSAGES,
#             'DeliveryReportingSupport': telepathy.CHANNEL_INTERFACE_MESSAGES,
#             })
# 
#     @dbus.service.method(telepathy.CHANNEL_TYPE_TEXT, in_signature='us', out_signature='',
#                          async_callbacks=('_success', '_error'))
#     def Send(self, message_type, text, _success, _error):
#         print ("NEW MESSAGE " + text)
#         self.Received(15, 34234234, 2, 0 , 0, "Hello!")


import telepathy
from .protocol import HangupsProtocol
from .text_channel import HangupsTextChannel


class HangupsConnectionManager(telepathy.server.ConnectionManager):
    def __init__(self):
        telepathy.server.ConnectionManager.__init__(self, 'hangups')

# Path: tphangups/protocol.py
# class HangupsProtocol(telepathy.server.Protocol,
#                       telepathy.server.ProtocolInterfacePresence):
#     _proto_ = "hangouts"
#     _englishName = "Google Hangouts"
#     _vcard_field = ""
#     _icon = "" #FIXME
# 
# 
#     _mandatory_parameters = {"account" : "s"}
# 
#     _supported_interfaces = [
#             telepathy.CONNECTION_INTERFACE_ALIASING,
#             telepathy.CONNECTION_INTERFACE_AVATARS,
#             telepathy.CONNECTION_INTERFACE_SIMPLE_PRESENCE,
#             telepathy.CONNECTION_INTERFACE_CONTACTS
#         ]
# 
#     _statuses = {
#             "online":(
#                 telepathy.CONNECTION_PRESENCE_TYPE_AVAILABLE,
#                 True, True),
#             "offline":(
#                 telepathy.CONNECTION_PRESENCE_TYPE_OFFLINE,
#                 True, False)
#             }
# 
#     #claim to support 1-1 text messages
#     _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'])]
# 
# 
#     def __init__(self, connection_manager):
#         print ("Making protocol")
#         telepathy.server.Protocol.__init__(self, connection_manager, 'hangouts')
#         telepathy.server.ProtocolInterfacePresence.__init__(self)
# 
#     def create_connection(self, connection_manager, parameters):
#         return HangupsConnection(self, connection_manager, parameters)
# 
#     def NormalizeContact(self, contactId):
#         return "BLAH"+contactId
# 
# Path: tphangups/text_channel.py
# class HangupsTextChannel(telepathy.server.ChannelTypeText,
#         telepathy.server.ChannelInterfaceChatState):
# 
#     #TODO probably pass the conversation object from Hangups client
#     def __init__(self, conn, manager, props, object_path=None):
#         telepathy.server.ChannelTypeText.__init__(self, conn, manager, props,
#                     object_path=object_path)
# 
#         self._implement_property_get(telepathy.CHANNEL_INTERFACE_MESSAGES, {
#             'SupportedContentTypes': lambda: ["text/plain"] ,
#             'MessagePartSupportFlags': lambda: 0,
#             'DeliveryReportingSupport': lambda: telepathy.DELIVERY_REPORTING_SUPPORT_FLAG_RECEIVE_FAILURES,
#             'PendingMessages': lambda: dbus.Array(self._pending_messages.values(), signature='aa{sv}')
#             })
# 
#         self._add_immutables({
#             'SupportedContentTypes': telepathy.CHANNEL_INTERFACE_MESSAGES,
#             'MessagePartSupportFlags': telepathy.CHANNEL_INTERFACE_MESSAGES,
#             'DeliveryReportingSupport': telepathy.CHANNEL_INTERFACE_MESSAGES,
#             })
# 
#     @dbus.service.method(telepathy.CHANNEL_TYPE_TEXT, in_signature='us', out_signature='',
#                          async_callbacks=('_success', '_error'))
#     def Send(self, message_type, text, _success, _error):
#         print ("NEW MESSAGE " + text)
#         self.Received(15, 34234234, 2, 0 , 0, "Hello!")


# Path: tphangups/connection_manager.py
import telepathy
from .protocol import HangupsProtocol
from .text_channel import HangupsTextChannel



class HangupsConnectionManager(telepathy.server.ConnectionManager):
    def __init__(self):
        telepathy.server.ConnectionManager.__init__(self, 'hangups')

        self._implement_protocol('hangouts', HangupsProtocol) #protocol is still hangouts, _NOT_ hangups