Skip to content

Commit

Permalink
Fix minimize at startup and decouple various tray and minimization op…
Browse files Browse the repository at this point in the history
…tions (keepassxreboot#109)

* Hide window on startup when configured to start minimized, fixes keepassxreboot#105
* Decouple different systray and minimization options, fixes keepassxreboot#64
* Commit missing changes in main.cpp to minimize at startup

* Remove obsolete code
  • Loading branch information
phoerious authored and droidmonkey committed Nov 23, 2016
1 parent 02d2ac9 commit 19a9608
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 60 deletions.
6 changes: 0 additions & 6 deletions src/gui/DatabaseOpenWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,6 @@ void DatabaseOpenWidget::openDatabase()

if (m_db) {
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 {
MessageBox::warning(this, tr("Error"), tr("Unable to open the database.").append("\n")
Expand Down
11 changes: 4 additions & 7 deletions src/gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,14 +329,12 @@ void MainWindow::openDatabase(const QString& fileName, const QString& pw, const
m_ui->tabWidget->openDatabase(fileName, pw, keyFile);
}

void MainWindow::configuredMinimizeWindow()
void MainWindow::minimizeWindow()
{
bool minimize = isTrayIconEnabled() &&
config()->get("GUI/MinimizeToTray").toBool() &&
config()->get("GUI/MinimizeOnClose").toBool() &&
config()->get("GUI/MinimizeOnStartup").toBool();
if (minimize) {
if (isTrayIconEnabled() && config()->get("GUI/MinimizeToTray").toBool()) {
hide();
} else {
setWindowState(Qt::WindowMinimized);
}
}

Expand Down Expand Up @@ -523,7 +521,6 @@ void MainWindow::databaseTabChanged(int tabIndex)
void MainWindow::closeEvent(QCloseEvent* event)
{
bool minimizeOnClose = isTrayIconEnabled() &&
config()->get("GUI/MinimizeToTray").toBool() &&
config()->get("GUI/MinimizeOnClose").toBool();
if (minimizeOnClose && !appExitCalled)
{
Expand Down
2 changes: 1 addition & 1 deletion src/gui/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class MainWindow : public QMainWindow
public:
MainWindow();
~MainWindow();
void configuredMinimizeWindow();
void minimizeWindow();

public Q_SLOTS:
void openDatabase(const QString& fileName, const QString& pw = QString(),
Expand Down
18 changes: 2 additions & 16 deletions src/gui/SettingsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,7 @@ SettingsWidget::SettingsWidget(QWidget* parent)
connect(m_generalUi->autoSaveAfterEveryChangeCheckBox, SIGNAL(toggled(bool)),
this, SLOT(enableAutoSaveOnExit(bool)));
connect(m_generalUi->systrayShowCheckBox, SIGNAL(toggled(bool)),
this, SLOT(enableSystrayMinimizeToTray(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)));
this, SLOT(enableSystray(bool)));

connect(m_secUi->clearClipboardCheckBox, SIGNAL(toggled(bool)),
m_secUi->clearClipboardSpinBox, SLOT(setEnabled(bool)));
Expand Down Expand Up @@ -209,18 +205,8 @@ void SettingsWidget::enableAutoSaveOnExit(bool checked)
m_generalUi->autoSaveOnExitCheckBox->setEnabled(!checked);
}

void SettingsWidget::enableSystrayMinimizeToTray(bool checked)
void SettingsWidget::enableSystray(bool 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);
bool checked2 = m_generalUi->systrayMinimizeOnCloseCheckBox->checkState();
m_generalUi->systrayMinimizeOnStartup->setEnabled(checked && checked2);
}
3 changes: 1 addition & 2 deletions src/gui/SettingsWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ private Q_SLOTS:
void saveSettings();
void reject();
void enableAutoSaveOnExit(bool checked);
void enableSystrayMinimizeToTray(bool checked);
void enableSystrayMinimizeToTray2(bool checked);
void enableSystray(bool checked);

private:
QWidget* const m_secWidget;
Expand Down
29 changes: 5 additions & 24 deletions src/gui/SettingsWidgetGeneral.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>684</width>
<height>394</height>
<height>452</height>
</rect>
</property>
<layout class="QFormLayout" name="formLayout">
Expand Down Expand Up @@ -37,7 +37,7 @@
<item row="2" column="0">
<widget class="QCheckBox" name="openPreviousDatabasesOnStartupCheckBox">
<property name="text">
<string>Open previous databases on startup</string>
<string>Load previous databases on startup</string>
</property>
</widget>
</item>
Expand Down Expand Up @@ -113,12 +113,9 @@
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<width>40</width>
<height>20</height>
</size>
</property>
Expand Down Expand Up @@ -166,7 +163,7 @@
<bool>false</bool>
</property>
<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>
</widget>
</item>
Expand All @@ -177,26 +174,10 @@
<property name="sizeConstraint">
<enum>QLayout::SetMaximumSize</enum>
</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>
<widget class="QCheckBox" name="systrayMinimizeOnStartup">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Hide window to system tray on App start</string>
<string>Minimize window at application startup</string>
</property>
</widget>
</item>
Expand Down
13 changes: 9 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ int main(int argc, char** argv)
#endif

MainWindow mainWindow;
mainWindow.show();
app.setMainWindow(&mainWindow);

mainWindow.show();

QObject::connect(&app, SIGNAL(openFile(QString)), &mainWindow, SLOT(openDatabase(QString)));

for (int ii=0; ii < args.length(); ii++) {
QString filename = args[ii];
if (!filename.isEmpty() && QFile::exists(filename)) {
Expand All @@ -111,6 +111,11 @@ int main(int argc, char** argv)
}
}
}


// start minimized if configured
if (config()->get("GUI/MinimizeOnStartup").toBool()) {
mainWindow.minimizeWindow();
}

return app.exec();
}

0 comments on commit 19a9608

Please sign in to comment.