Development/Tutorials/PIM/ical: Difference between revisions

From KDE TechBase
No edit summary
(Mark for deletion)
 
(5 intermediate revisions by one other user not shown)
Line 1: Line 1:
{{Proposed_deletion|Insufficient and outdated information.}}
[http://en.wikipedia.org/wiki/ICalendar 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.
[http://en.wikipedia.org/wiki/ICalendar 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.


= Loading a calendar =
= Writing a calendar =
Here is the easiest test case: A program that loads /tmp/test.ics.
As a start, we will write a program that generates the calendar file /tmp/test.ics containing one todo named "test todo".


== CMakeLists.txt ==
== CMakeLists.txt ==
Line 21: Line 23:
<pre>
<pre>
/*
/*
This is a test case for KDE's iCalendar functionality.
This is a demo/test case for KDE's iCalendar functionality.
(c) 2008 by Thorsten Staerk
(c) 2008-2011 by Thorsten Staerk
*/
*/


Line 28: Line 30:
#include <kapplication.h>
#include <kapplication.h>
#include <kaboutdata.h>
#include <kaboutdata.h>
#include <kmessagebox.h>
#include <kcmdlineargs.h>
#include <kcmdlineargs.h>
#include <KMainWindow>
#include <KMainWindow>
Line 47: Line 48:
   cal=resource;
   cal=resource;
   cal->load();
   cal->load();
  KCal::Todo* todo1 = new KCal::Todo();
  todo1->setSummary("test todo");
  cal->addTodo(todo1);
   KABC::Lock *lock = cal->lock();
   KABC::Lock *lock = cal->lock();
   cal->save();
   cal->save();
Line 55: Line 59:
== build and run it ==
== build and run it ==
  cmake . && make -j8 && ./kdestart
  cmake . && make -j8 && ./kdestart
== result ==
If we delete /tmp/test.ics and then run the program, the file will look about like this:
# cat /tmp/test.ics
BEGIN:VCALENDAR
PRODID:-//K Desktop Environment//NONSGML libkcal 4.3//EN
VERSION:2.0
BEGIN:VTODO
DTSTAMP:20110926T090835Z
CREATED:20110926T090835Z
UID:libkcal-1018318974.1052
LAST-MODIFIED:20110926T090835Z
SUMMARY:test todo
PERCENT-COMPLETE:0
END:VTODO
END:VCALENDAR
However, the UID is calculated by random. If we run the program several times, it will append new todos, not overwrite any.
= events =
Now we will create an event in the calendar. The files are available here:
* [http://quickgit.kde.org/?p=kdeexamples.git&a=blob_plain&f=ical/event/main.cpp main.cpp]
* [http://quickgit.kde.org/?p=kdeexamples.git&a=blob_plain&f=ical/event/CMakeLists.txt CMakeLists.txt]

Latest revision as of 14:28, 31 May 2019

 
Proposed for Deletion
This page has been proposed for deletion for the following reason:

Insufficient and outdated information.

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.

Writing a calendar

As a start, we will write a program that generates the calendar file /tmp/test.ics containing one todo named "test todo".

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

result

If we delete /tmp/test.ics and then run the program, the file will look about like this:

# cat /tmp/test.ics
BEGIN:VCALENDAR
PRODID:-//K Desktop Environment//NONSGML libkcal 4.3//EN
VERSION:2.0
BEGIN:VTODO
DTSTAMP:20110926T090835Z
CREATED:20110926T090835Z
UID:libkcal-1018318974.1052
LAST-MODIFIED:20110926T090835Z
SUMMARY:test todo
PERCENT-COMPLETE:0
END:VTODO
END:VCALENDAR

However, the UID is calculated by random. If we run the program several times, it will append new todos, not overwrite any.

events

Now we will create an event in the calendar. The files are available here: