implement a (nonperfect) hide-to-tray on win close

This commit is contained in:
denk-mal 2015-06-18 15:23:41 +02:00
parent 6b7f7bb777
commit 5982763bed
5 changed files with 35 additions and 2 deletions

View File

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

View File

@ -71,6 +71,8 @@ MainWindow::MainWindow()
: m_ui(new Ui::MainWindow()) : m_ui(new Ui::MainWindow())
, m_trayIcon(Q_NULLPTR) , m_trayIcon(Q_NULLPTR)
{ {
appExitCalled = false;
m_ui->setupUi(this); m_ui->setupUi(this);
m_countDefaultAttributes = m_ui->menuEntryCopyAttribute->actions().size(); m_countDefaultAttributes = m_ui->menuEntryCopyAttribute->actions().size();
@ -202,7 +204,7 @@ MainWindow::MainWindow()
SLOT(importKeePass1Database())); SLOT(importKeePass1Database()));
connect(m_ui->actionLockDatabases, SIGNAL(triggered()), m_ui->tabWidget, connect(m_ui->actionLockDatabases, SIGNAL(triggered()), m_ui->tabWidget,
SLOT(lockDatabases())); 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()), m_actionMultiplexer.connect(m_ui->actionEntryNew, SIGNAL(triggered()),
SLOT(createEntry())); SLOT(createEntry()));
@ -249,6 +251,12 @@ MainWindow::~MainWindow()
{ {
} }
void MainWindow::appExit()
{
appExitCalled = true;
close();
}
void MainWindow::updateLastDatabasesMenu() void MainWindow::updateLastDatabasesMenu()
{ {
m_ui->menuRecentDatabases->clear(); m_ui->menuRecentDatabases->clear();
@ -462,6 +470,13 @@ void MainWindow::databaseTabChanged(int tabIndex)
void MainWindow::closeEvent(QCloseEvent* event) void MainWindow::closeEvent(QCloseEvent* event)
{ {
if (config()->get("GUI/MinimizeOnClose").toBool() && !appExitCalled)
{
event->ignore();
hide();
return;
}
bool accept = saveLastDatabases(); bool accept = saveLastDatabases();
if (accept) { if (accept) {

View File

@ -65,6 +65,7 @@ private Q_SLOTS:
void applySettingsChanges(); void applySettingsChanges();
void trayIconTriggered(QSystemTrayIcon::ActivationReason reason); void trayIconTriggered(QSystemTrayIcon::ActivationReason reason);
void toggleWindow(); void toggleWindow();
void appExit();
private: private:
static void setShortcut(QAction* action, QKeySequence::StandardKey standard, int fallback = 0); static void setShortcut(QAction* action, QKeySequence::StandardKey standard, int fallback = 0);
@ -87,6 +88,8 @@ private:
QSystemTrayIcon* m_trayIcon; QSystemTrayIcon* m_trayIcon;
Q_DISABLE_COPY(MainWindow) Q_DISABLE_COPY(MainWindow)
bool appExitCalled;
}; };
#endif // KEEPASSX_MAINWINDOW_H #endif // KEEPASSX_MAINWINDOW_H

View File

@ -74,6 +74,8 @@ SettingsWidget::SettingsWidget(QWidget* parent)
this, SLOT(enableAutoSaveOnExit(bool))); this, SLOT(enableAutoSaveOnExit(bool)));
connect(m_generalUi->systrayShowCheckBox, SIGNAL(toggled(bool)), connect(m_generalUi->systrayShowCheckBox, SIGNAL(toggled(bool)),
m_generalUi->systrayMinimizeToTrayCheckBox, SLOT(setEnabled(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)), connect(m_secUi->clearClipboardCheckBox, SIGNAL(toggled(bool)),
m_secUi->clearClipboardSpinBox, SLOT(setEnabled(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->systrayShowCheckBox->setChecked(config()->get("GUI/ShowTrayIcon").toBool());
m_generalUi->systrayMinimizeToTrayCheckBox->setChecked(config()->get("GUI/MinimizeToTray").toBool()); m_generalUi->systrayMinimizeToTrayCheckBox->setChecked(config()->get("GUI/MinimizeToTray").toBool());
m_generalUi->systrayMinimizeOnCloseCheckBox->setChecked(config()->get("GUI/MinimizeOnClose").toBool());
if (autoType()->isAvailable()) { if (autoType()->isAvailable()) {
m_globalAutoTypeKey = static_cast<Qt::Key>(config()->get("GlobalAutoTypeKey").toInt()); 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/ShowTrayIcon", m_generalUi->systrayShowCheckBox->isChecked());
config()->set("GUI/MinimizeToTray", m_generalUi->systrayMinimizeToTrayCheckBox->isChecked()); config()->set("GUI/MinimizeToTray", m_generalUi->systrayMinimizeToTrayCheckBox->isChecked());
config()->set("GUI/MinimizeOnClose", m_generalUi->systrayMinimizeOnCloseCheckBox->isChecked());
if (autoType()->isAvailable()) { if (autoType()->isAvailable()) {
config()->set("GlobalAutoTypeKey", m_generalUi->autoTypeShortcutWidget->key()); config()->set("GlobalAutoTypeKey", m_generalUi->autoTypeShortcutWidget->key());

View File

@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>456</width> <width>456</width>
<height>313</height> <height>346</height>
</rect> </rect>
</property> </property>
<layout class="QFormLayout" name="formLayout"> <layout class="QFormLayout" name="formLayout">
@ -113,6 +113,16 @@
</property> </property>
</widget> </widget>
</item> </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> </layout>
</widget> </widget>
<customwidgets> <customwidgets>