summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2018-08-02 23:15:01 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2018-08-02 23:15:01 +0200
commit581b5a7f16a1c399958742a3b103f47ef9518662 (patch)
treecc7fa518f81d00522532b223e7373f2f04236f7e
parent6aa6051a1535db4fea13bbde62e7701ecba583e9 (diff)
downloadkube-581b5a7f16a1c399958742a3b103f47ef9518662.tar.gz
kube-581b5a7f16a1c399958742a3b103f47ef9518662.zip
Addressbook support for the contact composer
-rw-r--r--framework/qml/ComboBox.qml7
-rw-r--r--framework/src/domain/contactcontroller.cpp43
-rw-r--r--framework/src/domain/contactcontroller.h2
-rw-r--r--framework/src/entitymodel.cpp13
-rw-r--r--framework/src/entitymodel.h2
-rw-r--r--views/people/qml/People.qml3
-rw-r--r--views/people/qml/PersonComposer.qml28
7 files changed, 73 insertions, 25 deletions
diff --git a/framework/qml/ComboBox.qml b/framework/qml/ComboBox.qml
index 71c9bcc3..64a1c7b3 100644
--- a/framework/qml/ComboBox.qml
+++ b/framework/qml/ComboBox.qml
@@ -32,6 +32,13 @@ T.ComboBox {
32 spacing: Kube.Units.largeSpacing 32 spacing: Kube.Units.largeSpacing
33 padding: Kube.Units.smallSpacing 33 padding: Kube.Units.smallSpacing
34 34
35 //Autoselect the first item
36 onCountChanged: {
37 if (currentIndex < 0) {
38 currentIndex = 0
39 }
40 }
41
35 contentItem: Kube.Label { 42 contentItem: Kube.Label {
36 leftPadding: Kube.Units.smallSpacing 43 leftPadding: Kube.Units.smallSpacing
37 rightPadding: Kube.Units.largeSpacing 44 rightPadding: Kube.Units.largeSpacing
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
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 @@
23#include <QString> 23#include <QString>
24#include <QStringList> 24#include <QStringList>
25#include <QStandardItemModel> 25#include <QStandardItemModel>
26#include <sink/applicationdomaintype.h>
26 27
27#include "controller.h" 28#include "controller.h"
28 29
@@ -44,6 +45,7 @@ class KUBE_EXPORT ContactController : public Kube::Controller
44 KUBE_CONTROLLER_PROPERTY(QString, Company, company) 45 KUBE_CONTROLLER_PROPERTY(QString, Company, company)
45 KUBE_CONTROLLER_PROPERTY(QString, JobTitle, jobTitle) 46 KUBE_CONTROLLER_PROPERTY(QString, JobTitle, jobTitle)
46 KUBE_CONTROLLER_PROPERTY(QByteArray, ImageData, imageData) 47 KUBE_CONTROLLER_PROPERTY(QByteArray, ImageData, imageData)
48 KUBE_CONTROLLER_PROPERTY(Sink::ApplicationDomain::ApplicationDomainType::Ptr, Addressbook, addressbook)
47 49
48 KUBE_CONTROLLER_LISTCONTROLLER(mails) 50 KUBE_CONTROLLER_LISTCONTROLLER(mails)
49 KUBE_CONTROLLER_LISTCONTROLLER(phones) 51 KUBE_CONTROLLER_LISTCONTROLLER(phones)
diff --git a/framework/src/entitymodel.cpp b/framework/src/entitymodel.cpp
index b2d7a9ec..5a79fdf2 100644
--- a/framework/src/entitymodel.cpp
+++ b/framework/src/entitymodel.cpp
@@ -60,8 +60,11 @@ void EntityModel::runQuery(const Query &query)
60{ 60{
61 if (mType == "calendar") { 61 if (mType == "calendar") {
62 mModel = Store::loadModel<Calendar>(query); 62 mModel = Store::loadModel<Calendar>(query);
63 } else if (mType == "addressbook") {
64 mModel = Store::loadModel<Addressbook>(query);
63 } else { 65 } else {
64 qWarning() << "Type not supported " << mType; 66 qWarning() << "Type not supported " << mType;
67 Q_ASSERT(false);
65 } 68 }
66 setSourceModel(mModel.data()); 69 setSourceModel(mModel.data());
67} 70}
@@ -139,3 +142,13 @@ QVariantMap EntityModel::filter() const
139{ 142{
140 return {}; 143 return {};
141} 144}
145
146
147QVariantMap EntityModel::data(int row) const
148{
149 QVariantMap map;
150 for (const auto &r : mRoleNames.keys()) {
151 map.insert(mRoleNames.value(r), data(index(row, 0), r));
152 }
153 return map;
154}
diff --git a/framework/src/entitymodel.h b/framework/src/entitymodel.h
index b8a0417e..add66d78 100644
--- a/framework/src/entitymodel.h
+++ b/framework/src/entitymodel.h
@@ -63,6 +63,8 @@ public:
63 void setFilter(const QVariantMap &); 63 void setFilter(const QVariantMap &);
64 QVariantMap filter() const; 64 QVariantMap filter() const;
65 65
66 Q_INVOKABLE QVariantMap data(int row) const;
67
66private: 68private:
67 void runQuery(const Sink::Query &query); 69 void runQuery(const Sink::Query &query);
68 void updateQuery(); 70 void updateQuery();
diff --git a/views/people/qml/People.qml b/views/people/qml/People.qml
index 718d3c08..ad723427 100644
--- a/views/people/qml/People.qml
+++ b/views/people/qml/People.qml
@@ -51,8 +51,7 @@ FocusScope {
51 leftMargin: Kube.Units.smallSpacing 51 leftMargin: Kube.Units.smallSpacing
52 } 52 }
53 text: qsTr("New Contact") 53 text: qsTr("New Contact")
54 //visible: stack.depth == 1 54 visible: stack.depth == 1
55 visible: false
56 55
57 onClicked: { 56 onClicked: {
58 stack.push(personComposer) 57 stack.push(personComposer)
diff --git a/views/people/qml/PersonComposer.qml b/views/people/qml/PersonComposer.qml
index f56532f8..b409c3d6 100644
--- a/views/people/qml/PersonComposer.qml
+++ b/views/people/qml/PersonComposer.qml
@@ -194,7 +194,7 @@ Flickable {
194 } 194 }
195 } 195 }
196 196
197 Column{ 197 Column {
198 id: address 198 id: address
199 199
200 width: root.width - Kube.Units.largeSpacing 200 width: root.width - Kube.Units.largeSpacing
@@ -226,6 +226,32 @@ Flickable {
226 backgroundColor: "white" 226 backgroundColor: "white"
227 } 227 }
228 } 228 }
229
230 Column{
231 width: root.width - Kube.Units.largeSpacing
232 spacing: Kube.Units.smallSpacing
233
234 Kube.Label {
235 text: "Addressbook"
236 }
237 Kube.ComboBox {
238 width: Kube.Units.gridUnit * 20
239
240 model: Kube.EntityModel {
241 id: addressbookModel
242 type: "addressbook"
243 //TODO
244 //accountId: ""
245 roles: ["name", "color"]
246 }
247 textRole: "name"
248 Layout.fillWidth: true
249 onCurrentIndexChanged: {
250 contactController.addressbook = addressbookModel.data(currentIndex).object
251 }
252 }
253 }
254
229 Item { 255 Item {
230 width: parent.width 256 width: parent.width
231 height: Kube.Units.largeSpacing 257 height: Kube.Units.largeSpacing