Verified Commit 09f621ab authored by Daniel Vrátil's avatar Daniel Vrátil 🤖
Browse files

Merge contents of libKF5FollowupReminder into the Agent

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/D29699
parent 643897ac
......@@ -121,7 +121,6 @@ find_package(KF5PimTextEdit ${KPIMTEXTEDIT_LIB_VERSION} CONFIG REQUIRED)
find_package(KF5KontactInterface ${KONTACTINTERFACE_LIB_VERSION} CONFIG REQUIRED)
find_package(KF5Mime ${KMIME_LIB_VERSION} CONFIG REQUIRED)
find_package(KF5FollowupReminder ${KDEPIM_APPS_LIB_VERSION_LIB} CONFIG REQUIRED)
find_package(KF5Gravatar ${LIBGRAVATAR_VERSION_LIB} CONFIG REQUIRED)
find_package(KF5LibkdepimAkonadi ${LIBKDEPIM_LIB_VERSION_LIB} CONFIG REQUIRED)
find_package(KF5Libkleo ${LIBKLEO_LIB_VERSION_LIB} CONFIG REQUIRED)
......
......@@ -10,9 +10,16 @@ set(followupreminderagent_SRCS
followupremindermanager.cpp
followupremindernoanswerdialog.cpp
followupreminderinfowidget.cpp
followupreminderinfo.cpp
followupreminderutil.cpp
${followupreminderagent_job_SRCS}
)
kconfig_add_kcfg_files(followupreminderagent_SRCS
followupreminderagentsettings.kcfgc
)
ecm_qt_declare_logging_category(followupreminderagent_SRCS HEADER followupreminderagent_debug.h IDENTIFIER FOLLOWUPREMINDERAGENT_LOG CATEGORY_NAME org.kde.pim.followupreminderagent
DESCRIPTION "kmail (followupreminderagent)"
OLD_CATEGORY_NAMES log_followupreminderagent
......@@ -45,9 +52,6 @@ target_link_libraries(followupreminderagent
########################### Agent executable ################################
add_executable(akonadi_followupreminder_agent followupreminderagent.cpp)
target_link_libraries(akonadi_followupreminder_agent
followupreminderagent
KF5::AkonadiCore
......@@ -56,7 +60,6 @@ target_link_libraries(akonadi_followupreminder_agent
KF5::Mime
KF5::CalendarCore
KF5::DBusAddons
KF5::FollowupReminder
Qt5::Widgets
KF5::Notifications
KF5::I18n
......@@ -96,5 +99,4 @@ target_link_libraries(followupreminderagentconfig
KF5::AkonadiCore
KF5::XmlGui
KF5::I18n
KF5::FollowupReminder
)
......@@ -7,12 +7,12 @@ ecm_qt_declare_logging_category(autotest_categories_followupreminderagent_SRCS H
# Convenience macro to add unit tests.
macro( followupreminder_agent _source )
set( _test ${_source} ../followupreminderinfowidget.cpp ../jobs/followupremindershowmessagejob.cpp ../followupremindernoanswerdialog.cpp ${followupreminderagent_test_SRCS} ${autotest_categories_followupreminderagent_SRCS})
set( _test ${_source} ${followupreminderagent_test_SRCS} ${autotest_categories_followupreminderagent_SRCS})
get_filename_component( _name ${_source} NAME_WE )
ecm_add_test(${_test}
TEST_NAME ${_name}
NAME_PREFIX "followupreminder-"
LINK_LIBRARIES Qt5::Test KF5::AkonadiCore KF5::FollowupReminder Qt5::Widgets KF5::I18n KF5::XmlGui KF5::Service
LINK_LIBRARIES followupreminderagent Qt5::Test KF5::AkonadiCore Qt5::Widgets KF5::I18n KF5::XmlGui KF5::Service
)
endmacro()
......
......@@ -18,8 +18,9 @@
*/
#include "followupreminderconfigtest.h"
#include <FollowupReminder/FollowUpReminderUtil>
#include <FollowupReminder/FollowUpReminderInfo>
#include "../followupreminderutil.h"
#include "../followupreminderinfo.h"
#include <QTest>
#include <KSharedConfig>
#include <QRegularExpression>
......
......@@ -18,7 +18,8 @@
*/
#include "followupreminderinfotest.h"
#include <FollowupReminder/FollowUpReminderInfo>
#include "../followupreminderinfo.h"
#include <QTest>
#include <KConfigGroup>
#include <KSharedConfig>
......
......@@ -20,7 +20,8 @@
#include "followupremindernoanswerdialogtest.h"
#include "../followupremindernoanswerdialog.h"
#include "../followupreminderinfowidget.h"
#include <FollowupReminder/FollowUpReminderInfo>
#include "../followupreminderinfo.h"
#include <QTreeWidget>
#include <QTest>
#include <QStandardPaths>
......
......@@ -19,10 +19,10 @@
#include "followupreminderagent.h"
#include "followupremindermanager.h"
#include <FollowupReminder/FollowUpReminderUtil>
#include "followupreminderutil.h"
#include "followupreminderadaptor.h"
#include "followupreminderagentsettings.h"
#include <FollowupReminder/FollowUpReminderInfo>
#include "followupreminderinfo.h"
#include <KMime/Message>
......
<?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>
# Code generation options for kconfig_compiler
File=followupreminderagentsettings.kcfg
ClassName=FollowUpReminderAgentSettings
Singleton=true
Mutators=true
/*
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;
}
/*
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
......@@ -17,8 +17,8 @@
Boston, MA 02110-1301, USA.
*/
#include "followupreminderinfowidget.h"
#include <FollowupReminder/FollowUpReminderInfo>
#include <FollowupReminder/FollowUpReminderUtil>
#include "followupreminderinfo.h"
#include "followupreminderutil.h"
#include "jobs/followupremindershowmessagejob.h"
#include "followupreminderagent_debug.h"
......@@ -108,7 +108,7 @@ void FollowUpReminderInfoWidget::setInfo(const QList<FollowUpReminder::FollowUpR
void FollowUpReminderInfoWidget::load()
{
KSharedConfig::Ptr config = KSharedConfig::openConfig();
auto config = FollowUpReminder::FollowUpReminderUtil::defaultConfig();
const QStringList filterGroups = config->groupList().filter(QRegularExpression(followUpItemPattern()));
const int numberOfItem = filterGroups.count();
for (int i = 0; i < numberOfItem; ++i) {
......
......@@ -19,11 +19,12 @@
#include "followupremindermanager.h"
#include "followupreminderagent_debug.h"
#include <FollowupReminder/FollowUpReminderInfo>
#include <FollowupReminder/FollowUpReminderUtil>
#include "followupreminderinfo.h"
#include "followupreminderutil.h"
#include "followupremindernoanswerdialog.h"
#include "jobs/followupreminderjob.h"
#include "jobs/followupreminderfinishtaskjob.h"
#include <Akonadi/KMime/SpecialMailCollections>
#include <KConfigGroup>
......
......@@ -19,10 +19,9 @@
#include "followupremindernoanswerdialog.h"
#include "followupreminderinfowidget.h"
#include "followupreminderinfo.h"
#include "followupreminderagent_debug.h"
#include <FollowupReminder/FollowUpReminderInfo>
#include <KLocalizedString>
#include <KSharedConfig>
......
/*
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;