From 2b70834dd15c16b2b34efcc3952c5238419581da Mon Sep 17 00:00:00 2001 From: Hannah von Reth Date: Wed, 27 Oct 2021 11:05:14 +0200 Subject: Add branding parameter to disable explorer context menu icons Fixes: #9167 --- src/gui/socketapi/socketapi.cpp | 51 ++++++++++++++++++++++------------------- src/libsync/theme.cpp | 5 ++++ src/libsync/theme.h | 7 ++++++ 3 files changed, 39 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/gui/socketapi/socketapi.cpp b/src/gui/socketapi/socketapi.cpp index ed9eb036e..97b3b4bb5 100644 --- a/src/gui/socketapi/socketapi.cpp +++ b/src/gui/socketapi/socketapi.cpp @@ -873,33 +873,36 @@ void SocketApi::command_V2_GET_CLIENT_ICON(const QSharedPointer return; } + QByteArray data; const Theme *theme = Theme::instance(); - OC_ASSERT(theme); - const QIcon appIcon = theme->applicationIcon(); - qCDebug(lcSocketApi) << Q_FUNC_INFO << " got icon from theme: " << appIcon; - - // convert to pixmap (might be smaller if size is not available) - const QPixmap pixmap = appIcon.pixmap(QSize(size.toInt(), size.toInt())); - - // Convert pixmap to in-memory PNG - QByteArray png; - QBuffer pngBuffer(&png); - auto success = pngBuffer.open(QIODevice::WriteOnly); - if (!success) { - qCWarning(lcSocketApi) << "Error opening buffer for png in " << Q_FUNC_INFO; - job->failure(QStringLiteral("cannot get client icon")); - return; - } + // return an empty answer if the end point was disabled + if (theme->enableSocketApiIconSupport()) { + const QIcon appIcon = theme->applicationIcon(); + qCDebug(lcSocketApi) << Q_FUNC_INFO << " got icon from theme: " << appIcon; + + // convert to pixmap (might be smaller if size is not available) + const QPixmap pixmap = appIcon.pixmap(QSize(size.toInt(), size.toInt())); + + // Convert pixmap to in-memory PNG + QByteArray png; + QBuffer pngBuffer(&png); + auto success = pngBuffer.open(QIODevice::WriteOnly); + if (!success) { + qCWarning(lcSocketApi) << "Error opening buffer for png in " << Q_FUNC_INFO; + job->failure(QStringLiteral("cannot get client icon")); + return; + } - success = pixmap.save(&pngBuffer, "PNG"); - if (!success) { - qCWarning(lcSocketApi) << "Error saving client icon as png in " << Q_FUNC_INFO; - job->failure(QStringLiteral("cannot get client icon")); - return; - } + success = pixmap.save(&pngBuffer, "PNG"); + if (!success) { + qCWarning(lcSocketApi) << "Error saving client icon as png in " << Q_FUNC_INFO; + job->failure(QStringLiteral("cannot get client icon")); + return; + } - const QByteArray pngAsBase64 = pngBuffer.data().toBase64(); - job->success({ { QStringLiteral("png"), QString::fromUtf8(pngAsBase64) } }); + data = pngBuffer.data().toBase64(); + } + job->success({ { QStringLiteral("png"), QString::fromUtf8(data) } }); } void SocketApi::emailPrivateLink(const QString &link) diff --git a/src/libsync/theme.cpp b/src/libsync/theme.cpp index dca5280b8..b75beb36c 100644 --- a/src/libsync/theme.cpp +++ b/src/libsync/theme.cpp @@ -678,4 +678,9 @@ bool Theme::connectionValidatorClearCookies() const return false; } +bool Theme::enableSocketApiIconSupport() const +{ + return true; +} + } // end namespace client diff --git a/src/libsync/theme.h b/src/libsync/theme.h index ff1c5d4c4..13e19bb0a 100644 --- a/src/libsync/theme.h +++ b/src/libsync/theme.h @@ -428,6 +428,13 @@ public: virtual bool connectionValidatorClearCookies() const; + /** + * Enables the response of V2/GET_CLIENT_ICON, default true. + * See #9167 + */ + virtual bool enableSocketApiIconSupport() const; + + protected: #ifndef TOKEN_AUTH_ONLY QIcon themeUniversalIcon(const QString &name, IconType iconType = IconType::BrandedIcon) const; -- cgit v1.2.3