Resolve recurrence defect of edited event instance.
authorSungWan Kim <sw0726.kim@samsung.com>
Mon, 8 Apr 2013 09:55:54 +0000 (18:55 +0900)
committerSungWan Kim <sw0726.kim@samsung.com>
Mon, 8 Apr 2013 10:24:26 +0000 (19:24 +0900)
Change-Id: Ia4d94f59462e4b639a31b8219c19f205eda233c9
Signed-off-by: SungWan Kim <sw0726.kim@samsung.com>
src/ClEventPresentationModel.cpp

index 33d4e9b..7e0c13e 100644 (file)
@@ -500,6 +500,17 @@ EventPresentationModel::SetEvent(const CalEvent& event)
        delete __pEvent;
        __pEvent = new (std::nothrow) CalEvent(event);
 
+       if (__pEvent->GetBaseEventId() != __pEvent->GetRecordId() && __pEvent->GetBaseEventId() != INVALID_RECORD_ID)
+       {
+               CalEvent* pBaseEvent = __pCalendarbook->GetEventN(__pEvent->GetBaseEventId());
+               if (pBaseEvent != null)
+               {
+                       delete __pRecurrence;
+                       __pRecurrence = new (std::nothrow) Recurrence(*pBaseEvent->GetRecurrence());
+                       delete pBaseEvent;
+               }
+       }
+
        delete __pCalendar;
        if (__pEvent->GetCalendarId() != INVALID_RECORD_ID)
        {
@@ -570,6 +581,17 @@ EventPresentationModel::SetEventId(const RecordId eventId)
                delete __pEvent;
                __pEvent = pEvent;
 
+               if (__pEvent->GetBaseEventId() != __pEvent->GetRecordId() && __pEvent->GetBaseEventId() != INVALID_RECORD_ID)
+               {
+                       CalEvent* pBaseEvent = __pCalendarbook->GetEventN(__pEvent->GetBaseEventId());
+                       if (pBaseEvent != null)
+                       {
+                               delete __pRecurrence;
+                               __pRecurrence = new (std::nothrow) Recurrence(*pBaseEvent->GetRecurrence());
+                               delete pBaseEvent;
+                       }
+               }
+
                delete __pCalendar;
                if (__pEvent->GetCalendarId() != INVALID_RECORD_ID)
                {
@@ -607,12 +629,24 @@ EventPresentationModel::SetEventInstance(const CalEventInstance& event)
        {
                delete __pRecurrence;
                __pRecurrence = (pEvent->GetRecurrence() != null) ? new (std::nothrow) Recurrence(*pEvent->GetRecurrence()) : null;
+
                pEvent->SetRecurrence(null);
                pEvent->SetStartAndEndTime(__pEventInstance->GetStartTime(), __pEventInstance->GetEndTime());
        }
        delete __pEvent;
        __pEvent = pEvent;
 
+       if (__pEvent->GetBaseEventId() != __pEvent->GetRecordId() && __pEvent->GetBaseEventId() != INVALID_RECORD_ID)
+       {
+               CalEvent* pBaseEvent = __pCalendarbook->GetEventN(__pEvent->GetBaseEventId());
+               if (pBaseEvent != null)
+               {
+                       delete __pRecurrence;
+                       __pRecurrence = new (std::nothrow) Recurrence(*pBaseEvent->GetRecurrence());
+                       delete pBaseEvent;
+               }
+       }
+
        delete __pCalendar;
        if (__pEventInstance->GetCalendarId() != INVALID_RECORD_ID)
        {
@@ -848,23 +882,39 @@ EventPresentationModel::Update(void)
        }
        else if (__allEventEditing == true)
        {
-               RecordId calendarId = (__pEventInstance != null) ? __pEventInstance->GetCalendarId() : __pEvent->GetCalendarId();
-               if (__pCalendar != null && calendarId != INVALID_RECORD_ID && __pCalendar->GetRecordId() != calendarId)
+               if (__pEvent->GetBaseEventId() != eventId && __pEvent->GetBaseEventId() != INVALID_RECORD_ID)
                {
-                       if (__pEvent->GetCalendarId() != INVALID_RECORD_ID)
+                       __pEventInstance = GetEventInstance();
+                       if (__pEventInstance != null)
                        {
-                               __pCalendarbook->RemoveEvent(*__pEvent);
+                               r = __pCalendarbook->UpdateEventInstance(*__pEventInstance, *__pEvent);
                        }
                        else
                        {
-                               __pCalendarbook->RemoveEvent(eventId);
+                               r = E_FAILURE;
+                               AppLogDebug("[E_FAILURE] Unable to get event instance.");
                        }
-
-                       r = __pCalendarbook->AddEvent(*__pEvent, __pCalendar->GetRecordId());
                }
                else
                {
-                       r = __pCalendarbook->UpdateEvent(*__pEvent);
+                       RecordId calendarId = (__pEventInstance != null) ? __pEventInstance->GetCalendarId() : __pEvent->GetCalendarId();
+                       if (__pCalendar != null && calendarId != INVALID_RECORD_ID && __pCalendar->GetRecordId() != calendarId)
+                       {
+                               if (__pEvent->GetCalendarId() != INVALID_RECORD_ID)
+                               {
+                                       __pCalendarbook->RemoveEvent(*__pEvent);
+                               }
+                               else
+                               {
+                                       __pCalendarbook->RemoveEvent(eventId);
+                               }
+
+                               r = __pCalendarbook->AddEvent(*__pEvent, __pCalendar->GetRecordId());
+                       }
+                       else
+                       {
+                               r = __pCalendarbook->UpdateEvent(*__pEvent);
+                       }
                }
        }
        else if (__pEventInstance != null)