app/core/ContactPhotoFetch.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include <QList> | ||
| 4 | #include <QObject> | ||
| 5 | #include <QStringList> | ||
| 6 | |||
| 7 | #include "data/ContactStore.h" | ||
| 8 | |||
| 9 | class CardDavClient; | ||
| 10 | struct DavResponse; | ||
| 11 | |||
| 12 | // Photos given as a URI (Sprint 97 S97.5.7, decision D-15): after a book's | ||
| 13 | // sync, cards whose PHOTO points to the book's own DAV origin are fetched | ||
| 14 | // once with the account credentials and stored in contacts.db; the avatar | ||
| 15 | // provider decodes them from there. A URI on any other origin (or another | ||
| 16 | // scheme) is never requested — it is recorded as tried, so it is not looked | ||
| 17 | // at again until the card's URI changes (privacy, G20). | ||
| 18 | // | ||
| 19 | // Sequential GETs, at most MaxPerRun per sync and MaxBytes per image; a | ||
| 20 | // failed fetch is recorded like a foreign URI (shown as initials). | ||
| 21 | class ContactPhotoFetch : public QObject { | ||
| 22 | Q_OBJECT | ||
| 23 | public: | ||
| 24 | static constexpr int MaxPerRun = 25; | ||
| 25 | static constexpr qint64 MaxBytes = 2 * 1024 * 1024; | ||
| 26 | |||
| 27 | ContactPhotoFetch(ContactStore *store, CardDavClient *client, qint64 bookId, QObject *parent = nullptr); | ||
| 28 | // Emits finished() when done (queued when there is nothing to fetch). | ||
| 29 | void start(); | ||
| 30 | 73 | int requests() const { return m_requests; } | |
| 31 | // The photo URI resolved against the card's resource URL, when both have | ||
| 32 | // the same scheme (http/https), host and port; empty otherwise. | ||
| 33 | static QString sameOriginUrl(const QString &cardHref, const QString &photoUri); | ||
| 34 | |||
| 35 | signals: | ||
| 36 | // Card keys whose photo arrived (their avatars reload). | ||
| 37 | void finished(const QStringList &keys); | ||
| 38 | void progressed(); | ||
| 39 | |||
| 40 | private: | ||
| 41 | void next(); | ||
| 42 | void onResponse(const DavResponse &response); | ||
| 43 | |||
| 44 | ContactStore *m_store; | ||
| 45 | CardDavClient *m_client; | ||
| 46 | qint64 m_bookId; | ||
| 47 | QList<ContactStore::PendingPhoto> m_pending; | ||
| 48 | ContactStore::PendingPhoto m_current; | ||
| 49 | quint64 m_request = 0; | ||
| 50 | int m_requests = 0; | ||
| 51 | QStringList m_keys; | ||
| 52 | }; | ||
| 53 |