summaryrefslogtreecommitdiffstats
path: root/examples/dummyresource/resourcefactory.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2015-12-04 11:29:32 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2015-12-04 11:29:32 +0100
commitd2305f14fced3afdbda2b5a8f2a270ae91d79ae1 (patch)
treeb05f72eb639798dc8b1eadd0afc4209f7a2158cb /examples/dummyresource/resourcefactory.cpp
parent0f75ad4b96ec5994c022109278cad28a43255793 (diff)
downloadsink-d2305f14fced3afdbda2b5a8f2a270ae91d79ae1.tar.gz
sink-d2305f14fced3afdbda2b5a8f2a270ae91d79ae1.zip
Added mail and folder properties
Diffstat (limited to 'examples/dummyresource/resourcefactory.cpp')
-rw-r--r--examples/dummyresource/resourcefactory.cpp36
1 files changed, 20 insertions, 16 deletions
diff --git a/examples/dummyresource/resourcefactory.cpp b/examples/dummyresource/resourcefactory.cpp
index 9a577a0..a084c19 100644
--- a/examples/dummyresource/resourcefactory.cpp
+++ b/examples/dummyresource/resourcefactory.cpp
@@ -160,14 +160,27 @@ void DummyResource::createEvent(const QByteArray &ridBuffer, const QMap<QString,
160 Akonadi2::EntityBuffer::assembleEntityBuffer(entityFbb, 0, 0, m_fbb.GetBufferPointer(), m_fbb.GetSize(), 0, 0); 160 Akonadi2::EntityBuffer::assembleEntityBuffer(entityFbb, 0, 0, m_fbb.GetBufferPointer(), m_fbb.GetSize(), 0, 0);
161} 161}
162 162
163QString DummyResource::resolveRemoteId(const QByteArray &bufferType, const QString &remoteId, Akonadi2::Storage::Transaction &transaction)
164{
165 //Lookup local id for remote id, or insert a new pair otherwise
166 auto remoteIdWithType = bufferType + remoteId.toUtf8();
167 QByteArray akonadiId = Index("rid.mapping", transaction).lookup(remoteIdWithType);
168 if (akonadiId.isEmpty()) {
169 akonadiId = QUuid::createUuid().toString().toUtf8();
170 Index("rid.mapping", transaction).add(remoteIdWithType, akonadiId);
171 }
172 return akonadiId;
173}
174
175
163void DummyResource::createMail(const QByteArray &ridBuffer, const QMap<QString, QVariant> &data, flatbuffers::FlatBufferBuilder &entityFbb, Akonadi2::Storage::Transaction &transaction) 176void DummyResource::createMail(const QByteArray &ridBuffer, const QMap<QString, QVariant> &data, flatbuffers::FlatBufferBuilder &entityFbb, Akonadi2::Storage::Transaction &transaction)
164{ 177{
165 //Map the source format to the buffer format (which happens to be an exact copy here) 178 //Map the source format to the buffer format (which happens to be an almost exact copy here)
166 auto subject = m_fbb.CreateString(data.value("subject").toString().toStdString()); 179 auto subject = m_fbb.CreateString(data.value("subject").toString().toStdString());
167 auto sender = m_fbb.CreateString(data.value("sender").toString().toStdString()); 180 auto sender = m_fbb.CreateString(data.value("senderEmail").toString().toStdString());
168 auto senderName = m_fbb.CreateString(data.value("senderName").toString().toStdString()); 181 auto senderName = m_fbb.CreateString(data.value("senderName").toString().toStdString());
169 auto date = m_fbb.CreateString(data.value("date").toDate().toString().toStdString()); 182 auto date = m_fbb.CreateString(data.value("date").toDate().toString().toStdString());
170 auto folder = m_fbb.CreateString(std::string("inbox")); 183 auto folder = m_fbb.CreateString(resolveRemoteId(ENTITY_TYPE_MAIL, data.value("parentFolder").toString(), transaction).toStdString());
171 184
172 auto builder = Akonadi2::ApplicationDomain::Buffer::MailBuilder(m_fbb); 185 auto builder = Akonadi2::ApplicationDomain::Buffer::MailBuilder(m_fbb);
173 builder.add_subject(subject); 186 builder.add_subject(subject);
@@ -182,26 +195,16 @@ void DummyResource::createMail(const QByteArray &ridBuffer, const QMap<QString,
182 Akonadi2::EntityBuffer::assembleEntityBuffer(entityFbb, 0, 0, 0, 0, m_fbb.GetBufferPointer(), m_fbb.GetSize()); 195 Akonadi2::EntityBuffer::assembleEntityBuffer(entityFbb, 0, 0, 0, 0, m_fbb.GetBufferPointer(), m_fbb.GetSize());
183} 196}
184 197
185QString DummyResource::resolveRemoteId(const QString &remoteId, Akonadi2::Storage::Transaction &transaction)
186{
187 //Lookup local id for remote id, or insert a new pair otherwise
188 QByteArray akonadiId = Index("rid.mapping", transaction).lookup(remoteId.toLatin1());
189 if (akonadiId.isEmpty()) {
190 akonadiId = QUuid::createUuid().toString().toUtf8();
191 Index("rid.mapping", transaction).add(remoteId.toLatin1(), akonadiId);
192 }
193 return akonadiId;
194}
195
196void DummyResource::createFolder(const QByteArray &ridBuffer, const QMap<QString, QVariant> &data, flatbuffers::FlatBufferBuilder &entityFbb, Akonadi2::Storage::Transaction &transaction) 198void DummyResource::createFolder(const QByteArray &ridBuffer, const QMap<QString, QVariant> &data, flatbuffers::FlatBufferBuilder &entityFbb, Akonadi2::Storage::Transaction &transaction)
197{ 199{
198 //Map the source format to the buffer format (which happens to be an exact copy here) 200 //Map the source format to the buffer format (which happens to be an exact copy here)
199 auto name = m_fbb.CreateString(data.value("name").toString().toStdString()); 201 auto name = m_fbb.CreateString(data.value("name").toString().toStdString());
202 auto icon = m_fbb.CreateString(data.value("icon").toString().toStdString());
200 flatbuffers::Offset<flatbuffers::String> parent; 203 flatbuffers::Offset<flatbuffers::String> parent;
201 bool hasParent = false; 204 bool hasParent = false;
202 if (!data.value("parent").toString().isEmpty()) { 205 if (!data.value("parent").toString().isEmpty()) {
203 hasParent = true; 206 hasParent = true;
204 auto akonadiId = resolveRemoteId(data.value("parent").toString(), transaction); 207 auto akonadiId = resolveRemoteId(ENTITY_TYPE_FOLDER, data.value("parent").toString(), transaction);
205 parent = m_fbb.CreateString(akonadiId.toStdString()); 208 parent = m_fbb.CreateString(akonadiId.toStdString());
206 } 209 }
207 210
@@ -210,6 +213,7 @@ void DummyResource::createFolder(const QByteArray &ridBuffer, const QMap<QString
210 if (hasParent) { 213 if (hasParent) {
211 builder.add_parent(parent); 214 builder.add_parent(parent);
212 } 215 }
216 builder.add_icon(icon);
213 auto buffer = builder.Finish(); 217 auto buffer = builder.Finish();
214 Akonadi2::ApplicationDomain::Buffer::FinishFolderBuffer(m_fbb, buffer); 218 Akonadi2::ApplicationDomain::Buffer::FinishFolderBuffer(m_fbb, buffer);
215 Akonadi2::EntityBuffer::assembleEntityBuffer(entityFbb, 0, 0, 0, 0, m_fbb.GetBufferPointer(), m_fbb.GetSize()); 219 Akonadi2::EntityBuffer::assembleEntityBuffer(entityFbb, 0, 0, 0, 0, m_fbb.GetBufferPointer(), m_fbb.GetSize());
@@ -222,7 +226,7 @@ void DummyResource::synchronize(const QString &bufferType, const QMap<QString, Q
222 Index ridMapping("rid.mapping", synchronizationTransaction); 226 Index ridMapping("rid.mapping", synchronizationTransaction);
223 for (auto it = data.constBegin(); it != data.constEnd(); it++) { 227 for (auto it = data.constBegin(); it != data.constEnd(); it++) {
224 const auto remoteId = it.key().toUtf8(); 228 const auto remoteId = it.key().toUtf8();
225 auto akonadiId = resolveRemoteId(remoteId, synchronizationTransaction); 229 auto akonadiId = resolveRemoteId(bufferType.toUtf8(), remoteId, synchronizationTransaction);
226 230
227 bool found = false; 231 bool found = false;
228 transaction.openDatabase(bufferType.toUtf8() + ".main").scan(akonadiId.toUtf8(), [&found](const QByteArray &, const QByteArray &) -> bool { 232 transaction.openDatabase(bufferType.toUtf8() + ".main").scan(akonadiId.toUtf8(), [&found](const QByteArray &, const QByteArray &) -> bool {