From 8b5ab42b2499e028c580c68c5a613bfa7fed1ed8 Mon Sep 17 00:00:00 2001 From: Stefan Comanescu Date: Wed, 13 Nov 2019 08:58:23 +0200 Subject: [PATCH] Fix for 'Remove All entries from this domain' on history item --- src/core/Utils.cpp | 24 +++++++++++++++++++ src/core/Utils.h | 1 + .../windows/history/HistoryContentsWidget.cpp | 9 +++++-- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/core/Utils.cpp b/src/core/Utils.cpp index 437f8f2211..30d362f1ac 100644 --- a/src/core/Utils.cpp +++ b/src/core/Utils.cpp @@ -399,6 +399,30 @@ QString extractHost(const QUrl &url) return (url.isLocalFile() ? QLatin1String("localhost") : url.host()); } +QString extractDomainName(const QUrl &url) +{ + if (!url.isValid()) + { + return {}; + } + + const QString host = url.host(); + if (host.isEmpty()) + { + return {}; + } + + const QString tld = url.topLevelDomain(); + if (tld.isEmpty()) + { + return {}; + } + + const int domainStartIdx = host.lastIndexOf('.', (-1 * tld.size()) - 1) + 1; + + return host.mid(domainStartIdx); +} + QString formatElapsedTime(int value) { if (value < 0) diff --git a/src/core/Utils.h b/src/core/Utils.h index a03f2d9f3d..74ba80fb65 100644 --- a/src/core/Utils.h +++ b/src/core/Utils.h @@ -100,6 +100,7 @@ QString elideText(const QString &text, const QFontMetrics &fontMetrics, QWidget QString substitutePlaceholders(QString text, const QHash &placeholders); QString savePixmapAsDataUri(const QPixmap &pixmap); QString extractHost(const QUrl &url); +QString extractDomainName(const QUrl &url); QString formatElapsedTime(int value); QString formatDateTime(const QDateTime &dateTime, QString format = {}, bool allowFancy = true); QString formatUnit(qint64 value, bool isSpeed = false, int precision = 1, bool appendRaw = false); diff --git a/src/modules/windows/history/HistoryContentsWidget.cpp b/src/modules/windows/history/HistoryContentsWidget.cpp index 48b88c07a3..b5a3358530 100644 --- a/src/modules/windows/history/HistoryContentsWidget.cpp +++ b/src/modules/windows/history/HistoryContentsWidget.cpp @@ -187,7 +187,12 @@ void HistoryContentsWidget::removeDomainEntries() return; } - const QString host(QUrl(domainItem->text()).host()); + const QString domain(Utils::extractDomainName(QUrl(domainItem->text()))); + if (domain.isEmpty()) + { + return; + } + QVector entries; for (int i = 0; i < m_model->rowCount(); ++i) @@ -203,7 +208,7 @@ void HistoryContentsWidget::removeDomainEntries() { const QStandardItem *entryItem(groupItem->child(j, 0)); - if (entryItem && host == QUrl(entryItem->text()).host()) + if (entryItem && domain == Utils::extractDomainName(QUrl(entryItem->text()))) { entries.append(entryItem->data(IdentifierRole).toULongLong()); }