Development/Tutorials/PIM/ical

< Development‎ | Tutorials
Revision as of 10:08, 26 September 2011 by Tstaerk (Talk | contribs)

Jump to: navigation, search

iCal is a standardized data format for storing appointments, events and todos in a calendar file. It is being used by Apple and Outlook. Using the KDE libraries you can read and write files in this format.

Contents

Loading a calendar

Here is the easiest test case: A program that loads /tmp/test.ics.

CMakeLists.txt

PROJECT( kde4start )
FIND_PACKAGE(KDE4 REQUIRED)
INCLUDE_DIRECTORIES( ${KDE4_INCLUDES} . )


SET(kde4startSources main.cpp )

KDE4_ADD_EXECUTABLE(kde4start ${kde4startSources} )

TARGET_LINK_LIBRARIES(kde4start ${KDE4_KDEUI_LIBS} ${KDE4_KCAL_LIBS} ${KDE4_KPARTS_LIBS} kdepim kcal_resourceremote )

main.cpp

/*
This is a demo/test case for KDE's iCalendar functionality.
(c) 2008-2011 by Thorsten Staerk
*/

#include <QString>
#include <kapplication.h>
#include <kaboutdata.h>
#include <kcmdlineargs.h>
#include <KMainWindow>
#include <kcal/resourcecalendar.h>
#include <kcal/resourcecached.h>
#include <kcal/resourcelocal.h>

int main (int argc, char *argv[])
{
  const QByteArray& ba=QByteArray("test");
  const KLocalizedString name=ki18n("myName");
  KAboutData aboutData( ba, ba, name, ba, name);
  KCmdLineArgs::init( argc, argv, &aboutData );
  KApplication khello;
  KCal::ResourceCalendar* cal;
  KCal::ResourceCached* resource;
  resource=new KCal::ResourceLocal("/tmp/test.ics");
  cal=resource;
  cal->load();
  KCal::Todo* todo1 = new KCal::Todo();
  todo1->setSummary("test todo");
  cal->addTodo(todo1);
  KABC::Lock *lock = cal->lock();
  cal->save();
  lock->unlock();
}

build and run it

cmake . && make -j8 && ./kdestart

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V.Legal