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 <agentmanager.h>
16 #include <collection.h>
17 #include <specialmailcollections.h>
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()
35 {
36 }
37 
38 AgentInstance DispatcherInterface::dispatcherInstance() const
39 {
40  AgentInstance a = AgentManager::self()->instance(QStringLiteral("akonadi_maildispatcher_agent"));
41  if (!a.isValid()) {
42  qCWarning(MAILTRANSPORTAKONADI_LOG) << "Could not get MDA instance.";
43  }
44  return a;
45 }
46 
47 void DispatcherInterface::dispatchManually()
48 {
50  if (!outbox.isValid()) {
51  // qCritical() << "Could not access Outbox.";
52  return;
53  }
54 
55  auto mjob = new FilterActionJob(outbox, new SendQueuedAction, sInstance);
56  QObject::connect(mjob, &KJob::result, sInstance(), &DispatcherInterfacePrivate::massModifyResult);
57 }
58 
59 void DispatcherInterface::retryDispatching()
60 {
62  if (!outbox.isValid()) {
63  // qCritical() << "Could not access Outbox.";
64  return;
65  }
66 
67  auto mjob = new FilterActionJob(outbox, new ClearErrorAction, sInstance);
68  QObject::connect(mjob, &KJob::result, sInstance(), &DispatcherInterfacePrivate::massModifyResult);
69 }
70 
71 void DispatcherInterface::dispatchManualTransport(int transportId)
72 {
74  if (!outbox.isValid()) {
75  // qCritical() << "Could not access Outbox.";
76  return;
77  }
78 
79  auto mjob = new FilterActionJob(outbox, new DispatchManualTransportAction(transportId), sInstance);
80  QObject::connect(mjob, &KJob::result, sInstance(), &DispatcherInterfacePrivate::massModifyResult);
81 }
82 
83 #include "moc_dispatcherinterface_p.cpp"
bool isValid() const
AgentInstance instance(const QString &identifier) const
bool isValid() const
static SpecialMailCollections * self()
static AgentManager * self()
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)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Aug 3 2021 23:19:54 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.