diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-02-05 17:33:08 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-02-05 18:14:43 +0100 |
commit | 47bfba0d9152a1f7f689d7936b107b1a899a0b76 (patch) | |
tree | d3097b1da7bc87984bd7fdffbf803ed682e95fcc /examples/maildirresource/facade.cpp | |
parent | b9a79ed514e7ab6bab0d6dedfcb9a78387d2b7c1 (diff) | |
download | sink-47bfba0d9152a1f7f689d7936b107b1a899a0b76.tar.gz sink-47bfba0d9152a1f7f689d7936b107b1a899a0b76.zip |
Use property transformation for the mimeMessage
The filepath changes with every flag change. It is thus easier to only
store a limited path that remains stable, and figure out the rest as
the property is requested (we'll have to translate it anyways once we
the file handoff protocol is implemented).
The reason why we don't update the mimeMessage path on every
modification is because we move the message during change replay,
and not while storing the modification in the db. This would lead to
the message-path on disk not correspond to what is in the db for some
time.
Diffstat (limited to 'examples/maildirresource/facade.cpp')
-rw-r--r-- | examples/maildirresource/facade.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/examples/maildirresource/facade.cpp b/examples/maildirresource/facade.cpp index 7178ab9..a10a18b 100644 --- a/examples/maildirresource/facade.cpp +++ b/examples/maildirresource/facade.cpp | |||
@@ -19,17 +19,47 @@ | |||
19 | 19 | ||
20 | #include "facade.h" | 20 | #include "facade.h" |
21 | 21 | ||
22 | #include <QDir> | ||
23 | #include <QFileInfo> | ||
24 | |||
22 | #include "domainadaptor.h" | 25 | #include "domainadaptor.h" |
26 | #include "queryrunner.h" | ||
23 | 27 | ||
24 | MaildirResourceMailFacade::MaildirResourceMailFacade(const QByteArray &instanceIdentifier) | 28 | MaildirResourceMailFacade::MaildirResourceMailFacade(const QByteArray &instanceIdentifier) |
25 | : Sink::GenericFacade<Sink::ApplicationDomain::Mail>(instanceIdentifier, QSharedPointer<MaildirMailAdaptorFactory>::create()) | 29 | : Sink::GenericFacade<Sink::ApplicationDomain::Mail>(instanceIdentifier, QSharedPointer<MaildirMailAdaptorFactory>::create()) |
26 | { | 30 | { |
31 | mResultTransformation = [](Sink::ApplicationDomain::ApplicationDomainType &value) { | ||
32 | const auto property = value.getProperty("mimeMessage"); | ||
33 | if (property.isValid()) { | ||
34 | //Transform the mime message property into the actual path on disk. | ||
35 | const auto mimeMessage = property.toString(); | ||
36 | auto parts = mimeMessage.split('/'); | ||
37 | auto key = parts.takeLast(); | ||
38 | const auto folderPath = parts.join('/'); | ||
39 | const auto path = folderPath + "/cur/"; | ||
40 | |||
41 | Trace() << "Looking for mail in: " << path << key; | ||
42 | QDir dir(path); | ||
43 | const QFileInfoList list = dir.entryInfoList(QStringList() << (key+"*"), QDir::Files); | ||
44 | if (list.size() != 1) { | ||
45 | Warning() << "Failed to find message " << path << key << list.size(); | ||
46 | value.setProperty("mimeMessage", QVariant()); | ||
47 | } else { | ||
48 | value.setProperty("mimeMessage", list.at(0).filePath()); | ||
49 | } | ||
50 | } | ||
51 | }; | ||
27 | } | 52 | } |
28 | 53 | ||
29 | MaildirResourceMailFacade::~MaildirResourceMailFacade() | 54 | MaildirResourceMailFacade::~MaildirResourceMailFacade() |
30 | { | 55 | { |
31 | } | 56 | } |
32 | 57 | ||
58 | QPair<KAsync::Job<void>, Sink::ResultEmitter<Sink::ApplicationDomain::Mail::Ptr>::Ptr> MaildirResourceMailFacade::load(const Sink::Query &query) | ||
59 | { | ||
60 | return Sink::GenericFacade<Sink::ApplicationDomain::Mail>::load(query); | ||
61 | } | ||
62 | |||
33 | 63 | ||
34 | MaildirResourceFolderFacade::MaildirResourceFolderFacade(const QByteArray &instanceIdentifier) | 64 | MaildirResourceFolderFacade::MaildirResourceFolderFacade(const QByteArray &instanceIdentifier) |
35 | : Sink::GenericFacade<Sink::ApplicationDomain::Folder>(instanceIdentifier, QSharedPointer<MaildirFolderAdaptorFactory>::create()) | 65 | : Sink::GenericFacade<Sink::ApplicationDomain::Folder>(instanceIdentifier, QSharedPointer<MaildirFolderAdaptorFactory>::create()) |