diff options
author | Jonathan White <support@dmapps.us> | 2018-09-30 15:45:06 +0300 |
---|---|---|
committer | Jonathan White <droidmonkey@users.noreply.github.com> | 2018-09-30 16:36:39 +0300 |
commit | c1e9f45df9f21b7697241037643770a2862bb7ef (patch) | |
tree | bbb7a840c0199613203d2de90ece7dd47e87038e /src/core/TimeInfo.cpp | |
parent | b40e5686dccfb9f60abc186120e9db17edfa81c0 (diff) |
Introduce synchronize merge method
* Create history-based merging that keeps older data in history instead of discarding or deleting it
* Extract merge logic into the Merger class
* Allows special merge behavior
* Improve handling of deletion and changes on groups
* Enable basic change tracking while merging
* Prevent unintended timestamp changes while merging
* Handle differences in timestamp precision
* Introduce comparison operators to allow for more sophisticated comparisons (ignore special properties, ...)
* Introduce Clock class to handle datetime across the app
Merge Strategies:
* Default (use inherited/fallback method)
* Duplicate (duplicate conflicting nodes, apply all deletions)
* KeepLocal (use local values, but apply all deletions)
* KeepRemote (use remote values, but apply all deletions)
* KeepNewer (merge history only)
* Synchronize (merge history, newest value stays on top, apply all deletions)
Diffstat (limited to 'src/core/TimeInfo.cpp')
-rw-r--r-- | src/core/TimeInfo.cpp | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/src/core/TimeInfo.cpp b/src/core/TimeInfo.cpp index 85c53a567..c774a7c81 100644 --- a/src/core/TimeInfo.cpp +++ b/src/core/TimeInfo.cpp @@ -17,11 +17,13 @@ #include "TimeInfo.h" +#include "core/Clock.h" + TimeInfo::TimeInfo() : m_expires(false) , m_usageCount(0) { - QDateTime now = QDateTime::currentDateTimeUtc(); + QDateTime now = Clock::currentDateTimeUtc(); m_lastModificationTime = now; m_creationTime = now; m_lastAccessTime = now; @@ -103,3 +105,38 @@ void TimeInfo::setLocationChanged(const QDateTime& dateTime) Q_ASSERT(dateTime.timeSpec() == Qt::UTC); m_locationChanged = dateTime; } + +bool TimeInfo::operator==(const TimeInfo& other) const +{ + return equals(other, CompareItemDefault); +} + +bool TimeInfo::operator!=(const TimeInfo& other) const +{ + return !this->operator==(other); +} + +bool TimeInfo::equals(const TimeInfo& other, CompareItemOptions options) const +{ + if (::compare(m_lastModificationTime, other.m_lastModificationTime, options) != 0) { + return false; + } + if (::compare(m_creationTime, other.m_creationTime, options) != 0) { + return false; + } + if (::compare(!options.testFlag(CompareItemIgnoreStatistics), m_lastAccessTime, other.m_lastAccessTime, options) + != 0) { + return false; + } + if (::compare(m_expires, m_expiryTime, other.m_expires, other.expiryTime(), options) != 0) { + return false; + } + if (::compare(!options.testFlag(CompareItemIgnoreStatistics), m_usageCount, other.m_usageCount, options) != 0) { + return false; + } + if (::compare(!options.testFlag(CompareItemIgnoreLocation), m_locationChanged, other.m_locationChanged, options) + != 0) { + return false; + } + return true; +} |