summaryrefslogtreecommitdiff
path: root/sunshine
diff options
context:
space:
mode:
authorKrzysztof <kkszysiu@gmail.com>2011-03-27 17:03:36 +0200
committerKrzysztof <kkszysiu@gmail.com>2011-03-27 17:03:36 +0200
commit4ccfa17cc8f843aa55b9cbadc00dc2f68d3cf01d (patch)
tree130a52372169450e5f5500de785195baeae8d1d5 /sunshine
parent16ddc67ea21da549fc1f386d27b747f74c5eaff0 (diff)
Some fixes.
Diffstat (limited to 'sunshine')
-rw-r--r--sunshine/channel/contact_list.py92
-rw-r--r--sunshine/channel/group.py2
-rw-r--r--sunshine/channel/text.py4
3 files changed, 79 insertions, 19 deletions
diff --git a/sunshine/channel/contact_list.py b/sunshine/channel/contact_list.py
index 0fbf4f3..154966e 100644
--- a/sunshine/channel/contact_list.py
+++ b/sunshine/channel/contact_list.py
@@ -101,22 +101,21 @@ def SunshineContactListChannelFactory(connection, manager, handle, props):
props[telepathy.CHANNEL_INTERFACE + '.TargetHandleType'],
props[telepathy.CHANNEL_INTERFACE + '.TargetHandle'])
- if handle.get_name() == 'subscribe':
+ if handle.get_name() == 'stored':
+ raise telepathy.errors.NotImplemented
+ elif handle.get_name() == 'subscribe':
channel_class = SunshineSubscribeListChannel
- #hacky & tricky
-# elif handle.get_name() == 'publish':
-# channel_class = SunshineSubscribeListChannel
-
-# elif handle.get_name() == 'publish':
-# channel_class = ButterflyPublishListChannel
-# elif handle.get_name() == 'hide':
-# channel_class = ButterflyHideListChannel
-# elif handle.get_name() == 'allow':
-# channel_class = ButterflyAllowListChannel
-# elif handle.get_name() == 'deny':
-# channel_class = ButterflyDenyListChannel
+ elif handle.get_name() == 'publish':
+ raise telepathy.errors.NotImplemented
+ elif handle.get_name() == 'hide':
+ raise telepathy.errors.NotImplemented
+ elif handle.get_name() == 'allow':
+ raise telepathy.errors.NotImplemented
+ elif handle.get_name() == 'deny':
+ raise telepathy.errors.NotImplemented
else:
- raise TypeError("Unknown list type : " + handle.get_name())
+ logger.error("Unknown list type : " + handle.get_name())
+ raise telepathy.errors.InvalidHandle
return channel_class(connection, manager, props)
@@ -128,7 +127,7 @@ class SunshineListChannel(
def __init__(self, connection, manager, props, object_path=None):
self._conn_ref = weakref.ref(connection)
- telepathy.server.ChannelTypeContactList.__init__(self, connection, manager, props, object_path=None)
+ telepathy.server.ChannelTypeContactList.__init__(self, connection, manager, props, object_path=object_path)
SunshineChannel.__init__(self, connection, props)
telepathy.server.ChannelInterfaceGroup.__init__(self)
self._populate(connection)
@@ -210,13 +209,19 @@ class SunshineSubscribeListChannel(SunshineListChannel):
supposed to receive presence notification."""
def __init__(self, connection, manager, props):
- SunshineListChannel.__init__(self, connection, manager, props)
+ SunshineListChannel.__init__(self, connection, manager, props,
+ object_path='RosterChannel/List/subscribe')
self.GroupFlagsChanged(telepathy.CHANNEL_GROUP_FLAG_CAN_ADD |
telepathy.CHANNEL_GROUP_FLAG_CAN_REMOVE, 0)
def AddMembers(self, contacts, message):
logger.info("Subscribe - AddMembers called")
for h in contacts:
+ self._add(h, message)
+
+
+ """
+ for h in contacts:
handle = self._conn.handle(telepathy.constants.HANDLE_TYPE_CONTACT, h)
contact_xml = ET.Element("Contact")
ET.SubElement(contact_xml, "Guid").text = str(handle.name)
@@ -242,6 +247,7 @@ class SunshineSubscribeListChannel(SunshineListChannel):
handle.contact.updateGroups(self._conn_ref().pending_contacts_to_group[handle.name])
self._conn_ref().contactAdded(handle)
logger.info("Contact added.")
+<<<<<<< HEAD
def RemoveMembers(self, contacts, message):
for h in contacts:
@@ -250,10 +256,28 @@ class SunshineSubscribeListChannel(SunshineListChannel):
self._conn_ref().gadu_client.removeContact(contact, notify=True)
self.MembersChanged('', (), [handle], (), (), 0,
telepathy.CHANNEL_GROUP_CHANGE_REASON_NONE)
+=======
+ self._conn_ref().exportContactsFile()
+ """
+
+ def RemoveMembers(self, contacts, message):
+ for h in contacts:
+ self._remove(h)
+
+ """
+ for h in contacts:
+ handle = self._conn.handle(telepathy.HANDLE_TYPE_CONTACT, h)
+ contact = handle.contact
+ self._conn_ref().gadu_client.removeContact(contact, notify=True)
+ self.MembersChanged('', (), [handle], (), (), 0,
+ telepathy.CHANNEL_GROUP_CHANGE_REASON_NONE)
+ self._conn_ref().exportContactsFile()
+ """
def _filter_contact(self, contact):
return (True, False, False)
+
#@Lockable(mutex, 'add_subscribe', 'finished_cb')
# def _add(self, handle_id, message, finished_cb):
# logger.info("Subscribe - Add Members called.")
@@ -380,3 +404,39 @@ class SunshineSubscribeListChannel(SunshineListChannel):
# # Contact rejected
# self.MembersChanged('', (), [handle], (), (), 0,
# telepathy.CHANNEL_GROUP_CHANGE_REASON_NONE)
+ def _add(self, handle_id, message):
+ handle = self._conn.handle(telepathy.HANDLE_TYPE_CONTACT, handle_id)
+ if handle.contact is not None:
+ return True
+
+ contact_xml = ET.Element("Contact")
+ ET.SubElement(contact_xml, "Guid").text = str(handle.name)
+ ET.SubElement(contact_xml, "GGNumber").text = str(handle.name)
+ ET.SubElement(contact_xml, "ShowName").text = str(handle.name)
+ ET.SubElement(contact_xml, "Groups")
+ c = GaduContact.from_xml(contact_xml)
+ self._conn_ref().gadu_client.addContact( c )
+ self._conn_ref().gadu_client.notifyAboutContact( c )
+ logger.info("Adding contact: %s" % (handle.name))
+ self.MembersChanged('', [handle], (), (), (), 0,
+ telepathy.CHANNEL_GROUP_CHANGE_REASON_INVITED)
+
+ #alias and group settings for new contacts are bit tricky
+ #try to set alias
+ handle.contact.ShowName = self._conn_ref().get_contact_alias(handle.id)
+ #and group
+ if self._conn_ref().pending_contacts_to_group.has_key(handle.name):
+ logger.info("Trying to add temporary group.")
+ handle.contact.updateGroups(self._conn_ref().pending_contacts_to_group[handle.name])
+ self._conn_ref().contactAdded(handle)
+ logger.info("Contact added.")
+ self._conn_ref().exportContactsFile()
+
+ def _remove(self, handle_id):
+ handle = self._conn.handle(telepathy.HANDLE_TYPE_CONTACT, h)
+ contact = handle.contact
+ self._conn_ref().gadu_client.removeContact(contact, notify=True)
+ self.MembersChanged('', (), [handle], (), (), 0,
+ telepathy.CHANNEL_GROUP_CHANGE_REASON_NONE)
+ #self._conn_ref().exportContactsFile()
+
diff --git a/sunshine/channel/group.py b/sunshine/channel/group.py
index 5841613..375d07a 100644
--- a/sunshine/channel/group.py
+++ b/sunshine/channel/group.py
@@ -37,7 +37,7 @@ logger = logging.getLogger('Sunshine.GroupChannel')
class SunshineGroupChannel(SunshineListChannel):
- def __init__(self, connection, manager, props, object_path):
+ def __init__(self, connection, manager, props, object_path=None):
self.__pending_add = []
self.__pending_remove = []
self.conn = connection
diff --git a/sunshine/channel/text.py b/sunshine/channel/text.py
index 761a8b7..02f7f29 100644
--- a/sunshine/channel/text.py
+++ b/sunshine/channel/text.py
@@ -41,7 +41,7 @@ class SunshineTextChannel(SunshineChannel,
telepathy.server.ChannelInterfaceChatState,
ChannelInterfaceMessages):
- def __init__(self, conn, manager, conversation, props, object_path):
+ def __init__(self, conn, manager, conversation, props, object_path=None):
_, surpress_handler, handle = manager._get_type_requested_handle(props)
self._recv_id = 0
self._conn_ref = weakref.ref(conn)
@@ -50,7 +50,7 @@ class SunshineTextChannel(SunshineChannel,
self._pending_messages2 = {}
self.handle = handle
- telepathy.server.ChannelTypeText.__init__(self, conn, manager, props, object_path)
+ telepathy.server.ChannelTypeText.__init__(self, conn, manager, props, object_path=object_path)
SunshineChannel.__init__(self, conn, props)
telepathy.server.ChannelInterfaceChatState.__init__(self)
ChannelInterfaceMessages.__init__(self)