From 90a8d33f7c17c802730fd9b978db0e32d28a7dff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Nicole?= Date: Sun, 6 May 2018 17:42:37 +0200 Subject: Implement Todo entity type Summary: Some notes: - Needed to specialize some flatbuffers related functions for serializing QStringList and int - Removed useless qWarnings in caldav test - Rename EventSynchronizer -> CalDAVSynchronizer since it also synchronizes Calendars and Todos (and more to come!) Reviewers: cmollekopf Tags: #sink Differential Revision: https://phabricator.kde.org/D12695 --- common/todopreprocessor.cpp | 67 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 common/todopreprocessor.cpp (limited to 'common/todopreprocessor.cpp') 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()); +} -- cgit v1.2.3