Commit 3da314c5 authored by David Jarvie's avatar David Jarvie
Browse files

Convert KMail serial number to use Akonadi Item ID instead

KMail identifies its emails by Akonadi Item ID now.
parent bbec7693
......@@ -100,7 +100,7 @@ Compliant with the iCalendar specification, KAlarm defines a number of custom fi
<tr><td class=cont></td><td class=cont><tt>LATECANCEL;<em>interval</em></tt></td><td class=cont>How late the alarm can trigger (in minutes) before it will be cancelled; default = 1 minute</td></tr>
<tr><td class=cont></td><td class=cont><tt>LATECLOSE;<em>interval</em></tt></td><td class=cont>For a display alarm, how long after the trigger time (in minutes) until the alarm window is automatically closed; default = 1 minute. It will also be cancelled if it triggers after this time.</td></tr>
<tr><td class=cont></td><td class=cont><tt>TMPLAFTTIME;<em>interval</em></tt></td><td class=cont>For a template alarm, holds the value (in minutes) of the "After time" option</td></tr>
<tr><td class=cont></td><td class=cont><tt>KMAIL;<em>sernum</em></tt></td><td class=cont>The KMail serial number of the email whose text forms the alarm message. The alarm message must be in the form <tt>From: ...\nTo: ...\n<em>[</em>Cc: ...\n<em>]</em>Date: ...\nSubject: ...</tt></td></tr>
<tr><td class=cont></td><td class=cont><tt>KMAIL;<em>itemid</em></tt></td><td class=cont>The Akonadi Item ID of the email whose text forms the alarm message. The alarm message must be in the form <tt>From: ...\nTo: ...\n<em>[</em>Cc: ...\n<em>]</em>Date: ...\nSubject: ...</tt></td></tr>
<tr><td class=cont></td><td class=cont><tt>BCC</tt></td><td class=cont>For an email alarm, the email will be blind copied to the user</td></tr>
<tr><td class=cont></td><td class=cont><tt>REMINDER;<em>[</em>ONCE;<em>]interval</em></tt></td><td class=cont>The reminder interval for the alarm: &lt; 0 for a reminder before the main alarm, &gt; 0 for a reminder after the main alarm. A suffix indicates the time units: <tt>M</tt> = minutes, <tt>H</tt> = hours, <tt>D</tt> = days. E.g. <tt class=eg>-12M</tt>. If <tt>ONCE</tt> is specified, this indicates that the reminder should be shown only for the first recurrence.</td></tr>
<tr><td class=cont></td><td class=cont><tt>LOGIN</tt></td><td class=cont>For an active alarm, when its main alarm has expired, records that the original alarm was triggered each time KAlarm started up (normally at each login)</td></tr>
......
......@@ -2,7 +2,7 @@
This file is part of kalarmcal library, which provides access to KAlarm
calendar data.
Copyright (c) 2018 David Jarvie <djarvie@kde.org>
Copyright © 2018,2019 David Jarvie <djarvie@kde.org>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
......@@ -859,24 +859,24 @@ void KAEventTest::fromKCalEvent()
KAEvent event(kcalevent);
QVERIFY(!event.emailBcc());
QCOMPARE(event.templateAfterTime(), 31);
QCOMPARE(event.kmailSerialNumber(), 0UL);
QCOMPARE(event.akonadiItemId(), Akonadi::Item::Id(-1));
}
{
// KMail serial number, with alarm message in email format
// Akonadi item ID, with alarm message in email format
Alarm::Ptr kcalalarm;
Event::Ptr kcalevent = createKcalEvent(dt.qDateTime(), createdDt, kcalalarm);
kcalevent->setCustomProperty("KALARM", "FLAGS", QStringLiteral("KMAIL;759231"));
kcalalarm->setText(QStringLiteral("From: a@b.c\nTo: d@e.f\nDate: Sun, 01 Apr 2018 17:36:06 +0100\nSubject: About this"));
KAEvent event(kcalevent);
QCOMPARE(event.templateAfterTime(), -1);
QCOMPARE(event.kmailSerialNumber(), 759231UL);
QCOMPARE(event.akonadiItemId(), Akonadi::Item::Id(759231));
}
{
// KMail serial number, with alarm message in wrong format
// Akonadi item ID, with alarm message in wrong format
Event::Ptr kcalevent = createKcalEvent(dt.qDateTime(), createdDt);
kcalevent->setCustomProperty("KALARM", "FLAGS", QStringLiteral("KMAIL;759231"));
KAEvent event(kcalevent);
QCOMPARE(event.kmailSerialNumber(), 0UL);
QCOMPARE(event.akonadiItemId(), Akonadi::Item::Id(-1));
}
// Alarm custom properties
......
/*
* akonadi_serializer_kalarm.cpp - Akonadi resource serializer for KAlarm
* Copyright © 2009-2012,2018 by David Jarvie <djarvie@kde.org>
* Copyright © 2009-2019 David Jarvie <djarvie@kde.org>
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Library General Public License as published by
......@@ -231,8 +231,8 @@ void SerializerPluginKAlarm::compare(AbstractDifferencesReporter *reporter, cons
if (eventL.confirmAck() != eventR.confirmAck()) {
reportDifference(reporter, KAEventFormatter::ConfirmAck);
}
if (eventL.kmailSerialNumber() != eventR.kmailSerialNumber()) {
reportDifference(reporter, KAEventFormatter::KMailSerial);
if (eventL.akonadiItemId() != eventR.akonadiItemId()) {
reportDifference(reporter, KAEventFormatter::AkonadiItem);
}
if (eventL.beep() != eventR.beep()
|| eventL.speak() != eventR.speak()
......
/*
* kaeventformatter.cpp - converts KAlarmCal::KAEvent properties to text
* Copyright © 2010,2011,2018 by David Jarvie <djarvie@kde.org>
* Copyright © 2010-2019 David Jarvie <djarvie@kde.org>
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Library General Public License as published by
......@@ -115,8 +115,8 @@ QString KAEventFormatter::label(Parameter param)
return i18nc("@label Shell command to execute after alarm", "Post-alarm action");
case ConfirmAck:
return i18nc("@label", "Confirm acknowledgement");
case KMailSerial:
return i18nc("@label", "KMail serial number");
case AkonadiItem:
return i18nc("@label", "Akonadi Item ID");
case Sound:
return i18nc("@label Audio method", "Sound");
case SoundRepeat:
......@@ -206,7 +206,7 @@ bool KAEventFormatter::isApplicable(Parameter param) const
case PreAction:
case PostAction:
case ConfirmAck:
case KMailSerial:
case AkonadiItem:
case Reminder:
case DeferralType:
case DeferDefault:
......@@ -371,8 +371,8 @@ QString KAEventFormatter::value(Parameter param) const
return trueFalse(mEvent.deferDefaultDateOnly());
case ConfirmAck:
return trueFalse(mEvent.confirmAck());
case KMailSerial:
return mEvent.kmailSerialNumber() ? QLocale().toString(qulonglong(mEvent.kmailSerialNumber())) : trueFalse(false);
case AkonadiItem:
return (mEvent.akonadiItemId() >= 0) ? QLocale().toString(mEvent.akonadiItemId()) : trueFalse(false);
case Sound:
return !mEvent.audioFile().isEmpty() ? mEvent.audioFile()
: mEvent.speak() ? i18nc("@info", "Speak")
......
/*
* kaeventformatter.h - converts KAlarmCal::KAEvent properties to text
* Copyright © 2010-2011 by David Jarvie <djarvie@kde.org>
* Copyright © 2010-2019 David Jarvie <djarvie@kde.org>
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Library General Public License as published by
......@@ -68,7 +68,7 @@ public:
PreActionNoError,
PostAction,
ConfirmAck,
KMailSerial,
AkonadiItem,
Sound,
SoundRepeat,
SoundVolume,
......
......@@ -2,7 +2,7 @@
* alarmtext.cpp - text/email alarm text conversion
* This file is part of kalarmcal library, which provides access to KAlarm
* calendar data.
* Copyright © 2004,2005,2007-2016 by David Jarvie <djarvie@kde.org>
* Copyright © 2004-2019 David Jarvie <djarvie@kde.org>
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as published
......@@ -67,10 +67,10 @@ public:
static QString mSubjectPrefixEn;
static bool mInitialised;
QString mBody, mFrom, mTo, mCc, mTime, mSubject;
unsigned long mKMailSerialNum; // if email, message's KMail serial number, else 0
Type mType;
bool mIsEmail;
QString mBody, mFrom, mTo, mCc, mTime, mSubject;
Akonadi::Item::Id mAkonadiItemId; // if email, message's Akonadi item ID, else -1
Type mType;
bool mIsEmail;
};
QString AlarmText::Private::mFromPrefix;
......@@ -141,17 +141,17 @@ void AlarmText::setScript(const QString &text)
}
void AlarmText::setEmail(const QString &to, const QString &from, const QString &cc, const QString &time,
const QString &subject, const QString &body, unsigned long kmailSerialNumber)
const QString &subject, const QString &body, Akonadi::Item::Id itemId)
{
d->clear();
d->mType = Private::Email;
d->mTo = to;
d->mFrom = from;
d->mCc = cc;
d->mTime = time;
d->mSubject = subject;
d->mBody = body;
d->mKMailSerialNum = kmailSerialNumber;
d->mType = Private::Email;
d->mTo = to;
d->mFrom = from;
d->mCc = cc;
d->mTime = time;
d->mSubject = subject;
d->mBody = body;
d->mAkonadiItemId = itemId;
}
void AlarmText::setTodo(const KCalCore::Todo::Ptr &todo)
......@@ -305,7 +305,12 @@ bool AlarmText::isTodo() const
unsigned long AlarmText::kmailSerialNumber() const
{
return d->mKMailSerialNum;
return static_cast<unsigned long>(akonadiItemId());
}
Akonadi::Item::Id AlarmText::akonadiItemId() const
{
return d->mAkonadiItemId;
}
/******************************************************************************
......@@ -506,7 +511,7 @@ void AlarmText::Private::clear()
mCc.clear();
mTime.clear();
mSubject.clear();
mKMailSerialNum = 0;
mAkonadiItemId = -1;
}
/******************************************************************************
......
......@@ -2,7 +2,7 @@
* alarmtext.h - text/email alarm text conversion
* This file is part of kalarmcal library, which provides access to KAlarm
* calendar data.
* Copyright © 2004,2005,2008-2012 by David Jarvie <djarvie@kde.org>
* Copyright © 2004-2019 David Jarvie <djarvie@kde.org>
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as published
......@@ -26,6 +26,7 @@
#include "kalarmcal_export.h"
#include <kcalcore/todo.h>
#include <AkonadiCore/item.h>
#include <QString>
namespace KAlarmCal
......@@ -72,15 +73,16 @@ public:
void setScript(const QString &text);
/** Set the instance contents to be an email.
* @param to 'To' header parameter
* @param from 'From' header parameter
* @param cc 'Cc' header parameter
* @param time 'Date' header parameter
* @param subject 'Subject' header parameter
* @param body email body text
* @param to 'To' header parameter
* @param from 'From' header parameter
* @param cc 'Cc' header parameter
* @param time 'Date' header parameter
* @param subject 'Subject' header parameter
* @param body email body text
* @param itemId Akonadi item ID of the email.
*/
void setEmail(const QString &to, const QString &from, const QString &cc, const QString &time,
const QString &subject, const QString &body, unsigned long kmailSerialNumber = 0);
const QString &subject, const QString &body, Akonadi::Item::Id itemId = -1);
/** Set the instance contents to be a todo.
* @param todo Todo instance to set as the text
......@@ -144,7 +146,7 @@ public:
*/
QString description() const;
/** Return whether there is any text. */
/** Return whether the instance has any contents. */
bool isEmpty() const;
/** Return whether the instance contains the text of an email. */
......@@ -158,8 +160,14 @@ public:
/** Return the kmail serial number of an email.
* @return serial number, or 0 if none.
* @deprecated Use akonadiItemId() instead
*/
unsigned long kmailSerialNumber() const;
KALARMCAL_DEPRECATED unsigned long kmailSerialNumber() const;
/** Return the Akonadi item ID of an email.
* @return serial number, or 0 if none.
*/
Akonadi::Item::Id akonadiItemId() const;
/** Return the alarm summary text for either single line or tooltip display.
* @param event event whose summary text is to be returned
......
......@@ -2,7 +2,7 @@
* kaevent.cpp - represents calendar events
* This file is part of kalarmcal library, which provides access to KAlarm
* calendar data.
* Copyright © 2001-2016 by David Jarvie <djarvie@kde.org>
* Copyright © 2001-2019 David Jarvie <djarvie@kde.org>
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as published
......@@ -278,7 +278,7 @@ public:
int mNextRepeat; // repetition count of next due sub-repetition
int mAlarmCount; // number of alarms: count of !mMainExpired, mRepeatAtLogin, mDeferral, mReminderActive, mDisplaying
DeferType mDeferral; // whether the alarm is an extra deferred/deferred-reminder alarm
unsigned long mKMailSerialNumber; // if email text, message's KMail serial number
Akonadi::Item::Id mAkonadiItemId; // if email text, message's Akonadi item ID
int mTemplateAfterTime; // time not specified: use n minutes after default time, or -1 (applies to templates only)
QColor mBgColour; // background colour of alarm message
QColor mFgColour; // foreground colour of alarm message, or invalid for default
......@@ -337,7 +337,7 @@ public:
static const QString LATE_CANCEL_FLAG;
static const QString AUTO_CLOSE_FLAG;
static const QString TEMPL_AFTER_TIME_FLAG;
static const QString KMAIL_SERNUM_FLAG;
static const QString KMAIL_ITEM_FLAG;
static const QString ARCHIVE_FLAG;
static const QByteArray NEXT_RECUR_PROPERTY;
static const QByteArray REPEAT_PROPERTY;
......@@ -405,7 +405,7 @@ const QString KAEventPrivate::DEFER_FLAG = QStringLiteral("DEFER")
const QString KAEventPrivate::LATE_CANCEL_FLAG = QStringLiteral("LATECANCEL");
const QString KAEventPrivate::AUTO_CLOSE_FLAG = QStringLiteral("LATECLOSE");
const QString KAEventPrivate::TEMPL_AFTER_TIME_FLAG = QStringLiteral("TMPLAFTTIME");
const QString KAEventPrivate::KMAIL_SERNUM_FLAG = QStringLiteral("KMAIL");
const QString KAEventPrivate::KMAIL_ITEM_FLAG = QStringLiteral("KMAIL");
const QString KAEventPrivate::ARCHIVE_FLAG = QStringLiteral("ARCHIVE");
const QByteArray KAEventPrivate::NEXT_RECUR_PROPERTY("NEXTRECUR"); // X-KDE-KALARM-NEXTRECUR property
......@@ -599,7 +599,7 @@ void KAEventPrivate::copy(const KAEventPrivate &event)
mNextRepeat = event.mNextRepeat;
mAlarmCount = event.mAlarmCount;
mDeferral = event.mDeferral;
mKMailSerialNumber = event.mKMailSerialNumber;
mAkonadiItemId = event.mAkonadiItemId;
mTemplateAfterTime = event.mTemplateAfterTime;
mBgColour = event.mBgColour;
mFgColour = event.mFgColour;
......@@ -689,7 +689,7 @@ void KAEventPrivate::set(const KCalCore::Event::Ptr &event)
mReminderMinutes = 0;
mDeferDefaultMinutes = 0;
mLateCancel = 0;
mKMailSerialNumber = 0;
mAkonadiItemId = -1;
mExcludeHolidays = false;
mWorkTimeOnly = 0;
mChangeCount = 0;
......@@ -754,12 +754,12 @@ void KAEventPrivate::set(const KCalCore::Event::Ptr &event)
mExcludeHolidayRegion = holidays();
} else if (flag == WORK_TIME_ONLY_FLAG) {
mWorkTimeOnly = 1;
} else if (flag == KMAIL_SERNUM_FLAG) {
const unsigned long n = flags.at(i + 1).toULong(&ok);
} else if (flag == KMAIL_ITEM_FLAG) {
const Akonadi::Item::Id id = flags.at(i + 1).toLongLong(&ok);
if (!ok) {
continue;
}
mKMailSerialNumber = n;
mAkonadiItemId = id;
++i;
} else if (flag == KAEventPrivate::ARCHIVE_FLAG) {
mArchive = true;
......@@ -1047,7 +1047,7 @@ void KAEventPrivate::set(const KCalCore::Event::Ptr &event)
}
}
if (!isEmailText) {
mKMailSerialNumber = 0;
mAkonadiItemId = -1;
}
Recurrence *recur = event->recurrence();
......@@ -1173,7 +1173,7 @@ void KAEventPrivate::set(const KADateTime &dateTime, const QString &text, const
setRepeatAtLoginTrue(false);
}
mKMailSerialNumber = 0;
mAkonadiItemId = -1;
mReminderMinutes = 0;
mDeferDefaultMinutes = 0;
mDeferDefaultDateOnly = false;
......@@ -1289,8 +1289,8 @@ bool KAEventPrivate::updateKCalEvent(const Event::Ptr &ev, KAEvent::UidAction ui
if (!mTemplateName.isEmpty() && mTemplateAfterTime >= 0) {
(flags += TEMPL_AFTER_TIME_FLAG) += QString::number(mTemplateAfterTime);
}
if (mKMailSerialNumber) {
(flags += KMAIL_SERNUM_FLAG) += QString::number(mKMailSerialNumber);
if (mAkonadiItemId) {
(flags += KMAIL_ITEM_FLAG) += QString::number(mAkonadiItemId);
}
if (mArchive && !archived) {
flags += ARCHIVE_FLAG;
......@@ -1896,14 +1896,14 @@ bool KAEvent::autoClose() const
return d->mAutoClose;
}
void KAEvent::setKMailSerialNumber(unsigned long n)
void KAEvent::setAkonadiItemId(Akonadi::Item::Id id)
{
d->mKMailSerialNumber = n;
d->mAkonadiItemId = id;
}
unsigned long KAEvent::kmailSerialNumber() const
Akonadi::Item::Id KAEvent::akonadiItemId() const
{
return d->mKMailSerialNumber;
return d->mAkonadiItemId;
}
QString KAEvent::cleanText() const
......@@ -3806,7 +3806,7 @@ void KAEventPrivate::dumpDebug() const
}
qCDebug(KALARMCAL_LOG) << "-- mRepeatSoundPause:" << mRepeatSoundPause;
}
qCDebug(KALARMCAL_LOG) << "-- mKMailSerialNumber:" << mKMailSerialNumber;
qCDebug(KALARMCAL_LOG) << "-- mAkonadiItemId:" << mAkonadiItemId;
qCDebug(KALARMCAL_LOG) << "-- mCopyToKOrganizer:" << mCopyToKOrganizer;
qCDebug(KALARMCAL_LOG) << "-- mExcludeHolidays:" << mExcludeHolidays;
qCDebug(KALARMCAL_LOG) << "-- mWorkTimeOnly:" << mWorkTimeOnly;
......@@ -5245,7 +5245,7 @@ bool KAEvent::convertKCalEvents(const Calendar::Ptr &calendar, int calendarVersi
} else if (cat.startsWith(AUTO_CLOSE_CATEGORY)) {
(flags += KAEventPrivate::AUTO_CLOSE_FLAG) += cat.mid(AUTO_CLOSE_CATEGORY.length());
} else if (cat.startsWith(KMAIL_SERNUM_CATEGORY)) {
(flags += KAEventPrivate::KMAIL_SERNUM_FLAG) += cat.mid(KMAIL_SERNUM_CATEGORY.length());
(flags += KAEventPrivate::KMAIL_ITEM_FLAG) += cat.mid(KMAIL_SERNUM_CATEGORY.length());
} else if (cat == ARCHIVE_CATEGORY) {
event->setCustomProperty(KACalendar::APPNAME, ARCHIVE_PROPERTY, QStringLiteral("0"));
} else if (cat.startsWith(ARCHIVE_CATEGORIES)) {
......
......@@ -2,7 +2,7 @@
* kaevent.h - represents calendar events
* This file is part of kalarmcal library, which provides access to KAlarm
* calendar data.
* Copyright © 2001-2013 by David Jarvie <djarvie@kde.org>
* Copyright © 2001-2019 David Jarvie <djarvie@kde.org>
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as published
......@@ -34,6 +34,7 @@
#include <item.h>
#include <kcalcore/person.h>
#include <kcalcore/calendar.h>
#include <AkonadiCore/item.h>
#include <QBitArray>
#include <QColor>
......@@ -539,8 +540,13 @@ public:
*/
bool autoClose() const;
void setKMailSerialNumber(unsigned long n);
unsigned long kmailSerialNumber() const;
/** Set the Akonadi item ID of the email which the alarm is related to.
*/
void setAkonadiItemId(Akonadi::Item::Id id);
/** Return the Akonadi item ID of the email which the alarm is related to.
*/
Akonadi::Item::Id akonadiItemId() const;
/** Return the alarm's text. Its significance depends on the type of alarm;
* alternatively, use message(), displayMessage(), fileName() or command(),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment