diff --git a/framework/src/domain/controller.cpp b/framework/src/domain/controller.cpp index 5e9c43c7..62921822 100644 --- a/framework/src/domain/controller.cpp +++ b/framework/src/domain/controller.cpp @@ -1,192 +1,206 @@ /* Copyright (c) 2016 Christian Mollekopf This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "controller.h" #include #include #include #include #include #include using namespace Kube; ControllerState::ControllerState() : QObject() { QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership); } ControllerAction::ControllerAction() : ControllerState() { } void ControllerAction::execute() { emit triggered(); } void Controller::classBegin() { } void Controller::componentComplete() { init(); } void Controller::init() { } void Controller::clear() { auto meta = metaObject(); //We want to get the offset for this class, but clear the properties of all subclasses (thus staticMetaObject for the offset) for (auto i = staticMetaObject.propertyOffset(); i < meta->propertyCount(); i++) { auto property = meta->property(i); setProperty(property.name(), QVariant()); } for (const auto &p : dynamicPropertyNames()) { setProperty(p, QVariant()); } emit cleared(); } void Controller::run(const KAsync::Job &job) { auto jobToExec = job; jobToExec.onError([] (const KAsync::Error &error) { SinkWarningCtx(Sink::Log::Context{"controller"}) << "Error while executing job: " << error.errorMessage; }); //TODO handle error //TODO attach a log context to the execution that we can gather from the job? jobToExec.exec(); } static void traverse(const QStandardItemModel *model, const std::function &f) { auto root = model->invisibleRootItem(); for (int row = 0; row < root->rowCount(); row++) { if (!f(root->child(row, 0))) { return; } } } ListPropertyController::ListPropertyController(const QStringList &roles) : QObject(), mModel(new QStandardItemModel) { //Generate a set of roles for the names. We're not using any enum, so the actual role value doesn't matter. int role = Qt::UserRole + 1; mRoles.insert("id", role); role++; for (const auto &r : roles) { mRoles.insert(r, role); role++; } QHash roleNames; for (const auto r : mRoles.keys()) { roleNames.insert(mRoles[r], r.toLatin1()); } mModel->setItemRoleNames(roleNames); } void ListPropertyController::add(const QVariantMap &value) { auto item = new QStandardItem; auto id = QUuid::createUuid().toByteArray(); item->setData(id, mRoles["id"]); for (const auto &k : value.keys()) { item->setData(value.value(k), mRoles[k]); } mModel->appendRow(QList() << item); if (mModel->rowCount() <= 1) { emit emptyChanged(); } emit added(id, value); } void ListPropertyController::remove(const QByteArray &id) { auto root = mModel->invisibleRootItem(); const auto idRole = mRoles["id"]; for (int row = 0; row < root->rowCount(); row++) { if (root->child(row, 0)->data(idRole).toByteArray() == id) { root->removeRow(row); break; } } emit removed(id); if (mModel->rowCount() <= 0) { emit emptyChanged(); } } bool ListPropertyController::empty() const { return mModel->rowCount() == 0; } void ListPropertyController::clear() { mModel->clear(); } QAbstractItemModel *ListPropertyController::model() { QQmlEngine::setObjectOwnership(mModel.data(), QQmlEngine::CppOwnership); return mModel.data(); } void ListPropertyController::setValue(const QByteArray &id, const QString &key, const QVariant &value) { setValues(id, {{key, value}}); } +QByteArray ListPropertyController::findByProperty(const QByteArray &key, const QVariant &value) const +{ + QByteArray id; + const auto idRole = mRoles["id"]; + ::traverse(mModel.data(), [&] (QStandardItem *item) { + if (item->data(mRoles[key]) == value) { + id = item->data(idRole).toByteArray(); + return false; + } + return true; + }); + return id; +} + void ListPropertyController::setValues(const QByteArray &id, const QVariantMap &values) { const auto idRole = mRoles["id"]; ::traverse(mModel.data(), [&] (QStandardItem *item) { if (item->data(idRole).toByteArray() == id) { for (const auto &key : values.keys()) { item->setData(values.value(key), mRoles[key]); } return false; } return true; }); } void ListPropertyController::traverse(const std::function &f) { ::traverse(mModel.data(), [&] (QStandardItem *item) { QVariantMap map; for (const auto &key : mRoles.keys()) { map.insert(key, item->data(mRoles[key])); } f(map); return true; }); } diff --git a/framework/src/domain/controller.h b/framework/src/domain/controller.h index 062a6a1d..d5506ce8 100644 --- a/framework/src/domain/controller.h +++ b/framework/src/domain/controller.h @@ -1,159 +1,161 @@ /* Copyright (c) 2016 Christian Mollekopf This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #pragma once #include "kube_export.h" #include #include #include #include #include #include #define KUBE_CONTROLLER_PROPERTY(TYPE, NAME, LOWERCASENAME) \ public: Q_PROPERTY(TYPE LOWERCASENAME MEMBER m##NAME NOTIFY LOWERCASENAME##Changed) \ Q_SIGNALS: void LOWERCASENAME##Changed(); \ private: TYPE m##NAME; \ public: \ struct NAME { \ static constexpr const char *name = #LOWERCASENAME; \ typedef TYPE Type; \ }; \ void set##NAME(const TYPE &value) { setProperty(NAME::name, QVariant::fromValue(value)); } \ void clear##NAME() { setProperty(NAME::name, QVariant{}); } \ TYPE get##NAME() const { return m##NAME; } \ #define KUBE_CONTROLLER_ACTION(NAME) \ Q_PROPERTY (Kube::ControllerAction* NAME##Action READ NAME##Action CONSTANT) \ private: QScopedPointer action_##NAME; \ public: Kube::ControllerAction* NAME##Action() const { Q_ASSERT(action_##NAME); return action_##NAME.data(); } \ private slots: void NAME(); \ #define KUBE_CONTROLLER_LISTCONTROLLER(NAME) \ Q_PROPERTY (Kube::ListPropertyController* NAME READ NAME##Controller CONSTANT) \ private: QScopedPointer controller_##NAME; \ public: Kube::ListPropertyController* NAME##Controller() const { Q_ASSERT(controller_##NAME); return controller_##NAME.data(); } \ namespace Kube { class ControllerState : public QObject { Q_OBJECT Q_PROPERTY(bool enabled MEMBER mEnabled NOTIFY enabledChanged) public: ControllerState(); ~ControllerState() = default; void setEnabled(bool enabled) { setProperty("enabled", enabled); } signals: void enabledChanged(); private: bool mEnabled = false; }; class KUBE_EXPORT ControllerAction : public ControllerState { Q_OBJECT public: ControllerAction(); template ControllerAction(const typename QtPrivate::FunctionPointer::Object *obj, Func slot) : ControllerAction() { QObject::connect(this, &ControllerAction::triggered, obj, slot); } ~ControllerAction() = default; Q_INVOKABLE void execute(); signals: void triggered(); }; class Controller : public QObject, public QQmlParserStatus { Q_OBJECT Q_INTERFACES(QQmlParserStatus) public: Controller() = default; virtual ~Controller() = default; virtual void init(); void classBegin() override; void componentComplete() override; public slots: virtual void clear(); signals: void done(); void error(); void cleared(); protected: void run(const KAsync::Job &job); }; class KUBE_EXPORT ListPropertyController : public QObject { Q_OBJECT Q_PROPERTY(QAbstractItemModel* model READ model CONSTANT) Q_PROPERTY(bool empty READ empty NOTIFY emptyChanged) public: ListPropertyController(const QStringList &roles); Q_INVOKABLE virtual void add(const QVariantMap &value); Q_INVOKABLE virtual void remove(const QByteArray &id); Q_INVOKABLE void clear(); QAbstractItemModel *model(); void setValue(const QByteArray &id, const QString &key, const QVariant &); void setValues(const QByteArray &id, const QVariantMap &values); void traverse(const std::function &f); + QByteArray findByProperty(const QByteArray &key, const QVariant &) const; + template QList getList(const QString &property) { QList list; traverse([&] (const QVariantMap &map) { list << map[property].value(); }); return list; } bool empty() const; Q_SIGNALS: void added(QByteArray, QVariantMap); void removed(QByteArray); void emptyChanged(); protected: QScopedPointer mModel; private: QHash mRoles; }; } diff --git a/framework/src/domain/eventcontroller.cpp b/framework/src/domain/eventcontroller.cpp index eba88d3c..f50c5549 100644 --- a/framework/src/domain/eventcontroller.cpp +++ b/framework/src/domain/eventcontroller.cpp @@ -1,158 +1,206 @@ /* * Copyright (C) 2017 Michael Bohlender, * Copyright (C) 2018 Christian Mollekopf, * * 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 "eventcontroller.h" #include #include #include #include #include #include #include "eventoccurrencemodel.h" using namespace Sink::ApplicationDomain; +class AttendeeController : public Kube::ListPropertyController +{ + Q_OBJECT +public: + AttendeeController() : Kube::ListPropertyController{{"name", "email", "status"}} + { + } EventController::EventController() : Kube::Controller(), + controller_attendees{new AttendeeController}, action_save{new Kube::ControllerAction{this, &EventController::save}} { updateSaveAction(); } void EventController::save() { using namespace Sink; using namespace Sink::ApplicationDomain; const auto calendar = getCalendar(); if (!calendar) { qWarning() << "No calendar selected"; return; } const auto occurrenceVariant = getEventOccurrence(); if (occurrenceVariant.isValid()) { const auto occurrence = occurrenceVariant.value(); Sink::ApplicationDomain::Event event = *occurrence.domainObject; //Apply the changed properties on top of what's existing auto calcoreEvent = KCalCore::ICalFormat().readIncidence(event.getIcal()).dynamicCast(); if(!calcoreEvent) { SinkWarning() << "Invalid ICal to process, ignoring..."; return; } - calcoreEvent->setSummary(getSummary()); - calcoreEvent->setDescription(getDescription()); - calcoreEvent->setDtStart(getStart()); - calcoreEvent->setDtEnd(getEnd()); - calcoreEvent->setAllDay(getAllDay()); + saveToEvent(*calcoreEvent); event.setIcal(KCalCore::ICalFormat().toICalString(calcoreEvent).toUtf8()); event.setCalendar(*calendar); auto job = Store::modify(event) .then([&] (const KAsync::Error &error) { if (error) { SinkWarning() << "Failed to save the event: " << error; } emit done(); }); run(job); } else { Sink::ApplicationDomain::Event event(calendar->resourceInstanceIdentifier()); auto calcoreEvent = QSharedPointer::create(); calcoreEvent->setUid(QUuid::createUuid().toString()); - calcoreEvent->setSummary(getSummary()); - calcoreEvent->setDescription(getDescription()); - calcoreEvent->setLocation(getLocation()); - calcoreEvent->setDtStart(getStart()); - calcoreEvent->setDtEnd(getEnd()); - calcoreEvent->setAllDay(getAllDay()); + saveToEvent(*calcoreEvent); event.setIcal(KCalCore::ICalFormat().toICalString(calcoreEvent).toUtf8()); event.setCalendar(*calendar); auto job = Store::create(event) .then([&] (const KAsync::Error &error) { if (error) { SinkWarning() << "Failed to save the event: " << error; } emit done(); }); run(job); } } void EventController::updateSaveAction() { saveAction()->setEnabled(!getSummary().isEmpty()); } +static EventController::ParticipantStatus toStatus(KCalCore::Attendee::PartStat status) { + switch(status) { + case KCalCore::Attendee::Accepted: + return EventController::Accepted; + case KCalCore::Attendee::Declined: + return EventController::Declined; + case KCalCore::Attendee::NeedsAction: + default: + break; + } + return EventController::Unknown; +} + +static KCalCore::Attendee::PartStat fromStatus(EventController::ParticipantStatus status) { + switch(status) { + case EventController::Accepted: + return KCalCore::Attendee::Accepted; + case EventController::Declined: + return KCalCore::Attendee::Declined; + case EventController::Unknown: + break; + } + return KCalCore::Attendee::NeedsAction; +} + void EventController::populateFromEvent(const KCalCore::Event &event) { setSummary(event.summary()); setDescription(event.description()); setLocation(event.location()); setRecurring(event.recurs()); - //TODO translate recurrence to string (e.g. weekly) - setRecurrenceString(""); setAllDay(event.allDay()); + + for (const auto &attendee : event.attendees()) { + attendeesController()->add({{"name", attendee->name()}, {"email", attendee->email()}, {"status", toStatus(attendee->status())}}); + } +} + +void EventController::saveToEvent(KCalCore::Event &event) +{ + event.setSummary(getSummary()); + event.setDescription(getDescription()); + event.setLocation(getLocation()); + event.setDtStart(getStart()); + event.setDtEnd(getEnd()); + event.setAllDay(getAllDay()); + + event.clearAttendees(); + KCalCore::Attendee::List attendees; + attendeesController()->traverse([&] (const QVariantMap &map) { + bool rsvp = true; + KCalCore::Attendee::PartStat status = fromStatus(map["status"].value()); + KCalCore::Attendee::Role role = KCalCore::Attendee::ReqParticipant; + + event.addAttendee(KCalCore::Attendee::Ptr::create(map["name"].toString(), map["email"].toString(), rsvp, status, role, QString{})); + }); } void EventController::init() { using namespace Sink; const auto occurrenceVariant = getEventOccurrence(); if (occurrenceVariant.isValid()) { const auto occurrence = occurrenceVariant.value(); Sink::ApplicationDomain::Event event = *occurrence.domainObject; setCalendar(ApplicationDomainType::Ptr::create(ApplicationDomainType::createEntity(event.resourceInstanceIdentifier(), event.getCalendar()))); auto icalEvent = KCalCore::ICalFormat().readIncidence(event.getIcal()).dynamicCast(); if(!icalEvent) { SinkWarning() << "Invalid ICal to process, ignoring..."; return; } populateFromEvent(*icalEvent); setStart(occurrence.start); setEnd(occurrence.end); } } void EventController::remove() { const auto occurrenceVariant = getEventOccurrence(); if (occurrenceVariant.isValid()) { const auto occurrence = occurrenceVariant.value(); Sink::ApplicationDomain::Event event = *occurrence.domainObject; run(Sink::Store::remove(event)); } } + +#include "eventcontroller.moc" diff --git a/framework/src/domain/eventcontroller.h b/framework/src/domain/eventcontroller.h index fd7c4f7f..680b5f43 100644 --- a/framework/src/domain/eventcontroller.h +++ b/framework/src/domain/eventcontroller.h @@ -1,67 +1,77 @@ /* * Copyright (C) 2017 Michael Bohlender, * Copyright (C) 2018 Christian Mollekopf, * * 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. */ #pragma once #include "kube_export.h" #include #include #include #include "controller.h" namespace KCalCore { class Event; }; class KUBE_EXPORT EventController : public Kube::Controller { Q_OBJECT // Input properties KUBE_CONTROLLER_PROPERTY(QVariant, EventOccurrence, eventOccurrence) //Interface properties KUBE_CONTROLLER_PROPERTY(QByteArray, AccountId, accountId) KUBE_CONTROLLER_PROPERTY(QString, Summary, summary) KUBE_CONTROLLER_PROPERTY(QString, Description, description) KUBE_CONTROLLER_PROPERTY(QString, Location, location) KUBE_CONTROLLER_PROPERTY(QDateTime, Start, start) KUBE_CONTROLLER_PROPERTY(QDateTime, End, end) KUBE_CONTROLLER_PROPERTY(QString, RecurrenceString, recurrenceString) KUBE_CONTROLLER_PROPERTY(bool, AllDay, allDay) KUBE_CONTROLLER_PROPERTY(bool, Recurring, recurring) KUBE_CONTROLLER_PROPERTY(Sink::ApplicationDomain::ApplicationDomainType::Ptr, Calendar, calendar) + KUBE_CONTROLLER_LISTCONTROLLER(attendees) + KUBE_CONTROLLER_ACTION(save) public: + enum ParticipantStatus { + Unknown, + Accepted, + Declined, + }; + Q_ENUM(ParticipantStatus); + explicit EventController(); void init() override; Q_INVOKABLE void remove(); protected: void populateFromEvent(const KCalCore::Event &event); + void saveToEvent(KCalCore::Event &event); private slots: void updateSaveAction(); }; diff --git a/framework/src/domain/invitationcontroller.cpp b/framework/src/domain/invitationcontroller.cpp index bb39690c..621ba4ae 100644 --- a/framework/src/domain/invitationcontroller.cpp +++ b/framework/src/domain/invitationcontroller.cpp @@ -1,132 +1,148 @@ /* * Copyright (C) 2017 Michael Bohlender, * Copyright (C) 2018 Christian Mollekopf, * * 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 "invitationcontroller.h" #include #include #include #include #include #include #include using namespace Sink::ApplicationDomain; InvitationController::InvitationController() : EventController(), action_accept{new Kube::ControllerAction{this, &InvitationController::accept}}, action_decline{new Kube::ControllerAction{this, &InvitationController::decline}} { } void InvitationController::loadICal(const QString &ical) { using namespace Sink; using namespace Sink::ApplicationDomain; KCalCore::Calendar::Ptr calendar(new KCalCore::MemoryCalendar{QTimeZone::systemTimeZone()}); auto msg = KCalCore::ICalFormat{}.parseScheduleMessage(calendar, ical.toUtf8()); if (!msg) { SinkWarning() << "Invalid scheudle message to process, ignoring..."; return; } auto icalEvent = msg->event().dynamicCast(); if (msg->method() != KCalCore::iTIPRequest) { SinkWarning() << "Invalid method " << msg->method(); return; } if(!icalEvent) { SinkWarning() << "Invalid ICal to process, ignoring..."; return; } - Query query; query.request(); query.request(); query.filter(icalEvent->uid().toUtf8()); Store::fetchAll(query).then([this, icalEvent](const QList &events) { if (!events.isEmpty()) { setState(InvitationState::Accepted); auto icalEvent = KCalCore::ICalFormat().readIncidence(events.first()->getIcal()).dynamicCast(); if(!icalEvent) { SinkWarning() << "Invalid ICal to process, ignoring..."; return; } populateFromEvent(*icalEvent); setStart(icalEvent->dtStart()); setEnd(icalEvent->dtEnd()); setUid(icalEvent->uid().toUtf8()); } else { setState(InvitationState::Unknown); populateFromEvent(*icalEvent); setStart(icalEvent->dtStart()); setEnd(icalEvent->dtEnd()); setUid(icalEvent->uid().toUtf8()); } }).exec(); } void InvitationController::accept() { using namespace Sink; using namespace Sink::ApplicationDomain; const auto calendar = getCalendar(); if (!calendar) { qWarning() << "No calendar selected"; return; } - auto calcoreEvent = QSharedPointer::create(); - calcoreEvent->setUid(getUid()); - calcoreEvent->setSummary(getSummary()); - calcoreEvent->setDescription(getDescription()); - calcoreEvent->setLocation(getLocation()); - calcoreEvent->setDtStart(getStart()); - calcoreEvent->setDtEnd(getEnd()); - calcoreEvent->setAllDay(getAllDay()); - - Event event(calendar->resourceInstanceIdentifier()); - event.setIcal(KCalCore::ICalFormat().toICalString(calcoreEvent).toUtf8()); - event.setCalendar(*calendar); - - auto job = Store::create(event) - .then([&] (const KAsync::Error &error) { - if (error) { - SinkWarning() << "Failed to save the event: " << error; + Query query; + query.request() + .request() + .request(); + auto job = Store::fetchAll(query) + .then([=] (const QList &list) { + if (list.isEmpty()) { + qWarning() << "Failed to find an identity"; } - setState(InvitationState::Accepted); - emit done(); + bool foundMatch = false; + for (const auto &identity : list) { + const auto id = attendeesController()->findByProperty("email", identity->getAddress()); + if (!id.isEmpty()) { + attendeesController()->setValue(id, "status", EventController::Accepted); + foundMatch = true; + } + } + if (!foundMatch) { + qWarning() << "Failed to find a matching identity"; + return KAsync::error("Failed to find a matching identity"); + } + auto calcoreEvent = QSharedPointer::create(); + calcoreEvent->setUid(getUid()); + saveToEvent(*calcoreEvent); + + Event event(calendar->resourceInstanceIdentifier()); + event.setIcal(KCalCore::ICalFormat().toICalString(calcoreEvent).toUtf8()); + event.setCalendar(*calendar); + + return Store::create(event) + .then([&] (const KAsync::Error &error) { + if (error) { + SinkWarning() << "Failed to save the event: " << error; + } + setState(InvitationState::Accepted); + emit done(); + }); }); run(job); //TODO sendIMipMessage(calcoreEvent); } void InvitationController::decline() { } diff --git a/framework/src/tests/invitationcontrollertest.cpp b/framework/src/tests/invitationcontrollertest.cpp index b7a0cbaf..73578273 100644 --- a/framework/src/tests/invitationcontrollertest.cpp +++ b/framework/src/tests/invitationcontrollertest.cpp @@ -1,95 +1,102 @@ #include #include #include #include #include #include #include #include #include #include #include "invitationcontroller.h" using namespace Sink::ApplicationDomain; class InvitationControllerTest : public QObject { Q_OBJECT QByteArray resourceId; QString createInvitation(const QByteArray &uid) { auto calcoreEvent = QSharedPointer::create(); calcoreEvent->setUid(uid); calcoreEvent->setSummary("summary"); calcoreEvent->setDescription("description"); calcoreEvent->setLocation("location"); calcoreEvent->setDtStart(QDateTime::currentDateTime()); calcoreEvent->setOrganizer("organizer@test.com"); calcoreEvent->addAttendee(KCalCore::Attendee::Ptr::create("John Doe", "attendee1@test.com", true, KCalCore::Attendee::NeedsAction)); return KCalCore::ICalFormat{}.createScheduleMessage(calcoreEvent, KCalCore::iTIPRequest); } private slots: void initTestCase() { Sink::Test::initTest(); auto account = ApplicationDomainType::createEntity(); Sink::Store::create(account).exec().waitForFinished(); + auto identity = ApplicationDomainType::createEntity(); + identity.setAccount(account); + identity.setAddress("attendee1@test.com"); + identity.setName("John Doe"); + + Sink::Store::create(identity).exec().waitForFinished(); + auto resource = DummyResource::create(account.identifier()); Sink::Store::create(resource).exec().waitForFinished(); resourceId = resource.identifier(); } void testAccept() { auto calendar = ApplicationDomainType::createEntity(resourceId); Sink::Store::create(calendar).exec().waitForFinished(); const QByteArray uid{"uid1"}; const auto ical = createInvitation(uid); { InvitationController controller; controller.loadICal(ical); controller.setCalendar(ApplicationDomainType::Ptr::create(calendar)); QTRY_COMPARE(controller.getState(), InvitationController::Unknown); controller.acceptAction()->execute(); QTRY_COMPARE(controller.getState(), InvitationController::Accepted); QTRY_COMPARE(Sink::Store::read(Sink::Query{}.filter(calendar)).size(), 1); auto list = Sink::Store::read(Sink::Query{}.filter(calendar)); QCOMPARE(list.size(), 1); auto event = KCalCore::ICalFormat().readIncidence(list.first().getIcal()).dynamicCast(); QVERIFY(event); QCOMPARE(event->uid(), uid); const auto attendee = event->attendeeByMail("attendee1@test.com"); QVERIFY(attendee); QCOMPARE(attendee->status(), KCalCore::Attendee::Accepted); } { InvitationController controller; controller.loadICal(ical); QTRY_COMPARE(controller.getState(), InvitationController::Accepted); QTRY_COMPARE(controller.getUid(), uid); } } }; QTEST_MAIN(InvitationControllerTest) #include "invitationcontrollertest.moc"