summaryrefslogtreecommitdiffstats
path: root/examples/caldavresource/caldavresource.cpp
diff options
context:
space:
mode:
authorMinijackson <minijackson@riseup.net>2018-05-04 12:43:33 +0200
committerMinijackson <minijackson@riseup.net>2018-05-04 12:43:33 +0200
commitee074c7b460789e8fefb0d127ba217529fb88e2c (patch)
treeb32536cf633ba00893cfb84917469ef8e101a0ce /examples/caldavresource/caldavresource.cpp
parent404d4619ccfc2ea014bdec1a26a9c88d1c314227 (diff)
downloadsink-ee074c7b460789e8fefb0d127ba217529fb88e2c.tar.gz
sink-ee074c7b460789e8fefb0d127ba217529fb88e2c.zip
Add Todo support in caldav synchronizer
Diffstat (limited to 'examples/caldavresource/caldavresource.cpp')
-rw-r--r--examples/caldavresource/caldavresource.cpp80
1 files changed, 51 insertions, 29 deletions
diff --git a/examples/caldavresource/caldavresource.cpp b/examples/caldavresource/caldavresource.cpp
index cdd224f..e28fbc5 100644
--- a/examples/caldavresource/caldavresource.cpp
+++ b/examples/caldavresource/caldavresource.cpp
@@ -78,21 +78,27 @@ protected:
78 78
79 switch (incidence->type()) { 79 switch (incidence->type()) {
80 case Type::TypeEvent: { 80 case Type::TypeEvent: {
81 auto remoteEvent = dynamic_cast<const KCalCore::Event &>(*incidence);
82
83 Event localEvent; 81 Event localEvent;
84 localEvent.setIcal(ical); 82 localEvent.setIcal(ical);
85 localEvent.setCalendar(calendarLocalId); 83 localEvent.setCalendar(calendarLocalId);
86 84
87 SinkTrace() << "Found an event:" << localEvent.getSummary() << "with id:" << rid; 85 SinkTrace() << "Found an event with id:" << rid;
88 86
89 createOrModify(ENTITY_TYPE_EVENT, rid, localEvent, 87 createOrModify(ENTITY_TYPE_EVENT, rid, localEvent,
90 /* mergeCriteria = */ QHash<QByteArray, Sink::Query::Comparator>{}); 88 /* mergeCriteria = */ QHash<QByteArray, Sink::Query::Comparator>{});
91 break; 89 break;
92 } 90 }
93 case Type::TypeTodo: 91 case Type::TypeTodo: {
94 SinkWarning() << "Unimplemented add of a 'Todo' item in the Store"; 92 Todo localTodo;
93 localTodo.setIcal(ical);
94 localTodo.setCalendar(calendarLocalId);
95
96 SinkTrace() << "Found a Todo with id:" << rid;
97
98 createOrModify(ENTITY_TYPE_TODO, rid, localTodo,
99 /* mergeCriteria = */ QHash<QByteArray, Sink::Query::Comparator>{});
95 break; 100 break;
101 }
96 case Type::TypeJournal: 102 case Type::TypeJournal:
97 SinkWarning() << "Unimplemented add of a 'Journal' item in the Store"; 103 SinkWarning() << "Unimplemented add of a 'Journal' item in the Store";
98 break; 104 break;
@@ -112,58 +118,74 @@ protected:
112 return syncStore().resolveRemoteId(ENTITY_TYPE_CALENDAR, resourceID(calendar)); 118 return syncStore().resolveRemoteId(ENTITY_TYPE_CALENDAR, resourceID(calendar));
113 } 119 }
114 120
115 KAsync::Job<QByteArray> replay(const Event &event, Sink::Operation operation, 121 template<typename Item>
116 const QByteArray &oldRemoteId, const QList<QByteArray> &changedProperties) Q_DECL_OVERRIDE 122 KAsync::Job<QByteArray> replayItem(const Item &localItem, Sink::Operation operation,
123 const QByteArray &oldRemoteId, const QList<QByteArray> &changedProperties,
124 const QByteArray &entityType)
117 { 125 {
118 SinkLog() << "Replaying event"; 126 SinkLog() << "Replaying" << entityType;
119 127
120 KDAV2::DavItem item; 128 KDAV2::DavItem remoteItem;
121 129
122 switch (operation) { 130 switch (operation) {
123 case Sink::Operation_Creation: { 131 case Sink::Operation_Creation: {
124 auto rawIcal = event.getIcal(); 132 auto rawIcal = localItem.getIcal();
125 if(rawIcal == "") { 133 if (rawIcal == "") {
126 return KAsync::error<QByteArray>("No ICal in event for creation replay"); 134 return KAsync::error<QByteArray>("No ICal in item for creation replay");
127 } 135 }
128 136
129 auto collectionId = syncStore().resolveLocalId(ENTITY_TYPE_CALENDAR, event.getCalendar()); 137 auto collectionId = syncStore().resolveLocalId(ENTITY_TYPE_CALENDAR, localItem.getCalendar());
130 138
131 item.setData(rawIcal); 139 remoteItem.setData(rawIcal);
132 item.setContentType("text/calendar"); 140 remoteItem.setContentType("text/calendar");
133 item.setUrl(urlOf(collectionId, event.getUid())); 141 remoteItem.setUrl(urlOf(collectionId, localItem.getUid()));
134 142
135 SinkLog() << "Creating event:" << event.getSummary(); 143 SinkLog() << "Creating" << entityType << ":" << localItem.getSummary();
136 return createItem(item).then([item] { return resourceID(item); }); 144 return createItem(remoteItem).then([remoteItem] { return resourceID(remoteItem); });
137 } 145 }
138 case Sink::Operation_Removal: { 146 case Sink::Operation_Removal: {
139 // We only need the URL in the DAV item for removal 147 // We only need the URL in the DAV item for removal
140 item.setUrl(urlOf(oldRemoteId)); 148 remoteItem.setUrl(urlOf(oldRemoteId));
141 149
142 SinkLog() << "Removing event:" << oldRemoteId; 150 SinkLog() << "Removing" << entityType << ":" << oldRemoteId;
143 return removeItem(item).then([] { return QByteArray{}; }); 151 return removeItem(remoteItem).then([] { return QByteArray{}; });
144 } 152 }
145 case Sink::Operation_Modification: 153 case Sink::Operation_Modification:
146 auto rawIcal = event.getIcal(); 154 auto rawIcal = localItem.getIcal();
147 if(rawIcal == "") { 155 if (rawIcal == "") {
148 return KAsync::error<QByteArray>("No ICal in event for modification replay"); 156 return KAsync::error<QByteArray>("No ICal in item for modification replay");
149 } 157 }
150 158
151 item.setData(rawIcal); 159 remoteItem.setData(rawIcal);
152 item.setContentType("text/calendar"); 160 remoteItem.setContentType("text/calendar");
153 item.setUrl(urlOf(oldRemoteId)); 161 remoteItem.setUrl(urlOf(oldRemoteId));
154 162
155 SinkLog() << "Modifying event:" << event.getSummary(); 163 SinkLog() << "Modifying" << entityType << ":" << localItem.getSummary();
156 164
157 // It would be nice to check that the URL of the item hasn't 165 // It would be nice to check that the URL of the item hasn't
158 // changed and move he item if it did, but since the URL is 166 // changed and move he item if it did, but since the URL is
159 // pretty much arbitrary, whoe does that anyway? 167 // pretty much arbitrary, whoe does that anyway?
160 return modifyItem(item).then([oldRemoteId] { return oldRemoteId; }); 168 return modifyItem(remoteItem).then([oldRemoteId] { return oldRemoteId; });
161 } 169 }
162 } 170 }
163 171
172 KAsync::Job<QByteArray> replay(const Event &event, Sink::Operation operation,
173 const QByteArray &oldRemoteId, const QList<QByteArray> &changedProperties) Q_DECL_OVERRIDE
174 {
175 return replayItem(event, operation, oldRemoteId, changedProperties, ENTITY_TYPE_EVENT);
176 }
177
178 KAsync::Job<QByteArray> replay(const Todo &todo, Sink::Operation operation,
179 const QByteArray &oldRemoteId, const QList<QByteArray> &changedProperties) Q_DECL_OVERRIDE
180 {
181 return replayItem(todo, operation, oldRemoteId, changedProperties, ENTITY_TYPE_TODO);
182 }
183
164 KAsync::Job<QByteArray> replay(const Calendar &calendar, Sink::Operation operation, 184 KAsync::Job<QByteArray> replay(const Calendar &calendar, Sink::Operation operation,
165 const QByteArray &oldRemoteId, const QList<QByteArray> &changedProperties) Q_DECL_OVERRIDE 185 const QByteArray &oldRemoteId, const QList<QByteArray> &changedProperties) Q_DECL_OVERRIDE
166 { 186 {
187 SinkLog() << "Replaying calendar";
188
167 switch (operation) { 189 switch (operation) {
168 case Sink::Operation_Creation: 190 case Sink::Operation_Creation:
169 SinkWarning() << "Unimplemented replay of calendar creation"; 191 SinkWarning() << "Unimplemented replay of calendar creation";