Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle SVG branded clients #2844

Merged
merged 4 commits into from
Jan 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion NEXTCLOUD.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ set( APPLICATION_VENDOR "Nextcloud GmbH" )
set( APPLICATION_UPDATE_URL "https://updates.nextcloud.org/client/" CACHE STRING "URL for updater" )
set( APPLICATION_HELP_URL "" CACHE STRING "URL for the help menu" )
set( APPLICATION_ICON_NAME "Nextcloud" )
set( APPLICATION_ICON_SET "SVG" )
set( APPLICATION_SERVER_URL "" CACHE STRING "URL for the server to use. If entered, the UI field will be pre-filled with it" )
set( APPLICATION_SERVER_URL_ENFORCE ON ) # If set and APPLICATION_SERVER_URL is defined, the server can only connect to the pre-defined URL
set( APPLICATION_REV_DOMAIN "com.nextcloud.desktopclient" )
Expand Down Expand Up @@ -35,7 +36,7 @@ option( WITH_PROVIDERS "Build with providers list" ON )
## Theming options
set( APPLICATION_WIZARD_HEADER_BACKGROUND_COLOR "#0082c9" CACHE STRING "Hex color of the wizard header background")
set( APPLICATION_WIZARD_HEADER_TITLE_COLOR "#ffffff" CACHE STRING "Hex color of the text in the wizard header")
option( APPLICATION_WIZARD_USE_CUSTOM_LOGO "Use the logo from ':/client/theme/colored/wizard_logo.png' else the default application icon is used" ON )
option( APPLICATION_WIZARD_USE_CUSTOM_LOGO "Use the logo from ':/client/theme/colored/wizard_logo.(png|svg)' else the default application icon is used" ON )


#
Expand Down
1 change: 1 addition & 0 deletions config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#cmakedefine APPLICATION_UPDATE_URL "@APPLICATION_UPDATE_URL@"
#cmakedefine APPLICATION_HELP_URL "@APPLICATION_HELP_URL@"
#cmakedefine APPLICATION_ICON_NAME "@APPLICATION_ICON_NAME@"
#cmakedefine APPLICATION_ICON_SET "@APPLICATION_ICON_SET@"
#cmakedefine APPLICATION_SERVER_URL "@APPLICATION_SERVER_URL@"
#cmakedefine APPLICATION_SERVER_URL_ENFORCE "@APPLICATION_SERVER_URL_ENFORCE@"
#cmakedefine LINUX_APPLICATION_ID "@LINUX_APPLICATION_ID@"
Expand Down
47 changes: 34 additions & 13 deletions src/libsync/theme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ QUrl imagePathToUrl(const QString &imagePath)
}
}

bool shouldPreferSvg()
{
return QByteArray(APPLICATION_ICON_SET).toUpper() == QByteArrayLiteral("SVG");
}

}

namespace OCC {
Expand Down Expand Up @@ -187,10 +192,11 @@ QIcon Theme::themeIcon(const QString &name, bool sysTray) const
return QPixmap(pixmapName);
};

const auto sizes = isBranded() ? QVector<int>{ 16, 22, 32, 48, 64, 128, 256, 512, 1024 }
: QVector<int>{ 16, 32, 64, 128, 256 };
const auto useSvg = shouldPreferSvg();
const auto sizes = useSvg ? QVector<int>{ 16, 32, 64, 128, 256 }
: QVector<int>{ 16, 22, 32, 48, 64, 128, 256, 512, 1024 };
for (int size : sizes) {
auto px = isBranded() ? loadPixmap(size) : createPixmapFromSvg(size);
auto px = useSvg ? createPixmapFromSvg(size) : loadPixmap(size);
if (px.isNull()) {
continue;
}
Expand Down Expand Up @@ -219,20 +225,25 @@ QIcon Theme::themeIcon(const QString &name, bool sysTray) const
QString Theme::themeImagePath(const QString &name, int size, bool sysTray) const
{
const auto flavor = (!isBranded() && sysTray) ? systrayIconFlavor(_mono) : QLatin1String("colored");
const auto useSvg = shouldPreferSvg();

// branded client may have several sizes of the same icon
const QString filePath = (isBranded() && size > 0)
? QString::fromLatin1(":/client/theme/%1/%2-%3").arg(flavor).arg(name).arg(size)
: QString::fromLatin1(":/client/theme/%1/%2").arg(flavor).arg(name);

const QString brandedImagePath = filePath + ".png";
const QString filePath = (useSvg || size <= 0)
? QString::fromLatin1(":/client/theme/%1/%2").arg(flavor).arg(name)
: QString::fromLatin1(":/client/theme/%1/%2-%3").arg(flavor).arg(name).arg(size);

// only return branded .png image path if it exists, or fall-back to non-branded .svg otherwise
if (isBranded() && QFile::exists(brandedImagePath)) {
return brandedImagePath;
const QString svgPath = filePath + ".svg";
if (useSvg) {
return svgPath;
}

return filePath + ".svg";
const QString pngPath = filePath + ".png";
// Use the SVG as fallback if a PNG is missing so that we get a chance to display something
if (QFile::exists(pngPath)) {
return pngPath;
} else {
return svgPath;
}
}

QIcon Theme::uiThemeIcon(const QString &iconName, bool uiHasDarkBg) const
Expand Down Expand Up @@ -533,7 +544,17 @@ QColor Theme::wizardHeaderBackgroundColor() const
QPixmap Theme::wizardHeaderLogo() const
{
#ifdef APPLICATION_WIZARD_USE_CUSTOM_LOGO
return QPixmap(hidpiFileName(":/client/theme/colored/wizard_logo.png"));
const auto useSvg = shouldPreferSvg();
const auto logoBasePath = QStringLiteral(":/client/theme/colored/wizard_logo");
if (useSvg) {
const auto maxHeight = 64;
const auto maxWidth = 2 * maxHeight;
const auto icon = QIcon(logoBasePath + ".svg");
const auto size = icon.actualSize(QSize(maxWidth, maxHeight));
return icon.pixmap(size);
} else {
return QPixmap(hidpiFileName(logoBasePath + ".png"));
}
#else
return applicationIcon().pixmap(64);
#endif
Expand Down
1 change: 1 addition & 0 deletions theme.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<file>theme/colored/state-sync-256.png</file>
<file>theme/colored/wizard_logo.png</file>
<file>theme/colored/[email protected]</file>
<file>theme/colored/wizard_logo.svg</file>
<file>theme/white/state-error-32.png</file>
<file>theme/white/state-error-64.png</file>
<file>theme/white/state-error-128.png</file>
Expand Down