data/ICalEventPeople.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // Sprint 103 S103.1.10 (D-14): people named in an event with CONTACT and the | ||
| 2 | // read-only ATTENDEE/ORGANIZER entries of other clients. Part of | ||
| 3 | // ICalEventCodec; the writer never emits ATTENDEE from `people` (G21). | ||
| 4 | #include "ICalEventCodec.h" | ||
| 5 | |||
| 6 | namespace ICalEventCodec { | ||
| 7 | |||
| 8 | namespace { | ||
| 9 | |||
| 10 | 123 | QString bareUuid(const QString &uri) { | |
| 11 |
4/4✓ Branch 3 → 4 taken 123 times.
✓ Branch 4 → 5 taken 86 times.
✓ Branch 4 → 6 taken 37 times.
✓ Branch 5 → 7 taken 86 times.
|
123 | return uri.startsWith(QLatin1String("urn:uuid:"), Qt::CaseInsensitive) ? uri.mid(9) : QString(); |
| 12 | } | ||
| 13 | |||
| 14 | 685 | EventAttendee attendeeOf(const ICal::Property &property, bool organizer) { | |
| 15 | 685 | EventAttendee attendee; | |
| 16 |
1/1✓ Branch 2 → 3 taken 685 times.
|
685 | attendee.address = property.value.trimmed(); |
| 17 |
2/3✓ Branch 6 → 7 taken 685 times.
✓ Branch 7 → 8 taken 685 times.
✗ Branch 7 → 12 not taken.
|
685 | if (attendee.address.startsWith(QLatin1String("mailto:"), Qt::CaseInsensitive)) |
| 18 |
1/1✓ Branch 8 → 9 taken 685 times.
|
685 | attendee.address = attendee.address.mid(7); |
| 19 |
1/1✓ Branch 15 → 16 taken 685 times.
|
685 | attendee.name = property.parameter(QStringLiteral("CN")); |
| 20 |
12/20✓ Branch 20 → 21 taken 231 times.
✓ Branch 20 → 24 taken 454 times.
✓ Branch 27 → 28 taken 454 times.
✓ Branch 28 → 29 taken 454 times.
✓ Branch 31 → 32 taken 454 times.
✓ Branch 31 → 33 taken 231 times.
✓ Branch 33 → 34 taken 454 times.
✓ Branch 33 → 35 taken 231 times.
✓ Branch 35 → 36 taken 454 times.
✓ Branch 35 → 37 taken 231 times.
✓ Branch 37 → 38 taken 231 times.
✓ Branch 37 → 39 taken 454 times.
✗ Branch 71 → 72 not taken.
✗ Branch 71 → 73 not taken.
✗ Branch 75 → 76 not taken.
✗ Branch 75 → 77 not taken.
✗ Branch 79 → 80 not taken.
✗ Branch 79 → 81 not taken.
✗ Branch 83 → 84 not taken.
✗ Branch 83 → 85 not taken.
|
1370 | attendee.role = organizer ? QStringLiteral("ORGANIZER") : property.parameter(QStringLiteral("ROLE")).toUpper(); |
| 21 |
2/2✓ Branch 42 → 43 taken 685 times.
✓ Branch 43 → 44 taken 685 times.
|
685 | attendee.partstat = property.parameter(QStringLiteral("PARTSTAT")).toUpper(); |
| 22 |
2/2✓ Branch 52 → 53 taken 685 times.
✓ Branch 53 → 54 taken 685 times.
|
685 | attendee.cutype = property.parameter(QStringLiteral("CUTYPE")).toUpper(); |
| 23 | 685 | attendee.organizer = organizer; | |
| 24 | 685 | return attendee; | |
| 25 | ✗ | } | |
| 26 | |||
| 27 | } // namespace | ||
| 28 | |||
| 29 | 1944 | QList<EventPerson> peopleOf(const ICal::Component &vevent) { | |
| 30 | 1944 | QList<EventPerson> people; | |
| 31 |
5/5✓ Branch 5 → 6 taken 1944 times.
✓ Branch 8 → 9 taken 1944 times.
✓ Branch 9 → 10 taken 1944 times.
✓ Branch 39 → 11 taken 120 times.
✓ Branch 39 → 40 taken 1944 times.
|
2064 | for (const ICal::Property &contact : vevent.propertiesNamed(QStringLiteral("CONTACT"))) { |
| 32 | 120 | EventPerson person; | |
| 33 |
1/1✓ Branch 15 → 16 taken 120 times.
|
120 | person.uri = contact.parameter(QStringLiteral("ALTREP")); |
| 34 |
1/1✓ Branch 20 → 21 taken 120 times.
|
120 | person.uid = bareUuid(person.uri); |
| 35 |
2/2✓ Branch 23 → 24 taken 120 times.
✓ Branch 24 → 25 taken 120 times.
|
120 | person.name = ICal::unescapeText(contact.value).trimmed(); |
| 36 |
2/6✗ Branch 29 → 30 not taken.
✓ Branch 29 → 32 taken 120 times.
✗ Branch 31 → 32 not taken.
✗ Branch 31 → 33 not taken.
✓ Branch 34 → 35 taken 120 times.
✗ Branch 34 → 36 not taken.
|
120 | if (!person.name.isEmpty() || !person.uri.isEmpty()) |
| 37 |
1/1✓ Branch 35 → 36 taken 120 times.
|
120 | people.append(person); |
| 38 | 2064 | } | |
| 39 | 1944 | return people; | |
| 40 | ✗ | } | |
| 41 | |||
| 42 | 1896 | QList<EventAttendee> attendeesOf(const ICal::Component &vevent) { | |
| 43 | 1896 | QList<EventAttendee> attendees; | |
| 44 |
3/3✓ Branch 5 → 6 taken 1896 times.
✓ Branch 8 → 9 taken 231 times.
✓ Branch 8 → 13 taken 1665 times.
|
1896 | if (const ICal::Property *organizer = vevent.property(QStringLiteral("ORGANIZER"))) |
| 45 |
2/2✓ Branch 9 → 10 taken 231 times.
✓ Branch 10 → 11 taken 231 times.
|
231 | attendees.append(attendeeOf(*organizer, true)); |
| 46 |
5/5✓ Branch 16 → 17 taken 1896 times.
✓ Branch 19 → 20 taken 1896 times.
✓ Branch 20 → 21 taken 1896 times.
✓ Branch 28 → 22 taken 454 times.
✓ Branch 28 → 29 taken 1896 times.
|
2350 | for (const ICal::Property &attendee : vevent.propertiesNamed(QStringLiteral("ATTENDEE"))) |
| 47 |
2/2✓ Branch 23 → 24 taken 454 times.
✓ Branch 24 → 25 taken 454 times.
|
2350 | attendees.append(attendeeOf(attendee, false)); |
| 48 | 1896 | return attendees; | |
| 49 | ✗ | } | |
| 50 | |||
| 51 | // Keeps the CONTACT lines of people that stay (byte for byte), removes the | ||
| 52 | // others and appends the new ones behind the last CONTACT (or LOCATION). | ||
| 53 | 14 | void writePeople(ICal::Component *component, const QList<EventPerson> &after) { | |
| 54 | 14 | QList<EventPerson> remaining = after; | |
| 55 |
2/2✓ Branch 33 → 5 taken 79 times.
✓ Branch 33 → 34 taken 14 times.
|
93 | for (int i = int(component->properties.size()) - 1; i >= 0; --i) { |
| 56 | 79 | const ICal::Property &property = component->properties.at(i); | |
| 57 |
2/2✓ Branch 8 → 9 taken 76 times.
✓ Branch 8 → 10 taken 3 times.
|
79 | if (property.name != QLatin1String("CONTACT")) |
| 58 | 76 | continue; | |
| 59 | 3 | EventPerson person; | |
| 60 |
1/1✓ Branch 13 → 14 taken 3 times.
|
3 | person.uri = property.parameter(QStringLiteral("ALTREP")); |
| 61 |
1/1✓ Branch 18 → 19 taken 3 times.
|
3 | person.uid = bareUuid(person.uri); |
| 62 |
2/2✓ Branch 21 → 22 taken 3 times.
✓ Branch 22 → 23 taken 3 times.
|
3 | person.name = ICal::unescapeText(property.value).trimmed(); |
| 63 |
2/2✓ Branch 27 → 28 taken 2 times.
✓ Branch 27 → 29 taken 1 time.
|
3 | if (remaining.contains(person)) |
| 64 |
1/1✓ Branch 28 → 30 taken 2 times.
|
2 | remaining.removeOne(person); |
| 65 | else | ||
| 66 |
1/1✓ Branch 29 → 30 taken 1 time.
|
1 | component->properties.removeAt(i); |
| 67 | 3 | } | |
| 68 | 14 | int position = -1; | |
| 69 |
2/2✓ Branch 51 → 35 taken 78 times.
✓ Branch 51 → 52 taken 14 times.
|
92 | for (int i = 0; i < component->properties.size(); ++i) { |
| 70 | 78 | const QString name = component->properties.at(i).name; | |
| 71 |
8/8✓ Branch 39 → 40 taken 76 times.
✓ Branch 39 → 44 taken 2 times.
✓ Branch 40 → 41 taken 75 times.
✓ Branch 40 → 45 taken 1 time.
✓ Branch 43 → 44 taken 6 times.
✓ Branch 43 → 45 taken 69 times.
✓ Branch 46 → 47 taken 8 times.
✓ Branch 46 → 48 taken 70 times.
|
78 | if (name == QLatin1String("CONTACT") || (position < 0 && name == QLatin1String("LOCATION"))) |
| 72 | 8 | position = i + 1; | |
| 73 | 78 | } | |
| 74 |
2/2✓ Branch 52 → 53 taken 6 times.
✓ Branch 52 → 55 taken 8 times.
|
14 | if (position < 0) |
| 75 | 6 | position = int(component->properties.size()); | |
| 76 |
4/4✓ Branch 55 → 56 taken 14 times.
✓ Branch 56 → 57 taken 14 times.
✓ Branch 100 → 58 taken 20 times.
✓ Branch 100 → 101 taken 14 times.
|
34 | for (const EventPerson &person : remaining) { |
| 77 | 20 | ICal::Property contact; | |
| 78 | 20 | contact.name = QStringLiteral("CONTACT"); | |
| 79 |
1/1✓ Branch 65 → 66 taken 20 times.
|
20 | contact.value = ICal::escapeText(person.name); |
| 80 | 20 | QString altrep = person.uri; | |
| 81 |
4/6✓ Branch 70 → 71 taken 3 times.
✓ Branch 70 → 74 taken 17 times.
✗ Branch 72 → 73 not taken.
✓ Branch 72 → 74 taken 3 times.
✗ Branch 75 → 76 not taken.
✓ Branch 75 → 85 taken 20 times.
|
20 | if (altrep.isEmpty() && !person.uid.isEmpty()) |
| 82 | ✗ | altrep = QStringLiteral("urn:uuid:") + person.uid; | |
| 83 |
2/2✓ Branch 86 → 87 taken 17 times.
✓ Branch 86 → 95 taken 3 times.
|
20 | if (!altrep.isEmpty()) |
| 84 | 17 | contact.parameters.append({QStringLiteral("ALTREP"), altrep}); | |
| 85 |
1/1✓ Branch 95 → 96 taken 20 times.
|
20 | component->properties.insert(position++, contact); |
| 86 | 20 | } | |
| 87 | 31 | } | |
| 88 | |||
| 89 | |||
| 90 | } // namespace ICalEventCodec | ||
| 91 |