Moved dark icon logic into FilePath.

This commit is contained in:
Vlad N 2017-12-17 16:52:13 +02:00 committed by Janek Bevendorff
parent 55271311c4
commit 4fa00b74ad
3 changed files with 16 additions and 35 deletions

View File

@ -23,6 +23,7 @@
#include "config-keepassx.h"
#include "core/Global.h"
#include "core/Config.h"
FilePath* FilePath::m_instance(nullptr);
@ -91,21 +92,15 @@ QString FilePath::pluginPath(const QString& name)
QIcon FilePath::applicationIcon()
{
bool darkIcon = useDarkIcon();
#ifdef KEEPASSXC_DIST_SNAP
return icon("apps", "keepassxc", false);
return (darkIcon) ? icon("apps", "keepassxc-dark", false) : icon("apps", "keepassxc", false);
#else
return icon("apps", "keepassxc");
return (darkIcon) ? icon("apps", "keepassxc-dark") : icon("apps", "keepassxc");
#endif
}
QIcon FilePath::applicationIconDark()
{
#ifdef KEEPASSXC_DIST_SNAP
return icon("apps", "keepassxc-dark", false);
#else
return icon("apps", "keepassxc-dark");
#endif
}
QIcon FilePath::trayIconLocked()
{
@ -118,19 +113,12 @@ QIcon FilePath::trayIconLocked()
QIcon FilePath::trayIconUnlocked()
{
#ifdef KEEPASSXC_DIST_SNAP
return icon("apps", "keepassxc-unlocked", false);
#else
return icon("apps", "keepassxc-unlocked");
#endif
}
bool darkIcon = useDarkIcon();
QIcon FilePath::trayIconUnlockedDark()
{
#ifdef KEEPASSXC_DIST_SNAP
return icon("apps", "keepassxc-dark", false);
return (darkIcon) ? icon("apps", "keepassxc-dark", false) : icon("apps", "keepassxc-unlocked", false);
#else
return icon("apps", "keepassxc-dark");
return (darkIcon) ? icon("apps", "keepassxc-dark") : icon("apps", "keepassxc-unlocked");
#endif
}
@ -264,6 +252,11 @@ bool FilePath::testSetDir(const QString& dir)
}
}
bool FilePath::useDarkIcon()
{
return config()->get("GUI/DarkTrayIcon").toBool();
}
FilePath* FilePath::instance()
{
if (!m_instance) {

View File

@ -28,10 +28,8 @@ public:
QString dataPath(const QString& name);
QString pluginPath(const QString& name);
QIcon applicationIcon();
QIcon applicationIconDark();
QIcon trayIconLocked();
QIcon trayIconUnlocked();
QIcon trayIconUnlockedDark();
QIcon icon(const QString& category, const QString& name, bool fromTheme = true);
QIcon onOffIcon(const QString& category, const QString& name);
@ -40,6 +38,7 @@ public:
private:
FilePath();
bool testSetDir(const QString& dir);
bool useDarkIcon();
static FilePath* m_instance;

View File

@ -773,8 +773,6 @@ bool MainWindow::saveLastDatabases()
void MainWindow::updateTrayIcon()
{
if (isTrayIconEnabled()) {
bool darkIcon = config()->get("GUI/DarkTrayIcon").toBool();
if (!m_trayIcon) {
m_trayIcon = new QSystemTrayIcon(this);
QMenu* menu = new QMenu(this);
@ -797,20 +795,11 @@ void MainWindow::updateTrayIcon()
m_trayIcon->setContextMenu(menu);
if(darkIcon){
m_trayIcon->setIcon(filePath()->applicationIconDark());
} else {
m_trayIcon->setIcon(filePath()->applicationIcon());
}
m_trayIcon->setIcon(filePath()->applicationIcon());
m_trayIcon->show();
}
if (m_ui->tabWidget->hasLockableDatabases()) {
if(darkIcon){
m_trayIcon->setIcon(filePath()->trayIconUnlockedDark());
} else {
m_trayIcon->setIcon(filePath()->trayIconUnlocked());
}
m_trayIcon->setIcon(filePath()->trayIconUnlocked());
}
else {
m_trayIcon->setIcon(filePath()->trayIconLocked());