From 29695a1949c4f846f0d4ed21a400f3b864518ed1 Mon Sep 17 00:00:00 2001 From: Minijackson Date: Wed, 2 May 2018 16:44:11 +0200 Subject: Really add Todo entity type --- common/CMakeLists.txt | 2 + common/domain/applicationdomaintype.cpp | 13 +++++++ common/domain/applicationdomaintype.h | 17 +++++++++ common/domain/applicationdomaintype_p.h | 2 + common/domain/propertyregistry.cpp | 6 +++ common/domain/todo.fbs | 18 +++++++++ common/domain/typeimplementations.cpp | 35 +++++++++++++++++ common/domain/typeimplementations.h | 12 ++++++ common/propertymapper.cpp | 36 ++++++++++++++++++ common/propertymapper.h | 8 ++++ common/todopreprocessor.cpp | 67 +++++++++++++++++++++++++++++++++ common/todopreprocessor.h | 35 +++++++++++++++++ 12 files changed, 251 insertions(+) create mode 100644 common/domain/todo.fbs create mode 100644 common/todopreprocessor.cpp create mode 100644 common/todopreprocessor.h 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 contactpreprocessor.cpp mailpreprocessor.cpp eventpreprocessor.cpp + todopreprocessor.cpp specialpurposepreprocessor.cpp datastorequery.cpp storage/entitystore.cpp @@ -105,6 +106,7 @@ generate_flatbuffers( domain/contact domain/addressbook domain/event + domain/todo domain/calendar domain/mail 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); SINK_REGISTER_PROPERTY(Event, Ical); SINK_REGISTER_PROPERTY(Event, Calendar); +SINK_REGISTER_ENTITY(Todo); +SINK_REGISTER_PROPERTY(Todo, Uid); +SINK_REGISTER_PROPERTY(Todo, Summary); +SINK_REGISTER_PROPERTY(Todo, Description); +SINK_REGISTER_PROPERTY(Todo, CompletedDate); +SINK_REGISTER_PROPERTY(Todo, DueDate); +SINK_REGISTER_PROPERTY(Todo, StartDate); +SINK_REGISTER_PROPERTY(Todo, Status); +SINK_REGISTER_PROPERTY(Todo, Priority); +SINK_REGISTER_PROPERTY(Todo, Categories); +SINK_REGISTER_PROPERTY(Todo, Ical); +SINK_REGISTER_PROPERTY(Todo, Calendar); + SINK_REGISTER_ENTITY(Calendar); SINK_REGISTER_PROPERTY(Calendar, Name); 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 { struct SINK_EXPORT Todo : public Entity { SINK_ENTITY(Todo, todo); + SINK_EXTRACTED_PROPERTY(QString, Uid, uid); + SINK_EXTRACTED_PROPERTY(QString, Summary, summary); + SINK_EXTRACTED_PROPERTY(QString, Description, description); + SINK_EXTRACTED_PROPERTY(QDateTime, CompletedDate, completedDate); + SINK_EXTRACTED_PROPERTY(QDateTime, DueDate, dueDate); + SINK_EXTRACTED_PROPERTY(QDateTime, StartDate, startDate); + SINK_EXTRACTED_PROPERTY(QString, Status, status); + SINK_EXTRACTED_PROPERTY(int, Priority, priority); + SINK_EXTRACTED_PROPERTY(QStringList, Categories, categories); + SINK_PROPERTY(QByteArray, Ical, ical); + SINK_REFERENCE_PROPERTY(Calendar, Calendar, calendar); }; struct SINK_EXPORT Folder : public Entity { @@ -506,6 +517,11 @@ namespace Event { static constexpr const char *calendar = "calendar"; static constexpr const char *storage = "event.storage"; }; +namespace Todo { + static constexpr const char *todo = "todo"; + static constexpr const char *calendar = "calendar"; + static constexpr const char *storage = "todo.storage"; +}; }; namespace SpecialPurpose { @@ -558,6 +574,7 @@ class SINK_EXPORT TypeImplementation; REGISTER_TYPE(Sink::ApplicationDomain::Contact) \ REGISTER_TYPE(Sink::ApplicationDomain::Addressbook) \ REGISTER_TYPE(Sink::ApplicationDomain::Event) \ + REGISTER_TYPE(Sink::ApplicationDomain::Todo) \ REGISTER_TYPE(Sink::ApplicationDomain::Calendar) \ REGISTER_TYPE(Sink::ApplicationDomain::Mail) \ 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 { return Func{}(std::forward(args...)); } else if (type == Sink::ApplicationDomain::getTypeName()) { return Func{}(std::forward(args...)); + } else if (type == Sink::ApplicationDomain::getTypeName()) { + return Func{}(std::forward(args...)); } else if (type == Sink::ApplicationDomain::getTypeName()) { return Func{}(std::forward(args...)); } else if (type == Sink::ApplicationDomain::getTypeName()) { 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 @@ -74,6 +74,12 @@ QVariant parseString>(const QString &s) return QVariant::fromValue(result); } +template <> +QVariant parseString(const QString &s) +{ + return s.split(','); +} + template <> QVariant parseString(const QString &s) { 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 @@ +namespace Sink.ApplicationDomain.Buffer; + +table Todo { + uid:string; + summary:string; + description:string; + completedDate:string; + dueDate:string; + startDate:string; + status:string; + priority:int; + categories:[string]; + ical:string; + calendar:string; +} + +root_type Todo; +file_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 > EventIndexConfig; +typedef IndexConfig + > TodoIndexConfig; + typedef IndexConfig > CalendarIndexConfig; @@ -218,6 +222,37 @@ void TypeImplementation::configure(IndexPropertyMapper &) } +void TypeImplementation::configure(TypeIndex &index) +{ + TodoIndexConfig::configure(index); +} + +QMap TypeImplementation::typeDatabases() +{ + return merge(QMap{{QByteArray{Todo::name} + ".main", 0}}, TodoIndexConfig::databases()); +} + +void TypeImplementation::configure(PropertyMapper &propertyMapper) +{ + SINK_REGISTER_SERIALIZER(propertyMapper, Todo, Uid, uid); + SINK_REGISTER_SERIALIZER(propertyMapper, Todo, Summary, summary); + SINK_REGISTER_SERIALIZER(propertyMapper, Todo, Description, description); + SINK_REGISTER_SERIALIZER(propertyMapper, Todo, CompletedDate, completedDate); + SINK_REGISTER_SERIALIZER(propertyMapper, Todo, DueDate, dueDate); + SINK_REGISTER_SERIALIZER(propertyMapper, Todo, StartDate, startDate); + SINK_REGISTER_SERIALIZER(propertyMapper, Todo, Status, status); + SINK_REGISTER_SERIALIZER(propertyMapper, Todo, Priority, priority); + SINK_REGISTER_SERIALIZER(propertyMapper, Todo, Categories, categories); + SINK_REGISTER_SERIALIZER(propertyMapper, Todo, Ical, ical); + SINK_REGISTER_SERIALIZER(propertyMapper, Todo, Calendar, calendar); +} + +void TypeImplementation::configure(IndexPropertyMapper &) +{ + +} + + void TypeImplementation::configure(TypeIndex &index) { 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 @@ #include "mail_generated.h" #include "folder_generated.h" #include "event_generated.h" +#include "todo_generated.h" #include "calendar_generated.h" #include "contact_generated.h" #include "addressbook_generated.h" @@ -96,6 +97,17 @@ public: static QMap typeDatabases(); }; +template<> +class SINK_EXPORT TypeImplementation { +public: + typedef Sink::ApplicationDomain::Buffer::Todo Buffer; + typedef Sink::ApplicationDomain::Buffer::EventBuilder BufferBuilder; + static void configure(TypeIndex &); + static void configure(PropertyMapper &); + static void configure(IndexPropertyMapper &indexPropertyMapper); + static QMap typeDatabases(); +}; + template<> class SINK_EXPORT TypeImplementation { public: diff --git a/common/propertymapper.cpp b/common/propertymapper.cpp index 7c313cc..f9f9c9b 100644 --- a/common/propertymapper.cpp +++ b/common/propertymapper.cpp @@ -81,6 +81,21 @@ flatbuffers::uoffset_t variantToProperty(const QVariant &propert return 0; } +template <> +flatbuffers::uoffset_t variantToProperty(const QVariant &property, flatbuffers::FlatBufferBuilder &fbb) +{ + if (property.isValid()) { + const auto list = property.value(); + std::vector> vector; + for (const auto &value : list) { + auto offset = fbb.CreateString(value.toStdString()); + vector.push_back(offset); + } + return fbb.CreateVector(vector).o; + } + return 0; +} + template <> flatbuffers::uoffset_t variantToProperty(const QVariant &property, flatbuffers::FlatBufferBuilder &fbb) { @@ -186,6 +201,21 @@ QVariant propertyToVariant(const flatbuffers::Vector +QVariant propertyToVariant(const flatbuffers::Vector> *property) +{ + if (property) { + QStringList list; + for (auto it = property->begin(); it != property->end();) { + // We have to copy the memory, otherwise it would become eventually invalid + list << QString::fromStdString((*it)->str()); + it.operator++(); + } + return QVariant::fromValue(list); + } + return QVariant(); +} + template <> QVariant propertyToVariant(const Sink::ApplicationDomain::Buffer::MailContact *property) { @@ -231,6 +261,12 @@ QVariant propertyToVariant(uint8_t property) return static_cast(property); } +template <> +QVariant propertyToVariant(uint8_t property) +{ + return static_cast(property); +} + template <> QVariant propertyToVariant(const flatbuffers::String *property) { diff --git a/common/propertymapper.h b/common/propertymapper.h index fd24278..49224fa 100644 --- a/common/propertymapper.h +++ b/common/propertymapper.h @@ -130,6 +130,14 @@ private: }); } + template + void addWriteMapping(void (BufferBuilder::*f)(int)) + { + addWriteMapping(T::name, [f](const QVariant &value, flatbuffers::FlatBufferBuilder &fbb) -> std::function { + return [value, f](void *builder) { (static_cast(builder)->*f)(value.value()); }; + }); + } + template void addWriteMapping(void (BufferBuilder::*f)(bool)) { 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 @@ +/* + * Copyright (C) 2018 Christian Mollekopf + * Copyright (C) 2018 Rémi Nicole + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "todopreprocessor.h" + +#include + +void TodoPropertyExtractor::updatedIndexedProperties(Todo &todo, const QByteArray &rawIcal) +{ + auto incidence = KCalCore::ICalFormat().readIncidence(rawIcal); + + if(!incidence) { + SinkWarning() << "Invalid ICal to process, ignoring..."; + return; + } + + if(incidence->type() != KCalCore::IncidenceBase::IncidenceType::TypeTodo) { + SinkWarning() << "ICal to process is not of type `Todo`, ignoring..."; + return; + } + + auto icalTodo = dynamic_cast(incidence.data()); + // Should be guaranteed by the incidence->type() condition above. + Q_ASSERT(icalTodo); + + SinkTrace() << "Extracting properties for todo:" << icalTodo->summary(); + + todo.setExtractedUid(icalTodo->uid()); + todo.setExtractedSummary(icalTodo->summary()); + todo.setExtractedDescription(icalTodo->description()); + + // Sets invalid QDateTime if not defined + todo.setExtractedCompletedDate(icalTodo->completed()); + todo.setExtractedDueDate(icalTodo->dtDue()); + todo.setExtractedStartDate(icalTodo->dtStart()); + + todo.setExtractedStatus(icalTodo->customStatus()); + todo.setExtractedPriority(icalTodo->priority()); + todo.setExtractedCategories(icalTodo->categories()); +} + +void TodoPropertyExtractor::newEntity(Todo &todo) +{ + updatedIndexedProperties(todo, todo.getIcal()); +} + +void TodoPropertyExtractor::modifiedEntity(const Todo &oldTodo, Todo &newTodo) +{ + updatedIndexedProperties(newTodo, newTodo.getIcal()); +} 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 @@ +/* + * Copyright (C) 2018 Christian Mollekopf + * Copyright (C) 2018 Rémi Nicole + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "pipeline.h" +#include "sink_export.h" + +class SINK_EXPORT TodoPropertyExtractor : public Sink::EntityPreprocessor +{ + using Todo = Sink::ApplicationDomain::Todo; + +public: + virtual ~TodoPropertyExtractor() {} + virtual void newEntity(Todo &todo) Q_DECL_OVERRIDE; + virtual void modifiedEntity(const Todo &oldTodo, Todo &newTodo) Q_DECL_OVERRIDE; + +private: + static void updatedIndexedProperties(Todo &todo, const QByteArray &rawIcal); +}; -- cgit v1.2.3