2 * Copyright © 2022 Soren Stoutner <soren@stoutner.com>.
4 * This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-pc>.
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.
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.
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/>.
23 // Application headers.
24 #include "PrivacyWebEngineView.h"
26 // KDE Framework headers.
29 // Qt toolkit headers.
30 #include <QPushButton>
32 #include <QWebEngineCookieStore>
33 #include <QWebEngineFullScreenRequest>
34 #include <QWebEngineHistory>
35 #include <QWebEngineProfile>
36 #include <QWebEngineSettings>
37 #include <QWebEngineView>
39 class TabWidget : public QWidget
41 // Include the Q_OBJECT macro.
45 // The primary contructor.
46 explicit TabWidget(QWidget *parent);
51 // The public functions.
52 void applyOnTheFlyZoomFactor(const double &zoomFactor);
53 void loadInitialWebsite();
54 std::list<QNetworkCookie>* getCookieList() const;
55 QString& getDomainSettingsName() const;
56 void setTabBarVisible(const bool visible) const;
57 void toggleDomStorage() const;
58 void toggleJavaScript() const;
59 void toggleLocalStorage();
61 // The public static variables.
62 static QString webEngineDefaultUserAgent;
66 void addCookie(const QNetworkCookie &cookie) const;
67 void removeCookie(const QNetworkCookie &cookie) const;
68 void clearUrlLineEditFocus() const;
69 void fullScreenRequested(const bool toggleOn) const;
70 void hideProgressBar() const;
71 void linkHovered(const QString &linkUrl) const;
72 void showProgressBar(const int &progress) const;
73 void updateBackAction(const bool &isEnabled) const;
74 void updateCookiesAction(const int numberOfCookies) const;
75 void updateDomStorageAction(const bool &isEnabled) const;
76 void updateDomainSettingsIndicator(const bool status) const;
77 void updateForwardAction(const bool &isEnabled) const;
78 void updateJavaScriptAction(const bool &isEnabled) const;
79 void updateLocalStorageAction(const bool &isEnabled) const;
80 void updateSearchEngineActions(const QString &searchEngine, const bool &updateCustomSearchEngineStatus) const;
81 void updateUrlLineEdit(const QUrl &newUrl) const;
82 void updateUserAgentActions(const QString &userAgent, const bool &updateCustomUserAgentStatus) const;
83 void updateZoomFactorAction(const double &zoomFactor) const;
87 PrivacyWebEngineView* addTab();
88 void addCookieToStore(QNetworkCookie cookie, QWebEngineCookieStore *webEngineCookieStorePointer = nullptr) const;
89 void applyApplicationSettings();
90 void applyDomainSettingsAndReload();
91 void applyDomainSettingsWithoutReloading(const QString &hostname);
92 void applyOnTheFlySearchEngine(QAction *searchEngineActionPointer);
93 void applyOnTheFlyUserAgent(QAction *userAgentActionPointer) const;
95 void deleteAllCookies() const;
96 void deleteCookieFromStore(const QNetworkCookie &cookie) const;
99 void loadUrlFromLineEdit(QString url) const;
100 void mouseBack() const;
101 void mouseForward() const;
103 void printPreview() const;
104 void refresh() const;
107 // The private slots.
109 void deleteTab(const int tabIndex);
110 void fullScreenRequested(QWebEngineFullScreenRequest fullScreenRequest) const;
111 void loadFinished() const;
112 void loadProgress(const int &progress) const;
113 void loadStarted() const;
114 void pageLinkHovered(const QString &linkUrl) const;
115 void printWebpage(QPrinter *printerPointer) const;
116 void showSaveDialog(QWebEngineDownloadItem *downloadItemPointer) const;
117 void showSaveFilePickerDialog(QUrl &downloadUrl, QString &suggestedFileName);
118 void updateUiWithTabSettings();
119 void updateUrl(const QUrl &url) const;
122 // The private variables.
123 double currentZoomFactor; // This can be removed once <https://redmine.stoutner.com/issues/799> has been resolved.
124 PrivacyWebEngineView *currentPrivacyWebEngineViewPointer;
125 QWebEngineCookieStore *currentWebEngineCookieStorePointer;
126 QWebEngineHistory *currentWebEngineHistoryPointer;
127 QWebEnginePage *currentWebEnginePagePointer;
128 QWebEngineProfile *currentWebEngineProfilePointer;
129 QWebEngineSettings *currentWebEngineSettingsPointer;
130 QIcon defaultTabIcon = QIcon::fromTheme(QStringLiteral("globe"));
131 QString searchEngineUrl;
132 QTabWidget *tabWidgetPointer;
134 // The private functions.
135 void applyDomainSettings(const QString &hostname, const bool reloadWebsite);