Use tray icon from system theme only if option is set

PR #18733.
This commit is contained in:
Vladimir Golovnev 2023-03-22 13:51:39 +03:00 committed by GitHub
parent 8bcac1bed2
commit 77bd09bb8b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 38 deletions

View file

@ -38,7 +38,6 @@
#include <QSystemTrayIcon>
#endif
#include "base/logger.h"
#include "base/preferences.h"
#include "uithememanager.h"
@ -243,7 +242,7 @@ void DesktopIntegration::onPreferencesChanged()
if (m_systrayIcon)
{
// Reload systray icon
m_systrayIcon->setIcon(UIThemeManager::instance()->getSystrayIcon());
m_systrayIcon->setIcon(getSystrayIcon());
}
else
{
@ -264,7 +263,7 @@ void DesktopIntegration::createTrayIcon()
{
Q_ASSERT(!m_systrayIcon);
m_systrayIcon = new QSystemTrayIcon(UIThemeManager::instance()->getSystrayIcon(), this);
m_systrayIcon = new QSystemTrayIcon(getSystrayIcon(), this);
m_systrayIcon->setToolTip(m_toolTip);
@ -284,4 +283,21 @@ void DesktopIntegration::createTrayIcon()
m_systrayIcon->show();
emit stateChanged();
}
QIcon DesktopIntegration::getSystrayIcon() const
{
const TrayIcon::Style style = Preferences::instance()->trayIconStyle();
switch (style)
{
default:
case TrayIcon::Style::Normal:
return UIThemeManager::instance()->getIcon(u"qbittorrent-tray"_qs);
case TrayIcon::Style::MonoDark:
return UIThemeManager::instance()->getIcon(u"qbittorrent-tray-dark"_qs);
case TrayIcon::Style::MonoLight:
return UIThemeManager::instance()->getIcon(u"qbittorrent-tray-light"_qs);
}
}
#endif // Q_OS_MACOS

View file

@ -78,6 +78,7 @@ private:
void onPreferencesChanged();
#ifndef Q_OS_MACOS
void createTrayIcon();
QIcon getSystrayIcon() const;
#endif // Q_OS_MACOS
CachedSettingValue<bool> m_storeNotificationEnabled;

View file

@ -121,7 +121,7 @@ QIcon UIThemeManager::getIcon(const QString &iconId, [[maybe_unused]] const QStr
if (m_useSystemIcons)
{
auto icon = QIcon::fromTheme(iconId);
if (icon.name() != iconId)
if (icon.isNull() || icon.availableSizes().isEmpty())
icon = QIcon::fromTheme(fallback, QIcon(m_themeSource->getIconPath(iconId, colorMode).data()));
return icon;
}
@ -174,36 +174,6 @@ QColor UIThemeManager::getColor(const QString &id) const
return color;
}
#ifndef Q_OS_MACOS
QIcon UIThemeManager::getSystrayIcon() const
{
const TrayIcon::Style style = Preferences::instance()->trayIconStyle();
switch (style)
{
#if defined(Q_OS_UNIX)
case TrayIcon::Style::Normal:
return QIcon::fromTheme(u"qbittorrent-tray"_qs);
case TrayIcon::Style::MonoDark:
return QIcon::fromTheme(u"qbittorrent-tray-dark"_qs);
case TrayIcon::Style::MonoLight:
return QIcon::fromTheme(u"qbittorrent-tray-light"_qs);
#else
case TrayIcon::Style::Normal:
return getIcon(u"qbittorrent-tray"_qs);
case TrayIcon::Style::MonoDark:
return getIcon(u"qbittorrent-tray-dark"_qs);
case TrayIcon::Style::MonoLight:
return getIcon(u"qbittorrent-tray-light"_qs);
#endif
default:
break;
}
// As a failsafe in case the enum is invalid
return getIcon(u"qbittorrent-tray"_qs);
}
#endif
void UIThemeManager::applyPalette() const
{
struct ColorDescriptor

View file

@ -57,10 +57,6 @@ public:
QColor getColor(const QString &id) const;
#ifndef Q_OS_MACOS
QIcon getSystrayIcon() const;
#endif
private:
UIThemeManager(); // singleton class