summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKrzysztof Klinikowski <kkszysiu@gmail.com>2009-12-27 11:18:51 +0100
committerKrzysztof Klinikowski <kkszysiu@gmail.com>2009-12-27 11:18:51 +0100
commit186539de6b8067d7aa228d9b35394c442875a940 (patch)
tree8d877a71513035b106b636df2b6fd36bb7ad820f
parent4cc9078aac23440a432110e8e60c849b8021da91 (diff)
Mkay, now contacts can be added/deleted to/from group but just temporary because it is not saved in contact list file yet.
-rw-r--r--gadu/channel/group.py117
-rw-r--r--gadu/handle.py5
2 files changed, 63 insertions, 59 deletions
diff --git a/gadu/channel/group.py b/gadu/channel/group.py
index 1e93e91..1d4b6e5 100644
--- a/gadu/channel/group.py
+++ b/gadu/channel/group.py
@@ -47,7 +47,6 @@ class GaduGroupChannel(GaduListChannel):
def create_group():
if self._handle.group is None:
name = self._handle.name.encode("utf-8")
-
for group in self.conn.profile.groups:
if group.Name != name:
group_xml = ET.Element("Group")
@@ -59,66 +58,44 @@ class GaduGroupChannel(GaduListChannel):
g = GaduContactGroup.from_xml(group_xml)
self.conn.profile.addGroup(g)
create_group()
+# @async
+# def create_group():
+# if self._handle.group is None:
+# name = self._handle.name.encode("utf-8")
+# #connection.msn_client.address_book.add_group(name)
+# create_group()
-#
-# def AddMembers(self, contacts, message):
-# ab = self._conn.msn_client.address_book
-# if self._handle.group is None:
-# for contact_handle_id in contacts:
-# contact_handle = self._conn.handle(telepathy.HANDLE_TYPE_CONTACT,
-# contact_handle_id)
-# logger.info("Adding contact %s to pending group %s" %
-# (unicode(contact_handle), unicode(self._handle)))
-# if contact_handle_id in self.__pending_remove:
-# self.__pending_remove.remove(contact_handle_id)
-# else:
-# self.__pending_add.append(contact_handle_id)
-# return
-# else:
-# for contact_handle_id in contacts:
-# contact_handle = self._conn.handle(telepathy.HANDLE_TYPE_CONTACT,
-# contact_handle_id)
-# logger.info("Adding contact %s to group %s" %
-# (unicode(contact_handle), unicode(self._handle)))
-# contact = contact_handle.contact
-# group = self._handle.group
-# if contact is not None and contact.is_member(papyon.Membership.FORWARD):
-# ab.add_contact_to_group(group, contact)
-# else:
-# contact_handle.pending_groups.add(group)
-#
-# def RemoveMembers(self, contacts, message):
-# ab = self._conn.msn_client.address_book
-# if self._handle.group is None:
-# for contact_handle_id in contacts:
-# contact_handle = self._conn.handle(telepathy.HANDLE_TYPE_CONTACT,
-# contact_handle_id)
-# logger.info("Adding contact %s to pending group %s" %
-# (unicode(contact_handle), unicode(self._handle)))
-# if contact_handle_id in self.__pending_add:
-# self.__pending_add.remove(contact_handle_id)
-# else:
-# self.__pending_remove.append(contact_handle_id)
-# return
-# else:
-# for contact_handle_id in contacts:
-# contact_handle = self._conn.handle(telepathy.HANDLE_TYPE_CONTACT,
-# contact_handle_id)
-# logger.info("Removing contact %s from pending group %s" %
-# (unicode(contact_handle), unicode(self._handle)))
-# contact = contact_handle.contact
-# group = self._handle.group
-# if contact is not None and contact.is_member(papyon.Membership.FORWARD):
-# ab.delete_contact_from_group(group, contact)
-# else:
-# contact_handle.pending_groups.discard(group)
-#
-# def Close(self):
-# logger.debug("Deleting group %s" % self._handle.name)
+
+ def AddMembers(self, contacts, message):
+ for contact_handle_id in contacts:
+ contact_handle = self._conn.handle(telepathy.HANDLE_TYPE_CONTACT,
+ contact_handle_id)
+ logger.info("Adding contact %s to group %s" %
+ (unicode(contact_handle), unicode(self._handle)))
+ contact = contact_handle.contact
+ group = self._handle.group
+
+ self.add_contact_to_group(group, contact)
+
+
+ def RemoveMembers(self, contacts, message):
+ for contact_handle_id in contacts:
+ contact_handle = self._conn.handle(telepathy.HANDLE_TYPE_CONTACT,
+ contact_handle_id)
+ logger.info("Removing contact %s from pending group %s" %
+ (unicode(contact_handle), unicode(self._handle)))
+ contact = contact_handle.contact
+ group = self._handle.group
+
+ self.delete_contact_from_group(group, contact)
+
+ def Close(self):
+ logger.debug("Deleting group %s" % self._handle.name)
+ del self.conn.profile.groups[self._handle.name]
# ab = self._conn.msn_client.address_book
# group = self._handle.group
# ab.delete_group(group)
-#
+
# def _filter_contact(self, contact):
# if contact.is_member(papyon.Membership.FORWARD):
# for group in contact.groups:
@@ -168,3 +145,29 @@ class GaduGroupChannel(GaduListChannel):
# logger.debug("Contact %s removed from group %s" %
# (handle.name, group_name))
#
+ def add_contact_to_group(self, group, contact):
+ group_name = group.Name.decode("utf-8")
+ if group_name == self._handle.name:
+ handle = GaduHandleFactory(self.conn, 'contact',
+ contact.uin, None)
+ added = set()
+ added.add(handle)
+ self.MembersChanged('', added, (), (), (), 0,
+ telepathy.CHANNEL_GROUP_CHANGE_REASON_NONE)
+
+ logger.debug("Contact %s added to group %s" %
+ (handle.name, group_name))
+
+ def delete_contact_from_group(self, group, contact):
+ group_name = group.Name.decode("utf-8")
+ if group_name == self._handle.name:
+ handle = GaduHandleFactory(self.conn, 'contact',
+ contact.uin, None)
+ removed = set()
+ removed.add(handle)
+
+ self.MembersChanged('', (), removed, (), (), 0,
+ telepathy.CHANNEL_GROUP_CHANGE_REASON_NONE)
+
+ logger.debug("Contact %s removed from group %s" %
+ (handle.name, group_name)) \ No newline at end of file
diff --git a/gadu/handle.py b/gadu/handle.py
index f107298..bbbff36 100644
--- a/gadu/handle.py
+++ b/gadu/handle.py
@@ -118,9 +118,10 @@ class GaduListHandle(GaduHandle):
class GaduGroupHandle(GaduHandle):
def __init__(self, connection, id, group_name):
handle_type = telepathy.HANDLE_TYPE_GROUP
- self.handle_name = group_name
+ handle_name = group_name
self._connection = connection
- GaduHandle.__init__(self, connection, id, handle_type, self,handle_name)
+ self.handle_name = group_name
+ GaduHandle.__init__(self, connection, id, handle_type, handle_name)
@property
def group(self):