Browse Source

Use tray icon from system theme only if option is set

PR #18733.
adaptive-webui-19844
Vladimir Golovnev 2 years ago committed by GitHub
parent
commit
77bd09bb8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 22
      src/gui/desktopintegration.cpp
  2. 1
      src/gui/desktopintegration.h
  3. 32
      src/gui/uithememanager.cpp
  4. 4
      src/gui/uithememanager.h

22
src/gui/desktopintegration.cpp

@ -38,7 +38,6 @@ @@ -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() @@ -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() @@ -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() @@ -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

1
src/gui/desktopintegration.h

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

32
src/gui/uithememanager.cpp

@ -121,7 +121,7 @@ QIcon UIThemeManager::getIcon(const QString &iconId, [[maybe_unused]] const QStr @@ -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 @@ -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

4
src/gui/uithememanager.h

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

Loading…
Cancel
Save