Skip to content

Commit

Permalink
Add branding parameter to disable explorer context menu icons
Browse files Browse the repository at this point in the history
Fixes: #9167
  • Loading branch information
TheOneRing committed Oct 27, 2021
1 parent a707559 commit 79ff417
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 24 deletions.
6 changes: 6 additions & 0 deletions changelog/unreleased/9167
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Enhancement: Add branding option to disable icons in the file explorer

We implemented a branding parameter to disable the display of icons in the
file explorer context menu, this only affects Windows and Linux.

https://github.com/owncloud/client/issues/9167
51 changes: 27 additions & 24 deletions src/gui/socketapi/socketapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -873,33 +873,36 @@ void SocketApi::command_V2_GET_CLIENT_ICON(const QSharedPointer<SocketApiJobV2>
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)
Expand Down
5 changes: 5 additions & 0 deletions src/libsync/theme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -678,4 +678,9 @@ bool Theme::connectionValidatorClearCookies() const
return false;
}

bool Theme::enableSocketApiIconSupport() const
{
return true;
}

} // end namespace client
7 changes: 7 additions & 0 deletions src/libsync/theme.h
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,13 @@ class OWNCLOUDSYNC_EXPORT Theme : public QObject
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;
Expand Down

0 comments on commit 79ff417

Please sign in to comment.