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

Sergio Martins iamsergio at gmail.com
Mon Oct 14 08:43:45 BST 2013


Hi

On Monday, October 14, 2013 00:58:26 Friedrich W. H. Kossebau wrote:
> 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?

The method to call is CalendarSupport::KCalPrefs::instance()-
>defaultCalendarId(), unfortunately this is not in kdepimlibs, so you can't 
call it ( it's in kdepim/calendarsupport/kcalprefs.h ). We could move it to 
kdepimlibs though.

as a workaround ou could just open the config file directly and read the 
setting.


> 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.


Akonadi::IncidenceChanger is easier to use and provides more calendaring 
features, like sending invitations when creating events or recurrence stuff. 
You'll have to use 4.11 though.


Regards,
Sérgio Martins
_______________________________________________
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