[kupfer: 18/51] gajim/grouping: create more unversal JabberContact, fix grouping in gajim



commit eabc79b5bfb02bd64c85f1c4ea52dd2004a2c836
Author: Karol BÄ?dkowski <karol bedkowsk+gh gmail com>
Date:   Thu Jan 7 19:44:10 2010 +0100

    gajim/grouping: create more unversal JabberContact, fix grouping in gajim
    
    - Remove from JabberContact account, starus, resource
    - Change jabber keys to JABBER_*
    + Create GajimContact

 kupfer/obj/contacts.py |   30 ++++++++++++++++--------------
 kupfer/plugin/gajim.py |   25 +++++++++++++++++++------
 2 files changed, 35 insertions(+), 20 deletions(-)
---
diff --git a/kupfer/obj/contacts.py b/kupfer/obj/contacts.py
index 9be8544..1ab6b1c 100644
--- a/kupfer/obj/contacts.py
+++ b/kupfer/obj/contacts.py
@@ -17,12 +17,12 @@ __author__ = ("Ulrik Sverdrup <ulrik sverdrup gmail com>, "
 
 EMAIL_KEY = "EMAIL"
 NAME_KEY = "NAME"
-JID_KEY = "JID"
-
-CONTACTS_CATEGORY = "Contacts"
+JABBER_JID_KEY = "JID"
+JABBER_STATUS_KEY = "JABBER_STATUS"
+JABBER_RESOURCE_KEY = "JABBER_RESOURCE"
 
 class ContactLeaf(GroupingLeaf):
-	grouping_slots = (EMAIL_KEY, NAME_KEY)
+	grouping_slots = (NAME_KEY, )
 	def get_icon_name(self):
 		return "stock_person"
 
@@ -35,7 +35,7 @@ def _get_email_from_url(url):
 	return url[sep+3:] if sep > -1 else url
 
 # FIXME: Find a more robust (less strict?) approach than regex
-_CHECK_EMAIL_RE = re.compile(r"^[a-z0-9\ _%-+]+\ [a-z0-9 _%-]+\ [a-z]{2,6}$")
+_CHECK_EMAIL_RE = re.compile(r"^[a-z0-9\ _%-+]+\ [a-z0-9 _%-]+\ [a-z]{2,}$")
 
 def is_valid_email(email):
 	''' simple email check '''
@@ -55,6 +55,7 @@ def email_from_leaf(leaf):
 
 
 class EmailContact (ContactLeaf):
+	grouping_slots = ContactLeaf.grouping_slots + (EMAIL_KEY, )
 	def __init__(self, email, name):
 		slots = {EMAIL_KEY: email, NAME_KEY: name}
 		ContactLeaf.__init__(self, slots, name)
@@ -67,23 +68,24 @@ class EmailContact (ContactLeaf):
 
 
 class JabberContact (ContactLeaf):
-	grouping_slots = ContactLeaf.grouping_slots + (JID_KEY, )
-	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
+	''' Minimal class for all Jabber contacts. '''
+	grouping_slots = ContactLeaf.grouping_slots + (JABBER_JID_KEY, )
+
+	def __init__(self, jid, name, status, resource, slots=None):
+		jslots = {JABBER_JID_KEY: jid, NAME_KEY: name or jid}
+		if slots:
+			jslots.update(slots)
+		ContactLeaf.__init__(self, jslots, name or jid)
 
 		self._description = _("[%(status)s] %(userid)s/%(service)s") % \
 				{
 					"status": status,
 					"userid": jid,
-					"service": resource[0][0] if resource else u"",
+					"service": resource or u"",
 				}
 
 	def repr_key(self):
-		return self.object[JID_KEY]
+		return self.object[JABBER_JID_KEY]
 
 	def get_description(self):
 		return self._description
diff --git a/kupfer/plugin/gajim.py b/kupfer/plugin/gajim.py
index 346ef74..be90a97 100644
--- a/kupfer/plugin/gajim.py
+++ b/kupfer/plugin/gajim.py
@@ -6,7 +6,8 @@ from kupfer import pretty
 from kupfer.helplib import dbus_signal_connect_weakly, PicklingHelperMixin
 from kupfer import plugin_support
 from kupfer.obj.grouping import ToplevelGroupingSource
-from kupfer.obj.contacts import JID_KEY, ContactLeaf, JabberContact
+from kupfer.obj.contacts import ContactLeaf, JabberContact, JABBER_JID_KEY 
+		
 
 __kupfer_name__ = _("Gajim")
 __kupfer_sources__ = ("ContactsSource", )
@@ -32,6 +33,8 @@ _SERVICE_NAME = 'org.gajim.dbus'
 _OBJECT_NAME = '/org/gajim/dbus/RemoteObject'
 _IFACE_NAME = 'org.gajim.dbus.RemoteInterface'
 
+GAJIM_ACCOUNT_KEY = "GAJIM_ACCOUNT"
+
 def _create_dbus_connection(activate=False):
 	''' Create dbus connection to Gajim 
 		@activate: true=starts gajim if not running
@@ -63,6 +66,15 @@ def _check_gajim_version(conn):
 	return tversion
 
 
+class GajimContact(JabberContact):
+	def __init__(self, jid, name, status, resources, account):
+		gajim_slots = { GAJIM_ACCOUNT_KEY: account }
+		JabberContact.__init__(self, jid, name, status, resources, gajim_slots)
+
+	def repr_key(self):
+		return "".join((self.object[JABBER_JID_KEY], self.object[GAJIM_ACCOUNT_KEY]))
+
+
 class AccountStatus(Leaf):
 	pass
 
@@ -73,8 +85,8 @@ class OpenChat(Action):
 
 	def activate(self, leaf):
 		interface = _create_dbus_connection()
-		account = leaf.account
-		jid = JID_KEY in leaf and leaf[JID_KEY]
+		jid = JABBER_JID_KEY in leaf and leaf[JABBER_JID_KEY]
+		account = leaf[GAJIM_ACCOUNT_KEY]
 		if interface is not None:
 			vmaj,vmin,vbuild = _check_gajim_version(interface)
 			if vmaj == 0 and vmin < 13:
@@ -89,7 +101,7 @@ class OpenChat(Action):
 		yield ContactLeaf
 
 	def valid_for_item(self, item):
-		return JID_KEY in item and item[JID_KEY]
+		return GAJIM_ACCOUNT_KEY in item and item[GAJIM_ACCOUNT_KEY]
 
 
 class ChangeStatus(Action):
@@ -172,9 +184,10 @@ class ContactsSource(AppLeafContentMixin, ToplevelGroupingSource,
 
 			for contact in interface.list_contacts(account):
 				name = contact['name'] or contact['jid']
-				jc = JabberContact(contact['jid'], name, account, \
+				resources = contact['resources'][0][0] if contact['resources'] else u''
+				jc = GajimContact(contact['jid'], name, \
 						_STATUSES.get(contact['show'], contact['show']), \
-						contact['resources'])
+						resources, account)
 				yield jc
 
 	def get_icon_name(self):



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