Add User Agent to Domain Settings.
authorSoren Stoutner <soren@stoutner.com>
Wed, 23 Mar 2022 23:42:02 +0000 (16:42 -0700)
committerSoren Stoutner <soren@stoutner.com>
Wed, 23 Mar 2022 23:42:02 +0000 (16:42 -0700)
13 files changed:
src/CMakeLists.txt
src/DomainSettingsDialog.ui
src/SettingsGeneral.ui
src/SettingsPrivacy.ui
src/dialogs/DomainSettingsDialog.cpp
src/dialogs/DomainSettingsDialog.h
src/helpers/DomainsDatabaseHelper.cpp
src/helpers/DomainsDatabaseHelper.h
src/helpers/UserAgentHelper.cpp
src/helpers/UserAgentHelper.h
src/views/BrowserView.cpp
src/windows/BrowserWindow.cpp
src/windows/BrowserWindow.h

index c679f9997f6e47628ea37b8ade39600a0066c49f..55b3e3f75911dd82616e6361a452f080098d5ba0 100644 (file)
@@ -39,8 +39,8 @@ kconfig_add_kcfg_files(privacy-browser Settings.kcfgc)
 ki18n_wrap_ui(privacy-browser
     BrowserView.ui
     DomainSettingsDialog.ui
-    SettingsPrivacy.ui
     SettingsGeneral.ui
+    SettingsPrivacy.ui
 )
 
 # Link the following libraries.
@@ -64,9 +64,9 @@ target_link_libraries(privacy-browser
 # Add the subdirectories.
 add_subdirectory(dialogs)
 add_subdirectory(helpers)
+add_subdirectory(ui.rc)
 add_subdirectory(views)
 add_subdirectory(windows)
-add_subdirectory(ui.rc)
 
 # Install Privacy Browser using the default KDE arguments.
 install(TARGETS privacy-browser ${KDE_INSTALL_TARGETS_DEFAULT_ARGS})
index e6f9aca2079f6f574aa3bd7cf7f57a1d1cdb1aa9..a2abaf7f149c8fdd6b2db5a8a001b56bb985be84 100644 (file)
@@ -26,8 +26,8 @@
             <rect>
                 <x>0</x>
                 <y>0</y>
-                <width>700</width>
-                <height>500</height>
+                <height>1000</height>
+                <width>1500</width>
             </rect>
         </property>
 
                                         </item>
                                     </widget>
                                 </item>
+
+                                <item row="2" column="1">
+                                    <widget class="QLabel" name="javaScriptLabel">
+                                        <property name="textFormat">
+                                            <enum>Qt::RichText</enum>
+                                        </property>
+                                    </widget>
+                                </item>
+
+                                <!-- User Agent. -->
+                                <item row="3" column="0">
+                                    <widget class="QLabel">
+                                        <property name="text">
+                                            <string>User Agent</string>
+                                        </property>
+                                    </widget>
+                                </item>
+
+                                <item row="3" column="1">
+                                    <widget class="QComboBox" name="userAgentComboBox">
+                                        <property name="sizePolicy">
+                                            <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
+                                                <horstretch>0</horstretch>
+                                                <verstretch>0</verstretch>
+                                            </sizepolicy>
+                                        </property>
+
+                                        <property name="editable">
+                                            <bool>true</bool>
+                                        </property>
+
+                                        <item>
+                                            <property name="text">
+                                                <string>System default</string>
+                                            </property>
+                                        </item>
+
+                                        <item>
+                                            <property name="text">
+                                                <string>Privacy Browser</string>
+                                            </property>
+                                        </item>
+
+                                        <item>
+                                            <property name="text">
+                                                <string>Firefox on Linux</string>
+                                            </property>
+                                        </item>
+
+                                        <item>
+                                            <property name="text">
+                                                <string>Chromium on Linux</string>
+                                            </property>
+                                        </item>
+
+                                        <item>
+                                            <property name="text">
+                                                <string>Firefox on Windows</string>
+                                            </property>
+                                        </item>
+
+                                        <item>
+                                            <property name="text">
+                                                <string>Chrome on Windows</string>
+                                            </property>
+                                        </item>
+
+                                        <item>
+                                            <property name="text">
+                                                <string>Edge on Windows</string>
+                                            </property>
+                                        </item>
+
+                                        <item>
+                                            <property name="text">
+                                                <string>Safari on macOS</string>
+                                            </property>
+                                        </item>
+                                    </widget>
+                                </item>
+
+                                <item row="4" column="1">
+                                    <widget class="QLabel" name="userAgentLabel">
+                                        <property name="textFormat">
+                                            <enum>Qt::RichText</enum>
+                                        </property>
+                                    </widget>
+                                </item>
                             </layout>
                         </widget>
                     </item>
index 9e33b8a4ad5b7c54654b5a34c7a5bdfff52b7577..65b693ecfa4d346fea8bf8e7fccf0888480de601 100644 (file)
 
             <item row="1" column="1">
                 <widget class="QComboBox" name="kcfg_searchEngine">
-                    <property name="minimumSize">
-                        <size>
-                            <height>0</height>
-                            <width>500</width>
-                        </size>
+                    <property name="sizePolicy">
+                        <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
+                            <horstretch>0</horstretch>
+                            <verstretch>0</verstretch>
+                        </sizepolicy>
                     </property>
 
                     <property name="toolTip">
index 8c701d8afd6c018a1f01b2a6a3e33e62898c1b89..74c7a0fda799f25f626566340b15b81dd104a89c 100644 (file)
 
             <item row="1" column="1">
                 <widget class="QComboBox" name="kcfg_userAgent">
-                    <property name="minimumSize">
-                        <size>
-                            <height>0</height>
-                            <width>500</width>
-                        </size>
+                    <property name="sizePolicy">
+                        <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
+                            <horstretch>0</horstretch>
+                            <verstretch>0</verstretch>
+                        </sizepolicy>
                     </property>
 
                     <property name="toolTip">
index 0ebfb1448b85cf822dab246992fa02bcd65df0a3..e44af92563d63fb62b6605b5e7ef144a4acce462 100644 (file)
 
 // Application headers.
 #include "DomainSettingsDialog.h"
+#include "Settings.h"
 #include "ui_DomainSettingsDialog.h"
 #include "helpers/DomainsDatabaseHelper.h"
+#include "helpers/UserAgentHelper.h"
 
 // Qt toolkit headers.
 #include <QInputDialog>
@@ -40,6 +42,9 @@ DomainSettingsDialog::DomainSettingsDialog(QWidget *parent) : QDialog(parent)
     domainSettingsWidgetPointer = domainSettingsDialogUi.domainSettingsWidget;
     domainNameLineEditPointer = domainSettingsDialogUi.domainNameLineEdit;
     javaScriptComboBoxPointer = domainSettingsDialogUi.javaScriptComboBox;
+    javaScriptLabelPointer = domainSettingsDialogUi.javaScriptLabel;
+    userAgentComboBoxPointer = domainSettingsDialogUi.userAgentComboBox;
+    userAgentLabelPointer = domainSettingsDialogUi.userAgentLabel;
     QPushButton *addDomainButtonPointer = domainSettingsDialogUi.addDomainButton;
     deleteDomainButtonPointer = domainSettingsDialogUi.deleteDomainButton;
     QDialogButtonBox *dialogButtonBoxPointer = domainSettingsDialogUi.dialogButtonBox;
@@ -82,6 +87,7 @@ DomainSettingsDialog::DomainSettingsDialog(QWidget *parent) : QDialog(parent)
     // Connect the domain settings.
     connect(domainNameLineEditPointer, SIGNAL(textEdited(QString)), this, SLOT(domainNameChanged(QString)));
     connect(javaScriptComboBoxPointer, SIGNAL(currentIndexChanged(int)), this, SLOT(javaScriptChanged(int)));
+    connect(userAgentComboBoxPointer, SIGNAL(currentTextChanged(QString)), this, SLOT(userAgentChanged(QString)));
 
     // Connect the buttons.
     connect(addDomainButtonPointer, SIGNAL(released()), this, SLOT(showAddMessageBox()));
@@ -115,6 +121,9 @@ void DomainSettingsDialog::apply() const
 
     // Update the UI.
     updateUi();
+
+    // Emit the domain settings updated signal.
+    emit domainSettingsUpdated();
 }
 
 void DomainSettingsDialog::cancel()
