summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMinijackson <minijackson@riseup.net>2018-05-02 16:44:11 +0200
committerMinijackson <minijackson@riseup.net>2018-05-02 16:44:11 +0200
commit29695a1949c4f846f0d4ed21a400f3b864518ed1 (patch)
tree649ef0093dbd470fbb673ca525f53906fd79fd39
parent4d9192f4906989a0144d08d1ddb091dfa6efd9ed (diff)
downloadsink-29695a1949c4f846f0d4ed21a400f3b864518ed1.tar.gz
sink-29695a1949c4f846f0d4ed21a400f3b864518ed1.zip
Really add Todo entity type
-rw-r--r--common/CMakeLists.txt2
-rw-r--r--common/domain/applicationdomaintype.cpp13
-rw-r--r--common/domain/applicationdomaintype.h17
-rw-r--r--common/domain/applicationdomaintype_p.h2
-rw-r--r--common/domain/propertyregistry.cpp6
-rw-r--r--common/domain/todo.fbs18
-rw-r--r--common/domain/typeimplementations.cpp35
-rw-r--r--common/domain/typeimplementations.h12
-rw-r--r--common/propertymapper.cpp36
-rw-r--r--common/propertymapper.h8
-rw-r--r--common/todopreprocessor.cpp67
-rw-r--r--common/todopreprocessor.h35
12 files changed, 251 insertions, 0 deletions
diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt
index 51145fd..5077bbb 100644
--- a/common/CMakeLists.txt
+++ b/common/CMakeLists.txt
@@ -71,6 +71,7 @@ set(command_SRCS
71 contactpreprocessor.cpp 71 contactpreprocessor.cpp
72 mailpreprocessor.cpp 72 mailpreprocessor.cpp
73 eventpreprocessor.cpp 73 eventpreprocessor.cpp
74 todopreprocessor.cpp
74 specialpurposepreprocessor.cpp 75 specialpurposepreprocessor.cpp
75 datastorequery.cpp 76 datastorequery.cpp
76 storage/entitystore.cpp 77 storage/entitystore.cpp
@@ -105,6 +106,7 @@ generate_flatbuffers(
105 domain/contact 106 domain/contact
106 domain/addressbook 107 domain/addressbook
107 domain/event 108 domain/event
109 domain/todo
108 domain/calendar 110 domain/calendar
109 domain/mail 111 domain/mail
110 domain/folder 112 domain/folder
diff --git a/common/domain/applicationdomaintype.cpp b/common/domain/applicationdomaintype.cpp
index 78d46ee..b1469e1 100644
--- a/common/domain/applicationdomaintype.cpp
+++ b/common/domain/applicationdomaintype.cpp
@@ -132,6 +132,19 @@ SINK_REGISTER_PROPERTY(Event, EndTime);
132SINK_REGISTER_PROPERTY(Event, Ical); 132SINK_REGISTER_PROPERTY(Event, Ical);
133SINK_REGISTER_PROPERTY(Event, Calendar); 133SINK_REGISTER_PROPERTY(Event, Calendar);
134 134
135SINK_REGISTER_ENTITY(Todo);
136SINK_REGISTER_PROPERTY(Todo, Uid);
137SINK_REGISTER_PROPERTY(Todo, Summary);
138SINK_REGISTER_PROPERTY(Todo, Description);
139SINK_REGISTER_PROPERTY(Todo, CompletedDate);
140SINK_REGISTER_PROPERTY(Todo, DueDate);
141SINK_REGISTER_PROPERTY(Todo, StartDate);
142SINK_REGISTER_PROPERTY(Todo, Status);
143SINK_REGISTER_PROPERTY(Todo, Priority);
144SINK_REGISTER_PROPERTY(Todo, Categories);
145SINK_REGISTER_PROPERTY(Todo, Ical);
146SINK_REGISTER_PROPERTY(Todo, Calendar);
147
135SINK_REGISTER_ENTITY(Calendar); 148SINK_REGISTER_ENTITY(Calendar);
136SINK_REGISTER_PROPERTY(Calendar, Name); 149SINK_REGISTER_PROPERTY(Calendar, Name);
137 150
diff --git a/common/domain/applicationdomaintype.h b/common/domain/applicationdomaintype.h
index 39e66ab..93de8f5 100644
--- a/common/domain/applicationdomaintype.h
+++ b/common/domain/applicationdomaintype.h
@@ -407,6 +407,17 @@ struct SINK_EXPORT Event : public Entity {
407 407
408struct SINK_EXPORT Todo : public Entity { 408struct SINK_EXPORT Todo : public Entity {
409 SINK_ENTITY(Todo, todo); 409 SINK_ENTITY(Todo, todo);
410 SINK_EXTRACTED_PROPERTY(QString, Uid, uid);
411 SINK_EXTRACTED_PROPERTY(QString, Summary, summary);
412 SINK_EXTRACTED_PROPERTY(QString, Description, description);
413 SINK_EXTRACTED_PROPERTY(QDateTime, CompletedDate, completedDate);
414 SINK_EXTRACTED_PROPERTY(QDateTime, DueDate, dueDate);
415 SINK_EXTRACTED_PROPERTY(QDateTime, StartDate, startDate);
416 SINK_EXTRACTED_PROPERTY(QString, Status, status);
417 SINK_EXTRACTED_PROPERTY(int, Priority, priority);
418 SINK_EXTRACTED_PROPERTY(QStringList, Categories, categories);
419 SINK_PROPERTY(QByteArray, Ical, ical);
420 SINK_REFERENCE_PROPERTY(Calendar, Calendar, calendar);
410}; 421};
411 422
412struct SINK_EXPORT Folder : public Entity { 423struct SINK_EXPORT Folder : public Entity {
@@ -506,6 +517,11 @@ namespace Event {
506 static constexpr const char *calendar = "calendar"; 517 static constexpr const char *calendar = "calendar";
507 static constexpr const char *storage = "event.storage"; 518 static constexpr const char *storage = "event.storage";
508}; 519};
520namespace Todo {
521 static constexpr const char *todo = "todo";
522 static constexpr const char *calendar = "calendar";
523 static constexpr const char *storage = "todo.storage";
524};
509}; 525};
510 526
511namespace SpecialPurpose { 527namespace SpecialPurpose {
@@ -558,6 +574,7 @@ class SINK_EXPORT TypeImplementation;
558 REGISTER_TYPE(Sink::ApplicationDomain::Contact) \ 574 REGISTER_TYPE(Sink::ApplicationDomain::Contact) \
559 REGISTER_TYPE(Sink::ApplicationDomain::Addressbook) \ 575 REGISTER_TYPE(Sink::ApplicationDomain::Addressbook) \
560 REGISTER_TYPE(Sink::ApplicationDomain::Event) \ 576 REGISTER_TYPE(Sink::ApplicationDomain::Event) \
577 REGISTER_TYPE(Sink::ApplicationDomain::Todo) \
561 REGISTER_TYPE(Sink::ApplicationDomain::Calendar) \ 578 REGISTER_TYPE(Sink::ApplicationDomain::Calendar) \
562 REGISTER_TYPE(Sink::ApplicationDomain::Mail) \ 579 REGISTER_TYPE(Sink::ApplicationDomain::Mail) \
563 REGISTER_TYPE(Sink::ApplicationDomain::Folder) \ 580 REGISTER_TYPE(Sink::ApplicationDomain::Folder) \
diff --git a/common/domain/applicationdomaintype_p.h b/common/domain/applicationdomaintype_p.h
index 734ac3e..248f6f0 100644
--- a/common/domain/applicationdomaintype_p.h
+++ b/common/domain/applicationdomaintype_p.h
@@ -38,6 +38,8 @@ struct TypeHelper {
38 return Func<Sink::ApplicationDomain::Mail>{}(std::forward<Args...>(args...)); 38 return Func<Sink::ApplicationDomain::Mail>{}(std::forward<Args...>(args...));
39 } else if (type == Sink::ApplicationDomain::getTypeName<Sink::ApplicationDomain::Event>()) { 39 } else if (type == Sink::ApplicationDomain::getTypeName<Sink::ApplicationDomain::Event>()) {
40 return Func<Sink::ApplicationDomain::Event>{}(std::forward<Args...>(args...)); 40 return Func<Sink::ApplicationDomain::Event>{}(std::forward<Args...>(args...));
41 } else if (type == Sink::ApplicationDomain::getTypeName<Sink::ApplicationDomain::Todo>()) {
42 return Func<Sink::ApplicationDomain::Todo>{}(std::forward<Args...>(args...));
41 } else if (type == Sink::ApplicationDomain::getTypeName<Sink::ApplicationDomain::Calendar>()) { 43 } else if (type == Sink::ApplicationDomain::getTypeName<Sink::ApplicationDomain::Calendar>()) {
42 return Func<Sink::ApplicationDomain::Calendar>{}(std::forward<Args...>(args...)); 44 return Func<Sink::ApplicationDomain::Calendar>{}(std::forward<Args...>(args...));
43 } else if (type == Sink::ApplicationDomain::getTypeName<Sink::ApplicationDomain::Contact>()) { 45 } else if (type == Sink::ApplicationDomain::getTypeName<Sink::ApplicationDomain::Contact>()) {
diff --git a/common/domain/propertyregistry.cpp b/common/domain/propertyregistry.cpp
index d929d68..00bbb1d 100644
--- a/common/domain/propertyregistry.cpp
+++ b/common/domain/propertyregistry.cpp
@@ -75,6 +75,12 @@ QVariant parseString<QList<QByteArray>>(const QString &s)
75} 75}
76 76
77template <> 77template <>
78QVariant parseString<QStringList>(const QString &s)
79{
80 return s.split(',');
81}
82
83template <>
78QVariant parseString<QDateTime>(const QString &s) 84QVariant parseString<QDateTime>(const QString &s)
79{ 85{
80 return QVariant::fromValue(QDateTime::fromString(s, Qt::ISODate)); 86 return QVariant::fromValue(QDateTime::fromString(s, Qt::ISODate));
diff --git a/common/domain/todo.fbs b/common/domain/todo.fbs
new file mode 100644
index 0000000..b448cae
--- /dev/null
+++ b/common/domain/todo.fbs
@@ -0,0 +1,18 @@
1namespace Sink.ApplicationDomain.Buffer;
2
3table Todo {
4 uid:string;
5 summary:string;
6 description:string;
7 completedDate:string;
8 dueDate:string;
9 startDate:string;
10 status:string;
11 priority:int;
12 categories:[string];
13 ical:string;
14 calendar:string;
15}
16
17root_type Todo;
18file_identifier "AKFB";
diff --git a/common/domain/typeimplementations.cpp b/common/domain/typeimplementations.cpp
index 615c8e8..b584138 100644
--- a/common/domain/typeimplementations.cpp
+++ b/common/domain/typeimplementations.cpp
@@ -67,6 +67,10 @@ typedef IndexConfig<Event,
67 ValueIndex<Event::Uid> 67 ValueIndex<Event::Uid>
68 > EventIndexConfig; 68 > EventIndexConfig;
69 69
70typedef IndexConfig<Todo,
71 ValueIndex<Todo::Uid>
72 > TodoIndexConfig;
73
70typedef IndexConfig<Calendar, 74typedef IndexConfig<Calendar,
71 ValueIndex<Calendar::Name> 75 ValueIndex<Calendar::Name>
72 > CalendarIndexConfig; 76 > CalendarIndexConfig;
@@ -218,6 +222,37 @@ void TypeImplementation<Event>::configure(IndexPropertyMapper &)
218} 222}
219 223
220 224
225void TypeImplementation<Todo>::configure(TypeIndex &index)
226{
227 TodoIndexConfig::configure(index);
228}
229
230QMap<QByteArray, int> TypeImplementation<Todo>::typeDatabases()
231{
232 return merge(QMap<QByteArray, int>{{QByteArray{Todo::name} + ".main", 0}}, TodoIndexConfig::databases());
233}
234
235void TypeImplementation<Todo>::configure(PropertyMapper &propertyMapper)
236{
237 SINK_REGISTER_SERIALIZER(propertyMapper, Todo, Uid, uid);
238 SINK_REGISTER_SERIALIZER(propertyMapper, Todo, Summary, summary);
239 SINK_REGISTER_SERIALIZER(propertyMapper, Todo, Description, description);
240 SINK_REGISTER_SERIALIZER(propertyMapper, Todo, CompletedDate, completedDate);
241 SINK_REGISTER_SERIALIZER(propertyMapper, Todo, DueDate, dueDate);
242 SINK_REGISTER_SERIALIZER(propertyMapper, Todo, StartDate, startDate);
243 SINK_REGISTER_SERIALIZER(propertyMapper, Todo, Status, status);
244 SINK_REGISTER_SERIALIZER(propertyMapper, Todo, Priority, priority);
245 SINK_REGISTER_SERIALIZER(propertyMapper, Todo, Categories, categories);
246 SINK_REGISTER_SERIALIZER(propertyMapper, Todo, Ical, ical);
247 SINK_REGISTER_SERIALIZER(propertyMapper, Todo, Calendar, calendar);
248}
249
250void TypeImplementation<Todo>::configure(IndexPropertyMapper &)
251{
252
253}
254
255
221void TypeImplementation<Calendar>::configure(TypeIndex &index) 256void TypeImplementation<Calendar>::configure(TypeIndex &index)
222{ 257{
223 CalendarIndexConfig::configure(index); 258 CalendarIndexConfig::configure(index);
diff --git a/common/domain/typeimplementations.h b/common/domain/typeimplementations.h
index 672e83a..dea7426 100644
--- a/common/domain/typeimplementations.h
+++ b/common/domain/typeimplementations.h
@@ -24,6 +24,7 @@
24#include "mail_generated.h" 24#include "mail_generated.h"
25#include "folder_generated.h" 25#include "folder_generated.h"
26#include "event_generated.h" 26#include "event_generated.h"
27#include "todo_generated.h"
27#include "calendar_generated.h" 28#include "calendar_generated.h"
28#include "contact_generated.h" 29#include "contact_generated.h"
29#include "addressbook_generated.h" 30#include "addressbook_generated.h"
@@ -97,6 +98,17 @@ public:
97}; 98};
98 99
99template<> 100template<>
101class SINK_EXPORT TypeImplementation<Sink::ApplicationDomain::Todo> {
102public:
103 typedef Sink::ApplicationDomain::Buffer::Todo Buffer;
104 typedef Sink::ApplicationDomain::Buffer::EventBuilder BufferBuilder;
105 static void configure(TypeIndex &);
106 static void configure(PropertyMapper &);
107 static void configure(IndexPropertyMapper &indexPropertyMapper);
108 static QMap<QByteArray, int> typeDatabases();
109};
110
111template<>
100class SINK_EXPORT TypeImplementation<Sink::ApplicationDomain::Calendar> { 112class SINK_EXPORT TypeImplementation<Sink::ApplicationDomain::Calendar> {
101public: 113public:
102 typedef Sink::ApplicationDomain::Buffer::Calendar Buffer; 114 typedef Sink::ApplicationDomain::Buffer::Calendar Buffer;
diff --git a/common/propertymapper.cpp b/common/propertymapper.cpp
index 7c313cc..f9f9c9b 100644
--- a/common/propertymapper.cpp
+++ b/common/propertymapper.cpp
@@ -82,6 +82,21 @@ flatbuffers::uoffset_t variantToProperty<QByteArrayList>(const QVariant &propert
82} 82}
83 83
84template <> 84template <>
85flatbuffers::uoffset_t variantToProperty<QStringList>(const QVariant &property, flatbuffers::FlatBufferBuilder &fbb)
86{
87 if (property.isValid()) {
88 const auto list = property.value<QStringList>();
89 std::vector<flatbuffers::Offset<flatbuffers::String>> vector;
90 for (const auto &value : list) {
91 auto offset = fbb.CreateString(value.toStdString());
92 vector.push_back(offset);
93 }
94 return fbb.CreateVector(vector).o;
95 }
96 return 0;
97}
98
99template <>
85flatbuffers::uoffset_t variantToProperty<Sink::ApplicationDomain::Mail::Contact>(const QVariant &property, flatbuffers::FlatBufferBuilder &fbb) 100flatbuffers::uoffset_t variantToProperty<Sink::ApplicationDomain::Mail::Contact>(const QVariant &property, flatbuffers::FlatBufferBuilder &fbb)
86{ 101{
87 if (property.isValid()) { 102 if (property.isValid()) {
@@ -187,6 +202,21 @@ QVariant propertyToVariant<QByteArrayList>(const flatbuffers::Vector<flatbuffers
187} 202}
188 203
189template <> 204template <>
205QVariant propertyToVariant<QStringList>(const flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>> *property)
206{
207 if (property) {
208 QStringList list;
209 for (auto it = property->begin(); it != property->end();) {
210 // We have to copy the memory, otherwise it would become eventually invalid
211 list << QString::fromStdString((*it)->str());
212 it.operator++();
213 }
214 return QVariant::fromValue(list);
215 }
216 return QVariant();
217}
218
219template <>
190QVariant propertyToVariant<Sink::ApplicationDomain::Mail::Contact>(const Sink::ApplicationDomain::Buffer::MailContact *property) 220QVariant propertyToVariant<Sink::ApplicationDomain::Mail::Contact>(const Sink::ApplicationDomain::Buffer::MailContact *property)
191{ 221{
192 if (property) { 222 if (property) {
@@ -232,6 +262,12 @@ QVariant propertyToVariant<bool>(uint8_t property)
232} 262}
233 263
234template <> 264template <>
265QVariant propertyToVariant<int>(uint8_t property)
266{
267 return static_cast<int>(property);
268}
269
270template <>
235QVariant propertyToVariant<QDateTime>(const flatbuffers::String *property) 271QVariant propertyToVariant<QDateTime>(const flatbuffers::String *property)
236{ 272{
237 if (property) { 273 if (property) {
diff --git a/common/propertymapper.h b/common/propertymapper.h
index fd24278..49224fa 100644
--- a/common/propertymapper.h
+++ b/common/propertymapper.h
@@ -131,6 +131,14 @@ private:
131 } 131 }
132 132
133 template <typename T, typename BufferBuilder> 133 template <typename T, typename BufferBuilder>
134 void addWriteMapping(void (BufferBuilder::*f)(int))
135 {
136 addWriteMapping(T::name, [f](const QVariant &value, flatbuffers::FlatBufferBuilder &fbb) -> std::function<void(void *builder)> {
137 return [value, f](void *builder) { (static_cast<BufferBuilder*>(builder)->*f)(value.value<typename T::Type>()); };
138 });
139 }
140
141 template <typename T, typename BufferBuilder>
134 void addWriteMapping(void (BufferBuilder::*f)(bool)) 142 void addWriteMapping(void (BufferBuilder::*f)(bool))
135 { 143 {
136 addWriteMapping(T::name, [f](const QVariant &value, flatbuffers::FlatBufferBuilder &fbb) -> std::function<void(void *builder)> { 144 addWriteMapping(T::name, [f](const QVariant &value, flatbuffers::FlatBufferBuilder &fbb) -> std::function<void(void *builder)> {
diff --git a/common/todopreprocessor.cpp b/common/todopreprocessor.cpp
new file mode 100644
index 0000000..fe99953
--- /dev/null
+++ b/common/todopreprocessor.cpp
@@ -0,0 +1,67 @@
1/*
2 * Copyright (C) 2018 Christian Mollekopf <chrigi_1@fastmail.fm>
3 * Copyright (C) 2018 Rémi Nicole <minijackson@riseup.net>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the
17 * Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21#include "todopreprocessor.h"
22
23#include <KCalCore/ICalFormat>
24
25void TodoPropertyExtractor::updatedIndexedProperties(Todo &todo, const QByteArray &rawIcal)
26{
27 auto incidence = KCalCore::ICalFormat().readIncidence(rawIcal);
28
29 if(!incidence) {
30 SinkWarning() << "Invalid ICal to process, ignoring...";
31 return;
32 }
33
34 if(incidence->type() != KCalCore::IncidenceBase::IncidenceType::TypeTodo) {
35 SinkWarning() << "ICal to process is not of type `Todo`, ignoring...";
36 return;
37 }
38
39 auto icalTodo = dynamic_cast<const KCalCore::Todo *>(incidence.data());
40 // Should be guaranteed by the incidence->type() condition above.
41 Q_ASSERT(icalTodo);
42
43 SinkTrace() << "Extracting properties for todo:" << icalTodo->summary();
44
45 todo.setExtractedUid(icalTodo->uid());
46 todo.setExtractedSummary(icalTodo->summary());
47 todo.setExtractedDescription(icalTodo->description());
48
49 // Sets invalid QDateTime if not defined
50 todo.setExtractedCompletedDate(icalTodo->completed());
51 todo.setExtractedDueDate(icalTodo->dtDue());
52 todo.setExtractedStartDate(icalTodo->dtStart());
53
54 todo.setExtractedStatus(icalTodo->customStatus());
55 todo.setExtractedPriority(icalTodo->priority());
56 todo.setExtractedCategories(icalTodo->categories());
57}
58
59void TodoPropertyExtractor::newEntity(Todo &todo)
60{
61 updatedIndexedProperties(todo, todo.getIcal());
62}
63
64void TodoPropertyExtractor::modifiedEntity(const Todo &oldTodo, Todo &newTodo)
65{
66 updatedIndexedProperties(newTodo, newTodo.getIcal());
67}
diff --git a/common/todopreprocessor.h b/common/todopreprocessor.h
new file mode 100644
index 0000000..ccb9f1a
--- /dev/null
+++ b/common/todopreprocessor.h
@@ -0,0 +1,35 @@
1/*
2 * Copyright (C) 2018 Christian Mollekopf <chrigi_1@fastmail.fm>
3 * Copyright (C) 2018 Rémi Nicole <minijackson@riseup.net>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the
17 * Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21#include "pipeline.h"
22#include "sink_export.h"
23
24class SINK_EXPORT TodoPropertyExtractor : public Sink::EntityPreprocessor<Sink::ApplicationDomain::Todo>
25{
26 using Todo = Sink::ApplicationDomain::Todo;
27
28public:
29 virtual ~TodoPropertyExtractor() {}
30 virtual void newEntity(Todo &todo) Q_DECL_OVERRIDE;
31 virtual void modifiedEntity(const Todo &oldTodo, Todo &newTodo) Q_DECL_OVERRIDE;
32
33private:
34 static void updatedIndexedProperties(Todo &todo, const QByteArray &rawIcal);
35};