From: Soren Stoutner Date: Fri, 1 Apr 2022 19:38:28 +0000 (-0700) Subject: Add controls for local storage. https://redmine.stoutner.com/issues/830 X-Git-Tag: v0.1~43 X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserPC.git;a=commitdiff_plain;h=455108aa18c90514c0dad3c12dfea98180dfb471;hp=9514cabb5648123b68264e595e9ffef6261bd215 Add controls for local storage. https://redmine.stoutner.com/issues/830 --- diff --git a/src/BrowserView.ui b/src/BrowserView.ui deleted file mode 100644 index 11219fa..0000000 --- a/src/BrowserView.ui +++ /dev/null @@ -1,55 +0,0 @@ - - - - - - BrowserView - - - - - - - 0 - - - - - 0 - - - - 0 - - - - 0 - - - - 0 - - - - - - - - - diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 709b74c..8371822 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -32,14 +32,14 @@ ecm_qt_declare_logging_category(privacy-browser ) # Include the KConfig controller file. -kconfig_add_kcfg_files(privacy-browser Settings.kcfgc) +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 - BrowserView.ui - DomainSettingsDialog.ui - SettingsGeneral.ui - SettingsPrivacy.ui + ui/BrowserView.ui + ui/DomainSettingsDialog.ui + ui/SettingsGeneral.ui + ui/SettingsPrivacy.ui ) # Link the following libraries. diff --git a/src/DomainSettingsDialog.ui b/src/DomainSettingsDialog.ui deleted file mode 100644 index 82d6a0d..0000000 --- a/src/DomainSettingsDialog.ui +++ /dev/null @@ -1,300 +0,0 @@ - - - - - - DomainSettingsDialog - - - - - 0 - 0 - 1000 - 1500 - - - - - - - - - - - - - - - - - - - - Add Domain - - - - - - - - - - - - - Delete domain - - - - - - - - - - - - - Qt::Horizontal - - - - - - - - - - - - - - - - - - - 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 - - - - - - JavaScript disabled - - - - - - JavaScript enabled - - - - - - - - - Qt::RichText - - - - - - - - - User Agent - - - - - - - - - 0 - 0 - - - - - true - - - - - System default - - - - - - Privacy Browser - - - - - - Firefox on Linux - - - - - - Chromium on Linux - - - - - - Firefox on Windows - - - - - - Chrome on Windows - - - - - - Edge on Windows - - - - - - Safari on macOS - - - - - - - - - Qt::RichText - - - - - - - - - Zoom factor - - - - - - - - - System default - - - - - - Custom - - - - - - - - - Set the zoom factor between 0.25 and 5.00. The default is 1.00. - - - - 0.250000000000000 - - - - 5.000000000000000 - - - - 0.250000000000000 - - - - - - - - - - - - Qt::Vertical - - - - - - - - - QDialogButtonBox::Reset | QDialogButtonBox::Ok | QDialogButtonBox::Apply | QDialogButtonBox::Cancel - - - - - - - - diff --git a/src/Settings.kcfg b/src/Settings.kcfg deleted file mode 100644 index 25b12a8..0000000 --- a/src/Settings.kcfg +++ /dev/null @@ -1,53 +0,0 @@ - - - - - - - - - - - - - false - - - - Privacy Browser - - - - - - https://www.mojeek.com/ - - - - Mojeek - - - - 1.00 - - - diff --git a/src/Settings.kcfgc b/src/Settings.kcfgc deleted file mode 100644 index 3129834..0000000 --- a/src/Settings.kcfgc +++ /dev/null @@ -1,26 +0,0 @@ -# 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 . - - -# Specify the KConfig file. -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. -Singleton=true diff --git a/src/SettingsGeneral.ui b/src/SettingsGeneral.ui deleted file mode 100644 index 65b693e..0000000 --- a/src/SettingsGeneral.ui +++ /dev/null @@ -1,146 +0,0 @@ - - - - - - - GeneralSettings - - - - - - - - Homepage - - - - - - - - The default is https://www.mojeek.com/. - - - - - - - - - Search engine - - - - - - - - - 0 - 0 - - - - - The default is Mojeek. - - - - true - - - - - Mojeek - - - - - - Monocles - - - - - - MetaGer - - - - - - Google - - - - - - Bing - - - - - - Yahoo - - - - - - - - - Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - - - - - - - - - Zoom factor - - - - - - - - Set the zoom factor between 0.25 and 5.00. The default is 1.00. - - - - 0.250000000000000 - - - - 5.000000000000000 - - - - 0.250000000000000 - - - - - - diff --git a/src/SettingsPrivacy.ui b/src/SettingsPrivacy.ui deleted file mode 100644 index 74c7a0f..0000000 --- a/src/SettingsPrivacy.ui +++ /dev/null @@ -1,119 +0,0 @@ - - - - - - - PrivacySettings - - - - - - - - JavaScript - - - - JavaScript allows websites to run programs (scripts) on the device. The default is disabled. - - - - - - - - - User agent - - - - - - - - - 0 - 0 - - - - - The default is Privacy Browser. - - - - true - - - - - Privacy Browser - - - - - - Firefox Linux - - - - - - Chromium Linux - - - - - - Firefox Windows - - - - - - Chrome Windows - - - - - - Edge Windows - - - - - - Safari macOS - - - - - - - - - Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - - - - - - diff --git a/src/dialogs/DomainSettingsDialog.cpp b/src/dialogs/DomainSettingsDialog.cpp index e3745b5..a8960cd 100644 --- a/src/dialogs/DomainSettingsDialog.cpp +++ b/src/dialogs/DomainSettingsDialog.cpp @@ -43,6 +43,8 @@ DomainSettingsDialog::DomainSettingsDialog(QWidget *parent) : QDialog(parent) domainNameLineEditPointer = domainSettingsDialogUi.domainNameLineEdit; javaScriptComboBoxPointer = domainSettingsDialogUi.javaScriptComboBox; javaScriptLabelPointer = domainSettingsDialogUi.javaScriptLabel; + localStorageComboBoxPointer = domainSettingsDialogUi.localStorageComboBox; + localStorageLabelPointer = domainSettingsDialogUi.localStorageLabel; userAgentComboBoxPointer = domainSettingsDialogUi.userAgentComboBox; userAgentLabelPointer = domainSettingsDialogUi.userAgentLabel; zoomFactorComboBoxPointer = domainSettingsDialogUi.zoomFactorComboBox; @@ -89,6 +91,7 @@ DomainSettingsDialog::DomainSettingsDialog(QWidget *parent) : QDialog(parent) // Connect 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(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))); @@ -149,7 +152,6 @@ void DomainSettingsDialog::customZoomFactorChanged(const double &newValue) const updateUi(); } - void DomainSettingsDialog::domainNameChanged(const QString &updatedDomainName) const { // Update the domains table model. @@ -159,7 +161,6 @@ void DomainSettingsDialog::domainNameChanged(const QString &updatedDomainName) c updateUi(); } - void DomainSettingsDialog::domainSelected(const QModelIndex &modelIndex) const { // Populate the domain name line edit pointer. @@ -168,6 +169,9 @@ 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()); + // Get the user agent string. QString userAgent = modelIndex.siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::USER_AGENT)).data().toString(); @@ -194,6 +198,7 @@ void DomainSettingsDialog::domainSelected(const QModelIndex &modelIndex) const // Populate the labels. populateJavaScriptLabel(); + populateLocalStorageLabel(); populateUserAgentLabel(userAgentComboBoxPointer->currentText()); // Update the UI. @@ -213,6 +218,18 @@ void DomainSettingsDialog::javaScriptChanged(const int &newIndex) const updateUi(); } +void DomainSettingsDialog::localStorageChanged(const int &newIndex) const +{ + // Update the domains table model. + domainsTableModelPointer->setData(domainsListViewPointer->selectionModel()->currentIndex().siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::LOCAL_STORAGE)), + newIndex); + + // Populate the local storage label. + populateLocalStorageLabel(); + + // Update the UI. + updateUi(); +} void DomainSettingsDialog::ok() { @@ -234,14 +251,40 @@ void DomainSettingsDialog::populateJavaScriptLabel() const case (DomainsDatabaseHelper::SYSTEM_DEFAULT): { // Set the text according to the system default. - if (Settings::javaScript()) - { - javaScriptLabelPointer->setText(i18nc("Domains settings labels", "JavaScript enabled")); - } - else - { - javaScriptLabelPointer->setText(i18nc("Domain settings labels", "JavaScript disabled")); - } + if (Settings::javaScript()) javaScriptLabelPointer->setText(i18nc("Domains settings label", "JavaScript enabled")); + else javaScriptLabelPointer->setText(i18nc("Domain settings label", "JavaScript disabled")); + + break; + } + + case (DomainsDatabaseHelper::DISABLED): + { + // Set the label text in bold. + javaScriptLabelPointer->setText(i18nc("Domain settings label. The tags should be retained.", "JavaScript disabled")); + + break; + } + + case (DomainsDatabaseHelper::ENABLED): + { + // Set the label text in bold. + javaScriptLabelPointer->setText(i18nc("Domains settings label. The tags should be retained.", "JavaScript enabled")); + + break; + } + } +} + +void DomainSettingsDialog::populateLocalStorageLabel() const +{ + // Populate the label according to the currently selected index. + switch (localStorageComboBoxPointer->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")); break; } @@ -249,7 +292,7 @@ void DomainSettingsDialog::populateJavaScriptLabel() const case (DomainsDatabaseHelper::DISABLED): { // Set the label text in bold. - javaScriptLabelPointer->setText(i18nc("Domain settings labels. The tags should be retained.", "JavaScript disabled")); + localStorageLabelPointer->setText(i18nc("Local storage label. The tags should be retained.", "Local storage disabled")); break; } @@ -257,7 +300,7 @@ void DomainSettingsDialog::populateJavaScriptLabel() const case (DomainsDatabaseHelper::ENABLED): { // Set the label text in bold. - javaScriptLabelPointer->setText(i18nc("Domains settings labels. The tags should be retained.", "JavaScript enabled")); + localStorageLabelPointer->setText(i18nc("Local storage label. The tags should be retained.", "Local storage enabled")); break; } @@ -312,6 +355,7 @@ void DomainSettingsDialog::showAddMessageBox() // Set the values for the new domain. newDomainRecord.setValue(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::DOMAIN_NAME), newDomainName); newDomainRecord.setValue(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::JAVASCRIPT), DomainsDatabaseHelper::SYSTEM_DEFAULT); + newDomainRecord.setValue(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::LOCAL_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); diff --git a/src/dialogs/DomainSettingsDialog.h b/src/dialogs/DomainSettingsDialog.h index 0694177..41438ce 100644 --- a/src/dialogs/DomainSettingsDialog.h +++ b/src/dialogs/DomainSettingsDialog.h @@ -49,6 +49,7 @@ private Q_SLOTS: 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,6 +68,8 @@ private: QSqlTableModel *domainsTableModelPointer; QComboBox *javaScriptComboBoxPointer; QLabel *javaScriptLabelPointer; + QComboBox *localStorageComboBoxPointer; + QLabel *localStorageLabelPointer; QPushButton *resetButtonPointer; QComboBox *userAgentComboBoxPointer; QLabel *userAgentLabelPointer; @@ -74,6 +77,7 @@ private: // The private functions. void populateJavaScriptLabel() const; + void populateLocalStorageLabel() const; void populateUserAgentLabel(const QString &userAgentName) const; void updateUi() const; }; diff --git a/src/helpers/DomainsDatabaseHelper.cpp b/src/helpers/DomainsDatabaseHelper.cpp index 5b6c4fa..ed62e6a 100644 --- a/src/helpers/DomainsDatabaseHelper.cpp +++ b/src/helpers/DomainsDatabaseHelper.cpp @@ -26,12 +26,13 @@ const QString DomainsDatabaseHelper::CONNECTION_NAME = "domains_database"; const QString DomainsDatabaseHelper::DOMAINS_TABLE = "domains"; // Define the private static schema constants. -const int DomainsDatabaseHelper::SCHEMA_VERSION = 3; +const int DomainsDatabaseHelper::SCHEMA_VERSION = 4; // Define the public static database field names. 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::USER_AGENT = "user_agent"; const QString DomainsDatabaseHelper::ZOOM_FACTOR = "zoom_factor"; const QString DomainsDatabaseHelper::CUSTOM_ZOOM_FACTOR = "custom_zoom_factor"; @@ -74,9 +75,6 @@ void DomainsDatabaseHelper::addDatabase() // Add the JavaScript column. domainsDatabase.exec("ALTER TABLE " + DOMAINS_TABLE + " ADD COLUMN " + JAVASCRIPT + " INTEGER DEFAULT 0"); - // Set the default value. - domainsDatabase.exec("UPDATE " + DOMAINS_TABLE + " SET " + JAVASCRIPT + " = 0" ); - // Fallthrough to the next case. [[fallthrough]]; } @@ -97,7 +95,15 @@ void DomainsDatabaseHelper::addDatabase() // Add the Zoom Factor columns. domainsDatabase.exec("ALTER TABLE " + DOMAINS_TABLE + " ADD COLUMN " + ZOOM_FACTOR + " INTEGER DEFAULT 0"); domainsDatabase.exec("ALTER TABLE " + DOMAINS_TABLE + " ADD COLUMN " + CUSTOM_ZOOM_FACTOR + " REAL DEFAULT 1.0"); + + // Fallthrough to the next case. + [[fallthrough]]; } + + // Upgrade from schema version 3. + case 3: + // Add the Local Storage column. + domainsDatabase.exec("ALTER TABLE " + DOMAINS_TABLE + " ADD COLUMN " + LOCAL_STORAGE + " INTEGER DEFAULT 0"); } // Update the schema version. @@ -114,6 +120,7 @@ void DomainsDatabaseHelper::addDatabase() _ID + " INTEGER PRIMARY KEY, " + DOMAIN_NAME + " TEXT, " + JAVASCRIPT + " INTEGER DEFAULT 0, " + + LOCAL_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 b95988d..2ec812b 100644 --- a/src/helpers/DomainsDatabaseHelper.h +++ b/src/helpers/DomainsDatabaseHelper.h @@ -46,6 +46,7 @@ public: 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/settings/Settings.kcfg b/src/settings/Settings.kcfg new file mode 100644 index 0000000..c5435fa --- /dev/null +++ b/src/settings/Settings.kcfg @@ -0,0 +1,57 @@ + + + + + + + + + + + + + false + + + + false + + + + Privacy Browser + + + + + + https://www.mojeek.com/ + + + + Mojeek + + + + 1.00 + + + diff --git a/src/settings/Settings.kcfgc b/src/settings/Settings.kcfgc new file mode 100644 index 0000000..3129834 --- /dev/null +++ b/src/settings/Settings.kcfgc @@ -0,0 +1,26 @@ +# 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 . + + +# Specify the KConfig file. +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. +Singleton=true diff --git a/src/ui.rc/browser_ui.rc b/src/ui.rc/browser_ui.rc index 3c46ee0..dbbeb31 100644 --- a/src/ui.rc/browser_ui.rc +++ b/src/ui.rc/browser_ui.rc @@ -69,5 +69,9 @@ - URL Toolbar + URL Toolbar + + + + diff --git a/src/ui/BrowserView.ui b/src/ui/BrowserView.ui new file mode 100644 index 0000000..11219fa --- /dev/null +++ b/src/ui/BrowserView.ui @@ -0,0 +1,55 @@ + + + + + + BrowserView + + + + + + + 0 + + + + + 0 + + + + 0 + + + + 0 + + + + 0 + + + + + + + + + diff --git a/src/ui/DomainSettingsDialog.ui b/src/ui/DomainSettingsDialog.ui new file mode 100644 index 0000000..0b2f56f --- /dev/null +++ b/src/ui/DomainSettingsDialog.ui @@ -0,0 +1,343 @@ + + + + + + DomainSettingsDialog + + + + + 0 + 0 + 1000 + 1500 + + + + + + + + + + + + + + + + + + + + Add Domain + + + + + + + + + + + + + Delete domain + + + + + + + + + + + + + Qt::Horizontal + + + + + + + + + + + + + + + + + + + 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 + + + + + + JavaScript disabled + + + + + + JavaScript enabled + + + + + + + + + Qt::RichText + + + + + + + + + Local storage + + + + + + + + Local storage, sometimes also called DOM storage, is like cookies on steroids. + + + + + System default + + + + + + Local storage disabled + + + + + + Local storage enabled + + + + + + + + + Qt::RichText + + + + + + + + + User agent + + + + + + + + + 0 + 0 + + + + + true + + + + + System default + + + + + + Privacy Browser + + + + + + Firefox on Linux + + + + + + Chromium on Linux + + + + + + Firefox on Windows + + + + + + Chrome on Windows + + + + + + Edge on Windows + + + + + + Safari on macOS + + + + + + + + + Qt::RichText + + + + + + + + + Zoom factor + + + + + + + + + System default + + + + + + Custom + + + + + + + + + Set the zoom factor between 0.25 and 5.00. The default is 1.00. + + + + 0.250000000000000 + + + + 5.000000000000000 + + + + 0.250000000000000 + + + + + + + + + + + + Qt::Vertical + + + + + + + + + QDialogButtonBox::Reset | QDialogButtonBox::Ok | QDialogButtonBox::Apply | QDialogButtonBox::Cancel + + + + + + + + diff --git a/src/ui/SettingsGeneral.ui b/src/ui/SettingsGeneral.ui new file mode 100644 index 0000000..65b693e --- /dev/null +++ b/src/ui/SettingsGeneral.ui @@ -0,0 +1,146 @@ + + + + + + + GeneralSettings + + + + + + + + Homepage + + + + + + + + The default is https://www.mojeek.com/. + + + + + + + + + Search engine + + + + + + + + + 0 + 0 + + + + + The default is Mojeek. + + + + true + + + + + Mojeek + + + + + + Monocles + + + + + + MetaGer + + + + + + Google + + + + + + Bing + + + + + + Yahoo + + + + + + + + + Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + + + + + Zoom factor + + + + + + + + Set the zoom factor between 0.25 and 5.00. The default is 1.00. + + + + 0.250000000000000 + + + + 5.000000000000000 + + + + 0.250000000000000 + + + + + + diff --git a/src/ui/SettingsPrivacy.ui b/src/ui/SettingsPrivacy.ui new file mode 100644 index 0000000..a1445b6 --- /dev/null +++ b/src/ui/SettingsPrivacy.ui @@ -0,0 +1,132 @@ + + + + + + + PrivacySettings + + + + + + + + JavaScript + + + + JavaScript allows websites to run programs (scripts) on the device. The default is disabled. + + + + + + + + + Local storage + + + + Local storage, sometimes also called DOM storage, is like cookies on steroids. + + + + + + + + + User agent + + + + + + + + + 0 + 0 + + + + + The default is Privacy Browser. + + + + true + + + + + Privacy Browser + + + + + + Firefox Linux + + + + + + Chromium Linux + + + + + + Firefox Windows + + + + + + Chrome Windows + + + + + + Edge Windows + + + + + + Safari macOS + + + + + + + + + Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + + diff --git a/src/views/BrowserView.cpp b/src/views/BrowserView.cpp index 21e1493..933a300 100644 --- a/src/views/BrowserView.cpp +++ b/src/views/BrowserView.cpp @@ -162,6 +162,34 @@ void BrowserView::applyDomainSettings(const QString &hostname, const bool reload } } + // Set local storage. + switch (domainRecord.field(DomainsDatabaseHelper::LOCAL_STORAGE).value().toInt()) + { + case (DomainsDatabaseHelper::SYSTEM_DEFAULT): + { + // Set the default local storage status. + webEngineSettingsPointer->setAttribute(QWebEngineSettings::LocalStorageEnabled, Settings::localStorage()); + + break; + } + + case (DomainsDatabaseHelper::DISABLED): + { + // Disable local storage. + webEngineSettingsPointer->setAttribute(QWebEngineSettings::LocalStorageEnabled, false); + + break; + } + + case (DomainsDatabaseHelper::ENABLED): + { + // Enable local storage. + webEngineSettingsPointer->setAttribute(QWebEngineSettings::LocalStorageEnabled, true); + + break; + } + } + // Set the user agent. webEngineProfilePointer->setHttpUserAgent(UserAgentHelper::getResultingDomainSettingsUserAgent(domainRecord.field(DomainsDatabaseHelper::USER_AGENT).value().toString())); @@ -188,6 +216,9 @@ void BrowserView::applyDomainSettings(const QString &hostname, const bool reload // Set the JavaScript status. webEngineSettingsPointer->setAttribute(QWebEngineSettings::JavascriptEnabled, Settings::javaScript()); + // Set local storage. + webEngineSettingsPointer->setAttribute(QWebEngineSettings::LocalStorageEnabled, Settings::localStorage()); + // Set the user agent. webEngineProfilePointer->setHttpUserAgent(UserAgentHelper::getUserAgentFromDatabaseName(Settings::userAgent())); @@ -203,6 +234,7 @@ 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 updateUserAgentActions(webEngineProfilePointer->httpUserAgent()); emit updateZoomFactorAction(webEngineViewPointer->zoomFactor()); @@ -358,6 +390,18 @@ void BrowserView::toggleJavaScript() const webEngineViewPointer->reload(); } +void BrowserView::toggleLocalStorage() const +{ + // Toggle local storage. + webEngineSettingsPointer->setAttribute(QWebEngineSettings::LocalStorageEnabled, !webEngineSettingsPointer->testAttribute(QWebEngineSettings::LocalStorageEnabled)); + + // Update the local storage icon. + emit updateLocalStorageAction(webEngineSettingsPointer->testAttribute(QWebEngineSettings::LocalStorageEnabled)); + + // Reload the website. + webEngineViewPointer->reload(); +} + void BrowserView::updateUrl(const QUrl &url) const { // Update the URL line edit. diff --git a/src/views/BrowserView.h b/src/views/BrowserView.h index 143db41..1401468 100644 --- a/src/views/BrowserView.h +++ b/src/views/BrowserView.h @@ -41,6 +41,8 @@ public: // The public functions. void applyOnTheFlyZoomFactor(const double &zoomFactor); void loadInitialWebsite(); + void toggleJavaScript() const; + void toggleLocalStorage() const; signals: // The signals. @@ -51,6 +53,7 @@ signals: void updateDomainSettingsIndicator(const bool status) 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 QString &newUrl) const; void updateUserAgentActions(const QString &userAgent) const; @@ -67,7 +70,6 @@ public Q_SLOTS: void forward() const; void home() const; void loadUrlFromLineEdit(QString url) const; - void toggleJavaScript() const; void refresh() const; private Q_SLOTS: diff --git a/src/windows/BrowserWindow.cpp b/src/windows/BrowserWindow.cpp index 03ababc..13f470e 100644 --- a/src/windows/BrowserWindow.cpp +++ b/src/windows/BrowserWindow.cpp @@ -72,6 +72,7 @@ BrowserWindow::BrowserWindow() : KXmlGuiWindow() searchEngineYahooActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_yahoo")); searchEngineCustomActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_custom")); javaScriptActionPointer = actionCollectionPointer->addAction(QStringLiteral("javascript")); + localStorageActionPointer = actionCollectionPointer->addAction(QStringLiteral("local_storage")); domainSettingsActionPointer = actionCollectionPointer->addAction(QStringLiteral("domain_settings")); // Create the action groups @@ -127,6 +128,7 @@ BrowserWindow::BrowserWindow() : KXmlGuiWindow() 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")); // Set the action icons. @@ -162,12 +164,14 @@ BrowserWindow::BrowserWindow() : KXmlGuiWindow() // 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))); 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))); // Setup the GUI based on the browser_ui.rc file. setupGUI(StandardWindowOption::Default, ("browser_ui.rc")); @@ -179,9 +183,7 @@ BrowserWindow::BrowserWindow() : KXmlGuiWindow() urlLineEditPointer = new KLineEdit(); // Populate the URL toolbar. - urlToolBarPointer->addWidget(urlLineEditPointer); - urlToolBarPointer->addAction(javaScriptActionPointer); - urlToolBarPointer->addAction(domainSettingsActionPointer); + urlToolBarPointer->insertWidget(javaScriptActionPointer, urlLineEditPointer); // Load a new URL from the URL line edit. connect(urlLineEditPointer, SIGNAL(returnKeyPressed(const QString)), this, SLOT(loadUrlFromLineEdit(const QString))); @@ -324,15 +326,6 @@ void BrowserWindow::showProgressBar(const int &progress) const progressBarPointer->show(); } -void BrowserWindow::toggleJavaScript() const -{ - // Remove the focus from the URL line edit. - urlLineEditPointer->clearFocus(); - - // Toggle JavaScript. - browserViewPointer->toggleJavaScript(); -} - QSize BrowserWindow::sizeHint() const { // Return the default window size. @@ -414,6 +407,24 @@ void BrowserWindow::settingsConfigure() } } +void BrowserWindow::toggleJavaScript() const +{ + // Remove the focus from the URL line edit. + urlLineEditPointer->clearFocus(); + + // Toggle JavaScript. + browserViewPointer->toggleJavaScript(); +} + +void BrowserWindow::toggleLocalStorage() const +{ + // Remove the focus from the URL line edit. + urlLineEditPointer->clearFocus(); + + // Toggle JavaScript. + browserViewPointer->toggleLocalStorage(); +} + void BrowserWindow::updateDomainSettingsIndicator(const bool &status) const { // Set the domain palette according to the status. @@ -428,6 +439,13 @@ void BrowserWindow::updateJavaScriptAction(const bool &isEnabled) const else javaScriptActionPointer->setIcon(QIcon(":/icons/privacy-mode")); } +void BrowserWindow::updateLocalStorageAction(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")); +} + void BrowserWindow::updateSearchEngineActions(const QString &searchEngine) const { // Initialize the custom search engine flag. diff --git a/src/windows/BrowserWindow.h b/src/windows/BrowserWindow.h index 02978d4..b3630db 100644 --- a/src/windows/BrowserWindow.h +++ b/src/windows/BrowserWindow.h @@ -56,8 +56,10 @@ private Q_SLOTS: void settingsConfigure(); void showProgressBar(const int &progress) const; void toggleJavaScript() const; + void toggleLocalStorage() const; void updateDomainSettingsIndicator(const bool &status) const; void updateJavaScriptAction(const bool &isEnabled) const; + void updateLocalStorageAction(const bool &isEnabled) const; void updateSearchEngineActions(const QString &searchEngine) const; void updateUserAgentActions(const QString &userAgent) const; void updateZoomFactorAction(const double &zoomFactor); @@ -73,6 +75,7 @@ private: QPalette domainSettingsPalette; double currentZoomFactor; QAction *javaScriptActionPointer; + QAction *localStorageActionPointer; QPalette noDomainSettingsPalette; QProgressBar *progressBarPointer; QLabel *searchEngineLabelPointer;