00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "dispatcherinterface.h"
00021 #include "dispatcherinterface_p.h"
00022
00023 #include "outboxactions_p.h"
00024
00025 #include <KDebug>
00026 #include <KGlobal>
00027 #include <KLocalizedString>
00028
00029 #include <akonadi/agentmanager.h>
00030 #include <akonadi/collection.h>
00031 #include <akonadi/kmime/specialmailcollections.h>
00032 #include "transportattribute.h"
00033
00034 using namespace Akonadi;
00035 using namespace MailTransport;
00036
00037 K_GLOBAL_STATIC( DispatcherInterfacePrivate, sInstance )
00038
00039 void DispatcherInterfacePrivate::massModifyResult( KJob *job )
00040 {
00041
00042 if( job->error() ) {
00043 kDebug() << "failed" << job->errorString();
00044 } else {
00045 kDebug() << "succeeded.";
00046 }
00047 }
00048
00049 DispatcherInterface::DispatcherInterface()
00050 {
00051 }
00052
00053 AgentInstance DispatcherInterface::dispatcherInstance() const
00054 {
00055 AgentInstance a =
00056 AgentManager::self()->instance( QLatin1String( "akonadi_maildispatcher_agent" ) );
00057 if( !a.isValid() ) {
00058 kWarning() << "Could not get MDA instance.";
00059 }
00060 return a;
00061 }
00062
00063 void DispatcherInterface::dispatchManually()
00064 {
00065 Collection outbox =
00066 SpecialMailCollections::self()->defaultCollection( SpecialMailCollections::Outbox );
00067 if( !outbox.isValid() ) {
00068 kError() << "Could not access Outbox.";
00069 return;
00070 }
00071
00072 FilterActionJob *mjob = new FilterActionJob( outbox, new SendQueuedAction, sInstance );
00073 QObject::connect( mjob, SIGNAL(result(KJob*)), sInstance, SLOT(massModifyResult(KJob*)) );
00074 }
00075
00076 void DispatcherInterface::retryDispatching()
00077 {
00078 Collection outbox =
00079 SpecialMailCollections::self()->defaultCollection( SpecialMailCollections::Outbox );
00080 if( !outbox.isValid() ) {
00081 kError() << "Could not access Outbox.";
00082 return;
00083 }
00084
00085 FilterActionJob *mjob = new FilterActionJob( outbox, new ClearErrorAction, sInstance );
00086 QObject::connect( mjob, SIGNAL(result(KJob*)), sInstance, SLOT(massModifyResult(KJob*)) );
00087 }
00088
00089 void DispatcherInterface::dispatchManualTransport( int transportId )
00090 {
00091 Collection outbox =
00092 SpecialMailCollections::self()->defaultCollection( SpecialMailCollections::Outbox );
00093 if( !outbox.isValid() ) {
00094 kError() << "Could not access Outbox.";
00095 return;
00096 }
00097
00098 FilterActionJob *mjob =
00099 new FilterActionJob( outbox, new DispatchManualTransportAction( transportId ), sInstance );
00100 QObject::connect( mjob, SIGNAL(result(KJob*)), sInstance, SLOT(massModifyResult(KJob*)) );
00101 }
00102
00103 #include "dispatcherinterface_p.moc"