File indexing completed on 2024-11-24 04:53:14
0001 /* Copyright (C) 2006 - 2014 Jan Kundrát <jkt@flaska.net> 0002 0003 This file is part of the Trojita Qt IMAP e-mail client, 0004 http://trojita.flaska.net/ 0005 0006 This program is free software; you can redistribute it and/or 0007 modify it under the terms of the GNU General Public License as 0008 published by the Free Software Foundation; either version 2 of 0009 the License or (at your option) version 3 or any later version 0010 accepted by the membership of KDE e.V. (or its successor approved 0011 by the membership of KDE e.V.), which shall act as a proxy 0012 defined in Section 14 of version 3 of the license. 0013 0014 This program is distributed in the hope that it will be useful, 0015 but WITHOUT ANY WARRANTY; without even the implied warranty of 0016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0017 GNU General Public License for more details. 0018 0019 You should have received a copy of the GNU General Public License 0020 along with this program. If not, see <http://www.gnu.org/licenses/>. 0021 */ 0022 0023 #include "TaskFactory.h" 0024 #include "Common/ConnectionId.h" 0025 #include "Imap/Model/TaskPresentationModel.h" 0026 #include "Imap/Parser/Parser.h" 0027 #include "Imap/Tasks/AppendTask.h" 0028 #include "Imap/Tasks/CopyMoveMessagesTask.h" 0029 #include "Imap/Tasks/CreateMailboxTask.h" 0030 #include "Imap/Tasks/DeleteMailboxTask.h" 0031 #include "Imap/Tasks/EnableTask.h" 0032 #include "Imap/Tasks/ExpungeMailboxTask.h" 0033 #include "Imap/Tasks/FetchMsgMetadataTask.h" 0034 #include "Imap/Tasks/FetchMsgPartTask.h" 0035 #include "Imap/Tasks/GenUrlAuthTask.h" 0036 #include "Imap/Tasks/GetAnyConnectionTask.h" 0037 #include "Imap/Tasks/IdTask.h" 0038 #include "Imap/Tasks/KeepMailboxOpenTask.h" 0039 #include "Imap/Tasks/Fake_ListChildMailboxesTask.h" 0040 #include "Imap/Tasks/Fake_OpenConnectionTask.h" 0041 #include "Imap/Tasks/NumberOfMessagesTask.h" 0042 #include "Imap/Tasks/ObtainSynchronizedMailboxTask.h" 0043 #include "Imap/Tasks/OpenConnectionTask.h" 0044 #include "Imap/Tasks/UidSubmitTask.h" 0045 #include "Imap/Tasks/UpdateFlagsTask.h" 0046 #include "Imap/Tasks/UpdateFlagsOfAllMessagesTask.h" 0047 #include "Imap/Tasks/ThreadTask.h" 0048 #include "Imap/Tasks/NoopTask.h" 0049 #include "Imap/Tasks/UnSelectTask.h" 0050 #include "Imap/Tasks/SortTask.h" 0051 #include "Imap/Tasks/SubscribeUnsubscribeTask.h" 0052 #include "Streams/SocketFactory.h" 0053 0054 namespace Imap 0055 { 0056 namespace Mailbox 0057 { 0058 0059 TaskFactory::~TaskFactory() 0060 { 0061 } 0062 0063 OpenConnectionTask *TaskFactory::createOpenConnectionTask(Model *model) 0064 { 0065 return new OpenConnectionTask(model); 0066 } 0067 0068 CopyMoveMessagesTask *TaskFactory::createCopyMoveMessagesTask(Model *model, const QModelIndexList &messages, 0069 const QString &targetMailbox, const CopyMoveOperation op) 0070 { 0071 return new CopyMoveMessagesTask(model, messages, targetMailbox, op); 0072 } 0073 0074 CreateMailboxTask *TaskFactory::createCreateMailboxTask(Model *model, const QString &mailbox) 0075 { 0076 return new CreateMailboxTask(model, mailbox); 0077 } 0078 0079 GetAnyConnectionTask *TaskFactory::createGetAnyConnectionTask(Model *model) 0080 { 0081 return new GetAnyConnectionTask(model); 0082 } 0083 0084 ListChildMailboxesTask *TaskFactory::createListChildMailboxesTask(Model *model, const QModelIndex &mailbox) 0085 { 0086 return new ListChildMailboxesTask(model, mailbox); 0087 } 0088 0089 DeleteMailboxTask *TaskFactory::createDeleteMailboxTask(Model *model, const QString &mailbox) 0090 { 0091 return new DeleteMailboxTask(model, mailbox); 0092 } 0093 0094 ExpungeMailboxTask *TaskFactory::createExpungeMailboxTask(Model *model, const QModelIndex &mailbox) 0095 { 0096 return new ExpungeMailboxTask(model, mailbox); 0097 } 0098 0099 FetchMsgMetadataTask *TaskFactory::createFetchMsgMetadataTask(Model *model, const QModelIndex &mailbox, const Imap::Uids &uids) 0100 { 0101 return new FetchMsgMetadataTask(model, mailbox, uids); 0102 } 0103 0104 FetchMsgPartTask *TaskFactory::createFetchMsgPartTask(Model *model, const QModelIndex &mailbox, const Imap::Uids &uids, const QList<QByteArray> &parts) 0105 { 0106 return new FetchMsgPartTask(model, mailbox, uids, parts); 0107 } 0108 0109 IdTask *TaskFactory::createIdTask(Model *model, ImapTask *dependingTask) 0110 { 0111 return new IdTask(model, dependingTask); 0112 } 0113 0114 EnableTask *TaskFactory::createEnableTask(Model *model, ImapTask *dependingTask, const QList<QByteArray> &extensions) 0115 { 0116 return new EnableTask(model, dependingTask, extensions); 0117 } 0118 0119 KeepMailboxOpenTask *TaskFactory::createKeepMailboxOpenTask(Model *model, const QModelIndex &mailbox, Parser *oldParser) 0120 { 0121 return new KeepMailboxOpenTask(model, mailbox, oldParser); 0122 } 0123 0124 NumberOfMessagesTask *TaskFactory::createNumberOfMessagesTask(Model *model, const QModelIndex &mailbox) 0125 { 0126 return new NumberOfMessagesTask(model, mailbox); 0127 } 0128 0129 ObtainSynchronizedMailboxTask *TaskFactory::createObtainSynchronizedMailboxTask(Model *model, const QModelIndex &mailboxIndex, 0130 ImapTask *parentTask, KeepMailboxOpenTask *keepTask) 0131 { 0132 return new ObtainSynchronizedMailboxTask(model, mailboxIndex, parentTask, keepTask); 0133 } 0134 0135 UpdateFlagsOfAllMessagesTask *TaskFactory::createUpdateFlagsOfAllMessagesTask(Model *model, const QModelIndex &mailbox, 0136 const FlagsOperation flagOperation, const QString &flags) 0137 { 0138 return new UpdateFlagsOfAllMessagesTask(model, mailbox, flagOperation, flags); 0139 } 0140 0141 UpdateFlagsTask *TaskFactory::createUpdateFlagsTask(Model *model, const QModelIndexList &messages, const FlagsOperation flagOperation, const QString &flags) 0142 { 0143 return new UpdateFlagsTask(model, messages, flagOperation, flags); 0144 } 0145 0146 UpdateFlagsTask *TaskFactory::createUpdateFlagsTask(Model *model, CopyMoveMessagesTask *copyTask, const QList<QPersistentModelIndex> &messages, const FlagsOperation flagOperation, const QString &flags) 0147 { 0148 return new UpdateFlagsTask(model, copyTask, messages, flagOperation, flags); 0149 } 0150 0151 ThreadTask *TaskFactory::createThreadTask(Model *model, const QModelIndex &mailbox, const QByteArray &algorithm, const QStringList &searchCriteria) 0152 { 0153 return new ThreadTask(model, mailbox, algorithm, searchCriteria); 0154 } 0155 0156 ThreadTask *TaskFactory::createIncrementalThreadTask(Model *model, const QModelIndex &mailbox, const QByteArray &algorithm, const QStringList &searchCriteria) 0157 { 0158 return new ThreadTask(model, mailbox, algorithm, searchCriteria, ThreadTask::THREADING_INCREMENTAL); 0159 } 0160 0161 NoopTask *TaskFactory::createNoopTask(Model *model, ImapTask *parentTask) 0162 { 0163 return new NoopTask(model, parentTask); 0164 } 0165 0166 UnSelectTask *TaskFactory::createUnSelectTask(Model *model, ImapTask *parentTask) 0167 { 0168 return new UnSelectTask(model, parentTask); 0169 } 0170 0171 SortTask *TaskFactory::createSortTask(Model *model, const QModelIndex &mailbox, const QStringList &searchConditions, const QStringList &sortCriteria) 0172 { 0173 return new SortTask(model, mailbox, searchConditions, sortCriteria); 0174 } 0175 0176 AppendTask *TaskFactory::createAppendTask(Model *model, const QString &targetMailbox, const QByteArray &rawMessageData, 0177 const QStringList &flags, const QDateTime ×tamp) 0178 { 0179 return new AppendTask(model, targetMailbox, rawMessageData, flags, timestamp); 0180 } 0181 0182 AppendTask *TaskFactory::createAppendTask(Model *model, const QString &targetMailbox, const QList<CatenatePair> &data, 0183 const QStringList &flags, const QDateTime ×tamp) 0184 { 0185 return new AppendTask(model, targetMailbox, data, flags, timestamp); 0186 } 0187 0188 SubscribeUnsubscribeTask *TaskFactory::createSubscribeUnsubscribeTask(Model *model, const QString &mailboxName, 0189 const SubscribeUnsubscribeOperation operation) 0190 { 0191 return new SubscribeUnsubscribeTask(model, mailboxName, operation); 0192 } 0193 0194 SubscribeUnsubscribeTask *TaskFactory::createSubscribeUnsubscribeTask(Model *model, ImapTask *parentTask, const QString &mailboxName, 0195 const SubscribeUnsubscribeOperation operation) 0196 { 0197 return new SubscribeUnsubscribeTask(model, parentTask, mailboxName, operation); 0198 } 0199 0200 GenUrlAuthTask *TaskFactory::createGenUrlAuthTask(Model *model, const QString &host, const QString &user, const QString &mailbox, 0201 const uint uidValidity, const uint uid, const QString &part, const QString &access) 0202 { 0203 return new GenUrlAuthTask(model, host, user, mailbox, uidValidity, uid, part, access); 0204 } 0205 UidSubmitTask *TaskFactory::createUidSubmitTask(Model *model, const QString &mailbox, const uint uidValidity, const uint uid, 0206 const UidSubmitOptionsList &submitOptions) 0207 { 0208 return new UidSubmitTask(model, mailbox, uidValidity, uid, submitOptions); 0209 } 0210 0211 TestingTaskFactory::TestingTaskFactory(): TaskFactory(), fakeOpenConnectionTask(false), fakeListChildMailboxes(false) 0212 { 0213 } 0214 0215 Parser *TestingTaskFactory::newParser(Model *model) 0216 { 0217 Parser *parser = new Parser(model, model->m_socketFactory->create(), Common::ConnectionId::next()); 0218 ParserState parserState(parser); 0219 QObject::connect(parser, &Parser::responseReceived, 0220 model, static_cast<void (Model::*)(Parser *)>(&Model::responseReceived), Qt::QueuedConnection); 0221 QObject::connect(parser, &Parser::connectionStateChanged, model, &Model::handleSocketStateChanged); 0222 QObject::connect(parser, &Parser::lineReceived, model, &Model::slotParserLineReceived); 0223 QObject::connect(parser, &Parser::lineSent, model, &Model::slotParserLineSent); 0224 model->m_parsers[ parser ] = parserState; 0225 model->m_taskModel->slotParserCreated(parser); 0226 return parser; 0227 } 0228 0229 OpenConnectionTask *TestingTaskFactory::createOpenConnectionTask(Model *model) 0230 { 0231 if (fakeOpenConnectionTask) { 0232 return new Fake_OpenConnectionTask(model, newParser(model)); 0233 } else { 0234 return TaskFactory::createOpenConnectionTask(model); 0235 } 0236 } 0237 0238 ListChildMailboxesTask *TestingTaskFactory::createListChildMailboxesTask(Model *model, const QModelIndex &mailbox) 0239 { 0240 if (fakeListChildMailboxes) { 0241 return new Fake_ListChildMailboxesTask(model, mailbox); 0242 } else { 0243 return TaskFactory::createListChildMailboxesTask(model, mailbox); 0244 } 0245 } 0246 0247 } 0248 }