Made changes to streamline icon downloading process

This commit is contained in:
Jonathan White 2019-04-16 20:14:10 -04:00
parent 12e020b7c2
commit 42d34a1999
3 changed files with 23 additions and 22 deletions

View file

@ -195,7 +195,7 @@ QPixmap Metadata::customIconScaledPixmap(const QUuid& uuid) const
QPixmapCache::Key& cacheKey = m_customIconScaledCacheKeys[uuid]; QPixmapCache::Key& cacheKey = m_customIconScaledCacheKeys[uuid];
if (!QPixmapCache::find(cacheKey, &pixmap)) { if (!QPixmapCache::find(cacheKey, &pixmap)) {
QImage image = m_customIcons.value(uuid).scaled(16, 16, Qt::KeepAspectRatio, Qt::SmoothTransformation); QImage image = m_customIcons.value(uuid).scaled(16, 16, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
pixmap = QPixmap::fromImage(image); pixmap = QPixmap::fromImage(image);
cacheKey = QPixmapCache::insert(pixmap); cacheKey = QPixmapCache::insert(pixmap);
} }

View file

@ -212,7 +212,7 @@
<item> <item>
<widget class="QCheckBox" name="fallbackToSearch"> <widget class="QCheckBox" name="fallbackToSearch">
<property name="text"> <property name="text">
<string>Use DuckDuckGo to download website icons</string> <string>Use DuckDuckGo service to download website icons</string>
</property> </property>
</widget> </widget>
</item> </item>

View file

@ -197,8 +197,6 @@ void EditWidgetIcons::downloadFavicon()
QString fullyQualifiedDomain = m_url.host(); QString fullyQualifiedDomain = m_url.host();
m_urlsToTry.append(QUrl(m_url.scheme() + "://" + fullyQualifiedDomain + "/favicon.ico"));
// Determine if host portion of URL is an IP address by resolving it and // Determine if host portion of URL is an IP address by resolving it and
// searching for a match with the returned address(es). // searching for a match with the returned address(es).
bool hostIsIp = false; bool hostIsIp = false;
@ -209,32 +207,35 @@ void EditWidgetIcons::downloadFavicon()
} }
} }
// Determine the second-level domain, if available
QString secondLevelDomain;
if (!hostIsIp) { if (!hostIsIp) {
QString secondLevelDomain = getSecondLevelDomain(m_url); secondLevelDomain = getSecondLevelDomain(m_url);
// Attempt to simply load the favicon.ico file
if (fullyQualifiedDomain != secondLevelDomain) {
m_urlsToTry.append(QUrl(m_url.scheme() + "://" + secondLevelDomain + "/favicon.ico"));
}
} }
// Try to use alternative fallback URL, if enabled // Start with the "fallback" url (if enabled) to try to get the best favicon
if (config()->get("security/IconDownloadFallback", false).toBool()) { if (config()->get("security/IconDownloadFallback", false).toBool()) {
QUrl fallbackUrl = QUrl("https://icons.duckduckgo.com"); QUrl fallbackUrl = QUrl("https://icons.duckduckgo.com");
fallbackUrl.setPath("/ip3/" + QUrl::toPercentEncoding(fullyQualifiedDomain) + ".ico"); fallbackUrl.setPath("/ip3/" + QUrl::toPercentEncoding(fullyQualifiedDomain) + ".ico");
m_urlsToTry.append(fallbackUrl);
if (!hostIsIp) { // Also try a direct pull of the second-level domain (if possible)
QString secondLevelDomain = getSecondLevelDomain(m_url); if (!hostIsIp && fullyQualifiedDomain != secondLevelDomain) {
fallbackUrl.setPath("/ip3/" + QUrl::toPercentEncoding(secondLevelDomain) + ".ico");
if (fullyQualifiedDomain != secondLevelDomain) { m_urlsToTry.append(fallbackUrl);
fallbackUrl.setPath("/ip3/" + QUrl::toPercentEncoding(secondLevelDomain) + ".ico");
m_urlsToTry.prepend(fallbackUrl);
}
} }
m_urlsToTry.prepend(fallbackUrl);
} }
// Add a direct pull of the website's own favicon.ico file
m_urlsToTry.append(QUrl(m_url.scheme() + "://" + fullyQualifiedDomain + "/favicon.ico"));
// Also try a direct pull of the second-level domain (if possible)
if (!hostIsIp && fullyQualifiedDomain != secondLevelDomain) {
m_urlsToTry.append(QUrl(m_url.scheme() + "://" + secondLevelDomain + "/favicon.ico"));
}
// Use the first URL to start the download process
// If a favicon is not found, the next URL will be tried
startFetchFavicon(m_urlsToTry.takeFirst()); startFetchFavicon(m_urlsToTry.takeFirst());
#endif #endif
} }
@ -277,7 +278,7 @@ void EditWidgetIcons::fetchFinished()
if (!image.isNull()) { if (!image.isNull()) {
if (!addCustomIcon(image)) { if (!addCustomIcon(image)) {
emit messageEditEntry(tr("Custom icon already exists"), MessageWidget::Information); emit messageEditEntry(tr("Custom icon already exists"), MessageWidget::Information);
} else if (!this->isVisible()) { } else if (!isVisible()) {
// Show confirmation message if triggered from Entry tab download button // Show confirmation message if triggered from Entry tab download button
emit messageEditEntry(tr("Custom icon successfully downloaded"), MessageWidget::Positive); emit messageEditEntry(tr("Custom icon successfully downloaded"), MessageWidget::Positive);
} }
@ -289,7 +290,7 @@ void EditWidgetIcons::fetchFinished()
if (!fallbackEnabled) { if (!fallbackEnabled) {
emit messageEditEntry( emit messageEditEntry(
tr("Unable to fetch favicon.") + "\n" tr("Unable to fetch favicon.") + "\n"
+ tr("Hint: You can enable DuckDuckGo as a fallback under Tools>Settings>Security"), + tr("You can enable the DuckDuckGo website icon service under Tools -> Settings -> Security"),
MessageWidget::Error); MessageWidget::Error);
} else { } else {
emit messageEditEntry(tr("Unable to fetch favicon."), MessageWidget::Error); emit messageEditEntry(tr("Unable to fetch favicon."), MessageWidget::Error);