Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/owncloud/client.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHannah von Reth <hannah.vonreth@owncloud.com>2021-01-22 14:42:21 +0300
committerHannah von Reth <vonreth@kde.org>2021-01-25 17:51:45 +0300
commit2e87750c678689c7e843864b6d832a869e651dfa (patch)
treefad7d47b7d0fc57aa0edbff02cad56ba32e73dc2 /src
parentd6dc2abef6e90449ead6d37a872a620e90d54298 (diff)
Fix detection of availability of icon branding
Diffstat (limited to 'src')
-rw-r--r--src/gui/guiutility.cpp2
-rw-r--r--src/libsync/owncloudtheme.cpp4
-rw-r--r--src/libsync/theme.cpp87
-rw-r--r--src/libsync/theme.h28
4 files changed, 72 insertions, 49 deletions
diff --git a/src/gui/guiutility.cpp b/src/gui/guiutility.cpp
index c5a94724e..ead4a78ad 100644
--- a/src/gui/guiutility.cpp
+++ b/src/gui/guiutility.cpp
@@ -105,7 +105,7 @@ QIcon Utility::getCoreIcon(const QString &icon_name)
if (icon_name.isEmpty()) {
return {};
}
- const QString path = (Theme::instance()->isUsingDarkTheme() && Theme::instance()->hasTheme(Theme::IconType::VanillaIcon, QStringLiteral("dark"))) ? QStringLiteral("dark") : QStringLiteral("light");
+ const QString path = Theme::instance()->isUsingDarkTheme() ? QStringLiteral("dark") : QStringLiteral("light");
const QIcon icon(QStringLiteral(":/client/resources/%1/%2").arg(path, icon_name));
Q_ASSERT(!icon.isNull());
return icon;
diff --git a/src/libsync/owncloudtheme.cpp b/src/libsync/owncloudtheme.cpp
index 571d625b1..cb5cf96c1 100644
--- a/src/libsync/owncloudtheme.cpp
+++ b/src/libsync/owncloudtheme.cpp
@@ -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
diff --git a/src/libsync/theme.cpp b/src/libsync/theme.cpp
index c7353c00f..f1000026c 100644
--- a/src/libsync/theme.cpp
+++ b/src/libsync/theme.cpp
@@ -87,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;
}
@@ -160,7 +158,7 @@ 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
@@ -171,27 +169,44 @@ QIcon Theme::aboutIcon() const
bool Theme::isUsingDarkTheme() const
{
//TODO: replace by a command line switch
- static bool forceDark = qEnvironmentVariableIsSet("OWNCLOUD_FORCE_DARK_MODE");
+ 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(iconType, _mono, sysTrayMenuVisible);
- } else {
- if (isUsingDarkTheme() && hasTheme(iconType, darkTheme())) {
- flavor = darkTheme();
- } else {
- flavor = coloredTheme();
- }
- }
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
@@ -227,35 +242,24 @@ QIcon Theme::themeIcon(const QString &name, bool sysTray, bool sysTrayMenuVisibl
}
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(IconType type, const QString &theme) const
{
const auto key = qMakePair(type != IconType::VanillaIcon, theme);
- auto it = _themeCache.find(key);
- if (it == _themeCache.end()) {
- bool found = QFileInfo(QStringLiteral("%1/%2/").arg(type == IconType::VanillaIcon ? vanillaThemePath() : brandThemePath(), theme)).isDir();
- if (!found && type == IconType::BrandedIconWithFallbackToVanillaIcon) {
- found = hasTheme(IconType::VanillaIcon, theme);
- }
- return _themeCache[key] = found;
+ 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(IconType type, bool mono, bool sysTrayMenuVisible) const
+QString Theme::systrayIconFlavor(bool mono, bool sysTrayMenuVisible) const
{
Q_UNUSED(sysTrayMenuVisible)
QString flavor;
@@ -269,7 +273,7 @@ QString Theme::systrayIconFlavor(IconType type, bool mono, bool sysTrayMenuVisib
#endif
} else {
// we have a dark sys tray and the theme has support for that
- flavor = (Utility::hasDarkSystray() && hasTheme(type, darkTheme())) ? darkTheme() : coloredTheme();
+ flavor = (Utility::hasDarkSystray() && allowDarkTheme()) ? darkTheme() : coloredTheme();
}
return flavor;
}
@@ -278,7 +282,6 @@ QString Theme::systrayIconFlavor(IconType type, bool mono, bool sysTrayMenuVisib
Theme::Theme()
: QObject(nullptr)
- , _mono(false)
{
}
@@ -343,7 +346,9 @@ bool Theme::systrayUseMonoIcons() const
bool Theme::monoIconsAvailable() const
{
- return hasTheme(IconType::BrandedIcon, systrayIconFlavor(IconType::BrandedIcon, 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
@@ -511,8 +516,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
@@ -522,7 +530,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
diff --git a/src/libsync/theme.h b/src/libsync/theme.h
index ad8feb3fd..1c7f5221d 100644
--- a/src/libsync/theme.h
+++ b/src/libsync/theme.h
@@ -120,6 +120,11 @@ public:
* The function also ensures the theme supports the dark theme
*/
bool isUsingDarkTheme() const;
+
+ /**
+ * Whether the branding allows the dark theme
+ */
+ bool allowDarkTheme() const;
#endif
virtual QString statusHeaderText(SyncResult::Status) const;
@@ -189,7 +194,7 @@ public:
#ifndef TOKEN_AUTH_ONLY
/** colored, white or black */
- QString systrayIconFlavor(IconType type, bool mono, bool sysTrayMenuVisible = false) const;
+ QString systrayIconFlavor(bool mono, bool sysTrayMenuVisible = false) const;
/**
* Override to use a string or a custom image name.
@@ -407,12 +412,11 @@ public:
*/
virtual bool enableExperimentalFeatures() const;
- // whether or not a theme is available
- bool hasTheme(IconType type, const QString &theme) const;
-
protected:
#ifndef TOKEN_AUTH_ONLY
- QIcon themeIcon(const QString &name, bool sysTray = false, bool sysTrayMenuVisible = false, IconType iconType = IconType::BrandedIconWithFallbackToVanillaIcon) const;
+ 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();
@@ -423,13 +427,19 @@ private:
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
- // <is vanilla, theme name>
- mutable QMap<QPair<bool, QString>, bool> _themeCache;
-
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
};
}