Verified Commit 5d276528 authored by Daniel Vrátil's avatar Daniel Vrátil 🤖
Browse files

[sendlater] Use the new agent DBus call to save SendLater information

Summary:
Rather than using a shared library from kdepim-apps-libs, we use DBus to
talk to the agent. This ultimately allows us to kill the dedicated
libKF5SendLater library.

This also moves some pieces of the libKF5SendLater library that are used
in MessageComposer public API into MessageComposer library.

Reviewers: mlaurent

Reviewed By: mlaurent

Subscribers: kde-pim

Tags: #kde_pim

Differential Revision: https://phabricator.kde.org/D29722
parent 5cceae12
......@@ -81,6 +81,10 @@ add_messagecomposer_test( composerviewbasetest.cpp )
add_messagecomposer_test( recipientseditortest.cpp )
# SendLater
add_messagecomposer_test( sendlaterdialogtest.cpp )
add_messagecomposer_test( sendlaterinfotest.cpp )
# Crypto
add_messagecomposer_cryptotest( signjobtest.cpp )
add_messagecomposer_cryptotest( encryptjobtest.cpp )
......
/*
Copyright (C) 2015-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 "sendlaterdialogtest.h"
#include "sendlater/sendlaterdialog.h"
#include <KTimeComboBox>
#include <KDateComboBox>
#include <QLineEdit>
#include <QPushButton>
#include <QTest>
#include <QStandardPaths>
SendLaterDialogTest::SendLaterDialogTest(QObject *parent)
: QObject(parent)
{
}
SendLaterDialogTest::~SendLaterDialogTest()
{
}
void SendLaterDialogTest::initTestCase()
{
QStandardPaths::setTestModeEnabled(true);
}
void SendLaterDialogTest::shouldHaveDefaultValue()
{
MessageComposer::SendLaterDialog dlg(nullptr);
KTimeComboBox *timeCombo = dlg.findChild<KTimeComboBox *>(QStringLiteral("time_sendlater"));
QVERIFY(timeCombo);
KDateComboBox *dateCombo = dlg.findChild<KDateComboBox *>(QStringLiteral("date_sendlater"));
QVERIFY(dateCombo);
QVERIFY(dateCombo->date().isValid());
QPushButton *okButton = dlg.findChild<QPushButton *>(QStringLiteral("okbutton"));
QVERIFY(okButton);
QVERIFY(okButton->isEnabled());
dateCombo->lineEdit()->clear();
QVERIFY(!dateCombo->date().isValid());
QVERIFY(!okButton->isEnabled());
}
QTEST_MAIN(SendLaterDialogTest)
/*
Copyright (C) 2015-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 SENDLATERDIALOGTEST_H
#define SENDLATERDIALOGTEST_H
#include <QObject>
class SendLaterDialogTest : public QObject
{
Q_OBJECT
public:
explicit SendLaterDialogTest(QObject *parent = nullptr);
~SendLaterDialogTest();
private Q_SLOTS:
void shouldHaveDefaultValue();
void initTestCase();
};
#endif // SENDLATERDIALOGTEST_H
/*
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 "sendlaterinfotest.h"
#include "sendlater/sendlaterinfo.h"
#include <QTest>
#include <QDateTime>
#include <QStandardPaths>
SendLaterInfoTest::SendLaterInfoTest(QObject *parent)
: QObject(parent)
{
QStandardPaths::setTestModeEnabled(true);
}
void SendLaterInfoTest::shouldHaveDefaultValue()
{
MessageComposer::SendLaterInfo info;
QCOMPARE(info.itemId(), Akonadi::Item::Id(-1));
QCOMPARE(info.isRecurrence(), false);
QVERIFY(!info.dateTime().isValid());
QVERIFY(!info.lastDateTimeSend().isValid());
QCOMPARE(info.to(), QString());
QCOMPARE(info.subject(), QString());
QVERIFY(!info.isValid());
QCOMPARE(info.recurrenceUnit(), MessageComposer::SendLaterInfo::Days);
QCOMPARE(info.recurrenceEachValue(), 1);
}
void SendLaterInfoTest::shouldNotValidIfIdIsNotValid()
{
MessageComposer::SendLaterInfo info;
const QString to = QStringLiteral("kde.org");
info.setTo(to);
info.setSubject(QStringLiteral("Subject"));
info.setRecurrence(true);
info.setRecurrenceEachValue(5);
info.setRecurrenceUnit(MessageComposer::SendLaterInfo::Years);
const QDate date(2014, 1, 1);
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
info.setDateTime(QDateTime(date));
info.setLastDateTimeSend(QDateTime(date));
#else
info.setDateTime(QDateTime(date.startOfDay()));
info.setLastDateTimeSend(QDateTime(date.startOfDay()));
#endif
QVERIFY(!info.isValid());
}
void SendLaterInfoTest::shouldNotValidIfDateIsNotValid()
{
MessageComposer::SendLaterInfo info;
const QString to = QStringLiteral("kde.org");
info.setTo(to);
info.setItemId(Akonadi::Item::Id(42));
info.setSubject(QStringLiteral("Subject"));
info.setRecurrence(true);
info.setRecurrenceEachValue(5);
info.setRecurrenceUnit(MessageComposer::SendLaterInfo::Years);
const QDate date(2014, 1, 1);
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
info.setLastDateTimeSend(QDateTime(date));
#else
info.setLastDateTimeSend(QDateTime(date.startOfDay()));
#endif
QVERIFY(!info.isValid());
}
void SendLaterInfoTest::shouldCopyInfo()
{
MessageComposer::SendLaterInfo info;
const QString to = QStringLiteral("kde.org");
info.setTo(to);
info.setItemId(Akonadi::Item::Id(42));
info.setSubject(QStringLiteral("Subject"));
info.setRecurrence(true);
info.setRecurrenceEachValue(5);
info.setRecurrenceUnit(MessageComposer::SendLaterInfo::Years);
const QDate date(2014, 1, 1);
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
info.setDateTime(QDateTime(date));
info.setLastDateTimeSend(QDateTime(date));
#else
info.setDateTime(QDateTime(date.startOfDay()));
info.setLastDateTimeSend(QDateTime(date.startOfDay()));
#endif
MessageComposer::SendLaterInfo copyInfo(info);
QCOMPARE(info, copyInfo);
}
QTEST_MAIN(SendLaterInfoTest)
/*
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 SENDLATERINFOTEST_H
#define SENDLATERINFOTEST_H
#include <QObject>
class SendLaterInfoTest : public QObject
{
Q_OBJECT
public:
explicit SendLaterInfoTest(QObject *parent = nullptr);
private Q_SLOTS:
void shouldHaveDefaultValue();
void shouldNotValidIfIdIsNotValid();
void shouldNotValidIfDateIsNotValid();
void shouldCopyInfo();
};
#endif // SENDLATERINFOTEST_H
......@@ -149,6 +149,20 @@ set(messagecomposer_plugineditorgrammar_SRCS
plugineditorgrammar/plugineditorgrammarmanager.cpp
plugineditorgrammar/plugineditorgrammarcustomtoolsviewinterface.cpp
)
set(messagecomposer_sendlater_SRCS
sendlater/sendlaterinfo.cpp
sendlater/sendlaterjob.cpp
sendlater/sendlatercreatejob.cpp
sendlater/sendlaterremovejob.cpp
sendlater/sendlaterutil.cpp
sendlater/sendlaterdialog.cpp
sendlater/sendlatertimedatewidget.cpp
)
qt5_add_dbus_interface(messagecomposer_sendlater_SRCS
sendlater/org.freedesktop.Akonadi.SendLaterAgent.xml
sendlaterinterface
)
set( messagecomposer_src
${messagecomposer_snippet_src}
......@@ -168,12 +182,14 @@ set( messagecomposer_src
${messagecomposer_followupreminder_SRCS}
${messagecomposer_plugineditorcheckbeforesend_SRCS}
${messagecomposer_plugineditorgrammar_SRCS}
${messagecomposer_sendlater_SRCS}
utils/util.cpp
settings/messagecomposersettings.cpp
)
ki18n_wrap_ui(messagecomposer_src
imagescaling/ui/imagescalingwidget.ui
sendlater/ui/sendlaterwidget.ui
)
ecm_qt_declare_logging_category(messagecomposer_src HEADER messagecomposer_debug.h IDENTIFIER MESSAGECOMPOSER_LOG CATEGORY_NAME org.kde.pim.messagecomposer
DESCRIPTION "messagelib (messagecomposer)"
......@@ -223,7 +239,6 @@ target_link_libraries(KF5MessageComposer
KF5::SonnetUi
Grantlee5::TextDocument
KF5::CalendarCore # for KCalendarCore/Todo
KF5::SendLater
KF5::Archive
KF5::Contacts
KF5::SonnetCore
......@@ -424,6 +439,19 @@ ecm_generate_headers(MessageComposer_Camelcaseimagescaling_HEADERS
RELATIVE imagescaling
)
ecm_generate_headers(MessageComposer_Camelcasesendlater_HEADERS
HEADER_NAMES
SendLaterInfo
SendLaterDialog
SendLaterUtil
SendLaterJob
SendLaterCreateJob
SendLaterRemoveJob
REQUIRED_HEADERS MessageComposer_sendlater_HEADERS
PREFIX MessageComposer
RELATIVE sendlater
)
ecm_generate_headers(MessageComposer_Camelcasejob_HEADERS
HEADER_NAMES
JobBase
......@@ -469,6 +497,7 @@ install(FILES
${MessageComposer_Camelcasefollowupreminder_HEADERS}
${MessageComposer_Camelcaserecipient_HEADERS}
${MessageComposer_Camelcaseimagescaling_HEADERS}
${MessageComposer_Camelcasesendlater_HEADERS}
${MessageComposer_Camelcasejob_HEADERS}
${MessageComposer_Camelcaseattachement_HEADERS}
${MessageComposer_Camelplugineditor_HEADERS}
......@@ -497,6 +526,7 @@ install(FILES
${MessageComposer_followupreminder_HEADERS}
${MessageComposer_recipient_HEADERS}
${MessageComposer_imagescaling_HEADERS}
${MessageComposer_sendlater_HEADERS}
${MessageComposer_attachement_HEADERS}
${MessageComposer_job_HEADERS}
${MessageComposer_plugineditor_HEADERS}
......
......@@ -37,8 +37,8 @@
#include "utils/util_p.h"
#include "imagescaling/imagescalingutils.h"
#include <SendLater/SendLaterInfo>
#include <SendLater/SendLaterUtil>
#include "sendlater/sendlaterinfo.h"
#include "sendlater/sendlatercreatejob.h"
#include <Libkdepim/RecentAddresses>
#include "helper/messagehelper.h"
......@@ -107,10 +107,7 @@ ComposerViewBase::ComposerViewBase(QObject *parent, QWidget *parentGui)
initAutoSave();
}
ComposerViewBase::~ComposerViewBase()
{
delete mSendLaterInfo;
}
ComposerViewBase::~ComposerViewBase() = default;
bool ComposerViewBase::isComposing() const
{
......@@ -1361,11 +1358,7 @@ void ComposerViewBase::slotCreateItemResult(KJob *job)
Akonadi::ItemCreateJob *createJob = static_cast<Akonadi::ItemCreateJob *>(job);
const Akonadi::Item item = createJob->item();
if (item.isValid()) {
id = item.id();
mSendLaterInfo->setItemId(id);
SendLater::SendLaterUtil::writeSendLaterInfo(SendLater::SendLaterUtil::defaultConfig(), mSendLaterInfo);
delete mSendLaterInfo;
mSendLaterInfo = nullptr;
addSendLaterItem(item);
}
}
......@@ -2088,15 +2081,14 @@ bool ComposerViewBase::determineWhetherToEncrypt(bool doEncryptCompletely, Kleo:
return encrypt || doEncryptCompletely;
}
void ComposerViewBase::setSendLaterInfo(SendLater::SendLaterInfo *info)
void ComposerViewBase::setSendLaterInfo(SendLaterInfo *info)
{
delete mSendLaterInfo;
mSendLaterInfo = info;
mSendLaterInfo.reset(info);
}
SendLater::SendLaterInfo *ComposerViewBase::sendLaterInfo() const
SendLaterInfo *ComposerViewBase::sendLaterInfo() const
{
return mSendLaterInfo;
return mSendLaterInfo.get();
}
void ComposerViewBase::addFollowupReminder(const QString &messageId)
......@@ -2114,6 +2106,14 @@ void ComposerViewBase::addFollowupReminder(const QString &messageId)
}
}
void ComposerViewBase::addSendLaterItem(const Akonadi::Item &item)
{
mSendLaterInfo->setItemId(item.id());
auto job = new MessageComposer::SendLaterCreateJob(*mSendLaterInfo, this);
job->start();
}
bool ComposerViewBase::requestDeleveryConfirmation() const
{
return m_requestDeleveryConfirmation;
......
......@@ -41,10 +41,6 @@ namespace Sonnet {
class DictionaryComboBox;
}
namespace SendLater {
class SendLaterInfo;
}
namespace Akonadi {
class CollectionComboBox;
}
......@@ -73,6 +69,7 @@ class Composer;
class AttachmentControllerBase;
class AttachmentModel;
class SignatureController;
class SendLaterInfo;
/**
* @brief The ComposerViewBase class
*/
......@@ -218,8 +215,8 @@ public:
Q_REQUIRED_RESULT bool hasMissingAttachments(const QStringList &attachmentKeywords);
void setSendLaterInfo(SendLater::SendLaterInfo *info);
Q_REQUIRED_RESULT SendLater::SendLaterInfo *sendLaterInfo() const;
void setSendLaterInfo(SendLaterInfo *info);
Q_REQUIRED_RESULT SendLaterInfo *sendLaterInfo() const;
void saveMailSettings();
Q_REQUIRED_RESULT QDate followUpDate() const;
......@@ -326,6 +323,7 @@ private:
*/
void initAutoSave();
void addFollowupReminder(const QString &messageId);
void addSendLaterItem(const Akonadi::Item &item);
KMime::Message::Ptr m_msg;
MessageComposer::AttachmentControllerBase *m_attachmentController = nullptr;
......@@ -373,7 +371,7 @@ private:
QDate mFollowUpDate;
Akonadi::Collection mFollowUpCollection;
SendLater::SendLaterInfo *mSendLaterInfo = nullptr;
std::unique_ptr<SendLaterInfo> mSendLaterInfo;
};
} // namespace
......
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="org.freedesktop.Akonadi.SendLaterAgent">
<method name="setEnableAgent" >
<arg type="b" direction="in"/>
</method>
<method name="enabledAgent" >
<arg type="b" direction="out"/>
</method>
<method name="printDebugInfo" >
<arg type="s" direction="out"/>
</method>
<method name="reload" />
<method name="removeItem" >
<arg name="item" type="x" direction="in"/>
</method>
<method name="addItem">
<arg name="datetime" type="x" direction="in" />
<arg name="recurrence" type="b" direction="in" />
<arg name="recurrenceValue" type="i" direction="in" />
<arg name="recurrenceUnit" type="i" direction="in" />
<arg name="itemId" type="x" direction="in" />
<arg name="subject" type="s" direction="in" />
<arg name="to" type="s" direction="in" />
</method>
</interface>
</node>
/*
Copyright (C) 2020 Daniel Vrátil <dvratil@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 "sendlatercreatejob.h"
#include "sendlaterinterface.h"
#include <KLocalizedString>
using namespace MessageComposer;
SendLaterCreateJob::SendLaterCreateJob(const SendLaterInfo &info, QObject *parent)
: SendLaterJob(parent)
, mInfo(info)
{}
QDBusPendingReply<> SendLaterCreateJob::doCall(OrgFreedesktopAkonadiSendLaterAgentInterface *iface)
{
return iface->addItem(mInfo.dateTime().toSecsSinceEpoch(), mInfo.isRecurrence(), mInfo.recurrenceEachValue(), mInfo.recurrenceUnit(),
mInfo.itemId(), mInfo.subject(), mInfo.to());
}
QString SendLaterCreateJob::getErrorString(Error, const QString &detail) const
{
return i18n("Failed to schedule message for sending later: %1", detail);
}
/*
Copyright (C) 2020 Daniel Vrátil <dvratil@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 MESSAGECOMPOSER_SENDLATERCREATEJOB_H
#define MESSAGECOMPOSER_SENDLATERCREATEJOB_H
#include "sendlaterjob.h"
#include "sendlaterinfo.h"
#include "messagecomposer_export.h"
namespace MessageComposer {
class MESSAGECOMPOSER_EXPORT SendLaterCreateJob : public SendLaterJob
{
Q_OBJECT
public:
explicit SendLaterCreateJob(const SendLaterInfo &info, QObject *parent = nullptr);
protected:
QDBusPendingReply<> doCall(OrgFreedesktopAkonadiSendLaterAgentInterface *iface) override;
QString getErrorString(SendLaterJob::Error code, const QString &detail) const override;
private:
SendLaterInfo mInfo;
};
}
#endif
/*
Copyright (C) 2013-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 "sendlaterdialog.h"
#include "sendlaterinfo.h"
#include "sendlatertimedatewidget_p.h"
#include "ui_sendlaterwidget.h"
#include <KLocalizedString>
#include <KSeparator>
#include <QIcon>
#include <QVBoxLayout>
#include <QCheckBox>
#include <QDialogButtonBox>
#include <QPushButton>
using namespace MessageComposer;