presentation/ContactMerge.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | #include <QCoreApplication> | ||
| 3 | #include <QList> | ||
| 4 | #include <QVariantList> | ||
| 5 | #include <QVariantMap> | ||
| 6 | |||
| 7 | // F100-15: merging two or more contacts of one address book. Pure: the | ||
| 8 | // caller passes the cards (QuickContactModel::card maps) and saves the | ||
| 9 | // result. The most complete card is proposed as the one that stays; lists | ||
| 10 | // are united (emails and links by text, phone numbers by their digits so | ||
| 11 | // "+49 30 1234567" and "030 1234567" are one number, postal addresses by | ||
| 12 | // their one-line form), groups are united, empty fields are filled, notes | ||
| 13 | // joined. Only real conflicts — two different non-empty values of a single | ||
| 14 | // field — are asked; the kept card's value is the default. | ||
| 15 | class ContactMerge final { | ||
| 16 | 77 | Q_DECLARE_TR_FUNCTIONS(ContactMerge) | |
| 17 | public: | ||
| 18 | // Index of the most complete card (filled fields, number of values, | ||
| 19 | // photo); the first wins a tie. | ||
| 20 | static int keeperIndex(const QList<QVariantMap> &cards); | ||
| 21 | // [{field, label, options: [{text, from}], chosen}] for name, | ||
| 22 | // organization, department, title, nickname and birthday; `from` and | ||
| 23 | // `chosen` are card indices. | ||
| 24 | static QVariantList conflicts(const QList<QVariantMap> &cards, int keeper); | ||
| 25 | // Sprint 107 D-16: the list values of all cards, each value once — | ||
| 26 | // [{field, label, values: [{id, text, from: [card indices]}]}] for | ||
| 27 | // e-mail addresses, phone numbers (by digits), postal addresses (by the | ||
| 28 | // one-line form), links and groups. Every value is kept unless its `id` | ||
| 29 | // is passed to merged() as excluded. | ||
| 30 | static QVariantList setRows(const QList<QVariantMap> &cards, int keeper); | ||
| 31 | // The fields to save on cards[keeper]; `choices` maps a conflict field | ||
| 32 | // to the index of the card whose value wins; `excluded` holds setRows() | ||
| 33 | // value ids the user unchecked (also values of the kept card). | ||
| 34 | static QVariantMap merged(const QList<QVariantMap> &cards, int keeper, const QMap<QString, int> &choices, | ||
| 35 | const QStringList &excluded = {}); | ||
| 36 | // Phone numbers compared by digits; a national number matches its | ||
| 37 | // international form ("030 …" vs "+49 30 …"). | ||
| 38 | static bool samePhone(const QString &a, const QString &b); | ||
| 39 | }; | ||
| 40 |