Skip to content

Commit

Permalink
Show database public icon on tab when visible (#11725)
Browse files Browse the repository at this point in the history
* Show database public icon on tab when visible

* Remove unnecessary assert
  • Loading branch information
droidmonkey committed Feb 11, 2025
1 parent 3083626 commit 3b2f54d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
4 changes: 4 additions & 0 deletions share/translations/keepassxc_en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1551,6 +1551,10 @@ Backup database located at %2</source>
<source>Database file read error.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>No file path was provided.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>DatabaseOpenDialog</name>
Expand Down
11 changes: 7 additions & 4 deletions src/core/Database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,6 @@ QUuid Database::uuid() const
*/
bool Database::open(QSharedPointer<const CompositeKey> 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);
}

Expand All @@ -126,6 +122,13 @@ bool Database::open(QSharedPointer<const CompositeKey> key, QString* error)
*/
bool Database::open(const QString& filePath, QSharedPointer<const CompositeKey> 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) {
Expand Down
7 changes: 7 additions & 0 deletions src/gui/DatabaseTabWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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();
}

Expand Down
6 changes: 6 additions & 0 deletions src/gui/DatabaseWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ DatabaseWidget::DatabaseWidget(QSharedPointer<Database> 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();
Expand Down Expand Up @@ -1929,6 +1934,7 @@ bool DatabaseWidget::lock()
switchToOpenDatabase(m_db->filePath());

auto newDb = QSharedPointer<Database>::create(m_db->filePath());
newDb->open(nullptr);
replaceDatabase(newDb);

m_attemptingLock = false;
Expand Down

0 comments on commit 3b2f54d

Please sign in to comment.