fix ttrss icons

This commit is contained in:
Martin Rotter 2021-09-17 08:12:21 +02:00
parent f42c372c17
commit e3dd1acd5f
4 changed files with 15 additions and 17 deletions

View File

@ -26,7 +26,7 @@
<url type="donation">https://github.com/sponsors/martinrotter</url> <url type="donation">https://github.com/sponsors/martinrotter</url>
<content_rating type="oars-1.1" /> <content_rating type="oars-1.1" />
<releases> <releases>
<release version="4.0.2" date="2021-09-16"/> <release version="4.0.2" date="2021-09-17"/>
</releases> </releases>
<content_rating type="oars-1.0"> <content_rating type="oars-1.0">
<content_attribute id="violence-cartoon">none</content_attribute> <content_attribute id="violence-cartoon">none</content_attribute>

View File

@ -677,17 +677,16 @@ TtRssGetFeedsCategoriesResponse::TtRssGetFeedsCategoriesResponse(const QString&
TtRssGetFeedsCategoriesResponse::~TtRssGetFeedsCategoriesResponse() = default; TtRssGetFeedsCategoriesResponse::~TtRssGetFeedsCategoriesResponse() = default;
RootItem* TtRssGetFeedsCategoriesResponse::feedsCategories(bool obtain_icons, QString base_address) const { RootItem* TtRssGetFeedsCategoriesResponse::feedsCategories(bool obtain_icons, const QNetworkProxy& proxy, const QString& base_address) const {
auto* parent = new RootItem(); auto* parent = new RootItem();
// Chop the "api/" from the end of the address. // Chop the "api/" from the end of the address.
base_address.chop(4); qDebug("TT-RSS: Base address to '%s' to get feed icons.", qPrintable(base_address));
qDebug("TT-RSS: Chopped base address to '%s' to get feed icons.", qPrintable(base_address));
if (status() == TTRSS_API_STATUS_OK) { if (status() == TTRSS_API_STATUS_OK) {
// We have data, construct object tree according to data. // We have data, construct object tree according to data.
QJsonArray items_to_process = m_rawContent[QSL("content")].toObject()[QSL("categories")].toObject()[QSL("items")].toArray(); QJsonArray items_to_process = m_rawContent[QSL("content")].toObject()[QSL("categories")].toObject()[QSL("items")].toArray();
QVector<QPair<RootItem*, QJsonValue>> pairs; QVector<QPair<RootItem*, QJsonValue>> pairs; pairs.reserve(items_to_process.size());
for (const QJsonValue& item : items_to_process) { for (const QJsonValue& item : items_to_process) {
pairs.append(QPair<RootItem*, QJsonValue>(parent, item)); pairs.append(QPair<RootItem*, QJsonValue>(parent, item));
@ -697,7 +696,7 @@ RootItem* TtRssGetFeedsCategoriesResponse::feedsCategories(bool obtain_icons, QS
QPair<RootItem*, QJsonValue> pair = pairs.takeFirst(); QPair<RootItem*, QJsonValue> pair = pairs.takeFirst();
RootItem* act_parent = pair.first; RootItem* act_parent = pair.first;
QJsonObject item = pair.second.toObject(); QJsonObject item = pair.second.toObject();
int item_id = item["bare_id"].toInt(); int item_id = item[QSL("bare_id")].toInt();
bool is_category = item.contains(QSL("type")) && item[QSL("type")].toString() == QSL(TTRSS_GFT_TYPE_CATEGORY); bool is_category = item.contains(QSL("type")) && item[QSL("type")].toString() == QSL(TTRSS_GFT_TYPE_CATEGORY);
if (item_id >= 0) { if (item_id >= 0) {
@ -732,22 +731,21 @@ RootItem* TtRssGetFeedsCategoriesResponse::feedsCategories(bool obtain_icons, QS
// We have feed. // We have feed.
auto* feed = new TtRssFeed(); auto* feed = new TtRssFeed();
IOFactory::writeFile("aa.json", QJsonDocument(item).toJson());
if (obtain_icons) { if (obtain_icons) {
QString icon_path = item[QSL("icon")].type() == QJsonValue::String ? item[QSL("icon")].toString() : QString(); QString icon_path = item[QSL("icon")].type() == QJsonValue::String ? item[QSL("icon")].toString() : QString();
if (!icon_path.isEmpty()) { if (!icon_path.isEmpty()) {
// Chop the "api/" suffix out and append // Chop the "api/" suffix out and append
QString full_icon_address = base_address + QL1C('/') + icon_path; QString full_icon_address = base_address + QL1C('/') + icon_path;
QByteArray icon_data; QIcon icon;
if (NetworkFactory::performNetworkOperation(full_icon_address, DOWNLOAD_TIMEOUT, if (NetworkFactory::downloadIcon({ { full_icon_address, true } },
QByteArray(), icon_data, DOWNLOAD_TIMEOUT,
QNetworkAccessManager::GetOperation).first == QNetworkReply::NoError) { icon,
// Icon downloaded, set it up. proxy) == QNetworkReply::NoError) {
QPixmap icon_pixmap; feed->setIcon(icon);
icon_pixmap.loadFromData(icon_data);
feed->setIcon(QIcon(icon_pixmap));
} }
} }
} }

View File

@ -56,7 +56,7 @@ class TtRssGetFeedsCategoriesResponse : public TtRssResponse {
// Returns tree of feeds/categories. // Returns tree of feeds/categories.
// Top-level root of the tree is not needed here. // Top-level root of the tree is not needed here.
// Returned items do not have primary IDs assigned. // Returned items do not have primary IDs assigned.
RootItem* feedsCategories(bool obtain_icons, QString base_address = QString()) const; RootItem* feedsCategories(bool obtain_icons, const QNetworkProxy& proxy, const QString& base_address = QString()) const;
}; };
class ServiceRoot; class ServiceRoot;

View File

@ -276,7 +276,7 @@ RootItem* TtRssServiceRoot::obtainNewTreeForSyncIn() const {
TtRssGetLabelsResponse labels = m_network->getLabels(networkProxy()); TtRssGetLabelsResponse labels = m_network->getLabels(networkProxy());
if (m_network->lastError() == QNetworkReply::NoError) { if (m_network->lastError() == QNetworkReply::NoError) {
auto* tree = feed_cats.feedsCategories(true, m_network->url()); auto* tree = feed_cats.feedsCategories(true, networkProxy(), m_network->url());
auto* lblroot = new LabelsNode(tree); auto* lblroot = new LabelsNode(tree);
lblroot->setChildItems(labels.labels()); lblroot->setChildItems(labels.labels());