summaryrefslogtreecommitdiff
path: root/user/trojita/fetch-task.patch
blob: 378db64773431cd4a21e3599934c67dcaa9fca5c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
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