-
Notifications
You must be signed in to change notification settings - Fork 0
/
backendstrategies.h
150 lines (114 loc) · 4.16 KB
/
backendstrategies.h
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
#ifndef BACKEND_STRATEGIES_H
#define BACKEND_STRATEGIES_H
// QMF
#include <qmfclient/qmailstore.h> // QMailStore
#include <qmfclient/qmailserviceaction.h> // QMailRetrievalAction
#include <qmfclient/qmailfolder.h> // QMailFolder
#include "utils.h"
#include "serviceactionmanager.h"
namespace backend_strategy {
class InitFolder
{
public:
void operator()(const QMailFolderId &id)
{
Q_ASSERT (id.isValid());
QMailFolder folder(id);
Q_ASSERT (folder.id().isValid());
qDebug() << "@backend_strategy::InitFolder:"
<< "retrieving folders for account" << folder.id();
ServiceActionManager::instance()->retrieveMessageList(folder.parentAccountId(), folder.id(), 20);
}
};
class InitAccount
{
public:
void operator()(const QMailAccountId &id)
{
Q_ASSERT (id.isValid());
qDebug() << "@backend_strategy::InitAccount:"
<< "retrieving folders for account" << id;
ServiceActionManager::instance()->retrieveFolderList(id, QMailFolderId());
}
};
class SyncFolder
{
public:
void operator()(const QMailFolderId &id)
{
//qWarning() << "### SyncFolder";
Q_ASSERT (id.isValid());
QMailFolder folder(id);
Q_ASSERT (folder.id().isValid());
qDebug() << "@backend_strategy::SyncFolder:"
<< "retrieving messages for folder" << folder.id();
ServiceActionManager::instance()->retrieveMessageList(folder.parentAccountId(), folder.id(), 20);
// exportUpdates() ?
}
};
class DownloadMessageBody
{
public:
void operator()(const QMailMessage &message)
{
Q_ASSERT (message.id().isValid());
const QMailMessagePartContainer *body_container = find::messageBody(message);
if (NULL == body_container || check::isDownloaded(body_container)) {
qWarning() << "@backend_strategy::DownloadMessageBody:"
<< "DownloadMessageBody: nothing to download";
return;
}
ServiceActionManager *manager = ServiceActionManager::instance();
if (const QMailMessagePart *part = dynamic_cast<const QMailMessagePart*>(body_container)) {
qDebug() << "@backend_strategy::DownloadMessageBody:"
<< "Downloading part" << part->location().toString(true);
manager->retrieveMessagePart(part->location());
}
else {
qDebug() << "@backend_strategy::DownloadMessageBody:"
<< "Downloading message" << message.id();
manager->retrieveMessages(QMailMessageIdList() << message.id(),
QMailRetrievalAction::Content);
}
}
};
class DownloadMessagePart
{
public:
void operator()(const QMailMessagePart::Location &location)
{
qDebug() << "@backend_strategy::DownloadMessagePart:"
<< "Downloading part" << location.toString(true);
ServiceActionManager::instance()->retrieveMessagePart(location);
}
};
class StopDownloadMessageBody
{
public:
void operator()(const QMailMessage &message)
{
Q_ASSERT (message.id().isValid());
const QMailMessagePartContainer *body_container = find::messageBody(message);
if (NULL == body_container) {
qWarning() << "@backend_strategy::StopDownloadMessageBody:"
<< "body container not found.";
return;
}
ServiceActionManager *manager = ServiceActionManager::instance();
const QMailMessagePart *part = dynamic_cast<const QMailMessagePart*>(body_container);
const QList<quint64> &serials = part ? manager->operations(part->location()) :
manager->operations(message.id());
if (serials.isEmpty()) {
qWarning() << "@backend_strategy::StopDownloadMessageBody:"
<< "nothing to stop.";
return;
}
foreach (quint64 serial, serials) {
qDebug() << "@backend_strategy::StopDownloadMessageBody:"
<< "canceling" << serial;
manager->cancelOperation(serial);
}
}
};
}
#endif // BACKEND_STRATEGIES_H