KDE 4.5 PyKDE API Reference
  • KDE's Python API
  • Overview
  • PyKDE Home
  • Sitemap
  • Contact Us
 

ResourceBase Class Reference

from PyKDE4.akonadi import *

Inherits: Akonadi.AgentBase → QObject
Namespace: Akonadi

Detailed Description

The base class for all Akonadi resources.

This class should be used as a base class by all resource agents, because it encapsulates large parts of the protocol between resource agent, agent manager and the Akonadi storage.

It provides many convenience methods to make implementing a new Akonadi resource agent as simple as possible.

<h4>How to write a resource</h4>

The following provides an overview of what you need to do to implement your own Akonadi resource. In the following, the term 'backend' refers to the entity the resource connects with Akonadi, be it a single file or a remote server.

To do: Complete this (online/offline state management)

<h5>Basic %Resource Framework</h5>

The following is needed to create a new resource: - A new class deriving from Akonadi.ResourceBase, implementing at least all pure-virtual methods, see below for further details. - call init() in your main() function. - a .desktop file similar to the following example

 [Desktop Entry]
 Encoding=UTF-8
 Name=My Akonadi Resource
 Type=AkonadiResource
 Exec=akonadi_my_resource
 Icon=my-icon

 X-Akonadi-MimeTypes=<supported-mimetypes>
 X-Akonadi-Capabilities=Resource
 X-Akonadi-Identifier=akonadi_my_resource

<h5>Handling PIM Items</h5>

To follow item changes in the backend, the following steps are necessary: - Implement retrieveItems() to synchronize all items in the given collection. If the backend supports incremental retrieval, implementing support for that is recommended to improve performance. - Convert the items provided by the backend to Akonadi items. This typically happens either in retrieveItems() if you retrieved the collection synchronously (not recommended for network backends) or in the result slot of the asynchronous retrieval job. Converting means to create Akonadi.Item objects for every retrieved item. It's very important that every object has its remote identifier set. - Call itemsRetrieved() or itemsRetrievedIncremental() respectively with the item objects created above. The Akonadi storage will then be updated automatically. Note that it is usually not necessary to manipulate any item in the Akonadi storage manually.

To fetch item data on demand, the method retrieveItem() needs to be reimplemented. Fetch the requested data there and call itemRetrieved() with the result item.

To write local changes back to the backend, you need to re-implement the following three methods: - itemAdded() - itemChanged() - itemRemoved() Note that these three functions don't get the full payload of the items by default, you need to change the item fetch scope of the change recorder to fetch the full payload. This can be expensive with big payloads, though.
Once you have handled changes in these methods call changeCommitted(). These methods are called whenever a local item related to this resource is added, modified or deleted. They are only called if the resource is online, otherwise all changes are recorded and replayed as soon the resource is online again.

<h5>Handling Collections</h5>

To follow collection changes in the backend, the following steps are necessary: - Implement retrieveCollections() to retrieve collections from the backend. If the backend supports incremental collections updates, implementing support for that is recommended to improve performance. - Convert the collections of the backend to Akonadi collections. This typically happens either in retrieveCollections() if you retrieved the collection synchronously (not recommended for network backends) or in the result slot of the asynchronous retrieval job. Converting means to create Akonadi.Collection objects for every retrieved collection. It's very important that every object has its remote identifier and its parent remote identifier set. - Call collectionsRetrieved() or collectionsRetrievedIncremental() respectively with the collection objects created above. The Akonadi storage will then be updated automatically. Note that it is usually not necessary to manipulate any collection in the Akonadi storage manually.

To write local collection changes back to the backend, you need to re-implement the following three methods: - collectionAdded() - collectionChanged() - collectionRemoved() Once you have handled changes in these methods call changeCommitted(). These methods are called whenever a local collection related to this resource is added, modified or deleted. They are only called if the resource is online, otherwise all changes are recorded and replayed as soon the resource is online again.

To do: Convenience base class for collection-less resources


Enumerations

SchedulePriority { Prepend, AfterChangeReplay, Append }

Signals

 nameChanged (QString name)
 synchronized ()

Methods

 __init__ (self, QString id)
 cancelTask (self)
 cancelTask (self, QString error)
 changeCommitted (self, Akonadi.Item item)
 changeCommitted (self, Akonadi.Collection collection)
 clearCache (self)
 collectionsRetrievalDone (self)
 collectionsRetrieved (self, [Akonadi.Collection] collections)
 collectionsRetrievedIncremental (self, [Akonadi.Collection] changedCollections, [Akonadi.Collection] removedCollections)
