From 581b5a7f16a1c399958742a3b103f47ef9518662 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Thu, 2 Aug 2018 23:15:01 +0200 Subject: Addressbook support for the contact composer --- framework/src/domain/contactcontroller.cpp | 43 +++++++++++++++--------------- framework/src/domain/contactcontroller.h | 2 ++ 2 files changed, 23 insertions(+), 22 deletions(-) (limited to 'framework/src/domain') diff --git a/framework/src/domain/contactcontroller.cpp b/framework/src/domain/contactcontroller.cpp index 6bcaac62..0b46b34d 100644 --- a/framework/src/domain/contactcontroller.cpp +++ b/framework/src/domain/contactcontroller.cpp @@ -70,31 +70,30 @@ 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."); - }) + + const auto addressbook = getAddressbook(); + if (!addressbook) { + qWarning() << "No addressbook selected"; + } + + KContacts::Addressee addressee; + addressee.setGivenName(getFirstName()); + addressee.setFamilyName(getLastName()); + addressee.setFormattedName(getFirstName() + " " + getLastName()); + KContacts::VCardConverter converter; + + Contact contact(addressbook->resourceInstanceIdentifier()); + contact.setVcard(converter.createVCard(addressee, KContacts::VCardConverter::v3_0)); + contact.setAddressbook(*addressbook); + + auto job = Store::create(contact) .then([&] (const KAsync::Error &error) { - SinkLog() << "Failed to save the contact: " << error; + if (error) { + SinkWarning() << "Failed to save the contact: " << error; + } emit done(); }); + run(job); } diff --git a/framework/src/domain/contactcontroller.h b/framework/src/domain/contactcontroller.h index 61e37de8..ea853048 100644 --- a/framework/src/domain/contactcontroller.h +++ b/framework/src/domain/contactcontroller.h @@ -23,6 +23,7 @@ #include #include #include +#include #include "controller.h" @@ -44,6 +45,7 @@ class KUBE_EXPORT ContactController : public Kube::Controller KUBE_CONTROLLER_PROPERTY(QString, Company, company) KUBE_CONTROLLER_PROPERTY(QString, JobTitle, jobTitle) KUBE_CONTROLLER_PROPERTY(QByteArray, ImageData, imageData) + KUBE_CONTROLLER_PROPERTY(Sink::ApplicationDomain::ApplicationDomainType::Ptr, Addressbook, addressbook) KUBE_CONTROLLER_LISTCONTROLLER(mails) KUBE_CONTROLLER_LISTCONTROLLER(phones) -- cgit v1.2.3