Skip to content

Commit

Permalink
Add user-configurable summary to unlock screen.
Browse files Browse the repository at this point in the history
  • Loading branch information
techninja1008 committed May 27, 2024
1 parent 9aa0406 commit b51c6e7
Show file tree
Hide file tree
Showing 9 changed files with 164 additions and 4 deletions.
30 changes: 30 additions & 0 deletions src/core/Database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1049,3 +1049,33 @@ QUuid Database::publicUuid()

return QUuid::fromRfc4122(publicCustomData()["KPXC_PUBLIC_UUID"].toByteArray());
}

QString Database::publicSummary()
{
if (!publicCustomData().contains("KPXC_PUBLIC_SUMMARY")) {
return QString();
}

return publicCustomData()["KPXC_PUBLIC_SUMMARY"].toString();
}

void Database::setPublicSummary(const QString& newSummary)
{
publicCustomData().insert("KPXC_PUBLIC_SUMMARY", newSummary);
markAsModified();
}

QString Database::publicColor()
{
if (!publicCustomData().contains("KPXC_PUBLIC_COLOR")) {
return QString();
}

return publicCustomData()["KPXC_PUBLIC_COLOR"].toString();
}

void Database::setPublicColor(const QString& newSummary)
{
publicCustomData().insert("KPXC_PUBLIC_COLOR", newSummary);
markAsModified();
}
5 changes: 5 additions & 0 deletions src/core/Database.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ class Database : public ModifiableObject
QString canonicalFilePath() const;
void setFilePath(const QString& filePath);

QString publicSummary();
void setPublicSummary(const QString& newSummary);
QString publicColor();
void setPublicColor(const QString& newSummary);

Metadata* metadata();
const Metadata* metadata() const;
Group* rootGroup();
Expand Down
24 changes: 24 additions & 0 deletions src/gui/DatabaseOpenWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ DatabaseOpenWidget::DatabaseOpenWidget(QWidget* parent)
m_ui->labelHeadline->setFont(font);
m_ui->labelHeadline->setText(tr("Unlock KeePassXC Database"));

m_ui->publicSummaryLabel->setVisible(false);

m_ui->quickUnlockButton->setFont(font);
m_ui->quickUnlockButton->setIcon(
icons()->icon("fingerprint", true, palette().color(QPalette::Active, QPalette::HighlightedText)));
Expand Down Expand Up @@ -226,6 +228,28 @@ void DatabaseOpenWidget::load(const QString& filename)

m_ui->fileNameLabel->setRawText(m_filename);

if (!m_db->publicSummary().isEmpty()) {
m_ui->publicSummaryLabel->setVisible(true);
m_ui->publicSummaryLabel->setText(m_db->publicSummary());
}

m_ui->publicSummaryLabel->setStyleSheet("");

if (!m_db->publicColor().isEmpty()) {
QColor userColor = QColor(m_db->publicColor());

if (userColor.isValid()) {
float luminance = (0.299 * userColor.redF() + 0.587 * userColor.greenF() + 0.114 * userColor.blueF());

QColor textColor = Qt::white;
if (luminance > 0.5) {
textColor = Qt::black;
}

m_ui->publicSummaryLabel->setStyleSheet(QString("background-color:%1;color:%2;border-color:%1;").arg(userColor.name(), textColor.name()));
}
}