Akonadi.Collection currentCollection (self)
Akonadi.Item currentItem (self)
 deferTask (self)
 doSetOnline (self, bool online)
 itemRetrieved (self, Akonadi.Item item)
 itemsRetrievalDone (self)
 itemsRetrieved (self, [Akonadi.Item] items)
 itemsRetrievedIncremental (self, [Akonadi.Item] changedItems, [Akonadi.Item] removedItems)
QString name (self)
 retrieveCollections (self)
bool retrieveItem (self, Akonadi.Item item, QSet parts)
 retrieveItems (self, Akonadi.Collection collection)
 scheduleCustomTask (self, QObject receiver, QString method, QVariant argument, Akonadi.ResourceBase.SchedulePriority priority)
 setCollectionStreamingEnabled (self, bool enable)
 setHierarchicalRemoteIdentifiersEnabled (self, bool enable)
 setItemStreamingEnabled (self, bool enable)
 setName (self, QString name)
 setTotalItems (self, int amount)
 synchronize (self)
 synchronizeCollection (self, long id)
 synchronizeCollectionTree (self)
 taskDone (self)

Signal Documentation

nameChanged ( QString  name
)

This signal is emitted whenever the name of the resource has changed.

Parameters:
name  The new name of the resource.

Signal syntax:
QObject.connect(source, SIGNAL("nameChanged(const QString&)"), target_slot)
synchronized (   )

Emitted when a full synchronization has been completed.

Signal syntax:
QObject.connect(source, SIGNAL("synchronized()"), target_slot)

Method Documentation

__init__ (  self,
QString  id
)

Creates a base resource.

Parameters:
id  The instance id of the resource.

cancelTask (   self )

Stops the execution of the current task and continues with the next one. Additionally an error message is emitted.

cancelTask (  self,
QString  error
)

Stops the execution of the current task and continues with the next one. Additionally an error message is emitted.

changeCommitted (  self,
Akonadi.Item  item
)

Call whenever you have successfully handled or ignored a collection change notification.

This will update the remote identifier of collection if necessary, as well as any other collection attributes. This implicitly calls changeProcessed().

Parameters:
collection  The collection which changes have been handled.

changeCommitted (  self,
Akonadi.Collection  collection
)

Call whenever you have successfully handled or ignored a collection change notification.

This will update the remote identifier of collection if necessary, as well as any other collection attributes. This implicitly calls changeProcessed().

Parameters:
collection  The collection which changes have been handled.

clearCache (   self )

Call this method to remove all items and collections of the resource from the server cache.

The method should be used whenever the configuration of the resource has changed and therefor the cached items might not be valid any longer.

Since:
4.3

collectionsRetrievalDone (   self )

Call this method to indicate you finished synchronizing the collection tree.

This is not needed if you use the built in syncing without collection streaming and call collectionsRetrieved() or collectionRetrievedIncremental() instead. If collection streaming is enabled, call this method once all collections have been delivered using collectionsRetrieved() or collectionsRetrievedIncremental().

collectionsRetrieved (  self,
[Akonadi.Collection]  collections
)

Call this to supply the full folder tree retrieved from the remote server.

Parameters:
collections  A list of collections.

See also:
collectionsRetrievedIncremental()

collectionsRetrievedIncremental (  self,
[Akonadi.Collection]  changedCollections,
[Akonadi.Collection]  removedCollections
)

Call this to supply incrementally retrieved collections from the remote server.

Parameters:
changedCollections  Collections that have been added or changed.
removedCollections  Collections that have been deleted.

See also:
collectionsRetrieved()

Akonadi.Collection currentCollection (   self )

Returns the collection that is currently synchronized.

Akonadi.Item currentItem (   self )

Returns the item that is currently retrieved.

deferTask (   self )

Stops the execution of the current task and continues with the next one. The current task will be tried again later.

Since:
4.3

doSetOnline (  self,
bool  online
)

Inherited from AgentBase.

itemRetrieved (  self,
Akonadi.Item  item
)

Call this method from retrieveItem() once the result is available.

Parameters:
item  The retrieved item.

itemsRetrievalDone (   self )

Call this method to indicate you finished synchronizing the current collection.

This is not needed if you use the built in syncing without item streaming and call itemsRetrieved() or itemsRetrievedIncremental() instead. If item streaming is enabled, call this method once all items have been delivered using itemsRetrieved() or itemsRetrievedIncremental().

See also:
retrieveItems()

itemsRetrieved (  self,
[Akonadi.Item]  items
)

Call this method to supply the full collection listing from the remote server.

If the remote server supports incremental listing, it's strongly recommended to use itemsRetrievedIncremental() instead.

Parameters:
items  A list of items.

See also:
itemsRetrievedIncremental().

itemsRetrievedIncremental (  self,
[Akonadi.Item]  changedItems,
[Akonadi.Item]  removedItems
)

Call this method to supply incrementally retrieved items from the remote server.