@@ -144,6 +153,22 @@ void DomainSettingsDialog::domainSelected(QModelIndex modelIndex) const
     // Populate the JavaScript combo box.
     javaScriptComboBoxPointer->setCurrentIndex(modelIndex.siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::JAVASCRIPT)).data().toInt());
 
+    // Get the user agent string.
+    QString userAgent = modelIndex.siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::USER_AGENT)).data().toString();
+
+    // Get the user agent index.
+    int userAgentIndex = UserAgentHelper::getDomainSettingsUserAgentIndex(userAgent);
+
+    // Set the user agent combo box index.
+    userAgentComboBoxPointer->setCurrentIndex(userAgentIndex);
+
+    // Set the custom user agent if specified.
+    if (userAgentIndex == -1) userAgentComboBoxPointer->setCurrentText(userAgent);
+
+    // Populate the labels.
+    populateJavaScriptLabel();
+    populateUserAgentLabel(userAgentComboBoxPointer->currentText());
+
     // Update the UI.
     updateUi();
 }
@@ -154,6 +179,9 @@ void DomainSettingsDialog::javaScriptChanged(int newIndex) const
     domainsTableModelPointer->setData(domainsListViewPointer->selectionModel()->currentIndex().siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::JAVASCRIPT)),
                                       newIndex);
 
+    // Populate the JavaScript label.
+    populateJavaScriptLabel();
+
     // Update the UI.
     updateUi();
 }
@@ -164,17 +192,73 @@ void DomainSettingsDialog::ok()
     // Submit all pending changes.
     domainsTableModelPointer->submitAll();
 
+    // Emit the domain settings updated signal.
+    domainSettingsUpdated();
+
     // Close the dialog.
     accept();
 }
 
