diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-06-26 10:44:22 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-06-26 10:44:22 +0200 |
commit | c354798305f79805ca208951ba1ea8f43f7fe717 (patch) | |
tree | ad0324d62020af06bed4690d2ded19c5c96bb7fa /examples/maildirresource/maildirresource.cpp | |
parent | b29a17465d1e52bd7dd5c57f08e7af53e915eee6 (diff) | |
download | sink-c354798305f79805ca208951ba1ea8f43f7fe717.tar.gz sink-c354798305f79805ca208951ba1ea8f43f7fe717.zip |
Use specialpurpose preprocessor which gives us trash folder support.
Diffstat (limited to 'examples/maildirresource/maildirresource.cpp')
-rw-r--r-- | examples/maildirresource/maildirresource.cpp | 29 |
1 files changed, 8 insertions, 21 deletions
diff --git a/examples/maildirresource/maildirresource.cpp b/examples/maildirresource/maildirresource.cpp index ea780cc..92cfceb 100644 --- a/examples/maildirresource/maildirresource.cpp +++ b/examples/maildirresource/maildirresource.cpp | |||
@@ -39,6 +39,7 @@ | |||
39 | #include "synchronizer.h" | 39 | #include "synchronizer.h" |
40 | #include "sourcewriteback.h" | 40 | #include "sourcewriteback.h" |
41 | #include "adaptorfactoryregistry.h" | 41 | #include "adaptorfactoryregistry.h" |
42 | #include "specialpurposepreprocessor.h" | ||
42 | #include <QDate> | 43 | #include <QDate> |
43 | #include <QUuid> | 44 | #include <QUuid> |
44 | #include <QDir> | 45 | #include <QDir> |
@@ -105,10 +106,10 @@ public: | |||
105 | } | 106 | } |
106 | }; | 107 | }; |
107 | 108 | ||
108 | class FolderUpdater : public Sink::Preprocessor | 109 | class MaildirMimeMessageMover : public Sink::Preprocessor |
109 | { | 110 | { |
110 | public: | 111 | public: |
111 | FolderUpdater(const QByteArray &drafts) : mDraftsFolder(drafts) {} | 112 | MaildirMimeMessageMover(const QByteArray &resourceInstanceIdentifier, const QString &maildirPath) : mResourceInstanceIdentifier(resourceInstanceIdentifier), mMaildirPath(maildirPath) {} |
112 | 113 | ||
113 | QString getPath(const QByteArray &folderIdentifier, Sink::Storage::Transaction &transaction) | 114 | QString getPath(const QByteArray &folderIdentifier, Sink::Storage::Transaction &transaction) |
114 | { | 115 | { |
@@ -168,9 +169,6 @@ public: | |||
168 | 169 | ||
169 | void newEntity(const QByteArray &uid, qint64 revision, Sink::ApplicationDomain::BufferAdaptor &newEntity, Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE | 170 | void newEntity(const QByteArray &uid, qint64 revision, Sink::ApplicationDomain::BufferAdaptor &newEntity, Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE |
170 | { | 171 | { |
171 | if (newEntity.getProperty("draft").toBool()) { | ||
172 | newEntity.setProperty("folder", mDraftsFolder); | ||
173 | } | ||
174 | const auto mimeMessage = newEntity.getProperty("mimeMessage"); | 172 | const auto mimeMessage = newEntity.getProperty("mimeMessage"); |
175 | if (mimeMessage.isValid()) { | 173 | if (mimeMessage.isValid()) { |
176 | newEntity.setProperty("mimeMessage", moveMessage(mimeMessage.toString(), newEntity.getProperty("folder").toByteArray(), transaction)); | 174 | newEntity.setProperty("mimeMessage", moveMessage(mimeMessage.toString(), newEntity.getProperty("folder").toByteArray(), transaction)); |
@@ -180,9 +178,6 @@ public: | |||
180 | void modifiedEntity(const QByteArray &uid, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &oldEntity, Sink::ApplicationDomain::BufferAdaptor &newEntity, | 178 | void modifiedEntity(const QByteArray &uid, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &oldEntity, Sink::ApplicationDomain::BufferAdaptor &newEntity, |
181 | Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE | 179 | Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE |
182 | { | 180 | { |
183 | if (newEntity.getProperty("draft").toBool()) { | ||
184 | newEntity.setProperty("folder", mDraftsFolder); | ||
185 | } | ||
186 | const auto mimeMessage = newEntity.getProperty("mimeMessage"); | 181 | const auto mimeMessage = newEntity.getProperty("mimeMessage"); |
187 | const auto newFolder = newEntity.getProperty("folder"); | 182 | const auto newFolder = newEntity.getProperty("folder"); |
188 | const bool mimeMessageChanged = mimeMessage.isValid() && mimeMessage.toString() != oldEntity.getProperty("mimeMessage").toString(); | 183 | const bool mimeMessageChanged = mimeMessage.isValid() && mimeMessage.toString() != oldEntity.getProperty("mimeMessage").toString(); |
@@ -221,7 +216,6 @@ public: | |||
221 | const auto filePath = getFilePathFromMimeMessagePath(oldEntity.getProperty("mimeMessage").toString()); | 216 | const auto filePath = getFilePathFromMimeMessagePath(oldEntity.getProperty("mimeMessage").toString()); |
222 | QFile::remove(filePath); | 217 | QFile::remove(filePath); |
223 | } | 218 | } |
224 | QByteArray mDraftsFolder; | ||
225 | QByteArray mResourceInstanceIdentifier; | 219 | QByteArray mResourceInstanceIdentifier; |
226 | QString mMaildirPath; | 220 | QString mMaildirPath; |
227 | }; | 221 | }; |
@@ -229,7 +223,7 @@ public: | |||
229 | class FolderPreprocessor : public Sink::Preprocessor | 223 | class FolderPreprocessor : public Sink::Preprocessor |
230 | { | 224 | { |
231 | public: | 225 | public: |
232 | FolderPreprocessor() {} | 226 | FolderPreprocessor(const QString maildirPath) : mMaildirPath(maildirPath) {} |
233 | 227 | ||
234 | void newEntity(const QByteArray &uid, qint64 revision, Sink::ApplicationDomain::BufferAdaptor &newEntity, Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE | 228 | void newEntity(const QByteArray &uid, qint64 revision, Sink::ApplicationDomain::BufferAdaptor &newEntity, Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE |
235 | { | 229 | { |
@@ -499,23 +493,16 @@ MaildirResource::MaildirResource(const QByteArray &instanceIdentifier, const QSh | |||
499 | changereplay->mMaildirPath = mMaildirPath; | 493 | changereplay->mMaildirPath = mMaildirPath; |
500 | setupChangereplay(changereplay); | 494 | setupChangereplay(changereplay); |
501 | 495 | ||
502 | auto folderUpdater = new FolderUpdater(QByteArray()); | 496 | setupPreprocessors(ENTITY_TYPE_MAIL, QVector<Sink::Preprocessor*>() << new SpecialPurposeProcessor(mResourceType, mResourceInstanceIdentifier) << new MaildirMimeMessageMover(mResourceInstanceIdentifier, mMaildirPath) << new MaildirMailPropertyExtractor << new DefaultIndexUpdater<Sink::ApplicationDomain::Mail>); |
503 | setupPreprocessors(ENTITY_TYPE_MAIL, QVector<Sink::Preprocessor*>() << folderUpdater << new MaildirMailPropertyExtractor << new DefaultIndexUpdater<Sink::ApplicationDomain::Mail>); | 497 | setupPreprocessors(ENTITY_TYPE_FOLDER, QVector<Sink::Preprocessor*>() << new FolderPreprocessor(mMaildirPath) << new DefaultIndexUpdater<Sink::ApplicationDomain::Folder>); |
504 | auto folderPreprocessor = new FolderPreprocessor; | ||
505 | setupPreprocessors(ENTITY_TYPE_FOLDER, QVector<Sink::Preprocessor*>() << folderPreprocessor << new DefaultIndexUpdater<Sink::ApplicationDomain::Folder>); | ||
506 | 498 | ||
507 | KPIM::Maildir dir(mMaildirPath, true); | 499 | KPIM::Maildir dir(mMaildirPath, true); |
508 | Trace() << "Started maildir resource for maildir: " << mMaildirPath; | 500 | Trace() << "Started maildir resource for maildir: " << mMaildirPath; |
509 | mDraftsFolder = dir.addSubFolder("Drafts"); | 501 | auto draftsFolder = dir.addSubFolder("Drafts"); |
510 | 502 | ||
511 | auto remoteId = synchronizer->createFolder(mDraftsFolder, "folder", QByteArrayList() << "drafts"); | 503 | auto remoteId = synchronizer->createFolder(draftsFolder, "folder", QByteArrayList() << "drafts"); |
512 | auto draftsFolderLocalId = synchronizer->syncStore().resolveRemoteId(ENTITY_TYPE_FOLDER, remoteId); | 504 | auto draftsFolderLocalId = synchronizer->syncStore().resolveRemoteId(ENTITY_TYPE_FOLDER, remoteId); |
513 | synchronizer->commit(); | 505 | synchronizer->commit(); |
514 | |||
515 | folderUpdater->mDraftsFolder = draftsFolderLocalId; | ||
516 | folderUpdater->mResourceInstanceIdentifier = mResourceInstanceIdentifier; | ||
517 | folderUpdater->mMaildirPath = mMaildirPath; | ||
518 | folderPreprocessor->mMaildirPath = mMaildirPath; | ||
519 | } | 506 | } |
520 | 507 | ||
521 | void MaildirResource::removeFromDisk(const QByteArray &instanceIdentifier) | 508 | void MaildirResource::removeFromDisk(const QByteArray &instanceIdentifier) |