summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSandro Knauß <mail@sandroknauss.de>2015-02-19 12:31:41 (GMT)
committerSandro Knauß <mail@sandroknauss.de>2015-02-19 13:11:09 (GMT)
commit5c549ff13cb20de2482747decb789a2cd4761ec3 (patch)
tree7635b4c603dc7301e122c35be23953f2d6b977f8
parentdf8746790080a39099bce4330bc117b593d042a2 (diff)
downloadlibcalendaring-5c549ff13cb20de2482747decb789a2cd4761ec3.tar.gz
copy from kdepimlibs 4.13.0.1
-rw-r--r--kcalcore/alarm.cpp1085
-rw-r--r--kcalcore/alarm.h120
-rw-r--r--kcalcore/attachment.cpp204
-rw-r--r--kcalcore/attachment.h62
-rw-r--r--kcalcore/attendee.cpp296
-rw-r--r--kcalcore/attendee.h136
-rw-r--r--kcalcore/calendar.cpp1960
-rw-r--r--kcalcore/calendar.h437
-rw-r--r--kcalcore/duration.cpp190
-rw-r--r--kcalcore/duration.h106
-rw-r--r--kcalcore/freebusyperiod.cpp94
-rw-r--r--kcalcore/freebusyperiod.h63
-rw-r--r--kcalcore/icalformat_p.cpp4828
-rw-r--r--kcalcore/icalformat_p.h162
-rw-r--r--kcalcore/incidence.cpp1351
-rw-r--r--kcalcore/incidence.h225
-rw-r--r--kcalcore/incidencebase.cpp739
-rw-r--r--kcalcore/incidencebase.h288
-rw-r--r--kcalcore/memorycalendar.cpp1106
-rw-r--r--kcalcore/memorycalendar.h272
-rw-r--r--kcalcore/recurrence.cpp1986
-rw-r--r--kcalcore/recurrence.h156
-rw-r--r--kcalcore/recurrencerule.cpp3098
-rw-r--r--kcalcore/recurrencerule.h139
24 files changed, 10133 insertions, 8970 deletions
diff --git a/kcalcore/alarm.cpp b/kcalcore/alarm.cpp
index b23af98..f2db8c2 100644
--- a/kcalcore/alarm.cpp
+++ b/kcalcore/alarm.cpp
@@ -34,6 +34,8 @@
#include "duration.h"
#include "incidence.h"
+#include <QTime>
+
using namespace KCalCore;
/**
@@ -43,35 +45,35 @@ using namespace KCalCore;
//@cond PRIVATE
class KCalCore::Alarm::Private
{
- public:
+public:
Private()
- : mParent( 0 ),
- mType( Alarm::Invalid ),
- mAlarmSnoozeTime( 5 ),
- mAlarmRepeatCount( 0 ),
- mEndOffset( false ),
- mHasTime( false ),
- mAlarmEnabled( false ),
- mHasLocationRadius ( false ),
- mLocationRadius ( 0 )
+ : mParent(0),
+ mType(Alarm::Invalid),
+ mAlarmSnoozeTime(5),
+ mAlarmRepeatCount(0),
+ mEndOffset(false),
+ mHasTime(false),
+ mAlarmEnabled(false),
+ mHasLocationRadius(false),
+ mLocationRadius(0)
{}
- Private( const Private &other )
- : mParent( other.mParent ),
- mType( other.mType ),
- mDescription( other.mDescription ),
- mFile( other.mFile ),
- mMailSubject( other.mMailSubject ),
- mMailAttachFiles( other.mMailAttachFiles ),
- mMailAddresses( other.mMailAddresses ),
- mAlarmTime( other.mAlarmTime ),
- mAlarmSnoozeTime( other.mAlarmSnoozeTime ),
- mAlarmRepeatCount( other.mAlarmRepeatCount ),
- mOffset( other.mOffset ),
- mEndOffset( other.mEndOffset ),
- mHasTime( other.mHasTime ),
- mAlarmEnabled( other.mAlarmEnabled ),
- mHasLocationRadius( other.mHasLocationRadius ),
- mLocationRadius( other.mLocationRadius )
+ Private(const Private &other)
+ : mParent(other.mParent),
+ mType(other.mType),
+ mDescription(other.mDescription),
+ mFile(other.mFile),
+ mMailSubject(other.mMailSubject),
+ mMailAttachFiles(other.mMailAttachFiles),
+ mMailAddresses(other.mMailAddresses),
+ mAlarmTime(other.mAlarmTime),
+ mAlarmSnoozeTime(other.mAlarmSnoozeTime),
+ mAlarmRepeatCount(other.mAlarmRepeatCount),
+ mOffset(other.mOffset),
+ mEndOffset(other.mEndOffset),
+ mHasTime(other.mHasTime),
+ mAlarmEnabled(other.mAlarmEnabled),
+ mHasLocationRadius(other.mHasLocationRadius),
+ mLocationRadius(other.mLocationRadius)
{}
Incidence *mParent; // the incidence which this alarm belongs to
@@ -85,12 +87,12 @@ class KCalCore::Alarm::Private
KDateTime mAlarmTime;// time at which to trigger the alarm
Duration mAlarmSnoozeTime; // how long after alarm to snooze before
- // triggering again
+ // triggering again
int mAlarmRepeatCount;// number of times for alarm to repeat
- // after the initial time
+ // after the initial time
Duration mOffset; // time relative to incidence DTSTART
- // to trigger the alarm
+ // to trigger the alarm
bool mEndOffset; // if true, mOffset relates to DTEND, not DTSTART
bool mHasTime; // use mAlarmTime, not mOffset
bool mAlarmEnabled;
@@ -100,743 +102,780 @@ class KCalCore::Alarm::Private
};
//@endcond
-Alarm::Alarm( Incidence *parent ) : d( new KCalCore::Alarm::Private )
+Alarm::Alarm(Incidence *parent) : d(new KCalCore::Alarm::Private)
{
- d->mParent = parent;
+ d->mParent = parent;
}
-Alarm::Alarm( const Alarm &other ) :
- CustomProperties( other ), d( new KCalCore::Alarm::Private( *other.d ) )
+Alarm::Alarm(const Alarm &other) :
+ CustomProperties(other), d(new KCalCore::Alarm::Private(*other.d))
{
}
Alarm::~Alarm()
{
- delete d;
+ delete d;
}
-Alarm &Alarm::operator=( const Alarm &a )
+Alarm &Alarm::operator=(const Alarm &a)
{
- if ( &a != this ) {
- d->mParent = a.d->mParent;
- d->mType = a.d->mType;
- d->mDescription = a.d->mDescription;
- d->mFile = a.d->mFile;
- d->mMailAttachFiles = a.d->mMailAttachFiles;
- d->mMailAddresses = a.d->mMailAddresses;
- d->mMailSubject = a.d->mMailSubject;
- d->mAlarmSnoozeTime = a.d->mAlarmSnoozeTime;
- d->mAlarmRepeatCount = a.d->mAlarmRepeatCount;
- d->mAlarmTime = a.d->mAlarmTime;
- d->mOffset = a.d->mOffset;
- d->mEndOffset = a.d->mEndOffset;
- d->mHasTime = a.d->mHasTime;
- d->mAlarmEnabled = a.d->mAlarmEnabled;
- }
+ if (&a != this) {
+ d->mParent = a.d->mParent;
+ d->mType = a.d->mType;
+ d->mDescription = a.d->mDescription;
+ d->mFile = a.d->mFile;
+ d->mMailAttachFiles = a.d->mMailAttachFiles;
+ d->mMailAddresses = a.d->mMailAddresses;
+ d->mMailSubject = a.d->mMailSubject;
+ d->mAlarmSnoozeTime = a.d->mAlarmSnoozeTime;
+ d->mAlarmRepeatCount = a.d->mAlarmRepeatCount;
+ d->mAlarmTime = a.d->mAlarmTime;
+ d->mOffset = a.d->mOffset;
+ d->mEndOffset = a.d->mEndOffset;
+ d->mHasTime = a.d->mHasTime;
+ d->mAlarmEnabled = a.d->mAlarmEnabled;
+ }
- return *this;
+ return *this;
}
-bool Alarm::operator==( const Alarm &rhs ) const
+static bool compareMailAddresses(const Person::List &list1, const Person::List &list2)
{
- if ( d->mType != rhs.d->mType ||
- d->mAlarmSnoozeTime != rhs.d->mAlarmSnoozeTime ||
- d->mAlarmRepeatCount != rhs.d->mAlarmRepeatCount ||
- d->mAlarmEnabled != rhs.d->mAlarmEnabled ||
- d->mHasTime != rhs.d->mHasTime ||
- d->mHasLocationRadius != rhs.d->mHasLocationRadius ||
- d->mLocationRadius != rhs.d->mLocationRadius ) {
+ if (list1.count() == list2.count()) {
+ for (int i=0; i<list1.count(); ++i) {
+ if (*list1.at(i) != *list2.at(i)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
return false;
- }
+}
- if ( d->mHasTime ) {
- if ( d->mAlarmTime != rhs.d->mAlarmTime ) {
- return false;
+bool Alarm::operator==(const Alarm &rhs) const
+{
+ if (d->mType != rhs.d->mType ||
+ d->mAlarmSnoozeTime != rhs.d->mAlarmSnoozeTime ||
+ d->mAlarmRepeatCount != rhs.d->mAlarmRepeatCount ||
+ d->mAlarmEnabled != rhs.d->mAlarmEnabled ||
+ d->mHasTime != rhs.d->mHasTime ||
+ d->mHasLocationRadius != rhs.d->mHasLocationRadius ||
+ d->mLocationRadius != rhs.d->mLocationRadius) {
+ return false;
}
- } else {
- if ( d->mOffset != rhs.d->mOffset || d->mEndOffset != rhs.d->mEndOffset ) {
- return false;
+
+ if (d->mHasTime) {
+ if (d->mAlarmTime != rhs.d->mAlarmTime) {
+ return false;
+ }
+ } else {
+ if (d->mOffset != rhs.d->mOffset || d->mEndOffset != rhs.d->mEndOffset) {
+ return false;
+ }
}
- }
- switch ( d->mType ) {
+ switch (d->mType) {
case Display:
- return d->mDescription == rhs.d->mDescription;
+ return d->mDescription == rhs.d->mDescription;
case Email:
- return d->mDescription == rhs.d->mDescription &&
- d->mMailAttachFiles == rhs.d->mMailAttachFiles &&
- d->mMailAddresses == rhs.d->mMailAddresses &&
- d->mMailSubject == rhs.d->mMailSubject;
+ return d->mDescription == rhs.d->mDescription &&
+ d->mMailAttachFiles == rhs.d->mMailAttachFiles &&
+ compareMailAddresses(d->mMailAddresses, rhs.d->mMailAddresses) &&
+ d->mMailSubject == rhs.d->mMailSubject;
case Procedure:
- return d->mFile == rhs.d->mFile &&
- d->mDescription == rhs.d->mDescription;
+ return d->mFile == rhs.d->mFile &&
+ d->mDescription == rhs.d->mDescription;
case Audio:
- return d->mFile == rhs.d->mFile;
+ return d->mFile == rhs.d->mFile;
case Invalid:
- break;
- }
- return false;
+ break;
+ }
+ return false;
}
-bool Alarm::operator!=( const Alarm &a ) const
+bool Alarm::operator!=(const Alarm &a) const
{
- return !operator==( a );
+ return !operator==(a);
}
-void Alarm::setType( Alarm::Type type )
+void Alarm::setType(Alarm::Type type)
{
- if ( type == d->mType ) {
- return;
- }
+ if (type == d->mType) {
+ return;
+ }
- if ( d->mParent ) {
- d->mParent->update();
- }
- switch ( type ) {
+ if (d->mParent) {
+ d->mParent->update();
+ }
+ switch (type) {
case Display:
- d->mDescription = "";
- break;
+ d->mDescription = QLatin1String("");
+ break;
case Procedure:
- d->mFile = d->mDescription = "";
- break;
+ d->mFile = d->mDescription = QLatin1String("");
+ break;
case Audio:
- d->mFile = "";
- break;
+ d->mFile = QLatin1String("");
+ break;
case Email:
- d->mMailSubject = d->mDescription = "";
- d->mMailAddresses.clear();
- d->mMailAttachFiles.clear();
- break;
+ d->mMailSubject = d->mDescription = QLatin1String("");
+ d->mMailAddresses.clear();
+ d->mMailAttachFiles.clear();
+ break;
case Invalid:
- break;
+ break;
default:
- if ( d->mParent ) {
- d->mParent->updated(); // not really
- }
- return;
- }
- d->mType = type;
- if ( d->mParent ) {
- d->mParent->updated();
- }
+ if (d->mParent) {
+ d->mParent->updated(); // not really
+ }
+ return;
+ }
+ d->mType = type;
+ if (d->mParent) {
+ d->mParent->updated();
+ }
}
Alarm::Type Alarm::type() const
{
- return d->mType;
-}
-
-void Alarm::setAudioAlarm( const QString &audioFile )
-{
- if ( d->mParent ) {
- d->mParent->update();
- }
- d->mType = Audio;
- d->mFile = audioFile;
- if ( d->mParent ) {
- d->mParent->updated();
- }
+ return d->mType;
}
-void Alarm::setAudioFile( const QString &audioFile )
+void Alarm::setAudioAlarm(const QString &audioFile)
{
- if ( d->mType == Audio ) {
- if ( d->mParent ) {
- d->mParent->update();
+ if (d->mParent) {
+ d->mParent->update();
}
+ d->mType = Audio;
d->mFile = audioFile;
- if ( d->mParent ) {
- d->mParent->updated();
+ if (d->mParent) {
+ d->mParent->updated();
}
- }
}
-QString Alarm::audioFile() const
+void Alarm::setAudioFile(const QString &audioFile)
{
- return ( d->mType == Audio ) ? d->mFile : QString();
+ if (d->mType == Audio) {
+ if (d->mParent) {
+ d->mParent->update();
+ }
+ d->mFile = audioFile;
+ if (d->mParent) {
+ d->mParent->updated();
+ }
+ }
}
-void Alarm::setProcedureAlarm( const QString &programFile,
- const QString &arguments )
+QString Alarm::audioFile() const
{
- if ( d->mParent ) {
- d->mParent->update();
- }
- d->mType = Procedure;
- d->mFile = programFile;
- d->mDescription = arguments;
- if ( d->mParent ) {
- d->mParent->updated();
- }
+ return (d->mType == Audio) ? d->mFile : QString();
}
-void Alarm::setProgramFile( const QString &programFile )
+void Alarm::setProcedureAlarm(const QString &programFile,
+ const QString &arguments)
{
- if ( d->mType == Procedure ) {
- if ( d->mParent ) {
- d->mParent->update();
+ if (d->mParent) {
+ d->mParent->update();
}
+ d->mType = Procedure;
d->mFile = programFile;
- if ( d->mParent ) {
- d->mParent->updated();
+ d->mDescription = arguments;
+ if (d->mParent) {
+ d->mParent->updated();
+ }
+}
+
+void Alarm::setProgramFile(const QString &programFile)
+{
+ if (d->mType == Procedure) {
+ if (d->mParent) {
+ d->mParent->update();
+ }
+ d->mFile = programFile;
+ if (d->mParent) {
+ d->mParent->updated();
+ }
}
- }
}
QString Alarm::programFile() const
{
- return ( d->mType == Procedure ) ? d->mFile : QString();
+ return (d->mType == Procedure) ? d->mFile : QString();
}
-void Alarm::setProgramArguments( const QString &arguments )
+void Alarm::setProgramArguments(const QString &arguments)
{
- if ( d->mType == Procedure ) {
- if ( d->mParent ) {
- d->mParent->update();
- }
- d->mDescription = arguments;
- if ( d->mParent ) {
- d->mParent->updated();
+ if (d->mType == Procedure) {
+ if (d->mParent) {
+ d->mParent->update();
+ }
+ d->mDescription = arguments;
+ if (d->mParent) {
+ d->mParent->updated();
+ }
}
- }
}
QString Alarm::programArguments() const
{
- return ( d->mType == Procedure ) ? d->mDescription : QString();
+ return (d->mType == Procedure) ? d->mDescription : QString();
}
-void Alarm::setEmailAlarm( const QString &subject, const QString &text,
- const Person::List &addressees,
- const QStringList &attachments )
+void Alarm::setEmailAlarm(const QString &subject, const QString &text,
+ const Person::List &addressees,
+ const QStringList &attachments)
{
- if ( d->mParent ) {
- d->mParent->update();
- }
- d->mType = Email;
- d->mMailSubject = subject;
- d->mDescription = text;
- d->mMailAddresses = addressees;
- d->mMailAttachFiles = attachments;
- if ( d->mParent ) {
- d->mParent->updated();
- }
+ if (d->mParent) {
+ d->mParent->update();
+ }
+ d->mType = Email;
+ d->mMailSubject = subject;
+ d->mDescription = text;
+ d->mMailAddresses = addressees;
+ d->mMailAttachFiles = attachments;
+ if (d->mParent) {
+ d->mParent->updated();
+ }
}
-void Alarm::setMailAddress( const Person::Ptr &mailAddress )
+void Alarm::setMailAddress(const Person::Ptr &mailAddress)
{
- if ( d->mType == Email ) {
- if ( d->mParent ) {
- d->mParent->update();
- }
- d->mMailAddresses.clear();
- d->mMailAddresses.append( mailAddress );
- if ( d->mParent ) {
- d->mParent->updated();
+ if (d->mType == Email) {
+ if (d->mParent) {
+ d->mParent->update();
+ }
+ d->mMailAddresses.clear();
+ d->mMailAddresses.append(mailAddress);
+ if (d->mParent) {
+ d->mParent->updated();
+ }
}
- }
}
-void Alarm::setMailAddresses( const Person::List &mailAddresses )
+void Alarm::setMailAddresses(const Person::List &mailAddresses)
{
- if ( d->mType == Email ) {
- if ( d->mParent ) {
- d->mParent->update();
- }
- d->mMailAddresses += mailAddresses;
- if ( d->mParent ) {
- d->mParent->updated();
+ if (d->mType == Email) {
+ if (d->mParent) {
+ d->mParent->update();
+ }
+ d->mMailAddresses += mailAddresses;
+ if (d->mParent) {
+ d->mParent->updated();
+ }
}
- }
}
-void Alarm::addMailAddress( const Person::Ptr &mailAddress )
+void Alarm::addMailAddress(const Person::Ptr &mailAddress)
{
- if ( d->mType == Email ) {
- if ( d->mParent ) {
- d->mParent->update();
- }
- d->mMailAddresses.append( mailAddress );
- if ( d->mParent ) {
- d->mParent->updated();
+ if (d->mType == Email) {
+ if (d->mParent) {
+ d->mParent->update();
+ }
+ d->mMailAddresses.append(mailAddress);
+ if (d->mParent) {
+ d->mParent->updated();
+ }
}
- }
}
Person::List Alarm::mailAddresses() const
{
- return ( d->mType == Email ) ? d->mMailAddresses : Person::List();
+ return (d->mType == Email) ? d->mMailAddresses : Person::List();
}
-void Alarm::setMailSubject( const QString &mailAlarmSubject )
+void Alarm::setMailSubject(const QString &mailAlarmSubject)
{
- if ( d->mType == Email ) {
- if ( d->mParent ) {
- d->mParent->update();
- }
- d->mMailSubject = mailAlarmSubject;
- if ( d->mParent ) {
- d->mParent->updated();
+ if (d->mType == Email) {
+ if (d->mParent) {
+ d->mParent->update();
+ }
+ d->mMailSubject = mailAlarmSubject;
+ if (d->mParent) {
+ d->mParent->updated();
+ }
}
- }
}
QString Alarm::mailSubject() const
{
- return ( d->mType == Email ) ? d->mMailSubject : QString();
+ return (d->mType == Email) ? d->mMailSubject : QString();
}
-void Alarm::setMailAttachment( const QString &mailAttachFile )
+void Alarm::setMailAttachment(const QString &mailAttachFile)
{
- if ( d->mType == Email ) {
- if ( d->mParent ) {
- d->mParent->update();
- }
- d->mMailAttachFiles.clear();
- d->mMailAttachFiles += mailAttachFile;
- if ( d->mParent ) {
- d->mParent->updated();
+ if (d->mType == Email) {
+ if (d->mParent) {
+ d->mParent->update();
+ }
+ d->mMailAttachFiles.clear();
+ d->mMailAttachFiles += mailAttachFile;
+ if (d->mParent) {
+ d->mParent->updated();
+ }
}
- }
}
-void Alarm::setMailAttachments( const QStringList &mailAttachFiles )
+void Alarm::setMailAttachments(const QStringList &mailAttachFiles)
{
- if ( d->mType == Email ) {
- if ( d->mParent ) {
- d->mParent->update();
- }
- d->mMailAttachFiles = mailAttachFiles;
- if ( d->mParent ) {
- d->mParent->updated();
+ if (d->mType == Email) {
+ if (d->mParent) {
+ d->mParent->update();
+ }
+ d->mMailAttachFiles = mailAttachFiles;
+ if (d->mParent) {
+ d->mParent->updated();
+ }
}
- }
}
-void Alarm::addMailAttachment( const QString &mailAttachFile )
+void Alarm::addMailAttachment(const QString &mailAttachFile)
{
- if ( d->mType == Email ) {
- if ( d->mParent ) {
- d->mParent->update();
- }
- d->mMailAttachFiles += mailAttachFile;
- if ( d->mParent ) {
- d->mParent->updated();
+ if (d->mType == Email) {
+ if (d->mParent) {
+ d->mParent->update();
+ }
+ d->mMailAttachFiles += mailAttachFile;
+ if (d->mParent) {
+ d->mParent->updated();
+ }
}
- }
}
QStringList Alarm::mailAttachments() const
{
- return ( d->mType == Email ) ? d->mMailAttachFiles : QStringList();
+ return (d->mType == Email) ? d->mMailAttachFiles : QStringList();
}
-void Alarm::setMailText( const QString &text )
+void Alarm::setMailText(const QString &text)
{
- if ( d->mType == Email ) {
- if ( d->mParent ) {
- d->mParent->update();
- }
- d->mDescription = text;
- if ( d->mParent ) {
- d->mParent->updated();
+ if (d->mType == Email) {
+ if (d->mParent) {
+ d->mParent->update();
+ }
+ d->mDescription = text;
+ if (d->mParent) {
+ d->mParent->updated();
+ }
}
- }
}
QString Alarm::mailText() const
{
- return ( d->mType == Email ) ? d->mDescription : QString();
+ return (d->mType == Email) ? d->mDescription : QString();
}
-void Alarm::setDisplayAlarm( const QString &text )
+void Alarm::setDisplayAlarm(const QString &text)
{
- if ( d->mParent ) {
- d->mParent->update();
- }
- d->mType = Display;
- if ( !text.isNull() ) {
- d->mDescription = text;
- }
- if ( d->mParent ) {
- d->mParent->updated();
- }
+ if (d->mParent) {
+ d->mParent->update();
+ }
+ d->mType = Display;
+ if (!text.isNull()) {
+ d->mDescription = text;
+ }
+ if (d->mParent) {
+ d->mParent->updated();
+ }
}
-void Alarm::setText( const QString &text )
+void Alarm::setText(const QString &text)
{
- if ( d->mType == Display ) {
- if ( d->mParent ) {
- d->mParent->update();
- }
- d->mDescription = text;
- if ( d->mParent ) {
- d->mParent->updated();
+ if (d->mType == Display) {
+ if (d->mParent) {
+ d->mParent->update();
+ }
+ d->mDescription = text;
+ if (d->mParent) {
+ d->mParent->updated();
+ }
}
- }
}
QString Alarm::text() const
{
- return ( d->mType == Display ) ? d->mDescription : QString();
+ return (d->mType == Display) ? d->mDescription : QString();
}
-void Alarm::setTime( const KDateTime &alarmTime )
+void Alarm::setTime(const KDateTime &alarmTime)
{
- if ( d->mParent ) {
- d->mParent->update();
- }
- d->mAlarmTime = alarmTime;
- d->mHasTime = true;
+ if (d->mParent) {
+ d->mParent->update();
+ }
+ d->mAlarmTime = alarmTime;
+ d->mHasTime = true;
- if ( d->mParent ) {
- d->mParent->updated();
- }
+ if (d->mParent) {
+ d->mParent->updated();
+ }
}
KDateTime Alarm::time() const
{
- if ( hasTime() ) {
- return d->mAlarmTime;
- } else if ( d->mParent ) {
- if ( d->mEndOffset ) {
- KDateTime dt = d->mParent->dateTime( Incidence::RoleAlarmEndOffset );
- return d->mOffset.end( dt );
+ if (hasTime()) {
+ return d->mAlarmTime;
+ } else if (d->mParent) {
+ if (d->mEndOffset) {
+ KDateTime dt = d->mParent->dateTime(Incidence::RoleAlarmEndOffset);
+ return d->mOffset.end(dt);
+ } else {
+ KDateTime dt = d->mParent->dateTime(Incidence::RoleAlarmStartOffset);
+ return d->mOffset.end(dt);
+ }
+ } else {
+ return KDateTime();
+ }
+}
+
+KDateTime Alarm::nextTime(const KDateTime &preTime, bool ignoreRepetitions) const
+{
+ if (d->mParent && d->mParent->recurs()) {
+ KDateTime dtEnd = d->mParent->dateTime(Incidence::RoleAlarmEndOffset);
+
+ KDateTime dtStart = d->mParent->dtStart();
+ // Find the incidence's earliest alarm
+ // Alarm time is defined by an offset from the event start or end time.
+ KDateTime alarmStart = d->mOffset.end(d->mEndOffset ? dtEnd : dtStart);
+ // Find the offset from the event start time, which is also used as the
+ // offset from the recurrence time.
+ Duration alarmOffset(dtStart, alarmStart);
+ /*
+ kDebug() << "dtStart " << dtStart;
+ kDebug() << "dtEnd " << dtEnd;
+ kDebug() << "alarmStart " << alarmStart;
+ kDebug() << "alarmOffset " << alarmOffset.value();
+ kDebug() << "preTime " << preTime;
+ */
+ if (alarmStart > preTime) {
+ // No need to go further.
+ return alarmStart;
+ }
+ if (d->mAlarmRepeatCount && !ignoreRepetitions) {
+ // The alarm has repetitions, so check whether repetitions of previous
+ // recurrences happen after given time.
+ KDateTime prevRecurrence = d->mParent->recurrence()->getPreviousDateTime(preTime);
+ if (prevRecurrence.isValid()) {
+ KDateTime prevLastRepeat = alarmOffset.end(duration().end(prevRecurrence));
+ // kDebug() << "prevRecurrence" << prevRecurrence;
+ // kDebug() << "prevLastRepeat" << prevLastRepeat;
+ if (prevLastRepeat > preTime) {
+ // Yes they did, return alarm offset to previous recurrence.
+ KDateTime prevAlarm = alarmOffset.end(prevRecurrence);
+ // kDebug() << "prevAlarm " << prevAlarm;
+ return prevAlarm;
+ }
+ }
+ }
+ // Check the next recurrence now.
+ KDateTime nextRecurrence = d->mParent->recurrence()->getNextDateTime(preTime);
+ if (nextRecurrence.isValid()) {
+ KDateTime nextAlarm = alarmOffset.end(nextRecurrence);
+ /*
+ kDebug() << "nextRecurrence" << nextRecurrence;
+ kDebug() << "nextAlarm " << nextAlarm;
+ */
+ if (nextAlarm > preTime) {
+ // It's first alarm takes place after given time.
+ return nextAlarm;
+ }
+ }
} else {
- KDateTime dt = d->mParent->dateTime( Incidence::RoleAlarmStartOffset );
- return d->mOffset.end( dt );
+ // Not recurring.
+ KDateTime alarmTime = time();
+ if (alarmTime > preTime) {
+ return alarmTime;
+ }
}
- } else {
return KDateTime();
- }
-}
-
-KDateTime Alarm::nextTime( const KDateTime &preTime, bool ignoreRepetitions ) const
-{
- if ( d->mParent && d->mParent->recurs() ) {
- KDateTime dtEnd = d->mParent->dateTime( Incidence::RoleAlarmEndOffset );
-
- KDateTime dtStart = d->mParent->dtStart();
- // Find the incidence's earliest alarm
- // Alarm time is defined by an offset from the event start or end time.
- KDateTime alarmStart = d->mOffset.end( d->mEndOffset ? dtEnd : dtStart );
- // Find the offset from the event start time, which is also used as the
- // offset from the recurrence time.
- Duration alarmOffset( dtStart, alarmStart );
- /*
- qDebug() << "dtStart " << dtStart;
- qDebug() << "dtEnd " << dtEnd;
- qDebug() << "alarmStart " << alarmStart;
- qDebug() << "alarmOffset " << alarmOffset.value();
- qDebug() << "preTime " << preTime;
- */
- if ( alarmStart > preTime ) {
- // No need to go further.
- return alarmStart;
- }
- if ( d->mAlarmRepeatCount && !ignoreRepetitions ) {
- // The alarm has repetitions, so check whether repetitions of previous
- // recurrences happen after given time.
- KDateTime prevRecurrence = d->mParent->recurrence()->getPreviousDateTime( preTime );
- if ( prevRecurrence.isValid() ) {
- KDateTime prevLastRepeat = alarmOffset.end( duration().end( prevRecurrence ) );
- // qDebug() << "prevRecurrence" << prevRecurrence;
- // qDebug() << "prevLastRepeat" << prevLastRepeat;
- if ( prevLastRepeat > preTime ) {
- // Yes they did, return alarm offset to previous recurrence.
- KDateTime prevAlarm = alarmOffset.end( prevRecurrence );
- // qDebug() << "prevAlarm " << prevAlarm;
- return prevAlarm;
- }
- }
- }
- // Check the next recurrence now.
- KDateTime nextRecurrence = d->mParent->recurrence()->getNextDateTime( preTime );
- if ( nextRecurrence.isValid() ) {
- KDateTime nextAlarm = alarmOffset.end( nextRecurrence );
- /*
- qDebug() << "nextRecurrence" << nextRecurrence;
- qDebug() << "nextAlarm " << nextAlarm;
- */
- if ( nextAlarm > preTime ) {
- // It's first alarm takes place after given time.
- return nextAlarm;
- }
- }
- } else {
- // Not recurring.
- KDateTime alarmTime = time();
- if ( alarmTime > preTime ) {
- return alarmTime;
- }
- }
- return KDateTime();
}
bool Alarm::hasTime() const
{
- return d->mHasTime;
+ return d->mHasTime;
}
-void Alarm::shiftTimes( const KDateTime::Spec &oldSpec,
- const KDateTime::Spec &newSpec )
+void Alarm::shiftTimes(const KDateTime::Spec &oldSpec,
+ const KDateTime::Spec &newSpec)
{
- if ( d->mParent ) {
- d->mParent->update();
- }
- d->mAlarmTime = d->mAlarmTime.toTimeSpec( oldSpec );
- d->mAlarmTime.setTimeSpec( newSpec );
- if ( d->mParent ) {
- d->mParent->updated();
- }
+ if (d->mParent) {
+ d->mParent->update();
+ }
+ d->mAlarmTime = d->mAlarmTime.toTimeSpec(oldSpec);
+ d->mAlarmTime.setTimeSpec(newSpec);
+ if (d->mParent) {
+ d->mParent->updated();
+ }
}
-void Alarm::setSnoozeTime( const Duration &alarmSnoozeTime )
+void Alarm::setSnoozeTime(const Duration &alarmSnoozeTime)
{
- if ( alarmSnoozeTime.value() > 0 ) {
- if ( d->mParent ) {
- d->mParent->update();
- }
- d->mAlarmSnoozeTime = alarmSnoozeTime;
- if ( d->mParent ) {
- d->mParent->updated();
+ if (alarmSnoozeTime.value() > 0) {
+ if (d->mParent) {
+ d->mParent->update();
+ }
+ d->mAlarmSnoozeTime = alarmSnoozeTime;
+ if (d->mParent) {
+ d->mParent->updated();
+ }
}
- }
}
Duration Alarm::snoozeTime() const
{
- return d->mAlarmSnoozeTime;
+ return d->mAlarmSnoozeTime;
}
-void Alarm::setRepeatCount( int alarmRepeatCount )
+void Alarm::setRepeatCount(int alarmRepeatCount)
{
- if ( d->mParent ) {
- d->mParent->update();
- }
- d->mAlarmRepeatCount = alarmRepeatCount;
- if ( d->mParent ) {
- d->mParent->updated();
- }
+ if (d->mParent) {
+ d->mParent->update();
+ }
+ d->mAlarmRepeatCount = alarmRepeatCount;
+ if (d->mParent) {
+ d->mParent->updated();
+ }
}
int Alarm::repeatCount() const
{
- return d->mAlarmRepeatCount;
+ return d->mAlarmRepeatCount;
}
Duration Alarm::duration() const
{
- return Duration( d->mAlarmSnoozeTime.value() * d->mAlarmRepeatCount,
- d->mAlarmSnoozeTime.type() );
+ return Duration(d->mAlarmSnoozeTime.value() * d->mAlarmRepeatCount,
+ d->mAlarmSnoozeTime.type());
}
-KDateTime Alarm::nextRepetition( const KDateTime &preTime ) const
+KDateTime Alarm::nextRepetition(const KDateTime &preTime) const
{
- KDateTime at = nextTime( preTime );
- if ( at > preTime ) {
- return at;
- }
- if ( !d->mAlarmRepeatCount ) {
- // there isn't an occurrence after the specified time
- return KDateTime();
- }
- qint64 repetition;
- int interval = d->mAlarmSnoozeTime.value();
- bool daily = d->mAlarmSnoozeTime.isDaily();
- if ( daily ) {
- int daysTo = at.daysTo( preTime );
- if ( !preTime.isDateOnly() && preTime.time() <= at.time() ) {
- --daysTo;
- }
- repetition = daysTo / interval + 1;
- } else {
- repetition = at.secsTo_long( preTime ) / interval + 1;
- }
- if ( repetition > d->mAlarmRepeatCount ) {
- // all repetitions have finished before the specified time
- return KDateTime();
- }
- return daily ? at.addDays( int( repetition * interval ) )
- : at.addSecs( repetition * interval );
+ KDateTime at = nextTime(preTime);
+ if (at > preTime) {
+ return at;
+ }
+ if (!d->mAlarmRepeatCount) {
+ // there isn't an occurrence after the specified time
+ return KDateTime();
+ }
+ qint64 repetition;
+ int interval = d->mAlarmSnoozeTime.value();
+ bool daily = d->mAlarmSnoozeTime.isDaily();
+ if (daily) {
+ int daysTo = at.daysTo(preTime);
+ if (!preTime.isDateOnly() && preTime.time() <= at.time()) {
+ --daysTo;
+ }
+ repetition = daysTo / interval + 1;
+ } else {
+ repetition = at.secsTo_long(preTime) / interval + 1;
+ }
+ if (repetition > d->mAlarmRepeatCount) {
+ // all repetitions have finished before the specified time
+ return KDateTime();
+ }
+ return daily ? at.addDays(int(repetition * interval))
+ : at.addSecs(repetition * interval);
}
-KDateTime Alarm::previousRepetition( const KDateTime &afterTime ) const
+KDateTime Alarm::previousRepetition(const KDateTime &afterTime) const
{
- KDateTime at = time();
- if ( at >= afterTime ) {
- // alarm's first/only time is at/after the specified time
- return KDateTime();
- }
- if ( !d->mAlarmRepeatCount ) {
- return at;
- }
- qint64 repetition;
- int interval = d->mAlarmSnoozeTime.value();
- bool daily = d->mAlarmSnoozeTime.isDaily();
- if ( daily ) {
- int daysTo = at.daysTo( afterTime );
- if ( afterTime.isDateOnly() || afterTime.time() <= at.time() ) {
- --daysTo;
- }
- repetition = daysTo / interval;
- } else {
- repetition = ( at.secsTo_long( afterTime ) - 1 ) / interval;
- }
- if ( repetition > d->mAlarmRepeatCount ) {
- repetition = d->mAlarmRepeatCount;
- }
- return daily ? at.addDays( int( repetition * interval ) )
- : at.addSecs( repetition * interval );
+ KDateTime at = time();
+ if (at >= afterTime) {
+ // alarm's first/only time is at/after the specified time
+ return KDateTime();
+ }
+ if (!d->mAlarmRepeatCount) {
+ return at;
+ }
+ qint64 repetition;
+ int interval = d->mAlarmSnoozeTime.value();
+ bool daily = d->mAlarmSnoozeTime.isDaily();
+ if (daily) {
+ int daysTo = at.daysTo(afterTime);
+ if (afterTime.isDateOnly() || afterTime.time() <= at.time()) {
+ --daysTo;
+ }
+ repetition = daysTo / interval;
+ } else {
+ repetition = (at.secsTo_long(afterTime) - 1) / interval;
+ }
+ if (repetition > d->mAlarmRepeatCount) {
+ repetition = d->mAlarmRepeatCount;
+ }
+ return daily ? at.addDays(int(repetition * interval))
+ : at.addSecs(repetition * interval);
}
KDateTime Alarm::endTime() const
{
- if ( !d->mAlarmRepeatCount ) {
- return time();
- }
- if ( d->mAlarmSnoozeTime.isDaily() ) {
- return time().addDays( d->mAlarmRepeatCount * d->mAlarmSnoozeTime.asDays() );
- } else {
- return time().addSecs( d->mAlarmRepeatCount * d->mAlarmSnoozeTime.asSeconds() );
- }
+ if (!d->mAlarmRepeatCount) {
+ return time();
+ }
+ if (d->mAlarmSnoozeTime.isDaily()) {
+ return time().addDays(d->mAlarmRepeatCount * d->mAlarmSnoozeTime.asDays());
+ } else {
+ return time().addSecs(d->mAlarmRepeatCount * d->mAlarmSnoozeTime.asSeconds());
+ }
}
void Alarm::toggleAlarm()
{
- if ( d->mParent ) {
- d->mParent->update();
- }
- d->mAlarmEnabled = !d->mAlarmEnabled;
- if ( d->mParent ) {
- d->mParent->updated();
- }
+ if (d->mParent) {
+ d->mParent->update();
+ }
+ d->mAlarmEnabled = !d->mAlarmEnabled;
+ if (d->mParent) {
+ d->mParent->updated();
+ }
}
-void Alarm::setEnabled( bool enable )
+void Alarm::setEnabled(bool enable)
{
- if ( d->mParent ) {
- d->mParent->update();
- }
- d->mAlarmEnabled = enable;
- if ( d->mParent ) {
- d->mParent->updated();
- }
+ if (d->mParent) {
+ d->mParent->update();
+ }
+ d->mAlarmEnabled = enable;
+ if (d->mParent) {
+ d->mParent->updated();
+ }
}
bool Alarm::enabled() const
{
- return d->mAlarmEnabled;
+ return d->mAlarmEnabled;
}
-void Alarm::setStartOffset( const Duration &offset )
+void Alarm::setStartOffset(const Duration &offset)
{
- if ( d->mParent ) {
- d->mParent->update();
- }
- d->mOffset = offset;
- d->mEndOffset = false;
- d->mHasTime = false;
- if ( d->mParent ) {
- d->mParent->updated();
- }
+ if (d->mParent) {
+ d->mParent->update();
+ }
+ d->mOffset = offset;
+ d->mEndOffset = false;
+ d->mHasTime = false;
+ if (d->mParent) {
+ d->mParent->updated();
+ }
}
Duration Alarm::startOffset() const
{
- return ( d->mHasTime || d->mEndOffset ) ? Duration( 0 ) : d->mOffset;
+ return (d->mHasTime || d->mEndOffset) ? Duration(0) : d->mOffset;
}
bool Alarm::hasStartOffset() const
{
- return !d->mHasTime && !d->mEndOffset;
+ return !d->mHasTime && !d->mEndOffset;
}
bool Alarm::hasEndOffset() const
{
- return !d->mHasTime && d->mEndOffset;
+ return !d->mHasTime && d->mEndOffset;
}
-void Alarm::setEndOffset( const Duration &offset )
+void Alarm::setEndOffset(const Duration &offset)
{
- if ( d->mParent ) {
- d->mParent->update();
- }
- d->mOffset = offset;
- d->mEndOffset = true;
- d->mHasTime = false;
- if ( d->mParent ) {
- d->mParent->updated();
- }
+ if (d->mParent) {
+ d->mParent->update();
+ }
+ d->mOffset = offset;
+ d->mEndOffset = true;
+ d->mHasTime = false;
+ if (d->mParent) {
+ d->mParent->updated();
+ }
}
Duration Alarm::endOffset() const
{
- return ( d->mHasTime || !d->mEndOffset ) ? Duration( 0 ) : d->mOffset;
+ return (d->mHasTime || !d->mEndOffset) ? Duration(0) : d->mOffset;
}
-void Alarm::setParent( Incidence *parent )
+void Alarm::setParent(Incidence *parent)
{
- d->mParent = parent;
+ d->mParent = parent;
}
QString Alarm::parentUid() const
{
- return d->mParent ? d->mParent->uid() : QString();
+ return d->mParent ? d->mParent->uid() : QString();
}
void Alarm::customPropertyUpdated()
{
- if ( d->mParent ) {
- d->mParent->update();
- d->mParent->updated();
- }
+ if (d->mParent) {
+ d->mParent->update();
+ d->mParent->updated();
+ }
}
-void Alarm::setHasLocationRadius( bool hasLocationRadius )
+void Alarm::setHasLocationRadius(bool hasLocationRadius)
{
- if ( d->mParent ) {
- d->mParent->update();
- }
- d->mHasLocationRadius = hasLocationRadius;
- if ( hasLocationRadius ) {
- setNonKDECustomProperty( "X-LOCATION-RADIUS", QString::number( d->mLocationRadius ) );
- } else {
- removeNonKDECustomProperty( "X-LOCATION-RADIUS" );
- }
- if ( d->mParent ) {
- d->mParent->updated();
- }
+ if (d->mParent) {
+ d->mParent->update();
+ }
+ d->mHasLocationRadius = hasLocationRadius;
+ if (hasLocationRadius) {
+ setNonKDECustomProperty("X-LOCATION-RADIUS", QString::number(d->mLocationRadius));
+ } else {
+ removeNonKDECustomProperty("X-LOCATION-RADIUS");
+ }
+ if (d->mParent) {
+ d->mParent->updated();
+ }
}
bool Alarm::hasLocationRadius() const
{
- return d->mHasLocationRadius;
+ return d->mHasLocationRadius;
}
-void Alarm::setLocationRadius( int locationRadius )
+void Alarm::setLocationRadius(int locationRadius)
{
- if ( d->mParent ) {
- d->mParent->update();
- }
- d->mLocationRadius = locationRadius;
- if ( d->mParent ) {
- d->mParent->updated();
- }
+ if (d->mParent) {
+ d->mParent->update();
+ }
+ d->mLocationRadius = locationRadius;
+ if (d->mParent) {
+ d->mParent->updated();
+ }
}
int Alarm::locationRadius() const
{
- return d->mLocationRadius;
+ return d->mLocationRadius;
+}
+
+QDataStream& KCalCore::operator<<(QDataStream &out, const KCalCore::Alarm::Ptr &a)
+{
+ if (a) {
+ out << ((quint32)a->d->mType) << a->d->mAlarmSnoozeTime << a->d->mAlarmRepeatCount << a->d->mEndOffset << a->d->mHasTime
+ << a->d->mAlarmEnabled << a->d->mHasLocationRadius << a->d->mLocationRadius << a->d->mOffset << a->d->mAlarmTime
+ << a->d->mFile << a->d->mMailSubject << a->d->mDescription << a->d->mMailAttachFiles << a->d->mMailAddresses;
+ }
+ return out;
+}
+
+QDataStream& KCalCore::operator>>(QDataStream &in, const KCalCore::Alarm::Ptr &a)
+{
+ if (a) {
+ quint32 type;
+ in >> type;
+ a->d->mType = static_cast<Alarm::Type>(type);
+ in >> a->d->mAlarmSnoozeTime >> a->d->mAlarmRepeatCount >> a->d->mEndOffset >> a->d->mHasTime
+ >> a->d->mAlarmEnabled >> a->d->mHasLocationRadius >> a->d->mLocationRadius >> a->d->mOffset >> a->d->mAlarmTime
+ >> a->d->mFile >> a->d->mMailSubject >> a->d->mDescription >> a->d->mMailAttachFiles >> a->d->mMailAddresses;
+ }
+ return in;
}
-void Alarm::virtual_hook( int id, void *data )
+void Alarm::virtual_hook(int id, void *data)
{
- Q_UNUSED( id );
- Q_UNUSED( data );
- Q_ASSERT( false );
+ Q_UNUSED(id);
+ Q_UNUSED(data);
+ Q_ASSERT(false);
}
diff --git a/kcalcore/alarm.h b/kcalcore/alarm.h
index f918353..8759a55 100644
--- a/kcalcore/alarm.h
+++ b/kcalcore/alarm.h
@@ -36,11 +36,13 @@
#include "duration.h"
#include "person.h"
-#include <kdatetime.h>
+#include <KDE/KDateTime>
#include <QtCore/QString>
#include <QtCore/QStringList>
#include <QtCore/QVector>
+#include <QDataStream>
+#include <QMetaType>
namespace KCalCore {
@@ -58,16 +60,16 @@ class Incidence;
*/
class KCALCORE_EXPORT Alarm : public CustomProperties
{
- public:
+public:
/**
The different types of alarms.
*/
enum Type {
- Invalid, /**< Invalid, or no alarm */
- Display, /**< Display a dialog box */
- Procedure, /**< Call a script */
- Email, /**< Send email */
- Audio /**< Play an audio file */
+ Invalid, /**< Invalid, or no alarm */
+ Display, /**< Display a dialog box */
+ Procedure, /**< Call a script */
+ Email, /**< Send email */
+ Audio /**< Play an audio file */
};
/**
@@ -87,13 +89,13 @@ class KCALCORE_EXPORT Alarm : public CustomProperties
*/
// Can't find a way to use a shared pointer here.
// Inside incidence.cpp, it does alarm->setParent( this )
- explicit Alarm( Incidence *parent );
+ explicit Alarm(Incidence *parent);
/**
Copy constructor.
@param other is the alarm to copy.
*/
- Alarm( const Alarm &other );
+ Alarm(const Alarm &other);
/**
Destroys the alarm.
@@ -103,20 +105,20 @@ class KCALCORE_EXPORT Alarm : public CustomProperties
/**
Copy operator.
*/
- Alarm &operator=( const Alarm & );
+ Alarm &operator=(const Alarm &);
/**
Compares two alarms for equality.
@param a is the comparison alarm.
*/
- bool operator==( const Alarm &a ) const;
+ bool operator==(const Alarm &a) const;
/**
Compares two alarms for inequality.
@param a is the comparison alarm.
*/
- bool operator!=( const Alarm &a ) const;
+ bool operator!=(const Alarm &a) const;
/**
Sets the @p parent Incidence of the alarm.
@@ -130,7 +132,7 @@ class KCALCORE_EXPORT Alarm : public CustomProperties
// se we don't dereference a deleted pointer here.
// Also, I renamed "Incidence *parent()" to "QString parentUid()"
// So we don't return raw pointers
- void setParent( Incidence *parent );
+ void setParent(Incidence *parent);
/**
Returns the parent's incidence UID of the alarm.
@@ -149,7 +151,7 @@ class KCALCORE_EXPORT Alarm : public CustomProperties
@see type()
*/
- void setType( Type type );
+ void setType(Type type);
/**
Returns the #Type of the alarm.
@@ -167,7 +169,7 @@ class KCALCORE_EXPORT Alarm : public CustomProperties
@see setText(), text()
*/
- void setDisplayAlarm( const QString &text = QString() );
+ void setDisplayAlarm(const QString &text = QString());
/**
Sets the description @p text to be displayed when the alarm is triggered.
@@ -177,7 +179,7 @@ class KCALCORE_EXPORT Alarm : public CustomProperties
@see setDisplayAlarm(), text()
*/
- void setText( const QString &text );
+ void setText(const QString &text);
/**
Returns the display text string for a #Display alarm type.
@@ -196,7 +198,7 @@ class KCALCORE_EXPORT Alarm : public CustomProperties
@see setAudioFile(), audioFile()
*/
- void setAudioAlarm( const QString &audioFile = QString() );
+ void setAudioAlarm(const QString &audioFile = QString());
/**
Sets the name of the audio file to play when the audio alarm is triggered.
@@ -207,7 +209,7 @@ class KCALCORE_EXPORT Alarm : public CustomProperties
@see setAudioAlarm(), audioFile()
*/
- void setAudioFile( const QString &audioFile );
+ void setAudioFile(const QString &audioFile);
/**
Returns the audio file name for an #Audio alarm type.
@@ -228,8 +230,8 @@ class KCALCORE_EXPORT Alarm : public CustomProperties
@see setProgramFile(), programFile(),
setProgramArguments(), programArguments()
*/
- void setProcedureAlarm( const QString &programFile,
- const QString &arguments = QString() );
+ void setProcedureAlarm(const QString &programFile,
+ const QString &arguments = QString());
/**
Sets the program file to execute when the alarm is triggered.
@@ -241,7 +243,7 @@ class KCALCORE_EXPORT Alarm : public CustomProperties
@see setProcedureAlarm(), programFile(),
setProgramArguments(), programArguments()
*/
- void setProgramFile( const QString &programFile );
+ void setProgramFile(const QString &programFile);
/**
Returns the program file name for a #Procedure alarm type.
@@ -261,7 +263,7 @@ class KCALCORE_EXPORT Alarm : public CustomProperties
@see setProcedureAlarm(), setProgramFile(), programFile(),
programArguments()
*/
- void setProgramArguments( const QString &arguments );
+ void setProgramArguments(const QString &arguments);
/**
Returns the program arguments string for a #Procedure alarm type.
@@ -286,9 +288,9 @@ class KCALCORE_EXPORT Alarm : public CustomProperties
@see setMailSubject(), setMailText(), setMailAddresses(),
setMailAttachments()
*/
- void setEmailAlarm( const QString &subject, const QString &text,
- const Person::List &addressees,
- const QStringList &attachments = QStringList() );
+ void setEmailAlarm(const QString &subject, const QString &text,
+ const Person::List &addressees,
+ const QStringList &attachments = QStringList());
/**
Sets the email address of an #Email type alarm.
@@ -300,7 +302,7 @@ class KCALCORE_EXPORT Alarm : public CustomProperties
@see setMailSubject(), setMailText(), setMailAddresses(),
setMailAttachment(), setMailAttachments(), mailAddresses()
*/
- void setMailAddress( const Person::Ptr &mailAlarmAddress );
+ void setMailAddress(const Person::Ptr &mailAlarmAddress);
/**
Sets a list of email addresses of an #Email type alarm.
@@ -312,7 +314,7 @@ class KCALCORE_EXPORT Alarm : public CustomProperties
@see setMailSubject(), setMailText(), setMailAddress(),
setMailAttachments(), setMailAttachment(), mailAddresses()
*/
- void setMailAddresses( const Person::List &mailAlarmAddresses );
+ void setMailAddresses(const Person::List &mailAlarmAddresses);
/**
Adds an address to the list of email addresses to send mail to when the
@@ -324,7 +326,7 @@ class KCALCORE_EXPORT Alarm : public CustomProperties
@see setMailAddress(), setMailAddresses(), mailAddresses()
*/
- void addMailAddress( const Person::Ptr &mailAlarmAddress );
+ void addMailAddress(const Person::Ptr &mailAlarmAddress);
/**
Returns the list of addresses for an #Email alarm type.
@@ -344,7 +346,7 @@ class KCALCORE_EXPORT Alarm : public CustomProperties
@see setMailText(), setMailAddress(), setMailAddresses(),
setMailAttachment(), setMailAttachments(), mailSubject()
*/
- void setMailSubject( const QString &mailAlarmSubject );
+ void setMailSubject(const QString &mailAlarmSubject);
/**
Returns the subject line string for an #Email alarm type.
@@ -364,7 +366,7 @@ class KCALCORE_EXPORT Alarm : public CustomProperties
@see setMailSubject(), setMailText(), setMailAddress(),
setMailAddresses(), setMailAttachments(), mailAttachments()
*/
- void setMailAttachment( const QString &mailAttachFile );
+ void setMailAttachment(const QString &mailAttachFile);
/**
Sets a list of filenames to attach to a mail message for an #Email
@@ -376,7 +378,7 @@ class KCALCORE_EXPORT Alarm : public CustomProperties
@see setMailSubject(), setMailText(), setMailAttachment(),
setMailAddress(), setMailAddresses()
*/
- void setMailAttachments( const QStringList &mailAttachFiles );
+ void setMailAttachments(const QStringList &mailAttachFiles);
/**
Adds a filename to the list of files to attach to a mail message for
@@ -387,7 +389,7 @@ class KCALCORE_EXPORT Alarm : public CustomProperties
@see setMailAttachment(), setMailAttachments(), mailAttachments()
*/
- void addMailAttachment( const QString &mailAttachFile );
+ void addMailAttachment(const QString &mailAttachFile);
/**
Returns the list of attachment filenames for an #Email alarm type.
@@ -407,7 +409,7 @@ class KCALCORE_EXPORT Alarm : public CustomProperties
@see setMailSubject(), setMailAddress(), setMailAddresses(),
setMailAttachment(), setMailAttachments()
*/
- void setMailText( const QString &text );
+ void setMailText(const QString &text);
/**
Returns the body text for an #Email alarm type.
@@ -424,7 +426,7 @@ class KCALCORE_EXPORT Alarm : public CustomProperties
@see time()
*/
- void setTime( const KDateTime &alarmTime );
+ void setTime(const KDateTime &alarmTime);
/**
Returns the alarm trigger date/time.
@@ -441,7 +443,7 @@ class KCALCORE_EXPORT Alarm : public CustomProperties
@param ignoreRepetitions don't take repetitions into account
@see nextRepetition()
*/
- KDateTime nextTime( const KDateTime &preTime, bool ignoreRepetitions = false ) const;
+ KDateTime nextTime(const KDateTime &preTime, bool ignoreRepetitions = false) const;
/**
Returns the date/time when the last repetition of the alarm goes off.
@@ -464,7 +466,7 @@ class KCALCORE_EXPORT Alarm : public CustomProperties
@see setEndOffset(), startOffset(), endOffset()
*/
- void setStartOffset( const Duration &offset );
+ void setStartOffset(const Duration &offset);
/**
Returns offset of alarm in time relative to the start of the parent
@@ -491,7 +493,7 @@ class KCALCORE_EXPORT Alarm : public CustomProperties
@see setStartOffset(), startOffset(), endOffset()
*/
- void setEndOffset( const Duration &offset );
+ void setEndOffset(const Duration &offset);
/**
Returns offset of alarm in time relative to the end of the event.
@@ -524,8 +526,8 @@ class KCALCORE_EXPORT Alarm : public CustomProperties
@param oldSpec the time specification which provides the clock times
@param newSpec the new time specification
*/
- void shiftTimes( const KDateTime::Spec &oldSpec,
- const KDateTime::Spec &newSpec );
+ void shiftTimes(const KDateTime::Spec &oldSpec,
+ const KDateTime::Spec &newSpec);
/**
Sets the snooze time interval for the alarm.
@@ -534,7 +536,7 @@ class KCALCORE_EXPORT Alarm : public CustomProperties
@see snoozeTime()
*/
- void setSnoozeTime( const Duration &alarmSnoozeTime );
+ void setSnoozeTime(const Duration &alarmSnoozeTime);
/**
Returns the snooze time interval.
@@ -552,7 +554,7 @@ class KCALCORE_EXPORT Alarm : public CustomProperties
@see repeatCount()
*/
- void setRepeatCount( int alarmRepeatCount );
+ void setRepeatCount(int alarmRepeatCount);
/**
Returns how many times an alarm may repeats after its initial occurrence.
@@ -572,7 +574,7 @@ class KCALCORE_EXPORT Alarm : public CustomProperties
@see previousRepetition()
*/
- KDateTime nextRepetition( const KDateTime &preTime ) const;
+ KDateTime nextRepetition(const KDateTime &preTime) const;
/**
Returns the date/time of the alarm's latest repetition or, if none,
@@ -587,7 +589,7 @@ class KCALCORE_EXPORT Alarm : public CustomProperties
@see nextRepetition()
*/
- KDateTime previousRepetition( const KDateTime &afterTime ) const;
+ KDateTime previousRepetition(const KDateTime &afterTime) const;
/**
Returns the interval between the alarm's initial occurrence and
@@ -609,7 +611,7 @@ class KCALCORE_EXPORT Alarm : public CustomProperties
@see enabled(), toggleAlarm()
*/
- void setEnabled( bool enable );
+ void setEnabled(bool enable);
/**
Returns the alarm enabled status: true (enabled) or false (disabled).
@@ -624,7 +626,7 @@ class KCALCORE_EXPORT Alarm : public CustomProperties
@see setLocationRadius()
*/
- void setHasLocationRadius( bool hasLocationRadius );
+ void setHasLocationRadius(bool hasLocationRadius);
/**
Returns true if alarm has location radius defined.
@@ -641,7 +643,7 @@ class KCALCORE_EXPORT Alarm : public CustomProperties
@param locationRadius radius in meters
@see locationRadius()
*/
- void setLocationRadius( int locationRadius );
+ void setLocationRadius(int locationRadius);
/**
Returns the location radius in meters.
@@ -650,7 +652,7 @@ class KCALCORE_EXPORT Alarm : public CustomProperties
*/
int locationRadius() const;
- protected:
+protected:
/**
@copydoc
CustomProperties::customPropertyUpdated()
@@ -661,17 +663,35 @@ class KCALCORE_EXPORT Alarm : public CustomProperties
@copydoc
IncidenceBase::virtual_hook()
*/
- virtual void virtual_hook( int id, void *data );
+ virtual void virtual_hook(int id, void *data);
- private:
+private:
//@cond PRIVATE
class Private;
Private *const d;
//@endcond
+ friend KCALCORE_EXPORT QDataStream &operator<<(QDataStream &s, const KCalCore::Alarm::Ptr &);
+ friend KCALCORE_EXPORT QDataStream &operator>>(QDataStream &s, const KCalCore::Alarm::Ptr &);
};
+/**
+ * Alarm serializer.
+ *
+ * @since 4.12
+ */
+KCALCORE_EXPORT QDataStream &operator<<(QDataStream &out, const KCalCore::Alarm::Ptr &);
+
+/**
+ * Alarm deserializer.
+ *
+ * @since 4.12
+ */
+KCALCORE_EXPORT QDataStream &operator>>(QDataStream &in, const KCalCore::Alarm::Ptr &);
}
-Q_DECLARE_TYPEINFO( KCalCore::Alarm::Ptr, Q_MOVABLE_TYPE );
+//@cond PRIVATE
+Q_DECLARE_TYPEINFO(KCalCore::Alarm::Ptr, Q_MOVABLE_TYPE);
+Q_DECLARE_METATYPE(KCalCore::Alarm::Ptr)
+//@endcond
#endif
diff --git a/kcalcore/attachment.cpp b/kcalcore/attachment.cpp
index b80ec11..b972de6 100644
--- a/kcalcore/attachment.cpp
+++ b/kcalcore/attachment.cpp
@@ -30,6 +30,7 @@
*/
#include "attachment.h"
+#include <QDataStream>
using namespace KCalCore;
@@ -40,23 +41,23 @@ using namespace KCalCore;
//@cond PRIVATE
class KCalCore::Attachment::Private
{
- public:
- Private( const QString &mime, bool binary )
- : mSize( 0 ),
- mMimeType( mime ),
- mBinary( binary ),
- mLocal( false ),
- mShowInline( false )
+public:
+ Private(const QString &mime, bool binary)
+ : mSize(0),
+ mMimeType(mime),
+ mBinary(binary),
+ mLocal(false),
+ mShowInline(false)
{}
- Private( const Private &other )
- : mSize( other.mSize ),
- mMimeType( other.mMimeType ),
- mUri( other.mUri ),
- mEncodedData( other.mEncodedData ),
- mLabel( other.mLabel ),
- mBinary( other.mBinary ),
- mLocal( other.mLocal ),
- mShowInline( other.mShowInline )
+ Private(const Private &other)
+ : mSize(other.mSize),
+ mMimeType(other.mMimeType),
+ mUri(other.mUri),
+ mEncodedData(other.mEncodedData),
+ mLabel(other.mLabel),
+ mBinary(other.mBinary),
+ mLocal(other.mLocal),
+ mShowInline(other.mShowInline)
{}
~Private()
@@ -75,166 +76,181 @@ class KCalCore::Attachment::Private
};
//@endcond
-Attachment::Attachment( const Attachment &attachment )
- : d( new Attachment::Private( *attachment.d ) )
+Attachment::Attachment(const Attachment &attachment)
+ : d(new Attachment::Private(*attachment.d))
{
}
-Attachment::Attachment( const QString &uri, const QString &mime )
- : d( new Attachment::Private( mime, false ) )
+Attachment::Attachment(const QString &uri, const QString &mime)
+ : d(new Attachment::Private(mime, false))
{
- d->mUri = uri;
+ d->mUri = uri;
}
-Attachment::Attachment( const QByteArray &base64, const QString &mime )
- : d( new Attachment::Private( mime, true ) )
+Attachment::Attachment(const QByteArray &base64, const QString &mime)
+ : d(new Attachment::Private(mime, true))
{
- d->mEncodedData = base64;
+ d->mEncodedData = base64;
}
Attachment::~Attachment()
{
- delete d;
+ delete d;
}
bool Attachment::isUri() const
{
- return !d->mBinary;
+ return !d->mBinary;
}
QString Attachment::uri() const
{
- if ( !d->mBinary ) {
- return d->mUri;
- } else {
- return QString();
- }
+ if (!d->mBinary) {
+ return d->mUri;
+ } else {
+ return QString();
+ }
}
-void Attachment::setUri( const QString &uri )
+void Attachment::setUri(const QString &uri)
{
- d->mUri = uri;
- d->mBinary = false;
+ d->mUri = uri;
+ d->mBinary = false;
}
bool Attachment::isBinary() const
{
- return d->mBinary;
+ return d->mBinary;
}
QByteArray Attachment::data() const
{
- if ( d->mBinary ) {
- return d->mEncodedData;
- } else {
- return QByteArray();
- }
+ if (d->mBinary) {
+ return d->mEncodedData;
+ } else {
+ return QByteArray();
+ }
}
QByteArray Attachment::decodedData() const
{
- if ( d->mDecodedDataCache.isNull() ) {
- d->mDecodedDataCache = QByteArray::fromBase64( d->mEncodedData );
- }
+ if (d->mDecodedDataCache.isNull()) {
+ d->mDecodedDataCache = QByteArray::fromBase64(d->mEncodedData);
+ }
- return d->mDecodedDataCache;
+ return d->mDecodedDataCache;
}
-void Attachment::setDecodedData( const QByteArray &data )
+void Attachment::setDecodedData(const QByteArray &data)
{
- setData( data.toBase64() );
- d->mDecodedDataCache = data;
- d->mSize = d->mDecodedDataCache.size();
+ setData(data.toBase64());
+ d->mDecodedDataCache = data;
+ d->mSize = d->mDecodedDataCache.size();
}
-void Attachment::setData( const QByteArray &base64 )
+void Attachment::setData(const QByteArray &base64)
{
- d->mEncodedData = base64;
- d->mBinary = true;
- d->mDecodedDataCache = QByteArray();
- d->mSize = 0;
+ d->mEncodedData = base64;
+ d->mBinary = true;
+ d->mDecodedDataCache = QByteArray();
+ d->mSize = 0;
}
uint Attachment::size() const
{
- if ( isUri() ) {
- return 0;
- }
- if ( !d->mSize ) {
- d->mSize = decodedData().size();
- }
+ if (isUri()) {
+ return 0;
+ }
+ if (!d->mSize) {
+ d->mSize = decodedData().size();
+ }
- return d->mSize;
+ return d->mSize;
}
QString Attachment::mimeType() const
{
- return d->mMimeType;
+ return d->mMimeType;
}
-void Attachment::setMimeType( const QString &mime )
+void Attachment::setMimeType(const QString &mime)
{
- d->mMimeType = mime;
+ d->mMimeType = mime;
}
bool Attachment::showInline() const
{
- return d->mShowInline;
+ return d->mShowInline;
}
-void Attachment::setShowInline( bool showinline )
+void Attachment::setShowInline(bool showinline)
{
- d->mShowInline = showinline;
+ d->mShowInline = showinline;
}
QString Attachment::label() const
{
- return d->mLabel;
+ return d->mLabel;
}
-void Attachment::setLabel( const QString &label )
+void Attachment::setLabel(const QString &label)
{
- d->mLabel = label;
+ d->mLabel = label;
}
bool Attachment::isLocal() const
{
- return d->mLocal;
+ return d->mLocal;
}
-void Attachment::setLocal( bool local )
+void Attachment::setLocal(bool local)
{
- d->mLocal = local;
+ d->mLocal = local;
}
-Attachment &Attachment::operator=( const Attachment &other )
+Attachment &Attachment::operator=(const Attachment &other)
{
- if ( this != &other ) {
- d->mSize = other.d->mSize;
- d->mMimeType = other.d->mMimeType;
- d->mUri = other.d->mUri;
- d->mEncodedData = other.d->mEncodedData;
- d->mLabel = other.d->mLabel;
- d->mBinary = other.d->mBinary;
- d->mLocal = other.d->mLocal;
- d->mShowInline = other.d->mShowInline;
- }
+ if (this != &other) {
+ d->mSize = other.d->mSize;
+ d->mMimeType = other.d->mMimeType;
+ d->mUri = other.d->mUri;
+ d->mEncodedData = other.d->mEncodedData;
+ d->mLabel = other.d->mLabel;
+ d->mBinary = other.d->mBinary;
+ d->mLocal = other.d->mLocal;
+ d->mShowInline = other.d->mShowInline;
+ }
- return *this;
+ return *this;
}
-bool Attachment::operator==( const Attachment &a2 ) const
+bool Attachment::operator==(const Attachment &a2) const
{
- return uri() == a2.uri() &&
- d->mLabel == a2.label() &&
- d->mLocal == a2.isLocal() &&
- d->mBinary == a2.isBinary() &&
- d->mShowInline == a2.showInline() &&
- size() == a2.size() &&
- decodedData() == a2.decodedData();
+ return uri() == a2.uri() &&
+ d->mLabel == a2.label() &&
+ d->mLocal == a2.isLocal() &&
+ d->mBinary == a2.isBinary() &&
+ d->mShowInline == a2.showInline() &&
+ size() == a2.size() &&
+ decodedData() == a2.decodedData();
}
-bool Attachment::operator!=( const Attachment &a2 ) const
+bool Attachment::operator!=(const Attachment &a2) const
{
- return !( *this == a2 );
+ return !(*this == a2);
}
+
+QDataStream& KCalCore::operator<<(QDataStream &out, const KCalCore::Attachment::Ptr &a)
+{
+ if (a)
+ out << a->d->mSize << a->d->mMimeType << a->d->mUri << a->d->mEncodedData << a->d->mLabel << a->d->mBinary << a->d->mLocal << a->d->mShowInline;
+ return out;
+}
+
+QDataStream& KCalCore::operator>>(QDataStream &in, const KCalCore::Attachment::Ptr &a)
+{
+ if (a)
+ in >> a->d->mSize >> a->d->mMimeType >> a->d->mUri >> a->d->mEncodedData >> a->d->mLabel >> a->d->mBinary >> a->d->mLocal >> a->d->mShowInline;
+ return in;
+}
+
diff --git a/kcalcore/attachment.h b/kcalcore/attachment.h
index e614103..3f94e79 100644
--- a/kcalcore/attachment.h
+++ b/kcalcore/attachment.h
@@ -34,6 +34,7 @@
#include <QtCore/QHash>
#include <QtCore/QString>
#include <QtCore/QSharedPointer>
+#include <QMetaType>
namespace KCalCore {
@@ -57,7 +58,7 @@ namespace KCalCore {
*/
class KCALCORE_EXPORT Attachment
{
- public:
+public:
/**
A shared pointer to an Attachment object.
*/
@@ -74,7 +75,7 @@ class KCALCORE_EXPORT Attachment
@param uri is the @acronym URI referred to by this attachment.
@param mime is the (optional) @acronym MIME type of the @p uri
*/
- explicit Attachment( const QString &uri, const QString &mime = QString() );
+ explicit Attachment(const QString &uri, const QString &mime = QString());
/**
Constructs an attachment consisting of a binary blob of data
@@ -83,15 +84,15 @@ class KCALCORE_EXPORT Attachment
@param base64 is the binary data in base64 format for the attachment.
@param mime is the (optional) @acronym MIME type of the attachment
*/
- explicit Attachment( const QByteArray &base64,
- const QString &mime = QString() );
+ explicit Attachment(const QByteArray &base64,
+ const QString &mime = QString());
/**
Constructs an attachment by copying another attachment.
@param attachment is the attachment to be copied.
*/
- Attachment( const Attachment &attachment );
+ Attachment(const Attachment &attachment);
/**
Destroys the attachment.
@@ -105,7 +106,7 @@ class KCALCORE_EXPORT Attachment
@see uri(), isUri()
*/
- void setUri( const QString &uri );
+ void setUri(const QString &uri);
/**
Returns the @acronym URI of the attachment.
@@ -135,7 +136,7 @@ class KCALCORE_EXPORT Attachment
@see data(), decodedData()
*/
- void setData( const QByteArray &base64 );
+ void setData(const QByteArray &base64);
/**
Returns a pointer to a QByteArray containing the base64 encoded
@@ -152,7 +153,7 @@ class KCALCORE_EXPORT Attachment
@see decodedData(), data()
*/
- void setDecodedData( const QByteArray &data );
+ void setDecodedData(const QByteArray &data);
/**
Returns a QByteArray containing the decoded base64 binary data of the
@@ -176,7 +177,7 @@ class KCALCORE_EXPORT Attachment
@see mimeType()
*/
- void setMimeType( const QString &mime );
+ void setMimeType(const QString &mime);
/**
Returns the @acronym MIME-type of the attachment.
@@ -194,7 +195,7 @@ class KCALCORE_EXPORT Attachment
@see showInline()
*/
- void setShowInline( bool showinline );
+ void setShowInline(bool showinline);
/**
Returns the attachment "show in-line" flag.
@@ -211,7 +212,7 @@ class KCALCORE_EXPORT Attachment
@see label()
*/
- void setLabel( const QString &label );
+ void setLabel(const QString &label);
/**
Returns the attachment label string.
@@ -227,7 +228,7 @@ class KCALCORE_EXPORT Attachment
@see local()
*/
- void setLocal( bool local );
+ void setLocal(bool local);
/**
Returns the attachment "local" flag.
@@ -235,39 +236,60 @@ class KCALCORE_EXPORT Attachment
bool isLocal() const;
/**
- Assignment operator.
+ Assignment operator.
+ @param attachment is the attachment to assign.
*/
- Attachment &operator=( const Attachment &attachment );
+ Attachment &operator=(const Attachment &attachment);
/**
Compare this with @p attachment for equality.
@param attachment is the attachment to compare.
@return true if the attachments are equal; false otherwise.
*/
- bool operator==( const Attachment &attachment ) const;
+ bool operator==(const Attachment &attachment) const;
/**
Compare this with @p attachment for inequality.
@param attachment is the attachment to compare.
@return true if the attachments are /not/ equal; false otherwise.
*/
- bool operator!=( const Attachment &attachment ) const;
+ bool operator!=(const Attachment &attachment) const;
- private:
+private:
//@cond PRIVATE
class Private;
Private *const d;
//@endcond
+
+ friend KCALCORE_EXPORT QDataStream &operator<<(QDataStream &s, const KCalCore::Attachment::Ptr &);
+ friend KCALCORE_EXPORT QDataStream &operator>>(QDataStream &s, const KCalCore::Attachment::Ptr &);
};
+/**
+ * Attachment serializer.
+ *
+ * @since 4.12
+ */
+KCALCORE_EXPORT QDataStream &operator<<(QDataStream &out, const KCalCore::Attachment::Ptr &);
+
+/**
+ * Attachment deserializer.
+ *
+ * @since 4.12
+ */
+KCALCORE_EXPORT QDataStream &operator>>(QDataStream &in, const KCalCore::Attachment::Ptr &);
+
}
-Q_DECLARE_TYPEINFO( KCalCore::Attachment::Ptr, Q_MOVABLE_TYPE );
+//@cond PRIVATE
+Q_DECLARE_TYPEINFO(KCalCore::Attachment::Ptr, Q_MOVABLE_TYPE);
+Q_DECLARE_METATYPE(KCalCore::Attachment::Ptr)
+//@endcond
//@cond PRIVATE
-inline uint qHash( const QSharedPointer<KCalCore::Attachment> &key )
+inline uint qHash(const QSharedPointer<KCalCore::Attachment> &key)
{
- return qHash<KCalCore::Attachment>( key.data() );
+ return qHash<KCalCore::Attachment>(key.data());
}
//@endcond
diff --git a/kcalcore/attendee.cpp b/kcalcore/attendee.cpp
index 900c7ec..da51441 100644
--- a/kcalcore/attendee.cpp
+++ b/kcalcore/attendee.cpp
@@ -32,6 +32,9 @@
*/
#include "attendee.h"
+
+#include <QDataStream>
+
using namespace KCalCore;
/**
@@ -41,7 +44,12 @@ using namespace KCalCore;
//@cond PRIVATE
class KCalCore::Attendee::Private
{
- public:
+public:
+ void setCuType(CuType cuType);
+ void setCuType(const QString &cuType);
+ CuType cuType() const;
+ QString cuTypeStr() const;
+
bool mRSVP;
Role mRole;
PartStat mStatus;
@@ -49,180 +57,262 @@ class KCalCore::Attendee::Private
QString mDelegate;
QString mDelegator;
CustomProperties mCustomProperties;
+private:
+ QString sCuType;
+ CuType mCuType;
};
//@endcond
-Attendee::Attendee( const QString &name, const QString &email, bool rsvp,
- Attendee::PartStat status, Attendee::Role role, const QString &uid )
- : d( new Attendee::Private )
+void KCalCore::Attendee::Private::setCuType(Attendee::CuType cuType)
+{
+ mCuType = cuType;
+ sCuType.clear();
+}
+
+void KCalCore::Attendee::Private::setCuType(const QString &cuType)
+{
+ const QString upper = cuType.toUpper();
+ if (upper == QLatin1String("INDIVIDUAL")) {
+ setCuType(Attendee::Individual);
+ } else if (upper == QLatin1String("GROUP")) {
+ setCuType(Attendee::Group);
+ } else if (upper == QLatin1String("RESOURCE")) {
+ setCuType(Attendee::Resource);
+ } else if (upper == QLatin1String("ROOM")) {
+ setCuType(Attendee::Room);
+ } else {
+ setCuType(Attendee::Unknown);
+ if (upper.startsWith(QLatin1String("X-")) || upper.startsWith(QLatin1String("IANA-"))) {
+ sCuType = upper;
+ }
+ }
+}
+
+Attendee::CuType KCalCore::Attendee::Private::cuType() const
{
- setName( name );
- setEmail( email );
- d->mRSVP = rsvp;
- d->mStatus = status;
- d->mRole = role;
- d->mUid = uid;
+ return mCuType;
}
-Attendee::Attendee( const Attendee &attendee )
- : Person( attendee ),
- d( new Attendee::Private( *attendee.d ) )
+QString KCalCore::Attendee::Private::cuTypeStr() const
+{
+ switch (mCuType) {
+ case Attendee::Individual:
+ return QLatin1String("INDIVIDUAL");
+ case Attendee::Group:
+ return QLatin1String("GROUP");
+ case Attendee::Resource:
+ return QLatin1String("RESOURCE");
+ case Attendee::Room:
+ return QLatin1String("ROOM");
+ case Attendee::Unknown:
+ if (sCuType.isEmpty()) {
+ return QLatin1String("UNKNOWN");
+ } else {
+ return sCuType;
+ }
+ }
+ return QLatin1String("UNKNOWN");
+}
+
+
+
+Attendee::Attendee(const QString &name, const QString &email, bool rsvp,
+ Attendee::PartStat status, Attendee::Role role, const QString &uid)
+ : d(new Attendee::Private)
+{
+ setName(name);
+ setEmail(email);
+ d->mRSVP = rsvp;
+ d->mStatus = status;
+ d->mRole = role;
+ d->mUid = uid;
+ d->setCuType(Attendee::Individual);
+}
+
+Attendee::Attendee(const Attendee &attendee)
+ : Person(attendee),
+ d(new Attendee::Private(*attendee.d))
{
}
Attendee::~Attendee()
{
- delete d;
+ delete d;
}
-bool KCalCore::Attendee::operator==( const Attendee &attendee ) const
+bool KCalCore::Attendee::operator==(const Attendee &attendee) const
{
- return
- ( Person & )*this == ( const Person & )attendee &&
- d->mRSVP == attendee.d->mRSVP &&
- d->mRole == attendee.d->mRole &&
- d->mStatus == attendee.d->mStatus &&
- d->mUid == attendee.d->mUid &&
- d->mDelegate == attendee.d->mDelegate &&
- d->mDelegator == attendee.d->mDelegator;
+ return
+ d->mUid == attendee.d->mUid &&
+ d->mRSVP == attendee.d->mRSVP &&
+ d->mRole == attendee.d->mRole &&
+ d->mStatus == attendee.d->mStatus &&
+ d->mDelegate == attendee.d->mDelegate &&
+ d->mDelegator == attendee.d->mDelegator &&
+ d->cuTypeStr() == attendee.d->cuTypeStr() &&
+ (const Person &)*this == (const Person &)attendee;
}
-bool KCalCore::Attendee::operator!=( const Attendee &attendee ) const
+bool KCalCore::Attendee::operator!=(const Attendee &attendee) const
{
- return !operator==( attendee );
+ return !operator==(attendee);
}
-Attendee &KCalCore::Attendee::operator=( const Attendee &attendee )
+Attendee &KCalCore::Attendee::operator=(const Attendee &attendee)
{
- // check for self assignment
- if ( &attendee == this ) {
+ // check for self assignment
+ if (&attendee == this) {
+ return *this;
+ }
+
+ *d = *attendee.d;
+ setName(attendee.name());
+ setEmail(attendee.email());
return *this;
- }
-
- *d = *attendee.d;
- setName( attendee.name() );
- setEmail( attendee.email() );
- return *this;
}
-void Attendee::setRSVP( bool r )
+void Attendee::setRSVP(bool r)
{
- d->mRSVP = r;
+ d->mRSVP = r;
}
bool Attendee::RSVP() const
{
- return d->mRSVP;
+ return d->mRSVP;
}
-void Attendee::setStatus( Attendee::PartStat status )
+void Attendee::setStatus(Attendee::PartStat status)
{
- d->mStatus = status;
+ d->mStatus = status;
}
Attendee::PartStat Attendee::status() const
{
- return d->mStatus;
+ return d->mStatus;
}
-void Attendee::setRole( Attendee::Role role )
+void Attendee::setCuType(Attendee::CuType cuType)
{
- d->mRole = role;
+ d->setCuType(cuType);
+}
+
+void Attendee::setCuType(const QString &cuType)
+{
+ d->setCuType(cuType);
+}
+
+Attendee::CuType Attendee::cuType() const
+{
+ return d->cuType();
+}
+
+QString Attendee::cuTypeStr() const
+{
+ return d->cuTypeStr();
+}
+
+void Attendee::setRole(Attendee::Role role)
+{
+ d->mRole = role;
}
Attendee::Role Attendee::role() const
{
- return d->mRole;
+ return d->mRole;
}
-void Attendee::setUid( const QString &uid )
+void Attendee::setUid(const QString &uid)
{
- d->mUid = uid;
+ d->mUid = uid;
}
QString Attendee::uid() const
{
- return d->mUid;
+ return d->mUid;
}
-void Attendee::setDelegate( const QString &delegate )
+void Attendee::setDelegate(const QString &delegate)
{
- d->mDelegate = delegate;
+ d->mDelegate = delegate;
}
QString Attendee::delegate() const
{
- return d->mDelegate;
+ return d->mDelegate;
}
-void Attendee::setDelegator( const QString &delegator )
+void Attendee::setDelegator(const QString &delegator)
{
- d->mDelegator = delegator;
+ d->mDelegator = delegator;
}
QString Attendee::delegator() const
{
- return d->mDelegator;
+ return d->mDelegator;
}
-void Attendee::setCustomProperty( const QByteArray &xname, const QString &xvalue )
+void Attendee::setCustomProperty(const QByteArray &xname, const QString &xvalue)
{
- d->mCustomProperties.setNonKDECustomProperty( xname, xvalue );
+ d->mCustomProperties.setNonKDECustomProperty(xname, xvalue);
}
CustomProperties &Attendee::customProperties()
{
- return d->mCustomProperties;
+ return d->mCustomProperties;
}
const CustomProperties &Attendee::customProperties() const
{
- return d->mCustomProperties;
-}
-
-QDataStream &KCalCore::operator<<( QDataStream &stream, const KCalCore::Attendee::Ptr &attendee )
-{
- KCalCore::Person::Ptr p( new KCalCore::Person( *( (Person *)attendee.data() ) ) );
- stream << p;
- return stream << attendee->d->mRSVP
- << int( attendee->d->mRole )
- << int( attendee->d->mStatus )
- << attendee->d->mUid
- << attendee->d->mDelegate
- << attendee->d->mDelegator
- << attendee->d->mCustomProperties;
-}
-
-QDataStream &KCalCore::operator>>( QDataStream &stream, KCalCore::Attendee::Ptr &attendee )
-{
- bool RSVP;
- Attendee::Role role;
- Attendee::PartStat status;
- QString uid;
- QString delegate;
- QString delegator;
- CustomProperties customProperties;
- uint role_int;
- uint status_int;
-
- KCalCore::Person::Ptr person( new Person() );
- stream >> person;
- stream >> RSVP
- >> role_int
- >> status_int
- >> uid
- >> delegate
- >> delegator
- >> customProperties;
-
- role = Attendee::Role( role_int );
- status = Attendee::PartStat( status_int );
-
- Attendee::Ptr att_temp( new KCalCore::Attendee( person->name(), person->email(),
- RSVP, status, role, uid ) );
- att_temp->setDelegate( delegate );
- att_temp->setDelegator( delegator );
- att_temp->d->mCustomProperties = customProperties;
- attendee.swap( att_temp );
- return stream;
+ return d->mCustomProperties;
+}
+
+QDataStream &KCalCore::operator<<(QDataStream &stream, const KCalCore::Attendee::Ptr &attendee)
+{
+ KCalCore::Person::Ptr p(new KCalCore::Person(*((Person *)attendee.data())));
+ stream << p;
+ return stream << attendee->d->mRSVP
+ << int(attendee->d->mRole)
+ << int(attendee->d->mStatus)
+ << attendee->d->mUid
+ << attendee->d->mDelegate
+ << attendee->d->mDelegator
+ << attendee->d->cuTypeStr()
+ << attendee->d->mCustomProperties;
+}
+
+QDataStream &KCalCore::operator>>(QDataStream &stream, KCalCore::Attendee::Ptr &attendee)
+{
+ bool RSVP;
+ Attendee::Role role;
+ Attendee::PartStat status;
+ QString uid;
+ QString delegate;
+ QString delegator;
+ QString cuType;
+ CustomProperties customProperties;
+ uint role_int;
+ uint status_int;
+
+ KCalCore::Person::Ptr person(new Person());
+ stream >> person;
+ stream >> RSVP
+ >> role_int
+ >> status_int
+ >> uid
+ >> delegate
+ >> delegator
+ >> cuType
+ >> customProperties;
+
+ role = Attendee::Role(role_int);
+ status = Attendee::PartStat(status_int);
+
+ Attendee::Ptr att_temp(new KCalCore::Attendee(person->name(), person->email(),
+ RSVP, status, role, uid));
+ att_temp->setDelegate(delegate);
+ att_temp->setDelegator(delegator);
+ att_temp->setCuType(cuType);
+ att_temp->d->mCustomProperties = customProperties;
+ attendee.swap(att_temp);
+ return stream;
}
diff --git a/kcalcore/attendee.h b/kcalcore/attendee.h
index 6319cb2..4604e2f 100644
--- a/kcalcore/attendee.h
+++ b/kcalcore/attendee.h
@@ -56,7 +56,7 @@ namespace KCalCore {
*/
class KCALCORE_EXPORT Attendee : private Person
{
- public:
+public:
using Person::setEmail;
using Person::email;
using Person::setName;
@@ -68,24 +68,43 @@ class KCALCORE_EXPORT Attendee : private Person
The meaning is specific to the incidence type in context.
*/
enum PartStat {
- NeedsAction, /**< Event, to-do or journal needs action (default) */
- Accepted, /**< Event, to-do or journal accepted */
- Declined, /**< Event, to-do or journal declined */
- Tentative, /**< Event or to-do tentatively accepted */
- Delegated, /**< Event or to-do delegated */
- Completed, /**< To-do completed */
- InProcess, /**< To-do in process of being completed */
- None
+ NeedsAction, /**< Event, to-do or journal needs action (default) */
+ Accepted, /**< Event, to-do or journal accepted */
+ Declined, /**< Event, to-do or journal declined */
+ Tentative, /**< Event or to-do tentatively accepted */
+ Delegated, /**< Event or to-do delegated */
+ Completed, /**< To-do completed */
+ InProcess, /**< To-do in process of being completed */
+ None
};
/**
The different types of participation roles.
*/
enum Role {
- ReqParticipant, /**< Participation is required (default) */
- OptParticipant, /**< Participation is optional */
- NonParticipant, /**< Non-Participant; copied for information purposes */
- Chair /**< Chairperson */
+ ReqParticipant, /**< Participation is required (default) */
+ OptParticipant, /**< Participation is optional */
+ NonParticipant, /**< Non-Participant; copied for information purposes */
+ Chair /**< Chairperson */
+ };
+
+
+ /**
+ * The different types of a participant.
+ *
+ * @since 4.14
+ */
+ enum CuType {
+ Individual, /**< An individual (default) */
+ Group, /**< A group of individuals */
+ Resource, /**< A physical resource */
+ Room, /**< A room resource */
+ Unknown /**< Otherwise not known */
+ /**
+ * Parameters that have to set via the QString variant of @setCuType() and @cuType()
+ * x-name ; Experimental cuType
+ * iana-token ; Other IANA-registered
+ */
};
/**
@@ -110,16 +129,16 @@ class KCALCORE_EXPORT Attendee : private Person
@param role is the #Role of the attendee.
@param uid is the @acronym UID of the attendee.
*/
- Attendee( const QString &name, const QString &email,
- bool rsvp = false, PartStat status = None,
- Role role = ReqParticipant, const QString &uid = QString() );
+ Attendee(const QString &name, const QString &email,
+ bool rsvp = false, PartStat status = None,
+ Role role = ReqParticipant, const QString &uid = QString());
/**
Constructs an attendee by copying another attendee.
@param attendee is the attendee to be copied.
*/
- Attendee( const Attendee &attendee );
+ Attendee(const Attendee &attendee);
/**
Destroys the attendee.
@@ -133,7 +152,7 @@ class KCALCORE_EXPORT Attendee : private Person
@see role()
*/
- void setRole( Role role );
+ void setRole(Role role);
/**
Returns the Role of the attendee.
@@ -149,7 +168,7 @@ class KCALCORE_EXPORT Attendee : private Person
@see uid()
*/
- void setUid ( const QString &uid );
+ void setUid(const QString &uid);
/**
Returns the @acronym UID of the attendee.
@@ -165,7 +184,7 @@ class KCALCORE_EXPORT Attendee : private Person
@see status()
*/
- void setStatus( PartStat status );
+ void setStatus(PartStat status);
/**
Returns the #PartStat of the attendee.
@@ -175,6 +194,48 @@ class KCALCORE_EXPORT Attendee : private Person
PartStat status() const;
/**
+ Sets the #CuType of the attendee to @p cuType.
+
+ @param cuType is the #CuType to use for the attendee.
+
+ @see cuType()
+
+ @since 4.14
+ */
+ void setCuType(CuType cuType);
+
+ /**
+ Sets the #CuType of the attendee to @p cuType.
+
+ @param cuType is the #CuType to use for the attendee.
+
+ @see cuType()
+
+ @since 4.14
+ */
+ void setCuType(const QString &cuType);
+
+
+ /**
+ Returns the #CuType of the attendee.
+
+ @see setCuType()
+
+ @since 4.14
+ */
+ CuType cuType() const;
+
+ /**
+ Returns the #CuType of the attendee.
+
+ @see setCuType()
+
+ @since 4.14
+ */
+ QString cuTypeStr() const;
+
+
+ /**
Sets the @acronym RSVP flag of the attendee to @p rsvp.
@param rsvp if set (true), the attendee is requested to reply to
@@ -182,7 +243,7 @@ class KCALCORE_EXPORT Attendee : private Person
@see RSVP()
*/
- void setRSVP( bool rsvp );
+ void setRSVP(bool rsvp);
/**
Returns the attendee @acronym RSVP flag.
@@ -196,14 +257,14 @@ class KCALCORE_EXPORT Attendee : private Person
@param attendee the attendee to compare.
*/
- bool operator==( const Attendee &attendee ) const;
+ bool operator==(const Attendee &attendee) const;
/**
Compares this with @p attendee for inequality.
@param attendee the attendee to compare.
*/
- bool operator!=( const Attendee &attendee ) const;
+ bool operator!=(const Attendee &attendee) const;
/**
Sets the delegate.
@@ -211,7 +272,7 @@ class KCALCORE_EXPORT Attendee : private Person
to attend the meeting.
@see delegate(), setDelegator().
*/
- void setDelegate( const QString &delegate );
+ void setDelegate(const QString &delegate);
/**
Returns the delegate.
@@ -225,7 +286,7 @@ class KCALCORE_EXPORT Attendee : private Person
have delegated their meeting attendance.
@see delegator(), setDelegate().
*/
- void setDelegator( const QString &delegator );
+ void setDelegator(const QString &delegator);
/**
Returns the delegator.
@@ -238,7 +299,7 @@ class KCALCORE_EXPORT Attendee : private Person
@param xname is the name of the property.
@param xvalue is its value.
*/
- void setCustomProperty( const QByteArray &xname, const QString &xvalue );
+ void setCustomProperty(const QByteArray &xname, const QString &xvalue);
/**
Returns a reference to the CustomProperties object
@@ -255,18 +316,18 @@ class KCALCORE_EXPORT Attendee : private Person
@param attendee is the attendee to copy.
*/
- Attendee &operator=( const Attendee &attendee );
+ Attendee &operator=(const Attendee &attendee);
- private:
+private:
//@cond PRIVATE
class Private;
Private *const d;
//@endcond
- friend KCALCORE_EXPORT QDataStream &operator<<( QDataStream &s,
- const KCalCore::Attendee::Ptr &attendee );
- friend KCALCORE_EXPORT QDataStream &operator>>( QDataStream &s,
- KCalCore::Attendee::Ptr &attendee );
+ friend KCALCORE_EXPORT QDataStream &operator<<(QDataStream &s,
+ const KCalCore::Attendee::Ptr &attendee);
+ friend KCALCORE_EXPORT QDataStream &operator>>(QDataStream &s,
+ KCalCore::Attendee::Ptr &attendee);
};
/**
@@ -274,20 +335,21 @@ class KCALCORE_EXPORT Attendee : private Person
@param stream is a QDataStream.
@param attendee is a pointer to a Attendee object to be serialized.
*/
-KCALCORE_EXPORT QDataStream &operator<<( QDataStream &stream,
- const KCalCore::Attendee::Ptr &attendee );
+KCALCORE_EXPORT QDataStream &operator<<(QDataStream &stream,
+ const KCalCore::Attendee::Ptr &attendee);
/**
Initializes an Attendee object from a data stream.
@param stream is a QDataStream.
@param attendee is a pointer to a Attendee object to be initialized.
*/
-KCALCORE_EXPORT QDataStream &operator>>( QDataStream &stream, KCalCore::Attendee::Ptr &attendee );
+KCALCORE_EXPORT QDataStream &operator>>(QDataStream &stream,
+ KCalCore::Attendee::Ptr &attendee);
}
//@cond PRIVATE
-Q_DECLARE_TYPEINFO( KCalCore::Attendee::Ptr, Q_MOVABLE_TYPE );
-Q_DECLARE_METATYPE( KCalCore::Attendee::Ptr )
+Q_DECLARE_TYPEINFO(KCalCore::Attendee::Ptr, Q_MOVABLE_TYPE);
+Q_DECLARE_METATYPE(KCalCore::Attendee::Ptr)
//@endcond
#endif
diff --git a/kcalcore/calendar.cpp b/kcalcore/calendar.cpp
index c60bb4a..6c521c9 100644
--- a/kcalcore/calendar.cpp
+++ b/kcalcore/calendar.cpp
@@ -40,10 +40,10 @@
#include "sorting.h"
#include "visitor.h"
-#include <QtCore/QDebug>
+#include <KDebug>
extern "C" {
- #include <icaltimezone.h>
+#include <icaltimezone.h>
}
#include <algorithm> // for std::remove()
@@ -57,34 +57,35 @@ using namespace KCalCore;
//@cond PRIVATE
class KCalCore::Calendar::Private
{
- public:
+public:
Private()
- : mTimeZones( new ICalTimeZones ),
- mModified( false ),
- mNewObserver( false ),
- mObserversEnabled( true ),
- mDefaultFilter( new CalFilter ),
- batchAddingInProgress( false )
+ : mTimeZones(new ICalTimeZones),
+ mModified(false),
+ mNewObserver(false),
+ mObserversEnabled(true),
+ mDefaultFilter(new CalFilter),
+ batchAddingInProgress(false),
+ mDeletionTracking(true)
{
- // Setup default filter, which does nothing
- mFilter = mDefaultFilter;
- mFilter->setEnabled( false );
+ // Setup default filter, which does nothing
+ mFilter = mDefaultFilter;
+ mFilter->setEnabled(false);
- mOwner = Person::Ptr( new Person() );
- mOwner->setName( "Unknown Name" );
- mOwner->setEmail( "unknown@nowhere" );
+ mOwner = Person::Ptr(new Person());
+ mOwner->setName(QLatin1String("Unknown Name"));
+ mOwner->setEmail(QLatin1String("unknown@nowhere"));
}
~Private()
{
- delete mTimeZones;
- mTimeZones = 0;
- if ( mFilter != mDefaultFilter ) {
- delete mFilter;
- }
- delete mDefaultFilter;
+ delete mTimeZones;
+ mTimeZones = 0;
+ if (mFilter != mDefaultFilter) {
+ delete mFilter;
+ }
+ delete mDefaultFilter;
}
- KDateTime::Spec timeZoneIdSpec( const QString &timeZoneId, bool view );
+ KDateTime::Spec timeZoneIdSpec(const QString &timeZoneId, bool view);
QString mProductId;
Person::Ptr mOwner;
@@ -113,33 +114,33 @@ class KCalCore::Calendar::Private
QString mDefaultNotebook; // uid of default notebook
QMap<QString, Incidence::List > mIncidenceRelations;
bool batchAddingInProgress;
-
+ bool mDeletionTracking;
};
/**
Make a QHash::value that returns a QVector.
*/
template <typename K, typename V>
-QVector<V> values( const QMultiHash<K,V> &c )
+QVector<V> values(const QMultiHash<K,V> &c)
{
- QVector<V> v;
- v.reserve( c.size() );
- for ( typename QMultiHash<K,V>::const_iterator it = c.begin(), end = c.end(); it != end; ++it ) {
- v.push_back( it.value() );
- }
- return v;
+ QVector<V> v;
+ v.reserve(c.size());
+ for (typename QMultiHash<K,V>::const_iterator it = c.begin(), end = c.end(); it != end; ++it) {
+ v.push_back(it.value());
+ }
+ return v;
}
template <typename K, typename V>
-QVector<V> values( const QMultiHash<K,V> &c, const K &x )
+QVector<V> values(const QMultiHash<K,V> &c, const K &x)
{
- QVector<V> v;
- typename QMultiHash<K,V>::const_iterator it = c.find( x );
- while ( it != c.end() && it.key() == x ) {
- v.push_back( it.value() );
- ++it;
- }
- return v;
+ QVector<V> v;
+ typename QMultiHash<K,V>::const_iterator it = c.find(x);
+ while (it != c.end() && it.key() == x) {
+ v.push_back(it.value());
+ ++it;
+ }
+ return v;
}
/**
@@ -149,27 +150,27 @@ QVector<V> values( const QMultiHash<K,V> &c, const K &x )
template<class T>
class AddVisitor : public Visitor
{
- public:
- AddVisitor( T *r ) : mResource( r ) {}
+public:
+ AddVisitor(T *r) : mResource(r) {}
- bool visit( Event::Ptr e )
+ bool visit(Event::Ptr e)
{
- return mResource->addEvent( e );
+ return mResource->addEvent(e);
}
- bool visit( Todo::Ptr t )
+ bool visit(Todo::Ptr t)
{
- return mResource->addTodo( t );
+ return mResource->addTodo(t);
}
- bool visit( Journal::Ptr j )
+ bool visit(Journal::Ptr j)
{
- return mResource->addJournal( j );
+ return mResource->addJournal(j);
}
- bool visit( FreeBusy::Ptr )
+ bool visit(FreeBusy::Ptr)
{
- return false;
+ return false;
}
- private:
+private:
T *mResource;
};
@@ -181,1323 +182,1368 @@ class AddVisitor : public Visitor
template<class T>
class DeleteVisitor : public Visitor
{
- public:
- DeleteVisitor( T *r ) : mResource( r ) {}
+public:
+ DeleteVisitor(T *r) : mResource(r) {}
- bool visit( Event::Ptr e )
+ bool visit(Event::Ptr e)
{
- mResource->deleteEvent( e );
- return true;
+ mResource->deleteEvent(e);
+ return true;
}
- bool visit( Todo::Ptr t )
+ bool visit(Todo::Ptr t)
{
- mResource->deleteTodo( t );
- return true;
+ mResource->deleteTodo(t);
+ return true;
}
- bool visit( Journal::Ptr j )
+ bool visit(Journal::Ptr j)
{
- mResource->deleteJournal( j );
- return true;
+ mResource->deleteJournal(j);
+ return true;
}
- bool visit( FreeBusy::Ptr )
+ bool visit(FreeBusy::Ptr)
{
- return false;
+ return false;
}
- private:
+private:
T *mResource;
};
//@endcond
-Calendar::Calendar( const KDateTime::Spec &timeSpec )
- : d( new KCalCore::Calendar::Private )
+Calendar::Calendar(const KDateTime::Spec &timeSpec)
+ : d(new KCalCore::Calendar::Private)
{
- d->mTimeSpec = timeSpec;
- d->mViewTimeSpec = timeSpec;
+ d->mTimeSpec = timeSpec;
+ d->mViewTimeSpec = timeSpec;
}
-Calendar::Calendar( const QString &timeZoneId )
- : d( new KCalCore::Calendar::Private )
+Calendar::Calendar(const QString &timeZoneId)
+ : d(new KCalCore::Calendar::Private)
{
- setTimeZoneId( timeZoneId );
+ setTimeZoneId(timeZoneId);
}
Calendar::~Calendar()
{
- delete d;
+ delete d;
}
Person::Ptr Calendar::owner() const
{
- return d->mOwner;
+ return d->mOwner;
}
-void Calendar::setOwner( const Person::Ptr &owner )
+void Calendar::setOwner(const Person::Ptr &owner)
{
- Q_ASSERT( owner );
- d->mOwner = owner;
- setModified( true );
+ Q_ASSERT(owner);
+ d->mOwner = owner;
+ setModified(true);
}
-void Calendar::setTimeSpec( const KDateTime::Spec &timeSpec )
+void Calendar::setTimeSpec(const KDateTime::Spec &timeSpec)
{
- d->mTimeSpec = timeSpec;
- d->mBuiltInTimeZone = ICalTimeZone();
- setViewTimeSpec( timeSpec );
+ d->mTimeSpec = timeSpec;
+ d->mBuiltInTimeZone = ICalTimeZone();
+ setViewTimeSpec(timeSpec);
- doSetTimeSpec( d->mTimeSpec );
+ doSetTimeSpec(d->mTimeSpec);
}
KDateTime::Spec Calendar::timeSpec() const
{
- return d->mTimeSpec;
+ return d->mTimeSpec;
}
-void Calendar::setTimeZoneId( const QString &timeZoneId )
+void Calendar::setTimeZoneId(const QString &timeZoneId)
{
- d->mTimeSpec = d->timeZoneIdSpec( timeZoneId, false );
- d->mViewTimeSpec = d->mTimeSpec;
- d->mBuiltInViewTimeZone = d->mBuiltInTimeZone;
+ d->mTimeSpec = d->timeZoneIdSpec(timeZoneId, false);
+ d->mViewTimeSpec = d->mTimeSpec;
+ d->mBuiltInViewTimeZone = d->mBuiltInTimeZone;
- doSetTimeSpec( d->mTimeSpec );
+ doSetTimeSpec(d->mTimeSpec);
}
//@cond PRIVATE
-KDateTime::Spec Calendar::Private::timeZoneIdSpec( const QString &timeZoneId,
- bool view )
-{
- if ( view ) {
- mBuiltInViewTimeZone = ICalTimeZone();
- } else {
- mBuiltInTimeZone = ICalTimeZone();
- }
- if ( timeZoneId == QLatin1String( "UTC" ) ) {
- return KDateTime::UTC;
- }
- ICalTimeZone tz = mTimeZones->zone( timeZoneId );
- if ( !tz.isValid() ) {
- ICalTimeZoneSource tzsrc;
- tz = tzsrc.parse( icaltimezone_get_builtin_timezone( timeZoneId.toLatin1() ) );
- if ( view ) {
- mBuiltInViewTimeZone = tz;
+KDateTime::Spec Calendar::Private::timeZoneIdSpec(const QString &timeZoneId,
+ bool view)
+{
+ if (view) {
+ mBuiltInViewTimeZone = ICalTimeZone();
} else {
- mBuiltInTimeZone = tz;
+ mBuiltInTimeZone = ICalTimeZone();
+ }
+ if (timeZoneId == QLatin1String("UTC")) {
+ return KDateTime::UTC;
+ }
+ ICalTimeZone tz = mTimeZones->zone(timeZoneId);
+ if (!tz.isValid()) {
+ ICalTimeZoneSource tzsrc;
+ tz = tzsrc.parse(icaltimezone_get_builtin_timezone(timeZoneId.toLatin1()));
+ if (view) {
+ mBuiltInViewTimeZone = tz;
+ } else {
+ mBuiltInTimeZone = tz;
+ }
+ }
+ if (tz.isValid()) {
+ return tz;
+ } else {
+ return KDateTime::ClockTime;
}
- }
- if ( tz.isValid() ) {
- return tz;
- } else {
- return KDateTime::ClockTime;
- }
}
//@endcond
QString Calendar::timeZoneId() const
{
- KTimeZone tz = d->mTimeSpec.timeZone();
- return tz.isValid() ? tz.name() : QString();
+ KTimeZone tz = d->mTimeSpec.timeZone();
+ return tz.isValid() ? tz.name() : QString();
}
-void Calendar::setViewTimeSpec( const KDateTime::Spec &timeSpec ) const
+void Calendar::setViewTimeSpec(const KDateTime::Spec &timeSpec) const
{
- d->mViewTimeSpec = timeSpec;
- d->mBuiltInViewTimeZone = ICalTimeZone();
+ d->mViewTimeSpec = timeSpec;
+ d->mBuiltInViewTimeZone = ICalTimeZone();
}
-void Calendar::setViewTimeZoneId( const QString &timeZoneId ) const
+void Calendar::setViewTimeZoneId(const QString &timeZoneId) const
{
- d->mViewTimeSpec = d->timeZoneIdSpec( timeZoneId, true );
+ d->mViewTimeSpec = d->timeZoneIdSpec(timeZoneId, true);
}
KDateTime::Spec Calendar::viewTimeSpec() const
{
- return d->mViewTimeSpec;
+ return d->mViewTimeSpec;
}
QString Calendar::viewTimeZoneId() const
{
- KTimeZone tz = d->mViewTimeSpec.timeZone();
- return tz.isValid() ? tz.name() : QString();
+ KTimeZone tz = d->mViewTimeSpec.timeZone();
+ return tz.isValid() ? tz.name() : QString();
}
ICalTimeZones *Calendar::timeZones() const
{
- return d->mTimeZones;
+ return d->mTimeZones;
}
-void Calendar::setTimeZones( ICalTimeZones *zones )
+void Calendar::setTimeZones(ICalTimeZones *zones)
{
- if ( !zones ) {
- return;
- }
+ if (!zones) {
+ return;
+ }
- if ( d->mTimeZones && ( d->mTimeZones != zones ) ) {
- delete d->mTimeZones;
- d->mTimeZones = 0;
- }
- d->mTimeZones = zones;
+ if (d->mTimeZones && (d->mTimeZones != zones)) {
+ delete d->mTimeZones;
+ d->mTimeZones = 0;
+ }
+ d->mTimeZones = zones;
}
-void Calendar::shiftTimes( const KDateTime::Spec &oldSpec, const KDateTime::Spec &newSpec )
+void Calendar::shiftTimes(const KDateTime::Spec &oldSpec, const KDateTime::Spec &newSpec)
{
- setTimeSpec( newSpec );
+ setTimeSpec(newSpec);
- int i, end;
- Event::List ev = events();
- for ( i = 0, end = ev.count(); i < end; ++i ) {
- ev[i]->shiftTimes( oldSpec, newSpec );
- }
+ int i, end;
+ Event::List ev = events();
+ for (i = 0, end = ev.count(); i < end; ++i) {
+ ev[i]->shiftTimes(oldSpec, newSpec);
+ }
- Todo::List to = todos();
- for ( i = 0, end = to.count(); i < end; ++i ) {
- to[i]->shiftTimes( oldSpec, newSpec );
- }
+ Todo::List to = todos();
+ for (i = 0, end = to.count(); i < end; ++i) {
+ to[i]->shiftTimes(oldSpec, newSpec);
+ }
- Journal::List jo = journals();
- for ( i = 0, end = jo.count(); i < end; ++i ) {
- jo[i]->shiftTimes( oldSpec, newSpec );
- }
+ Journal::List jo = journals();
+ for (i = 0, end = jo.count(); i < end; ++i) {
+ jo[i]->shiftTimes(oldSpec, newSpec);
+ }
}
-void Calendar::setFilter( CalFilter *filter )
+void Calendar::setFilter(CalFilter *filter)
{
- if ( filter ) {
- d->mFilter = filter;
- } else {
- d->mFilter = d->mDefaultFilter;
- }
+ if (filter) {
+ d->mFilter = filter;
+ } else {
+ d->mFilter = d->mDefaultFilter;
+ }
+ emit filterChanged();
}
CalFilter *Calendar::filter() const
{
- return d->mFilter;
+ return d->mFilter;
}
QStringList Calendar::categories() const
{
- Incidence::List rawInc( rawIncidences() );
- QStringList cats, thisCats;
- // @TODO: For now just iterate over all incidences. In the future,
- // the list of categories should be built when reading the file.
- for ( Incidence::List::ConstIterator i = rawInc.constBegin();
- i != rawInc.constEnd(); ++i ) {
- thisCats = (*i)->categories();
- for ( QStringList::ConstIterator si = thisCats.constBegin();
- si != thisCats.constEnd(); ++si ) {
- if ( !cats.contains( *si ) ) {
- cats.append( *si );
- }
+ Incidence::List rawInc(rawIncidences());
+ QStringList cats, thisCats;
+ // @TODO: For now just iterate over all incidences. In the future,
+ // the list of categories should be built when reading the file.
+ for (Incidence::List::ConstIterator i = rawInc.constBegin();
+ i != rawInc.constEnd(); ++i) {
+ thisCats = (*i)->categories();
+ for (QStringList::ConstIterator si = thisCats.constBegin();
+ si != thisCats.constEnd(); ++si) {
+ if (!cats.contains(*si)) {
+ cats.append(*si);
+ }
+ }
}
- }
- return cats;
+ return cats;
}
-Incidence::List Calendar::incidences( const QDate &date ) const
+Incidence::List Calendar::incidences(const QDate &date) const
{
- return mergeIncidenceList( events( date ), todos( date ), journals( date ) );
+ return mergeIncidenceList(events(date), todos(date), journals(date));
}
Incidence::List Calendar::incidences() const
{
- return mergeIncidenceList( events(), todos(), journals() );
+ return mergeIncidenceList(events(), todos(), journals());
}
Incidence::List Calendar::rawIncidences() const
{
- return mergeIncidenceList( rawEvents(), rawTodos(), rawJournals() );
+ return mergeIncidenceList(rawEvents(), rawTodos(), rawJournals());
}
-Incidence::List Calendar::instances( const Incidence::Ptr &incidence ) const
+Incidence::List Calendar::instances(const Incidence::Ptr &incidence) const
{
- if ( incidence ) {
- Event::List elist;
- Todo::List tlist;
- Journal::List jlist;
+ if (incidence) {
+ Event::List elist;
+ Todo::List tlist;
+ Journal::List jlist;
- if ( incidence->type() == Incidence::TypeEvent ) {
- elist = eventInstances( incidence );
- } else if ( incidence->type() == Incidence::TypeTodo ) {
- tlist = todoInstances( incidence );
- } else if ( incidence->type() == Incidence::TypeJournal ) {
- jlist = journalInstances( incidence );
+ if (incidence->type() == Incidence::TypeEvent) {
+ elist = eventInstances(incidence);
+ } else if (incidence->type() == Incidence::TypeTodo) {
+ tlist = todoInstances(incidence);
+ } else if (incidence->type() == Incidence::TypeJournal) {
+ jlist = journalInstances(incidence);
+ }
+ return mergeIncidenceList(elist, tlist, jlist);
+ } else {
+ return Incidence::List();
}
- return mergeIncidenceList( elist, tlist, jlist );
- } else {
- return Incidence::List();
- }
}
-Incidence::List Calendar::duplicates( const Incidence::Ptr &incidence )
+Incidence::List Calendar::duplicates(const Incidence::Ptr &incidence)
{
- if ( incidence ) {
- Incidence::List list;
- Incidence::List vals = values( d->mNotebookIncidences );
- Incidence::List::const_iterator it;
- for ( it = vals.constBegin(); it != vals.constEnd(); ++it ) {
- if ( ( ( incidence->dtStart() == (*it)->dtStart() ) ||
- ( !incidence->dtStart().isValid() && !(*it)->dtStart().isValid() ) ) &&
- ( incidence->summary() == (*it)->summary() ) ) {
- list.append( *it );
- }
+ if (incidence) {
+ Incidence::List list;
+ Incidence::List vals = values(d->mNotebookIncidences);
+ Incidence::List::const_iterator it;
+ for (it = vals.constBegin(); it != vals.constEnd(); ++it) {
+ if (((incidence->dtStart() == (*it)->dtStart()) ||
+ (!incidence->dtStart().isValid() && !(*it)->dtStart().isValid())) &&
+ (incidence->summary() == (*it)->summary())) {
+ list.append(*it);
+ }
+ }
+ return list;
+ } else {
+ return Incidence::List();
}
- return list;
- } else {
- return Incidence::List();
- }
}
-bool Calendar::addNotebook( const QString &notebook, bool isVisible )
+bool Calendar::addNotebook(const QString &notebook, bool isVisible)
{
- if ( d->mNotebooks.contains( notebook ) ) {
- return false;
- } else {
- d->mNotebooks.insert( notebook, isVisible );
- return true;
- }
+ if (d->mNotebooks.contains(notebook)) {
+ return false;
+ } else {
+ d->mNotebooks.insert(notebook, isVisible);
+ return true;
+ }
}
-bool Calendar::updateNotebook( const QString &notebook, bool isVisible )
+bool Calendar::updateNotebook(const QString &notebook, bool isVisible)
{
- if ( !d->mNotebooks.contains( notebook ) ) {
- return false;
- } else {
- d->mNotebooks.insert( notebook, isVisible );
- return true;
- }
+ if (!d->mNotebooks.contains(notebook)) {
+ return false;
+ } else {
+ d->mNotebooks.insert(notebook, isVisible);
+ return true;
+ }
}
-bool Calendar::deleteNotebook( const QString &notebook )
+bool Calendar::deleteNotebook(const QString &notebook)
{
- if ( !d->mNotebooks.contains( notebook ) ) {
- return false;
- } else {
- return d->mNotebooks.remove( notebook );
- }
+ if (!d->mNotebooks.contains(notebook)) {
+ return false;
+ } else {
+ return d->mNotebooks.remove(notebook);
+ }
}
-bool Calendar::setDefaultNotebook( const QString &notebook )
+bool Calendar::setDefaultNotebook(const QString &notebook)
{
- if ( !d->mNotebooks.contains( notebook ) ) {
- return false;
- } else {
- d->mDefaultNotebook = notebook;
- return true;
- }
+ if (!d->mNotebooks.contains(notebook)) {
+ return false;
+ } else {
+ d->mDefaultNotebook = notebook;
+ return true;
+ }
}
QString Calendar::defaultNotebook() const
{
- return d->mDefaultNotebook;
+ return d->mDefaultNotebook;
}
-bool Calendar::hasValidNotebook( const QString &notebook ) const
+bool Calendar::hasValidNotebook(const QString &notebook) const
{
- return d->mNotebooks.contains( notebook );
+ return d->mNotebooks.contains(notebook);
}
-bool Calendar::isVisible( const Incidence::Ptr &incidence ) const
+bool Calendar::isVisible(const Incidence::Ptr &incidence) const
{
- if ( d->mIncidenceVisibility.contains( incidence ) ) {
- return d->mIncidenceVisibility[incidence];
- }
- const QString nuid = notebook( incidence );
- bool rv;
- if ( d->mNotebooks.contains( nuid ) ) {
- rv = d->mNotebooks.value( nuid );
- } else {
- // NOTE returns true also for nonexisting notebooks for compatibility
- rv = true;
- }
- d->mIncidenceVisibility[incidence] = rv;
- return rv;
+ if (d->mIncidenceVisibility.contains(incidence)) {
+ return d->mIncidenceVisibility[incidence];
+ }
+ const QString nuid = notebook(incidence);
+ bool rv;
+ if (d->mNotebooks.contains(nuid)) {
+ rv = d->mNotebooks.value(nuid);
+ } else {
+ // NOTE returns true also for nonexisting notebooks for compatibility
+ rv = true;
+ }
+ d->mIncidenceVisibility[incidence] = rv;
+ return rv;
}
void Calendar::clearNotebookAssociations()
{
- d->mNotebookIncidences.clear();
- d->mUidToNotebook.clear();
- d->mIncidenceVisibility.clear();
+ d->mNotebookIncidences.clear();
+ d->mUidToNotebook.clear();
+ d->mIncidenceVisibility.clear();
}
-bool Calendar::setNotebook( const Incidence::Ptr &inc, const QString &notebook )
+bool Calendar::setNotebook(const Incidence::Ptr &inc, const QString &notebook)
{
- if ( !inc ) {
- return false;
- }
-
- if ( !notebook.isEmpty() &&
- !incidence( inc->uid(), inc->recurrenceId() ) ) {
- qWarning() << "cannot set notebook until incidence has been added";
- return false;
- }
+ if (!inc) {
+ return false;
+ }
- if ( d->mUidToNotebook.contains( inc->uid() ) ) {
- QString old = d->mUidToNotebook.value( inc->uid() );
- if ( !old.isEmpty() && notebook != old ) {
- if ( inc->hasRecurrenceId() ) {
- qWarning() << "cannot set notebook for child incidences";
+ if (!notebook.isEmpty() &&
+ !incidence(inc->uid(), inc->recurrenceId())) {
+ kWarning() << "cannot set notebook until incidence has been added";
return false;
- }
- // Move all possible children also.
- Incidence::List list = instances( inc );
- Incidence::List::Iterator it;
- for ( it = list.begin(); it != list.end(); ++it ) {
- d->mNotebookIncidences.remove( old, *it );
- d->mNotebookIncidences.insert( notebook, *it );
- }
- notifyIncidenceChanged( inc ); // for removing from old notebook
- // don not remove from mUidToNotebook to keep deleted incidences
- d->mNotebookIncidences.remove( old, inc );
}
- }
- if ( !notebook.isEmpty() ) {
- d->mUidToNotebook.insert( inc->uid(), notebook );
- d->mNotebookIncidences.insert( notebook, inc );
- qDebug() << "setting notebook" << notebook << "for" << inc->uid();
- notifyIncidenceChanged( inc ); // for inserting into new notebook
- }
- return true;
+ if (d->mUidToNotebook.contains(inc->uid())) {
+ QString old = d->mUidToNotebook.value(inc->uid());
+ if (!old.isEmpty() && notebook != old) {
+ if (inc->hasRecurrenceId()) {
+ kWarning() << "cannot set notebook for child incidences";
+ return false;
+ }
+ // Move all possible children also.
+ Incidence::List list = instances(inc);
+ Incidence::List::Iterator it;
+ for (it = list.begin(); it != list.end(); ++it) {
+ d->mNotebookIncidences.remove(old, *it);
+ d->mNotebookIncidences.insert(notebook, *it);
+ }
+ notifyIncidenceChanged(inc); // for removing from old notebook
+ // don not remove from mUidToNotebook to keep deleted incidences
+ d->mNotebookIncidences.remove(old, inc);
+ }
+ }
+ if (!notebook.isEmpty()) {
+ d->mUidToNotebook.insert(inc->uid(), notebook);
+ d->mNotebookIncidences.insert(notebook, inc);
+ kDebug() << "setting notebook" << notebook << "for" << inc->uid();
+ notifyIncidenceChanged(inc); // for inserting into new notebook
+ }
+
+ return true;
}
-QString Calendar::notebook( const Incidence::Ptr &incidence ) const
+QString Calendar::notebook(const Incidence::Ptr &incidence) const
{
- if ( incidence ) {
- return d->mUidToNotebook.value( incidence->uid() );
- } else {
- return QString();
- }
+ if (incidence) {
+ return d->mUidToNotebook.value(incidence->uid());
+ } else {
+ return QString();
+ }
}
-QString Calendar::notebook( const QString &uid ) const
+QString Calendar::notebook(const QString &uid) const
{
- return d->mUidToNotebook.value( uid );
+ return d->mUidToNotebook.value(uid);
}
QStringList Calendar::notebooks() const
{
- return d->mNotebookIncidences.uniqueKeys();
+ return d->mNotebookIncidences.uniqueKeys();
}
-Incidence::List Calendar::incidences( const QString &notebook ) const
+Incidence::List Calendar::incidences(const QString &notebook) const
{
- if ( notebook.isEmpty() ) {
- return values( d->mNotebookIncidences );
- } else {
- return values( d->mNotebookIncidences, notebook );
- }
+ if (notebook.isEmpty()) {
+ return values(d->mNotebookIncidences);
+ } else {
+ return values(d->mNotebookIncidences, notebook);
+ }
}
/** static */
-Event::List Calendar::sortEvents( const Event::List &eventList,
- EventSortField sortField,
- SortDirection sortDirection )
+Event::List Calendar::sortEvents(const Event::List &eventList,
+ EventSortField sortField,
+ SortDirection sortDirection)
{
- if ( eventList.isEmpty() ) {
- return Event::List();
- }
+ if (eventList.isEmpty()) {
+ return Event::List();
+ }
- Event::List eventListSorted;
+ Event::List eventListSorted;
- // Notice we alphabetically presort Summaries first.
- // We do this so comparison "ties" stay in a nice order.
- eventListSorted = eventList;
- switch( sortField ) {
- case EventSortUnsorted:
- break;
+ // Notice we alphabetically presort Summaries first.
+ // We do this so comparison "ties" stay in a nice order.
+ eventListSorted = eventList;
+ switch (sortField) {
+ case EventSortUnsorted:
+ break;
- case EventSortStartDate:
- if ( sortDirection == SortDirectionAscending ) {
- qSort( eventListSorted.begin(), eventListSorted.end(), Events::startDateLessThan );
- } else {
- qSort( eventListSorted.begin(), eventListSorted.end(), Events::startDateMoreThan );
- }
- break;
+ case EventSortStartDate:
+ if (sortDirection == SortDirectionAscending) {
+ qSort(eventListSorted.begin(), eventListSorted.end(), Events::startDateLessThan);
+ } else {
+ qSort(eventListSorted.begin(), eventListSorted.end(), Events::startDateMoreThan);
+ }
+ break;
- case EventSortEndDate:
- if ( sortDirection == SortDirectionAscending ) {
- qSort( eventListSorted.begin(), eventListSorted.end(), Events::endDateLessThan );
- } else {
- qSort( eventListSorted.begin(), eventListSorted.end(), Events::endDateMoreThan );
- }
- break;
+ case EventSortEndDate:
+ if (sortDirection == SortDirectionAscending) {
+ qSort(eventListSorted.begin(), eventListSorted.end(), Events::endDateLessThan);
+ } else {
+ qSort(eventListSorted.begin(), eventListSorted.end(), Events::endDateMoreThan);
+ }
+ break;
- case EventSortSummary:
- if ( sortDirection == SortDirectionAscending ) {
- qSort( eventListSorted.begin(), eventListSorted.end(), Events::summaryLessThan );
- } else {
- qSort( eventListSorted.begin(), eventListSorted.end(), Events::summaryMoreThan );
+ case EventSortSummary:
+ if (sortDirection == SortDirectionAscending) {
+ qSort(eventListSorted.begin(), eventListSorted.end(), Events::summaryLessThan);
+ } else {
+ qSort(eventListSorted.begin(), eventListSorted.end(), Events::summaryMoreThan);
+ }
+ break;
}
- break;
- }
- return eventListSorted;
+ return eventListSorted;
}
-Event::List Calendar::events( const QDate &date,
- const KDateTime::Spec &timeSpec,
- EventSortField sortField,
- SortDirection sortDirection ) const
+Event::List Calendar::events(const QDate &date,
+ const KDateTime::Spec &timeSpec,
+ EventSortField sortField,
+ SortDirection sortDirection) const
{
- Event::List el = rawEventsForDate( date, timeSpec, sortField, sortDirection );
- d->mFilter->apply( &el );
- return el;
+ Event::List el = rawEventsForDate(date, timeSpec, sortField, sortDirection);
+ d->mFilter->apply(&el);
+ return el;
}
-Event::List Calendar::events( const KDateTime &dt ) const
+Event::List Calendar::events(const KDateTime &dt) const
{
- Event::List el = rawEventsForDate( dt );
- d->mFilter->apply( &el );
- return el;
+ Event::List el = rawEventsForDate(dt);
+ d->mFilter->apply(&el);
+ return el;
}
-Event::List Calendar::events( const QDate &start, const QDate &end,
- const KDateTime::Spec &timeSpec,
- bool inclusive ) const
+Event::List Calendar::events(const QDate &start, const QDate &end,
+ const KDateTime::Spec &timeSpec,
+ bool inclusive) const
{
- Event::List el = rawEvents( start, end, timeSpec, inclusive );
- d->mFilter->apply( &el );
- return el;
+ Event::List el = rawEvents(start, end, timeSpec, inclusive);
+ d->mFilter->apply(&el);
+ return el;
}
-Event::List Calendar::events( EventSortField sortField,
- SortDirection sortDirection ) const
+Event::List Calendar::events(EventSortField sortField,
+ SortDirection sortDirection) const
{
- Event::List el = rawEvents( sortField, sortDirection );
- d->mFilter->apply( &el );
- return el;
+ Event::List el = rawEvents(sortField, sortDirection);
+ d->mFilter->apply(&el);
+ return el;
}
-bool Calendar::addIncidence( const Incidence::Ptr &incidence )
+bool Calendar::addIncidence(const Incidence::Ptr &incidence)
{
- if ( !incidence ) {
- return false;
- }
+ if (!incidence) {
+ return false;
+ }
- AddVisitor<Calendar> v( this );
- return incidence->accept( v, incidence );
+ AddVisitor<Calendar> v(this);
+ return incidence->accept(v, incidence);
}
-bool Calendar::deleteIncidence( const Incidence::Ptr &incidence )
+bool Calendar::deleteIncidence(const Incidence::Ptr &incidence)
{
- if ( !incidence ) {
- return false;
- }
+ if (!incidence) {
+ return false;
+ }
- if ( beginChange( incidence ) ) {
- DeleteVisitor<Calendar> v( this );
- const bool result = incidence->accept( v, incidence );
- endChange( incidence );
- return result;
- } else {
- return false;
- }
+ if (beginChange(incidence)) {
+ DeleteVisitor<Calendar> v(this);
+ const bool result = incidence->accept(v, incidence);
+ endChange(incidence);
+ return result;
+ } else {
+ return false;
+ }
+}
+
+Incidence::Ptr Calendar::createException(const Incidence::Ptr &incidence,
+ const KDateTime &recurrenceId,
+ bool thisAndFuture)
+{
+ Q_ASSERT(recurrenceId.isValid());
+ if (!incidence || !incidence->recurs() || !recurrenceId.isValid()) {
+ return Incidence::Ptr();
+ }
+
+ Incidence::Ptr newInc(incidence->clone());
+ newInc->setCreated(KDateTime::currentUtcDateTime());
+ newInc->setRevision(0);
+ //Recurring exceptions are not support for now
+ newInc->clearRecurrence();
+
+ newInc->setRecurrenceId(recurrenceId);
+ newInc->setThisAndFuture(thisAndFuture);
+ newInc->setDtStart(recurrenceId);
+
+ // Calculate and set the new end of the incidence
+ KDateTime end = incidence->dateTime(IncidenceBase::RoleEnd);
+
+ if (end.isValid()) {
+ if (incidence->dtStart().isDateOnly()) {
+ int offset = incidence->dtStart().daysTo(recurrenceId);
+ end = end.addDays(offset);
+ } else {
+ qint64 offset = incidence->dtStart().secsTo_long(recurrenceId);
+ end = end.addSecs(offset);
+ }
+ newInc->setDateTime(end, IncidenceBase::RoleEnd);
+ }
+ return newInc;
}
// Dissociate a single occurrence or all future occurrences from a recurring
// sequence. The new incidence is returned, but not automatically inserted
// into the calendar, which is left to the calling application.
-Incidence::Ptr Calendar::dissociateOccurrence( const Incidence::Ptr &incidence,
- const QDate &date,
- const KDateTime::Spec &spec,
- bool single )
+Incidence::Ptr Calendar::dissociateOccurrence(const Incidence::Ptr &incidence,
+ const QDate &date,
+ const KDateTime::Spec &spec,
+ bool single)
{
- if ( !incidence || !incidence->recurs() ) {
- return Incidence::Ptr();
- }
-
- Incidence::Ptr newInc( incidence->clone() );
- newInc->recreate();
- // Do not call setRelatedTo() when dissociating recurring to-dos, otherwise the new to-do
- // will appear as a child. Originally, we planned to set a relation with reltype SIBLING
- // when dissociating to-dos, but currently kcalcore only supports reltype PARENT.
- // We can uncomment the following line when we support the PARENT reltype.
- //newInc->setRelatedTo( incidence );
- Recurrence *recur = newInc->recurrence();
- if ( single ) {
- recur->clear();
- } else {
- // Adjust the recurrence for the future incidences. In particular adjust
- // the "end after n occurrences" rules! "No end date" and "end by ..."
- // don't need to be modified.
- int duration = recur->duration();
- if ( duration > 0 ) {
- int doneduration = recur->durationTo( date.addDays( -1 ) );
- if ( doneduration >= duration ) {
- qDebug() << "The dissociated event already occurred more often"
- << "than it was supposed to ever occur. ERROR!";
+ if (!incidence || !incidence->recurs()) {
+ return Incidence::Ptr();
+ }
+
+ Incidence::Ptr newInc(incidence->clone());
+ newInc->recreate();
+ // Do not call setRelatedTo() when dissociating recurring to-dos, otherwise the new to-do
+ // will appear as a child. Originally, we planned to set a relation with reltype SIBLING
+ // when dissociating to-dos, but currently kcalcore only supports reltype PARENT.
+ // We can uncomment the following line when we support the PARENT reltype.
+ //newInc->setRelatedTo( incidence );
+ Recurrence *recur = newInc->recurrence();
+ if (single) {
recur->clear();
- } else {
- recur->setDuration( duration - doneduration );
- }
- }
- }
- // Adjust the date of the incidence
- if ( incidence->type() == Incidence::TypeEvent ) {
- Event::Ptr ev = newInc.staticCast<Event>();
- KDateTime start( ev->dtStart() );
- int daysTo = start.toTimeSpec( spec ).date().daysTo( date );
- ev->setDtStart( start.addDays( daysTo ) );
- ev->setDtEnd( ev->dtEnd().addDays( daysTo ) );
- } else if ( incidence->type() == Incidence::TypeTodo ) {
- Todo::Ptr td = newInc.staticCast<Todo>();
- bool haveOffset = false;
- int daysTo = 0;
- if ( td->hasDueDate() ) {
- KDateTime due( td->dtDue() );
- daysTo = due.toTimeSpec( spec ).date().daysTo( date );
- td->setDtDue( due.addDays( daysTo ), true );
- haveOffset = true;
- }
- if ( td->hasStartDate() ) {
- KDateTime start( td->dtStart() );
- if ( !haveOffset ) {
- daysTo = start.toTimeSpec( spec ).date().daysTo( date );
- }
- td->setDtStart( start.addDays( daysTo ) );
- haveOffset = true;
- }
- }
- recur = incidence->recurrence();
- if ( recur ) {
- if ( single ) {
- recur->addExDate( date );
} else {
- // Make sure the recurrence of the past events ends
- // at the corresponding day
- recur->setEndDate( date.addDays(-1) );
+ // Adjust the recurrence for the future incidences. In particular adjust
+ // the "end after n occurrences" rules! "No end date" and "end by ..."
+ // don't need to be modified.
+ int duration = recur->duration();
+ if (duration > 0) {
+ int doneduration = recur->durationTo(date.addDays(-1));
+ if (doneduration >= duration) {
+ kDebug() << "The dissociated event already occurred more often"
+ << "than it was supposed to ever occur. ERROR!";
+ recur->clear();
+ } else {
+ recur->setDuration(duration - doneduration);
+ }
+ }
}
- }
- return newInc;
+ // Adjust the date of the incidence
+ if (incidence->type() == Incidence::TypeEvent) {
+ Event::Ptr ev = newInc.staticCast<Event>();
+ KDateTime start(ev->dtStart());
+ int daysTo = start.toTimeSpec(spec).date().daysTo(date);
+ ev->setDtStart(start.addDays(daysTo));
+ ev->setDtEnd(ev->dtEnd().addDays(daysTo));
+ } else if (incidence->type() == Incidence::TypeTodo) {
+ Todo::Ptr td = newInc.staticCast<Todo>();
+ bool haveOffset = false;
+ int daysTo = 0;
+ if (td->hasDueDate()) {
+ KDateTime due(td->dtDue());
+ daysTo = due.toTimeSpec(spec).date().daysTo(date);
+ td->setDtDue(due.addDays(daysTo), true);
+ haveOffset = true;
+ }
+ if (td->hasStartDate()) {
+ KDateTime start(td->dtStart());
+ if (!haveOffset) {
+ daysTo = start.toTimeSpec(spec).date().daysTo(date);
+ }
+ td->setDtStart(start.addDays(daysTo));
+ haveOffset = true;
+ }
+ }
+ recur = incidence->recurrence();
+ if (recur) {
+ if (single) {
+ recur->addExDate(date);
+ } else {
+ // Make sure the recurrence of the past events ends
+ // at the corresponding day
+ recur->setEndDate(date.addDays(-1));
+ }
+ }
+ return newInc;
}
-Incidence::Ptr Calendar::incidence( const QString &uid,
- const KDateTime &recurrenceId ) const
+Incidence::Ptr Calendar::incidence(const QString &uid,
+ const KDateTime &recurrenceId) const
{
- Incidence::Ptr i = event( uid, recurrenceId );
- if ( i ) {
- return i;
- }
+ Incidence::Ptr i = event(uid, recurrenceId);
+ if (i) {
+ return i;
+ }
- i = todo( uid, recurrenceId );
- if ( i ) {
- return i;
- }
+ i = todo(uid, recurrenceId);
+ if (i) {
+ return i;
+ }
- i = journal( uid, recurrenceId );
- return i;
+ i = journal(uid, recurrenceId);
+ return i;
}
-Incidence::Ptr Calendar::deleted( const QString &uid, const KDateTime &recurrenceId ) const
+Incidence::Ptr Calendar::deleted(const QString &uid, const KDateTime &recurrenceId) const
{
- Incidence::Ptr i = deletedEvent( uid, recurrenceId );
- if ( i ) {
- return i;
- }
+ Incidence::Ptr i = deletedEvent(uid, recurrenceId);
+ if (i) {
+ return i;
+ }
- i = deletedTodo( uid, recurrenceId );
- if ( i ) {
- return i;
- }
+ i = deletedTodo(uid, recurrenceId);
+ if (i) {
+ return i;
+ }
- i = deletedJournal( uid, recurrenceId );
- return i;
+ i = deletedJournal(uid, recurrenceId);
+ return i;
}
-Incidence::List Calendar::incidencesFromSchedulingID( const QString &sid ) const
+Incidence::List Calendar::incidencesFromSchedulingID(const QString &sid) const
{
- Incidence::List result;
- const Incidence::List incidences = rawIncidences();
- Incidence::List::const_iterator it = incidences.begin();
- for ( ; it != incidences.end(); ++it ) {
- if ( (*it)->schedulingID() == sid ) {
- result.append( *it );
+ Incidence::List result;
+ const Incidence::List incidences = rawIncidences();
+ Incidence::List::const_iterator it = incidences.begin();
+ for (; it != incidences.end(); ++it) {
+ if ((*it)->schedulingID() == sid) {
+ result.append(*it);
+ }
}
- }
- return result;
+ return result;
}
-Incidence::Ptr Calendar::incidenceFromSchedulingID( const QString &uid ) const
+Incidence::Ptr Calendar::incidenceFromSchedulingID(const QString &uid) const
{
- const Incidence::List incidences = rawIncidences();
- Incidence::List::const_iterator it = incidences.begin();
- for ( ; it != incidences.end(); ++it ) {
- if ( (*it)->schedulingID() == uid ) {
- // Touchdown, and the crowd goes wild
- return *it;
+ const Incidence::List incidences = rawIncidences();
+ Incidence::List::const_iterator it = incidences.begin();
+ for (; it != incidences.end(); ++it) {
+ if ((*it)->schedulingID() == uid) {
+ // Touchdown, and the crowd goes wild
+ return *it;
+ }
}
- }
- // Not found
- return Incidence::Ptr();
+ // Not found
+ return Incidence::Ptr();
}
/** static */
-Todo::List Calendar::sortTodos( const Todo::List &todoList,
- TodoSortField sortField,
- SortDirection sortDirection )
+Todo::List Calendar::sortTodos(const Todo::List &todoList,
+ TodoSortField sortField,
+ SortDirection sortDirection)
{
- if ( todoList.isEmpty() ) {
- return Todo::List();
- }
+ if (todoList.isEmpty()) {
+ return Todo::List();
+ }
- Todo::List todoListSorted;
+ Todo::List todoListSorted;
- // Notice we alphabetically presort Summaries first.
- // We do this so comparison "ties" stay in a nice order.
+ // Notice we alphabetically presort Summaries first.
+ // We do this so comparison "ties" stay in a nice order.
- // Note that To-dos may not have Start DateTimes nor due DateTimes.
+ // Note that To-dos may not have Start DateTimes nor due DateTimes.
- todoListSorted = todoList;
- switch( sortField ) {
- case TodoSortUnsorted:
- break;
+ todoListSorted = todoList;
+ switch (sortField) {
+ case TodoSortUnsorted:
+ break;
- case TodoSortStartDate:
- if ( sortDirection == SortDirectionAscending ) {
- qSort( todoListSorted.begin(), todoListSorted.end(), Todos::startDateLessThan );
- } else {
- qSort( todoListSorted.begin(), todoListSorted.end(), Todos::startDateMoreThan );
- }
- break;
+ case TodoSortStartDate:
+ if (sortDirection == SortDirectionAscending) {
+ qSort(todoListSorted.begin(), todoListSorted.end(), Todos::startDateLessThan);
+ } else {
+ qSort(todoListSorted.begin(), todoListSorted.end(), Todos::startDateMoreThan);
+ }
+ break;
- case TodoSortDueDate:
- if ( sortDirection == SortDirectionAscending ) {
- qSort( todoListSorted.begin(), todoListSorted.end(), Todos::dueDateLessThan );
- } else {
- qSort( todoListSorted.begin(), todoListSorted.end(), Todos::dueDateMoreThan );
- }
- break;
+ case TodoSortDueDate:
+ if (sortDirection == SortDirectionAscending) {
+ qSort(todoListSorted.begin(), todoListSorted.end(), Todos::dueDateLessThan);
+ } else {
+ qSort(todoListSorted.begin(), todoListSorted.end(), Todos::dueDateMoreThan);
+ }
+ break;
- case TodoSortPriority:
- if ( sortDirection == SortDirectionAscending ) {
- qSort( todoListSorted.begin(), todoListSorted.end(), Todos::priorityLessThan );
- } else {
- qSort( todoListSorted.begin(), todoListSorted.end(), Todos::priorityMoreThan );
- }
- break;
+ case TodoSortPriority:
+ if (sortDirection == SortDirectionAscending) {
+ qSort(todoListSorted.begin(), todoListSorted.end(), Todos::priorityLessThan);
+ } else {
+ qSort(todoListSorted.begin(), todoListSorted.end(), Todos::priorityMoreThan);
+ }
+ break;
- case TodoSortPercentComplete:
- if ( sortDirection == SortDirectionAscending ) {
- qSort( todoListSorted.begin(), todoListSorted.end(), Todos::percentLessThan );
- } else {
- qSort( todoListSorted.begin(), todoListSorted.end(), Todos::percentMoreThan );
- }
- break;
+ case TodoSortPercentComplete:
+ if (sortDirection == SortDirectionAscending) {
+ qSort(todoListSorted.begin(), todoListSorted.end(), Todos::percentLessThan);
+ } else {
+ qSort(todoListSorted.begin(), todoListSorted.end(), Todos::percentMoreThan);
+ }
+ break;
- case TodoSortSummary:
- if ( sortDirection == SortDirectionAscending ) {
- qSort( todoListSorted.begin(), todoListSorted.end(), Todos::summaryLessThan );
- } else {
- qSort( todoListSorted.begin(), todoListSorted.end(), Todos::summaryMoreThan );
- }
- break;
+ case TodoSortSummary:
+ if (sortDirection == SortDirectionAscending) {
+ qSort(todoListSorted.begin(), todoListSorted.end(), Todos::summaryLessThan);
+ } else {
+ qSort(todoListSorted.begin(), todoListSorted.end(), Todos::summaryMoreThan);
+ }
+ break;
- case TodoSortCreated:
- if ( sortDirection == SortDirectionAscending ) {
- qSort( todoListSorted.begin(), todoListSorted.end(), Todos::createdLessThan );
- } else {
- qSort( todoListSorted.begin(), todoListSorted.end(), Todos::createdMoreThan );
+ case TodoSortCreated:
+ if (sortDirection == SortDirectionAscending) {
+ qSort(todoListSorted.begin(), todoListSorted.end(), Todos::createdLessThan);
+ } else {
+ qSort(todoListSorted.begin(), todoListSorted.end(), Todos::createdMoreThan);
+ }
+ break;
}
- break;
- }
- return todoListSorted;
+ return todoListSorted;
}
-Todo::List Calendar::todos( TodoSortField sortField,
- SortDirection sortDirection ) const
+Todo::List Calendar::todos(TodoSortField sortField,
+ SortDirection sortDirection) const
{
- Todo::List tl = rawTodos( sortField, sortDirection );
- d->mFilter->apply( &tl );
- return tl;
+ Todo::List tl = rawTodos(sortField, sortDirection);
+ d->mFilter->apply(&tl);
+ return tl;
}
-Todo::List Calendar::todos( const QDate &date ) const
+Todo::List Calendar::todos(const QDate &date) const
{
- Todo::List el = rawTodosForDate( date );
- d->mFilter->apply( &el );
- return el;
+ Todo::List el = rawTodosForDate(date);
+ d->mFilter->apply(&el);
+ return el;
}
-Todo::List Calendar::todos( const QDate &start, const QDate &end,
- const KDateTime::Spec &timespec, bool inclusive ) const
+Todo::List Calendar::todos(const QDate &start, const QDate &end,
+ const KDateTime::Spec &timespec, bool inclusive) const
{
- Todo::List tl = rawTodos( start, end, timespec, inclusive );
- d->mFilter->apply( &tl );
- return tl;
+ Todo::List tl = rawTodos(start, end, timespec, inclusive);
+ d->mFilter->apply(&tl);
+ return tl;
}
/** static */
-Journal::List Calendar::sortJournals( const Journal::List &journalList,
- JournalSortField sortField,
- SortDirection sortDirection )
+Journal::List Calendar::sortJournals(const Journal::List &journalList,
+ JournalSortField sortField,
+ SortDirection sortDirection)
{
- if ( journalList.isEmpty() ) {
- return Journal::List();
- }
+ if (journalList.isEmpty()) {
+ return Journal::List();
+ }
- Journal::List journalListSorted = journalList;
+ Journal::List journalListSorted = journalList;
- switch( sortField ) {
- case JournalSortUnsorted:
- break;
+ switch (sortField) {
+ case JournalSortUnsorted:
+ break;
- case JournalSortDate:
- if ( sortDirection == SortDirectionAscending ) {
- qSort( journalListSorted.begin(), journalListSorted.end(), Journals::dateLessThan );
- } else {
- qSort( journalListSorted.begin(), journalListSorted.end(), Journals::dateMoreThan );
- }
- break;
+ case JournalSortDate:
+ if (sortDirection == SortDirectionAscending) {
+ qSort(journalListSorted.begin(), journalListSorted.end(), Journals::dateLessThan);
+ } else {
+ qSort(journalListSorted.begin(), journalListSorted.end(), Journals::dateMoreThan);
+ }
+ break;
- case JournalSortSummary:
- if ( sortDirection == SortDirectionAscending ) {
- qSort( journalListSorted.begin(), journalListSorted.end(), Journals::summaryLessThan );
- } else {
- qSort( journalListSorted.begin(), journalListSorted.end(), Journals::summaryMoreThan );
+ case JournalSortSummary:
+ if (sortDirection == SortDirectionAscending) {
+ qSort(journalListSorted.begin(), journalListSorted.end(), Journals::summaryLessThan);
+ } else {
+ qSort(journalListSorted.begin(), journalListSorted.end(), Journals::summaryMoreThan);
+ }
+ break;
}
- break;
- }
- return journalListSorted;
+ return journalListSorted;
}
-Journal::List Calendar::journals( JournalSortField sortField,
- SortDirection sortDirection ) const
+Journal::List Calendar::journals(JournalSortField sortField,
+ SortDirection sortDirection) const
{
- Journal::List jl = rawJournals( sortField, sortDirection );
- d->mFilter->apply( &jl );
- return jl;
+ Journal::List jl = rawJournals(sortField, sortDirection);
+ d->mFilter->apply(&jl);
+ return jl;
}
-Journal::List Calendar::journals( const QDate &date ) const
+Journal::List Calendar::journals(const QDate &date) const
{
- Journal::List el = rawJournalsForDate( date );
- d->mFilter->apply( &el );
- return el;
+ Journal::List el = rawJournalsForDate(date);
+ d->mFilter->apply(&el);
+ return el;
}
// When this is called, the to-dos have already been added to the calendar.
// This method is only about linking related to-dos.
-void Calendar::setupRelations( const Incidence::Ptr &forincidence )
-{
- if ( !forincidence ) {
- return;
- }
-
- const QString uid = forincidence->uid();
-
- // First, go over the list of orphans and see if this is their parent
- Incidence::List l = values( d->mOrphans, uid );
- d->mOrphans.remove( uid );
- for ( int i = 0, end = l.count(); i < end; ++i ) {
- d->mIncidenceRelations[uid].append( l[i] );
- d->mOrphanUids.remove( l[i]->uid() );
- }
-
- // Now see about this incidences parent
- if ( forincidence->relatedTo().isEmpty() && !forincidence->relatedTo().isEmpty() ) {
- // Incidence has a uid it is related to but is not registered to it yet.
- // Try to find it
- Incidence::Ptr parent = incidence( forincidence->relatedTo() );
- if ( parent ) {
- // Found it
-
- // look for hierarchy loops
- if ( isAncestorOf( forincidence, parent ) ) {
- forincidence->setRelatedTo( QString() );
- qWarning() << "hierarchy loop beetween " << forincidence->uid() << " and " << parent->uid();
- } else {
- d->mIncidenceRelations[parent->uid()].append( forincidence );
- }
- } else {
- // Not found, put this in the mOrphans list
- // Note that the mOrphans dict might contain multiple entries with the
- // same key! which are multiple children that wait for the parent
- // incidence to be inserted.
- d->mOrphans.insert( forincidence->relatedTo(), forincidence );
- d->mOrphanUids.insert( forincidence->uid(), forincidence );
+void Calendar::setupRelations(const Incidence::Ptr &forincidence)
+{
+ if (!forincidence) {
+ return;
+ }
+
+ const QString uid = forincidence->uid();
+
+ // First, go over the list of orphans and see if this is their parent
+ Incidence::List l = values(d->mOrphans, uid);
+ d->mOrphans.remove(uid);
+ for (int i = 0, end = l.count(); i < end; ++i) {
+ d->mIncidenceRelations[uid].append(l[i]);
+ d->mOrphanUids.remove(l[i]->uid());
+ }
+
+ // Now see about this incidences parent
+ if (forincidence->relatedTo().isEmpty() && !forincidence->relatedTo().isEmpty()) {
+ // Incidence has a uid it is related to but is not registered to it yet.
+ // Try to find it
+ Incidence::Ptr parent = incidence(forincidence->relatedTo());
+ if (parent) {
+ // Found it
+
+ // look for hierarchy loops
+ if (isAncestorOf(forincidence, parent)) {
+ forincidence->setRelatedTo(QString());
+ kWarning() << "hierarchy loop beetween " << forincidence->uid() << " and " << parent->uid();
+ } else {
+ d->mIncidenceRelations[parent->uid()].append(forincidence);
+ }
+ } else {
+ // Not found, put this in the mOrphans list
+ // Note that the mOrphans dict might contain multiple entries with the
+ // same key! which are multiple children that wait for the parent
+ // incidence to be inserted.
+ d->mOrphans.insert(forincidence->relatedTo(), forincidence);
+ d->mOrphanUids.insert(forincidence->uid(), forincidence);
+ }
}
- }
}
// If a to-do with sub-to-dos is deleted, move it's sub-to-dos to the orphan list
-void Calendar::removeRelations( const Incidence::Ptr &incidence )
-{
- if ( !incidence ) {
- qDebug() << "Warning: incidence is 0";
- return;
- }
-
- const QString uid = incidence->uid();
-
- foreach ( Incidence::Ptr i, d->mIncidenceRelations[uid] ) {
- if ( !d->mOrphanUids.contains( i->uid() ) ) {
- d->mOrphans.insert( uid, i );
- d->mOrphanUids.insert( i->uid(), i );
- i->setRelatedTo( uid );
- }
- }
-
- const QString parentUid = incidence->relatedTo();
-
- // If this incidence is related to something else, tell that about it
- if ( !parentUid.isEmpty() ) {
- d->mIncidenceRelations[parentUid].erase(
- std::remove( d->mIncidenceRelations[parentUid].begin(),
- d->mIncidenceRelations[parentUid].end(), incidence ),
- d->mIncidenceRelations[parentUid].end() );
- }
-
- // Remove this one from the orphans list
- if ( d->mOrphanUids.remove( uid ) ) {
- // This incidence is located in the orphans list - it should be removed
- // Since the mOrphans dict might contain the same key (with different
- // child incidence pointers!) multiple times, take care that we remove
- // the correct one. So we need to remove all items with the given
- // parent UID, and readd those that are not for this item. Also, there
- // might be other entries with differnet UID that point to this
- // incidence (this might happen when the relatedTo of the item is
- // changed before its parent is inserted. This might happen with
- // groupware servers....). Remove them, too
- QStringList relatedToUids;
-
- // First, create a list of all keys in the mOrphans list which point
- // to the removed item
- relatedToUids << incidence->relatedTo();
- for ( QMultiHash<QString, Incidence::Ptr>::Iterator it = d->mOrphans.begin();
- it != d->mOrphans.end(); ++it ) {
- if ( it.value()->uid() == uid ) {
- relatedToUids << it.key();
- }
- }
-
- // now go through all uids that have one entry that point to the incidence
- for ( QStringList::const_iterator uidit = relatedToUids.constBegin();
- uidit != relatedToUids.constEnd(); ++uidit ) {
- Incidence::List tempList;
- // Remove all to get access to the remaining entries
- QList<Incidence::Ptr> l = d->mOrphans.values( *uidit );
- d->mOrphans.remove( *uidit );
- foreach ( Incidence::Ptr i, l ) {
- if ( i != incidence ) {
- tempList.append( i );
+void Calendar::removeRelations(const Incidence::Ptr &incidence)
+{
+ if (!incidence) {
+ kDebug() << "Warning: incidence is 0";
+ return;
+ }
+
+ const QString uid = incidence->uid();
+
+ foreach(Incidence::Ptr i, d->mIncidenceRelations[uid]) {
+ if (!d->mOrphanUids.contains(i->uid())) {
+ d->mOrphans.insert(uid, i);
+ d->mOrphanUids.insert(i->uid(), i);
+ i->setRelatedTo(uid);
+ }
+ }
+
+ const QString parentUid = incidence->relatedTo();
+
+ // If this incidence is related to something else, tell that about it
+ if (!parentUid.isEmpty()) {
+ d->mIncidenceRelations[parentUid].erase(
+ std::remove(d->mIncidenceRelations[parentUid].begin(),
+ d->mIncidenceRelations[parentUid].end(), incidence),
+ d->mIncidenceRelations[parentUid].end());
+ }
+
+ // Remove this one from the orphans list
+ if (d->mOrphanUids.remove(uid)) {
+ // This incidence is located in the orphans list - it should be removed
+ // Since the mOrphans dict might contain the same key (with different
+ // child incidence pointers!) multiple times, take care that we remove
+ // the correct one. So we need to remove all items with the given
+ // parent UID, and readd those that are not for this item. Also, there
+ // might be other entries with differnet UID that point to this
+ // incidence (this might happen when the relatedTo of the item is
+ // changed before its parent is inserted. This might happen with
+ // groupware servers....). Remove them, too
+ QStringList relatedToUids;
+
+ // First, create a list of all keys in the mOrphans list which point
+ // to the removed item
+ relatedToUids << incidence->relatedTo();
+ for (QMultiHash<QString, Incidence::Ptr>::Iterator it = d->mOrphans.begin();
+ it != d->mOrphans.end(); ++it) {
+ if (it.value()->uid() == uid) {
+ relatedToUids << it.key();
+ }
+ }
+
+ // now go through all uids that have one entry that point to the incidence
+ for (QStringList::const_iterator uidit = relatedToUids.constBegin();
+ uidit != relatedToUids.constEnd(); ++uidit) {
+ Incidence::List tempList;
+ // Remove all to get access to the remaining entries
+ QList<Incidence::Ptr> l = d->mOrphans.values(*uidit);
+ d->mOrphans.remove(*uidit);
+ foreach(Incidence::Ptr i, l) {
+ if (i != incidence) {
+ tempList.append(i);
+ }
+ }
+ // Readd those that point to a different orphan incidence
+ for (Incidence::List::Iterator incit = tempList.begin();
+ incit != tempList.end(); ++incit) {
+ d->mOrphans.insert(*uidit, *incit);
+ }
}
- }
- // Readd those that point to a different orphan incidence
- for ( Incidence::List::Iterator incit = tempList.begin();
- incit != tempList.end(); ++incit ) {
- d->mOrphans.insert( *uidit, *incit );
- }
- }
- }
-
- // Make sure the deleted incidence doesn't relate to a non-deleted incidence,
- // since that would cause trouble in MemoryCalendar::close(), as the deleted
- // incidences are destroyed after the non-deleted incidences. The destructor
- // of the deleted incidences would then try to access the already destroyed
- // non-deleted incidence, which would segfault.
- //
- // So in short: Make sure dead incidences don't point to alive incidences
- // via the relation.
- //
- // This crash is tested in MemoryCalendarTest::testRelationsCrash().
+ }
+
+ // Make sure the deleted incidence doesn't relate to a non-deleted incidence,
+ // since that would cause trouble in MemoryCalendar::close(), as the deleted
+ // incidences are destroyed after the non-deleted incidences. The destructor
+ // of the deleted incidences would then try to access the already destroyed
+ // non-deleted incidence, which would segfault.
+ //
+ // So in short: Make sure dead incidences don't point to alive incidences
+ // via the relation.
+ //
+ // This crash is tested in MemoryCalendarTest::testRelationsCrash().
// incidence->setRelatedTo( Incidence::Ptr() );
}
-bool Calendar::isAncestorOf( const Incidence::Ptr &ancestor,
- const Incidence::Ptr &incidence ) const
+bool Calendar::isAncestorOf(const Incidence::Ptr &ancestor,
+ const Incidence::Ptr &incidence) const
{
- if ( !incidence || incidence->relatedTo().isEmpty() ) {
- return false;
- } else if ( incidence->relatedTo() == ancestor->uid() ) {
- return true;
- } else {
- return isAncestorOf( ancestor, this->incidence( incidence->relatedTo() ) );
- }
+ if (!incidence || incidence->relatedTo().isEmpty()) {
+ return false;
+ } else if (incidence->relatedTo() == ancestor->uid()) {
+ return true;
+ } else {
+ return isAncestorOf(ancestor, this->incidence(incidence->relatedTo()));
+ }
}
-Incidence::List Calendar::relations( const QString &uid ) const
+Incidence::List Calendar::relations(const QString &uid) const
{
- return d->mIncidenceRelations[uid];
+ return d->mIncidenceRelations[uid];
}
Calendar::CalendarObserver::~CalendarObserver()
{
}
-void Calendar::CalendarObserver::calendarModified( bool modified, Calendar *calendar )
+void Calendar::CalendarObserver::calendarModified(bool modified, Calendar *calendar)
{
- Q_UNUSED( modified );
- Q_UNUSED( calendar );
+ Q_UNUSED(modified);
+ Q_UNUSED(calendar);
}
-void Calendar::CalendarObserver::calendarIncidenceAdded( const Incidence::Ptr &incidence )
+void Calendar::CalendarObserver::calendarIncidenceAdded(const Incidence::Ptr &incidence)
{
- Q_UNUSED( incidence );
+ Q_UNUSED(incidence);
}
-void Calendar::CalendarObserver::calendarIncidenceChanged( const Incidence::Ptr &incidence )
+void Calendar::CalendarObserver::calendarIncidenceChanged(const Incidence::Ptr &incidence)
{
- Q_UNUSED( incidence );
+ Q_UNUSED(incidence);
}
-void Calendar::CalendarObserver::calendarIncidenceDeleted( const Incidence::Ptr &incidence )
+void Calendar::CalendarObserver::calendarIncidenceDeleted(const Incidence::Ptr &incidence)
{
- Q_UNUSED( incidence );
+ Q_UNUSED(incidence);
}
void
-Calendar::CalendarObserver::calendarIncidenceAdditionCanceled( const Incidence::Ptr &incidence )
+Calendar::CalendarObserver::calendarIncidenceAdditionCanceled(const Incidence::Ptr &incidence)
{
- Q_UNUSED( incidence );
+ Q_UNUSED(incidence);
}
-void Calendar::registerObserver( CalendarObserver *observer )
+void Calendar::registerObserver(CalendarObserver *observer)
{
- if ( !observer ) {
- return;
- }
+ if (!observer) {
+ return;
+ }
- if ( !d->mObservers.contains( observer ) ) {
- d->mObservers.append( observer );
- } else {
- d->mNewObserver = true;
- }
+ if (!d->mObservers.contains(observer)) {
+ d->mObservers.append(observer);
+ } else {
+ d->mNewObserver = true;
+ }
}
-void Calendar::unregisterObserver( CalendarObserver *observer )
+void Calendar::unregisterObserver(CalendarObserver *observer)
{
- if ( !observer ) {
- return;
- } else {
- d->mObservers.removeAll( observer );
- }
+ if (!observer) {
+ return;
+ } else {
+ d->mObservers.removeAll(observer);
+ }
}
bool Calendar::isSaving() const
{
- return false;
+ return false;
}
-void Calendar::setModified( bool modified )
+void Calendar::setModified(bool modified)
{
- if ( modified != d->mModified || d->mNewObserver ) {
- d->mNewObserver = false;
- foreach ( CalendarObserver *observer, d->mObservers ) {
- observer->calendarModified( modified, this );
+ if (modified != d->mModified || d->mNewObserver) {
+ d->mNewObserver = false;
+ foreach(CalendarObserver *observer, d->mObservers) {
+ observer->calendarModified(modified, this);
+ }
+ d->mModified = modified;
}
- d->mModified = modified;
- }
}
bool Calendar::isModified() const
{
- return d->mModified;
+ return d->mModified;
}
bool Calendar::save()
{
- return true;
+ return true;
}
bool Calendar::reload()
{
- return true;
+ return true;
}
-void Calendar::incidenceUpdated( const QString &uid, const KDateTime &recurrenceId )
+void Calendar::incidenceUpdated(const QString &uid, const KDateTime &recurrenceId)
{
- Incidence::Ptr inc = incidence( uid, recurrenceId );
+ Incidence::Ptr inc = incidence(uid, recurrenceId);
- if ( !inc ) {
- return;
- }
+ if (!inc) {
+ return;
+ }
- inc->setLastModified( KDateTime::currentUtcDateTime() );
- // we should probably update the revision number here,
- // or internally in the Event itself when certain things change.
- // need to verify with ical documentation.
+ inc->setLastModified(KDateTime::currentUtcDateTime());
+ // we should probably update the revision number here,
+ // or internally in the Event itself when certain things change.
+ // need to verify with ical documentation.
- notifyIncidenceChanged( inc );
+ notifyIncidenceChanged(inc);
- setModified( true );
+ setModified(true);
}
-void Calendar::doSetTimeSpec( const KDateTime::Spec &timeSpec )
+void Calendar::doSetTimeSpec(const KDateTime::Spec &timeSpec)
{
- Q_UNUSED( timeSpec );
+ Q_UNUSED(timeSpec);
}
-void Calendar::notifyIncidenceAdded( const Incidence::Ptr &incidence )
+void Calendar::notifyIncidenceAdded(const Incidence::Ptr &incidence)
{
- if ( !incidence ) {
- return;
- }
+ if (!incidence) {
+ return;
+ }
- if ( !d->mObserversEnabled ) {
- return;
- }
+ if (!d->mObserversEnabled) {
+ return;
+ }
- foreach ( CalendarObserver *observer, d->mObservers ) {
- observer->calendarIncidenceAdded( incidence );
- }
+ foreach(CalendarObserver *observer, d->mObservers) {
+ observer->calendarIncidenceAdded(incidence);
+ }
}
-void Calendar::notifyIncidenceChanged( const Incidence::Ptr &incidence )
+void Calendar::notifyIncidenceChanged(const Incidence::Ptr &incidence)
{
- if ( !incidence ) {
- return;
- }
+ if (!incidence) {
+ return;
+ }
- if ( !d->mObserversEnabled ) {
- return;
- }
+ if (!d->mObserversEnabled) {
+ return;
+ }
- foreach ( CalendarObserver *observer, d->mObservers ) {
- observer->calendarIncidenceChanged( incidence );
- }
+ foreach(CalendarObserver *observer, d->mObservers) {
+ observer->calendarIncidenceChanged(incidence);
+ }
}
-void Calendar::notifyIncidenceDeleted( const Incidence::Ptr &incidence )
+void Calendar::notifyIncidenceDeleted(const Incidence::Ptr &incidence)
{
- if ( !incidence ) {
- return;
- }
+ if (!incidence) {
+ return;
+ }
- if ( !d->mObserversEnabled ) {
- return;
- }
+ if (!d->mObserversEnabled) {
+ return;
+ }
- foreach ( CalendarObserver *observer, d->mObservers ) {
- observer->calendarIncidenceDeleted( incidence );
- }
+ foreach(CalendarObserver *observer, d->mObservers) {
+ observer->calendarIncidenceDeleted(incidence);
+ }
}
-void Calendar::notifyIncidenceAdditionCanceled( const Incidence::Ptr &incidence )
+void Calendar::notifyIncidenceAdditionCanceled(const Incidence::Ptr &incidence)
{
- if ( !incidence ) {
- return;
- }
+ if (!incidence) {
+ return;
+ }
- if ( !d->mObserversEnabled ) {
- return;
- }
+ if (!d->mObserversEnabled) {
+ return;
+ }
- foreach ( CalendarObserver *observer, d->mObservers ) {
- observer->calendarIncidenceAdditionCanceled( incidence );
- }
+ foreach(CalendarObserver *observer, d->mObservers) {
+ observer->calendarIncidenceAdditionCanceled(incidence);
+ }
}
void Calendar::customPropertyUpdated()
{
- setModified( true );
+ setModified(true);
}
-void Calendar::setProductId( const QString &id )
+void Calendar::setProductId(const QString &id)
{
- d->mProductId = id;
+ d->mProductId = id;
}
QString Calendar::productId() const
{
- return d->mProductId;
+ return d->mProductId;
}
/** static */
-Incidence::List Calendar::mergeIncidenceList( const Event::List &events,
- const Todo::List &todos,
- const Journal::List &journals )
+Incidence::List Calendar::mergeIncidenceList(const Event::List &events,
+ const Todo::List &todos,
+ const Journal::List &journals)
{
- Incidence::List incidences;
+ Incidence::List incidences;
- int i, end;
- for ( i = 0, end = events.count(); i < end; ++i ) {
- incidences.append( events[i] );
- }
+ int i, end;
+ for (i = 0, end = events.count(); i < end; ++i) {
+ incidences.append(events[i]);
+ }
- for ( i = 0, end = todos.count(); i < end; ++i ) {
- incidences.append( todos[i] );
- }
+ for (i = 0, end = todos.count(); i < end; ++i) {
+ incidences.append(todos[i]);
+ }
- for ( i = 0, end = journals.count(); i < end; ++i ) {
- incidences.append( journals[i] );
- }
+ for (i = 0, end = journals.count(); i < end; ++i) {
+ incidences.append(journals[i]);
+ }
- return incidences;
+ return incidences;
}
-bool Calendar::beginChange( const Incidence::Ptr &incidence )
+bool Calendar::beginChange(const Incidence::Ptr &incidence)
{
- Q_UNUSED( incidence );
- return true;
+ Q_UNUSED(incidence);
+ return true;
}
-bool Calendar::endChange( const Incidence::Ptr &incidence )
+bool Calendar::endChange(const Incidence::Ptr &incidence)
{
- Q_UNUSED( incidence );
- return true;
+ Q_UNUSED(incidence);
+ return true;
}
-void Calendar::setObserversEnabled( bool enabled )
+void Calendar::setObserversEnabled(bool enabled)
{
- d->mObserversEnabled = enabled;
+ d->mObserversEnabled = enabled;
}
-void Calendar::appendAlarms( Alarm::List &alarms, const Incidence::Ptr &incidence,
- const KDateTime &from, const KDateTime &to ) const
+void Calendar::appendAlarms(Alarm::List &alarms, const Incidence::Ptr &incidence,
+ const KDateTime &from, const KDateTime &to) const
{
- KDateTime preTime = from.addSecs(-1);
+ KDateTime preTime = from.addSecs(-1);
- Alarm::List alarmlist = incidence->alarms();
- for ( int i = 0, iend = alarmlist.count(); i < iend; ++i ) {
- if ( alarmlist[i]->enabled() ) {
- KDateTime dt = alarmlist[i]->nextRepetition( preTime );
- if ( dt.isValid() && dt <= to ) {
- qDebug() << incidence->summary() << "':" << dt.toString();
- alarms.append( alarmlist[i] );
- }
+ Alarm::List alarmlist = incidence->alarms();
+ for (int i = 0, iend = alarmlist.count(); i < iend; ++i) {
+ if (alarmlist[i]->enabled()) {
+ KDateTime dt = alarmlist[i]->nextRepetition(preTime);
+ if (dt.isValid() && dt <= to) {
+ kDebug() << incidence->summary() << "':" << dt.toString();
+ alarms.append(alarmlist[i]);
+ }
+ }
}
- }
}
-void Calendar::appendRecurringAlarms( Alarm::List &alarms,
- const Incidence::Ptr &incidence,
- const KDateTime &from,
- const KDateTime &to ) const
-{
- KDateTime dt;
- bool endOffsetValid = false;
- Duration endOffset( 0 );
- Duration period( from, to );
-
- Alarm::List alarmlist = incidence->alarms();
- for ( int i = 0, iend = alarmlist.count(); i < iend; ++i ) {
- Alarm::Ptr a = alarmlist[i];
- if ( a->enabled() ) {
- if ( a->hasTime() ) {
- // The alarm time is defined as an absolute date/time
- dt = a->nextRepetition( from.addSecs(-1) );
- if ( !dt.isValid() || dt > to ) {
- continue;
- }
- } else {
- // Alarm time is defined by an offset from the event start or end time.
- // Find the offset from the event start time, which is also used as the
- // offset from the recurrence time.
- Duration offset( 0 );
- if ( a->hasStartOffset() ) {
- offset = a->startOffset();
- } else if ( a->hasEndOffset() ) {
- offset = a->endOffset();
- if ( !endOffsetValid ) {
- endOffset = Duration( incidence->dtStart(),
- incidence->dateTime( Incidence::RoleAlarmEndOffset ) );
- endOffsetValid = true;
- }
- }
-
- // Find the incidence's earliest alarm
- KDateTime alarmStart =
- offset.end( a->hasEndOffset() ? incidence->dateTime( Incidence::RoleAlarmEndOffset ) :
- incidence->dtStart() );
+void Calendar::appendRecurringAlarms(Alarm::List &alarms,
+ const Incidence::Ptr &incidence,
+ const KDateTime &from,
+ const KDateTime &to) const
+{
+ KDateTime dt;
+ bool endOffsetValid = false;
+ Duration endOffset(0);
+ Duration period(from, to);
+
+ Alarm::List alarmlist = incidence->alarms();
+ for (int i = 0, iend = alarmlist.count(); i < iend; ++i) {
+ Alarm::Ptr a = alarmlist[i];
+ if (a->enabled()) {
+ if (a->hasTime()) {
+ // The alarm time is defined as an absolute date/time
+ dt = a->nextRepetition(from.addSecs(-1));
+ if (!dt.isValid() || dt > to) {
+ continue;
+ }
+ } else {
+ // Alarm time is defined by an offset from the event start or end time.
+ // Find the offset from the event start time, which is also used as the
+ // offset from the recurrence time.
+ Duration offset(0);
+ if (a->hasStartOffset()) {
+ offset = a->startOffset();
+ } else if (a->hasEndOffset()) {
+ offset = a->endOffset();
+ if (!endOffsetValid) {
+ endOffset = Duration(incidence->dtStart(),
+ incidence->dateTime(Incidence::RoleAlarmEndOffset));
+ endOffsetValid = true;
+ }
+ }
+
+ // Find the incidence's earliest alarm
+ KDateTime alarmStart =
+ offset.end(a->hasEndOffset() ? incidence->dateTime(Incidence::RoleAlarmEndOffset) :
+ incidence->dtStart());
// KDateTime alarmStart = incidence->dtStart().addSecs( offset );
- if ( alarmStart > to ) {
- continue;
- }
- KDateTime baseStart = incidence->dtStart();
- if ( from > alarmStart ) {
- alarmStart = from; // don't look earlier than the earliest alarm
- baseStart = (-offset).end( (-endOffset).end( alarmStart ) );
- }
-
- // Adjust the 'alarmStart' date/time and find the next recurrence at or after it.
- // Treate the two offsets separately in case one is daily and the other not.
- dt = incidence->recurrence()->getNextDateTime( baseStart.addSecs(-1) );
- if ( !dt.isValid() ||
- ( dt = endOffset.end( offset.end( dt ) ) ) > to ) // adjust 'dt' to get the alarm time
- {
- // The next recurrence is too late.
- if ( !a->repeatCount() ) {
- continue;
- }
-
- // The alarm has repetitions, so check whether repetitions of previous
- // recurrences fall within the time period.
- bool found = false;
- Duration alarmDuration = a->duration();
- for ( KDateTime base = baseStart;
- ( dt = incidence->recurrence()->getPreviousDateTime( base ) ).isValid();
- base = dt ) {
- if ( a->duration().end( dt ) < base ) {
- break; // this recurrence's last repetition is too early, so give up
- }
-
- // The last repetition of this recurrence is at or after 'alarmStart' time.
- // Check if a repetition occurs between 'alarmStart' and 'to'.
- int snooze = a->snoozeTime().value(); // in seconds or days
- if ( a->snoozeTime().isDaily() ) {
- Duration toFromDuration( dt, base );
- int toFrom = toFromDuration.asDays();
- if ( a->snoozeTime().end( from ) <= to ||
- ( toFromDuration.isDaily() && toFrom % snooze == 0 ) ||
- ( toFrom / snooze + 1 ) * snooze <= toFrom + period.asDays() ) {
- found = true;
+ if (alarmStart > to) {
+ continue;
+ }
+ KDateTime baseStart = incidence->dtStart();
+ if (from > alarmStart) {
+ alarmStart = from; // don't look earlier than the earliest alarm
+ baseStart = (-offset).end((-endOffset).end(alarmStart));
+ }
+
+ // Adjust the 'alarmStart' date/time and find the next recurrence at or after it.
+ // Treate the two offsets separately in case one is daily and the other not.
+ dt = incidence->recurrence()->getNextDateTime(baseStart.addSecs(-1));
+ if (!dt.isValid() ||
+ (dt = endOffset.end(offset.end(dt))) > to) // adjust 'dt' to get the alarm time
+ {
+ // The next recurrence is too late.
+ if (!a->repeatCount()) {
+ continue;
+ }
+
+ // The alarm has repetitions, so check whether repetitions of previous
+ // recurrences fall within the time period.
+ bool found = false;
+ Duration alarmDuration = a->duration();
+ for (KDateTime base = baseStart;
+ (dt = incidence->recurrence()->getPreviousDateTime(base)).isValid();
+ base = dt) {
+ if (a->duration().end(dt) < base) {
+ break; // this recurrence's last repetition is too early, so give up
+ }
+
+ // The last repetition of this recurrence is at or after 'alarmStart' time.
+ // Check if a repetition occurs between 'alarmStart' and 'to'.
+ int snooze = a->snoozeTime().value(); // in seconds or days
+ if (a->snoozeTime().isDaily()) {
+ Duration toFromDuration(dt, base);
+ int toFrom = toFromDuration.asDays();
+ if (a->snoozeTime().end(from) <= to ||
+ (toFromDuration.isDaily() && toFrom % snooze == 0) ||
+ (toFrom / snooze + 1) * snooze <= toFrom + period.asDays()) {
+ found = true;
#ifndef NDEBUG
- // for debug output
- dt = offset.end( dt ).addDays( ( ( toFrom - 1 ) / snooze + 1 ) * snooze );
+ // for debug output
+ dt = offset.end(dt).addDays(((toFrom - 1) / snooze + 1) * snooze);
#endif
- break;
- }
- } else {
- int toFrom = dt.secsTo( base );
- if ( period.asSeconds() >= snooze ||
- toFrom % snooze == 0 ||
- ( toFrom / snooze + 1 ) * snooze <= toFrom + period.asSeconds() )
- {
- found = true;
+ break;
+ }
+ } else {
+ int toFrom = dt.secsTo(base);
+ if (period.asSeconds() >= snooze ||
+ toFrom % snooze == 0 ||
+ (toFrom / snooze + 1) * snooze <= toFrom + period.asSeconds())
+ {
+ found = true;
#ifndef NDEBUG
- // for debug output
- dt = offset.end( dt ).addSecs( ( ( toFrom - 1 ) / snooze + 1 ) * snooze );
+ // for debug output
+ dt = offset.end(dt).addSecs(((toFrom - 1) / snooze + 1) * snooze);
#endif
- break;
- }
+ break;
+ }
+ }
+ }
+ if (!found) {
+ continue;
+ }
+ }
}
- }
- if ( !found ) {
- continue;
- }
+ kDebug() << incidence->summary() << "':" << dt.toString();
+ alarms.append(a);
}
- }
- qDebug() << incidence->summary() << "':" << dt.toString();
- alarms.append( a );
}
- }
}
void Calendar::startBatchAdding()
{
- d->batchAddingInProgress = true;
+ d->batchAddingInProgress = true;
}
void Calendar::endBatchAdding()
{
- d->batchAddingInProgress = false;
+ d->batchAddingInProgress = false;
}
bool Calendar::batchAdding() const
{
- return d->batchAddingInProgress;
+ return d->batchAddingInProgress;
+}
+
+void Calendar::setDeletionTracking(bool enable)
+{
+ d->mDeletionTracking = enable;
+}
+
+bool Calendar::deletionTracking() const
+{
+ return d->mDeletionTracking;
}
-void Calendar::virtual_hook( int id, void *data )
+void Calendar::virtual_hook(int id, void *data)
{
- Q_UNUSED( id );
- Q_UNUSED( data );
- Q_ASSERT( false );
+ Q_UNUSED(id);
+ Q_UNUSED(data);
+ Q_ASSERT(false);
}
-#include "calendar.moc" \ No newline at end of file
diff --git a/kcalcore/calendar.h b/kcalcore/calendar.h
index d1dcc39..25415d3 100644
--- a/kcalcore/calendar.h
+++ b/kcalcore/calendar.h
@@ -67,40 +67,40 @@ class ICalTimeZones;
Calendar Incidence sort directions.
*/
enum SortDirection {
- SortDirectionAscending, /**< Sort in ascending order (first to last) */
- SortDirectionDescending /**< Sort in descending order (last to first) */
+ SortDirectionAscending, /**< Sort in ascending order (first to last) */
+ SortDirectionDescending /**< Sort in descending order (last to first) */
};
/**
Calendar Event sort keys.
*/
enum EventSortField {
- EventSortUnsorted, /**< Do not sort Events */
- EventSortStartDate, /**< Sort Events chronologically, by start date */
- EventSortEndDate, /**< Sort Events chronologically, by end date */
- EventSortSummary /**< Sort Events alphabetically, by summary */
+ EventSortUnsorted, /**< Do not sort Events */
+ EventSortStartDate, /**< Sort Events chronologically, by start date */
+ EventSortEndDate, /**< Sort Events chronologically, by end date */
+ EventSortSummary /**< Sort Events alphabetically, by summary */
};
/**
Calendar Todo sort keys.
*/
enum TodoSortField {
- TodoSortUnsorted, /**< Do not sort Todos */
- TodoSortStartDate, /**< Sort Todos chronologically, by start date */
- TodoSortDueDate, /**< Sort Todos chronologically, by due date */
- TodoSortPriority, /**< Sort Todos by priority */
- TodoSortPercentComplete, /**< Sort Todos by percentage completed */
- TodoSortSummary, /**< Sort Todos alphabetically, by summary */
- TodoSortCreated /**< Sort Todos chronologically, by creation date */
+ TodoSortUnsorted, /**< Do not sort Todos */
+ TodoSortStartDate, /**< Sort Todos chronologically, by start date */
+ TodoSortDueDate, /**< Sort Todos chronologically, by due date */
+ TodoSortPriority, /**< Sort Todos by priority */
+ TodoSortPercentComplete, /**< Sort Todos by percentage completed */
+ TodoSortSummary, /**< Sort Todos alphabetically, by summary */
+ TodoSortCreated /**< Sort Todos chronologically, by creation date */
};
/**
Calendar Journal sort keys.
*/
enum JournalSortField {
- JournalSortUnsorted, /**< Do not sort Journals */
- JournalSortDate, /**< Sort Journals chronologically by date */
- JournalSortSummary /**< Sort Journals alphabetically, by summary */
+ JournalSortUnsorted, /**< Do not sort Journals */
+ JournalSortDate, /**< Sort Journals chronologically by date */
+ JournalSortSummary /**< Sort Journals alphabetically, by summary */
};
/**
@@ -126,11 +126,11 @@ enum JournalSortField {
object you get from Calendar -- use the delete...() methods.
*/
class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
- public IncidenceBase::IncidenceObserver
+ public IncidenceBase::IncidenceObserver
{
- Q_OBJECT
+ Q_OBJECT
- public:
+public:
/**
A shared pointer to a Calendar
@@ -147,7 +147,7 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@param timeSpec time specification
*/
- explicit Calendar( const KDateTime::Spec &timeSpec );
+ explicit Calendar(const KDateTime::Spec &timeSpec);
/**
Construct Calendar object using a time zone ID.
@@ -162,7 +162,7 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
specification is set to local clock time.
@e Example: "Europe/Berlin"
*/
- explicit Calendar( const QString &timeZoneId );
+ explicit Calendar(const QString &timeZoneId);
/**
Destroys the calendar.
@@ -176,7 +176,7 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@see productId() const
*/
- void setProductId( const QString &id );
+ void setProductId(const QString &id);
/**
Returns the calendar's Product ID.
@@ -192,7 +192,7 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@see owner()
*/
- void setOwner( const Person::Ptr &owner );
+ void setOwner(const Person::Ptr &owner);
/**
Returns the owner of the calendar.
@@ -211,7 +211,7 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@param timeSpec time specification
*/
- void setTimeSpec( const KDateTime::Spec &timeSpec );
+ void setTimeSpec(const KDateTime::Spec &timeSpec);
/**
Get the time specification (time zone etc.) used for creating or
@@ -234,7 +234,7 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@e Example: "Europe/Berlin"
@see setTimeSpec()
*/
- void setTimeZoneId( const QString &timeZoneId );
+ void setTimeZoneId(const QString &timeZoneId);
/**
Returns the time zone ID used for creating or modifying incidences in
@@ -259,7 +259,7 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@see viewTimeSpec()
*/
- void setViewTimeSpec( const KDateTime::Spec &timeSpec ) const;
+ void setViewTimeSpec(const KDateTime::Spec &timeSpec) const;
/**
Notes the time zone Id which the client application intends to use for
@@ -279,7 +279,7 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@see viewTimeZoneId()
*/
- void setViewTimeZoneId( const QString &timeZoneId ) const;
+ void setViewTimeZoneId(const QString &timeZoneId) const;
/**
Returns the time specification used for viewing the incidences in
@@ -313,7 +313,7 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@see isLocalTime()
*/
- void shiftTimes( const KDateTime::Spec &oldSpec, const KDateTime::Spec &newSpec );
+ void shiftTimes(const KDateTime::Spec &oldSpec, const KDateTime::Spec &newSpec);
/**
Returns the time zone collection used by the calendar.
@@ -330,7 +330,7 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@param zones time zones collection. Important: all time zones references
in the calendar must be included in the collection.
*/
- void setTimeZones( ICalTimeZones *zones );
+ void setTimeZones(ICalTimeZones *zones);
/**
Sets if the calendar has been modified.
@@ -340,7 +340,7 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@see isModified()
*/
- void setModified( bool modified );
+ void setModified(bool modified);
/**
Determine the calendar's modification status.
@@ -387,7 +387,7 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
*/
QStringList categories() const;
- // Incidence Specific Methods //
+ // Incidence Specific Methods //
/**
Call this to tell the calendar that you're adding a batch of incidences.
@@ -418,7 +418,7 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@see deleteIncidence()
*/
- virtual bool addIncidence( const Incidence::Ptr &incidence );
+ virtual bool addIncidence(const Incidence::Ptr &incidence);
/**
Removes an Incidence from the calendar.
@@ -429,7 +429,7 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@see addIncidence()
*/
- virtual bool deleteIncidence( const Incidence::Ptr &incidence );
+ virtual bool deleteIncidence(const Incidence::Ptr &incidence);
/**
Returns a filtered list of all Incidences for this Calendar.
@@ -445,7 +445,7 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@return the list of filtered Incidences occurring on the specified date.
*/
- virtual Incidence::List incidences( const QDate &date ) const;
+ virtual Incidence::List incidences(const QDate &date) const;
/**
Returns an unfiltered list of all Incidences for this Calendar.
@@ -455,13 +455,13 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
virtual Incidence::List rawIncidences() const;
/**
- Returns an unfiltered list of all possible instances for this recurring Incidence.
+ Returns an unfiltered list of all exceptions of this recurring incidence.
@param incidence incidence to check
- @return the list of all unfiltered Incidences.
+ @return the list of all unfiltered exceptions.
*/
- virtual Incidence::List instances( const Incidence::Ptr &incidence ) const;
+ virtual Incidence::List instances(const Incidence::Ptr &incidence) const;
// Notebook Specific Methods //
@@ -479,7 +479,7 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@return true if the operation was successful; false otherwise.
*/
- virtual bool setNotebook( const Incidence::Ptr &incidence, const QString &notebook );
+ virtual bool setNotebook(const Incidence::Ptr &incidence, const QString &notebook);
/**
Get incidence's notebook.
@@ -488,7 +488,7 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@return notebook uid
*/
- virtual QString notebook( const Incidence::Ptr &incidence ) const;
+ virtual QString notebook(const Incidence::Ptr &incidence) const;
/**
Get incidence's notebook.
@@ -497,7 +497,7 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@return notebook uid
*/
- virtual QString notebook( const QString &uid ) const;
+ virtual QString notebook(const QString &uid) const;
/**
List all uids of notebooks currently in the memory.
@@ -513,7 +513,7 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@param notebook notebook uid
@return true if calendar has valid notebook
*/
- bool hasValidNotebook( const QString &notebook ) const;
+ bool hasValidNotebook(const QString &notebook) const;
/**
Add notebook information into calendar.
@@ -524,7 +524,7 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@return true if operation succeeded
@see isVisible()
*/
- bool addNotebook( const QString &notebook, bool isVisible );
+ bool addNotebook(const QString &notebook, bool isVisible);
/**
Update notebook information in calendar.
@@ -535,7 +535,7 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@return true if operation succeeded
@see isVisible()
*/
- bool updateNotebook( const QString &notebook, bool isVisible );
+ bool updateNotebook(const QString &notebook, bool isVisible);
/**
Delete notebook information from calendar.
@@ -545,7 +545,7 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@return true if operation succeeded
@see isVisible()
*/
- bool deleteNotebook( const QString &notebook );
+ bool deleteNotebook(const QString &notebook);
/**
set DefaultNotebook information to calendar.
@@ -553,7 +553,7 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@param notebook notebook uid
@return true if operation was successful; false otherwise.
*/
- bool setDefaultNotebook( const QString &notebook );
+ bool setDefaultNotebook(const QString &notebook);
/**
Get uid of default notebook.
@@ -567,7 +567,7 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@param incidence is a pointer to the Incidence to check for visibility.
@return true if incidence is visible, false otherwise
*/
- bool isVisible( const Incidence::Ptr &incidence ) const;
+ bool isVisible(const Incidence::Ptr &incidence) const;
/**
List all notebook incidences in the memory.
@@ -575,7 +575,7 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@param notebook is the notebook uid.
@return a list of incidences for the notebook.
*/
- virtual Incidence::List incidences( const QString &notebook ) const;
+ virtual Incidence::List incidences(const QString &notebook) const;
/**
List all possible duplicate incidences.
@@ -583,7 +583,7 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@param incidence is the incidence to check.
@return a list of duplicate incidences.
*/
- virtual Incidence::List duplicates( const Incidence::Ptr &incidence );
+ virtual Incidence::List duplicates(const Incidence::Ptr &incidence);
/**
Returns the Incidence associated with the given unique identifier.
@@ -594,8 +594,8 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@return a pointer to the Incidence.
A null pointer is returned if no such Incidence exists.
*/
- Incidence::Ptr incidence( const QString &uid,
- const KDateTime &recurrenceId = KDateTime() ) const;
+ Incidence::Ptr incidence(const QString &uid,
+ const KDateTime &recurrenceId = KDateTime()) const;
/**
Returns the deleted Incidence associated with the given unique identifier.
@@ -606,7 +606,7 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@return a pointer to the Incidence.
A null pointer is returned if no such Incidence exists.
*/
- Incidence::Ptr deleted( const QString &uid, const KDateTime &recurrenceId = KDateTime() ) const;
+ Incidence::Ptr deleted(const QString &uid, const KDateTime &recurrenceId = KDateTime()) const;
/**
Delete all incidences that are instances of recurring incidence @p incidence.
@@ -614,7 +614,7 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@param incidence is a pointer to a deleted Incidence
@return true if delete was successful; false otherwise
*/
- virtual bool deleteIncidenceInstances( const Incidence::Ptr &incidence ) = 0;
+ virtual bool deleteIncidenceInstances(const Incidence::Ptr &incidence) = 0;
/**
Returns the Incidence associated with the given scheduling identifier.
@@ -624,7 +624,7 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@return a pointer to the Incidence.
A null pointer is returned if no such Incidence exists.
*/
- virtual Incidence::Ptr incidenceFromSchedulingID( const QString &sid ) const;
+ virtual Incidence::Ptr incidenceFromSchedulingID(const QString &sid) const;
/**
Searches all events and todos for an incidence with this
@@ -632,7 +632,7 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@param sid is a unique scheduling identifier string.
*/
- virtual Incidence::List incidencesFromSchedulingID( const QString &sid ) const;
+ virtual Incidence::List incidencesFromSchedulingID(const QString &sid) const;
/**
Create a merged list of Events, Todos, and Journals.
@@ -643,21 +643,21 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@return a list of merged Incidences.
*/
- static Incidence::List mergeIncidenceList( const Event::List &events,
- const Todo::List &todos,
- const Journal::List &journals );
+ static Incidence::List mergeIncidenceList(const Event::List &events,
+ const Todo::List &todos,
+ const Journal::List &journals);
/**
Flag that a change to a Calendar Incidence is starting.
@param incidence is a pointer to the Incidence that will be changing.
*/
- virtual bool beginChange( const Incidence::Ptr &incidence );
+ virtual bool beginChange(const Incidence::Ptr &incidence);
/**
Flag that a change to a Calendar Incidence has completed.
@param incidence is a pointer to the Incidence that was changed.
*/
- virtual bool endChange( const Incidence::Ptr &incidence );
+ virtual bool endChange(const Incidence::Ptr &incidence);
/**
Dissociate an Incidence from a recurring Incidence.
@@ -675,12 +675,30 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
from the recurring Incidences after @a date.
@return a pointer to a new recurring Incidence if @a single is false.
+ @deprecated Use createException()
*/
- Incidence::Ptr dissociateOccurrence( const Incidence::Ptr &incidence, const QDate &date,
- const KDateTime::Spec &spec,
- bool single = true );
+ KCALCORE_DEPRECATED Incidence::Ptr dissociateOccurrence(
+ const Incidence::Ptr &incidence, const QDate &date,
+ const KDateTime::Spec &spec, bool single = true);
+ /**
+ Creates an exception for an occurrence from a recurring Incidence.
+
+ The returned exception is not automatically inserted into the calendar.
- // Event Specific Methods //
+ @param incidence is a pointer to a recurring Incidence.
+ @param recurrenceId specifies the specific occurrence for which the
+ exception applies.
+ @param thisAndFuture specifies if the exception applies only this specific
+ occcurrence or also to all future occurrences.
+
+ @return a pointer to a new exception incidence with @param recurrenceId set.
+ @since 4.11
+ */
+ static Incidence::Ptr createException(const Incidence::Ptr &incidence,
+ const KDateTime &recurrenceId,
+ bool thisAndFuture = false);
+
+ // Event Specific Methods //
/**
Inserts an Event into the calendar.
@@ -691,7 +709,7 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@see deleteEvent()
*/
- virtual bool addEvent( const Event::Ptr &event ) = 0;
+ virtual bool addEvent(const Event::Ptr &event) = 0;
/**
Removes an Event from the calendar.
@@ -702,7 +720,7 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@see addEvent(), deleteAllEvents()
*/
- virtual bool deleteEvent( const Event::Ptr &event ) = 0;
+ virtual bool deleteEvent(const Event::Ptr &event) = 0;
/**
Delete all events that are instances of recurring event @p event.
@@ -710,11 +728,12 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@param event is a pointer to a deleted Event
@return true if delete was successful; false otherwise
*/
- virtual bool deleteEventInstances( const Event::Ptr &event ) = 0;
+ virtual bool deleteEventInstances(const Event::Ptr &event) = 0;
/**
Removes all Events from the calendar.
@see deleteEvent()
+ TODO_KDE5: Remove these methods. They are dangerous and don't add value.
*/
virtual void deleteAllEvents() = 0;
@@ -727,9 +746,9 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@return a list of Events sorted as specified.
*/
- static Event::List sortEvents( const Event::List &eventList,
- EventSortField sortField,
- SortDirection sortDirection );
+ static Event::List sortEvents(const Event::List &eventList,
+ EventSortField sortField,
+ SortDirection sortDirection);
/**
Returns a sorted, filtered list of all Events for this Calendar.
@@ -738,8 +757,8 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@return the list of all filtered Events sorted as specified.
*/
- virtual Event::List events( EventSortField sortField = EventSortUnsorted,
- SortDirection sortDirection = SortDirectionAscending ) const;
+ virtual Event::List events(EventSortField sortField = EventSortUnsorted,
+ SortDirection sortDirection = SortDirectionAscending) const;
/**
Returns a filtered list of all Events which occur on the given timestamp.
@@ -748,7 +767,7 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@return the list of filtered Events occurring on the specified timestamp.
*/
- Event::List events( const KDateTime &dt ) const;
+ Event::List events(const KDateTime &dt) const;
/**
Returns a filtered list of all Events occurring within a date range.
@@ -763,9 +782,9 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@return the list of filtered Events occurring within the specified
date range.
*/
- Event::List events( const QDate &start, const QDate &end,
- const KDateTime::Spec &timeSpec = KDateTime::Spec(),
- bool inclusive = false ) const;
+ Event::List events(const QDate &start, const QDate &end,
+ const KDateTime::Spec &timeSpec = KDateTime::Spec(),
+ bool inclusive = false) const;
/**
Returns a sorted, filtered list of all Events which occur on the given
@@ -780,10 +799,10 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@return the list of sorted, filtered Events occurring on @a date.
*/
- Event::List events( const QDate &date,
- const KDateTime::Spec &timeSpec = KDateTime::Spec(),
- EventSortField sortField = EventSortUnsorted,
- SortDirection sortDirection = SortDirectionAscending ) const;
+ Event::List events(const QDate &date,
+ const KDateTime::Spec &timeSpec = KDateTime::Spec(),
+ EventSortField sortField = EventSortUnsorted,
+ SortDirection sortDirection = SortDirectionAscending) const;
/**
Returns a sorted, unfiltered list of all Events for this Calendar.
@@ -794,8 +813,8 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@return the list of all unfiltered Events sorted as specified.
*/
virtual Event::List rawEvents(
- EventSortField sortField = EventSortUnsorted,
- SortDirection sortDirection = SortDirectionAscending ) const = 0;
+ EventSortField sortField = EventSortUnsorted,
+ SortDirection sortDirection = SortDirectionAscending) const = 0;
/**
Returns an unfiltered list of all Events which occur on the given
@@ -806,7 +825,7 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@return the list of unfiltered Events occurring on the specified
timestamp.
*/
- virtual Event::List rawEventsForDate( const KDateTime &dt ) const = 0;
+ virtual Event::List rawEventsForDate(const KDateTime &dt) const = 0;
/**
Returns an unfiltered list of all Events occurring within a date range.
@@ -821,9 +840,9 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@return the list of unfiltered Events occurring within the specified
date range.
*/
- virtual Event::List rawEvents( const QDate &start, const QDate &end,
- const KDateTime::Spec &timeSpec = KDateTime::Spec(),
- bool inclusive = false ) const = 0;
+ virtual Event::List rawEvents(const QDate &start, const QDate &end,
+ const KDateTime::Spec &timeSpec = KDateTime::Spec(),
+ bool inclusive = false) const = 0;
/**
Returns a sorted, unfiltered list of all Events which occur on the given
@@ -839,10 +858,10 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@return the list of sorted, unfiltered Events occurring on @p date
*/
virtual Event::List rawEventsForDate(
- const QDate &date,
- const KDateTime::Spec &timeSpec = KDateTime::Spec(),
- EventSortField sortField = EventSortUnsorted,
- SortDirection sortDirection = SortDirectionAscending ) const = 0;
+ const QDate &date,
+ const KDateTime::Spec &timeSpec = KDateTime::Spec(),
+ EventSortField sortField = EventSortUnsorted,
+ SortDirection sortDirection = SortDirectionAscending) const = 0;
/**
Returns the Event associated with the given unique identifier.
@@ -853,8 +872,8 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@return a pointer to the Event.
A null pointer is returned if no such Event exists.
*/
- virtual Event::Ptr event( const QString &uid,
- const KDateTime &recurrenceId = KDateTime() ) const = 0;
+ virtual Event::Ptr event(const QString &uid,
+ const KDateTime &recurrenceId = KDateTime()) const = 0;
/**
Returns the deleted Event associated with the given unique identifier.
@@ -863,10 +882,13 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@param recurrenceId is possible recurrenceId of event, default is null
@return a pointer to the deleted Event.
- A null pointer is returned if no such deleted Event exists.
+ A null pointer is returned if no such deleted Event exists, or if deletion tracking
+ is disabled.
+
+ @see deletionTracking()
*/
- virtual Event::Ptr deletedEvent( const QString &uid,
- const KDateTime &recurrenceId = KDateTime() ) const = 0;
+ virtual Event::Ptr deletedEvent(const QString &uid,
+ const KDateTime &recurrenceId = KDateTime()) const = 0;
/**
Returns a sorted, unfiltered list of all deleted Events for this Calendar.
@@ -874,11 +896,14 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@param sortField specifies the EventSortField.
@param sortDirection specifies the SortDirection.
- @return the list of all unfiltered deleted Events sorted as specified.
+ @return the list of all unfiltered deleted Events sorted as specified. An empty list
+ is returned if deletion tracking is disabled.
+
+ @see deletionTracking()
*/
virtual Event::List deletedEvents(
- EventSortField sortField = EventSortUnsorted,
- SortDirection sortDirection = SortDirectionAscending ) const = 0;
+ EventSortField sortField = EventSortUnsorted,
+ SortDirection sortDirection = SortDirectionAscending) const = 0;
/**
Returns a sorted, unfiltered list of all possible instances for this recurring Event.
@@ -890,11 +915,11 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@return the list of all unfiltered event instances sorted as specified.
*/
virtual Event::List eventInstances(
- const Incidence::Ptr &event,
- EventSortField sortField = EventSortUnsorted,
- SortDirection sortDirection = SortDirectionAscending ) const = 0;
+ const Incidence::Ptr &event,
+ EventSortField sortField = EventSortUnsorted,
+ SortDirection sortDirection = SortDirectionAscending) const = 0;
- // Todo Specific Methods //
+ // Todo Specific Methods //
/**
Inserts a Todo into the calendar.
@@ -905,7 +930,7 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@see deleteTodo()
*/
- virtual bool addTodo( const Todo::Ptr &todo ) = 0;
+ virtual bool addTodo(const Todo::Ptr &todo) = 0;
/**
Removes a Todo from the calendar.
@@ -916,14 +941,14 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@see addTodo(), deleteAllTodos()
*/
- virtual bool deleteTodo( const Todo::Ptr &todo ) = 0;
+ virtual bool deleteTodo(const Todo::Ptr &todo) = 0;
/**
Delete all to-dos that are instances of recurring to-do @p todo.
@param todo is a pointer to a deleted Todo
@return true if delete was successful; false otherwise
*/
- virtual bool deleteTodoInstances( const Todo::Ptr &todo ) = 0;
+ virtual bool deleteTodoInstances(const Todo::Ptr &todo) = 0;
/**
Removes all To-dos from the calendar.
@@ -940,9 +965,9 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@return a list of Todos sorted as specified.
*/
- static Todo::List sortTodos( const Todo::List &todoList,
- TodoSortField sortField,
- SortDirection sortDirection );
+ static Todo::List sortTodos(const Todo::List &todoList,
+ TodoSortField sortField,
+ SortDirection sortDirection);
/**
Returns a sorted, filtered list of all Todos for this Calendar.
@@ -952,8 +977,8 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@return the list of all filtered Todos sorted as specified.
*/
- virtual Todo::List todos( TodoSortField sortField = TodoSortUnsorted,
- SortDirection sortDirection = SortDirectionAscending ) const;
+ virtual Todo::List todos(TodoSortField sortField = TodoSortUnsorted,
+ SortDirection sortDirection = SortDirectionAscending) const;
/**
Returns a filtered list of all Todos which are due on the specified date.
@@ -962,7 +987,7 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@return the list of filtered Todos due on the specified date.
*/
- virtual Todo::List todos( const QDate &date ) const;
+ virtual Todo::List todos(const QDate &date) const;
/**
Returns a filtered list of all Todos occurring within a date range.
@@ -977,9 +1002,9 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@return the list of filtered Todos occurring within the specified
date range.
*/
- virtual Todo::List todos( const QDate &start, const QDate &end,
- const KDateTime::Spec &timespec = KDateTime::Spec(),
- bool inclusive = false ) const;
+ virtual Todo::List todos(const QDate &start, const QDate &end,
+ const KDateTime::Spec &timespec = KDateTime::Spec(),
+ bool inclusive = false) const;
/**
Returns a sorted, unfiltered list of all Todos for this Calendar.
@@ -990,8 +1015,8 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@return the list of all unfiltered Todos sorted as specified.
*/
virtual Todo::List rawTodos(
- TodoSortField sortField = TodoSortUnsorted,
- SortDirection sortDirection = SortDirectionAscending ) const = 0;
+ TodoSortField sortField = TodoSortUnsorted,
+ SortDirection sortDirection = SortDirectionAscending) const = 0;
/**
Returns an unfiltered list of all Todos which due on the specified date.
@@ -1000,7 +1025,7 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@return the list of unfiltered Todos due on the specified date.
*/
- virtual Todo::List rawTodosForDate( const QDate &date ) const = 0;
+ virtual Todo::List rawTodosForDate(const QDate &date) const = 0;
/**
Returns an unfiltered list of all Todos occurring within a date range.
@@ -1015,9 +1040,9 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@return the list of unfiltered Todos occurring within the specified
date range.
*/
- virtual Todo::List rawTodos( const QDate &start, const QDate &end,
- const KDateTime::Spec &timespec = KDateTime::Spec(),
- bool inclusive = false ) const = 0;
+ virtual Todo::List rawTodos(const QDate &start, const QDate &end,
+ const KDateTime::Spec &timespec = KDateTime::Spec(),
+ bool inclusive = false) const = 0;
/**
Returns the Todo associated with the given unique identifier.
@@ -1028,8 +1053,8 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@return a pointer to the Todo.
A null pointer is returned if no such Todo exists.
*/
- virtual Todo::Ptr todo( const QString &uid,
- const KDateTime &recurrenceId = KDateTime() ) const = 0;
+ virtual Todo::Ptr todo(const QString &uid,
+ const KDateTime &recurrenceId = KDateTime()) const = 0;
/**
Returns the deleted Todo associated with the given unique identifier.
@@ -1038,10 +1063,13 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@param recurrenceId is possible recurrenceId of todo, default is null
@return a pointer to the deleted Todo.
- A null pointer is returned if no such deletef Todo exists.
+ A null pointer is returned if no such deleted Todo exists or if deletion tracking
+ is disabled.
+
+ @see deletionTracking()
*/
- virtual Todo::Ptr deletedTodo( const QString &uid,
- const KDateTime &recurrenceId = KDateTime() ) const = 0;
+ virtual Todo::Ptr deletedTodo(const QString &uid,
+ const KDateTime &recurrenceId = KDateTime()) const = 0;
/**
Returns a sorted, unfiltered list of all deleted Todos for this Calendar.
@@ -1049,11 +1077,14 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@param sortField specifies the TodoSortField.
@param sortDirection specifies the SortDirection.
- @return the list of all unfiltered deleted Todos sorted as specified.
+ @return the list of all unfiltered deleted Todos sorted as specified. An empty list
+ is returned if deletion tracking is disabled.
+
+ @see deletionTracking()
*/
virtual Todo::List deletedTodos(
- TodoSortField sortField = TodoSortUnsorted,
- SortDirection sortDirection = SortDirectionAscending ) const = 0;
+ TodoSortField sortField = TodoSortUnsorted,
+ SortDirection sortDirection = SortDirectionAscending) const = 0;
/**
Returns a sorted, unfiltered list of all possible instances for this recurring Todo.
@@ -1065,11 +1096,11 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@return the list of all unfiltered todo instances sorted as specified.
*/
virtual Todo::List todoInstances(
- const Incidence::Ptr &todo,
- TodoSortField sortField = TodoSortUnsorted,
- SortDirection sortDirection = SortDirectionAscending ) const = 0;
+ const Incidence::Ptr &todo,
+ TodoSortField sortField = TodoSortUnsorted,
+ SortDirection sortDirection = SortDirectionAscending) const = 0;
- // Journal Specific Methods //
+ // Journal Specific Methods //
/**
Inserts a Journal into the calendar.
@@ -1080,7 +1111,7 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@see deleteJournal()
*/
- virtual bool addJournal( const Journal::Ptr &journal ) = 0;
+ virtual bool addJournal(const Journal::Ptr &journal) = 0;
/**
Removes a Journal from the calendar.
@@ -1091,7 +1122,7 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@see addJournal(), deleteAllJournals()
*/
- virtual bool deleteJournal( const Journal::Ptr &journal ) = 0;
+ virtual bool deleteJournal(const Journal::Ptr &journal) = 0;
/**
Delete all journals that are instances of recurring journal @p journal.
@@ -1099,7 +1130,7 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@param journal is a pointer to a deleted Journal
@return true if delete was successful; false otherwise
*/
- virtual bool deleteJournalInstances( const Journal::Ptr &journal ) = 0;
+ virtual bool deleteJournalInstances(const Journal::Ptr &journal) = 0;
/**
Removes all Journals from the calendar.
@@ -1116,9 +1147,9 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@return a list of Journals sorted as specified.
*/
- static Journal::List sortJournals( const Journal::List &journalList,
- JournalSortField sortField,
- SortDirection sortDirection );
+ static Journal::List sortJournals(const Journal::List &journalList,
+ JournalSortField sortField,
+ SortDirection sortDirection);
/**
Returns a sorted, filtered list of all Journals for this Calendar.
@@ -1128,8 +1159,8 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@return the list of all filtered Journals sorted as specified.
*/
virtual Journal::List journals(
- JournalSortField sortField = JournalSortUnsorted,
- SortDirection sortDirection = SortDirectionAscending ) const;
+ JournalSortField sortField = JournalSortUnsorted,
+ SortDirection sortDirection = SortDirectionAscending) const;
/**
Returns a filtered list of all Journals for on the specified date.
@@ -1138,7 +1169,7 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@return the list of filtered Journals for the specified date.
*/
- virtual Journal::List journals( const QDate &date ) const;
+ virtual Journal::List journals(const QDate &date) const;
/**
Returns a sorted, unfiltered list of all Journals for this Calendar.
@@ -1149,8 +1180,8 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@return the list of all unfiltered Journals sorted as specified.
*/
virtual Journal::List rawJournals(
- JournalSortField sortField = JournalSortUnsorted,
- SortDirection sortDirection = SortDirectionAscending ) const = 0;
+ JournalSortField sortField = JournalSortUnsorted,
+ SortDirection sortDirection = SortDirectionAscending) const = 0;
/**
Returns an unfiltered list of all Journals for on the specified date.
@@ -1159,7 +1190,7 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@return the list of unfiltered Journals for the specified date.
*/
- virtual Journal::List rawJournalsForDate( const QDate &date ) const = 0;
+ virtual Journal::List rawJournalsForDate(const QDate &date) const = 0;
/**
Returns the Journal associated with the given unique identifier.
@@ -1170,8 +1201,8 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@return a pointer to the Journal.
A null pointer is returned if no such Journal exists.
*/
- virtual Journal::Ptr journal( const QString &uid,
- const KDateTime &recurrenceId = KDateTime() ) const = 0;
+ virtual Journal::Ptr journal(const QString &uid,
+ const KDateTime &recurrenceId = KDateTime()) const = 0;
/**
Returns the deleted Journal associated with the given unique identifier.
@@ -1180,10 +1211,13 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@param recurrenceId is possible recurrenceId of journal, default is null
@return a pointer to the deleted Journal.
- A null pointer is returned if no such deleted Journal exists.
+ A null pointer is returned if no such deleted Journal exists or if deletion tracking
+ is disabled.
+
+ @see deletionTracking()
*/
- virtual Journal::Ptr deletedJournal( const QString &uid,
- const KDateTime &recurrenceId = KDateTime() ) const = 0;
+ virtual Journal::Ptr deletedJournal(const QString &uid,
+ const KDateTime &recurrenceId = KDateTime()) const = 0;
/**
Returns a sorted, unfiltered list of all deleted Journals for this Calendar.
@@ -1191,11 +1225,14 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@param sortField specifies the JournalSortField.
@param sortDirection specifies the SortDirection.
- @return the list of all unfiltered deleted Journals sorted as specified.
+ @return the list of all unfiltered deleted Journals sorted as specified. An empty list
+ is returned if deletion tracking is disabled.
+
+ @see deletionTracking()
*/
virtual Journal::List deletedJournals(
- JournalSortField sortField = JournalSortUnsorted,
- SortDirection sortDirection = SortDirectionAscending ) const = 0;
+ JournalSortField sortField = JournalSortUnsorted,
+ SortDirection sortDirection = SortDirectionAscending) const = 0;
/**
Returns a sorted, unfiltered list of all instances for this recurring Journal.
@@ -1207,24 +1244,24 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@return the list of all unfiltered journal instances sorted as specified.
*/
virtual Journal::List journalInstances(
- const Incidence::Ptr &journal,
- JournalSortField sortField = JournalSortUnsorted,
- SortDirection sortDirection = SortDirectionAscending ) const = 0;
+ const Incidence::Ptr &journal,
+ JournalSortField sortField = JournalSortUnsorted,
+ SortDirection sortDirection = SortDirectionAscending) const = 0;
- // Relations Specific Methods //
+ // Relations Specific Methods //
/**
Setup Relations for an Incidence.
@param incidence is a pointer to the Incidence to have a Relation setup.
*/
- virtual void setupRelations( const Incidence::Ptr &incidence );
+ virtual void setupRelations(const Incidence::Ptr &incidence);
/**
Removes all Relations from an Incidence.
@param incidence is a pointer to the Incidence to have a Relation removed.
*/
- virtual void removeRelations( const Incidence::Ptr &incidence );
+ virtual void removeRelations(const Incidence::Ptr &incidence);
/**
Checks if @p ancestor is an ancestor of @p incidence
@@ -1232,8 +1269,8 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@param ancestor is the incidence we are testing to be an ancestor.
@param incidence is the incidence we are testing to be descended from @p ancestor.
*/
- bool isAncestorOf( const Incidence::Ptr &ancestor,
- const Incidence::Ptr &incidence ) const;
+ bool isAncestorOf(const Incidence::Ptr &ancestor,
+ const Incidence::Ptr &incidence) const;
/**
Returns a list of incidences that have a relation of RELTYPE parent
@@ -1241,9 +1278,9 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@param uid The parent identifier whos children we want to obtain.
*/
- Incidence::List relations( const QString &uid ) const;
+ Incidence::List relations(const QString &uid) const;
- // Filter Specific Methods //
+ // Filter Specific Methods //
/**
Sets the calendar filter.
@@ -1254,7 +1291,7 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@see filter()
*/
- void setFilter( CalFilter *filter );
+ void setFilter(CalFilter *filter);
/**
Returns the calendar filter.
@@ -1266,7 +1303,7 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
*/
CalFilter *filter() const;
- // Alarm Specific Methods //
+ // Alarm Specific Methods //
/**
Returns a list of Alarms within a time range for this Calendar.
@@ -1276,9 +1313,9 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@return the list of Alarms for the for the specified time range.
*/
- virtual Alarm::List alarms( const KDateTime &from, const KDateTime &to ) const = 0;
+ virtual Alarm::List alarms(const KDateTime &from, const KDateTime &to) const = 0;
- // Observer Specific Methods //
+ // Observer Specific Methods //
/**
@class CalendarObserver
@@ -1287,7 +1324,7 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
*/
class KCALCORE_EXPORT CalendarObserver //krazy:exclude=dpointer
{
- public:
+ public:
/**
Destructor.
*/
@@ -1300,31 +1337,31 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@param calendar is a pointer to the Calendar object that
is being observed.
*/
- virtual void calendarModified( bool modified, Calendar *calendar );
+ virtual void calendarModified(bool modified, Calendar *calendar);
/**
Notify the Observer that an Incidence has been inserted.
@param incidence is a pointer to the Incidence that was inserted.
*/
- virtual void calendarIncidenceAdded( const Incidence::Ptr &incidence );
+ virtual void calendarIncidenceAdded(const Incidence::Ptr &incidence);
/**
Notify the Observer that an Incidence has been modified.
@param incidence is a pointer to the Incidence that was modified.
*/
- virtual void calendarIncidenceChanged( const Incidence::Ptr &incidence );
+ virtual void calendarIncidenceChanged(const Incidence::Ptr &incidence);
/**
Notify the Observer that an Incidence has been removed.
@param incidence is a pointer to the Incidence that was removed.
*/
- virtual void calendarIncidenceDeleted( const Incidence::Ptr &incidence );
+ virtual void calendarIncidenceDeleted(const Incidence::Ptr &incidence);
/**
Notify the Observer that an addition of Incidence has been canceled.
@param incidence is a pointer to the Incidence that was removed.
*/
- virtual void calendarIncidenceAdditionCanceled( const Incidence::Ptr &incidence );
+ virtual void calendarIncidenceAdditionCanceled(const Incidence::Ptr &incidence);
};
/**
@@ -1335,7 +1372,7 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@see unregisterObserver()
*/
- void registerObserver( CalendarObserver *observer );
+ void registerObserver(CalendarObserver *observer);
/**
Unregisters an Observer for this Calendar.
@@ -1345,48 +1382,48 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@see registerObserver()
*/
- void unregisterObserver( CalendarObserver *observer );
+ void unregisterObserver(CalendarObserver *observer);
using QObject::event; // prevent warning about hidden virtual method
- protected:
+protected:
/**
The Observer interface. So far not implemented.
@param uid is the UID for the Incidence that has been updated.
@param recurrenceId is possible recurrenceid of incidence.
*/
- void incidenceUpdated( const QString &uid, const KDateTime &recurrenceId );
+ void incidenceUpdated(const QString &uid, const KDateTime &recurrenceId);
/**
Let Calendar subclasses set the time specification.
@param timeSpec is the time specification (time zone, etc.) for
viewing Incidence dates.\n
*/
- virtual void doSetTimeSpec( const KDateTime::Spec &timeSpec );
+ virtual void doSetTimeSpec(const KDateTime::Spec &timeSpec);
/**
Let Calendar subclasses notify that they inserted an Incidence.
@param incidence is a pointer to the Incidence object that was inserted.
*/
- void notifyIncidenceAdded( const Incidence::Ptr &incidence );
+ void notifyIncidenceAdded(const Incidence::Ptr &incidence);
/**
Let Calendar subclasses notify that they modified an Incidence.
@param incidence is a pointer to the Incidence object that was modified.
*/
- void notifyIncidenceChanged( const Incidence::Ptr &incidence );
+ void notifyIncidenceChanged(const Incidence::Ptr &incidence);
/**
Let Calendar subclasses notify that they removed an Incidence.
@param incidence is a pointer to the Incidence object that was removed.
*/
- void notifyIncidenceDeleted( const Incidence::Ptr &incidence );
+ void notifyIncidenceDeleted(const Incidence::Ptr &incidence);
/**
Let Calendar subclasses notify that they canceled addition of an Incidence.
@param incidence is a pointer to the Incidence object that addition as canceled.
*/
- void notifyIncidenceAdditionCanceled( const Incidence::Ptr &incidence );
+ void notifyIncidenceAdditionCanceled(const Incidence::Ptr &incidence);
/**
@copydoc
@@ -1400,7 +1437,7 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@param enabled if true tells the calendar that a subclass has
enabled an Observer.
*/
- void setObserversEnabled( bool enabled );
+ void setObserversEnabled(bool enabled);
/**
Appends alarms of incidence in interval to list of alarms.
@@ -1411,8 +1448,8 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@param from is the lower range of the next Alarm repitition.
@param to is the upper range of the next Alarm repitition.
*/
- void appendAlarms( Alarm::List &alarms, const Incidence::Ptr &incidence,
- const KDateTime &from, const KDateTime &to ) const;
+ void appendAlarms(Alarm::List &alarms, const Incidence::Ptr &incidence,
+ const KDateTime &from, const KDateTime &to) const;
/**
Appends alarms of recurring events in interval to list of alarms.
@@ -1423,22 +1460,46 @@ class KCALCORE_EXPORT Calendar : public QObject, public CustomProperties,
@param from is the lower range of the next Alarm repitition.
@param to is the upper range of the next Alarm repitition.
*/
- void appendRecurringAlarms( Alarm::List &alarms, const Incidence::Ptr &incidence,
- const KDateTime &from, const KDateTime &to ) const;
+ void appendRecurringAlarms(Alarm::List &alarms, const Incidence::Ptr &incidence,
+ const KDateTime &from, const KDateTime &to) const;
+
+ /**
+ Enables or disabled deletion tracking.
+ Default is true.
+ @see deletedEvent()
+ @see deletedTodo()
+ @see deletedJournal()
+ @since 4.11
+ */
+ void setDeletionTracking(bool enable);
+
+ /**
+ Returns if deletion tracking is enabled.
+ Default is true.
+ @since 4.11
+ */
+ bool deletionTracking() const;
/**
@copydoc
IncidenceBase::virtual_hook()
*/
- virtual void virtual_hook( int id, void *data );
+ virtual void virtual_hook(int id, void *data);
+
+Q_SIGNALS:
+ /**
+ Emitted when setFilter() is called.
+ @since 4.11
+ */
+ void filterChanged();
- private:
+private:
//@cond PRIVATE
class Private;
Private *const d;
//@endcond
- Q_DISABLE_COPY( Calendar )
+ Q_DISABLE_COPY(Calendar)
};
}
diff --git a/kcalcore/duration.cpp b/kcalcore/duration.cpp
index bab21d0..0267db9 100644
--- a/kcalcore/duration.cpp
+++ b/kcalcore/duration.cpp
@@ -31,7 +31,9 @@
@author David Jarvie \<software@astrojar.org.uk\>
*/
#include "duration.h"
-#include <kdatetime.h>
+#include <KDateTime>
+
+#include <QTime>
using namespace KCalCore;
@@ -42,9 +44,9 @@ using namespace KCalCore;
//@cond PRIVATE
class KCalCore::Duration::Private
{
- public:
+public:
int seconds() const {
- return mDaily ? mDuration * 86400 : mDuration;
+ return mDaily ? mDuration * 86400 : mDuration;
}
int mDuration; // number of seconds or days in the duration
bool mDaily; // specified in terms of days rather than seconds
@@ -52,160 +54,172 @@ class KCalCore::Duration::Private
//@endcond
Duration::Duration()
- : d( new KCalCore::Duration::Private() )
+ : d(new KCalCore::Duration::Private())
{
}
-Duration::Duration( const KDateTime &start, const KDateTime &end )
- : d( new KCalCore::Duration::Private() )
+Duration::Duration(const KDateTime &start, const KDateTime &end)
+ : d(new KCalCore::Duration::Private())
{
- if ( start.time() == end.time() && start.timeSpec() == end.timeSpec() ) {
- d->mDuration = start.daysTo( end );
- d->mDaily = true;
- } else {
- d->mDuration = start.secsTo( end );
- d->mDaily = false;
- }
+ if (start.time() == end.time() && start.timeSpec() == end.timeSpec()) {
+ d->mDuration = start.daysTo(end);
+ d->mDaily = true;
+ } else {
+ d->mDuration = start.secsTo(end);
+ d->mDaily = false;
+ }
}
-Duration::Duration( const KDateTime &start, const KDateTime &end, Type type )
- : d( new KCalCore::Duration::Private() )
-{
- if ( type == Days ) {
- KDateTime endSt( end.toTimeSpec( start ) );
- d->mDuration = start.daysTo( endSt );
- if ( d->mDuration ) {
- // Round down to whole number of days if necessary
- if ( start < endSt ) {
- if ( endSt.time() < start.time() ) {
- --d->mDuration;
+Duration::Duration(const KDateTime &start, const KDateTime &end, Type type)
+ : d(new KCalCore::Duration::Private())
+{
+ if (type == Days) {
+ KDateTime endSt(end.toTimeSpec(start));
+ d->mDuration = start.daysTo(endSt);
+ if (d->mDuration) {
+ // Round down to whole number of days if necessary
+ if (start < endSt) {
+ if (endSt.time() < start.time()) {
+ --d->mDuration;
+ }
+ } else {
+ if (endSt.time() > start.time()) {
+ ++d->mDuration;
+ }
+ }
}
- } else {
- if ( endSt.time() > start.time() ) {
- ++d->mDuration;
- }
- }
+ d->mDaily = true;
+ } else {
+ d->mDuration = start.secsTo(end);
+ d->mDaily = false;
}
- d->mDaily = true;
- } else {
- d->mDuration = start.secsTo( end );
- d->mDaily = false;
- }
}
-Duration::Duration( int duration, Type type )
- : d( new KCalCore::Duration::Private() )
+Duration::Duration(int duration, Type type)
+ : d(new KCalCore::Duration::Private())
{
- d->mDuration = duration;
- d->mDaily = ( type == Days );
+ d->mDuration = duration;
+ d->mDaily = (type == Days);
}
-Duration::Duration( const Duration &duration )
- : d( new KCalCore::Duration::Private( *duration.d ) )
+Duration::Duration(const Duration &duration)
+ : d(new KCalCore::Duration::Private(*duration.d))
{
}
Duration::~Duration()
{
- delete d;
+ delete d;
}
-Duration &Duration::operator=( const Duration &duration )
+Duration &Duration::operator=(const Duration &duration)
{
- // check for self assignment
- if ( &duration == this ) {
- return *this;
- }
+ // check for self assignment
+ if (&duration == this) {
+ return *this;
+ }
- *d = *duration.d;
- return *this;
+ *d = *duration.d;
+ return *this;
}
Duration::operator bool() const
{
- return d->mDuration;
+ return d->mDuration;
}
-bool Duration::operator<( const Duration &other ) const
+bool Duration::operator<(const Duration &other) const
{
- if ( d->mDaily == other.d->mDaily ) {
- // guard against integer overflow for two daily durations
- return d->mDuration < other.d->mDuration;
- }
- return d->seconds() < other.d->seconds();
+ if (d->mDaily == other.d->mDaily) {
+ // guard against integer overflow for two daily durations
+ return d->mDuration < other.d->mDuration;
+ }
+ return d->seconds() < other.d->seconds();
}
-bool Duration::operator==( const Duration &other ) const
+bool Duration::operator==(const Duration &other) const
{
- // Note: daily and non-daily durations are always unequal, since a day's
- // duration may differ from 24 hours if it happens to span a daylight saving
- // time change.
- return d->mDuration == other.d->mDuration &&
- d->mDaily == other.d->mDaily;
+ // Note: daily and non-daily durations are always unequal, since a day's
+ // duration may differ from 24 hours if it happens to span a daylight saving
+ // time change.
+ return d->mDuration == other.d->mDuration &&
+ d->mDaily == other.d->mDaily;
}
-Duration &Duration::operator+=( const Duration &other )
+Duration &Duration::operator+=(const Duration &other)
{
- if ( d->mDaily == other.d->mDaily ) {
- d->mDuration += other.d->mDuration;
- } else if ( d->mDaily ) {
- d->mDuration = d->mDuration * 86400 + other.d->mDuration;
- d->mDaily = false;
- } else {
- d->mDuration += other.d->mDuration + 86400;
- }
- return *this;
+ if (d->mDaily == other.d->mDaily) {
+ d->mDuration += other.d->mDuration;
+ } else if (d->mDaily) {
+ d->mDuration = d->mDuration * 86400 + other.d->mDuration;
+ d->mDaily = false;
+ } else {
+ d->mDuration += other.d->mDuration + 86400;
+ }
+ return *this;
}
Duration Duration::operator-() const
{
- return Duration( -d->mDuration, ( d->mDaily ? Days : Seconds ) );
+ return Duration(-d->mDuration, (d->mDaily ? Days : Seconds));
}
-Duration &Duration::operator-=( const Duration &duration )
+Duration &Duration::operator-=(const Duration &duration)
{
- return operator+=( -duration );
+ return operator+=(-duration);
}
-Duration &Duration::operator*=( int value )
+Duration &Duration::operator*=(int value)
{
- d->mDuration *= value;
- return *this;
+ d->mDuration *= value;
+ return *this;
}
-Duration &Duration::operator/=( int value )
+Duration &Duration::operator/=(int value)
{
- d->mDuration /= value;
- return *this;
+ d->mDuration /= value;
+ return *this;
}
-KDateTime Duration::end( const KDateTime &start ) const
+KDateTime Duration::end(const KDateTime &start) const
{
- return d->mDaily ? start.addDays( d->mDuration )
- : start.addSecs( d->mDuration );
+ return d->mDaily ? start.addDays(d->mDuration)
+ : start.addSecs(d->mDuration);
}
Duration::Type Duration::type() const
{
- return d->mDaily ? Days : Seconds;
+ return d->mDaily ? Days : Seconds;
}
bool Duration::isDaily() const
{
- return d->mDaily;
+ return d->mDaily;
}
int Duration::asSeconds() const
{
- return d->seconds();
+ return d->seconds();
}
int Duration::asDays() const
{
- return d->mDaily ? d->mDuration : d->mDuration / 86400;
+ return d->mDaily ? d->mDuration : d->mDuration / 86400;
}
int Duration::value() const
{
- return d->mDuration;
+ return d->mDuration;
+}
+
+QDataStream &KCalCore::operator<<(QDataStream &out, const KCalCore::Duration &duration)
+{
+ out << duration.d->mDuration << duration.d->mDaily;
+ return out;
+}
+
+QDataStream &KCalCore::operator>>(QDataStream &in, KCalCore::Duration &duration)
+{
+ in >> duration.d->mDuration >> duration.d->mDaily;
+ return in;
}
diff --git a/kcalcore/duration.h b/kcalcore/duration.h
index e7aec11..61d430b 100644
--- a/kcalcore/duration.h
+++ b/kcalcore/duration.h
@@ -33,6 +33,9 @@
#include "kcalcore_export.h"
+#include <QDataStream>
+#include <QMetaType>
+
class KDateTime;
namespace KCalCore {
@@ -51,13 +54,13 @@ namespace KCalCore {
*/
class KCALCORE_EXPORT Duration
{
- public:
+public:
/**
The unit of time used to define the duration.
*/
enum Type {
- Seconds, /**< duration is a number of seconds */
- Days /**< duration is a number of days */
+ Seconds, /**< duration is a number of seconds */
+ Days /**< duration is a number of days */
};
/**
@@ -76,7 +79,7 @@ class KCALCORE_EXPORT Duration
@param start is the time the duration begins.
@param end is the time the duration ends.
*/
- Duration( const KDateTime &start, const KDateTime &end );
+ Duration(const KDateTime &start, const KDateTime &end);
/**
Constructs a duration from @p start to @p end.
@@ -89,7 +92,7 @@ class KCALCORE_EXPORT Duration
@param end is the time the duration ends.
@param type the unit of time to use (seconds or days)
*/
- Duration( const KDateTime &start, const KDateTime &end, Type type );
+ Duration(const KDateTime &start, const KDateTime &end, Type type);
/**
Constructs a duration with a number of seconds or days.
@@ -98,14 +101,14 @@ class KCALCORE_EXPORT Duration
@param type the unit of time to use (seconds or days)
*/
// Keep the following implicit since instances are often used in integer evaluations.
- Duration( int duration, Type type = Seconds ); //krazy:exclude=explicit
+ Duration(int duration, Type type = Seconds); //krazy:exclude=explicit
/**
Constructs a duration by copying another duration object.
@param duration is the duration to copy.
*/
- Duration( const Duration &duration );
+ Duration(const Duration &duration);
/**
Destroys a duration.
@@ -117,7 +120,7 @@ class KCALCORE_EXPORT Duration
@param duration is the duration to copy.
*/
- Duration &operator=( const Duration &duration );
+ Duration &operator=(const Duration &duration);
/**
Returns true if this duration is non-zero.
@@ -127,34 +130,42 @@ class KCALCORE_EXPORT Duration
/**
Returns true if this duration is zero.
*/
- bool operator!() const { return !operator bool(); }
+ bool operator!() const {
+ return !operator bool();
+ }
/**
Returns true if this duration is smaller than the @p other.
@param other is the other duration to compare.
*/
- bool operator<( const Duration &other ) const;
+ bool operator<(const Duration &other) const;
/**
Returns true if this duration is smaller than or equal to the @p other.
@param other is the other duration to compare.
*/
- bool operator<=( const Duration &other ) const
- { return !other.operator<( *this ); }
+ bool operator<=(const Duration &other) const
+ {
+ return !other.operator<(*this);
+ }
/**
Returns true if this duration is greater than the @p other.
@param other is the other duration to compare.
*/
- bool operator>( const Duration &other ) const
- { return other.operator<( *this ); }
+ bool operator>(const Duration &other) const
+ {
+ return other.operator<(*this);
+ }
/**
Returns true if this duration is greater than or equal to the @p other.
@param other is the other duration to compare.
*/
- bool operator>=( const Duration &other ) const
- { return !operator<( other ); }
+ bool operator>=(const Duration &other) const
+ {
+ return !operator<(other);
+ }
/**
Returns true if this duration is equal to the @p other.
@@ -163,7 +174,7 @@ class KCALCORE_EXPORT Duration
saving time change.
@param other the other duration to compare
*/
- bool operator==( const Duration &other ) const;
+ bool operator==(const Duration &other) const;
/**
Returns true if this duration is not equal to the @p other.
@@ -172,8 +183,10 @@ class KCALCORE_EXPORT Duration
saving time change.
@param other is the other duration to compare.
*/
- bool operator!=( const Duration &other ) const
- { return !operator==( other ); }
+ bool operator!=(const Duration &other) const
+ {
+ return !operator==(other);
+ }
/**
Adds another duration to this one.
@@ -181,7 +194,7 @@ class KCALCORE_EXPORT Duration
the result is in terms of seconds.
@param other the other duration to add
*/
- Duration &operator+=( const Duration &other );
+ Duration &operator+=(const Duration &other);
/**
Adds two durations.
@@ -191,8 +204,10 @@ class KCALCORE_EXPORT Duration
@param other the other duration to add
@return combined duration
*/
- Duration operator+( const Duration &other ) const
- { return Duration( *this ) += other; }
+ Duration operator+(const Duration &other) const
+ {
+ return Duration(*this) += other;
+ }
/**
Returns the negative of this duration.
@@ -206,7 +221,7 @@ class KCALCORE_EXPORT Duration
@param other the other duration to subtract
*/
- Duration &operator-=( const Duration &other );
+ Duration &operator-=(const Duration &other);
/**
Returns the difference between another duration and this.
@@ -216,14 +231,16 @@ class KCALCORE_EXPORT Duration
@param other the other duration to subtract
@return difference in durations
*/
- Duration operator-( const Duration &other ) const
- { return Duration( *this ) += other; }
+ Duration operator-(const Duration &other) const
+ {
+ return Duration(*this) += other;
+ }
/**
Multiplies this duration by a value.
@param value value to multiply by
*/
- Duration &operator*=( int value );
+ Duration &operator*=(int value);
/**
Multiplies a duration by a value.
@@ -231,14 +248,16 @@ class KCALCORE_EXPORT Duration
@param value value to multiply by
@return resultant duration
*/
- Duration operator*( int value ) const
- { return Duration( *this ) *= value; }
+ Duration operator*(int value) const
+ {
+ return Duration(*this) *= value;
+ }
/**
Divides this duration by a value.
@param value value to divide by
*/
- Duration &operator/=( int value );
+ Duration &operator/=(int value);
/**
Divides a duration by a value.
@@ -246,8 +265,10 @@ class KCALCORE_EXPORT Duration
@param value value to divide by
@return resultant duration
*/
- Duration operator/( int value ) const
- { return Duration( *this ) /= value; }
+ Duration operator/(int value) const
+ {
+ return Duration(*this) /= value;
+ }
/**
Computes a duration end time by adding the number of seconds or
@@ -256,7 +277,7 @@ class KCALCORE_EXPORT Duration
@param start is the start time.
@return end time.
*/
- KDateTime end( const KDateTime &start ) const;
+ KDateTime end(const KDateTime &start) const;
/**
Returns the time units (seconds or days) used to specify the duration.
@@ -288,13 +309,32 @@ class KCALCORE_EXPORT Duration
*/
int value() const;
- private:
+private:
//@cond PRIVATE
class Private;
Private *const d;
//@endcond
+
+ friend KCALCORE_EXPORT QDataStream &operator<<(QDataStream &s, const KCalCore::Duration &);
+ friend KCALCORE_EXPORT QDataStream &operator>>(QDataStream &s, KCalCore::Duration &);
};
+/**
+ * Duration serializer.
+ *
+ * @since 4.12
+ */
+KCALCORE_EXPORT QDataStream &operator<<(QDataStream &out, const KCalCore::Duration &);
+
+/**
+ * Duration deserializer.
+ *
+ * @since 4.12
+ */
+KCALCORE_EXPORT QDataStream &operator>>(QDataStream &in, KCalCore::Duration &);
+
}
+Q_DECLARE_METATYPE(KCalCore::Duration)
+
#endif
diff --git a/kcalcore/freebusyperiod.cpp b/kcalcore/freebusyperiod.cpp
index a4cf2f2..0f02d63 100644
--- a/kcalcore/freebusyperiod.cpp
+++ b/kcalcore/freebusyperiod.cpp
@@ -37,93 +37,109 @@ using namespace KCalCore;
//@cond PRIVATE
class KCalCore::FreeBusyPeriod::Private
{
- public:
- Private() {}
+public:
+ Private():
+ mType(Unknown)
+ {}
QString mSummary;
QString mLocation;
+ FreeBusyType mType;
};
//@endcond
-FreeBusyPeriod::FreeBusyPeriod() : Period(), d( new KCalCore::FreeBusyPeriod::Private() )
+FreeBusyPeriod::FreeBusyPeriod() : Period(), d(new KCalCore::FreeBusyPeriod::Private())
{
}
-FreeBusyPeriod::FreeBusyPeriod( const KDateTime &start, const KDateTime &end )
- : Period( start, end ), d( new KCalCore::FreeBusyPeriod::Private() )
+FreeBusyPeriod::FreeBusyPeriod(const KDateTime &start, const KDateTime &end)
+ : Period(start, end), d(new KCalCore::FreeBusyPeriod::Private())
{
}
-FreeBusyPeriod::FreeBusyPeriod( const KDateTime &start, const Duration &duration )
- : Period( start, duration ), d( new KCalCore::FreeBusyPeriod::Private() )
+FreeBusyPeriod::FreeBusyPeriod(const KDateTime &start, const Duration &duration)
+ : Period(start, duration), d(new KCalCore::FreeBusyPeriod::Private())
{
}
-FreeBusyPeriod::FreeBusyPeriod( const FreeBusyPeriod &period )
- : Period( period ), d( new KCalCore::FreeBusyPeriod::Private( *period.d ) )
+FreeBusyPeriod::FreeBusyPeriod(const FreeBusyPeriod &period)
+ : Period(period), d(new KCalCore::FreeBusyPeriod::Private(*period.d))
{
}
-FreeBusyPeriod::FreeBusyPeriod( const Period &period )
- : Period( period ), d( new KCalCore::FreeBusyPeriod::Private() )
+FreeBusyPeriod::FreeBusyPeriod(const Period &period)
+ : Period(period), d(new KCalCore::FreeBusyPeriod::Private())
{
}
FreeBusyPeriod::~FreeBusyPeriod()
{
- delete d;
+ delete d;
}
-FreeBusyPeriod &FreeBusyPeriod::operator=( const FreeBusyPeriod &other )
+FreeBusyPeriod &FreeBusyPeriod::operator=(const FreeBusyPeriod &other)
{
- // check for self assignment
- if ( &other == this ) {
- return *this;
- }
+ // check for self assignment
+ if (&other == this) {
+ return *this;
+ }
- Period::operator=(other);
- *d = *other.d;
- return *this;
+ Period::operator=(other);
+ *d = *other.d;
+ return *this;
}
QString FreeBusyPeriod::summary() const
{
- return d->mSummary;
+ return d->mSummary;
}
-void FreeBusyPeriod::setSummary( const QString &summary )
+void FreeBusyPeriod::setSummary(const QString &summary)
{
- d->mSummary = summary;
+ d->mSummary = summary;
}
QString FreeBusyPeriod::location() const
{
- return d->mLocation;
+ return d->mLocation;
+}
+
+void FreeBusyPeriod::setLocation(const QString &location)
+{
+ d->mLocation = location;
}
-void FreeBusyPeriod::setLocation( const QString &location )
+FreeBusyPeriod::FreeBusyType FreeBusyPeriod::type() const
{
- d->mLocation = location;
+ return d->mType;
}
-QDataStream &KCalCore::operator<<( QDataStream &stream, const KCalCore::FreeBusyPeriod &period )
+void FreeBusyPeriod::setType(FreeBusyPeriod::FreeBusyType type)
+{
+ d->mType = type;
+}
+
+
+QDataStream &KCalCore::operator<<(QDataStream &stream, const KCalCore::FreeBusyPeriod &period)
{
- KCalCore::Period periodParent = static_cast<KCalCore::Period>( period );
- stream << periodParent;
- stream << period.summary() << period.location();
- return stream;
+ KCalCore::Period periodParent = static_cast<KCalCore::Period>(period);
+ stream << periodParent;
+ stream << period.summary() << period.location() << static_cast<int>(period.type());
+ return stream;
}
-QDataStream &KCalCore::operator>>( QDataStream &stream, FreeBusyPeriod &period )
+QDataStream &KCalCore::operator>>(QDataStream &stream, FreeBusyPeriod &period)
{
- KCalCore::Period periodParent;
- QString summary, location;
+ KCalCore::Period periodParent;
+ QString summary, location;
+ int type;
- stream >> periodParent >> summary >> location;
+ stream >> periodParent >> summary >> location >> type;
- period = periodParent;
- period.setLocation( location );
- period.setSummary( summary );
- return stream;
+ period = periodParent;
+ period.setLocation(location);
+ period.setSummary(summary);
+ period.setType(static_cast<FreeBusyPeriod::FreeBusyType>(type));
+ return stream;
}
diff --git a/kcalcore/freebusyperiod.h b/kcalcore/freebusyperiod.h
index 5e8f7f3..e4aa00c 100644
--- a/kcalcore/freebusyperiod.h
+++ b/kcalcore/freebusyperiod.h
@@ -45,10 +45,18 @@ namespace KCalCore {
*/
class KCALCORE_EXPORT FreeBusyPeriod : public Period
{
- public:
- /**
- List of periods.
- */
+public:
+ enum FreeBusyType {
+ Free,
+ Busy,
+ BusyUnavailable,
+ BusyTentative,
+ Unknown
+ };
+
+ /**
+ List of periods.
+ */
typedef QVector<FreeBusyPeriod> List;
/**
@@ -62,7 +70,7 @@ class KCALCORE_EXPORT FreeBusyPeriod : public Period
@param start the time the period begins.
@param end the time the period ends.
*/
- FreeBusyPeriod( const KDateTime &start, const KDateTime &end );
+ FreeBusyPeriod(const KDateTime &start, const KDateTime &end);
/**
Constructs a period from @p start and lasting @p duration.
@@ -70,7 +78,7 @@ class KCALCORE_EXPORT FreeBusyPeriod : public Period
@param start the time when the period starts.
@param duration how long the period lasts.
*/
- FreeBusyPeriod( const KDateTime &start, const Duration &duration );
+ FreeBusyPeriod(const KDateTime &start, const Duration &duration);
/**
Constructs a period by copying another period object
@@ -78,7 +86,7 @@ class KCALCORE_EXPORT FreeBusyPeriod : public Period
@param period the period to copy
*/
- FreeBusyPeriod( const FreeBusyPeriod &period );
+ FreeBusyPeriod(const FreeBusyPeriod &period);
/**
Constructs a period by copying another period object
@@ -86,7 +94,7 @@ class KCALCORE_EXPORT FreeBusyPeriod : public Period
@param period the period to copy
*/
- FreeBusyPeriod( const Period &period );
+ FreeBusyPeriod(const Period &period); //krazy:exclude=explicit
/**
Destroys a period.
@@ -98,14 +106,14 @@ class KCALCORE_EXPORT FreeBusyPeriod : public Period
@param other is the other period to compare.
*/
- FreeBusyPeriod &operator=( const FreeBusyPeriod &other );
+ FreeBusyPeriod &operator=(const FreeBusyPeriod &other);
/**
Sets the period summary.
@param summary is the period summary string.
@see summary().
*/
- void setSummary( const QString &summary );
+ void setSummary(const QString &summary);
/**
Returns the period summary.
@@ -118,7 +126,7 @@ class KCALCORE_EXPORT FreeBusyPeriod : public Period
@param location is the period location string.
@see location().
*/
- void setLocation( const QString &location );
+ void setLocation(const QString &location);
/**
Returns the period location.
@@ -126,28 +134,43 @@ class KCALCORE_EXPORT FreeBusyPeriod : public Period
*/
QString location() const;
- private:
+ /**
+ Sets the free/busy type.
+ @param type is the type of free/busy period
+ @see type().
+ @since 4.15
+ */
+ void setType(FreeBusyType type);
+
+ /**
+ Returns free/busy type
+ @see setType().
+ @since 4.15
+ */
+ FreeBusyType type() const;
+
+private:
//@cond PRIVATE
class Private;
Private *const d;
//@endcond
- friend KCALCORE_EXPORT QDataStream &operator<<( QDataStream &stream,
- const KCalCore::FreeBusyPeriod &period );
- friend KCALCORE_EXPORT QDataStream &operator>>( QDataStream &stream,
- KCalCore::FreeBusyPeriod &period );
+ friend KCALCORE_EXPORT QDataStream &operator<<(QDataStream &stream,
+ const KCalCore::FreeBusyPeriod &period);
+ friend KCALCORE_EXPORT QDataStream &operator>>(QDataStream &stream,
+ KCalCore::FreeBusyPeriod &period);
};
/** Write @p period to the datastream @p stream, in binary format. */
-KCALCORE_EXPORT QDataStream &operator<<( QDataStream &stream,
- const KCalCore::FreeBusyPeriod &period );
+KCALCORE_EXPORT QDataStream &operator<<(QDataStream &stream,
+ const KCalCore::FreeBusyPeriod &period);
/** Read a Period object into @p period from @p stream, in binary format. */
-KCALCORE_EXPORT QDataStream &operator>>( QDataStream &stream, KCalCore::FreeBusyPeriod &period );
+KCALCORE_EXPORT QDataStream &operator>>(QDataStream &stream, KCalCore::FreeBusyPeriod &period);
}
//@cond PRIVATE
-Q_DECLARE_METATYPE( KCalCore::FreeBusyPeriod )
+Q_DECLARE_METATYPE(KCalCore::FreeBusyPeriod)
//@endcond
#endif
diff --git a/kcalcore/icalformat_p.cpp b/kcalcore/icalformat_p.cpp
index dfbbc05..03ea0ad 100644
--- a/kcalcore/icalformat_p.cpp
+++ b/kcalcore/icalformat_p.cpp
@@ -4,6 +4,7 @@
Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
Copyright (c) 2006 David Jarvie <software@astrojar.org.uk>
+ Copyright (C) 2012 Christian Mollekopf <mollekopf@kolabsys.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
@@ -46,8 +47,8 @@
#include "todo.h"
#include "visitor.h"
-#include <kcodecs.h>
-#include <QtCore/QDebug>
+#include <KCodecs>
+#include <KDebug>
#include <QtCore/QFile>
@@ -61,34 +62,40 @@ static const char IMPLEMENTATION_VERSION_XPROPERTY[] = "X-KDE-ICAL-IMPLEMENTATIO
/*
static void _dumpIcaltime( const icaltimetype& t)
{
- qDebug() << "--- Y:" << t.year << "M:" << t.month << "D:" << t.day;
- qDebug() << "--- H:" << t.hour << "M:" << t.minute << "S:" << t.second;
- qDebug() << "--- isUtc:" << icaltime_is_utc( t );
- qDebug() << "--- zoneId:" << icaltimezone_get_tzid( const_cast<icaltimezone*>( t.zone ) );
+ kDebug() << "--- Y:" << t.year << "M:" << t.month << "D:" << t.day;
+ kDebug() << "--- H:" << t.hour << "M:" << t.minute << "S:" << t.second;
+ kDebug() << "--- isUtc:" << icaltime_is_utc( t );
+ kDebug() << "--- zoneId:" << icaltimezone_get_tzid( const_cast<icaltimezone*>( t.zone ) );
}
*/
//@cond PRIVATE
template <typename K>
-void removeAllICal( QVector< QSharedPointer<K> > &c, const QSharedPointer<K> &x )
+void removeAllICal(QVector< QSharedPointer<K> > &c, const QSharedPointer<K> &x)
{
- if ( c.count( x ) != 1 ) {
- qCritical() << "The size of the vector is " << c.count();
- Q_ASSERT_X( false, "removeAllICal", "Count is not 1." );
- return;
- }
+ if (c.count() < 1) {
+ return;
+ }
+
+ int cnt = c.count(x);
+ if (cnt != 1) {
+ qCritical() << "There number of relatedTos for this incidence is "
+ << cnt << " (there must be 1 relatedTo only)";
+ Q_ASSERT_X(false, "removeAllICal", "Count is not 1.");
+ return;
+ }
- c.remove( c.indexOf( x ) );
+ c.remove(c.indexOf(x));
}
-static QString quoteForParam( const QString &text )
+static QString quoteForParam(const QString &text)
{
- QString tmp = text;
- tmp.remove( '"' );
- if ( tmp.contains( ';' ) || tmp.contains( ':' ) || tmp.contains( ',' ) ) {
- return tmp; // libical quotes in this case already, see icalparameter_as_ical_string()
- }
- return QString::fromLatin1( "\"" ) + tmp + QString::fromLatin1( "\"" );
+ QString tmp = text;
+ tmp.remove(QLatin1Char('"'));
+ if (tmp.contains(QLatin1Char(';')) || tmp.contains(QLatin1Char(':')) || tmp.contains(QLatin1Char(','))) {
+ return tmp; // libical quotes in this case already, see icalparameter_as_ical_string()
+ }
+ return QString::fromLatin1("\"") + tmp + QString::fromLatin1("\"");
}
const int gSecondsPerMinute = 60;
@@ -98,40 +105,40 @@ const int gSecondsPerWeek = gSecondsPerDay * 7;
class ToComponentVisitor : public Visitor
{
- public:
- ToComponentVisitor( ICalFormatImpl *impl, iTIPMethod m, ICalTimeZones *tzList = 0,
- ICalTimeZones *tzUsedList = 0 )
- : mImpl( impl ), mComponent( 0 ), mMethod( m ), mTzList( tzList ), mTzUsedList( tzUsedList )
+public:
+ ToComponentVisitor(ICalFormatImpl *impl, iTIPMethod m, ICalTimeZones *tzList = 0,
+ ICalTimeZones *tzUsedList = 0)
+ : mImpl(impl), mComponent(0), mMethod(m), mTzList(tzList), mTzUsedList(tzUsedList)
{
}
- bool visit( Event::Ptr e )
+ bool visit(Event::Ptr e)
{
- mComponent = mImpl->writeEvent( e, mTzList, mTzUsedList );
- return true;
+ mComponent = mImpl->writeEvent(e, mTzList, mTzUsedList);
+ return true;
}
- bool visit( Todo::Ptr t )
+ bool visit(Todo::Ptr t)
{
- mComponent = mImpl->writeTodo( t, mTzList, mTzUsedList );
- return true;
+ mComponent = mImpl->writeTodo(t, mTzList, mTzUsedList);
+ return true;
}
- bool visit( Journal::Ptr j )
+ bool visit(Journal::Ptr j)
{
- mComponent = mImpl->writeJournal( j, mTzList, mTzUsedList );
- return true;
+ mComponent = mImpl->writeJournal(j, mTzList, mTzUsedList);
+ return true;
}
- bool visit( FreeBusy::Ptr fb )
+ bool visit(FreeBusy::Ptr fb)
{
- mComponent = mImpl->writeFreeBusy( fb, mMethod );
- return true;
+ mComponent = mImpl->writeFreeBusy(fb, mMethod);
+ return true;
}
icalcomponent *component()
{
- return mComponent;
+ return mComponent;
}
- private:
+private:
ICalFormatImpl *mImpl;
icalcomponent *mComponent;
iTIPMethod mMethod;
@@ -141,14 +148,16 @@ class ToComponentVisitor : public Visitor
class ICalFormatImpl::Private
{
- public:
- Private( ICalFormatImpl *impl, ICalFormat *parent )
- : mImpl( impl ), mParent( parent ), mCompat( new Compat ) {}
- ~Private() { delete mCompat; }
- void writeIncidenceBase( icalcomponent *parent, IncidenceBase::Ptr );
- void readIncidenceBase( icalcomponent *parent, IncidenceBase::Ptr );
- void writeCustomProperties( icalcomponent *parent, CustomProperties * );
- void readCustomProperties( icalcomponent *parent, CustomProperties * );
+public:
+ Private(ICalFormatImpl *impl, ICalFormat *parent)
+ : mImpl(impl), mParent(parent), mCompat(new Compat) {}
+ ~Private() {
+ delete mCompat;
+ }
+ void writeIncidenceBase(icalcomponent *parent, IncidenceBase::Ptr);
+ void readIncidenceBase(icalcomponent *parent, IncidenceBase::Ptr);
+ void writeCustomProperties(icalcomponent *parent, CustomProperties *);
+ void readCustomProperties(icalcomponent *parent, CustomProperties *);
ICalFormatImpl *mImpl;
ICalFormat *mParent;
@@ -159,1829 +168,1973 @@ class ICalFormatImpl::Private
};
//@endcond
-inline icaltimetype ICalFormatImpl::writeICalUtcDateTime ( const KDateTime &dt )
+inline icaltimetype ICalFormatImpl::writeICalUtcDateTime(const KDateTime &dt)
{
- return writeICalDateTime( dt.toUtc() );
+ return writeICalDateTime(dt.toUtc());
}
-ICalFormatImpl::ICalFormatImpl( ICalFormat *parent )
- : d( new Private( this, parent ) )
+ICalFormatImpl::ICalFormatImpl(ICalFormat *parent)
+ : d(new Private(this, parent))
{
}
ICalFormatImpl::~ICalFormatImpl()
{
- delete d;
+ delete d;
}
QString ICalFormatImpl::loadedProductId() const
{
- return d->mLoadedProductId;
+ return d->mLoadedProductId;
}
-icalcomponent *ICalFormatImpl::writeIncidence( const IncidenceBase::Ptr &incidence,
- iTIPMethod method,
- ICalTimeZones *tzList,
- ICalTimeZones *tzUsedList )
+icalcomponent *ICalFormatImpl::writeIncidence(const IncidenceBase::Ptr &incidence,
+ iTIPMethod method,
+ ICalTimeZones *tzList,
+ ICalTimeZones *tzUsedList)
{
- ToComponentVisitor v( this, method, tzList, tzUsedList );
- if ( incidence->accept( v, incidence ) ) {
- return v.component();
- } else {
- return 0;
- }
+ ToComponentVisitor v(this, method, tzList, tzUsedList);
+ if (incidence->accept(v, incidence)) {
+ return v.component();
+ } else {
+ return 0;
+ }
}
-icalcomponent *ICalFormatImpl::writeTodo( const Todo::Ptr &todo, ICalTimeZones *tzlist,
- ICalTimeZones *tzUsedList )
+icalcomponent *ICalFormatImpl::writeTodo(const Todo::Ptr &todo, ICalTimeZones *tzlist,
+ ICalTimeZones *tzUsedList)
{
- QString tmpStr;
- QStringList tmpStrList;
+ QString tmpStr;
+ QStringList tmpStrList;
- icalcomponent *vtodo = icalcomponent_new( ICAL_VTODO_COMPONENT );
+ icalcomponent *vtodo = icalcomponent_new(ICAL_VTODO_COMPONENT);
- writeIncidence( vtodo, todo.staticCast<Incidence>(), tzlist, tzUsedList );
+ writeIncidence(vtodo, todo.staticCast<Incidence>(), tzlist, tzUsedList);
- // due date
- icalproperty *prop;
- if ( todo->hasDueDate() ) {
- icaltimetype due;
- if ( todo->allDay() ) {
- due = writeICalDate( todo->dtDue( true ).date() );
- prop = icalproperty_new_due(due);
- } else {
- prop = writeICalDateTimeProperty(
- ICAL_DUE_PROPERTY, todo->dtDue(true), tzlist, tzUsedList );
+ // due date
+ icalproperty *prop;
+ if (todo->hasDueDate()) {
+ icaltimetype due;
+ if (todo->allDay()) {
+ due = writeICalDate(todo->dtDue(true).date());
+ prop = icalproperty_new_due(due);
+ } else {
+ prop = writeICalDateTimeProperty(
+ ICAL_DUE_PROPERTY, todo->dtDue(true), tzlist, tzUsedList);
+ }
+ icalcomponent_add_property(vtodo, prop);
}
- icalcomponent_add_property( vtodo, prop );
- }
- // start time
- if ( todo->hasStartDate() ) {
- icaltimetype start;
- if ( todo->allDay() ) {
- start = writeICalDate( todo->dtStart( true ).date() );
- prop = icalproperty_new_dtstart( start );
- } else {
- prop = writeICalDateTimeProperty(
- ICAL_DTSTART_PROPERTY, todo->dtStart( true ), tzlist, tzUsedList );
+ // start time
+ if (todo->hasStartDate()) {
+ icaltimetype start;
+ if (todo->allDay()) {
+ start = writeICalDate(todo->dtStart(true).date());
+ prop = icalproperty_new_dtstart(start);
+ } else {
+ prop = writeICalDateTimeProperty(
+ ICAL_DTSTART_PROPERTY, todo->dtStart(true), tzlist, tzUsedList);
+ }
+ icalcomponent_add_property(vtodo, prop);
}
- icalcomponent_add_property( vtodo, prop );
- }
- // completion date (UTC)
- if ( todo->isCompleted() ) {
- if ( !todo->hasCompletedDate() ) {
- // If the todo was created by KOrganizer<2.2 it does not have
- // a correct completion date. Set one now.
- todo->setCompleted( KDateTime::currentUtcDateTime() );
+ // completion date (UTC)
+ if (todo->isCompleted()) {
+ if (!todo->hasCompletedDate()) {
+ // If the todo was created by KOrganizer<2.2 it does not have
+ // a correct completion date. Set one now.
+ todo->setCompleted(KDateTime::currentUtcDateTime());
+ }
+ icaltimetype completed = writeICalUtcDateTime(todo->completed());
+ icalcomponent_add_property(
+ vtodo, icalproperty_new_completed(completed));
}
- icaltimetype completed = writeICalUtcDateTime( todo->completed() );
- icalcomponent_add_property(
- vtodo, icalproperty_new_completed ( completed ) );
- }
- icalcomponent_add_property(
- vtodo, icalproperty_new_percentcomplete( todo->percentComplete() ) );
+ icalcomponent_add_property(
+ vtodo, icalproperty_new_percentcomplete(todo->percentComplete()));
- if ( todo->isCompleted() ) {
- if ( icalcomponent_count_properties( vtodo, ICAL_STATUS_PROPERTY ) ) {
- icalproperty *p = icalcomponent_get_first_property( vtodo, ICAL_STATUS_PROPERTY );
- icalcomponent_remove_property( vtodo, p );
+ if (todo->isCompleted()) {
+ if (icalcomponent_count_properties(vtodo, ICAL_STATUS_PROPERTY)) {
+ icalproperty *p = icalcomponent_get_first_property(vtodo, ICAL_STATUS_PROPERTY);
+ icalcomponent_remove_property(vtodo, p);
+ icalproperty_free(p);
+ }
+ icalcomponent_add_property(vtodo, icalproperty_new_status(ICAL_STATUS_COMPLETED));
}
- icalcomponent_add_property( vtodo, icalproperty_new_status( ICAL_STATUS_COMPLETED ) );
- }
- if ( todo->recurs() && todo->dtDue().isValid() ) {
- // dtDue( first = true ) returns the dtRecurrence()
- prop = writeICalDateTimeProperty( ICAL_X_PROPERTY, todo->dtDue(), tzlist, tzUsedList );
- icalproperty_set_x_name( prop, "X-KDE-LIBKCAL-DTRECURRENCE" );
- icalcomponent_add_property( vtodo, prop );
- }
+ if (todo->recurs() && todo->dtDue().isValid()) {
+ // dtDue( first = true ) returns the dtRecurrence()
+ prop = writeICalDateTimeProperty(ICAL_X_PROPERTY, todo->dtDue(), tzlist, tzUsedList);
+ icalproperty_set_x_name(prop, "X-KDE-LIBKCAL-DTRECURRENCE");
+ icalcomponent_add_property(vtodo, prop);
+ }
- return vtodo;
+ return vtodo;
}
-icalcomponent *ICalFormatImpl::writeEvent( const Event::Ptr &event,
- ICalTimeZones *tzlist,
- ICalTimeZones *tzUsedList )
+icalcomponent *ICalFormatImpl::writeEvent(const Event::Ptr &event,
+ ICalTimeZones *tzlist,
+ ICalTimeZones *tzUsedList)
{
- icalcomponent *vevent = icalcomponent_new( ICAL_VEVENT_COMPONENT );
+ icalcomponent *vevent = icalcomponent_new(ICAL_VEVENT_COMPONENT);
- writeIncidence( vevent, event.staticCast<Incidence>(), tzlist, tzUsedList );
+ writeIncidence(vevent, event.staticCast<Incidence>(), tzlist, tzUsedList);
- // start time
- icalproperty *prop;
- icaltimetype start;
+ // start time
+ icalproperty *prop;
+ icaltimetype start;
- KDateTime dt = event->dtStart();
- if ( dt.isValid() ) {
- if ( event->allDay() ) {
- start = writeICalDate( event->dtStart().date() );
- prop = icalproperty_new_dtstart( start );
- } else {
- prop = writeICalDateTimeProperty(
- ICAL_DTSTART_PROPERTY, event->dtStart(), tzlist, tzUsedList );
+ KDateTime dt = event->dtStart();
+ if (dt.isValid()) {
+ if (event->allDay()) {
+ start = writeICalDate(event->dtStart().date());
+ prop = icalproperty_new_dtstart(start);
+ } else {
+ prop = writeICalDateTimeProperty(
+ ICAL_DTSTART_PROPERTY, event->dtStart(), tzlist, tzUsedList);
+ }
+ icalcomponent_add_property(vevent, prop);
}
- icalcomponent_add_property( vevent, prop );
- }
- if ( event->hasEndDate() ) {
- // End time.
- // RFC2445 says that if DTEND is present, it has to be greater than DTSTART.
- icaltimetype end;
- KDateTime dt = event->dtEnd();
- if ( event->allDay() ) {
+ if (event->hasEndDate()) {
+ // End time.
+ // RFC2445 says that if DTEND is present, it has to be greater than DTSTART.
+ icaltimetype end;
+ KDateTime dt = event->dtEnd();
+ if (event->allDay()) {
#if !defined(KCALCORE_FOR_MEEGO)
- // +1 day because end date is non-inclusive.
- end = writeICalDate( dt.date().addDays( 1 ) );
+ // +1 day because end date is non-inclusive.
+ end = writeICalDate(dt.date().addDays(1));
#else
- end = writeICalDate( dt.date() );
+ end = writeICalDate(dt.date());
#endif
- icalcomponent_add_property( vevent, icalproperty_new_dtend(end) );
- } else {
- if ( dt != event->dtStart() ) {
- icalcomponent_add_property(
- vevent, writeICalDateTimeProperty(
- ICAL_DTEND_PROPERTY, dt, tzlist, tzUsedList ) );
- }
+ icalcomponent_add_property(vevent, icalproperty_new_dtend(end));
+ } else {
+ if (dt != event->dtStart()) {
+ icalcomponent_add_property(
+ vevent, writeICalDateTimeProperty(
+ ICAL_DTEND_PROPERTY, dt, tzlist, tzUsedList));
+ }
+ }
}
- }
// TODO: resources
#if 0
- // resources
- QStringList tmpStrList = anEvent->resources();
- QString tmpStr = tmpStrList.join( ";" );
- if ( !tmpStr.isEmpty() ) {
- addPropValue( vevent, VCResourcesProp, tmpStr.toUtf8() );
- }
+ // resources
+ QStringList tmpStrList = anEvent->resources();
+ QString tmpStr = tmpStrList.join(";");
+ if (!tmpStr.isEmpty()) {
+ addPropValue(vevent, VCResourcesProp, tmpStr.toUtf8());
+ }
#endif
- // Transparency
- switch( event->transparency() ) {
- case Event::Transparent:
- icalcomponent_add_property(
- vevent,
- icalproperty_new_transp( ICAL_TRANSP_TRANSPARENT ) );
- break;
- case Event::Opaque:
- icalcomponent_add_property(
- vevent,
- icalproperty_new_transp( ICAL_TRANSP_OPAQUE ) );
- break;
- }
+ // Transparency
+ switch (event->transparency()) {
+ case Event::Transparent:
+ icalcomponent_add_property(
+ vevent,
+ icalproperty_new_transp(ICAL_TRANSP_TRANSPARENT));
+ break;
+ case Event::Opaque:
+ icalcomponent_add_property(
+ vevent,
+ icalproperty_new_transp(ICAL_TRANSP_OPAQUE));
+ break;
+ }
- return vevent;
+ return vevent;
}
-icalcomponent *ICalFormatImpl::writeFreeBusy( const FreeBusy::Ptr &freebusy,
- iTIPMethod method )
+icalcomponent *ICalFormatImpl::writeFreeBusy(const FreeBusy::Ptr &freebusy,
+ iTIPMethod method)
{
- icalcomponent *vfreebusy = icalcomponent_new( ICAL_VFREEBUSY_COMPONENT );
-
- d->writeIncidenceBase( vfreebusy, freebusy.staticCast<IncidenceBase>() );
+ icalcomponent *vfreebusy = icalcomponent_new(ICAL_VFREEBUSY_COMPONENT);
- icalcomponent_add_property(
- vfreebusy, icalproperty_new_dtstart( writeICalUtcDateTime( freebusy->dtStart() ) ) );
+ d->writeIncidenceBase(vfreebusy, freebusy.staticCast<IncidenceBase>());
- icalcomponent_add_property(
- vfreebusy, icalproperty_new_dtend( writeICalUtcDateTime( freebusy->dtEnd() ) ) );
+ icalcomponent_add_property(
+ vfreebusy, icalproperty_new_dtstart(writeICalUtcDateTime(freebusy->dtStart())));
- Q_UNUSED(method);
- icalcomponent_add_property(
- vfreebusy, icalproperty_new_uid( freebusy->uid().toUtf8() ) );
+ icalcomponent_add_property(
+ vfreebusy, icalproperty_new_dtend(writeICalUtcDateTime(freebusy->dtEnd())));
- //Loops through all the periods in the freebusy object
- Period::List list = freebusy->busyPeriods();
- icalperiodtype period = icalperiodtype_null_period();
- for ( int i = 0, count = list.count(); i < count; ++i ) {
- period.start = writeICalUtcDateTime( list[i].start() );
- if ( list[i].hasDuration() ) {
- period.duration = writeICalDuration( list[i].duration() );
- } else {
- period.end = writeICalUtcDateTime( list[i].end() );
- }
+#ifdef USE_ICAL_1_0
+ Q_UNUSED(method);
icalcomponent_add_property(
- vfreebusy, icalproperty_new_freebusy( period ) );
- }
+ vfreebusy, icalproperty_new_uid(freebusy->uid().toUtf8()));
+#else
+ if (method == iTIPRequest) {
+ icalcomponent_add_property(
+ vfreebusy, icalproperty_new_uid(freebusy->uid().toUtf8()));
+ }
+#endif
- return vfreebusy;
-}
+ //Loops through all the periods in the freebusy object
+ FreeBusyPeriod::List list = freebusy->fullBusyPeriods();
+ icalperiodtype period = icalperiodtype_null_period();
+ for (int i = 0, count = list.count(); i < count; ++i) {
+ const FreeBusyPeriod fbPeriod = list[i];
+ period.start = writeICalUtcDateTime(fbPeriod.start());
+ if (fbPeriod.hasDuration()) {
+ period.duration = writeICalDuration(fbPeriod.duration());
+ } else {
+ period.end = writeICalUtcDateTime(fbPeriod.end());
+ }
-icalcomponent *ICalFormatImpl::writeJournal( const Journal::Ptr &journal,
- ICalTimeZones *tzlist,
- ICalTimeZones *tzUsedList )
-{
- icalcomponent *vjournal = icalcomponent_new( ICAL_VJOURNAL_COMPONENT );
+ icalproperty *property = icalproperty_new_freebusy(period);
+
+ icalparameter_fbtype fbType;
+ switch (fbPeriod.type()) {
+ case FreeBusyPeriod::Free:
+ fbType = ICAL_FBTYPE_FREE;
+ break;
+ case FreeBusyPeriod::Busy:
+ fbType = ICAL_FBTYPE_BUSY;
+ break;
+ case FreeBusyPeriod::BusyTentative:
+ fbType = ICAL_FBTYPE_BUSYTENTATIVE;
+ break;
+ case FreeBusyPeriod::BusyUnavailable:
+ fbType = ICAL_FBTYPE_BUSYUNAVAILABLE;
+ break;
+ case FreeBusyPeriod::Unknown:
+ fbType = ICAL_FBTYPE_X;
+ break;
+ default:
+ fbType = ICAL_FBTYPE_NONE;
+ break;
+ }
+ icalproperty_set_parameter(property, icalparameter_new_fbtype(fbType));
- writeIncidence( vjournal, journal.staticCast<Incidence>(), tzlist, tzUsedList );
+ if (!fbPeriod.summary().isEmpty()) {
+ icalparameter *param = icalparameter_new_x("X-SUMMARY");
+ icalparameter_set_xvalue(param, KCodecs::base64Encode(fbPeriod.summary().toUtf8()));
+ icalproperty_set_parameter(property, param);
+ }
+ if (!fbPeriod.location().isEmpty()) {
+ icalparameter *param = icalparameter_new_x("X-LOCATION");
+ icalparameter_set_xvalue(param, KCodecs::base64Encode(fbPeriod.location().toUtf8()));
+ icalproperty_set_parameter(property, param);
+ }
- // start time
- icalproperty *prop;
- KDateTime dt = journal->dtStart();
- if ( dt.isValid() ) {
- icaltimetype start;
- if ( journal->allDay() ) {
- start = writeICalDate( dt.date() );
- prop = icalproperty_new_dtstart( start );
- } else {
- prop = writeICalDateTimeProperty(
- ICAL_DTSTART_PROPERTY, dt, tzlist, tzUsedList );
+ icalcomponent_add_property(vfreebusy, property);
}
- icalcomponent_add_property( vjournal, prop );
- }
- return vjournal;
+ return vfreebusy;
}
-void ICalFormatImpl::writeIncidence( icalcomponent *parent,
- const Incidence::Ptr &incidence,
- ICalTimeZones *tzlist,
- ICalTimeZones *tzUsedList )
+icalcomponent *ICalFormatImpl::writeJournal(const Journal::Ptr &journal,
+ ICalTimeZones *tzlist,
+ ICalTimeZones *tzUsedList)
{
- if ( incidence->schedulingID() != incidence->uid() ) {
- // We need to store the UID in here. The rawSchedulingID will
- // go into the iCal UID component
- incidence->setCustomProperty( "LIBKCAL", "ID", incidence->uid() );
- } else {
- incidence->removeCustomProperty( "LIBKCAL", "ID" );
- }
+ icalcomponent *vjournal = icalcomponent_new(ICAL_VJOURNAL_COMPONENT);
+
+ writeIncidence(vjournal, journal.staticCast<Incidence>(), tzlist, tzUsedList);
+
+ // start time
+ icalproperty *prop;
+ KDateTime dt = journal->dtStart();
+ if (dt.isValid()) {
+ icaltimetype start;
+ if (journal->allDay()) {
+ start = writeICalDate(dt.date());
+ prop = icalproperty_new_dtstart(start);
+ } else {
+ prop = writeICalDateTimeProperty(
+ ICAL_DTSTART_PROPERTY, dt, tzlist, tzUsedList);
+ }
+ icalcomponent_add_property(vjournal, prop);
+ }
- d->writeIncidenceBase( parent, incidence.staticCast<IncidenceBase>() );
+ return vjournal;
+}
- // creation date in storage
- icalcomponent_add_property(
- parent, writeICalDateTimeProperty(
- ICAL_CREATED_PROPERTY, incidence->created() ) );
+void ICalFormatImpl::writeIncidence(icalcomponent *parent,
+ const Incidence::Ptr &incidence,
+ ICalTimeZones *tzlist,
+ ICalTimeZones *tzUsedList)
+{
+ if (incidence->schedulingID() != incidence->uid()) {
+ // We need to store the UID in here. The rawSchedulingID will
+ // go into the iCal UID component
+ incidence->setCustomProperty("LIBKCAL", "ID", incidence->uid());
+ } else {
+ incidence->removeCustomProperty("LIBKCAL", "ID");
+ }
- // unique id
- // If the scheduling ID is different from the real UID, the real
- // one is stored on X-REALID above
- if ( !incidence->schedulingID().isEmpty() ) {
- icalcomponent_add_property(
- parent, icalproperty_new_uid( incidence->schedulingID().toUtf8() ) );
- }
+ d->writeIncidenceBase(parent, incidence.staticCast<IncidenceBase>());
- // revision
- if ( incidence->revision() > 0 ) { // 0 is default, so don't write that out
+ // creation date in storage
icalcomponent_add_property(
- parent, icalproperty_new_sequence( incidence->revision() ) );
- }
+ parent, writeICalDateTimeProperty(
+ ICAL_CREATED_PROPERTY, incidence->created()));
- // last modification date
- if ( incidence->lastModified().isValid() ) {
- icalcomponent_add_property(
- parent, writeICalDateTimeProperty(
- ICAL_LASTMODIFIED_PROPERTY, incidence->lastModified() ) );
- }
+ // unique id
+ // If the scheduling ID is different from the real UID, the real
+ // one is stored on X-REALID above
+ if (!incidence->schedulingID().isEmpty()) {
+ icalcomponent_add_property(
+ parent, icalproperty_new_uid(incidence->schedulingID().toUtf8()));
+ }
- // description
- if ( !incidence->description().isEmpty() ) {
- icalcomponent_add_property(
- parent, writeDescription(
- incidence->description(), incidence->descriptionIsRich() ) );
- }
+ // revision
+ if (incidence->revision() > 0) { // 0 is default, so don't write that out
+ icalcomponent_add_property(
+ parent, icalproperty_new_sequence(incidence->revision()));
+ }
- // summary
- if ( !incidence->summary().isEmpty() ) {
- icalcomponent_add_property(
- parent, writeSummary(
- incidence->summary(), incidence->summaryIsRich() ) );
- }
+ // last modification date
+ if (incidence->lastModified().isValid()) {
+ icalcomponent_add_property(
+ parent, writeICalDateTimeProperty(
+ ICAL_LASTMODIFIED_PROPERTY, incidence->lastModified()));
+ }
- // location
- if ( !incidence->location().isEmpty() ) {
- icalcomponent_add_property(
- parent, writeLocation(
- incidence->location(), incidence->locationIsRich() ) );
- }
+ // description
+ if (!incidence->description().isEmpty()) {
+ icalcomponent_add_property(
+ parent, writeDescription(
+ incidence->description(), incidence->descriptionIsRich()));
+ }
- // status
- icalproperty_status status = ICAL_STATUS_NONE;
- switch ( incidence->status() ) {
- case Incidence::StatusTentative:
- status = ICAL_STATUS_TENTATIVE;
- break;
- case Incidence::StatusConfirmed:
- status = ICAL_STATUS_CONFIRMED;
- break;
- case Incidence::StatusCompleted:
- status = ICAL_STATUS_COMPLETED;
- break;
- case Incidence::StatusNeedsAction:
- status = ICAL_STATUS_NEEDSACTION;
- break;
- case Incidence::StatusCanceled:
- status = ICAL_STATUS_CANCELLED;
- break;
- case Incidence::StatusInProcess:
- status = ICAL_STATUS_INPROCESS;
- break;
- case Incidence::StatusDraft:
- status = ICAL_STATUS_DRAFT;
- break;
- case Incidence::StatusFinal:
- status = ICAL_STATUS_FINAL;
- break;
- case Incidence::StatusX:
- {
- icalproperty *p = icalproperty_new_status( ICAL_STATUS_X );
- icalvalue_set_x( icalproperty_get_value( p ), incidence->customStatus().toUtf8() );
- icalcomponent_add_property( parent, p );
- break;
- }
- case Incidence::StatusNone:
- default:
- break;
- }
- if ( status != ICAL_STATUS_NONE ) {
- icalcomponent_add_property( parent, icalproperty_new_status( status ) );
- }
+ // summary
+ if (!incidence->summary().isEmpty()) {
+ icalcomponent_add_property(
+ parent, writeSummary(
+ incidence->summary(), incidence->summaryIsRich()));
+ }
- // secrecy
- icalproperty_class secClass;
- switch ( incidence->secrecy() ) {
- case Incidence::SecrecyPublic:
- secClass = ICAL_CLASS_PUBLIC;
- break;
- case Incidence::SecrecyConfidential:
- secClass = ICAL_CLASS_CONFIDENTIAL;
- break;
- case Incidence::SecrecyPrivate:
- default:
- secClass = ICAL_CLASS_PRIVATE;
- break;
- }
- if ( secClass != ICAL_CLASS_PUBLIC ) {
- icalcomponent_add_property( parent, icalproperty_new_class( secClass ) );
- }
+ // location
+ if (!incidence->location().isEmpty()) {
+ icalcomponent_add_property(
+ parent, writeLocation(
+ incidence->location(), incidence->locationIsRich()));
+ }
- // geo
- if ( incidence->hasGeo() ) {
- icalgeotype geo;
- geo.lat = incidence->geoLatitude();
- geo.lon = incidence->geoLongitude();
- icalcomponent_add_property( parent, icalproperty_new_geo( geo ) );
- }
+ // status
+ icalproperty_status status = ICAL_STATUS_NONE;
+ switch (incidence->status()) {
+ case Incidence::StatusTentative:
+ status = ICAL_STATUS_TENTATIVE;
+ break;
+ case Incidence::StatusConfirmed:
+ status = ICAL_STATUS_CONFIRMED;
+ break;
+ case Incidence::StatusCompleted:
+ status = ICAL_STATUS_COMPLETED;
+ break;
+ case Incidence::StatusNeedsAction:
+ status = ICAL_STATUS_NEEDSACTION;
+ break;
+ case Incidence::StatusCanceled:
+ status = ICAL_STATUS_CANCELLED;
+ break;
+ case Incidence::StatusInProcess:
+ status = ICAL_STATUS_INPROCESS;
+ break;
+ case Incidence::StatusDraft:
+ status = ICAL_STATUS_DRAFT;
+ break;
+ case Incidence::StatusFinal:
+ status = ICAL_STATUS_FINAL;
+ break;
+ case Incidence::StatusX:
+ {
+ icalproperty *p = icalproperty_new_status(ICAL_STATUS_X);
+ icalvalue_set_x(icalproperty_get_value(p), incidence->customStatus().toUtf8());
+ icalcomponent_add_property(parent, p);
+ break;
+ }
+ case Incidence::StatusNone:
+ default:
+ break;
+ }
+ if (status != ICAL_STATUS_NONE) {
+ icalcomponent_add_property(parent, icalproperty_new_status(status));
+ }
- // priority
- if ( incidence->priority() > 0 ) { // 0 is undefined priority
- icalcomponent_add_property(
- parent, icalproperty_new_priority( incidence->priority() ) );
- }
+ // secrecy
+ icalproperty_class secClass;
+ switch (incidence->secrecy()) {
+ case Incidence::SecrecyPublic:
+ secClass = ICAL_CLASS_PUBLIC;
+ break;
+ case Incidence::SecrecyConfidential:
+ secClass = ICAL_CLASS_CONFIDENTIAL;
+ break;
+ case Incidence::SecrecyPrivate:
+ default:
+ secClass = ICAL_CLASS_PRIVATE;
+ break;
+ }
+ if (secClass != ICAL_CLASS_PUBLIC) {
+ icalcomponent_add_property(parent, icalproperty_new_class(secClass));
+ }
- // categories
- QString categories = incidence->categories().join( "," );
- if ( !categories.isEmpty() ) {
- icalcomponent_add_property(
- parent, icalproperty_new_categories( categories.toUtf8() ) );
- }
+ // geo
+ if (incidence->hasGeo()) {
+ icalgeotype geo;
+ geo.lat = incidence->geoLatitude();
+ geo.lon = incidence->geoLongitude();
+ icalcomponent_add_property(parent, icalproperty_new_geo(geo));
+ }
- // related event
- if ( !incidence->relatedTo().isEmpty() ) {
- icalcomponent_add_property(
- parent, icalproperty_new_relatedto( incidence->relatedTo().toUtf8() ) );
- }
+ // priority
+ if (incidence->priority() > 0) { // 0 is undefined priority
+ icalcomponent_add_property(
+ parent, icalproperty_new_priority(incidence->priority()));
+ }
- // recurrenceid
- if ( incidence->hasRecurrenceId() ) {
- icalcomponent_add_property(
- parent, writeICalDateTimeProperty(
- ICAL_RECURRENCEID_PROPERTY, incidence->recurrenceId(), tzlist, tzUsedList ) );
- }
+ // categories
+ QString categories = incidence->categories().join(QLatin1String(","));
+ if (!categories.isEmpty()) {
+ icalcomponent_add_property(
+ parent, icalproperty_new_categories(categories.toUtf8()));
+ }
- RecurrenceRule::List rrules( incidence->recurrence()->rRules() );
- RecurrenceRule::List::ConstIterator rit;
- for ( rit = rrules.constBegin(); rit != rrules.constEnd(); ++rit ) {
- icalcomponent_add_property(
- parent, icalproperty_new_rrule( writeRecurrenceRule( (*rit) ) ) );
- }
+ // related event
+ if (!incidence->relatedTo().isEmpty()) {
+ icalcomponent_add_property(
+ parent, icalproperty_new_relatedto(incidence->relatedTo().toUtf8()));
+ }
- RecurrenceRule::List exrules( incidence->recurrence()->exRules() );
- RecurrenceRule::List::ConstIterator exit;
- for ( exit = exrules.constBegin(); exit != exrules.constEnd(); ++exit ) {
- icalcomponent_add_property(
- parent, icalproperty_new_exrule( writeRecurrenceRule( (*exit) ) ) );
- }
+ // recurrenceid
+ if (incidence->hasRecurrenceId()) {
+ icalproperty *p = writeICalDateTimeProperty(
+ ICAL_RECURRENCEID_PROPERTY, incidence->recurrenceId(), tzlist, tzUsedList);
+ if (incidence->thisAndFuture()) {
+ icalproperty_add_parameter(
+ p, icalparameter_new_range(ICAL_RANGE_THISANDFUTURE));
+ }
+ icalcomponent_add_property(parent, p);
+ }
- DateList dateList = incidence->recurrence()->exDates();
- DateList::ConstIterator exIt;
- for ( exIt = dateList.constBegin(); exIt != dateList.constEnd(); ++exIt ) {
- icalcomponent_add_property(
- parent, icalproperty_new_exdate( writeICalDate(*exIt) ) );
- }
+ RecurrenceRule::List rrules(incidence->recurrence()->rRules());
+ RecurrenceRule::List::ConstIterator rit;
+ for (rit = rrules.constBegin(); rit != rrules.constEnd(); ++rit) {
+ icalcomponent_add_property(
+ parent, icalproperty_new_rrule(writeRecurrenceRule((*rit))));
+ }
- DateTimeList dateTimeList = incidence->recurrence()->exDateTimes();
- DateTimeList::ConstIterator extIt;
- for ( extIt = dateTimeList.constBegin(); extIt != dateTimeList.constEnd(); ++extIt ) {
- icalcomponent_add_property(
- parent, writeICalDateTimeProperty( ICAL_EXDATE_PROPERTY, *extIt, tzlist, tzUsedList ) );
- }
+ RecurrenceRule::List exrules(incidence->recurrence()->exRules());
+ RecurrenceRule::List::ConstIterator exit;
+ for (exit = exrules.constBegin(); exit != exrules.constEnd(); ++exit) {
+ icalcomponent_add_property(
+ parent, icalproperty_new_exrule(writeRecurrenceRule((*exit))));
+ }
- dateList = incidence->recurrence()->rDates();
- DateList::ConstIterator rdIt;
- for ( rdIt = dateList.constBegin(); rdIt != dateList.constEnd(); ++rdIt ) {
- icalcomponent_add_property(
- parent, icalproperty_new_rdate( writeICalDatePeriod(*rdIt) ) );
- }
- dateTimeList = incidence->recurrence()->rDateTimes();
- DateTimeList::ConstIterator rdtIt;
- for ( rdtIt = dateTimeList.constBegin(); rdtIt != dateTimeList.constEnd(); ++rdtIt ) {
- icalcomponent_add_property(
- parent, writeICalDateTimeProperty( ICAL_RDATE_PROPERTY, *rdtIt, tzlist, tzUsedList ) );
- }
+ DateList dateList = incidence->recurrence()->exDates();
+ DateList::ConstIterator exIt;
+ for (exIt = dateList.constBegin(); exIt != dateList.constEnd(); ++exIt) {
+ icalcomponent_add_property(
+ parent, icalproperty_new_exdate(writeICalDate(*exIt)));
+ }
- // attachments
- Attachment::List attachments = incidence->attachments();
- Attachment::List::ConstIterator atIt;
- for ( atIt = attachments.constBegin(); atIt != attachments.constEnd(); ++atIt ) {
- icalcomponent_add_property( parent, writeAttachment( *atIt ) );
- }
+ DateTimeList dateTimeList = incidence->recurrence()->exDateTimes();
+ DateTimeList::ConstIterator extIt;
+ for (extIt = dateTimeList.constBegin(); extIt != dateTimeList.constEnd(); ++extIt) {
+ icalcomponent_add_property(
+ parent, writeICalDateTimeProperty(ICAL_EXDATE_PROPERTY, *extIt, tzlist, tzUsedList));
+ }
- // alarms
- Alarm::List::ConstIterator alarmIt;
- for ( alarmIt = incidence->alarms().constBegin();
- alarmIt != incidence->alarms().constEnd(); ++alarmIt ) {
- icalcomponent_add_component( parent, writeAlarm( *alarmIt ) );
- }
+ dateList = incidence->recurrence()->rDates();
+ DateList::ConstIterator rdIt;
+ for (rdIt = dateList.constBegin(); rdIt != dateList.constEnd(); ++rdIt) {
+ icalcomponent_add_property(
+ parent, icalproperty_new_rdate(writeICalDatePeriod(*rdIt)));
+ }
+ dateTimeList = incidence->recurrence()->rDateTimes();
+ DateTimeList::ConstIterator rdtIt;
+ for (rdtIt = dateTimeList.constBegin(); rdtIt != dateTimeList.constEnd(); ++rdtIt) {
+ icalcomponent_add_property(
+ parent, writeICalDateTimeProperty(ICAL_RDATE_PROPERTY, *rdtIt, tzlist, tzUsedList));
+ }
- // duration
- if ( incidence->hasDuration() ) {
- icaldurationtype duration;
- duration = writeICalDuration( incidence->duration() );
- icalcomponent_add_property( parent, icalproperty_new_duration( duration ) );
- }
+ // attachments
+ Attachment::List attachments = incidence->attachments();
+ Attachment::List::ConstIterator atIt;
+ for (atIt = attachments.constBegin(); atIt != attachments.constEnd(); ++atIt) {
+ icalcomponent_add_property(parent, writeAttachment(*atIt));
+ }
+
+ // alarms
+ Alarm::List::ConstIterator alarmIt;
+ for (alarmIt = incidence->alarms().constBegin();
+ alarmIt != incidence->alarms().constEnd(); ++alarmIt) {
+ icalcomponent_add_component(parent, writeAlarm(*alarmIt));
+ }
+
+ // duration
+ if (incidence->hasDuration()) {
+ icaldurationtype duration;
+ duration = writeICalDuration(incidence->duration());
+ icalcomponent_add_property(parent, icalproperty_new_duration(duration));
+ }
}
//@cond PRIVATE
-void ICalFormatImpl::Private::writeIncidenceBase( icalcomponent *parent,
- IncidenceBase::Ptr incidenceBase )
+void ICalFormatImpl::Private::writeIncidenceBase(icalcomponent *parent,
+ IncidenceBase::Ptr incidenceBase)
{
- // organizer stuff
- if ( !incidenceBase->organizer()->isEmpty() ) {
- icalproperty *p = mImpl->writeOrganizer( incidenceBase->organizer() );
- if ( p ) {
- icalcomponent_add_property( parent, p );
+ // organizer stuff
+ if (!incidenceBase->organizer()->isEmpty()) {
+ icalproperty *p = mImpl->writeOrganizer(incidenceBase->organizer());
+ if (p) {
+ icalcomponent_add_property(parent, p);
+ }
}
- }
- icalcomponent_add_property(
- parent, icalproperty_new_dtstamp( writeICalUtcDateTime( incidenceBase->lastModified() ) ) );
-
- // attendees
- if ( incidenceBase->attendeeCount() > 0 ) {
- Attendee::List::ConstIterator it;
- for ( it = incidenceBase->attendees().constBegin();
- it != incidenceBase->attendees().constEnd(); ++it ) {
- icalproperty *p = mImpl->writeAttendee( *it );
- if ( p ) {
- icalcomponent_add_property( parent, p );
- }
+ icalcomponent_add_property(
+ parent, icalproperty_new_dtstamp(writeICalUtcDateTime(incidenceBase->lastModified())));
+
+ // attendees
+ if (incidenceBase->attendeeCount() > 0) {
+ Attendee::List::ConstIterator it;
+ for (it = incidenceBase->attendees().constBegin();
+ it != incidenceBase->attendees().constEnd(); ++it) {
+ icalproperty *p = mImpl->writeAttendee(*it);
+ if (p) {
+ icalcomponent_add_property(parent, p);
+ }
+ }
}
- }
- //contacts
- QStringList contacts = incidenceBase->contacts();
- for ( QStringList::const_iterator it = contacts.constBegin(); it != contacts.constEnd(); ++it ) {
- icalcomponent_add_property( parent, icalproperty_new_contact( (*it).toUtf8() ) );
- }
+ //contacts
+ QStringList contacts = incidenceBase->contacts();
+ for (QStringList::const_iterator it = contacts.constBegin(); it != contacts.constEnd(); ++it) {
+ icalcomponent_add_property(parent, icalproperty_new_contact((*it).toUtf8()));
+ }
- // comments
- QStringList comments = incidenceBase->comments();
- for ( QStringList::const_iterator it = comments.constBegin(); it != comments.constEnd(); ++it ) {
- icalcomponent_add_property( parent, icalproperty_new_comment( (*it).toUtf8() ) );
- }
+ // comments
+ QStringList comments = incidenceBase->comments();
+ for (QStringList::const_iterator it = comments.constBegin(); it != comments.constEnd(); ++it) {
+ icalcomponent_add_property(parent, icalproperty_new_comment((*it).toUtf8()));
+ }
+
+ // url
+ const QUrl url = incidenceBase->url();
+ if (url.isValid()) {
+ icalcomponent_add_property(parent, icalproperty_new_url(url.toString().toUtf8()));
+ }
- // custom properties
- writeCustomProperties( parent, incidenceBase.data() );
+ // custom properties
+ writeCustomProperties(parent, incidenceBase.data());
}
-void ICalFormatImpl::Private::writeCustomProperties( icalcomponent *parent,
- CustomProperties *properties )
+void ICalFormatImpl::Private::writeCustomProperties(icalcomponent *parent,
+ CustomProperties *properties)
{
- const QMap<QByteArray, QString> custom = properties->customProperties();
- for ( QMap<QByteArray, QString>::ConstIterator c = custom.begin(); c != custom.end(); ++c ) {
-
- icalproperty *p = icalproperty_new_x( c.value().toUtf8() );
- QString parameters = properties->nonKDECustomPropertyParameters( c.key() );
-
- // Minimalist parameter handler: extract icalparameter's out of
- // the given input text (not really parsing as such)
- if ( !parameters.isEmpty() ) {
- QStringList sl = parameters.split( ';' );
- foreach ( const QString &parameter, sl ) {
- icalparameter *param = icalparameter_new_from_string( parameter.toUtf8() );
- if ( param ) {
- icalproperty_add_parameter( p, param );
+ const QMap<QByteArray, QString> custom = properties->customProperties();
+ for (QMap<QByteArray, QString>::ConstIterator c = custom.begin(); c != custom.end(); ++c) {
+ if (c.key().startsWith("X-KDE-VOLATILE")) { //krazy:exclude=strings
+ // We don't write these properties to disk to disk
+ continue;
+ }
+ icalproperty *p = icalproperty_new_x(c.value().toUtf8());
+ QString parameters = properties->nonKDECustomPropertyParameters(c.key());
+
+ // Minimalist parameter handler: extract icalparameter's out of
+ // the given input text (not really parsing as such)
+ if (!parameters.isEmpty()) {
+ QStringList sl = parameters.split(QLatin1Char(';'));
+ foreach(const QString &parameter, sl) {
+ icalparameter *param = icalparameter_new_from_string(parameter.toUtf8());
+ if (param) {
+ icalproperty_add_parameter(p, param);
+ }
+ }
}
- }
- }
- icalproperty_set_x_name( p, c.key() );
- icalcomponent_add_property( parent, p );
- }
+ icalproperty_set_x_name(p, c.key());
+ icalcomponent_add_property(parent, p);
+ }
}
//@endcond
-icalproperty *ICalFormatImpl::writeOrganizer( const Person::Ptr &organizer )
+icalproperty *ICalFormatImpl::writeOrganizer(const Person::Ptr &organizer)
{
- if ( organizer->email().isEmpty() ) {
- return 0;
- }
+ if (organizer->email().isEmpty()) {
+ return 0;
+ }
- icalproperty *p = icalproperty_new_organizer( "MAILTO:" + organizer->email().toUtf8() );
+ icalproperty *p = icalproperty_new_organizer(QByteArray(QByteArray("MAILTO:") + organizer->email().toUtf8()));
- if ( !organizer->name().isEmpty() ) {
- icalproperty_add_parameter(
- p, icalparameter_new_cn( quoteForParam( organizer->name() ).toUtf8() ) );
- }
- // TODO: Write dir, sent-by and language
+ if (!organizer->name().isEmpty()) {
+ icalproperty_add_parameter(
+ p, icalparameter_new_cn(quoteForParam(organizer->name()).toUtf8()));
+ }
+ // TODO: Write dir, sent-by and language
- return p;
+ return p;
}
-icalproperty *ICalFormatImpl::writeDescription( const QString &description, bool isRich )
+icalproperty *ICalFormatImpl::writeDescription(const QString &description, bool isRich)
{
- icalproperty *p = icalproperty_new_description( description.toUtf8() );
- if ( isRich ) {
- icalproperty_add_parameter( p, icalparameter_new_from_string( "X-KDE-TEXTFORMAT=HTML" ) );
- }
- return p;
+ icalproperty *p = icalproperty_new_description(description.toUtf8());
+ if (isRich) {
+ icalproperty_add_parameter(p, icalparameter_new_from_string("X-KDE-TEXTFORMAT=HTML"));
+ }
+ return p;
}
-icalproperty *ICalFormatImpl::writeSummary( const QString &summary, bool isRich )
+icalproperty *ICalFormatImpl::writeSummary(const QString &summary, bool isRich)
{
- icalproperty *p = icalproperty_new_summary( summary.toUtf8() );
- if ( isRich ) {
- icalproperty_add_parameter( p, icalparameter_new_from_string( "X-KDE-TEXTFORMAT=HTML" ) );
- }
- return p;
+ icalproperty *p = icalproperty_new_summary(summary.toUtf8());
+ if (isRich) {
+ icalproperty_add_parameter(p, icalparameter_new_from_string("X-KDE-TEXTFORMAT=HTML"));
+ }
+ return p;
}
-icalproperty *ICalFormatImpl::writeLocation( const QString &location, bool isRich )
+icalproperty *ICalFormatImpl::writeLocation(const QString &location, bool isRich)
{
- icalproperty *p = icalproperty_new_location( location.toUtf8() );
- if ( isRich ) {
- icalproperty_add_parameter( p, icalparameter_new_from_string( "X-KDE-TEXTFORMAT=HTML" ) );
- }
- return p;
+ icalproperty *p = icalproperty_new_location(location.toUtf8());
+ if (isRich) {
+ icalproperty_add_parameter(p, icalparameter_new_from_string("X-KDE-TEXTFORMAT=HTML"));
+ }
+ return p;
}
-icalproperty *ICalFormatImpl::writeAttendee( const Attendee::Ptr &attendee )
+icalproperty *ICalFormatImpl::writeAttendee(const Attendee::Ptr &attendee)
{
- if ( attendee->email().isEmpty() ) {
- return 0;
- }
+ if (attendee->email().isEmpty()) {
+ return 0;
+ }
- icalproperty *p =
- icalproperty_new_attendee( "mailto:" + attendee->email().toUtf8() );
+ icalproperty *p =
+ icalproperty_new_attendee(QByteArray(QByteArray("mailto:") + attendee->email().toUtf8()));
+
+ if (!attendee->name().isEmpty()) {
+ icalproperty_add_parameter(
+ p, icalparameter_new_cn(quoteForParam(attendee->name()).toUtf8()));
+ }
- if ( !attendee->name().isEmpty() ) {
icalproperty_add_parameter(
- p, icalparameter_new_cn( quoteForParam( attendee->name() ).toUtf8() ) );
- }
+ p, icalparameter_new_rsvp(attendee->RSVP() ? ICAL_RSVP_TRUE : ICAL_RSVP_FALSE));
- icalproperty_add_parameter(
- p, icalparameter_new_rsvp( attendee->RSVP() ? ICAL_RSVP_TRUE : ICAL_RSVP_FALSE ) );
+ icalparameter_partstat status = ICAL_PARTSTAT_NEEDSACTION;
+ switch (attendee->status()) {
+ default:
+ case Attendee::NeedsAction:
+ status = ICAL_PARTSTAT_NEEDSACTION;
+ break;
+ case Attendee::Accepted:
+ status = ICAL_PARTSTAT_ACCEPTED;
+ break;
+ case Attendee::Declined:
+ status = ICAL_PARTSTAT_DECLINED;
+ break;
+ case Attendee::Tentative:
+ status = ICAL_PARTSTAT_TENTATIVE;
+ break;
+ case Attendee::Delegated:
+ status = ICAL_PARTSTAT_DELEGATED;
+ break;
+ case Attendee::Completed:
+ status = ICAL_PARTSTAT_COMPLETED;
+ break;
+ case Attendee::InProcess:
+ status = ICAL_PARTSTAT_INPROCESS;
+ break;
+ }
+ icalproperty_add_parameter(p, icalparameter_new_partstat(status));
- icalparameter_partstat status = ICAL_PARTSTAT_NEEDSACTION;
- switch ( attendee->status() ) {
- default:
- case Attendee::NeedsAction:
- status = ICAL_PARTSTAT_NEEDSACTION;
- break;
- case Attendee::Accepted:
- status = ICAL_PARTSTAT_ACCEPTED;
- break;
- case Attendee::Declined:
- status = ICAL_PARTSTAT_DECLINED;
- break;
- case Attendee::Tentative:
- status = ICAL_PARTSTAT_TENTATIVE;
- break;
- case Attendee::Delegated:
- status = ICAL_PARTSTAT_DELEGATED;
- break;
- case Attendee::Completed:
- status = ICAL_PARTSTAT_COMPLETED;
- break;
- case Attendee::InProcess:
- status = ICAL_PARTSTAT_INPROCESS;
- break;
- }
- icalproperty_add_parameter( p, icalparameter_new_partstat( status ) );
+ icalparameter_role role = ICAL_ROLE_REQPARTICIPANT;
+ switch (attendee->role()) {
+ case Attendee::Chair:
+ role = ICAL_ROLE_CHAIR;
+ break;
+ default:
+ case Attendee::ReqParticipant:
+ role = ICAL_ROLE_REQPARTICIPANT;
+ break;
+ case Attendee::OptParticipant:
+ role = ICAL_ROLE_OPTPARTICIPANT;
+ break;
+ case Attendee::NonParticipant:
+ role = ICAL_ROLE_NONPARTICIPANT;
+ break;
+ }
+ icalproperty_add_parameter(p, icalparameter_new_role(role));
- icalparameter_role role = ICAL_ROLE_REQPARTICIPANT;
- switch ( attendee->role() ) {
- case Attendee::Chair:
- role = ICAL_ROLE_CHAIR;
- break;
- default:
- case Attendee::ReqParticipant:
- role = ICAL_ROLE_REQPARTICIPANT;
- break;
- case Attendee::OptParticipant:
- role = ICAL_ROLE_OPTPARTICIPANT;
- break;
- case Attendee::NonParticipant:
- role = ICAL_ROLE_NONPARTICIPANT;
- break;
- }
- icalproperty_add_parameter( p, icalparameter_new_role( role ) );
+ icalparameter_cutype cutype = ICAL_CUTYPE_INDIVIDUAL;
+ switch (attendee->cuType()) {
+ case Attendee::Unknown:
+ cutype = ICAL_CUTYPE_UNKNOWN;
+ break;
+ default:
+ case Attendee::Individual:
+ cutype = ICAL_CUTYPE_INDIVIDUAL;
+ break;
+ case Attendee::Group:
+ cutype = ICAL_CUTYPE_GROUP;
+ break;
+ case Attendee::Resource:
+ cutype = ICAL_CUTYPE_RESOURCE;
+ break;
+ case Attendee::Room:
+ cutype = ICAL_CUTYPE_ROOM;
+ break;
+ }
+ icalproperty_add_parameter(p, icalparameter_new_cutype(cutype));
- if ( !attendee->uid().isEmpty() ) {
- icalparameter *icalparameter_uid = icalparameter_new_x( attendee->uid().toUtf8() );
+ if (!attendee->uid().isEmpty()) {
+ icalparameter *icalparameter_uid = icalparameter_new_x(attendee->uid().toUtf8());
- icalparameter_set_xname( icalparameter_uid, "X-UID" );
- icalproperty_add_parameter( p, icalparameter_uid );
- }
+ icalparameter_set_xname(icalparameter_uid, "X-UID");
+ icalproperty_add_parameter(p, icalparameter_uid);
+ }
- if ( !attendee->delegate().isEmpty() ) {
- icalparameter *icalparameter_delegate =
- icalparameter_new_delegatedto( attendee->delegate().toUtf8() );
- icalproperty_add_parameter( p, icalparameter_delegate );
- }
+ if (!attendee->delegate().isEmpty()) {
+ icalparameter *icalparameter_delegate =
+ icalparameter_new_delegatedto(attendee->delegate().toUtf8());
+ icalproperty_add_parameter(p, icalparameter_delegate);
+ }
- if ( !attendee->delegator().isEmpty() ) {
- icalparameter *icalparameter_delegator =
- icalparameter_new_delegatedfrom( attendee->delegator().toUtf8() );
- icalproperty_add_parameter( p, icalparameter_delegator );
- }
+ if (!attendee->delegator().isEmpty()) {
+ icalparameter *icalparameter_delegator =
+ icalparameter_new_delegatedfrom(attendee->delegator().toUtf8());
+ icalproperty_add_parameter(p, icalparameter_delegator);
+ }
- return p;
+ return p;
}
-icalproperty *ICalFormatImpl::writeAttachment( const Attachment::Ptr &att )
+icalproperty *ICalFormatImpl::writeAttachment(const Attachment::Ptr &att)
{
- icalattach *attach;
- if ( att->isUri() ) {
- attach = icalattach_new_from_url( att->uri().toUtf8().data() );
- } else {
+ icalattach *attach;
+ if (att->isUri()) {
+ attach = icalattach_new_from_url(att->uri().toUtf8().data());
+ } else {
#ifdef USE_ICAL_0_46
- attach = icalattach_new_from_data( ( const char * )att->data().data(), 0, 0 );
+ attach = icalattach_new_from_data((const char *)att->data().data(), 0, 0);
#else
- attach = icalattach_new_from_data( ( unsigned char * )att->data().data(), 0, 0 );
+ attach = icalattach_new_from_data((unsigned char *)att->data().data(), 0, 0);
#endif
- }
- icalproperty *p = icalproperty_new_attach( attach );
+ }
+ icalproperty *p = icalproperty_new_attach(attach);
- icalattach_unref( attach );
+ icalattach_unref(attach);
- if ( !att->mimeType().isEmpty() ) {
- icalproperty_add_parameter(
- p, icalparameter_new_fmttype( att->mimeType().toUtf8().data() ) );
- }
+ if (!att->mimeType().isEmpty()) {
+ icalproperty_add_parameter(
+ p, icalparameter_new_fmttype(att->mimeType().toUtf8().data()));
+ }
- if ( att->isBinary() ) {
- icalproperty_add_parameter( p, icalparameter_new_value( ICAL_VALUE_BINARY ) );
- icalproperty_add_parameter( p, icalparameter_new_encoding( ICAL_ENCODING_BASE64 ) );
- }
+ if (att->isBinary()) {
+ icalproperty_add_parameter(p, icalparameter_new_value(ICAL_VALUE_BINARY));
+ icalproperty_add_parameter(p, icalparameter_new_encoding(ICAL_ENCODING_BASE64));
+ }
- if ( att->showInline() ) {
- icalparameter *icalparameter_inline = icalparameter_new_x( "inline" );
- icalparameter_set_xname( icalparameter_inline, "X-CONTENT-DISPOSITION" );
- icalproperty_add_parameter( p, icalparameter_inline );
- }
+ if (att->showInline()) {
+ icalparameter *icalparameter_inline = icalparameter_new_x("inline");
+ icalparameter_set_xname(icalparameter_inline, "X-CONTENT-DISPOSITION");
+ icalproperty_add_parameter(p, icalparameter_inline);
+ }
- if ( !att->label().isEmpty() ) {
- icalparameter *icalparameter_label = icalparameter_new_x( att->label().toUtf8() );
- icalparameter_set_xname( icalparameter_label, "X-LABEL" );
- icalproperty_add_parameter( p, icalparameter_label );
- }
+ if (!att->label().isEmpty()) {
+ icalparameter *icalparameter_label = icalparameter_new_x(att->label().toUtf8());
+ icalparameter_set_xname(icalparameter_label, "X-LABEL");
+ icalproperty_add_parameter(p, icalparameter_label);
+ }
- if ( att->isLocal() ) {
- icalparameter *icalparameter_local = icalparameter_new_x( "local" );
- icalparameter_set_xname( icalparameter_local, "X-KONTACT-TYPE" );
- icalproperty_add_parameter( p, icalparameter_local );
- }
+ if (att->isLocal()) {
+ icalparameter *icalparameter_local = icalparameter_new_x("local");
+ icalparameter_set_xname(icalparameter_local, "X-KONTACT-TYPE");
+ icalproperty_add_parameter(p, icalparameter_local);
+ }
- return p;
+ return p;
}
-icalrecurrencetype ICalFormatImpl::writeRecurrenceRule( RecurrenceRule *recur )
+icalrecurrencetype ICalFormatImpl::writeRecurrenceRule(RecurrenceRule *recur)
{
- icalrecurrencetype r;
- icalrecurrencetype_clear( &r );
+ icalrecurrencetype r;
+ icalrecurrencetype_clear(&r);
- switch( recur->recurrenceType() ) {
- case RecurrenceRule::rSecondly:
- r.freq = ICAL_SECONDLY_RECURRENCE;
- break;
- case RecurrenceRule::rMinutely:
- r.freq = ICAL_MINUTELY_RECURRENCE;
- break;
- case RecurrenceRule::rHourly:
- r.freq = ICAL_HOURLY_RECURRENCE;
- break;
- case RecurrenceRule::rDaily:
- r.freq = ICAL_DAILY_RECURRENCE;
- break;
- case RecurrenceRule::rWeekly:
- r.freq = ICAL_WEEKLY_RECURRENCE;
- break;
- case RecurrenceRule::rMonthly:
- r.freq = ICAL_MONTHLY_RECURRENCE;
- break;
- case RecurrenceRule::rYearly:
- r.freq = ICAL_YEARLY_RECURRENCE;
- break;
- default:
- r.freq = ICAL_NO_RECURRENCE;
- qDebug() << "no recurrence";
- break;
- }
+ switch (recur->recurrenceType()) {
+ case RecurrenceRule::rSecondly:
+ r.freq = ICAL_SECONDLY_RECURRENCE;
+ break;
+ case RecurrenceRule::rMinutely:
+ r.freq = ICAL_MINUTELY_RECURRENCE;
+ break;
+ case RecurrenceRule::rHourly:
+ r.freq = ICAL_HOURLY_RECURRENCE;
+ break;
+ case RecurrenceRule::rDaily:
+ r.freq = ICAL_DAILY_RECURRENCE;
+ break;
+ case RecurrenceRule::rWeekly:
+ r.freq = ICAL_WEEKLY_RECURRENCE;
+ break;
+ case RecurrenceRule::rMonthly:
+ r.freq = ICAL_MONTHLY_RECURRENCE;
+ break;
+ case RecurrenceRule::rYearly:
+ r.freq = ICAL_YEARLY_RECURRENCE;
+ break;
+ default:
+ r.freq = ICAL_NO_RECURRENCE;
+ kDebug() << "no recurrence";
+ break;
+ }
- int index = 0;
- QList<int> bys;
- QList<int>::ConstIterator it;
+ int index = 0;
+ QList<int> bys;
+ QList<int>::ConstIterator it;
- // Now write out the BY* parts:
- bys = recur->bySeconds();
- index = 0;
- for ( it = bys.constBegin(); it != bys.constEnd(); ++it ) {
- r.by_second[index++] = *it;
- r.by_second[index++] = static_cast<short>( *it );
- }
+ // Now write out the BY* parts:
+ bys = recur->bySeconds();
+ index = 0;
+ for (it = bys.constBegin(); it != bys.constEnd(); ++it) {
+ r.by_second[index++] = *it;
+ r.by_second[index++] = static_cast<short>(*it);
+ }
- bys = recur->byMinutes();
- index = 0;
- for ( it = bys.constBegin(); it != bys.constEnd(); ++it ) {
- r.by_minute[index++] = *it;
- r.by_minute[index++] = static_cast<short>( *it );
- }
+ bys = recur->byMinutes();
+ index = 0;
+ for (it = bys.constBegin(); it != bys.constEnd(); ++it) {
+ r.by_minute[index++] = *it;
+ r.by_minute[index++] = static_cast<short>(*it);
+ }
- bys = recur->byHours();
- index = 0;
- for ( it = bys.constBegin(); it != bys.constEnd(); ++it ) {
- r.by_hour[index++] = *it;
- r.by_hour[index++] = static_cast<short>( *it );
- }
+ bys = recur->byHours();
+ index = 0;
+ for (it = bys.constBegin(); it != bys.constEnd(); ++it) {
+ r.by_hour[index++] = *it;
+ r.by_hour[index++] = static_cast<short>(*it);
+ }
- bys = recur->byMonthDays();
- index = 0;
- for ( it = bys.constBegin(); it != bys.constEnd(); ++it ) {
- short dShort = static_cast<short>( ( *it ) * 8 );
- r.by_month_day[index++] = static_cast<short>( icalrecurrencetype_day_position( dShort ) );
- }
+ bys = recur->byMonthDays();
+ index = 0;
+ for (it = bys.constBegin(); it != bys.constEnd(); ++it) {
+ short dShort = static_cast<short>((*it) * 8);
+ r.by_month_day[index++] = static_cast<short>(icalrecurrencetype_day_position(dShort));
+ }
- bys = recur->byYearDays();
- index = 0;
- for ( it = bys.constBegin(); it != bys.constEnd(); ++it ) {
- r.by_year_day[index++] = static_cast<short>( *it );
- }
+ bys = recur->byYearDays();
+ index = 0;
+ for (it = bys.constBegin(); it != bys.constEnd(); ++it) {
+ r.by_year_day[index++] = static_cast<short>(*it);
+ }
- bys = recur->byWeekNumbers();
- index = 0;
- for ( it = bys.constBegin(); it != bys.constEnd(); ++it ) {
- r.by_week_no[index++] = static_cast<short>( *it );
- }
+ bys = recur->byWeekNumbers();
+ index = 0;
+ for (it = bys.constBegin(); it != bys.constEnd(); ++it) {
+ r.by_week_no[index++] = static_cast<short>(*it);
+ }
- bys = recur->byMonths();
- index = 0;
- for ( it = bys.constBegin(); it != bys.constEnd(); ++it ) {
- r.by_month[index++] = static_cast<short>( *it );
- }
+ bys = recur->byMonths();
+ index = 0;
+ for (it = bys.constBegin(); it != bys.constEnd(); ++it) {
+ r.by_month[index++] = static_cast<short>(*it);
+ }
- bys = recur->bySetPos();
- index = 0;
- for ( it = bys.constBegin(); it != bys.constEnd(); ++it ) {
- r.by_set_pos[index++] = static_cast<short>( *it );
- }
+ bys = recur->bySetPos();
+ index = 0;
+ for (it = bys.constBegin(); it != bys.constEnd(); ++it) {
+ r.by_set_pos[index++] = static_cast<short>(*it);
+ }
- QList<RecurrenceRule::WDayPos> byd = recur->byDays();
- int day;
- index = 0;
- for ( QList<RecurrenceRule::WDayPos>::ConstIterator dit = byd.constBegin();
- dit != byd.constEnd(); ++dit ) {
- day = (*dit).day() % 7 + 1; // convert from Monday=1 to Sunday=1
- if ( (*dit).pos() < 0 ) {
- day += ( -(*dit).pos() ) * 8;
- day = -day;
- } else {
- day += (*dit).pos() * 8;
+ QList<RecurrenceRule::WDayPos> byd = recur->byDays();
+ int day;
+ index = 0;
+ for (QList<RecurrenceRule::WDayPos>::ConstIterator dit = byd.constBegin();
+ dit != byd.constEnd(); ++dit) {
+ day = (*dit).day() % 7 + 1; // convert from Monday=1 to Sunday=1
+ if ((*dit).pos() < 0) {
+ day += (-(*dit).pos()) * 8;
+ day = -day;
+ } else {
+ day += (*dit).pos() * 8;
+ }
+ r.by_day[index++] = static_cast<short>(day);
}
- r.by_day[index++] = static_cast<short>( day );
- }
- r.week_start =
- static_cast<icalrecurrencetype_weekday>( recur->weekStart() % 7 + 1 );
+ r.week_start =
+ static_cast<icalrecurrencetype_weekday>(recur->weekStart() % 7 + 1);
- if ( recur->frequency() > 1 ) {
- // Dont' write out INTERVAL=1, because that's the default anyway
- r.interval = static_cast<short>( recur->frequency() );
- }
+ if (recur->frequency() > 1) {
+ // Dont' write out INTERVAL=1, because that's the default anyway
+ r.interval = static_cast<short>(recur->frequency());
+ }
- if ( recur->duration() > 0 ) {
- r.count = recur->duration();
- } else if ( recur->duration() == -1 ) {
- r.count = 0;
- } else {
- if ( recur->allDay() ) {
- r.until = writeICalDate( recur->endDt().date() );
+ if (recur->duration() > 0) {
+ r.count = recur->duration();
+ } else if (recur->duration() == -1) {
+ r.count = 0;
} else {
- r.until = writeICalUtcDateTime( recur->endDt() );
+ if (recur->allDay()) {
+ r.until = writeICalDate(recur->endDt().date());
+ } else {
+ r.until = writeICalUtcDateTime(recur->endDt());
+ }
}
- }
- return r;
+ return r;
}
-icalcomponent *ICalFormatImpl::writeAlarm( const Alarm::Ptr &alarm )
+icalcomponent *ICalFormatImpl::writeAlarm(const Alarm::Ptr &alarm)
{
- if ( alarm->enabled() ) {
- alarm->setCustomProperty( APP_NAME_FOR_XPROPERTIES, ENABLED_ALARM_XPROPERTY, "TRUE" );
- } else {
- alarm->setCustomProperty( APP_NAME_FOR_XPROPERTIES, ENABLED_ALARM_XPROPERTY, "FALSE" );
- }
-
- icalcomponent *a = icalcomponent_new( ICAL_VALARM_COMPONENT );
-
- icalproperty_action action;
- icalattach *attach = 0;
-
- switch ( alarm->type() ) {
- case Alarm::Procedure:
- action = ICAL_ACTION_PROCEDURE;
- attach = icalattach_new_from_url(
- QFile::encodeName( alarm->programFile() ).data() );
- icalcomponent_add_property( a, icalproperty_new_attach( attach ) );
- if ( !alarm->programArguments().isEmpty() ) {
- icalcomponent_add_property(
- a, icalproperty_new_description( alarm->programArguments().toUtf8() ) );
- }
- break;
- case Alarm::Audio:
- action = ICAL_ACTION_AUDIO;
- if ( !alarm->audioFile().isEmpty() ) {
- attach = icalattach_new_from_url(
- QFile::encodeName( alarm->audioFile() ).data() );
- icalcomponent_add_property( a, icalproperty_new_attach( attach ) );
- }
- break;
- case Alarm::Email:
- {
- action = ICAL_ACTION_EMAIL;
- const Person::List addresses = alarm->mailAddresses();
- for ( Person::List::ConstIterator ad = addresses.constBegin();
- ad != addresses.constEnd(); ++ad ) {
- if ( !(*ad)->email().isEmpty() ) {
- icalproperty *p = icalproperty_new_attendee( "MAILTO:" + (*ad)->email().toUtf8() );
- if ( !(*ad)->name().isEmpty() ) {
- icalproperty_add_parameter(
- p, icalparameter_new_cn( quoteForParam( (*ad)->name() ).toUtf8() ) );
- }
- icalcomponent_add_property( a, p );
- }
- }
- icalcomponent_add_property(
- a, icalproperty_new_summary( alarm->mailSubject().toUtf8() ) );
- icalcomponent_add_property(
- a, icalproperty_new_description( alarm->mailText().toUtf8() ) );
- QStringList attachments = alarm->mailAttachments();
- if ( attachments.count() > 0 ) {
- for ( QStringList::const_iterator at = attachments.constBegin();
- at != attachments.constEnd(); ++at ) {
- attach = icalattach_new_from_url( QFile::encodeName( *at ).data() );
- icalcomponent_add_property( a, icalproperty_new_attach( attach ) );
- }
- }
- break;
- }
- case Alarm::Display:
- action = ICAL_ACTION_DISPLAY;
- icalcomponent_add_property(
- a, icalproperty_new_description( alarm->text().toUtf8() ) );
- break;
- case Alarm::Invalid:
- default:
- qDebug() << "Unknown type of alarm";
- action = ICAL_ACTION_NONE;
- break;
- }
- icalcomponent_add_property( a, icalproperty_new_action( action ) );
-
- // Trigger time
- icaltriggertype trigger;
- if ( alarm->hasTime() ) {
- trigger.time = writeICalUtcDateTime( alarm->time() );
- trigger.duration = icaldurationtype_null_duration();
- } else {
- trigger.time = icaltime_null_time();
- Duration offset;
- if ( alarm->hasStartOffset() ) {
- offset = alarm->startOffset();
+ if (alarm->enabled()) {
+ alarm->setCustomProperty(APP_NAME_FOR_XPROPERTIES, ENABLED_ALARM_XPROPERTY, QLatin1String("TRUE"));
} else {
- offset = alarm->endOffset();
+ alarm->setCustomProperty(APP_NAME_FOR_XPROPERTIES, ENABLED_ALARM_XPROPERTY, QLatin1String("FALSE"));
}
- trigger.duration = writeICalDuration( offset );
- }
- icalproperty *p = icalproperty_new_trigger( trigger );
- if ( alarm->hasEndOffset() ) {
- icalproperty_add_parameter( p, icalparameter_new_related( ICAL_RELATED_END ) );
- }
- icalcomponent_add_property( a, p );
- // Repeat count and duration
- if ( alarm->repeatCount() ) {
- icalcomponent_add_property(
- a, icalproperty_new_repeat( alarm->repeatCount() ) );
- icalcomponent_add_property(
- a, icalproperty_new_duration( writeICalDuration( alarm->snoozeTime() ) ) );
- }
+ icalcomponent *a = icalcomponent_new(ICAL_VALARM_COMPONENT);
- // Custom properties
- const QMap<QByteArray, QString> custom = alarm->customProperties();
- for ( QMap<QByteArray, QString>::ConstIterator c = custom.begin(); c != custom.end(); ++c ) {
- icalproperty *p = icalproperty_new_x( c.value().toUtf8() );
- icalproperty_set_x_name( p, c.key() );
- icalcomponent_add_property( a, p );
- }
-
- icalattach_unref( attach );
-
- return a;
-}
+ icalproperty_action action;
+ icalattach *attach = 0;
-Todo::Ptr ICalFormatImpl::readTodo( icalcomponent *vtodo, ICalTimeZones *tzlist )
-{
- Todo::Ptr todo( new Todo );
-
- readIncidence( vtodo, todo, tzlist );
-
- icalproperty *p = icalcomponent_get_first_property( vtodo, ICAL_ANY_PROPERTY );
-
- while ( p ) {
- icalproperty_kind kind = icalproperty_isa(p);
- switch ( kind ) {
- case ICAL_DUE_PROPERTY:
- { // due date/time
- KDateTime kdt = readICalDateTimeProperty( p, tzlist );
- todo->setDtDue( kdt, true );
- todo->setHasDueDate( true );
- todo->setAllDay( kdt.isDateOnly() );
- break;
- }
- case ICAL_COMPLETED_PROPERTY: // completion date/time
- todo->setCompleted( readICalDateTimeProperty( p, tzlist ) );
- break;
-
- case ICAL_PERCENTCOMPLETE_PROPERTY: // Percent completed
- todo->setPercentComplete( icalproperty_get_percentcomplete( p ) );
- break;
-
- case ICAL_RELATEDTO_PROPERTY: // related todo (parent)
- todo->setRelatedTo( QString::fromUtf8( icalproperty_get_relatedto( p ) ) );
- d->mTodosRelate.append( todo );
- break;
-
- case ICAL_DTSTART_PROPERTY:
- // Flag that todo has start date. Value is read in by readIncidence().
- if ( todo->comments().filter( "NoStartDate" ).count() ) {
- todo->setHasStartDate( false );
- } else {
- todo->setHasStartDate( true );
- }
- break;
- case ICAL_X_PROPERTY:
+ switch (alarm->type()) {
+ case Alarm::Procedure:
+ action = ICAL_ACTION_PROCEDURE;
+ attach = icalattach_new_from_url(
+ QFile::encodeName(alarm->programFile()).data());
+ icalcomponent_add_property(a, icalproperty_new_attach(attach));
+ if (!alarm->programArguments().isEmpty()) {
+ icalcomponent_add_property(
+ a, icalproperty_new_description(alarm->programArguments().toUtf8()));
+ }
+ break;
+ case Alarm::Audio:
+ action = ICAL_ACTION_AUDIO;
+ if (!alarm->audioFile().isEmpty()) {
+ attach = icalattach_new_from_url(
+ QFile::encodeName(alarm->audioFile()).data());
+ icalcomponent_add_property(a, icalproperty_new_attach(attach));
+ }
+ break;
+ case Alarm::Email:
{
- const KDateTime dateTime = readICalDateTimeProperty( p, tzlist );
- if ( dateTime.isValid() ) {
- todo->setDtRecurrence( dateTime );
- } else {
- qDebug() << "Invalid dateTime";
- }
+ action = ICAL_ACTION_EMAIL;
+ const Person::List addresses = alarm->mailAddresses();
+ for (Person::List::ConstIterator ad = addresses.constBegin();
+ ad != addresses.constEnd(); ++ad) {
+ if (!(*ad)->email().isEmpty()) {
+ icalproperty *p = icalproperty_new_attendee(QByteArray(QByteArray("MAILTO:") + (*ad)->email().toUtf8()));
+ if (!(*ad)->name().isEmpty()) {
+ icalproperty_add_parameter(
+ p, icalparameter_new_cn(quoteForParam((*ad)->name()).toUtf8()));
+ }
+ icalcomponent_add_property(a, p);
+ }
+ }
+ icalcomponent_add_property(
+ a, icalproperty_new_summary(alarm->mailSubject().toUtf8()));
+ icalcomponent_add_property(
+ a, icalproperty_new_description(alarm->mailText().toUtf8()));
+ QStringList attachments = alarm->mailAttachments();
+ if (attachments.count() > 0) {
+ for (QStringList::const_iterator at = attachments.constBegin();
+ at != attachments.constEnd(); ++at) {
+ attach = icalattach_new_from_url(QFile::encodeName(*at).data());
+ icalcomponent_add_property(a, icalproperty_new_attach(attach));
+ }
+ }
+ break;
}
- break;
+ case Alarm::Display:
+ action = ICAL_ACTION_DISPLAY;
+ icalcomponent_add_property(
+ a, icalproperty_new_description(alarm->text().toUtf8()));
+ break;
+ case Alarm::Invalid:
default:
- // TODO: do something about unknown properties?
- break;
+ kDebug() << "Unknown type of alarm";
+ action = ICAL_ACTION_NONE;
+ break;
}
+ icalcomponent_add_property(a, icalproperty_new_action(action));
- p = icalcomponent_get_next_property( vtodo, ICAL_ANY_PROPERTY );
- }
+ // Trigger time
+ icaltriggertype trigger;
+ if (alarm->hasTime()) {
+ trigger.time = writeICalUtcDateTime(alarm->time());
+ trigger.duration = icaldurationtype_null_duration();
+ } else {
+ trigger.time = icaltime_null_time();
+ Duration offset;
+ if (alarm->hasStartOffset()) {
+ offset = alarm->startOffset();
+ } else {
+ offset = alarm->endOffset();
+ }
+ trigger.duration = writeICalDuration(offset);
+ }
+ icalproperty *p = icalproperty_new_trigger(trigger);
+ if (alarm->hasEndOffset()) {
+ icalproperty_add_parameter(p, icalparameter_new_related(ICAL_RELATED_END));
+ }
+ icalcomponent_add_property(a, p);
- if ( d->mCompat ) {
- d->mCompat->fixEmptySummary( todo );
- }
+ // Repeat count and duration
+ if (alarm->repeatCount()) {
+ icalcomponent_add_property(
+ a, icalproperty_new_repeat(alarm->repeatCount()));
+ icalcomponent_add_property(
+ a, icalproperty_new_duration(writeICalDuration(alarm->snoozeTime())));
+ }
- return todo;
+ // Custom properties
+ const QMap<QByteArray, QString> custom = alarm->customProperties();
+ for (QMap<QByteArray, QString>::ConstIterator c = custom.begin(); c != custom.end(); ++c) {
+ icalproperty *p = icalproperty_new_x(c.value().toUtf8());
+ icalproperty_set_x_name(p, c.key());
+ icalcomponent_add_property(a, p);
+ }
+
+ icalattach_unref(attach);
+
+ return a;
}
-Event::Ptr ICalFormatImpl::readEvent( icalcomponent *vevent, ICalTimeZones *tzlist )
+Todo::Ptr ICalFormatImpl::readTodo(icalcomponent *vtodo, ICalTimeZones *tzlist)
{
- Event::Ptr event( new Event );
-
- readIncidence( vevent, event, tzlist );
+ Todo::Ptr todo(new Todo);
- icalproperty *p = icalcomponent_get_first_property( vevent, ICAL_ANY_PROPERTY );
+ readIncidence(vtodo, todo, tzlist);
- bool dtEndProcessed = false;
+ icalproperty *p = icalcomponent_get_first_property(vtodo, ICAL_ANY_PROPERTY);
- while ( p ) {
- icalproperty_kind kind = icalproperty_isa( p );
- switch ( kind ) {
- case ICAL_DTEND_PROPERTY:
- { // end date and time
- KDateTime kdt = readICalDateTimeProperty( p, tzlist );
- if ( kdt.isDateOnly() ) {
- // End date is non-inclusive
- QDate endDate = kdt.date().addDays( -1 );
- if ( d->mCompat ) {
- d->mCompat->fixFloatingEnd( endDate );
+ while (p) {
+ icalproperty_kind kind = icalproperty_isa(p);
+ switch (kind) {
+ case ICAL_DUE_PROPERTY:
+ { // due date/time
+ KDateTime kdt = readICalDateTimeProperty(p, tzlist);
+ todo->setDtDue(kdt, true);
+ todo->setAllDay(kdt.isDateOnly());
+ break;
}
- if ( endDate < event->dtStart().date() ) {
- endDate = event->dtStart().date();
+ case ICAL_COMPLETED_PROPERTY: // completion date/time
+ todo->setCompleted(readICalDateTimeProperty(p, tzlist));
+ break;
+
+ case ICAL_PERCENTCOMPLETE_PROPERTY: // Percent completed
+ todo->setPercentComplete(icalproperty_get_percentcomplete(p));
+ break;
+
+ case ICAL_RELATEDTO_PROPERTY: // related todo (parent)
+ todo->setRelatedTo(QString::fromUtf8(icalproperty_get_relatedto(p)));
+ d->mTodosRelate.append(todo);
+ break;
+
+ case ICAL_DTSTART_PROPERTY:
+ // Flag that todo has start date. Value is read in by readIncidence().
+ if (todo->comments().filter(QLatin1String("NoStartDate")).count()) {
+ todo->setDtStart(KDateTime());
+ } else {
+ todo->setHasStartDate(true);
+ }
+ break;
+ case ICAL_X_PROPERTY:
+ {
+ //FIXME we should figure out which x-property we're trying to read here.
+ //Just setting any parsable date that happens to be stored in an x-property is clearly wrong.
+ const KDateTime dateTime = readICalDateTimeProperty(p, tzlist);
+ if (dateTime.isValid()) {
+ todo->setDtRecurrence(dateTime);
+ }
+ }
+ break;
+ default:
+ // TODO: do something about unknown properties?
+ break;
}
- event->setDtEnd( KDateTime( endDate, event->dtStart().timeSpec() ) );
- } else {
- event->setDtEnd( kdt );
- event->setAllDay( false );
- }
- dtEndProcessed = true;
- break;
- }
- case ICAL_RELATEDTO_PROPERTY: // related event (parent)
- event->setRelatedTo( QString::fromUtf8( icalproperty_get_relatedto( p ) ) );
- d->mEventsRelate.append( event );
- break;
- case ICAL_TRANSP_PROPERTY: // Transparency
- {
- icalproperty_transp transparency = icalproperty_get_transp( p );
- if ( transparency == ICAL_TRANSP_TRANSPARENT ) {
- event->setTransparency( Event::Transparent );
- } else {
- event->setTransparency( Event::Opaque );
- }
- break;
+ p = icalcomponent_get_next_property(vtodo, ICAL_ANY_PROPERTY);
}
- default:
- // TODO: do something about unknown properties?
- break;
+ if (d->mCompat) {
+ d->mCompat->fixEmptySummary(todo);
}
- p = icalcomponent_get_next_property( vevent, ICAL_ANY_PROPERTY );
- }
-
- // according to rfc2445 the dtend shouldn't be written when it equals
- // start date. so assign one equal to start date.
- if ( !dtEndProcessed && !event->hasDuration() ) {
- event->setDtEnd( event->dtStart() );
- event->setHasEndDate( false );
- }
-
- QString msade = event->nonKDECustomProperty( "X-MICROSOFT-CDO-ALLDAYEVENT" );
- if ( !msade.isEmpty() ) {
- bool allDay = ( msade == QLatin1String( "TRUE" ) );
- event->setAllDay( allDay );
- }
-
- if ( d->mCompat ) {
- d->mCompat->fixEmptySummary( event );
- }
-
- return event;
+ todo->resetDirtyFields();
+ return todo;
}
-FreeBusy::Ptr ICalFormatImpl::readFreeBusy( icalcomponent *vfreebusy )
+Event::Ptr ICalFormatImpl::readEvent(icalcomponent *vevent, ICalTimeZones *tzlist)
{
- FreeBusy::Ptr freebusy( new FreeBusy );
+ Event::Ptr event(new Event);
+
+ readIncidence(vevent, event, tzlist);
+
+ icalproperty *p = icalcomponent_get_first_property(vevent, ICAL_ANY_PROPERTY);
+
+ bool dtEndProcessed = false;
+
+ while (p) {
+ icalproperty_kind kind = icalproperty_isa(p);
+ switch (kind) {
+ case ICAL_DTEND_PROPERTY:
+ { // end date and time
+ KDateTime kdt = readICalDateTimeProperty(p, tzlist);
+ if (kdt.isDateOnly()) {
+ // End date is non-inclusive
+ QDate endDate = kdt.date().addDays(-1);
+ if (d->mCompat) {
+ d->mCompat->fixFloatingEnd(endDate);
+ }
+ if (endDate < event->dtStart().date()) {
+ endDate = event->dtStart().date();
+ }
+ event->setDtEnd(KDateTime(endDate, event->dtStart().timeSpec()));
+ } else {
+ event->setDtEnd(kdt);
+ event->setAllDay(false);
+ }
+ dtEndProcessed = true;
+ break;
+ }
+ case ICAL_RELATEDTO_PROPERTY: // related event (parent)
+ event->setRelatedTo(QString::fromUtf8(icalproperty_get_relatedto(p)));
+ d->mEventsRelate.append(event);
+ break;
+
+ case ICAL_TRANSP_PROPERTY: // Transparency
+ {
+ icalproperty_transp transparency = icalproperty_get_transp(p);
+ if (transparency == ICAL_TRANSP_TRANSPARENT) {
+ event->setTransparency(Event::Transparent);
+ } else {
+ event->setTransparency(Event::Opaque);
+ }
+ break;
+ }
- d->readIncidenceBase( vfreebusy, freebusy );
+ default:
+ // TODO: do something about unknown properties?
+ break;
+ }
- icalproperty *p = icalcomponent_get_first_property( vfreebusy, ICAL_ANY_PROPERTY );
+ p = icalcomponent_get_next_property(vevent, ICAL_ANY_PROPERTY);
+ }
- FreeBusyPeriod::List periods;
+ // according to rfc2445 the dtend shouldn't be written when it equals
+ // start date. so assign one equal to start date.
+ if (!dtEndProcessed && !event->hasDuration()) {
+ event->setDtEnd(event->dtStart());
+ event->setHasEndDate(false);
+ }
- while ( p ) {
- icalproperty_kind kind = icalproperty_isa( p );
- switch ( kind ) {
- case ICAL_DTSTART_PROPERTY: // start date and time (UTC)
- freebusy->setDtStart( readICalUtcDateTimeProperty( p ) );
- break;
+ QString msade = event->nonKDECustomProperty("X-MICROSOFT-CDO-ALLDAYEVENT");
+ if (!msade.isEmpty()) {
+ bool allDay = (msade == QLatin1String("TRUE"));
+ event->setAllDay(allDay);
+ }
- case ICAL_DTEND_PROPERTY: // end Date and Time (UTC)
- freebusy->setDtEnd( readICalUtcDateTimeProperty( p ) );
- break;
+ if (d->mCompat) {
+ d->mCompat->fixEmptySummary(event);
+ }
- case ICAL_FREEBUSY_PROPERTY: //Any FreeBusy Times (UTC)
- {
- icalperiodtype icalperiod = icalproperty_get_freebusy( p );
- KDateTime period_start = readICalUtcDateTime( p, icalperiod.start );
- FreeBusyPeriod period;
- if ( !icaltime_is_null_time( icalperiod.end ) ) {
- KDateTime period_end = readICalUtcDateTime( p, icalperiod.end );
- period = FreeBusyPeriod( period_start, period_end );
- } else {
- Duration duration ( readICalDuration( icalperiod.duration ) );
- period = FreeBusyPeriod( period_start, duration );
- }
+ event->resetDirtyFields();
+ return event;
+}
- icalparameter *param = icalproperty_get_first_parameter( p, ICAL_X_PARAMETER );
- while ( param ) {
- if ( strncmp( icalparameter_get_xname( param ), "X-SUMMARY", 9 ) == 0 ) {
- period.setSummary( QString::fromUtf8(
- KCodecs::base64Decode( icalparameter_get_xvalue( param ) ) ) );
- }
- if ( strncmp( icalparameter_get_xname( param ), "X-LOCATION", 10 ) == 0 ) {
- period.setLocation( QString::fromUtf8(
- KCodecs::base64Decode( icalparameter_get_xvalue( param ) ) ) );
+FreeBusy::Ptr ICalFormatImpl::readFreeBusy(icalcomponent *vfreebusy)
+{
+ FreeBusy::Ptr freebusy(new FreeBusy);
+
+ d->readIncidenceBase(vfreebusy, freebusy);
+
+ icalproperty *p = icalcomponent_get_first_property(vfreebusy, ICAL_ANY_PROPERTY);
+
+ FreeBusyPeriod::List periods;
+
+ while (p) {
+ icalproperty_kind kind = icalproperty_isa(p);
+ switch (kind) {
+ case ICAL_DTSTART_PROPERTY: // start date and time (UTC)
+ freebusy->setDtStart(readICalUtcDateTimeProperty(p));
+ break;
+
+ case ICAL_DTEND_PROPERTY: // end Date and Time (UTC)
+ freebusy->setDtEnd(readICalUtcDateTimeProperty(p));
+ break;
+
+ case ICAL_FREEBUSY_PROPERTY: //Any FreeBusy Times (UTC)
+ {
+ icalperiodtype icalperiod = icalproperty_get_freebusy(p);
+ KDateTime period_start = readICalUtcDateTime(p, icalperiod.start);
+ FreeBusyPeriod period;
+ if (!icaltime_is_null_time(icalperiod.end)) {
+ KDateTime period_end = readICalUtcDateTime(p, icalperiod.end);
+ period = FreeBusyPeriod(period_start, period_end);
+ } else {
+ Duration duration(readICalDuration(icalperiod.duration));
+ period = FreeBusyPeriod(period_start, duration);
+ }
+
+ icalparameter *param = icalproperty_get_first_parameter(p, ICAL_FBTYPE_PARAMETER);
+ if (param) {
+ icalparameter_fbtype fbType = icalparameter_get_fbtype(param);
+ switch (fbType) {
+ case ICAL_FBTYPE_FREE:
+ period.setType(FreeBusyPeriod::Free);
+ break;
+ case ICAL_FBTYPE_BUSY:
+ period.setType(FreeBusyPeriod::Busy);
+ break;
+ case ICAL_FBTYPE_BUSYTENTATIVE:
+ period.setType(FreeBusyPeriod::BusyTentative);
+ break;
+ case ICAL_FBTYPE_BUSYUNAVAILABLE:
+ period.setType(FreeBusyPeriod::BusyUnavailable);
+ break;
+ case ICAL_FBTYPE_X:
+ period.setType(FreeBusyPeriod::Unknown);
+ break;
+ case ICAL_FBTYPE_NONE:
+ period.setType(FreeBusyPeriod::Free);
+ break;
+ }
+ }
+
+ param = icalproperty_get_first_parameter(p, ICAL_X_PARAMETER);
+ while (param) {
+ if (strncmp(icalparameter_get_xname(param), "X-SUMMARY", 9) == 0) {
+ period.setSummary(QString::fromUtf8(
+ KCodecs::base64Decode(icalparameter_get_xvalue(param))));
+ }
+ if (strncmp(icalparameter_get_xname(param), "X-LOCATION", 10) == 0) {
+ period.setLocation(QString::fromUtf8(
+ KCodecs::base64Decode(icalparameter_get_xvalue(param))));
+ }
+ param = icalproperty_get_next_parameter(p, ICAL_X_PARAMETER);
+ }
+
+ periods.append(period);
+ break;
}
- param = icalproperty_get_next_parameter( p, ICAL_X_PARAMETER );
- }
-
- periods.append( period );
- break;
- }
- default:
- // TODO: do something about unknown properties?
- break;
+ default:
+ // TODO: do something about unknown properties?
+ break;
+ }
+ p = icalcomponent_get_next_property(vfreebusy, ICAL_ANY_PROPERTY);
}
- p = icalcomponent_get_next_property( vfreebusy, ICAL_ANY_PROPERTY );
- }
- freebusy->addPeriods( periods );
+ freebusy->addPeriods(periods);
- return freebusy;
+ freebusy->resetDirtyFields();
+ return freebusy;
}
-Journal::Ptr ICalFormatImpl::readJournal( icalcomponent *vjournal,
- ICalTimeZones *tzlist )
+Journal::Ptr ICalFormatImpl::readJournal(icalcomponent *vjournal,
+ ICalTimeZones *tzlist)
{
- Journal::Ptr journal( new Journal );
- readIncidence( vjournal, journal, tzlist );
+ Journal::Ptr journal(new Journal);
+ readIncidence(vjournal, journal, tzlist);
- return journal;
+ journal->resetDirtyFields();
+ return journal;
}
-Attendee::Ptr ICalFormatImpl::readAttendee( icalproperty *attendee )
+Attendee::Ptr ICalFormatImpl::readAttendee(icalproperty *attendee)
{
- // the following is a hack to support broken calendars (like WebCalendar 1.0.x)
- // that include non-RFC-compliant attendees. Otherwise libical 0.42 asserts.
- if ( !icalproperty_get_value( attendee ) ) {
- return Attendee::Ptr();
- }
-
- icalparameter *p = 0;
+ // the following is a hack to support broken calendars (like WebCalendar 1.0.x)
+ // that include non-RFC-compliant attendees. Otherwise libical 0.42 asserts.
+ if (!icalproperty_get_value(attendee)) {
+ return Attendee::Ptr();
+ }
- QString email = QString::fromUtf8( icalproperty_get_attendee( attendee ) );
- if ( email.startsWith( QLatin1String( "mailto:" ), Qt::CaseInsensitive ) ) {
- email = email.mid( 7 );
- }
+ icalparameter *p = 0;
- // libical may return everything after ATTENDEE tag if the rest is
- // not meaningful. Verify the address to filter out these cases.
- if ( !Person::isValidEmail( email ) ) {
- return Attendee::Ptr();
- }
-
- QString name;
- QString uid;
- p = icalproperty_get_first_parameter( attendee, ICAL_CN_PARAMETER );
- if ( p ) {
- name = QString::fromUtf8( icalparameter_get_cn( p ) );
- } else {
- }
+ QString email = QString::fromUtf8(icalproperty_get_attendee(attendee));
+ if (email.startsWith(QLatin1String("mailto:"), Qt::CaseInsensitive)) {
+ email = email.mid(7);
+ }
- bool rsvp = false;
- p = icalproperty_get_first_parameter( attendee, ICAL_RSVP_PARAMETER );
- if ( p ) {
- icalparameter_rsvp rsvpParameter = icalparameter_get_rsvp( p );
- if ( rsvpParameter == ICAL_RSVP_TRUE ) {
- rsvp = true;
+ // libical may return everything after ATTENDEE tag if the rest is
+ // not meaningful. Verify the address to filter out these cases.
+ if (!Person::isValidEmail(email)) {
+ return Attendee::Ptr();
}
- }
- Attendee::PartStat status = Attendee::NeedsAction;
- p = icalproperty_get_first_parameter( attendee, ICAL_PARTSTAT_PARAMETER );
- if ( p ) {
- icalparameter_partstat partStatParameter = icalparameter_get_partstat( p );
- switch( partStatParameter ) {
- default:
- case ICAL_PARTSTAT_NEEDSACTION:
- status = Attendee::NeedsAction;
- break;
- case ICAL_PARTSTAT_ACCEPTED:
- status = Attendee::Accepted;
- break;
- case ICAL_PARTSTAT_DECLINED:
- status = Attendee::Declined;
- break;
- case ICAL_PARTSTAT_TENTATIVE:
- status = Attendee::Tentative;
- break;
- case ICAL_PARTSTAT_DELEGATED:
- status = Attendee::Delegated;
- break;
- case ICAL_PARTSTAT_COMPLETED:
- status = Attendee::Completed;
- break;
- case ICAL_PARTSTAT_INPROCESS:
- status = Attendee::InProcess;
- break;
+ QString name;
+ QString uid;
+ p = icalproperty_get_first_parameter(attendee, ICAL_CN_PARAMETER);
+ if (p) {
+ name = QString::fromUtf8(icalparameter_get_cn(p));
+ } else {
}
- }
- Attendee::Role role = Attendee::ReqParticipant;
- p = icalproperty_get_first_parameter( attendee, ICAL_ROLE_PARAMETER );
- if ( p ) {
- icalparameter_role roleParameter = icalparameter_get_role( p );
- switch( roleParameter ) {
- case ICAL_ROLE_CHAIR:
- role = Attendee::Chair;
- break;
- default:
- case ICAL_ROLE_REQPARTICIPANT:
- role = Attendee::ReqParticipant;
- break;
- case ICAL_ROLE_OPTPARTICIPANT:
- role = Attendee::OptParticipant;
- break;
- case ICAL_ROLE_NONPARTICIPANT:
- role = Attendee::NonParticipant;
- break;
+ bool rsvp = false;
+ p = icalproperty_get_first_parameter(attendee, ICAL_RSVP_PARAMETER);
+ if (p) {
+ icalparameter_rsvp rsvpParameter = icalparameter_get_rsvp(p);
+ if (rsvpParameter == ICAL_RSVP_TRUE) {
+ rsvp = true;
+ }
}
- }
- p = icalproperty_get_first_parameter( attendee, ICAL_X_PARAMETER );
- QMap<QByteArray, QString> custom;
- while ( p ) {
- QString xname = QString( icalparameter_get_xname( p ) ).toUpper();
- QString xvalue = QString::fromUtf8( icalparameter_get_xvalue( p ) );
- if ( xname == "X-UID" ) {
- uid = xvalue;
- } else {
- custom[xname.toUtf8()] = xvalue;
+ Attendee::PartStat status = Attendee::NeedsAction;
+ p = icalproperty_get_first_parameter(attendee, ICAL_PARTSTAT_PARAMETER);
+ if (p) {
+ icalparameter_partstat partStatParameter = icalparameter_get_partstat(p);
+ switch (partStatParameter) {
+ default:
+ case ICAL_PARTSTAT_NEEDSACTION:
+ status = Attendee::NeedsAction;
+ break;
+ case ICAL_PARTSTAT_ACCEPTED:
+ status = Attendee::Accepted;
+ break;
+ case ICAL_PARTSTAT_DECLINED:
+ status = Attendee::Declined;
+ break;
+ case ICAL_PARTSTAT_TENTATIVE:
+ status = Attendee::Tentative;
+ break;
+ case ICAL_PARTSTAT_DELEGATED:
+ status = Attendee::Delegated;
+ break;
+ case ICAL_PARTSTAT_COMPLETED:
+ status = Attendee::Completed;
+ break;
+ case ICAL_PARTSTAT_INPROCESS:
+ status = Attendee::InProcess;
+ break;
+ }
}
- p = icalproperty_get_next_parameter( attendee, ICAL_X_PARAMETER );
- }
- Attendee::Ptr a( new Attendee( name, email, rsvp, status, role, uid ) );
- a->customProperties().setCustomProperties( custom );
+ Attendee::Role role = Attendee::ReqParticipant;
+ p = icalproperty_get_first_parameter(attendee, ICAL_ROLE_PARAMETER);
+ if (p) {
+ icalparameter_role roleParameter = icalparameter_get_role(p);
+ switch (roleParameter) {
+ case ICAL_ROLE_CHAIR:
+ role = Attendee::Chair;
+ break;
+ default:
+ case ICAL_ROLE_REQPARTICIPANT:
+ role = Attendee::ReqParticipant;
+ break;
+ case ICAL_ROLE_OPTPARTICIPANT:
+ role = Attendee::OptParticipant;
+ break;
+ case ICAL_ROLE_NONPARTICIPANT:
+ role = Attendee::NonParticipant;
+ break;
+ }
+ }
- p = icalproperty_get_first_parameter( attendee, ICAL_DELEGATEDTO_PARAMETER );
- if ( p ) {
- a->setDelegate( icalparameter_get_delegatedto( p ) );
- }
+ Attendee::CuType cuType = Attendee::Individual;
+ p = icalproperty_get_first_parameter( attendee, ICAL_CUTYPE_PARAMETER );
+ if (p) {
+ icalparameter_cutype cutypeParameter = icalparameter_get_cutype(p);
+ switch (cutypeParameter) {
+ case ICAL_CUTYPE_X:
+ case ICAL_CUTYPE_UNKNOWN:
+ cuType = Attendee::Unknown;
+ break;
+ default:
+ case ICAL_CUTYPE_NONE:
+ case ICAL_CUTYPE_INDIVIDUAL:
+ cuType = Attendee::Individual;
+ break;
+ case ICAL_CUTYPE_GROUP:
+ cuType = Attendee::Group;
+ break;
+ case ICAL_CUTYPE_RESOURCE:
+ cuType = Attendee::Resource;
+ break;
+ case ICAL_CUTYPE_ROOM:
+ cuType = Attendee::Room;
+ break;
+ }
+ }
- p = icalproperty_get_first_parameter( attendee, ICAL_DELEGATEDFROM_PARAMETER );
- if ( p ) {
- a->setDelegator( icalparameter_get_delegatedfrom( p ) );
- }
+ p = icalproperty_get_first_parameter(attendee, ICAL_X_PARAMETER);
+ QMap<QByteArray, QString> custom;
+ while (p) {
+ QString xname = QString::fromLatin1(icalparameter_get_xname(p)).toUpper();
+ QString xvalue = QString::fromUtf8(icalparameter_get_xvalue(p));
+ if (xname == QLatin1String("X-UID")) {
+ uid = xvalue;
+ } else {
+ custom[xname.toUtf8()] = xvalue;
+ }
+ p = icalproperty_get_next_parameter(attendee, ICAL_X_PARAMETER);
+ }
- return a;
-}
+ Attendee::Ptr a(new Attendee(name, email, rsvp, status, role, uid));
+ a->setCuType(cuType);
+ a->customProperties().setCustomProperties(custom);
-Person::Ptr ICalFormatImpl::readOrganizer( icalproperty *organizer )
-{
- QString email = QString::fromUtf8( icalproperty_get_organizer( organizer ) );
- if ( email.startsWith( QLatin1String( "mailto:" ), Qt::CaseInsensitive ) ) {
- email = email.mid( 7 );
- }
- QString cn;
+ p = icalproperty_get_first_parameter(attendee, ICAL_DELEGATEDTO_PARAMETER);
+ if (p) {
+ a->setDelegate(QLatin1String(icalparameter_get_delegatedto(p)));
+ }
- icalparameter *p = icalproperty_get_first_parameter( organizer, ICAL_CN_PARAMETER );
+ p = icalproperty_get_first_parameter(attendee, ICAL_DELEGATEDFROM_PARAMETER);
+ if (p) {
+ a->setDelegator(QLatin1String(icalparameter_get_delegatedfrom(p)));
+ }
- if ( p ) {
- cn = QString::fromUtf8( icalparameter_get_cn( p ) );
- }
- Person::Ptr org( new Person( cn, email ) );
- // TODO: Treat sent-by, dir and language here, too
- return org;
+ return a;
}
-Attachment::Ptr ICalFormatImpl::readAttachment( icalproperty *attach )
+Person::Ptr ICalFormatImpl::readOrganizer(icalproperty *organizer)
{
- Attachment::Ptr attachment;
-
- QByteArray p;
- icalvalue *value = icalproperty_get_value( attach );
-
- switch( icalvalue_isa( value ) ) {
- case ICAL_ATTACH_VALUE:
- {
- icalattach *a = icalproperty_get_attach( attach );
- if ( !icalattach_get_is_url( a ) ) {
- p = QByteArray( reinterpret_cast<const char *>( icalattach_get_data( a ) ) );
- if ( !p.isEmpty() ) {
- attachment = Attachment::Ptr( new Attachment( p ) );
- }
- } else {
- p = icalattach_get_url( a );
- if ( !p.isEmpty() ) {
- attachment = Attachment::Ptr( new Attachment( QString::fromUtf8( p ) ) );
- }
+ QString email = QString::fromUtf8(icalproperty_get_organizer(organizer));
+ if (email.startsWith(QLatin1String("mailto:"), Qt::CaseInsensitive)) {
+ email = email.mid(7);
}
- break;
- }
- case ICAL_BINARY_VALUE:
- {
- icalattach *a = icalproperty_get_attach( attach );
- p = QByteArray( reinterpret_cast<const char *>( icalattach_get_data( a ) ) );
- if ( !p.isEmpty() ) {
- attachment = Attachment::Ptr( new Attachment( p ) );
- }
- break;
- }
- case ICAL_URI_VALUE:
- p = icalvalue_get_uri( value );
- attachment = Attachment::Ptr( new Attachment( QString::fromUtf8( p ) ) );
- break;
- default:
- break;
- }
+ QString cn;
- if ( attachment ) {
- icalparameter *p =
- icalproperty_get_first_parameter( attach, ICAL_FMTTYPE_PARAMETER );
- if ( p ) {
- attachment->setMimeType( QString( icalparameter_get_fmttype( p ) ) );
- }
-
- p = icalproperty_get_first_parameter( attach, ICAL_X_PARAMETER );
- while ( p ) {
- QString xname = QString( icalparameter_get_xname( p ) ).toUpper();
- QString xvalue = QString::fromUtf8( icalparameter_get_xvalue( p ) );
- if ( xname == "X-CONTENT-DISPOSITION" ) {
- attachment->setShowInline( xvalue.toLower() == "inline" );
- }
- if ( xname == "X-LABEL" ) {
- attachment->setLabel( xvalue );
- }
- if ( xname == "X-KONTACT-TYPE" ) {
- attachment->setLocal( xvalue.toLower() == "local" );
- }
- p = icalproperty_get_next_parameter( attach, ICAL_X_PARAMETER );
- }
+ icalparameter *p = icalproperty_get_first_parameter(organizer, ICAL_CN_PARAMETER);
- p = icalproperty_get_first_parameter( attach, ICAL_X_PARAMETER );
- while ( p ) {
- if ( strncmp( icalparameter_get_xname( p ), "X-LABEL", 7 ) == 0 ) {
- attachment->setLabel( QString::fromUtf8( icalparameter_get_xvalue( p ) ) );
- }
- p = icalproperty_get_next_parameter( attach, ICAL_X_PARAMETER );
+ if (p) {
+ cn = QString::fromUtf8(icalparameter_get_cn(p));
}
- }
-
- return attachment;
+ Person::Ptr org(new Person(cn, email));
+ // TODO: Treat sent-by, dir and language here, too
+ return org;
}
-void ICalFormatImpl::readIncidence( icalcomponent *parent,
- Incidence::Ptr incidence,
- ICalTimeZones *tzlist )
+Attachment::Ptr ICalFormatImpl::readAttachment(icalproperty *attach)
{
- d->readIncidenceBase( parent, incidence );
-
- icalproperty *p = icalcomponent_get_first_property( parent, ICAL_ANY_PROPERTY );
-
- const char *text;
- int intvalue, inttext;
- icaldurationtype icalduration;
- KDateTime kdt;
- KDateTime dtstamp;
-
- QStringList categories;
-
- while ( p ) {
- icalproperty_kind kind = icalproperty_isa( p );
- switch ( kind ) {
- case ICAL_CREATED_PROPERTY:
- incidence->setCreated( readICalDateTimeProperty( p, tzlist ) );
- break;
-
- case ICAL_DTSTAMP_PROPERTY:
- dtstamp = readICalDateTimeProperty( p, tzlist );
- break;
+ Attachment::Ptr attachment;
- case ICAL_SEQUENCE_PROPERTY: // sequence
- intvalue = icalproperty_get_sequence( p );
- incidence->setRevision( intvalue );
- break;
+ QByteArray p;
+ icalvalue *value = icalproperty_get_value(attach);
- case ICAL_LASTMODIFIED_PROPERTY: // last modification UTC date/time
- incidence->setLastModified( readICalDateTimeProperty( p, tzlist ) );
- break;
-
- case ICAL_DTSTART_PROPERTY: // start date and time
- kdt = readICalDateTimeProperty( p, tzlist );
- incidence->setDtStart( kdt );
- incidence->setAllDay( kdt.isDateOnly() );
- break;
-
- case ICAL_DURATION_PROPERTY: // start date and time
- icalduration = icalproperty_get_duration( p );
- incidence->setDuration( readICalDuration( icalduration ) );
- break;
-
- case ICAL_DESCRIPTION_PROPERTY: // description
+ switch (icalvalue_isa(value)) {
+ case ICAL_ATTACH_VALUE:
{
- QString textStr = QString::fromUtf8( icalproperty_get_description( p ) );
- if ( !textStr.isEmpty() ) {
- QString valStr = QString::fromUtf8(
- icalproperty_get_parameter_as_string( p, "X-KDE-TEXTFORMAT" ) );
- if ( !valStr.compare( "HTML", Qt::CaseInsensitive ) ) {
- incidence->setDescription( textStr, true );
+ icalattach *a = icalproperty_get_attach(attach);
+ if (!icalattach_get_is_url(a)) {
+ p = QByteArray(reinterpret_cast<const char *>(icalattach_get_data(a)));
+ if (!p.isEmpty()) {
+ attachment = Attachment::Ptr(new Attachment(p));
+ }
} else {
- incidence->setDescription( textStr, false );
+ p = icalattach_get_url(a);
+ if (!p.isEmpty()) {
+ attachment = Attachment::Ptr(new Attachment(QString::fromUtf8(p)));
+ }
}
- }
+ break;
}
- break;
-
- case ICAL_SUMMARY_PROPERTY: // summary
+ case ICAL_BINARY_VALUE:
{
- QString textStr = QString::fromUtf8( icalproperty_get_summary( p ) );
- if ( !textStr.isEmpty() ) {
- QString valStr = QString::fromUtf8(
- icalproperty_get_parameter_as_string( p, "X-KDE-TEXTFORMAT" ) );
- if ( !valStr.compare( "HTML", Qt::CaseInsensitive ) ) {
- incidence->setSummary( textStr, true );
- } else {
- incidence->setSummary( textStr, false );
+ icalattach *a = icalproperty_get_attach(attach);
+ p = QByteArray(reinterpret_cast<const char *>(icalattach_get_data(a)));
+ if (!p.isEmpty()) {
+ attachment = Attachment::Ptr(new Attachment(p));
}
- }
- }
- break;
-
- case ICAL_LOCATION_PROPERTY: // location
- {
- if ( !icalproperty_get_value( p ) ) {
- //Fix for #191472. This is a pre-crash guard in case libical was
- //compiled in superstrict mode (--enable-icalerrors-are-fatal)
- //TODO: pre-crash guard other property getters too.
break;
- }
- QString textStr = QString::fromUtf8( icalproperty_get_location( p ) );
- if ( !textStr.isEmpty() ) {
- QString valStr = QString::fromUtf8(
- icalproperty_get_parameter_as_string( p, "X-KDE-TEXTFORMAT" ) );
- if ( !valStr.compare( "HTML", Qt::CaseInsensitive ) ) {
- incidence->setLocation( textStr, true );
- } else {
- incidence->setLocation( textStr, false );
- }
- }
}
- break;
-
- case ICAL_STATUS_PROPERTY: // status
- {
- Incidence::Status stat;
- switch ( icalproperty_get_status( p ) ) {
- case ICAL_STATUS_TENTATIVE:
- stat = Incidence::StatusTentative;
- break;
- case ICAL_STATUS_CONFIRMED:
- stat = Incidence::StatusConfirmed;
- break;
- case ICAL_STATUS_COMPLETED:
- stat = Incidence::StatusCompleted;
- break;
- case ICAL_STATUS_NEEDSACTION:
- stat = Incidence::StatusNeedsAction;
+ case ICAL_URI_VALUE:
+ p = icalvalue_get_uri(value);
+ attachment = Attachment::Ptr(new Attachment(QString::fromUtf8(p)));
break;
- case ICAL_STATUS_CANCELLED:
- stat = Incidence::StatusCanceled;
- break;
- case ICAL_STATUS_INPROCESS:
- stat = Incidence::StatusInProcess;
- break;
- case ICAL_STATUS_DRAFT:
- stat = Incidence::StatusDraft;
- break;
- case ICAL_STATUS_FINAL:
- stat = Incidence::StatusFinal;
- break;
- case ICAL_STATUS_X:
- incidence->setCustomStatus(
- QString::fromUtf8( icalvalue_get_x( icalproperty_get_value( p ) ) ) );
- stat = Incidence::StatusX;
- break;
- case ICAL_STATUS_NONE:
- default:
- stat = Incidence::StatusNone;
+ default:
break;
- }
- if ( stat != Incidence::StatusX ) {
- incidence->setStatus( stat );
- }
- break;
}
- case ICAL_GEO_PROPERTY: // geo
- {
- icalgeotype geo = icalproperty_get_geo( p );
- incidence->setGeoLatitude( geo.lat );
- incidence->setGeoLongitude( geo.lon );
- incidence->setHasGeo( true );
- break;
- }
+ if (attachment) {
+ icalparameter *p =
+ icalproperty_get_first_parameter(attach, ICAL_FMTTYPE_PARAMETER);
+ if (p) {
+ attachment->setMimeType(QLatin1String(icalparameter_get_fmttype(p)));
+ }
- case ICAL_PRIORITY_PROPERTY: // priority
- intvalue = icalproperty_get_priority( p );
- if ( d->mCompat ) {
- intvalue = d->mCompat->fixPriority( intvalue );
- }
- incidence->setPriority( intvalue );
- break;
+ p = icalproperty_get_first_parameter(attach, ICAL_X_PARAMETER);
+ while (p) {
+ QString xname = QString::fromLatin1(icalparameter_get_xname(p)).toUpper();
+ QString xvalue = QString::fromUtf8(icalparameter_get_xvalue(p));
+ if (xname == QLatin1String("X-CONTENT-DISPOSITION")) {
+ attachment->setShowInline(xvalue.toLower() == QLatin1String("inline"));
+ }
+ if (xname == QLatin1String("X-LABEL")) {
+ attachment->setLabel(xvalue);
+ }
+ if (xname == QLatin1String("X-KONTACT-TYPE")) {
+ attachment->setLocal(xvalue.toLower() == QLatin1String("local"));
+ }
+ p = icalproperty_get_next_parameter(attach, ICAL_X_PARAMETER);
+ }
- case ICAL_CATEGORIES_PROPERTY: // categories
- {
- // We have always supported multiple CATEGORIES properties per component
- // even though the RFC seems to indicate only 1 is permitted.
- // We can't change that -- in order to retain backwards compatibility.
- text = icalproperty_get_categories( p );
- const QString val = QString::fromUtf8( text );
- foreach ( const QString &cat, val.split( ',', QString::SkipEmptyParts ) ) {
- // ensure no duplicates
- if ( !categories.contains( cat ) ) {
- categories.append( cat );
+ p = icalproperty_get_first_parameter(attach, ICAL_X_PARAMETER);
+ while (p) {
+ if (strncmp(icalparameter_get_xname(p), "X-LABEL", 7) == 0) {
+ attachment->setLabel(QString::fromUtf8(icalparameter_get_xvalue(p)));
+ }
+ p = icalproperty_get_next_parameter(attach, ICAL_X_PARAMETER);
}
- }
- break;
}
- case ICAL_RECURRENCEID_PROPERTY: // recurrenceId
- kdt = readICalDateTimeProperty( p, tzlist );
- if ( kdt.isValid() ) {
- incidence->setRecurrenceId( kdt );
- }
- break;
+ return attachment;
+}
- case ICAL_RRULE_PROPERTY:
- readRecurrenceRule( p, incidence );
- break;
+void ICalFormatImpl::readIncidence(icalcomponent *parent,
+ Incidence::Ptr incidence,
+ ICalTimeZones *tzlist)
+{
+ d->readIncidenceBase(parent, incidence);
+
+ icalproperty *p = icalcomponent_get_first_property(parent, ICAL_ANY_PROPERTY);
+
+ const char *text;
+ int intvalue, inttext;
+ icaldurationtype icalduration;
+ KDateTime kdt;
+ KDateTime dtstamp;
+
+ QStringList categories;
+
+ while (p) {
+ icalproperty_kind kind = icalproperty_isa(p);
+ switch (kind) {
+ case ICAL_CREATED_PROPERTY:
+ incidence->setCreated(readICalDateTimeProperty(p, tzlist));
+ break;
+
+ case ICAL_DTSTAMP_PROPERTY:
+ dtstamp = readICalDateTimeProperty(p, tzlist);
+ break;
+
+ case ICAL_SEQUENCE_PROPERTY: // sequence
+ intvalue = icalproperty_get_sequence(p);
+ incidence->setRevision(intvalue);
+ break;
+
+ case ICAL_LASTMODIFIED_PROPERTY: // last modification UTC date/time
+ incidence->setLastModified(readICalDateTimeProperty(p, tzlist));
+ break;
+
+ case ICAL_DTSTART_PROPERTY: // start date and time
+ kdt = readICalDateTimeProperty(p, tzlist);
+ incidence->setDtStart(kdt);
+ incidence->setAllDay(kdt.isDateOnly());
+ break;
+
+ case ICAL_DURATION_PROPERTY: // start date and time
+ icalduration = icalproperty_get_duration(p);
+ incidence->setDuration(readICalDuration(icalduration));
+ break;
+
+ case ICAL_DESCRIPTION_PROPERTY: // description
+ {
+ QString textStr = QString::fromUtf8(icalproperty_get_description(p));
+ if (!textStr.isEmpty()) {
+ QString valStr = QString::fromUtf8(
+ icalproperty_get_parameter_as_string(p, "X-KDE-TEXTFORMAT"));
+ if (!valStr.compare(QLatin1String("HTML"), Qt::CaseInsensitive)) {
+ incidence->setDescription(textStr, true);
+ } else {
+ incidence->setDescription(textStr, false);
+ }
+ }
+ }
+ break;
- case ICAL_RDATE_PROPERTY:
- kdt = readICalDateTimeProperty( p, tzlist );
- if ( kdt.isValid() ) {
- if ( kdt.isDateOnly() ) {
- incidence->recurrence()->addRDate( kdt.date() );
- } else {
- incidence->recurrence()->addRDateTime( kdt );
+ case ICAL_SUMMARY_PROPERTY: // summary
+ {
+ QString textStr = QString::fromUtf8(icalproperty_get_summary(p));
+ if (!textStr.isEmpty()) {
+ QString valStr = QString::fromUtf8(
+ icalproperty_get_parameter_as_string(p, "X-KDE-TEXTFORMAT"));
+ if (!valStr.compare(QLatin1String("HTML"), Qt::CaseInsensitive)) {
+ incidence->setSummary(textStr, true);
+ } else {
+ incidence->setSummary(textStr, false);
+ }
+ }
}
- } else {
- // TODO: RDates as period are not yet implemented!
- }
- break;
+ break;
- case ICAL_EXRULE_PROPERTY:
- readExceptionRule( p, incidence );
- break;
+ case ICAL_LOCATION_PROPERTY: // location
+ {
+ if (!icalproperty_get_value(p)) {
+ //Fix for #191472. This is a pre-crash guard in case libical was
+ //compiled in superstrict mode (--enable-icalerrors-are-fatal)
+ //TODO: pre-crash guard other property getters too.
+ break;
+ }
+ QString textStr = QString::fromUtf8(icalproperty_get_location(p));
+ if (!textStr.isEmpty()) {
+ QString valStr = QString::fromUtf8(
+ icalproperty_get_parameter_as_string(p, "X-KDE-TEXTFORMAT"));
+ if (!valStr.compare(QLatin1String("HTML"), Qt::CaseInsensitive)) {
+ incidence->setLocation(textStr, true);
+ } else {
+ incidence->setLocation(textStr, false);
+ }
+ }
+ }
+ break;
- case ICAL_EXDATE_PROPERTY:
- kdt = readICalDateTimeProperty( p, tzlist );
- if ( kdt.isDateOnly() ) {
- incidence->recurrence()->addExDate( kdt.date() );
- } else {
- incidence->recurrence()->addExDateTime( kdt );
- }
- break;
-
- case ICAL_CLASS_PROPERTY:
- inttext = icalproperty_get_class( p );
- if ( inttext == ICAL_CLASS_PUBLIC ) {
- incidence->setSecrecy( Incidence::SecrecyPublic );
- } else if ( inttext == ICAL_CLASS_CONFIDENTIAL ) {
- incidence->setSecrecy( Incidence::SecrecyConfidential );
- } else {
- incidence->setSecrecy( Incidence::SecrecyPrivate );
- }
- break;
+ case ICAL_STATUS_PROPERTY: // status
+ {
+ Incidence::Status stat;
+ switch (icalproperty_get_status(p)) {
+ case ICAL_STATUS_TENTATIVE:
+ stat = Incidence::StatusTentative;
+ break;
+ case ICAL_STATUS_CONFIRMED:
+ stat = Incidence::StatusConfirmed;
+ break;
+ case ICAL_STATUS_COMPLETED:
+ stat = Incidence::StatusCompleted;
+ break;
+ case ICAL_STATUS_NEEDSACTION:
+ stat = Incidence::StatusNeedsAction;
+ break;
+ case ICAL_STATUS_CANCELLED:
+ stat = Incidence::StatusCanceled;
+ break;
+ case ICAL_STATUS_INPROCESS:
+ stat = Incidence::StatusInProcess;
+ break;
+ case ICAL_STATUS_DRAFT:
+ stat = Incidence::StatusDraft;
+ break;
+ case ICAL_STATUS_FINAL:
+ stat = Incidence::StatusFinal;
+ break;
+ case ICAL_STATUS_X:
+ incidence->setCustomStatus(
+ QString::fromUtf8(icalvalue_get_x(icalproperty_get_value(p))));
+ stat = Incidence::StatusX;
+ break;
+ case ICAL_STATUS_NONE:
+ default:
+ stat = Incidence::StatusNone;
+ break;
+ }
+ if (stat != Incidence::StatusX) {
+ incidence->setStatus(stat);
+ }
+ break;
+ }
- case ICAL_ATTACH_PROPERTY: // attachments
- incidence->addAttachment( readAttachment( p ) );
- break;
+ case ICAL_GEO_PROPERTY: // geo
+ {
+ icalgeotype geo = icalproperty_get_geo(p);
+ incidence->setGeoLatitude(geo.lat);
+ incidence->setGeoLongitude(geo.lon);
+ incidence->setHasGeo(true);
+ break;
+ }
- default:
- // TODO: do something about unknown properties?
- break;
- }
+ case ICAL_PRIORITY_PROPERTY: // priority
+ intvalue = icalproperty_get_priority(p);
+ if (d->mCompat) {
+ intvalue = d->mCompat->fixPriority(intvalue);
+ }
+ incidence->setPriority(intvalue);
+ break;
+
+ case ICAL_CATEGORIES_PROPERTY: // categories
+ {
+ // We have always supported multiple CATEGORIES properties per component
+ // even though the RFC seems to indicate only 1 is permitted.
+ // We can't change that -- in order to retain backwards compatibility.
+ text = icalproperty_get_categories(p);
+ const QString val = QString::fromUtf8(text);
+ foreach(const QString &cat, val.split(QLatin1Char(','), QString::SkipEmptyParts)) {
+ // ensure no duplicates
+ if (!categories.contains(cat)) {
+ categories.append(cat);
+ }
+ }
+ break;
+ }
- p = icalcomponent_get_next_property( parent, ICAL_ANY_PROPERTY );
- }
+ case ICAL_RECURRENCEID_PROPERTY: // recurrenceId
+ kdt = readICalDateTimeProperty(p, tzlist);
+ if (kdt.isValid()) {
+ incidence->setRecurrenceId(kdt);
+ const icalparameter *param =
+ icalproperty_get_first_parameter(p, ICAL_RANGE_PARAMETER);
+ if (param && icalparameter_get_range(param) == ICAL_RANGE_THISANDFUTURE) {
+ incidence->setThisAndFuture(true);
+ }
+ }
+ break;
+
+ case ICAL_RRULE_PROPERTY:
+ readRecurrenceRule(p, incidence);
+ break;
+
+ case ICAL_RDATE_PROPERTY:
+ kdt = readICalDateTimeProperty(p, tzlist);
+ if (kdt.isValid()) {
+ if (kdt.isDateOnly()) {
+ incidence->recurrence()->addRDate(kdt.date());
+ } else {
+ incidence->recurrence()->addRDateTime(kdt);
+ }
+ } else {
+ // TODO: RDates as period are not yet implemented!
+ }
+ break;
+
+ case ICAL_EXRULE_PROPERTY:
+ readExceptionRule(p, incidence);
+ break;
+
+ case ICAL_EXDATE_PROPERTY:
+ kdt = readICalDateTimeProperty(p, tzlist);
+ if (kdt.isDateOnly()) {
+ incidence->recurrence()->addExDate(kdt.date());
+ } else {
+ incidence->recurrence()->addExDateTime(kdt);
+ }
+ break;
+
+ case ICAL_CLASS_PROPERTY:
+ inttext = icalproperty_get_class(p);
+ if (inttext == ICAL_CLASS_PUBLIC) {
+ incidence->setSecrecy(Incidence::SecrecyPublic);
+ } else if (inttext == ICAL_CLASS_CONFIDENTIAL) {
+ incidence->setSecrecy(Incidence::SecrecyConfidential);
+ } else {
+ incidence->setSecrecy(Incidence::SecrecyPrivate);
+ }
+ break;
+
+ case ICAL_ATTACH_PROPERTY: // attachments
+ incidence->addAttachment(readAttachment(p));
+ break;
- // Set the scheduling ID
- const QString uid = incidence->customProperty( "LIBKCAL", "ID" );
- if ( !uid.isNull() ) {
- // The UID stored in incidencebase is actually the scheduling ID
- // It has to be stored in the iCal UID component for compatibility
- // with other iCal applications
- incidence->setSchedulingID( incidence->uid(), uid );
- }
+ default:
+ // TODO: do something about unknown properties?
+ break;
+ }
- // Now that recurrence and exception stuff is completely set up,
- // do any backwards compatibility adjustments.
- if ( incidence->recurs() && d->mCompat ) {
- d->mCompat->fixRecurrence( incidence );
- }
+ p = icalcomponent_get_next_property(parent, ICAL_ANY_PROPERTY);
+ }
- // add categories
- incidence->setCategories( categories );
+ // Set the scheduling ID
+ const QString uid = incidence->customProperty("LIBKCAL", "ID");
+ if (!uid.isNull()) {
+ // The UID stored in incidencebase is actually the scheduling ID
+ // It has to be stored in the iCal UID component for compatibility
+ // with other iCal applications
+ incidence->setSchedulingID(incidence->uid(), uid);
+ }
- // iterate through all alarms
- for ( icalcomponent *alarm = icalcomponent_get_first_component( parent, ICAL_VALARM_COMPONENT );
- alarm;
- alarm = icalcomponent_get_next_component( parent, ICAL_VALARM_COMPONENT ) ) {
- readAlarm( alarm, incidence, tzlist );
- }
+ // Now that recurrence and exception stuff is completely set up,
+ // do any backwards compatibility adjustments.
+ if (incidence->recurs() && d->mCompat) {
+ d->mCompat->fixRecurrence(incidence);
+ }
- if ( d->mCompat ) {
- // Fix incorrect alarm settings by other applications (like outloook 9)
- d->mCompat->fixAlarms( incidence );
- d->mCompat->setCreatedToDtStamp( incidence, dtstamp );
- }
+ // add categories
+ incidence->setCategories(categories);
+
+ // iterate through all alarms
+ for (icalcomponent *alarm = icalcomponent_get_first_component(parent, ICAL_VALARM_COMPONENT);
+ alarm;
+ alarm = icalcomponent_get_next_component(parent, ICAL_VALARM_COMPONENT)) {
+ readAlarm(alarm, incidence, tzlist);
+ }
+
+ if (d->mCompat) {
+ // Fix incorrect alarm settings by other applications (like outloook 9)
+ d->mCompat->fixAlarms(incidence);
+ d->mCompat->setCreatedToDtStamp(incidence, dtstamp);
+ }
}
//@cond PRIVATE
-void ICalFormatImpl::Private::readIncidenceBase( icalcomponent *parent,
- IncidenceBase::Ptr incidenceBase )
+void ICalFormatImpl::Private::readIncidenceBase(icalcomponent *parent,
+ IncidenceBase::Ptr incidenceBase)
{
- icalproperty *p = icalcomponent_get_first_property( parent, ICAL_ANY_PROPERTY );
- bool uidProcessed = false;
- while ( p ) {
- icalproperty_kind kind = icalproperty_isa( p );
- switch ( kind ) {
- case ICAL_UID_PROPERTY: // unique id
- uidProcessed = true;
- incidenceBase->setUid( QString::fromUtf8( icalproperty_get_uid( p ) ) );
- break;
-
- case ICAL_ORGANIZER_PROPERTY: // organizer
- incidenceBase->setOrganizer( mImpl->readOrganizer( p ) );
- break;
-
- case ICAL_ATTENDEE_PROPERTY: // attendee
- incidenceBase->addAttendee( mImpl->readAttendee( p ) );
- break;
-
- case ICAL_COMMENT_PROPERTY:
- incidenceBase->addComment(
- QString::fromUtf8( icalproperty_get_comment( p ) ) );
- break;
-
- case ICAL_CONTACT_PROPERTY:
- incidenceBase->addContact(
- QString::fromUtf8( icalproperty_get_contact( p ) ) );
- break;
+ icalproperty *p = icalcomponent_get_first_property(parent, ICAL_ANY_PROPERTY);
+ bool uidProcessed = false;
+ while (p) {
+ icalproperty_kind kind = icalproperty_isa(p);
+ switch (kind) {
+ case ICAL_UID_PROPERTY: // unique id
+ uidProcessed = true;
+ incidenceBase->setUid(QString::fromUtf8(icalproperty_get_uid(p)));
+ break;
+
+ case ICAL_ORGANIZER_PROPERTY: // organizer
+ incidenceBase->setOrganizer(mImpl->readOrganizer(p));
+ break;
+
+ case ICAL_ATTENDEE_PROPERTY: // attendee
+ incidenceBase->addAttendee(mImpl->readAttendee(p));
+ break;
+
+ case ICAL_COMMENT_PROPERTY:
+ incidenceBase->addComment(
+ QString::fromUtf8(icalproperty_get_comment(p)));
+ break;
+
+ case ICAL_CONTACT_PROPERTY:
+ incidenceBase->addContact(
+ QString::fromUtf8(icalproperty_get_contact(p)));
+ break;
+
+ case ICAL_URL_PROPERTY:
+ incidenceBase->setUrl(
+ QUrl(QString::fromUtf8(icalproperty_get_url(p))));
+ break;
- default:
- break;
- }
+ default:
+ break;
+ }
- p = icalcomponent_get_next_property( parent, ICAL_ANY_PROPERTY );
- }
+ p = icalcomponent_get_next_property(parent, ICAL_ANY_PROPERTY);
+ }
- if ( !uidProcessed ) {
- qWarning() << "The incidence didn't have any UID! Report a bug "
- << "to the application that generated this file."
- << endl;
+ if (!uidProcessed) {
+ kWarning() << "The incidence didn't have any UID! Report a bug "
+ << "to the application that generated this file."
+ << endl;
- // Our in-memory incidence has a random uid generated in Event's ctor.
- // Make it empty so it matches what's in the file:
- incidenceBase->setUid( QString() );
+ // Our in-memory incidence has a random uid generated in Event's ctor.
+ // Make it empty so it matches what's in the file:
+ incidenceBase->setUid(QString());
- // Otherwise, next time we read the file, this function will return
- // an event with another random uid and we will have two events in the calendar.
- }
+ // Otherwise, next time we read the file, this function will return
+ // an event with another random uid and we will have two events in the calendar.
+ }
- // custom properties
- readCustomProperties( parent, incidenceBase.data() );
+ // custom properties
+ readCustomProperties(parent, incidenceBase.data());
}
-void ICalFormatImpl::Private::readCustomProperties( icalcomponent *parent,
- CustomProperties *properties )
+void ICalFormatImpl::Private::readCustomProperties(icalcomponent *parent,
+ CustomProperties *properties)
{
- QByteArray property;
- QString value, parameters;
- icalproperty *p = icalcomponent_get_first_property( parent, ICAL_X_PROPERTY );
- icalparameter *param;
-
- while ( p ) {
- QString nvalue = QString::fromUtf8( icalproperty_get_x( p ) );
- if ( nvalue.isEmpty() ) {
- icalvalue *value = icalproperty_get_value( p );
- if ( icalvalue_isa( value ) == ICAL_TEXT_VALUE ) {
- // Calling icalvalue_get_text( value ) on a datetime value crashes.
- nvalue = QString::fromUtf8( icalvalue_get_text( value ) );
- } else {
- p = icalcomponent_get_next_property( parent, ICAL_X_PROPERTY );
- continue;
- }
+ QByteArray property;
+ QString value, parameters;
+ icalproperty *p = icalcomponent_get_first_property(parent, ICAL_X_PROPERTY);
+ icalparameter *param;
+
+ while (p) {
+ QString nvalue = QString::fromUtf8(icalproperty_get_x(p));
+ if (nvalue.isEmpty()) {
+ icalvalue *value = icalproperty_get_value(p);
+ if (icalvalue_isa(value) == ICAL_TEXT_VALUE) {
+ // Calling icalvalue_get_text( value ) on a datetime value crashes.
+ nvalue = QString::fromUtf8(icalvalue_get_text(value));
+ } else {
+ p = icalcomponent_get_next_property(parent, ICAL_X_PROPERTY);
+ continue;
+ }
+ }
+ const char *name = icalproperty_get_x_name(p);
+ QByteArray nproperty(name);
+ if (property != nproperty) {
+ // New property
+ if (!property.isEmpty()) {
+ properties->setNonKDECustomProperty(property, value, parameters);
+ }
+ property = name;
+ value = nvalue;
+ QStringList parametervalues;
+ for (param = icalproperty_get_first_parameter(p, ICAL_ANY_PARAMETER);
+ param;
+ param = icalproperty_get_next_parameter(p, ICAL_ANY_PARAMETER)) {
+ // 'c' is owned by ical library => all we need to do is just use it
+ const char *c = icalparameter_as_ical_string(param);
+ parametervalues.push_back(QLatin1String(c));
+ }
+ parameters = parametervalues.join(QLatin1String(";"));
+ } else {
+ value = value.append(QLatin1String(",")).append(nvalue);
+ }
+ p = icalcomponent_get_next_property(parent, ICAL_X_PROPERTY);
}
- const char *name = icalproperty_get_x_name( p );
- QByteArray nproperty(name);
- if ( property != nproperty ) {
- // New property
- if ( !property.isEmpty() ) {
- properties->setNonKDECustomProperty( property, value, parameters );
- }
- property = name;
- value = nvalue;
- QStringList parametervalues;
- for ( param = icalproperty_get_first_parameter( p, ICAL_ANY_PARAMETER );
- param;
- param = icalproperty_get_next_parameter( p, ICAL_ANY_PARAMETER ) ) {
- // 'c' is owned by ical library => all we need to do is just use it
- const char *c = icalparameter_as_ical_string( param );
- parametervalues.push_back( c );
- }
- parameters = parametervalues.join( ";" );
- } else {
- value = value.append( "," ).append( nvalue );
+ if (!property.isEmpty()) {
+ properties->setNonKDECustomProperty(property, value, parameters);
}
- p = icalcomponent_get_next_property( parent, ICAL_X_PROPERTY );
- }
- if ( !property.isEmpty() ) {
- properties->setNonKDECustomProperty( property, value, parameters );
- }
}
//@endcond
-void ICalFormatImpl::readRecurrenceRule( icalproperty *rrule, Incidence::Ptr incidence )
+void ICalFormatImpl::readRecurrenceRule(icalproperty *rrule, Incidence::Ptr incidence)
{
- Recurrence *recur = incidence->recurrence();
+ Recurrence *recur = incidence->recurrence();
- struct icalrecurrencetype r = icalproperty_get_rrule( rrule );
- // dumpIcalRecurrence(r);
+ struct icalrecurrencetype r = icalproperty_get_rrule(rrule);
+ // dumpIcalRecurrence(r);
- RecurrenceRule *recurrule = new RecurrenceRule( /*incidence*/);
- recurrule->setStartDt( incidence->dtStart() );
- readRecurrence( r, recurrule );
- recur->addRRule( recurrule );
+ RecurrenceRule *recurrule = new RecurrenceRule(/*incidence*/);
+ recurrule->setStartDt(incidence->dtStart());
+ readRecurrence(r, recurrule);
+ recur->addRRule(recurrule);
}
-void ICalFormatImpl::readExceptionRule( icalproperty *rrule, Incidence::Ptr incidence )
+void ICalFormatImpl::readExceptionRule(icalproperty *rrule, Incidence::Ptr incidence)
{
- struct icalrecurrencetype r = icalproperty_get_exrule( rrule );
- // dumpIcalRecurrence(r);
+ struct icalrecurrencetype r = icalproperty_get_exrule(rrule);
+ // dumpIcalRecurrence(r);
- RecurrenceRule *recurrule = new RecurrenceRule( /*incidence*/);
- recurrule->setStartDt( incidence->dtStart() );
- readRecurrence( r, recurrule );
+ RecurrenceRule *recurrule = new RecurrenceRule(/*incidence*/);
+ recurrule->setStartDt(incidence->dtStart());
+ readRecurrence(r, recurrule);
- Recurrence *recur = incidence->recurrence();
- recur->addExRule( recurrule );
+ Recurrence *recur = incidence->recurrence();
+ recur->addExRule(recurrule);
}
-void ICalFormatImpl::readRecurrence( const struct icalrecurrencetype &r, RecurrenceRule *recur )
+void ICalFormatImpl::readRecurrence(const struct icalrecurrencetype &r, RecurrenceRule *recur)
{
- // Generate the RRULE string
- recur->setRRule(
- QString( icalrecurrencetype_as_string( const_cast<struct icalrecurrencetype*>( &r ) ) ) );
- // Period
- switch ( r.freq ) {
- case ICAL_SECONDLY_RECURRENCE:
- recur->setRecurrenceType( RecurrenceRule::rSecondly );
- break;
- case ICAL_MINUTELY_RECURRENCE:
- recur->setRecurrenceType( RecurrenceRule::rMinutely );
- break;
- case ICAL_HOURLY_RECURRENCE:
- recur->setRecurrenceType( RecurrenceRule::rHourly );
- break;
- case ICAL_DAILY_RECURRENCE:
- recur->setRecurrenceType( RecurrenceRule::rDaily );
- break;
- case ICAL_WEEKLY_RECURRENCE:
- recur->setRecurrenceType( RecurrenceRule::rWeekly );
- break;
- case ICAL_MONTHLY_RECURRENCE:
- recur->setRecurrenceType( RecurrenceRule::rMonthly );
- break;
- case ICAL_YEARLY_RECURRENCE:
- recur->setRecurrenceType( RecurrenceRule::rYearly );
- break;
- case ICAL_NO_RECURRENCE:
- default:
- recur->setRecurrenceType( RecurrenceRule::rNone );
- }
- // Frequency
- recur->setFrequency( r.interval );
-
- // Duration & End Date
- if ( !icaltime_is_null_time( r.until ) ) {
- icaltimetype t = r.until;
- recur->setEndDt( readICalUtcDateTime( 0, t ) );
- } else {
- if ( r.count == 0 ) {
- recur->setDuration( -1 );
+ // Generate the RRULE string
+ recur->setRRule(
+ QLatin1String(icalrecurrencetype_as_string(const_cast<struct icalrecurrencetype*>(&r))));
+ // Period
+ switch (r.freq) {
+ case ICAL_SECONDLY_RECURRENCE:
+ recur->setRecurrenceType(RecurrenceRule::rSecondly);
+ break;
+ case ICAL_MINUTELY_RECURRENCE:
+ recur->setRecurrenceType(RecurrenceRule::rMinutely);
+ break;
+ case ICAL_HOURLY_RECURRENCE:
+ recur->setRecurrenceType(RecurrenceRule::rHourly);
+ break;
+ case ICAL_DAILY_RECURRENCE:
+ recur->setRecurrenceType(RecurrenceRule::rDaily);
+ break;
+ case ICAL_WEEKLY_RECURRENCE:
+ recur->setRecurrenceType(RecurrenceRule::rWeekly);
+ break;
+ case ICAL_MONTHLY_RECURRENCE:
+ recur->setRecurrenceType(RecurrenceRule::rMonthly);
+ break;
+ case ICAL_YEARLY_RECURRENCE:
+ recur->setRecurrenceType(RecurrenceRule::rYearly);
+ break;
+ case ICAL_NO_RECURRENCE:
+ default:
+ recur->setRecurrenceType(RecurrenceRule::rNone);
+ }
+ // Frequency
+ recur->setFrequency(r.interval);
+
+ // Duration & End Date
+ if (!icaltime_is_null_time(r.until)) {
+ icaltimetype t = r.until;
+ recur->setEndDt(readICalUtcDateTime(0, t));
} else {
- recur->setDuration( r.count );
+ if (r.count == 0) {
+ recur->setDuration(-1);
+ } else {
+ recur->setDuration(r.count);
+ }
}
- }
- // Week start setting
- short wkst = static_cast<short>( ( r.week_start + 5 ) % 7 + 1 );
- recur->setWeekStart( wkst );
+ // Week start setting
+ short wkst = static_cast<short>((r.week_start + 5) % 7 + 1);
+ recur->setWeekStart(wkst);
- // And now all BY*
- QList<int> lst;
- int i;
- int index = 0;
+ // And now all BY*
+ QList<int> lst;
+ int i;
+ int index = 0;
//@cond PRIVATE
#define readSetByList( rrulecomp, setfunc ) \
@@ -1995,782 +2148,815 @@ void ICalFormatImpl::readRecurrence( const struct icalrecurrencetype &r, Recurre
}
//@endcond
- // BYSECOND, MINUTE and HOUR, MONTHDAY, YEARDAY, WEEKNUMBER, MONTH
- // and SETPOS are standard int lists, so we can treat them with the
- // same macro
- readSetByList( by_second, setBySeconds );
- readSetByList( by_minute, setByMinutes );
- readSetByList( by_hour, setByHours );
- readSetByList( by_month_day, setByMonthDays );
- readSetByList( by_year_day, setByYearDays );
- readSetByList( by_week_no, setByWeekNumbers );
- readSetByList( by_month, setByMonths );
- readSetByList( by_set_pos, setBySetPos );
+ // BYSECOND, MINUTE and HOUR, MONTHDAY, YEARDAY, WEEKNUMBER, MONTH
+ // and SETPOS are standard int lists, so we can treat them with the
+ // same macro
+ readSetByList(by_second, setBySeconds);
+ readSetByList(by_minute, setByMinutes);
+ readSetByList(by_hour, setByHours);
+ readSetByList(by_month_day, setByMonthDays);
+ readSetByList(by_year_day, setByYearDays);
+ readSetByList(by_week_no, setByWeekNumbers);
+ readSetByList(by_month, setByMonths);
+ readSetByList(by_set_pos, setBySetPos);
#undef readSetByList
- // BYDAY is a special case, since it's not an int list
- QList<RecurrenceRule::WDayPos> wdlst;
- short day;
- index=0;
- while ( ( day = r.by_day[index++] ) != ICAL_RECURRENCE_ARRAY_MAX ) {
- RecurrenceRule::WDayPos pos;
- pos.setDay( static_cast<short>( ( icalrecurrencetype_day_day_of_week( day ) + 5 ) % 7 + 1 ) );
- pos.setPos( icalrecurrencetype_day_position( day ) );
- wdlst.append( pos );
- }
- if ( !wdlst.isEmpty() ) {
- recur->setByDays( wdlst );
- }
+ // BYDAY is a special case, since it's not an int list
+ QList<RecurrenceRule::WDayPos> wdlst;
+ short day;
+ index=0;
+ while ((day = r.by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
+ RecurrenceRule::WDayPos pos;
+ pos.setDay(static_cast<short>((icalrecurrencetype_day_day_of_week(day) + 5) % 7 + 1));
+ pos.setPos(icalrecurrencetype_day_position(day));
+ wdlst.append(pos);
+ }
+ if (!wdlst.isEmpty()) {
+ recur->setByDays(wdlst);
+ }
- // TODO: Store all X- fields of the RRULE inside the recurrence (so they are
- // preserved
+ // TODO: Store all X- fields of the RRULE inside the recurrence (so they are
+ // preserved
}
-void ICalFormatImpl::readAlarm( icalcomponent *alarm,
- Incidence::Ptr incidence,
- ICalTimeZones *tzlist )
+void ICalFormatImpl::readAlarm(icalcomponent *alarm,
+ Incidence::Ptr incidence,
+ ICalTimeZones *tzlist)
{
- Alarm::Ptr ialarm = incidence->newAlarm();
- ialarm->setRepeatCount( 0 );
- ialarm->setEnabled( true );
-
- // Determine the alarm's action type
- icalproperty *p = icalcomponent_get_first_property( alarm, ICAL_ACTION_PROPERTY );
- Alarm::Type type = Alarm::Display;
- icalproperty_action action = ICAL_ACTION_DISPLAY;
- if ( !p ) {
- qDebug() << "Unknown type of alarm, using default";
- // TODO: do something about unknown alarm type?
- } else {
-
- action = icalproperty_get_action( p );
- switch ( action ) {
- case ICAL_ACTION_DISPLAY:
- type = Alarm::Display;
- break;
- case ICAL_ACTION_AUDIO:
- type = Alarm::Audio;
- break;
- case ICAL_ACTION_PROCEDURE:
- type = Alarm::Procedure;
- break;
- case ICAL_ACTION_EMAIL:
- type = Alarm::Email;
- break;
- default:
- break;
- // TODO: do something about invalid alarm type?
- }
- }
- ialarm->setType( type );
-
- p = icalcomponent_get_first_property( alarm, ICAL_ANY_PROPERTY );
- while ( p ) {
- icalproperty_kind kind = icalproperty_isa( p );
-
- switch ( kind ) {
- case ICAL_TRIGGER_PROPERTY:
- {
- icaltriggertype trigger = icalproperty_get_trigger( p );
- if ( !icaltime_is_null_time( trigger.time ) ) {
- //set the trigger to a specific time (which is not in rfc2445, btw)
- ialarm->setTime( readICalUtcDateTime( p, trigger.time, tzlist ) );
- } else {
- //set the trigger to an offset from the incidence start or end time.
- if ( !icaldurationtype_is_bad_duration( trigger.duration ) ) {
- Duration duration( readICalDuration( trigger.duration ) );
- icalparameter *param =
- icalproperty_get_first_parameter( p, ICAL_RELATED_PARAMETER );
- if ( param && icalparameter_get_related( param ) == ICAL_RELATED_END ) {
- ialarm->setEndOffset( duration );
- } else {
- ialarm->setStartOffset( duration );
- }
- } else {
- // a bad duration was encountered, just set a 0 duration from start
- ialarm->setStartOffset( Duration( 0 ) );
- }
- }
- break;
- }
- case ICAL_DURATION_PROPERTY:
- {
- icaldurationtype duration = icalproperty_get_duration( p );
- ialarm->setSnoozeTime( readICalDuration( duration ) );
- break;
- }
- case ICAL_REPEAT_PROPERTY:
- ialarm->setRepeatCount( icalproperty_get_repeat( p ) );
- break;
-
- case ICAL_DESCRIPTION_PROPERTY:
- { // Only in DISPLAY and EMAIL and PROCEDURE alarms
- QString description = QString::fromUtf8( icalproperty_get_description( p ) );
- switch ( action ) {
- case ICAL_ACTION_DISPLAY:
- ialarm->setText( description );
- break;
- case ICAL_ACTION_PROCEDURE:
- ialarm->setProgramArguments( description );
- break;
- case ICAL_ACTION_EMAIL:
- ialarm->setMailText( description );
- break;
- default:
- break;
- }
- break;
- }
- case ICAL_SUMMARY_PROPERTY:
- // Only in EMAIL alarm
- ialarm->setMailSubject( QString::fromUtf8( icalproperty_get_summary( p ) ) );
- break;
-
- case ICAL_ATTENDEE_PROPERTY:
- { // Only in EMAIL alarm
- QString email = QString::fromUtf8( icalproperty_get_attendee( p ) );
- if ( email.startsWith( QLatin1String( "mailto:" ), Qt::CaseInsensitive ) ) {
- email = email.mid( 7 );
- }
- QString name;
- icalparameter *param = icalproperty_get_first_parameter( p, ICAL_CN_PARAMETER );
- if ( param ) {
- name = QString::fromUtf8( icalparameter_get_cn( param ) );
- }
- ialarm->addMailAddress( Person::Ptr( new Person( name, email ) ) );
- break;
- }
+ Alarm::Ptr ialarm = incidence->newAlarm();
+ ialarm->setRepeatCount(0);
+ ialarm->setEnabled(true);
+
+ // Determine the alarm's action type
+ icalproperty *p = icalcomponent_get_first_property(alarm, ICAL_ACTION_PROPERTY);
+ Alarm::Type type = Alarm::Display;
+ icalproperty_action action = ICAL_ACTION_DISPLAY;
+ if (!p) {
+ kDebug() << "Unknown type of alarm, using default";
+ // TODO: do something about unknown alarm type?
+ } else {
- case ICAL_ATTACH_PROPERTY:
- { // Only in AUDIO and EMAIL and PROCEDURE alarms
- Attachment::Ptr attach = readAttachment( p );
- if ( attach && attach->isUri() ) {
- switch ( action ) {
+ action = icalproperty_get_action(p);
+ switch (action) {
+ case ICAL_ACTION_DISPLAY:
+ type = Alarm::Display;
+ break;
case ICAL_ACTION_AUDIO:
- ialarm->setAudioFile( attach->uri() );
- break;
+ type = Alarm::Audio;
+ break;
case ICAL_ACTION_PROCEDURE:
- ialarm->setProgramFile( attach->uri() );
- break;
+ type = Alarm::Procedure;
+ break;
case ICAL_ACTION_EMAIL:
- ialarm->addMailAttachment( attach->uri() );
- break;
+ type = Alarm::Email;
+ break;
default:
- break;
+ break;
+ // TODO: do something about invalid alarm type?
}
- } else {
- qDebug() << "Alarm attachments currently only support URIs,"
- << "but no binary data";
- }
- break;
}
- default:
- break;
+ ialarm->setType(type);
+
+ p = icalcomponent_get_first_property(alarm, ICAL_ANY_PROPERTY);
+ while (p) {
+ icalproperty_kind kind = icalproperty_isa(p);
+
+ switch (kind) {
+ case ICAL_TRIGGER_PROPERTY:
+ {
+ icaltriggertype trigger = icalproperty_get_trigger(p);
+ if (!icaltime_is_null_time(trigger.time)) {
+ //set the trigger to a specific time (which is not in rfc2445, btw)
+ ialarm->setTime(readICalUtcDateTime(p, trigger.time, tzlist));
+ } else {
+ //set the trigger to an offset from the incidence start or end time.
+ if (!icaldurationtype_is_bad_duration(trigger.duration)) {
+ Duration duration(readICalDuration(trigger.duration));
+ icalparameter *param =
+ icalproperty_get_first_parameter(p, ICAL_RELATED_PARAMETER);
+ if (param && icalparameter_get_related(param) == ICAL_RELATED_END) {
+ ialarm->setEndOffset(duration);
+ } else {
+ ialarm->setStartOffset(duration);
+ }
+ } else {
+ // a bad duration was encountered, just set a 0 duration from start
+ ialarm->setStartOffset(Duration(0));
+ }
+ }
+ break;
+ }
+ case ICAL_DURATION_PROPERTY:
+ {
+ icaldurationtype duration = icalproperty_get_duration(p);
+ ialarm->setSnoozeTime(readICalDuration(duration));
+ break;
+ }
+ case ICAL_REPEAT_PROPERTY:
+ ialarm->setRepeatCount(icalproperty_get_repeat(p));
+ break;
+
+ case ICAL_DESCRIPTION_PROPERTY:
+ { // Only in DISPLAY and EMAIL and PROCEDURE alarms
+ QString description = QString::fromUtf8(icalproperty_get_description(p));
+ switch (action) {
+ case ICAL_ACTION_DISPLAY:
+ ialarm->setText(description);
+ break;
+ case ICAL_ACTION_PROCEDURE:
+ ialarm->setProgramArguments(description);
+ break;
+ case ICAL_ACTION_EMAIL:
+ ialarm->setMailText(description);
+ break;
+ default:
+ break;
+ }
+ break;
+ }
+ case ICAL_SUMMARY_PROPERTY:
+ // Only in EMAIL alarm
+ ialarm->setMailSubject(QString::fromUtf8(icalproperty_get_summary(p)));
+ break;
+
+ case ICAL_ATTENDEE_PROPERTY:
+ { // Only in EMAIL alarm
+ QString email = QString::fromUtf8(icalproperty_get_attendee(p));
+ if (email.startsWith(QLatin1String("mailto:"), Qt::CaseInsensitive)) {
+ email = email.mid(7);
+ }
+ QString name;
+ icalparameter *param = icalproperty_get_first_parameter(p, ICAL_CN_PARAMETER);
+ if (param) {
+ name = QString::fromUtf8(icalparameter_get_cn(param));
+ }
+ ialarm->addMailAddress(Person::Ptr(new Person(name, email)));
+ break;
+ }
+
+ case ICAL_ATTACH_PROPERTY:
+ { // Only in AUDIO and EMAIL and PROCEDURE alarms
+ Attachment::Ptr attach = readAttachment(p);
+ if (attach && attach->isUri()) {
+ switch (action) {
+ case ICAL_ACTION_AUDIO:
+ ialarm->setAudioFile(attach->uri());
+ break;
+ case ICAL_ACTION_PROCEDURE:
+ ialarm->setProgramFile(attach->uri());
+ break;
+ case ICAL_ACTION_EMAIL:
+ ialarm->addMailAttachment(attach->uri());
+ break;
+ default:
+ break;
+ }
+ } else {
+ kDebug() << "Alarm attachments currently only support URIs,"
+ << "but no binary data";
+ }
+ break;
+ }
+ default:
+ break;
+ }
+ p = icalcomponent_get_next_property(alarm, ICAL_ANY_PROPERTY);
}
- p = icalcomponent_get_next_property( alarm, ICAL_ANY_PROPERTY );
- }
- // custom properties
- d->readCustomProperties( alarm, ialarm.data() );
+ // custom properties
+ d->readCustomProperties(alarm, ialarm.data());
- QString locationRadius = ialarm->nonKDECustomProperty( "X-LOCATION-RADIUS" );
- if ( !locationRadius.isEmpty() ) {
- ialarm->setLocationRadius( locationRadius.toInt() );
- ialarm->setHasLocationRadius( true );
- }
+ QString locationRadius = ialarm->nonKDECustomProperty("X-LOCATION-RADIUS");
+ if (!locationRadius.isEmpty()) {
+ ialarm->setLocationRadius(locationRadius.toInt());
+ ialarm->setHasLocationRadius(true);
+ }
- if ( ialarm->customProperty( APP_NAME_FOR_XPROPERTIES,
- ENABLED_ALARM_XPROPERTY ) == QLatin1String( "FALSE" ) ) {
- ialarm->setEnabled( false );
- }
- // TODO: check for consistency of alarm properties
+ if (ialarm->customProperty(APP_NAME_FOR_XPROPERTIES,
+ ENABLED_ALARM_XPROPERTY) == QLatin1String("FALSE")) {
+ ialarm->setEnabled(false);
+ }
+ // TODO: check for consistency of alarm properties
}
-icaldatetimeperiodtype ICalFormatImpl::writeICalDatePeriod( const QDate &date )
+icaldatetimeperiodtype ICalFormatImpl::writeICalDatePeriod(const QDate &date)
{
- icaldatetimeperiodtype t;
- t.time = writeICalDate( date );
- t.period = icalperiodtype_null_period();
- return t;
+ icaldatetimeperiodtype t;
+ t.time = writeICalDate(date);
+ t.period = icalperiodtype_null_period();
+ return t;
}
-icaltimetype ICalFormatImpl::writeICalDate( const QDate &date )
+icaltimetype ICalFormatImpl::writeICalDate(const QDate &date)
{
- icaltimetype t = icaltime_null_time();
+ icaltimetype t = icaltime_null_time();
- t.year = date.year();
- t.month = date.month();
- t.day = date.day();
+ t.year = date.year();
+ t.month = date.month();
+ t.day = date.day();
- t.hour = 0;
- t.minute = 0;
- t.second = 0;
+ t.hour = 0;
+ t.minute = 0;
+ t.second = 0;
- t.is_date = 1;
- t.is_utc = 0;
- t.zone = 0;
+ t.is_date = 1;
+ t.is_utc = 0;
+ t.zone = 0;
- return t;
+ return t;
}
-icaltimetype ICalFormatImpl::writeICalDateTime( const KDateTime &datetime )
+icaltimetype ICalFormatImpl::writeICalDateTime(const KDateTime &datetime)
{
- icaltimetype t = icaltime_null_time();
+ icaltimetype t = icaltime_null_time();
- t.year = datetime.date().year();
- t.month = datetime.date().month();
- t.day = datetime.date().day();
+ t.year = datetime.date().year();
+ t.month = datetime.date().month();
+ t.day = datetime.date().day();
- t.is_date = datetime.isDateOnly() ? 1 : 0;
+ t.is_date = datetime.isDateOnly() ? 1 : 0;
- if ( !t.is_date ) {
- t.hour = datetime.time().hour();
- t.minute = datetime.time().minute();
- t.second = datetime.time().second();
- }
- t.zone = 0; // zone is NOT set
- t.is_utc = datetime.isUtc() ? 1 : 0;
+ if (!t.is_date) {
+ t.hour = datetime.time().hour();
+ t.minute = datetime.time().minute();
+ t.second = datetime.time().second();
+ }
+ t.zone = 0; // zone is NOT set
+ t.is_utc = datetime.isUtc() ? 1 : 0;
- // _dumpIcaltime( t );
+ // _dumpIcaltime( t );
- return t;
+ return t;
}
-icalproperty *ICalFormatImpl::writeICalDateTimeProperty( const icalproperty_kind type,
- const KDateTime &dt,
- ICalTimeZones *tzlist,
- ICalTimeZones *tzUsedList )
+icalproperty *ICalFormatImpl::writeICalDateTimeProperty(const icalproperty_kind type,
+ const KDateTime &dt,
+ ICalTimeZones *tzlist,
+ ICalTimeZones *tzUsedList)
{
- icaltimetype t;
+ icaltimetype t;
- switch ( type ) {
- case ICAL_DTSTAMP_PROPERTY:
- case ICAL_CREATED_PROPERTY:
- case ICAL_LASTMODIFIED_PROPERTY:
- t = writeICalDateTime( dt.toUtc() );
- break;
- default:
- t = writeICalDateTime( dt );
- break;
- }
+ switch (type) {
+ case ICAL_DTSTAMP_PROPERTY:
+ case ICAL_CREATED_PROPERTY:
+ case ICAL_LASTMODIFIED_PROPERTY:
+ t = writeICalDateTime(dt.toUtc());
+ break;
+ default:
+ t = writeICalDateTime(dt);
+ break;
+ }
- icalproperty *p;
- switch ( type ) {
- case ICAL_DTSTAMP_PROPERTY:
- p = icalproperty_new_dtstamp( t );
- break;
- case ICAL_CREATED_PROPERTY:
- p = icalproperty_new_created( t );
- break;
- case ICAL_LASTMODIFIED_PROPERTY:
- p = icalproperty_new_lastmodified( t );
- break;
- case ICAL_DTSTART_PROPERTY: // start date and time
- p = icalproperty_new_dtstart( t );
- break;
- case ICAL_DTEND_PROPERTY: // end date and time
- p = icalproperty_new_dtend( t );
- break;
- case ICAL_DUE_PROPERTY:
- p = icalproperty_new_due( t );
- break;
- case ICAL_RECURRENCEID_PROPERTY:
- p = icalproperty_new_recurrenceid( t );
- break;
- case ICAL_EXDATE_PROPERTY:
- p = icalproperty_new_exdate( t );
+ icalproperty *p;
+ switch (type) {
+ case ICAL_DTSTAMP_PROPERTY:
+ p = icalproperty_new_dtstamp(t);
+ break;
+ case ICAL_CREATED_PROPERTY:
+ p = icalproperty_new_created(t);
+ break;
+ case ICAL_LASTMODIFIED_PROPERTY:
+ p = icalproperty_new_lastmodified(t);
+ break;
+ case ICAL_DTSTART_PROPERTY: // start date and time
+ p = icalproperty_new_dtstart(t);
+ break;
+ case ICAL_DTEND_PROPERTY: // end date and time
+ p = icalproperty_new_dtend(t);
+ break;
+ case ICAL_DUE_PROPERTY:
+ p = icalproperty_new_due(t);
+ break;
+ case ICAL_RECURRENCEID_PROPERTY:
+ p = icalproperty_new_recurrenceid(t);
+ break;
+ case ICAL_EXDATE_PROPERTY:
+ p = icalproperty_new_exdate(t);
+ break;
+ case ICAL_X_PROPERTY:
+ {
+ p = icalproperty_new_x("");
+ icaltimetype timeType = writeICalDateTime(dt);
+ icalvalue *text = icalvalue_new_datetime(timeType);
+ icalproperty_set_value(p, text);
+ }
break;
- case ICAL_X_PROPERTY:
- {
- p = icalproperty_new_x( "" );
- icaltimetype timeType = writeICalDateTime( dt );
- icalvalue *text = icalvalue_new_datetime( timeType );
- icalproperty_set_value( p, text );
- }
- break;
- default:
- {
- icaldatetimeperiodtype tp;
- tp.time = t;
- tp.period = icalperiodtype_null_period();
- switch ( type ) {
- case ICAL_RDATE_PROPERTY:
- p = icalproperty_new_rdate( tp );
- break;
default:
- return 0;
+ {
+ icaldatetimeperiodtype tp;
+ tp.time = t;
+ tp.period = icalperiodtype_null_period();
+ switch (type) {
+ case ICAL_RDATE_PROPERTY:
+ p = icalproperty_new_rdate(tp);
+ break;
+ default:
+ return 0;
+ }
+ }
}
- }
- }
- KTimeZone ktz;
- if ( !t.is_utc ) {
- ktz = dt.timeZone();
- }
+ KTimeZone ktz;
+ if (!t.is_utc) {
+ ktz = dt.timeZone();
+ }
- if ( ktz.isValid() ) {
- if ( tzlist ) {
- ICalTimeZone tz = tzlist->zone( ktz.name() );
- if ( !tz.isValid() ) {
- // The time zone isn't in the list of known zones for the calendar
- // - add it to the calendar's zone list
- ICalTimeZone tznew( ktz );
- tzlist->add( tznew );
- tz = tznew;
- }
- if ( tzUsedList ) {
- tzUsedList->add( tz );
- }
+ if (ktz.isValid()) {
+ if (tzlist) {
+ ICalTimeZone tz = tzlist->zone(ktz.name());
+ if (!tz.isValid()) {
+ // The time zone isn't in the list of known zones for the calendar
+ // - add it to the calendar's zone list
+ ICalTimeZone tznew(ktz);
+ tzlist->add(tznew);
+ tz = tznew;
+ }
+ if (tzUsedList) {
+ tzUsedList->add(tz);
+ }
+ }
+ icalproperty_add_parameter(
+ p, icalparameter_new_tzid(ktz.name().toUtf8()));
}
- icalproperty_add_parameter(
- p, icalparameter_new_tzid( ktz.name().toUtf8() ) );
- }
- return p;
+ return p;
}
-KDateTime ICalFormatImpl::readICalDateTime( icalproperty *p,
- const icaltimetype &t,
- ICalTimeZones *tzlist,
- bool utc )
+KDateTime ICalFormatImpl::readICalDateTime(icalproperty *p,
+ const icaltimetype &t,
+ ICalTimeZones *tzlist,
+ bool utc)
{
-// qDebug();
+// kDebug();
// _dumpIcaltime( t );
- KDateTime::Spec timeSpec;
- if ( t.is_utc || t.zone == icaltimezone_get_utc_timezone() ) {
- timeSpec = KDateTime::UTC; // the time zone is UTC
- utc = false; // no need to convert to UTC
- } else {
- if ( !tzlist ) {
- utc = true; // should be UTC, but it isn't
- }
- icalparameter *param =
- p ? icalproperty_get_first_parameter( p, ICAL_TZID_PARAMETER ) : 0;
- const char *tzid = param ? icalparameter_get_tzid( param ) : 0;
- if ( !tzid ) {
- timeSpec = KDateTime::ClockTime;
+ KDateTime::Spec timeSpec;
+ if (t.is_utc || t.zone == icaltimezone_get_utc_timezone()) {
+ timeSpec = KDateTime::UTC; // the time zone is UTC
+ utc = false; // no need to convert to UTC
} else {
- QString tzidStr = QString::fromUtf8( tzid );
- ICalTimeZone tz;
- if ( tzlist ) {
- tz = tzlist->zone( tzidStr );
- }
- if ( !tz.isValid() ) {
- // The time zone is not in the existing list for the calendar.
- // Try to read it from the system or libical databases.
- ICalTimeZoneSource tzsource;
- ICalTimeZone newtz = tzsource.standardZone( tzidStr );
- if ( newtz.isValid() && tzlist ) {
- tzlist->add( newtz );
- }
- tz = newtz;
- }
- timeSpec = tz.isValid() ? KDateTime::Spec( tz ) : KDateTime::LocalZone;
+ if (!tzlist) {
+ utc = true; // should be UTC, but it isn't
+ }
+ icalparameter *param =
+ p ? icalproperty_get_first_parameter(p, ICAL_TZID_PARAMETER) : 0;
+ const char *tzid = param ? icalparameter_get_tzid(param) : 0;
+ if (!tzid) {
+ timeSpec = KDateTime::ClockTime;
+ } else {
+ QString tzidStr = QString::fromUtf8(tzid);
+ ICalTimeZone tz;
+ if (tzlist) {
+ tz = tzlist->zone(tzidStr);
+ }
+ if (!tz.isValid()) {
+ // The time zone is not in the existing list for the calendar.
+ // Try to read it from the system or libical databases.
+ ICalTimeZoneSource tzsource;
+ ICalTimeZone newtz = tzsource.standardZone(tzidStr);
+ if (newtz.isValid() && tzlist) {
+ tzlist->add(newtz);
+ }
+ tz = newtz;
+ }
+ timeSpec = tz.isValid() ? KDateTime::Spec(tz) : KDateTime::LocalZone;
+ }
}
- }
- KDateTime result;
- if ( t.is_date ) {
- result = KDateTime( QDate( t.year, t.month, t.day ), timeSpec );
- } else {
- result = KDateTime( QDate( t.year, t.month, t.day ),
- QTime( t.hour, t.minute, t.second ), timeSpec );
- }
- return utc ? result.toUtc() : result;
+ KDateTime result;
+ if (t.is_date) {
+ result = KDateTime(QDate(t.year, t.month, t.day), timeSpec);
+ } else {
+ result = KDateTime(QDate(t.year, t.month, t.day),
+ QTime(t.hour, t.minute, t.second), timeSpec);
+ }
+ return utc ? result.toUtc() : result;
}
-QDate ICalFormatImpl::readICalDate( icaltimetype t )
+QDate ICalFormatImpl::readICalDate(icaltimetype t)
{
- return QDate( t.year, t.month, t.day );
+ return QDate(t.year, t.month, t.day);
}
-KDateTime ICalFormatImpl::readICalDateTimeProperty( icalproperty *p,
- ICalTimeZones *tzlist,
- bool utc )
+KDateTime ICalFormatImpl::readICalDateTimeProperty(icalproperty *p,
+ ICalTimeZones *tzlist,
+ bool utc)
{
- icaldatetimeperiodtype tp;
- icalproperty_kind kind = icalproperty_isa( p );
- switch ( kind ) {
- case ICAL_CREATED_PROPERTY: // UTC date/time
- tp.time = icalproperty_get_created( p );
- utc = true;
- break;
- case ICAL_DTSTAMP_PROPERTY: // UTC date/time
- tp.time = icalproperty_get_dtstamp( p );
- utc = true;
- break;
- case ICAL_LASTMODIFIED_PROPERTY: // last modification UTC date/time
- tp.time = icalproperty_get_lastmodified( p );
- utc = true;
- break;
- case ICAL_DTSTART_PROPERTY: // start date and time (UTC for freebusy)
- tp.time = icalproperty_get_dtstart( p );
- break;
- case ICAL_DTEND_PROPERTY: // end date and time (UTC for freebusy)
- tp.time = icalproperty_get_dtend( p );
- break;
- case ICAL_DUE_PROPERTY: // due date/time
- tp.time = icalproperty_get_due( p );
- break;
- case ICAL_COMPLETED_PROPERTY: // UTC completion date/time
- tp.time = icalproperty_get_completed( p );
- utc = true;
- break;
- case ICAL_RECURRENCEID_PROPERTY:
- tp.time = icalproperty_get_recurrenceid( p );
- break;
- case ICAL_EXDATE_PROPERTY:
- tp.time = icalproperty_get_exdate( p );
- break;
- case ICAL_X_PROPERTY:
- {
- const char *name = icalproperty_get_x_name( p );
- if ( QLatin1String( name ) == QLatin1String( "X-KDE-LIBKCAL-DTRECURRENCE" ) ) {
- const char *value = icalvalue_as_ical_string( icalproperty_get_value( p ) );
- icalvalue *v = icalvalue_new_from_string( ICAL_DATETIME_VALUE, value );
- tp.time = icalvalue_get_datetime( v );
- icalvalue_free( v );
- break;
+ icaldatetimeperiodtype tp;
+ icalproperty_kind kind = icalproperty_isa(p);
+ switch (kind) {
+ case ICAL_CREATED_PROPERTY: // UTC date/time
+ tp.time = icalproperty_get_created(p);
+ utc = true;
+ break;
+ case ICAL_DTSTAMP_PROPERTY: // UTC date/time
+ tp.time = icalproperty_get_dtstamp(p);
+ utc = true;
+ break;
+ case ICAL_LASTMODIFIED_PROPERTY: // last modification UTC date/time
+ tp.time = icalproperty_get_lastmodified(p);
+ utc = true;
+ break;
+ case ICAL_DTSTART_PROPERTY: // start date and time (UTC for freebusy)
+ tp.time = icalproperty_get_dtstart(p);
+ break;
+ case ICAL_DTEND_PROPERTY: // end date and time (UTC for freebusy)
+ tp.time = icalproperty_get_dtend(p);
+ break;
+ case ICAL_DUE_PROPERTY: // due date/time
+ tp.time = icalproperty_get_due(p);
+ break;
+ case ICAL_COMPLETED_PROPERTY: // UTC completion date/time
+ tp.time = icalproperty_get_completed(p);
+ utc = true;
+ break;
+ case ICAL_RECURRENCEID_PROPERTY:
+ tp.time = icalproperty_get_recurrenceid(p);
+ break;
+ case ICAL_EXDATE_PROPERTY:
+ tp.time = icalproperty_get_exdate(p);
+ break;
+ case ICAL_X_PROPERTY:
+ {
+ const char *name = icalproperty_get_x_name(p);
+ if (QLatin1String(name) == QLatin1String("X-KDE-LIBKCAL-DTRECURRENCE")) {
+ const char *value = icalvalue_as_ical_string(icalproperty_get_value(p));
+ icalvalue *v = icalvalue_new_from_string(ICAL_DATETIME_VALUE, value);
+ tp.time = icalvalue_get_datetime(v);
+ icalvalue_free(v);
+ break;
+ }
}
- }
- default:
- switch ( kind ) {
- case ICAL_RDATE_PROPERTY:
- tp = icalproperty_get_rdate( p );
- break;
default:
- return KDateTime();
+ switch (kind) {
+ case ICAL_RDATE_PROPERTY:
+ tp = icalproperty_get_rdate(p);
+ break;
+ default:
+ return KDateTime();
+ }
+ if (!icaltime_is_valid_time(tp.time)) {
+ return KDateTime(); // a time period was found (not implemented yet)
+ }
+ break;
}
- if ( !icaltime_is_valid_time( tp.time ) ) {
- return KDateTime(); // a time period was found (not implemented yet)
+ if (tp.time.is_date) {
+ return KDateTime(readICalDate(tp.time), KDateTime::Spec::ClockTime());
+ } else {
+ return readICalDateTime(p, tp.time, tzlist, utc);
}
- break;
- }
- if ( tp.time.is_date ) {
- return KDateTime( readICalDate( tp.time ), KDateTime::Spec::ClockTime() );
- } else {
- return readICalDateTime( p, tp.time, tzlist, utc );
- }
}
-icaldurationtype ICalFormatImpl::writeICalDuration( const Duration &duration )
+icaldurationtype ICalFormatImpl::writeICalDuration(const Duration &duration)
{
- // should be able to use icaldurationtype_from_int(), except we know
- // that some older tools do not properly support weeks. So we never
- // set a week duration, only days
-
- icaldurationtype d;
-
- int value = duration.value();
- d.is_neg = ( value < 0 ) ? 1 : 0;
- if ( value < 0 ) {
- value = -value;
- }
- // RFC2445 states that an ical duration value must be
- // EITHER weeks OR days/time, not both.
- if ( duration.isDaily() ) {
- if ( !( value % 7 ) ) {
- d.weeks = value / 7;
- d.days = 0;
- } else {
- d.weeks = 0;
- d.days = value;
- }
- d.hours = d.minutes = d.seconds = 0;
- } else {
- if ( !( value % gSecondsPerWeek ) ) {
- d.weeks = value / gSecondsPerWeek;
- d.days = d.hours = d.minutes = d.seconds = 0;
+ // should be able to use icaldurationtype_from_int(), except we know
+ // that some older tools do not properly support weeks. So we never
+ // set a week duration, only days
+
+ icaldurationtype d;
+
+ int value = duration.value();
+ d.is_neg = (value < 0) ? 1 : 0;
+ if (value < 0) {
+ value = -value;
+ }
+ // RFC2445 states that an ical duration value must be
+ // EITHER weeks OR days/time, not both.
+ if (duration.isDaily()) {
+ if (!(value % 7)) {
+ d.weeks = value / 7;
+ d.days = 0;
+ } else {
+ d.weeks = 0;
+ d.days = value;
+ }
+ d.hours = d.minutes = d.seconds = 0;
} else {
- d.weeks = 0;
- d.days = value / gSecondsPerDay;
- value %= gSecondsPerDay;
- d.hours = value / gSecondsPerHour;
- value %= gSecondsPerHour;
- d.minutes = value / gSecondsPerMinute;
- value %= gSecondsPerMinute;
- d.seconds = value;
- }
- }
+ if (!(value % gSecondsPerWeek)) {
+ d.weeks = value / gSecondsPerWeek;
+ d.days = d.hours = d.minutes = d.seconds = 0;
+ } else {
+ d.weeks = 0;
+ d.days = value / gSecondsPerDay;
+ value %= gSecondsPerDay;
+ d.hours = value / gSecondsPerHour;
+ value %= gSecondsPerHour;
+ d.minutes = value / gSecondsPerMinute;
+ value %= gSecondsPerMinute;
+ d.seconds = value;
+ }
+ }
- return d;
+ return d;
}
-Duration ICalFormatImpl::readICalDuration( icaldurationtype d )
+Duration ICalFormatImpl::readICalDuration(icaldurationtype d)
{
- int days = d.weeks * 7;
- days += d.days;
- int seconds = d.hours * gSecondsPerHour;
- seconds += d.minutes * gSecondsPerMinute;
- seconds += d.seconds;
- if ( seconds ) {
- seconds += days * gSecondsPerDay;
- if ( d.is_neg ) {
- seconds = -seconds;
- }
- return Duration( seconds, Duration::Seconds );
- } else {
- if ( d.is_neg ) {
- days = -days;
- }
- return Duration( days, Duration::Days );
- }
+ int days = d.weeks * 7;
+ days += d.days;
+ int seconds = d.hours * gSecondsPerHour;
+ seconds += d.minutes * gSecondsPerMinute;
+ seconds += d.seconds;
+ if (seconds) {
+ seconds += days * gSecondsPerDay;
+ if (d.is_neg) {
+ seconds = -seconds;
+ }
+ return Duration(seconds, Duration::Seconds);
+ } else {
+ if (d.is_neg) {
+ days = -days;
+ }
+ return Duration(days, Duration::Days);
+ }
}
-icalcomponent *ICalFormatImpl::createCalendarComponent( const Calendar::Ptr &cal )
+icalcomponent *ICalFormatImpl::createCalendarComponent(const Calendar::Ptr &cal)
{
- icalcomponent *calendar;
-
- // Root component
- calendar = icalcomponent_new( ICAL_VCALENDAR_COMPONENT );
-
- icalproperty *p;
-
- // Product Identifier
- p = icalproperty_new_prodid( CalFormat::productId().toUtf8() );
- icalcomponent_add_property( calendar, p );
-
- // iCalendar version (2.0)
- p = icalproperty_new_version( const_cast<char *>(_ICAL_VERSION) );
- icalcomponent_add_property( calendar, p );
-
- // Implementation Version
- p = icalproperty_new_x( _ICAL_IMPLEMENTATION_VERSION );
- icalproperty_set_x_name( p, IMPLEMENTATION_VERSION_XPROPERTY );
- icalcomponent_add_property( calendar, p );
-
- // Add time zone
- // NOTE: Commented out since relevant timezones are added by the caller.
- // Previously we got some timezones listed twice in the ical file.
- /*
- if ( cal && cal->timeZones() ) {
- const ICalTimeZones::ZoneMap zmaps = cal->timeZones()->zones();
- for ( ICalTimeZones::ZoneMap::ConstIterator it=zmaps.constBegin();
- it != zmaps.constEnd(); ++it ) {
- icaltimezone *icaltz = (*it).icalTimezone();
- if ( !icaltz ) {
- kError() << "bad time zone";
- } else {
- icalcomponent *tz = icalcomponent_new_clone( icaltimezone_get_component( icaltz ) );
- icalcomponent_add_component( calendar, tz );
- icaltimezone_free( icaltz, 1 );
+ icalcomponent *calendar;
+
+ // Root component
+ calendar = icalcomponent_new(ICAL_VCALENDAR_COMPONENT);
+
+ icalproperty *p;
+
+ // Product Identifier
+ p = icalproperty_new_prodid(CalFormat::productId().toUtf8());
+ icalcomponent_add_property(calendar, p);
+
+ // iCalendar version (2.0)
+ p = icalproperty_new_version(const_cast<char *>(_ICAL_VERSION));
+ icalcomponent_add_property(calendar, p);
+
+ // Implementation Version
+ p = icalproperty_new_x(_ICAL_IMPLEMENTATION_VERSION);
+ icalproperty_set_x_name(p, IMPLEMENTATION_VERSION_XPROPERTY);
+ icalcomponent_add_property(calendar, p);
+
+ // Add time zone
+ // NOTE: Commented out since relevant timezones are added by the caller.
+ // Previously we got some timezones listed twice in the ical file.
+ /*
+ if ( cal && cal->timeZones() ) {
+ const ICalTimeZones::ZoneMap zmaps = cal->timeZones()->zones();
+ for ( ICalTimeZones::ZoneMap::ConstIterator it=zmaps.constBegin();
+ it != zmaps.constEnd(); ++it ) {
+ icaltimezone *icaltz = (*it).icalTimezone();
+ if ( !icaltz ) {
+ kError() << "bad time zone";
+ } else {
+ icalcomponent *tz = icalcomponent_new_clone( icaltimezone_get_component( icaltz ) );
+ icalcomponent_add_component( calendar, tz );
+ icaltimezone_free( icaltz, 1 );
+ }
}
}
- }
- */
- // Custom properties
- if( cal != 0 ) {
- d->writeCustomProperties( calendar, cal.data() );
- }
+ */
+ // Custom properties
+ if (cal != 0) {
+ d->writeCustomProperties(calendar, cal.data());
+ }
- return calendar;
+ return calendar;
+}
+
+Incidence::Ptr ICalFormatImpl::readOneIncidence(icalcomponent *calendar, ICalTimeZones *tzlist)
+{
+ if (!calendar) {
+ kWarning() << "Populate called with empty calendar";
+ return Incidence::Ptr();
+ }
+ icalcomponent *c;
+ c = icalcomponent_get_first_component(calendar, ICAL_VEVENT_COMPONENT);
+ if (c) {
+ return readEvent(c, tzlist);
+ }
+ c = icalcomponent_get_first_component(calendar, ICAL_VTODO_COMPONENT);
+ if (c) {
+ return readTodo(c, tzlist);
+ }
+ c = icalcomponent_get_first_component(calendar, ICAL_VJOURNAL_COMPONENT);
+ if (c) {
+ return readJournal(c, tzlist);
+ }
+ kWarning() << "Found no incidence";
+ return Incidence::Ptr();
}
// take a raw vcalendar (i.e. from a file on disk, clipboard, etc. etc.
// and break it down from its tree-like format into the dictionary format
// that is used internally in the ICalFormatImpl.
-bool ICalFormatImpl::populate( const Calendar::Ptr &cal, icalcomponent *calendar,
- bool deleted, const QString &notebook )
+bool ICalFormatImpl::populate(const Calendar::Ptr &cal, icalcomponent *calendar,
+ bool deleted, const QString &notebook)
{
- Q_UNUSED(notebook);
+ Q_UNUSED(notebook);
- // qDebug()<<"Populate called";
+ // kDebug()<<"Populate called";
- // this function will populate the caldict dictionary and other event
- // lists. It turns vevents into Events and then inserts them.
+ // this function will populate the caldict dictionary and other event
+ // lists. It turns vevents into Events and then inserts them.
- if ( !calendar ) {
- qDebug() << "Populate called with empty calendar";
- return false;
- }
+ if (!calendar) {
+ kWarning() << "Populate called with empty calendar";
+ return false;
+ }
// TODO: check for METHOD
- icalproperty *p;
-
- p = icalcomponent_get_first_property( calendar, ICAL_X_PROPERTY );
- QString implementationVersion;
-
- while ( p ) {
- const char *name = icalproperty_get_x_name( p );
- QByteArray nproperty( name );
- if ( nproperty == QByteArray( IMPLEMENTATION_VERSION_XPROPERTY ) ) {
- QString nvalue = QString::fromUtf8( icalproperty_get_x( p ) );
- if ( nvalue.isEmpty() ) {
- icalvalue *value = icalproperty_get_value( p );
- if ( icalvalue_isa( value ) == ICAL_TEXT_VALUE ) {
- nvalue = QString::fromUtf8( icalvalue_get_text( value ) );
+ icalproperty *p;
+
+ p = icalcomponent_get_first_property(calendar, ICAL_X_PROPERTY);
+ QString implementationVersion;
+
+ while (p) {
+ const char *name = icalproperty_get_x_name(p);
+ QByteArray nproperty(name);
+ if (nproperty == QByteArray(IMPLEMENTATION_VERSION_XPROPERTY)) {
+ QString nvalue = QString::fromUtf8(icalproperty_get_x(p));
+ if (nvalue.isEmpty()) {
+ icalvalue *value = icalproperty_get_value(p);
+ if (icalvalue_isa(value) == ICAL_TEXT_VALUE) {
+ nvalue = QString::fromUtf8(icalvalue_get_text(value));
+ }
+ }
+ implementationVersion = nvalue;
+ icalcomponent_remove_property(calendar, p);
+ icalproperty_free(p);
}
- }
- implementationVersion = nvalue;
- icalcomponent_remove_property( calendar, p );
+ p = icalcomponent_get_next_property(calendar, ICAL_X_PROPERTY);
}
- p = icalcomponent_get_next_property( calendar, ICAL_X_PROPERTY );
- }
- p = icalcomponent_get_first_property( calendar, ICAL_PRODID_PROPERTY );
- if ( !p ) {
- qDebug() << "No PRODID property found";
- d->mLoadedProductId = "";
- } else {
- d->mLoadedProductId = QString::fromUtf8( icalproperty_get_prodid( p ) );
-
- delete d->mCompat;
- d->mCompat = CompatFactory::createCompat( d->mLoadedProductId, implementationVersion );
- }
+ p = icalcomponent_get_first_property(calendar, ICAL_PRODID_PROPERTY);
+ if (!p) {
+ kDebug() << "No PRODID property found";
+ d->mLoadedProductId = QLatin1String("");
+ } else {
+ d->mLoadedProductId = QString::fromUtf8(icalproperty_get_prodid(p));
- p = icalcomponent_get_first_property( calendar, ICAL_VERSION_PROPERTY );
- if ( !p ) {
- qDebug() << "No VERSION property found";
- d->mParent->setException( new Exception( Exception::CalVersionUnknown ) );
- return false;
- } else {
- const char *version = icalproperty_get_version( p );
- if ( !version ) {
- qDebug() << "No VERSION property found";
- d->mParent->setException( new Exception( Exception::VersionPropertyMissing ) );
-
- return false;
- }
- if ( strcmp( version, "1.0" ) == 0 ) {
- qDebug() << "Expected iCalendar, got vCalendar";
- d->mParent->setException( new Exception( Exception::CalVersion1 ) );
- return false;
- } else if ( strcmp( version, "2.0" ) != 0 ) {
- qDebug() << "Expected iCalendar, got unknown format";
- d->mParent->setException( new Exception(
- Exception::CalVersionUnknown ) );
- return false;
+ delete d->mCompat;
+ d->mCompat = CompatFactory::createCompat(d->mLoadedProductId, implementationVersion);
}
- }
- // Populate the calendar's time zone collection with all VTIMEZONE components
- ICalTimeZones *tzlist = cal->timeZones();
- ICalTimeZoneSource tzs;
- tzs.parse( calendar, *tzlist );
-
- // custom properties
- d->readCustomProperties( calendar, cal.data() );
-
- // Store all events with a relatedTo property in a list for post-processing
- d->mEventsRelate.clear();
- d->mTodosRelate.clear();
- // TODO: make sure that only actually added events go to this lists.
-
- icalcomponent *c;
-
- c = icalcomponent_get_first_component( calendar, ICAL_VTODO_COMPONENT );
- while ( c ) {
- Todo::Ptr todo = readTodo( c, tzlist );
- if ( todo ) {
- // qDebug() << "todo is no zero and deleted is " << deleted;
- Todo::Ptr old = cal->todo( todo->uid(), todo->recurrenceId() );
- if ( old ) {
- // qDebug() << "Found an old todo with uid " << old->uid();;
- if ( deleted ) {
- // qDebug()<<"Todo " << todo->uid() << " already deleted2";
- cal->deleteTodo( old ); // move old to deleted
- removeAllICal( d->mTodosRelate, old );
- } else if ( todo->revision() > old->revision() ) {
- // qDebug() << "Replacing old todo " << old.data() << " with this one " << todo.data();
- cal->deleteTodo( old ); // move old to deleted
- removeAllICal( d->mTodosRelate, old );
- cal->addTodo( todo ); // and replace it with this one
- }
- } else if ( deleted ) {
- // qDebug()<<"Todo " << todo->uid() << " already deleted";
- old = cal->deletedTodo( todo->uid(), todo->recurrenceId() );
- if ( !old ) {
- cal->addTodo( todo ); // add this one
- cal->deleteTodo( todo ); // and move it to deleted
- }
- } else {
- // qDebug() << "Adding todo " << todo.data() << todo->uid();
- cal->addTodo( todo ); // just add this one
- }
- }
- c = icalcomponent_get_next_component( calendar, ICAL_VTODO_COMPONENT );
- }
+ p = icalcomponent_get_first_property(calendar, ICAL_VERSION_PROPERTY);
+ if (!p) {
+ kDebug() << "No VERSION property found";
+ d->mParent->setException(new Exception(Exception::CalVersionUnknown));
+ return false;
+ } else {
+ const char *version = icalproperty_get_version(p);
+ if (!version) {
+ kDebug() << "No VERSION property found";
+ d->mParent->setException(new Exception(Exception::VersionPropertyMissing));
- // Iterate through all events
- c = icalcomponent_get_first_component( calendar, ICAL_VEVENT_COMPONENT );
- while ( c ) {
- Event::Ptr event = readEvent( c, tzlist );
-
- //qDebug() << "Inserting" << cal->event( event->uid() );
- if ( event ) {
- Event::Ptr old = cal->event( event->uid(), event->recurrenceId() );
- if ( old ) {
- if ( old->uid().isEmpty() ) {
- qWarning() << "Skipping invalid VEVENT";
- c = icalcomponent_get_next_component( calendar, ICAL_VEVENT_COMPONENT );
- continue;
- }
- qDebug() << "OLD EVENT" << old->uid();
- if ( deleted ) {
- cal->deleteEvent( old ); // move old to deleted
- removeAllICal( d->mEventsRelate, old );
- } else if ( event->revision() > old->revision() ) {
- cal->deleteEvent( old ); // move old to deleted
- removeAllICal( d->mEventsRelate, old );
- cal->addEvent( event ); // and replace it with this one
- }
- } else if ( deleted ) {
- old = cal->deletedEvent( event->uid(), event->recurrenceId() );
- if ( !old ) {
- cal->addEvent( event ); // add this one
- cal->deleteEvent( event ); // and move it to deleted
- }
- } else {
- cal->addEvent( event ); // just add this one
- }
+ return false;
+ }
+ if (strcmp(version, "1.0") == 0) {
+ kDebug() << "Expected iCalendar, got vCalendar";
+ d->mParent->setException(new Exception(Exception::CalVersion1));
+ return false;
+ } else if (strcmp(version, "2.0") != 0) {
+ kDebug() << "Expected iCalendar, got unknown format";
+ d->mParent->setException(new Exception(
+ Exception::CalVersionUnknown));
+ return false;
+ }
}
- c = icalcomponent_get_next_component( calendar, ICAL_VEVENT_COMPONENT );
- }
- // Iterate through all journals
- c = icalcomponent_get_first_component( calendar, ICAL_VJOURNAL_COMPONENT );
- while ( c ) {
- Journal::Ptr journal = readJournal( c, tzlist );
- if ( journal ) {
- Journal::Ptr old = cal->journal( journal->uid(), journal->recurrenceId() );
- if ( old ) {
- if ( deleted ) {
- cal->deleteJournal( old ); // move old to deleted
- } else if ( journal->revision() > old->revision() ) {
- cal->deleteJournal( old ); // move old to deleted
- cal->addJournal( journal ); // and replace it with this one
- }
- } else if ( deleted ) {
- old = cal->deletedJournal( journal->uid(), journal->recurrenceId() );
- if ( !old ) {
- cal->addJournal( journal ); // add this one
- cal->deleteJournal( journal ); // and move it to deleted
- }
- } else {
- cal->addJournal( journal ); // just add this one
- }
+ // Populate the calendar's time zone collection with all VTIMEZONE components
+ // FIXME: HUUUUUGE memory consumption
+ ICalTimeZones *tzlist = cal->timeZones();
+ ICalTimeZoneSource tzs;
+ tzs.parse(calendar, *tzlist);
+
+ // custom properties
+ d->readCustomProperties(calendar, cal.data());
+
+ // Store all events with a relatedTo property in a list for post-processing
+ d->mEventsRelate.clear();
+ d->mTodosRelate.clear();
+ // TODO: make sure that only actually added events go to this lists.
+
+ icalcomponent *c;
+
+ c = icalcomponent_get_first_component(calendar, ICAL_VTODO_COMPONENT);
+ while (c) {
+ Todo::Ptr todo = readTodo(c, tzlist);
+ if (todo) {
+ // kDebug() << "todo is not zero and deleted is " << deleted;
+ Todo::Ptr old = cal->todo(todo->uid(), todo->recurrenceId());
+ if (old) {
+ if (old->uid().isEmpty()) {
+ kWarning() << "Skipping invalid VTODO";
+ c = icalcomponent_get_next_component(calendar, ICAL_VTODO_COMPONENT);
+ continue;
+ }
+ // kDebug() << "Found an old todo with uid " << old->uid();
+ if (deleted) {
+ // kDebug() << "Todo " << todo->uid() << " already deleted";
+ cal->deleteTodo(old); // move old to deleted
+ removeAllICal(d->mTodosRelate, old);
+ } else if (todo->revision() > old->revision()) {
+ // kDebug() << "Replacing old todo " << old.data() << " with this one " << todo.data();
+ cal->deleteTodo(old); // move old to deleted
+ removeAllICal(d->mTodosRelate, old);
+ cal->addTodo(todo); // and replace it with this one
+ }
+ } else if (deleted) {
+ // kDebug() << "Todo " << todo->uid() << " already deleted";
+ old = cal->deletedTodo(todo->uid(), todo->recurrenceId());
+ if (!old) {
+ cal->addTodo(todo); // add this one
+ cal->deleteTodo(todo); // and move it to deleted
+ }
+ } else {
+ // kDebug() << "Adding todo " << todo.data() << todo->uid();
+ cal->addTodo(todo); // just add this one
+ }
+ }
+ c = icalcomponent_get_next_component(calendar, ICAL_VTODO_COMPONENT);
+ }
+
+ // Iterate through all events
+ c = icalcomponent_get_first_component(calendar, ICAL_VEVENT_COMPONENT);
+ while (c) {
+ Event::Ptr event = readEvent(c, tzlist);
+ if (event) {
+ // kDebug() << "event is not zero and deleted is " << deleted;
+ Event::Ptr old = cal->event(event->uid(), event->recurrenceId());
+ if (old) {
+ if (old->uid().isEmpty()) {
+ kWarning() << "Skipping invalid VEVENT";
+ c = icalcomponent_get_next_component(calendar, ICAL_VEVENT_COMPONENT);
+ continue;
+ }
+ // kDebug() << "Found an old event with uid " << old->uid();
+ if (deleted) {
+ // kDebug() << "Event " << event->uid() << " already deleted";
+ cal->deleteEvent(old); // move old to deleted
+ removeAllICal(d->mEventsRelate, old);
+ } else if (event->revision() > old->revision()) {
+ // kDebug() << "Replacing old event " << old.data() << " with this one " << event.data();
+ cal->deleteEvent(old); // move old to deleted
+ removeAllICal(d->mEventsRelate, old);
+ cal->addEvent(event); // and replace it with this one
+ }
+ } else if (deleted) {
+ // kDebug() << "Event " << event->uid() << " already deleted";
+ old = cal->deletedEvent(event->uid(), event->recurrenceId());
+ if (!old) {
+ cal->addEvent(event); // add this one
+ cal->deleteEvent(event); // and move it to deleted
+ }
+ } else {
+ // kDebug() << "Adding event " << event.data() << event->uid();
+ cal->addEvent(event); // just add this one
+ }
+ }
+ c = icalcomponent_get_next_component(calendar, ICAL_VEVENT_COMPONENT);
+ }
+
+ // Iterate through all journals
+ c = icalcomponent_get_first_component(calendar, ICAL_VJOURNAL_COMPONENT);
+ while (c) {
+ Journal::Ptr journal = readJournal(c, tzlist);
+ if (journal) {
+ Journal::Ptr old = cal->journal(journal->uid(), journal->recurrenceId());
+ if (old) {
+ if (deleted) {
+ cal->deleteJournal(old); // move old to deleted
+ } else if (journal->revision() > old->revision()) {
+ cal->deleteJournal(old); // move old to deleted
+ cal->addJournal(journal); // and replace it with this one
+ }
+ } else if (deleted) {
+ old = cal->deletedJournal(journal->uid(), journal->recurrenceId());
+ if (!old) {
+ cal->addJournal(journal); // add this one
+ cal->deleteJournal(journal); // and move it to deleted
+ }
+ } else {
+ cal->addJournal(journal); // just add this one
+ }
+ }
+ c = icalcomponent_get_next_component(calendar, ICAL_VJOURNAL_COMPONENT);
}
- c = icalcomponent_get_next_component( calendar, ICAL_VJOURNAL_COMPONENT );
- }
- // TODO: Remove any previous time zones no longer referenced in the calendar
+ // TODO: Remove any previous time zones no longer referenced in the calendar
- return true;
+ return true;
}
-QString ICalFormatImpl::extractErrorProperty( icalcomponent *c )
+QString ICalFormatImpl::extractErrorProperty(icalcomponent *c)
{
- QString errorMessage;
-
- icalproperty *error;
- error = icalcomponent_get_first_property( c, ICAL_XLICERROR_PROPERTY );
- while ( error ) {
- errorMessage += icalproperty_get_xlicerror( error );
- errorMessage += '\n';
- error = icalcomponent_get_next_property( c, ICAL_XLICERROR_PROPERTY );
- }
+ QString errorMessage;
+
+ icalproperty *error;
+ error = icalcomponent_get_first_property(c, ICAL_XLICERROR_PROPERTY);
+ while (error) {
+ errorMessage += QLatin1String(icalproperty_get_xlicerror(error));
+ errorMessage += QLatin1Char('\n');
+ error = icalcomponent_get_next_property(c, ICAL_XLICERROR_PROPERTY);
+ }
- return errorMessage;
+ return errorMessage;
}
/*
@@ -2778,16 +2964,16 @@ void ICalFormatImpl::dumpIcalRecurrence( const icalrecurrencetype &r )
{
int i;
- qDebug() << " Freq:" << int( r.freq );
- qDebug() << " Until:" << icaltime_as_ical_string( r.until );
- qDebug() << " Count:" << r.count;
+ kDebug() << " Freq:" << int( r.freq );
+ kDebug() << " Until:" << icaltime_as_ical_string( r.until );
+ kDebug() << " Count:" << r.count;
if ( r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX ) {
int index = 0;
QString out = " By Day: ";
while ( ( i = r.by_day[index++] ) != ICAL_RECURRENCE_ARRAY_MAX ) {
out.append( QString::number( i ) + ' ' );
}
- qDebug() << out;
+ kDebug() << out;
}
if ( r.by_month_day[0] != ICAL_RECURRENCE_ARRAY_MAX ) {
int index = 0;
@@ -2795,7 +2981,7 @@ void ICalFormatImpl::dumpIcalRecurrence( const icalrecurrencetype &r )
while ( ( i = r.by_month_day[index++] ) != ICAL_RECURRENCE_ARRAY_MAX ) {
out.append( QString::number( i ) + ' ' );
}
- qDebug() << out;
+ kDebug() << out;
}
if ( r.by_year_day[0] != ICAL_RECURRENCE_ARRAY_MAX ) {
int index = 0;
@@ -2803,7 +2989,7 @@ void ICalFormatImpl::dumpIcalRecurrence( const icalrecurrencetype &r )
while ( ( i = r.by_year_day[index++] ) != ICAL_RECURRENCE_ARRAY_MAX ) {
out.append( QString::number( i ) + ' ' );
}
- qDebug() << out;
+ kDebug() << out;
}
if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX ) {
int index = 0;
@@ -2811,114 +2997,114 @@ void ICalFormatImpl::dumpIcalRecurrence( const icalrecurrencetype &r )
while ( ( i = r.by_month[index++] ) != ICAL_RECURRENCE_ARRAY_MAX ) {
out.append( QString::number( i ) + ' ' );
}
- qDebug() << out;
+ kDebug() << out;
}
if ( r.by_set_pos[0] != ICAL_RECURRENCE_ARRAY_MAX ) {
int index = 0;
QString out = " By Set Pos: ";
while ( ( i = r.by_set_pos[index++] ) != ICAL_RECURRENCE_ARRAY_MAX ) {
- qDebug() << "=========" << i;
+ kDebug() << "=========" << i;
out.append( QString::number( i ) + ' ' );
}
- qDebug() << out;
+ kDebug() << out;
}
}
*/
-icalcomponent *ICalFormatImpl::createScheduleComponent( const IncidenceBase::Ptr &incidence,
- iTIPMethod method )
+icalcomponent *ICalFormatImpl::createScheduleComponent(const IncidenceBase::Ptr &incidence,
+ iTIPMethod method)
{
- icalcomponent *message = createCalendarComponent();
+ icalcomponent *message = createCalendarComponent();
- // Create VTIMEZONE components for this incidence
- ICalTimeZones zones;
- if ( incidence ) {
- const KDateTime kd1 = incidence->dateTime( IncidenceBase::RoleStartTimeZone );
- const KDateTime kd2 = incidence->dateTime( IncidenceBase::RoleEndTimeZone );
+ // Create VTIMEZONE components for this incidence
+ ICalTimeZones zones;
+ if (incidence) {
+ const KDateTime kd1 = incidence->dateTime(IncidenceBase::RoleStartTimeZone);
+ const KDateTime kd2 = incidence->dateTime(IncidenceBase::RoleEndTimeZone);
- if ( kd1.isValid() && kd1.timeZone() != KTimeZone::utc() ) {
- zones.add( ICalTimeZone( kd1.timeZone() ) );
- }
+ if (kd1.isValid() && kd1.timeZone() != KTimeZone::utc()) {
+ zones.add(ICalTimeZone(kd1.timeZone()));
+ }
- if ( kd2.isValid() && kd2.timeZone() != KTimeZone::utc() ) {
- zones.add( ICalTimeZone( kd2.timeZone() ) );
- }
+ if (kd2.isValid() && kd2.timeZone() != KTimeZone::utc()) {
+ zones.add(ICalTimeZone(kd2.timeZone()));
+ }
- const ICalTimeZones::ZoneMap zmaps = zones.zones();
- for ( ICalTimeZones::ZoneMap::ConstIterator it=zmaps.constBegin();
- it != zmaps.constEnd(); ++it ) {
- icaltimezone *icaltz = (*it).icalTimezone();
- if ( !icaltz ) {
- qWarning() << "bad time zone";
- } else {
- icalcomponent *tz = icalcomponent_new_clone( icaltimezone_get_component( icaltz ) );
- icalcomponent_add_component( message, tz );
- icaltimezone_free( icaltz, 1 );
- }
+ const ICalTimeZones::ZoneMap zmaps = zones.zones();
+ for (ICalTimeZones::ZoneMap::ConstIterator it=zmaps.constBegin();
+ it != zmaps.constEnd(); ++it) {
+ icaltimezone *icaltz = (*it).icalTimezone();
+ if (!icaltz) {
+ kError() << "bad time zone";
+ } else {
+ icalcomponent *tz = icalcomponent_new_clone(icaltimezone_get_component(icaltz));
+ icalcomponent_add_component(message, tz);
+ icaltimezone_free(icaltz, 1);
+ }
+ }
+ } else {
+ kDebug() << "No incidence";
+ return message;
}
- } else {
- qDebug() << "No incidence";
- return message;
- }
- icalproperty_method icalmethod = ICAL_METHOD_NONE;
+ icalproperty_method icalmethod = ICAL_METHOD_NONE;
- switch (method) {
- case iTIPPublish:
- icalmethod = ICAL_METHOD_PUBLISH;
- break;
- case iTIPRequest:
- icalmethod = ICAL_METHOD_REQUEST;
- break;
- case iTIPRefresh:
- icalmethod = ICAL_METHOD_REFRESH;
- break;
- case iTIPCancel:
- icalmethod = ICAL_METHOD_CANCEL;
- break;
- case iTIPAdd:
- icalmethod = ICAL_METHOD_ADD;
- break;
- case iTIPReply:
- icalmethod = ICAL_METHOD_REPLY;
- break;
- case iTIPCounter:
- icalmethod = ICAL_METHOD_COUNTER;
- break;
- case iTIPDeclineCounter:
- icalmethod = ICAL_METHOD_DECLINECOUNTER;
- break;
- default:
- qDebug() << "Unknown method";
- return message;
- }
+ switch (method) {
+ case iTIPPublish:
+ icalmethod = ICAL_METHOD_PUBLISH;
+ break;
+ case iTIPRequest:
+ icalmethod = ICAL_METHOD_REQUEST;
+ break;
+ case iTIPRefresh:
+ icalmethod = ICAL_METHOD_REFRESH;
+ break;
+ case iTIPCancel:
+ icalmethod = ICAL_METHOD_CANCEL;
+ break;
+ case iTIPAdd:
+ icalmethod = ICAL_METHOD_ADD;
+ break;
+ case iTIPReply:
+ icalmethod = ICAL_METHOD_REPLY;
+ break;
+ case iTIPCounter:
+ icalmethod = ICAL_METHOD_COUNTER;
+ break;
+ case iTIPDeclineCounter:
+ icalmethod = ICAL_METHOD_DECLINECOUNTER;
+ break;
+ default:
+ kDebug() << "Unknown method";
+ return message;
+ }
- icalcomponent_add_property( message, icalproperty_new_method( icalmethod ) );
+ icalcomponent_add_property(message, icalproperty_new_method(icalmethod));
- icalcomponent *inc = writeIncidence( incidence, method );
+ icalcomponent *inc = writeIncidence(incidence, method);
- if ( method != KCalCore::iTIPNoMethod ) {
- //Not very nice, but since dtstamp changes semantics if used in scheduling, we have to adapt
- icalcomponent_set_dtstamp(
- inc, writeICalUtcDateTime( KDateTime::currentUtcDateTime() ) );
- }
+ if (method != KCalCore::iTIPNoMethod) {
+ //Not very nice, but since dtstamp changes semantics if used in scheduling, we have to adapt
+ icalcomponent_set_dtstamp(
+ inc, writeICalUtcDateTime(KDateTime::currentUtcDateTime()));
+ }
- /*
- * RFC 2446 states in section 3.4.3 ( REPLY to a VTODO ), that
- * a REQUEST-STATUS property has to be present. For the other two, event and
- * free busy, it can be there, but is optional. Until we do more
- * fine grained handling, assume all is well. Note that this is the
- * status of the _request_, not the attendee. Just to avoid confusion.
- * - till
- */
- if ( icalmethod == ICAL_METHOD_REPLY ) {
- struct icalreqstattype rst;
- rst.code = ICAL_2_0_SUCCESS_STATUS;
- rst.desc = 0;
- rst.debug = 0;
- icalcomponent_add_property( inc, icalproperty_new_requeststatus( rst ) );
- }
- icalcomponent_add_component( message, inc );
+ /*
+ * RFC 2446 states in section 3.4.3 ( REPLY to a VTODO ), that
+ * a REQUEST-STATUS property has to be present. For the other two, event and
+ * free busy, it can be there, but is optional. Until we do more
+ * fine grained handling, assume all is well. Note that this is the
+ * status of the _request_, not the attendee. Just to avoid confusion.
+ * - till
+ */
+ if (icalmethod == ICAL_METHOD_REPLY) {
+ struct icalreqstattype rst;
+ rst.code = ICAL_2_0_SUCCESS_STATUS;
+ rst.desc = 0;
+ rst.debug = 0;
+ icalcomponent_add_property(inc, icalproperty_new_requeststatus(rst));
+ }
+ icalcomponent_add_component(message, inc);
- return message;
+ return message;
}
diff --git a/kcalcore/icalformat_p.h b/kcalcore/icalformat_p.h
index 4d26950..dfb5047 100644
--- a/kcalcore/icalformat_p.h
+++ b/kcalcore/icalformat_p.h
@@ -4,6 +4,7 @@
Copyright (c) 2001-2003 Cornelius Schumacher <schumacher@kde.org>
Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
Copyright (c) 2006 David Jarvie <software@astrojar.org.uk>
+ Copyright (C) 2012 Christian Mollekopf <mollekopf@kolabsys.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
@@ -41,9 +42,9 @@
#include "calendar.h"
#include "schedulemessage.h"
-#include <kdatetime.h>
+#include <KDateTime>
-#include <ical.h>
+#include <libical/ical.h>
class QDate;
@@ -87,12 +88,12 @@ class Todo;
*/
class ICalFormatImpl
{
- public:
+public:
/**
Construct a new iCal format for calendar object.
@param parent is a pointer to a valid ICalFormat object.
*/
- explicit ICalFormatImpl( ICalFormat *parent );
+ explicit ICalFormatImpl(ICalFormat *parent);
/**
Destructor.
@@ -104,68 +105,70 @@ class ICalFormatImpl
existing in @p calendar are not affected except that if a new incidence
with the same UID is found, the existing incidence is replaced.
*/
- bool populate( const Calendar::Ptr &calendar, icalcomponent *fs,
- bool deleted = false, const QString &notebook = QString() );
-
- icalcomponent *writeIncidence( const IncidenceBase::Ptr &incidence,
- iTIPMethod method = iTIPRequest,
- ICalTimeZones *tzList = 0,
- ICalTimeZones *tzUsedList = 0 );
-
- icalcomponent *writeTodo( const Todo::Ptr &todo, ICalTimeZones *tzlist = 0,
- ICalTimeZones *tzUsedList = 0 );
-
- icalcomponent *writeEvent( const Event::Ptr &event, ICalTimeZones *tzlist = 0,
- ICalTimeZones *tzUsedList = 0 );
-
- icalcomponent *writeJournal( const Journal::Ptr &journal, ICalTimeZones *tzlist = 0,
- ICalTimeZones *tzUsedList = 0 );
-
- icalcomponent *writeFreeBusy( const FreeBusy::Ptr &freebusy,
- iTIPMethod method = iTIPPublish );
-
- void writeIncidence( icalcomponent *parent, const Incidence::Ptr &incidence,
- ICalTimeZones *tzlist = 0, ICalTimeZones *tzUsedList = 0 );
-
- icalproperty *writeDescription( const QString &description, bool isRich = false );
- icalproperty *writeSummary( const QString &summary, bool isRich = false );
- icalproperty *writeLocation( const QString &location, bool isRich = false );
- icalproperty *writeAttendee( const Attendee::Ptr &attendee );
- icalproperty *writeOrganizer( const Person::Ptr &organizer );
- icalproperty *writeAttachment( const Attachment::Ptr &attach );
- icalproperty *writeRecurrenceRule( Recurrence * );
- icalrecurrencetype writeRecurrenceRule( RecurrenceRule *recur );
- icalcomponent *writeAlarm( const Alarm::Ptr &alarm );
-
- QString extractErrorProperty( icalcomponent * );
- Todo::Ptr readTodo( icalcomponent *vtodo, ICalTimeZones *tzlist );
- Event::Ptr readEvent( icalcomponent *vevent, ICalTimeZones *tzlist );
- FreeBusy::Ptr readFreeBusy( icalcomponent *vfreebusy );
- Journal::Ptr readJournal( icalcomponent *vjournal, ICalTimeZones *tzlist );
- Attendee::Ptr readAttendee( icalproperty *attendee );
- Person::Ptr readOrganizer( icalproperty *organizer );
- Attachment::Ptr readAttachment( icalproperty *attach );
- void readIncidence( icalcomponent *parent, Incidence::Ptr incidence,
- ICalTimeZones *tzlist );
- void readRecurrenceRule( icalproperty *rrule, Incidence::Ptr event );
- void readExceptionRule( icalproperty *rrule, Incidence::Ptr incidence );
- void readRecurrence( const struct icalrecurrencetype &r,
- RecurrenceRule *recur );
- void readAlarm( icalcomponent *alarm, Incidence::Ptr incidence,
- ICalTimeZones *tzlist );
+ bool populate(const Calendar::Ptr &calendar, icalcomponent *fs,
+ bool deleted = false, const QString &notebook = QString());
+
+ Incidence::Ptr readOneIncidence(icalcomponent *calendar, ICalTimeZones *tzlist);
+
+ icalcomponent *writeIncidence(const IncidenceBase::Ptr &incidence,
+ iTIPMethod method = iTIPRequest,
+ ICalTimeZones *tzList = 0,
+ ICalTimeZones *tzUsedList = 0);
+
+ icalcomponent *writeTodo(const Todo::Ptr &todo, ICalTimeZones *tzlist = 0,
+ ICalTimeZones *tzUsedList = 0);
+
+ icalcomponent *writeEvent(const Event::Ptr &event, ICalTimeZones *tzlist = 0,
+ ICalTimeZones *tzUsedList = 0);
+
+ icalcomponent *writeJournal(const Journal::Ptr &journal, ICalTimeZones *tzlist = 0,
+ ICalTimeZones *tzUsedList = 0);
+
+ icalcomponent *writeFreeBusy(const FreeBusy::Ptr &freebusy,
+ iTIPMethod method = iTIPPublish);
+
+ void writeIncidence(icalcomponent *parent, const Incidence::Ptr &incidence,
+ ICalTimeZones *tzlist = 0, ICalTimeZones *tzUsedList = 0);
+
+ icalproperty *writeDescription(const QString &description, bool isRich = false);
+ icalproperty *writeSummary(const QString &summary, bool isRich = false);
+ icalproperty *writeLocation(const QString &location, bool isRich = false);
+ icalproperty *writeAttendee(const Attendee::Ptr &attendee);
+ icalproperty *writeOrganizer(const Person::Ptr &organizer);
+ icalproperty *writeAttachment(const Attachment::Ptr &attach);
+ icalproperty *writeRecurrenceRule(Recurrence *);
+ icalrecurrencetype writeRecurrenceRule(RecurrenceRule *recur);
+ icalcomponent *writeAlarm(const Alarm::Ptr &alarm);
+
+ QString extractErrorProperty(icalcomponent *);
+ Todo::Ptr readTodo(icalcomponent *vtodo, ICalTimeZones *tzlist);
+ Event::Ptr readEvent(icalcomponent *vevent, ICalTimeZones *tzlist);
+ FreeBusy::Ptr readFreeBusy(icalcomponent *vfreebusy);
+ Journal::Ptr readJournal(icalcomponent *vjournal, ICalTimeZones *tzlist);
+ Attendee::Ptr readAttendee(icalproperty *attendee);
+ Person::Ptr readOrganizer(icalproperty *organizer);
+ Attachment::Ptr readAttachment(icalproperty *attach);
+ void readIncidence(icalcomponent *parent, Incidence::Ptr incidence,
+ ICalTimeZones *tzlist);
+ void readRecurrenceRule(icalproperty *rrule, Incidence::Ptr event);
+ void readExceptionRule(icalproperty *rrule, Incidence::Ptr incidence);
+ void readRecurrence(const struct icalrecurrencetype &r,
+ RecurrenceRule *recur);
+ void readAlarm(icalcomponent *alarm, Incidence::Ptr incidence,
+ ICalTimeZones *tzlist);
/**
Returns the PRODID string loaded from calendar file.
*/
QString loadedProductId() const;
- static icaltimetype writeICalDate( const QDate & );
+ static icaltimetype writeICalDate(const QDate &);
static QDate readICalDate(icaltimetype);
- static icaltimetype writeICalDateTime( const KDateTime & );
+ static icaltimetype writeICalDateTime(const KDateTime &);
- static icaltimetype writeICalUtcDateTime( const KDateTime & );
+ static icaltimetype writeICalUtcDateTime(const KDateTime &);
/**
Creates an ical property from a date/time value.
@@ -182,10 +185,10 @@ class ICalFormatImpl
@return property, or null if error. It is the caller's responsibility
to free the returned property.
*/
- static icalproperty *writeICalDateTimeProperty( const icalproperty_kind kind,
- const KDateTime &dt,
- ICalTimeZones *tzlist = 0,
- ICalTimeZones *tzUsedList = 0 );
+ static icalproperty *writeICalDateTimeProperty(const icalproperty_kind kind,
+ const KDateTime &dt,
+ ICalTimeZones *tzlist = 0,
+ ICalTimeZones *tzUsedList = 0);
/**
Converts a date/time from ICal format.
@@ -199,8 +202,8 @@ class ICalFormatImpl
@param utc UTC date/time is expected
@return date/time, converted to UTC if @p utc is @c true
*/
- static KDateTime readICalDateTime( icalproperty *p, const icaltimetype &t,
- ICalTimeZones *tzlist, bool utc = false );
+ static KDateTime readICalDateTime(icalproperty *p, const icaltimetype &t,
+ ICalTimeZones *tzlist, bool utc = false);
/**
Converts a UTC date/time from ICal format.
@@ -211,9 +214,12 @@ class ICalFormatImpl
@param tzlist time zones collection
@return date/time, or invalid if @p t is not UTC
*/
- static KDateTime readICalUtcDateTime( icalproperty *p, icaltimetype &t,
- ICalTimeZones *tzlist = 0 )
- { return readICalDateTime( p, t, tzlist, true ); }
+ static KDateTime readICalUtcDateTime(icalproperty *p, icaltimetype &t,
+ ICalTimeZones *tzlist = 0)
+ //TODO: KDE5, move this implementation to icalformat_p.cpp
+ {
+ return readICalDateTime(p, t, tzlist, true);
+ }
/**
Reads a date or date/time value from a property.
@@ -225,31 +231,33 @@ class ICalFormatImpl
@return date or date/time, or invalid if property doesn't contain
a time value.
*/
- static KDateTime readICalDateTimeProperty( icalproperty *p,
- ICalTimeZones *tzlist, bool utc = false );
+ static KDateTime readICalDateTimeProperty(icalproperty *p,
+ ICalTimeZones *tzlist, bool utc = false);
/**
Reads a UTC date/time value from a property.
@param p is a pointer to a valid icalproperty structure.
*/
- static KDateTime readICalUtcDateTimeProperty( icalproperty *p )
- { return readICalDateTimeProperty( p, 0, true ); }
+ static KDateTime readICalUtcDateTimeProperty(icalproperty *p)
+ {
+ return readICalDateTimeProperty(p, 0, true);
+ }
- static icaldurationtype writeICalDuration( const Duration &duration );
+ static icaldurationtype writeICalDuration(const Duration &duration);
- static Duration readICalDuration( icaldurationtype d );
+ static Duration readICalDuration(icaldurationtype d);
- static icaldatetimeperiodtype writeICalDatePeriod( const QDate &date );
+ static icaldatetimeperiodtype writeICalDatePeriod(const QDate &date);
- icalcomponent *createCalendarComponent( const Calendar::Ptr &calendar = Calendar::Ptr() );
+ icalcomponent *createCalendarComponent(const Calendar::Ptr &calendar = Calendar::Ptr());
- icalcomponent *createScheduleComponent( const IncidenceBase::Ptr &incidence,
- iTIPMethod method );
+ icalcomponent *createScheduleComponent(const IncidenceBase::Ptr &incidence,
+ iTIPMethod method);
- protected:
+protected:
// void dumpIcalRecurrence( const icalrecurrencetype &r );
- private:
+private:
//@cond PRIVATE
class Private;
Private *const d;
diff --git a/kcalcore/incidence.cpp b/kcalcore/incidence.cpp
index 7b143e6..7abe2a4 100644
--- a/kcalcore/incidence.cpp
+++ b/kcalcore/incidence.cpp
@@ -34,11 +34,14 @@
#include "incidence.h"
#include "calformat.h"
-#include <QtCore/qtemporaryfile.h>
-#include <kmimetype.h>
+#include <KMimeType>
+#include <KTemporaryFile>
+#include <KDebug>
#include <QTextDocument> // for Qt::escape() and Qt::mightBeRichText()
+#include <QStringList>
+#include <QTime>
using namespace KCalCore;
@@ -49,97 +52,100 @@ using namespace KCalCore;
//@cond PRIVATE
class KCalCore::Incidence::Private
{
- public:
+public:
Private()
- : mRevision( 0 ),
- mDescriptionIsRich( false ),
- mSummaryIsRich( false ),
- mLocationIsRich( false ),
- mRecurrence( 0 ),
- mStatus( StatusNone ),
- mSecrecy( SecrecyPublic ),
- mPriority( 0 ),
- mGeoLatitude( INVALID_LATLON ),
- mGeoLongitude( INVALID_LATLON ),
- mHasGeo( false ),
- mLocalOnly( false )
+ : mRevision(0),
+ mDescriptionIsRich(false),
+ mSummaryIsRich(false),
+ mLocationIsRich(false),
+ mRecurrence(0),
+ mStatus(StatusNone),
+ mSecrecy(SecrecyPublic),
+ mPriority(0),
+ mGeoLatitude(INVALID_LATLON),
+ mGeoLongitude(INVALID_LATLON),
+ mHasGeo(false),
+ mThisAndFuture(false),
+ mLocalOnly(false)
{
}
- Private( const Private &p )
- : mCreated( p.mCreated ),
- mRevision( p.mRevision ),
- mDescription( p.mDescription ),
- mDescriptionIsRich( p.mDescriptionIsRich ),
- mSummary( p.mSummary ),
- mSummaryIsRich( p.mSummaryIsRich ),
- mLocation( p.mLocation ),
- mLocationIsRich( p.mLocationIsRich ),
- mCategories( p.mCategories ),
- mRecurrence ( 0 ),
- mResources( p.mResources ),
- mStatus( p.mStatus ),
- mStatusString( p.mStatusString ),
- mSecrecy( p.mSecrecy ),
- mPriority( p.mPriority ),
- mSchedulingID( p.mSchedulingID ),
- mRelatedToUid( p.mRelatedToUid ),
- mGeoLatitude( p.mGeoLatitude ),
- mGeoLongitude( p.mGeoLongitude ),
- mHasGeo( p.mHasGeo ),
- mRecurrenceId( p.mRecurrenceId ),
- mLocalOnly( false )
+ Private(const Private &p)
+ : mCreated(p.mCreated),
+ mRevision(p.mRevision),
+ mDescription(p.mDescription),
+ mDescriptionIsRich(p.mDescriptionIsRich),
+ mSummary(p.mSummary),
+ mSummaryIsRich(p.mSummaryIsRich),
+ mLocation(p.mLocation),
+ mLocationIsRich(p.mLocationIsRich),
+ mCategories(p.mCategories),
+ mRecurrence(0),
+ mResources(p.mResources),
+ mStatus(p.mStatus),
+ mStatusString(p.mStatusString),
+ mSecrecy(p.mSecrecy),
+ mPriority(p.mPriority),
+ mSchedulingID(p.mSchedulingID),
+ mRelatedToUid(p.mRelatedToUid),
+ mGeoLatitude(p.mGeoLatitude),
+ mGeoLongitude(p.mGeoLongitude),
+ mHasGeo(p.mHasGeo),
+ mRecurrenceId(p.mRecurrenceId),
+ mThisAndFuture(p.mThisAndFuture),
+ mLocalOnly(false)
{
}
void clear()
{
- mAlarms.clear();
- mAttachments.clear();
- delete mRecurrence;
- mRecurrence = 0;
+ mAlarms.clear();
+ mAttachments.clear();
+ delete mRecurrence;
+ mRecurrence = 0;
}
- void init( Incidence *dest, const Incidence &src )
+ void init(Incidence *dest, const Incidence &src)
{
- mRevision = src.d->mRevision;
- mCreated = src.d->mCreated;
- mDescription = src.d->mDescription;
- mSummary = src.d->mSummary;
- mCategories = src.d->mCategories;
- mRelatedToUid = src.d->mRelatedToUid;
- mResources = src.d->mResources;
- mStatusString = src.d->mStatusString;
- mStatus = src.d->mStatus;
- mSecrecy = src.d->mSecrecy;
- mPriority = src.d->mPriority;
- mLocation = src.d->mLocation;
- mGeoLatitude = src.d->mGeoLatitude;
- mGeoLongitude = src.d->mGeoLongitude;
- mHasGeo = src.d->mHasGeo;
- mRecurrenceId = src.d->mRecurrenceId;
- mLocalOnly = src.d->mLocalOnly;
-
- // Alarms and Attachments are stored in ListBase<...>, which is a QValueList<...*>.
- // We need to really duplicate the objects stored therein, otherwise deleting
- // i will also delete all attachments from this object (setAutoDelete...)
- foreach ( Alarm::Ptr alarm, src.d->mAlarms ) {
- Alarm::Ptr b ( new Alarm( *alarm.data() ) );
- b->setParent( dest );
- mAlarms.append( b );
- }
-
- foreach ( Attachment::Ptr attachment, src.d->mAttachments ) {
- Attachment::Ptr a( new Attachment( *attachment ) );
- mAttachments.append( a );
- }
-
- if ( src.d->mRecurrence ) {
- mRecurrence = new Recurrence( *( src.d->mRecurrence ) );
- mRecurrence->addObserver( dest );
- } else {
- mRecurrence = 0;
- }
+ mRevision = src.d->mRevision;
+ mCreated = src.d->mCreated;
+ mDescription = src.d->mDescription;
+ mSummary = src.d->mSummary;
+ mCategories = src.d->mCategories;
+ mRelatedToUid = src.d->mRelatedToUid;
+ mResources = src.d->mResources;
+ mStatusString = src.d->mStatusString;
+ mStatus = src.d->mStatus;
+ mSecrecy = src.d->mSecrecy;
+ mPriority = src.d->mPriority;
+ mLocation = src.d->mLocation;
+ mGeoLatitude = src.d->mGeoLatitude;
+ mGeoLongitude = src.d->mGeoLongitude;
+ mHasGeo = src.d->mHasGeo;
+ mRecurrenceId = src.d->mRecurrenceId;
+ mThisAndFuture = src.d->mThisAndFuture;
+ mLocalOnly = src.d->mLocalOnly;
+
+ // Alarms and Attachments are stored in ListBase<...>, which is a QValueList<...*>.
+ // We need to really duplicate the objects stored therein, otherwise deleting
+ // i will also delete all attachments from this object (setAutoDelete...)
+ foreach(Alarm::Ptr alarm, src.d->mAlarms) {
+ Alarm::Ptr b(new Alarm(*alarm.data()));
+ b->setParent(dest);
+ mAlarms.append(b);
+ }
+
+ foreach(Attachment::Ptr attachment, src.d->mAttachments) {
+ Attachment::Ptr a(new Attachment(*attachment));
+ mAttachments.append(a);
+ }
+
+ if (src.d->mRecurrence) {
+ mRecurrence = new Recurrence(*(src.d->mRecurrence));
+ mRecurrence->addObserver(dest);
+ } else {
+ mRecurrence = 0;
+ }
}
KDateTime mCreated; // creation datetime
@@ -168,183 +174,194 @@ class KCalCore::Incidence::Private
bool mHasGeo; // if incidence has geo data
QHash<Attachment::Ptr,QString> mTempFiles; // Temporary files for writing attachments to.
KDateTime mRecurrenceId; // recurrenceId
+ bool mThisAndFuture;
bool mLocalOnly; // allow changes that won't go to the server
};
//@endcond
Incidence::Incidence()
- : IncidenceBase(), d( new KCalCore::Incidence::Private )
+ : IncidenceBase(), d(new KCalCore::Incidence::Private)
{
- recreate();
- resetDirtyFields();
+ recreate();
+ resetDirtyFields();
}
-Incidence::Incidence( const Incidence &i )
- : IncidenceBase( i ),
- Recurrence::RecurrenceObserver(),
- d( new KCalCore::Incidence::Private( *i.d ) )
+Incidence::Incidence(const Incidence &i)
+ : IncidenceBase(i),
+ Recurrence::RecurrenceObserver(),
+ d(new KCalCore::Incidence::Private(*i.d))
{
- d->init( this, i );
- resetDirtyFields();
+ d->init(this, i);
+ resetDirtyFields();
}
Incidence::~Incidence()
{
- // Alarm has a raw incidence pointer, so we must set it to 0
- // so Alarm doesn't use it after Incidence is destroyed
- foreach ( Alarm::Ptr alarm, d->mAlarms ) {
- alarm->setParent( 0 );
- }
+ // Alarm has a raw incidence pointer, so we must set it to 0
+ // so Alarm doesn't use it after Incidence is destroyed
+ foreach(Alarm::Ptr alarm, d->mAlarms) {
+ alarm->setParent(0);
+ }
- delete d->mRecurrence;
- delete d;
+ delete d->mRecurrence;
+ delete d;
}
//@cond PRIVATE
// A string comparison that considers that null and empty are the same
-static bool stringCompare( const QString &s1, const QString &s2 )
+static bool stringCompare(const QString &s1, const QString &s2)
{
- return ( s1.isEmpty() && s2.isEmpty() ) || ( s1 == s2 );
+ return (s1.isEmpty() && s2.isEmpty()) || (s1 == s2);
}
//@endcond
-IncidenceBase &Incidence::assign( const IncidenceBase &other )
-{
- if ( &other != this ) {
- d->clear();
- //TODO: should relations be cleared out, as in destructor???
- IncidenceBase::assign( other );
- const Incidence *i = static_cast<const Incidence*>( &other );
- d->init( this, *i );
- }
+IncidenceBase &Incidence::assign(const IncidenceBase &other)
+{
+ if (&other != this) {
+ d->clear();
+ //TODO: should relations be cleared out, as in destructor???
+ IncidenceBase::assign(other);
+ const Incidence *i = static_cast<const Incidence*>(&other);
+ d->init(this, *i);
+ }
- return *this;
+ return *this;
}
-bool Incidence::equals( const IncidenceBase &incidence ) const
+bool Incidence::equals(const IncidenceBase &incidence) const
{
- if ( !IncidenceBase::equals( incidence ) ) {
- return false;
- }
+ if (!IncidenceBase::equals(incidence)) {
+ return false;
+ }
- // If they weren't the same type IncidenceBase::equals would had returned false already
- const Incidence *i2 = static_cast<const Incidence *>( &incidence );
+ // If they weren't the same type IncidenceBase::equals would had returned false already
+ const Incidence *i2 = static_cast<const Incidence *>(&incidence);
- if ( alarms().count() != i2->alarms().count() ) {
- return false;
- }
-
- Alarm::List::ConstIterator a1 = alarms().constBegin();
- Alarm::List::ConstIterator a1end = alarms().constEnd();
- Alarm::List::ConstIterator a2 = i2->alarms().constBegin();
- Alarm::List::ConstIterator a2end = i2->alarms().constEnd();
- for ( ; a1 != a1end && a2 != a2end; ++a1, ++a2 ) {
- if ( **a1 == **a2 ) {
- continue;
- } else {
- return false;
+ if (alarms().count() != i2->alarms().count()) {
+ return false;
}
- }
- if ( attachments().count() != i2->attachments().count() ) {
- return false;
- }
-
- Attachment::List::ConstIterator att1 = attachments().constBegin();
- const Attachment::List::ConstIterator att1end = attachments().constEnd();
- Attachment::List::ConstIterator att2 = i2->attachments().constBegin();
- const Attachment::List::ConstIterator att2end = i2->attachments().constEnd();
- for ( ; att1 != att1end && att2 != att2end; ++att1, ++att2 ) {
- if ( **att1 == **att2 ) {
- continue;
- } else {
- return false;
- }
- }
-
- bool recurrenceEqual = ( d->mRecurrence == 0 && i2->d->mRecurrence == 0 );
- if ( !recurrenceEqual ) {
- recurrence(); // create if doesn't exist
- i2->recurrence(); // create if doesn't exist
- recurrenceEqual = d->mRecurrence != 0 &&
- i2->d->mRecurrence != 0 &&
- *d->mRecurrence == *i2->d->mRecurrence;
- }
-
- return
- recurrenceEqual &&
- created() == i2->created() &&
- stringCompare( description(), i2->description() ) &&
- stringCompare( summary(), i2->summary() ) &&
- categories() == i2->categories() &&
- stringCompare( relatedTo(), i2->relatedTo() ) &&
- resources() == i2->resources() &&
- d->mStatus == i2->d->mStatus &&
- ( d->mStatus == StatusNone ||
- stringCompare( d->mStatusString, i2->d->mStatusString ) ) &&
- secrecy() == i2->secrecy() &&
- priority() == i2->priority() &&
- stringCompare( location(), i2->location() ) &&
- stringCompare( schedulingID(), i2->schedulingID() );
+ Alarm::List::ConstIterator a1 = alarms().constBegin();
+ Alarm::List::ConstIterator a1end = alarms().constEnd();
+ Alarm::List::ConstIterator a2 = i2->alarms().constBegin();
+ Alarm::List::ConstIterator a2end = i2->alarms().constEnd();
+ for (; a1 != a1end && a2 != a2end; ++a1, ++a2) {
+ if (**a1 == **a2) {
+ continue;
+ } else {
+ return false;
+ }
+ }
+
+ if (attachments().count() != i2->attachments().count()) {
+ return false;
+ }
+
+ Attachment::List::ConstIterator att1 = attachments().constBegin();
+ const Attachment::List::ConstIterator att1end = attachments().constEnd();
+ Attachment::List::ConstIterator att2 = i2->attachments().constBegin();
+ const Attachment::List::ConstIterator att2end = i2->attachments().constEnd();
+ for (; att1 != att1end && att2 != att2end; ++att1, ++att2) {
+ if (**att1 == **att2) {
+ continue;
+ } else {
+ return false;
+ }
+ }
+
+ bool recurrenceEqual = (d->mRecurrence == 0 && i2->d->mRecurrence == 0);
+ if (!recurrenceEqual) {
+ recurrence(); // create if doesn't exist
+ i2->recurrence(); // create if doesn't exist
+ recurrenceEqual = d->mRecurrence != 0 &&
+ i2->d->mRecurrence != 0 &&
+ *d->mRecurrence == *i2->d->mRecurrence;
+ }
+
+ return
+ recurrenceEqual &&
+ created() == i2->created() &&
+ stringCompare(description(), i2->description()) &&
+ stringCompare(summary(), i2->summary()) &&
+ categories() == i2->categories() &&
+ stringCompare(relatedTo(), i2->relatedTo()) &&
+ resources() == i2->resources() &&
+ d->mStatus == i2->d->mStatus &&
+ (d->mStatus == StatusNone ||
+ stringCompare(d->mStatusString, i2->d->mStatusString)) &&
+ secrecy() == i2->secrecy() &&
+ priority() == i2->priority() &&
+ stringCompare(location(), i2->location()) &&
+ stringCompare(schedulingID(), i2->schedulingID()) &&
+ recurrenceId() == i2->recurrenceId() &&
+ thisAndFuture() == i2->thisAndFuture();
+}
+
+QString Incidence::instanceIdentifier() const
+{
+ if (hasRecurrenceId()) {
+ return uid() + recurrenceId().toString();
+ }
+ return uid();
}
void Incidence::recreate()
{
- const KDateTime nowUTC = KDateTime::currentUtcDateTime();
- setCreated( nowUTC );
+ const KDateTime nowUTC = KDateTime::currentUtcDateTime();
+ setCreated(nowUTC);
- setSchedulingID( QString(), CalFormat::createUniqueId() );
- setRevision( 0 );
- setLastModified( nowUTC );
+ setSchedulingID(QString(), CalFormat::createUniqueId());
+ setRevision(0);
+ setLastModified(nowUTC);
}
-void Incidence::setLastModified( const KDateTime &lm )
+void Incidence::setLastModified(const KDateTime &lm)
{
- if ( !d->mLocalOnly ) {
- IncidenceBase::setLastModified( lm );
- }
+ if (!d->mLocalOnly) {
+ IncidenceBase::setLastModified(lm);
+ }
}
-void Incidence::setReadOnly( bool readOnly )
+void Incidence::setReadOnly(bool readOnly)
{
- IncidenceBase::setReadOnly( readOnly );
- if ( d->mRecurrence ) {
- d->mRecurrence->setRecurReadOnly( readOnly );
- }
+ IncidenceBase::setReadOnly(readOnly);
+ if (d->mRecurrence) {
+ d->mRecurrence->setRecurReadOnly(readOnly);
+ }
}
-void Incidence::setLocalOnly( bool localOnly )
+void Incidence::setLocalOnly(bool localOnly)
{
- if ( mReadOnly ) {
- return;
+ if (mReadOnly) {
+ return;
}
d->mLocalOnly = localOnly;
}
bool Incidence::localOnly() const
{
- return d->mLocalOnly;
+ return d->mLocalOnly;
}
-void Incidence::setAllDay( bool allDay )
+void Incidence::setAllDay(bool allDay)
{
- if ( mReadOnly ) {
- return;
- }
- if ( d->mRecurrence ) {
- d->mRecurrence->setAllDay( allDay );
- }
- IncidenceBase::setAllDay( allDay );
+ if (mReadOnly) {
+ return;
+ }
+ if (d->mRecurrence) {
+ d->mRecurrence->setAllDay(allDay);
+ }
+ IncidenceBase::setAllDay(allDay);
}
-void Incidence::setCreated( const KDateTime &created )
+void Incidence::setCreated(const KDateTime &created)
{
- if ( mReadOnly || d->mLocalOnly ) {
- return;
- }
+ if (mReadOnly || d->mLocalOnly) {
+ return;
+ }
- d->mCreated = created.toUtc();
- setFieldDirty( FieldCreated );
+ d->mCreated = created.toUtc();
+ setFieldDirty(FieldCreated);
// FIXME: Shouldn't we call updated for the creation date, too?
// updated();
@@ -352,729 +369,819 @@ void Incidence::setCreated( const KDateTime &created )
KDateTime Incidence::created() const
{
- return d->mCreated;
+ return d->mCreated;
}
-void Incidence::setRevision( int rev )
+void Incidence::setRevision(int rev)
{
- if ( mReadOnly || d->mLocalOnly ) {
- return;
- }
+ if (mReadOnly || d->mLocalOnly) {
+ return;
+ }
- update();
+ update();
- d->mRevision = rev;
- setFieldDirty( FieldRevision );
- updated();
+ d->mRevision = rev;
+ setFieldDirty(FieldRevision);
+ updated();
}
int Incidence::revision() const
{
- return d->mRevision;
+ return d->mRevision;
}
-void Incidence::setDtStart( const KDateTime &dt )
+void Incidence::setDtStart(const KDateTime &dt)
{
- if ( d->mRecurrence ) {
- d->mRecurrence->setStartDateTime( dt );
- d->mRecurrence->setAllDay( allDay() );
- }
- IncidenceBase::setDtStart( dt );
+ if (d->mRecurrence) {
+ d->mRecurrence->setStartDateTime(dt);
+ }
+ IncidenceBase::setDtStart(dt);
}
-void Incidence::shiftTimes( const KDateTime::Spec &oldSpec,
- const KDateTime::Spec &newSpec )
+void Incidence::shiftTimes(const KDateTime::Spec &oldSpec,
+ const KDateTime::Spec &newSpec)
{
- IncidenceBase::shiftTimes( oldSpec, newSpec );
- if ( d->mRecurrence ) {
- d->mRecurrence->shiftTimes( oldSpec, newSpec );
- }
- for ( int i = 0, end = d->mAlarms.count(); i < end; ++i ) {
- d->mAlarms[i]->shiftTimes( oldSpec, newSpec );
- }
+ IncidenceBase::shiftTimes(oldSpec, newSpec);
+ if (d->mRecurrence) {
+ d->mRecurrence->shiftTimes(oldSpec, newSpec);
+ }
+ for (int i = 0, end = d->mAlarms.count(); i < end; ++i) {
+ d->mAlarms[i]->shiftTimes(oldSpec, newSpec);
+ }
}
-void Incidence::setDescription( const QString &description, bool isRich )
+void Incidence::setDescription(const QString &description, bool isRich)
{
- if ( mReadOnly ) {
- return;
- }
- update();
- d->mDescription = description;
- d->mDescriptionIsRich = isRich;
- setFieldDirty( FieldDescription );
- updated();
+ if (mReadOnly) {
+ return;
+ }
+ update();
+ d->mDescription = description;
+ d->mDescriptionIsRich = isRich;
+ setFieldDirty(FieldDescription);
+ updated();
}
-void Incidence::setDescription( const QString &description )
+void Incidence::setDescription(const QString &description)
{
- setDescription( description, Qt::mightBeRichText( description ) );
+ setDescription(description, Qt::mightBeRichText(description));
}
QString Incidence::description() const
{
- return d->mDescription;
+ return d->mDescription;
}
QString Incidence::richDescription() const
{
- if ( descriptionIsRich() ) {
- return d->mDescription;
- } else {
- return Qt::escape( d->mDescription ).replace( '\n', "<br/>" );
- }
+ if (descriptionIsRich()) {
+ return d->mDescription;
+ } else {
+ return Qt::escape(d->mDescription).replace(QLatin1Char('\n'), QLatin1String("<br/>"));
+ }
}
bool Incidence::descriptionIsRich() const
{
- return d->mDescriptionIsRich;
+ return d->mDescriptionIsRich;
}
-void Incidence::setSummary( const QString &summary, bool isRich )
+void Incidence::setSummary(const QString &summary, bool isRich)
{
- if ( mReadOnly ) {
- return;
- }
- update();
- d->mSummary = summary;
- d->mSummaryIsRich = isRich;
- setFieldDirty( FieldSummary );
- updated();
+ if (mReadOnly) {
+ return;
+ }
+ update();
+ d->mSummary = summary;
+ d->mSummaryIsRich = isRich;
+ setFieldDirty(FieldSummary);
+ updated();
}
-void Incidence::setSummary( const QString &summary )
+void Incidence::setSummary(const QString &summary)
{
- setSummary( summary, Qt::mightBeRichText( summary ) );
+ setSummary(summary, Qt::mightBeRichText(summary));
}
QString Incidence::summary() const
{
- return d->mSummary;
+ return d->mSummary;
}
QString Incidence::richSummary() const
{
- if ( summaryIsRich() ) {
- return d->mSummary;
- } else {
- return Qt::escape( d->mSummary ).replace( '\n', "<br/>" );
- }
+ if (summaryIsRich()) {
+ return d->mSummary;
+ } else {
+ return Qt::escape(d->mSummary).replace(QLatin1Char('\n'), QLatin1String("<br/>"));
+ }
}
bool Incidence::summaryIsRich() const
{
- return d->mSummaryIsRich;
+ return d->mSummaryIsRich;
}
-void Incidence::setCategories( const QStringList &categories )
+void Incidence::setCategories(const QStringList &categories)
{
- if ( mReadOnly ) {
- return;
- }
+ if (mReadOnly) {
+ return;
+ }
- update();
- d->mCategories = categories;
- updated();
+ update();
+ d->mCategories = categories;
+ updated();
}
-void Incidence::setCategories( const QString &catStr )
+void Incidence::setCategories(const QString &catStr)
{
- if ( mReadOnly ) {
- return;
- }
- update();
- setFieldDirty( FieldCategories );
+ if (mReadOnly) {
+ return;
+ }
+ update();
+ setFieldDirty(FieldCategories);
- d->mCategories.clear();
+ d->mCategories.clear();
- if ( catStr.isEmpty() ) {
- updated();
- return;
- }
+ if (catStr.isEmpty()) {
+ updated();
+ return;
+ }
- d->mCategories = catStr.split( ',' );
+ d->mCategories = catStr.split(QLatin1Char(','));
- QStringList::Iterator it;
- for ( it = d->mCategories.begin();it != d->mCategories.end(); ++it ) {
- *it = (*it).trimmed();
- }
+ QStringList::Iterator it;
+ for (it = d->mCategories.begin(); it != d->mCategories.end(); ++it) {
+ *it = (*it).trimmed();
+ }
- updated();
+ updated();
}
QStringList Incidence::categories() const
{
- return d->mCategories;
+ return d->mCategories;
}
QString Incidence::categoriesStr() const
{
- return d->mCategories.join( "," );
+ return d->mCategories.join(QLatin1String(","));
}
-void Incidence::setRelatedTo( const QString &relatedToUid, RelType relType )
+void Incidence::setRelatedTo(const QString &relatedToUid, RelType relType)
{
- // TODO: RFC says that an incidence can have more than one related-to field
- // even for the same relType.
+ // TODO: RFC says that an incidence can have more than one related-to field
+ // even for the same relType.
- if ( d->mRelatedToUid[relType] != relatedToUid ) {
- update();
- d->mRelatedToUid[relType] = relatedToUid;
- setFieldDirty( FieldRelatedTo );
- updated();
- }
+ if (d->mRelatedToUid[relType] != relatedToUid) {
+ update();
+ d->mRelatedToUid[relType] = relatedToUid;
+ setFieldDirty(FieldRelatedTo);
+ updated();
+ }
}
-QString Incidence::relatedTo( RelType relType ) const
+QString Incidence::relatedTo(RelType relType) const
{
- return d->mRelatedToUid.value( relType );
+ return d->mRelatedToUid.value(relType);
}
// %%%%%%%%%%%% Recurrence-related methods %%%%%%%%%%%%%%%%%%%%
Recurrence *Incidence::recurrence() const
{
- if ( !d->mRecurrence ) {
- d->mRecurrence = new Recurrence();
- d->mRecurrence->setStartDateTime( IncidenceBase::dtStart() );
- d->mRecurrence->setAllDay( allDay() );
- d->mRecurrence->setRecurReadOnly( mReadOnly );
- d->mRecurrence->addObserver( const_cast<KCalCore::Incidence*>( this ) );
- }
+ if (!d->mRecurrence) {
+ d->mRecurrence = new Recurrence();
+ d->mRecurrence->setStartDateTime(dateTime(RoleRecurrenceStart));
+ d->mRecurrence->setAllDay(allDay());
+ d->mRecurrence->setRecurReadOnly(mReadOnly);
+ d->mRecurrence->addObserver(const_cast<KCalCore::Incidence*>(this));
+ }
- return d->mRecurrence;
+ return d->mRecurrence;
}
void Incidence::clearRecurrence()
{
- delete d->mRecurrence;
- d->mRecurrence = 0;
+ delete d->mRecurrence;
+ d->mRecurrence = 0;
}
ushort Incidence::recurrenceType() const
{
- if ( d->mRecurrence ) {
- return d->mRecurrence->recurrenceType();
- } else {
- return Recurrence::rNone;
- }
+ if (d->mRecurrence) {
+ return d->mRecurrence->recurrenceType();
+ } else {
+ return Recurrence::rNone;
+ }
}
bool Incidence::recurs() const
{
- if ( d->mRecurrence ) {
- return d->mRecurrence->recurs();
- } else {
- return false;
- }
+ if (d->mRecurrence) {
+ return d->mRecurrence->recurs();
+ } else {
+ return false;
+ }
}
-bool Incidence::recursOn( const QDate &date,
- const KDateTime::Spec &timeSpec ) const
+bool Incidence::recursOn(const QDate &date,
+ const KDateTime::Spec &timeSpec) const
{
- return d->mRecurrence && d->mRecurrence->recursOn( date, timeSpec );
+ return d->mRecurrence && d->mRecurrence->recursOn(date, timeSpec);
}
-bool Incidence::recursAt( const KDateTime &qdt ) const
+bool Incidence::recursAt(const KDateTime &qdt) const
{
- return d->mRecurrence && d->mRecurrence->recursAt( qdt );
+ return d->mRecurrence && d->mRecurrence->recursAt(qdt);
}
-QList<KDateTime> Incidence::startDateTimesForDate( const QDate &date,
- const KDateTime::Spec &timeSpec ) const
+QList<KDateTime> Incidence::startDateTimesForDate(const QDate &date,
+ const KDateTime::Spec &timeSpec) const
{
- KDateTime start = dtStart();
- KDateTime end = dateTime( RoleEndRecurrenceBase );
+ KDateTime start = dtStart();
+ KDateTime end = dateTime(RoleEndRecurrenceBase);
- QList<KDateTime> result;
+ QList<KDateTime> result;
- // TODO_Recurrence: Also work if only due date is given...
- if ( !start.isValid() && ! end.isValid() ) {
- return result;
- }
+ // TODO_Recurrence: Also work if only due date is given...
+ if (!start.isValid() && ! end.isValid()) {
+ return result;
+ }
- // if the incidence doesn't recur,
- KDateTime kdate( date, timeSpec );
- if ( !recurs() ) {
- if ( !( start > kdate || end < kdate ) ) {
- result << start;
+ // if the incidence doesn't recur,
+ KDateTime kdate(date, timeSpec);
+ if (!recurs()) {
+ if (!(start > kdate || end < kdate)) {
+ result << start;
+ }
+ return result;
}
- return result;
- }
-
- int days = start.daysTo( end );
- // Account for possible recurrences going over midnight, while the original event doesn't
- QDate tmpday( date.addDays( -days - 1 ) );
- KDateTime tmp;
- while ( tmpday <= date ) {
- if ( recurrence()->recursOn( tmpday, timeSpec ) ) {
- QList<QTime> times = recurrence()->recurTimesOn( tmpday, timeSpec );
- foreach ( const QTime &time, times ) {
- tmp = KDateTime( tmpday, time, start.timeSpec() );
- if ( endDateForStart( tmp ) >= kdate ) {
- result << tmp;
+
+ int days = start.daysTo(end);
+ // Account for possible recurrences going over midnight, while the original event doesn't
+ QDate tmpday(date.addDays(-days - 1));
+ KDateTime tmp;
+ while (tmpday <= date) {
+ if (recurrence()->recursOn(tmpday, timeSpec)) {
+ QList<QTime> times = recurrence()->recurTimesOn(tmpday, timeSpec);
+ foreach(const QTime &time, times) {
+ tmp = KDateTime(tmpday, time, start.timeSpec());
+ if (endDateForStart(tmp) >= kdate) {
+ result << tmp;
+ }
+ }
}
- }
+ tmpday = tmpday.addDays(1);
}
- tmpday = tmpday.addDays( 1 );
- }
- return result;
+ return result;
}
-QList<KDateTime> Incidence::startDateTimesForDateTime( const KDateTime &datetime ) const
+QList<KDateTime> Incidence::startDateTimesForDateTime(const KDateTime &datetime) const
{
- KDateTime start = dtStart();
- KDateTime end = dateTime( RoleEndRecurrenceBase );
+ KDateTime start = dtStart();
+ KDateTime end = dateTime(RoleEndRecurrenceBase);
- QList<KDateTime> result;
+ QList<KDateTime> result;
- // TODO_Recurrence: Also work if only due date is given...
- if ( !start.isValid() && ! end.isValid() ) {
- return result;
- }
+ // TODO_Recurrence: Also work if only due date is given...
+ if (!start.isValid() && ! end.isValid()) {
+ return result;
+ }
- // if the incidence doesn't recur,
- if ( !recurs() ) {
- if ( !( start > datetime || end < datetime ) ) {
- result << start;
+ // if the incidence doesn't recur,
+ if (!recurs()) {
+ if (!(start > datetime || end < datetime)) {
+ result << start;
+ }
+ return result;
}
- return result;
- }
-
- int days = start.daysTo( end );
- // Account for possible recurrences going over midnight, while the original event doesn't
- QDate tmpday( datetime.date().addDays( -days - 1 ) );
- KDateTime tmp;
- while ( tmpday <= datetime.date() ) {
- if ( recurrence()->recursOn( tmpday, datetime.timeSpec() ) ) {
- // Get the times during the day (in start date's time zone) when recurrences happen
- QList<QTime> times = recurrence()->recurTimesOn( tmpday, start.timeSpec() );
- foreach ( const QTime &time, times ) {
- tmp = KDateTime( tmpday, time, start.timeSpec() );
- if ( !( tmp > datetime || endDateForStart( tmp ) < datetime ) ) {
- result << tmp;
+
+ int days = start.daysTo(end);
+ // Account for possible recurrences going over midnight, while the original event doesn't
+ QDate tmpday(datetime.date().addDays(-days - 1));
+ KDateTime tmp;
+ while (tmpday <= datetime.date()) {
+ if (recurrence()->recursOn(tmpday, datetime.timeSpec())) {
+ // Get the times during the day (in start date's time zone) when recurrences happen
+ QList<QTime> times = recurrence()->recurTimesOn(tmpday, start.timeSpec());
+ foreach(const QTime &time, times) {
+ tmp = KDateTime(tmpday, time, start.timeSpec());
+ if (!(tmp > datetime || endDateForStart(tmp) < datetime)) {
+ result << tmp;
+ }
+ }
}
- }
+ tmpday = tmpday.addDays(1);
}
- tmpday = tmpday.addDays( 1 );
- }
- return result;
+ return result;
}
-KDateTime Incidence::endDateForStart( const KDateTime &startDt ) const
+KDateTime Incidence::endDateForStart(const KDateTime &startDt) const
{
- KDateTime start = dtStart();
- KDateTime end = dateTime( RoleEndRecurrenceBase );
- if ( !end.isValid() ) {
- return start;
- }
- if ( !start.isValid() ) {
- return end;
- }
+ KDateTime start = dtStart();
+ KDateTime end = dateTime(RoleEndRecurrenceBase);
+ if (!end.isValid()) {
+ return start;
+ }
+ if (!start.isValid()) {
+ return end;
+ }
- return startDt.addSecs( start.secsTo( end ) );
+ return startDt.addSecs(start.secsTo(end));
}
-void Incidence::addAttachment( const Attachment::Ptr &attachment )
+void Incidence::addAttachment(const Attachment::Ptr &attachment)
{
- if ( mReadOnly || !attachment ) {
- return;
- }
+ if (mReadOnly || !attachment) {
+ return;
+ }
- Q_ASSERT( !d->mAttachments.contains( attachment ) );
+ Q_ASSERT(!d->mAttachments.contains(attachment));
- update();
- d->mAttachments.append( attachment );
- setFieldDirty( FieldAttachment );
- updated();
+ update();
+ d->mAttachments.append(attachment);
+ setFieldDirty(FieldAttachment);
+ updated();
}
-void Incidence::deleteAttachment( const Attachment::Ptr &attachment )
+void Incidence::deleteAttachment(const Attachment::Ptr &attachment)
{
- int index = d->mAttachments.indexOf( attachment );
- if ( index > -1 ) {
- setFieldDirty( FieldAttachment );
- d->mAttachments.remove( index );
- }
+ int index = d->mAttachments.indexOf(attachment);
+ if (index > -1) {
+ setFieldDirty(FieldAttachment);
+ d->mAttachments.remove(index);
+ }
}
-void Incidence::deleteAttachments( const QString &mime )
+void Incidence::deleteAttachments(const QString &mime)
{
- Attachment::List result;
- Attachment::List::Iterator it = d->mAttachments.begin();
- while ( it != d->mAttachments.end() ) {
- if ( (*it)->mimeType() != mime ) {
- result += *it;
+ Attachment::List result;
+ Attachment::List::Iterator it = d->mAttachments.begin();
+ while (it != d->mAttachments.end()) {
+ if ((*it)->mimeType() != mime) {
+ result += *it;
+ }
+ ++it;
}
- ++it;
- }
- d->mAttachments = result;
- setFieldDirty( FieldAttachment );
+ d->mAttachments = result;
+ setFieldDirty(FieldAttachment);
}
Attachment::List Incidence::attachments() const
{
- return d->mAttachments;
+ return d->mAttachments;
}
-Attachment::List Incidence::attachments( const QString &mime ) const
+Attachment::List Incidence::attachments(const QString &mime) const
{
- Attachment::List attachments;
- foreach ( Attachment::Ptr attachment, d->mAttachments ) {
- if ( attachment->mimeType() == mime ) {
- attachments.append( attachment );
+ Attachment::List attachments;
+ foreach(Attachment::Ptr attachment, d->mAttachments) {
+ if (attachment->mimeType() == mime) {
+ attachments.append(attachment);
+ }
}
- }
- return attachments;
+ return attachments;
}
void Incidence::clearAttachments()
{
- setFieldDirty( FieldAttachment );
- d->mAttachments.clear();
+ setFieldDirty(FieldAttachment);
+ d->mAttachments.clear();
}
-QString Incidence::writeAttachmentToTempFile( const Attachment::Ptr &attachment ) const
+QString Incidence::writeAttachmentToTempFile(const Attachment::Ptr &attachment) const
{
- if ( d->mTempFiles.contains( attachment ) ) {
- return d->mTempFiles.value( attachment );
- }
- QTemporaryFile *file = new QTemporaryFile();
+ if (d->mTempFiles.contains(attachment)) {
+ return d->mTempFiles.value(attachment);
+ }
+ KTemporaryFile *file = new KTemporaryFile();
- QStringList patterns = KMimeType::mimeType( attachment->mimeType() )->patterns();
+ QStringList patterns = KMimeType::mimeType(attachment->mimeType())->patterns();
- if ( !patterns.empty() ) {
- file->setFileTemplate(QLatin1String("XXXXXX.")+QString( patterns.first() ).remove( '*' ));
- }
- file->setAutoRemove( true );
- file->open();
- // read-only not to give the idea that it could be written to
- file->setPermissions( QFile::ReadUser );
- file->write( QByteArray::fromBase64( attachment->data() ) );
- d->mTempFiles.insert( attachment, file->fileName() );
- file->close();
- return d->mTempFiles.value( attachment );
+ if (!patterns.empty()) {
+ file->setSuffix(QString(patterns.first()).remove(QLatin1Char('*')));
+ }
+ file->setAutoRemove(true);
+ file->open();
+ // read-only not to give the idea that it could be written to
+ file->setPermissions(QFile::ReadUser);
+ file->write(QByteArray::fromBase64(attachment->data()));
+ d->mTempFiles.insert(attachment, file->fileName());
+ file->close();
+ return d->mTempFiles.value(attachment);
}
void Incidence::clearTempFiles()
{
- QHash<Attachment::Ptr,QString>::const_iterator it = d->mTempFiles.constBegin();
- const QHash<Attachment::Ptr,QString>::const_iterator end = d->mTempFiles.constEnd();
- for ( ; it != end; ++it ) {
- QFile::remove( it.value() );
- }
- d->mTempFiles.clear();
+ QHash<Attachment::Ptr,QString>::const_iterator it = d->mTempFiles.constBegin();
+ const QHash<Attachment::Ptr,QString>::const_iterator end = d->mTempFiles.constEnd();
+ for (; it != end; ++it) {
+ QFile::remove(it.value());
+ }
+ d->mTempFiles.clear();
}
-void Incidence::setResources( const QStringList &resources )
+void Incidence::setResources(const QStringList &resources)
{
- if ( mReadOnly ) {
- return;
- }
+ if (mReadOnly) {
+ return;
+ }
- update();
- d->mResources = resources;
- setFieldDirty( FieldResources );
- updated();
+ update();
+ d->mResources = resources;
+ setFieldDirty(FieldResources);
+ updated();
}
QStringList Incidence::resources() const
{
- return d->mResources;
+ return d->mResources;
}
-void Incidence::setPriority( int priority )
+void Incidence::setPriority(int priority)
{
- if ( mReadOnly ) {
- return;
- }
+ if (mReadOnly) {
+ return;
+ }
- update();
- d->mPriority = priority;
- setFieldDirty( FieldPriority );
- updated();
+ update();
+ d->mPriority = priority;
+ setFieldDirty(FieldPriority);
+ updated();
}
int Incidence::priority() const
{
- return d->mPriority;
+ return d->mPriority;
}
-void Incidence::setStatus( Incidence::Status status )
+void Incidence::setStatus(Incidence::Status status)
{
- if ( mReadOnly || status == StatusX ) {
- return;
- }
+ if (mReadOnly || status == StatusX) {
+ return;
+ }
- update();
- d->mStatus = status;
- d->mStatusString.clear();
- setFieldDirty( FieldStatus );
- updated();
+ update();
+ d->mStatus = status;
+ d->mStatusString.clear();
+ setFieldDirty(FieldStatus);
+ updated();
}
-void Incidence::setCustomStatus( const QString &status )
+void Incidence::setCustomStatus(const QString &status)
{
- if ( mReadOnly ) {
- return;
- }
+ if (mReadOnly) {
+ return;
+ }
- update();
- d->mStatus = status.isEmpty() ? StatusNone : StatusX;
- d->mStatusString = status;
- setFieldDirty( FieldStatus );
- updated();
+ update();
+ d->mStatus = status.isEmpty() ? StatusNone : StatusX;
+ d->mStatusString = status;
+ setFieldDirty(FieldStatus);
+ updated();
}
Incidence::Status Incidence::status() const
{
- return d->mStatus;
+ return d->mStatus;
}
QString Incidence::customStatus() const
{
- if ( d->mStatus == StatusX ) {
- return d->mStatusString;
- } else {
- return QString();
- }
+ if (d->mStatus == StatusX) {
+ return d->mStatusString;
+ } else {
+ return QString();
+ }
}
-void Incidence::setSecrecy( Incidence::Secrecy secrecy )
+void Incidence::setSecrecy(Incidence::Secrecy secrecy)
{
- if ( mReadOnly ) {
- return;
- }
+ if (mReadOnly) {
+ return;
+ }
- update();
- d->mSecrecy = secrecy;
- setFieldDirty( FieldSecrecy );
- updated();
+ update();
+ d->mSecrecy = secrecy;
+ setFieldDirty(FieldSecrecy);
+ updated();
}
Incidence::Secrecy Incidence::secrecy() const
{
- return d->mSecrecy;
+ return d->mSecrecy;
}
Alarm::List Incidence::alarms() const
{
- return d->mAlarms;
+ return d->mAlarms;
}
Alarm::Ptr Incidence::newAlarm()
{
- Alarm::Ptr alarm( new Alarm( this ) );
- d->mAlarms.append( alarm );
- return alarm;
+ Alarm::Ptr alarm(new Alarm(this));
+ d->mAlarms.append(alarm);
+ return alarm;
}
-void Incidence::addAlarm( const Alarm::Ptr &alarm )
+void Incidence::addAlarm(const Alarm::Ptr &alarm)
{
- update();
- d->mAlarms.append( alarm );
- setFieldDirty( FieldAlarms );
- updated();
+ update();
+ d->mAlarms.append(alarm);
+ setFieldDirty(FieldAlarms);
+ updated();
}
-void Incidence::removeAlarm( const Alarm::Ptr &alarm )
+void Incidence::removeAlarm(const Alarm::Ptr &alarm)
{
- const int index = d->mAlarms.indexOf( alarm );
- if ( index > -1 ) {
- update();
- d->mAlarms.remove( index );
- setFieldDirty( FieldAlarms );
- updated();
- }
+ const int index = d->mAlarms.indexOf(alarm);
+ if (index > -1) {
+ update();
+ d->mAlarms.remove(index);
+ setFieldDirty(FieldAlarms);
+ updated();
+ }
}
void Incidence::clearAlarms()
{
- update();
- d->mAlarms.clear();
- setFieldDirty( FieldAlarms );
- updated();
+ update();
+ d->mAlarms.clear();
+ setFieldDirty(FieldAlarms);
+ updated();
}
bool Incidence::hasEnabledAlarms() const
{
- foreach ( Alarm::Ptr alarm, d->mAlarms ) {
- if ( alarm->enabled() ) {
- return true;
+ foreach(Alarm::Ptr alarm, d->mAlarms) {
+ if (alarm->enabled()) {
+ return true;
+ }
}
- }
- return false;
+ return false;
}
-void Incidence::setLocation( const QString &location, bool isRich )
+void Incidence::setLocation(const QString &location, bool isRich)
{
- if ( mReadOnly ) {
- return;
- }
+ if (mReadOnly) {
+ return;
+ }
- update();
- d->mLocation = location;
- d->mLocationIsRich = isRich;
- setFieldDirty( FieldLocation );
- updated();
+ update();
+ d->mLocation = location;
+ d->mLocationIsRich = isRich;
+ setFieldDirty(FieldLocation);
+ updated();
}
-void Incidence::setLocation( const QString &location )
+void Incidence::setLocation(const QString &location)
{
- setLocation( location, Qt::mightBeRichText( location ) );
+ setLocation(location, Qt::mightBeRichText(location));
}
QString Incidence::location() const
{
- return d->mLocation;
+ return d->mLocation;
}
QString Incidence::richLocation() const
{
- if ( locationIsRich() ) {
- return d->mLocation;
- } else {
- return Qt::escape( d->mLocation ).replace( '\n', "<br/>" );
- }
+ if (locationIsRich()) {
+ return d->mLocation;
+ } else {
+ return Qt::escape(d->mLocation).replace(QLatin1Char('\n'), QLatin1String("<br/>"));
+ }
}
bool Incidence::locationIsRich() const
{
- return d->mLocationIsRich;
+ return d->mLocationIsRich;
}
-void Incidence::setSchedulingID( const QString &sid, const QString &uid )
+void Incidence::setSchedulingID(const QString &sid, const QString &uid)
{
- d->mSchedulingID = sid;
- if ( !uid.isEmpty() ) {
- setUid( uid );
- }
- setFieldDirty( FieldSchedulingId );
+ d->mSchedulingID = sid;
+ if (!uid.isEmpty()) {
+ setUid(uid);
+ }
+ setFieldDirty(FieldSchedulingId);
}
QString Incidence::schedulingID() const
{
- if ( d->mSchedulingID.isNull() ) {
- // Nothing set, so use the normal uid
- return uid();
- }
- return d->mSchedulingID;
+ if (d->mSchedulingID.isNull()) {
+ // Nothing set, so use the normal uid
+ return uid();
+ }
+ return d->mSchedulingID;
}
bool Incidence::hasGeo() const
{
- return d->mHasGeo;
+ return d->mHasGeo;
}
-void Incidence::setHasGeo( bool hasGeo )
+void Incidence::setHasGeo(bool hasGeo)
{
- if ( mReadOnly ) {
- return;
- }
+ if (mReadOnly) {
+ return;
+ }
- if ( hasGeo == d->mHasGeo ) {
- return;
- }
+ if (hasGeo == d->mHasGeo) {
+ return;
+ }
- update();
- d->mHasGeo = hasGeo;
- setFieldDirty( FieldGeoLatitude );
- setFieldDirty( FieldGeoLongitude );
- updated();
+ update();
+ d->mHasGeo = hasGeo;
+ setFieldDirty(FieldGeoLatitude);
+ setFieldDirty(FieldGeoLongitude);
+ updated();
}
float Incidence::geoLatitude() const
{
- return d->mGeoLatitude;
+ return d->mGeoLatitude;
}
-void Incidence::setGeoLatitude( float geolatitude )
+void Incidence::setGeoLatitude(float geolatitude)
{
- if ( mReadOnly ) {
- return;
- }
+ if (mReadOnly) {
+ return;
+ }
- update();
- d->mGeoLatitude = geolatitude;
- setFieldDirty( FieldGeoLatitude );
- updated();
+ update();
+ d->mGeoLatitude = geolatitude;
+ setFieldDirty(FieldGeoLatitude);
+ updated();
}
float Incidence::geoLongitude() const
{
- return d->mGeoLongitude;
+ return d->mGeoLongitude;
}
-void Incidence::setGeoLongitude( float geolongitude )
+void Incidence::setGeoLongitude(float geolongitude)
{
- if ( !mReadOnly ) {
- update();
- d->mGeoLongitude = geolongitude;
- setFieldDirty( FieldGeoLongitude );
- updated();
- }
+ if (!mReadOnly) {
+ update();
+ d->mGeoLongitude = geolongitude;
+ setFieldDirty(FieldGeoLongitude);
+ updated();
+ }
}
bool Incidence::hasRecurrenceId() const
{
- return d->mRecurrenceId.isValid();
+ return d->mRecurrenceId.isValid();
}
KDateTime Incidence::recurrenceId() const
{
- return d->mRecurrenceId;
+ return d->mRecurrenceId;
}
-void Incidence::setRecurrenceId( const KDateTime &recurrenceId )
+void Incidence::setThisAndFuture(bool thisAndFuture)
{
- if ( !mReadOnly ) {
- update();
- d->mRecurrenceId = recurrenceId;
- setFieldDirty( FieldRecurrenceId );
- updated();
- }
+ d->mThisAndFuture = thisAndFuture;
+}
+
+bool Incidence::thisAndFuture() const
+{
+ return d->mThisAndFuture;
+}
+
+void Incidence::setRecurrenceId(const KDateTime &recurrenceId)
+{
+ if (!mReadOnly) {
+ update();
+ d->mRecurrenceId = recurrenceId;
+ setFieldDirty(FieldRecurrenceId);
+ updated();
+ }
}
/** Observer interface for the recurrence class. If the recurrence is changed,
this method will be called for the incidence the recurrence object
belongs to. */
-void Incidence::recurrenceUpdated( Recurrence *recurrence )
+void Incidence::recurrenceUpdated(Recurrence *recurrence)
{
- if ( recurrence == d->mRecurrence ) {
- update();
- updated();
- }
+ if (recurrence == d->mRecurrence) {
+ update();
+ setFieldDirty(FieldRecurrence);
+ updated();
+ }
}
//@cond PRIVATE
#define ALT_DESC_FIELD "X-ALT-DESC"
-#define ALT_DESC_PARAMETERS "FMTTYPE=text/html"
+#define ALT_DESC_PARAMETERS QLatin1String("FMTTYPE=text/html")
//@endcond
bool Incidence::hasAltDescription() const
{
- const QString value = nonKDECustomProperty( ALT_DESC_FIELD );
- const QString parameter = nonKDECustomPropertyParameters( ALT_DESC_FIELD );
+ const QString value = nonKDECustomProperty(ALT_DESC_FIELD);
+ const QString parameter = nonKDECustomPropertyParameters(ALT_DESC_FIELD);
- return parameter == ALT_DESC_PARAMETERS && !value.isEmpty();
+ return parameter == ALT_DESC_PARAMETERS && !value.isEmpty();
}
-void Incidence::setAltDescription( const QString &altdescription )
+void Incidence::setAltDescription(const QString &altdescription)
{
- if ( altdescription.isEmpty() ) {
- removeNonKDECustomProperty( ALT_DESC_FIELD );
- } else {
- setNonKDECustomProperty( ALT_DESC_FIELD,
- altdescription,
- ALT_DESC_PARAMETERS );
- }
+ if (altdescription.isEmpty()) {
+ removeNonKDECustomProperty(ALT_DESC_FIELD);
+ } else {
+ setNonKDECustomProperty(ALT_DESC_FIELD,
+ altdescription,
+ ALT_DESC_PARAMETERS);
+ }
}
QString Incidence::altDescription() const
{
- if ( !hasAltDescription() ) {
- return QString();
- } else {
- return nonKDECustomProperty( ALT_DESC_FIELD );
- }
+ if (!hasAltDescription()) {
+ return QString();
+ } else {
+ return nonKDECustomProperty(ALT_DESC_FIELD);
+ }
+}
+
+bool Incidence::supportsGroupwareCommunication() const
+{
+ return type() == TypeEvent || type() == TypeTodo;
+}
+
+/** static */
+QStringList Incidence::mimeTypes()
+{
+ return QStringList() << QLatin1String("text/calendar")
+ << KCalCore::Event::eventMimeType()
+ << KCalCore::Todo::todoMimeType()
+ << KCalCore::Journal::journalMimeType();
+}
+
+void Incidence::serialize(QDataStream &out)
+{
+ out << d->mCreated << d->mRevision << d->mDescription << d->mDescriptionIsRich << d->mSummary
+ << d->mSummaryIsRich << d->mLocation << d->mLocationIsRich << d->mCategories
+ << d->mResources << d->mStatusString << d->mPriority << d->mSchedulingID
+ << d->mGeoLatitude << d->mGeoLongitude << d->mHasGeo << d->mRecurrenceId << d->mThisAndFuture
+ << d->mLocalOnly << d->mStatus << d->mSecrecy << (d->mRecurrence ? true : false)
+ << d->mAttachments.count() << d->mAlarms.count() << d->mRelatedToUid;
+
+ if (d->mRecurrence)
+ out << d->mRecurrence;
+
+ foreach(const Attachment::Ptr &attachment, d->mAttachments) {
+ out << attachment;
+ }
+
+ foreach(const Alarm::Ptr &alarm, d->mAlarms) {
+ out << alarm;
+ }
+}
+
+void Incidence::deserialize(QDataStream &in)
+{
+ quint32 status, secrecy;
+ bool hasRecurrence;
+ int attachmentCount, alarmCount;
+ QMap<int,QString> relatedToUid;
+ in >> d->mCreated >> d->mRevision >> d->mDescription >> d->mDescriptionIsRich >> d->mSummary
+ >> d->mSummaryIsRich >> d->mLocation >> d->mLocationIsRich >> d->mCategories
+ >> d->mResources >> d->mStatusString >> d->mPriority >> d->mSchedulingID
+ >> d->mGeoLatitude >> d->mGeoLongitude >> d->mHasGeo >> d->mRecurrenceId >> d->mThisAndFuture
+ >> d->mLocalOnly >> status >> secrecy >> hasRecurrence >> attachmentCount >> alarmCount
+ >> relatedToUid;
+
+ if (hasRecurrence) {
+ d->mRecurrence = new Recurrence();
+ d->mRecurrence->addObserver(const_cast<KCalCore::Incidence*>(this));
+ in >> d->mRecurrence;
+ }
+
+ d->mAttachments.clear();
+ d->mAlarms.clear();
+
+ for (int i=0; i<attachmentCount; ++i) {
+ Attachment::Ptr attachment = Attachment::Ptr(new Attachment(QString()));
+ in >> attachment;
+ d->mAttachments.append(attachment);
+ }
+
+ for (int i=0; i<alarmCount; ++i) {
+ Alarm::Ptr alarm = Alarm::Ptr(new Alarm(this));
+ in >> alarm;
+ d->mAlarms.append(alarm);
+ }
+
+ d->mStatus = static_cast<Incidence::Status>(status);
+ d->mSecrecy = static_cast<Incidence::Secrecy>(secrecy);
+
+ d->mRelatedToUid.clear();
+ foreach(int key, relatedToUid.keys()) { //krazy:exclude=foreach
+ d->mRelatedToUid.insert(static_cast<Incidence::RelType>(key), relatedToUid.value(key));
+ }
+
+
}
diff --git a/kcalcore/incidence.h b/kcalcore/incidence.h
index edd27ab..c5642b8 100644
--- a/kcalcore/incidence.h
+++ b/kcalcore/incidence.h
@@ -66,34 +66,34 @@ namespace KCalCore {
Events, Todos and Journals, but are not allowed for FreeBusy entries.
*/
class KCALCORE_EXPORT Incidence
- : public IncidenceBase, public Recurrence::RecurrenceObserver
+ : public IncidenceBase, public Recurrence::RecurrenceObserver
{
- public:
+public:
/**
The different types of overall incidence status or confirmation.
The meaning is specific to the incidence type in context.
*/
enum Status {
- StatusNone, /**< No status */
- StatusTentative, /**< event is tentative */
- StatusConfirmed, /**< event is definite */
- StatusCompleted, /**< to-do completed */
- StatusNeedsAction, /**< to-do needs action */
- StatusCanceled, /**< event or to-do canceled; journal removed */
- StatusInProcess, /**< to-do in process */
- StatusDraft, /**< journal is draft */
- StatusFinal, /**< journal is final */
- StatusX /**< a non-standard status string */
+ StatusNone, /**< No status */
+ StatusTentative, /**< event is tentative */
+ StatusConfirmed, /**< event is definite */
+ StatusCompleted, /**< to-do completed */
+ StatusNeedsAction, /**< to-do needs action */
+ StatusCanceled, /**< event or to-do canceled; journal removed */
+ StatusInProcess, /**< to-do in process */
+ StatusDraft, /**< journal is draft */
+ StatusFinal, /**< journal is final */
+ StatusX /**< a non-standard status string */
};
/**
The different types of incidence access classifications.
*/
enum Secrecy {
- SecrecyPublic, /**< Not secret (default) */
- SecrecyPrivate, /**< Secret to the owner */
- SecrecyConfidential /**< Secret to the owner and some others */
+ SecrecyPublic, /**< Not secret (default) */
+ SecrecyPrivate, /**< Secret to the owner */
+ SecrecyConfidential /**< Secret to the owner and some others */
};
/**
@@ -101,9 +101,9 @@ class KCALCORE_EXPORT Incidence
Only RelTypeParent is supported for now.
*/
enum RelType {
- RelTypeParent, /**< The related incidence is a parent. */
- RelTypeChild, /**< The related incidence is a child. */
- RelTypeSibling /**< The related incidence is a peer. */
+ RelTypeParent, /**< The related incidence is a parent. */
+ RelTypeChild, /**< The related incidence is a child. */
+ RelTypeSibling /**< The related incidence is a peer. */
};
/**
@@ -135,18 +135,25 @@ class KCALCORE_EXPORT Incidence
virtual Incidence *clone() const = 0;
/**
+ Returns a unique identifier for a specific instance of an incidence.
+
+ Due to the recurrence-id, the uid is not unique for a KCalCore::Incidence.
+ @since 4.11
+ */
+ QString instanceIdentifier() const;
+
+ /**
Set readonly state of incidence.
@param readonly If true, the incidence is set to readonly, if false the
incidence is set to readwrite.
*/
- void setReadOnly( bool readonly );
+ void setReadOnly(bool readonly);
/**
- @copydoc
- IncidenceBase::setLastModified().
+ @copydoc IncidenceBase::setLastModified().
*/
- void setLastModified( const KDateTime &lm );
+ void setLastModified(const KDateTime &lm);
/**
Set localOnly state of incidence.
@@ -156,21 +163,20 @@ class KCALCORE_EXPORT Incidence
@param localonly If true, the incidence is set to localonly, if false the
incidence is set to normal stat.
*/
- void setLocalOnly( bool localonly );
+ void setLocalOnly(bool localonly);
/**
Get the localOnly status.
+ @return true if Local only, false otherwise.
@see setLocalOnly()
- @return True if Local only, false otherwise
*/
bool localOnly() const;
/**
- @copydoc
- IncidenceBase::setAllDay().
+ @copydoc IncidenceBase::setAllDay().
*/
- void setAllDay( bool allDay );
+ void setAllDay(bool allDay);
/**
Recreate incidence. The incidence is made a new unique incidence, but already stored
@@ -185,7 +191,7 @@ class KCALCORE_EXPORT Incidence
@param dt is the creation date/time.
@see created().
*/
- void setCreated( const KDateTime &dt );
+ void setCreated(const KDateTime &dt);
/**
Returns the incidence creation date/time.
@@ -199,7 +205,7 @@ class KCALCORE_EXPORT Incidence
@param rev is the incidence revision number.
@see revision().
*/
- void setRevision( int rev );
+ void setRevision(int rev);
/**
Returns the number of revisions this incidence has seen.
@@ -213,14 +219,13 @@ class KCALCORE_EXPORT Incidence
@param dt is the starting date/time.
@see IncidenceBase::dtStart().
*/
- virtual void setDtStart( const KDateTime &dt );
+ virtual void setDtStart(const KDateTime &dt);
/**
- @copydoc
- IncidenceBase::shiftTimes()
+ @copydoc IncidenceBase::shiftTimes()
*/
- virtual void shiftTimes( const KDateTime::Spec &oldSpec,
- const KDateTime::Spec &newSpec );
+ virtual void shiftTimes(const KDateTime::Spec &oldSpec,
+ const KDateTime::Spec &newSpec);
/**
Sets the incidence description.
@@ -229,7 +234,7 @@ class KCALCORE_EXPORT Incidence
@param isRich if true indicates the description string contains richtext.
@see description().
*/
- void setDescription( const QString &description, bool isRich );
+ void setDescription(const QString &description, bool isRich);
/**
Sets the incidence description and tries to guess if the description
@@ -238,7 +243,7 @@ class KCALCORE_EXPORT Incidence
@param description is the incidence description string.
@see description().
*/
- void setDescription( const QString &description );
+ void setDescription(const QString &description);
/**
Returns the incidence description.
@@ -267,7 +272,7 @@ class KCALCORE_EXPORT Incidence
@param isRich if true indicates the summary string contains richtext.
@see summary().
*/
- void setSummary( const QString &summary, bool isRich );
+ void setSummary(const QString &summary, bool isRich);
/**
Sets the incidence summary and tries to guess if the summary is richtext.
@@ -275,7 +280,7 @@ class KCALCORE_EXPORT Incidence
@param summary is the incidence summary string.
@see summary().
*/
- void setSummary( const QString &summary );
+ void setSummary(const QString &summary);
/**
Returns the incidence summary.
@@ -304,7 +309,7 @@ class KCALCORE_EXPORT Incidence
@param isRich if true indicates the location string contains richtext.
@see location().
*/
- void setLocation( const QString &location, bool isRich );
+ void setLocation(const QString &location, bool isRich);
/**
Sets the incidence location and tries to guess if the location is
@@ -313,7 +318,7 @@ class KCALCORE_EXPORT Incidence
@param location is the incidence location string.
@see location().
*/
- void setLocation( const QString &location );
+ void setLocation(const QString &location);
/**
Returns the incidence location. Do _not_ use with journals.
@@ -341,7 +346,7 @@ class KCALCORE_EXPORT Incidence
@param categories is a list of category strings.
@see setCategories( const QString &), categories().
*/
- void setCategories( const QStringList &categories );
+ void setCategories(const QStringList &categories);
/**
Sets the incidence category list based on a comma delimited string.
@@ -350,7 +355,7 @@ class KCALCORE_EXPORT Incidence
are delimited by a comma character.
@see setCategories( const QStringList &), categories().
*/
- void setCategories( const QString &catStr );
+ void setCategories(const QString &catStr);
/**
Returns the incidence categories as a list of strings.
@@ -375,7 +380,7 @@ class KCALCORE_EXPORT Incidence
@see relatedTo().
*/
- void setRelatedTo( const QString &uid, RelType relType = RelTypeParent );
+ void setRelatedTo(const QString &uid, RelType relType = RelTypeParent);
/**
Returns a UID string for the incidence that is related to this one.
@@ -388,7 +393,7 @@ class KCALCORE_EXPORT Incidence
@see setRelatedTo().
*/
- QString relatedTo( RelType relType = RelTypeParent ) const;
+ QString relatedTo(RelType relType = RelTypeParent) const;
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// %%%%% Convenience wrappers for property handling
@@ -406,7 +411,7 @@ class KCALCORE_EXPORT Incidence
@param altdescription is the incidence altdescription string.
@see altAltdescription().
*/
- void setAltDescription( const QString &altdescription );
+ void setAltDescription(const QString &altdescription);
/**
Returns the incidence alternative (=text/html) description.
@@ -430,28 +435,24 @@ class KCALCORE_EXPORT Incidence
void clearRecurrence();
/**
- @copydoc
- Recurrence::recurs()
+ @copydoc Recurrence::recurs()
*/
bool recurs() const;
/**
- @copydoc
- Recurrence::recurrenceType()
+ @copydoc Recurrence::recurrenceType()
*/
ushort recurrenceType() const;
/**
- @copydoc
- Recurrence::recursOn()
+ @copydoc Recurrence::recursOn()
*/
- virtual bool recursOn( const QDate &date, const KDateTime::Spec &timeSpec ) const;
+ virtual bool recursOn(const QDate &date, const KDateTime::Spec &timeSpec) const;
/**
- @copydoc
- Recurrence::recursAt()
+ @copydoc Recurrence::recursAt()
*/
- bool recursAt( const KDateTime &dt ) const;
+ bool recursAt(const KDateTime &dt) const;
/**
Calculates the start date/time for all recurrences that happen at some
@@ -465,8 +466,8 @@ class KCALCORE_EXPORT Incidence
date at all.
*/
virtual QList<KDateTime> startDateTimesForDate(
- const QDate &date,
- const KDateTime::Spec &timeSpec = KDateTime::LocalZone ) const;
+ const QDate &date,
+ const KDateTime::Spec &timeSpec = KDateTime::LocalZone) const;
/**
Calculates the start date/time for all recurrences that happen at the
@@ -478,7 +479,7 @@ class KCALCORE_EXPORT Incidence
given time at all.
*/
virtual QList<KDateTime> startDateTimesForDateTime(
- const KDateTime &datetime ) const;
+ const KDateTime &datetime) const;
/**
Returns the end date/time of the incidence occurrence if it starts at
@@ -489,7 +490,7 @@ class KCALCORE_EXPORT Incidence
date/time if the end date/time is invalid; or the end date/time if
the start date/time is invalid.
*/
- virtual KDateTime endDateForStart( const KDateTime &startDt ) const;
+ virtual KDateTime endDateForStart(const KDateTime &startDt) const;
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// %%%%% Attachment-related methods
@@ -501,7 +502,7 @@ class KCALCORE_EXPORT Incidence
@param attachment is a pointer to a valid Attachment object.
@see deleteAttachment().
*/
- void addAttachment( const Attachment::Ptr &attachment );
+ void addAttachment(const Attachment::Ptr &attachment);
/**
Removes the specified attachment from the incidence. Additionally,
@@ -510,7 +511,7 @@ class KCALCORE_EXPORT Incidence
@param attachment is a pointer to a valid Attachment object.
@see addAttachment(), deleteAttachments().
*/
- void deleteAttachment( const Attachment::Ptr &attachment );
+ void deleteAttachment(const Attachment::Ptr &attachment);
/**
Removes all attachments of the specified MIME type from the incidence.
@@ -519,7 +520,7 @@ class KCALCORE_EXPORT Incidence
@param mime is a QString containing the MIME type.
@see deleteAttachment().
*/
- void deleteAttachments( const QString &mime );
+ void deleteAttachments(const QString &mime);
/**
Returns a list of all incidence attachments.
@@ -533,7 +534,7 @@ class KCALCORE_EXPORT Incidence
@param mime is a QString containing the MIME type.
@see attachments().
*/
- Attachment::List attachments( const QString &mime ) const;
+ Attachment::List attachments(const QString &mime) const;
/**
Removes all attachments and frees the memory used by them.
@@ -549,7 +550,7 @@ class KCALCORE_EXPORT Incidence
@return a string containing the name of the temporary file containing the attachment.
@see clearTempFiles().
*/
- QString writeAttachmentToTempFile( const Attachment::Ptr &attachment ) const;
+ QString writeAttachmentToTempFile(const Attachment::Ptr &attachment) const;
/**
Deletes all temporary files used by attachments and frees any memory in use by them.
@@ -567,7 +568,7 @@ class KCALCORE_EXPORT Incidence
@param secrecy is the incidence #Secrecy to set.
@see secrecy(), secrecyStr().
*/
- void setSecrecy( Secrecy secrecy );
+ void setSecrecy(Secrecy secrecy);
/**
Returns the incidence #Secrecy.
@@ -582,7 +583,7 @@ class KCALCORE_EXPORT Incidence
@param status is the incidence #Status to set.
@see status(), setCustomStatus().
*/
- void setStatus( Status status );
+ void setStatus(Status status);
/**
Sets the incidence #Status to a non-standard status value.
@@ -591,7 +592,7 @@ class KCALCORE_EXPORT Incidence
the incidence #Status will be set to StatusNone.
@see setStatus(), status() customStatus().
*/
- void setCustomStatus( const QString &status );
+ void setCustomStatus(const QString &status);
/**
Returns the non-standard status value.
@@ -616,7 +617,7 @@ class KCALCORE_EXPORT Incidence
@param resources is a list of resource strings.
@see resources().
*/
- void setResources( const QStringList &resources );
+ void setResources(const QStringList &resources);
/**
Returns the incidence resources as a list of strings.
@@ -632,7 +633,7 @@ class KCALCORE_EXPORT Incidence
@param priority is the incidence priority to set.
@see priority().
*/
- void setPriority( int priority );
+ void setPriority(int priority);
/**
Returns the incidence priority.
@@ -651,14 +652,14 @@ class KCALCORE_EXPORT Incidence
@param hasGeo true if incidence has geo data, otherwise false
@see hasGeo(), geoLatitude(), geoLongitude().
*/
- void setHasGeo( bool hasGeo );
+ void setHasGeo(bool hasGeo);
/**
Set the incidences geoLatitude.
@param geolatitude is the incidence geolatitude to set
@see geoLatitude().
*/
- void setGeoLatitude( float geolatitude );
+ void setGeoLatitude(float geolatitude);
/**
Returns the incidence geoLatidude.
@@ -672,7 +673,7 @@ class KCALCORE_EXPORT Incidence
@param geolongitude is the incidence geolongitude to set
@see geoLongitude().
*/
- void setGeoLongitude( float geolongitude );
+ void setGeoLongitude(float geolongitude);
/**
Returns the incidence geoLongitude.
@@ -683,16 +684,18 @@ class KCALCORE_EXPORT Incidence
/**
Returns true if the incidence has recurrenceId, otherwise return false.
- @see setHasRecurrenceID(), setRecurrenceId(KDateTime)
+ @see setRecurrenceId(KDateTime)
*/
bool hasRecurrenceId() const;
/**
Set the incidences recurrenceId.
+ This field indicates that this is an exception to a recurring incidence.
+ The uid of this incidence MUST be the same as the one of the recurring main incidence.
@param recurrenceId is the incidence recurrenceId to set
@see recurrenceId().
*/
- void setRecurrenceId( const KDateTime &recurrenceId );
+ void setRecurrenceId(const KDateTime &recurrenceId);
/**
Returns the incidence recurrenceId.
@@ -701,6 +704,23 @@ class KCALCORE_EXPORT Incidence
*/
KDateTime recurrenceId() const;
+ /**
+ Set to true if the exception also applies to all future occurrences.
+ This option is only relevant if the incidence has a recurrenceId set.
+ @param thisAndFuture value
+ @see thisAndFuture(), setRecurrenceId()
+ @since 4.11
+ */
+ void setThisAndFuture(bool thisAndFuture);
+
+ /**
+ Returns true if the exception also applies to all future occurrences.
+ @return incidences thisAndFuture value
+ @see setThisAndFuture()
+ @since 4.11
+ */
+ bool thisAndFuture() const;
+
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// %%%%% Alarm-related methods
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -721,7 +741,7 @@ class KCALCORE_EXPORT Incidence
@param alarm is a pointer to a valid Alarm object.
@see removeAlarm().
*/
- void addAlarm( const Alarm::Ptr &alarm );
+ void addAlarm(const Alarm::Ptr &alarm);
/**
Removes the specified alarm from the incidence.
@@ -729,7 +749,7 @@ class KCALCORE_EXPORT Incidence
@param alarm is a pointer to a valid Alarm object.
@see addAlarm().
*/
- void removeAlarm( const Alarm::Ptr &alarm );
+ void removeAlarm(const Alarm::Ptr &alarm);
/**
Removes all alarms.
@@ -770,8 +790,8 @@ class KCALCORE_EXPORT Incidence
is ignored.
@see schedulingID().
*/
- void setSchedulingID( const QString &sid,
- const QString &uid = QString() );
+ void setSchedulingID(const QString &sid,
+ const QString &uid = QString());
/**
Returns the incidence scheduling ID. Do _not_ use with journals.
@@ -787,7 +807,7 @@ class KCALCORE_EXPORT Incidence
@param recurrence is a pointer to a valid Recurrence object.
*/
- virtual void recurrenceUpdated( Recurrence *recurrence );
+ virtual void recurrenceUpdated(Recurrence *recurrence);
/**
Returns the name of the icon that best represents this incidence.
@@ -796,37 +816,56 @@ class KCALCORE_EXPORT Incidence
for example, completed to-do occurrences. Use this parameter to identify
the specific occurrence in a recurring serie.
*/
- virtual QLatin1String iconName( const KDateTime &recurrenceId = KDateTime() ) const = 0;
+ virtual QLatin1String iconName(const KDateTime &recurrenceId = KDateTime()) const = 0;
- protected:
+ /**
+ * Returns true if the incidence type supports groupware communication.
+ * @since 4.10
+ */ //TODO_KDE5: make pure virtual
+ bool supportsGroupwareCommunication() const;
+
+ /**
+ Returns the list of possible mime types in an Incidence object:
+ "text/calendar"
+ "application/x-vnd.akonadi.calendar.event"
+ "application/x-vnd.akonadi.calendar.todo"
+ "application/x-vnd.akonadi.calendar.journal"
+
+ @since 4.12
+ */
+ static QStringList mimeTypes();
+
+protected:
/**
Copy constructor.
@param other is the incidence to copy.
*/
- Incidence( const Incidence &other );
+ Incidence(const Incidence &other);
/**
Compares this with Incidence @p incidence for equality.
@param incidence is the Incidence to compare against.
@return true if the incidences are equal; false otherwise.
*/
- virtual bool equals( const IncidenceBase &incidence ) const;
+ virtual bool equals(const IncidenceBase &incidence) const;
/**
- @copydoc
- IncidenceBase::assign()
+ @copydoc IncidenceBase::assign()
*/
- virtual IncidenceBase &assign( const IncidenceBase &other );
+ virtual IncidenceBase &assign(const IncidenceBase &other);
+
+ void serialize(QDataStream &out);
+ void deserialize(QDataStream &in);
- private:
+private:
/**
Disabled, not polymorphic.
Use IncidenceBase::operator= which is safe because it calls
virtual function assign.
@param other is another Incidence object to assign to this one.
*/
- Incidence &operator=( const Incidence &other );
+ Incidence &operator=(const Incidence &other);
//@cond PRIVATE
class Private;
@@ -837,13 +876,15 @@ class KCALCORE_EXPORT Incidence
}
//@cond PRIVATE
-inline uint qHash( const QSharedPointer<KCalCore::Incidence> &key )
+inline uint qHash(const QSharedPointer<KCalCore::Incidence> &key)
{
- return qHash<KCalCore::Incidence>( key.data() );
+ return qHash<KCalCore::Incidence>(key.data());
}
//@endcond
-Q_DECLARE_TYPEINFO( KCalCore::Incidence::Ptr, Q_MOVABLE_TYPE );
-Q_DECLARE_METATYPE( KCalCore::Incidence * )
+//@cond PRIVATE
+Q_DECLARE_TYPEINFO(KCalCore::Incidence::Ptr, Q_MOVABLE_TYPE);
+Q_DECLARE_METATYPE(KCalCore::Incidence *)
+//@endcond
#endif
diff --git a/kcalcore/incidencebase.cpp b/kcalcore/incidencebase.cpp
index 9dd3a4e..baca4c7 100644
--- a/kcalcore/incidencebase.cpp
+++ b/kcalcore/incidencebase.cpp
@@ -38,12 +38,14 @@
#include "calformat.h"
#include "visitor.h"
-#include <QtCore/QDebug>
-
-// #include <KUrl>
+#include <QTime>
+#include <KDebug>
+#include <KUrl>
#include <QtCore/QStringList>
-#include <QUrl>
+
+#define KCALCORE_MAGIC_NUMBER 0xCA1C012E
+#define KCALCORE_SERIALIZATION_VERSION 1
using namespace KCalCore;
@@ -54,29 +56,29 @@ using namespace KCalCore;
//@cond PRIVATE
class KCalCore::IncidenceBase::Private
{
- public:
+public:
Private()
- : mOrganizer( new Person() ),
- mUpdateGroupLevel( 0 ),
- mUpdatedPending( false ),
- mAllDay( true ),
- mHasDuration( false )
+ : mOrganizer(0),
+ mUpdateGroupLevel(0),
+ mUpdatedPending(false),
+ mAllDay(true),
+ mHasDuration(false)
{}
- Private( const Private &other )
- : mUpdateGroupLevel( 0 ),
- mUpdatedPending( false ),
- mAllDay( true ),
- mHasDuration( false )
+ Private(const Private &other)
+ : mUpdateGroupLevel(0),
+ mUpdatedPending(false),
+ mAllDay(true),
+ mHasDuration(false)
{
- init( other );
+ init(other);
}
~Private()
{
}
- void init( const Private &other );
+ void init(const Private &other);
KDateTime mLastModified; // incidence last modified date
KDateTime mDtStart; // incidence start time
@@ -92,550 +94,651 @@ class KCalCore::IncidenceBase::Private
QStringList mContacts; // list of incidence contacts
QList<IncidenceObserver*> mObservers; // list of incidence observers
QSet<Field> mDirtyFields; // Fields that changed since last time the incidence was created
- // or since resetDirtyFlags() was called
+ // or since resetDirtyFlags() was called
+ QUrl mUrl; // incidence url property
};
-void IncidenceBase::Private::init( const Private &other )
+void IncidenceBase::Private::init(const Private &other)
{
- mLastModified = other.mLastModified;
- mDtStart = other.mDtStart;
- mOrganizer = other.mOrganizer;
- mUid = other.mUid;
- mDuration = other.mDuration;
- mAllDay = other.mAllDay;
- mHasDuration = other.mHasDuration;
+ mLastModified = other.mLastModified;
+ mDtStart = other.mDtStart;
+ mOrganizer = other.mOrganizer;
+ mUid = other.mUid;
+ mDuration = other.mDuration;
+ mAllDay = other.mAllDay;
+ mHasDuration = other.mHasDuration;
- mComments = other.mComments;
- mContacts = other.mContacts;
+ mComments = other.mComments;
+ mContacts = other.mContacts;
- mAttendees.clear();
- Attendee::List::ConstIterator it;
- for ( it = other.mAttendees.constBegin(); it != other.mAttendees.constEnd(); ++it ) {
- mAttendees.append( Attendee::Ptr( new Attendee( *(*it) ) ) );
- }
+ mAttendees.clear();
+ Attendee::List::ConstIterator it;
+ for (it = other.mAttendees.constBegin(); it != other.mAttendees.constEnd(); ++it) {
+ mAttendees.append(Attendee::Ptr(new Attendee(*(*it))));
+ }
+ mUrl = other.mUrl;
}
//@endcond
IncidenceBase::IncidenceBase()
- : d( new KCalCore::IncidenceBase::Private )
+ : d(new KCalCore::IncidenceBase::Private)
{
- mReadOnly = false;
- setUid( CalFormat::createUniqueId() );
+ mReadOnly = false;
+ setUid(CalFormat::createUniqueId());
}
-IncidenceBase::IncidenceBase( const IncidenceBase &i )
- : CustomProperties( i ),
- d( new KCalCore::IncidenceBase::Private( *i.d ) )
+IncidenceBase::IncidenceBase(const IncidenceBase &i)
+ : CustomProperties(i),
+ d(new KCalCore::IncidenceBase::Private(*i.d))
{
- mReadOnly = i.mReadOnly;
+ mReadOnly = i.mReadOnly;
}
IncidenceBase::~IncidenceBase()
{
- delete d;
+ delete d;
}
-IncidenceBase &IncidenceBase::operator=( const IncidenceBase &other )
+IncidenceBase &IncidenceBase::operator=(const IncidenceBase &other)
{
- Q_ASSERT( type() == other.type() );
+ Q_ASSERT(type() == other.type());
- startUpdates();
+ startUpdates();
- // assign is virtual, will call the derived class's
- IncidenceBase &ret = assign( other );
- endUpdates();
- return ret;
+ // assign is virtual, will call the derived class's
+ IncidenceBase &ret = assign(other);
+ endUpdates();
+ return ret;
}
-IncidenceBase &IncidenceBase::assign( const IncidenceBase &other )
+IncidenceBase &IncidenceBase::assign(const IncidenceBase &other)
{
- CustomProperties::operator=( other );
- d->init( *other.d );
- mReadOnly = other.mReadOnly;
- d->mDirtyFields.clear();
- d->mDirtyFields.insert( FieldUnknown );
- return *this;
+ CustomProperties::operator=(other);
+ d->init(*other.d);
+ mReadOnly = other.mReadOnly;
+ d->mDirtyFields.clear();
+ d->mDirtyFields.insert(FieldUnknown);
+ return *this;
}
-bool IncidenceBase::operator==( const IncidenceBase &i2 ) const
+bool IncidenceBase::operator==(const IncidenceBase &i2) const
{
- if ( i2.type() != type() ) {
- return false;
- } else {
- // equals is virtual, so here we're calling the derived class method
- return equals( i2 );
- }
+ if (i2.type() != type()) {
+ return false;
+ } else {
+ // equals is virtual, so here we're calling the derived class method
+ return equals(i2);
+ }
}
-bool IncidenceBase::operator!=( const IncidenceBase &i2 ) const
+bool IncidenceBase::operator!=(const IncidenceBase &i2) const
{
- return !operator==( i2 );
+ return !operator==(i2);
}
-bool IncidenceBase::equals( const IncidenceBase &i2 ) const
+bool IncidenceBase::equals(const IncidenceBase &i2) const
{
- if ( attendees().count() != i2.attendees().count() ) {
- return false;
- }
+ if (attendees().count() != i2.attendees().count()) {
+ // kDebug() << "Attendee count is different";
+ return false;
+ }
- Attendee::List al1 = attendees();
- Attendee::List al2 = i2.attendees();
- Attendee::List::ConstIterator a1 = al1.constBegin();
- Attendee::List::ConstIterator a2 = al2.constBegin();
- //TODO Does the order of attendees in the list really matter?
- //Please delete this comment if you know it's ok, kthx
- for ( ; a1 != al1.constEnd() && a2 != al2.constEnd(); ++a1, ++a2 ) {
- if ( !( **a1 == **a2 ) ) {
- return false;
+ Attendee::List al1 = attendees();
+ Attendee::List al2 = i2.attendees();
+ Attendee::List::ConstIterator a1 = al1.constBegin();
+ Attendee::List::ConstIterator a2 = al2.constBegin();
+ //TODO Does the order of attendees in the list really matter?
+ //Please delete this comment if you know it's ok, kthx
+ for (; a1 != al1.constEnd() && a2 != al2.constEnd(); ++a1, ++a2) {
+ if (!(**a1 == **a2)) {
+ // kDebug() << "Attendees are different";
+ return false;
+ }
}
- }
- if ( !CustomProperties::operator==( i2 ) ) {
- return false;
- }
+ if (!CustomProperties::operator==(i2)) {
+ // kDebug() << "Properties are different";
+ return false;
+ }
- return
- ( ( dtStart() == i2.dtStart() ) ||
- ( !dtStart().isValid() && !i2.dtStart().isValid() ) ) &&
- *( organizer().data() ) == *( i2.organizer().data() ) &&
- uid() == i2.uid() &&
// Don't compare lastModified, otherwise the operator is not
// of much use. We are not comparing for identity, after all.
- allDay() == i2.allDay() &&
- duration() == i2.duration() &&
- hasDuration() == i2.hasDuration();
// no need to compare mObserver
+
+ bool a = ((dtStart() == i2.dtStart()) || (!dtStart().isValid() && !i2.dtStart().isValid()));
+ bool b = *(organizer().data()) == *(i2.organizer().data());
+ bool c = uid() == i2.uid();
+ bool d = allDay() == i2.allDay();
+ bool e = duration() == i2.duration();
+ bool f = hasDuration() == i2.hasDuration();
+ bool g = url() == i2.url();
+
+ //kDebug() << a << b << c << d << e << f << g;
+ return a && b && c && d && e && f && g;
}
-bool IncidenceBase::accept( Visitor &v, IncidenceBase::Ptr incidence )
+bool IncidenceBase::accept(Visitor &v, IncidenceBase::Ptr incidence)
{
- Q_UNUSED( v );
- Q_UNUSED( incidence );
- return false;
+ Q_UNUSED(v);
+ Q_UNUSED(incidence);
+ return false;
}
-void IncidenceBase::setUid( const QString &uid )
+void IncidenceBase::setUid(const QString &uid)
{
- update();
- d->mUid = uid;
- d->mDirtyFields.insert( FieldUid );
- updated();
+ update();
+ d->mUid = uid;
+ d->mDirtyFields.insert(FieldUid);
+ updated();
}
QString IncidenceBase::uid() const
{
- return d->mUid;
+ return d->mUid;
}
-void IncidenceBase::setLastModified( const KDateTime &lm )
+void IncidenceBase::setLastModified(const KDateTime &lm)
{
- // DON'T! updated() because we call this from
- // Calendar::updateEvent().
+ // DON'T! updated() because we call this from
+ // Calendar::updateEvent().
- d->mDirtyFields.insert( FieldLastModified );
+ d->mDirtyFields.insert(FieldLastModified);
- // Convert to UTC and remove milliseconds part.
- KDateTime current = lm.toUtc();
- QTime t = current.time();
- t.setHMS( t.hour(), t.minute(), t.second(), 0 );
- current.setTime( t );
+ // Convert to UTC and remove milliseconds part.
+ KDateTime current = lm.toUtc();
+ QTime t = current.time();
+ t.setHMS(t.hour(), t.minute(), t.second(), 0);
+ current.setTime(t);
- d->mLastModified = current;
+ d->mLastModified = current;
}
KDateTime IncidenceBase::lastModified() const
{
- return d->mLastModified;
+ return d->mLastModified;
}
-void IncidenceBase::setOrganizer( const Person::Ptr &o )
+void IncidenceBase::setOrganizer(const Person::Ptr &organizer)
{
- update();
- // we don't check for readonly here, because it is
- // possible that by setting the organizer we are changing
- // the event's readonly status...
- d->mOrganizer = o;
+ if (organizer) {
+ update();
+ // we don't check for readonly here, because it is
+ // possible that by setting the organizer we are changing
+ // the event's readonly status...
+ d->mOrganizer = organizer;
- d->mDirtyFields.insert( FieldOrganizer );
+ d->mDirtyFields.insert(FieldOrganizer);
- updated();
+ updated();
+ }
}
-void IncidenceBase::setOrganizer( const QString &o )
+void IncidenceBase::setOrganizer(const QString &o)
{
- QString mail( o );
- if ( mail.startsWith( QLatin1String( "MAILTO:" ), Qt::CaseInsensitive ) ) {
- mail = mail.remove( 0, 7 );
- }
+ QString mail(o);
+ if (mail.startsWith(QLatin1String("MAILTO:"), Qt::CaseInsensitive)) {
+ mail = mail.remove(0, 7);
+ }
- // split the string into full name plus email.
- const Person::Ptr organizer = Person::fromFullName( mail );
- setOrganizer( organizer );
+ // split the string into full name plus email.
+ const Person::Ptr organizer = Person::fromFullName(mail);
+ setOrganizer(organizer);
}
Person::Ptr IncidenceBase::organizer() const
{
- return d->mOrganizer;
+ if (!d->mOrganizer)
+ d->mOrganizer = Person::Ptr(new Person()); // init at first use only to save memory
+
+ return d->mOrganizer;
}
-void IncidenceBase::setReadOnly( bool readOnly )
+void IncidenceBase::setReadOnly(bool readOnly)
{
- mReadOnly = readOnly;
+ mReadOnly = readOnly;
}
bool IncidenceBase::isReadOnly() const
{
- return mReadOnly;
+ return mReadOnly;
}
-void IncidenceBase::setDtStart( const KDateTime &dtStart )
+void IncidenceBase::setDtStart(const KDateTime &dtStart)
{
// if ( mReadOnly ) return;
- update();
- d->mDtStart = dtStart;
- d->mAllDay = dtStart.isDateOnly();
- d->mDirtyFields.insert( FieldDtStart );
- updated();
+
+ if (!dtStart.isValid() && type() != IncidenceBase::TypeTodo) {
+ kWarning() << "Invalid dtStart";
+ }
+
+ update();
+ d->mDtStart = dtStart;
+ d->mAllDay = dtStart.isDateOnly();
+ d->mDirtyFields.insert(FieldDtStart);
+ updated();
}
KDateTime IncidenceBase::dtStart() const
{
- return d->mDtStart;
+ return d->mDtStart;
}
bool IncidenceBase::allDay() const
{
- return d->mAllDay;
+ return d->mAllDay;
}
-void IncidenceBase::setAllDay( bool f )
+void IncidenceBase::setAllDay(bool f)
{
- if ( mReadOnly || f == d->mAllDay ) {
- return;
- }
- update();
- d->mAllDay = f;
- if ( d->mDtStart.isValid() ) {
- d->mDirtyFields.insert( FieldDtStart );
- }
- updated();
+ if (mReadOnly || f == d->mAllDay) {
+ return;
+ }
+ update();
+ d->mAllDay = f;
+ if (d->mDtStart.isValid()) {
+ d->mDirtyFields.insert(FieldDtStart);
+ }
+ updated();
}
-void IncidenceBase::shiftTimes( const KDateTime::Spec &oldSpec,
- const KDateTime::Spec &newSpec )
+void IncidenceBase::shiftTimes(const KDateTime::Spec &oldSpec,
+ const KDateTime::Spec &newSpec)
{
- update();
- d->mDtStart = d->mDtStart.toTimeSpec( oldSpec );
- d->mDtStart.setTimeSpec( newSpec );
- d->mDirtyFields.insert( FieldDtStart );
- d->mDirtyFields.insert( FieldDtEnd );
- updated();
+ update();
+ d->mDtStart = d->mDtStart.toTimeSpec(oldSpec);
+ d->mDtStart.setTimeSpec(newSpec);
+ d->mDirtyFields.insert(FieldDtStart);
+ d->mDirtyFields.insert(FieldDtEnd);
+ updated();
}
-void IncidenceBase::addComment( const QString &comment )
+void IncidenceBase::addComment(const QString &comment)
{
- d->mComments += comment;
+ d->mComments += comment;
}
-bool IncidenceBase::removeComment( const QString &comment )
+bool IncidenceBase::removeComment(const QString &comment)
{
- bool found = false;
- QStringList::Iterator i;
+ bool found = false;
+ QStringList::Iterator i;
- for ( i = d->mComments.begin(); !found && i != d->mComments.end(); ++i ) {
- if ( (*i) == comment ) {
- found = true;
- d->mComments.erase( i );
+ for (i = d->mComments.begin(); !found && i != d->mComments.end(); ++i) {
+ if ((*i) == comment) {
+ found = true;
+ d->mComments.erase(i);
+ }
}
- }
- if ( found ) {
- d->mDirtyFields.insert( FieldComment );
- }
+ if (found) {
+ d->mDirtyFields.insert(FieldComment);
+ }
- return found;
+ return found;
}
void IncidenceBase::clearComments()
{
- d->mDirtyFields.insert( FieldComment );
- d->mComments.clear();
+ d->mDirtyFields.insert(FieldComment);
+ d->mComments.clear();
}
QStringList IncidenceBase::comments() const
{
- return d->mComments;
+ return d->mComments;
}
-void IncidenceBase::addContact( const QString &contact )
+void IncidenceBase::addContact(const QString &contact)
{
- if ( !contact.isEmpty() ) {
- d->mContacts += contact;
- d->mDirtyFields.insert( FieldContact );
- }
+ if (!contact.isEmpty()) {
+ d->mContacts += contact;
+ d->mDirtyFields.insert(FieldContact);
+ }
}
-bool IncidenceBase::removeContact( const QString &contact )
+bool IncidenceBase::removeContact(const QString &contact)
{
- bool found = false;
- QStringList::Iterator i;
+ bool found = false;
+ QStringList::Iterator i;
- for ( i = d->mContacts.begin(); !found && i != d->mContacts.end(); ++i ) {
- if ( (*i) == contact ) {
- found = true;
- d->mContacts.erase( i );
+ for (i = d->mContacts.begin(); !found && i != d->mContacts.end(); ++i) {
+ if ((*i) == contact) {
+ found = true;
+ d->mContacts.erase(i);
+ }
}
- }
- if ( found ) {
- d->mDirtyFields.insert( FieldContact );
- }
+ if (found) {
+ d->mDirtyFields.insert(FieldContact);
+ }
- return found;
+ return found;
}
void IncidenceBase::clearContacts()
{
- d->mDirtyFields.insert( FieldContact );
- d->mContacts.clear();
+ d->mDirtyFields.insert(FieldContact);
+ d->mContacts.clear();
}
QStringList IncidenceBase::contacts() const
{
- return d->mContacts;
+ return d->mContacts;
}
-void IncidenceBase::addAttendee( const Attendee::Ptr &a, bool doupdate )
+void IncidenceBase::addAttendee(const Attendee::Ptr &a, bool doupdate)
{
- if ( !a || mReadOnly ) {
- return;
- }
+ if (!a || mReadOnly) {
+ return;
+ }
- Q_ASSERT( !d->mAttendees.contains( a ) );
+ Q_ASSERT(!d->mAttendees.contains(a));
- if ( doupdate ) {
- update();
- }
- if ( a->name().left(7).toUpper() == "MAILTO:" ) {
- a->setName( a->name().remove( 0, 7 ) );
- }
-
- /* If Uid is empty, just use the pointer to Attendee (encoded to
- * string) as Uid. Only thing that matters is that the Uid is unique
- * insofar IncidenceBase is concerned, and this does that (albeit
- * not very nicely). If these are ever saved to disk, should use
- * (considerably more expensive) CalFormat::createUniqueId(). As Uid
- * is not part of Attendee in iCal std, it's fairly safe bet that
- * these will never hit disc though so faster generation speed is
- * more important than actually being forever unique.*/
- if ( a->uid().isEmpty() ) {
- a->setUid( QString::number( (qlonglong)a.data() ) );
- }
-
- d->mAttendees.append( a );
- if ( doupdate ) {
- d->mDirtyFields.insert( FieldAttendees );
- updated();
- }
+ if (doupdate) {
+ update();
+ }
+ if (a->name().left(7).toUpper() == QLatin1String("MAILTO:")) {
+ a->setName(a->name().remove(0, 7));
+ }
+
+ /* If Uid is empty, just use the pointer to Attendee (encoded to
+ * string) as Uid. Only thing that matters is that the Uid is unique
+ * insofar IncidenceBase is concerned, and this does that (albeit
+ * not very nicely). If these are ever saved to disk, should use
+ * (considerably more expensive) CalFormat::createUniqueId(). As Uid
+ * is not part of Attendee in iCal std, it's fairly safe bet that
+ * these will never hit disc though so faster generation speed is
+ * more important than actually being forever unique.*/
+ if (a->uid().isEmpty()) {
+ a->setUid(QString::number((qlonglong)a.data()));
+ }
+
+ d->mAttendees.append(a);
+ if (doupdate) {
+ d->mDirtyFields.insert(FieldAttendees);
+ updated();
+ }
}
-void IncidenceBase::deleteAttendee( const Attendee::Ptr &a, bool doupdate )
+void IncidenceBase::deleteAttendee(const Attendee::Ptr &a, bool doupdate)
{
- if ( !a || mReadOnly ) {
- return;
- }
-
- int index = d->mAttendees.indexOf( a );
- if ( index >= 0 ) {
- if ( doupdate ) {
- update();
+ if (!a || mReadOnly) {
+ return;
}
- d->mAttendees.remove( index );
+ int index = d->mAttendees.indexOf(a);
+ if (index >= 0) {
+ if (doupdate) {
+ update();
+ }
+
+ d->mAttendees.remove(index);
- if ( doupdate ) {
- d->mDirtyFields.insert( FieldAttendees );
- updated();
+ if (doupdate) {
+ d->mDirtyFields.insert(FieldAttendees);
+ updated();
+ }
}
- }
}
Attendee::List IncidenceBase::attendees() const
{
- return d->mAttendees;
+ return d->mAttendees;
}
int IncidenceBase::attendeeCount() const
{
- return d->mAttendees.count();
+ return d->mAttendees.count();
}
void IncidenceBase::clearAttendees()
{
- if ( mReadOnly ) {
- return;
- }
- d->mDirtyFields.insert( FieldAttendees );
- d->mAttendees.clear();
+ if (mReadOnly) {
+ return;
+ }
+ d->mDirtyFields.insert(FieldAttendees);
+ d->mAttendees.clear();
}
-Attendee::Ptr IncidenceBase::attendeeByMail( const QString &email ) const
+Attendee::Ptr IncidenceBase::attendeeByMail(const QString &email) const
{
- Attendee::List::ConstIterator it;
- for ( it = d->mAttendees.constBegin(); it != d->mAttendees.constEnd(); ++it ) {
- if ( (*it)->email() == email ) {
- return *it;
+ Attendee::List::ConstIterator it;
+ for (it = d->mAttendees.constBegin(); it != d->mAttendees.constEnd(); ++it) {
+ if ((*it)->email() == email) {
+ return *it;
+ }
}
- }
- return Attendee::Ptr();
+ return Attendee::Ptr();
}
-Attendee::Ptr IncidenceBase::attendeeByMails( const QStringList &emails,
- const QString &email ) const
+Attendee::Ptr IncidenceBase::attendeeByMails(const QStringList &emails,
+ const QString &email) const
{
- QStringList mails = emails;
- if ( !email.isEmpty() ) {
- mails.append( email );
- }
+ QStringList mails = emails;
+ if (!email.isEmpty()) {
+ mails.append(email);
+ }
- Attendee::List::ConstIterator itA;
- for ( itA = d->mAttendees.constBegin(); itA != d->mAttendees.constEnd(); ++itA ) {
- for ( QStringList::const_iterator it = mails.constBegin(); it != mails.constEnd(); ++it ) {
- if ( (*itA)->email() == (*it) ) {
- return *itA;
- }
+ Attendee::List::ConstIterator itA;
+ for (itA = d->mAttendees.constBegin(); itA != d->mAttendees.constEnd(); ++itA) {
+ for (QStringList::const_iterator it = mails.constBegin(); it != mails.constEnd(); ++it) {
+ if ((*itA)->email() == (*it)) {
+ return *itA;
+ }
+ }
}
- }
- return Attendee::Ptr();
+ return Attendee::Ptr();
}
-Attendee::Ptr IncidenceBase::attendeeByUid( const QString &uid ) const
+Attendee::Ptr IncidenceBase::attendeeByUid(const QString &uid) const
{
- Attendee::List::ConstIterator it;
- for ( it = d->mAttendees.constBegin(); it != d->mAttendees.constEnd(); ++it ) {
- if ( (*it)->uid() == uid ) {
- return *it;
+ Attendee::List::ConstIterator it;
+ for (it = d->mAttendees.constBegin(); it != d->mAttendees.constEnd(); ++it) {
+ if ((*it)->uid() == uid) {
+ return *it;
+ }
}
- }
- return Attendee::Ptr();
+ return Attendee::Ptr();
}
-void IncidenceBase::setDuration( const Duration &duration )
+void IncidenceBase::setDuration(const Duration &duration)
{
- update();
- d->mDuration = duration;
- setHasDuration( true );
- d->mDirtyFields.insert( FieldDuration );
- updated();
+ update();
+ d->mDuration = duration;
+ setHasDuration(true);
+ d->mDirtyFields.insert(FieldDuration);
+ updated();
}
Duration IncidenceBase::duration() const
{
- return d->mDuration;
+ return d->mDuration;
}
-void IncidenceBase::setHasDuration( bool hasDuration )
+void IncidenceBase::setHasDuration(bool hasDuration)
{
- d->mHasDuration = hasDuration;
+ d->mHasDuration = hasDuration;
}
bool IncidenceBase::hasDuration() const
{
- return d->mHasDuration;
+ return d->mHasDuration;
}
-void IncidenceBase::registerObserver( IncidenceBase::IncidenceObserver *observer )
+void IncidenceBase::setUrl(const QUrl& url)
{
- if ( observer && !d->mObservers.contains( observer ) ) {
- d->mObservers.append( observer );
- }
+ d->mDirtyFields.insert(FieldUrl);
+ d->mUrl = url;
+}
+
+QUrl IncidenceBase::url() const
+{
+ return d->mUrl;
+}
+
+void IncidenceBase::registerObserver(IncidenceBase::IncidenceObserver *observer)
+{
+ if (observer && !d->mObservers.contains(observer)) {
+ d->mObservers.append(observer);
+ }
}
-void IncidenceBase::unRegisterObserver( IncidenceBase::IncidenceObserver *observer )
+void IncidenceBase::unRegisterObserver(IncidenceBase::IncidenceObserver *observer)
{
- d->mObservers.removeAll( observer );
+ d->mObservers.removeAll(observer);
}
void IncidenceBase::update()
{
- if ( !d->mUpdateGroupLevel ) {
- d->mUpdatedPending = true;
- KDateTime rid = recurrenceId();
- foreach ( IncidenceObserver *o, d->mObservers ) {
- o->incidenceUpdate( uid(), rid );
+ if (!d->mUpdateGroupLevel) {
+ d->mUpdatedPending = true;
+ KDateTime rid = recurrenceId();
+ foreach(IncidenceObserver *o, d->mObservers) {
+ o->incidenceUpdate(uid(), rid);
+ }
}
- }
}
void IncidenceBase::updated()
{
- if ( d->mUpdateGroupLevel ) {
- d->mUpdatedPending = true;
- } else {
- KDateTime rid = recurrenceId();
- foreach ( IncidenceObserver *o, d->mObservers ) {
- o->incidenceUpdated( uid(), rid );
+ if (d->mUpdateGroupLevel) {
+ d->mUpdatedPending = true;
+ } else {
+ const KDateTime rid = recurrenceId();
+ foreach(IncidenceObserver *o, d->mObservers) {
+ o->incidenceUpdated(uid(), rid);
+ }
}
- }
}
void IncidenceBase::startUpdates()
{
- update();
- ++d->mUpdateGroupLevel;
+ update();
+ ++d->mUpdateGroupLevel;
}
void IncidenceBase::endUpdates()
{
- if ( d->mUpdateGroupLevel > 0 ) {
- if ( --d->mUpdateGroupLevel == 0 && d->mUpdatedPending ) {
- d->mUpdatedPending = false;
- updated();
+ if (d->mUpdateGroupLevel > 0) {
+ if (--d->mUpdateGroupLevel == 0 && d->mUpdatedPending) {
+ d->mUpdatedPending = false;
+ updated();
+ }
}
- }
}
void IncidenceBase::customPropertyUpdate()
{
- update();
+ update();
}
void IncidenceBase::customPropertyUpdated()
{
- updated();
+ updated();
}
KDateTime IncidenceBase::recurrenceId() const
{
- return KDateTime();
+ return KDateTime();
}
void IncidenceBase::resetDirtyFields()
{
- d->mDirtyFields.clear();
+ d->mDirtyFields.clear();
}
QSet<IncidenceBase::Field> IncidenceBase::dirtyFields() const
{
- return d->mDirtyFields;
+ return d->mDirtyFields;
+}
+
+void IncidenceBase::setFieldDirty(IncidenceBase::Field field)
+{
+ d->mDirtyFields.insert(field);
+}
+
+KUrl IncidenceBase::uri() const
+{
+ return KUrl(QLatin1String("urn:x-ical:") + uid());
+}
+
+void IncidenceBase::setDirtyFields(const QSet<IncidenceBase::Field> &dirtyFields)
+{
+ d->mDirtyFields = dirtyFields;
}
-void IncidenceBase::setFieldDirty( IncidenceBase::Field field )
+/** static */
+quint32 IncidenceBase::magicSerializationIdentifier()
{
- d->mDirtyFields.insert( field );
+ return KCALCORE_MAGIC_NUMBER;
}
-QUrl IncidenceBase::uri() const
+QDataStream& KCalCore::operator<<(QDataStream &out, const KCalCore::IncidenceBase::Ptr &i)
{
- return QUrl( QString( "urn:x-ical:" ) + uid() );
+ if (!i)
+ return out;
+
+ out << static_cast<quint32>(KCALCORE_MAGIC_NUMBER); // Magic number to identify KCalCore data
+ out << static_cast<quint32>(KCALCORE_SERIALIZATION_VERSION);
+ out << static_cast<qint32>(i->type());
+
+ out << *(static_cast<CustomProperties*>(i.data()));
+ out << i->d->mLastModified << i->d->mDtStart << i->organizer() << i->d->mUid << i->d->mDuration
+ << i->d->mAllDay << i->d->mHasDuration << i->d->mComments << i->d->mContacts
+ << i->d->mAttendees.count() << i->d->mUrl;
+
+ foreach(const Attendee::Ptr &attendee, i->d->mAttendees) {
+ out << attendee;
+ }
+
+ // Serialize the sub-class data. In KDE5 we can add new virtuals.
+ i->virtual_hook(KCalCore::IncidenceBase::SerializerHook, &out);
+
+ return out;
}
-void IncidenceBase::setDirtyFields( const QSet<IncidenceBase::Field> &dirtyFields )
+QDataStream& KCalCore::operator>>(QDataStream &in, const KCalCore::IncidenceBase::Ptr &i)
{
- d->mDirtyFields = dirtyFields;
+ if (!i)
+ return in;
+
+ qint32 attendeeCount, type;
+ quint32 magic, version;
+
+ in >> magic;
+
+ if (magic != KCALCORE_MAGIC_NUMBER) {
+ kWarning() << "Invalid magic on serialized data";
+ return in;
+ }
+
+ in >> version;
+
+ if (version > KCALCORE_MAGIC_NUMBER) {
+ kWarning() << "Invalid version on serialized data";
+ return in;
+ }
+
+ in >> type;
+
+ in >> *(static_cast<CustomProperties*>(i.data()));
+ in >> i->d->mLastModified >> i->d->mDtStart >> i->d->mOrganizer >> i->d->mUid >> i->d->mDuration
+ >> i->d->mAllDay >> i->d->mHasDuration >> i->d->mComments >> i->d->mContacts >> attendeeCount
+ >> i->d->mUrl;
+
+ i->d->mAttendees.clear();
+ for (int it=0; it<attendeeCount; it++) {
+ Attendee::Ptr attendee = Attendee::Ptr(new Attendee(QString(), QString()));
+ in >> attendee;
+ i->d->mAttendees.append(attendee);
+ }
+
+ // Deserialize the sub-class data. In KDE5 we can add new virtuals.
+ i->virtual_hook(KCalCore::IncidenceBase::DeserializerHook, &in);
+
+ return in;
}
IncidenceBase::IncidenceObserver::~IncidenceObserver()
diff --git a/kcalcore/incidencebase.h b/kcalcore/incidencebase.h
index 96ecdf5..e2f0847 100644
--- a/kcalcore/incidencebase.h
+++ b/kcalcore/incidencebase.h
@@ -61,9 +61,11 @@
#include "duration.h"
#include "sortablelist.h"
-#include <kdatetime.h>
+#include <KDE/KDateTime>
#include <QtCore/QSet>
+#include <QtCore/QUrl>
+#include <QDataStream>
class KUrl;
class QDate;
@@ -106,7 +108,7 @@ class Visitor;
*/
class KCALCORE_EXPORT IncidenceBase : public CustomProperties
{
- public:
+public:
/**
A shared pointer to an IncidenceBase.
*/
@@ -117,11 +119,11 @@ class KCALCORE_EXPORT IncidenceBase : public CustomProperties
@see type(), typeStr()
*/
enum IncidenceType {
- TypeEvent = 0, /**< Type is an event */
- TypeTodo, /**< Type is a to-do */
- TypeJournal, /**< Type is a journal */
- TypeFreeBusy, /**< Type is a free/busy */
- TypeUnknown /**< Type unknown */
+ TypeEvent = 0, /**< Type is an event */
+ TypeTodo, /**< Type is a to-do */
+ TypeJournal, /**< Type is a journal */
+ TypeFreeBusy, /**< Type is a free/busy */
+ TypeUnknown /**< Type unknown */
};
/**
@@ -129,62 +131,66 @@ class KCALCORE_EXPORT IncidenceBase : public CustomProperties
@see dateTime()
*/
enum DateTimeRole {
- RoleAlarmStartOffset = 0,/**< Role for an incidence alarm's starting offset date/time */
- RoleAlarmEndOffset, /**< Role for an incidence alarm's ending offset date/time */
- RoleSort, /**< Role for an incidence's date/time used when sorting */
- RoleCalendarHashing, /**< Role for looking up an incidence in a Calendar */
- RoleStartTimeZone, /**< Role for determining an incidence's starting timezone */
- RoleEndTimeZone, /**< Role for determining an incidence's ending timezone */
- RoleEndRecurrenceBase,
- RoleEnd, /**< Role for determining an incidence's dtEnd, will return
+ RoleAlarmStartOffset = 0,/**< Role for an incidence alarm's starting offset date/time */
+ RoleAlarmEndOffset, /**< Role for an incidence alarm's ending offset date/time */
+ RoleSort, /**< Role for an incidence's date/time used when sorting */
+ RoleCalendarHashing, /**< Role for looking up an incidence in a Calendar */
+ RoleStartTimeZone, /**< Role for determining an incidence's starting timezone */
+ RoleEndTimeZone, /**< Role for determining an incidence's ending timezone */
+ RoleEndRecurrenceBase,
+ RoleEnd, /**< Role for determining an incidence's dtEnd, will return
an invalid KDateTime if the incidence does not support dtEnd */
- RoleDisplayEnd, /**< Role used for display purposes, represents the end boundary
+ RoleDisplayEnd, /**< Role used for display purposes, represents the end boundary
if an incidence supports dtEnd */
- RoleAlarm, /**< Role for determining the date/time of the first alarm.
+ RoleAlarm, /**< Role for determining the date/time of the first alarm.
Returns invalid time if the incidence doesn't have any alarm */
- RoleRecurrenceStart, /**< Role for determining the start of the recurrence.
+ RoleRecurrenceStart, /**< Role for determining the start of the recurrence.
Currently that's DTSTART for an event and DTDUE for a to-do.
(NOTE: If the incidence is a to-do, recurrence should be
calculated having DTSTART for a reference, not DT-DUE.
This is one place KCalCore isn't compliant with RFC2445) */
- RoleDisplayStart, /**< Role for display purposes, represents the start boundary of an
+ RoleDisplayStart, /**< Role for display purposes, represents the start boundary of an
incidence. To-dos return dtDue here, for historical reasons */
- RoleDnD /**< Role for determining new start and end dates after a DnD */
+ RoleDnD /**< Role for determining new start and end dates after a DnD */
};
+ /**
+ The different types of incidence fields.
+ */
enum Field {
- FieldDtStart, ///> Field representing the DTSTART component.
- FieldDtEnd, ///> Field representing the DTEND component.
- FieldLastModified, ///> Field representing the LAST-MODIFIED component.
- FieldDescription, ///> Field representing the DESCRIPTION component.
- FieldSummary, ///> Field representing the SUMMARY component.
- FieldLocation, ///> Field representing the LOCATION component.
- FieldCompleted, ///> Field representing the COMPLETED component.
- FieldPercentComplete, ///> Field representing the PERCENT-COMPLETE component.
- FieldDtDue, ///> Field representing the DUE component.
- FieldCategories, ///> Field representing the CATEGORIES component.
- FieldRelatedTo, ///> Field representing the RELATED-TO component.
- FieldRecurrence, ///> Field representing the EXDATE, EXRULE, RDATE, and RRULE components.
- FieldAttachment, ///> Field representing the ATTACH component.
- FieldSecrecy, ///> Field representing the CLASS component.
- FieldStatus, ///> Field representing the STATUS component.
- FieldTransparency, ///> Field representing the TRANSPARENCY component.
- FieldResources, ///> Field representing the RESOURCES component.
- FieldPriority, ///> Field representing the PRIORITY component.
- FieldGeoLatitude, ///> Field representing the latitude part of the GEO component.
- FieldGeoLongitude, ///> Field representing the longitude part of the GEO component.
- FieldRecurrenceId, ///> Field representing the RECURRENCE-ID component.
- FieldAlarms, ///> Field representing the VALARM component.
- FieldSchedulingId, ///> Field representing the X-KDE-LIBKCAL-ID component.
- FieldAttendees, ///> Field representing the ATTENDEE component.
- FieldOrganizer, ///> Field representing the ORGANIZER component.
- FieldCreated, ///> Field representing the CREATED component.
- FieldRevision, ///> Field representing the SEQUENCE component.
- FieldDuration, ///> Field representing the DURATION component.
- FieldContact, ///> Field representing the CONTACT component.
- FieldComment, ///> Field representing the COMMENT component.
- FieldUid, ///> Field representing the UID component.
- FieldUnknown ///> Something changed. Always set when you use the assignment operator.
+ FieldDtStart, ///> Field representing the DTSTART component.
+ FieldDtEnd, ///> Field representing the DTEND component.
+ FieldLastModified, ///> Field representing the LAST-MODIFIED component.
+ FieldDescription, ///> Field representing the DESCRIPTION component.
+ FieldSummary, ///> Field representing the SUMMARY component.
+ FieldLocation, ///> Field representing the LOCATION component.
+ FieldCompleted, ///> Field representing the COMPLETED component.
+ FieldPercentComplete, ///> Field representing the PERCENT-COMPLETE component.
+ FieldDtDue, ///> Field representing the DUE component.
+ FieldCategories, ///> Field representing the CATEGORIES component.
+ FieldRelatedTo, ///> Field representing the RELATED-TO component.
+ FieldRecurrence, ///> Field representing the EXDATE, EXRULE, RDATE, and RRULE components.
+ FieldAttachment, ///> Field representing the ATTACH component.
+ FieldSecrecy, ///> Field representing the CLASS component.
+ FieldStatus, ///> Field representing the STATUS component.
+ FieldTransparency, ///> Field representing the TRANSPARENCY component.
+ FieldResources, ///> Field representing the RESOURCES component.
+ FieldPriority, ///> Field representing the PRIORITY component.
+ FieldGeoLatitude, ///> Field representing the latitude part of the GEO component.
+ FieldGeoLongitude, ///> Field representing the longitude part of the GEO component.
+ FieldRecurrenceId, ///> Field representing the RECURRENCE-ID component.
+ FieldAlarms, ///> Field representing the VALARM component.
+ FieldSchedulingId, ///> Field representing the X-KDE-LIBKCAL-ID component.
+ FieldAttendees, ///> Field representing the ATTENDEE component.
+ FieldOrganizer, ///> Field representing the ORGANIZER component.
+ FieldCreated, ///> Field representing the CREATED component.
+ FieldRevision, ///> Field representing the SEQUENCE component.
+ FieldDuration, ///> Field representing the DURATION component.
+ FieldContact, ///> Field representing the CONTACT component.
+ FieldComment, ///> Field representing the COMMENT component.
+ FieldUid, ///> Field representing the UID component.
+ FieldUnknown, ///> Something changed. Always set when you use the assignment operator.
+ FieldUrl ///> Field representing the URL component.
};
/**
@@ -192,7 +198,7 @@ class KCALCORE_EXPORT IncidenceBase : public CustomProperties
*/
class KCALCORE_EXPORT IncidenceObserver
{
- public:
+ public:
/**
Destroys the IncidenceObserver.
@@ -201,19 +207,19 @@ class KCALCORE_EXPORT IncidenceBase : public CustomProperties
/**
The IncidenceObserver interface.
- This function is called before any changes are made.
+ This function is called before any changes are made.
@param uid is the string containing the incidence @ref uid.
@param recurrenceId is possible recurrenceid of incidence.
*/
- virtual void incidenceUpdate( const QString &uid, const KDateTime &recurrenceId ) = 0;
+ virtual void incidenceUpdate(const QString &uid, const KDateTime &recurrenceId) = 0;
/**
The IncidenceObserver interface.
- This function is called after changes are completed.
+ This function is called after changes are completed.
@param uid is the string containing the incidence @ref uid.
@param recurrenceId is possible recurrenceid of incidence.
*/
- virtual void incidenceUpdated( const QString &uid, const KDateTime &recurrenceId ) = 0;
+ virtual void incidenceUpdated(const QString &uid, const KDateTime &recurrenceId) = 0;
};
/**
@@ -235,7 +241,7 @@ class KCALCORE_EXPORT IncidenceBase : public CustomProperties
if ( i1.type() == i2.type() ) {
i1 = i2;
} else {
- qDebug() << "Invalid assignment!";
+ kDebug() << "Invalid assignment!";
}
@endcode
@@ -243,7 +249,7 @@ class KCALCORE_EXPORT IncidenceBase : public CustomProperties
@param other is the IncidenceBase to assign.
*/
- IncidenceBase &operator=( const IncidenceBase &other );
+ IncidenceBase &operator=(const IncidenceBase &other);
/**
Compares this with IncidenceBase @p ib for equality.
@@ -251,26 +257,26 @@ class KCALCORE_EXPORT IncidenceBase : public CustomProperties
@param ib is the IncidenceBase to compare against.
@return true if the incidences are equal; false otherwise.
*/
- bool operator==( const IncidenceBase &ib ) const;
+ bool operator==(const IncidenceBase &ib) const;
/**
Compares this with IncidenceBase @p ib for inequality.
@param ib is the IncidenceBase to compare against.
@return true if the incidences are /not/ equal; false otherwise.
*/
- bool operator!=( const IncidenceBase &ib ) const;
+ bool operator!=(const IncidenceBase &ib) const;
- /**
- Accept IncidenceVisitor. A class taking part in the visitor mechanism
- has to provide this implementation:
- <pre>
- bool accept(Visitor &v) { return v.visit(this); }
- </pre>
+ /**
+ Accept IncidenceVisitor. A class taking part in the visitor mechanism
+ has to provide this implementation:
+ <pre>
+ bool accept(Visitor &v) { return v.visit(this); }
+ </pre>
- @param v is a reference to a Visitor object.
- @param incidence is a valid IncidenceBase object for visting.
+ @param v is a reference to a Visitor object.
+ @param incidence is a valid IncidenceBase object for visting.
*/
- virtual bool accept( Visitor &v, IncidenceBase::Ptr incidence );
+ virtual bool accept(Visitor &v, IncidenceBase::Ptr incidence);
/**
Returns the incidence type.
@@ -287,7 +293,7 @@ class KCALCORE_EXPORT IncidenceBase : public CustomProperties
@param uid is the string containing the incidence @ref uid.
@see uid()
*/
- void setUid( const QString &uid );
+ void setUid(const QString &uid);
/**
Returns the unique id (@ref uid) for the incidence.
@@ -298,7 +304,7 @@ class KCALCORE_EXPORT IncidenceBase : public CustomProperties
/**
Returns the uri for the incidence, of form urn:x-ical:\<uid\>
*/
- QUrl uri() const;
+ KUrl uri() const;
/**
Sets the time the incidence was last modified to @p lm.
@@ -308,7 +314,7 @@ class KCALCORE_EXPORT IncidenceBase : public CustomProperties
@see lastModified()
*/
- virtual void setLastModified( const KDateTime &lm );
+ virtual void setLastModified(const KDateTime &lm);
/**
Returns the time the incidence was last modified.
@@ -319,10 +325,10 @@ class KCALCORE_EXPORT IncidenceBase : public CustomProperties
/**
Sets the organizer for the incidence.
- @param organizer is a Person to use as the incidence @ref organizer.
+ @param organizer is a non-null Person to use as the incidence @ref organizer.
@see organizer(), setOrganizer(const QString &)
*/
- void setOrganizer( const Person::Ptr &organizer );
+ void setOrganizer(const Person::Ptr &organizer);
/**
Sets the incidence organizer to any string @p organizer.
@@ -330,10 +336,12 @@ class KCALCORE_EXPORT IncidenceBase : public CustomProperties
@param organizer is a string to use as the incidence @ref organizer.
@see organizer(), setOrganizer(const Person &)
*/
- void setOrganizer( const QString &organizer );
+ void setOrganizer(const QString &organizer);
/**
Returns the Person associated with this incidence.
+ If no Person was set through setOrganizer(), a default Person()
+ is returned.
@see setOrganizer(const QString &), setOrganizer(const Person &)
*/
Person::Ptr organizer() const;
@@ -345,7 +353,7 @@ class KCALCORE_EXPORT IncidenceBase : public CustomProperties
can be modified.
@see isReadOnly().
*/
- virtual void setReadOnly( bool readOnly );
+ virtual void setReadOnly(bool readOnly);
/**
Returns true the object is read-only; false otherwise.
@@ -361,7 +369,7 @@ class KCALCORE_EXPORT IncidenceBase : public CustomProperties
@param dtStart is the incidence start date/time.
@see dtStart().
*/
- virtual void setDtStart( const KDateTime &dtStart );
+ virtual void setDtStart(const KDateTime &dtStart);
/**
Returns an incidence's starting date/time as a KDateTime.
@@ -376,7 +384,7 @@ class KCALCORE_EXPORT IncidenceBase : public CustomProperties
@see duration()
*/
- virtual void setDuration( const Duration &duration );
+ virtual void setDuration(const Duration &duration);
/**
Returns the length of the incidence duration.
@@ -389,7 +397,7 @@ class KCALCORE_EXPORT IncidenceBase : public CustomProperties
@param hasDuration true if the incidence has a duration; false otherwise.
@see hasDuration()
*/
- void setHasDuration( bool hasDuration );
+ void setHasDuration(bool hasDuration);
/**
Returns true if the incidence has a duration; false otherwise.
@@ -412,7 +420,7 @@ class KCALCORE_EXPORT IncidenceBase : public CustomProperties
@see allDay()
*/
- void setAllDay( bool allDay );
+ void setAllDay(bool allDay);
/**
Shift the times of the incidence so that they appear at the same clock
@@ -428,17 +436,17 @@ class KCALCORE_EXPORT IncidenceBase : public CustomProperties
@param oldSpec the time specification which provides the clock times
@param newSpec the new time specification
*/
- virtual void shiftTimes( const KDateTime::Spec &oldSpec,
- const KDateTime::Spec &newSpec );
+ virtual void shiftTimes(const KDateTime::Spec &oldSpec,
+ const KDateTime::Spec &newSpec);
/**
- Adds a comment to thieincidence. Does not add a linefeed character; simply
+ Adds a comment to the incidence. Does not add a linefeed character; simply
appends the text as specified.
@param comment is the QString containing the comment to add.
@see removeComment().
*/
- void addComment( const QString &comment );
+ void addComment(const QString &comment);
/**
Removes a comment from the incidence. Removes the first comment whose
@@ -448,7 +456,7 @@ class KCALCORE_EXPORT IncidenceBase : public CustomProperties
@return true if match found, false otherwise.
@see addComment().
*/
- bool removeComment( const QString &comment );
+ bool removeComment(const QString &comment);
/**
Deletes all incidence comments.
@@ -467,7 +475,7 @@ class KCALCORE_EXPORT IncidenceBase : public CustomProperties
@param contact is the QString containing the contact to add.
@see removeContact().
*/
- void addContact( const QString &contact );
+ void addContact(const QString &contact);
/**
Removes a contact from the incidence. Removes the first contact whose
@@ -477,7 +485,7 @@ class KCALCORE_EXPORT IncidenceBase : public CustomProperties
@return true if match found, false otherwise.
@see addContact().
*/
- bool removeContact( const QString &contact );
+ bool removeContact(const QString &contact);
/**
Deletes all incidence contacts.
@@ -496,8 +504,8 @@ class KCALCORE_EXPORT IncidenceBase : public CustomProperties
@param attendee a pointer to the attendee to add
@param doUpdate If true the Observers are notified, if false they are not.
*/
- void addAttendee( const Attendee::Ptr &attendee,
- bool doUpdate = true );
+ void addAttendee(const Attendee::Ptr &attendee,
+ bool doUpdate = true);
/**
Removes all attendees from the incidence.
@@ -512,8 +520,8 @@ class KCALCORE_EXPORT IncidenceBase : public CustomProperties
@param attendee The attendee to be removeComment
@param doUpdate If true the Observers are notified, if false they are not.
*/
- void deleteAttendee( const Attendee::Ptr &attendee,
- bool doUpdate = true );
+ void deleteAttendee(const Attendee::Ptr &attendee,
+ bool doUpdate = true);
/**
Returns a list of incidence attendees.
@@ -533,7 +541,7 @@ class KCALCORE_EXPORT IncidenceBase : public CustomProperties
form "FirstName LastName <emailaddress>".
@see attendeeByMails(), attendeesByUid().
*/
- Attendee::Ptr attendeeByMail( const QString &email ) const;
+ Attendee::Ptr attendeeByMail(const QString &email) const;
/**
Returns the first incidence attendee with one of the specified
@@ -545,8 +553,8 @@ class KCALCORE_EXPORT IncidenceBase : public CustomProperties
in addition to the list specified in @p emails.
@see attendeeByMail(), attendeesByUid().
*/
- Attendee::Ptr attendeeByMails( const QStringList &emails,
- const QString &email = QString() ) const;
+ Attendee::Ptr attendeeByMails(const QStringList &emails,
+ const QString &email = QString()) const;
/**
Returns the incidence attendee with the specified attendee @acronym UID.
@@ -554,7 +562,27 @@ class KCALCORE_EXPORT IncidenceBase : public CustomProperties
@param uid is a QString containing an attendee @acronym UID.
@see attendeeByMail(), attendeeByMails().
*/
- Attendee::Ptr attendeeByUid( const QString &uid ) const;
+ Attendee::Ptr attendeeByUid(const QString &uid) const;
+
+ /**
+ Sets the incidences url.
+
+ This property can be used to point to a more dynamic rendition of the incidence.
+ I.e. a website related to the incidence.
+
+ @param url of the incience.
+ @see url()
+ @since 4.12
+ */
+ void setUrl(const QUrl &url);
+
+ /**
+ Returns the url.
+ @return incidences url value
+ @see setUrl()
+ @since 4.12
+ */
+ QUrl url() const;
/**
Register observer. The observer is notified when the observed object
@@ -564,7 +592,7 @@ class KCALCORE_EXPORT IncidenceBase : public CustomProperties
watching this incidence.
@see unRegisterObserver()
*/
- void registerObserver( IncidenceObserver *observer );
+ void registerObserver(IncidenceObserver *observer);
/**
Unregister observer. It isn't notified anymore about changes.
@@ -573,7 +601,7 @@ class KCALCORE_EXPORT IncidenceBase : public CustomProperties
watching this incidence.
@see registerObserver().
*/
- void unRegisterObserver( IncidenceObserver *observer );
+ void unRegisterObserver(IncidenceObserver *observer);
/**
Call this to notify the observers after the IncidenceBase object will be
@@ -605,14 +633,14 @@ class KCALCORE_EXPORT IncidenceBase : public CustomProperties
Returns a date/time corresponding to the specified DateTimeRole.
@param role is a DateTimeRole.
*/
- virtual KDateTime dateTime( DateTimeRole role ) const = 0;
+ virtual KDateTime dateTime(DateTimeRole role) const = 0;
/**
Sets the date/time corresponding to the specified DateTimeRole.
@param dateTime is KDateTime value to set.
@param role is a DateTimeRole.
*/
- virtual void setDateTime( const KDateTime &dateTime, DateTimeRole role ) = 0;
+ virtual void setDateTime(const KDateTime &dateTime, DateTimeRole role) = 0;
/**
Returns the Akonadi specific sub MIME type of a KCalCore::IncidenceBase item,
@@ -640,7 +668,7 @@ class KCALCORE_EXPORT IncidenceBase : public CustomProperties
@see dirtyFields()
@since 4.8
*/
- void setDirtyFields( const QSet<IncidenceBase::Field> & );
+ void setDirtyFields(const QSet<IncidenceBase::Field> &);
/**
Resets dirty fields.
@@ -648,13 +676,21 @@ class KCALCORE_EXPORT IncidenceBase : public CustomProperties
*/
void resetDirtyFields();
- protected:
+ /**
+ * Constant that identifies KCalCore data in a binary stream.
+ *
+ * @since 4.12
+ */
+ static quint32 magicSerializationIdentifier();
+
+protected:
/**
Marks Field @p field as dirty.
+ @param field is the Field type to mark as dirty.
@see dirtyFields()
*/
- void setFieldDirty( IncidenceBase::Field field );
+ void setFieldDirty(IncidenceBase::Field field);
/**
@copydoc
@@ -670,10 +706,9 @@ class KCALCORE_EXPORT IncidenceBase : public CustomProperties
/**
Constructs an IncidenceBase as a copy of another IncidenceBase object.
-
@param ib is the IncidenceBase to copy.
*/
- IncidenceBase( const IncidenceBase &ib );
+ IncidenceBase(const IncidenceBase &ib);
/**
Provides polymorfic comparison for equality.
@@ -682,13 +717,13 @@ class KCALCORE_EXPORT IncidenceBase : public CustomProperties
@param incidenceBase is the IncidenceBase to compare against.
@return true if the incidences are equal; false otherwise.
*/
- virtual bool equals( const IncidenceBase &incidenceBase ) const;
+ virtual bool equals(const IncidenceBase &incidenceBase) const;
/**
Provides polymorfic assignment.
@param other is the IncidenceBase to assign.
*/
- virtual IncidenceBase &assign( const IncidenceBase &other );
+ virtual IncidenceBase &assign(const IncidenceBase &other);
/**
Standard trick to add virtuals later.
@@ -696,21 +731,56 @@ class KCALCORE_EXPORT IncidenceBase : public CustomProperties
@param id is any integer unique to this class which we will use to identify the method
to be called.
@param data is a pointer to some glob of data, typically a struct.
+ // TODO_KDE5: change from int to VirtualHook type.
*/
- virtual void virtual_hook( int id, void *data ) = 0;
+ virtual void virtual_hook(int id, void *data) = 0;
+
+ enum VirtualHook {
+ SerializerHook,
+ DeserializerHook
+ };
/**
Identifies a read-only incidence.
*/
bool mReadOnly;
- private:
+private:
//@cond PRIVATE
class Private;
Private *const d;
//@endcond
+
+ friend KCALCORE_EXPORT QDataStream &operator<<(QDataStream &stream,
+ const KCalCore::IncidenceBase::Ptr &);
+
+ friend KCALCORE_EXPORT QDataStream &operator>>(QDataStream &stream,
+ const KCalCore::IncidenceBase::Ptr &);
};
+/**
+ * Incidence serializer.
+ * Uses the virtual_hook internally to avoid slicing.
+ *
+ * // TODO_KDE5: Provide a virtual serialize() method, as done with assign() and equals().
+ *
+ * @since 4.12
+ */
+KCALCORE_EXPORT QDataStream &operator<<(QDataStream &out, const KCalCore::IncidenceBase::Ptr &);
+
+/**
+ * Incidence deserializer.
+ * Uses the virtual_hook internally to avoid slicing.
+ *
+ * // TODO_KDE5: Provide a virtual serialize() method, as done with assign() and equals().
+ *
+ * @since 4.12
+ */
+KCALCORE_EXPORT QDataStream &operator>>(QDataStream &in, const KCalCore::IncidenceBase::Ptr &);
+
}
+Q_DECLARE_METATYPE(KCalCore::IncidenceBase *)
+Q_DECLARE_METATYPE(KCalCore::IncidenceBase::Ptr)
+
#endif
diff --git a/kcalcore/memorycalendar.cpp b/kcalcore/memorycalendar.cpp
index 397382b..71f669f 100644
--- a/kcalcore/memorycalendar.cpp
+++ b/kcalcore/memorycalendar.cpp
@@ -34,7 +34,10 @@
#include "memorycalendar.h"
-#include <QtCore/QDebug>
+#include <KDebug>
+#include <QDate>
+#include <QDataStream>
+#include <KDateTime>
using namespace KCalCore;
@@ -45,9 +48,9 @@ using namespace KCalCore;
//@cond PRIVATE
class KCalCore::MemoryCalendar::Private
{
- public:
- Private( MemoryCalendar *qq )
- : q( qq ), mFormat( 0 )
+public:
+ Private(MemoryCalendar *qq)
+ : q(qq), mFormat(0)
{
}
~Private()
@@ -55,8 +58,8 @@ class KCalCore::MemoryCalendar::Private
}
MemoryCalendar *q;
- QString mFileName; // filename where calendar is stored
CalFormat *mFormat; // calendar format
+ QString mIncidenceBeingUpdated; // Instance identifier of Incidence currently being updated
/**
* List of all incidences.
@@ -65,6 +68,11 @@ class KCalCore::MemoryCalendar::Private
QMap<IncidenceBase::IncidenceType, QMultiHash<QString, Incidence::Ptr> > mIncidences;
/**
+ * Has all incidences, indexed by identifier.
+ */
+ QHash<QString,KCalCore::Incidence::Ptr> mIncidencesByIdentifier;
+
+ /**
* List of all deleted incidences.
* First indexed by incidence->type(), then by incidence->uid();
*/
@@ -83,726 +91,772 @@ class KCalCore::MemoryCalendar::Private
*/
QMap<IncidenceBase::IncidenceType, QMultiHash<QString, IncidenceBase::Ptr> > mIncidencesForDate;
- void insertIncidence( Incidence::Ptr incidence );
+ void insertIncidence(const Incidence::Ptr &incidence);
- Incidence::Ptr incidence( const QString &uid,
- const IncidenceBase::IncidenceType type,
- const KDateTime &recurrenceId = KDateTime() ) const;
+ Incidence::Ptr incidence(const QString &uid,
+ const IncidenceBase::IncidenceType type,
+ const KDateTime &recurrenceId = KDateTime()) const;
- Incidence::Ptr deletedIncidence( const QString &uid,
- const KDateTime &recurrenceId,
- const IncidenceBase::IncidenceType type ) const;
+ Incidence::Ptr deletedIncidence(const QString &uid,
+ const KDateTime &recurrenceId,
+ const IncidenceBase::IncidenceType type) const;
- void deleteAllIncidences( const IncidenceBase::IncidenceType type );
+ void deleteAllIncidences(const IncidenceBase::IncidenceType type);
};
+//@endcond
-MemoryCalendar::MemoryCalendar( const KDateTime::Spec &timeSpec )
- : Calendar( timeSpec ),
- d( new KCalCore::MemoryCalendar::Private( this ) )
+MemoryCalendar::MemoryCalendar(const KDateTime::Spec &timeSpec)
+ : Calendar(timeSpec),
+ d(new KCalCore::MemoryCalendar::Private(this))
{
}
-MemoryCalendar::MemoryCalendar( const QString &timeZoneId )
- : Calendar( timeZoneId ),
- d( new KCalCore::MemoryCalendar::Private( this ) )
+MemoryCalendar::MemoryCalendar(const QString &timeZoneId)
+ : Calendar(timeZoneId),
+ d(new KCalCore::MemoryCalendar::Private(this))
{
}
MemoryCalendar::~MemoryCalendar()
{
- close();
- delete d;
+ close();
+ delete d;
}
void MemoryCalendar::close()
{
- setObserversEnabled( false );
- d->mFileName.clear();
+ setObserversEnabled(false);
- deleteAllEvents();
- deleteAllTodos();
- deleteAllJournals();
+ // Don't call the virtual function deleteEvents() etc, the base class might have
+ // other ways of deleting the data.
+ d->deleteAllIncidences(Incidence::TypeEvent);
+ d->deleteAllIncidences(Incidence::TypeTodo);
+ d->deleteAllIncidences(Incidence::TypeJournal);
- d->mDeletedIncidences.clear();
+ d->mIncidencesByIdentifier.clear();
+ d->mDeletedIncidences.clear();
- setModified( false );
+ setModified(false);
- setObserversEnabled( true );
+ setObserversEnabled(true);
}
-bool MemoryCalendar::deleteIncidence( const Incidence::Ptr &incidence )
+bool MemoryCalendar::deleteIncidence(const Incidence::Ptr &incidence)
{
- // Handle orphaned children
- // relations is an Incidence's property, not a Todo's, so
- // we remove relations in deleteIncidence, not in deleteTodo.
- removeRelations( incidence );
- const Incidence::IncidenceType type = incidence->type();
- const QString uid = incidence->uid();
- if ( d->mIncidences[type].remove( uid, incidence ) ) {
- setModified( true );
- notifyIncidenceDeleted( incidence );
- d->mDeletedIncidences[type].insert( uid, incidence );
+ // Handle orphaned children
+ // relations is an Incidence's property, not a Todo's, so
+ // we remove relations in deleteIncidence, not in deleteTodo.
+ removeRelations(incidence);
+ const Incidence::IncidenceType type = incidence->type();
+ const QString uid = incidence->uid();
+ if (d->mIncidences[type].remove(uid, incidence)) {
+ d->mIncidencesByIdentifier.remove(incidence->instanceIdentifier());
+ setModified(true);
+ notifyIncidenceDeleted(incidence);
+ if (deletionTracking())
+ d->mDeletedIncidences[type].insert(uid, incidence);
- const KDateTime dt = incidence->dateTime( Incidence::RoleCalendarHashing );
- if ( dt.isValid() ) {
- d->mIncidencesForDate[type].remove( dt.date().toString(), incidence );
+ const KDateTime dt = incidence->dateTime(Incidence::RoleCalendarHashing);
+ if (dt.isValid()) {
+ d->mIncidencesForDate[type].remove(dt.date().toString(), incidence);
+ }
+ // Delete child-incidences.
+ if (!incidence->hasRecurrenceId()) {
+ deleteIncidenceInstances(incidence);
+ }
+ return true;
+ } else {
+ kWarning() << incidence->typeStr() << " not found. uid=" << uid;
+ return false;
}
- // Delete child-incidences.
- if ( !incidence->hasRecurrenceId() ) {
- deleteIncidenceInstances( incidence );
+}
+
+bool MemoryCalendar::deleteIncidenceInstances(const Incidence::Ptr &incidence)
+{
+ const Incidence::IncidenceType type = incidence->type();
+ QList<Incidence::Ptr> values = d->mIncidences[type].values(incidence->uid());
+ QList<Incidence::Ptr>::const_iterator it;
+ for (it = values.constBegin(); it != values.constEnd(); ++it) {
+ Incidence::Ptr i = *it;
+ if (i->hasRecurrenceId()) {
+ kDebug() << "deleting child"
+ << ", type=" << int(type)
+ << ", uid=" << i->uid()
+ << ", start=" << i->dtStart()
+ << " from calendar";
+ deleteIncidence(i);
+ }
}
+
return true;
- } else {
- qWarning() << incidence->typeStr() << " not found.";
- return false;
- }
-}
-
-bool MemoryCalendar::deleteIncidenceInstances( const Incidence::Ptr &incidence )
-{
- const Incidence::IncidenceType type = incidence->type();
- QList<Incidence::Ptr> values = d->mIncidences[type].values( incidence->uid() );
- QList<Incidence::Ptr>::const_iterator it;
- for ( it = values.constBegin(); it != values.constEnd(); ++it ) {
- Incidence::Ptr i = *it;
- if ( i->hasRecurrenceId() ) {
-// qDebug() << "deleting child"
-// << ", type=" << int( type )
-// << ", uid=" << i->uid()
-// << ", start=" << i->dtStart()
-// << " from calendar";
- deleteIncidence( i );
- }
- }
-
- return true;
-}
-
-void MemoryCalendar::Private::deleteAllIncidences( const Incidence::IncidenceType incidenceType )
-{
- QHashIterator<QString, Incidence::Ptr>i( mIncidences[incidenceType] );
- while ( i.hasNext() ) {
- i.next();
- q->notifyIncidenceDeleted( i.value() );
- // suppress update notifications for the relation removal triggered
- // by the following deletions
- i.value()->startUpdates();
- }
- mIncidences[incidenceType].clear();
- mIncidencesForDate[incidenceType].clear();
-}
-
-Incidence::Ptr MemoryCalendar::Private::incidence( const QString &uid,
- const Incidence::IncidenceType type,
- const KDateTime &recurrenceId ) const
-{
- QList<Incidence::Ptr> values = mIncidences[type].values( uid );
- QList<Incidence::Ptr>::const_iterator it;
- for ( it = values.constBegin(); it != values.constEnd(); ++it ) {
- Incidence::Ptr i = *it;
- if ( recurrenceId.isNull() ) {
- if ( !i->hasRecurrenceId() ) {
- return i;
- }
- } else {
- if ( i->hasRecurrenceId() && i->recurrenceId() == recurrenceId ) {
- return i;
- }
+}
+
+//@cond PRIVATE
+void MemoryCalendar::Private::deleteAllIncidences(const Incidence::IncidenceType incidenceType)
+{
+ QHashIterator<QString, Incidence::Ptr>i(mIncidences[incidenceType]);
+ while (i.hasNext()) {
+ i.next();
+ q->notifyIncidenceDeleted(i.value());
+ i.value()->unRegisterObserver(q);
+ }
+ mIncidences[incidenceType].clear();
+ mIncidencesForDate[incidenceType].clear();
+}
+
+Incidence::Ptr MemoryCalendar::Private::incidence(const QString &uid,
+ const Incidence::IncidenceType type,
+ const KDateTime &recurrenceId) const
+{
+ QList<Incidence::Ptr> values = mIncidences[type].values(uid);
+ QList<Incidence::Ptr>::const_iterator it;
+ for (it = values.constBegin(); it != values.constEnd(); ++it) {
+ Incidence::Ptr i = *it;
+ if (recurrenceId.isNull()) {
+ if (!i->hasRecurrenceId()) {
+ return i;
+ }
+ } else {
+ if (i->hasRecurrenceId() && i->recurrenceId() == recurrenceId) {
+ return i;
+ }
+ }
}
- }
- return Incidence::Ptr();
+ return Incidence::Ptr();
}
Incidence::Ptr
-MemoryCalendar::Private::deletedIncidence( const QString &uid,
- const KDateTime &recurrenceId,
- const IncidenceBase::IncidenceType type ) const
-{
- QList<Incidence::Ptr> values = mDeletedIncidences[type].values( uid );
- QList<Incidence::Ptr>::const_iterator it;
- for ( it = values.constBegin(); it != values.constEnd(); ++it ) {
- Incidence::Ptr i = *it;
- if ( recurrenceId.isNull() ) {
- if ( !i->hasRecurrenceId() ) {
- return i;
- }
- } else {
- if ( i->hasRecurrenceId() && i->recurrenceId() == recurrenceId ) {
- return i;
- }
+MemoryCalendar::Private::deletedIncidence(const QString &uid,
+ const KDateTime &recurrenceId,
+ const IncidenceBase::IncidenceType type) const
+{
+ if (!q->deletionTracking()) {
+ return Incidence::Ptr();
}
- }
- return Incidence::Ptr();
+
+ QList<Incidence::Ptr> values = mDeletedIncidences[type].values(uid);
+ QList<Incidence::Ptr>::const_iterator it;
+ for (it = values.constBegin(); it != values.constEnd(); ++it) {
+ Incidence::Ptr i = *it;
+ if (recurrenceId.isNull()) {
+ if (!i->hasRecurrenceId()) {
+ return i;
+ }
+ } else {
+ if (i->hasRecurrenceId() && i->recurrenceId() == recurrenceId) {
+ return i;
+ }
+ }
+ }
+ return Incidence::Ptr();
}
-//@cond PRIVATE
-void MemoryCalendar::Private::insertIncidence( Incidence::Ptr incidence )
+void MemoryCalendar::Private::insertIncidence(const Incidence::Ptr &incidence)
{
- const QString uid = incidence->uid();
- const Incidence::IncidenceType type = incidence->type();
- if ( !mIncidences[type].contains( uid, incidence ) ) {
- mIncidences[type].insert( uid, incidence );
- const KDateTime dt = incidence->dateTime( Incidence::RoleCalendarHashing );
- if ( dt.isValid() ) {
- mIncidencesForDate[type].insert( dt.date().toString(), incidence );
- }
+ const QString uid = incidence->uid();
+ const Incidence::IncidenceType type = incidence->type();
+ if (!mIncidences[type].contains(uid, incidence)) {
+ mIncidences[type].insert(uid, incidence);
+ mIncidencesByIdentifier.insert(incidence->instanceIdentifier(), incidence);
+ const KDateTime dt = incidence->dateTime(Incidence::RoleCalendarHashing);
+ if (dt.isValid()) {
+ mIncidencesForDate[type].insert(dt.date().toString(), incidence);
+ }
- } else {
+ } else {
#ifndef NDEBUG
- // if we already have an to-do with this UID, it must be the same incidence,
- // otherwise something's really broken
- Q_ASSERT( mIncidences[type].value( uid ) == incidence );
+ // if we already have an to-do with this UID, it must be the same incidence,
+ // otherwise something's really broken
+ Q_ASSERT(mIncidences[type].value(uid) == incidence);
#endif
- }
+ }
}
//@endcond
-bool MemoryCalendar::addIncidence( const Incidence::Ptr &incidence )
+bool MemoryCalendar::addIncidence(const Incidence::Ptr &incidence)
{
- notifyIncidenceAdded( incidence );
+ d->insertIncidence(incidence);
- d->insertIncidence( incidence );
+ notifyIncidenceAdded(incidence);
- incidence->registerObserver( this );
+ incidence->registerObserver(this);
- setupRelations( incidence );
+ setupRelations(incidence);
- setModified( true );
+ setModified(true);
- return true;
+ return true;
}
-bool MemoryCalendar::addEvent( const Event::Ptr &event )
+bool MemoryCalendar::addEvent(const Event::Ptr &event)
{
- return addIncidence( event );
+ return addIncidence(event);
}
-bool MemoryCalendar::deleteEvent( const Event::Ptr &event )
+bool MemoryCalendar::deleteEvent(const Event::Ptr &event)
{
- return deleteIncidence( event );
+ return deleteIncidence(event);
}
-bool MemoryCalendar::deleteEventInstances( const Event::Ptr &event )
+bool MemoryCalendar::deleteEventInstances(const Event::Ptr &event)
{
- return deleteIncidenceInstances( event );
+ return deleteIncidenceInstances(event);
}
void MemoryCalendar::deleteAllEvents()
{
- d->deleteAllIncidences( Incidence::TypeEvent );
+ d->deleteAllIncidences(Incidence::TypeEvent);
}
-Event::Ptr MemoryCalendar::event( const QString &uid,
- const KDateTime &recurrenceId ) const
+Event::Ptr MemoryCalendar::event(const QString &uid,
+ const KDateTime &recurrenceId) const
{
- return d->incidence( uid, Incidence::TypeEvent, recurrenceId ).staticCast<Event>();
+ return d->incidence(uid, Incidence::TypeEvent, recurrenceId).staticCast<Event>();
}
-Event::Ptr MemoryCalendar::deletedEvent( const QString &uid, const KDateTime &recurrenceId ) const
+Event::Ptr MemoryCalendar::deletedEvent(const QString &uid, const KDateTime &recurrenceId) const
{
- return d->deletedIncidence( uid, recurrenceId, Incidence::TypeEvent ).staticCast<Event>();
+ return d->deletedIncidence(uid, recurrenceId, Incidence::TypeEvent).staticCast<Event>();
}
-bool MemoryCalendar::addTodo( const Todo::Ptr &todo )
+bool MemoryCalendar::addTodo(const Todo::Ptr &todo)
{
- return addIncidence( todo );
+ return addIncidence(todo);
}
-bool MemoryCalendar::deleteTodo( const Todo::Ptr &todo )
+bool MemoryCalendar::deleteTodo(const Todo::Ptr &todo)
{
- return deleteIncidence( todo );
+ return deleteIncidence(todo);
}
-bool MemoryCalendar::deleteTodoInstances( const Todo::Ptr &todo )
+bool MemoryCalendar::deleteTodoInstances(const Todo::Ptr &todo)
{
- return deleteIncidenceInstances( todo );
+ return deleteIncidenceInstances(todo);
}
void MemoryCalendar::deleteAllTodos()
{
- d->deleteAllIncidences( Incidence::TypeTodo );
+ d->deleteAllIncidences(Incidence::TypeTodo);
}
-Todo::Ptr MemoryCalendar::todo( const QString &uid,
- const KDateTime &recurrenceId ) const
+Todo::Ptr MemoryCalendar::todo(const QString &uid,
+ const KDateTime &recurrenceId) const
{
- return d->incidence( uid, Incidence::TypeTodo, recurrenceId ).staticCast<Todo>();
+ return d->incidence(uid, Incidence::TypeTodo, recurrenceId).staticCast<Todo>();
}
-Todo::Ptr MemoryCalendar::deletedTodo( const QString &uid,
- const KDateTime &recurrenceId ) const
+Todo::Ptr MemoryCalendar::deletedTodo(const QString &uid,
+ const KDateTime &recurrenceId) const
{
- return d->deletedIncidence( uid, recurrenceId, Incidence::TypeTodo ).staticCast<Todo>();
+ return d->deletedIncidence(uid, recurrenceId, Incidence::TypeTodo).staticCast<Todo>();
}
-Todo::List MemoryCalendar::rawTodos( TodoSortField sortField,
- SortDirection sortDirection ) const
+Todo::List MemoryCalendar::rawTodos(TodoSortField sortField,
+ SortDirection sortDirection) const
{
- Todo::List todoList;
- QHashIterator<QString, Incidence::Ptr>i( d->mIncidences[Incidence::TypeTodo] );
- while ( i.hasNext() ) {
- i.next();
- todoList.append( i.value().staticCast<Todo>() );
- }
- return Calendar::sortTodos( todoList, sortField, sortDirection );
+ Todo::List todoList;
+ QHashIterator<QString, Incidence::Ptr>i(d->mIncidences[Incidence::TypeTodo]);
+ while (i.hasNext()) {
+ i.next();
+ todoList.append(i.value().staticCast<Todo>());
+ }
+ return Calendar::sortTodos(todoList, sortField, sortDirection);
}
-Todo::List MemoryCalendar::deletedTodos( TodoSortField sortField,
- SortDirection sortDirection ) const
+Todo::List MemoryCalendar::deletedTodos(TodoSortField sortField,
+ SortDirection sortDirection) const
{
- Todo::List todoList;
- QHashIterator<QString, Incidence::Ptr >i( d->mDeletedIncidences[Incidence::TypeTodo] );
- while ( i.hasNext() ) {
- i.next();
- todoList.append( i.value().staticCast<Todo>() );
- }
- return Calendar::sortTodos( todoList, sortField, sortDirection );
+ if (!deletionTracking()) {
+ return Todo::List();
+ }
+
+ Todo::List todoList;
+ QHashIterator<QString, Incidence::Ptr >i(d->mDeletedIncidences[Incidence::TypeTodo]);
+ while (i.hasNext()) {
+ i.next();
+ todoList.append(i.value().staticCast<Todo>());
+ }
+ return Calendar::sortTodos(todoList, sortField, sortDirection);
}
-Todo::List MemoryCalendar::todoInstances( const Incidence::Ptr &todo,
- TodoSortField sortField,
- SortDirection sortDirection ) const
+Todo::List MemoryCalendar::todoInstances(const Incidence::Ptr &todo,
+ TodoSortField sortField,
+ SortDirection sortDirection) const
{
- Todo::List list;
+ Todo::List list;
- QList<Incidence::Ptr > values = d->mIncidences[Incidence::TypeTodo].values( todo->uid() );
- QList<Incidence::Ptr>::const_iterator it;
- for ( it = values.constBegin(); it != values.constEnd(); ++it ) {
- Todo::Ptr t = ( *it ).staticCast<Todo>();
- if ( t->hasRecurrenceId() ) {
- list.append( t );
+ QList<Incidence::Ptr > values = d->mIncidences[Incidence::TypeTodo].values(todo->uid());
+ QList<Incidence::Ptr>::const_iterator it;
+ for (it = values.constBegin(); it != values.constEnd(); ++it) {
+ Todo::Ptr t = (*it).staticCast<Todo>();
+ if (t->hasRecurrenceId()) {
+ list.append(t);
+ }
}
- }
- return Calendar::sortTodos( list, sortField, sortDirection );
+ return Calendar::sortTodos(list, sortField, sortDirection);
}
-Todo::List MemoryCalendar::rawTodosForDate( const QDate &date ) const
+Todo::List MemoryCalendar::rawTodosForDate(const QDate &date) const
{
- Todo::List todoList;
- Todo::Ptr t;
+ Todo::List todoList;
+ Todo::Ptr t;
- KDateTime::Spec ts = timeSpec();
- const QString dateStr = date.toString();
- QMultiHash<QString, IncidenceBase::Ptr >::const_iterator it =
- d->mIncidencesForDate[Incidence::TypeTodo].constFind( dateStr );
- while ( it != d->mIncidencesForDate[Incidence::TypeTodo].constEnd() && it.key() == dateStr ) {
- t = it.value().staticCast<Todo>();
- todoList.append( t );
- ++it;
- }
+ KDateTime::Spec ts = timeSpec();
+ const QString dateStr = date.toString();
+ QMultiHash<QString, IncidenceBase::Ptr >::const_iterator it =
+ d->mIncidencesForDate[Incidence::TypeTodo].constFind(dateStr);
+ while (it != d->mIncidencesForDate[Incidence::TypeTodo].constEnd() && it.key() == dateStr) {
+ t = it.value().staticCast<Todo>();
+ todoList.append(t);
+ ++it;
+ }
- // Iterate over all todos. Look for recurring todoss that occur on this date
- QHashIterator<QString, Incidence::Ptr >i( d->mIncidences[Incidence::TypeTodo] );
- while ( i.hasNext() ) {
- i.next();
- t = i.value().staticCast<Todo>();
- if ( t->recurs() ) {
- if ( t->recursOn( date, ts ) ) {
- todoList.append( t );
- }
+ // Iterate over all todos. Look for recurring todoss that occur on this date
+ QHashIterator<QString, Incidence::Ptr >i(d->mIncidences[Incidence::TypeTodo]);
+ while (i.hasNext()) {
+ i.next();
+ t = i.value().staticCast<Todo>();
+ if (t->recurs()) {
+ if (t->recursOn(date, ts)) {
+ todoList.append(t);
+ }
+ }
}
- }
- return todoList;
+ return todoList;
}
-Todo::List MemoryCalendar::rawTodos( const QDate &start,
- const QDate &end,
- const KDateTime::Spec &timespec,
- bool inclusive ) const
+Todo::List MemoryCalendar::rawTodos(const QDate &start,
+ const QDate &end,
+ const KDateTime::Spec &timespec,
+ bool inclusive) const
{
- Q_UNUSED( inclusive ); // use only exact dtDue/dtStart, not dtStart and dtEnd
-
- Todo::List todoList;
- KDateTime::Spec ts = timespec.isValid() ? timespec : timeSpec();
- KDateTime st( start, ts );
- KDateTime nd( end, ts );
+ Q_UNUSED(inclusive); // use only exact dtDue/dtStart, not dtStart and dtEnd
- // Get todos
- QHashIterator<QString, Incidence::Ptr >i( d->mIncidences[Incidence::TypeTodo] );
- Todo::Ptr todo;
- while ( i.hasNext() ) {
- i.next();
- todo = i.value().staticCast<Todo>();
- if ( !isVisible( todo ) ) {
- continue;
- }
+ Todo::List todoList;
+ KDateTime::Spec ts = timespec.isValid() ? timespec : timeSpec();
+ KDateTime st(start, ts);
+ KDateTime nd(end, ts);
- KDateTime rStart = todo->hasDueDate() ? todo->dtDue() :
- todo->hasStartDate() ? todo->dtStart() : KDateTime();
- if ( !rStart.isValid() ) {
- continue;
- }
-
- if ( !todo->recurs() ) { // non-recurring todos
- if ( nd.isValid() && nd < rStart ) {
- continue;
- }
- if ( st.isValid() && rStart < st ) {
- continue;
- }
- } else { // recurring events
- switch( todo->recurrence()->duration() ) {
- case -1: // infinite
- break;
- case 0: // end date given
- default: // count given
- KDateTime rEnd( todo->recurrence()->endDate(), ts );
- if ( !rEnd.isValid() ) {
- continue;
+ // Get todos
+ QHashIterator<QString, Incidence::Ptr >i(d->mIncidences[Incidence::TypeTodo]);
+ Todo::Ptr todo;
+ while (i.hasNext()) {
+ i.next();
+ todo = i.value().staticCast<Todo>();
+ if (!isVisible(todo)) {
+ continue;
}
- if ( st.isValid() && rEnd < st ) {
- continue;
+
+ KDateTime rStart = todo->hasDueDate() ? todo->dtDue() :
+ todo->hasStartDate() ? todo->dtStart() : KDateTime();
+ if (!rStart.isValid()) {
+ continue;
}
- break;
- } // switch(duration)
- } //if(recurs)
- todoList.append( todo );
- }
+ if (!todo->recurs()) { // non-recurring todos
+ if (nd.isValid() && nd < rStart) {
+ continue;
+ }
+ if (st.isValid() && rStart < st) {
+ continue;
+ }
+ } else { // recurring events
+ switch (todo->recurrence()->duration()) {
+ case -1: // infinite
+ break;
+ case 0: // end date given
+ default: // count given
+ KDateTime rEnd(todo->recurrence()->endDate(), ts);
+ if (!rEnd.isValid()) {
+ continue;
+ }
+ if (st.isValid() && rEnd < st) {
+ continue;
+ }
+ break;
+ } // switch(duration)
+ } //if(recurs)
+
+ todoList.append(todo);
+ }
- return todoList;
+ return todoList;
}
-Alarm::List MemoryCalendar::alarmsTo( const KDateTime &to ) const
+Alarm::List MemoryCalendar::alarmsTo(const KDateTime &to) const
{
- return alarms( KDateTime( QDate( 1900, 1, 1 ) ), to );
+ return alarms(KDateTime(QDate(1900, 1, 1)), to);
}
-Alarm::List MemoryCalendar::alarms( const KDateTime &from, const KDateTime &to ) const
+Alarm::List MemoryCalendar::alarms(const KDateTime &from, const KDateTime &to) const
{
- Alarm::List alarmList;
- QHashIterator<QString, Incidence::Ptr>ie( d->mIncidences[Incidence::TypeEvent] );
- Event::Ptr e;
- while ( ie.hasNext() ) {
- ie.next();
- e = ie.value().staticCast<Event>();
- if ( e->recurs() ) {
- appendRecurringAlarms( alarmList, e, from, to );
- } else {
- appendAlarms( alarmList, e, from, to );
+ Alarm::List alarmList;
+ QHashIterator<QString, Incidence::Ptr>ie(d->mIncidences[Incidence::TypeEvent]);
+ Event::Ptr e;
+ while (ie.hasNext()) {
+ ie.next();
+ e = ie.value().staticCast<Event>();
+ if (e->recurs()) {
+ appendRecurringAlarms(alarmList, e, from, to);
+ } else {
+ appendAlarms(alarmList, e, from, to);
+ }
}
- }
-
- QHashIterator<QString, Incidence::Ptr>it( d->mIncidences[Incidence::TypeTodo] );
- Todo::Ptr t;
- while ( it.hasNext() ) {
- it.next();
- t = it.value().staticCast<Todo>();
- if ( !t->isCompleted() ) {
- appendAlarms( alarmList, t, from, to );
- if ( t->recurs() ) {
- appendRecurringAlarms( alarmList, t, from, to );
- } else {
- appendAlarms( alarmList, t, from, to );
- }
+ QHashIterator<QString, Incidence::Ptr>it(d->mIncidences[Incidence::TypeTodo]);
+ Todo::Ptr t;
+ while (it.hasNext()) {
+ it.next();
+ t = it.value().staticCast<Todo>();
+
+ if (!t->isCompleted()) {
+ appendAlarms(alarmList, t, from, to);
+ if (t->recurs()) {
+ appendRecurringAlarms(alarmList, t, from, to);
+ } else {
+ appendAlarms(alarmList, t, from, to);
+ }
+ }
}
- }
- return alarmList;
+ return alarmList;
}
-void MemoryCalendar::incidenceUpdate( const QString &uid, const KDateTime &recurrenceId )
+void MemoryCalendar::incidenceUpdate(const QString &uid, const KDateTime &recurrenceId)
{
- Incidence::Ptr inc = incidence( uid, recurrenceId );
+ Incidence::Ptr inc = incidence(uid, recurrenceId);
+
+ if (inc) {
+ if (!d->mIncidenceBeingUpdated.isEmpty()) {
+ kWarning() << "Incidence::update() called twice without an updated() call in between.";
+ }
- if ( inc ) {
- const Incidence::IncidenceType type = inc->type();
- const KDateTime dt = inc->dateTime( Incidence::RoleCalendarHashing );
+ // Save it so we can detect changes to uid or recurringId.
+ d->mIncidenceBeingUpdated = inc->instanceIdentifier();
- if ( dt.isValid() ) {
- d->mIncidencesForDate[type].remove( dt.date().toString(), inc );
+ const KDateTime dt = inc->dateTime(Incidence::RoleCalendarHashing);
+ if (dt.isValid()) {
+ const Incidence::IncidenceType type = inc->type();
+ d->mIncidencesForDate[type].remove(dt.date().toString(), inc);
+ }
}
- }
}
-void MemoryCalendar::incidenceUpdated( const QString &uid, const KDateTime &recurrenceId )
+void MemoryCalendar::incidenceUpdated(const QString &uid, const KDateTime &recurrenceId)
{
- Incidence::Ptr inc = incidence( uid, recurrenceId );
+ Incidence::Ptr inc = incidence(uid, recurrenceId);
- if ( inc ) {
- KDateTime nowUTC = KDateTime::currentUtcDateTime();
- inc->setLastModified( nowUTC );
- // we should probably update the revision number here,
- // or internally in the Event itself when certain things change.
- // need to verify with ical documentation.
+ if (inc) {
- const Incidence::IncidenceType type = inc->type();
- const KDateTime dt = inc->dateTime( Incidence::RoleCalendarHashing );
+ if (d->mIncidenceBeingUpdated.isEmpty()) {
+ kWarning() << "Incidence::updated() called twice without an update() call in between.";
+ } else if (inc->instanceIdentifier() != d->mIncidenceBeingUpdated) {
+ // Instance identifier changed, update our hash table
+ d->mIncidencesByIdentifier.remove(d->mIncidenceBeingUpdated);
+ d->mIncidencesByIdentifier.insert(inc->instanceIdentifier(), inc);
+ }
- if ( dt.isValid() ) {
- d->mIncidencesForDate[type].insert( dt.date().toString(), inc );
- }
+ d->mIncidenceBeingUpdated = QString();
- notifyIncidenceChanged( inc );
+ inc->setLastModified(KDateTime::currentUtcDateTime());
+ // we should probably update the revision number here,
+ // or internally in the Event itself when certain things change.
+ // need to verify with ical documentation.
- setModified( true );
- }
+ const KDateTime dt = inc->dateTime(Incidence::RoleCalendarHashing);
+ if (dt.isValid()) {
+ const Incidence::IncidenceType type = inc->type();
+ d->mIncidencesForDate[type].insert(dt.date().toString(), inc);
+ }
+
+ notifyIncidenceChanged(inc);
+
+ setModified(true);
+ }
}
-Event::List MemoryCalendar::rawEventsForDate( const QDate &date,
- const KDateTime::Spec &timespec,
- EventSortField sortField,
- SortDirection sortDirection ) const
+Event::List MemoryCalendar::rawEventsForDate(const QDate &date,
+ const KDateTime::Spec &timespec,
+ EventSortField sortField,
+ SortDirection sortDirection) const
{
- Event::List eventList;
- Event::Ptr ev;
+ Event::List eventList;
- // Find the hash for the specified date
- const QString dateStr = date.toString();
- QMultiHash<QString, IncidenceBase::Ptr >::const_iterator it =
- d->mIncidencesForDate[Incidence::TypeEvent].constFind( dateStr );
- // Iterate over all non-recurring, single-day events that start on this date
- KDateTime::Spec ts = timespec.isValid() ? timespec : timeSpec();
- KDateTime kdt( date, ts );
- while ( it != d->mIncidencesForDate[Incidence::TypeEvent].constEnd() && it.key() == dateStr ) {
- ev = it.value().staticCast<Event>();
- KDateTime end( ev->dtEnd().toTimeSpec( ev->dtStart() ) );
- if ( ev->allDay() ) {
- end.setDateOnly( true );
- } else {
- end = end.addSecs( -1 );
- }
- if ( end >= kdt ) {
- eventList.append( ev );
- }
- ++it;
- }
-
- // Iterate over all events. Look for recurring events that occur on this date
- QHashIterator<QString, Incidence::Ptr>i( d->mIncidences[Incidence::TypeEvent] );
- while ( i.hasNext() ) {
- i.next();
- ev = i.value().staticCast<Event>();
- if ( ev->recurs() ) {
- if ( ev->isMultiDay() ) {
- int extraDays = ev->dtStart().date().daysTo( ev->dtEnd().date() );
- for ( int i = 0; i <= extraDays; ++i ) {
- if ( ev->recursOn( date.addDays( -i ), ts ) ) {
- eventList.a