scaled all downloaded icons to 48x48 to avoid DB size exploding
This commit is contained in:
parent
50a7546f15
commit
6358e8aa0e
@ -149,7 +149,7 @@ QString NetworkFactory::sanitizeUrl(const QString& url) {
|
||||
|
||||
QNetworkReply::NetworkError NetworkFactory::downloadIcon(const QList<QPair<QString, bool>>& urls,
|
||||
int timeout,
|
||||
QIcon& output,
|
||||
QPixmap& output,
|
||||
const QList<QPair<QByteArray, QByteArray>>& additional_headers,
|
||||
const QNetworkProxy& custom_proxy) {
|
||||
QNetworkReply::NetworkError network_result = QNetworkReply::NetworkError::UnknownNetworkError;
|
||||
@ -179,9 +179,12 @@ QNetworkReply::NetworkError NetworkFactory::downloadIcon(const QList<QPair<QStri
|
||||
QPixmap icon_pixmap;
|
||||
|
||||
icon_pixmap.loadFromData(icon_data);
|
||||
output = QIcon(icon_pixmap);
|
||||
output = icon_pixmap;
|
||||
|
||||
if (!output.isNull()) {
|
||||
output = output.scaled(QSize(48, 48),
|
||||
Qt::AspectRatioMode::KeepAspectRatio,
|
||||
Qt::TransformationMode::SmoothTransformation);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -222,9 +225,13 @@ QNetworkReply::NetworkError NetworkFactory::downloadIcon(const QList<QPair<QStri
|
||||
QPixmap icon_pixmap;
|
||||
|
||||
icon_pixmap.loadFromData(icon_data);
|
||||
output = QIcon(icon_pixmap);
|
||||
output = icon_pixmap;
|
||||
|
||||
if (!output.isNull()) {
|
||||
output = output.scaled(QSize(48, 48),
|
||||
Qt::AspectRatioMode::KeepAspectRatio,
|
||||
Qt::TransformationMode::SmoothTransformation);
|
||||
|
||||
return network_result;
|
||||
}
|
||||
}
|
||||
|
@ -43,11 +43,11 @@ class NetworkFactory {
|
||||
static QString networkErrorText(QNetworkReply::NetworkError error_code);
|
||||
static QString sanitizeUrl(const QString& url);
|
||||
|
||||
// Performs SYNCHRONOUS download if favicon for the site,
|
||||
// Performs SYNCHRONOUS favicon download for the site,
|
||||
// given URL belongs to.
|
||||
static QNetworkReply::NetworkError downloadIcon(const QList<QPair<QString, bool>>& urls,
|
||||
int timeout,
|
||||
QIcon& output,
|
||||
QPixmap& output,
|
||||
const QList<QPair<QByteArray, QByteArray>>& additional_headers,
|
||||
const QNetworkProxy& custom_proxy =
|
||||
QNetworkProxy::ProxyType::DefaultProxy);
|
||||
|
@ -562,7 +562,7 @@ RootItem* FeedlyNetwork::decodeCollections(const QByteArray& json,
|
||||
}
|
||||
|
||||
if (obtain_icons) {
|
||||
QIcon icon;
|
||||
QPixmap icon;
|
||||
auto result = NetworkFactory::downloadIcon({{fee_obj[QSL("iconUrl")].toString(), true},
|
||||
{fee_obj[QSL("website")].toString(), false},
|
||||
{fee_obj[QSL("logo")].toString(), true}},
|
||||
|
@ -720,7 +720,7 @@ RootItem* GreaderNetwork::decodeTagsSubscriptions(const QString& categories,
|
||||
|
||||
icon_urls.append({url, false});
|
||||
|
||||
QIcon icon;
|
||||
QPixmap icon;
|
||||
|
||||
if (NetworkFactory::downloadIcon(icon_urls, 1000, icon, {}, proxy) == QNetworkReply::NetworkError::NoError) {
|
||||
feed->setIcon(icon);
|
||||
|
@ -21,8 +21,7 @@
|
||||
|
||||
NewsBlurNetwork::NewsBlurNetwork(QObject* parent)
|
||||
: QObject(parent), m_root(nullptr), m_username(QString()), m_password(QString()), m_baseUrl(QSL(NEWSBLUR_URL)),
|
||||
m_batchSize(NEWSBLUR_DEFAULT_BATCH_SIZE),
|
||||
m_downloadOnlyUnreadMessages(false) {
|
||||
m_batchSize(NEWSBLUR_DEFAULT_BATCH_SIZE), m_downloadOnlyUnreadMessages(false) {
|
||||
clearCredentials();
|
||||
}
|
||||
|
||||
@ -31,9 +30,7 @@ RootItem* NewsBlurNetwork::categoriesFeedsLabelsTree(const QNetworkProxy& proxy)
|
||||
RootItem* root = new RootItem();
|
||||
const auto timeout = qApp->settings()->value(GROUP(Feeds), SETTING(Feeds::UpdateTimeout)).toInt();
|
||||
QMap<QString, RootItem*> cats;
|
||||
QList<QPair<RootItem*, QJsonArray>> cats_array = {
|
||||
{ root, json.object()["folders"].toArray() }
|
||||
};
|
||||
QList<QPair<RootItem*, QJsonArray>> cats_array = {{root, json.object()["folders"].toArray()}};
|
||||
|
||||
while (!cats_array.isEmpty()) {
|
||||
// Add direct descendants as categories to parent, then process their children.
|
||||
@ -54,9 +51,9 @@ RootItem* NewsBlurNetwork::categoriesFeedsLabelsTree(const QNetworkProxy& proxy)
|
||||
QString favicon_url = feed_json["favicon_url"].toString();
|
||||
|
||||
if (!favicon_url.isEmpty()) {
|
||||
QIcon icon;
|
||||
QPixmap icon;
|
||||
|
||||
if (NetworkFactory::downloadIcon({ { favicon_url, true } }, timeout, icon, {}, proxy) ==
|
||||
if (NetworkFactory::downloadIcon({{favicon_url, true}}, timeout, icon, {}, proxy) ==
|
||||
QNetworkReply::NetworkError::NoError) {
|
||||
feed->setIcon(icon);
|
||||
}
|
||||
@ -72,10 +69,7 @@ RootItem* NewsBlurNetwork::categoriesFeedsLabelsTree(const QNetworkProxy& proxy)
|
||||
category->setCustomId(category_name);
|
||||
|
||||
cats_for_parent.first->appendChild(category);
|
||||
cats_array.append({
|
||||
category,
|
||||
var.toObject()[category_name].toArray()
|
||||
});
|
||||
cats_array.append({category, var.toObject()[category_name].toArray()});
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -101,7 +95,8 @@ QJsonDocument NewsBlurNetwork::feeds(const QNetworkProxy& proxy) {
|
||||
proxy);
|
||||
|
||||
if (network_result.m_networkError == QNetworkReply::NetworkError::NoError) {
|
||||
ApiResult res; res.decodeBaseResponse(output);
|
||||
ApiResult res;
|
||||
res.decodeBaseResponse(output);
|
||||
|
||||
return res.m_json;
|
||||
}
|
||||
@ -115,27 +110,29 @@ LoginResult NewsBlurNetwork::login(const QNetworkProxy& proxy) {
|
||||
const auto timeout = qApp->settings()->value(GROUP(Feeds), SETTING(Feeds::UpdateTimeout)).toInt();
|
||||
const QString data = QSL("username=%1&password=%2").arg(m_username, m_password);
|
||||
QByteArray output;
|
||||
auto network_result = NetworkFactory::performNetworkOperation(full_url,
|
||||
timeout,
|
||||
data.toUtf8(),
|
||||
output,
|
||||
QNetworkAccessManager::Operation::PostOperation,
|
||||
{ {
|
||||
QSL(HTTP_HEADERS_CONTENT_TYPE).toLocal8Bit(),
|
||||
QSL("application/x-www-form-urlencoded").toLocal8Bit()
|
||||
} },
|
||||
false,
|
||||
{},
|
||||
{},
|
||||
proxy);
|
||||
auto network_result =
|
||||
NetworkFactory::performNetworkOperation(full_url,
|
||||
timeout,
|
||||
data.toUtf8(),
|
||||
output,
|
||||
QNetworkAccessManager::Operation::PostOperation,
|
||||
{{QSL(HTTP_HEADERS_CONTENT_TYPE).toLocal8Bit(),
|
||||
QSL("application/x-www-form-urlencoded").toLocal8Bit()}},
|
||||
false,
|
||||
{},
|
||||
{},
|
||||
proxy);
|
||||
|
||||
if (network_result.m_networkError == QNetworkReply::NetworkError::NoError) {
|
||||
LoginResult res; res.decodeBaseResponse(output);
|
||||
LoginResult res;
|
||||
res.decodeBaseResponse(output);
|
||||
|
||||
res.m_userId = res.m_json.object()["user_id"].toInt();
|
||||
res.m_sessiodId = boolinq::from(network_result.m_cookies).firstOrDefault([](const QNetworkCookie& c) {
|
||||
return c.name() == QSL(NEWSBLUS_AUTH_COOKIE);
|
||||
}).value();
|
||||
res.m_sessiodId = boolinq::from(network_result.m_cookies)
|
||||
.firstOrDefault([](const QNetworkCookie& c) {
|
||||
return c.name() == QSL(NEWSBLUS_AUTH_COOKIE);
|
||||
})
|
||||
.value();
|
||||
|
||||
return res;
|
||||
}
|
||||
@ -169,8 +166,7 @@ void NewsBlurNetwork::setBaseUrl(const QString& base_url) {
|
||||
}
|
||||
|
||||
QPair<QByteArray, QByteArray> NewsBlurNetwork::authHeader() const {
|
||||
return { QSL("Cookie").toLocal8Bit(),
|
||||
QSL("newsblur_sessionid=%1").arg(m_authSid).toLocal8Bit() };
|
||||
return {QSL("Cookie").toLocal8Bit(), QSL("newsblur_sessionid=%1").arg(m_authSid).toLocal8Bit()};
|
||||
}
|
||||
|
||||
void NewsBlurNetwork::ensureLogin(const QNetworkProxy& proxy) {
|
||||
@ -258,7 +254,7 @@ void ApiResult::decodeBaseResponse(const QByteArray& json_data) {
|
||||
QJsonObject obj_errs = doc.object()["errors"].toObject();
|
||||
|
||||
for (const QString& key : obj_errs.keys()) {
|
||||
for (const QJsonValue& val: obj_errs.value(key).toArray()) {
|
||||
for (const QJsonValue& val : obj_errs.value(key).toArray()) {
|
||||
errs << val.toString();
|
||||
}
|
||||
}
|
||||
|
@ -187,7 +187,7 @@ QList<Feed*> RedditNetworkFactory::subreddits(const QNetworkProxy& custom_proxy)
|
||||
|
||||
new_sub->setPrefixedName(sub_obj["url"].toString());
|
||||
|
||||
QIcon icon;
|
||||
QPixmap icon;
|
||||
QString icon_url = sub_obj["community_icon"].toString();
|
||||
|
||||
if (icon_url.isEmpty()) {
|
||||
|
@ -445,7 +445,7 @@ StandardFeed* StandardFeed::guessFeed(StandardFeed::SourceType source_type,
|
||||
}
|
||||
|
||||
// Try to obtain icon.
|
||||
QIcon icon_data;
|
||||
QPixmap icon_data;
|
||||
|
||||
if (NetworkFactory::downloadIcon(icon_possible_locations, DOWNLOAD_TIMEOUT, icon_data, {}, custom_proxy) ==
|
||||
QNetworkReply::NetworkError::NoError) {
|
||||
|
@ -931,7 +931,7 @@ RootItem* TtRssGetFeedsCategoriesResponse::feedsCategories(TtRssNetworkFactory*
|
||||
if (!icon_path.isEmpty()) {
|
||||
// Chop the "api/" suffix out and append
|
||||
QString full_icon_address = base_address + QL1C('/') + icon_path;
|
||||
QIcon icon;
|
||||
QPixmap icon;
|
||||
QList<QPair<QByteArray, QByteArray>> headers;
|
||||
|
||||
if (network->authIsUsed()) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user