From 18221ecd5f457e31204cd76e6083862f839bff3d Mon Sep 17 00:00:00 2001 From: Jonathan White Date: Sat, 15 Jul 2023 22:38:37 -0400 Subject: [PATCH] Simplify tray icon selection code --- src/gui/Icons.cpp | 28 ++++++++-------------------- src/gui/Icons.h | 4 +--- src/gui/MainWindow.cpp | 8 ++------ 3 files changed, 11 insertions(+), 29 deletions(-) diff --git a/src/gui/Icons.cpp b/src/gui/Icons.cpp index 395331221b..8dd0c8d0a6 100644 --- a/src/gui/Icons.cpp +++ b/src/gui/Icons.cpp @@ -77,29 +77,27 @@ QString Icons::trayIconAppearance() const return iconAppearance; } -QIcon Icons::trayIcon(QString style) +QIcon Icons::trayIcon(bool unlocked) { - if (style == "unlocked") { - style.clear(); - } - if (!style.isEmpty()) { - style = "-" + style; + QString suffix; + if (!unlocked) { + suffix = "-locked"; } auto iconApperance = trayIconAppearance(); if (!iconApperance.startsWith("monochrome")) { - return icon(QString("%1%2").arg(applicationIconName(), style), false); + return icon(QString("%1%2").arg(applicationIconName(), suffix), false); } QIcon i; #if defined(Q_OS_MACOS) || defined(Q_OS_WIN) if (osUtils->isStatusBarDark()) { - i = icon(QString("keepassxc-monochrome-light%1").arg(style), false); + i = icon(QString("keepassxc-monochrome-light%1").arg(suffix), false); } else { - i = icon(QString("keepassxc-monochrome-dark%1").arg(style), false); + i = icon(QString("keepassxc-monochrome-dark%1").arg(suffix), false); } #else - i = icon(QString("%1-%2%3").arg(applicationIconName(), iconApperance, style), false); + i = icon(QString("%1-%2%3").arg(applicationIconName(), iconApperance, suffix), false); #endif #if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0) // Set as mask to allow the operating system to recolour the tray icon. This may look weird @@ -111,16 +109,6 @@ QIcon Icons::trayIcon(QString style) return i; } -QIcon Icons::trayIconLocked() -{ - return trayIcon("locked"); -} - -QIcon Icons::trayIconUnlocked() -{ - return trayIcon("unlocked"); -} - AdaptiveIconEngine::AdaptiveIconEngine(QIcon baseIcon, QColor overrideColor) : QIconEngine() , m_baseIcon(std::move(baseIcon)) diff --git a/src/gui/Icons.h b/src/gui/Icons.h index db342ae193..15b3b1be9c 100644 --- a/src/gui/Icons.h +++ b/src/gui/Icons.h @@ -29,9 +29,7 @@ class Icons public: QString applicationIconName(); QIcon applicationIcon(); - QIcon trayIcon(QString style = "unlocked"); - QIcon trayIconLocked(); - QIcon trayIconUnlocked(); + QIcon trayIcon(bool unlocked = true); QString trayIconAppearance() const; QIcon icon(const QString& name, bool recolor = true, const QColor& overrideColor = QColor::Invalid); QIcon onOffIcon(const QString& name, bool on, bool recolor = true); diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index aa9e339910..a9e53c6e9d 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -1548,12 +1548,8 @@ void MainWindow::updateTrayIcon() connect(actionToggle, SIGNAL(triggered()), SLOT(toggleWindow())); } - if (m_ui->tabWidget->hasLockableDatabases()) { - m_trayIcon->setIcon(icons()->trayIconUnlocked()); - } else { - m_trayIcon->setIcon(icons()->trayIconLocked()); - } - + bool showUnlocked = m_ui->tabWidget->hasLockableDatabases(); + m_trayIcon->setIcon(icons()->trayIcon(showUnlocked)); m_trayIcon->setToolTip(windowTitle().replace("[*]", isWindowModified() ? "*" : "")); m_trayIcon->show();