]> gitweb.stoutner.com Git - PrivacyBrowserPC.git/blob - src/widgets/TabWidget.h
Enable opening links in new windows.
[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
26 // KDE Framework headers.
27 #include <KLineEdit>
28
29 // Qt toolkit headers.
30 #include <QPushButton>
31 #include <QTabWidget>
32 #include <QWebEngineCookieStore>
33 #include <QWebEngineFullScreenRequest>
34 #include <QWebEngineHistory>
35 #include <QWebEngineProfile>
36 #include <QWebEngineSettings>
37 #include <QWebEngineView>
38
39 class TabWidget : public QWidget
40 {
41     // Include the Q_OBJECT macro.
42     Q_OBJECT
43
44 public:
45     // The primary contructor.
46     explicit TabWidget(QWidget *parent);
47
48     // The destructor.
49     ~TabWidget();
50
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();
61
62     // The public static variables.
63     static QString webEngineDefaultUserAgent;
64
65 signals:
66     // The signals.
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;
86
87 public Q_SLOTS:
88     // The public slots.
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;
96     void back() const;
97     void deleteAllCookies() const;
98     void deleteCookieFromStore(const QNetworkCookie &cookie) const;
99     void forward() const;
100     void home() const;
101     void loadUrlFromLineEdit(QString url) const;
102     void mouseBack() const;
103     void mouseForward() const;
104     void print() const;
105     void printPreview() const;
106     void refresh() const;
107
108 private Q_SLOTS:
109     // The private slots.
110     void addFirstTab();
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();
118
119 private:
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;
131
132     // The private functions.
133     void applyDomainSettings(const QString &hostname, const bool reloadWebsite);
134 };
135 #endif