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>
<content_rating type="oars-1.1" />
<releases>
<release version="4.0.2" date="2021-09-16"/>
<release version="4.0.2" date="2021-09-17"/>
</releases>
<content_rating type="oars-1.0">
<content_attribute id="violence-cartoon">none</content_attribute>

View File

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

View File

@ -56,7 +56,7 @@ class TtRssGetFeedsCategoriesResponse : public TtRssResponse {
// Returns tree of feeds/categories.
// Top-level root of the tree is not needed here.
// 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;

View File

@ -276,7 +276,7 @@ RootItem* TtRssServiceRoot::obtainNewTreeForSyncIn() const {
TtRssGetLabelsResponse labels = m_network->getLabels(networkProxy());
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);
lblroot->setChildItems(labels.labels());