Commit 0b0fa901 authored by Volker Krause's avatar Volker Krause
Browse files

Also consider KCalendarCore::Event properties for extractor selection

So far this was only looking at Calendar-level properties, which isn't
enough e.g. for reliably identifying RegioJet ical attachments.
parent 5064cb93
......@@ -522,7 +522,10 @@ void ExtractorEnginePrivate::determineExtractors()
m_repo.extractorsForPass(m_pass.get(), m_extractors);
#ifdef HAVE_KCAL
} else if (m_calendar) {
m_repo.extractorsForCalendar(m_calendar, m_extractors);
m_repo.extractorsForCalendar(m_calendar.get(), m_extractors);
for (const auto &event : m_calendar->events()) {
m_repo.extractorsForEvent(event.get(), m_extractors);
}
#endif
}
if (m_mimeContext) {
......
......@@ -25,6 +25,7 @@
#ifdef HAVE_KCAL
#include <KCalendarCore/Calendar>
#include <KCalendarCore/Event>
#endif
#include <KMime/Content>
......@@ -35,6 +36,7 @@
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QMetaProperty>
#include <QStandardPaths>
using namespace KItinerary;
......@@ -208,9 +210,8 @@ void ExtractorRepository::extractorsForBarcode(const QString &code, std::vector<
}
#ifdef HAVE_KCAL
void ExtractorRepository::extractorsForCalendar(const QSharedPointer<KCalendarCore::Calendar> &cal, std::vector<Extractor> &extractors) const
void ExtractorRepository::extractorsForCalendar(const KCalendarCore::Calendar *cal, std::vector<Extractor> &extractors) const
{
std::vector<Extractor> v;
for (auto it = d->m_extractors.begin(), end = d->m_extractors.end(); it != end; ++it) {
for (const auto &filter : (*it).filters()) {
if (filter.type() != ExtractorInput::ICal) {
......@@ -225,6 +226,28 @@ void ExtractorRepository::extractorsForCalendar(const QSharedPointer<KCalendarCo
}
}
}
void ExtractorRepository::extractorsForEvent(const KCalendarCore::Event *event, std::vector<Extractor> &extractors) const
{
for (auto it = d->m_extractors.begin(), end = d->m_extractors.end(); it != end; ++it) {
for (const auto &filter : (*it).filters()) {
if (filter.type() != ExtractorInput::ICal) {
continue;
}
const auto propIdx = KCalendarCore::Event::staticMetaObject.indexOfProperty(filter.fieldName().toUtf8().constData());
if (propIdx < 0) {
continue;
}
const auto prop = KCalendarCore::Event::staticMetaObject.property(propIdx);
const auto value = prop.readOnGadget(event);
if (filter.matches(value.toString())) {
ExtractorRepositoryPrivate::insertExtractor(*it, extractors);
break;
}
}
}
}
#endif
void ExtractorRepository::extractorsForContent(const QString &content, std::vector<Extractor> &extractors) const
......
......@@ -22,13 +22,12 @@
#include "kitinerary_export.h"
#include <QSharedPointer>
#include <memory>
#include <vector>
namespace KCalendarCore {
class Calendar;
class Event;
}
namespace KMime {
......@@ -41,6 +40,7 @@ class Pass;
class QJsonArray;
class QString;
class QStringList;
namespace KItinerary {
......@@ -76,7 +76,9 @@ public:
/** Finds matching extractors for the given barcode string. */
void extractorsForBarcode(const QString &code, std::vector<Extractor> &extractors) const;
/** Find matching extractors for the given iCal calendar. */
void extractorsForCalendar(const QSharedPointer<KCalendarCore::Calendar> &cal, std::vector<Extractor> &extractors) const;
void extractorsForCalendar(const KCalendarCore::Calendar *cal, std::vector<Extractor> &extractors) const;
/** Find matching extractors for the given iCal event. */
void extractorsForEvent(const KCalendarCore::Event *event, std::vector<Extractor> &extractors) const;
/** Find matching extractors for the given content. */
void extractorsForContent(const QString &content, std::vector<Extractor> &extractors) const;
/** Returns the extractor with the given identifier. */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment