Skip to content

Commit

Permalink
feature/historyPreviousModifiedFields
Browse files Browse the repository at this point in the history
  • Loading branch information
shemeshg committed Aug 1, 2021
1 parent 089c8df commit cd095ee
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/gui/entry/EditEntryWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,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 @@ -1088,7 +1088,7 @@ bool EditEntryWidget::commitEntry()
m_entry->endUpdate();
}

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

showMessage(tr("Entry updated successfully."), MessageWidget::Positive);
Expand Down
87 changes: 78 additions & 9 deletions src/gui/entry/EntryHistoryModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Entry* EntryHistoryModel::entryFromIndex(const QModelIndex& index) const
int EntryHistoryModel::columnCount(const QModelIndex& parent) const
{
Q_UNUSED(parent);
return 4;
return 6;
}

int EntryHistoryModel::rowCount(const QModelIndex& parent) const
Expand All @@ -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) {
Expand All @@ -64,11 +68,15 @@ 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);
case 5:
return entry->notes().section("\n", 0, 0).simplified();
}
}

Expand All @@ -82,24 +90,28 @@ 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");
case 5:
return tr("Notes");
}
}

return QVariant();
}

void EntryHistoryModel::setEntries(const QList<Entry*>& entries)
void EntryHistoryModel::setEntries(const QList<Entry*>& entries, Entry* parentEntry)
{
beginResetModel();

m_historyEntries = entries;
m_deletedHistoryEntries.clear();

m_parentEntry = parentEntry;
endResetModel();
}

Expand Down Expand Up @@ -146,3 +158,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(",");
}
5 changes: 4 additions & 1 deletion src/gui/entry/EntryHistoryModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<Entry*>& entries);
void setEntries(const QList<Entry*>& entries, Entry* parentEntry);
void clear();
void clearDeletedEntries();
QList<Entry*> deletedEntries();
Expand All @@ -45,6 +45,9 @@ class EntryHistoryModel : public QAbstractTableModel
private:
QList<Entry*> m_historyEntries;
QList<Entry*> m_deletedHistoryEntries;
Entry* m_parentEntry;

QString previousModifiedFields(const QModelIndex& index) const;
};

#endif // KEEPASSX_ENTRYHISTORYMODEL_H

0 comments on commit cd095ee

Please sign in to comment.