2 * Copyright 2022-2023 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"
25 #include "helpers/UserAgentHelper.h"
27 // KDE Framework headers.
30 // Qt toolkit headers.
32 #include <QPushButton>
34 #include <QWebEngineCookieStore>
35 #include <QWebEngineFullScreenRequest>
36 #include <QWebEngineHistory>
37 #include <QWebEngineProfile>
38 #include <QWebEngineSettings>
39 #include <QWebEngineView>
41 class TabWidget : public QWidget
43 // Include the Q_OBJECT macro.
47 // The primary contructor.
48 explicit TabWidget(QWidget *parent);
53 // The public functions.
54 void applyOnTheFlyZoomFactor(const double &zoomFactor) const;
55 void applySpellCheckLanguages() const;
56 PrivacyWebEngineView* loadBlankInitialWebsite();
57 void loadInitialWebsite();
58 void findPrevious(const QString &text) const;
59 std::list<QNetworkCookie>* getCookieList() const;
60 QString& getDomainSettingsName() const;
61 void setTabBarVisible(const bool visible) const;
62 void toggleDomStorage() const;
63 void toggleFindCaseSensitive(const QString &text);
64 void toggleJavaScript() const;
65 void toggleLocalStorage();
67 // The public static variables.
68 static QString webEngineDefaultUserAgent;
72 void addCookie(const QNetworkCookie &cookie) const;
73 void removeCookie(const QNetworkCookie &cookie) const;
74 void clearUrlLineEditFocus() const;
75 void fullScreenRequested(const bool toggleOn) const;
76 void hideProgressBar() const;
77 void linkHovered(const QString &linkUrl) const;
78 void showProgressBar(const int &progress) const;
79 void updateBackAction(const bool &isEnabled) const;
80 void updateCookiesAction(const int numberOfCookies) const;
81 void updateDomStorageAction(const bool &isEnabled) const;
82 void updateDomainSettingsIndicator(const bool status) const;
83 void updateFindText(const QString &text, const bool findCaseSensitive) const;
84 void updateFindTextResults(const QWebEngineFindTextResult &findTextResult) const;
85 void updateForwardAction(const bool &isEnabled) const;
86 void updateJavaScriptAction(const bool &isEnabled) const;
87 void updateLocalStorageAction(const bool &isEnabled) const;
88 void updateSearchEngineActions(const QString &searchEngine, const bool &updateCustomSearchEngineStatus) const;
89 void updateUrlLineEdit(const QUrl &newUrl) const;
90 void updateUserAgentActions(const QString &userAgent, const bool &updateCustomUserAgentStatus) const;
91 void updateWindowTitle(const QString &title) const;
92 void updateZoomFactorAction(const double &zoomFactor) const;
96 void addCookieToStore(QNetworkCookie cookie, QWebEngineCookieStore *webEngineCookieStorePointer = nullptr) const;
97 PrivacyWebEngineView* addTab(const bool removeUrlLineEditFocus=false, const bool backgroundTab=false);
98 void applyApplicationSettings();
99 void applyDomainSettingsAndReload();
100 void applyOnTheFlySearchEngine(QAction *searchEngineActionPointer);
101 void applyOnTheFlyUserAgent(QAction *userAgentActionPointer) const;
103 void deleteAllCookies() const;
104 void deleteCookieFromStore(const QNetworkCookie &cookie) const;
105 void findText(const QString &text) const;
106 void forward() const;
108 void loadUrlFromLineEdit(QString url) const;
109 void mouseBack() const;
110 void mouseForward() const;
112 void printPreview() const;
113 void refresh() const;
116 // The private slots.
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 updateUiFromWebEngineView(const PrivacyWebEngineView *privacyWebEngineViewPointer) const;
125 void updateUiWithTabSettings();
126 void useNativeKdeDownloader(QUrl &downloadUrl, QString &suggestedFileName);
129 // The private variables.
130 PrivacyWebEngineView *currentPrivacyWebEngineViewPointer;
131 QWebEngineCookieStore *currentWebEngineCookieStorePointer;
132 QWebEngineHistory *currentWebEngineHistoryPointer;
133 QWebEnginePage *currentWebEnginePagePointer;
134 QWebEngineProfile *currentWebEngineProfilePointer;
135 QWebEngineSettings *currentWebEngineSettingsPointer;
136 QIcon defaultFavoriteIcon = QIcon::fromTheme(QStringLiteral("globe"));
137 bool isRunningKde = false;
138 QMovie *loadingFavoriteIconMoviePointer;
139 QString searchEngineUrl;
140 QTabWidget *qTabWidgetPointer;
141 UserAgentHelper *userAgentHelperPointer;
142 bool wipingCurrentFindTextSelection = false;