]> gitweb.stoutner.com Git - PrivacyBrowserPC.git/blob - src/widgets/TabWidget.h
Enable spell checking. https://redmine.stoutner.com/issues/840
[PrivacyBrowserPC.git] / src / widgets / TabWidget.h
1 /*
2  * Copyright 2022-2023 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 #include "helpers/UserAgentHelper.h"
26
27 // KDE Framework headers.
28 #include <KLineEdit>
29
30 // Qt toolkit headers.
31 #include <QPushButton>
32 #include <QTabWidget>
33 #include <QWebEngineCookieStore>
34 #include <QWebEngineFullScreenRequest>
35 #include <QWebEngineHistory>
36 #include <QWebEngineProfile>
37 #include <QWebEngineSettings>
38 #include <QWebEngineView>
39
40 class TabWidget : public QWidget
41 {
42     // Include the Q_OBJECT macro.
43     Q_OBJECT
44
45 public:
46     // The primary contructor.
47     explicit TabWidget(QWidget *parent);
48
49     // The destructor.
50     ~TabWidget();
51
52     // The public functions.
53     void applyOnTheFlyZoomFactor(const double &zoomFactor);
54     void applySpellCheckLanguages() const;
55     PrivacyWebEngineView* loadBlankInitialWebsite();
56     void loadInitialWebsite();
57     void findPrevious(const QString &text) const;
58     std::list<QNetworkCookie>* getCookieList() const;
59     QString& getDomainSettingsName() const;
60     void setTabBarVisible(const bool visible) const;
61     void toggleDomStorage() const;
62     void toggleFindCaseSensitive(const QString &text);
63     void toggleJavaScript() const;
64     void toggleLocalStorage();
65
66     // The public static variables.
67     static QString webEngineDefaultUserAgent;
68
69 signals:
70     // The signals.
71     void addCookie(const QNetworkCookie &cookie) const;
72     void removeCookie(const QNetworkCookie &cookie) const;
73     void clearUrlLineEditFocus() const;
74     void fullScreenRequested(const bool toggleOn) const;
75     void hideProgressBar() const;
76     void linkHovered(const QString &linkUrl) const;
77     void showProgressBar(const int &progress) const;
78     void updateBackAction(const bool &isEnabled) const;
79     void updateCookiesAction(const int numberOfCookies) const;
80     void updateDomStorageAction(const bool &isEnabled) const;
81     void updateDomainSettingsIndicator(const bool status) const;
82     void updateFindText(const QString &text, const bool findCaseSensitive) const;
83     void updateFindTextResults(const QWebEngineFindTextResult &findTextResult) const;
84     void updateForwardAction(const bool &isEnabled) const;
85     void updateJavaScriptAction(const bool &isEnabled) const;
86     void updateLocalStorageAction(const bool &isEnabled) const;
87     void updateSearchEngineActions(const QString &searchEngine, const bool &updateCustomSearchEngineStatus) const;
88     void updateUrlLineEdit(const QUrl &newUrl) const;
89     void updateUserAgentActions(const QString &userAgent, const bool &updateCustomUserAgentStatus) const;
90     void updateWindowTitle(const QString &title) const;
91     void updateZoomFactorAction(const double &zoomFactor) const;
92
93 public Q_SLOTS:
94     // The public slots.
95     void addCookieToStore(QNetworkCookie cookie, QWebEngineCookieStore *webEngineCookieStorePointer = nullptr) const;
96     PrivacyWebEngineView* addTab(const bool removeUrlLineEditFocus=false, const bool backgroundTab=false);
97     void applyApplicationSettings();
98     void applyDomainSettingsAndReload();
99     void applyDomainSettingsWithoutReloading(const QString &hostname);
100     void applyOnTheFlySearchEngine(QAction *searchEngineActionPointer);
101     void applyOnTheFlyUserAgent(QAction *userAgentActionPointer) const;
102     void back() const;
103     void deleteAllCookies() const;
104     void deleteCookieFromStore(const QNetworkCookie &cookie) const;
105     void findText(const QString &text) const;
106     void forward() const;
107     void home() const;
108     void loadUrlFromLineEdit(QString url) const;
109     void mouseBack() const;
110     void mouseForward() const;
111     void print() const;
112     void printPreview() const;
113     void refresh() const;
114
115 private Q_SLOTS:
116     // The private slots.
117     void addFirstTab();
118     void deleteTab(const int tabIndex);
119     void findTextFinished(const QWebEngineFindTextResult &findTextResult);
120     void fullScreenRequested(QWebEngineFullScreenRequest fullScreenRequest) const;
121     void pageLinkHovered(const QString &linkUrl) const;
122     void printWebpage(QPrinter *printerPointer) const;
123     void showSaveDialog(QWebEngineDownloadItem *downloadItemPointer);
124     void updateUiWithTabSettings();
125     void useNativeDownloader(QUrl &downloadUrl, QString &suggestedFileName);
126
127 private:
128     // The private variables.
129     double currentZoomFactor;  // This can be removed once <https://redmine.stoutner.com/issues/799> has been resolved.
130     PrivacyWebEngineView *currentPrivacyWebEngineViewPointer;
131     QWebEngineCookieStore *currentWebEngineCookieStorePointer;
132     QWebEngineHistory *currentWebEngineHistoryPointer;
133     QWebEnginePage *currentWebEnginePagePointer;
134     QWebEngineProfile *currentWebEngineProfilePointer;
135     QWebEngineSettings *currentWebEngineSettingsPointer;
136     QIcon defaultTabIcon = QIcon::fromTheme(QStringLiteral("globe"));
137     QString searchEngineUrl;
138     QTabWidget *tabWidgetPointer;
139     UserAgentHelper *userAgentHelperPointer;
140     bool wipingCurrentFindTextSelection = false;
141
142     // The private functions.
143     void applyDomainSettings(const QString &hostname, const bool reloadWebsite);
144 };
145 #endif