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 PrivacyWebEngineView* loadBlankInitialWebsite();
54 void loadInitialWebsite();
55 std::list<QNetworkCookie>* getCookieList() const;
56 QString& getDomainSettingsName() const;
57 void setTabBarVisible(const bool visible) const;
58 void toggleDomStorage() const;
59 void toggleJavaScript() const;
60 void toggleLocalStorage();
62 // The public static variables.
63 static QString webEngineDefaultUserAgent;
67 void addCookie(const QNetworkCookie &cookie) const;
68 void removeCookie(const QNetworkCookie &cookie) const;
69 void clearUrlLineEditFocus() const;
70 void fullScreenRequested(const bool toggleOn) const;
71 void hideProgressBar() const;
72 void linkHovered(const QString &linkUrl) const;
73 void showProgressBar(const int &progress) const;
74 void updateBackAction(const bool &isEnabled) const;
75 void updateCookiesAction(const int numberOfCookies) const;
76 void updateDomStorageAction(const bool &isEnabled) const;
77 void updateDomainSettingsIndicator(const bool status) const;
78 void updateForwardAction(const bool &isEnabled) const;
79 void updateJavaScriptAction(const bool &isEnabled) const;
80 void updateLocalStorageAction(const bool &isEnabled) const;
81 void updateSearchEngineActions(const QString &searchEngine, const bool &updateCustomSearchEngineStatus) const;
82 void updateUrlLineEdit(const QUrl &newUrl) const;
83 void updateUserAgentActions(const QString &userAgent, const bool &updateCustomUserAgentStatus) const;
84 void updateWindowTitle(const QString &title) const;
85 void updateZoomFactorAction(const double &zoomFactor) const;
89 void addCookieToStore(QNetworkCookie cookie, QWebEngineCookieStore *webEngineCookieStorePointer = nullptr) const;
90 PrivacyWebEngineView* addTab(const bool focusNewWebEngineView=false);
91 void applyApplicationSettings();
92 void applyDomainSettingsAndReload();
93 void applyDomainSettingsWithoutReloading(const QString &hostname);
94 void applyOnTheFlySearchEngine(QAction *searchEngineActionPointer);
95 void applyOnTheFlyUserAgent(QAction *userAgentActionPointer) const;
97 void deleteAllCookies() const;
98 void deleteCookieFromStore(const QNetworkCookie &cookie) const;
101 void loadUrlFromLineEdit(QString url) const;
102 void mouseBack() const;
103 void mouseForward() const;
105 void printPreview() const;
106 void refresh() const;
109 // The private slots.
111 void deleteTab(const int tabIndex);
112 void fullScreenRequested(QWebEngineFullScreenRequest fullScreenRequest) const;
113 void pageLinkHovered(const QString &linkUrl) const;
114 void printWebpage(QPrinter *printerPointer) const;
115 void showSaveDialog(QWebEngineDownloadItem *downloadItemPointer) const;
116 void showSaveFilePickerDialog(QUrl &downloadUrl, QString &suggestedFileName);
117 void updateUiWithTabSettings();
120 // The private variables.
121 double currentZoomFactor; // This can be removed once <https://redmine.stoutner.com/issues/799> has been resolved.
122 PrivacyWebEngineView *currentPrivacyWebEngineViewPointer;
123 QWebEngineCookieStore *currentWebEngineCookieStorePointer;
124 QWebEngineHistory *currentWebEngineHistoryPointer;
125 QWebEnginePage *currentWebEnginePagePointer;
126 QWebEngineProfile *currentWebEngineProfilePointer;
127 QWebEngineSettings *currentWebEngineSettingsPointer;
128 QIcon defaultTabIcon = QIcon::fromTheme(QStringLiteral("globe"));
129 QString searchEngineUrl;
130 QTabWidget *tabWidgetPointer;
132 // The private functions.
133 void applyDomainSettings(const QString &hostname, const bool reloadWebsite);