MailTransport

dispatcherinterface.cpp
1 /*
2  SPDX-FileCopyrightText: 2009 Constantin Berzan <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "dispatcherinterface.h"
8 #include "dispatcherinterface_p.h"
9 
10 #include "kmailtransportakonadi/outboxactions_p.h"
11 
12 #include "mailtransportakonadi_debug.h"
13 
14 #include "kmailtransportakonadi/transportattribute.h"
15 #include <Akonadi/AgentManager>
16 #include <Akonadi/Collection>
17 #include <Akonadi/SpecialMailCollections>
18 
19 using namespace Akonadi;
20 using namespace MailTransport;
21 
22 Q_GLOBAL_STATIC(DispatcherInterfacePrivate, sInstance)
23 
24 void DispatcherInterfacePrivate::massModifyResult(KJob *job)
25 {
26  // Nothing to do here, really. If the job fails, the user can retry it.
27  if (job->error()) {
28  qCDebug(MAILTRANSPORTAKONADI_LOG) << "failed" << job->errorString();
29  } else {
30  qCDebug(MAILTRANSPORTAKONADI_LOG) << "succeeded.";
31  }
32 }
33 
34 DispatcherInterface::DispatcherInterface() = default;
35 
36 AgentInstance DispatcherInterface::dispatcherInstance() const
37 {
38  AgentInstance a = AgentManager::self()->instance(QStringLiteral("akonadi_maildispatcher_agent"));
39  if (!a.isValid()) {
40  qCWarning(MAILTRANSPORTAKONADI_LOG) << "Could not get MDA instance.";
41  }
42  return a;
43 }
44 
45 void DispatcherInterface::dispatchManually()
46 {
48  if (!outbox.isValid()) {
49  // qCritical() << "Could not access Outbox.";
50  return;
51  }
52 
53  auto mjob = new FilterActionJob(outbox, new SendQueuedAction, sInstance);
54  QObject::connect(mjob, &KJob::result, sInstance(), &DispatcherInterfacePrivate::massModifyResult);
55 }
56 
57 void DispatcherInterface::retryDispatching()
58 {
60  if (!outbox.isValid()) {
61  // qCritical() << "Could not access Outbox.";
62  return;
63  }
64 
65  auto mjob = new FilterActionJob(outbox, new ClearErrorAction, sInstance);
66  QObject::connect(mjob, &KJob::result, sInstance(), &DispatcherInterfacePrivate::massModifyResult);
67 }
68 
69 void DispatcherInterface::dispatchManualTransport(int transportId)
70 {
72  if (!outbox.isValid()) {
73  // qCritical() << "Could not access Outbox.";
74  return;
75  }
76 
77  auto mjob = new FilterActionJob(outbox, new DispatchManualTransportAction(transportId), sInstance);
78  QObject::connect(mjob, &KJob::result, sInstance(), &DispatcherInterfacePrivate::massModifyResult);
79 }
80 
81 #include "moc_dispatcherinterface_p.cpp"
Akonadi::Collection defaultCollection(Type type) const
void result(KJob *job)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
Q_GLOBAL_STATIC(Internal::StaticControl, s_instance) class ControlPrivate
AgentInstance instance(const QString &identifier) const
static SpecialMailCollections * self()
static AgentManager * self()
bool isValid() const
virtual QString errorString() const
int error() const
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Thu Mar 23 2023 04:19:12 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.