Skip to content

Commit

Permalink
Simplify tray icon selection code
Browse files Browse the repository at this point in the history
  • Loading branch information
droidmonkey committed Jul 16, 2023
1 parent 11c5ec9 commit 18221ec
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 29 deletions.
28 changes: 8 additions & 20 deletions src/gui/Icons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
Expand Down
4 changes: 1 addition & 3 deletions src/gui/Icons.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 2 additions & 6 deletions src/gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 18221ec

Please sign in to comment.