From c354798305f79805ca208951ba1ea8f43f7fe717 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sun, 26 Jun 2016 10:44:22 +0200 Subject: Use specialpurpose preprocessor which gives us trash folder support. --- common/domain/applicationdomaintype.cpp | 2 +- examples/maildirresource/maildirresource.cpp | 29 ++++++++-------------------- 2 files changed, 9 insertions(+), 22 deletions(-) diff --git a/common/domain/applicationdomaintype.cpp b/common/domain/applicationdomaintype.cpp index df63c35..d1faf25 100644 --- a/common/domain/applicationdomaintype.cpp +++ b/common/domain/applicationdomaintype.cpp @@ -253,7 +253,7 @@ namespace MaildirResource { auto &&resource = ApplicationDomainType::createEntity(); resource.setProperty("type", "org.kde.maildir"); resource.setProperty("account", account); - resource.setProperty("capabilities", QVariant::fromValue(QByteArrayList() << ResourceCapabilities::Mail::storage << ResourceCapabilities::Mail::drafts << "-folder.rename")); + resource.setProperty("capabilities", QVariant::fromValue(QByteArrayList() << ResourceCapabilities::Mail::storage << ResourceCapabilities::Mail::drafts << "-folder.rename" << ResourceCapabilities::Mail::trash)); return resource; } } 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 @@ #include "synchronizer.h" #include "sourcewriteback.h" #include "adaptorfactoryregistry.h" +#include "specialpurposepreprocessor.h" #include #include #include @@ -105,10 +106,10 @@ public: } }; -class FolderUpdater : public Sink::Preprocessor +class MaildirMimeMessageMover : public Sink::Preprocessor { public: - FolderUpdater(const QByteArray &drafts) : mDraftsFolder(drafts) {} + MaildirMimeMessageMover(const QByteArray &resourceInstanceIdentifier, const QString &maildirPath) : mResourceInstanceIdentifier(resourceInstanceIdentifier), mMaildirPath(maildirPath) {} QString getPath(const QByteArray &folderIdentifier, Sink::Storage::Transaction &transaction) { @@ -168,9 +169,6 @@ public: void newEntity(const QByteArray &uid, qint64 revision, Sink::ApplicationDomain::BufferAdaptor &newEntity, Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE { - if (newEntity.getProperty("draft").toBool()) { - newEntity.setProperty("folder", mDraftsFolder); - } const auto mimeMessage = newEntity.getProperty("mimeMessage"); if (mimeMessage.isValid()) { newEntity.setProperty("mimeMessage", moveMessage(mimeMessage.toString(), newEntity.getProperty("folder").toByteArray(), transaction)); @@ -180,9 +178,6 @@ public: void modifiedEntity(const QByteArray &uid, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &oldEntity, Sink::ApplicationDomain::BufferAdaptor &newEntity, Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE { - if (newEntity.getProperty("draft").toBool()) { - newEntity.setProperty("folder", mDraftsFolder); - } const auto mimeMessage = newEntity.getProperty("mimeMessage"); const auto newFolder = newEntity.getProperty("folder"); const bool mimeMessageChanged = mimeMessage.isValid() && mimeMessage.toString() != oldEntity.getProperty("mimeMessage").toString(); @@ -221,7 +216,6 @@ public: const auto filePath = getFilePathFromMimeMessagePath(oldEntity.getProperty("mimeMessage").toString()); QFile::remove(filePath); } - QByteArray mDraftsFolder; QByteArray mResourceInstanceIdentifier; QString mMaildirPath; }; @@ -229,7 +223,7 @@ public: class FolderPreprocessor : public Sink::Preprocessor { public: - FolderPreprocessor() {} + FolderPreprocessor(const QString maildirPath) : mMaildirPath(maildirPath) {} void newEntity(const QByteArray &uid, qint64 revision, Sink::ApplicationDomain::BufferAdaptor &newEntity, Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE { @@ -499,23 +493,16 @@ MaildirResource::MaildirResource(const QByteArray &instanceIdentifier, const QSh changereplay->mMaildirPath = mMaildirPath; setupChangereplay(changereplay); - auto folderUpdater = new FolderUpdater(QByteArray()); - setupPreprocessors(ENTITY_TYPE_MAIL, QVector() << folderUpdater << new MaildirMailPropertyExtractor << new DefaultIndexUpdater); - auto folderPreprocessor = new FolderPreprocessor; - setupPreprocessors(ENTITY_TYPE_FOLDER, QVector() << folderPreprocessor << new DefaultIndexUpdater); + setupPreprocessors(ENTITY_TYPE_MAIL, QVector() << new SpecialPurposeProcessor(mResourceType, mResourceInstanceIdentifier) << new MaildirMimeMessageMover(mResourceInstanceIdentifier, mMaildirPath) << new MaildirMailPropertyExtractor << new DefaultIndexUpdater); + setupPreprocessors(ENTITY_TYPE_FOLDER, QVector() << new FolderPreprocessor(mMaildirPath) << new DefaultIndexUpdater); KPIM::Maildir dir(mMaildirPath, true); Trace() << "Started maildir resource for maildir: " << mMaildirPath; - mDraftsFolder = dir.addSubFolder("Drafts"); + auto draftsFolder = dir.addSubFolder("Drafts"); - auto remoteId = synchronizer->createFolder(mDraftsFolder, "folder", QByteArrayList() << "drafts"); + auto remoteId = synchronizer->createFolder(draftsFolder, "folder", QByteArrayList() << "drafts"); auto draftsFolderLocalId = synchronizer->syncStore().resolveRemoteId(ENTITY_TYPE_FOLDER, remoteId); synchronizer->commit(); - - folderUpdater->mDraftsFolder = draftsFolderLocalId; - folderUpdater->mResourceInstanceIdentifier = mResourceInstanceIdentifier; - folderUpdater->mMaildirPath = mMaildirPath; - folderPreprocessor->mMaildirPath = mMaildirPath; } void MaildirResource::removeFromDisk(const QByteArray &instanceIdentifier) -- cgit v1.2.3