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. --- examples/dummyresource/resourcefactory.cpp | 25 ++++++++++++------------- examples/imapresource/imapresource.cpp | 8 ++++---- examples/maildirresource/maildirresource.cpp | 8 ++++---- 3 files changed, 20 insertions(+), 21 deletions(-) (limited to 'examples') diff --git a/examples/dummyresource/resourcefactory.cpp b/examples/dummyresource/resourcefactory.cpp index d230ea3..07021b9 100644 --- a/examples/dummyresource/resourcefactory.cpp +++ b/examples/dummyresource/resourcefactory.cpp @@ -59,34 +59,33 @@ class DummySynchronizer : public Sink::Synchronizer { { static uint8_t rawData[100]; auto event = Sink::ApplicationDomain::Event::Ptr::create(); - event->setProperty("summary", data.value("summary").toString()); + event->setSummary(data.value("summary").toString()); event->setProperty("remoteId", ridBuffer); - event->setProperty("description", data.value("description").toString()); - event->setProperty("attachment", QByteArray::fromRawData(reinterpret_cast(rawData), 100)); + event->setDescription(data.value("description").toString()); + event->setAttachment(QByteArray::fromRawData(reinterpret_cast(rawData), 100)); return event; } Sink::ApplicationDomain::Mail::Ptr createMail(const QByteArray &ridBuffer, const QMap &data) { auto mail = Sink::ApplicationDomain::Mail::Ptr::create(); - mail->setProperty("subject", data.value("subject").toString()); - mail->setProperty("senderEmail", data.value("senderEmail").toString()); - mail->setProperty("senderName", data.value("senderName").toString()); - mail->setProperty("date", data.value("date").toString()); - mail->setProperty("folder", syncStore().resolveRemoteId(ENTITY_TYPE_FOLDER, data.value("parentFolder").toByteArray())); - mail->setProperty("unread", data.value("unread").toBool()); - mail->setProperty("important", data.value("important").toBool()); + mail->setExtractedSubject(data.value("subject").toString()); + mail->setExtractedSender(Sink::ApplicationDomain::Mail::Contact{data.value("senderName").toString(), data.value("senderEmail").toString()}); + mail->setExtractedDate(data.value("date").toDateTime()); + mail->setFolder(syncStore().resolveRemoteId(ENTITY_TYPE_FOLDER, data.value("parentFolder").toByteArray())); + mail->setUnread(data.value("unread").toBool()); + mail->setImportant(data.value("important").toBool()); return mail; } Sink::ApplicationDomain::Folder::Ptr createFolder(const QByteArray &ridBuffer, const QMap &data) { auto folder = Sink::ApplicationDomain::Folder::Ptr::create(); - folder->setProperty("name", data.value("name").toString()); - folder->setProperty("icon", data.value("icon").toString()); + folder->setName(data.value("name").toString()); + folder->setIcon(data.value("icon").toByteArray()); if (!data.value("parent").toString().isEmpty()) { auto sinkId = syncStore().resolveRemoteId(ENTITY_TYPE_FOLDER, data.value("parent").toByteArray()); - folder->setProperty("parent", sinkId); + folder->setParent(sinkId); } return folder; } diff --git a/examples/imapresource/imapresource.cpp b/examples/imapresource/imapresource.cpp index 9577f3e..238fb0c 100644 --- a/examples/imapresource/imapresource.cpp +++ b/examples/imapresource/imapresource.cpp @@ -92,17 +92,17 @@ public: const auto remoteId = folderPath.toUtf8(); const auto bufferType = ENTITY_TYPE_FOLDER; Sink::ApplicationDomain::Folder folder; - folder.setProperty(ApplicationDomain::Folder::Name::name, folderName); - folder.setProperty(ApplicationDomain::Folder::Icon::name, icon); + folder.setName(folderName); + folder.setIcon(icon); QHash mergeCriteria; if (SpecialPurpose::isSpecialPurposeFolderName(folderName)) { auto type = SpecialPurpose::getSpecialPurposeType(folderName); - folder.setProperty(ApplicationDomain::Folder::SpecialPurpose::name, QVariant::fromValue(QByteArrayList() << type)); + folder.setSpecialPurpose(QByteArrayList() << type); mergeCriteria.insert(ApplicationDomain::Folder::SpecialPurpose::name, Query::Comparator(type, Query::Comparator::Contains)); } if (!parentFolderRid.isEmpty()) { - folder.setProperty("parent", syncStore().resolveRemoteId(ENTITY_TYPE_FOLDER, parentFolderRid.toUtf8())); + folder.setParent(syncStore().resolveRemoteId(ENTITY_TYPE_FOLDER, parentFolderRid.toUtf8())); } createOrModify(bufferType, remoteId, folder, mergeCriteria); return remoteId; diff --git a/examples/maildirresource/maildirresource.cpp b/examples/maildirresource/maildirresource.cpp index 1eee786..a05afc6 100644 --- a/examples/maildirresource/maildirresource.cpp +++ b/examples/maildirresource/maildirresource.cpp @@ -129,16 +129,16 @@ public: void newEntity(Sink::ApplicationDomain::ApplicationDomainType &newEntity) Q_DECL_OVERRIDE { - const ApplicationDomain::Mail mail{newEntity}; + auto mail = newEntity.cast(); const auto mimeMessage = mail.getMimeMessagePath(); if (!mimeMessage.isNull()) { - ApplicationDomain::Mail{newEntity}.setMimeMessagePath(moveMessage(mimeMessage, mail.getFolder())); + mail.setMimeMessagePath(moveMessage(mimeMessage, mail.getFolder())); } } void modifiedEntity(const Sink::ApplicationDomain::ApplicationDomainType &oldEntity, Sink::ApplicationDomain::ApplicationDomainType &newEntity) Q_DECL_OVERRIDE { - ApplicationDomain::Mail newMail{newEntity}; + auto newMail = newEntity.cast(); const ApplicationDomain::Mail oldMail{oldEntity}; const auto mimeMessage = newMail.getMimeMessagePath(); const auto newFolder = newMail.getFolder(); @@ -190,7 +190,7 @@ public: void newEntity(Sink::ApplicationDomain::ApplicationDomainType &newEntity) Q_DECL_OVERRIDE { - auto folderName = newEntity.getProperty("name").toString(); + auto folderName = Sink::ApplicationDomain::Folder{newEntity}.getName(); const auto path = mMaildirPath + "/" + folderName; KPIM::Maildir maildir(path, false); maildir.create(); -- cgit v1.2.3