diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-12-06 18:32:32 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-12-06 18:32:32 +0100 |
commit | 319a303bdceba18d0e5629f3de7a2b85646223be (patch) | |
tree | 7e4ccb76fa5ee875f49ea3d65e9e519e90573354 /examples/maildirresource/maildirresource.cpp | |
parent | 59aa460cf704d5f1a1fb1fe6b8ede4457da083ff (diff) | |
download | sink-319a303bdceba18d0e5629f3de7a2b85646223be.tar.gz sink-319a303bdceba18d0e5629f3de7a2b85646223be.zip |
Wrap blob properties in type so we can distinguish it from other properties.
When moving an entity to another resource we have to move the blob
properties to a temporary directory first, and that requires that we are
able to distinguish blob properties from the rest at runtime.
Diffstat (limited to 'examples/maildirresource/maildirresource.cpp')
-rw-r--r-- | examples/maildirresource/maildirresource.cpp | 46 |
1 files changed, 25 insertions, 21 deletions
diff --git a/examples/maildirresource/maildirresource.cpp b/examples/maildirresource/maildirresource.cpp index 708dabc..1eee786 100644 --- a/examples/maildirresource/maildirresource.cpp +++ b/examples/maildirresource/maildirresource.cpp | |||
@@ -129,41 +129,44 @@ public: | |||
129 | 129 | ||
130 | void newEntity(Sink::ApplicationDomain::ApplicationDomainType &newEntity) Q_DECL_OVERRIDE | 130 | void newEntity(Sink::ApplicationDomain::ApplicationDomainType &newEntity) Q_DECL_OVERRIDE |
131 | { | 131 | { |
132 | const auto mimeMessage = newEntity.getProperty("mimeMessage"); | 132 | const ApplicationDomain::Mail mail{newEntity}; |
133 | if (mimeMessage.isValid()) { | 133 | const auto mimeMessage = mail.getMimeMessagePath(); |
134 | newEntity.setProperty("mimeMessage", moveMessage(mimeMessage.toString(), newEntity.getProperty("folder").toByteArray())); | 134 | if (!mimeMessage.isNull()) { |
135 | ApplicationDomain::Mail{newEntity}.setMimeMessagePath(moveMessage(mimeMessage, mail.getFolder())); | ||
135 | } | 136 | } |
136 | } | 137 | } |
137 | 138 | ||
138 | void modifiedEntity(const Sink::ApplicationDomain::ApplicationDomainType &oldEntity, Sink::ApplicationDomain::ApplicationDomainType &newEntity) Q_DECL_OVERRIDE | 139 | void modifiedEntity(const Sink::ApplicationDomain::ApplicationDomainType &oldEntity, Sink::ApplicationDomain::ApplicationDomainType &newEntity) Q_DECL_OVERRIDE |
139 | { | 140 | { |
140 | const auto mimeMessage = newEntity.getProperty("mimeMessage"); | 141 | ApplicationDomain::Mail newMail{newEntity}; |
141 | const auto newFolder = newEntity.getProperty("folder"); | 142 | const ApplicationDomain::Mail oldMail{oldEntity}; |
142 | const bool mimeMessageChanged = mimeMessage.isValid() && mimeMessage.toString() != oldEntity.getProperty("mimeMessage").toString(); | 143 | const auto mimeMessage = newMail.getMimeMessagePath(); |
143 | const bool folderChanged = newFolder.isValid() && newFolder.toString() != oldEntity.getProperty("mimeMessage").toString(); | 144 | const auto newFolder = newMail.getFolder(); |
145 | const bool mimeMessageChanged = !mimeMessage.isNull() && mimeMessage != oldMail.getMimeMessagePath(); | ||
146 | const bool folderChanged = !newFolder.isNull() && newFolder != oldMail.getFolder(); | ||
144 | if (mimeMessageChanged || folderChanged) { | 147 | if (mimeMessageChanged || folderChanged) { |
145 | SinkTrace() << "Moving mime message: " << mimeMessageChanged << folderChanged; | 148 | SinkTrace() << "Moving mime message: " << mimeMessageChanged << folderChanged; |
146 | auto newPath = moveMessage(mimeMessage.toString(), newEntity.getProperty("folder").toByteArray()); | 149 | auto newPath = moveMessage(mimeMessage, newMail.getFolder()); |
147 | if (newPath != oldEntity.getProperty("mimeMessage").toString()) { | 150 | if (newPath != oldMail.getMimeMessagePath()) { |
148 | const auto oldPath = getFilePathFromMimeMessagePath(oldEntity.getProperty("mimeMessage").toString()); | 151 | const auto oldPath = getFilePathFromMimeMessagePath(oldMail.getMimeMessagePath()); |
149 | newEntity.setProperty("mimeMessage", newPath); | 152 | newMail.setMimeMessagePath(newPath); |
150 | //Remove the olde mime message if there is a new one | 153 | //Remove the olde mime message if there is a new one |
151 | QFile::remove(oldPath); | 154 | QFile::remove(oldPath); |
152 | } | 155 | } |
153 | } | 156 | } |
154 | 157 | ||
155 | auto mimeMessagePath = newEntity.getProperty("mimeMessage").toString(); | 158 | auto mimeMessagePath = newMail.getMimeMessagePath(); |
156 | const auto maildirPath = getPath(newEntity.getProperty("folder").toByteArray()); | 159 | const auto maildirPath = getPath(newMail.getFolder()); |
157 | KPIM::Maildir maildir(maildirPath, false); | 160 | KPIM::Maildir maildir(maildirPath, false); |
158 | const auto file = getFilePathFromMimeMessagePath(mimeMessagePath); | 161 | const auto file = getFilePathFromMimeMessagePath(mimeMessagePath); |
159 | QString identifier = KPIM::Maildir::getKeyFromFile(file); | 162 | QString identifier = KPIM::Maildir::getKeyFromFile(file); |
160 | 163 | ||
161 | //get flags from | 164 | //get flags from |
162 | KPIM::Maildir::Flags flags; | 165 | KPIM::Maildir::Flags flags; |
163 | if (!newEntity.getProperty("unread").toBool()) { | 166 | if (!newMail.getUnread()) { |
164 | flags |= KPIM::Maildir::Seen; | 167 | flags |= KPIM::Maildir::Seen; |
165 | } | 168 | } |
166 | if (newEntity.getProperty("important").toBool()) { | 169 | if (newMail.getImportant()) { |
167 | flags |= KPIM::Maildir::Flagged; | 170 | flags |= KPIM::Maildir::Flagged; |
168 | } | 171 | } |
169 | 172 | ||
@@ -172,7 +175,8 @@ public: | |||
172 | 175 | ||
173 | void deletedEntity(const Sink::ApplicationDomain::ApplicationDomainType &oldEntity) Q_DECL_OVERRIDE | 176 | void deletedEntity(const Sink::ApplicationDomain::ApplicationDomainType &oldEntity) Q_DECL_OVERRIDE |
174 | { | 177 | { |
175 | const auto filePath = getFilePathFromMimeMessagePath(oldEntity.getProperty("mimeMessage").toString()); | 178 | const ApplicationDomain::Mail oldMail{oldEntity}; |
179 | const auto filePath = getFilePathFromMimeMessagePath(oldMail.getMimeMessagePath()); | ||
176 | QFile::remove(filePath); | 180 | QFile::remove(filePath); |
177 | } | 181 | } |
178 | QByteArray mResourceInstanceIdentifier; | 182 | QByteArray mResourceInstanceIdentifier; |
@@ -239,7 +243,7 @@ public: | |||
239 | } | 243 | } |
240 | 244 | ||
241 | if (!md.isRoot()) { | 245 | if (!md.isRoot()) { |
242 | folder.setProperty("parent", syncStore().resolveRemoteId(ENTITY_TYPE_FOLDER, md.parent().path().toUtf8())); | 246 | folder.setParent(syncStore().resolveRemoteId(ENTITY_TYPE_FOLDER, md.parent().path().toUtf8())); |
243 | } | 247 | } |
244 | createOrModify(bufferType, remoteId, folder); | 248 | createOrModify(bufferType, remoteId, folder); |
245 | return remoteId; | 249 | return remoteId; |
@@ -317,11 +321,11 @@ public: | |||
317 | SinkTrace() << "Found a mail " << filePath << " : " << fileName; | 321 | SinkTrace() << "Found a mail " << filePath << " : " << fileName; |
318 | 322 | ||
319 | Sink::ApplicationDomain::Mail mail; | 323 | Sink::ApplicationDomain::Mail mail; |
320 | mail.setProperty("folder", folderLocalId); | 324 | mail.setFolder(folderLocalId); |
321 | //We only store the directory path + key, so we facade can add the changing bits (flags) | 325 | //We only store the directory path + key, so we facade can add the changing bits (flags) |
322 | mail.setProperty("mimeMessage", KPIM::Maildir::getDirectoryFromFile(filePath) + maildirKey); | 326 | mail.setMimeMessagePath(KPIM::Maildir::getDirectoryFromFile(filePath) + maildirKey); |
323 | mail.setProperty("unread", !flags.testFlag(KPIM::Maildir::Seen)); | 327 | mail.setUnread(!flags.testFlag(KPIM::Maildir::Seen)); |
324 | mail.setProperty("important", flags.testFlag(KPIM::Maildir::Flagged)); | 328 | mail.setImportant(flags.testFlag(KPIM::Maildir::Flagged)); |
325 | 329 | ||
326 | createOrModify(bufferType, remoteId, mail); | 330 | createOrModify(bufferType, remoteId, mail); |
327 | } | 331 | } |