summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sunshine/channel/contact_list.py2
-rw-r--r--sunshine/channel/text.py117
-rw-r--r--sunshine/channel_manager.py32
-rw-r--r--sunshine/connection.py38
-rw-r--r--sunshine/util/config.py5
5 files changed, 24 insertions, 170 deletions
diff --git a/sunshine/channel/contact_list.py b/sunshine/channel/contact_list.py
index cc2b321..4d3f0f5 100644
--- a/sunshine/channel/contact_list.py
+++ b/sunshine/channel/contact_list.py
@@ -101,7 +101,7 @@ def SunshineContactListChannelFactory(connection, manager, handle, props):
props[telepathy.CHANNEL_INTERFACE + '.TargetHandleType'],
props[telepathy.CHANNEL_INTERFACE + '.TargetHandle'])
- if handle.get_name() == 'stored':
+ if handle.get_name() == 'subscribe':
channel_class = SunshineSubscribeListChannel
#hacky & tricky
# elif handle.get_name() == 'publish':
diff --git a/sunshine/channel/text.py b/sunshine/channel/text.py
index 2e5fb80..e74bf64 100644
--- a/sunshine/channel/text.py
+++ b/sunshine/channel/text.py
@@ -152,8 +152,6 @@ class SunshineRoomTextChannel(telepathy.server.ChannelTypeText, telepathy.server
# del self._pending_offline_messages[id]
# self._oim_box_ref().delete_messages(messages)
- # Rededefine ListPendingMessages to remove offline messages
- # from the oim box.
def ListPendingMessages(self, clear):
return telepathy.server.ChannelTypeText.ListPendingMessages(self, clear)
@@ -164,116 +162,5 @@ class SunshineRoomTextChannel(telepathy.server.ChannelTypeText, telepathy.server
# messages = self._pending_offline_messages.values()
# self._oim_box_ref().delete_messages(messages)
# return telepathy.server.ChannelTypeText.ListPendingMessages(self, clear)
-#
-# # papyon.event.ConversationEventInterface
-# def on_conversation_user_joined(self, contact):
-# handle = ButterflyHandleFactory(self._conn_ref(), 'contact',
-# contact.account, contact.network_id)
-# logger.info("User %s joined" % unicode(handle))
-# if handle not in self._members:
-# self.MembersChanged('', [handle], [], [], [],
-# handle, telepathy.CHANNEL_GROUP_CHANGE_REASON_INVITED)
-#
-# # papyon.event.ConversationEventInterface
-# def on_conversation_user_left(self, contact):
-# handle = ButterflyHandleFactory(self._conn_ref(), 'contact',
-# contact.account, contact.network_id)
-# logger.info("User %s left" % unicode(handle))
-# # There was only us and we are leaving, is it necessary?
-# if len(self._members) == 1:
-# self.ChatStateChanged(handle, telepathy.CHANNEL_CHAT_STATE_GONE)
-# elif len(self._members) == 2:
-# # Add the last user who left as the offline contact so we may still send
-# # him offlines messages and destroy the conversation
-# self._conversation.leave()
-# self._conversation = None
-# self._offline_handle = handle
-# self._offline_contact = contact
-# else:
-# #If there is only us and a offline contact don't remove him from
-# #the members since we still send him messages
-# self.MembersChanged('', [], [handle], [], [],
-# handle, telepathy.CHANNEL_GROUP_CHANGE_REASON_NONE)
-#
-# # papyon.event.ConversationEventInterface
-# def on_conversation_user_typing(self, contact):
-# handle = ButterflyHandleFactory(self._conn_ref(), 'contact',
-# contact.account, contact.network_id)
-# logger.info("User %s is typing" % unicode(handle))
-# self.ChatStateChanged(handle, telepathy.CHANNEL_CHAT_STATE_COMPOSING)
-#
-# # papyon.event.ConversationEventInterface
-# def on_conversation_message_received(self, sender, message):
-# id = self._recv_id
-# timestamp = int(time.time())
-# handle = ButterflyHandleFactory(self._conn_ref(), 'contact',
-# sender.account, sender.network_id)
-# type = telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL
-# message = message.content
-# logger.info("User %s sent a message" % unicode(handle))
-# self.Received(id, timestamp, handle, type, 0, message)
-# self._recv_id += 1
-#
-# # papyon.event.ConversationEventInterface
-# def on_conversation_nudge_received(self, sender):
-# id = self._recv_id
-# timestamp = int(time.time())
-# handle = ButterflyHandleFactory(self._conn_ref(), 'contact',
-# sender.account, sender.network_id)
-# type = telepathy.CHANNEL_TEXT_MESSAGE_TYPE_ACTION
-# text = unicode("sends you a nudge", "utf-8")
-# logger.info("User %s sent a nudge" % unicode(handle))
-# self.Received(id, timestamp, handle, type, 0, text)
-# self._recv_id += 1
-#
-# # papyon.event.ContactEventInterface
-# def on_contact_presence_changed(self, contact):
-# handle = ButterflyHandleFactory(self._conn_ref(), 'contact',
-# contact.account, contact.network_id)
-# # Recreate a conversation if our contact join
-# if self._offline_contact == contact and contact.presence != papyon.Presence.OFFLINE:
-# logger.info('Contact %s connected, inviting him to the text channel' % unicode(contact))
-# client = self._conn_ref().msn_client
-# self._conversation = papyon.Conversation(client, [contact])
-# papyon.event.ConversationEventInterface.__init__(self, self._conversation)
-# self._offline_contact = None
-# self._offline_handle = None
-# #FIXME : I really hope there is no race condition between the time
-# # the contact accept the invitation and the time we send him a message
-# # Can a user refuse an invitation? what happens then?
-#
-#
-# # Public API
-# def offline_message_received(self, message):
-# # @message a papyon.OfflineIM.OfflineMessage
-# id = self._recv_id
-# sender = message.sender
-# timestamp = time.mktime(message.date.timetuple())
-# text = message.text
-#
-# # Map the id to the offline message so we can remove it
-# # when acked by the client
-# self._pending_offline_messages[id] = message
-#
-# handle = ButterflyHandleFactory(self._conn_ref(), 'contact',
-# sender.account, sender.network_id)
-# type = telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL
-# logger.info("User %r sent a offline message" % handle)
-# self.Received(id, timestamp, handle, type, 0, text)
-#
-# self._recv_id += 1
-#
-# @async
-# def __add_initial_participants(self):
-# handles = []
-# handles.append(self._conn.GetSelfHandle())
-# if self._conversation:
-# for participant in self._conversation.participants:
-# handle = ButterflyHandleFactory(self._conn_ref(), 'contact',
-# participant.account, participant.network_id)
-# handles.append(handle)
-# else:
-# handles.append(self._offline_handle)
-#
-# self.MembersChanged('', handles, [], [], [],
-# 0, telepathy.CHANNEL_GROUP_CHANGE_REASON_NONE)
+
+
diff --git a/sunshine/channel_manager.py b/sunshine/channel_manager.py
index f067b6c..cce3321 100644
--- a/sunshine/channel_manager.py
+++ b/sunshine/channel_manager.py
@@ -125,25 +125,7 @@ class SunshineChannelManager(telepathy.server.ChannelManager):
# 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)
@@ -156,18 +138,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 8e491fc..c2888ec 100644
--- a/sunshine/connection.py
+++ b/sunshine/connection.py
@@ -24,6 +24,11 @@ import logging
import xml.etree.ElementTree as ET
+try:
+ import cStringIO as StringIO
+except ImportError:
+ import StringIO
+
from sunshine.util.config import SunshineConfig
from sunshine.lqsoft.pygadu.twisted_protocol import GaduClient
@@ -236,14 +241,6 @@ class SunshineConnection(telepathy.server.Connection,
self.getServerAdress(self._account[0])
def Disconnect(self):
- #if self.profile.contactsLoop:
- # self.profile.contactsLoop.stop()
- # self.profile.contactsLoop = None
- #if self._export_contacts == True:
- # if self.profile.exportLoop:
- # self.profile.exportLoop.stop()
- # self.profile.exportLoop = None
-
self.StatusChanged(telepathy.CONNECTION_STATUS_DISCONNECTED,
telepathy.CONNECTION_STATUS_REASON_REQUESTED)
self.profile.disconnect()
@@ -319,24 +316,25 @@ class SunshineConnection(telepathy.server.Connection,
_success(channel._object_path)
self.signal_new_channels([channel])
- def updateContactsFile(self):
- """Method that updates contact file when it changes and in loop every 5 seconds."""
- return self.configfile.make_contacts_file(self.profile.groups, self.profile.contacts)
-
+ @async
def exportContactsFile(self):
- logger.info("Exporting contacts.")
- print "self.profile.groups:", self.profile.groups
- print "self.profile.contacts:", self.profile.contacts
- contacts_xml = self.updateContactsFile()
- print "contacts_xml:", contacts_xml
+ contacts_xml = self.configfile.make_contacts_file(self.profile.groups, self.profile.contacts)
+ output = StringIO.StringIO()
+
+ contacts_xml.write(output, encoding="UTF-8")
+
+ contents = output.getvalue()
+ output.close()
- if len(contacts_xml) != 0:
- self.profile.exportContacts(contacts_xml)
+ if len(ET.tostring(contacts_xml.getroot())) != 0:
+ logger.info("Exporting contacts.")
+ print 'Output:', str(contents)
+ self.profile.exportContacts(str(contents))
@async
def makeTelepathyContactsChannel(self):
logger.debug("Method makeTelepathyContactsChannel called.")
- handle = SunshineHandleFactory(self, 'list', 'stored')
+ handle = SunshineHandleFactory(self, 'list', 'subscribe')
props = self._generate_props(telepathy.CHANNEL_TYPE_CONTACT_LIST,
handle, False)
self._channel_manager.channel_for_props(props, signal=True)
diff --git a/sunshine/util/config.py b/sunshine/util/config.py
index 3fa300e..3a209a3 100644
--- a/sunshine/util/config.py
+++ b/sunshine/util/config.py
@@ -47,10 +47,9 @@ class SunshineConfig(object):
ET.SubElement(contact_avatars_xml, "URL").text = ""
ET.SubElement(contact_xml, "FlagNormal").text = "true"
- #main_xml = ET.ElementTree(contactbook_xml)
+ main_xml = ET.ElementTree(contactbook_xml)
if self.contacts_len >= 0 and self.groups_len >= 0:
- #main_xml.write(self.path, encoding="UTF-8")
- return "%s\n%s" % ("<?xml version='1.0' encoding='UTF-8'?>", ET.tostring(contactbook_xml))
+ return main_xml
def get_contacts_count(self):
return self.contacts_count