diff --git a/resources/text/CHANGELOG b/resources/text/CHANGELOG
index fd4d35f9a..dacf3461f 100644
--- a/resources/text/CHANGELOG
+++ b/resources/text/CHANGELOG
@@ -7,6 +7,7 @@ Added:
Fixed:
+- Enhanced downloading of feed icons. Now combines Google API along with the actual links obtained from feed XMLs.
- Fixed restarting issues. (issue #109)
- Target directory settings is now used for all kinds of downloading + when prompt for each download destination is set, then previously used folder is saved. (issue #108)
- Fixed solarized skin. (issue #111)
diff --git a/src/core/feedsmodelfeed.cpp b/src/core/feedsmodelfeed.cpp
index 24dad4413..58754f6e7 100755
--- a/src/core/feedsmodelfeed.cpp
+++ b/src/core/feedsmodelfeed.cpp
@@ -146,16 +146,6 @@ QPair FeedsModelFeed::guessFeed(co
const QString &password) {
QPair result; result.first = NULL;
- // Try to obtain icon.
- QIcon icon_data;
-
- if ((result.second = NetworkFactory::downloadIcon(url, 5000, icon_data)) ==
- QNetworkReply::NoError) {
- // Icon for feed was downloaded and is stored now in _icon_data.
- result.first = new FeedsModelFeed();
- result.first->setIcon(icon_data);
- }
-
QByteArray feed_contents;
NetworkResult network_result = NetworkFactory::downloadFeedFile(url,
qApp->settings()->value(GROUP(Feeds),
@@ -223,6 +213,9 @@ QPair FeedsModelFeed::guessFeed(co
QDomElement root_element = xml_document.documentElement();
QString root_tag_name = root_element.tagName();
+ QList icon_possible_locations;
+
+ icon_possible_locations.append(url);
if (root_tag_name == "rdf:RDF") {
// We found RDF feed.
@@ -231,6 +224,12 @@ QPair FeedsModelFeed::guessFeed(co
result.first->setType(Rdf);
result.first->setTitle(channel_element.namedItem("title").toElement().text());
result.first->setDescription(channel_element.namedItem("description").toElement().text());
+
+ QString source_link = channel_element.namedItem("link").toElement().text();
+
+ if (!source_link.isEmpty()) {
+ icon_possible_locations.prepend(source_link);
+ }
}
else if (root_tag_name == "rss") {
// We found RSS 0.91/0.92/0.93/2.0/2.0.1 feed.
@@ -247,18 +246,41 @@ QPair FeedsModelFeed::guessFeed(co
result.first->setTitle(channel_element.namedItem("title").toElement().text());
result.first->setDescription(channel_element.namedItem("description").toElement().text());
+
+ QString source_link = channel_element.namedItem("link").toElement().text();
+
+ if (!source_link.isEmpty()) {
+ icon_possible_locations.prepend(source_link);
+ }
}
else if (root_tag_name == "feed") {
// We found ATOM feed.
result.first->setType(Atom10);
result.first->setTitle(root_element.namedItem("title").toElement().text());
result.first->setDescription(root_element.namedItem("subtitle").toElement().text());
+
+ QString source_link = root_element.namedItem("link").toElement().text();
+
+ if (!source_link.isEmpty()) {
+ icon_possible_locations.prepend(source_link);
+ }
}
else {
// File was downloaded and it really was XML file
// but feed format was NOT recognized.
result.second = QNetworkReply::UnknownContentError;
}
+
+ // Try to obtain icon.
+ QIcon icon_data;
+
+ if ((result.second = NetworkFactory::downloadIcon(icon_possible_locations,
+ DOWNLOAD_TIMEOUT,
+ icon_data)) == QNetworkReply::NoError) {
+ // Icon for feed was downloaded and is stored now in _icon_data.
+ result.first = new FeedsModelFeed();
+ result.first->setIcon(icon_data);
+ }
}
return result;
diff --git a/src/network-web/networkfactory.cpp b/src/network-web/networkfactory.cpp
index 43bed7b90..26fe108df 100755
--- a/src/network-web/networkfactory.cpp
+++ b/src/network-web/networkfactory.cpp
@@ -119,19 +119,24 @@ QString NetworkFactory::networkErrorText(QNetworkReply::NetworkError error_code)
}
}
-QNetworkReply::NetworkError NetworkFactory::downloadIcon(const QString &url, int timeout, QIcon &output) {
-#if QT_VERSION >= 0x050000
- QString google_s2_with_url = QString("http://www.google.com/s2/favicons?domain=%1").arg(url.toHtmlEscaped());
-#else
- QString google_s2_with_url = QString("http://www.google.com/s2/favicons?domain=%1").arg(Qt::escape(url));
-#endif
- QByteArray icon_data;
- QNetworkReply::NetworkError network_result = downloadFile(google_s2_with_url, timeout, icon_data).first;
+QNetworkReply::NetworkError NetworkFactory::downloadIcon(const QList &urls, int timeout, QIcon &output) {
+ QNetworkReply::NetworkError network_result;
- if (network_result == QNetworkReply::NoError) {
- QPixmap icon_pixmap;
- icon_pixmap.loadFromData(icon_data);
- output = QIcon(icon_pixmap);
+ foreach (const QString &url, urls) {
+#if QT_VERSION >= 0x050000
+ QString google_s2_with_url = QString("http://www.google.com/s2/favicons?domain=%1").arg(url.toHtmlEscaped());
+#else
+ QString google_s2_with_url = QString("http://www.google.com/s2/favicons?domain=%1").arg(Qt::escape(url));
+#endif
+ QByteArray icon_data;
+ network_result = downloadFile(google_s2_with_url, timeout, icon_data).first;
+
+ if (network_result == QNetworkReply::NoError) {
+ QPixmap icon_pixmap;
+ icon_pixmap.loadFromData(icon_data);
+ output = QIcon(icon_pixmap);
+ break;
+ }
}
return network_result;
diff --git a/src/network-web/networkfactory.h b/src/network-web/networkfactory.h
index 6cf8bd1fd..8d11e2a08 100644
--- a/src/network-web/networkfactory.h
+++ b/src/network-web/networkfactory.h
@@ -41,7 +41,7 @@ class NetworkFactory {
// Performs SYNCHRONOUS download if favicon for the site,
// given URL belongs to.
- static QNetworkReply::NetworkError downloadIcon(const QString &url, int timeout, QIcon &output);
+ static QNetworkReply::NetworkError downloadIcon(const QList &urls, int timeout, QIcon &output);
static NetworkResult downloadFeedFile(const QString &url, int timeout, QByteArray &output,
bool protected_contents = false, const QString &username = QString(),