TizenRefApp-6852 Edited event duplicated after editing this and future events 53/93153/3
authorSergei Kobec <s.kobec@samsung.com>
Fri, 21 Oct 2016 08:42:16 +0000 (11:42 +0300)
committerGerrit Code Review <gerrit@review.vlan103.tizen.org>
Fri, 21 Oct 2016 14:12:42 +0000 (07:12 -0700)
Fixed issue with deleting child events during update and delete

Change-Id: I6b9c7e0f174c3df997ed8e7395867078266c9864
Signed-off-by: Sergei Kobec <s.kobec@samsung.com>
common/model/CalDataManager.cpp
common/model/CalDataManager.h
common/model/CalOriginalSchedule.cpp

index d1a5357..b6c7422 100644 (file)
@@ -28,6 +28,7 @@
 #include <sstream>
 #include <app.h>
 #include <contacts.h>
+#include <functional>
 
 SINGLETON_INSTANCE(CalDataManager);
 
@@ -173,6 +174,7 @@ void CalDataManager::__updateThisAndFutureInstances(const CalSchedule& inputSche
        }
 
        originalSchedule->truncateRepeatToBeforeDate(inputInstanceStartTime);
+       __deleteChildRecords(*originalSchedule, inputInstanceStartTime, false);
        __updateSchedule(*originalSchedule);
 
        __deleteExceptionRecordsOnAndAfter(*originalSchedule, inputInstanceStartTime);
@@ -278,6 +280,7 @@ void CalDataManager::__deleteThisAndFutureInstances(const CalSchedule& inputSche
        }
 
        originalSchedule->truncateRepeatToBeforeDate(inputInstanceStartTime);
+       __deleteChildRecords(*originalSchedule, inputInstanceStartTime, false);
        __updateSchedule(*originalSchedule);
        __deleteExceptionRecordsOnAndAfter(*originalSchedule, inputInstanceStartTime);
 }
@@ -408,7 +411,7 @@ void CalDataManager::__setThisAndFutureRepeatCount(const CalSchedule& inputSched
        const auto originalSchedule = __getOriginalSchedule(inputSchedule);
 
        int countBefore = originalSchedule->getInstanceCountBeforeDate(inputInstanceStartTime);
-       __deleteChildRecordsBefore(workingCopy, inputInstanceStartTime);
+       __deleteChildRecords(workingCopy, inputInstanceStartTime);
        repeat.untilInfo.times -= countBefore;
        repeat.print();
 
@@ -1057,9 +1060,19 @@ void CalDataManager::__deleteExceptionRecordsOnAndAfter(const CalOriginalSchedul
        }
 }
 
-void CalDataManager::__deleteChildRecordsBefore(const CalOriginalSchedule& originalSchedule, const CalDateTime& inputInstanceStartTime)
+void CalDataManager::__deleteChildRecords(const CalSchedule& originalSchedule, const CalDateTime& inputInstanceStartTime, bool before)
 {
+       typedef long long int OperandType;
+       typedef std::function<bool(const OperandType &, const OperandType &)> Comparator;
+
+       Comparator comparator;
+       if (before) {
+               comparator = std::less<OperandType>();
+       } else {
+               comparator = std::greater_equal<OperandType>();
+       }
        calendar_record_h origRecord = originalSchedule.getRecord();
+
        if (origRecord) {
                unsigned count = 0;
                calendar_record_get_child_record_count(origRecord, _calendar_event.exception, &count);
@@ -1069,7 +1082,8 @@ void CalDataManager::__deleteChildRecordsBefore(const CalOriginalSchedule& origi
 
                        calendar_time_s calTime = { CALENDAR_TIME_UTIME, { 0, } };
                        calendar_record_get_caltime(childRecord, _calendar_event.start_time, &calTime);
-                       if (calTime.time.utime < inputInstanceStartTime.getUtimeFromTm()) {
+
+                       if (comparator(calTime.time.utime, inputInstanceStartTime.getUtimeFromTm())) {
                                calendar_record_remove_child_record(origRecord, _calendar_event.exception, childRecord);
                        }
                }
index 239203c..aecac04 100644 (file)
@@ -213,7 +213,7 @@ private:
        static void __onChanged(const char* uri, void* userData);
        static std::shared_ptr<CalOriginalSchedule> __getOriginalSchedule(const CalSchedule& instance);
        static void __deleteExceptionRecordsOnAndAfter(const CalOriginalSchedule& originalSchedule, const CalDateTime& inputInstanceStartTime);
-       static void __deleteChildRecordsBefore(const CalOriginalSchedule& originalSchedule, const CalDateTime& inputInstanceStartTime);
+       static void __deleteChildRecords(const CalSchedule& originalSchedule, const CalDateTime& inputInstanceStartTime, bool before = true);
        static void __deleteAllExceptionRecords(const CalOriginalSchedule& originalSchedule);
 
        int __localVersion;
index 43a2be3..ea4d147 100644 (file)
@@ -747,7 +747,7 @@ int CalOriginalSchedule::getChildInstanceCountBeforeDate(int originalId, const C
        unsigned count = 0;
        calendar_record_get_child_record_count(origRecord, _calendar_event.exception, &count);
 
-       for (int i = 0; i < count; ++i) {
+       for (unsigned i = 0; i < count; ++i) {
                calendar_record_h record = nullptr;
                calendar_record_get_child_record_at_p(origRecord, _calendar_event.exception, i, &record);