summaryrefslogtreecommitdiffstats
path: root/examples/caldavresource/caldavresource.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'examples/caldavresource/caldavresource.cpp')
-rw-r--r--examples/caldavresource/caldavresource.cpp68
1 files changed, 68 insertions, 0 deletions
diff --git a/examples/caldavresource/caldavresource.cpp b/examples/caldavresource/caldavresource.cpp
index 6bf1a27..d9f8c69 100644
--- a/examples/caldavresource/caldavresource.cpp
+++ b/examples/caldavresource/caldavresource.cpp
@@ -107,6 +107,74 @@ protected:
107 { 107 {
108 return syncStore().resolveRemoteId(ENTITY_TYPE_CALENDAR, resourceID(calendar)); 108 return syncStore().resolveRemoteId(ENTITY_TYPE_CALENDAR, resourceID(calendar));
109 } 109 }
110
111 KAsync::Job<QByteArray> replay(const Event &event, Sink::Operation operation,
112 const QByteArray &oldRemoteId, const QList<QByteArray> &changedProperties) Q_DECL_OVERRIDE
113 {
114 SinkLog() << "Replaying event";
115
116 KDAV2::DavItem item;
117
118 switch (operation) {
119 case Sink::Operation_Creation: {
120 auto rawIcal = event.getIcal();
121 if(rawIcal == "") {
122 return KAsync::error<QByteArray>("No ICal in event for creation replay");
123 }
124
125 auto collectionId = syncStore().resolveLocalId(ENTITY_TYPE_CALENDAR, event.getCalendar());
126
127 item.setData(rawIcal);
128 item.setContentType("text/calendar");
129 item.setUrl(urlOf(collectionId, event.getUid()));
130
131 SinkLog() << "Creating event:" << event.getSummary();
132 return createItem(item).then([item] { return resourceID(item); });
133 }
134 case Sink::Operation_Removal: {
135 // We only need the URL in the DAV item for removal
136 item.setUrl(urlOf(oldRemoteId));
137
138 SinkLog() << "Removing event:" << oldRemoteId;
139 return removeItem(item).then([] { return QByteArray{}; });
140 }
141 case Sink::Operation_Modification:
142 auto rawIcal = event.getIcal();
143 if(rawIcal == "") {
144 return KAsync::error<QByteArray>("No ICal in event for modification replay");
145 }
146
147 item.setData(rawIcal);
148 item.setContentType("text/calendar");
149 item.setUrl(urlOf(oldRemoteId));
150
151 SinkLog() << "Modifying event:" << event.getSummary();
152
153 // It would be nice to check that the URL of the item hasn't
154 // changed and move he item if it did, but since the URL is
155 // pretty much arbitrary, whoe does that anyway?
156 return modifyItem(item).then([oldRemoteId] { return oldRemoteId; });
157 }
158 }
159
160 KAsync::Job<QByteArray> replay(const Calendar &calendar, Sink::Operation operation,
161 const QByteArray &oldRemoteId, const QList<QByteArray> &changedProperties) Q_DECL_OVERRIDE
162 {
163 switch (operation) {
164 case Sink::Operation_Creation:
165 SinkWarning() << "Unimplemented replay of calendar creation";
166 break;
167 case Sink::Operation_Removal:
168 SinkLog() << "Replaying calendar removal";
169 removeCollection(urlOf(oldRemoteId));
170 break;
171 case Sink::Operation_Modification:
172 SinkWarning() << "Unimplemented replay of calendar modification";
173 break;
174 }
175
176 return KAsync::null<QByteArray>();
177 }
110}; 178};
111 179
112CalDavResource::CalDavResource(const Sink::ResourceContext &context) 180CalDavResource::CalDavResource(const Sink::ResourceContext &context)