Merge pull request #1154 from rk4n/feature/dark-tray-icon

Add dark tray icon parameter to settings.
This commit is contained in:
Janek Bevendorff 2017-12-27 17:00:05 +01:00 committed by GitHub
commit 528e93004f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 59 additions and 5 deletions

View File

@ -16,6 +16,7 @@ LastOpenedDatabases=@Invalid()
[GUI]
Language=system
ShowTrayIcon=false
DarkTrayIcon=false
MinimizeToTray=false
MinimizeOnClose=false
MinimizeOnStartup=false

View File

@ -135,6 +135,7 @@ void Config::init(const QString& fileName)
m_defaults.insert("security/IconDownloadFallbackToGoogle", false);
m_defaults.insert("GUI/Language", "system");
m_defaults.insert("GUI/ShowTrayIcon", false);
m_defaults.insert("GUI/DarkTrayIcon", false);
m_defaults.insert("GUI/MinimizeToTray", false);
m_defaults.insert("GUI/MinimizeOnClose", false);
}

View File

@ -1,4 +1,5 @@
/*
* Copyright (C) 2017 KeePassXC Team <team@keepassxc.org>
* Copyright (C) 2011 Felix Geyer <debfx@fobos.de>
*
* This program is free software: you can redistribute it and/or modify
@ -23,6 +24,7 @@
#include "config-keepassx.h"
#include "core/Global.h"
#include "core/Config.h"
FilePath* FilePath::m_instance(nullptr);
@ -91,13 +93,16 @@ 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::trayIconLocked()
{
#ifdef KEEPASSXC_DIST_SNAP
@ -109,10 +114,12 @@ QIcon FilePath::trayIconLocked()
QIcon FilePath::trayIconUnlocked()
{
bool darkIcon = useDarkIcon();
#ifdef KEEPASSXC_DIST_SNAP
return icon("apps", "keepassxc-unlocked", false);
return darkIcon ? icon("apps", "keepassxc-dark", false) : icon("apps", "keepassxc-unlocked", false);
#else
return icon("apps", "keepassxc-unlocked");
return darkIcon ? icon("apps", "keepassxc-dark") : icon("apps", "keepassxc-unlocked");
#endif
}
@ -246,6 +253,11 @@ bool FilePath::testSetDir(const QString& dir)
}
}
bool FilePath::useDarkIcon()
{
return config()->get("GUI/DarkTrayIcon").toBool();
}
FilePath* FilePath::instance()
{
if (!m_instance) {

View File

@ -38,6 +38,7 @@ public:
private:
FilePath();
bool testSetDir(const QString& dir);
bool useDarkIcon();
static FilePath* m_instance;

View File

@ -775,7 +775,6 @@ void MainWindow::updateTrayIcon()
if (isTrayIconEnabled()) {
if (!m_trayIcon) {
m_trayIcon = new QSystemTrayIcon(this);
QMenu* menu = new QMenu(this);
QAction* actionToggle = new QAction(tr("Toggle window"), menu);
@ -795,6 +794,7 @@ void MainWindow::updateTrayIcon()
connect(actionToggle, SIGNAL(triggered()), SLOT(toggleWindow()));
m_trayIcon->setContextMenu(menu);
m_trayIcon->setIcon(filePath()->applicationIcon());
m_trayIcon->show();
}

View File

@ -136,6 +136,7 @@ void SettingsWidget::loadSettings()
m_generalUi->detailsHideCheckBox->setChecked(config()->get("GUI/HideDetailsView").toBool());
m_generalUi->systrayShowCheckBox->setChecked(config()->get("GUI/ShowTrayIcon").toBool());
m_generalUi->systrayDarkIconCheckBox->setChecked(config()->get("GUI/DarkTrayIcon").toBool());
m_generalUi->systrayMinimizeToTrayCheckBox->setChecked(config()->get("GUI/MinimizeToTray").toBool());
m_generalUi->systrayMinimizeOnCloseCheckBox->setChecked(config()->get("GUI/MinimizeOnClose").toBool());
m_generalUi->systrayMinimizeOnStartup->setChecked(config()->get("GUI/MinimizeOnStartup").toBool());
@ -208,6 +209,7 @@ void SettingsWidget::saveSettings()
config()->set("GUI/HideDetailsView", m_generalUi->detailsHideCheckBox->isChecked());
config()->set("GUI/ShowTrayIcon", m_generalUi->systrayShowCheckBox->isChecked());
config()->set("GUI/DarkTrayIcon", m_generalUi->systrayDarkIconCheckBox->isChecked());
config()->set("GUI/MinimizeToTray", m_generalUi->systrayMinimizeToTrayCheckBox->isChecked());
config()->set("GUI/MinimizeOnClose", m_generalUi->systrayMinimizeOnCloseCheckBox->isChecked());
config()->set("GUI/MinimizeOnStartup", m_generalUi->systrayMinimizeOnStartup->isChecked());
@ -265,6 +267,7 @@ void SettingsWidget::enableAutoSaveOnExit(bool checked)
void SettingsWidget::enableSystray(bool checked)
{
m_generalUi->systrayDarkIconCheckBox->setEnabled(checked);
m_generalUi->systrayMinimizeToTrayCheckBox->setEnabled(checked);
m_generalUi->systrayMinimizeOnCloseCheckBox->setEnabled(checked);
}

View File

@ -245,6 +245,42 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<property name="spacing">
<number>0</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SetMaximumSize</enum>
</property>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="systrayDarkIconCheckBox">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Dark system tray icon</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>