Commit 6d678cee authored by David Jarvie's avatar David Jarvie
Browse files

Use typedef for email IDs

parent be700e83
Pipeline #154169 passed with stage
in 2 minutes
......@@ -286,13 +286,13 @@ CheckBox* EditDisplayAlarmDlg::createConfirmAckCheckbox(QWidget* parent)
void EditDisplayAlarmDlg::type_initValues(const KAEvent& event)
{
mTryButton->setToolTip(i18nc("@info:tooltip", "Display the alarm now"));
mAkonadiItemId = -1;
mEmailId = -1;
lateCancel()->showAutoClose(true);
if (event.isValid())
{
if (mAlarmType == KAEvent::MESSAGE && event.akonadiItemId()
if (mAlarmType == KAEvent::MESSAGE && event.emailId()
&& AlarmText::checkIfEmail(event.cleanText()))
mAkonadiItemId = event.akonadiItemId();
mEmailId = event.emailId();
lateCancel()->setAutoClose(event.autoClose());
if (event.useDefaultFont())
mFontColourButton->setDefaultFont();
......@@ -432,7 +432,7 @@ void EditDisplayAlarmDlg::setAction(KAEvent::SubAction action, const AlarmText&
case KAEvent::MESSAGE:
mTypeCombo->setCurrentIndex(tTEXT);
mTextMessageEdit->setPlainText(text);
mAkonadiItemId = alarmText.isEmail() ? alarmText.akonadiItemId() : -1;
mEmailId = alarmText.isEmail() ? alarmText.emailId() : -1;
break;
case KAEvent::FILE:
mTypeCombo->setCurrentIndex(tFILE);
......@@ -615,7 +615,7 @@ void EditDisplayAlarmDlg::type_setEvent(KAEvent& event, const KADateTime& dt, co
if (type == KAEvent::MESSAGE)
{
if (AlarmText::checkIfEmail(text))
event.setAkonadiItemId(mAkonadiItemId);
event.setEmailId(mEmailId);
}
float fadeVolume;
int fadeSecs;
......
......@@ -95,7 +95,7 @@ private:
CheckBox* mConfirmAck;
FontColourButton* mFontColourButton;
SpecialActionsButton* mSpecialActionsButton {nullptr};
Akonadi::Item::Id mAkonadiItemId; // if email text, message's Akonadi item ID, else -1
KAEvent::EmailId mEmailId; // if email text, message's Akonadi item ID, else -1
bool mReminderDeferral {false};
bool mReminderArchived {false};
// Text message alarm widgets
......
......@@ -56,10 +56,10 @@ public:
static QString mSubjectPrefixEn;
static bool mInitialised;
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 mBody, mFrom, mTo, mCc, mTime, mSubject;
KAEvent::EmailId mEmailId; // if email, message's Akonadi item ID, else -1
Type mType;
bool mIsEmail;
};
QString AlarmText::Private::mFromPrefix;
......@@ -134,17 +134,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, Akonadi::Item::Id itemId)
const QString& subject, const QString& body, KAEvent::EmailId emailId)
{
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->mAkonadiItemId = itemId;
d->mType = Private::Email;
d->mTo = to;
d->mFrom = from;
d->mCc = cc;
d->mTime = time;
d->mSubject = subject;
d->mBody = body;
d->mEmailId = emailId;
}
void AlarmText::setTodo(const KCalendarCore::Todo::Ptr& todo)
......@@ -291,9 +291,9 @@ bool AlarmText::isTodo() const
return d->mType == Private::Todo;
}
Akonadi::Item::Id AlarmText::akonadiItemId() const
KAEvent::EmailId AlarmText::emailId() const
{
return d->mAkonadiItemId;
return d->mEmailId;
}
/******************************************************************************
......@@ -488,7 +488,7 @@ void AlarmText::Private::clear()
mCc.clear();
mTime.clear();
mSubject.clear();
mAkonadiItemId = -1;
mEmailId = -1;
}
/******************************************************************************
......
......@@ -11,8 +11,8 @@
#pragma once
#include "kalarmcal_export.h"
#include "kaevent.h"
#include <Akonadi/Item>
#include <KCalendarCore/Todo>
#include <QString>
......@@ -72,7 +72,7 @@ public:
* @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, Akonadi::Item::Id itemId = -1);
const QString& subject, const QString& body, KAEvent::EmailId emailId = -1);
/** Set the instance contents to be a todo.
* @param todo Todo instance to set as the text
......@@ -148,10 +148,10 @@ public:
/** Return whether the instance contains the text of a todo. */
bool isTodo() const;
/** Return the Akonadi item ID of an email.
* @return Item ID, or -1 if none.
/** Return the ID of an email.
* @return Email ID, or -1 if none.
*/
Akonadi::Item::Id akonadiItemId() const;
KAEvent::EmailId emailId() 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 @@
This file is part of kalarmcal library, which provides access to KAlarm
calendar data.
SPDX-FileCopyrightText: 2018-2020 David Jarvie <djarvie@kde.org>
SPDX-FileCopyrightText: 2018-2022 David Jarvie <djarvie@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
......@@ -861,7 +861,7 @@ void KAEventTest::fromKCalEvent()
KAEvent event(kcalevent);
QVERIFY(!event.emailBcc());
QCOMPARE(event.templateAfterTime(), 31);
QCOMPARE(event.akonadiItemId(), Akonadi::Item::Id(-1));
QCOMPARE(event.emailId(), KAEvent::EmailId(-1));
}
{
// Akonadi item ID, with alarm message in email format
......@@ -871,14 +871,14 @@ void KAEventTest::fromKCalEvent()
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.akonadiItemId(), Akonadi::Item::Id(759231));
QCOMPARE(event.emailId(), KAEvent::EmailId(759231));
}
{
// 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.akonadiItemId(), Akonadi::Item::Id(-1));
QCOMPARE(event.emailId(), KAEvent::EmailId(-1));
}
// Alarm custom properties
......
......@@ -267,7 +267,7 @@ public:
int mNextRepeat{0}; // repetition count of next due sub-repetition
int mAlarmCount{0}; // number of alarms: count of !mMainExpired, mRepeatAtLogin, mDeferral, mReminderActive, mDisplaying
DeferType mDeferral{NO_DEFERRAL}; // whether the alarm is an extra deferred/deferred-reminder alarm
Akonadi::Item::Id mAkonadiItemId{-1}; // if email text, message's Akonadi item ID
KAEvent::EmailId mEmailId{-1}; // if email text, message's Akonadi item ID
int mTemplateAfterTime{-1}; // 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
......@@ -641,10 +641,10 @@ KAEventPrivate::KAEventPrivate(const KCalendarCore::Event::Ptr& event)
mNotify = true;
else if (flag == KMAIL_ITEM_FLAG)
{
const Akonadi::Item::Id id = flags.at(i + 1).toLongLong(&ok);
const KAEvent::EmailId id = flags.at(i + 1).toLongLong(&ok);
if (!ok)
continue;
mAkonadiItemId = id;
mEmailId = id;
++i;
}
else if (flag == KAEventPrivate::ARCHIVE_FLAG)
......@@ -922,7 +922,7 @@ KAEventPrivate::KAEventPrivate(const KCalendarCore::Event::Ptr& event)
}
}
if (!isEmailText)
mAkonadiItemId = -1;
mEmailId = -1;
Recurrence* recur = event->recurrence();
if (recur && recur->recurs())
......@@ -1034,7 +1034,7 @@ void KAEventPrivate::copy(const KAEventPrivate& event)
mNextRepeat = event.mNextRepeat;
mAlarmCount = event.mAlarmCount;
mDeferral = event.mDeferral;
mAkonadiItemId = event.mAkonadiItemId;
mEmailId = event.mEmailId;
mTemplateAfterTime = event.mTemplateAfterTime;
mBgColour = event.mBgColour;
mFgColour = event.mFgColour;
......@@ -1174,8 +1174,8 @@ bool KAEventPrivate::updateKCalEvent(const Event::Ptr& ev, KAEvent::UidAction ui
}
if (mCategory == CalEvent::TEMPLATE && mTemplateAfterTime >= 0)
(flags += TEMPL_AFTER_TIME_FLAG) += QString::number(mTemplateAfterTime);
if (mAkonadiItemId >= 0)
(flags += KMAIL_ITEM_FLAG) += QString::number(mAkonadiItemId);
if (mEmailId >= 0)
(flags += KMAIL_ITEM_FLAG) += QString::number(mEmailId);
if (mArchive && !archived)
{
flags += ARCHIVE_FLAG;
......@@ -1749,14 +1749,14 @@ bool KAEvent::notify() const
return d->mNotify;
}
void KAEvent::setAkonadiItemId(Akonadi::Item::Id id)
void KAEvent::setEmailId(EmailId id)
{
d->mAkonadiItemId = id;
d->mEmailId = id;
}
Akonadi::Item::Id KAEvent::akonadiItemId() const
KAEvent::EmailId KAEvent::emailId() const
{
return d->mAkonadiItemId;
return d->mEmailId;
}
void KAEvent::setName(const QString& newName)
......@@ -3720,7 +3720,7 @@ bool KAEventPrivate::compare(const KAEventPrivate& other, KAEvent::Comparison co
|| mCommandError != other.mCommandError
|| mConfirmAck != other.mConfirmAck
|| mNotify != other.mNotify
|| mAkonadiItemId != other.mAkonadiItemId
|| mEmailId != other.mEmailId
|| mBeep != other.mBeep
|| mSpeak != other.mSpeak
|| mAudioFile != other.mAudioFile)
......@@ -3891,7 +3891,7 @@ void KAEventPrivate::dumpDebug() const
qCDebug(KALARMCAL_LOG) << "-- mSoundVolume:-:";
qCDebug(KALARMCAL_LOG) << "-- mRepeatSoundPause:" << mRepeatSoundPause;
}
qCDebug(KALARMCAL_LOG) << "-- mAkonadiItemId:" << mAkonadiItemId;
qCDebug(KALARMCAL_LOG) << "-- mEmailId:" << mEmailId;
qCDebug(KALARMCAL_LOG) << "-- mCopyToKOrganizer:" << mCopyToKOrganizer;
qCDebug(KALARMCAL_LOG) << "-- mExcludeHolidays:" << mExcludeHolidays;
qCDebug(KALARMCAL_LOG) << "-- mWorkTimeOnly:" << mWorkTimeOnly;
......
......@@ -17,7 +17,6 @@
#include "kacalendar.h"
#include "repetition.h"
#include <Akonadi/Item>
#include <KCalendarCore/Calendar>
#include <KCalendarCore/Person>
......@@ -189,6 +188,9 @@ public:
/** A list of pointers to KAEvent objects. */
using List = QVector<KAEvent*>;
/** Email ID, equivalent to Akonadi::Item::Id. */
using EmailId = qint64;
/** Flags for use in D-Bus calls, etc. Flags may be combined by OR'ing them together. */
enum Flag
{
......@@ -515,11 +517,11 @@ public:
/** Set the Akonadi item ID of the email which the alarm is related to.
*/
void setAkonadiItemId(Akonadi::Item::Id id);
void setEmailId(EmailId id);
/** Return the Akonadi item ID of the email which the alarm is related to.
/** Return the ID of the email which the alarm is related to.
*/
Akonadi::Item::Id akonadiItemId() const;
EmailId emailId() const;
/** Set the alarm's name. */
void setName(const QString& newName);
......
......@@ -372,7 +372,7 @@ QString KAEventFormatter::value(Parameter param) const
case ConfirmAck:
return trueFalse(mEvent.confirmAck());
case AkonadiItem:
return (mEvent.akonadiItemId() >= 0) ? QLocale().toString(mEvent.akonadiItemId()) : trueFalse(false);
return (mEvent.emailId() >= 0) ? QLocale().toString(mEvent.emailId()) : trueFalse(false);
case Sound:
return !mEvent.audioFile().isEmpty() ? mEvent.audioFile()
: mEvent.speak() ? i18nc("@info", "Speak")
......
......@@ -170,7 +170,7 @@ protected:
float mVolume() const { return mHelper->mVolume; }
float mFadeVolume() const { return mHelper->mFadeVolume; }
int mDefaultDeferMinutes() const { return mHelper->mDefaultDeferMinutes; }
Akonadi::Item::Id mAkonadiItemId() const { return mHelper->mAkonadiItemId; }
KAEvent::EmailId mEmailId() const { return mHelper->mEmailId; }
KAEvent::CmdErrType mCommandError() const { return mHelper->mCommandError; }
bool& mNoPostAction() { return mHelper->mNoPostAction; }
......
......@@ -84,7 +84,7 @@ MessageDisplayHelper::MessageDisplayHelper(MessageDisplay* parent, const KAEvent
, mDefaultDeferMinutes(event.deferDefaultMinutes())
, mAlarmType(alarm.type())
, mAction(event.actionSubType())
, mAkonadiItemId(event.akonadiItemId())
, mEmailId(event.emailId())
, mCommandError(event.commandError())
, mAudioRepeatPause(event.repeatSoundPause())
, mConfirmAck(event.confirmAck())
......@@ -139,7 +139,7 @@ MessageDisplayHelper::MessageDisplayHelper(MessageDisplay* parent, const KAEvent
, mEventId(event)
, mAlarmType(KAAlarm::MAIN_ALARM)
, mAction(event.actionSubType())
, mAkonadiItemId(-1)
, mEmailId(-1)
, mCommandError(KAEvent::CMD_NO_ERROR)
, mErrorMsgs(errmsgs)
, mDontShowAgain(dontShowAgain)
......@@ -605,7 +605,7 @@ bool MessageDisplayHelper::saveProperties(KConfigGroup& config)
config.writeEntry("DeferMins", mDefaultDeferMinutes);
config.writeEntry("NoDefer", mNoDefer);
config.writeEntry("NoPostAction", mNoPostAction);
config.writeEntry("AkonadiItemId", mAkonadiItemId);
config.writeEntry("EmailId", mEmailId);
config.writeEntry("CmdErr", static_cast<int>(mCommandError));
config.writeEntry("DontShowAgain", mDontShowAgain);
return true;
......@@ -681,7 +681,7 @@ bool MessageDisplayHelper::readPropertyValues(const KConfigGroup& config)
mDefaultDeferMinutes = config.readEntry("DeferMins", 0);
mNoDefer = config.readEntry("NoDefer", false);
mNoPostAction = config.readEntry("NoPostAction", true);
mAkonadiItemId = config.readEntry("AkonadiItemId", QVariant(QVariant::LongLong)).toLongLong();
mEmailId = config.readEntry("EmailId", QVariant(QVariant::LongLong)).toLongLong();
mCommandError = KAEvent::CmdErrType(config.readEntry("CmdErr", static_cast<int>(KAEvent::CMD_NO_ERROR)));
mDontShowAgain = config.readEntry("DontShowAgain", QString());
mShowEdit = false;
......
......@@ -168,7 +168,7 @@ public:
int mDefaultDeferMinutes;
KAAlarm::Type mAlarmType;
KAEvent::SubAction mAction;
Akonadi::Item::Id mAkonadiItemId; // if email text, message's Akonadi Item ID, else -1
KAEvent::EmailId mEmailId; // if email text, message's Akonadi Item ID, else -1
KAEvent::CmdErrType mCommandError;
QStringList mErrorMsgs;
QString mDontShowAgain; // non-null for don't-show-again option with error message
......
......@@ -468,7 +468,7 @@ void MessageWindow::setUpDisplay()
mHelper->setSilenceButton(mSilenceButton);
}
if (mAkonadiItemId() >= 0)
if (mEmailId() >= 0)
{
// KMail button
mKMailButton = new PushButton(topWidget);
......@@ -1094,7 +1094,7 @@ void MessageWindow::slotOk()
void MessageWindow::slotShowKMailMessage()
{
qCDebug(KALARM_LOG) << "MessageWindow::slotShowKMailMessage";
if (mAkonadiItemId() < 0)
if (mEmailId() < 0)
return;
const QString err = KAlarm::runKMail();
if (!err.isNull())
......@@ -1104,7 +1104,7 @@ void MessageWindow::slotShowKMailMessage()
}
org::kde::kmail::kmail kmail(KMAIL_DBUS_SERVICE, KMAIL_DBUS_PATH, QDBusConnection::sessionBus());
// Display the message contents
QDBusReply<bool> reply = kmail.showMail(mAkonadiItemId());
QDBusReply<bool> reply = kmail.showMail(mEmailId());
bool failed1 = true;
bool failed2 = true;
if (!reply.isValid())
......@@ -1113,13 +1113,13 @@ void MessageWindow::slotShowKMailMessage()
failed1 = false;
// Select the mail folder containing the message
Akonadi::ItemFetchJob* job = new Akonadi::ItemFetchJob(Akonadi::Item(mAkonadiItemId()));
Akonadi::ItemFetchJob* job = new Akonadi::ItemFetchJob(Akonadi::Item(mEmailId()));
job->fetchScope().setAncestorRetrieval(Akonadi::ItemFetchScope::Parent);
Akonadi::Item::List items;
if (job->exec())
items = job->items();
if (items.isEmpty() || !items.at(0).isValid())
qCWarning(KALARM_LOG) << "MessageWindow::slotShowKMailMessage: No parent found for item" << mAkonadiItemId();
qCWarning(KALARM_LOG) << "MessageWindow::slotShowKMailMessage: No parent found for item" << mEmailId();
else
{
const Akonadi::Item& it = items.at(0);
......
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