]> gitweb.stoutner.com Git - PrivacyBrowserPC.git/commitdiff
Create new domain settings with the currently applied settings. https://redmine...
authorSoren Stoutner <soren@stoutner.com>
Wed, 10 Jan 2024 21:55:25 +0000 (14:55 -0700)
committerSoren Stoutner <soren@stoutner.com>
Wed, 10 Jan 2024 21:55:25 +0000 (14:55 -0700)
13 files changed:
COPYING
doc/index.docbook
src/databases/DomainsDatabase.cpp
src/databases/DomainsDatabase.h
src/dialogs/DomainSettingsDialog.cpp
src/dialogs/DomainSettingsDialog.h
src/helpers/UserAgentHelper.cpp
src/helpers/UserAgentHelper.h
src/main.cpp
src/widgets/TabWidget.cpp
src/widgets/TabWidget.h
src/windows/BrowserWindow.cpp
src/windows/BrowserWindow.h

diff --git a/COPYING b/COPYING
index 6e022374b6cb60f2f7d3966e4caba399999cc7a4..7cf0ecb902105a203c48a00dee37df42be93a594 100644 (file)
--- a/COPYING
+++ b/COPYING
@@ -1,4 +1,4 @@
-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>.
 
 This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-pc>.
 
index d0611633d73afac75515ad5b03f7461b589a40d4..27ee1fc310350518021857851bb41de99bcee7c6 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0" ?>
 
 <!--
-  Copyright 2023 Soren Stoutner <soren@stoutner.com>.
+  Copyright 2023-2024 Soren Stoutner <soren@stoutner.com>.
 
   This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-pc>.
 
@@ -36,7 +36,7 @@
         </authorgroup>
 
         <copyright>
-            <year>2016-2017, 2021-2023</year>
+            <year>2016-2017, 2021-2024</year>
             <holder>&Soren.Stoutner;</holder>
         </copyright>
 
@@ -44,7 +44,7 @@
         <legalnotice>&FDLNotice;</legalnotice>
 
         <!-- Last update. -->
-        <date>2023-10-12</date>
+        <date>2024-01-06</date>
 
         <!-- The version of Privacy Browser this documentation is written for. -->
         <releaseinfo>&privacybrowser; version 0.5</releaseinfo>
                         </listitem>
                     </varlistentry>
 
+                    <!-- Save Archive. -->
+                    <varlistentry id="file-save-archive">
+                        <term>
+                            <menuchoice>
+                                <shortcut>
+                                    <keycombo action="simul">&Ctrl;<keycap>A</keycap></keycombo>
+                                </shortcut>
+
+                                <guimenu>File</guimenu>
+
+                                <guimenuitem>Save Archive</guimenuitem>
+                            </menuchoice>
+                        </term>
+
+                        <listitem>
+                            <para>
+                                Save the webpage as an MHT (MIME encapsulation of aggregate HTML documents) archive.
+                            </para>
+                        </listitem>
+                    </varlistentry>
+
                     <!-- Print. -->
                     <varlistentry  id="file-print">
                         <term>
                 <title>View</title>
 
                 <variablelist>
+                    <!-- Zoom Default. -->
+                    <varlistentry id="zoom-default">
+                        <term>
+                            <menuchoice>
+                                <shortcut>
+                                    <keycombo action="simul">&Ctrl;<keycap>0</keycap></keycombo>
+                                </shortcut>
+
+                                <guimenu>View</guimenu>
+
+                                <guimenuitem>Zoom Default</guimenuitem>
+                            </menuchoice>
+                        </term>
+
+                        <listitem>
+                            <para>
+                                Return to either the app or the domain default zoom factor.
+                            </para>
+                        </listitem>
+                    </varlistentry>
+
                     <!-- Zoom In. -->
                     <varlistentry id="zoom-in">
                         <term>
 
                         <listitem>
                             <para>
