[kupfer: 8/51] grouping: add support for jabber contacts



commit 0bd6ac25242af5c26f386a12a467cddfc5280c23
Author: Karol BÄ?dkowski <karol bedkowsk+gh gmail com>
Date:   Wed Jan 6 12:57:00 2010 +0100

    grouping: add support for jabber contacts

 kupfer/obj/contacts.py |   24 +++++++++++++++++++++++-
 kupfer/obj/grouping.py |    5 +++--
 2 files changed, 26 insertions(+), 3 deletions(-)
---
diff --git a/kupfer/obj/contacts.py b/kupfer/obj/contacts.py
index c25207e..f82a15b 100644
--- a/kupfer/obj/contacts.py
+++ b/kupfer/obj/contacts.py
@@ -1,4 +1,4 @@
-from kupfer.obj.grouping import ContactLeaf, EMAIL_KEY, NAME_KEY
+from kupfer.obj.grouping import ContactLeaf, EMAIL_KEY, NAME_KEY, JID_KEY
 
 class EmailContact (ContactLeaf):
 	def __init__(self, email, name):
@@ -11,3 +11,25 @@ class EmailContact (ContactLeaf):
 	def get_description(self):
 		return self.object[EMAIL_KEY]
 
+
+class JabberContact (ContactLeaf):
+	def __init__(self, jid, name, accout, status, resource):
+		slots = {JID_KEY: jid, NAME_KEY: name}
+		ContactLeaf.__init__(self, slots, name)
+		self.accout = accout
+		self.status = status
+		self.resource = resource
+
+		self._description = _("[%(status)s] %(userid)s/%(service)s") % \
+				{
+					"status": status,
+					"userid": jid,
+					"service": resource[0][0] if resource else u"",
+				}
+
+	def repr_key(self):
+		return self.object[JID_KEY]
+
+	def get_description(self):
+		return self._description
+
diff --git a/kupfer/obj/grouping.py b/kupfer/obj/grouping.py
index dc9223a..08e9958 100644
--- a/kupfer/obj/grouping.py
+++ b/kupfer/obj/grouping.py
@@ -15,6 +15,7 @@ __author__ = ("Karol BÄ?dkowski <karol bedkowsk+gh gmail com>, "
 
 EMAIL_KEY = "EMAIL"
 NAME_KEY = "NAME"
+JID_KEY = "JID"
 
 CONTACTS_CATEGORY = "Contacts"
 HOSTS_CATEGORY = "Hosts"
@@ -53,7 +54,7 @@ class GroupingLeaf (Leaf):
 		return [leaf.object[key] for leaf in self.links if key in leaf.object]
 
 class GroupingSource (Source):
-	grouping_keys = [EMAIL_KEY, NAME_KEY]
+	grouping_keys = [EMAIL_KEY, NAME_KEY, JID_KEY]
 
 	def __init__(self, name, sources):
 		Source.__init__(self, name)
@@ -75,8 +76,8 @@ class GroupingSource (Source):
 					# Let through Non-grouping leaves
 					yield leaf
 					continue
+				slots = leaf.slots()
 				for slot in self.grouping_keys:
-					slots = leaf.slots()
 					if slot not in slots:
 						continue
 					groups.setdefault((slot, slots[slot]), set()).add(leaf)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]