| 1 | // For license of this file, see <project-root-folder>/LICENSE.md. |
| 2 | |
| 3 | #ifndef WEBBROWSER_H |
| 4 | #define WEBBROWSER_H |
| 5 | |
| 6 | #include "core/message.h" |
| 7 | #include "gui/tabcontent.h" |
| 8 | #include "services/abstract/rootitem.h" |
| 9 | |
| 10 | #include <QPointer> |
| 11 | #include <QToolBar> |
| 12 | #include <QUrl> |
| 13 | |
| 14 | class QToolButton; |
| 15 | class QVBoxLayout; |
| 16 | class QHBoxLayout; |
| 17 | class QProgressBar; |
| 18 | class QWidgetAction; |
| 19 | class QMenu; |
| 20 | class QLabel; |
| 21 | class TabWidget; |
| 22 | class WebViewer; |
| 23 | class LocationLineEdit; |
| 24 | class SearchTextWidget; |
| 25 | |
| 26 | class RSSGUARD_DLLSPEC WebBrowser : public TabContent { |
| 27 | Q_OBJECT |
| 28 | |
| 29 | friend class WebEngineViewer; |
| 30 | friend class TextBrowserViewer; |
| 31 | |
| 32 | public: |
| 33 | explicit WebBrowser(WebViewer* viewer = nullptr, QWidget* parent = nullptr); |
| 34 | virtual ~WebBrowser(); |
| 35 | |
| 36 | virtual WebBrowser* webBrowser() const; |
| 37 | |
| 38 | WebViewer* viewer() const; |
| 39 | |
| 40 | void reloadFontSettings(); |
| 41 | |
| 42 | double verticalScrollBarPosition() const; |
| 43 | void setVerticalScrollBarPosition(double pos); |
| 44 | |
| 45 | void scrollUp(); |
| 46 | void scrollDown(); |
| 47 | |
| 48 | public slots: |
| 49 | void clear(bool also_hide); |
| 50 | void loadUrl(const QString& url); |
| 51 | void loadUrl(const QUrl& url); |
| 52 | void setHtml(const QString& html, const QUrl& base_url = {}); |
| 53 | void loadMessages(const QList<Message>& messages, RootItem* root); |
| 54 | void setNavigationBarVisible(bool visible); |
| 55 | |
| 56 | protected: |
| 57 | virtual bool eventFilter(QObject* watched, QEvent* event); |
| 58 | |
| 59 | private slots: |
| 60 | void onZoomFactorChanged(); |
| 61 | |
| 62 | #if defined(ENABLE_MEDIAPLAYER) |
| 63 | void playCurrentSiteInMediaPlayer(); |
| 64 | #endif |
| 65 | |
| 66 | void openCurrentSiteInSystemBrowser(); |
| 67 | void updateUrl(const QUrl& url); |
| 68 | void onLoadingStarted(); |
| 69 | void onLoadingProgress(int progress); |
| 70 | void onLoadingFinished(bool success); |
| 71 | void onTitleChanged(const QString& new_title); |
| 72 | void onIconChanged(const QIcon& icon); |
| 73 | void onLinkHovered(const QUrl& url); |
| 74 | void newWindowRequested(WebViewer* viewer); |
| 75 | |
| 76 | void readabilePage(); |
| 77 | void getFullArticle(); |
| 78 | |
| 79 | void setReadabledHtml(const QObject* sndr, const QString& better_html); |
| 80 | void readabilityFailed(const QObject* sndr, const QString& error); |
| 81 | |
| 82 | void setFullArticleHtml(const QObject* sndr, const QString& url, const QString& json_answer); |
| 83 | void fullArticleFailed(const QObject* sndr, const QString& error); |
| 84 | |
| 85 | signals: |
| 86 | void windowCloseRequested(); |
| 87 | |
| 88 | void iconChanged(int index, const QIcon& icon); |
| 89 | void titleChanged(int index, const QString& title); |
| 90 | |
| 91 | private: |
| 92 | void initializeLayout(); |
| 93 | void bindWebView(); |
| 94 | void createConnections(); |
| 95 | |
| 96 | Message messageFromExtractor(const QJsonDocument& extracted_data) const; |
| 97 | |
| 98 | private: |
| 99 | QVBoxLayout* m_layout; |
| 100 | QToolBar* m_toolBar; |
| 101 | WebViewer* m_webView; |
| 102 | SearchTextWidget* m_searchWidget; |
| 103 | LocationLineEdit* m_txtLocation; |
| 104 | QAction* m_txtLocationAction; |
| 105 | QProgressBar* m_loadingProgress; |
| 106 | QAction* m_actionBack; |
| 107 | QAction* m_actionForward; |
| 108 | QAction* m_actionReload; |
| 109 | QAction* m_actionStop; |
| 110 | QAction* m_actionOpenInSystemBrowser; |
| 111 | |
| 112 | #if defined(ENABLE_MEDIAPLAYER) |
| 113 | QAction* m_actionPlayPageInMediaPlayer; |
| 114 | #endif |
| 115 | |
| 116 | QAction* m_actionReadabilePage; |
| 117 | QAction* m_actionGetFullArticle; |
| 118 | |
| 119 | QList<Message> m_messages; |
| 120 | QPointer<RootItem> m_root; |
| 121 | }; |
| 122 | |
| 123 | inline WebBrowser* WebBrowser::webBrowser() const { |
| 124 | return const_cast<WebBrowser*>(this); |
| 125 | } |
| 126 | |
| 127 | inline WebViewer* WebBrowser::viewer() const { |
| 128 | return m_webView; |
| 129 | } |
| 130 | |
| 131 | inline void WebBrowser::setNavigationBarVisible(bool visible) { |
| 132 | m_toolBar->setVisible(visible); |
| 133 | } |
| 134 | |
| 135 | #endif // WEBBROWSER_H |