1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-19 18:26:34 +01:00

SiteSettings: Store more details about url

Store protocol, port, host.

Signed-off-by: Juraj Oravec <jurajoravec@mailo.com>
This commit is contained in:
Juraj Oravec 2024-07-14 07:31:13 +02:00
parent 061672798b
commit bbe03cf9c2
Signed by: SGOrava
GPG Key ID: 13660A3F1D9F093B
4 changed files with 31 additions and 13 deletions

View File

@ -413,7 +413,9 @@ void ProfileManager::updateDatabase()
for (auto [feature, settingName] : html5SettingPairs.asKeyValueRange()) { for (auto [feature, settingName] : html5SettingPairs.asKeyValueRange()) {
auto const serverList = settings.value(settingName + suflix, QStringList()).toStringList(); auto const serverList = settings.value(settingName + suflix, QStringList()).toStringList();
for (const auto &server : serverList) { for (const auto &serverUrl : serverList) {
const auto server = SiteSettingsManager::adjustUrl(QUrl(serverUrl));
if (!siteSettings.contains(server)) { if (!siteSettings.contains(server)) {
siteSettings[server] = SiteSettingsManager::SiteSettings(); siteSettings[server] = SiteSettingsManager::SiteSettings();
for (auto [f, nameUnused] : html5SettingPairs.asKeyValueRange()) { for (auto [f, nameUnused] : html5SettingPairs.asKeyValueRange()) {
@ -438,7 +440,8 @@ void ProfileManager::updateDatabase()
auto loadCookiesSettings = [&](const QString &listName, const SiteSettingsManager::Permission permission) { auto loadCookiesSettings = [&](const QString &listName, const SiteSettingsManager::Permission permission) {
auto const serverList = settings.value(listName, QStringList()).toStringList(); auto const serverList = settings.value(listName, QStringList()).toStringList();
for (const auto &server : serverList) { for (const auto &serverUrl : serverList) {
const auto server = SiteSettingsManager::adjustUrl(QUrl(serverUrl));
if (!siteSettings.contains(server)) { if (!siteSettings.contains(server)) {
siteSettings[server] = SiteSettingsManager::SiteSettings(); siteSettings[server] = SiteSettingsManager::SiteSettings();
} }

View File

@ -377,7 +377,7 @@ void SiteInfo::saveSiteSettings()
siteSettings.AllowCookies = item->permission(); siteSettings.AllowCookies = item->permission();
siteSettings.ZoomLevel = -1; siteSettings.ZoomLevel = -1;
siteSettings.server = m_baseUrl.host(); siteSettings.server = mApp->siteSettingsManager()->adjustUrl(m_baseUrl);
auto storedSiteSettings = mApp->siteSettingsManager()->getSiteSettings(m_baseUrl); auto storedSiteSettings = mApp->siteSettingsManager()->getSiteSettings(m_baseUrl);

View File

@ -95,7 +95,7 @@ void SiteSettingsManager::saveSettings()
QHash<QWebEngineSettings::WebAttribute, bool> SiteSettingsManager::getWebAttributes(const QUrl& url) QHash<QWebEngineSettings::WebAttribute, bool> SiteSettingsManager::getWebAttributes(const QUrl& url)
{ {
QHash<QWebEngineSettings::WebAttribute, bool> attributes; QHash<QWebEngineSettings::WebAttribute, bool> attributes;
QString host = url.host(); QString host = adjustUrl(url);
if (host.isEmpty()) { if (host.isEmpty()) {
for (int i = 0; i < supportedAttribute.size(); ++i) { for (int i = 0; i < supportedAttribute.size(); ++i) {
@ -133,7 +133,7 @@ QHash<QWebEngineSettings::WebAttribute, bool> SiteSettingsManager::getWebAttribu
void SiteSettingsManager::setOption(const QString& column, const QUrl& url, const int value) void SiteSettingsManager::setOption(const QString& column, const QUrl& url, const int value)
{ {
QString host = url.host(); QString host = adjustUrl(url);
if (column.isEmpty() || host.isEmpty()) { if (column.isEmpty() || host.isEmpty()) {
return; return;
@ -208,22 +208,22 @@ SiteSettingsManager::Permission SiteSettingsManager::getPermission(const QWebEng
SiteSettingsManager::Permission SiteSettingsManager::getPermission(const QString &column, const QUrl& url) SiteSettingsManager::Permission SiteSettingsManager::getPermission(const QString &column, const QUrl& url)
{ {
return getPermission(column, url.host()); return getPermission(column, adjustUrl(url));
} }
SiteSettingsManager::Permission SiteSettingsManager::getPermission(const SiteSettingsManager::PageOptions option, const QUrl& url) SiteSettingsManager::Permission SiteSettingsManager::getPermission(const SiteSettingsManager::PageOptions option, const QUrl& url)
{ {
return getPermission(optionToSqlColumn(option), url.host()); return getPermission(optionToSqlColumn(option), adjustUrl(url));
} }
SiteSettingsManager::Permission SiteSettingsManager::getPermission(const QWebEnginePage::Feature feature, const QUrl& url) SiteSettingsManager::Permission SiteSettingsManager::getPermission(const QWebEnginePage::Feature feature, const QUrl& url)
{ {
return getPermission(featureToSqlColumn(feature), url.host()); return getPermission(featureToSqlColumn(feature), adjustUrl(url));
} }
SiteSettingsManager::Permission SiteSettingsManager::getPermission(const QWebEngineSettings::WebAttribute attribute, const QUrl& url) SiteSettingsManager::Permission SiteSettingsManager::getPermission(const QWebEngineSettings::WebAttribute attribute, const QUrl& url)
{ {
return getPermission(webAttributeToSqlColumn(attribute), url.host()); return getPermission(webAttributeToSqlColumn(attribute), adjustUrl(url));
} }
SiteSettingsManager::Permission SiteSettingsManager::getDefaultPermission(const SiteSettingsManager::PageOptions option) SiteSettingsManager::Permission SiteSettingsManager::getDefaultPermission(const SiteSettingsManager::PageOptions option)
@ -464,9 +464,9 @@ QList<QWebEnginePage::Feature> SiteSettingsManager::getSupportedFeatures() const
SiteSettingsManager::SiteSettings SiteSettingsManager::getSiteSettings(QUrl& url) SiteSettingsManager::SiteSettings SiteSettingsManager::getSiteSettings(QUrl& url)
{ {
SiteSettings siteSettings; SiteSettings siteSettings;
siteSettings.server = url.host(); siteSettings.server = adjustUrl(url);
if (url.isEmpty()) { if (url.isEmpty() || siteSettings.server.isEmpty()) {
return siteSettings; return siteSettings;
} }
@ -474,7 +474,7 @@ SiteSettingsManager::SiteSettings SiteSettingsManager::getSiteSettings(QUrl& url
QSqlQuery query(SqlDatabase::instance()->database()); QSqlQuery query(SqlDatabase::instance()->database());
query.prepare(everythingSql.arg(sqlTable())); query.prepare(everythingSql.arg(sqlTable()));
query.addBindValue(url.host()); query.addBindValue(siteSettings.server);
query.exec(); query.exec();
if (query.next()) { if (query.next()) {
@ -623,4 +623,17 @@ void SiteSettingsManager::prepareSqls() {
everythingUpdateSql.append(QSL("=? ")); everythingUpdateSql.append(QSL("=? "));
everythingUpdateSql.append(QSL(" WHERE server=?")); everythingUpdateSql.append(QSL(" WHERE server=?"));
} }
QString SiteSettingsManager::adjustUrl(const QUrl url)
{
QUrl urlAdjusted = url.adjusted(
QUrl::RemoveUserInfo
| QUrl::RemovePath
| QUrl::RemoveQuery
| QUrl::RemoveFragment
| QUrl::StripTrailingSlash
);
return urlAdjusted.toString();
}

View File

@ -119,6 +119,8 @@ public:
QString sqlTable(); QString sqlTable();
Permission intToPermission(const int permission) const; Permission intToPermission(const int permission) const;
static QString adjustUrl(const QUrl url);
private: private:
void prepareSqls(); void prepareSqls();