diff --git a/framework/src/domain/eventcontroller.cpp b/framework/src/domain/eventcontroller.cpp index 47247f09..2298ef58 100644 --- a/framework/src/domain/eventcontroller.cpp +++ b/framework/src/domain/eventcontroller.cpp @@ -1,107 +1,107 @@ /* * 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 using namespace Sink::ApplicationDomain; EventController::EventController() : Kube::Controller(), 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"; } auto calcoreEvent = QSharedPointer::create(); calcoreEvent->setUid(QUuid::createUuid().toString()); calcoreEvent->setSummary(getSummary()); calcoreEvent->setDescription(getDescription()); 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; } emit done(); }); run(job); } void EventController::updateSaveAction() { saveAction()->setEnabled(!getSummary().isEmpty()); } void EventController::loadEvent(const QVariant &variant) { using namespace Sink; mEvent = variant; if (auto event = variant.value()) { 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; } setSummary(icalEvent->summary()); setDescription(icalEvent->description()); setStart(icalEvent->dtStart()); setEnd(icalEvent->dtEnd()); } } void EventController::remove() { if (auto c = mEvent.value()) { run(Sink::Store::remove(*c)); } } -QVariant EventController::event() const +QVariant EventController::getEvent() const { return mEvent; } diff --git a/framework/src/domain/eventcontroller.h b/framework/src/domain/eventcontroller.h index d84cc6bb..7cda6d40 100644 --- a/framework/src/domain/eventcontroller.h +++ b/framework/src/domain/eventcontroller.h @@ -1,62 +1,62 @@ /* * 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 #include #include "controller.h" class KUBE_EXPORT EventController : public Kube::Controller { Q_OBJECT // Input properties - Q_PROPERTY(QVariant event READ event WRITE loadEvent) + Q_PROPERTY(QVariant event READ getEvent WRITE loadEvent) //Interface properties KUBE_CONTROLLER_PROPERTY(QByteArray, AccountId, accountId) KUBE_CONTROLLER_PROPERTY(QString, Summary, summary) KUBE_CONTROLLER_PROPERTY(QString, Description, description) KUBE_CONTROLLER_PROPERTY(QDateTime, Start, start) KUBE_CONTROLLER_PROPERTY(QDateTime, End, end) KUBE_CONTROLLER_PROPERTY(bool, AllDay, allDay) KUBE_CONTROLLER_PROPERTY(Sink::ApplicationDomain::ApplicationDomainType::Ptr, Calendar, calendar) KUBE_CONTROLLER_ACTION(save) public: explicit EventController(); Q_INVOKABLE void loadEvent(const QVariant &event); Q_INVOKABLE void remove(); - QVariant event() const; + QVariant getEvent() const; private slots: void updateSaveAction(); private: QVariant mEvent; };