1 | /* |
2 | Copyright (c) 2009 Constantin Berzan <exit3219@gmail.com> |
3 | |
4 | This library is free software; you can redistribute it and/or modify it |
5 | under the terms of the GNU Library General Public License as published by |
6 | the Free Software Foundation; either version 2 of the License, or (at your |
7 | option) any later version. |
8 | |
9 | This library is distributed in the hope that it will be useful, but WITHOUT |
10 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
11 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public |
12 | License for more details. |
13 | |
14 | You should have received a copy of the GNU Library General Public License |
15 | along with this library; see the file COPYING.LIB. If not, write to the |
16 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
17 | 02110-1301, USA. |
18 | */ |
19 | |
20 | #include "dispatcherinterface.h" |
21 | #include "dispatcherinterface_p.h" |
22 | |
23 | #include "outboxactions_p.h" |
24 | |
25 | #include <KDebug> |
26 | #include <KGlobal> |
27 | |
28 | #include <akonadi/agentmanager.h> |
29 | #include <akonadi/collection.h> |
30 | #include <akonadi/kmime/specialmailcollections.h> |
31 | #include "transportattribute.h" |
32 | |
33 | using namespace Akonadi; |
34 | using namespace MailTransport; |
35 | |
36 | K_GLOBAL_STATIC( DispatcherInterfacePrivate, sInstance ) |
37 | |
38 | void DispatcherInterfacePrivate::massModifyResult( KJob *job ) |
39 | { |
40 | // Nothing to do here, really. If the job fails, the user can retry it. |
41 | if ( job->error() ) { |
42 | kDebug() << "failed" << job->errorString(); |
43 | } else { |
44 | kDebug() << "succeeded." ; |
45 | } |
46 | } |
47 | |
48 | DispatcherInterface::DispatcherInterface() |
49 | { |
50 | } |
51 | |
52 | AgentInstance DispatcherInterface::dispatcherInstance() const |
53 | { |
54 | AgentInstance a = |
55 | AgentManager::self()->instance( QLatin1String( "akonadi_maildispatcher_agent" ) ); |
56 | if ( !a.isValid() ) { |
57 | kWarning() << "Could not get MDA instance." ; |
58 | } |
59 | return a; |
60 | } |
61 | |
62 | void DispatcherInterface::dispatchManually() |
63 | { |
64 | Collection outbox = |
65 | SpecialMailCollections::self()->defaultCollection( SpecialMailCollections::Outbox ); |
66 | if ( !outbox.isValid() ) { |
67 | // kError() << "Could not access Outbox."; |
68 | return; |
69 | } |
70 | |
71 | FilterActionJob *mjob = new FilterActionJob( outbox, new SendQueuedAction, sInstance ); |
72 | QObject::connect( mjob, SIGNAL(result(KJob*)), sInstance, SLOT(massModifyResult(KJob*)) ); |
73 | } |
74 | |
75 | void DispatcherInterface::retryDispatching() |
76 | { |
77 | Collection outbox = |
78 | SpecialMailCollections::self()->defaultCollection( SpecialMailCollections::Outbox ); |
79 | if ( !outbox.isValid() ) { |
80 | // kError() << "Could not access Outbox."; |
81 | return; |
82 | } |
83 | |
84 | FilterActionJob *mjob = new FilterActionJob( outbox, new ClearErrorAction, sInstance ); |
85 | QObject::connect( mjob, SIGNAL(result(KJob*)), sInstance, SLOT(massModifyResult(KJob*)) ); |
86 | } |
87 | |
88 | void DispatcherInterface::dispatchManualTransport( int transportId ) |
89 | { |
90 | Collection outbox = |
91 | SpecialMailCollections::self()->defaultCollection( SpecialMailCollections::Outbox ); |
92 | if ( !outbox.isValid() ) { |
93 | // kError() << "Could not access Outbox."; |
94 | return; |
95 | } |
96 | |
97 | FilterActionJob *mjob = |
98 | new FilterActionJob( outbox, new DispatchManualTransportAction( transportId ), sInstance ); |
99 | QObject::connect( mjob, SIGNAL(result(KJob*)), sInstance, SLOT(massModifyResult(KJob*)) ); |
100 | } |
101 | |
102 | #include "moc_dispatcherinterface_p.cpp" |
103 | |