[Kde-pim] Re: Akonadi resource: How to update item if backend data changed

Kevin Krammer kevin.krammer at gmx.at
Thu Jun 9 08:50:35 BST 2011


On Wednesday, 2011-06-08, rgruber at users.sourceforge.net wrote:
> Hi!
> 
> First of all thanks for the replies, although I'm a bit more confused now
> :(
> 
> At first David Jarvie said one must use ItemModifyJob. But I thought
> ItemModifyJob is ment for external programs that want to modify an Item in
> the Akonadi store. Like e.g. a program might use it to change the details
> of a contact or set a different start time for an event. Wouldn't a
> ItemModifyJob result in a call to itemChanged() of my resource? Because
> this definately must not happen. Because in itemChanged() I would need
> some code that tries to change the data on the backend.

ItemModifyJob can be used by clients to change an item (payload, attributes, 
flags, etc) in Akonadi. Any program connecting to Akonadi server is a client 
of it, i.e. this includes resources.

Regarding your valid concern about this resulting in an itemChanged() 
notification: each connection (session) to Akonadi has an identifier and 
Akonadi does not notify the owner of a connection about its own changes.
So in the case of a resource using ItemModifyJob, all other clients will be 
notified about the change but the resource will not.

(this is actually controllable, the Akonadi::Monitor can be told to ignore 
changes from certain resources, by default this is true for resources 
themselves).

> Kevin Krammer suggested to call synchronize() or synchronizeCollection().
> But I'm already inside of retrieveItems(), calling synchronize() will only
> recall retrieveItems(). And I would still have the problem that
> retrieveItem() will not be called for the changed items.

Misunderstanding on my part, sorry. I thought you were asking about modifying 
items outside of operations requested by Akonadi server.
In your case you simply put modified items into the list that means "new or 
changed" items.

I think the piece you are missing here is telling Akonadi that a cached data 
of an item should be invalidated.
Assuming that your backend has some kind of versioning for items (e.g. 
modification timestamp), have a look at Item::setRemoteRevision().

Like the remote ID this is a property over which a resource has full and 
exclusive control, so it doesn't have to have any meaning outside of your 
resource, Akonadi will simply check for string difference,

> The API doc of itemsRetrievedIncremental() for the first parameter says
> "Items changed in the backend". So is this wrong? Should it say "New items
> in the backend" instead?

The docs are correct, it works for both kinds of items.

> If I really must use ItemModifyJob to update, I would need to retrieve all
> the data for the item inside of the retrieveItems() method. What is the
> retrieveItem() for then? Only to fetch data for new items?

As explained above this would be for a different use case, i.e. when the 
backend has notification capabiltities and resource wants to react to those 
and modify individual items as a result of such a backend notification.

> PS: I already checked out the openchange akonadi resource from playground a
> while ago. Unfortunately it's in a bad state. I was not even able to
> compile it with the latest libmapi/libmapi++ that kubuntu come with. After
> I brought it to compile it instantly crashed when trying to synchronize
> it.

I see, just wanted to make sure you are aware of previous efforts.

Cheers,
Kevin

-- 
Kevin Krammer, KDE developer, xdg-utils developer
KDE user support, developer mentoring
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kde-pim/attachments/20110609/dfb5c6d9/attachment.sig>
-------------- next part --------------
_______________________________________________
KDE PIM mailing list kde-pim at kde.org
https://mail.kde.org/mailman/listinfo/kde-pim
KDE PIM home page at http://pim.kde.org/


More information about the kde-pim mailing list