From 310828788817f6acf54c77138ec38d97c8bdaf3d Mon Sep 17 00:00:00 2001 From: Soren Stoutner Date: Wed, 14 Jun 2023 15:58:47 -0700 Subject: [PATCH] Move `enabled` above `disabled` in the domain settings spinners. https://redmine.stoutner.com/issues/1019 --- doc/index.docbook | 4 +- src/databases/CookiesDatabase.cpp | 98 ++++++++++------ src/databases/CookiesDatabase.h | 4 +- src/databases/DomainsDatabase.cpp | 162 ++++++++++++++++++++++----- src/databases/DomainsDatabase.h | 8 +- src/dialogs/DomainSettingsDialog.cpp | 42 +++---- src/dialogs/DurableCookiesDialog.cpp | 4 +- src/uis/DomainSettingsDialog.ui | 12 +- src/widgets/PrivacyWebEngineView.cpp | 53 +++++---- 9 files changed, 263 insertions(+), 124 deletions(-) diff --git a/doc/index.docbook b/doc/index.docbook index f9b5f61..fbad58a 100644 --- a/doc/index.docbook +++ b/doc/index.docbook @@ -1323,8 +1323,8 @@ - 0.4 - - 13 June 2023 + <ulink url="https://www.stoutner.com/privacy-browser-pc-0-4/">0.4</ulink> - + <ulink url="https://gitweb.stoutner.com/?p=PrivacyBrowserPC.git;a=commitdiff;h=b4c8c8d02113d14c2a07751eb3b0c1bdeec7abb4">13 June 2023</ulink> Add a setting to control spatial navigation. diff --git a/src/databases/CookiesDatabase.cpp b/src/databases/CookiesDatabase.cpp index 207f45b..dcb6f0b 100644 --- a/src/databases/CookiesDatabase.cpp +++ b/src/databases/CookiesDatabase.cpp @@ -1,5 +1,5 @@ /* - * Copyright © 2022 Soren Stoutner . + * Copyright 2022-2023 Soren Stoutner . * * This file is part of Privacy Browser PC . * @@ -23,17 +23,15 @@ // Define the private static schema constants. const int CookiesDatabase::SCHEMA_VERSION = 0; -// Define the public static database constants. +// Define the public static constants. const QString CookiesDatabase::CONNECTION_NAME = "cookies_database"; const QString CookiesDatabase::COOKIES_TABLE = "cookies"; - -// Define the public static database field names. -const QString CookiesDatabase::_ID = "_id"; const QString CookiesDatabase::DOMAIN = "domain"; -const QString CookiesDatabase::NAME = "name"; -const QString CookiesDatabase::PATH = "path"; const QString CookiesDatabase::EXPIRATION_DATE = "expiration_date"; const QString CookiesDatabase::HTTP_ONLY = "http_only"; +const QString CookiesDatabase::ID = "_id"; +const QString CookiesDatabase::NAME = "name"; +const QString CookiesDatabase::PATH = "path"; const QString CookiesDatabase::SECURE = "secure"; const QString CookiesDatabase::VALUE = "value"; @@ -83,15 +81,14 @@ void CookiesDatabase::addDatabase() // Prepare the create table query. createTableQuery.prepare("CREATE TABLE " + COOKIES_TABLE + "(" + - _ID + " INTEGER PRIMARY KEY, " + - DOMAIN + " TEXT NOT NULL, " + - NAME + " TEXT NOT NULL, " + - PATH + " TEXT NOT NULL, " + - EXPIRATION_DATE + " TEXT, " + - HTTP_ONLY + " INTEGER NOT NULL DEFAULT 0, " + - SECURE + " INTEGER NOT NULL DEFAULT 0, " + - VALUE + " TEXT NOT NULL)" - ); + ID + " INTEGER PRIMARY KEY, " + + DOMAIN + " TEXT NOT NULL, " + + NAME + " TEXT NOT NULL, " + + PATH + " TEXT NOT NULL, " + + EXPIRATION_DATE + " TEXT, " + + HTTP_ONLY + " INTEGER NOT NULL DEFAULT 0, " + + SECURE + " INTEGER NOT NULL DEFAULT 0, " + + VALUE + " TEXT NOT NULL)"); // Execute the query. if (!createTableQuery.exec()) @@ -128,8 +125,15 @@ void CookiesDatabase::addCookie(const QNetworkCookie &cookie) QSqlQuery addCookieQuery(cookiesDatabase); // Prepare the add cookie query. - addCookieQuery.prepare("INSERT INTO " + COOKIES_TABLE + " (" + DOMAIN + ", " + NAME + ", " + PATH + ", " + EXPIRATION_DATE + ", " + HTTP_ONLY + ", " + SECURE + ", " + VALUE + ") " - "VALUES (:domain, :name, :path, :expiration_date, :http_only, :secure, :value)" + addCookieQuery.prepare("INSERT INTO " + COOKIES_TABLE + " (" + + DOMAIN + ", " + + NAME + ", " + + PATH + ", " + + EXPIRATION_DATE + ", " + + HTTP_ONLY + ", " + + SECURE + ", " + + VALUE + ") " + "VALUES (:domain, :name, :path, :expiration_date, :http_only, :secure, :value)" ); // Bind the values. @@ -158,7 +162,7 @@ int CookiesDatabase::cookieCount() countCookiesQuery.setForwardOnly(true); // Prepare the query. - countCookiesQuery.prepare("SELECT " + _ID + " FROM " + COOKIES_TABLE); + countCookiesQuery.prepare("SELECT " + ID + " FROM " + COOKIES_TABLE); // Execute the query. countCookiesQuery.exec(); @@ -204,7 +208,10 @@ void CookiesDatabase::deleteCookie(const QNetworkCookie &cookie) QSqlQuery deleteCookieQuery(cookiesDatabase); // Prepare the delete cookie query. - deleteCookieQuery.prepare("DELETE FROM " + COOKIES_TABLE + " WHERE " + DOMAIN + " = :domain AND " + NAME + " = :name AND " + PATH + " = :path"); + deleteCookieQuery.prepare("DELETE FROM " + COOKIES_TABLE + " WHERE " + + DOMAIN + " = :domain AND " + + NAME + " = :name AND " + + PATH + " = :path"); // Bind the values. deleteCookieQuery.bindValue(":domain", cookie.domain()); @@ -270,7 +277,7 @@ QNetworkCookie* CookiesDatabase::getCookieById(const int &id) cookieQuery.setForwardOnly(true); // Prepare the cookies query. - cookieQuery.prepare("SELECT * FROM " + COOKIES_TABLE + " WHERE " + _ID + " = :id"); + cookieQuery.prepare("SELECT * FROM " + COOKIES_TABLE + " WHERE " + ID + " = :id"); // Bind the values. cookieQuery.bindValue(":id", id); @@ -309,7 +316,10 @@ bool CookiesDatabase::isDurable(const QNetworkCookie &cookie) isDurableQuery.setForwardOnly(true); // Prepare the is durable query. - isDurableQuery.prepare("SELECT " + _ID + " FROM " + COOKIES_TABLE + " WHERE " + DOMAIN + " = :domain AND " + NAME + " = :name AND " + PATH + " = :path"); + isDurableQuery.prepare("SELECT " + ID + " FROM " + COOKIES_TABLE + " WHERE " + + DOMAIN + " = :domain AND " + + NAME + " = :name AND " + + PATH + " = :path"); // Bind the values. isDurableQuery.bindValue(":domain", cookie.domain()); @@ -335,8 +345,14 @@ bool CookiesDatabase::isUpdate(const QNetworkCookie &cookie) QSqlQuery isUpdateQuery(cookiesDatabase); // Prepare the is update query. - isUpdateQuery.prepare("SELECT " + EXPIRATION_DATE + " , " + HTTP_ONLY + " , " + SECURE + " , " + VALUE + " FROM " + COOKIES_TABLE + " WHERE " + DOMAIN + " = :domain AND " + - NAME + " = :name AND " + PATH + " = :path"); + isUpdateQuery.prepare("SELECT " + EXPIRATION_DATE + " , " + + HTTP_ONLY + " , " + + SECURE + " , " + + VALUE + + " FROM " + COOKIES_TABLE + + " WHERE " + DOMAIN + " = :domain AND " + + NAME + " = :name AND " + + PATH + " = :path"); // Bind the values. isUpdateQuery.bindValue(":domain", cookie.domain()); @@ -353,10 +369,10 @@ bool CookiesDatabase::isUpdate(const QNetworkCookie &cookie) if (isUpdateQuery.isValid()) // The cookie exists in the database. { // Check to see if the cookie data has changed. - if ((QDateTime::fromString(isUpdateQuery.value(0).toString(), Qt::ISODate) != cookie.expirationDate()) || - (isUpdateQuery.value(1).toBool() != cookie.isHttpOnly()) || - (isUpdateQuery.value(2).toBool() != cookie.isSecure()) || - (isUpdateQuery.value(3).toString().toUtf8() != cookie.value())) // The cookies data has changed. + if ((QDateTime::fromString(isUpdateQuery.value(EXPIRATION_DATE).toString(), Qt::ISODate) != cookie.expirationDate()) || + (isUpdateQuery.value(HTTP_ONLY).toBool() != cookie.isHttpOnly()) || + (isUpdateQuery.value(SECURE).toBool() != cookie.isSecure()) || + (isUpdateQuery.value(VALUE).toString().toUtf8() != cookie.value())) // The cookies data has changed. { //qDebug() << "The durable cookie data has changed."; @@ -387,8 +403,14 @@ void CookiesDatabase::updateCookie(const QNetworkCookie &cookie) QSqlQuery updateCookieQuery(cookiesDatabase); // Prepare the edit cookie query. - updateCookieQuery.prepare("UPDATE " + COOKIES_TABLE + " SET " + EXPIRATION_DATE + " = :expiration_date , " + HTTP_ONLY + " = :http_only , " + SECURE + " = :secure , " + - VALUE + " = :value WHERE " + DOMAIN + " = :domain AND " + NAME + " = :name AND " + PATH + " = :path"); + updateCookieQuery.prepare("UPDATE " + COOKIES_TABLE + + " SET " + EXPIRATION_DATE + " = :expiration_date , " + + HTTP_ONLY + " = :http_only , " + + SECURE + " = :secure , " + + VALUE + " = :value " + + "WHERE " + DOMAIN + " = :domain AND " + + NAME + " = :name AND " + + PATH + " = :path"); // Bind the values. updateCookieQuery.bindValue(":domain", cookie.domain()); @@ -415,7 +437,10 @@ void CookiesDatabase::updateCookie(const QNetworkCookie &oldCookie, const QNetwo oldCookieQuery.setForwardOnly(true); // Prepare the old cookie query. - oldCookieQuery.prepare("SELECT " + _ID + " FROM " + COOKIES_TABLE + " WHERE " + DOMAIN + " = :domain AND " + NAME + " = :name AND " + PATH + " = :path"); + oldCookieQuery.prepare("SELECT " + ID + " FROM " + COOKIES_TABLE + + " WHERE " + DOMAIN + " = :domain AND " + + NAME + " = :name AND " + + PATH + " = :path"); // Bind the values. oldCookieQuery.bindValue(":domain", oldCookie.domain()); @@ -432,8 +457,15 @@ void CookiesDatabase::updateCookie(const QNetworkCookie &oldCookie, const QNetwo QSqlQuery updateCookieQuery(cookiesDatabase); // Prepare the update cookie query. - updateCookieQuery.prepare("UPDATE " + COOKIES_TABLE + " SET " + DOMAIN + " = :domain , " + NAME + " = :name , " + PATH + " = :path , " + EXPIRATION_DATE + " = :expiration_date , " + - HTTP_ONLY + " = :http_only , " + SECURE + " = :secure , " + VALUE + " = :value WHERE " + _ID + " = :id"); + updateCookieQuery.prepare("UPDATE " + COOKIES_TABLE + + " SET " + DOMAIN + " = :domain , " + + NAME + " = :name , " + + PATH + " = :path , " + + EXPIRATION_DATE + " = :expiration_date , " + + HTTP_ONLY + " = :http_only , " + + SECURE + " = :secure , " + + VALUE + " = :value " + + "WHERE " + ID + " = :id"); // Bind the values. updateCookieQuery.bindValue(":id", oldCookieQuery.value(0).toLongLong()); diff --git a/src/databases/CookiesDatabase.h b/src/databases/CookiesDatabase.h index 76e788c..b81557b 100644 --- a/src/databases/CookiesDatabase.h +++ b/src/databases/CookiesDatabase.h @@ -1,5 +1,5 @@ /* - * Copyright © 2022 Soren Stoutner . + * Copyright 2022-2023 Soren Stoutner . * * This file is part of Privacy Browser PC . * @@ -44,12 +44,12 @@ public: static void updateCookie(const QNetworkCookie &oldCookie, const QNetworkCookie &newCookie); // The public constants. - static const QString _ID; static const QString CONNECTION_NAME; static const QString COOKIES_TABLE; static const QString DOMAIN; static const QString EXPIRATION_DATE; static const QString HTTP_ONLY; + static const QString ID; static const QString NAME; static const QString PATH; static const QString SECURE; diff --git a/src/databases/DomainsDatabase.cpp b/src/databases/DomainsDatabase.cpp index 6dfc1bd..0553543 100644 --- a/src/databases/DomainsDatabase.cpp +++ b/src/databases/DomainsDatabase.cpp @@ -1,5 +1,5 @@ /* - * Copyright © 2022 Soren Stoutner . + * Copyright 2022-2023 Soren Stoutner . * * This file is part of Privacy Browser PC . * @@ -22,21 +22,19 @@ #include "helpers/UserAgentHelper.h" // Define the private static schema constants. -const int DomainsDatabase::SCHEMA_VERSION = 5; +const int DomainsDatabase::SCHEMA_VERSION = 6; -// Define the public static database constants. +// Define the public static constants. const QString DomainsDatabase::CONNECTION_NAME = "domains_database"; -const QString DomainsDatabase::DOMAINS_TABLE = "domains"; - -// Define the public static database field names. -const QString DomainsDatabase::_ID = "_id"; +const QString DomainsDatabase::CUSTOM_ZOOM_FACTOR = "custom_zoom_factor"; +const QString DomainsDatabase::DOM_STORAGE = "dom_storage"; const QString DomainsDatabase::DOMAIN_NAME = "domain_name"; +const QString DomainsDatabase::DOMAINS_TABLE = "domains"; +const QString DomainsDatabase::ID = "_id"; const QString DomainsDatabase::JAVASCRIPT = "javascript"; const QString DomainsDatabase::LOCAL_STORAGE = "local_storage"; -const QString DomainsDatabase::DOM_STORAGE = "dom_storage"; const QString DomainsDatabase::USER_AGENT = "user_agent"; const QString DomainsDatabase::ZOOM_FACTOR = "zoom_factor"; -const QString DomainsDatabase::CUSTOM_ZOOM_FACTOR = "custom_zoom_factor"; // Construct the class. DomainsDatabase::DomainsDatabase() {} @@ -76,7 +74,7 @@ void DomainsDatabase::addDatabase() // Add the JavaScript column. domainsDatabase.exec("ALTER TABLE " + DOMAINS_TABLE + " ADD COLUMN " + JAVASCRIPT + " INTEGER DEFAULT 0"); - // Fallthrough to the next case. + // Fall through to the next case. [[fallthrough]]; } @@ -86,7 +84,7 @@ void DomainsDatabase::addDatabase() // Add the User Agent column. domainsDatabase.exec("ALTER TABLE " + DOMAINS_TABLE + " ADD COLUMN " + USER_AGENT + " TEXT DEFAULT '" + UserAgentHelper::SYSTEM_DEFAULT_DATABASE + "'"); - // Fallthrough to the next case. + // Fall through to the next case. [[fallthrough]]; } @@ -97,7 +95,7 @@ void DomainsDatabase::addDatabase() 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. + // Fall through to the next case. [[fallthrough]]; } @@ -107,7 +105,7 @@ void DomainsDatabase::addDatabase() // Add the DOM Storage column. domainsDatabase.exec("ALTER TABLE " + DOMAINS_TABLE + " ADD COLUMN " + DOM_STORAGE + " INTEGER DEFAULT 0"); - // Fallthrough to the next case. + // Fall through to the next case. [[fallthrough]]; } @@ -117,7 +115,120 @@ void DomainsDatabase::addDatabase() // Add the Local Storage column. domainsDatabase.exec("ALTER TABLE " + DOMAINS_TABLE + " ADD COLUMN " + LOCAL_STORAGE + " INTEGER DEFAULT 0"); - // Fallthrough to the next case. + // Fall through to the next case. + [[fallthrough]]; + } + + // Upgrade from schema version 5 to schema version 6. + case 5: + { + // Instantiate a spinner query. + QSqlQuery spinnerQuery(domainsDatabase); + + // Set the query to be forward only (increases performance while iterating over the query). + spinnerQuery.setForwardOnly(true); + + // Prepare the query. + spinnerQuery.prepare("SELECT " + ID + "," + JAVASCRIPT + "," + LOCAL_STORAGE + "," + DOM_STORAGE + " FROM " + DOMAINS_TABLE); + + // Execute the query. + spinnerQuery.exec(); + + // Update the spinner values so that enabled is 1 and disabled is 2. + while (spinnerQuery.next()) + { + // Initialize the new spinner values. + int newJavaScriptValue = SYSTEM_DEFAULT; + int newLocalStorageValue = SYSTEM_DEFAULT; + int newDomStorageValue = SYSTEM_DEFAULT; + + // Update the new JavaScript value if needed. + switch (spinnerQuery.value(JAVASCRIPT).toInt()) + { + // Disabled used to be 1. + case 1: + { + // Update the value to be 2. + newJavaScriptValue = DISABLED; + + break; + } + + // Enabled used to be 2. + case 2: + { + // Update the new value to be 1. + newJavaScriptValue = ENABLED; + + break; + } + } + + // Update the new local storage value if needed. + switch (spinnerQuery.value(LOCAL_STORAGE).toInt()) + { + // Disabled used to be 1. + case 1: + { + // Update the new value to be 2. + newLocalStorageValue = DISABLED; + + break; + } + + // Enabled used to be 2. + case 2: + { + // Update the new value to be 1. + newLocalStorageValue = ENABLED; + + break; + } + } + + // Update the new DOM storage value if needed. + switch (spinnerQuery.value(DOM_STORAGE).toInt()) + { + // Disabled used to be 1. + case 1: + { + // Update the new value to be 2. + newDomStorageValue = DISABLED; + + break; + } + + // Enabled used to be 2. + case 2: + { + // Update the new value to be 1. + newDomStorageValue = ENABLED; + + break; + } + } + + // Create an update spinner query. + QSqlQuery updateSpinnerQuery(domainsDatabase); + + // Prepare the update spinner query. + updateSpinnerQuery.prepare("UPDATE " + DOMAINS_TABLE + " SET " + + JAVASCRIPT + " = :javascript , " + + LOCAL_STORAGE + " = :local_storage , " + + DOM_STORAGE + " = :dom_storage " + + " WHERE " + ID + " = :id"); + + // Bind the values. + updateSpinnerQuery.bindValue(":javascript", newJavaScriptValue); + updateSpinnerQuery.bindValue(":local_storage", newLocalStorageValue); + updateSpinnerQuery.bindValue(":dom_storage", newDomStorageValue); + updateSpinnerQuery.bindValue(":id", spinnerQuery.value(ID)); + + // Execute the query. + updateSpinnerQuery.exec(); + } + + // Fall through to the next case. // [[fallthrough]]; } } @@ -133,15 +244,14 @@ void DomainsDatabase::addDatabase() // Prepare the create table query. createTableQuery.prepare("CREATE TABLE " + DOMAINS_TABLE + "(" + - _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)" - ); + 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)"); // Execute the query. if (!createTableQuery.exec()) @@ -173,7 +283,7 @@ QSqlQuery DomainsDatabase::getDomainQuery(const QString &hostname) allDomainNamesQuery.setForwardOnly(true); // Prepare the query. - allDomainNamesQuery.prepare("SELECT " + _ID + "," + DOMAIN_NAME + " FROM " + DOMAINS_TABLE); + allDomainNamesQuery.prepare("SELECT " + ID + "," + DOMAIN_NAME + " FROM " + DOMAINS_TABLE); // Execute the query. allDomainNamesQuery.exec(); @@ -185,7 +295,7 @@ QSqlQuery DomainsDatabase::getDomainQuery(const QString &hostname) while (allDomainNamesQuery.next()) { // Add the domain name and database ID to the map. - domainSettingsMap.insert(allDomainNamesQuery.record().field(DOMAIN_NAME).value().toString(), allDomainNamesQuery.record().field(_ID).value().toInt()); + domainSettingsMap.insert(allDomainNamesQuery.value(DOMAIN_NAME).toString(), allDomainNamesQuery.value(ID).toInt()); } // Initialize the database ID tracker. @@ -218,7 +328,7 @@ QSqlQuery DomainsDatabase::getDomainQuery(const QString &hostname) QSqlQuery domainLookupQuery(domainsDatabase); // Prepare the domain lookup query. - domainLookupQuery.prepare("SELECT * FROM " + DOMAINS_TABLE + " WHERE " + _ID + " = " + QString::number(databaseId)); + domainLookupQuery.prepare("SELECT * FROM " + DOMAINS_TABLE + " WHERE " + ID + " = " + QString::number(databaseId)); // Execute the query. domainLookupQuery.exec(); diff --git a/src/databases/DomainsDatabase.h b/src/databases/DomainsDatabase.h index a75b831..cb7e09d 100644 --- a/src/databases/DomainsDatabase.h +++ b/src/databases/DomainsDatabase.h @@ -1,5 +1,5 @@ /* - * Copyright © 2022 Soren Stoutner . + * Copyright 2022-2023 Soren Stoutner . * * This file is part of Privacy Browser PC . * @@ -35,17 +35,17 @@ public: // The public int constants. static const int SYSTEM_DEFAULT = 0; - static const int DISABLED = 1; - static const int ENABLED = 2; + static const int ENABLED = 1; + static const int DISABLED = 2; static const int CUSTOM = 1; // The public constants. - 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 ID; static const QString JAVASCRIPT; static const QString LOCAL_STORAGE; static const QString USER_AGENT; diff --git a/src/dialogs/DomainSettingsDialog.cpp b/src/dialogs/DomainSettingsDialog.cpp index ea5558c..6964d37 100644 --- a/src/dialogs/DomainSettingsDialog.cpp +++ b/src/dialogs/DomainSettingsDialog.cpp @@ -1,5 +1,5 @@ /* - * Copyright © 2022 Soren Stoutner . + * Copyright 2022-2023 Soren Stoutner . * * This file is part of Privacy Browser PC . * @@ -219,13 +219,13 @@ void DomainSettingsDialog::apply() const QModelIndex currentIndex = domainsListViewPointer->currentIndex(); // Get the ID of the current index row. - QVariant currentId = currentIndex.siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabase::_ID)).data(); + QVariant currentId = currentIndex.siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabase::ID)).data(); // Submit all pending changes. domainsTableModelPointer->submitAll(); // Find the new index for the selected id. The `1` keeps searching after the first match. - QModelIndexList newIndexList = domainsTableModelPointer->match(currentIndex.siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabase::_ID)), Qt::DisplayRole, currentId, + QModelIndexList newIndexList = domainsTableModelPointer->match(currentIndex.siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabase::ID)), Qt::DisplayRole, currentId, 1, Qt::MatchWrap); // Select the new index. @@ -389,10 +389,10 @@ void DomainSettingsDialog::populateDomStorageLabel() const break; } - case (DomainsDatabase::DISABLED): + case (DomainsDatabase::ENABLED): { - // Set the disabled text in bold. - domStorageLabelPointer->setText(i18nc("Domain settings DOM storage label. The tags should be retained.", "DOM storage disabled")); + // Set the enabled text in bold. + domStorageLabelPointer->setText(i18nc("Domain settings DOM storage label. The tags should be retained.", "DOM storage enabled")); // Set the palette. domStorageWidgetPointer->setPalette(highlightedPalette); @@ -400,10 +400,10 @@ void DomainSettingsDialog::populateDomStorageLabel() const break; } - case (DomainsDatabase::ENABLED): + case (DomainsDatabase::DISABLED): { - // Set the enabled text in bold. - domStorageLabelPointer->setText(i18nc("Domain settings DOM storage label. The tags should be retained.", "DOM storage enabled")); + // Set the disabled text in bold. + domStorageLabelPointer->setText(i18nc("Domain settings DOM storage label. The tags should be retained.", "DOM storage disabled")); // Set the palette. domStorageWidgetPointer->setPalette(highlightedPalette); @@ -432,10 +432,10 @@ void DomainSettingsDialog::populateJavaScriptLabel() const break; } - case (DomainsDatabase::DISABLED): + case (DomainsDatabase::ENABLED): { - // Set the disabled text in bold. - javaScriptLabelPointer->setText(i18nc("Domain settings JavaScript label. The tags should be retained.", "JavaScript disabled")); + // Set the enabled text in bold. + javaScriptLabelPointer->setText(i18nc("Domain settings JavaScript label. The tags should be retained.", "JavaScript enabled")); // Set the palette. javaScriptWidgetPointer->setPalette(highlightedPalette); @@ -443,10 +443,10 @@ void DomainSettingsDialog::populateJavaScriptLabel() const break; } - case (DomainsDatabase::ENABLED): + case (DomainsDatabase::DISABLED): { - // Set the enabled text in bold. - javaScriptLabelPointer->setText(i18nc("Domain settings JavaScript label. The tags should be retained.", "JavaScript enabled")); + // Set the disabled text in bold. + javaScriptLabelPointer->setText(i18nc("Domain settings JavaScript label. The tags should be retained.", "JavaScript disabled")); // Set the palette. javaScriptWidgetPointer->setPalette(highlightedPalette); @@ -475,10 +475,10 @@ void DomainSettingsDialog::populateLocalStorageLabel() const break; } - case (DomainsDatabase::DISABLED): + case (DomainsDatabase::ENABLED): { - // Set the disabled text in bold. - localStorageLabelPointer->setText(i18nc("Domain settings local storage label. The tags should be retained.", "Local storage disabled")); + // Set the enabled text in bold. + localStorageLabelPointer->setText(i18nc("Domain settings local storage label. The tabs should be retained.", "Local storage enabled")); // Set the palette. localStorageWidgetPointer->setPalette(highlightedPalette); @@ -486,10 +486,10 @@ void DomainSettingsDialog::populateLocalStorageLabel() const break; } - case (DomainsDatabase::ENABLED): + case (DomainsDatabase::DISABLED): { - // Set the enabled text in bold. - localStorageLabelPointer->setText(i18nc("Domain settings local storage label. The tabs should be retained.", "Local storage enabled")); + // Set the disabled text in bold. + localStorageLabelPointer->setText(i18nc("Domain settings local storage label. The tags should be retained.", "Local storage disabled")); // Set the palette. localStorageWidgetPointer->setPalette(highlightedPalette); diff --git a/src/dialogs/DurableCookiesDialog.cpp b/src/dialogs/DurableCookiesDialog.cpp index d998c20..abc21e9 100644 --- a/src/dialogs/DurableCookiesDialog.cpp +++ b/src/dialogs/DurableCookiesDialog.cpp @@ -1,5 +1,5 @@ /* - * Copyright © 2022 Soren Stoutner . + * Copyright 2022-2023 Soren Stoutner . * * This file is part of Privacy Browser PC . * @@ -150,7 +150,7 @@ void DurableCookiesDialog::beforeUpdate(int row, QSqlRecord &sqlRecord) const if (sqlRecord.isGenerated(CookiesDatabase::DOMAIN) || sqlRecord.isGenerated(CookiesDatabase::NAME) || sqlRecord.isGenerated(CookiesDatabase::PATH)) { // Get the ID of the cookie - int id = sqlRecord.value(CookiesDatabase::_ID).toInt(); + int id = sqlRecord.value(CookiesDatabase::ID).toInt(); // Get the cookie. QNetworkCookie *cookiePointer = CookiesDatabase::getCookieById(id); diff --git a/src/uis/DomainSettingsDialog.ui b/src/uis/DomainSettingsDialog.ui index d498a10..c432b7c 100644 --- a/src/uis/DomainSettingsDialog.ui +++ b/src/uis/DomainSettingsDialog.ui @@ -155,13 +155,13 @@ - JavaScript disabled + JavaScript enabled - JavaScript enabled + JavaScript disabled @@ -221,13 +221,13 @@ - Local storage disabled + Local storage enabled - Local storage enabled + Local storage disabled @@ -287,13 +287,13 @@ - DOM storage disabled + DOM storage enabled - DOM storage enabled + DOM storage disabled diff --git a/src/widgets/PrivacyWebEngineView.cpp b/src/widgets/PrivacyWebEngineView.cpp index 96a0da5..37c26bf 100644 --- a/src/widgets/PrivacyWebEngineView.cpp +++ b/src/widgets/PrivacyWebEngineView.cpp @@ -86,14 +86,11 @@ void PrivacyWebEngineView::applyDomainSettings(const QString &hostname, const bo // Check if the hostname has domain settings. if (domainQuery.isValid()) // The hostname has domain settings. { - // Get the domain record. - QSqlRecord domainRecord = domainQuery.record(); - // Store the domain settings name. - domainSettingsName = domainRecord.field(DomainsDatabase::DOMAIN_NAME).value().toString(); + domainSettingsName = domainQuery.value(DomainsDatabase::DOMAIN_NAME).toString(); // Set the JavaScript status. - switch (domainRecord.field(DomainsDatabase::JAVASCRIPT).value().toInt()) + switch (domainQuery.value(DomainsDatabase::JAVASCRIPT).toInt()) { // Set the default JavaScript status. case (DomainsDatabase::SYSTEM_DEFAULT): @@ -103,25 +100,25 @@ void PrivacyWebEngineView::applyDomainSettings(const QString &hostname, const bo break; } - // Disable JavaScript. - case (DomainsDatabase::DISABLED): + // Enable JavaScript. + case (DomainsDatabase::ENABLED): { - webEngineSettingsPointer->setAttribute(QWebEngineSettings::JavascriptEnabled, false); + webEngineSettingsPointer->setAttribute(QWebEngineSettings::JavascriptEnabled, true); break; } - // Enable JavaScript. - case (DomainsDatabase::ENABLED): + // Disable JavaScript. + case (DomainsDatabase::DISABLED): { - webEngineSettingsPointer->setAttribute(QWebEngineSettings::JavascriptEnabled, true); + webEngineSettingsPointer->setAttribute(QWebEngineSettings::JavascriptEnabled, false); break; } } // Set the local storage status. - switch (domainRecord.field(DomainsDatabase::LOCAL_STORAGE).value().toInt()) + switch (domainQuery.value(DomainsDatabase::LOCAL_STORAGE).toInt()) { // Set the default local storage status. case (DomainsDatabase::SYSTEM_DEFAULT): @@ -131,25 +128,25 @@ void PrivacyWebEngineView::applyDomainSettings(const QString &hostname, const bo break; } - // Disable local storage. - case (DomainsDatabase::DISABLED): + // Enable local storage. + case (DomainsDatabase::ENABLED): { - localStorageEnabled = false; + localStorageEnabled = true; break; } - // Enable local storage. - case (DomainsDatabase::ENABLED): + // Disable local storage. + case (DomainsDatabase::DISABLED): { - localStorageEnabled = true; + localStorageEnabled = false; break; } } // Set the DOM storage status. - switch (domainRecord.field(DomainsDatabase::DOM_STORAGE).value().toInt()) + switch (domainQuery.value(DomainsDatabase::DOM_STORAGE).toInt()) { // Set the default DOM storage status. QWebEngineSettings confusingly calls this local storage. case (DomainsDatabase::SYSTEM_DEFAULT): @@ -159,31 +156,31 @@ void PrivacyWebEngineView::applyDomainSettings(const QString &hostname, const bo break; } - // Disable DOM storage. QWebEngineSettings confusingly calls this local storage. - case (DomainsDatabase::DISABLED): + // Enable DOM storage. QWebEngineSettings confusingly calls this local storage. + case (DomainsDatabase::ENABLED): { - webEngineSettingsPointer->setAttribute(QWebEngineSettings::LocalStorageEnabled, false); + webEngineSettingsPointer->setAttribute(QWebEngineSettings::LocalStorageEnabled, true); break; } - // Enable DOM storage. QWebEngineSettings confusingly calls this local storage. - case (DomainsDatabase::ENABLED): + // Disable DOM storage. QWebEngineSettings confusingly calls this local storage. + case (DomainsDatabase::DISABLED): { - webEngineSettingsPointer->setAttribute(QWebEngineSettings::LocalStorageEnabled, true); + webEngineSettingsPointer->setAttribute(QWebEngineSettings::LocalStorageEnabled, false); break; } } // Set the user agent. - webEngineProfilePointer->setHttpUserAgent(UserAgentHelper::getResultingDomainSettingsUserAgent(domainRecord.field(DomainsDatabase::USER_AGENT).value().toString())); + webEngineProfilePointer->setHttpUserAgent(UserAgentHelper::getResultingDomainSettingsUserAgent(domainQuery.value(DomainsDatabase::USER_AGENT).toString())); // Check if a custom zoom factor is set. - if (domainRecord.field(DomainsDatabase::ZOOM_FACTOR).value().toInt()) + if (domainQuery.value(DomainsDatabase::ZOOM_FACTOR).toInt()) { // Store the current zoom factor. - setZoomFactor(domainRecord.field(DomainsDatabase::CUSTOM_ZOOM_FACTOR).value().toDouble()); + setZoomFactor(domainQuery.value(DomainsDatabase::CUSTOM_ZOOM_FACTOR).toDouble()); } else { -- 2.45.2