mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-07-26 16:25:23 -04:00
Fix minimize at startup and decouple various tray and minimization options (#109)
* Hide window on startup when configured to start minimized, fixes #105 * Decouple different systray and minimization options, fixes #64 * Commit missing changes in main.cpp to minimize at startup * Remove obsolete code
This commit is contained in:
parent
02d2ac904d
commit
19a960856c
7 changed files with 22 additions and 60 deletions
|
@ -113,12 +113,6 @@ void DatabaseOpenWidget::openDatabase()
|
||||||
|
|
||||||
if (m_db) {
|
if (m_db) {
|
||||||
Q_EMIT editFinished(true);
|
Q_EMIT editFinished(true);
|
||||||
// this is a c++11 equivalent foreach construct
|
|
||||||
// if c++11 is not available another iteration loop style is needed!
|
|
||||||
for (auto widget : qApp->topLevelWidgets()) {
|
|
||||||
if(widget->inherits("QMainWindow"))
|
|
||||||
static_cast<MainWindow*>(widget)->configuredMinimizeWindow();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
MessageBox::warning(this, tr("Error"), tr("Unable to open the database.").append("\n")
|
MessageBox::warning(this, tr("Error"), tr("Unable to open the database.").append("\n")
|
||||||
|
|
|
@ -329,14 +329,12 @@ void MainWindow::openDatabase(const QString& fileName, const QString& pw, const
|
||||||
m_ui->tabWidget->openDatabase(fileName, pw, keyFile);
|
m_ui->tabWidget->openDatabase(fileName, pw, keyFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::configuredMinimizeWindow()
|
void MainWindow::minimizeWindow()
|
||||||
{
|
{
|
||||||
bool minimize = isTrayIconEnabled() &&
|
if (isTrayIconEnabled() && config()->get("GUI/MinimizeToTray").toBool()) {
|
||||||
config()->get("GUI/MinimizeToTray").toBool() &&
|
|
||||||
config()->get("GUI/MinimizeOnClose").toBool() &&
|
|
||||||
config()->get("GUI/MinimizeOnStartup").toBool();
|
|
||||||
if (minimize) {
|
|
||||||
hide();
|
hide();
|
||||||
|
} else {
|
||||||
|
setWindowState(Qt::WindowMinimized);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -523,7 +521,6 @@ void MainWindow::databaseTabChanged(int tabIndex)
|
||||||
void MainWindow::closeEvent(QCloseEvent* event)
|
void MainWindow::closeEvent(QCloseEvent* event)
|
||||||
{
|
{
|
||||||
bool minimizeOnClose = isTrayIconEnabled() &&
|
bool minimizeOnClose = isTrayIconEnabled() &&
|
||||||
config()->get("GUI/MinimizeToTray").toBool() &&
|
|
||||||
config()->get("GUI/MinimizeOnClose").toBool();
|
config()->get("GUI/MinimizeOnClose").toBool();
|
||||||
if (minimizeOnClose && !appExitCalled)
|
if (minimizeOnClose && !appExitCalled)
|
||||||
{
|
{
|
||||||
|
|
|
@ -38,7 +38,7 @@ class MainWindow : public QMainWindow
|
||||||
public:
|
public:
|
||||||
MainWindow();
|
MainWindow();
|
||||||
~MainWindow();
|
~MainWindow();
|
||||||
void configuredMinimizeWindow();
|
void minimizeWindow();
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void openDatabase(const QString& fileName, const QString& pw = QString(),
|
void openDatabase(const QString& fileName, const QString& pw = QString(),
|
||||||
|
|
|
@ -74,11 +74,7 @@ SettingsWidget::SettingsWidget(QWidget* parent)
|
||||||
connect(m_generalUi->autoSaveAfterEveryChangeCheckBox, SIGNAL(toggled(bool)),
|
connect(m_generalUi->autoSaveAfterEveryChangeCheckBox, SIGNAL(toggled(bool)),
|
||||||
this, SLOT(enableAutoSaveOnExit(bool)));
|
this, SLOT(enableAutoSaveOnExit(bool)));
|
||||||
connect(m_generalUi->systrayShowCheckBox, SIGNAL(toggled(bool)),
|
connect(m_generalUi->systrayShowCheckBox, SIGNAL(toggled(bool)),
|
||||||
this, SLOT(enableSystrayMinimizeToTray(bool)));
|
this, SLOT(enableSystray(bool)));
|
||||||
connect(m_generalUi->systrayMinimizeToTrayCheckBox, SIGNAL(toggled(bool)),
|
|
||||||
this, SLOT(enableSystrayMinimizeToTray2(bool)));
|
|
||||||
connect(m_generalUi->systrayMinimizeOnCloseCheckBox, SIGNAL(toggled(bool)),
|
|
||||||
m_generalUi->systrayMinimizeOnStartup, 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)));
|
||||||
|
@ -209,18 +205,8 @@ void SettingsWidget::enableAutoSaveOnExit(bool checked)
|
||||||
m_generalUi->autoSaveOnExitCheckBox->setEnabled(!checked);
|
m_generalUi->autoSaveOnExitCheckBox->setEnabled(!checked);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingsWidget::enableSystrayMinimizeToTray(bool checked)
|
void SettingsWidget::enableSystray(bool checked)
|
||||||
{
|
{
|
||||||
m_generalUi->systrayMinimizeToTrayCheckBox->setEnabled(checked);
|
m_generalUi->systrayMinimizeToTrayCheckBox->setEnabled(checked);
|
||||||
bool checked2 = m_generalUi->systrayMinimizeToTrayCheckBox->checkState();
|
|
||||||
m_generalUi->systrayMinimizeOnCloseCheckBox->setEnabled(checked && checked2);
|
|
||||||
bool checked3 = m_generalUi->systrayMinimizeOnCloseCheckBox->checkState();
|
|
||||||
m_generalUi->systrayMinimizeOnStartup->setEnabled(checked && checked2 && checked3);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SettingsWidget::enableSystrayMinimizeToTray2(bool checked)
|
|
||||||
{
|
|
||||||
m_generalUi->systrayMinimizeOnCloseCheckBox->setEnabled(checked);
|
m_generalUi->systrayMinimizeOnCloseCheckBox->setEnabled(checked);
|
||||||
bool checked2 = m_generalUi->systrayMinimizeOnCloseCheckBox->checkState();
|
|
||||||
m_generalUi->systrayMinimizeOnStartup->setEnabled(checked && checked2);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,8 +51,7 @@ private Q_SLOTS:
|
||||||
void saveSettings();
|
void saveSettings();
|
||||||
void reject();
|
void reject();
|
||||||
void enableAutoSaveOnExit(bool checked);
|
void enableAutoSaveOnExit(bool checked);
|
||||||
void enableSystrayMinimizeToTray(bool checked);
|
void enableSystray(bool checked);
|
||||||
void enableSystrayMinimizeToTray2(bool checked);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QWidget* const m_secWidget;
|
QWidget* const m_secWidget;
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>684</width>
|
<width>684</width>
|
||||||
<height>394</height>
|
<height>452</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QFormLayout" name="formLayout">
|
<layout class="QFormLayout" name="formLayout">
|
||||||
|
@ -37,7 +37,7 @@
|
||||||
<item row="2" column="0">
|
<item row="2" column="0">
|
||||||
<widget class="QCheckBox" name="openPreviousDatabasesOnStartupCheckBox">
|
<widget class="QCheckBox" name="openPreviousDatabasesOnStartupCheckBox">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Open previous databases on startup</string>
|
<string>Load previous databases on startup</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
@ -113,12 +113,9 @@
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizeType">
|
|
||||||
<enum>QSizePolicy::Fixed</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeHint" stdset="0">
|
<property name="sizeHint" stdset="0">
|
||||||
<size>
|
<size>
|
||||||
<width>20</width>
|
<width>40</width>
|
||||||
<height>20</height>
|
<height>20</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
|
@ -166,7 +163,7 @@
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Hide window to system tray instead of App Exit</string>
|
<string>Hide window to system tray instead of app exit</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
@ -177,26 +174,10 @@
|
||||||
<property name="sizeConstraint">
|
<property name="sizeConstraint">
|
||||||
<enum>QLayout::SetMaximumSize</enum>
|
<enum>QLayout::SetMaximumSize</enum>
|
||||||
</property>
|
</property>
|
||||||
<item>
|
|
||||||
<spacer name="horizontalSpacer_3">
|
|
||||||
<property name="orientation">
|
|
||||||
<enum>Qt::Horizontal</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeHint" stdset="0">
|
|
||||||
<size>
|
|
||||||
<width>60</width>
|
|
||||||
<height>20</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</spacer>
|
|
||||||
</item>
|
|
||||||
<item>
|
<item>
|
||||||
<widget class="QCheckBox" name="systrayMinimizeOnStartup">
|
<widget class="QCheckBox" name="systrayMinimizeOnStartup">
|
||||||
<property name="enabled">
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Hide window to system tray on App start</string>
|
<string>Minimize window at application startup</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|
|
@ -86,8 +86,8 @@ int main(int argc, char** argv)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
MainWindow mainWindow;
|
MainWindow mainWindow;
|
||||||
mainWindow.show();
|
|
||||||
app.setMainWindow(&mainWindow);
|
app.setMainWindow(&mainWindow);
|
||||||
|
mainWindow.show();
|
||||||
|
|
||||||
QObject::connect(&app, SIGNAL(openFile(QString)), &mainWindow, SLOT(openDatabase(QString)));
|
QObject::connect(&app, SIGNAL(openFile(QString)), &mainWindow, SLOT(openDatabase(QString)));
|
||||||
|
|
||||||
|
@ -112,5 +112,10 @@ int main(int argc, char** argv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// start minimized if configured
|
||||||
|
if (config()->get("GUI/MinimizeOnStartup").toBool()) {
|
||||||
|
mainWindow.minimizeWindow();
|
||||||
|
}
|
||||||
|
|
||||||
return app.exec();
|
return app.exec();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue