diff --git a/src/core/Bootstrap.cpp b/src/core/Bootstrap.cpp index 1950735ae2..a06bf74c1d 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 90b851bd9e..849df03aeb 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 ffcfea2be9..85b3b4700e 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 798971bfe8..8885ef7cb4 100644 --- a/src/gui/ApplicationSettingsWidgetGeneral.ui +++ b/src/gui/ApplicationSettingsWidgetGeneral.ui @@ -50,19 +50,16 @@ - + - Remember last databases - - - true + Minimize window at application startup - + - Remember last key files and security dongles + Remember previously used databases true @@ -70,18 +67,76 @@ - - - Load previous databases on startup + + + 0 - + + QLayout::SetMaximumSize + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 20 + 20 + + + + + + + + Load previously open databases on startup + + + true + + + + - - - Minimize window at application startup + + + 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/DatabaseTabWidget.cpp b/src/gui/DatabaseTabWidget.cpp index c908a82ec1..7693c90169 100644 --- a/src/gui/DatabaseTabWidget.cpp +++ b/src/gui/DatabaseTabWidget.cpp @@ -137,10 +137,15 @@ void DatabaseTabWidget::openDatabase() * database has been opened already. * * @param filePath database file path - * @param password optional, password to unlock database * @param inBackground optional, don't focus tab after opening + * @param password optional, password to unlock database + * @param keyfile optional, path to keyfile to unlock database + * */ -void DatabaseTabWidget::addDatabaseTab(const QString& filePath, bool inBackground, const QString& password) +void DatabaseTabWidget::addDatabaseTab(const QString& filePath, + bool inBackground, + const QString& password, + const QString& keyfile) { QFileInfo fileInfo(filePath); QString canonicalFilePath = fileInfo.canonicalFilePath(); @@ -154,7 +159,7 @@ void DatabaseTabWidget::addDatabaseTab(const QString& filePath, bool inBackgroun Q_ASSERT(dbWidget); if (dbWidget && dbWidget->database()->filePath() == canonicalFilePath) { if (!password.isEmpty()) { - dbWidget->performUnlockDatabase(password); + dbWidget->performUnlockDatabase(password, keyfile); } if (!inBackground) { // switch to existing tab if file is already open @@ -167,7 +172,7 @@ void DatabaseTabWidget::addDatabaseTab(const QString& filePath, bool inBackgroun auto* dbWidget = new DatabaseWidget(QSharedPointer::create(filePath), this); addDatabaseTab(dbWidget, inBackground); if (!password.isEmpty()) { - dbWidget->performUnlockDatabase(password); + dbWidget->performUnlockDatabase(password, keyfile); } updateLastDatabases(filePath); } diff --git a/src/gui/DatabaseTabWidget.h b/src/gui/DatabaseTabWidget.h index eda28839a2..bafbfa37af 100644 --- a/src/gui/DatabaseTabWidget.h +++ b/src/gui/DatabaseTabWidget.h @@ -48,7 +48,10 @@ class DatabaseTabWidget : public QTabWidget bool hasLockableDatabases() const; public slots: - void addDatabaseTab(const QString& filePath, bool inBackground = false, const QString& password = {}); + void addDatabaseTab(const QString& filePath, + bool inBackground = false, + const QString& password = {}, + const QString& keyfile = {}); void addDatabaseTab(DatabaseWidget* dbWidget, bool inBackground = false); bool closeDatabaseTab(int index); bool closeDatabaseTab(DatabaseWidget* dbWidget); diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 6e3c96af0c..3683021a4f 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -494,28 +494,9 @@ void MainWindow::clearLastDatabases() } } -void MainWindow::openDatabase(const QString& filePath, const QString& pw, const QString& keyFile) +void MainWindow::openDatabase(const QString& filePath, const QString& password, const QString& keyfile) { - if (pw.isEmpty() && keyFile.isEmpty()) { - m_ui->tabWidget->addDatabaseTab(filePath); - return; - } - - auto db = QSharedPointer::create(); - auto key = QSharedPointer::create(); - if (!pw.isEmpty()) { - key->addKey(QSharedPointer::create(pw)); - } - if (!keyFile.isEmpty()) { - auto fileKey = QSharedPointer::create(); - fileKey->load(keyFile); - key->addKey(fileKey); - } - if (db->open(filePath, key, nullptr, false)) { - auto* dbWidget = new DatabaseWidget(db, this); - m_ui->tabWidget->addDatabaseTab(dbWidget); - dbWidget->switchToMainView(true); - } + m_ui->tabWidget->addDatabaseTab(filePath, false, password, keyfile); } void MainWindow::setMenuActionState(DatabaseWidget::Mode mode) @@ -920,24 +901,27 @@ void MainWindow::saveWindowInformation() bool MainWindow::saveLastDatabases() { - bool accept; - m_openDatabases.clear(); - bool openPreviousDatabasesOnStartup = config()->get("OpenPreviousDatabasesOnStartup").toBool(); - - if (openPreviousDatabasesOnStartup) { - connect( - m_ui->tabWidget, SIGNAL(databaseClosed(const QString&)), this, SLOT(rememberOpenDatabases(const QString&))); - } + if (config()->get("OpenPreviousDatabasesOnStartup").toBool()) { + auto currentDbWidget = m_ui->tabWidget->currentDatabaseWidget(); + if (currentDbWidget) { + config()->set("LastActiveDatabase", currentDbWidget->database()->filePath()); + } else { + config()->set("LastActiveDatabase", {}); + } - accept = m_ui->tabWidget->closeAllDatabaseTabs(); + QStringList openDatabases; + for (int i=0; i < m_ui->tabWidget->count(); ++i) { + auto dbWidget = m_ui->tabWidget->databaseWidgetFromIndex(i); + openDatabases.append(dbWidget->database()->filePath()); + } - if (openPreviousDatabasesOnStartup) { - disconnect( - m_ui->tabWidget, SIGNAL(databaseClosed(const QString&)), this, SLOT(rememberOpenDatabases(const QString&))); - config()->set("LastOpenedDatabases", m_openDatabases); + config()->set("LastOpenedDatabases", openDatabases); + } else { + config()->set("LastActiveDatabase", {}); + config()->set("LastOpenedDatabases", {}); } - return accept; + return m_ui->tabWidget->closeAllDatabaseTabs(); } void MainWindow::updateTrayIcon() @@ -1002,11 +986,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 cd7b1a39bd..5a72d6f027 100644 --- a/src/gui/MainWindow.h +++ b/src/gui/MainWindow.h @@ -56,7 +56,7 @@ class MainWindow : public QMainWindow }; public slots: - void openDatabase(const QString& filePath, const QString& pw = {}, const QString& keyFile = {}); + void openDatabase(const QString& filePath, const QString& password = {}, const QString& keyfile = {}); void appExit(); void displayGlobalMessage(const QString& text, MessageWidget::MessageType type, @@ -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 slots: QAction* m_searchWidgetAction; QActionGroup* m_lastDatabasesActions; QActionGroup* m_copyAdditionalAttributeActions; - QStringList m_openDatabases; InactivityTimer* m_inactivityTimer; InactivityTimer* m_touchIDinactivityTimer; int m_countDefaultAttributes;