presentation/MetSentence.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include <QList> | ||
| 4 | #include <QLocale> | ||
| 5 | #include <QString> | ||
| 6 | #include <QStringList> | ||
| 7 | |||
| 8 | #include "data/ContactModels.h" | ||
| 9 | |||
| 10 | // The *Met* sentence of the contact card (Sprint 103 S103.3.1, interaction.md | ||
| 11 | // §2.3): when · where · occasion · by mail · through whom, built from the | ||
| 12 | // parts that exist, in the UI language. Returned as segments so QML renders | ||
| 13 | // plain text with links (no rich text for untrusted names, Sprint 102): | ||
| 14 | // a segment with a `link` is clickable ("place", "event", "person:<key>"). | ||
| 15 | // | ||
| 16 | // June 2019 at Chaos Communication Camp, through Ben Weber | ||
| 17 | // Juni 2019 beim Chaos Communication Camp, über Ben Weber | ||
| 18 | namespace MetSentence { | ||
| 19 | |||
| 20 | struct Segment { | ||
| 21 | 3 | QString text; | |
| 22 | 3 | QString link; // "", "place", "event", "person:<card key>" | |
| 23 |
2/4✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 3 times.
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 8 taken 3 times.
|
3 | bool operator==(const Segment &) const = default; |
| 24 | }; | ||
| 25 | |||
| 26 | struct Person { | ||
| 27 | QString name; | ||
| 28 | QString key; // card key when the introducer is a contact | ||
| 29 | }; | ||
| 30 | |||
| 31 | struct Input { | ||
| 32 | LooseDate date; | ||
| 33 | QString place; | ||
| 34 | bool placeIsCity = false; // the place is a gazetteer city ("in Lisbon") | ||
| 35 | QString eventTitle; // the occasion's title when the event is known | ||
| 36 | QString channel; // "mail" | ||
| 37 | QList<Person> via; | ||
| 38 | }; | ||
| 39 | |||
| 40 | QList<Segment> build(const Input &input, const QLocale &locale = QLocale()); | ||
| 41 | QString plainText(const QList<Segment> &segments); | ||
| 42 | // "June 2019", "2019", "14 June 2019", "14 June" in the locale. | ||
| 43 | QString formatDate(const LooseDate &date, const QLocale &locale = QLocale()); | ||
| 44 | |||
| 45 | } // namespace MetSentence | ||
| 46 |