Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/2.7' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
TheOneRing committed Jan 25, 2021
2 parents ba9b01d + 1186fd5 commit 45f9d7f
Show file tree
Hide file tree
Showing 10 changed files with 144 additions and 60 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/8390
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Bugfix: Fix wrong option provided to OIDC

We fixed a bug where we passed a wrong value to the OIDC display parameter

https://github.com/owncloud/client/issues/8390
30 changes: 21 additions & 9 deletions cmake/modules/OCGenerateTheme.cmake
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
function(__addIcon THEME ICON_NAME)
set(icon "theme/${THEME}/${ICON_NAME}.svg")
set(options)
set(oneValueArgs SRC_PATH)
set(multiValueArgs)
cmake_parse_arguments(_ICON "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

if(NOT _ICON_SRC_PATH)
set(_ICON_SRC_PATH ${THEME})
endif()

set(icon "theme/${_ICON_SRC_PATH}/${ICON_NAME}.svg")
set(iconAlias "theme/${THEME}/${ICON_NAME}.svg")
if (EXISTS ${OEM_THEME_DIR}/${icon})
file(APPEND "${QRC}" "<file alias=\"${icon}\">${OEM_THEME_DIR}/${icon}</file>\n")
file(APPEND "${QRC}" "<file alias=\"${iconAlias}\">${OEM_THEME_DIR}/${icon}</file>\n")
else()
set(icon "theme/${THEME}/${ICON_NAME}.png")
set(icon "theme/${_ICON_SRC_PATH}/${ICON_NAME}.png")
set(iconAlias "theme/${THEME}/${ICON_NAME}.png")
if (EXISTS ${OEM_THEME_DIR}/${icon})
file(APPEND "${QRC}" "<file alias=\"${icon}\">${OEM_THEME_DIR}/${icon}</file>\n")
file(APPEND "${QRC}" "<file alias=\"${iconAlias}\">${OEM_THEME_DIR}/${icon}</file>\n")
else()
set(SIZES "16;22,32;48;64;128;256;512;1024")
set(SIZES "16;22;32;48;64;128;256;512;1024")
foreach(size ${SIZES})
set(icon "theme/${THEME}/${ICON_NAME}-${size}.png")
set(icon "theme/${_ICON_SRC_PATH}/${ICON_NAME}-${size}.png")
set(iconAlias "theme/${THEME}/${ICON_NAME}-${size}.png")
if (EXISTS ${OEM_THEME_DIR}/${icon})
file(APPEND "${QRC}" "<file alias=\"${icon}\">${OEM_THEME_DIR}/${icon}</file>\n")
file(APPEND "${QRC}" "<file alias=\"${iconAlias}\">${OEM_THEME_DIR}/${icon}</file>\n")
endif()
endforeach()
endif()
Expand All @@ -22,8 +34,8 @@ function(generate_theme TARGET)
if(NOT "${OEM_THEME_DIR}" STREQUAL "${PROJECT_SOURCE_DIR}")
set(QRC ${CMAKE_BINARY_DIR}/theme.qrc)
file(WRITE "${QRC}" "<RCC>\n<qresource prefix=\"/client/${APPLICATION_SHORTNAME}\">\n")
__addIcon("colored" "${APPLICATION_ICON_NAME}-icon")
__addIcon("colored" "wizard_logo")
__addIcon("universal" "${APPLICATION_ICON_NAME}-icon" SRC_PATH "colored")
__addIcon("universal" "wizard_logo" SRC_PATH "colored")

set(STATES "ok;error;information;offline;pause;sync")
set(THEMES "colored;dark;black;white")
Expand Down
6 changes: 3 additions & 3 deletions core_theme.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@
<file alias="theme/black/state-offline.svg">theme/black/ui-light-plain-monochrom-state-offline.svg</file>
<file alias="theme/black/state-pause.svg">theme/black/ui-light-plain-monochrom-state-pause.svg</file>
<file alias="theme/black/state-sync.svg">theme/black/ui-light-plain-monochrom-state-sync.svg</file>
<file>theme/colored/owncloud-icon.svg</file>
<file>theme/colored/oc-image-about.svg</file>
<file alias="theme/colored/state-ok.svg">theme/colored/ui-light-plain-color-state-checkmark.svg</file>
<file alias="theme/colored/state-error.svg">theme/colored/ui-light-plain-color-state-error.svg</file>
<file alias="theme/colored/state-information.svg">theme/colored/ui-light-plain-color-state-info.svg</file>
<file alias="theme/colored/state-offline.svg">theme/colored/ui-light-plain-color-state-offline.svg</file>
<file alias="theme/colored/state-pause.svg">theme/colored/ui-light-plain-color-state-pause.svg</file>
<file alias="theme/colored/state-sync.svg">theme/colored/ui-light-plain-color-state-sync.svg</file>
<file>theme/colored/wizard_logo.svg</file>
<file alias="theme/dark/state-ok.svg">theme/dark/ui-dark-plain-color-state-checkmark.svg</file>
<file alias="theme/dark/state-error.svg">theme/dark/ui-dark-plain-color-state-error.svg</file>
<file alias="theme/dark/state-information.svg">theme/dark/ui-dark-plain-color-state-info.svg</file>
<file alias="theme/dark/state-offline.svg">theme/dark/ui-dark-plain-color-state-offline.svg</file>
<file alias="theme/dark/state-pause.svg">theme/dark/ui-dark-plain-color-state-pause.svg</file>
<file alias="theme/dark/state-sync.svg">theme/dark/ui-dark-plain-color-state-sync.svg</file>
<file>theme/universal/oc-image-about.svg</file>
<file>theme/universal/owncloud-icon.svg</file>
<file>theme/universal/wizard_logo.svg</file>
<file alias="theme/white/state-ok.svg">theme/white/ui-dark-plain-monochrom-state-checkmark.svg</file>
<file alias="theme/white/state-error.svg">theme/white/ui-dark-plain-monochrom-state-error.svg</file>
<file alias="theme/white/state-information.svg">theme/white/ui-dark-plain-monochrom-state-info.svg</file>
Expand Down
3 changes: 1 addition & 2 deletions src/libsync/creds/oauth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,7 @@ QUrl OAuth::authorisationLink() const
{ QStringLiteral("code_challenge_method"), QStringLiteral("S256") },
{ QStringLiteral("scope"), Theme::instance()->openIdConnectScopes() },
{ QStringLiteral("prompt"), Theme::instance()->openIdConnectPrompt() },
{ QStringLiteral("state"), QString::fromUtf8(_state) },
{ QStringLiteral("display"), Theme::instance()->appNameGUI() } });
{ QStringLiteral("state"), QString::fromUtf8(_state) } });

