]> gitweb.stoutner.com Git - PrivacyBrowserPC.git/blob - src/widgets/TabWidget.h
Implement finding of text withing a page.
[PrivacyBrowserPC.git] / src / widgets / TabWidget.h
1 /*
2  * Copyright © 2022 Soren Stoutner <soren@stoutner.com>.
3  *
4  * This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-pc>.
5  *
6  * Privacy Browser PC is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Privacy Browser PC is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Privacy Browser PC.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 #ifndef TABWIDGET_H
21 #define TABWIDGET_H
22
23 // Application headers.
24 #include "PrivacyWebEngineView.h"
25
26 // KDE Framework headers.
27 #include <KLineEdit>
28
29 // Qt toolkit headers.
30 #include <QPushButton>
31 #include <QTabWidget>
32 #include <QWebEngineCookieStore>
33 #include <QWebEngineFullScreenRequest>
34 #include <QWebEngineHistory>
35 #include <QWebEngineProfile>
36 #include <QWebEngineSettings>
37 #include <QWebEngineView>
38
39 class TabWidget : public QWidget
40 {
41     // Include the Q_OBJECT macro.
42     Q_OBJECT
43
44 public:
45     // The primary contructor.
46     explicit TabWidget(QWidget *parent);
47
48     // The destructor.
49     ~TabWidget();
50
51     // The public functions.
52     void applyOnTheFlyZoomFactor(const double &zoomFactor);
53     PrivacyWebEngineView* loadBlankInitialWebsite();
54     void loadInitialWebsite();
55     void findPrevious(const QString &text) const;
56     std::list<QNetworkCookie>* getCookieList() const;
57     QString& getDomainSettingsName() const;
58     void setTabBarVisible(const bool visible) const;
59     void toggleDomStorage() const;
60     void toggleFindCaseSensitive(const QString &text);
61     void toggleJavaScript() const;
62     void toggleLocalStorage();
63
64     // The public static variables.
65     static QString webEngineDefaultUserAgent;
66
67 signals:
68     // The signals.
69     void addCookie(const QNetworkCookie &cookie) const;
70     void removeCookie(const QNetworkCookie &cookie) const;
71     void clearUrlLineEditFocus() const;
72     void fullScreenRequested(const bool toggleOn) const;
73     void hideProgressBar() const;
74     void linkHovered(const QString &linkUrl) const;
75     void showProgressBar(const int &progress) const;
76     void updateBackAction(const bool &isEnabled) const;
77     void updateCookiesAction(const int numberOfCookies) const;
78     void updateDomStorageAction(const bool &isEnabled) const;
79     void updateDomainSettingsIndicator(const bool status) const;
80     void updateFindText(const QString &text, const bool findCaseSensitive) const;
81     void updateFindTextResults(const QWebEngineFindTextResult &findTextResult) const;
82     void updateForwardAction(const bool &isEnabled) const;
83     void updateJavaScriptAction(const bool &isEnabled) const;
84     void updateLocalStorageAction(const bool &isEnabled) const;
85     void updateSearchEngineActions(const QString &searchEngine, const bool &updateCustomSearchEngineStatus) const;
86     void updateUrlLineEdit(const QUrl &newUrl) const;
87     void updateUserAgentActions(const QString &userAgent, const bool &updateCustomUserAgentStatus) const;
88     void updateWindowTitle(const QString &title) const;
89     void updateZoomFactorAction(const double &zoomFactor) const;
90
91 public Q_SLOTS:
92     // The public slots.
93     void addCookieToStore(QNetworkCookie cookie, QWebEngineCookieStore *webEngineCookieStorePointer = nullptr) const;
94     PrivacyWebEngineView* addTab(const bool focusNewWebEngineView=false);
95     void applyApplicationSettings();
96     void applyDomainSettingsAndReload();
97     void applyDomainSettingsWithoutReloading(const QString &hostname);
98     void applyOnTheFlySearchEngine(QAction *searchEngineActionPointer);
99     void applyOnTheFlyUserAgent(QAction *userAgentActionPointer) const;
100     void back() const;
101     void deleteAllCookies() const;
102     void deleteCookieFromStore(const QNetworkCookie &cookie) const;
103     void findText(const QString &text) const;
104     void forward() const;
105     void home() const;
106     void loadUrlFromLineEdit(QString url) const;
107     void mouseBack() const;
108     void mouseForward() const;
109     void print() const;
110     void printPreview() const;
111     void refresh() const;
112
113 private Q_SLOTS:
114     // The private slots.
115     void addFirstTab();
116     void deleteTab(const int tabIndex);
117     void findTextFinished(const QWebEngineFindTextResult &findTextResult);
118     void fullScreenRequested(QWebEngineFullScreenRequest fullScreenRequest) const;
119     void pageLinkHovered(const QString &linkUrl) const;
120     void printWebpage(QPrinter *printerPointer) const;
121     void showSaveDialog(QWebEngineDownloadItem *downloadItemPointer) const;
122     void showSaveFilePickerDialog(QUrl &downloadUrl, QString &suggestedFileName);
123     void updateUiWithTabSettings();
124
125 private:
126     // The private variables.
127     double currentZoomFactor;  // This can be removed once <https://redmine.stoutner.com/issues/799> has been resolved.
128     PrivacyWebEngineView *currentPrivacyWebEngineViewPointer;
129     QWebEngineCookieStore *currentWebEngineCookieStorePointer;
130     QWebEngineHistory *currentWebEngineHistoryPointer;
131     QWebEnginePage *currentWebEnginePagePointer;
132     QWebEngineProfile *currentWebEngineProfilePointer;
133     QWebEngineSettings *currentWebEngineSettingsPointer;
134     QIcon defaultTabIcon = QIcon::fromTheme(QStringLiteral("globe"));
135     QString searchEngineUrl;
136     QTabWidget *tabWidgetPointer;
137     bool wipingCurrentFindTextSelection = false;
138
139     // The private functions.
140     void applyDomainSettings(const QString &hostname, const bool reloadWebsite);
141 };
142 #endif