Skip to content

Commit

Permalink
Use tray icon from system theme only if option is set
Browse files Browse the repository at this point in the history
PR #18733.
  • Loading branch information
glassez committed Mar 22, 2023
1 parent 8bcac1b commit 77bd09b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 38 deletions.
22 changes: 19 additions & 3 deletions src/gui/desktopintegration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
#include <QSystemTrayIcon>
#endif

#include "base/logger.h"
#include "base/preferences.h"
#include "uithememanager.h"

Expand Down Expand Up @@ -243,7 +242,7 @@ void DesktopIntegration::onPreferencesChanged()
if (m_systrayIcon)
{
// Reload systray icon
m_systrayIcon->setIcon(UIThemeManager::instance()->getSystrayIcon());
m_systrayIcon->setIcon(getSystrayIcon());
}
else
{
Expand All @@ -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);

Expand All @@ -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 change: 1 addition & 0 deletions src/gui/desktopintegration.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class DesktopIntegration final : public QObject
void onPreferencesChanged();
#ifndef Q_OS_MACOS
void createTrayIcon();
QIcon getSystrayIcon() const;
#endif // Q_OS_MACOS

CachedSettingValue<bool> m_storeNotificationEnabled;
Expand Down
32 changes: 1 addition & 31 deletions src/gui/uithememanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions src/gui/uithememanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@ class UIThemeManager final : public QObject

QColor getColor(const QString &id) const;

#ifndef Q_OS_MACOS
QIcon getSystrayIcon() const;
#endif

private:
UIThemeManager(); // singleton class

Expand Down

0 comments on commit 77bd09b

Please sign in to comment.