diff --git a/src/gui/DatabaseTabWidget.cpp b/src/gui/DatabaseTabWidget.cpp index df0e1a1da..b443aba10 100644 --- a/src/gui/DatabaseTabWidget.cpp +++ b/src/gui/DatabaseTabWidget.cpp @@ -129,7 +129,13 @@ void DatabaseTabWidget::openDatabase(const QString& fileName, const QString& pw, while (i.hasNext()) { i.next(); if (i.value().canonicalFilePath == canonicalFilePath) { - setCurrentIndex(databaseIndex(i.key())); + if (pw.isEmpty() && keyFile.isEmpty()) { + setCurrentIndex(databaseIndex(i.key())); + } else { + if (!i.key()->hasKey()) { + i.value().dbWidget->switchToOpenDatabase(canonicalFilePath, pw, keyFile); + } + } return; } } @@ -607,6 +613,39 @@ void DatabaseTabWidget::updateTabNameFromDbWidgetSender() DatabaseWidget* dbWidget = static_cast(sender()); updateTabName(databaseFromDatabaseWidget(dbWidget)); + + Database* db = dbWidget->database(); + Group *autoload = db->rootGroup()->findChildByName("AutoOpen"); + if (autoload) + { + const DatabaseManagerStruct& dbStruct = m_dbList.value(db); + QFileInfo dbpath(dbStruct.canonicalFilePath); + QDir dbFolder(dbpath.canonicalPath()); + + for (auto entry : autoload->entries()) { + + if (entry->url().isEmpty() || entry->password().isEmpty()) + continue; + + QFileInfo filepath; + if (entry->url().startsWith("file:/")) { + QUrl url(entry->url()); + filepath.setFile(url.toLocalFile()); + } + else { + filepath.setFile(entry->url()); + if (filepath.isRelative()) { + filepath.setFile(dbFolder, entry->url()); + } + } + + if (!filepath.isFile()) + continue; + + openDatabase(filepath.canonicalFilePath(), entry->password(), ""); + + } + } } int DatabaseTabWidget::databaseIndex(Database* db) diff --git a/src/gui/DatabaseWidget.cpp b/src/gui/DatabaseWidget.cpp index 3a39bddcf..e5693e4f9 100644 --- a/src/gui/DatabaseWidget.cpp +++ b/src/gui/DatabaseWidget.cpp @@ -897,8 +897,13 @@ void DatabaseWidget::switchToDatabaseSettings() void DatabaseWidget::switchToOpenDatabase(const QString& fileName) { updateFilename(fileName); - m_databaseOpenWidget->load(fileName); - setCurrentWidget(m_databaseOpenWidget); + if (m_databaseOpenWidget) { + m_databaseOpenWidget->load(fileName); + setCurrentWidget(m_databaseOpenWidget); + } else if (m_unlockDatabaseWidget) { + m_unlockDatabaseWidget->load(fileName); + setCurrentWidget(m_unlockDatabaseWidget); + } } void DatabaseWidget::switchToOpenDatabase(const QString& fileName, const QString& password, @@ -906,7 +911,11 @@ void DatabaseWidget::switchToOpenDatabase(const QString& fileName, const QString { updateFilename(fileName); switchToOpenDatabase(fileName); - m_databaseOpenWidget->enterKey(password, keyFile); + if (m_databaseOpenWidget) { + m_databaseOpenWidget->enterKey(password, keyFile); + } else if (m_unlockDatabaseWidget) { + m_unlockDatabaseWidget->enterKey(password, keyFile); + } } void DatabaseWidget::switchToImportCsv(const QString& fileName)