[Kde-pim] How to store events to the default calendar?

Friedrich W. H. Kossebau kossebau at kde.org
Sun Oct 13 23:58:26 BST 2013


Hi,

I want to create some generated events to the default calendar, at least as 
set in KOrganizer.

Now I am wondering:

Q1: Is there such a concept as a default calendar (=resource?) outside of 
KOrganizer, so queryable from Akonadi?

Q2: Is there a better way to get the default calendar and insert the event 
than below?

--- 8< ---
	// first query for all event collections
	Akonadi::CollectionFetchJob *collectionFetchJob =
		new Akonadi::CollectionFetchJob(Collection::root(),
			CollectionFetchJob::FirstLevel);
	collectionFetchJob->fetchScope().setContentMimeTypes(
		QStringList() << KCalCore::Event::mimeType());
	connect(
		collectionFetchJob,
 		SIGNAL(collectionsReceived(Akonadi::Collection::List)),
		SLOT(onCollectionsReceived(Akonadi::Collection::List)));

	[...]

	// in onCollectionsReceived(...):
	// check for create-able (and default, if possible, otherwise first)
	// collection.rights() & Akonadi::Collection::CanCreateItem

	// insert the event
	Akonadi::Item item;
	item.setPayload<KCalCore::Event::Ptr>(event);
	item.setMimeType(event->mimeType());

	Akonadi::ItemCreateJob *itemCreateJob =
		new Akonadi::ItemCreateJob(item, collection);
	connect(itemCreateJob, SIGNAL(result(KJob*)),
		SLOT(onCreateJobFinished(KJob*)));
--- 8< ---

Ideally the code should work with KDEPIM 4.7 or similar.

Cheers
Friedrich
_______________________________________________
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