Messagelib

sendlaterjob.cpp
1/*
2 SPDX-FileCopyrightText: 2020 Daniel Vrátil <dvratil@kde.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "sendlaterjob.h"
8#include "messagecomposer_debug.h"
9#include "sendlaterinterface.h"
10#include "sendlaterutil_p.h"
11
12#include <KLocalizedString>
13
14#include <QDBusPendingCallWatcher>
15
16#include <memory>
17
18using namespace MessageComposer;
19
20SendLaterJob::SendLaterJob(QObject *parent)
21 : KJob(parent)
22{
23}
24
25void SendLaterJob::start()
26{
27 std::unique_ptr<org::freedesktop::Akonadi::SendLaterAgent> iface{
28 new org::freedesktop::Akonadi::SendLaterAgent{SendLaterUtil::agentServiceName(), SendLaterUtil::dbusPath(), QDBusConnection::sessionBus()}};
29 if (!iface->isValid()) {
30 qCWarning(MESSAGECOMPOSER_LOG) << "The SendLater agent is not running!";
31 setError(SendLaterJob::AgentNotAvailable);
32 setErrorText(getErrorString(SendLaterJob::AgentNotAvailable, i18n("The Send Later agent is not running.")));
33 emitResult();
34 return;
35 }
36
37 auto reply = doCall(iface.get());
38
39 auto watcher = new QDBusPendingCallWatcher(reply);
40 connect(watcher, &QDBusPendingCallWatcher::finished, this, [this, iface_ = std::move(iface)](QDBusPendingCallWatcher *call) mutable {
41 auto iface = std::move(iface_);
42 call->deleteLater();
43 QDBusPendingReply<void> reply = *call;
44 if (reply.isError()) {
45 qCWarning(MESSAGECOMPOSER_LOG) << "SendLater agent DBus call failed:" << reply.error().message();
46 setError(SendLaterJob::CallFailed);
47 setErrorText(getErrorString(SendLaterJob::CallFailed, reply.error().message()));
48 }
49
50 emitResult();
51 });
52}
53
54#include "moc_sendlaterjob.cpp"
void setErrorText(const QString &errorText)
void emitResult()
void setError(int errorCode)
QString i18n(const char *text, const TYPE &arg...)
Simple interface that both EncryptJob and SignEncryptJob implement so the composer can extract some e...
QDBusConnection sessionBus()
QString message() const const
void finished(QDBusPendingCallWatcher *self)
QDBusError error() const const
bool isError() const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void deleteLater()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:33:25 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.