if (!_account->davUser().isNull()) {
const QString davUser = _account->davUser().replace(QLatin1Char('+'), QStringLiteral("%2B")); // Issue #7762;
Expand Down
4 changes: 2 additions & 2 deletions src/libsync/owncloudtheme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ QColor ownCloudTheme::wizardHeaderSubTitleColor() const

QIcon ownCloudTheme::wizardHeaderLogo() const
{
return themeIcon(QStringLiteral("wizard_logo"), false, false, Theme::IconType::BrandedIcon);
return themeUniversalIcon(QStringLiteral("wizard_logo"));
}

QIcon ownCloudTheme::aboutIcon() const
{
return QIcon(QStringLiteral(":/client/ownCloud/theme/colored/oc-image-about.svg"));
return themeUniversalIcon(QStringLiteral("oc-image-about"));
}

#endif
Expand Down
129 changes: 91 additions & 38 deletions src/libsync/theme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,41 @@
#endif

namespace {
QString vanillaThemePath()
{
return QStringLiteral(":/client/ownCloud/theme");
}

QString brandThemePath()
{
return QStringLiteral(":/client/" APPLICATION_SHORTNAME "/theme");
}

QString darkTheme()
{
return QStringLiteral("dark");
}

QString coloredTheme()
{
return QStringLiteral("colored");
}

QString whiteTheme()
{
return QStringLiteral("white");
}

QString blackTheme()
{
return QStringLiteral("black");
}

constexpr bool strings_equal(char const *a, char const *b)
{
return *a == *b && (*a == '\0' || strings_equal(a + 1, b + 1));
}

constexpr bool isVanilla()
{
// TODO: c++17 stringview
Expand All @@ -56,8 +87,6 @@ Theme *Theme::instance()
{
if (!_instance) {
_instance = new THEME_CLASS;
// some themes may not call the base ctor
_instance->_mono = false;
}
return _instance;
}
Expand Down Expand Up @@ -129,39 +158,56 @@ QString Theme::configFileName() const

QIcon Theme::applicationIcon() const
{
return themeIcon(QStringLiteral(APPLICATION_ICON_NAME "-icon"));
return themeUniversalIcon(QStringLiteral(APPLICATION_ICON_NAME "-icon"));
}

QIcon Theme::aboutIcon() const
{
return applicationIcon();
}

bool Theme::isUsingDarkTheme(IconType type) const
bool Theme::isUsingDarkTheme() const
{
if (!_hasDarkColoredTheme && type != IconType::VanillaIcon) {
return false;
}
return QPalette().base().color().lightnessF() <= 0.5;
//TODO: replace by a command line switch
static bool forceDark = qEnvironmentVariableIntValue("OWNCLOUD_FORCE_DARK_MODE") != 0;
return forceDark || QPalette().base().color().lightnessF() <= 0.5;
}

bool Theme::allowDarkTheme() const
{
return _hasBrandedColored == _hasBrandedDark;
}


QIcon Theme::themeUniversalIcon(const QString &name, Theme::IconType iconType) const
{
return loadIcon(QStringLiteral("universal"), name, iconType);
}

QIcon Theme::themeTrayIcon(const QString &name, bool sysTrayMenuVisible, IconType iconType) const
{
auto icon = loadIcon(systrayIconFlavor(_mono, sysTrayMenuVisible), name, iconType);
#ifdef Q_OS_MAC
// This defines the icon as a template and enables automatic macOS color handling
// See https://bugreports.qt.io/browse/QTBUG-42109
icon.setIsMask(_mono && !sysTrayMenuVisible);
#endif
return icon;
}

QIcon Theme::themeIcon(const QString &name, Theme::IconType iconType) const
{
return loadIcon((isUsingDarkTheme() && allowDarkTheme()) ? darkTheme() : coloredTheme(), name, iconType);
}
/*
* helper to load a icon from either the icon theme the desktop provides or from
* the apps Qt resources.
*/
QIcon Theme::themeIcon(const QString &name, bool sysTray, bool sysTrayMenuVisible, IconType iconType) const
QIcon Theme::loadIcon(const QString &flavor, const QString &name, IconType iconType) const
{
// prevent recusion
const bool useCoreIcon = (iconType == IconType::VanillaIcon) || isVanilla();
QString flavor;
if (sysTray) {
flavor = systrayIconFlavor(_mono, sysTrayMenuVisible);
} else {
if (isUsingDarkTheme(iconType)) {
flavor = QStringLiteral("dark");
} else {
flavor = QStringLiteral("colored");
}
}
const QString path = useCoreIcon ? QStringLiteral(":/client/ownCloud/theme") : QStringLiteral(":/client/%1/theme").arg(appName());
const QString path = useCoreIcon ? vanillaThemePath() : brandThemePath();
const QString key = name + QLatin1Char(',') + flavor;
QIcon &cached = _iconCache[key]; // Take reference, this will also "set" the cache entry
if (cached.isNull()) {
Expand Down Expand Up @@ -189,38 +235,36 @@ QIcon Theme::themeIcon(const QString &name, bool sysTray, bool sysTrayMenuVisibl
} else if (size >= 128) {
if (!previousIcon.isEmpty()) {
qWarning() << "Upsacling:" << previousIcon << "to" << size;
cached.addPixmap(QPixmap(previousIcon).scaled({ size, size }, Qt::KeepAspectRatio));
cached.addPixmap(QPixmap(previousIcon).scaled({ size, size }, Qt::KeepAspectRatio, Qt::SmoothTransformation));
}
}
}
}
if (cached.isNull()) {
if (!useCoreIcon && iconType == IconType::BrandedIconWithFallbackToVanillaIcon) {
return themeIcon(name, sysTray, sysTrayMenuVisible, IconType::VanillaIcon);
return loadIcon(flavor, name, IconType::VanillaIcon);
}
qWarning() << "Failed to locate the icon" << name;
}

#ifdef Q_OS_MAC
// This defines the icon as a template and enables automatic macOS color handling
// See https://bugreports.qt.io/browse/QTBUG-42109
cached.setIsMask(_mono && sysTray && !sysTrayMenuVisible);
#endif

return cached;
}

bool Theme::hasTheme(const QString &theme)
bool Theme::hasTheme(IconType type, const QString &theme) const
{
return QFileInfo(QStringLiteral(":/client/" APPLICATION_SHORTNAME "/theme/%1/").arg(theme)).isDir();
const auto key = qMakePair(type != IconType::VanillaIcon, theme);
auto it = _themeCache.constFind(key);
if (it == _themeCache.cend()) {
return _themeCache[key] = QFileInfo(QStringLiteral("%1/%2/").arg(type == IconType::VanillaIcon ? vanillaThemePath() : brandThemePath(), theme)).isDir();
}
return it.value();
}

QString Theme::systrayIconFlavor(bool mono, bool sysTrayMenuVisible) const
{
Q_UNUSED(sysTrayMenuVisible)
QString flavor;
if (mono) {
flavor = Utility::hasDarkSystray() ? QStringLiteral("white") : QStringLiteral("black");
flavor = Utility::hasDarkSystray() ? whiteTheme() : blackTheme();

#ifdef Q_OS_MAC
if (sysTrayMenuVisible) {
Expand All @@ -229,7 +273,7 @@ QString Theme::systrayIconFlavor(bool mono, bool sysTrayMenuVisible) const
#endif
} else {
// we have a dark sys tray and the theme has support for that
flavor = (Utility::hasDarkSystray() && _hasDarkColoredTheme) ? QStringLiteral("dark") : QStringLiteral("colored");
flavor = (Utility::hasDarkSystray() && allowDarkTheme()) ? darkTheme() : coloredTheme();
}
return flavor;
}
Expand All @@ -238,7 +282,6 @@ QString Theme::systrayIconFlavor(bool mono, bool sysTrayMenuVisible) const

Theme::Theme()
: QObject(nullptr)
, _mono(false)
{
}

Expand Down Expand Up @@ -303,7 +346,9 @@ bool Theme::systrayUseMonoIcons() const

bool Theme::monoIconsAvailable() const
{
return hasTheme(systrayIconFlavor(true));
// mono icons are only supported in vanilla and if a customer provides them
// no fallback to vanilla
return hasTheme(IconType::BrandedIcon, systrayIconFlavor(true));
}

QString Theme::updateCheckUrl() const
Expand Down Expand Up @@ -472,8 +517,11 @@ QIcon Theme::syncStateIcon(SyncResult::Status status, bool sysTray, bool sysTray
default:
statusIcon = QStringLiteral("state-error");
}

return themeIcon(statusIcon, sysTray, sysTrayMenuVisible);
if (sysTray) {
return themeTrayIcon(statusIcon, sysTrayMenuVisible);
} else {
return themeIcon(statusIcon);
}
}

QIcon Theme::folderDisabledIcon() const
Expand All @@ -483,7 +531,12 @@ QIcon Theme::folderDisabledIcon() const

QIcon Theme::folderOfflineIcon(bool sysTray, bool sysTrayMenuVisible) const
{
return themeIcon(QLatin1String("state-offline"), sysTray, sysTrayMenuVisible);
const auto statusIcon = QLatin1String("state-offline");
if (sysTray) {
return themeTrayIcon(statusIcon, sysTrayMenuVisible);
} else {
return themeIcon(statusIcon);
}
}

QColor Theme::wizardHeaderTitleColor() const
Expand Down
27 changes: 21 additions & 6 deletions src/libsync/theme.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ class OWNCLOUDSYNC_EXPORT Theme : public QObject
BrandedIconWithFallbackToVanillaIcon,
VanillaIcon
};

/**
* get an sync state icon
*/
Expand All @@ -118,7 +119,12 @@ class OWNCLOUDSYNC_EXPORT Theme : public QObject
* Whether use the dark icon theme
* The function also ensures the theme supports the dark theme
*/
bool isUsingDarkTheme(IconType fallbackType = IconType::BrandedIcon) const;
bool isUsingDarkTheme() const;

/**
* Whether the branding allows the dark theme
*/
bool allowDarkTheme() const;
#endif

virtual QString statusHeaderText(SyncResult::Status) const;
Expand Down Expand Up @@ -408,8 +414,9 @@ class OWNCLOUDSYNC_EXPORT Theme : public QObject

protected:
#ifndef TOKEN_AUTH_ONLY
QIcon themeIcon(const QString &name, bool sysTray = false, bool sysTrayMenuVisible = false, IconType iconType = IconType::BrandedIconWithFallbackToVanillaIcon) const;
static bool hasTheme(const QString &theme);
QIcon themeUniversalIcon(const QString &name, IconType iconType = IconType::BrandedIcon) const;
QIcon themeTrayIcon(const QString &name, bool sysTrayMenuVisible = false, IconType iconType = IconType::BrandedIconWithFallbackToVanillaIcon) const;
QIcon themeIcon(const QString &name, IconType iconType = IconType::BrandedIconWithFallbackToVanillaIcon) const;
#endif
Theme();

Expand All @@ -420,11 +427,19 @@ class OWNCLOUDSYNC_EXPORT Theme : public QObject
Theme(Theme const &);
Theme &operator=(Theme const &);

QIcon loadIcon(const QString &flavor, const QString &name, IconType iconType) const;
// whether or not a theme is available
bool hasTheme(IconType type, const QString &theme) const;

static Theme *_instance;
bool _mono;
bool _mono = false;
#ifndef TOKEN_AUTH_ONLY
bool _hasDarkColoredTheme = hasTheme(QStringLiteral("dark"));
mutable QHash<QString, QIcon> _iconCache;
mutable QMap<QString, QIcon> _iconCache;
// <<is vanilla, theme name>, bool
// caches the availability of themes for branded and unbranded themes
mutable QMap<QPair<bool, QString>, bool> _themeCache;
const bool _hasBrandedColored = hasTheme(IconType::BrandedIcon, QStringLiteral("colored"));
const bool _hasBrandedDark = hasTheme(IconType::BrandedIcon, QStringLiteral("dark"));
#endif
};
}
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes

0 comments on commit 45f9d7f

Please sign in to comment.