summaryrefslogtreecommitdiffstats
path: root/framework/src/domain/contactcontroller.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'framework/src/domain/contactcontroller.cpp')
-rw-r--r--framework/src/domain/contactcontroller.cpp43
1 files changed, 21 insertions, 22 deletions
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()
70{ 70{
71 using namespace Sink; 71 using namespace Sink;
72 using namespace Sink::ApplicationDomain; 72 using namespace Sink::ApplicationDomain;
73 Query query; 73
74 query.containsFilter<SinkResource::Capabilities>(ResourceCapabilities::Contact::storage); 74 const auto addressbook = getAddressbook();
75 auto job = Store::fetchAll<SinkResource>(query) 75 if (!addressbook) {
76 .then([=](const QList<SinkResource::Ptr> &resources) { 76 qWarning() << "No addressbook selected";
77 if (!resources.isEmpty()) { 77 }
78 auto resourceId = resources[0]->identifier(); 78
79 KContacts::Addressee addressee; 79 KContacts::Addressee addressee;
80 addressee.setGivenName(getFirstName()); 80 addressee.setGivenName(getFirstName());
81 addressee.setFamilyName(getLastName()); 81 addressee.setFamilyName(getLastName());
82 addressee.setFormattedName(getFirstName() + " " + getLastName()); 82 addressee.setFormattedName(getFirstName() + " " + getLastName());
83 KContacts::VCardConverter converter; 83 KContacts::VCardConverter converter;
84 const auto vcard = converter.createVCard(addressee, KContacts::VCardConverter::v3_0); 84
85 85 Contact contact(addressbook->resourceInstanceIdentifier());
86 Contact contact(resourceId); 86 contact.setVcard(converter.createVCard(addressee, KContacts::VCardConverter::v3_0));
87 contact.setVcard(vcard); 87 contact.setAddressbook(*addressbook);
88 88
89 return Store::create(contact); 89 auto job = Store::create(contact)
90 }
91 SinkWarning() << "Failed to find a resource for the contact";
92 return KAsync::error<void>(0, "Failed to find a contact resource.");
93 })
94 .then([&] (const KAsync::Error &error) { 90 .then([&] (const KAsync::Error &error) {
95 SinkLog() << "Failed to save the contact: " << error; 91 if (error) {
92 SinkWarning() << "Failed to save the contact: " << error;
93 }
96 emit done(); 94 emit done();
97 }); 95 });
96
98 run(job); 97 run(job);
99} 98}
100 99