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