ki18n_wrap_ui(privacy-browser
BrowserView.ui
DomainSettingsDialog.ui
- SettingsPrivacy.ui
SettingsGeneral.ui
+ SettingsPrivacy.ui
)
# Link the following libraries.
# 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})
<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>
<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">
<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">
// 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>
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;
// 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()));
// Update the UI.
updateUi();
+
+ // Emit the domain settings updated signal.
+ emit domainSettingsUpdated();
}
void DomainSettingsDialog::cancel()
// 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();
}
domainsTableModelPointer->setData(domainsListViewPointer->selectionModel()->currentIndex().siblingAtColumn(domainsTableModelPointer->fieldIndex(DomainsDatabaseHelper::JAVASCRIPT)),
newIndex);
+ // Populate the JavaScript label.
+ populateJavaScriptLabel();
+
// Update the UI.
updateUi();
}
// 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();
// 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);
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();
+}
+
+
// Qt toolkit headers.
#include <QDialog>
+#include <QLabel>
#include <QtSql>
class DomainSettingsDialog : public QDialog
// The primary constructor.
explicit DomainSettingsDialog(QWidget *parent = nullptr);
+signals:
+ void domainSettingsUpdated() const;
+
private Q_SLOTS:
// The private slots.
void apply() const;
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;
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
// 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() {}
// 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 + "'");
}
}
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.
static const QString DOMAIN_NAME;
static const QString DOMAINS_TABLE;
static const QString JAVASCRIPT;
+ static const QString USER_AGENT;
private:
// The private static constants.
*/
// 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.
}
// 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
// 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()));
// Check if the hostname has domain settings.
if (domainQuery.isValid()) // The hostname has domain settings.
{
-
-
// Get the domain record.
QSqlRecord domainRecord = domainQuery.record();
}
}
- // 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());
// 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());
}
// 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.
userAgentName.remove('&');
// Apply the user agent.
- webEngineProfilePointer->setHttpUserAgent(UserAgentHelper::getUserAgent(userAgentName));
+ webEngineProfilePointer->setHttpUserAgent(UserAgentHelper::getUserAgentFromTranslatedName(userAgentName));
// Reload the website.
webEngineViewPointer->reload();
// 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
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"));
// 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);
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.
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));
}
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.