summaryrefslogtreecommitdiffstats
path: root/common/specialpurposepreprocessor.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2016-12-08 13:18:19 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2016-12-08 13:18:19 +0100
commitae4b64b198a143240aa5dd1e202e5016abfdae71 (patch)
tree5d9d58a512ebc60c44637d11c9424f67a02887e8 /common/specialpurposepreprocessor.cpp
parentf425c2070131161dc11bcf70e35f8d1848cadb65 (diff)
downloadsink-ae4b64b198a143240aa5dd1e202e5016abfdae71.tar.gz
sink-ae4b64b198a143240aa5dd1e202e5016abfdae71.zip
Wrap references in a Reerence type.
This allows us to make sure that references are not taken out of context (the resource). Because we need to use the type-specific accessors more we also ran into a problem that we cannot "downcast" a reference with the change recording still working, for that we have the cast<T>() operator now.
Diffstat (limited to 'common/specialpurposepreprocessor.cpp')
-rw-r--r--common/specialpurposepreprocessor.cpp20
1 files changed, 13 insertions, 7 deletions
diff --git a/common/specialpurposepreprocessor.cpp b/common/specialpurposepreprocessor.cpp
index ce1a218..e73e4ce 100644
--- a/common/specialpurposepreprocessor.cpp
+++ b/common/specialpurposepreprocessor.cpp
@@ -59,7 +59,7 @@ QByteArray SpecialPurposeProcessor::ensureFolder(const QByteArray &specialPurpos
59 }); 59 });
60 60
61 if (!mSpecialPurposeFolders.contains(specialPurpose)) { 61 if (!mSpecialPurposeFolders.contains(specialPurpose)) {
62 SinkTrace() << "Failed to find a drafts folder, creating a new one"; 62 SinkTrace() << "Failed to find a " << specialPurpose << " folder, creating a new one";
63 auto folder = ApplicationDomain::Folder::create(mResourceInstanceIdentifier); 63 auto folder = ApplicationDomain::Folder::create(mResourceInstanceIdentifier);
64 folder.setSpecialPurpose(QByteArrayList() << specialPurpose); 64 folder.setSpecialPurpose(QByteArrayList() << specialPurpose);
65 folder.setName(sSpecialPurposeFolders.value(specialPurpose)); 65 folder.setName(sSpecialPurposeFolders.value(specialPurpose));
@@ -74,15 +74,21 @@ QByteArray SpecialPurposeProcessor::ensureFolder(const QByteArray &specialPurpos
74 74
75void SpecialPurposeProcessor::moveToFolder(Sink::ApplicationDomain::ApplicationDomainType &newEntity) 75void SpecialPurposeProcessor::moveToFolder(Sink::ApplicationDomain::ApplicationDomainType &newEntity)
76{ 76{
77 if (newEntity.getProperty(ApplicationDomain::Mail::Trash::name).toBool()) { 77 using namespace Sink::ApplicationDomain;
78 newEntity.setProperty("folder", ensureFolder(ApplicationDomain::SpecialPurpose::Mail::trash)); 78 auto mail = newEntity.cast<Mail>();
79 if (mail.getTrash()) {
80 auto f = ensureFolder(ApplicationDomain::SpecialPurpose::Mail::trash);
81 SinkTrace() << "Setting trash folder: " << f;
82 mail.setFolder(f);
79 return; 83 return;
80 } 84 }
81 if (newEntity.getProperty(ApplicationDomain::Mail::Draft::name).toBool()) { 85 if (mail.getDraft()) {
82 newEntity.setProperty("folder", ensureFolder(ApplicationDomain::SpecialPurpose::Mail::drafts)); 86 mail.setFolder(ensureFolder(ApplicationDomain::SpecialPurpose::Mail::drafts));
87 return;
83 } 88 }
84 if (newEntity.getProperty(ApplicationDomain::Mail::Sent::name).toBool()) { 89 if (mail.getSent()) {
85 newEntity.setProperty("folder", ensureFolder(ApplicationDomain::SpecialPurpose::Mail::sent)); 90 mail.setFolder(ensureFolder(ApplicationDomain::SpecialPurpose::Mail::sent));
91 return;
86 } 92 }
87} 93}
88 94