From 03d1e9e85a1fc8c7f561d0c7d9492ef1bee292db Mon Sep 17 00:00:00 2001 From: Soren Stoutner Date: Wed, 10 Jan 2024 14:55:25 -0700 Subject: [PATCH] Create new domain settings with the currently applied settings. https://redmine.stoutner.com/issues/1101 --- COPYING | 2 +- doc/index.docbook | 102 +++++++++++++++++++++--- src/databases/DomainsDatabase.cpp | 45 ++++++++++- src/databases/DomainsDatabase.h | 5 +- src/dialogs/DomainSettingsDialog.cpp | 79 +++++++------------ src/dialogs/DomainSettingsDialog.h | 3 +- src/helpers/UserAgentHelper.cpp | 16 +++- src/helpers/UserAgentHelper.h | 5 +- src/main.cpp | 4 +- src/widgets/TabWidget.cpp | 12 ++- src/widgets/TabWidget.h | 9 ++- src/windows/BrowserWindow.cpp | 111 ++++++++++++++++++--------- src/windows/BrowserWindow.h | 11 +-- 13 files changed, 282 insertions(+), 122 deletions(-) diff --git a/COPYING b/COPYING index 6e02237..7cf0ecb 100644 --- a/COPYING +++ b/COPYING @@ -1,4 +1,4 @@ -Privacy Browser PC copyright 2016-2017,2021-2023 Soren Stoutner . +Privacy Browser PC copyright 2016-2017,2021-2024 Soren Stoutner . This file is part of Privacy Browser PC . diff --git a/doc/index.docbook b/doc/index.docbook index d061163..27ee1fc 100644 --- a/doc/index.docbook +++ b/doc/index.docbook @@ -1,7 +1,7 @@ - 2023-10-12 + 2024-01-06 &privacybrowser; version 0.5 @@ -394,6 +394,27 @@ + + + + + + &Ctrl;A + + + File + + Save Archive + + + + + + Save the webpage as an MHT (MIME encapsulation of aggregate HTML documents) archive. + + + + @@ -535,6 +556,27 @@ View + + + + + + &Ctrl;0 + + + View + + Zoom Default + + + + + + Return to either the app or the domain default zoom factor. + + + + @@ -594,7 +636,7 @@ - Reload the website in the current tab. + Reload the website in the current tab. When Refresh is visible, is hidden. @@ -620,6 +662,27 @@ + + + + + + &Ctrl;&Shift;X + + + View + + Stop + + + + + + Stop the loading of the website in the current tab. When Stop is visible, is hidden. + + + + @@ -663,6 +726,27 @@ + + + + + + F12 + + + View + + Developer Tools + + + + + + Display the developer tools, which are used to debug websites. + + + + @@ -1242,7 +1326,7 @@ - + @@ -1263,7 +1347,7 @@ - + @@ -1284,7 +1368,7 @@ - + @@ -1305,7 +1389,7 @@ - + @@ -1762,7 +1846,7 @@ Credits and License - Privacy Browser PC copyright 2016-2017,2021-2023 Soren Stoutner soren@stoutner.com. + Privacy Browser PC copyright 2016-2017,2021-2024 Soren Stoutner soren@stoutner.com. diff --git a/src/databases/DomainsDatabase.cpp b/src/databases/DomainsDatabase.cpp index 0553543..d52647c 100644 --- a/src/databases/DomainsDatabase.cpp +++ b/src/databases/DomainsDatabase.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2022-2023 Soren Stoutner . + * Copyright 2022-2024 Soren Stoutner . * * This file is part of Privacy Browser PC . * @@ -19,6 +19,7 @@ // Application headers. #include "DomainsDatabase.h" +#include "Settings.h" #include "helpers/UserAgentHelper.h" // Define the private static schema constants. @@ -266,11 +267,51 @@ void DomainsDatabase::addDatabase() } else // Opening the database failed. { - // Write the last database error message to the debug output. + // Write the last database error message to the debug output.Settings::zoom qDebug().noquote().nospace() << "Error opening database: " << domainsDatabase.lastError(); } }; +void DomainsDatabase::addDomain(const QString &domainName) +{ + // Add the domain: + addDomain(domainName, SYSTEM_DEFAULT, SYSTEM_DEFAULT, SYSTEM_DEFAULT, UserAgentHelper::SYSTEM_DEFAULT_DATABASE, SYSTEM_DEFAULT, Settings::zoomFactor()); +} + +void DomainsDatabase::addDomain(const QString &domainName, const int javaScriptInt, const int localStorageInt, const int domStorageInt, const QString &userAgentDatabaseString, + const int zoomFactorInt, const double currentZoomFactorDouble) +{ + // Get a handle for the domains database. + QSqlDatabase domainsDatabase = QSqlDatabase::database(CONNECTION_NAME); + + // Instantiate an add domain settings query. + QSqlQuery addDomainSettingsQuery(domainsDatabase); + + // Prepare the query. + addDomainSettingsQuery.prepare("INSERT INTO " + DomainsDatabase::DOMAINS_TABLE + " (" + + DomainsDatabase::DOMAIN_NAME + ", " + + DomainsDatabase::JAVASCRIPT + ", " + + DomainsDatabase::LOCAL_STORAGE + ", " + + DomainsDatabase::DOM_STORAGE + ", " + + DomainsDatabase::USER_AGENT + ", " + + DomainsDatabase::ZOOM_FACTOR + ", " + + DomainsDatabase::CUSTOM_ZOOM_FACTOR + ") " + + "VALUES (:domain_name, :javascript, :local_storage, :dom_storage, :user_agent, :zoom_factor, :custom_zoom_factor)" + ); + + // Bind the query values. + addDomainSettingsQuery.bindValue(":domain_name", domainName); + addDomainSettingsQuery.bindValue(":javascript", javaScriptInt); + addDomainSettingsQuery.bindValue(":local_storage", localStorageInt); + addDomainSettingsQuery.bindValue(":dom_storage", domStorageInt); + addDomainSettingsQuery.bindValue(":user_agent", userAgentDatabaseString); + addDomainSettingsQuery.bindValue(":zoom_factor", zoomFactorInt); + addDomainSettingsQuery.bindValue(":custom_zoom_factor", currentZoomFactorDouble); + + // Execute the query. + addDomainSettingsQuery.exec(); +} + QSqlQuery DomainsDatabase::getDomainQuery(const QString &hostname) { // Get a handle for the domains database. diff --git a/src/databases/DomainsDatabase.h b/src/databases/DomainsDatabase.h index cb7e09d..1e58d2e 100644 --- a/src/databases/DomainsDatabase.h +++ b/src/databases/DomainsDatabase.h @@ -1,5 +1,5 @@ /* - * Copyright 2022-2023 Soren Stoutner . + * Copyright 2022-2024 Soren Stoutner . * * This file is part of Privacy Browser PC . * @@ -31,6 +31,9 @@ public: // The public functions. static void addDatabase(); + static void addDomain(const QString &domainName); + static void addDomain(const QString &domainName, const int javaScriptInt, const int localStorageInt, const int domStorageInt, const QString &userAgentDatabaseString, const int zoomFactorInt, + const double currentZoomFactorDouble); static QSqlQuery getDomainQuery(const QString &hostname); // The public int constants. diff --git a/src/dialogs/DomainSettingsDialog.cpp b/src/dialogs/DomainSettingsDialog.cpp index 82f0f64..59d7bdb 100644 --- a/src/dialogs/DomainSettingsDialog.cpp +++ b/src/dialogs/DomainSettingsDialog.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2022-2023 Soren Stoutner . + * Copyright 2022-2024 Soren Stoutner . * * This file is part of Privacy Browser PC . * @@ -31,8 +31,7 @@ // Define the public static int constants. const int DomainSettingsDialog::SHOW_ALL_DOMAINS = 0; -const int DomainSettingsDialog::ADD_DOMAIN = 1; -const int DomainSettingsDialog::EDIT_DOMAIN = 2; +const int DomainSettingsDialog::EDIT_DOMAIN = 1; // Construct the class. DomainSettingsDialog::DomainSettingsDialog(const int &startType, const QString &domainName) : QDialog(nullptr) @@ -133,17 +132,6 @@ DomainSettingsDialog::DomainSettingsDialog(const int &startType, const QString & break; } - case ADD_DOMAIN: - { - // Add the new domain. - addDomain(domainName); - - // Emit the domain settings updated signal after 100 milliseconds. This is necessary because the browser window takes time to process the connect command to receive the signal. - QTimer::singleShot(100, [this] () { emit domainSettingsUpdated();}); - - break; - } - case EDIT_DOMAIN: { // Find the index for the new domain. `1` returns the first match. @@ -184,43 +172,6 @@ DomainSettingsDialog::DomainSettingsDialog(const int &startType, const QString & updateUi(); } -void DomainSettingsDialog::addDomain(const QString &domainName) const -{ - // Create a new domain record. - QSqlRecord newDomainRecord = QSqlDatabase::database(DomainsDatabase::CONNECTION_NAME).record(DomainsDatabase::DOMAINS_TABLE); - - // Set the values for the new domain. - newDomainRecord.setValue(domainsTableModelPointer->fieldIndex(DomainsDatabase::DOMAIN_NAME), domainName); - newDomainRecord.setValue(domainsTableModelPointer->fieldIndex(DomainsDatabase::JAVASCRIPT), DomainsDatabase::SYSTEM_DEFAULT); - newDomainRecord.setValue(domainsTableModelPointer->fieldIndex(DomainsDatabase::LOCAL_STORAGE), DomainsDatabase::SYSTEM_DEFAULT); - newDomainRecord.setValue(domainsTableModelPointer->fieldIndex(DomainsDatabase::DOM_STORAGE), DomainsDatabase::SYSTEM_DEFAULT); - newDomainRecord.setValue(domainsTableModelPointer->fieldIndex(DomainsDatabase::USER_AGENT), UserAgentHelper::SYSTEM_DEFAULT_DATABASE); - newDomainRecord.setValue(domainsTableModelPointer->fieldIndex(DomainsDatabase::ZOOM_FACTOR), DomainsDatabase::SYSTEM_DEFAULT); - newDomainRecord.setValue(domainsTableModelPointer->fieldIndex(DomainsDatabase::CUSTOM_ZOOM_FACTOR), 1.0); - - // Insert the new domain. `-1` appends it to the end. - domainsTableModelPointer->insertRecord(-1, newDomainRecord); - - // Submit all pending changes. - domainsTableModelPointer->submitAll(); - - // Find the index for the new domain. `-1` allows for multiple entries to be returned. - QModelIndexList newDomainIndex = domainsTableModelPointer->match(domainsTableModelPointer->index(0, domainsTableModelPointer->fieldIndex(DomainsDatabase::DOMAIN_NAME)), - Qt::DisplayRole, domainName, -1, Qt::MatchWrap); - - // Move to the new domain. If there are multiple domains with the same name, the new one should be the last in the list. - domainsListViewPointer->setCurrentIndex(newDomainIndex[newDomainIndex.size() - 1]); - - // Populate the domain settings. - domainSelected(domainsSelectionModelPointer->currentIndex()); - - // Update the UI. - updateUi(); - - // Emit the domain settings updated signal. - emit domainSettingsUpdated(); -} - void DomainSettingsDialog::apply() const { // Get the current index. @@ -560,7 +511,31 @@ void DomainSettingsDialog::showAddMessageBox() QLineEdit::Normal, QString(), &okClicked); // Add the new domain if the user clicked OK. - if (okClicked) addDomain(newDomainName); + if (okClicked) + { + // Add the new domain. + DomainsDatabase::addDomain(newDomainName); + + // Submit all pending changes. This reloads the model from the database, getting the new domain added above. + domainsTableModelPointer->submitAll(); + + + // Find the index for the new domain. `-1` allows for multiple entries to be returned. + QModelIndexList newDomainIndex = domainsTableModelPointer->match(domainsTableModelPointer->index(0, domainsTableModelPointer->fieldIndex(DomainsDatabase::DOMAIN_NAME)), + Qt::DisplayRole, newDomainName, -1, Qt::MatchWrap); + + // Move to the new domain. If there are multiple domains with the same name, the new one should be the last in the list. + domainsListViewPointer->setCurrentIndex(newDomainIndex[newDomainIndex.size() - 1]); + + // Populate the domain settings. + domainSelected(domainsSelectionModelPointer->currentIndex()); + + // Update the UI. + updateUi(); + + // Emit the domain settings updated signal. + emit domainSettingsUpdated(); + } } void DomainSettingsDialog::showDeleteMessageBox() const diff --git a/src/dialogs/DomainSettingsDialog.h b/src/dialogs/DomainSettingsDialog.h index 7163458..543c1bb 100644 --- a/src/dialogs/DomainSettingsDialog.h +++ b/src/dialogs/DomainSettingsDialog.h @@ -1,5 +1,5 @@ /* - * Copyright © 2022 Soren Stoutner . + * Copyright 2022,2024 Soren Stoutner . * * This file is part of Privacy Browser PC . * @@ -96,7 +96,6 @@ private: QComboBox *zoomFactorComboBoxPointer; // The private functions. - void addDomain(const QString &domainName) const; void populateDomStorageLabel() const; void populateJavaScriptLabel() const; void populateLocalStorageLabel() const; diff --git a/src/helpers/UserAgentHelper.cpp b/src/helpers/UserAgentHelper.cpp index 1033c93..de58905 100644 --- a/src/helpers/UserAgentHelper.cpp +++ b/src/helpers/UserAgentHelper.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2022-2023 Soren Stoutner . + * Copyright 2022-2024 Soren Stoutner . * * This file is part of Privacy Browser PC . * @@ -74,6 +74,20 @@ QString UserAgentHelper::getDatabaseUserAgentNameFromTranslatedName(const QStrin else return translatedUserAgentName; // Return the custom user agent. } +QString UserAgentHelper::getDatabaseUserAgentNameFromUserAgent(const QString &userAgent) +{ + // Return the database user agent name. + if (userAgent == PRIVACY_BROWSER_USER_AGENT) return PRIVACY_BROWSER_DATABASE; // Privacy Browser. + else if (userAgent == TabWidget::webEngineDefaultUserAgent) return WEB_ENGINE_DEFAULT_DATABASE; // WebEngine default. + else if (userAgent == FIREFOX_LINUX_USER_AGENT) return FIREFOX_LINUX_DATABASE; // Firefox Linux. + else if (userAgent == CHROMIUM_LINUX_USER_AGENT) return CHROMIUM_LINUX_DATABASE; // Chromium Linux. + else if (userAgent == FIREFOX_WINDOWS_USER_AGENT) return FIREFOX_WINDOWS_DATABASE; // Firefox Windows. + else if (userAgent == CHROME_WINDOWS_USER_AGENT) return CHROME_WINDOWS_DATABASE; // Chrome Windows. + else if (userAgent == EDGE_WINDOWS_USER_AGENT) return EDGE_WINDOWS_DATABASE; // Edge Windows. + else if (userAgent == SAFARI_MACOS_USER_AGENT) return SAFARI_MACOS_DATABASE; // Safari macOS. + else return userAgent; // Return the custom user agent. +} + int UserAgentHelper::getDomainSettingsUserAgentIndex(const QString &userAgentName) { // Return the domain settings user agent index. diff --git a/src/helpers/UserAgentHelper.h b/src/helpers/UserAgentHelper.h index aee7bc9..60f9902 100644 --- a/src/helpers/UserAgentHelper.h +++ b/src/helpers/UserAgentHelper.h @@ -1,5 +1,5 @@ /* - * Copyright © 2022 Soren Stoutner . + * Copyright 2022,2024 Soren Stoutner . * * This file is part of Privacy Browser PC . * @@ -51,6 +51,7 @@ public: static const QString WEB_ENGINE_DEFAULT_DATABASE; // The public static functions. + static QString getDatabaseUserAgentNameFromUserAgent(const QString &userAgent); static int getDomainSettingsUserAgentIndex(const QString &userAgentName); static QString getUserAgentFromDatabaseName(const QString &userAgentDatabaseName); static QString getResultingDomainSettingsUserAgent(const QString &rawUserAgent); @@ -66,7 +67,7 @@ public: QString EDGE_WINDOWS_TRANSLATED; QString SAFARI_MACOS_TRANSLATED; - // The public functions. + // The public functions. Anything that accesses the translated user names must use an instantiated copy of the class. QString getDatabaseUserAgentNameFromTranslatedName(const QString &translatedUserAgentName); QString getUserAgentFromTranslatedName(const QString &userAgentTranslatedName); QString getTranslatedUserAgentNameFromDatabaseName(const QString &userAgentName); diff --git a/src/main.cpp b/src/main.cpp index 3cedc08..0c499f2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2022-2023 Soren Stoutner . + * Copyright 2022-2024 Soren Stoutner . * * This file is part of Privacy Browser PC . * @@ -54,7 +54,7 @@ int main(int argc, char *argv[]) // Populate additional about data info. aboutData.setBugAddress("https://redmine.stoutner.com/projects/privacy-browser-pc/issues"); - aboutData.setCopyrightStatement(i18nc("Copyright", "Copyright 2016-2017,2021-2023 Soren Stoutner ")); + aboutData.setCopyrightStatement(i18nc("Copyright", "Copyright 2016-2017,2021-2024 Soren Stoutner ")); aboutData.setDesktopFileName(QStringLiteral("com.stoutner.privacybrowser")); aboutData.setHomepage(QStringLiteral("https://www.stoutner.com/privacy-browser-pc/")); //aboutData.setLicense(KAboutLicense::GPL_V3, KAboutLicense::OrLaterVersions); diff --git a/src/widgets/TabWidget.cpp b/src/widgets/TabWidget.cpp index 4f4a635..58ccfc6 100644 --- a/src/widgets/TabWidget.cpp +++ b/src/widgets/TabWidget.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2022-2023 Soren Stoutner . + * Copyright 2022-2024 Soren Stoutner . * * This file is part of Privacy Browser PC . * @@ -573,10 +573,10 @@ void TabWidget::applyOnTheFlyUserAgent(QAction *userAgentActionPointer) const currentPrivacyWebEngineViewPointer->reload(); } -void TabWidget::applyOnTheFlyZoomFactor(const double &zoomFactor) const +void TabWidget::applyOnTheFlyZoomFactor(const double zoomFactorDouble) const { // Set the zoom factor. - currentPrivacyWebEngineViewPointer->setZoomFactor(zoomFactor); + currentPrivacyWebEngineViewPointer->setZoomFactor(zoomFactorDouble); } void TabWidget::applySpellCheckLanguages() const @@ -737,6 +737,12 @@ QString TabWidget::getCurrentTabUrl() const return currentPrivacyWebEngineViewPointer->url().toString(); } +QString TabWidget::getCurrentUserAgent() const +{ + // Return the current WebEngine user agent. + return currentWebEngineProfilePointer->httpUserAgent(); +} + QString& TabWidget::getDomainSettingsName() const { // Return the domain settings name. diff --git a/src/widgets/TabWidget.h b/src/widgets/TabWidget.h index 06676d6..7dbb581 100644 --- a/src/widgets/TabWidget.h +++ b/src/widgets/TabWidget.h @@ -1,5 +1,5 @@ /* - * Copyright 2022-2023 Soren Stoutner . + * Copyright 2022-2024 Soren Stoutner . * * This file is part of Privacy Browser PC . * @@ -51,7 +51,7 @@ public: ~TabWidget(); // The public functions. - void applyOnTheFlyZoomFactor(const double &zoomFactor) const; + void applyOnTheFlyZoomFactor(const double zoomFactorDouble) const; void applySpellCheckLanguages() const; PrivacyWebEngineView* loadBlankInitialWebsite(); void loadInitialWebsite(); @@ -60,6 +60,7 @@ public: QIcon getCurrentTabFavoritIcon() const; QString getCurrentTabTitle() const; QString getCurrentTabUrl() const; + QString getCurrentUserAgent() const; QString& getDomainSettingsName() const; void setTabBarVisible(const bool visible) const; void toggleDeveloperTools(const bool enabled) const; @@ -82,7 +83,7 @@ signals: void showProgressBar(const int &progress) const; void updateBackAction(const bool &isEnabled) const; void updateCookiesAction(const int numberOfCookies) const; - void updateDefaultZoomFactor(const double newDefaultZoomFactor) const; + void updateDefaultZoomFactor(const double newDefaultZoomFactorDouble) const; void updateDeveloperToolsAction(const bool &isEnabled) const; void updateDomStorageAction(const bool &isEnabled) const; void updateDomainSettingsIndicator(const bool status) const; @@ -95,7 +96,7 @@ signals: void updateUrlLineEdit(const QUrl &newUrl) const; void updateUserAgentActions(const QString &userAgent, const bool &updateCustomUserAgentStatus) const; void updateWindowTitle(const QString &title) const; - void updateZoomActions(const double &zoomFactor) const; + void updateZoomActions(const double zoomFactorDouble) const; public Q_SLOTS: // The public slots. diff --git a/src/windows/BrowserWindow.cpp b/src/windows/BrowserWindow.cpp index 1513d1a..13e3c51 100644 --- a/src/windows/BrowserWindow.cpp +++ b/src/windows/BrowserWindow.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2022-2023 Soren Stoutner . + * Copyright 2022-2024 Soren Stoutner . * * This file is part of Privacy Browser PC . * @@ -24,6 +24,7 @@ #include "ui_SettingsPrivacy.h" #include "ui_SettingsSpellCheck.h" #include "databases/BookmarksDatabase.h" +#include "databases/DomainsDatabase.h" #include "dialogs/AddBookmarkDialog.h" #include "dialogs/AddFolderDialog.h" #include "dialogs/BookmarksDialog.h" @@ -773,24 +774,47 @@ void BrowserWindow::addOrEditDomainSettings() const // Remove the focus from the URL line edit. urlLineEditPointer->clearFocus(); - // Create the domain settings dialog pointer. - DomainSettingsDialog *domainSettingsDialogPointer; - // Get the current domain settings name. QString ¤tDomainSettingsName = tabWidgetPointer->getDomainSettingsName(); // Run the commands according to the current domain settings status. if (currentDomainSettingsName == QStringLiteral("")) // Domain settings are not currently applied. { - // Instruct the domain settings dialog to add a new domain. - domainSettingsDialogPointer = new DomainSettingsDialog(DomainSettingsDialog::ADD_DOMAIN, currentUrl.host()); - } - else // Domain settings are currently applied. - { - // Instruct the domain settings dialog to edit the current domain. - domainSettingsDialogPointer = new DomainSettingsDialog(DomainSettingsDialog::EDIT_DOMAIN, currentDomainSettingsName); + // Get the current settings status. + int javaScriptInt = calculateSettingsInt(javaScriptEnabled, Settings::javaScriptEnabled()); + int localStorageInt = calculateSettingsInt(localStorageActionPointer->isChecked(), Settings::localStorageEnabled()); + int domStorageInt = calculateSettingsInt(domStorageActionPointer->isChecked(), Settings::domStorageEnabled()); + + // Get the current user agent string. + QString currentUserAgentString = tabWidgetPointer->getCurrentUserAgent(); + + // Get the current user agent database string. + QString currentUserAgentDatabaseString = UserAgentHelper::getDatabaseUserAgentNameFromUserAgent(currentUserAgentString); + + // Initialize the user agent database string. + QString userAgentDatabaseString = UserAgentHelper::SYSTEM_DEFAULT_DATABASE; + + // Replace the user agent database string if the current user agent is not the default. + if (currentUserAgentDatabaseString != Settings::userAgent()) + userAgentDatabaseString = currentUserAgentDatabaseString; + + // Initialize the zoom factor variables. + int zoomFactorInt = DomainsDatabase::SYSTEM_DEFAULT; + + // Use a custom zoom factor if currently applied. Doubles cannot be reliably compared using `==`, so a mathematical workaround is used. + if (abs(currentZoomFactorDouble - defaultZoomFactorDouble ) > 0.01) + zoomFactorInt = DomainsDatabase::CUSTOM; + + // Add the domain. + DomainsDatabase::addDomain(currentUrl.host(), javaScriptInt, localStorageInt, domStorageInt, userAgentDatabaseString, zoomFactorInt, currentZoomFactorDouble); + + // Apply the domain settings. + tabWidgetPointer->applyDomainSettingsAndReload(); } + // Create the domain settings dialog pointer. + DomainSettingsDialog *domainSettingsDialogPointer = new DomainSettingsDialog(DomainSettingsDialog::EDIT_DOMAIN, currentDomainSettingsName); + // Reload the tabs when domain settings are updated. connect(domainSettingsDialogPointer, SIGNAL(domainSettingsUpdated()), tabWidgetPointer, SLOT(applyDomainSettingsAndReload())); @@ -807,6 +831,17 @@ void BrowserWindow::back() const tabWidgetPointer->back(); } +int BrowserWindow::calculateSettingsInt(const bool settingCurrentlyEnabled, const bool settingEnabledByDefault) const +{ + // Return the int that matches the current state. + if (settingCurrentlyEnabled == settingEnabledByDefault) // The current system default is used. + return DomainsDatabase::SYSTEM_DEFAULT; + else if (settingCurrentlyEnabled) // The setting is enabled, which is different from the system default. + return DomainsDatabase::ENABLED; + else // The setting is disabled, which is different from the system default. + return DomainsDatabase::DISABLED; +} + void BrowserWindow::clearUrlLineEditFocus() const { // Remove the focus from the URL line edit. @@ -816,17 +851,17 @@ void BrowserWindow::clearUrlLineEditFocus() const void BrowserWindow::decrementZoom() { // Update the current zoom factor. - currentZoomFactor = currentZoomFactor - 0.25; + currentZoomFactorDouble = currentZoomFactorDouble - 0.25; // Check to make sure the zoom factor is in the valid range (0.25 to 5.00). - if (currentZoomFactor < 0.25) - currentZoomFactor = 0.25; + if (currentZoomFactorDouble < 0.25) + currentZoomFactorDouble = 0.25; // Set the new zoom factor. - tabWidgetPointer->applyOnTheFlyZoomFactor(currentZoomFactor); + tabWidgetPointer->applyOnTheFlyZoomFactor(currentZoomFactorDouble); // Update the on-the-fly action text. - updateZoomActions(currentZoomFactor); + updateZoomActions(currentZoomFactorDouble); } void BrowserWindow::editBookmarks() const @@ -951,18 +986,18 @@ void BrowserWindow::getZoomFactorFromUser() bool okClicked; // Display a dialog to get the new zoom factor from the user. Format the double to display two decimals and have a 0.25 step. - double newZoomFactor = QInputDialog::getDouble(this, i18nc("The on-the-fly zoom factor dialog title", "On-The-Fly Zoom Factor"), + double newZoomFactorDouble = QInputDialog::getDouble(this, i18nc("The on-the-fly zoom factor dialog title", "On-The-Fly Zoom Factor"), i18nc("The instruction text of the on-the-fly zoom factor dialog", "Enter a zoom factor between 0.25 and 5.00"), - currentZoomFactor, .025, 5.00, 2, &okClicked, Qt::WindowFlags(), 0.25); + currentZoomFactorDouble, .025, 5.00, 2, &okClicked, Qt::WindowFlags(), 0.25); // Update the zoom factor if the user clicked OK. if (okClicked) { // Set the new zoom factor. - tabWidgetPointer->applyOnTheFlyZoomFactor(newZoomFactor); + tabWidgetPointer->applyOnTheFlyZoomFactor(newZoomFactorDouble); // Update the on-the-fly action text. - updateZoomActions(newZoomFactor); + updateZoomActions(newZoomFactorDouble); } } @@ -1003,17 +1038,17 @@ void BrowserWindow::hideProgressBar() const void BrowserWindow::incrementZoom() { // Update the current zoom factor. - currentZoomFactor = currentZoomFactor + 0.25; + currentZoomFactorDouble = currentZoomFactorDouble + 0.25; // Check to make sure the zoom factor is in the valid range (0.25 to 5.00). - if (currentZoomFactor > 5.0) - currentZoomFactor = 5.0; + if (currentZoomFactorDouble > 5.0) + currentZoomFactorDouble = 5.0; // Set the new zoom factor. - tabWidgetPointer->applyOnTheFlyZoomFactor(currentZoomFactor); + tabWidgetPointer->applyOnTheFlyZoomFactor(currentZoomFactorDouble); // Update the on-the-fly action text. - updateZoomActions(currentZoomFactor); + updateZoomActions(currentZoomFactorDouble); } void BrowserWindow::loadUrlFromLineEdit(const QString &url) const @@ -1843,10 +1878,10 @@ void BrowserWindow::updateCookiesAction(const int numberOfCookies) const cookiesActionPointer->setText(i18nc("The Cookies action, which also displays the number of cookies", "Cookies - %1", numberOfCookies)); } -void BrowserWindow::updateDefaultZoomFactor(const double newDefaultZoomFactor) +void BrowserWindow::updateDefaultZoomFactor(const double newDefaultZoomFactorDouble) { // Store the new default zoom factor. - defaultZoomFactor = newDefaultZoomFactor; + defaultZoomFactorDouble = newDefaultZoomFactorDouble; } void BrowserWindow::updateDomStorageAction(const bool &isEnabled) const @@ -2244,35 +2279,35 @@ void BrowserWindow::updateWindowTitle(const QString &title) setWindowTitle(title); } -void BrowserWindow::updateZoomActions(const double &zoomFactor) +void BrowserWindow::updateZoomActions(const double zoomFactorDouble) { // Set the current zoom factor. - currentZoomFactor = zoomFactor; + currentZoomFactorDouble = zoomFactorDouble; // Set the status of the default zoom action. - zoomDefaultActionPointer->setEnabled(currentZoomFactor != defaultZoomFactor); + zoomDefaultActionPointer->setEnabled(currentZoomFactorDouble != defaultZoomFactorDouble); // Set the status of the zoom in action and button. - zoomInActionPointer->setEnabled(currentZoomFactor <= 4.99); - zoomPlusButtonPointer->setEnabled(currentZoomFactor <= 4.99); + zoomInActionPointer->setEnabled(currentZoomFactorDouble <= 4.99); + zoomPlusButtonPointer->setEnabled(currentZoomFactorDouble <= 4.99); // Set the status of the zoom out action and button. - zoomMinusButtonPointer->setEnabled(currentZoomFactor > 0.25); - zoomOutActionPointer->setEnabled(currentZoomFactor > 0.25); + zoomMinusButtonPointer->setEnabled(currentZoomFactorDouble > 0.25); + zoomOutActionPointer->setEnabled(currentZoomFactorDouble > 0.25); // Update the zoom factor action text, formatting the double with 2 decimal places. `0` specifies no extra field width. `'0'` sets the format to not use scientific notation. - zoomFactorActionPointer->setText(ki18nc("The zoom factor action", "Zoom Factor - %1").subs(zoomFactor, 0, '0', 2).toString()); + zoomFactorActionPointer->setText(ki18nc("The zoom factor action", "Zoom Factor - %1").subs(zoomFactorDouble, 0, '0', 2).toString()); // Update the status bar zoom factor label. - currentZoomButtonPointer->setText(ki18nc("The status bar zoom, which is just the formatted zoom factor", "%1").subs(zoomFactor, 0, '0', 2).toString()); + currentZoomButtonPointer->setText(ki18nc("The status bar zoom, which is just the formatted zoom factor", "%1").subs(zoomFactorDouble, 0, '0', 2).toString()); } void BrowserWindow::zoomDefault() { // Set the new zoom factor. - tabWidgetPointer->applyOnTheFlyZoomFactor(defaultZoomFactor); + tabWidgetPointer->applyOnTheFlyZoomFactor(defaultZoomFactorDouble); // Update the on-the-fly action text. - updateZoomActions(defaultZoomFactor); + updateZoomActions(defaultZoomFactorDouble); } diff --git a/src/windows/BrowserWindow.h b/src/windows/BrowserWindow.h index 143e35f..eedc250 100644 --- a/src/windows/BrowserWindow.h +++ b/src/windows/BrowserWindow.h @@ -1,5 +1,5 @@ /* - * Copyright 2022-2023 Soren Stoutner . + * Copyright 2022-2024 Soren Stoutner . * * This file is part of Privacy Browser PC . * @@ -93,7 +93,7 @@ private Q_SLOTS: void toggleViewSource() const; void toggleViewSourceInNewTab() const; void updateCookiesAction(const int numberOfCookies) const; - void updateDefaultZoomFactor(const double newDefaultZoomFactor); + void updateDefaultZoomFactor(const double newDefaultZoomFactorDouble); void updateDomStorageAction(const bool &isEnabled) const; void updateDomainSettingsIndicator(const bool status); void updateFindText(const QString &text, const bool findCaseSensitive) const; @@ -102,7 +102,7 @@ private Q_SLOTS: void updateLocalStorageAction(const bool &isEnabled); void updateSearchEngineActions(const QString &searchEngine, const bool &updateCustomSearchEngineStatus); void updateUserAgentActions(const QString &userAgent, const bool &updateCustomUserAgentStatus); - void updateZoomActions(const double &zoomFactor); + void updateZoomActions(const double zoomFactorDouble); void updateSearchEngineLabel(const QString &searchEngineString) const; void updateUrlLineEdit(const QUrl &newUrl); void updateUserAgentLabel(const QString &userAgentDatabaseName) const; @@ -127,10 +127,10 @@ private: QAction *cookiesActionPointer; QUrl currentUrl; QPushButton *currentZoomButtonPointer; - double currentZoomFactor; + double currentZoomFactorDouble; bool customSearchEngineEnabled; bool customUserAgentEnabled; - double defaultZoomFactor; + double defaultZoomFactorDouble; QAction *developerToolsActionPointer; QAction *domStorageActionPointer; QComboBox *downloadDirectoryComboBoxPointer; @@ -189,6 +189,7 @@ private: // The private functions. void addFinalBookmarkFolderMenuActions(QMenu *menuPointer, double folderId); + int calculateSettingsInt(const bool settingCurrentlyEnabled, const bool settingEnabledByDefault) const; void populateBookmarksMenuSubfolders(const double folderId, QMenu *menuPointer); void populateBookmarksToolBar(); void populateBookmarksToolBarSubfolders(const double folderId, QMenu *menuPointer); -- 2.43.0