+void DomainSettingsDialog::populateJavaScriptLabel() const
+{
+    // Populate the label according to the currently selected index.
+    switch (javaScriptComboBoxPointer->currentIndex())
+    {
+        case (DomainsDatabaseHelper::SYSTEM_DEFAULT):
+        {
+            // Set the text according to the system default.
+            if (Settings::javaScript())
+            {
+                javaScriptLabelPointer->setText(i18nc("Domains settings labels", "JavaScript enabled"));
+            }
+            else
+            {
+                javaScriptLabelPointer->setText(i18nc("Domain settings labels", "JavaScript disabled"));
+            }
+
+            break;
+        }
+
+        case (DomainsDatabaseHelper::DISABLED):
+        {
+            // Set the label text in bold.
+            javaScriptLabelPointer->setText(i18nc("Domain settings labels.  The <strong> tags should be retained.", "<strong>JavaScript disabled</strong>"));
+
+            break;
+        }
+
+        case (DomainsDatabaseHelper::ENABLED):
+        {
+            // Set the label text in bold.
+            javaScriptLabelPointer->setText(i18nc("Domains settings labels.  The <strong> tags should be retained.", "<strong>JavaScript enabled</strong>"));
+
+            break;
+        }
+    }
+}
+
+void DomainSettingsDialog::populateUserAgentLabel(const QString &userAgentName) const
+{
+    // Populate the label according to the type.
+    if (userAgentName == UserAgentHelper::SYSTEM_DEFAULT_TRANSLATED)
+    {
+        // Display the system default user agent name.
+        userAgentLabelPointer->setText(UserAgentHelper::getTranslatedUserAgentName(Settings::userAgent()));
+    }
+    else
+    {
+        // Display the user agent name in bold.
+        userAgentLabelPointer->setText("<strong>" + userAgentName + "</strong>");
+    }
+}
+
 void DomainSettingsDialog::reset() const
 {
     // Cancel all pending changes.
     domainsTableModelPointer->revertAll();
 
-    // Repopulate the domain name line edit.
-    domainNameLineEditPointer->setText(domainsListViewPointer->currentIndex().data().toString());
+    // Repopulate the domain settings.
+    domainSelected(domainsListViewPointer->currentIndex());
 
     // Update the UI.
     updateUi();
@@ -201,9 +285,12 @@ void DomainSettingsDialog::showAddMessageBox()
         // Add the new domain name.
         newDomainRecord.setValue(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::DOMAIN_NAME), newDomainName);
 
-        // Set the default value of `0` for the other columns.
+        // Set the default value of `0` for JavaScript.
         newDomainRecord.setValue(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::JAVASCRIPT), 0);
 
+        // Set the default value for the user agent.
+        newDomainRecord.setValue(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::USER_AGENT), UserAgentHelper::SYSTEM_DEFAULT_DATABASE);
+
         // Insert the new domain.  `-1` appends it to the end.
         domainsTableModelPointer->insertRecord(-1, newDomainRecord);
 
@@ -301,3 +388,17 @@ void DomainSettingsDialog::updateUi() const
     domainSettingsWidgetPointer->setVisible(domainsTableModelPointer->rowCount() > 0);
 }
 
+void DomainSettingsDialog::userAgentChanged(const QString updatedUserAgent) const
+{
+    // Update the domains table model.
+    domainsTableModelPointer->setData(domainsListViewPointer->selectionModel()->currentIndex().siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::USER_AGENT)),
+                                      UserAgentHelper::getDatabaseUserAgentName(updatedUserAgent));
+
+    // Populate the user agent label.
+    populateUserAgentLabel(updatedUserAgent);
+
+    // Update the UI.
+    updateUi();
+}
+
+
index 3ae50b567ac14d710e40324fea0252666bc4f2c5..6acfcb57e9d0cb8720ff12b3d19bb4784b0f90a1 100644 (file)
@@ -25,6 +25,7 @@
 
 // Qt toolkit headers.
 #include <QDialog>
+#include <QLabel>
 #include <QtSql>
 
 class DomainSettingsDialog : public QDialog
@@ -36,6 +37,9 @@ public:
     // The primary constructor.
     explicit DomainSettingsDialog(QWidget *parent = nullptr);
 
+signals:
+    void domainSettingsUpdated() const;
+
 private Q_SLOTS:
     // The private slots.
     void apply() const;
@@ -47,11 +51,9 @@ private Q_SLOTS:
     void reset() const;
     void showAddMessageBox();
     void showDeleteMessageBox() const;
+    void userAgentChanged(const QString updatedUserAgent) const;
 
 private:
-    // The private functions.
-    void updateUi() const;
-
     // The private variables.
     QPushButton *applyButtonPointer;
     QPushButton *deleteDomainButtonPointer;
@@ -60,6 +62,14 @@ private:
     QWidget *domainSettingsWidgetPointer;
     QSqlTableModel *domainsTableModelPointer;
     QComboBox *javaScriptComboBoxPointer;
+    QLabel *javaScriptLabelPointer;
     QPushButton *resetButtonPointer;
+    QComboBox *userAgentComboBoxPointer;
+    QLabel *userAgentLabelPointer;
+
+    // The private functions.
+    void populateJavaScriptLabel() const;
+    void populateUserAgentLabel(const QString &userAgentName) const;
+    void updateUi() const;
 };
 #endif
index 5de297d229fe688da8a4aa00d9eb00ca4ca48f3e..48b28a34966733b7bbbbc26dadc043b94f5c71ae 100644 (file)
 
 // Application headers.
 #include "DomainsDatabaseHelper.h"
+#include "UserAgentHelper.h"
 
 // Define the public static domain constants.
 const QString DomainsDatabaseHelper::CONNECTION_NAME = "domains_database";
 const QString DomainsDatabaseHelper::DOMAINS_TABLE = "domains";
 
 // Define the private static schema constants.
-const int DomainsDatabaseHelper::SCHEMA_VERSION = 1;
+const int DomainsDatabaseHelper::SCHEMA_VERSION = 2;
 
 // Define the public static database field names.
 const QString DomainsDatabaseHelper::_ID = "_id";
 const QString DomainsDatabaseHelper::DOMAIN_NAME = "domain_name";
 const QString DomainsDatabaseHelper::JAVASCRIPT = "javascript";
