mirror of
https://github.com/martinrotter/rssguard.git
synced 2025-02-07 12:53:40 +01:00
Fix for icon loading.
This commit is contained in:
parent
9356766d24
commit
7ebf8c6e8c
@ -7,6 +7,7 @@ Added:
|
|||||||
|
|
||||||
Fixed:
|
Fixed:
|
||||||
<ul>
|
<ul>
|
||||||
|
<li>Enhanced downloading of feed icons. Now combines Google API along with the actual links obtained from feed XMLs.</li>
|
||||||
<li>Fixed restarting issues. (issue #109)</li>
|
<li>Fixed restarting issues. (issue #109)</li>
|
||||||
<li>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)</li>
|
<li>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)</li>
|
||||||
<li>Fixed solarized skin. (issue #111)</li>
|
<li>Fixed solarized skin. (issue #111)</li>
|
||||||
|
@ -146,16 +146,6 @@ QPair<FeedsModelFeed*, QNetworkReply::NetworkError> FeedsModelFeed::guessFeed(co
|
|||||||
const QString &password) {
|
const QString &password) {
|
||||||
QPair<FeedsModelFeed*, QNetworkReply::NetworkError> result; result.first = NULL;
|
QPair<FeedsModelFeed*, QNetworkReply::NetworkError> 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;
|
QByteArray feed_contents;
|
||||||
NetworkResult network_result = NetworkFactory::downloadFeedFile(url,
|
NetworkResult network_result = NetworkFactory::downloadFeedFile(url,
|
||||||
qApp->settings()->value(GROUP(Feeds),
|
qApp->settings()->value(GROUP(Feeds),
|
||||||
@ -223,6 +213,9 @@ QPair<FeedsModelFeed*, QNetworkReply::NetworkError> FeedsModelFeed::guessFeed(co
|
|||||||
|
|
||||||
QDomElement root_element = xml_document.documentElement();
|
QDomElement root_element = xml_document.documentElement();
|
||||||
QString root_tag_name = root_element.tagName();
|
QString root_tag_name = root_element.tagName();
|
||||||
|
QList<QString> icon_possible_locations;
|
||||||
|
|
||||||
|
icon_possible_locations.append(url);
|
||||||
|
|
||||||
if (root_tag_name == "rdf:RDF") {
|
if (root_tag_name == "rdf:RDF") {
|
||||||
// We found RDF feed.
|
// We found RDF feed.
|
||||||
@ -231,6 +224,12 @@ QPair<FeedsModelFeed*, QNetworkReply::NetworkError> FeedsModelFeed::guessFeed(co
|
|||||||
result.first->setType(Rdf);
|
result.first->setType(Rdf);
|
||||||
result.first->setTitle(channel_element.namedItem("title").toElement().text());
|
result.first->setTitle(channel_element.namedItem("title").toElement().text());
|
||||||
result.first->setDescription(channel_element.namedItem("description").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") {
|
else if (root_tag_name == "rss") {
|
||||||
// We found RSS 0.91/0.92/0.93/2.0/2.0.1 feed.
|
// We found RSS 0.91/0.92/0.93/2.0/2.0.1 feed.
|
||||||
@ -247,18 +246,41 @@ QPair<FeedsModelFeed*, QNetworkReply::NetworkError> FeedsModelFeed::guessFeed(co
|
|||||||
|
|
||||||
result.first->setTitle(channel_element.namedItem("title").toElement().text());
|
result.first->setTitle(channel_element.namedItem("title").toElement().text());
|
||||||
result.first->setDescription(channel_element.namedItem("description").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") {
|
else if (root_tag_name == "feed") {
|
||||||
// We found ATOM feed.
|
// We found ATOM feed.
|
||||||
result.first->setType(Atom10);
|
result.first->setType(Atom10);
|
||||||
result.first->setTitle(root_element.namedItem("title").toElement().text());
|
result.first->setTitle(root_element.namedItem("title").toElement().text());
|
||||||
result.first->setDescription(root_element.namedItem("subtitle").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 {
|
else {
|
||||||
// File was downloaded and it really was XML file
|
// File was downloaded and it really was XML file
|
||||||
// but feed format was NOT recognized.
|
// but feed format was NOT recognized.
|
||||||
result.second = QNetworkReply::UnknownContentError;
|
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;
|
return result;
|
||||||
|
@ -119,19 +119,24 @@ QString NetworkFactory::networkErrorText(QNetworkReply::NetworkError error_code)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QNetworkReply::NetworkError NetworkFactory::downloadIcon(const QString &url, int timeout, QIcon &output) {
|
QNetworkReply::NetworkError NetworkFactory::downloadIcon(const QList<QString> &urls, int timeout, QIcon &output) {
|
||||||
#if QT_VERSION >= 0x050000
|
QNetworkReply::NetworkError network_result;
|
||||||
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;
|
|
||||||
|
|
||||||
if (network_result == QNetworkReply::NoError) {
|
foreach (const QString &url, urls) {
|
||||||
QPixmap icon_pixmap;
|
#if QT_VERSION >= 0x050000
|
||||||
icon_pixmap.loadFromData(icon_data);
|
QString google_s2_with_url = QString("http://www.google.com/s2/favicons?domain=%1").arg(url.toHtmlEscaped());
|
||||||
output = QIcon(icon_pixmap);
|
#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;
|
return network_result;
|
||||||
|
@ -41,7 +41,7 @@ class NetworkFactory {
|
|||||||
|
|
||||||
// Performs SYNCHRONOUS download if favicon for the site,
|
// Performs SYNCHRONOUS download if favicon for the site,
|
||||||
// given URL belongs to.
|
// given URL belongs to.
|
||||||
static QNetworkReply::NetworkError downloadIcon(const QString &url, int timeout, QIcon &output);
|
static QNetworkReply::NetworkError downloadIcon(const QList<QString> &urls, int timeout, QIcon &output);
|
||||||
|
|
||||||
static NetworkResult downloadFeedFile(const QString &url, int timeout, QByteArray &output,
|
static NetworkResult downloadFeedFile(const QString &url, int timeout, QByteArray &output,
|
||||||
bool protected_contents = false, const QString &username = QString(),
|
bool protected_contents = false, const QString &username = QString(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user