app/SearchCoordinator.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include <QObject> | ||
| 4 | #include <QStringList> | ||
| 5 | #include <functional> | ||
| 6 | |||
| 7 | #include "data/MailCache.h" | ||
| 8 | #include "data/MailRequest.h" | ||
| 9 | |||
| 10 | class MailSearchReadService; | ||
| 11 | |||
| 12 | // The command bar's search previews (Sprint 98 S98.1.11): the top 20 local | ||
| 13 | // results of the line being typed, read on the shared search reader. Since | ||
| 14 | // Sprint 101 the full search runs in a search tab (MailSearchSession); this | ||
| 15 | // class keeps only the preview lane (S101.6.6: the search mode of the folder | ||
| 16 | // list, its "leave" variants and the virtual search node are gone). | ||
| 17 | class SearchCoordinator : public QObject { | ||
| 18 | 36 | Q_OBJECT | |
| 19 | |||
| 20 | public: | ||
| 21 | struct Deps { | ||
| 22 | MailCache *cache = nullptr; | ||
| 23 | MailSearchReadService *readService = nullptr; | ||
| 24 | // False while the canonical FTS generation is incomplete. | ||
| 25 | std::function<bool()> localIndexReady; | ||
| 26 | std::function<quint64()> localIndexGeneration = {}; | ||
| 27 | // The account the previews search (applied in SQL before the limit). | ||
| 28 | std::function<QString()> accountScope = {}; | ||
| 29 | std::function<bool(const MailId &, const QString &)> acceptCachedResult = {}; | ||
| 30 | }; | ||
| 31 | static constexpr int PreviewRows = 20; | ||
| 32 | |||
| 33 | explicit SearchCoordinator(const Deps &deps, QObject *parent = nullptr); | ||
| 34 | ~SearchCoordinator() override; | ||
| 35 | |||
| 36 | // Query → the top PreviewRows local results (the latest request wins). | ||
| 37 | void updateQuickResults(const QString &query); | ||
| 38 | void cancelQuickResults(); | ||
| 39 | 2262 | int quickResultCount() const { return int(m_quickResults.size()); } | |
| 40 | MailCache::SearchResult quickResultAt(int index) const; | ||
| 41 | |||
| 42 | // T-87.D3 burst-adaptive delay, shared with the search tab's title field: | ||
| 43 | // a first or quiet edit runs promptly, a typing burst coalesces toward | ||
| 44 | // the cap. Exposed for deterministic tests. | ||
| 45 | static int adaptiveDebounceMs(qint64 msSincePreviousEdit); | ||
| 46 | static constexpr int PromptEditDebounceMs = 60; | ||
| 47 | static constexpr int BurstQuietGapMs = 150; | ||
| 48 | static constexpr int BurstDebounceCapMs = 240; | ||
| 49 | |||
| 50 | signals: | ||
| 51 | void statusMessage(const QString &message); | ||
| 52 | void quickResultsChanged(); | ||
| 53 | |||
| 54 | private: | ||
| 55 | void present(QList<MailCache::SearchResult> results); | ||
| 56 | |||
| 57 | Deps m_d; | ||
| 58 | QList<MailCache::SearchResult> m_quickResults; | ||
| 59 | quint64 m_previewGeneration = 0; | ||
| 60 | QObject m_previewOwner; | ||
| 61 | }; | ||
| 62 |