Namespaces
Variants
Actions
Revision as of 04:16, 11 October 2012 by hamishwillee (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Create calendar events with alarms with Harmattan platform API

Jump to: navigation, search

This article explains how to create a calendar event with an alarm using the platform SDK for Harmattan. This is an alternative to the Qt Mobility Calendar API (1.2.1), that at time of writing has issues with associating alarms with calendar events.

Article Metadata

Tested with
Article
Created: hugolima (30 Nov 2011)
Last edited: hamishwillee (11 Oct 2012)

To use the platform SDK you will need to setup a Linux environment because the SDK only runs on Linux. For this you can follow the instructions at http://harmattan-dev.nokia.com/platform-sdk/.

The Harmattan platform calendar package is based on KDE's KCalendar with some modifications to allow for a SQLite persistance layer, to interface with this native functionality there is a lib (shared object) called "mkcal" that you can link to in your code.

To use mkcal lib you'll need to make the following modifications to your project file:

contains(MEEGO_EDITION,harmattan) {
LIBS += -ldl /scratchbox/users/<user>/targets/<arch>/usr/lib/libmkcal.so
LIBS += -ldl /scratchbox/users/<user>/targets/<arch>/usr/lib/libkcalcoren.so
}

Replace <user> with the name of the scratchbox user and <arch> with "HARMATTAN_X86" if you are compiling for scratchbox or "HARMATTAN_ARMEL" if compiling for the emulator or for the device.

And also add the following credentials to your project aegis manifest file (project_folder/debian/project_name.aegis):

  <aegis>
<request policy="add">
<credential name="GRP::calendar" />
<credential name="TrackerWriteAccess" />
<credential name="TrackerReadAccess" />
<for path="path_to_project" />
</request>
</aegis>

The following is an example code to demonstrate the use of the API:

    #include "mkcal/extendedcalendar.h"
#include "mkcal/extendedstorage.h"
#include "mkcal/notebook.h"
#include "kcalcoren/event.h"
#include "kcalcoren/alarm.h"
#include "kcalcoren/kdatetime.h"
#include "kcalcoren/duration.h"
#include <QSharedPointer>
#include <QLatin1String>
 
using namespace KCalCore;
using namespace mKCal;
 
QString CalWrapper::setAlarm(QDateTime start, QDateTime end, QString message)
{
#if defined(MEEGO_VERSION)
ExtendedCalendar::Ptr calendar = ExtendedCalendar::Ptr ( new ExtendedCalendar( KDateTime::Spec::LocalZone() ) );
ExtendedStorage::Ptr storage = calendar->defaultStorage(calendar);
Event::Ptr event;
Alarm::Ptr alarm;
 
storage->open();
storage->load(start.date(), end.date());
 
event=Event::Ptr(new Event());
event->setDtStart(KDateTime(start));
event->setDescription(message);
event->setSummary(message);
 
alarm=Alarm::Ptr(new Alarm(event.data()));
alarm->setDisplayAlarm(message);
alarm->setEnabled(true);
alarm->setRepeatCount(1);
alarm->setStartOffset(Duration(0));
alarm->setTime(KDateTime(start));
alarm->setEndOffset(Duration(0));
 
event->addAlarm(alarm);
 
 
// the second parameter refers to the personal calendar uid
calendar->addEvent(event, "11111111-2222-3333-4444-555555555555");
calendar->save();
 
storage->save();
storage->close();
 
qDebug() << "CalWrapper::setAlarm:Alarm set";
return event->uid();
#else
return "";
#endif
}
 
void CalWrapper::removeAlarm(QString key, QDate date)
{
#if defined(MEEGO_VERSION)
ExtendedCalendar::Ptr calendar = ExtendedCalendar::Ptr ( new ExtendedCalendar( KDateTime::Spec::LocalZone() ) );
ExtendedStorage::Ptr storage = calendar->defaultStorage(calendar);
Event::Ptr event;
 
storage->open();
storage->load(date.addDays(-15), date.addDays(15));
 
event=calendar->event(key);
if (event.data()==NULL)
qDebug() << "CalWrapper::removeAlarm:Event doesnt exist";
else
{
calendar->deleteEvent(event);
calendar->save();
storage->save();
 
qDebug() << "CalWrapper::Alarm removed";
}
 
storage->close();
#else
#endif
}

You can also check the Qt Mobility bug report, at https://bugreports.qt-project.org/browse/QTMOBILITY-1890, for updates on this issue.

All tests were done on an Nokia N9.

Related Articles

Adding event to native calender application on Meego Harmattan using QOrganizer API

235 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved