diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.5) -set(PIM_VERSION "5.14.43") +set(PIM_VERSION "5.14.44") if (POLICY CMP0053) cmake_policy(SET CMP0053 NEW) diff --git a/messagecomposer/autotests/CMakeLists.txt b/messagecomposer/autotests/CMakeLists.txt --- a/messagecomposer/autotests/CMakeLists.txt +++ b/messagecomposer/autotests/CMakeLists.txt @@ -81,6 +81,10 @@ 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 ) diff --git a/messagecomposer/autotests/sendlaterdialogtest.h b/messagecomposer/autotests/sendlaterdialogtest.h new file mode 100644 --- /dev/null +++ b/messagecomposer/autotests/sendlaterdialogtest.h @@ -0,0 +1,36 @@ +/* + Copyright (C) 2015-2020 Laurent Montel + + 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 + +class SendLaterDialogTest : public QObject +{ + Q_OBJECT +public: + explicit SendLaterDialogTest(QObject *parent = nullptr); + ~SendLaterDialogTest(); +private Q_SLOTS: + void shouldHaveDefaultValue(); + void initTestCase(); +}; + +#endif // SENDLATERDIALOGTEST_H diff --git a/messagecomposer/autotests/sendlaterdialogtest.cpp b/messagecomposer/autotests/sendlaterdialogtest.cpp new file mode 100644 --- /dev/null +++ b/messagecomposer/autotests/sendlaterdialogtest.cpp @@ -0,0 +1,60 @@ +/* + Copyright (C) 2015-2020 Laurent Montel + + 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 +#include +#include +#include +#include +#include + +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(QStringLiteral("time_sendlater")); + QVERIFY(timeCombo); + KDateComboBox *dateCombo = dlg.findChild(QStringLiteral("date_sendlater")); + QVERIFY(dateCombo); + QVERIFY(dateCombo->date().isValid()); + QPushButton *okButton = dlg.findChild(QStringLiteral("okbutton")); + QVERIFY(okButton); + QVERIFY(okButton->isEnabled()); + dateCombo->lineEdit()->clear(); + QVERIFY(!dateCombo->date().isValid()); + QVERIFY(!okButton->isEnabled()); +} + +QTEST_MAIN(SendLaterDialogTest) diff --git a/messagecomposer/autotests/sendlaterinfotest.h b/messagecomposer/autotests/sendlaterinfotest.h new file mode 100644 --- /dev/null +++ b/messagecomposer/autotests/sendlaterinfotest.h @@ -0,0 +1,38 @@ +/* + Copyright (C) 2014-2020 Laurent Montel + + 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 + +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 diff --git a/messagecomposer/autotests/sendlaterinfotest.cpp b/messagecomposer/autotests/sendlaterinfotest.cpp new file mode 100644 --- /dev/null +++ b/messagecomposer/autotests/sendlaterinfotest.cpp @@ -0,0 +1,108 @@ +/* + Copyright (C) 2014-2020 Laurent Montel + + 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 +#include +#include + +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) diff --git a/messagecomposer/src/CMakeLists.txt b/messagecomposer/src/CMakeLists.txt --- a/messagecomposer/src/CMakeLists.txt +++ b/messagecomposer/src/CMakeLists.txt @@ -149,6 +149,20 @@ 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 @@ ${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 @@ KF5::SonnetUi Grantlee5::TextDocument KF5::CalendarCore # for KCalendarCore/Todo - KF5::SendLater KF5::Archive KF5::Contacts KF5::SonnetCore @@ -424,6 +439,19 @@ 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 @@ ${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 @@ ${MessageComposer_followupreminder_HEADERS} ${MessageComposer_recipient_HEADERS} ${MessageComposer_imagescaling_HEADERS} + ${MessageComposer_sendlater_HEADERS} ${MessageComposer_attachement_HEADERS} ${MessageComposer_job_HEADERS} ${MessageComposer_plugineditor_HEADERS} diff --git a/messagecomposer/src/composer/composerviewbase.h b/messagecomposer/src/composer/composerviewbase.h --- a/messagecomposer/src/composer/composerviewbase.h +++ b/messagecomposer/src/composer/composerviewbase.h @@ -41,10 +41,6 @@ class DictionaryComboBox; } -namespace SendLater { -class SendLaterInfo; -} - namespace Akonadi { class CollectionComboBox; } @@ -73,6 +69,7 @@ class AttachmentControllerBase; class AttachmentModel; class SignatureController; +class SendLaterInfo; /** * @brief The ComposerViewBase class */ @@ -218,8 +215,8 @@ 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 @@ */ 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 @@ QDate mFollowUpDate; Akonadi::Collection mFollowUpCollection; - SendLater::SendLaterInfo *mSendLaterInfo = nullptr; + std::unique_ptr mSendLaterInfo; }; } // namespace diff --git a/messagecomposer/src/composer/composerviewbase.cpp b/messagecomposer/src/composer/composerviewbase.cpp --- a/messagecomposer/src/composer/composerviewbase.cpp +++ b/messagecomposer/src/composer/composerviewbase.cpp @@ -37,8 +37,8 @@ #include "utils/util_p.h" #include "imagescaling/imagescalingutils.h" -#include -#include +#include "sendlater/sendlaterinfo.h" +#include "sendlater/sendlatercreatejob.h" #include #include "helper/messagehelper.h" @@ -107,10 +107,7 @@ initAutoSave(); } -ComposerViewBase::~ComposerViewBase() -{ - delete mSendLaterInfo; -} +ComposerViewBase::~ComposerViewBase() = default; bool ComposerViewBase::isComposing() const { @@ -1361,11 +1358,7 @@ Akonadi::ItemCreateJob *createJob = static_cast(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 @@ 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::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; diff --git a/messagecomposer/src/sendlater/org.freedesktop.Akonadi.SendLaterAgent.xml b/messagecomposer/src/sendlater/org.freedesktop.Akonadi.SendLaterAgent.xml new file mode 100644 --- /dev/null +++ b/messagecomposer/src/sendlater/org.freedesktop.Akonadi.SendLaterAgent.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/messagecomposer/src/sendlater/sendlatercreatejob.h b/messagecomposer/src/sendlater/sendlatercreatejob.h new file mode 100644 --- /dev/null +++ b/messagecomposer/src/sendlater/sendlatercreatejob.h @@ -0,0 +1,45 @@ +/* + Copyright (C) 2020 Daniel Vrátil + + 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 diff --git a/messagecomposer/src/sendlater/sendlatercreatejob.cpp b/messagecomposer/src/sendlater/sendlatercreatejob.cpp new file mode 100644 --- /dev/null +++ b/messagecomposer/src/sendlater/sendlatercreatejob.cpp @@ -0,0 +1,41 @@ +/* + Copyright (C) 2020 Daniel Vrátil + + 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 + +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); +} diff --git a/messagecomposer/src/sendlater/sendlaterdialog.h b/messagecomposer/src/sendlater/sendlaterdialog.h new file mode 100644 --- /dev/null +++ b/messagecomposer/src/sendlater/sendlaterdialog.h @@ -0,0 +1,74 @@ +/* + Copyright (C) 2013-2020 Laurent Montel + + 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_SENDLATERDIALOG_H +#define MESSAGECOMPOSER_SENDLATERDIALOG_H + +#include +#include + +#include "messagecomposer_export.h" + +class QCheckBox; +class QPushButton; +namespace Ui { +class SendLaterWidget; +} + +namespace MessageComposer { + +class SendLaterInfo; + +/** Send later dialog. */ +class MESSAGECOMPOSER_EXPORT SendLaterDialog : public QDialog +{ + Q_OBJECT +public: + enum SendLaterAction { + Unknown = 0, + SendDeliveryAtTime = 1, + Canceled = 2, + PutInOutbox = 3 + }; + + explicit SendLaterDialog(SendLaterInfo *info, QWidget *parent = nullptr); + ~SendLaterDialog(); + + SendLaterInfo *info(); + + Q_REQUIRED_RESULT SendLaterAction action() const; + +private: + void slotRecurrenceClicked(bool); + void slotOkClicked(); + void slotDelay(bool delayEnabled); + + void slotDateChanged(const QString &date); + void load(SendLaterInfo *info); + +private: + QDateTime mSendDateTime; + SendLaterAction mAction = Unknown; + QCheckBox *mDelay = nullptr; + Ui::SendLaterWidget *mSendLaterWidget = nullptr; + SendLaterInfo *mInfo = nullptr; + QPushButton *mOkButton = nullptr; +}; +} +#endif // SENDLATERDIALOG_H diff --git a/messagecomposer/src/sendlater/sendlaterdialog.cpp b/messagecomposer/src/sendlater/sendlaterdialog.cpp new file mode 100644 --- /dev/null +++ b/messagecomposer/src/sendlater/sendlaterdialog.cpp @@ -0,0 +1,159 @@ +/* + Copyright (C) 2013-2020 Laurent Montel + + 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 +#include +#include + +#include +#include +#include +#include + +using namespace MessageComposer; + +SendLaterDialog::SendLaterDialog(SendLaterInfo *info, QWidget *parent) + : QDialog(parent) + , mInfo(info) +{ + setWindowTitle(i18nc("@title:window", "Send Later")); + setWindowIcon(QIcon::fromTheme(QStringLiteral("kmail"))); + + QVBoxLayout *mainLayout = new QVBoxLayout(this); + + QWidget *sendLaterWidget = new QWidget(this); + mSendLaterWidget = new Ui::SendLaterWidget; + mSendLaterWidget->setupUi(sendLaterWidget); + + QWidget *w = new QWidget(this); + QVBoxLayout *lay = new QVBoxLayout; + lay->setContentsMargins(0, 0, 0, 0); + w->setLayout(lay); + + QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); + mOkButton = buttonBox->button(QDialogButtonBox::Ok); + mOkButton->setObjectName(QStringLiteral("okbutton")); + mOkButton->setDefault(true); + mOkButton->setShortcut(Qt::CTRL | Qt::Key_Return); + connect(buttonBox, &QDialogButtonBox::rejected, this, &SendLaterDialog::reject); + + if (!info) { + mOkButton->setText(i18n("Send Later")); + mDelay = new QCheckBox(i18n("Delay")); + mDelay->setChecked(false); + slotDelay(false); + connect(mDelay, &QCheckBox::clicked, this, &SendLaterDialog::slotDelay); + lay->addWidget(mDelay); + } + + connect(mOkButton, &QPushButton::clicked, this, &SendLaterDialog::slotOkClicked); + + lay->addWidget(sendLaterWidget); + + QDateTime t = QDateTime::currentDateTime(); + t = t.addSecs(60 * 60); + + mSendLaterWidget->mDateTime->setDateTime(t); + connect(mSendLaterWidget->mRecurrence, &QCheckBox::clicked, this, &SendLaterDialog::slotRecurrenceClicked); + const QStringList unitsList = {i18n("Days"), i18n("Weeks"), i18n("Months"), i18n("Years")}; + mSendLaterWidget->mRecurrenceComboBox->addItems(unitsList); + connect(mSendLaterWidget->mDateTime, &SendLaterTimeDateWidget::dateChanged, this, &SendLaterDialog::slotDateChanged); + + lay->addWidget(new KSeparator); + + mainLayout->addWidget(w); + mainLayout->addWidget(buttonBox); + slotRecurrenceClicked(false); + if (info) { + load(info); + } + resize(180, 120); +} + +SendLaterDialog::~SendLaterDialog() +{ + delete mSendLaterWidget; +} + +void SendLaterDialog::slotDateChanged(const QString &date) +{ + mOkButton->setEnabled(!date.isEmpty()); +} + +void SendLaterDialog::slotRecurrenceClicked(bool clicked) +{ + mSendLaterWidget->mRecurrenceValue->setEnabled(clicked); + mSendLaterWidget->mRecurrenceComboBox->setEnabled(clicked); +} + +void SendLaterDialog::load(SendLaterInfo *info) +{ + mSendLaterWidget->mDateTime->setDateTime(info->dateTime()); + const bool recurrence = info->isRecurrence(); + mSendLaterWidget->mRecurrence->setChecked(recurrence); + slotRecurrenceClicked(recurrence); + mSendLaterWidget->mRecurrenceValue->setValue(info->recurrenceEachValue()); + mSendLaterWidget->mRecurrenceComboBox->setCurrentIndex(static_cast(info->recurrenceUnit())); +} + +SendLaterInfo *SendLaterDialog::info() +{ + if (!mInfo) { + mInfo = new SendLaterInfo(); + } + mInfo->setRecurrence(mSendLaterWidget->mRecurrence->isChecked()); + mInfo->setRecurrenceEachValue(mSendLaterWidget->mRecurrenceValue->value()); + mInfo->setRecurrenceUnit(static_cast(mSendLaterWidget->mRecurrenceComboBox->currentIndex())); + if (mSendDateTime.isValid()) { + mInfo->setDateTime(mSendDateTime); + } else { + mInfo->setDateTime(mSendLaterWidget->mDateTime->dateTime()); + } + return mInfo; +} + +SendLaterDialog::SendLaterAction SendLaterDialog::action() const +{ + return mAction; +} + +void SendLaterDialog::slotOkClicked() +{ + if (!mDelay || mDelay->isChecked()) { + mSendDateTime = mSendLaterWidget->mDateTime->dateTime(); + mAction = SendDeliveryAtTime; + } else { + mAction = PutInOutbox; + } + accept(); +} + +void SendLaterDialog::slotDelay(bool delayEnabled) +{ + mSendLaterWidget->mLabel->setEnabled(delayEnabled); + mSendLaterWidget->mDateTime->setEnabled(delayEnabled); + mSendLaterWidget->mRecurrence->setEnabled(delayEnabled); + mSendLaterWidget->mRecurrenceValue->setEnabled(delayEnabled && mSendLaterWidget->mRecurrence->isChecked()); + mSendLaterWidget->mRecurrenceComboBox->setEnabled(delayEnabled && mSendLaterWidget->mRecurrence->isChecked()); +} diff --git a/messagecomposer/src/sendlater/sendlaterinfo.h b/messagecomposer/src/sendlater/sendlaterinfo.h new file mode 100644 --- /dev/null +++ b/messagecomposer/src/sendlater/sendlaterinfo.h @@ -0,0 +1,89 @@ +/* + Copyright (C) 2013-2020 Laurent Montel + + 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_SENDLATERINFO_H +#define MESSAGECOMPOSER_SENDLATERINFO_H + +#include +#include + +#include "messagecomposer_export.h" + +namespace MessageComposer { + +/** Send later information. */ +class MESSAGECOMPOSER_EXPORT SendLaterInfo +{ +public: + explicit SendLaterInfo() = default; + + enum RecurrenceUnit { + Days = 0, + Weeks, + Months, + Years + }; + + Q_REQUIRED_RESULT bool isValid() const; + + void setItemId(Akonadi::Item::Id id); + Q_REQUIRED_RESULT Akonadi::Item::Id itemId() const; + + void setRecurrenceUnit(RecurrenceUnit unit); + Q_REQUIRED_RESULT RecurrenceUnit recurrenceUnit() const; + + void setRecurrenceEachValue(int value); + Q_REQUIRED_RESULT int recurrenceEachValue() const; + + Q_REQUIRED_RESULT bool isRecurrence() const; + void setRecurrence(bool b); + + void setDateTime(const QDateTime &time); + Q_REQUIRED_RESULT QDateTime dateTime() const; + + void setLastDateTimeSend(const QDateTime &date); + Q_REQUIRED_RESULT QDateTime lastDateTimeSend() const; + + void setSubject(const QString &subject); + Q_REQUIRED_RESULT QString subject() const; + + void setTo(const QString &to); + Q_REQUIRED_RESULT QString to() const; + + bool operator ==(const SendLaterInfo &other) const; + inline bool operator !=(const SendLaterInfo &other) const + { + return !(*this == other); + } + +private: + QString mTo; + QString mSubject; + QDateTime mDateTime; + QDateTime mLastDateTimeSend; + Akonadi::Item::Id mId = -1; + int mRecurrenceEachValue = 1; + RecurrenceUnit mRecurrenceUnit = Days; + bool mRecurrence = false; +}; +} + +MESSAGECOMPOSER_EXPORT QDebug operator<<(QDebug debug, const MessageComposer::SendLaterInfo &info); + +#endif // SENDLATERINFO_H diff --git a/messagecomposer/src/sendlater/sendlaterinfo.cpp b/messagecomposer/src/sendlater/sendlaterinfo.cpp new file mode 100644 --- /dev/null +++ b/messagecomposer/src/sendlater/sendlaterinfo.cpp @@ -0,0 +1,132 @@ +/* + Copyright (C) 2013-2020 Laurent Montel + + 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 "sendlaterinfo.h" + +using namespace MessageComposer; + +bool SendLaterInfo::isValid() const +{ + return (mId != -1) && mDateTime.isValid(); +} + +bool SendLaterInfo::isRecurrence() const +{ + return mRecurrence; +} + +void SendLaterInfo::setRecurrence(bool b) +{ + mRecurrence = b; +} + +void SendLaterInfo::setRecurrenceUnit(SendLaterInfo::RecurrenceUnit unit) +{ + mRecurrenceUnit = unit; +} + +SendLaterInfo::RecurrenceUnit SendLaterInfo::recurrenceUnit() const +{ + return mRecurrenceUnit; +} + +void SendLaterInfo::setRecurrenceEachValue(int value) +{ + mRecurrenceEachValue = value; +} + +int SendLaterInfo::recurrenceEachValue() const +{ + return mRecurrenceEachValue; +} + +void SendLaterInfo::setItemId(Akonadi::Item::Id id) +{ + mId = id; +} + +Akonadi::Item::Id SendLaterInfo::itemId() const +{ + return mId; +} + +void SendLaterInfo::setDateTime(const QDateTime &time) +{ + mDateTime = time; +} + +QDateTime SendLaterInfo::dateTime() const +{ + return mDateTime; +} + +void SendLaterInfo::setLastDateTimeSend(const QDateTime &dateTime) +{ + mLastDateTimeSend = dateTime; +} + +QDateTime SendLaterInfo::lastDateTimeSend() const +{ + return mLastDateTimeSend; +} + +void SendLaterInfo::setSubject(const QString &subject) +{ + mSubject = subject; +} + +QString SendLaterInfo::subject() const +{ + return mSubject; +} + +void SendLaterInfo::setTo(const QString &to) +{ + mTo = to; +} + +QString SendLaterInfo::to() const +{ + return mTo; +} + +bool SendLaterInfo::operator ==(const SendLaterInfo &other) const +{ + return (itemId() == other.itemId()) + && (recurrenceUnit() == other.recurrenceUnit()) + && (recurrenceEachValue() == other.recurrenceEachValue()) + && (isRecurrence() == other.isRecurrence()) + && (dateTime() == other.dateTime()) + && (lastDateTimeSend() == other.lastDateTimeSend()) + && (subject() == other.subject()) + && (to() == other.to()); +} + +QDebug operator<<(QDebug d, const SendLaterInfo &info) +{ + d << "mTo: " << info.to(); + d << "mSubject: " << info.subject(); + d << "mDateTime: " << info.dateTime().toString(); + d << "mLastDateTimeSend: " << info.lastDateTimeSend().toString(); + d << "mId: " << info.itemId(); + d << "mRecurrenceEachValue: " << info.recurrenceEachValue(); + d << "mRecurrenceUnit: " << info.recurrenceUnit(); + d << "mRecurrence: " << info.isRecurrence(); + return d; +} diff --git a/messagecomposer/src/sendlater/sendlaterjob.h b/messagecomposer/src/sendlater/sendlaterjob.h new file mode 100644 --- /dev/null +++ b/messagecomposer/src/sendlater/sendlaterjob.h @@ -0,0 +1,52 @@ +/* + Copyright (C) 2020 Daniel Vrátil + + 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_SENDLATERJOB_H +#define MESSAGECOMPOSER_SENDLATERJOB_H + +#include +#include + +#include "messagecomposer_export.h" + +class OrgFreedesktopAkonadiSendLaterAgentInterface; + +namespace MessageComposer { + +class MESSAGECOMPOSER_EXPORT SendLaterJob: public KJob +{ + Q_OBJECT +public: + enum Error { + AgentNotAvailable = KJob::UserDefinedError, + CallFailed + }; + + explicit SendLaterJob(QObject *parent = nullptr); + + void start() final; + +protected: + virtual QDBusPendingReply<> doCall(OrgFreedesktopAkonadiSendLaterAgentInterface *iface) = 0; + virtual QString getErrorString(Error error, const QString &desc) const = 0; + +}; +} + +#endif diff --git a/messagecomposer/src/sendlater/sendlaterjob.cpp b/messagecomposer/src/sendlater/sendlaterjob.cpp new file mode 100644 --- /dev/null +++ b/messagecomposer/src/sendlater/sendlaterjob.cpp @@ -0,0 +1,69 @@ +/* + Copyright (C) 2020 Daniel Vrátil + + 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 "sendlaterjob.h" +#include "sendlaterinterface.h" +#include "sendlaterutil_p.h" +#include "messagecomposer_debug.h" + +#include + +#include +#include + +#include + +using namespace MessageComposer; + +SendLaterJob::SendLaterJob(QObject *parent) + : KJob(parent) +{} + +void SendLaterJob::start() +{ + std::unique_ptr iface{ + new org::freedesktop::Akonadi::SendLaterAgent{ + SendLaterUtil::agentServiceName(), SendLaterUtil::dbusPath(), + QDBusConnection::sessionBus() + }}; + if (!iface->isValid()) { + qCWarning(MESSAGECOMPOSER_LOG) << "The SendLater agent is not running!"; + setError(SendLaterJob::AgentNotAvailable); + setErrorText(getErrorString(SendLaterJob::AgentNotAvailable, i18n("The Send Later agent is not running."))); + emitResult(); + return; + } + + auto reply = doCall(iface.get()); + + auto watcher = new QDBusPendingCallWatcher(reply); + connect(watcher, &QDBusPendingCallWatcher::finished, + this, [this, iface_ = std::move(iface)](QDBusPendingCallWatcher *call) mutable { + auto iface = std::move(iface_); + call->deleteLater(); + QDBusPendingReply reply = *call; + if (reply.isError()) { + qCWarning(MESSAGECOMPOSER_LOG) << "SendLater agent DBus call failed:" << reply.error().message(); + setError(SendLaterJob::CallFailed); + setErrorText(getErrorString(SendLaterJob::CallFailed, reply.error().message())); + } + + emitResult(); + }); +} diff --git a/messagecomposer/src/sendlater/sendlaterremovejob.h b/messagecomposer/src/sendlater/sendlaterremovejob.h new file mode 100644 --- /dev/null +++ b/messagecomposer/src/sendlater/sendlaterremovejob.h @@ -0,0 +1,46 @@ +/* + Copyright (C) 2020 Daniel Vrátil + + 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_SENDLATERREMOVEJOB_H +#define MESSAGECOMPOSER_SENDLATERREMOVEJOB_H + +#include "sendlaterjob.h" +#include "messagecomposer_export.h" + +#include + +namespace MessageComposer { + +class MESSAGECOMPOSER_EXPORT SendLaterRemoveJob : public SendLaterJob +{ + Q_OBJECT +public: + explicit SendLaterRemoveJob(Akonadi::Item::Id item, QObject *parent = nullptr); + +protected: + QDBusPendingReply<> doCall(OrgFreedesktopAkonadiSendLaterAgentInterface *iface) override; + QString getErrorString(Error error, const QString &detail) const override; + +private: + Akonadi::Item::Id mItem; +}; + +} + +#endif diff --git a/messagecomposer/src/sendlater/sendlaterremovejob.cpp b/messagecomposer/src/sendlater/sendlaterremovejob.cpp new file mode 100644 --- /dev/null +++ b/messagecomposer/src/sendlater/sendlaterremovejob.cpp @@ -0,0 +1,40 @@ +/* + Copyright (C) 2020 Daniel Vrátil + + 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 "sendlaterremovejob.h" +#include "sendlaterinterface.h" + +#include + +using namespace MessageComposer; + +SendLaterRemoveJob::SendLaterRemoveJob(Akonadi::Item::Id item, QObject *parent) + : SendLaterJob(parent) + , mItem(item) +{} + +QDBusPendingReply<> SendLaterRemoveJob::doCall(OrgFreedesktopAkonadiSendLaterAgentInterface *iface) +{ + return iface->removeItem(mItem); +} + +QString SendLaterRemoveJob::getErrorString(Error, const QString &detail) const +{ + return i18n("Failed to removed message from send later schedule: %1", detail); +} diff --git a/messagecomposer/src/sendlater/sendlatertimedatewidget.cpp b/messagecomposer/src/sendlater/sendlatertimedatewidget.cpp new file mode 100644 --- /dev/null +++ b/messagecomposer/src/sendlater/sendlatertimedatewidget.cpp @@ -0,0 +1,78 @@ +/* + Copyright (C) 2013-2020 Laurent Montel + + 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 "sendlatertimedatewidget_p.h" + +#include +#include +#include +#include + +#include + +using namespace MessageComposer; + +SendLaterTimeDateWidget::SendLaterTimeDateWidget(QWidget *parent) + : QWidget(parent) +{ + QHBoxLayout *lay = new QHBoxLayout; + lay->setContentsMargins(0, 0, 0, 0); + + QDateTime t = QDateTime::currentDateTime(); + t = t.addSecs(60 * 60); + mTimeComboBox.reset(new KTimeComboBox); + connect(mTimeComboBox.get(), &KTimeComboBox::timeChanged, this, &SendLaterTimeDateWidget::slotDateTimeChanged); + mTimeComboBox->setObjectName(QStringLiteral("time_sendlater")); + + mDateComboBox.reset(new KDateComboBox); + mDateComboBox->setOptions(KDateComboBox::EditDate | KDateComboBox::SelectDate | KDateComboBox::DatePicker | KDateComboBox::DateKeywords | KDateComboBox::WarnOnInvalid); + mDateComboBox->setObjectName(QStringLiteral("date_sendlater")); + connect(mDateComboBox->lineEdit(), &QLineEdit::textChanged, this, &SendLaterTimeDateWidget::dateChanged); + mDateComboBox->setMinimumDate(t.date(), i18n("You cannot select a date prior to the current date.")); + connect(mDateComboBox.get(), &KDateComboBox::dateChanged, this, &SendLaterTimeDateWidget::slotDateTimeChanged); + + lay->addWidget(mDateComboBox.get()); + lay->addWidget(mTimeComboBox.get()); + + setLayout(lay); +} + +SendLaterTimeDateWidget::~SendLaterTimeDateWidget() = default; + +void SendLaterTimeDateWidget::slotDateTimeChanged() +{ + QDateTime dt; + dt.setDate(mDateComboBox->date()); + dt.setTime(mTimeComboBox->time()); + Q_EMIT dateTimeChanged(dt); +} + +QDateTime SendLaterTimeDateWidget::dateTime() const +{ + QDateTime dt; + dt.setDate(mDateComboBox->date()); + dt.setTime(mTimeComboBox->time()); + return dt; +} + +void SendLaterTimeDateWidget::setDateTime(const QDateTime &datetime) +{ + mTimeComboBox->setTime(datetime.time()); + mDateComboBox->setDate(datetime.date()); +} diff --git a/messagecomposer/src/sendlater/sendlatertimedatewidget_p.h b/messagecomposer/src/sendlater/sendlatertimedatewidget_p.h new file mode 100644 --- /dev/null +++ b/messagecomposer/src/sendlater/sendlatertimedatewidget_p.h @@ -0,0 +1,53 @@ +/* + Copyright (C) 2013-2020 Laurent Montel + + 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_SENDLATERTIMEDATEWIDGET_H +#define MESSAGECOMPOSER_SENDLATERTIMEDATEWIDGET_H + +#include +#include + +class KTimeComboBox; +class KDateComboBox; + +namespace MessageComposer { + +/** Send later date/time widget. */ +class SendLaterTimeDateWidget : public QWidget +{ + Q_OBJECT +public: + explicit SendLaterTimeDateWidget(QWidget *parent = nullptr); + ~SendLaterTimeDateWidget() override; + + void setDateTime(const QDateTime &); + Q_REQUIRED_RESULT QDateTime dateTime() const; + +Q_SIGNALS: + void dateTimeChanged(const QDateTime &); + void dateChanged(const QString &); + +private: + void slotDateTimeChanged(); + std::unique_ptr mTimeComboBox; + std::unique_ptr mDateComboBox; +}; +} + +#endif // MESSAGECOMPOSER_SENDLATERTIMEDATEWIDGET_H diff --git a/messagecomposer/src/sendlater/sendlaterutil.h b/messagecomposer/src/sendlater/sendlaterutil.h new file mode 100644 --- /dev/null +++ b/messagecomposer/src/sendlater/sendlaterutil.h @@ -0,0 +1,39 @@ +/* + Copyright (C) 2013-2020 Laurent Montel + + 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_SENDLATERUTIL_H +#define MESSAGECOMPOSER_SENDLATERUTIL_H + +#include "messagecomposer_export.h" + +#include + +namespace MessageComposer +{ + +/** Send later utilities. */ +namespace SendLaterUtil { + +Q_REQUIRED_RESULT MESSAGECOMPOSER_EXPORT bool sentLaterAgentWasRegistered(); + +Q_REQUIRED_RESULT MESSAGECOMPOSER_EXPORT bool sentLaterAgentEnabled(); + +} +} +#endif // SENDLATERUTIL_H diff --git a/messagecomposer/src/sendlater/sendlaterutil.cpp b/messagecomposer/src/sendlater/sendlaterutil.cpp new file mode 100644 --- /dev/null +++ b/messagecomposer/src/sendlater/sendlaterutil.cpp @@ -0,0 +1,52 @@ +/* + Copyright (C) 2013-2020 Laurent Montel + + 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 "sendlaterutil.h" +#include "sendlaterutil_p.h" +#include "sendlaterinterface.h" + +#include + +#include +#include + +using namespace MessageComposer; + +QString SendLaterUtil::agentServiceName() +{ + using Akonadi::ServerManager; + return ServerManager::agentServiceName(ServerManager::Agent, QStringLiteral("akonadi_sendlater_agent")); +} + +QString SendLaterUtil::dbusPath() +{ + return QStringLiteral("/SendLaterAgent"); +} + +bool SendLaterUtil::sentLaterAgentWasRegistered() +{ + return org::freedesktop::Akonadi::SendLaterAgent{agentServiceName(), dbusPath(), QDBusConnection::sessionBus()}.isValid(); +} + +bool SendLaterUtil::sentLaterAgentEnabled() +{ + org::freedesktop::Akonadi::SendLaterAgent iface{agentServiceName(), dbusPath(), QDBusConnection::sessionBus()}; + return iface.isValid() && iface.enabledAgent(); +} + diff --git a/messagecomposer/src/sendlater/sendlaterutil_p.h b/messagecomposer/src/sendlater/sendlaterutil_p.h new file mode 100644 --- /dev/null +++ b/messagecomposer/src/sendlater/sendlaterutil_p.h @@ -0,0 +1,37 @@ +/* + Copyright (C) 2013-2020 Laurent Montel + + 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_SENDLATERUTIL_P_H +#define MESSAGECOMPOSER_SENDLATERUTIL_P_H + +#include +#include + +namespace MessageComposer +{ +namespace SendLaterUtil +{ + +QString agentServiceName(); +QString dbusPath(); + +} +} + +#endif diff --git a/messagecomposer/src/sendlater/ui/sendlaterwidget.ui b/messagecomposer/src/sendlater/ui/sendlaterwidget.ui new file mode 100644 --- /dev/null +++ b/messagecomposer/src/sendlater/ui/sendlaterwidget.ui @@ -0,0 +1,67 @@ + + + SendLaterWidget + + + + 0 + 0 + 452 + 85 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Send at: + + + + + + + + + + Repeat every: + + + + + + + 1 + + + 365 + + + + + + + + + + + MessageComposer::SendLaterTimeDateWidget + QWidget +
sendlater/sendlatertimedatewidget_p.h
+
+
+ + +