if (config()->get(Config::RememberLastKeyFiles).toBool()) {
auto lastKeyFiles = config()->get(Config::LastKeyFiles).toHash();
if (lastKeyFiles.contains(m_filename)) {
Expand Down
18 changes: 17 additions & 1 deletion src/gui/DatabaseOpenWidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
</item>
<item>
<widget class="QWidget" name="formContainer" native="true">
<layout class="QVBoxLayout" name="verticalLayout_4" stretch="1,0,0,0,0,2">
<layout class="QVBoxLayout" name="verticalLayout_4" stretch="1,0,0,0,0,0,2">
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
Expand Down Expand Up @@ -90,6 +90,22 @@
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="publicSummaryLabel">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="text">
<string>publicSummary</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="margin">
<number>10</number>
</property>
</widget>
</item>
<item>
<widget class="QStackedWidget" name="centralStack">
<property name="minimumSize">
Expand Down
17 changes: 17 additions & 0 deletions src/gui/dbsettings/DatabaseSettingsWidgetGeneral.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include "DatabaseSettingsWidgetGeneral.h"
#include "ui_DatabaseSettingsWidgetGeneral.h"

#include <QColorDialog>

#include "core/Clock.h"
#include "core/Group.h"
#include "core/Metadata.h"
Expand All @@ -29,6 +31,8 @@ DatabaseSettingsWidgetGeneral::DatabaseSettingsWidgetGeneral(QWidget* parent)
{
m_ui->setupUi(this);

connect(m_ui->dbPublicColorChooseButton, SIGNAL(clicked()), SLOT(pickColor()));

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)));
Expand All @@ -46,6 +50,9 @@ void DatabaseSettingsWidgetGeneral::initialize()
m_ui->defaultUsernameEdit->setText(meta->defaultUserName());
m_ui->compressionCheckbox->setChecked(m_db->compressionAlgorithm() != Database::CompressionNone);

m_ui->dbPublicSummary->setText(m_db->publicSummary());
m_ui->dbPublicColor->setText(m_db->publicColor());

if (meta->historyMaxItems() > -1) {
m_ui->historyMaxItemsSpinBox->setValue(meta->historyMaxItems());
m_ui->historyMaxItemsCheckBox->setChecked(true);
Expand Down Expand Up @@ -116,6 +123,9 @@ bool DatabaseSettingsWidgetGeneral::save()
meta->setRecycleBinEnabled(m_ui->recycleBinEnabledCheckBox->isChecked());
meta->setSettingsChanged(Clock::currentDateTimeUtc());

m_db->setPublicSummary(m_ui->dbPublicSummary->text());
m_db->setPublicColor(m_ui->dbPublicColor->text());

bool truncate = false;

int historyMaxItems;
Expand Down Expand Up @@ -155,3 +165,10 @@ bool DatabaseSettingsWidgetGeneral::save()

return true;
}

void DatabaseSettingsWidgetGeneral::pickColor()
{
QColor oldColor = QColor(m_ui->dbPublicColor->text());
QColor newColor = QColorDialog::getColor(oldColor);
m_ui->dbPublicColor->setText(newColor.name());
}
3 changes: 3 additions & 0 deletions src/gui/dbsettings/DatabaseSettingsWidgetGeneral.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public slots:
void uninitialize() override;
bool save() override;

private slots:
void pickColor();

protected:
void showEvent(QShowEvent* event) override;

Expand Down
67 changes: 66 additions & 1 deletion src/gui/dbsettings/DatabaseSettingsWidgetGeneral.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>453</width>
<height>394</height>
<height>647</height>
</rect>
</property>
<property name="sizePolicy">
Expand Down Expand Up @@ -92,6 +92,71 @@
</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="text">
<string>Warning: the following settings are stored unencrypted.</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>Database summary:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="dbPublicSummary">
<property name="accessibleName">
<string>Database summary field</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="dbPublicColorLabel">
<property name="text">
<string>Database color:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="topMargin">
<number>0</number>
</property>
<item>
<widget class="QLineEdit" name="dbPublicColor">
<property name="accessibleName">
<string>Database color field</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="dbPublicColorChooseButton">
<property name="text">
<string>Pick color...</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
Expand Down
2 changes: 1 addition & 1 deletion src/gui/styles/base/basestyle.qss
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ EntryPreviewWidget TagsEdit
padding-left: 0px;
}

DatabaseOpenWidget #centralStack {
DatabaseOpenWidget #centralStack, DatabaseOpenWidget #publicSummaryLabel {
border: 1px solid palette(mid);
background: palette(light);
}
Expand Down
2 changes: 1 addition & 1 deletion src/gui/styles/base/classicstyle.qss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
DatabaseOpenWidget #centralStack {
DatabaseOpenWidget #centralStack, DatabaseOpenWidget #publicSummaryLabel {
border: 2px groove palette(mid);
background: palette(light);
}
Expand Down

0 comments on commit b51c6e7

Please sign in to comment.