summaryrefslogtreecommitdiff
path: root/user/trojita/fetch-task.patch
diff options
context:
space:
mode:
Diffstat (limited to 'user/trojita/fetch-task.patch')
-rw-r--r--user/trojita/fetch-task.patch204
1 files changed, 204 insertions, 0 deletions
diff --git a/user/trojita/fetch-task.patch b/user/trojita/fetch-task.patch
new file mode 100644
index 000000000..378db6477
--- /dev/null
+++ b/user/trojita/fetch-task.patch
@@ -0,0 +1,204 @@
+From b12f18885861b125ed139f83fa27491d4b3f9f4e Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Jan=20Kundr=C3=A1t?= <jkt@kde.org>
+Date: Mon, 2 Jan 2017 19:01:16 +0100
+Subject: [PATCH] Refactoring: move FETCH finalization to a corresponding Task
+
+The tasks were always meant to be able to directly perform these
+operations. There's no point in stashing all functionality in the Model
+class -- that one is way too big already.
+
+Change-Id: I9adfefbdf2d7ecd3d060e764ace5535be10dd0d3
+---
+ src/Imap/Model/MailboxTree.cpp | 16 +++++++++++----
+ src/Imap/Model/MailboxTree.h | 2 ++
+ src/Imap/Model/Model.cpp | 28 -------------------------
+ src/Imap/Model/Model.h | 1 -
+ src/Imap/Tasks/FetchMsgPartTask.cpp | 32 ++++++++++++++++++++++++++++-
+ src/Imap/Tasks/FetchMsgPartTask.h | 10 +++++----
+ 6 files changed, 51 insertions(+), 38 deletions(-)
+
+diff --git a/src/Imap/Model/MailboxTree.cpp b/src/Imap/Model/MailboxTree.cpp
+index 8c28775f..47ea675c 100644
+--- a/src/Imap/Model/MailboxTree.cpp
++++ b/src/Imap/Model/MailboxTree.cpp
+@@ -1556,8 +1556,12 @@ bool TreeItemMessage::hasNestedAttachments(Model *const model, TreeItemPart *par
+ }
+
+
+-TreeItemPart::TreeItemPart(TreeItem *parent, const QByteArray &mimeType):
+- TreeItem(parent), m_mimeType(mimeType.toLower()), m_octets(0), m_partMime(0), m_partRaw(0)
++TreeItemPart::TreeItemPart(TreeItem *parent, const QByteArray &mimeType)
++ : TreeItem(parent)
++ , m_mimeType(mimeType.toLower())
++ , m_octets(0)
++ , m_partMime(nullptr)
++ , m_partRaw(nullptr)
+ {
+ if (isTopLevelMultiPart()) {
+ // Note that top-level multipart messages are special, their immediate contents
+@@ -1566,8 +1570,12 @@ TreeItemPart::TreeItemPart(TreeItem *parent, const QByteArray &mimeType):
+ }
+ }
+
+-TreeItemPart::TreeItemPart(TreeItem *parent):
+- TreeItem(parent), m_mimeType("text/plain"), m_octets(0), m_partMime(0), m_partRaw(0)
++TreeItemPart::TreeItemPart(TreeItem *parent)
++ : TreeItem(parent)
++ , m_mimeType("text/plain")
++ , m_octets(0)
++ , m_partMime(nullptr)
++ , m_partRaw(nullptr)
+ {
+ }
+
+diff --git a/src/Imap/Model/MailboxTree.h b/src/Imap/Model/MailboxTree.h
+index 5cfd843a..137d4a5f 100644
+--- a/src/Imap/Model/MailboxTree.h
++++ b/src/Imap/Model/MailboxTree.h
+@@ -55,6 +55,7 @@ class TreeItem
+ friend class MsgListModel; // for direct access to m_children
+ friend class ThreadingMsgListModel; // for direct access to m_children
+ friend class UpdateFlagsOfAllMessagesTask; // for direct access to m_children
++ friend class FetchMsgPartTask; // for direct access to m_children
+
+ protected:
+ /** @short Availability of an item */
+@@ -140,6 +141,7 @@ class TreeItemMailbox: public TreeItem
+ friend class DeleteMailboxTask; // for direct access to maintainingTask
+ friend class KeepMailboxOpenTask; // needs access to maintainingTask
+ friend class SubscribeUnsubscribeTask; // needs access to m_metadata.flags
++ friend class FetchMsgPartTask; // needs access to partIdToPtr()
+ static QLatin1String flagNoInferiors;
+ static QLatin1String flagHasNoChildren;
+ static QLatin1String flagHasChildren;
+diff --git a/src/Imap/Model/Model.cpp b/src/Imap/Model/Model.cpp
+index e62ef3dd..dc985d44 100644
+--- a/src/Imap/Model/Model.cpp
++++ b/src/Imap/Model/Model.cpp
+@@ -500,34 +500,6 @@ void Model::emitMessageCountChanged(TreeItemMailbox *const mailbox)
+ emit messageCountPossiblyChanged(mailboxIndex);
+ }
+
+-/** @short Retrieval of a message part has completed */
+-bool Model::finalizeFetchPart(TreeItemMailbox *const mailbox, const uint sequenceNo, const QByteArray &partId)
+-{
+- // At first, verify that the message itself is marked as loaded.
+- // If it isn't, it's probably because of Model::releaseMessageData().
+- TreeItem *item = mailbox->m_children[0]; // TreeItemMsgList
+- item = item->child(sequenceNo - 1, this); // TreeItemMessage
+- Q_ASSERT(item); // FIXME: or rather throw an exception?
+- if (item->accessFetchStatus() == TreeItem::NONE) {
+- // ...and it indeed got released, so let's just return and don't try to check anything
+- return false;
+- }
+-
+- TreeItemPart *part = mailbox->partIdToPtr(this, static_cast<TreeItemMessage *>(item), partId);
+- if (! part) {
+- qDebug() << "Can't verify part fetching status: part is not here!";
+- return false;
+- }
+- if (part->loading()) {
+- part->setFetchStatus(TreeItem::UNAVAILABLE);
+- QModelIndex idx = part->toIndex(this);
+- emit dataChanged(idx, idx);
+- return false;
+- } else {
+- return true;
+- }
+-}
+-
+ void Model::handleCapability(Imap::Parser *ptr, const Imap::Responses::Capability *const resp)
+ {
+ updateCapabilities(ptr, resp->capabilities);
+diff --git a/src/Imap/Model/Model.h b/src/Imap/Model/Model.h
+index 46dce087..114e29ac 100644
+--- a/src/Imap/Model/Model.h
++++ b/src/Imap/Model/Model.h
+@@ -492,7 +492,6 @@ private:
+
+ void finalizeList(Parser *parser, TreeItemMailbox *const mailboxPtr);
+ void finalizeIncrementalList(Parser *parser, const QString &parentMailboxName);
+- bool finalizeFetchPart(TreeItemMailbox *const mailbox, const uint sequenceNo, const QByteArray &partId);
+ void genericHandleFetch(TreeItemMailbox *mailbox, const Imap::Responses::Fetch *const resp);
+
+ void replaceChildMailboxes(TreeItemMailbox *mailboxPtr, const TreeItemChildrenList &mailboxes);
+diff --git a/src/Imap/Tasks/FetchMsgPartTask.cpp b/src/Imap/Tasks/FetchMsgPartTask.cpp
+index c7a49437..40e7ec81 100644
+--- a/src/Imap/Tasks/FetchMsgPartTask.cpp
++++ b/src/Imap/Tasks/FetchMsgPartTask.cpp
+@@ -121,7 +121,7 @@ void FetchMsgPartTask::markPendingItemsUnavailable()
+ QList<TreeItemMessage *> messages = model->findMessagesByUids(mailbox, uids);
+ Q_FOREACH(TreeItemMessage *message, messages) {
+ Q_FOREACH(const QByteArray &partId, parts) {
+- if (model->finalizeFetchPart(mailbox, message->row() + 1, partId)) {
++ if (finalizeFetchPart(mailbox, message->row() + 1, partId)) {
+ log(QLatin1String("Fetched part ") + QString::fromUtf8(partId), Common::LOG_MESSAGES);
+ } else {
+ log(QLatin1String("Received no data for part ") + QString::fromUtf8(partId), Common::LOG_MESSAGES);
+@@ -130,5 +130,35 @@ void FetchMsgPartTask::markPendingItemsUnavailable()
+ }
+ }
+
++/** @short Retrieval of a message part has completed */
++bool FetchMsgPartTask::finalizeFetchPart(TreeItemMailbox *const mailbox, const uint sequenceNo, const QByteArray &partId)
++{
++ Q_ASSERT(model);
++ // At first, verify that the message itself is marked as loaded.
++ // If it isn't, it's probably because of Model::releaseMessageData().
++ TreeItem *item = mailbox->m_children[0]; // TreeItemMsgList
++ item = item->child(sequenceNo - 1, model); // TreeItemMessage
++ Q_ASSERT(item); // FIXME: or rather throw an exception?
++ if (item->accessFetchStatus() == TreeItem::NONE) {
++ // ...and it indeed got released, so let's just return and don't try to check anything
++ return false;
++ }
++
++ TreeItemPart *part = mailbox->partIdToPtr(model, static_cast<TreeItemMessage *>(item), partId);
++ if (!part) {
++ log(QStringLiteral("Can't verify part fetching status: part is not here!"), Common::LOG_MESSAGES);
++ return false;
++ }
++ if (part->loading()) {
++ part->setFetchStatus(TreeItem::UNAVAILABLE);
++ QModelIndex idx = part->toIndex(model);
++ emit model->dataChanged(idx, idx);
++ return false;
++ } else {
++ return true;
++ }
++}
++
++
+ }
+ }
+diff --git a/src/Imap/Tasks/FetchMsgPartTask.h b/src/Imap/Tasks/FetchMsgPartTask.h
+index 4d5b591f..a7e4b2c1 100644
+--- a/src/Imap/Tasks/FetchMsgPartTask.h
++++ b/src/Imap/Tasks/FetchMsgPartTask.h
+@@ -26,10 +26,10 @@
+ #include <QPersistentModelIndex>
+ #include "ImapTask.h"
+
+-namespace Imap
+-{
+-namespace Mailbox
+-{
++namespace Imap {
++namespace Mailbox {
++
++class TreeItemMailbox;
+
+ /** @short Fetch a message part */
+ class FetchMsgPartTask : public ImapTask
+@@ -48,6 +48,8 @@ public:
+ protected slots:
+ void markPendingItemsUnavailable();
+ private:
++ bool finalizeFetchPart(TreeItemMailbox *const mailbox, const uint sequenceNo, const QByteArray &partId);
++
+ CommandHandle tag;
+ ImapTask *conn;
+ Imap::Uids uids;
+--
+GitLab
+