Add database name, color, and icon options for unlock view (#10819)

Closes #10783

Adds three database configuration options (stored as public custom data) that allow a database to have a public name/summary, color, and/or icon to be displayed on the unlock screen. This information is configured in the Database Settings and stored in the database public custom data (ie, unencrypted).

The name/summary is stored in KPXC_PUBLIC_NAME, the color is stored in KPXC_PUBLIC_COLOR, and the icon is stored in KPXC_PUBLIC_ICON.

---------

Co-authored-by: Jonathan White <support@dmapps.us>
This commit is contained in:
techninja1008 2024-10-08 04:42:22 +01:00 committed by GitHub
parent 7498fe24dc
commit dbf9587775
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 437 additions and 28 deletions

View File

@ -2194,6 +2194,50 @@ removed from the database.</source>
<source>Autosave delay since last change checkbox</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Public Database Metadata</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Warning: the following settings are not encrypted.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Display name:</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Publically visible display name used on the unlock dialog</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Database public display name</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Display color:</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Publically visible color used on the unlock dialog</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Database public display color chooser</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Clear</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Display icon:</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Select Database Icon</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>DatabaseSettingsWidgetKeeShare</name>

View File

@ -1051,6 +1051,54 @@ QUuid Database::publicUuid()
return QUuid::fromRfc4122(publicCustomData()["KPXC_PUBLIC_UUID"].toByteArray());
}
QString Database::publicName()
{
return publicCustomData().value("KPXC_PUBLIC_NAME").toString();
}
void Database::setPublicName(const QString& name)
{
if (name.isEmpty()) {
publicCustomData().remove("KPXC_PUBLIC_NAME");
} else {
publicCustomData().insert("KPXC_PUBLIC_NAME", name);
}
markAsModified();
}
QString Database::publicColor()
{
return publicCustomData().value("KPXC_PUBLIC_COLOR").toString();
}
void Database::setPublicColor(const QString& color)
{
if (color.isEmpty()) {
publicCustomData().remove("KPXC_PUBLIC_COLOR");
} else {
publicCustomData().insert("KPXC_PUBLIC_COLOR", color);
}
markAsModified();
}
int Database::publicIcon()
{
if (publicCustomData().contains("KPXC_PUBLIC_ICON")) {
return publicCustomData().value("KPXC_PUBLIC_ICON").toInt();
}
return -1;
}
void Database::setPublicIcon(int iconIndex)
{
if (iconIndex < 0) {
publicCustomData().remove("KPXC_PUBLIC_ICON");
} else {
publicCustomData().insert("KPXC_PUBLIC_ICON", iconIndex);
}
markAsModified();
}
void Database::markAsTemporaryDatabase()
{
m_isTemporaryDatabase = true;

View File

@ -108,6 +108,13 @@ public:
QString canonicalFilePath() const;
void setFilePath(const QString& filePath);
QString publicName();
void setPublicName(const QString& name);
QString publicColor();
void setPublicColor(const QString& color);
int publicIcon();
void setPublicIcon(int iconIndex);
Metadata* metadata();
const Metadata* metadata() const;
Group* rootGroup();

View File

@ -72,7 +72,6 @@ DatabaseOpenWidget::DatabaseOpenWidget(QWidget* parent)
font.setPointSize(font.pointSize() + 4);
font.setBold(true);
m_ui->labelHeadline->setFont(font);
m_ui->labelHeadline->setText(tr("Unlock KeePassXC Database"));
m_ui->quickUnlockButton->setFont(font);
m_ui->quickUnlockButton->setIcon(
@ -229,6 +228,31 @@ void DatabaseOpenWidget::load(const QString& filename)
m_ui->fileNameLabel->setRawText(m_filename);
// Set the public name if defined
auto label = tr("Unlock KeePassXC Database");
if (!m_db->publicName().isEmpty()) {
label.append(QString(": %1").arg(m_db->publicName()));
}
m_ui->labelHeadline->setText(label);
// Apply the public color to the central unlock stack if defined
auto color = m_db->publicColor();
if (!color.isEmpty()) {
m_ui->centralStack->setStyleSheet(QString("QStackedWidget {border: 4px solid %1}").arg(color));
} else {
m_ui->centralStack->setStyleSheet("");
}
// Show the database icon if defined
auto iconIndex = m_db->publicIcon();
if (iconIndex >= 0 && iconIndex < databaseIcons()->count()) {
m_ui->dbIconLabel->setPixmap(databaseIcons()->icon(iconIndex, IconSize::Large));
m_ui->dbIconLabel->setVisible(true);
} else {
m_ui->dbIconLabel->setPixmap({});
m_ui->dbIconLabel->setVisible(false);
}
if (config()->get(Config::RememberLastKeyFiles).toBool()) {
auto lastKeyFiles = config()->get(Config::LastKeyFiles).toHash();
if (lastKeyFiles.contains(m_filename)) {

View File

@ -54,6 +54,27 @@
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>9</number>
</property>
<item>
<widget class="QLabel" name="dbIconLabel">
<property name="minimumSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="labelHeadline">
<property name="font">
@ -68,6 +89,21 @@
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="ElidedLabel" name="fileNameLabel">
<property name="text">

View File

@ -18,9 +18,16 @@
#include "DatabaseSettingsWidgetGeneral.h"
#include "ui_DatabaseSettingsWidgetGeneral.h"
#include <QColorDialog>
#include <QDialogButtonBox>
#include <QInputDialog>
#include <QListView>
#include "core/Clock.h"
#include "core/Group.h"
#include "core/Metadata.h"
#include "gui/DatabaseIcons.h"
#include "gui/IconModels.h"
#include "gui/MessageBox.h"
DatabaseSettingsWidgetGeneral::DatabaseSettingsWidgetGeneral(QWidget* parent)
@ -29,6 +36,11 @@ DatabaseSettingsWidgetGeneral::DatabaseSettingsWidgetGeneral(QWidget* parent)
{
m_ui->setupUi(this);
connect(m_ui->dbPublicColorButton, &QPushButton::clicked, this, &DatabaseSettingsWidgetGeneral::pickPublicColor);
connect(m_ui->dbPublicColorClearButton, &QPushButton::clicked, this, [this] { setupPublicColorButton({}); });
connect(m_ui->dbPublicIconButton, &QPushButton::clicked, this, &DatabaseSettingsWidgetGeneral::pickPublicIcon);
connect(m_ui->dbPublicIconClearButton, &QPushButton::clicked, this, [this] { setupPublicIconButton(-1); });
connect(m_ui->historyMaxItemsCheckBox, SIGNAL(toggled(bool)), m_ui->historyMaxItemsSpinBox, SLOT(setEnabled(bool)));
connect(m_ui->historyMaxSizeCheckBox, SIGNAL(toggled(bool)), m_ui->historyMaxSizeSpinBox, SLOT(setEnabled(bool)));
connect(m_ui->autosaveDelayCheckBox, SIGNAL(toggled(bool)), m_ui->autosaveDelaySpinBox, SLOT(setEnabled(bool)));
@ -46,6 +58,10 @@ void DatabaseSettingsWidgetGeneral::initialize()
m_ui->defaultUsernameEdit->setText(meta->defaultUserName());
m_ui->compressionCheckbox->setChecked(m_db->compressionAlgorithm() != Database::CompressionNone);
m_ui->dbPublicName->setText(m_db->publicName());
setupPublicColorButton(m_db->publicColor());
setupPublicIconButton(m_db->publicIcon());
if (meta->historyMaxItems() > -1) {
m_ui->historyMaxItemsSpinBox->setValue(meta->historyMaxItems());
m_ui->historyMaxItemsCheckBox->setChecked(true);
@ -116,6 +132,10 @@ bool DatabaseSettingsWidgetGeneral::saveSettings()
meta->setRecycleBinEnabled(m_ui->recycleBinEnabledCheckBox->isChecked());
meta->setSettingsChanged(Clock::currentDateTimeUtc());
m_db->setPublicName(m_ui->dbPublicName->text());
m_db->setPublicColor(m_ui->dbPublicColorButton->property("color").toString());
m_db->setPublicIcon(m_ui->dbPublicIconButton->property("iconIndex").toInt());
bool truncate = false;
int historyMaxItems;
@ -155,3 +175,79 @@ bool DatabaseSettingsWidgetGeneral::saveSettings()
return true;
}
void DatabaseSettingsWidgetGeneral::pickPublicColor()
{
auto oldColor = QColor(m_ui->dbPublicColorButton->property("color").toString());
auto newColor = QColorDialog::getColor(oldColor);
if (newColor.isValid()) {
setupPublicColorButton(newColor);
}
}
void DatabaseSettingsWidgetGeneral::setupPublicColorButton(const QColor& color)
{
m_ui->dbPublicColorClearButton->setVisible(color.isValid());
if (color.isValid()) {
m_ui->dbPublicColorButton->setStyleSheet(QString("background-color:%1").arg(color.name()));
m_ui->dbPublicColorButton->setProperty("color", color.name());
} else {
m_ui->dbPublicColorButton->setStyleSheet("");
m_ui->dbPublicColorButton->setProperty("color", {});
}
}
void DatabaseSettingsWidgetGeneral::pickPublicIcon()
{
QDialog dialog(this);
dialog.setSizeGripEnabled(false);
dialog.setWindowTitle(tr("Select Database Icon"));
auto iconList = new QListView;
iconList->setFlow(QListView::LeftToRight);
iconList->setMovement(QListView::Static);
iconList->setResizeMode(QListView::Adjust);
iconList->setWrapping(true);
iconList->setSpacing(4);
auto iconModel = new DefaultIconModel;
iconList->setModel(iconModel);
if (m_ui->dbPublicIconButton->property("iconIndex").toInt() >= 0) {
iconList->setCurrentIndex(iconModel->index(m_ui->dbPublicIconButton->property("iconIndex").toInt(), 0));
} else {
iconList->setCurrentIndex(iconModel->index(0, 0));
}
auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
auto layout = new QVBoxLayout(&dialog);
layout->addWidget(iconList);
layout->addWidget(buttonBox);
// Resize the dialog to fit the default icon list
auto cellSize = iconList->sizeHintForIndex(iconModel->index(0, 0));
auto spacing = iconList->spacing() * 2;
dialog.resize((cellSize.width() + spacing) * 15, (cellSize.height() + spacing) * 6 + 16);
connect(iconList, &QListView::doubleClicked, &dialog, &QDialog::accept);
connect(buttonBox, &QDialogButtonBox::accepted, &dialog, &QDialog::accept);
connect(buttonBox, &QDialogButtonBox::rejected, &dialog, &QDialog::reject);
connect(
&dialog, &QDialog::accepted, this, [this, iconList] { setupPublicIconButton(iconList->currentIndex().row()); });
dialog.exec();
}
void DatabaseSettingsWidgetGeneral::setupPublicIconButton(int iconIndex)
{
auto valid = iconIndex >= 0 && iconIndex < databaseIcons()->count();
m_ui->dbPublicIconClearButton->setVisible(valid);
if (valid) {
m_ui->dbPublicIconButton->setIcon(databaseIcons()->icon(iconIndex));
m_ui->dbPublicIconButton->setProperty("iconIndex", iconIndex);
m_ui->dbPublicIconClearButton->setVisible(true);
} else {
m_ui->dbPublicIconButton->setIcon(QIcon());
m_ui->dbPublicIconButton->setProperty("iconIndex", -1);
m_ui->dbPublicIconClearButton->setVisible(false);
}
}

View File

@ -20,6 +20,8 @@
#include "DatabaseSettingsWidget.h"
#include <QColor>
class Database;
namespace Ui
{
@ -43,6 +45,13 @@ public slots:
protected:
void showEvent(QShowEvent* event) override;
private slots:
void pickPublicColor();
void setupPublicColorButton(const QColor& color);
void pickPublicIcon();
void setupPublicIconButton(int iconIndex);
private:
const QScopedPointer<Ui::DatabaseSettingsWidgetGeneral> m_ui;
};

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>453</width>
<height>394</height>
<height>647</height>
</rect>
</property>
<property name="sizePolicy">
@ -92,6 +92,151 @@
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_4">
<property name="title">
<string>Public Database Metadata</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QLabel" name="warningLabel">
<property name="font">
<font>
<italic>true</italic>
</font>
</property>
<property name="text">
<string>Warning: the following settings are not encrypted.</string>
</property>
</widget>
</item>
<item>
<layout class="QFormLayout" name="formLayout_2">
<property name="topMargin">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="dbPublicSummaryLabel">
<property name="text">
<string>Display name:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="dbPublicName">
<property name="toolTip">
<string>Publically visible display name used on the unlock dialog</string>
</property>
<property name="accessibleName">
<string>Database public display name</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="dbPublicColorLabel">
<property name="text">
<string>Display color:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QPushButton" name="dbPublicColorButton">
<property name="maximumSize">
<size>
<width>30</width>
<height>30</height>
</size>
</property>
<property name="toolTip">
<string>Publically visible color used on the unlock dialog</string>
</property>
<property name="accessibleName">
<string>Database public display color chooser</string>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="dbPublicColorClearButton">
<property name="text">
<string>Clear</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="2" column="0">
<widget class="QLabel" name="dbPublicIconLabel">
<property name="text">
<string>Display icon:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QPushButton" name="dbPublicIconButton">
<property name="maximumSize">
<size>
<width>30</width>
<height>30</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="iconSize">
<size>
<width>30</width>
<height>30</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="dbPublicIconClearButton">
<property name="text">
<string>Clear</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
@ -113,6 +258,19 @@ of entries remain at most.</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="recycleBinEnabledCheckBox">
<property name="toolTip">
<string>Move entries to a recycle bin group
instead of deleting them from the database.
Entries deleted from the recycle bin are
removed from the database.</string>
</property>
<property name="text">
<string>Use recycle bin</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="historyMaxSizeCheckBox">
<property name="toolTip">
@ -158,19 +316,6 @@ add up to the specified amount at most.</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="recycleBinEnabledCheckBox">
<property name="toolTip">
<string>Move entries to a recycle bin group
instead of deleting them from the database.
Entries deleted from the recycle bin are
removed from the database.</string>
</property>
<property name="text">
<string>Use recycle bin</string>
</property>
</widget>
</item>
</layout>
</item>
<item>

View File

@ -38,7 +38,7 @@ EntryPreviewWidget TagsEdit
padding-left: 0px;
}
DatabaseOpenWidget #centralStack {
DatabaseOpenWidget #centralStack, DatabaseOpenWidget #publicSummaryLabel {
border: 1px solid palette(mid);
background: palette(light);
}

View File

@ -1,4 +1,4 @@
DatabaseOpenWidget #centralStack {
DatabaseOpenWidget #centralStack, DatabaseOpenWidget #publicSummaryLabel {
border: 2px groove palette(mid);
background: palette(light);
}