mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-01-13 16:30:29 -05:00
Add a button to reveal protected attributes in entry preview
Closes #1930
This commit is contained in:
parent
81a66c439c
commit
64cb1553d0
@ -19,6 +19,7 @@
|
||||
#include "EntryPreviewWidget.h"
|
||||
#include "ui_EntryPreviewWidget.h"
|
||||
|
||||
#include "Clipboard.h"
|
||||
#include "Font.h"
|
||||
#include "entry/EntryAttachmentsModel.h"
|
||||
#include "gui/Icons.h"
|
||||
@ -276,29 +277,68 @@ void EntryPreviewWidget::updateEntryGeneralTab()
|
||||
void EntryPreviewWidget::updateEntryAdvancedTab()
|
||||
{
|
||||
Q_ASSERT(m_currentEntry);
|
||||
m_ui->entryAttributesEdit->clear();
|
||||
m_ui->entryAttributesTable->clear();
|
||||
|
||||
const EntryAttributes* attributes = m_currentEntry->attributes();
|
||||
const QStringList customAttributes = attributes->customKeys();
|
||||
const bool hasAttributes = !customAttributes.isEmpty();
|
||||
const bool hasAttachments = !m_currentEntry->attachments()->isEmpty();
|
||||
m_ui->entryAttributesTable->setRowCount(customAttributes.size());
|
||||
m_ui->entryAttributesTable->setColumnCount(3);
|
||||
|
||||
setTabEnabled(m_ui->entryTabWidget, m_ui->entryAdvancedTab, hasAttributes || hasAttachments);
|
||||
if (hasAttributes) {
|
||||
QString attributesText("<table>");
|
||||
auto i = 0;
|
||||
QFont font;
|
||||
font.setBold(true);
|
||||
for (const QString& key : customAttributes) {
|
||||
QString value;
|
||||
if (m_currentEntry->attributes()->isProtected(key)) {
|
||||
value = "<i>" + tr("[PROTECTED]") + "</i>";
|
||||
m_ui->entryAttributesTable->setItem(i, 0, new QTableWidgetItem(key));
|
||||
|
||||
if (attributes->isProtected(key)) {
|
||||
// only show the reveal button on protected attributes
|
||||
auto button = new QToolButton();
|
||||
button->setCheckable(true);
|
||||
button->setChecked(false);
|
||||
button->setIcon(icons()->onOffIcon("password-show", false));
|
||||
button->setProperty("value", attributes->value(key));
|
||||
button->setProperty("row", i);
|
||||
m_ui->entryAttributesTable->setCellWidget(i, 1, button);
|
||||
m_ui->entryAttributesTable->setItem(i, 2, new QTableWidgetItem(QString("\u25cf").repeated(6)));
|
||||
|
||||
connect(button, &QToolButton::clicked, this, [this](bool state) {
|
||||
auto btn = qobject_cast<QToolButton*>(sender());
|
||||
btn->setIcon(icons()->onOffIcon("password-show", state));
|
||||
auto row = btn->property("row").toInt();
|
||||
if (state) {
|
||||
m_ui->entryAttributesTable->item(row, 2)->setText(btn->property("value").toString());
|
||||
} else {
|
||||
m_ui->entryAttributesTable->item(row, 2)->setText(QString("\u25cf").repeated(6));
|
||||
}
|
||||
// Maintain button height while showing contents of cell
|
||||
auto size = btn->size();
|
||||
m_ui->entryAttributesTable->resizeRowToContents(row);
|
||||
btn->setFixedSize(size);
|
||||
});
|
||||
} else {
|
||||
value = m_currentEntry->attributes()->value(key).toHtmlEscaped();
|
||||
value.replace('\n', "<br/>");
|
||||
m_ui->entryAttributesTable->setItem(i, 2, new QTableWidgetItem(attributes->value(key)));
|
||||
}
|
||||
attributesText.append(QString("<tr><td><b>%1</b>:</td><td>%2</td></tr>").arg(key, value));
|
||||
|
||||
m_ui->entryAttributesTable->item(i, 0)->setFont(font);
|
||||
m_ui->entryAttributesTable->item(i, 0)->setTextAlignment(Qt::AlignTop | Qt::AlignLeft);
|
||||
m_ui->entryAttributesTable->item(i, 2)->setTextAlignment(Qt::AlignTop | Qt::AlignLeft);
|
||||
|
||||
++i;
|
||||
}
|
||||
attributesText.append("</table>");
|
||||
m_ui->entryAttributesEdit->setText(attributesText);
|
||||
connect(m_ui->entryAttributesTable, &QTableWidget::cellDoubleClicked, this, [this](int row, int column) {
|
||||
if (column == 2) {
|
||||
clipboard()->setText(m_ui->entryAttributesTable->item(row, column)->text());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
m_ui->entryAttributesTable->horizontalHeader()->setStretchLastSection(true);
|
||||
m_ui->entryAttributesTable->resizeColumnsToContents();
|
||||
m_ui->entryAttributesTable->resizeRowsToContents();
|
||||
m_ui->entryAttachmentsWidget->setEntryAttachments(m_currentEntry->attachments());
|
||||
}
|
||||
|
||||
|
@ -145,7 +145,7 @@
|
||||
<item>
|
||||
<widget class="QTabWidget" name="entryTabWidget">
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="documentMode">
|
||||
<bool>false</bool>
|
||||
@ -534,71 +534,23 @@
|
||||
<attribute name="title">
|
||||
<string>Advanced</string>
|
||||
</attribute>
|
||||
<layout class="QGridLayout" name="gridLayout_1" rowstretch="0,0" columnstretch="0,1,0,2,0">
|
||||
<layout class="QGridLayout" name="gridLayout_1">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
<number>5</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>5</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
<number>5</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>5</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<spacer name="entryAdvancedLeftHorizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Fixed</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>5</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<property name="horizontalSpacing">
|
||||
<number>8</number>
|
||||
</property>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLabel" name="attributesTitleLabel">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Attributes</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<spacer name="entryAdvancedMiddleHorizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Fixed</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>5</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="0" column="3">
|
||||
<widget class="QLabel" name="attachmentsTitleLabel">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
|
||||
@ -617,87 +569,75 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="4">
|
||||
<spacer name="entryAdvancedRightHorizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
<item row="1" column="1">
|
||||
<widget class="EntryAttachmentsWidget" name="entryAttachmentsWidget" native="true">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Fixed</enum>
|
||||
<property name="focusPolicy">
|
||||
<enum>Qt::ClickFocus</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>5</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="attributesTitleLabel">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</spacer>
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Attributes</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<spacer name="entryAdvancedLeftHorizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Fixed</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>5</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QTextEdit" name="entryAttributesEdit">
|
||||
<widget class="QTableWidget" name="entryAttributesTable">
|
||||
<property name="focusPolicy">
|
||||
<enum>Qt::ClickFocus</enum>
|
||||
<enum>Qt::NoFocus</enum>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<property name="styleSheet">
|
||||
<string notr="true">QTableView::item {padding: 3px;}</string>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="editTriggers">
|
||||
<set>QAbstractItemView::NoEditTriggers</set>
|
||||
</property>
|
||||
<property name="showDropIndicator" stdset="0">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::NoSelection</enum>
|
||||
</property>
|
||||
<property name="showGrid">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="cornerButtonEnabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<attribute name="horizontalHeaderVisible">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<attribute name="horizontalHeaderStretchLastSection">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</attribute>
|
||||
<attribute name="verticalHeaderVisible">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<spacer name="entryAdvancedMiddleHorizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Fixed</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>5</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="1" column="3">
|
||||
<widget class="EntryAttachmentsWidget" name="entryAttachmentsWidget" native="true">
|
||||
<property name="focusPolicy">
|
||||
<enum>Qt::ClickFocus</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="4">
|
||||
<spacer name="entryAdvancedRightHorizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Fixed</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>5</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="entryAutotypeTab">
|
||||
@ -738,7 +678,7 @@
|
||||
<string>Default Sequence</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignVCenter</set>
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -754,7 +694,7 @@
|
||||
<string notr="true">sequence</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignLeft|Qt::AlignVCenter</set>
|
||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
Loading…
Reference in New Issue
Block a user