diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-07-13 13:49:10 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-07-13 13:49:10 +0200 |
commit | 1cdd003f623dec1fc2aff80c073c94e82b263a85 (patch) | |
tree | b06e382c9db3a38208d15d677fe9f6e7cddd058b | |
parent | 86b5f159d5206ce90ddc15dca969e217051ff881 (diff) | |
download | kube-1cdd003f623dec1fc2aff80c073c94e82b263a85.tar.gz kube-1cdd003f623dec1fc2aff80c073c94e82b263a85.zip |
Some progress on creating contacts
-rw-r--r-- | framework/src/domain/contactcontroller.cpp | 42 | ||||
-rw-r--r-- | framework/src/domain/contactcontroller.h | 3 | ||||
-rw-r--r-- | views/people/qml/PersonComposer.qml | 9 |
3 files changed, 50 insertions, 4 deletions
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 @@ | |||
19 | #include "contactcontroller.h" | 19 | #include "contactcontroller.h" |
20 | 20 | ||
21 | #include <sink/applicationdomaintype.h> | 21 | #include <sink/applicationdomaintype.h> |
22 | #include <sink/store.h> | ||
23 | #include <sink/log.h> | ||
22 | #include <KContacts/VCardConverter> | 24 | #include <KContacts/VCardConverter> |
23 | 25 | ||
24 | class MailsController : public Kube::ListPropertyController | 26 | class MailsController : public Kube::ListPropertyController |
@@ -64,22 +66,54 @@ ContactController::ContactController() | |||
64 | updateSaveAction(); | 66 | updateSaveAction(); |
65 | } | 67 | } |
66 | 68 | ||
67 | void ContactController::save() { | 69 | void ContactController::save() |
68 | qWarning() << "Saving is not implemented"; | 70 | { |
71 | using namespace Sink; | ||
72 | using namespace Sink::ApplicationDomain; | ||
73 | Query query; | ||
74 | query.containsFilter<SinkResource::Capabilities>(ResourceCapabilities::Contact::storage); | ||
75 | auto job = Store::fetchAll<SinkResource>(query) | ||
76 | .then([=](const QList<SinkResource::Ptr> &resources) { | ||
77 | if (!resources.isEmpty()) { | ||
78 | auto resourceId = resources[0]->identifier(); | ||
79 | KContacts::Addressee addressee; | ||
80 | addressee.setGivenName(getFirstName()); | ||
81 | addressee.setFamilyName(getLastName()); | ||
82 | addressee.setFormattedName(getFirstName() + " " + getLastName()); | ||
83 | KContacts::VCardConverter converter; | ||
84 | const auto vcard = converter.createVCard(addressee, KContacts::VCardConverter::v3_0); | ||
85 | |||
86 | Contact contact(resourceId); | ||
87 | contact.setVcard(vcard); | ||
88 | |||
89 | return 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) { | ||
95 | SinkLog() << "Failed to save the contact: " << error; | ||
96 | emit done(); | ||
97 | }); | ||
98 | run(job); | ||
69 | } | 99 | } |
70 | 100 | ||
71 | void ContactController::updateSaveAction() | 101 | void ContactController::updateSaveAction() |
72 | { | 102 | { |
73 | saveAction()->setEnabled(!getName().isEmpty()); | 103 | saveAction()->setEnabled(!getFirstName().isEmpty()); |
74 | } | 104 | } |
75 | 105 | ||
76 | void ContactController::loadContact(const QVariant &contact) | 106 | void ContactController::loadContact(const QVariant &contact) |
77 | { | 107 | { |
78 | if (auto c = contact.value<Sink::ApplicationDomain::Contact::Ptr>()) { | 108 | if (auto c = contact.value<Sink::ApplicationDomain::Contact::Ptr>()) { |
79 | setName(c->getFn()); | ||
80 | const auto &vcard = c->getVcard(); | 109 | const auto &vcard = c->getVcard(); |
81 | KContacts::VCardConverter converter; | 110 | KContacts::VCardConverter converter; |
82 | const auto addressee = converter.parseVCard(vcard); | 111 | const auto addressee = converter.parseVCard(vcard); |
112 | |||
113 | setName(c->getFn()); | ||
114 | setFirstName(addressee.givenName()); | ||
115 | setLastName(addressee.familyName()); | ||
116 | |||
83 | static_cast<MailsController*>(mailsController())->set(addressee.emails()); | 117 | static_cast<MailsController*>(mailsController())->set(addressee.emails()); |
84 | 118 | ||
85 | QStringList numbers; | 119 | 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 | |||
34 | Q_PROPERTY(QVariant contact READ contact WRITE loadContact) | 34 | Q_PROPERTY(QVariant contact READ contact WRITE loadContact) |
35 | 35 | ||
36 | //Interface properties | 36 | //Interface properties |
37 | KUBE_CONTROLLER_PROPERTY(QByteArray, AccountId, accountId) | ||
38 | KUBE_CONTROLLER_PROPERTY(QString, FirstName, firstName) | ||
39 | KUBE_CONTROLLER_PROPERTY(QString, LastName, lastName) | ||
37 | KUBE_CONTROLLER_PROPERTY(QString, Name, name) | 40 | KUBE_CONTROLLER_PROPERTY(QString, Name, name) |
38 | KUBE_CONTROLLER_PROPERTY(QString, Street, street) | 41 | KUBE_CONTROLLER_PROPERTY(QString, Street, street) |
39 | KUBE_CONTROLLER_PROPERTY(QString, City, city) | 42 | KUBE_CONTROLLER_PROPERTY(QString, City, city) |
diff --git a/views/people/qml/PersonComposer.qml b/views/people/qml/PersonComposer.qml index bd469e47..f56532f8 100644 --- a/views/people/qml/PersonComposer.qml +++ b/views/people/qml/PersonComposer.qml | |||
@@ -121,12 +121,16 @@ Flickable { | |||
121 | width: Kube.Units.gridUnit * 15 | 121 | width: Kube.Units.gridUnit * 15 |
122 | placeholderText: qsTr("First Name") | 122 | placeholderText: qsTr("First Name") |
123 | backgroundColor: "white" | 123 | backgroundColor: "white" |
124 | text: contactController.firstName | ||
125 | onTextChanged: contactController.firstName = text | ||
124 | } | 126 | } |
125 | 127 | ||
126 | Kube.TextField { | 128 | Kube.TextField { |
127 | width: Kube.Units.gridUnit * 15 | 129 | width: Kube.Units.gridUnit * 15 |
128 | placeholderText: qsTr("Last Name") | 130 | placeholderText: qsTr("Last Name") |
129 | backgroundColor: "white" | 131 | backgroundColor: "white" |
132 | text: contactController.lastName | ||
133 | onTextChanged: contactController.lastName = text | ||
130 | } | 134 | } |
131 | } | 135 | } |
132 | 136 | ||
@@ -142,6 +146,7 @@ Flickable { | |||
142 | 146 | ||
143 | width: Kube.Units.gridUnit * 20 | 147 | width: Kube.Units.gridUnit * 20 |
144 | text: contactController.jobTitle | 148 | text: contactController.jobTitle |
149 | onTextChanged: contactController.jobTitle = text | ||
145 | placeholderText: qsTr("Job Title") | 150 | placeholderText: qsTr("Job Title") |
146 | backgroundColor: "white" | 151 | backgroundColor: "white" |
147 | } | 152 | } |
@@ -158,6 +163,7 @@ Flickable { | |||
158 | 163 | ||
159 | placeholderText: qsTr("Company") | 164 | placeholderText: qsTr("Company") |
160 | text: contactController.company | 165 | text: contactController.company |
166 | onTextChanged: contactController.company = text | ||
161 | backgroundColor: "white" | 167 | backgroundColor: "white" |
162 | } | 168 | } |
163 | } | 169 | } |
@@ -201,18 +207,21 @@ Flickable { | |||
201 | Kube.TextField { | 207 | Kube.TextField { |
202 | width: Kube.Units.gridUnit * 20 | 208 | width: Kube.Units.gridUnit * 20 |
203 | text: contactController.street | 209 | text: contactController.street |
210 | onTextChanged: contactController.stree = text | ||
204 | placeholderText: qsTr("Street") | 211 | placeholderText: qsTr("Street") |
205 | backgroundColor: "white" | 212 | backgroundColor: "white" |
206 | } | 213 | } |
207 | Kube.TextField { | 214 | Kube.TextField { |
208 | width: Kube.Units.gridUnit * 20 | 215 | width: Kube.Units.gridUnit * 20 |
209 | text: contactController.city | 216 | text: contactController.city |
217 | onTextChanged: contactController.city = text | ||
210 | placeholderText: qsTr("City") | 218 | placeholderText: qsTr("City") |
211 | backgroundColor: "white" | 219 | backgroundColor: "white" |
212 | } | 220 | } |
213 | Kube.TextField { | 221 | Kube.TextField { |
214 | width: Kube.Units.gridUnit * 20 | 222 | width: Kube.Units.gridUnit * 20 |
215 | text: contactController.country | 223 | text: contactController.country |
224 | onTextChanged: contactController.country = text | ||
216 | placeholderText: qsTr("Country") | 225 | placeholderText: qsTr("Country") |
217 | backgroundColor: "white" | 226 | backgroundColor: "white" |
218 | } | 227 | } |