-                                Reload the website in the current tab.
+                                Reload the website in the current tab.  When Refresh is visible, <xref linkend="view-stop"/> is hidden.
                             </para>
                         </listitem>
                     </varlistentry>
                         </listitem>
                     </varlistentry>
 
+                    <!-- Stop. -->
+                    <varlistentry id="view-stop">
+                        <term>
+                            <menuchoice>
+                                <shortcut>
+                                    <keycombo action="simul">&Ctrl;&Shift;<keycap>X</keycap></keycombo>
+                                </shortcut>
+
+                                <guimenu>View</guimenu>
+
+                                <guimenuitem>Stop</guimenuitem>
+                            </menuchoice>
+                        </term>
+
+                        <listitem>
+                            <para>
+                                Stop the loading of the website in the current tab.  When Stop is visible, <xref linkend="view-refresh"/> is hidden.
+                            </para>
+                        </listitem>
+                    </varlistentry>
+
                     <!-- View Source. -->
                     <varlistentry id="view-source">
                         <term>
                         </listitem>
                     </varlistentry>
 
+                    <!-- Developer Tools. -->
+                    <varlistentry id="view-developer-tools">
+                        <term>
+                            <menuchoice>
+                                <shortcut>
+                                    <keycap>F12</keycap>
+                                </shortcut>
+
+                                <guimenu>View</guimenu>
+
+                                <guimenuitem>Developer Tools</guimenuitem>
+                            </menuchoice>
+                        </term>
+
+                        <listitem>
+                            <para>
+                                Display the developer tools, which are used to debug websites.
+                            </para>
+                        </listitem>
+                    </varlistentry>
+
                     <!-- Full Screen Mode. -->
                     <varlistentry id="view-full-screen-mode">
                         <term>
 
                 <variablelist>
                     <!-- Edit Bookmarks. -->
-                    <varlistentry id="edit-bookmarks">
+                    <varlistentry id="bookmarks-edit-bookmarks">
                         <term>
                             <menuchoice>
                                 <shortcut>
                     </varlistentry>
 
                     <!-- View Bookmarks Toolbar. -->
-                    <varlistentry id="view-bookmarks-toolbar">
+                    <varlistentry id="bookmarks-view-bookmarks-toolbar">
                         <term>
                             <menuchoice>
                                 <shortcut>
                     </varlistentry>
 
                     <!-- Add Bookmark. -->
-                    <varlistentry id="add-bookmark">
+                    <varlistentry id="bookmarks-add-bookmark">
                         <term>
                             <menuchoice>
                                 <shortcut>
                     </varlistentry>
 
                     <!-- Add Folder. -->
-                    <varlistentry id="add-folder">
+                    <varlistentry id="bookmarks-add-folder">
                         <term>
                             <menuchoice>
                                 <shortcut>
         <title>Credits and License</title>
 
         <para>
-            Privacy Browser PC copyright 2016-2017,2021-2023 Soren Stoutner <ulink url="mailto:soren@stoutner.com">soren@stoutner.com</ulink>.
+            Privacy Browser PC copyright 2016-2017,2021-2024 Soren Stoutner <ulink url="mailto:soren@stoutner.com">soren@stoutner.com</ulink>.
         </para>
 
         <!-- Program. -->
index 05535436efa2a418e435748db9ff5e30bf4a244a..d52647cca107ca5163f9493f173e164ae4060530 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2022-2023 Soren Stoutner <soren@stoutner.com>.
+ * Copyright 2022-2024 Soren Stoutner <soren@stoutner.com>.
  *
  * This file is part of Privacy Browser PC <https://www.stoutner.com/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.
index cb7e09d4fac139dec11fc6b39fc40a796cd79dba..1e58d2e38057d606b7215632587e0ee67b66e4f6 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2022-2023 Soren Stoutner <soren@stoutner.com>.
+ * Copyright 2022-2024 Soren Stoutner <soren@stoutner.com>.
  *
  * This file is part of Privacy Browser PC <https://www.stoutner.com/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.
