Skip to content

Commit ecc2a76

Browse files
committed
[buteo-sync-plugin-caldav] Add support for VTODO on received ICS data.
1 parent 2692a7d commit ecc2a76

4 files changed

Lines changed: 63 additions & 36 deletions

File tree

‎src/reader.cpp‎

Lines changed: 25 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ void Reader::readResponse()
200200
if (mReader->name() == "href") {
201201
resource.href = QUrl::fromPercentEncoding(mReader->readElementText().toLatin1());
202202
} else if (mReader->name() == "propstat") {
203-
readPropStat(&resource);
203+
readPropStat(resource);
204204
}
205205
}
206206
if (resource.href.isEmpty()) {
@@ -209,16 +209,14 @@ void Reader::readResponse()
209209
}
210210
if (!resource.iCalData.trimmed().isEmpty()) {
211211
bool parsed = true;
212-
bool isVCalFormat = false;
213212
QString icsData = preprocessIcsData(resource.iCalData);
214213
KCalCore::ICalFormat iCalFormat;
215214
KCalCore::MemoryCalendar::Ptr cal(new KCalCore::MemoryCalendar(KDateTime::UTC));
216215
if (!iCalFormat.fromString(cal, icsData)) {
217216
if (iCalFormat.exception() && iCalFormat.exception()->code()
218217
== KCalCore::Exception::CalVersion1) {
219218
KCalCore::VCalFormat vCalFormat;
220-
isVCalFormat = vCalFormat.fromString(cal, icsData);
221-
if (!isVCalFormat) {
219+
if (!vCalFormat.fromString(cal, icsData)) {
222220
LOG_WARNING("unable to parse vCal data");
223221
parsed = false;
224222
}
@@ -240,61 +238,54 @@ void Reader::readResponse()
240238
}
241239
}
242240
if (parsed) {
243-
KCalCore::Event::List events = cal->events(); // TODO: incidences() not just events()
244-
LOG_DEBUG("iCal data contains" << cal->events().count() << "VEVENT instances");
245-
if (events.count() <= 1) {
246-
// single event, or journal/todos
247-
if (isVCalFormat && events.count() == 1) {
248-
resource.incidences = KCalCore::Incidence::List() << events.first();
249-
} else {
250-
KCalCore::Incidence::Ptr incidence = iCalFormat.fromString(icsData);
251-
if (!incidence.isNull()) {
252-
resource.incidences = KCalCore::Incidence::List() << incidence;
253-
} else {
254-
LOG_WARNING("iCal data doesn't contain a valid incidence");
255-
}
256-
}
257-
} else {
258-
// contains some recurring event information, with exception / RECURRENCE-ID defined.
259-
QString eventUid = events.first()->uid();
260-
Q_FOREACH (const KCalCore::Event::Ptr &event, events) {
261-
if (event->uid() != eventUid) {
262-
LOG_WARNING("iCal data contains invalid events with conflicting uids");
263-
eventUid.clear();
241+
KCalCore::Incidence::List incidences = cal->incidences();
242+
LOG_DEBUG("iCal data contains" << incidences.count() << " incidences");
243+
if (incidences.count()) {
244+
QString uid = incidences.first()->uid();
245+
// In case of more than one incidence, it contains some
246+
// recurring event information, with exception / RECURRENCE-ID defined.
247+
Q_FOREACH (const KCalCore::Incidence::Ptr &incidence, incidences) {
248+
if (incidence->uid() != uid) {
249+
LOG_WARNING("iCal data contains invalid incidences with conflicting uids");
250+
uid.clear();
264251
break;
265252
}
266253
}
267-
if (!eventUid.isEmpty()) {
268-
Q_FOREACH (const KCalCore::Event::Ptr &event, events) {
269-
resource.incidences.append(event);
254+
if (!uid.isEmpty()) {
255+
Q_FOREACH (const KCalCore::Incidence::Ptr &incidence, incidences) {
256+
if (incidence->type() == KCalCore::IncidenceBase::TypeEvent
257+
|| incidence->type() == KCalCore::IncidenceBase::TypeTodo)
258+
resource.incidences.append(incidence);
270259
}
271260
}
272-
LOG_DEBUG("parsed" << resource.incidences.count() << "events from the iCal data");
261+
LOG_DEBUG("parsed" << resource.incidences.count() << "events or todos from the iCal data");
262+
} else {
263+
LOG_WARNING("iCal data doesn't contain a valid incidence");
273264
}
274265
}
275266
}
276267

277268
mResults.append(resource);
278269
}
279270

280-
void Reader::readPropStat(CalendarResource *resource)
271+
void Reader::readPropStat(CalendarResource &resource)
281272
{
282273
while (mReader->readNextStartElement()) {
283274
if (mReader->name() == "prop") {
284275
readProp(resource);
285276
} else if (mReader->name() == "status") {
286-
resource->status = mReader->readElementText();
277+
resource.status = mReader->readElementText();
287278
}
288279
}
289280
}
290281

291-
void Reader::readProp(CalendarResource *resource)
282+
void Reader::readProp(CalendarResource &resource)
292283
{
293284
while (mReader->readNextStartElement()) {
294285
if (mReader->name() == "getetag") {
295-
resource->etag = mReader->readElementText();
286+
resource.etag = mReader->readElementText();
296287
} else if (mReader->name() == "calendar-data") {
297-
resource->iCalData = mReader->readElementText(QXmlStreamReader::IncludeChildElements);
288+
resource.iCalData = mReader->readElementText(QXmlStreamReader::IncludeChildElements);
298289
}
299290
}
300291
}

‎src/reader.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ class Reader : public QObject
5252
private:
5353
void readMultiStatus();
5454
void readResponse();
55-
void readPropStat(CalendarResource *resource);
56-
void readProp(CalendarResource *resource);
55+
void readPropStat(CalendarResource &resource);
56+
void readProp(CalendarResource &resource);
5757

5858
private:
5959
QXmlStreamReader *mReader;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<multistatus xmlns:d="DAV:" xmlns:cal="urn:ietf:params:xml:ns:caldav">
2+
<response>
3+
<href>/dcaliste/Prive.ics/20070313T123432Z-456553.ics</href>
4+
<propstat>
5+
<prop>
6+
<getetag>\"78e30cfc6a537db0221a67584eea36f3\"</getetag>
7+
<cal:calendar-data>BEGIN:VCALENDAR
8+
PRODID:-//K Desktop Environment//NONSGML libkcal 4.3//EN
9+
VERSION:2.0
10+
X-KDE-ICAL-IMPLEMENTATION-VERSION:1.0
11+
BEGIN:VTODO
12+
UID:20070313T123432Z-456553@example.com
13+
DTSTAMP:20070313T123432Z
14+
DUE;VALUE=DATE:20070501
15+
SUMMARY:Submit Quebec Income Tax Return for 2006
16+
CLASS:CONFIDENTIAL
17+
CATEGORIES:FAMILY,FINANCE
18+
STATUS:NEEDS-ACTION
19+
END:VTODO
20+
END:VCALENDAR
21+
</cal:calendar-data>
22+
</prop>
23+
<status>HTTP/1.1 200 OK</status>
24+
</propstat>
25+
</response>
26+
</multistatus>

‎tests/reader/tst_reader.cpp‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,16 @@ void tst_Reader::readICal_data()
227227
<< QStringLiteral("Alarm with relative time.")
228228
<< false
229229
<< 1;
230+
QTest::newRow("pending todo")
231+
<< QStringLiteral("data/reader_todo_pending.xml")
232+
<< true
233+
<< 1
234+
<< 1
235+
<< QStringLiteral("20070313T123432Z-456553@example.com")
236+
<< QStringLiteral("Submit Quebec Income Tax Return for 2006")
237+
<< QString()
238+
<< false
239+
<< 0;
230240
}
231241

232242
void tst_Reader::readICal()

0 commit comments

Comments
 (0)