# Use KDE Frameworks to handle internationalization of the following UI files.
ki18n_wrap_ui(privacy-browser
ui/BrowserView.ui
+ ui/CookiesDialog.ui
+ ui/CookieWidget.ui
ui/DomainSettingsDialog.ui
ui/SettingsGeneral.ui
ui/SettingsPrivacy.ui
# List the sources to include in the executable.
target_sources(privacy-browser PRIVATE
+ CookiesDialog.cpp
DomainSettingsDialog.cpp
)
--- /dev/null
+/*
+ * Copyright © 2022 Soren Stoutner <soren@stoutner.com>.
+ *
+ * This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-pc>.
+ *
+ * Privacy Browser PC is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Privacy Browser PC is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Privacy Browser PC. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+// Application headers.
+#include "CookiesDialog.h"
+#include "ui_CookiesDialog.h"
+#include "ui_CookieWidget.h"
+
+// The KDE Frameworks headers.
+#include <KLocalizedString>
+
+// The Qt toolkit headers.
+#include <QDateTime>
+#include <QMessageBox>
+
+CookiesDialog::CookiesDialog(QList<QNetworkCookie> *originalCookieListPointer) : QDialog(nullptr), cookieListPointer(originalCookieListPointer)
+{
+ // Set the dialog window title.
+ setWindowTitle(i18nc("The cookies dialog window title", "Cookies"));
+
+ // Set the window modality.
+ setWindowModality(Qt::WindowModality::WindowModal);
+
+ // Instantiate the cookie settings dialog UI.
+ Ui::CookiesDialog cookiesDialogUi;
+
+ // Setup the UI.
+ cookiesDialogUi.setupUi(this);
+
+ // Create the scroll area widget.
+ QWidget *scrollAreaWidgetPointer = new QWidget();
+
+ // Create the cookies VBox layout.
+ cookiesVBoxLayoutPointer = new QVBoxLayout();
+
+ // Populate the VBoxLayout.
+ for (QNetworkCookie cookie : *cookieListPointer)
+ {
+ // Create a cookie display widget.
+ QWidget *cookieDisplayWidgetPointer = new QWidget();
+
+ // Instantiate the cookie widget dialog UI.
+ Ui::CookieWidget cookieWidgetUi;
+
+ // Setup the UI.
+ cookieWidgetUi.setupUi(cookieDisplayWidgetPointer);
+
+ // Get handles for the views.
+ QLabel *domainLabelPointer = cookieWidgetUi.domainLabel;
+ QLabel *nameLabelPointer = cookieWidgetUi.nameLabel;
+ QLabel *expirationDateLabelPointer = cookieWidgetUi.expirationDateLabel;
+ QLabel *pathLabelPointer = cookieWidgetUi.pathLabel;
+ QCheckBox *httpOnlyCheckBoxPointer = cookieWidgetUi.httpOnlyCheckBox;
+ QCheckBox *secureCheckBoxPointer = cookieWidgetUi.secureCheckBox;
+ QLabel *valueLabelPointer = cookieWidgetUi.valueLabel;
+
+ // Populate the views.
+ domainLabelPointer->setText("<font size=\"+1\"><b>" + cookie.domain() + "</b></font>");
+ nameLabelPointer->setText("<font size=\"+1\"><b>" + cookie.name() + "</b></font>");
+ expirationDateLabelPointer->setText("<b>" + cookie.expirationDate().toString() + "</b>");
+ pathLabelPointer->setText("<b>" + cookie.path() + "</b>");
+ httpOnlyCheckBoxPointer->setChecked(cookie.isHttpOnly());
+ secureCheckBoxPointer->setChecked(cookie.isSecure());
+ valueLabelPointer->setText("<b>" + cookie.value() + "</b>");
+
+ // Add the widget to the cookies VBox layout.
+ cookiesVBoxLayoutPointer->addWidget(cookieDisplayWidgetPointer);
+
+ // Create a line.
+ QFrame *lineFrame = new QFrame();
+
+ // Format the line.
+ lineFrame->setFrameShape(QFrame::HLine);
+ lineFrame->setFrameShadow(QFrame::Sunken);
+
+ // Add the line to the cookies VBox layout.
+ cookiesVBoxLayoutPointer->addWidget(lineFrame);
+ }
+
+ // Set the scroll area widget layout.
+ scrollAreaWidgetPointer->setLayout(cookiesVBoxLayoutPointer);
+
+ // Get a handle for the scroll area.
+ QScrollArea *scrollAreaPointer = cookiesDialogUi.scrollArea;
+
+ // Set the scroll area widget.
+ scrollAreaPointer->setWidget(scrollAreaWidgetPointer);
+
+ // Get handles for the buttons.
+ QDialogButtonBox *dialogButtonBoxPointer = cookiesDialogUi.dialogButtonBox;
+ QPushButton *cancelButtonPointer = dialogButtonBoxPointer->button(QDialogButtonBox::Close);
+
+ // Add a delete all button to the dialog button box.
+ deleteAllButtonPointer = dialogButtonBoxPointer->addButton(i18nc("Delete all cookies button", "Delete all"), QDialogButtonBox::ActionRole);
+
+ // Set the delete all button icon.
+ deleteAllButtonPointer->setIcon(QIcon::fromTheme("delete"));
+
+ // Connect the buttons.
+ connect(deleteAllButtonPointer, SIGNAL(released()), this, SLOT(showDeleteAllMessageBox()));
+ connect(dialogButtonBoxPointer, SIGNAL(rejected()), this, SLOT(reject()));
+
+ // Set the cancel button to be the default.
+ cancelButtonPointer->setDefault(true);
+
+ // Update the UI.
+ updateUi();
+};
+
+void CookiesDialog::showDeleteAllMessageBox() const
+{
+ // Instantiate a delete all message box.
+ QMessageBox deleteAllCookiesMessageBox;
+
+ // Set the icon.
+ deleteAllCookiesMessageBox.setIcon(QMessageBox::Warning);
+
+ // Set the window title.
+ deleteAllCookiesMessageBox.setWindowTitle(i18nc("Delete all cookies dialog title", "Delete All Cookies"));
+
+ // Set the text.
+ deleteAllCookiesMessageBox.setText(i18nc("Delete all cookies dialog text", "Delete all cookies?"));
+
+ // Set the standard buttons.
+ deleteAllCookiesMessageBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
+
+ // Set the default button.
+ deleteAllCookiesMessageBox.setDefaultButton(QMessageBox::No);
+
+ // Display the dialog and capture the return value.
+ int returnValue = deleteAllCookiesMessageBox.exec();
+
+ // Delete all cookies if instructed.
+ if (returnValue == QMessageBox::Yes)
+ {
+ // Delete all the cookies.
+ emit deleteAllCookies();
+
+ // Clear the cookie list.
+ cookieListPointer->clear();
+
+ // Create a layout item pointer.
+ QLayoutItem *layoutItemPointer;
+
+ // Delete each cookie widget.
+ while ((layoutItemPointer = cookiesVBoxLayoutPointer->takeAt(0)) != nullptr)
+ {
+ // Delete the widget.
+ delete layoutItemPointer->widget();
+
+ // Delete the layout.
+ delete layoutItemPointer;
+ }
+
+ // Update the UI.
+ updateUi();
+ }
+}
+
+void CookiesDialog::updateUi() const
+{
+ // Set the status of the buttons.
+ deleteAllButtonPointer->setEnabled(cookieListPointer->count() > 0);
+}
--- /dev/null
+/*
+ * Copyright © 2022 Soren Stoutner <soren@stoutner.com>.
+ *
+ * This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-pc>.
+ *
+ * Privacy Browser PC is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Privacy Browser PC is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Privacy Browser PC. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef COOKIESDIALOG_H
+#define COOKIESDIALOG_H
+
+// Qt toolkit headers.
+#include <QDialog>
+#include <QNetworkCookie>
+#include <QVBoxLayout>
+
+class CookiesDialog : public QDialog
+{
+ // Include the Q_OBJECT macro.
+ Q_OBJECT
+
+public:
+ // The default constructor.
+ explicit CookiesDialog(QList<QNetworkCookie> *cookieListPointer);
+
+signals:
+ void deleteAllCookies() const;
+
+private Q_SLOTS:
+ // The private slots.
+ void showDeleteAllMessageBox() const;
+
+private:
+ // The private variables.
+ QList<QNetworkCookie> *cookieListPointer;
+ QVBoxLayout *cookiesVBoxLayoutPointer;
+ QPushButton *deleteAllButtonPointer;
+
+ // The private functions.
+ void updateUi() const;
+};
+#endif
DomainSettingsDialog::DomainSettingsDialog(const int &startType, const QString &domainName) : QDialog(nullptr)
{
- // Instantiate the domain settings view UI.
+ // Set the window title.
+ setWindowTitle(i18nc("The domain settings dialog window title", "Domain Settings"));
+
+ // Set the window modality.
+ setWindowModality(Qt::WindowModality::WindowModal);;
+
+ // Instantiate the domain settings dialog UI.
Ui::DomainSettingsDialog domainSettingsDialogUi;
// Setup the UI.
deleteDialogMessageBox.setWindowTitle(i18nc("Delete domain dialog title", "Delete Domain"));
// Set the text.
- deleteDialogMessageBox.setText(i18nc("Delete domain main message", "Delete the current domain?"));
+ deleteDialogMessageBox.setText(i18nc("Delete domain dialog main message", "Delete the current domain?"));
// Set the informative text.
- deleteDialogMessageBox.setInformativeText(i18nc("Delete domain secondary message", "Doing so will also save any pending changes that have been made to other domains."));
+ deleteDialogMessageBox.setInformativeText(i18nc("Delete domain dialog secondary message", "Doing so will also save any pending changes that have been made to other domains."));
// Set the standard buttons.
deleteDialogMessageBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
// Display the dialog and capture the return value.
int returnValue = deleteDialogMessageBox.exec();
+ // Delete the domain if instructed.
if (returnValue == QMessageBox::Yes)
{
// Get the current index.
// Qt headers.
#include <QObject>
-#include <QWebEngineView>
class MouseEventFilter : public QObject
{
<!-- Settings. -->
<Menu name="settings">
<Action name="domain_settings" />
+ <Action name="cookies" />
</Menu>
</MenuBar>
<ui version="4.0">
<class>BrowserView</class>
<!-- Main widget. -->
- <widget class="QWidget" name="BrowserView">
+ <widget class="QWidget">
<!-- Main layout. -->
<layout class="QVBoxLayout">
<!-- Set the spacing between items to 0. -->
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ Copyright © 2022 Soren Stoutner <soren@stoutner.com>.
+
+ This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-android>.
+
+ Privacy Browser PC is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Privacy Browser PC is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Privacy Browser PC. If not, see <http://www.gnu.org/licenses/>. -->
+
+<ui version="4.0">
+ <class>CookieWidget</class>
+
+ <widget class="QWidget">
+ <layout class="QVBoxLayout">
+ <item>
+ <layout class="QHBoxLayout">
+ <property name="alignment">
+ <enum>Qt::AlignLeft</enum>
+ </property>
+
+ <!-- Domain. -->
+ <item>
+ <widget class="QLabel">
+ <property name="toolTip">
+ <string>Cookies prepended by a period are accessible to all subdomains.</string>
+ </property>
+
+ <property name="textFormat">
+ <enum>Qt::RichText</enum>
+ </property>
+
+ <property name="text">
+ <string><font size="+1">Domain:&nbsp;</font></string>
+ </property>
+ </widget>
+ </item>
+
+ <item>
+ <widget class="QLabel" name="domainLabel">
+ <property name="toolTip">
+ <string>Cookies prepended by a period are accessible to all subdomains.</string>
+ </property>
+
+ <property name="textFormat">
+ <enum>Qt::RichText</enum>
+ </property>
+
+ <property name="textInteractionFlags">
+ <set>Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
+ </property>
+ </widget>
+ </item>
+
+ <!-- Name. -->
+ <item>
+ <widget class="QLabel">
+ <property name="toolTip">
+ <string>The identifier of the cookie, which is unique when combined with the domain and the path.</string>
+ </property>
+
+ <property name="textFormat">
+ <enum>Qt::RichText</enum>
+ </property>
+
+ <property name="text">
+ <string><font size="+1">&nbsp;&nbsp;&nbsp;&nbsp;Name:&nbsp;</font></string>
+ </property>
+ </widget>
+ </item>
+
+ <item>
+ <widget class="QLabel" name="nameLabel">
+ <property name="toolTip">
+ <string>The identifier of the cookie, which is unique when combined with the domain and the path.</string>
+ </property>
+
+ <property name="textFormat">
+ <enum>Qt::RichText</enum>
+ </property>
+
+ <property name="textInteractionFlags">
+ <set>Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+
+ <item>
+ <layout class="QHBoxLayout">
+ <property name="alignment">
+ <enum>Qt::AlignLeft</enum>
+ </property>
+
+ <!-- Expiration date. -->
+ <item>
+ <widget class="QLabel">
+ <property name="toolTip">
+ <string>Cookies without an expiration date are known as session cookies and are expected to be deleted every time the browser closes.</string>
+ </property>
+
+ <property name="textFormat">
+ <enum>Qt::RichText</enum>
+ </property>
+
+ <property name="text">
+ <string>Expiration date:&nbsp;</string>
+ </property>
+ </widget>
+ </item>
+
+ <item>
+ <widget class="QLabel" name="expirationDateLabel">
+ <property name="toolTip">
+ <string>Cookies without an expiration date are known as session cookies and are expected to be deleted every time the browser closes.</string>
+ </property>
+
+ <property name="textFormat">
+ <enum>Qt::RichText</enum>
+ </property>
+
+ <property name="textInteractionFlags">
+ <set>Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
+ </property>
+ </widget>
+ </item>
+
+ <!-- Path. -->
+ <item>
+ <widget class="QLabel">
+ <property name="toolTip">
+ <string>Websites can restrict access to only a subpath of their URL.</string>
+ </property>
+
+ <property name="textFormat">
+ <enum>Qt::RichText</enum>
+ </property>
+
+ <property name="text">
+ <string>&nbsp;&nbsp;&nbsp;&nbsp;Path:&nbsp;</string>
+ </property>
+ </widget>
+ </item>
+
+ <item>
+ <widget class="QLabel" name="pathLabel">
+ <property name="toolTip">
+ <string>Websites can restrict access to only a subpath of their URL.</string>
+ </property>
+
+ <property name="textFormat">
+ <enum>Qt::RichText</enum>
+ </property>
+
+ <property name="textInteractionFlags">
+ <set>Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
+ </property>
+ </widget>
+ </item>
+
+ <!-- A spacer labe. Necessary to add space before the check box. -->
+ <item>
+ <widget class="QLabel">
+ <property name="textFormat">
+ <enum>Qt::RichText</enum>
+ </property>
+
+ <property name="text">
+ <string>&nbsp;&nbsp;&nbsp;&nbsp;</string>
+ </property>
+ </widget>
+ </item>
+
+ <!-- HTTP only. -->
+ <item>
+ <widget class="QCheckBox" name="httpOnlyCheckBox">
+ <property name="toolTip">
+ <string>Restrict cookie access to HTTP (and HTTPS). This prevents JavaScript from accessing the cookie, which hardens it against cross-site scripting attacks.</string>
+ </property>
+
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+
+ <item>
+ <widget class="QLabel">
+ <property name="toolTip">
+ <string>Restrict cookie access to HTTP (and HTTPS). This prevents JavaScript from accessing the cookie, which hardens it against cross-site scripting attacks.</string>
+ </property>
+
+ <property name="textFormat">
+ <enum>Qt::RichText</enum>
+ </property>
+
+ <property name="text">
+ <string>HTTP only&nbsp;&nbsp;&nbsp;&nbsp;</string>
+ </property>
+ </widget>
+ </item>
+
+ <!-- Secure. -->
+ <item>
+ <widget class="QCheckBox" name="secureCheckBox">
+ <property name="toolTip">
+ <string>Only allow the cookie to be transferred across HTTPS (as opposed to HTTP).</string>
+ </property>
+
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+
+ <item>
+ <widget class="QLabel">
+ <property name="toolTip">
+ <string>Only allow the cookie to be transferred across HTTPS (as opposed to HTTP).</string>
+ </property>
+
+ <property name="text">
+ <string>Secure</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+
+ <item>
+ <layout class="QHBoxLayout">
+ <property name="alignment">
+ <enum>Qt::AlignLeft</enum>
+ </property>
+
+ <!-- Value. -->
+ <item>
+ <widget class="QLabel">
+ <property name="toolTip">
+ <string>The value contains the cookie data.</string>
+ </property>
+
+ <property name="textFormat">
+ <enum>Qt::RichText</enum>
+ </property>
+
+ <property name="text">
+ <string>Value:&nbsp;</string>
+ </property>
+ </widget>
+ </item>
+
+ <item>
+ <widget class="QLabel" name="valueLabel">
+ <property name="toolTip">
+ <string>The value contains the cookie data.</string>
+ </property>
+
+ <property name="wordWrap">
+ <bool>true</bool>
+ </property>
+
+ <property name="textFormat">
+ <enum>Qt::RichText</enum>
+ </property>
+
+ <property name="textInteractionFlags">
+ <set>Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+</ui>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ Copyright © 2022 Soren Stoutner <soren@stoutner.com>.
+
+ This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-android>.
+
+ Privacy Browser PC is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Privacy Browser PC is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Privacy Browser PC. If not, see <http://www.gnu.org/licenses/>. -->
+
+<ui version="4.0">
+ <class>CookiesDialog</class>
+
+
+ <widget class="QWidget">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <height>1000</height>
+ <width>1500</width>
+ </rect>
+ </property>
+
+ <layout class="QVBoxLayout">
+ <item>
+ <!-- Scroll area. -->
+ <widget class="QScrollArea" name="scrollArea" />
+ </item>
+
+ <item>
+ <layout class="QHBoxLayout">
+ <!-- Add cookie button. -->
+ <item>
+ <widget class="QPushButton" name="addCookieButton">
+ <property name="text">
+ <string>Add cookie</string>
+ </property>
+
+ <property name="icon">
+ <iconset theme="list-add" />
+ </property>
+ </widget>
+ </item>
+
+ <!-- Edit cookie button. -->
+ <item>
+ <widget class="QPushButton" name="editDomainButton">
+ <property name="text">
+ <string>Edit cookie</string>
+ </property>
+
+ <property name="icon">
+ <iconset theme="edit-entry" />
+ </property>
+ </widget>
+ </item>
+
+ <!-- Delete domain button. -->
+ <item>
+ <widget class="QPushButton" name="deleteDomainButton">
+ <property name="text">
+ <string>Delete cookie</string>
+ </property>
+
+ <property name="icon">
+ <iconset theme="list-remove" />
+ </property>
+ </widget>
+ </item>
+
+ <!-- Close button. -->
+ <item>
+ <widget class="QDialogButtonBox" name="dialogButtonBox">
+ <property name="standardButtons">
+ <set>QDialogButtonBox::Close</set>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+</ui>
<ui version="4.0">
<class>DomainSettingsDialog</class>
- <widget class="QWidget" name="DomainSettingsDialog">
+ <widget class="QWidget">
<property name="geometry">
<rect>
<x>0</x>
<item>
<widget class="QPushButton" name="addDomainButton">
<property name="text">
- <string>Add Domain</string>
+ <string>Add domain</string>
</property>
<property name="icon">
- <iconset theme="list-add"/>
+ <iconset theme="list-add" />
</property>
</widget>
</item>
</property>
<property name="icon">
- <iconset theme="list-remove"/>
+ <iconset theme="list-remove" />
</property>
</widget>
</item>
// Qt framework headers.
#include <QAction>
-#include <QWebEngineProfile>
// Initialize the public static variables.
QString BrowserView::webEngineDefaultUserAgent = QStringLiteral("");
webEngineProfilePointer = new QWebEngineProfile(QStringLiteral(""));
// Create a WebEngine page.
- QWebEnginePage *webEnginePagePointer = new QWebEnginePage(webEngineProfilePointer);
+ webEnginePagePointer = new QWebEnginePage(webEngineProfilePointer);
// Set the WebEngine page.
webEngineViewPointer->setPage(webEnginePagePointer);
// Get handles for the aspects of the WebEngine.
webEngineHistoryPointer = webEnginePagePointer->history();
webEngineSettingsPointer = webEngineViewPointer->settings();
+ webEngineCookieStorePointer = webEngineProfilePointer->cookieStore();
+
+ // Store a copy of each cookie when it is added.
+ connect(webEngineCookieStorePointer, SIGNAL(cookieAdded(QNetworkCookie)), this, SLOT(cookieAdded(QNetworkCookie)));
// Store a copy of the WebEngine default user agent.
webEngineDefaultUserAgent = webEngineProfilePointer->httpUserAgent();
webEngineViewPointer->setFocus();
}
+BrowserView::~BrowserView()
+{
+ // Delay the deletion of the WebEngine page to prevent the following error: `Release of profile requested but WebEnginePage still not deleted. Expect troubles !`
+ webEnginePagePointer->deleteLater();
+}
+
void BrowserView::applyApplicationSettings()
{
// Set the search engine URL.
webEngineViewPointer->back();
}
+void BrowserView::cookieAdded(const QNetworkCookie &cookie) const
+{
+ // Add the cookie to the cookie list.
+ emit addCookie(cookie);
+}
+
+void BrowserView::deleteAllCookies() const
+{
+ // Delete all the cookies.
+ webEngineCookieStorePointer->deleteAllCookies();
+}
+
void BrowserView::forward() const
{
// Go forward.
// Qt framework headers.
#include <QPushButton>
#include <QWebEngineHistory>
+#include <QWebEngineProfile>
#include <QWebEngineSettings>
#include <QWebEngineView>
// The primary contructor.
explicit BrowserView(QWidget *parent);
+ // The destructor.
+ ~BrowserView();
+
// The public functions.
void applyOnTheFlyZoomFactor(const double &zoomFactor);
void loadInitialWebsite();
signals:
// The signals.
+ void addCookie(const QNetworkCookie &cookie) const;
void clearUrlLineEditFocus() const;
void hideProgressBar() const;
void linkHovered(const QString &linkUrl) const;
void applyOnTheFlySearchEngine(QAction *searchEngineActionPointer);
void applyOnTheFlyUserAgent(QAction *userAgentActionPointer) const;
void back() const;
+ void deleteAllCookies() const;
void forward() const;
void home() const;
void loadUrlFromLineEdit(QString url) const;
private Q_SLOTS:
// The private slots.
+ void cookieAdded(const QNetworkCookie &cookie) const;
void loadFinished() const;
void loadProgress(const int &progress) const;
void loadStarted() const;
// The private variables.
double currentZoomFactor; // This can be removed once <https://redmine.stoutner.com/issues/799> has been resolved.
QString searchEngineUrl;
+ QWebEngineCookieStore *webEngineCookieStorePointer;
QWebEngineHistory *webEngineHistoryPointer;
+ QWebEnginePage *webEnginePagePointer;
QWebEngineProfile *webEngineProfilePointer;
QWebEngineSettings *webEngineSettingsPointer;
QWebEngineView *webEngineViewPointer;
#include "Settings.h"
#include "ui_SettingsPrivacy.h"
#include "ui_SettingsGeneral.h"
+#include "dialogs/CookiesDialog.h"
#include "dialogs/DomainSettingsDialog.h"
#include "helpers/SearchEngineHelper.h"
#include "helpers/UserAgentHelper.h"
// Qt toolkit headers.
#include <QInputDialog>
+#include <QNetworkCookie>
#include <QStatusBar>
BrowserWindow::BrowserWindow() : KXmlGuiWindow()
searchEngineBingActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_bing"));
searchEngineYahooActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_yahoo"));
searchEngineCustomActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_custom"));
+ QAction *domainSettingsActionPointer = actionCollectionPointer->addAction(QStringLiteral("domain_settings"));
+ QAction *cookiesActionPointer = actionCollectionPointer->addAction(QStringLiteral("cookies"));
javaScriptActionPointer = actionCollectionPointer->addAction(QStringLiteral("javascript"));
localStorageActionPointer = actionCollectionPointer->addAction(QStringLiteral("local_storage"));
- domainSettingsActionPointer = actionCollectionPointer->addAction(QStringLiteral("domain_settings"));
// Create the action groups
QActionGroup *userAgentActionGroupPointer = new QActionGroup(this);
searchEngineGoogleActionPointer->setText(i18nc("Search engine", "Google"));
searchEngineBingActionPointer->setText(i18nc("Search engine", "Bing"));
searchEngineYahooActionPointer->setText(i18nc("Search engine", "Yahoo"));
- javaScriptActionPointer->setText(i18nc("JavaScript button", "JavaScript"));
- localStorageActionPointer->setText(i18nc("Local Storage Button", "Local Storage"));
- domainSettingsActionPointer->setText(i18nc("Domain Settings button", "Domain Settings"));
+ domainSettingsActionPointer->setText(i18nc("Domain Settings action", "Domain Settings"));
+ cookiesActionPointer->setText(i18nc("Cookies action", "Cookies"));
+ javaScriptActionPointer->setText(i18nc("JavaScript action", "JavaScript"));
+ localStorageActionPointer->setText(i18nc("Local Storage action", "Local Storage"));
// Set the action icons.
userAgentPrivacyBrowserActionPointer->setIcon(QIcon(":/icons/privacy-mode"));
searchEngineCustomActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("search")));
zoomFactorActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("zoom")));
domainSettingsActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("settings-configure")));
+ cookiesActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("preferences-web-browser-cookies")));
// Update the on-the-fly menus.
connect(browserViewPointer, SIGNAL(updateUserAgentActions(QString)), this, SLOT(updateUserAgentActions(QString)));
// Display dialogs.
connect(zoomFactorActionPointer, SIGNAL(triggered()), this, SLOT(getZoomFactorFromUser()));
+ connect(cookiesActionPointer, SIGNAL(triggered()), this, SLOT(openCookiesDialog()));
+ connect(domainSettingsActionPointer, SIGNAL(triggered()), this, SLOT(openDomainSettings()));
// Connect the URL toolbar actions.
connect(javaScriptActionPointer, SIGNAL(triggered()), this, SLOT(toggleJavaScript()));
connect(localStorageActionPointer, SIGNAL(triggered()), this, SLOT(toggleLocalStorage()));
- connect(domainSettingsActionPointer, SIGNAL(triggered()), this, SLOT(openDomainSettings()));
// Update the URL toolbar actions.
connect(browserViewPointer, SIGNAL(updateBackAction(bool)), backActionPointer, SLOT(setEnabled(bool)));
// Update the applied palette.
connect(browserViewPointer, SIGNAL(updateDomainSettingsIndicator(bool, QString)), this, SLOT(updateDomainSettingsIndicator(bool, QString)));
+ // Initialize the cookie list.
+ cookieListPointer = new QList<QNetworkCookie>;
+
+ // Add new cookies to the list.
+ connect(browserViewPointer, SIGNAL(addCookie(QNetworkCookie)), this, SLOT(addCookie(QNetworkCookie)));
+
// Load the initial website.
browserViewPointer->loadInitialWebsite();
}
+void BrowserWindow::addCookie(const QNetworkCookie &newCookie) const
+{
+ // Check to see if the list already contains a cookie with this ID.
+ for (QNetworkCookie existingCookie : *cookieListPointer)
+ {
+ // Remove the old version of the cookie.
+ if (existingCookie.hasSameIdentifier(newCookie)) cookieListPointer->removeOne(existingCookie);
+ }
+
+ // Add the new cookie to the list.
+ cookieListPointer->append(newCookie);
+}
+
void BrowserWindow::addOrEditDomainSettings() const
{
// Remove the focus from the URL line edit.
browserViewPointer->loadUrlFromLineEdit(url);
}
+void BrowserWindow::openCookiesDialog()
+{
+ // Remove the focus from the URL line edit.
+ urlLineEditPointer->clearFocus();
+
+ // Instantiate the cookie settings dialog.
+ CookiesDialog *cookiesDialogPointer = new CookiesDialog(cookieListPointer);
+
+ // Show the dialog.
+ cookiesDialogPointer->show();
+
+ // Connect the dialog signals.
+ connect(cookiesDialogPointer, SIGNAL(deleteAllCookies()), browserViewPointer, SLOT(deleteAllCookies()));
+}
+
+
void BrowserWindow::openDomainSettings() const
{
// Remove the focus from the URL line edit.
// Instantiate the domain settings dialog.
DomainSettingsDialog *domainSettingsDialogPointer = new DomainSettingsDialog();
- // Set the dialog window title.
- domainSettingsDialogPointer->setWindowTitle(i18nc("The domain settings dialog title", "Domain Settings"));
-
- // Set the modality.
- domainSettingsDialogPointer->setWindowModality(Qt::WindowModality::WindowModal);;
-
// Show the dialog.
domainSettingsDialogPointer->show();
private Q_SLOTS:
// The private slots.
+ void addCookie(const QNetworkCookie &newCookie) const;
void addOrEditDomainSettings() const;
void back() const;
void clearUrlLineEditFocus() const;
void getZoomFactorFromUser();
void home() const;
void loadUrlFromLineEdit(const QString &url) const;
+ void openCookiesDialog();
void openDomainSettings() const;
void refresh() const;
void settingsConfigure();
// The private variables.
BrowserView *browserViewPointer;
KConfigDialog *configDialogPointer;
+ QList<QNetworkCookie> *cookieListPointer;
QString currentDomainSettingsDomain;
QUrl currentUrl;
double currentZoomFactor;
- QAction *domainSettingsActionPointer;
QPalette domainSettingsPalette;
QAction *javaScriptActionPointer;
QAction *localStorageActionPointer;