+const QString DomainsDatabaseHelper::USER_AGENT = "user_agent";
 
 // The default constructor.
 DomainsDatabaseHelper::DomainsDatabaseHelper() {}
@@ -72,6 +74,15 @@ void DomainsDatabaseHelper::addDatabase()
 
                         // Set the default value.
                         domainsDatabase.exec("UPDATE " + DOMAINS_TABLE + " SET " + JAVASCRIPT + " = 0" );
+
+                        [[fallthrough]];
+                    }
+
+                    // Upgrade from schema version 1.
+                    case 1:
+                    {
+                        // Add the User Agent column.
+                        domainsDatabase.exec("ALTER TABLE " + DOMAINS_TABLE + " ADD COLUMN " + USER_AGENT + " TEXT DEFAULT '" + UserAgentHelper::SYSTEM_DEFAULT_DATABASE + "'");
                     }
                 }
 
@@ -88,7 +99,8 @@ void DomainsDatabaseHelper::addDatabase()
             createTableQuery.prepare("CREATE TABLE " + DOMAINS_TABLE + "(" +
                 _ID + " INTEGER PRIMARY KEY, " +
                 DOMAIN_NAME + " TEXT, " +
-                JAVASCRIPT + " INTEGER DEFAULT 0)"
+                JAVASCRIPT + " INTEGER DEFAULT 0," +
+                USER_AGENT + " TEXT DEFAULT '" + UserAgentHelper::SYSTEM_DEFAULT_DATABASE + "')"
             );
 
             // Execute the query.
index b02a4cf9631342e17b9f3f5c8103b2d139500c3e..4badf418208e29f3c573b425b442a889fc1911c2 100644 (file)
@@ -44,6 +44,7 @@ public:
     static const QString DOMAIN_NAME;
     static const QString DOMAINS_TABLE;
     static const QString JAVASCRIPT;
+    static const QString USER_AGENT;
 
 private:
     // The private static constants.
index 4b1fd85475b8ec46e28fd52ae3e25e2b0624a3d8..1b02146c370820c4ce5e581c82836ce4f5fb8866 100644 (file)
  */
 
 // Application headers.
+#include "Settings.h"
 #include "UserAgentHelper.h"
 
+// KDE Framework headers.
+#include <KLocalizedString>
+
+// Define the public database constants.
+const QString UserAgentHelper::SYSTEM_DEFAULT_DATABASE = QStringLiteral("System Default");
+const QString UserAgentHelper::PRIVACY_BROWSER_DATABASE = QStringLiteral("Privacy Browser");
+const QString UserAgentHelper::FIREFOX_LINUX_DATABASE = QStringLiteral("Firefox Linux");
+const QString UserAgentHelper::CHROMIUM_LINUX_DATABASE = QStringLiteral("Chromium Linux");
+const QString UserAgentHelper::FIREFOX_WINDOWS_DATABASE = QStringLiteral("Firefox Windows");
+const QString UserAgentHelper::CHROME_WINDOWS_DATABASE = QStringLiteral("Chrome Windows");
+const QString UserAgentHelper::EDGE_WINDOWS_DATABASE = QStringLiteral("Edge Windows");
+const QString UserAgentHelper::SAFARI_MACOS_DATABASE = QStringLiteral("Safari macOS");
+
+// Define the public translated constants.
+const QString UserAgentHelper::SYSTEM_DEFAULT_TRANSLATED = i18n("System default");
+const QString UserAgentHelper::PRIVACY_BROWSER_TRANSLATED = i18n("Privacy Browser");
+const QString UserAgentHelper::FIREFOX_LINUX_TRANSLATED = i18n("Firefox on Linux");
+const QString UserAgentHelper::CHROMIUM_LINUX_TRANSLATED = i18n("Chromium on Linux");
+const QString UserAgentHelper::FIREFOX_WINDOWS_TRANSLATED = i18n("Firefox on Windows");
+const QString UserAgentHelper::CHROME_WINDOWS_TRANSLATED = i18n("Chrome on Windows");
+const QString UserAgentHelper::EDGE_WINDOWS_TRANSLATED = i18n("Edge on Windows");
+const QString UserAgentHelper::SAFARI_MACOS_TRANSLATED = i18n("Safari on macOS");
+
+// Define the public user agent constants.
+const QString UserAgentHelper::PRIVACY_BROWSER_USER_AGENT = QStringLiteral("PrivacyBrowser/1.0");
+const QString UserAgentHelper::FIREFOX_LINUX_USER_AGENT = QStringLiteral("Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Firefox/91.0");
+const QString UserAgentHelper::CHROMIUM_LINUX_USER_AGENT = QStringLiteral("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36");
+const QString UserAgentHelper::FIREFOX_WINDOWS_USER_AGENT = QStringLiteral("Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:97.0) Gecko/20100101 Firefox/97.0");
+const QString UserAgentHelper::CHROME_WINDOWS_USER_AGENT = QStringLiteral("Mozilla/5.0 (Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36");
+const QString UserAgentHelper::EDGE_WINDOWS_USER_AGENT = QStringLiteral("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36 Edg/98.0.1108.56");
+const QString UserAgentHelper::SAFARI_MACOS_USER_AGENT = QStringLiteral("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.1 Safari/605.1.15");
+
 // The default constructor.
 UserAgentHelper::UserAgentHelper() {};
 
