From 2facce32fb6d97b52a7dc148044cae4b36a65d4c Mon Sep 17 00:00:00 2001 From: Soren Stoutner Date: Tue, 17 May 2022 16:10:23 -0700 Subject: [PATCH] Rename Local Storage to DOM Storage. https://redmine.stoutner.com/issues/852 --- src/CMakeLists.txt | 15 +-- src/dialogs/AddOrEditCookieDialog.cpp | 1 + src/dialogs/CookiesDialog.cpp | 3 +- src/dialogs/CookiesDialog.h | 6 +- src/dialogs/DomainSettingsDialog.cpp | 51 +++++----- src/dialogs/DomainSettingsDialog.h | 8 +- src/filters/MouseEventFilter.cpp | 1 + src/helpers/DomainsDatabaseHelper.cpp | 10 +- src/helpers/DomainsDatabaseHelper.h | 2 +- src/helpers/SearchEngineHelper.cpp | 2 +- src/helpers/UserAgentHelper.cpp | 2 +- src/icons/cookies-off.svg | 54 +++++++++++ src/icons/cookies-on.svg | 59 ++++++++++++ src/interceptors/UrlRequestInterceptor.cpp | 2 +- src/resources.qrc | 2 + src/settings/Settings.kcfg | 8 +- src/settings/Settings.kcfgc | 2 +- src/structs/CMakeLists.txt | 22 +++++ src/structs/PrivacyWebEngine.cpp | 28 ++++++ src/structs/PrivacyWebEngine.h | 36 +++++++ src/{ui.rc => ui.rcs}/CMakeLists.txt | 0 src/{ui.rc => ui.rcs}/browser_ui.rc | 3 +- src/{ui => uis}/AddOrEditCookieDialog.ui | 0 src/{ui => uis}/BrowserView.ui | 0 src/{ui => uis}/CookiesDialog.ui | 0 src/{ui => uis}/DomainSettingsDialog.ui | 99 ++++++++++++++------ src/{ui => uis}/SettingsGeneral.ui | 23 ++--- src/{ui => uis}/SettingsPrivacy.ui | 37 +++++--- src/views/BrowserView.cpp | 80 +++++++++++++--- src/views/BrowserView.h | 13 ++- src/windows/BrowserWindow.cpp | 104 ++++++++++++++++----- src/windows/BrowserWindow.h | 18 ++-- 32 files changed, 546 insertions(+), 145 deletions(-) create mode 100644 src/icons/cookies-off.svg create mode 100644 src/icons/cookies-on.svg create mode 100644 src/structs/CMakeLists.txt create mode 100644 src/structs/PrivacyWebEngine.cpp create mode 100644 src/structs/PrivacyWebEngine.h rename src/{ui.rc => ui.rcs}/CMakeLists.txt (100%) rename src/{ui.rc => ui.rcs}/browser_ui.rc (97%) rename src/{ui => uis}/AddOrEditCookieDialog.ui (100%) rename src/{ui => uis}/BrowserView.ui (100%) rename src/{ui => uis}/CookiesDialog.ui (100%) rename src/{ui => uis}/DomainSettingsDialog.ui (83%) rename src/{ui => uis}/SettingsGeneral.ui (98%) rename src/{ui => uis}/SettingsPrivacy.ui (77%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9729c95..fb70231 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -35,12 +35,12 @@ kconfig_add_kcfg_files(privacy-browser settings/Settings.kcfgc) # Use KDE Frameworks to handle internationalization of the following UI files. ki18n_wrap_ui(privacy-browser - ui/AddOrEditCookieDialog.ui - ui/BrowserView.ui - ui/CookiesDialog.ui - ui/DomainSettingsDialog.ui - ui/SettingsGeneral.ui - ui/SettingsPrivacy.ui + uis/AddOrEditCookieDialog.ui + uis/BrowserView.ui + uis/CookiesDialog.ui + uis/DomainSettingsDialog.ui + uis/SettingsGeneral.ui + uis/SettingsPrivacy.ui ) # Link the following libraries. @@ -66,7 +66,8 @@ add_subdirectory(dialogs) add_subdirectory(filters) add_subdirectory(helpers) add_subdirectory(interceptors) -add_subdirectory(ui.rc) +add_subdirectory(structs) +add_subdirectory(ui.rcs) add_subdirectory(views) add_subdirectory(windows) diff --git a/src/dialogs/AddOrEditCookieDialog.cpp b/src/dialogs/AddOrEditCookieDialog.cpp index 1b0a944..78234a6 100644 --- a/src/dialogs/AddOrEditCookieDialog.cpp +++ b/src/dialogs/AddOrEditCookieDialog.cpp @@ -32,6 +32,7 @@ const int AddOrEditCookieDialog::AddCookie = 0; const int AddOrEditCookieDialog::EditCookie = 1; +// Construct the class. AddOrEditCookieDialog::AddOrEditCookieDialog(const int &dialogType, const QNetworkCookie *cookiePointer) : QDialog(nullptr) { // Set the dialog window title according to the dialog type. diff --git a/src/dialogs/CookiesDialog.cpp b/src/dialogs/CookiesDialog.cpp index 5763cb9..b200891 100644 --- a/src/dialogs/CookiesDialog.cpp +++ b/src/dialogs/CookiesDialog.cpp @@ -31,6 +31,7 @@ #include #include +// Construct the class. bool cookieSortPredicate(const QNetworkCookie &leftHandCookie, const QNetworkCookie &rightHandCookie) { // Check to see if the domains are identical. @@ -99,7 +100,7 @@ bool cookieSortPredicate(const QNetworkCookie &leftHandCookie, const QNetworkCoo } } -CookiesDialog::CookiesDialog(std::forward_list *originalCookieListPointer) : QDialog(nullptr), cookieListPointer(originalCookieListPointer) +CookiesDialog::CookiesDialog(std::list *originalCookieListPointer) : QDialog(nullptr), cookieListPointer(originalCookieListPointer) { // Set the dialog window title. setWindowTitle(i18nc("The cookies dialog window title", "Cookies")); diff --git a/src/dialogs/CookiesDialog.h b/src/dialogs/CookiesDialog.h index 770a846..f34beca 100644 --- a/src/dialogs/CookiesDialog.h +++ b/src/dialogs/CookiesDialog.h @@ -28,7 +28,7 @@ #include // C++ headers. -#include +#include class CookiesDialog : public QDialog { @@ -37,7 +37,7 @@ class CookiesDialog : public QDialog public: // The primary constructor. - explicit CookiesDialog(std::forward_list *cookieListPointer); + explicit CookiesDialog(std::list *cookieListPointer); signals: // The signals. @@ -59,7 +59,7 @@ private: // The private variables. QItemSelectionModel *treeViewSelectionModelPointer; QPushButton *addCookieButtonPointer; - std::forward_list *cookieListPointer; + std::list *cookieListPointer; QPushButton *deleteAllButtonPointer; QPushButton *deleteCookieButtonPointer; QPushButton *editCookieButtonPointer; diff --git a/src/dialogs/DomainSettingsDialog.cpp b/src/dialogs/DomainSettingsDialog.cpp index 32d61d0..eb43fb5 100644 --- a/src/dialogs/DomainSettingsDialog.cpp +++ b/src/dialogs/DomainSettingsDialog.cpp @@ -34,6 +34,7 @@ const int DomainSettingsDialog::SHOW_ALL_DOMAINS = 0; const int DomainSettingsDialog::ADD_DOMAIN = 1; const int DomainSettingsDialog::EDIT_DOMAIN = 2; +// Construct the class. DomainSettingsDialog::DomainSettingsDialog(const int &startType, const QString &domainName) : QDialog(nullptr) { // Set the window title. @@ -48,14 +49,14 @@ DomainSettingsDialog::DomainSettingsDialog(const int &startType, const QString & // Setup the UI. domainSettingsDialogUi.setupUi(this); - // Get handles for the views. + // Get handles for the widgets. domainsListViewPointer = domainSettingsDialogUi.domainsListView; domainSettingsWidgetPointer = domainSettingsDialogUi.domainSettingsWidget; domainNameLineEditPointer = domainSettingsDialogUi.domainNameLineEdit; javaScriptComboBoxPointer = domainSettingsDialogUi.javaScriptComboBox; javaScriptLabelPointer = domainSettingsDialogUi.javaScriptLabel; - localStorageComboBoxPointer = domainSettingsDialogUi.localStorageComboBox; - localStorageLabelPointer = domainSettingsDialogUi.localStorageLabel; + domStorageComboBoxPointer = domainSettingsDialogUi.domStorageComboBox; + domStorageLabelPointer = domainSettingsDialogUi.domStorageLabel; userAgentComboBoxPointer = domainSettingsDialogUi.userAgentComboBox; userAgentLabelPointer = domainSettingsDialogUi.userAgentLabel; zoomFactorComboBoxPointer = domainSettingsDialogUi.zoomFactorComboBox; @@ -129,10 +130,10 @@ DomainSettingsDialog::DomainSettingsDialog(const int &startType, const QString & // Handle clicks on the domains. connect(domainsListViewPointer, SIGNAL(activated(QModelIndex)), this, SLOT(domainSelected(QModelIndex))); - // Connect the domain settings. + // Process changes to the domain settings. connect(domainNameLineEditPointer, SIGNAL(textEdited(QString)), this, SLOT(domainNameChanged(QString))); connect(javaScriptComboBoxPointer, SIGNAL(currentIndexChanged(int)), this, SLOT(javaScriptChanged(int))); - connect(localStorageComboBoxPointer, SIGNAL(currentIndexChanged(int)), this, SLOT(localStorageChanged(int))); + connect(domStorageComboBoxPointer, SIGNAL(currentIndexChanged(int)), this, SLOT(domStorageChanged(int))); connect(userAgentComboBoxPointer, SIGNAL(currentTextChanged(QString)), this, SLOT(userAgentChanged(QString))); connect(zoomFactorComboBoxPointer, SIGNAL(currentIndexChanged(int)), this, SLOT(zoomFactorComboBoxChanged(int))); connect(customZoomFactorSpinBoxPointer, SIGNAL(valueChanged(double)), this, SLOT(customZoomFactorChanged(double))); @@ -157,7 +158,7 @@ void DomainSettingsDialog::addDomain(const QString &domainName) const // Set the values for the new domain. newDomainRecord.setValue(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::DOMAIN_NAME), domainName); newDomainRecord.setValue(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::JAVASCRIPT), DomainsDatabaseHelper::SYSTEM_DEFAULT); - newDomainRecord.setValue(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::LOCAL_STORAGE), DomainsDatabaseHelper::SYSTEM_DEFAULT); + newDomainRecord.setValue(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::DOM_STORAGE), DomainsDatabaseHelper::SYSTEM_DEFAULT); newDomainRecord.setValue(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::USER_AGENT), UserAgentHelper::SYSTEM_DEFAULT_DATABASE); newDomainRecord.setValue(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::ZOOM_FACTOR), DomainsDatabaseHelper::SYSTEM_DEFAULT); newDomainRecord.setValue(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::CUSTOM_ZOOM_FACTOR), 1.0); @@ -244,8 +245,8 @@ void DomainSettingsDialog::domainSelected(const QModelIndex &modelIndex) const // Populate the JavaScript combo box. javaScriptComboBoxPointer->setCurrentIndex(modelIndex.siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::JAVASCRIPT)).data().toInt()); - // Populate the local storage combo box. - localStorageComboBoxPointer->setCurrentIndex(modelIndex.siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::LOCAL_STORAGE)).data().toInt()); + // Populate the DOM storage combo box. + domStorageComboBoxPointer->setCurrentIndex(modelIndex.siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::DOM_STORAGE)).data().toInt()); // Get the user agent string. QString userAgent = modelIndex.siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::USER_AGENT)).data().toString(); @@ -282,7 +283,7 @@ void DomainSettingsDialog::domainSelected(const QModelIndex &modelIndex) const // Populate the labels. populateJavaScriptLabel(); - populateLocalStorageLabel(); + populateDomStorageLabel(); populateUserAgentLabel(userAgentComboBoxPointer->currentText()); // Update the UI. @@ -302,14 +303,14 @@ void DomainSettingsDialog::javaScriptChanged(const int &newIndex) const updateUi(); } -void DomainSettingsDialog::localStorageChanged(const int &newIndex) const +void DomainSettingsDialog::domStorageChanged(const int &newIndex) const { // Update the domains table model. - domainsTableModelPointer->setData(domainsListViewPointer->selectionModel()->currentIndex().siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::LOCAL_STORAGE)), + domainsTableModelPointer->setData(domainsListViewPointer->selectionModel()->currentIndex().siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::DOM_STORAGE)), newIndex); - // Populate the local storage label. - populateLocalStorageLabel(); + // Populate the DOM storage label. + populateDomStorageLabel(); // Update the UI. updateUi(); @@ -335,8 +336,10 @@ void DomainSettingsDialog::populateJavaScriptLabel() const case (DomainsDatabaseHelper::SYSTEM_DEFAULT): { // Set the text according to the system default. - if (Settings::javaScript()) javaScriptLabelPointer->setText(i18nc("Domains settings label", "JavaScript enabled")); - else javaScriptLabelPointer->setText(i18nc("Domain settings label", "JavaScript disabled")); + if (Settings::javaScriptEnabled()) + javaScriptLabelPointer->setText(i18nc("Domains settings label", "JavaScript enabled")); + else + javaScriptLabelPointer->setText(i18nc("Domain settings label", "JavaScript disabled")); break; } @@ -344,7 +347,7 @@ void DomainSettingsDialog::populateJavaScriptLabel() const case (DomainsDatabaseHelper::DISABLED): { // Set the label text in bold. - javaScriptLabelPointer->setText(i18nc("Domain settings label. The tags should be retained.", "JavaScript disabled")); + javaScriptLabelPointer->setText(i18nc("Domain settings label. The tags should be retained.", "JavaScript disabled")); break; } @@ -352,23 +355,25 @@ void DomainSettingsDialog::populateJavaScriptLabel() const case (DomainsDatabaseHelper::ENABLED): { // Set the label text in bold. - javaScriptLabelPointer->setText(i18nc("Domains settings label. The tags should be retained.", "JavaScript enabled")); + javaScriptLabelPointer->setText(i18nc("Domains settings label. The tags should be retained.", "JavaScript enabled")); break; } } } -void DomainSettingsDialog::populateLocalStorageLabel() const +void DomainSettingsDialog::populateDomStorageLabel() const { // Populate the label according to the currently selected index. - switch (localStorageComboBoxPointer->currentIndex()) + switch (domStorageComboBoxPointer->currentIndex()) { case (DomainsDatabaseHelper::SYSTEM_DEFAULT): { // Set the text according to the system default. - if (Settings::localStorage()) localStorageLabelPointer->setText(i18nc("Local storage label", "Local storage enabled")); - else localStorageLabelPointer->setText(i18nc("Local storage label", "Local storage disabled")); + if (Settings::domStorageEnabled()) + domStorageLabelPointer->setText(i18nc("DOM storage label", "DOM storage enabled")); + else + domStorageLabelPointer->setText(i18nc("DOM storage label", "DOM storage disabled")); break; } @@ -376,7 +381,7 @@ void DomainSettingsDialog::populateLocalStorageLabel() const case (DomainsDatabaseHelper::DISABLED): { // Set the label text in bold. - localStorageLabelPointer->setText(i18nc("Local storage label. The tags should be retained.", "Local storage disabled")); + domStorageLabelPointer->setText(i18nc("DOM storage label. The tags should be retained.", "DOM storage disabled")); break; } @@ -384,7 +389,7 @@ void DomainSettingsDialog::populateLocalStorageLabel() const case (DomainsDatabaseHelper::ENABLED): { // Set the label text in bold. - localStorageLabelPointer->setText(i18nc("Local storage label. The tags should be retained.", "Local storage enabled")); + domStorageLabelPointer->setText(i18nc("DOM storage label. The tags should be retained.", "DOM storage enabled")); break; } diff --git a/src/dialogs/DomainSettingsDialog.h b/src/dialogs/DomainSettingsDialog.h index 5663787..a96c0d0 100644 --- a/src/dialogs/DomainSettingsDialog.h +++ b/src/dialogs/DomainSettingsDialog.h @@ -51,10 +51,10 @@ private Q_SLOTS: void apply() const; void cancel(); void customZoomFactorChanged(const double &newValue) const; + void domStorageChanged(const int &newIndex) const; void domainNameChanged(const QString &updatedDomainName) const; void domainSelected(const QModelIndex &modelIndex) const; void javaScriptChanged(const int &newIndex) const; - void localStorageChanged(const int &newIndex) const; void ok(); void reset() const; void showAddMessageBox(); @@ -67,14 +67,14 @@ private: QPushButton *applyButtonPointer; QDoubleSpinBox *customZoomFactorSpinBoxPointer; QPushButton *deleteDomainButtonPointer; + QComboBox *domStorageComboBoxPointer; + QLabel *domStorageLabelPointer; QListView *domainsListViewPointer; KLineEdit *domainNameLineEditPointer; QWidget *domainSettingsWidgetPointer; QSqlTableModel *domainsTableModelPointer; QComboBox *javaScriptComboBoxPointer; QLabel *javaScriptLabelPointer; - QComboBox *localStorageComboBoxPointer; - QLabel *localStorageLabelPointer; QPushButton *resetButtonPointer; QComboBox *userAgentComboBoxPointer; QLabel *userAgentLabelPointer; @@ -83,7 +83,7 @@ private: // The private functions. void addDomain(const QString &domainName) const; void populateJavaScriptLabel() const; - void populateLocalStorageLabel() const; + void populateDomStorageLabel() const; void populateUserAgentLabel(const QString &userAgentName) const; void updateUi() const; }; diff --git a/src/filters/MouseEventFilter.cpp b/src/filters/MouseEventFilter.cpp index 51bbb09..b6cb81f 100644 --- a/src/filters/MouseEventFilter.cpp +++ b/src/filters/MouseEventFilter.cpp @@ -27,6 +27,7 @@ // The primary constructor. MouseEventFilter::MouseEventFilter() : QObject() {}; +// Construct the class. bool MouseEventFilter::eventFilter(QObject *objectPointer, QEvent *eventPointer) { // Only process mouse button press events. diff --git a/src/helpers/DomainsDatabaseHelper.cpp b/src/helpers/DomainsDatabaseHelper.cpp index 6ed8716..2d63bd9 100644 --- a/src/helpers/DomainsDatabaseHelper.cpp +++ b/src/helpers/DomainsDatabaseHelper.cpp @@ -32,12 +32,12 @@ const int DomainsDatabaseHelper::SCHEMA_VERSION = 4; const QString DomainsDatabaseHelper::_ID = "_id"; const QString DomainsDatabaseHelper::DOMAIN_NAME = "domain_name"; const QString DomainsDatabaseHelper::JAVASCRIPT = "javascript"; -const QString DomainsDatabaseHelper::LOCAL_STORAGE = "local_storage"; +const QString DomainsDatabaseHelper::DOM_STORAGE = "dom_storage"; const QString DomainsDatabaseHelper::USER_AGENT = "user_agent"; const QString DomainsDatabaseHelper::ZOOM_FACTOR = "zoom_factor"; const QString DomainsDatabaseHelper::CUSTOM_ZOOM_FACTOR = "custom_zoom_factor"; -// The default constructor. +// Construct the class. DomainsDatabaseHelper::DomainsDatabaseHelper() {} void DomainsDatabaseHelper::addDatabase() @@ -102,8 +102,8 @@ void DomainsDatabaseHelper::addDatabase() // Upgrade from schema version 3 to schema version 4. case 3: - // Add the Local Storage column. - domainsDatabase.exec("ALTER TABLE " + DOMAINS_TABLE + " ADD COLUMN " + LOCAL_STORAGE + " INTEGER DEFAULT 0"); + // Add the DOM Storage column. + domainsDatabase.exec("ALTER TABLE " + DOMAINS_TABLE + " ADD COLUMN " + DOM_STORAGE + " INTEGER DEFAULT 0"); } // Update the schema version. @@ -120,7 +120,7 @@ void DomainsDatabaseHelper::addDatabase() _ID + " INTEGER PRIMARY KEY, " + DOMAIN_NAME + " TEXT, " + JAVASCRIPT + " INTEGER DEFAULT 0, " + - LOCAL_STORAGE + " INTEGER DEFAULT 0, " + + DOM_STORAGE + " INTEGER DEFAULT 0, " + USER_AGENT + " TEXT DEFAULT '" + UserAgentHelper::SYSTEM_DEFAULT_DATABASE + "', " + ZOOM_FACTOR + " INTEGER DEFAULT 0, " + CUSTOM_ZOOM_FACTOR + " REAL DEFAULT 1.0)" diff --git a/src/helpers/DomainsDatabaseHelper.h b/src/helpers/DomainsDatabaseHelper.h index 2ec812b..9ab0f92 100644 --- a/src/helpers/DomainsDatabaseHelper.h +++ b/src/helpers/DomainsDatabaseHelper.h @@ -43,10 +43,10 @@ public: static const QString _ID; static const QString CONNECTION_NAME; static const QString CUSTOM_ZOOM_FACTOR; + static const QString DOM_STORAGE; static const QString DOMAIN_NAME; static const QString DOMAINS_TABLE; static const QString JAVASCRIPT; - static const QString LOCAL_STORAGE; static const QString USER_AGENT; static const QString ZOOM_FACTOR; diff --git a/src/helpers/SearchEngineHelper.cpp b/src/helpers/SearchEngineHelper.cpp index 8291926..8c0feb4 100644 --- a/src/helpers/SearchEngineHelper.cpp +++ b/src/helpers/SearchEngineHelper.cpp @@ -20,7 +20,7 @@ // Application headers. #include "SearchEngineHelper.h" -// The default constructor. +// Construct the class. SearchEngineHelper::SearchEngineHelper() {}; QString SearchEngineHelper::getSearchUrl(const QString &searchEngineName) diff --git a/src/helpers/UserAgentHelper.cpp b/src/helpers/UserAgentHelper.cpp index 9a51f22..634f16b 100644 --- a/src/helpers/UserAgentHelper.cpp +++ b/src/helpers/UserAgentHelper.cpp @@ -56,7 +56,7 @@ const QString UserAgentHelper::CHROME_WINDOWS_USER_AGENT = QStringLiteral("Mozil const QString UserAgentHelper::EDGE_WINDOWS_USER_AGENT = QStringLiteral("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36 Edg/98.0.1108.56"); const QString UserAgentHelper::SAFARI_MACOS_USER_AGENT = QStringLiteral("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.1 Safari/605.1.15"); -// The default constructor. +// Construct the class. UserAgentHelper::UserAgentHelper() {}; QString UserAgentHelper::getDatabaseUserAgentNameFromTranslatedName(const QString &translatedUserAgentName) diff --git a/src/icons/cookies-off.svg b/src/icons/cookies-off.svg new file mode 100644 index 0000000..7f84085 --- /dev/null +++ b/src/icons/cookies-off.svg @@ -0,0 +1,54 @@ + + + + + + + + diff --git a/src/icons/cookies-on.svg b/src/icons/cookies-on.svg new file mode 100644 index 0000000..191f07a --- /dev/null +++ b/src/icons/cookies-on.svg @@ -0,0 +1,59 @@ + + + + + + + + + + + diff --git a/src/interceptors/UrlRequestInterceptor.cpp b/src/interceptors/UrlRequestInterceptor.cpp index 2b9bd05..d405928 100644 --- a/src/interceptors/UrlRequestInterceptor.cpp +++ b/src/interceptors/UrlRequestInterceptor.cpp @@ -20,7 +20,7 @@ // Application headers. #include "UrlRequestInterceptor.h" -// The default constructor. +// Construct the class. UrlRequestInterceptor::UrlRequestInterceptor(QObject *parentObjectPointer) : QWebEngineUrlRequestInterceptor(parentObjectPointer) {} void UrlRequestInterceptor::interceptRequest(QWebEngineUrlRequestInfo &urlRequestInfo) diff --git a/src/resources.qrc b/src/resources.qrc index cfa6f79..a311b84 100644 --- a/src/resources.qrc +++ b/src/resources.qrc @@ -19,6 +19,8 @@ + icons/cookies-off.svg + icons/cookies-on.svg icons/javascript-warning.svg icons/privacy-mode.svg icons/sc-apps-privacy-browser.svg diff --git a/src/settings/Settings.kcfg b/src/settings/Settings.kcfg index c5435fa..10d08f3 100644 --- a/src/settings/Settings.kcfg +++ b/src/settings/Settings.kcfg @@ -28,11 +28,15 @@ - + false - + + false + + + false diff --git a/src/settings/Settings.kcfgc b/src/settings/Settings.kcfgc index 3129834..42940f7 100644 --- a/src/settings/Settings.kcfgc +++ b/src/settings/Settings.kcfgc @@ -22,5 +22,5 @@ File=Settings.kcfg # Specify the class name, which will be used to autogenerate .cpp and .h files. ClassName=Settings -# Make the generated class a singleton. TODO, the default is false. This may not be needed. +# Make the generated class a singleton. Singleton=true diff --git a/src/structs/CMakeLists.txt b/src/structs/CMakeLists.txt new file mode 100644 index 0000000..9e6e2cb --- /dev/null +++ b/src/structs/CMakeLists.txt @@ -0,0 +1,22 @@ +# Copyright © 2022 Soren Stoutner . +# +# This file is part of 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 . + + +# List the sources to include in the executable. +target_sources(privacy-browser PRIVATE + PrivacyWebEngine.cpp +) diff --git a/src/structs/PrivacyWebEngine.cpp b/src/structs/PrivacyWebEngine.cpp new file mode 100644 index 0000000..14ccad7 --- /dev/null +++ b/src/structs/PrivacyWebEngine.cpp @@ -0,0 +1,28 @@ +/* + * Copyright © 2022 Soren Stoutner . + * + * This file is part of 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 . + */ + +// Application headers. +#include "PrivacyWebEngine.h" + +// Construct the struct. +PrivacyWebEngine::PrivacyWebEngine(QWebEngineView *inputWebEngineViewPointer) : webEngineViewPointer(inputWebEngineViewPointer) +{ + // Initialize the cookie status. + cookiesEnabled = false; +} diff --git a/src/structs/PrivacyWebEngine.h b/src/structs/PrivacyWebEngine.h new file mode 100644 index 0000000..b536c4f --- /dev/null +++ b/src/structs/PrivacyWebEngine.h @@ -0,0 +1,36 @@ +/* + * Copyright © 2022 Soren Stoutner . + * + * This file is part of 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 . + */ + +#ifndef PRIVACYWEBENGINE_H +#define PRIVACYWEBENGINE_H + +// Qt toolkit headers. +#include + +struct PrivacyWebEngine +{ +public: + // The primary constructor. + PrivacyWebEngine(QWebEngineView *inputWebEngineViewPointer); + + // The public variables. + bool cookiesEnabled; + QWebEngineView *webEngineViewPointer; +}; +#endif diff --git a/src/ui.rc/CMakeLists.txt b/src/ui.rcs/CMakeLists.txt similarity index 100% rename from src/ui.rc/CMakeLists.txt rename to src/ui.rcs/CMakeLists.txt diff --git a/src/ui.rc/browser_ui.rc b/src/ui.rcs/browser_ui.rc similarity index 97% rename from src/ui.rc/browser_ui.rc rename to src/ui.rcs/browser_ui.rc index e75b573..fd80ccb 100644 --- a/src/ui.rc/browser_ui.rc +++ b/src/ui.rcs/browser_ui.rc @@ -79,6 +79,7 @@ URL Toolbar - + + diff --git a/src/ui/AddOrEditCookieDialog.ui b/src/uis/AddOrEditCookieDialog.ui similarity index 100% rename from src/ui/AddOrEditCookieDialog.ui rename to src/uis/AddOrEditCookieDialog.ui diff --git a/src/ui/BrowserView.ui b/src/uis/BrowserView.ui similarity index 100% rename from src/ui/BrowserView.ui rename to src/uis/BrowserView.ui diff --git a/src/ui/CookiesDialog.ui b/src/uis/CookiesDialog.ui similarity index 100% rename from src/ui/CookiesDialog.ui rename to src/uis/CookiesDialog.ui diff --git a/src/ui/DomainSettingsDialog.ui b/src/uis/DomainSettingsDialog.ui similarity index 83% rename from src/ui/DomainSettingsDialog.ui rename to src/uis/DomainSettingsDialog.ui index ae9322d..1972848 100644 --- a/src/ui/DomainSettingsDialog.ui +++ b/src/uis/DomainSettingsDialog.ui @@ -94,32 +94,32 @@ Domain name - - - - *. may be prepended to a domain to include all subdomains (eg. *.stoutner.com). + + + + JavaScript - - - - JavaScript allows websites to run programs (scripts) on the device. + + + + System default @@ -148,21 +148,64 @@ - + - Local storage + Cookies + + + + Local storage includes cookies, IndexedDB, DOM storage, filesystem API, and service workers. DOM storage also requires a separate control to be enabled. Local storage is disabled by default. - + + + + System default + + + + + + Cookies enabled + + + + + + Cookies disabled + + + + + + + + + Qt::RichText + + + + + + + + + DOM storage + + - Local storage, sometimes also called DOM storage, is like cookies on steroids. + DOM storage, sometimes called web storage, is like cookies on steroids. To function, it requires that both JavaScript and local storage be enabled. + + + + System default @@ -171,20 +214,20 @@ - Local storage disabled + DOM storage disabled - Local storage enabled + DOM storage enabled - - + + Qt::RichText @@ -192,15 +235,19 @@ - + User agent + + + The user agent identifies the browser to the web server. It serves no useful purpose, but many web servers refuse to return the web page if they don't see a user agent they like. + - + @@ -269,7 +316,7 @@ - + Qt::RichText @@ -278,15 +325,19 @@ - + Zoom factor + + + Set the zoom factor between 0.25 and 5.00. + - + @@ -302,12 +353,8 @@ - + - - Set the zoom factor between 0.25 and 5.00. The default is 1.00. - - 0.250000000000000 diff --git a/src/ui/SettingsGeneral.ui b/src/uis/SettingsGeneral.ui similarity index 98% rename from src/ui/SettingsGeneral.ui rename to src/uis/SettingsGeneral.ui index 65b693e..425ea65 100644 --- a/src/ui/SettingsGeneral.ui +++ b/src/uis/SettingsGeneral.ui @@ -30,23 +30,27 @@ Homepage - - - - The default is https://www.mojeek.com/. + + + + Search engine + + + The default is Mojeek. + @@ -59,10 +63,6 @@ - - The default is Mojeek. - - true @@ -119,14 +119,15 @@ Zoom factor + + + Set the zoom factor between 0.25 and 5.00. The default is 1.00. + - - Set the zoom factor between 0.25 and 5.00. The default is 1.00. - 0.250000000000000 diff --git a/src/ui/SettingsPrivacy.ui b/src/uis/SettingsPrivacy.ui similarity index 77% rename from src/ui/SettingsPrivacy.ui rename to src/uis/SettingsPrivacy.ui index 6fa7c5b..6989f2a 100644 --- a/src/ui/SettingsPrivacy.ui +++ b/src/uis/SettingsPrivacy.ui @@ -26,7 +26,7 @@ - + JavaScript @@ -37,29 +37,46 @@ - + - + - Local storage + Cookies - Local storage, sometimes also called DOM storage, is like cookies on steroids. + Local storage includes cookies, IndexedDB, DOM storage, filesystem API, and service workers. DOM storage also requires a separate control to be enabled. Local storage is disabled by default. + + + + + + + + + DOM storage + + + + DOM storage, sometimes called web storage, is like cookies on steroids. To function, it requires that both JavaScript and local storage be enabled. It is disabled by default. - + User agent + + + The user agent identifies the browser to the web server. It serves no useful purpose, but many web servers refuse to return the web page if they don't see a user agent they like. The default is Privacy Browser. + - + @@ -68,10 +85,6 @@ - - The default is Privacy Browser. - - true @@ -126,7 +139,7 @@ - + Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse diff --git a/src/views/BrowserView.cpp b/src/views/BrowserView.cpp index 82e7e3e..777d12e 100644 --- a/src/views/BrowserView.cpp +++ b/src/views/BrowserView.cpp @@ -34,8 +34,12 @@ // Initialize the public static variables. QString BrowserView::webEngineDefaultUserAgent = QStringLiteral(""); +// Construct the class. BrowserView::BrowserView(QWidget *parent) : QWidget(parent) { + // Initialize the variables. + privacyWebEngineListPointer = new QList; + // Instantiate the browser view UI. Ui::BrowserView browserViewUi; @@ -59,6 +63,33 @@ BrowserView::BrowserView(QWidget *parent) : QWidget(parent) webEngineSettingsPointer = webEngineViewPointer->settings(); webEngineCookieStorePointer = webEngineProfilePointer->cookieStore(); + // Initialize the current privacy web engine pointer. + currentPrivacyWebEnginePointer = new PrivacyWebEngine(webEngineViewPointer); + + // Populate the privacy web engine list. + privacyWebEngineListPointer->append(currentPrivacyWebEnginePointer); + + // Set the cookie filter. + webEngineCookieStorePointer->setCookieFilter([this](const QWebEngineCookieStore::FilterRequest &filterRequest) + { + // qDebug() << "Cookie page URL: " << filterRequest.firstPartyUrl << ", Cookie URL: " << filterRequest.origin << ", Is third-party: " << filterRequest.thirdParty; + + // Block all third party local storage requests, including the sneaky ones that don't register a first party URL. + if (filterRequest.thirdParty || (filterRequest.firstPartyUrl == QStringLiteral(""))) + return false; + + // Check each tab to see if this local storage request should be allowed. + for (PrivacyWebEngine *privacyWebEnginePointer : *privacyWebEngineListPointer) + { + // Allow this local storage request if it comes from a tab with local storage enabled. + if (privacyWebEnginePointer->cookiesEnabled && (webEngineViewPointer->url().host() == filterRequest.firstPartyUrl.host())) + return true; + } + + // Block any remaining local storage requests. + return false; + }); + // Process cookie changes. connect(webEngineCookieStorePointer, SIGNAL(cookieAdded(QNetworkCookie)), this, SLOT(cookieAdded(QNetworkCookie))); connect(webEngineCookieStorePointer, SIGNAL(cookieRemoved(QNetworkCookie)), this, SLOT(cookieRemoved(QNetworkCookie))); @@ -185,7 +216,7 @@ void BrowserView::applyDomainSettings(const QString &hostname, const bool reload case (DomainsDatabaseHelper::SYSTEM_DEFAULT): { // Set the default JavaScript status. - webEngineSettingsPointer->setAttribute(QWebEngineSettings::JavascriptEnabled, Settings::javaScript()); + webEngineSettingsPointer->setAttribute(QWebEngineSettings::JavascriptEnabled, Settings::javaScriptEnabled()); break; } @@ -207,20 +238,23 @@ void BrowserView::applyDomainSettings(const QString &hostname, const bool reload } } - // Set local storage. - switch (domainRecord.field(DomainsDatabaseHelper::LOCAL_STORAGE).value().toInt()) + // Set the cookie status. TODO. + currentPrivacyWebEnginePointer->cookiesEnabled = Settings::cookiesEnabled(); + + // Set DOM storage. + switch (domainRecord.field(DomainsDatabaseHelper::DOM_STORAGE).value().toInt()) { case (DomainsDatabaseHelper::SYSTEM_DEFAULT): { - // Set the default local storage status. - webEngineSettingsPointer->setAttribute(QWebEngineSettings::LocalStorageEnabled, Settings::localStorage()); + // Set the default DOM storage status. + webEngineSettingsPointer->setAttribute(QWebEngineSettings::LocalStorageEnabled, Settings::domStorageEnabled()); break; } case (DomainsDatabaseHelper::DISABLED): { - // Disable local storage. + // Disable DOM storage. webEngineSettingsPointer->setAttribute(QWebEngineSettings::LocalStorageEnabled, false); break; @@ -228,7 +262,7 @@ void BrowserView::applyDomainSettings(const QString &hostname, const bool reload case (DomainsDatabaseHelper::ENABLED): { - // Enable local storage. + // Enable DOM storage. webEngineSettingsPointer->setAttribute(QWebEngineSettings::LocalStorageEnabled, true); break; @@ -259,10 +293,13 @@ void BrowserView::applyDomainSettings(const QString &hostname, const bool reload else // The hostname does not have domain settings. { // Set the JavaScript status. - webEngineSettingsPointer->setAttribute(QWebEngineSettings::JavascriptEnabled, Settings::javaScript()); + webEngineSettingsPointer->setAttribute(QWebEngineSettings::JavascriptEnabled, Settings::javaScriptEnabled()); + + // Set the cookie status. + currentPrivacyWebEnginePointer->cookiesEnabled = Settings::cookiesEnabled(); - // Set local storage. - webEngineSettingsPointer->setAttribute(QWebEngineSettings::LocalStorageEnabled, Settings::localStorage()); + // Set DOM storage. + webEngineSettingsPointer->setAttribute(QWebEngineSettings::LocalStorageEnabled, Settings::domStorageEnabled()); // Set the user agent. webEngineProfilePointer->setHttpUserAgent(UserAgentHelper::getUserAgentFromDatabaseName(Settings::userAgent())); @@ -279,7 +316,8 @@ void BrowserView::applyDomainSettings(const QString &hostname, const bool reload // Emit the update actions signals. emit updateJavaScriptAction(webEngineSettingsPointer->testAttribute(QWebEngineSettings::JavascriptEnabled)); - emit updateLocalStorageAction(webEngineSettingsPointer->testAttribute(QWebEngineSettings::LocalStorageEnabled)); + emit updateCookiesAction(currentPrivacyWebEnginePointer->cookiesEnabled); + emit updateDomStorageAction(webEngineSettingsPointer->testAttribute(QWebEngineSettings::LocalStorageEnabled)); emit updateUserAgentActions(webEngineProfilePointer->httpUserAgent()); emit updateZoomFactorAction(webEngineViewPointer->zoomFactor()); @@ -473,6 +511,18 @@ void BrowserView::refresh() const webEngineViewPointer->reload(); } +void BrowserView::toggleCookies() +{ + // Toggle cookies. + currentPrivacyWebEnginePointer->cookiesEnabled = !currentPrivacyWebEnginePointer->cookiesEnabled; + + // Update the cookies icon. + emit updateCookiesAction(currentPrivacyWebEnginePointer->cookiesEnabled); + + // Reload the website. + webEngineViewPointer->reload(); +} + void BrowserView::toggleJavaScript() const { // Toggle JavaScript. @@ -485,13 +535,13 @@ void BrowserView::toggleJavaScript() const webEngineViewPointer->reload(); } -void BrowserView::toggleLocalStorage() const +void BrowserView::toggleDomStorage() const { - // Toggle local storage. + // Toggle DOM storage. webEngineSettingsPointer->setAttribute(QWebEngineSettings::LocalStorageEnabled, !webEngineSettingsPointer->testAttribute(QWebEngineSettings::LocalStorageEnabled)); - // Update the local storage icon. - emit updateLocalStorageAction(webEngineSettingsPointer->testAttribute(QWebEngineSettings::LocalStorageEnabled)); + // Update the DOM storage action icon. + emit updateDomStorageAction(webEngineSettingsPointer->testAttribute(QWebEngineSettings::LocalStorageEnabled)); // Reload the website. webEngineViewPointer->reload(); diff --git a/src/views/BrowserView.h b/src/views/BrowserView.h index ae1c06a..0314966 100644 --- a/src/views/BrowserView.h +++ b/src/views/BrowserView.h @@ -20,10 +20,13 @@ #ifndef BROWSERVIEW_H #define BROWSERVIEW_H +// Application headers. +#include "structs/PrivacyWebEngine.h" + // KDE Framework headers. #include -// Qt framework headers. +// Qt toolkit headers. #include #include #include @@ -45,8 +48,9 @@ public: // The public functions. void applyOnTheFlyZoomFactor(const double &zoomFactor); void loadInitialWebsite(); + void toggleCookies(); + void toggleDomStorage() const; void toggleJavaScript() const; - void toggleLocalStorage() const; // The public static variables. static QString webEngineDefaultUserAgent; @@ -60,10 +64,11 @@ signals: void linkHovered(const QString &linkUrl) const; void showProgressBar(const int &progress) const; void updateBackAction(const bool &isEnabled) const; + void updateCookiesAction(const bool &isEnabled) const; + void updateDomStorageAction(const bool &isEnabled) const; void updateDomainSettingsIndicator(const bool &status, const QString &domainSettingsDomain) const; void updateForwardAction(const bool &isEnabled) const; void updateJavaScriptAction(const bool &isEnabled) const; - void updateLocalStorageAction(const bool &isEnabled) const; void updateSearchEngineActions(const QString &searchEngine) const; void updateUrlLineEdit(const QUrl &newUrl) const; void updateUserAgentActions(const QString &userAgent) const; @@ -100,6 +105,8 @@ private Q_SLOTS: private: // The private variables. double currentZoomFactor; // This can be removed once has been resolved. + PrivacyWebEngine *currentPrivacyWebEnginePointer; + QList *privacyWebEngineListPointer; QString searchEngineUrl; QWebEngineCookieStore *webEngineCookieStorePointer; QWebEngineHistory *webEngineHistoryPointer; diff --git a/src/windows/BrowserWindow.cpp b/src/windows/BrowserWindow.cpp index 2cfc251..ef264a5 100644 --- a/src/windows/BrowserWindow.cpp +++ b/src/windows/BrowserWindow.cpp @@ -36,8 +36,14 @@ #include #include +// Construct the class. BrowserWindow::BrowserWindow() : KXmlGuiWindow() { + // Initialize the variables. + cookieListPointer = new std::list; + cookiesEnabled = false; + javaScriptEnabled = false; + // Instantiate the main view pointer. browserViewPointer = new BrowserView(this); @@ -75,9 +81,10 @@ BrowserWindow::BrowserWindow() : KXmlGuiWindow() 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")); + cookiesActionPointer = actionCollectionPointer->addAction(QStringLiteral("cookies")); javaScriptActionPointer = actionCollectionPointer->addAction(QStringLiteral("javascript")); - localStorageActionPointer = actionCollectionPointer->addAction(QStringLiteral("local_storage")); + onTheFlyCookiesActionPointer = actionCollectionPointer->addAction(QStringLiteral("on-the-fly_cookies")); + domStorageActionPointer = actionCollectionPointer->addAction(QStringLiteral("dom_storage")); // Create the action groups QActionGroup *userAgentActionGroupPointer = new QActionGroup(this); @@ -119,7 +126,10 @@ BrowserWindow::BrowserWindow() : KXmlGuiWindow() searchEngineYahooActionPointer->setCheckable(true); searchEngineCustomActionPointer->setCheckable(true); - // Set the non-mutable action text. + // Get the number of cookies. + int numberOfCookies = cookieListPointer->size(); + + // Set the action text. userAgentPrivacyBrowserActionPointer->setText(UserAgentHelper::PRIVACY_BROWSER_TRANSLATED); userAgentWebEngineDefaultActionPointer->setText(UserAgentHelper::WEB_ENGINE_DEFAULT_TRANSLATED); userAgentFirefoxLinuxActionPointer->setText(UserAgentHelper::FIREFOX_LINUX_TRANSLATED); @@ -135,9 +145,10 @@ BrowserWindow::BrowserWindow() : KXmlGuiWindow() searchEngineBingActionPointer->setText(i18nc("Search engine", "Bing")); searchEngineYahooActionPointer->setText(i18nc("Search engine", "Yahoo")); domainSettingsActionPointer->setText(i18nc("Domain Settings action", "Domain Settings")); - cookiesActionPointer->setText(i18nc("Cookies action", "Cookies")); + cookiesActionPointer->setText(i18nc("The Cookies action, which also displays the number of cookies", "Cookies - %1", numberOfCookies)); javaScriptActionPointer->setText(i18nc("JavaScript action", "JavaScript")); - localStorageActionPointer->setText(i18nc("Local Storage action", "Local Storage")); + onTheFlyCookiesActionPointer->setText(i18nc("The On-The-Fly Cookies action, which also display the number of cookies", "Cookies - %1", numberOfCookies)); + domStorageActionPointer->setText(i18nc("DOM Storage action", "DOM Storage")); // Set the action icons. userAgentPrivacyBrowserActionPointer->setIcon(QIcon(":/icons/privacy-mode")); @@ -159,6 +170,7 @@ BrowserWindow::BrowserWindow() : KXmlGuiWindow() zoomFactorActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("zoom"))); domainSettingsActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("settings-configure"))); cookiesActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("preferences-web-browser-cookies"))); + onTheFlyCookiesActionPointer->setIcon(QIcon(":/icons/cookies-off")); // Update the on-the-fly menus. connect(browserViewPointer, SIGNAL(updateUserAgentActions(QString)), this, SLOT(updateUserAgentActions(QString))); @@ -176,13 +188,15 @@ BrowserWindow::BrowserWindow() : KXmlGuiWindow() // Connect the URL toolbar actions. connect(javaScriptActionPointer, SIGNAL(triggered()), this, SLOT(toggleJavaScript())); - connect(localStorageActionPointer, SIGNAL(triggered()), this, SLOT(toggleLocalStorage())); + connect(onTheFlyCookiesActionPointer, SIGNAL(triggered()), this, SLOT(toggleCookies())); + connect(domStorageActionPointer, SIGNAL(triggered()), this, SLOT(toggleDomStorage())); // Update the URL toolbar actions. connect(browserViewPointer, SIGNAL(updateBackAction(bool)), backActionPointer, SLOT(setEnabled(bool))); connect(browserViewPointer, SIGNAL(updateForwardAction(bool)), forwardActionPointer, SLOT(setEnabled(bool))); connect(browserViewPointer, SIGNAL(updateJavaScriptAction(bool)), this, SLOT(updateJavaScriptAction(bool))); - connect(browserViewPointer, SIGNAL(updateLocalStorageAction(bool)), this, SLOT(updateLocalStorageAction(bool))); + connect(browserViewPointer, SIGNAL(updateCookiesAction(bool)), this, SLOT(updateCookiesAction(bool))); + connect(browserViewPointer, SIGNAL(updateDomStorageAction(bool)), this, SLOT(updateDomStorageAction(bool))); // Setup the GUI based on the browser_ui.rc file. setupGUI(StandardWindowOption::Default, ("browser_ui.rc")); @@ -237,9 +251,6 @@ BrowserWindow::BrowserWindow() : KXmlGuiWindow() // Update the applied palette. connect(browserViewPointer, SIGNAL(updateDomainSettingsIndicator(bool, QString)), this, SLOT(updateDomainSettingsIndicator(bool, QString))); - // Initialize the cookie list. - cookieListPointer = new std::forward_list; - // Process cookie changes. connect(browserViewPointer, SIGNAL(addCookie(QNetworkCookie)), this, SLOT(addCookieToList(QNetworkCookie))); connect(browserViewPointer, SIGNAL(removeCookie(QNetworkCookie)), this, SLOT(removeCookieFromList(QNetworkCookie))); @@ -251,8 +262,16 @@ BrowserWindow::BrowserWindow() : KXmlGuiWindow() void BrowserWindow::addCookieToList(const QNetworkCookie &newCookie) const { qDebug() << "Add cookie: " << newCookie.toRawForm(); + // Add the new cookie to the list. cookieListPointer->push_front(newCookie); + + // Get the number of cookies. + int numberOfCookies = cookieListPointer->size(); + + // Update the action text. + cookiesActionPointer->setText(i18nc("The Cookies action, which also displays the number of cookies", "Cookies - %1", numberOfCookies)); + onTheFlyCookiesActionPointer->setText(i18nc("The On-The-Fly Cookies action, which also display the number of cookies", "Cookies - %1", numberOfCookies)); } void BrowserWindow::addOrEditDomainSettings() const @@ -407,6 +426,13 @@ void BrowserWindow::removeCookieFromList(const QNetworkCookie &cookie) const // Remove the cookie from the list. cookieListPointer->remove(cookie); + + // Get the number of cookies. + int numberOfCookies = cookieListPointer->size(); + + // Update the action text. + cookiesActionPointer->setText(i18nc("The Cookies action, which also displays the number of cookies", "Cookies - %1", numberOfCookies)); + onTheFlyCookiesActionPointer->setText(i18nc("The On-The-Fly Cookies action, which also display the number of cookies", "Cookies - %1", numberOfCookies)); } void BrowserWindow::showProgressBar(const int &progress) const @@ -499,6 +525,15 @@ void BrowserWindow::settingsConfigure() } } +void BrowserWindow::toggleCookies() const +{ + // Remove the focus from teh URL line edit. + urlLineEditPointer->clearFocus(); + + // Toggle cookies. + browserViewPointer->toggleCookies(); +} + void BrowserWindow::toggleJavaScript() const { // Remove the focus from the URL line edit. @@ -508,37 +543,64 @@ void BrowserWindow::toggleJavaScript() const browserViewPointer->toggleJavaScript(); } -void BrowserWindow::toggleLocalStorage() const +void BrowserWindow::toggleDomStorage() const { // Remove the focus from the URL line edit. urlLineEditPointer->clearFocus(); - // Toggle JavaScript. - browserViewPointer->toggleLocalStorage(); + // Toggle DOM storage. + browserViewPointer->toggleDomStorage(); +} + +void BrowserWindow::updateCookiesAction(const bool &isEnabled) +{ + // Update the cookies status. + cookiesEnabled = isEnabled; + + // Update the icon. + if (cookiesEnabled) + onTheFlyCookiesActionPointer->setIcon(QIcon(":/icons/cookies-on")); + else + onTheFlyCookiesActionPointer->setIcon(QIcon(":/icons/cookies-off")); + + // Update the status of the DOM storage action. + domStorageActionPointer->setEnabled(cookiesEnabled & javaScriptEnabled); } void BrowserWindow::updateDomainSettingsIndicator(const bool &status, const QString &domainSettingsDomain) { // Set the domain palette according to the status. - if (status) urlLineEditPointer->setPalette(domainSettingsPalette); - else urlLineEditPointer->setPalette(noDomainSettingsPalette); + if (status) + urlLineEditPointer->setPalette(domainSettingsPalette); + else + urlLineEditPointer->setPalette(noDomainSettingsPalette); // Store the domain. currentDomainSettingsDomain = domainSettingsDomain; } -void BrowserWindow::updateJavaScriptAction(const bool &isEnabled) const +void BrowserWindow::updateJavaScriptAction(const bool &isEnabled) { + // Update the JavaScript status. + javaScriptEnabled = isEnabled; + // Set the icon according to the status. - if (isEnabled) javaScriptActionPointer->setIcon(QIcon(":/icons/javascript-warning")); - else javaScriptActionPointer->setIcon(QIcon(":/icons/privacy-mode")); + if (javaScriptEnabled) + javaScriptActionPointer->setIcon(QIcon(":/icons/javascript-warning")); + else + javaScriptActionPointer->setIcon(QIcon(":/icons/privacy-mode")); + + // Update the status of the DOM storage action. + domStorageActionPointer->setEnabled(javaScriptEnabled & cookiesEnabled); } -void BrowserWindow::updateLocalStorageAction(const bool &isEnabled) const +void BrowserWindow::updateDomStorageAction(const bool &isEnabled) const { // Set the icon according to the status. - if (isEnabled) localStorageActionPointer->setIcon(QIcon::fromTheme("disk-quota-low")); - else localStorageActionPointer->setIcon(QIcon::fromTheme("disk-quota")); + if (isEnabled) + domStorageActionPointer->setIcon(QIcon::fromTheme("disk-quota-low")); + else + domStorageActionPointer->setIcon(QIcon::fromTheme("disk-quota")); } void BrowserWindow::updateSearchEngineActions(const QString &searchEngine) const diff --git a/src/windows/BrowserWindow.h b/src/windows/BrowserWindow.h index a35e060..c66a528 100644 --- a/src/windows/BrowserWindow.h +++ b/src/windows/BrowserWindow.h @@ -32,7 +32,7 @@ #include // C++ headers. -#include +#include class BrowserWindow : public KXmlGuiWindow { @@ -63,11 +63,13 @@ private Q_SLOTS: void removeCookieFromList(const QNetworkCookie &cookie) const; void settingsConfigure(); void showProgressBar(const int &progress) const; + void toggleCookies() const; + void toggleDomStorage() const; void toggleJavaScript() const; - void toggleLocalStorage() const; + void updateCookiesAction(const bool &isEnabled); + void updateDomStorageAction(const bool &isEnabled) const; void updateDomainSettingsIndicator(const bool &status, const QString &domainSettingsDomain); - void updateJavaScriptAction(const bool &isEnabled) const; - void updateLocalStorageAction(const bool &isEnabled) const; + void updateJavaScriptAction(const bool &isEnabled); void updateSearchEngineActions(const QString &searchEngine) const; void updateUserAgentActions(const QString &userAgent) const; void updateZoomFactorAction(const double &zoomFactor); @@ -79,14 +81,18 @@ private: // The private variables. BrowserView *browserViewPointer; KConfigDialog *configDialogPointer; - std::forward_list *cookieListPointer; + std::list *cookieListPointer; + QAction *cookiesActionPointer; + bool cookiesEnabled; QString currentDomainSettingsDomain; QUrl currentUrl; double currentZoomFactor; + QAction *domStorageActionPointer; QPalette domainSettingsPalette; QAction *javaScriptActionPointer; - QAction *localStorageActionPointer; + bool javaScriptEnabled; QPalette noDomainSettingsPalette; + QAction *onTheFlyCookiesActionPointer; QProgressBar *progressBarPointer; QLabel *searchEngineLabelPointer; QAction *searchEngineMojeekActionPointer; -- 2.45.2