Commit 40d1e469 authored by Daniel Vrátil's avatar Daniel Vrátil 🤖

Merge duplicated code, fix some bugs discovered by tests

parent 7145faa8
...@@ -145,23 +145,21 @@ const QMultiHash<QDate, CalendarEvents::EventData> &EventDataVisitor::results() ...@@ -145,23 +145,21 @@ const QMultiHash<QDate, CalendarEvents::EventData> &EventDataVisitor::results()
return mResults; return mResults;
} }
bool EventDataVisitor::visit(const KCalCore::Incidence::Ptr &incidence,
bool EventDataVisitor::visit(const KCalCore::Event::Ptr &event) CalendarEvents::EventData::EventType type)
{ {
CalendarEvents::EventData data = incidenceData(event); CalendarEvents::EventData data = incidenceData(incidence);
data.setEventType(CalendarEvents::EventData::Event); data.setEventType(type);
if (event->recurs()) { if (incidence->recurs()) {
bool ok = false; bool ok = false;
const auto list = explodeIncidenceOccurences(data, event, ok); const auto list = explodeIncidenceOccurences(data, incidence, ok);
if (ok) { if (ok) {
for (const auto &data : list) { for (const auto &data : list) {
mResults.insert(data.startDateTime().date(), data); mResults.insert(data.startDateTime().date(), data);
} }
} }
return ok; return ok;
} else if (isInRange(event->dtStart().date(), event->dtEnd().date())) { } else if (isInRange(data.startDateTime().date(), data.endDateTime().date())) {
data.setStartDateTime(event->dtStart().dateTime());
data.setEndDateTime(event->dtEnd().dateTime());
mResults.insert(data.startDateTime().date(), data); mResults.insert(data.startDateTime().date(), data);
return true; return true;
} }
...@@ -169,27 +167,14 @@ bool EventDataVisitor::visit(const KCalCore::Event::Ptr &event) ...@@ -169,27 +167,14 @@ bool EventDataVisitor::visit(const KCalCore::Event::Ptr &event)
return false; return false;
} }
bool EventDataVisitor::visit(const KCalCore::Todo::Ptr &todo) bool EventDataVisitor::visit(const KCalCore::Event::Ptr &event)
{ {
CalendarEvents::EventData data = incidenceData(todo); return visit(event, CalendarEvents::EventData::Event);
data.setEventType(CalendarEvents::EventData::Todo); }
if (todo->recurs()) {
bool ok = false;
const auto list = explodeIncidenceOccurences(data, todo, ok);
if (ok) {
for (const auto &data : list) {
mResults.insert(data.startDateTime().date(), data);
}
}
return ok;
} else if (isInRange(todo->dtStart().date(), todo->dtDue().date())) {
data.setStartDateTime(todo->dtStart().dateTime());
data.setEndDateTime(todo->dtDue().dateTime());
mResults.insert(data.startDateTime().date(), data);
return true;
}
return false; bool EventDataVisitor::visit(const KCalCore::Todo::Ptr &todo)
{
return visit(todo, CalendarEvents::EventData::Todo);
} }
CalendarEvents::EventData EventDataVisitor::incidenceData(const KCalCore::Incidence::Ptr &incidence) const CalendarEvents::EventData EventDataVisitor::incidenceData(const KCalCore::Incidence::Ptr &incidence) const
...@@ -200,6 +185,8 @@ CalendarEvents::EventData EventDataVisitor::incidenceData(const KCalCore::Incide ...@@ -200,6 +185,8 @@ CalendarEvents::EventData EventDataVisitor::incidenceData(const KCalCore::Incide
data.setIsAllDay(incidence->allDay()); data.setIsAllDay(incidence->allDay());
data.setIsMinor(false); data.setIsMinor(false);
data.setUid(generateUid(incidence)); data.setUid(generateUid(incidence));
data.setStartDateTime(incidence->dtStart().dateTime());
data.setEndDateTime(incidence->dateTime(KCalCore::Incidence::RoleEnd).dateTime());
// TODO: Set calendar color // TODO: Set calendar color
return data; return data;
} }
...@@ -216,10 +203,20 @@ const QStringList &EventDataIdVisitor::results() const ...@@ -216,10 +203,20 @@ const QStringList &EventDataIdVisitor::results() const
bool EventDataIdVisitor::visit(const KCalCore::Event::Ptr &event) bool EventDataIdVisitor::visit(const KCalCore::Event::Ptr &event)
{ {
if (event->recurs()) { return visit(event.staticCast<KCalCore::Incidence>());
}
bool EventDataIdVisitor::visit(const KCalCore::Todo::Ptr &todo)
{
return visit(todo.staticCast<KCalCore::Incidence>());
}
bool EventDataIdVisitor::visit(const KCalCore::Incidence::Ptr& incidence)
{
if (incidence->recurs()) {
CalendarEvents::EventData ed; CalendarEvents::EventData ed;
bool ok = false; bool ok = false;
const auto list = explodeIncidenceOccurences(ed, event, ok); const auto list = explodeIncidenceOccurences(ed, incidence, ok);
if (ok) { if (ok) {
for (const auto &data : list) { for (const auto &data : list) {
mResults.push_back(data.uid()); mResults.push_back(data.uid());
...@@ -227,15 +224,7 @@ bool EventDataIdVisitor::visit(const KCalCore::Event::Ptr &event) ...@@ -227,15 +224,7 @@ bool EventDataIdVisitor::visit(const KCalCore::Event::Ptr &event)
} }
return ok; return ok;
} else { } else {
mResults.push_back(generateUid(event, event->recurrenceId())); mResults.push_back(generateUid(incidence, incidence->recurrenceId()));
} }
return true; return true;
} }
bool EventDataIdVisitor::visit(const KCalCore::Todo::Ptr &todo)
{
mResults.push_back(generateUid(todo, todo->recurrenceId()));
return true;
}
...@@ -70,6 +70,7 @@ protected: ...@@ -70,6 +70,7 @@ protected:
bool visit(const KCalCore::Journal::Ptr &) Q_DECL_OVERRIDE { return false; } bool visit(const KCalCore::Journal::Ptr &) Q_DECL_OVERRIDE { return false; }
bool visit(const KCalCore::FreeBusy::Ptr &) Q_DECL_OVERRIDE { return false; } bool visit(const KCalCore::FreeBusy::Ptr &) Q_DECL_OVERRIDE { return false; }
private: private:
bool visit(const KCalCore::Incidence::Ptr &incidence, CalendarEvents::EventData::EventType eventType);
CalendarEvents::EventData incidenceData(const KCalCore::Incidence::Ptr &incidence) const; CalendarEvents::EventData incidenceData(const KCalCore::Incidence::Ptr &incidence) const;
QMultiHash<QDate, CalendarEvents::EventData> mResults; QMultiHash<QDate, CalendarEvents::EventData> mResults;
...@@ -91,6 +92,8 @@ protected: ...@@ -91,6 +92,8 @@ protected:
bool visit(const KCalCore::FreeBusy::Ptr &) Q_DECL_OVERRIDE { return false; } bool visit(const KCalCore::FreeBusy::Ptr &) Q_DECL_OVERRIDE { return false; }
private: private:
bool visit(const KCalCore::Incidence::Ptr &incidence);
QStringList mResults; QStringList mResults;
}; };
......
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