quick/ExternalWhitelistModel.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include "data/MailCache.h" | ||
| 4 | #include <QAbstractListModel> | ||
| 5 | #include <QList> | ||
| 6 | #include <QString> | ||
| 7 | |||
| 8 | class MailCache; | ||
| 9 | |||
| 10 | // Normalizes user-entered whitelist domain text: trims whitespace, lowercases | ||
| 11 | // and strips a trailing dot. Returns an empty string when the input cannot be | ||
| 12 | // a hostname (empty, whitespace, separators, scheme, path, credentials or a | ||
| 13 | // label longer than the DNS maximum). | ||
| 14 | QString normalizeWhitelistDomain(const QString &input); | ||
| 15 | |||
| 16 | // Read-only flat view of the MailCache external-content whitelist. The model | ||
| 17 | // refreshes from the cache whenever the cache reports whitelistChanged(), so | ||
| 18 | // editors written through any path (this UI, Widgets settings, remote sync) | ||
| 19 | // stay consistent. Only "domain" entries are offered; sender entries remain | ||
| 20 | // stored for settings compatibility but never grant automatic trust. | ||
| 21 | class ExternalWhitelistModel final : public QAbstractListModel { | ||
| 22 | Q_OBJECT | ||
| 23 | Q_PROPERTY(int count READ count NOTIFY countChanged) | ||
| 24 | public: | ||
| 25 | enum Roles { | ||
| 26 | EntryId = Qt::UserRole + 1, | ||
| 27 | EntryType, | ||
| 28 | EntryValue, | ||
| 29 | EntryAdded, | ||
| 30 | }; | ||
| 31 | explicit ExternalWhitelistModel(MailCache &cache, QObject *parent = nullptr); | ||
| 32 | |||
| 33 | int rowCount(const QModelIndex &parent = {}) const override; | ||
| 34 | QVariant data(const QModelIndex &index, int role) const override; | ||
| 35 | QHash<int, QByteArray> roleNames() const override; | ||
| 36 | 1 | int count() const { return m_entries.size(); } | |
| 37 | |||
| 38 | signals: | ||
| 39 | void countChanged(); | ||
| 40 | |||
| 41 | private: | ||
| 42 | void refresh(); | ||
| 43 | MailCache &m_cache; | ||
| 44 | QList<WhitelistEntry> m_entries; | ||
| 45 | }; | ||
| 46 |