index 82f0f64b890af85781c3187a5f3ecf7902d04f2a..59d7bdb073628886be1e964237a208df26f03adc 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2022-2023 Soren Stoutner <soren@stoutner.com>.
+ * Copyright 2022-2024 Soren Stoutner <soren@stoutner.com>.
  *
  * This file is part of Privacy Browser PC <https://www.stoutner.com/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
index 7163458cb125f9c28bc7ced6339fc7790b2f2403..543c1bbb6f2eab80d93db7a3165f5807cd70cd6a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2022 Soren Stoutner <soren@stoutner.com>.
+ * Copyright 2022,2024 Soren Stoutner <soren@stoutner.com>.
  *
  * This file is part of Privacy Browser PC <https://www.stoutner.com/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;
index 1033c9321000b3f5180d7ee6c730cfc58f3e200f..de58905f08b2f355874c6cae7e57c74705acb358 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2022-2023 Soren Stoutner <soren@stoutner.com>.
+ * Copyright 2022-2024 Soren Stoutner <soren@stoutner.com>.
  *
  * This file is part of Privacy Browser PC <https://www.stoutner.com/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.
index aee7bc900124112b4c3933251de61bc600e5c8b6..60f9902812a8599348cd225f9c2a74a881f90c8e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2022 Soren Stoutner <soren@stoutner.com>.
+ * Copyright 2022,2024 Soren Stoutner <soren@stoutner.com>.
  *
  * This file is part of Privacy Browser PC <https://www.stoutner.com/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);
index 3cedc083329ea04e88cc5599a17324d828267022..0c499f2750e19f01ea294c011c6e7701542f72b4 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2022-2023 Soren Stoutner <soren@stoutner.com>.
+ * Copyright 2022-2024 Soren Stoutner <soren@stoutner.com>.
  *
  * This file is part of Privacy Browser PC <https://www.stoutner.com/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 <soren@stoutner.com>"));
+    aboutData.setCopyrightStatement(i18nc("Copyright", "Copyright 2016-2017,2021-2024 Soren Stoutner <soren@stoutner.com>"));
     aboutData.setDesktopFileName(QStringLiteral("com.stoutner.privacybrowser"));
     aboutData.setHomepage(QStringLiteral("https://www.stoutner.com/privacy-browser-pc/"));
     //aboutData.setLicense(KAboutLicense::GPL_V3, KAboutLicense::OrLaterVersions);  <https://redmine.stoutner.com/issues/822>
index 4f4a635651a16fca4ebd60a335408081cd056b13..58ccfc65281af538a445d44411e174973dc44113 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2022-2023 Soren Stoutner <soren@stoutner.com>.
+ * Copyright 2022-2024 Soren Stoutner <soren@stoutner.com>.
  *
  * This file is part of Privacy Browser PC <https://www.stoutner.com/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.
index 06676d642e14cbe91b871323bf3dc25f59c13635..7dbb581f401a27f09ce2f665ec54d83fce81a6e9 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2022-2023 Soren Stoutner <soren@stoutner.com>.
+ * Copyright 2022-2024 Soren Stoutner <soren@stoutner.com>.
  *
  * This file is part of Privacy Browser PC <https://www.stoutner.com/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.
index 1513d1af30e7eb31ccd3435ff22a1524cd6a8867..13e3c51ebbaa93ca054569b257bf7e0bba3deac7 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2022-2023 Soren Stoutner <soren@stoutner.com>.
+ * Copyright 2022-2024 Soren Stoutner <soren@stoutner.com>.
  *
  * This file is part of Privacy Browser PC <https://www.stoutner.com/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 &currentDomainSettingsName = 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);
 }
index 143e35f1571ecbec87eba2f136f937358bea7577..eedc2502c693e0aea3179a82b8bc185e6f36b4ce 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2022-2023 Soren Stoutner <soren@stoutner.com>.
+ * Copyright 2022-2024 Soren Stoutner <soren@stoutner.com>.
  *
  * This file is part of Privacy Browser PC <https://www.stoutner.com/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);