Skip to content

Commit

Permalink
Show what changed between entry history items
Browse files Browse the repository at this point in the history
* Also show what is changed on the current state
* Closes #2621
  • Loading branch information
shemeshg authored and droidmonkey committed Dec 20, 2021
1 parent 12990e5 commit d4ae5a2
Show file tree
Hide file tree
Showing 6 changed files with 277 additions and 32 deletions.
98 changes: 98 additions & 0 deletions share/translations/keepassxc_en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3614,6 +3614,62 @@ Would you like to overwrite the existing attachment?</source>
<source>URL</source>
<translation>URL</translation>
</message>
<message>
<source>Current</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Age</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Difference</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Size</source>
<translation type="unfinished">Size</translation>
</message>
<message>
<source>Password</source>
<translation type="unfinished">Password</translation>
</message>
<message>
<source>Notes</source>
<translation type="unfinished">Notes</translation>
</message>
<message>
<source>Custom Attributes</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Icon</source>
<translation type="unfinished">Icon</translation>
</message>
<message>
<source>Color</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Expiration</source>
<translation type="unfinished">Expiration</translation>
</message>
<message>
<source>TOTP</source>
<translation type="unfinished">TOTP</translation>
</message>
<message>
<source>Custom Data</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Attachments</source>
<translation type="unfinished">Attachments</translation>
</message>
<message>
<source>Auto-Type</source>
<translation type="unfinished">Auto-Type</translation>
</message>
</context>
<context>
<name>EntryModel</name>
Expand Down Expand Up @@ -7633,6 +7689,48 @@ Please consider generating a new key file.</source>
<source>KeeShare</source>
<translation type="unfinished"></translation>
</message>
<message numerus="yes">
<source>over %1 year(s)</source>
<translation type="unfinished">
<numerusform></numerusform>
<numerusform></numerusform>
</translation>
</message>
<message numerus="yes">
<source>about %1 month(s)</source>
<translation type="unfinished">
<numerusform></numerusform>
<numerusform></numerusform>
</translation>
</message>
<message numerus="yes">
<source>%1 week(s)</source>
<translation type="unfinished">
<numerusform></numerusform>
<numerusform></numerusform>
</translation>
</message>
<message numerus="yes">
<source>%1 day(s)</source>
<translation type="unfinished">
<numerusform></numerusform>
<numerusform></numerusform>
</translation>
</message>
<message numerus="yes">
<source>%1 hour(s)</source>
<translation type="unfinished">
<numerusform></numerusform>
<numerusform></numerusform>
</translation>
</message>
<message numerus="yes">
<source>%1 minute(s)</source>
<translation type="unfinished">
<numerusform></numerusform>
<numerusform></numerusform>
</translation>
</message>
</context>
<context>
<name>QtIOCompressor</name>
Expand Down
31 changes: 31 additions & 0 deletions src/core/Tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,37 @@ namespace Tools
return QString("%1 %2").arg(QLocale().toString(size, 'f', precision), units.at(i));
}

QString humanTimeDifference(qint64 seconds)
{
constexpr qint64 secondsInHour = 3600;
constexpr qint64 secondsInDay = secondsInHour * 24;
constexpr qint64 secondsInWeek = secondsInDay * 7;
constexpr qint64 secondsInMonth = secondsInDay * 30; // Approximation
constexpr qint64 secondsInYear = secondsInDay * 365;

seconds = abs(seconds);

if (seconds >= secondsInYear) {
auto years = seconds / secondsInYear;
return QObject::tr("over %1 year(s)", nullptr, years).arg(years);
} else if (seconds >= secondsInMonth) {
auto months = seconds / secondsInMonth;
return QObject::tr("about %1 month(s)", nullptr, months).arg(months);
} else if (seconds >= secondsInWeek) {
auto weeks = seconds / secondsInWeek;
return QObject::tr("%1 week(s)", nullptr, weeks).arg(weeks);
} else if (seconds >= secondsInDay) {
auto days = seconds / secondsInDay;
return QObject::tr("%1 day(s)", nullptr, days).arg(days);
} else if (seconds >= secondsInHour) {
auto hours = seconds / secondsInHour;
return QObject::tr("%1 hour(s)", nullptr, hours).arg(hours);
}

auto minutes = seconds / 60;
return QObject::tr("%1 minute(s)", nullptr, minutes).arg(minutes);
}

bool readFromDevice(QIODevice* device, QByteArray& data, int size)
{
QByteArray buffer;
Expand Down
2 changes: 2 additions & 0 deletions src/core/Tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include "core/Global.h"

#include <QDateTime>
#include <QProcessEnvironment>

class QIODevice;
Expand All @@ -30,6 +31,7 @@ namespace Tools
{
QString debugInfo();
QString humanReadableFileSize(qint64 bytes, quint32 precision = 2);
QString humanTimeDifference(qint64 seconds);
bool readFromDevice(QIODevice* device, QByteArray& data, int size = 16384);
bool readAllFromDevice(QIODevice* device, QByteArray& data);
bool isHex(const QByteArray& ba);
Expand Down
18 changes: 11 additions & 7 deletions src/gui/entry/EditEntryWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,9 @@ void EditEntryWidget::emitHistoryEntryActivated(const QModelIndex& index)
Q_ASSERT(!m_history);

Entry* entry = m_historyModel->entryFromIndex(index);
emit historyEntryActivated(entry);
if (entry) {
emit historyEntryActivated(entry);
}
}

void EditEntryWidget::histEntryActivated(const QModelIndex& index)
Expand All @@ -521,7 +523,7 @@ void EditEntryWidget::updateHistoryButtons(const QModelIndex& current, const QMo
{
Q_UNUSED(previous);

if (current.isValid()) {
if (m_historyModel->entryFromIndex(current)) {
m_historyUi->showButton->setEnabled(true);
m_historyUi->restoreButton->setEnabled(true);
m_historyUi->deleteButton->setEnabled(true);
Expand Down Expand Up @@ -1025,7 +1027,7 @@ void EditEntryWidget::setForms(Entry* entry, bool restore)
m_editWidgetProperties->setFields(entry->timeInfo(), entry->uuid());

if (!m_history && !restore) {
m_historyModel->setEntries(entry->historyItems());
m_historyModel->setEntries(entry->historyItems(), entry);
m_historyUi->historyView->sortByColumn(0, Qt::DescendingOrder);
}
if (m_historyModel->rowCount() > 0) {
Expand Down Expand Up @@ -1129,7 +1131,8 @@ bool EditEntryWidget::commitEntry()
m_entry->endUpdate();
}

m_historyModel->setEntries(m_entry->historyItems());
m_historyModel->setEntries(m_entry->historyItems(), m_entry);
m_advancedUi->attachmentsWidget->linkAttachments(m_entry->attachments());

showMessage(tr("Entry updated successfully."), MessageWidget::Positive);
setModified(false);
Expand Down Expand Up @@ -1538,16 +1541,17 @@ void EditEntryWidget::showHistoryEntry()
void EditEntryWidget::restoreHistoryEntry()
{
QModelIndex index = m_sortModel->mapToSource(m_historyUi->historyView->currentIndex());
if (index.isValid()) {
setForms(m_historyModel->entryFromIndex(index), true);
auto entry = m_historyModel->entryFromIndex(index);
if (entry) {
setForms(entry, true);
setModified(true);
}
}

void EditEntryWidget::deleteHistoryEntry()
{
QModelIndex index = m_sortModel->mapToSource(m_historyUi->historyView->currentIndex());
if (index.isValid()) {
if (m_historyModel->entryFromIndex(index)) {
m_historyModel->deleteIndex(index);
if (m_historyModel->rowCount() > 0) {
m_historyUi->deleteAllButton->setEnabled(true);
Expand Down
Loading

0 comments on commit d4ae5a2

Please sign in to comment.