Skip to content

Commit

Permalink
Fix for 'Remove All entries from this domain' on history item
Browse files Browse the repository at this point in the history
  • Loading branch information
fnkkio committed Nov 13, 2019
1 parent a3c73ca commit 8b5ab42
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
24 changes: 24 additions & 0 deletions src/core/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/core/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ QString elideText(const QString &text, const QFontMetrics &fontMetrics, QWidget
QString substitutePlaceholders(QString text, const QHash<QString, QString> &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);
Expand Down
9 changes: 7 additions & 2 deletions src/modules/windows/history/HistoryContentsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<quint64> entries;

for (int i = 0; i < m_model->rowCount(); ++i)
Expand All @@ -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());
}
Expand Down

0 comments on commit 8b5ab42

Please sign in to comment.