From 1cdd003f623dec1fc2aff80c073c94e82b263a85 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Fri, 13 Jul 2018 13:49:10 +0200 Subject: Some progress on creating contacts --- framework/src/domain/contactcontroller.cpp | 42 +++++++++++++++++++++++++++--- framework/src/domain/contactcontroller.h | 3 +++ 2 files changed, 41 insertions(+), 4 deletions(-) (limited to 'framework/src') diff --git a/framework/src/domain/contactcontroller.cpp b/framework/src/domain/contactcontroller.cpp index effe96e8..e27c4a3b 100644 --- a/framework/src/domain/contactcontroller.cpp +++ b/framework/src/domain/contactcontroller.cpp @@ -19,6 +19,8 @@ #include "contactcontroller.h" #include +#include +#include #include class MailsController : public Kube::ListPropertyController @@ -64,22 +66,54 @@ ContactController::ContactController() updateSaveAction(); } -void ContactController::save() { - qWarning() << "Saving is not implemented"; +void ContactController::save() +{ + using namespace Sink; + using namespace Sink::ApplicationDomain; + Query query; + query.containsFilter(ResourceCapabilities::Contact::storage); + auto job = Store::fetchAll(query) + .then([=](const QList &resources) { + if (!resources.isEmpty()) { + auto resourceId = resources[0]->identifier(); + KContacts::Addressee addressee; + addressee.setGivenName(getFirstName()); + addressee.setFamilyName(getLastName()); + addressee.setFormattedName(getFirstName() + " " + getLastName()); + KContacts::VCardConverter converter; + const auto vcard = converter.createVCard(addressee, KContacts::VCardConverter::v3_0); + + Contact contact(resourceId); + contact.setVcard(vcard); + + return Store::create(contact); + } + SinkWarning() << "Failed to find a resource for the contact"; + return KAsync::error(0, "Failed to find a contact resource."); + }) + .then([&] (const KAsync::Error &error) { + SinkLog() << "Failed to save the contact: " << error; + emit done(); + }); + run(job); } void ContactController::updateSaveAction() { - saveAction()->setEnabled(!getName().isEmpty()); + saveAction()->setEnabled(!getFirstName().isEmpty()); } void ContactController::loadContact(const QVariant &contact) { if (auto c = contact.value()) { - setName(c->getFn()); const auto &vcard = c->getVcard(); KContacts::VCardConverter converter; const auto addressee = converter.parseVCard(vcard); + + setName(c->getFn()); + setFirstName(addressee.givenName()); + setLastName(addressee.familyName()); + static_cast(mailsController())->set(addressee.emails()); QStringList numbers; diff --git a/framework/src/domain/contactcontroller.h b/framework/src/domain/contactcontroller.h index 5b49c77b..852a003f 100644 --- a/framework/src/domain/contactcontroller.h +++ b/framework/src/domain/contactcontroller.h @@ -34,6 +34,9 @@ class KUBE_EXPORT ContactController : public Kube::Controller Q_PROPERTY(QVariant contact READ contact WRITE loadContact) //Interface properties + KUBE_CONTROLLER_PROPERTY(QByteArray, AccountId, accountId) + KUBE_CONTROLLER_PROPERTY(QString, FirstName, firstName) + KUBE_CONTROLLER_PROPERTY(QString, LastName, lastName) KUBE_CONTROLLER_PROPERTY(QString, Name, name) KUBE_CONTROLLER_PROPERTY(QString, Street, street) KUBE_CONTROLLER_PROPERTY(QString, City, city) -- cgit v1.2.3