Parameters:
changedItems  Items changed in the backend.
removedItems  Items removed from the backend.

QString name (   self )

Returns the name of the resource.

retrieveCollections (   self )
Abstract method:
This method is abstract and can be overridden but not called directly.

Retrieve the collection tree from the remote server and supply it via collectionsRetrieved() or collectionsRetrievedIncremental().

See also:
collectionsRetrieved(), collectionsRetrievedIncremental()

bool retrieveItem (  self,
Akonadi.Item  item,
QSet  parts
)
Abstract method:
This method is abstract and can be overridden but not called directly.

Retrieve a single item from the backend. The item to retrieve is provided as item. Add the requested payload parts and call itemRetrieved() when done.

Parameters:
item  The empty item whose payload should be retrieved. Use this object when delivering the result instead of creating a new item to ensure conflict detection will work.
parts  The item parts that should be retrieved.

Returns:
false if there is an immediate error when retrieving the item.
See also:
itemRetrieved()

retrieveItems (  self,
Akonadi.Collection  collection
)
Abstract method:
This method is abstract and can be overridden but not called directly.

Retrieve all (new/changed) items in collection collection. It is recommended to use incremental retrieval if the backend supports that and provide the result by calling itemsRetrievedIncremental(). If incremental retrieval is not possible, provide the full listing by calling itemsRetrieved( const Item.List& ). In any case, ensure that all items have a correctly set remote identifier to allow synchronizing with items already existing locally. In case you don't want to use the built-in item syncing code, store the retrieved items manually and call itemsRetrieved() once you are done.

Parameters:
collection  The collection whose items to retrieve.

See also:
itemsRetrieved( const Item.List& ), itemsRetrievedIncremental(), itemsRetrieved(), currentCollection()

scheduleCustomTask (  self,
QObject  receiver,
QString  method,
QVariant  argument,
Akonadi.ResourceBase.SchedulePriority  priority
)

Schedules a custom task in the internal scheduler. It will be queued with all other tasks such as change replays and retrieval requests and eventually executed by calling the specified method. With the priority parameter the time of execution of the Task can be influenced.

See also:
SchedulePriority

Parameters:
receiver  The object the slot should be called on.
method  The name of the method (and only the name, not signature, not SLOT(...) macro), that should be called to execute this task. The method has to be a slot and take a QVariant as argument.
argument  A QVariant argument passed to the method specified above. Use this to pass task parameters.
priority  Priority of the task. Use this to influence the position in the execution queue.

Since:
4.4

setCollectionStreamingEnabled (  self,
bool  enable
)

Enable collection streaming, that is collections don't have to be delivered at once as result of a retrieveCollections() call but can be delivered by multiple calls to collectionsRetrieved() or collectionsRetrievedIncremental(). When all collections have been retrieved, call collectionsRetrievalDone().

Parameters:
enable  true if collection streaming should be enabled, false by default

setHierarchicalRemoteIdentifiersEnabled (  self,
bool  enable
)

Indicate the use of hierarchical remote identifiers.

This means that it is possible to have two different items with the same remoteId in different Collections.

This should be called in the resource constructor as needed.

Since:
4.4

setItemStreamingEnabled (  self,
bool  enable
)

Enable item streaming. Item streaming is disabled by default.

Parameters:
enable  true if items are delivered in chunks rather in one big block.

setName (  self,
QString  name
)

This method is used to set the name of the resource.

setTotalItems (  self,
int  amount
)

Call this method when you want to use the itemsRetrieved() method in streaming mode and indicate the amount of items that will arrive that way.

Deprecated:
Use setItemStreamingEnabled( true ) + itemsRetrieved[Incremental]() + itemsRetrieved() instead.

synchronize (   self )

This method is called whenever the resource should start synchronize all data.

synchronizeCollection (  self,
long  id
)

This method is called whenever the collection with the given id shall be synchronized.

synchronizeCollectionTree (   self )

Refetches the Collections.

taskDone (   self )

Indicate that the current task is finished. Use this method from the slot called via scheduleCustomTaks(). As with all the other callbacks, make sure to either call taskDone() or cancelTask()/deferTask() on all exit paths, otherwise the resource will hang.

Since:
4.4


Enumeration Documentation

SchedulePriority

Describes the scheduling priority of a task that has been queued for execution.

See also:
scheduleCustomTask
Since:
4.4

Enumerator:
Prepend 
AfterChangeReplay 
Append 

  • Full Index

Modules

  • akonadi
  • dnssd
  • kdecore
  • kdeui
  • khtml
  • kio
  • knewstuff
  • kparts
  • kutils
  • nepomuk
  • phonon
  • plasma
  • polkitqt
  • solid
  • soprano
This documentation is maintained by Simon Edwards.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal