Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/keepassxreboot/keepassxc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan White <support@dmapps.us>2020-05-31 17:00:11 +0300
committerJonathan White <support@dmapps.us>2020-06-04 17:03:40 +0300
commit9d107926409217c53b1a3988556515faec774351 (patch)
tree2b672a9f94224271dcce2565f0143a7d40ff8867
parent2073f2ddc30f6922eda89ee3c66e80f9cb426859 (diff)
Update edit entry widget when backing entry changes
* Fixes #4060 * Also fix not emitting entryModified() when history is truncated. This possibly fixes other crashes with apply button when the history is truncated and then the history page is shown with a deleted entry.
-rw-r--r--src/core/Entry.cpp7
-rw-r--r--src/gui/entry/EditEntryWidget.cpp14
-rw-r--r--src/gui/entry/EditEntryWidget.h2
-rw-r--r--tests/gui/TestGui.cpp4
4 files changed, 25 insertions, 2 deletions
diff --git a/src/core/Entry.cpp b/src/core/Entry.cpp
index fc553f9e5..65a271c2e 100644
--- a/src/core/Entry.cpp
+++ b/src/core/Entry.cpp
@@ -663,6 +663,7 @@ void Entry::truncateHistory()
return;
}
+ bool changed = false;
int histMaxItems = db->metadata()->historyMaxItems();
if (histMaxItems > -1) {
int historyCount = 0;
@@ -674,6 +675,7 @@ void Entry::truncateHistory()
if (historyCount > histMaxItems) {
delete entry;
i.remove();
+ changed = true;
}
}
}
@@ -697,9 +699,14 @@ void Entry::truncateHistory()
if (size > histMaxSize) {
delete historyItem;
i.remove();
+ changed = true;
}
}
}
+
+ if (changed) {
+ emit entryModified();
+ }
}
bool Entry::equals(const Entry* other, CompareItemOptions options) const
diff --git a/src/gui/entry/EditEntryWidget.cpp b/src/gui/entry/EditEntryWidget.cpp
index 23fd51670..cfe6fd5a9 100644
--- a/src/gui/entry/EditEntryWidget.cpp
+++ b/src/gui/entry/EditEntryWidget.cpp
@@ -118,6 +118,14 @@ EditEntryWidget::EditEntryWidget(QWidget* parent)
setupHistory();
setupEntryUpdate();
+ m_entryModifiedTimer.setSingleShot(true);
+ m_entryModifiedTimer.setInterval(0);
+ connect(&m_entryModifiedTimer, &QTimer::timeout, this, [this] {
+ if (isVisible() && m_entry) {
+ setForms(m_entry);
+ }
+ });
+
connect(this, SIGNAL(accepted()), SLOT(acceptEntry()));
connect(this, SIGNAL(rejected()), SLOT(cancel()));
connect(this, SIGNAL(apply()), SLOT(commitEntry()));
@@ -785,6 +793,8 @@ void EditEntryWidget::loadEntry(Entry* entry,
m_create = create;
m_history = history;
+ connect(m_entry, &Entry::entryModified, this, [this] { m_entryModifiedTimer.start(); });
+
if (history) {
setHeadline(QString("%1 \u2B29 %2").arg(parentName, tr("Entry history")));
} else {
@@ -1130,6 +1140,10 @@ void EditEntryWidget::cancel()
void EditEntryWidget::clear()
{
+ if (m_entry) {
+ m_entry->disconnect(this);
+ }
+
m_entry = nullptr;
m_db.reset();
diff --git a/src/gui/entry/EditEntryWidget.h b/src/gui/entry/EditEntryWidget.h
index ea630d7eb..3d1835396 100644
--- a/src/gui/entry/EditEntryWidget.h
+++ b/src/gui/entry/EditEntryWidget.h
@@ -24,6 +24,7 @@
#include <QModelIndex>
#include <QPointer>
#include <QScopedPointer>
+#include <QTimer>
#include "config-keepassx.h"
#include "gui/EditWidget.h"
@@ -198,6 +199,7 @@ private:
QButtonGroup* const m_autoTypeWindowSequenceGroup;
QCompleter* const m_usernameCompleter;
QStringListModel* const m_usernameCompleterModel;
+ QTimer m_entryModifiedTimer;
Q_DISABLE_COPY(EditEntryWidget)
};
diff --git a/tests/gui/TestGui.cpp b/tests/gui/TestGui.cpp
index c2ef5e192..e59540a02 100644
--- a/tests/gui/TestGui.cpp
+++ b/tests/gui/TestGui.cpp
@@ -499,9 +499,9 @@ void TestGui::testEditEntry()
// Confirm edit was made
QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::Mode::ViewMode);
QCOMPARE(entry->title(), QString("Sample Entry_test"));
- QCOMPARE(entry->foregroundColor(), fgColor);
+ QCOMPARE(entry->foregroundColor().toUpper(), fgColor.toUpper());
QCOMPARE(entryItem.data(Qt::ForegroundRole), QVariant(fgColor));
- QCOMPARE(entry->backgroundColor(), bgColor);
+ QCOMPARE(entry->backgroundColor().toUpper(), bgColor.toUpper());
QCOMPARE(entryItem.data(Qt::BackgroundRole), QVariant(bgColor));
QCOMPARE(entry->historyItems().size(), ++editCount);