Merge pull request #583 from keepassxreboot/feature/macos-minimize-onclose

Add trayicon on macOS and enable minimize onClose
This commit is contained in:
Janek Bevendorff 2017-05-19 18:51:17 +02:00 committed by GitHub
commit 6c050c55d9
2 changed files with 9 additions and 10 deletions

View File

@ -759,10 +759,17 @@ void MainWindow::updateTrayIcon()
QAction* actionToggle = new QAction(tr("Toggle window"), menu); QAction* actionToggle = new QAction(tr("Toggle window"), menu);
menu->addAction(actionToggle); menu->addAction(actionToggle);
#ifdef Q_OS_MAC
QAction* actionQuit = new QAction(tr("Quit KeePassXC"), menu);
menu->addAction(actionQuit);
connect(actionQuit, SIGNAL(triggered()), SLOT(appExit()));
#else
menu->addAction(m_ui->actionQuit); menu->addAction(m_ui->actionQuit);
connect(m_trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), connect(m_trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
SLOT(trayIconTriggered(QSystemTrayIcon::ActivationReason))); SLOT(trayIconTriggered(QSystemTrayIcon::ActivationReason)));
#endif
connect(actionToggle, SIGNAL(triggered()), SLOT(toggleWindow())); connect(actionToggle, SIGNAL(triggered()), SLOT(toggleWindow()));
m_trayIcon->setContextMenu(menu); m_trayIcon->setContextMenu(menu);
@ -842,7 +849,9 @@ void MainWindow::trayIconTriggered(QSystemTrayIcon::ActivationReason reason)
void MainWindow::hideWindow() void MainWindow::hideWindow()
{ {
#ifndef Q_OS_MAC
setWindowState(windowState() | Qt::WindowMinimized); setWindowState(windowState() | Qt::WindowMinimized);
#endif
QTimer::singleShot(0, this, SLOT(hide())); QTimer::singleShot(0, this, SLOT(hide()));
if (config()->get("security/lockdatabaseminimize").toBool()) { if (config()->get("security/lockdatabaseminimize").toBool()) {
@ -925,13 +934,8 @@ void MainWindow::repairDatabase()
bool MainWindow::isTrayIconEnabled() const bool MainWindow::isTrayIconEnabled() const
{ {
#ifdef Q_OS_MAC
// systray not useful on OS X
return false;
#else
return config()->get("GUI/ShowTrayIcon").toBool() return config()->get("GUI/ShowTrayIcon").toBool()
&& QSystemTrayIcon::isSystemTrayAvailable(); && QSystemTrayIcon::isSystemTrayAvailable();
#endif
} }
void MainWindow::displayGlobalMessage(const QString& text, MessageWidget::MessageType type, bool showClosebutton) void MainWindow::displayGlobalMessage(const QString& text, MessageWidget::MessageType type, bool showClosebutton)

View File

@ -66,11 +66,6 @@ SettingsWidget::SettingsWidget(QWidget* parent)
m_generalUi->generalSettingsTabWidget->removeTab(1); m_generalUi->generalSettingsTabWidget->removeTab(1);
} }
#ifdef Q_OS_MAC
// systray not useful on OS X
m_generalUi->systraySettings->setVisible(false);
#endif
connect(this, SIGNAL(accepted()), SLOT(saveSettings())); connect(this, SIGNAL(accepted()), SLOT(saveSettings()));
connect(this, SIGNAL(rejected()), SLOT(reject())); connect(this, SIGNAL(rejected()), SLOT(reject()));