diff options
Diffstat (limited to 'examples/maildirresource/maildirresource.cpp')
-rw-r--r-- | examples/maildirresource/maildirresource.cpp | 33 |
1 files changed, 15 insertions, 18 deletions
diff --git a/examples/maildirresource/maildirresource.cpp b/examples/maildirresource/maildirresource.cpp index b89d78c..920bd28 100644 --- a/examples/maildirresource/maildirresource.cpp +++ b/examples/maildirresource/maildirresource.cpp | |||
@@ -33,7 +33,6 @@ | |||
33 | #include "domain/mail.h" | 33 | #include "domain/mail.h" |
34 | #include "definitions.h" | 34 | #include "definitions.h" |
35 | #include "facadefactory.h" | 35 | #include "facadefactory.h" |
36 | #include "indexupdater.h" | ||
37 | #include "libmaildir/maildir.h" | 36 | #include "libmaildir/maildir.h" |
38 | #include "inspection.h" | 37 | #include "inspection.h" |
39 | #include "synchronizer.h" | 38 | #include "synchronizer.h" |
@@ -85,7 +84,7 @@ class MaildirMimeMessageMover : public Sink::Preprocessor | |||
85 | public: | 84 | public: |
86 | MaildirMimeMessageMover(const QByteArray &resourceInstanceIdentifier, const QString &maildirPath) : mResourceInstanceIdentifier(resourceInstanceIdentifier), mMaildirPath(maildirPath) {} | 85 | MaildirMimeMessageMover(const QByteArray &resourceInstanceIdentifier, const QString &maildirPath) : mResourceInstanceIdentifier(resourceInstanceIdentifier), mMaildirPath(maildirPath) {} |
87 | 86 | ||
88 | QString getPath(const QByteArray &folderIdentifier, Sink::Storage::DataStore::Transaction &transaction) | 87 | QString getPath(const QByteArray &folderIdentifier) |
89 | { | 88 | { |
90 | if (folderIdentifier.isEmpty()) { | 89 | if (folderIdentifier.isEmpty()) { |
91 | return mMaildirPath; | 90 | return mMaildirPath; |
@@ -108,10 +107,10 @@ public: | |||
108 | return folderPath; | 107 | return folderPath; |
109 | } | 108 | } |
110 | 109 | ||
111 | QString moveMessage(const QString &oldPath, const QByteArray &folder, Sink::Storage::DataStore::Transaction &transaction) | 110 | QString moveMessage(const QString &oldPath, const QByteArray &folder) |
112 | { | 111 | { |
113 | if (oldPath.startsWith(Sink::temporaryFileLocation())) { | 112 | if (oldPath.startsWith(Sink::temporaryFileLocation())) { |
114 | const auto path = getPath(folder, transaction); | 113 | const auto path = getPath(folder); |
115 | KPIM::Maildir maildir(path, false); | 114 | KPIM::Maildir maildir(path, false); |
116 | if (!maildir.isValid(true)) { | 115 | if (!maildir.isValid(true)) { |
117 | SinkWarning() << "Maildir is not existing: " << path; | 116 | SinkWarning() << "Maildir is not existing: " << path; |
@@ -120,7 +119,7 @@ public: | |||
120 | return path + "/" + identifier; | 119 | return path + "/" + identifier; |
121 | } else { | 120 | } else { |
122 | //Handle moves | 121 | //Handle moves |
123 | const auto path = getPath(folder, transaction); | 122 | const auto path = getPath(folder); |
124 | KPIM::Maildir maildir(path, false); | 123 | KPIM::Maildir maildir(path, false); |
125 | if (!maildir.isValid(true)) { | 124 | if (!maildir.isValid(true)) { |
126 | SinkWarning() << "Maildir is not existing: " << path; | 125 | SinkWarning() << "Maildir is not existing: " << path; |
@@ -141,16 +140,15 @@ public: | |||
141 | } | 140 | } |
142 | } | 141 | } |
143 | 142 | ||
144 | void newEntity(const QByteArray &uid, qint64 revision, Sink::ApplicationDomain::BufferAdaptor &newEntity, Sink::Storage::DataStore::Transaction &transaction) Q_DECL_OVERRIDE | 143 | void newEntity(Sink::ApplicationDomain::ApplicationDomainType &newEntity) Q_DECL_OVERRIDE |
145 | { | 144 | { |
146 | const auto mimeMessage = newEntity.getProperty("mimeMessage"); | 145 | const auto mimeMessage = newEntity.getProperty("mimeMessage"); |
147 | if (mimeMessage.isValid()) { | 146 | if (mimeMessage.isValid()) { |
148 | newEntity.setProperty("mimeMessage", moveMessage(mimeMessage.toString(), newEntity.getProperty("folder").toByteArray(), transaction)); | 147 | newEntity.setProperty("mimeMessage", moveMessage(mimeMessage.toString(), newEntity.getProperty("folder").toByteArray())); |
149 | } | 148 | } |
150 | } | 149 | } |
151 | 150 | ||
152 | void modifiedEntity(const QByteArray &uid, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &oldEntity, Sink::ApplicationDomain::BufferAdaptor &newEntity, | 151 | void modifiedEntity(const Sink::ApplicationDomain::ApplicationDomainType &oldEntity, Sink::ApplicationDomain::ApplicationDomainType &newEntity) Q_DECL_OVERRIDE |
153 | Sink::Storage::DataStore::Transaction &transaction) Q_DECL_OVERRIDE | ||
154 | { | 152 | { |
155 | const auto mimeMessage = newEntity.getProperty("mimeMessage"); | 153 | const auto mimeMessage = newEntity.getProperty("mimeMessage"); |
156 | const auto newFolder = newEntity.getProperty("folder"); | 154 | const auto newFolder = newEntity.getProperty("folder"); |
@@ -158,7 +156,7 @@ public: | |||
158 | const bool folderChanged = newFolder.isValid() && newFolder.toString() != oldEntity.getProperty("mimeMessage").toString(); | 156 | const bool folderChanged = newFolder.isValid() && newFolder.toString() != oldEntity.getProperty("mimeMessage").toString(); |
159 | if (mimeMessageChanged || folderChanged) { | 157 | if (mimeMessageChanged || folderChanged) { |
160 | SinkTrace() << "Moving mime message: " << mimeMessageChanged << folderChanged; | 158 | SinkTrace() << "Moving mime message: " << mimeMessageChanged << folderChanged; |
161 | auto newPath = moveMessage(mimeMessage.toString(), newEntity.getProperty("folder").toByteArray(), transaction); | 159 | auto newPath = moveMessage(mimeMessage.toString(), newEntity.getProperty("folder").toByteArray()); |
162 | if (newPath != oldEntity.getProperty("mimeMessage").toString()) { | 160 | if (newPath != oldEntity.getProperty("mimeMessage").toString()) { |
163 | const auto oldPath = getFilePathFromMimeMessagePath(oldEntity.getProperty("mimeMessage").toString()); | 161 | const auto oldPath = getFilePathFromMimeMessagePath(oldEntity.getProperty("mimeMessage").toString()); |
164 | newEntity.setProperty("mimeMessage", newPath); | 162 | newEntity.setProperty("mimeMessage", newPath); |
@@ -168,7 +166,7 @@ public: | |||
168 | } | 166 | } |
169 | 167 | ||
170 | auto mimeMessagePath = newEntity.getProperty("mimeMessage").toString(); | 168 | auto mimeMessagePath = newEntity.getProperty("mimeMessage").toString(); |
171 | const auto maildirPath = getPath(newEntity.getProperty("folder").toByteArray(), transaction); | 169 | const auto maildirPath = getPath(newEntity.getProperty("folder").toByteArray()); |
172 | KPIM::Maildir maildir(maildirPath, false); | 170 | KPIM::Maildir maildir(maildirPath, false); |
173 | const auto file = getFilePathFromMimeMessagePath(mimeMessagePath); | 171 | const auto file = getFilePathFromMimeMessagePath(mimeMessagePath); |
174 | QString identifier = KPIM::Maildir::getKeyFromFile(file); | 172 | QString identifier = KPIM::Maildir::getKeyFromFile(file); |
@@ -185,7 +183,7 @@ public: | |||
185 | maildir.changeEntryFlags(identifier, flags); | 183 | maildir.changeEntryFlags(identifier, flags); |
186 | } | 184 | } |
187 | 185 | ||
188 | void deletedEntity(const QByteArray &uid, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &oldEntity, Sink::Storage::DataStore::Transaction &transaction) Q_DECL_OVERRIDE | 186 | void deletedEntity(const Sink::ApplicationDomain::ApplicationDomainType &oldEntity) Q_DECL_OVERRIDE |
189 | { | 187 | { |
190 | const auto filePath = getFilePathFromMimeMessagePath(oldEntity.getProperty("mimeMessage").toString()); | 188 | const auto filePath = getFilePathFromMimeMessagePath(oldEntity.getProperty("mimeMessage").toString()); |
191 | QFile::remove(filePath); | 189 | QFile::remove(filePath); |
@@ -199,7 +197,7 @@ class FolderPreprocessor : public Sink::Preprocessor | |||
199 | public: | 197 | public: |
200 | FolderPreprocessor(const QString maildirPath) : mMaildirPath(maildirPath) {} | 198 | FolderPreprocessor(const QString maildirPath) : mMaildirPath(maildirPath) {} |
201 | 199 | ||
202 | void newEntity(const QByteArray &uid, qint64 revision, Sink::ApplicationDomain::BufferAdaptor &newEntity, Sink::Storage::DataStore::Transaction &transaction) Q_DECL_OVERRIDE | 200 | void newEntity(Sink::ApplicationDomain::ApplicationDomainType &newEntity) Q_DECL_OVERRIDE |
203 | { | 201 | { |
204 | auto folderName = newEntity.getProperty("name").toString(); | 202 | auto folderName = newEntity.getProperty("name").toString(); |
205 | const auto path = mMaildirPath + "/" + folderName; | 203 | const auto path = mMaildirPath + "/" + folderName; |
@@ -207,12 +205,11 @@ public: | |||
207 | maildir.create(); | 205 | maildir.create(); |
208 | } | 206 | } |
209 | 207 | ||
210 | void modifiedEntity(const QByteArray &uid, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &oldEntity, Sink::ApplicationDomain::BufferAdaptor &newEntity, | 208 | void modifiedEntity(const Sink::ApplicationDomain::ApplicationDomainType &oldEntity, Sink::ApplicationDomain::ApplicationDomainType &newEntity) Q_DECL_OVERRIDE |
211 | Sink::Storage::DataStore::Transaction &transaction) Q_DECL_OVERRIDE | ||
212 | { | 209 | { |
213 | } | 210 | } |
214 | 211 | ||
215 | void deletedEntity(const QByteArray &uid, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &oldEntity, Sink::Storage::DataStore::Transaction &transaction) Q_DECL_OVERRIDE | 212 | void deletedEntity(const Sink::ApplicationDomain::ApplicationDomainType &oldEntity) Q_DECL_OVERRIDE |
216 | { | 213 | { |
217 | } | 214 | } |
218 | QString mMaildirPath; | 215 | QString mMaildirPath; |
@@ -440,8 +437,8 @@ MaildirResource::MaildirResource(const Sink::ResourceContext &resourceContext, c | |||
440 | changereplay->mMaildirPath = mMaildirPath; | 437 | changereplay->mMaildirPath = mMaildirPath; |
441 | setupChangereplay(changereplay); | 438 | setupChangereplay(changereplay); |
442 | 439 | ||
443 | setupPreprocessors(ENTITY_TYPE_MAIL, QVector<Sink::Preprocessor*>() << new SpecialPurposeProcessor(resourceContext.resourceType, resourceContext.instanceId()) << new MaildirMimeMessageMover(resourceContext.instanceId(), mMaildirPath) << new MaildirMailPropertyExtractor << new DefaultIndexUpdater<Sink::ApplicationDomain::Mail>); | 440 | setupPreprocessors(ENTITY_TYPE_MAIL, QVector<Sink::Preprocessor*>() << new SpecialPurposeProcessor(resourceContext.resourceType, resourceContext.instanceId()) << new MaildirMimeMessageMover(resourceContext.instanceId(), mMaildirPath) << new MaildirMailPropertyExtractor); |
444 | setupPreprocessors(ENTITY_TYPE_FOLDER, QVector<Sink::Preprocessor*>() << new FolderPreprocessor(mMaildirPath) << new DefaultIndexUpdater<Sink::ApplicationDomain::Folder>); | 441 | setupPreprocessors(ENTITY_TYPE_FOLDER, QVector<Sink::Preprocessor*>() << new FolderPreprocessor(mMaildirPath)); |
445 | 442 | ||
446 | KPIM::Maildir dir(mMaildirPath, true); | 443 | KPIM::Maildir dir(mMaildirPath, true); |
447 | SinkTrace() << "Started maildir resource for maildir: " << mMaildirPath; | 444 | SinkTrace() << "Started maildir resource for maildir: " << mMaildirPath; |