diff --git a/share/translations/keepassxc_en.ts b/share/translations/keepassxc_en.ts index 16efe642ff..4474a32b8f 100644 --- a/share/translations/keepassxc_en.ts +++ b/share/translations/keepassxc_en.ts @@ -1551,6 +1551,10 @@ Backup database located at %2 Database file read error. + + No file path was provided. + + DatabaseOpenDialog diff --git a/src/core/Database.cpp b/src/core/Database.cpp index ab3d09ba28..073bce47e4 100644 --- a/src/core/Database.cpp +++ b/src/core/Database.cpp @@ -107,10 +107,6 @@ QUuid Database::uuid() const */ bool Database::open(QSharedPointer key, QString* error) { - Q_ASSERT(!m_data.filePath.isEmpty()); - if (m_data.filePath.isEmpty()) { - return false; - } return open(m_data.filePath, std::move(key), error); } @@ -126,6 +122,13 @@ bool Database::open(QSharedPointer key, QString* error) */ bool Database::open(const QString& filePath, QSharedPointer key, QString* error) { + if (filePath.isEmpty()) { + if (error) { + *error = tr("No file path was provided."); + } + return false; + } + QFile dbFile(filePath); if (!dbFile.exists()) { if (error) { diff --git a/src/gui/DatabaseTabWidget.cpp b/src/gui/DatabaseTabWidget.cpp index 8fb210e9bd..e414a15ef1 100644 --- a/src/gui/DatabaseTabWidget.cpp +++ b/src/gui/DatabaseTabWidget.cpp @@ -25,6 +25,7 @@ #include "core/Tools.h" #include "format/CsvExporter.h" #include "gui/Clipboard.h" +#include "gui/DatabaseIcons.h" #include "gui/DatabaseOpenDialog.h" #include "gui/DatabaseWidget.h" #include "gui/DatabaseWidgetStateSync.h" @@ -656,6 +657,12 @@ void DatabaseTabWidget::updateTabName(int index) index = indexOf(dbWidget); setTabText(index, tabName(index)); setTabToolTip(index, dbWidget->displayFilePath()); + auto iconIndex = dbWidget->database()->publicIcon(); + if (iconIndex >= 0 && iconIndex < databaseIcons()->count()) { + setTabIcon(index, databaseIcons()->icon(iconIndex)); + } else { + setTabIcon(index, {}); + } emit tabNameChanged(); } diff --git a/src/gui/DatabaseWidget.cpp b/src/gui/DatabaseWidget.cpp index ebe7c6db1e..90f2fecb59 100644 --- a/src/gui/DatabaseWidget.cpp +++ b/src/gui/DatabaseWidget.cpp @@ -92,6 +92,11 @@ DatabaseWidget::DatabaseWidget(QSharedPointer db, QWidget* parent) { Q_ASSERT(m_db); + // Read public headers if the database hasn't been opened yet + if (!m_db->isInitialized()) { + m_db->open(nullptr); + } + m_messageWidget->setHidden(true); auto mainLayout = new QVBoxLayout(); @@ -1929,6 +1934,7 @@ bool DatabaseWidget::lock() switchToOpenDatabase(m_db->filePath()); auto newDb = QSharedPointer::create(m_db->filePath()); + newDb->open(nullptr); replaceDatabase(newDb); m_attemptingLock = false;