diff options
Diffstat (limited to 'framework')
-rw-r--r-- | framework/qml/ComboBox.qml | 7 | ||||
-rw-r--r-- | framework/src/domain/contactcontroller.cpp | 43 | ||||
-rw-r--r-- | framework/src/domain/contactcontroller.h | 2 | ||||
-rw-r--r-- | framework/src/entitymodel.cpp | 13 | ||||
-rw-r--r-- | framework/src/entitymodel.h | 2 |
5 files changed, 45 insertions, 22 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 | |||
147 | QVariantMap 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 | |||
66 | private: | 68 | private: |
67 | void runQuery(const Sink::Query &query); | 69 | void runQuery(const Sink::Query &query); |
68 | void updateQuery(); | 70 | void updateQuery(); |