[kupfer: 17/23] thunderbird: Comments and changes



commit 034f7c980a30624b5cb47674913293d1bae44b6c
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Sun Dec 13 23:34:39 2009 +0100

    thunderbird: Comments and changes
    
    Hi Karol, here are some comments when reading the plugin. I had to fix
    something with abook_dir, because I started the plugin before I had
    installed icedove, so with luck I then found an error (_abook_dir was
    None).
    
    Please amend/rebase your changes on top of this commit; the comments
    in this change are just for you to read and are not needed later.
    
    I have not looked into the mork parsing.. what a horrible format!
    
    Do you have any idea how the parsing handles unicode text? Encoding is
    always a concern. (My mork file seems to specify the iso 8859-1
    encoding (latin-1)).
    
    Also, the email regex is very conservative -- it doesn't allow
    international domain names nor .museum TDL :-) that can be fixed later
    though.

 kupfer/plugin/thunderbird.py         |   38 ++++++++++++++++++++-------------
 kupfer/plugin/thunderbird_support.py |    9 ++++---
 2 files changed, 28 insertions(+), 19 deletions(-)
---
diff --git a/kupfer/plugin/thunderbird.py b/kupfer/plugin/thunderbird.py
index d0fe731..13193a0 100644
--- a/kupfer/plugin/thunderbird.py
+++ b/kupfer/plugin/thunderbird.py
@@ -5,9 +5,10 @@ from __future__ import with_statement
 import os
 import re
 
-from kupfer.objects import (Leaf, Action, Source, TextLeaf, UrlLeaf, RunnableLeaf, 
-		FilesystemWatchMixin, AppLeafContentMixin)
-from kupfer import utils
+from kupfer.objects import Leaf, Action, Source
+from kupfer.objects import TextLeaf, UrlLeaf, RunnableLeaf, AppLeafContentMixin
+from kupfer.helplib import FilesystemWatchMixin, PicklingHelperMixin
+from kupfer import utils, icons
 
 from kupfer.plugin import thunderbird_support as support
 
@@ -32,10 +33,9 @@ def _check_email(email):
 
 
 class Contact(Leaf):
-	''' Leaf represent single contact from Claws address book '''
-	def get_actions(self):
-		yield NewMailAction()
-
+	''' Leaf represents a single contact from the address book '''
+	# no builtin actions if it is later going to be "decorated" automatically with NewMailAction
+	# that's why it was duplicated
 	def get_description(self):
 		return self.object
 
@@ -95,21 +95,29 @@ class NewMailAction(Action):
 		return False
 
 
-class ContactsSource(AppLeafContentMixin, Source, FilesystemWatchMixin):
+class ContactsSource(AppLeafContentMixin, Source, FilesystemWatchMixin, PicklingHelperMixin):
 	appleaf_content_id = ('thunderbird', 'icedove')
 
-	def __init__(self, name=_("Thundrbird Address Book")):
+	def __init__(self, name=_("Thunderbird Address Book")):
 		Source.__init__(self, name)
-		self._abook_dir, self._abook_file = support.get_addressbook_dir_file()
 		self.unpickle_finish()
 
 	def unpickle_finish(self):
-		if not os.path.isdir(self._abook_dir):
+		# _abook_dir might be None here => then we crash
+		# File "/usr/lib/python2.5/posixpath.py", line 195, in isdir
+		#	st = os.stat(path)
+		# TypeError: coercing to Unicode: need string or buffer, NoneType found
+
+		# don't store _abook_dir or _abook_file on self,
+		# they are never needed later Simply compute them here
+		# I changed the function to return only the directory
+		abook_dir = support.get_addressbook_dir_file()
+		if not abook_dir or not os.path.isdir(abook_dir):
 			return
-		self.monitor_token = self.monitor_directories(self._abook_dir)
+		self.monitor_token = self.monitor_directories(abook_dir)
 
 	def monitor_include_file(self, gfile):
-		return gfile and gfile.get_basename() == self._abook_file
+		return gfile and gfile.get_basename() == support.ABOOK_FILE
 
 	def get_items(self):
 		for name, email in support.get_contacts():
@@ -120,8 +128,8 @@ class ContactsSource(AppLeafContentMixin, Source, FilesystemWatchMixin):
 	def get_description(self):
 		return _("Contacts from Thunderbird Address Book")
 
-	def get_icon_name(self):
-		return "thunderbird"
+	def get_gicon(self):
+		return icons.get_gicon_with_fallbacks(None, ("thunderbird", "icedove"))
 
 	def provides(self):
 		yield Contact
diff --git a/kupfer/plugin/thunderbird_support.py b/kupfer/plugin/thunderbird_support.py
index 85e8c43..ebb0f9b 100644
--- a/kupfer/plugin/thunderbird_support.py
+++ b/kupfer/plugin/thunderbird_support.py
@@ -242,7 +242,7 @@ def get_addressbook_dir_file():
 			break
 
 	if not thunderbird_home:
-		return None, None
+		return None
 
 	config = RawConfigParser()
 	config.read(tprofile)
@@ -258,17 +258,18 @@ def get_addressbook_dir_file():
 
 	if path:
 		path = os.path.join(thunderbird_home, path)
-	return path, ABOOK_FILE
+	# I thought it was strange to return something that is constant here
+	return path
 
 
 def get_addressbook_file():
 	''' Get full path to the Thunderbird address book file.
 		Return None if it don't exists '''
-	path, filename = get_addressbook_dir_file()
+	path = get_addressbook_dir_file()
 	if not path:
 		return None
 
-	fullpath = os.path.join(path, filename)
+	fullpath = os.path.join(path, ABOOK_FILE)
 	if os.path.isfile(fullpath):
 		return fullpath
 



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