Messagelib

sendlaterjob.cpp
1 /*
2  SPDX-FileCopyrightText: 2020 Daniel Vr├ítil <[email protected]>
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 
18 using namespace MessageComposer;
19 
20 SendLaterJob::SendLaterJob(QObject *parent)
21  : KJob(parent)
22 {
23 }
24 
25 void 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 }
void finished(QDBusPendingCallWatcher *self)
QString message() const const
QDBusConnection sessionBus()
void deleteLater()
QDBusError error() const const
QString i18n(const char *text, const TYPE &arg...)
Simple interface that both EncryptJob and SignEncryptJob implement so the composer can extract some e...
bool isError() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Dec 6 2021 23:04:58 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.