diff --git a/src/gui/entry/EditEntryWidget.cpp b/src/gui/entry/EditEntryWidget.cpp index f9527966bf..cf32e570e5 100644 --- a/src/gui/entry/EditEntryWidget.cpp +++ b/src/gui/entry/EditEntryWidget.cpp @@ -1025,7 +1025,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) { @@ -1129,7 +1129,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); diff --git a/src/gui/entry/EntryHistoryModel.cpp b/src/gui/entry/EntryHistoryModel.cpp index 2506e06d78..dbb62e8c99 100644 --- a/src/gui/entry/EntryHistoryModel.cpp +++ b/src/gui/entry/EntryHistoryModel.cpp @@ -34,7 +34,7 @@ Entry* EntryHistoryModel::entryFromIndex(const QModelIndex& index) const int EntryHistoryModel::columnCount(const QModelIndex& parent) const { Q_UNUSED(parent); - return 4; + return 5; } int EntryHistoryModel::rowCount(const QModelIndex& parent) const @@ -56,6 +56,10 @@ QVariant EntryHistoryModel::data(const QModelIndex& index, int role) const Entry* entry = entryFromIndex(index); const TimeInfo& timeInfo = entry->timeInfo(); QDateTime lastModificationLocalTime = timeInfo.lastModificationTime().toLocalTime(); + + QDateTime dNow(QDate::currentDate()); + int entryAge = lastModificationLocalTime.daysTo(dNow); + switch (index.column()) { case 0: if (role == Qt::DisplayRole) { @@ -64,11 +68,13 @@ QVariant EntryHistoryModel::data(const QModelIndex& index, int role) const return lastModificationLocalTime; } case 1: - return entry->title(); + return entryAge; case 2: - return entry->username(); + return entry->size(); case 3: - return entry->url(); + return entry->attachments()->keys().count(); + case 4: + return previousModifiedFields(index); } } @@ -82,24 +88,26 @@ QVariant EntryHistoryModel::headerData(int section, Qt::Orientation orientation, case 0: return tr("Last modified"); case 1: - return tr("Title"); + return tr("Age"); case 2: - return tr("Username"); + return tr("Size"); case 3: - return tr("URL"); + return tr("Attachments"); + case 4: + return tr("Data modified"); } } return QVariant(); } -void EntryHistoryModel::setEntries(const QList& entries) +void EntryHistoryModel::setEntries(const QList& entries, Entry* parentEntry) { beginResetModel(); m_historyEntries = entries; m_deletedHistoryEntries.clear(); - + m_parentEntry = parentEntry; endResetModel(); } @@ -146,3 +154,60 @@ void EntryHistoryModel::deleteAll() m_historyEntries.clear(); endRemoveRows(); } + +QString EntryHistoryModel::previousModifiedFields(const QModelIndex& index) const +{ + QModelIndex nextIndex = index.siblingAtRow(index.row() + 1); + Entry* nextEntry; + if (nextIndex.isValid()) { + nextEntry = entryFromIndex(nextIndex); + } else { + nextEntry = m_parentEntry; + } + + QStringList modifiedFields = {}; + Entry* curr = entryFromIndex(index); + + if (*curr->attributes() != *nextEntry->attributes()) { + bool foundAttribute = false; + + if (curr->title() != nextEntry->title()) { + modifiedFields << tr("Title"); + foundAttribute = true; + } + if (curr->username() != nextEntry->username()) { + modifiedFields << tr("Username"); + foundAttribute = true; + } + if (curr->password() != nextEntry->password()) { + modifiedFields << tr("Password"); + foundAttribute = true; + } + if (curr->url() != nextEntry->url()) { + modifiedFields << tr("URL"); + foundAttribute = true; + } + if (curr->notes() != nextEntry->notes()) { + modifiedFields << tr("notes"); + foundAttribute = true; + } + + if (!foundAttribute) { + modifiedFields << tr("Attributes"); + } + } + if (curr->totpSettingsString() != nextEntry->totpSettingsString()) { + modifiedFields << tr("Totp"); + } + if (*curr->customData() != *nextEntry->customData()) { + modifiedFields << tr("Custom Data"); + } + if (*curr->attachments() != *nextEntry->attachments()) { + modifiedFields << tr("Attachments"); + } + if (*curr->autoTypeAssociations() != *nextEntry->autoTypeAssociations()) { + modifiedFields << tr("AutoTypeAssociations"); + } + + return modifiedFields.join(","); +} diff --git a/src/gui/entry/EntryHistoryModel.h b/src/gui/entry/EntryHistoryModel.h index 6d186f0493..26116e06ad 100644 --- a/src/gui/entry/EntryHistoryModel.h +++ b/src/gui/entry/EntryHistoryModel.h @@ -35,7 +35,7 @@ class EntryHistoryModel : public QAbstractTableModel QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; QVariant headerData(int section, Qt::Orientation orientation, int role) const override; - void setEntries(const QList& entries); + void setEntries(const QList& entries, Entry* parentEntry); void clear(); void clearDeletedEntries(); QList deletedEntries(); @@ -45,6 +45,9 @@ class EntryHistoryModel : public QAbstractTableModel private: QList m_historyEntries; QList m_deletedHistoryEntries; + Entry* m_parentEntry; + + QString previousModifiedFields(const QModelIndex& index) const; }; #endif // KEEPASSX_ENTRYHISTORYMODEL_H