Summary: The library is no longer used anywhere and the agent now has DBus API that clients can use to interact with it, so we no longer need a dedicated library. This changes moves the code from the library into the Agent (where it is still used). Some cleanup changes will follow soon after. Reviewers: mlaurent Reviewed By: mlaurent Subscribers: kde-pim Tags: #kde_pim Differential Revision: https://phabricator.kde.org/D29699wilder
parent
643897ac54
commit
09f621ab19
21 changed files with 538 additions and 28 deletions
@ -0,0 +1,12 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0 |
||||
http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" > |
||||
<kcfgfile name="akonadi_followupreminder_agentrc" /> |
||||
<group name="General"> |
||||
<entry name="enabled" key="enabled" type="Bool"> |
||||
<default>true</default> |
||||
</entry> |
||||
</group> |
||||
</kcfg> |
||||
@ -0,0 +1,6 @@ |
||||
# Code generation options for kconfig_compiler |
||||
File=followupreminderagentsettings.kcfg |
||||
ClassName=FollowUpReminderAgentSettings |
||||
Singleton=true |
||||
Mutators=true |
||||
|
||||
@ -0,0 +1,201 @@ |
||||
/*
|
||||
Copyright (C) 2014-2020 Laurent Montel <montel@kde.org> |
||||
|
||||
This program is free software; you can redistribute it and/or |
||||
modify it under the terms of the GNU General Public |
||||
License as published by the Free Software Foundation; either |
||||
version 2 of the License, or (at your option) any later version. |
||||
|
||||
This program is distributed in the hope that it will be useful, |
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
General Public License for more details. |
||||
|
||||
You should have received a copy of the GNU General Public License |
||||
along with this program; see the file COPYING. If not, write to |
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
||||
Boston, MA 02110-1301, USA. |
||||
*/ |
||||
#include "followupreminderinfo.h" |
||||
|
||||
#include <KConfigGroup> |
||||
using namespace FollowUpReminder; |
||||
|
||||
FollowUpReminderInfo::FollowUpReminderInfo() |
||||
{ |
||||
} |
||||
|
||||
FollowUpReminderInfo::FollowUpReminderInfo(const KConfigGroup &config) |
||||
{ |
||||
readConfig(config); |
||||
} |
||||
|
||||
FollowUpReminderInfo::FollowUpReminderInfo(const FollowUpReminderInfo &info) |
||||
{ |
||||
mFollowUpReminderDate = info.followUpReminderDate(); |
||||
mOriginalMessageItemId = info.originalMessageItemId(); |
||||
mMessageId = info.messageId(); |
||||
mTo = info.to(); |
||||
mSubject = info.subject(); |
||||
mAnswerWasReceived = info.answerWasReceived(); |
||||
mAnswerMessageItemId = info.answerMessageItemId(); |
||||
mUniqueIdentifier = info.uniqueIdentifier(); |
||||
mTodoId = info.todoId(); |
||||
} |
||||
|
||||
void FollowUpReminderInfo::readConfig(const KConfigGroup &config) |
||||
{ |
||||
if (config.hasKey(QStringLiteral("followUpReminderDate"))) { |
||||
mFollowUpReminderDate = QDate::fromString(config.readEntry("followUpReminderDate"), Qt::ISODate); |
||||
} |
||||
mOriginalMessageItemId = config.readEntry("itemId", -1); |
||||
mMessageId = config.readEntry("messageId", QString()); |
||||
mTo = config.readEntry("to", QString()); |
||||
mSubject = config.readEntry("subject", QString()); |
||||
mAnswerWasReceived = config.readEntry("answerWasReceived", false); |
||||
mAnswerMessageItemId = config.readEntry("answerMessageItemId", -1); |
||||
mTodoId = config.readEntry("todoId", -1); |
||||
mUniqueIdentifier = config.readEntry("identifier", -1); |
||||
} |
||||
|
||||
qint32 FollowUpReminderInfo::uniqueIdentifier() const |
||||
{ |
||||
return mUniqueIdentifier; |
||||
} |
||||
|
||||
void FollowUpReminderInfo::setUniqueIdentifier(qint32 uniqueIdentifier) |
||||
{ |
||||
mUniqueIdentifier = uniqueIdentifier; |
||||
} |
||||
|
||||
Akonadi::Item::Id FollowUpReminderInfo::answerMessageItemId() const |
||||
{ |
||||
return mAnswerMessageItemId; |
||||
} |
||||
|
||||
void FollowUpReminderInfo::setAnswerMessageItemId(Akonadi::Item::Id answerMessageId) |
||||
{ |
||||
mAnswerMessageItemId = answerMessageId; |
||||
} |
||||
|
||||
bool FollowUpReminderInfo::answerWasReceived() const |
||||
{ |
||||
return mAnswerWasReceived; |
||||
} |
||||
|
||||
void FollowUpReminderInfo::setAnswerWasReceived(bool answerWasReceived) |
||||
{ |
||||
mAnswerWasReceived = answerWasReceived; |
||||
} |
||||
|
||||
QString FollowUpReminderInfo::subject() const |
||||
{ |
||||
return mSubject; |
||||
} |
||||
|
||||
void FollowUpReminderInfo::setSubject(const QString &subject) |
||||
{ |
||||
mSubject = subject; |
||||
} |
||||
|
||||
void FollowUpReminderInfo::writeConfig(KConfigGroup &config, qint32 identifier) |
||||
{ |
||||
if (mFollowUpReminderDate.isValid()) { |
||||
config.writeEntry("followUpReminderDate", mFollowUpReminderDate.toString(Qt::ISODate)); |
||||
} |
||||
setUniqueIdentifier(identifier); |
||||
config.writeEntry("messageId", mMessageId); |
||||
config.writeEntry("itemId", mOriginalMessageItemId); |
||||
config.writeEntry("to", mTo); |
||||
config.writeEntry("subject", mSubject); |
||||
config.writeEntry("answerWasReceived", mAnswerWasReceived); |
||||
config.writeEntry("answerMessageItemId", mAnswerMessageItemId); |
||||
config.writeEntry("todoId", mTodoId); |
||||
config.writeEntry("identifier", identifier); |
||||
config.sync(); |
||||
} |
||||
|
||||
Akonadi::Item::Id FollowUpReminderInfo::originalMessageItemId() const |
||||
{ |
||||
return mOriginalMessageItemId; |
||||
} |
||||
|
||||
void FollowUpReminderInfo::setOriginalMessageItemId(Akonadi::Item::Id value) |
||||
{ |
||||
mOriginalMessageItemId = value; |
||||
} |
||||
|
||||
Akonadi::Item::Id FollowUpReminderInfo::todoId() const |
||||
{ |
||||
return mTodoId; |
||||
} |
||||
|
||||
void FollowUpReminderInfo::setTodoId(Akonadi::Item::Id value) |
||||
{ |
||||
mTodoId = value; |
||||
} |
||||
|
||||
bool FollowUpReminderInfo::isValid() const |
||||
{ |
||||
return !mMessageId.isEmpty() |
||||
&& mFollowUpReminderDate.isValid() |
||||
&& !mTo.isEmpty(); |
||||
} |
||||
|
||||
QString FollowUpReminderInfo::messageId() const |
||||
{ |
||||
return mMessageId; |
||||
} |
||||
|
||||
void FollowUpReminderInfo::setMessageId(const QString &messageId) |
||||
{ |
||||
mMessageId = messageId; |
||||
} |
||||
|
||||
void FollowUpReminderInfo::setTo(const QString &to) |
||||
{ |
||||
mTo = to; |
||||
} |
||||
|
||||
QString FollowUpReminderInfo::to() const |
||||
{ |
||||
return mTo; |
||||
} |
||||
|
||||
QDate FollowUpReminderInfo::followUpReminderDate() const |
||||
{ |
||||
return mFollowUpReminderDate; |
||||
} |
||||
|
||||
void FollowUpReminderInfo::setFollowUpReminderDate(const QDate &followUpReminderDate) |
||||
{ |
||||
mFollowUpReminderDate = followUpReminderDate; |
||||
} |
||||
|
||||
bool FollowUpReminderInfo::operator==(const FollowUpReminderInfo &other) const |
||||
{ |
||||
return mOriginalMessageItemId == other.originalMessageItemId() |
||||
&& mMessageId == other.messageId() |
||||
&& mTo == other.to() |
||||
&& mFollowUpReminderDate == other.followUpReminderDate() |
||||
&& mSubject == other.subject() |
||||
&& mAnswerWasReceived == other.answerWasReceived() |
||||
&& mAnswerMessageItemId == other.answerMessageItemId() |
||||
&& mUniqueIdentifier == other.uniqueIdentifier() |
||||
&& mTodoId == other.todoId(); |
||||
} |
||||
|
||||
QDebug operator<<(QDebug d, const FollowUpReminderInfo &other) |
||||
{ |
||||
d << "mOriginalMessageItemId: " << other.originalMessageItemId(); |
||||
d << "mMessageId: " << other.messageId(); |
||||
d << "mTo: " << other.to(); |
||||
d << "mFollowUpReminderDate: " << other.followUpReminderDate(); |
||||
d << "mSubject: " << other.subject(); |
||||
d << "mAnswerWasReceived: " << other.answerWasReceived(); |
||||
d << "mAnswerMessageItemId: " << other.answerMessageItemId(); |
||||
d << "mUniqueIdentifier: " << other.uniqueIdentifier(); |
||||
d << "mTodoId: " << other.todoId(); |
||||
|
||||
return d; |
||||
} |
||||
@ -0,0 +1,87 @@ |
||||
/*
|
||||
Copyright (C) 2014-2020 Laurent Montel <montel@kde.org> |
||||
|
||||
This program is free software; you can redistribute it and/or |
||||
modify it under the terms of the GNU General Public |
||||
License as published by the Free Software Foundation; either |
||||
version 2 of the License, or (at your option) any later version. |
||||
|
||||
This program is distributed in the hope that it will be useful, |
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
General Public License for more details. |
||||
|
||||
You should have received a copy of the GNU General Public License |
||||
along with this program; see the file COPYING. If not, write to |
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
||||
Boston, MA 02110-1301, USA. |
||||
*/ |
||||
|
||||
#ifndef FOLLOWUPREMINDERINFO_H |
||||
#define FOLLOWUPREMINDERINFO_H |
||||
|
||||
#include <AkonadiCore/Item> |
||||
#include <QDate> |
||||
|
||||
class KConfigGroup; |
||||
namespace FollowUpReminder { |
||||
|
||||
/** Follow up reminder information. */ |
||||
class FollowUpReminderInfo |
||||
{ |
||||
public: |
||||
FollowUpReminderInfo(); |
||||
FollowUpReminderInfo(const KConfigGroup &config); |
||||
FollowUpReminderInfo(const FollowUpReminderInfo &info); |
||||
|
||||
//Can be invalid.
|
||||
Q_REQUIRED_RESULT Akonadi::Item::Id originalMessageItemId() const; |
||||
void setOriginalMessageItemId(Akonadi::Item::Id value); |
||||
|
||||
Q_REQUIRED_RESULT Akonadi::Item::Id todoId() const; |
||||
void setTodoId(Akonadi::Item::Id value); |
||||
|
||||
Q_REQUIRED_RESULT bool isValid() const; |
||||
|
||||
Q_REQUIRED_RESULT QString messageId() const; |
||||
void setMessageId(const QString &messageId); |
||||
|
||||
void setTo(const QString &to); |
||||
Q_REQUIRED_RESULT QString to() const; |
||||
|
||||
Q_REQUIRED_RESULT QDate followUpReminderDate() const; |
||||
void setFollowUpReminderDate(const QDate &followUpReminderDate); |
||||
|
||||
void writeConfig(KConfigGroup &config, qint32 identifier); |
||||
|
||||
Q_REQUIRED_RESULT QString subject() const; |
||||
void setSubject(const QString &subject); |
||||
|
||||
bool operator ==(const FollowUpReminderInfo &other) const; |
||||
|
||||
Q_REQUIRED_RESULT bool answerWasReceived() const; |
||||
void setAnswerWasReceived(bool answerWasReceived); |
||||
|
||||
Q_REQUIRED_RESULT Akonadi::Item::Id answerMessageItemId() const; |
||||
void setAnswerMessageItemId(Akonadi::Item::Id answerMessageItemId); |
||||
|
||||
Q_REQUIRED_RESULT qint32 uniqueIdentifier() const; |
||||
void setUniqueIdentifier(qint32 uniqueIdentifier); |
||||
|
||||
private: |
||||
void readConfig(const KConfigGroup &config); |
||||
Akonadi::Item::Id mOriginalMessageItemId = -1; |
||||
Akonadi::Item::Id mAnswerMessageItemId = -1; |
||||
Akonadi::Item::Id mTodoId = -1; |
||||
QString mMessageId; |
||||
QDate mFollowUpReminderDate; |
||||
QString mTo; |
||||
QString mSubject; |
||||
qint32 mUniqueIdentifier = -1; |
||||
bool mAnswerWasReceived = false; |
||||
}; |
||||
} |
||||
|
||||
QDebug operator<<(QDebug debug, const FollowUpReminder::FollowUpReminderInfo &info); |
||||
|
||||
#endif // FOLLOWUPREMINDERINFO_H
|
||||
@ -0,0 +1,140 @@ |
||||
/*
|
||||
Copyright (C) 2014-2020 Laurent Montel <montel@kde.org> |
||||
|
||||
This program is free software; you can redistribute it and/or |
||||
modify it under the terms of the GNU General Public |
||||
License as published by the Free Software Foundation; either |
||||
version 2 of the License, or (at your option) any later version. |
||||
|
||||
This program is distributed in the hope that it will be useful, |
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
General Public License for more details. |
||||
|
||||
You should have received a copy of the GNU General Public License |
||||
along with this program; see the file COPYING. If not, write to |
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
||||
Boston, MA 02110-1301, USA. |
||||
*/ |
||||
|
||||
#include "followupreminderutil.h" |
||||
#include "followupreminderinfo.h" |
||||
#include <AkonadiCore/ServerManager> |
||||
|
||||
#include <QDBusInterface> |
||||
#include "followupreminderagentsettings.h" |
||||
|
||||
namespace { |
||||
QString serviceName() |
||||
{ |
||||
return Akonadi::ServerManager::agentServiceName(Akonadi::ServerManager::Agent, |
||||
QStringLiteral("akonadi_followupreminder_agent")); |
||||
} |
||||
|
||||
QString dbusPath() |
||||
{ |
||||
return QStringLiteral("/FollowUpReminder"); |
||||
} |
||||
} |
||||
|
||||
bool FollowUpReminder::FollowUpReminderUtil::followupReminderAgentWasRegistered() |
||||
{ |
||||
QDBusInterface interface(serviceName(), dbusPath()); |
||||
return interface.isValid(); |
||||
} |
||||
|
||||
bool FollowUpReminder::FollowUpReminderUtil::followupReminderAgentEnabled() |
||||
{ |
||||
return FollowUpReminderAgentSettings::self()->enabled(); |
||||
} |
||||
|
||||
void FollowUpReminder::FollowUpReminderUtil::reload() |
||||
{ |
||||
QDBusInterface interface(serviceName(), dbusPath()); |
||||
if (interface.isValid()) { |
||||
interface.call(QStringLiteral("reload")); |
||||
} |
||||
} |
||||
|
||||
void FollowUpReminder::FollowUpReminderUtil::forceReparseConfiguration() |
||||
{ |
||||
FollowUpReminderAgentSettings::self()->save(); |
||||
FollowUpReminderAgentSettings::self()->config()->reparseConfiguration(); |
||||
} |
||||
|
||||
KSharedConfig::Ptr FollowUpReminder::FollowUpReminderUtil::defaultConfig() |
||||
{ |
||||
return KSharedConfig::openConfig(QStringLiteral("akonadi_followupreminder_agentrc"), KConfig::SimpleConfig); |
||||
} |
||||
|
||||
void FollowUpReminder::FollowUpReminderUtil::writeFollowupReminderInfo(KSharedConfig::Ptr config, FollowUpReminder::FollowUpReminderInfo *info, bool forceReload) |
||||
{ |
||||
if (!info || !info->isValid()) { |
||||
return; |
||||
} |
||||
|
||||
KConfigGroup general = config->group(QStringLiteral("General")); |
||||
int value = general.readEntry("Number", 0); |
||||
int identifier = info->uniqueIdentifier(); |
||||
if (identifier == -1) { |
||||
identifier = value; |
||||
} |
||||
++value; |
||||
|
||||
const QString groupName = FollowUpReminder::FollowUpReminderUtil::followUpReminderPattern().arg(identifier); |
||||
// first, delete all filter groups:
|
||||
const QStringList filterGroups = config->groupList(); |
||||
for (const QString &group : filterGroups) { |
||||
if (group == groupName) { |
||||
config->deleteGroup(group); |
||||
} |
||||
} |
||||
KConfigGroup group = config->group(groupName); |
||||
info->writeConfig(group, identifier); |
||||
|
||||
general.writeEntry("Number", value); |
||||
|
||||
config->sync(); |
||||
config->reparseConfiguration(); |
||||
if (forceReload) { |
||||
reload(); |
||||
} |
||||
} |
||||
|
||||
bool FollowUpReminder::FollowUpReminderUtil::removeFollowupReminderInfo(KSharedConfig::Ptr config, const QList<qint32> &listRemove, bool forceReload) |
||||
{ |
||||
if (listRemove.isEmpty()) { |
||||
return false; |
||||
} |
||||
|
||||
bool needSaveConfig = false; |
||||
KConfigGroup general = config->group(QStringLiteral("General")); |
||||
int value = general.readEntry("Number", 0); |
||||
|
||||
for (qint32 identifier : listRemove) { |
||||
const QString groupName = FollowUpReminder::FollowUpReminderUtil::followUpReminderPattern().arg(identifier); |
||||
const QStringList filterGroups = config->groupList(); |
||||
for (const QString &group : filterGroups) { |
||||
if (group == groupName) { |
||||
config->deleteGroup(group); |
||||
--value; |
||||
needSaveConfig = true; |
||||
} |
||||
} |
||||
} |
||||
if (needSaveConfig) { |
||||
general.writeEntry("Number", value); |
||||
|
||||
config->sync(); |
||||
config->reparseConfiguration(); |
||||
if (forceReload) { |
||||
reload(); |
||||
} |
||||
} |
||||
return needSaveConfig; |
||||
} |
||||
|
||||
QString FollowUpReminder::FollowUpReminderUtil::followUpReminderPattern() |
||||
{ |
||||
return QStringLiteral("FollowupReminderItem %1"); |
||||
} |
||||
@ -0,0 +1,49 @@ |
||||
/*
|
||||
Copyright (C) 2014-2020 Laurent Montel <montel@kde.org> |
||||
|
||||
This program is free software; you can redistribute it and/or |
||||
modify it under the terms of the GNU General Public |
||||
License as published by the Free Software Foundation; either |
||||
version 2 of the License, or (at your option) any later version. |
||||
|
||||
This program is distributed in the hope that it will be useful, |
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
General Public License for more details. |
||||
|
||||
You should have received a copy of the GNU General Public License |
||||
along with this program; see the file COPYING. If not, write to |
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
||||
Boston, MA 02110-1301, USA. |
||||
*/ |
||||
|
||||
#ifndef FOLLOWUPREMINDERUTIL_H |
||||
#define FOLLOWUPREMINDERUTIL_H |
||||
|
||||
#include <KSharedConfig> |
||||
|
||||
namespace FollowUpReminder { |
||||
class FollowUpReminderInfo; |
||||
|
||||
/** Follow up reminder utilities. */ |
||||
namespace FollowUpReminderUtil { |
||||
Q_REQUIRED_RESULT bool followupReminderAgentWasRegistered(); |
||||
|
||||
Q_REQUIRED_RESULT bool followupReminderAgentEnabled(); |
||||
|
||||
void reload(); |
||||
|
||||
void forceReparseConfiguration(); |
||||
|
||||
KSharedConfig::Ptr defaultConfig(); |
||||
|
||||
void writeFollowupReminderInfo(KSharedConfig::Ptr config, FollowUpReminder::FollowUpReminderInfo *info, bool forceReload); |
||||
|
||||
Q_REQUIRED_RESULT bool removeFollowupReminderInfo(KSharedConfig::Ptr config, const QList<qint32> &listRemove, bool forceReload = false); |
||||
|
||||
Q_REQUIRED_RESULT QString followUpReminderPattern(); |
||||
|
||||
} |
||||
} |
||||
|
||||
#endif // FOLLOWUPREMINDERUTIL_H
|
||||
Loading…
Reference in new issue