From e7fcf1550ffc2d413424595c990e7bd652300318 Mon Sep 17 00:00:00 2001 From: Jyrki Gadinger Date: Wed, 25 Mar 2026 16:04:42 +0100 Subject: [PATCH 1/5] refactor(asyncimageresponse): use Qt::StringLiterals Signed-off-by: Jyrki Gadinger --- src/gui/tray/asyncimageresponse.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/gui/tray/asyncimageresponse.cpp b/src/gui/tray/asyncimageresponse.cpp index 26965619ab79f..cddc6700eabb4 100644 --- a/src/gui/tray/asyncimageresponse.cpp +++ b/src/gui/tray/asyncimageresponse.cpp @@ -11,6 +11,8 @@ #include "accountmanager.h" +using namespace Qt::StringLiterals; + AsyncImageResponse::AsyncImageResponse(const QString &id, const QSize &requestedSize) { if (id.isEmpty()) { @@ -19,7 +21,7 @@ AsyncImageResponse::AsyncImageResponse(const QString &id, const QSize &requested } auto actualId = id; - const auto idSplit = id.split(QStringLiteral("/"), Qt::SkipEmptyParts); + const auto idSplit = id.split('/'_L1, Qt::SkipEmptyParts); const auto color = QColor(idSplit.last()); if(color.isValid()) { @@ -27,7 +29,7 @@ AsyncImageResponse::AsyncImageResponse(const QString &id, const QSize &requested actualId.remove("/" % idSplit.last()); } - _imagePaths = actualId.split(QLatin1Char(';'), Qt::SkipEmptyParts); + _imagePaths = actualId.split(';'_L1, Qt::SkipEmptyParts); _requestedImageSize = requestedSize; if (_imagePaths.isEmpty()) { @@ -56,10 +58,10 @@ void AsyncImageResponse::processNextImage() } const auto imagePath = _imagePaths.at(_index); - if (imagePath.startsWith(QStringLiteral(":/client"))) { + if (imagePath.startsWith(u":/client"_s)) { setImageAndEmitFinished(QIcon(imagePath).pixmap(_requestedImageSize).toImage()); return; - } else if (imagePath.startsWith(QStringLiteral(":/fileicon"))) { + } else if (imagePath.startsWith(u":/fileicon"_s)) { const auto filePath = imagePath.mid(10); const auto fileInfo = QFileInfo(filePath); setImageAndEmitFinished(_fileIconProvider.icon(fileInfo).pixmap(_requestedImageSize).toImage()); @@ -83,7 +85,7 @@ void AsyncImageResponse::processNextImage() // for some reason trying to use `accountInRequestedServer` causes clang 21 to crash for me :( const auto accountQnam = accountInRequestedServer->networkAccessManager(); QMetaObject::invokeMethod(accountQnam, [this, accountInRequestedServer, iconUrl]() -> void { - const auto reply = accountInRequestedServer->sendRawRequest(QByteArrayLiteral("GET"), iconUrl); + const auto reply = accountInRequestedServer->sendRawRequest("GET"_ba, iconUrl); connect(reply, &QNetworkReply::finished, this, [this, reply]() -> void { QMetaObject::invokeMethod(this, [this, reply]() -> void { processNetworkReply(reply); @@ -109,10 +111,10 @@ void AsyncImageResponse::processNetworkReply(QNetworkReply *reply) const QByteArray imageData = reply->readAll(); // server returns "[]" for some some file previews (have no idea why), so, we use another image // from the list if available - if (imageData.isEmpty() || imageData == QByteArrayLiteral("[]")) { + if (imageData.isEmpty() || imageData == "[]"_ba) { processNextImage(); } else { - if (imageData.startsWith(QByteArrayLiteral(" Date: Wed, 25 Mar 2026 16:06:24 +0100 Subject: [PATCH 2/5] refactor(asyncimageresponse): use early returns where possible Signed-off-by: Jyrki Gadinger --- src/gui/tray/asyncimageresponse.cpp | 58 +++++++++++++++-------------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/src/gui/tray/asyncimageresponse.cpp b/src/gui/tray/asyncimageresponse.cpp index cddc6700eabb4..c25c37c7b9e8a 100644 --- a/src/gui/tray/asyncimageresponse.cpp +++ b/src/gui/tray/asyncimageresponse.cpp @@ -113,34 +113,36 @@ void AsyncImageResponse::processNetworkReply(QNetworkReply *reply) // from the list if available if (imageData.isEmpty() || imageData == "[]"_ba) { processNextImage(); - } else { - if (imageData.startsWith(" Date: Wed, 25 Mar 2026 16:31:35 +0100 Subject: [PATCH 3/5] fix(asyncimageresponse): enhance check for received SVG response Some SVG files do not start with ` --- src/gui/tray/asyncimageresponse.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/gui/tray/asyncimageresponse.cpp b/src/gui/tray/asyncimageresponse.cpp index c25c37c7b9e8a..3a514d2111e2f 100644 --- a/src/gui/tray/asyncimageresponse.cpp +++ b/src/gui/tray/asyncimageresponse.cpp @@ -116,7 +116,12 @@ void AsyncImageResponse::processNetworkReply(QNetworkReply *reply) return; } - if (!imageData.startsWith("header(QNetworkRequest::ContentTypeHeader); + !(contentTypeHeader.toString().startsWith("image/svg"_ba) || imageData.first(qMin(imageData.size(), 512)).contains(" Date: Wed, 25 Mar 2026 16:38:03 +0100 Subject: [PATCH 4/5] fix(asyncimageresponse): scale QImage to requested size this may cause an infinite re-request loop if the layout does not match Signed-off-by: Jyrki Gadinger --- src/gui/tray/asyncimageresponse.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/tray/asyncimageresponse.cpp b/src/gui/tray/asyncimageresponse.cpp index 3a514d2111e2f..034639fcde6db 100644 --- a/src/gui/tray/asyncimageresponse.cpp +++ b/src/gui/tray/asyncimageresponse.cpp @@ -122,7 +122,7 @@ void AsyncImageResponse::processNetworkReply(QNetworkReply *reply) if (const auto contentTypeHeader = reply->header(QNetworkRequest::ContentTypeHeader); !(contentTypeHeader.toString().startsWith("image/svg"_ba) || imageData.first(qMin(imageData.size(), 512)).contains(" Date: Thu, 26 Mar 2026 13:25:31 +0100 Subject: [PATCH 5/5] refactor(asyncimageresponse): use QMimeDatabase for SVG check Signed-off-by: Jyrki Gadinger --- src/gui/tray/asyncimageresponse.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/gui/tray/asyncimageresponse.cpp b/src/gui/tray/asyncimageresponse.cpp index 034639fcde6db..875a2d16eb755 100644 --- a/src/gui/tray/asyncimageresponse.cpp +++ b/src/gui/tray/asyncimageresponse.cpp @@ -6,6 +6,7 @@ #include "asyncimageresponse.h" #include +#include #include #include @@ -116,11 +117,10 @@ void AsyncImageResponse::processNetworkReply(QNetworkReply *reply) return; } - // check whether the reply might be an SVG by looking at the content type and the first 512 bytes of the response for `header(QNetworkRequest::ContentTypeHeader); - !(contentTypeHeader.toString().startsWith("image/svg"_ba) || imageData.first(qMin(imageData.size(), 512)).contains("