diff options
-rw-r--r-- | tests/teststore.cpp | 45 | ||||
-rw-r--r-- | views/people/main.qml | 66 |
2 files changed, 111 insertions, 0 deletions
diff --git a/tests/teststore.cpp b/tests/teststore.cpp index c69588ef..ad494d52 100644 --- a/tests/teststore.cpp +++ b/tests/teststore.cpp | |||
@@ -26,6 +26,7 @@ | |||
26 | 26 | ||
27 | #include <KCalCore/Event> | 27 | #include <KCalCore/Event> |
28 | #include <KCalCore/ICalFormat> | 28 | #include <KCalCore/ICalFormat> |
29 | #include <KContacts/VCardConverter> | ||
29 | 30 | ||
30 | #include <QDebug> | 31 | #include <QDebug> |
31 | #include <QUuid> | 32 | #include <QUuid> |
@@ -186,6 +187,46 @@ static void createCalendar(const QVariantMap &object) | |||
186 | [calendarId](const QVariantMap &object) { createEvent(object, calendarId); }); | 187 | [calendarId](const QVariantMap &object) { createEvent(object, calendarId); }); |
187 | } | 188 | } |
188 | 189 | ||
190 | static void createContact(const QVariantMap &object, const QByteArray &addressbookId = {}) | ||
191 | { | ||
192 | using Sink::ApplicationDomain::ApplicationDomainType; | ||
193 | using Sink::ApplicationDomain::Contact; | ||
194 | |||
195 | QString uid; | ||
196 | if (object.contains("uid")) { | ||
197 | uid = object["uid"].toString(); | ||
198 | } else { | ||
199 | uid = QUuid::createUuid().toString(); | ||
200 | } | ||
201 | |||
202 | auto sinkContact = ApplicationDomainType::createEntity<Contact>(object["resource"].toByteArray()); | ||
203 | |||
204 | KContacts::Addressee addressee; | ||
205 | addressee.setUid(uid); | ||
206 | addressee.setGivenName(object["givenname"].toString()); | ||
207 | addressee.setFamilyName(object["familyname"].toString()); | ||
208 | |||
209 | KContacts::VCardConverter converter; | ||
210 | |||
211 | auto contact = ApplicationDomainType::createEntity<Contact>(object["resource"].toByteArray()); | ||
212 | contact.setVcard(converter.createVCard(addressee, KContacts::VCardConverter::v3_0)); | ||
213 | contact.setAddressbook(addressbookId); | ||
214 | |||
215 | Sink::Store::create(contact).exec().waitForFinished(); | ||
216 | } | ||
217 | |||
218 | static void createAddressbook(const QVariantMap &object) | ||
219 | { | ||
220 | using namespace Sink::ApplicationDomain; | ||
221 | auto addressbook = ApplicationDomainType::createEntity<Addressbook>(object["resource"].toByteArray()); | ||
222 | addressbook.setName(object["name"].toString()); | ||
223 | Sink::Store::create(addressbook).exec().waitForFinished(); | ||
224 | |||
225 | iterateOverObjects(object.value("contacts").toList(), [=](const QVariantMap &object) { | ||
226 | createContact(object, addressbook.identifier()); | ||
227 | }); | ||
228 | } | ||
229 | |||
189 | void TestStore::setup(const QVariantMap &map) | 230 | void TestStore::setup(const QVariantMap &map) |
190 | { | 231 | { |
191 | using namespace Sink::ApplicationDomain; | 232 | using namespace Sink::ApplicationDomain; |
@@ -215,6 +256,9 @@ void TestStore::setup(const QVariantMap &map) | |||
215 | } else if (object["type"] == "caldav") { | 256 | } else if (object["type"] == "caldav") { |
216 | resource.setResourceType("sink.caldav"); | 257 | resource.setResourceType("sink.caldav"); |
217 | resource.setProperty("testmode", true); | 258 | resource.setProperty("testmode", true); |
259 | } else if (object["type"] == "carddav") { | ||
260 | resource.setResourceType("sink.carddav"); | ||
261 | resource.setProperty("testmode", true); | ||
218 | } else { | 262 | } else { |
219 | Q_ASSERT(false); | 263 | Q_ASSERT(false); |
220 | } | 264 | } |
@@ -239,6 +283,7 @@ void TestStore::setup(const QVariantMap &map) | |||
239 | }); | 283 | }); |
240 | 284 | ||
241 | iterateOverObjects(map.value("calendars").toList(), createCalendar); | 285 | iterateOverObjects(map.value("calendars").toList(), createCalendar); |
286 | iterateOverObjects(map.value("addressbooks").toList(), createAddressbook); | ||
242 | 287 | ||
243 | Sink::ResourceControl::flushMessageQueue(resources).exec().waitForFinished(); | 288 | Sink::ResourceControl::flushMessageQueue(resources).exec().waitForFinished(); |
244 | } | 289 | } |
diff --git a/views/people/main.qml b/views/people/main.qml new file mode 100644 index 00000000..0ff35db3 --- /dev/null +++ b/views/people/main.qml | |||
@@ -0,0 +1,66 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2018 Christian Mollekopf, <mollekopf@kolabsys.com> | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License as published by | ||
6 | * the Free Software Foundation; either version 2 of the License, or | ||
7 | * (at your option) any later version. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | * GNU General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License along | ||
15 | * with this program; if not, write to the Free Software Foundation, Inc., | ||
16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
17 | */ | ||
18 | |||
19 | import QtQuick 2.7 | ||
20 | import QtQuick.Controls 2.0 | ||
21 | import QtQuick.Window 2.0 | ||
22 | |||
23 | import org.kube.framework 1.0 as Kube | ||
24 | import org.kube.test 1.0 | ||
25 | import "qml" | ||
26 | |||
27 | ApplicationWindow { | ||
28 | id: app | ||
29 | height: Screen.desktopAvailableHeight * 0.8 | ||
30 | width: Screen.desktopAvailableWidth * 0.8 | ||
31 | |||
32 | Component.onCompleted: { | ||
33 | var initialState = { | ||
34 | accounts: [{ | ||
35 | id: "account1", | ||
36 | name: "Test Account" | ||
37 | }], | ||
38 | identities: [{ | ||
39 | account: "account1", | ||
40 | name: "Test Identity", | ||
41 | address: "identity@example.org" | ||
42 | }], | ||
43 | resources: [{ | ||
44 | id: "carddavresource", | ||
45 | account: "account1", | ||
46 | type: "carddav", | ||
47 | }], | ||
48 | addressbooks: [{ | ||
49 | id: "addressbook1", | ||
50 | resource: "carddavresource", | ||
51 | name: "Default Addressbook", | ||
52 | contacts: [{ | ||
53 | resource: "carddavresource", | ||
54 | uid: "uid1", | ||
55 | givenname: "John", | ||
56 | familyname: "Doe" | ||
57 | }], | ||
58 | }], | ||
59 | } | ||
60 | TestStore.setup(initialState) | ||
61 | } | ||
62 | |||
63 | View { | ||
64 | anchors.fill: parent | ||
65 | } | ||
66 | } | ||