diff options
Diffstat (limited to 'examples/carddavresource/carddavresource.cpp')
-rw-r--r-- | examples/carddavresource/carddavresource.cpp | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/examples/carddavresource/carddavresource.cpp b/examples/carddavresource/carddavresource.cpp index fc2b946..0bf851b 100644 --- a/examples/carddavresource/carddavresource.cpp +++ b/examples/carddavresource/carddavresource.cpp | |||
@@ -94,7 +94,44 @@ protected: | |||
94 | 94 | ||
95 | KAsync::Job<QByteArray> replay(const ApplicationDomain::Contact &contact, Sink::Operation operation, const QByteArray &oldRemoteId, const QList<QByteArray> &changedProperties) Q_DECL_OVERRIDE | 95 | KAsync::Job<QByteArray> replay(const ApplicationDomain::Contact &contact, Sink::Operation operation, const QByteArray &oldRemoteId, const QList<QByteArray> &changedProperties) Q_DECL_OVERRIDE |
96 | { | 96 | { |
97 | return KAsync::null<QByteArray>(); | 97 | SinkLog() << "Replaying to:" << serverUrl().url(); |
98 | switch (operation) { | ||
99 | case Sink::Operation_Creation: { | ||
100 | const auto vcard = contact.getVcard(); | ||
101 | if (vcard.isEmpty()) { | ||
102 | return KAsync::error<QByteArray>("No vcard in item for creation replay."); | ||
103 | } | ||
104 | |||
105 | auto collectionId = syncStore().resolveLocalId(ENTITY_TYPE_ADDRESSBOOK, contact.getAddressbook()); | ||
106 | |||
107 | KDAV2::DavItem remoteItem; | ||
108 | remoteItem.setData(vcard); | ||
109 | remoteItem.setContentType("text/vcard"); | ||
110 | remoteItem.setUrl(urlOf(collectionId, contact.getUid())); | ||
111 | SinkLog() << "Creating:" << contact.getUid() << remoteItem.url().url() << vcard; | ||
112 | return createItem(remoteItem).then([=] { return resourceID(remoteItem); }); | ||
113 | } | ||
114 | case Sink::Operation_Removal: { | ||
115 | // We only need the URL in the DAV item for removal | ||
116 | KDAV2::DavItem remoteItem; | ||
117 | remoteItem.setUrl(urlOf(oldRemoteId)); | ||
118 | |||
119 | SinkLog() << "Removing:" << oldRemoteId; | ||
120 | return removeItem(remoteItem).then([] { return QByteArray{}; }); | ||
121 | } | ||
122 | case Sink::Operation_Modification: | ||
123 | const auto vcard = contact.getVcard(); | ||
124 | if (vcard.isEmpty()) { | ||
125 | return KAsync::error<QByteArray>("No ICal in item for modification replay"); | ||
126 | } | ||
127 | |||
128 | KDAV2::DavItem remoteItem; | ||
129 | remoteItem.setData(vcard); | ||
130 | remoteItem.setContentType("text/vcard"); | ||
131 | remoteItem.setUrl(urlOf(oldRemoteId)); | ||
132 | |||
133 | return modifyItem(remoteItem).then([=] { return oldRemoteId; }); | ||
134 | } | ||
98 | } | 135 | } |
99 | 136 | ||
100 | KAsync::Job<QByteArray> replay(const ApplicationDomain::Addressbook &addressbook, Sink::Operation operation, const QByteArray &oldRemoteId, const QList<QByteArray> &changedProperties) Q_DECL_OVERRIDE | 137 | KAsync::Job<QByteArray> replay(const ApplicationDomain::Addressbook &addressbook, Sink::Operation operation, const QByteArray &oldRemoteId, const QList<QByteArray> &changedProperties) Q_DECL_OVERRIDE |