mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2024-12-27 16:29:44 -05:00
implement a (nonperfect) hide-to-tray on win close
This commit is contained in:
parent
6b7f7bb777
commit
5982763bed
@ -106,6 +106,7 @@ void Config::init(const QString& fileName)
|
||||
m_defaults.insert("GUI/Language", "system");
|
||||
m_defaults.insert("GUI/ShowTrayIcon", false);
|
||||
m_defaults.insert("GUI/MinimizeToTray", false);
|
||||
m_defaults.insert("GUI/MinimizeOnClose", false);
|
||||
}
|
||||
|
||||
Config* Config::instance()
|
||||
|
@ -71,6 +71,8 @@ MainWindow::MainWindow()
|
||||
: m_ui(new Ui::MainWindow())
|
||||
, m_trayIcon(Q_NULLPTR)
|
||||
{
|
||||
appExitCalled = false;
|
||||
|
||||
m_ui->setupUi(this);
|
||||
|
||||
m_countDefaultAttributes = m_ui->menuEntryCopyAttribute->actions().size();
|
||||
@ -202,7 +204,7 @@ MainWindow::MainWindow()
|
||||
SLOT(importKeePass1Database()));
|
||||
connect(m_ui->actionLockDatabases, SIGNAL(triggered()), m_ui->tabWidget,
|
||||
SLOT(lockDatabases()));
|
||||
connect(m_ui->actionQuit, SIGNAL(triggered()), SLOT(close()));
|
||||
connect(m_ui->actionQuit, SIGNAL(triggered()), SLOT(appExit()));
|
||||
|
||||
m_actionMultiplexer.connect(m_ui->actionEntryNew, SIGNAL(triggered()),
|
||||
SLOT(createEntry()));
|
||||
@ -249,6 +251,12 @@ MainWindow::~MainWindow()
|
||||
{
|
||||
}
|
||||
|
||||
void MainWindow::appExit()
|
||||
{
|
||||
appExitCalled = true;
|
||||
close();
|
||||
}
|
||||
|
||||
void MainWindow::updateLastDatabasesMenu()
|
||||
{
|
||||
m_ui->menuRecentDatabases->clear();
|
||||
@ -462,6 +470,13 @@ void MainWindow::databaseTabChanged(int tabIndex)
|
||||
|
||||
void MainWindow::closeEvent(QCloseEvent* event)
|
||||
{
|
||||
if (config()->get("GUI/MinimizeOnClose").toBool() && !appExitCalled)
|
||||
{
|
||||
event->ignore();
|
||||
hide();
|
||||
return;
|
||||
}
|
||||
|
||||
bool accept = saveLastDatabases();
|
||||
|
||||
if (accept) {
|
||||
|
@ -65,6 +65,7 @@ private Q_SLOTS:
|
||||
void applySettingsChanges();
|
||||
void trayIconTriggered(QSystemTrayIcon::ActivationReason reason);
|
||||
void toggleWindow();
|
||||
void appExit();
|
||||
|
||||
private:
|
||||
static void setShortcut(QAction* action, QKeySequence::StandardKey standard, int fallback = 0);
|
||||
@ -87,6 +88,8 @@ private:
|
||||
QSystemTrayIcon* m_trayIcon;
|
||||
|
||||
Q_DISABLE_COPY(MainWindow)
|
||||
|
||||
bool appExitCalled;
|
||||
};
|
||||
|
||||
#endif // KEEPASSX_MAINWINDOW_H
|
||||
|
@ -74,6 +74,8 @@ SettingsWidget::SettingsWidget(QWidget* parent)
|
||||
this, SLOT(enableAutoSaveOnExit(bool)));
|
||||
connect(m_generalUi->systrayShowCheckBox, SIGNAL(toggled(bool)),
|
||||
m_generalUi->systrayMinimizeToTrayCheckBox, SLOT(setEnabled(bool)));
|
||||
connect(m_generalUi->systrayMinimizeToTrayCheckBox, SIGNAL(toggled(bool)),
|
||||
m_generalUi->systrayMinimizeOnCloseCheckBox, SLOT(setEnabled(bool)));
|
||||
|
||||
connect(m_secUi->clearClipboardCheckBox, SIGNAL(toggled(bool)),
|
||||
m_secUi->clearClipboardSpinBox, SLOT(setEnabled(bool)));
|
||||
@ -117,6 +119,7 @@ void SettingsWidget::loadSettings()
|
||||
|
||||
m_generalUi->systrayShowCheckBox->setChecked(config()->get("GUI/ShowTrayIcon").toBool());
|
||||
m_generalUi->systrayMinimizeToTrayCheckBox->setChecked(config()->get("GUI/MinimizeToTray").toBool());
|
||||
m_generalUi->systrayMinimizeOnCloseCheckBox->setChecked(config()->get("GUI/MinimizeOnClose").toBool());
|
||||
|
||||
if (autoType()->isAvailable()) {
|
||||
m_globalAutoTypeKey = static_cast<Qt::Key>(config()->get("GlobalAutoTypeKey").toInt());
|
||||
@ -161,6 +164,7 @@ void SettingsWidget::saveSettings()
|
||||
|
||||
config()->set("GUI/ShowTrayIcon", m_generalUi->systrayShowCheckBox->isChecked());
|
||||
config()->set("GUI/MinimizeToTray", m_generalUi->systrayMinimizeToTrayCheckBox->isChecked());
|
||||
config()->set("GUI/MinimizeOnClose", m_generalUi->systrayMinimizeOnCloseCheckBox->isChecked());
|
||||
|
||||
if (autoType()->isAvailable()) {
|
||||
config()->set("GlobalAutoTypeKey", m_generalUi->autoTypeShortcutWidget->key());
|
||||
|
@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>456</width>
|
||||
<height>313</height>
|
||||
<height>346</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
@ -113,6 +113,16 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="12" column="0">
|
||||
<widget class="QCheckBox" name="systrayMinimizeOnCloseCheckBox">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Hide window to system tray instead of App Exit</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
|
Loading…
Reference in New Issue
Block a user