[kupfer: 15/51] grouping: Use JID as email address in Pidgin if valid
- From: Ulrik Sverdrup <usverdrup src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [kupfer: 15/51] grouping: Use JID as email address in Pidgin if valid
- Date: Sun, 10 Jan 2010 11:58:05 +0000 (UTC)
commit 8264f8a8de5e14716b454a24f49c5eea4a4c1d35
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date: Thu Jan 7 03:37:48 2010 +0100
grouping: Use JID as email address in Pidgin if valid
If the JID is a valid email address we register it as such for Pidgin
contacts. This is twofold: We allow e-mail actions to work on pidgin
contacts, which is really flexible. We also use the address for
matching/grouping with other contacts.
Grouping API updated to ignore values of None when grouping leaves.
kupfer/obj/contacts.py | 5 +++--
kupfer/obj/grouping.py | 14 +++++++++-----
kupfer/plugin/pidgin.py | 5 ++++-
3 files changed, 16 insertions(+), 8 deletions(-)
---
diff --git a/kupfer/obj/contacts.py b/kupfer/obj/contacts.py
index 8c638bd..9be8544 100644
--- a/kupfer/obj/contacts.py
+++ b/kupfer/obj/contacts.py
@@ -34,9 +34,10 @@ def _get_email_from_url(url):
sep = url.find('://')
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}$")
-def _check_email(email):
+def is_valid_email(email):
''' simple email check '''
return len(email) > 7 and _CHECK_EMAIL_RE.match(email.lower()) is not None
@@ -50,7 +51,7 @@ def email_from_leaf(leaf):
if isinstance(leaf, ContactLeaf):
return EMAIL_KEY in leaf and leaf[EMAIL_KEY]
email = _get_email_from_url(leaf.object)
- return _check_email(email) and email
+ return is_valid_email(email) and email
class EmailContact (ContactLeaf):
diff --git a/kupfer/obj/grouping.py b/kupfer/obj/grouping.py
index 3341208..e5e1e74 100644
--- a/kupfer/obj/grouping.py
+++ b/kupfer/obj/grouping.py
@@ -18,10 +18,12 @@ class GroupingLeaf (Leaf):
"""
A Leaf that groups with other leaves inside Grouping Sources
- The represented object of a GroupedLeaf is a
- dictionary of (slot, value) pairs, where
- slot identifies the slot, and the value is something that
- must be equal to be grouped.
+ The represented object of a GroupedLeaf is a dictionary of (slot, value)
+ pairs, where slot identifies the slot, and the value is something that must
+ be equal to be grouped.
+
+ The GroupingLeaf must have a value for all @grouping_slots, but values of
+ None will not be grouped with others.
"""
grouping_slots = ()
@@ -80,7 +82,9 @@ class GroupingSource (Source):
continue
slots = leaf.slots()
for slot in leaf.grouping_slots:
- groups.setdefault((slot, slots[slot]), set()).add(leaf)
+ value = slots[slot]
+ if value:
+ groups.setdefault((slot, value), set()).add(leaf)
if not leaf.grouping_slots:
self.output_error("GroupingLeaf has no grouping slots",
repr(leaf))
diff --git a/kupfer/plugin/pidgin.py b/kupfer/plugin/pidgin.py
index 9892606..ca808a6 100644
--- a/kupfer/plugin/pidgin.py
+++ b/kupfer/plugin/pidgin.py
@@ -9,7 +9,7 @@ from kupfer import icons
from kupfer import plugin_support
from kupfer.helplib import dbus_signal_connect_weakly, PicklingHelperMixin
from kupfer.obj.grouping import ToplevelGroupingSource
-from kupfer.obj.contacts import NAME_KEY, EMAIL_KEY, ContactLeaf
+from kupfer.obj.contacts import NAME_KEY, EMAIL_KEY, ContactLeaf, is_valid_email
__kupfer_name__ = _("Pidgin")
__kupfer_sources__ = ("ContactsSource", )
@@ -130,6 +130,9 @@ class PidginContact(ContactLeaf):
PIDGIN_ACCOUNT: account,
PIDGIN_JID: jid,
}
+ if not is_valid_email(jid):
+ slots[EMAIL_KEY] = None
+
ContactLeaf.__init__(self, slots, name or jid)
# we use @jid as an alias for this contact
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]