File indexing completed on 2024-05-12 05:11:10

0001 /*
0002     SPDX-FileCopyrightText: 2009 Constantin Berzan <exit3219@gmail.com>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "dispatcherinterface.h"
0008 #include "dispatcherinterface_p.h"
0009 
0010 #include "outboxactions_p.h"
0011 
0012 #include "akonadi_mime_debug.h"
0013 
0014 #include "transportattribute.h"
0015 #include <Akonadi/AgentManager>
0016 #include <Akonadi/Collection>
0017 #include <Akonadi/SpecialMailCollections>
0018 
0019 using namespace Akonadi;
0020 
0021 Q_GLOBAL_STATIC(DispatcherInterfacePrivate, sInstance)
0022 
0023 void DispatcherInterfacePrivate::massModifyResult(KJob *job)
0024 {
0025     // Nothing to do here, really.  If the job fails, the user can retry it.
0026     if (job->error()) {
0027         qCDebug(AKONADIMIME_LOG) << "failed" << job->errorString();
0028     } else {
0029         qCDebug(AKONADIMIME_LOG) << "succeeded.";
0030     }
0031 }
0032 
0033 DispatcherInterface::DispatcherInterface() = default;
0034 
0035 AgentInstance DispatcherInterface::dispatcherInstance() const
0036 {
0037     AgentInstance a = AgentManager::self()->instance(QStringLiteral("akonadi_maildispatcher_agent"));
0038     if (!a.isValid()) {
0039         qCWarning(AKONADIMIME_LOG) << "Could not get MDA instance.";
0040     }
0041     return a;
0042 }
0043 
0044 void DispatcherInterface::dispatchManually()
0045 {
0046     Collection outbox = SpecialMailCollections::self()->defaultCollection(SpecialMailCollections::Outbox);
0047     if (!outbox.isValid()) {
0048         //    qCritical() << "Could not access Outbox.";
0049         return;
0050     }
0051 
0052     auto mjob = new FilterActionJob(outbox, new SendQueuedAction, sInstance);
0053     QObject::connect(mjob, &KJob::result, sInstance(), &DispatcherInterfacePrivate::massModifyResult);
0054 }
0055 
0056 void DispatcherInterface::retryDispatching()
0057 {
0058     Collection outbox = SpecialMailCollections::self()->defaultCollection(SpecialMailCollections::Outbox);
0059     if (!outbox.isValid()) {
0060         //    qCritical() << "Could not access Outbox.";
0061         return;
0062     }
0063 
0064     auto mjob = new FilterActionJob(outbox, new ClearErrorAction, sInstance);
0065     QObject::connect(mjob, &KJob::result, sInstance(), &DispatcherInterfacePrivate::massModifyResult);
0066 }
0067 
0068 void DispatcherInterface::dispatchManualTransport(int transportId)
0069 {
0070     Collection outbox = SpecialMailCollections::self()->defaultCollection(SpecialMailCollections::Outbox);
0071     if (!outbox.isValid()) {
0072         //    qCritical() << "Could not access Outbox.";
0073         return;
0074     }
0075 
0076     auto mjob = new FilterActionJob(outbox, new DispatchManualTransportAction(transportId), sInstance);
0077     QObject::connect(mjob, &KJob::result, sInstance(), &DispatcherInterfacePrivate::massModifyResult);
0078 }
0079 
0080 #include "moc_dispatcherinterface_p.cpp"