-QString UserAgentHelper::getUserAgent(const QString &userAgentName)
+QString UserAgentHelper::getUserAgentFromDatabaseName(const QString &userAgentDatabaseName)
+{
+    if (userAgentDatabaseName == PRIVACY_BROWSER_DATABASE) return PRIVACY_BROWSER_USER_AGENT;  // Privacy Browser.
+    else if (userAgentDatabaseName == FIREFOX_LINUX_DATABASE) return FIREFOX_LINUX_USER_AGENT;  // Firefox Linux.
+    else if (userAgentDatabaseName == CHROMIUM_LINUX_DATABASE) return CHROMIUM_LINUX_USER_AGENT;  // Chromium Linux.
+    else if (userAgentDatabaseName == FIREFOX_WINDOWS_DATABASE) return FIREFOX_WINDOWS_USER_AGENT;  // Firefox Windows.
+    else if (userAgentDatabaseName == CHROME_WINDOWS_DATABASE) return CHROME_WINDOWS_USER_AGENT;  // Chrome Windows.
+    else if (userAgentDatabaseName == EDGE_WINDOWS_DATABASE) return EDGE_WINDOWS_USER_AGENT;  // Edge Windows.
+    else if (userAgentDatabaseName == SAFARI_MACOS_DATABASE) return SAFARI_MACOS_USER_AGENT;  // Safari macOS.
+    else return userAgentDatabaseName;  // Return the custom user agent.
+}
+
+QString UserAgentHelper::getUserAgentFromTranslatedName(const QString &userAgentTranslatedName)
+{
+    if (userAgentTranslatedName == PRIVACY_BROWSER_TRANSLATED) return PRIVACY_BROWSER_USER_AGENT;  // Privacy Browser.
+    else if (userAgentTranslatedName == FIREFOX_LINUX_TRANSLATED) return FIREFOX_LINUX_USER_AGENT;  // Firefox on Linux.
+    else if (userAgentTranslatedName == CHROMIUM_LINUX_TRANSLATED) return CHROMIUM_LINUX_USER_AGENT;  // Chromium on Linux.
+    else if (userAgentTranslatedName == FIREFOX_WINDOWS_TRANSLATED) return FIREFOX_WINDOWS_USER_AGENT;  // Firefox on Windows.
+    else if (userAgentTranslatedName == CHROME_WINDOWS_TRANSLATED) return CHROME_WINDOWS_USER_AGENT;  // Chrome on Windows.
+    else if (userAgentTranslatedName == EDGE_WINDOWS_TRANSLATED) return EDGE_WINDOWS_USER_AGENT;  // Edge on Windows.
+    else if (userAgentTranslatedName == SAFARI_MACOS_TRANSLATED) return SAFARI_MACOS_USER_AGENT;  // Safari on macOS.
+    else return userAgentTranslatedName;  // Return the custom user agent.
+}
+
+QString UserAgentHelper::getDatabaseUserAgentName(const QString &translatedUserAgentName)
+{
+    // Return the database user agent name.
+    if (translatedUserAgentName == SYSTEM_DEFAULT_TRANSLATED) return SYSTEM_DEFAULT_DATABASE;  // System Default.
+    else if (translatedUserAgentName == PRIVACY_BROWSER_TRANSLATED) return PRIVACY_BROWSER_DATABASE;  // Privacy Browser.
+    else if (translatedUserAgentName == FIREFOX_LINUX_TRANSLATED) return FIREFOX_LINUX_DATABASE;  // Firefox Linux.
+    else if (translatedUserAgentName == CHROMIUM_LINUX_TRANSLATED) return CHROMIUM_LINUX_DATABASE;  // Chromium Linux.
+    else if (translatedUserAgentName == FIREFOX_WINDOWS_TRANSLATED) return FIREFOX_WINDOWS_DATABASE;  // Firefox Windows.
+    else if (translatedUserAgentName == CHROME_WINDOWS_TRANSLATED) return CHROME_WINDOWS_DATABASE;  // Chrome Windows.
+    else if (translatedUserAgentName == EDGE_WINDOWS_TRANSLATED) return EDGE_WINDOWS_DATABASE;  // Edge Windows.
+    else if (translatedUserAgentName == SAFARI_MACOS_TRANSLATED) return SAFARI_MACOS_DATABASE;  // Safari macOS.
+    else return translatedUserAgentName;  // Return the custom user agent.
+}
+
+int UserAgentHelper::getDomainSettingsUserAgentIndex(const QString &userAgentName)
+{
+    // Return the domain settings user agent index.
+    if (userAgentName == SYSTEM_DEFAULT_DATABASE) return 0;  // System Default.
+    else if (userAgentName == PRIVACY_BROWSER_DATABASE) return 1;  // Privacy Browser.
+    else if (userAgentName == FIREFOX_LINUX_DATABASE) return 2;  // Firefox Linux.
+    else if (userAgentName == CHROMIUM_LINUX_DATABASE) return 3;  // Chromium Linux.
+    else if (userAgentName == FIREFOX_WINDOWS_DATABASE) return 4;  // Firefox Windows.
+    else if (userAgentName == CHROME_WINDOWS_DATABASE) return 5;  // Chrome Windows.
+    else if (userAgentName == EDGE_WINDOWS_DATABASE) return 6;  // Edge Windows.
+    else if (userAgentName == SAFARI_MACOS_DATABASE) return 7;  // Safari macOS.
+    else return -1;  // Custom user agent.
+}
+
+QString UserAgentHelper::getResultingDomainSettingsUserAgent(const QString &rawUserAgent)
+{
+    // Return the resulting user agent.
+    if (rawUserAgent == SYSTEM_DEFAULT_DATABASE) return getUserAgentFromDatabaseName(Settings::userAgent());  // Return the default user agent.
+    else return getUserAgentFromDatabaseName(rawUserAgent);  // Return the domain user agent.
+}
+
+QString UserAgentHelper::getTranslatedUserAgentName(const QString &userAgentName)
 {
-    if (userAgentName == "Privacy Browser")  // Privacy Browser.
-    {
-        return "PrivacyBrowser/1.0";
-    }
-    else if (userAgentName == "Firefox Linux")  // Firefox Linux.
-    {
-        return "Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Firefox/91.0";
-    }
-    else if (userAgentName == "Chromium Linux")  // Chromium Linux.
-    {
-        return "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36";
-    }
-    else if (userAgentName == "Firefox Windows")  // Firefox Windows.
-    {
-        return "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:97.0) Gecko/20100101 Firefox/97.0";
-    }
-    else if (userAgentName == "Chrome Windows")  // Chrome Windows.
-    {
-        return "Mozilla/5.0 (Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36";
-    }
-    else if (userAgentName == "Edge Windows")  // Edge Windows.
-    {
-        return "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36 Edg/98.0.1108.56";
-    }
-    else if (userAgentName == "Safari macOS")  // Safari macOS.
-    {
-        return "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.1 Safari/605.1.15";
-    }
-    else
-    {
-        // Return the custom user agent.
-        return userAgentName;
-    }
+    // Return the translated user agent name.
+    if (userAgentName == PRIVACY_BROWSER_DATABASE) return PRIVACY_BROWSER_TRANSLATED;  // Privacy Browser.
+    else if (userAgentName == FIREFOX_LINUX_DATABASE) return FIREFOX_LINUX_TRANSLATED;  // Firefox on Linux.
+    else if (userAgentName == CHROMIUM_LINUX_DATABASE) return CHROMIUM_LINUX_TRANSLATED;  // Chromium on Linux.
+    else if (userAgentName == FIREFOX_WINDOWS_DATABASE) return FIREFOX_WINDOWS_TRANSLATED;  // Firefox on Windows.
+    else if (userAgentName == CHROME_WINDOWS_DATABASE) return CHROME_WINDOWS_TRANSLATED;  // Chrome on Windows.
+    else if (userAgentName == EDGE_WINDOWS_DATABASE) return EDGE_WINDOWS_TRANSLATED;  // Edge on Windows.
+    else if (userAgentName == SAFARI_MACOS_DATABASE) return SAFARI_MACOS_TRANSLATED;  // Safari on macOS.
+    else return userAgentName;  // Return the custom user agent.
 }
