Re: [Request] Evolution AddressBook plugin



Il giorno mer, 03/02/2010 alle 22.18 +0100, Ulrik Sverdrup ha scritto:
> 2010/1/26 Francesco Marella <francesco marella gmail com>:
> > Hi all,
> >
> > wondering if someone could add a plugin to Kupfer to access the contacts
> > inside the Evolution addressbook.
> > It could be done via Dbus, I've found some related info:
> > http://wiki.openmoko.org/wiki/Org_gnome_evolution_dataserver_AddressBook._org_gnome_evolution_dataserver_addressbook_BookFactory
> > http://wiki.openmoko.org/wiki/Org_gnome_evolution_dataserver_AddressBook._org_gnome_evolution_dataserver_addressbook_file_3a_2f_2f_2f_home_2f_root_2f_2e_evolution_2f_addressbook_2f_local_2f_system
> >
> > or via the evolution.ebook module.
> >
> > Thanks in advance.
> 
> Hi,
> 
> given the complexity of evolution's address book and calendar API,
> it's a godsend with a good python package for evolution for the person
> wanting to build an evolution plugin.
> 
> I don't have evolution installed, but you can install python-evolution
> anyway, so I made the following simplest possible evolution plugin
> that will extract all primary mail addresses and nothing more.
> Something to build on for interested people. It might even be useful,
> but bear in mind that the evolution address book has a ton of
> information that could be used.
> 
> Ulrik

Hi Ulrik,

Thanks for the draft plugin, I've been hacked it and the final plugin is
attached. This plugin is *heavily inspired* from Karol's claws-mail
plugin (thank you too). Tested and working.

-- 
Francesco Marella <francesco marella gmail com>
# -*- coding: UTF-8 -*-
from __future__ import absolute_import

__kupfer_name__ = _("Evolution")
__kupfer_sources__ = ("ContactsSource", )
__kupfer_actions__ = ("NewMailAction", )
__description__ = _("Evolution contacts")
__version__ = "2010-02-08"
__author__ = "Francesco Marella, Karol Będkowski, Ulrik Sverdrup"

import evolution

from kupfer.objects import Action
from kupfer.objects import TextLeaf, UrlLeaf, RunnableLeaf
from kupfer import utils
from kupfer.obj.apps import AppLeafContentMixin
from kupfer.obj.grouping import ToplevelGroupingSource
from kupfer.obj.contacts import ContactLeaf, EmailContact, email_from_leaf

class ComposeMail(RunnableLeaf):
	''' Create new mail without recipient '''
	def __init__(self):
		RunnableLeaf.__init__(self, name=_("Compose New Email"))

	def run(self):
		utils.launch_commandline('evolution mailto:')

	def get_description(self):
		return _("Compose a new message in Evolution")

	def get_icon_name(self):
		return "mail-message-new"


class NewMailAction(Action):
	''' Create new mail to selected leaf'''
	def __init__(self):
		Action.__init__(self, _('Compose Email'))

	def activate(self, leaf):
		self.activate_multiple((leaf, ))

	def activate_multiple(self, objects):
		recipients = ",".join(email_from_leaf(L) for L in objects)
		utils.spawn_async(["evolution", "mailto:%s"; % recipients])

	def get_icon_name(self):
		return "mail-message-new"

	def item_types(self):
		yield ContactLeaf
		# we can enter email
		yield TextLeaf
		yield UrlLeaf

	def valid_for_item(self, item):
		return bool(email_from_leaf(item))


class ContactsSource(AppLeafContentMixin, ToplevelGroupingSource):
	appleaf_content_id = 'evolution'

	def __init__(self, name=_("Evolution Address Book")):
		super(ContactsSource, self).__init__(name, "Contacts")

	def get_items(self):
		ebook_ = evolution.ebook.open_addressbook("default")
		for contact in ebook_.get_all_contacts():
			name = contact.get_property("full-name")
			email = contact.get_property("email-1")
			if email:
				yield EmailContact(email, name)

		yield ComposeMail()

	def should_sort_lexically(self):
		return True

	def get_description(self):
		return _("Evolution contacts")

	def get_icon_name(self):
		return "evolution"

	def provides(self):
		yield RunnableLeaf
		yield ContactLeaf



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