| 1 | // For license of this file, see <project-root-folder>/LICENSE.md. |
| 2 | |
| 3 | #ifndef WEBFACTORY_H |
| 4 | #define WEBFACTORY_H |
| 5 | |
| 6 | #include "core/message.h" |
| 7 | |
| 8 | #include <QMap> |
| 9 | #include <QObject> |
| 10 | |
| 11 | #if defined(NO_LITE) |
| 12 | class QWebEngineProfile; |
| 13 | class QWebEngineSettings; |
| 14 | class QAction; |
| 15 | class NetworkUrlInterceptor; |
| 16 | class GeminiSchemeHandler; |
| 17 | #endif |
| 18 | |
| 19 | class QMenu; |
| 20 | class AdBlockManager; |
| 21 | class CookieJar; |
| 22 | class ApiServer; |
| 23 | class Readability; |
| 24 | class ArticleParse; |
| 25 | |
| 26 | class RSSGUARD_DLLSPEC WebFactory : public QObject { |
| 27 | Q_OBJECT |
| 28 | |
| 29 | public: |
| 30 | explicit WebFactory(QObject* parent = nullptr); |
| 31 | virtual ~WebFactory(); |
| 32 | |
| 33 | // Strips "<....>" (HTML, XML) tags from given text. |
| 34 | QString stripTags(QString text); |
| 35 | |
| 36 | // HTML entity unescaping. This method |
| 37 | // converts both HTML entity names and numbers to UTF-8 string. |
| 38 | // Example of entities are: |
| 39 | // ∀ = ∀ (entity name), ∀ (base-10 entity), ∀ (base-16 entity) |
| 40 | static QString unescapeHtml(const QString& html); |
| 41 | |
| 42 | QString limitSizeOfHtmlImages(const QString& html, int desired_width, int images_max_height) const; |
| 43 | QString processFeedUriScheme(const QString& url); |
| 44 | |
| 45 | AdBlockManager* adBlock() const; |
| 46 | |
| 47 | #if defined(NO_LITE) |
| 48 | QAction* engineSettingsAction(); |
| 49 | NetworkUrlInterceptor* urlIinterceptor() const; |
| 50 | QWebEngineProfile* engineProfile() const; |
| 51 | #endif |
| 52 | |
| 53 | CookieJar* cookieJar() const; |
| 54 | Readability* readability() const; |
| 55 | ArticleParse* articleParse() const; |
| 56 | |
| 57 | void startApiServer(); |
| 58 | void stopApiServer(); |
| 59 | |
| 60 | void updateProxy(); |
| 61 | bool sendMessageViaEmail(const Message& message); |
| 62 | |
| 63 | #if defined(NO_LITE) |
| 64 | void loadCustomCss(const QString user_styles_path); |
| 65 | #endif |
| 66 | |
| 67 | QString customUserAgent() const; |
| 68 | void setCustomUserAgent(const QString& user_agent); |
| 69 | |
| 70 | public slots: |
| 71 | #if defined(NO_LITE) |
| 72 | void cleanupCache(); |
| 73 | #endif |
| 74 | |
| 75 | bool openUrlInExternalBrowser(const QUrl& url) const; |
| 76 | |
| 77 | #if defined(NO_LITE) |
| 78 | private slots: |
| 79 | void createMenu(QMenu* menu = nullptr); |
| 80 | void webEngineSettingChanged(bool enabled); |
| 81 | |
| 82 | private: |
| 83 | QAction* createEngineSettingsAction(const QString& title, int web_attribute); |
| 84 | #endif |
| 85 | |
| 86 | private: |
| 87 | static QMap<QString, char16_t> generateUnescapes(); |
| 88 | |
| 89 | private: |
| 90 | AdBlockManager* m_adBlock; |
| 91 | |
| 92 | #if defined(NO_LITE) |
| 93 | QWebEngineProfile* m_engineProfile; |
| 94 | NetworkUrlInterceptor* m_urlInterceptor; |
| 95 | QAction* m_engineSettings; |
| 96 | GeminiSchemeHandler* m_geminiHandler; |
| 97 | #endif |
| 98 | |
| 99 | ApiServer* m_apiServer; |
| 100 | CookieJar* m_cookieJar; |
| 101 | Readability* m_readability; |
| 102 | ArticleParse* m_articleParse; |
| 103 | QString m_customUserAgent; |
| 104 | }; |
| 105 | |
| 106 | #endif // WEBFACTORY_H |