index f93696804499f173cf3bfa6c82711a9edb2944c1..1043d372b3920973a30c11d91b123684b6298522 100644 (file)
@@ -29,7 +29,37 @@ public:
     // The default constructor.
     UserAgentHelper();
 
+    // The public constants.
+    static const QString CHROMIUM_LINUX_DATABASE;
+    static const QString CHROMIUM_LINUX_TRANSLATED;
+    static const QString CHROMIUM_LINUX_USER_AGENT;
+    static const QString CHROME_WINDOWS_DATABASE;
+    static const QString CHROME_WINDOWS_TRANSLATED;
+    static const QString CHROME_WINDOWS_USER_AGENT;
+    static const QString EDGE_WINDOWS_DATABASE;
+    static const QString EDGE_WINDOWS_TRANSLATED;
+    static const QString EDGE_WINDOWS_USER_AGENT;
+    static const QString FIREFOX_LINUX_DATABASE;
+    static const QString FIREFOX_LINUX_TRANSLATED;
+    static const QString FIREFOX_LINUX_USER_AGENT;
+    static const QString FIREFOX_WINDOWS_DATABASE;
+    static const QString FIREFOX_WINDOWS_TRANSLATED;
+    static const QString FIREFOX_WINDOWS_USER_AGENT;
+    static const QString PRIVACY_BROWSER_DATABASE;
+    static const QString PRIVACY_BROWSER_TRANSLATED;
+    static const QString PRIVACY_BROWSER_USER_AGENT;
+    static const QString SAFARI_MACOS_DATABASE;
+    static const QString SAFARI_MACOS_TRANSLATED;
+    static const QString SAFARI_MACOS_USER_AGENT;
+    static const QString SYSTEM_DEFAULT_DATABASE;
+    static const QString SYSTEM_DEFAULT_TRANSLATED;
+
     // The public functions.
-    static QString getUserAgent(const QString &userAgentName);
+    static QString getUserAgentFromDatabaseName(const QString &userAgentDatabaseName);
+    static QString getUserAgentFromTranslatedName(const QString &userAgentTranslatedName);
+    static QString getDatabaseUserAgentName(const QString &translatedUserAgentName);
+    static int getDomainSettingsUserAgentIndex(const QString &userAgentName);
+    static QString getResultingDomainSettingsUserAgent(const QString &rawUserAgent);
+    static QString getTranslatedUserAgentName(const QString &userAgentName);
 };
 #endif
