[kupfer: 7/51] thunderbird: Port to Contacts API



commit ae8a84d89f50f8d1227e2b5ee644de51a6110fdf
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Tue Jan 5 21:59:29 2010 +0100

    thunderbird: Port to Contacts API

 kupfer/plugin/thunderbird.py |   27 +++++++++++----------------
 1 files changed, 11 insertions(+), 16 deletions(-)
---
diff --git a/kupfer/plugin/thunderbird.py b/kupfer/plugin/thunderbird.py
index f245912..6e2ef0f 100644
--- a/kupfer/plugin/thunderbird.py
+++ b/kupfer/plugin/thunderbird.py
@@ -9,6 +9,7 @@ from kupfer.objects import Leaf, Action, Source
 from kupfer.objects import TextLeaf, UrlLeaf, RunnableLeaf, AppLeafContentMixin
 from kupfer.helplib import FilesystemWatchMixin
 from kupfer import utils, icons
+from kupfer.obj.contacts import EmailContact, ContactLeaf, EMAIL_KEY
 
 from kupfer.plugin import thunderbird_support as support
 
@@ -32,15 +33,6 @@ def _check_email(email):
 	return len(email) > 7 and _CHECK_EMAIL_RE.match(email.lower()) is not None
 
 
-class Contact(Leaf):
-	''' Leaf represents a single contact from the address book '''
-	def get_description(self):
-		return self.object
-
-	def get_icon_name(self):
-		return "stock_person"
-
-
 class ComposeMail(RunnableLeaf):
 	''' Create new mail without recipient '''
 	def __init__(self):
@@ -63,9 +55,12 @@ class NewMailAction(Action):
 		Action.__init__(self, _('Compose New Mail To'))
 
 	def activate(self, leaf):
-		email = leaf.object
-		if isinstance(leaf, UrlLeaf):
+		if isinstance(leaf, ContactLeaf):
+			email = leaf.object[EMAIL_KEY]
+		elif isinstance(leaf, UrlLeaf):
 			email = _get_email_from_url(email)
+		else:
+			email = leaf.object
 
 		if not utils.launch_commandline("thunderbird mailto:%s"; % email):
 			utils.launch_commandline("icedove mailto:%s"; % email)
@@ -74,14 +69,14 @@ class NewMailAction(Action):
 		return "mail-message-new"
 
 	def item_types(self):
-		yield Contact
+		yield ContactLeaf
 		# we can enter email
 		yield TextLeaf
 		yield UrlLeaf
 
 	def valid_for_item(self, item):
-		if isinstance(item, Contact):
-			return True
+		if isinstance(item, ContactLeaf):
+			return EMAIL_KEY in item
 
 		elif isinstance(item, TextLeaf):
 			return _check_email(item.object)
@@ -110,7 +105,7 @@ class ContactsSource(AppLeafContentMixin, Source, FilesystemWatchMixin):
 
 	def get_items(self):
 		for name, email in support.get_contacts():
-			yield Contact(email, name)
+			yield EmailContact(email, name)
 
 		yield ComposeMail()
 
@@ -121,7 +116,7 @@ class ContactsSource(AppLeafContentMixin, Source, FilesystemWatchMixin):
 		return icons.get_gicon_with_fallbacks(None, ("thunderbird", "icedove"))
 
 	def provides(self):
-		yield Contact
+		yield ContactLeaf
 		yield RunnableLeaf
 
 



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