From 588db73b94af7b596b0e532f4557aa8b6c41f5c3 Mon Sep 17 00:00:00 2001 From: Soren Stoutner Date: Thu, 19 May 2022 13:14:04 -0700 Subject: [PATCH] Add local storage domain settings. --- src/dialogs/DomainSettingsDialog.cpp | 125 ++++++++++++++++++-------- src/dialogs/DomainSettingsDialog.h | 9 +- src/helpers/DomainsDatabaseHelper.cpp | 18 +++- src/helpers/DomainsDatabaseHelper.h | 1 + src/icons/cookies-off.svg | 54 ----------- src/icons/cookies-on.svg | 59 ------------ src/resources.qrc | 2 - src/settings/Settings.kcfg | 2 +- src/structs/PrivacyWebEngine.cpp | 4 +- src/structs/PrivacyWebEngine.h | 2 +- src/ui.rcs/browser_ui.rc | 2 +- src/uis/DomainSettingsDialog.ui | 14 +-- src/uis/SettingsGeneral.ui | 2 +- src/uis/SettingsPrivacy.ui | 4 +- src/views/BrowserView.cpp | 80 +++++++++++------ src/views/BrowserView.h | 6 +- src/windows/BrowserWindow.cpp | 81 ++++++++--------- src/windows/BrowserWindow.h | 8 +- 18 files changed, 227 insertions(+), 246 deletions(-) delete mode 100644 src/icons/cookies-off.svg delete mode 100644 src/icons/cookies-on.svg diff --git a/src/dialogs/DomainSettingsDialog.cpp b/src/dialogs/DomainSettingsDialog.cpp index eb43fb5..151a0b4 100644 --- a/src/dialogs/DomainSettingsDialog.cpp +++ b/src/dialogs/DomainSettingsDialog.cpp @@ -55,6 +55,8 @@ DomainSettingsDialog::DomainSettingsDialog(const int &startType, const QString & domainNameLineEditPointer = domainSettingsDialogUi.domainNameLineEdit; javaScriptComboBoxPointer = domainSettingsDialogUi.javaScriptComboBox; javaScriptLabelPointer = domainSettingsDialogUi.javaScriptLabel; + localStorageComboBoxPointer = domainSettingsDialogUi.localStorageComboBox; + localStorageLabelPointer = domainSettingsDialogUi.localStorageLabel; domStorageComboBoxPointer = domainSettingsDialogUi.domStorageComboBox; domStorageLabelPointer = domainSettingsDialogUi.domStorageLabel; userAgentComboBoxPointer = domainSettingsDialogUi.userAgentComboBox; @@ -85,6 +87,9 @@ DomainSettingsDialog::DomainSettingsDialog(const int &startType, const QString & // Set the visible column to be the domain name. domainsListViewPointer->setModelColumn(1); + // Get the domains selection model pointer. + domainsSelectionModelPointer = domainsListViewPointer->selectionModel(); + // Disable editing of the list view. domainsListViewPointer->setEditTriggers(QAbstractItemView::NoEditTriggers); @@ -100,7 +105,7 @@ DomainSettingsDialog::DomainSettingsDialog(const int &startType, const QString & domainsListViewPointer->setCurrentIndex(domainsTableModelPointer->index(0, domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::DOMAIN_NAME))); // Populate the domain settings. - domainSelected(domainsListViewPointer->selectionModel()->currentIndex()); + domainSelected(domainsSelectionModelPointer->currentIndex()); break; } @@ -123,7 +128,9 @@ DomainSettingsDialog::DomainSettingsDialog(const int &startType, const QString & domainsListViewPointer->setCurrentIndex(newDomainIndex[0]); // Populate the domain settings. - domainSelected(domainsListViewPointer->selectionModel()->currentIndex()); + domainSelected(domainsSelectionModelPointer->currentIndex()); + + break; } } @@ -133,6 +140,7 @@ DomainSettingsDialog::DomainSettingsDialog(const int &startType, const QString & // 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))); @@ -177,13 +185,12 @@ void DomainSettingsDialog::addDomain(const QString &domainName) const domainsListViewPointer->setCurrentIndex(newDomainIndex[newDomainIndex.size() - 1]); // Populate the domain settings. - domainSelected(domainsListViewPointer->selectionModel()->currentIndex()); + domainSelected(domainsSelectionModelPointer->currentIndex()); // Update the UI. updateUi(); } - void DomainSettingsDialog::apply() const { // Get the current index. @@ -221,8 +228,19 @@ void DomainSettingsDialog::cancel() void DomainSettingsDialog::customZoomFactorChanged(const double &newValue) const { // Update the domains table model. - domainsTableModelPointer->setData(domainsListViewPointer->selectionModel()->currentIndex().siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::CUSTOM_ZOOM_FACTOR)), - newValue); + domainsTableModelPointer->setData(domainsSelectionModelPointer->currentIndex().siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::CUSTOM_ZOOM_FACTOR)), newValue); + + // Update the UI. + updateUi(); +} + +void DomainSettingsDialog::domStorageChanged(const int &newIndex) const +{ + // Update the domains table model. + domainsTableModelPointer->setData(domainsSelectionModelPointer->currentIndex().siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::DOM_STORAGE)), newIndex); + + // Populate the DOM storage label. + populateDomStorageLabel(); // Update the UI. updateUi(); @@ -231,7 +249,7 @@ void DomainSettingsDialog::customZoomFactorChanged(const double &newValue) const void DomainSettingsDialog::domainNameChanged(const QString &updatedDomainName) const { // Update the domains table model. - domainsTableModelPointer->setData(domainsListViewPointer->selectionModel()->currentIndex(), updatedDomainName); + domainsTableModelPointer->setData(domainsSelectionModelPointer->currentIndex(), updatedDomainName); // Update the UI. updateUi(); @@ -245,6 +263,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()); + // Populate the DOM storage combo box. domStorageComboBoxPointer->setCurrentIndex(modelIndex.siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::DOM_STORAGE)).data().toInt()); @@ -283,6 +304,7 @@ void DomainSettingsDialog::domainSelected(const QModelIndex &modelIndex) const // Populate the labels. populateJavaScriptLabel(); + populateLocalStorageLabel(); populateDomStorageLabel(); populateUserAgentLabel(userAgentComboBoxPointer->currentText()); @@ -293,8 +315,7 @@ void DomainSettingsDialog::domainSelected(const QModelIndex &modelIndex) const void DomainSettingsDialog::javaScriptChanged(const int &newIndex) const { // Update the domains table model. - domainsTableModelPointer->setData(domainsListViewPointer->selectionModel()->currentIndex().siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::JAVASCRIPT)), - newIndex); + domainsTableModelPointer->setData(domainsSelectionModelPointer->currentIndex().siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::JAVASCRIPT)), newIndex); // Populate the JavaScript label. populateJavaScriptLabel(); @@ -303,14 +324,13 @@ void DomainSettingsDialog::javaScriptChanged(const int &newIndex) const updateUi(); } -void DomainSettingsDialog::domStorageChanged(const int &newIndex) const +void DomainSettingsDialog::localStorageChanged(const int &newIndex) const { // Update the domains table model. - domainsTableModelPointer->setData(domainsListViewPointer->selectionModel()->currentIndex().siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::DOM_STORAGE)), - newIndex); + domainsTableModelPointer->setData(domainsSelectionModelPointer->currentIndex().siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::LOCAL_STORAGE)), newIndex); - // Populate the DOM storage label. - populateDomStorageLabel(); + // Poplate the local storage label. + populateLocalStorageLabel(); // Update the UI. updateUi(); @@ -328,74 +348,109 @@ void DomainSettingsDialog::ok() accept(); } +void DomainSettingsDialog::populateDomStorageLabel() const +{ + // Populate the label according to the currently selected index. + switch (domStorageComboBoxPointer->currentIndex()) + { + // Set the text according to the system default. + case (DomainsDatabaseHelper::SYSTEM_DEFAULT): + { + if (Settings::domStorageEnabled()) + domStorageLabelPointer->setText(i18nc("Domain settings DOM storage label.", "DOM storage enabled")); + else + domStorageLabelPointer->setText(i18nc("Domain settings DOM storage label.", "DOM storage disabled")); + + break; + } + + // Set the disabled text in bold. + case (DomainsDatabaseHelper::DISABLED): + { + domStorageLabelPointer->setText(i18nc("Domain settings DOM storage label. The tags should be retained.", "DOM storage disabled")); + + break; + } + + // Set the enabled text in bold. + case (DomainsDatabaseHelper::ENABLED): + { + domStorageLabelPointer->setText(i18nc("Domain settings DOM storage label. The tags should be retained.", "DOM storage enabled")); + + break; + } + } +} + void DomainSettingsDialog::populateJavaScriptLabel() const { // Populate the label according to the currently selected index. switch (javaScriptComboBoxPointer->currentIndex()) { + // Set the text according to the system default. case (DomainsDatabaseHelper::SYSTEM_DEFAULT): { - // Set the text according to the system default. if (Settings::javaScriptEnabled()) - javaScriptLabelPointer->setText(i18nc("Domains settings label", "JavaScript enabled")); + javaScriptLabelPointer->setText(i18nc("Domain settings JavaScript label.", "JavaScript enabled")); else - javaScriptLabelPointer->setText(i18nc("Domain settings label", "JavaScript disabled")); + javaScriptLabelPointer->setText(i18nc("Domain settings JavaScript label.", "JavaScript disabled")); break; } + // Set the disabled text in bold. 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 JavaScript label. The tags should be retained.", "JavaScript disabled")); break; } + // Set the enabled text in bold. 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("Domain settings JavaScript label. The tags should be retained.", "JavaScript enabled")); break; } } } -void DomainSettingsDialog::populateDomStorageLabel() const +void DomainSettingsDialog::populateLocalStorageLabel() const { // Populate the label according to the currently selected index. - switch (domStorageComboBoxPointer->currentIndex()) + switch (localStorageComboBoxPointer->currentIndex()) { + // Set the text according to the system default. case (DomainsDatabaseHelper::SYSTEM_DEFAULT): { - // Set the text according to the system default. - if (Settings::domStorageEnabled()) - domStorageLabelPointer->setText(i18nc("DOM storage label", "DOM storage enabled")); + if (Settings::localStorageEnabled()) + localStorageLabelPointer->setText(i18nc("Domain settings local storage label.", "Local storage enabled")); else - domStorageLabelPointer->setText(i18nc("DOM storage label", "DOM storage disabled")); + localStorageLabelPointer->setText(i18nc("Domain settings local storage label.", "Local storage disabled")); break; } + // Set the disabled text in bold. case (DomainsDatabaseHelper::DISABLED): { - // Set the label text in bold. - domStorageLabelPointer->setText(i18nc("DOM storage label. The tags should be retained.", "DOM storage disabled")); + localStorageLabelPointer->setText(i18nc("Domain settings local storage label. The tags should be retained.", "Local storage disabled")); break; } + // Set the enabled text in bold. case (DomainsDatabaseHelper::ENABLED): { - // Set the label text in bold. - domStorageLabelPointer->setText(i18nc("DOM storage label. The tags should be retained.", "DOM storage enabled")); + localStorageLabelPointer->setText(i18nc("Domain settings local storage label. The tabs should be retained.", "Local storage enabled")); break; } } } + void DomainSettingsDialog::populateUserAgentLabel(const QString &userAgentName) const { // Populate the label according to the type. @@ -472,7 +527,7 @@ void DomainSettingsDialog::showDeleteMessageBox() const QModelIndex currentIndex = domainsListViewPointer->currentIndex(); // Delete the current row. - domainsTableModelPointer->removeRow(domainsListViewPointer->selectionModel()->currentIndex().row()); + domainsTableModelPointer->removeRow(domainsSelectionModelPointer->currentIndex().row()); // Submit all pending changes. domainsTableModelPointer->submitAll(); @@ -504,7 +559,7 @@ void DomainSettingsDialog::showDeleteMessageBox() const void DomainSettingsDialog::updateUi() const { // Update the delete button status. - deleteDomainButtonPointer->setEnabled(domainsListViewPointer->selectionModel()->hasSelection()); + deleteDomainButtonPointer->setEnabled(domainsSelectionModelPointer->hasSelection()); // Update the apply button status. applyButtonPointer->setEnabled(domainsTableModelPointer->isDirty()); @@ -519,7 +574,7 @@ void DomainSettingsDialog::updateUi() const void DomainSettingsDialog::userAgentChanged(const QString &updatedUserAgent) const { // Update the domains table model. - domainsTableModelPointer->setData(domainsListViewPointer->selectionModel()->currentIndex().siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::USER_AGENT)), + domainsTableModelPointer->setData(domainsSelectionModelPointer->currentIndex().siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::USER_AGENT)), UserAgentHelper::getDatabaseUserAgentNameFromTranslatedName(updatedUserAgent)); // Populate the user agent label. @@ -532,7 +587,7 @@ void DomainSettingsDialog::userAgentChanged(const QString &updatedUserAgent) con void DomainSettingsDialog::zoomFactorComboBoxChanged(const int &newIndex) const { // Get the current model index. - QModelIndex modelIndex = domainsListViewPointer->selectionModel()->currentIndex(); + QModelIndex modelIndex = domainsSelectionModelPointer->currentIndex(); // Update the domains table model. domainsTableModelPointer->setData(modelIndex.siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::ZOOM_FACTOR)), newIndex); diff --git a/src/dialogs/DomainSettingsDialog.h b/src/dialogs/DomainSettingsDialog.h index a96c0d0..fb45902 100644 --- a/src/dialogs/DomainSettingsDialog.h +++ b/src/dialogs/DomainSettingsDialog.h @@ -55,6 +55,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(); @@ -69,12 +70,15 @@ private: QPushButton *deleteDomainButtonPointer; QComboBox *domStorageComboBoxPointer; QLabel *domStorageLabelPointer; - QListView *domainsListViewPointer; KLineEdit *domainNameLineEditPointer; QWidget *domainSettingsWidgetPointer; + QListView *domainsListViewPointer; QSqlTableModel *domainsTableModelPointer; + QItemSelectionModel *domainsSelectionModelPointer; QComboBox *javaScriptComboBoxPointer; QLabel *javaScriptLabelPointer; + QComboBox *localStorageComboBoxPointer; + QLabel *localStorageLabelPointer; QPushButton *resetButtonPointer; QComboBox *userAgentComboBoxPointer; QLabel *userAgentLabelPointer; @@ -82,8 +86,9 @@ private: // The private functions. void addDomain(const QString &domainName) const; - void populateJavaScriptLabel() const; void populateDomStorageLabel() const; + 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 2d63bd9..d1f8b22 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 = 4; +const int DomainsDatabaseHelper::SCHEMA_VERSION = 5; // 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::DOM_STORAGE = "dom_storage"; const QString DomainsDatabaseHelper::USER_AGENT = "user_agent"; const QString DomainsDatabaseHelper::ZOOM_FACTOR = "zoom_factor"; @@ -102,8 +103,22 @@ void DomainsDatabaseHelper::addDatabase() // Upgrade from schema version 3 to schema version 4. case 3: + { // Add the DOM Storage column. domainsDatabase.exec("ALTER TABLE " + DOMAINS_TABLE + " ADD COLUMN " + DOM_STORAGE + " INTEGER DEFAULT 0"); + + // Fallthrough to the next case. + [[fallthrough]]; + } + + case 4: + { + // Add the Local Storage column. + domainsDatabase.exec("ALTER TABLE " + DOMAINS_TABLE + " ADD COLUMN " + LOCAL_STORAGE + " INTEGER DEFAULT 0"); + + // Fallthrough to the next case. + // [[fallthrough]]; + } } // Update the schema version. @@ -120,6 +135,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, " + diff --git a/src/helpers/DomainsDatabaseHelper.h b/src/helpers/DomainsDatabaseHelper.h index 9ab0f92..50058db 100644 --- a/src/helpers/DomainsDatabaseHelper.h +++ b/src/helpers/DomainsDatabaseHelper.h @@ -47,6 +47,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/icons/cookies-off.svg b/src/icons/cookies-off.svg deleted file mode 100644 index 7f84085..0000000 --- a/src/icons/cookies-off.svg +++ /dev/null @@ -1,54 +0,0 @@ - - - - - - - - diff --git a/src/icons/cookies-on.svg b/src/icons/cookies-on.svg deleted file mode 100644 index 191f07a..0000000 --- a/src/icons/cookies-on.svg +++ /dev/null @@ -1,59 +0,0 @@ - - - - - - - - - - - diff --git a/src/resources.qrc b/src/resources.qrc index a311b84..cfa6f79 100644 --- a/src/resources.qrc +++ b/src/resources.qrc @@ -19,8 +19,6 @@ - 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 10d08f3..36193bf 100644 --- a/src/settings/Settings.kcfg +++ b/src/settings/Settings.kcfg @@ -32,7 +32,7 @@ false - + false diff --git a/src/structs/PrivacyWebEngine.cpp b/src/structs/PrivacyWebEngine.cpp index 14ccad7..411ac93 100644 --- a/src/structs/PrivacyWebEngine.cpp +++ b/src/structs/PrivacyWebEngine.cpp @@ -23,6 +23,6 @@ // Construct the struct. PrivacyWebEngine::PrivacyWebEngine(QWebEngineView *inputWebEngineViewPointer) : webEngineViewPointer(inputWebEngineViewPointer) { - // Initialize the cookie status. - cookiesEnabled = false; + // Initialize the local storage status. + localStorageEnabled = false; } diff --git a/src/structs/PrivacyWebEngine.h b/src/structs/PrivacyWebEngine.h index b536c4f..2d5035a 100644 --- a/src/structs/PrivacyWebEngine.h +++ b/src/structs/PrivacyWebEngine.h @@ -30,7 +30,7 @@ public: PrivacyWebEngine(QWebEngineView *inputWebEngineViewPointer); // The public variables. - bool cookiesEnabled; + bool localStorageEnabled; QWebEngineView *webEngineViewPointer; }; #endif diff --git a/src/ui.rcs/browser_ui.rc b/src/ui.rcs/browser_ui.rc index fd80ccb..2f77d1c 100644 --- a/src/ui.rcs/browser_ui.rc +++ b/src/ui.rcs/browser_ui.rc @@ -79,7 +79,7 @@ URL Toolbar - + diff --git a/src/uis/DomainSettingsDialog.ui b/src/uis/DomainSettingsDialog.ui index 1972848..9cf7324 100644 --- a/src/uis/DomainSettingsDialog.ui +++ b/src/uis/DomainSettingsDialog.ui @@ -148,11 +148,11 @@ - + - Cookies + Local storage @@ -162,7 +162,7 @@ - + System default @@ -171,20 +171,20 @@ - Cookies enabled + Local storage disabled - Cookies disabled + Local storage enabled - + Qt::RichText @@ -332,7 +332,7 @@ - Set the zoom factor between 0.25 and 5.00. + Valid values for the zoom factor are between 0.25 and 5.00. diff --git a/src/uis/SettingsGeneral.ui b/src/uis/SettingsGeneral.ui index 425ea65..5248663 100644 --- a/src/uis/SettingsGeneral.ui +++ b/src/uis/SettingsGeneral.ui @@ -121,7 +121,7 @@ - Set the zoom factor between 0.25 and 5.00. The default is 1.00. + Valid values for the zoom factor are between 0.25 and 5.00. The default is 1.00. diff --git a/src/uis/SettingsPrivacy.ui b/src/uis/SettingsPrivacy.ui index 6989f2a..0affb07 100644 --- a/src/uis/SettingsPrivacy.ui +++ b/src/uis/SettingsPrivacy.ui @@ -39,9 +39,9 @@ - + - Cookies + Local storage diff --git a/src/views/BrowserView.cpp b/src/views/BrowserView.cpp index 777d12e..440c694 100644 --- a/src/views/BrowserView.cpp +++ b/src/views/BrowserView.cpp @@ -69,10 +69,10 @@ BrowserView::BrowserView(QWidget *parent) : QWidget(parent) // Populate the privacy web engine list. privacyWebEngineListPointer->append(currentPrivacyWebEnginePointer); - // Set the cookie filter. + // Set the local storage filter. webEngineCookieStorePointer->setCookieFilter([this](const QWebEngineCookieStore::FilterRequest &filterRequest) { - // qDebug() << "Cookie page URL: " << filterRequest.firstPartyUrl << ", Cookie URL: " << filterRequest.origin << ", Is third-party: " << filterRequest.thirdParty; + // qDebug() << "Page URL: " << filterRequest.firstPartyUrl << ", Local storage 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(""))) @@ -82,7 +82,7 @@ BrowserView::BrowserView(QWidget *parent) : QWidget(parent) 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())) + if (privacyWebEnginePointer->localStorageEnabled && (webEngineViewPointer->url().host() == filterRequest.firstPartyUrl.host())) return true; } @@ -152,8 +152,7 @@ BrowserView::~BrowserView() webEnginePagePointer->deleteLater(); } -// The cookie is copied instead of referenced so that changes made to the cookie do not create a race condition with the display of the cookie in the dialog. -void BrowserView::addCookieToStore(QNetworkCookie cookie) const +void BrowserView::addCookieToStore(QNetworkCookie &cookie) const { // Create a url. QUrl url; @@ -213,56 +212,81 @@ void BrowserView::applyDomainSettings(const QString &hostname, const bool reload // Set the JavaScript status. switch (domainRecord.field(DomainsDatabaseHelper::JAVASCRIPT).value().toInt()) { + // Set the default JavaScript status. case (DomainsDatabaseHelper::SYSTEM_DEFAULT): { - // Set the default JavaScript status. webEngineSettingsPointer->setAttribute(QWebEngineSettings::JavascriptEnabled, Settings::javaScriptEnabled()); break; } + // Disable JavaScript. case (DomainsDatabaseHelper::DISABLED): { - // Disable JavaScript. webEngineSettingsPointer->setAttribute(QWebEngineSettings::JavascriptEnabled, false); break; } + // Enable JavaScript. case (DomainsDatabaseHelper::ENABLED): { - // Enable JavaScript. webEngineSettingsPointer->setAttribute(QWebEngineSettings::JavascriptEnabled, true); break; } } - // Set the cookie status. TODO. - currentPrivacyWebEnginePointer->cookiesEnabled = Settings::cookiesEnabled(); + // Set the local storage status. + switch (domainRecord.field(DomainsDatabaseHelper::LOCAL_STORAGE).value().toInt()) + { + // Set the default local storage status. + case (DomainsDatabaseHelper::SYSTEM_DEFAULT): + { + currentPrivacyWebEnginePointer->localStorageEnabled = Settings::localStorageEnabled(); - // Set DOM storage. + break; + } + + // Disable local storage. + case (DomainsDatabaseHelper::DISABLED): + { + currentPrivacyWebEnginePointer->localStorageEnabled = false; + + break; + } + + // Enable local storage. + case (DomainsDatabaseHelper::ENABLED): + { + currentPrivacyWebEnginePointer->localStorageEnabled = true; + + break; + } + } + + // Set the DOM storage status. switch (domainRecord.field(DomainsDatabaseHelper::DOM_STORAGE).value().toInt()) { + // Set the default DOM storage status. case (DomainsDatabaseHelper::SYSTEM_DEFAULT): { - // Set the default DOM storage status. webEngineSettingsPointer->setAttribute(QWebEngineSettings::LocalStorageEnabled, Settings::domStorageEnabled()); break; } + // Disable DOM storage. case (DomainsDatabaseHelper::DISABLED): { - // Disable DOM storage. webEngineSettingsPointer->setAttribute(QWebEngineSettings::LocalStorageEnabled, false); break; } + // Enable DOM storage. case (DomainsDatabaseHelper::ENABLED): { - // Enable DOM storage. webEngineSettingsPointer->setAttribute(QWebEngineSettings::LocalStorageEnabled, true); break; @@ -295,8 +319,8 @@ void BrowserView::applyDomainSettings(const QString &hostname, const bool reload // Set the JavaScript status. webEngineSettingsPointer->setAttribute(QWebEngineSettings::JavascriptEnabled, Settings::javaScriptEnabled()); - // Set the cookie status. - currentPrivacyWebEnginePointer->cookiesEnabled = Settings::cookiesEnabled(); + // Set the local storage status. + currentPrivacyWebEnginePointer->localStorageEnabled = Settings::localStorageEnabled(); // Set DOM storage. webEngineSettingsPointer->setAttribute(QWebEngineSettings::LocalStorageEnabled, Settings::domStorageEnabled()); @@ -316,7 +340,7 @@ void BrowserView::applyDomainSettings(const QString &hostname, const bool reload // Emit the update actions signals. emit updateJavaScriptAction(webEngineSettingsPointer->testAttribute(QWebEngineSettings::JavascriptEnabled)); - emit updateCookiesAction(currentPrivacyWebEnginePointer->cookiesEnabled); + emit updateLocalStorageAction(currentPrivacyWebEnginePointer->localStorageEnabled); emit updateDomStorageAction(webEngineSettingsPointer->testAttribute(QWebEngineSettings::LocalStorageEnabled)); emit updateUserAgentActions(webEngineProfilePointer->httpUserAgent()); emit updateZoomFactorAction(webEngineViewPointer->zoomFactor()); @@ -511,13 +535,13 @@ void BrowserView::refresh() const webEngineViewPointer->reload(); } -void BrowserView::toggleCookies() +void BrowserView::toggleDomStorage() const { - // Toggle cookies. - currentPrivacyWebEnginePointer->cookiesEnabled = !currentPrivacyWebEnginePointer->cookiesEnabled; + // Toggle DOM storage. + webEngineSettingsPointer->setAttribute(QWebEngineSettings::LocalStorageEnabled, !webEngineSettingsPointer->testAttribute(QWebEngineSettings::LocalStorageEnabled)); - // Update the cookies icon. - emit updateCookiesAction(currentPrivacyWebEnginePointer->cookiesEnabled); + // Update the DOM storage action. + emit updateDomStorageAction(webEngineSettingsPointer->testAttribute(QWebEngineSettings::LocalStorageEnabled)); // Reload the website. webEngineViewPointer->reload(); @@ -528,20 +552,20 @@ void BrowserView::toggleJavaScript() const // Toggle JavaScript. webEngineSettingsPointer->setAttribute(QWebEngineSettings::JavascriptEnabled, !webEngineSettingsPointer->testAttribute(QWebEngineSettings::JavascriptEnabled)); - // Update the JavaScript icon. + // Update the JavaScript action. emit updateJavaScriptAction(webEngineSettingsPointer->testAttribute(QWebEngineSettings::JavascriptEnabled)); // Reload the website. webEngineViewPointer->reload(); } -void BrowserView::toggleDomStorage() const +void BrowserView::toggleLocalStorage() { - // Toggle DOM storage. - webEngineSettingsPointer->setAttribute(QWebEngineSettings::LocalStorageEnabled, !webEngineSettingsPointer->testAttribute(QWebEngineSettings::LocalStorageEnabled)); + // Toggle local storeage. + currentPrivacyWebEnginePointer->localStorageEnabled = !currentPrivacyWebEnginePointer->localStorageEnabled; - // Update the DOM storage action icon. - emit updateDomStorageAction(webEngineSettingsPointer->testAttribute(QWebEngineSettings::LocalStorageEnabled)); + // Update the local storage action. + emit updateLocalStorageAction(currentPrivacyWebEnginePointer->localStorageEnabled); // Reload the website. webEngineViewPointer->reload(); diff --git a/src/views/BrowserView.h b/src/views/BrowserView.h index 0314966..859a93f 100644 --- a/src/views/BrowserView.h +++ b/src/views/BrowserView.h @@ -48,9 +48,9 @@ public: // The public functions. void applyOnTheFlyZoomFactor(const double &zoomFactor); void loadInitialWebsite(); - void toggleCookies(); void toggleDomStorage() const; void toggleJavaScript() const; + void toggleLocalStorage(); // The public static variables. static QString webEngineDefaultUserAgent; @@ -64,11 +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; @@ -76,7 +76,7 @@ signals: public Q_SLOTS: // The public slots. - void addCookieToStore(QNetworkCookie cookie) const; + void addCookieToStore(QNetworkCookie &cookie) const; void applyApplicationSettings(); void applyDomainSettingsAndReload(); void applyDomainSettingsWithoutReloading(const QString &hostname); diff --git a/src/windows/BrowserWindow.cpp b/src/windows/BrowserWindow.cpp index ef264a5..60ddaa4 100644 --- a/src/windows/BrowserWindow.cpp +++ b/src/windows/BrowserWindow.cpp @@ -41,8 +41,8 @@ BrowserWindow::BrowserWindow() : KXmlGuiWindow() { // Initialize the variables. cookieListPointer = new std::list; - cookiesEnabled = false; javaScriptEnabled = false; + localStorageEnabled = false; // Instantiate the main view pointer. browserViewPointer = new BrowserView(this); @@ -83,7 +83,7 @@ BrowserWindow::BrowserWindow() : KXmlGuiWindow() QAction *domainSettingsActionPointer = actionCollectionPointer->addAction(QStringLiteral("domain_settings")); cookiesActionPointer = actionCollectionPointer->addAction(QStringLiteral("cookies")); javaScriptActionPointer = actionCollectionPointer->addAction(QStringLiteral("javascript")); - onTheFlyCookiesActionPointer = actionCollectionPointer->addAction(QStringLiteral("on-the-fly_cookies")); + localStorageActionPointer = actionCollectionPointer->addAction(QStringLiteral("local_storage")); domStorageActionPointer = actionCollectionPointer->addAction(QStringLiteral("dom_storage")); // Create the action groups @@ -109,6 +109,9 @@ BrowserWindow::BrowserWindow() : KXmlGuiWindow() searchEngineActionGroupPointer->addAction(searchEngineCustomActionPointer); // Set some actions to be checkable. + javaScriptActionPointer->setCheckable(true); + localStorageActionPointer->setCheckable(true); + domStorageActionPointer->setCheckable(true); userAgentPrivacyBrowserActionPointer->setCheckable(true); userAgentWebEngineDefaultActionPointer->setCheckable(true); userAgentFirefoxLinuxActionPointer->setCheckable(true); @@ -126,9 +129,6 @@ BrowserWindow::BrowserWindow() : KXmlGuiWindow() searchEngineYahooActionPointer->setCheckable(true); searchEngineCustomActionPointer->setCheckable(true); - // 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); @@ -145,9 +145,9 @@ 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("The Cookies action, which also displays the number of cookies", "Cookies - %1", numberOfCookies)); + cookiesActionPointer->setText(i18nc("The Cookies action, which also displays the number of cookies", "Cookies - %1", cookieListPointer->size())); javaScriptActionPointer->setText(i18nc("JavaScript action", "JavaScript")); - onTheFlyCookiesActionPointer->setText(i18nc("The On-The-Fly Cookies action, which also display the number of cookies", "Cookies - %1", numberOfCookies)); + localStorageActionPointer->setText(i18nc("The Local Storage action", "Local Storage")); domStorageActionPointer->setText(i18nc("DOM Storage action", "DOM Storage")); // Set the action icons. @@ -170,7 +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")); + domStorageActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("view-web-browser-dom-tree"))); // Update the on-the-fly menus. connect(browserViewPointer, SIGNAL(updateUserAgentActions(QString)), this, SLOT(updateUserAgentActions(QString))); @@ -188,14 +188,14 @@ BrowserWindow::BrowserWindow() : KXmlGuiWindow() // Connect the URL toolbar actions. connect(javaScriptActionPointer, SIGNAL(triggered()), this, SLOT(toggleJavaScript())); - connect(onTheFlyCookiesActionPointer, SIGNAL(triggered()), this, SLOT(toggleCookies())); + connect(localStorageActionPointer, SIGNAL(triggered()), this, SLOT(toggleLocalStorage())); 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(updateCookiesAction(bool)), this, SLOT(updateCookiesAction(bool))); + connect(browserViewPointer, SIGNAL(updateLocalStorageAction(bool)), this, SLOT(updateLocalStorageAction(bool))); connect(browserViewPointer, SIGNAL(updateDomStorageAction(bool)), this, SLOT(updateDomStorageAction(bool))); // Setup the GUI based on the browser_ui.rc file. @@ -266,12 +266,8 @@ void BrowserWindow::addCookieToList(const QNetworkCookie &newCookie) const // 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)); + cookiesActionPointer->setText(i18nc("The Cookies action, which also displays the number of cookies", "Cookies - %1", cookieListPointer->size())); } void BrowserWindow::addOrEditDomainSettings() const @@ -427,12 +423,8 @@ 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)); + cookiesActionPointer->setText(i18nc("The Cookies action, which also displays the number of cookies", "Cookies - %1", cookieListPointer->size())); } void BrowserWindow::showProgressBar(const int &progress) const @@ -525,13 +517,13 @@ void BrowserWindow::settingsConfigure() } } -void BrowserWindow::toggleCookies() const +void BrowserWindow::toggleLocalStorage() const { // Remove the focus from teh URL line edit. urlLineEditPointer->clearFocus(); - // Toggle cookies. - browserViewPointer->toggleCookies(); + // Toggle local storage. + browserViewPointer->toggleLocalStorage(); } void BrowserWindow::toggleJavaScript() const @@ -552,19 +544,10 @@ void BrowserWindow::toggleDomStorage() const browserViewPointer->toggleDomStorage(); } -void BrowserWindow::updateCookiesAction(const bool &isEnabled) +void BrowserWindow::updateDomStorageAction(const bool &isEnabled) const { - // 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); + // Set the action checked status. + domStorageActionPointer->setChecked(isEnabled); } void BrowserWindow::updateDomainSettingsIndicator(const bool &status, const QString &domainSettingsDomain) @@ -586,21 +569,33 @@ void BrowserWindow::updateJavaScriptAction(const bool &isEnabled) // Set the icon according to the status. if (javaScriptEnabled) - javaScriptActionPointer->setIcon(QIcon(":/icons/javascript-warning")); + javaScriptActionPointer->setIcon(QIcon(QStringLiteral(":/icons/javascript-warning"))); else - javaScriptActionPointer->setIcon(QIcon(":/icons/privacy-mode")); + javaScriptActionPointer->setIcon(QIcon(QStringLiteral(":/icons/privacy-mode"))); + + // Set the action checked status. + javaScriptActionPointer->setChecked(javaScriptEnabled); // Update the status of the DOM storage action. - domStorageActionPointer->setEnabled(javaScriptEnabled & cookiesEnabled); + domStorageActionPointer->setEnabled(javaScriptEnabled & localStorageEnabled); } -void BrowserWindow::updateDomStorageAction(const bool &isEnabled) const +void BrowserWindow::updateLocalStorageAction(const bool &isEnabled) { - // Set the icon according to the status. - if (isEnabled) - domStorageActionPointer->setIcon(QIcon::fromTheme("disk-quota-low")); + // Update the local storage status. + localStorageEnabled = isEnabled; + + // Update the icon. + if (localStorageEnabled) + localStorageActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("disk-quota-high"))); else - domStorageActionPointer->setIcon(QIcon::fromTheme("disk-quota")); + localStorageActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("disk-quota"))); + + // Set the action checked status. + localStorageActionPointer->setChecked(localStorageEnabled); + + // Update the status of the DOM storage action. + domStorageActionPointer->setEnabled(localStorageEnabled & javaScriptEnabled); } void BrowserWindow::updateSearchEngineActions(const QString &searchEngine) const diff --git a/src/windows/BrowserWindow.h b/src/windows/BrowserWindow.h index c66a528..0239a4e 100644 --- a/src/windows/BrowserWindow.h +++ b/src/windows/BrowserWindow.h @@ -63,13 +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 updateCookiesAction(const bool &isEnabled); + void toggleLocalStorage() const; void updateDomStorageAction(const bool &isEnabled) const; void updateDomainSettingsIndicator(const bool &status, const QString &domainSettingsDomain); void updateJavaScriptAction(const bool &isEnabled); + void updateLocalStorageAction(const bool &isEnabled); void updateSearchEngineActions(const QString &searchEngine) const; void updateUserAgentActions(const QString &userAgent) const; void updateZoomFactorAction(const double &zoomFactor); @@ -83,7 +83,6 @@ private: KConfigDialog *configDialogPointer; std::list *cookieListPointer; QAction *cookiesActionPointer; - bool cookiesEnabled; QString currentDomainSettingsDomain; QUrl currentUrl; double currentZoomFactor; @@ -91,8 +90,9 @@ private: QPalette domainSettingsPalette; QAction *javaScriptActionPointer; bool javaScriptEnabled; + QAction *localStorageActionPointer; + bool localStorageEnabled; QPalette noDomainSettingsPalette; - QAction *onTheFlyCookiesActionPointer; QProgressBar *progressBarPointer; QLabel *searchEngineLabelPointer; QAction *searchEngineMojeekActionPointer; -- 2.45.2