@@ -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}
0 commit comments