|
From: Daniel G. <go...@b1...> - 2010-09-19 01:34:43
|
On Sunday, September 19, 2010 12:28:43 pm deloptes wrote:
> > The plugin should never update the config. It only reads from it, in
> > my opinion. It's the app that changes the config.
Not fully correct for ressource configuration.
>
> you mean also the discover process?
In discover phase you are allowed to modify/create ressource configuraiton via the OpenSync API.
>
> I was thinking it can change the config and let the user choose what
> ressource he/she would like to sync.
Right. During the initial discover phase the plugin _can_ create resource configuration for all resources
which are discovered (e.g. via the akonadi specific protocol/API)
Later (rich) opensync frontends should be used to select which resource should be used for syncing by
enable/disable the resources. AFAIK there isn't any plugin implementation which is doing that yet. Since there
was no PIM-API or Synchroniatzion Protocol which allowed to do something like that.
So what you can do in the discover function is:
Get the OSyncPluingConifg pointer of the akonadi-sync plugin and do something like that:
---8<---
static osync_bool discover(OSyncPluginInfo *info, void *userdata, OSyncError **error)
{
OSyncPluginConfig *config = osync_plugin_info_get_config(info);
if (!config) {
osync_error_set(error, OSYNC_ERROR_GENERIC, "Unable to get config.");
goto error;
}
/* akonadi api magic */
foreach (akonadi_resource) {
if (akonadi_resource == contact) {
/* for each discovered resource do something like this: */
OSyncPluginResource *res = osync_plugin_resource_new(error);
if (!res)
goto error;
osync_plugin_resource_set_name(res, "LDAP Adressbook");
osync_plugin_resource_set_objtype(res, "contact");
osync_plugin_resource_set_preferred_format(res, "vcard30");
if (akonadi_default_contact_resource)
osync_plugin_resource_enable(res, TRUE);
else
osync_plugin_resource_enable(res, FALSE);
OSyncObjFormatSink *contact_ldap_format_1 = osync_objformat_sink_new("vcard30",
error);
if (!contact_ldap_format)
goto error;
if (akonadi_special_format_config_or_extension)
osync_objformat_sink_set_config(contact_ldap_format, "VCARD_EXTENSION=Akonadi-
LDAP");
osync_plugin_resource_add_objformat_sink(res, contact_ldap_format);
/* if there is support for multiple contact formats - e.g. vcard21 - just do the same
and call:
* osync_plugin_resource_add_objformat_sink(res,
$pointer_to_objformat_sink_for_vcard21);
*/
/* Report avaliable sinks... */
OSyncObjTypeSink *sink = osync_plugin_info_find_objtype(info, "contact");
if (!sink)
continue;
osync_objtype_sink_set_available(sink, TRUE);
/* TODO: Assemble dynamic capabilities.
* osync_plugin_info_set_capabilities() - check evo2-sync for example ...
*/
} else if ( .... ) {
}
}
OSyncVersion *version = osync_version_new(error);
--->8---
This should you allow to ship a default akonadi-sync configuration without any resource
configuration. The resource configuraiton would be assemble via the OSyncPluginRessource API
within your discover() function.
Instead of filling a default xml config, you use the API with the coressponding values.
As Chris already told you, for objtype (what's the term of the Type of (pim)Data) we use
predefined values:
- contact
- event (appointments, not todos)
- todo
- ...
Regarding the objformat, you might want to use the native format akonadi is providing
you. We have a vformat plugin which handles:
- vcard21 (vCard 2.1)
- vcard30 (vCard 3.0)
- vevent10 (vCalendar)
- vevent20 (iCalendar)
- vtodo10 (vCalendar
- vtodo20 (iCalendar)
If there is heavy use of akonadi specific extensions you might need to extend
the vformat plugin. Check how this is done for Evolution and kpepim3 ("KDE").
In this case just pass a objformat_sink_config like "VCARD_EXTENSION=akonadi" or so ...
With the code above you could discover and configure on the fly all available
akonadi resources.
Example: if someone has a LDAP-Contact resource supporting vCard 3.0 (prefered) and vcard2.1 and some file-
resource using vCard 2.1 and some webdav resource using vCard 3.0. And one Calendar as local-file
resource .. the result of the Resource configuration could look like this:
<Resources>
<Resource>
<Enabled>1</Enabled>
<Formats>
<Format>
<Name>vcard30</Name>
<Config>VCARD_EXTENSION=akonadi</Config>
</Format>
<Format>
<Name>vcard21</Name>
<Config>VCARD_EXTENSION=akonadi</Config>
</Formats>
<Name>Daniels LDAP Addressbook</Name>
<Preferred>vcard30</Preferred>
<ObjType>contact</ObjType>
<Url>akonadi:?collection=2</Url>
</Resource>
<Resource>
<Enabled>0</Enabled>
<Formats>
<Format>
<Name>vcard21</Name>
<Config>VCARD_EXTENSION=akonadi</Config>
</Formats>
<Name>Daniels File Addressbook</Name>
<ObjType>contact</ObjType>
<Path>/home/dgollub/vcard.txt</Path>
</Resource>
<Resource>
<Enabled>0</Enabled>
<Formats>
<Format>
<Name>vcard30</Name>
<Config>VCARD_EXTENSION=akonadi</Config>
</Formats>
<Name>Daniels Webdav Addressbook</Name>
<ObjType>contact</ObjType>
<Url>webdavs://foo/bar/lala.vcard</Url>
</Resource>
<Resource>
<Enabled>1</Enabled>
<Formats>
<Format>
<Name>vevent30</Name>
<Config>ICAL_EXTENSION=akonadi</Config>
</Formats>
<Name>Daniels File Calendar</Name>
<ObjType>event</ObjType>
<Path>/home/dgollub/cal.ical</Path>
</Resource>
</Resources>
Propaply you want to do assemble this within the OpenSync API.
Some notes which might be important:
You can discover as many resources as you want. But you can only enable one resource per object type.
You can't have in any plugin two resources enabled with the same objtype.
Hope that helps ...
Best Regards,
Daniel
--
Daniel Gollub Geschaeftsfuehrer: Ralph Dehner
Linux Consultant & Developer Unternehmenssitz: Vohburg
B1 Systems GmbH Amtsgericht: Ingolstadt
Mobil: +49-(0)-160 47 73 970 Handelsregister: HRB 3537
EMail: go...@b1... http://www.b1-systems.de
Adresse: B1 Systems GmbH, Osterfeldstraße 7, 85088 Vohburg
http://pgpkeys.pca.dfn.de/pks/lookup?op=get&search=0xED14B95C2F8CA78D
|