From 55271311c4754d4bd204ad2fa3a1f4c253df3269 Mon Sep 17 00:00:00 2001 From: Vlad N Date: Sat, 21 Oct 2017 15:16:52 +0300 Subject: [PATCH 1/3] Added dark tray icon parameter to settings. --- share/keepassxc.ini | 1 + src/core/FilePath.cpp | 18 ++++++++++++++++ src/core/FilePath.h | 2 ++ src/gui/MainWindow.cpp | 17 ++++++++++++--- src/gui/SettingsWidget.cpp | 3 +++ src/gui/SettingsWidgetGeneral.ui | 36 ++++++++++++++++++++++++++++++++ 6 files changed, 74 insertions(+), 3 deletions(-) diff --git a/share/keepassxc.ini b/share/keepassxc.ini index c6f0654fe..54920224a 100644 --- a/share/keepassxc.ini +++ b/share/keepassxc.ini @@ -16,6 +16,7 @@ LastOpenedDatabases=@Invalid() [GUI] Language=system ShowTrayIcon=false +DarkTrayIcon=false MinimizeToTray=false MinimizeOnClose=false MinimizeOnStartup=false diff --git a/src/core/FilePath.cpp b/src/core/FilePath.cpp index b5c9d1020..89b0e4643 100644 --- a/src/core/FilePath.cpp +++ b/src/core/FilePath.cpp @@ -98,6 +98,15 @@ QIcon FilePath::applicationIcon() #endif } +QIcon FilePath::applicationIconDark() +{ +#ifdef KEEPASSXC_DIST_SNAP + return icon("apps", "keepassxc-dark", false); +#else + return icon("apps", "keepassxc-dark"); +#endif +} + QIcon FilePath::trayIconLocked() { #ifdef KEEPASSXC_DIST_SNAP @@ -116,6 +125,15 @@ QIcon FilePath::trayIconUnlocked() #endif } +QIcon FilePath::trayIconUnlockedDark() +{ +#ifdef KEEPASSXC_DIST_SNAP + return icon("apps", "keepassxc-dark", false); +#else + return icon("apps", "keepassxc-dark"); +#endif +} + QIcon FilePath::icon(const QString& category, const QString& name, bool fromTheme) { QString combinedName = category + "/" + name; diff --git a/src/core/FilePath.h b/src/core/FilePath.h index 34edcbc93..fdadee79e 100644 --- a/src/core/FilePath.h +++ b/src/core/FilePath.h @@ -28,8 +28,10 @@ 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); diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index fa16adb80..044cb736b 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -773,9 +773,10 @@ 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); QAction* actionToggle = new QAction(tr("Toggle window"), menu); @@ -795,11 +796,21 @@ void MainWindow::updateTrayIcon() connect(actionToggle, SIGNAL(triggered()), SLOT(toggleWindow())); m_trayIcon->setContextMenu(menu); - m_trayIcon->setIcon(filePath()->applicationIcon()); + + if(darkIcon){ + m_trayIcon->setIcon(filePath()->applicationIconDark()); + } else { + m_trayIcon->setIcon(filePath()->applicationIcon()); + } + m_trayIcon->show(); } if (m_ui->tabWidget->hasLockableDatabases()) { - m_trayIcon->setIcon(filePath()->trayIconUnlocked()); + if(darkIcon){ + m_trayIcon->setIcon(filePath()->trayIconUnlockedDark()); + } else { + m_trayIcon->setIcon(filePath()->trayIconUnlocked()); + } } else { m_trayIcon->setIcon(filePath()->trayIconLocked()); diff --git a/src/gui/SettingsWidget.cpp b/src/gui/SettingsWidget.cpp index 4ba81c6f7..ce3df3338 100644 --- a/src/gui/SettingsWidget.cpp +++ b/src/gui/SettingsWidget.cpp @@ -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); } diff --git a/src/gui/SettingsWidgetGeneral.ui b/src/gui/SettingsWidgetGeneral.ui index 7dc4487cf..684cb4353 100644 --- a/src/gui/SettingsWidgetGeneral.ui +++ b/src/gui/SettingsWidgetGeneral.ui @@ -245,6 +245,42 @@ + + + + 0 + + + QLayout::SetMaximumSize + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 40 + 20 + + + + + + + + false + + + Dark system tray icon + + + + + From 4fa00b74ad75b968011acf80ebd3554173199d85 Mon Sep 17 00:00:00 2001 From: Vlad N Date: Sun, 17 Dec 2017 16:52:13 +0200 Subject: [PATCH 2/3] Moved dark icon logic into FilePath. --- src/core/FilePath.cpp | 33 +++++++++++++-------------------- src/core/FilePath.h | 3 +-- src/gui/MainWindow.cpp | 15 ++------------- 3 files changed, 16 insertions(+), 35 deletions(-) diff --git a/src/core/FilePath.cpp b/src/core/FilePath.cpp index 89b0e4643..f4703b99b 100644 --- a/src/core/FilePath.cpp +++ b/src/core/FilePath.cpp @@ -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) { diff --git a/src/core/FilePath.h b/src/core/FilePath.h index fdadee79e..2db496937 100644 --- a/src/core/FilePath.h +++ b/src/core/FilePath.h @@ -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; diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 044cb736b..d63545bf1 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -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()); From 23f8d58859d637da6fcb75050c8dde90fa37ae8e Mon Sep 17 00:00:00 2001 From: Janek Bevendorff Date: Wed, 27 Dec 2017 16:46:56 +0100 Subject: [PATCH 3/3] Add default value for DarkTrayIcon option and fix style issues --- src/core/Config.cpp | 1 + src/core/FilePath.cpp | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/core/Config.cpp b/src/core/Config.cpp index 2047919b1..96fd385ff 100644 --- a/src/core/Config.cpp +++ b/src/core/Config.cpp @@ -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); } diff --git a/src/core/FilePath.cpp b/src/core/FilePath.cpp index f4703b99b..f694f548b 100644 --- a/src/core/FilePath.cpp +++ b/src/core/FilePath.cpp @@ -1,4 +1,5 @@ /* + * Copyright (C) 2017 KeePassXC Team * Copyright (C) 2011 Felix Geyer * * This program is free software: you can redistribute it and/or modify @@ -116,9 +117,9 @@ QIcon FilePath::trayIconUnlocked() bool darkIcon = useDarkIcon(); #ifdef KEEPASSXC_DIST_SNAP - return (darkIcon) ? icon("apps", "keepassxc-dark", false) : icon("apps", "keepassxc-unlocked", false); + return darkIcon ? icon("apps", "keepassxc-dark", false) : icon("apps", "keepassxc-unlocked", false); #else - return (darkIcon) ? icon("apps", "keepassxc-dark") : icon("apps", "keepassxc-unlocked"); + return darkIcon ? icon("apps", "keepassxc-dark") : icon("apps", "keepassxc-unlocked"); #endif }