[kupfer/next] Change KupferObject's alias API
- From: Ulrik Sverdrup <usverdrup src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [kupfer/next] Change KupferObject's alias API
- Date: Mon, 1 Feb 2010 08:37:44 +0000 (UTC)
commit 9a8016c2349d2afc83f0142943bc6da850685292
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date: Fri Jan 22 02:25:45 2010 +0100
Change KupferObject's alias API
kupfer/obj/base.py | 10 +++++++---
kupfer/obj/grouping.py | 4 +---
kupfer/obj/objects.py | 6 +++---
kupfer/plugin/pidgin.py | 4 +---
kupfer/plugin/skype.py | 3 +--
5 files changed, 13 insertions(+), 14 deletions(-)
---
diff --git a/kupfer/obj/base.py b/kupfer/obj/base.py
index 5f659b6..3da7fcf 100644
--- a/kupfer/obj/base.py
+++ b/kupfer/obj/base.py
@@ -61,9 +61,13 @@ class KupferObject (object):
name = self.__class__.__name__
self.name = tounicode(name)
folded_name = tofolded(self.name)
- self.name_aliases = set()
- if folded_name != self.name:
- self.name_aliases.add(folded_name)
+ self.kupfer_add_alias(folded_name)
+
+ def kupfer_add_alias(self, alias):
+ if alias != unicode(self):
+ if not hasattr(self, "name_aliases"):
+ self.name_aliases = set()
+ self.name_aliases.add(alias)
def __str__(self):
return toutf8(self.name)
diff --git a/kupfer/obj/grouping.py b/kupfer/obj/grouping.py
index e61ad12..c50fb47 100644
--- a/kupfer/obj/grouping.py
+++ b/kupfer/obj/grouping.py
@@ -135,14 +135,12 @@ class GroupingSource (Source):
return leaf
obj = copy.copy(iter(leaves).next())
obj.links = list(leaves)
- obj.name_aliases = set(obj.name_aliases)
for other in leaves:
- obj.name_aliases.add(unicode(other))
+ obj.kupfer_add_alias(unicode(other))
# adding the other's aliases can be misleading
# since the matched email address might not be
# what we are e-mailing
# obj.name_aliases.update(other.name_aliases)
- obj.name_aliases.discard(unicode(obj))
return obj
class ToplevelGroupingSource (GroupingSource):
diff --git a/kupfer/obj/objects.py b/kupfer/obj/objects.py
index 78e40e0..a034bc2 100644
--- a/kupfer/obj/objects.py
+++ b/kupfer/obj/objects.py
@@ -157,15 +157,15 @@ class AppLeaf (Leaf, pretty.OutputMixin):
# finish will raise InvalidDataError on invalid item
self.finish()
Leaf.__init__(self, self.object, self.object.get_name())
- self.name_aliases.update(self._get_aliases())
+ self._add_aliases()
- def _get_aliases(self):
+ def _add_aliases(self):
# find suitable alias
# use package name: non-extension part of ID
lowername = unicode(self).lower()
package_name = self._get_package_name()
if package_name and package_name not in lowername:
- yield package_name
+ self.kupfer_add_alias(package_name)
def __getstate__(self):
self.init_item_id = self.object and self.object.get_id()
diff --git a/kupfer/plugin/pidgin.py b/kupfer/plugin/pidgin.py
index 5ab6d13..7c11536 100644
--- a/kupfer/plugin/pidgin.py
+++ b/kupfer/plugin/pidgin.py
@@ -147,9 +147,7 @@ class PidginContact(ContactLeaf):
ContactLeaf.__init__(self, slots, name or jid)
- # we use @jid as an alias for this contact
- if unicode(self) != jid:
- self.name_aliases.add(jid)
+ self.kupfer_add_alias(jid)
self._description = _("[%(status)s] %(userid)s/%(service)s") % \
{
diff --git a/kupfer/plugin/skype.py b/kupfer/plugin/skype.py
index 80198eb..90441c3 100644
--- a/kupfer/plugin/skype.py
+++ b/kupfer/plugin/skype.py
@@ -177,8 +177,7 @@ class Contact(ContactLeaf):
def __init__(self, name, handle, status):
slots = {SKYPE_KEY: handle, NAME_KEY: name}
ContactLeaf.__init__(self, slots, name)
- if name != handle:
- self.name_aliases.add(handle)
+ self.kupfer_add_alias(handle)
self._description = _("[%(status)s] %(userid)s") % \
dict(status=status, userid=handle)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]