diff options
Diffstat (limited to 'examples/dummyresource/dummystore.cpp')
-rw-r--r-- | examples/dummyresource/dummystore.cpp | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/examples/dummyresource/dummystore.cpp b/examples/dummyresource/dummystore.cpp new file mode 100644 index 0000000..44bea5c --- /dev/null +++ b/examples/dummyresource/dummystore.cpp | |||
@@ -0,0 +1,62 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2015 Christian Mollekopf <chrigi_1@fastmail.fm> | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License as published by | ||
6 | * the Free Software Foundation; either version 2 of the License, or | ||
7 | * (at your option) any later version. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | * GNU General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program; if not, write to the | ||
16 | * Free Software Foundation, Inc., | ||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
18 | */ | ||
19 | #include "dummystore.h" | ||
20 | |||
21 | #include <QString> | ||
22 | |||
23 | #include "dummycalendar_generated.h" | ||
24 | |||
25 | static std::string createEvent() | ||
26 | { | ||
27 | static const size_t attachmentSize = 1024*2; // 2KB | ||
28 | static uint8_t rawData[attachmentSize]; | ||
29 | static flatbuffers::FlatBufferBuilder fbb; | ||
30 | fbb.Clear(); | ||
31 | { | ||
32 | uint8_t *rawDataPtr = nullptr; | ||
33 | auto summary = fbb.CreateString("summary"); | ||
34 | auto data = fbb.CreateUninitializedVector<uint8_t>(attachmentSize, &rawDataPtr); | ||
35 | DummyCalendar::DummyEventBuilder eventBuilder(fbb); | ||
36 | eventBuilder.add_summary(summary); | ||
37 | eventBuilder.add_attachment(data); | ||
38 | auto eventLocation = eventBuilder.Finish(); | ||
39 | DummyCalendar::FinishDummyEventBuffer(fbb, eventLocation); | ||
40 | memcpy((void*)rawDataPtr, rawData, attachmentSize); | ||
41 | } | ||
42 | |||
43 | return std::string(reinterpret_cast<const char *>(fbb.GetBufferPointer()), fbb.GetSize()); | ||
44 | } | ||
45 | |||
46 | QMap<QString, QString> populate() | ||
47 | { | ||
48 | QMap<QString, QString> content; | ||
49 | for (int i = 0; i < 2; i++) { | ||
50 | auto event = createEvent(); | ||
51 | content.insert(QString("key%1").arg(i), QString::fromStdString(event)); | ||
52 | } | ||
53 | return content; | ||
54 | } | ||
55 | |||
56 | static QMap<QString, QString> s_dataSource = populate(); | ||
57 | |||
58 | |||
59 | QMap<QString, QString> DummyStore::data() const | ||
60 | { | ||
61 | return s_dataSource; | ||
62 | } | ||