diff --git a/src/core/Bootstrap.cpp b/src/core/Bootstrap.cpp index 1950735ae..a06bf74c1 100644 --- a/src/core/Bootstrap.cpp +++ b/src/core/Bootstrap.cpp @@ -112,6 +112,10 @@ namespace Bootstrap mainWindow.openDatabase(filename); } } + auto lastActiveFile = config()->get("LastActiveDatabase").toString(); + if (!lastActiveFile.isEmpty()) { + mainWindow.openDatabase(lastActiveFile); + } } } diff --git a/src/gui/ApplicationSettingsWidget.cpp b/src/gui/ApplicationSettingsWidget.cpp index 90b851bd9..849df03ae 100644 --- a/src/gui/ApplicationSettingsWidget.cpp +++ b/src/gui/ApplicationSettingsWidget.cpp @@ -81,7 +81,8 @@ ApplicationSettingsWidget::ApplicationSettingsWidget(QWidget* parent) // clang-format off connect(m_generalUi->autoSaveAfterEveryChangeCheckBox, SIGNAL(toggled(bool)), SLOT(autoSaveToggled(bool))); connect(m_generalUi->systrayShowCheckBox, SIGNAL(toggled(bool)), SLOT(systrayToggled(bool))); - connect(m_generalUi->toolbarHideCheckBox, SIGNAL(toggled(bool)), SLOT(enableToolbarSettings(bool))); + connect(m_generalUi->toolbarHideCheckBox, SIGNAL(toggled(bool)), SLOT(toolbarSettingsToggled(bool))); + connect(m_generalUi->rememberLastDatabasesCheckBox, SIGNAL(toggled(bool)), SLOT(rememberDatabasesToggled(bool))); connect(m_secUi->clearClipboardCheckBox, SIGNAL(toggled(bool)), m_secUi->clearClipboardSpinBox, SLOT(setEnabled(bool))); @@ -294,11 +295,13 @@ void ApplicationSettingsWidget::saveSettings() // Security: clear storage if related settings are disabled if (!config()->get("RememberLastDatabases").toBool()) { - config()->set("LastDatabases", QVariant()); + config()->set("LastDatabases", {}); + config()->set("OpenPreviousDatabasesOnStartup", {}); + config()->set("LastActiveDatabase", {}); } if (!config()->get("RememberLastKeyFiles").toBool()) { - config()->set("LastKeyFiles", QVariant()); + config()->set("LastKeyFiles", {}); config()->set("LastDir", ""); } @@ -330,9 +333,20 @@ void ApplicationSettingsWidget::systrayToggled(bool checked) m_generalUi->systrayMinimizeToTrayCheckBox->setEnabled(checked); } -void ApplicationSettingsWidget::enableToolbarSettings(bool checked) +void ApplicationSettingsWidget::toolbarSettingsToggled(bool checked) { m_generalUi->toolbarMovableCheckBox->setEnabled(!checked); m_generalUi->toolButtonStyleComboBox->setEnabled(!checked); m_generalUi->toolButtonStyleLabel->setEnabled(!checked); } + +void ApplicationSettingsWidget::rememberDatabasesToggled(bool checked) +{ + if (!checked) { + m_generalUi->rememberLastKeyFilesCheckBox->setChecked(false); + m_generalUi->openPreviousDatabasesOnStartupCheckBox->setChecked(false); + } + + m_generalUi->rememberLastKeyFilesCheckBox->setEnabled(checked); + m_generalUi->openPreviousDatabasesOnStartupCheckBox->setEnabled(checked); +} diff --git a/src/gui/ApplicationSettingsWidget.h b/src/gui/ApplicationSettingsWidget.h index ffcfea2be..85b3b4700 100644 --- a/src/gui/ApplicationSettingsWidget.h +++ b/src/gui/ApplicationSettingsWidget.h @@ -55,7 +55,8 @@ private slots: void reject(); void autoSaveToggled(bool checked); void systrayToggled(bool checked); - void enableToolbarSettings(bool checked); + void toolbarSettingsToggled(bool checked); + void rememberDatabasesToggled(bool checked); private: QWidget* const m_secWidget; diff --git a/src/gui/ApplicationSettingsWidgetGeneral.ui b/src/gui/ApplicationSettingsWidgetGeneral.ui index 798971bfe..8885ef7cb 100644 --- a/src/gui/ApplicationSettingsWidgetGeneral.ui +++ b/src/gui/ApplicationSettingsWidgetGeneral.ui @@ -49,33 +49,6 @@ - - - - Remember last databases - - - true - - - - - - - Remember last key files and security dongles - - - true - - - - - - - Load previous databases on startup - - - @@ -83,6 +56,88 @@ + + + + Remember previously used databases + + + true + + + + + + + 0 + + + QLayout::SetMaximumSize + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 20 + 20 + + + + + + + + Load previously open databases on startup + + + true + + + + + + + + + 0 + + + QLayout::SetMaximumSize + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 20 + 20 + + + + + + + + Remember database key files and security dongles + + + true + + + + + @@ -218,7 +273,7 @@ - 40 + 20 20 @@ -245,7 +300,7 @@ - 15 + 0 @@ -257,7 +312,7 @@ - 40 + 20 20 @@ -274,8 +329,11 @@ 0 + + margin-right: 5px + - Button style + Button style: @@ -326,7 +384,7 @@ - 40 + 20 20 @@ -377,7 +435,7 @@ - 40 + 20 20 @@ -407,7 +465,7 @@ - 15 + 8 @@ -418,7 +476,7 @@ - Language + Language: diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 03fa54945..9e60b53e2 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -903,24 +903,27 @@ void MainWindow::saveWindowInformation() bool MainWindow::saveLastDatabases() { - bool accept; - m_openDatabases.clear(); - bool openPreviousDatabasesOnStartup = config()->get("OpenPreviousDatabasesOnStartup").toBool(); + if (config()->get("OpenPreviousDatabasesOnStartup").toBool()) { + auto currentDbWidget = m_ui->tabWidget->currentDatabaseWidget(); + if (currentDbWidget) { + config()->set("LastActiveDatabase", currentDbWidget->database()->filePath()); + } else { + config()->set("LastActiveDatabase", {}); + } - if (openPreviousDatabasesOnStartup) { - connect( - m_ui->tabWidget, SIGNAL(databaseClosed(const QString&)), this, SLOT(rememberOpenDatabases(const QString&))); + QStringList openDatabases; + for (int i=0; i < m_ui->tabWidget->count(); ++i) { + auto dbWidget = m_ui->tabWidget->databaseWidgetFromIndex(i); + openDatabases.append(dbWidget->database()->filePath()); + } + + config()->set("LastOpenedDatabases", openDatabases); + } else { + config()->set("LastActiveDatabase", {}); + config()->set("LastOpenedDatabases", {}); } - accept = m_ui->tabWidget->closeAllDatabaseTabs(); - - if (openPreviousDatabasesOnStartup) { - disconnect( - m_ui->tabWidget, SIGNAL(databaseClosed(const QString&)), this, SLOT(rememberOpenDatabases(const QString&))); - config()->set("LastOpenedDatabases", m_openDatabases); - } - - return accept; + return m_ui->tabWidget->closeAllDatabaseTabs(); } void MainWindow::updateTrayIcon() @@ -985,11 +988,6 @@ void MainWindow::setShortcut(QAction* action, QKeySequence::StandardKey standard } } -void MainWindow::rememberOpenDatabases(const QString& filePath) -{ - m_openDatabases.prepend(filePath); -} - void MainWindow::applySettingsChanges() { int timeout = config()->get("security/lockdatabaseidlesec").toInt() * 1000; diff --git a/src/gui/MainWindow.h b/src/gui/MainWindow.h index 14083da70..5a72d6f02 100644 --- a/src/gui/MainWindow.h +++ b/src/gui/MainWindow.h @@ -105,7 +105,6 @@ private slots: void updateCopyAttributesMenu(); void showEntryContextMenu(const QPoint& globalPos); void showGroupContextMenu(const QPoint& globalPos); - void rememberOpenDatabases(const QString& filePath); void applySettingsChanges(); void trayIconTriggered(QSystemTrayIcon::ActivationReason reason); void lockDatabasesAfterInactivity(); @@ -137,7 +136,6 @@ private: QAction* m_searchWidgetAction; QActionGroup* m_lastDatabasesActions; QActionGroup* m_copyAdditionalAttributeActions; - QStringList m_openDatabases; InactivityTimer* m_inactivityTimer; InactivityTimer* m_touchIDinactivityTimer; int m_countDefaultAttributes;