index 3a116e267344aef1d6496cee9c781577ecf5f0cc..c6a984c880023acc641d7fa18cbc3ca419c27b5d 100644 (file)
@@ -60,7 +60,7 @@ BrowserView::BrowserView(QWidget *parent) : QWidget(parent)
     // Update the webengine view from the URL line edit.
     connect(urlLineEditPointer, SIGNAL(returnKeyPressed(const QString)), this, SLOT(loadUrlFromTextBox(const QString)));
 
-    // Update the URL line edit form the webengine view.
+    // Update the URL line edit from the webengine view.
     connect(webEngineViewPointer, SIGNAL(loadStarted()), this, SLOT(updateInterface()));
     connect(webEngineViewPointer, SIGNAL(loadProgress(const int)), this, SLOT(updateInterface()));
     connect(webEngineViewPointer, SIGNAL(loadFinished(const bool)), this, SLOT(updateInterface()));
@@ -139,8 +139,6 @@ void BrowserView::applyDomainSettings(const QString &hostname, const bool reload
     // Check if the hostname has domain settings.
     if (domainQuery.isValid())  // The hostname has domain settings.
     {
-
-
         // Get the domain record.
         QSqlRecord domainRecord = domainQuery.record();
 
@@ -172,8 +170,8 @@ void BrowserView::applyDomainSettings(const QString &hostname, const bool reload
             }
         }
 
-        // Apply the user agent.
-        webEngineProfilePointer->setHttpUserAgent(UserAgentHelper::getUserAgent(Settings::userAgent()));
+        // Set the user agent.
+        webEngineProfilePointer->setHttpUserAgent(UserAgentHelper::getResultingDomainSettingsUserAgent(domainRecord.field(DomainsDatabaseHelper::USER_AGENT).value().toString()));
 
         // Set the zoom factor.
         webEngineViewPointer->setZoomFactor(Settings::zoomFactor());
@@ -186,8 +184,8 @@ void BrowserView::applyDomainSettings(const QString &hostname, const bool reload
         // Set the JavaScript status.
         webEngineSettingsPointer->setAttribute(QWebEngineSettings::JavascriptEnabled, Settings::javaScript());
 
-        // Apply the user agent.
-        webEngineProfilePointer->setHttpUserAgent(UserAgentHelper::getUserAgent(Settings::userAgent()));
+        // Set the user agent.
+        webEngineProfilePointer->setHttpUserAgent(UserAgentHelper::getUserAgentFromDatabaseName(Settings::userAgent()));
 
         // Set the zoom factor.
         webEngineViewPointer->setZoomFactor(Settings::zoomFactor());
@@ -207,7 +205,7 @@ void BrowserView::applyDomainSettings(const QString &hostname, const bool reload
     }
 
     // Emit the on-the-fly menu update signals.
-    emit userAgentUpdated(Settings::userAgent());
+    emit userAgentUpdated(webEngineProfilePointer->httpUserAgent());
     emit zoomFactorUpdated(Settings::zoomFactor());
 
     // Reload the website if requested.
@@ -238,7 +236,7 @@ void BrowserView::applyOnTheFlyUserAgent(QAction *userAgentActionPointer) const
     userAgentName.remove('&');
 
     // Apply the user agent.
-    webEngineProfilePointer->setHttpUserAgent(UserAgentHelper::getUserAgent(userAgentName));
+    webEngineProfilePointer->setHttpUserAgent(UserAgentHelper::getUserAgentFromTranslatedName(userAgentName));
 
     // Reload the website.
     webEngineViewPointer->reload();
@@ -310,14 +308,14 @@ void BrowserView::openDomainSettings() const
     // Set the dialog window title.
     domainSettingsDialogPointer->setWindowTitle(i18nc("The domain settings dialog title", "Domain Settings"));
 
-    // Resize the dialog window.
-    domainSettingsDialogPointer->resize(1500, 1000);
-
     // Set the modality.
     domainSettingsDialogPointer->setWindowModality(Qt::WindowModality::WindowModal);;
 
     // Show the dialog.
     domainSettingsDialogPointer->show();
+
+    // Reload the tabs when domain settings are updated.
+    connect(domainSettingsDialogPointer, SIGNAL(domainSettingsUpdated()), this, SLOT(applyDomainSettingsAndReload()));
 }
 
 void BrowserView::pageLinkHovered(const QString &linkUrl) const
index 1ab6cfc613bb0292a6a837c3093b6d4a74678410..3d6eb61880f8954792a9f024db2a4a19cd84f5f4 100644 (file)
@@ -105,13 +105,13 @@ BrowserWindow::BrowserWindow() : KXmlGuiWindow()
     searchEngineCustomActionPointer->setCheckable(true);
 
     // Set the non-mutable action text.
-    userAgentPrivacyBrowserActionPointer->setText(i18nc("@action", "Privacy Browser"));
-    userAgentFirefoxLinuxActionPointer->setText(i18nc("@action", "Firefox Linux"));
-    userAgentChromiumLinuxActionPointer->setText(i18nc("@action", "Chromium Linux"));
-    userAgentFirefoxWindowsActionPointer->setText(i18nc("@action", "Firefox Windows"));
-    userAgentChromeWindowsActionPointer->setText(i18nc("@action", "Chrome Windows"));
-    userAgentEdgeWindowsActionPointer->setText(i18nc("@action", "Edge Windows"));
-    userAgentSafariMacosActionPointer->setText(i18nc("@action", "Safari macOS"));
+    userAgentPrivacyBrowserActionPointer->setText(UserAgentHelper::PRIVACY_BROWSER_TRANSLATED);
+    userAgentFirefoxLinuxActionPointer->setText(UserAgentHelper::FIREFOX_LINUX_TRANSLATED);
+    userAgentChromiumLinuxActionPointer->setText(UserAgentHelper::CHROMIUM_LINUX_TRANSLATED);
+    userAgentFirefoxWindowsActionPointer->setText(UserAgentHelper::FIREFOX_WINDOWS_TRANSLATED);
+    userAgentChromeWindowsActionPointer->setText(UserAgentHelper::CHROME_WINDOWS_TRANSLATED);
+    userAgentEdgeWindowsActionPointer->setText(UserAgentHelper::EDGE_WINDOWS_TRANSLATED);
+    userAgentSafariMacosActionPointer->setText(UserAgentHelper::SAFARI_MACOS_TRANSLATED);
     searchEngineMojeekActionPointer->setText(i18nc("@action", "Mojeek"));
     searchEngineMonoclesActionPointer->setText(i18nc("@action", "Monocles"));
     searchEngineMetagerActionPointer->setText(i18nc("@action", "MetaGer"));
@@ -231,6 +231,12 @@ void BrowserWindow::settingsConfigure()
         // Make it so.
         configDialogPointer->show();
 
+        // TODO.  KConfigDialog does not respect expanding size policies.
+        configDialogPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+        privacySettingsWidgetPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+        generalSettingsWidgetPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+        configDialogPointer->adjustSize();
+
         // Expand the config dialog.
         configDialogPointer->resize(1000, 500);
 
@@ -304,34 +310,13 @@ void BrowserWindow::updateOnTheFlyUserAgent(const QString &userAgent) const
     bool customUserAgent = false;
 
     // Check the indicated on-the-fly user agent.
-    if (userAgent == "Privacy Browser")  // Privacy Browser.
-    {
-        userAgentPrivacyBrowserActionPointer->setChecked(true);
-    }
-    else if (userAgent == "Firefox Linux")  // Firefox Linux.
-    {
-        userAgentFirefoxLinuxActionPointer->setChecked(true);
-    }
-    else if (userAgent == "Chromium Linux")  // Chromium Linux.
-    {
-        userAgentChromiumLinuxActionPointer->setChecked(true);
-    }
-    else if (userAgent == "Firefox Windows")  // Firefox Windows.
-    {
-        userAgentFirefoxWindowsActionPointer->setChecked(true);
-    }
-    else if (userAgent == "Chrome Windows")  // Chrome Windows.
-    {
-        userAgentChromeWindowsActionPointer->setChecked(true);
-    }
-    else if (userAgent == "Edge Windows")  // Edge Windows.
-    {
-        userAgentEdgeWindowsActionPointer->setChecked(true);
-    }
-    else if (userAgent == "Safari macOS")  // Safari macOS.
-    {
-        userAgentSafariMacosActionPointer->setChecked(true);
-    }
+    if (userAgent == UserAgentHelper::PRIVACY_BROWSER_USER_AGENT) userAgentPrivacyBrowserActionPointer->setChecked(true);  // Privacy Browser.
+    else if (userAgent == UserAgentHelper::FIREFOX_LINUX_USER_AGENT) userAgentFirefoxLinuxActionPointer->setChecked(true);  // Firefox Linux.
+    else if (userAgent == UserAgentHelper::CHROMIUM_LINUX_USER_AGENT) userAgentChromiumLinuxActionPointer->setChecked(true);  // Chromium Linux.
+    else if (userAgent == UserAgentHelper::FIREFOX_WINDOWS_USER_AGENT) userAgentFirefoxWindowsActionPointer->setChecked(true);  // Firefox Windows.
+    else if (userAgent == UserAgentHelper::CHROME_WINDOWS_USER_AGENT) userAgentChromeWindowsActionPointer->setChecked(true);  // Chrome Windows.
+    else if (userAgent == UserAgentHelper::EDGE_WINDOWS_USER_AGENT) userAgentEdgeWindowsActionPointer->setChecked(true);  // Edge Windows.
+    else if (userAgent == UserAgentHelper::SAFARI_MACOS_USER_AGENT) userAgentSafariMacosActionPointer->setChecked(true);  // Safara macOS.
     else  // Custom user agent.
     {
         // Check the user agent.
@@ -382,8 +367,8 @@ void BrowserWindow::updateStatusBar(const QString &statusBarMessage) const
     statusBar()->showMessage(statusBarMessage);
 }
 
-void BrowserWindow::updateUserAgentLabel(const QString &userAgentName) const
+void BrowserWindow::updateUserAgentLabel(const QString &userAgentDatabaseName) const
 {
     // Update the user agent label.
-    userAgentLabelPointer->setText(UserAgentHelper::getUserAgent(userAgentName));
+    userAgentLabelPointer->setText(UserAgentHelper::getUserAgentFromDatabaseName(userAgentDatabaseName));
 }
index 7b64a966cb53fe81ac90608d63e6e499f448615e..f4dc071e5f4c597c245f270e1dcf484fed09dbab 100644 (file)
@@ -49,7 +49,7 @@ private Q_SLOTS:
     void updateOnTheFlyZoomFactor(const double &zoomFactor);
     void updateSearchEngineLabel(const QString &searchEngineString) const;
     void updateStatusBar(const QString &statusBarMessage) const;
-    void updateUserAgentLabel(const QString &userAgentName) const;
+    void updateUserAgentLabel(const QString &userAgentDatabaseName) const;
 
 private:
     // The private variables.