From f4b371e8f0e03240e7720a9f75ddae5774402ac6 Mon Sep 17 00:00:00 2001 From: Juraj Oravec Date: Wed, 11 Dec 2024 00:18:09 +0100 Subject: [PATCH] UserAgentDialog: Use QUrl::host on user URL input The system internally works with QUrl::host to compare the visited and stored addresses to set UserAgent. BUG: 497223 Signed-off-by: Juraj Oravec --- src/lib/app/profilemanager.cpp | 28 +++++++++++++++++++++++++ src/lib/preferences/useragentdialog.cpp | 5 +++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/lib/app/profilemanager.cpp b/src/lib/app/profilemanager.cpp index aa083c0f8..8bbf3b547 100644 --- a/src/lib/app/profilemanager.cpp +++ b/src/lib/app/profilemanager.cpp @@ -220,6 +220,34 @@ void ProfileManager::updateProfile(const QString ¤t, const QString &profil if (prof < Updater::Version(QStringLiteral("3.1.99"))) { return; } + + if (prof < Updater::Version(QStringLiteral("25.03.80"))) { + QSettings settings(DataPaths::currentProfilePath() + QLatin1String("/settings.ini"), QSettings::IniFormat); + + settings.beginGroup(QSL("User-Agent-Settings")); + QStringList domainList = settings.value(QSL("DomainList"), QStringList()).toStringList(); + QStringList userAgentsList = settings.value(QSL("UserAgentsList"), QStringList()).toStringList(); + + if (domainList.count() == userAgentsList.count()) { + QStringList modifiedDomainList; + QStringList modifiedUserAgentsList; + + for (int i = 0; i < domainList.count(); ++i) { + QString host = QUrl(domainList.at(i)).host(); + if (!host.isEmpty()) { + modifiedDomainList.append(host); + modifiedUserAgentsList.append(userAgentsList.at(i)); + } + } + + settings.setValue(QSL("DomainList"), modifiedDomainList); + settings.setValue(QSL("UserAgentsList"), modifiedUserAgentsList); + settings.endGroup(); + settings.sync(); + + qInfo() << "ProfileManager: Updated UserAgent per domain settings"; + } + } } void ProfileManager::copyDataToProfile() diff --git a/src/lib/preferences/useragentdialog.cpp b/src/lib/preferences/useragentdialog.cpp index 9bf44b4da..50c72e4cc 100644 --- a/src/lib/preferences/useragentdialog.cpp +++ b/src/lib/preferences/useragentdialog.cpp @@ -26,6 +26,7 @@ #include #include #include +#include UserAgentDialog::UserAgentDialog(QWidget* parent) : QDialog(parent) @@ -97,7 +98,7 @@ void UserAgentDialog::addSite() QString userAgent; if (showEditDialog(tr("Add new site"), &site, &userAgent)) { - auto* siteItem = new QTableWidgetItem(site); + auto* siteItem = new QTableWidgetItem(QUrl(site).host()); auto* userAgentItem = new QTableWidgetItem(userAgent); int row = ui->table->rowCount(); @@ -135,7 +136,7 @@ void UserAgentDialog::editSite() QString userAgent = userAgentItem->text(); if (showEditDialog(tr("Edit site"), &site, &userAgent)) { - siteItem->setText(site); + siteItem->setText(QUrl(site).host()); userAgentItem->setText(userAgent); } }