home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / lib / deskbar-applet / handlers / evolution.py < prev    next >
Encoding:
Python Source  |  2007-04-09  |  2.2 KB  |  69 lines

  1. from gettext import gettext as _
  2. import cgi
  3. import gnomevfs
  4. import deskbar, deskbar.Indexer, deskbar.Handler, deskbar.evolution, deskbar.Utils, deskbar.Match
  5. from deskbar.defs import VERSION
  6.  
  7. def _check_requirements():
  8.     if deskbar.evolution.num_address_books_with_completion() > 0:
  9.         return (deskbar.Handler.HANDLER_IS_HAPPY, None, None)
  10.     else:
  11.         return (deskbar.Handler.HANDLER_HAS_REQUIREMENTS,
  12.         _("You need to enable autocomplete in your mail preferences"),
  13.         lambda dialog: deskbar.Utils.more_information_dialog(
  14.             dialog,
  15.             _("Autocompletion Needs to be Enabled"),
  16.             _("We cannot provide e-mail addresses from your address book unless autocompletion is enabled.  To do this, from your mail program's menu, choose Edit - Preferences, and then Autocompletion.")
  17.             ))
  18.  
  19. HANDLERS = {
  20.     "EvolutionHandler" : {
  21.         "name": _("Mail (Address Book)"),
  22.         "description": _("Send mail to your contacts by typing their name or e-mail address"),
  23.         "requirements" : _check_requirements,
  24.         "version": VERSION,
  25.     }
  26. }
  27.  
  28. class EvolutionMatch(deskbar.Match.Match):
  29.     def __init__(self, backend, name=None, email=None, pixbuf=None, **args):
  30.         deskbar.Match.Match.__init__(self, backend, name=name, email=email, **args)
  31.         self._icon = pixbuf
  32.         self.email = email
  33.         
  34.     def action(self, text=None):
  35.         deskbar.Utils.url_show("mailto:"+self.email)
  36.         
  37.     def get_category(self):
  38.         return "people"
  39.     
  40.     def get_name(self, text=None):
  41.         return {
  42.             "name": cgi.escape(self.name),
  43.             "email": self.email,
  44.         }
  45.         
  46.     def get_verb(self):
  47.         #translators: First %s is the contact full name, second %s is the email address
  48.         return _("Send Email to <b>%(name)s</b> (%(email)s)")
  49.     
  50.     def get_hash(self, text=None):
  51.         return self.email
  52.         
  53. class EvolutionHandler(deskbar.Handler.Handler):
  54.     def __init__(self):
  55.         deskbar.Handler.Handler.__init__(self, "stock_addressbook")    
  56.     
  57.     def initialize(self):
  58.         deskbar.evolution.set_pixbuf_size(deskbar.ICON_HEIGHT)
  59.         
  60.     def query(self, query):
  61.         hits = deskbar.evolution.search_sync(query, deskbar.DEFAULT_RESULTS_PER_HANDLER)
  62.         matches = []
  63.         for name, email, pixbuf in hits:
  64.             if name == None or email == None:
  65.                 continue
  66.             
  67.             matches.append(EvolutionMatch(self, name, email, pixbuf))
  68.         return matches
  69.