From cd81aed814286887911d99648d62bbb3c63e404c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Nicole?= Date: Fri, 13 Apr 2018 11:51:18 +0200 Subject: Change most of Event's properties to extracted properties Summary: Fix T8485 Reviewers: cmollekopf Reviewed By: cmollekopf Tags: #sink Maniphest Tasks: T8485 Differential Revision: https://phabricator.kde.org/D12106 --- common/CMakeLists.txt | 2 ++ common/domain/applicationdomaintype.h | 10 +++--- common/eventpreprocessor.cpp | 60 +++++++++++++++++++++++++++++++++++ common/eventpreprocessor.h | 35 ++++++++++++++++++++ 4 files changed, 102 insertions(+), 5 deletions(-) create mode 100644 common/eventpreprocessor.cpp create mode 100644 common/eventpreprocessor.h (limited to 'common') diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 9c4d4f1..51145fd 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -70,6 +70,7 @@ set(command_SRCS synchronizerstore.cpp contactpreprocessor.cpp mailpreprocessor.cpp + eventpreprocessor.cpp specialpurposepreprocessor.cpp datastorequery.cpp storage/entitystore.cpp @@ -130,6 +131,7 @@ PRIVATE Qt5::Gui KF5::Mime KF5::Contacts + KF5::CalendarCore ${XAPIAN_LIBRARIES} ) install(TARGETS ${PROJECT_NAME} diff --git a/common/domain/applicationdomaintype.h b/common/domain/applicationdomaintype.h index 43d385c..f3c954a 100644 --- a/common/domain/applicationdomaintype.h +++ b/common/domain/applicationdomaintype.h @@ -396,11 +396,11 @@ struct SINK_EXPORT Calendar : public Entity { struct SINK_EXPORT Event : public Entity { SINK_ENTITY(Event, event); - SINK_PROPERTY(QString, Uid, uid); - SINK_PROPERTY(QString, Summary, summary); - SINK_PROPERTY(QString, Description, description); - SINK_PROPERTY(QDateTime, StartTime, startTime); - SINK_PROPERTY(QDateTime, EndTime, endTime); + SINK_EXTRACTED_PROPERTY(QString, Uid, uid); + SINK_EXTRACTED_PROPERTY(QString, Summary, summary); + SINK_EXTRACTED_PROPERTY(QString, Description, description); + SINK_EXTRACTED_PROPERTY(QDateTime, StartTime, startTime); + SINK_EXTRACTED_PROPERTY(QDateTime, EndTime, endTime); SINK_PROPERTY(QByteArray, Ical, ical); SINK_REFERENCE_PROPERTY(Calendar, Calendar, calendar); }; diff --git a/common/eventpreprocessor.cpp b/common/eventpreprocessor.cpp new file mode 100644 index 0000000..e087563 --- /dev/null +++ b/common/eventpreprocessor.cpp @@ -0,0 +1,60 @@ +/* + * 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 "eventpreprocessor.h" + +#include + +void EventPropertyExtractor::updatedIndexedProperties(Event &event, const QByteArray &rawIcal) +{ + auto incidence = KCalCore::ICalFormat().readIncidence(rawIcal); + + if(!incidence) { + SinkWarning() << "Invalid ICal to process, ignoring..."; + return; + } + + if(incidence->type() != KCalCore::IncidenceBase::IncidenceType::TypeEvent) { + SinkWarning() << "ICal to process is not of type `Event`, ignoring..."; + return; + } + + auto icalEvent = dynamic_cast(incidence.data()); + // Should be guaranteed by the incidence->type() condition above. + Q_ASSERT(icalEvent); + + SinkTrace() << "Extracting properties for event:" << icalEvent->summary(); + + event.setExtractedUid(icalEvent->uid()); + event.setExtractedSummary(icalEvent->summary()); + event.setExtractedDescription(icalEvent->description()); + event.setExtractedStartTime(icalEvent->dtStart()); + event.setExtractedEndTime(icalEvent->dtEnd()); +} + +void EventPropertyExtractor::newEntity(Event &event) +{ + updatedIndexedProperties(event, event.getIcal()); +} + +void EventPropertyExtractor::modifiedEntity(const Event &oldEvent, Event &newEvent) +{ + updatedIndexedProperties(newEvent, newEvent.getIcal()); +} diff --git a/common/eventpreprocessor.h b/common/eventpreprocessor.h new file mode 100644 index 0000000..3fde8b2 --- /dev/null +++ b/common/eventpreprocessor.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 EventPropertyExtractor : public Sink::EntityPreprocessor +{ + using Event = Sink::ApplicationDomain::Event; + +public: + virtual ~EventPropertyExtractor() {} + virtual void newEntity(Event &event) Q_DECL_OVERRIDE; + virtual void modifiedEntity(const Event &oldEvent, Event &newEvent) Q_DECL_OVERRIDE; + +private: + static void updatedIndexedProperties(Event &event, const QByteArray &rawIcal); +}; -- cgit v1.2.3