// Application headers.
#include "Settings.h"
#include "UserAgentHelper.h"
+#include "views/BrowserView.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::WEB_ENGINE_DEFAULT_DATABASE = QStringLiteral("WebEngine Default");
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");
// 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::WEB_ENGINE_DEFAULT_TRANSLATED = i18n("WebEngine default");
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");
// The default constructor.
UserAgentHelper::UserAgentHelper() {};
+QString UserAgentHelper::getDatabaseUserAgentNameFromTranslatedName(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 == WEB_ENGINE_DEFAULT_TRANSLATED) return WEB_ENGINE_DEFAULT_DATABASE; // WebEngine default.
+ 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 == WEB_ENGINE_DEFAULT_DATABASE) return 2; // WebEngine default.
+ else if (userAgentName == FIREFOX_LINUX_DATABASE) return 3; // Firefox Linux.
+ else if (userAgentName == CHROMIUM_LINUX_DATABASE) return 4; // Chromium Linux.
+ else if (userAgentName == FIREFOX_WINDOWS_DATABASE) return 5; // Firefox Windows.
+ else if (userAgentName == CHROME_WINDOWS_DATABASE) return 6; // Chrome Windows.
+ else if (userAgentName == EDGE_WINDOWS_DATABASE) return 7; // Edge Windows.
+ else if (userAgentName == SAFARI_MACOS_DATABASE) return 8; // Safari macOS.
+ else return -1; // Custom user agent.
+}
+
QString UserAgentHelper::getUserAgentFromDatabaseName(const QString &userAgentDatabaseName)
{
if (userAgentDatabaseName == PRIVACY_BROWSER_DATABASE) return PRIVACY_BROWSER_USER_AGENT; // Privacy Browser.
+ else if (userAgentDatabaseName == WEB_ENGINE_DEFAULT_DATABASE) return BrowserView::webEngineDefaultUserAgent; // WebEngine default.
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.
QString UserAgentHelper::getUserAgentFromTranslatedName(const QString &userAgentTranslatedName)
{
if (userAgentTranslatedName == PRIVACY_BROWSER_TRANSLATED) return PRIVACY_BROWSER_USER_AGENT; // Privacy Browser.
+ else if (userAgentTranslatedName == WEB_ENGINE_DEFAULT_TRANSLATED) return BrowserView::webEngineDefaultUserAgent; // WebEngine default.
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 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.
+ // Return the resulting user agent. If `System default` is selected, it looks up the default user agent from the settings.
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)
+QString UserAgentHelper::getTranslatedUserAgentNameFromDatabaseName(const QString &userAgentName)
{
// Return the translated user agent name.
if (userAgentName == PRIVACY_BROWSER_DATABASE) return PRIVACY_BROWSER_TRANSLATED; // Privacy Browser.
+ else if (userAgentName == WEB_ENGINE_DEFAULT_DATABASE) return WEB_ENGINE_DEFAULT_TRANSLATED; // WebEngine default.
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.
// Add the custom actions.
userAgentPrivacyBrowserActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_privacy_browser"));
+ userAgentWebEngineDefaultActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_webengine_default"));
userAgentFirefoxLinuxActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_firefox_linux"));
userAgentChromiumLinuxActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_chromium_linux"));
userAgentFirefoxWindowsActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_firefox_windows"));
// Add the actions to the groups.
userAgentActionGroupPointer->addAction(userAgentPrivacyBrowserActionPointer);
+ userAgentActionGroupPointer->addAction(userAgentWebEngineDefaultActionPointer);
userAgentActionGroupPointer->addAction(userAgentFirefoxLinuxActionPointer);
userAgentActionGroupPointer->addAction(userAgentChromiumLinuxActionPointer);
userAgentActionGroupPointer->addAction(userAgentFirefoxWindowsActionPointer);
// Set some actions to be checkable.
userAgentPrivacyBrowserActionPointer->setCheckable(true);
+ userAgentWebEngineDefaultActionPointer->setCheckable(true);
userAgentFirefoxLinuxActionPointer->setCheckable(true);
userAgentChromiumLinuxActionPointer->setCheckable(true);
userAgentFirefoxWindowsActionPointer->setCheckable(true);
// Set the non-mutable action text.
userAgentPrivacyBrowserActionPointer->setText(UserAgentHelper::PRIVACY_BROWSER_TRANSLATED);
+ userAgentWebEngineDefaultActionPointer->setText(UserAgentHelper::WEB_ENGINE_DEFAULT_TRANSLATED);
userAgentFirefoxLinuxActionPointer->setText(UserAgentHelper::FIREFOX_LINUX_TRANSLATED);
userAgentChromiumLinuxActionPointer->setText(UserAgentHelper::CHROMIUM_LINUX_TRANSLATED);
userAgentFirefoxWindowsActionPointer->setText(UserAgentHelper::FIREFOX_WINDOWS_TRANSLATED);
// Set the action icons.
userAgentPrivacyBrowserActionPointer->setIcon(QIcon(":/icons/privacy-mode"));
+ userAgentWebEngineDefaultActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("user-group-properties")));
userAgentFirefoxLinuxActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("firefox-esr")));
userAgentChromiumLinuxActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("chromium")));
userAgentFirefoxWindowsActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("firefox-esr")));
// Check the indicated on-the-fly user agent.
if (userAgent == UserAgentHelper::PRIVACY_BROWSER_USER_AGENT) userAgentPrivacyBrowserActionPointer->setChecked(true); // Privacy Browser.
+ else if (userAgent == BrowserView::webEngineDefaultUserAgent) userAgentWebEngineDefaultActionPointer->setChecked(true); // WebEngine default.
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.