From ae4b64b198a143240aa5dd1e202e5016abfdae71 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Thu, 8 Dec 2016 13:18:19 +0100 Subject: 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() operator now. --- common/specialpurposepreprocessor.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'common/specialpurposepreprocessor.cpp') 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 }); if (!mSpecialPurposeFolders.contains(specialPurpose)) { - SinkTrace() << "Failed to find a drafts folder, creating a new one"; + SinkTrace() << "Failed to find a " << specialPurpose << " folder, creating a new one"; auto folder = ApplicationDomain::Folder::create(mResourceInstanceIdentifier); folder.setSpecialPurpose(QByteArrayList() << specialPurpose); folder.setName(sSpecialPurposeFolders.value(specialPurpose)); @@ -74,15 +74,21 @@ QByteArray SpecialPurposeProcessor::ensureFolder(const QByteArray &specialPurpos void SpecialPurposeProcessor::moveToFolder(Sink::ApplicationDomain::ApplicationDomainType &newEntity) { - if (newEntity.getProperty(ApplicationDomain::Mail::Trash::name).toBool()) { - newEntity.setProperty("folder", ensureFolder(ApplicationDomain::SpecialPurpose::Mail::trash)); + using namespace Sink::ApplicationDomain; + auto mail = newEntity.cast(); + if (mail.getTrash()) { + auto f = ensureFolder(ApplicationDomain::SpecialPurpose::Mail::trash); + SinkTrace() << "Setting trash folder: " << f; + mail.setFolder(f); return; } - if (newEntity.getProperty(ApplicationDomain::Mail::Draft::name).toBool()) { - newEntity.setProperty("folder", ensureFolder(ApplicationDomain::SpecialPurpose::Mail::drafts)); + if (mail.getDraft()) { + mail.setFolder(ensureFolder(ApplicationDomain::SpecialPurpose::Mail::drafts)); + return; } - if (newEntity.getProperty(ApplicationDomain::Mail::Sent::name).toBool()) { - newEntity.setProperty("folder", ensureFolder(ApplicationDomain::SpecialPurpose::Mail::sent)); + if (mail.getSent()) { + mail.setFolder(ensureFolder(ApplicationDomain::SpecialPurpose::Mail::sent)); + return; } } -- cgit v1.2.3