diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-12-08 13:18:19 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-12-08 13:18:19 +0100 |
commit | ae4b64b198a143240aa5dd1e202e5016abfdae71 (patch) | |
tree | 5d9d58a512ebc60c44637d11c9424f67a02887e8 /examples | |
parent | f425c2070131161dc11bcf70e35f8d1848cadb65 (diff) | |
download | sink-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 'examples')
-rw-r--r-- | examples/dummyresource/resourcefactory.cpp | 25 | ||||
-rw-r--r-- | examples/imapresource/imapresource.cpp | 8 | ||||
-rw-r--r-- | examples/maildirresource/maildirresource.cpp | 8 |
3 files changed, 20 insertions, 21 deletions
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 { | |||
59 | { | 59 | { |
60 | static uint8_t rawData[100]; | 60 | static uint8_t rawData[100]; |
61 | auto event = Sink::ApplicationDomain::Event::Ptr::create(); | 61 | auto event = Sink::ApplicationDomain::Event::Ptr::create(); |
62 | event->setProperty("summary", data.value("summary").toString()); | 62 | event->setSummary(data.value("summary").toString()); |
63 | event->setProperty("remoteId", ridBuffer); | 63 | event->setProperty("remoteId", ridBuffer); |
64 | event->setProperty("description", data.value("description").toString()); | 64 | event->setDescription(data.value("description").toString()); |
65 | event->setProperty("attachment", QByteArray::fromRawData(reinterpret_cast<const char*>(rawData), 100)); | 65 | event->setAttachment(QByteArray::fromRawData(reinterpret_cast<const char*>(rawData), 100)); |
66 | return event; | 66 | return event; |
67 | } | 67 | } |
68 | 68 | ||
69 | Sink::ApplicationDomain::Mail::Ptr createMail(const QByteArray &ridBuffer, const QMap<QString, QVariant> &data) | 69 | Sink::ApplicationDomain::Mail::Ptr createMail(const QByteArray &ridBuffer, const QMap<QString, QVariant> &data) |
70 | { | 70 | { |
71 | auto mail = Sink::ApplicationDomain::Mail::Ptr::create(); | 71 | auto mail = Sink::ApplicationDomain::Mail::Ptr::create(); |
72 | mail->setProperty("subject", data.value("subject").toString()); | 72 | mail->setExtractedSubject(data.value("subject").toString()); |
73 | mail->setProperty("senderEmail", data.value("senderEmail").toString()); | 73 | mail->setExtractedSender(Sink::ApplicationDomain::Mail::Contact{data.value("senderName").toString(), data.value("senderEmail").toString()}); |
74 | mail->setProperty("senderName", data.value("senderName").toString()); | 74 | mail->setExtractedDate(data.value("date").toDateTime()); |
75 | mail->setProperty("date", data.value("date").toString()); | 75 | mail->setFolder(syncStore().resolveRemoteId(ENTITY_TYPE_FOLDER, data.value("parentFolder").toByteArray())); |
76 | mail->setProperty("folder", syncStore().resolveRemoteId(ENTITY_TYPE_FOLDER, data.value("parentFolder").toByteArray())); | 76 | mail->setUnread(data.value("unread").toBool()); |
77 | mail->setProperty("unread", data.value("unread").toBool()); | 77 | mail->setImportant(data.value("important").toBool()); |
78 | mail->setProperty("important", data.value("important").toBool()); | ||
79 | return mail; | 78 | return mail; |
80 | } | 79 | } |
81 | 80 | ||
82 | Sink::ApplicationDomain::Folder::Ptr createFolder(const QByteArray &ridBuffer, const QMap<QString, QVariant> &data) | 81 | Sink::ApplicationDomain::Folder::Ptr createFolder(const QByteArray &ridBuffer, const QMap<QString, QVariant> &data) |
83 | { | 82 | { |
84 | auto folder = Sink::ApplicationDomain::Folder::Ptr::create(); | 83 | auto folder = Sink::ApplicationDomain::Folder::Ptr::create(); |
85 | folder->setProperty("name", data.value("name").toString()); | 84 | folder->setName(data.value("name").toString()); |
86 | folder->setProperty("icon", data.value("icon").toString()); | 85 | folder->setIcon(data.value("icon").toByteArray()); |
87 | if (!data.value("parent").toString().isEmpty()) { | 86 | if (!data.value("parent").toString().isEmpty()) { |
88 | auto sinkId = syncStore().resolveRemoteId(ENTITY_TYPE_FOLDER, data.value("parent").toByteArray()); | 87 | auto sinkId = syncStore().resolveRemoteId(ENTITY_TYPE_FOLDER, data.value("parent").toByteArray()); |
89 | folder->setProperty("parent", sinkId); | 88 | folder->setParent(sinkId); |
90 | } | 89 | } |
91 | return folder; | 90 | return folder; |
92 | } | 91 | } |
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: | |||
92 | const auto remoteId = folderPath.toUtf8(); | 92 | const auto remoteId = folderPath.toUtf8(); |
93 | const auto bufferType = ENTITY_TYPE_FOLDER; | 93 | const auto bufferType = ENTITY_TYPE_FOLDER; |
94 | Sink::ApplicationDomain::Folder folder; | 94 | Sink::ApplicationDomain::Folder folder; |
95 | folder.setProperty(ApplicationDomain::Folder::Name::name, folderName); | 95 | folder.setName(folderName); |
96 | folder.setProperty(ApplicationDomain::Folder::Icon::name, icon); | 96 | folder.setIcon(icon); |
97 | QHash<QByteArray, Query::Comparator> mergeCriteria; | 97 | QHash<QByteArray, Query::Comparator> mergeCriteria; |
98 | if (SpecialPurpose::isSpecialPurposeFolderName(folderName)) { | 98 | if (SpecialPurpose::isSpecialPurposeFolderName(folderName)) { |
99 | auto type = SpecialPurpose::getSpecialPurposeType(folderName); | 99 | auto type = SpecialPurpose::getSpecialPurposeType(folderName); |
100 | folder.setProperty(ApplicationDomain::Folder::SpecialPurpose::name, QVariant::fromValue(QByteArrayList() << type)); | 100 | folder.setSpecialPurpose(QByteArrayList() << type); |
101 | mergeCriteria.insert(ApplicationDomain::Folder::SpecialPurpose::name, Query::Comparator(type, Query::Comparator::Contains)); | 101 | mergeCriteria.insert(ApplicationDomain::Folder::SpecialPurpose::name, Query::Comparator(type, Query::Comparator::Contains)); |
102 | } | 102 | } |
103 | 103 | ||
104 | if (!parentFolderRid.isEmpty()) { | 104 | if (!parentFolderRid.isEmpty()) { |
105 | folder.setProperty("parent", syncStore().resolveRemoteId(ENTITY_TYPE_FOLDER, parentFolderRid.toUtf8())); | 105 | folder.setParent(syncStore().resolveRemoteId(ENTITY_TYPE_FOLDER, parentFolderRid.toUtf8())); |
106 | } | 106 | } |
107 | createOrModify(bufferType, remoteId, folder, mergeCriteria); | 107 | createOrModify(bufferType, remoteId, folder, mergeCriteria); |
108 | return remoteId; | 108 | 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: | |||
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 ApplicationDomain::Mail mail{newEntity}; | 132 | auto mail = newEntity.cast<ApplicationDomain::Mail>(); |
133 | const auto mimeMessage = mail.getMimeMessagePath(); | 133 | const auto mimeMessage = mail.getMimeMessagePath(); |
134 | if (!mimeMessage.isNull()) { | 134 | if (!mimeMessage.isNull()) { |
135 | ApplicationDomain::Mail{newEntity}.setMimeMessagePath(moveMessage(mimeMessage, mail.getFolder())); | 135 | mail.setMimeMessagePath(moveMessage(mimeMessage, mail.getFolder())); |
136 | } | 136 | } |
137 | } | 137 | } |
138 | 138 | ||
139 | 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 |
140 | { | 140 | { |
141 | ApplicationDomain::Mail newMail{newEntity}; | 141 | auto newMail = newEntity.cast<ApplicationDomain::Mail>(); |
142 | const ApplicationDomain::Mail oldMail{oldEntity}; | 142 | const ApplicationDomain::Mail oldMail{oldEntity}; |
143 | const auto mimeMessage = newMail.getMimeMessagePath(); | 143 | const auto mimeMessage = newMail.getMimeMessagePath(); |
144 | const auto newFolder = newMail.getFolder(); | 144 | const auto newFolder = newMail.getFolder(); |
@@ -190,7 +190,7 @@ public: | |||
190 | 190 | ||
191 | void newEntity(Sink::ApplicationDomain::ApplicationDomainType &newEntity) Q_DECL_OVERRIDE | 191 | void newEntity(Sink::ApplicationDomain::ApplicationDomainType &newEntity) Q_DECL_OVERRIDE |
192 | { | 192 | { |
193 | auto folderName = newEntity.getProperty("name").toString(); | 193 | auto folderName = Sink::ApplicationDomain::Folder{newEntity}.getName(); |
194 | const auto path = mMaildirPath + "/" + folderName; | 194 | const auto path = mMaildirPath + "/" + folderName; |
195 | KPIM::Maildir maildir(path, false); | 195 | KPIM::Maildir maildir(path, false); |
196 | maildir.create(); | 196 | maildir.create(); |