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/eventpreprocessor.cpp | 60 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 common/eventpreprocessor.cpp (limited to 'common/eventpreprocessor.cpp') 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()); +} -- cgit v1.2.3